index.js 680 B

12345678910111213141516171819202122232425
  1. var semverCompare = require('semver-compare')
  2. module.exports = function pleaseUpgradeNode(pkg, opts) {
  3. var opts = opts || {}
  4. var requiredVersion = pkg.engines.node.replace('>=', '')
  5. var currentVersion = process.version.replace('v', '')
  6. if (semverCompare(currentVersion, requiredVersion) === -1) {
  7. if (opts.message) {
  8. console.error(opts.message(requiredVersion))
  9. } else {
  10. console.error(
  11. pkg.name +
  12. ' requires at least version ' +
  13. requiredVersion +
  14. ' of Node, please upgrade'
  15. )
  16. }
  17. if (opts.hasOwnProperty('exitCode')) {
  18. process.exit(opts.exitCode)
  19. } else {
  20. process.exit(1)
  21. }
  22. }
  23. }