`-s --` 标志对 npm 有什么作用?
What does the `-s --` flag do for npm?
我刚看了一个video by Kent C. Dodds where he explains his .bash_profile
.
他为 yarn
和 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"
我想知道,-s --
标志有什么作用? Kent 没有在视频中解释它,我在旗帜上找不到任何 info。
表示命令选项结束。因此,您不能在双破折号后使用命令选项(例如 -s
)。但是,例如,您可以列出要通过命令处理的文件。
-s
选项本身相当于禁用日志输出的 --loglevel=silent
。
-s
等同于 --silent
.
--
是常见的 Unix 约定,表示选项结束。在那之后,即使一个参数看起来像一个选项,它也会被认为是一个位置参数。
选项 -s
使 yarn
不在标准输出上输出任何内容,即。将其静音。
--
来自 posix utility conventions 并且在命令行 linux 工具中很常见:
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.
所以:
> printf "%s" -n
-n
一切正常,它将打印-n
。但是:
> printf -n
bash: printf: -n: invalid option
printf: usage: printf [-v var] format [arguments]
允许通过 -n
,即。以 -
开头的选项作为 printf 的第一个参数,可以使用 --
:
> printf -- -n
-n
所以:
alias yas="yarn run start -s";
yas -package
将通过 yarn 抛出未知选项,因为它会尝试将 -p
解析为选项。正在做:
alias yas="yarn run start -s --";
yas -package
将由 yarn
抛出未知包,因为没有名为 -package
的包。通过使用 --
,作者有效地阻止了用户(他自己)将任何其他选项传递给 yarn,因为以下所有参数将仅被解释为包名称。
我刚看了一个video by Kent C. Dodds where he explains his .bash_profile
.
他为 yarn
和 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"
我想知道,-s --
标志有什么作用? Kent 没有在视频中解释它,我在旗帜上找不到任何 info。
表示命令选项结束。因此,您不能在双破折号后使用命令选项(例如 -s
)。但是,例如,您可以列出要通过命令处理的文件。
-s
选项本身相当于禁用日志输出的 --loglevel=silent
。
-s
等同于 --silent
.
--
是常见的 Unix 约定,表示选项结束。在那之后,即使一个参数看起来像一个选项,它也会被认为是一个位置参数。
选项 -s
使 yarn
不在标准输出上输出任何内容,即。将其静音。
--
来自 posix utility conventions 并且在命令行 linux 工具中很常见:
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.
所以:
> printf "%s" -n
-n
一切正常,它将打印-n
。但是:
> printf -n
bash: printf: -n: invalid option
printf: usage: printf [-v var] format [arguments]
允许通过 -n
,即。以 -
开头的选项作为 printf 的第一个参数,可以使用 --
:
> printf -- -n
-n
所以:
alias yas="yarn run start -s";
yas -package
将通过 yarn 抛出未知选项,因为它会尝试将 -p
解析为选项。正在做:
alias yas="yarn run start -s --";
yas -package
将由 yarn
抛出未知包,因为没有名为 -package
的包。通过使用 --
,作者有效地阻止了用户(他自己)将任何其他选项传递给 yarn,因为以下所有参数将仅被解释为包名称。