From b7e25bdf02e23926f110cb00d1b3c4ab49a1e6ff Mon Sep 17 00:00:00 2001 From: Matei-Paul Trandafir Date: Wed, 22 Jan 2025 02:27:42 +0200 Subject: [PATCH 1/5] Forward exit code of svelte-check --- packages/cli/commands/check.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/cli/commands/check.ts b/packages/cli/commands/check.ts index 23797d20..ba0067eb 100644 --- a/packages/cli/commands/check.ts +++ b/packages/cli/commands/check.ts @@ -42,5 +42,17 @@ 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) { + // TypeScript lore + if ( + error && + typeof error === 'object' && + 'status' in error && + typeof error.status == 'number' + ) { + process.exit(error.status); + } else { + process.exit(1); + } + } } From 3df125875e65e68b53153b039afb8a29c1ae15f8 Mon Sep 17 00:00:00 2001 From: Matei Trandafir Date: Wed, 22 Jan 2025 02:47:26 +0200 Subject: [PATCH 2/5] Remove emotional comment Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- packages/cli/commands/check.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cli/commands/check.ts b/packages/cli/commands/check.ts index ba0067eb..6f949c57 100644 --- a/packages/cli/commands/check.ts +++ b/packages/cli/commands/check.ts @@ -43,7 +43,6 @@ function runCheck(cwd: string, args: string[]) { const cmd = resolveCommand(pm, 'execute-local', ['svelte-check', ...args])!; execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit', cwd }); } catch (error) { - // TypeScript lore if ( error && typeof error === 'object' && From d4efdf4c8d29c86d954327be1af20533c7d093fd Mon Sep 17 00:00:00 2001 From: Matei-Paul Trandafir Date: Wed, 22 Jan 2025 13:51:56 +0200 Subject: [PATCH 3/5] Also apply change to sv migrate --- packages/cli/commands/check.ts | 12 ++---------- packages/cli/commands/migrate.ts | 5 ++++- packages/cli/utils/common.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/cli/commands/check.ts b/packages/cli/commands/check.ts index 6f949c57..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') @@ -43,15 +44,6 @@ function runCheck(cwd: string, args: string[]) { const cmd = resolveCommand(pm, 'execute-local', ['svelte-check', ...args])!; execSync(`${cmd.command} ${cmd.args.join(' ')}`, { stdio: 'inherit', cwd }); } catch (error) { - if ( - error && - typeof error === 'object' && - 'status' in error && - typeof error.status == 'number' - ) { - process.exit(error.status); - } else { - process.exit(1); - } + 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); + } +} From 690f2ec98e5a3b5f3a6def0e8115ef238b66c3e3 Mon Sep 17 00:00:00 2001 From: Matei-Paul Trandafir Date: Wed, 22 Jan 2025 14:04:10 +0200 Subject: [PATCH 4/5] Changeset --- .changeset/proud-apples-watch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/proud-apples-watch.md diff --git a/.changeset/proud-apples-watch.md b/.changeset/proud-apples-watch.md new file mode 100644 index 00000000..921e7e85 --- /dev/null +++ b/.changeset/proud-apples-watch.md @@ -0,0 +1,5 @@ +--- +'sv': minor +--- + +fix: forward exit code of external package commands From f244c744ab8f8d0fecc0df0dfdb4495278e6ea7c Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 22 Jan 2025 08:37:35 -0800 Subject: [PATCH 5/5] Update .changeset/proud-apples-watch.md --- .changeset/proud-apples-watch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/proud-apples-watch.md b/.changeset/proud-apples-watch.md index 921e7e85..83289958 100644 --- a/.changeset/proud-apples-watch.md +++ b/.changeset/proud-apples-watch.md @@ -1,5 +1,5 @@ --- -'sv': minor +'sv': patch --- fix: forward exit code of external package commands