janbiasi/rollup-plugin-sbom

GitHub: janbiasi/rollup-plugin-sbom

为 Vite、Rollup 和 Rolldown 项目自动生成 CycloneDX 格式 SBOM 的构建插件,仅包含实际进入生产产物的依赖。

Stars: 23 | Forks: 6

[![在 npmx.dev 上打开](https://npmx.dev/api/registry/badge/version/rollup-plugin-sbom)](https://npmx.dev/package/rollup-plugin-sbom) [![在 npmx.dev 上打开](https://npmx.dev/api/registry/badge/downloads-year/rollup-plugin-sbom)](https://npmx.dev/package/rollup-plugin-sbom) [![在 npmx.dev 上打开](https://npmx.dev/api/registry/badge/engines/rollup-plugin-sbom)](https://npmx.dev/package/rollup-plugin-sbom) [![在 npmx.dev 上打开](https://npmx.dev/api/registry/badge/vulnerabilities/rollup-plugin-sbom)](https://npmx.dev/package/rollup-plugin-sbom) # rollup-plugin-sbom 为你的 [Vite](https://vitejs.dev/) 和 [Rollup](https://rollupjs.org/) 项目创建 [CycloneDX](https://cyclonedx.org/) 格式的 [SBOMs]() _(软件物料清单)_,仅包含你真正投入到生产环境中的软件。 ## 文档 - [要求与兼容性](#requirements-and-compatibility) - [安装](#installation) - [使用指南](#usage) - [在 Vite 中使用](#usage-with-vite) - [在 Rollup 中使用](#usage-with-rollup) - [在 Rolldown 中使用](#usage-with-rolldown) - [配置选项与默认值](#configuration-options) - [调试](#debugging) - [流程图](#sequence-chart) - [贡献](#contributing) - [贡献流程](#workflow) - [做出你的第一次贡献](#good-first-issues) - [贡献者](#contributors) ### 要求与兼容性 | Plugin | Vite | Rollup | Rolldown | Node | CDX Spec | | ------ | ---------- | ------ | -------- | ---------- | -------- | | v1 | 4, 5 | 3, 4 | - | 18, 20 | 1.5 | | v2 | 4, 5, 6 | 3, 4 | - | 18, 20, 22 | 1.6 | | v3 | 5, 6, 7, 8 | 4 | 1 | 20, 22, 24 | 1.6 | 我们始终支持处于 LTS 阶段的 Node.js 版本,以及仍享有安全支持的版本。 一旦某个 Node.js 版本达到其最终的 EOL(生命周期结束),我们将不再提供对该 Plugin 的支持。 ### 安装 你可以通过 [NPM](https://www.npmjs.com/package/rollup-plugin-sbom) 使用你喜欢的包管理器来安装该插件: ``` npm install --save-dev rollup-plugin-sbom pnpm install -D rollup-plugin-sbom yarn add --dev rollup-plugin-sbom ``` ### 用法 #### 在 [Vite](https://vitejs.dev/) 中使用 ``` import { defineConfig } from "vite"; import sbom from "rollup-plugin-sbom"; export default defineConfig({ plugins: [sbom()], }); // or export default defineConfig({ build: { rollupOptions: { plugins: [sbom()], }, }, }); ``` #### 在 [Rollup](https://rollupjs.org/) 中使用 ``` import sbom from "rollup-plugin-sbom"; export default { plugins: [sbom()], }; ``` #### 在 [Rolldown](https://rolldown.rs/) 中使用 ``` import { defineConfig } from "rolldown"; import sbom from "rollup-plugin-sbom"; export default defineConfig({ plugins: [sbom()], }); ``` #### 配置选项 | 名称 | 默认值 | 描述 | | ------------------- | ------------- | ------------------------------------------------------------------------------------------- | | `specVersion` | `1.6` | 要使用的 CycloneDX 规范版本 | | `rootComponentType` | `application` | 根组件类型,可以是 `library` 或 `application` | | `outDir` | `cyclonedx` | 保存 BOM 文件的输出目录。 | | `outFilename` | `bom` | SBOM 文件的基础文件名。 | | `outFormats` | `['json']` | 输出的格式。可以是 `json` 和 `xml` 中的任意一种(注意:`xml` 需要 `xmlbuilder2`)。 | | `saveTimestamp` | `true` | 是否在 BOM 元数据中保存时间戳。 | | `autodetect` | `true` | 是否自动注册根包。 | | `generateSerial` | `false` | 是否为 BOM 生成序列号。 | | `includeWellKnown` | `true` | 是否在 `well-known` 目录中生成 SBOM。 | | `supplier` | - | 提供组织实体信息 | | `beforeCollect` | - | 在收集依赖之前增强 BOM | | `afterCollect` | - | 在收集依赖之后转换 BOM | ### 可选的 Peer Dependencies 某些功能需要可选的 peer dependencies —— 有关版本的详细信息,请参阅 package.json。 - 在 Node.js 上序列化为 XML 需要以下任意一项: - `xmlbuilder2` ### 调试 此插件添加了 `debug` 日志,以收集有关你的 SBOM 是如何构建的信息,以便你了解为什么将某个依赖项添加到图中。要启用调试,你可以将 `logLevel` 选项设置为 `"debug"`。 ``` // rollup and rolldown export default { logLevel: "debug", }; // vite export default defineConfig({ build: { rollupOptions: { logLevel: "debug", }, }, }); ```
来自我们的 测试固件 "resolution" 的输出示例 关于何时以及如何阅读调试信息的一般建议: - 查看注册了哪些工具 (`Registering tool `) - 查看分析了哪些生成的 bundles (`Processing generated module `) - 检查已分析的第三方模块及其依赖树 (`Processing (imported by - depends on )`) ``` [plugin rollup-plugin-sbom] Autodetection enabled, trying to resolve root component [plugin rollup-plugin-sbom] Saving timestamp to SBOM [plugin rollup-plugin-sbom] Generating serial number for SBOM [plugin rollup-plugin-sbom] Registering tool rollup-plugin-sbom [plugin rollup-plugin-sbom] Registering tool vite [plugin rollup-plugin-sbom] Registering tool rollup [plugin rollup-plugin-sbom] Processing generated module "index.js" [plugin rollup-plugin-sbom] Found 4 external modules within "index.js" [plugin rollup-plugin-sbom] Found 3 unique external modules accross all bundles [plugin rollup-plugin-sbom] Processing a (imported by /rollup-plugin-sbom/test/fixtures/resolution/node_modules/a/index.js - depends on c) [plugin rollup-plugin-sbom] Attaching nested dependency "c" to parent component a [plugin rollup-plugin-sbom] Processing c (imported by /rollup-plugin-sbom/test/fixtures/resolution/node_modules/a/node_modules/c/index.js - depends on none) [plugin rollup-plugin-sbom] Processing side-effect (imported by /rollup-plugin-sbom/test/fixtures/resolution/node_modules/b/node_modules/side-effect/index.js - depends on none) [plugin rollup-plugin-sbom] Processing b (imported by /rollup-plugin-sbom/test/fixtures/resolution/node_modules/b/index.js - depends on a, side-effect) [plugin rollup-plugin-sbom] Attaching nested dependency "a" to parent component b [plugin rollup-plugin-sbom] Processing a (imported by /rollup-plugin-sbom/test/fixtures/resolution/node_modules/b/node_modules/a/index.js - depends on none) [plugin rollup-plugin-sbom] Attaching nested dependency "side-effect" to parent component b [plugin rollup-plugin-sbom] Emitting SBOM asset to plugin-outdir/filename.json [plugin rollup-plugin-sbom] Emitting SBOM asset to plugin-outdir/filename.xml [plugin rollup-plugin-sbom] Emitting well-known file to .well-known/sbom ```
### 流程图 ``` sequenceDiagram participant Bundler box Hook Phases participant SB as Start Build participant MP as Module Parsed participant GB as Generate Bundle participant EF as Emit Files end box Plugin participant AN as Analyzer participant PR as Package Registry end activate Bundler activate SB Bundler->>SB: Register Root Component Bundler->>SB: Register Tools deactivate SB Bundler-->>MP: Invoke for each module activate MP MP-->>PR: Find and load package.json deactivate MP activate GB Bundler->>GB: Invoke with generated chunks AN->>AN: Build tree (recursive) GB->>AN: Analyze generated chunk AN->>GB: Send module tree GB->>PR: Request package.json for module PR->>GB: Return normalized package GB->>EF: Emit SBOM files GB->>EF: Emit Well Known deactivate GB EF->>Bundler: Finish build deactivate Bundler ``` ## 赞助商

## 许可证 该插件采用 [MIT 许可证](./LICENSE) 授权
标签:CycloneDX, LLM防护, MITM代理, Node.js插件, Rollup, SBOM生成, Vite, 数据可视化, 自动化攻击