"npm install"和"npm install"之间有什么区别?和"npm ci"? [英] What is the difference between "npm install" and "npm ci"?

查看:416
本文介绍了"npm install"和"npm install"之间有什么区别?和"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.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆