diff options
author | Gar <gar+gh@danger.computer> | 2022-03-24 21:09:41 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2022-03-28 23:21:36 +0300 |
commit | 57d8f75eb864486f6aa17bb3dd2f213b5c148073 (patch) | |
tree | b5ba5d58c0f33534b7f073a32b09d59199b8f1ff /lib/cli.js | |
parent | f76d4f2f661bcc2534f541ee0e7d683155372baf (diff) |
fix: consolidate node version support logic
Diffstat (limited to 'lib/cli.js')
-rw-r--r-- | lib/cli.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/cli.js b/lib/cli.js index 6583bd0c0..f261dae12 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -11,9 +11,25 @@ module.exports = async process => { // so now both broken and unsupported use console, but only broken // will process.exit. It is important to now perform *both* of these // checks as early as possible so the user gets the error message. - const { checkForBrokenNode, checkForUnsupportedNode } = require('./utils/unsupported.js') - checkForBrokenNode() - checkForUnsupportedNode() + const semver = require('semver') + const supported = require('../package.json').engines.node + const knownBroken = '<6.2.0 || 9 <9.3.0' + + const nodejsVersion = process.version.replace(/-.*$/, '') + /* eslint-disable no-console */ + if (semver.satisfies(nodejsVersion, knownBroken)) { + console.error('ERROR: npm is known not to run on Node.js ' + process.version) + console.error("You'll need to upgrade to a newer Node.js version in order to use this") + console.error('version of npm. You can find the latest version at https://nodejs.org/') + process.exit(1) + } + if (!semver.satisfies(nodejsVersion, supported)) { + console.error('npm does not support Node.js ' + process.version) + console.error('You should probably upgrade to a newer version of node as we') + console.error("can't make any promises that npm will work with this version.") + console.error('You can find the latest version at https://nodejs.org/') + } + /* eslint-enable no-console */ const exitHandler = require('./utils/exit-handler.js') process.on('uncaughtException', exitHandler) |