Skip to content

Commit 3877896

Browse files
committed
fix(node): Fix a mistake in undoDeduplication()
ORT runs `npm list --depth Infinity` to obtain a de-duplicated or rather truncated dependency tree. The data model for the tree nodes is the `ModuleInfo` class. Truncated nodes have the dependencies stripped, which is why `undoDeduplication()` patches up any truncated node by copying the `dependencies` from a non-truncated node corresponding to the same package. However, the truncated node not just lacks the dependencies, but also has further properties not set. So, adjust the logic to cover all properties to ensure each truncated node is patched up completely. This fixes an issue where a patched node accidentally had `resolved` set to `null`, which lead to `isProject` returning `false`, which in turn lead to `NpmDependencyHandler.createPackage()` returning `null`. As result the analyzer aborted with [^1]. [^1]: Exception in thread "main" java.lang.IllegalArgumentException: The following references do not actually refer to packages: '$PACKAGE'. at org.ossreviewtoolkit.model.utils.DependencyGraphBuilder .checkReferences() Signed-off-by: Frank Viernau <frank.viernau@gmail.com>
1 parent 5dc8acb commit 3877896

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • plugins/package-managers/node/src/main/kotlin/npm

plugins/package-managers/node/src/main/kotlin/npm/Npm.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,13 @@ private fun ModuleInfo.undoDeduplication(): ModuleInfo {
244244

245245
fun ModuleInfo.undoDeduplicationRec(ancestorsIds: Set<String> = emptySet()): ModuleInfo {
246246
val dependencyAncestorIds = ancestorsIds + setOfNotNull(id)
247-
val dependencies = (replacements[id] ?: this)
248-
.dependencies
249-
.filter { it.value.id !in dependencyAncestorIds } // break cycles.
250-
.mapValues { it.value.undoDeduplicationRec(dependencyAncestorIds) }
247+
val replacement = replacements[id] ?: this
251248

252-
return copy(dependencies = dependencies)
249+
return replacement.copy(
250+
dependencies = replacement.dependencies
251+
.filter { it.value.id !in dependencyAncestorIds } // break cycles.
252+
.mapValues { it.value.undoDeduplicationRec(dependencyAncestorIds) }
253+
)
253254
}
254255

255256
return undoDeduplicationRec()

0 commit comments

Comments
 (0)