@preventive/deptree 1.3.2 → 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 (68) 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 +24 -6
  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 +3 -6
  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/pnpm/write.js +2 -1
  60. package/src/soldeer/tree.js +2 -2
  61. package/src/soldeer/zip.js +11 -42
  62. package/src/tarball.js +1 -3
  63. package/src/yarn1/hoist.js +4 -2
  64. package/src/yarn1/manifest.js +3 -2
  65. package/src/yarn1/requests.js +1 -1
  66. package/src/yarn1/resolve.js +16 -6
  67. package/src/yarn1/tree.js +12 -8
  68. package/src/soldeer/git.js +0 -67
@@ -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
- }