@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.10
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/LICENSE-APACHE +202 -0
- package/bin/compare.js +132 -0
- package/bin/deptree.js +211 -0
- package/bin/npmrc.js +21 -0
- package/cargo.d.ts +223 -0
- package/cargo.js +6 -0
- package/npm.d.ts +321 -0
- package/npm.js +7 -0
- package/package.json +92 -11
- package/pnpm.d.ts +401 -81
- package/pnpm.js +4 -9
- package/soldeer.d.ts +235 -0
- package/soldeer.js +6 -0
- package/src/cargo/crate.js +183 -0
- package/src/cargo/inputs.js +81 -0
- package/src/cargo/members.js +90 -0
- package/src/cargo/registry.js +65 -0
- package/src/cargo/tree.js +125 -0
- package/src/cargo/workspace.js +177 -0
- package/src/concurrent.js +32 -0
- package/src/error.js +8 -10
- package/src/glob.js +55 -0
- package/src/hash.js +51 -16
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +124 -42
- package/src/npm/bins.js +54 -0
- package/src/npm/compat.js +97 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +75 -0
- package/src/npm/manifests.js +130 -0
- package/src/npm/package.js +57 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +139 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +26 -45
- package/src/pnpm/bins.js +202 -322
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +230 -0
- package/src/pnpm/filename.js +19 -16
- package/src/pnpm/frozen.js +29 -73
- package/src/pnpm/gitignore.js +138 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +26 -34
- package/src/pnpm/hoist.js +96 -59
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +177 -0
- package/src/pnpm/install.js +123 -124
- package/src/pnpm/local.js +95 -40
- package/src/pnpm/minimatch.js +319 -0
- package/src/pnpm/nm-hoist-graph.js +299 -0
- package/src/pnpm/nm-hoist.js +149 -0
- package/src/pnpm/npm-packlist.js +217 -0
- package/src/pnpm/overrides.js +11 -51
- package/src/pnpm/package.js +123 -0
- package/src/pnpm/packlist.js +176 -81
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +132 -89
- package/src/pnpm/readers.js +122 -77
- package/src/pnpm/settings.js +74 -95
- package/src/pnpm/tree.js +216 -237
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +152 -126
- package/src/project.js +56 -0
- package/src/soldeer/config.js +63 -0
- package/src/soldeer/git.js +52 -0
- package/src/soldeer/inputs.js +30 -0
- package/src/soldeer/tree.js +83 -0
- package/src/soldeer/zip.js +121 -0
- package/src/tarball.js +123 -131
- package/src/yarn1/bins.js +28 -0
- package/src/yarn1/compat.js +67 -0
- package/src/yarn1/hoist.js +249 -0
- package/src/yarn1/inputs.js +83 -0
- package/src/yarn1/manifest.js +64 -0
- package/src/yarn1/package.js +206 -0
- package/src/yarn1/peers.js +51 -0
- package/src/yarn1/requests.js +74 -0
- package/src/yarn1/resolve.js +289 -0
- package/src/yarn1/settings.js +95 -0
- package/src/yarn1/tree.js +219 -0
- package/yarn1.d.ts +368 -0
- package/yarn1.js +7 -0
- package/src/pnpm/npmrc.js +0 -31
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/install.js
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
|
-
// Which snapshots a
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// reached both ways is left out or not by which way is walked first.
|
|
9
|
-
// Anything else incompatible is installed, as pnpm installs it with a
|
|
10
|
-
// warning, or refused where `engineStrict` has pnpm refuse it.
|
|
11
|
-
//
|
|
12
|
-
// The projects are walked in the lockfile's order, which is the order of
|
|
13
|
-
// their directories; pnpm walks them in the order it finds them on disk,
|
|
14
|
-
// which only a snapshot reached both ways as above can tell apart.
|
|
15
|
-
//
|
|
16
|
-
// pnpm 11 walks breadth first, and by the kind of each edge rather than of
|
|
17
|
-
// each snapshot: an optional dependency the host cannot run is not taken,
|
|
18
|
-
// and what a taken package requires is taken whether the host can run it
|
|
19
|
-
// or not, with a warning; each reachable snapshot not taken is left out.
|
|
20
|
-
// Where a package of an optional edge names no os, cpu or libc, pnpm 11
|
|
21
|
-
// infers them from its name, as `@nx/nx-win32-arm64-msvc` names win32.
|
|
22
|
-
|
|
23
|
-
import { satisfies } from '@preventive/upstream/semver.js'
|
|
1
|
+
// Which snapshots a frozen install leaves out. pnpm 9 and 10 walk depth first
|
|
2
|
+
// (@pnpm/lockfile.filtering's pkgAllDeps) and leave out an optional one the
|
|
3
|
+
// host cannot run or first reached through one not installed: the first
|
|
4
|
+
// reach decides. Projects go in lockfile order, pnpm's being the order it
|
|
5
|
+
// finds them on disk, which only a snapshot reached both ways can tell.
|
|
6
|
+
|
|
7
|
+
import { satisfies, validRange } from '@preventive/upstream/semver.js'
|
|
24
8
|
import { DeptreeError, quote } from '../error.js'
|
|
25
9
|
|
|
26
|
-
// pnpm's checkList
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
// takes nothing where the host is taken to be more than one thing; pnpm 11
|
|
30
|
-
// does not.
|
|
10
|
+
// pnpm's checkList. pnpm 10 counts the exclusions over every value the host
|
|
11
|
+
// is taken to be, so a list of them alone takes nothing where there is more
|
|
12
|
+
// than one. pnpm 12 takes, of each value, the first item that names it.
|
|
31
13
|
function checkList(values, list, major) {
|
|
32
14
|
if (list.length === 1 && list[0] === 'any') return true
|
|
33
15
|
let match = false
|
|
@@ -37,14 +19,16 @@ function checkList(values, list, major) {
|
|
|
37
19
|
if (item.startsWith('!')) {
|
|
38
20
|
if (item.slice(1) === value) return false
|
|
39
21
|
excluded++
|
|
40
|
-
} else if (item === value)
|
|
22
|
+
} else if (item === value) {
|
|
23
|
+
match = true
|
|
24
|
+
if (major >= 12) break
|
|
25
|
+
}
|
|
41
26
|
}
|
|
42
27
|
}
|
|
43
28
|
return match || (major >= 11 ? list.every((item) => item.startsWith('!')) : excluded === list.length)
|
|
44
29
|
}
|
|
45
30
|
|
|
46
|
-
// pnpm 11's inferPlatformFromPackageName
|
|
47
|
-
// of a package's name, less its scope, say it is for.
|
|
31
|
+
// pnpm 11's inferPlatformFromPackageName, from the unscoped name's words.
|
|
48
32
|
const OS_WORDS = { __proto__: null, aix: 'aix', android: 'android', darwin: 'darwin', macos: 'darwin', osx: 'darwin', freebsd: 'freebsd', linux: 'linux', netbsd: 'netbsd', openbsd: 'openbsd', openharmony: 'openharmony', sunos: 'sunos', win32: 'win32', windows: 'win32' }
|
|
49
33
|
const CPU_WORDS = { __proto__: null, arm: 'arm', armv6: 'arm', armv7: 'arm', arm64: 'arm64', aarch64: 'arm64', ia32: 'ia32', loong64: 'loong64', mips64el: 'mips64el', ppc64: 'ppc64', ppc64le: 'ppc64', riscv64: 'riscv64', s390x: 's390x', x64: 'x64', amd64: 'x64', wasm32: 'wasm32' }
|
|
50
34
|
const LIBC_WORDS = { __proto__: null, glibc: 'glibc', gnu: 'glibc', gnueabihf: 'glibc', musl: 'musl', musleabihf: 'musl' }
|
|
@@ -66,43 +50,54 @@ function effectivePlatform(pkg) {
|
|
|
66
50
|
return { ...pkg, os: pkg.os ?? inferred.os, cpu: pkg.cpu ?? inferred.cpu, libc: pkg.libc ?? inferred.libc }
|
|
67
51
|
}
|
|
68
52
|
|
|
69
|
-
// What the host is taken to be: itself, or what `supportedArchitectures`
|
|
70
|
-
// lists for each, `current` standing for itself.
|
|
71
53
|
const current = (value, supported) => (supported ?? ['current']).map((item) => (item === 'current' ? value : item))
|
|
72
54
|
|
|
73
|
-
const takesPlatform = (pkg, host, supported) =>
|
|
74
|
-
|
|
75
|
-
&& (host.libc === 'unknown' || checkList(current(host.libc, supported?.libc), pkg.libc ?? ['any'], host.major))
|
|
55
|
+
const takesPlatform = (pkg, host, supported) => ['os', 'cpu', 'libc'].every((key) => (key === 'libc' && host.libc === 'unknown')
|
|
56
|
+
|| checkList(current(host[key], supported?.[key]), pkg[key] ?? ['any'], host.major))
|
|
76
57
|
|
|
77
58
|
const takesEngine = (engines, node) => !engines.node || satisfies(node, engines.node, { includePrerelease: true })
|
|
78
59
|
|
|
79
|
-
//
|
|
80
|
-
|
|
60
|
+
// pnpm 12 drops what of a range it cannot parse, where npm's semver takes
|
|
61
|
+
// none of it, and reads a `-` range with an `x` as taking nothing.
|
|
62
|
+
function checkSure12(range, where, what = 'its engines.node') {
|
|
63
|
+
if (typeof range !== 'string' || (validRange(range) !== null && !(/\s-\s/u.test(range) && /[*xX]/u.test(range)))) return
|
|
64
|
+
throw new DeptreeError(`${what}, ${quote(range)}, pnpm 12 reads otherwise than npm's semver, which is not supported`, where)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const nodeOf = ({ host, settings }) => settings.nodeVersion ?? settings.runtimeNodeVersion ?? host.node
|
|
81
68
|
|
|
82
|
-
// With engineStrict, pnpm 11
|
|
83
|
-
//
|
|
84
|
-
// patched, to the Node instead.
|
|
69
|
+
// With engineStrict, pnpm 11 checks a patched snapshot's engines from its
|
|
70
|
+
// package.json, once patched, rather than from the lockfile.
|
|
85
71
|
const patchedLater = ({ host, settings }) => host.major >= 11 && settings.engineStrict === true
|
|
86
72
|
|
|
87
|
-
// A package.json's os, cpu or libc as pnpm's checkList reads one
|
|
88
|
-
// is a list of it, and what is not a string in a list is passed over.
|
|
73
|
+
// A package.json's os, cpu or libc as pnpm's checkList reads one.
|
|
89
74
|
function platformList(value, where) {
|
|
90
|
-
if (value
|
|
75
|
+
if (value == null) return undefined
|
|
91
76
|
if (typeof value === 'string') return [value]
|
|
92
77
|
if (Array.isArray(value)) return value.filter((item) => typeof item === 'string')
|
|
93
78
|
throw new DeptreeError('expected a string or a list of them', where)
|
|
94
79
|
}
|
|
95
80
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
81
|
+
function checkRoot12(manifest, where, context) {
|
|
82
|
+
const range = manifest.engines?.node
|
|
83
|
+
if (!context.settings.engineStrict || typeof range !== 'string' || range === '') return
|
|
84
|
+
const node = nodeOf(context)
|
|
85
|
+
checkSure12(range, where)
|
|
86
|
+
if (!takesEngine({ node: range }, node)) throw new DeptreeError(`its engines.node, ${quote(range)}, does not take Node ${node}, which engineStrict refuses`, where)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// As pnpm's packageIsInstallable: a platform the host is not only warns, and
|
|
90
|
+
// is found first, so the engines are then not checked. pnpm 9 holds it to the
|
|
91
|
+
// host alone, before it reads supportedArchitectures.
|
|
92
|
+
export function checkProject(manifest, where, { host, settings, root }) {
|
|
93
|
+
if (host.major >= 12) {
|
|
94
|
+
if (root) checkRoot12(manifest, where, { host, settings })
|
|
95
|
+
return
|
|
96
|
+
}
|
|
102
97
|
const platform = { os: platformList(manifest.os, `${where}.os`), cpu: platformList(manifest.cpu, `${where}.cpu`), libc: platformList(manifest.libc, `${where}.libc`) }
|
|
103
|
-
if (!takesPlatform(platform, host, settings.supportedArchitectures)) return
|
|
104
|
-
const engines = manifest
|
|
105
|
-
if (engines
|
|
98
|
+
if (!takesPlatform(platform, host, host.major < 10 ? undefined : settings.supportedArchitectures)) return
|
|
99
|
+
const { engines } = manifest
|
|
100
|
+
if (engines == null) return
|
|
106
101
|
const node = nodeOf({ host, settings })
|
|
107
102
|
if (engines.pnpm && !satisfies(host.pnpm, engines.pnpm, { includePrerelease: true })) {
|
|
108
103
|
throw new DeptreeError(`its engines.pnpm, ${quote(String(engines.pnpm))}, does not take pnpm ${host.pnpm}, which pnpm refuses`, where)
|
|
@@ -110,39 +105,39 @@ export function checkProject(manifest, where, { host, settings }) {
|
|
|
110
105
|
if (settings.engineStrict && !takesEngine(engines, node)) throw new DeptreeError(`its engines.node, ${quote(String(engines.node))}, does not take Node ${node}, which engineStrict refuses`, where)
|
|
111
106
|
}
|
|
112
107
|
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
// to be optional as the lockfile marks it; pnpm 11 as the edge it is
|
|
118
|
-
// reached by.
|
|
108
|
+
// True where the host can run a snapshot, false where it is optional and
|
|
109
|
+
// cannot, null where it cannot but is installed anyway. pnpm 11 and 12 take
|
|
110
|
+
// `optional` from the edge. A patched one's engines are checked later
|
|
111
|
+
// (patchedLater), save its published ones by pnpm 12 `walking` the lockfile.
|
|
119
112
|
function createCheck(context) {
|
|
120
113
|
const { host, settings } = context
|
|
121
114
|
const node = nodeOf(context)
|
|
122
115
|
const later = patchedLater(context)
|
|
123
|
-
return (key, pkg, optional = pkg.optional) => {
|
|
116
|
+
return (key, pkg, optional = pkg.optional, walking = false) => {
|
|
124
117
|
const platform = takesPlatform(host.major >= 11 && optional ? effectivePlatform(pkg) : pkg, host, settings.supportedArchitectures)
|
|
125
|
-
|
|
118
|
+
const engines = later && !(walking && host.major >= 12) && pkg.patchHash !== undefined ? {} : pkg.engines
|
|
119
|
+
if (host.major >= 12 && platform && (optional || settings.engineStrict)) checkSure12(engines.node, quote(key))
|
|
120
|
+
if (platform && takesEngine(engines, node)) return true
|
|
126
121
|
if (optional) return false
|
|
127
|
-
if (settings.engineStrict && !pkg.optional) throw new DeptreeError(`the host does not take its ${platform ? 'engines.node' : 'os, cpu or libc'}, which engineStrict refuses`, quote(key))
|
|
122
|
+
if (settings.engineStrict && (host.major >= 12 || !pkg.optional)) throw new DeptreeError(`the host does not take its ${platform ? 'engines.node' : 'os, cpu or libc'}, which engineStrict refuses`, quote(key))
|
|
128
123
|
return null
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
// the package is optional, it removes it from the tree it has linked,
|
|
135
|
-
// which is refused too.
|
|
127
|
+
// pnpm removes an optional package that fails this from the tree already
|
|
128
|
+
// linked, also refused. pnpm 12 passes over engines.runtime's Node here.
|
|
136
129
|
export function createPatchedCheck(context) {
|
|
137
130
|
if (!patchedLater(context)) return undefined
|
|
138
|
-
const
|
|
131
|
+
const { host, settings } = context
|
|
132
|
+
const node = host.major >= 12 ? settings.nodeVersion ?? host.node : nodeOf(context)
|
|
139
133
|
return (manifest, where) => {
|
|
140
|
-
if (manifest.engines
|
|
141
|
-
|
|
134
|
+
if (manifest.engines == null) return
|
|
135
|
+
if (host.major >= 12) checkSure12(manifest.engines.node, where, 'the engines.node of its package.json, patched')
|
|
136
|
+
if (takesEngine(manifest.engines, node)) return
|
|
137
|
+
throw new DeptreeError(`its package.json, patched, has an engines.node, ${quote(String(manifest.engines.node))}, that does not take Node ${node}, which pnpm ${host.major} refuses with engineStrict, or removes the package for where it is optional`, where)
|
|
142
138
|
}
|
|
143
139
|
}
|
|
144
140
|
|
|
145
|
-
// A reference's key, or the project a `link:` leads to, if it is one.
|
|
146
141
|
function split(targets, lockfile) {
|
|
147
142
|
const keys = []
|
|
148
143
|
const projects = []
|
|
@@ -153,61 +148,66 @@ function split(targets, lockfile) {
|
|
|
153
148
|
return { keys, projects }
|
|
154
149
|
}
|
|
155
150
|
|
|
156
|
-
//
|
|
157
|
-
// links to
|
|
158
|
-
//
|
|
151
|
+
// As pnpm's toImporterDepPaths lists them: a project's snapshots, then those
|
|
152
|
+
// of projects it links to not walked yet. A loop where pnpm recurses, so a
|
|
153
|
+
// long chain of projects runs out of no stack.
|
|
159
154
|
function projectKeys(lockfile, ids, walked) {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
155
|
+
const all = []
|
|
156
|
+
for (let more = ids; more.length > 0;) {
|
|
157
|
+
const targets = more.flatMap((id) => {
|
|
158
|
+
const importer = lockfile.importers[id]
|
|
159
|
+
return Object.values({ ...importer.dependencies, ...importer.devDependencies, ...importer.optionalDependencies })
|
|
160
|
+
})
|
|
161
|
+
const { keys, projects } = split(targets, lockfile)
|
|
162
|
+
for (const key of keys) all.push(key)
|
|
163
|
+
more = projects.filter((id) => !walked.has(id))
|
|
164
|
+
for (const id of more) walked.add(id)
|
|
165
|
+
}
|
|
166
|
+
return all
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
//
|
|
171
|
-
|
|
169
|
+
// Each key by `check`: false adds it to `skipped`, null to `incompatible`.
|
|
170
|
+
function checkEach(keys, check, skipped = new Set()) {
|
|
171
|
+
const incompatible = new Set()
|
|
172
|
+
for (const key of keys) {
|
|
173
|
+
const ok = check(key)
|
|
174
|
+
if (ok === false) skipped.add(key)
|
|
175
|
+
if (ok === null) incompatible.add(key)
|
|
176
|
+
}
|
|
177
|
+
return { skipped, incompatible }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// pnpm 11's filterLockfileByImportersAndEngine, breadth first by edge kind:
|
|
181
|
+
// an optional edge to a snapshot the host cannot run is not taken, a
|
|
182
|
+
// required one is, with a warning; each reachable one not taken is left out.
|
|
172
183
|
function skippedSnapshots11(lockfile, check) {
|
|
173
184
|
const edgesOf = (deps, optional) => Object.values(deps).filter((target) => !target.startsWith('link:')).map((key) => ({ key, optional }))
|
|
174
185
|
const queue = Object.values(lockfile.importers).flatMap((importer) => [...edgesOf(importer.dependencies, false), ...edgesOf(importer.devDependencies, false), ...edgesOf(importer.optionalDependencies, true)])
|
|
175
186
|
const starts = queue.map(({ key }) => key)
|
|
176
187
|
const installed = new Set()
|
|
177
188
|
const required = new Set()
|
|
178
|
-
const
|
|
189
|
+
const reached = new Map()
|
|
179
190
|
for (let i = 0; i < queue.length; i++) {
|
|
180
191
|
const { key, optional } = queue[i]
|
|
181
192
|
if (!optional) required.add(key)
|
|
182
193
|
if (installed.has(key)) continue
|
|
183
194
|
const pkg = lockfile.packages[key]
|
|
184
|
-
if (!
|
|
185
|
-
if (optional &&
|
|
195
|
+
if (!reached.has(key)) reached.set(key, optional && check(key, pkg, true, true) === false)
|
|
196
|
+
if (optional && reached.get(key)) continue
|
|
186
197
|
installed.add(key)
|
|
187
198
|
queue.push(...edgesOf(pkg.dependencies, false), ...edgesOf(pkg.optionalDependencies, true))
|
|
188
199
|
}
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
for (const key of
|
|
192
|
-
const pkg = lockfile.packages[key]
|
|
193
|
-
const ok = check(key, pkg, !installed.has(key) || !required.has(key))
|
|
194
|
-
if (ok === false) skipped.add(key)
|
|
195
|
-
if (ok === null) warned.add(key)
|
|
196
|
-
}
|
|
197
|
-
const seen = new Set()
|
|
198
|
-
for (let i = 0; i < starts.length; i++) {
|
|
199
|
-
const key = starts[i]
|
|
200
|
-
if (seen.has(key)) continue
|
|
201
|
-
seen.add(key)
|
|
200
|
+
const checked = checkEach(reached.keys(), (key) => check(key, lockfile.packages[key], !installed.has(key) || !required.has(key)))
|
|
201
|
+
const seen = new Set(starts)
|
|
202
|
+
for (const key of seen) {
|
|
202
203
|
const pkg = lockfile.packages[key]
|
|
203
|
-
if (!installed.has(key) && pkg.optional) skipped.add(key)
|
|
204
|
-
|
|
204
|
+
if (!installed.has(key) && pkg.optional) checked.skipped.add(key)
|
|
205
|
+
for (const edge of [...edgesOf(pkg.dependencies), ...edgesOf(pkg.optionalDependencies)]) seen.add(edge.key)
|
|
205
206
|
}
|
|
206
|
-
return
|
|
207
|
+
return checked
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
// The
|
|
210
|
-
// host cannot run them, the host and settings being `context`'s.
|
|
210
|
+
// The snapshots left out, and those installed that the host cannot run.
|
|
211
211
|
export function skippedSnapshots(lockfile, context) {
|
|
212
212
|
const check = createCheck(context)
|
|
213
213
|
if (context.host.major >= 11) return skippedSnapshots11(lockfile, check)
|
|
@@ -215,26 +215,25 @@ export function skippedSnapshots(lockfile, context) {
|
|
|
215
215
|
const walked = new Set(ids)
|
|
216
216
|
const picked = new Set()
|
|
217
217
|
const skipped = new Set()
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
visit([...next, ...projectKeys(lockfile, projects, walked)], installable)
|
|
218
|
+
// Depth first, as pnpm recurses, on a stack of its own: a chain of
|
|
219
|
+
// snapshots as long as a lockfile can make runs out of none.
|
|
220
|
+
const stack = [{ keys: projectKeys(lockfile, ids, walked).values(), installable: true }]
|
|
221
|
+
while (stack.length > 0) {
|
|
222
|
+
const { keys, installable: parentInstallable } = stack.at(-1)
|
|
223
|
+
const { value: key, done } = keys.next()
|
|
224
|
+
if (done) {
|
|
225
|
+
stack.pop()
|
|
226
|
+
continue
|
|
228
227
|
}
|
|
228
|
+
if (picked.has(key)) continue
|
|
229
|
+
const pkg = lockfile.packages[key]
|
|
230
|
+
const installable = parentInstallable && check(key, pkg) !== false
|
|
231
|
+
if (!installable && pkg.optional) skipped.add(key)
|
|
232
|
+
picked.add(key)
|
|
233
|
+
const { keys: next, projects } = split(Object.values({ ...pkg.dependencies, ...pkg.optionalDependencies }), lockfile)
|
|
234
|
+
for (const id of projects) walked.add(id)
|
|
235
|
+
stack.push({ keys: [...next, ...projectKeys(lockfile, projects, walked)].values(), installable })
|
|
229
236
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const incompatible = new Set()
|
|
233
|
-
for (const key of picked) {
|
|
234
|
-
if (skipped.has(key)) continue
|
|
235
|
-
const ok = check(key, lockfile.packages[key])
|
|
236
|
-
if (ok === false) skipped.add(key)
|
|
237
|
-
if (ok === null) incompatible.add(key)
|
|
238
|
-
}
|
|
239
|
-
return { skipped, incompatible }
|
|
237
|
+
// @pnpm/deps.graph-builder checks the rest again, each on its own.
|
|
238
|
+
return checkEach([...picked].filter((key) => !skipped.has(key)), (key) => check(key, lockfile.packages[key]), skipped)
|
|
240
239
|
}
|
package/src/pnpm/local.js
CHANGED
|
@@ -1,65 +1,120 @@
|
|
|
1
|
-
// Directories outside node_modules the tree links to or installs,
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// and is under the lockfile's directory. Each has to hold a package.json
|
|
5
|
-
// there, whose bins take their names as pnpm links them. An override to a
|
|
6
|
-
// directory is read only from a Vfs given. One by `file:` has pnpm install
|
|
7
|
-
// the directory as a package, of the files npm-packlist picks
|
|
8
|
-
// (packlist.js); one to a tarball is refused.
|
|
1
|
+
// Directories outside node_modules the tree links to or installs, read from the
|
|
2
|
+
// project given. Each must hold a package.json, whose bins take their names as
|
|
3
|
+
// pnpm links them.
|
|
9
4
|
|
|
10
|
-
import {
|
|
5
|
+
import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
6
|
+
import { DeptreeError, difference, quote } from '../error.js'
|
|
7
|
+
import { readManifest } from '../manifest.js'
|
|
8
|
+
import { readText, typeOf } from '../project.js'
|
|
9
|
+
import { parseSpec } from './frozen.js'
|
|
10
|
+
import { localOf } from './overrides.js'
|
|
11
|
+
import { checkManifest } from './package.js'
|
|
11
12
|
import { packDirectory } from './packlist.js'
|
|
12
|
-
import { readManifest } from './projects.js'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
function manifestAt(vfs, dir, where) {
|
|
18
|
-
const path = `/${dir}/package.json`
|
|
19
|
-
if (!vfs.isFile(path)) throw new DeptreeError(`${quote(dir)} holds no package.json in the Vfs given`, where)
|
|
20
|
-
let text
|
|
21
|
-
try {
|
|
22
|
-
text = decoder.decode(vfs.readFile(path))
|
|
23
|
-
} catch {
|
|
24
|
-
throw new DeptreeError(`${quote(`${dir}/package.json`)} is not UTF-8`, where)
|
|
25
|
-
}
|
|
14
|
+
function manifestAt(project, dir, where) {
|
|
15
|
+
const text = readText(project, `/${dir}/package.json`, where)
|
|
16
|
+
if (text === undefined) throw new DeptreeError(`${quote(dir)} ${typeOf(project, `/${dir}`) === undefined ? 'is not in' : 'holds no package.json in'} the project given`, where)
|
|
26
17
|
return readManifest(text, where)
|
|
27
18
|
}
|
|
28
19
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
export function checkLocalOverrides(overrides, vfs) {
|
|
20
|
+
// The directories `file:` overrides have pnpm install.
|
|
21
|
+
export function checkLocalOverrides(overrides, project) {
|
|
32
22
|
const installed = new Set()
|
|
33
23
|
for (const { selector, local } of overrides) {
|
|
34
24
|
if (local === undefined) continue
|
|
35
25
|
const where = `overrides[${quote(selector)}]`
|
|
36
|
-
if (
|
|
37
|
-
if (local.protocol === 'file:' &&
|
|
38
|
-
manifestAt(
|
|
26
|
+
if (project === undefined) throw new DeptreeError(`an override to a directory, ${quote(local.dir)}, is read only from a project given`, where)
|
|
27
|
+
if (local.protocol === 'file:' && typeOf(project, `/${local.dir}`) === 'file') throw new DeptreeError(`${quote(local.dir)} is a file in the project given, and an override to a tarball is not supported`, where)
|
|
28
|
+
manifestAt(project, local.dir, where)
|
|
39
29
|
if (local.protocol === 'file:') installed.add(local.dir)
|
|
40
30
|
}
|
|
41
31
|
return installed
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
// The
|
|
45
|
-
|
|
46
|
-
// to be for the name the lockfile has; the lockfile has no version.
|
|
47
|
-
export function readDirectoryPackage(vfs, pkg, where, major) {
|
|
34
|
+
// The lockfile records no version for a `file:` dependency's directory.
|
|
35
|
+
export function readDirectoryPackage(project, pkg, where, host) {
|
|
48
36
|
const { directory } = pkg.resolution
|
|
49
|
-
const manifest = manifestAt(
|
|
37
|
+
const manifest = manifestAt(project, directory, where)
|
|
50
38
|
if (manifest.name !== pkg.name) throw new DeptreeError(`its package.json is for ${quote(String(manifest.name))}`, where)
|
|
51
|
-
|
|
39
|
+
const files = packDirectory(project, directory, manifest, host.pnpm, where)
|
|
40
|
+
checkManifest(manifest, pkg, where, host.major)
|
|
41
|
+
return { files, manifest, local: true }
|
|
52
42
|
}
|
|
53
43
|
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
// pnpm takes `npm:@scope/name@workspace:<range>` for a path, for its `/`,
|
|
45
|
+
// which no other resolver takes, and links to a directory of that name.
|
|
46
|
+
const ALIASED = /(?:^|\/)(npm:(@[^/]+\/[^/]+)@(workspace:[^/]*))$/u
|
|
47
|
+
|
|
48
|
+
// pnpm links to a directory that is not there all the same: pnpm 10 and 11
|
|
49
|
+
// warn as they resolve, and none does as a frozen install. Refused, with the
|
|
50
|
+
// project given or, for the spec it takes for a path, without, but where the
|
|
51
|
+
// project holds a directory of that name.
|
|
52
|
+
export function readLinked(links, nodes, projects, project) {
|
|
58
53
|
const linked = new Map()
|
|
59
|
-
if (vfs === undefined) return linked
|
|
60
54
|
for (const [path, target] of links) {
|
|
61
55
|
if (nodes.has(target) || projects.has(target) || linked.has(target) || target === '..' || target.startsWith('../')) continue
|
|
62
|
-
|
|
56
|
+
const aliased = ALIASED.exec(target)
|
|
57
|
+
if (aliased !== null && (project === undefined || typeOf(project, `/${target}`) === undefined)) {
|
|
58
|
+
const [, spec, name, range] = aliased
|
|
59
|
+
throw new DeptreeError(`pnpm takes ${quote(spec)} for a path, for its "/", and links to ${quote(target)}${project === undefined ? '' : ', which is not there'}; ${quote(range.replace(':', `:${name}@`))} is the spec that links the workspace package`, quote(path))
|
|
60
|
+
}
|
|
61
|
+
if (project !== undefined) linked.set(target, manifestAt(project, target, quote(path)))
|
|
63
62
|
}
|
|
64
63
|
return linked
|
|
65
64
|
}
|
|
65
|
+
|
|
66
|
+
// Whether pnpm 12 takes `target` to be what `spec` asks for.
|
|
67
|
+
function resolvesTo(name, spec, target, packages) {
|
|
68
|
+
if (target.startsWith('link:')) return false
|
|
69
|
+
const locked = packages[target]
|
|
70
|
+
const { name: wanted, range } = parseSpec(spec, name)
|
|
71
|
+
if (locked.name !== wanted) return false
|
|
72
|
+
const version = valid(locked.version ?? '')
|
|
73
|
+
return validRange(range) === null || version === null || satisfies(version, range)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const optionalPeers = (meta) => Object.entries(meta ?? {}).filter(([, item]) => item?.optional === true).map(([name]) => name).sort()
|
|
77
|
+
|
|
78
|
+
// `read` is the hooked package.json. A peer may be among the snapshot's
|
|
79
|
+
// dependencies and an optional one missing; a `file:` or `link:` one is left to
|
|
80
|
+
// package.js's checkDependencies.
|
|
81
|
+
function checkFresh(read, pkg, packages, where) {
|
|
82
|
+
const outdated = (why) => new DeptreeError(`the lockfile is not up to date with its package.json, which a frozen install of pnpm 12 refuses: ${why}`, where)
|
|
83
|
+
const wanted = { dependencies: read.dependencies ?? {}, optionalDependencies: read.optionalDependencies ?? {} }
|
|
84
|
+
const peers = read.peerDependencies ?? {}
|
|
85
|
+
for (const [kind, others] of [['dependencies', peers], ['optionalDependencies', {}]]) {
|
|
86
|
+
for (const name of Object.keys(pkg[kind])) {
|
|
87
|
+
if (!Object.hasOwn(wanted[kind], name) && !Object.hasOwn(others, name)) throw outdated(`${kind}.${name} is not one it asks for`)
|
|
88
|
+
}
|
|
89
|
+
for (const [name, spec] of Object.entries(wanted[kind])) {
|
|
90
|
+
const target = pkg[kind][name]
|
|
91
|
+
if (target === undefined) {
|
|
92
|
+
if (kind === 'optionalDependencies') continue
|
|
93
|
+
throw outdated(`${kind}.${name} is not in the lockfile`)
|
|
94
|
+
}
|
|
95
|
+
if (spec.startsWith('file:') || spec.startsWith('link:')) continue
|
|
96
|
+
if (spec.startsWith('workspace:')) throw new DeptreeError(`a workspace: dependency, ${quote(name)}, of a directory pnpm 12 holds to the lockfile is not supported`, where)
|
|
97
|
+
if (localOf(spec, where) !== undefined || !resolvesTo(name, spec, target, packages)) throw outdated(`${kind}.${name} is not resolved as it asks`)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const peersDiffer = difference(peers, pkg.peerDependencies, ['its package.json', 'the lockfile'])
|
|
101
|
+
if (peersDiffer !== undefined) throw outdated(`its peerDependencies are not the lockfile's: ${peersDiffer}`)
|
|
102
|
+
if (JSON.stringify(optionalPeers(read.peerDependenciesMeta)) !== JSON.stringify(optionalPeers(pkg.peerDependenciesMeta))) throw outdated('which of its peers are optional is not the lockfile\'s')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// pnpm 12's check, before it installs, of each snapshot a project depends on by
|
|
106
|
+
// a `file:` specifier to a directory.
|
|
107
|
+
export function createFreshnessCheck(lockfile, major) {
|
|
108
|
+
if (major < 12) return undefined
|
|
109
|
+
const direct = new Set()
|
|
110
|
+
for (const importer of Object.values(lockfile.importers)) {
|
|
111
|
+
for (const [name, target] of Object.entries({ ...importer.dependencies, ...importer.devDependencies, ...importer.optionalDependencies })) {
|
|
112
|
+
const spec = importer.specifiers[name]
|
|
113
|
+
if (target.startsWith('link:') || !spec?.startsWith('file:') || /\.(?:tgz|tar\.gz|tar)$/u.test(spec)) continue
|
|
114
|
+
if (lockfile.packages[target].resolution.type === 'directory') direct.add(target)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return (node, read) => {
|
|
118
|
+
if (direct.has(node.key)) checkFresh(read, node.pkg, lockfile.packages, quote(node.key))
|
|
119
|
+
}
|
|
120
|
+
}
|