Skip to content

Commit 056e1a8

Browse files
committed
Update versions for NPM libs managed in version catalogs
1 parent 7dff49c commit 056e1a8

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/extensions/gradle/Dependency.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ internal fun Dependency.npmModuleId(): ModuleId.Npm {
2323
}
2424

2525
internal fun Dependency.matches(moduleId: ModuleId): Boolean {
26-
return moduleId.group == group && moduleId.name == name
26+
return if ((moduleId is ModuleId.Npm) && (moduleId.group != null)) {
27+
moduleId.let { "@${it.group}/${it.name}" } == name
28+
} else {
29+
moduleId.group == group && moduleId.name == name
30+
}
2731
}

plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionManagementKind.kt

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package de.fayard.refreshVersions.core.internal
22

33
import de.fayard.refreshVersions.core.ModuleId
44
import de.fayard.refreshVersions.core.extensions.gradle.moduleId
5+
import de.fayard.refreshVersions.core.extensions.gradle.npmModuleId
6+
import de.fayard.refreshVersions.core.extensions.gradle.tryExtractingSimpleVersion
57
import de.fayard.refreshVersions.core.internal.VersionManagementKind.Match
68
import de.fayard.refreshVersions.core.internal.VersionManagementKind.NoMatch
79
import org.gradle.api.artifacts.Dependency
@@ -89,15 +91,28 @@ private fun Dependency.hasVersionInVersionCatalog(
8991
versionsCatalogLibraries: Collection<MinimalExternalModuleDependency>,
9092
versionsCatalogPlugins: Set<PluginDependencyCompat> = emptySet()
9193
): Boolean {
92-
if (this !is ExternalDependency) return false
94+
when {
95+
this::class.simpleName == "NpmDependency" -> {
96+
return versionsCatalogLibraries.any {
97+
val moduleId = npmModuleId()
98+
it.module.group == (moduleId.group ?: "<unscoped>") && it.module.name == moduleId.name
99+
&& it.versionConstraint.tryExtractingSimpleVersion() == version
100+
}
101+
}
93102

94-
val matchingLib = versionsCatalogLibraries.any {
95-
it.module.group == group && it.module.name == name && it.versionConstraint == versionConstraint
96-
}
97-
if (matchingLib) return true
103+
this is ExternalDependency -> {
104+
val matchingLib = versionsCatalogLibraries.any {
105+
it.module.group == group && it.module.name == name
106+
&& it.versionConstraint == versionConstraint
107+
}
108+
if (matchingLib) return true
98109

99-
if (name.endsWith(".gradle.plugin").not()) return false
110+
if (name.endsWith(".gradle.plugin").not()) return false
100111

101-
val pluginId = name.substringBeforeLast(".gradle.plugin")
102-
return versionsCatalogPlugins.any { it.pluginId == pluginId && it.version == versionConstraint }
112+
val pluginId = name.substringBeforeLast(".gradle.plugin")
113+
return versionsCatalogPlugins.any { it.pluginId == pluginId && it.version == versionConstraint }
114+
}
115+
116+
else -> return false
117+
}
103118
}

plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal class VersionsCatalogUpdater(
5151
}.mapNotNull { libOrPlugin ->
5252
dependenciesUpdates.firstOrNull {
5353
val moduleId = it.moduleId
54-
(moduleId.name == libOrPlugin.name) && (moduleId.group == libOrPlugin.group)
54+
(moduleId.name == libOrPlugin.name) && ((moduleId.group ?: "<unscoped>") == libOrPlugin.group)
5555
}
5656
}.firstOrNull()
5757
}

0 commit comments

Comments
 (0)