npm run 是如何工作的? [英] how does npm run work?
问题描述
当我输入 npm run
时会发生什么?
What happens when I type npm run <command>
?
Is the <command> passed to the sh shell, like:
sh -c <command>
在shell中添加了额外的局部变量,即node_modules/.bin
的路径?
with additional local variables added to the shell, ie a path to the node_modules/.bin
?
我认为 npm 只能通过使用 node 在 JavaScript 世界中工作,但似乎还有很多事情要做.&
和 &&
是如何处理的?globstar 使用安全吗?
I thought npm works only in JavaScript universe by using node, but it seems there's a lot more going on out there. How &
and &&
are handled? Is globstar safe to use?
推荐答案
npm run-script
使用 sh -c
来运行命令,并且
npm run-script <command>
uses sh -c
to run the command, and cmd /d /s /c
on windows. (source) It is run by child_process.spawn.
npm env
列出了 npm 在运行命令时使用的环境.文档 列出了一些内容它增加了环境.这包括 package.json
中的所有内容、您提到的 PATH
附加内容等等.
npm env
lists the environment that npm uses when it runs commands. The documentation lists some of the things it adds to the environment. This includes everything from package.json
, the PATH
additions you mentioned and more.
&
和 &&
由 shell 处理,但 spawn
正在等待进程结束,即使它由 &
置于后台.&&
与您在 sh
中习惯的一样工作.
&
and &&
are handled by the shell, but spawn
is waiting for the process to end, even when it is put in the background by &
. &&
is working as you are used to in sh
.
globstar 将按您的预期工作,但在您使用 通配符 的 Windows 上除外.
globstar will work as you expect, except on Windows where you have wildcards instead.
这篇关于npm run 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!