@preventive/deptree 1.5.2 → 1.5.3

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 (80) hide show
  1. package/bin/compare.js +10 -21
  2. package/bin/deptree.js +5 -10
  3. package/cargo.d.ts +139 -195
  4. package/cargo.js +0 -2
  5. package/cocoapods.d.ts +211 -381
  6. package/cocoapods.js +0 -2
  7. package/npm.d.ts +245 -369
  8. package/npm.js +4 -6
  9. package/package.json +1 -1
  10. package/pnpm.d.ts +258 -667
  11. package/pnpm.js +2 -4
  12. package/soldeer.d.ts +144 -215
  13. package/soldeer.js +0 -2
  14. package/src/cargo/crate.js +21 -46
  15. package/src/cargo/inputs.js +5 -8
  16. package/src/cargo/members.js +6 -12
  17. package/src/cargo/registry.js +5 -9
  18. package/src/cargo/tree.js +8 -13
  19. package/src/cargo/workspace.js +13 -26
  20. package/src/cocoapods/archive.js +19 -40
  21. package/src/cocoapods/clean.js +21 -45
  22. package/src/cocoapods/fnmatch.js +12 -27
  23. package/src/cocoapods/inputs.js +5 -11
  24. package/src/cocoapods/install.js +11 -24
  25. package/src/cocoapods/podspec.js +19 -40
  26. package/src/cocoapods/podtree.js +10 -19
  27. package/src/cocoapods/source.js +13 -30
  28. package/src/cocoapods/tree.js +17 -39
  29. package/src/cocoapods/unicode.js +3 -9
  30. package/src/github.js +12 -24
  31. package/src/glob.js +2 -4
  32. package/src/lazy.js +2 -4
  33. package/src/manifest.js +2 -4
  34. package/src/matcher.js +3 -5
  35. package/src/mount.js +7 -14
  36. package/src/npm/bins.js +3 -5
  37. package/src/npm/compat.js +3 -5
  38. package/src/npm/package.js +6 -12
  39. package/src/npm/ratio.js +3 -5
  40. package/src/npm/settings.js +3 -5
  41. package/src/npm/tree.js +6 -11
  42. package/src/npm/versions.js +3 -4
  43. package/src/npmrc.js +2 -4
  44. package/src/patch.js +8 -14
  45. package/src/pnpm/bins.js +16 -42
  46. package/src/pnpm/filename.js +2 -4
  47. package/src/pnpm/gitignore.js +2 -4
  48. package/src/pnpm/glob.js +3 -5
  49. package/src/pnpm/hoist.js +8 -16
  50. package/src/pnpm/hoisted.js +15 -44
  51. package/src/pnpm/hook.js +2 -4
  52. package/src/pnpm/install.js +5 -10
  53. package/src/pnpm/lazy.js +8 -23
  54. package/src/pnpm/local.js +2 -4
  55. package/src/pnpm/minimatch.js +8 -15
  56. package/src/pnpm/nm-hoist.js +5 -11
  57. package/src/pnpm/npm-packlist.js +3 -6
  58. package/src/pnpm/overrides.js +2 -4
  59. package/src/pnpm/package.js +10 -16
  60. package/src/pnpm/packlist.js +3 -7
  61. package/src/pnpm/patches.js +3 -4
  62. package/src/pnpm/production.js +9 -28
  63. package/src/pnpm/projects.js +2 -6
  64. package/src/pnpm/readers.js +2 -4
  65. package/src/pnpm/settings.js +2 -5
  66. package/src/pnpm/tree.js +14 -37
  67. package/src/pnpm/workspace.js +4 -7
  68. package/src/pnpm/write.js +1 -1
  69. package/src/soldeer/config.js +5 -9
  70. package/src/soldeer/tree.js +2 -4
  71. package/src/soldeer/zip.js +8 -17
  72. package/src/tarball.js +12 -29
  73. package/src/yarn1/compat.js +2 -4
  74. package/src/yarn1/hoist.js +3 -8
  75. package/src/yarn1/package.js +12 -23
  76. package/src/yarn1/resolve.js +6 -11
  77. package/src/yarn1/settings.js +5 -10
  78. package/src/yarn1/tree.js +9 -18
  79. package/yarn1.d.ts +203 -360
  80. package/yarn1.js +4 -6
package/pnpm.js CHANGED
@@ -1,7 +1,5 @@
1
- // A node_modules tree built in memory from a pnpm lockfile, as pnpm 9, 10,
2
- // 11 or 12 installs it with the isolated linker; see pnpm.d.ts.
3
- export { buildPnpmTree } from './src/pnpm/tree.js'
4
- export { findPnpmProjects } from './src/pnpm/inputs.js'
5
1
  export { DeptreeError } from './src/error.js'
2
+ export { findPnpmProjects } from './src/pnpm/inputs.js'
3
+ export { buildPnpmTree } from './src/pnpm/tree.js'
6
4
  export { setCacheDir } from '@preventive/upstream/npm.js'
7
5
  export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
package/soldeer.d.ts CHANGED
@@ -1,240 +1,169 @@
1
- import type { Client } from '@preventive/upstream/github.js'
2
- import type { NodeType, Vfs } from '@preventive/vfs'
3
-
4
- export { LockfileError, TomlError } from '@preventive/lockfile/soldeer.js'
5
-
6
- // Where @preventive/upstream caches what it fetches, zips and GitHub's
7
- // tarballs among them. Both are fetched through it, and that is the one
8
- // place anything here touches a filesystem: from its cache, where one is
9
- // set, which is where it writes each it fetches -- setCacheDir() sets the
10
- // default one, and setCacheDir(false) unsets it; unset, which it is until
11
- // set, it has none, and writes nothing. Soldeer's own folders are never
12
- // read. The project is read only through the view given as `project`, and
13
- // the tree built in a Vfs.
14
- export { setCacheDir } from '@preventive/upstream/npm.js'
15
-
16
- // The machine Soldeer would install on: `soldeer` is the version that
17
- // installs, on its own or as `forge soldeer`, and has to be 0.12.0, which
18
- // extracts zips otherwise than 0.11 and older; `os` as Node names it --
19
- // `linux`, `darwin`. Windows is refused: Soldeer names folders and reads
20
- // paths in zips otherwise there.
1
+ /**
2
+ * The dependencies folder `soldeer install` makes from a soldeer.lock, built in memory
3
+ *
4
+ * ```js
5
+ * import { buildSoldeerTree } from '@preventive/deptree/soldeer.js'
6
+ * ```
7
+ *
8
+ * Everything is fetched through `@preventive/upstream`, whose cache (`setCacheDir`) is the one place
9
+ * a filesystem is touched; Soldeer's own folders are never read. Nothing is left to a guess: what
10
+ * Soldeer would read otherwise, or what this cannot reproduce exactly, is refused.
11
+ *
12
+ * @module @preventive/deptree/soldeer.js
13
+ */
14
+
15
+ import type { Client } from '@preventive/upstream/github.js';
16
+ import type { NodeType, Vfs } from '@preventive/vfs';
17
+
18
+ export { LockfileError, TomlError } from '@preventive/lockfile/soldeer.js';
19
+
20
+ // Where `@preventive/upstream` caches zips and GitHub's tarballs: setCacheDir() the default, false none, as until set
21
+ export { setCacheDir } from '@preventive/upstream/npm.js';
22
+
23
+ /** The machine Soldeer would install on */
21
24
  export interface SoldeerHost {
22
- soldeer: string
23
- os: string
25
+ /** The Soldeer that installs, alone or as `forge soldeer`: 0.12.0, which extracts zips otherwise than 0.11 */
26
+ soldeer: string;
27
+ /** As Node names it, `linux` or `darwin`; Windows is refused, as Soldeer names folders otherwise there */
28
+ os: string;
24
29
  }
25
30
 
26
- // A view of the project's root, by paths from `/`: a Vfs, or anything
27
- // with its readdir, lstat, stat and readFile, such as one of a directory
28
- // on disk, of which only soldeer.lock, foundry.toml and, where there is
29
- // no foundry.toml, soldeer.toml are read there, as Soldeer reads them,
30
- // each as UTF-8, and refused where it is not. Nothing is written to it.
31
+ /**
32
+ * The project's root, by paths from `/`: a Vfs, or anything with these methods, such as a view of a
33
+ * directory on disk. Only soldeer.lock, foundry.toml and, without that, soldeer.toml are read, as
34
+ * UTF-8; nothing is written.
35
+ */
31
36
  export interface SoldeerProject {
32
- readdir(path: string): string[]
33
- lstat(path: string): { type: NodeType }
34
- stat(path: string): { type: NodeType }
35
- readFile(path: string): Uint8Array
37
+ readdir(path: string): string[];
38
+ lstat(path: string): { type: NodeType };
39
+ stat(path: string): { type: NodeType };
40
+ readFile(path: string): Uint8Array;
36
41
  }
37
42
 
38
- // The files an install reads at the project's root: soldeer.lock, and
39
- // foundry.toml and soldeer.toml, where they are.
40
- //
41
- // Of the two, the config is the one Soldeer reads: foundry.toml, where it
42
- // has a [dependencies] table, written as one rather than inline; else
43
- // soldeer.toml, where there is no foundry.toml. Where neither holds, which
44
- // is so of a foundry.toml with no such table, whatever soldeer.toml there
45
- // is, Soldeer asks which file to make its config, and that is refused. Of
46
- // foundry.toml, what Soldeer fails on as it adds `dependencies` to the
47
- // default profile's libs is refused: a profile or profile.default that is
48
- // not a table, or written inline, and libs that are not an array. Of the
49
- // config's [soldeer] settings, a value of a type Soldeer fails on is
50
- // refused, and so is recursive_deps = true, which has Soldeer install what
51
- // each dependency depends on too; the others change nothing beneath
52
- // dependencies/. A setting Soldeer 0.12 does not have is refused, though
53
- // Soldeer passes it over, as a later Soldeer may install otherwise by it.
54
- // A config whose `dependencies` is inline, which Soldeer reads none
55
- // from, is refused.
56
- //
57
- // The two ways the files come, one or the other: given, with `lockfile`
58
- // and, where they are, `foundry` and `soldeer`; or read, with `project`
59
- // and none of them.
60
- //
61
- // `vfs` is a Vfs to mount the tree into, at its root, which is taken to be
62
- // the project's -- it may be `project` too; without one, a new Vfs holds
63
- // the tree alone. A Vfs that holds a `dependencies` at its root, or on
64
- // macOS a name that is one there, is refused before anything is fetched,
65
- // as Soldeer would keep or remove what is in it by what it holds. Nothing
66
- // there is written over: each directory the tree has is one there or is
67
- // made, and every file is written where nothing is. The tree is built, and
68
- // held to every check below, before any of it is written, so a refusal
69
- // leaves the Vfs as it was.
70
- //
71
- // `github` is the client from @preventive/upstream/github.js's createClient
72
- // each git dependency is fetched through, with whatever token it was made
73
- // with, or none. It is needed only where the lockfile has a git dependency,
74
- // and there it is a TypeError to leave it out, before anything is fetched.
75
- export type SoldeerTreeOptions = SoldeerTreeGiven | SoldeerTreeRead
76
-
77
- export interface SoldeerTreeGiven {
78
- lockfile: string
79
- foundry?: string
80
- soldeer?: string
81
- project?: undefined
82
- host: SoldeerHost
83
- vfs?: Vfs
84
- github?: Client
43
+ /**
44
+ * The files an install reads, given as text (`lockfile`, and `foundry` and `soldeer` where there) or
45
+ * read from `project`
46
+ *
47
+ * The config is foundry.toml where it has a `[dependencies]` table, else soldeer.toml where there is
48
+ * no foundry.toml; otherwise Soldeer asks which file to make its config, which is refused. Refused too:
49
+ * - in foundry.toml, a profile or profile.default that is not a table, or libs that are not an array,
50
+ * which Soldeer fails on as it adds `dependencies` to them
51
+ * - in `[soldeer]`, a value of a type Soldeer fails on, `recursive_deps = true`, and a setting Soldeer
52
+ * 0.12 does not have, as a later Soldeer may install otherwise by it
53
+ * - an inline `dependencies`, which Soldeer reads none from
54
+ */
55
+ export type SoldeerTreeOptions = SoldeerTreeGiven | SoldeerTreeRead;
56
+
57
+ interface SoldeerTreeCommon {
58
+ host: SoldeerHost;
59
+ /**
60
+ * A Vfs to mount the tree into, at the project's root (it may be `project`), or a new one. One that
61
+ * holds a `dependencies` (on macOS, a name that is one there) is refused before anything is fetched.
62
+ * Nothing there is written over, and a refusal leaves it as it was.
63
+ */
64
+ vfs?: Vfs;
65
+ /** From upstream's `createClient`, for each git dependency; a TypeError where one needs it and it is missing */
66
+ github?: Client;
67
+ }
68
+
69
+ export interface SoldeerTreeGiven extends SoldeerTreeCommon {
70
+ lockfile: string;
71
+ foundry?: string;
72
+ soldeer?: string;
73
+ project?: undefined;
85
74
  }
86
75
 
87
- export interface SoldeerTreeRead {
88
- lockfile?: undefined
89
- foundry?: undefined
90
- soldeer?: undefined
91
- project: SoldeerProject
92
- host: SoldeerHost
93
- vfs?: Vfs
94
- github?: Client
76
+ export interface SoldeerTreeRead extends SoldeerTreeCommon {
77
+ lockfile?: undefined;
78
+ foundry?: undefined;
79
+ soldeer?: undefined;
80
+ project: SoldeerProject;
95
81
  }
96
82
 
97
- // What buildSoldeerTree counts, all of it plain numbers: `dependencies`
98
- // those installed, each a zip or a tarball fetched; `files` and `bytes`
99
- // what is written, and `links` the symlinks, which git dependencies alone
100
- // have, as a zip's are written as files.
83
+ /** What was installed */
101
84
  export interface SoldeerTreeStats {
102
- dependencies: number
103
- files: number
104
- bytes: number
105
- links: number
85
+ /** Dependencies installed, each a zip or a tarball fetched */
86
+ dependencies: number;
87
+ /** Files written */
88
+ files: number;
89
+ /** Bytes written */
90
+ bytes: number;
91
+ /** Symlinks, which git dependencies alone have: a zip's are written as files */
92
+ links: number;
106
93
  }
107
94
 
108
- // A dependency in the tree, as an SBOM would list it: `path` is its
109
- // folder, from the project's root, which is `/` of the Vfs --
110
- // dependencies/<name>-<version>; `name` and `version` the lockfile's, as
111
- // the registry has them, or for a git dependency, the config's. From the
112
- // registry, `checksum` is the hex sha256 its zip is held to; from git,
113
- // `git` is the repository's URL and `rev` the commit, as the lockfile has
114
- // them, and `commit` that commit again, as the other trees name one.
115
- export type SoldeerInstalled = SoldeerInstalledZip | SoldeerInstalledGit
95
+ /** A dependency as an SBOM would list it */
96
+ export type SoldeerInstalled = SoldeerInstalledZip | SoldeerInstalledGit;
116
97
 
117
98
  export interface SoldeerInstalledZip {
118
- path: string
119
- name: string
120
- version: string
121
- checksum: string
99
+ /** `dependencies/<name>-<version>`, from the project's root */
100
+ path: string;
101
+ name: string;
102
+ version: string;
103
+ /** The hex sha256 its zip is held to */
104
+ checksum: string;
122
105
  }
123
106
 
124
107
  export interface SoldeerInstalledGit {
125
- path: string
126
- name: string
127
- version: string
128
- git: string
129
- rev: string
130
- commit: string
108
+ /** `dependencies/<name>-<version>`, from the project's root */
109
+ path: string;
110
+ /** The config's */
111
+ name: string;
112
+ /** The config's */
113
+ version: string;
114
+ /** The repository's URL, as the lockfile has it */
115
+ git: string;
116
+ /** The commit, as the lockfile has it */
117
+ rev: string;
118
+ /** `rev` again, as the other trees name a commit */
119
+ commit: string;
131
120
  }
132
121
 
133
- // `vfs` is the one given, the tree mounted into it, or a new one.
134
- // `installed` is each dependency, in the lockfile's order.
135
122
  export interface SoldeerTree {
136
- vfs: Vfs
137
- stats: SoldeerTreeStats
138
- installed: SoldeerInstalled[]
123
+ /** The one given, the tree mounted into it, or a new one */
124
+ vfs: Vfs;
125
+ stats: SoldeerTreeStats;
126
+ /** In the lockfile's order */
127
+ installed: SoldeerInstalled[];
139
128
  }
140
129
 
141
- // The dependencies folder `soldeer install` makes from the lockfile, with
142
- // host.soldeer, in a project with no dependencies folder yet: rooted at
143
- // the project's root, it holds `dependencies/<name>-<version>` for each
144
- // dependency, and nothing else of the project. What Soldeer writes beside
145
- // it -- the lockfile again, remappings, foundry.toml's libs -- is not
146
- // written, and where writing it fails after the install, as Soldeer may on
147
- // a remappings.txt it does not read, that is not followed.
148
- //
149
- // Each registry dependency's zip is fetched from Soldeer's registry, as
150
- // Soldeer 0.12 asks for it anew rather than taking the lockfile's URL,
151
- // and held to the lockfile's checksum, its sha256. It is extracted as
152
- // Soldeer extracts it, with the zip crate, into a folder of its own: no
153
- // root folder taken off; of two entries of one name, the later alone,
154
- // where the first was; anything under a `.git` passed over, as Windows
155
- // reads the name -- trailing dots and spaces dropped, ASCII letters in
156
- // either case; each symlink written as a file holding its target. Each
157
- // directory is 0o755; each file's mode is its Unix mode as the zip crate
158
- // reads it -- from the upper half of its external attributes, by whatever
159
- // system made it, or none at all for Unix where that is 0, else for MS-DOS
160
- // from its read-only bit -- without the
161
- // type, setuid, setgid, sticky and group and other write bits; or 0o644,
162
- // where the zip crate reads none, or for a symlink, or for a file written
163
- // again by a name the zip crate reads no mode of, the mode it had. Both
164
- // are as a umask of 0o022 leaves them. The lockfile's integrity, which
165
- // Soldeer records anew as it installs and does not check, is not checked.
166
- //
167
- // The lockfile is held to what the lockfile reader holds it to, with the
168
- // config: each dependency has its entry, which Soldeer installs it from,
169
- // and each entry a dependency. And to more than Soldeer holds it to: a zip
170
- // is read with @preventive/archive/zip.js, which refuses what it does not
171
- // read -- a `..`, absolute or backslashed name, one starting with a drive
172
- // letter, zip64, encryption, an entry inside one that is not a directory,
173
- // two entries of one name that differ, a directory by its name or its
174
- // attributes and not by the other, entries that come to more than 512
175
- // MiB -- where Soldeer would take some of it;
176
- // and what the zip crate reads otherwise than the archive reader is
177
- // refused: a name with a byte past ASCII that is not flagged UTF-8, which
178
- // it reads as CP437, and an AES or a Unicode comment extra field. What
179
- // Soldeer fails on is refused: a name with a `:` in it, an NTFS extra
180
- // field or an extended timestamp the zip crate does not read. A folder
181
- // Soldeer downloads another dependency's zip into, `<folder>.zip`, is
182
- // refused. On macOS, two names in one directory that differ only in case
183
- // or normalization are refused, as they would be one name there, and so
184
- // is a folder that is one there with another dependency's zip.
185
- //
186
- // A git dependency Soldeer clones, `git clone` of the lockfile's `git`,
187
- // then `git checkout` of its `rev`; here it is fetched from a GitHub
188
- // repository alone, by `github`, as GitHub's tarball of the tree of that
189
- // commit: the tree read off the commit's own object, which upstream's
190
- // getCommitTree fetches from github.com as git fetches it and holds to the
191
- // commit's id, and the tarball, which getRepoTreeTarball holds to it. A
192
- // repository renamed or transferred since, which GitHub answers with a
193
- // redirect that git's clone follows, is fetched by the name GitHub gives
194
- // it now, as upstream's getRepo follows that redirect with
195
- // `followRedirect`; any other redirect is refused. It is written as a
196
- // checkout with no git config and a umask of 0o022 writes it: each
197
- // directory 0o755, each file 0o644, or 0o755 where git has it executable;
198
- // each symlink a symlink to its target, as git has it; a submodule an
199
- // empty directory, as Soldeer leaves it without recursive_deps; a file the
200
- // tree's .gitattributes mark `eol=crlf` with CRLF, as upstream reads them.
201
- // The .git a clone has is not written, so nothing of the repository's
202
- // history is there; nor is what git config on the machine would change,
203
- // `core.autocrlf` or a filter such as Git LFS's. Its folder is the
204
- // config's name and version, which Soldeer's sanitize_filename has to
205
- // leave as they are. The `git` is the repository's URL over https or ssh,
206
- // as git takes it -- `https://github.com/<owner>/<name>`,
207
- // `ssh://git@github.com/<owner>/<name>` or
208
- // `git@github.com:<owner>/<name>`, `.git` after or not; git's http and git
209
- // protocols, which Soldeer has git refuse, are refused. GitHub's tarball
210
- // is refused where upstream refuses it -- a tree with files marked
211
- // `export-ignore`, `ident` or `working-tree-encoding`, from a repo set to
212
- // include Git LFS objects in archives -- and where the tar reader of
213
- // @preventive/archive/tar.js does, as for a symlink whose target climbs
214
- // out of the tarball; so is a path git refuses to check out, with a `.git`
215
- // in it, or its short name `git~1`, in any case, dots and spaces after it,
216
- // or a `:` after that. That the repository's branches and tags still
217
- // reach the commit, without which Soldeer's clone does not have it, is not
218
- // checked: GitHub answers for any commit it has.
219
- //
220
- // Dependencies come from Soldeer's registry, each by a name and a version
221
- // the registry takes, or from GitHub: one from another git host, from a
222
- // URL the config gives, or one the registry keeps private, which it hands
223
- // out to those signed in alone, is refused.
224
- //
225
- // Nothing is left to a guess: a lockfile the lockfile reader refuses, a
226
- // config this does not read as Soldeer reads it, a dependency from
227
- // anywhere but the registry or GitHub, a check above that fails -- each is
228
- // refused with a DeptreeError, a LockfileError or a TomlError that says
229
- // where. A TypeError is thrown for options of the wrong type, and for a
230
- // git dependency without `github`.
231
- export function buildSoldeerTree(options: SoldeerTreeOptions): Promise<SoldeerTree>
232
-
233
- // `where` is what a refusal is about -- `foundry.toml: profile.default`,
234
- // `dependencies["forge-std"]`, an entry of a zip -- or undefined for the
235
- // call as a whole; the message leads with it. `cause` is what a package
236
- // beneath refused with, where one did.
130
+ /**
131
+ * The dependencies folder `soldeer install` makes, with `host.soldeer`, in a project with no
132
+ * dependencies folder yet: `dependencies/<name>-<version>` for each dependency, and nothing else
133
+ *
134
+ * What Soldeer writes beside it (the lockfile again, remappings, foundry.toml's libs) is not written.
135
+ * The lockfile is held to the config, each dependency to have its entry and each entry a dependency.
136
+ *
137
+ * A registry dependency's zip is fetched anew from Soldeer's registry, as 0.12 does, held to the
138
+ * lockfile's sha256, and extracted as the zip crate extracts it: no root folder taken off; of two
139
+ * entries of one name the later, where the first was; anything under a `.git` (as Windows reads the
140
+ * name) passed over; a symlink written as a file of its target. Directories are 0o755, a file its Unix
141
+ * mode as the zip crate reads it, or 0o644 where it reads none, as a 0o022 umask leaves them. Refused:
142
+ * - what `@preventive/archive/zip.js` refuses, such as a `..` or absolute name, zip64 or encryption
143
+ * - what the zip crate reads otherwise: a name past ASCII not flagged UTF-8, an AES or Unicode comment
144
+ * extra field
145
+ * - what Soldeer fails on: a `:` in a name, an NTFS field or extended timestamp the zip crate does not read
146
+ * - a folder another dependency's zip is downloaded into, `<folder>.zip`
147
+ * - on macOS, two names that are one there
148
+ *
149
+ * A git dependency is fetched from GitHub alone, by `github`, as the tarball of the commit's tree (held
150
+ * to the commit's id), and written as a checkout with no git config under a 0o022 umask: files 0o644,
151
+ * or 0o755 where git has them executable, symlinks as symlinks, a submodule an empty directory, a file
152
+ * `.gitattributes` marks `eol=crlf` with CRLF. Its URL is GitHub's over https or ssh, and its folder one
153
+ * Soldeer's sanitize_filename leaves as it is. Refused: what upstream refuses of the tarball (such as
154
+ * `export-ignore` or Git LFS), and a path git refuses to check out (a `.git` or `git~1` in it).
155
+ *
156
+ * A dependency from another git host, a URL of its own, or a private one is refused.
157
+ *
158
+ * @param options - The files and where to build
159
+ * @returns The tree, what it holds, and its dependencies
160
+ * @throws DeptreeError, LockfileError or TomlError saying where; TypeError for options of the wrong type
161
+ */
162
+ export function buildSoldeerTree(options: SoldeerTreeOptions): Promise<SoldeerTree>;
163
+
164
+ /** A refusal */
237
165
  export class DeptreeError extends Error {
238
- constructor(detail: string, where?: string, options?: { cause?: unknown })
239
- where: string | undefined
166
+ constructor(detail: string, where?: string, options?: { cause?: unknown });
167
+ /** What it is about, such as `dependencies["forge-std"]`, which the message leads with; undefined for the call */
168
+ where: string | undefined;
240
169
  }
package/soldeer.js CHANGED
@@ -1,5 +1,3 @@
1
- // The dependencies folder built in memory from a soldeer.lock, as Soldeer
2
- // 0.12 installs it; see soldeer.d.ts.
3
1
  export { buildSoldeerTree } from './src/soldeer/tree.js'
4
2
  export { DeptreeError } from './src/error.js'
5
3
  export { setCacheDir } from '@preventive/upstream/npm.js'
@@ -1,8 +1,5 @@
1
- // A .crate as `cargo vendor` unpacks it into vendor/, cargo 1.94 to 1.99:
2
- // registry/mod.rs's unpack, through vendor.rs's vendor_this; what the archive
3
- // reader takes and cargo would read otherwise is refused. As a 0o022 umask
4
- // leaves them, each directory is 0o755 unless its own entry gives a mode, and
5
- // each file its mode within 0o777, both without group and other write bits.
1
+ // A .crate as `cargo vendor` 1.94 to 1.99 unpacks it (registry/mod.rs's unpack, vendor.rs's vendor_this),
2
+ // under a 0o022 umask; what the archive reader takes and cargo would read otherwise is refused
6
3
 
7
4
  import { crc32 } from '@exodus/bytes/crc.js'
8
5
  import { utf8fromString, utf8toString } from '@exodus/bytes/utf8.js'
@@ -13,13 +10,11 @@ import { DeptreeError, quote } from '../error.js'
13
10
  import { bytesSha256Hex } from '../hash.js'
14
11
  import { own } from '../manifest.js'
15
12
 
16
- // Cargo's bound on what a .crate unpacks to: 512 MiB, or twenty times the
17
- // .crate where that is more.
13
+ // Cargo's bound on what a .crate unpacks to: 512 MiB, or twenty times the .crate where that is more
18
14
  const unpackLimit = (bytes) => Math.max(512 * 1024 * 1024, bytes.length * 20)
19
15
  const [FTEXT, FEXTRA, FNAME, FCOMMENT] = [0x01, 0x04, 0x08, 0x10]
20
16
 
21
- // Where the gzip member's deflate data starts, past its header: a header CRC
22
- // or a reserved flag, which a reader may take or not, is refused.
17
+ // Where the deflate data starts; a header CRC or a reserved flag, which a reader may take or not, is refused
23
18
  function deflateStart(bytes, where) {
24
19
  if (bytes.length < 18 || bytes[0] !== 0x1f || bytes[1] !== 0x8b || bytes[2] !== 0x08) throw new DeptreeError('the .crate is not gzipped', where)
25
20
  const flags = bytes[3]
@@ -35,22 +30,15 @@ function deflateStart(bytes, where) {
35
30
  return at
36
31
  }
37
32
 
38
- // flate2's GzDecoder, which cargo reads a .crate through, reads its first
39
- // gzip member alone, where the platform's stream reads on into any after it;
40
- // so the first has to be all of it. Its deflate data has to end where its
41
- // eight-byte trailer starts, which deflate-raw holds it to, refusing what
42
- // follows; and the trailer has to be the data's CRC-32 and length, as flate2
43
- // checks them.
33
+ // flate2's GzDecoder reads the first gzip member alone, where the platform reads on, so it has to be all
34
+ // of it: deflate-raw holds its data to end at the trailer, which has to be its CRC-32 and length
44
35
  async function gunzip(bytes, where) {
45
36
  const start = deflateStart(bytes, where)
46
37
  const limit = unpackLimit(bytes)
47
- let tar
48
- try {
49
- tar = await decompress(bytes.subarray(start, bytes.length - 8), 'deflate-raw', { limit })
50
- } catch (error) {
38
+ const tar = await decompress(bytes.subarray(start, bytes.length - 8), 'deflate-raw', { limit }).catch((error) => {
51
39
  if (!(error instanceof CompressionError)) throw error
52
40
  throw new DeptreeError(error.limited ? `the .crate unpacks to more than ${limit} bytes, which cargo refuses` : 'the .crate is not one gzip member, which cargo reads the first of alone', where, { cause: error })
53
- }
41
+ })
54
42
  const trailer = new DataView(bytes.buffer, bytes.byteOffset + bytes.length - 8, 8)
55
43
  if (trailer.getUint32(0, true) !== crc32(tar) || trailer.getUint32(4, true) !== tar.length >>> 0) throw new DeptreeError('the .crate\'s gzip trailer does not match its data', where)
56
44
  return tar
@@ -65,20 +53,16 @@ function entriesOf(tar, where) {
65
53
  }
66
54
  }
67
55
 
68
- // vendor_this: a `.git` anywhere on the way, a .gitattributes or .gitignore
69
- // by name, .cargo-ok at the root; each is passed over before its type is
70
- // looked at, unlike unpack's own .cargo-ok anywhere, after it.
56
+ // vendor_this passes over a `.git` anywhere on the way, a .gitattributes or .gitignore, and .cargo-ok at
57
+ // the root, before the type is looked at, unlike unpack's own .cargo-ok anywhere, after it
71
58
  const vendored = (segments, last) => !segments.includes('.git') && last !== '.gitattributes' && last !== '.gitignore' && segments.join('/') !== '.cargo-ok'
72
59
 
73
60
  const modeOf = (entry) => entry.mode & 0o777 & ~0o022
74
61
  const unsupported = (entry, why, here) => new DeptreeError(`mode ${entry.mode.toString(8)}, which keeps cargo from ${why} as any user but root, is not supported`, here)
75
62
 
76
- // As any user but root, cargo reads back no file without its owner's read
77
- // bit; lists nothing in a directory without its owner's read and search
78
- // bits, leaving what is in it out of .cargo-checksum.json; and writes
79
- // nothing into one without its write bit once its entry has set it, `after`.
80
- // A directory nothing is in may have any mode. The package's always has
81
- // something written into it last, its .cargo-checksum.json.
63
+ // As any user but root, cargo reads back no file without its owner's read, lists nothing in a directory
64
+ // without its owner's read and search, and writes nothing into one without its write once its entry has
65
+ // set it (`after`), as .cargo-checksum.json always is into the package's
82
66
  function fileMode(entry, here) {
83
67
  const mode = modeOf(entry)
84
68
  if (!(mode & 0o400)) throw unsupported(entry, 'reading it back to checksum it', here)
@@ -91,9 +75,7 @@ function dirMode({ entry, here, after }, content) {
91
75
  return mode
92
76
  }
93
77
 
94
- // The directory `<name>-<version>` every entry has to be in, as Rust's
95
- // strip_prefix reads a path: by its components, so `./` or `/` before it
96
- // is not it.
78
+ // The directory every entry has to be in, by components as Rust's strip_prefix reads them: not `./` or `/` it
97
79
  function segmentsOf(entry, prefix, here) {
98
80
  const [first, ...rest] = entry.name.split('/')
99
81
  if (entry.storedName.startsWith('/') || entry.storedName.startsWith('./') || first !== prefix) throw new DeptreeError(`not under ${quote(prefix)}, which cargo refuses`, here)
@@ -102,8 +84,7 @@ function segmentsOf(entry, prefix, here) {
102
84
  return rest
103
85
  }
104
86
 
105
- // `root` is the mode of the package's directory; `dirs` maps each directory
106
- // under it to its mode, 0o755 where no entry of its own gives one.
87
+ // `root` is the package's directory's mode, `dirs` each under it, 0o755 where no entry of its own gives one
107
88
  function vendorEntries(entries, prefix, where) {
108
89
  const dirs = new Map()
109
90
  const files = new Map()
@@ -140,8 +121,7 @@ function vendorEntries(entries, prefix, where) {
140
121
 
141
122
  const COMMENT = 'This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.'
142
123
 
143
- // vendor.rs's, as serde_json writes it: compact, each map's keys in UTF-8
144
- // byte order, `$comment` from cargo 1.97 on.
124
+ // vendor.rs's, as serde_json writes it: compact, keys in UTF-8 byte order, `$comment` from cargo 1.97 on
145
125
  async function checksumFile(files, checksum, comment) {
146
126
  const paths = [...files.keys()].sort(compareNames)
147
127
  const sums = await Promise.all(paths.map((path) => bytesSha256Hex(files.get(path).data)))
@@ -149,15 +129,11 @@ async function checksumFile(files, checksum, comment) {
149
129
  return `{${comment ? `"$comment":${JSON.stringify(COMMENT)},` : ''}"files":{${listed}},"package":${JSON.stringify(checksum)}}`
150
130
  }
151
131
 
152
- // A full commit id, as git writes one: 40 lowercase hex digits, or 64 in a
153
- // repository of SHA-256 objects.
132
+ // A full commit id: 40 lowercase hex digits, or 64 in a repository of SHA-256 objects
154
133
  const COMMIT = /^(?:[\da-f]{40}|[\da-f]{64})$/u
155
134
 
156
- // The commit .cargo_vcs_info.json names, which `cargo package` writes where
157
- // it packs from a git checkout: none where it found the checkout dirty, as
158
- // the files are then not that commit's, nor where it names anything but a
159
- // full id. Cargo reads none of it, so one that is not JSON names none, and
160
- // is vendored all the same.
135
+ // The commit `cargo package` wrote in .cargo_vcs_info.json, none where the checkout was dirty or it is not
136
+ // a full id. Cargo reads none of it, so one that is not JSON names none and is vendored all the same.
161
137
  function vcsCommitOf(file) {
162
138
  if (file === undefined) return undefined
163
139
  try {
@@ -170,9 +146,8 @@ function vcsCommitOf(file) {
170
146
  }
171
147
  }
172
148
 
173
- // What vendor/<directory> holds of a package, `.cargo-checksum.json` among
174
- // its files. getCrate has held the .crate to its checksum; it is held to it
175
- // again where it is unpacked.
149
+ // What vendor/<directory> holds, .cargo-checksum.json among it. getCrate has held the .crate to its
150
+ // checksum; it is held to it again where it is unpacked.
176
151
  export async function vendorCrate(bytes, { name, version, checksum }, comment, where) {
177
152
  if (await bytesSha256Hex(bytes) !== checksum) throw new DeptreeError(`its .crate's sha256 is not ${checksum}`, where)
178
153
  const { root, dirs, files } = vendorEntries(entriesOf(await gunzip(bytes, where), where), `${name}-${version}`, where)
@@ -1,6 +1,5 @@
1
- // What buildCargoTree takes, as text or read from the project's root. Texts
2
- // given are laid out as the project they stand for, so that both are read
3
- // one way.
1
+ // What buildCargoTree takes, as text or read from the project's root; texts given are laid out as the
2
+ // project they stand for, so both are read one way
4
3
 
5
4
  import { Vfs } from '@preventive/vfs'
6
5
  import { DeptreeError, quote } from '../error.js'
@@ -18,9 +17,8 @@ export function checkHost(host) {
18
17
  return { cargo: host.cargo, os: host.os, comment: Number(minor) >= 97 }
19
18
  }
20
19
 
21
- // A file cargo reads, by its path from the root, as text, or undefined where
22
- // there is none: a link at it or on the way to it is refused, so that nothing
23
- // is read from outside the project's view.
20
+ // A file cargo reads, or undefined where there is none: a link at or on the way to it is refused, so
21
+ // nothing is read from outside the project's view
24
22
  export function readUnlinked(project, file, what) {
25
23
  const segments = file.split('/')
26
24
  for (let i = 1; i <= segments.length; i++) {
@@ -61,8 +59,7 @@ function given(manifests) {
61
59
 
62
60
  const LOCKFILE = 'lockfile must be the Cargo.lock text, or left out where project is given'
63
61
 
64
- // `project` the view manifests are read from, and `given` the directories
65
- // of those given, which have to be those read.
62
+ // `given` are the directories of the manifests given, which have to be those read
66
63
  export function inputsOf(options) {
67
64
  const { lockfile, manifests, config, project } = options
68
65
  if (lockfile === undefined) {