Skip to content

Commit

Permalink
refactor(yarn2): Extract isCorepackEnabled()
Browse files Browse the repository at this point in the history
Improve the readability a bit.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Sep 12, 2024
1 parent da6cc49 commit 5bc030e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,7 @@ class Yarn2(

override fun command(workingDir: File?): String {
if (workingDir == null) return ""

val corepackEnabled = if (OPTION_COREPACK_OVERRIDE in options) {
options[OPTION_COREPACK_OVERRIDE].toBoolean()
} else {
isCorepackEnabledInManifest(workingDir)
}

if (corepackEnabled) return "yarn"
if (isCorepackEnabled(workingDir)) return "yarn"

return yarn2ExecutablesByPath.getOrPut(workingDir) {
val yarnExecutable = getYarnExecutable(workingDir)
Expand Down Expand Up @@ -205,6 +198,13 @@ class Yarn2(

override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=2.0.0")

private fun isCorepackEnabled(workingDir: File): Boolean =
if (OPTION_COREPACK_OVERRIDE in options) {
options[OPTION_COREPACK_OVERRIDE].toBoolean()
} else {
isCorepackEnabledInManifest(workingDir)
}

override fun mapDefinitionFiles(definitionFiles: List<File>) =
NpmDetection(definitionFiles).filterApplicable(NodePackageManager.YARN2)

Expand Down

0 comments on commit 5bc030e

Please sign in to comment.