diff options
author | isaacs <i@izs.me> | 2020-02-18 23:01:59 +0300 |
---|---|---|
committer | Darcy Clarke <darcy@darcyclarke.me> | 2020-02-25 20:30:17 +0300 |
commit | 28c3d40d65eef63f9d6ccb60b99ac57f5057a46e (patch) | |
tree | 4cc9155f962511d32cb615e9918cdeb6e54f67c0 /lib | |
parent | 0769c5b200fe27d9dfb77db097f0c8b71e166893 (diff) |
Use a package.json engines field to specify support
That is what the `engines` in package.json is for, after all.
PR-URL: https://github.com/npm/cli/pull/945
Credit: @isaacs
Close: #945
Reviewed-by: @darcyclarke
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/unsupported.js | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/lib/utils/unsupported.js b/lib/utils/unsupported.js index 8e0d729b3..b0cda8a86 100644 --- a/lib/utils/unsupported.js +++ b/lib/utils/unsupported.js @@ -1,25 +1,14 @@ 'use strict' var semver = require('semver') -var earliestSupportedNode = '9.3.0' -var supportedNode = [ - {ver: '6', min: '6.0.0'}, - {ver: '8', min: '8.0.0'}, - {ver: '9', min: '9.0.0'}, - {ver: '10', min: '10.0.0'}, - {ver: '11', min: '11.0.0'}, - {ver: '12', min: '12.0.0'}, - {ver: '13', min: '13.0.0'}, - {ver: '14', min: '14.0.0'} -] -var knownBroken = '<6.2.0 || 9.0 - 9.2' +var supported = require('../../package.json').engines.node +var knownBroken = '<6.2.0 || 9 <9.3.0' var checkVersion = exports.checkVersion = function (version) { var versionNoPrerelease = version.replace(/-.*$/, '') - var isExplicitlySupportedNode = semver.satisfies(versionNoPrerelease, supportedNode.map(function (n) { return '^' + n.min }).join('||')) return { version: versionNoPrerelease, broken: semver.satisfies(versionNoPrerelease, knownBroken), - unsupported: !isExplicitlySupportedNode || !semver.gte(versionNoPrerelease, earliestSupportedNode) + unsupported: !semver.satisfies(versionNoPrerelease, supported) } } @@ -36,9 +25,8 @@ exports.checkForBrokenNode = function () { } }) var supportedMajors = supportedNode.map(function (n) { return n.ver }).join(', ') - console.error("You'll need to upgrade to a newer version in order to use this") - console.error('version of npm. Supported versions are ' + supportedMajors + '. You can find the') - console.error('latest version at https://nodejs.org/') + 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) } } @@ -51,7 +39,6 @@ exports.checkForUnsupportedNode = function () { log.warn('npm', 'npm does not support Node.js ' + process.version) log.warn('npm', 'You should probably upgrade to a newer version of node as we') log.warn('npm', "can't make any promises that npm will work with this version.") - log.warn('npm', 'Supported releases of Node.js are the latest release of ' + supportedMajors + '.') log.warn('npm', 'You can find the latest version at https://nodejs.org/') } } |