Skip to content

Commit c5ebbe0

Browse files
benesjanaztec-bot
authored andcommitted
refactor: getPackageVersion fn cleanup (#22941)
[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
1 parent 562d5e3 commit c5ebbe0

10 files changed

Lines changed: 34 additions & 50 deletions

File tree

yarn-project/aztec-node/src/aztec-node/server.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ import { getPackageVersion } from '@aztec/stdlib/update-checker';
4242
import type { ValidatorClient } from '@aztec/validator-client';
4343

4444
import { jest } from '@jest/globals';
45-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
45+
import { mkdtempSync, rmSync, writeFileSync } from 'fs';
4646
import { type MockProxy, mock } from 'jest-mock-extended';
4747
import { tmpdir } from 'os';
48-
import { dirname, join, resolve } from 'path';
49-
import { fileURLToPath } from 'url';
48+
import { join } from 'path';
5049
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
5150

5251
import { type AztecNodeConfig, getConfigEnvVars } from './config.js';
@@ -197,7 +196,7 @@ describe('aztec node', () => {
197196
rollupVersion.toNumber(),
198197
globalVariablesBuilder,
199198
epochCache,
200-
getPackageVersion() ?? '',
199+
getPackageVersion(),
201200
new TestCircuitVerifier(),
202201
);
203202
});
@@ -319,13 +318,8 @@ describe('aztec node', () => {
319318

320319
describe('node info', () => {
321320
it('returns the correct node version', async () => {
322-
const releasePleaseVersionFile = readFileSync(
323-
resolve(dirname(fileURLToPath(import.meta.url)), '../../../../.release-please-manifest.json'),
324-
).toString();
325-
const releasePleaseVersion = JSON.parse(releasePleaseVersionFile)['.'];
326-
327321
const nodeInfo = await node.getNodeInfo();
328-
expect(nodeInfo.nodeVersion).toBe(releasePleaseVersion);
322+
expect(nodeInfo.nodeVersion).toBe(getPackageVersion());
329323
});
330324
});
331325

@@ -731,7 +725,7 @@ describe('aztec node', () => {
731725
rollupVersion.toNumber(),
732726
globalVariablesBuilder,
733727
epochCache,
734-
getPackageVersion() ?? '',
728+
getPackageVersion(),
735729
new TestCircuitVerifier(),
736730
undefined,
737731
undefined,
@@ -919,7 +913,7 @@ describe('aztec node', () => {
919913
rollupVersion.toNumber(),
920914
globalVariablesBuilder,
921915
epochCache,
922-
getPackageVersion() ?? '',
916+
getPackageVersion(),
923917
new TestCircuitVerifier(),
924918
undefined,
925919
undefined,
@@ -988,7 +982,7 @@ describe('aztec node', () => {
988982
rollupVersion.toNumber(),
989983
globalVariablesBuilder,
990984
epochCache,
991-
getPackageVersion() ?? '',
985+
getPackageVersion(),
992986
new TestCircuitVerifier(),
993987
);
994988
});

yarn-project/aztec-node/src/aztec-node/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
208208
): Promise<AztecNodeService> {
209209
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
210210
const log = deps.logger ?? createLogger('node');
211-
const packageVersion = getPackageVersion() ?? '';
211+
const packageVersion = getPackageVersion();
212212
const telemetry = deps.telemetry ?? getTelemetryClient();
213213
const dateProvider = deps.dateProvider ?? new DateProvider();
214214
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);

yarn-project/aztec/src/bin/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function main() {
4747
await enrichEnvironmentWithNetworkConfig(networkName);
4848
enrichEnvironmentWithChainName(networkName);
4949

50-
const cliVersion = getPackageVersion() ?? 'unknown';
50+
const cliVersion = getPackageVersion();
5151
let program = new Command('aztec');
5252
program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
5353
program = injectAztecCommands(program, userLog, debugLogger);

yarn-project/aztec/src/cli/aztec_start_action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
2929
if (options.localNetwork) {
3030
const localNetwork = extractNamespacedOptions(options, 'localNetwork');
3131
userLog(`${splash}\n${github}\n\n`);
32-
userLog(`Setting up Aztec local network ${packageVersion ?? 'unknown'}, please stand by...`);
32+
userLog(`Setting up Aztec local network ${packageVersion}, please stand by...`);
3333

3434
const { node, stop } = await createLocalNetwork(
3535
{

yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DEV_VERSION } from '@aztec/stdlib/update-checker';
2+
13
import { afterEach, beforeEach, describe, expect, it } from '@jest/globals';
24
import { mkdir, rm, writeFile } from 'fs/promises';
35
import { tmpdir } from 'os';
@@ -136,13 +138,14 @@ describe('warnIfAztecVersionMismatch', () => {
136138
expect(logMessages.filter(m => m.includes('WARNING'))).toHaveLength(0);
137139
});
138140

139-
it('warns when the CLI version is not available', async () => {
140-
await makePackage(tempDir, 'project', 'contract');
141+
it('skips the check when running from a monorepo checkout', async () => {
142+
await makePackage(tempDir, 'project', 'contract', {
143+
aztec: '{ git = "https://github.com/AztecProtocol/aztec-nr", tag = "v1.2.3", directory = "aztec" }',
144+
});
141145

142-
await warnIfAztecVersionMismatch(log, '');
146+
await warnIfAztecVersionMismatch(log, DEV_VERSION);
143147

144-
expect(logMessages).toHaveLength(1);
145-
expect(logMessages[0]).toContain('CLI version not found');
148+
expect(logMessages).toHaveLength(0);
146149
});
147150

148151
it('does not warn when the project has no aztec dependency', async () => {

yarn-project/aztec/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LogFn } from '@aztec/foundation/log';
2-
import { getPackageVersion } from '@aztec/stdlib/update-checker';
2+
import { DEV_VERSION, getPackageVersion } from '@aztec/stdlib/update-checker';
33

44
import TOML from '@iarna/toml';
55
import { readFile } from 'fs/promises';
@@ -28,8 +28,7 @@ function isAztecNrGitUrl(gitUrl: string): boolean {
2828
/** Warns if any aztec-nr git dependency in a crate's Nargo.toml has a tag that doesn't match the CLI version. */
2929
export async function warnIfAztecVersionMismatch(log: LogFn, cliVersion?: string): Promise<void> {
3030
const version = cliVersion ?? getPackageVersion();
31-
if (!version) {
32-
log(`WARNING: aztec CLI version not found. Skipping dependency compatibility check.`);
31+
if (version === DEV_VERSION) {
3332
return;
3433
}
3534

yarn-project/aztec/src/cli/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export async function setupVersionChecker(
311311
const checks: Array<VersionCheck> = [];
312312
checks.push({
313313
name: 'node',
314-
currentVersion: getPackageVersion() ?? 'unknown',
314+
currentVersion: getPackageVersion(),
315315
getLatestVersion: async () => {
316316
const cfg = await getNetworkConfig(network, cacheDir);
317317
return cfg?.nodeVersion;

yarn-project/cli-wallet/src/bin/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function injectInternalCommands(program: Command, log: LogFn, db: WalletDB) {
7373

7474
/** CLI wallet main entrypoint */
7575
async function main() {
76-
const walletVersion = getPackageVersion() ?? '0.0.0';
76+
const walletVersion = getPackageVersion();
7777

7878
const db = WalletDB.getInstance();
7979
const walletAndNodeWrapper = new CliWalletAndNodeWrapper();

yarn-project/stdlib/src/update-checker/package_version.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,16 @@ import { fileURLToPath } from '@aztec/foundation/url';
33
import { readFileSync } from 'fs';
44
import { dirname, resolve } from 'path';
55

6-
/** Returns the package version from the release-please manifest or the package.json, or undefined if not found. */
7-
export function getPackageVersion(): string | undefined {
8-
const dir = dirname(fileURLToPath(import.meta.url));
9-
10-
// Try the release-please manifest first (works in dev/repo checkout).
11-
try {
12-
const releasePleaseManifestPath = resolve(dir, '../../../../.release-please-manifest.json');
13-
return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
14-
} catch {
15-
// Not in a repo checkout, fall through.
16-
}
6+
/** Placeholder version returned when running from a local monorepo checkout rather than an npm-installed package. */
7+
export const DEV_VERSION = 'dev';
178

18-
// Fall back to the stdlib package.json version (works in npm-installed packages).
19-
try {
20-
const packageJsonPath = resolve(dir, '../../package.json');
21-
const version = JSON.parse(readFileSync(packageJsonPath).toString()).version;
22-
if (version && version !== '0.1.0') {
23-
return version;
24-
}
25-
} catch {
26-
// No package.json found either.
27-
}
28-
29-
return undefined;
9+
/**
10+
* Returns the package version from the stdlib `package.json`, or `DEV_VERSION` when the version is the `0.1.0`
11+
* placeholder (which indicates a local monorepo checkout rather than an npm-installed package).
12+
*/
13+
export function getPackageVersion(): string {
14+
const dir = dirname(fileURLToPath(import.meta.url));
15+
const packageJsonPath = resolve(dir, '../../package.json');
16+
const version = JSON.parse(readFileSync(packageJsonPath).toString()).version;
17+
return version === '0.1.0' ? DEV_VERSION : version;
3018
}

yarn-project/txe/src/state_machine/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class TXEStateMachine {
5757
CHAIN_ID,
5858
new TXEGlobalVariablesBuilder(),
5959
new MockEpochCache(),
60-
getPackageVersion() ?? '',
60+
getPackageVersion(),
6161
new TestCircuitVerifier(),
6262
undefined,
6363
log,

0 commit comments

Comments
 (0)