perf: fix a perf regression shipped in v5.13.7

Fixed a performance regression that was caused by #3032
and shipped in pnpm v5.13.7

The performance of repeat `pnpm install` execution
was in some cases significantly slower.

PR #3061
This commit is contained in:
Zoltan Kochan
2021-01-10 14:50:34 +02:00
committed by GitHub
parent 1e4a3a17a0
commit d5ef7958ab
3 changed files with 18 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/headless": patch
---
Fixed a performance regression that was caused by [#3032](https://github.com/pnpm/pnpm/pull/3032).

View File

@@ -223,11 +223,6 @@ export default async (opts: HeadlessOptions) => {
pnpmVersion: opts.currentEngine.pnpmVersion,
} as LockfileToDepGraphOptions
)
if (filteredLockfile.packages) {
for (const skippedDepPath of Array.from(skipped)) {
delete filteredLockfile.packages[skippedDepPath]
}
}
if (opts.enablePnp) {
const importerNames = R.fromPairs(
opts.projects.map(({ manifest, id }) => [id, manifest.name ?? id])
@@ -276,8 +271,15 @@ export default async (opts: HeadlessOptions) => {
let newHoistedDependencies!: HoistedDependencies
if (opts.hoistPattern != null || opts.publicHoistPattern != null) {
// It is important to keep the skipped packages in the lockfile which will be saved as the "current lockfile".
// pnpm is comparing the current lockfile to the wanted one and they should much.
// But for hoisting, we need a version of the lockfile w/o the skipped packages, so we're making a copy.
const hoistLockfile = {
...filteredLockfile,
packages: R.omit(Array.from(skipped), filteredLockfile.packages),
}
newHoistedDependencies = await hoist({
lockfile: filteredLockfile,
lockfile: hoistLockfile,
lockfileDir,
privateHoistedModulesDir: hoistedModulesDir,
privateHoistPattern: opts.hoistPattern ?? [],

View File

@@ -502,7 +502,6 @@ test('should recreate node_modules with hoisting', async () => {
test('hoisting should not create a broken symlink to a skipped optional dependency', async () => {
const project = prepareEmpty()
console.log(process.cwd())
await install({
optionalDependencies: {
@@ -522,4 +521,9 @@ test('hoisting should not create a broken symlink to a skipped optional dependen
}, await testDefaults({ publicHoistPattern: '*' }))
await project.hasNot('dep-of-optional-pkg')
const rootModules = assertProject(process.cwd())
const currentLockfile = await rootModules.readCurrentLockfile()
const wantedLockfile = await rootModules.readLockfile()
expect(currentLockfile).toStrictEqual(wantedLockfile)
})