问题
I am writing an npm module which comes with some scripts, e.g. npm run cureCancer
.
I want these scripts to accept extra parameters, which is possible only with npm 2 and above, e.g. npm run cureCancer -- fast
This means that my module depends on npm 2 or newer, so I added the following to package.json:
"devDependencies": {
"npm": "^2.7.5"
}
Then I ran npm install
.
Then I ran npm -v
- expected:
2.7.5
- observed:
1.4.23
.
And of course npm run cureCancer -- fast
fails.
How can my module require a specific version of npm?
As a bonus, I would like npm@2 to be installed locally only, so as not to mess with people's global setup.
UPDATE
Adding npm to the dependencies works, but it doesn't override the global version when using the npm
command. To use the locally installed npm instead, use ./node_modules/.bin/npm
. This is pretty ugly and unfriendly, so creating an alias might be a good idea.
来源:https://stackoverflow.com/questions/29560416/how-can-my-module-require-a-specific-version-of-npm