@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/cargo.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Hand-written against cargo.js; a change to either belongs with the other.
|
|
2
|
+
|
|
3
|
+
import type { NodeType, Vfs } from '@preventive/vfs'
|
|
4
|
+
|
|
5
|
+
export { LockfileError, TomlError } from '@preventive/lockfile/cargo.js'
|
|
6
|
+
|
|
7
|
+
// Where @preventive/upstream caches what it fetches, .crate files among
|
|
8
|
+
// them. Each .crate is fetched through it, and that is the one place
|
|
9
|
+
// anything here touches a filesystem. Before the network, it takes one from
|
|
10
|
+
// cargo's own cache — each registry's under $CARGO_HOME/registry/cache, or
|
|
11
|
+
// ~/.cargo where that is unset — where one there has the lockfile's
|
|
12
|
+
// checksum, and writes none of it; then from its own cache, where one is
|
|
13
|
+
// set, which is where it writes each .crate it fetches: setCacheDir() sets
|
|
14
|
+
// the default one, and setCacheDir(false) unsets it. Unset, which it is
|
|
15
|
+
// until set, it writes nothing. The project is read only through the view
|
|
16
|
+
// given as `project`, and the tree built in a Vfs.
|
|
17
|
+
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
18
|
+
|
|
19
|
+
// The machine cargo would vendor on: `cargo` is the version that vendors,
|
|
20
|
+
// exact, 1.94.0 to 1.99.x, which unpack a .crate alike, those from 1.97 on
|
|
21
|
+
// writing a `$comment` in each .cargo-checksum.json that those before do
|
|
22
|
+
// not; `os` as Node names it — `linux`, `darwin`. Windows is refused:
|
|
23
|
+
// cargo unpacks and names files otherwise there.
|
|
24
|
+
export interface CargoHost {
|
|
25
|
+
cargo: string
|
|
26
|
+
os: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// A view of the project's root, by paths from `/`: a Vfs, or anything with
|
|
30
|
+
// its readdir, lstat, stat and readFile, such as one of a directory on
|
|
31
|
+
// disk, of which only this is read: Cargo.lock; the Cargo.toml of every
|
|
32
|
+
// path package cargo reads, as below, and of each directory between one and
|
|
33
|
+
// the root, as cargo looks there for a workspace's root; the directories
|
|
34
|
+
// workspace.members takes; and .cargo/config, or else .cargo/config.toml.
|
|
35
|
+
// Each is read as UTF-8, and refused where it is not. A link where cargo
|
|
36
|
+
// looks for members, or at or on the way to any file it reads — Cargo.lock,
|
|
37
|
+
// the config, a Cargo.toml — is refused, so that nothing is read from
|
|
38
|
+
// outside the view. Each throws an error
|
|
39
|
+
// whose `code` is ENOENT, ENOTDIR or ELOOP for a path that leads nowhere.
|
|
40
|
+
// Nothing is written to it.
|
|
41
|
+
export interface CargoProject {
|
|
42
|
+
readdir(path: string): string[]
|
|
43
|
+
lstat(path: string): { type: NodeType }
|
|
44
|
+
stat(path: string): { type: NodeType }
|
|
45
|
+
readFile(path: string): Uint8Array
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The files `cargo vendor` reads, run at the project's root, which is taken
|
|
49
|
+
// to be the workspace's, with no workspace above it: Cargo.lock; the
|
|
50
|
+
// Cargo.toml of the root and of every other path package cargo reads; and
|
|
51
|
+
// the project's .cargo/config.toml, where there is one.
|
|
52
|
+
//
|
|
53
|
+
// The path packages are the members — the root's package, each directory
|
|
54
|
+
// workspace.members takes and workspace.exclude does not, and each path
|
|
55
|
+
// dependency of a member that is in the root and not excluded — and every
|
|
56
|
+
// other package cargo reads from a path: each path dependency of a member
|
|
57
|
+
// that is not one, each [patch] from a path, and each normal or build path
|
|
58
|
+
// dependency of those, which cargo resolves where it resolves their
|
|
59
|
+
// dev-dependencies for members alone. Each inherits from the root's
|
|
60
|
+
// [workspace] where cargo has it inherit: where it is in the root and not
|
|
61
|
+
// excluded, or its package.workspace points to the root.
|
|
62
|
+
//
|
|
63
|
+
// With `lockfile`, they are given as text: `manifests` by directory, `.`
|
|
64
|
+
// for the root and each other's path from it, with no `.`, `..` or empty
|
|
65
|
+
// segment; and `config`, where there is one. They stand for the project, so
|
|
66
|
+
// that a directory none of them is in is taken not to be there, and every
|
|
67
|
+
// one cargo reads has to be given, and none else. Without it, they are read
|
|
68
|
+
// from `project`, and none of them may be given. A refusal names each by
|
|
69
|
+
// its path from the root: `crates/a/Cargo.toml`.
|
|
70
|
+
//
|
|
71
|
+
// Of a workspace, what cargo reads otherwise than this is refused: a glob
|
|
72
|
+
// in workspace.members or default-members with a `**` or a `[`, a path in
|
|
73
|
+
// one of the three lists or in a manifest that is absolute, leads out of
|
|
74
|
+
// the project or has a `..` after a name; a package.workspace that points
|
|
75
|
+
// elsewhere than the root, or a root's at all; a [workspace] between a
|
|
76
|
+
// package and the root. What cargo refuses of one is refused too: a glob
|
|
77
|
+
// that takes nothing, a member with no Cargo.toml or with a [workspace] of
|
|
78
|
+
// its own, a root excluded from its own workspace, a default member that is
|
|
79
|
+
// no member, a path dependency or [patch] that leads to no package or to
|
|
80
|
+
// another of the name. Settings from anywhere else — a config above the
|
|
81
|
+
// project or in cargo's home, the environment, the command line — are not
|
|
82
|
+
// read, and are taken to be at their defaults. Of the config, [patch] is
|
|
83
|
+
// read, as cargo resolves with it; `paths` and `include` are refused; the
|
|
84
|
+
// rest is passed over, as it bears on where packages are fetched from and
|
|
85
|
+
// not on what is vendored: `cargo vendor` replaces no source unless told
|
|
86
|
+
// to with --respect-source-config.
|
|
87
|
+
//
|
|
88
|
+
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to be
|
|
89
|
+
// the project's — it may be `project` too; without one, a new Vfs holds
|
|
90
|
+
// the tree alone. A Vfs that holds a `vendor` at its root, or on macOS a
|
|
91
|
+
// name that is one there, is refused before anything is fetched: cargo
|
|
92
|
+
// would remove what is in it. Nothing there is written over: each
|
|
93
|
+
// directory the tree has is one there or is made, and every file is written
|
|
94
|
+
// where nothing is. The tree is built, and held to every check below,
|
|
95
|
+
// before any of it is written, so a refusal leaves the Vfs as it was.
|
|
96
|
+
export type CargoTreeOptions = CargoTreeGiven | CargoTreeRead
|
|
97
|
+
|
|
98
|
+
export interface CargoTreeGiven {
|
|
99
|
+
lockfile: string
|
|
100
|
+
manifests: Record<string, string> | Map<string, string>
|
|
101
|
+
config?: string
|
|
102
|
+
project?: undefined
|
|
103
|
+
host: CargoHost
|
|
104
|
+
vfs?: Vfs
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface CargoTreeRead {
|
|
108
|
+
lockfile?: undefined
|
|
109
|
+
manifests?: undefined
|
|
110
|
+
config?: undefined
|
|
111
|
+
project: CargoProject
|
|
112
|
+
host: CargoHost
|
|
113
|
+
vfs?: Vfs
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// What buildCargoTree counts, all of it plain numbers: `packages` the
|
|
117
|
+
// lockfile's; `vendored` those copied into vendor/, each a .crate fetched;
|
|
118
|
+
// `files` and `bytes` what is written, each .cargo-checksum.json among it.
|
|
119
|
+
export interface CargoTreeStats {
|
|
120
|
+
packages: number
|
|
121
|
+
vendored: number
|
|
122
|
+
files: number
|
|
123
|
+
bytes: number
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// A package in the tree, as an SBOM would list it: `path` is its
|
|
127
|
+
// directory, from the project's root, which is `/` of the Vfs —
|
|
128
|
+
// vendor/<name>, or vendor/<name>-<version> for all but the greatest
|
|
129
|
+
// version of a name; `name`, `version` and `source` the lockfile's;
|
|
130
|
+
// `checksum` the hex sha256 its .crate is held to; `commit` the commit its
|
|
131
|
+
// .cargo_vcs_info.json names, as `cargo package` writes one where it packs
|
|
132
|
+
// from a git checkout, where that is a full commit id and the checkout was
|
|
133
|
+
// not dirty, and undefined elsewhere; `repository` and `homepage` those its
|
|
134
|
+
// Cargo.toml's [package] gives, as cargo packed it, each undefined where it
|
|
135
|
+
// gives none. All of it is the publisher's word, held to no repository.
|
|
136
|
+
export interface CargoInstalled {
|
|
137
|
+
path: string
|
|
138
|
+
name: string
|
|
139
|
+
version: string
|
|
140
|
+
source: string
|
|
141
|
+
checksum: string
|
|
142
|
+
commit: string | undefined
|
|
143
|
+
repository: string | undefined
|
|
144
|
+
homepage: string | undefined
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// `vfs` is the one given, the tree mounted into it, or a new one.
|
|
148
|
+
// `installed` is each package vendored, in the lockfile's order.
|
|
149
|
+
export interface CargoTree {
|
|
150
|
+
vfs: Vfs
|
|
151
|
+
stats: CargoTreeStats
|
|
152
|
+
installed: CargoInstalled[]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// The vendor directory `cargo vendor` makes from the lockfile, with
|
|
156
|
+
// host.cargo and none of its options, in a project with no vendor directory
|
|
157
|
+
// yet: rooted at the project's root, it holds vendor/<directory> for each
|
|
158
|
+
// package of the lockfile but a path one, and nothing else of the project;
|
|
159
|
+
// none at all where every package is a path one. Each package's directory
|
|
160
|
+
// is its name, or `<name>-<version>` for all but the greatest version of
|
|
161
|
+
// that name, by the semver crate's order. What cargo writes or prints
|
|
162
|
+
// beside it — the config that reads from it, the lockfile again — is not
|
|
163
|
+
// written.
|
|
164
|
+
//
|
|
165
|
+
// The lockfile is held to the manifests, as cargo would resolve anew one
|
|
166
|
+
// that is out of date with them and vendor what that comes to: every
|
|
167
|
+
// package's, a vendored one's from its .crate, laid over it with
|
|
168
|
+
// @preventive/lockfile/cargo.js's linkCargo, with what that refuses, and
|
|
169
|
+
// each path dependency to the package in the directory it leads to. Every
|
|
170
|
+
// path package of the lockfile has to be one cargo reads, and every member
|
|
171
|
+
// one of the lockfile's.
|
|
172
|
+
//
|
|
173
|
+
// Each .crate is fetched from crates.io and held to the lockfile's checksum,
|
|
174
|
+
// its sha256. It is unpacked as cargo unpacks it into vendor/: every entry
|
|
175
|
+
// under the directory `<name>-<version>`, that directory taken off; of what
|
|
176
|
+
// is under it, anything under a `.git`, a .gitattributes or .gitignore,
|
|
177
|
+
// and a .cargo-ok, passed over, and a directory none but such entries are
|
|
178
|
+
// in not made. Each directory is 0o755, or its own entry's mode where it has
|
|
179
|
+
// one; each file its mode within 0o777; both as a umask of 0o022 leaves
|
|
180
|
+
// them. Each directory then gets a .cargo-checksum.json, 0o644, as cargo
|
|
181
|
+
// writes it: the sha256 of each file and of the .crate, as serde_json
|
|
182
|
+
// writes them.
|
|
183
|
+
//
|
|
184
|
+
// What the archive readers refuse is refused: @preventive/archive's
|
|
185
|
+
// compression.js and tar.js refuse a name with a backslash, a control or
|
|
186
|
+
// formatting character, an empty or `..` segment, or a drive letter, two
|
|
187
|
+
// entries of one name that differ, an entry inside one that is not a
|
|
188
|
+
// directory, a sparse entry — where cargo would take some of it. What cargo
|
|
189
|
+
// reads otherwise than the readers is refused:
|
|
190
|
+
// a .crate of more than one gzip member, of which cargo reads the first
|
|
191
|
+
// alone; a gzip header CRC or reserved flag; a pax size, which cargo 1.94.0
|
|
192
|
+
// reads otherwise. What cargo refuses or fails on is refused: a .crate that
|
|
193
|
+
// unpacks to more than 512 MiB, or twenty times its size where that is
|
|
194
|
+
// more; an entry not under `<name>-<version>`, an entry not a file or
|
|
195
|
+
// directory, a .crate's own .cargo-checksum.json, which cargo lists and
|
|
196
|
+
// writes over so that it cannot build from it. So is what cargo fails on or
|
|
197
|
+
// reads otherwise as any user but root: a file whose mode lacks the owner's
|
|
198
|
+
// read, which cargo cannot checksum; a directory with anything in it whose
|
|
199
|
+
// mode lacks the owner's read or search, whose files cargo leaves out of
|
|
200
|
+
// .cargo-checksum.json; and one whose mode lacks the owner's write where
|
|
201
|
+
// anything is written into it after its own entry, as .cargo-checksum.json
|
|
202
|
+
// always is into the package's. A directory with nothing in it may have any
|
|
203
|
+
// mode. On macOS, two names in one directory that differ only in case
|
|
204
|
+
// or normalization are refused, as they would be one name there.
|
|
205
|
+
//
|
|
206
|
+
// Packages come from crates.io alone: one from git, which cargo vendor
|
|
207
|
+
// checks out with git, or from another registry, is refused.
|
|
208
|
+
//
|
|
209
|
+
// Nothing is left to a guess: a lockfile or manifest the lockfile reader
|
|
210
|
+
// refuses, a workspace this does not read as cargo reads it, a package from
|
|
211
|
+
// anywhere but crates.io, a check above that fails — each is refused with a
|
|
212
|
+
// DeptreeError, a LockfileError or a TomlError that says where. A TypeError
|
|
213
|
+
// is thrown for options of the wrong type.
|
|
214
|
+
export function buildCargoTree(options: CargoTreeOptions): Promise<CargoTree>
|
|
215
|
+
|
|
216
|
+
// `where` is what a refusal is about — `crates/a/Cargo.toml`,
|
|
217
|
+
// `packages["serde 1.0.0 (registry+…)"]`, an entry of a .crate — or
|
|
218
|
+
// undefined for the call as a whole; the message leads with it. `cause` is
|
|
219
|
+
// what a package beneath refused with, where one did.
|
|
220
|
+
export class DeptreeError extends Error {
|
|
221
|
+
constructor(detail: string, where?: string, options?: { cause?: unknown })
|
|
222
|
+
where: string | undefined
|
|
223
|
+
}
|
package/cargo.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The vendor directory built in memory from a Cargo.lock, as `cargo vendor`
|
|
2
|
+
// makes it; see cargo.d.ts.
|
|
3
|
+
export { buildCargoTree } from './src/cargo/tree.js'
|
|
4
|
+
export { DeptreeError } from './src/error.js'
|
|
5
|
+
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
6
|
+
export { LockfileError, TomlError } from '@preventive/lockfile/cargo.js'
|
package/npm.d.ts
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// Hand-written against npm.js; a change to either belongs with the other.
|
|
2
|
+
|
|
3
|
+
import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js'
|
|
4
|
+
import type { NodeType, Vfs } from '@preventive/vfs'
|
|
5
|
+
|
|
6
|
+
export { LockfileError } from '@preventive/lockfile/npm.js'
|
|
7
|
+
|
|
8
|
+
// Where @preventive/upstream caches what it fetches, tarballs among them.
|
|
9
|
+
// Tarballs are fetched through it, and that is the one place anything here
|
|
10
|
+
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
11
|
+
// cache — under $npm_config_cache, or ~/.npm — from ~/.audit/cache/tgz, or
|
|
12
|
+
// from its own default cache directory or stasis's, where one there has the
|
|
13
|
+
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
14
|
+
// where one is set, which is where it writes each tarball it fetches:
|
|
15
|
+
// setCacheDir() sets the default one, and setCacheDir(false) unsets it.
|
|
16
|
+
// Unset, which it is until set, it writes nothing. The project is read
|
|
17
|
+
// only through the view given as `project`, and the tree built in a Vfs.
|
|
18
|
+
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
19
|
+
|
|
20
|
+
// The machine npm would install on, which a tree depends on. `npm` is the
|
|
21
|
+
// version that installs, exact: 10.9.3 to 10.9.9, or 11.11.1 to 11.21.0
|
|
22
|
+
// (10.9.0 to 10.9.2 escape a `#` in the project's path, which is not known
|
|
23
|
+
// here); npm reads no packageManager field, so the root package.json's is
|
|
24
|
+
// not read. `node` is
|
|
25
|
+
// the Node npm runs on, an exact version; `os` and `cpu` as Node names
|
|
26
|
+
// them — `linux`, `x64`; and `libc` the C library npm finds on Linux,
|
|
27
|
+
// `glibc` or `musl`, and left out elsewhere, where npm finds none. Windows
|
|
28
|
+
// is refused: npm links bins there with shims, and workspaces with
|
|
29
|
+
// junctions.
|
|
30
|
+
//
|
|
31
|
+
// A package whose os, cpu, libc or engines the host does not take is left
|
|
32
|
+
// out where npm takes it as optional, and with it what npm leaves out with
|
|
33
|
+
// it; one that is not optional is refused where its platform is not the
|
|
34
|
+
// host's, as npm fails on it, and installed where its engines are not, as
|
|
35
|
+
// npm warns of them, unless engine-strict is set. So for the root and each
|
|
36
|
+
// workspace, by their package.json. A libc a package names fails a host
|
|
37
|
+
// with none, whatever it names.
|
|
38
|
+
export interface NpmHost {
|
|
39
|
+
npm: string
|
|
40
|
+
node: string
|
|
41
|
+
os: string
|
|
42
|
+
cpu: string
|
|
43
|
+
libc?: 'glibc' | 'musl'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// A view of the lockfile's directory, by paths from `/`: a Vfs, or
|
|
47
|
+
// anything with its readdir, lstat, stat and readFile, such as one of a
|
|
48
|
+
// directory on disk, of which only this is read: the names in a
|
|
49
|
+
// directory; what a path is, `file`, `directory` or `symlink`, with lstat,
|
|
50
|
+
// and what it leads to with stat; and a file's bytes. Each throws an error
|
|
51
|
+
// whose `code` is ENOENT, ENOTDIR or ELOOP for a path that leads nowhere.
|
|
52
|
+
// Nothing is written to it.
|
|
53
|
+
export interface NpmProject {
|
|
54
|
+
readdir(path: string): string[]
|
|
55
|
+
lstat(path: string): { type: NodeType }
|
|
56
|
+
stat(path: string): { type: NodeType }
|
|
57
|
+
readFile(path: string): Uint8Array
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The files `npm ci` reads: package-lock.json; the package.json of the
|
|
61
|
+
// root and of every workspace; and the .npmrc, where there is one.
|
|
62
|
+
//
|
|
63
|
+
// With `lockfile`, they are given as text: `manifests` by the project's
|
|
64
|
+
// directory relative to the lockfile's (`.` for the root, then each
|
|
65
|
+
// workspace's, as findNpmWorkspaces lists them: a directory under the
|
|
66
|
+
// lockfile's, with no `.`, `..` or empty segment). Every workspace npm would
|
|
67
|
+
// find has to be given, and none else: the lockfile's have to be those.
|
|
68
|
+
//
|
|
69
|
+
// Without it, they are read from `project`, as npm reads them there, and
|
|
70
|
+
// none of them may be given: package-lock.json, which has to be there; the
|
|
71
|
+
// root package.json, which has to be there too; the package.json of every
|
|
72
|
+
// directory the root's `workspaces` globs take, as npm globs for them,
|
|
73
|
+
// outside node_modules, on macOS whatever the case; and the .npmrc. Each
|
|
74
|
+
// is read as UTF-8, and refused where it is not. A refusal names each as
|
|
75
|
+
// it would given: `manifests["packages/x"]`. Refused there: an
|
|
76
|
+
// npm-shrinkwrap.json, which npm reads in the lockfile's stead; and a link
|
|
77
|
+
// anywhere the globs reach, which glob follows or not by where it is.
|
|
78
|
+
//
|
|
79
|
+
// Settings from anywhere else — an .npmrc in the home directory or npm's
|
|
80
|
+
// own, the environment, NODE_ENV among it, the command line — are not
|
|
81
|
+
// read, and are taken to be at their defaults; so is the directory npm is
|
|
82
|
+
// run in, taken to be the lockfile's, with no workspace above it.
|
|
83
|
+
//
|
|
84
|
+
// Of the .npmrc, as npm reads it: npm hands the install each setting as
|
|
85
|
+
// ini reads it, before it checks it, so `bin-links=0` links bins, "0" being
|
|
86
|
+
// a truthy string. A setting that can change what npm installs is read
|
|
87
|
+
// only in a form with one reading, a key and a value neither quoted,
|
|
88
|
+
// escaped, cut at a `;` or `#`, nor filled in from the environment, and
|
|
89
|
+
// refused in any other. Three are followed: legacy-peer-deps, engine-strict
|
|
90
|
+
// and bin-links, each true or false. install-strategy is taken as hoisted,
|
|
91
|
+
// lockfile-version as 1, 2 or 3, allow-git, allow-directory, allow-file
|
|
92
|
+
// and allow-remote as all, and install-links, force, dry-run, global,
|
|
93
|
+
// package-lock-only, usage and include-workspace-root as false, and refused
|
|
94
|
+
// otherwise. omit, include, production, dev, only, also, optional, os,
|
|
95
|
+
// cpu, libc, workspace, workspaces, location, umask, prefix, globalconfig,
|
|
96
|
+
// userconfig, allow-scripts and a credential not scoped to a registry are
|
|
97
|
+
// refused, whatever their value; so are two settings npm takes as
|
|
98
|
+
// exclusive, set together, and a section. Any other setting is passed
|
|
99
|
+
// over: npm reads it for where it fetches from, how, what it prints, or
|
|
100
|
+
// another command, and the tree is held to the lockfile's integrities
|
|
101
|
+
// whatever serves it.
|
|
102
|
+
//
|
|
103
|
+
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to
|
|
104
|
+
// be the lockfile's directory, beside whatever it holds, such as the
|
|
105
|
+
// projects themselves — it may be `project` too; without one, a new Vfs
|
|
106
|
+
// holds the tree alone. Nothing the tree is built from is read from it. A
|
|
107
|
+
// Vfs that holds a node_modules anywhere, or on macOS a name that is one
|
|
108
|
+
// there, is refused before anything is fetched: kept beside the tree, Node
|
|
109
|
+
// would read it as the tree's, and removed, it would be the caller's lost.
|
|
110
|
+
// Nothing there is written over: each directory the tree has is one there
|
|
111
|
+
// or is made, and every file and link is written where nothing is. The
|
|
112
|
+
// tree is built, and held to every check below, before any of it is
|
|
113
|
+
// written, so a refusal leaves the Vfs as it was.
|
|
114
|
+
//
|
|
115
|
+
// `metadata`, true unless given false, has each registry package's version
|
|
116
|
+
// document asked for beside its tarball, through getMeta of
|
|
117
|
+
// @preventive/upstream given the lockfile's dist: the one `cache` keeps,
|
|
118
|
+
// where its dist is that one, else the registry's, a request for each name
|
|
119
|
+
// and version. Its dist has to be the lockfile's, the tarball
|
|
120
|
+
// the registry's own URL and the integrity the lockfile's sha512, compared
|
|
121
|
+
// as text, with nothing hashed again, as the lockfile copies the
|
|
122
|
+
// registry's; and its gitHead, repository, homepage and bugs are the
|
|
123
|
+
// package's. False fetches none, and gives none of them.
|
|
124
|
+
//
|
|
125
|
+
// `cache` is where each registry package's tarball and version document
|
|
126
|
+
// are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
|
|
127
|
+
// cache where it is left out; in a store of the caller's, with `read` and
|
|
128
|
+
// `write`, in place of it; or with false, nowhere, though setCacheDir's
|
|
129
|
+
// cache is read all the same. Other tools' caches are read for tarballs
|
|
130
|
+
// whatever it is. A TypeError is thrown for anything else.
|
|
131
|
+
export type NpmTreeOptions = NpmTreeGiven | NpmTreeRead
|
|
132
|
+
|
|
133
|
+
export interface NpmTreeGiven {
|
|
134
|
+
lockfile: string
|
|
135
|
+
manifests: Record<string, string> | Map<string, string>
|
|
136
|
+
npmrc?: string
|
|
137
|
+
project?: undefined
|
|
138
|
+
host: NpmHost
|
|
139
|
+
vfs?: Vfs
|
|
140
|
+
metadata?: boolean
|
|
141
|
+
cache?: CacheOptions['cache']
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface NpmTreeRead {
|
|
145
|
+
lockfile?: undefined
|
|
146
|
+
manifests?: undefined
|
|
147
|
+
npmrc?: undefined
|
|
148
|
+
project: NpmProject
|
|
149
|
+
host: NpmHost
|
|
150
|
+
vfs?: Vfs
|
|
151
|
+
metadata?: boolean
|
|
152
|
+
cache?: CacheOptions['cache']
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// What buildNpmTree counts, all of it plain numbers: `packages` the
|
|
156
|
+
// lockfile's, each a copy in a node_modules; `installed` those in the
|
|
157
|
+
// tree; `skipped` those left out, as the host cannot run them or only such
|
|
158
|
+
// need them; `tarballs` those fetched, each once; `files` and `bytes` what
|
|
159
|
+
// is written; `links` the workspaces linked.
|
|
160
|
+
export interface NpmTreeStats {
|
|
161
|
+
packages: number
|
|
162
|
+
installed: number
|
|
163
|
+
skipped: number
|
|
164
|
+
tarballs: number
|
|
165
|
+
files: number
|
|
166
|
+
bytes: number
|
|
167
|
+
links: number
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// A package in the tree, as an SBOM would list it: `path` is where its
|
|
171
|
+
// files are, the lockfile's key of it, from the lockfile's directory,
|
|
172
|
+
// which is `/` of the Vfs — node_modules/<name>, beneath another package's
|
|
173
|
+
// node_modules, or beneath a workspace's. `name` and `version` are the
|
|
174
|
+
// package's own, whatever alias it is installed as, as the lockfile has
|
|
175
|
+
// them; `integrity` the sha512 its tarball is held to. `commit` is the
|
|
176
|
+
// gitHead of the registry's version document, where `metadata` has it
|
|
177
|
+
// fetched and it is a full commit id, the commit npm read off the checkout
|
|
178
|
+
// it published from; `repository`, `homepage` and `bugs` the document's,
|
|
179
|
+
// as getMeta of @preventive/upstream reads them; each undefined elsewhere,
|
|
180
|
+
// and all of it the publisher's word, held to no repository. The flags are
|
|
181
|
+
// those
|
|
182
|
+
// npm installs by, the lockfile's as npm 10 takes them and as npm 11 works
|
|
183
|
+
// them out again: `dev` is whether dev dependencies alone reach it, which
|
|
184
|
+
// --omit=dev leaves out; `optional` whether optional dependencies alone
|
|
185
|
+
// reach it, which --omit=optional leaves out; `devOptional` whether either
|
|
186
|
+
// is, or both together, which --omit=dev with --omit=optional leaves out;
|
|
187
|
+
// `peer` whether peer dependencies alone reach it, which --omit=peer
|
|
188
|
+
// leaves out.
|
|
189
|
+
export interface NpmInstalled {
|
|
190
|
+
path: string
|
|
191
|
+
name: string
|
|
192
|
+
version: string
|
|
193
|
+
integrity: string
|
|
194
|
+
commit: string | undefined
|
|
195
|
+
repository: string | PackageRepository | undefined
|
|
196
|
+
homepage: string | undefined
|
|
197
|
+
bugs: string | PackageBugs | undefined
|
|
198
|
+
dev: boolean
|
|
199
|
+
optional: boolean
|
|
200
|
+
devOptional: boolean
|
|
201
|
+
peer: boolean
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// `vfs` is the one given, the tree mounted into it, or a new one.
|
|
205
|
+
// `installed` is each package in the tree, in the lockfile's order; a
|
|
206
|
+
// workspace, whose files the tree does not hold, is not among them.
|
|
207
|
+
export interface NpmTree {
|
|
208
|
+
vfs: Vfs
|
|
209
|
+
stats: NpmTreeStats
|
|
210
|
+
installed: NpmInstalled[]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// The node_modules tree `npm ci --ignore-scripts` makes, with host.npm,
|
|
214
|
+
// into a project with no node_modules yet: rooted at the lockfile's
|
|
215
|
+
// directory, each package's files unpacked where the lockfile puts it,
|
|
216
|
+
// and each workspace linked as node_modules/<its name>, by a relative link
|
|
217
|
+
// to its directory, with what the lockfile puts beneath it in that
|
|
218
|
+
// directory's own node_modules. The tree holds node_modules and nothing
|
|
219
|
+
// else of the projects.
|
|
220
|
+
//
|
|
221
|
+
// Each package is unpacked as npm's tar unpacks it: the first segment of
|
|
222
|
+
// each name dropped; a file alone kept, so that a link, a device and a
|
|
223
|
+
// directory entry are passed over and no empty directory is made; each
|
|
224
|
+
// file's mode the tarball's with read and write for all added, and a umask
|
|
225
|
+
// of 0o022 then taken off, so that its execute bits stay; and a .gitignore
|
|
226
|
+
// renamed .npmignore, and dropped where a .npmignore came before it in its
|
|
227
|
+
// directory, or, where one comes after it, holding the second's bytes with
|
|
228
|
+
// the first's mode. Directories are 0o755.
|
|
229
|
+
//
|
|
230
|
+
// Scripts are always ignored, as `--ignore-scripts` has npm ignore them,
|
|
231
|
+
// whatever the settings say; npm 10 runs a workspace's prepare script all
|
|
232
|
+
// the same, and one with a prepare script is refused for it. No .bin is
|
|
233
|
+
// written, nor npm's own node_modules/.package-lock.json; but each bin's
|
|
234
|
+
// target is changed as linking it changes it, unless bin-links is false:
|
|
235
|
+
// of the bins the lockfile gives the packages of one node_modules, the
|
|
236
|
+
// first of each name, as npm sorts its packages by path, is linked, and its
|
|
237
|
+
// target, where the package has it, made 0o755, and the CR dropped from a
|
|
238
|
+
// first line in its first 2048 bytes that is a shebang ending in CRLF. A
|
|
239
|
+
// target that is a directory, runs through a file, or is in the package's
|
|
240
|
+
// own node_modules is refused, and one with such a line that is not UTF-8,
|
|
241
|
+
// which npm rewrites with replacement characters. A workspace's bins are
|
|
242
|
+
// its own files, which the tree does not hold; one in the workspace's own
|
|
243
|
+
// node_modules, or by directories.bin, is refused. So is the root's
|
|
244
|
+
// allowScripts, which npm 11.16 and later read for whose bins to link.
|
|
245
|
+
//
|
|
246
|
+
// npm 10 leaves out an optional package the host cannot run only once it
|
|
247
|
+
// has made directories for every package, and so leaves the directories
|
|
248
|
+
// it was in, a scope's or another package's node_modules, which the tree
|
|
249
|
+
// has too, empty. Of what only such a package needs, npm 11.13 and later
|
|
250
|
+
// leave out too what another left out needs as well. The tar of npm 10.9.9
|
|
251
|
+
// and 11.18 on gives up on a tarball that inflates more than 1000 times
|
|
252
|
+
// what it has read at any point, which is refused where it may, with a
|
|
253
|
+
// margin, as where it checks depends on how the bytes come.
|
|
254
|
+
//
|
|
255
|
+
// The lockfile is held to what the lockfile reader holds it to, with the
|
|
256
|
+
// flags npm installs by: npm 11 works them out again at every install, and
|
|
257
|
+
// npm 10 takes them as written, unless the root package.json asks for
|
|
258
|
+
// other than the lockfile's entry of it to the letter, as one asking for a
|
|
259
|
+
// name in two lists, or for a workspace by name too, does. Each project's
|
|
260
|
+
// package.json is held to the lockfile's entry of its directory: the same
|
|
261
|
+
// names asked for, in the same lists, by the same specs, as npm ci would
|
|
262
|
+
// otherwise resolve them anew or refuse; and each workspace to the name
|
|
263
|
+
// and version the lockfile gives it. The root's devEngines are checked as
|
|
264
|
+
// npm checks them, against the host, which has no os version to check.
|
|
265
|
+
// Refused too, as npm's releases read them otherwise: a range with a
|
|
266
|
+
// wildcard before a number, `1.x.0`, and for npm 10 an optional peer the
|
|
267
|
+
// lockfile does not meet by a range, which it resolves again.
|
|
268
|
+
//
|
|
269
|
+
// And to more than npm holds it to, where a lockfile npm writes, or a
|
|
270
|
+
// package the registry serves, always holds: each tarball gzipped, every
|
|
271
|
+
// entry under one directory, named as tar reads it, with no `\` and no
|
|
272
|
+
// more than 1024 segments, none in the package's own node_modules, where
|
|
273
|
+
// npm installs its dependencies, no setuid, setgid or sticky bit, no link
|
|
274
|
+
// name on a file, no global pax header, and no pax size with a long name, a
|
|
275
|
+
// long link or a global header between it and its entry, which tar's
|
|
276
|
+
// releases read otherwise; each with the sha512 integrity the lockfile
|
|
277
|
+
// records. A pax size is taken over the header's, as every tar release
|
|
278
|
+
// takes it; npm's tar writes one into each pax header it packs, as for a
|
|
279
|
+
// name ustar cannot hold. On
|
|
280
|
+
// macOS, two names in one directory that differ only in case or
|
|
281
|
+
// normalization are refused, as they would be one name there.
|
|
282
|
+
//
|
|
283
|
+
// Packages come from npm's registry alone: each lockfile entry's
|
|
284
|
+
// `resolved` has to be the registry's own URL of its tarball,
|
|
285
|
+
// https://registry.npmjs.org/<name>/-/<base>-<version>.tgz, a scope's `/`
|
|
286
|
+
// as `%2f` or not, or that same URL on yarn's mirror,
|
|
287
|
+
// https://registry.yarnpkg.com/, which is taken for npm's; it is fetched
|
|
288
|
+
// from npm's through @preventive/upstream.
|
|
289
|
+
//
|
|
290
|
+
// Ranges and versions are read with npm's own semver, borrowed from the
|
|
291
|
+
// npm beside node as @preventive/upstream borrows it, or with its semver
|
|
292
|
+
// peer where there is no npm, without either of which this throws.
|
|
293
|
+
//
|
|
294
|
+
// Nothing is left to a guess: a lockfile the lockfile reader refuses, a
|
|
295
|
+
// setting this does not know or does not build for, a package from
|
|
296
|
+
// anywhere but the registry — git, a tarball's URL or one on disk, a
|
|
297
|
+
// directory by `file:` — or with no resolved URL, which npm fetches by the
|
|
298
|
+
// registry's packument, a package bundled in another, a link but to a
|
|
299
|
+
// workspace, overrides, acceptDependencies, a check above that fails —
|
|
300
|
+
// each is refused with a DeptreeError or a LockfileError that says where.
|
|
301
|
+
// A TypeError is thrown for options of the wrong type.
|
|
302
|
+
export function buildNpmTree(options: NpmTreeOptions): Promise<NpmTree>
|
|
303
|
+
|
|
304
|
+
// The directories of the projects npm finds in `project`, by which
|
|
305
|
+
// buildNpmTree takes their package.json given: `.`, the root, first, then
|
|
306
|
+
// each directory with a package.json that a glob of the root's
|
|
307
|
+
// `workspaces` takes, outside node_modules, as npm finds them, and as
|
|
308
|
+
// buildNpmTree reads them from a project; with `os` darwin, whatever the
|
|
309
|
+
// case, as npm's glob matches on macOS. Refused as buildNpmTree refuses
|
|
310
|
+
// it: a link where the globs reach; and a root with no package.json.
|
|
311
|
+
export interface NpmWorkspacesOptions {
|
|
312
|
+
project: NpmProject
|
|
313
|
+
os?: string
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function findNpmWorkspaces(options: NpmWorkspacesOptions): string[]
|
|
317
|
+
|
|
318
|
+
// `where` is what a refusal is about — `.npmrc:3`, `manifests["."]`, a
|
|
319
|
+
// lockfile entry, `packages["node_modules/a"]` — or undefined for the call
|
|
320
|
+
// as a whole; the message leads with it. `cause` is what a package beneath
|
|
321
|
+
// refused with, where one did.
|
|
322
|
+
export class DeptreeError extends Error {
|
|
323
|
+
constructor(detail: string, where?: string, options?: { cause?: unknown })
|
|
324
|
+
where: string | undefined
|
|
325
|
+
}
|
package/npm.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// A node_modules tree built in memory from a package-lock.json, as npm 10
|
|
2
|
+
// or 11 installs it with `npm ci`; see npm.d.ts.
|
|
3
|
+
export { buildNpmTree } from './src/npm/tree.js'
|
|
4
|
+
export { findNpmWorkspaces } from './src/npm/inputs.js'
|
|
5
|
+
export { DeptreeError } from './src/error.js'
|
|
6
|
+
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
7
|
+
export { LockfileError } from '@preventive/lockfile/npm.js'
|