Skip to content

Commit 28c3d40

Browse files
isaacsdarcyclarke
authored andcommitted
Use a package.json engines field to specify support
That is what the `engines` in package.json is for, after all. PR-URL: #945 Credit: @isaacs Close: #945 Reviewed-by: @darcyclarke
1 parent 0769c5b commit 28c3d40

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

lib/utils/unsupported.js

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
'use strict'
22
var semver = require('semver')
3-
var earliestSupportedNode = '9.3.0'
4-
var supportedNode = [
5-
{ver: '6', min: '6.0.0'},
6-
{ver: '8', min: '8.0.0'},
7-
{ver: '9', min: '9.0.0'},
8-
{ver: '10', min: '10.0.0'},
9-
{ver: '11', min: '11.0.0'},
10-
{ver: '12', min: '12.0.0'},
11-
{ver: '13', min: '13.0.0'},
12-
{ver: '14', min: '14.0.0'}
13-
]
14-
var knownBroken = '<6.2.0 || 9.0 - 9.2'
3+
var supported = require('../../package.json').engines.node
4+
var knownBroken = '<6.2.0 || 9 <9.3.0'
155

166
var checkVersion = exports.checkVersion = function (version) {
177
var versionNoPrerelease = version.replace(/-.*$/, '')
18-
var isExplicitlySupportedNode = semver.satisfies(versionNoPrerelease, supportedNode.map(function (n) { return '^' + n.min }).join('||'))
198
return {
209
version: versionNoPrerelease,
2110
broken: semver.satisfies(versionNoPrerelease, knownBroken),
22-
unsupported: !isExplicitlySupportedNode || !semver.gte(versionNoPrerelease, earliestSupportedNode)
11+
unsupported: !semver.satisfies(versionNoPrerelease, supported)
2312
}
2413
}
2514

@@ -36,9 +25,8 @@ exports.checkForBrokenNode = function () {
3625
}
3726
})
3827
var supportedMajors = supportedNode.map(function (n) { return n.ver }).join(', ')
39-
console.error("You'll need to upgrade to a newer version in order to use this")
40-
console.error('version of npm. Supported versions are ' + supportedMajors + '. You can find the')
41-
console.error('latest version at https://nodejs.org/')
28+
console.error("You'll need to upgrade to a newer Node.js version in order to use this")
29+
console.error('version of npm. You can find the latest version at https://nodejs.org/')
4230
process.exit(1)
4331
}
4432
}
@@ -51,7 +39,6 @@ exports.checkForUnsupportedNode = function () {
5139
log.warn('npm', 'npm does not support Node.js ' + process.version)
5240
log.warn('npm', 'You should probably upgrade to a newer version of node as we')
5341
log.warn('npm', "can't make any promises that npm will work with this version.")
54-
log.warn('npm', 'Supported releases of Node.js are the latest release of ' + supportedMajors + '.')
5542
log.warn('npm', 'You can find the latest version at https://nodejs.org/')
5643
}
5744
}

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,8 @@
307307
"test-tap": "npm run tap -- \"test/tap/*.js\" \"test/network/*.js\"",
308308
"test-node": "tap --timeout 240 \"test/tap/*.js\" \"test/network/*.js\""
309309
},
310-
"license": "Artistic-2.0"
310+
"license": "Artistic-2.0",
311+
"engines": {
312+
"node": "6 >=6.2.0 || 8 || >=9.3.0"
313+
}
311314
}

0 commit comments

Comments
 (0)