E.g.
program.version(JSON.parse(require('fs').readFileSync(
require.main.filename.match(/^(.+)\/.+$/)[1] + '/../package.json')).version)
But a test is needed for the existence of package.json, I think the 2 most used locations are
So 1, check for main_module_dir/package.json and 2, check for main_module_dir/../package.json.
Agreed, I'd love this.
+1
just realized this is implemented wrong, you'll get commander's version every time
your require() is always relative to commander's ./lib
For others finding this issue: you know where the package.json is in your project, so you can just do:
program
.version(require('./package.json').version)
Most helpful comment
For others finding this issue: you know where the package.json is in your project, so you can just do: