简体   繁体   English

是否有工具可以验证/检查 package.json 和 package-lock.json 是否一致?

[英]Is there a tool to validate/check that package.json and package-lock.json are consistent?

Sometimes people change package.json and forget to run npm i which will update package-lock.json , or package.json and package-lock.json are otherwise out of sync.有时人们更改package.json并忘记运行npm i这将更新package-lock.json ,或者package.jsonpackage-lock.json否则不同步。 This is an assumption not to be discussed/questioned here.这是一个不在这里讨论/质疑的假设。 I am looking for a tool that helps detect such cases.我正在寻找一种有助于检测此类情况的工具。

Do you know of an npm feature or third-party tool that can sanity-check package-lock.json ?您是否知道可以对package-lock.json进行完整性检查的 npm 功能或第三方工具? For example, it should resolve all transitive dependencies, and check that they all are mentioned in the lock file with a version in the correct semver range.例如,它应该解决所有传递依赖项,并检查它们是否都在锁定文件中提及,并且版本在正确的 semver 范围内。 It should tell whether it would make sense to run npm i in order to update your lockfile, or also whether npm ci would get you all the dependencies required as defined in package.json (accounting for transitivity).它应该说明运行npm i以更新您的锁文件是否有意义,或者npm ci是否会为您提供package.json定义的所有依赖项(考虑到传递性)。

I thought that npm --loglevel verbose install --dry-run would be a reasonable candidate, but its output does not mention what it would do to package-lock.json in case it would be run without --dry-run .我认为npm --loglevel verbose install --dry-run将是一个合理的候选者,但它的输出没有提到它会对package-lock.json做什么,以防它在没有--dry-run情况下--dry-run Of course one option would be to run npm i and then git diff package-lock.json (or similar), but that's dirty.当然,一种选择是运行npm i ,然后运行git diff package-lock.json (或类似的),但这很脏。

npm ls --depth 1 does these checks: npm ls --depth 1执行以下检查:

for example, this is the output:例如,这是输出:

+-- UNMET DEPENDENCY fastify@^2.0.0
+-- foo@0.0.7 extraneous
`-- got@10.3.0
  +-- @sindresorhus/is@1.2.0
  +-- @szmarczak/http-timer@4.0.0
  +-- @types/cacheable-request@6.0.1
  +-- cacheable-lookup@0.2.2
  +-- cacheable-request@7.0.1
  +-- decompress-response@5.0.0
  +-- duplexer3@0.1.4
  +-- get-stream@5.1.0
  +-- lowercase-keys@2.0.0
  +-- mimic-response@2.0.0
  +-- p-cancelable@2.0.0
  +-- responselike@2.0.0
  +-- to-readable-stream@2.1.0
  `-- type-fest@0.9.0

npm ERR! missing: fastify@^2.0.0, required by asd@1.0.0
npm ERR! extraneous: foo@0.0.7

I get this doing:我这样做:

npm init --yes
npm i got
npm i foo
// removed foo manually from package json
// added fastify manually to package json

暂无
暂无

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

相关问题 有没有办法从 package-lock.json 中提取 package.json? - Is there a way to extract package.json from package-lock.json? 从 package-lock.json 创建 package.json - Create package.json from package-lock.json Whats difference between package-lock.json and package.json, when is package.json generated? - Whats difference between package-lock.json and package.json, when is package.json generated? 如何使用 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? 什么是package-lock.json? - What is package-lock.json? 升级React库版本:建议只推送package.json还是同时推送package.json和package-lock.json? - Upgrading React library version: is it advisable to push only package.json or to push package.json and package-lock.json both? 如何为节点 js 项目重新生成 package.json 和 package-lock.json 文件? - How to regenerate a package.json and package-lock.json file for a node js project? npm-force-resolutions 是否会破坏 package.json 和 package-lock.json 之间的同步? - Does npm-force-resolutions break the sync between package.json and package-lock.json? 角度应用程序中需要 package.json 和 package-lock.json 文件 - Need for both package.json, package-lock.json files in an angular application 如何使用 package-lock.json 但没有 package.json 获取项目的依赖项? - how to get the dependencies of a project with a package-lock.json but no package.json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM