ohm icon indicating copy to clipboard operation
ohm copied to clipboard

cli.js is reading incorrect package.json file for version

Open andysturrock opened this issue 1 year ago • 2 comments

Line 6 of cli.js reads the package.json file from the current directory: const {version} = JSON.parse(fs.readFileSync('./package.json')); If that package.json file does not have a version key then npx ohm generateBundles fails with: TypeError: Cannot read properties of undefined (reading 'option') If the local file does have a version then the -v flag will return that, rather than the version of ohmjs.

To get the current version of ohmjs, I think it should be: const {version} = JSON.parse(fs.readFileSync('./node_modules/@ohm-js/cli/package.json'));

If you agree I am happy to submit a PR.

andysturrock avatar Jul 21 '23 10:07 andysturrock

Thanks for the bug report! I think a more appropriate fix would be to use a module-relative URL...e.g. something like:

fs.readFileSync(new URL('../package.json', import.meta.url));

pdubroy avatar Aug 01 '23 10:08 pdubroy

Yep that makes more sense.

PR https://github.com/ohmjs/ohm/pull/458 created

andysturrock avatar Aug 11 '23 10:08 andysturrock