@preventive/deptree 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pnpm.d.ts +11 -3
- package/src/pnpm/bins.js +28 -0
- package/src/pnpm/lazy.js +26 -10
- package/src/pnpm/tree.js +17 -15
package/package.json
CHANGED
package/pnpm.d.ts
CHANGED
|
@@ -275,9 +275,17 @@ export interface PnpmProject {
|
|
|
275
275
|
// on; or any bin of a patched package. With the hoisted linker where any
|
|
276
276
|
// patch is configured, so does what pnpm's build pass does to a package it
|
|
277
277
|
// builds, patched or with an install script, which is read for every such
|
|
278
|
-
// package. The first such unpack fetches
|
|
279
|
-
//
|
|
280
|
-
// keeps them
|
|
278
|
+
// package. The first such unpack fetches the packages whose bins those are
|
|
279
|
+
// read from, but those unpacked already, which are read back from the
|
|
280
|
+
// tree, and keeps them: with the isolated linker, those the lockfile says
|
|
281
|
+
// have bins, those that bundle others, those whose bins pnpm reads whatever
|
|
282
|
+
// the lockfile says (a project's dependencies with pnpm 9 and 10, their
|
|
283
|
+
// peers with pnpm 11 and 12, and those beside a dependency outside the tree
|
|
284
|
+
// with pnpm 9 to 11), and directories, which are read with the tree; with
|
|
285
|
+
// the hoisted linker, every package. Any other is read as having no bins,
|
|
286
|
+
// as the lockfile says: where a patch is configured and pnpm builds one,
|
|
287
|
+
// the bins it links of its own are read once it is unpacked, which turn on
|
|
288
|
+
// nothing else's. Where the files could change the layout, the lockfile is
|
|
281
289
|
// refused as with sizeEstimateOnly. A `vfs` is not taken with it, nor
|
|
282
290
|
// `sizeEstimateOnly`.
|
|
283
291
|
//
|
package/src/pnpm/bins.js
CHANGED
|
@@ -157,6 +157,34 @@ export function binTargets({ nodes, projects, direct, links, publicHoist, buildi
|
|
|
157
157
|
return fixedFiles(nodes, fixed, contested, major)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// The packages of `nodes` whose files binTargets reads, given the same
|
|
161
|
+
// options, but those it reads for their own build alone, which the lockfile
|
|
162
|
+
// says have no bins: building one whose children are all packages links
|
|
163
|
+
// again what their first link did, and fixes nothing of theirs. The others
|
|
164
|
+
// are read as having no bins (lazy.js).
|
|
165
|
+
export function binReads({ nodes, projects, direct, links, publicHoist, peers, major }) {
|
|
166
|
+
const mayHaveBin = (dir) => nodes.get(dir)?.pkg.hasBin === true || nodes.get(dir)?.pkg.resolution.type === 'directory'
|
|
167
|
+
const reads = new Set()
|
|
168
|
+
for (const node of nodes.values()) {
|
|
169
|
+
if (mayHaveBin(node.dir) || node.pkg.bundledDependencies !== undefined) reads.add(node.dir)
|
|
170
|
+
const children = [...node.children.values()]
|
|
171
|
+
if (major < 12 && !children.every((dir) => nodes.has(dir))) for (const dir of [node.dir, ...children]) reads.add(dir)
|
|
172
|
+
}
|
|
173
|
+
for (const [id, children] of direct) {
|
|
174
|
+
if (major >= 11 && peers) for (const dir of peersOf(children, nodes)) reads.add(dir)
|
|
175
|
+
if (id === '.' && publicHoist) {
|
|
176
|
+
const manifest = projects.get('.')
|
|
177
|
+
const own = new Set(Object.keys({ ...manifest.devDependencies, ...manifest.dependencies, ...manifest.optionalDependencies }))
|
|
178
|
+
for (const [path, dir] of links) {
|
|
179
|
+
if (/^node_modules\/(?:@[^/]+\/)?[^/@.][^/]*$/u.test(path) && (major < 12 || own.has(path.slice('node_modules/'.length)))) reads.add(dir)
|
|
180
|
+
}
|
|
181
|
+
} else if (major < 11) {
|
|
182
|
+
for (const dir of children.values()) reads.add(dir)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return new Set([...reads].filter((dir) => nodes.has(dir)))
|
|
186
|
+
}
|
|
187
|
+
|
|
160
188
|
// The copies of one package pnpm's build pass makes hardlinks of the one it
|
|
161
189
|
// builds (hoisted.js): what is fixed in that one before, as each copy's own
|
|
162
190
|
// bins are where pnpm fills its node_modules, is in all; and so is what is
|
package/src/pnpm/lazy.js
CHANGED
|
@@ -61,12 +61,15 @@ function filesIn(vfs, dir, dirs) {
|
|
|
61
61
|
// full tree writes it, `patched` and `composing` being what compose takes, and
|
|
62
62
|
// listed by `entryOf`. What linking bins fixes of it turns on the other
|
|
63
63
|
// packages' bins only where a package is bound (above): the first such
|
|
64
|
-
// unpack fetches
|
|
65
|
-
// `fixes`, as the full tree does
|
|
66
|
-
// tree, where it is as it came
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
|
|
64
|
+
// unpack fetches those of `reads()` not unpacked yet, every package where it
|
|
65
|
+
// is not given, and reads the fixes by `fixes`, as the full tree does, one
|
|
66
|
+
// unpacked before read back from the tree, where it is as it came, and one
|
|
67
|
+
// not at hand read as having no bins, as the lockfile says. One read so that
|
|
68
|
+
// is bound once unpacked has the fixes read again, with its own files. A
|
|
69
|
+
// package's files are let go once it is unpacked, and its tarball once each
|
|
70
|
+
// of its snapshots is, but a patched one's, and every one's once the fixes
|
|
71
|
+
// are read.
|
|
72
|
+
export function lazyUnpacker({ vfs, byDir, stats, fixes, reads, builds, checks, patched, composing, entryOf, fetching, folded }) {
|
|
70
73
|
const { major } = composing
|
|
71
74
|
const limit = limited()
|
|
72
75
|
const fetched = new Map()
|
|
@@ -99,11 +102,24 @@ export function lazyUnpacker({ vfs, byDir, stats, fixes, builds, checks, patched
|
|
|
99
102
|
checkFetched(node, got, checks)
|
|
100
103
|
Object.assign(node, { files: got.files, manifest: got.manifest, about: got.about ?? NO_ABOUT })
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
// The fixes, with the packages not at hand read as having no bins.
|
|
106
|
+
const readFixes = () => {
|
|
107
|
+
const stubs = [...byDir.values()].filter((node) => node.files === undefined)
|
|
108
|
+
const manifests = stubs.map((node) => node.manifest)
|
|
109
|
+
for (const node of stubs) Object.assign(node, { files: new Map(), manifest: {} })
|
|
110
|
+
try {
|
|
111
|
+
return { ...fixes(), stubbed: new Set(stubs.map((node) => node.dir)) }
|
|
112
|
+
} finally {
|
|
113
|
+
for (const [i, node] of stubs.entries()) Object.assign(node, { files: undefined, manifest: manifests[i] })
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const fixesFor = async (node) => {
|
|
103
117
|
made ??= (async () => {
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
const read = reads?.()
|
|
119
|
+
await eachConcurrently([...byDir.values()].filter((other) => read?.has(other.dir) ?? true), prepare, (other) => quote(other.key))
|
|
120
|
+
return readFixes()
|
|
106
121
|
})()
|
|
122
|
+
if ((await made).stubbed.has(node.dir)) made = Promise.try(readFixes)
|
|
107
123
|
return made
|
|
108
124
|
}
|
|
109
125
|
const release = (node) => {
|
|
@@ -115,7 +131,7 @@ export function lazyUnpacker({ vfs, byDir, stats, fixes, builds, checks, patched
|
|
|
115
131
|
|
|
116
132
|
return unpacker(new Map([...byDir.values()].map((node) => [node.dir, node])), async (node) => {
|
|
117
133
|
await prepare(node)
|
|
118
|
-
const { targets, executable } = bound(node, major, builds) ? await
|
|
134
|
+
const { targets, executable } = bound(node, major, builds) ? await fixesFor(node) : { targets: new Map(), executable: new Map() }
|
|
119
135
|
const tree = new Vfs()
|
|
120
136
|
const written = { files: 0, bytes: 0 }
|
|
121
137
|
try {
|
package/src/pnpm/tree.js
CHANGED
|
@@ -16,7 +16,7 @@ import { DeptreeError, quote, refusalOf } from '../error.js'
|
|
|
16
16
|
import { checkNoModules, fold, makeDirs, mount, writeLink } from '../mount.js'
|
|
17
17
|
import { checkProject } from '../project.js'
|
|
18
18
|
import { NO_ABOUT, REGISTRY, fetchSize, fetchingOf, tarballUrl } from '../tarball.js'
|
|
19
|
-
import { binTargets, hoistedBinTargets, requiresBuild } from './bins.js'
|
|
19
|
+
import { binReads, binTargets, hoistedBinTargets, requiresBuild } from './bins.js'
|
|
20
20
|
import { buildGraph } from './graph.js'
|
|
21
21
|
import { hoist } from './hoist.js'
|
|
22
22
|
import { checkNoneDropped, hoistedBuilds, hoistedLayout, hoistedModules, packageIdOf, prodPackages, workspaceHoists } from './hoisted.js'
|
|
@@ -214,7 +214,8 @@ async function buildHoisted({ lockfile, settings, host, project, hook, installed
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
// The isolated layout: each package in node_modules/.pnpm, linked from what
|
|
217
|
-
// needs it and where it is hoisted; `fixes` as buildHoisted's
|
|
217
|
+
// needs it and where it is hoisted; `fixes` as buildHoisted's, and `reads`
|
|
218
|
+
// the packages they read the files of (binReads).
|
|
218
219
|
async function buildIsolated({ lockfile, settings, host, project, hook, installed, manifests, names, skipped, fetching }) {
|
|
219
220
|
const { major } = host
|
|
220
221
|
const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength, major)
|
|
@@ -224,20 +225,21 @@ async function buildIsolated({ lockfile, settings, host, project, hook, installe
|
|
|
224
225
|
const linked = readLinked(links, byDir, manifests, project)
|
|
225
226
|
const prod = reachedInProd(lockfile.importers, nodes, byDir)
|
|
226
227
|
const dev = (node) => !prod.has(node.dir)
|
|
228
|
+
const linking = {
|
|
229
|
+
nodes: byDir,
|
|
230
|
+
projects: new Map([...manifests, ...linked]),
|
|
231
|
+
direct,
|
|
232
|
+
links,
|
|
233
|
+
publicHoist: settings.publicHoistPattern?.length > 0,
|
|
234
|
+
building: Object.keys(settings.patchedDependencies ?? {}).length > 0,
|
|
235
|
+
peers: settings.autoInstallPeers,
|
|
236
|
+
major,
|
|
237
|
+
}
|
|
227
238
|
const fixes = () => {
|
|
228
|
-
const targets = binTargets(
|
|
229
|
-
nodes: byDir,
|
|
230
|
-
projects: new Map([...manifests, ...linked]),
|
|
231
|
-
direct,
|
|
232
|
-
links,
|
|
233
|
-
publicHoist: settings.publicHoistPattern?.length > 0,
|
|
234
|
-
building: Object.keys(settings.patchedDependencies ?? {}).length > 0,
|
|
235
|
-
peers: settings.autoInstallPeers,
|
|
236
|
-
major,
|
|
237
|
-
})
|
|
239
|
+
const targets = binTargets(linking)
|
|
238
240
|
return { targets, executable: executableElsewhere(byDir, targets, settings.packageImportMethod, major) }
|
|
239
241
|
}
|
|
240
|
-
return { byDir, links, fixes, tarballs, dev, checks }
|
|
242
|
+
return { byDir, links, fixes, reads: () => binReads(linking), tarballs, dev, checks }
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
export async function buildPnpmTree(options) {
|
|
@@ -278,7 +280,7 @@ export async function buildPnpmTree(options) {
|
|
|
278
280
|
const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
|
|
279
281
|
const { skipped, incompatible } = skippedSnapshots(lockfile, { host, settings })
|
|
280
282
|
const hoisted = settings.nodeLinker === 'hoisted'
|
|
281
|
-
const { byDir, links, fixes, builds, tarballs, dev, checks } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile, settings, host, project, hook, installed, manifests, names, patched, skipped, fetching })
|
|
283
|
+
const { byDir, links, fixes, reads, builds, tarballs, dev, checks } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile, settings, host, project, hook, installed, manifests, names, patched, skipped, fetching })
|
|
282
284
|
const laidOut = fetching.sizeEstimateOnly || fetching.lazy
|
|
283
285
|
const { targets, executable } = laidOut ? { targets: new Map(), executable: new Map() } : fixes()
|
|
284
286
|
|
|
@@ -311,5 +313,5 @@ export async function buildPnpmTree(options) {
|
|
|
311
313
|
const tree = mount(vfs, into, folded)
|
|
312
314
|
if (!fetching.lazy) return { vfs: tree, stats, installed: listed }
|
|
313
315
|
const entryOf = (node) => installedOf(node, dev(node), patched, false)
|
|
314
|
-
return { vfs: tree, stats, installed: listed, unpack: lazyUnpacker({ vfs: tree, byDir, stats, fixes, builds, checks, patched, composing, entryOf, fetching, folded }) }
|
|
316
|
+
return { vfs: tree, stats, installed: listed, unpack: lazyUnpacker({ vfs: tree, byDir, stats, fixes, reads, builds, checks, patched, composing, entryOf, fetching, folded }) }
|
|
315
317
|
}
|