Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
fix(new): correctly verify the versionn of npm
Browse files Browse the repository at this point in the history
Closes #121
  • Loading branch information
RomainLanz committed Jan 17, 2019
1 parent 3f8394b commit 1ceef76
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Services/check-node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const semver = require('semver')
const requiredNodeVersion = '>=8.0.0'
const requiredNodeVersionNumber = 8
const requiredNpmVersion = '>=3.0.0'
const requiredNpmVersionNumber = 3

/**
* This step checks the Node.js and npm version
Expand All @@ -32,9 +33,10 @@ module.exports = async function (stepsCounter) {
step.start()

/**
* Verify Node.js version
* Uses `semver.parse` instead of `semver.satistfies` to support prereleases
* of Node.js
* Verify Node.js version.
*
* Uses `semver.parse` instead of `semver.satisfies` to support prereleases
* version of Node.js.
*/
const nodeVersion = process.version
if (semver.parse(nodeVersion).major < requiredNodeVersionNumber) {
Expand All @@ -43,11 +45,13 @@ module.exports = async function (stepsCounter) {
}

/**
* Verify npm version
* Verify npm version.
*
* Uses `semver.parse` instead of `semver.satisfies` to support prereleases
* version of npm.
*/
let npmVersion = await require('./exec')('npm -v')
npmVersion = npmVersion.trim()
if (!semver.satisfies(npmVersion, '>=3.0.0')) {
const npmVersion = (await require('./exec')('npm -v')).trim()
if (semver.parse(npmVersion).major < requiredNpmVersionNumber) {
step.error('Unsupported npm version', 'x')
throw new Error(`Unsatisfied npm version ${npmVersion}. Please update npm to ${requiredNpmVersion} before you continue`)
}
Expand Down

0 comments on commit 1ceef76

Please sign in to comment.