Skip to content

Commit ba005b6

Browse files
committed
add the option
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent e5f4deb commit ba005b6

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

Diff for: HISTORY.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ All notable changes to this project will be documented in this file.
66

77
* Added
88
* Components' install path/location will be visible in the SBOM result ([#305] via [#308])
9+
* new CLI option `--deduplicate-components` ... write something([#306] via [#309])
910

1011
[#305]: https://github.com/CycloneDX/cyclonedx-node-npm/issues/305
1112
[#308]: https://github.com/CycloneDX/cyclonedx-node-npm/pull/308
13+
[#306]: https://github.com/CycloneDX/cyclonedx-node-npm/issues/306
14+
[#309]: https://github.com/CycloneDX/cyclonedx-node-npm/pull/309
1215

1316
## 1.4.1 - 2022-11-06
1417

Diff for: README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ Options:
7777
This might be used, if "npm install" was run with "--force" or "--legacy-peer-deps".
7878
(default: false)
7979
--package-lock-only Whether to only use the lock file, ignoring "node_modules".
80-
This means the output will be based only on the few details in and the tree described by the "npm-shrinkwrap.json" or "package-lock.json", rather than the contents of "node_modules" directory.
80+
Enabling this feature means the output will be based only on the few details in and the tree described by the "npm-shrinkwrap.json" or "package-lock.json", rather than the contents of "node_modules" directory.
8181
(default: false)
8282
--omit <type...> Dependency types to omit from the installation tree.
8383
(can be set multiple times)
8484
(choices: "dev", "optional", "peer", default: "dev" if the NODE_ENV environment variable is set to "production", otherwise empty)
8585
--flatten-components Whether to flatten the components.
86-
This means the actual nesting of node packages is not represented in the SBOM result.
86+
Enabling this feature means the actual nesting of node packages is not represented in the SBOM result.
87+
(default: false)
88+
--deduplicate-components Whether to artificially de-duplicate the node packages.
89+
Enabling this feature implies option "--flatten-components=true"
90+
(default: false)
8791
--short-PURLs Omit all qualifiers from PackageURLs.
88-
This causes information loss in trade of shorter PURLs, which might improve digesting these strings.
92+
Enabling this feature causes information loss in trade of shorter PURLs, which might improve digesting these strings.
8993
(default: false)
9094
--spec-version <version> Which version of CycloneDX spec to use.
9195
(choices: "1.2", "1.3", "1.4", default: "1.4")

Diff for: docs/component_deduplication.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Component De-duplication
2+
3+
TODO

Diff for: src/builders.ts

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface BomBuilderOptions {
3535
omitDependencyTypes?: Iterable<OmittableDependencyTypes>
3636
reproducible?: BomBuilder['reproducible']
3737
flattenComponents?: BomBuilder['flattenComponents']
38+
deduplicateComponents?: BomBuilder['deduplicateComponents']
3839
shortPURLs?: BomBuilder['shortPURLs']
3940
}
4041

@@ -54,6 +55,7 @@ export class BomBuilder {
5455
omitDependencyTypes: Set<OmittableDependencyTypes>
5556
reproducible: boolean
5657
flattenComponents: boolean
58+
deduplicateComponents: boolean
5759
shortPURLs: boolean
5860

5961
console: Console
@@ -77,6 +79,7 @@ export class BomBuilder {
7779
this.omitDependencyTypes = new Set(options.omitDependencyTypes ?? [])
7880
this.reproducible = options.reproducible ?? false
7981
this.flattenComponents = options.flattenComponents ?? false
82+
this.deduplicateComponents = options.deduplicateComponents ?? false
8083
this.shortPURLs = options.shortPURLs ?? false
8184

8285
this.console = console_
@@ -249,6 +252,7 @@ export class BomBuilder {
249252
component.properties.forEach(p => {
250253
if (p.name === PropertyNames.PackageBundled) {
251254
// bundle-markers have no value when components are flattened, because it is impossible to identify where a component was bundled into.
255+
// this is no lnger true after this got implemented: https://github.com/CycloneDX/cyclonedx-node-npm/issues/305
252256
component.properties.delete(p)
253257
}
254258
})
@@ -257,6 +261,9 @@ export class BomBuilder {
257261
bom.components.add(component)
258262
}
259263
}
264+
if (this.deduplicateComponents) {
265+
// TODO
266+
}
260267
}
261268

262269
// endregion components

Diff for: src/cli.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface CommandOptions {
4343
omit: Omittable[]
4444
specVersion: Spec.Version
4545
flattenComponents: boolean
46+
deduplicateComponents: boolean
4647
shortPURLs: boolean
4748
outputReproducible: boolean
4849
outputFormat: OutputFormat
@@ -67,7 +68,7 @@ function makeCommand (process: NodeJS.Process): Command {
6768
new Option(
6869
'--package-lock-only',
6970
'Whether to only use the lock file, ignoring "node_modules".\n' +
70-
'This means the output will be based only on the few details in and the tree described by the "npm-shrinkwrap.json" or "package-lock.json", rather than the contents of "node_modules" directory.'
71+
'Enabling this feature means the output will be based only on the few details in and the tree described by the "npm-shrinkwrap.json" or "package-lock.json", rather than the contents of "node_modules" directory.'
7172
).default(false)
7273
).addOption(
7374
new Option(
@@ -86,13 +87,19 @@ function makeCommand (process: NodeJS.Process): Command {
8687
new Option(
8788
'--flatten-components',
8889
'Whether to flatten the components.\n' +
89-
'This means the actual nesting of node packages is not represented in the SBOM result.'
90+
'Enabling this feature means the actual nesting of node packages is not represented in the SBOM result.'
91+
).default(false)
92+
).addOption(
93+
new Option(
94+
'--deduplicate-components',
95+
'Whether to artificially de-duplicate the node packages.\n' +
96+
'Enabling this feature implies option "--flatten-components=true"'
9097
).default(false)
9198
).addOption(
9299
new Option(
93100
'--short-PURLs',
94101
'Omit all qualifiers from PackageURLs.\n' +
95-
'This causes information loss in trade of shorter PURLs, which might improve digesting these strings.'
102+
'Enabling this feature causes information loss in trade of shorter PURLs, which might improve digesting these strings.'
96103
).default(false)
97104
).addOption(
98105
new Option(
@@ -107,7 +114,7 @@ function makeCommand (process: NodeJS.Process): Command {
107114
new Option(
108115
'--output-reproducible',
109116
'Whether to go the extra mile and make the output reproducible.\n' +
110-
'This requires more resources, and might result in loss of time- and random-based-values.'
117+
'Enabling this feature requires more resources, and might result in loss of time- and random-based-values.'
111118
).env(
112119
'BOM_REPRODUCIBLE'
113120
)
@@ -178,6 +185,10 @@ export function run (process: NodeJS.Process): void {
178185
program.parse(process.argv)
179186

180187
const options: CommandOptions = program.opts()
188+
if (options.deduplicateComponents && !options.flattenComponents) {
189+
myConsole.info('INFO | Found option --deduplicate-components=true - therefore, forced option --flatten-components=true')
190+
options.flattenComponents = true
191+
}
181192
myConsole.debug('DEBUG | options: %j', options)
182193

183194
const packageFile = resolve(process.cwd(), program.args[0] ?? 'package.json')
@@ -221,6 +232,7 @@ export function run (process: NodeJS.Process): void {
221232
omitDependencyTypes: options.omit,
222233
reproducible: options.outputReproducible,
223234
flattenComponents: options.flattenComponents,
235+
deduplicateComponents: options.deduplicateComponents,
224236
shortPURLs: options.shortPURLs
225237
},
226238
myConsole

0 commit comments

Comments
 (0)