Skip to content

Commit

Permalink
refactor(yarn2): Port isCorepackEnabledInManifest() to KxS
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau authored and sschuberth committed Sep 12, 2024
1 parent 184eb55 commit 519a76a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ data class PackageJson(
val from: String? = null,
@SerialName("_integrity")
val integrity: String? = null,
val packageManager: String? = null,
/** This property does not belong to package.json but to the JSON returned by 'npm info'. */
val dist: Distribution? = null
) {
Expand Down
10 changes: 2 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 @@ -19,8 +19,6 @@

package org.ossreviewtoolkit.plugins.packagemanagers.node.yarn2

import com.fasterxml.jackson.module.kotlin.contains

import java.io.File

import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -130,11 +128,6 @@ class Yarn2(
*/
private const val MANIFEST_FILE = "package.json"

/**
* The name of the property that defines the package manager and its version if Corepack is enabled.
*/
private const val PACKAGE_MANAGER_PROPERTY = "packageManager"

/**
* The name of the default executable. This is used when the [OPTION_COREPACK_OVERRIDE] option is set.
*/
Expand All @@ -146,7 +139,8 @@ class Yarn2(
*/
private fun isCorepackEnabledInManifest(workingDir: File): Boolean =
runCatching {
PACKAGE_MANAGER_PROPERTY in jsonMapper.readTree(workingDir.resolve(MANIFEST_FILE))
val packageJson = parsePackageJson(workingDir.resolve(MANIFEST_FILE))
!packageJson.packageManager.isNullOrEmpty()
}.getOrDefault(false)
}

Expand Down

0 comments on commit 519a76a

Please sign in to comment.