Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Catch errors thrown on sanity check of SB installs #22039

Merged
merged 1 commit into from Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions code/lib/cli/src/js-package-manager/JsPackageManager.ts
Expand Up @@ -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,
Expand All @@ -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 ?? '');
}

Expand Down
11 changes: 9 additions & 2 deletions code/lib/cli/src/js-package-manager/NPMProxy.ts
Expand Up @@ -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);
Expand Down