"npm install"和"npm install"之间有什么区别?和"npm ci"? [英] What is the difference between "npm install" and "npm ci"?
问题描述
我正在进行持续集成,并发现了 npm ci 命令.
I'm working with continuous integration and discovered the npm ci command.
我不知道在我的工作流程中使用此命令有什么好处.
I can't figure what the advantages are of using this command for my workflow.
速度更快吗?这样会使测试变得更难,更好吗?
Is it faster? Does it make the test harder, okay, and after?
推荐答案
来自 npm文档 :
简而言之,使用npm install和npm ci之间的主要区别是:
In short, the main differences between using npm install and npm ci are:
- 项目必须具有现有的package-lock.json或npm-shrinkwrap.json.
- 如果程序包锁定中的依赖项与package.json中的依赖项不匹配,则npm ci会退出并显示错误,而不是更新程序包锁定.
- npm ci一次只能安装整个项目:此命令不能添加单个依赖项.
- 如果已经存在一个node_modules,它将在npm ci开始安装之前自动删除.
- 它永远不会写入package.json或任何包锁:安装实际上是冻结的.
从本质上讲,
npm install
读取package.json
创建依赖关系列表,并使用package-lock.json
告知要安装这些依赖关系的版本. 如果依赖项不在package-lock.json
中,则会由npm install
添加.
Essentially,
npm install
reads package.json
to create a list of dependencies and uses package-lock.json
to inform which versions of these dependencies to install. If a dependency is not in package-lock.json
it will be added by npm install
.
npm ci
(以 C 不连续的 I 集成命名)直接从package-lock.json
安装依赖项,并且仅使用package.json
进行验证没有不匹配的版本. 如果缺少任何依赖项或版本不兼容,则会抛出错误.
npm ci
(named after Continuous Integration) installs dependencies directly from package-lock.json
and uses package.json
only to validate that there are no mismatched versions. If any dependencies are missing or have incompatible versions, it will throw an error.
使用npm install
添加新的依赖关系,并更新对项目的依赖关系.通常,在拉动更新依赖项列表的更改之后,您将在开发期间使用它.但是在这种情况下,使用npm ci
是个好主意.
Use npm install
to add new dependencies, and to update dependencies on a project. Usually, you would use it during development after pulling changes that update the list of dependencies but it may be a good idea to use npm ci
in this case.
如果需要确定的,可重复的构建,请使用npm ci
.例如,在持续集成,自动化作业等过程中以及首次安装依赖项时,而不是npm install
.
Use npm ci
if you need a deterministic, repeatable build. For example during continuous integration, automated jobs, etc. and when installing dependencies for the first time, instead of npm install
.
- 安装软件包及其所有依赖项.
- 依赖关系由
npm-shrinkwrap.json
和package-lock.json
(按此顺序)驱动. - 不带参数:安装本地模块的依赖项.
- 可以安装全局软件包.
- 将在
node_modules
中安装所有缺少的依赖项. - 它可以写入
package.json
或package-lock.json
.- 与自变量(
npm i packagename
)一起使用时,它可能会写入package.json
以添加或更新依赖项. - 在不带参数的情况下使用(
npm i
)可能会写入package-lock.json
以锁定某些依赖项的版本(如果该文件中尚未存在这些依赖项的话).
- Installs a package and all its dependencies.
- Dependencies are driven by
npm-shrinkwrap.json
andpackage-lock.json
(in that order). - without arguments: installs dependencies of a local module.
- Can install global packages.
- Will install any missing dependencies in
node_modules
. - It may write to
package.json
orpackage-lock.json
.- When used with an argument (
npm i packagename
) it may write topackage.json
to add or update the dependency. - when used without arguments, (
npm i
) it may write topackage-lock.json
to lock down the version of some dependencies if they are not already in this file.
- 至少需要npm v5.7.1 .
- 需要
package-lock.json
或npm-shrinkwrap.json
出现. - 如果来自这两个文件的依赖项与
package.json
不匹配,则会引发错误. - 删除
node_modules
并立即安装所有依赖项. - 它永远不会写入
package.json
或package-lock.json
.
- Requires at least npm v5.7.1.
- Requires
package-lock.json
ornpm-shrinkwrap.json
to be present. - Throws an error if dependencies from these two files don't match
package.json
. - Removes
node_modules
and install all dependencies at once. - It never writes to
package.json
orpackage-lock.json
.
npm ci
从package-lock.json
或npm-shrinkwrap.json
生成整个依赖关系树时,npm install
使用以下算法更新node_modules
的内容(While
npm ci
generates the entire dependency tree frompackage-lock.json
ornpm-shrinkwrap.json
,npm install
updates the contents ofnode_modules
using the following algorithm (source):load the existing node_modules tree from disk clone the tree fetch the package.json and assorted metadata and add it to the clone walk the clone and add any missing dependencies dependencies will be added as close to the top as is possible without breaking any other modules compare the original tree with the cloned tree and make a list of actions to take to convert one to the other execute all of the actions, deepest first kinds of actions are install, update, remove and move
这篇关于"npm install"和"npm install"之间有什么区别?和"npm ci"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- When used with an argument (
- 与自变量(