Skip to content

Commit 43ffcf2

Browse files
committed
fix(ci): handle non-JSON prefix/suffix lines from print-config
1 parent b42fdde commit 43ffcf2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/ci/src/lib/cli/commands/print-config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ export async function runPrintConfig({
1515
if (!silent) {
1616
console.info(stdout);
1717
}
18+
19+
// workaround for 1st lines like `> nx run utils:code-pushup -- print-config`
20+
const lines = stdout.split(/\r?\n/);
21+
const jsonLines = lines.slice(lines.indexOf('{'), lines.indexOf('}') + 1);
22+
const stdoutSanitized = jsonLines.join('\n');
23+
1824
try {
19-
return JSON.parse(stdout) as unknown;
25+
return JSON.parse(stdoutSanitized) as unknown;
2026
} catch (error) {
27+
if (silent) {
28+
console.info('Invalid output from print-config:');
29+
console.info(stdout);
30+
}
2131
throw new Error(
2232
`Error parsing output of print-config command - ${stringifyError(error)}`,
2333
);

0 commit comments

Comments
 (0)