Releases: google/zx
Releases · google/zx
8.2.4 – Leaky Faucet
8.2.3 – Golden Wrench
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
8.2.2
What's Changed
- test: stdio inherit by @antongolub in #941
- fix: handle nullable stdout/stderr by @antongolub in #943
Full Changelog: 8.2.1...8.2.2
8.2.1
8.2.0
Pipes supercharge today! 🚀
Features
- Delayed piping. You can fill dependent streams at any time during the origin process lifecycle (even when finished) without losing data. #914
const result = $`echo 1; sleep 1; echo 2; sleep 1; echo 3`
const piped1 = result.pipe`cat`
let piped2
setTimeout(() => {
piped2 = result.pipe`cat`
}, 1500)
await piped1
assert.equal((await piped1).toString(), '1\n2\n3\n')
assert.equal((await piped2).toString(), '1\n2\n3\n')
const file = tempfile()
const fileStream = fs.createWriteStream(file)
const p = $`echo "hello"`
.pipe(
new Transform({
transform(chunk, encoding, callback) {
callback(null, String(chunk).toUpperCase())
},
})
)
.pipe(fileStream)
p instanceof WriteStream // true
await p === fileStream // true
(await fs.readFile(file)).toString() // 'HELLO\n'
Chore
8.1.9
Today's release is a minor update that includes:
Enhancements
- We have replaced
ProcessOutput
fields with lazy getters to reduce mem consumption #903, #908 - Reduced ReDos risks for codeblock patterns #906
- Kept
argv
reference on update #916 - Strengthened
Shell
interface to properly handlesync
mode #915:
expectType<ProcessPromise>($`cmd`)
expectType<ProcessPromise>($({ sync: false })`cmd`)
expectType<ProcessOutput>($({ sync: true })`cmd`)
expectType<ProcessOutput>($.sync`cmd`)
Fixes
8.1.8
8.1.7
Step by step on the road to improvements
Fixes
Finally, we've fixed the issue with piped process rejection #640 #899:
const p1 = $`exit 1`.pipe($`echo hello`)
try {
await p1
} catch (e) {
assert.equal(e.exitCode, 1)
}
const p2 = await $({ nothrow: true })`echo hello && exit 1`.pipe($`cat`)
assert.equal(p2.exitCode, 0)
assert.equal(p2.stdout.trim(), 'hello')
Enhancements
Added cmd
display to ProcessPromise
#891:
const foo = 'bar'
const p = $`echo ${foo}`
p.cmd // 'echo bar'
and duration
field to ProcessOutput
#892:
const p = $`sleep 1`.nothrow()
const o = await p
o.duration // ~1000 (in ms)
Enabled zurk-like pipe string literals #900:
const p = await $`echo foo`.pipe`cat`
p.stdout.trim() // 'foo'
8.1.6
Improvements & Fixes
$.preferLocal = true // injects node_modules/.bin to the $PATH
$.preferLocal = '/foo/bar' // attaches /foo/bar to the $PATH
$.preferLocal = ['/bar', '/baz'] // now the $PATH includes both /bar and /baz
Why not just $.env['PATH'] = 'extra:' + '$.env['PATH']
?
Well, the API internally does the same, but also handles the win paths peculiarities.
- Provided
$.killSignal
option for the symmetry with the$.timeoutSignal
. You can override the default termination flow #885:
$.killSignal = 'SIGKILL'
const p = $({nothrow: true})`sleep 10000`
setTimeout(p.kill, 100)
(await p).signal // SIGKILL
$
opt presets became chainable #883:
const $$ = $({ nothrow: true })
assert.equal((await $$`exit 1`).exitCode, 1)
const $$$ = $$({ sync: true }) // Both {nothrow: true, sync: true} are applied
assert.equal($$$`exit 2`.exitCode, 2)
- Enhanced the internal
Duration
parser #884:
const p = $({timeout: '1mss'})`sleep 999` // raises an error now