Skip to content

Commit

Permalink
fix(ci): handle non-JSON prefix/suffix lines from print-config
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Dec 16, 2024
1 parent b42fdde commit 43ffcf2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/ci/src/lib/cli/commands/print-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ export async function runPrintConfig({
if (!silent) {
console.info(stdout);
}

// workaround for 1st lines like `> nx run utils:code-pushup -- print-config`
const lines = stdout.split(/\r?\n/);
const jsonLines = lines.slice(lines.indexOf('{'), lines.indexOf('}') + 1);
const stdoutSanitized = jsonLines.join('\n');

try {
return JSON.parse(stdout) as unknown;
return JSON.parse(stdoutSanitized) as unknown;
} catch (error) {
if (silent) {
console.info('Invalid output from print-config:');
console.info(stdout);
}
throw new Error(
`Error parsing output of print-config command - ${stringifyError(error)}`,
);
Expand Down

0 comments on commit 43ffcf2

Please sign in to comment.