@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
package/src/github.js ADDED
@@ -0,0 +1,92 @@
1
+ // A git dependency that a package manager clones, `git clone` and then a
2
+ // checkout of one commit, from GitHub's tarball of that commit's tree
3
+ // instead: the files a checkout writes, without the .git it clones.
4
+
5
+ import { decompress } from '@preventive/archive/compression.js'
6
+ import { ArchiveError, unpack } from '@preventive/archive/tar.js'
7
+ import { HttpError } from '@preventive/upstream/github.js'
8
+ import { DeptreeError, quote } from './error.js'
9
+ import { MAX_BYTES } from './tarball.js'
10
+
11
+ // A name git's checkout refuses, as its verify_path does with
12
+ // core.protectNTFS, on by default wherever git runs: `.git`, or its short
13
+ // name `git~1`, in any case, dots and spaces after it, and then nothing, or
14
+ // a `:` and anything.
15
+ const isDotGit = (name) => /^(?:\.git|git~1)[. ]*(?::|$)/iu.test(name)
16
+
17
+ // A GitHub repository as git takes its URL over https and ssh, `.git` after
18
+ // it or not, the scheme and host in any case: https://github.com/<repo>,
19
+ // ssh://git@github.com/<repo> and git@github.com:<repo>. The owner and name
20
+ // are as GitHub takes them.
21
+ const REPO = String.raw`(?<repo>(?=[\dA-Za-z-]{1,39}\/)[\dA-Za-z](?:-?[\dA-Za-z])*\/[\w.-]{1,100}?)(?:\.git)?`
22
+ const URL_FORM = new RegExp(String.raw`^(?:(?i:https):\/\/|(?i:ssh):\/\/git@)(?i:github\.com)\/${REPO}\/?$`, 'u')
23
+ const SCP_FORM = new RegExp(String.raw`^git@(?i:github\.com):${REPO}$`, 'u')
24
+
25
+ export function githubRepoOf(url) {
26
+ const repo = (URL_FORM.exec(url) ?? SCP_FORM.exec(url))?.groups.repo
27
+ return repo === undefined || /\/\.\.?$/u.test(repo) ? undefined : repo
28
+ }
29
+
30
+ const isRedirect = (error) => error instanceof HttpError && error.status >= 300 && error.status < 400
31
+
32
+ // A repository renamed or transferred since it was named, which GitHub
33
+ // answers with a redirect that git's clone follows, is asked for by the
34
+ // name GitHub gives it now, as upstream's getRepo follows the redirect;
35
+ // any other redirect is refused there.
36
+ async function followingMoves(github, repo, ask) {
37
+ try {
38
+ return await ask(repo)
39
+ } catch (error) {
40
+ if (!isRedirect(error)) throw error
41
+ const moved = await github.getRepo({ repo, followRedirect: true })
42
+ return await ask(moved.full_name)
43
+ }
44
+ }
45
+
46
+ // That `commit` is one a clone of the repository has, which GitHub's API
47
+ // does not tell: it answers for a commit of any fork through the
48
+ // repository's name, and for one no branch or tag reaches any longer. Of
49
+ // what a clone fetches, the default branch's history alone is asked of, so
50
+ // that a commit on another branch alone is refused too.
51
+ export async function checkCloned(github, repo, commit, where) {
52
+ const { status } = await followingMoves(github, repo, async (name) => {
53
+ const { default_branch: branch } = await github.getRepo({ repo: name })
54
+ return await github.compareCommits({ repo: name, base: commit, head: branch })
55
+ })
56
+ if (status !== 'ahead' && status !== 'identical') {
57
+ throw new DeptreeError(`${commit} is not in the history of the repository's default branch, which is all that is held to be in a clone of it`, where)
58
+ }
59
+ }
60
+
61
+ // GitHub's tarball of the commit's tree: the tree read off the commit's own
62
+ // object, which upstream's getCommitTree fetches as git does and holds to
63
+ // the commit's id, so that it is the commit's whatever GitHub's API says;
64
+ // and the tarball held to that tree, files, symlinks and the submodules it
65
+ // shows as empty directories alike. Unpacked as a checkout with umask
66
+ // 0o022 writes it: directories 0o755, files 0o644 or 0o755 by the bit git
67
+ // keeps, symlinks as symlinks.
68
+ export async function checkoutOf(github, repo, rev, where) {
69
+ const bytes = await followingMoves(github, repo, async (name) => github.getRepoTreeTarball({ repo: name, tree: await github.getCommitTree({ repo: name, sha: rev }) }))
70
+ let entries
71
+ try {
72
+ entries = unpack(await decompress(bytes, 'gzip', { limit: MAX_BYTES }))
73
+ } catch (error) {
74
+ if (error instanceof ArchiveError) throw new DeptreeError(`its tarball from GitHub cannot be read: ${error.message}`, where, { cause: error })
75
+ throw error
76
+ }
77
+ const top = entries[0]?.name.split('/')[0]
78
+ const dirs = new Set()
79
+ const files = new Map()
80
+ const links = new Map()
81
+ for (const entry of entries) {
82
+ if (entry.name === top) continue
83
+ if (!entry.name.startsWith(`${top}/`)) throw new Error('unreachable: an entry outside the one top directory upstream holds the tarball to')
84
+ const path = entry.name.slice(top.length + 1)
85
+ if (path.split('/').some(isDotGit)) throw new DeptreeError('a path with a .git in it, or its short name, which git refuses to check out', `${where}: ${quote(path)}`)
86
+ if (entry.type === 'directory') dirs.add(path)
87
+ else if (entry.type === 'symlink') links.set(path, entry.linkname)
88
+ else if (entry.type === 'file') files.set(path, { data: entry.data, mode: entry.mode & 0o100 ? 0o755 : 0o644 })
89
+ else throw new Error(`unreachable: a ${entry.type} in a tarball of a git tree`)
90
+ }
91
+ return { dirs, files, links }
92
+ }
package/src/glob.js CHANGED
@@ -39,9 +39,10 @@ export function walkWorkspaces(project, globs, { manager, fold = (path) => path,
39
39
  const dir = pending.pop()
40
40
  for (const name of project.readdir(`/${dir}`)) {
41
41
  const path = dir === '' ? name : `${dir}/${name}`
42
+ if (skip(name)) continue
42
43
  const key = fold(path)
43
44
  const taken = folded.some((glob) => matchesGlob(glob, key))
44
- if (skip(name) || (!taken && !folded.some((glob) => reachesBelow(glob, key)))) continue
45
+ if (!taken && !folded.some((glob) => reachesBelow(glob, key))) continue
45
46
  const { type } = project.lstat(`/${path}`)
46
47
  if (type === 'symlink') throw new DeptreeError(`a link where ${manager} looks for workspaces is not supported`, quote(path))
47
48
  if (type !== 'directory') continue
package/src/hash.js CHANGED
@@ -1,4 +1,3 @@
1
- import { toBase32 } from '@exodus/bytes/base32.js'
2
1
  import { toBase64 } from '@exodus/bytes/base64.js'
3
2
  import { toHex } from '@exodus/bytes/hex.js'
4
3
  import { utf8fromString } from '@exodus/bytes/utf8.js'
@@ -15,39 +14,7 @@ function utf8(text, where) {
15
14
 
16
15
  export const sha256Hex = async (text, where) => toHex(await digest('SHA-256', utf8(text, where)))
17
16
 
18
- // MD5, which Web Crypto has not, as RFC 1321 has it.
19
- const SHIFTS = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21]
20
- const SINES = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32) >>> 0)
21
- function md5(input) {
22
- const padded = new Uint8Array(Math.ceil((input.length + 9) / 64) * 64)
23
- padded.set(input)
24
- padded[input.length] = 0x80
25
- const view = new DataView(padded.buffer)
26
- view.setUint32(padded.length - 8, (input.length * 8) >>> 0, true)
27
- view.setUint32(padded.length - 4, Math.floor(input.length / 2 ** 29), true)
28
- const state = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
29
- for (let block = 0; block < padded.length; block += 64) {
30
- let [a, b, c, d] = state
31
- for (let i = 0; i < 64; i++) {
32
- const round = i >> 4
33
- const f = round === 0 ? (b & c) | (~b & d) : round === 1 ? (d & b) | (~d & c) : round === 2 ? b ^ c ^ d : c ^ (b | ~d)
34
- const g = round === 0 ? i : round === 1 ? (5 * i + 1) % 16 : round === 2 ? (3 * i + 5) % 16 : (7 * i) % 16
35
- const shift = SHIFTS[round * 4 + (i % 4)]
36
- const sum = (a + f + SINES[i] + view.getUint32(block + g * 4, true)) >>> 0
37
- ;[a, d, c] = [d, c, b]
38
- b = (b + ((sum << shift) | (sum >>> (32 - shift)))) >>> 0
39
- }
40
- for (const [i, word] of [a, b, c, d].entries()) state[i] = (state[i] + word) >>> 0
41
- }
42
- const bytes = new Uint8Array(16)
43
- const out = new DataView(bytes.buffer)
44
- state.forEach((word, i) => out.setUint32(i * 4, word, true))
45
- return bytes
46
- }
47
-
48
- // pnpm 9's createBase32Hash: the MD5 of the text's UTF-8, in RFC 4648's
49
- // base32, lowercased and unpadded.
50
- export const md5Base32 = (text, where) => toBase32(md5(utf8(text, where)), { padding: false }).toLowerCase()
17
+ export const sha256Base64 = async (text, where) => toBase64(await digest('SHA-256', utf8(text, where)))
51
18
 
52
19
  export const matchesIntegrity = async (bytes, integrity) => integrity === `sha512-${toBase64(await digest('SHA-512', bytes))}`
53
20
 
package/src/matcher.js CHANGED
@@ -73,12 +73,10 @@ export function createMatcher(patterns) {
73
73
  return { ignore, match: matcherOf(ignore ? pattern.slice(1) : pattern) }
74
74
  })
75
75
  if (matchers.every(({ ignore }) => ignore)) return (input) => !matchers.some(({ match }) => match(input))
76
+ // The last pattern to match decides: a plain one for, a `!` one against.
76
77
  return (input) => {
77
78
  let matched = false
78
- for (const { ignore, match } of matchers) {
79
- if (ignore) { if (match(input)) matched = false }
80
- else if (!matched && match(input)) matched = true
81
- }
79
+ for (const { ignore, match } of matchers) if (match(input)) matched = !ignore
82
80
  return matched
83
81
  }
84
82
  }
package/src/mount.js CHANGED
@@ -25,7 +25,7 @@ export function checkNoModules(vfs, folded) {
25
25
  // dependencies and cargo's vendor: `what` it is called.
26
26
  export const checkNoDir = (name, what) => (vfs, folded) => {
27
27
  for (const there of vfs.readdir('/')) {
28
- if (there === name || (folded && fold(there) === name)) {
28
+ if (there === name || (folded && fold(there) === fold(name))) {
29
29
  throw new DeptreeError(`${what} is there already, which is neither kept beside the tree nor removed`, where(`/${there}`))
30
30
  }
31
31
  }
@@ -48,10 +48,7 @@ export const within = (parent, child) => child === parent || (parent === '.' ? c
48
48
  // a line or paragraph separator, a bidirectional control).
49
49
  export const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
50
50
 
51
- const asRefusal = (error, what, path) => {
52
- if (error instanceof VfsError) return new DeptreeError(`cannot be ${what}: ${error.message}`, quote(path), { cause: error })
53
- return error
54
- }
51
+ const asRefusal = (error, what, path) => (error instanceof VfsError ? new DeptreeError(`cannot be ${what}: ${error.message}`, quote(path), { cause: error }) : error)
55
52
 
56
53
  // Each builder holds what a tarball names and where a package goes to that
57
54
  // first, and makes no link where a package is written after. What is made
package/src/npm/compat.js CHANGED
@@ -87,8 +87,7 @@ export function skippedOf(nodes, host, settings, omitted = new Set()) {
87
87
  if (host.reuse || !omitted.has(node)) checkRuns(node.manifest, host, where, settings.engineStrict, ', and it is not optional')
88
88
  continue
89
89
  }
90
- if (host.reuse && omitted.has(node)) continue
91
- if (!host.reuse && skipped.has(node)) continue
90
+ if (host.reuse ? omitted.has(node) : skipped.has(node)) continue
92
91
  if (checkEngine(node.manifest, host) === undefined && checkPlatform(node.manifest, host, where) === undefined) continue
93
92
  for (const member of optionalSet(node, host, skipped)) skipped.add(member)
94
93
  }
@@ -101,10 +100,10 @@ export function skippedOf(nodes, host, settings, omitted = new Set()) {
101
100
  // `set`, and what is in the node_modules of each of its nodes.
102
101
  function withBeneath(nodes, set) {
103
102
  const under = (node) => node.parent !== undefined && (set.has(nodes.get(node.parent)) || under(nodes.get(node.parent)))
104
- return new Set([...nodes.values()].filter((node) => set.has(node) || under(node)))
103
+ return new Set(nodes.values().filter((node) => set.has(node) || under(node)))
105
104
  }
106
105
 
107
106
  // What --omit=dev leaves out: each package the lockfile's flags say only dev
108
107
  // dependencies reach, and so what is beneath it, as the lockfile reader holds
109
108
  // the flags to what depends on each.
110
- export const omittedOf = (nodes) => new Set([...nodes.values()].filter((node) => node.kind === 'package' && node.pkg.dev))
109
+ export const omittedOf = (nodes) => new Set(nodes.values().filter((node) => node.kind === 'package' && node.pkg.dev))
@@ -63,7 +63,7 @@ export function recalculates(lists, edges) {
63
63
  }
64
64
  }
65
65
  for (const name of Object.keys(optionalDependencies)) delete byType.prod[name]
66
- const left = new Set([...edges].filter(([, edge]) => edge.type !== 'workspace').map(([name]) => name))
66
+ const left = new Set(edges.keys().filter((name) => edges.get(name).type !== 'workspace'))
67
67
  for (const [type, specs] of Object.entries(byType)) {
68
68
  for (const [name, spec] of Object.entries(specs)) {
69
69
  if (edges.get(name)?.type !== type || edges.get(name).spec !== spec) return true
package/src/npm/tree.js CHANGED
@@ -27,7 +27,7 @@ const whereOf = (node) => `packages[${quote(node.location)}]`
27
27
 
28
28
  function checkLinks(lockfile) {
29
29
  for (const [location, target] of Object.entries(lockfile.links)) {
30
- const where = `packages[${quote(location)}]`
30
+ const where = whereOf({ location })
31
31
  const importer = lockfile.importers[target]
32
32
  if (!importer?.workspace) throw new DeptreeError(`a link to ${importer === undefined ? 'a package' : 'the project'} is not supported`, where)
33
33
  if (location !== `node_modules/${importer.name}`) throw new DeptreeError(`a workspace linked other than as node_modules/${importer.name} is not supported`, where)
@@ -173,13 +173,14 @@ function rootListsOf(text) {
173
173
  }
174
174
 
175
175
  export async function buildNpmTree(options) {
176
- const { host: given, vfs: into } = options ?? {}
176
+ const given = options ?? {}
177
+ const into = given.vfs
177
178
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
178
- const fetching = fetchingOf(options ?? {}, into)
179
- const production = productionOf(options ?? {})
180
- const host = checkHost(given)
179
+ const fetching = fetchingOf(given, into)
180
+ const production = productionOf(given)
181
+ const host = checkHost(given.host)
181
182
  const folded = host.os === 'darwin'
182
- const inputs = inputsOf(options ?? {}, folded)
183
+ const inputs = inputsOf(given, folded)
183
184
  // Refused before anything is fetched; mount checks again.
184
185
  if (into !== undefined) checkNoModules(into, folded)
185
186
  const { settings, manifests } = inputs
@@ -193,7 +194,7 @@ export async function buildNpmTree(options) {
193
194
  const nodes = graphOf(lockfile, manifests)
194
195
  const omitted = production ? omittedOf(nodes) : new Set()
195
196
  const skipped = skippedOf(nodes, host, settings, omitted)
196
- const kept = [...nodes.values()].filter((node) => node.kind === 'package' && !skipped.has(node) && !omitted.has(node))
197
+ const kept = nodes.values().filter((node) => node.kind === 'package' && !skipped.has(node) && !omitted.has(node)).toArray()
197
198
  const tarballs = tarballsOf(kept)
198
199
  const fetched = fetching.lazy ? new Map() : await fetchAll(tarballs, host, fetching)
199
200
  const changed = settings.binLinks && !fetching.sizeEstimateOnly && !fetching.lazy ? fixBins(kept, fetched) : new Map()
@@ -205,7 +206,7 @@ export async function buildNpmTree(options) {
205
206
  const { name, version, dev, optional, devOptional, peer } = node.pkg
206
207
  return { path: node.location, name, version, integrity, ...about, dev, optional, devOptional, peer, ...fetching.sizeEstimateOnly ? { size } : {} }
207
208
  }
208
- const tarballOf = new Map([...tarballs.values()].flatMap((group) => group.nodes.map((node) => [node, group])))
209
+ const tarballOf = new Map(tarballs.values().flatMap((group) => group.nodes.map((node) => [node, group])))
209
210
  // With `lazy`, by the lockfile's integrity, and nothing a document says yet.
210
211
  const installed = kept.map((node) => entryOf(node, fetched.get(node) ?? { integrity: tarballOf.get(node).tarball.integrity, about: NO_ABOUT }))
211
212
  const tree = mount(vfs, into, folded)
package/src/patch.js CHANGED
@@ -62,8 +62,12 @@ function readHunks(lines, where) {
62
62
  if (!lines.every((line) => HUNK_LINE.test(line))) throw new DeptreeError('expected only hunks after the header', where)
63
63
  const files = parseDiff(`${lines.join('\n')}\n`)
64
64
  const hunks = files.flatMap((file) => file.hunks)
65
- const heads = lines.filter((line) => line.startsWith('@@ ')).length
66
- const held = lines.filter((line) => !line.startsWith('@@ ') && !line.startsWith('\\')).length
65
+ let heads = 0
66
+ let held = 0
67
+ for (const line of lines) {
68
+ if (line.startsWith('@@ ')) heads++
69
+ else if (!line.startsWith('\\')) held++
70
+ }
67
71
  if (files.length !== 1 || files[0].format !== 'unified' || hunks.length !== heads || hunks.reduce((sum, hunk) => sum + hunk.lines.length, 0) !== held) {
68
72
  throw new DeptreeError('expected unified hunks and nothing between them', where)
69
73
  }
@@ -89,9 +93,9 @@ function applyTo(text, { hunks, blocks, where }) {
89
93
  for (const hunk of hunks) {
90
94
  const kept = hunk.lines.filter((line) => line.tag !== '+')
91
95
  if (hunk.oldStart < end || (kept.length === 0 && hunk.oldStart !== 0)) throw new DeptreeError('hunks out of order, or one with no context', where)
92
- kept.forEach((line, index) => {
96
+ for (const [index, line] of kept.entries()) {
93
97
  if (records[hunk.oldStart + index] !== line.text) throw new DeptreeError(`the hunk at line ${hunk.oldStart + 1} does not apply`, where)
94
- })
98
+ }
95
99
  end = hunk.oldStart + kept.length
96
100
  }
97
101
  return applyChangeSet(text, blocks)
@@ -112,7 +116,7 @@ export function applyPatch(files, patch, { createdMode } = {}) {
112
116
  for (const file of patch) {
113
117
  const current = next.get(file.path)
114
118
  if (file.change === 'create') {
115
- const taken = current !== undefined || [...next.keys()].some((path) => path.startsWith(`${file.path}/`)) || parentsOf(file.path).some((dir) => next.get(dir)?.data !== undefined)
119
+ const taken = current !== undefined || next.keys().some((path) => path.startsWith(`${file.path}/`)) || parentsOf(file.path).some((dir) => next.get(dir)?.data !== undefined)
116
120
  if (taken) throw new DeptreeError('creates a file that is there', file.where)
117
121
  next.set(file.path, { data: bytesOf(applyTo('', file), file.where), mode: createdMode ?? file.mode })
118
122
  continue
package/src/pnpm/bins.js CHANGED
@@ -5,8 +5,7 @@
5
5
  // rewrites no `#!` line.
6
6
  // Where any patch is configured, pnpm 10 and 11 build each package patched
7
7
  // or with an install script, which links its own bins beside its children's
8
- // before the patch; pnpm 12 links them together, with no build pass. pnpm 9
9
- // links as pnpm 10 does, but fails on a bin that is a directory.
8
+ // before the patch; pnpm 12 links them together, with no build pass.
10
9
 
11
10
  import { DeptreeError, quote } from '../error.js'
12
11
  import { crlfShebang, fixShebang } from '../tarball.js'
@@ -99,8 +98,9 @@ const PUBLIC = /^node_modules\/(?:@[^/]+\/)?[^/@.][^/]*$/u
99
98
  function preferOwn(entries, manifest, commandsOfDir) {
100
99
  const own = ownNames(manifest)
101
100
  const commands = entries.flatMap(([alias, dir]) => commandsOfDir(dir).map((command) => ({ ...command, direct: own.has(alias) })))
102
- const names = new Set(commands.filter((command) => command.direct).map(({ name }) => name))
103
- return [...commands.filter((command) => command.direct), ...commands.filter((command) => !names.has(command.name))]
101
+ const direct = commands.filter((command) => command.direct)
102
+ const names = new Set(direct.map(({ name }) => name))
103
+ return [...direct, ...commands.filter((command) => !names.has(command.name))]
104
104
  }
105
105
 
106
106
  // The files pnpm runs fixBin on, as sets of paths by package directory.
@@ -135,7 +135,7 @@ export function binTargets({ nodes, projects, direct, links, publicHoist, buildi
135
135
  const hoisted = [...links].filter(([path, dir]) => path.startsWith(PRIVATE) && nodes.get(dir)?.pkg.hasBin)
136
136
  link(hoisted.flatMap(([, dir]) => commandsOfDir(dir)), { ordered: true, where: quote(PRIVATE.slice(0, -1)) })
137
137
 
138
- const patched = [...nodes.values()].some((node) => node.pkg.patchHash !== undefined)
138
+ const patched = nodes.values().some((node) => node.pkg.patchHash !== undefined)
139
139
  for (const [id, children] of direct) {
140
140
  const where = `importers[${quote(id)}]`
141
141
  const peerDirs = major >= 11 && peers ? peersOf(children, nodes) : []
@@ -188,7 +188,7 @@ export function binReads({ nodes, projects, direct, links, publicHoist, peers, m
188
188
  for (const dir of children.values()) reads.add(dir)
189
189
  }
190
190
  }
191
- return new Set([...reads].filter((dir) => nodes.has(dir)))
191
+ return new Set(reads.values().filter((dir) => nodes.has(dir)))
192
192
  }
193
193
 
194
194
  // The copies of one package pnpm's build pass makes hardlinks of the one it
@@ -278,7 +278,7 @@ export function hoistedBinTargets({ nodes, projects, modules, builds = [], hardl
278
278
  // before or after as they depend on each other.
279
279
  // What each snapshot reaches through the copies' dependencies, each taken
280
280
  // for the copies of its id.
281
- const pkgs = new Map([...nodes.values()].map((node) => [idOf(node.key), node.pkg]))
281
+ const pkgs = new Map(nodes.values().map((node) => [idOf(node.key), node.pkg]))
282
282
  const edges = (id) => Object.values({ ...pkgs.get(id)?.dependencies, ...pkgs.get(id)?.optionalDependencies }).map(idOf)
283
283
  const building = builds.map((build) => {
284
284
  const where = quote(build.key)
@@ -302,9 +302,9 @@ export function hoistedBinTargets({ nodes, projects, modules, builds = [], hardl
302
302
  return fixedFiles(nodes, fixed, contested, major)
303
303
  }
304
304
 
305
- // pnpm 9 and 12 read each linked file's `#!` line. '' is the package.
305
+ // pnpm 12 reads each linked file's `#!` line. '' is the package.
306
306
  export function failsAsDirectory(node, path, major) {
307
- if (major >= 10 && major < 12) return false
307
+ if (major < 12) return false
308
308
  const prefix = `${path}/`
309
309
  return path === '' || node.files.keys().some((name) => name.startsWith(prefix))
310
310
  }
@@ -324,9 +324,10 @@ function fixedFiles(nodes, fixed, contested, major) {
324
324
  }
325
325
  const byNode = new Map()
326
326
  for (const [target, owner] of fixed) {
327
+ const node = nodes.get(owner)
327
328
  const path = target.slice(owner.length + 1)
328
- checkDirectory(nodes.get(owner), path)
329
- if (nodes.get(owner).files.get(path)?.data === undefined) continue
329
+ checkDirectory(node, path)
330
+ if (node.files.get(path)?.data === undefined) continue
330
331
  if (!byNode.has(owner)) byNode.set(owner, new Set())
331
332
  byNode.get(owner).add(path)
332
333
  }
@@ -1,7 +1,5 @@
1
1
  // A package's commands as @pnpm/package-bins reads them to link its bins, or
2
- // pnpm 12's bin_resolver crate, which reads a package.json unnormalized. pnpm 9
3
- // filters a command by its name before it drops the scope, and links a `bin`
4
- // string or a directories.bin wherever it leads.
2
+ // pnpm 12's bin_resolver crate, which reads a package.json unnormalized.
5
3
 
6
4
  import { compareVersions, valid } from '@preventive/upstream/semver.js'
7
5
  import { basename, compareNames, join } from '@preventive/vfs/path.js'
@@ -10,7 +8,7 @@ import { checkNesting } from '../manifest.js'
10
8
  import { within } from '../mount.js'
11
9
 
12
10
  // A package whose directory has no package.json is still linked by these names
13
- // by pnpm 10, to the runtime's binary inside it; pnpm 9 links none.
11
+ // by pnpm 10, to the runtime's binary inside it.
14
12
  const RUNTIMES = { __proto__: null, node: 'bin/node', deno: 'deno', bun: 'bun' }
15
13
 
16
14
  // The packages pnpm 11 and 12 take to own a command by a name not their own.
@@ -97,21 +95,15 @@ function commands12(dir, manifest, files, base, where) {
97
95
  return filesAsCommands(filesUnder(files, base, root, { dots: true }).filter((path) => safeName(basename(path))), root, common)
98
96
  }
99
97
 
100
- const outOf = (rel, where) => new DeptreeError(`${quote(rel)} leads out of the package, which pnpm 9 links a bin to all the same, and that is not supported`, where)
101
-
102
98
  const uriSafe = (name) => name === encodeURIComponent(name) || name === '$'
103
99
 
104
- // pnpm 9 also takes a scope with whatever follows it.
105
- const takes9 = (command) => uriSafe(command) || command[0] === '@'
106
-
107
100
  // `files` are the holding package's (itself, or the one bundling it), by path
108
101
  // under `base`; both are undefined for a project or `link:` target.
109
102
  export function commandsOf(dir, manifest, files, base, where, major) {
110
103
  if (major >= 12) return commands12(dir, manifest, files, base, where)
111
104
  const common = { pkgName: manifest.name, pkgVersion: manifest.version, owner: base }
112
105
  if (typeof manifest.bin === 'string' && !manifest.name) throw new DeptreeError('it has a bin and no name, which pnpm fails on', where)
113
- // pnpm 9 knows no runtime.
114
- if (major >= 10 && downloadsNode(manifest.engines?.runtime, where)) {
106
+ if (downloadsNode(manifest.engines?.runtime, where)) {
115
107
  throw new DeptreeError('its engines.runtime has pnpm look for a Node to run its bins with, which is not supported', where)
116
108
  }
117
109
  if (manifest.bin) {
@@ -120,13 +112,12 @@ export function commandsOf(dir, manifest, files, base, where, major) {
120
112
  const commands = []
121
113
  for (const [command, rel] of entries) {
122
114
  const name = command[0] === '@' ? command.slice(command.indexOf('/') + 1) : command
123
- if (!(major < 10 ? string || takes9(command) : uriSafe(name))) continue
115
+ if (!uriSafe(name)) continue
124
116
  if (name === '' || name === '.' || name === '..' || name.includes('/')) {
125
117
  if (major >= 11) continue
126
118
  throw new DeptreeError(`a bin named ${quote(name)} is not supported`, where)
127
119
  }
128
120
  const target = inPackage(dir, rel, where)
129
- if (target === undefined && major < 10 && string) throw outOf(rel, where)
130
121
  if (target !== undefined) commands.push({ ...common, name, target })
131
122
  }
132
123
  return commands
@@ -134,7 +125,6 @@ export function commandsOf(dir, manifest, files, base, where, major) {
134
125
  const binDir = manifest.directories?.bin
135
126
  if (!binDir) return []
136
127
  const root = inPackage(dir, binDir, where)
137
- if (root === undefined && major < 10) throw outOf(binDir, where)
138
128
  if (root === undefined) return []
139
129
  if (files === undefined) return [UNKNOWN]
140
130
  return filesAsCommands(filesUnder(files, base, root), root, common)
@@ -211,7 +201,7 @@ export function bundledCommands(node, where, major) {
211
201
  commands.push(...commandsOf(dir, major >= 12 ? manifest : normalized(manifest, here), node.files, node.dir, here, major))
212
202
  } else if (major >= 11) {
213
203
  if (major < 12) throw new DeptreeError('it bundles a package with no package.json, whose bins pnpm 11 looks for above it', here)
214
- } else if (major >= 10 && name in RUNTIMES) {
204
+ } else if (name in RUNTIMES) {
215
205
  commands.push({ name, target: `${dir}/${RUNTIMES[name]}`, owner: node.dir, own: true, pkgName: '', pkgVersion: '' })
216
206
  }
217
207
  }