From 44556483e5eb750cad241d65559c0957510a90c1 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 5 May 2026 09:31:52 +0000 Subject: [PATCH] refactor: read package version from package.json instead of release-please manifest The release-please manifest holds the *next* stable target rather than the actually-installed/built version, so reads were stale for nightly and stable releases. Read from the stdlib `package.json` (which release tooling stamps at publish time) and substitute `DEV_VERSION` ('dev') for the `0.1.0` placeholder used in monorepo checkouts. Also narrows the return type from `string | undefined` to `string` and drops the now-dead `?? ''` chains in callers. `warnIfAztecVersionMismatch` gets an early return on `DEV_VERSION` so monorepo checkouts no longer warn on every aztec-nr dep. --- .../aztec-node/src/aztec-node/server.test.ts | 20 ++++------- .../aztec-node/src/aztec-node/server.ts | 2 +- yarn-project/aztec/src/bin/index.ts | 2 +- .../aztec/src/cli/aztec_start_action.ts | 2 +- .../warn_if_aztec_version_mismatch.test.ts | 13 ++++--- .../utils/warn_if_aztec_version_mismatch.ts | 5 ++- yarn-project/aztec/src/cli/util.ts | 2 +- yarn-project/cli-wallet/src/bin/index.ts | 2 +- .../src/update-checker/package_version.ts | 34 ++++++------------- yarn-project/txe/src/state_machine/index.ts | 2 +- 10 files changed, 34 insertions(+), 50 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.test.ts b/yarn-project/aztec-node/src/aztec-node/server.test.ts index 9df49ffbe54f..b778dc1d60e9 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.test.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.test.ts @@ -43,11 +43,10 @@ import { getPackageVersion } from '@aztec/stdlib/update-checker'; import type { ValidatorClient } from '@aztec/validator-client'; import { jest } from '@jest/globals'; -import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs'; +import { mkdtempSync, rmSync, writeFileSync } from 'fs'; import { type MockProxy, mock } from 'jest-mock-extended'; import { tmpdir } from 'os'; -import { dirname, join, resolve } from 'path'; -import { fileURLToPath } from 'url'; +import { join } from 'path'; import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; import { blockResponseFromL2Block } from './block_response_helpers.js'; @@ -203,7 +202,7 @@ describe('aztec node', () => { globalVariablesBuilder, feeProvider, epochCache, - getPackageVersion() ?? '', + getPackageVersion(), new TestCircuitVerifier(), new TestCircuitVerifier(), ); @@ -332,13 +331,8 @@ describe('aztec node', () => { describe('node info', () => { it('returns the correct node version', async () => { - const releasePleaseVersionFile = readFileSync( - resolve(dirname(fileURLToPath(import.meta.url)), '../../../../.release-please-manifest.json'), - ).toString(); - const releasePleaseVersion = JSON.parse(releasePleaseVersionFile)['.']; - const nodeInfo = await node.getNodeInfo(); - expect(nodeInfo.nodeVersion).toBe(releasePleaseVersion); + expect(nodeInfo.nodeVersion).toBe(getPackageVersion()); }); }); @@ -756,7 +750,7 @@ describe('aztec node', () => { globalVariablesBuilder, feeProvider, epochCache, - getPackageVersion() ?? '', + getPackageVersion(), new TestCircuitVerifier(), new TestCircuitVerifier(), undefined, @@ -947,7 +941,7 @@ describe('aztec node', () => { globalVariablesBuilder, feeProvider, epochCache, - getPackageVersion() ?? '', + getPackageVersion(), new TestCircuitVerifier(), new TestCircuitVerifier(), undefined, @@ -1019,7 +1013,7 @@ describe('aztec node', () => { globalVariablesBuilder, mock(), epochCache, - getPackageVersion() ?? '', + getPackageVersion(), new TestCircuitVerifier(), new TestCircuitVerifier(), ); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index a48a5dcd9bbf..3c5d9c6cc74f 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -508,7 +508,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb ): Promise { const config = { ...inputConfig }; // Copy the config so we dont mutate the input object const log = deps.logger ?? createLogger('node'); - const packageVersion = getPackageVersion() ?? ''; + const packageVersion = getPackageVersion(); const telemetry = deps.telemetry ?? getTelemetryClient(); const dateProvider = deps.dateProvider ?? new DateProvider(); const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId); diff --git a/yarn-project/aztec/src/bin/index.ts b/yarn-project/aztec/src/bin/index.ts index 55d55831457d..a47a27bf2f34 100644 --- a/yarn-project/aztec/src/bin/index.ts +++ b/yarn-project/aztec/src/bin/index.ts @@ -47,7 +47,7 @@ async function main() { await enrichEnvironmentWithNetworkConfig(networkName); enrichEnvironmentWithChainName(networkName); - const cliVersion = getPackageVersion() ?? 'unknown'; + const cliVersion = getPackageVersion(); let program = new Command('aztec'); program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions(); program = injectAztecCommands(program, userLog, debugLogger); diff --git a/yarn-project/aztec/src/cli/aztec_start_action.ts b/yarn-project/aztec/src/cli/aztec_start_action.ts index bc46c50af937..6149d8757626 100644 --- a/yarn-project/aztec/src/cli/aztec_start_action.ts +++ b/yarn-project/aztec/src/cli/aztec_start_action.ts @@ -29,7 +29,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg if (options.localNetwork) { const localNetwork = extractNamespacedOptions(options, 'localNetwork'); userLog(`${splash}\n${github}\n\n`); - userLog(`Setting up Aztec local network ${packageVersion ?? 'unknown'}, please stand by...`); + userLog(`Setting up Aztec local network ${packageVersion}, please stand by...`); const { node, stop } = await createLocalNetwork( { diff --git a/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.test.ts b/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.test.ts index 544e201bfc0d..5a336ccdb0ee 100644 --- a/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.test.ts +++ b/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.test.ts @@ -1,3 +1,5 @@ +import { DEV_VERSION } from '@aztec/stdlib/update-checker'; + import { afterEach, beforeEach, describe, expect, it } from '@jest/globals'; import { mkdir, rm, writeFile } from 'fs/promises'; import { tmpdir } from 'os'; @@ -136,13 +138,14 @@ describe('warnIfAztecVersionMismatch', () => { expect(logMessages.filter(m => m.includes('WARNING'))).toHaveLength(0); }); - it('warns when the CLI version is not available', async () => { - await makePackage(tempDir, 'project', 'contract'); + it('skips the check when running from a monorepo checkout', async () => { + await makePackage(tempDir, 'project', 'contract', { + aztec: '{ git = "https://github.com/AztecProtocol/aztec-nr", tag = "v1.2.3", directory = "aztec" }', + }); - await warnIfAztecVersionMismatch(log, ''); + await warnIfAztecVersionMismatch(log, DEV_VERSION); - expect(logMessages).toHaveLength(1); - expect(logMessages[0]).toContain('CLI version not found'); + expect(logMessages).toHaveLength(0); }); it('does not warn when the project has no aztec dependency', async () => { diff --git a/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts b/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts index 3cedfa39a660..7c0e2a1f664c 100644 --- a/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +++ b/yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts @@ -1,5 +1,5 @@ import type { LogFn } from '@aztec/foundation/log'; -import { getPackageVersion } from '@aztec/stdlib/update-checker'; +import { DEV_VERSION, getPackageVersion } from '@aztec/stdlib/update-checker'; import TOML from '@iarna/toml'; import { readFile } from 'fs/promises'; @@ -28,8 +28,7 @@ function isAztecNrGitUrl(gitUrl: string): boolean { /** Warns if any aztec-nr git dependency in a crate's Nargo.toml has a tag that doesn't match the CLI version. */ export async function warnIfAztecVersionMismatch(log: LogFn, cliVersion?: string): Promise { const version = cliVersion ?? getPackageVersion(); - if (!version) { - log(`WARNING: aztec CLI version not found. Skipping dependency compatibility check.`); + if (version === DEV_VERSION) { return; } diff --git a/yarn-project/aztec/src/cli/util.ts b/yarn-project/aztec/src/cli/util.ts index 1a908ab6c93a..06d91a711ae2 100644 --- a/yarn-project/aztec/src/cli/util.ts +++ b/yarn-project/aztec/src/cli/util.ts @@ -311,7 +311,7 @@ export async function setupVersionChecker( const checks: Array = []; checks.push({ name: 'node', - currentVersion: getPackageVersion() ?? 'unknown', + currentVersion: getPackageVersion(), getLatestVersion: async () => { const cfg = await getNetworkConfig(network, cacheDir); return cfg?.nodeVersion; diff --git a/yarn-project/cli-wallet/src/bin/index.ts b/yarn-project/cli-wallet/src/bin/index.ts index 1334ad2e1c72..bef096bcb357 100644 --- a/yarn-project/cli-wallet/src/bin/index.ts +++ b/yarn-project/cli-wallet/src/bin/index.ts @@ -73,7 +73,7 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) { /** CLI wallet main entrypoint */ async function main() { - const walletVersion = getPackageVersion() ?? '0.0.0'; + const walletVersion = getPackageVersion(); const db = WalletDB.getInstance(); const walletAndNodeWrapper = new CliWalletAndNodeWrapper(); diff --git a/yarn-project/stdlib/src/update-checker/package_version.ts b/yarn-project/stdlib/src/update-checker/package_version.ts index 30a3b1d816f4..f77189be607a 100644 --- a/yarn-project/stdlib/src/update-checker/package_version.ts +++ b/yarn-project/stdlib/src/update-checker/package_version.ts @@ -3,28 +3,16 @@ import { fileURLToPath } from '@aztec/foundation/url'; import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; -/** Returns the package version from the release-please manifest or the package.json, or undefined if not found. */ -export function getPackageVersion(): string | undefined { - const dir = dirname(fileURLToPath(import.meta.url)); - - // Try the release-please manifest first (works in dev/repo checkout). - try { - const releasePleaseManifestPath = resolve(dir, '../../../../.release-please-manifest.json'); - return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.']; - } catch { - // Not in a repo checkout, fall through. - } +/** Placeholder version returned when running from a local monorepo checkout rather than an npm-installed package. */ +export const DEV_VERSION = 'dev'; - // Fall back to the stdlib package.json version (works in npm-installed packages). - try { - const packageJsonPath = resolve(dir, '../../package.json'); - const version = JSON.parse(readFileSync(packageJsonPath).toString()).version; - if (version && version !== '0.1.0') { - return version; - } - } catch { - // No package.json found either. - } - - return undefined; +/** + * Returns the package version from the stdlib `package.json`, or `DEV_VERSION` when the version is the `0.1.0` + * placeholder (which indicates a local monorepo checkout rather than an npm-installed package). + */ +export function getPackageVersion(): 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; } diff --git a/yarn-project/txe/src/state_machine/index.ts b/yarn-project/txe/src/state_machine/index.ts index 2d48c09b8f53..ec00644c007e 100644 --- a/yarn-project/txe/src/state_machine/index.ts +++ b/yarn-project/txe/src/state_machine/index.ts @@ -59,7 +59,7 @@ export class TXEStateMachine { new TXEGlobalVariablesBuilder(), new TXEFeeProvider(), new MockEpochCache(), - getPackageVersion() ?? '', + getPackageVersion(), new TestCircuitVerifier(), new TestCircuitVerifier(), undefined,