diff --git a/README.md b/README.md
index 291b926d..a5931fd9 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,7 @@ new CycloneDxWebpackPlugin(options?: object)
| **`rootComponentType`** | `{string}` | `"application"` | Set the RootComponent's type.
See [the list of valid values](https://cyclonedx.org/docs/1.4/json/#metadata_component_type). Supported values depend on [CycloneDX-javascript-library]'s enum `ComponentType`. |
| **`rootComponentName`** | optional `{string}` | `undefined` | If `rootComponentAutodetect` is disabled, then this value is assumed as the "name" of the `package.json`. |
| **`rootComponentVersion`** | optional `{string}` | `undefined` | If `rootComponentAutodetect` is disabled, then this value is assumed as the "version" of the `package.json`. |
+| **`postProcess`** | optional `(bom: BOM)=>void` | `undefined` | If `postProcess` is given, bom will be passed to it and can be altered prior to serialization. |
### Example
diff --git a/src/plugin.ts b/src/plugin.ts
index 1059ec15..70375af9 100644
--- a/src/plugin.ts
+++ b/src/plugin.ts
@@ -93,6 +93,13 @@ export interface CycloneDxWebpackPluginOptions {
* @default undefined
*/
rootComponentVersion?: CycloneDxWebpackPlugin['rootComponentVersion']
+
+ /**
+ * If this function is given, bom will be passed to it and can be altered prior to serialization.
+ *
+ * @default undefined
+ */
+ postProcess?: (bom: CDX.Models.Bom) => void
}
/** @public */
@@ -108,6 +115,7 @@ export class CycloneDxWebpackPlugin {
rootComponentType: CDX.Models.Component['type']
rootComponentName: CDX.Models.Component['name'] | undefined
rootComponentVersion: CDX.Models.Component['version'] | undefined
+ postProcess: ((bom: CDX.Models.Bom) => void) | undefined
constructor ({
specVersion = CDX.Spec.Version.v1dot4,
@@ -118,7 +126,8 @@ export class CycloneDxWebpackPlugin {
rootComponentAutodetect = true,
rootComponentType = CDX.Enums.ComponentType.Application,
rootComponentName = undefined,
- rootComponentVersion = undefined
+ rootComponentVersion = undefined,
+ postProcess = undefined
}: CycloneDxWebpackPluginOptions = {}) {
this.specVersion = specVersion
this.reproducibleResults = reproducibleResults
@@ -131,6 +140,7 @@ export class CycloneDxWebpackPlugin {
this.rootComponentType = rootComponentType
this.rootComponentName = rootComponentName
this.rootComponentVersion = rootComponentVersion
+ this.postProcess = postProcess
}
apply (compiler: Compiler): void {
@@ -263,6 +273,10 @@ export class CycloneDxWebpackPlugin {
bom.metadata.component.purl = cdxPurlFactory.makeFromComponent(bom.metadata.component)
bom.metadata.component.bomRef.value = bom.metadata.component.purl?.toString()
}
+
+ if (typeof this.postProcess === 'function') {
+ this.postProcess(bom)
+ }
}
* #makeTools (builder: CDX.Builders.FromNodePackageJson.ToolBuilder): Generator {
diff --git a/tests/integration/__snapshots__/index.test.js.snap b/tests/integration/__snapshots__/index.test.js.snap
index 6929091d..903f57ed 100644
--- a/tests/integration/__snapshots__/index.test.js.snap
+++ b/tests/integration/__snapshots__/index.test.js.snap
@@ -921,6 +921,7 @@ exports[`integration webpack5 with react18 generated json file: dist/.bom/bom.js
\\"group\\": \\"@cyclonedx-webpack-plugin-tests\\",
\\"version\\": \\"0.0.1\\",
\\"bom-ref\\": \\"pkg:npm/%40cyclonedx-webpack-plugin-tests/example-webpack5-react18@0.0.1\\",
+ \\"author\\": \\"testing-post-process-option\\",
\\"description\\": \\"example setup with react and webpack5\\",
\\"purl\\": \\"pkg:npm/%40cyclonedx-webpack-plugin-tests/example-webpack5-react18@0.0.1\\"
}
@@ -1175,6 +1176,7 @@ exports[`integration webpack5 with react18 generated json file: dist/.well-known
\\"group\\": \\"@cyclonedx-webpack-plugin-tests\\",
\\"version\\": \\"0.0.1\\",
\\"bom-ref\\": \\"pkg:npm/%40cyclonedx-webpack-plugin-tests/example-webpack5-react18@0.0.1\\",
+ \\"author\\": \\"testing-post-process-option\\",
\\"description\\": \\"example setup with react and webpack5\\",
\\"purl\\": \\"pkg:npm/%40cyclonedx-webpack-plugin-tests/example-webpack5-react18@0.0.1\\"
}
@@ -1415,6 +1417,7 @@ exports[`integration webpack5 with react18 generated xml file: dist/.bom/bom.xml
+ testing-post-process-option
@cyclonedx-webpack-plugin-tests
example-webpack5-react18
0.0.1
diff --git a/tests/integration/webpack5-react18/config/webpack.config.js b/tests/integration/webpack5-react18/config/webpack.config.js
index 477fedf3..70bc9683 100644
--- a/tests/integration/webpack5-react18/config/webpack.config.js
+++ b/tests/integration/webpack5-react18/config/webpack.config.js
@@ -750,7 +750,10 @@ module.exports = function (webpackEnv) {
}),
new CycloneDxWebpackPlugin({
outputLocation: '.bom',
- reproducibleResults: true
+ reproducibleResults: true,
+ postProcess: (bom) => {
+ bom.metadata.component.author = 'testing-post-process-option'
+ }
})
].filter(Boolean),
// Turn off performance processing because we utilize