fix: don't update all deps when running up/add <pkg>

close #2226
This commit is contained in:
Zoltan Kochan
2019-12-19 20:39:22 +02:00
parent a5aad38ce7
commit a48b93dfb9
2 changed files with 23 additions and 4 deletions

View File

@@ -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<WantedDependency & { isNew?: boolean, updateDepth: number }>
if (!importer.manifest || hoist) {
if (!importer.manifest) {
wantedDependencies = [
...importer.wantedDependencies,
...existingDeps,
]
.map((dep) => ({
...dep,
updateDepth: hoist ? Infinity : opts.defaultUpdateDepth,
updateDepth: opts.defaultUpdateDepth,
}))
} else {
wantedDependencies = [

View File

@@ -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'])
})