@vltpkg/graph 0.0.0-3 → 0.0.0-30
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/README.md +148 -12
- package/dist/esm/actual/load.d.ts +44 -3
- package/dist/esm/actual/load.d.ts.map +1 -1
- package/dist/esm/actual/load.js +123 -73
- package/dist/esm/actual/load.js.map +1 -1
- package/dist/esm/browser.d.ts +8 -4
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +6 -2
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/dependencies.d.ts +14 -5
- package/dist/esm/dependencies.d.ts.map +1 -1
- package/dist/esm/dependencies.js +67 -2
- package/dist/esm/dependencies.js.map +1 -1
- package/dist/esm/diff.d.ts +5 -0
- package/dist/esm/diff.d.ts.map +1 -1
- package/dist/esm/diff.js +13 -0
- package/dist/esm/diff.js.map +1 -1
- package/dist/esm/edge.d.ts +2 -3
- package/dist/esm/edge.d.ts.map +1 -1
- package/dist/esm/edge.js +1 -1
- package/dist/esm/edge.js.map +1 -1
- package/dist/esm/graph.d.ts +22 -12
- package/dist/esm/graph.d.ts.map +1 -1
- package/dist/esm/graph.js +122 -23
- package/dist/esm/graph.js.map +1 -1
- package/dist/esm/ideal/add-nodes.d.ts +6 -1
- package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/add-nodes.js +9 -4
- package/dist/esm/ideal/add-nodes.js.map +1 -1
- package/dist/esm/ideal/append-nodes.d.ts +9 -1
- package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
- package/dist/esm/ideal/append-nodes.js +155 -31
- package/dist/esm/ideal/append-nodes.js.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
- package/dist/esm/ideal/build-ideal-from-starting-graph.js +9 -5
- package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
- package/dist/esm/ideal/build.d.ts +4 -0
- package/dist/esm/ideal/build.d.ts.map +1 -1
- package/dist/esm/ideal/build.js +2 -0
- package/dist/esm/ideal/build.js.map +1 -1
- package/dist/esm/ideal/get-importer-specs.d.ts +3 -2
- package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
- package/dist/esm/ideal/get-importer-specs.js +7 -5
- package/dist/esm/ideal/get-importer-specs.js.map +1 -1
- package/dist/esm/index.d.ts +6 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install.d.ts +4 -5
- package/dist/esm/install.d.ts.map +1 -1
- package/dist/esm/install.js +143 -23
- package/dist/esm/install.js.map +1 -1
- package/dist/esm/lockfile/load-edges.d.ts +8 -1
- package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
- package/dist/esm/lockfile/load-edges.js +79 -15
- package/dist/esm/lockfile/load-edges.js.map +1 -1
- package/dist/esm/lockfile/load-nodes.d.ts +3 -2
- package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
- package/dist/esm/lockfile/load-nodes.js +64 -11
- package/dist/esm/lockfile/load-nodes.js.map +1 -1
- package/dist/esm/lockfile/load.d.ts +18 -5
- package/dist/esm/lockfile/load.d.ts.map +1 -1
- package/dist/esm/lockfile/load.js +51 -22
- package/dist/esm/lockfile/load.js.map +1 -1
- package/dist/esm/lockfile/save.d.ts +8 -3
- package/dist/esm/lockfile/save.d.ts.map +1 -1
- package/dist/esm/lockfile/save.js +30 -12
- package/dist/esm/lockfile/save.js.map +1 -1
- package/dist/esm/lockfile/types.d.ts +17 -4
- package/dist/esm/lockfile/types.d.ts.map +1 -1
- package/dist/esm/lockfile/types.js.map +1 -1
- package/dist/esm/modifiers.d.ts +189 -0
- package/dist/esm/modifiers.d.ts.map +1 -0
- package/dist/esm/modifiers.js +330 -0
- package/dist/esm/modifiers.js.map +1 -0
- package/dist/esm/node.d.ts +54 -5
- package/dist/esm/node.d.ts.map +1 -1
- package/dist/esm/node.js +77 -2
- package/dist/esm/node.js.map +1 -1
- package/dist/esm/reify/add-edge.d.ts +1 -1
- package/dist/esm/reify/add-edge.d.ts.map +1 -1
- package/dist/esm/reify/add-edge.js +36 -14
- package/dist/esm/reify/add-edge.js.map +1 -1
- package/dist/esm/reify/add-nodes.d.ts.map +1 -1
- package/dist/esm/reify/add-nodes.js +4 -2
- package/dist/esm/reify/add-nodes.js.map +1 -1
- package/dist/esm/reify/bin-paths.d.ts +1 -1
- package/dist/esm/reify/bin-paths.d.ts.map +1 -1
- package/dist/esm/reify/bin-paths.js.map +1 -1
- package/dist/esm/reify/build.js +6 -3
- package/dist/esm/reify/build.js.map +1 -1
- package/dist/esm/reify/calculate-save-value.d.ts +3 -0
- package/dist/esm/reify/calculate-save-value.d.ts.map +1 -0
- package/dist/esm/reify/calculate-save-value.js +45 -0
- package/dist/esm/reify/calculate-save-value.js.map +1 -0
- package/dist/esm/reify/delete-edge.js +1 -1
- package/dist/esm/reify/delete-edge.js.map +1 -1
- package/dist/esm/reify/delete-nodes.d.ts.map +1 -1
- package/dist/esm/reify/delete-nodes.js +4 -0
- package/dist/esm/reify/delete-nodes.js.map +1 -1
- package/dist/esm/reify/index.d.ts +2 -0
- package/dist/esm/reify/index.d.ts.map +1 -1
- package/dist/esm/reify/index.js +20 -2
- package/dist/esm/reify/index.js.map +1 -1
- package/dist/esm/reify/internal-hoist.d.ts +9 -0
- package/dist/esm/reify/internal-hoist.d.ts.map +1 -0
- package/dist/esm/reify/internal-hoist.js +121 -0
- package/dist/esm/reify/internal-hoist.js.map +1 -0
- package/dist/esm/reify/update-importers-package-json.d.ts +1 -1
- package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
- package/dist/esm/reify/update-importers-package-json.js +35 -12
- package/dist/esm/reify/update-importers-package-json.js.map +1 -1
- package/dist/esm/remove-optional-subgraph.js +1 -1
- package/dist/esm/remove-optional-subgraph.js.map +1 -1
- package/dist/esm/resolve-save-type.d.ts +6 -0
- package/dist/esm/resolve-save-type.d.ts.map +1 -0
- package/dist/esm/resolve-save-type.js +5 -0
- package/dist/esm/resolve-save-type.js.map +1 -0
- package/dist/esm/stringify-node.d.ts +1 -1
- package/dist/esm/stringify-node.d.ts.map +1 -1
- package/dist/esm/stringify-node.js.map +1 -1
- package/dist/esm/transfer-data/load.d.ts +44 -0
- package/dist/esm/transfer-data/load.d.ts.map +1 -0
- package/dist/esm/transfer-data/load.js +176 -0
- package/dist/esm/transfer-data/load.js.map +1 -0
- package/dist/esm/uninstall.d.ts +3 -5
- package/dist/esm/uninstall.d.ts.map +1 -1
- package/dist/esm/uninstall.js +0 -3
- package/dist/esm/uninstall.js.map +1 -1
- package/dist/esm/update.d.ts +11 -0
- package/dist/esm/update.d.ts.map +1 -0
- package/dist/esm/update.js +49 -0
- package/dist/esm/update.js.map +1 -0
- package/dist/esm/virtual-root.d.ts +16 -0
- package/dist/esm/virtual-root.d.ts.map +1 -0
- package/dist/esm/virtual-root.js +78 -0
- package/dist/esm/virtual-root.js.map +1 -0
- package/dist/esm/visualization/human-readable-output.d.ts +4 -5
- package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
- package/dist/esm/visualization/human-readable-output.js +51 -24
- package/dist/esm/visualization/human-readable-output.js.map +1 -1
- package/dist/esm/visualization/json-output.d.ts +7 -3
- package/dist/esm/visualization/json-output.d.ts.map +1 -1
- package/dist/esm/visualization/json-output.js +35 -12
- package/dist/esm/visualization/json-output.js.map +1 -1
- package/dist/esm/visualization/mermaid-output.d.ts +7 -1
- package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
- package/dist/esm/visualization/mermaid-output.js +64 -9
- package/dist/esm/visualization/mermaid-output.js.map +1 -1
- package/dist/esm/visualization/object-like-output.d.ts +1 -1
- package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
- package/dist/esm/visualization/object-like-output.js.map +1 -1
- package/package.json +29 -25
- package/dist/esm/types.d.ts +0 -39
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { parseBreadcrumb, specificitySort, } from '@vltpkg/dss-breadcrumb';
|
|
2
|
+
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import { Spec } from '@vltpkg/spec';
|
|
4
|
+
import { asNormalizedManifest, assertRecordStringString, normalizeManifest, } from '@vltpkg/types';
|
|
5
|
+
import { load } from '@vltpkg/vlt-json';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing loaded modifiers configuration for a project.
|
|
8
|
+
*
|
|
9
|
+
* Instances of this class can be used as a helper to modify the graph
|
|
10
|
+
* during the graph build ideal traversal time.
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* const modifier = new GraphModifier(options)
|
|
14
|
+
* modifier.load(options)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* The `tryImporter` method can be used to register the initial importer
|
|
18
|
+
* node along with any modifier that includes an importer selector, e.g:
|
|
19
|
+
* `modifier.tryImporter(graph.mainImporter)`
|
|
20
|
+
*
|
|
21
|
+
* When traversing the graph, use the `tryNewDependency` method to check
|
|
22
|
+
* if a given dependency spec to the current traversed node has matching
|
|
23
|
+
* registered modifiers, e.g:
|
|
24
|
+
* `const entries = modifier.tryNewDependency(fromNode, depSpec)`
|
|
25
|
+
*
|
|
26
|
+
* Use `updateActiveEntry` to update a given active modifier entry state
|
|
27
|
+
* with the current node of the graph being traversed. e.g:
|
|
28
|
+
* ```
|
|
29
|
+
* for (const entry of entries)
|
|
30
|
+
* modifier.updateActiveEntry(fromNode, entry)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class GraphModifier {
|
|
34
|
+
/** The loaded modifiers configuration */
|
|
35
|
+
#config;
|
|
36
|
+
/** A set of all modifiers loaded from vlt.json */
|
|
37
|
+
#modifiers = new Set();
|
|
38
|
+
/** A set of all edge modifiers loaded from vlt.json */
|
|
39
|
+
#edgeModifiers = new Set();
|
|
40
|
+
/** A set of all node modifiers loaded from vlt.json */
|
|
41
|
+
#nodeModifiers = new Set();
|
|
42
|
+
/**
|
|
43
|
+
* A map of initial entries, keyed by the name of the first breadcrumb
|
|
44
|
+
* item to its modifier entry. Useful for checking for non-importer
|
|
45
|
+
* starting breadcrumbs, e.g: `#a > #b`
|
|
46
|
+
*/
|
|
47
|
+
#initialEntries = new Map();
|
|
48
|
+
/**
|
|
49
|
+
* A multi-level map of active entries, keyed by:
|
|
50
|
+
* - modifiers
|
|
51
|
+
* - edge name
|
|
52
|
+
* - from node
|
|
53
|
+
* that allows for retrieving seen {@link ModifierActiveEntry} instances
|
|
54
|
+
* in constant time.
|
|
55
|
+
*/
|
|
56
|
+
#activeEntries = new Map();
|
|
57
|
+
/**
|
|
58
|
+
* A set of currently active modifiers, which are being parsed.
|
|
59
|
+
*/
|
|
60
|
+
activeModifiers = new Set();
|
|
61
|
+
/** A set of all modifier string values loaded from vlt.json */
|
|
62
|
+
modifierNames = new Set();
|
|
63
|
+
constructor(options) {
|
|
64
|
+
this.load(options);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Load the modifiers definitions from vlt.json,
|
|
68
|
+
* converting the result into a GraphModifierConfigObject
|
|
69
|
+
*/
|
|
70
|
+
get config() {
|
|
71
|
+
if (this.#config)
|
|
72
|
+
return this.#config;
|
|
73
|
+
return (this.#config =
|
|
74
|
+
load('modifiers', assertRecordStringString) ?? {});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Loads the modifiers defined in `vlt.json` into memory.
|
|
78
|
+
*/
|
|
79
|
+
load(options) {
|
|
80
|
+
for (const [key, value] of Object.entries(this.config)) {
|
|
81
|
+
this.modifierNames.add(key);
|
|
82
|
+
const breadcrumb = parseBreadcrumb(key);
|
|
83
|
+
/* c8 ignore start - should not be possible */
|
|
84
|
+
if (!breadcrumb.last.name) {
|
|
85
|
+
throw error('Could not find name in breadcrumb', {
|
|
86
|
+
found: key,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/* c8 ignore stop */
|
|
90
|
+
let mod;
|
|
91
|
+
if (typeof value === 'string') {
|
|
92
|
+
mod = {
|
|
93
|
+
breadcrumb,
|
|
94
|
+
query: key,
|
|
95
|
+
refs: new Set(),
|
|
96
|
+
spec: Spec.parse(breadcrumb.last.name, value, options),
|
|
97
|
+
type: 'edge',
|
|
98
|
+
value,
|
|
99
|
+
};
|
|
100
|
+
this.#edgeModifiers.add(mod);
|
|
101
|
+
/* c8 ignore start - TODO */
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const manifest = asNormalizedManifest(normalizeManifest(value));
|
|
105
|
+
mod = {
|
|
106
|
+
breadcrumb,
|
|
107
|
+
query: key,
|
|
108
|
+
manifest,
|
|
109
|
+
refs: new Set(),
|
|
110
|
+
type: 'node',
|
|
111
|
+
value: manifest,
|
|
112
|
+
};
|
|
113
|
+
this.#nodeModifiers.add(mod);
|
|
114
|
+
}
|
|
115
|
+
/* c8 ignore end */
|
|
116
|
+
this.#modifiers.add(mod);
|
|
117
|
+
// if the breadcrumb starts with an id, then add it to the
|
|
118
|
+
// map of initial entries, so that we can use it to match
|
|
119
|
+
if (breadcrumb.first.name) {
|
|
120
|
+
const initialSet = this.#initialEntries.get(breadcrumb.first.name) ?? new Set();
|
|
121
|
+
initialSet.add(mod);
|
|
122
|
+
this.#initialEntries.set(breadcrumb.first.name, initialSet);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Try matching the provided node against the top-level selectors. In case
|
|
128
|
+
* a match is found it will also register the active entry modifier and
|
|
129
|
+
* update the active entry to the current importer node.
|
|
130
|
+
*/
|
|
131
|
+
tryImporter(importer) {
|
|
132
|
+
for (const modifier of this.#modifiers) {
|
|
133
|
+
// if the first item in the breadcrumb is an importer and it matches
|
|
134
|
+
// any of the valid top-level selectors, then register the modifier
|
|
135
|
+
const { first } = modifier.breadcrumb;
|
|
136
|
+
const matchRoot = first.value === ':root' && importer.mainImporter;
|
|
137
|
+
const matchWorkspace = first.value === ':workspace' && importer.importer;
|
|
138
|
+
const matchAny = first.value === ':project' || matchRoot || matchWorkspace;
|
|
139
|
+
if (first.importer && matchAny) {
|
|
140
|
+
const active = this.newModifier(importer, modifier);
|
|
141
|
+
const single = active.modifier.breadcrumb.single;
|
|
142
|
+
// only the importers will update the active entry right after
|
|
143
|
+
// registering it since tryImporter doesn't try to match from
|
|
144
|
+
// active dependencies
|
|
145
|
+
if (!single) {
|
|
146
|
+
this.updateActiveEntry(importer, active);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Try matching the provided node and spec to the current
|
|
153
|
+
* active parsing modifier entries along with possible starting-level
|
|
154
|
+
* modifiers.
|
|
155
|
+
*
|
|
156
|
+
* Any entries in which the breachcrumb have already reached its last
|
|
157
|
+
* element will be prioritized, along with checking for specificity,
|
|
158
|
+
* the complete entry with the highest specificity will be returned or just
|
|
159
|
+
* the entry with the highest specificity if no complete entry is found.
|
|
160
|
+
* Returns `undefined` if no matching entry is found.
|
|
161
|
+
*
|
|
162
|
+
* This method works with the assumption that it's going to be called
|
|
163
|
+
* during a graph traversal, such that any ascendent has been checked
|
|
164
|
+
* and the active modifier entry state has been updated in the previous
|
|
165
|
+
* iteration.
|
|
166
|
+
*/
|
|
167
|
+
tryNewDependency(from, spec) {
|
|
168
|
+
const { name, semver } = spec;
|
|
169
|
+
// here we use a map instead of a set so that we can associate each
|
|
170
|
+
// modifier active entry with its breadcrumb so that it's easier to
|
|
171
|
+
// pick the correct entry when we sort breadcrbumbs by specificity
|
|
172
|
+
const all = new Map();
|
|
173
|
+
for (const modifier of this.#modifiers) {
|
|
174
|
+
// if an active entry is found then returns that
|
|
175
|
+
const entry = this.#activeEntries
|
|
176
|
+
.get(modifier)
|
|
177
|
+
?.get(name)
|
|
178
|
+
?.get(from);
|
|
179
|
+
if (entry) {
|
|
180
|
+
all.set(entry.modifier.breadcrumb, entry);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// matches the name against the initial entries, this will make it so
|
|
184
|
+
// that modifier queries that start with a name (e.g: #a > #b) can
|
|
185
|
+
// match at any point of the graph traversal
|
|
186
|
+
const initialSet = this.#initialEntries.get(name) ?? new Set();
|
|
187
|
+
for (const initial of initialSet) {
|
|
188
|
+
const initialEntry =
|
|
189
|
+
/* c8 ignore next - difficult to test branch */
|
|
190
|
+
this.#activeEntries.get(initial)?.get(name)?.get(from) ??
|
|
191
|
+
this.newModifier(from, initial);
|
|
192
|
+
all.set(initialEntry.modifier.breadcrumb, initialEntry);
|
|
193
|
+
}
|
|
194
|
+
// selects the active entry that should apply to this dependency,
|
|
195
|
+
// any active entry that is done parsing has the priority, if we
|
|
196
|
+
// find multiple entries then we use css specificity to pick a winner
|
|
197
|
+
// if we have multiple matches but no active entry is complete, then
|
|
198
|
+
// we pick the one with the highest specificity breadcrumb
|
|
199
|
+
const arr = [...all.values()];
|
|
200
|
+
const completeEntries = arr.filter(active => active.interactiveBreadcrumb.current ===
|
|
201
|
+
active.modifier.breadcrumb.last);
|
|
202
|
+
// deregister completed entries
|
|
203
|
+
for (const entry of completeEntries) {
|
|
204
|
+
this.deregisterModifier(entry.modifier);
|
|
205
|
+
}
|
|
206
|
+
// returns the highest specificity entry from either the complete entries
|
|
207
|
+
// if any were found or from any of the entries if available, otherwise
|
|
208
|
+
// it will return undefined as no entry is found in the `all` map
|
|
209
|
+
const entries = completeEntries.length ? completeEntries : arr;
|
|
210
|
+
return all.get(specificitySort(entries
|
|
211
|
+
// here we filter out any entries that do not match the
|
|
212
|
+
// pseudo selector comparators used in the breadcrumb item
|
|
213
|
+
.filter(i => i.interactiveBreadcrumb.current?.comparator({
|
|
214
|
+
semver,
|
|
215
|
+
}))
|
|
216
|
+
.map(i => i.modifier.breadcrumb))[0]);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns the set of {@link ModifierActiveEntry} instances that matches
|
|
220
|
+
* the provided {@link Dependency} specs for a given node.
|
|
221
|
+
*
|
|
222
|
+
* This method is mostly a helper to {@link GraphModifier.tryNewDependency}
|
|
223
|
+
* that handles the registered modifiers traversal lookup.
|
|
224
|
+
*/
|
|
225
|
+
tryDependencies(from, dependencies) {
|
|
226
|
+
const modifierRefs = new Map();
|
|
227
|
+
for (const { spec } of dependencies) {
|
|
228
|
+
const active = this.tryNewDependency(from, spec);
|
|
229
|
+
if (active) {
|
|
230
|
+
modifierRefs.set(spec.name, active);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return modifierRefs;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Updates an active entry state keeping track of items in the multi-level
|
|
237
|
+
* active entries map. If the current breadcrumb state shows there's no more
|
|
238
|
+
* items left, then we deregister the modifier.
|
|
239
|
+
*/
|
|
240
|
+
updateActiveEntry(from, active) {
|
|
241
|
+
const { modifier } = active;
|
|
242
|
+
const interactiveBreadcrumb = active.interactiveBreadcrumb.next();
|
|
243
|
+
const name = interactiveBreadcrumb.current?.name;
|
|
244
|
+
// if there's no name, or we're done parsing then we
|
|
245
|
+
// deregister the modifier instead of updating the entry
|
|
246
|
+
if (interactiveBreadcrumb.done || !name) {
|
|
247
|
+
this.deregisterModifier(modifier);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
// register the active modifier
|
|
251
|
+
this.activeModifiers.add(active);
|
|
252
|
+
active.modifier.refs.add({ from, name });
|
|
253
|
+
// optionally read or create the nested maps
|
|
254
|
+
const nameMap = this.#activeEntries.get(modifier) ??
|
|
255
|
+
new Map();
|
|
256
|
+
this.#activeEntries.set(modifier, nameMap);
|
|
257
|
+
const nodeMap = nameMap.get(name) ?? new Map();
|
|
258
|
+
nameMap.set(name, nodeMap);
|
|
259
|
+
// sets the active entry in the map
|
|
260
|
+
nodeMap.set(from, active);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Creates a new active modifier.
|
|
264
|
+
*/
|
|
265
|
+
newModifier(from, modifier) {
|
|
266
|
+
return {
|
|
267
|
+
modifier,
|
|
268
|
+
interactiveBreadcrumb: modifier.breadcrumb.interactive(),
|
|
269
|
+
originalFrom: from,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Removes a previously registered modifier from the active entries.
|
|
274
|
+
*/
|
|
275
|
+
deregisterModifier(modifier) {
|
|
276
|
+
for (const { from, name } of modifier.refs) {
|
|
277
|
+
const nodeMap = this.#activeEntries.get(modifier)?.get(name);
|
|
278
|
+
if (nodeMap) {
|
|
279
|
+
// if an entry is found, we remove it from the active set
|
|
280
|
+
const entry = nodeMap.get(from);
|
|
281
|
+
if (entry) {
|
|
282
|
+
this.activeModifiers.delete(entry);
|
|
283
|
+
}
|
|
284
|
+
// then we remove the entry from the map
|
|
285
|
+
nodeMap.delete(from);
|
|
286
|
+
// if the map is empty, we remove it from the active entries map
|
|
287
|
+
if (!nodeMap.size) {
|
|
288
|
+
this.#activeEntries.get(modifier)?.delete(name);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Operates in previously registered nodes and edges in order to put
|
|
295
|
+
* back in place any of the original edges that were referenced to in
|
|
296
|
+
* active (ongoing) breadcrumb parsing entries that were never completed.
|
|
297
|
+
*
|
|
298
|
+
* This method can be used to easily rollback any pending operations
|
|
299
|
+
* once the graph traversal is done.
|
|
300
|
+
*/
|
|
301
|
+
rollbackActiveEntries() {
|
|
302
|
+
for (const modifier of this.activeModifiers) {
|
|
303
|
+
// if the modifier has an original edge, we can put it back in place
|
|
304
|
+
if (modifier.originalEdge) {
|
|
305
|
+
modifier.originalFrom.edgesOut.set(modifier.originalEdge.spec.name, modifier.originalEdge);
|
|
306
|
+
}
|
|
307
|
+
// then we deregister the modifier
|
|
308
|
+
this.deregisterModifier(modifier.modifier);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Convenience method to instantiate and load in one call.
|
|
313
|
+
* Returns undefined if the project does not have a vlt.json file,
|
|
314
|
+
* otherwise returns the loaded Modifiers instance.
|
|
315
|
+
*/
|
|
316
|
+
static maybeLoad(options) {
|
|
317
|
+
const config = load('modifiers', assertRecordStringString);
|
|
318
|
+
if (!config)
|
|
319
|
+
return;
|
|
320
|
+
return new GraphModifier(options);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Convenience method to instantiate and load in one call.
|
|
324
|
+
* Throws if called on a directory that does not have a vlt.json file.
|
|
325
|
+
*/
|
|
326
|
+
static load(options) {
|
|
327
|
+
return new GraphModifier(options);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=modifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../../src/modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,GAChB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAyFvC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,aAAa;IACxB,yCAAyC;IACzC,OAAO,CAA4B;IACnC,kDAAkD;IAClD,UAAU,GAAG,IAAI,GAAG,EAAiB,CAAA;IACrC,uDAAuD;IACvD,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC7C,uDAAuD;IACvD,cAAc,GAAG,IAAI,GAAG,EAAqB,CAAA;IAC7C;;;;OAIG;IACH,eAAe,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD;;;;;;;OAOG;IACH,cAAc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AI,QAAQ,CAAC,YAAY,EAAE,CAAC;gBAC1B,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAC/B,QAAQ,CAAC,YAAY,CACtB,CAAA;YACH,CAAC;YACD,kCAAkC;YAClC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,OAAoB;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAA;QAC1D,IAAI,CAAC,MAAM;YAAE,OAAM;QACnB,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAoB;QAC9B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC;CACF","sourcesContent":["import {\n parseBreadcrumb,\n specificitySort,\n} from '@vltpkg/dss-breadcrumb'\nimport { error } from '@vltpkg/error-cause'\nimport { Spec } from '@vltpkg/spec'\nimport {\n asNormalizedManifest,\n assertRecordStringString,\n normalizeManifest,\n} from '@vltpkg/types'\nimport { load } from '@vltpkg/vlt-json'\nimport type {\n ModifierBreadcrumb,\n ModifierInteractiveBreadcrumb,\n} from '@vltpkg/dss-breadcrumb'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport type { Edge } from './edge.ts'\nimport type { Node } from './node.ts'\nimport type { Dependency } from './dependencies.ts'\n\n/**\n * Loaded modifiers configuration as described in the `vlt.json` file.\n */\nexport type GraphModifierLoadedConfig = {\n modifiers: GraphModifierConfigObject\n}\n\n/**\n * Type definition for the modifiers configuration object\n */\n// TODO: subtype string into a more specific type for Queries\nexport type GraphModifierConfigObject = Record<string, string>\n\n/**\n * Info needed to define a graph modifier.\n */\nexport type BaseModifierEntry = {\n type: 'edge' | 'node'\n query: string\n breadcrumb: ModifierBreadcrumb\n value: string | NormalizedManifest\n refs: Set<{\n name: string\n from: Node\n }>\n}\n\n/**\n * Extra info to define specifically a graph edge modifier.\n */\nexport type EdgeModifierEntry = BaseModifierEntry & {\n type: 'edge'\n spec: Spec\n value: string\n}\n\n/**\n * Extra info to define the graph node modifier.\n */\nexport type NodeModifierEntry = BaseModifierEntry & {\n type: 'node'\n manifest: NormalizedManifest\n}\n\n/**\n * A graph modifier entry, which can be either an edge or a node modifier.\n */\nexport type ModifierEntry = EdgeModifierEntry | NodeModifierEntry\n\n/**\n * An object to track modifiers that have matched an initial part of the\n * breadcrumb. It holds pointers to both nodes and edges matched in the\n * current traversed graph on top of the modifier info and the breadcrumb\n * state that is used to track the current state of the parsing.\n */\nexport type ModifierActiveEntry = {\n /**\n * The modifier this active entry is working with.\n */\n modifier: ModifierEntry\n /**\n * The breadcrumb that is used to track the current state of the parsing.\n */\n interactiveBreadcrumb: ModifierInteractiveBreadcrumb\n /**\n * The first node to be affected by this modifier.\n */\n originalFrom: Node\n /**\n * The original edge that is being replaced with this entry.\n */\n originalEdge?: Edge\n /**\n * The modified edge that is being used to replace the original edge.\n */\n modifiedEdge?: Edge\n}\n\n/**\n * Class representing loaded modifiers configuration for a project.\n *\n * Instances of this class can be used as a helper to modify the graph\n * during the graph build ideal traversal time.\n *\n * ```\n * const modifier = new GraphModifier(options)\n * modifier.load(options)\n * ```\n *\n * The `tryImporter` method can be used to register the initial importer\n * node along with any modifier that includes an importer selector, e.g:\n * `modifier.tryImporter(graph.mainImporter)`\n *\n * When traversing the graph, use the `tryNewDependency` method to check\n * if a given dependency spec to the current traversed node has matching\n * registered modifiers, e.g:\n * `const entries = modifier.tryNewDependency(fromNode, depSpec)`\n *\n * Use `updateActiveEntry` to update a given active modifier entry state\n * with the current node of the graph being traversed. e.g:\n * ```\n * for (const entry of entries)\n * modifier.updateActiveEntry(fromNode, entry)\n * ```\n */\nexport class GraphModifier {\n /** The loaded modifiers configuration */\n #config?: GraphModifierConfigObject\n /** A set of all modifiers loaded from vlt.json */\n #modifiers = new Set<ModifierEntry>()\n /** A set of all edge modifiers loaded from vlt.json */\n #edgeModifiers = new Set<EdgeModifierEntry>()\n /** A set of all node modifiers loaded from vlt.json */\n #nodeModifiers = new Set<NodeModifierEntry>()\n /**\n * A map of initial entries, keyed by the name of the first breadcrumb\n * item to its modifier entry. Useful for checking for non-importer\n * starting breadcrumbs, e.g: `#a > #b`\n */\n #initialEntries = new Map<string, Set<ModifierEntry>>()\n /**\n * A multi-level map of active entries, keyed by:\n * - modifiers\n * - edge name\n * - from node\n * that allows for retrieving seen {@link ModifierActiveEntry} instances\n * in constant time.\n */\n #activeEntries = new Map<\n ModifierEntry,\n Map<string, Map<Node, ModifierActiveEntry>>\n >()\n /**\n * A set of currently active modifiers, which are being parsed.\n */\n activeModifiers = new Set<ModifierActiveEntry>()\n /** A set of all modifier string values loaded from vlt.json */\n modifierNames = new Set<string>()\n\n constructor(options: SpecOptions) {\n this.load(options)\n }\n\n /**\n * Load the modifiers definitions from vlt.json,\n * converting the result into a GraphModifierConfigObject\n */\n get config(): GraphModifierConfigObject {\n if (this.#config) return this.#config\n return (this.#config =\n load('modifiers', assertRecordStringString) ?? {})\n }\n\n /**\n * Loads the modifiers defined in `vlt.json` into memory.\n */\n load(options: SpecOptions) {\n for (const [key, value] of Object.entries(this.config)) {\n this.modifierNames.add(key)\n const breadcrumb = parseBreadcrumb(key)\n /* c8 ignore start - should not be possible */\n if (!breadcrumb.last.name) {\n throw error('Could not find name in breadcrumb', {\n found: key,\n })\n }\n /* c8 ignore stop */\n let mod: ModifierEntry\n if (typeof value === 'string') {\n mod = {\n breadcrumb,\n query: key,\n refs: new Set(),\n spec: Spec.parse(breadcrumb.last.name, value, options),\n type: 'edge',\n value,\n } satisfies EdgeModifierEntry\n this.#edgeModifiers.add(mod)\n /* c8 ignore start - TODO */\n } else {\n const manifest = asNormalizedManifest(\n normalizeManifest(value),\n )\n mod = {\n breadcrumb,\n query: key,\n manifest,\n refs: new Set(),\n type: 'node',\n value: manifest,\n } satisfies NodeModifierEntry\n this.#nodeModifiers.add(mod)\n }\n /* c8 ignore end */\n this.#modifiers.add(mod)\n // if the breadcrumb starts with an id, then add it to the\n // map of initial entries, so that we can use it to match\n if (breadcrumb.first.name) {\n const initialSet =\n this.#initialEntries.get(breadcrumb.first.name) ?? new Set()\n initialSet.add(mod)\n this.#initialEntries.set(breadcrumb.first.name, initialSet)\n }\n }\n }\n\n /**\n * Try matching the provided node against the top-level selectors. In case\n * a match is found it will also register the active entry modifier and\n * update the active entry to the current importer node.\n */\n tryImporter(importer: Node) {\n for (const modifier of this.#modifiers) {\n // if the first item in the breadcrumb is an importer and it matches\n // any of the valid top-level selectors, then register the modifier\n const { first } = modifier.breadcrumb\n const matchRoot =\n first.value === ':root' && importer.mainImporter\n const matchWorkspace =\n first.value === ':workspace' && importer.importer\n const matchAny =\n first.value === ':project' || matchRoot || matchWorkspace\n if (first.importer && matchAny) {\n const active = this.newModifier(importer, modifier)\n const single = active.modifier.breadcrumb.single\n // only the importers will update the active entry right after\n // registering it since tryImporter doesn't try to match from\n // active dependencies\n if (!single) {\n this.updateActiveEntry(importer, active)\n }\n }\n }\n }\n\n /**\n * Try matching the provided node and spec to the current\n * active parsing modifier entries along with possible starting-level\n * modifiers.\n *\n * Any entries in which the breachcrumb have already reached its last\n * element will be prioritized, along with checking for specificity,\n * the complete entry with the highest specificity will be returned or just\n * the entry with the highest specificity if no complete entry is found.\n * Returns `undefined` if no matching entry is found.\n *\n * This method works with the assumption that it's going to be called\n * during a graph traversal, such that any ascendent has been checked\n * and the active modifier entry state has been updated in the previous\n * iteration.\n */\n tryNewDependency(\n from: Node,\n spec: Spec,\n ): ModifierActiveEntry | undefined {\n const { name, semver } = spec\n // here we use a map instead of a set so that we can associate each\n // modifier active entry with its breadcrumb so that it's easier to\n // pick the correct entry when we sort breadcrbumbs by specificity\n const all = new Map<\n ModifierBreadcrumb | undefined,\n ModifierActiveEntry\n >()\n for (const modifier of this.#modifiers) {\n // if an active entry is found then returns that\n const entry = this.#activeEntries\n .get(modifier)\n ?.get(name)\n ?.get(from)\n if (entry) {\n all.set(entry.modifier.breadcrumb, entry)\n }\n }\n // matches the name against the initial entries, this will make it so\n // that modifier queries that start with a name (e.g: #a > #b) can\n // match at any point of the graph traversal\n const initialSet =\n this.#initialEntries.get(name) ?? new Set<ModifierEntry>()\n for (const initial of initialSet) {\n const initialEntry =\n /* c8 ignore next - difficult to test branch */\n this.#activeEntries.get(initial)?.get(name)?.get(from) ??\n this.newModifier(from, initial)\n all.set(initialEntry.modifier.breadcrumb, initialEntry)\n }\n // selects the active entry that should apply to this dependency,\n // any active entry that is done parsing has the priority, if we\n // find multiple entries then we use css specificity to pick a winner\n // if we have multiple matches but no active entry is complete, then\n // we pick the one with the highest specificity breadcrumb\n const arr = [...all.values()]\n const completeEntries = arr.filter(\n active =>\n active.interactiveBreadcrumb.current ===\n active.modifier.breadcrumb.last,\n )\n // deregister completed entries\n for (const entry of completeEntries) {\n this.deregisterModifier(entry.modifier)\n }\n // returns the highest specificity entry from either the complete entries\n // if any were found or from any of the entries if available, otherwise\n // it will return undefined as no entry is found in the `all` map\n const entries = completeEntries.length ? completeEntries : arr\n return all.get(\n specificitySort(\n entries\n // here we filter out any entries that do not match the\n // pseudo selector comparators used in the breadcrumb item\n .filter(i =>\n i.interactiveBreadcrumb.current?.comparator({\n semver,\n }),\n )\n .map(i => i.modifier.breadcrumb),\n )[0],\n )\n }\n\n /**\n * Returns the set of {@link ModifierActiveEntry} instances that matches\n * the provided {@link Dependency} specs for a given node.\n *\n * This method is mostly a helper to {@link GraphModifier.tryNewDependency}\n * that handles the registered modifiers traversal lookup.\n */\n tryDependencies(\n from: Node,\n dependencies: Dependency[] | Edge[],\n ): Map<string, ModifierActiveEntry> {\n const modifierRefs = new Map<string, ModifierActiveEntry>()\n for (const { spec } of dependencies) {\n const active = this.tryNewDependency(from, spec)\n if (active) {\n modifierRefs.set(spec.name, active)\n }\n }\n return modifierRefs\n }\n\n /**\n * Updates an active entry state keeping track of items in the multi-level\n * active entries map. If the current breadcrumb state shows there's no more\n * items left, then we deregister the modifier.\n */\n updateActiveEntry(from: Node, active: ModifierActiveEntry): void {\n const { modifier } = active\n const interactiveBreadcrumb = active.interactiveBreadcrumb.next()\n const name = interactiveBreadcrumb.current?.name\n\n // if there's no name, or we're done parsing then we\n // deregister the modifier instead of updating the entry\n if (interactiveBreadcrumb.done || !name) {\n this.deregisterModifier(modifier)\n return\n }\n\n // register the active modifier\n this.activeModifiers.add(active)\n active.modifier.refs.add({ from, name })\n\n // optionally read or create the nested maps\n const nameMap =\n this.#activeEntries.get(modifier) ??\n new Map<string, Map<Node, ModifierActiveEntry>>()\n this.#activeEntries.set(modifier, nameMap)\n const nodeMap =\n nameMap.get(name) ?? new Map<Node, ModifierActiveEntry>()\n nameMap.set(name, nodeMap)\n\n // sets the active entry in the map\n nodeMap.set(from, active)\n }\n\n /**\n * Creates a new active modifier.\n */\n newModifier(\n from: Node,\n modifier: ModifierEntry,\n ): ModifierActiveEntry {\n return {\n modifier,\n interactiveBreadcrumb: modifier.breadcrumb.interactive(),\n originalFrom: from,\n }\n }\n\n /**\n * Removes a previously registered modifier from the active entries.\n */\n deregisterModifier(modifier: ModifierEntry): void {\n for (const { from, name } of modifier.refs) {\n const nodeMap = this.#activeEntries.get(modifier)?.get(name)\n if (nodeMap) {\n // if an entry is found, we remove it from the active set\n const entry = nodeMap.get(from)\n if (entry) {\n this.activeModifiers.delete(entry)\n }\n // then we remove the entry from the map\n nodeMap.delete(from)\n // if the map is empty, we remove it from the active entries map\n if (!nodeMap.size) {\n this.#activeEntries.get(modifier)?.delete(name)\n }\n }\n }\n }\n\n /**\n * Operates in previously registered nodes and edges in order to put\n * back in place any of the original edges that were referenced to in\n * active (ongoing) breadcrumb parsing entries that were never completed.\n *\n * This method can be used to easily rollback any pending operations\n * once the graph traversal is done.\n */\n rollbackActiveEntries(): void {\n for (const modifier of this.activeModifiers) {\n // if the modifier has an original edge, we can put it back in place\n if (modifier.originalEdge) {\n modifier.originalFrom.edgesOut.set(\n modifier.originalEdge.spec.name,\n modifier.originalEdge,\n )\n }\n // then we deregister the modifier\n this.deregisterModifier(modifier.modifier)\n }\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Returns undefined if the project does not have a vlt.json file,\n * otherwise returns the loaded Modifiers instance.\n */\n static maybeLoad(options: SpecOptions) {\n const config = load('modifiers', assertRecordStringString)\n if (!config) return\n return new GraphModifier(options)\n }\n\n /**\n * Convenience method to instantiate and load in one call.\n * Throws if called on a directory that does not have a vlt.json file.\n */\n static load(options: SpecOptions) {\n return new GraphModifier(options)\n }\n}\n"]}
|
package/dist/esm/node.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { PathScurry } from 'path-scurry';
|
|
2
2
|
import type { DepID } from '@vltpkg/dep-id';
|
|
3
3
|
import type { Spec, SpecOptions } from '@vltpkg/spec';
|
|
4
|
-
import type { Integrity,
|
|
4
|
+
import type { Integrity, NormalizedManifest, DependencyTypeShort, GraphLike, NodeLike } from '@vltpkg/types';
|
|
5
5
|
import { Edge } from './edge.ts';
|
|
6
|
-
import type { GraphLike, NodeLike } from './types.ts';
|
|
7
6
|
export type NodeOptions = SpecOptions & {
|
|
8
7
|
projectRoot: string;
|
|
9
8
|
graph: GraphLike;
|
|
@@ -34,6 +33,10 @@ export declare class Node implements NodeLike {
|
|
|
34
33
|
isDev(): this is Node & {
|
|
35
34
|
dev: true;
|
|
36
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* True if there's a manifest-confused package name.
|
|
38
|
+
*/
|
|
39
|
+
confused: boolean;
|
|
37
40
|
/**
|
|
38
41
|
* List of edges coming into this node.
|
|
39
42
|
*/
|
|
@@ -43,6 +46,11 @@ export declare class Node implements NodeLike {
|
|
|
43
46
|
* that the connected node is a direct dependency of this node.
|
|
44
47
|
*/
|
|
45
48
|
edgesOut: Map<string, Edge>;
|
|
49
|
+
/**
|
|
50
|
+
* A `mainImporter` node may have workspace connected to it,
|
|
51
|
+
* equivalent to its `edgesOut` linked deps.
|
|
52
|
+
*/
|
|
53
|
+
workspaces: Map<string, Edge> | undefined;
|
|
46
54
|
/**
|
|
47
55
|
* A reference to the {@link DepID} this node represents in the graph.
|
|
48
56
|
*/
|
|
@@ -66,7 +74,7 @@ export declare class Node implements NodeLike {
|
|
|
66
74
|
/**
|
|
67
75
|
* The manifest this node represents in the graph.
|
|
68
76
|
*/
|
|
69
|
-
manifest?:
|
|
77
|
+
manifest?: NormalizedManifest;
|
|
70
78
|
/**
|
|
71
79
|
* Project where this node resides
|
|
72
80
|
*/
|
|
@@ -77,6 +85,12 @@ export declare class Node implements NodeLike {
|
|
|
77
85
|
* the same registry, if it's not the default.
|
|
78
86
|
*/
|
|
79
87
|
registry?: string;
|
|
88
|
+
/**
|
|
89
|
+
* If this node has been modified as part of applying a {@link GraphModifier}
|
|
90
|
+
* then this field will contain the modifier query that was applied.
|
|
91
|
+
* Otherwise, it will be `undefined`.
|
|
92
|
+
*/
|
|
93
|
+
modifier: string | undefined;
|
|
80
94
|
get name(): string;
|
|
81
95
|
/**
|
|
82
96
|
* The version of the package represented by this node, this is usually
|
|
@@ -89,6 +103,16 @@ export declare class Node implements NodeLike {
|
|
|
89
103
|
* An address {@link PackageInfoClient} may use to extract this package.
|
|
90
104
|
*/
|
|
91
105
|
resolved?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Platform requirements (engines, os, cpu) extracted from manifest.
|
|
108
|
+
* Stored separately for optional dependencies to enable platform checks
|
|
109
|
+
* when manifest is not loaded.
|
|
110
|
+
*/
|
|
111
|
+
platform?: {
|
|
112
|
+
engines?: Record<string, string>;
|
|
113
|
+
os?: string[] | string;
|
|
114
|
+
cpu?: string[] | string;
|
|
115
|
+
};
|
|
92
116
|
/**
|
|
93
117
|
* The file system location for this node.
|
|
94
118
|
*/
|
|
@@ -107,13 +131,15 @@ export declare class Node implements NodeLike {
|
|
|
107
131
|
* directly inside the node's directory.
|
|
108
132
|
*/
|
|
109
133
|
nodeModules(scurry: PathScurry): string;
|
|
110
|
-
constructor(options: NodeOptions, id?: DepID, manifest?:
|
|
134
|
+
constructor(options: NodeOptions, id?: DepID, manifest?: NormalizedManifest, spec?: Spec, name?: string, version?: string);
|
|
111
135
|
/**
|
|
112
136
|
* return true if this node is located in the vlt store
|
|
113
137
|
* memoized the first time it's called, since the store location
|
|
114
138
|
* doesn't change within the context of a single operation.
|
|
115
139
|
*/
|
|
116
140
|
inVltStore(): boolean;
|
|
141
|
+
get options(): SpecOptions;
|
|
142
|
+
set options(_opts: SpecOptions);
|
|
117
143
|
equals(other: Node): boolean;
|
|
118
144
|
/**
|
|
119
145
|
* Sets the node as an importer along with its location.
|
|
@@ -130,19 +156,42 @@ export declare class Node implements NodeLike {
|
|
|
130
156
|
* Add an edge from this node connecting it to a direct dependency.
|
|
131
157
|
*/
|
|
132
158
|
addEdgesTo(type: DependencyTypeShort, spec: Spec, node?: Node): Edge;
|
|
159
|
+
/**
|
|
160
|
+
* The raw manifest before any modifications.
|
|
161
|
+
* If not set, falls back to the current manifest.
|
|
162
|
+
*/
|
|
163
|
+
get rawManifest(): NormalizedManifest | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Sets this node as having a manifest-confused manifest.
|
|
166
|
+
*/
|
|
167
|
+
setConfusedManifest(fixed: NormalizedManifest, confused?: NormalizedManifest): void;
|
|
168
|
+
/**
|
|
169
|
+
* Sets this node as having a manifest-confused manifest.
|
|
170
|
+
*/
|
|
171
|
+
maybeSetConfusedManifest(spec: Spec, confused?: NormalizedManifest): void;
|
|
133
172
|
toJSON(): {
|
|
173
|
+
rawManifest?: import("@vltpkg/types").Override<import("@vltpkg/types").Manifest, import("@vltpkg/types").NormalizedFields> | undefined;
|
|
134
174
|
id: DepID;
|
|
135
175
|
name: string;
|
|
136
176
|
version: string | undefined;
|
|
137
177
|
location: string;
|
|
138
178
|
importer: boolean;
|
|
139
|
-
manifest: Manifest | undefined;
|
|
179
|
+
manifest: import("@vltpkg/types").Override<import("@vltpkg/types").Manifest, import("@vltpkg/types").NormalizedFields> | undefined;
|
|
140
180
|
projectRoot: string;
|
|
141
181
|
integrity: `sha512-${string}` | undefined;
|
|
142
182
|
resolved: string | undefined;
|
|
143
183
|
dev: boolean;
|
|
144
184
|
optional: boolean;
|
|
185
|
+
confused: boolean;
|
|
186
|
+
modifier: string | undefined;
|
|
187
|
+
platform: {
|
|
188
|
+
engines?: Record<string, string>;
|
|
189
|
+
os?: string[] | string;
|
|
190
|
+
cpu?: string[] | string;
|
|
191
|
+
} | undefined;
|
|
145
192
|
};
|
|
146
193
|
toString(): string;
|
|
147
194
|
}
|
|
195
|
+
export declare const isNode: (value: unknown) => value is Node;
|
|
196
|
+
export declare const asNode: (value: unknown) => Node;
|
|
148
197
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/esm/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAO7C,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,QAAQ,EACT,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAKhC,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,WA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IAa/B,MAAM;;;;;;;;;;;;;;;;sBA5MM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;iBAC3B,MAAM,EAAE,GAAG,MAAM;kBAChB,MAAM,EAAE,GAAG,MAAM;;;IAkOzB,QAAQ;CAGT;AAED,eAAO,MAAM,MAAM,UAAW,OAAO,KAAG,KAAK,IAAI,IAQhD,CAAA;AAED,eAAO,MAAM,MAAM,UAAW,OAAO,KAAG,IAKvC,CAAA"}
|
package/dist/esm/node.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getId, hydrateTuple, splitDepID } from '@vltpkg/dep-id';
|
|
1
|
+
import { isPackageNameConfused, getId, hydrateTuple, splitDepID, } from '@vltpkg/dep-id';
|
|
2
2
|
import { typeError } from '@vltpkg/error-cause';
|
|
3
|
+
import { expandNormalizedManifestSymbols } from '@vltpkg/types';
|
|
3
4
|
import { Edge } from "./edge.js";
|
|
4
5
|
import { stringifyNode } from "./stringify-node.js";
|
|
5
6
|
export class Node {
|
|
@@ -8,6 +9,7 @@ export class Node {
|
|
|
8
9
|
}
|
|
9
10
|
#options;
|
|
10
11
|
#location;
|
|
12
|
+
#rawManifest;
|
|
11
13
|
#optional = false;
|
|
12
14
|
/**
|
|
13
15
|
* True if a node is only reachable via optional or peerOptional edges from
|
|
@@ -57,6 +59,10 @@ export class Node {
|
|
|
57
59
|
isDev() {
|
|
58
60
|
return this.#dev;
|
|
59
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* True if there's a manifest-confused package name.
|
|
64
|
+
*/
|
|
65
|
+
confused = false;
|
|
60
66
|
/**
|
|
61
67
|
* List of edges coming into this node.
|
|
62
68
|
*/
|
|
@@ -66,6 +72,11 @@ export class Node {
|
|
|
66
72
|
* that the connected node is a direct dependency of this node.
|
|
67
73
|
*/
|
|
68
74
|
edgesOut = new Map();
|
|
75
|
+
/**
|
|
76
|
+
* A `mainImporter` node may have workspace connected to it,
|
|
77
|
+
* equivalent to its `edgesOut` linked deps.
|
|
78
|
+
*/
|
|
79
|
+
workspaces;
|
|
69
80
|
/**
|
|
70
81
|
* A reference to the {@link DepID} this node represents in the graph.
|
|
71
82
|
*/
|
|
@@ -100,6 +111,12 @@ export class Node {
|
|
|
100
111
|
* the same registry, if it's not the default.
|
|
101
112
|
*/
|
|
102
113
|
registry;
|
|
114
|
+
/**
|
|
115
|
+
* If this node has been modified as part of applying a {@link GraphModifier}
|
|
116
|
+
* then this field will contain the modifier query that was applied.
|
|
117
|
+
* Otherwise, it will be `undefined`.
|
|
118
|
+
*/
|
|
119
|
+
modifier;
|
|
103
120
|
/**
|
|
104
121
|
* The name of the package represented by this node, this is usually
|
|
105
122
|
* equivalent to `manifest.name` but in a few ways it may differ such as
|
|
@@ -124,6 +141,12 @@ export class Node {
|
|
|
124
141
|
* An address {@link PackageInfoClient} may use to extract this package.
|
|
125
142
|
*/
|
|
126
143
|
resolved;
|
|
144
|
+
/**
|
|
145
|
+
* Platform requirements (engines, os, cpu) extracted from manifest.
|
|
146
|
+
* Stored separately for optional dependencies to enable platform checks
|
|
147
|
+
* when manifest is not loaded.
|
|
148
|
+
*/
|
|
149
|
+
platform;
|
|
127
150
|
/**
|
|
128
151
|
* The file system location for this node.
|
|
129
152
|
*/
|
|
@@ -201,6 +224,11 @@ export class Node {
|
|
|
201
224
|
this.manifest?.dist?.tarball || spec.conventionalRegistryTarball;
|
|
202
225
|
this.integrity ??= this.manifest?.dist?.integrity;
|
|
203
226
|
}
|
|
227
|
+
get options() {
|
|
228
|
+
return this.#options;
|
|
229
|
+
}
|
|
230
|
+
/* c8 ignore next */
|
|
231
|
+
set options(_opts) { }
|
|
204
232
|
equals(other) {
|
|
205
233
|
return this.id === other.id && this.location === other.location;
|
|
206
234
|
}
|
|
@@ -250,6 +278,33 @@ export class Node {
|
|
|
250
278
|
this.edgesOut.set(spec.name, edge);
|
|
251
279
|
return edge;
|
|
252
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* The raw manifest before any modifications.
|
|
283
|
+
* If not set, falls back to the current manifest.
|
|
284
|
+
*/
|
|
285
|
+
get rawManifest() {
|
|
286
|
+
return this.#rawManifest ?? this.manifest;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Sets this node as having a manifest-confused manifest.
|
|
290
|
+
*/
|
|
291
|
+
setConfusedManifest(fixed, confused) {
|
|
292
|
+
this.manifest = fixed;
|
|
293
|
+
this.#rawManifest = confused;
|
|
294
|
+
this.confused = true;
|
|
295
|
+
this.#name = this.manifest.name;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Sets this node as having a manifest-confused manifest.
|
|
299
|
+
*/
|
|
300
|
+
maybeSetConfusedManifest(spec, confused) {
|
|
301
|
+
if (isPackageNameConfused(spec, this.manifest?.name)) {
|
|
302
|
+
this.setConfusedManifest({
|
|
303
|
+
...this.manifest,
|
|
304
|
+
name: spec.name,
|
|
305
|
+
}, confused);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
253
308
|
toJSON() {
|
|
254
309
|
return {
|
|
255
310
|
id: this.id,
|
|
@@ -257,16 +312,36 @@ export class Node {
|
|
|
257
312
|
version: this.version,
|
|
258
313
|
location: this.location,
|
|
259
314
|
importer: this.importer,
|
|
260
|
-
manifest: this.manifest
|
|
315
|
+
manifest: this.manifest &&
|
|
316
|
+
expandNormalizedManifestSymbols(this.manifest),
|
|
261
317
|
projectRoot: this.projectRoot,
|
|
262
318
|
integrity: this.integrity,
|
|
263
319
|
resolved: this.resolved,
|
|
264
320
|
dev: this.dev,
|
|
265
321
|
optional: this.optional,
|
|
322
|
+
confused: this.confused,
|
|
323
|
+
modifier: this.modifier,
|
|
324
|
+
platform: this.platform,
|
|
325
|
+
...(this.confused ?
|
|
326
|
+
{ rawManifest: this.#rawManifest }
|
|
327
|
+
: undefined),
|
|
266
328
|
};
|
|
267
329
|
}
|
|
268
330
|
toString() {
|
|
269
331
|
return stringifyNode(this);
|
|
270
332
|
}
|
|
271
333
|
}
|
|
334
|
+
export const isNode = (value) => {
|
|
335
|
+
return (typeof value === 'object' &&
|
|
336
|
+
value != null &&
|
|
337
|
+
'id' in value &&
|
|
338
|
+
'manifest' in value &&
|
|
339
|
+
value[Symbol.toStringTag] === '@vltpkg/graph.Node');
|
|
340
|
+
};
|
|
341
|
+
export const asNode = (value) => {
|
|
342
|
+
if (!isNode(value)) {
|
|
343
|
+
throw typeError('Expected a node', { found: value });
|
|
344
|
+
}
|
|
345
|
+
return value;
|
|
346
|
+
};
|
|
272
347
|
//# sourceMappingURL=node.js.map
|