Skip to content

Commit

Permalink
refactor(yarn2): Factor out getPackageInfos()
Browse files Browse the repository at this point in the history
Improve readability.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Nov 22, 2024
1 parent eeba28e commit cb62ba0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ class Yarn2(

run("install", workingDir = workingDir)

val packageInfos = getPackageInfos(workingDir)
val packageHeaders = parsePackageHeaders(packageInfos)
val packageDetails = queryPackageDetails(workingDir, packageHeaders)

val allProjects = parseAllPackages(packageInfos, definitionFile, packageHeaders, packageDetails)
val scopeNames = YarnDependencyType.entries.mapTo(mutableSetOf()) { it.type }

return allProjects.values.map { project ->
ProjectAnalyzerResult(project.copy(scopeNames = scopeNames), emptySet(), issues)
}.toList()
}

private fun getPackageInfos(workingDir: File): List<PackageInfo> {
// Query the list of all packages with their dependencies. The output is in NDJSON format.
val process = run(
"info",
Expand All @@ -212,16 +225,7 @@ class Yarn2(

logger.info { "Parsing packages..." }

val packageInfos = parsePackageInfos(process.stdout)
val packageHeaders = parsePackageHeaders(packageInfos)
val packageDetails = queryPackageDetails(workingDir, packageHeaders)

val allProjects = parseAllPackages(packageInfos, definitionFile, packageHeaders, packageDetails)
val scopeNames = YarnDependencyType.entries.mapTo(mutableSetOf()) { it.type }

return allProjects.values.map { project ->
ProjectAnalyzerResult(project.copy(scopeNames = scopeNames), emptySet(), issues)
}.toList()
return parsePackageInfos(process.stdout)
}

/**
Expand Down

0 comments on commit cb62ba0

Please sign in to comment.