From 09529b8a08478ae2b66381e79050a02379af49c2 Mon Sep 17 00:00:00 2001 From: Mohak Gupta Date: Wed, 19 Aug 2026 17:43:55 +0530 Subject: [PATCH] fix: parse stdout, not stdall, in `ProcessOutput.json()` `json()` ran JSON.parse on stdall (the combined stdout+stderr stream), so a well-behaved CLI that writes JSON to stdout and progress/prompts to stderr would break json() even though stdout alone contains valid JSON. Parse stdout instead. --- build/core.cjs | 2 +- src/core.ts | 2 +- test/core.test.js | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/build/core.cjs b/build/core.cjs index cd9f1f0706..98337f0c12 100644 --- a/build/core.cjs +++ b/build/core.cjs @@ -1029,7 +1029,7 @@ var _ProcessOutput = class _ProcessOutput extends Error { return !this._dto.error && this.exitCode === 0; } json() { - return JSON.parse(this.stdall); + return JSON.parse(this.stdout); } buffer() { return import_node_buffer.Buffer.from(this.stdall); diff --git a/src/core.ts b/src/core.ts index 39c320149f..ad69630f1f 100644 --- a/src/core.ts +++ b/src/core.ts @@ -934,7 +934,7 @@ export class ProcessOutput extends Error { } json(): T { - return JSON.parse(this.stdall) + return JSON.parse(this.stdout) } buffer(): Buffer { diff --git a/test/core.test.js b/test/core.test.js index b80a2eda91..ac73eb94e3 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -1495,6 +1495,17 @@ describe('core', () => { assert.equal(o.toString(), 'foo\n') }) + test('json() parses stdout, not the combined stdout+stderr', async () => { + const o = new ProcessOutput( + 0, + null, + '{"ok":true}', + 'progress...', + 'progress...{"ok":true}' + ) + assert.deepEqual(o.json(), { ok: true }) + }) + test('valueOf()', async () => { const o = new ProcessOutput(null, null, '', '', 'foo\n') assert.equal(o.valueOf(), 'foo') @@ -1502,7 +1513,13 @@ describe('core', () => { }) test('json()', async () => { - const o = new ProcessOutput(null, null, '', '', '{"key":"value"}') + const o = new ProcessOutput( + null, + null, + '{"key":"value"}', + '', + '{"key":"value"}' + ) assert.deepEqual(o.json(), { key: 'value' }) })