Skip to content

Commit

Permalink
perf: improve performance of peer dependencies resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed May 8, 2024
1 parent d0bc0b8 commit 7b911f4
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 148 deletions.
2 changes: 2 additions & 0 deletions pkg-manager/resolve-dependencies/src/index.ts
Expand Up @@ -133,6 +133,7 @@ export async function resolveDependencies (
wantedToBeSkippedPackageIds,
appliedPatches,
time,
allPeerDeps,
} = await resolveDependencyTree(projectsToResolve, opts)

// We only check whether patches were applied in cases when the whole lockfile was reanalyzed.
Expand Down Expand Up @@ -191,6 +192,7 @@ export async function resolveDependencies (
dependenciesByProjectId,
peerDependencyIssuesByProjects,
} = await resolvePeers({
allPeers: allPeerDeps,
dependenciesTree,
dedupePeerDependents: opts.dedupePeerDependents,
dedupeInjectedDeps: opts.dedupeInjectedDeps,
Expand Down
7 changes: 7 additions & 0 deletions pkg-manager/resolve-dependencies/src/resolveDependencies.ts
Expand Up @@ -130,6 +130,7 @@ export interface ChildrenByParentDepPath {
}

export interface ResolutionContext {
allPeerDeps: Set<string>
autoInstallPeers: boolean
autoInstallPeersFromHighestMatch: boolean
allowBuild?: (pkgName: string) => boolean
Expand Down Expand Up @@ -1329,6 +1330,12 @@ async function resolveDependency (
ctx.outdatedDependencies[pkgResponse.body.id] = pkgResponse.body.latest
}

Object.keys(pkg.peerDependencies ?? {}).forEach((name) => {
ctx.allPeerDeps.add(name)
})
Object.keys(pkg.peerDependenciesMeta ?? {}).forEach((name) => {
ctx.allPeerDeps.add(name)
})
// In case of leaf dependencies (dependencies that have no prod deps or peer deps),
// we only ever need to analyze one leaf dep in a graph, so the nodeId can be short and stateless.
const nodeId = pkgIsLeaf(pkg)
Expand Down
3 changes: 3 additions & 0 deletions pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts
Expand Up @@ -107,6 +107,7 @@ export interface ResolveDependenciesOptions {
}

export interface ResolveDependencyTreeResult {
allPeerDeps: Set<string>
dependenciesTree: DependenciesTree<ResolvedPackage>
outdatedDependencies: {
[pkgId: string]: string
Expand Down Expand Up @@ -160,6 +161,7 @@ export async function resolveDependencyTree<T> (
workspacePackages: opts.workspacePackages,
missingPeersOfChildrenByPkgId: {},
hoistPeers: autoInstallPeers || opts.dedupePeerDependents,
allPeerDeps: new Set(),
}

const resolveArgs: ImporterToResolve[] = importers.map((importer) => {
Expand Down Expand Up @@ -252,6 +254,7 @@ export async function resolveDependencyTree<T> (
wantedToBeSkippedPackageIds,
appliedPatches: ctx.appliedPatches,
time,
allPeerDeps: ctx.allPeerDeps,
}
}

Expand Down

0 comments on commit 7b911f4

Please sign in to comment.