Skip to content

Commit

Permalink
Update versions for NPM libs managed in version catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 9, 2023
1 parent 7958f92 commit 74ff323
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ internal fun Dependency.npmModuleId(): ModuleId.Npm {
}

internal fun Dependency.matches(moduleId: ModuleId): Boolean {
return moduleId.group == group && moduleId.name == name
return moduleId == moduleId()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.fayard.refreshVersions.core.internal

import de.fayard.refreshVersions.core.ModuleId
import de.fayard.refreshVersions.core.extensions.gradle.moduleId
import de.fayard.refreshVersions.core.extensions.gradle.npmModuleId
import de.fayard.refreshVersions.core.extensions.gradle.tryExtractingSimpleVersion
import de.fayard.refreshVersions.core.internal.VersionManagementKind.Match
import de.fayard.refreshVersions.core.internal.VersionManagementKind.NoMatch
import org.gradle.api.artifacts.Dependency
Expand Down Expand Up @@ -89,15 +91,28 @@ private fun Dependency.hasVersionInVersionCatalog(
versionsCatalogLibraries: Collection<MinimalExternalModuleDependency>,
versionsCatalogPlugins: Set<PluginDependencyCompat> = emptySet()
): Boolean {
if (this !is ExternalDependency) return false
when {
this::class.simpleName == "NpmDependency" -> {
return versionsCatalogLibraries.any {
val moduleId = npmModuleId()
it.module.group == (moduleId.group ?: "<unscoped>") && it.module.name == moduleId.name
&& it.versionConstraint.tryExtractingSimpleVersion() == version
}
}

val matchingLib = versionsCatalogLibraries.any {
it.module.group == group && it.module.name == name && it.versionConstraint == versionConstraint
}
if (matchingLib) return true
this is ExternalDependency -> {
val matchingLib = versionsCatalogLibraries.any {
it.module.group == group && it.module.name == name
&& it.versionConstraint == versionConstraint
}
if (matchingLib) return true

if (name.endsWith(".gradle.plugin").not()) return false
if (name.endsWith(".gradle.plugin").not()) return false

val pluginId = name.substringBeforeLast(".gradle.plugin")
return versionsCatalogPlugins.any { it.pluginId == pluginId && it.version == versionConstraint }
val pluginId = name.substringBeforeLast(".gradle.plugin")
return versionsCatalogPlugins.any { it.pluginId == pluginId && it.version == versionConstraint }
}

else -> return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class VersionsCatalogUpdater(
}.mapNotNull { libOrPlugin ->
dependenciesUpdates.firstOrNull {
val moduleId = it.moduleId
(moduleId.name == libOrPlugin.name) && (moduleId.group == libOrPlugin.group)
(moduleId.name == libOrPlugin.name) && ((moduleId.group ?: "<unscoped>") == libOrPlugin.group)
}
}.firstOrNull()
}
Expand Down

0 comments on commit 74ff323

Please sign in to comment.