Skip to content

Commit

Permalink
fix: use exit code
Browse files Browse the repository at this point in the history
Signed-off-by: Marty Jones <[email protected]>
  • Loading branch information
Marty Jones committed Dec 19, 2024
1 parent 4190189 commit b71559b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export interface StricliProcess extends WritableStreams {
*/
readonly env?: Readonly<Partial<Record<string, string>>>;
/**
* Set the exit code and end the current process.
* A number which will be the process exit code.
*/
readonly exit?: (code: number) => void;
exitCode?: number | string;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ export async function run<CONTEXT extends CommandContext>(
context: StricliDynamicCommandContext<CONTEXT>,
): Promise<void> {
const exitCode = await runApplication(app, inputs, context);
context.process.exit?.(exitCode);

// We set the exit code instead of calling exit() so as not
// to cancel any pending tasks (e.g. stdout writes)
context.process.exitCode = exitCode;
}
1 change: 0 additions & 1 deletion packages/core/tests/fakes/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface FakeProcess extends StricliProcess {
readonly stdout: FakeWritable;
readonly stderr: FakeWritable;
readonly exit: (code: number) => void;
readonly exitCode: number;
}

export type FakeContext = StricliDynamicCommandContext<CommandContext> & {
Expand Down

0 comments on commit b71559b

Please sign in to comment.