@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/bin/compare.js CHANGED
@@ -30,8 +30,11 @@ export function projectView(root) {
30
30
  }
31
31
 
32
32
  // What deptree never builds: the .bin directories, each package manager's
33
- // record of its install, and the .git of a dependency Soldeer clones.
34
- const NOT_BUILT = /(?:^|\/)node_modules\/(?:\.bin|\.modules\.yaml|\.pnpm-workspace-state(?:-v\d+)?\.json|\.pnpm\/lock\.yaml|\.package-lock\.json|\.yarn-integrity)(?:\/|$)|^dependencies\/[^/]+\/\.git(?:\/|$)/u
33
+ // record of its install and pnpm 11's unread package map, the .git of a
34
+ // dependency Soldeer clones, and what CocoaPods generates in Pods beside the
35
+ // pods but its record, Manifest.lock: the podspecs of pods by :path, headers,
36
+ // support files and the projects.
37
+ const NOT_BUILT = /(?:^|\/)node_modules\/(?:\.bin|\.modules\.yaml|\.pnpm-workspace-state(?:-v\d+)?\.json|\.pnpm\/lock\.yaml|\.package-lock\.json|\.package-map\.json|\.yarn-integrity)(?:\/|$)|^dependencies\/[^/]+\/\.git(?:\/|$)|^Pods\/(?:Local Podspecs|Headers|Target Support Files|\.project_cache|[^/]+\.xcodeproj)(?:\/|$)/u
35
38
 
36
39
  // Everything under each of `dirs` as `view` has it, the disk's projectView
37
40
  // or the tree's Vfs: links not followed, every file read whole, and a
package/bin/deptree.js CHANGED
@@ -11,41 +11,58 @@ import { createClient } from '@preventive/upstream/github.js'
11
11
  import { defaultCacheDir, setCacheDir } from '@preventive/upstream/npm.js'
12
12
  import { join } from '@preventive/vfs/path.js'
13
13
  import { buildCargoTree } from '../cargo.js'
14
+ import { buildCocoaPodsTree } from '../cocoapods.js'
14
15
  import { buildNpmTree, findNpmWorkspaces } from '../npm.js'
15
16
  import { DeptreeError, LockfileError, buildPnpmTree, findPnpmProjects } from '../pnpm.js'
16
17
  import { TomlError, buildSoldeerTree } from '../soldeer.js'
17
18
  import { buildYarn1Tree, findYarn1Workspaces } from '../yarn1.js'
18
19
  import { escaped } from '../src/error.js'
19
- import { typeOf } from '../src/project.js'
20
+ import { readText, typeOf } from '../src/project.js'
20
21
  import { difference, leftBehind, leftOut, projectView, readSide } from './compare.js'
21
22
  import { userToken } from './npmrc.js'
22
23
 
23
24
  const USAGE = `Usage: deptree compare [options] [<dir>]
24
25
 
25
26
  Builds the tree the lockfile in <dir> (by default .) installs, from
26
- pnpm-lock.yaml, package-lock.json, yarn.lock, soldeer.lock or Cargo.lock,
27
- and lists where it differs from what is on disk, every node_modules of the
28
- project, Soldeer's dependencies or cargo's vendor:
27
+ pnpm-lock.yaml, package-lock.json, yarn.lock, soldeer.lock, Cargo.lock or
28
+ Podfile.lock, and lists where it differs from what is on disk, every
29
+ node_modules of the project, Soldeer's dependencies, cargo's vendor or the
30
+ pods' directories and Manifest.lock in CocoaPods' Pods:
29
31
 
30
32
  + <path> only in the tree
31
33
  - <path> only on disk
32
34
  ~ <path> in both, but of another type, content, mode or link target
33
35
 
34
36
  A directory one side has alone is one line, ending in /. Left out unless
35
- --all: .bin directories, state files, Soldeer's .git, and directories on
36
- disk holding nothing else. Exits 0 where the two are the same, 1 where
37
- they differ, 2 on trouble.
37
+ --all: .bin directories, state files, Soldeer's .git, what CocoaPods
38
+ generates in Pods but Manifest.lock, and directories on disk holding
39
+ nothing else. Exits 0 where the two are the same, 1 where they differ, 2
40
+ on trouble.
38
41
 
39
- Tarballs, zips and crates are kept in ${defaultCacheDir ?? 'no cache, as no home directory is known'}.
42
+ A pod by :podspec is built by its podspec in Pods/Local Podspecs, which
43
+ SPEC CHECKSUMS holds, and an archive by :http by the podspec's sha256 of
44
+ it. A pod by a git tag, which the lockfile holds no commit for, is not
45
+ built.
46
+
47
+ Tarballs, zips, crates, podspecs and archives are kept in ${defaultCacheDir ?? 'no cache, as no home directory is known'}.
40
48
  A scoped package is fetched with PREVENTIVE_MEASURES_NPM_TOKEN,
41
49
  STASIS_NPM_TOKEN or NPM_TOKEN, else with a ~/.npmrc line of nothing but
42
- //registry.npmjs.org/:_authToken=npm_\u2026; a Soldeer git dependency with
43
- GITHUB_TOKEN or GH_TOKEN, else anonymously.
50
+ //registry.npmjs.org/:_authToken=npm_\u2026; a Soldeer git dependency or a
51
+ pod with GITHUB_TOKEN or GH_TOKEN, else anonymously.
44
52
 
45
- --pnpm, --yarn, --npm, --soldeer, --cargo <version>
53
+ --pnpm, --yarn, --npm, --soldeer, --cargo, --cocoapods <version>
46
54
  the one that installed: by default the one
47
- packageManager pins, or Soldeer 0.12.0; npm's and
48
- cargo's are needed
55
+ packageManager pins, Soldeer 0.12.0, or the
56
+ CocoaPods Podfile.lock names; npm's and cargo's are
57
+ needed
58
+ --platform <name> a platform the Podfile's targets are for, ios, osx,
59
+ tvos, visionos or watchos, once for each; needed
60
+ where a pod names other files on another
61
+ --partial compare the pods deptree downloads alone, leaving
62
+ out each it does not for where it is from -- a spec
63
+ repo but trunk, an external source but :path and
64
+ :podspec, a source but git by a commit and :http
65
+ from GitHub, a prepare_command -- and saying why
49
66
  --node <version> the Node it installed with; by default this one
50
67
  --production devDependencies were left out, as by pnpm install
51
68
  --prod, npm ci --omit=dev or yarn install --production
@@ -63,6 +80,9 @@ const OPTIONS = {
63
80
  npm: { type: 'string' },
64
81
  soldeer: { type: 'string' },
65
82
  cargo: { type: 'string' },
83
+ cocoapods: { type: 'string' },
84
+ platform: { type: 'string', multiple: true },
85
+ partial: { type: 'boolean' },
66
86
  node: { type: 'string' },
67
87
  metadata: { type: 'boolean', default: false },
68
88
  production: { type: 'boolean', default: false },
@@ -73,8 +93,11 @@ const OPTIONS = {
73
93
 
74
94
  // Each package manager by its version flag: its lockfile, the folder it
75
95
  // installs into in each project it finds, and the version where the flag is
76
- // left out and nothing pins one, or, `unpinned`, that the flag is needed;
77
- // `development`, that it installs every dependency, there being no other kind.
96
+ // left out and nothing pins one, or, `pinned`, what the project pins, or,
97
+ // `unpinned`, that the flag is needed; `development`, that it installs every
98
+ // dependency, there being no other kind.
99
+ const github = () => createClient({ token: process.env.GITHUB_TOKEN || process.env.GH_TOKEN || null })
100
+
78
101
  const MANAGERS = {
79
102
  pnpm: { lockfile: 'pnpm-lock.yaml', folder: 'node_modules', projects: findPnpmProjects, build: buildPnpmTree },
80
103
  yarn: { lockfile: 'yarn.lock', folder: 'node_modules', projects: findYarn1Workspaces, build: buildYarn1Tree },
@@ -85,9 +108,19 @@ const MANAGERS = {
85
108
  version: '0.12.0',
86
109
  development: true,
87
110
  projects: () => ['.'],
88
- build: (options) => buildSoldeerTree({ ...options, github: createClient({ token: process.env.GITHUB_TOKEN || process.env.GH_TOKEN || null }) }),
111
+ build: (options) => buildSoldeerTree({ ...options, github: github() }),
89
112
  },
90
113
  cargo: { lockfile: 'Cargo.lock', folder: 'vendor', unpinned: true, development: true, projects: () => ['.'], build: buildCargoTree },
114
+ // The pods' directories and Manifest.lock, a copy of the lockfile: what
115
+ // else is in Pods, CocoaPods generates.
116
+ cocoapods: {
117
+ lockfile: 'Podfile.lock',
118
+ folder: 'Pods',
119
+ pinned: (project) => /^COCOAPODS: (\S+)$/mu.exec(readText(project, '/Podfile.lock', 'Podfile.lock') ?? '')?.[1],
120
+ development: true,
121
+ projects: () => ['.'],
122
+ build: (options) => buildCocoaPodsTree({ ...options, github: github(), manifest: true }),
123
+ },
91
124
  }
92
125
 
93
126
  async function main(argv) {
@@ -101,21 +134,28 @@ async function main(argv) {
101
134
  const project = projectView(resolve(dir))
102
135
  const name = managerOf(project, dir, values)
103
136
  const manager = MANAGERS[name]
104
- if (values.production && manager.development) fail(`deptree: ${manager.lockfile}: --production is not taken: ${name === 'cargo' ? 'cargo vendor vendors dev-dependencies too' : 'Soldeer has no devDependencies to leave out'}\n`)
137
+ if (values.production && manager.development) fail(`deptree: ${manager.lockfile}: --production is not taken: ${DEVELOPMENT[name]}\n`)
138
+ for (const flag of ['platform', 'partial']) if (values[flag] !== undefined && name !== 'cocoapods') fail(`deptree: ${manager.lockfile}: --${flag} is taken for CocoaPods alone\n`)
105
139
  if (defaultCacheDir !== undefined) setCacheDir()
106
140
  // upstream reads it for each request, and sends it for a scoped package.
107
141
  process.env.NPM_TOKEN ||= userToken() ?? ''
108
142
  // This machine, which installed what is on disk; npm takes no libc where
109
143
  // there is none to find.
110
144
  const libc = libcOf()
111
- const host = { [name]: values[name] ?? manager.version, node: values.node ?? process.versions.node, os: process.platform, cpu: process.arch, ...(name === 'npm' && libc === 'unknown' ? {} : { libc }) }
145
+ const host = { [name]: values[name] ?? manager.version ?? manager.pinned?.(project), node: values.node ?? process.versions.node, os: process.platform, cpu: process.arch, ...(name === 'npm' && libc === 'unknown' ? {} : { libc }) }
112
146
  // The disk first, as it is before anything is fetched.
113
147
  const dirs = manager.projects({ project, host, os: host.os }).map((at) => join(at, manager.folder))
114
148
  const disk = readSide(project, dirs)
115
149
  const files = [...disk.values()].filter((entry) => entry.type === 'file')
116
150
  note(`${manager.folder} on disk: ${files.length} files, ${size(files.reduce((sum, file) => sum + file.data.length, 0))}`)
117
- const tree = await manager.build({ project, host, metadata: values.metadata, ...values.production ? { production: true } : {} })
151
+ const tree = await manager.build({ project, host, metadata: values.metadata, platforms: values.platform, partial: values.partial, ...values.production ? { production: true } : {} })
118
152
  note(`${manager.lockfile}: ${tree.stats.files} files, ${size(tree.stats.bytes)} built`)
153
+ // A pod --partial skips is CocoaPods' to download: its directory on disk
154
+ // is not compared. The reason quotes what it names, as a refusal does.
155
+ for (const { name: pod, reason } of tree.skipped ?? []) {
156
+ note(`not compared: ${reason}`)
157
+ for (const path of disk.keys()) if (path === `Pods/${pod}` || path.startsWith(`Pods/${pod}/`)) disk.delete(path)
158
+ }
119
159
  const built = readSide(tree.vfs, dirs)
120
160
  const changes = difference(disk, built)
121
161
  const left = values.all ? new Set() : leftOut(changes, disk)
@@ -130,6 +170,13 @@ async function main(argv) {
130
170
  return listed.length === 0 ? 0 : 1
131
171
  }
132
172
 
173
+ // Why --production means nothing to each manager that installs everything.
174
+ const DEVELOPMENT = {
175
+ soldeer: 'Soldeer has no devDependencies to leave out',
176
+ cargo: 'cargo vendor vendors dev-dependencies too',
177
+ cocoapods: 'CocoaPods installs every pod the Podfile asks for',
178
+ }
179
+
133
180
  // The one a version flag names, or else the one whose lockfile is there.
134
181
  function managerOf(project, dir, values) {
135
182
  const names = Object.keys(MANAGERS)
package/cocoapods.d.ts ADDED
@@ -0,0 +1,372 @@
1
+ import type { Client } from '@preventive/upstream/github.js'
2
+ import type { NodeType, Vfs } from '@preventive/vfs'
3
+
4
+ export { LockfileError } from '@preventive/lockfile/cocoapods.js'
5
+
6
+ // Where @preventive/upstream caches what it fetches, podspecs, GitHub's
7
+ // tarballs and archives by :http among them. Each is fetched through it,
8
+ // and that is the one place anything here touches a filesystem. Before the
9
+ // network, it takes a podspec from CocoaPods' own spec repos, under
10
+ // $CP_REPOS_DIR, else $CP_HOME_DIR/repos, else ~/.cocoapods/repos, where
11
+ // one there has the lockfile's checksum, and writes none of it; then from
12
+ // its own cache, where one is set, which is where it writes each it fetches
13
+ // -- setCacheDir() sets the default one, and setCacheDir(false) unsets it;
14
+ // unset, which it is until set, it writes nothing. CocoaPods' own download
15
+ // cache is never read. The project is read only through the view given as
16
+ // `project`, and the tree built in a Vfs.
17
+ export { setCacheDir } from '@preventive/upstream/npm.js'
18
+
19
+ // The machine CocoaPods would install on: `cocoapods` is the version that
20
+ // installs, exact, 1.13.0 to 1.17.x, which download, clean and lock a pod
21
+ // alike; `os` as Node names it -- `darwin` or `linux`. Windows is refused.
22
+ export interface CocoaPodsHost {
23
+ cocoapods: string
24
+ os: string
25
+ }
26
+
27
+ // What the Podfile's targets are for, as CocoaPods names a platform.
28
+ export type CocoaPodsPlatform = 'ios' | 'osx' | 'tvos' | 'visionos' | 'watchos'
29
+
30
+ // A view of the project's root, by paths from `/`: a Vfs, or anything with
31
+ // its readdir, lstat, stat and readFile, such as one of a directory on
32
+ // disk, of which only Podfile.lock and the Podfile are read there: the
33
+ // first of CocoaPods.podfile.yaml, CocoaPods.podfile, Podfile and
34
+ // Podfile.rb that is a file, as CocoaPods looks for one; and, where no
35
+ // `podspecs` are given, Pods/Local Podspecs/<name>.podspec.json for each
36
+ // pod by :podspec. The lockfile is read as UTF-8, and refused where it is
37
+ // not; the Podfile and the podspecs as bytes, the Podfile not read
38
+ // otherwise. Nothing is written to it.
39
+ export interface CocoaPodsProject {
40
+ readdir(path: string): string[]
41
+ lstat(path: string): { type: NodeType }
42
+ stat(path: string): { type: NodeType }
43
+ readFile(path: string): Uint8Array
44
+ }
45
+
46
+ // The files `pod install` reads at the project's root: Podfile.lock, and
47
+ // the Podfile, whose sha1 PODFILE CHECKSUM has to be, as CocoaPods resolves
48
+ // anew what a changed Podfile asks for. The Podfile is Ruby, and is not
49
+ // read otherwise: what it says beyond which pods it asks for -- the
50
+ // install! options, hooks, the targets and their platforms -- is not
51
+ // known here, and is taken to be as below.
52
+ //
53
+ // The two ways the files come, one or the other: given, with `lockfile`
54
+ // and, where it is, `podfile`, as text or bytes; or read, with `project`
55
+ // and neither of them. A Podfile given is held to PODFILE CHECKSUM as one
56
+ // read is; without one, nothing is.
57
+ //
58
+ // `platforms` are those the Podfile's targets are for, by CocoaPods' names;
59
+ // left out, any. A spec installed has to name the same files on each of
60
+ // those it takes, as the lockfile does not say which targets, of which
61
+ // platforms, it is installed for; one that names other files on another is
62
+ // refused. A spec for none of them is refused too.
63
+ //
64
+ // `podspecs` are the podspecs of the pods by :podspec, by name, each as
65
+ // text or bytes: the JSON CocoaPods writes of one as Pods/Local
66
+ // Podspecs/<name>.podspec.json, which is what SPEC CHECKSUMS has the sha1
67
+ // of, the podspec it evaluated and not its Ruby, which is not read here.
68
+ // Each is held to that checksum. Left out where `project` is given, those
69
+ // in the project's Pods/Local Podspecs are read; left out where `lockfile`
70
+ // is, there are none. One the lockfile has no pod by :podspec of is not
71
+ // read. A pod by :podspec without one is refused, or with `partial`
72
+ // skipped.
73
+ //
74
+ // `manifest` writes Pods/Manifest.lock too, CocoaPods' record of what is
75
+ // in Pods/: the lockfile's bytes, as CocoaPods writes the two alike, and
76
+ // as the Check Pods Manifest.lock phase of a build holds them to be. With
77
+ // it there, `pod install` downloads no pod whose directory is there and
78
+ // which the manifest has at the version, checksum, specs and dependency it
79
+ // resolves; it downloads only the pods whose directory is not there, or
80
+ // holds nothing but names that start with `.`, which it takes to be empty;
81
+ // then it generates the rest of Pods/ as it does. Without it, CocoaPods
82
+ // takes Pods/ to hold nothing, and downloads every pod again.
83
+ //
84
+ // `partial` skips each pod refused for where it is downloaded from, as the
85
+ // lockfile or its podspec says, rather than refusing the call: one from a
86
+ // spec repo but trunk, or an external source but :path and :podspec; one by
87
+ // :podspec without its podspec, or with CHECKOUT OPTIONS; one with a
88
+ // prepare_command; and one whose source is neither git from GitHub by a
89
+ // full commit, without its submodules, nor :http as below: one by a tag
90
+ // among them. Nothing is written for it, and it is listed in `skipped`, for
91
+ // CocoaPods to download: with `manifest`, it downloads those and no other.
92
+ // A podspec is held to the lockfile's checksum all the same, and an archive
93
+ // to its hash. Every other refusal stands. So everything written is held to
94
+ // a hash the lockfile holds, or that a podspec it holds does, whether
95
+ // `partial` is given or not.
96
+ //
97
+ // `vfs` is a Vfs to mount the tree into, at its root, which is taken to be
98
+ // the project's -- it may be `project` too; without one, a new Vfs holds
99
+ // the tree alone. A Vfs that holds a `Pods` at its root, or on macOS a name
100
+ // that is one there, is refused before anything is fetched, as CocoaPods
101
+ // keeps and removes what is in it by its own record of it. Nothing there
102
+ // is written over: each directory the tree has is one there or is made,
103
+ // and every file is written where nothing is. The tree is built, and held
104
+ // to every check below, before any of it is written, so a refusal leaves
105
+ // the Vfs as it was.
106
+ //
107
+ // `github` is the client from @preventive/upstream/github.js's createClient
108
+ // each pod is fetched through, with whatever token it was made with, or
109
+ // none. It is needed only where the lockfile has a pod CocoaPods
110
+ // downloads, and there it is a TypeError to leave it out, before anything
111
+ // is fetched.
112
+ export type CocoaPodsTreeOptions = CocoaPodsTreeGiven | CocoaPodsTreeRead
113
+
114
+ export interface CocoaPodsTreeGiven {
115
+ lockfile: string
116
+ podfile?: string | Uint8Array
117
+ project?: undefined
118
+ host: CocoaPodsHost
119
+ platforms?: CocoaPodsPlatform[]
120
+ podspecs?: Record<string, string | Uint8Array>
121
+ manifest?: boolean
122
+ partial?: boolean
123
+ vfs?: Vfs
124
+ github?: Client
125
+ }
126
+
127
+ export interface CocoaPodsTreeRead {
128
+ lockfile?: undefined
129
+ podfile?: undefined
130
+ project: CocoaPodsProject
131
+ host: CocoaPodsHost
132
+ platforms?: CocoaPodsPlatform[]
133
+ podspecs?: Record<string, string | Uint8Array>
134
+ manifest?: boolean
135
+ partial?: boolean
136
+ vfs?: Vfs
137
+ github?: Client
138
+ }
139
+
140
+ // What buildCocoaPodsTree counts, all of it plain numbers: `pods` the
141
+ // lockfile's roots; `downloaded` those written into Pods/, each a podspec
142
+ // and a tarball or an archive fetched, and the others those by :path, or
143
+ // skipped;
144
+ // `files` and `bytes` what is written, Manifest.lock among them, and
145
+ // `links` the symlinks.
146
+ export interface CocoaPodsTreeStats {
147
+ pods: number
148
+ downloaded: number
149
+ files: number
150
+ bytes: number
151
+ links: number
152
+ }
153
+
154
+ // A pod in the tree, as an SBOM would list it: `path` is its directory,
155
+ // from the project's root, which is `/` of the Vfs -- Pods/<name>; `name`
156
+ // and `version` the lockfile's, of the root; `checksum` the hex sha1 its
157
+ // podspec is held to, SPEC CHECKSUMS'; `pods` the specs of it installed,
158
+ // the root and its subspecs as PODS names them.
159
+ export type CocoaPodsInstalled = CocoaPodsInstalledGit | CocoaPodsInstalledHttp
160
+
161
+ export interface CocoaPodsInstalledPod {
162
+ path: string
163
+ name: string
164
+ version: string
165
+ checksum: string
166
+ pods: string[]
167
+ }
168
+
169
+ // From git: `git` is the repository's URL as the podspec gives it, and
170
+ // `commit` the commit the podspec names, which is checked out.
171
+ export interface CocoaPodsInstalledGit extends CocoaPodsInstalledPod {
172
+ git: string
173
+ commit: string
174
+ }
175
+
176
+ // By :http: `http` is the archive's URL as the podspec gives it, and
177
+ // `sha256` the podspec's hash of it, which it is held to.
178
+ export interface CocoaPodsInstalledHttp extends CocoaPodsInstalledPod {
179
+ http: string
180
+ sha256: string
181
+ }
182
+
183
+ // A pod `partial` skips: `name` and `version` the lockfile's, of the root;
184
+ // `reason` the refusal's message, as the call throws it without `partial`,
185
+ // leading with `pods["<name>"]`.
186
+ export interface CocoaPodsSkipped {
187
+ name: string
188
+ version: string
189
+ reason: string
190
+ }
191
+
192
+ // `vfs` is the one given, the tree mounted into it, or a new one.
193
+ // `installed` is each pod downloaded, in the lockfile's order; `skipped`
194
+ // each pod `partial` skips, in the lockfile's order, and none without it.
195
+ export interface CocoaPodsTree {
196
+ vfs: Vfs
197
+ stats: CocoaPodsTreeStats
198
+ installed: CocoaPodsInstalled[]
199
+ skipped: CocoaPodsSkipped[]
200
+ }
201
+
202
+ // The pods' directories `pod install` makes in Pods/ from the lockfile,
203
+ // with host.cocoapods, in a project with no Pods directory yet, its
204
+ // install! options at their defaults and no hook that changes what is
205
+ // downloaded, CocoaPods' download cache used, as it is unless
206
+ // COCOAPODS_SKIP_CACHE is set, and each pod in one pod target, as where
207
+ // the Podfile's targets that use a pod ask for the same specs of it: where
208
+ // they ask for others, CocoaPods makes a pod target of each, and makes the
209
+ // source files of the first of them read-only alone, which is not followed,
210
+ // as the lockfile has the specs of them all and not which target has
211
+ // which. The project's path and the cache's, ~/Library/Caches/CocoaPods or
212
+ // $CP_CACHE_DIR, are taken to have none of a glob's `*`, `?`, `[`, `]`, `{`
213
+ // and `}`, and to be as NFKC normalizes them, as CocoaPods cleans a pod's
214
+ // directory by its path as it is. Rooted at the project's root, it holds
215
+ // Pods/<name> for each root CocoaPods downloads, but those `partial`
216
+ // skips, and nothing else of the project; none at all where every pod is
217
+ // by :path, as CocoaPods reads those where they are. What CocoaPods writes
218
+ // beside them in Pods/ -- Manifest.lock, Local Podspecs, Headers, Target
219
+ // Support Files, Pods.xcodeproj -- is not written, but Manifest.lock with
220
+ // `manifest`, which is written whatever pods there are; nor is anything of
221
+ // the user's project.
222
+ //
223
+ // Each root's podspec is fetched from trunk and held to the lockfile's
224
+ // checksum, its sha1, with @preventive/upstream/cocoapods.js's getPodspec;
225
+ // that of a pod by :podspec is `podspecs`', held to it alike. Its `source`
226
+ // has to be a git repository on GitHub, by a full commit, or an archive on
227
+ // GitHub by :http, as below. A git source by a tag is refused: CocoaPods
228
+ // records no commit for one, and GitHub can move it, so nothing would hold
229
+ // what is downloaded to a hash. Of git, CocoaPods clones the repository and
230
+ // checks the commit out, and here GitHub's tarball of the commit's tree is
231
+ // fetched instead, by `github`: the tree read off the commit's own object,
232
+ // which upstream's getCommitTree fetches from github.com as git fetches it
233
+ // and holds to the commit's id, so that it is the commit's whatever
234
+ // GitHub's API says; and the tarball, which getRepoTreeTarball holds to
235
+ // that tree. A repository renamed or transferred since is fetched by the
236
+ // name GitHub gives it now, as upstream's getRepo follows that redirect
237
+ // with `followRedirect`. The checkout is as git writes one with no git
238
+ // config and a umask of 0o022: each directory 0o755, each file 0o644, or
239
+ // 0o755 where git has it executable; each symlink a symlink to its target;
240
+ // a submodule an empty directory; a file the tree's .gitattributes mark
241
+ // `eol=crlf` with CRLF, as upstream reads them. What git config on the
242
+ // machine would change -- `core.autocrlf`, a filter such as Git LFS's -- is
243
+ // not followed. GitHub's tarball is refused where upstream refuses it, and
244
+ // where the tar reader of @preventive/archive/tar.js does, and so is a path
245
+ // git refuses to check out: one with a `.git` in it, or its short name
246
+ // `git~1`, in any case, dots and spaces after it, or a `:` after that. A
247
+ // commit the podspec names has to be in the history of the repository's
248
+ // default branch, as GitHub answers for a commit of any fork, and for one
249
+ // no branch or tag reaches, which a clone does not have; one on another
250
+ // branch alone is refused too.
251
+ //
252
+ // An archive by :http has to be on GitHub, over https: its URL
253
+ // https://github.com/<owner>/<repo>/ and a path under it, such as GitHub's
254
+ // archive of a tag, `archive/refs/tags/<tag>.tar.gz` or `.zip`, or a
255
+ // release's asset, with no query, fragment, credentials or port, each
256
+ // segment of the path letters, digits, `_`, `.`, `~`, `@`, `-` or a
257
+ // %-escape in capitals. The podspec has to hold it to its :sha256, in
258
+ // lowercase hex, as RemoteFile checks one before a :sha1, and does: so the
259
+ // lockfile's checksum of the podspec is the archive's as well. One held to
260
+ // a :sha1 alone, which two archives can be made to share, is refused. It is
261
+ // fetched with upstream's getPodArchive, which follows GitHub's redirects
262
+ // and holds the bytes to that hash. Its type is RemoteFile's, by :type or
263
+ // else by the end of its URL's path: tgz, tar, tbz or txz, which it
264
+ // extracts with `tar xf`, or zip, with `unzip`; a dmg is refused.
265
+ //
266
+ // A tar is read by what it is, as `tar xf` reads it, gzipped or not, as GNU
267
+ // tar and bsdtar extract one for a user other than root, under a umask of
268
+ // 0o022: each file of its mode but the group's and others' write, each
269
+ // symlink to its target, a hard link a copy of what it links to, as
270
+ // CocoaPods' copies into its cache and into Pods/ make it. What one
271
+ // machine's tar would make otherwise than another's is refused: another
272
+ // compression than gzip, or a zip, which bsdtar reads and GNU tar does not;
273
+ // a setuid, setgid or sticky bit; a directory its owner cannot list and
274
+ // write in, or a file it cannot read, which CocoaPods' cleaner and copy
275
+ // would fail on; a name starting with `._`, which bsdtar on macOS reads as
276
+ // the extended attributes of another; a `.git` in a path; a FIFO or a
277
+ // device.
278
+ //
279
+ // A zip is read as Info-ZIP's unzip 6.0 extracts one under that umask: a
280
+ // file of the mode a Unix maker stored, but for a setuid, setgid or sticky
281
+ // bit, and of 0o644, or 0o444 by the DOS read-only bit, from any other
282
+ // maker, unless it stored a Unix mode that agrees with those bits, which is
283
+ // kept; a symlink by its mode, from a Unix maker; an MS-DOS volume label
284
+ // left out, as unzip skips one. Refused is what unzip would stop and ask
285
+ // about, which fails `pod install`, or write otherwise
286
+ // than @preventive/archive/zip.js reads it, beside what that reader
287
+ // refuses: an empty archive; a name again; an entry that needs PKZIP past
288
+ // 4.5, or is marked as stored in VMS format; an Amiga or THEOS maker; a
289
+ // name outside ASCII, or ending in a `.` segment or in `;` and digits; a
290
+ // directory its owner cannot list and write in, or a file it cannot read;
291
+ // a `.git` in a path.
292
+ //
293
+ // Either is then flattened as RemoteFile flattens it, by :flatten where
294
+ // that is given, as Ruby reads a value, and else a tar always and a zip
295
+ // never: where it holds one thing, and that a directory, its contents in
296
+ // its place. What its moves would meet is refused: the name it downloads
297
+ // the archive under, `file.<type>`, at its root; the one thing to flatten a
298
+ // link, or of a name ending in `.`, or holding its name and `.tmp`. An
299
+ // :http source with :headers, which curl sends, is refused.
300
+ //
301
+ // Every podspec is fetched and held to all that it says, below as here,
302
+ // before any tarball or archive is fetched, so that a pod refused costs no
303
+ // download; a tarball or an archive is fetched once, for all the pods of
304
+ // it.
305
+ //
306
+ // What CocoaPods then keeps of the download is what it keeps: it cleans
307
+ // the download in its cache, by the file patterns of every spec of the
308
+ // podspec on every platform each takes, copies that into Pods/, and cleans
309
+ // it again there by those of the specs the lockfile installs, each a
310
+ // Sandbox::PodDirCleaner, with a FileAccessor per spec and platform over a
311
+ // PathList of what is there. Each is followed as CocoaPods has it, with
312
+ // File.fnmatch as Ruby has it, case folded for ASCII alone: a pattern that
313
+ // is a path there taken as it is, else one that names a directory with
314
+ // what lies under it, then the braces expanded as PathList expands them
315
+ // and matched; exclude_files taken out; the readme and the license the
316
+ // first found where the podspec names no license file there; a path
317
+ // removed with all under it but where it ends in `.` or, downcased, it is a
318
+ // used file's path or one of the two is at the start of the other, as
319
+ // Ruby's `include?` finds it in the pod's directory's path. Each source
320
+ // file is then made read-only by its owner, through a link to the file it
321
+ // leads to, as lock_files! leaves it. A link is followed as the machine
322
+ // follows it, on macOS to a name whatever its case and normalization, up to
323
+ // 40 links on the way on Linux and 32 on macOS, past which the path leads
324
+ // nowhere, and a link to nothing at all leads nowhere. A link CocoaPods
325
+ // follows to find whether it leads to a directory, which is every link, and
326
+ // which leads out of the download, is refused, as what it finds there is
327
+ // the machine's.
328
+ //
329
+ // What CocoaPods fails on is refused: a podspec that is not JSON, a value
330
+ // of a type it fails on, a source file that links to nothing, a pod named
331
+ // as what it writes beside the pods in Pods/, a path in the download of
332
+ // 4096 bytes or more on Linux, 1024 on macOS, or with a name of more than
333
+ // 255. So is what CocoaPods cleans otherwise than its patterns say: a pod
334
+ // named with a glob's `*`, `?`, `[`, `]`, `{` or `}`, whose directory it
335
+ // then cleans by that glob; and, from 1.13 to 1.15, a pod whose patterns
336
+ // keep the .git of the clone that they copy into their cache, as what is in
337
+ // it is not known. And what one release of CocoaPods or Ruby reads
338
+ // otherwise than another: a platform named in another case, or `xros`; a
339
+ // value that breaks braces apart by a backslash; a path, a link's target or
340
+ // a pattern with a letter whose case Ruby maps otherwise in a release from
341
+ // 2.6 on than in another, as one encoded after Unicode 12.1. A pattern
342
+ // longer than 4096 characters, or that expands to more than 4096, is
343
+ // refused, and so is a pod whose patterns take more than 200,000,000
344
+ // matches of a path to clean it, and a readme or a license of two files of
345
+ // one name but for case, of which CocoaPods takes either. On macOS, a
346
+ // download with two names in one directory that differ only in case or
347
+ // normalization is refused, as they would be one name there and git's
348
+ // checkout writes one of them alone, whatever CocoaPods keeps of it.
349
+ //
350
+ // Pods come from trunk, as SPEC REPOS has it, by `trunk` or by the git
351
+ // repository of CocoaPods/Specs, by :podspec, or by :path: one from another
352
+ // spec repo, one from any other external source, one by :podspec that
353
+ // CHECKOUT OPTIONS has, which CocoaPods downloads by those, one with a
354
+ // prepare_command, which CocoaPods runs as a script in the download, and
355
+ // one whose source is neither git from GitHub, by a full commit and
356
+ // without its submodules, nor :http as above, is refused, or with `partial`
357
+ // skipped: one by a tag or a branch among them.
358
+ //
359
+ // Nothing is left to a guess: a lockfile the lockfile reader refuses, a pod
360
+ // from anywhere but trunk and :podspec, a check above that fails -- each is
361
+ // refused with a DeptreeError or a LockfileError that says where. A
362
+ // TypeError is thrown for options of the wrong type, and for a pod to
363
+ // download without `github`.
364
+ export function buildCocoaPodsTree(options: CocoaPodsTreeOptions): Promise<CocoaPodsTree>
365
+
366
+ // `where` is what a refusal is about -- `pods["Alamofire"]`, a path in a
367
+ // pod's download -- or undefined for the call as a whole; the message leads
368
+ // with it. `cause` is what a package beneath refused with, where one did.
369
+ export class DeptreeError extends Error {
370
+ constructor(detail: string, where?: string, options?: { cause?: unknown })
371
+ where: string | undefined
372
+ }
package/cocoapods.js ADDED
@@ -0,0 +1,6 @@
1
+ // The Pods directory built in memory from a Podfile.lock, as CocoaPods 1.13
2
+ // to 1.17 download pods into it; see cocoapods.d.ts.
3
+ export { buildCocoaPodsTree } from './src/cocoapods/tree.js'
4
+ export { DeptreeError } from './src/error.js'
5
+ export { setCacheDir } from '@preventive/upstream/npm.js'
6
+ export { LockfileError } from '@preventive/lockfile/cocoapods.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/deptree",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "In-memory dependency tree, as a package manager installs it",
5
5
  "type": "module",
6
6
  "exports": {
@@ -23,6 +23,10 @@
23
23
  "./cargo.js": {
24
24
  "types": "./cargo.d.ts",
25
25
  "default": "./cargo.js"
26
+ },
27
+ "./cocoapods.js": {
28
+ "types": "./cocoapods.d.ts",
29
+ "default": "./cocoapods.js"
26
30
  }
27
31
  },
28
32
  "bin": {
@@ -33,6 +37,8 @@
33
37
  "LICENSE-MIT",
34
38
  "cargo.d.ts",
35
39
  "cargo.js",
40
+ "cocoapods.d.ts",
41
+ "cocoapods.js",
36
42
  "npm.d.ts",
37
43
  "npm.js",
38
44
  "pnpm.d.ts",
@@ -50,8 +56,19 @@
50
56
  "src/cargo/registry.js",
51
57
  "src/cargo/tree.js",
52
58
  "src/cargo/workspace.js",
59
+ "src/cocoapods/archive.js",
60
+ "src/cocoapods/clean.js",
61
+ "src/cocoapods/fnmatch.js",
62
+ "src/cocoapods/inputs.js",
63
+ "src/cocoapods/install.js",
64
+ "src/cocoapods/podspec.js",
65
+ "src/cocoapods/podtree.js",
66
+ "src/cocoapods/source.js",
67
+ "src/cocoapods/tree.js",
68
+ "src/cocoapods/unicode.js",
53
69
  "src/concurrent.js",
54
70
  "src/error.js",
71
+ "src/github.js",
55
72
  "src/glob.js",
56
73
  "src/hash.js",
57
74
  "src/lazy.js",
@@ -74,6 +91,8 @@
74
91
  "src/pnpm/bins.js",
75
92
  "src/pnpm/checks.js",
76
93
  "src/pnpm/commands.js",
94
+ "src/pnpm/directories.js",
95
+ "src/pnpm/extensions.js",
77
96
  "src/pnpm/filename.js",
78
97
  "src/pnpm/frozen.js",
79
98
  "src/pnpm/gitignore.js",
@@ -104,7 +123,6 @@
104
123
  "src/pnpm/write.js",
105
124
  "src/project.js",
106
125
  "src/soldeer/config.js",
107
- "src/soldeer/git.js",
108
126
  "src/soldeer/inputs.js",
109
127
  "src/soldeer/tree.js",
110
128
  "src/soldeer/zip.js",
@@ -148,11 +166,11 @@
148
166
  "dependencies": {
149
167
  "@chalker/queue": "^1.0.1",
150
168
  "@exodus/bytes": "^1.16.0",
151
- "@preventive/archive": "^1.2.2",
169
+ "@preventive/archive": "^1.4.0",
152
170
  "@preventive/compare": "^1.2.11",
153
171
  "@preventive/diff": "^1.1.0",
154
- "@preventive/lockfile": "^1.2.0",
155
- "@preventive/upstream": "^1.3.0",
172
+ "@preventive/lockfile": "^1.3.0",
173
+ "@preventive/upstream": "^1.6.0",
156
174
  "@preventive/vfs": "^1.1.0"
157
175
  }
158
176
  }