unsupported.js 1.3 KB

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