Skip to content

Commit ea45ddb

Browse files
rChaozbenmccann
andauthored
fix: forward exit code of external package commands (#412)
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
1 parent 8e76bbf commit ea45ddb

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

.changeset/proud-apples-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix: forward exit code of external package commands

packages/cli/commands/check.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Command } from 'commander';
55
import * as resolve from 'empathic/resolve';
66
import { resolveCommand } from 'package-manager-detector/commands';
77
import { getUserAgent } from '../utils/package-manager.ts';
8+
import { forwardExitCode } from '../utils/common.js';
89

910
export const check = new Command('check')
1011
.description('a CLI for checking your Svelte code')
@@ -42,5 +43,7 @@ function runCheck(cwd: string, args: string[]) {
4243
try {
4344
const cmd = resolveCommand(pm, 'execute-local', ['svelte-check', ...args])!;
4445
execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit', cwd });
45-
} catch {}
46+
} catch (error) {
47+
forwardExitCode(error);
48+
}
4649
}

packages/cli/commands/migrate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import process from 'node:process';
33
import { Command } from 'commander';
44
import { resolveCommand } from 'package-manager-detector';
55
import { getUserAgent } from '../utils/package-manager.ts';
6+
import { forwardExitCode } from '../utils/common.js';
67

78
export const migrate = new Command('migrate')
89
.description('a CLI for migrating Svelte(Kit) codebases')
@@ -31,5 +32,7 @@ function runMigrate(cwd: string, args: string[]) {
3132

3233
const cmd = resolveCommand(pm, 'execute', cmdArgs)!;
3334
execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit', cwd });
34-
} catch {}
35+
} catch (error) {
36+
forwardExitCode(error);
37+
}
3538
}

packages/cli/utils/common.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import pkg from '../package.json' with { type: 'json' };
33
import * as p from '@sveltejs/clack-prompts';
44
import type { Argument, HelpConfiguration, Option } from 'commander';
55
import { UnsupportedError } from './errors.ts';
6+
import process from 'node:process';
67

78
const NO_PREFIX = '--no-';
89
let options: readonly Option[] = [];
@@ -96,3 +97,11 @@ export function getPadding(lines: string[]) {
9697
const lengths = lines.map((s) => s.length);
9798
return Math.max(...lengths);
9899
}
100+
101+
export function forwardExitCode(error: unknown) {
102+
if (error && typeof error === 'object' && 'status' in error && typeof error.status == 'number') {
103+
process.exit(error.status);
104+
} else {
105+
process.exit(1);
106+
}
107+
}

0 commit comments

Comments
 (0)