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

fix: node version check now uses process.versions.node #450

Merged
merged 7 commits into from Aug 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/index.ts
Expand Up @@ -19,8 +19,9 @@ import { readFileSync } from 'fs'
const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
? Number(process.env.YARGS_MIN_NODE_VERSION)
: 12
if (process && process.version) {
const major = Number(process.version.match(/v([^.]+)/)![1])
const nodeVersion = process && (process.versions ? process.versions.node : process.version.slice(1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do:

const nodeVersion = process?.versions?.node && process.version.slice(1);

To simplify the logic slightly?

Copy link
Contributor Author

@paperdave paperdave Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an || in your snippet, but yes the logic could be simplified. i wasn't sure if i was able to use ?. in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have edited this, but do note that this syntax doesn't work below node v14, though your build process makes sure this gets transpiled down. it should be noted that this syntax isnt used anywhere else in the project yet.

if (nodeVersion) {
const major = Number(nodeVersion.match(/^([^.]+)/)![1])
if (major < minNodeVersion) {
throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`)
}
Expand Down