@preventive/deptree 1.3.3 → 1.4.1

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 +64 -78
  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 +6 -18
  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 +3 -2
  51. package/src/pnpm/patches.js +15 -13
  52. package/src/pnpm/production.js +41 -13
  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 +36 -26
  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
@@ -4,61 +4,32 @@
4
4
  // every directory is 0o755, and a file's mode its Unix mode as the zip crate
5
5
  // reads it, or 0o644 where it reads none; a symlink is a file of its target.
6
6
 
7
- import { utf8fromStringLoose, utf8toStringLoose } from '@exodus/bytes/utf8.js'
7
+ import { utf8fromStringLoose } from '@exodus/bytes/utf8.js'
8
8
  import { ArchiveError, unzip } from '@preventive/archive/zip.js'
9
9
  import { DeptreeError, quote } from '../error.js'
10
10
  import { bytesSha256Hex } from '../hash.js'
11
11
  import { MAX_BYTES } from '../tarball.js'
12
12
 
13
- const END = 0x06054b50
14
- const CENTRAL = 0x02014b50
15
13
  const UTF8 = 0x0800
14
+ const NON_ASCII = /[^\u0020-\u007E]/u
16
15
  const S_IFLNK = 0o120000
17
16
  const [NTFS, TIMESTAMP, UNICODE_COMMENT, AES] = [0x000a, 0x5455, 0x6375, 0x9901]
18
17
 
19
- // As the archive reader decodes a name: a leading U+FEFF is part of it.
20
-
21
18
  const ones = (byte) => [...byte.toString(2)].filter((bit) => bit === '1').length
22
19
 
23
20
  // Why the zip crate would fail on an entry's extra fields, or undefined; an
24
21
  // AES or a Unicode comment field is refused here.
25
- function extraRefusal(view, at, length) {
26
- for (let pos = at; pos < at + length;) {
27
- const id = view.getUint16(pos, true)
28
- const size = view.getUint16(pos + 2, true)
29
- const body = pos + 4
30
- if (id === NTFS && (size !== 32 || view.getUint16(body + 4, true) !== 1 || view.getUint16(body + 6, true) !== 24)) return 'an NTFS extra field the zip crate does not read'
31
- if (id === TIMESTAMP && (size === 0 || (size !== 5 && size !== 1 + 4 * ones(view.getUint8(body))))) return 'an extended timestamp the zip crate does not read'
22
+ function extraRefusal(extra) {
23
+ for (const { id, data } of extra) {
24
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength)
25
+ if (id === NTFS && (data.length !== 32 || view.getUint16(4, true) !== 1 || view.getUint16(6, true) !== 24)) return 'an NTFS extra field the zip crate does not read'
26
+ if (id === TIMESTAMP && (data.length === 0 || (data.length !== 5 && data.length !== 1 + 4 * ones(data[0])))) return 'an extended timestamp the zip crate does not read'
32
27
  if (id === AES) return 'an AES extra field, which has the zip crate decrypt the entry'
33
28
  if (id === UNICODE_COMMENT) return 'a Unicode comment extra field, which the zip crate checks'
34
- pos = body + size
35
29
  }
36
30
  return undefined
37
31
  }
38
32
 
39
- // What the zip crate reads of each entry that unzip does not hand out. unzip
40
- // has checked the layout whole, so each record is where it says.
41
- function centralRecords(bytes) {
42
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
43
- let end = bytes.length - 22
44
- while (view.getUint32(end, true) !== END || end + 22 + view.getUint16(end + 20, true) !== bytes.length) end--
45
- const records = []
46
- let at = view.getUint32(end + 16, true)
47
- for (let i = 0; i < view.getUint16(end + 10, true); i++) {
48
- if (view.getUint32(at, true) !== CENTRAL) throw new Error('unreachable: a central record where unzip found none')
49
- const [nameLength, extraLength, commentLength] = [at + 28, at + 30, at + 32].map((field) => view.getUint16(field, true))
50
- records.push({
51
- system: view.getUint8(at + 5),
52
- flags: view.getUint16(at + 8, true),
53
- attributes: view.getUint32(at + 38, true),
54
- name: bytes.subarray(at + 46, at + 46 + nameLength),
55
- extra: extraRefusal(view, at + 46 + nameLength, extraLength),
56
- })
57
- at += 46 + nameLength + extraLength + commentLength
58
- }
59
- return records
60
- }
61
-
62
33
  // The zip crate's ZipFileData::unix_mode; system 0 is MS-DOS, and 3 Unix.
63
34
  function unixMode({ system, attributes }) {
64
35
  if (attributes === 0) return undefined
@@ -86,16 +57,14 @@ export async function extractZip(bytes, checksum, where) {
86
57
  if (error instanceof ArchiveError) throw new DeptreeError(`its zip cannot be read: ${error.message}`, where, { cause: error })
87
58
  throw error
88
59
  }
89
- const records = centralRecords(bytes)
90
60
  // The zip crate keys entries by their names' bytes, here the stored names:
91
61
  // of two of one name, the later is extracted where the first was.
92
62
  const last = new Map()
93
63
  for (const [index, entry] of entries.entries()) {
94
- const record = records[index]
95
- if (utf8toStringLoose(record.name) !== entry.storedName) throw new Error('unreachable: unzip lists entries out of the central directory\'s order')
96
64
  const here = `${where}: ${quote(entry.storedName)}`
97
- if (record.extra !== undefined) throw new DeptreeError(`${record.extra}, which Soldeer fails on`, here)
98
- if (!(record.flags & UTF8) && record.name.some((byte) => byte >= 0x80)) throw new DeptreeError('a name not flagged UTF-8, which Soldeer reads as CP437, is not supported', here)
65
+ const refusal = extraRefusal(entry.extra)
66
+ if (refusal !== undefined) throw new DeptreeError(`${refusal}, which Soldeer fails on`, here)
67
+ if (!(entry.flags & UTF8) && NON_ASCII.test(entry.storedName)) throw new DeptreeError('a name not flagged UTF-8, which Soldeer reads as CP437, is not supported', here)
99
68
  last.set(entry.storedName, index)
100
69
  }
101
70
  const dirs = new Set()
@@ -111,7 +80,7 @@ export async function extractZip(bytes, checksum, where) {
111
80
  dirs.add(entry.name)
112
81
  continue
113
82
  }
114
- const mode = unixMode(records[index])
83
+ const mode = unixMode(entry)
115
84
  const data = entry.type === 'symlink' ? utf8fromStringLoose(entry.linkname) : entry.data
116
85
  // A file written again keeps its mode where the zip crate reads none.
117
86
  const kept = mode === undefined || (mode & S_IFLNK) === S_IFLNK ? files.get(entry.name)?.mode ?? 0o644 : mode & 0o777 & ~0o022
package/src/tarball.js CHANGED
@@ -123,9 +123,7 @@ export async function fetchTarball(name, version, given, where, { metadata, cach
123
123
  const integrity = given ?? meta.dist.integrity
124
124
  if (!SHA512.test(integrity)) throw new DeptreeError('a tarball with no sha512 integrity is not supported', where)
125
125
  const dist = { tarball: tarballUrl(name, version), integrity }
126
- let about = NO_ABOUT
127
- if (meta !== undefined) about = aboutOf(meta)
128
- else if (metadata) about = getMeta(name, version, { dist, cache }).then(aboutOf)
126
+ const about = meta === undefined ? (metadata ? getMeta(name, version, { dist, cache }).then(aboutOf) : NO_ABOUT) : aboutOf(meta)
129
127
  const [bytes, said] = await settled([getTarball(name, version, dist, { cache }), about])
130
128
  if (!await matchesIntegrity(bytes, integrity)) throw new DeptreeError(`the tarball is not ${integrity}`, where)
131
129
  if (bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the tarball is not gzipped', where)
@@ -63,7 +63,9 @@ export class Hoister {
63
63
  sorted.push(item)
64
64
  available.add(pattern)
65
65
  changed = true
66
- } else queue.push(item)
66
+ } else {
67
+ queue.push(item)
68
+ }
67
69
  }
68
70
  }
69
71
  for (const [pattern, parent] of sorted.concat(queue)) {
@@ -89,7 +91,7 @@ export class Hoister {
89
91
  }
90
92
 
91
93
  propagateRequired() {
92
- const toVisit = [...this.tree.values()].filter((info) => info.isRequired)
94
+ const toVisit = this.tree.values().filter((info) => info.isRequired).toArray()
93
95
  // In yarn's order, but by index, as shift() copies a long array.
94
96
  for (let i = 0; i < toVisit.length; i++) {
95
97
  const info = toVisit[i]
@@ -14,8 +14,9 @@ export function cleanDependencies(manifest) {
14
14
  for (const kind of kinds) {
15
15
  const list = manifest[kind]
16
16
  for (const name of Object.keys(list)) {
17
- if (seen.has(name)) delete list[name]
18
- else {
17
+ if (seen.has(name)) {
18
+ delete list[name]
19
+ } else {
19
20
  list[name] = ranges.get(name) ?? list[name]
20
21
  seen.add(name)
21
22
  }
@@ -19,7 +19,7 @@ export function workspacesOf(manifests) {
19
19
  const workspaces = new Map()
20
20
  const found = new Set()
21
21
  for (const glob of globsOf(root)) {
22
- const dirs = [...manifests.keys()].filter((dir) => dir !== '.' && !found.has(dir) && matchesGlob(glob, dir))
22
+ const dirs = manifests.keys().filter((dir) => dir !== '.' && !found.has(dir) && matchesGlob(glob, dir)).toArray()
23
23
  dirs.sort((a, b) => `${a}/package.json`.localeCompare(`${b}/package.json`, 'en'))
24
24
  for (const dir of dirs) {
25
25
  found.add(dir)
@@ -119,9 +119,13 @@ class Resolver {
119
119
  return { kind, name, version: entry.version, entry, dir }
120
120
  }
121
121
 
122
+ refsOf(name) {
123
+ return (this.byName.get(name) ?? []).map((pattern) => this.patterns.get(pattern))
124
+ }
125
+
122
126
  // exoticRangeMatch: the package of `name` copied from `dir` already.
123
127
  copyOf(name, dir) {
124
- return this.byName.get(name)?.map((pattern) => this.patterns.get(pattern)).find((ref) => ref.kind === 'directory' && ref.dir === dir)
128
+ return this.refsOf(name).find((ref) => ref.kind === 'directory' && ref.dir === dir)
125
129
  }
126
130
 
127
131
  // No resolution applies to a top-level request.
@@ -138,7 +142,7 @@ class Resolver {
138
142
  }
139
143
 
140
144
  exactMatch(name, version) {
141
- return this.byName.get(name)?.map((pattern) => this.patterns.get(pattern)).find((ref) => ref.version === version)
145
+ return this.refsOf(name).find((ref) => ref.version === version)
142
146
  }
143
147
 
144
148
  // Waits where a package of its name and version is resolved already; else
@@ -180,8 +184,11 @@ class Resolver {
180
184
  start(request) {
181
185
  const rule = this.ruleOf(request)
182
186
  if (rule !== undefined) {
183
- if (this.patterns.has(rule.pattern)) this.divert(request, rule)
184
- else this.diverted.push([request, rule])
187
+ if (this.patterns.has(rule.pattern)) {
188
+ this.divert(request, rule)
189
+ } else {
190
+ this.diverted.push([request, rule])
191
+ }
185
192
  return undefined
186
193
  }
187
194
  const info = this.infoOf(request)
@@ -252,8 +259,11 @@ class Resolver {
252
259
  turn(strands) {
253
260
  const next = []
254
261
  for (const strand of strands) {
255
- if (--strand.left > 0) next.push(strand)
256
- else next.push(...this.check(strand.request, strand.info).map((child) => this.start(child)).filter(Boolean))
262
+ if (--strand.left > 0) {
263
+ next.push(strand)
264
+ } else {
265
+ next.push(...this.check(strand.request, strand.info).map((child) => this.start(child)).filter(Boolean))
266
+ }
257
267
  }
258
268
  return next
259
269
  }
package/src/yarn1/tree.js CHANGED
@@ -175,8 +175,11 @@ function writeTree(placed, fetched) {
175
175
  }
176
176
  const pkg = fetched.get(ref)
177
177
  const earlier = copies.get(dest)
178
- if (earlier?.[0].ref === ref) earlier.push(info)
179
- else copies.set(dest, [info])
178
+ if (earlier?.[0].ref === ref) {
179
+ earlier.push(info)
180
+ } else {
181
+ copies.set(dest, [info])
182
+ }
180
183
  writeFiles(vfs, dest, pkg, counted, skipped)
181
184
  left.set(pkg, left.get(pkg) - 1)
182
185
  if (left.get(pkg) === 0) letGo(pkg)
@@ -199,15 +202,16 @@ function listInstalled(copies, fetched, asked, hoister) {
199
202
  }
200
203
 
201
204
  export async function buildYarn1Tree(options) {
202
- const { host: given, vfs: into } = options ?? {}
205
+ const given = options ?? {}
206
+ const into = given.vfs
203
207
  if (into !== undefined && !(into instanceof Vfs)) throw new TypeError('vfs must be a Vfs, or left out')
204
- const fetching = fetchingOf(options ?? {})
208
+ const fetching = fetchingOf(given)
205
209
  for (const option of ['sizeEstimateOnly', 'lazy']) {
206
210
  if (fetching[option]) throw new TypeError(`${option} is not taken for yarn 1, which hoists and leaves out packages by what their package.json says, which only their tarballs hold`)
207
211
  }
208
- const production = productionOf(options ?? {})
209
- const inputs = inputsOf(options ?? {})
210
- const host = checkHost(given, inputs.manifests.get('.'))
212
+ const production = productionOf(given)
213
+ const inputs = inputsOf(given)
214
+ const host = checkHost(given.host, inputs.manifests.get('.'))
211
215
  const folded = host.os === 'darwin'
212
216
  // Refused before anything is fetched; mount checks again.
213
217
  if (into !== undefined) checkNoModules(into, folded)
@@ -219,7 +223,7 @@ export async function buildYarn1Tree(options) {
219
223
  checkBinLinks({ placed, patterns: resolved.patterns, locations, realOf: (path) => realOf(links, path) })
220
224
  const stats = {
221
225
  packages,
222
- skipped: [...manifestOf.keys()].filter((ref) => ref.incompatible).length,
226
+ skipped: manifestOf.keys().filter((ref) => ref.incompatible).toArray().length,
223
227
  installed: placed.filter(({ info }) => info.ref.kind !== 'workspace').length,
224
228
  files,
225
229
  bytes,
@@ -1,67 +0,0 @@
1
- // A git dependency as Soldeer 0.12 installs it, `git clone` and then `git
2
- // checkout` of the lockfile's rev, from GitHub's tarball of that commit's
3
- // tree 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
- import { isGit } from './zip.js'
11
-
12
- // A GitHub repository as git takes its URL over the protocols Soldeer has
13
- // it allow, https and ssh, `.git` after it or not, the scheme and host in
14
- // any case: https://github.com/<repo>, ssh://git@github.com/<repo> and
15
- // git@github.com:<repo>. The owner and name are as GitHub takes them.
16
- const REPO = String.raw`(?<repo>(?=[\dA-Za-z-]{1,39}\/)[\dA-Za-z](?:-?[\dA-Za-z])*\/[\w.-]{1,100}?)(?:\.git)?`
17
- const URL_FORM = new RegExp(String.raw`^(?:(?i:https):\/\/|(?i:ssh):\/\/git@)(?i:github\.com)\/${REPO}\/?$`, 'u')
18
- const SCP_FORM = new RegExp(String.raw`^git@(?i:github\.com):${REPO}$`, 'u')
19
-
20
- export function githubRepoOf(url) {
21
- const repo = (URL_FORM.exec(url) ?? SCP_FORM.exec(url))?.groups.repo
22
- return repo === undefined || /\/\.\.?$/u.test(repo) ? undefined : repo
23
- }
24
-
25
- // A repository renamed or transferred since the lockfile named it, which
26
- // GitHub answers with a redirect that git's clone follows, is asked for by
27
- // the name GitHub gives it now, as upstream's getRepo follows the redirect;
28
- // any other redirect is refused there. The commit holds what is fetched.
29
- async function tarballOf(github, repo, rev) {
30
- try {
31
- return await github.getRepoTarball({ repo, sha: rev })
32
- } catch (error) {
33
- if (!(error instanceof HttpError) || error.status < 300 || error.status >= 400) throw error
34
- const moved = await github.getRepo({ repo, followRedirect: true })
35
- return await github.getRepoTarball({ repo: moved.full_name, sha: rev })
36
- }
37
- }
38
-
39
- // GitHub's tarball, which upstream holds to the tree GitHub names for the
40
- // commit, files, symlinks and the submodules it shows as empty directories
41
- // alike. Unpacked as a checkout with umask 0o022 writes it: directories
42
- // 0o755, files 0o644 or 0o755 by the bit git keeps, symlinks as symlinks.
43
- export async function checkoutOf(github, repo, rev, where) {
44
- const bytes = await tarballOf(github, repo, rev)
45
- let entries
46
- try {
47
- entries = unpack(await decompress(bytes, 'gzip', { limit: MAX_BYTES }))
48
- } catch (error) {
49
- if (error instanceof ArchiveError) throw new DeptreeError(`its tarball from GitHub cannot be read: ${error.message}`, where, { cause: error })
50
- throw error
51
- }
52
- const top = entries[0]?.name.split('/')[0]
53
- const dirs = new Set()
54
- const files = new Map()
55
- const links = new Map()
56
- for (const entry of entries) {
57
- if (entry.name === top) continue
58
- if (!entry.name.startsWith(`${top}/`)) throw new Error('unreachable: an entry outside the one top directory upstream holds the tarball to')
59
- const path = entry.name.slice(top.length + 1)
60
- if (path.split('/').some(isGit)) throw new DeptreeError('a path with a .git in it, which git refuses to check out', `${where}: ${quote(path)}`)
61
- if (entry.type === 'directory') dirs.add(path)
62
- else if (entry.type === 'symlink') links.set(path, entry.linkname)
63
- else if (entry.type === 'file') files.set(path, { data: entry.data, mode: entry.mode & 0o100 ? 0o755 : 0o644 })
64
- else throw new Error(`unreachable: a ${entry.type} in a tarball of a git tree`)
65
- }
66
- return { dirs, files, links }
67
- }