@@ -10,15 +10,31 @@ import check from 'check-node-version';
1010import { execSync } from 'child_process' ;
1111import commands from './command/index.js' ;
1212import RC from './rc/index.js' ;
13- import { createRequire } from 'module' ; // Bring in the ability to create the 'require' method
14- const require = createRequire ( import . meta . url ) ; // construct the require method
15- const pkg = require ( '../package.json' ) ;
13+ import { readFileSync } from 'fs' ;
14+ import { fileURLToPath } from 'url' ;
15+ import path from 'path' ;
1616import { logger } from './utils/myLogger.js' ;
1717import { userHomeDir } from './utils/userHomeDir.js' ;
1818
1919const minVersion = '10.9.0' ;
2020
21+ export function getPackageJson ( ) {
22+ let dirname ;
23+ try {
24+ // for test as we cannot use import.meta.url in Jest
25+ dirname = __dirname ;
26+ } catch {
27+ const __filename = fileURLToPath ( import . meta. url ) ;
28+ dirname = path . dirname ( __filename ) ;
29+ }
30+ const filePath = path . resolve ( dirname , '../package.json' ) ;
31+ const data = readFileSync ( filePath , 'utf-8' ) ;
32+ const packageJson = JSON . parse ( data ) ;
33+ return packageJson ;
34+ }
35+
2136function init ( options ) {
37+ const pkg = getPackageJson ( ) ;
2238 const commander = new Command ( ) ;
2339 // Configuration for test
2440 if ( options ?. exitOverride ) {
0 commit comments