Commit f659526

Anton Golub <antongolub@antongolub.com>
2022-07-02 23:13:05
fix: omit fn prototype methods in $ proxy (#472)
* fix: omit fn prototype methods in $ proxy * chore: simplify
1 parent 68c7a0e
Changed files (2)
src/core.ts
@@ -109,11 +109,13 @@ export const $ = new Proxy<Shell & Options>(
   } as Shell & Options,
   {
     set(_, key, value) {
-      Reflect.set(getStore(), key, value)
+      const target = key in Function.prototype ? _ : getStore()
+      Reflect.set(target, key, value)
       return true
     },
     get(_, key) {
-      return Reflect.get(getStore(), key)
+      const target = key in Function.prototype ? _ : getStore()
+      return Reflect.get(target, key)
     },
   }
 )
test/core.test.js
@@ -425,4 +425,12 @@ test('malformed cmd error', async () => {
   assert.throws(() => $`\033`, /malformed/i)
 })
 
+test('$ is a regular function', async () => {
+  const _$ = $.bind(null)
+  let foo = await _$`echo foo`
+  assert.is(foo.stdout, 'foo\n')
+  assert.ok(typeof $.call === 'function')
+  assert.ok(typeof $.apply === 'function')
+})
+
 test.run()