2

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

tk421
  • 5,775
  • 6
  • 23
  • 34
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
  • 2
    That's two flags. By convention, `-s` is the shorthand for `--silent`. `--` is just the end of the args to `run` and the start of the args to whatever you're running. See https://docs.npmjs.com/cli/run-script.html (not the install docs, for which that isn't used). – jonrsharpe Feb 12 '19 at 10:14
  • Possible duplicate of [What does -- do when running an npm command?](https://stackoverflow.com/questions/43046885/what-does-do-when-running-an-npm-command) – jonrsharpe Feb 12 '19 at 10:16
  • Also https://stackoverflow.com/q/41383247/3001761 – jonrsharpe Feb 12 '19 at 10:16

3 Answers3

5

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.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
4

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

Amadan
  • 191,408
  • 23
  • 240
  • 301
1

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.

alberand
  • 632
  • 5
  • 13