Skip to content

Instantly share code, notes, and snippets.

@mykohsu
Last active February 4, 2016 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mykohsu/b6256301c722d9bec293 to your computer and use it in GitHub Desktop.
Save mykohsu/b6256301c722d9bec293 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.
:: VS201X alternative for %APPDATA%\nodejs\npm.cmd
@ECHO OFF
SETLOCAL
SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST %NODE_EXE% (
SET PATHEXT=%PATHEXT:;.JS;=;%
SET "NODE_EXE=node"
)
SET "OUTDIR=%~dp0"
IF "%1 %2 %3"=="ls -g " (
IF NOT EXIST "%OUTDIR%\npm.ls-g.cache" (
%NODE_EXE% "%~dp0\node_modules\npm\bin\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% "%~dp0\node_modules\npm\bin\npm-cli.js" %*
)
@giggio
Copy link

giggio commented Feb 2, 2016

Good job, it helped!
I forked and updated it to maintain npm original behavior. See it here: https://gist.github.com/giggio/1ba8168628c38b397bde

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment