Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.

<!-- unreleased changes go here -->

* Added
* Configuration option for `rootComponentBuildSystem` ([#1344] via [#1349])

[#1344]: https://github.com/CycloneDX/cyclonedx-webpack-plugin/issues/1344
[#1349]: https://github.com/CycloneDX/cyclonedx-webpack-plugin/pull/1349

## 3.15.1 - 2024-12-03

* Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ new CycloneDxWebpackPlugin(options?: object)
| **`rootComponentType`** | `{string}` | `"application"` | Set the RootComponent's type.<br/>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`. |
| **`rootComponentBuildSystem`** | optional `{string}` | `undefined` | Set's the URL for the RootComponent's External References' build-system. |
| **`collectEvidence`** | `{boolean}` | `false` | Whether to collect (license) evidence and attach them to the resulting SBOM. |

### Example
Expand Down
1 change: 1 addition & 0 deletions examples/simple/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const cycloneDxWebpackPluginOptions = {
rootComponentType: 'application',
rootComponentName: undefined,
rootComponentVersion: undefined,
rootComponentBuildSystem: undefined,
collectEvidence: true
}

Expand Down
28 changes: 27 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export interface CycloneDxWebpackPluginOptions {
*/
rootComponentVersion?: CycloneDxWebpackPlugin['rootComponentVersion']

/**
* Set the externalReference URL for the build-system for the RootComponent.
* See {@link https://cyclonedx.org/docs/1.6/json/#metadata_component_externalReferences}.
*/
rootComponentBuildSystem?: CycloneDxWebpackPlugin['rootComponentBuildSystem']

/**
* Whether to collect (license) evidence and attach them to the resulting SBOM.
*
Expand Down Expand Up @@ -135,6 +141,7 @@ export class CycloneDxWebpackPlugin {
rootComponentType: CDX.Models.Component['type']
rootComponentName: CDX.Models.Component['name'] | undefined
rootComponentVersion: CDX.Models.Component['version'] | undefined
rootComponentBuildSystem: CDX.Models.ExternalReference['url'] | undefined

collectEvidence: boolean

Expand All @@ -149,6 +156,7 @@ export class CycloneDxWebpackPlugin {
rootComponentType = CDX.Enums.ComponentType.Application,
rootComponentName = undefined,
rootComponentVersion = undefined,
rootComponentBuildSystem = undefined,
collectEvidence = false
}: CycloneDxWebpackPluginOptions = {}) {
this.specVersion = specVersion
Expand All @@ -163,6 +171,7 @@ export class CycloneDxWebpackPlugin {
this.rootComponentType = rootComponentType
this.rootComponentName = rootComponentName
this.rootComponentVersion = rootComponentVersion
this.rootComponentBuildSystem = rootComponentBuildSystem
this.collectEvidence = collectEvidence
}

Expand Down Expand Up @@ -244,6 +253,7 @@ export class CycloneDxWebpackPlugin {
// metadata matches this exact component.
// -> so the component is actually treated as the root component.
thisLogger.debug('update bom.metadata.component - replace', bom.metadata.component, 'with', component)
this.#addRootComponentExtRefs(component, thisLogger)
bom.metadata.component = component
} else {
thisLogger.debug('add to bom.components', component)
Expand Down Expand Up @@ -306,6 +316,20 @@ export class CycloneDxWebpackPlugin {
)
}

#addRootComponentExtRefs (component: CDX.Models.Component | undefined, logger: WebpackLogger): void {
if (component === undefined) { return }
if (typeof this.rootComponentBuildSystem === 'string' && this.rootComponentBuildSystem.length > 0) {
component.externalReferences.add(
new CDX.Models.ExternalReference(
this.rootComponentBuildSystem,
CDX.Enums.ExternalReferenceType.BuildSystem,
{ comment: 'as declared via cyclonedx-webpack-plugin config "rootComponentBuildSystem"' }
)
)
logger.debug('Added rootComponent BuildSystem URL:', this.rootComponentBuildSystem)
}
}

#makeRootComponent (
path: string,
builder: CDX.Builders.FromNodePackageJson.ComponentBuilder,
Expand All @@ -316,7 +340,9 @@ export class CycloneDxWebpackPlugin {
: { name: this.rootComponentName, version: this.rootComponentVersion }
if (thisPackageJson === undefined) { return undefined }
normalizePackageJson(thisPackageJson, w => { logger.debug('normalizePackageJson from PkgPath', path, 'caused:', w) })
return builder.makeComponent(thisPackageJson)
const component = builder.makeComponent(thisPackageJson)
this.#addRootComponentExtRefs(component, logger)
return component
}

#finalizeBom (
Expand Down
Loading