From 863937f23c3102f804cdea78ee3097e28c7c289f Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sun, 5 Jul 2020 17:44:06 -0700 Subject: [PATCH] feat!: drop support for EOL Node 8 (#1686) --- .github/release-please.yml | 2 -- .github/workflows/ci.yaml | 2 +- README.md | 6 ++++++ package.json | 2 +- test/yargs.js | 9 +++++++++ yargs.js | 13 ++++++++++--- 6 files changed, 27 insertions(+), 7 deletions(-) delete mode 100644 .github/release-please.yml diff --git a/.github/release-please.yml b/.github/release-please.yml deleted file mode 100644 index 3c0659977..000000000 --- a/.github/release-please.yml +++ /dev/null @@ -1,2 +0,0 @@ -releaseType: node -handleGHRelease: true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 824164644..ab1bd7c89 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [8, 10, 12, 13] + node: [10, 12, 13, 14] steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 diff --git a/README.md b/README.md index 0db992b1a..f73236d0c 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,12 @@ Having problems? want to contribute? join our [community slack](http://devtoolsc * [Customizing Yargs' Parser](/docs/advanced.md#customizing) * [Contributing](/contributing.md) +## 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). + [travis-url]: https://travis-ci.org/yargs/yargs [travis-image]: https://img.shields.io/travis/yargs/yargs/master.svg [npm-url]: https://www.npmjs.com/package/yargs diff --git a/package.json b/package.json index 0e76f0541..c203748db 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,6 @@ ], "license": "MIT", "engines": { - "node": ">=8" + "node": ">=10" } } diff --git a/test/yargs.js b/test/yargs.js index 4d5f1027f..95acc2955 100644 --- a/test/yargs.js +++ b/test/yargs.js @@ -2583,4 +2583,13 @@ describe('yargs dsl tests', () => { argv._.should.eql(['item2', 'item4', 'item6', 'item8']) }) }) + + it('throws error for unsupported Node.js versions', () => { + process.env.YARGS_MIN_NODE_VERSION = '55' + delete require.cache[require.resolve('../yargs')] + expect(() => { + require('../yargs') + }).to.throw(/yargs supports a minimum Node.js version of 55/) + delete process.env.YARGS_MIN_NODE_VERSION + }) }) diff --git a/yargs.js b/yargs.js index 93e8059ef..83fafe3b7 100644 --- a/yargs.js +++ b/yargs.js @@ -1,8 +1,15 @@ 'use strict' -// an async function fails early in Node.js versions prior to 8. -async function requiresNode8OrGreater () {} -requiresNode8OrGreater() +// See https://github.com/yargs/yargs#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 supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs#supported-nodejs-versions`) + } +} const { Yargs, rebase } = require('./build/lib/yargs') const Parser = require('yargs-parser')