Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "zx/core",
"path": ["build/core.cjs", "build/util.cjs", "build/vendor-core.cjs"],
"limit": "77.5 kB",
"limit": "77.6 kB",
"brotli": false,
"gzip": false
},
Expand Down Expand Up @@ -30,7 +30,7 @@
{
"name": "all",
"path": "build/*",
"limit": "850 kB",
"limit": "850.2 kB",
"brotli": false,
"gzip": false
}
Expand Down
10 changes: 6 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ type ProcessDto = {

export class ProcessOutput extends Error {
private readonly _dto: ProcessDto
cause!: Error | null
message!: string
stdout!: string
stderr!: string
stdall!: string
constructor(dto: ProcessDto)
constructor(
code: number | null,
Expand Down Expand Up @@ -704,6 +709,7 @@ export class ProcessOutput extends Error {
: { code, signal, duration, error, from, store }

Object.defineProperties(this, {
cause: { value: dto.error, enumerable: false, writable: true, configurable: true },
stdout: { get: once(() => bufArrJoin(dto.store.stdout)) },
stderr: { get: once(() => bufArrJoin(dto.store.stderr)) },
stdall: { get: once(() => bufArrJoin(dto.store.stdall)) },
Expand All @@ -715,10 +721,6 @@ export class ProcessOutput extends Error {
},
})
}
message!: string
stdout!: string
stderr!: string
stdall!: string

get exitCode(): number | null {
return this._dto.code
Expand Down
2 changes: 1 addition & 1 deletion src/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export async function spinner<T>(
title: string | (() => T),
callback?: () => T
): Promise<T> {
if (typeof title == 'function') {
if (typeof title === 'function') {
callback = title
title = ''
}
Expand Down
4 changes: 3 additions & 1 deletion test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,17 @@ describe('core', () => {
assert.equal(o1.exitCode, 1)
assert.match(o1.message, /exit code: 1/)

const err = new Error('BrokenSpawn')
const o2 = await $({
nothrow: true,
spawn() {
throw new Error('BrokenSpawn')
throw err
},
})`echo foo`
assert.equal(o2.ok, false)
assert.equal(o2.exitCode, null)
assert.match(o2.message, /BrokenSpawn/)
assert.equal(o2.cause, err)
})

test('handles `input` option', async () => {
Expand Down