@preventive/deptree 1.5.4 → 1.5.5
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 +2 -2
- package/pnpm.d.ts +1 -1
- package/src/pnpm/hoisted.js +3 -3
- package/src/pnpm/production.js +6 -0
- package/src/pnpm/tree.js +14 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/deptree",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "In-memory dependency tree, as a package manager installs it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -172,7 +172,7 @@
|
|
|
172
172
|
"@preventive/archive": "^1.4.0",
|
|
173
173
|
"@preventive/compare": "^1.2.11",
|
|
174
174
|
"@preventive/diff": "^1.1.1",
|
|
175
|
-
"@preventive/lockfile": "^1.3.
|
|
175
|
+
"@preventive/lockfile": "^1.3.1",
|
|
176
176
|
"@preventive/upstream": "^1.8.0",
|
|
177
177
|
"@preventive/vfs": "^1.1.0"
|
|
178
178
|
}
|
package/pnpm.d.ts
CHANGED
|
@@ -194,7 +194,7 @@ export interface PnpmInstalled {
|
|
|
194
194
|
repository: string | PackageRepository | undefined;
|
|
195
195
|
homepage: string | undefined;
|
|
196
196
|
bugs: string | PackageBugs | undefined;
|
|
197
|
-
/** Whether
|
|
197
|
+
/** Whether `--prod` would leave it out; hoisted, by name and version */
|
|
198
198
|
dev: boolean;
|
|
199
199
|
/** Whether optional dependencies alone reach it, as the lockfile records */
|
|
200
200
|
optional: boolean;
|
package/src/pnpm/hoisted.js
CHANGED
|
@@ -219,9 +219,9 @@ export function hoistedModules(byDir, links, projects, manifests, lockfile) {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
// The snapshots `pnpm install --prod` would install, by pnpm's name@version.
|
|
222
|
-
export function prodPackages(lockfile, skipped, directories) {
|
|
223
|
-
const edges = ({ dependencies, optionalDependencies }) => [...Object.
|
|
224
|
-
const reached = reachable(Object.values(lockfile.importers).flatMap(edges), (key) => edges(lockfile.packages[key]), (key) => key.startsWith('link:') || skipped.has(key))
|
|
222
|
+
export function prodPackages(lockfile, skipped, directories, unwalked = new Map()) {
|
|
223
|
+
const edges = ({ dependencies, optionalDependencies }, aliases) => [...Object.entries(dependencies), ...Object.entries(optionalDependencies)].flatMap(([alias, target]) => (aliases?.has(alias) ? [] : [target]))
|
|
224
|
+
const reached = reachable(Object.values(lockfile.importers).flatMap((importer) => edges(importer)), (key) => edges(lockfile.packages[key], unwalked.get(key)), (key) => key.startsWith('link:') || skipped.has(key))
|
|
225
225
|
return new Set(reached.values().map((key) => packageIdOf(key, lockfile.packages[key], directories)))
|
|
226
226
|
}
|
|
227
227
|
|
package/src/pnpm/production.js
CHANGED
|
@@ -94,6 +94,12 @@ function satisfactionEdges(lockfile, rule, fromRoot) {
|
|
|
94
94
|
return edges
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// By snapshot, the aliases --prod does not walk; pnpm 12 before 12.7.0 walks them all.
|
|
98
|
+
export function unwalkedEdges(lockfile, { pnpm, major, resolvePeersFromWorkspaceRoot }) {
|
|
99
|
+
const rule = ruleOf(pnpm, major)
|
|
100
|
+
return rule === undefined || rule.refused ? new Map() : satisfactionEdges(lockfile, rule, resolvePeersFromWorkspaceRoot)
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
// Each snapshot `edges` names, without those of its edges `drop` takes.
|
|
98
104
|
function without(packages, edges, drop) {
|
|
99
105
|
const kept = { ...packages }
|
package/src/pnpm/tree.js
CHANGED
|
@@ -23,7 +23,7 @@ import { checkLinks, checkOptional } from './checks.js'
|
|
|
23
23
|
import { createDirectoryCheck } from './directories.js'
|
|
24
24
|
import { listExtensions } from './extensions.js'
|
|
25
25
|
import { createHook } from './hook.js'
|
|
26
|
-
import { productionLockfile } from './production.js'
|
|
26
|
+
import { productionLockfile, unwalkedEdges } from './production.js'
|
|
27
27
|
import { listOverrides } from './overrides.js'
|
|
28
28
|
import { checkHost, inputsOf, manifestsOf, patchesOf, readLockfile } from './inputs.js'
|
|
29
29
|
import { checkProjects, pinsPnpm, workspaceNames } from './projects.js'
|
|
@@ -122,14 +122,16 @@ function linkTarget(path, target) {
|
|
|
122
122
|
return relative(`${root}/${dirname(path)}`, `${root}/${target}`) || '.'
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
// What no project's dependencies or optionalDependencies reach is dev-only.
|
|
126
|
-
function reachedInProd(importers, nodes, byDir) {
|
|
125
|
+
// What no project's dependencies or optionalDependencies reach, by the edges --prod walks, is dev-only.
|
|
126
|
+
function reachedInProd(importers, nodes, byDir, unwalked) {
|
|
127
127
|
const reached = new Set(Object.values(importers)
|
|
128
128
|
.flatMap(({ dependencies, optionalDependencies }) => [...Object.values(dependencies), ...Object.values(optionalDependencies)])
|
|
129
129
|
.map((target) => nodes.get(target)?.dir)
|
|
130
130
|
.filter((dir) => byDir.has(dir)))
|
|
131
131
|
for (const dir of reached) {
|
|
132
|
-
|
|
132
|
+
const { key, children } = byDir.get(dir)
|
|
133
|
+
const aliases = unwalked.get(key)
|
|
134
|
+
for (const [alias, child] of children) if (byDir.has(child) && !aliases?.has(alias)) reached.add(child)
|
|
133
135
|
}
|
|
134
136
|
return reached
|
|
135
137
|
}
|
|
@@ -173,7 +175,7 @@ const COPYING = new Set(['copy', 'clone', 'clone-or-copy'])
|
|
|
173
175
|
// The hoisted layout of pnpm 10 and 11 (hoisted.js), each copy a parent before what lands in its
|
|
174
176
|
// node_modules. `fixes` are what linking bins and the build pass do to the files, read once every
|
|
175
177
|
// package's are at hand; `builds` what the build pass builds; `checks` hold the lockfile to the whole one.
|
|
176
|
-
async function buildHoisted({ lockfile, checks, settings, host, project, installed, manifests, names, patched, skipped, fetching }) {
|
|
178
|
+
async function buildHoisted({ lockfile, checks, settings, host, project, installed, manifests, names, patched, skipped, unwalked, fetching }) {
|
|
177
179
|
const { major } = host
|
|
178
180
|
const since = (version) => compareVersions(host.pnpm, version) >= 0
|
|
179
181
|
if (!COPYING.has(settings.packageImportMethod)) {
|
|
@@ -191,7 +193,7 @@ async function buildHoisted({ lockfile, checks, settings, host, project, install
|
|
|
191
193
|
if (fetching.sizeEstimateOnly) checkNoneDropped(dropping, host.pnpm)
|
|
192
194
|
const { byDir, tarballs } = await fetchNodes(placed, checks, project, host, fetching)
|
|
193
195
|
const linked = readLinked(links, byDir, manifests, project)
|
|
194
|
-
const prod = prodPackages(lockfile, skipped, directories)
|
|
196
|
+
const prod = prodPackages(lockfile, skipped, directories, unwalked)
|
|
195
197
|
const dev = (node) => !prod.has(packageIdOf(node.key, node.pkg, directories))
|
|
196
198
|
const builds = building ? (node) => node.pkg.patchHash !== undefined || requiresBuild(node.manifest, node.files, major) : undefined
|
|
197
199
|
const idOf = since('11.23.0') ? (key) => packageIdOf(key, lockfile.packages[key], directories) : (key) => key
|
|
@@ -209,14 +211,14 @@ async function buildHoisted({ lockfile, checks, settings, host, project, install
|
|
|
209
211
|
|
|
210
212
|
// The isolated layout: each package in node_modules/.pnpm, linked from what needs it and where it is
|
|
211
213
|
// hoisted; `reads` are the packages `fixes` read the files of (binReads)
|
|
212
|
-
async function buildIsolated({ lockfile, checks, settings, host, project, installed, manifests, names, skipped, fetching }) {
|
|
214
|
+
async function buildIsolated({ lockfile, checks, settings, host, project, installed, manifests, names, skipped, unwalked, fetching }) {
|
|
213
215
|
const { major } = host
|
|
214
216
|
const { nodes, direct, hoisting } = await buildGraph(lockfile, skipped, settings.virtualStoreDirMaxLength, major)
|
|
215
217
|
for (const node of nodes.values()) checkSource(node, installed)
|
|
216
218
|
const { byDir, tarballs } = await fetchNodes(nodes, checks, project, host, fetching)
|
|
217
219
|
const links = linksOf(byDir, direct, settings, names, major, hoisting)
|
|
218
220
|
const linked = readLinked(links, byDir, manifests, project)
|
|
219
|
-
const prod = reachedInProd(lockfile.importers, nodes, byDir)
|
|
221
|
+
const prod = reachedInProd(lockfile.importers, nodes, byDir, unwalked)
|
|
220
222
|
const dev = (node) => !prod.has(node.dir)
|
|
221
223
|
const linking = {
|
|
222
224
|
nodes: byDir,
|
|
@@ -276,10 +278,12 @@ export async function buildPnpmTree(options) {
|
|
|
276
278
|
checkOptional(lockfile)
|
|
277
279
|
const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
|
|
278
280
|
const skippedOf = (walked) => skippedSnapshots(walked, { host, settings })
|
|
279
|
-
const
|
|
281
|
+
const peers = { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }
|
|
282
|
+
const { installing, skipped, incompatible } = production ? productionLockfile(lockfile, peers, skippedOf) : { installing: lockfile, ...skippedOf(lockfile) }
|
|
283
|
+
const unwalked = production ? new Map() : unwalkedEdges(lockfile, peers)
|
|
280
284
|
const hoisted = settings.nodeLinker === 'hoisted'
|
|
281
285
|
const checks = { lockfile, hook, fresh, drops }
|
|
282
|
-
const { byDir, links, fixes, reads, builds, early, tarballs, dev } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile: installing, checks, settings, host, project, installed, manifests, names, patched, skipped, fetching })
|
|
286
|
+
const { byDir, links, fixes, reads, builds, early, tarballs, dev } = await (hoisted ? buildHoisted : buildIsolated)({ lockfile: installing, checks, settings, host, project, installed, manifests, names, patched, skipped, unwalked, fetching })
|
|
283
287
|
const laidOut = fetching.sizeEstimateOnly || fetching.lazy
|
|
284
288
|
const { targets, executable } = laidOut ? { targets: new Map(), executable: new Map() } : fixes()
|
|
285
289
|
|