-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm libs in version catalogs #671
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is a convention I invented and also suggested in the mentioned https://youtrack.jetbrains.com/issue/KT-56416/KJS-Gradle-npm-compatibility-with-Gradle-version-catalogs ticket. Just having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I would hope is for Gradle to allow |
||
&& 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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leads to an allocation on every single
matches
check, that's the reason why I didn't just use the conversion trick.Could you revert this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I can not, otherwise it does not work anymore, that was not just a cosmetic change:
I can try to reprogram it so that still the necessary calculation is done but no allocation necessary maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to mention that I did. :-)