@preventive/deptree 1.0.0-alpha.1 → 1.0.0-alpha.11
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.
- package/LICENSE-APACHE +202 -0
- package/bin/compare.js +132 -0
- package/bin/deptree.js +211 -0
- package/bin/npmrc.js +21 -0
- package/cargo.d.ts +223 -0
- package/cargo.js +6 -0
- package/npm.d.ts +325 -0
- package/npm.js +7 -0
- package/package.json +92 -11
- package/pnpm.d.ts +401 -81
- package/pnpm.js +4 -9
- package/soldeer.d.ts +235 -0
- package/soldeer.js +6 -0
- package/src/cargo/crate.js +183 -0
- package/src/cargo/inputs.js +81 -0
- package/src/cargo/members.js +90 -0
- package/src/cargo/registry.js +65 -0
- package/src/cargo/tree.js +125 -0
- package/src/cargo/workspace.js +177 -0
- package/src/concurrent.js +32 -0
- package/src/error.js +8 -10
- package/src/glob.js +55 -0
- package/src/hash.js +51 -16
- package/src/manifest.js +52 -0
- package/src/matcher.js +60 -10
- package/src/mount.js +124 -42
- package/src/npm/bins.js +54 -0
- package/src/npm/compat.js +97 -0
- package/src/npm/dev-engines.js +52 -0
- package/src/npm/graph.js +68 -0
- package/src/npm/inputs.js +75 -0
- package/src/npm/manifests.js +130 -0
- package/src/npm/package.js +96 -0
- package/src/npm/ratio.js +34 -0
- package/src/npm/settings.js +67 -0
- package/src/npm/tree.js +139 -0
- package/src/npm/versions.js +20 -0
- package/src/npmrc.js +24 -0
- package/src/patch.js +26 -45
- package/src/pnpm/bins.js +202 -322
- package/src/pnpm/checks.js +8 -35
- package/src/pnpm/commands.js +230 -0
- package/src/pnpm/filename.js +19 -16
- package/src/pnpm/frozen.js +29 -73
- package/src/pnpm/gitignore.js +138 -0
- package/src/pnpm/glob.js +65 -0
- package/src/pnpm/graph.js +26 -34
- package/src/pnpm/hoist.js +96 -59
- package/src/pnpm/hoisted.js +234 -0
- package/src/pnpm/hook.js +26 -31
- package/src/pnpm/inputs.js +177 -0
- package/src/pnpm/install.js +123 -124
- package/src/pnpm/local.js +95 -40
- package/src/pnpm/minimatch.js +319 -0
- package/src/pnpm/nm-hoist-graph.js +299 -0
- package/src/pnpm/nm-hoist.js +149 -0
- package/src/pnpm/npm-packlist.js +217 -0
- package/src/pnpm/overrides.js +11 -51
- package/src/pnpm/package.js +123 -0
- package/src/pnpm/packlist.js +176 -81
- package/src/pnpm/patches.js +18 -25
- package/src/pnpm/projects.js +132 -89
- package/src/pnpm/readers.js +122 -77
- package/src/pnpm/settings.js +74 -95
- package/src/pnpm/tree.js +216 -237
- package/src/pnpm/uptodate.js +16 -28
- package/src/pnpm/workspace.js +152 -126
- package/src/project.js +56 -0
- package/src/soldeer/config.js +63 -0
- package/src/soldeer/git.js +52 -0
- package/src/soldeer/inputs.js +30 -0
- package/src/soldeer/tree.js +83 -0
- package/src/soldeer/zip.js +121 -0
- package/src/tarball.js +123 -131
- package/src/yarn1/bins.js +28 -0
- package/src/yarn1/compat.js +67 -0
- package/src/yarn1/hoist.js +249 -0
- package/src/yarn1/inputs.js +83 -0
- package/src/yarn1/manifest.js +64 -0
- package/src/yarn1/package.js +206 -0
- package/src/yarn1/peers.js +51 -0
- package/src/yarn1/requests.js +74 -0
- package/src/yarn1/resolve.js +289 -0
- package/src/yarn1/settings.js +95 -0
- package/src/yarn1/tree.js +219 -0
- package/yarn1.d.ts +368 -0
- package/yarn1.js +7 -0
- package/src/pnpm/npmrc.js +0 -31
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/pnpm.d.ts
CHANGED
|
@@ -1,50 +1,97 @@
|
|
|
1
1
|
// Hand-written against pnpm.js; a change to either belongs with the other.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js'
|
|
4
|
+
import type { NodeType, Vfs } from '@preventive/vfs'
|
|
4
5
|
|
|
6
|
+
// What the lockfile reader and the YAML parser refuse with: the cause of
|
|
7
|
+
// the DeptreeError that names the file they refused, pnpm-lock.yaml or
|
|
8
|
+
// pnpm-workspace.yaml.
|
|
5
9
|
export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
|
|
6
10
|
|
|
7
11
|
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
12
|
+
// Tarballs are fetched through it, and that is the one place anything here
|
|
13
|
+
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
14
|
+
// cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
|
|
15
|
+
// from its own default cache directory or stasis's, where one there has the
|
|
16
|
+
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
17
|
+
// where one is set, which is where it writes each tarball it fetches:
|
|
18
|
+
// setCacheDir() sets the default one, and setCacheDir(false) unsets it.
|
|
19
|
+
// Unset, which it is until set, it writes nothing: a tarball in none of
|
|
20
|
+
// the others is fetched every time, each once for however many snapshots
|
|
21
|
+
// it has. The project is read only through the view given as `project`,
|
|
22
|
+
// and the tree built in a Vfs.
|
|
11
23
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
12
24
|
|
|
13
25
|
// The machine pnpm would install on, which a tree depends on: `pnpm` is
|
|
14
|
-
// the version that installs, and has to be a
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// package.json's
|
|
18
|
-
//
|
|
19
|
-
//
|
|
26
|
+
// the version that installs, and has to be a 9.x from 9.15.0 on, a 10.x,
|
|
27
|
+
// an 11.x or a 12.x from 12.8.1 on, the four built for, each as it differs
|
|
28
|
+
// from the others; an earlier 9.x or 12.x installs otherwise in places, and
|
|
29
|
+
// is refused. Left out, it is the one the root package.json's
|
|
30
|
+
// packageManager pins, which pnpm switches to, and has to be given where
|
|
31
|
+
// that pins none. `node` is the Node it runs on,
|
|
32
|
+
// unless the settings name a nodeVersion or, for pnpm 11, the root
|
|
33
|
+
// package.json's engines.runtime pins one; `os`, `cpu` and `libc` as Node
|
|
34
|
+
// and pnpm name them — `linux`, `x64`, `glibc` — with `unknown` for a libc
|
|
35
|
+
// outside Linux, as pnpm has it.
|
|
20
36
|
// Windows is refused: pnpm links there with junctions to absolute paths.
|
|
21
37
|
// An optional package the machine cannot run is left out, as pnpm leaves
|
|
22
38
|
// it out; supportedArchitectures in the settings widens what is taken.
|
|
23
39
|
export interface PnpmHost {
|
|
24
|
-
pnpm
|
|
40
|
+
pnpm?: string
|
|
25
41
|
node: string
|
|
26
42
|
os: string
|
|
27
43
|
cpu: string
|
|
28
44
|
libc: 'glibc' | 'musl' | 'unknown'
|
|
29
45
|
}
|
|
30
46
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
47
|
+
// A view of the lockfile's directory, by paths from `/`: a Vfs, or
|
|
48
|
+
// anything with its readdir, lstat, stat and readFile, such as one of a
|
|
49
|
+
// directory on disk, of which only this is read: the names in a
|
|
50
|
+
// directory; what a path is, `file`, `directory` or `symlink`, and its
|
|
51
|
+
// mode, with lstat, and what it leads to with stat; and a file's bytes.
|
|
52
|
+
// Each throws an error whose `code` is ENOENT, ENOTDIR or ELOOP for a path
|
|
53
|
+
// that leads nowhere. Nothing is written to it.
|
|
54
|
+
export interface PnpmProject {
|
|
55
|
+
readdir(path: string): string[]
|
|
56
|
+
lstat(path: string): { type: NodeType, mode: number }
|
|
57
|
+
stat(path: string): { type: NodeType }
|
|
58
|
+
readFile(path: string): Uint8Array
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The files an install reads: pnpm-lock.yaml; the package.json of every
|
|
62
|
+
// project it installs; pnpm-workspace.yaml and the .npmrc, where there are
|
|
63
|
+
// any; and every patch file the settings' patchedDependencies name.
|
|
64
|
+
//
|
|
65
|
+
// With `lockfile`, they are given as text: `manifests` by the project's
|
|
66
|
+
// directory relative to the lockfile's (`.` for the root, then as its
|
|
67
|
+
// importers are keyed), `patches` by the path from the lockfile's
|
|
68
|
+
// directory the settings name each by, and only those.
|
|
69
|
+
//
|
|
70
|
+
// Without it, they are read from `project`, as pnpm reads them there, and
|
|
71
|
+
// none of them may be given: pnpm-lock.yaml, which has to be there;
|
|
72
|
+
// pnpm-workspace.yaml, which, where there is none, pnpm refuses under
|
|
73
|
+
// another name it looks for it by, such as pnpm-workspace.yml; the .npmrc;
|
|
74
|
+
// the package.json of every project pnpm finds, as findPnpmProjects finds
|
|
75
|
+
// them, and no other, an importer pnpm-workspace.yaml's packages do not
|
|
76
|
+
// take refused unread; and each patch the settings name, and no other,
|
|
77
|
+
// which has to be under the lockfile's directory. Each is read as
|
|
78
|
+
// UTF-8, and refused where it is not, a byte order mark kept as it is in
|
|
79
|
+
// text given; a refusal names each as it would given:
|
|
80
|
+
// `manifests["packages/x"]`, `patches["patches/p.patch"]`.
|
|
81
|
+
//
|
|
82
|
+
// Settings from anywhere else — another .npmrc, the environment, the
|
|
83
|
+
// command line — are not read, and are taken to be at their defaults; so
|
|
84
|
+
// is pnpm taken to run as itself, not under corepack, and free to switch
|
|
85
|
+
// to the version a project pins.
|
|
39
86
|
//
|
|
40
87
|
// A workspace is one lockfile for several projects, each a package.json:
|
|
41
88
|
// the root, and every directory pnpm-workspace.yaml's `packages` globs
|
|
42
89
|
// take, as pnpm globs for them — `*` and `**`, a leading `!` to leave out,
|
|
43
90
|
// and no other glob syntax. Without `packages` the root is the only
|
|
44
|
-
// project. Every importer has to have its package.json
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
// directories: findPnpmProjects finds them in those. A project the
|
|
91
|
+
// project. Every importer has to have its package.json, and be a project
|
|
92
|
+
// those globs take; and every project pnpm would find has to be given,
|
|
93
|
+
// which buildPnpmTree cannot check where it is given them, as it is not
|
|
94
|
+
// given the directories: findPnpmProjects finds them in those. A project the
|
|
48
95
|
// lockfile has no importer for is held to an empty one, as pnpm holds it:
|
|
49
96
|
// with no dependencies it is installed, and hoisted by its name, and with
|
|
50
97
|
// any it is refused as not up to date. Its directory has to be given as
|
|
@@ -65,25 +112,59 @@ export interface PnpmHost {
|
|
|
65
112
|
// one is the root package.json's own specifier for `name`, and
|
|
66
113
|
// `catalog:` what the workspace's catalog gives the package. One to a
|
|
67
114
|
// directory — a path alone, such as `./vendor/foo`, `link:` or `file:` —
|
|
68
|
-
// is read only with `
|
|
69
|
-
// the lockfile's and holds a package.json there. pnpm links to it by a
|
|
115
|
+
// is read only with `project` given, and only where the directory is
|
|
116
|
+
// under the lockfile's and holds a package.json there. pnpm links to it by a
|
|
70
117
|
// path alone or `link:`. By `file:` it installs it as a package, of the
|
|
71
|
-
// files npm-packlist
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
118
|
+
// files its packlist picks — npm-packlist 5.1.3 for pnpm 9 and 10, 10.0.4
|
|
119
|
+
// for pnpm 11, and pnpm 12's own port of it — which each is followed here
|
|
120
|
+
// as that version runs: by package.json's `files`, `main`, `bin` and, but
|
|
121
|
+
// for pnpm 12, `browser`; by the .npmignore and .gitignore files where it
|
|
122
|
+
// reads them; and by its own rules, case and all, odd steps among them,
|
|
123
|
+
// such as pnpm 9 and 10 keeping what a `files` glob takes that their rules
|
|
124
|
+
// leave out, or the minimatch pnpm 10 bundles from 10.31 matching `**`
|
|
125
|
+
// otherwise. Of glob syntax only `*`, `?` and `**` are followed, which all
|
|
126
|
+
// read alike: a pattern with braces, a class, an extglob or a backslash is
|
|
127
|
+
// refused, and so are a link the walk comes on, bundled dependencies,
|
|
128
|
+
// `files` that is not a list of strings, a file kept by a path a pattern
|
|
129
|
+
// spells with a `.` part, and a package.json with a byte order mark for
|
|
130
|
+
// pnpm 11 before 11.28, which fails on it. Refused too, where a pnpm may
|
|
131
|
+
// make too large a regexp of it, failing for pnpm 9, 10 and 11 and dropping
|
|
132
|
+
// it unread for 12, is a pattern of more than 4096 characters and, for pnpm
|
|
133
|
+
// 12, an ignore file or `files` of more than 16 KiB; and so are a pattern
|
|
134
|
+
// with more than 100 `**` parts for pnpm 9 and 10, and a directory nested
|
|
135
|
+
// more than 100 deep, for the time matching them takes. Matching takes
|
|
136
|
+
// time linear in the path and the pattern. pnpm hardlinks those files from
|
|
137
|
+
// the directory into each snapshot of the package, in their modes, which
|
|
138
|
+
// are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
|
|
139
|
+
// 0o755 and 0o775. So a file linking a bin makes executable — 0o755 for
|
|
140
|
+
// pnpm 9 and 10, its mode with 0o111 added for 11 and 12 — is made so in
|
|
141
|
+
// every snapshot and in the directory, which is not written here; a CRLF
|
|
142
|
+
// `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package — an install script, a
|
|
143
|
+
// binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
|
|
144
|
+
// .hooks directory — or, with pnpm 11 and 12, where packageImportMethod is
|
|
145
|
+
// other than auto or hardlink, each snapshot has a copy of its own
|
|
146
|
+
// instead. One by `file:` to a tarball is refused, and so is a `file:`
|
|
147
|
+
// dependency no override names. One to the lockfile's own directory that
|
|
148
|
+
// the lockfile has as `file:` and an empty path, as pnpm 9, 10 and 11
|
|
149
|
+
// write it, is refused for pnpm 12, which fails on that lockfile.
|
|
150
|
+
//
|
|
151
|
+
// pnpm 9 reads its settings as pnpm 10 does, but none of
|
|
152
|
+
// pnpm-workspace.yaml: of that it reads the projects and the catalogs
|
|
153
|
+
// alone, and fails on one that sets anything else but no `packages`, which
|
|
154
|
+
// is refused; where one sets nothing, it finds projects everywhere, as `**`
|
|
155
|
+
// does. Of the package.json's `pnpm` field it reads fewer keys, and what
|
|
156
|
+
// pnpm 10 has that pnpm 9 has no setting for, such as dedupePeers or
|
|
157
|
+
// enableGlobalVirtualStore, it passes over. It hoists `*eslint*` and
|
|
158
|
+
// `*prettier*` publicly by default.
|
|
79
159
|
//
|
|
80
160
|
// Of the .npmrc, only what pnpm reads for an install is read: its settings
|
|
81
161
|
// by their kebab-case names, those that can change the tree held to what
|
|
82
162
|
// is built here, and all else — npm's own settings, publishing's,
|
|
83
163
|
// credentials, other names — passed over. A `${VAR}` pnpm would fill in is
|
|
84
|
-
// taken in a line passed over
|
|
85
|
-
//
|
|
86
|
-
//
|
|
164
|
+
// taken in a line passed over where the rest of the file would not change
|
|
165
|
+
// the tree, as pnpm drops the whole file where the variable is unset; but
|
|
166
|
+
// `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`, the registry's token as
|
|
167
|
+
// a project commonly gives it, is taken to be set, and the rest read.
|
|
87
168
|
//
|
|
88
169
|
// pnpm 11 reads its settings from pnpm-workspace.yaml alone, as this does
|
|
89
170
|
// for it: of the .npmrc only its registries, and of the package.json no
|
|
@@ -96,33 +177,97 @@ export interface PnpmHost {
|
|
|
96
177
|
// lockfile against the registry by before it installs — each package's
|
|
97
178
|
// publish time, its tarball URL, its trust — are passed over.
|
|
98
179
|
//
|
|
180
|
+
// pnpm 12 reads them so too. Where the root package.json pins a pnpm that
|
|
181
|
+
// host.pnpm is, it fails on a key of pnpm-workspace.yaml it does not know,
|
|
182
|
+
// one of pnpm 11's such as alwaysAuth among them, which is refused; it
|
|
183
|
+
// drops one otherwise, and passes over one not in camelCase it knows. It
|
|
184
|
+
// takes hoistPattern and publicHoistPattern only as lists, and passes over
|
|
185
|
+
// what it has that pnpm 11 has not but `cargo` or `python` enabled, which
|
|
186
|
+
// is refused. It parses every key of pnpm-workspace.yaml into a type of
|
|
187
|
+
// its own, and fails on a value that does not parse, or a `tasks` entry it
|
|
188
|
+
// holds to be wrong: that is not checked here of a key that leaves the
|
|
189
|
+
// tree as it is. Where there is no pnpm-workspace.yaml, it writes one of
|
|
190
|
+
// the root package.json's `workspaces` list, its strings but empty ones,
|
|
191
|
+
// and installs by it, as this does for it.
|
|
192
|
+
//
|
|
193
|
+
// `project` is read only where it is said to be here: for the files an
|
|
194
|
+
// install reads, without `lockfile`; for the directories a `link:` or an
|
|
195
|
+
// override leads to. With it given, a directory the tree links to that is
|
|
196
|
+
// no project, and is under the lockfile's, has to be there with a
|
|
197
|
+
// package.json, whose bins are read as pnpm reads them; pnpm links to one
|
|
198
|
+
// that is not there all the same, warning only as pnpm 10 and 11 resolve,
|
|
199
|
+
// never as a frozen install. So it does for `npm:@scope/name@workspace:^`,
|
|
200
|
+
// as an override or a dependency, which it takes for a path for its `/`,
|
|
201
|
+
// and that link is refused with or without `project`, but where it holds
|
|
202
|
+
// a directory of that very name:
|
|
203
|
+
// `workspace:@scope/name@^` is the spec that links the workspace package
|
|
204
|
+
// by another name. Without it, or
|
|
205
|
+
// outside the lockfile's directory, such a directory's bins are not
|
|
206
|
+
// known, and neither are those of a project that has them by the files of
|
|
207
|
+
// its directories.bin: where one could win a command a package's file is
|
|
208
|
+
// linked by, and so decide whether pnpm fixes that file, and fixing it
|
|
209
|
+
// would change it, the tree is refused.
|
|
210
|
+
//
|
|
99
211
|
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to
|
|
100
212
|
// be the lockfile's directory, beside whatever it holds, such as the
|
|
101
|
-
// projects themselves; without one, a new Vfs
|
|
102
|
-
//
|
|
213
|
+
// projects themselves — it may be `project` too; without one, a new Vfs
|
|
214
|
+
// holds the tree alone. Nothing the tree is built from is read from it. A
|
|
215
|
+
// Vfs that holds a node_modules anywhere, or on macOS a name that is one
|
|
103
216
|
// there, is refused before anything is fetched: kept beside the tree, Node
|
|
104
217
|
// would read it as the tree's, and removed, it would be the caller's lost.
|
|
105
218
|
// Nothing there is written over: each directory the tree has is one there
|
|
106
219
|
// or is made, and every file and link is written where nothing is. The
|
|
107
220
|
// tree is built, and held to every check below, before any of it is
|
|
108
|
-
// written, so a refusal leaves the Vfs as it was.
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
|
|
221
|
+
// written, so a refusal leaves the Vfs as it was. Nothing outside
|
|
222
|
+
// node_modules is written, though pnpm 9 and 10 make the files a linked
|
|
223
|
+
// directory's bins run executable too.
|
|
224
|
+
//
|
|
225
|
+
// `metadata`, true unless given false, has each registry package's version
|
|
226
|
+
// document asked for beside its tarball, through getMeta of
|
|
227
|
+
// @preventive/upstream given the lockfile's dist: the one `cache` keeps,
|
|
228
|
+
// where its dist is that one, else the registry's, a request for each name
|
|
229
|
+
// and version. Its dist has to be the lockfile's, the tarball
|
|
230
|
+
// the registry's own URL and the integrity the lockfile's sha512, compared
|
|
231
|
+
// as text, with nothing hashed again, as the lockfile copies the
|
|
232
|
+
// registry's; and its gitHead, repository, homepage and bugs are the
|
|
233
|
+
// package's. False fetches none, and gives none of them.
|
|
234
|
+
//
|
|
235
|
+
// `cache` is where each registry package's tarball and version document
|
|
236
|
+
// are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
|
|
237
|
+
// cache where it is left out; in a store of the caller's, with `read` and
|
|
238
|
+
// `write`, in place of it; or with false, nowhere, though setCacheDir's
|
|
239
|
+
// cache is read all the same. Other tools' caches are read for tarballs
|
|
240
|
+
// whatever it is. A TypeError is thrown for anything else.
|
|
241
|
+
//
|
|
242
|
+
// The two ways the files come, one or the other: given, with `lockfile`
|
|
243
|
+
// and `manifests`, `project` read only for directories; or read, with
|
|
244
|
+
// `project` and none of them.
|
|
245
|
+
export type PnpmTreeOptions = PnpmTreeGiven | PnpmTreeRead
|
|
246
|
+
|
|
247
|
+
export interface PnpmTreeGiven {
|
|
119
248
|
lockfile: string
|
|
120
249
|
manifests: Record<string, string> | Map<string, string>
|
|
121
250
|
workspace?: string
|
|
122
251
|
npmrc?: string
|
|
123
252
|
patches?: Record<string, string> | Map<string, string>
|
|
253
|
+
project?: PnpmProject
|
|
254
|
+
host: PnpmHost
|
|
255
|
+
vfs?: Vfs
|
|
256
|
+
metadata?: boolean
|
|
257
|
+
cache?: CacheOptions['cache']
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface PnpmTreeRead {
|
|
261
|
+
lockfile?: undefined
|
|
262
|
+
manifests?: undefined
|
|
263
|
+
workspace?: undefined
|
|
264
|
+
npmrc?: undefined
|
|
265
|
+
patches?: undefined
|
|
266
|
+
project: PnpmProject
|
|
124
267
|
host: PnpmHost
|
|
125
268
|
vfs?: Vfs
|
|
269
|
+
metadata?: boolean
|
|
270
|
+
cache?: CacheOptions['cache']
|
|
126
271
|
}
|
|
127
272
|
|
|
128
273
|
// What buildPnpmTree counts, all of it plain numbers: `projects` the
|
|
@@ -145,15 +290,56 @@ export interface PnpmTreeStats {
|
|
|
145
290
|
links: number
|
|
146
291
|
}
|
|
147
292
|
|
|
293
|
+
// A snapshot in the tree, as an SBOM would list it: `path` is where its
|
|
294
|
+
// files are, from the lockfile's directory, which is `/` of the Vfs —
|
|
295
|
+
// node_modules/.pnpm/<dir>/node_modules/<name>; `key` the lockfile's
|
|
296
|
+
// snapshot key, its peers and patch hash in it. `name` and `version` are
|
|
297
|
+
// the package's own, which its package.json is held to, and `integrity`
|
|
298
|
+
// the sha512 its tarball is held to; one a `file:` override has pnpm
|
|
299
|
+
// install from a directory has `directory`, from the lockfile's, `.` for
|
|
300
|
+
// its own, and neither a version nor an integrity, as the lockfile records
|
|
301
|
+
// none. `commit` is the gitHead of a registry package's version document,
|
|
302
|
+
// where `metadata` has it fetched and it is a full commit id, the commit
|
|
303
|
+
// npm read off the checkout it published from; `repository`, `homepage`
|
|
304
|
+
// and `bugs` the document's, as getMeta of @preventive/upstream reads
|
|
305
|
+
// them; each undefined elsewhere, and all of it the publisher's word, held
|
|
306
|
+
// to no repository.
|
|
307
|
+
// `dev` is whether devDependencies alone reach it: no project's
|
|
308
|
+
// dependencies or optionalDependencies do, through what is installed, so
|
|
309
|
+
// `pnpm install --prod` would leave it out. `optional` is whether optional
|
|
310
|
+
// dependencies alone reach it, as the lockfile records it. `patch` is the
|
|
311
|
+
// patch applied to it, by pnpm's hash of it and the path the settings name
|
|
312
|
+
// it by: of two patches of one text, the first they name.
|
|
313
|
+
export interface PnpmInstalled {
|
|
314
|
+
path: string
|
|
315
|
+
key: string
|
|
316
|
+
name: string
|
|
317
|
+
version: string | undefined
|
|
318
|
+
integrity: string | undefined
|
|
319
|
+
directory: string | undefined
|
|
320
|
+
commit: string | undefined
|
|
321
|
+
repository: string | PackageRepository | undefined
|
|
322
|
+
homepage: string | undefined
|
|
323
|
+
bugs: string | PackageBugs | undefined
|
|
324
|
+
dev: boolean
|
|
325
|
+
optional: boolean
|
|
326
|
+
patch: { hash: string, path: string } | undefined
|
|
327
|
+
}
|
|
328
|
+
|
|
148
329
|
// `vfs` is the one given, the tree mounted into it, or a new one.
|
|
330
|
+
// `installed` is each snapshot in the tree, one for each `stats.installed`
|
|
331
|
+
// counts, in the lockfile's order; with the hoisted linker, each copy, at
|
|
332
|
+
// node_modules/<alias> under where it landed, in the order pnpm makes them,
|
|
333
|
+
// each with the snapshot copied there.
|
|
149
334
|
export interface PnpmTree {
|
|
150
335
|
vfs: Vfs
|
|
151
336
|
stats: PnpmTreeStats
|
|
337
|
+
installed: PnpmInstalled[]
|
|
152
338
|
}
|
|
153
339
|
|
|
154
340
|
// The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`
|
|
155
|
-
// makes with the isolated linker of host.pnpm, 10 or
|
|
156
|
-
// install: whatever the
|
|
341
|
+
// makes with the isolated linker of host.pnpm, 9, 10, 11 or 12, or the
|
|
342
|
+
// hoisted one of pnpm 10 or 11, and no other install: whatever the
|
|
157
343
|
// settings say of frozen lockfiles, the install is frozen, which is also
|
|
158
344
|
// the only one that hoists by the lockfile's graph alone. It is rooted at
|
|
159
345
|
// the lockfile's directory: each package's
|
|
@@ -171,10 +357,78 @@ export interface PnpmTree {
|
|
|
171
357
|
// installs too, which is not followed here. Every file is written once,
|
|
172
358
|
// and a write that would replace anything with something else is refused;
|
|
173
359
|
// into a Vfs given, one that would replace anything at all.
|
|
360
|
+
//
|
|
361
|
+
// pnpm 9 makes its tree as pnpm 10 does but in places, each built as
|
|
362
|
+
// pnpm 9 makes it. It ends the name of a directory under
|
|
363
|
+
// node_modules/.pnpm it cuts short with 26 base32 characters of an MD5,
|
|
364
|
+
// not 32 hex of a SHA-256, and leaves a `#` in it. It hoists from the
|
|
365
|
+
// lockfile, not the graph: the snapshots of one depth in the order of
|
|
366
|
+
// their keys, not their directories', and an alias taken by a child left
|
|
367
|
+
// out, a `link:` or a project as well as by a snapshot hoisted, the root's
|
|
368
|
+
// all taken from the start as its specifiers spell them. It takes a bin's
|
|
369
|
+
// command by its name before it drops the scope, so links `@x/y z` as
|
|
370
|
+
// `y z`, and links a `bin` string, or a directories.bin, where it leads
|
|
371
|
+
// out of the package, which is refused; it fails on a bin that is a
|
|
372
|
+
// directory, which is refused, where pnpm 10 passes over it.
|
|
373
|
+
//
|
|
174
374
|
// pnpm 11 links bins otherwise in places — npm owns `npx` and pnpm its
|
|
175
375
|
// aliases, a project's .bin takes the bins of the peers its dependencies
|
|
176
376
|
// require — and each is built as the one given links them.
|
|
177
377
|
//
|
|
378
|
+
// pnpm 12, a rewrite of pnpm, makes its tree otherwise again, and it is
|
|
379
|
+
// built as pnpm 12 makes it. It links each package's own bins into its own
|
|
380
|
+
// node_modules/.bin, beside its dependencies', and of two of one name
|
|
381
|
+
// keeps the one of the package whose name sorts first by its bytes; makes
|
|
382
|
+
// a file a bin runs executable without rewriting a CRLF `#!` line, and
|
|
383
|
+
// fails on a bin that is a directory, which is refused; reads `bin` and
|
|
384
|
+
// directories.bin otherwise, dotfiles among them, and a package's null
|
|
385
|
+
// `bin` beside a directories.bin as its store has the package or not,
|
|
386
|
+
// which is refused. It links no package to
|
|
387
|
+
// a dependency of its own name, and writes a file a patch makes as
|
|
388
|
+
// 0o644, whatever mode the patch gives it. It hoists from a graph of every
|
|
389
|
+
// snapshot, those left out walked through but not hoisted, keeps from
|
|
390
|
+
// hoisting the root project's aliases but its `link:`s, those left out
|
|
391
|
+
// among them, and takes the snapshots of one depth in the order of their
|
|
392
|
+
// directories' names. It names a directory under node_modules/.pnpm by the
|
|
393
|
+
// UTF-8 bytes of its key, which only a key that is not ASCII tells. It
|
|
394
|
+
// shares pnpm 11's store, and takes what pnpm 11 left there, such as a
|
|
395
|
+
// patched package as pnpm 11 built it, which is not followed here: the
|
|
396
|
+
// tree is the one a store of pnpm 12's own gives.
|
|
397
|
+
//
|
|
398
|
+
// With nodeLinker: hoisted, for pnpm 10 and 11, the tree is the one the
|
|
399
|
+
// hoisted linker makes: each package copied to node_modules/<alias> as near
|
|
400
|
+
// the root as @yarnpkg/nm's hoist takes it, under what needs it where the
|
|
401
|
+
// name there is another's, and each project's dependencies the root has
|
|
402
|
+
// another of in its own node_modules; a project's `link:` dependencies
|
|
403
|
+
// linked there, and a package's refused, which pnpm links nowhere; and no
|
|
404
|
+
// node_modules/.pnpm, where pnpm keeps only its state. pnpm takes every
|
|
405
|
+
// snapshot of one name and version for the first it comes to, and every
|
|
406
|
+
// directory of one name for one, as is followed here; from pnpm 11.24, each
|
|
407
|
+
// snapshot of a directory for its own. From pnpm 11.28 it also links each
|
|
408
|
+
// named project into the root's node_modules by its name, as
|
|
409
|
+
// hoistWorkspacePackages has it, where a hoist pattern matches it and the
|
|
410
|
+
// root depends on nothing of that name and no package landed there by it,
|
|
411
|
+
// their case folded; and from 11.28.1 does not hoist a project's `link:`
|
|
412
|
+
// into itself (`link:<root>/`). Every copy has to be its own, so
|
|
413
|
+
// packageImportMethod has to be copy, clone or clone-or-copy: any other
|
|
414
|
+
// hardlinks from pnpm's store. Bins are fixed as pnpm links them: in each
|
|
415
|
+
// node_modules as it fills it, then in each project's again with its links
|
|
416
|
+
// in, a command of the project's own dependencies over another's. Where any
|
|
417
|
+
// patch is configured, pnpm builds each package patched or with an install
|
|
418
|
+
// script in one of its copies, which it finds through the dependencies of
|
|
419
|
+
// each, by snapshot or from pnpm 11.23 by package, linking its
|
|
420
|
+
// dependencies' bins and its own, and links that copy's files into the
|
|
421
|
+
// others: before pnpm 10.21 in place, which leaves the others unpatched;
|
|
422
|
+
// from 10.21 a copy of hardlinks put in place of each, with no
|
|
423
|
+
// node_modules, which drops the copy's own; and from 11.25 each file but
|
|
424
|
+
// those under a node_modules in place of the copy's own, keeping its
|
|
425
|
+
// node_modules and what the built copy has not, which leaves a file the
|
|
426
|
+
// patch deletes in the others. These are refused where they would change a
|
|
427
|
+
// copy, and so is a patched package no copy of which the build reaches,
|
|
428
|
+
// which pnpm leaves unpatched; which copy pnpm builds is not followed, and
|
|
429
|
+
// refused where it would change a bin. Hoisting is refused past 50,000,000
|
|
430
|
+
// steps, weighted by the work each does, or a tree of 100,000 packages.
|
|
431
|
+
//
|
|
178
432
|
// The lockfile is held to what a frozen install holds it to, and refused
|
|
179
433
|
// where pnpm would refuse it: the settings that shaped its resolution —
|
|
180
434
|
// catalogs, overrides, package extensions, optional dependencies left out,
|
|
@@ -197,6 +451,46 @@ export interface PnpmTree {
|
|
|
197
451
|
// for it; and a root engines.runtime whose onFail is `error` has to take
|
|
198
452
|
// host.node.
|
|
199
453
|
//
|
|
454
|
+
// pnpm 12 reads devEngines.packageManager over packageManager, as pnpm 11
|
|
455
|
+
// does but for the onFail of a list with no pnpm in it, which is its first
|
|
456
|
+
// entry's own. Unless what to do on a mismatch, or pmOnFail, is to ignore,
|
|
457
|
+
// host.pnpm has to be in the pnpm it pins, or the mismatch only to warn,
|
|
458
|
+
// and another package manager is refused unless it is only to warn; and a
|
|
459
|
+
// pin of devEngines, or of a pnpm 12 by packageManager, has to be recorded
|
|
460
|
+
// in the lockfile's env document, of `pnpm` alone at the version pinned,
|
|
461
|
+
// or at host.pnpm for a range, with its package: pnpm 12 runs that one,
|
|
462
|
+
// and fails a frozen install where it is not there.
|
|
463
|
+
//
|
|
464
|
+
// pnpm 9 holds a lockfile to less than pnpm 10: neither to the catalogs
|
|
465
|
+
// nor to dedupePeers, nor a dependency's version to its range. It hashes a
|
|
466
|
+
// patch with MD5, in base32, and picks one for a package by `name@version`
|
|
467
|
+
// as spelled, else by `name`, never by a range. It overrides a peer in
|
|
468
|
+
// place, whatever the override. Where the root package.json's
|
|
469
|
+
// packageManager pins another pnpm, pnpm 9 installs with itself, unless
|
|
470
|
+
// managePackageManagerVersions has it switch to that one, or
|
|
471
|
+
// packageManagerStrict and packageManagerStrictVersion have it fail, each
|
|
472
|
+
// refused; and it fails on another package manager with
|
|
473
|
+
// packageManagerStrict, as it is by default, which is refused. It knows no
|
|
474
|
+
// runtime, and holds a project's os, cpu and libc to the host's own,
|
|
475
|
+
// whatever supportedArchitectures says.
|
|
476
|
+
//
|
|
477
|
+
// pnpm 12 makes none of pnpm 11's further checks of a lockfile, but holds
|
|
478
|
+
// a directory a project depends on by `file:` to it: each dependency the
|
|
479
|
+
// snapshot has is one its package.json, overridden, asks for, a peer among
|
|
480
|
+
// them; each it asks for is resolved as it asks, an optional one there or
|
|
481
|
+
// not; and its peers, and which are optional, are what the lockfile
|
|
482
|
+
// records. A project the lockfile has no importer for is held to none
|
|
483
|
+
// where it has no dependencies but peers, and refused otherwise. It checks
|
|
484
|
+
// of the projects only the root's engines.node, with engineStrict, and
|
|
485
|
+
// with engineStrict refuses whatever it installs that the host cannot run,
|
|
486
|
+
// though the lockfile mark it optional. An os, cpu or libc list is read
|
|
487
|
+
// by its first entry that names the host's. A patched package's
|
|
488
|
+
// engines.node is held to nodeVersion, or the host's Node, whatever the
|
|
489
|
+
// root's engines.runtime pins. An engines.node npm's semver does not read,
|
|
490
|
+
// or a range of a `-` with an `x`, pnpm 12 reads otherwise, which is
|
|
491
|
+
// refused where it would decide what is installed. host.node is, for pnpm
|
|
492
|
+
// 12, the `node` it finds on the PATH.
|
|
493
|
+
//
|
|
200
494
|
// And to more than pnpm holds it to, where a lockfile pnpm writes, or a
|
|
201
495
|
// package the registry serves, always holds: each dependency linked where
|
|
202
496
|
// the package.json names a directory for it, a path alone among them; each
|
|
@@ -215,31 +509,55 @@ export interface PnpmTree {
|
|
|
215
509
|
// integrity; each patch to the lockfile's hash of it, and applied only
|
|
216
510
|
// where every hunk matches exactly where it says.
|
|
217
511
|
//
|
|
218
|
-
// Nothing is left to a guess: a lockfile the lockfile reader refuses,
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
// that
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
512
|
+
// Nothing is left to a guess: a lockfile the lockfile reader refuses, or
|
|
513
|
+
// one of the env document pnpm 11 writes alone before anything is
|
|
514
|
+
// installed, a setting this does not know or does not build for, overrides
|
|
515
|
+
// pnpm cannot read, a lockfile not resolved with these settings, a package
|
|
516
|
+
// from anywhere but the registry, a pnpmfile, package extensions, an
|
|
517
|
+
// injected dependency, a lockfile not up to date with a package.json,
|
|
518
|
+
// another package manager, a runtime to download, two projects of one
|
|
519
|
+
// name, a patch that does not hash or apply, a check above that fails,
|
|
520
|
+
// text that is not well-formed where it is hashed, a patch that would
|
|
521
|
+
// change a bin's file between two times pnpm links it, a file whose mode
|
|
522
|
+
// would turn on the order a directory is read in — each is refused with a
|
|
523
|
+
// DeptreeError that says where: where the lockfile reader or the YAML
|
|
524
|
+
// parser refused pnpm-lock.yaml or pnpm-workspace.yaml, it names the file,
|
|
525
|
+
// and its cause is their LockfileError or YamlError. A TypeError is thrown
|
|
526
|
+
// for options of the wrong type.
|
|
230
527
|
export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
|
|
231
528
|
|
|
232
|
-
// The directories of the projects pnpm finds
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
//
|
|
529
|
+
// The directories of the projects pnpm finds in `project`, by which
|
|
530
|
+
// buildPnpmTree takes their package.json given: `.`, the root, first, then
|
|
531
|
+
// in order each directory whose package.json a glob of
|
|
532
|
+
// pnpm-workspace.yaml's `packages` takes, as pnpm `host.pnpm` finds them.
|
|
533
|
+
// pnpm-workspace.yaml is read from `project`, as buildPnpmTree reads it;
|
|
534
|
+
// so is the root package.json, where host.pnpm is left out, for the pnpm
|
|
535
|
+
// its packageManager pins, or, for pnpm 12, where there is no
|
|
536
|
+
// pnpm-workspace.yaml, for its `workspaces`.
|
|
236
537
|
//
|
|
237
|
-
// `
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
538
|
+
// Of `project`, besides those, only the directories pnpm walks into are
|
|
539
|
+
// read: none under node_modules or bower_components, and none whose name
|
|
540
|
+
// starts with a dot unless a glob spells it there. A manifest is a file,
|
|
541
|
+
// or a link to one; a link that leads nowhere, or to a directory, is none,
|
|
542
|
+
// as pnpm has it.
|
|
543
|
+
//
|
|
544
|
+
// pnpm 12 finds them otherwise in places: a `**` may take no directory
|
|
545
|
+
// before one a glob spells with a leading dot; it walks into no
|
|
546
|
+
// node_modules or bower_components, wherever they are; it fails where a
|
|
547
|
+
// glob with a `*` takes a directory whose first manifest there is not a
|
|
548
|
+
// file, which is refused; and the projects come in the order of their
|
|
549
|
+
// paths by name, `a/b` before `a-b`.
|
|
550
|
+
//
|
|
551
|
+
// pnpm 9 finds them with fast-glob, otherwise again: past the names before
|
|
552
|
+
// a glob's first `**` it walks into every directory, one with a leading
|
|
553
|
+
// dot among them, though no `*` or `**` takes a project there; it walks
|
|
554
|
+
// from the top for every glob where one has a `*` in its first name; and
|
|
555
|
+
// it leaves out what a `!` glob takes, leading dots and all. It reads
|
|
556
|
+
// every manifest a project has, not the first, and fails on a glob that
|
|
557
|
+
// leads through a file, both refused. Where pnpm-workspace.yaml sets
|
|
558
|
+
// nothing, it finds projects everywhere, as `**` does; where it sets
|
|
559
|
+
// anything but no `packages`, it fails, which is refused; and it refuses
|
|
560
|
+
// no name for it but pnpm-workspace.yml.
|
|
243
561
|
//
|
|
244
562
|
// Refused: a root with no manifest, which pnpm takes for no project; a
|
|
245
563
|
// project, the root among them, whose manifest is package.json5 or
|
|
@@ -249,20 +567,22 @@ export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
|
|
|
249
567
|
// project in a directory a lockfile could not key its importer by, with a
|
|
250
568
|
// control, bidirectional or backslash character in its path, or a drive
|
|
251
569
|
// letter; a node_modules pnpm walks into, which it does only under a
|
|
252
|
-
// directory with a leading dot
|
|
253
|
-
// buildPnpmTree refuses, or a pnpm not 10.x
|
|
570
|
+
// directory with a leading dot, one a glob spells or, for pnpm 9, one
|
|
571
|
+
// past a `**`; a glob buildPnpmTree refuses, or a pnpm not 9.x, 10.x, 11.x
|
|
572
|
+
// or 12.x; and a pnpm-workspace.yaml that is not YAML, is not a mapping,
|
|
573
|
+
// is not UTF-8, or is under another name pnpm refuses.
|
|
254
574
|
export interface PnpmProjectsOptions {
|
|
255
|
-
|
|
256
|
-
host
|
|
257
|
-
vfs: Pick<Vfs, 'readdir' | 'lstat' | 'stat'>
|
|
575
|
+
project: PnpmProject
|
|
576
|
+
host?: Pick<PnpmHost, 'pnpm'>
|
|
258
577
|
}
|
|
259
578
|
|
|
260
579
|
export function findPnpmProjects(options: PnpmProjectsOptions): string[]
|
|
261
580
|
|
|
262
581
|
// `where` is what a refusal is about — `pnpm-workspace.yaml: nodeLinker`,
|
|
263
|
-
// `.npmrc:3: node-linker`, a package's key — or
|
|
264
|
-
// a whole; the message leads with it. `cause` is
|
|
265
|
-
// refused with, where one did
|
|
582
|
+
// `.npmrc:3: node-linker`, `pnpm-lock.yaml`, a package's key — or
|
|
583
|
+
// undefined for the call as a whole; the message leads with it. `cause` is
|
|
584
|
+
// what a package beneath refused with, where one did: the lockfile
|
|
585
|
+
// reader's LockfileError, its YamlError, a fetch's failure.
|
|
266
586
|
export class DeptreeError extends Error {
|
|
267
587
|
constructor(detail: string, where?: string, options?: { cause?: unknown })
|
|
268
588
|
where: string | undefined
|
package/pnpm.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
// A node_modules tree built in memory from a pnpm lockfile, as pnpm 10
|
|
2
|
-
// 11 installs it with the isolated linker
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { buildPnpmTree, findPnpmProjects } from './src/pnpm/tree.js'
|
|
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'
|
|
6
5
|
export { DeptreeError } from './src/error.js'
|
|
7
|
-
// Where @preventive/upstream caches what it fetches, tarballs among it;
|
|
8
|
-
// unset, nothing is cached and nothing is written.
|
|
9
6
|
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
10
|
-
// What the inputs beneath are refused with: the lockfile, and the YAML of
|
|
11
|
-
// it and of pnpm-workspace.yaml.
|
|
12
7
|
export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
|