diff --git a/.changeset/proud-apples-watch.md b/.changeset/proud-apples-watch.md new file mode 100644 index 00000000..83289958 --- /dev/null +++ b/.changeset/proud-apples-watch.md @@ -0,0 +1,5 @@ +--- +'sv': patch +--- + +fix: forward exit code of external package commands diff --git a/packages/cli/commands/check.ts b/packages/cli/commands/check.ts index 23797d20..d436c618 100644 --- a/packages/cli/commands/check.ts +++ b/packages/cli/commands/check.ts @@ -5,6 +5,7 @@ import { Command } from 'commander'; import * as resolve from 'empathic/resolve'; import { resolveCommand } from 'package-manager-detector/commands'; import { getUserAgent } from '../utils/package-manager.ts'; +import { forwardExitCode } from '../utils/common.js'; export const check = new Command('check') .description('a CLI for checking your Svelte code') @@ -42,5 +43,7 @@ function runCheck(cwd: string, args: string[]) { try { const cmd = resolveCommand(pm, 'execute-local', ['svelte-check', ...args])!; execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit', cwd }); - } catch {} + } catch (error) { + forwardExitCode(error); + } } diff --git a/packages/cli/commands/migrate.ts b/packages/cli/commands/migrate.ts index b3fecb36..abb684b9 100644 --- a/packages/cli/commands/migrate.ts +++ b/packages/cli/commands/migrate.ts @@ -3,6 +3,7 @@ import process from 'node:process'; import { Command } from 'commander'; import { resolveCommand } from 'package-manager-detector'; import { getUserAgent } from '../utils/package-manager.ts'; +import { forwardExitCode } from '../utils/common.js'; export const migrate = new Command('migrate') .description('a CLI for migrating Svelte(Kit) codebases') @@ -31,5 +32,7 @@ function runMigrate(cwd: string, args: string[]) { const cmd = resolveCommand(pm, 'execute', cmdArgs)!; execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit', cwd }); - } catch {} + } catch (error) { + forwardExitCode(error); + } } diff --git a/packages/cli/utils/common.ts b/packages/cli/utils/common.ts index ed6809ee..3c4e66d6 100644 --- a/packages/cli/utils/common.ts +++ b/packages/cli/utils/common.ts @@ -3,6 +3,7 @@ import pkg from '../package.json' with { type: 'json' }; import * as p from '@sveltejs/clack-prompts'; import type { Argument, HelpConfiguration, Option } from 'commander'; import { UnsupportedError } from './errors.ts'; +import process from 'node:process'; const NO_PREFIX = '--no-'; let options: readonly Option[] = []; @@ -96,3 +97,11 @@ export function getPadding(lines: string[]) { const lengths = lines.map((s) => s.length); return Math.max(...lengths); } + +export function forwardExitCode(error: unknown) { + if (error && typeof error === 'object' && 'status' in error && typeof error.status == 'number') { + process.exit(error.status); + } else { + process.exit(1); + } +}