File tree Expand file tree Collapse file tree
yarn-project/stdlib/src/update-checker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,15 +3,28 @@ import { fileURLToPath } from '@aztec/foundation/url';
33import { readFileSync } from 'fs' ;
44import { 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. */
77export 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}
You can’t perform that action at this time.
0 commit comments