pnpm sbom
新增于:v11.0.0
🌐 Added in: v11.0.0
为项目生成软件材料清单(SBOM)。
🌐 Generate a Software Bill of Materials (SBOM) for the project.
支持的格式:
🌐 Supported formats:
-
CycloneDX 1.7 (JSON)
-
SPDX 2.3 (JSON)
用法
🌐 Usage
pnpm sbom --sbom-format cyclonedx
pnpm sbom --sbom-format spdx
pnpm sbom --sbom-format cyclonedx --lockfile-only
pnpm sbom --sbom-format spdx --prod
pnpm sbom --sbom-format cyclonedx --out sbom.cdx.json
pnpm sbom --sbom-format cyclonedx --split
pnpm sbom --sbom-format cyclonedx --exclude-peers
在工作区内,pnpm sbom 支持筛选。当选择单个工作区包时,SBOM 中的根组件使用该包的元数据。
🌐 Inside a workspace, pnpm sbom supports filtering. When a single workspace package is selected, the root component in the SBOM uses that package's metadata.
CycloneDX 输出将仅通过 devDependencies 可访问的组件标记为 scope: "excluded" 并带有 cdx:npm:package:development 属性。运行时组件,包括已安装的可选依赖,使用默认的必需作用域。
🌐 CycloneDX output marks components reachable only through devDependencies with scope: "excluded" and the cdx:npm:package:development property. Runtime components, including installed optional dependencies, use the default required scope.
选项
🌐 Options
--sbom-format <cyclonedx|spdx>
SBOM 输出格式。此选项是必需的。支持的值:cyclonedx、spdx。
🌐 The SBOM output format. This option is required. Supported values: cyclonedx, spdx.
--sbom-type <library|application>
- 默认:库
根包的组件类型。
🌐 The component type for the root package.
--sbom-spec-version <version>
新增于:v11.1.0
🌐 Added in: v11.1.0
- 默认值:1.7
- 类型:1.5、1.6、1.7
要发布的 CycloneDX 规范版本。仅在 --sbom-format cyclonedx 中有效。
🌐 The CycloneDX specification version to emit. Only valid with --sbom-format cyclonedx.
--lockfile-only
仅使用锁文件数据(跳过从存储读取)。
🌐 Only use lockfile data (skip reading from the store).
--sbom-authors <names>
SBOM 作者的逗号分隔列表。写入 CycloneDX 输出中的 metadata.authors。
🌐 Comma-separated list of SBOM authors. Written to metadata.authors in the CycloneDX output.
--sbom-supplier <name>
SBOM 供应商名称。在 CycloneDX 输出中写入到 metadata.supplier。
🌐 SBOM supplier name. Written to metadata.supplier in the CycloneDX output.
--out <path>
新增于:v11.8.0
🌐 Added in: v11.8.0
将 SBOM 写入文件而不是标准输出。
🌐 Write the SBOM to a file instead of stdout.
在路径中使用 %s 作为包名的占位符,使用 %v 作为包版本的占位符。在工作区中,包含 %s 的路径会为每个选定的包写入一个 SBOM:
🌐 Use %s in the path as a placeholder for the package name and %v as a placeholder for the package version. In a workspace, a path containing %s writes one SBOM per selected package:
pnpm sbom --sbom-format cyclonedx --out out/%s.cdx.json
pnpm sbom --sbom-format cyclonedx --out out/%s-%v.cdx.json
--split
新增于:v11.8.0
🌐 Added in: v11.8.0
为每个选定的工作区包生成单独的 SBOM。如果没有 --out,SBOM 会以 NDJSON 打印到标准输出,每行一个 JSON 文档。
🌐 Generate a separate SBOM for each selected workspace package. Without --out, the SBOMs are printed to stdout as NDJSON, one JSON document per line.
当 --split 与 --out 结合时,输出路径必须包含 %s。
🌐 When --split is combined with --out, the output path must contain %s.
--exclude-peers
新增于:v11.9.0
🌐 Added in: v11.9.0
从 SBOM 中排除对等依赖。仅通过这些对等依赖可访问的依赖也会被排除。
🌐 Exclude peer dependencies from the SBOM. Dependencies reachable only through those peers are also excluded.
这在 auto-install-peers 中很有用,因为 peer 依赖会被解析到锁文件中,否则看起来和普通依赖一样。
🌐 This is useful with auto-install-peers because peer dependencies are resolved into the lockfile and otherwise look the same as regular dependencies.
--prod, -P
仅包含 dependencies 和 optionalDependencies。
🌐 Only include dependencies and optionalDependencies.
--dev, -D
只包括 devDependencies。
🌐 Only include devDependencies.
--no-optional
不要包括 optionalDependencies。
🌐 Don't include optionalDependencies.