Specify which shell Yarn uses for running scripts

折月煮酒 提交于 2021-02-07 06:13:48

问题


My package.json has a script in it like this:

"buildTslint": "node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts",

Note the {,helpers/}*.ts part, this is called Brace Expansion and is only possible in bash, not sh.

When running yarn buildTslint I get the following output:

# yarn buildTslint
yarn buildTslint v0.22.0
$ node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts
error TS6053: File 'node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts' not found.
error Command failed with exit code 2.

It seems that Yarn uses sh to execute these scripts, but I'd like to use bash for this, to be able to use brace expansion.


回答1:


It may launch the command using system function see also man 3 system.

To see which system call is used :

strace yarn ...

system uses fork+exec+wait and the exec family functions uses shell /bin/sh

to use bash the command can be changed to bash -c 'command ..'




回答2:


yarn version 1.19 added support for a new config parameter script-shell. You can now do the following:

yarn config set script-shell /bin/bash



回答3:


Yarn doesn't yet provide a way to configure the default shell used for running scripts, see: https://github.com/yarnpkg/yarn/issues/4248

However, since yarn uses Node for spawning its processes, you can work around that by changing the default shell that Node itself uses.

On Ubuntu, if you have root permissions, you can do this by changing the symlink /bin/sh to point to something other than dash:

sudo ln -sf /bin/bash /bin/sh

In Git-bash in Windows, you can change the COMSPEC environment variable to something other than C:\Windows\system32\cmd.exe, but I haven't gotten that to work for me.

See also:

  • Force node to use git bash on windows


来源:https://stackoverflow.com/questions/43778649/specify-which-shell-yarn-uses-for-running-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!