@preventive/deptree 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/bin/compare.js +5 -2
  2. package/bin/deptree.js +66 -19
  3. package/cocoapods.d.ts +372 -0
  4. package/cocoapods.js +6 -0
  5. package/package.json +23 -5
  6. package/pnpm.d.ts +52 -75
  7. package/soldeer.d.ts +6 -3
  8. package/src/cargo/members.js +3 -2
  9. package/src/cargo/tree.js +2 -2
  10. package/src/cargo/workspace.js +3 -6
  11. package/src/cocoapods/archive.js +223 -0
  12. package/src/cocoapods/clean.js +186 -0
  13. package/src/cocoapods/fnmatch.js +198 -0
  14. package/src/cocoapods/inputs.js +80 -0
  15. package/src/cocoapods/install.js +61 -0
  16. package/src/cocoapods/podspec.js +203 -0
  17. package/src/cocoapods/podtree.js +131 -0
  18. package/src/cocoapods/source.js +90 -0
  19. package/src/cocoapods/tree.js +184 -0
  20. package/src/cocoapods/unicode.js +17 -0
  21. package/src/github.js +92 -0
  22. package/src/glob.js +2 -1
  23. package/src/hash.js +1 -34
  24. package/src/matcher.js +2 -4
  25. package/src/mount.js +2 -5
  26. package/src/npm/compat.js +3 -4
  27. package/src/npm/manifests.js +1 -1
  28. package/src/npm/tree.js +9 -8
  29. package/src/patch.js +9 -5
  30. package/src/pnpm/bins.js +12 -11
  31. package/src/pnpm/commands.js +5 -15
  32. package/src/pnpm/directories.js +250 -0
  33. package/src/pnpm/extensions.js +76 -0
  34. package/src/pnpm/filename.js +4 -4
  35. package/src/pnpm/frozen.js +3 -2
  36. package/src/pnpm/glob.js +1 -1
  37. package/src/pnpm/graph.js +7 -9
  38. package/src/pnpm/hoist.js +0 -36
  39. package/src/pnpm/hoisted.js +3 -3
  40. package/src/pnpm/hook.js +13 -21
  41. package/src/pnpm/inputs.js +7 -16
  42. package/src/pnpm/install.js +3 -4
  43. package/src/pnpm/lazy.js +18 -18
  44. package/src/pnpm/local.js +29 -15
  45. package/src/pnpm/minimatch.js +2 -2
  46. package/src/pnpm/nm-hoist.js +1 -1
  47. package/src/pnpm/npm-packlist.js +1 -1
  48. package/src/pnpm/overrides.js +3 -4
  49. package/src/pnpm/package.js +17 -9
  50. package/src/pnpm/packlist.js +1 -2
  51. package/src/pnpm/patches.js +15 -13
  52. package/src/pnpm/production.js +1 -1
  53. package/src/pnpm/projects.js +14 -40
  54. package/src/pnpm/readers.js +6 -29
  55. package/src/pnpm/settings.js +14 -37
  56. package/src/pnpm/tree.js +34 -24
  57. package/src/pnpm/uptodate.js +12 -13
  58. package/src/pnpm/workspace.js +8 -79
  59. package/src/soldeer/tree.js +2 -2
  60. package/src/soldeer/zip.js +11 -42
  61. package/src/tarball.js +1 -3
  62. package/src/yarn1/hoist.js +4 -2
  63. package/src/yarn1/manifest.js +3 -2
  64. package/src/yarn1/requests.js +1 -1
  65. package/src/yarn1/resolve.js +16 -6
  66. package/src/yarn1/tree.js +12 -8
  67. package/src/soldeer/git.js +0 -67
@@ -1,4 +1,4 @@
1
- // Which snapshots a frozen install leaves out. pnpm 9 and 10 walk depth first
1
+ // Which snapshots a frozen install leaves out. pnpm 10 walks depth first
2
2
  // (@pnpm/lockfile.filtering's pkgAllDeps) and leave out an optional one the
3
3
  // host cannot run or first reached through one not installed: the first
4
4
  // reach decides. Projects go in lockfile order, pnpm's being the order it
@@ -87,15 +87,14 @@ function checkRoot12(manifest, where, context) {
87
87
  }
88
88
 
89
89
  // As pnpm's packageIsInstallable: a platform the host is not only warns, and
90
- // is found first, so the engines are then not checked. pnpm 9 holds it to the
91
- // host alone, before it reads supportedArchitectures.
90
+ // is found first, so the engines are then not checked.
92
91
  export function checkProject(manifest, where, { host, settings, root }) {
93
92
  if (host.major >= 12) {
94
93
  if (root) checkRoot12(manifest, where, { host, settings })
95
94
  return
96
95
  }
97
96
  const platform = { os: platformList(manifest.os, `${where}.os`), cpu: platformList(manifest.cpu, `${where}.cpu`), libc: platformList(manifest.libc, `${where}.libc`) }
98
- if (!takesPlatform(platform, host, host.major < 10 ? undefined : settings.supportedArchitectures)) return
97
+ if (!takesPlatform(platform, host, settings.supportedArchitectures)) return
99
98
  const { engines } = manifest
100
99
  if (engines == null) return
101
100
  const node = nodeOf({ host, settings })
package/src/pnpm/lazy.js CHANGED
@@ -17,7 +17,7 @@ import { compose, writeNode } from './write.js'
17
17
  // build pass builds it (`builds`), patched or with an install script, which
18
18
  // turns on its other copies and what else is built; or which of its bins pnpm
19
19
  // links could change them, one linked being fixed otherwise than it is, made
20
- // executable or its CRLF `#!` line made LF; or pnpm 9 and 12 fail on one that
20
+ // executable or its CRLF `#!` line made LF; or pnpm 12 fails on one that
21
21
  // is a directory; or the package is patched, which is held to its bins as
22
22
  // linked; or its commands cannot be read alone. Else its files are as fetched
23
23
  // and patched, whatever pnpm links of its bins, and of anything else's.
@@ -31,13 +31,10 @@ function bound(node, major, builds) {
31
31
  }
32
32
  if (bins.size === 0) return false
33
33
  if (node.pkg.patchHash !== undefined) return true
34
- for (const path of bins.keys()) {
35
- if (failsAsDirectory(node, path, major)) return true
34
+ return bins.keys().some((path) => {
36
35
  const file = node.files.get(path)
37
- if (file?.data === undefined) continue
38
- if (fixChanges(file, major)) return true
39
- }
40
- return false
36
+ return failsAsDirectory(node, path, major) || (file?.data !== undefined && fixChanges(file, major))
37
+ })
41
38
  }
42
39
 
43
40
  // What an unpacked package's files were, read back from the tree, which holds
@@ -76,21 +73,24 @@ export async function lazyUnpacker({ vfs, byDir, stats, fixes, reads, builds, ea
76
73
  const fetched = new Map()
77
74
  const counted = new Set()
78
75
  const left = new Map()
79
- for (const node of byDir.values()) left.set(packageKeyOf(node.key), (left.get(packageKeyOf(node.key)) ?? 0) + 1)
76
+ for (const node of byDir.values()) {
77
+ const id = packageKeyOf(node.key)
78
+ left.set(id, (left.get(id) ?? 0) + 1)
79
+ }
80
80
  let made
81
81
 
82
82
  const fetchOnce = (node) => {
83
83
  const id = packageKeyOf(node.key)
84
- if (!fetched.has(id)) {
85
- fetched.set(id, limit(() => fetchPackage(node.pkg, quote(id), major, fetching)).then((got) => {
86
- counted.add(id)
87
- stats.tarballs = counted.size
88
- return got
89
- }, (error) => {
90
- throw refusalOf(error, quote(id))
91
- }))
92
- }
93
- return fetched.get(id)
84
+ if (fetched.has(id)) return fetched.get(id)
85
+ const promise = limit(() => fetchPackage(node.pkg, quote(id), major, fetching)).then((got) => {
86
+ counted.add(id)
87
+ stats.tarballs = counted.size
88
+ return got
89
+ }, (error) => {
90
+ throw refusalOf(error, quote(id))
91
+ })
92
+ fetched.set(id, promise)
93
+ return promise
94
94
  }
95
95
  // A directory's files are read with the tree.
96
96
  const prepare = async (node) => {
package/src/pnpm/local.js CHANGED
@@ -2,16 +2,17 @@
2
2
  // project given. Each must hold a package.json, whose bins take their names as
3
3
  // pnpm links them.
4
4
 
5
- import { satisfies, valid, validRange } from '@preventive/upstream/semver.js'
5
+ import { compareVersions, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
6
6
  import { DeptreeError, difference, quote } from '../error.js'
7
7
  import { readManifest } from '../manifest.js'
8
8
  import { readText, typeOf } from '../project.js'
9
+ import { extensionsOf } from './extensions.js'
9
10
  import { parseSpec } from './frozen.js'
10
11
  import { localOf } from './overrides.js'
11
12
  import { checkManifest } from './package.js'
12
13
  import { packDirectory } from './packlist.js'
13
14
 
14
- function manifestAt(project, dir, where) {
15
+ export function manifestAt(project, dir, where) {
15
16
  const text = readText(project, `/${dir}/package.json`, where)
16
17
  if (text === undefined) throw new DeptreeError(`${quote(dir)} ${typeOf(project, `/${dir}`) === undefined ? 'is not in' : 'holds no package.json in'} the project given`, where)
17
18
  return readManifest(text, where)
@@ -73,18 +74,23 @@ function resolvesTo(name, spec, target, packages) {
73
74
  return validRange(range) === null || version === null || satisfies(version, range)
74
75
  }
75
76
 
77
+ const partition = (items, test) => [items.filter(test), items.filter((item) => !test(item))]
76
78
  const optionalPeers = (meta) => Object.entries(meta ?? {}).filter(([, item]) => item?.optional === true).map(([name]) => name).sort()
77
79
 
78
- // `read` is the hooked package.json. A peer may be among the snapshot's
79
- // dependencies and an optional one missing; a `file:` or `link:` one is left to
80
- // package.js's checkDependencies.
81
- function checkFresh(read, pkg, packages, where) {
80
+ // `read` is the hooked package.json. A peer only in peerDependenciesMeta is one
81
+ // at `*`, and an optional peer may be among the optional dependencies too; one
82
+ // in both lists is optional, at the dependency's range.
83
+ function checkFresh(read, pkg, { packages, autoInstallPeers }, where) {
82
84
  const outdated = (why) => new DeptreeError(`the lockfile is not up to date with its package.json, which a frozen install of pnpm 12 refuses: ${why}`, where)
83
- const wanted = { dependencies: read.dependencies ?? {}, optionalDependencies: read.optionalDependencies ?? {} }
84
- const peers = read.peerDependencies ?? {}
85
- for (const [kind, others] of [['dependencies', peers], ['optionalDependencies', {}]]) {
85
+ const optional = read.optionalDependencies ?? {}
86
+ const [both, deps] = partition(Object.entries(read.dependencies ?? {}), ([name]) => Object.hasOwn(optional, name))
87
+ const wanted = { dependencies: Object.fromEntries(deps), optionalDependencies: { ...optional, ...Object.fromEntries(both) } }
88
+ const optionalNames = optionalPeers(read.peerDependenciesMeta)
89
+ const peers = { ...Object.fromEntries(optionalNames.map((name) => [name, '*'])), ...read.peerDependencies }
90
+ const others = { dependencies: read.peerDependencies ?? {}, optionalDependencies: Object.fromEntries(optionalNames.map((name) => [name, peers[name]])) }
91
+ for (const kind of ['dependencies', 'optionalDependencies']) {
86
92
  for (const name of Object.keys(pkg[kind])) {
87
- if (!Object.hasOwn(wanted[kind], name) && !Object.hasOwn(others, name)) throw outdated(`${kind}.${name} is not one it asks for`)
93
+ if (!Object.hasOwn(wanted[kind], name) && !Object.hasOwn(others[kind], name)) throw outdated(`${kind}.${name} is not one it asks for`)
88
94
  }
89
95
  for (const [name, spec] of Object.entries(wanted[kind])) {
90
96
  const target = pkg[kind][name]
@@ -97,15 +103,20 @@ function checkFresh(read, pkg, packages, where) {
97
103
  if (localOf(spec, where) !== undefined || !resolvesTo(name, spec, target, packages)) throw outdated(`${kind}.${name} is not resolved as it asks`)
98
104
  }
99
105
  }
100
- const peersDiffer = difference(peers, pkg.peerDependencies, ['its package.json', 'the lockfile'])
106
+ // A peer that is its own dependency too may go unrecorded, but where pnpm installs it.
107
+ const unrecorded = (name) => !Object.hasOwn(pkg.peerDependencies, name) && Object.hasOwn(read.dependencies ?? {}, name) && !(autoInstallPeers && !optionalNames.includes(name))
108
+ const recorded = Object.fromEntries(Object.entries(peers).filter(([name]) => !unrecorded(name)))
109
+ const peersDiffer = difference(recorded, pkg.peerDependencies, ['its package.json', 'the lockfile'])
101
110
  if (peersDiffer !== undefined) throw outdated(`its peerDependencies are not the lockfile's: ${peersDiffer}`)
102
- if (JSON.stringify(optionalPeers(read.peerDependenciesMeta)) !== JSON.stringify(optionalPeers(pkg.peerDependenciesMeta))) throw outdated('which of its peers are optional is not the lockfile\'s')
111
+ if (JSON.stringify(optionalNames.filter((name) => Object.hasOwn(recorded, name))) !== JSON.stringify(optionalPeers(pkg.peerDependenciesMeta))) throw outdated('which of its peers are optional is not the lockfile\'s')
103
112
  }
104
113
 
105
114
  // pnpm 12's check, before it installs, of each snapshot a project depends on by
106
- // a `file:` specifier to a directory.
107
- export function createFreshnessCheck(lockfile, major) {
115
+ // a `file:` specifier to a directory. Before 12.17.0 it reads the package.json
116
+ // without its extensions, refusing the lockfile it wrote of one extended.
117
+ export function createFreshnessCheck(lockfile, { pnpm, major }, extensions = [], autoInstallPeers = true) {
108
118
  if (major < 12) return undefined
119
+ const unextended = compareVersions(pnpm, '12.17.0') < 0
109
120
  const direct = new Set()
110
121
  for (const importer of Object.values(lockfile.importers)) {
111
122
  for (const [name, target] of Object.entries({ ...importer.dependencies, ...importer.devDependencies, ...importer.optionalDependencies })) {
@@ -115,6 +126,9 @@ export function createFreshnessCheck(lockfile, major) {
115
126
  }
116
127
  }
117
128
  return (node, read) => {
118
- if (direct.has(node.key)) checkFresh(read, lockfile.packages[node.key], lockfile.packages, quote(node.key))
129
+ if (!direct.has(node.key)) return
130
+ const where = quote(node.key)
131
+ if (unextended && extensionsOf(extensions, read, where).length > 0) throw new DeptreeError('a package extension names it, and pnpm 12 before 12.17.0 holds a directory to its package.json without one, which is not supported', where)
132
+ checkFresh(read, lockfile.packages[node.key], { packages: lockfile.packages, autoInstallPeers }, where)
119
133
  }
120
134
  }
@@ -1,6 +1,6 @@
1
1
  // minimatch as npm-packlist runs it, with matchBase, dot, flipNegate and
2
2
  // nocase, of patterns whose only glob syntax is `*`, `?` and `**`: 5.1.6 for
3
- // pnpm 9 and for 10 before 10.31, 5.1.9 for 10 from 10.31, which matches
3
+ // pnpm 10 before 10.31, 5.1.9 from 10.31, which matches
4
4
  // `**` by other steps, and 10.2 for pnpm 11. Its regexps have no `u`, as
5
5
  // minimatch's have none: they take UTF-16 code units, and fold case as such
6
6
  // a regexp folds it.
@@ -22,7 +22,7 @@ export function checkGlob(body, where, { parent = false } = {}) {
22
22
  }
23
23
 
24
24
  // A longer pattern minimatch may make too large a regexp of for V8, which
25
- // pnpm 9, 10 and 11 then fail on, and globset one, which pnpm 12 then drops
25
+ // pnpm 10 and 11 then fail on, and globset one, which pnpm 12 then drops
26
26
  // with the rest of its file; none does below several times this.
27
27
  const MAX_LENGTH = 4096
28
28
 
@@ -1,4 +1,4 @@
1
- // The hoist of @yarnpkg/nm 4.0.5, which pnpm 9 and 10 bundle for the hoisted
1
+ // The hoist of @yarnpkg/nm 4.0.5, which pnpm 10 bundles for the hoisted
2
2
  // linker: each package is moved as near the root as it can go without
3
3
  // shadowing a different one of its name for a package that needs that one.
4
4
  // Step for step as it runs, with its recursions on stacks of their own, and
@@ -1,4 +1,4 @@
1
- // The walks of npm-packlist over ignore-walk that pnpm 9 and 10 (npm-packlist
1
+ // The walks of npm-packlist over ignore-walk that pnpm 10 (npm-packlist
2
2
  // 5.1.3, ignore-walk 5) and pnpm 11 (npm-packlist 10.0.4, ignore-walk 8)
3
3
  // run over a directory, kept to their steps, odd ones and all: a walker of a
4
4
  // directory asks its parent of each entry by a path from there, and reads
@@ -12,14 +12,14 @@ import { own } from '../manifest.js'
12
12
  const SCOPED = /^(?:@([^/]+?)\/)?([^/]+?)$/u
13
13
  export function validForOldPackages(name) {
14
14
  if (name === '' || name.startsWith('.') || name.startsWith('_') || name.trim() !== name) return false
15
- if (name.toLowerCase() === 'node_modules' || name.toLowerCase() === 'favicon.ico') return false
15
+ if (['node_modules', 'favicon.ico'].includes(name.toLowerCase())) return false
16
16
  if (encodeURIComponent(name) === name) return true
17
17
  const m = SCOPED.exec(name)
18
18
  return m !== null && encodeURIComponent(m[1]) === m[1] && encodeURIComponent(m[2]) === m[2]
19
19
  }
20
20
 
21
21
  // @pnpm/parse-wanted-dependency.
22
- function parseWanted(raw) {
22
+ export function parseWanted(raw) {
23
23
  const at = raw.indexOf('@', 1)
24
24
  const name = at === -1 ? raw : raw.slice(0, at)
25
25
  return validForOldPackages(name) ? { name, range: at === -1 ? undefined : raw.slice(at + 1) } : undefined
@@ -29,9 +29,8 @@ function parseWanted(raw) {
29
29
  const DELIMITER = /[^ @|]>/u
30
30
 
31
31
  export function parseSelector(selector, where) {
32
- if (!selector.isWellFormed()) throw new DeptreeError(`pnpm cannot parse the selector ${quote(selector)}`, where)
33
32
  const split = selector.search(DELIMITER)
34
- const parsed = (split === -1 ? [selector] : [selector.slice(0, split + 1), selector.slice(split + 2)]).map(parseWanted)
33
+ const parsed = selector.isWellFormed() ? (split === -1 ? [selector] : [selector.slice(0, split + 1), selector.slice(split + 2)]).map(parseWanted) : [undefined]
35
34
  if (parsed.includes(undefined)) throw new DeptreeError(`pnpm cannot parse the selector ${quote(selector)}`, where)
36
35
  return parsed.length === 1 ? { target: parsed[0] } : { parent: parsed[0], target: parsed[1] }
37
36
  }
@@ -4,6 +4,7 @@
4
4
  // find it wherever it is hoisted, if anywhere.
5
5
 
6
6
  import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
7
+ import { compareVersions } from '@preventive/upstream/semver.js'
7
8
  import { normalize } from '@preventive/vfs/path.js'
8
9
  import { DeptreeError, quote } from '../error.js'
9
10
  import { checkNesting } from '../manifest.js'
@@ -18,7 +19,7 @@ function nameOf(stored) {
18
19
  return name.replaceAll('//', '/')
19
20
  }
20
21
 
21
- // pnpm 9, 10 and 11 drop a name's first segment at a `\` as at a `/` where the
22
+ // pnpm 10 and 11 drop a name's first segment at a `\` as at a `/` where the
22
23
  // ustar header holds the name, and pnpm 10 and 11, where a name has a `.\`,
23
24
  // turn each `\` into a `/` before normalizing it; pnpm 12 takes every `\` for
24
25
  // a separator, and fails on a `..` that makes.
@@ -32,9 +33,7 @@ function filesOf(entries, where) {
32
33
  tops.add(entry.storedName.slice(0, Math.max(entry.storedName.indexOf('/'), 0)))
33
34
  if (tops.size > 1 || tops.has('')) throw new DeptreeError('the tarball has files under more than one directory, or at its top', where)
34
35
  const name = nameOf(entry.storedName)
35
- if (!isInside(name)) {
36
- throw new DeptreeError(`${quote(entry.storedName)} names no file in the package`, where)
37
- }
36
+ if (!isInside(name)) throw new DeptreeError(`${quote(entry.storedName)} names no file in the package`, where)
38
37
  const file = { data: entry.data, mode: (entry.mode & 0o111) === 0 ? 0o644 : 0o755 }
39
38
  const earlier = files.get(name)
40
39
  if (earlier !== undefined && !sameFile(earlier, file)) throw new DeptreeError(`${quote(name)} is in the tarball twice`, where)
@@ -77,7 +76,7 @@ function readManifest(files, pkg, where) {
77
76
 
78
77
  // npm's abbreviated metadata, which pnpm resolves from unless a setting such
79
78
  // as supportedArchitectures.libc has it ask for the full document, has no
80
- // libc, nor has the package.json pnpm 9 and 10 keep in the store: a lockfile
79
+ // libc, nor has the package.json pnpm 10 keeps in the store: a lockfile
81
80
  // may leave out a libc a registry package's package.json has. One it names is
82
81
  // held to it, as a directory's always is: pnpm reads that package.json whole.
83
82
  export function checkManifest(manifest, pkg, where, major, registry = false) {
@@ -97,12 +96,21 @@ const bundledOf = (manifest) => manifest.bundleDependencies ?? manifest.bundledD
97
96
  // and npm publishes none.
98
97
  const listed = (bundled) => (bundled === false || (Array.isArray(bundled) && bundled.length === 0) ? undefined : bundled)
99
98
 
99
+ // Whether pnpm may leave a dependency out of a snapshot: one its package.json
100
+ // also has as an optional peer, before 11.28.0 where it installs peers by
101
+ // itself, and until 11.28.6 and 12.14.0 in some graphs.
102
+ export function createPeerDrop({ pnpm, major }, autoInstallPeers) {
103
+ const since = (version) => compareVersions(pnpm, version) >= 0
104
+ const drops = major >= 12 ? !since('12.14.0') : !since('11.28.6') && (autoInstallPeers || since('11.28.0'))
105
+ return (read, name) => drops && Object.hasOwn(read.peerDependencies ?? {}, name) && read.peerDependenciesMeta?.[name]?.optional === true
106
+ }
107
+
100
108
  // `read` is the package.json as hook.js's hook has it, and `packages` the
101
109
  // lockfile's, by which a `file:` target is the directory it resolves to.
102
- function checkDependencies(manifest, read, pkg, packages, where) {
110
+ function checkDependencies(manifest, read, pkg, packages, where, drops) {
103
111
  const bundled = bundledOf(manifest)
104
112
  const given = new Set([...names(pkg.dependencies), ...names(pkg.optionalDependencies)])
105
- for (const name of [...names(read.dependencies), ...names(read.optionalDependencies)]) {
113
+ for (const name of [...names(read.dependencies).filter((dependency) => !drops(read, dependency)), ...names(read.optionalDependencies)]) {
106
114
  if (bundled === true || (Array.isArray(bundled) && bundled.includes(name)) || given.has(name)) continue
107
115
  throw new DeptreeError(`package.json asks for ${quote(name)}, which the lockfile does not give it`, where)
108
116
  }
@@ -124,10 +132,10 @@ function checkDependencies(manifest, read, pkg, packages, where) {
124
132
  // What is held of a package's files once fetched, for one of its snapshots:
125
133
  // its package.json, as the hook has it, asks for what the snapshot gives it,
126
134
  // as `lockfile` has it, though the tree has fewer of its edges.
127
- export function checkFetched(node, got, { lockfile, hook, fresh }) {
135
+ export function checkFetched(node, got, { lockfile, hook, fresh, drops }) {
128
136
  if (got.manifest === undefined) return
129
137
  got.read ??= hook(got.manifest, `${quote(packageKeyOf(node.key))}: package.json`)
130
- checkDependencies(got.manifest, got.read, lockfile.packages[node.key], lockfile.packages, quote(node.key))
138
+ checkDependencies(got.manifest, got.read, lockfile.packages[node.key], lockfile.packages, quote(node.key), drops)
131
139
  fresh?.(node, got.read)
132
140
  }
133
141
 
@@ -1,5 +1,5 @@
1
1
  // The files pnpm's directory fetcher installs of a `file:` dependency, as its
2
- // packlist picks them: npm-packlist 5.1.3 for pnpm 9 and 10, 10.0.4 for pnpm
2
+ // packlist picks them: npm-packlist 5.1.3 for pnpm 10, 10.0.4 for pnpm
3
3
  // 11, and pnpm 12's own port of it, by package.json's `files`, `main` and
4
4
  // `bin`, the .npmignore and .gitignore files where they read them, and their
5
5
  // own rules. Of glob syntax only `*`, `?` and `**` are followed, which they
@@ -14,7 +14,6 @@ import { readBytes } from '../project.js'
14
14
  import { bytesOf, gitignoreGlob, matched, matchedOrParents } from './gitignore.js'
15
15
  import { pack10, pack11 } from './npm-packlist.js'
16
16
 
17
-
18
17
  const MODES = new Set([0o644, 0o664, 0o755, 0o775])
19
18
 
20
19
  // How deep a directory is walked: each entry is matched against the rules
@@ -1,8 +1,7 @@
1
1
  // pnpm 10 applies the patch patchedDependencies picks for a package's name and
2
2
  // version (@pnpm/patching.config's getPatchInfo), not the one its snapshot key
3
3
  // names, so every snapshot must name that pick's hash. Every patch must be some
4
- // snapshot's, which pnpm checks only when resolving. pnpm 9 picks by the
5
- // selector `name@version` as spelled, else `name`, and takes no range.
4
+ // snapshot's, which pnpm checks only when resolving.
6
5
 
7
6
  import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
8
7
  import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
@@ -26,11 +25,17 @@ function group(selectors) {
26
25
  }
27
26
  for (const selector of selectors) {
28
27
  const { name, version, range } = parseSelector(selector)
29
- if (version !== undefined) of(name).exact.set(version, selector)
30
- else if (range === undefined) of(selector).all = selector
31
- else if (validRange(range) === null) throw new DeptreeError(`${quote(range)} is not a version range, which pnpm refuses`, `patchedDependencies[${quote(selector)}]`)
32
- else if (range.trim() === '*') of(name).all = selector
33
- else of(name).ranges.push({ range, selector })
28
+ if (version !== undefined) {
29
+ of(name).exact.set(version, selector)
30
+ } else if (range === undefined) {
31
+ of(selector).all = selector
32
+ } else if (validRange(range) === null) {
33
+ throw new DeptreeError(`${quote(range)} is not a version range, which pnpm refuses`, `patchedDependencies[${quote(selector)}]`)
34
+ } else if (range.trim() === '*') {
35
+ of(name).all = selector
36
+ } else {
37
+ of(name).ranges.push({ range, selector })
38
+ }
34
39
  }
35
40
  return groups
36
41
  }
@@ -44,14 +49,11 @@ function pick(groups, name, version, where) {
44
49
  return taking[0]?.selector ?? found.all
45
50
  }
46
51
 
47
- // pnpm 9's getPatchInfo.
48
- const pick9 = (hashes, name, version) => [`${name}@${version}`, name].find((selector) => Object.hasOwn(hashes, selector))
49
-
50
- export function checkPatchUse(lockfile, hashes, major = 10) {
51
- const groups = major < 10 ? undefined : group(Object.keys(hashes))
52
+ export function checkPatchUse(lockfile, hashes) {
53
+ const groups = group(Object.keys(hashes))
52
54
  const used = new Set()
53
55
  for (const [key, pkg] of Object.entries(lockfile.packages)) {
54
- const selector = major < 10 ? pick9(hashes, pkg.name, pkg.version) : pick(groups, pkg.name, pkg.version, quote(key))
56
+ const selector = pick(groups, pkg.name, pkg.version, quote(key))
55
57
  const wanted = selector === undefined ? undefined : hashes[selector].hash
56
58
  if (wanted !== pkg.patchHash) {
57
59
  throw new DeptreeError(`pnpm applies ${selector === undefined ? 'no patch' : `the patch of ${quote(selector)}`} to it, and the lockfile names ${pkg.patchHash === undefined ? 'none' : `the patch ${pkg.patchHash}`}`, quote(key))
@@ -3,7 +3,7 @@
3
3
  // with devDependencies left out: every project's devDependencies dropped, and
4
4
  // of the snapshots those the rest reach, through dependencies,
5
5
  // optionalDependencies and `link:`s, which lead only to projects, all of them
6
- // installed anyway. The root's specifiers stay, which pnpm 9 hoists by.
6
+ // installed anyway.
7
7
  //
8
8
  // From pnpm 11.28 and 12.8.1 on (@pnpm/lockfile.peer-edges), an edge to an
9
9
  // optional peer that a snapshot has only as the projects that reach it list
@@ -9,6 +9,7 @@ import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstre
9
9
  import { DeptreeError, difference, quote } from '../error.js'
10
10
  import { own, readManifest } from '../manifest.js'
11
11
  import { createMatcher } from '../matcher.js'
12
+ import { extensionsOf } from './extensions.js'
12
13
  import { KINDS, checkCatalogResolutions, checkLinkTargets, checkLinkedPackages, indexProjects, resolvedOf, sameSpecifier } from './frozen.js'
13
14
  import { checkProject } from './install.js'
14
15
  import { validForOldPackages } from './overrides.js'
@@ -50,7 +51,6 @@ function wantedOf(manifest, autoInstallPeers, unresolved) {
50
51
  // it is not set.
51
52
  const metaOf = (meta) => JSON.stringify(Object.entries(meta).map(([name, item]) => [name, item?.injected === true, item?.node]).sort())
52
53
 
53
- // pnpm 9 does not hold what a dependency resolved to to its range.
54
54
  function checkKind(importer, kinds, kind, unresolved, major) {
55
55
  const locked = importer[kind]
56
56
  const wanted = kind === 'devDependencies' ? kinds[kind] : omit(kinds[kind], unresolved)
@@ -61,7 +61,8 @@ function checkKind(importer, kinds, kind, unresolved, major) {
61
61
  for (const name of names) {
62
62
  if (!locked[name] || !sameSpecifier(importer.specifiers[name], wanted[name], major)) return `${kind}.${name} is not what package.json asks for`
63
63
  const spec = importer.specifiers[name]
64
- if (major < 10 || validRange(spec) === null) continue
64
+ // pnpm resolves `*` to a prerelease `latest`, and checks no such range.
65
+ if (validRange(spec) === null || validRange(spec) === '*') continue
65
66
  const version = resolvedOf(name, locked[name])
66
67
  if (valid(version) !== null && !satisfies(version, spec)) return `${kind}.${name} resolved to ${quote(version)}, which is not in ${quote(spec)}`
67
68
  }
@@ -100,8 +101,7 @@ function devEnginesPackageManager(devEngines, where) {
100
101
  const engine = list[Math.max(index, 0)]
101
102
  if (!engine.name) return undefined
102
103
  let { onFail } = engine
103
- if (Array.isArray(engines) && index === -1) onFail = list.at(-1).onFail ?? 'error'
104
- else if (Array.isArray(engines)) onFail ??= index === list.length - 1 ? 'error' : 'ignore'
104
+ if (Array.isArray(engines)) onFail = index === -1 ? list.at(-1).onFail ?? 'error' : onFail ?? (index === list.length - 1 ? 'error' : 'ignore')
105
105
  return { name: engine.name, onFail }
106
106
  }
107
107
 
@@ -160,37 +160,8 @@ function checkPackageManager12(manifest, host, pmOnFail, env) {
160
160
  }
161
161
  }
162
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
163
  function checkPackageManager(manifest, host, settings, env) {
192
164
  const { pmOnFail } = settings
193
- if (host.major < 10) return checkPackageManager9(manifest, host, settings.packageManagerChecks)
194
165
  if (host.major >= 12) return checkPackageManager12(manifest, host, pmOnFail, env)
195
166
  const { packageManager } = manifest
196
167
  if (host.major >= 11) {
@@ -212,8 +183,6 @@ function checkPackageManager(manifest, host, settings, env) {
212
183
  const RUNTIMES = [['devEngines', 'devDependencies'], ['engines', 'dependencies']]
213
184
  const RUNTIME_NAMES = ['node', 'deno', 'bun']
214
185
  function checkRuntimes(manifest, where, { host, root, onFail }) {
215
- // pnpm 9 knows no runtime.
216
- if (host.major < 10) return
217
186
  const checked = new Set()
218
187
  for (const [field, kind] of RUNTIMES) {
219
188
  const runtime = manifest[field]?.runtime
@@ -245,13 +214,16 @@ function dependsOn(manifest, ignored) {
245
214
  return names(manifest.devDependencies).length > 0 || [...names(manifest.dependencies), ...names(manifest.optionalDependencies)].some((name) => !optional.has(name))
246
215
  }
247
216
 
248
- export function checkProjects(lockfile, manifests, { hook, host, settings, env }) {
217
+ // pnpm extends a project's package.json too, which is refused: not every
218
+ // place one is read in here is read through the hook.
219
+ export function checkProjects(lockfile, manifests, { hook, extensions = [], host, settings, env, directories }) {
249
220
  checkPackageManager(manifests.get('.'), host, settings, env)
250
221
  const ignored = createMatcher(settings.ignoredOptionalDependencies ?? [])
251
222
  let index
252
223
  for (const [id, manifest] of manifests) {
253
224
  const where = `manifests[${quote(id)}]`
254
225
  const root = id === '.'
226
+ if (extensionsOf(extensions, manifest, where).length > 0) throw new DeptreeError('a package extension names this project, whose package.json pnpm extends too, which is not supported', where)
255
227
  checkProject(manifest, where, { host, settings, root })
256
228
  checkRuntimes(manifest, where, { host, root, onFail: root ? settings.runtimeOnFail : undefined })
257
229
  const importer = lockfile.importers[id]
@@ -263,10 +235,12 @@ export function checkProjects(lockfile, manifests, { hook, host, settings, env }
263
235
  const reason = mismatch(importer, hooked, settings.autoInstallPeers, host.major, where)
264
236
  if (reason !== undefined) throw new DeptreeError(`the lockfile is not up to date with this package.json, which a frozen install refuses: ${reason}`, where)
265
237
  checkLinkTargets({ id, manifest: hooked, importer }, where)
266
- if (host.major !== 11) continue
267
- checkCatalogResolutions(importer, lockfile.catalogs, where)
268
- index ??= indexProjects(manifests)
269
- checkLinkedPackages({ manifest: hooked, importer, index, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
238
+ if (host.major === 11) {
239
+ checkCatalogResolutions(importer, lockfile.catalogs, where)
240
+ index ??= indexProjects(manifests)
241
+ checkLinkedPackages({ manifest: hooked, importer, index, linkWorkspacePackages: settings.linkWorkspacePackages }, where)
242
+ }
243
+ directories?.(hooked, importer)
270
244
  }
271
245
  }
272
246
 
@@ -1,6 +1,6 @@
1
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
2
+ // and checked (READ, READ_11, READ_12) or passed over as leaving
3
+ // the tree as it is (IGNORED, IGNORED_11, IGNORED_12); any other is
4
4
  // refused.
5
5
 
6
6
  import { valid } from '@preventive/upstream/semver.js'
@@ -104,9 +104,8 @@ export const READ = {
104
104
  filterProd: { kind: 'texts', check: never('every project is installed') },
105
105
  useNodeVersion: { kind: 'text', check: never('the Node a tree is built for is the host\'s, or nodeVersion') },
106
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).
107
+ // [] loads none, not even the default one. An .npmrc's is passed over: a
108
+ // pnpmfile with hooks puts its pnpmfileChecksum in the lockfile, which is refused (tree.js).
110
109
  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 },
111
110
  registry: { kind: 'text', check: checkRegistry },
112
111
  virtualStoreDirMaxLength: { kind: 'count' },
@@ -192,26 +191,6 @@ const UNRECOGNIZED_12 = new Set([
192
191
 
193
192
  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)
194
193
 
195
- // What pnpm 9 reads that pnpm 10 passes over: how it holds the root
196
- // package.json's packageManager to the pnpm that runs (projects.js).
197
- const READ_9 = {
198
- __proto__: null,
199
- nodeLinker: only('text', 'isolated', 'only the isolated node_modules layout is built for pnpm 9'),
200
- managePackageManagerVersions: { kind: 'boolean' },
201
- packageManagerStrict: { kind: 'boolean' },
202
- packageManagerStrictVersion: { kind: 'boolean' },
203
- }
204
-
205
- // What pnpm 10 reads that pnpm 9 has no setting for, and passes over.
206
- const NOT_9 = new Set(['dedupePeers', 'enableGlobalVirtualStore', 'injectWorkspacePackages'])
207
-
208
- // The keys of package.json's `pnpm` pnpm 9 reads, passing over any other.
209
- export const MANIFEST_KEYS_9 = [
210
- 'allowNonAppliedPatches', 'allowedDeprecatedVersions', 'ignoredOptionalDependencies', 'neverBuiltDependencies',
211
- 'onlyBuiltDependencies', 'onlyBuiltDependenciesFile', 'overrides', 'packageExtensions', 'patchedDependencies',
212
- 'peerDependencyRules', 'supportedArchitectures',
213
- ]
214
-
215
194
  // The keys of package.json's `pnpm` pnpm 10 reads, passing over any other.
216
195
  export const MANIFEST_KEYS = [
217
196
  'allowBuilds', 'allowNonAppliedPatches', 'allowUnusedPatches', 'allowedDeprecatedVersions', 'auditConfig',
@@ -278,11 +257,9 @@ function checkCatalogs(value, where) {
278
257
  for (const [name, catalog] of Object.entries(value)) checkCatalog(readers.mapping(catalog, `${where}.${name}`), `${where}.${name}`)
279
258
  }
280
259
 
281
- // `{}` where a setting leaves the tree as it is or pnpm 9 has no such setting,
282
- // undefined where not known here. pnpm 12 takes a pattern only as a list.
260
+ // `{}` where a setting leaves the tree as it is, undefined where not known
261
+ // here. pnpm 12 takes a pattern only as a list.
283
262
  function lookup(name, major) {
284
- if (major < 10 && name in READ_9) return { read: READ_9[name] }
285
- if (major < 10 && NOT_9.has(name)) return {}
286
263
  if (major >= 12 && UNRECOGNIZED_12.has(name)) return { unrecognized: true }
287
264
  if (major >= 12 && name in READ_12) return { read: READ_12[name] }
288
265
  if (major >= 11 && name in READ_11) return { read: READ_11[name] }