perf(rebuild): only link bins if something was built (#7193)

This commit is contained in:
Zoltan Kochan
2023-10-11 17:55:54 +03:00
committed by GitHub
parent e19de6a596
commit 4aa41ef3a6
2 changed files with 30 additions and 21 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-rebuild": patch
---
Only link bins after rebuild, when at least one dependency was actually built.

View File

@@ -285,6 +285,7 @@ async function _rebuild (
}
const allowBuild = createAllowBuildFunction(opts) ?? (() => true)
const builtDepPaths = new Set<string>()
const groups = chunks.map((chunk) => chunk.filter((depPath) => ctx.pkgsToRebuild.has(depPath) && !ctx.skipped.has(depPath)).map((depPath) =>
async () => {
@@ -336,6 +337,7 @@ async function _rebuild (
unsafePerm: opts.unsafePerm || false,
})
if (hasSideEffects && (opts.sideEffectsCacheWrite ?? true) && resolution.integrity) {
builtDepPaths.add(depPath)
const filesIndexFile = getFilePathInCafs(cafsDir, resolution.integrity!.toString(), 'index')
try {
if (!sideEffectsCacheKey) {
@@ -388,27 +390,29 @@ async function _rebuild (
await runGroups(opts.childConcurrency || 5, groups)
// It may be optimized because some bins were already linked before running lifecycle scripts
await Promise.all(
Object
.keys(pkgSnapshots)
.filter((depPath) => !packageIsIndependent(pkgSnapshots[depPath]))
.map(async (depPath) => limitLinking(async () => {
const pkgSnapshot = pkgSnapshots[depPath]
const pkgInfo = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
const modules = path.join(ctx.virtualStoreDir, dp.depPathToFilename(depPath), 'node_modules')
const binPath = path.join(modules, pkgInfo.name, 'node_modules', '.bin')
return linkBins(modules, binPath, { warn })
}))
)
await Promise.all(Object.values(ctx.projects).map(async ({ rootDir }) => limitLinking(async () => {
const modules = path.join(rootDir, 'node_modules')
const binPath = path.join(modules, '.bin')
return linkBins(modules, binPath, {
allowExoticManifests: true,
warn,
})
})))
if (builtDepPaths.size > 0) {
// It may be optimized because some bins were already linked before running lifecycle scripts
await Promise.all(
Object
.keys(pkgSnapshots)
.filter((depPath) => !packageIsIndependent(pkgSnapshots[depPath]))
.map(async (depPath) => limitLinking(async () => {
const pkgSnapshot = pkgSnapshots[depPath]
const pkgInfo = nameVerFromPkgSnapshot(depPath, pkgSnapshot)
const modules = path.join(ctx.virtualStoreDir, dp.depPathToFilename(depPath), 'node_modules')
const binPath = path.join(modules, pkgInfo.name, 'node_modules', '.bin')
return linkBins(modules, binPath, { warn })
}))
)
await Promise.all(Object.values(ctx.projects).map(async ({ rootDir }) => limitLinking(async () => {
const modules = path.join(rootDir, 'node_modules')
const binPath = path.join(modules, '.bin')
return linkBins(modules, binPath, {
allowExoticManifests: true,
warn,
})
})))
}
return pkgsThatWereRebuilt
}