@vltpkg/graph 0.0.0-0.1730239248325
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 +15 -0
- package/README.md +33 -0
- package/dist/esm/actual/load.d.ts +54 -0
- package/dist/esm/actual/load.d.ts.map +1 -0
- package/dist/esm/actual/load.js +243 -0
- package/dist/esm/actual/load.js.map +1 -0
- package/dist/esm/browser.d.ts +9 -0
- package/dist/esm/browser.d.ts.map +1 -0
- package/dist/esm/browser.js +11 -0
- package/dist/esm/browser.js.map +1 -0
- package/dist/esm/dependencies.d.ts +69 -0
- package/dist/esm/dependencies.d.ts.map +1 -0
- package/dist/esm/dependencies.js +71 -0
- package/dist/esm/dependencies.js.map +1 -0
- package/dist/esm/diff.d.ts +49 -0
- package/dist/esm/diff.d.ts.map +1 -0
- package/dist/esm/diff.js +123 -0
- package/dist/esm/diff.js.map +1 -0
- package/dist/esm/edge.d.ts +41 -0
- package/dist/esm/edge.d.ts.map +1 -0
- package/dist/esm/edge.js +66 -0
- package/dist/esm/edge.js.map +1 -0
- package/dist/esm/graph.d.ts +123 -0
- package/dist/esm/graph.d.ts.map +1 -0
- package/dist/esm/graph.js +301 -0
- package/dist/esm/graph.js.map +1 -0
- package/dist/esm/ideal/add-nodes.d.ts +19 -0
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/add-nodes.js +28 -0
- package/dist/esm/ideal/add-nodes.js.map +1 -0
- package/dist/esm/ideal/append-nodes.d.ts +9 -0
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/append-nodes.js +121 -0
- package/dist/esm/ideal/append-nodes.js.map +1 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +15 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +28 -0
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -0
- package/dist/esm/ideal/build.d.ts +32 -0
- package/dist/esm/ideal/build.d.ts.map +1 -0
- package/dist/esm/ideal/build.js +42 -0
- package/dist/esm/ideal/build.js.map +1 -0
- package/dist/esm/ideal/get-importer-specs.d.ts +13 -0
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -0
- package/dist/esm/ideal/get-importer-specs.js +76 -0
- package/dist/esm/ideal/get-importer-specs.js.map +1 -0
- package/dist/esm/ideal/remove-nodes.d.ts +7 -0
- package/dist/esm/ideal/remove-nodes.d.ts.map +1 -0
- package/dist/esm/ideal/remove-nodes.js +19 -0
- package/dist/esm/ideal/remove-nodes.js.map +1 -0
- package/dist/esm/ideal/remove-satisfied-specs.d.ts +8 -0
- package/dist/esm/ideal/remove-satisfied-specs.d.ts.map +1 -0
- package/dist/esm/ideal/remove-satisfied-specs.js +35 -0
- package/dist/esm/ideal/remove-satisfied-specs.js.map +1 -0
- package/dist/esm/ideal/types.d.ts +35 -0
- package/dist/esm/ideal/types.d.ts.map +1 -0
- package/dist/esm/ideal/types.js +2 -0
- package/dist/esm/ideal/types.js.map +1 -0
- package/dist/esm/index.d.ts +31 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lockfile/load-edges.d.ts +5 -0
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -0
- package/dist/esm/lockfile/load-edges.js +40 -0
- package/dist/esm/lockfile/load-edges.js.map +1 -0
- package/dist/esm/lockfile/load-nodes.d.ts +4 -0
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -0
- package/dist/esm/lockfile/load-nodes.js +28 -0
- package/dist/esm/lockfile/load-nodes.js.map +1 -0
- package/dist/esm/lockfile/load.d.ts +33 -0
- package/dist/esm/lockfile/load.d.ts.map +1 -0
- package/dist/esm/lockfile/load.js +53 -0
- package/dist/esm/lockfile/load.js.map +1 -0
- package/dist/esm/lockfile/save.d.ts +18 -0
- package/dist/esm/lockfile/save.d.ts.map +1 -0
- package/dist/esm/lockfile/save.js +128 -0
- package/dist/esm/lockfile/save.js.map +1 -0
- package/dist/esm/lockfile/types.d.ts +60 -0
- package/dist/esm/lockfile/types.d.ts.map +1 -0
- package/dist/esm/lockfile/types.js +13 -0
- package/dist/esm/lockfile/types.js.map +1 -0
- package/dist/esm/node.d.ts +144 -0
- package/dist/esm/node.d.ts.map +1 -0
- package/dist/esm/node.js +266 -0
- package/dist/esm/node.js.map +1 -0
- package/dist/esm/non-empty-list.d.ts +3 -0
- package/dist/esm/non-empty-list.d.ts.map +1 -0
- package/dist/esm/non-empty-list.js +3 -0
- package/dist/esm/non-empty-list.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/reify/add-edge.d.ts +11 -0
- package/dist/esm/reify/add-edge.d.ts.map +1 -0
- package/dist/esm/reify/add-edge.js +43 -0
- package/dist/esm/reify/add-edge.js.map +1 -0
- package/dist/esm/reify/add-edges.d.ts +6 -0
- package/dist/esm/reify/add-edges.d.ts.map +1 -0
- package/dist/esm/reify/add-edges.js +13 -0
- package/dist/esm/reify/add-edges.js.map +1 -0
- package/dist/esm/reify/add-nodes.d.ts +7 -0
- package/dist/esm/reify/add-nodes.d.ts.map +1 -0
- package/dist/esm/reify/add-nodes.js +37 -0
- package/dist/esm/reify/add-nodes.js.map +1 -0
- package/dist/esm/reify/bin-paths.d.ts +4 -0
- package/dist/esm/reify/bin-paths.d.ts.map +1 -0
- package/dist/esm/reify/bin-paths.js +23 -0
- package/dist/esm/reify/bin-paths.js.map +1 -0
- package/dist/esm/reify/build.d.ts +5 -0
- package/dist/esm/reify/build.d.ts.map +1 -0
- package/dist/esm/reify/build.js +90 -0
- package/dist/esm/reify/build.js.map +1 -0
- package/dist/esm/reify/delete-edge.d.ts +5 -0
- package/dist/esm/reify/delete-edge.d.ts.map +1 -0
- package/dist/esm/reify/delete-edge.js +29 -0
- package/dist/esm/reify/delete-edge.js.map +1 -0
- package/dist/esm/reify/delete-edges.d.ts +5 -0
- package/dist/esm/reify/delete-edges.d.ts.map +1 -0
- package/dist/esm/reify/delete-edges.js +14 -0
- package/dist/esm/reify/delete-edges.js.map +1 -0
- package/dist/esm/reify/delete-nodes.d.ts +5 -0
- package/dist/esm/reify/delete-nodes.d.ts.map +1 -0
- package/dist/esm/reify/delete-nodes.js +12 -0
- package/dist/esm/reify/delete-nodes.js.map +1 -0
- package/dist/esm/reify/index.d.ts +16 -0
- package/dist/esm/reify/index.d.ts.map +1 -0
- package/dist/esm/reify/index.js +85 -0
- package/dist/esm/reify/index.js.map +1 -0
- package/dist/esm/reify/optional-fail.d.ts +16 -0
- package/dist/esm/reify/optional-fail.d.ts.map +1 -0
- package/dist/esm/reify/optional-fail.js +16 -0
- package/dist/esm/reify/optional-fail.js.map +1 -0
- package/dist/esm/reify/rollback.d.ts +5 -0
- package/dist/esm/reify/rollback.d.ts.map +1 -0
- package/dist/esm/reify/rollback.js +24 -0
- package/dist/esm/reify/rollback.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts +36 -0
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -0
- package/dist/esm/reify/update-importers-package-json.js +95 -0
- package/dist/esm/reify/update-importers-package-json.js.map +1 -0
- package/dist/esm/remove-optional-subgraph.d.ts +34 -0
- package/dist/esm/remove-optional-subgraph.d.ts.map +1 -0
- package/dist/esm/remove-optional-subgraph.js +48 -0
- package/dist/esm/remove-optional-subgraph.js.map +1 -0
- package/dist/esm/stringify-node.d.ts +3 -0
- package/dist/esm/stringify-node.d.ts.map +1 -0
- package/dist/esm/stringify-node.js +24 -0
- package/dist/esm/stringify-node.js.map +1 -0
- package/dist/esm/types.d.ts +39 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +25 -0
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -0
- package/dist/esm/visualization/human-readable-output.js +132 -0
- package/dist/esm/visualization/human-readable-output.js.map +1 -0
- package/dist/esm/visualization/json-output.d.ts +37 -0
- package/dist/esm/visualization/json-output.d.ts.map +1 -0
- package/dist/esm/visualization/json-output.js +28 -0
- package/dist/esm/visualization/json-output.js.map +1 -0
- package/dist/esm/visualization/mermaid-output.d.ts +11 -0
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -0
- package/dist/esm/visualization/mermaid-output.js +68 -0
- package/dist/esm/visualization/mermaid-output.js.map +1 -0
- package/dist/esm/visualization/object-like-output.d.ts +3 -0
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -0
- package/dist/esm/visualization/object-like-output.js +49 -0
- package/dist/esm/visualization/object-like-output.js.map +1 -0
- package/package.json +86 -0
package/dist/esm/node.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { getId, hydrateTuple, splitDepID, } from '@vltpkg/dep-id';
|
|
2
|
+
import { typeError } from '@vltpkg/error-cause';
|
|
3
|
+
import { Edge } from './edge.js';
|
|
4
|
+
import { stringifyNode } from './stringify-node.js';
|
|
5
|
+
export class Node {
|
|
6
|
+
get [Symbol.toStringTag]() {
|
|
7
|
+
return '@vltpkg/graph.Node';
|
|
8
|
+
}
|
|
9
|
+
#options;
|
|
10
|
+
#location;
|
|
11
|
+
#optional = false;
|
|
12
|
+
/**
|
|
13
|
+
* True if a node is only reachable via optional or peerOptional edges from
|
|
14
|
+
* any importer.
|
|
15
|
+
*
|
|
16
|
+
* Setting this to false, if previously set to true, will also unset
|
|
17
|
+
* the flag on any optional-flagged non-optional dependencies.
|
|
18
|
+
*/
|
|
19
|
+
get optional() {
|
|
20
|
+
return this.#optional;
|
|
21
|
+
}
|
|
22
|
+
set optional(optional) {
|
|
23
|
+
const before = this.#optional;
|
|
24
|
+
this.#optional = optional;
|
|
25
|
+
if (before && !optional) {
|
|
26
|
+
// unset for all deps, as well
|
|
27
|
+
for (const { to, optional } of this.edgesOut.values()) {
|
|
28
|
+
if (!optional && to?.optional)
|
|
29
|
+
to.optional = false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
isOptional() {
|
|
34
|
+
return this.#optional;
|
|
35
|
+
}
|
|
36
|
+
#dev = false;
|
|
37
|
+
/**
|
|
38
|
+
* True if a node is only reachable via dev edges from any importer.
|
|
39
|
+
*
|
|
40
|
+
* Setting this to false, if previously set to true, will also unset
|
|
41
|
+
* the flag on any dev-flagged non-dev dependencies.
|
|
42
|
+
*/
|
|
43
|
+
get dev() {
|
|
44
|
+
return this.#dev;
|
|
45
|
+
}
|
|
46
|
+
set dev(dev) {
|
|
47
|
+
const before = this.#dev;
|
|
48
|
+
this.#dev = dev;
|
|
49
|
+
if (before && !dev) {
|
|
50
|
+
// unset for all deps, as well
|
|
51
|
+
for (const { to, dev } of this.edgesOut.values()) {
|
|
52
|
+
if (!dev && to?.dev)
|
|
53
|
+
to.dev = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
isDev() {
|
|
58
|
+
return this.#dev;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* List of edges coming into this node.
|
|
62
|
+
*/
|
|
63
|
+
edgesIn = new Set();
|
|
64
|
+
/**
|
|
65
|
+
* List of edges from this node into other nodes. This usually represents
|
|
66
|
+
* that the connected node is a direct dependency of this node.
|
|
67
|
+
*/
|
|
68
|
+
edgesOut = new Map();
|
|
69
|
+
/**
|
|
70
|
+
* A reference to the {@link DepID} this node represents in the graph.
|
|
71
|
+
*/
|
|
72
|
+
id;
|
|
73
|
+
/**
|
|
74
|
+
* True if this node is an importer node.
|
|
75
|
+
*/
|
|
76
|
+
importer = false;
|
|
77
|
+
/**
|
|
78
|
+
* True if this node is the project root node.
|
|
79
|
+
*/
|
|
80
|
+
mainImporter = false;
|
|
81
|
+
/**
|
|
82
|
+
* A reference to the graph this node is a part of.
|
|
83
|
+
*/
|
|
84
|
+
graph;
|
|
85
|
+
/**
|
|
86
|
+
* The manifest integrity value.
|
|
87
|
+
*/
|
|
88
|
+
integrity;
|
|
89
|
+
/**
|
|
90
|
+
* The manifest this node represents in the graph.
|
|
91
|
+
*/
|
|
92
|
+
manifest;
|
|
93
|
+
/**
|
|
94
|
+
* Project where this node resides
|
|
95
|
+
*/
|
|
96
|
+
projectRoot;
|
|
97
|
+
/**
|
|
98
|
+
* For registry nodes, this is the registry we fetched them from.
|
|
99
|
+
* Needed because their un-prefixed dependencies need to come from
|
|
100
|
+
* the same registry, if it's not the default.
|
|
101
|
+
*/
|
|
102
|
+
registry;
|
|
103
|
+
/**
|
|
104
|
+
* The name of the package represented by this node, this is usually
|
|
105
|
+
* equivalent to `manifest.name` but in a few ways it may differ such as
|
|
106
|
+
* nodes loaded from a lockfile that lacks a loaded manifest.
|
|
107
|
+
* This field should be used to retrieve package names instead.
|
|
108
|
+
*/
|
|
109
|
+
#name;
|
|
110
|
+
get name() {
|
|
111
|
+
if (this.#name)
|
|
112
|
+
return this.#name;
|
|
113
|
+
this.#name = this.id;
|
|
114
|
+
return this.#name;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The location of the node_modules folder where this node's edgesOut
|
|
118
|
+
* should be linked into. For nodes in the store, this is the parent
|
|
119
|
+
* directory, since they're extracted into a node_modules folder
|
|
120
|
+
* side by side with links to their deps. For nodes outside of the store
|
|
121
|
+
* (ie, importers and arbitrary link deps) this is the node_modules folder
|
|
122
|
+
* directly inside the node's directory.
|
|
123
|
+
*/
|
|
124
|
+
get nodeModules() {
|
|
125
|
+
const loc = this.location;
|
|
126
|
+
return this.inVltStore() ?
|
|
127
|
+
loc.substring(0, loc.length - this.name.length - 1)
|
|
128
|
+
: loc + '/node_modules';
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The version of the package represented by this node, this is usually
|
|
132
|
+
* equivalent to `manifest.version` but in a few ways it may differ such as
|
|
133
|
+
* nodes loaded from a lockfile that lacks a loaded manifest.
|
|
134
|
+
* This field should be used to retrieve package versions instead.
|
|
135
|
+
*/
|
|
136
|
+
version;
|
|
137
|
+
/**
|
|
138
|
+
* An address {@link PackageInfoClient} may use to extract this package.
|
|
139
|
+
*/
|
|
140
|
+
resolved;
|
|
141
|
+
/**
|
|
142
|
+
* The file system location for this node.
|
|
143
|
+
*/
|
|
144
|
+
get location() {
|
|
145
|
+
if (this.#location) {
|
|
146
|
+
return this.#location;
|
|
147
|
+
}
|
|
148
|
+
this.#location = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`;
|
|
149
|
+
// if using the default location, it is in the store
|
|
150
|
+
this.inVltStore = () => true;
|
|
151
|
+
return this.#location;
|
|
152
|
+
}
|
|
153
|
+
set location(location) {
|
|
154
|
+
this.#location = location;
|
|
155
|
+
// reset memoization, since it might be elsewhere now
|
|
156
|
+
if (this.inVltStore !== Node.prototype.inVltStore) {
|
|
157
|
+
this.inVltStore = Node.prototype.inVltStore;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
constructor(options, id, manifest, spec, name, version) {
|
|
161
|
+
this.#options = options;
|
|
162
|
+
this.projectRoot = options.projectRoot;
|
|
163
|
+
if (id) {
|
|
164
|
+
this.id = id;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
if (!manifest || !spec) {
|
|
168
|
+
throw typeError('A new Node needs either a manifest & spec or an id parameter', {
|
|
169
|
+
manifest,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
this.id = getId(spec, manifest);
|
|
173
|
+
}
|
|
174
|
+
this.graph = options.graph;
|
|
175
|
+
this.manifest = manifest;
|
|
176
|
+
this.#name = name || this.manifest?.name;
|
|
177
|
+
this.version = version || this.manifest?.version;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* return true if this node is located in the vlt store
|
|
181
|
+
* memoized the first time it's called, since the store location
|
|
182
|
+
* doesn't change within the context of a single operation.
|
|
183
|
+
*/
|
|
184
|
+
inVltStore() {
|
|
185
|
+
// technically this just means it's in *a* vlt store, but we can safely
|
|
186
|
+
// assume that a user won't construct a path like this by accident,
|
|
187
|
+
// and there's only ever one store in any given project.
|
|
188
|
+
const inStore = this.location.endsWith(`.vlt/${this.id}/node_modules/${this.name}`);
|
|
189
|
+
this.inVltStore = () => inStore;
|
|
190
|
+
return inStore;
|
|
191
|
+
}
|
|
192
|
+
#registryNodeResolved(tuple) {
|
|
193
|
+
const spec = hydrateTuple(tuple, this.#name, this.#options);
|
|
194
|
+
this.resolved =
|
|
195
|
+
this.manifest?.dist?.tarball || spec.conventionalRegistryTarball;
|
|
196
|
+
this.integrity ??= this.manifest?.dist?.integrity;
|
|
197
|
+
}
|
|
198
|
+
equals(other) {
|
|
199
|
+
return this.id === other.id && this.location === other.location;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sets the node as an importer along with its location.
|
|
203
|
+
*/
|
|
204
|
+
setImporterLocation(location) {
|
|
205
|
+
this.#location = location;
|
|
206
|
+
this.importer = true;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Sets the appropriate resolve / integrity value for this node.
|
|
210
|
+
* Note that other places might also set these values, like for
|
|
211
|
+
* example the lockfile that might have already have this info.
|
|
212
|
+
*/
|
|
213
|
+
setResolved() {
|
|
214
|
+
// file | remote | workspace type of ids all points to a URI that
|
|
215
|
+
// can be used as the `resolved` value, so we split the dep id
|
|
216
|
+
// for these cases.
|
|
217
|
+
const tuple = splitDepID(this.id);
|
|
218
|
+
const [type, resolved] = tuple;
|
|
219
|
+
switch (type) {
|
|
220
|
+
case 'registry':
|
|
221
|
+
this.#registryNodeResolved(tuple);
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
this.resolved = resolved;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
setDefaultLocation() {
|
|
229
|
+
const def = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`;
|
|
230
|
+
// only relocate if the location is in node_modules already
|
|
231
|
+
if (!this.importer &&
|
|
232
|
+
(!this.#location ||
|
|
233
|
+
(this.#location !== def &&
|
|
234
|
+
/^(?:\.\/)?node_modules\//.test(this.#location)))) {
|
|
235
|
+
this.#location = def;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Add an edge from this node connecting it to a direct dependency.
|
|
240
|
+
*/
|
|
241
|
+
addEdgesTo(type, spec, node) {
|
|
242
|
+
const edge = new Edge(type, spec, this, node);
|
|
243
|
+
node?.edgesIn.add(edge);
|
|
244
|
+
this.edgesOut.set(spec.name, edge);
|
|
245
|
+
return edge;
|
|
246
|
+
}
|
|
247
|
+
toJSON() {
|
|
248
|
+
return {
|
|
249
|
+
id: this.id,
|
|
250
|
+
name: this.name,
|
|
251
|
+
version: this.version,
|
|
252
|
+
location: this.location,
|
|
253
|
+
importer: this.importer,
|
|
254
|
+
manifest: this.manifest,
|
|
255
|
+
projectRoot: this.projectRoot,
|
|
256
|
+
integrity: this.integrity,
|
|
257
|
+
resolved: this.resolved,
|
|
258
|
+
dev: this.dev,
|
|
259
|
+
optional: this.optional,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
toString() {
|
|
263
|
+
return stringifyNode(this);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,EACL,YAAY,EACZ,UAAU,GACX,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAI/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAOnD,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,QAAQ,CAAa;IACrB,SAA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'\nimport { Spec, SpecOptions } from '@vltpkg/spec'\nimport { Integrity, Manifest } from '@vltpkg/types'\nimport { DependencyTypeShort } from './dependencies.js'\nimport { Edge } from './edge.js'\nimport { GraphLike, NodeLike } from './types.js'\nimport { stringifyNode } from './stringify-node.js'\n\nexport type NodeOptions = SpecOptions & {\n projectRoot: string\n graph: GraphLike\n}\n\nexport class Node implements NodeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Node'\n }\n\n #options: SpecOptions\n #location?: string\n\n #optional = false\n /**\n * True if a node is only reachable via optional or peerOptional edges from\n * any importer.\n *\n * Setting this to false, if previously set to true, will also unset\n * the flag on any optional-flagged non-optional dependencies.\n */\n get optional() {\n return this.#optional\n }\n set optional(optional: boolean) {\n const before = this.#optional\n this.#optional = optional\n if (before && !optional) {\n // unset for all deps, as well\n for (const { to, optional } of this.edgesOut.values()) {\n if (!optional && to?.optional) to.optional = false\n }\n }\n }\n\n isOptional(): this is Node & { optional: true } {\n return this.#optional\n }\n\n #dev = false\n /**\n * True if a node is only reachable via dev edges from any importer.\n *\n * Setting this to false, if previously set to true, will also unset\n * the flag on any dev-flagged non-dev dependencies.\n */\n get dev() {\n return this.#dev\n }\n set dev(dev: boolean) {\n const before = this.#dev\n this.#dev = dev\n if (before && !dev) {\n // unset for all deps, as well\n for (const { to, dev } of this.edgesOut.values()) {\n if (!dev && to?.dev) to.dev = false\n }\n }\n }\n\n isDev(): this is Node & { dev: true } {\n return this.#dev\n }\n\n /**\n * List of edges coming into this node.\n */\n edgesIn = new Set<Edge>()\n\n /**\n * List of edges from this node into other nodes. This usually represents\n * that the connected node is a direct dependency of this node.\n */\n edgesOut = new Map<string, Edge>()\n\n /**\n * A reference to the {@link DepID} this node represents in the graph.\n */\n id: DepID\n\n /**\n * True if this node is an importer node.\n */\n importer = false\n\n /**\n * True if this node is the project root node.\n */\n mainImporter = false\n\n /**\n * A reference to the graph this node is a part of.\n */\n graph: GraphLike\n\n /**\n * The manifest integrity value.\n */\n integrity?: Integrity\n\n /**\n * The manifest this node represents in the graph.\n */\n manifest?: Manifest\n\n /**\n * Project where this node resides\n */\n projectRoot: string\n\n /**\n * For registry nodes, this is the registry we fetched them from.\n * Needed because their un-prefixed dependencies need to come from\n * the same registry, if it's not the default.\n */\n registry?: string\n\n /**\n * The name of the package represented by this node, this is usually\n * equivalent to `manifest.name` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package names instead.\n */\n #name?: string\n get name() {\n if (this.#name) return this.#name\n this.#name = this.id\n return this.#name\n }\n\n /**\n * The location of the node_modules folder where this node's edgesOut\n * should be linked into. For nodes in the store, this is the parent\n * directory, since they're extracted into a node_modules folder\n * side by side with links to their deps. For nodes outside of the store\n * (ie, importers and arbitrary link deps) this is the node_modules folder\n * directly inside the node's directory.\n */\n get nodeModules() {\n const loc = this.location\n return this.inVltStore() ?\n loc.substring(0, loc.length - this.name.length - 1)\n : loc + '/node_modules'\n }\n\n /**\n * The version of the package represented by this node, this is usually\n * equivalent to `manifest.version` but in a few ways it may differ such as\n * nodes loaded from a lockfile that lacks a loaded manifest.\n * This field should be used to retrieve package versions instead.\n */\n version?: string\n\n /**\n * An address {@link PackageInfoClient} may use to extract this package.\n */\n resolved?: string\n\n /**\n * The file system location for this node.\n */\n get location(): string {\n if (this.#location) {\n return this.#location\n }\n this.#location = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`\n // if using the default location, it is in the store\n this.inVltStore = () => true\n return this.#location\n }\n\n set location(location: string) {\n this.#location = location\n // reset memoization, since it might be elsewhere now\n if (this.inVltStore !== Node.prototype.inVltStore) {\n this.inVltStore = Node.prototype.inVltStore\n }\n }\n\n constructor(\n options: NodeOptions,\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) {\n this.#options = options\n this.projectRoot = options.projectRoot\n if (id) {\n this.id = id\n } else {\n if (!manifest || !spec) {\n throw typeError(\n 'A new Node needs either a manifest & spec or an id parameter',\n {\n manifest,\n },\n )\n }\n this.id = getId(spec, manifest)\n }\n this.graph = options.graph\n this.manifest = manifest\n this.#name = name || this.manifest?.name\n this.version = version || this.manifest?.version\n }\n\n /**\n * return true if this node is located in the vlt store\n * memoized the first time it's called, since the store location\n * doesn't change within the context of a single operation.\n */\n inVltStore(): boolean {\n // technically this just means it's in *a* vlt store, but we can safely\n // assume that a user won't construct a path like this by accident,\n // and there's only ever one store in any given project.\n const inStore = this.location.endsWith(\n `.vlt/${this.id}/node_modules/${this.name}`,\n )\n this.inVltStore = () => inStore\n return inStore\n }\n\n #registryNodeResolved(tuple: DepIDTuple) {\n const spec = hydrateTuple(tuple, this.#name, this.#options)\n this.resolved =\n this.manifest?.dist?.tarball || spec.conventionalRegistryTarball\n this.integrity ??= this.manifest?.dist?.integrity\n }\n\n equals(other: Node) {\n return this.id === other.id && this.location === other.location\n }\n\n /**\n * Sets the node as an importer along with its location.\n */\n setImporterLocation(location: string) {\n this.#location = location\n this.importer = true\n }\n\n /**\n * Sets the appropriate resolve / integrity value for this node.\n * Note that other places might also set these values, like for\n * example the lockfile that might have already have this info.\n */\n setResolved() {\n // file | remote | workspace type of ids all points to a URI that\n // can be used as the `resolved` value, so we split the dep id\n // for these cases.\n const tuple = splitDepID(this.id)\n const [type, resolved] = tuple\n switch (type) {\n case 'registry':\n this.#registryNodeResolved(tuple)\n break\n default:\n this.resolved = resolved\n break\n }\n }\n\n setDefaultLocation() {\n const def = `./node_modules/.vlt/${this.id}/node_modules/${this.name}`\n\n // only relocate if the location is in node_modules already\n if (\n !this.importer &&\n (!this.#location ||\n (this.#location !== def &&\n /^(?:\\.\\/)?node_modules\\//.test(this.#location)))\n ) {\n this.#location = def\n }\n }\n\n /**\n * Add an edge from this node connecting it to a direct dependency.\n */\n addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node) {\n const edge = new Edge(type, spec, this, node)\n node?.edgesIn.add(edge)\n this.edgesOut.set(spec.name, edge)\n return edge\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n version: this.version,\n location: this.location,\n importer: this.importer,\n manifest: this.manifest,\n projectRoot: this.projectRoot,\n integrity: this.integrity,\n resolved: this.resolved,\n dev: this.dev,\n optional: this.optional,\n }\n }\n\n toString() {\n return stringifyNode(this)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-empty-list.d.ts","sourceRoot":"","sources":["../../src/non-empty-list.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,CAAC,QACxB,CAAC,EAAE,KACR,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAkB,CAAA;AAEpD,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,CAAC,EAAE,yCACC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-empty-list.js","sourceRoot":"","sources":["../../src/non-empty-list.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,IAAS,EACyB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAA;AAEpD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAI,KAAU,EAAE,EAAE,CAC5C,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA","sourcesContent":["export const isNonEmptyList = <T>(\n list: T[],\n): list is [first: T, ...rest: T[]] => !!list.length\n\nexport const nonEmptyList = <T>(nodes: T[]) =>\n isNonEmptyList(nodes) ? nodes : undefined\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
2
|
+
import { Manifest } from '@vltpkg/types';
|
|
3
|
+
import { PathScurry } from 'path-scurry';
|
|
4
|
+
import { Edge } from '../edge.js';
|
|
5
|
+
/**
|
|
6
|
+
* reify an edge into a node_modules folder, with bins linked
|
|
7
|
+
* this does NOT chmod the bins to 0o777, because they might not exist
|
|
8
|
+
* until scripts are run, in the case of non-store deps like workspaces
|
|
9
|
+
*/
|
|
10
|
+
export declare const addEdge: (edge: Edge, manifest: Manifest, scurry: PathScurry, remover: RollbackRemove) => Promise<void>;
|
|
11
|
+
//# sourceMappingURL=add-edge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-edge.d.ts","sourceRoot":"","sources":["../../../src/reify/add-edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAwBjC;;;;GAIG;AACH,eAAO,MAAM,OAAO,SACZ,IAAI,YACA,QAAQ,UACV,UAAU,WACT,cAAc,kBAmBxB,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { mkdir, symlink } from 'fs/promises';
|
|
2
|
+
import { dirname, relative } from 'path';
|
|
3
|
+
import { binPaths } from './bin-paths.js';
|
|
4
|
+
const clobberSymlink = async (target, link, remover, type = 'file') => {
|
|
5
|
+
await mkdir(dirname(link), { recursive: true });
|
|
6
|
+
try {
|
|
7
|
+
await symlink(target, link, type);
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
const er = e;
|
|
11
|
+
if (er.code === 'EEXIST') {
|
|
12
|
+
return remover.rm(link).then(() => symlink(target, link));
|
|
13
|
+
/* c8 ignore start */
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
throw er;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/* c8 ignore stop */
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* reify an edge into a node_modules folder, with bins linked
|
|
23
|
+
* this does NOT chmod the bins to 0o777, because they might not exist
|
|
24
|
+
* until scripts are run, in the case of non-store deps like workspaces
|
|
25
|
+
*/
|
|
26
|
+
export const addEdge = async (edge, manifest, scurry, remover) => {
|
|
27
|
+
if (!edge.to)
|
|
28
|
+
return;
|
|
29
|
+
const binRoot = scurry.resolve(edge.from.nodeModules, '.bin');
|
|
30
|
+
const path = scurry.resolve(edge.from.nodeModules, edge.spec.name);
|
|
31
|
+
const promises = [];
|
|
32
|
+
const target = relative(dirname(path), scurry.resolve(edge.to.location));
|
|
33
|
+
promises.push(clobberSymlink(target, path, remover, 'dir'));
|
|
34
|
+
const bp = binPaths(manifest);
|
|
35
|
+
for (const [key, val] of Object.entries(bp)) {
|
|
36
|
+
const link = scurry.resolve(binRoot, key);
|
|
37
|
+
const target = relative(binRoot, scurry.resolve(path, val));
|
|
38
|
+
// TODO: bash/cmd/pwsh shims on Windows
|
|
39
|
+
promises.push(clobberSymlink(target, link, remover));
|
|
40
|
+
}
|
|
41
|
+
await Promise.all(promises);
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=add-edge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-edge.js","sourceRoot":"","sources":["../../../src/reify/add-edge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,cAAc,GAAG,KAAK,EAC1B,MAAc,EACd,IAAY,EACZ,OAAuB,EACvB,IAAI,GAAG,MAAM,EACb,EAAE;IACF,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/C,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC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MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;QACzC,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;QAC3D,uCAAuC;QACvC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;IACtD,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["import { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { Manifest } from '@vltpkg/types'\nimport { mkdir, symlink } from 'fs/promises'\nimport { dirname, relative } from 'path'\nimport { PathScurry } from 'path-scurry'\nimport { Edge } from '../edge.js'\nimport { binPaths } from './bin-paths.js'\n\nconst clobberSymlink = async (\n target: string,\n link: string,\n remover: RollbackRemove,\n type = 'file',\n) => {\n await mkdir(dirname(link), { recursive: true })\n try {\n await symlink(target, link, type)\n } catch (e) {\n const er = e as NodeJS.ErrnoException\n if (er.code === 'EEXIST') {\n return remover.rm(link).then(() => symlink(target, link))\n /* c8 ignore start */\n } else {\n throw er\n }\n }\n /* c8 ignore stop */\n}\n\n/**\n * reify an edge into a node_modules folder, with bins linked\n * this does NOT chmod the bins to 0o777, because they might not exist\n * until scripts are run, in the case of non-store deps like workspaces\n */\nexport const addEdge = async (\n edge: Edge,\n manifest: Manifest,\n scurry: PathScurry,\n remover: RollbackRemove,\n) => {\n if (!edge.to) return\n const binRoot = scurry.resolve(edge.from.nodeModules, '.bin')\n const path = scurry.resolve(edge.from.nodeModules, edge.spec.name)\n const promises: Promise<unknown>[] = []\n const target = relative(\n dirname(path),\n scurry.resolve(edge.to.location),\n )\n promises.push(clobberSymlink(target, path, remover, 'dir'))\n const bp = binPaths(manifest)\n for (const [key, val] of Object.entries(bp)) {\n const link = scurry.resolve(binRoot, key)\n const target = relative(binRoot, scurry.resolve(path, val))\n // TODO: bash/cmd/pwsh shims on Windows\n promises.push(clobberSymlink(target, link, remover))\n }\n await Promise.all(promises)\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PackageJson } from '@vltpkg/package-json';
|
|
2
|
+
import type { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
3
|
+
import { PathScurry } from 'path-scurry';
|
|
4
|
+
import type { Diff } from '../diff.js';
|
|
5
|
+
export declare const addEdges: (diff: Diff, packageJson: PackageJson, scurry: PathScurry, remover: RollbackRemove) => Promise<unknown>[];
|
|
6
|
+
//# sourceMappingURL=add-edges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-edges.d.ts","sourceRoot":"","sources":["../../../src/reify/add-edges.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGtC,eAAO,MAAM,QAAQ,SACb,IAAI,eACG,WAAW,UAChB,UAAU,WACT,cAAc,KACtB,OAAO,CAAC,OAAO,CAAC,EASlB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { addEdge } from './add-edge.js';
|
|
2
|
+
export const addEdges = (diff, packageJson, scurry, remover) => {
|
|
3
|
+
const actions = [];
|
|
4
|
+
for (const edge of diff.edges.add) {
|
|
5
|
+
const { to } = edge;
|
|
6
|
+
if (!to)
|
|
7
|
+
continue;
|
|
8
|
+
const mani = to.manifest ?? packageJson.read(to.location);
|
|
9
|
+
actions.push(addEdge(edge, mani, scurry, remover));
|
|
10
|
+
}
|
|
11
|
+
return actions;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=add-edges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-edges.js","sourceRoot":"","sources":["../../../src/reify/add-edges.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAU,EACV,WAAwB,EACxB,MAAkB,EAClB,OAAuB,EACH,EAAE;IACtB,MAAM,OAAO,GAAuB,EAAE,CAAA;IACtC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAClC,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,EAAE;YAAE,SAAQ;QACjB,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;QACzD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACpD,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import type { PackageJson } from '@vltpkg/package-json'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { PathScurry } from 'path-scurry'\nimport type { Diff } from '../diff.js'\nimport { addEdge } from './add-edge.js'\n\nexport const addEdges = (\n diff: Diff,\n packageJson: PackageJson,\n scurry: PathScurry,\n remover: RollbackRemove,\n): Promise<unknown>[] => {\n const actions: Promise<unknown>[] = []\n for (const edge of diff.edges.add) {\n const { to } = edge\n if (!to) continue\n const mani = to.manifest ?? packageJson.read(to.location)\n actions.push(addEdge(edge, mani, scurry, remover))\n }\n return actions\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PackageInfoClient } from '@vltpkg/package-info';
|
|
2
|
+
import { RollbackRemove } from '@vltpkg/rollback-remove';
|
|
3
|
+
import { SpecOptions } from '@vltpkg/spec';
|
|
4
|
+
import { PathScurry } from 'path-scurry';
|
|
5
|
+
import { Diff } from '../diff.js';
|
|
6
|
+
export declare const addNodes: (diff: Diff, scurry: PathScurry, remover: RollbackRemove, options: SpecOptions, packageInfo: PackageInfoClient) => (() => Promise<unknown>)[];
|
|
7
|
+
//# sourceMappingURL=add-nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-nodes.d.ts","sourceRoot":"","sources":["../../../src/reify/add-nodes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAGjC,eAAO,MAAM,QAAQ,SACb,IAAI,UACF,UAAU,WACT,cAAc,WACd,WAAW,eACP,iBAAiB,KAC7B,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,EA0C1B,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { hydrate } from '@vltpkg/dep-id';
|
|
2
|
+
import { platformCheck } from '@vltpkg/pick-manifest';
|
|
3
|
+
import { optionalFail } from './optional-fail.js';
|
|
4
|
+
export const addNodes = (diff, scurry, remover, options, packageInfo) => {
|
|
5
|
+
const actions = [];
|
|
6
|
+
// fetch and extract all the nodes, removing any in the way
|
|
7
|
+
for (const node of diff.nodes.add) {
|
|
8
|
+
/* c8 ignore next - all nodes have manifests by this point */
|
|
9
|
+
const { manifest = {} } = node;
|
|
10
|
+
// if it's not in the store, we don't have to extract it, because
|
|
11
|
+
// we're just linking to a location that already exists.
|
|
12
|
+
if (!node.inVltStore())
|
|
13
|
+
continue;
|
|
14
|
+
// remove anything already there
|
|
15
|
+
const target = scurry.resolve(node.location);
|
|
16
|
+
const from = scurry.resolve('');
|
|
17
|
+
const spec = hydrate(node.id, manifest.name, options);
|
|
18
|
+
const onErr = optionalFail(diff, node);
|
|
19
|
+
// if it's optional, and we know it isn't for this platform, or it's
|
|
20
|
+
// deprecated, don't install it. if it's not optional, try our best.
|
|
21
|
+
if (onErr &&
|
|
22
|
+
(manifest.deprecated ||
|
|
23
|
+
!platformCheck(manifest, process.version, process.platform, process.arch))) {
|
|
24
|
+
onErr();
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
actions.push(() => remover
|
|
28
|
+
.rm(target)
|
|
29
|
+
.then(() => onErr ?
|
|
30
|
+
packageInfo
|
|
31
|
+
.extract(spec, target, { from })
|
|
32
|
+
.then(x => x, onErr)
|
|
33
|
+
: packageInfo.extract(spec, target, { from })));
|
|
34
|
+
}
|
|
35
|
+
return actions;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=add-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-nodes.js","sourceRoot":"","sources":["../../../src/reify/add-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAKrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,IAAU,EACV,MAAkB,EAClB,OAAuB,EACvB,OAAoB,EACpB,WAA8B,EACF,EAAE;IAC9B,MAAM,OAAO,GAA+B,EAAE,CAAA;IAC9C,2DAA2D;IAC3D,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAClC,6DAA6D;QAC7D,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,IAAI,CAAA;QAC9B,iEAAiE;QACjE,wDAAwD;QACxD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAAE,SAAQ;QAChC,gCAAgC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACrD,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACtC,oEAAoE;QACpE,oEAAoE;QACpE,IACE,KAAK;YACL,CAAC,QAAQ,CAAC,UAAU;gBAClB,CAAC,aAAa,CACZ,QAAQ,EACR,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,IAAI,CACb,CAAC,EACJ,CAAC;YACD,KAAK,EAAE,CAAA;YACP,SAAQ;QACV,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAChB,OAAO;aACJ,EAAE,CAAC,MAAM,CAAC;aACV,IAAI,CAAC,GAAG,EAAE,CACT,KAAK,CAAC,CAAC;YACL,WAAW;iBACR,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC;iBAC/B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC;YACxB,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAC9C,CACJ,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import { hydrate } from '@vltpkg/dep-id'\nimport { PackageInfoClient } from '@vltpkg/package-info'\nimport { platformCheck } from '@vltpkg/pick-manifest'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { SpecOptions } from '@vltpkg/spec'\nimport { PathScurry } from 'path-scurry'\nimport { Diff } from '../diff.js'\nimport { optionalFail } from './optional-fail.js'\n\nexport const addNodes = (\n diff: Diff,\n scurry: PathScurry,\n remover: RollbackRemove,\n options: SpecOptions,\n packageInfo: PackageInfoClient,\n): (() => Promise<unknown>)[] => {\n const actions: (() => Promise<unknown>)[] = []\n // fetch and extract all the nodes, removing any in the way\n for (const node of diff.nodes.add) {\n /* c8 ignore next - all nodes have manifests by this point */\n const { manifest = {} } = node\n // if it's not in the store, we don't have to extract it, because\n // we're just linking to a location that already exists.\n if (!node.inVltStore()) continue\n // remove anything already there\n const target = scurry.resolve(node.location)\n const from = scurry.resolve('')\n const spec = hydrate(node.id, manifest.name, options)\n const onErr = optionalFail(diff, node)\n // if it's optional, and we know it isn't for this platform, or it's\n // deprecated, don't install it. if it's not optional, try our best.\n if (\n onErr &&\n (manifest.deprecated ||\n !platformCheck(\n manifest,\n process.version,\n process.platform,\n process.arch,\n ))\n ) {\n onErr()\n continue\n }\n actions.push(() =>\n remover\n .rm(target)\n .then(() =>\n onErr ?\n packageInfo\n .extract(spec, target, { from })\n .then(x => x, onErr)\n : packageInfo.extract(spec, target, { from }),\n ),\n )\n }\n return actions\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin-paths.d.ts","sourceRoot":"","sources":["../../../src/reify/bin-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAUxC,wCAAwC;AACxC,eAAO,MAAM,QAAQ,aACT,QAAQ,KACjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAYvB,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const parseScope = (scoped) => {
|
|
2
|
+
if (scoped.startsWith('@')) {
|
|
3
|
+
const [scope, name, ...rest] = scoped.split('/');
|
|
4
|
+
if (scope && name && rest.length === 0)
|
|
5
|
+
return [scope, name];
|
|
6
|
+
}
|
|
7
|
+
return [undefined, scoped];
|
|
8
|
+
};
|
|
9
|
+
/** get the bin scripts for a package */
|
|
10
|
+
export const binPaths = (manifest) => {
|
|
11
|
+
const { name, bin } = manifest;
|
|
12
|
+
if (bin) {
|
|
13
|
+
if (name && typeof bin === 'string') {
|
|
14
|
+
const [_scope, pkg] = parseScope(name);
|
|
15
|
+
return { [pkg]: bin };
|
|
16
|
+
}
|
|
17
|
+
else if (typeof bin === 'object') {
|
|
18
|
+
return bin;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return {};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=bin-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin-paths.js","sourceRoot":"","sources":["../../../src/reify/bin-paths.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,CAAC,MAAc,EAAgC,EAAE;IAClE,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAChD,IAAI,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAA;AAED,wCAAwC;AACxC,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAkB,EACM,EAAE;IAC1B,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAA;IAE9B,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;YACtC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAA;QACvB,CAAC;aAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,GAAG,CAAA;QACZ,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC,CAAA","sourcesContent":["import { Manifest } from '@vltpkg/types'\n\nconst parseScope = (scoped: string): [string | undefined, string] => {\n if (scoped.startsWith('@')) {\n const [scope, name, ...rest] = scoped.split('/')\n if (scope && name && rest.length === 0) return [scope, name]\n }\n return [undefined, scoped]\n}\n\n/** get the bin scripts for a package */\nexport const binPaths = (\n manifest: Manifest,\n): Record<string, string> => {\n const { name, bin } = manifest\n\n if (bin) {\n if (name && typeof bin === 'string') {\n const [_scope, pkg] = parseScope(name)\n return { [pkg]: bin }\n } else if (typeof bin === 'object') {\n return bin\n }\n }\n return {}\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PackageJson } from '@vltpkg/package-json';
|
|
2
|
+
import { PathScurry } from 'path-scurry';
|
|
3
|
+
import { Diff } from '../diff.js';
|
|
4
|
+
export declare const build: (diff: Diff, packageJson: PackageJson, scurry: PathScurry) => Promise<void>;
|
|
5
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAKlD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAMjC,eAAO,MAAM,KAAK,SACV,IAAI,eACG,WAAW,UAChB,UAAU,kBAiCnB,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// walk the graph of added nodes, building and chmoding their bins
|
|
2
|
+
// at the end, we get back to the importers, and run their prepare
|
|
3
|
+
// script as well as install script.
|
|
4
|
+
import { run } from '@vltpkg/run';
|
|
5
|
+
import { statSync } from 'fs';
|
|
6
|
+
import { chmod } from 'fs/promises';
|
|
7
|
+
import { graphRun } from 'graph-run';
|
|
8
|
+
import { nonEmptyList } from '../non-empty-list.js';
|
|
9
|
+
import { binPaths } from './bin-paths.js';
|
|
10
|
+
import { optionalFail } from './optional-fail.js';
|
|
11
|
+
export const build = async (diff, packageJson, scurry) => {
|
|
12
|
+
const graph = diff.to;
|
|
13
|
+
const nodes = nonEmptyList([...graph.importers]);
|
|
14
|
+
/* c8 ignore next - all graphs have at least one importer */
|
|
15
|
+
if (!nodes)
|
|
16
|
+
return;
|
|
17
|
+
await graphRun({
|
|
18
|
+
graph: nodes,
|
|
19
|
+
visit: async (node, signal, path) => {
|
|
20
|
+
// if it's not an importer or an added node, nothing to do.
|
|
21
|
+
// TODO: only build importers if it has changed deps, there's never
|
|
22
|
+
// been a previous build, or it contains something newer than the
|
|
23
|
+
// most recent build.
|
|
24
|
+
// For now, just always build all importers, because we don't
|
|
25
|
+
// track all that other stuff.
|
|
26
|
+
if (!node.importer && !diff.nodes.add.has(node))
|
|
27
|
+
return;
|
|
28
|
+
await visit(packageJson, scurry, node, signal, path).then(x => x, optionalFail(diff, node));
|
|
29
|
+
},
|
|
30
|
+
getDeps: node => {
|
|
31
|
+
const deps = [];
|
|
32
|
+
for (const { to } of node.edgesOut.values()) {
|
|
33
|
+
/* c8 ignore next - vanishingly unlikely in practice */
|
|
34
|
+
if (to)
|
|
35
|
+
deps.push(to);
|
|
36
|
+
}
|
|
37
|
+
return deps;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const visit = async (packageJson, scurry, node, signal, _path) => {
|
|
42
|
+
node.manifest ??= packageJson.read(scurry.resolve(node.location));
|
|
43
|
+
const { manifest } = node;
|
|
44
|
+
const { scripts = {} } = manifest;
|
|
45
|
+
const { install, preinstall, postinstall, prepare, preprepare, postprepare, } = scripts;
|
|
46
|
+
// if it has install script, run it
|
|
47
|
+
const runInstall = !!(install || preinstall || postinstall);
|
|
48
|
+
if (runInstall) {
|
|
49
|
+
await run({
|
|
50
|
+
signal,
|
|
51
|
+
arg0: 'install',
|
|
52
|
+
ignoreMissing: true,
|
|
53
|
+
packageJson,
|
|
54
|
+
cwd: node.location,
|
|
55
|
+
projectRoot: node.projectRoot,
|
|
56
|
+
manifest,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// if it's an importer or git, run prepare
|
|
60
|
+
const prepable = node.id.startsWith('git') || node.importer || !node.inVltStore();
|
|
61
|
+
const runPrepare = !!(prepare || preprepare || postprepare) && prepable;
|
|
62
|
+
if (runPrepare) {
|
|
63
|
+
await run({
|
|
64
|
+
signal,
|
|
65
|
+
arg0: 'prepare',
|
|
66
|
+
ignoreMissing: true,
|
|
67
|
+
packageJson,
|
|
68
|
+
cwd: node.location,
|
|
69
|
+
projectRoot: node.projectRoot,
|
|
70
|
+
manifest,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const chmods = [];
|
|
74
|
+
for (const bin of Object.values(binPaths(manifest))) {
|
|
75
|
+
const path = scurry.resolve(node.location, bin);
|
|
76
|
+
chmods.push(makeExecutable(path));
|
|
77
|
+
}
|
|
78
|
+
await Promise.all(chmods);
|
|
79
|
+
};
|
|
80
|
+
// 0 is "not yet set"
|
|
81
|
+
// This is defined by doing `0o111 | <mode>` so that systems
|
|
82
|
+
// that create files group-writable result in 0o775 instead of 0o755
|
|
83
|
+
let execMode = 0;
|
|
84
|
+
const makeExecutable = async (path) => {
|
|
85
|
+
if (!execMode) {
|
|
86
|
+
execMode = (statSync(path).mode & 0o777) | 0o111;
|
|
87
|
+
}
|
|
88
|
+
await chmod(path, execMode);
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/reify/build.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAClE,oCAAoC;AAGpC,OAA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AI,WAAW,CAAC,IAAI,QAAQ,CAAA;IAEtD,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,GAAG,CAAC;YACR,MAAM;YACN,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,IAAI;YACnB,WAAW;YACX,GAAG,EAAE,IAAI,CAAC,QAAQ;YAClB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,MAAM,GAAuB,EAAE,CAAA;IACrC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;QAC/C,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;IACnC,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,qBAAqB;AACrB,4DAA4D;AAC5D,oEAAoE;AACpE,IAAI,QAAQ,GAAG,CAAC,CAAA;AAChB,MAAM,cAAc,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAA;IAClD,CAAC;IACD,MAAM,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["// walk the graph of added nodes, building and chmoding their bins\n// at the end, we get back to the importers, and run their prepare\n// script as well as install script.\n\nimport { PackageJson } from '@vltpkg/package-json'\nimport { run } from '@vltpkg/run'\nimport { statSync } from 'fs'\nimport { chmod } from 'fs/promises'\nimport { graphRun } from 'graph-run'\nimport { PathScurry } from 'path-scurry'\nimport { Diff } from '../diff.js'\nimport { Node } from '../node.js'\nimport { nonEmptyList } from '../non-empty-list.js'\nimport { binPaths } from './bin-paths.js'\nimport { optionalFail } from './optional-fail.js'\n\nexport const build = async (\n diff: Diff,\n packageJson: PackageJson,\n scurry: PathScurry,\n) => {\n const graph = diff.to\n const nodes = nonEmptyList([...graph.importers])\n /* c8 ignore next - all graphs have at least one importer */\n if (!nodes) return\n\n await graphRun<Node, unknown>({\n graph: nodes,\n visit: async (node: Node, signal, path) => {\n // if it's not an importer or an added node, nothing to do.\n // TODO: only build importers if it has changed deps, there's never\n // been a previous build, or it contains something newer than the\n // most recent build.\n // For now, just always build all importers, because we don't\n // track all that other stuff.\n if (!node.importer && !diff.nodes.add.has(node)) return\n\n await visit(packageJson, scurry, node, signal, path).then(\n x => x,\n optionalFail(diff, node),\n )\n },\n\n getDeps: node => {\n const deps: Node[] = []\n for (const { to } of node.edgesOut.values()) {\n /* c8 ignore next - vanishingly unlikely in practice */\n if (to) deps.push(to)\n }\n return deps\n },\n })\n}\n\nconst visit = async (\n packageJson: PackageJson,\n scurry: PathScurry,\n node: Node,\n signal: AbortSignal,\n _path: Node[],\n): Promise<void> => {\n node.manifest ??= packageJson.read(scurry.resolve(node.location))\n const { manifest } = node\n const { scripts = {} } = manifest\n\n const {\n install,\n preinstall,\n postinstall,\n prepare,\n preprepare,\n postprepare,\n } = scripts\n\n // if it has install script, run it\n const runInstall = !!(install || preinstall || postinstall)\n if (runInstall) {\n await run({\n signal,\n arg0: 'install',\n ignoreMissing: true,\n packageJson,\n cwd: node.location,\n projectRoot: node.projectRoot,\n manifest,\n })\n }\n\n // if it's an importer or git, run prepare\n const prepable =\n node.id.startsWith('git') || node.importer || !node.inVltStore()\n const runPrepare =\n !!(prepare || preprepare || postprepare) && prepable\n\n if (runPrepare) {\n await run({\n signal,\n arg0: 'prepare',\n ignoreMissing: true,\n packageJson,\n cwd: node.location,\n projectRoot: node.projectRoot,\n manifest,\n })\n }\n\n const chmods: Promise<unknown>[] = []\n for (const bin of Object.values(binPaths(manifest))) {\n const path = scurry.resolve(node.location, bin)\n chmods.push(makeExecutable(path))\n }\n await Promise.all(chmods)\n}\n\n// 0 is \"not yet set\"\n// This is defined by doing `0o111 | <mode>` so that systems\n// that create files group-writable result in 0o775 instead of 0o755\nlet execMode = 0\nconst makeExecutable = async (path: string) => {\n if (!execMode) {\n execMode = (statSync(path).mode & 0o777) | 0o111\n }\n await chmod(path, execMode)\n}\n"]}
|