fix: fall back to package.json for CLI version detection#21382
Conversation
## Summary Fixes `aztec --version` returning `unknown` when installed via `install.aztec-labs.com`. Closes https://linear.app/aztec-labs/issue/A-642/aztec-version-returns-unkonwn ClaudeBox log: https://claudebox.work/s/9b17d34db367f45c?run=1
|
✅ Successfully backported to backport-to-v4-staging #21410. |
BEGIN_COMMIT_OVERRIDE fix: fall back to package.json for CLI version detection (#21382) chore: Removed multiplier config (#21412) chore: Removed default snapshot url config (#21413) chore: Read tx filestores from network config (#21416) feat(p2p): use l2 priority fee only for tx priority (#21420) fix: update private kernel reset hints builder (#20760) END_COMMIT_OVERRIDE
BEGIN_COMMIT_OVERRIDE feat: add ETHEREUM_HTTP_TIMEOUT_MS env var for viem HTTP transport (#20919) fix(archiver): filter tagged log queries by block number (#21388) fix(node): handle slot zero in getL2ToL1Messages (#21386) feat(sequencer): redistribute checkpoint budget evenly across remaining blocks (#21378) fix: fall back to package.json for CLI version detection (#21382) chore: Removed multiplier config (#21412) chore: Removed default snapshot url config (#21413) chore: Read tx filestores from network config (#21416) fix(node): check world state against requested block hash (#21385) feat(p2p): use l2 priority fee only for tx priority (#21420) feat(p2p): reject and evict txs with insufficient max fee per gas (#21281) revert "feat(p2p): reject and evict txs with insufficient max fee per gas (#21281)" (#21432) chore: Reduce log spam (#21436) fix(tx): reject txs with invalid setup when unprotecting (#21224) fix: orchestrator enqueue yield (#21286) chore(builder): check archive tree next leaf index during block building (#21457) fix: scenario deployment (#21428) chore: add claude skill to read network-logs (#21495) chore: update claude network-logs skill (#21523) feat(rpc): add package version to RPC response headers (#21526) chore(prover): silence "epoch to prove" debug logs (#21527) chore(sequencer): do not log blob data (#21530) fix: dependabot alerts (#21531) docs(p2p): nicer READMEs (#21456) fix(archiver): guard getL1ToL2Messages against incomplete message sync (#21494) fix(sequencer): await syncing proposed block to archiver (#21554) feat(ethereum): check VK tree root and protocol contracts hash in rollup compatibility (#21537) fix: marking peer as dumb on failed responses (#21316) fix(kv-store): make LMDB clear and drop operations atomic across sub-databases (#21539) feat(world-state): add blockHash verification to syncImmediate (#21556) chore(monitor): print out l2 fees components (#21559) chore: rm faucet (#21538) chore: remove old merkle trees (#21577) feat: Implement commit all and revert all for world state checkpoints (#21532) chore: skip flaky browser acir tests in CI (#21596) fix: Better detection for epoch prune (#21478) chore: logging (#21604) fix: Don't update state if we failed to execute sufficient transactions (#21443) END_COMMIT_OVERRIDE
| return version; | ||
| } | ||
| } catch { | ||
| // No package.json found either. |
There was a problem hiding this comment.
@ludamad I would ping you about this on slack but at this point I don't know how so asking here.
2 things seem strange to me in this function:
- We are getting the version here from
.release-please-manifest.jsonwhich seems strange given that release please is deprecated. Also it doesn't seem to correctly resolve the specific version (e.g. a given nightly) and instead it just resolves the future stable version (e.g. currently 4.3.0 onv4). - When we don't find the package.json we don't error out and instead we just return undefined.
Given these 2 problems I implemented my own function in this PR that looks as follows:
/**
* Returns the package version for embedding in contract artifacts or `dev` if the version in package.json is
* the placeholder value (that would indicate that this is used from a locally checked out monorepo instead of npm).
*/
function getPackageVersionOrDev(): string {
const dir = dirname(fileURLToPath(import.meta.url));
const packageJsonPath = resolve(dir, '../../../package.json');
const version = JSON.parse(readFileSync(packageJsonPath).toString()).version;
return version === '0.1.0' ? DEV_VERSION : version;
}What this does is that it returns the version from package.json or "dev" string when the code is run froms a checked out monorepo and not a real release.
I think we should replace the getPackageVersion function with my implementation.
(and maybe drop the .release-please-manifest.json file)
Would you agree?
There was a problem hiding this comment.
AI feedback
Agree with the diagnosis, broadly agree with the replacement, but a few wrinkles before wholesale replacing it.
On the diagnosis — yes:
.release-please-manifest.jsoncurrently holds5.0.0in this checkout. That's the next stable target, not the actually-installed/built version. So for nightlies and stable releases the manifest reading is straight-up wrong;package.json(which release tooling stamps at publish time) is the right source.- Returning
undefinedforces every caller into?? '<fallback>'('','unknown','0.0.0'— all different, none ideal). A typed string is cleaner.
Wrinkles to think about before swapping:
-
Path depth. Your snippet uses
../../../package.jsonbut the existing fallback in this file uses../../package.json. Fordest/update-checker/package_version.jsin the published stdlib package,../../is the package root. Make sure the depth in feat: stamping aztec version into contract artifacts #22550 matches the file's actual location, not a copy-paste from elsewhere. -
Caller behavior change in dev. Today, in a repo checkout, every caller sees
5.0.0. After the change they'll see'dev'. Mostly fine, butwarn_if_aztec_version_mismatch.tsbuildsexpectedTag = \v${version}`→'vdev'and will then warn on every aztec-nr dep. That caller needs an explicitif (version === DEV_VERSION) return;` guard. -
Other callers of
?? ''.aztec-node/server.tsetc. compare versions across the network — if the node reports'dev', downstream comparisons should treat that explicitly rather than as "just another version string." Worth a pass. -
Don't delete
.release-please-manifest.jsonin this PR. Even if release-please is deprecated, that file may still be consumed by current release tooling / GH actions. Confirm it's actually unused first; it's a separate, riskier change from "stop reading it from JS." -
Naming.
getPackageVersionOrDevis fine, but since you're replacing the canonical one, I'd just keepgetPackageVersion(): string(always-returns-a-string semantics, with'dev'baked in) so callers don't need to know the suffix. The behavior is now "the package version, orDEV_VERSIONfor unstamped checkouts."
So: yes, replace it. But fold the dev guard into the version-mismatch warner in the same PR, double-check the path depth, and split off the manifest-file deletion.
[This other PR](#22941) of mine was motivation for this because there we need to stamp aztec version into contract artifact and the current `getPackageVersion` was not helpful in that because it failed to resolve the actual version (e.g. `v4.3.0-nightly.20260427` instead of `v4.3.0`). To workaround this I will no longer read the version from `.release-please-manifest.json` and will read it from package.json instead where the version is stamped during a release. If the code is not run from a release the version is simply populated with "dev" which seems better then returning undefined and forcing the callsites to deal with it. Bothering Adam and Alex with a review here since you are the only people that seemed to have touched the function. ## AI Summary - `getPackageVersion` previously read from `.release-please-manifest.json`, which holds the *next* stable target (currently `5.0.0`) — not the actually-installed/built version. So nightlies and stable releases reported a stale version. - It now reads from the stdlib `package.json` (which release tooling stamps at publish time) and substitutes `DEV_VERSION` (`'dev'`) for the `0.1.0` placeholder used in a monorepo checkout. - Return type narrowed from `string | undefined` to `string`, and the now-dead `?? '<fallback>'` chains in callers (`aztec-node`, `aztec` CLI, `cli-wallet`, `txe`) are dropped. - `warnIfAztecVersionMismatch` gets an early return on `DEV_VERSION` so monorepo checkouts no longer spam warnings about every aztec-nr dep tag mismatch (previously it would compare against `v5.0.0`, now it would have compared against `vdev` — both wrong). `.release-please-manifest.json` is left in place for now since release tooling may still consume it; removing it can be a separate change. Context from #21382 review thread: https://github.com/AztecProtocol/aztec-packages/pull/21382/files#r3182335186
[This other PR](#22941) of mine was motivation for this because there we need to stamp aztec version into contract artifact and the current `getPackageVersion` was not helpful in that because it failed to resolve the actual version (e.g. `v4.3.0-nightly.20260427` instead of `v4.3.0`). To workaround this I will no longer read the version from `.release-please-manifest.json` and will read it from package.json instead where the version is stamped during a release. If the code is not run from a release the version is simply populated with "dev" which seems better then returning undefined and forcing the callsites to deal with it. Bothering Adam and Alex with a review here since you are the only people that seemed to have touched the function. ## AI Summary - `getPackageVersion` previously read from `.release-please-manifest.json`, which holds the *next* stable target (currently `5.0.0`) — not the actually-installed/built version. So nightlies and stable releases reported a stale version. - It now reads from the stdlib `package.json` (which release tooling stamps at publish time) and substitutes `DEV_VERSION` (`'dev'`) for the `0.1.0` placeholder used in a monorepo checkout. - Return type narrowed from `string | undefined` to `string`, and the now-dead `?? '<fallback>'` chains in callers (`aztec-node`, `aztec` CLI, `cli-wallet`, `txe`) are dropped. - `warnIfAztecVersionMismatch` gets an early return on `DEV_VERSION` so monorepo checkouts no longer spam warnings about every aztec-nr dep tag mismatch (previously it would compare against `v5.0.0`, now it would have compared against `vdev` — both wrong). `.release-please-manifest.json` is left in place for now since release tooling may still consume it; removing it can be a separate change. Context from #21382 review thread: https://github.com/AztecProtocol/aztec-packages/pull/21382/files#r3182335186
Summary
Fixes
aztec --versionreturningunknownwhen installed viainstall.aztec-labs.com.Closes https://linear.app/aztec-labs/issue/A-642/aztec-version-returns-unkonwn
ClaudeBox log: https://claudebox.work/s/9b17d34db367f45c?run=1