Commit d0e889c

Anton Medvedev <anton@medv.io>
2021-05-21 01:17:32
Disallow strings in pipe()
1 parent 237844e
Changed files (2)
index.mjs
@@ -156,7 +156,9 @@ export class ProcessPromise extends Promise {
   }
 
   pipe(dest) {
-    if (typeof dest === 'string') return this.pipe($([dest]))
+    if (typeof dest === 'string') {
+      throw new Error('The pipe() method does not take strings. Forgot $?')
+    }
     if (dest instanceof ProcessPromise) {
       process.stdin.unpipe(dest.stdin)
       this.stdout.pipe(dest.stdin)
test.mjs
@@ -88,7 +88,7 @@ import {strict as assert} from 'assert'
 }
 
 { // Pipes works both ways
-  let p = $`read foo; echo "$foo"`.pipe($`cat | wc`).pipe('wc -c')
+  let p = $`read foo; echo "$foo"`.pipe($`cat | wc`).pipe($`wc -c`)
   p.stdin.write('hello\n')
   assert((await p).stdout === 'hello\n')
 }