Skip to content

Commit

Permalink
Use a package.json engines field to specify support
Browse files Browse the repository at this point in the history
That is what the `engines` in package.json is for, after all.

PR-URL: #945
Credit: @isaacs
Close: #945
Reviewed-by: @darcyclarke
  • Loading branch information
isaacs authored and darcyclarke committed Feb 25, 2020
1 parent 0769c5b commit 28c3d40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
23 changes: 5 additions & 18 deletions lib/utils/unsupported.js
Original file line number Diff line number Diff line change
@@ -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)
}
}

Expand All @@ -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)
}
}
Expand All @@ -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/')
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 28c3d40

Please # to comment.