Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify which shell Yarn uses for running scripts

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.

like image 240
Jeff Huijsmans Avatar asked May 04 '17 09:05

Jeff Huijsmans


2 Answers

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
like image 93
PPrice Avatar answered Oct 20 '22 07:10

PPrice


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 ..'

like image 44
Nahuel Fouilleul Avatar answered Oct 20 '22 07:10

Nahuel Fouilleul