@preventive/deptree 1.0.0-alpha.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/compare.js +123 -0
- package/bin/deptree.js +217 -0
- package/bin/npmrc.js +21 -0
- package/cargo.d.ts +221 -0
- package/cargo.js +6 -0
- package/npm.d.ts +87 -17
- package/package.json +26 -6
- package/pnpm.d.ts +102 -28
- package/soldeer.d.ts +36 -33
- 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 +9 -0
- package/src/error.js +4 -2
- package/src/hash.js +14 -30
- package/src/manifest.js +1 -1
- package/src/matcher.js +1 -1
- package/src/mount.js +10 -0
- package/src/npm/package.js +44 -5
- package/src/npm/tree.js +25 -10
- package/src/patch.js +2 -3
- package/src/pnpm/gitignore.js +2 -3
- package/src/pnpm/hoisted.js +15 -0
- package/src/pnpm/package.js +11 -5
- package/src/pnpm/packlist.js +2 -2
- package/src/pnpm/tree.js +53 -27
- package/src/project.js +4 -5
- package/src/soldeer/config.js +6 -1
- package/src/soldeer/git.js +16 -1
- package/src/soldeer/tree.js +6 -12
- package/src/soldeer/zip.js +3 -4
- package/src/tarball.js +53 -38
- package/src/yarn1/package.js +51 -6
- package/src/yarn1/resolve.js +58 -11
- package/src/yarn1/tree.js +27 -15
- package/yarn1.d.ts +69 -26
package/npm.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js'
|
|
3
2
|
import type { NodeType, Vfs } from '@preventive/vfs'
|
|
4
3
|
|
|
5
4
|
export { LockfileError } from '@preventive/lockfile/npm.js'
|
|
@@ -7,7 +6,7 @@ export { LockfileError } from '@preventive/lockfile/npm.js'
|
|
|
7
6
|
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
8
7
|
// Tarballs are fetched through it, and that is the one place anything here
|
|
9
8
|
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
10
|
-
// cache
|
|
9
|
+
// cache -- under $npm_config_cache, or ~/.npm -- from ~/.audit/cache/tgz, or
|
|
11
10
|
// from its own default cache directory or stasis's, where one there has the
|
|
12
11
|
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
13
12
|
// where one is set, which is where it writes each tarball it fetches:
|
|
@@ -22,7 +21,7 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
22
21
|
// here); npm reads no packageManager field, so the root package.json's is
|
|
23
22
|
// not read. `node` is
|
|
24
23
|
// the Node npm runs on, an exact version; `os` and `cpu` as Node names
|
|
25
|
-
// them
|
|
24
|
+
// them -- `linux`, `x64`; and `libc` the C library npm finds on Linux,
|
|
26
25
|
// `glibc` or `musl`, and left out elsewhere, where npm finds none. Windows
|
|
27
26
|
// is refused: npm links bins there with shims, and workspaces with
|
|
28
27
|
// junctions.
|
|
@@ -75,8 +74,8 @@ export interface NpmProject {
|
|
|
75
74
|
// npm-shrinkwrap.json, which npm reads in the lockfile's stead; and a link
|
|
76
75
|
// anywhere the globs reach, which glob follows or not by where it is.
|
|
77
76
|
//
|
|
78
|
-
// Settings from anywhere else
|
|
79
|
-
// own, the environment, NODE_ENV among it, the command line
|
|
77
|
+
// Settings from anywhere else -- an .npmrc in the home directory or npm's
|
|
78
|
+
// own, the environment, NODE_ENV among it, the command line -- are not
|
|
80
79
|
// read, and are taken to be at their defaults; so is the directory npm is
|
|
81
80
|
// run in, taken to be the lockfile's, with no workspace above it.
|
|
82
81
|
//
|
|
@@ -101,7 +100,7 @@ export interface NpmProject {
|
|
|
101
100
|
//
|
|
102
101
|
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to
|
|
103
102
|
// be the lockfile's directory, beside whatever it holds, such as the
|
|
104
|
-
// projects themselves
|
|
103
|
+
// projects themselves -- it may be `project` too; without one, a new Vfs
|
|
105
104
|
// holds the tree alone. Nothing the tree is built from is read from it. A
|
|
106
105
|
// Vfs that holds a node_modules anywhere, or on macOS a name that is one
|
|
107
106
|
// there, is refused before anything is fetched: kept beside the tree, Node
|
|
@@ -110,8 +109,41 @@ export interface NpmProject {
|
|
|
110
109
|
// or is made, and every file and link is written where nothing is. The
|
|
111
110
|
// tree is built, and held to every check below, before any of it is
|
|
112
111
|
// written, so a refusal leaves the Vfs as it was.
|
|
112
|
+
//
|
|
113
|
+
// `metadata`, true unless given false, has each registry package's version
|
|
114
|
+
// document asked for beside its tarball, through getMeta of
|
|
115
|
+
// @preventive/upstream given the lockfile's dist: the one `cache` keeps,
|
|
116
|
+
// where its dist is that one, else the registry's, a request for each name
|
|
117
|
+
// and version. Its dist has to be the lockfile's, the tarball
|
|
118
|
+
// the registry's own URL and the integrity the lockfile's sha512, compared
|
|
119
|
+
// as text, with nothing hashed again, as the lockfile copies the
|
|
120
|
+
// registry's; and its gitHead, repository, homepage and bugs are the
|
|
121
|
+
// package's. False fetches none, and gives none of them.
|
|
122
|
+
//
|
|
123
|
+
// `cache` is where each registry package's tarball and version document
|
|
124
|
+
// are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
|
|
125
|
+
// cache where it is left out; in a store of the caller's, with `read` and
|
|
126
|
+
// `write`, in place of it; or with false, nowhere, though setCacheDir's
|
|
127
|
+
// cache is read all the same. Other tools' caches are read for tarballs
|
|
128
|
+
// whatever it is. A TypeError is thrown for anything else.
|
|
129
|
+
//
|
|
130
|
+
// `sizeEstimateOnly`, false unless given true, builds the tree's directories
|
|
131
|
+
// and links alone, and fetches no tarball: each package's directory is made
|
|
132
|
+
// where the lockfile puts it, and left empty, and each link is made as it is.
|
|
133
|
+
// Each package's version document is asked for as `metadata` asks for it,
|
|
134
|
+
// whatever `metadata` says, and held to the lockfile's dist as it is held
|
|
135
|
+
// there; and each package is listed with its `size`, the document's
|
|
136
|
+
// dist.unpackedSize, as getMeta of @preventive/upstream reads it: the bytes
|
|
137
|
+
// of the files in its tarball, as the registry counted them when it was
|
|
138
|
+
// published, which is what npm writes of it, but for a .gitignore it drops
|
|
139
|
+
// and a CRLF `#!` line of a bin it rewrites; not the blocks they take. It is
|
|
140
|
+
// undefined where the document names none. What is checked of a package's
|
|
141
|
+
// tarball and files is not, so a lockfile one of those checks would refuse is
|
|
142
|
+
// laid out all the same. A `vfs` is not taken with it.
|
|
113
143
|
export type NpmTreeOptions = NpmTreeGiven | NpmTreeRead
|
|
114
144
|
|
|
145
|
+
export type NpmLayoutOptions = NpmTreeOptions & { sizeEstimateOnly: true, vfs?: undefined }
|
|
146
|
+
|
|
115
147
|
export interface NpmTreeGiven {
|
|
116
148
|
lockfile: string
|
|
117
149
|
manifests: Record<string, string> | Map<string, string>
|
|
@@ -119,6 +151,9 @@ export interface NpmTreeGiven {
|
|
|
119
151
|
project?: undefined
|
|
120
152
|
host: NpmHost
|
|
121
153
|
vfs?: Vfs
|
|
154
|
+
metadata?: boolean
|
|
155
|
+
cache?: CacheOptions['cache']
|
|
156
|
+
sizeEstimateOnly?: boolean
|
|
122
157
|
}
|
|
123
158
|
|
|
124
159
|
export interface NpmTreeRead {
|
|
@@ -128,13 +163,19 @@ export interface NpmTreeRead {
|
|
|
128
163
|
project: NpmProject
|
|
129
164
|
host: NpmHost
|
|
130
165
|
vfs?: Vfs
|
|
166
|
+
metadata?: boolean
|
|
167
|
+
cache?: CacheOptions['cache']
|
|
168
|
+
sizeEstimateOnly?: boolean
|
|
131
169
|
}
|
|
132
170
|
|
|
133
171
|
// What buildNpmTree counts, all of it plain numbers: `packages` the
|
|
134
172
|
// lockfile's, each a copy in a node_modules; `installed` those in the
|
|
135
173
|
// tree; `skipped` those left out, as the host cannot run them or only such
|
|
136
174
|
// need them; `tarballs` those fetched, each once; `files` and `bytes` what
|
|
137
|
-
// is written; `links` the workspaces linked.
|
|
175
|
+
// is written; `links` the workspaces linked. With `sizeEstimateOnly`,
|
|
176
|
+
// `tarballs` counts those fetched by their version document alone; `files`
|
|
177
|
+
// is 0, as none is written, and `bytes` what the sizes of those installed
|
|
178
|
+
// add up to, each copy's, of those with one.
|
|
138
179
|
export interface NpmTreeStats {
|
|
139
180
|
packages: number
|
|
140
181
|
installed: number
|
|
@@ -147,10 +188,16 @@ export interface NpmTreeStats {
|
|
|
147
188
|
|
|
148
189
|
// A package in the tree, as an SBOM would list it: `path` is where its
|
|
149
190
|
// files are, the lockfile's key of it, from the lockfile's directory,
|
|
150
|
-
// which is `/` of the Vfs
|
|
191
|
+
// which is `/` of the Vfs -- node_modules/<name>, beneath another package's
|
|
151
192
|
// node_modules, or beneath a workspace's. `name` and `version` are the
|
|
152
193
|
// package's own, whatever alias it is installed as, as the lockfile has
|
|
153
|
-
// them; `integrity` the sha512 its tarball is held to.
|
|
194
|
+
// them; `integrity` the sha512 its tarball is held to. `commit` is the
|
|
195
|
+
// gitHead of the registry's version document, where `metadata` has it
|
|
196
|
+
// fetched and it is a full commit id, the commit npm read off the checkout
|
|
197
|
+
// it published from; `repository`, `homepage` and `bugs` the document's,
|
|
198
|
+
// as getMeta of @preventive/upstream reads them; each undefined elsewhere,
|
|
199
|
+
// and all of it the publisher's word, held to no repository. The flags are
|
|
200
|
+
// those
|
|
154
201
|
// npm installs by, the lockfile's as npm 10 takes them and as npm 11 works
|
|
155
202
|
// them out again: `dev` is whether dev dependencies alone reach it, which
|
|
156
203
|
// --omit=dev leaves out; `optional` whether optional dependencies alone
|
|
@@ -163,6 +210,10 @@ export interface NpmInstalled {
|
|
|
163
210
|
name: string
|
|
164
211
|
version: string
|
|
165
212
|
integrity: string
|
|
213
|
+
commit: string | undefined
|
|
214
|
+
repository: string | PackageRepository | undefined
|
|
215
|
+
homepage: string | undefined
|
|
216
|
+
bugs: string | PackageBugs | undefined
|
|
166
217
|
dev: boolean
|
|
167
218
|
optional: boolean
|
|
168
219
|
devOptional: boolean
|
|
@@ -178,6 +229,20 @@ export interface NpmTree {
|
|
|
178
229
|
installed: NpmInstalled[]
|
|
179
230
|
}
|
|
180
231
|
|
|
232
|
+
// With `sizeEstimateOnly`, each package as `installed` lists it, with its
|
|
233
|
+
// `size`.
|
|
234
|
+
export interface NpmLaidOut extends NpmInstalled {
|
|
235
|
+
size: number | undefined
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// With `sizeEstimateOnly`: `vfs` a new one, of the tree's directories and
|
|
239
|
+
// links.
|
|
240
|
+
export interface NpmLayout {
|
|
241
|
+
vfs: Vfs
|
|
242
|
+
stats: NpmTreeStats
|
|
243
|
+
installed: NpmLaidOut[]
|
|
244
|
+
}
|
|
245
|
+
|
|
181
246
|
// The node_modules tree `npm ci --ignore-scripts` makes, with host.npm,
|
|
182
247
|
// into a project with no node_modules yet: rooted at the lockfile's
|
|
183
248
|
// directory, each package's files unpacked where the lockfile puts it,
|
|
@@ -239,8 +304,12 @@ export interface NpmTree {
|
|
|
239
304
|
// entry under one directory, named as tar reads it, with no `\` and no
|
|
240
305
|
// more than 1024 segments, none in the package's own node_modules, where
|
|
241
306
|
// npm installs its dependencies, no setuid, setgid or sticky bit, no link
|
|
242
|
-
// name on a file, no global pax header
|
|
243
|
-
//
|
|
307
|
+
// name on a file, no global pax header, and no pax size with a long name, a
|
|
308
|
+
// long link or a global header between it and its entry, which tar's
|
|
309
|
+
// releases read otherwise; each with the sha512 integrity the lockfile
|
|
310
|
+
// records. A pax size is taken over the header's, as every tar release
|
|
311
|
+
// takes it; npm's tar writes one into each pax header it packs, as for a
|
|
312
|
+
// name ustar cannot hold. On
|
|
244
313
|
// macOS, two names in one directory that differ only in case or
|
|
245
314
|
// normalization are refused, as they would be one name there.
|
|
246
315
|
//
|
|
@@ -257,12 +326,13 @@ export interface NpmTree {
|
|
|
257
326
|
//
|
|
258
327
|
// Nothing is left to a guess: a lockfile the lockfile reader refuses, a
|
|
259
328
|
// setting this does not know or does not build for, a package from
|
|
260
|
-
// anywhere but the registry
|
|
261
|
-
// directory by `file:`
|
|
329
|
+
// anywhere but the registry -- git, a tarball's URL or one on disk, a
|
|
330
|
+
// directory by `file:` -- or with no resolved URL, which npm fetches by the
|
|
262
331
|
// registry's packument, a package bundled in another, a link but to a
|
|
263
|
-
// workspace, overrides, acceptDependencies, a check above that fails
|
|
332
|
+
// workspace, overrides, acceptDependencies, a check above that fails --
|
|
264
333
|
// each is refused with a DeptreeError or a LockfileError that says where.
|
|
265
334
|
// A TypeError is thrown for options of the wrong type.
|
|
335
|
+
export function buildNpmTree(options: NpmLayoutOptions): Promise<NpmLayout>
|
|
266
336
|
export function buildNpmTree(options: NpmTreeOptions): Promise<NpmTree>
|
|
267
337
|
|
|
268
338
|
// The directories of the projects npm finds in `project`, by which
|
|
@@ -279,8 +349,8 @@ export interface NpmWorkspacesOptions {
|
|
|
279
349
|
|
|
280
350
|
export function findNpmWorkspaces(options: NpmWorkspacesOptions): string[]
|
|
281
351
|
|
|
282
|
-
// `where` is what a refusal is about
|
|
283
|
-
// lockfile entry, `packages["node_modules/a"]`
|
|
352
|
+
// `where` is what a refusal is about -- `.npmrc:3`, `manifests["."]`, a
|
|
353
|
+
// lockfile entry, `packages["node_modules/a"]` -- or undefined for the call
|
|
284
354
|
// as a whole; the message leads with it. `cause` is what a package beneath
|
|
285
355
|
// refused with, where one did.
|
|
286
356
|
export class DeptreeError extends Error {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/deptree",
|
|
3
|
-
"version": "1.0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "In-memory dependency tree, as a package manager installs it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./pnpm.js": {
|
|
@@ -19,11 +19,20 @@
|
|
|
19
19
|
"./soldeer.js": {
|
|
20
20
|
"types": "./soldeer.d.ts",
|
|
21
21
|
"default": "./soldeer.js"
|
|
22
|
+
},
|
|
23
|
+
"./cargo.js": {
|
|
24
|
+
"types": "./cargo.d.ts",
|
|
25
|
+
"default": "./cargo.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"deptree": "bin/deptree.js"
|
|
30
|
+
},
|
|
24
31
|
"files": [
|
|
25
32
|
"LICENSE-APACHE",
|
|
26
33
|
"LICENSE-MIT",
|
|
34
|
+
"cargo.d.ts",
|
|
35
|
+
"cargo.js",
|
|
27
36
|
"npm.d.ts",
|
|
28
37
|
"npm.js",
|
|
29
38
|
"pnpm.d.ts",
|
|
@@ -32,6 +41,15 @@
|
|
|
32
41
|
"soldeer.js",
|
|
33
42
|
"yarn1.d.ts",
|
|
34
43
|
"yarn1.js",
|
|
44
|
+
"bin/compare.js",
|
|
45
|
+
"bin/deptree.js",
|
|
46
|
+
"bin/npmrc.js",
|
|
47
|
+
"src/cargo/crate.js",
|
|
48
|
+
"src/cargo/inputs.js",
|
|
49
|
+
"src/cargo/members.js",
|
|
50
|
+
"src/cargo/registry.js",
|
|
51
|
+
"src/cargo/tree.js",
|
|
52
|
+
"src/cargo/workspace.js",
|
|
35
53
|
"src/concurrent.js",
|
|
36
54
|
"src/error.js",
|
|
37
55
|
"src/glob.js",
|
|
@@ -125,10 +143,12 @@
|
|
|
125
143
|
},
|
|
126
144
|
"dependencies": {
|
|
127
145
|
"@chalker/queue": "^1.0.1",
|
|
128
|
-
"@
|
|
129
|
-
"@preventive/
|
|
130
|
-
"@preventive/
|
|
131
|
-
"@preventive/
|
|
146
|
+
"@exodus/bytes": "^1.16.0",
|
|
147
|
+
"@preventive/archive": "1.0.0",
|
|
148
|
+
"@preventive/compare": "^1.2.11",
|
|
149
|
+
"@preventive/diff": "^1.1.0",
|
|
150
|
+
"@preventive/lockfile": "^1.2.0",
|
|
151
|
+
"@preventive/upstream": "^1.2.0",
|
|
132
152
|
"@preventive/vfs": "1.0.0-beta.4"
|
|
133
153
|
}
|
|
134
154
|
}
|
package/pnpm.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js'
|
|
3
2
|
import type { NodeType, Vfs } from '@preventive/vfs'
|
|
4
3
|
|
|
5
4
|
// What the lockfile reader and the YAML parser refuse with: the cause of
|
|
@@ -10,7 +9,7 @@ export { LockfileError, YamlError } from '@preventive/lockfile/pnpm.js'
|
|
|
10
9
|
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
11
10
|
// Tarballs are fetched through it, and that is the one place anything here
|
|
12
11
|
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
13
|
-
// cache
|
|
12
|
+
// cache -- under $npm_config_cache, or ~/.npm -- from ~/.audit/cache/tgz, or
|
|
14
13
|
// from its own default cache directory or stasis's, where one there has the
|
|
15
14
|
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
16
15
|
// where one is set, which is where it writes each tarball it fetches:
|
|
@@ -30,7 +29,7 @@ export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
|
30
29
|
// that pins none. `node` is the Node it runs on,
|
|
31
30
|
// unless the settings name a nodeVersion or, for pnpm 11, the root
|
|
32
31
|
// package.json's engines.runtime pins one; `os`, `cpu` and `libc` as Node
|
|
33
|
-
// and pnpm name them
|
|
32
|
+
// and pnpm name them -- `linux`, `x64`, `glibc` -- with `unknown` for a libc
|
|
34
33
|
// outside Linux, as pnpm has it.
|
|
35
34
|
// Windows is refused: pnpm links there with junctions to absolute paths.
|
|
36
35
|
// An optional package the machine cannot run is left out, as pnpm leaves
|
|
@@ -78,14 +77,14 @@ export interface PnpmProject {
|
|
|
78
77
|
// text given; a refusal names each as it would given:
|
|
79
78
|
// `manifests["packages/x"]`, `patches["patches/p.patch"]`.
|
|
80
79
|
//
|
|
81
|
-
// Settings from anywhere else
|
|
82
|
-
// command line
|
|
80
|
+
// Settings from anywhere else -- another .npmrc, the environment, the
|
|
81
|
+
// command line -- are not read, and are taken to be at their defaults; so
|
|
83
82
|
// is pnpm taken to run as itself, not under corepack, and free to switch
|
|
84
83
|
// to the version a project pins.
|
|
85
84
|
//
|
|
86
85
|
// A workspace is one lockfile for several projects, each a package.json:
|
|
87
86
|
// the root, and every directory pnpm-workspace.yaml's `packages` globs
|
|
88
|
-
// take, as pnpm globs for them
|
|
87
|
+
// take, as pnpm globs for them -- `*` and `**`, a leading `!` to leave out,
|
|
89
88
|
// and no other glob syntax. Without `packages` the root is the only
|
|
90
89
|
// project. Every importer has to have its package.json, and be a project
|
|
91
90
|
// those globs take; and every project pnpm would find has to be given,
|
|
@@ -110,12 +109,12 @@ export interface PnpmProject {
|
|
|
110
109
|
// those name none are pnpm-workspace.yaml's `overrides` read. `$name` in
|
|
111
110
|
// one is the root package.json's own specifier for `name`, and
|
|
112
111
|
// `catalog:` what the workspace's catalog gives the package. One to a
|
|
113
|
-
// directory
|
|
112
|
+
// directory -- a path alone, such as `./vendor/foo`, `link:` or `file:` --
|
|
114
113
|
// is read only with `project` given, and only where the directory is
|
|
115
114
|
// under the lockfile's and holds a package.json there. pnpm links to it by a
|
|
116
115
|
// path alone or `link:`. By `file:` it installs it as a package, of the
|
|
117
|
-
// files its packlist picks
|
|
118
|
-
// for pnpm 11, and pnpm 12's own port of it
|
|
116
|
+
// files its packlist picks -- npm-packlist 5.1.3 for pnpm 9 and 10, 10.0.4
|
|
117
|
+
// for pnpm 11, and pnpm 12's own port of it -- which each is followed here
|
|
119
118
|
// as that version runs: by package.json's `files`, `main`, `bin` and, but
|
|
120
119
|
// for pnpm 12, `browser`; by the .npmignore and .gitignore files where it
|
|
121
120
|
// reads them; and by its own rules, case and all, odd steps among them,
|
|
@@ -135,12 +134,12 @@ export interface PnpmProject {
|
|
|
135
134
|
// time linear in the path and the pattern. pnpm hardlinks those files from
|
|
136
135
|
// the directory into each snapshot of the package, in their modes, which
|
|
137
136
|
// are refused but for a checkout's under umask 022 or 002: 0o644, 0o664,
|
|
138
|
-
// 0o755 and 0o775. So a file linking a bin makes executable
|
|
139
|
-
// pnpm 9 and 10, its mode with 0o111 added for 11 and 12
|
|
137
|
+
// 0o755 and 0o775. So a file linking a bin makes executable -- 0o755 for
|
|
138
|
+
// pnpm 9 and 10, its mode with 0o111 added for 11 and 12 -- is made so in
|
|
140
139
|
// every snapshot and in the directory, which is not written here; a CRLF
|
|
141
|
-
// `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package
|
|
140
|
+
// `#!` line it rewrites is rewritten as a file of that snapshot's own. Where it builds the package -- an install script, a
|
|
142
141
|
// binding.gyp, which pnpm 11 and 12 pass over with `gypfile: false`, or a
|
|
143
|
-
// .hooks directory
|
|
142
|
+
// .hooks directory -- or, with pnpm 11 and 12, where packageImportMethod is
|
|
144
143
|
// other than auto or hardlink, each snapshot has a copy of its own
|
|
145
144
|
// instead. One by `file:` to a tarball is refused, and so is a `file:`
|
|
146
145
|
// dependency no override names. One to the lockfile's own directory that
|
|
@@ -158,8 +157,8 @@ export interface PnpmProject {
|
|
|
158
157
|
//
|
|
159
158
|
// Of the .npmrc, only what pnpm reads for an install is read: its settings
|
|
160
159
|
// by their kebab-case names, those that can change the tree held to what
|
|
161
|
-
// is built here, and all else
|
|
162
|
-
// credentials, other names
|
|
160
|
+
// is built here, and all else -- npm's own settings, publishing's,
|
|
161
|
+
// credentials, other names -- passed over. A `${VAR}` pnpm would fill in is
|
|
163
162
|
// taken in a line passed over where the rest of the file would not change
|
|
164
163
|
// the tree, as pnpm drops the whole file where the variable is unset; but
|
|
165
164
|
// `//registry.npmjs.org/:_authToken=${NPM_TOKEN}`, the registry's token as
|
|
@@ -173,8 +172,8 @@ export interface PnpmProject {
|
|
|
173
172
|
// its packageManager, devEngines.packageManager and engines.runtime
|
|
174
173
|
// checks do. The tree follows the lockfile, as pnpm 11's does with
|
|
175
174
|
// trustLockfile: minimumReleaseAge, and the rest of what pnpm 11 checks the
|
|
176
|
-
// lockfile against the registry by before it installs
|
|
177
|
-
// publish time, its tarball URL, its trust
|
|
175
|
+
// lockfile against the registry by before it installs -- each package's
|
|
176
|
+
// publish time, its tarball URL, its trust -- are passed over.
|
|
178
177
|
//
|
|
179
178
|
// pnpm 12 reads them so too. Where the root package.json pins a pnpm that
|
|
180
179
|
// host.pnpm is, it fails on a key of pnpm-workspace.yaml it does not know,
|
|
@@ -209,7 +208,7 @@ export interface PnpmProject {
|
|
|
209
208
|
//
|
|
210
209
|
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to
|
|
211
210
|
// be the lockfile's directory, beside whatever it holds, such as the
|
|
212
|
-
// projects themselves
|
|
211
|
+
// projects themselves -- it may be `project` too; without one, a new Vfs
|
|
213
212
|
// holds the tree alone. Nothing the tree is built from is read from it. A
|
|
214
213
|
// Vfs that holds a node_modules anywhere, or on macOS a name that is one
|
|
215
214
|
// there, is refused before anything is fetched: kept beside the tree, Node
|
|
@@ -221,11 +220,52 @@ export interface PnpmProject {
|
|
|
221
220
|
// node_modules is written, though pnpm 9 and 10 make the files a linked
|
|
222
221
|
// directory's bins run executable too.
|
|
223
222
|
//
|
|
223
|
+
// `metadata`, true unless given false, has each registry package's version
|
|
224
|
+
// document asked for beside its tarball, through getMeta of
|
|
225
|
+
// @preventive/upstream given the lockfile's dist: the one `cache` keeps,
|
|
226
|
+
// where its dist is that one, else the registry's, a request for each name
|
|
227
|
+
// and version. Its dist has to be the lockfile's, the tarball
|
|
228
|
+
// the registry's own URL and the integrity the lockfile's sha512, compared
|
|
229
|
+
// as text, with nothing hashed again, as the lockfile copies the
|
|
230
|
+
// registry's; and its gitHead, repository, homepage and bugs are the
|
|
231
|
+
// package's. False fetches none, and gives none of them.
|
|
232
|
+
//
|
|
233
|
+
// `cache` is where each registry package's tarball and version document
|
|
234
|
+
// are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
|
|
235
|
+
// cache where it is left out; in a store of the caller's, with `read` and
|
|
236
|
+
// `write`, in place of it; or with false, nowhere, though setCacheDir's
|
|
237
|
+
// cache is read all the same. Other tools' caches are read for tarballs
|
|
238
|
+
// whatever it is. A TypeError is thrown for anything else.
|
|
239
|
+
//
|
|
240
|
+
// `sizeEstimateOnly`, false unless given true, builds the tree's directories
|
|
241
|
+
// and links alone, and fetches no tarball: each package's directory is made
|
|
242
|
+
// where its files would be, and left empty, and each link is made as it is.
|
|
243
|
+
// Each registry package's version document is asked for as `metadata` asks
|
|
244
|
+
// for it, whatever `metadata` says, and held to the lockfile's dist as it is
|
|
245
|
+
// held there; and each copy is listed with its `size`, the document's
|
|
246
|
+
// dist.unpackedSize, as getMeta of @preventive/upstream reads it: the bytes
|
|
247
|
+
// of the files in its tarball, as the registry counted them when it was
|
|
248
|
+
// published, which is what pnpm writes of it, but for a patch and a CRLF `#!`
|
|
249
|
+
// line of a bin it rewrites; not the blocks they take, nor what pnpm shares
|
|
250
|
+
// by hardlinks from its store. It is undefined where the document names none.
|
|
251
|
+
// A `file:` directory is read whole all the same, and its size is that of the
|
|
252
|
+
// files its packlist picks. What is checked of a package's files and
|
|
253
|
+
// package.json is not, so a lockfile one of those checks would refuse is laid
|
|
254
|
+
// out all the same; so is a patched package that pnpm 11 and 12 would, with
|
|
255
|
+
// engineStrict, take out or fail on by the engines.node of its package.json,
|
|
256
|
+
// patched. But where the files could change the layout, the lockfile is
|
|
257
|
+
// refused, before anything is fetched: for the hoisted linker of pnpm 10.21
|
|
258
|
+
// to before 11.25, where any patch is configured, a package of more than one
|
|
259
|
+
// copy, one with a node_modules, which pnpm drops where it builds the
|
|
260
|
+
// package. A `vfs` is not taken with it.
|
|
261
|
+
//
|
|
224
262
|
// The two ways the files come, one or the other: given, with `lockfile`
|
|
225
263
|
// and `manifests`, `project` read only for directories; or read, with
|
|
226
264
|
// `project` and none of them.
|
|
227
265
|
export type PnpmTreeOptions = PnpmTreeGiven | PnpmTreeRead
|
|
228
266
|
|
|
267
|
+
export type PnpmLayoutOptions = PnpmTreeOptions & { sizeEstimateOnly: true, vfs?: undefined }
|
|
268
|
+
|
|
229
269
|
export interface PnpmTreeGiven {
|
|
230
270
|
lockfile: string
|
|
231
271
|
manifests: Record<string, string> | Map<string, string>
|
|
@@ -235,6 +275,9 @@ export interface PnpmTreeGiven {
|
|
|
235
275
|
project?: PnpmProject
|
|
236
276
|
host: PnpmHost
|
|
237
277
|
vfs?: Vfs
|
|
278
|
+
metadata?: boolean
|
|
279
|
+
cache?: CacheOptions['cache']
|
|
280
|
+
sizeEstimateOnly?: boolean
|
|
238
281
|
}
|
|
239
282
|
|
|
240
283
|
export interface PnpmTreeRead {
|
|
@@ -246,6 +289,9 @@ export interface PnpmTreeRead {
|
|
|
246
289
|
project: PnpmProject
|
|
247
290
|
host: PnpmHost
|
|
248
291
|
vfs?: Vfs
|
|
292
|
+
metadata?: boolean
|
|
293
|
+
cache?: CacheOptions['cache']
|
|
294
|
+
sizeEstimateOnly?: boolean
|
|
249
295
|
}
|
|
250
296
|
|
|
251
297
|
// What buildPnpmTree counts, all of it plain numbers: `projects` the
|
|
@@ -255,6 +301,10 @@ export interface PnpmTreeRead {
|
|
|
255
301
|
// does not take their platform or engines, which pnpm warns of; `tarballs`
|
|
256
302
|
// the packages fetched, each once; `patched` the snapshots a patch is
|
|
257
303
|
// applied to; `files` and `bytes` what is written; `links` the symlinks.
|
|
304
|
+
// With `sizeEstimateOnly`, `tarballs` counts the packages fetched by their
|
|
305
|
+
// version document alone; `files` is 0, as none is written, and `bytes`
|
|
306
|
+
// what the sizes of those installed add up to, each copy's, of those with
|
|
307
|
+
// one.
|
|
258
308
|
export interface PnpmTreeStats {
|
|
259
309
|
projects: number
|
|
260
310
|
snapshots: number
|
|
@@ -269,14 +319,19 @@ export interface PnpmTreeStats {
|
|
|
269
319
|
}
|
|
270
320
|
|
|
271
321
|
// A snapshot in the tree, as an SBOM would list it: `path` is where its
|
|
272
|
-
// files are, from the lockfile's directory, which is `/` of the Vfs
|
|
322
|
+
// files are, from the lockfile's directory, which is `/` of the Vfs --
|
|
273
323
|
// node_modules/.pnpm/<dir>/node_modules/<name>; `key` the lockfile's
|
|
274
324
|
// snapshot key, its peers and patch hash in it. `name` and `version` are
|
|
275
325
|
// the package's own, which its package.json is held to, and `integrity`
|
|
276
326
|
// the sha512 its tarball is held to; one a `file:` override has pnpm
|
|
277
327
|
// install from a directory has `directory`, from the lockfile's, `.` for
|
|
278
328
|
// its own, and neither a version nor an integrity, as the lockfile records
|
|
279
|
-
// none.
|
|
329
|
+
// none. `commit` is the gitHead of a registry package's version document,
|
|
330
|
+
// where `metadata` has it fetched and it is a full commit id, the commit
|
|
331
|
+
// npm read off the checkout it published from; `repository`, `homepage`
|
|
332
|
+
// and `bugs` the document's, as getMeta of @preventive/upstream reads
|
|
333
|
+
// them; each undefined elsewhere, and all of it the publisher's word, held
|
|
334
|
+
// to no repository.
|
|
280
335
|
// `dev` is whether devDependencies alone reach it: no project's
|
|
281
336
|
// dependencies or optionalDependencies do, through what is installed, so
|
|
282
337
|
// `pnpm install --prod` would leave it out. `optional` is whether optional
|
|
@@ -290,6 +345,10 @@ export interface PnpmInstalled {
|
|
|
290
345
|
version: string | undefined
|
|
291
346
|
integrity: string | undefined
|
|
292
347
|
directory: string | undefined
|
|
348
|
+
commit: string | undefined
|
|
349
|
+
repository: string | PackageRepository | undefined
|
|
350
|
+
homepage: string | undefined
|
|
351
|
+
bugs: string | PackageBugs | undefined
|
|
293
352
|
dev: boolean
|
|
294
353
|
optional: boolean
|
|
295
354
|
patch: { hash: string, path: string } | undefined
|
|
@@ -306,6 +365,20 @@ export interface PnpmTree {
|
|
|
306
365
|
installed: PnpmInstalled[]
|
|
307
366
|
}
|
|
308
367
|
|
|
368
|
+
// With `sizeEstimateOnly`, each copy as `installed` lists it, with its
|
|
369
|
+
// `size`.
|
|
370
|
+
export interface PnpmLaidOut extends PnpmInstalled {
|
|
371
|
+
size: number | undefined
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// With `sizeEstimateOnly`: `vfs` a new one, of the tree's directories and
|
|
375
|
+
// links.
|
|
376
|
+
export interface PnpmLayout {
|
|
377
|
+
vfs: Vfs
|
|
378
|
+
stats: PnpmTreeStats
|
|
379
|
+
installed: PnpmLaidOut[]
|
|
380
|
+
}
|
|
381
|
+
|
|
309
382
|
// The node_modules tree `pnpm install --frozen-lockfile --ignore-scripts`
|
|
310
383
|
// makes with the isolated linker of host.pnpm, 9, 10, 11 or 12, or the
|
|
311
384
|
// hoisted one of pnpm 10 or 11, and no other install: whatever the
|
|
@@ -340,9 +413,9 @@ export interface PnpmTree {
|
|
|
340
413
|
// out of the package, which is refused; it fails on a bin that is a
|
|
341
414
|
// directory, which is refused, where pnpm 10 passes over it.
|
|
342
415
|
//
|
|
343
|
-
// pnpm 11 links bins otherwise in places
|
|
416
|
+
// pnpm 11 links bins otherwise in places -- npm owns `npx` and pnpm its
|
|
344
417
|
// aliases, a project's .bin takes the bins of the peers its dependencies
|
|
345
|
-
// require
|
|
418
|
+
// require -- and each is built as the one given links them.
|
|
346
419
|
//
|
|
347
420
|
// pnpm 12, a rewrite of pnpm, makes its tree otherwise again, and it is
|
|
348
421
|
// built as pnpm 12 makes it. It links each package's own bins into its own
|
|
@@ -399,9 +472,9 @@ export interface PnpmTree {
|
|
|
399
472
|
// steps, weighted by the work each does, or a tree of 100,000 packages.
|
|
400
473
|
//
|
|
401
474
|
// The lockfile is held to what a frozen install holds it to, and refused
|
|
402
|
-
// where pnpm would refuse it: the settings that shaped its resolution
|
|
475
|
+
// where pnpm would refuse it: the settings that shaped its resolution --
|
|
403
476
|
// catalogs, overrides, package extensions, optional dependencies left out,
|
|
404
|
-
// patches, autoInstallPeers, dedupePeers, peersSuffixMaxLength
|
|
477
|
+
// patches, autoInstallPeers, dedupePeers, peersSuffixMaxLength -- and each
|
|
405
478
|
// project's package.json, read through pnpm's read-package hook as pnpm
|
|
406
479
|
// reads it. The root package.json's packageManager, where it has one, has
|
|
407
480
|
// to be `pnpm@` host.pnpm exactly, as pnpm would switch to the one it
|
|
@@ -488,11 +561,12 @@ export interface PnpmTree {
|
|
|
488
561
|
// name, a patch that does not hash or apply, a check above that fails,
|
|
489
562
|
// text that is not well-formed where it is hashed, a patch that would
|
|
490
563
|
// change a bin's file between two times pnpm links it, a file whose mode
|
|
491
|
-
// would turn on the order a directory is read in
|
|
564
|
+
// would turn on the order a directory is read in -- each is refused with a
|
|
492
565
|
// DeptreeError that says where: where the lockfile reader or the YAML
|
|
493
566
|
// parser refused pnpm-lock.yaml or pnpm-workspace.yaml, it names the file,
|
|
494
567
|
// and its cause is their LockfileError or YamlError. A TypeError is thrown
|
|
495
568
|
// for options of the wrong type.
|
|
569
|
+
export function buildPnpmTree(options: PnpmLayoutOptions): Promise<PnpmLayout>
|
|
496
570
|
export function buildPnpmTree(options: PnpmTreeOptions): Promise<PnpmTree>
|
|
497
571
|
|
|
498
572
|
// The directories of the projects pnpm finds in `project`, by which
|
|
@@ -547,8 +621,8 @@ export interface PnpmProjectsOptions {
|
|
|
547
621
|
|
|
548
622
|
export function findPnpmProjects(options: PnpmProjectsOptions): string[]
|
|
549
623
|
|
|
550
|
-
// `where` is what a refusal is about
|
|
551
|
-
// `.npmrc:3: node-linker`, `pnpm-lock.yaml`, a package's key
|
|
624
|
+
// `where` is what a refusal is about -- `pnpm-workspace.yaml: nodeLinker`,
|
|
625
|
+
// `.npmrc:3: node-linker`, `pnpm-lock.yaml`, a package's key -- or
|
|
552
626
|
// undefined for the call as a whole; the message leads with it. `cause` is
|
|
553
627
|
// what a package beneath refused with, where one did: the lockfile
|
|
554
628
|
// reader's LockfileError, its YamlError, a fetch's failure.
|