From 9cdf34a156e3f5c063ca5559367ce9277356a13f Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Sat, 11 May 2024 22:05:55 +0100 Subject: [PATCH] fix: can deploy error, as json output could not be parsed --- src/can-deploy/can-deploy.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/can-deploy/can-deploy.ts b/src/can-deploy/can-deploy.ts index 32643020..6364f323 100644 --- a/src/can-deploy/can-deploy.ts +++ b/src/can-deploy/can-deploy.ts @@ -100,7 +100,7 @@ export class CanDeploy { ], this.__argMapping ); - const output: Array = []; + let output: Array = []; if (instance.stdout && instance.stderr) { instance.stdout.on('data', (l) => output.push(l)); instance.stderr.on('data', (l) => output.push(l)); @@ -110,9 +110,15 @@ export class CanDeploy { if (this.options.output === 'json') { try { - const startIndex = output.findIndex((l: string | Buffer) => - l.toString().startsWith('{') - ); + const findJsonIndex = (data: (string | Buffer)[]) => + data.findIndex((l: string | Buffer) => + l.toString().startsWith('{') + ); + let startIndex = findJsonIndex(output); + if (startIndex === -1) { + output = output.toString().split('\n'); + startIndex = findJsonIndex(output); + } if (startIndex === -1) { logger.error( `can-i-deploy produced no json output:\n${result}`