-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4654 from zpao/checkversionsoninstall
Check for compatible node,npm versions on install
- Loading branch information
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var devEngines = require('../package').devEngines; | ||
|
||
var assert = require('assert'); | ||
var exec = require('child_process').exec; | ||
var semver = require('semver'); | ||
var f = require('util').format; | ||
|
||
if (devEngines.node !== undefined) { | ||
// First check that devEngines are valid semver | ||
assert( | ||
semver.validRange(devEngines.node), | ||
f('devEngines.node (%s) is not a valid semver range', devEngines.node) | ||
); | ||
// Then actually check that our version satisfies | ||
var nodeVersion = process.versions.node; | ||
assert( | ||
semver.satisfies(nodeVersion, devEngines.node), | ||
f('Current node version is not supported for development, expected "%s" to satisfy "%s".', nodeVersion, devEngines.node) | ||
); | ||
} | ||
|
||
if (devEngines.npm !== undefined) { | ||
// First check that devEngines are valid semver | ||
assert( | ||
semver.validRange(devEngines.npm), | ||
f('devEngines.npm (%s) is not a valid semver range', devEngines.npm) | ||
); | ||
|
||
// Then actually check that our version satisfies | ||
exec('npm --version', function(err, stdout, stderr) { | ||
assert(err === null, f('Failed to get npm version... %s'), stderr); | ||
|
||
var npmVersion = stdout.trim(); | ||
assert( | ||
semver.satisfies(npmVersion, devEngines.npm), | ||
f('Current npm version is not supported for development, expected "%s" to satisfy "%s".', npmVersion, devEngines.npm) | ||
); | ||
}); | ||
} |