@preventive/deptree 1.0.0-alpha.5 → 1.0.0-alpha.7
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/npm.d.ts +288 -0
- package/npm.js +7 -0
- package/package.json +41 -12
- package/pnpm.d.ts +158 -25
- package/pnpm.js +2 -10
- package/soldeer.d.ts +13 -0
- package/soldeer.js +1 -7
- package/src/concurrent.js +16 -17
- package/src/error.js +5 -9
- package/src/glob.js +55 -0
- package/src/hash.js +60 -13
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +104 -44
- 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 +136 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +22 -41
- package/src/pnpm/bins.js +152 -131
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +53 -96
- package/src/pnpm/filename.js +10 -21
- package/src/pnpm/frozen.js +29 -75
- package/src/pnpm/gitignore.js +139 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +15 -43
- package/src/pnpm/hoist.js +68 -61
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +73 -56
- package/src/pnpm/install.js +85 -131
- package/src/pnpm/local.js +21 -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 +121 -0
- package/src/pnpm/packlist.js +169 -109
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +63 -107
- package/src/pnpm/readers.js +63 -83
- package/src/pnpm/settings.js +64 -100
- package/src/pnpm/tree.js +197 -169
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +124 -133
- package/src/project.js +57 -0
- package/src/soldeer/config.js +8 -24
- package/src/soldeer/inputs.js +5 -15
- package/src/soldeer/tree.js +22 -60
- package/src/soldeer/zip.js +17 -36
- package/src/tarball.js +55 -140
- package/src/yarn1/bins.js +9 -19
- package/src/yarn1/compat.js +9 -28
- package/src/yarn1/hoist.js +53 -68
- package/src/yarn1/inputs.js +19 -61
- package/src/yarn1/manifest.js +8 -23
- package/src/yarn1/package.js +24 -63
- package/src/yarn1/peers.js +8 -15
- package/src/yarn1/requests.js +19 -37
- package/src/yarn1/resolve.js +36 -113
- package/src/yarn1/settings.js +15 -43
- package/src/yarn1/tree.js +67 -91
- package/yarn1.d.ts +34 -5
- package/yarn1.js +1 -8
- package/src/pnpm/npmrc.js +0 -31
- package/src/pnpm/project.js +0 -97
- package/src/yarn1/glob.js +0 -52
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/src/pnpm/install.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
// Which snapshots a
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// as it does for pnpm (@pnpm/lockfile.filtering's pkgAllDeps, then
|
|
7
|
-
// @pnpm/deps.graph-builder checking every snapshot again), so a snapshot
|
|
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
|
-
// pnpm 12 leaves out the same, but refuses with engineStrict whatever it
|
|
24
|
-
// installs that the host cannot run, the lockfile's optional mark or not,
|
|
25
|
-
// and holds a patched package's published engines to the host as it walks
|
|
26
|
-
// it. Of a project it checks only the root's engines.node, and only with
|
|
27
|
-
// engineStrict. It reads an engines.node npm's semver does not, or a
|
|
28
|
-
// range of a `-` with an `x`, otherwise than npm's semver, which is
|
|
29
|
-
// refused where it would decide what is installed.
|
|
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.
|
|
30
6
|
|
|
31
7
|
import { satisfies, validRange } from '@preventive/upstream/semver.js'
|
|
32
8
|
import { DeptreeError, quote } from '../error.js'
|
|
33
9
|
|
|
34
|
-
// pnpm's checkList
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
// takes nothing where the host is taken to be more than one thing; pnpm 11
|
|
38
|
-
// does not. pnpm 12 takes, of each value, the first item that names it.
|
|
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.
|
|
39
13
|
function checkList(values, list, major) {
|
|
40
14
|
if (list.length === 1 && list[0] === 'any') return true
|
|
41
15
|
let match = false
|
|
@@ -54,8 +28,7 @@ function checkList(values, list, major) {
|
|
|
54
28
|
return match || (major >= 11 ? list.every((item) => item.startsWith('!')) : excluded === list.length)
|
|
55
29
|
}
|
|
56
30
|
|
|
57
|
-
// pnpm 11's inferPlatformFromPackageName
|
|
58
|
-
// of a package's name, less its scope, say it is for.
|
|
31
|
+
// pnpm 11's inferPlatformFromPackageName, from the unscoped name's words.
|
|
59
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' }
|
|
60
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' }
|
|
61
34
|
const LIBC_WORDS = { __proto__: null, glibc: 'glibc', gnu: 'glibc', gnueabihf: 'glibc', musl: 'musl', musleabihf: 'musl' }
|
|
@@ -77,44 +50,34 @@ function effectivePlatform(pkg) {
|
|
|
77
50
|
return { ...pkg, os: pkg.os ?? inferred.os, cpu: pkg.cpu ?? inferred.cpu, libc: pkg.libc ?? inferred.libc }
|
|
78
51
|
}
|
|
79
52
|
|
|
80
|
-
// What the host is taken to be: itself, or what `supportedArchitectures`
|
|
81
|
-
// lists for each, `current` standing for itself.
|
|
82
53
|
const current = (value, supported) => (supported ?? ['current']).map((item) => (item === 'current' ? value : item))
|
|
83
54
|
|
|
84
|
-
const takesPlatform = (pkg, host, supported) =>
|
|
85
|
-
|
|
86
|
-
&& (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))
|
|
87
57
|
|
|
88
58
|
const takesEngine = (engines, node) => !engines.node || satisfies(node, engines.node, { includePrerelease: true })
|
|
89
59
|
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
// takes none of it, and reads a `-` range with an `x` as taking nothing.
|
|
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.
|
|
93
62
|
function checkSure12(range, where, what = 'its engines.node') {
|
|
94
63
|
if (typeof range !== 'string' || (validRange(range) !== null && !(/\s-\s/u.test(range) && /[*xX]/u.test(range)))) return
|
|
95
64
|
throw new DeptreeError(`${what}, ${quote(range)}, pnpm 12 reads otherwise than npm's semver, which is not supported`, where)
|
|
96
65
|
}
|
|
97
66
|
|
|
98
|
-
// The Node pnpm checks engines.node against: nodeVersion, else the Node
|
|
99
|
-
// the root's engines.runtime pins, else the host's.
|
|
100
67
|
const nodeOf = ({ host, settings }) => settings.nodeVersion ?? settings.runtimeNodeVersion ?? host.node
|
|
101
68
|
|
|
102
|
-
// With engineStrict, pnpm 11
|
|
103
|
-
//
|
|
104
|
-
// 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.
|
|
105
71
|
const patchedLater = ({ host, settings }) => host.major >= 11 && settings.engineStrict === true
|
|
106
72
|
|
|
107
|
-
// A package.json's os, cpu or libc as pnpm's checkList reads one
|
|
108
|
-
// 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.
|
|
109
74
|
function platformList(value, where) {
|
|
110
|
-
if (value
|
|
75
|
+
if (value == null) return undefined
|
|
111
76
|
if (typeof value === 'string') return [value]
|
|
112
77
|
if (Array.isArray(value)) return value.filter((item) => typeof item === 'string')
|
|
113
78
|
throw new DeptreeError('expected a string or a list of them', where)
|
|
114
79
|
}
|
|
115
80
|
|
|
116
|
-
// pnpm 12 checks the root project's engines.node, where it is text, with
|
|
117
|
-
// engineStrict alone.
|
|
118
81
|
function checkRoot12(manifest, where, context) {
|
|
119
82
|
const range = manifest.engines?.node
|
|
120
83
|
if (!context.settings.engineStrict || typeof range !== 'string' || range === '') return
|
|
@@ -123,21 +86,18 @@ function checkRoot12(manifest, where, context) {
|
|
|
123
86
|
if (!takesEngine({ node: range }, node)) throw new DeptreeError(`its engines.node, ${quote(range)}, does not take Node ${node}, which engineStrict refuses`, where)
|
|
124
87
|
}
|
|
125
88
|
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
// does not take is always refused. As pnpm has it, a platform that does
|
|
130
|
-
// not match is found first, and the engines are then not looked at.
|
|
131
|
-
// pnpm 12's is checkRoot12, of the root alone.
|
|
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.
|
|
132
92
|
export function checkProject(manifest, where, { host, settings, root }) {
|
|
133
93
|
if (host.major >= 12) {
|
|
134
94
|
if (root) checkRoot12(manifest, where, { host, settings })
|
|
135
95
|
return
|
|
136
96
|
}
|
|
137
97
|
const platform = { os: platformList(manifest.os, `${where}.os`), cpu: platformList(manifest.cpu, `${where}.cpu`), libc: platformList(manifest.libc, `${where}.libc`) }
|
|
138
|
-
if (!takesPlatform(platform, host, settings.supportedArchitectures)) return
|
|
139
|
-
const engines = manifest
|
|
140
|
-
if (engines
|
|
98
|
+
if (!takesPlatform(platform, host, host.major < 10 ? undefined : settings.supportedArchitectures)) return
|
|
99
|
+
const { engines } = manifest
|
|
100
|
+
if (engines == null) return
|
|
141
101
|
const node = nodeOf({ host, settings })
|
|
142
102
|
if (engines.pnpm && !satisfies(host.pnpm, engines.pnpm, { includePrerelease: true })) {
|
|
143
103
|
throw new DeptreeError(`its engines.pnpm, ${quote(String(engines.pnpm))}, does not take pnpm ${host.pnpm}, which pnpm refuses`, where)
|
|
@@ -145,14 +105,10 @@ export function checkProject(manifest, where, { host, settings, root }) {
|
|
|
145
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)
|
|
146
106
|
}
|
|
147
107
|
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
// takes a snapshot to be optional as the lockfile marks it; pnpm 11 as the
|
|
153
|
-
// edge it is reached by. A patched one's engines wait for its package.json,
|
|
154
|
-
// patched (patchedLater), but where pnpm 12 is `walking` the lockfile,
|
|
155
|
-
// which holds it to its published ones.
|
|
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.
|
|
156
112
|
function createCheck(context) {
|
|
157
113
|
const { host, settings } = context
|
|
158
114
|
const node = nodeOf(context)
|
|
@@ -168,24 +124,20 @@ function createCheck(context) {
|
|
|
168
124
|
}
|
|
169
125
|
}
|
|
170
126
|
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
// the package is optional, it removes it from the tree it has linked,
|
|
174
|
-
// which is refused too. pnpm 12 holds it to nodeVersion, else the host's
|
|
175
|
-
// Node, whatever the root's engines.runtime pins.
|
|
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.
|
|
176
129
|
export function createPatchedCheck(context) {
|
|
177
130
|
if (!patchedLater(context)) return undefined
|
|
178
131
|
const { host, settings } = context
|
|
179
132
|
const node = host.major >= 12 ? settings.nodeVersion ?? host.node : nodeOf(context)
|
|
180
133
|
return (manifest, where) => {
|
|
181
|
-
if (manifest.engines
|
|
134
|
+
if (manifest.engines == null) return
|
|
182
135
|
if (host.major >= 12) checkSure12(manifest.engines.node, where, 'the engines.node of its package.json, patched')
|
|
183
136
|
if (takesEngine(manifest.engines, node)) return
|
|
184
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)
|
|
185
138
|
}
|
|
186
139
|
}
|
|
187
140
|
|
|
188
|
-
// A reference's key, or the project a `link:` leads to, if it is one.
|
|
189
141
|
function split(targets, lockfile) {
|
|
190
142
|
const keys = []
|
|
191
143
|
const projects = []
|
|
@@ -196,30 +148,44 @@ function split(targets, lockfile) {
|
|
|
196
148
|
return { keys, projects }
|
|
197
149
|
}
|
|
198
150
|
|
|
199
|
-
//
|
|
200
|
-
// links to
|
|
201
|
-
//
|
|
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.
|
|
202
154
|
function projectKeys(lockfile, ids, walked) {
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
211
167
|
}
|
|
212
168
|
|
|
213
|
-
//
|
|
214
|
-
|
|
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.
|
|
215
183
|
function skippedSnapshots11(lockfile, check) {
|
|
216
184
|
const edgesOf = (deps, optional) => Object.values(deps).filter((target) => !target.startsWith('link:')).map((key) => ({ key, optional }))
|
|
217
185
|
const queue = Object.values(lockfile.importers).flatMap((importer) => [...edgesOf(importer.dependencies, false), ...edgesOf(importer.devDependencies, false), ...edgesOf(importer.optionalDependencies, true)])
|
|
218
186
|
const starts = queue.map(({ key }) => key)
|
|
219
187
|
const installed = new Set()
|
|
220
188
|
const required = new Set()
|
|
221
|
-
// Each snapshot reached, and whether the host cannot run it, as checked
|
|
222
|
-
// where an optional edge first reaches it.
|
|
223
189
|
const reached = new Map()
|
|
224
190
|
for (let i = 0; i < queue.length; i++) {
|
|
225
191
|
const { key, optional } = queue[i]
|
|
@@ -231,28 +197,17 @@ function skippedSnapshots11(lockfile, check) {
|
|
|
231
197
|
installed.add(key)
|
|
232
198
|
queue.push(...edgesOf(pkg.dependencies, false), ...edgesOf(pkg.optionalDependencies, true))
|
|
233
199
|
}
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
for (const key of
|
|
237
|
-
const pkg = lockfile.packages[key]
|
|
238
|
-
const ok = check(key, pkg, !installed.has(key) || !required.has(key))
|
|
239
|
-
if (ok === false) skipped.add(key)
|
|
240
|
-
if (ok === null) warned.add(key)
|
|
241
|
-
}
|
|
242
|
-
const seen = new Set()
|
|
243
|
-
for (let i = 0; i < starts.length; i++) {
|
|
244
|
-
const key = starts[i]
|
|
245
|
-
if (seen.has(key)) continue
|
|
246
|
-
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) {
|
|
247
203
|
const pkg = lockfile.packages[key]
|
|
248
|
-
if (!installed.has(key) && pkg.optional) skipped.add(key)
|
|
249
|
-
|
|
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)
|
|
250
206
|
}
|
|
251
|
-
return
|
|
207
|
+
return checked
|
|
252
208
|
}
|
|
253
209
|
|
|
254
|
-
// The
|
|
255
|
-
// host cannot run them, the host and settings being `context`'s.
|
|
210
|
+
// The snapshots left out, and those installed that the host cannot run.
|
|
256
211
|
export function skippedSnapshots(lockfile, context) {
|
|
257
212
|
const check = createCheck(context)
|
|
258
213
|
if (context.host.major >= 11) return skippedSnapshots11(lockfile, check)
|
|
@@ -260,26 +215,25 @@ export function skippedSnapshots(lockfile, context) {
|
|
|
260
215
|
const walked = new Set(ids)
|
|
261
216
|
const picked = new Set()
|
|
262
217
|
const skipped = new Set()
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
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
|
|
273
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 })
|
|
274
236
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const incompatible = new Set()
|
|
278
|
-
for (const key of picked) {
|
|
279
|
-
if (skipped.has(key)) continue
|
|
280
|
-
const ok = check(key, lockfile.packages[key])
|
|
281
|
-
if (ok === false) skipped.add(key)
|
|
282
|
-
if (ok === null) incompatible.add(key)
|
|
283
|
-
}
|
|
284
|
-
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)
|
|
285
239
|
}
|
package/src/pnpm/local.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
// Directories outside node_modules the tree links to or installs, read
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// the lockfile's directory. Each has to hold a package.json there, whose
|
|
5
|
-
// bins take their names as pnpm links them. An override to a directory is
|
|
6
|
-
// read only from a project given. One by `file:` has pnpm install the
|
|
7
|
-
// directory as a package, of the files npm-packlist picks (packlist.js);
|
|
8
|
-
// one to a tarball is refused. pnpm 12 holds one a project depends on to
|
|
9
|
-
// the lockfile before it installs (createFreshnessCheck).
|
|
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.
|
|
10
4
|
|
|
11
5
|
import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
|
|
12
6
|
import { DeptreeError, difference, quote } from '../error.js'
|
|
13
|
-
import {
|
|
7
|
+
import { readManifest } from '../manifest.js'
|
|
8
|
+
import { readText, typeOf } from '../project.js'
|
|
9
|
+
import { parseSpec } from './frozen.js'
|
|
14
10
|
import { localOf } from './overrides.js'
|
|
11
|
+
import { checkManifest } from './package.js'
|
|
15
12
|
import { packDirectory } from './packlist.js'
|
|
16
|
-
import { readText, typeOf } from './project.js'
|
|
17
|
-
import { readManifest } from './projects.js'
|
|
18
13
|
|
|
19
14
|
function manifestAt(project, dir, where) {
|
|
20
15
|
const text = readText(project, `/${dir}/package.json`, where)
|
|
@@ -22,8 +17,7 @@ function manifestAt(project, dir, where) {
|
|
|
22
17
|
return readManifest(text, where)
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
//
|
|
26
|
-
// overrides have pnpm install.
|
|
20
|
+
// The directories `file:` overrides have pnpm install.
|
|
27
21
|
export function checkLocalOverrides(overrides, project) {
|
|
28
22
|
const installed = new Set()
|
|
29
23
|
for (const { selector, local } of overrides) {
|
|
@@ -37,19 +31,16 @@ export function checkLocalOverrides(overrides, project) {
|
|
|
37
31
|
return installed
|
|
38
32
|
}
|
|
39
33
|
|
|
40
|
-
// The
|
|
41
|
-
|
|
42
|
-
// to be for the name the lockfile has; the lockfile has no version.
|
|
43
|
-
export function readDirectoryPackage(project, pkg, where, major) {
|
|
34
|
+
// The lockfile records no version for a `file:` dependency's directory.
|
|
35
|
+
export function readDirectoryPackage(project, pkg, where, host) {
|
|
44
36
|
const { directory } = pkg.resolution
|
|
45
37
|
const manifest = manifestAt(project, directory, where)
|
|
46
38
|
if (manifest.name !== pkg.name) throw new DeptreeError(`its package.json is for ${quote(String(manifest.name))}`, where)
|
|
47
|
-
|
|
39
|
+
const files = packDirectory(project, directory, manifest, host.pnpm, where)
|
|
40
|
+
checkManifest(manifest, pkg, where, host.major)
|
|
41
|
+
return { files, manifest, local: true }
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
// By directory, the package.json of each directory the tree links to that
|
|
51
|
-
// is no node of `nodes`, no project of `projects`, and under the
|
|
52
|
-
// lockfile's directory, read from `project`; none without one.
|
|
53
44
|
export function readLinked(links, nodes, projects, project) {
|
|
54
45
|
const linked = new Map()
|
|
55
46
|
if (project === undefined) return linked
|
|
@@ -60,29 +51,21 @@ export function readLinked(links, nodes, projects, project) {
|
|
|
60
51
|
return linked
|
|
61
52
|
}
|
|
62
53
|
|
|
63
|
-
// Whether pnpm 12 takes
|
|
64
|
-
// to a directory, to be what the lockfile resolved it to, `target`: a
|
|
65
|
-
// package of the name it asks for, `npm:` aliasing another, at a version
|
|
66
|
-
// in its range, where it is a range and the version is one.
|
|
54
|
+
// Whether pnpm 12 takes `target` to be what `spec` asks for.
|
|
67
55
|
function resolvesTo(name, spec, target, packages) {
|
|
68
56
|
if (target.startsWith('link:')) return false
|
|
69
57
|
const locked = packages[target]
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
const { name: wanted, range } = parseSpec(spec, name)
|
|
59
|
+
if (locked.name !== wanted) return false
|
|
72
60
|
const version = valid(locked.version ?? '')
|
|
73
61
|
return validRange(range) === null || version === null || satisfies(version, range)
|
|
74
62
|
}
|
|
75
63
|
|
|
76
64
|
const optionalPeers = (meta) => Object.entries(meta ?? {}).filter(([, item]) => item?.optional === true).map(([name]) => name).sort()
|
|
77
65
|
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
// them, and each it asks for is there, resolved as it asks, an optional one
|
|
82
|
-
// there or not; its peers are exactly what the lockfile records, and so is
|
|
83
|
-
// which of them are optional. A `file:` or `link:` one is held to where it
|
|
84
|
-
// leads by tarball.js's checkDependencies; a path alone, or `workspace:`,
|
|
85
|
-
// is refused. `packages` is the lockfile's.
|
|
66
|
+
// `read` is the hooked package.json. A peer may be among the snapshot's
|
|
67
|
+
// dependencies and an optional one missing; a `file:` or `link:` one is left to
|
|
68
|
+
// package.js's checkDependencies.
|
|
86
69
|
function checkFresh(read, pkg, packages, where) {
|
|
87
70
|
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)
|
|
88
71
|
const wanted = { dependencies: read.dependencies ?? {}, optionalDependencies: read.optionalDependencies ?? {} }
|
|
@@ -107,10 +90,8 @@ function checkFresh(read, pkg, packages, where) {
|
|
|
107
90
|
if (JSON.stringify(optionalPeers(read.peerDependenciesMeta)) !== JSON.stringify(optionalPeers(pkg.peerDependenciesMeta))) throw outdated('which of its peers are optional is not the lockfile\'s')
|
|
108
91
|
}
|
|
109
92
|
|
|
110
|
-
// pnpm 12's check, before it installs, of each snapshot a project depends
|
|
111
|
-
//
|
|
112
|
-
// It is given the node of a snapshot and its package.json as hook.js reads
|
|
113
|
-
// it.
|
|
93
|
+
// pnpm 12's check, before it installs, of each snapshot a project depends on by
|
|
94
|
+
// a `file:` specifier to a directory.
|
|
114
95
|
export function createFreshnessCheck(lockfile, major) {
|
|
115
96
|
if (major < 12) return undefined
|
|
116
97
|
const direct = new Set()
|