Skip to content

Commit b819b71

Browse files
authored
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 4520681 commit b819b71

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
@@ -43,11 +43,10 @@ import { getPackageVersion } from '@aztec/stdlib/update-checker';
4343
import type { ValidatorClient } from '@aztec/validator-client';
4444

4545
import { jest } from '@jest/globals';
46-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
46+
import { mkdtempSync, rmSync, writeFileSync } from 'fs';
4747
import { type MockProxy, mock } from 'jest-mock-extended';
4848
import { tmpdir } from 'os';
49-
import { dirname, join, resolve } from 'path';
50-
import { fileURLToPath } from 'url';
49+
import { join } from 'path';
5150
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
5251

5352
import { blockResponseFromL2Block } from './block_response_helpers.js';
@@ -203,7 +202,7 @@ describe('aztec node', () => {
203202
globalVariablesBuilder,
204203
feeProvider,
205204
epochCache,
206-
getPackageVersion() ?? '',
205+
getPackageVersion(),
207206
new TestCircuitVerifier(),
208207
new TestCircuitVerifier(),
209208
);
@@ -332,13 +331,8 @@ describe('aztec node', () => {
332331

333332
describe('node info', () => {
334333
it('returns the correct node version', async () => {
335-
const releasePleaseVersionFile = readFileSync(
336-
resolve(dirname(fileURLToPath(import.meta.url)), '../../../../.release-please-manifest.json'),
337-
).toString();
338-
const releasePleaseVersion = JSON.parse(releasePleaseVersionFile)['.'];
339-
340334
const nodeInfo = await node.getNodeInfo();
341-
expect(nodeInfo.nodeVersion).toBe(releasePleaseVersion);
335+
expect(nodeInfo.nodeVersion).toBe(getPackageVersion());
342336
});
343337
});
344338

@@ -756,7 +750,7 @@ describe('aztec node', () => {
756750
globalVariablesBuilder,
757751
feeProvider,
758752
epochCache,
759-
getPackageVersion() ?? '',
753+
getPackageVersion(),
760754
new TestCircuitVerifier(),
761755
new TestCircuitVerifier(),
762756
undefined,
@@ -947,7 +941,7 @@ describe('aztec node', () => {
947941
globalVariablesBuilder,
948942
feeProvider,
949943
epochCache,
950-
getPackageVersion() ?? '',
944+
getPackageVersion(),
951945
new TestCircuitVerifier(),
952946
new TestCircuitVerifier(),
953947
undefined,
@@ -1019,7 +1013,7 @@ describe('aztec node', () => {
10191013
globalVariablesBuilder,
10201014
mock<FeeProvider>(),
10211015
epochCache,
1022-
getPackageVersion() ?? '',
1016+
getPackageVersion(),
10231017
new TestCircuitVerifier(),
10241018
new TestCircuitVerifier(),
10251019
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
508508
): Promise<AztecNodeService> {
509509
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
510510
const log = deps.logger ?? createLogger('node');
511-
const packageVersion = getPackageVersion() ?? '';
511+
const packageVersion = getPackageVersion();
512512
const telemetry = deps.telemetry ?? getTelemetryClient();
513513
const dateProvider = deps.dateProvider ?? new DateProvider();
514514
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
@@ -59,7 +59,7 @@ export class TXEStateMachine {
5959
new TXEGlobalVariablesBuilder(),
6060
new TXEFeeProvider(),
6161
new MockEpochCache(),
62-
getPackageVersion() ?? '',
62+
getPackageVersion(),
6363
new TestCircuitVerifier(),
6464
new TestCircuitVerifier(),
6565
undefined,

0 commit comments

Comments
 (0)