Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andysturrock opened this issue Jul 21, 2023 · 2 comments
Open

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

andysturrock opened this issue Jul 21, 2023 · 2 comments

Comments

@andysturrock
Copy link
Contributor

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
Copy link
Contributor

pdubroy commented Aug 1, 2023

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 added a commit to andysturrock/ohm that referenced this issue Aug 11, 2023
From ohmjs#456

Parse ohm's package.json file to obtain the version.
cli.js was parsing the package.json in the current directory to obtain
the package version.
It now parses its own package.json file, not the one from the
project that is using ohm.
@andysturrock
Copy link
Contributor Author

Yep that makes more sense.

PR #458 created

pdubroy pushed a commit that referenced this issue Aug 16, 2023
From #456

Parse ohm's package.json file to obtain the version.
cli.js was parsing the package.json in the current directory to obtain
the package version.
It now parses its own package.json file, not the one from the
project that is using ohm.

Co-authored-by: Andy Sturrock <andysturrock@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants