Read the --version string from package.json - #19
Merged
Merged
Conversation
src/index.ts hard-coded .version("0.8.0"), so the published 0.9.1 printed
0.8.0. src/version.ts now reads the version from the package's own
package.json (the same createRequire pattern getanyapi-com/mcp uses), which
npm always packs, so the installed CLI reports the installed release.
The new test runs the real entrypoint with --version and fails if what it
prints differs from package.json; it failed on the old code (0.8.0 vs 0.9.1).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
src/version.ts(new) exportsVERSION, read at runtime from the package's ownpackage.jsonwithcreateRequire(import.meta.url)('../package.json'). This is the same pattern getanyapi-com/mcp uses in itssrc/version.ts.src/index.tspassesVERSIONto commander's.version()instead of the hard-coded"0.8.0". No hand-kept version string remains insrc/.__tests__/version.test.ts(new) runs the real entrypoint with--version, captures what it prints, and fails if that differs frompackage.json.No version bump, no publish, no changelog entry.
Why
src/index.ts:34hard-coded.version("0.8.0"), so the published 0.9.1 prints0.8.0. Measured across releases, the printed version was wrong in 7 of 15. Every release needed a second manual edit, and it was missed about half the time.../package.jsonresolves from bothsrc/(tests) anddist/(the published build), because both sit one level below the package root. npm always includespackage.jsonin the tarball. The lookup goes through the module's own URL, not the working directory, so the installed CLI reports its own release wherever it is run from.Proof
The test fails on the old code (new test only,
src/index.tsunchanged):With the fix:
Repo gate (
npm test && npm run build, from AGENTS.md):Packed artifact. I ran
npm pack, installed the tarball into an empty temp project created bynpm init -y(whose ownpackage.jsonsays1.0.0), then ran the installed binary:The installed CLI prints its own
0.9.1, not the old0.8.0and not the surrounding project's1.0.0.🤖 Generated with Claude Code