sindresorhus / meow

šŸˆ CLI app helper
MIT License
3.53k stars 150 forks source link

Expose package.json version as property #224

Closed joeykilpatrick closed 1 year ago

joeykilpatrick commented 1 year ago

Would be nice if there was access to the package version like so:

const cli = meow(`
    ...
`, {
    importMeta: import.meta,
});

const version: string = cli.version;

I know cli.showVersion() is available, but it prints the string instead of returning it. Without this feature, the package.json must be parsed separately, which this package is already doing internally.

Alternatively, this package could expose the entire parsed package.json.

Would be more than happy to submit a PR.

sindresorhus commented 1 year ago

This is already available: cli.pkg

tommy-mitchell commented 1 year ago

@sindresorhus I think it could be worth adding something like a cli.pkgVersion. Thereā€™s been a few discussions about moving away from read-pkg-up or lazy parsing package.json when cli.pkg is first accessed for performance; having a quick access for the version number could be beneficial.

sindresorhus commented 1 year ago

How is cli.pkgVersion better than just cli.pkg.version when cli.pkg is lazy?

tommy-mitchell commented 1 year ago

Youā€™re right, didnā€™t fully consider that.