Skip to content

Commit fa33d31

Browse files
sweetmantechclaude
andauthored
fix: CLI always reported version 0.1.0 (#10)
* fix: read CLI version from package.json at runtime The version was hardcoded as "0.1.0" in bin.ts, so every published version reported itself as 0.1.0 regardless of the actual version. Also reorders the publish workflow to bump version before building, so the built artifact includes the correct version. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: build before test in CI workflow The version test requires dist/bin.cjs to exist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4e7087d commit fa33d31

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ jobs:
3131

3232
- run: pnpm test
3333

34-
- run: pnpm build
35-
3634
- name: Bump patch version
3735
run: |
3836
git config user.name "github-actions[bot]"
@@ -43,6 +41,8 @@ jobs:
4341
git commit -m "chore: bump version to $VERSION [skip ci]"
4442
git push
4543
44+
- run: pnpm build
45+
4646
- name: Publish to npm
4747
run: pnpm publish --no-git-checks
4848
env:

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ jobs:
2020

2121
- run: pnpm install --frozen-lockfile
2222

23-
- run: pnpm test
24-
2523
- run: pnpm build
24+
25+
- run: pnpm test

__tests__/bin.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, it, expect } from "vitest";
2+
import { readFileSync } from "node:fs";
3+
import { join } from "node:path";
4+
import { execFileSync } from "node:child_process";
5+
6+
describe("CLI version", () => {
7+
it("reports the version from package.json", () => {
8+
const pkg = JSON.parse(
9+
readFileSync(join(__dirname, "..", "package.json"), "utf-8"),
10+
);
11+
12+
const output = execFileSync(
13+
"node",
14+
[join(__dirname, "..", "dist", "bin.cjs"), "--version"],
15+
{ encoding: "utf-8" },
16+
).trim();
17+
18+
expect(output).toBe(pkg.version);
19+
});
20+
});

src/bin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { readFileSync } from "node:fs";
2+
import { join } from "node:path";
13
import { Command } from "commander";
24
import { whoamiCommand } from "./commands/whoami.js";
35
import { artistsCommand } from "./commands/artists.js";
@@ -6,12 +8,15 @@ import { sandboxesCommand } from "./commands/sandboxes.js";
68
import { notificationsCommand } from "./commands/notifications.js";
79
import { orgsCommand } from "./commands/orgs.js";
810

11+
const pkgPath = join(__dirname, "..", "package.json");
12+
const { version } = JSON.parse(readFileSync(pkgPath, "utf-8"));
13+
914
const program = new Command();
1015

1116
program
1217
.name("recoup")
1318
.description("Recoup platform CLI")
14-
.version("0.1.0");
19+
.version(version);
1520

1621
program.addCommand(whoamiCommand);
1722
program.addCommand(artistsCommand);

0 commit comments

Comments
 (0)