ohmjs / ohm

A library and language for building parsers, interpreters, compilers, etc.
MIT License
5.01k stars 217 forks source link

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

Open andysturrock opened 1 year ago

andysturrock commented 1 year ago

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.

pdubroy commented 1 year ago

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));
andysturrock commented 1 year ago

Yep that makes more sense.

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