Skip to content

Commit

Permalink
fix: unknown command error not showing with package.json (#82)
Browse files Browse the repository at this point in the history
* fix: unknown command error not showing with package.json

* chore: remove debug log

* fix
  • Loading branch information
marvinhagemeister authored Apr 29, 2024
1 parent cdda834 commit de10288
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,10 @@ if (args.length === 0) {
await runScript(process.cwd(), cmd, { pkgManagerName });
});
} else {
console.error(kl.red(`Unknown command: ${cmd}`));
console.log();
printHelp();
process.exit(1);
throwUnknownCommand(cmd);
}
} else {
throwUnknownCommand(cmd);
}
}
}
Expand All @@ -278,3 +277,10 @@ async function run(fn: () => Promise<void>) {
throw err;
}
}

function throwUnknownCommand(cmd: string) {
console.error(kl.red(`Unknown command: ${cmd}`));
console.log();
printHelp();
process.exit(1);
}
33 changes: 33 additions & 0 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,39 @@ import {
writeTextFile,
} from "../src/utils";

describe("general", () => {
it("exit 1 on unknown command", async () => {
try {
await withTempEnv(["foo"], async () => {});
assert.fail("no");
} catch (err) {
if (err instanceof Error) {
assert.match(err.message, /Child process/);
assert.equal((err as any).code, 1);
} else {
throw err;
}
}
});

// See https://github.com/jsr-io/jsr-npm/issues/79
it("exit 1 on unknown command in empty folder", async () => {
await runInTempDir(async (dir) => {
try {
await runJsr(["asdf"], dir);
assert.fail("no");
} catch (err) {
if (err instanceof Error) {
assert.match(err.message, /Child process/);
assert.equal((err as any).code, 1);
} else {
throw err;
}
}
});
});
});

describe("install", () => {
it("jsr i @std/encoding - resolve latest version", async () => {
await withTempEnv(["i", "@std/encoding"], async (dir) => {
Expand Down

0 comments on commit de10288

Please sign in to comment.