@preventive/deptree 1.4.0 → 1.4.1
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 +15 -6
- package/src/pnpm/inputs.js +1 -4
- package/src/pnpm/packlist.js +2 -0
- package/src/pnpm/production.js +40 -12
- package/src/pnpm/tree.js +2 -2
package/package.json
CHANGED
package/pnpm.d.ts
CHANGED
|
@@ -21,9 +21,13 @@ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
|
|
|
21
21
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
22
22
|
|
|
23
23
|
// The machine pnpm would install on, which a tree depends on: `pnpm` is
|
|
24
|
-
// the version that installs, and has to be a 10.x, an 11.x or a 12.x
|
|
25
|
-
//
|
|
26
|
-
//
|
|
24
|
+
// the version that installs, and has to be a 10.x, an 11.x or a 12.x, the
|
|
25
|
+
// three built for, each as it differs from the others. pnpm 12 is checked
|
|
26
|
+
// against real installs from 12.8.1 on; an earlier one is taken but where
|
|
27
|
+
// its changelog says it installs otherwise, as its bug, which is not built
|
|
28
|
+
// for: a `file:` directory's file whose mode is not 0o644, for 12.8.0, and
|
|
29
|
+
// a production tree an edge to an optional peer changes, before 12.7.0.
|
|
30
|
+
// Left out, it is the one the root package.json's
|
|
27
31
|
// packageManager pins, which pnpm switches to, and has to be given where
|
|
28
32
|
// that pins none. `node` is the Node it runs on,
|
|
29
33
|
// unless the settings name a nodeVersion or, for pnpm 11, the root
|
|
@@ -134,7 +138,8 @@ export interface PnpmProject {
|
|
|
134
138
|
// time linear in the path and the pattern. pnpm hardlinks those files from
|
|
135
139
|
// the directory into each snapshot of the package, in their modes, which
|
|
136
140
|
// are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
|
|
137
|
-
// 0o755 and 0o775
|
|
141
|
+
// 0o755 and 0o775, and, for pnpm 12.8.0, which installs each at 0o644, any
|
|
142
|
+
// but 0o644. So a file linking a bin makes executable -- 0o755 for
|
|
138
143
|
// pnpm 10, its mode with 0o111 added for 11 and 12 -- is made so in
|
|
139
144
|
// every snapshot and in the directory, which is not written here; a CRLF
|
|
140
145
|
// `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package -- an install script, a
|
|
@@ -317,7 +322,7 @@ export interface PnpmProject {
|
|
|
317
322
|
// host cannot run left out as pnpm walks them, hoisted, its bins linked --
|
|
318
323
|
// as without it. Nothing else is fetched,
|
|
319
324
|
// nor its files checked; all else is held to the whole lockfile, as
|
|
320
|
-
// without it. From pnpm 11.28.0
|
|
325
|
+
// without it. From pnpm 11.28.0 and 12.7.0, an edge to an optional
|
|
321
326
|
// peer, which the snapshot is linked to only as each project that reaches it
|
|
322
327
|
// lists the peer itself, or as the peer is among the root's devDependencies
|
|
323
328
|
// and resolvePeersFromWorkspaceRoot is set, is not walked, and is linked
|
|
@@ -327,7 +332,11 @@ export interface PnpmProject {
|
|
|
327
332
|
// of a key with a hash in place of its peers; before, any dependency by the
|
|
328
333
|
// name of one of the snapshot's optional peers, though the snapshot
|
|
329
334
|
// resolved it as its own and its package.json asks for it, as the lockfile
|
|
330
|
-
// pnpm 11.28.7 and 12.15.0 on write records.
|
|
335
|
+
// pnpm 11.28.7 and 12.15.0 on write records. pnpm 12 before 12.7.0 walks
|
|
336
|
+
// each such edge, as pnpm 11 before 11.28.0 does; a lockfile where walking
|
|
337
|
+
// those 12.15.0 does not walk installs otherwise, or leaves out otherwise
|
|
338
|
+
// what the host cannot run, is refused, and any other is laid out as both
|
|
339
|
+
// lay it out.
|
|
331
340
|
//
|
|
332
341
|
// The two ways the files come, one or the other: given, with `lockfile`
|
|
333
342
|
// and `manifests`, `project` read only for directories; or read, with
|
package/src/pnpm/inputs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { LockfileError, YamlError, parsePnpmLockfile } from '@preventive/lockfile/pnpm.js'
|
|
5
5
|
import { parseYaml } from '@preventive/lockfile/yaml.js'
|
|
6
|
-
import {
|
|
6
|
+
import { valid } from '@preventive/upstream/semver.js'
|
|
7
7
|
import { normalize } from '@preventive/vfs/path.js'
|
|
8
8
|
import { DeptreeError, quote } from '../error.js'
|
|
9
9
|
import { readManifest } from '../manifest.js'
|
|
@@ -36,12 +36,9 @@ function readPatches(project, configured) {
|
|
|
36
36
|
return texts
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// pnpm 12 before 12.8.1 installs otherwise in places, and is refused.
|
|
40
|
-
const SINCE = { 12: '12.8.1' }
|
|
41
39
|
function majorOf(pnpm) {
|
|
42
40
|
const major = Number(valid(pnpm)?.split('.')[0])
|
|
43
41
|
if (major < 10 || major > 12 || !Number.isInteger(major)) throw new DeptreeError(`pnpm ${quote(pnpm)} is not supported: only pnpm 10, 11 and 12 are`, 'host.pnpm')
|
|
44
|
-
if (major in SINCE && compareVersions(pnpm, SINCE[major]) < 0) throw new DeptreeError(`pnpm ${quote(pnpm)} is not supported: pnpm ${major} is from ${SINCE[major]} on`, 'host.pnpm')
|
|
45
42
|
return major
|
|
46
43
|
}
|
|
47
44
|
|
package/src/pnpm/packlist.js
CHANGED
|
@@ -187,6 +187,8 @@ export function packDirectory(project, dir, manifest, version, where) {
|
|
|
187
187
|
if (rel.split('/').some((part) => part === '' || part === '.')) throw new DeptreeError('pnpm keeps it as a pattern spells it, which is not supported', here)
|
|
188
188
|
const { mode } = view.lstat(rel)
|
|
189
189
|
if (!MODES.has(mode)) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644, 664, 755 or 775, which is not supported`, here)
|
|
190
|
+
// pnpm 12.8.0 installs each at 644, whatever its own mode, which 12.8.1 fixed.
|
|
191
|
+
if (pnpm === '12.8.0' && mode !== 0o644) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644, which pnpm 12.8.0 installs it at, and that is not supported`, here)
|
|
190
192
|
files.set(rel, { data: view.bytes(rel), mode })
|
|
191
193
|
}
|
|
192
194
|
return files
|
package/src/pnpm/production.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// optionalDependencies and `link:`s, which lead only to projects, all of them
|
|
6
6
|
// installed anyway.
|
|
7
7
|
//
|
|
8
|
-
// From pnpm 11.28 and 12.
|
|
8
|
+
// From pnpm 11.28 and 12.7.0 on (@pnpm/lockfile.peer-edges), an edge to an
|
|
9
9
|
// optional peer that a snapshot has only as the projects that reach it list
|
|
10
10
|
// the peer themselves is not walked, and is dropped from the snapshot where
|
|
11
11
|
// nothing else reaches the peer: a devDependency only there to satisfy an
|
|
@@ -13,15 +13,22 @@
|
|
|
13
13
|
// only an edge to a peer the snapshot's key binds is such an edge, or any of
|
|
14
14
|
// one whose key ends in a hash of its peers; before, any edge by the name of
|
|
15
15
|
// an optional peer was, though the snapshot resolved it as its own.
|
|
16
|
+
//
|
|
17
|
+
// pnpm 12 before 12.7.0 walks such an edge too, as pnpm 11 before 11.28
|
|
18
|
+
// does, which is pnpm's bug and not built for: a lockfile where walking the
|
|
19
|
+
// edges 12.15.0 does not walk installs otherwise is refused.
|
|
16
20
|
|
|
17
21
|
import { compareVersions } from '@preventive/upstream/semver.js'
|
|
18
22
|
import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
|
|
23
|
+
import { DeptreeError, quote } from '../error.js'
|
|
19
24
|
import { reachable } from './nm-hoist.js'
|
|
20
25
|
|
|
21
|
-
// undefined where there is no such edge; else whether the key must bind it
|
|
26
|
+
// undefined where there is no such edge; else whether the key must bind it,
|
|
27
|
+
// and whether a lockfile that walking the edges installs otherwise is refused.
|
|
22
28
|
function ruleOf(pnpm, major) {
|
|
23
29
|
const since = (version) => compareVersions(pnpm, version) >= 0
|
|
24
30
|
if (major < 11 || (major === 11 && !since('11.28.0'))) return undefined
|
|
31
|
+
if (major === 12 && !since('12.7.0')) return { bound: true, refused: true }
|
|
25
32
|
return { bound: since(major === 11 ? '11.28.7' : '12.15.0') }
|
|
26
33
|
}
|
|
27
34
|
|
|
@@ -116,17 +123,38 @@ function without(packages, edges, drop) {
|
|
|
116
123
|
return kept
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
|
|
126
|
+
const same = (a, b) => a.size === b.size && [...a].every((key) => b.has(key))
|
|
127
|
+
|
|
128
|
+
// The edge to name in refusing: one to a snapshot `fixed` leaves out, else
|
|
129
|
+
// one of a snapshot walking them all reaches.
|
|
130
|
+
function refusalOf(edges, all, fixed, packages) {
|
|
131
|
+
const listed = [...edges].flatMap(([parent, aliases]) => [...aliases].map((alias) => ({ parent, alias, target: packages[parent].dependencies[alias] ?? packages[parent].optionalDependencies[alias] })))
|
|
132
|
+
const reached = listed.filter((edge) => all.picked.has(edge.parent))
|
|
133
|
+
const edge = reached.find(({ target }) => !fixed.picked.has(target)) ?? reached[0]
|
|
134
|
+
return new DeptreeError(`pnpm 12 before 12.7.0 walks its edge to its optional peer ${quote(edge.alias)}, which pnpm 12.7.0 on does not, and installs otherwise with devDependencies left out, which is not supported`, `snapshots[${quote(edge.parent)}]`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// `installing`, the lockfile the tree is laid out from: the snapshots
|
|
138
|
+
// reached, each but for the edges pnpm does not walk to a snapshot not
|
|
139
|
+
// reached; and what `skippedOf` makes of what pnpm walks to leave out what
|
|
140
|
+
// the host cannot run: every snapshot, but for those edges. Each importer's
|
|
141
|
+
// devDependencies are empty.
|
|
142
|
+
export function productionLockfile(lockfile, { pnpm, major, resolvePeersFromWorkspaceRoot }, skippedOf) {
|
|
124
143
|
const importers = Object.fromEntries(Object.entries(lockfile.importers).map(([id, importer]) => [id, { ...importer, devDependencies: {} }]))
|
|
144
|
+
const starts = Object.values(importers).flatMap(prodEdgesOf)
|
|
145
|
+
const filtered = (edges) => {
|
|
146
|
+
const walked = { ...lockfile, importers, packages: without(lockfile.packages, edges, () => true) }
|
|
147
|
+
const picked = reachable(starts, (key) => prodEdgesOf(walked.packages[key]))
|
|
148
|
+
const packages = Object.fromEntries(Object.entries(lockfile.packages).filter(([key]) => picked.has(key)))
|
|
149
|
+
return { picked, installing: { ...lockfile, importers, packages: without(packages, edges, (target) => !picked.has(target)) }, ...skippedOf(walked) }
|
|
150
|
+
}
|
|
125
151
|
const rule = ruleOf(pnpm, major)
|
|
126
152
|
const edges = rule === undefined ? new Map() : satisfactionEdges(lockfile, rule, resolvePeersFromWorkspaceRoot)
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
153
|
+
const fixed = filtered(edges)
|
|
154
|
+
if (!rule?.refused || edges.size === 0) return fixed
|
|
155
|
+
// Where walking every edge reaches the same snapshots and leaves out the
|
|
156
|
+
// same, it lays out the same tree.
|
|
157
|
+
const all = filtered(new Map())
|
|
158
|
+
if (!same(all.picked, fixed.picked) || !same(all.skipped, fixed.skipped) || !same(all.incompatible, fixed.incompatible)) throw refusalOf(edges, all, fixed, lockfile.packages)
|
|
159
|
+
return all
|
|
132
160
|
}
|
package/src/pnpm/tree.js
CHANGED
|
@@ -296,8 +296,8 @@ export async function buildPnpmTree(options) {
|
|
|
296
296
|
checkProjects(lockfile, manifests, { hook, extensions, host, settings, env, directories })
|
|
297
297
|
checkOptional(lockfile)
|
|
298
298
|
const names = settings.hoistWorkspacePackages ? workspaceNames(manifests) : new Map()
|
|
299
|
-
const
|
|
300
|
-
const { skipped, incompatible } =
|
|
299
|
+
const skippedOf = (walked) => skippedSnapshots(walked, { host, settings })
|
|
300
|
+
const { installing, skipped, incompatible } = production ? productionLockfile(lockfile, { ...host, resolvePeersFromWorkspaceRoot: settings.resolvePeersFromWorkspaceRoot }, skippedOf) : { installing: lockfile, ...skippedOf(lockfile) }
|
|
301
301
|
const hoisted = settings.nodeLinker === 'hoisted'
|
|
302
302
|
const checks = { lockfile, hook, fresh, drops }
|
|
303
303
|
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 })
|