Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"README.md",
"LICENSE"
],
"limit": "129.46 kB",
"limit": "129.54 kB",
"brotli": false,
"gzip": false
},
Expand All @@ -33,7 +33,7 @@
"build/globals.js",
"build/deno.js"
],
"limit": "881.85 kB",
"limit": "881.93 kB",
"brotli": false,
"gzip": false
},
Expand Down Expand Up @@ -66,7 +66,7 @@
"README.md",
"LICENSE"
],
"limit": "944.60 kB",
"limit": "944.68 kB",
"brotli": false,
"gzip": false
}
Expand Down
3 changes: 2 additions & 1 deletion build/core.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
},
on: {
start: () => {
$2.log({ kind: "cmd", cmd: $2.cmd, cwd, verbose: self.isVerbose(), id });
const log2 = () => $2.log({ kind: "cmd", cmd: $2.cmd, cwd, verbose: self.isVerbose(), id });
self.sync ? log2() : queueMicrotask(log2);
self.timeout($2.timeout, $2.timeoutSignal);
},
stdout: (data) => {
Expand Down
6 changes: 5 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,11 @@ export class ProcessPromise extends Promise<ProcessOutput> {
},
on: {
start: () => {
$.log({ kind: 'cmd', cmd: $.cmd, cwd, verbose: self.isVerbose(), id })
// A process starts eagerly, so chained configurators (`quiet()`, `verbose()`)
// are applied after this hook. Defer the entry to pick them up.
// Sync mode gets no such chance and needs the cmd logged before its output.
const log = () => $.log({ kind: 'cmd', cmd: $.cmd, cwd, verbose: self.isVerbose(), id })
self.sync ? log() : queueMicrotask(log)
self.timeout($.timeout, $.timeoutSignal)
},
stdout: (data) => {
Expand Down
46 changes: 46 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,52 @@ describe('core', () => {
id,
})
})

it('applies chained configurators to the `cmd` entry', async () => {
// https://github.com/google/zx/issues/931
const entries = []
const log = (entry) => entries.push([entry.kind, entry.verbose])
const capture = async (p) => {
entries.length = 0
await p
return entries.slice()
}

assert.deepEqual(
await capture($({ log, verbose: true })`echo foo`.quiet()),
[
['cmd', false],
['stdout', false],
['end', false],
]
)
assert.deepEqual(
await capture($({ log, verbose: true })`echo foo`.verbose(false)),
[
['cmd', false],
['stdout', false],
['end', false],
]
)
assert.deepEqual(
await capture(
$({ log, verbose: true, quiet: true })`echo foo`.quiet(false)
),
[
['cmd', true],
['stdout', true],
['end', true],
]
)
})

it('keeps the `cmd` entry ahead of the output in sync mode', () => {
const entries = []
const log = (entry) => entries.push(entry.kind)
$.sync({ log, verbose: true })`echo foo`

assert.deepEqual(entries, ['cmd', 'stdout', 'end'])
})
})

describe('ProcessPromise', () => {
Expand Down