From 28c3d40d65eef63f9d6ccb60b99ac57f5057a46e Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 18 Feb 2020 12:01:59 -0800 Subject: [PATCH] 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 --- lib/utils/unsupported.js | 23 +++++------------------ package.json | 5 ++++- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/utils/unsupported.js b/lib/utils/unsupported.js index 8e0d729b307fd..b0cda8a86f32e 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/') } } diff --git a/package.json b/package.json index 3c37420f4c5ec..8997cd16071a5 100644 --- a/package.json +++ b/package.json @@ -307,5 +307,8 @@ "test-tap": "npm run tap -- \"test/tap/*.js\" \"test/network/*.js\"", "test-node": "tap --timeout 240 \"test/tap/*.js\" \"test/network/*.js\"" }, - "license": "Artistic-2.0" + "license": "Artistic-2.0", + "engines": { + "node": "6 >=6.2.0 || 8 || >=9.3.0" + } }