@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.d.ts CHANGED
@@ -1,708 +1,299 @@
1
- import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js'
2
- import type { NodeType, Vfs } from '@preventive/vfs'
1
+ /**
2
+ * The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts` makes, built in memory from a
3
+ * pnpm lockfile: with the isolated linker of pnpm 10, 11 or 12, or the hoisted one of pnpm 10 or 11
4
+ *
5
+ * ```js
6
+ * import { buildPnpmTree, findPnpmProjects } from '@preventive/deptree/pnpm.js'
7
+ * ```
8
+ *
9
+ * Packages come from https://registry.npmjs.org/ alone, through `@preventive/upstream`, each tarball
10
+ * held to the lockfile's integrity and each patch to its hash, applied only where every hunk matches.
11
+ * Nothing is left to a guess: whatever this does not build exactly as that pnpm would is refused with
12
+ * a DeptreeError saying where.
13
+ *
14
+ * @module @preventive/deptree/pnpm.js
15
+ */
3
16
 
4
- // What the lockfile reader and the YAML parser refuse with: the cause of
5
- // the DeptreeError that names the file they refused, pnpm-lock.yaml or
6
- // pnpm-workspace.yaml.
7
- export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
17
+ import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js';
18
+ import type { NodeType, Vfs } from '@preventive/vfs';
8
19
 
9
- // Where @preventive/upstream caches what it fetches, tarballs among them.
10
- // Tarballs are fetched through it, and that is the one place anything here
11
- // touches a filesystem. Before the network, it takes a tarball from npm's
12
- // cache -- under $npm_config_cache, or ~/.npm -- from ~/.audit/cache/tgz, or
13
- // from its own default cache directory or stasis's, where one there has the
14
- // lockfile's integrity, and writes none of them; then from its own cache,
15
- // where one is set, which is where it writes each tarball it fetches:
16
- // setCacheDir() sets the default one, and setCacheDir(false) unsets it.
17
- // Unset, which it is until set, it writes nothing: a tarball in none of
18
- // the others is fetched every time, each once for however many snapshots
19
- // it has. The project is read only through the view given as `project`,
20
- // and the tree built in a Vfs.
21
- export { setCacheDir } from '@preventive/upstream/npm.js'
20
+ /** What the lockfile reader and the YAML parser refuse with, as the `cause` of a DeptreeError naming the file */
21
+ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js';
22
22
 
23
- // The machine pnpm would install on, which a tree depends on: `pnpm` is
24
- // the version that installs, and has to be a 10.x, an 11.x or a 12.x, the
25
- // three built for, each as it differs from the others. pnpm 12 is checked
26
- // against real installs from 12.8.1 on; an earlier one is taken but where
27
- // its changelog says it installs otherwise, as its bug, which is not built
28
- // for: a `file:` directory's file whose mode is not 0o644, for 12.8.0, and
29
- // a production tree an edge to an optional peer changes, before 12.7.0.
30
- // Left out, it is the one the root package.json's
31
- // packageManager pins, which pnpm switches to, and has to be given where
32
- // that pins none. `node` is the Node it runs on, an exact version,
33
- // unless the settings name a nodeVersion or, for pnpm 11, the root
34
- // package.json's engines.runtime pins one; left out, with none of those,
35
- // the Node is unknown, and every engines.node and range for Node takes it,
36
- // so nothing is refused or left out for it; `os`, `cpu` and `libc` as Node
37
- // and pnpm name them -- `linux`, `x64`, `glibc` -- with `unknown` for a libc
38
- // outside Linux, as pnpm has it.
39
- // Windows is refused: pnpm links there with junctions to absolute paths.
40
- // An optional package the machine cannot run is left out, as pnpm leaves
41
- // it out; supportedArchitectures in the settings widens what is taken.
23
+ /**
24
+ * Sets where `@preventive/upstream` caches the tarballs it fetches, or with false unsets it
25
+ *
26
+ * Before the network, a tarball is taken from npm's cache ($npm_config_cache or ~/.npm),
27
+ * ~/.audit/cache/tgz, or upstream's or stasis's default cache, where one has the lockfile's integrity,
28
+ * none of which is written. Unset, which it is until set, nothing is written, and a tarball is fetched
29
+ * every time.
30
+ */
31
+ export { setCacheDir } from '@preventive/upstream/npm.js';
32
+
33
+ /**
34
+ * The machine pnpm would install on
35
+ *
36
+ * An optional package the host cannot run is left out, as pnpm leaves it out; supportedArchitectures in
37
+ * the settings widens what is taken. Windows is refused, as pnpm links there with junctions to absolute
38
+ * paths.
39
+ */
42
40
  export interface PnpmHost {
43
- pnpm?: string
44
- node?: string
45
- os: string
46
- cpu: string
47
- libc: 'glibc' | 'musl' | 'unknown'
41
+ /**
42
+ * The pnpm that installs, a 10.x, 11.x or 12.x, each built for as it differs (12 checked from 12.8.1)
43
+ *
44
+ * Default: the one the root package.json's packageManager pins, which pnpm switches to.
45
+ */
46
+ pnpm?: string;
47
+ /** The exact Node it runs on (default: the settings' nodeVersion, or pnpm 11's engines.runtime pin, else any) */
48
+ node?: string;
49
+ /** As Node names it, such as `linux` */
50
+ os: string;
51
+ /** As Node names it, such as `x64` */
52
+ cpu: string;
53
+ /** As pnpm names it, `unknown` outside Linux */
54
+ libc: 'glibc' | 'musl' | 'unknown';
48
55
  }
49
56
 
50
- // A view of the lockfile's directory, by paths from `/`: a Vfs, or
51
- // anything with its readdir, lstat, stat and readFile, such as one of a
52
- // directory on disk, of which only this is read: the names in a
53
- // directory; what a path is, `file`, `directory` or `symlink`, and its
54
- // mode, with lstat, and what it leads to with stat; and a file's bytes.
55
- // Each throws an error whose `code` is ENOENT, ENOTDIR or ELOOP for a path
56
- // that leads nowhere. Nothing is written to it.
57
+ /**
58
+ * A read-only view of the lockfile's directory, by paths from `/`: a Vfs, or one of a directory on disk
59
+ *
60
+ * Each method throws an error whose `code` is ENOENT, ENOTDIR or ELOOP for a path that leads nowhere.
61
+ */
57
62
  export interface PnpmProject {
58
- readdir(path: string): string[]
59
- lstat(path: string): { type: NodeType, mode: number }
60
- stat(path: string): { type: NodeType }
61
- readFile(path: string): Uint8Array
63
+ readdir(path: string): string[];
64
+ lstat(path: string): { type: NodeType; mode: number };
65
+ stat(path: string): { type: NodeType };
66
+ readFile(path: string): Uint8Array;
62
67
  }
63
68
 
64
- // The files an install reads: pnpm-lock.yaml; the package.json of every
65
- // project it installs; pnpm-workspace.yaml and the .npmrc, where there are
66
- // any; and every patch file the settings' patchedDependencies name.
67
- //
68
- // With `lockfile`, they are given as text: `manifests` by the project's
69
- // directory relative to the lockfile's (`.` for the root, then as its
70
- // importers are keyed), `patches` by the path from the lockfile's
71
- // directory the settings name each by, and only those.
72
- //
73
- // Without it, they are read from `project`, as pnpm reads them there, and
74
- // none of them may be given: pnpm-lock.yaml, which has to be there;
75
- // pnpm-workspace.yaml, which, where there is none, pnpm refuses under
76
- // another name it looks for it by, such as pnpm-workspace.yml; the .npmrc;
77
- // the package.json of every project pnpm finds, as findPnpmProjects finds
78
- // them, and no other, an importer pnpm-workspace.yaml's packages do not
79
- // take refused unread; and each patch the settings name, and no other,
80
- // which has to be under the lockfile's directory. Each is read as
81
- // UTF-8, and refused where it is not, a byte order mark kept as it is in
82
- // text given; a refusal names each as it would given:
83
- // `manifests["packages/x"]`, `patches["patches/p.patch"]`.
84
- //
85
- // Settings from anywhere else -- another .npmrc, the environment, the
86
- // command line -- are not read, and are taken to be at their defaults; so
87
- // is pnpm taken to run as itself, not under corepack, and free to switch
88
- // to the version a project pins.
89
- //
90
- // A workspace is one lockfile for several projects, each a package.json:
91
- // the root, and every directory pnpm-workspace.yaml's `packages` globs
92
- // take, as pnpm globs for them -- `*` and `**`, a leading `!` to leave out,
93
- // and no other glob syntax. Without `packages` the root is the only
94
- // project. Every importer has to have its package.json, and be a project
95
- // those globs take; and every project pnpm would find has to be given,
96
- // which buildPnpmTree cannot check where it is given them, as it is not
97
- // given the directories: findPnpmProjects finds them in those. A project the
98
- // lockfile has no importer for is held to an empty one, as pnpm holds it:
99
- // with no dependencies it is installed, and hoisted by its name, and with
100
- // any it is refused as not up to date. Its directory has to be given as
101
- // pnpm would key its importer: from the lockfile's, in normal form.
102
- //
103
- // Each project is held to its importer as --frozen-lockfile holds it: its
104
- // dependencies, devDependencies, optionalDependencies and, with
105
- // autoInstallPeers, the peers it lists nowhere else, have to be what the
106
- // importer records, and in the ranges they ask for, but `*`, which pnpm
107
- // resolves to a prerelease `latest` too. The projects' names are what
108
- // hoistWorkspacePackages hoists them by.
109
- //
110
- // Settings are read as `pnpm install` 10 reads them, each source over the
111
- // one before: the .npmrc, then pnpm-workspace.yaml, then what the
112
- // package.json's `pnpm` field sets, which pnpm's install spreads over the
113
- // rest. Overrides are the package.json's Yarn-style `resolutions` and
114
- // `pnpm.overrides`, the second winning a selector both name; only where
115
- // those name none are pnpm-workspace.yaml's `overrides` read. `$name` in
116
- // one is the root package.json's own specifier for `name`, and
117
- // `catalog:` what the workspace's catalog gives the package. One to a
118
- // directory -- a path alone, such as `./vendor/foo`, `link:` or `file:` --
119
- // is read only with `project` given, and only where the directory is
120
- // under the lockfile's and holds a package.json there. pnpm links to it by a
121
- // path alone or `link:`. By `file:` it installs it as a package, of the
122
- // files its packlist picks -- npm-packlist 5.1.3 for pnpm 10, 10.0.4
123
- // for pnpm 11, and pnpm 12's own port of it -- which each is followed here
124
- // as that version runs: by package.json's `files`, `main`, `bin` and, but
125
- // for pnpm 12, `browser`; by the .npmignore and .gitignore files where it
126
- // reads them; and by its own rules, case and all, odd steps among them,
127
- // such as pnpm 10 keeping what a `files` glob takes that their rules
128
- // leave out, or the minimatch pnpm 10 bundles from 10.31 matching `**`
129
- // otherwise. Of glob syntax only `*`, `?` and `**` are followed, which all
130
- // read alike: a pattern with braces, a class, an extglob or a backslash is
131
- // refused, and so are a link the walk comes on, bundled dependencies,
132
- // `files` that is not a list of strings, a file kept by a path a pattern
133
- // spells with a `.` part, and a package.json with a byte order mark for
134
- // pnpm 11 before 11.28, which fails on it. Refused too, where a pnpm may
135
- // make too large a regexp of it, failing for pnpm 10 and 11 and dropping
136
- // it unread for 12, is a pattern of more than 4096 characters and, for pnpm
137
- // 12, an ignore file or `files` of more than 16 KiB; and so are a pattern
138
- // with more than 100 `**` parts for pnpm 10, and a directory nested
139
- // more than 100 deep, for the time matching them takes. Matching takes
140
- // time linear in the path and the pattern. pnpm hardlinks those files from
141
- // the directory into each snapshot of the package, in their modes, which
142
- // are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
143
- // 0o755 and 0o775, and, for pnpm 12.8.0, which installs each at 0o644, any
144
- // but 0o644. So a file linking a bin makes executable -- 0o755 for
145
- // pnpm 10, its mode with 0o111 added for 11 and 12 -- is made so in
146
- // every snapshot and in the directory, which is not written here; a CRLF
147
- // `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package -- an install script, a
148
- // binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
149
- // .hooks directory -- or, with pnpm 11 and 12, where packageImportMethod is
150
- // other than auto or hardlink, each snapshot has a copy of its own
151
- // instead. One by `file:` to a tarball is refused, and so is a `file:`
152
- // dependency no override names. One to the lockfile's own directory that
153
- // the lockfile has as `file:` and an empty path, as pnpm 10 and 11
154
- // write it, is refused for pnpm 12, which fails on that lockfile.
155
- //
156
- // Package extensions, `packageExtensions`, add to the package.json of each
157
- // package a selector names, by its name and the versions in its range,
158
- // before the overrides are read: the package.json's own entry in a field
159
- // wins, and of two extensions the first. The lockfile is held to their
160
- // checksum, as pnpm holds it: object-hash's sha256 of the setting, its
161
- // names sorted by code point for pnpm 12. Only what pnpm 10, 11 and 12
162
- // hash alike is taken: dependencies, optionalDependencies and
163
- // peerDependencies of names to strings, and peerDependenciesMeta of names
164
- // to `optional` alone. Refused too: a selector that names no package; an
165
- // extension that names a project, whose package.json pnpm extends too;
166
- // for pnpm 12, a range other than comparators and x-ranges joined by
167
- // spaces and `||`, as it fails on some that npm's semver reads, and a name
168
- // of digits alone, as it applies them in the order written; and, for pnpm
169
- // 12 before 12.17.0, an extension of a directory a project depends on by
170
- // `file:`, which that pnpm holds to its package.json without it.
171
- //
172
- // Of the .npmrc, only what pnpm reads for an install is read: its settings
173
- // by their kebab-case names, those that can change the tree held to what
174
- // is built here, and all else -- npm's own settings, publishing's,
175
- // credentials, other names -- passed over. A `${VAR}` pnpm would fill in is
176
- // taken in a line passed over where the rest of the file would not change
177
- // the tree, as pnpm drops the whole file where the variable is unset; but
178
- // `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`, the registry's token as
179
- // a project commonly gives it, is taken to be set, and the rest read.
180
- //
181
- // pnpm 11 reads its settings from pnpm-workspace.yaml alone, as this does
182
- // for it: of the .npmrc only its registries, and of the package.json no
183
- // setting, `resolutions` and the `pnpm` field none. It passes over a
184
- // pnpm-workspace.yaml key not in camelCase; its own settings are read as
185
- // the rest are, pmOnFail and runtimeOnFail among them, which decide what
186
- // its packageManager, devEngines.packageManager and engines.runtime
187
- // checks do. The tree follows the lockfile, as pnpm 11's does with
188
- // trustLockfile: minimumReleaseAge, and the rest of what pnpm 11 checks the
189
- // lockfile against the registry by before it installs -- each package's
190
- // publish time, its tarball URL, its trust -- are passed over.
191
- //
192
- // pnpm 12 reads them so too. Where the root package.json pins a pnpm that
193
- // host.pnpm is, it fails on a key of pnpm-workspace.yaml it does not know,
194
- // one of pnpm 11's such as alwaysAuth among them, which is refused; it
195
- // drops one otherwise, and passes over one not in camelCase it knows. It
196
- // takes hoistPattern and publicHoistPattern only as lists, and passes over
197
- // what it has that pnpm 11 has not but `cargo` or `python` enabled, which
198
- // is refused. It parses every key of pnpm-workspace.yaml into a type of
199
- // its own, and fails on a value that does not parse, or a `tasks` entry it
200
- // holds to be wrong: that is not checked here of a key that leaves the
201
- // tree as it is. Where there is no pnpm-workspace.yaml, it writes one of
202
- // the root package.json's `workspaces` list, its strings but empty ones,
203
- // and installs by it, as this does for it.
204
- //
205
- // `project` is read only where it is said to be here: for the files an
206
- // install reads, without `lockfile`; for the directories a `link:` or an
207
- // override leads to. With it given, a directory the tree links to that is
208
- // no project, and is under the lockfile's, has to be there with a
209
- // package.json, whose bins are read as pnpm reads them; pnpm links to one
210
- // that is not there all the same, warning only as pnpm 10 and 11 resolve,
211
- // never as a frozen install. So it does for `npm:@scope/name@workspace:^`,
212
- // as an override or a dependency, which it takes for a path for its `/`,
213
- // and that link is refused with or without `project`, but where it holds
214
- // a directory of that very name:
215
- // `workspace:@scope/name@^` is the spec that links the workspace package
216
- // by another name. Without it, or
217
- // outside the lockfile's directory, such a directory's bins are not
218
- // known, and neither are those of a project that has them by the files of
219
- // its directories.bin: where one could win a command a package's file is
220
- // linked by, and so decide whether pnpm fixes that file, and fixing it
221
- // would change it, the tree is refused.
222
- //
223
- // `vfs` is a Vfs to mount the tree into, at its root, which is taken to
224
- // be the lockfile's directory, beside whatever it holds, such as the
225
- // projects themselves -- it may be `project` too; without one, a new Vfs
226
- // holds the tree alone. Nothing the tree is built from is read from it. A
227
- // Vfs that holds a node_modules anywhere, or on macOS a name that is one
228
- // there, is refused before anything is fetched: kept beside the tree, Node
229
- // would read it as the tree's, and removed, it would be the caller's lost.
230
- // Nothing there is written over: each directory the tree has is one there
231
- // or is made, and every file and link is written where nothing is. The
232
- // tree is built, and held to every check below, before any of it is
233
- // written, so a refusal leaves the Vfs as it was. Nothing outside
234
- // node_modules is written, though pnpm 10 makes the files a linked
235
- // directory's bins run executable too.
236
- //
237
- // `metadata`, true unless given false, has each registry package's version
238
- // document asked for beside its tarball, through getMeta of
239
- // @preventive/upstream given the lockfile's dist: the one `cache` keeps,
240
- // where its dist is that one, else the registry's, a request for each name
241
- // and version. Its dist has to be the lockfile's, the tarball
242
- // the registry's own URL and the integrity the lockfile's sha512, compared
243
- // as text, with nothing hashed again, as the lockfile copies the
244
- // registry's; and its gitHead, repository, homepage and bugs are the
245
- // package's. False fetches none, and gives none of them.
246
- //
247
- // `cache` is where each registry package's tarball and version document
248
- // are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
249
- // cache where it is left out; in a store of the caller's, with `read` and
250
- // `write`, in place of it; or with false, nowhere, though setCacheDir's
251
- // cache is read all the same. Other tools' caches are read for tarballs
252
- // whatever it is. A TypeError is thrown for anything else.
253
- //
254
- // `sizeEstimateOnly`, false unless given true, builds the tree's directories
255
- // and links alone, and fetches no tarball: each package's directory is made
256
- // where its files would be, and left empty, and each link is made as it is.
257
- // Each registry package's version document is asked for as `metadata` asks
258
- // for it, whatever `metadata` says, and held to the lockfile's dist as it is
259
- // held there; and each copy is listed with its `size`, the document's
260
- // dist.unpackedSize, as getMeta of @preventive/upstream reads it: the bytes
261
- // of the files in its tarball, as the registry counted them when it was
262
- // published, which is what pnpm writes of it, but for a patch and a CRLF `#!`
263
- // line of a bin it rewrites; not the blocks they take, nor what pnpm shares
264
- // by hardlinks from its store. It is undefined where the document names none.
265
- // A `file:` directory is read whole all the same, and its size is that of the
266
- // files its packlist picks. What is checked of a package's files and
267
- // package.json is not, so a lockfile one of those checks would refuse is laid
268
- // out all the same; so is a patched package that pnpm 11 and 12 would, with
269
- // engineStrict, take out or fail on by the engines.node of its package.json,
270
- // patched. But where the files could change the layout, the lockfile is
271
- // refused, before anything is fetched: for the hoisted linker of pnpm 10.21
272
- // to before 11.25, where any patch is configured, a package of more than one
273
- // copy, one with a node_modules, which pnpm drops where it builds the
274
- // package. A `vfs` is not taken with it.
275
- //
276
- // `lazy`, false unless given true, lays the tree out as sizeEstimateOnly
277
- // does, each package's directory made and left empty and each link made,
278
- // but fetches nothing, not even a version document, but where the files
279
- // could change the layout (below): each package is unpacked into it once
280
- // asked for by the tree's `unpack`, and only then fetched, as `metadata`
281
- // and `cache` say. A package unpacked is what the
282
- // full tree has at its path, file for file, patched and fixed as linking
283
- // bins fixes it, and held to every check of its tarball, package.json and
284
- // patch the full tree holds it to; one never asked for is never fetched, so
285
- // a lockfile one of those checks would refuse is laid out all the same, and
286
- // refused where that package is unpacked. Which of a package's bins pnpm
287
- // links turns on the others' bins, and is read only where it could change
288
- // the package's files: a bin pnpm would make executable, or whose CRLF `#!`
289
- // line it would make LF; one that is a directory, which pnpm 12 fails
290
- // on; or any bin of a patched package. With the hoisted linker where any
291
- // patch is configured, so does what pnpm's build pass does to a package it
292
- // builds, patched or with an install script, which is read for every such
293
- // package. The first such unpack fetches the packages whose bins those are
294
- // read from, but those unpacked already, which are read back from the
295
- // tree, and keeps them: with the isolated linker, those the lockfile says
296
- // have bins, those that bundle others, those whose bins pnpm reads whatever
297
- // the lockfile says (a project's dependencies with pnpm 10, their
298
- // peers with pnpm 11 and 12, and those beside a dependency outside the tree
299
- // with pnpm 10 and 11), and directories, which are read with the tree; with
300
- // the hoisted linker, those the lockfile says have bins, those that bundle
301
- // others, and directories, and where a patch is configured, those patched
302
- // and those that depend on one with bins, whose bins pnpm's build pass
303
- // links where it builds one. Any other is read as having no bins, as the
304
- // lockfile says, and with the hoisted linker as not built: where a patch is
305
- // configured and pnpm builds one, what that does to it, and the bins it
306
- // links of its own, are read once it is unpacked, which turn on nothing
307
- // else's. The hoisted linker links the bins of each package it puts in a
308
- // node_modules, whatever the lockfile says: one whose package.json's `bin`
309
- // is empty text, false or 0 beside a directories.bin, which pnpm 10's
310
- // lockfile says has none, has bins all the same, and the others' bins of
311
- // their names in that node_modules are fixed as though it had none. Where
312
- // the files could change the layout, with the hoisted linker of pnpm 10.21
313
- // to before 11.25 where any patch is configured, a package of more than one
314
- // copy, one with a node_modules, is fetched with the tree, held to its
315
- // checks then, and the lockfile refused as the full tree refuses it where
316
- // pnpm builds the package. A
317
- // `vfs` is not taken with it, nor `sizeEstimateOnly`.
318
- //
319
- // `production`, false unless given true, builds the tree `pnpm install
320
- // --prod` makes, from the lockfile pnpm leaves of it: each project's
321
- // devDependencies dropped, a `link:` among them, and of the snapshots
322
- // those the rest reach, through dependencies, optionalDependencies and the
323
- // projects they link to. The tree is laid out of those alone -- what the
324
- // host cannot run left out as pnpm walks them, hoisted, its bins linked --
325
- // as without it. Nothing else is fetched,
326
- // nor its files checked; all else is held to the whole lockfile, as
327
- // without it. From pnpm 11.28.0 and 12.7.0, an edge to an optional
328
- // peer, which the snapshot is linked to only as each project that reaches it
329
- // lists the peer itself, or as the peer is among the root's devDependencies
330
- // and resolvePeersFromWorkspaceRoot is set, is not walked, and is linked
331
- // only where the rest reach the peer: a devDependency only there to satisfy
332
- // an optional peer of a production dependency is left out. From 11.28.7 and
333
- // 12.15.0, such an edge is one to a peer the snapshot's key binds, or to any
334
- // of a key with a hash in place of its peers; before, any dependency by the
335
- // name of one of the snapshot's optional peers, though the snapshot
336
- // resolved it as its own and its package.json asks for it, as the lockfile
337
- // pnpm 11.28.7 and 12.15.0 on write records. pnpm 12 before 12.7.0 walks
338
- // each such edge, as pnpm 11 before 11.28.0 does; a lockfile where walking
339
- // those 12.15.0 does not walk installs otherwise, or leaves out otherwise
340
- // what the host cannot run, is refused, and any other is laid out as both
341
- // lay it out.
342
- //
343
- // The two ways the files come, one or the other: given, with `lockfile`
344
- // and `manifests`, `project` read only for directories; or read, with
345
- // `project` and none of them.
346
- export type PnpmTreeOptions = PnpmTreeGiven | PnpmTreeRead
69
+ /**
70
+ * How the tree is built: from the files an install reads, given as text (PnpmTreeGiven) or read from
71
+ * `project` as pnpm reads them from disk (PnpmTreeRead)
72
+ *
73
+ * Settings are read as `pnpm install` reads them for the host's pnpm: pnpm 10 the .npmrc, then
74
+ * pnpm-workspace.yaml, then package.json's `pnpm` field, each over the one before; pnpm 11 and 12
75
+ * pnpm-workspace.yaml alone, and of the .npmrc only its registries. Settings from anywhere else are at
76
+ * their defaults. Each setting that can change the tree is held to what is built, and each other one is
77
+ * passed over.
78
+ */
79
+ export type PnpmTreeOptions = PnpmTreeGiven | PnpmTreeRead;
80
+
81
+ export type PnpmLayoutOptions = PnpmTreeOptions & { sizeEstimateOnly: true; vfs?: undefined };
347
82
 
348
- export type PnpmLayoutOptions = PnpmTreeOptions & { sizeEstimateOnly: true, vfs?: undefined }
83
+ export type PnpmLazyOptions = PnpmTreeOptions & { lazy: true; sizeEstimateOnly?: false; vfs?: undefined };
349
84
 
350
- export type PnpmLazyOptions = PnpmTreeOptions & { lazy: true, sizeEstimateOnly?: false, vfs?: undefined }
85
+ /** What both ways of giving the files take */
86
+ interface PnpmTreeCommon {
87
+ host: PnpmHost;
88
+ /**
89
+ * A Vfs to mount the tree into at its root, the lockfile's directory, beside what it holds
90
+ *
91
+ * Default: a new one. One holding a node_modules anywhere is refused before anything is fetched;
92
+ * nothing in it is written over, and a refusal leaves it as it was.
93
+ */
94
+ vfs?: Vfs;
95
+ /**
96
+ * Fetch each registry package's version document, through getMeta of `@preventive/upstream`, for its
97
+ * commit, repository, homepage and bugs; its dist has to be the lockfile's (default: true)
98
+ */
99
+ metadata?: boolean;
100
+ /**
101
+ * Where tarballs and version documents are kept: setCacheDir's (the default), a store with `read` and
102
+ * `write`, or false for nowhere
103
+ */
104
+ cache?: CacheOptions['cache'];
105
+ /**
106
+ * Lay out the directories and links alone, fetching no tarball: each copy is listed with the size
107
+ * its version document gives (default: false)
108
+ *
109
+ * A package's files are not checked, but where they could change the layout, which is refused.
110
+ */
111
+ sizeEstimateOnly?: boolean;
112
+ /**
113
+ * Lay out the directories and links alone, fetching nothing, and unpack each package into the tree
114
+ * once asked for by `unpack`, held then to every check the full tree holds it to (default: false)
115
+ */
116
+ lazy?: boolean;
117
+ /**
118
+ * Build the tree `--prod` makes, from the lockfile pnpm leaves of it, each project's devDependencies
119
+ * dropped; all else is held to the whole lockfile (default: false)
120
+ */
121
+ production?: boolean;
122
+ }
351
123
 
352
- export interface PnpmTreeGiven {
353
- lockfile: string
354
- manifests: Record<string, string> | Map<string, string>
355
- workspace?: string
356
- npmrc?: string
357
- patches?: Record<string, string> | Map<string, string>
358
- project?: PnpmProject
359
- host: PnpmHost
360
- vfs?: Vfs
361
- metadata?: boolean
362
- cache?: CacheOptions['cache']
363
- sizeEstimateOnly?: boolean
364
- lazy?: boolean
365
- production?: boolean
124
+ /** The files given as text */
125
+ export interface PnpmTreeGiven extends PnpmTreeCommon {
126
+ /** pnpm-lock.yaml */
127
+ lockfile: string;
128
+ /**
129
+ * Each project's package.json, by its directory from the lockfile's as its importer is keyed, `.` for
130
+ * the root: every project pnpm would find (findPnpmProjects), and no other
131
+ */
132
+ manifests: Record<string, string> | Map<string, string>;
133
+ /** pnpm-workspace.yaml */
134
+ workspace?: string;
135
+ /** The .npmrc beside the lockfile */
136
+ npmrc?: string;
137
+ /** Each patch patchedDependencies names, by the path it names it by, and no other */
138
+ patches?: Record<string, string> | Map<string, string>;
139
+ /** Read only for the directories a `link:` or an override leads to, where it is given */
140
+ project?: PnpmProject;
366
141
  }
367
142
 
368
- export interface PnpmTreeRead {
369
- lockfile?: undefined
370
- manifests?: undefined
371
- workspace?: undefined
372
- npmrc?: undefined
373
- patches?: undefined
374
- project: PnpmProject
375
- host: PnpmHost
376
- vfs?: Vfs
377
- metadata?: boolean
378
- cache?: CacheOptions['cache']
379
- sizeEstimateOnly?: boolean
380
- lazy?: boolean
381
- production?: boolean
143
+ /** The files read from `project`, as pnpm reads them; none of them may be given */
144
+ export interface PnpmTreeRead extends PnpmTreeCommon {
145
+ lockfile?: undefined;
146
+ manifests?: undefined;
147
+ workspace?: undefined;
148
+ npmrc?: undefined;
149
+ patches?: undefined;
150
+ project: PnpmProject;
382
151
  }
383
152
 
384
- // What buildPnpmTree counts, all of it plain numbers: `projects` the
385
- // importers; `snapshots` the lockfile's; `installed` those in the tree;
386
- // `skipped` the optional ones left out, as the host cannot run them or
387
- // only such reach them; `incompatible` those installed although the host
388
- // does not take their platform or engines, which pnpm warns of; `tarballs`
389
- // the packages fetched, each once; `patched` the snapshots a patch is
390
- // applied to; `files` and `bytes` what is written; `links` the symlinks.
391
- // With `sizeEstimateOnly`, `tarballs` counts the packages fetched by their
392
- // version document alone; `files` is 0, as none is written, and `bytes`
393
- // what the sizes of those installed add up to, each copy's, of those with
394
- // one. With `lazy`, `tarballs`, `files` and `bytes` count what is unpacked,
395
- // each 0 until `unpack` is asked, which adds to them.
153
+ /** What a build counts */
396
154
  export interface PnpmTreeStats {
397
- projects: number
398
- snapshots: number
399
- installed: number
400
- skipped: number
401
- incompatible: number
402
- tarballs: number
403
- patched: number
404
- files: number
405
- bytes: number
406
- links: number
155
+ /** The importers */
156
+ projects: number;
157
+ /** The lockfile's snapshots */
158
+ snapshots: number;
159
+ /** The snapshots in the tree */
160
+ installed: number;
161
+ /** The optional ones left out, as the host cannot run them or only such reach them */
162
+ skipped: number;
163
+ /** Those installed though the host does not take their platform or engines, which pnpm warns of */
164
+ incompatible: number;
165
+ /** The packages fetched, each once; with `sizeEstimateOnly` by their version document, with `lazy` as unpacked */
166
+ tarballs: number;
167
+ /** The snapshots a patch is applied to */
168
+ patched: number;
169
+ /** The files written; 0 with `sizeEstimateOnly`, and with `lazy` those unpacked */
170
+ files: number;
171
+ /** Their bytes; with `sizeEstimateOnly`, the sizes of the copies installed */
172
+ bytes: number;
173
+ /** The symlinks */
174
+ links: number;
407
175
  }
408
176
 
409
- // A snapshot in the tree, as an SBOM would list it: `path` is where its
410
- // files are, from the lockfile's directory, which is `/` of the Vfs --
411
- // node_modules/.pnpm/<dir>/node_modules/<name>; `key` the lockfile's
412
- // snapshot key, its peers and patch hash in it. `name` and `version` are
413
- // the package's own, which its package.json is held to, and `integrity`
414
- // the sha512 its tarball is held to; one a `file:` override has pnpm
415
- // install from a directory has `directory`, from the lockfile's, `.` for
416
- // its own, and neither a version nor an integrity, as the lockfile records
417
- // none. `commit` is the gitHead of a registry package's version document,
418
- // where `metadata` has it fetched and it is a full commit id, the commit
419
- // npm read off the checkout it published from; `repository`, `homepage`
420
- // and `bugs` the document's, as getMeta of @preventive/upstream reads
421
- // them; each undefined elsewhere, and all of it the publisher's word, held
422
- // to no repository.
423
- // `dev` is whether devDependencies alone reach it: no project's
424
- // dependencies or optionalDependencies do, through what is installed, so
425
- // `pnpm install --prod` would leave it out, and so none is with
426
- // `production`. `optional` is whether optional
427
- // dependencies alone reach it, as the lockfile records it. `patch` is the
428
- // patch applied to it, by pnpm's hash of it and the path the settings name
429
- // it by: of two patches of one text, the first they name.
177
+ /** A snapshot in the tree, as an SBOM would list it */
430
178
  export interface PnpmInstalled {
431
- path: string
432
- key: string
433
- name: string
434
- version: string | undefined
435
- integrity: string | undefined
436
- directory: string | undefined
437
- commit: string | undefined
438
- repository: string | PackageRepository | undefined
439
- homepage: string | undefined
440
- bugs: string | PackageBugs | undefined
441
- dev: boolean
442
- optional: boolean
443
- patch: { hash: string, path: string } | undefined
179
+ /** Where its files are, from the lockfile's directory: node_modules/.pnpm/<dir>/node_modules/<name>, or a hoisted copy's */
180
+ path: string;
181
+ /** The lockfile's snapshot key, its peers and patch hash in it */
182
+ key: string;
183
+ /** The package's own, which its package.json is held to */
184
+ name: string;
185
+ /** Undefined for a package installed from a directory */
186
+ version: string | undefined;
187
+ /** The sha512 its tarball is held to; undefined for a directory */
188
+ integrity: string | undefined;
189
+ /** The directory a `file:` override installs it from, from the lockfile's (`.` for its own) */
190
+ directory: string | undefined;
191
+ /** The gitHead of its version document, where `metadata` fetched it and it is a full commit id */
192
+ commit: string | undefined;
193
+ /** As its version document gives it: the publisher's word, held to no repository */
194
+ repository: string | PackageRepository | undefined;
195
+ homepage: string | undefined;
196
+ bugs: string | PackageBugs | undefined;
197
+ /** Whether devDependencies alone reach it, so `--prod` would leave it out */
198
+ dev: boolean;
199
+ /** Whether optional dependencies alone reach it, as the lockfile records */
200
+ optional: boolean;
201
+ /** The patch applied, by pnpm's hash and the path the settings name it by (the first, of two of one text) */
202
+ patch: { hash: string; path: string } | undefined;
444
203
  }
445
204
 
446
- // `vfs` is the one given, the tree mounted into it, or a new one.
447
- // `installed` is each snapshot in the tree, one for each `stats.installed`
448
- // counts, in the lockfile's order; with the hoisted linker, each copy, at
449
- // node_modules/<alias> under where it landed, in the order pnpm makes them,
450
- // each with the snapshot copied there.
451
205
  export interface PnpmTree {
452
- vfs: Vfs
453
- stats: PnpmTreeStats
454
- installed: PnpmInstalled[]
206
+ /** The one given, the tree mounted into it, or a new one */
207
+ vfs: Vfs;
208
+ stats: PnpmTreeStats;
209
+ /** Each snapshot in the tree in lockfile order; with the hoisted linker each copy, in the order pnpm makes them */
210
+ installed: PnpmInstalled[];
455
211
  }
456
212
 
457
- // With `sizeEstimateOnly`, each copy as `installed` lists it, with its
458
- // `size`.
459
213
  export interface PnpmLaidOut extends PnpmInstalled {
460
- size: number | undefined
214
+ /** Its version document's dist.unpackedSize, or a directory's files' bytes */
215
+ size: number | undefined;
461
216
  }
462
217
 
463
- // With `sizeEstimateOnly`: `vfs` a new one, of the tree's directories and
464
- // links.
218
+ /** With `sizeEstimateOnly`: a new Vfs of the tree's directories and links */
465
219
  export interface PnpmLayout {
466
- vfs: Vfs
467
- stats: PnpmTreeStats
468
- installed: PnpmLaidOut[]
220
+ vfs: Vfs;
221
+ stats: PnpmTreeStats;
222
+ installed: PnpmLaidOut[];
469
223
  }
470
224
 
471
- // With `lazy`: `vfs` a new one, of the tree's directories and links, which
472
- // `unpack` writes each package's files into; `installed` each snapshot, with
473
- // nothing its version document says, as none is fetched. `unpack` takes the
474
- // paths of snapshots as `installed` lists them, and resolves once each is
475
- // unpacked, to their entries in that order, with what each one's version
476
- // document says where `metadata` has it fetched. Each is unpacked once,
477
- // however often and at once it is asked for, and a few tarballs are fetched at
478
- // a time; each is written whole or not at all, and one refused rejects the
479
- // call, and each call that asks for it after, with the DeptreeError the full
480
- // tree is refused with, once every package the call asks for is done. A path
481
- // the tree installs no package at is a TypeError.
225
+ /** With `lazy`: a new Vfs of the tree's directories and links, which `unpack` writes packages into */
482
226
  export interface PnpmLazyTree extends PnpmTree {
483
- unpack(paths: Iterable<string>): Promise<PnpmInstalled[]>
227
+ /**
228
+ * Unpack the packages at `paths`, as `installed` lists them, a few fetched at a time
229
+ *
230
+ * Each is unpacked once, however often asked for, and written whole or not at all; one refused rejects
231
+ * this call and each later one asking for it, with the DeptreeError the full tree is refused with. A
232
+ * path the tree has no package at is a TypeError.
233
+ *
234
+ * @returns Their entries in that order, with what each version document says where `metadata` fetched it
235
+ */
236
+ unpack(paths: Iterable<string>): Promise<PnpmInstalled[]>;
484
237
  }
485
238
 
486
- // The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`,
487
- // with `production` --prod too, makes with the isolated linker of
488
- // host.pnpm, 10, 11 or 12, or the hoisted one of pnpm 10 or 11, and no
489
- // other install: whatever the settings say of frozen lockfiles, the install
490
- // is frozen, which is also the only one that hoists by the lockfile's graph
491
- // alone. It is rooted at the lockfile's directory: each package's
492
- // files at node_modules/.pnpm/<dir>/node_modules/<name>, its dependencies
493
- // linked beside it, the hoisted aliases, and each project's own
494
- // node_modules of links. Links are relative; a `link:` dependency leads
495
- // where the lockfile says, which the tree does not hold. Scripts are
496
- // always ignored, as `--ignore-scripts` has pnpm ignore them, whatever the
497
- // settings would allow to build. No .bin is written, nor pnpm's own state
498
- // files; but each file a bin pnpm links runs is left as linking leaves it:
499
- // executable, and with a CRLF ending its `#!` line made LF. Every file is
500
- // its own, as pnpm's files are where it clones or copies them from its
501
- // store; where it hardlinks them instead, making one executable makes
502
- // every file of the same content executable, and the store's, for later
503
- // installs too, which is not followed here. Every file is written once,
504
- // and a write that would replace anything with something else is refused;
505
- // into a Vfs given, one that would replace anything at all.
506
- //
507
- // pnpm 11 links bins otherwise in places -- npm owns `npx` and pnpm its
508
- // aliases, a project's .bin takes the bins of the peers its dependencies
509
- // require -- and each is built as the one given links them.
510
- //
511
- // pnpm 12, a rewrite of pnpm, makes its tree otherwise again, and it is
512
- // built as pnpm 12 makes it. It links each package's own bins into its own
513
- // node_modules/.bin, beside its dependencies', and of two of one name
514
- // keeps the one of the package whose name sorts first by its bytes; makes
515
- // a file a bin runs executable without rewriting a CRLF `#!` line, and
516
- // fails on a bin that is a directory, which is refused; reads `bin` and
517
- // directories.bin otherwise, dotfiles among them, and a package's null
518
- // `bin` beside a directories.bin as its store has the package or not,
519
- // which is refused. It links no package to
520
- // a dependency of its own name, and writes a file a patch makes as
521
- // 0o644, whatever mode the patch gives it. It hoists from a graph of every
522
- // snapshot, those left out walked through but not hoisted, keeps from
523
- // hoisting the root project's aliases but its `link:`s, those left out
524
- // among them, and takes the snapshots of one depth in the order of their
525
- // directories' names. It names a directory under node_modules/.pnpm by the
526
- // UTF-8 bytes of its key, which only a key that is not ASCII tells. It
527
- // shares pnpm 11's store, and takes what pnpm 11 left there, such as a
528
- // patched package as pnpm 11 built it, which is not followed here: the
529
- // tree is the one a store of pnpm 12's own gives.
530
- //
531
- // With nodeLinker: hoisted, for pnpm 10 and 11, the tree is the one the
532
- // hoisted linker makes: each package copied to node_modules/<alias> as near
533
- // the root as @yarnpkg/nm's hoist takes it, under what needs it where the
534
- // name there is another's, and each project's dependencies the root has
535
- // another of in its own node_modules; a project's `link:` dependencies
536
- // linked there, and a package's refused, which pnpm links nowhere; and no
537
- // node_modules/.pnpm, where pnpm keeps only its state. pnpm takes every
538
- // snapshot of one name and version for the first it comes to, and every
539
- // directory of one name for one, as is followed here; from pnpm 11.24, each
540
- // snapshot of a directory for its own. From pnpm 11.28 it also links each
541
- // named project into the root's node_modules by its name, as
542
- // hoistWorkspacePackages has it, where a hoist pattern matches it and the
543
- // root depends on nothing of that name and no package landed there by it,
544
- // their case folded; and from 11.28.1 does not hoist a project's `link:`
545
- // into itself (`link:<root>/`). Every copy has to be its own, so
546
- // packageImportMethod has to be copy, clone or clone-or-copy: any other
547
- // hardlinks from pnpm's store. Bins are fixed as pnpm links them: in each
548
- // node_modules as it fills it, then in each project's again with its links
549
- // in, a command of the project's own dependencies over another's. Where any
550
- // patch is configured, pnpm builds each package patched or with an install
551
- // script in one of its copies, which it finds through the dependencies of
552
- // each, by snapshot or from pnpm 11.23 by package, linking its
553
- // dependencies' bins and its own, and links that copy's files into the
554
- // others: before pnpm 10.21 in place, which leaves the others unpatched;
555
- // from 10.21 a copy of hardlinks put in place of each, with no
556
- // node_modules, which drops the copy's own; and from 11.25 each file but
557
- // those under a node_modules in place of the copy's own, keeping its
558
- // node_modules and what the built copy has not, which leaves a file the
559
- // patch deletes in the others. These are refused where they would change a
560
- // copy, and so is a patched package no copy of which the build reaches,
561
- // which pnpm leaves unpatched; which copy pnpm builds is not followed, and
562
- // refused where it would change a bin. Hoisting is refused past 50,000,000
563
- // steps, weighted by the work each does, or a tree of 100,000 packages.
564
- //
565
- // The lockfile is held to what a frozen install holds it to, and refused
566
- // where pnpm would refuse it: the settings that shaped its resolution --
567
- // catalogs, overrides, package extensions, optional dependencies left out,
568
- // patches, autoInstallPeers, dedupePeers, peersSuffixMaxLength -- and each
569
- // project's package.json, read through pnpm's read-package hook as pnpm
570
- // reads it. The root package.json's packageManager, where it has one, has
571
- // to be `pnpm@` host.pnpm exactly, as pnpm would switch to the one it
572
- // names; a project's engines.pnpm has to take host.pnpm, and with
573
- // engineStrict its engines.node host.node. With engineStrict, pnpm 11
574
- // holds a patched package's engines.node to host.node as its package.json
575
- // has it once patched, not as the lockfile records it, and fails on, or
576
- // takes out, one that does not take it, which is refused. pnpm 11 holds a
577
- // lockfile to more before it installs, and so does this for it: a catalog
578
- // dependency to the catalog's version, a workspace package linked exactly
579
- // where its version is in range, and a patch hash in a snapshot's peers to
580
- // the patch; it lets an optional dependency the importer has no specifier
581
- // for go unresolved, and takes two spellings of one git commit alike. From
582
- // 11.28.7 it holds each directory snapshot a project reaches by `file:` (from
583
- // 11.28.10, through a registry package too) to the directory's package.json. A
584
- // devEngines.packageManager is refused unless its onFail, or pmOnFail, is
585
- // to warn or ignore, as pnpm 11 installs with the pnpm the lockfile pins
586
- // for it; and a root engines.runtime whose onFail is `error` has to take
587
- // host.node.
588
- //
589
- // pnpm 12 reads devEngines.packageManager over packageManager, as pnpm 11
590
- // does but for the onFail of a list with no pnpm in it, which is its first
591
- // entry's own. Unless what to do on a mismatch, or pmOnFail, is to ignore,
592
- // host.pnpm has to be in the pnpm it pins, or the mismatch only to warn,
593
- // and another package manager is refused unless it is only to warn; and a
594
- // pin of devEngines, or of a pnpm 12 by packageManager, has to be recorded
595
- // in the lockfile's env document, of `pnpm` alone at the version pinned,
596
- // or at host.pnpm for a range, with its package: pnpm 12 runs that one,
597
- // and fails a frozen install where it is not there.
598
- //
599
- // pnpm 12 makes none of pnpm 11's further checks of a lockfile, but holds
600
- // a directory a project depends on by `file:` to it: each dependency the
601
- // snapshot has is one its package.json, overridden, asks for, a peer among
602
- // them, an optional peer among its optional dependencies too; each it asks
603
- // for is resolved as it asks, an optional one there or not, and one in both
604
- // lists as optional at the dependency's range; and its peers, one only in
605
- // peerDependenciesMeta at `*`, and which are optional, are what the lockfile
606
- // records, but one that is a dependency too and that pnpm does not install
607
- // itself. A project the lockfile has no importer for is held to none
608
- // where it has no dependencies but peers, and refused otherwise. It checks
609
- // of the projects only the root's engines.node, with engineStrict, and
610
- // with engineStrict refuses whatever it installs that the host cannot run,
611
- // though the lockfile mark it optional. An os, cpu or libc list is read
612
- // by its first entry that names the host's. A patched package's
613
- // engines.node is held to nodeVersion, or the host's Node, whatever the
614
- // root's engines.runtime pins. An engines.node npm's semver does not read,
615
- // or a range of a `-` with an `x`, pnpm 12 reads otherwise, which is
616
- // refused where it would decide what is installed. host.node is, for pnpm
617
- // 12, the `node` it finds on the PATH.
618
- //
619
- // And to more than pnpm holds it to, where a lockfile pnpm writes, or a
620
- // package the registry serves, always holds: each dependency linked where
621
- // the package.json names a directory for it, a path alone among them; each
622
- // snapshot marked optional exactly where only optional dependencies reach
623
- // it; each patch
624
- // on the package the settings pick it for, and each used; each tarball
625
- // gzipped, every file under one directory, no link or device in it, and
626
- // a package.json for exactly its name and version, whose os, cpu, libc,
627
- // bins and bundled dependencies are what the lockfile recorded and whose
628
- // every dependency the snapshot has, those package extensions add among
629
- // them, but one its package.json also has as an optional peer where pnpm
630
- // may leave that out: before 11.28.0 with autoInstallPeers, and in some
631
- // graphs until 11.28.6 and 12.14.0; and, for any pnpm, each directory snapshot
632
- // held so by every path, as no lockfile pnpm writes fails. On macOS, two names
633
- // in one directory that differ only in case or normalization are refused, as
634
- // they would be one name there.
635
- //
636
- // Packages come from https://registry.npmjs.org/ alone, fetched through
637
- // @preventive/upstream, and each tarball is held to the lockfile's
638
- // integrity; each patch to the lockfile's hash of it, and applied only
639
- // where every hunk matches exactly where it says.
640
- //
641
- // Nothing is left to a guess: a lockfile the lockfile reader refuses, or
642
- // one of the env document pnpm 11 writes alone before anything is
643
- // installed, a setting this does not know or does not build for, overrides
644
- // pnpm cannot read, a lockfile not resolved with these settings, a package
645
- // from anywhere but the registry, a pnpmfile, some package extensions, an
646
- // injected dependency, a lockfile not up to date with a package.json,
647
- // another package manager, a runtime to download, two projects of one
648
- // name, a patch that does not hash or apply, a check above that fails,
649
- // text that is not well-formed where it is hashed, a patch that would
650
- // change a bin's file between two times pnpm links it, a file whose mode
651
- // would turn on the order a directory is read in -- each is refused with a
652
- // DeptreeError that says where: where the lockfile reader or the YAML
653
- // parser refused pnpm-lock.yaml or pnpm-workspace.yaml, it names the file,
654
- // and its cause is their LockfileError or YamlError. A TypeError is thrown
655
- // for options of the wrong type.
656
- export function buildPnpmTree(options: PnpmLayoutOptions): Promise<PnpmLayout>
657
- export function buildPnpmTree(options: PnpmLazyOptions): Promise<PnpmLazyTree>
658
- export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
239
+ /**
240
+ * Build the node_modules tree a frozen, script-less install of `host.pnpm` makes
241
+ *
242
+ * Rooted at the lockfile's directory, with relative links, a `link:` leading where the lockfile says,
243
+ * outside the tree. No .bin is written, nor pnpm's state, but each file a bin pnpm links runs is left as
244
+ * linking leaves it: executable, and with a CRLF `#!` line made LF but by pnpm 12. Every file is its own,
245
+ * as where pnpm clones or copies from its store. pnpm 11's and 12's ways of linking bins and hoisting
246
+ * are built as each makes them; the hoisted linker as @yarnpkg/nm hoists, where packageImportMethod is
247
+ * copy, clone or clone-or-copy, refused past 50,000,000 weighted steps or 100,000 packages.
248
+ *
249
+ * The lockfile is held to what a frozen install holds it to: the settings it was resolved with
250
+ * (catalogs, overrides, package extensions, patches, autoInstallPeers, dedupePeers,
251
+ * peersSuffixMaxLength, optional dependencies left out), and each project's package.json read through
252
+ * pnpm's read-package hook; with pnpm 11 and 12 to their further checks. It is held to more where every
253
+ * lockfile pnpm writes and package the registry serves holds: each tarball gzipped, under one
254
+ * directory, with no link or device, and with a package.json for exactly its name and version, whose
255
+ * platforms, bins, bundled and other dependencies are what the lockfile records. On macOS, two names of
256
+ * one directory that differ only in case or normalization are refused.
257
+ *
258
+ * Refused, among the rest: a setting not built for, a pnpmfile, an injected dependency, a package from
259
+ * anywhere but the registry, a `file:` tarball, another package manager or a runtime to download, a
260
+ * lockfile not up to date, two projects of one name, a patch that does not hash or apply or would change
261
+ * a bin between two links, and a file whose mode would turn on the order a directory is read in.
262
+ *
263
+ * @param options - The files, the host, and how to build
264
+ * @returns The tree, its counts, and the snapshots installed
265
+ * @throws DeptreeError, naming where; TypeError for options of the wrong type
266
+ */
267
+ export function buildPnpmTree(options: PnpmLayoutOptions): Promise<PnpmLayout>;
268
+ export function buildPnpmTree(options: PnpmLazyOptions): Promise<PnpmLazyTree>;
269
+ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>;
659
270
 
660
- // The directories of the projects pnpm finds in `project`, by which
661
- // buildPnpmTree takes their package.json given: `.`, the root, first, then
662
- // in order each directory whose package.json a glob of
663
- // pnpm-workspace.yaml's `packages` takes, as pnpm `host.pnpm` finds them.
664
- // pnpm-workspace.yaml is read from `project`, as buildPnpmTree reads it;
665
- // so is the root package.json, where host.pnpm is left out, for the pnpm
666
- // its packageManager pins, or, for pnpm 12, where there is no
667
- // pnpm-workspace.yaml, for its `workspaces`.
668
- //
669
- // Of `project`, besides those, only the directories pnpm walks into are
670
- // read: none under node_modules or bower_components, and none whose name
671
- // starts with a dot unless a glob spells it there. A manifest is a file,
672
- // or a link to one; a link that leads nowhere, or to a directory, is none,
673
- // as pnpm has it.
674
- //
675
- // pnpm 12 finds them otherwise in places: a `**` may take no directory
676
- // before one a glob spells with a leading dot; it walks into no
677
- // node_modules or bower_components, wherever they are; it fails where a
678
- // glob with a `*` takes a directory whose first manifest there is not a
679
- // file, which is refused; and the projects come in the order of their
680
- // paths by name, `a/b` before `a-b`.
681
- //
682
- // Refused: a root with no manifest, which pnpm takes for no project; a
683
- // project, the root among them, whose manifest is package.json5 or
684
- // package.yaml, which pnpm reads where there is no package.json, or is a
685
- // link; a project pnpm finds through a link to a directory, which it
686
- // follows, and a link to a directory in one followed, which is not; a
687
- // project in a directory a lockfile could not key its importer by, with a
688
- // control, bidirectional or backslash character in its path, or a drive
689
- // letter; a node_modules pnpm walks into, which it does only under a
690
- // directory with a leading dot, or one a glob spells; a glob
691
- // buildPnpmTree refuses, or a pnpm not 10.x, 11.x or 12.x; and a pnpm-workspace.yaml that is not YAML, is not a mapping,
692
- // is not UTF-8, or is under another name pnpm refuses.
693
271
  export interface PnpmProjectsOptions {
694
- project: PnpmProject
695
- host?: Pick<PnpmHost, 'pnpm'>
272
+ /** Read for pnpm-workspace.yaml, the root package.json and the directories pnpm walks into */
273
+ project: PnpmProject;
274
+ /** Default: the pnpm the root package.json's packageManager pins */
275
+ host?: Pick<PnpmHost, 'pnpm'>;
696
276
  }
697
277
 
698
- export function findPnpmProjects(options: PnpmProjectsOptions): string[]
278
+ /**
279
+ * The directories of the projects pnpm finds, by which buildPnpmTree takes their package.json given
280
+ *
281
+ * pnpm-workspace.yaml's `packages` globs are followed as that pnpm follows them: `*`, `**` as a whole
282
+ * name, and a leading `!`, never into a node_modules or bower_components or a dotted name no glob spells.
283
+ * Refused: a root with no manifest, a manifest that is a link or not package.json, a project found
284
+ * through a link, a path a lockfile could not key an importer by, and a pnpm-workspace.yaml pnpm refuses.
285
+ *
286
+ * @param options - The project, and the pnpm whose finding is followed
287
+ * @returns `.` first, then each project, in the order that pnpm finds them
288
+ */
289
+ export function findPnpmProjects(options: PnpmProjectsOptions): string[];
699
290
 
700
- // `where` is what a refusal is about -- `pnpm-workspace.yaml: nodeLinker`,
701
- // `.npmrc:3: node-linker`, `pnpm-lock.yaml`, a package's key -- or
702
- // undefined for the call as a whole; the message leads with it. `cause` is
703
- // what a package beneath refused with, where one did: the lockfile
704
- // reader's LockfileError, its YamlError, a fetch's failure.
291
+ /** What anything here is refused with */
705
292
  export class DeptreeError extends Error {
706
- constructor(detail: string, where?: string, options?: { cause?: unknown })
707
- where: string | undefined
293
+ constructor(detail: string, where?: string, options?: { cause?: unknown });
294
+ /**
295
+ * What the refusal is about, which the message leads with: `pnpm-workspace.yaml: nodeLinker`,
296
+ * `.npmrc:3: node-linker`, a package's key; undefined for the call as a whole
297
+ */
298
+ where: string | undefined;
708
299
  }