mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-02 05:57:27 -05:00
fix: peer of subdeps when node-linker is hoisted (#6680)
This commit is contained in:
7
.changeset/quiet-moons-sparkle.md
Normal file
7
.changeset/quiet-moons-sparkle.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/real-hoist": patch
|
||||
"@pnpm/headless": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Peer dependencies of subdependencies should be installed, when `node-linker` is set to `hoisted` [#6680](https://github.com/pnpm/pnpm/pull/6680).
|
||||
@@ -316,3 +316,17 @@ test('linking bins of local projects when node-linker is set to hoisted', async
|
||||
|
||||
expect(fs.existsSync('project-1/node_modules/.bin/project-2')).toBeTruthy()
|
||||
})
|
||||
|
||||
test('peerDependencies should be installed when autoInstallPeers is set to true and nodeLinker is set to hoisted', async () => {
|
||||
prepareEmpty()
|
||||
await install({
|
||||
dependencies: {
|
||||
'react-dom': '18.2.0',
|
||||
},
|
||||
}, await testDefaults({
|
||||
nodeLinker: 'hoisted',
|
||||
autoInstallPeers: true,
|
||||
}))
|
||||
|
||||
expect(fs.existsSync('node_modules/react')).toBeTruthy()
|
||||
})
|
||||
|
||||
@@ -53,6 +53,7 @@ export interface DependenciesGraph {
|
||||
}
|
||||
|
||||
export interface LockfileToDepGraphOptions {
|
||||
autoInstallPeers: boolean
|
||||
engineStrict: boolean
|
||||
force: boolean
|
||||
importerIds: string[]
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from './lockfileToDepGraph'
|
||||
|
||||
export interface LockfileToHoistedDepGraphOptions {
|
||||
autoInstallPeers: boolean
|
||||
engineStrict: boolean
|
||||
force: boolean
|
||||
hoistingLimits?: HoistingLimits
|
||||
@@ -68,7 +69,11 @@ async function _lockfileToHoistedDepGraph (
|
||||
lockfile: Lockfile,
|
||||
opts: LockfileToHoistedDepGraphOptions
|
||||
): Promise<Omit<LockfileToDepGraphResult, 'prevGraph'>> {
|
||||
const tree = hoist(lockfile, { hoistingLimits: opts.hoistingLimits, externalDependencies: opts.externalDependencies })
|
||||
const tree = hoist(lockfile, {
|
||||
hoistingLimits: opts.hoistingLimits,
|
||||
externalDependencies: opts.externalDependencies,
|
||||
autoInstallPeers: opts.autoInstallPeers,
|
||||
})
|
||||
const graph: DependenciesGraph = {}
|
||||
const modulesDir = path.join(opts.lockfileDir, 'node_modules')
|
||||
const fetchDepsOpts = {
|
||||
|
||||
@@ -17,6 +17,7 @@ export function hoist (
|
||||
// This option was added for Bit CLI in order to prevent pnpm from overwriting dependencies linked by Bit.
|
||||
// However, in the future it might be useful to use it in pnpm for skipping any dependencies added by external tools.
|
||||
externalDependencies?: Set<string>
|
||||
autoInstallPeers?: boolean
|
||||
}
|
||||
): HoisterResult {
|
||||
const nodes = new Map<string, HoisterTree>()
|
||||
@@ -37,7 +38,7 @@ export function hoist (
|
||||
acc[dep] = 'link:'
|
||||
return acc
|
||||
}, {} as Record<string, string>),
|
||||
}),
|
||||
}, opts?.autoInstallPeers),
|
||||
}
|
||||
for (const [importerId, importer] of Object.entries(lockfile.importers)) {
|
||||
if (importerId === '.') continue
|
||||
@@ -51,7 +52,7 @@ export function hoist (
|
||||
...importer.dependencies,
|
||||
...importer.devDependencies,
|
||||
...importer.optionalDependencies,
|
||||
}),
|
||||
}, opts?.autoInstallPeers),
|
||||
}
|
||||
node.dependencies.add(importerNode)
|
||||
}
|
||||
@@ -67,7 +68,12 @@ export function hoist (
|
||||
return hoisterResult
|
||||
}
|
||||
|
||||
function toTree (nodes: Map<string, HoisterTree>, lockfile: Lockfile, deps: Record<string, string>): Set<HoisterTree> {
|
||||
function toTree (
|
||||
nodes: Map<string, HoisterTree>,
|
||||
lockfile: Lockfile,
|
||||
deps: Record<string, string>,
|
||||
autoInstallPeers?: boolean
|
||||
): Set<HoisterTree> {
|
||||
return new Set(Object.entries(deps).map(([alias, ref]) => {
|
||||
const depPath = dp.refToRelative(ref, alias)!
|
||||
if (!depPath) {
|
||||
@@ -100,10 +106,12 @@ function toTree (nodes: Map<string, HoisterTree>, lockfile: Lockfile, deps: Reco
|
||||
reference: depPath,
|
||||
dependencyKind: HoisterDependencyKind.REGULAR,
|
||||
dependencies: new Set(),
|
||||
peerNames: new Set([
|
||||
...Object.keys(pkgSnapshot.peerDependencies ?? {}),
|
||||
...(pkgSnapshot.transitivePeerDependencies ?? []),
|
||||
]),
|
||||
peerNames: new Set(autoInstallPeers
|
||||
? []
|
||||
: [
|
||||
...Object.keys(pkgSnapshot.peerDependencies ?? {}),
|
||||
...(pkgSnapshot.transitivePeerDependencies ?? []),
|
||||
]),
|
||||
}
|
||||
nodes.set(key, node)
|
||||
node.dependencies = toTree(nodes, lockfile, { ...pkgSnapshot.dependencies, ...pkgSnapshot.optionalDependencies })
|
||||
|
||||
Reference in New Issue
Block a user