@preventive/deptree 1.0.0-alpha.5 → 1.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/npm.d.ts +288 -0
  3. package/npm.js +7 -0
  4. package/package.json +41 -12
  5. package/pnpm.d.ts +158 -25
  6. package/pnpm.js +2 -10
  7. package/soldeer.d.ts +13 -0
  8. package/soldeer.js +1 -7
  9. package/src/concurrent.js +16 -17
  10. package/src/error.js +5 -9
  11. package/src/glob.js +55 -0
  12. package/src/hash.js +60 -13
  13. package/src/manifest.js +52 -0
  14. package/src/matcher.js +60 -10
  15. package/src/mount.js +104 -44
  16. package/src/npm/bins.js +54 -0
  17. package/src/npm/compat.js +97 -0
  18. package/src/npm/dev-engines.js +52 -0
  19. package/src/npm/graph.js +68 -0
  20. package/src/npm/inputs.js +75 -0
  21. package/src/npm/manifests.js +130 -0
  22. package/src/npm/package.js +57 -0
  23. package/src/npm/ratio.js +34 -0
  24. package/src/npm/settings.js +67 -0
  25. package/src/npm/tree.js +136 -0
  26. package/src/npm/versions.js +20 -0
  27. package/src/npmrc.js +24 -0
  28. package/src/patch.js +22 -41
  29. package/src/pnpm/bins.js +152 -131
  30. package/src/pnpm/checks.js +8 -35
  31. package/src/pnpm/commands.js +53 -96
  32. package/src/pnpm/filename.js +10 -21
  33. package/src/pnpm/frozen.js +29 -75
  34. package/src/pnpm/gitignore.js +139 -0
  35. package/src/pnpm/glob.js +65 -0
  36. package/src/pnpm/graph.js +15 -43
  37. package/src/pnpm/hoist.js +68 -61
  38. package/src/pnpm/hoisted.js +234 -0
  39. package/src/pnpm/hook.js +26 -31
  40. package/src/pnpm/inputs.js +73 -56
  41. package/src/pnpm/install.js +85 -131
  42. package/src/pnpm/local.js +21 -40
  43. package/src/pnpm/minimatch.js +319 -0
  44. package/src/pnpm/nm-hoist-graph.js +299 -0
  45. package/src/pnpm/nm-hoist.js +149 -0
  46. package/src/pnpm/npm-packlist.js +217 -0
  47. package/src/pnpm/overrides.js +11 -51
  48. package/src/pnpm/package.js +121 -0
  49. package/src/pnpm/packlist.js +169 -109
  50. package/src/pnpm/patches.js +18 -25
  51. package/src/pnpm/projects.js +63 -107
  52. package/src/pnpm/readers.js +63 -83
  53. package/src/pnpm/settings.js +64 -100
  54. package/src/pnpm/tree.js +197 -169
  55. package/src/pnpm/uptodate.js +16 -28
  56. package/src/pnpm/workspace.js +124 -133
  57. package/src/project.js +57 -0
  58. package/src/soldeer/config.js +8 -24
  59. package/src/soldeer/inputs.js +5 -15
  60. package/src/soldeer/tree.js +22 -60
  61. package/src/soldeer/zip.js +17 -36
  62. package/src/tarball.js +55 -140
  63. package/src/yarn1/bins.js +9 -19
  64. package/src/yarn1/compat.js +9 -28
  65. package/src/yarn1/hoist.js +53 -68
  66. package/src/yarn1/inputs.js +19 -61
  67. package/src/yarn1/manifest.js +8 -23
  68. package/src/yarn1/package.js +24 -63
  69. package/src/yarn1/peers.js +8 -15
  70. package/src/yarn1/requests.js +19 -37
  71. package/src/yarn1/resolve.js +36 -113
  72. package/src/yarn1/settings.js +15 -43
  73. package/src/yarn1/tree.js +67 -91
  74. package/yarn1.d.ts +34 -5
  75. package/yarn1.js +1 -8
  76. package/src/pnpm/npmrc.js +0 -31
  77. package/src/pnpm/project.js +0 -97
  78. package/src/yarn1/glob.js +0 -52
  79. /package/{LICENSE → LICENSE-MIT} +0 -0
@@ -1,134 +1,194 @@
1
- // The files pnpm installs of a directory a `file:` dependency names: its
2
- // directory fetcher picks them with npm-packlist — 5.1.3 for pnpm 10,
3
- // 10.0.4 for pnpm 11, its own port of it (fs-packlist) for pnpm 12 — and
4
- // hardlinks or copies them into the tree (tree.js). Only the built-in
5
- // rules are followed here. npm-packlist's leave out, by name and whatever
6
- // its case:
7
- //
8
- // - anywhere, `.git`, `.svn`, `.hg`, `CVS`, `.npmrc`, `.DS_Store`,
9
- // `npm-debug.log`, `.npmignore`, `.gitignore`, and a name starting
10
- // with `._`, or `.` and ending in `.swp`, or ending in `.orig`, with
11
- // everything in it;
12
- // - at the top, and with pnpm 11 in every directory, `.lock-wscript`,
13
- // `.wafpickle-*`, `build/config.gypi` and what is in
14
- // `archived-packages`;
15
- // - at the top, `node_modules` and the lockfiles `package-lock.json`,
16
- // `yarn.lock`, `pnpm-lock.yaml` and, with pnpm 11, `bun.lockb`;
17
- //
18
- // and every name with a `*` in it. pnpm 12's leave out, by name as it is
19
- // spelled:
20
- //
21
- // - anywhere, `.git`, `.svn`, `.hg` and `CVS`, with everything in them,
22
- // and a file `.npmrc`, `npm-debug.log`, `.DS_Store`,
23
- // `package-lock.json`, `yarn.lock` or `pnpm-lock.yaml`, or one whose
24
- // name ends in `.orig`;
25
- // - at the top, `node_modules`.
26
- //
27
- // A directory those do not describe is refused: one with a .npmignore
28
- // or .gitignore in it, or a package.json with `files` or bundled
29
- // dependencies, whose rules are not followed here; one with a link in
30
- // it, which the two pass over differently; and one where a file those
31
- // leave out is one npm-packlist would keep, a readme, copying, license or
32
- // licence file, or one `main`, `browser` or `bin` names, as the two keep
33
- // them differently, or, with pnpm 12, one in node_modules that `main` or
34
- // `bin` names, the only file it keeps of those its rules leave out. So is
35
- // a file whose mode is not 0o644 or 0o755, which linking a bin would
36
- // change otherwise than fixBin has it.
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
3
+ // 11, and pnpm 12's own port of it, by package.json's `files`, `main` and
4
+ // `bin`, the .npmignore and .gitignore files where they read them, and their
5
+ // own rules. Of glob syntax only `*`, `?` and `**` are followed, which they
6
+ // all read alike. Refused are a link the walk comes on, which they treat
7
+ // differently, and a mode a checkout does not have under umask 022 or 002.
37
8
 
38
- import { join } from '@preventive/vfs/path.js'
9
+ import { compareVersions, valid } from '@preventive/upstream/semver.js'
10
+ import { normalize } from '@preventive/vfs/path.js'
39
11
  import { DeptreeError, quote } from '../error.js'
40
- import { readBytes } from './project.js'
12
+ import { readBytes } from '../project.js'
13
+ import { bytesOf, gitignoreGlob, matched, matchedOrParents } from './gitignore.js'
14
+ import { pack10, pack11 } from './npm-packlist.js'
41
15
 
42
- // The rules each name is held to, folded, wherever it is.
43
- const ANYWHERE = /^(?:\.git|\.svn|\.hg|cvs|\.npmrc|\.ds_store|npm-debug\.log|\.npmignore|\.gitignore|\._.*|\..*\.swp|.*\.orig)$/u
16
+ const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true })
44
17
 
45
- // The rules held to the path, by its names folded, from the directory they
46
- // are read in: the top for npm-packlist 5, and every directory for
47
- // npm-packlist 10, which reads them again in each.
48
- const anchored = (names, directory) => (names.length === 1 && (names[0] === '.lock-wscript' || names[0].startsWith('.wafpickle-') || (directory && names[0] === 'archived-packages')))
49
- || (names.length === 2 && names[0] === 'build' && names[1] === 'config.gypi')
18
+ const MODES = new Set([0o644, 0o664, 0o755, 0o775])
50
19
 
51
- // The names left out at the top alone.
52
- const TOP = ['node_modules', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml']
53
- const TOP_11 = [...TOP, 'bun.lockb']
20
+ // How deep a directory is walked: each entry is matched against the rules
21
+ // of every directory above it, which takes time growing with the cube.
22
+ const MAX_DEPTH = 100
54
23
 
55
- // pnpm 12's rules: the names left out wherever they are, and the files.
24
+ // The directory by paths from it, `.` parts and all, which refuses a link
25
+ // on the way to anything it is asked of.
26
+ function viewOf(project, dir, where) {
27
+ const types = new Map()
28
+ const absolute = (rel) => `/${[dir, ...rel.split('/').filter((part) => part !== '' && part !== '.')].filter(Boolean).join('/')}`
29
+ const type = (rel) => {
30
+ const path = absolute(rel)
31
+ if (!types.has(path)) {
32
+ let found
33
+ try {
34
+ found = project.lstat(path).type
35
+ } catch (error) {
36
+ if (!['ENOENT', 'ENOTDIR'].includes(error.code)) throw error
37
+ }
38
+ if (found === 'symlink') throw new DeptreeError('a link in a directory pnpm installs a copy of is not supported', `${where}: ${quote(normalize(rel))}`)
39
+ types.set(path, found)
40
+ }
41
+ return types.get(path)
42
+ }
43
+ const view = {
44
+ // What `rel` is once normalized, as path.join would; nothing outside.
45
+ type(rel) {
46
+ const normal = normalize(rel)
47
+ if (normal === '..' || normal.startsWith('../')) return undefined
48
+ const parts = normal.split('/').filter((part) => part !== '' && part !== '.')
49
+ for (let i = 1; i < parts.length; i++) if (type(parts.slice(0, i).join('/')) !== 'directory') return undefined
50
+ const found = parts.length === 0 ? 'directory' : type(parts.join('/'))
51
+ return rel.endsWith('/') && found !== 'directory' ? undefined : found
52
+ },
53
+ entries(rel) {
54
+ if (view.type(rel) !== 'directory') return undefined
55
+ if (normalize(rel).split('/').length > MAX_DEPTH) throw new DeptreeError(`a directory nested more than ${MAX_DEPTH} deep, each of whose entries the packlists match against the rules of every directory above it, is not supported`, `${where}: ${quote(normalize(rel))}`)
56
+ return project.readdir(absolute(rel))
57
+ },
58
+ text(rel, here) {
59
+ if (view.type(rel) !== 'file') throw new DeptreeError('it is not a file, which pnpm fails to read', here)
60
+ try {
61
+ return decoder.decode(readBytes(project, absolute(rel)))
62
+ } catch {
63
+ throw new DeptreeError('it is not UTF-8, which is not supported', here)
64
+ }
65
+ },
66
+ bytes: (rel) => readBytes(project, absolute(rel)),
67
+ lstat: (rel) => project.lstat(absolute(rel)),
68
+ }
69
+ return view
70
+ }
71
+
72
+ // pnpm 12's lists of names.
56
73
  const VCS = new Set(['.git', '.svn', '.hg', 'CVS'])
57
74
  const CRUFT = new Set(['.npmrc', 'npm-debug.log', '.DS_Store', 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml'])
75
+ const alwaysExcluded = (rel) => CRUFT.has(rel.split('/').at(-1)) || rel.split('/').some((part) => VCS.has(part)) || rel.endsWith('.orig')
76
+ const asciiLower = (name) => name.replaceAll(/[A-Z]/gu, (char) => char.toLowerCase())
77
+ const alwaysIncluded = (name) => asciiLower(name) === 'package.json' || ['readme', 'license', 'licence'].some((start) => asciiLower(name).startsWith(start))
78
+ const ALTERNATES = new Set(['package.yaml', 'package.json5'])
79
+ const fieldPath = (path) => path.replace(/^(?:\.\/)+/u, '').replace(/^\/+/u, '')
58
80
 
59
- // Whether pnpm 12's rules leave out the entry at `names`, its path from the
60
- // package's directory by name, which is a directory where `directory`.
61
- function leftOut12(names, directory) {
62
- const name = names.at(-1)
63
- return VCS.has(name) || (names.length === 1 && name === 'node_modules') || (!directory && (CRUFT.has(name) || name.endsWith('.orig')))
81
+ // pnpm 12 makes one regexp of the globs of an ignore file, or of `files`,
82
+ // and drops them all where it grows too large, which none does below twice
83
+ // this many bytes of them.
84
+ const MAX_GLOBS_12 = 16 * 1024
85
+ const checkGlobs12 = (lines, what, where) => {
86
+ if (lines.reduce((sum, line) => sum + bytesOf(line).length + 1, 0) > MAX_GLOBS_12) throw new DeptreeError(`${what} of more than ${MAX_GLOBS_12 / 1024} KiB, all of which pnpm 12 may drop as too large a regexp, is not supported`, where)
64
87
  }
65
88
 
66
- // Whether pnpm 12 leaves out the file at `path` even where `main` or `bin`
67
- // names it: by all its rules but node_modules's.
68
- function alwaysLeftOut12(path) {
69
- const names = path.split('/')
70
- const name = names.at(-1)
71
- return names.some((each) => VCS.has(each)) || CRUFT.has(name) || name.endsWith('.orig')
89
+ // pnpm 12's `files` allowlist: its matcher, or undefined where no entry is
90
+ // one, and the files it names outright.
91
+ function filesOf12(view, files, where) {
92
+ checkGlobs12(files ?? [], 'its package.json has `files`', where)
93
+ const globs = []
94
+ for (const entry of files ?? []) {
95
+ const path = fieldPath(entry)
96
+ if (path !== '') globs.push(gitignoreGlob(path.startsWith('!') ? path : `/${path}`, `${where}: files[${quote(entry)}]`))
97
+ }
98
+ const named = new Set((files ?? []).filter((entry) => !entry.startsWith('!') && !entry.endsWith('/') && !/[*?[\]{}]/u.test(entry)).map(fieldPath).filter((path) => path !== '' && !path.split('/').includes('..') && view.type(path) === 'file'))
99
+ return { globs: globs.length > 0 ? globs : undefined, named }
72
100
  }
73
101
 
74
- // Whether npm-packlist's built-in rules, as pnpm `major` runs it, leave out
75
- // the entry at `names`, as for leftOut12.
76
- function leftOutByNpm(names, directory, major) {
77
- const folded = names.map((name) => name.toLowerCase())
78
- const readIn = major >= 11 ? folded.map((_, i) => folded.slice(i)) : [folded]
79
- return ANYWHERE.test(folded.at(-1)) || readIn.some((path) => anchored(path, directory))
80
- || (folded.length === 1 && (major >= 11 ? TOP_11 : TOP).includes(folded[0]))
102
+ function includedBy12(globs, rel, named) {
103
+ if (globs.some((glob) => glob.whitelist) && !named.has(rel)) {
104
+ const parts = rel.split('/')
105
+ for (let i = parts.length - 1; i >= 0; i--) if (matched(globs, parts.slice(0, i).join('/'), true) === 'whitelist') return false
106
+ }
107
+ return matchedOrParents(globs, rel, false) === 'ignore'
81
108
  }
82
109
 
83
- // npm-packlist's names it keeps, whatever else says.
84
- const MUST_HAVE = /^(?:readme|copying|license|licence)(?:\..*[^~$])?$/iu
110
+ // The ignore crate's walk: each directory's .npmignore and, unless the top
111
+ // has one, .gitignore, the nearest to match a path deciding, an .npmignore's
112
+ // before any .gitignore's. Neither is read where `files` has a matcher.
113
+ function walk12(view, { globs }, where) {
114
+ const useGit = view.type('.npmignore') !== 'file'
115
+ const found = []
116
+ const visit = (rel, stack) => {
117
+ const names = view.entries(rel)
118
+ const own = { dir: rel }
119
+ for (const [key, name] of [['custom', '.npmignore'], ['git', '.gitignore']]) {
120
+ if (globs === undefined && (key === 'custom' || useGit) && names.includes(name)) {
121
+ const path = rel === '' ? name : `${rel}/${name}`
122
+ const here = `${where}: ${quote(path)}`
123
+ const lines = view.text(path, here).split('\n')
124
+ checkGlobs12(lines, 'an ignore file', here)
125
+ own[key] = lines.map((line, i) => (i === 0 ? line.replace(/^\uFEFF/u, '') : line).replace(/\r$/u, '')).map((line) => gitignoreGlob(line, here)).filter(Boolean)
126
+ }
127
+ }
128
+ const chain = [own, ...stack]
129
+ for (const name of names) {
130
+ const path = rel === '' ? name : `${rel}/${name}`
131
+ if ((rel === '' && name === 'node_modules') || VCS.has(name)) continue
132
+ const isDir = view.type(path) === 'directory'
133
+ const verdict = (key) => chain.values().map((level) => level[key] === undefined ? undefined : matched(level[key], level.dir === '' ? path : path.slice(level.dir.length + 1), isDir)).find(Boolean)
134
+ if ((verdict('custom') ?? verdict('git')) === 'ignore') continue
135
+ if (isDir) visit(path, chain)
136
+ else found.push(path)
137
+ }
138
+ }
139
+ visit('', [])
140
+ return found
141
+ }
85
142
 
86
- // The paths a package.json's main, browser and bin name, from its
87
- // directory, whatever their case, that pnpm `major` may keep whatever its
88
- // rules say: with pnpm 12, those main and bin name that its rules but
89
- // node_modules's do not leave out.
90
- function namedByManifest(manifest, major) {
91
- const { main, browser, bin } = manifest
92
- const bins = typeof bin === 'string' ? [bin] : Object.values(bin ?? {})
93
- const paths = (major >= 12 ? [main, ...bins] : [main, browser, ...bins]).filter((path) => typeof path === 'string').map((path) => join('.', path))
94
- return (major >= 12 ? paths.filter((path) => !alwaysLeftOut12(path)) : paths).map((path) => path.toLowerCase())
143
+ function pack12(view, manifest, where) {
144
+ const files = Array.isArray(manifest.files) ? filesOf12(view, manifest.files, where) : { named: new Set() }
145
+ const main = typeof manifest.main === 'string' ? [manifest.main] : []
146
+ const bins = typeof manifest.bin === 'string' ? [manifest.bin] : manifest.bin !== null && typeof manifest.bin === 'object' && !Array.isArray(manifest.bin) ? Object.values(manifest.bin).filter((bin) => typeof bin === 'string') : []
147
+ const fields = [...main, ...bins].map(fieldPath)
148
+ const kept = new Set(walk12(view, files, where).filter((rel) => !alwaysExcluded(rel) && !rel.startsWith('node_modules/')
149
+ && (files.globs === undefined || includedBy12(files.globs, rel, files.named) || (!rel.includes('/') && alwaysIncluded(rel)) || fields.includes(rel))))
150
+ for (const name of view.entries('')) {
151
+ if (!alwaysExcluded(name) && (alwaysIncluded(name) || ALTERNATES.has(asciiLower(name))) && view.type(name) === 'file') kept.add(name)
152
+ }
153
+ // A main or bin path that stays inside, kept as it is spelled.
154
+ for (const path of fields) {
155
+ const parts = path.split('/')
156
+ if (path === '' || path.includes('\\') || parts.includes('..') || parts[0] === '.' || alwaysExcluded(path) || view.type(path) !== 'file') continue
157
+ if (parts.some((part) => part === '' || part === '.') || parts[0] === 'node_modules') throw new DeptreeError(`main or bin names ${quote(path)}, which pnpm 12 keeps as it is spelled, and which is not supported`, where)
158
+ kept.add(path)
159
+ }
160
+ return kept
95
161
  }
96
162
 
97
- // Whether a package.json's list of bundled dependencies may name any: an
98
- // empty one bundles none, with either npm-packlist.
99
163
  const bundles = (list) => Boolean(list) && !(Array.isArray(list) && list.length === 0)
100
164
 
101
- // The files of the package at `dir` of `project` npm-packlist picks, with
102
- // their data and modes, by their paths from it; `manifest` is its
103
- // package.json as parsed.
104
- export function packDirectory(project, dir, manifest, major, where) {
105
- if (manifest.files !== undefined) throw new DeptreeError('its package.json has `files`, which npm-packlist picks the files pnpm installs by, and which is not followed here', where)
165
+ function checkManifest(manifest, pnpm, view, where) {
166
+ const { files, bin } = manifest
106
167
  if (bundles(manifest.bundleDependencies) || bundles(manifest.bundledDependencies)) throw new DeptreeError('a directory with bundled dependencies is not supported', where)
107
- const named = namedByManifest(manifest, major)
108
- const leftOut = major >= 12 ? leftOut12 : (names, directory) => leftOutByNpm(names, directory, major)
168
+ if (files !== undefined && files !== null && !(Array.isArray(files) && files.every((entry) => typeof entry === 'string'))) throw new DeptreeError('its package.json has `files` that is not a list of strings, which is not supported', where)
169
+ if (Array.isArray(bin) && bin.some((path) => typeof path !== 'string') && !pnpm.startsWith('11.') && !pnpm.startsWith('12.')) throw new DeptreeError('its package.json has a bin list with other than strings, which npm-packlist then reads unnormalized, and which is not supported', where)
170
+ if (!pnpm.startsWith('11.')) return
171
+ if (bin !== null && typeof bin === 'object' && Object.values(bin).some((path) => typeof path !== 'string')) throw new DeptreeError('its package.json has a bin that is not a string, which pnpm 11 fails on', where)
172
+ if (compareVersions(pnpm, '11.28.0') < 0 && view.text('package.json', where).startsWith('\uFEFF')) throw new DeptreeError('its package.json starts with a byte order mark, which pnpm 11 fails on before 11.28', where)
173
+ }
174
+
175
+ // `version` is the version that installs, as host.pnpm gives it: `v11.28.2`
176
+ // is read as 11.28.2.
177
+ export function packDirectory(project, dir, manifest, version, where) {
178
+ const pnpm = valid(version)
179
+ const view = viewOf(project, dir, where)
180
+ checkManifest(manifest, pnpm, view, where)
181
+ const major = Number(pnpm.split('.')[0])
182
+ const kept = major >= 12 ? pack12(view, manifest, where)
183
+ : major === 11 ? pack11(view, manifest, where, compareVersions(pnpm, '11.28.0') >= 0)
184
+ : pack10(view, view.text('package.json', where).startsWith('\uFEFF') ? undefined : manifest, where, major === 10 && compareVersions(pnpm, '10.31.0') >= 0 ? '5.1.9' : '5.1.6')
109
185
  const files = new Map()
110
- const visit = (names) => {
111
- for (const entry of project.readdir(['', dir, ...names].join('/'))) {
112
- const at = [...names, entry]
113
- const rel = at.join('/')
114
- const here = `${where}: ${quote(rel)}`
115
- const { type, mode } = project.lstat(`/${dir}/${rel}`)
116
- if (type === 'symlink') throw new DeptreeError('a link in a directory pnpm installs a copy of is not supported', here)
117
- if (entry === '.npmignore' || entry === '.gitignore') throw new DeptreeError(`${entry}'s rules, which npm-packlist picks the files pnpm installs by, are not followed here`, here)
118
- if (major < 12 && names.length === 0 && entry !== 'node_modules' && entry.toLowerCase() === 'node_modules') throw new DeptreeError('a name that is node_modules but for its case is kept by pnpm 10 and left out by pnpm 11', here)
119
- if (major < 12 && entry.includes('*')) continue
120
- if (leftOut(at, type === 'directory')) {
121
- const folded = rel.toLowerCase()
122
- if ((major < 12 && MUST_HAVE.test(entry)) || named.some((kept) => kept === folded || kept.startsWith(`${folded}/`))) {
123
- throw new DeptreeError('whether pnpm installs it turns on rules of npm-packlist not followed here', here)
124
- }
125
- continue
126
- }
127
- if (type === 'directory') visit(at)
128
- else if (mode !== 0o644 && mode !== 0o755) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644 or 755, which is not supported`, here)
129
- else files.set(rel, { data: readBytes(project, `/${dir}/${rel}`), mode })
130
- }
186
+ for (const rel of [...new Set([...kept].map((path) => path.replace(/^\.\//u, '')))].sort()) {
187
+ const here = `${where}: ${quote(rel)}`
188
+ if (rel.split('/').some((part) => part === '' || part === '.')) throw new DeptreeError('pnpm keeps it as a pattern spells it, which is not supported', here)
189
+ const { mode } = view.lstat(rel)
190
+ if (!MODES.has(mode)) throw new DeptreeError(`its mode, ${mode.toString(8)}, is not 644, 664, 755 or 775, which is not supported`, here)
191
+ files.set(rel, { data: view.bytes(rel), mode })
131
192
  }
132
- visit([])
133
193
  return files
134
194
  }
@@ -1,19 +1,14 @@
1
- // Which patch pnpm 10 applies to a package: not the one its snapshot key
2
- // names, but the one the settings' patchedDependencies pick for its name
3
- // and version (@pnpm/patching.config's getPatchInfo): `name@version`
4
- // exactly, else the one `name@range` whose range takes the version — two
5
- // that do are refused — else `name@*` or `name` alone. Every snapshot is
6
- // held to have the patch hash that pick has, so the patch applied here by
7
- // the key is the one pnpm applies; and, stricter than pnpm, which checks
8
- // this only when it resolves, every patch configured has to be the pick of
9
- // some snapshot.
1
+ // pnpm 10 applies the patch patchedDependencies picks for a package's name and
2
+ // version (@pnpm/patching.config's getPatchInfo), not the one its snapshot key
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.
10
6
 
11
7
  import { packageKeyOf } from '@preventive/lockfile/pnpm.js'
12
8
  import { isExactVersion, satisfies, valid, validRange } from '@preventive/upstream/semver.js'
13
9
  import { DeptreeError, quote } from '../error.js'
14
10
 
15
- // dependency-path's parse of a selector: a name and an exact version, a
16
- // name and anything else after its `@`, or neither.
11
+ // dependency-path's parse of a selector.
17
12
  function parseSelector(selector) {
18
13
  const at = selector.indexOf('@', 1)
19
14
  const rest = at === -1 ? '' : packageKeyOf(selector).slice(at + 1)
@@ -22,8 +17,7 @@ function parseSelector(selector) {
22
17
  return isExactVersion(rest) ? { name, version: rest } : { name, range: rest }
23
18
  }
24
19
 
25
- // groupPatchedDependencies: by package name, the selectors that can pick
26
- // it; a later one of a kind over an earlier, as pnpm assigns them.
20
+ // groupPatchedDependencies: a later selector of a kind wins, as pnpm assigns.
27
21
  function group(selectors) {
28
22
  const groups = new Map()
29
23
  const of = (name) => {
@@ -50,12 +44,14 @@ function pick(groups, name, version, where) {
50
44
  return taking[0]?.selector ?? found.all
51
45
  }
52
46
 
53
- // `hashes` is the configured patches' hashes and paths, by selector.
54
- export function checkPatchUse(lockfile, hashes) {
55
- const groups = group(Object.keys(hashes))
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))
56
52
  const used = new Set()
57
53
  for (const [key, pkg] of Object.entries(lockfile.packages)) {
58
- const selector = pick(groups, pkg.name, pkg.version, quote(key))
54
+ const selector = major < 10 ? pick9(hashes, pkg.name, pkg.version) : pick(groups, pkg.name, pkg.version, quote(key))
59
55
  const wanted = selector === undefined ? undefined : hashes[selector].hash
60
56
  if (wanted !== pkg.patchHash) {
61
57
  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))
@@ -69,7 +65,7 @@ export function checkPatchUse(lockfile, hashes) {
69
65
 
70
66
  const PATCH = '(patch_hash='
71
67
 
72
- // A key's run of balanced groups at its end, each on its own, and what is
68
+ // A key's trailing parenthesized groups, each on its own, and what is
73
69
  // before them; undefined where they do not balance.
74
70
  function splitSuffix(key) {
75
71
  const segments = []
@@ -88,8 +84,7 @@ function splitSuffix(key) {
88
84
  return { locator: key.slice(0, end), segments }
89
85
  }
90
86
 
91
- // dependency-path's parse, of what is read here: the name, the version
92
- // where it is SemVer, and the patch hash.
87
+ // dependency-path's parse, of the name, a SemVer version and the patch hash.
93
88
  function parseKey(key) {
94
89
  const at = key.indexOf('@', 1)
95
90
  if (at === -1 || at === key.length - 1) return {}
@@ -99,11 +94,9 @@ function parseKey(key) {
99
94
  return { name: key.slice(0, at), version: valid(base) === null ? undefined : base, hash }
100
95
  }
101
96
 
102
- // pnpm 11 holds what a key names to their patches down through its peers
103
- // (@pnpm/lockfile.fs's checkPatchedDepPaths), where pnpm 10 holds only the
104
- // snapshot: a peer that names a patch hash, or, unless dedupePeers leaves
105
- // them out, one of a version of a patched package, has to name the hash of
106
- // the patch picked for it. One whose hash cannot be told is refused too.
97
+ // pnpm 11's checkPatchedDepPaths (@pnpm/lockfile.fs) checks hashes down through
98
+ // a key's peers too: a peer that names one, or, unless dedupePeers leaves
99
+ // versions out, a version of a patched package.
107
100
  export function checkPeerPatches(lockfile, hashes) {
108
101
  const groups = group(Object.keys(hashes))
109
102
  const carried = lockfile.settings.dedupePeers !== true