Merge 6731b0b9f1 into 972be30a1a
This commit is contained in:
commit
7def9cfadc
16
nvm.sh
16
nvm.sh
|
|
@ -60,8 +60,24 @@ nvm_has_system_iojs() {
|
||||||
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
|
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# npm --version can report its version, but it typically takes a couple hundred
|
||||||
|
# ms to start npm. If we can load npm's own package.json file, we can scrape
|
||||||
|
# the version out of it and avoid that work. This speeds up `nvm use`
|
||||||
|
# substantially, at the cost of some extra complexity here.
|
||||||
nvm_print_npm_version() {
|
nvm_print_npm_version() {
|
||||||
if nvm_has "npm"; then
|
if nvm_has "npm"; then
|
||||||
|
local PACKAGE_JSON
|
||||||
|
PACKAGE_JSON="$(dirname "$(dirname "$(which npm 2>/dev/null)")")/lib/node_modules/npm/package.json"
|
||||||
|
|
||||||
|
if [ -f "${package_json}" ]; then
|
||||||
|
local NPM_VERSION
|
||||||
|
NPM_VERSION="$(command awk -F '"' '$2 == "version" { print $4; exit }' < "${PACKAGE_JSON}")"
|
||||||
|
if [ -n "${NPM_VERSION}" ]; then
|
||||||
|
echo " (npm v${NPM_VERSION})"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
echo " (npm v$(npm --version 2>/dev/null))"
|
echo " (npm v$(npm --version 2>/dev/null))"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue