@preventive/deptree 1.5.2 → 1.5.4
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 +10 -21
- package/bin/deptree.js +5 -10
- package/cargo.d.ts +139 -195
- package/cargo.js +0 -2
- package/cocoapods.d.ts +211 -381
- package/cocoapods.js +0 -2
- package/npm.d.ts +245 -369
- package/npm.js +4 -6
- package/package.json +1 -1
- package/pnpm.d.ts +258 -667
- package/pnpm.js +2 -4
- package/soldeer.d.ts +144 -215
- package/soldeer.js +0 -2
- package/src/cargo/crate.js +21 -46
- package/src/cargo/inputs.js +5 -8
- package/src/cargo/members.js +6 -12
- package/src/cargo/registry.js +5 -9
- package/src/cargo/tree.js +8 -13
- package/src/cargo/workspace.js +13 -26
- package/src/cocoapods/archive.js +19 -40
- package/src/cocoapods/clean.js +21 -45
- package/src/cocoapods/fnmatch.js +12 -27
- package/src/cocoapods/inputs.js +5 -11
- package/src/cocoapods/install.js +11 -24
- package/src/cocoapods/podspec.js +19 -40
- package/src/cocoapods/podtree.js +10 -19
- package/src/cocoapods/source.js +13 -30
- package/src/cocoapods/tree.js +17 -39
- package/src/cocoapods/unicode.js +3 -9
- package/src/github.js +12 -24
- package/src/glob.js +2 -4
- package/src/lazy.js +2 -4
- package/src/manifest.js +2 -4
- package/src/matcher.js +3 -5
- package/src/mount.js +7 -14
- package/src/npm/bins.js +3 -5
- package/src/npm/compat.js +3 -5
- package/src/npm/package.js +13 -14
- package/src/npm/ratio.js +3 -5
- package/src/npm/settings.js +3 -5
- package/src/npm/tree.js +6 -11
- package/src/npm/versions.js +3 -4
- package/src/npmrc.js +2 -4
- package/src/patch.js +8 -14
- package/src/pnpm/bins.js +16 -42
- package/src/pnpm/filename.js +2 -4
- package/src/pnpm/gitignore.js +2 -4
- package/src/pnpm/glob.js +3 -5
- package/src/pnpm/hoist.js +8 -16
- package/src/pnpm/hoisted.js +15 -44
- package/src/pnpm/hook.js +2 -4
- package/src/pnpm/install.js +5 -10
- package/src/pnpm/lazy.js +8 -23
- package/src/pnpm/local.js +2 -4
- package/src/pnpm/minimatch.js +8 -15
- package/src/pnpm/nm-hoist.js +5 -11
- package/src/pnpm/npm-packlist.js +3 -6
- package/src/pnpm/overrides.js +2 -4
- package/src/pnpm/package.js +10 -16
- package/src/pnpm/packlist.js +3 -7
- package/src/pnpm/patches.js +3 -4
- package/src/pnpm/production.js +9 -28
- package/src/pnpm/projects.js +2 -6
- package/src/pnpm/readers.js +2 -4
- package/src/pnpm/settings.js +2 -5
- package/src/pnpm/tree.js +14 -37
- package/src/pnpm/workspace.js +4 -7
- package/src/pnpm/write.js +1 -1
- package/src/soldeer/config.js +5 -9
- package/src/soldeer/tree.js +2 -4
- package/src/soldeer/zip.js +8 -17
- package/src/tarball.js +12 -29
- package/src/yarn1/compat.js +2 -4
- package/src/yarn1/hoist.js +3 -8
- package/src/yarn1/package.js +12 -23
- package/src/yarn1/resolve.js +6 -11
- package/src/yarn1/settings.js +5 -10
- package/src/yarn1/tree.js +9 -18
- package/yarn1.d.ts +203 -360
- package/yarn1.js +4 -6
package/npm.d.ts
CHANGED
|
@@ -1,410 +1,286 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A node_modules tree built in memory from a package-lock.json, as npm 10 or 11 installs it with `npm ci`
|
|
3
|
+
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { buildNpmTree, findNpmWorkspaces } from '@preventive/deptree/npm.js'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Nothing is left to a guess: a lockfile the reader refuses, a setting not followed, a package from
|
|
9
|
+
* anywhere but the registry (git, another tarball, a directory by `file:`) or with no resolved URL, a
|
|
10
|
+
* bundled package, a link but to a workspace, overrides, acceptDependencies, or a check that fails is
|
|
11
|
+
* refused with a DeptreeError or a LockfileError saying where. Options of the wrong type throw a TypeError.
|
|
12
|
+
*
|
|
13
|
+
* @module @preventive/deptree/npm.js
|
|
14
|
+
*/
|
|
3
15
|
|
|
4
|
-
|
|
16
|
+
import type { CacheOptions, PackageBugs, PackageRepository } from '@preventive/upstream/npm.js';
|
|
17
|
+
import type { NodeType, Vfs } from '@preventive/vfs';
|
|
5
18
|
|
|
6
|
-
|
|
7
|
-
// Tarballs are fetched through it, and that is the one place anything here
|
|
8
|
-
// touches a filesystem. Before the network, it takes a tarball from npm's
|
|
9
|
-
// cache -- under $npm_config_cache, or ~/.npm -- from ~/.audit/cache/tgz, or
|
|
10
|
-
// from its own default cache directory or stasis's, where one there has the
|
|
11
|
-
// lockfile's integrity, and writes none of them; then from its own cache,
|
|
12
|
-
// where one is set, which is where it writes each tarball it fetches:
|
|
13
|
-
// setCacheDir() sets the default one, and setCacheDir(false) unsets it.
|
|
14
|
-
// Unset, which it is until set, it writes nothing. The project is read
|
|
15
|
-
// only through the view given as `project`, and the tree built in a Vfs.
|
|
16
|
-
export { setCacheDir } from '@preventive/upstream/npm.js'
|
|
19
|
+
export { LockfileError } from '@preventive/lockfile/npm.js';
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Sets where @preventive/upstream caches what it fetches, which is unset until set
|
|
23
|
+
*
|
|
24
|
+
* Tarballs are fetched through it, the one place anything here touches a filesystem: before the network
|
|
25
|
+
* it reads npm's cache, ~/.audit/cache/tgz and its own or stasis's default directory for one of the
|
|
26
|
+
* lockfile's integrity, writing none of them, then this one, which it writes each tarball it fetches to.
|
|
27
|
+
* `setCacheDir()` sets the default directory and `setCacheDir(false)` unsets it.
|
|
28
|
+
*/
|
|
29
|
+
export { setCacheDir } from '@preventive/upstream/npm.js';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The machine npm would install on; Windows is refused, as npm links bins there with shims
|
|
33
|
+
*
|
|
34
|
+
* A package whose os, cpu, libc or engines the host does not take is left out where npm takes it as
|
|
35
|
+
* optional, with what npm leaves out with it. One not optional is refused where its platform is not the
|
|
36
|
+
* host's, as npm fails on it, and installed where its engines are not, as npm warns, unless engine-strict
|
|
37
|
+
* is set; so for the root and each workspace. A libc a package names fails a host with none.
|
|
38
|
+
*/
|
|
36
39
|
export interface NpmHost {
|
|
37
|
-
npm:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
/** The npm that installs, exact: 10.9.3 to 10.9.9, or 11.11.1 to 11.21.0; no packageManager is read */
|
|
41
|
+
npm: string;
|
|
42
|
+
/** The Node npm runs on, exact, or left out for one unknown, which every engines.node and devEngines takes */
|
|
43
|
+
node?: string;
|
|
44
|
+
/** As Node names it, such as `linux` */
|
|
45
|
+
os: string;
|
|
46
|
+
/** As Node names it, such as `x64` */
|
|
47
|
+
cpu: string;
|
|
48
|
+
/** The C library npm finds on Linux, and left out elsewhere */
|
|
49
|
+
libc?: 'glibc' | 'musl';
|
|
42
50
|
}
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// whose `code` is ENOENT, ENOTDIR or ELOOP for a path that leads nowhere.
|
|
50
|
-
// Nothing is written to it.
|
|
52
|
+
/**
|
|
53
|
+
* A view of the lockfile's directory by paths from `/`, such as a Vfs; nothing is written to it
|
|
54
|
+
*
|
|
55
|
+
* Each method throws an error whose `code` is ENOENT, ENOTDIR or ELOOP for a path that leads nowhere.
|
|
56
|
+
*/
|
|
51
57
|
export interface NpmProject {
|
|
52
|
-
readdir(path: string): string[]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
readdir(path: string): string[];
|
|
59
|
+
/** What a path is */
|
|
60
|
+
lstat(path: string): { type: NodeType };
|
|
61
|
+
/** What a path leads to */
|
|
62
|
+
stat(path: string): { type: NodeType };
|
|
63
|
+
readFile(path: string): Uint8Array;
|
|
56
64
|
}
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// read, and are taken to be at their defaults; so is the directory npm is
|
|
80
|
-
// run in, taken to be the lockfile's, with no workspace above it.
|
|
81
|
-
//
|
|
82
|
-
// Of the .npmrc, as npm reads it: npm hands the install each setting as
|
|
83
|
-
// ini reads it, before it checks it, so `bin-links=0` links bins, "0" being
|
|
84
|
-
// a truthy string. A setting that can change what npm installs is read
|
|
85
|
-
// only in a form with one reading, a key and a value neither quoted,
|
|
86
|
-
// escaped, cut at a `;` or `#`, nor filled in from the environment, and
|
|
87
|
-
// refused in any other. Three are followed: legacy-peer-deps, engine-strict
|
|
88
|
-
// and bin-links, each true or false. install-strategy is taken as hoisted,
|
|
89
|
-
// lockfile-version as 1, 2 or 3, allow-git, allow-directory, allow-file
|
|
90
|
-
// and allow-remote as all, and install-links, force, dry-run, global,
|
|
91
|
-
// package-lock-only, usage and include-workspace-root as false, and refused
|
|
92
|
-
// otherwise. omit, include, production, dev, only, also, optional, os,
|
|
93
|
-
// cpu, libc, workspace, workspaces, location, umask, prefix, globalconfig,
|
|
94
|
-
// userconfig, allow-scripts and a credential not scoped to a registry are
|
|
95
|
-
// refused, whatever their value, which of the dependencies are installed
|
|
96
|
-
// being `production`'s to say; so are two settings npm takes as
|
|
97
|
-
// exclusive, set together, and a section. Any other setting is passed
|
|
98
|
-
// over: npm reads it for where it fetches from, how, what it prints, or
|
|
99
|
-
// another command, and the tree is held to the lockfile's integrities
|
|
100
|
-
// whatever serves it.
|
|
101
|
-
//
|
|
102
|
-
// `vfs` is a Vfs to mount the tree into, at its root, which is taken to
|
|
103
|
-
// be the lockfile's directory, beside whatever it holds, such as the
|
|
104
|
-
// projects themselves -- it may be `project` too; without one, a new Vfs
|
|
105
|
-
// holds the tree alone. Nothing the tree is built from is read from it. A
|
|
106
|
-
// Vfs that holds a node_modules anywhere, or on macOS a name that is one
|
|
107
|
-
// there, is refused before anything is fetched: kept beside the tree, Node
|
|
108
|
-
// would read it as the tree's, and removed, it would be the caller's lost.
|
|
109
|
-
// Nothing there is written over: each directory the tree has is one there
|
|
110
|
-
// or is made, and every file and link is written where nothing is. The
|
|
111
|
-
// tree is built, and held to every check below, before any of it is
|
|
112
|
-
// written, so a refusal leaves the Vfs as it was.
|
|
113
|
-
//
|
|
114
|
-
// `metadata`, true unless given false, has each registry package's version
|
|
115
|
-
// document asked for beside its tarball, through getMeta of
|
|
116
|
-
// @preventive/upstream given the lockfile's dist: the one `cache` keeps,
|
|
117
|
-
// where its dist is that one, else the registry's, a request for each name
|
|
118
|
-
// and version. Its dist has to be the lockfile's, the tarball
|
|
119
|
-
// the registry's own URL and the integrity the lockfile's sha512, compared
|
|
120
|
-
// as text, with nothing hashed again, as the lockfile copies the
|
|
121
|
-
// registry's; and its gitHead, repository, homepage and bugs are the
|
|
122
|
-
// package's. False fetches none, and gives none of them.
|
|
123
|
-
//
|
|
124
|
-
// `cache` is where each registry package's tarball and version document
|
|
125
|
-
// are kept, as @preventive/upstream's CacheOptions take it: in setCacheDir's
|
|
126
|
-
// cache where it is left out; in a store of the caller's, with `read` and
|
|
127
|
-
// `write`, in place of it; or with false, nowhere, though setCacheDir's
|
|
128
|
-
// cache is read all the same. Other tools' caches are read for tarballs
|
|
129
|
-
// whatever it is. A TypeError is thrown for anything else.
|
|
130
|
-
//
|
|
131
|
-
// `sizeEstimateOnly`, false unless given true, builds the tree's directories
|
|
132
|
-
// and links alone, and fetches no tarball: each package's directory is made
|
|
133
|
-
// where the lockfile puts it, and left empty, and each link is made as it is.
|
|
134
|
-
// Each package's version document is asked for as `metadata` asks for it,
|
|
135
|
-
// whatever `metadata` says, and held to the lockfile's dist as it is held
|
|
136
|
-
// there; and each package is listed with its `size`, the document's
|
|
137
|
-
// dist.unpackedSize, as getMeta of @preventive/upstream reads it: the bytes
|
|
138
|
-
// of the files in its tarball, as the registry counted them when it was
|
|
139
|
-
// published, which is what npm writes of it, but for a .gitignore it drops
|
|
140
|
-
// and a CRLF `#!` line of a bin it rewrites; not the blocks they take. It is
|
|
141
|
-
// undefined where the document names none. What is checked of a package's
|
|
142
|
-
// tarball and files is not, so a lockfile one of those checks would refuse is
|
|
143
|
-
// laid out all the same. A `vfs` is not taken with it.
|
|
144
|
-
//
|
|
145
|
-
// `lazy`, false unless given true, lays the tree out as sizeEstimateOnly
|
|
146
|
-
// does, each package's directory made and left empty and each link made,
|
|
147
|
-
// but fetches nothing, not even a version document: each package is
|
|
148
|
-
// unpacked into it once asked for by the tree's `unpack`, and only then
|
|
149
|
-
// fetched, as `metadata` and `cache` say. A package unpacked is what the
|
|
150
|
-
// full tree has at its path, file for file, with the bins it links fixed,
|
|
151
|
-
// which the lockfile alone tells, and held to every check of its tarball and
|
|
152
|
-
// files the full tree holds it to; one never asked for is never fetched, so
|
|
153
|
-
// a lockfile one of those checks would refuse is laid out all the same, and
|
|
154
|
-
// refused where that package is unpacked. A `vfs` is not taken with it, nor
|
|
155
|
-
// `sizeEstimateOnly`.
|
|
156
|
-
//
|
|
157
|
-
// `production`, false unless given true, builds the tree `npm ci
|
|
158
|
-
// --omit=dev` makes: each package the lockfile's flags, as npm takes them,
|
|
159
|
-
// say dev dependencies alone reach is left out, as is what is beneath it,
|
|
160
|
-
// and its bins are linked by none of its names. npm 10 makes every
|
|
161
|
-
// package's directory before it leaves those out, and so leaves the
|
|
162
|
-
// directories they were in, a scope's or a workspace's node_modules, which
|
|
163
|
-
// the tree has too, empty; it holds each of them that is not optional to
|
|
164
|
-
// the host as without it, and leaves out nothing for one that is and that
|
|
165
|
-
// the host cannot run. npm 11 holds to the host none of them but those that
|
|
166
|
-
// are optional, each left out with its optionalSet where the host cannot
|
|
167
|
-
// run it, as without it. A workspace is linked all the same.
|
|
168
|
-
export type NpmTreeOptions = NpmTreeGiven | NpmTreeRead
|
|
66
|
+
/**
|
|
67
|
+
* The files `npm ci` reads, either given as text or read from `project`
|
|
68
|
+
*
|
|
69
|
+
* Read, they are package-lock.json and the root's package.json, which have to be there; the package.json
|
|
70
|
+
* of each directory the root's `workspaces` globs take, outside node_modules and on macOS whatever the case;
|
|
71
|
+
* and the .npmrc. Each is UTF-8, and a refusal names it as it would given: `manifests["packages/x"]`.
|
|
72
|
+
* Refused there: an npm-shrinkwrap.json, and a link the globs reach. Settings from anywhere else, NODE_ENV
|
|
73
|
+
* among them, are taken at their defaults, and npm as run in the lockfile's directory.
|
|
74
|
+
*
|
|
75
|
+
* Of the .npmrc, as ini reads it before npm checks it (`bin-links=0` links bins): a setting that can change
|
|
76
|
+
* what npm installs is read only as a bare key and value, neither quoted, escaped, cut at `;` or `#`, nor
|
|
77
|
+
* taken from the environment. legacy-peer-deps, engine-strict and bin-links are followed, true or false;
|
|
78
|
+
* install-strategy has to be hoisted, lockfile-version 1, 2 or 3, the allow-* settings all, and
|
|
79
|
+
* install-links, force, dry-run, global, package-lock-only, usage and include-workspace-root false. omit,
|
|
80
|
+
* include, production, dev, optional, os, cpu, libc, workspace, location, umask, prefix, the config paths,
|
|
81
|
+
* allow-scripts, an unscoped credential, two exclusive settings together and a section are refused; any
|
|
82
|
+
* other setting is passed over, as npm reads it for where it fetches from, how, or what it prints.
|
|
83
|
+
*/
|
|
84
|
+
export type NpmTreeOptions = NpmTreeGiven | NpmTreeRead;
|
|
85
|
+
|
|
86
|
+
export type NpmLayoutOptions = NpmTreeOptions & { sizeEstimateOnly: true; vfs?: undefined };
|
|
169
87
|
|
|
170
|
-
export type
|
|
88
|
+
export type NpmLazyOptions = NpmTreeOptions & { lazy: true; sizeEstimateOnly?: false; vfs?: undefined };
|
|
171
89
|
|
|
172
|
-
|
|
90
|
+
interface NpmTreeShared {
|
|
91
|
+
host: NpmHost;
|
|
92
|
+
/**
|
|
93
|
+
* A Vfs to mount the tree into, at the lockfile's directory, beside what it holds (default: a new one)
|
|
94
|
+
*
|
|
95
|
+
* One holding a node_modules, or on macOS a name that is one there, is refused before anything is
|
|
96
|
+
* fetched. Nothing there is written over, and the tree is built and checked first, so a refusal leaves
|
|
97
|
+
* it as it was. Not taken with `sizeEstimateOnly` or `lazy`.
|
|
98
|
+
*/
|
|
99
|
+
vfs?: Vfs;
|
|
100
|
+
/**
|
|
101
|
+
* Fetch each registry package's version document by @preventive/upstream's getMeta, its dist held to the
|
|
102
|
+
* lockfile's, for `commit`, `repository`, `homepage` and `bugs` (default: true)
|
|
103
|
+
*/
|
|
104
|
+
metadata?: boolean;
|
|
105
|
+
/** Where tarballs and version documents are kept, as @preventive/upstream's CacheOptions take it */
|
|
106
|
+
cache?: CacheOptions['cache'];
|
|
107
|
+
/**
|
|
108
|
+
* Build the directories and links alone, fetching each package's version document and no tarball, and
|
|
109
|
+
* list each package with its `size` (default: false)
|
|
110
|
+
*
|
|
111
|
+
* `size` is the document's dist.unpackedSize, the bytes of its files as the registry counted them, or
|
|
112
|
+
* undefined. A package's tarball and files go unchecked, so a lockfile those checks refuse is laid out.
|
|
113
|
+
*/
|
|
114
|
+
sizeEstimateOnly?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Build the directories and links alone, fetching nothing, each package unpacked once the tree's
|
|
117
|
+
* `unpack` asks for it, and fetched only then (default: false)
|
|
118
|
+
*
|
|
119
|
+
* An unpacked package is what the full tree has, file for file, with the bins it links fixed, and held
|
|
120
|
+
* to every check the full tree holds it to; one never asked for is never fetched, nor refused.
|
|
121
|
+
*/
|
|
122
|
+
lazy?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* The tree `--omit=dev` makes: each package only dev dependencies reach by the lockfile's flags left out,
|
|
125
|
+
* with what is beneath it (default: false)
|
|
126
|
+
*
|
|
127
|
+
* npm 10 makes every directory before it leaves those out, leaving the directories they were in empty,
|
|
128
|
+
* and holds each not optional to the host as without it; npm 11 holds to the host only the optional.
|
|
129
|
+
*/
|
|
130
|
+
production?: boolean;
|
|
131
|
+
}
|
|
173
132
|
|
|
174
|
-
export interface NpmTreeGiven {
|
|
175
|
-
lockfile: string
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
sizeEstimateOnly?: boolean
|
|
184
|
-
lazy?: boolean
|
|
185
|
-
production?: boolean
|
|
133
|
+
export interface NpmTreeGiven extends NpmTreeShared {
|
|
134
|
+
lockfile: string;
|
|
135
|
+
/**
|
|
136
|
+
* Each project's package.json by its directory from the lockfile's, `.` for the root, as
|
|
137
|
+
* findNpmWorkspaces lists them: every workspace npm would find, and those alone
|
|
138
|
+
*/
|
|
139
|
+
manifests: Record<string, string> | Map<string, string>;
|
|
140
|
+
npmrc?: string;
|
|
141
|
+
project?: undefined;
|
|
186
142
|
}
|
|
187
143
|
|
|
188
|
-
export interface NpmTreeRead {
|
|
189
|
-
lockfile?: undefined
|
|
190
|
-
manifests?: undefined
|
|
191
|
-
npmrc?: undefined
|
|
192
|
-
project: NpmProject
|
|
193
|
-
host: NpmHost
|
|
194
|
-
vfs?: Vfs
|
|
195
|
-
metadata?: boolean
|
|
196
|
-
cache?: CacheOptions['cache']
|
|
197
|
-
sizeEstimateOnly?: boolean
|
|
198
|
-
lazy?: boolean
|
|
199
|
-
production?: boolean
|
|
144
|
+
export interface NpmTreeRead extends NpmTreeShared {
|
|
145
|
+
lockfile?: undefined;
|
|
146
|
+
manifests?: undefined;
|
|
147
|
+
npmrc?: undefined;
|
|
148
|
+
project: NpmProject;
|
|
200
149
|
}
|
|
201
150
|
|
|
202
|
-
|
|
203
|
-
// lockfile's, each a copy in a node_modules; `installed` those in the
|
|
204
|
-
// tree; `skipped` those left out, as the host cannot run them or only such
|
|
205
|
-
// need them; `tarballs` those fetched, each once; `files` and `bytes` what
|
|
206
|
-
// is written; `links` the workspaces linked. With `sizeEstimateOnly`,
|
|
207
|
-
// `tarballs` counts those fetched by their version document alone; `files`
|
|
208
|
-
// is 0, as none is written, and `bytes` what the sizes of those installed
|
|
209
|
-
// add up to, each copy's, of those with one. With `lazy`, `tarballs`,
|
|
210
|
-
// `files` and `bytes` count what is unpacked, each 0 until `unpack` is
|
|
211
|
-
// asked, which adds to them. With `production`, those it leaves out are
|
|
212
|
-
// counted in neither `installed` nor `skipped`.
|
|
151
|
+
/** What buildNpmTree counts */
|
|
213
152
|
export interface NpmTreeStats {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
153
|
+
/** The lockfile's, each a copy in a node_modules */
|
|
154
|
+
packages: number;
|
|
155
|
+
/** Those in the tree */
|
|
156
|
+
installed: number;
|
|
157
|
+
/** Those left out as the host cannot run them, or only such need them; not those `production` leaves out */
|
|
158
|
+
skipped: number;
|
|
159
|
+
/** Those fetched, each once; with `sizeEstimateOnly` by their document, with `lazy` as unpacked */
|
|
160
|
+
tarballs: number;
|
|
161
|
+
/** Written; 0 with `sizeEstimateOnly`, and with `lazy` as unpacked */
|
|
162
|
+
files: number;
|
|
163
|
+
/** Written; with `sizeEstimateOnly` the sizes of those installed, with `lazy` as unpacked */
|
|
164
|
+
bytes: number;
|
|
165
|
+
/** The workspaces linked */
|
|
166
|
+
links: number;
|
|
221
167
|
}
|
|
222
168
|
|
|
223
|
-
|
|
224
|
-
// files are, the lockfile's key of it, from the lockfile's directory,
|
|
225
|
-
// which is `/` of the Vfs -- node_modules/<name>, beneath another package's
|
|
226
|
-
// node_modules, or beneath a workspace's. `name` and `version` are the
|
|
227
|
-
// package's own, whatever alias it is installed as, as the lockfile has
|
|
228
|
-
// them; `integrity` the sha512 its tarball is held to. `commit` is the
|
|
229
|
-
// gitHead of the registry's version document, where `metadata` has it
|
|
230
|
-
// fetched and it is a full commit id, the commit npm read off the checkout
|
|
231
|
-
// it published from; `repository`, `homepage` and `bugs` the document's,
|
|
232
|
-
// as getMeta of @preventive/upstream reads them; each undefined elsewhere,
|
|
233
|
-
// and all of it the publisher's word, held to no repository. The flags are
|
|
234
|
-
// those
|
|
235
|
-
// npm installs by, the lockfile's as npm 10 takes them and as npm 11 works
|
|
236
|
-
// them out again: `dev` is whether dev dependencies alone reach it, which
|
|
237
|
-
// --omit=dev leaves out, and so none is with `production`; `optional`
|
|
238
|
-
// whether optional dependencies alone
|
|
239
|
-
// reach it, which --omit=optional leaves out; `devOptional` whether either
|
|
240
|
-
// is, or both together, which --omit=dev with --omit=optional leaves out;
|
|
241
|
-
// `peer` whether peer dependencies alone reach it, which --omit=peer
|
|
242
|
-
// leaves out.
|
|
169
|
+
/** A package in the tree, as an SBOM would list it */
|
|
243
170
|
export interface NpmInstalled {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
171
|
+
/** Where its files are, the lockfile's key of it, from the lockfile's directory */
|
|
172
|
+
path: string;
|
|
173
|
+
/** The package's own, whatever alias it is installed as */
|
|
174
|
+
name: string;
|
|
175
|
+
version: string;
|
|
176
|
+
/** The sha512 its tarball is held to */
|
|
177
|
+
integrity: string;
|
|
178
|
+
/** Its version document's gitHead, where fetched and a full commit id: the publisher's word */
|
|
179
|
+
commit: string | undefined;
|
|
180
|
+
/** Its version document's, as getMeta reads it, where fetched; held to no repository */
|
|
181
|
+
repository: string | PackageRepository | undefined;
|
|
182
|
+
homepage: string | undefined;
|
|
183
|
+
bugs: string | PackageBugs | undefined;
|
|
184
|
+
/** Whether only dev dependencies reach it, as --omit=dev leaves out; none with `production` */
|
|
185
|
+
dev: boolean;
|
|
186
|
+
/** Whether only optional dependencies reach it, as --omit=optional leaves out */
|
|
187
|
+
optional: boolean;
|
|
188
|
+
/** Whether either does, or both together, as --omit=dev with --omit=optional leaves out */
|
|
189
|
+
devOptional: boolean;
|
|
190
|
+
/** Whether only peer dependencies reach it, as --omit=peer leaves out */
|
|
191
|
+
peer: boolean;
|
|
256
192
|
}
|
|
257
193
|
|
|
258
|
-
// `vfs` is the one given, the tree mounted into it, or a new one.
|
|
259
|
-
// `installed` is each package in the tree, in the lockfile's order; a
|
|
260
|
-
// workspace, whose files the tree does not hold, is not among them.
|
|
261
194
|
export interface NpmTree {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
195
|
+
/** The Vfs given, the tree mounted into it, or a new one */
|
|
196
|
+
vfs: Vfs;
|
|
197
|
+
stats: NpmTreeStats;
|
|
198
|
+
/** Each package in the tree, in the lockfile's order; no workspace, whose files the tree does not hold */
|
|
199
|
+
installed: NpmInstalled[];
|
|
265
200
|
}
|
|
266
201
|
|
|
267
|
-
// With `sizeEstimateOnly`, each package as `installed` lists it, with its
|
|
268
|
-
// `size`.
|
|
269
202
|
export interface NpmLaidOut extends NpmInstalled {
|
|
270
|
-
|
|
203
|
+
/** dist.unpackedSize, or undefined where the document names none */
|
|
204
|
+
size: number | undefined;
|
|
271
205
|
}
|
|
272
206
|
|
|
273
|
-
|
|
274
|
-
// links.
|
|
207
|
+
/** With `sizeEstimateOnly`: a new Vfs of the tree's directories and links */
|
|
275
208
|
export interface NpmLayout {
|
|
276
|
-
vfs: Vfs
|
|
277
|
-
stats: NpmTreeStats
|
|
278
|
-
installed: NpmLaidOut[]
|
|
209
|
+
vfs: Vfs;
|
|
210
|
+
stats: NpmTreeStats;
|
|
211
|
+
installed: NpmLaidOut[];
|
|
279
212
|
}
|
|
280
213
|
|
|
281
|
-
|
|
282
|
-
// `unpack` writes each package's files into; `installed` each package, with
|
|
283
|
-
// nothing its version document says, as none is fetched. `unpack` takes the
|
|
284
|
-
// paths of packages as `installed` lists them, and resolves once each is
|
|
285
|
-
// unpacked, to their entries in that order, with what each one's version
|
|
286
|
-
// document says where `metadata` has it fetched. Each is unpacked once,
|
|
287
|
-
// however often and at once it is asked for, and a few tarballs are fetched at
|
|
288
|
-
// a time; each is written whole or not at all, and one refused rejects the
|
|
289
|
-
// call, and each call that asks for it after, with the DeptreeError the full
|
|
290
|
-
// tree is refused with, once every package the call asks for is done. A path
|
|
291
|
-
// the tree installs no package at is a TypeError.
|
|
214
|
+
/** With `lazy`: a new Vfs of the tree's directories and links, and nothing a version document says yet */
|
|
292
215
|
export interface NpmLazyTree extends NpmTree {
|
|
293
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Unpack the packages at `paths`, as `installed` lists them, a few tarballs at a time
|
|
218
|
+
*
|
|
219
|
+
* Each is unpacked once however often it is asked for, written whole or not at all; one refused rejects
|
|
220
|
+
* this call and each after that asks for it, with the full tree's DeptreeError, once the rest are done.
|
|
221
|
+
*
|
|
222
|
+
* @param paths - Paths of packages; one the tree has no package at is a TypeError
|
|
223
|
+
* @returns Their entries in that order, with what each version document says where `metadata` fetches it
|
|
224
|
+
*/
|
|
225
|
+
unpack(paths: Iterable<string>): Promise<NpmInstalled[]>;
|
|
294
226
|
}
|
|
295
227
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
// and 11.18 on gives up on a tarball that inflates more than 1000 times
|
|
335
|
-
// what it has read at any point, which is refused where it may, with a
|
|
336
|
-
// margin, as where it checks depends on how the bytes come.
|
|
337
|
-
//
|
|
338
|
-
// The lockfile is held to what the lockfile reader holds it to, with the
|
|
339
|
-
// flags npm installs by: npm 11 works them out again at every install, and
|
|
340
|
-
// npm 10 takes them as written, unless the root package.json asks for
|
|
341
|
-
// other than the lockfile's entry of it to the letter, as one asking for a
|
|
342
|
-
// name in two lists, or for a workspace by name too, does. Each project's
|
|
343
|
-
// package.json is held to the lockfile's entry of its directory: the same
|
|
344
|
-
// names asked for, in the same lists, by the same specs, as npm ci would
|
|
345
|
-
// otherwise resolve them anew or refuse; and each workspace to the name
|
|
346
|
-
// and version the lockfile gives it. The root's devEngines are checked as
|
|
347
|
-
// npm checks them, against the host, which has no os version to check.
|
|
348
|
-
// Refused too, as npm's releases read them otherwise: a range with a
|
|
349
|
-
// wildcard before a number, `1.x.0`, and for npm 10 an optional peer the
|
|
350
|
-
// lockfile does not meet by a range, which it resolves again.
|
|
351
|
-
//
|
|
352
|
-
// And to more than npm holds it to, where a lockfile npm writes, or a
|
|
353
|
-
// package the registry serves, always holds: each tarball gzipped, every
|
|
354
|
-
// entry under one directory, named as tar reads it, with no `\` and no
|
|
355
|
-
// more than 1024 segments, none in the package's own node_modules, where
|
|
356
|
-
// npm installs its dependencies, no setuid, setgid or sticky bit, no link
|
|
357
|
-
// name on a file, no global pax header, and no pax size with a long name, a
|
|
358
|
-
// long link or a global header between it and its entry, which tar's
|
|
359
|
-
// releases read otherwise; each with the sha512 integrity the lockfile
|
|
360
|
-
// records. A pax size is taken over the header's, as every tar release
|
|
361
|
-
// takes it; npm's tar writes one into each pax header it packs, as for a
|
|
362
|
-
// name ustar cannot hold. On
|
|
363
|
-
// macOS, two names in one directory that differ only in case or
|
|
364
|
-
// normalization are refused, as they would be one name there.
|
|
365
|
-
//
|
|
366
|
-
// Packages come from npm's registry alone: each lockfile entry's
|
|
367
|
-
// `resolved` has to be the registry's own URL of its tarball,
|
|
368
|
-
// https://registry.npmjs.org/<name>/-/<base>-<version>.tgz, a scope's `/`
|
|
369
|
-
// as `%2f` or not, or that same URL on yarn's mirror,
|
|
370
|
-
// https://registry.yarnpkg.com/, which is taken for npm's; it is fetched
|
|
371
|
-
// from npm's through @preventive/upstream.
|
|
372
|
-
//
|
|
373
|
-
// Ranges and versions are read with npm's own semver, borrowed from the
|
|
374
|
-
// npm beside node as @preventive/upstream borrows it, or with its semver
|
|
375
|
-
// peer where there is no npm, without either of which this throws.
|
|
376
|
-
//
|
|
377
|
-
// Nothing is left to a guess: a lockfile the lockfile reader refuses, a
|
|
378
|
-
// setting this does not know or does not build for, a package from
|
|
379
|
-
// anywhere but the registry -- git, a tarball's URL or one on disk, a
|
|
380
|
-
// directory by `file:` -- or with no resolved URL, which npm fetches by the
|
|
381
|
-
// registry's packument, a package bundled in another, a link but to a
|
|
382
|
-
// workspace, overrides, acceptDependencies, a check above that fails --
|
|
383
|
-
// each is refused with a DeptreeError or a LockfileError that says where.
|
|
384
|
-
// A TypeError is thrown for options of the wrong type.
|
|
385
|
-
export function buildNpmTree(options: NpmLayoutOptions): Promise<NpmLayout>
|
|
386
|
-
export function buildNpmTree(options: NpmLazyOptions): Promise<NpmLazyTree>
|
|
387
|
-
export function buildNpmTree(options: NpmTreeOptions): Promise<NpmTree>
|
|
228
|
+
/**
|
|
229
|
+
* The node_modules tree `npm ci --ignore-scripts` makes with host.npm into a project with no node_modules
|
|
230
|
+
* yet
|
|
231
|
+
*
|
|
232
|
+
* Each package's files are unpacked where the lockfile puts it, and each workspace linked as
|
|
233
|
+
* node_modules/<its name> by a relative link, with what is beneath it in its own node_modules; nothing else
|
|
234
|
+
* of the projects is in the tree. Unpacked as npm's tar unpacks it: the first segment dropped, files alone
|
|
235
|
+
* (no link, device or empty directory), modes with read and write for all and a 0o022 umask taken off, a
|
|
236
|
+
* .gitignore renamed .npmignore unless one came before it, and directories 0o755.
|
|
237
|
+
*
|
|
238
|
+
* Scripts never run (a workspace with a prepare script, which npm 10 runs anyway, is refused), and no .bin
|
|
239
|
+
* or .package-lock.json is written. Unless bin-links is false, each bin's target is changed as linking it
|
|
240
|
+
* changes it: of a node_modules' packages, by path, the first bin of each name is linked, its target made
|
|
241
|
+
* 0o755, and a CRLF shebang in its first 2048 bytes made LF. A target that is a directory, runs through a
|
|
242
|
+
* file, or is in its own node_modules is refused, as is a workspace's bin in its node_modules, by
|
|
243
|
+
* directories.bin, or under the root's allowScripts.
|
|
244
|
+
*
|
|
245
|
+
* Held to the lockfile reader's checks, with the flags npm installs by: npm 11 works them out again, npm 10
|
|
246
|
+
* takes them as written unless the root asks for other than its entry to the letter. Each project's
|
|
247
|
+
* package.json is held to its lockfile entry (the same names, lists and specs) and each workspace to its
|
|
248
|
+
* name and version; the root's devEngines are checked against the host. Refused too, as npm's releases read
|
|
249
|
+
* them otherwise: a wildcard before a number (`1.x.0`), and for npm 10 an optional peer the lockfile does
|
|
250
|
+
* not meet. npm 10.9.9 and 11.18 on give up on a tarball inflating 1000 times what they read, so one near
|
|
251
|
+
* that is refused.
|
|
252
|
+
*
|
|
253
|
+
* And held to what npm's lockfiles and the registry always hold: each tarball gzipped, under one directory,
|
|
254
|
+
* named as tar reads it (no `\`, at most 1024 segments), with nothing in its own node_modules, no setuid,
|
|
255
|
+
* setgid or sticky bit, no link name on a file, no global pax header but one of a comment alone (as git
|
|
256
|
+
* archive writes its commit), no pax size ahead of another extended header, and the lockfile's sha512. On macOS, two names in a directory differing only in case or
|
|
257
|
+
* normalization are refused. Each package's `resolved` has to be the registry's own tarball URL, a scope's
|
|
258
|
+
* `/` as `%2f` or not, or that on yarn's mirror. Ranges are read with the semver of the npm beside node.
|
|
259
|
+
*
|
|
260
|
+
* @param options - The files, the host and where the tree goes
|
|
261
|
+
* @returns The tree
|
|
262
|
+
*/
|
|
263
|
+
export function buildNpmTree(options: NpmLayoutOptions): Promise<NpmLayout>;
|
|
264
|
+
export function buildNpmTree(options: NpmLazyOptions): Promise<NpmLazyTree>;
|
|
265
|
+
export function buildNpmTree(options: NpmTreeOptions): Promise<NpmTree>;
|
|
388
266
|
|
|
389
|
-
// The directories of the projects npm finds in `project`, by which
|
|
390
|
-
// buildNpmTree takes their package.json given: `.`, the root, first, then
|
|
391
|
-
// each directory with a package.json that a glob of the root's
|
|
392
|
-
// `workspaces` takes, outside node_modules, as npm finds them, and as
|
|
393
|
-
// buildNpmTree reads them from a project; with `os` darwin, whatever the
|
|
394
|
-
// case, as npm's glob matches on macOS. Refused as buildNpmTree refuses
|
|
395
|
-
// it: a link where the globs reach; and a root with no package.json.
|
|
396
267
|
export interface NpmWorkspacesOptions {
|
|
397
|
-
project: NpmProject
|
|
398
|
-
|
|
268
|
+
project: NpmProject;
|
|
269
|
+
/** `darwin` matches the globs whatever the case, as npm's glob does on macOS */
|
|
270
|
+
os?: string;
|
|
399
271
|
}
|
|
400
272
|
|
|
401
|
-
|
|
273
|
+
/**
|
|
274
|
+
* The directories of the projects npm finds in `project`, by which buildNpmTree takes their package.json
|
|
275
|
+
* given; refused as buildNpmTree refuses them, as is a root with no package.json
|
|
276
|
+
*
|
|
277
|
+
* @returns `.` first, then each directory with a package.json a glob of the root's `workspaces` takes
|
|
278
|
+
*/
|
|
279
|
+
export function findNpmWorkspaces(options: NpmWorkspacesOptions): string[];
|
|
402
280
|
|
|
403
|
-
|
|
404
|
-
// lockfile entry, `packages["node_modules/a"]` -- or undefined for the call
|
|
405
|
-
// as a whole; the message leads with it. `cause` is what a package beneath
|
|
406
|
-
// refused with, where one did.
|
|
281
|
+
/** A refusal; `cause` is what a package beneath refused with, where one did */
|
|
407
282
|
export class DeptreeError extends Error {
|
|
408
|
-
constructor(detail: string, where?: string, options?: { cause?: unknown })
|
|
409
|
-
|
|
283
|
+
constructor(detail: string, where?: string, options?: { cause?: unknown });
|
|
284
|
+
/** What it is about, which the message leads with (`.npmrc:3`, `packages["node_modules/a"]`), or undefined */
|
|
285
|
+
where: string | undefined;
|
|
410
286
|
}
|