简体   繁体   English

如何在不进行 npm install 的情况下更新 package-lock.json?

[英]How to update package-lock.json without doing npm install?

Question问题

What is the way to update/generate package-lock.json without making a real installation of node_modules (what npm install does)?在不真正安装node_modules的情况下更新/生成package-lock.json的方法是什么( npm install是做什么的)?

I want just a valid package-lock.json based on my package.json , that's it.我只想要一个基于我的package.json的有效package-lock.json ,就是这样。

Motivation动机

You might use yarn locally, when CI server uses npm .当 CI 服务器使用npm时,您可能会在本地使用yarn It's probably not the best practice, but still might ok as a temporary solution.这可能不是最佳实践,但仍然可以作为临时解决方案。

Bonus question : Same for yarn .额外问题yarn也是如此。 Is it possible to generate yarn-lock.json without doing a real installation?是否可以在不进行实际安装的情况下生成yarn-lock.json

npm npm

As of npm 6.x, you can use the following command:从 npm 6.x 开始,您可以使用以下命令:

npm i --package-lock-only

Documentation ( https://docs.npmjs.com/cli/install.html ) says:文档( https://docs.npmjs.com/cli/install.html )说:

The --package-lock-only argument will only update the package-lock.json , instead of checking node_modules and downloading dependencies. --package-lock-only参数只会更新package-lock.json ,而不是检查 node_modules 和下载依赖项。

yarn

As of yarn 3.0.0, you can use the following command:从 yarn 3.0.0 开始,您可以使用以下命令:

yarn install --mode update-lockfile

Documentation ( https://yarnpkg.com/cli/install#options-mode%20%230 ) says:文档( https://yarnpkg.com/cli/install#options-mode%20%230 )说:

If the --mode=<mode> option is set, Yarn will change which artifacts are generated.如果设置了--mode=<mode>选项,Yarn 将更改生成的工件。

update-lockfile will skip the link step altogether, and only fetch packages that are missing from the lockfile (or that have no associated checksums). update-lockfile将完全跳过链接步骤,并且仅获取锁定文件中缺少的包(或没有关联的校验和)。 This mode is typically used by tools like Renovate or Dependabot to keep a lockfile up-to-date without incurring the full install cost.这种模式通常由 Renovate 或 Dependabot 等工具使用,以保持锁定文件为最新,而不会产生全部安装成本。

As of Sep. 10, 2019: yarn doesn't seem to support generating a lock-file without installing the modules.截至 2019 年 9 月 10 日: yarn 似乎不支持在不安装模块的情况下生成锁定文件。 Relevant GitHub issue: https://github.com/yarnpkg/yarn/issues/5738相关 GitHub 问题: https ://github.com/yarnpkg/yarn/issues/5738

I don't have enough reputation to comment, so just add an answer :)我没有足够的声誉来发表评论,所以只需添加一个答案:)

In addition to Teh 's answer , for Yarn now you can:除了Teh回答,对于 Yarn 现在你可以:

yarn install --mode update-lockfile

Documentation: https://yarnpkg.com/cli/install#options-mode%20%230文档: https ://yarnpkg.com/cli/install#options-mode%20%230

update-lockfile will skip the link step altogether, and only fetch packages that are missing from the lockfile (or that have no associated checksums). update-lockfile将完全跳过链接步骤,并且仅获取锁定文件中缺少的包(或没有关联的校验和)。 This mode is typically used by tools like Renovate or Dependabot to keep a lockfile up-to-date without incurring the full install cost.这种模式通常由 Renovate 或 Dependabot 等工具使用,以保持锁定文件为最新,而不会产生全部安装成本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在不进行npm安装的情况下生成package-lock.json文件? - Is it possible to generate just a package-lock.json file without doing an npm install? package-lock.json不是用npm install创建的 - package-lock.json not created with npm install 如何在尊重 package-lock.json 的同时“npm install packageX” - How to “npm install packageX” while respecting package-lock.json 有没有办法让“npm ci”安装 devDependencies 或“npm install”不更新 package-lock.json? - Is there a way of making "npm ci" install devDependencies, or "npm install" not update package-lock.json? `npm update`和`remove package-lock.json`加上`npm install`之间的区别? - Difference between `npm update` and `remove package-lock.json` plus `npm install`? 如何使用 npm 将 package-lock.json 和/或 package.json 中的包版本更新到最新版本? - How to update version of a package in package-lock.json and/or package.json using npm to latest version? npm 在 package-lock.json 中更新 package 存在安全漏洞 - npm update package in package-lock.json with security vulnerability 我可以在不删除我的 package-lock.json 文件的情况下解决 npm install 错误吗? - Can I resolve an npm install error without deleting my package-lock.json file? 使用 npm 从任何位置安装,而无需每次都制作新的 package-lock.json? - Using npm install from any location without making new package-lock.json everytime? package-lock.json 在 npm 安装后被重写 - package-lock.json is rewritten after npm install
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM