@vltpkg/graph 1.0.0-rc.22 → 1.0.0-rc.24
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/dist/actual/load.d.ts +107 -0
- package/dist/actual/load.js +336 -0
- package/dist/browser.d.ts +14 -0
- package/dist/browser.js +16 -0
- package/dist/build.d.ts +28 -0
- package/dist/build.js +78 -0
- package/dist/dependencies.d.ts +65 -0
- package/dist/dependencies.js +111 -0
- package/dist/diff.d.ts +119 -0
- package/dist/diff.js +151 -0
- package/dist/edge.d.ts +46 -0
- package/dist/edge.js +77 -0
- package/dist/fixup-added-names.d.ts +18 -0
- package/dist/fixup-added-names.js +46 -0
- package/dist/graph.d.ts +153 -0
- package/dist/graph.js +444 -0
- package/dist/ideal/append-nodes.d.ts +31 -0
- package/dist/ideal/append-nodes.js +560 -0
- package/dist/ideal/build-ideal-from-starting-graph.d.ts +14 -0
- package/dist/ideal/build-ideal-from-starting-graph.js +69 -0
- package/dist/ideal/build.d.ts +40 -0
- package/dist/ideal/build.js +84 -0
- package/dist/ideal/get-importer-specs.d.ts +20 -0
- package/dist/ideal/get-importer-specs.js +180 -0
- package/dist/ideal/peers.d.ts +160 -0
- package/dist/ideal/peers.js +696 -0
- package/dist/ideal/refresh-ideal-graph.d.ts +43 -0
- package/dist/ideal/refresh-ideal-graph.js +62 -0
- package/dist/ideal/remove-satisfied-specs.d.ts +7 -0
- package/dist/ideal/remove-satisfied-specs.js +34 -0
- package/dist/ideal/sorting.d.ts +45 -0
- package/dist/ideal/sorting.js +70 -0
- package/dist/ideal/types.d.ts +107 -0
- package/dist/ideal/types.js +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +32 -0
- package/dist/install.d.ts +19 -0
- package/dist/install.js +208 -0
- package/dist/lockfile/load-edges.d.ts +11 -0
- package/dist/lockfile/load-edges.js +105 -0
- package/dist/lockfile/load-nodes.d.ts +4 -0
- package/dist/lockfile/load-nodes.js +101 -0
- package/dist/lockfile/load.d.ts +45 -0
- package/dist/lockfile/load.js +84 -0
- package/dist/lockfile/save.d.ts +30 -0
- package/dist/lockfile/save.js +174 -0
- package/dist/lockfile/types.d.ts +95 -0
- package/dist/lockfile/types.js +49 -0
- package/dist/modifiers.d.ts +188 -0
- package/dist/modifiers.js +329 -0
- package/dist/node.d.ts +234 -0
- package/dist/node.js +388 -0
- package/dist/non-empty-list.d.ts +2 -0
- package/dist/non-empty-list.js +2 -0
- package/dist/reify/add-edge.d.ts +9 -0
- package/dist/reify/add-edge.js +71 -0
- package/dist/reify/add-edges.d.ts +4 -0
- package/dist/reify/add-edges.js +12 -0
- package/dist/reify/add-nodes.d.ts +6 -0
- package/dist/reify/add-nodes.js +16 -0
- package/dist/reify/bin-chmod.d.ts +10 -0
- package/dist/reify/bin-chmod.js +38 -0
- package/dist/reify/build.d.ts +13 -0
- package/dist/reify/build.js +111 -0
- package/dist/reify/calculate-save-value.d.ts +2 -0
- package/dist/reify/calculate-save-value.js +50 -0
- package/dist/reify/check-needed-build.d.ts +34 -0
- package/dist/reify/check-needed-build.js +71 -0
- package/dist/reify/delete-edge.d.ts +4 -0
- package/dist/reify/delete-edge.js +27 -0
- package/dist/reify/delete-edges.d.ts +4 -0
- package/dist/reify/delete-edges.js +13 -0
- package/dist/reify/delete-nodes.d.ts +4 -0
- package/dist/reify/delete-nodes.js +15 -0
- package/dist/reify/extract-node.d.ts +23 -0
- package/dist/reify/extract-node.js +83 -0
- package/dist/reify/index.d.ts +34 -0
- package/dist/reify/index.js +161 -0
- package/dist/reify/internal-hoist.d.ts +8 -0
- package/dist/reify/internal-hoist.js +133 -0
- package/dist/reify/optional-fail.d.ts +15 -0
- package/dist/reify/optional-fail.js +15 -0
- package/dist/reify/rollback.d.ts +4 -0
- package/dist/reify/rollback.js +23 -0
- package/dist/reify/update-importers-package-json.d.ts +35 -0
- package/dist/reify/update-importers-package-json.js +122 -0
- package/dist/remove-optional-subgraph.d.ts +33 -0
- package/dist/remove-optional-subgraph.js +47 -0
- package/dist/resolve-save-type.d.ts +5 -0
- package/dist/resolve-save-type.js +4 -0
- package/dist/stringify-node.d.ts +2 -0
- package/dist/stringify-node.js +32 -0
- package/dist/transfer-data/load.d.ts +43 -0
- package/dist/transfer-data/load.js +175 -0
- package/dist/uninstall.d.ts +14 -0
- package/dist/uninstall.js +75 -0
- package/dist/update.d.ts +12 -0
- package/dist/update.js +73 -0
- package/dist/virtual-root.d.ts +15 -0
- package/dist/virtual-root.js +78 -0
- package/dist/visualization/human-readable-output.d.ts +26 -0
- package/dist/visualization/human-readable-output.js +163 -0
- package/dist/visualization/json-output.d.ts +41 -0
- package/dist/visualization/json-output.js +50 -0
- package/dist/visualization/mermaid-output.d.ts +17 -0
- package/dist/visualization/mermaid-output.js +170 -0
- package/dist/visualization/object-like-output.d.ts +2 -0
- package/dist/visualization/object-like-output.js +47 -0
- package/package.json +25 -25
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { PathScurry } from 'path-scurry';
|
|
2
|
+
import type { DepID } from '@vltpkg/dep-id';
|
|
3
|
+
import type { Spec, SpecOptions } from '@vltpkg/spec';
|
|
4
|
+
import type { Integrity, NormalizedManifest, DependencyTypeShort, GraphLike, NodeLike } from '@vltpkg/types';
|
|
5
|
+
import { Edge } from './edge.ts';
|
|
6
|
+
import type { Graph } from './graph.ts';
|
|
7
|
+
export type NodeOptions = SpecOptions & {
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
graph: GraphLike;
|
|
10
|
+
};
|
|
11
|
+
export declare class Node implements NodeLike {
|
|
12
|
+
#private;
|
|
13
|
+
get [Symbol.toStringTag](): string;
|
|
14
|
+
/**
|
|
15
|
+
* True if a node is only reachable via optional or peerOptional edges from
|
|
16
|
+
* any importer.
|
|
17
|
+
*
|
|
18
|
+
* Setting this to false, if previously set to true, will also unset
|
|
19
|
+
* the flag on any optional-flagged non-optional dependencies.
|
|
20
|
+
*/
|
|
21
|
+
get optional(): boolean;
|
|
22
|
+
set optional(optional: boolean);
|
|
23
|
+
isOptional(): this is Node & {
|
|
24
|
+
optional: true;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* True if a node is only reachable via dev edges from any importer.
|
|
28
|
+
*
|
|
29
|
+
* Setting this to false, if previously set to true, will also unset
|
|
30
|
+
* the flag on any dev-flagged non-dev dependencies.
|
|
31
|
+
*/
|
|
32
|
+
get dev(): boolean;
|
|
33
|
+
set dev(dev: boolean);
|
|
34
|
+
isDev(): this is Node & {
|
|
35
|
+
dev: true;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* True if there's a manifest-confused package name.
|
|
39
|
+
*/
|
|
40
|
+
confused: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* True if this node has been extracted to the file system.
|
|
43
|
+
*/
|
|
44
|
+
extracted: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* List of edges coming into this node.
|
|
47
|
+
*/
|
|
48
|
+
edgesIn: Set<Edge>;
|
|
49
|
+
/**
|
|
50
|
+
* List of edges from this node into other nodes. This usually represents
|
|
51
|
+
* that the connected node is a direct dependency of this node.
|
|
52
|
+
*/
|
|
53
|
+
edgesOut: Map<string, Edge>;
|
|
54
|
+
/**
|
|
55
|
+
* A `mainImporter` node may have workspace connected to it,
|
|
56
|
+
* equivalent to its `edgesOut` linked deps.
|
|
57
|
+
*/
|
|
58
|
+
workspaces: Map<string, Edge> | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* A reference to the {@link DepID} this node represents in the graph.
|
|
61
|
+
*/
|
|
62
|
+
id: DepID;
|
|
63
|
+
/**
|
|
64
|
+
* True if this node is an importer node.
|
|
65
|
+
*/
|
|
66
|
+
importer: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* True if this node is the project root node.
|
|
69
|
+
*/
|
|
70
|
+
mainImporter: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* A reference to the graph this node is a part of.
|
|
73
|
+
*/
|
|
74
|
+
graph: Graph;
|
|
75
|
+
/**
|
|
76
|
+
* The manifest integrity value.
|
|
77
|
+
*/
|
|
78
|
+
integrity?: Integrity;
|
|
79
|
+
/**
|
|
80
|
+
* The manifest this node represents in the graph.
|
|
81
|
+
*/
|
|
82
|
+
manifest?: NormalizedManifest;
|
|
83
|
+
/**
|
|
84
|
+
* Project where this node resides
|
|
85
|
+
*/
|
|
86
|
+
projectRoot: string;
|
|
87
|
+
/**
|
|
88
|
+
* For registry nodes, this is the registry we fetched them from.
|
|
89
|
+
* Needed because their un-prefixed dependencies need to come from
|
|
90
|
+
* the same registry, if it's not the default.
|
|
91
|
+
*/
|
|
92
|
+
registry?: string;
|
|
93
|
+
/**
|
|
94
|
+
* If this node has been modified as part of applying a {@link GraphModifier}
|
|
95
|
+
* then this field will contain the modifier query that was applied.
|
|
96
|
+
* Otherwise, it will be `undefined`.
|
|
97
|
+
*/
|
|
98
|
+
modifier: string | undefined;
|
|
99
|
+
get name(): string;
|
|
100
|
+
/**
|
|
101
|
+
* The version of the package represented by this node, this is usually
|
|
102
|
+
* equivalent to `manifest.version` but in a few ways it may differ such as
|
|
103
|
+
* nodes loaded from a lockfile that lacks a loaded manifest.
|
|
104
|
+
* This field should be used to retrieve package versions instead.
|
|
105
|
+
*/
|
|
106
|
+
version?: string;
|
|
107
|
+
/**
|
|
108
|
+
* An address {@link PackageInfoClient} may use to extract this package.
|
|
109
|
+
*/
|
|
110
|
+
resolved?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Platform requirements (engines, os, cpu) extracted from manifest.
|
|
113
|
+
* Stored separately for optional dependencies to enable platform checks
|
|
114
|
+
* when manifest is not loaded.
|
|
115
|
+
*/
|
|
116
|
+
platform?: {
|
|
117
|
+
engines?: Record<string, string>;
|
|
118
|
+
os?: string[] | string;
|
|
119
|
+
cpu?: string[] | string;
|
|
120
|
+
libc?: string[] | string;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Record of binary names to their paths in the package, if any.
|
|
124
|
+
*/
|
|
125
|
+
bins?: Record<string, string>;
|
|
126
|
+
/**
|
|
127
|
+
* True if this node has been built as part of the reify step.
|
|
128
|
+
*/
|
|
129
|
+
built: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Build state of this node - tracks whether it needs building, has been built, or failed.
|
|
132
|
+
* - 'none': No build state (default)
|
|
133
|
+
* - 'needed': Node needs to be built
|
|
134
|
+
* - 'built': Node has been successfully built
|
|
135
|
+
* - 'failed': Node build has failed
|
|
136
|
+
*/
|
|
137
|
+
buildState: 'none' | 'needed' | 'built' | 'failed';
|
|
138
|
+
/**
|
|
139
|
+
* Deterministic unique string used to identify (and ultimately duplicate)
|
|
140
|
+
* nodes that are affected by a peer context set modified resolution.
|
|
141
|
+
* These are appended to the node {@link DepID} as the `extra` suffix.
|
|
142
|
+
*/
|
|
143
|
+
peerSetHash?: string;
|
|
144
|
+
/**
|
|
145
|
+
* True if this node is detached from the graph.
|
|
146
|
+
* This is used to indicate that the node is not part of the graph
|
|
147
|
+
* although the node is still available as part of the resolution process.
|
|
148
|
+
* Allows for skipping fetching manifests for detached nodes.
|
|
149
|
+
*/
|
|
150
|
+
detached: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* The file system location for this node.
|
|
153
|
+
*/
|
|
154
|
+
get location(): string;
|
|
155
|
+
set location(location: string);
|
|
156
|
+
/**
|
|
157
|
+
* The resolved location of the node in the file system.
|
|
158
|
+
*/
|
|
159
|
+
resolvedLocation(scurry: PathScurry): string;
|
|
160
|
+
/**
|
|
161
|
+
* The location of the node_modules folder where this node's edgesOut
|
|
162
|
+
* should be linked into. For nodes in the store, this is the parent
|
|
163
|
+
* directory, since they're extracted into a node_modules folder
|
|
164
|
+
* side by side with links to their deps. For nodes outside of the store
|
|
165
|
+
* (ie, importers and arbitrary link deps) this is the node_modules folder
|
|
166
|
+
* directly inside the node's directory.
|
|
167
|
+
*/
|
|
168
|
+
nodeModules(scurry: PathScurry): string;
|
|
169
|
+
constructor(options: NodeOptions, id?: DepID, manifest?: NormalizedManifest, spec?: Spec, name?: string, version?: string);
|
|
170
|
+
/**
|
|
171
|
+
* return true if this node is located in the vlt store
|
|
172
|
+
* memoized the first time it's called, since the store location
|
|
173
|
+
* doesn't change within the context of a single operation.
|
|
174
|
+
*/
|
|
175
|
+
inVltStore(): boolean;
|
|
176
|
+
get options(): SpecOptions;
|
|
177
|
+
set options(_opts: SpecOptions);
|
|
178
|
+
equals(other: Node): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Sets the node as an importer along with its location.
|
|
181
|
+
*/
|
|
182
|
+
setImporterLocation(location: string): void;
|
|
183
|
+
/**
|
|
184
|
+
* Sets the appropriate resolve / integrity value for this node.
|
|
185
|
+
* Note that other places might also set these values, like for
|
|
186
|
+
* example the lockfile that might have already have this info.
|
|
187
|
+
*/
|
|
188
|
+
setResolved(): void;
|
|
189
|
+
setDefaultLocation(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Add an edge from this node connecting it to a direct dependency.
|
|
192
|
+
*/
|
|
193
|
+
addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node): Edge;
|
|
194
|
+
/**
|
|
195
|
+
* The raw manifest before any modifications.
|
|
196
|
+
* If not set, falls back to the current manifest.
|
|
197
|
+
*/
|
|
198
|
+
get rawManifest(): NormalizedManifest | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* Sets this node as having a manifest-confused manifest.
|
|
201
|
+
*/
|
|
202
|
+
setConfusedManifest(fixed: NormalizedManifest, confused?: NormalizedManifest): void;
|
|
203
|
+
/**
|
|
204
|
+
* Sets this node as having a manifest-confused manifest.
|
|
205
|
+
*/
|
|
206
|
+
maybeSetConfusedManifest(spec: Spec, confused?: NormalizedManifest): void;
|
|
207
|
+
toJSON(): {
|
|
208
|
+
rawManifest?: import("@vltpkg/types").Override<import("@vltpkg/types").Manifest, import("@vltpkg/types").NormalizedFields> | undefined;
|
|
209
|
+
peerSetHash?: string | undefined;
|
|
210
|
+
id: DepID;
|
|
211
|
+
name: string;
|
|
212
|
+
version: string | undefined;
|
|
213
|
+
location: string;
|
|
214
|
+
importer: boolean;
|
|
215
|
+
manifest: import("@vltpkg/types").Override<import("@vltpkg/types").Manifest, import("@vltpkg/types").NormalizedFields> | undefined;
|
|
216
|
+
projectRoot: string;
|
|
217
|
+
integrity: `sha512-${string}` | undefined;
|
|
218
|
+
resolved: string | undefined;
|
|
219
|
+
dev: boolean;
|
|
220
|
+
optional: boolean;
|
|
221
|
+
confused: boolean;
|
|
222
|
+
modifier: string | undefined;
|
|
223
|
+
platform: {
|
|
224
|
+
engines?: Record<string, string>;
|
|
225
|
+
os?: string[] | string;
|
|
226
|
+
cpu?: string[] | string;
|
|
227
|
+
libc?: string[] | string;
|
|
228
|
+
} | undefined;
|
|
229
|
+
buildState: "none" | "needed" | "built" | "failed";
|
|
230
|
+
};
|
|
231
|
+
toString(): string;
|
|
232
|
+
}
|
|
233
|
+
export declare const isNode: (value: unknown) => value is Node;
|
|
234
|
+
export declare const asNode: (value: unknown) => Node;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { isPackageNameConfused, getId, hydrateTuple, splitDepID, } from '@vltpkg/dep-id';
|
|
2
|
+
import { typeError } from '@vltpkg/error-cause';
|
|
3
|
+
import { expandNormalizedManifestSymbols } from '@vltpkg/types';
|
|
4
|
+
import { Edge } from "./edge.js";
|
|
5
|
+
import { stringifyNode } from "./stringify-node.js";
|
|
6
|
+
export class Node {
|
|
7
|
+
get [Symbol.toStringTag]() {
|
|
8
|
+
return '@vltpkg/graph.Node';
|
|
9
|
+
}
|
|
10
|
+
#options;
|
|
11
|
+
#location;
|
|
12
|
+
#rawManifest;
|
|
13
|
+
#optional = false;
|
|
14
|
+
/**
|
|
15
|
+
* True if a node is only reachable via optional or peerOptional edges from
|
|
16
|
+
* any importer.
|
|
17
|
+
*
|
|
18
|
+
* Setting this to false, if previously set to true, will also unset
|
|
19
|
+
* the flag on any optional-flagged non-optional dependencies.
|
|
20
|
+
*/
|
|
21
|
+
get optional() {
|
|
22
|
+
return this.#optional;
|
|
23
|
+
}
|
|
24
|
+
set optional(optional) {
|
|
25
|
+
const before = this.#optional;
|
|
26
|
+
this.#optional = optional;
|
|
27
|
+
if (before && !optional) {
|
|
28
|
+
// unset for all deps, as well
|
|
29
|
+
for (const { to, optional } of this.edgesOut.values()) {
|
|
30
|
+
if (!optional && to?.optional)
|
|
31
|
+
to.optional = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
isOptional() {
|
|
36
|
+
return this.#optional;
|
|
37
|
+
}
|
|
38
|
+
#dev = false;
|
|
39
|
+
/**
|
|
40
|
+
* True if a node is only reachable via dev edges from any importer.
|
|
41
|
+
*
|
|
42
|
+
* Setting this to false, if previously set to true, will also unset
|
|
43
|
+
* the flag on any dev-flagged non-dev dependencies.
|
|
44
|
+
*/
|
|
45
|
+
get dev() {
|
|
46
|
+
return this.#dev;
|
|
47
|
+
}
|
|
48
|
+
set dev(dev) {
|
|
49
|
+
const before = this.#dev;
|
|
50
|
+
this.#dev = dev;
|
|
51
|
+
if (before && !dev) {
|
|
52
|
+
// unset for all deps, as well
|
|
53
|
+
for (const { to, dev } of this.edgesOut.values()) {
|
|
54
|
+
if (!dev && to?.dev)
|
|
55
|
+
to.dev = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
isDev() {
|
|
60
|
+
return this.#dev;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* True if there's a manifest-confused package name.
|
|
64
|
+
*/
|
|
65
|
+
confused = false;
|
|
66
|
+
/**
|
|
67
|
+
* True if this node has been extracted to the file system.
|
|
68
|
+
*/
|
|
69
|
+
extracted = false;
|
|
70
|
+
/**
|
|
71
|
+
* List of edges coming into this node.
|
|
72
|
+
*/
|
|
73
|
+
edgesIn = new Set();
|
|
74
|
+
/**
|
|
75
|
+
* List of edges from this node into other nodes. This usually represents
|
|
76
|
+
* that the connected node is a direct dependency of this node.
|
|
77
|
+
*/
|
|
78
|
+
edgesOut = new Map();
|
|
79
|
+
/**
|
|
80
|
+
* A `mainImporter` node may have workspace connected to it,
|
|
81
|
+
* equivalent to its `edgesOut` linked deps.
|
|
82
|
+
*/
|
|
83
|
+
workspaces;
|
|
84
|
+
/**
|
|
85
|
+
* A reference to the {@link DepID} this node represents in the graph.
|
|
86
|
+
*/
|
|
87
|
+
id;
|
|
88
|
+
/**
|
|
89
|
+
* True if this node is an importer node.
|
|
90
|
+
*/
|
|
91
|
+
importer = false;
|
|
92
|
+
/**
|
|
93
|
+
* True if this node is the project root node.
|
|
94
|
+
*/
|
|
95
|
+
mainImporter = false;
|
|
96
|
+
/**
|
|
97
|
+
* A reference to the graph this node is a part of.
|
|
98
|
+
*/
|
|
99
|
+
graph;
|
|
100
|
+
/**
|
|
101
|
+
* The manifest integrity value.
|
|
102
|
+
*/
|
|
103
|
+
integrity;
|
|
104
|
+
/**
|
|
105
|
+
* The manifest this node represents in the graph.
|
|
106
|
+
*/
|
|
107
|
+
manifest;
|
|
108
|
+
/**
|
|
109
|
+
* Project where this node resides
|
|
110
|
+
*/
|
|
111
|
+
projectRoot;
|
|
112
|
+
/**
|
|
113
|
+
* For registry nodes, this is the registry we fetched them from.
|
|
114
|
+
* Needed because their un-prefixed dependencies need to come from
|
|
115
|
+
* the same registry, if it's not the default.
|
|
116
|
+
*/
|
|
117
|
+
registry;
|
|
118
|
+
/**
|
|
119
|
+
* If this node has been modified as part of applying a {@link GraphModifier}
|
|
120
|
+
* then this field will contain the modifier query that was applied.
|
|
121
|
+
* Otherwise, it will be `undefined`.
|
|
122
|
+
*/
|
|
123
|
+
modifier;
|
|
124
|
+
/**
|
|
125
|
+
* The name of the package represented by this node, this is usually
|
|
126
|
+
* equivalent to `manifest.name` but in a few ways it may differ such as
|
|
127
|
+
* nodes loaded from a lockfile that lacks a loaded manifest.
|
|
128
|
+
* This field should be used to retrieve package names instead.
|
|
129
|
+
*/
|
|
130
|
+
#name;
|
|
131
|
+
get name() {
|
|
132
|
+
if (this.#name)
|
|
133
|
+
return this.#name;
|
|
134
|
+
this.#name = this.id;
|
|
135
|
+
return this.#name;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The version of the package represented by this node, this is usually
|
|
139
|
+
* equivalent to `manifest.version` but in a few ways it may differ such as
|
|
140
|
+
* nodes loaded from a lockfile that lacks a loaded manifest.
|
|
141
|
+
* This field should be used to retrieve package versions instead.
|
|
142
|
+
*/
|
|
143
|
+
version;
|
|
144
|
+
/**
|
|
145
|
+
* An address {@link PackageInfoClient} may use to extract this package.
|
|
146
|
+
*/
|
|
147
|
+
resolved;
|
|
148
|
+
/**
|
|
149
|
+
* Platform requirements (engines, os, cpu) extracted from manifest.
|
|
150
|
+
* Stored separately for optional dependencies to enable platform checks
|
|
151
|
+
* when manifest is not loaded.
|
|
152
|
+
*/
|
|
153
|
+
platform;
|
|
154
|
+
/**
|
|
155
|
+
* Record of binary names to their paths in the package, if any.
|
|
156
|
+
*/
|
|
157
|
+
bins;
|
|
158
|
+
/**
|
|
159
|
+
* True if this node has been built as part of the reify step.
|
|
160
|
+
*/
|
|
161
|
+
built = false;
|
|
162
|
+
/**
|
|
163
|
+
* Build state of this node - tracks whether it needs building, has been built, or failed.
|
|
164
|
+
* - 'none': No build state (default)
|
|
165
|
+
* - 'needed': Node needs to be built
|
|
166
|
+
* - 'built': Node has been successfully built
|
|
167
|
+
* - 'failed': Node build has failed
|
|
168
|
+
*/
|
|
169
|
+
buildState = 'none';
|
|
170
|
+
/**
|
|
171
|
+
* Deterministic unique string used to identify (and ultimately duplicate)
|
|
172
|
+
* nodes that are affected by a peer context set modified resolution.
|
|
173
|
+
* These are appended to the node {@link DepID} as the `extra` suffix.
|
|
174
|
+
*/
|
|
175
|
+
peerSetHash;
|
|
176
|
+
/**
|
|
177
|
+
* True if this node is detached from the graph.
|
|
178
|
+
* This is used to indicate that the node is not part of the graph
|
|
179
|
+
* although the node is still available as part of the resolution process.
|
|
180
|
+
* Allows for skipping fetching manifests for detached nodes.
|
|
181
|
+
*/
|
|
182
|
+
detached = false;
|
|
183
|
+
/**
|
|
184
|
+
* The file system location for this node.
|
|
185
|
+
*/
|
|
186
|
+
get location() {
|
|
187
|
+
if (this.#location) {
|
|
188
|
+
return this.#location;
|
|
189
|
+
}
|
|
190
|
+
this.#location = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`;
|
|
191
|
+
// if using the default location, it is in the store
|
|
192
|
+
this.inVltStore = () => true;
|
|
193
|
+
return this.#location;
|
|
194
|
+
}
|
|
195
|
+
set location(location) {
|
|
196
|
+
this.#location = location;
|
|
197
|
+
// reset memoization, since it might be elsewhere now
|
|
198
|
+
if (this.inVltStore !== Node.prototype.inVltStore) {
|
|
199
|
+
this.inVltStore = Node.prototype.inVltStore;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The resolved location of the node in the file system.
|
|
204
|
+
*/
|
|
205
|
+
resolvedLocation(scurry) {
|
|
206
|
+
return scurry.cwd.resolve(this.location).fullpath();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The location of the node_modules folder where this node's edgesOut
|
|
210
|
+
* should be linked into. For nodes in the store, this is the parent
|
|
211
|
+
* directory, since they're extracted into a node_modules folder
|
|
212
|
+
* side by side with links to their deps. For nodes outside of the store
|
|
213
|
+
* (ie, importers and arbitrary link deps) this is the node_modules folder
|
|
214
|
+
* directly inside the node's directory.
|
|
215
|
+
*/
|
|
216
|
+
nodeModules(scurry) {
|
|
217
|
+
const loc = this.resolvedLocation(scurry);
|
|
218
|
+
return this.inVltStore() ?
|
|
219
|
+
loc.substring(0, loc.length - this.name.length - 1)
|
|
220
|
+
: scurry.resolve(loc, 'node_modules');
|
|
221
|
+
}
|
|
222
|
+
constructor(options, id, manifest, spec, name, version) {
|
|
223
|
+
this.#options = options;
|
|
224
|
+
this.projectRoot = options.projectRoot;
|
|
225
|
+
if (id) {
|
|
226
|
+
this.id = id;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if (!manifest || !spec) {
|
|
230
|
+
throw typeError('A new Node needs either a manifest & spec or an id parameter', {
|
|
231
|
+
manifest,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
this.id = getId(spec, manifest);
|
|
235
|
+
}
|
|
236
|
+
this.graph = options.graph;
|
|
237
|
+
this.manifest = manifest;
|
|
238
|
+
this.#name = name || this.manifest?.name;
|
|
239
|
+
this.version = version || this.manifest?.version;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* return true if this node is located in the vlt store
|
|
243
|
+
* memoized the first time it's called, since the store location
|
|
244
|
+
* doesn't change within the context of a single operation.
|
|
245
|
+
*/
|
|
246
|
+
inVltStore() {
|
|
247
|
+
// technically this just means it's in *a* vlt store, but we can safely
|
|
248
|
+
// assume that a user won't construct a path like this by accident,
|
|
249
|
+
// and there's only ever one store in any given project.
|
|
250
|
+
const inStore = this.location.endsWith(`.vlt/${this.id}/node_modules/${this.name}`);
|
|
251
|
+
this.inVltStore = () => inStore;
|
|
252
|
+
return inStore;
|
|
253
|
+
}
|
|
254
|
+
#registryNodeResolved(tuple) {
|
|
255
|
+
const spec = hydrateTuple(tuple, this.#name, this.#options);
|
|
256
|
+
this.resolved =
|
|
257
|
+
this.manifest?.dist?.tarball || spec.conventionalRegistryTarball;
|
|
258
|
+
this.integrity ??= this.manifest?.dist?.integrity;
|
|
259
|
+
}
|
|
260
|
+
get options() {
|
|
261
|
+
return this.#options;
|
|
262
|
+
}
|
|
263
|
+
/* c8 ignore next */
|
|
264
|
+
set options(_opts) { }
|
|
265
|
+
equals(other) {
|
|
266
|
+
return this.id === other.id && this.location === other.location;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Sets the node as an importer along with its location.
|
|
270
|
+
*/
|
|
271
|
+
setImporterLocation(location) {
|
|
272
|
+
this.#location = location;
|
|
273
|
+
this.importer = true;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Sets the appropriate resolve / integrity value for this node.
|
|
277
|
+
* Note that other places might also set these values, like for
|
|
278
|
+
* example the lockfile that might have already have this info.
|
|
279
|
+
*/
|
|
280
|
+
setResolved() {
|
|
281
|
+
// file | remote | workspace type of ids all points to a URI that
|
|
282
|
+
// can be used as the `resolved` value, so we split the dep id
|
|
283
|
+
// for these cases.
|
|
284
|
+
const tuple = splitDepID(this.id);
|
|
285
|
+
const [type, resolved] = tuple;
|
|
286
|
+
switch (type) {
|
|
287
|
+
case 'remote': {
|
|
288
|
+
this.resolved = resolved;
|
|
289
|
+
this.integrity ??= this.manifest?.dist?.integrity;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case 'registry':
|
|
293
|
+
this.#registryNodeResolved(tuple);
|
|
294
|
+
break;
|
|
295
|
+
default:
|
|
296
|
+
this.resolved = resolved;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
setDefaultLocation() {
|
|
301
|
+
const def = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`;
|
|
302
|
+
// only relocate if the location is in node_modules already
|
|
303
|
+
if (!this.importer &&
|
|
304
|
+
(!this.#location ||
|
|
305
|
+
(this.#location !== def &&
|
|
306
|
+
/^(?:\.\/)?node_modules\//.test(this.#location)))) {
|
|
307
|
+
this.#location = def;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Add an edge from this node connecting it to a direct dependency.
|
|
312
|
+
*/
|
|
313
|
+
addEdgesTo(type, spec, node) {
|
|
314
|
+
const edge = new Edge(type, spec, this, node);
|
|
315
|
+
node?.edgesIn.add(edge);
|
|
316
|
+
this.edgesOut.set(spec.name, edge);
|
|
317
|
+
return edge;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* The raw manifest before any modifications.
|
|
321
|
+
* If not set, falls back to the current manifest.
|
|
322
|
+
*/
|
|
323
|
+
get rawManifest() {
|
|
324
|
+
return this.#rawManifest ?? this.manifest;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Sets this node as having a manifest-confused manifest.
|
|
328
|
+
*/
|
|
329
|
+
setConfusedManifest(fixed, confused) {
|
|
330
|
+
this.manifest = fixed;
|
|
331
|
+
this.#rawManifest = confused;
|
|
332
|
+
this.confused = true;
|
|
333
|
+
this.#name = this.manifest.name;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Sets this node as having a manifest-confused manifest.
|
|
337
|
+
*/
|
|
338
|
+
maybeSetConfusedManifest(spec, confused) {
|
|
339
|
+
if (isPackageNameConfused(spec, this.manifest?.name)) {
|
|
340
|
+
this.setConfusedManifest({
|
|
341
|
+
...this.manifest,
|
|
342
|
+
name: spec.name,
|
|
343
|
+
}, confused);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
toJSON() {
|
|
347
|
+
return {
|
|
348
|
+
id: this.id,
|
|
349
|
+
name: this.name,
|
|
350
|
+
version: this.version,
|
|
351
|
+
location: this.location,
|
|
352
|
+
importer: this.importer,
|
|
353
|
+
manifest: this.manifest &&
|
|
354
|
+
expandNormalizedManifestSymbols(this.manifest),
|
|
355
|
+
projectRoot: this.projectRoot,
|
|
356
|
+
integrity: this.integrity,
|
|
357
|
+
resolved: this.resolved,
|
|
358
|
+
dev: this.dev,
|
|
359
|
+
optional: this.optional,
|
|
360
|
+
confused: this.confused,
|
|
361
|
+
modifier: this.modifier,
|
|
362
|
+
platform: this.platform,
|
|
363
|
+
buildState: this.buildState,
|
|
364
|
+
...(this.peerSetHash ?
|
|
365
|
+
{ peerSetHash: this.peerSetHash }
|
|
366
|
+
: undefined),
|
|
367
|
+
...(this.confused ?
|
|
368
|
+
{ rawManifest: this.#rawManifest }
|
|
369
|
+
: undefined),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
toString() {
|
|
373
|
+
return stringifyNode(this);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
export const isNode = (value) => {
|
|
377
|
+
return (typeof value === 'object' &&
|
|
378
|
+
value != null &&
|
|
379
|
+
'id' in value &&
|
|
380
|
+
'manifest' in value &&
|
|
381
|
+
value[Symbol.toStringTag] === '@vltpkg/graph.Node');
|
|
382
|
+
};
|
|
383
|
+
export const asNode = (value) => {
|
|
384
|
+
if (!isNode(value)) {
|
|
385
|
+
throw typeError('Expected a node', { found: value });
|
|
386
|
+
}
|
|
387
|
+
return value;
|
|
388
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import type { PathScurry } from 'path-scurry';
|
|
3
|
+
import type { Edge } from '../edge.ts';
|
|
4
|
+
/**
|
|
5
|
+
* reify an edge into a node_modules folder, with bins linked
|
|
6
|
+
* this does NOT chmod the bins to 0o777, because they might not exist
|
|
7
|
+
* until scripts are run, in the case of non-store deps like workspaces
|
|
8
|
+
*/
|
|
9
|
+
export declare const addEdge: (edge: Edge, scurry: PathScurry, remover: RollbackRemove, bins?: Record<string, string>) => Promise<void>;
|