diff --git a/packages/supi/src/install/index.ts b/packages/supi/src/install/index.ts index db6bb6a394..a00879f80a 100644 --- a/packages/supi/src/install/index.ts +++ b/packages/supi/src/install/index.ts @@ -665,7 +665,7 @@ async function installInContext ( virtualStoreDir: ctx.virtualStoreDir, workspacePackages: opts.workspacePackages, }) - const importersToResolve = await Promise.all(importers.map((importer) => _toResolveImporter(importer, Boolean(ctx.hoistPattern && importer.id === '.')))) + const importersToResolve = await Promise.all(importers.map((importer) => _toResolveImporter(importer))) const { dependenciesTree, outdatedDependencies, @@ -896,7 +896,6 @@ async function toResolveImporter ( workspacePackages: WorkspacePackages, }, importer: ImporterToUpdate, - hoist: boolean, ) { const allDeps = getWantedDependencies(importer.manifest) const { linkedAliases, nonLinkedDependencies } = await partitionLinkedPackages(allDeps, { @@ -910,14 +909,14 @@ async function toResolveImporter ( const existingDeps = nonLinkedDependencies .filter(({ alias }) => !importer.wantedDependencies.some((wantedDep) => wantedDep.alias === alias)) let wantedDependencies!: Array - if (!importer.manifest || hoist) { + if (!importer.manifest) { wantedDependencies = [ ...importer.wantedDependencies, ...existingDeps, ] .map((dep) => ({ ...dep, - updateDepth: hoist ? Infinity : opts.defaultUpdateDepth, + updateDepth: opts.defaultUpdateDepth, })) } else { wantedDependencies = [ diff --git a/packages/supi/test/install/update.ts b/packages/supi/test/install/update.ts index f7c9849d1a..764ec31bef 100644 --- a/packages/supi/test/install/update.ts +++ b/packages/supi/test/install/update.ts @@ -125,3 +125,23 @@ test('preserve subdeps when installing on a package that has one dependency spec qar: '100.0.0', }) }) + +// Covers https://github.com/pnpm/pnpm/issues/2226 +test('update only the packages that were requested to be updated when hoisting is on', async (t) => { + const project = prepareEmpty(t) + + await addDistTag('bar', '100.0.0', 'latest') + await addDistTag('foo', '100.0.0', 'latest') + + let manifest = await addDependenciesToPackage({}, ['bar', 'foo'], await testDefaults({ hoistPattern: ['*'] })) + + await addDistTag('bar', '100.1.0', 'latest') + await addDistTag('foo', '100.1.0', 'latest') + + manifest = await addDependenciesToPackage(manifest, ['foo'], await testDefaults({ allowNew: false, update: true, hoistPattern: ['*'] })) + + t.deepEqual(manifest.dependencies, { bar: '^100.0.0', foo: '^100.1.0' }) + + const lockfile = await project.readLockfile() + t.deepEqual(Object.keys(lockfile.packages), ['/bar/100.0.0', '/foo/100.1.0']) +})