diff --git a/code/lib/cli/src/js-package-manager/JsPackageManager.ts b/code/lib/cli/src/js-package-manager/JsPackageManager.ts index 4900ba2fe88e..107b39ab62b0 100644 --- a/code/lib/cli/src/js-package-manager/JsPackageManager.ts +++ b/code/lib/cli/src/js-package-manager/JsPackageManager.ts @@ -416,7 +416,8 @@ export abstract class JsPackageManager { command: string, args: string[], stdio?: 'pipe' | 'inherit', - cwd?: string + cwd?: string, + ignoreError?: boolean ): string { const commandResult = spawnSync(command, args, { cwd: cwd ?? this.cwd, @@ -425,7 +426,7 @@ export abstract class JsPackageManager { shell: true, }); - if (commandResult.status !== 0) { + if (commandResult.status !== 0 && ignoreError !== true) { throw new Error(commandResult.stderr ?? ''); } diff --git a/code/lib/cli/src/js-package-manager/NPMProxy.ts b/code/lib/cli/src/js-package-manager/NPMProxy.ts index 709b6703eef8..f8f7eb9f231f 100644 --- a/code/lib/cli/src/js-package-manager/NPMProxy.ts +++ b/code/lib/cli/src/js-package-manager/NPMProxy.ts @@ -48,12 +48,19 @@ export class NPMProxy extends JsPackageManager { } public runPackageCommand(command: string, args: string[], cwd?: string): string { - return this.executeCommand(`npm`, ['exec', '--', command, ...args], undefined, cwd); + return this.executeCommand('npm', ['exec', '--', command, ...args], undefined, cwd); } public findInstallations() { const pipeToNull = platform() === 'win32' ? '2>NUL' : '2>/dev/null'; - const commandResult = this.executeCommand('npm', ['ls', '--json', '--depth=99', pipeToNull]); + const commandResult = this.executeCommand( + 'npm', + ['ls', '--json', '--depth=99', pipeToNull], + undefined, + undefined, + // ignore errors, because npm ls will exit with code 1 if there are e.g. unmet peer dependencies + true + ); try { const parsedOutput = JSON.parse(commandResult);