• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var semver = require('semver')
3var supported = require('../../package.json').engines.node
4var knownBroken = '<6.2.0 || 9 <9.3.0'
5
6var checkVersion = exports.checkVersion = function (version) {
7  var versionNoPrerelease = version.replace(/-.*$/, '')
8  return {
9    version: versionNoPrerelease,
10    broken: semver.satisfies(versionNoPrerelease, knownBroken),
11    unsupported: !semver.satisfies(versionNoPrerelease, supported)
12  }
13}
14
15exports.checkForBrokenNode = function () {
16  var nodejs = checkVersion(process.version)
17  if (nodejs.broken) {
18    console.error('ERROR: npm is known not to run on Node.js ' + process.version)
19    console.error("You'll need to upgrade to a newer Node.js version in order to use this")
20    console.error('version of npm. You can find the latest version at https://nodejs.org/')
21    process.exit(1)
22  }
23}
24
25exports.checkForUnsupportedNode = function () {
26  var nodejs = checkVersion(process.version)
27  if (nodejs.unsupported) {
28    var log = require('npmlog')
29    log.warn('npm', 'npm does not support Node.js ' + process.version)
30    log.warn('npm', 'You should probably upgrade to a newer version of node as we')
31    log.warn('npm', "can't make any promises that npm will work with this version.")
32    log.warn('npm', 'You can find the latest version at https://nodejs.org/')
33  }
34}
35