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

fix: forward exit code of external package commands #412

Merged
merged 5 commits into from
Jan 22, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-apples-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix: forward exit code of external package commands
5 changes: 4 additions & 1 deletion packages/cli/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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);
}
}
5 changes: 4 additions & 1 deletion packages/cli/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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);
}
}
9 changes: 9 additions & 0 deletions packages/cli/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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);
}
}
Loading