-
-
Save giggio/1ba8168628c38b397bde to your computer and use it in GitHub Desktop.
Alternative npm.cmd for VS201X node tools integration. Caches npm ls -g result until a different npm command is issued.
This file contains hidden or 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
@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%" | |
) | |
SET "OUTDIR=%~dp0" | |
IF "%1 %2"=="ls -g" ( | |
IF NOT EXIST "%OUTDIR%\npm.ls-g.cache" ( | |
"%NODE_EXE%" "%NPM_CLI_JS%" %* >>"%OUTDIR%\npm.ls-g.cache" | |
) | |
FOR /F "tokens=2 delims=:" %%F IN ('CALL CHCP') DO ( | |
SET "LS-GCHCP=%%F" | |
) | |
CHCP 65001>nul | |
TYPE "%OUTDIR%\npm.ls-g.cache" | |
CHCP %LS-GCHCP%>nul | |
) ELSE ( | |
ERASE "%OUTDIR%\npm.ls-g.cache" 2> nul | |
"%NODE_EXE%" "%NPM_CLI_JS%" %* | |
) |
@giggio Actually depending on the node version or where it is installed the original npm script is different. I have both versions, but the one under the user roaming profile used PATHEXT and @ for each command.
You'll want SET "OUTDIR=%%F"
in the first FOR statement so that it is set to the global node path rather than the input path.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use, run on powershell:
gcm npm
It will output something like this:
Update the file listed on
Source
.