我的package.json
中有一个脚本,如下所示:
"buildTslint": "node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts",
请注意{,helpers/}*.ts
部分,此部分称为Brace Expansion,仅适用于bash
,而非sh
。
运行yarn buildTslint
时,我得到以下输出:
# 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.
似乎Yarn使用sh
来执行这些脚本,但我想使用bash
来实现此功能,以便能够使用大括号扩展。
答案 0 :(得分:1)
它可以使用system
函数启动命令,另请参阅man 3 system
。
查看使用了哪个系统调用:
strace yarn ...
system
使用fork
+ exec
+ wait
,exec系列函数使用shell /bin/sh
使用bash命令可以更改为bash -c 'command ..'
答案 1 :(得分:1)
Yarn还没有提供配置用于运行脚本的默认shell的方法,请参阅:https://github.com/yarnpkg/yarn/issues/4248
但是,由于yarn使用Node来生成其进程,您可以通过更改Node本身使用的默认shell来解决这个问题。
在Ubuntu上,如果您拥有root权限,则可以通过将符号链接/bin/sh
更改为指向dash
以外的其他内容来执行此操作:
sudo ln -sf /bin/bash /bin/sh
在Windows中的Git-bash中,您可以将COMSPEC
环境变量更改为C:\Windows\system32\cmd.exe
以外的其他内容,但我还没有让它为我工作。
另见:
答案 2 :(得分:1)