@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,66 +1,28 @@
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'
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.
7
+
8
+ import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
35
9
  import { DeptreeError, difference, quote } from '../error.js'
36
- import { checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, refOf, sameSpecifier } from './frozen.js'
10
+ import { own, readManifest } from '../manifest.js'
11
+ import { createMatcher } from '../matcher.js'
12
+ import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
37
13
  import { checkProject } from './install.js'
38
14
  import { validForOldPackages } from './overrides.js'
15
+ import { checkProjectId } from './workspace.js'
39
16
 
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
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()
61
20
  for (const [id, text] of manifests instanceof Map ? manifests : Object.entries(manifests)) {
62
21
  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)
22
+ if (!(id in lockfile.importers)) {
23
+ checkProjectId(id, where)
24
+ lockfile.importers[id] = { specifiers: {}, dependencies: {}, devDependencies: {}, optionalDependencies: {}, dependenciesMeta: {}, linkDirectory: true, made: true }
25
+ }
64
26
  read.set(id, readManifest(text, where))
65
27
  }
66
28
  for (const id of Object.keys(lockfile.importers)) {
@@ -71,10 +33,7 @@ export function readManifests(manifests, lockfile) {
71
33
 
72
34
  const omit = (deps, names) => Object.fromEntries(Object.entries(deps).filter(([name]) => !names.has(name)))
73
35
 
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.
36
+ // The hook has held each of these fields to a mapping of strings.
78
37
  function wantedOf(manifest, autoInstallPeers, unresolved) {
79
38
  const kinds = Object.fromEntries(KINDS.map((kind) => [kind, manifest[kind] ?? {}]))
80
39
  let all = omit({ ...kinds.devDependencies, ...kinds.dependencies, ...kinds.optionalDependencies }, unresolved)
@@ -87,33 +46,32 @@ function wantedOf(manifest, autoInstallPeers, unresolved) {
87
46
  return { kinds, all }
88
47
  }
89
48
 
90
- // dependenciesMeta as the lockfile reader hands it back: `injected` false
91
- // where it is not set.
49
+ // As the lockfile reader hands dependenciesMeta back: `injected` false where
50
+ // it is not set.
92
51
  const metaOf = (meta) => JSON.stringify(Object.entries(meta).map(([name, item]) => [name, item?.injected === true, item?.node]).sort())
93
52
 
53
+ // pnpm 9 does not hold what a dependency resolved to to its range.
94
54
  function checkKind(importer, kinds, kind, unresolved, major) {
95
55
  const locked = importer[kind]
96
56
  const wanted = kind === 'devDependencies' ? kinds[kind] : omit(kinds[kind], unresolved)
97
57
  const names = Object.keys(wanted).filter((name) => kind === 'optionalDependencies'
98
- || (!kinds.optionalDependencies[name] && (kind === 'dependencies' || !kinds.dependencies[name])))
58
+ || (!own(kinds.optionalDependencies, name) && (kind === 'dependencies' || !own(kinds.dependencies, name))))
99
59
  const unlinked = Object.values(locked).filter((target) => !target.includes('link:') && !target.includes('file:')).length
100
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`
101
61
  for (const name of names) {
102
62
  if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
103
63
  const spec = importer.specifiers[name]
104
- if (validRange(spec) === null) continue
105
- const version = packageKeyOf(refOf(name, locked[name]))
64
+ if (major < 10 || validRange(spec) === null) continue
65
+ const version = resolvedOf(name, locked[name])
106
66
  if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
107
67
  }
108
68
  return undefined
109
69
  }
110
70
 
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.
71
+ // Why pnpm finds `importer` out of date: of the specifiers, the first
72
+ // difference, as pnpm's diffFlatRecords finds.
114
73
  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) : [])
74
+ const unresolved = new Set(major >= 11 ? Object.keys(manifest.optionalDependencies ?? {}).filter((name) => importer.specifiers[name] === undefined) : [])
117
75
  const { kinds, all } = wantedOf(manifest, autoInstallPeers, unresolved)
118
76
  const specified = difference(importer.specifiers, all, ['the lockfile', 'package.json'], (a, b) => sameSpecifier(a, b, major))
119
77
  if (specified !== undefined) return `the specifiers differ: ${specified}`
@@ -131,8 +89,7 @@ function mismatch(importer, manifest, autoInstallPeers, major, where) {
131
89
  return undefined
132
90
  }
133
91
 
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.
92
+ // devEngines.packageManager as pnpm 11 reads it.
136
93
  function devEnginesPackageManager(devEngines, where) {
137
94
  const engines = devEngines?.packageManager
138
95
  if (!engines) return undefined
@@ -148,13 +105,93 @@ function devEnginesPackageManager(devEngines, where) {
148
105
  return { name: engine.name, onFail }
149
106
  }
150
107
 
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) {
108
+ // The exact pnpm version packageManager names, per pnpm's parsePackageManager.
109
+ export function pinnedPnpm(packageManager) {
110
+ const version = typeof packageManager === 'string' ? /^pnpm@([^+:@]+)(?:\+.*)?$/u.exec(packageManager)?.[1] : undefined
111
+ return isExactVersion(version) ? version : undefined
112
+ }
113
+
114
+ // The root's pin, as pnpm 12's wanted_package_manager reads it.
115
+ function wantedPackageManager(manifest) {
116
+ const declared = manifest.devEngines?.packageManager
117
+ const list = Array.isArray(declared) ? declared : declared == null ? [] : [declared]
118
+ const index = Array.isArray(declared) ? Math.max(list.findIndex((entry) => entry?.name === 'pnpm'), 0) : 0
119
+ const entry = list[index]
120
+ if (typeof entry?.name === 'string') {
121
+ const onFail = typeof entry.onFail === 'string' ? entry.onFail : Array.isArray(declared) ? (index === list.length - 1 ? 'error' : 'ignore') : undefined
122
+ const version = typeof entry.version === 'string' && validRange(entry.version) !== null ? entry.version : undefined
123
+ return { name: entry.name, version, devEngines: true, onFail }
124
+ }
125
+ if (typeof manifest.packageManager !== 'string') return undefined
126
+ const [, name, version] = /^(@?[^@]*)(?:@(.*))?$/u.exec(manifest.packageManager)
127
+ const exact = version === undefined ? undefined : version.replace(/\+.*$/u, '')
128
+ return { name, version: isExactVersion(exact) && valid(exact) === exact ? exact : undefined, devEngines: false, onFail: undefined }
129
+ }
130
+
131
+ // Whether the root package.json pins a pnpm that `pnpm` is, which makes
132
+ // pnpm 12 fail on a setting it does not know.
133
+ export function pinsPnpm(manifest, pnpm) {
134
+ const wanted = wantedPackageManager(manifest)
135
+ return wanted?.name === 'pnpm' && wanted.version !== undefined && satisfies(pnpm, wanted.version, { includePrerelease: true })
136
+ }
137
+
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.
141
+ function checkPackageManager12(manifest, host, pmOnFail, env) {
142
+ const wanted = wantedPackageManager(manifest)
143
+ if (wanted === undefined) return
144
+ const where = `manifests["."].${wanted.devEngines ? 'devEngines.packageManager' : 'packageManager'}`
145
+ const onFail = pmOnFail ?? wanted.onFail ?? 'download'
146
+ if (onFail === 'ignore' || (onFail === 'warn' && wanted.name !== 'pnpm')) return
147
+ if (wanted.name !== 'pnpm') throw new DeptreeError(`the project is installed by ${quote(wanted.name)}, which pnpm 12 refuses`, where)
148
+ if (wanted.version === undefined) throw new DeptreeError('it names no version of pnpm, or none pnpm takes, which is not supported', where)
149
+ const running = satisfies(host.pnpm, wanted.version, { includePrerelease: true })
150
+ if (!running && onFail !== 'warn') throw new DeptreeError(`pnpm ${host.pnpm} is not in ${quote(wanted.version)}, which pnpm 12 switches from or refuses`, where)
151
+ if (!wanted.devEngines && Number(wanted.version.split('.')[0]) < 12) return
152
+ const version = isExactVersion(wanted.version) ? wanted.version : running ? host.pnpm : undefined
153
+ if (version === undefined) return
154
+ const recorded = env?.importers['.'].packageManagerDependencies ?? {}
155
+ const here = 'env.importers["."].packageManagerDependencies'
156
+ if (recorded.pnpm === undefined) throw new DeptreeError(`the lockfile records no pnpm for ${where}, which a frozen install of pnpm 12 fails on`, here)
157
+ for (const [name, key] of Object.entries(recorded)) {
158
+ if (key !== `${name}@${version}`) throw new DeptreeError(`${quote(key)} is not ${name} ${version}, which pnpm 12 would run or fail on`, `${here}.${name}`)
159
+ if (env.packages[key] === undefined) throw new DeptreeError(`the lockfile records no package ${quote(key)}, which a frozen install of pnpm 12 fails on`, `${here}.${name}`)
160
+ }
161
+ }
162
+
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)
194
+ if (host.major >= 12) return checkPackageManager12(manifest, host, pmOnFail, env)
158
195
  const { packageManager } = manifest
159
196
  if (host.major >= 11) {
160
197
  const where = 'manifests["."].devEngines.packageManager'
@@ -165,32 +202,33 @@ function checkPackageManager(manifest, host, pmOnFail) {
165
202
  }
166
203
  if (packageManager === undefined) return
167
204
  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)
205
+ const version = pinnedPnpm(packageManager)
206
+ if (version === undefined) throw new DeptreeError(`${quote(String(packageManager))} is not pnpm at an exact version`, where)
170
207
  if (version !== host.pnpm) throw new DeptreeError(`the project is installed by pnpm ${version}, which pnpm switches to, not ${host.pnpm}`, where)
171
208
  }
172
209
 
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.
210
+ // A runtime pnpm would download as a dependency is refused, as the lockfile
211
+ // reader refuses a `runtime:` one.
177
212
  const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
178
- function checkRuntimes(manifest, where, { host, onFail }) {
213
+ const RUNTIME_NAMES = ['node', 'deno', 'bun']
214
+ function checkRuntimes(manifest, where, { host, root, onFail }) {
215
+ // pnpm 9 knows no runtime.
216
+ if (host.major < 10) return
179
217
  const checked = new Set()
180
218
  for (const [field, kind] of RUNTIMES) {
181
219
  const runtime = manifest[field]?.runtime
182
- if (runtime === undefined || runtime === null) continue
220
+ if (runtime == null) continue
183
221
  const here = `${where}.${field}.runtime`
184
222
  const runtimes = Array.isArray(runtime) ? runtime : [runtime]
185
- for (const name of ['node', 'deno', 'bun']) {
223
+ for (const name of RUNTIME_NAMES) {
186
224
  if (manifest[kind]?.[name]) continue
187
225
  const item = runtimes.find((each) => each?.name === name)
188
226
  if (item !== undefined && (onFail ?? item.onFail) === 'download') throw new DeptreeError(`a ${name} runtime to download is not supported`, here)
189
227
  }
190
- if (host.major < 11 || where !== 'manifests["."]') continue
228
+ if (host.major < 11 || !root) continue
191
229
  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
230
  for (const item of runtimes) {
193
- if (!['node', 'deno', 'bun'].includes(item.name) || checked.has(item.name)) continue
231
+ if (!RUNTIME_NAMES.includes(item.name) || checked.has(item.name)) continue
194
232
  checked.add(item.name)
195
233
  if ((onFail ?? item.onFail) !== 'error') continue
196
234
  if (item.name !== 'node') throw new DeptreeError(`the ${item.name} it runs on is checked by pnpm 11, and is not known here`, here)
@@ -200,29 +238,40 @@ function checkRuntimes(manifest, where, { host, onFail }) {
200
238
  }
201
239
  }
202
240
 
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)
241
+ // pnpm 12 counts no ignored optional dependency, nor any peer.
242
+ function dependsOn(manifest, ignored) {
243
+ const names = (deps) => (deps !== null && typeof deps === 'object' ? Object.keys(deps) : [])
244
+ const optional = new Set(names(manifest.optionalDependencies).filter((name) => ignored(name)))
245
+ return names(manifest.devDependencies).length > 0 || [...names(manifest.dependencies), ...names(manifest.optionalDependencies)].some((name) => !optional.has(name))
246
+ }
247
+
248
+ export function checkProjects(lockfile, manifests, { hook, host, settings, env }) {
249
+ checkPackageManager(manifests.get('.'), host, settings, env)
250
+ const ignored = createMatcher(settings.ignoredOptionalDependencies ?? [])
251
+ let index
207
252
  for (const [id, manifest] of manifests) {
208
253
  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 })
254
+ const root = id === '.'
255
+ checkProject(manifest, where, { host, settings, root })
256
+ checkRuntimes(manifest, where, { host, root, onFail: root ? settings.runtimeOnFail : undefined })
212
257
  const importer = lockfile.importers[id]
258
+ if (host.major >= 12 && importer.made) {
259
+ if (dependsOn(manifest, ignored)) throw new DeptreeError('the lockfile has no importer for this project, which has dependencies, and pnpm 12 refuses it', where)
260
+ continue
261
+ }
262
+ const hooked = hook(manifest, where, { dir: id })
213
263
  const reason = mismatch(importer, hooked, settings.autoInstallPeers, host.major, where)
214
264
  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
265
  checkLinkTargets({ id, manifest: hooked, importer }, where)
216
- if (host.major < 11) continue
266
+ if (host.major !== 11) continue
217
267
  checkCatalogResolutions(importer, lockfile.catalogs, where)
218
- checkLinkedPackages({ manifest: hooked, importer, projects: manifests, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
268
+ index ??= indexProjects(manifests)
269
+ checkLinkedPackages({ manifest: hooked, importer, index, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
219
270
  }
220
271
  }
221
272
 
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.
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.
226
275
  export function workspaceNames(manifests) {
227
276
  const names = new Map()
228
277
  const taken = new Set()