Skip to content

Commit f019963

Browse files
committed
refactor(yarn2): Simplify extracting the module name
The module name may contain at most one '@'. If it does, the '@' is always the first character. So, use `startIndex=1` to find the en marker '@' of the module name. Signed-off-by: Frank Viernau <[email protected]>
1 parent 7bec2dc commit f019963

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2DependencyHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ internal class Yarn2DependencyHandler(
8484
internal val PackageInfo.isProject: Boolean get() = value.substringAfterLast("@").startsWith("workspace:")
8585

8686
internal val PackageInfo.moduleName: String get() {
87-
val firstComponent = value.substringBefore(":")
8887
// TODO: Handle patched packages different than non-patched ones.
8988
// Patch packages have locators as e.g. the following, where the first component ends with "@patch".
9089
// resolve@patch:resolve@npm%3A1.22.8#optional!builtin<compat/resolve>::version=1.22.8&hash=c3c19d
91-
return firstComponent.substringBeforeLast("@")
90+
val endIndex = value.indexOf("@", startIndex = 1)
91+
return value.take(endIndex)
9292
}
9393

9494
internal val PackageInfo.moduleId: String get() = buildString {

0 commit comments

Comments
 (0)