Skip to content

fix: read the CLI version from package.json - #11

Merged
Asdivyansh merged 1 commit into
SilosLabs:mainfrom
TheDreamSaver:fix/single-source-version
Nov 2, 2026
Merged

Asdivyansh merged 1 commit into
SilosLabs:mainfrom
TheDreamSaver:fix/single-source-version

Conversation

@TheDreamSaver

Copy link
Copy Markdown
Member

Fixes #10

What

  • New src/version.ts: exports VERSION, read from package.json with createRequire(import.meta.url)("../package.json"). That path resolves the same from src/ (tsx, vitest) and from the bundled dist/cli.js / dist/proxy-daemon.js, and package.json ships next to dist/ in the npm package, with npm link, and with install.sh (which copies it).
  • The five hard-coded 0.2.0s now use VERSION: silo --version (cli.ts), the logger banner, the two onboarding banners, and the silo integrations test user-agent.
  • New tests/version.test.ts: checks that VERSION matches package.json and is a semver string.

I used createRequire rather than fs.readFileSync deliberately: tests/commands/onboard.test.ts mocks node:fs with only existsSync, so a readFileSync at module load would break any test that mocks fs that way.

Testing

  • npm run typecheck: passes.
  • npm test: 24 files, 341 tests pass (2 new).
  • npm run build: succeeds. Both bundles contain the runtime createRequire(...)("../package.json"), so nothing is baked in at build time.
  • End to end:
    • node dist/cli.js --version prints 0.2.0.
    • After temporarily setting package.json to 0.2.1-test, it prints 0.2.1-test with no rebuild.
    • Restored afterwards.

The version was hard-coded as "0.2.0" in five places (--version, the
logger and onboarding banners, and the integrations-test user-agent),
so bumping package.json for a release would leave them stale.

Add src/version.ts, which loads package.json with createRequire so the
path resolves the same from src/ and from the bundled dist/ files and
is unaffected by tests that mock node:fs. Use it everywhere.

Fixes SilosLabs#10
@Asdivyansh
Asdivyansh merged commit aa864a1 into SilosLabs:main Nov 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Version is hard-coded in five places, so silo --version won't follow a package.json bump

2 participants