简体   繁体   English

如何将 npm 审核与 NPM 工作区一起使用?

[英]How to use npm audit with NPM workspaces?

For a project using the AWS CDK we are moving from lerna to NPM workspaces.对于使用 AWS CDK 的项目,我们将从 lerna 移动到 NPM 工作区。 Everything seems fine so far, except for running npm audit in the project root, which doesn't seem to take the workspace into account.到目前为止一切似乎都很好,除了在项目根目录中运行npm audit ,它似乎没有考虑工作空间。

We are using the following folder structure:我们正在使用以下文件夹结构:

.
|-package.json
|-package-lock.json
|-ts-config.json
|-lib
 |-index.ts
 |-lambdas
  |-workspace-a
   |-index.ts
   |-package.json

When adding a dependency with vulnerabilities to the project root's package.json , npm audit greets us with the report of those as usual.当向项目根目录的package.json添加具有漏洞的依赖项时, npm audit会像往常一样向我们发送报告。 When installing the same dependency in the workspace-a package.json , it ends up in the project's root package-lock.json section for the workspace, as expected, but goes unnoticed by npm audit and reports 0 vulnerabilities.当在workspace-a package.json中安装相同的依赖项时,它最终出现在项目的根package-lock.json工作区部分,正如预期的那样,但没有被npm audit注意到并报告 0 个漏洞。

So far I have tried several ways of running npm audit ;到目前为止,我已经尝试了几种运行npm audit的方法; by adding --workspaces=true , --workspace lib/lambdas/workspace-a and --package-lock-only , but neither seem to work.通过添加--workspaces=true--workspace lib/lambdas/workspace-a--package-lock-only ,但似乎都不起作用。

Is there something I'm failing to see to get npm audit to work for workspace-a ?有什么我没有看到让npm audit工作workspace-a吗?

After some testing with sample projects on the same and different machines, the solution seems to lie in the registry set in the .npmrc .在相同和不同机器上对示例项目进行一些测试后,解决方案似乎位于.npmrc中的注册表集。 When commenting out the enterprise npm repository, the audits get picked up again.当注释掉企业 npm 存储库时,审计再次被拾取。

Alternatively, running npm audit --registry=https://registry.npmjs.org will work without changing the global config.或者,运行npm audit --registry=https://registry.npmjs.org将在不更改全局配置的情况下运行。

This only seems to be needed for audits on workspaces and nested dependencies, as the top-level dependencies on the root package level will be audited just fine either way.这似乎只需要对工作区和嵌套依赖项进行审计,因为根 package 级别上的顶级依赖项将以任何一种方式进行审计。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM