Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJoão Reis <reis@janeasystems.com>2015-07-28 18:43:58 +0300
committerRebecca Turner <me@re-becca.org>2015-08-21 04:58:23 +0300
commit89320ba9d27e25ea3f8c88d7089d9fcf0bf0d440 (patch)
treea45dd8ef69774cd07df099786a0ae35b2bc2c210 /bin
parent599240faeb22e2529302e877e620b43b8b6d83b4 (diff)
windows: search for a user-installed npm
This changes npm.cmd and the npm script when running in Cygwin to look for an npm installation in prefix, running it if found. The default npm is used to get the prefix. This implements the changes described in https://github.com/joyent/node/issues/8528 . Fixes joyent/node#8528. Reference: joyent/node#8554. Fixes: #6412 PR-URL: https://github.com/npm/npm/pull/9089
Diffstat (limited to 'bin')
-rwxr-xr-xbin/npm21
-rw-r--r--bin/npm.cmd21
2 files changed, 34 insertions, 8 deletions
diff --git a/bin/npm b/bin/npm
index d020ccfe7..45e8e4103 100755
--- a/bin/npm
+++ b/bin/npm
@@ -7,8 +7,21 @@ case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
-if [ -x "$basedir/node.exe" ]; then
- "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
-else
- node "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
+NODE_EXE="$basedir/node.exe"
+if ! [ -x "$NODE_EXE" ]; then
+ NODE_EXE=node
fi
+
+NPM_CLI_JS="$basedir/node_modules/npm/bin/npm-cli.js"
+
+case `uname` in
+ *CYGWIN*)
+ NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
+ NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
+ if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
+ NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
+ fi
+ ;;
+esac
+
+"$NODE_EXE" "$NPM_CLI_JS" "$@"
diff --git a/bin/npm.cmd b/bin/npm.cmd
index 7720e2052..f111c59d1 100644
--- a/bin/npm.cmd
+++ b/bin/npm.cmd
@@ -1,6 +1,19 @@
:: Created by npm, please don't edit manually.
-@IF EXIST "%~dp0\node.exe" (
- "%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
-) ELSE (
- node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
+@ECHO OFF
+
+SETLOCAL
+
+SET "NODE_EXE=%~dp0\node.exe"
+IF NOT EXIST "%NODE_EXE%" (
+ SET "NODE_EXE=node"
)
+
+SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
+FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
+ SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
+)
+IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
+ SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
+)
+
+"%NODE_EXE%" "%NPM_CLI_JS%" %*