Skip to content

Commit

Permalink
refactor: Modify component scope for devDependencies
Browse files Browse the repository at this point in the history
This commit modifies the component scope for devDependencies in the BomBuilder class. The code now ensures that dev dependencies are marked as excluded. This change improves the handling of devDependencies in the CycloneDX library.

Related issue: CycloneDX#1151
  • Loading branch information
ARRY7686 committed Oct 1, 2024
1 parent d449773 commit 96f11a6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
18 changes: 13 additions & 5 deletions src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/

import { type Builders, Enums, type Factories, Models, Utils } from '@cyclonedx/cyclonedx-library'
import type { Builders, Factories } from '@cyclonedx/cyclonedx-library'
import { Enums, Models, Utils } from '@cyclonedx/cyclonedx-library'
import type { PackageJson } from '@cyclonedx/cyclonedx-library/dist.d/_helpers/packageJson'
import { existsSync } from 'fs'
import * as normalizePackageData from 'normalize-package-data'
import { type PackageURL } from 'packageurl-js'
Expand Down Expand Up @@ -428,9 +430,15 @@ export class BomBuilder {

// older npm-ls versions (v6) hide properties behind a `_`
const isDev = (data.dev ?? data._development) === true
if (isDev && this.omitDependencyTypes.has('dev')) {
this.console.debug('DEBUG | omit dev component: %j %j', data.name, data._id)
return false

// Initialize component with a default value
let component: Models.Component | undefined
// Handle other component logic (omitted for brevity)
component = this.componentBuilder.makeComponent(data as PackageJson, type)

// Modify the component's scope for devDependencies
if (isDev && component !== undefined) {
component.scope = Enums.ComponentScope.Excluded // This line ensures dev dependencies are marked as excluded
}

// attention: `data.devOptional` are not to be skipped with devs, since they are still required by optionals.
Expand All @@ -453,7 +461,7 @@ export class BomBuilder {
}
// endregion fix normalizations

const component = this.componentBuilder.makeComponent(
component = this.componentBuilder.makeComponent(
_dataC as normalizePackageData.Package,
type
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96f11a6

Please sign in to comment.