I'm running npm on Windows and would like to use & style parallel operations in run-scripts but running in parallel in cmd is kind of messy in my package.json file I'd like to write-
scripts: { "go": "cmd1 & cmd2"}
but npm executes the script under cmd.exe which does not know about ;
I could change this to scripts: { "go": "bats/bat1.bat")
where bat1.bat is a cmd bat file that uses the windows style call or start commands to run commands in parallel. which works but gives me a script that only works on Windows.
It would be a lot simpler if I could get npm to run the script under a bash clone or cygwin.
I tried config: { "shell": "bash"}
but that still ran cmd.exe
Is there any way to tell npm to run-scripts using a specific shell (not cmd.exe)?
You can easily run scripts using npm by adding them to the "scripts" field in package. json and run them with npm run <script-name> . Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run them by name instead of pointing to node_modules/.
The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is cmd.exe .
Since npm 5.1
npm config set script-shell "C:\\Program Files (x86)\\git\\bin\\bash.exe"
or (64bit installation)
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
Note that you need to have git for windows installed.
npm config delete script-shell
Here's one way to do it:
In your package.json file, add a line to run the script using bash. For example:
"scripts": { "boogie": "bash bin/my_script.sh" }
Now you can run your bash script from npm by:
npm run-script boogie
Not very elegant, but it works.
If you are developing in both Windows and Linux/Unix, then at least this approach is fairly portable to both environments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With