@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.
Files changed (79) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/npm.d.ts +288 -0
  3. package/npm.js +7 -0
  4. package/package.json +41 -12
  5. package/pnpm.d.ts +158 -25
  6. package/pnpm.js +2 -10
  7. package/soldeer.d.ts +13 -0
  8. package/soldeer.js +1 -7
  9. package/src/concurrent.js +16 -17
  10. package/src/error.js +5 -9
  11. package/src/glob.js +55 -0
  12. package/src/hash.js +60 -13
  13. package/src/manifest.js +52 -0
  14. package/src/matcher.js +60 -10
  15. package/src/mount.js +104 -44
  16. package/src/npm/bins.js +54 -0
  17. package/src/npm/compat.js +97 -0
  18. package/src/npm/dev-engines.js +52 -0
  19. package/src/npm/graph.js +68 -0
  20. package/src/npm/inputs.js +75 -0
  21. package/src/npm/manifests.js +130 -0
  22. package/src/npm/package.js +57 -0
  23. package/src/npm/ratio.js +34 -0
  24. package/src/npm/settings.js +67 -0
  25. package/src/npm/tree.js +136 -0
  26. package/src/npm/versions.js +20 -0
  27. package/src/npmrc.js +24 -0
  28. package/src/patch.js +22 -41
  29. package/src/pnpm/bins.js +152 -131
  30. package/src/pnpm/checks.js +8 -35
  31. package/src/pnpm/commands.js +53 -96
  32. package/src/pnpm/filename.js +10 -21
  33. package/src/pnpm/frozen.js +29 -75
  34. package/src/pnpm/gitignore.js +139 -0
  35. package/src/pnpm/glob.js +65 -0
  36. package/src/pnpm/graph.js +15 -43
  37. package/src/pnpm/hoist.js +68 -61
  38. package/src/pnpm/hoisted.js +234 -0
  39. package/src/pnpm/hook.js +26 -31
  40. package/src/pnpm/inputs.js +73 -56
  41. package/src/pnpm/install.js +85 -131
  42. package/src/pnpm/local.js +21 -40
  43. package/src/pnpm/minimatch.js +319 -0
  44. package/src/pnpm/nm-hoist-graph.js +299 -0
  45. package/src/pnpm/nm-hoist.js +149 -0
  46. package/src/pnpm/npm-packlist.js +217 -0
  47. package/src/pnpm/overrides.js +11 -51
  48. package/src/pnpm/package.js +121 -0
  49. package/src/pnpm/packlist.js +169 -109
  50. package/src/pnpm/patches.js +18 -25
  51. package/src/pnpm/projects.js +63 -107
  52. package/src/pnpm/readers.js +63 -83
  53. package/src/pnpm/settings.js +64 -100
  54. package/src/pnpm/tree.js +197 -169
  55. package/src/pnpm/uptodate.js +16 -28
  56. package/src/pnpm/workspace.js +124 -133
  57. package/src/project.js +57 -0
  58. package/src/soldeer/config.js +8 -24
  59. package/src/soldeer/inputs.js +5 -15
  60. package/src/soldeer/tree.js +22 -60
  61. package/src/soldeer/zip.js +17 -36
  62. package/src/tarball.js +55 -140
  63. package/src/yarn1/bins.js +9 -19
  64. package/src/yarn1/compat.js +9 -28
  65. package/src/yarn1/hoist.js +53 -68
  66. package/src/yarn1/inputs.js +19 -61
  67. package/src/yarn1/manifest.js +8 -23
  68. package/src/yarn1/package.js +24 -63
  69. package/src/yarn1/peers.js +8 -15
  70. package/src/yarn1/requests.js +19 -37
  71. package/src/yarn1/resolve.js +36 -113
  72. package/src/yarn1/settings.js +15 -43
  73. package/src/yarn1/tree.js +67 -91
  74. package/yarn1.d.ts +34 -5
  75. package/yarn1.js +1 -8
  76. package/src/pnpm/npmrc.js +0 -31
  77. package/src/pnpm/project.js +0 -97
  78. package/src/yarn1/glob.js +0 -52
  79. /package/{LICENSE → LICENSE-MIT} +0 -0
@@ -1,60 +1,19 @@
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 importer has to be a project: the projects pnpm finds are what it
7
- // installs, and an importer none of them is would be left out. A project
8
- // the lockfile has no importer for pnpm gives an empty one, which it is
9
- // then held to: one with dependencies is refused as not up to date.
10
- //
11
- // A project's specifiers are its dependencies, devDependencies and
12
- // optionalDependencies, and, with autoInstallPeers, the peerDependencies
13
- // it does not also list otherwise, which pnpm installs as dependencies;
14
- // each has to be what the importer records, under the kind pnpm files it
15
- // under, and a version the importer resolved has to be in its range. Its
16
- // publishConfig.directory and dependenciesMeta have to be the importer's.
17
- //
18
- // Each package.json is read as pnpm reads it before that: through its
19
- // read-package hook (hook.js), so a direct dependency overridden or an
20
- // optional one ignored is held to the importer as overridden or left out;
21
- // and held to the host by its engines (install.js's checkProject). The
22
- // root one's packageManager, where it names one, has to be the pnpm the
23
- // tree is built for: pnpm 10 would run that one instead.
24
- //
25
- // pnpm 11 lets an optional dependency the importer has no specifier for
26
- // go unresolved, takes git specifiers of one commit to be the same however
27
- // spelled, holds publishConfig.linkDirectory to the importer too, and
28
- // makes frozen.js's further checks.
29
- //
30
- // Installs are frozen, always: pnpm 10's further checks without
31
- // --frozen-lockfile, that workspace packages are linked exactly where
32
- // their version is in range, are not made; pnpm 11 makes them frozen too.
1
+ // Each project's package.json, read through its read-package hook (hook.js),
2
+ // held to its importer as a frozen install holds it
3
+ // (@pnpm/lockfile.verification's satisfiesPackageManifest). Every importer
4
+ // has to be a project, or pnpm would leave it out. The check pnpm 10 makes
5
+ // only when not frozen, that workspace packages are linked exactly where
6
+ // their version is in range, is not made.
33
7
 
34
8
  import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
35
9
  import { DeptreeError, difference, quote } from '../error.js'
10
+ import { own, readManifest } from '../manifest.js'
36
11
  import { createMatcher } from '../matcher.js'
37
12
  import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
38
13
  import { checkProject } from './install.js'
39
14
  import { validForOldPackages } from './overrides.js'
40
15
  import { checkProjectId } from './workspace.js'
41
16
 
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
17
  export function readManifests(manifests, lockfile) {
59
18
  if (manifests === null || typeof manifests !== 'object') throw new TypeError('manifests must map each project\'s directory to its package.json')
60
19
  const read = new Map()
@@ -62,7 +21,6 @@ export function readManifests(manifests, lockfile) {
62
21
  const where = `manifests[${quote(id)}]`
63
22
  if (!(id in lockfile.importers)) {
64
23
  checkProjectId(id, where)
65
- // `made`, as the lockfile has no importer for the project.
66
24
  lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true, made: true }
67
25
  }
68
26
  read.set(id, readManifest(text, where))
@@ -75,10 +33,7 @@ export function readManifests(manifests, lockfile) {
75
33
 
76
34
  const omit = (deps, names) => Object.fromEntries(Object.entries(deps).filter(([name]) => !names.has(name)))
77
35
 
78
- // The dependencies pnpm reads a project as asking for: with
79
- // autoInstallPeers, a peer it does not list elsewhere is a dependency; and
80
- // those `unresolved` left out. The hook has held each of these fields to a
81
- // mapping of strings.
36
+ // The hook has held each of these fields to a mapping of strings.
82
37
  function wantedOf(manifest, autoInstallPeers, unresolved) {
83
38
  const kinds = Object.fromEntries(KINDS.map((kind) => [kind, manifest[kind] ?? {}]))
84
39
  let all = omit({ ...kinds.devDependencies, ...kinds.dependencies, ...kinds.optionalDependencies }, unresolved)
@@ -91,33 +46,32 @@ function wantedOf(manifest, autoInstallPeers, unresolved) {
91
46
  return { kinds, all }
92
47
  }
93
48
 
94
- // dependenciesMeta as the lockfile reader hands it back: `injected` false
95
- // where it is not set.
49
+ // As the lockfile reader hands dependenciesMeta back: `injected` false where
50
+ // it is not set.
96
51
  const metaOf = (meta) => JSON.stringify(Object.entries(meta).map(([name, item]) => [name, item?.injected === true, item?.node]).sort())
97
52
 
53
+ // pnpm 9 does not hold what a dependency resolved to to its range.
98
54
  function checkKind(importer, kinds, kind, unresolved, major) {
99
55
  const locked = importer[kind]
100
56
  const wanted = kind === 'devDependencies' ? kinds[kind] : omit(kinds[kind], unresolved)
101
57
  const names = Object.keys(wanted).filter((name) => kind === 'optionalDependencies'
102
- || (!kinds.optionalDependencies[name] && (kind === 'dependencies' || !kinds.dependencies[name])))
58
+ || (!own(kinds.optionalDependencies, name) && (kind === 'dependencies' || !own(kinds.dependencies, name))))
103
59
  const unlinked = Object.values(locked).filter((target) => !target.includes('link:') && !target.includes('file:')).length
104
60
  if (names.length !== Object.keys(locked).length && names.length !== unlinked) return `${kind} in the lockfile do not match the same field in package.json`
105
61
  for (const name of names) {
106
62
  if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
107
63
  const spec = importer.specifiers[name]
108
- if (validRange(spec) === null) continue
64
+ if (major < 10 || validRange(spec) === null) continue
109
65
  const version = resolvedOf(name, locked[name])
110
66
  if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
111
67
  }
112
68
  return undefined
113
69
  }
114
70
 
115
- // Why pnpm would find `importer` not to be what `manifest` asks for, or
116
- // undefined where it is; of the specifiers, the first difference, as
117
- // pnpm's diffFlatRecords finds.
71
+ // Why pnpm finds `importer` out of date: of the specifiers, the first
72
+ // difference, as pnpm's diffFlatRecords finds.
118
73
  function mismatch(importer, manifest, autoInstallPeers, major, where) {
119
- const optional = manifest.optionalDependencies ?? {}
120
- const unresolved = new Set(major >= 11 ? Object.keys(optional).filter((name) => importer.specifiers[name] === undefined) : [])
74
+ const unresolved = new Set(major >= 11 ? Object.keys(manifest.optionalDependencies ?? {}).filter((name) => importer.specifiers[name] === undefined) : [])
121
75
  const { kinds, all } = wantedOf(manifest, autoInstallPeers, unresolved)
122
76
  const specified = difference(importer.specifiers, all, ['the lockfile', 'package.json'], (a, b) => sameSpecifier(a, b, major))
123
77
  if (specified !== undefined) return `the specifiers differ: ${specified}`
@@ -135,8 +89,7 @@ function mismatch(importer, manifest, autoInstallPeers, major, where) {
135
89
  return undefined
136
90
  }
137
91
 
138
- // devEngines.packageManager as pnpm 11 reads it: the pnpm one of a list,
139
- // else its first, and what to do where it does not match.
92
+ // devEngines.packageManager as pnpm 11 reads it.
140
93
  function devEnginesPackageManager(devEngines, where) {
141
94
  const engines = devEngines?.packageManager
142
95
  if (!engines) return undefined
@@ -152,21 +105,16 @@ function devEnginesPackageManager(devEngines, where) {
152
105
  return { name: engine.name, onFail }
153
106
  }
154
107
 
155
- // The version of pnpm packageManager names, as pnpm's parsePackageManager
156
- // reads it, where it names pnpm at an exact version.
108
+ // The exact pnpm version packageManager names, per pnpm's parsePackageManager.
157
109
  export function pinnedPnpm(packageManager) {
158
110
  const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
159
111
  return isExactVersion(version) ? version : undefined
160
112
  }
161
113
 
162
- // The package manager the root package.json pins as pnpm 12 reads it
163
- // (wanted_package_manager): devEngines.packageManager over packageManager,
164
- // the pnpm one of a list, else its first, whose own onFail it takes, else
165
- // `error` for the last of a list and `ignore` for another; a version that
166
- // is not a range is none, and packageManager's has to be exact.
114
+ // The root's pin, as pnpm 12's wanted_package_manager reads it.
167
115
  function wantedPackageManager(manifest) {
168
116
  const declared = manifest.devEngines?.packageManager
169
- const list = Array.isArray(declared) ? declared : declared === undefined || declared === null ? [] : [declared]
117
+ const list = Array.isArray(declared) ? declared : declared == null ? [] : [declared]
170
118
  const index = Array.isArray(declared) ? Math.max(list.findIndex((entry) => entry?.name === 'pnpm'), 0) : 0
171
119
  const entry = list[index]
172
120
  if (typeof entry?.name === 'string') {
@@ -187,14 +135,9 @@ export function pinsPnpm(manifest, pnpm) {
187
135
  return wanted?.name === 'pnpm' && wanted.version !== undefined && satisfies(pnpm, wanted.version, { includePrerelease: true })
188
136
  }
189
137
 
190
- // pnpm 12 runs, of a pin that is not to be ignored, the pnpm the lockfile's
191
- // env document records for it; it records a devEngines one, or a
192
- // packageManager one of 12 or later, and a frozen install fails where it
193
- // has none: there has to be one, of `pnpm` alone at the pinned version, or
194
- // at the running one for a range it is in, and its package. The pnpm that
195
- // runs has to be in the pin, which it would be switched from or refused
196
- // by, unless it is only to warn. Another package manager fails it unless
197
- // it is only to warn.
138
+ // pnpm 12 runs the pnpm the lockfile's env document records for a pin. It
139
+ // records one for a devEngines pin, or a packageManager one of 12 or later,
140
+ // at the pinned version or, for a range, the running one.
198
141
  function checkPackageManager12(manifest, host, pmOnFail, env) {
199
142
  const wanted = wantedPackageManager(manifest)
200
143
  if (wanted === undefined) return
@@ -217,14 +160,37 @@ function checkPackageManager12(manifest, host, pmOnFail, env) {
217
160
  }
218
161
  }
219
162
 
220
- // packageManager as pnpm's parsePackageManager reads it, held to be this
221
- // pnpm, exactly: pnpm switches to the version it names, and one it cannot
222
- // switch to, or another package manager, is refused rather than run over.
223
- // pnpm 11 reads devEngines.packageManager over it, and switches to the
224
- // pnpm the lockfile pins for that, which is refused; either is passed
225
- // over where what to do on a mismatch, or pmOnFail, is to warn or ignore.
226
- // pnpm 12's are checkPackageManager12's.
227
- function checkPackageManager(manifest, host, pmOnFail, env) {
163
+ // pnpm 9's parsePackageManager.
164
+ function parsePackageManager(packageManager) {
165
+ if (!packageManager.includes('@')) return { name: packageManager, version: undefined }
166
+ const [name, reference] = packageManager.split('@')
167
+ return { name, version: reference.includes(':') ? undefined : reference.split('+')[0] }
168
+ }
169
+
170
+ // pnpm 9 switches to the pnpm packageManager pins only with
171
+ // managePackageManagerVersions; otherwise it refuses another package
172
+ // manager with packageManagerStrict, and another pnpm with that and
173
+ // packageManagerStrictVersion, and installs with itself. 9.15.0 switches
174
+ // to a version semver reads but spells otherwise, and later 9.15s do not.
175
+ function checkPackageManager9(manifest, host, { manage, strict, strictVersion }) {
176
+ const { packageManager } = manifest
177
+ if (!packageManager) return
178
+ const where = 'manifests["."].packageManager'
179
+ if (typeof packageManager !== 'string') throw new DeptreeError('expected a string, which pnpm 9 fails on otherwise', where)
180
+ const { name, version } = parsePackageManager(packageManager)
181
+ if (manage && name === 'pnpm') {
182
+ const exact = version === undefined ? null : valid(version)
183
+ if (version === undefined || version === host.pnpm || exact === null) return
184
+ if (exact !== version.trim()) throw new DeptreeError(`pnpm ${quote(version)} is one pnpm 9.15.0 switches to and a later 9.15 does not, which is not supported`, where)
185
+ throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm 9 switches to with managePackageManagerVersions, not ${host.pnpm}`, where)
186
+ }
187
+ if (name && name !== 'pnpm' && strict) throw new DeptreeError(`the project is installed by ${quote(name)}, which pnpm 9 refuses with packageManagerStrict`, where)
188
+ if (name === 'pnpm' && strict && strictVersion && version && version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, not ${host.pnpm}, which pnpm 9 refuses with packageManagerStrict and packageManagerStrictVersion`, where)
189
+ }
190
+
191
+ function checkPackageManager(manifest, host, settings, env) {
192
+ const { pmOnFail } = settings
193
+ if (host.major < 10) return checkPackageManager9(manifest, host, settings.packageManagerChecks)
228
194
  if (host.major >= 12) return checkPackageManager12(manifest, host, pmOnFail, env)
229
195
  const { packageManager } = manifest
230
196
  if (host.major >= 11) {
@@ -241,17 +207,17 @@ function checkPackageManager(manifest, host, pmOnFail, env) {
241
207
  if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
242
208
  }
243
209
 
244
- // A runtime pnpm would download and install as a dependency, which is
245
- // refused as the lockfile reader refuses a `runtime:` one. For the root
246
- // project, pnpm 11 takes runtimeOnFail for each one's onFail, and checks a
247
- // runtime whose onFail is `error` against the host's before it installs.
210
+ // A runtime pnpm would download as a dependency is refused, as the lockfile
211
+ // reader refuses a `runtime:` one.
248
212
  const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
249
213
  const RUNTIME_NAMES = ['node', 'deno', 'bun']
250
214
  function checkRuntimes(manifest, where, { host, root, onFail }) {
215
+ // pnpm 9 knows no runtime.
216
+ if (host.major < 10) return
251
217
  const checked = new Set()
252
218
  for (const [field, kind] of RUNTIMES) {
253
219
  const runtime = manifest[field]?.runtime
254
- if (runtime === undefined || runtime === null) continue
220
+ if (runtime == null) continue
255
221
  const here = `${where}.${field}.runtime`
256
222
  const runtimes = Array.isArray(runtime) ? runtime : [runtime]
257
223
  for (const name of RUNTIME_NAMES) {
@@ -272,23 +238,15 @@ function checkRuntimes(manifest, where, { host, root, onFail }) {
272
238
  }
273
239
  }
274
240
 
275
- // Whether pnpm 12 takes a project to have dependencies, where the lockfile
276
- // has no importer for it: any of its devDependencies, or of its
277
- // dependencies and optionalDependencies, but optional ones it ignores, as
278
- // its package.json has them; its peers are none.
241
+ // pnpm 12 counts no ignored optional dependency, nor any peer.
279
242
  function dependsOn(manifest, ignored) {
280
243
  const names = (deps) => (deps !== null && typeof deps === 'object' ? Object.keys(deps) : [])
281
244
  const optional = new Set(names(manifest.optionalDependencies).filter((name) => ignored(name)))
282
245
  return names(manifest.devDependencies).length > 0 || [...names(manifest.dependencies), ...names(manifest.optionalDependencies)].some((name) => !optional.has(name))
283
246
  }
284
247
 
285
- // `hook` is hook.js's, which each package.json is read through; `host`
286
- // and `settings` what its engines are held to; `env` the lockfile's env
287
- // document, where it has one. pnpm 12 holds a project the lockfile has no
288
- // importer for to none, if it has no dependencies, and refuses it
289
- // otherwise; and makes none of pnpm 11's further checks.
290
248
  export function checkProjects(lockfile, manifests, { hook, host, settings, env }) {
291
- checkPackageManager(manifests.get('.'), host, settings.pmOnFail, env)
249
+ checkPackageManager(manifests.get('.'), host, settings, env)
292
250
  const ignored = createMatcher(settings.ignoredOptionalDependencies ?? [])
293
251
  let index
294
252
  for (const [id, manifest] of manifests) {
@@ -312,10 +270,8 @@ export function checkProjects(lockfile, manifests, { hook, host, settings, env }
312
270
  }
313
271
  }
314
272
 
315
- // The projects hoisting links by name where hoistWorkspacePackages is on:
316
- // every one but the root that has a name, by its directory.
317
- // Two of one name would leave which is hoisted to the order pnpm finds
318
- // them in, and are refused.
273
+ // The names hoistWorkspacePackages links projects by. Two of one name are
274
+ // refused, as which is hoisted would turn on the order pnpm finds them in.
319
275
  export function workspaceNames(manifests) {
320
276
  const names = new Map()
321
277
  const taken = new Set()
@@ -1,7 +1,7 @@
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.
1
+ // Each setting pnpm reads, by its pnpm-workspace.yaml name, is either read
2
+ // and checked (READ, READ_9, READ_11, READ_12) or passed over as leaving
3
+ // the tree as it is (IGNORED, NOT_9, IGNORED_11, IGNORED_12); any other is
4
+ // refused.
5
5
 
6
6
  import { valid } from '@preventive/upstream/semver.js'
7
7
  import { DeptreeError, quote } from '../error.js'
@@ -12,62 +12,42 @@ const IMPORT_METHODS = new Set(['auto', 'hardlink', 'copy', 'clone', 'clone-or-c
12
12
 
13
13
  const show = (value) => (typeof value === 'string' ? quote(value) : Array.isArray(value) ? 'a list' : value === null ? 'null' : typeof value === 'object' ? 'a mapping' : String(value))
14
14
 
15
- // A reader of one of the values of `allowed`.
16
- const oneOf = (allowed) => (value, where) => {
17
- if (allowed.has(value)) return value
18
- throw new DeptreeError(`expected one of ${[...allowed].join(', ')}, found ${show(value)}`, where)
15
+ // `read` where `ok`, or else `value` refused as not `what`.
16
+ function checked(ok, value, what, where, read = value) {
17
+ if (ok) return read
18
+ throw new DeptreeError(`expected ${what}, found ${show(value)}`, where)
19
19
  }
20
20
 
21
+ const oneOf = (allowed) => (value, where) => checked(allowed.has(value), value, `one of ${[...allowed].join(', ')}`, where)
22
+
21
23
  export const readers = {
22
24
  boolean(value, where) {
23
- if (typeof value === 'boolean') return value
24
- if (value === 'true' || value === 'false') return value === 'true'
25
- throw new DeptreeError(`expected true or false, found ${show(value)}`, where)
25
+ return value === 'true' || value === 'false' ? value === 'true' : checked(typeof value === 'boolean', value, 'true or false', where)
26
26
  },
27
27
  count(value, where) {
28
28
  const number = typeof value === 'string' && /^\d{1,9}$/u.test(value) ? Number(value) : value
29
- if (Number.isSafeInteger(number) && number > 0) return number
30
- throw new DeptreeError(`expected a positive integer, found ${show(value)}`, where)
29
+ return checked(Number.isSafeInteger(number) && number > 0, value, 'a positive integer', where, number)
31
30
  },
32
- text(value, where) {
33
- if (typeof value === 'string') return value
34
- throw new DeptreeError(`expected a string, found ${show(value)}`, where)
35
- },
36
- // A list: a string alone is a list of it, as pnpm reads a hoist pattern.
31
+ text: (value, where) => checked(typeof value === 'string', value, 'a string', where),
32
+ // A string alone is a list of it, as pnpm reads a hoist pattern.
37
33
  texts(value, where) {
38
34
  return readers.list(typeof value === 'string' ? [value] : value, where, 'a string or a list of strings')
39
35
  },
40
- // A list, and only a list: pnpm fails on a string alone where it sorts or
41
- // maps the value.
42
- list(value, where, expected = 'a list of strings') {
43
- if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) throw new DeptreeError(`expected ${expected}, found ${show(value)}`, where)
44
- return [...value]
45
- },
46
- // pnpm-workspace.yaml's `packages`, which pnpm holds to a list of
47
- // non-empty strings.
48
- globs(value, where) {
49
- 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)
50
- return [...value]
51
- },
52
- mapping(value, where) {
53
- if (value !== null && typeof value === 'object' && !Array.isArray(value)) return value
54
- throw new DeptreeError(`expected a mapping, found ${show(value)}`, where)
55
- },
36
+ // Only a list: pnpm fails on a string alone where it sorts or maps it.
37
+ list: (value, where, expected = 'a list of strings') => [...checked(Array.isArray(value) && value.every((item) => typeof item === 'string'), value, expected, where)],
38
+ globs: (value, where) => [...checked(Array.isArray(value) && value.every((item) => typeof item === 'string' && item !== ''), value, 'a list of non-empty strings', where)],
39
+ mapping: (value, where) => checked(value !== null && typeof value === 'object' && !Array.isArray(value), value, 'a mapping', where),
56
40
  importMethod: oneOf(IMPORT_METHODS),
57
41
  onFail: oneOf(ON_FAIL),
58
42
  linkWorkspacePackages(value, where) {
59
43
  return value === 'deep' ? true : readers.boolean(value, where)
60
44
  },
61
- // true or false, or what to read and write, and a remote cache, which is
62
- // refused.
63
45
  sideEffectsCache(value, where) {
64
46
  if (typeof value === 'boolean') return value
65
47
  if (readers.mapping(value, where).remote != null) never('what a build left in a remote cache is not restored here')(value.remote, `${where}.remote`)
66
48
  return value
67
49
  },
68
- // By project name, or as a list each with the names it matches: what
69
- // pnpm 11 takes for a project that pnpm 10 took from its own .npmrc. Of
70
- // those, where to save and how is all that leaves the tree as it is.
50
+ // pnpm 11's per-project settings: by project name, or a list with `match`.
71
51
  packageConfigs(value, where) {
72
52
  const configs = Array.isArray(value) ? value.map((item, i) => [i, item]) : Object.entries(readers.mapping(value, where))
73
53
  for (const [key, config] of configs) {
@@ -81,19 +61,16 @@ export const readers = {
81
61
  },
82
62
  }
83
63
 
84
- // Read, and held to one value: the default, or the only one built for.
85
- const only = (kind, wanted, why) => ({ kind, check: (value, where) => {
86
- if (value !== wanted) throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
87
- } })
64
+ const only = (kind, wanted, why) => ({ kind, check: (value, where) => value === wanted || never(why)(value, where) })
88
65
 
89
- // Read, and refused whatever it is.
90
66
  const never = (why) => (value, where) => {
91
67
  throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
92
68
  }
93
69
 
94
70
  export const READ = {
95
71
  __proto__: null,
96
- nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built'),
72
+ // pnpm 10's hoisted layout too (hoisted.js).
73
+ nodeLinker: { kind: 'text', check: (value, where) => value === 'hoisted' || value === 'isolated' || never('only the isolated and hoisted node_modules layouts are built')(value, where) },
97
74
  symlink: only('boolean', true, 'a tree without its links is not built'),
98
75
  enableModulesDir: only('boolean', true, 'a tree without node_modules is not built'),
99
76
  modulesDir: only('text', 'node_modules', 'the modules directory is always node_modules'),
@@ -135,8 +112,7 @@ export const READ = {
135
112
  autoInstallPeers: { kind: 'boolean' },
136
113
  dedupePeers: { kind: 'boolean' },
137
114
  peersSuffixMaxLength: { kind: 'count' },
138
- // Whether a package installed from a directory has the files of each of
139
- // its snapshots as one, hardlinked, or each as its own (tree.js).
115
+ // Whether a directory package's snapshots share hardlinked files (tree.js).
140
116
  packageImportMethod: { kind: 'importMethod' },
141
117
  // Neither pnpm's .npmrc nor ours has these.
142
118
  supportedArchitectures: { kind: 'mapping', check: checkArchitectures, rc: false },
@@ -165,11 +141,8 @@ const READ_11 = {
165
141
  linkWorkspacePackages: { kind: 'linkWorkspacePackages' },
166
142
  }
167
143
 
168
- // What pnpm 11 has that leaves the tree as it is. The tree follows the
169
- // lockfile, as pnpm 11's and 12's do with trustLockfile: minimumReleaseAge and the
170
- // rest of what pnpm 11 checks the lockfile against the registry by before
171
- // it installs — each package's publish time, its tarball URL, its trust —
172
- // are passed over.
144
+ // The tree follows the lockfile, as pnpm 11's and 12's do with trustLockfile,
145
+ // so what pnpm 11 checks the lockfile against the registry by is passed over.
173
146
  const IGNORED_11 = new Set([
174
147
  'minimumReleaseAgeIgnoreMissingTime', 'minimumReleaseAgeStrict', 'minimumReleaseAgeExcludePrune', 'trustLockfile',
175
148
  'trustPolicy', 'trustPolicyExclude', 'trustPolicyExcludePrune', 'trustPolicyIgnoreAfter', 'pnprServer',
@@ -186,26 +159,21 @@ const IGNORED_11 = new Set([
186
159
  'nodeVersionFromEnginesRuntime', 'cliOptions', 'explicitlySetKeys', 'packageManager', 'wantedPackageManager',
187
160
  ])
188
161
 
189
- // What pnpm 12 has that pnpm 11 has not: those that leave an isolated
190
- // tree as it is — resolution's, the hoisted linker's, the tasks of
191
- // `pnpm run`, the global install's — and a Cargo or Python install beside
192
- // the tree's, which is refused where it is enabled.
162
+ // What pnpm 12 adds that leaves an isolated tree as it is.
193
163
  const IGNORED_12 = new Set([
194
164
  'autoDedupe', 'autoInstallPeersFromHighestMatch', 'externalDependencies', 'hoistingLimits', 'globalShims',
195
165
  'concurrencyGroups', 'pipelines', 'pipelineBase', 'publishWaitTimeout', 'saveTypes', 'tools', 'macosBackup',
196
166
  ])
197
167
  const notEnabled = (value, where) => {
198
- if (value.enabled !== undefined && value.enabled !== null && value.enabled !== false) never('an install of Cargo or Python packages beside the tree is not supported')(value.enabled, `${where}.enabled`)
168
+ if (value.enabled != null && value.enabled !== false) never('an install of Cargo or Python packages beside the tree is not supported')(value.enabled, `${where}.enabled`)
199
169
  }
200
170
  const READ_12 = {
201
171
  __proto__: null,
172
+ nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 12'),
202
173
  cargo: { kind: 'mapping', check: notEnabled },
203
174
  python: { kind: 'mapping', check: notEnabled },
204
175
  }
205
176
 
206
- // What pnpm 11 reads or passes over that pnpm 12 does not know: it drops
207
- // each, and fails on one where the root package.json pins the pnpm that
208
- // runs.
209
177
  const UNRECOGNIZED_12 = new Set([
210
178
  'allowNonAppliedPatches', 'alwaysAuth', 'email', 'enginePinManifest', 'ignoreDepScripts', 'ignorePatchFailures',
211
179
  'lockfileDirectory', 'managePackageManagerVersions', 'nodeVersionFromEnginesRuntime', 'packageManagerStrict',
@@ -214,8 +182,27 @@ const UNRECOGNIZED_12 = new Set([
214
182
 
215
183
  export const unrecognized12 = (where) => new DeptreeError('pnpm 12 does not know it, and fails on it where the root package.json pins the pnpm that runs', where)
216
184
 
217
- // The keys of the root package.json's `pnpm` field pnpm 10 reads; it
218
- // passes over any other there.
185
+ // What pnpm 9 reads that pnpm 10 passes over: how it holds the root
186
+ // package.json's packageManager to the pnpm that runs (projects.js).
187
+ const READ_9 = {
188
+ __proto__: null,
189
+ nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 9'),
190
+ managePackageManagerVersions: { kind: 'boolean' },
191
+ packageManagerStrict: { kind: 'boolean' },
192
+ packageManagerStrictVersion: { kind: 'boolean' },
193
+ }
194
+
195
+ // What pnpm 10 reads that pnpm 9 has no setting for, and passes over.
196
+ const NOT_9 = new Set(['dedupePeers', 'enableGlobalVirtualStore', 'injectWorkspacePackages'])
197
+
198
+ // The keys of package.json's `pnpm` pnpm 9 reads, passing over any other.
199
+ export const MANIFEST_KEYS_9 = [
200
+ 'allowNonAppliedPatches', 'allowedDeprecatedVersions', 'ignoredOptionalDependencies', 'neverBuiltDependencies',
201
+ 'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'overrides', 'packageExtensions', 'patchedDependencies',
202
+ 'peerDependencyRules', 'supportedArchitectures',
203
+ ]
204
+
205
+ // The keys of package.json's `pnpm` pnpm 10 reads, passing over any other.
219
206
  export const MANIFEST_KEYS = [
220
207
  'allowBuilds', 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'auditConfig',
221
208
  'configDependencies', 'executionEnv', 'ignorePatchFailures', 'ignoredBuiltDependencies', 'ignoredOptionalDependencies',
@@ -223,21 +210,16 @@ export const MANIFEST_KEYS = [
223
210
  'patchedDependencies', 'peerDependencyRules', 'requiredScripts', 'supportedArchitectures', 'updateConfig',
224
211
  ]
225
212
 
226
- // Settings that leave the tree as it is. Resolution is done: the lockfile
227
- // is what these made of the manifests, and a frozen install holds it to
228
- // none of them (uptodate.js has those it does). Fetching goes to the public
229
- // registry alone, through @preventive/upstream, so the network and its
230
- // credentials are its own; the store, caches and state live outside
231
- // node_modules; bins are never written here, and scripts never run, as
232
- // with --ignore-scripts, whatever a setting would allow to build.
233
- export const IGNORED = new Set([
213
+ // A frozen install holds the lockfile to none of the resolution settings
214
+ // here (uptodate.js has those it does).
215
+ const IGNORED = new Set([
234
216
  // resolution, already in the lockfile
235
217
  'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
236
218
  'dedupeInjectedDeps', 'dedupePeerDependents', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
237
219
  'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
238
220
  'registrySupportsTimeField', 'resolutionMode', 'resolvePeersFromWorkspaceRoot', 'saveExact', 'savePrefix',
239
221
  'saveWorkspaceProtocol', 'strictPeerDependencies',
240
- // the network, and credentials for it
222
+ // the network and its credentials, which @preventive/upstream handles
241
223
  'alwaysAuth', 'ca', 'cafile', 'cert', 'email', 'fetchRetries', 'fetchRetryFactor', 'fetchRetryMaxtimeout',
242
224
  'fetchRetryMintimeout', 'fetchTimeout', 'httpProxy', 'httpsProxy', 'key', 'localAddress', 'maxsockets',
243
225
  'networkConcurrency', 'noProxy', 'noproxy', 'offline', 'preferOffline', 'proxy', 'strictSsl', 'userAgent',
@@ -262,7 +244,6 @@ export function checkRegistry(value, where) {
262
244
  if ((value.endsWith('/') ? value : `${value}/`) !== REGISTRY) throw new DeptreeError(`${quote(value)} is not supported: packages are fetched from ${REGISTRY} alone`, where)
263
245
  }
264
246
 
265
- // pnpm 11's registries: by scope, or `default`, the registry's URL.
266
247
  function checkRegistries(value, where) {
267
248
  for (const [scope, url] of Object.entries(value)) checkRegistry(readers.text(url, `${where}.${scope}`), `${where}.${scope}`)
268
249
  }
@@ -279,7 +260,6 @@ function checkArchitectures(value, where) {
279
260
  }
280
261
  }
281
262
 
282
- // A catalog: by name, the specifier it gives the package.
283
263
  function checkCatalog(value, where) {
284
264
  for (const [name, spec] of Object.entries(value)) readers.text(spec, `${where}.${name}`)
285
265
  }
@@ -288,11 +268,11 @@ function checkCatalogs(value, where) {
288
268
  for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
289
269
  }
290
270
 
291
- // What pnpm of `major` does with a setting, as far as is known here: reads
292
- // it, with `read`; leaves the tree as it is, with none; or for pnpm 12,
293
- // does not recognize it. Undefined for one not known. pnpm 12 takes a
294
- // pattern only as a list.
271
+ // `{}` where a setting leaves the tree as it is or pnpm 9 has no such setting,
272
+ // undefined where not known here. pnpm 12 takes a pattern only as a list.
295
273
  function lookup(name, major) {
274
+ if (major < 10 && name in READ_9) return { read: READ_9[name] }
275
+ if (major < 10 && NOT_9.has(name)) return {}
296
276
  if (major >= 12 && UNRECOGNIZED_12.has(name)) return { unrecognized: true }
297
277
  if (major >= 12 && name in READ_12) return { read: READ_12[name] }
298
278
  if (major >= 11 && name in READ_11) return { read: READ_11[name] }
@@ -301,9 +281,12 @@ function lookup(name, major) {
301
281
  return { read: major >= 12 && READ[name].kind === 'texts' ? { ...READ[name], kind: 'list' } : READ[name] }
302
282
  }
303
283
 
304
- // What reads a setting for pnpm of `major`, or undefined for one that
305
- // leaves the tree as it is; one not known is refused. `pinned` is whether
306
- // pnpm 12 fails on one it does not recognize.
284
+ // An .npmrc setting pnpm passes over is undefined.
285
+ export function npmrcReader(name, major) {
286
+ const read = lookup(name, major)?.read
287
+ return read?.rc === false ? undefined : read
288
+ }
289
+
307
290
  export function readerOf(name, where, major, pinned = false) {
308
291
  const found = lookup(name, major)
309
292
  if (found === undefined) throw new DeptreeError('unsupported setting', where)
@@ -311,14 +294,11 @@ export function readerOf(name, where, major, pinned = false) {
311
294
  return found.read
312
295
  }
313
296
 
314
- // Whether pnpm 12 knows a setting, read or passed over, as far as is known
315
- // here.
316
297
  export function known12(name) {
317
298
  const found = lookup(name, 12)
318
299
  return found !== undefined && !found.unrecognized
319
300
  }
320
301
 
321
- // By selector, the patch file, relative to the workspace's directory.
322
302
  function checkPatches(value, where) {
323
303
  for (const [selector, path] of Object.entries(value)) {
324
304
  const here = `${where}[${quote(selector)}]`