@@ -5,21 +5,31 @@ import type { PackageJson } from 'nx/src/utils/package-json';
55const workspaceRoot = path . join ( __dirname , '../../' ) ;
66const projectsFolder = path . join ( __dirname , '../../../' ) ;
77
8- export const cpNxPluginVersion = loadPackageJson ( workspaceRoot ) . version ;
9- export const cpModelVersion = loadPackageJson (
8+ export const cpNxPluginVersion = readDependencyVersion ( workspaceRoot ) ;
9+ export const cpModelVersion = readDependencyVersion (
1010 path . join ( projectsFolder , 'cli' ) ,
11- ) . version ;
12- export const cpUtilsVersion = loadPackageJson (
11+ ) ;
12+ export const cpUtilsVersion = readDependencyVersion (
1313 path . join ( projectsFolder , 'utils' ) ,
14- ) . version ;
15- export const cpCliVersion = loadPackageJson (
14+ ) ;
15+ export const cpCliVersion = readDependencyVersion (
1616 path . join ( projectsFolder , 'models' ) ,
17- ) . version ;
17+ ) ;
1818
1919/**
20- * Load the package.json file from the given folder path.
21- * @param folderPath
20+ * Load the package.json file from the given folder path and returns the package version .
21+ * If the version is not given of the package.json file does not exist it returns the fallback value.
2222 */
23- function loadPackageJson ( folderPath : string ) : PackageJson {
24- return readJsonFile < PackageJson > ( path . join ( folderPath , 'package.json' ) ) ;
23+ function readDependencyVersion (
24+ folderPath : string ,
25+ fallbackVersion = 'latest' ,
26+ ) : string {
27+ try {
28+ return (
29+ readJsonFile < PackageJson > ( path . join ( folderPath , 'package.json' ) )
30+ . version ?? fallbackVersion
31+ ) ;
32+ } catch {
33+ return fallbackVersion ;
34+ }
2535}
0 commit comments