Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tools as components #1235

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
}
],
"dependencies": {
"@cyclonedx/cyclonedx-library": "^6.11.0",
"@cyclonedx/cyclonedx-library": "^7.0.0-beta.1",
jkowalleck marked this conversation as resolved.
Show resolved Hide resolved
"commander": "^10.0.0",
"normalize-package-data": "^3||^4||^5||^6",
"packageurl-js": "^1.2.1",
"packageurl-js": "^2.0.0",
"xmlbuilder2": "^3.0.2"
},
"devDependencies": {
Expand Down
21 changes: 9 additions & 12 deletions src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
type AllComponents = Map<cPath, Models.Component>

export class BomBuilder {
toolBuilder: Builders.FromNodePackageJson.ToolBuilder
componentBuilder: Builders.FromNodePackageJson.ComponentBuilder
treeBuilder: TreeBuilder
purlFactory: Factories.FromNodePackageJson.PackageUrlFactory
Expand All @@ -61,14 +60,12 @@
console: Console

constructor (
toolBuilder: BomBuilder['toolBuilder'],
componentBuilder: BomBuilder['componentBuilder'],
treeBuilder: BomBuilder['treeBuilder'],
purlFactory: BomBuilder['purlFactory'],
options: BomBuilderOptions,
console_: BomBuilder['console']
) {
this.toolBuilder = toolBuilder
this.componentBuilder = componentBuilder
this.treeBuilder = treeBuilder
this.purlFactory = purlFactory
Expand Down Expand Up @@ -227,14 +224,14 @@

bom.metadata.component = rootComponent

bom.metadata.tools.add(new Models.Tool({
name: 'npm',
bom.metadata.tools.components.add(new Models.Component(
Enums.ComponentType.Application, 'npm' ,{

Check failure on line 228 in src/builders.ts

View workflow job for this annotation

GitHub Actions / test standards

There should be no space before ','

Check failure on line 228 in src/builders.ts

View workflow job for this annotation

GitHub Actions / test standards

A space is required after ','
version: npmVersion // use the self-proclaimed `version`

Check failure on line 229 in src/builders.ts

View workflow job for this annotation

GitHub Actions / test standards

Expected indentation of 8 spaces but found 6
// omit `vendor` and `externalReferences`, because we cannot be sure about the used tool's actual origin
// omit `group` and `externalReferences`, because we cannot be sure about the used tool's actual origin
// omit `hashes`, because unfortunately there is no agreed process of generating them
}))

Check failure on line 232 in src/builders.ts

View workflow job for this annotation

GitHub Actions / test standards

Expected indentation of 6 spaces but found 4
for (const tool of this.makeTools()) {
bom.metadata.tools.add(tool)
for (const toolC of this.makeToolCs()) {
bom.metadata.tools.components.add(toolC)
}

if (!this.reproducible) {
Expand Down Expand Up @@ -582,7 +579,7 @@
}
}

private * makeTools (): Generator<Models.Tool> {
private * makeToolCs (): Generator<Models.Component> {
const packageJsonPaths = [path.resolve(module.path, '..', 'package.json')]

const libs = [
Expand All @@ -605,9 +602,9 @@
for (const packageJsonPath of packageJsonPaths) {
const packageData: object = loadJsonFile(packageJsonPath) ?? {}
normalizePackageData(packageData /* add debug for warnings? */)
const tool = this.toolBuilder.makeTool(packageData)
if (tool !== undefined) {
yield tool
const toolC = this.componentBuilder.makeComponent(packageData)
if (toolC !== undefined) {
yield toolC
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,10 @@ export async function run (process: NodeJS.Process): Promise<number> {
throw new Error('missing evidence')
}

const extRefFactory = new Factories.FromNodePackageJson.ExternalReferenceFactory()

myConsole.log('LOG | gathering BOM data ...')
const bom = new BomBuilder(
new Builders.FromNodePackageJson.ToolBuilder(extRefFactory),
new Builders.FromNodePackageJson.ComponentBuilder(
extRefFactory,
new Factories.FromNodePackageJson.ExternalReferenceFactory(),
new Factories.LicenseFactory()
),
new TreeBuilder(),
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.

Loading
Loading