We need a way to specify which shell a script is written for #115
-
There appears to be no way to specify which shell is to be used to execute an
IMO, we need the equivalent of the shebang Current Behavior:Prints the literal string Expected Behavior:Prints something like Steps To Reproduce:
Environment:
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 6 replies
-
I'm also aware I could write things like "scripts": {
"install": "bash -c 'echo $SHELL'"
} But this is still making the assumption that all possible arbitrary shells that the installer could be using will interpret the string |
Beta Was this translation helpful? Give feedback.
-
Pinging the @npm/cli team |
Beta Was this translation helpful? Give feedback.
-
This is the reason why so many install/build scripts are written as Node.js programs, since you're it's much more likely that I'm open to putting the {
"engines": {
"node": ">=10",
"npm": ">=6",
"shell": "bash"
}
} Also, it seems like you expect npm (or perhaps Maybe the So, looks like, three distinct but related issues. (Set script-shell in package.json, set env.SHELL to script-shell, and default script-shell to env.SHELL if set.) Anything I missed there? |
Beta Was this translation helpful? Give feedback.
-
Thanks @isaacs. For context, the specific problem I had was that I developed a package with an install script that assumed Setting I did expect npm to set the Defaulting to the current |
Beta Was this translation helpful? Give feedback.
-
Is there any progress on this? It's really a struggle not being able to define the shell in the project. It doesn't make sense that the behavior of npm scripts are non-deterministic. |
Beta Was this translation helpful? Give feedback.
-
I prefer to config shell for different platforms, like {
"engines": {
"node": ">=10",
"npm": ">=6",
"windows-shell": "pwsh",
"unix-shell": "tcsh",
"darwin-shell": "zsh",
}
} |
Beta Was this translation helpful? Give feedback.
-
What about a syntax idea, f.e.: "scripts": {
"foo<<pwsh": "Get-Command cmd",
"bar<<bash": "which npm",
} where |
Beta Was this translation helpful? Give feedback.
-
I use PowerShell. But, because Windows users likely install Git along with Git Bash, I'd recommend setting that as the default on Windows systems if the path is available. Additionally, that will unify most command-line tools available to users, such as date, grep, ssh, etc. |
Beta Was this translation helpful? Give feedback.
This is the reason why so many install/build scripts are written as Node.js programs, since you're it's much more likely that
node install.js
will work.I'm open to putting the
script-shell
config in a package.json file somewhere. Maybe it should be in"engines"
somewhere, since it's kind of like "this is the platform that should be used to run this package"?Also, it seems like you expect npm (or perhaps
@npmcli/run-script
) to add thescript-shell
config to theSHELL
environment variable, which is seems completely reasonable to me.Maybe the
script-shell
config should also default to whateverprocess.env.SHELL
…