Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions yarn-project/aztec-node/src/aztec-node/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -203,7 +202,7 @@ describe('aztec node', () => {
globalVariablesBuilder,
feeProvider,
epochCache,
getPackageVersion() ?? '',
getPackageVersion(),
new TestCircuitVerifier(),
new TestCircuitVerifier(),
);
Expand Down Expand Up @@ -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());
});
});

Expand Down Expand Up @@ -756,7 +750,7 @@ describe('aztec node', () => {
globalVariablesBuilder,
feeProvider,
epochCache,
getPackageVersion() ?? '',
getPackageVersion(),
new TestCircuitVerifier(),
new TestCircuitVerifier(),
undefined,
Expand Down Expand Up @@ -947,7 +941,7 @@ describe('aztec node', () => {
globalVariablesBuilder,
feeProvider,
epochCache,
getPackageVersion() ?? '',
getPackageVersion(),
new TestCircuitVerifier(),
new TestCircuitVerifier(),
undefined,
Expand Down Expand Up @@ -1019,7 +1013,7 @@ describe('aztec node', () => {
globalVariablesBuilder,
mock<FeeProvider>(),
epochCache,
getPackageVersion() ?? '',
getPackageVersion(),
new TestCircuitVerifier(),
new TestCircuitVerifier(),
);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
): Promise<AztecNodeService> {
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);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/aztec_start_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<void> {
const version = cliVersion ?? getPackageVersion();
if (!version) {
log(`WARNING: aztec CLI version not found. Skipping dependency compatibility check.`);
if (version === DEV_VERSION) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/cli/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export async function setupVersionChecker(
const checks: Array<VersionCheck> = [];
checks.push({
name: 'node',
currentVersion: getPackageVersion() ?? 'unknown',
currentVersion: getPackageVersion(),
getLatestVersion: async () => {
const cfg = await getNetworkConfig(network, cacheDir);
return cfg?.nodeVersion;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli-wallet/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
34 changes: 11 additions & 23 deletions yarn-project/stdlib/src/update-checker/package_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion yarn-project/txe/src/state_machine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class TXEStateMachine {
new TXEGlobalVariablesBuilder(),
new TXEFeeProvider(),
new MockEpochCache(),
getPackageVersion() ?? '',
getPackageVersion(),
new TestCircuitVerifier(),
new TestCircuitVerifier(),
undefined,
Expand Down
Loading