Skip to content

fix(release): pack the tarball after the CLI is rebuilt - #91

Merged
simoncodes-ca merged 1 commit into
developfrom
fix/cli-version-in-release-tarball
Sep 5, 2026
Merged

simoncodes-ca merged 1 commit into
developfrom
fix/cli-version-in-release-tarball

Conversation

@simoncodes-ca

Copy link
Copy Markdown
Owner

Fixes the aside reported on #86: lingo-tracker --version printed 0.16.0 on the published
0.17.0 package. Confirmed against the published tarball — package.json says 0.17.0,
dist/apps/cli/main.cjs says version("0.16.0").

Cause

The version is not hardcoded. apps/cli/src/main.ts uses .version(__CLI_VERSION__), and
apps/cli/esbuild.config.js replaces that token at build time from the root package.json.
The bundle therefore freezes whatever version was current when the CLI was built.

The workflow's Build step runs before pnpm run release, so the first CLI bundle carries
the previous version. semantic-release then runs its prepare steps in plugin order:

# Plugin What it does
1 @semantic-release/changelog writes CHANGELOG.md
2 @semantic-release/npm bumps package.json, then packs the tarball into dist/
3 @semantic-release/exec pnpm nx build cli --skip-nx-cache — rebuilds with the right version
4 @semantic-release/git commits

Step 3 fixes the bundle, but step 2 already packed the tarball, so npm publish ./dist/*.tgz ships the pre-bump build.

The republish job does not have the bug: it checks out the tag (already bumped), builds,
then packs.

Fix

Drop tarballDir from the npm plugin so it only bumps the version, and pack from the exec
step after the rebuild — the ordering republish already proves works.

["@semantic-release/npm", { "npmPublish": false }],
["@semantic-release/exec", {
  "prepareCmd": "pnpm nx build cli --skip-nx-cache && npm pack --pack-destination dist"
}]

Also adds a step that unpacks the tarball and fails the release if the packed CLI does not
report the version in package.json, so a regression here stops before npm rather than
after. Same spirit as the existing "Verify tag matches package version" step in republish.

Verified

Ran nx build cli --skip-nx-cache && npm pack --pack-destination dist locally and unpacked
the result:

version("0.17.0")   ← dist/apps/cli/main.cjs
"version": "0.17.0" ← package.json

The tarball lands as dist/simoncodes-ca-lingo-tracker-0.17.0.tgz, so the existing
dist/*.tgz glob and hashFiles guard still match. The verify step's shell was exercised
both ways: it passes on a matching tarball and its failure branch fires on a mismatched one.

One caveat: the fix can only fully prove itself on a real release run, since locally
package.json was already at the released version. The verify step exists to catch it if
the ordering is still wrong.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RifJr7xyhZkaTWn4ssV1b4

`lingo-tracker --version` printed 0.16.0 on the published 0.17.0 package. The
version is not hardcoded: apps/cli/src/main.ts uses `.version(__CLI_VERSION__)`,
which esbuild replaces at build time from the root package.json. The bundle
therefore freezes whatever version was current when the CLI was built.

semantic-release runs its prepare steps in plugin order, and @semantic-release/npm
both bumps package.json and packs the tarball in the same step. So the tarball was
packed from the CLI built by the workflow's earlier `pnpm run build` — before the
bump — and the @semantic-release/exec rebuild that followed came too late to reach
it. `npm publish ./dist/*.tgz` then shipped the pre-bump bundle.

Drop `tarballDir` from the npm plugin and pack from the exec step instead, after
the rebuild. This is the ordering the `republish` job already uses: checkout the
tag, build, then pack.

Also verify the packed CLI reports the released version before publishing, so a
regression fails the release instead of reaching npm.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RifJr7xyhZkaTWn4ssV1b4
@simoncodes-ca
simoncodes-ca merged commit b406e9a into develop Sep 5, 2026
1 check passed
@simoncodes-ca
simoncodes-ca deleted the fix/cli-version-in-release-tarball branch September 5, 2026 05:39
@lingo-tracker-release

Copy link
Copy Markdown

🎉 This PR is included in version 0.18.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants