@preventive/deptree 1.0.0-alpha.0 → 1.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/bin/compare.js +132 -0
  3. package/bin/deptree.js +211 -0
  4. package/bin/npmrc.js +21 -0
  5. package/cargo.d.ts +223 -0
  6. package/cargo.js +6 -0
  7. package/npm.d.ts +321 -0
  8. package/npm.js +7 -0
  9. package/package.json +93 -11
  10. package/pnpm.d.ts +422 -60
  11. package/pnpm.js +3 -8
  12. package/soldeer.d.ts +235 -0
  13. package/soldeer.js +6 -0
  14. package/src/cargo/crate.js +183 -0
  15. package/src/cargo/inputs.js +81 -0
  16. package/src/cargo/members.js +90 -0
  17. package/src/cargo/registry.js +65 -0
  18. package/src/cargo/tree.js +125 -0
  19. package/src/cargo/workspace.js +177 -0
  20. package/src/concurrent.js +32 -0
  21. package/src/error.js +8 -10
  22. package/src/glob.js +55 -0
  23. package/src/hash.js +51 -16
  24. package/src/manifest.js +52 -0
  25. package/src/matcher.js +60 -10
  26. package/src/mount.js +128 -39
  27. package/src/npm/bins.js +54 -0
  28. package/src/npm/compat.js +97 -0
  29. package/src/npm/dev-engines.js +52 -0
  30. package/src/npm/graph.js +68 -0
  31. package/src/npm/inputs.js +75 -0
  32. package/src/npm/manifests.js +130 -0
  33. package/src/npm/package.js +57 -0
  34. package/src/npm/ratio.js +34 -0
  35. package/src/npm/settings.js +67 -0
  36. package/src/npm/tree.js +139 -0
  37. package/src/npm/versions.js +20 -0
  38. package/src/npmrc.js +24 -0
  39. package/src/patch.js +26 -45
  40. package/src/pnpm/bins.js +207 -327
  41. package/src/pnpm/checks.js +8 -35
  42. package/src/pnpm/commands.js +230 -0
  43. package/src/pnpm/filename.js +19 -16
  44. package/src/pnpm/frozen.js +47 -81
  45. package/src/pnpm/gitignore.js +138 -0
  46. package/src/pnpm/glob.js +65 -0
  47. package/src/pnpm/graph.js +26 -34
  48. package/src/pnpm/hoist.js +97 -59
  49. package/src/pnpm/hoisted.js +234 -0
  50. package/src/pnpm/hook.js +37 -51
  51. package/src/pnpm/inputs.js +177 -0
  52. package/src/pnpm/install.js +140 -130
  53. package/src/pnpm/local.js +105 -34
  54. package/src/pnpm/minimatch.js +319 -0
  55. package/src/pnpm/nm-hoist-graph.js +299 -0
  56. package/src/pnpm/nm-hoist.js +149 -0
  57. package/src/pnpm/npm-packlist.js +217 -0
  58. package/src/pnpm/overrides.js +20 -53
  59. package/src/pnpm/package.js +123 -0
  60. package/src/pnpm/packlist.js +194 -0
  61. package/src/pnpm/patches.js +21 -28
  62. package/src/pnpm/projects.js +150 -101
  63. package/src/pnpm/readers.js +122 -77
  64. package/src/pnpm/settings.js +85 -93
  65. package/src/pnpm/tree.js +234 -188
  66. package/src/pnpm/uptodate.js +17 -29
  67. package/src/pnpm/workspace.js +210 -53
  68. package/src/project.js +56 -0
  69. package/src/soldeer/config.js +63 -0
  70. package/src/soldeer/git.js +52 -0
  71. package/src/soldeer/inputs.js +30 -0
  72. package/src/soldeer/tree.js +83 -0
  73. package/src/soldeer/zip.js +121 -0
  74. package/src/tarball.js +123 -125
  75. package/src/yarn1/bins.js +28 -0
  76. package/src/yarn1/compat.js +67 -0
  77. package/src/yarn1/hoist.js +249 -0
  78. package/src/yarn1/inputs.js +83 -0
  79. package/src/yarn1/manifest.js +64 -0
  80. package/src/yarn1/package.js +206 -0
  81. package/src/yarn1/peers.js +51 -0
  82. package/src/yarn1/requests.js +74 -0
  83. package/src/yarn1/resolve.js +289 -0
  84. package/src/yarn1/settings.js +95 -0
  85. package/src/yarn1/tree.js +219 -0
  86. package/yarn1.d.ts +368 -0
  87. package/yarn1.js +7 -0
  88. package/src/pnpm/npmrc.js +0 -31
  89. /package/{LICENSE → LICENSE-MIT} +0 -0
@@ -1,64 +1,57 @@
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'
8
8
  import { REGISTRY } from '../tarball.js'
9
9
 
10
+ const ON_FAIL = new Set(['download', 'error', 'warn', 'ignore'])
11
+ const IMPORT_METHODS = new Set(['auto', 'hardlink', 'copy', 'clone', 'clone-or-copy'])
12
+
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
+
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
+ }
20
+
21
+ const oneOf = (allowed) => (value, where) => checked(allowed.has(value), value, `one of ${[...allowed].join(', ')}`, where)
22
+
10
23
  export const readers = {
11
24
  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)
25
+ return value === 'true' || value === 'false' ? value === 'true' : checked(typeof value === 'boolean', value, 'true or false', where)
15
26
  },
16
27
  count(value, where) {
17
28
  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)
29
+ return checked(Number.isSafeInteger(number) && number > 0, value, 'a positive integer', where, number)
20
30
  },
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.
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.
26
33
  texts(value, where) {
27
34
  return readers.list(typeof value === 'string' ? [value] : value, where, 'a string or a list of strings')
28
35
  },
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
- },
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),
40
+ importMethod: oneOf(IMPORT_METHODS),
41
+ onFail: oneOf(ON_FAIL),
49
42
  linkWorkspacePackages(value, where) {
50
43
  return value === 'deep' ? true : readers.boolean(value, where)
51
44
  },
52
- // true or false, or what to read and write, and a remote cache, which is
53
- // refused.
45
+ // A path, or a list of them, which pnpm 12 takes too.
46
+ pnpmfile(value, where) {
47
+ return typeof value === 'string' ? value : readers.list(value, where, 'a string or a list of strings')
48
+ },
54
49
  sideEffectsCache(value, where) {
55
50
  if (typeof value === 'boolean') return value
56
51
  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
52
  return value
58
53
  },
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.
54
+ // pnpm 11's per-project settings: by project name, or a list with `match`.
62
55
  packageConfigs(value, where) {
63
56
  const configs = Array.isArray(value) ? value.map((item, i) => [i, item]) : Object.entries(readers.mapping(value, where))
64
57
  for (const [key, config] of configs) {
@@ -72,23 +65,16 @@ export const readers = {
72
65
  },
73
66
  }
74
67
 
75
- const ON_FAIL = new Set(['download', 'error', 'warn', 'ignore'])
68
+ const only = (kind, wanted, why) => ({ kind, check: (value, where) => value === wanted || never(why)(value, where) })
76
69
 
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
70
  const never = (why) => (value, where) => {
86
71
  throw new DeptreeError(`${show(value)} is not supported: ${why}`, where)
87
72
  }
88
73
 
89
74
  export const READ = {
90
75
  __proto__: null,
91
- nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built'),
76
+ // pnpm 10's hoisted layout too (hoisted.js).
77
+ nodeLinker: { kind: 'text', check: (value, where) => value === 'hoisted' || value === 'isolated' || never('only the isolated and hoisted node_modules layouts are built')(value, where) },
92
78
  symlink: only('boolean', true, 'a tree without its links is not built'),
93
79
  enableModulesDir: only('boolean', true, 'a tree without node_modules is not built'),
94
80
  modulesDir: only('text', 'node_modules', 'the modules directory is always node_modules'),
@@ -118,6 +104,10 @@ export const READ = {
118
104
  filterProd: { kind: 'texts', check: never('every project is installed') },
119
105
  useNodeVersion: { kind: 'text', check: never('the Node a tree is built for is the host\'s, or nodeVersion') },
120
106
  globalPnpmfile: { kind: 'text', check: never('a pnpmfile\'s hooks are not run here') },
107
+ // [] loads none, not even the default one. An .npmrc's is passed over: from
108
+ // a path that leads nowhere pnpm 9 loads none, and a pnpmfile with hooks
109
+ // puts its pnpmfileChecksum in the lockfile, which is refused (tree.js).
110
+ pnpmfile: { kind: 'pnpmfile', check: (value, where) => (Array.isArray(value) && value.length === 0) || never('a pnpmfile\'s hooks are not run here')(value, where), rc: false },
121
111
  registry: { kind: 'text', check: checkRegistry },
122
112
  virtualStoreDirMaxLength: { kind: 'count' },
123
113
  hoist: { kind: 'boolean' },
@@ -130,6 +120,8 @@ export const READ = {
130
120
  autoInstallPeers: { kind: 'boolean' },
131
121
  dedupePeers: { kind: 'boolean' },
132
122
  peersSuffixMaxLength: { kind: 'count' },
123
+ // Whether a directory package's snapshots share hardlinked files (tree.js).
124
+ packageImportMethod: { kind: 'importMethod' },
133
125
  // Neither pnpm's .npmrc nor ours has these.
134
126
  supportedArchitectures: { kind: 'mapping', check: checkArchitectures, rc: false },
135
127
  patchedDependencies: { kind: 'mapping', check: checkPatches, rc: false },
@@ -157,11 +149,8 @@ const READ_11 = {
157
149
  linkWorkspacePackages: { kind: 'linkWorkspacePackages' },
158
150
  }
159
151
 
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.
152
+ // The tree follows the lockfile, as pnpm 11's and 12's do with trustLockfile,
153
+ // so what pnpm 11 checks the lockfile against the registry by is passed over.
165
154
  const IGNORED_11 = new Set([
166
155
  'minimumReleaseAgeIgnoreMissingTime', 'minimumReleaseAgeStrict', 'minimumReleaseAgeExcludePrune', 'trustLockfile',
167
156
  'trustPolicy', 'trustPolicyExclude', 'trustPolicyExcludePrune', 'trustPolicyIgnoreAfter', 'pnprServer',
@@ -178,8 +167,50 @@ const IGNORED_11 = new Set([
178
167
  'nodeVersionFromEnginesRuntime', 'cliOptions', 'explicitlySetKeys', 'packageManager', 'wantedPackageManager',
179
168
  ])
180
169
 
181
- // The keys of the root package.json's `pnpm` field pnpm 10 reads; it
182
- // passes over any other there.
170
+ // What pnpm 12 adds that leaves an isolated tree as it is.
171
+ const IGNORED_12 = new Set([
172
+ 'autoDedupe', 'autoInstallPeersFromHighestMatch', 'externalDependencies', 'hoistingLimits', 'globalShims',
173
+ 'concurrencyGroups', 'pipelines', 'pipelineBase', 'publishWaitTimeout', 'saveTypes', 'tools', 'macosBackup',
174
+ ])
175
+ const notEnabled = (value, where) => {
176
+ 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`)
177
+ }
178
+ const READ_12 = {
179
+ __proto__: null,
180
+ nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 12'),
181
+ cargo: { kind: 'mapping', check: notEnabled },
182
+ python: { kind: 'mapping', check: notEnabled },
183
+ }
184
+
185
+ const UNRECOGNIZED_12 = new Set([
186
+ 'allowNonAppliedPatches', 'alwaysAuth', 'email', 'enginePinManifest', 'ignoreDepScripts', 'ignorePatchFailures',
187
+ 'lockfileDirectory', 'managePackageManagerVersions', 'nodeVersionFromEnginesRuntime', 'packageManagerStrict',
188
+ 'packageManagerStrictVersion', 'shamefullyFlatten', 'useNodeVersion',
189
+ ])
190
+
191
+ 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)
192
+
193
+ // What pnpm 9 reads that pnpm 10 passes over: how it holds the root
194
+ // package.json's packageManager to the pnpm that runs (projects.js).
195
+ const READ_9 = {
196
+ __proto__: null,
197
+ nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 9'),
198
+ managePackageManagerVersions: { kind: 'boolean' },
199
+ packageManagerStrict: { kind: 'boolean' },
200
+ packageManagerStrictVersion: { kind: 'boolean' },
201
+ }
202
+
203
+ // What pnpm 10 reads that pnpm 9 has no setting for, and passes over.
204
+ const NOT_9 = new Set(['dedupePeers', 'enableGlobalVirtualStore', 'injectWorkspacePackages'])
205
+
206
+ // The keys of package.json's `pnpm` pnpm 9 reads, passing over any other.
207
+ export const MANIFEST_KEYS_9 = [
208
+ 'allowNonAppliedPatches', 'allowedDeprecatedVersions', 'ignoredOptionalDependencies', 'neverBuiltDependencies',
209
+ 'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'overrides', 'packageExtensions', 'patchedDependencies',
210
+ 'peerDependencyRules', 'supportedArchitectures',
211
+ ]
212
+
213
+ // The keys of package.json's `pnpm` pnpm 10 reads, passing over any other.
183
214
  export const MANIFEST_KEYS = [
184
215
  'allowBuilds', 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'auditConfig',
185
216
  'configDependencies', 'executionEnv', 'ignorePatchFailures', 'ignoredBuiltDependencies', 'ignoredOptionalDependencies',
@@ -187,26 +218,21 @@ export const MANIFEST_KEYS = [
187
218
  'patchedDependencies', 'peerDependencyRules', 'requiredScripts', 'supportedArchitectures', 'updateConfig',
188
219
  ]
189
220
 
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([
221
+ // A frozen install holds the lockfile to none of the resolution settings
222
+ // here (uptodate.js has those it does).
223
+ const IGNORED = new Set([
198
224
  // resolution, already in the lockfile
199
225
  'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'blockExoticSubdeps', 'catalogMode',
200
- 'dedupeInjectedDeps', 'dedupePeerDependents', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
226
+ 'dedupeInjectedDeps', 'dedupePeerDependents', 'ignoreCompatibilityDb', 'linkWorkspacePackages', 'lockfileIncludeTarballUrl',
201
227
  'minimumReleaseAge', 'minimumReleaseAgeExclude', 'peerDependencyRules', 'preferWorkspacePackages',
202
228
  'registrySupportsTimeField', 'resolutionMode', 'resolvePeersFromWorkspaceRoot', 'saveExact', 'savePrefix',
203
229
  'saveWorkspaceProtocol', 'strictPeerDependencies',
204
- // the network, and credentials for it
230
+ // the network and its credentials, which @preventive/upstream handles
205
231
  'alwaysAuth', 'ca', 'cafile', 'cert', 'email', 'fetchRetries', 'fetchRetryFactor', 'fetchRetryMaxtimeout',
206
232
  'fetchRetryMintimeout', 'fetchTimeout', 'httpProxy', 'httpsProxy', 'key', 'localAddress', 'maxsockets',
207
233
  'networkConcurrency', 'noProxy', 'noproxy', 'offline', 'preferOffline', 'proxy', 'strictSsl', 'userAgent',
208
234
  // the store, caches and state, none of it in node_modules
209
- 'cacheDir', 'modulesCacheMaxAge', 'packageImportMethod', 'sideEffectsCache', 'sideEffectsCacheReadonly',
235
+ 'cacheDir', 'modulesCacheMaxAge', 'sideEffectsCache', 'sideEffectsCacheReadonly',
210
236
  'stateDir', 'storeDir', 'strictStorePkgContentCheck', 'verifyStoreIntegrity',
211
237
  // scripts, which are not run, and bins, which are not written
212
238
  'allowBuilds', 'childConcurrency', 'dangerouslyAllowAllBuilds', 'enablePrePostScripts', 'extendNodePath',
@@ -226,7 +252,6 @@ export function checkRegistry(value, where) {
226
252
  if ((value.endsWith('/') ? value : `${value}/`) !== REGISTRY) throw new DeptreeError(`${quote(value)} is not supported: packages are fetched from ${REGISTRY} alone`, where)
227
253
  }
228
254
 
229
- // pnpm 11's registries: by scope, or `default`, the registry's URL.
230
255
  function checkRegistries(value, where) {
231
256
  for (const [scope, url] of Object.entries(value)) checkRegistry(readers.text(url, `${where}.${scope}`), `${where}.${scope}`)
232
257
  }
@@ -243,7 +268,6 @@ function checkArchitectures(value, where) {
243
268
  }
244
269
  }
245
270
 
246
- // A catalog: by name, the specifier it gives the package.
247
271
  function checkCatalog(value, where) {
248
272
  for (const [name, spec] of Object.entries(value)) readers.text(spec, `${where}.${name}`)
249
273
  }
@@ -252,16 +276,37 @@ function checkCatalogs(value, where) {
252
276
  for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
253
277
  }
254
278
 
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]
279
+ // `{}` where a setting leaves the tree as it is or pnpm 9 has no such setting,
280
+ // undefined where not known here. pnpm 12 takes a pattern only as a list.
281
+ function lookup(name, major) {
282
+ if (major < 10 && name in READ_9) return { read: READ_9[name] }
283
+ if (major < 10 && NOT_9.has(name)) return {}
284
+ if (major >= 12 && UNRECOGNIZED_12.has(name)) return { unrecognized: true }
285
+ if (major >= 12 && name in READ_12) return { read: READ_12[name] }
286
+ if (major >= 11 && name in READ_11) return { read: READ_11[name] }
287
+ if (IGNORED.has(name) || (major >= 11 && IGNORED_11.has(name)) || (major >= 12 && IGNORED_12.has(name))) return {}
288
+ if (!(name in READ)) return undefined
289
+ return { read: major >= 12 && READ[name].kind === 'texts' ? { ...READ[name], kind: 'list' } : READ[name] }
290
+ }
291
+
292
+ // An .npmrc setting pnpm passes over is undefined.
293
+ export function npmrcReader(name, major) {
294
+ const read = lookup(name, major)?.read
295
+ return read?.rc === false ? undefined : read
296
+ }
297
+
298
+ export function readerOf(name, where, major, pinned = false) {
299
+ const found = lookup(name, major)
300
+ if (found === undefined) throw new DeptreeError('unsupported setting', where)
301
+ if (found.unrecognized && pinned) throw unrecognized12(where)
302
+ return found.read
303
+ }
304
+
305
+ export function known12(name) {
306
+ const found = lookup(name, 12)
307
+ return found !== undefined && !found.unrecognized
262
308
  }
263
309
 
264
- // By selector, the patch file, relative to the workspace's directory.
265
310
  function checkPatches(value, where) {
266
311
  for (const [selector, path] of Object.entries(value)) {
267
312
  const here = `${where}[${quote(selector)}]`
@@ -1,49 +1,17 @@
1
- // The settings a pnpm 10 install reads from the .npmrc beside the lockfile,
2
- // from pnpm-workspace.yaml, and from the root package.json's `pnpm` field,
3
- // each over the one before: `pnpm install` spreads what the package.json
4
- // sets over the config it read the others into, so there the package.json
5
- // wins, whatever pnpm's config alone would say.
6
- // In pnpm-workspace.yaml and the package.json, every key is one of three
7
- // things (readers.js): a setting read here, and held to the values this
8
- // package builds a tree for; a setting that leaves the tree as it is,
9
- // whether because a frozen lockfile already says what it would have
10
- // changed, because it is about the network, the store, a cache, a script
11
- // or a bin — no script is ever run, whatever a setting allows — or because
12
- // it is a credential; or anything else, which is refused by name, as is a
13
- // value read here that this package does not build for.
14
- //
15
- // An .npmrc is read as pnpm reads one: by the kebab-case names of its
16
- // settings alone, and of those only the ones it has types for, which are
17
- // npm's and its own. Every one of those that can change the tree is read
18
- // here as above; anything else in the file — npm's settings pnpm has no
19
- // use for, publishing's, credentials, any other spelling — pnpm passes
20
- // over for an install, and so does this. A value pnpm would take from the
21
- // environment is not known here: pnpm drops the whole file where one such
22
- // variable is unset, so one in a line passed over is taken only where the
23
- // file sets nothing that dropping it would change.
24
- //
25
- // Only these files are read. Settings from anywhere else pnpm looks — a
26
- // user or global .npmrc, `npm_config_*` in the environment, the command
27
- // line — are not seen, and a tree built here is the one those leave at
28
- // their defaults. Of the package.json, pnpm 10 reads only the keys of
29
- // `pnpm` below (MANIFEST_KEYS) and Yarn's `resolutions`, and so does this.
30
- //
31
- // pnpm 11 reads its settings from pnpm-workspace.yaml alone: an .npmrc
32
- // for credentials and registries, and the package.json for none but the
33
- // Node its engines.runtime pins, which it takes for nodeVersion. Of the
34
- // yaml it passes over a key not in camelCase, and one about the machine,
35
- // the run or a login; it has settings pnpm 10 has not (READ_11, IGNORED_11),
36
- // and reads linkWorkspacePackages for a frozen install too.
1
+ // The settings an install reads. pnpm 10 reads the .npmrc beside the
2
+ // lockfile, pnpm-workspace.yaml and the root package.json's `pnpm` field,
3
+ // each over the one before; pnpm 9 reads only `packages` and the catalogs of
4
+ // pnpm-workspace.yaml, and pnpm 11 and 12 read pnpm-workspace.yaml alone.
5
+ // Settings from anywhere else (a user or global .npmrc, `npm_config_*`, the
6
+ // command line) are taken to be at their defaults.
37
7
 
38
8
  import { valid, validRange } from '@preventive/upstream/semver.js'
39
9
  import { DeptreeError, quote } from '../error.js'
40
- import { parseNpmrc } from './npmrc.js'
10
+ import { parseNpmrc } from '../npmrc.js'
41
11
  import { replaceReferences } from './overrides.js'
42
- import { IGNORED, MANIFEST_KEYS, READ, checkRegistry, readerOf, readers } from './readers.js'
12
+ import { MANIFEST_KEYS, MANIFEST_KEYS_9, READ, checkRegistry, known12, npmrcReader, readerOf, readers, unrecognized12 } from './readers.js'
43
13
 
44
- // An .npmrc value read only where it can mean one thing: not quoted, not
45
- // escaped, with no `;` or `#` that ini would cut it at. Neither file's
46
- // value is read where pnpm would fill it in from the environment.
14
+ // An .npmrc value can mean one thing only with no quote, escape, `;` or `#`.
47
15
  const PLAIN = /^[^"'`;#\\]*$/u
48
16
  function plain(value, where) {
49
17
  if (!PLAIN.test(value)) throw new DeptreeError(`${quote(value)} is quoted, escaped or commented, which is not read here`, where)
@@ -61,94 +29,109 @@ function noEnvironment(value, where) {
61
29
  const KEBAB = /^[a-z][\da-z]*(?:-[\da-z]+)*$/u
62
30
  const camelCase = (key) => key.replace(/-+([a-z\d])/gu, (_, char) => char.toUpperCase())
63
31
 
64
- // An .npmrc's settings by name, each written once, or once with `[]` each
65
- // time, and whether any line takes something from the environment. A
66
- // registry for a scope has to be the public one.
67
- // pnpm 11 reads an .npmrc for credentials and registries alone, and passes
68
- // over a registry of a project's .npmrc that names a variable.
32
+ // pnpm 11 reads an .npmrc for credentials and registries alone; a registry
33
+ // that names a variable is passed over.
34
+ function checkNpmrcRegistries(text) {
35
+ for (const { key, value, line } of parseNpmrc(text)) {
36
+ if ((key !== 'registry' && !/^@[^:]+:registry$/u.test(key)) || fromEnvironment(value)) continue
37
+ const where = `.npmrc:${line}: ${key}`
38
+ checkRegistry(plain(value, where), where)
39
+ }
40
+ }
41
+
42
+ // The registry's token as a project's .npmrc commonly gives it is taken to
43
+ // be set, as @preventive/upstream reads it too: pnpm reads the file then.
44
+ const isNpmToken = (key, value) => key === '//registry.npmjs.org/:_authToken' && value === '${NPM_TOKEN}'
45
+
69
46
  function fromNpmrc(text, major) {
70
47
  const settings = new Map()
71
48
  let environment = false
72
49
  for (const { key, value, list, line } of parseNpmrc(text)) {
73
50
  const where = `.npmrc:${line}: ${key}`
74
- if (major >= 11) {
75
- if ((key === 'registry' || /^@[^:]+:registry$/u.test(key)) && !fromEnvironment(value)) checkRegistry(plain(value, where), where)
76
- continue
77
- }
78
51
  if (/^@[^:]+:registry$/u.test(key)) {
79
52
  checkRegistry(plain(noEnvironment(value, where), where), where)
80
53
  continue
81
54
  }
82
55
  const name = KEBAB.test(key) ? camelCase(key) : undefined
83
- if (!(name in READ) || READ[name].rc === false || IGNORED.has(name)) {
84
- environment ||= fromEnvironment(key) || fromEnvironment(value)
56
+ const read = name === undefined ? undefined : npmrcReader(name, major)
57
+ if (read === undefined) {
58
+ if (!isNpmToken(key, value)) environment ||= fromEnvironment(key) || fromEnvironment(value)
85
59
  continue
86
60
  }
87
61
  noEnvironment(value, where)
88
62
  const earlier = settings.get(name)
89
63
  if (earlier !== undefined && !(list && earlier.list)) throw new DeptreeError('set more than once', where)
90
- if (list && READ[name].kind !== 'texts') throw new DeptreeError('not a list', where)
64
+ if (list && read.kind !== 'texts') throw new DeptreeError('not a list', where)
91
65
  const next = list ? [...(earlier?.value ?? []), plain(value, where)] : plain(value, where)
92
- settings.set(name, { value: next, list, where, read: READ[name] })
66
+ settings.set(name, { value: next, list, where, read })
93
67
  }
94
68
  return { settings, environment }
95
69
  }
96
70
 
97
- // The root package.json's settings: the keys of `pnpm` pnpm reads, and
98
- // overrides of `resolutions` and `pnpm.overrides` both, the second over the
99
- // first.
100
- function fromManifest(manifest) {
71
+ // pnpm 10 takes Yarn's `resolutions` as overrides, under `pnpm.overrides`.
72
+ function fromManifest(manifest, major) {
101
73
  const pnpm = manifest.pnpm === undefined ? {} : readers.mapping(manifest.pnpm, 'package.json: pnpm')
102
74
  const settings = new Map()
103
- for (const name of MANIFEST_KEYS) {
75
+ for (const name of major < 10 ? MANIFEST_KEYS_9 : MANIFEST_KEYS) {
104
76
  if (!Object.hasOwn(pnpm, name) || name === 'overrides') continue
105
77
  const where = `package.json: pnpm.${name}`
106
78
  noEnvironment(pnpm[name], where)
107
- const read = readerOf(name, where, 10)
79
+ const read = readerOf(name, where, major)
108
80
  if (read !== undefined) settings.set(name, { value: pnpm[name], where, read })
109
81
  }
110
82
  const { resolutions } = manifest
111
83
  if (resolutions !== undefined || Object.hasOwn(pnpm, 'overrides')) {
112
- const where = 'package.json: resolutions and pnpm.overrides'
113
84
  const value = { ...(resolutions === undefined ? {} : readers.mapping(resolutions, 'package.json: resolutions')), ...(Object.hasOwn(pnpm, 'overrides') ? readers.mapping(pnpm.overrides, 'package.json: pnpm.overrides') : {}) }
114
- settings.set('overrides', { value, where, read: READ.overrides })
85
+ settings.set('overrides', { value, where: 'package.json: resolutions and pnpm.overrides', read: READ.overrides })
115
86
  }
116
87
  return settings
117
88
  }
118
89
 
119
- // pnpm 11 passes over a key not in camelCase.
120
90
  const CAMEL = /^[a-z][\dA-Za-z]*$/u
121
91
 
122
- function fromWorkspace(workspace, major) {
92
+ // pnpm 12 passes over a key with no value.
93
+ function fromWorkspace(workspace, major, pinned) {
123
94
  if (workspace === null || typeof workspace !== 'object' || Array.isArray(workspace)) throw new DeptreeError('expected a mapping', 'pnpm-workspace.yaml')
124
95
  const settings = new Map()
125
96
  for (const [name, value] of Object.entries(workspace)) {
126
97
  const where = `pnpm-workspace.yaml: ${name}`
127
98
  noEnvironment(name, where)
128
99
  noEnvironment(value, where)
129
- if (major >= 11 && !CAMEL.test(name)) continue
130
- const read = readerOf(name, where, major)
100
+ if (major >= 11 && !CAMEL.test(name)) {
101
+ if (major >= 12 && pinned && value !== null && !known12(camelCase(name))) throw unrecognized12(where)
102
+ continue
103
+ }
104
+ const read = readerOf(name, where, major, pinned && value !== null)
131
105
  if (read !== undefined) settings.set(name, { value, where, read })
132
106
  }
133
107
  return settings
134
108
  }
135
109
 
136
- // The settings as pnpm 10 derives what it installs by: `hoist: false`
137
- // drops the private pattern, `shamefullyHoist` sets or drops the public
138
- // one, and an empty public pattern is none. A pattern left undefined is
139
- // not hoisted to at all.
140
- function derive(get, os) {
110
+ // pnpm 9 passes over the rest of pnpm-workspace.yaml unread, a catalog of null
111
+ // among it.
112
+ function fromWorkspace9(workspace) {
113
+ readers.mapping(workspace, 'pnpm-workspace.yaml')
114
+ const names = ['packages', 'catalog', 'catalogs'].filter((name) => workspace[name] != null)
115
+ return new Map(names.map((name) => [name, { value: workspace[name], where: `pnpm-workspace.yaml: ${name}`, read: READ[name] }]))
116
+ }
117
+
118
+ const PUBLIC_9 = ['*eslint*', '*prettier*']
119
+
120
+ // A hoist pattern left undefined is not hoisted to at all. Only on Windows,
121
+ // which checkHost refuses, is virtualStoreDirMaxLength 60 by default.
122
+ function derive(get, major) {
141
123
  const shamefullyHoist = get('shamefullyHoist')
142
- let publicHoistPattern = get('publicHoistPattern') ?? []
124
+ let publicHoistPattern = get('publicHoistPattern') ?? (major < 10 ? PUBLIC_9 : [])
143
125
  if (shamefullyHoist === true) publicHoistPattern = ['*']
144
126
  else if (shamefullyHoist === false || (publicHoistPattern.length === 1 && publicHoistPattern[0] === '')) publicHoistPattern = undefined
145
127
  return {
146
- virtualStoreDirMaxLength: get('virtualStoreDirMaxLength') ?? (os === 'win32' ? 60 : 120),
128
+ virtualStoreDirMaxLength: get('virtualStoreDirMaxLength') ?? 120,
147
129
  hoistPattern: get('hoist') === false ? undefined : get('hoistPattern') ?? ['*'],
148
130
  publicHoistPattern,
149
131
  hoistWorkspacePackages: get('hoistWorkspacePackages') ?? true,
150
132
  engineStrict: get('engineStrict') ?? false,
151
133
  nodeVersion: get('nodeVersion'),
134
+ runtimeNodeVersion: undefined,
152
135
  supportedArchitectures: get('supportedArchitectures'),
153
136
  patchedDependencies: get('patchedDependencies'),
154
137
  overrides: get('overrides'),
@@ -162,11 +145,18 @@ function derive(get, os) {
162
145
  linkWorkspacePackages: get('linkWorkspacePackages') ?? false,
163
146
  pmOnFail: get('pmOnFail'),
164
147
  runtimeOnFail: get('runtimeOnFail'),
148
+ packageImportMethod: get('packageImportMethod') ?? 'auto',
149
+ nodeLinker: get('nodeLinker') ?? 'isolated',
150
+ ...major < 10 ? {
151
+ packageManagerChecks: {
152
+ manage: get('managePackageManagerVersions') ?? false,
153
+ strict: get('packageManagerStrict') ?? true,
154
+ strictVersion: get('packageManagerStrictVersion') ?? false,
155
+ },
156
+ } : {},
165
157
  }
166
158
  }
167
159
 
168
- // The catalogs by name, `catalog` being `default`, as pnpm has them, which
169
- // refuses the default one written both ways.
170
160
  function catalogsOf(catalog, catalogs = {}) {
171
161
  if (catalog !== undefined && Object.hasOwn(catalogs, 'default')) {
172
162
  throw new DeptreeError('the default catalog is defined twice, as catalog and as catalogs.default', 'pnpm-workspace.yaml: catalog')
@@ -174,8 +164,7 @@ function catalogsOf(catalog, catalogs = {}) {
174
164
  return Object.assign(Object.create(null), catalog === undefined ? {} : { default: catalog }, catalogs)
175
165
  }
176
166
 
177
- // Each layer over the one before, as `derive` has them.
178
- function settle(layers, manifest, os) {
167
+ function settle(layers, manifest, major) {
179
168
  const values = new Map()
180
169
  for (const layer of layers) {
181
170
  for (const [name, { value, where, read: { kind, check } }] of layer) {
@@ -188,30 +177,33 @@ function settle(layers, manifest, os) {
188
177
  values.set(name, read)
189
178
  }
190
179
  }
191
- return derive((name) => values.get(name), os)
180
+ return derive((name) => values.get(name), major)
192
181
  }
193
182
 
194
- // `workspace` is pnpm-workspace.yaml as parsed and `npmrc` the text of the
195
- // .npmrc, either of which may be undefined; `manifest` the root
196
- // package.json as parsed. `os` is the host's, which one default depends
197
- // on. Overrides that name nothing are none, and leave those below them.
198
- export function readSettings({ workspace, npmrc, manifest, os, major = 10 }) {
183
+ // Overrides that name nothing are none, and leave those below them.
184
+ export function readSettings({ workspace, npmrc, manifest, major = 10, pinned = false }) {
185
+ const fromYaml = () => {
186
+ if (workspace === undefined) return new Map()
187
+ return major < 10 ? fromWorkspace9(workspace) : fromWorkspace(workspace, major, pinned)
188
+ }
189
+ if (major >= 11) {
190
+ if (npmrc !== undefined) checkNpmrcRegistries(npmrc)
191
+ const settings = settle([fromYaml()], manifest, major)
192
+ settings.runtimeNodeVersion = runtimeNode(manifest, settings.runtimeOnFail)
193
+ return settings
194
+ }
199
195
  const rc = npmrc === undefined ? { settings: new Map(), environment: false } : fromNpmrc(npmrc, major)
200
- // pnpm 11 reads no setting from the package.json, its `resolutions` none.
201
- const rest = [workspace === undefined ? new Map() : fromWorkspace(workspace, major), major >= 11 ? new Map() : fromManifest(manifest)]
202
- const settings = settle([rc.settings, ...rest], manifest, os)
203
- if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest, os))) {
196
+ const rest = [fromYaml(), fromManifest(manifest, major)]
197
+ const settings = settle([rc.settings, ...rest], manifest, major)
198
+ if (rc.environment && JSON.stringify(settings) !== JSON.stringify(settle(rest, manifest, major))) {
204
199
  throw new DeptreeError('a line takes a value from the environment, which pnpm drops the whole file for where it is unset, and the file sets what would change the tree', '.npmrc')
205
200
  }
206
- if (major >= 11) settings.nodeVersion ??= runtimeNode(manifest, settings.runtimeOnFail)
207
201
  return settings
208
202
  }
209
203
 
210
- // The Node the root package.json's devEngines.runtime or engines.runtime
211
- // pins, which pnpm 11 takes for nodeVersion where none is set: the first
212
- // that names a range for Node decides, and gives its version where that is
213
- // exact. One to download, which gives the range's lowest, is refused;
214
- // runtimeOnFail stands for each one's onFail.
204
+ // The Node the root's runtime pins, for nodeVersion where none is set: the
205
+ // first naming a range for Node decides, with its version where exact. One
206
+ // to download, which gives the range's lowest, is refused.
215
207
  function runtimeNode(manifest, onFail) {
216
208
  for (const field of ['devEngines', 'engines']) {
217
209
  const runtime = manifest[field]?.runtime