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

build!: drops Node 6. begin following Node.js LTS schedule #278

Merged
merged 4 commits into from Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [8, 10, 12, 13]
node: [10, 12, 14]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -439,6 +439,12 @@ node example.js --unknown-option --known-option 2 --string-option --unknown-opti
{ _: ['--unknown-option'], knownOption: 2, stringOption: '--unknown-option2' }
```

## Supported Node.js Versions

Libraries in this ecosystem make a best effort to track
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).

## Special Thanks

The yargs project evolves from optimist and minimist. It owes its
Expand Down
13 changes: 12 additions & 1 deletion index.js
Expand Up @@ -4,6 +4,17 @@ const path = require('path')
const tokenizeArgString = require('./lib/tokenize-arg-string')
const util = require('util')

// See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
// version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
? Number(process.env.YARGS_MIN_NODE_VERSION) : 10
if (process && process.version) {
const major = Number(process.version.match(/v([^.]+)/)[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`)
}
}

function parse (args, opts) {
opts = Object.assign(Object.create(null), opts)
// allow a string argument to be passed in rather
Expand Down Expand Up @@ -626,8 +637,8 @@ function parse (args, opts) {
}

function applyEnvVars (argv, configOnly) {
if (!process) return
if (typeof envPrefix === 'undefined') return

const prefix = typeof envPrefix === 'string' ? envPrefix : ''
Object.keys(process.env).forEach(function (envVar) {
if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,6 +41,6 @@
"index.js"
],
"engines": {
"node": ">=6"
"node": ">=10"
}
}
9 changes: 9 additions & 0 deletions test/yargs-parser.js
Expand Up @@ -3823,4 +3823,13 @@ describe('yargs-parser', function () {
}
})
})

it('throws error for unsupported Node.js versions', () => {
process.env.YARGS_MIN_NODE_VERSION = '55'
delete require.cache[require.resolve('../')]
expect(() => {
require('../')
}).to.throw(/yargs parser supports a minimum Node.js version of 55/)
delete process.env.YARGS_MIN_NODE_VERSION
})
})