Skip to content

Commit

Permalink
windows: search for a user-installed npm
Browse files Browse the repository at this point in the history
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
nodejs/node-v0.x-archive#8528 .

Fixes nodejs/node-v0.x-archive#8528. Reference: nodejs/node-v0.x-archive#8554.

Fixes: npm#6412

PR-URL: npm/npm#9089
  • Loading branch information
joaocgreis authored and iarna committed Aug 21, 2015
1 parent 599240f commit 89320ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
21 changes: 17 additions & 4 deletions bin/npm
Original file line number Diff line number Diff line change
Expand Up @@ -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" "$@"
21 changes: 17 additions & 4 deletions bin/npm.cmd
Original file line number Diff line number Diff line change
@@ -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%" %*

0 comments on commit 89320ba

Please sign in to comment.