This release continues the work on pipe API enhancements:
const { stdout } = await $({ halt: true })`echo "hello"`
.pipe`awk '{print $1" world"}'`
.pipe`tr '[a-z]' '[A-Z]'`
.run()
stdout // 'HELLO WORLD'
- Let $ be piped directly from streams #953
const getUpperCaseTransform = () =>
new Transform({
transform(chunk, encoding, callback) {
callback(null, String(chunk).toUpperCase())
},
})
// $ > stream (promisified) > $
const o1 = await $`echo "hello"`
.pipe(getUpperCaseTransform())
.pipe($`cat`)
o1.stdout // 'HELLO\n'
// stream > $
const file = tempfile()
await fs.writeFile(file, 'test')
const o2 = await fs
.createReadStream(file)
.pipe(getUpperCaseTransform())
.pipe($`cat`)
o2.stdout // 'TEST'
const file = tempfile()
const fileStream = fs.createWriteStream(file)
const p = $`echo "hello"`
.pipe(getUpperCaseTransform())
.pipe(fileStream)
const o = await p
p instanceof WriteStream // true
o instanceof WriteStream // true
o.stdout // 'hello\n'
o.exitCode; // 0
(await fs.readFile(file)).toString() // 'HELLO\n'
We've also slightly tweaked up dist contents for better compatibility with bundlers #957