Skip to content

Commit

Permalink
refactor: call addRootComponentExtRefs() only once (#1358)
Browse files Browse the repository at this point in the history
followup of #1355

Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck authored Jan 30, 2025
1 parent cadda7b commit 8dc54dd
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ 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 @@ -323,8 +322,7 @@ export class CycloneDxWebpackPlugin {
)
}

#addRootComponentExtRefs (component: CDX.Models.Component | undefined, logger: WebpackLogger): void {
if (component === undefined) { return }
#addRootComponentExtRefs (component: CDX.Models.Component, logger: WebpackLogger): void {
if (
typeof this.rootComponentBuildSystem === 'string' &&
this.rootComponentBuildSystem.length > 0 &&
Expand Down Expand Up @@ -371,9 +369,7 @@ 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) })
const component = builder.makeComponent(thisPackageJson)
this.#addRootComponentExtRefs(component, logger)
return component
return builder.makeComponent(thisPackageJson)
}

#finalizeBom (
Expand All @@ -399,6 +395,7 @@ export class CycloneDxWebpackPlugin {
}

if (bom.metadata.component !== undefined) {
this.#addRootComponentExtRefs(bom.metadata.component, logger)
bom.metadata.component.type = this.rootComponentType
bom.metadata.component.purl = cdxPurlFactory.makeFromComponent(bom.metadata.component)
bom.metadata.component.bomRef.value = bom.metadata.component.purl?.toString()
Expand Down

0 comments on commit 8dc54dd

Please sign in to comment.