Skip to content

Commit

Permalink
refactor(yarn2): Make queryPackageDetails() only take identifiers
Browse files Browse the repository at this point in the history
It is not necessary to take `PackageHeader`s.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Nov 22, 2024
1 parent 4c9569b commit 76c7958
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ class Yarn2(

val packageInfos = getPackageInfos(workingDir)
val packageHeaders = parsePackageHeaders(packageInfos)
val packageDetails = queryPackageDetails(workingDir, packageHeaders)
val packageDetails = queryPackageDetails(
workingDir,
moduleIds = packageHeaders.values.filterNot { it.isProject }.mapTo(mutableSetOf()) { it.moduleId }
)

val allProjects = parseAllPackages(packageInfos, definitionFile, packageHeaders, packageDetails)
val scopeNames = YarnDependencyType.entries.mapTo(mutableSetOf()) { it.type }
Expand Down Expand Up @@ -252,22 +255,15 @@ class Yarn2(
}

/**
* Query the details of several packages. [iterator] should come from a NDJSON file. [packagesHeaders] should be
* the package representations as a triple: rawName/type/locator, mapped by package id.
* Query the details for the given NPM [moduleIds].
* The packages are separated in chunks and queried with `npm file` in [workingDir]. Unfortunately, under the hood,
* NPM does a request per package. However, if a solution to batch these requests arise, the code is ready for it.
* From the response to `npm file`, package details are extracted and returned.
*/
private fun queryPackageDetails(
workingDir: File,
packagesHeaders: Map<String, PackageHeader>
): Map<String, AdditionalData> {
private fun queryPackageDetails(workingDir: File, moduleIds: Set<String>): Map<String, AdditionalData> {
logger.info { "Fetching packages details..." }

val chunks = packagesHeaders
.filterValues { !it.isProject }
.values.map { it.moduleId }
.chunked(YARN_NPM_INFO_CHUNK_SIZE)
val chunks = moduleIds.chunked(YARN_NPM_INFO_CHUNK_SIZE)

return runBlocking(Dispatchers.IO) {
chunks.mapIndexed { index, chunk ->
Expand Down

0 comments on commit 76c7958

Please sign in to comment.