Skip to content
Merged
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
25 changes: 19 additions & 6 deletions yarn-project/stdlib/src/update-checker/package_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ 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 undefined if not found. */
/** 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(
dirname(fileURLToPath(import.meta.url)),
'../../../../.release-please-manifest.json',
);
const releasePleaseManifestPath = resolve(dir, '../../../../.release-please-manifest.json');
return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
} catch {
return undefined;
// Not in a repo checkout, fall through.
}

// 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;
}
Loading