@cdxgen/cdxgen 13.2.0 → 13.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -14
- package/bin/cdxgen.js +310 -138
- package/bin/evinse.js +22 -0
- package/bin/repl.js +86 -0
- package/bin/sign.js +119 -15
- package/bin/tracebom.js +69 -5
- package/bin/validate.js +107 -19
- package/bin/verify.js +172 -63
- package/data/helpers/init.gradle +46 -21
- package/data/remediations.json +85 -0
- package/data/rules/dependency-sources.yaml +67 -0
- package/data/rules/scala-evidence.yaml +115 -0
- package/lib/audit/index.js +38 -6
- package/lib/cli/bomAssembly.js +105 -15
- package/lib/cli/cliOptions.js +93 -1
- package/lib/cli/index.js +156 -58
- package/lib/cli/jsBom.js +99 -53
- package/lib/cli/jvmBom.js +708 -147
- package/lib/cli/managedBom.js +415 -224
- package/lib/cli/nativeBom.js +264 -44
- package/lib/core/activity.js +12 -0
- package/lib/core/env.js +22 -15
- package/lib/core/fs.js +176 -7
- package/lib/core/httpClient.js +159 -24
- package/lib/core/metadataProperties.js +97 -0
- package/lib/core/pluginRun.js +184 -0
- package/lib/core/processTree.js +100 -0
- package/lib/core/projectConfig.js +31 -4
- package/lib/core/runState.js +39 -0
- package/lib/core/toml.js +72 -0
- package/lib/ecosystems/asarutils.js +4 -2
- package/lib/ecosystems/bunutils.js +274 -108
- package/lib/ecosystems/cargoCache.js +231 -8
- package/lib/ecosystems/caxa.js +434 -2
- package/lib/ecosystems/cmakeResolver.js +76 -21
- package/lib/ecosystems/cppBuildContext.js +631 -0
- package/lib/ecosystems/cppEvidence.js +399 -51
- package/lib/ecosystems/cppIncludeResolver.js +294 -0
- package/lib/ecosystems/denoutils.js +93 -66
- package/lib/ecosystems/ecosystems.js +1983 -793
- package/lib/ecosystems/golem.js +28 -12
- package/lib/ecosystems/gradleutils.js +356 -37
- package/lib/ecosystems/jsEvidence.js +104 -44
- package/lib/ecosystems/kosi.js +31 -7
- package/lib/ecosystems/npmutils.js +174 -9
- package/lib/ecosystems/parsers-dotnet.js +616 -159
- package/lib/ecosystems/parsers-elm.js +46 -28
- package/lib/ecosystems/parsers-gleam.js +3 -4
- package/lib/ecosystems/parsers-go.js +371 -70
- package/lib/ecosystems/parsers-js.js +263 -76
- package/lib/ecosystems/parsers-julia.js +2 -3
- package/lib/ecosystems/parsers-jvm.js +204 -12
- package/lib/ecosystems/parsers-misc.js +929 -216
- package/lib/ecosystems/parsers-python.js +167 -24
- package/lib/ecosystems/parsers-rust.js +28 -22
- package/lib/ecosystems/parsers-terraform.js +1573 -19
- package/lib/ecosystems/pythonutils.js +102 -6
- package/lib/ecosystems/remote/huggingface.js +3 -0
- package/lib/ecosystems/rubyutils.js +1492 -182
- package/lib/ecosystems/rusi.js +54 -10
- package/lib/ecosystems/sbtutils.js +243 -187
- package/lib/ecosystems/scalacliutils.js +342 -0
- package/lib/ecosystems/scalasem.js +2618 -0
- package/lib/ecosystems/terraformRegistry.js +288 -0
- package/lib/ecosystems/utils.js +2 -0
- package/lib/ecosystems/vendoredCode.js +156 -0
- package/lib/evinser/evinser.js +1008 -191
- package/lib/evinser/swiftsem.js +1914 -302
- package/lib/helpers/agenticToolutils.js +2 -2
- package/lib/helpers/bomSigner.js +1101 -222
- package/lib/inventory/aiCollector.js +4 -1
- package/lib/inventory/analyzer.js +110 -127
- package/lib/inventory/atomUtils.js +703 -43
- package/lib/inventory/auditCategories.js +7 -0
- package/lib/inventory/buildToolRateLimit.js +144 -0
- package/lib/inventory/cacheCommands.js +2 -1
- package/lib/inventory/cdxrs.js +103 -12
- package/lib/inventory/cmakeBuildDirs.js +254 -0
- package/lib/inventory/deps.js +501 -124
- package/lib/inventory/depsUtils.js +183 -11
- package/lib/inventory/display.js +4 -5
- package/lib/inventory/dosai.js +798 -57
- package/lib/inventory/dosaiParsers.js +310 -15
- package/lib/inventory/dynamic.js +90 -6
- package/lib/inventory/evidenceUtils.js +166 -113
- package/lib/inventory/fetchBatch.js +690 -55
- package/lib/inventory/fetchDiskCache.js +597 -0
- package/lib/inventory/forgeEnricher.js +14 -5
- package/lib/inventory/jvmLocalRepos.js +917 -0
- package/lib/inventory/mcpConfigParser.js +2 -3
- package/lib/inventory/parentSelection.js +146 -0
- package/lib/inventory/protobom.js +8 -1
- package/lib/inventory/purl.js +152 -3
- package/lib/inventory/rustFormulationParser.js +3 -4
- package/lib/inventory/sbomDocument.js +2 -70
- package/lib/inventory/scalaCoords.js +153 -0
- package/lib/inventory/source.js +45 -27
- package/lib/inventory/spdx.js +101 -0
- package/lib/inventory/traceRunner.js +295 -25
- package/lib/inventory/tracedCrypto.js +294 -0
- package/lib/managers/binary.js +115 -24
- package/lib/managers/docker.js +467 -46
- package/lib/managers/oci.js +63 -3
- package/lib/parsers/cmakeCache.js +69 -0
- package/lib/parsers/cmakeLists.js +466 -0
- package/lib/parsers/cmakePresets.js +400 -0
- package/lib/parsers/compileCommands.js +557 -0
- package/lib/parsers/largeJson.js +454 -0
- package/lib/parsers/npmrc.js +19 -1
- package/lib/parsers/strictJson.js +322 -0
- package/lib/parsers/terraformConfig.js +1073 -0
- package/lib/parsers/terraformSource.js +652 -0
- package/lib/server/server.js +23 -0
- package/lib/stages/postgen/introspection/markers.js +1 -1
- package/lib/stages/postgen/postgen.js +83 -16
- package/lib/stages/postgen/specVersionCompat.js +32 -0
- package/lib/validator/bomValidator.js +6 -16
- package/lib/validator/index.js +64 -11
- package/lib/validator/reporters/console.js +3 -0
- package/lib/validator/reporters/json.js +2 -0
- package/lib/validator/reporters/sarif.js +7 -0
- package/package.json +23 -23
- package/types/lib/audit/index.d.ts.map +1 -1
- package/types/lib/cli/bomAssembly.d.ts +2 -1
- package/types/lib/cli/bomAssembly.d.ts.map +1 -1
- package/types/lib/cli/cliOptions.d.ts +33 -1
- package/types/lib/cli/cliOptions.d.ts.map +1 -1
- package/types/lib/cli/index.d.ts.map +1 -1
- package/types/lib/cli/jsBom.d.ts.map +1 -1
- package/types/lib/cli/jvmBom.d.ts +24 -1
- package/types/lib/cli/jvmBom.d.ts.map +1 -1
- package/types/lib/cli/managedBom.d.ts +7 -4
- package/types/lib/cli/managedBom.d.ts.map +1 -1
- package/types/lib/cli/nativeBom.d.ts +3 -1
- package/types/lib/cli/nativeBom.d.ts.map +1 -1
- package/types/lib/core/activity.d.ts.map +1 -1
- package/types/lib/core/env.d.ts +9 -0
- package/types/lib/core/env.d.ts.map +1 -1
- package/types/lib/core/fs.d.ts +55 -0
- package/types/lib/core/fs.d.ts.map +1 -1
- package/types/lib/core/httpClient.d.ts +13 -8
- package/types/lib/core/httpClient.d.ts.map +1 -1
- package/types/lib/core/metadataProperties.d.ts +39 -0
- package/types/lib/core/metadataProperties.d.ts.map +1 -0
- package/types/lib/core/pluginRun.d.ts +97 -0
- package/types/lib/core/pluginRun.d.ts.map +1 -0
- package/types/lib/core/processTree.d.ts +36 -0
- package/types/lib/core/processTree.d.ts.map +1 -0
- package/types/lib/core/projectConfig.d.ts +6 -2
- package/types/lib/core/projectConfig.d.ts.map +1 -1
- package/types/lib/core/runState.d.ts +29 -0
- package/types/lib/core/runState.d.ts.map +1 -0
- package/types/lib/core/toml.d.ts +20 -0
- package/types/lib/core/toml.d.ts.map +1 -0
- package/types/lib/ecosystems/asarutils.d.ts.map +1 -1
- package/types/lib/ecosystems/bunutils.d.ts +12 -5
- package/types/lib/ecosystems/bunutils.d.ts.map +1 -1
- package/types/lib/ecosystems/cargoCache.d.ts +12 -0
- package/types/lib/ecosystems/cargoCache.d.ts.map +1 -1
- package/types/lib/ecosystems/caxa.d.ts +14 -0
- package/types/lib/ecosystems/caxa.d.ts.map +1 -1
- package/types/lib/ecosystems/cmakeResolver.d.ts +28 -3
- package/types/lib/ecosystems/cmakeResolver.d.ts.map +1 -1
- package/types/lib/ecosystems/cppBuildContext.d.ts +55 -0
- package/types/lib/ecosystems/cppBuildContext.d.ts.map +1 -0
- package/types/lib/ecosystems/cppEvidence.d.ts +17 -1
- package/types/lib/ecosystems/cppEvidence.d.ts.map +1 -1
- package/types/lib/ecosystems/cppIncludeResolver.d.ts +92 -0
- package/types/lib/ecosystems/cppIncludeResolver.d.ts.map +1 -0
- package/types/lib/ecosystems/denoutils.d.ts +9 -3
- package/types/lib/ecosystems/denoutils.d.ts.map +1 -1
- package/types/lib/ecosystems/ecosystems.d.ts +62 -13
- package/types/lib/ecosystems/ecosystems.d.ts.map +1 -1
- package/types/lib/ecosystems/golem.d.ts.map +1 -1
- package/types/lib/ecosystems/gradleutils.d.ts +70 -4
- package/types/lib/ecosystems/gradleutils.d.ts.map +1 -1
- package/types/lib/ecosystems/jsEvidence.d.ts +5 -2
- package/types/lib/ecosystems/jsEvidence.d.ts.map +1 -1
- package/types/lib/ecosystems/kosi.d.ts +13 -0
- package/types/lib/ecosystems/kosi.d.ts.map +1 -1
- package/types/lib/ecosystems/npmutils.d.ts +57 -0
- package/types/lib/ecosystems/npmutils.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-dotnet.d.ts +118 -4
- package/types/lib/ecosystems/parsers-dotnet.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-elm.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-gleam.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-go.d.ts +54 -2
- package/types/lib/ecosystems/parsers-go.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-js.d.ts +16 -5
- package/types/lib/ecosystems/parsers-js.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-julia.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-jvm.d.ts +46 -1
- package/types/lib/ecosystems/parsers-jvm.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-misc.d.ts +70 -4
- package/types/lib/ecosystems/parsers-misc.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-python.d.ts +53 -3
- package/types/lib/ecosystems/parsers-python.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-rust.d.ts.map +1 -1
- package/types/lib/ecosystems/parsers-terraform.d.ts +38 -21
- package/types/lib/ecosystems/parsers-terraform.d.ts.map +1 -1
- package/types/lib/ecosystems/pythonutils.d.ts +27 -2
- package/types/lib/ecosystems/pythonutils.d.ts.map +1 -1
- package/types/lib/ecosystems/remote/huggingface.d.ts.map +1 -1
- package/types/lib/ecosystems/rubyutils.d.ts +164 -3
- package/types/lib/ecosystems/rubyutils.d.ts.map +1 -1
- package/types/lib/ecosystems/rusi.d.ts +13 -0
- package/types/lib/ecosystems/rusi.d.ts.map +1 -1
- package/types/lib/ecosystems/sbtutils.d.ts +88 -2
- package/types/lib/ecosystems/sbtutils.d.ts.map +1 -1
- package/types/lib/ecosystems/scalacliutils.d.ts +56 -0
- package/types/lib/ecosystems/scalacliutils.d.ts.map +1 -0
- package/types/lib/ecosystems/scalasem.d.ts +311 -0
- package/types/lib/ecosystems/scalasem.d.ts.map +1 -0
- package/types/lib/ecosystems/terraformRegistry.d.ts +9 -0
- package/types/lib/ecosystems/terraformRegistry.d.ts.map +1 -0
- package/types/lib/ecosystems/utils.d.ts +2 -2
- package/types/lib/ecosystems/utils.d.ts.map +1 -1
- package/types/lib/ecosystems/vendoredCode.d.ts +32 -0
- package/types/lib/ecosystems/vendoredCode.d.ts.map +1 -0
- package/types/lib/evinser/evinser.d.ts +132 -15
- package/types/lib/evinser/evinser.d.ts.map +1 -1
- package/types/lib/evinser/swiftsem.d.ts +280 -15
- package/types/lib/evinser/swiftsem.d.ts.map +1 -1
- package/types/lib/helpers/bomSigner.d.ts +182 -13
- package/types/lib/helpers/bomSigner.d.ts.map +1 -1
- package/types/lib/inventory/aiCollector.d.ts.map +1 -1
- package/types/lib/inventory/analyzer.d.ts.map +1 -1
- package/types/lib/inventory/atomUtils.d.ts +219 -5
- package/types/lib/inventory/atomUtils.d.ts.map +1 -1
- package/types/lib/inventory/auditCategories.d.ts +3 -0
- package/types/lib/inventory/auditCategories.d.ts.map +1 -1
- package/types/lib/inventory/buildToolRateLimit.d.ts +38 -0
- package/types/lib/inventory/buildToolRateLimit.d.ts.map +1 -0
- package/types/lib/inventory/cacheCommands.d.ts +2 -1
- package/types/lib/inventory/cacheCommands.d.ts.map +1 -1
- package/types/lib/inventory/cdxrs.d.ts +8 -3
- package/types/lib/inventory/cdxrs.d.ts.map +1 -1
- package/types/lib/inventory/cmakeBuildDirs.d.ts +58 -0
- package/types/lib/inventory/cmakeBuildDirs.d.ts.map +1 -0
- package/types/lib/inventory/deps.d.ts +59 -1
- package/types/lib/inventory/deps.d.ts.map +1 -1
- package/types/lib/inventory/depsUtils.d.ts +15 -0
- package/types/lib/inventory/depsUtils.d.ts.map +1 -1
- package/types/lib/inventory/display.d.ts.map +1 -1
- package/types/lib/inventory/dosai.d.ts +121 -9
- package/types/lib/inventory/dosai.d.ts.map +1 -1
- package/types/lib/inventory/dosaiParsers.d.ts +53 -7
- package/types/lib/inventory/dosaiParsers.d.ts.map +1 -1
- package/types/lib/inventory/dynamic.d.ts +10 -0
- package/types/lib/inventory/dynamic.d.ts.map +1 -1
- package/types/lib/inventory/evidenceUtils.d.ts +19 -4
- package/types/lib/inventory/evidenceUtils.d.ts.map +1 -1
- package/types/lib/inventory/fetchBatch.d.ts +83 -14
- package/types/lib/inventory/fetchBatch.d.ts.map +1 -1
- package/types/lib/inventory/fetchDiskCache.d.ts +169 -0
- package/types/lib/inventory/fetchDiskCache.d.ts.map +1 -0
- package/types/lib/inventory/forgeEnricher.d.ts.map +1 -1
- package/types/lib/inventory/jvmLocalRepos.d.ts +178 -0
- package/types/lib/inventory/jvmLocalRepos.d.ts.map +1 -0
- package/types/lib/inventory/mcpConfigParser.d.ts.map +1 -1
- package/types/lib/inventory/parentSelection.d.ts +34 -0
- package/types/lib/inventory/parentSelection.d.ts.map +1 -0
- package/types/lib/inventory/plugins.d.ts.map +1 -1
- package/types/lib/inventory/protobom.d.ts.map +1 -1
- package/types/lib/inventory/purl.d.ts +71 -2
- package/types/lib/inventory/purl.d.ts.map +1 -1
- package/types/lib/inventory/rustFormulationParser.d.ts.map +1 -1
- package/types/lib/inventory/sbomDocument.d.ts.map +1 -1
- package/types/lib/inventory/scalaCoords.d.ts +80 -0
- package/types/lib/inventory/scalaCoords.d.ts.map +1 -0
- package/types/lib/inventory/source.d.ts.map +1 -1
- package/types/lib/inventory/spdx.d.ts +9 -0
- package/types/lib/inventory/spdx.d.ts.map +1 -1
- package/types/lib/inventory/traceRunner.d.ts +59 -1
- package/types/lib/inventory/traceRunner.d.ts.map +1 -1
- package/types/lib/inventory/tracedCrypto.d.ts +42 -0
- package/types/lib/inventory/tracedCrypto.d.ts.map +1 -0
- package/types/lib/managers/binary.d.ts +30 -1
- package/types/lib/managers/binary.d.ts.map +1 -1
- package/types/lib/managers/docker.d.ts +29 -0
- package/types/lib/managers/docker.d.ts.map +1 -1
- package/types/lib/managers/oci.d.ts +17 -1
- package/types/lib/managers/oci.d.ts.map +1 -1
- package/types/lib/parsers/cmakeCache.d.ts +16 -0
- package/types/lib/parsers/cmakeCache.d.ts.map +1 -1
- package/types/lib/parsers/cmakeLists.d.ts +77 -0
- package/types/lib/parsers/cmakeLists.d.ts.map +1 -0
- package/types/lib/parsers/cmakePresets.d.ts +78 -0
- package/types/lib/parsers/cmakePresets.d.ts.map +1 -0
- package/types/lib/parsers/compileCommands.d.ts +115 -0
- package/types/lib/parsers/compileCommands.d.ts.map +1 -0
- package/types/lib/parsers/largeJson.d.ts +52 -0
- package/types/lib/parsers/largeJson.d.ts.map +1 -0
- package/types/lib/parsers/npmrc.d.ts +5 -0
- package/types/lib/parsers/npmrc.d.ts.map +1 -1
- package/types/lib/parsers/strictJson.d.ts +46 -0
- package/types/lib/parsers/strictJson.d.ts.map +1 -0
- package/types/lib/parsers/terraformConfig.d.ts +70 -0
- package/types/lib/parsers/terraformConfig.d.ts.map +1 -0
- package/types/lib/parsers/terraformSource.d.ts +66 -0
- package/types/lib/parsers/terraformSource.d.ts.map +1 -0
- package/types/lib/server/server.d.ts.map +1 -1
- package/types/lib/stages/postgen/postgen.d.ts.map +1 -1
- package/types/lib/stages/postgen/specVersionCompat.d.ts.map +1 -1
- package/types/lib/validator/bomValidator.d.ts.map +1 -1
- package/types/lib/validator/index.d.ts +18 -1
- package/types/lib/validator/index.d.ts.map +1 -1
- package/types/lib/validator/reporters/console.d.ts.map +1 -1
- package/types/lib/validator/reporters/json.d.ts.map +1 -1
- package/types/lib/validator/reporters/sarif.d.ts.map +1 -1
- package/lib/third-party/arborist/snapshots/calc-dep-flags.test.cjs +0 -462
|
@@ -215,6 +215,112 @@ export function propagateRequiredScopeFromDependencies(
|
|
|
215
215
|
return components;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
function isTypeOnlyExcludedComponent(component) {
|
|
219
|
+
if (component?.scope !== "excluded") {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return (
|
|
223
|
+
isNpmTypesOnlyComponent(component) ||
|
|
224
|
+
(component.properties || []).some(
|
|
225
|
+
(property) =>
|
|
226
|
+
property.name === "cdx:npm:package:type-only" &&
|
|
227
|
+
property.value === "true",
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Scopes the dependencies of type-only npm packages as optional.
|
|
234
|
+
*
|
|
235
|
+
* A package imported only for its TypeScript types, like an `@types` package,
|
|
236
|
+
* is erased at compile time, and so is what it depends on unless a runtime
|
|
237
|
+
* package depends on it too. A component below a type-only package becomes
|
|
238
|
+
* optional when no dependency path from a root of the graph reaches it without
|
|
239
|
+
* passing through a type-only package. A component that already has a scope,
|
|
240
|
+
* from its manifest or from usage evidence, keeps it.
|
|
241
|
+
*
|
|
242
|
+
* @param {Object[]} components CycloneDX component objects
|
|
243
|
+
* @param {Object[]} dependencies CycloneDX dependency entries
|
|
244
|
+
* @returns {Object[]} The same component array with scopes updated in place
|
|
245
|
+
*/
|
|
246
|
+
export function markTypeOnlyDependenciesOptional(
|
|
247
|
+
components = [],
|
|
248
|
+
dependencies = [],
|
|
249
|
+
) {
|
|
250
|
+
if (!components?.length || !dependencies?.length) {
|
|
251
|
+
return components;
|
|
252
|
+
}
|
|
253
|
+
const componentByRef = new Map();
|
|
254
|
+
const typeOnlyRefs = new Set();
|
|
255
|
+
for (const component of components) {
|
|
256
|
+
for (const ref of [component?.["bom-ref"], component?.purl]) {
|
|
257
|
+
if (!ref) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const normalizedRef = normalizeBomRef(ref);
|
|
261
|
+
componentByRef.set(normalizedRef, component);
|
|
262
|
+
if (isTypeOnlyExcludedComponent(component)) {
|
|
263
|
+
typeOnlyRefs.add(normalizedRef);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!typeOnlyRefs.size) {
|
|
268
|
+
return components;
|
|
269
|
+
}
|
|
270
|
+
const childrenByRef = new Map();
|
|
271
|
+
const dependentRefs = new Set();
|
|
272
|
+
for (const dependency of dependencies) {
|
|
273
|
+
const ref = normalizeBomRef(dependency?.ref);
|
|
274
|
+
if (!ref) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (!childrenByRef.has(ref)) {
|
|
278
|
+
childrenByRef.set(ref, new Set());
|
|
279
|
+
}
|
|
280
|
+
for (const dependsOnRef of dependency.dependsOn || []) {
|
|
281
|
+
const childRef = normalizeBomRef(dependsOnRef);
|
|
282
|
+
if (childRef && childRef !== ref) {
|
|
283
|
+
childrenByRef.get(ref).add(childRef);
|
|
284
|
+
dependentRefs.add(childRef);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const walk = (startRefs) => {
|
|
289
|
+
const seen = new Set();
|
|
290
|
+
const stack = [...startRefs];
|
|
291
|
+
while (stack.length) {
|
|
292
|
+
const ref = stack.pop();
|
|
293
|
+
if (seen.has(ref)) {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
seen.add(ref);
|
|
297
|
+
for (const childRef of childrenByRef.get(ref) || []) {
|
|
298
|
+
if (!typeOnlyRefs.has(childRef)) {
|
|
299
|
+
stack.push(childRef);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return seen;
|
|
304
|
+
};
|
|
305
|
+
// Every ref nothing depends on is a root, so a partial graph errs towards
|
|
306
|
+
// keeping a component rather than scoping it optional.
|
|
307
|
+
const runtimeRefs = walk(
|
|
308
|
+
[...childrenByRef.keys()].filter(
|
|
309
|
+
(ref) => !dependentRefs.has(ref) && !typeOnlyRefs.has(ref),
|
|
310
|
+
),
|
|
311
|
+
);
|
|
312
|
+
for (const ref of walk(typeOnlyRefs)) {
|
|
313
|
+
if (typeOnlyRefs.has(ref) || runtimeRefs.has(ref)) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const component = componentByRef.get(ref);
|
|
317
|
+
if (component && !component.scope) {
|
|
318
|
+
component.scope = "optional";
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return components;
|
|
322
|
+
}
|
|
323
|
+
|
|
218
324
|
function serviceIdentityKey(service) {
|
|
219
325
|
if (service?.["bom-ref"]) {
|
|
220
326
|
return service["bom-ref"].toLowerCase();
|
|
@@ -395,6 +501,71 @@ export function mergeServices(services, newServices) {
|
|
|
395
501
|
return Array.from(serviceMap.values());
|
|
396
502
|
}
|
|
397
503
|
|
|
504
|
+
// Descriptive fields, each listed with the raw spellings that collectors set
|
|
505
|
+
// before component conversion. Conversion prefers the converted `licenses`
|
|
506
|
+
// over a raw `license`, and a raw `author` over `authors`, so a field is only
|
|
507
|
+
// filled in, under the spelling the duplicate uses, when the retained
|
|
508
|
+
// component has no spelling of it.
|
|
509
|
+
const DESCRIPTIVE_FIELDS = [
|
|
510
|
+
["description"],
|
|
511
|
+
["publisher"],
|
|
512
|
+
["copyright"],
|
|
513
|
+
["authors", "author"],
|
|
514
|
+
["licenses", "license"],
|
|
515
|
+
];
|
|
516
|
+
|
|
517
|
+
const hasFieldValue = (value) =>
|
|
518
|
+
value !== undefined &&
|
|
519
|
+
value !== null &&
|
|
520
|
+
value !== "" &&
|
|
521
|
+
!(Array.isArray(value) && !value.length);
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Carry the descriptive metadata of a duplicate sighting over to the retained
|
|
525
|
+
* component. A lockfile is usually parsed first and knows only the identity,
|
|
526
|
+
* while a manifest seen later, such as a gemspec, knows the description,
|
|
527
|
+
* authors, licenses, and project links (discussion 4389).
|
|
528
|
+
*
|
|
529
|
+
* The retained sighting keeps its own values. Lists are not unioned because
|
|
530
|
+
* two sightings spell the same fact differently: one license as an SPDX id and
|
|
531
|
+
* as a name, or as an expression that must never share the `licenses` array
|
|
532
|
+
* with license objects. External references are unioned, since each one is a
|
|
533
|
+
* distinct link.
|
|
534
|
+
*
|
|
535
|
+
* @param {object} existingComponent Retained component, updated in place
|
|
536
|
+
* @param {object} comp Duplicate sighting of the same component
|
|
537
|
+
*/
|
|
538
|
+
function mergeDescriptiveFields(existingComponent, comp) {
|
|
539
|
+
for (const spellings of DESCRIPTIVE_FIELDS) {
|
|
540
|
+
if (
|
|
541
|
+
spellings.some((spelling) => hasFieldValue(existingComponent[spelling]))
|
|
542
|
+
) {
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
const spelling = spellings.find((aspelling) =>
|
|
546
|
+
hasFieldValue(comp[aspelling]),
|
|
547
|
+
);
|
|
548
|
+
if (spelling) {
|
|
549
|
+
existingComponent[spelling] = comp[spelling];
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (!comp.externalReferences?.length) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
// A copy, as the array may be shared with another sighting
|
|
556
|
+
const existingRefs = [...(existingComponent.externalReferences || [])];
|
|
557
|
+
for (const newref of comp.externalReferences) {
|
|
558
|
+
if (
|
|
559
|
+
!existingRefs.some(
|
|
560
|
+
(ref) => ref.type === newref.type && ref.url === newref.url,
|
|
561
|
+
)
|
|
562
|
+
) {
|
|
563
|
+
existingRefs.push(newref);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
existingComponent.externalReferences = existingRefs;
|
|
567
|
+
}
|
|
568
|
+
|
|
398
569
|
/**
|
|
399
570
|
* Trim duplicate components by retaining all the properties
|
|
400
571
|
*
|
|
@@ -403,18 +574,21 @@ export function mergeServices(services, newServices) {
|
|
|
403
574
|
* @returns {Array} Filtered components
|
|
404
575
|
*/
|
|
405
576
|
export function trimComponents(components) {
|
|
406
|
-
|
|
407
|
-
|
|
577
|
+
// The keys come from the scanned manifests. In a plain object, a key such as
|
|
578
|
+
// `__proto__` would resolve to Object.prototype and the merge below would
|
|
579
|
+
// write to it.
|
|
580
|
+
const keyCache = new Map();
|
|
408
581
|
for (const comp of components) {
|
|
409
582
|
const key = (
|
|
410
583
|
comp.purl ||
|
|
411
584
|
comp["bom-ref"] ||
|
|
412
585
|
comp.name + comp.version
|
|
413
586
|
).toLowerCase();
|
|
414
|
-
if (!keyCache
|
|
415
|
-
keyCache
|
|
587
|
+
if (!keyCache.has(key)) {
|
|
588
|
+
keyCache.set(key, comp);
|
|
416
589
|
} else {
|
|
417
|
-
const existingComponent = keyCache
|
|
590
|
+
const existingComponent = keyCache.get(key);
|
|
591
|
+
mergeDescriptiveFields(existingComponent, comp);
|
|
418
592
|
// We need to retain any properties that differ
|
|
419
593
|
if (comp.properties) {
|
|
420
594
|
if (existingComponent.properties) {
|
|
@@ -530,10 +704,7 @@ export function trimComponents(components) {
|
|
|
530
704
|
}
|
|
531
705
|
}
|
|
532
706
|
}
|
|
533
|
-
|
|
534
|
-
filteredComponents.push(keyCache[akey]);
|
|
535
|
-
}
|
|
536
|
-
return filteredComponents;
|
|
707
|
+
return Array.from(keyCache.values());
|
|
537
708
|
}
|
|
538
709
|
|
|
539
710
|
/**
|
|
@@ -603,7 +774,8 @@ export function isPartialTree(dependencies, componentsCount = 1) {
|
|
|
603
774
|
let isCbom = false;
|
|
604
775
|
let parentsWithChildsCount = 0;
|
|
605
776
|
for (const adep of dependencies) {
|
|
606
|
-
|
|
777
|
+
// Producers such as protobuf omit empty dependsOn lists
|
|
778
|
+
if (adep?.dependsOn?.length > 0) {
|
|
607
779
|
parentsWithChildsCount++;
|
|
608
780
|
}
|
|
609
781
|
if (!isCbom && adep?.provides?.length > 0) {
|
|
@@ -640,7 +812,7 @@ export function recomputeScope(pkgList, dependencies) {
|
|
|
640
812
|
}
|
|
641
813
|
for (const adep of dependencies) {
|
|
642
814
|
if (requiredPkgs[adep.ref]) {
|
|
643
|
-
for (const ado of adep.dependsOn) {
|
|
815
|
+
for (const ado of adep.dependsOn || []) {
|
|
644
816
|
requiredPkgs[ado] = true;
|
|
645
817
|
}
|
|
646
818
|
}
|
package/lib/inventory/display.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import process from "node:process";
|
|
4
3
|
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
import { safeExistsSync } from "../core/fs.js";
|
|
12
11
|
import { toCamel } from "../core/paths.js";
|
|
13
12
|
import { detectAiModelVariants } from "./aiModelVariants.js";
|
|
13
|
+
import { readReachablesSlices } from "./atomUtils.js";
|
|
14
14
|
import { formatOccurrenceEvidence } from "./evidenceUtils.js";
|
|
15
15
|
import {
|
|
16
16
|
formatHbomHardwareClassSummary,
|
|
@@ -1407,12 +1407,11 @@ export function printReachables(sliceArtefacts) {
|
|
|
1407
1407
|
return;
|
|
1408
1408
|
}
|
|
1409
1409
|
const purlCounts = {};
|
|
1410
|
-
const reachablesSlices =
|
|
1411
|
-
|
|
1412
|
-
);
|
|
1410
|
+
const reachablesSlices = readReachablesSlices(reachablesSlicesFile);
|
|
1411
|
+
// undefined when the slices file was unreadable; readReachablesSlices warned.
|
|
1413
1412
|
const rflows = Array.isArray(reachablesSlices)
|
|
1414
1413
|
? reachablesSlices
|
|
1415
|
-
: reachablesSlices
|
|
1414
|
+
: reachablesSlices?.reachables || [];
|
|
1416
1415
|
for (const areachable of rflows) {
|
|
1417
1416
|
const purls = areachable.purls || [];
|
|
1418
1417
|
for (const apurl of purls) {
|