@preventive/deptree 1.0.0-alpha.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.
@@ -0,0 +1,240 @@
1
+ // The projects a lockfile installs, each by its package.json, held to its
2
+ // importer as `pnpm install --frozen-lockfile` holds them
3
+ // (@pnpm/lockfile.verification's satisfiesPackageManifest): where one is
4
+ // not, pnpm refuses the lockfile as not up to date with that package.json,
5
+ // and resolves anew without --frozen-lockfile, so it is refused here too.
6
+ // Every project has to have an importer and every importer a project: the
7
+ // projects pnpm finds are what it installs, and an importer none of them
8
+ // is would be left out.
9
+ //
10
+ // A project's specifiers are its dependencies, devDependencies and
11
+ // optionalDependencies, and, with autoInstallPeers, the peerDependencies
12
+ // it does not also list otherwise, which pnpm installs as dependencies;
13
+ // each has to be what the importer records, under the kind pnpm files it
14
+ // under, and a version the importer resolved has to be in its range. Its
15
+ // publishConfig.directory and dependenciesMeta have to be the importer's.
16
+ //
17
+ // Each package.json is read as pnpm reads it before that: through its
18
+ // read-package hook (hook.js), so a direct dependency overridden or an
19
+ // optional one ignored is held to the importer as overridden or left out;
20
+ // and held to the host by its engines (install.js's checkProject). The
21
+ // root one's packageManager, where it names one, has to be the pnpm the
22
+ // tree is built for: pnpm 10 would run that one instead.
23
+ //
24
+ // pnpm 11 lets an optional dependency the importer has no specifier for
25
+ // go unresolved, takes git specifiers of one commit to be the same however
26
+ // spelled, holds publishConfig.linkDirectory to the importer too, and
27
+ // makes frozen.js's further checks.
28
+ //
29
+ // Installs are frozen, always: pnpm 10's further checks without
30
+ // --frozen-lockfile, that workspace packages are linked exactly where
31
+ // their version is in range, are not made; pnpm 11 makes them frozen too.
32
+
33
+ import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
34
+ import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
35
+ import { DeptreeError, difference, quote } from '../error.js'
36
+ import { checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, refOf, sameSpecifier } from './frozen.js'
37
+ import { checkProject } from './install.js'
38
+ import { validForOldPackages } from './overrides.js'
39
+
40
+ const KINDS = ['optionalDependencies', 'dependencies', 'devDependencies']
41
+
42
+ // A package.json as parsed, as pnpm reads one: a byte order mark dropped,
43
+ // and an object.
44
+ export function readManifest(text, where) {
45
+ if (typeof text !== 'string') throw new TypeError(`${where} must be the text of a package.json`)
46
+ let manifest
47
+ try {
48
+ manifest = JSON.parse(text.replace(/^/u, ''))
49
+ } catch (error) {
50
+ throw new DeptreeError(`not JSON: ${error.message}`, where, { cause: error })
51
+ }
52
+ if (manifest === null || typeof manifest !== 'object' || Array.isArray(manifest)) throw new DeptreeError('expected an object', where)
53
+ return manifest
54
+ }
55
+
56
+ // The manifests by project, the root one among them, as given by the
57
+ // project's directory relative to the lockfile's.
58
+ export function readManifests(manifests, lockfile) {
59
+ if (manifests === null || typeof manifests !== 'object') throw new TypeError('manifests must map each project\'s directory to its package.json')
60
+ const read = new Map()
61
+ for (const [id, text] of manifests instanceof Map ? manifests : Object.entries(manifests)) {
62
+ const where = `manifests[${quote(id)}]`
63
+ if (!(id in lockfile.importers)) throw new DeptreeError('the lockfile has no importer for this project, which pnpm refuses a frozen install for', where)
64
+ read.set(id, readManifest(text, where))
65
+ }
66
+ for (const id of Object.keys(lockfile.importers)) {
67
+ if (!read.has(id)) throw new DeptreeError('the package.json of this project is not given', `importers[${quote(id)}]`)
68
+ }
69
+ return read
70
+ }
71
+
72
+ const omit = (deps, names) => Object.fromEntries(Object.entries(deps).filter(([name]) => !names.has(name)))
73
+
74
+ // The dependencies pnpm reads a project as asking for: with
75
+ // autoInstallPeers, a peer it does not list elsewhere is a dependency; and
76
+ // those `unresolved` left out. The hook has held each of these fields to a
77
+ // mapping of strings.
78
+ function wantedOf(manifest, autoInstallPeers, unresolved) {
79
+ const kinds = Object.fromEntries(KINDS.map((kind) => [kind, manifest[kind] ?? {}]))
80
+ let all = omit({ ...kinds.devDependencies, ...kinds.dependencies, ...kinds.optionalDependencies }, unresolved)
81
+ if (autoInstallPeers) {
82
+ const peers = manifest.peerDependencies ?? {}
83
+ const unlisted = Object.fromEntries(Object.entries(peers).filter(([name]) => !Object.hasOwn(all, name)))
84
+ kinds.dependencies = { ...unlisted, ...kinds.dependencies }
85
+ all = { ...peers, ...all }
86
+ }
87
+ return { kinds, all }
88
+ }
89
+
90
+ // dependenciesMeta as the lockfile reader hands it back: `injected` false
91
+ // where it is not set.
92
+ const metaOf = (meta) => JSON.stringify(Object.entries(meta).map(([name, item]) => [name, item?.injected === true, item?.node]).sort())
93
+
94
+ function checkKind(importer, kinds, kind, unresolved, major) {
95
+ const locked = importer[kind]
96
+ const wanted = kind === 'devDependencies' ? kinds[kind] : omit(kinds[kind], unresolved)
97
+ const names = Object.keys(wanted).filter((name) => kind === 'optionalDependencies'
98
+ || (!kinds.optionalDependencies[name] && (kind === 'dependencies' || !kinds.dependencies[name])))
99
+ const unlinked = Object.values(locked).filter((target) => !target.includes('link:') && !target.includes('file:')).length
100
+ if (names.length !== Object.keys(locked).length && names.length !== unlinked) return `${kind} in the lockfile do not match the same field in package.json`
101
+ for (const name of names) {
102
+ if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
103
+ const spec = importer.specifiers[name]
104
+ if (validRange(spec) === null) continue
105
+ const version = packageKeyOf(refOf(name, locked[name]))
106
+ if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
107
+ }
108
+ return undefined
109
+ }
110
+
111
+ // Why pnpm would find `importer` not to be what `manifest` asks for, or
112
+ // undefined where it is; of the specifiers, the first difference, as
113
+ // pnpm's diffFlatRecords finds.
114
+ function mismatch(importer, manifest, autoInstallPeers, major, where) {
115
+ const optional = manifest.optionalDependencies ?? {}
116
+ const unresolved = new Set(major >= 11 ? Object.keys(optional).filter((name) => importer.specifiers[name] === undefined) : [])
117
+ const { kinds, all } = wantedOf(manifest, autoInstallPeers, unresolved)
118
+ const specified = difference(importer.specifiers, all, ['the lockfile', 'package.json'], (a, b) => sameSpecifier(a, b, major))
119
+ if (specified !== undefined) return `the specifiers differ: ${specified}`
120
+ const directory = manifest.publishConfig?.directory
121
+ if (importer.publishDirectory !== directory) return `publishDirectory is ${quote(String(importer.publishDirectory))} in the lockfile and publishConfig.directory ${quote(String(directory))} in package.json`
122
+ const linksDirectory = directory != null && manifest.publishConfig.linkDirectory !== false
123
+ if (major >= 11 && (importer.publishDirectory !== undefined && importer.linkDirectory) !== linksDirectory) return `linkDirectory is ${!linksDirectory} in the lockfile and publishConfig.linkDirectory ${linksDirectory} in package.json`
124
+ const meta = manifest.dependenciesMeta ?? {}
125
+ if (typeof meta !== 'object' || Array.isArray(meta)) throw new DeptreeError('expected a mapping', `${where}.dependenciesMeta`)
126
+ if (metaOf(importer.dependenciesMeta) !== metaOf(meta)) return 'dependenciesMeta differs'
127
+ for (const kind of KINDS) {
128
+ const reason = checkKind(importer, kinds, kind, unresolved, major)
129
+ if (reason !== undefined) return reason
130
+ }
131
+ return undefined
132
+ }
133
+
134
+ // devEngines.packageManager as pnpm 11 reads it: the pnpm one of a list,
135
+ // else its first, and what to do where it does not match.
136
+ function devEnginesPackageManager(devEngines, where) {
137
+ const engines = devEngines?.packageManager
138
+ if (!engines) return undefined
139
+ const list = Array.isArray(engines) ? engines : [engines]
140
+ if (list.some((item) => item === null || typeof item !== 'object')) throw new DeptreeError('expected a mapping or a list of mappings, which pnpm fails on otherwise', where)
141
+ if (list.length === 0) return undefined
142
+ const index = list.findIndex((item) => item.name === 'pnpm')
143
+ const engine = list[Math.max(index, 0)]
144
+ if (!engine.name) return undefined
145
+ let { onFail } = engine
146
+ if (Array.isArray(engines) && index === -1) onFail = list.at(-1).onFail ?? 'error'
147
+ else if (Array.isArray(engines)) onFail ??= index === list.length - 1 ? 'error' : 'ignore'
148
+ return { name: engine.name, onFail }
149
+ }
150
+
151
+ // packageManager as pnpm's parsePackageManager reads it, held to be this
152
+ // pnpm, exactly: pnpm switches to the version it names, and one it cannot
153
+ // switch to, or another package manager, is refused rather than run over.
154
+ // pnpm 11 reads devEngines.packageManager over it, and switches to the
155
+ // pnpm the lockfile pins for that, which is refused; either is passed
156
+ // over where what to do on a mismatch, or pmOnFail, is to warn or ignore.
157
+ function checkPackageManager(manifest, host, pmOnFail) {
158
+ const { packageManager } = manifest
159
+ if (host.major >= 11) {
160
+ const where = 'manifests["."].devEngines.packageManager'
161
+ const engine = devEnginesPackageManager(manifest.devEngines, where)
162
+ const onFail = pmOnFail ?? engine?.onFail ?? 'download'
163
+ if (onFail === 'ignore' || onFail === 'warn' || (engine === undefined && !packageManager)) return
164
+ if (engine !== undefined) throw new DeptreeError('not supported: pnpm 11 installs with the pnpm the lockfile pins for it, where it does not refuse', where)
165
+ }
166
+ if (packageManager === undefined) return
167
+ const where = 'manifests["."].packageManager'
168
+ const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
169
+ if (version === undefined || valid(version) !== version) throw new DeptreeError(`${quote(String(packageManager))} is not pnpm at an exact version`, where)
170
+ if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
171
+ }
172
+
173
+ // A runtime pnpm would download and install as a dependency, which is
174
+ // refused as the lockfile reader refuses a `runtime:` one. For the root
175
+ // project, pnpm 11 takes runtimeOnFail for each one's onFail, and checks a
176
+ // runtime whose onFail is `error` against the host's before it installs.
177
+ const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
178
+ function checkRuntimes(manifest, where, { host, onFail }) {
179
+ const checked = new Set()
180
+ for (const [field, kind] of RUNTIMES) {
181
+ const runtime = manifest[field]?.runtime
182
+ if (runtime === undefined || runtime === null) continue
183
+ const here = `${where}.${field}.runtime`
184
+ const runtimes = Array.isArray(runtime) ? runtime : [runtime]
185
+ for (const name of ['node', 'deno', 'bun']) {
186
+ if (manifest[kind]?.[name]) continue
187
+ const item = runtimes.find((each) => each?.name === name)
188
+ if (item !== undefined && (onFail ?? item.onFail) === 'download') throw new DeptreeError(`a ${name} runtime to download is not supported`, here)
189
+ }
190
+ if (host.major < 11 || where !== 'manifests["."]') continue
191
+ if (runtimes.some((item) => item === null || typeof item !== 'object')) throw new DeptreeError('expected a mapping or a list of mappings, which pnpm 11 fails on otherwise', here)
192
+ for (const item of runtimes) {
193
+ if (!['node', 'deno', 'bun'].includes(item.name) || checked.has(item.name)) continue
194
+ checked.add(item.name)
195
+ if ((onFail ?? item.onFail) !== 'error') continue
196
+ if (item.name !== 'node') throw new DeptreeError(`the ${item.name} it runs on is checked by pnpm 11, and is not known here`, here)
197
+ if (!item.version || validRange(item.version) === null) throw new DeptreeError(`${quote(String(item.version))} is not a range for Node, which pnpm 11 refuses`, here)
198
+ if (!satisfies(host.node, item.version, { includePrerelease: true })) throw new DeptreeError(`Node ${host.node} is not in ${quote(item.version)}, which pnpm 11 refuses to install with`, here)
199
+ }
200
+ }
201
+ }
202
+
203
+ // `hook` is hook.js's, which each package.json is read through; `host`
204
+ // and `settings` what its engines are held to.
205
+ export function checkProjects(lockfile, manifests, { hook, host, settings }) {
206
+ checkPackageManager(manifests.get('.'), host, settings.pmOnFail)
207
+ for (const [id, manifest] of manifests) {
208
+ const where = `manifests[${quote(id)}]`
209
+ checkProject(manifest, where, { host, settings })
210
+ checkRuntimes(manifest, where, { host, onFail: id === '.' ? settings.runtimeOnFail : undefined })
211
+ const hooked = hook(manifest, where, { dir: id })
212
+ const importer = lockfile.importers[id]
213
+ const reason = mismatch(importer, hooked, settings.autoInstallPeers, host.major, where)
214
+ if (reason !== undefined) throw new DeptreeError(`the lockfile is not up to date with this package.json, which a frozen install refuses: ${reason}`, where)
215
+ checkLinkTargets({ id, manifest: hooked, importer }, where)
216
+ if (host.major < 11) continue
217
+ checkCatalogResolutions(importer, lockfile.catalogs, where)
218
+ checkLinkedPackages({ manifest: hooked, importer, projects: manifests, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
219
+ }
220
+ }
221
+
222
+ // The projects hoisting links by name where hoistWorkspacePackages is on:
223
+ // every one but the root that has a name, by its directory.
224
+ // Two of one name would leave which is hoisted to the order pnpm finds
225
+ // them in, and are refused.
226
+ export function workspaceNames(manifests) {
227
+ const names = new Map()
228
+ const taken = new Set()
229
+ for (const [id, { name }] of manifests) {
230
+ if (id === '.' || !name) continue
231
+ const where = `manifests[${quote(id)}].name`
232
+ if (typeof name !== 'string' || !validForOldPackages(name) || name.split('/').some((part) => part === '.' || part === '..')) {
233
+ throw new DeptreeError(`${quote(String(name))} is not a name a package can be linked by`, where)
234
+ }
235
+ if (taken.has(name)) throw new DeptreeError(`${quote(name)} is the name of another project too`, where)
236
+ taken.add(name)
237
+ names.set(id, name)
238
+ }
239
+ return names
240
+ }
@@ -0,0 +1,270 @@
1
+ // How each setting pnpm reads is read: by its name, as pnpm-workspace.yaml
2
+ // spells it, its kind and what it is held to (READ, READ_11), or passed
3
+ // over as leaving the tree as it is (IGNORED, IGNORED_11); a name that is
4
+ // neither is refused, as is a value read that is not one built for.
5
+
6
+ import { valid } from '@preventive/upstream/semver.js'
7
+ import { DeptreeError, quote } from '../error.js'
8
+ import { REGISTRY } from '../tarball.js'
9
+
10
+ export const readers = {
11
+ boolean(value, where) {
12
+ if (typeof value === 'boolean') return value
13
+ if (value === 'true' || value === 'false') return value === 'true'
14
+ throw new DeptreeError(`expected true or false, found ${show(value)}`, where)
15
+ },
16
+ count(value, where) {
17
+ const number = typeof value === 'string' && /^\d{1,9}$/u.test(value) ? Number(value) : value
18
+ if (Number.isSafeInteger(number) && number > 0) return number
19
+ throw new DeptreeError(`expected a positive integer, found ${show(value)}`, where)
20
+ },
21
+ text(value, where) {
22
+ if (typeof value === 'string') return value
23
+ throw new DeptreeError(`expected a string, found ${show(value)}`, where)
24
+ },
25
+ // A list: a string alone is a list of it, as pnpm reads a hoist pattern.
26
+ texts(value, where) {
27
+ return readers.list(typeof value === 'string' ? [value] : value, where, 'a string or a list of strings')
28
+ },
29
+ // A list, and only a list: pnpm fails on a string alone where it sorts or
30
+ // maps the value.
31
+ list(value, where, expected = 'a list of strings') {
32
+ if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) throw new DeptreeError(`expected ${expected}, found ${show(value)}`, where)
33
+ return [...value]
34
+ },
35
+ // pnpm-workspace.yaml's `packages`, which pnpm holds to a list of
36
+ // non-empty strings.
37
+ globs(value, where) {
38
+ if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || item === '')) throw new DeptreeError(`expected a list of non-empty strings, found ${show(value)}`, where)
39
+ return [...value]
40
+ },
41
+ mapping(value, where) {
42
+ if (value !== null && typeof value === 'object' && !Array.isArray(value)) return value
43
+ throw new DeptreeError(`expected a mapping, found ${show(value)}`, where)
44
+ },
45
+ onFail(value, where) {
46
+ if (ON_FAIL.has(value)) return value
47
+ throw new DeptreeError(`expected one of ${[...ON_FAIL].join(', ')}, found ${show(value)}`, where)
48
+ },
49
+ linkWorkspacePackages(value, where) {
50
+ return value === 'deep' ? true : readers.boolean(value, where)
51
+ },
52
+ // true or false, or what to read and write, and a remote cache, which is
53
+ // refused.
54
+ sideEffectsCache(value, where) {
55
+ if (typeof value === 'boolean') return value
56
+ if (readers.mapping(value, where).remote != null) never('what a build left in a remote cache is not restored here')(value.remote, `${where}.remote`)
57
+ return value
58
+ },
59
+ // By project name, or as a list each with the names it matches: what
60
+ // pnpm 11 takes for a project that pnpm 10 took from its own .npmrc. Of
61
+ // those, where to save and how is all that leaves the tree as it is.
62
+ packageConfigs(value, where) {
63
+ const configs = Array.isArray(value) ? value.map((item, i) => [i, item]) : Object.entries(readers.mapping(value, where))
64
+ for (const [key, config] of configs) {
65
+ const here = `${where}[${quote(String(key))}]`
66
+ for (const field of Object.keys(readers.mapping(config, here))) {
67
+ if (field === 'saveExact' || field === 'savePrefix' || (field === 'match' && Array.isArray(value))) continue
68
+ throw new DeptreeError(`${quote(field)} is not supported: of a project's settings, only saveExact and savePrefix are read`, here)
69
+ }
70
+ }
71
+ return value
72
+ },
73
+ }
74
+
75
+ const ON_FAIL = new Set(['download', 'error', 'warn', 'ignore'])
76
+
77
+ const show = (value) => (typeof value === 'string' ? quote(value) : Array.isArray(value) ? 'a list' : value === null ? 'null' : typeof value === 'object' ? 'a mapping' : String(value))
78
+
79
+ // Read, and held to one value: the default, or the only one built for.
80
+ const only = (kind, wanted, why) => ({ kind, check: (value, where) => {
81
+ if (value !== wanted) throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
82
+ } })
83
+
84
+ // Read, and refused whatever it is.
85
+ const never = (why) => (value, where) => {
86
+ throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
87
+ }
88
+
89
+ export const READ = {
90
+ __proto__: null,
91
+ nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built'),
92
+ symlink: only('boolean', true, 'a tree without its links is not built'),
93
+ enableModulesDir: only('boolean', true, 'a tree without node_modules is not built'),
94
+ modulesDir: only('text', 'node_modules', 'the modules directory is always node_modules'),
95
+ virtualStoreDir: only('text', 'node_modules/.pnpm', 'the virtual store is always node_modules/.pnpm'),
96
+ enableGlobalVirtualStore: only('boolean', false, 'a global virtual store is not built'),
97
+ dedupeDirectDeps: only('boolean', false, 'direct dependencies are linked into every project'),
98
+ injectWorkspacePackages: only('boolean', false, 'workspace packages are linked, never injected'),
99
+ excludeLinksFromLockfile: only('boolean', false, 'links left out of the lockfile would be left out of the tree'),
100
+ sharedWorkspaceLockfile: only('boolean', true, 'one lockfile is read for the whole workspace'),
101
+ lockfile: only('boolean', true, 'the tree is the lockfile\'s'),
102
+ packageLock: only('boolean', true, 'the tree is the lockfile\'s'),
103
+ optional: only('boolean', true, 'optional dependencies are installed'),
104
+ production: only('boolean', false, 'devDependencies are installed'),
105
+ dev: only('boolean', false, 'dependencies are installed'),
106
+ ignorePatchFailures: { ...only('boolean', false, 'a patch that does not apply is an error'), rc: false },
107
+ force: only('boolean', false, 'optional packages the host cannot run are left out'),
108
+ recursiveInstall: only('boolean', true, 'every project is installed'),
109
+ ignoreWorkspace: only('boolean', false, 'the workspace is installed as one'),
110
+ shamefullyFlatten: only('boolean', false, 'its old name is not read for shamefullyHoist'),
111
+ gitBranchLockfile: only('boolean', false, 'the lockfile is the one given'),
112
+ mergeGitBranchLockfiles: only('boolean', false, 'the lockfile is the one given'),
113
+ mergeGitBranchLockfilesBranchPattern: { kind: 'texts', check: never('the lockfile is the one given') },
114
+ lockfileDir: { kind: 'text', check: never('the lockfile is the one given, at the root of the tree') },
115
+ lockfileDirectory: { kind: 'text', check: never('the lockfile is the one given, at the root of the tree') },
116
+ only: { kind: 'text', check: never('dependencies and devDependencies are both installed') },
117
+ filter: { kind: 'texts', check: never('every project is installed') },
118
+ filterProd: { kind: 'texts', check: never('every project is installed') },
119
+ useNodeVersion: { kind: 'text', check: never('the Node a tree is built for is the host\'s, or nodeVersion') },
120
+ globalPnpmfile: { kind: 'text', check: never('a pnpmfile\'s hooks are not run here') },
121
+ registry: { kind: 'text', check: checkRegistry },
122
+ virtualStoreDirMaxLength: { kind: 'count' },
123
+ hoist: { kind: 'boolean' },
124
+ hoistPattern: { kind: 'texts' },
125
+ publicHoistPattern: { kind: 'texts' },
126
+ shamefullyHoist: { kind: 'boolean' },
127
+ hoistWorkspacePackages: { kind: 'boolean' },
128
+ engineStrict: { kind: 'boolean' },
129
+ nodeVersion: { kind: 'text', check: checkNodeVersion },
130
+ autoInstallPeers: { kind: 'boolean' },
131
+ dedupePeers: { kind: 'boolean' },
132
+ peersSuffixMaxLength: { kind: 'count' },
133
+ // Neither pnpm's .npmrc nor ours has these.
134
+ supportedArchitectures: { kind: 'mapping', check: checkArchitectures, rc: false },
135
+ patchedDependencies: { kind: 'mapping', check: checkPatches, rc: false },
136
+ overrides: { kind: 'mapping', rc: false },
137
+ catalog: { kind: 'mapping', check: checkCatalog, rc: false },
138
+ catalogs: { kind: 'mapping', check: checkCatalogs, rc: false },
139
+ packageExtensions: { kind: 'mapping', rc: false },
140
+ ignoredOptionalDependencies: { kind: 'list', rc: false },
141
+ packages: { kind: 'globs', rc: false },
142
+ }
143
+
144
+ // What pnpm 11 reads that pnpm 10 has not, or reads otherwise.
145
+ const READ_11 = {
146
+ __proto__: null,
147
+ virtualStoreType: only('text', 'project', 'a global virtual store is not built'),
148
+ virtualStoreOnly: only('boolean', false, 'a tree without its projects\' links is not built'),
149
+ nodeExperimentalPackageMap: only('boolean', false, 'node_modules/.package-map.json is not written'),
150
+ registries: { kind: 'mapping', check: checkRegistries },
151
+ namedRegistries: { kind: 'mapping', check: (value, where) => Object.keys(value).length === 0 || never('packages are fetched from the public registry alone')(value, where) },
152
+ remoteSideEffectsCache: { kind: 'mapping', check: never('what a build left in a remote cache is not restored here') },
153
+ sideEffectsCache: { kind: 'sideEffectsCache' },
154
+ packageConfigs: { kind: 'packageConfigs' },
155
+ pmOnFail: { kind: 'onFail' },
156
+ runtimeOnFail: { kind: 'onFail' },
157
+ linkWorkspacePackages: { kind: 'linkWorkspacePackages' },
158
+ }
159
+
160
+ // What pnpm 11 has that leaves the tree as it is. The tree follows the
161
+ // lockfile, as pnpm 11's does with trustLockfile: minimumReleaseAge and the
162
+ // rest of what pnpm 11 checks the lockfile against the registry by before
163
+ // it installs — each package's publish time, its tarball URL, its trust —
164
+ // are passed over.
165
+ const IGNORED_11 = new Set([
166
+ 'minimumReleaseAgeIgnoreMissingTime', 'minimumReleaseAgeStrict', 'minimumReleaseAgeExcludePrune', 'trustLockfile',
167
+ 'trustPolicy', 'trustPolicyExclude', 'trustPolicyExcludePrune', 'trustPolicyIgnoreAfter', 'pnprServer',
168
+ 'fetchMinSpeedKiBps', 'fetchWarnTimeoutMs', 'fetchingConcurrency', 'gitShallowHosts', 'npmrcAuthFile', 'nodeDownloadMirrors',
169
+ 'frozenStore', 'globalVirtualStoreDir', 'dlxCacheMaxAge', 'optimisticRepeatInstall', 'forceIgnoresPlatform',
170
+ 'audit', 'auditLevel', 'update', 'tasks', 'versioning', 'patchesDir', 'syncInjectedDepsAfterScripts', 'nodePackageMapType',
171
+ // a patch that does not apply is always an error in pnpm 11
172
+ 'ignorePatchFailures',
173
+ // passed over in a project's pnpm-workspace.yaml
174
+ 'configDir', 'globalBinDir', 'globalDir', 'globalPkgDir', 'pnpmHomeDir', 'stateDir', 'userconfig', 'bin', 'dir',
175
+ 'rootProjectManifestDir', 'workspaceDir', 'authConfig', 'userConfig', 'configByUri', 'packageManagerNetworkConfig',
176
+ 'packageManagerRegistries', 'scope', 'hooks', 'finders', 'allProjects', 'selectedProjectsGraph', 'allProjectsGraph',
177
+ 'prodAllProjectsGraph', 'prodOnlySelectedProjectDirs', 'rootProjectManifest', 'enginePinManifest',
178
+ 'nodeVersionFromEnginesRuntime', 'cliOptions', 'explicitlySetKeys', 'packageManager', 'wantedPackageManager',
179
+ ])
180
+
181
+ // The keys of the root package.json's `pnpm` field pnpm 10 reads; it
182
+ // passes over any other there.
183
+ export const MANIFEST_KEYS = [
184
+ 'allowBuilds', 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'auditConfig',
185
+ 'configDependencies', 'executionEnv', 'ignorePatchFailures', 'ignoredBuiltDependencies', 'ignoredOptionalDependencies',
186
+ 'neverBuiltDependencies', 'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'overrides', 'packageExtensions',
187
+ 'patchedDependencies', 'peerDependencyRules', 'requiredScripts', 'supportedArchitectures', 'updateConfig',
188
+ ]
189
+
190
+ // Settings that leave the tree as it is. Resolution is done: the lockfile
191
+ // is what these made of the manifests, and a frozen install holds it to
192
+ // none of them (uptodate.js has those it does). Fetching goes to the public
193
+ // registry alone, through @preventive/upstream, so the network and its
194
+ // credentials are its own; the store, caches and state live outside
195
+ // node_modules; bins are never written here, and scripts never run, as
196
+ // with --ignore-scripts, whatever a setting would allow to build.
197
+ export const IGNORED = new Set([
198
+ // resolution, already in the lockfile
199
+ 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
200
+ 'dedupeInjectedDeps', 'dedupePeerDependents', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
201
+ 'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
202
+ 'registrySupportsTimeField', 'resolutionMode', 'resolvePeersFromWorkspaceRoot', 'saveExact', 'savePrefix',
203
+ 'saveWorkspaceProtocol', 'strictPeerDependencies',
204
+ // the network, and credentials for it
205
+ 'alwaysAuth', 'ca', 'cafile', 'cert', 'email', 'fetchRetries', 'fetchRetryFactor', 'fetchRetryMaxtimeout',
206
+ 'fetchRetryMintimeout', 'fetchTimeout', 'httpProxy', 'httpsProxy', 'key', 'localAddress', 'maxsockets',
207
+ 'networkConcurrency', 'noProxy', 'noproxy', 'offline', 'preferOffline', 'proxy', 'strictSsl', 'userAgent',
208
+ // the store, caches and state, none of it in node_modules
209
+ 'cacheDir', 'modulesCacheMaxAge', 'packageImportMethod', 'sideEffectsCache', 'sideEffectsCacheReadonly',
210
+ 'stateDir', 'storeDir', 'strictStorePkgContentCheck', 'verifyStoreIntegrity',
211
+ // scripts, which are not run, and bins, which are not written
212
+ 'allowBuilds', 'childConcurrency', 'dangerouslyAllowAllBuilds', 'enablePrePostScripts', 'extendNodePath',
213
+ 'ignoreDepScripts', 'ignoreScripts', 'ignoredBuiltDependencies', 'neverBuiltDependencies', 'nodeOptions',
214
+ 'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'preferSymlinkedExecutables', 'scriptShell',
215
+ 'shellEmulator', 'strictDepBuilds', 'unsafePerm', 'verifyDepsBeforeRun',
216
+ // how the command runs, and what other commands read
217
+ 'auditConfig', 'bail', 'ci', 'color', 'executionEnv', 'ignoreWorkspaceRootCheck', 'loglevel',
218
+ 'reporter', 'requiredScripts', 'updateConfig', 'updateNotifier', 'useBetaCli', 'workspaceConcurrency',
219
+ // an install here is always frozen, whatever these say
220
+ 'frozenLockfile', 'preferFrozenLockfile',
221
+ // the root package.json's packageManager is always held to be host.pnpm
222
+ 'managePackageManagerVersions', 'packageManagerStrict', 'packageManagerStrictVersion',
223
+ ])
224
+
225
+ export function checkRegistry(value, where) {
226
+ if ((value.endsWith('/') ? value : `${value}/`) !== REGISTRY) throw new DeptreeError(`${quote(value)} is not supported: packages are fetched from ${REGISTRY} alone`, where)
227
+ }
228
+
229
+ // pnpm 11's registries: by scope, or `default`, the registry's URL.
230
+ function checkRegistries(value, where) {
231
+ for (const [scope, url] of Object.entries(value)) checkRegistry(readers.text(url, `${where}.${scope}`), `${where}.${scope}`)
232
+ }
233
+
234
+ function checkNodeVersion(value, where) {
235
+ if (valid(value) === null) throw new DeptreeError(`${quote(value)} is not an exact version`, where)
236
+ }
237
+
238
+ const ARCHITECTURES = new Set(['os', 'cpu', 'libc'])
239
+ function checkArchitectures(value, where) {
240
+ for (const [key, list] of Object.entries(value)) {
241
+ if (!ARCHITECTURES.has(key)) throw new DeptreeError(`unsupported key ${quote(key)}`, where)
242
+ readers.list(list, `${where}.${key}`)
243
+ }
244
+ }
245
+
246
+ // A catalog: by name, the specifier it gives the package.
247
+ function checkCatalog(value, where) {
248
+ for (const [name, spec] of Object.entries(value)) readers.text(spec, `${where}.${name}`)
249
+ }
250
+
251
+ function checkCatalogs(value, where) {
252
+ for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
253
+ }
254
+
255
+ // What reads a setting for pnpm of `major`, or undefined for one that
256
+ // leaves the tree as it is; one that is neither is refused.
257
+ export function readerOf(name, where, major) {
258
+ if (major >= 11 && name in READ_11) return READ_11[name]
259
+ if (IGNORED.has(name) || (major >= 11 && IGNORED_11.has(name))) return undefined
260
+ if (!(name in READ)) throw new DeptreeError('unsupported setting', where)
261
+ return READ[name]
262
+ }
263
+
264
+ // By selector, the patch file, relative to the workspace's directory.
265
+ function checkPatches(value, where) {
266
+ for (const [selector, path] of Object.entries(value)) {
267
+ const here = `${where}[${quote(selector)}]`
268
+ if (readers.text(path, here).startsWith('/')) throw new DeptreeError('an absolute patch path is not supported', here)
269
+ }
270
+ }