-
-
Notifications
You must be signed in to change notification settings - Fork 39
Add dependency graph info to BoM #244
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -24,6 +24,9 @@ const CycloneDXObject = require('./CycloneDXObject') | |||
| const Metadata = require('./Metadata') | ||||
| const Tool = require('./Tool') | ||||
| const program = require('../package.json') | ||||
| const Dependency = require('./Dependency') | ||||
| const parsePackageJsonName = require('parse-packagejson-name') | ||||
| const { PackageURL } = require('packageurl-js') | ||||
|
|
||||
| class Bom extends CycloneDXObject { | ||||
| constructor (pkg, componentType, includeSerialNumber = true, includeLicenseText = true, lockfile) { | ||||
|
|
@@ -38,11 +41,47 @@ class Bom extends CycloneDXObject { | |||
| if (pkg) { | ||||
| this._metadata = this.createMetadata(pkg, componentType) | ||||
| this._components = this.listComponents(pkg, lockfile) | ||||
| this._dependencies = this.listDependencies(pkg) | ||||
| } else { | ||||
| this._components = [] | ||||
| this._dependencies = [] | ||||
| } | ||||
| } | ||||
|
|
||||
| listDependencies (pkg) { | ||||
| const list = [] | ||||
| this.createDependency(pkg, list) | ||||
| return list | ||||
| } | ||||
|
|
||||
| createDependency (pkg, list) { | ||||
| // read-installed with default options marks devDependencies as extraneous | ||||
| // if a package is marked as extraneous, do not include it as a dependency | ||||
| // if -d or --include-dev is specified then all dev dependencies are considered | ||||
| if (pkg.extraneous) return | ||||
| const ref = this.createPackageURL(pkg) | ||||
| const deplist = [] | ||||
| if (pkg._dependencies && Object.keys(pkg._dependencies).length !== 0) { | ||||
| Object.keys(pkg._dependencies) | ||||
| .map(x => pkg.dependencies[x]) | ||||
| .filter(x => x !== undefined && typeof (x) !== 'string') // remove cycles | ||||
| .map(x => deplist.push(new Dependency(this.createPackageURL(x), this.createDependency(x, list)))) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its not handled yet and as I said in the previous comment, creation of BomReference class will solve this issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #244 (comment) |
||||
| list.push(new Dependency(ref, deplist)) | ||||
| } | ||||
| return deplist | ||||
| } | ||||
|
|
||||
| createPackageURL (pkg) { | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗ there is code to crate a PURL already. see cyclonedx-node-module/model/Component.js Line 43 in b8f6940
if you really want to use a PURL as the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the reason I wanted to implement the BomReference class and make use of creation of PURL in both Component and Bom. Is it okay to do something like this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jkowalleck Any suggestions on this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #244 (comment) |
||||
| let purl = null | ||||
| const pkgIdentifier = parsePackageJsonName(pkg.name) | ||||
| let group = (pkgIdentifier.scope) ? pkgIdentifier.scope : undefined | ||||
| if (group) group = '@' + group | ||||
| const name = (pkgIdentifier.fullName) ? pkgIdentifier.fullName : undefined | ||||
| const version = (pkg.version) ? pkg.version : undefined | ||||
| if (name && version) { purl = new PackageURL('npm', group, name, version, null, null).toString() } | ||||
| return purl | ||||
| } | ||||
|
|
||||
| createMetadata (pkg, componentType) { | ||||
| const metadata = new Metadata() | ||||
| metadata.component = new Component(pkg, this.includeLicenseText) | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.