From d4be77fb31e051f53599df0e0783a01f13566d9b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:39:21 -0700 Subject: [PATCH] Fix missing exit codes --- .changeset/tidy-buttons-press.md | 5 +++++ src/common.ts | 16 +++++++++++----- src/git.ts | 8 ++++---- src/typescript.ts | 8 ++++---- 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 .changeset/tidy-buttons-press.md diff --git a/.changeset/tidy-buttons-press.md b/.changeset/tidy-buttons-press.md new file mode 100644 index 0000000..5e28436 --- /dev/null +++ b/.changeset/tidy-buttons-press.md @@ -0,0 +1,5 @@ +--- +"every-ts": patch +--- + +Fix missing exit codes diff --git a/src/common.ts b/src/common.ts index 5037e1d..f4bbdd2 100644 --- a/src/common.ts +++ b/src/common.ts @@ -53,13 +53,19 @@ export class ExitError extends Error { } export abstract class BaseCommand extends Command { - override catch(error: any): Promise { - if (error instanceof ExitError) { - this.context.stderr.write(`${error.message}\n`); - return Promise.resolve(error.exitCode); + override async execute(): Promise { + try { + return await this.executeOrThrow(); + } catch (e) { + if (e instanceof ExitError) { + this.context.stderr.write(`${e.message}\n`); + return e.exitCode; + } + throw e; } - return super.catch(error); } + + abstract executeOrThrow(): Promise; } export async function revParse(rev: string) { diff --git a/src/git.ts b/src/git.ts index f1072ca..7cb3a47 100644 --- a/src/git.ts +++ b/src/git.ts @@ -32,7 +32,7 @@ export class Bisect extends BaseCommand { subcommand = Option.String({ required: true }); args = Option.Proxy(); - override async execute(): Promise { + override async executeOrThrow(): Promise { let startArgs: string[] = []; let revs; let endArgs: string[] = []; @@ -117,7 +117,7 @@ export class BisectRun extends BaseCommand { args = Option.Proxy({ required: 1 }); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureRepo(); if (!await getBisectInfo()) { @@ -168,7 +168,7 @@ export class Switch extends BaseCommand { rev = Option.String({ required: false }); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureRepo(); const target = await findRev(this.rev ?? `main`, true); @@ -200,7 +200,7 @@ export class Fetch extends BaseCommand { description: `Fetches the latest info for the TypeScript checkout.`, }); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureRepo(); await execa(`git`, [`fetch`, `--all`, `--tags`], { cwd: tsDir }); // This will usually be a noop, but if this is what's used to fetch the first time, diff --git a/src/typescript.ts b/src/typescript.ts index e7e11f1..b21701b 100644 --- a/src/typescript.ts +++ b/src/typescript.ts @@ -13,7 +13,7 @@ export class Tsc extends BaseCommand { args = Option.Proxy(); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureBuilt(); const { tsc } = getPaths(); const result = await execa(`node`, [tsc, ...this.args], { stdio: `inherit`, reject: false }); @@ -30,7 +30,7 @@ export class Tsdk extends BaseCommand { args = Option.Proxy(); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureBuilt(); const { baseDir } = getPaths(); console.log(`"typescript.tsdk": ${JSON.stringify(baseDir)}`); @@ -46,7 +46,7 @@ export class Exec extends BaseCommand { args = Option.Proxy({ required: 1 }); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureBuilt(); const result = await execa( this.args[0], @@ -64,7 +64,7 @@ export class Dir extends BaseCommand { description: `Gets the path to the TypeScript checkout, for use in "npm link", etc.`, }); - override async execute(): Promise { + override async executeOrThrow(): Promise { await ensureBuilt(); console.log(tsDir); }