Skip to content

Commit f819f38

Browse files
AztecBotaztec-bot
authored andcommitted
fix: fall back to package.json for CLI version detection (#21382)
## 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
1 parent 28a6ca7 commit f819f38

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@ 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 undefined if not found. */
6+
/** Returns the package version from the release-please manifest or the package.json, or undefined if not found. */
77
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).
811
try {
9-
const releasePleaseManifestPath = resolve(
10-
dirname(fileURLToPath(import.meta.url)),
11-
'../../../../.release-please-manifest.json',
12-
);
12+
const releasePleaseManifestPath = resolve(dir, '../../../../.release-please-manifest.json');
1313
return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
1414
} catch {
15-
return undefined;
15+
// Not in a repo checkout, fall through.
16+
}
17+
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.
1627
}
28+
29+
return undefined;
1730
}

0 commit comments

Comments
 (0)