J. Hesters
J. Hesters

Reputation: 14796

What does the `-s --` flag do for npm?

I just watched a video by Kent C. Dodds where he explains his .bash_profile.

He uses the following aliases for yarn and npm:

## npm aliases
alias ni="npm install";
alias nrs="npm run start -s --";
alias nrb="npm run build -s --";
alias nrd="npm run dev -s --";
alias nrt="npm run test -s --";
alias nrtw="npm run test:watch -s --";
alias nrv="npm run validate -s --";
alias rmn="rm -rf node_modules";
alias flush-npm="rm -rf node_modules && npm i && say NPM is done";
alias nicache="npm install --prefer-offline";
alias nioff="npm install --offline";

## yarn aliases
alias yar="yarn run";
alias yas="yarn run start -s --";
alias yab="yarn run build -s --";
alias yat="yarn run test -s --";
alias yav="yarn run validate -s --";
alias yoff="yarn add --offline";
alias ypm="echo \"Installing deps without lockfile and ignoring engines\" && yarn install --no-lockfile --ignore-engines"

I was wondering, what does the -s -- flag do? Kent does not explain it in the video and I couldn't find any info on the flag(s).

Upvotes: 2

Views: 2282

Answers (3)

KamilCuk
KamilCuk

Reputation: 141473

Option -s makes yarn don't output anything on standard output, ie. silences it.

The -- comes from posix utility conventions and is very common among command line linux tools:

Guideline 10:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.

So:

> printf "%s" -n
-n

All ok, it will print -n. But:

> printf -n
bash: printf: -n: invalid option
printf: usage: printf [-v var] format [arguments]

To allow passing -n, ie. option starting with a leading - as the first argument to printf, one can use --:

> printf -- -n
-n

So:

alias yas="yarn run start -s";
yas -package

will throw unknown option by yarn, as it will try to parse -p as an option. Doing:

alias yas="yarn run start -s --";
yas -package 

will throw unknown package by yarn as there is no package named -package. By using -- the author effectively blocks the user (himself) from passing any additional options to yarn, as all following arguments will be interpreted as package names only.

Upvotes: 5

Amadan
Amadan

Reputation: 198418

-s is equivalent to --silent.

-- is common Unix convention signifying end of options. After that, even if an argument looks like an option, it will be considered a positional argument.

Upvotes: 4

alberand
alberand

Reputation: 662

It means the end of command options. Therefore, you can't use command options (such as -s) after double dash. However, you can, for example, list files to process by command.

Explained here

The -s option itself is short equivalent to --loglevel=silent which disables logging output.

Upvotes: 1

Related Questions