Skip to content

Instantly share code, notes, and snippets.

@Soul-Master
Created November 2, 2022 17:54
Show Gist options
  • Save Soul-Master/241d3092f490af5d3cc2a442e91e8e51 to your computer and use it in GitHub Desktop.
Save Soul-Master/241d3092f490af5d3cc2a442e91e8e51 to your computer and use it in GitHub Desktop.
Fix Node.js working directory issue in NPM 8.19.2
#!/usr/bin/env node
// Restore working dir and remove additional argument
const originalCwd = process.argv.length >= 3 ? process.argv[2] : '';
if(originalCwd.startsWith('$$')) {
process.argv.splice(2, 1);
process.chdir(originalCwd.substring(2));
}
require('../lib/cli.js')(process)
@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
:: Pass current dir as last argument to `npm-cli.js`
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\node_modules\npm\bin\npm-cli.js" "$$%cd%" %*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment