mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
perf(pkgs-graph): speed up createPkgGraph by using a table for manifest name lookup (#6287)
This commit is contained in:
5
.changeset/purple-stingrays-argue.md
Normal file
5
.changeset/purple-stingrays-argue.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/workspace.pkgs-graph": patch
|
||||
---
|
||||
|
||||
Speed up createPkgGraph by using a table for manifest name lookup
|
||||
@@ -36,6 +36,12 @@ export function createPkgGraph<T> (pkgs: Array<Package & T>, opts?: {
|
||||
} {
|
||||
const pkgMap = createPkgMap(pkgs)
|
||||
const pkgMapValues = Object.values(pkgMap)
|
||||
const pkgMapByManifestName: Record<string, Package[] | undefined> = {}
|
||||
for (const pkg of pkgMapValues) {
|
||||
if (pkg.manifest.name) {
|
||||
(pkgMapByManifestName[pkg.manifest.name] ??= []).push(pkg)
|
||||
}
|
||||
}
|
||||
const unmatched: Array<{ pkgName: string, range: string }> = []
|
||||
const graph = mapValues((pkg) => ({
|
||||
dependencies: createNode(pkg),
|
||||
@@ -76,8 +82,8 @@ export function createPkgGraph<T> (pkgs: Array<Package & T>, opts?: {
|
||||
|
||||
if (spec.type !== 'version' && spec.type !== 'range') return ''
|
||||
|
||||
const pkgs = pkgMapValues.filter(pkg => pkg.manifest.name === depName)
|
||||
if (pkgs.length === 0) return ''
|
||||
const pkgs = pkgMapByManifestName[depName]
|
||||
if (!pkgs || pkgs.length === 0) return ''
|
||||
const versions = pkgs.filter(({ manifest }) => manifest.version)
|
||||
.map(pkg => pkg.manifest.version) as string[]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user