[BUG] <prepare script called with CMD on windows>
Is there an existing issue for this?
- [X] I have searched the existing issues
This issue exists in the latest npm version
- [X] I am using the latest npm
Current Behavior
Hi,
I'm trying to have a script running on installation of a package and also on clone of the repo (setting up git hooks). So, I wrote a simple shell script:
#!/bin/bash
git config set core.hookspath $path
And use it in prepare and install script on package.json.
{
"script": {
"install": ".hooks/setup",
"prepare": ".hooks/setup"
}
}
As I'm on windows, I've already defined my shell and script-shell o point to C:\\Program Files\\git\\bin\\bash.exe.
Therefore, is I run .hooks/setup, npm run prepare or npm install the script is correctly executed. But, if I do npm pack or npm publish, I get an error .hooks is not a valid command on the line C:\WINDOWS\system32\cmd.exe /d /s /c .hooks/setup.
Expected Behavior
The shell config should be honored, whatever the way it is used.
Steps To Reproduce
- On windows
- run
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" - Have
"prepare": "./test"onpackage.json'sscript - Have a simple
testexecutable file withecho "ok"for example - Run
npm run prepare=> ✅ will print "ok" - Run
npm pack=> ❌ will throw an error
Environment
- npm: 10.8.2
- Node.js: 22.6.0
- OS Name: Windows 10
- npm config:
script-shell = "C:\\Program Files\\git\\bin\\bash.exe"
shell = "C:\\Program Files\\git\\bin\\bash.exe"
Might be related to #6435 or #3972
This is reproducible on windows as described in issue report.
This behaviour seems expected as prepare script run for git dependencies as well as directory for which it's doing pack. scriptshell flag seems to be left out of prepare script intentionally. Need to check some specifics around the issue and code here before it's marked Triaged again.