diff --git a/packages/plugin-js-packages/src/lib/runner/index.ts b/packages/plugin-js-packages/src/lib/runner/index.ts index e2784e30e..f8bca562d 100644 --- a/packages/plugin-js-packages/src/lib/runner/index.ts +++ b/packages/plugin-js-packages/src/lib/runner/index.ts @@ -78,18 +78,13 @@ async function processOutdated( packageJsonPaths: PackageJsonPaths, ) { const pm = packageManagers[id]; - const { stdout, stderr } = await executeProcess({ + const { stdout } = await executeProcess({ command: pm.command, args: pm.outdated.commandArgs, cwd: process.cwd(), ignoreExitCode: true, // outdated returns exit code 1 when outdated dependencies are found }); - // Successful outdated check has empty stderr - if (stderr) { - throw new Error(`JS packages plugin: outdated error: ${stderr}`); - } - // Locate all package.json files in the repository if not provided const finalPaths = Array.isArray(packageJsonPaths) ? packageJsonPaths @@ -122,16 +117,12 @@ async function processAudit( const auditResults = await Promise.allSettled( compatibleAuditDepGroups.map( async (depGroup): Promise<[DependencyGroup, AuditResult]> => { - const { stdout, stderr } = await executeProcess({ + const { stdout } = await executeProcess({ command: pm.command, args: pm.audit.getCommandArgs(depGroup), cwd: process.cwd(), ignoreExitCode: pm.audit.ignoreExitCode, }); - // Successful audit check has empty stderr - if (stderr) { - throw new Error(`JS packages plugin: audit error: ${stderr}`); - } return [depGroup, pm.audit.unifyResult(stdout)]; }, ), diff --git a/packages/utils/src/lib/transform.ts b/packages/utils/src/lib/transform.ts index f33aaa40e..86caf9aef 100644 --- a/packages/utils/src/lib/transform.ts +++ b/packages/utils/src/lib/transform.ts @@ -114,9 +114,19 @@ export function toUnixNewlines(text: string): string { return platform() === 'win32' ? text.replace(/\r\n/g, '\n') : text; } -export function fromJsonLines(jsonLines: string) { +export function fromJsonLines(jsonLines: string) { const unifiedNewLines = toUnixNewlines(jsonLines).trim(); - return JSON.parse(`[${unifiedNewLines.split('\n').join(',')}]`) as T; + const invalid = Symbol('invalid json'); + return unifiedNewLines + .split('\n') + .map(line => { + try { + return JSON.parse(line); + } catch { + return invalid; + } + }) + .filter(line => line !== invalid) as T; } export function toJsonLines(json: T[]) { diff --git a/packages/utils/src/lib/transform.unit.test.ts b/packages/utils/src/lib/transform.unit.test.ts index d4ad2cfcf..b72982e3d 100644 --- a/packages/utils/src/lib/transform.unit.test.ts +++ b/packages/utils/src/lib/transform.unit.test.ts @@ -258,6 +258,17 @@ describe('JSON lines format', () => { expect(fromJsonLines(jsonLines)).toEqual([head, body]); }); + + it('should ignore non-JSON lines', () => { + const jsonLines = [ + '(node:346640) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.', + '(Use `node --trace-deprecation ...` to show where the warning was created)', + JSON.stringify(head), + JSON.stringify(body), + ].join('\n'); + + expect(fromJsonLines(jsonLines)).toEqual([head, body]); + }); }); describe('toJsonLines', () => {