@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.
Files changed (157) hide show
  1. package/README.md +148 -12
  2. package/dist/esm/actual/load.d.ts +44 -3
  3. package/dist/esm/actual/load.d.ts.map +1 -1
  4. package/dist/esm/actual/load.js +123 -73
  5. package/dist/esm/actual/load.js.map +1 -1
  6. package/dist/esm/browser.d.ts +8 -4
  7. package/dist/esm/browser.d.ts.map +1 -1
  8. package/dist/esm/browser.js +6 -2
  9. package/dist/esm/browser.js.map +1 -1
  10. package/dist/esm/dependencies.d.ts +14 -5
  11. package/dist/esm/dependencies.d.ts.map +1 -1
  12. package/dist/esm/dependencies.js +67 -2
  13. package/dist/esm/dependencies.js.map +1 -1
  14. package/dist/esm/diff.d.ts +5 -0
  15. package/dist/esm/diff.d.ts.map +1 -1
  16. package/dist/esm/diff.js +13 -0
  17. package/dist/esm/diff.js.map +1 -1
  18. package/dist/esm/edge.d.ts +2 -3
  19. package/dist/esm/edge.d.ts.map +1 -1
  20. package/dist/esm/edge.js +1 -1
  21. package/dist/esm/edge.js.map +1 -1
  22. package/dist/esm/graph.d.ts +22 -12
  23. package/dist/esm/graph.d.ts.map +1 -1
  24. package/dist/esm/graph.js +122 -23
  25. package/dist/esm/graph.js.map +1 -1
  26. package/dist/esm/ideal/add-nodes.d.ts +6 -1
  27. package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
  28. package/dist/esm/ideal/add-nodes.js +9 -4
  29. package/dist/esm/ideal/add-nodes.js.map +1 -1
  30. package/dist/esm/ideal/append-nodes.d.ts +9 -1
  31. package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
  32. package/dist/esm/ideal/append-nodes.js +155 -31
  33. package/dist/esm/ideal/append-nodes.js.map +1 -1
  34. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
  35. package/dist/esm/ideal/build-ideal-from-starting-graph.js +9 -5
  36. package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
  37. package/dist/esm/ideal/build.d.ts +4 -0
  38. package/dist/esm/ideal/build.d.ts.map +1 -1
  39. package/dist/esm/ideal/build.js +2 -0
  40. package/dist/esm/ideal/build.js.map +1 -1
  41. package/dist/esm/ideal/get-importer-specs.d.ts +3 -2
  42. package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
  43. package/dist/esm/ideal/get-importer-specs.js +7 -5
  44. package/dist/esm/ideal/get-importer-specs.js.map +1 -1
  45. package/dist/esm/index.d.ts +6 -4
  46. package/dist/esm/index.d.ts.map +1 -1
  47. package/dist/esm/index.js +3 -1
  48. package/dist/esm/index.js.map +1 -1
  49. package/dist/esm/install.d.ts +4 -5
  50. package/dist/esm/install.d.ts.map +1 -1
  51. package/dist/esm/install.js +143 -23
  52. package/dist/esm/install.js.map +1 -1
  53. package/dist/esm/lockfile/load-edges.d.ts +8 -1
  54. package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
  55. package/dist/esm/lockfile/load-edges.js +79 -15
  56. package/dist/esm/lockfile/load-edges.js.map +1 -1
  57. package/dist/esm/lockfile/load-nodes.d.ts +3 -2
  58. package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
  59. package/dist/esm/lockfile/load-nodes.js +64 -11
  60. package/dist/esm/lockfile/load-nodes.js.map +1 -1
  61. package/dist/esm/lockfile/load.d.ts +18 -5
  62. package/dist/esm/lockfile/load.d.ts.map +1 -1
  63. package/dist/esm/lockfile/load.js +51 -22
  64. package/dist/esm/lockfile/load.js.map +1 -1
  65. package/dist/esm/lockfile/save.d.ts +8 -3
  66. package/dist/esm/lockfile/save.d.ts.map +1 -1
  67. package/dist/esm/lockfile/save.js +30 -12
  68. package/dist/esm/lockfile/save.js.map +1 -1
  69. package/dist/esm/lockfile/types.d.ts +17 -4
  70. package/dist/esm/lockfile/types.d.ts.map +1 -1
  71. package/dist/esm/lockfile/types.js.map +1 -1
  72. package/dist/esm/modifiers.d.ts +189 -0
  73. package/dist/esm/modifiers.d.ts.map +1 -0
  74. package/dist/esm/modifiers.js +330 -0
  75. package/dist/esm/modifiers.js.map +1 -0
  76. package/dist/esm/node.d.ts +54 -5
  77. package/dist/esm/node.d.ts.map +1 -1
  78. package/dist/esm/node.js +77 -2
  79. package/dist/esm/node.js.map +1 -1
  80. package/dist/esm/reify/add-edge.d.ts +1 -1
  81. package/dist/esm/reify/add-edge.d.ts.map +1 -1
  82. package/dist/esm/reify/add-edge.js +36 -14
  83. package/dist/esm/reify/add-edge.js.map +1 -1
  84. package/dist/esm/reify/add-nodes.d.ts.map +1 -1
  85. package/dist/esm/reify/add-nodes.js +4 -2
  86. package/dist/esm/reify/add-nodes.js.map +1 -1
  87. package/dist/esm/reify/bin-paths.d.ts +1 -1
  88. package/dist/esm/reify/bin-paths.d.ts.map +1 -1
  89. package/dist/esm/reify/bin-paths.js.map +1 -1
  90. package/dist/esm/reify/build.js +6 -3
  91. package/dist/esm/reify/build.js.map +1 -1
  92. package/dist/esm/reify/calculate-save-value.d.ts +3 -0
  93. package/dist/esm/reify/calculate-save-value.d.ts.map +1 -0
  94. package/dist/esm/reify/calculate-save-value.js +45 -0
  95. package/dist/esm/reify/calculate-save-value.js.map +1 -0
  96. package/dist/esm/reify/delete-edge.js +1 -1
  97. package/dist/esm/reify/delete-edge.js.map +1 -1
  98. package/dist/esm/reify/delete-nodes.d.ts.map +1 -1
  99. package/dist/esm/reify/delete-nodes.js +4 -0
  100. package/dist/esm/reify/delete-nodes.js.map +1 -1
  101. package/dist/esm/reify/index.d.ts +2 -0
  102. package/dist/esm/reify/index.d.ts.map +1 -1
  103. package/dist/esm/reify/index.js +20 -2
  104. package/dist/esm/reify/index.js.map +1 -1
  105. package/dist/esm/reify/internal-hoist.d.ts +9 -0
  106. package/dist/esm/reify/internal-hoist.d.ts.map +1 -0
  107. package/dist/esm/reify/internal-hoist.js +121 -0
  108. package/dist/esm/reify/internal-hoist.js.map +1 -0
  109. package/dist/esm/reify/update-importers-package-json.d.ts +1 -1
  110. package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
  111. package/dist/esm/reify/update-importers-package-json.js +35 -12
  112. package/dist/esm/reify/update-importers-package-json.js.map +1 -1
  113. package/dist/esm/remove-optional-subgraph.js +1 -1
  114. package/dist/esm/remove-optional-subgraph.js.map +1 -1
  115. package/dist/esm/resolve-save-type.d.ts +6 -0
  116. package/dist/esm/resolve-save-type.d.ts.map +1 -0
  117. package/dist/esm/resolve-save-type.js +5 -0
  118. package/dist/esm/resolve-save-type.js.map +1 -0
  119. package/dist/esm/stringify-node.d.ts +1 -1
  120. package/dist/esm/stringify-node.d.ts.map +1 -1
  121. package/dist/esm/stringify-node.js.map +1 -1
  122. package/dist/esm/transfer-data/load.d.ts +44 -0
  123. package/dist/esm/transfer-data/load.d.ts.map +1 -0
  124. package/dist/esm/transfer-data/load.js +176 -0
  125. package/dist/esm/transfer-data/load.js.map +1 -0
  126. package/dist/esm/uninstall.d.ts +3 -5
  127. package/dist/esm/uninstall.d.ts.map +1 -1
  128. package/dist/esm/uninstall.js +0 -3
  129. package/dist/esm/uninstall.js.map +1 -1
  130. package/dist/esm/update.d.ts +11 -0
  131. package/dist/esm/update.d.ts.map +1 -0
  132. package/dist/esm/update.js +49 -0
  133. package/dist/esm/update.js.map +1 -0
  134. package/dist/esm/virtual-root.d.ts +16 -0
  135. package/dist/esm/virtual-root.d.ts.map +1 -0
  136. package/dist/esm/virtual-root.js +78 -0
  137. package/dist/esm/virtual-root.js.map +1 -0
  138. package/dist/esm/visualization/human-readable-output.d.ts +4 -5
  139. package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
  140. package/dist/esm/visualization/human-readable-output.js +51 -24
  141. package/dist/esm/visualization/human-readable-output.js.map +1 -1
  142. package/dist/esm/visualization/json-output.d.ts +7 -3
  143. package/dist/esm/visualization/json-output.d.ts.map +1 -1
  144. package/dist/esm/visualization/json-output.js +35 -12
  145. package/dist/esm/visualization/json-output.js.map +1 -1
  146. package/dist/esm/visualization/mermaid-output.d.ts +7 -1
  147. package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
  148. package/dist/esm/visualization/mermaid-output.js +64 -9
  149. package/dist/esm/visualization/mermaid-output.js.map +1 -1
  150. package/dist/esm/visualization/object-like-output.d.ts +1 -1
  151. package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
  152. package/dist/esm/visualization/object-like-output.js.map +1 -1
  153. package/package.json +29 -25
  154. package/dist/esm/types.d.ts +0 -39
  155. package/dist/esm/types.d.ts.map +0 -1
  156. package/dist/esm/types.js +0 -2
  157. package/dist/esm/types.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { joinDepIDTuple } from '@vltpkg/dep-id';
2
2
  import { error } from '@vltpkg/error-cause';
3
3
  import { Spec } from '@vltpkg/spec';
4
- import { longDependencyTypes } from '@vltpkg/types';
4
+ import { longDependencyTypes, normalizeManifest } from '@vltpkg/types';
5
5
  import { asDependency, shorten } from "../dependencies.js";
6
6
  import { removeOptionalSubgraph } from "../remove-optional-subgraph.js";
7
7
  /**
@@ -36,22 +36,47 @@ const getFileTypeInfo = (spec, fromNode, scurry) => {
36
36
  };
37
37
  };
38
38
  const isStringArray = (a) => Array.isArray(a) && !a.some(b => typeof b !== 'string');
39
- export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurry, options, seen) => {
40
- /* c8 ignore next */
41
- if (seen.has(fromNode.id))
42
- return;
43
- seen.add(fromNode.id);
44
- await Promise.all(deps.map(async ({ spec, type }) => {
45
- // see if there's a satisfying node in the graph currently
39
+ /**
40
+ * Fetch manifests for dependencies and create placement tasks.
41
+ */
42
+ const fetchManifestsForDeps = async (packageInfo, graph, fromNode, deps, scurry, modifierRefs, depth = 0) => {
43
+ // Create fetch tasks for all dependencies at this level
44
+ const fetchTasks = [];
45
+ for (const { spec: originalSpec, type } of deps) {
46
+ let spec = originalSpec;
46
47
  const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry);
47
- const existingNode = graph.findResolution(spec, fromNode);
48
+ const activeModifier = modifierRefs?.get(spec.name);
49
+ // here is the place we swap specs if a edge modifier was defined
50
+ const queryModifier = activeModifier?.modifier.query;
51
+ const completeModifier = activeModifier &&
52
+ activeModifier.interactiveBreadcrumb.current ===
53
+ activeModifier.modifier.breadcrumb.last;
54
+ if (queryModifier &&
55
+ completeModifier &&
56
+ 'spec' in activeModifier.modifier) {
57
+ spec = activeModifier.modifier.spec;
58
+ if (spec.bareSpec === '-') {
59
+ continue;
60
+ }
61
+ }
62
+ const existingNode = graph.findResolution(spec, fromNode, queryModifier);
48
63
  if (existingNode) {
49
- graph.addEdge(type, spec, fromNode, existingNode);
50
- return;
64
+ // For peerOptional dependencies, create a dangling edge instead of linking to existing node
65
+ if (type === 'peerOptional') {
66
+ /* c8 ignore next 3 */
67
+ // This case happens when peerOptional dep already exists in graph
68
+ graph.addEdge(type, spec, fromNode);
69
+ }
70
+ else {
71
+ graph.addEdge(type, spec, fromNode, existingNode);
72
+ }
73
+ continue;
51
74
  }
52
75
  const edgeOptional = type === 'optional' || type === 'peerOptional';
53
- const mani = await packageInfo
76
+ // Start manifest fetch immediately for parallel processing
77
+ const manifestPromise = packageInfo
54
78
  .manifest(spec, { from: scurry.resolve(fromNode.location) })
79
+ .then(manifest => manifest)
55
80
  .catch((er) => {
56
81
  // optional deps ignored if inaccessible
57
82
  if (edgeOptional || fromNode.optional) {
@@ -59,36 +84,72 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
59
84
  }
60
85
  throw er;
61
86
  });
62
- // when an user is adding a nameless dependency, e.g: `github:foo/bar`,
63
- // `file:./foo/bar`, we need to update the `add` option value to set the
64
- // correct name once we have it, so that it can properly be stored in
65
- // the `package.json` file at the end of reify.
66
- if (mani?.name && spec.name === '(unknown)') {
87
+ const fetchTask = {
88
+ spec,
89
+ type,
90
+ fromNode,
91
+ fileTypeInfo,
92
+ activeModifier,
93
+ queryModifier,
94
+ edgeOptional,
95
+ manifestPromise,
96
+ depth,
97
+ };
98
+ fetchTasks.push(fetchTask);
99
+ }
100
+ // Create placement tasks
101
+ const placementTasks = [];
102
+ for (const fetchTask of fetchTasks) {
103
+ const manifest = await fetchTask.manifestPromise;
104
+ placementTasks.push({
105
+ fetchTask,
106
+ manifest,
107
+ });
108
+ }
109
+ return placementTasks;
110
+ };
111
+ /**
112
+ * Process placement tasks and collect child dependencies
113
+ */
114
+ const processPlacementTasks = async (add, graph, options, placementTasks, modifiers) => {
115
+ const childDepsToProcess = [];
116
+ for (const placementTask of placementTasks) {
117
+ const { fetchTask, manifest } = placementTask;
118
+ let { spec } = fetchTask;
119
+ const type = fetchTask.type;
120
+ const fromNode = fetchTask.fromNode;
121
+ const fileTypeInfo = fetchTask.fileTypeInfo;
122
+ const activeModifier = fetchTask.activeModifier;
123
+ const queryModifier = fetchTask.queryModifier;
124
+ const edgeOptional = fetchTask.edgeOptional;
125
+ // Handle nameless dependencies
126
+ if (manifest?.name && spec.name === '(unknown)') {
67
127
  const s = add.get(String(spec));
68
128
  if (s) {
69
129
  // removes the previous, placeholder entry key
70
130
  add.delete(String(spec));
71
131
  // replaces spec with a version with the correct name
72
- spec = Spec.parse(mani.name, spec.bareSpec, options);
132
+ spec = Spec.parse(manifest.name, spec.bareSpec, options);
73
133
  // updates the add map with the fixed up spec
74
134
  const n = asDependency({
75
135
  ...s,
76
136
  spec,
77
137
  });
78
- add.set(mani.name, n);
138
+ add.set(manifest.name, n);
79
139
  }
80
140
  }
81
- if (!mani) {
141
+ // handles missing manifest resolution
142
+ if (!manifest) {
82
143
  if (!edgeOptional && fromNode.isOptional()) {
83
144
  // failed resolution of a non-optional dep of an optional node
84
145
  // have to clean up the dependents
85
146
  removeOptionalSubgraph(graph, fromNode);
86
- return;
147
+ continue;
87
148
  }
88
149
  else if (edgeOptional) {
89
150
  // failed resolution of an optional dep, just ignore it,
90
151
  // nothing to prune because we never added it in the first place.
91
- return;
152
+ continue;
92
153
  }
93
154
  else {
94
155
  throw error('failed to resolve dependency', {
@@ -97,7 +158,14 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
97
158
  });
98
159
  }
99
160
  }
100
- const node = graph.placePackage(fromNode, type, spec, mani, fileTypeInfo?.id);
161
+ // Skip placing peerOptional dependencies, just create a dangling edge
162
+ if (type === 'peerOptional') {
163
+ /* c8 ignore next 3 */
164
+ graph.addEdge(type, spec, fromNode);
165
+ continue;
166
+ }
167
+ // places a new node in the graph representing a newly seen dependency
168
+ const node = graph.placePackage(fromNode, type, spec, normalizeManifest(manifest), fileTypeInfo?.id, queryModifier);
101
169
  /* c8 ignore start - not possible, already ensured manifest */
102
170
  if (!node) {
103
171
  throw error('failed to place package', {
@@ -106,26 +174,32 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
106
174
  });
107
175
  }
108
176
  /* c8 ignore stop */
177
+ // update the node modifier tracker
178
+ if (activeModifier) {
179
+ modifiers?.updateActiveEntry(node, activeModifier);
180
+ }
181
+ // updates graph node information
109
182
  if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {
110
183
  node.location = fileTypeInfo.path;
111
184
  }
112
185
  node.setResolved();
113
- const nestedAppends = [];
114
- const bundleDeps = node.manifest?.bundleDependencies;
186
+ // Collect child dependencies for processing in the next level
187
+ const bundleDeps = manifest.bundleDependencies;
115
188
  const bundled = new Set((node.id.startsWith('git') ||
116
189
  node.importer ||
117
190
  !isStringArray(bundleDeps)) ?
118
191
  []
119
192
  : bundleDeps);
193
+ // recursively process all child dependencies in the manifest
120
194
  const nextDeps = [];
121
195
  for (const depTypeName of longDependencyTypes) {
122
- const depRecord = mani[depTypeName];
196
+ const depRecord = manifest[depTypeName];
123
197
  if (depRecord && shouldInstallDepType(node, depTypeName)) {
124
198
  for (const [name, bareSpec] of Object.entries(depRecord)) {
125
199
  if (bundled.has(name))
126
200
  continue;
127
201
  nextDeps.push({
128
- type: shorten(depTypeName, name, mani),
202
+ type: shorten(depTypeName, name, manifest),
129
203
  spec: Spec.parse(name, bareSpec, {
130
204
  ...options,
131
205
  registry: spec.registry,
@@ -134,10 +208,60 @@ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurr
134
208
  }
135
209
  }
136
210
  }
137
- if (nextDeps.length) {
138
- nestedAppends.push(appendNodes(add, packageInfo, graph, node, nextDeps, scurry, options, seen));
211
+ if (nextDeps.length > 0) {
212
+ childDepsToProcess.push({
213
+ node,
214
+ deps: nextDeps,
215
+ modifierRefs: modifiers?.tryDependencies(node, nextDeps),
216
+ });
217
+ }
218
+ }
219
+ return { childDepsToProcess };
220
+ };
221
+ /**
222
+ * Append new nodes in the given `graph` for dependencies specified at `add`
223
+ * and missing dependencies from the `deps` parameter.
224
+ *
225
+ * It also applies any modifiers that applies to a given node as it processes
226
+ * and builds the graph.
227
+ */
228
+ export const appendNodes = async (add, packageInfo, graph, fromNode, deps, scurry, options, seen, modifiers, modifierRefs) => {
229
+ /* c8 ignore next */
230
+ if (seen.has(fromNode.id))
231
+ return;
232
+ seen.add(fromNode.id);
233
+ // Use a queue for breadth-first processing
234
+ let currentLevelDeps = [
235
+ { node: fromNode, deps, modifierRefs, depth: 0 },
236
+ ];
237
+ while (currentLevelDeps.length > 0) {
238
+ const nextLevelDeps = [];
239
+ // Process all nodes at the current level in parallel
240
+ const levelResults = await Promise.all(currentLevelDeps.map(async ({ node, deps: nodeDeps, modifierRefs: nodeModifierRefs, depth, }) => {
241
+ // Mark node as seen when we start processing its dependencies
242
+ seen.add(node.id);
243
+ // Fetch manifests for this node's dependencies
244
+ const placementTasks = await fetchManifestsForDeps(packageInfo, graph, node,
245
+ // Sort dependencies by spec.name for deterministic ordering
246
+ nodeDeps.sort((a, b) => a.spec.name.localeCompare(b.spec.name, 'en')), scurry, nodeModifierRefs, depth);
247
+ // Process the placement tasks and get child dependencies
248
+ return await processPlacementTasks(add, graph, options, placementTasks, modifiers);
249
+ }));
250
+ // Collect all child dependencies for the next level
251
+ for (const { childDepsToProcess } of levelResults) {
252
+ for (const childDep of childDepsToProcess) {
253
+ if (!seen.has(childDep.node.id)) {
254
+ /* c8 ignore next */
255
+ const currentDepth = currentLevelDeps[0]?.depth ?? 0;
256
+ nextLevelDeps.push({
257
+ ...childDep,
258
+ depth: currentDepth + 1,
259
+ });
260
+ }
261
+ }
139
262
  }
140
- await Promise.all(nestedAppends);
141
- }));
263
+ // Move to the next level
264
+ currentLevelDeps = nextLevelDeps;
265
+ }
142
266
  };
143
267
  //# sourceMappingURL=append-nodes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"append-nodes.js","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAGnD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAQvE;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAC3B,IAAU,EACV,OAA2B,EAC3B,EAAE,CACF,OAAO,KAAK,iBAAiB;IAC7B,IAAI,CAAC,QAAQ;IACb,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAE3B;;GAEG;AACH,MAAM,eAAe,GAAG,CACtB,IAAU,EACV,QAAc,EACd,MAAkB,EACQ,EAAE;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;IACpB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;QAAE,OAAM;IAE7B,4CAA4C;IAC5C,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC,2BAA2B,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IACpD,CAAC;I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,UAAU,CACb,CAAA;QAED,MAAM,QAAQ,GAAiB,EAAE,CAAA;QAEjC,KAAK,MAAM,WAAW,IAAI,mBAAmB,EAAE,CAAC;YAC9C,MAAM,SAAS,GACb,IAAI,CAAC,WAAW,CAAC,CAAA;YAEnB,IAAI,SAAS,IAAI,oBAAoB,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;gBACzD,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;oBACzD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;wBAAE,SAAQ;oBAC/B,QAAQ,CAAC,IAAI,CAAC;wBACZ,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC;wBACtC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE;4BAC/B,GAAG,OAAO;4BACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;yBACxB,CAAC;qBACH,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAChB,WAAW,CACT,GAAG,EACH,WAAW,EACX,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,CACL,CACF,CAAA;QACH,CAAC;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport type { DependencyTypeLong } from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n await Promise.all(\n deps.map(async ({ spec, type }) => {\n // see if there's a satisfying node in the graph currently\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const existingNode = graph.findResolution(spec, fromNode)\n if (existingNode) {\n graph.addEdge(type, spec, fromNode, existingNode)\n return\n }\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n const mani = await packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n // when an user is adding a nameless dependency, e.g: `github:foo/bar`,\n // `file:./foo/bar`, we need to update the `add` option value to set the\n // correct name once we have it, so that it can properly be stored in\n // the `package.json` file at the end of reify.\n if (mani?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(mani.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(mani.name, n)\n }\n }\n\n if (!mani) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n return\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n return\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n mani,\n fileTypeInfo?.id,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n const nestedAppends: Promise<unknown>[] = []\n\n const bundleDeps = node.manifest?.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n mani[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, mani),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length) {\n nestedAppends.push(\n appendNodes(\n add,\n packageInfo,\n graph,\n node,\n nextDeps,\n scurry,\n options,\n seen,\n ),\n )\n }\n await Promise.all(nestedAppends)\n }),\n )\n}\n"]}
1
+ {"version":3,"file":"append-nodes.js","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAOtE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAYvE;;;GAGG;AACH,MAAM,oBAAoB,GAAG,CAC3B,IAAU,EACV,OAA2B,EAC3B,EAAE,CACF,OAAO,KAAK,iBAAiB;IAC7B,IAAI,CAAC,QAAQ;IACb,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAE3B;;GAEG;AACH,MAAM,eAAe,GAAG,CACtB,IAAU,EACV,QAAc,EACd,MAAkB,EACQ,EAAE;IAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;IACpB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;QAAE,OAAM;IAE7B,4CAA4C;IAC5C,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC,2BAA2B,EAAE,EAAE,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AAgB,GAAG,aAAa,CAAA;IAClC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes, normalizeManifest } from '@vltpkg/types'\nimport type {\n DependencyTypeLong,\n DependencySaveType,\n Manifest,\n} from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\nimport type {\n GraphModifier,\n ModifierActiveEntry,\n} from '../modifiers.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\n/**\n * Represents a manifest fetch operation with all the context needed.\n */\ntype ManifestFetchTask = {\n spec: Spec\n type: DependencySaveType\n fromNode: Node\n fileTypeInfo?: FileTypeInfo\n activeModifier?: ModifierActiveEntry\n queryModifier?: string\n edgeOptional: boolean\n manifestPromise: Promise<Manifest | undefined>\n depth: number\n}\n\n/**\n * Represents a node placement operation that depends on a resolved manifest.\n */\ntype NodePlacementTask = {\n fetchTask: ManifestFetchTask\n manifest: Manifest | undefined\n node?: Node\n childDeps?: Dependency[]\n childModifierRefs?: Map<string, ModifierActiveEntry>\n}\n\n/**\n * Represents an ongoing append operation for a node and its dependencies.\n */\ntype AppendNodeEntry = {\n node: Node\n deps: Dependency[]\n modifierRefs?: Map<string, ModifierActiveEntry>\n depth: number\n}\n\n/**\n * Fetch manifests for dependencies and create placement tasks.\n */\nconst fetchManifestsForDeps = async (\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n depth = 0,\n): Promise<NodePlacementTask[]> => {\n // Create fetch tasks for all dependencies at this level\n const fetchTasks: ManifestFetchTask[] = []\n\n for (const { spec: originalSpec, type } of deps) {\n let spec = originalSpec\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const activeModifier = modifierRefs?.get(spec.name)\n\n // here is the place we swap specs if a edge modifier was defined\n const queryModifier = activeModifier?.modifier.query\n const completeModifier =\n activeModifier &&\n activeModifier.interactiveBreadcrumb.current ===\n activeModifier.modifier.breadcrumb.last\n if (\n queryModifier &&\n completeModifier &&\n 'spec' in activeModifier.modifier\n ) {\n spec = activeModifier.modifier.spec\n if (spec.bareSpec === '-') {\n continue\n }\n }\n\n const existingNode = graph.findResolution(\n spec,\n fromNode,\n queryModifier,\n )\n if (existingNode) {\n // For peerOptional dependencies, create a dangling edge instead of linking to existing node\n if (type === 'peerOptional') {\n /* c8 ignore next 3 */\n // This case happens when peerOptional dep already exists in graph\n graph.addEdge(type, spec, fromNode)\n } else {\n graph.addEdge(type, spec, fromNode, existingNode)\n }\n continue\n }\n\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n\n // Start manifest fetch immediately for parallel processing\n const manifestPromise = packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .then(manifest => manifest as Manifest | undefined)\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n const fetchTask: ManifestFetchTask = {\n spec,\n type,\n fromNode,\n fileTypeInfo,\n activeModifier,\n queryModifier,\n edgeOptional,\n manifestPromise,\n depth,\n }\n\n fetchTasks.push(fetchTask)\n }\n\n // Create placement tasks\n const placementTasks: NodePlacementTask[] = []\n for (const fetchTask of fetchTasks) {\n const manifest = await fetchTask.manifestPromise\n\n placementTasks.push({\n fetchTask,\n manifest,\n })\n }\n\n return placementTasks\n}\n\n/**\n * Process placement tasks and collect child dependencies\n */\nconst processPlacementTasks = async (\n add: Map<string, Dependency>,\n graph: Graph,\n options: SpecOptions,\n placementTasks: NodePlacementTask[],\n modifiers?: GraphModifier,\n): Promise<{\n childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[]\n}> => {\n const childDepsToProcess: Omit<AppendNodeEntry, 'depth'>[] = []\n\n for (const placementTask of placementTasks) {\n const { fetchTask, manifest } = placementTask\n let { spec } = fetchTask\n const type = fetchTask.type\n const fromNode = fetchTask.fromNode\n const fileTypeInfo = fetchTask.fileTypeInfo\n const activeModifier = fetchTask.activeModifier\n const queryModifier = fetchTask.queryModifier\n const edgeOptional = fetchTask.edgeOptional\n\n // Handle nameless dependencies\n if (manifest?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(manifest.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(manifest.name, n)\n }\n }\n\n // handles missing manifest resolution\n if (!manifest) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n continue\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n continue\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n // Skip placing peerOptional dependencies, just create a dangling edge\n if (type === 'peerOptional') {\n /* c8 ignore next 3 */\n graph.addEdge(type, spec, fromNode)\n continue\n }\n\n // places a new node in the graph representing a newly seen dependency\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n normalizeManifest(manifest),\n fileTypeInfo?.id,\n queryModifier,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n // update the node modifier tracker\n if (activeModifier) {\n modifiers?.updateActiveEntry(node, activeModifier)\n }\n\n // updates graph node information\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n\n // Collect child dependencies for processing in the next level\n const bundleDeps = manifest.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n // recursively process all child dependencies in the manifest\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n manifest[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, manifest),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length > 0) {\n childDepsToProcess.push({\n node,\n deps: nextDeps,\n modifierRefs: modifiers?.tryDependencies(node, nextDeps),\n })\n }\n }\n\n return { childDepsToProcess }\n}\n\n/**\n * Append new nodes in the given `graph` for dependencies specified at `add`\n * and missing dependencies from the `deps` parameter.\n *\n * It also applies any modifiers that applies to a given node as it processes\n * and builds the graph.\n */\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n modifiers?: GraphModifier,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n // Use a queue for breadth-first processing\n let currentLevelDeps: AppendNodeEntry[] = [\n { node: fromNode, deps, modifierRefs, depth: 0 },\n ]\n\n while (currentLevelDeps.length > 0) {\n const nextLevelDeps: AppendNodeEntry[] = []\n\n // Process all nodes at the current level in parallel\n const levelResults = await Promise.all(\n currentLevelDeps.map(\n async ({\n node,\n deps: nodeDeps,\n modifierRefs: nodeModifierRefs,\n depth,\n }: AppendNodeEntry) => {\n // Mark node as seen when we start processing its dependencies\n seen.add(node.id)\n\n // Fetch manifests for this node's dependencies\n const placementTasks = await fetchManifestsForDeps(\n packageInfo,\n graph,\n node,\n // Sort dependencies by spec.name for deterministic ordering\n nodeDeps.sort((a, b) =>\n a.spec.name.localeCompare(b.spec.name, 'en'),\n ),\n scurry,\n nodeModifierRefs,\n depth,\n )\n\n // Process the placement tasks and get child dependencies\n return await processPlacementTasks(\n add,\n graph,\n options,\n placementTasks,\n modifiers,\n )\n },\n ),\n )\n\n // Collect all child dependencies for the next level\n for (const { childDepsToProcess } of levelResults) {\n for (const childDep of childDepsToProcess) {\n if (!seen.has(childDep.node.id)) {\n /* c8 ignore next */\n const currentDepth = currentLevelDeps[0]?.depth ?? 0\n nextLevelDeps.push({\n ...childDep,\n depth: currentDepth + 1,\n })\n }\n }\n }\n\n // Move to the next level\n currentLevelDeps = nextLevelDeps\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"build-ideal-from-starting-graph.d.ts","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,MAAM,MAAM,kCAAkC,GAAG,eAAe,GAC9D,kBAAkB,GAAG;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,YAC7B,kCAAkC,KAC1C,OAAO,CAAC,KAAK,CA+Cf,CAAA"}
1
+ {"version":3,"file":"build-ideal-from-starting-graph.d.ts","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,MAAM,MAAM,kCAAkC,GAAG,eAAe,GAC9D,kBAAkB,GAAG;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,YAC7B,kCAAkC,KAC1C,OAAO,CAAC,KAAK,CAoDf,CAAA"}
@@ -37,11 +37,15 @@ export const buildIdealFromStartingGraph = async (options) => {
37
37
  }
38
38
  }
39
39
  }
40
- // add nodes, fetching remote manifests for each dependency to be added
41
- await addNodes(options);
42
- // move things into their default locations, if possible
43
- for (const node of options.graph.nodes.values()) {
44
- node.setDefaultLocation();
40
+ // hydrate the resolution cache
41
+ if (options.add.modifiedDependencies) {
42
+ options.graph.resetResolution();
43
+ // add nodes, fetching remote manifests for each dependency to be added
44
+ await addNodes(options);
45
+ // move things into their default locations, if possible
46
+ for (const node of options.graph.nodes.values()) {
47
+ node.setDefaultLocation();
48
+ }
45
49
  }
46
50
  // removes any dependencies that are listed in the `remove` option
47
51
  removeNodes({ ...options, remove: importerSpecs.remove });
@@ -1 +1 @@
1
- {"version":3,"file":"build-ideal-from-starting-graph.js","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAQ/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,OAA2C,EAC3B,EAAE;IAClB,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,oDAAoD;IACpD,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAE/C,mCAAmC;IACnC,OAAO,CAAC,GAAG,CAAC,oBAAoB;QAC9B,OAAO,CAAC,GAAG,CAAC,oBAAoB;YAChC,aAAa,CAAC,GAAG,CAAC,oBAAoB,CAAA;IACxC,OAAO,CAAC,MAAM,CAAC,oBAAoB;QACjC,OAAO,CAAC,MAAM,CAAC,oBAAoB;YACnC,aAAa,CAAC,MAAM,CAAC,oBAAoB,CAAA;IAE3C,4CAA4C;IAC5C,0CAA0C;IAC1C,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,aAAa,CAAC,GAAG,EAAE,CAAC;QACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;YACjC,SAAQ;QACV,CAAC;QAED,2DAA2D;QAC3D,2DAA2D;QAC3D,4CAA4C;QAC5C,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,uEAAuE;IACvE,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAA;IAEvB,wDAAwD;IACxD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QAChD,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC3B,CAAC;IAED,kEAAkE;IAClE,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;IAEzD,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;IAElB,OAAO,OAAO,CAAC,KAAK,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import type { Graph } from '../graph.ts'\nimport { getImporterSpecs } from './get-importer-specs.ts'\nimport { addNodes } from './add-nodes.ts'\nimport type { AddNodesOptions } from './add-nodes.ts'\nimport { removeNodes } from './remove-nodes.ts'\nimport type { RemoveNodesOptions } from './remove-nodes.ts'\n\nexport type BuildIdealFromStartingGraphOptions = AddNodesOptions &\n RemoveNodesOptions & {\n projectRoot: string\n }\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using the `graph` set\n * in options as a starting point. Also add / remove any dependencies\n * listed in the `add` and `remove` properties.\n */\nexport const buildIdealFromStartingGraph = async (\n options: BuildIdealFromStartingGraphOptions,\n): Promise<Graph> => {\n // Gets a map of dependencies that are keyed to its importer node ids,\n // merging values already found in the graph with user specified values.\n // Any dependencies that are already satisfied in the starting `graph`\n // are going to be pruned from the resulting object.\n const importerSpecs = getImporterSpecs(options)\n\n // merge modifiedDependencies flags\n options.add.modifiedDependencies =\n options.add.modifiedDependencies ||\n importerSpecs.add.modifiedDependencies\n options.remove.modifiedDependencies =\n options.remove.modifiedDependencies ||\n importerSpecs.remove.modifiedDependencies\n\n // merge values found on importer specs with\n // user-provided values from `options.add`\n for (const [importerId, deps] of importerSpecs.add) {\n if (!options.add.has(importerId)) {\n options.add.set(importerId, deps)\n continue\n }\n\n // merge any deps found when reading the importers manifest\n // with the ones provided by the user in the `add` options,\n // user-provided deps should take precedence\n for (const [depName, dep] of deps) {\n if (!options.add.get(importerId)?.has(depName)) {\n options.add.get(importerId)?.set(depName, dep)\n }\n }\n }\n\n // add nodes, fetching remote manifests for each dependency to be added\n await addNodes(options)\n\n // move things into their default locations, if possible\n for (const node of options.graph.nodes.values()) {\n node.setDefaultLocation()\n }\n\n // removes any dependencies that are listed in the `remove` option\n removeNodes({ ...options, remove: importerSpecs.remove })\n\n options.graph.gc()\n\n return options.graph\n}\n"]}
1
+ {"version":3,"file":"build-ideal-from-starting-graph.js","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAQ/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,OAA2C,EAC3B,EAAE;IAClB,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,oDAAoD;IACpD,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;IA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AA;QAC3B,CAAC;IACH,CAAC;IAED,kEAAkE;IAClE,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;IAEzD,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;IAElB,OAAO,OAAO,CAAC,KAAK,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import type { Graph } from '../graph.ts'\nimport { getImporterSpecs } from './get-importer-specs.ts'\nimport { addNodes } from './add-nodes.ts'\nimport type { AddNodesOptions } from './add-nodes.ts'\nimport { removeNodes } from './remove-nodes.ts'\nimport type { RemoveNodesOptions } from './remove-nodes.ts'\n\nexport type BuildIdealFromStartingGraphOptions = AddNodesOptions &\n RemoveNodesOptions & {\n projectRoot: string\n }\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using the `graph` set\n * in options as a starting point. Also add / remove any dependencies\n * listed in the `add` and `remove` properties.\n */\nexport const buildIdealFromStartingGraph = async (\n options: BuildIdealFromStartingGraphOptions,\n): Promise<Graph> => {\n // Gets a map of dependencies that are keyed to its importer node ids,\n // merging values already found in the graph with user specified values.\n // Any dependencies that are already satisfied in the starting `graph`\n // are going to be pruned from the resulting object.\n const importerSpecs = getImporterSpecs(options)\n\n // merge modifiedDependencies flags\n options.add.modifiedDependencies =\n options.add.modifiedDependencies ||\n importerSpecs.add.modifiedDependencies\n options.remove.modifiedDependencies =\n options.remove.modifiedDependencies ||\n importerSpecs.remove.modifiedDependencies\n\n // merge values found on importer specs with\n // user-provided values from `options.add`\n for (const [importerId, deps] of importerSpecs.add) {\n if (!options.add.has(importerId)) {\n options.add.set(importerId, deps)\n continue\n }\n\n // merge any deps found when reading the importers manifest\n // with the ones provided by the user in the `add` options,\n // user-provided deps should take precedence\n for (const [depName, dep] of deps) {\n if (!options.add.get(importerId)?.has(depName)) {\n options.add.get(importerId)?.set(depName, dep)\n }\n }\n }\n\n // hydrate the resolution cache\n if (options.add.modifiedDependencies) {\n options.graph.resetResolution()\n\n // add nodes, fetching remote manifests for each dependency to be added\n await addNodes(options)\n\n // move things into their default locations, if possible\n for (const node of options.graph.nodes.values()) {\n node.setDefaultLocation()\n }\n }\n\n // removes any dependencies that are listed in the `remove` option\n removeNodes({ ...options, remove: importerSpecs.remove })\n\n options.graph.gc()\n\n return options.graph\n}\n"]}
@@ -3,6 +3,10 @@ import type { LoadOptions as LoadActualOptions } from '../actual/load.ts';
3
3
  import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '../dependencies.ts';
4
4
  import type { Graph } from '../graph.ts';
5
5
  export type BuildIdealOptions = LoadActualOptions & {
6
+ /**
7
+ * An actual graph
8
+ */
9
+ actual?: Graph;
6
10
  /**
7
11
  * A `Map` in which keys are {@link DepID} linking to another `Map` in which
8
12
  * keys are the dependency names and values are {@link Dependency}. This
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAE/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AASxC,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAClD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP,iBAAiB,KACzB,OAAO,CAAC,KAAK,CAiCf,CAAA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAE/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AASxC,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAClD;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IACd;;;;;OAKG;IACH,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP,iBAAiB,KACzB,OAAO,CAAC,KAAK,CAmCf,CAAA"}
@@ -22,6 +22,7 @@ export const build = async (options) => {
22
22
  ...options,
23
23
  mainManifest,
24
24
  monorepo,
25
+ skipLoadingNodesOnModifiersChange: true,
25
26
  });
26
27
  }
27
28
  catch {
@@ -29,6 +30,7 @@ export const build = async (options) => {
29
30
  ...options,
30
31
  mainManifest,
31
32
  monorepo,
33
+ skipLoadingNodesOnModifiersChange: true,
32
34
  });
33
35
  }
34
36
  const res = await buildIdealFromStartingGraph({
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQtD,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAA;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,MAAM,MAAM,GAAG,CAA0B,CAAK,EAAE,EAAE,CAChD,CAAC,IAAK,IAAI,GAAG,EAAQ,CAAA;AAsBvB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,OAA0B,EACV,EAAE;IAClB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAE/B,yDAAyD;IACzD,iDAAiD;IACjD,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAC9D,MAAM,YAAY,GAChB,OAAO,CAAC,YAAY,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC/D,IAAI,KAAK,CAAA;IACT,IAAI,CAAC;QACH,KAAK,GAAG,WAAW,CAAC;YAClB,GAAG,OAAO;YACV,YAAY;YACZ,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,KAAK,GAAG,UAAU,CAAC;YACjB,GAAG,OAAO;YACV,YAAY;YACZ,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,2BAA2B,CAAC;QAC5C,GAAG,OAAO;QACV,MAAM;QACN,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QACxB,KAAK;QACL,WAAW;QACX,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;KAC/B,CAAC,CAAA;IACF,IAAI,EAAE,CAAA;IACN,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import type { PackageInfoClient } from '@vltpkg/package-info'\nimport { load as loadActual } from '../actual/load.ts'\nimport type { LoadOptions as LoadActualOptions } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n Dependency,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { load as loadVirtual } from '../lockfile/load.ts'\nimport { buildIdealFromStartingGraph } from './build-ideal-from-starting-graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { graphStep } from '@vltpkg/output'\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\nexport type BuildIdealOptions = LoadActualOptions & {\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n}\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using either the\n * virtual or actual graph as a starting point. Also add / remove any\n * dependencies listed in the `add` and `remove` properties.\n */\nexport const build = async (\n options: BuildIdealOptions,\n): Promise<Graph> => {\n const done = graphStep('build')\n\n // Creates the shared instances that are going to be used\n // in both the loader methods and the build graph\n const { packageInfo, packageJson, scurry, monorepo } = options\n const mainManifest =\n options.mainManifest ?? packageJson.read(options.projectRoot)\n let graph\n try {\n graph = loadVirtual({\n ...options,\n mainManifest,\n monorepo,\n })\n } catch {\n graph = loadActual({\n ...options,\n mainManifest,\n monorepo,\n })\n }\n\n const res = await buildIdealFromStartingGraph({\n ...options,\n scurry,\n add: getMap(options.add),\n graph,\n packageInfo,\n remove: getMap(options.remove),\n })\n done()\n return res\n}\n"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQtD,OAAO,EAAE,IAAI,IAAI,WAAW,E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} from '../actual/load.ts'\nimport type { LoadOptions as LoadActualOptions } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n Dependency,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { load as loadVirtual } from '../lockfile/load.ts'\nimport { buildIdealFromStartingGraph } from './build-ideal-from-starting-graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { graphStep } from '@vltpkg/output'\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\nexport type BuildIdealOptions = LoadActualOptions & {\n /**\n * An actual graph\n */\n actual?: Graph\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n}\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using either the\n * virtual or actual graph as a starting point. Also add / remove any\n * dependencies listed in the `add` and `remove` properties.\n */\nexport const build = async (\n options: BuildIdealOptions,\n): Promise<Graph> => {\n const done = graphStep('build')\n\n // Creates the shared instances that are going to be used\n // in both the loader methods and the build graph\n const { packageInfo, packageJson, scurry, monorepo } = options\n const mainManifest =\n options.mainManifest ?? packageJson.read(options.projectRoot)\n let graph\n try {\n graph = loadVirtual({\n ...options,\n mainManifest,\n monorepo,\n skipLoadingNodesOnModifiersChange: true,\n })\n } catch {\n graph = loadActual({\n ...options,\n mainManifest,\n monorepo,\n skipLoadingNodesOnModifiersChange: true,\n })\n }\n\n const res = await buildIdealFromStartingGraph({\n ...options,\n scurry,\n add: getMap(options.add),\n graph,\n packageInfo,\n remove: getMap(options.remove),\n })\n done()\n return res\n}\n"]}
@@ -1,12 +1,13 @@
1
1
  import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '../dependencies.ts';
2
2
  import type { BuildIdealAddOptions, BuildIdealFromGraphOptions, BuildIdealRemoveOptions } from './types.ts';
3
- export type GetImporterSpecsOptions = BuildIdealAddOptions & BuildIdealFromGraphOptions & BuildIdealRemoveOptions;
3
+ import type { SpecOptions } from '@vltpkg/spec';
4
+ export type GetImporterSpecsOptions = BuildIdealAddOptions & BuildIdealFromGraphOptions & BuildIdealRemoveOptions & SpecOptions;
4
5
  /**
5
6
  * Given a {@link Graph} and a list of {@link Dependency}, merges the
6
7
  * dependencies info found in the graph importers and returns the add & remove
7
8
  * results as a Map in which keys are {@link DepID} of each importer node.
8
9
  */
9
- export declare const getImporterSpecs: ({ add, graph, remove, }: GetImporterSpecsOptions) => {
10
+ export declare const getImporterSpecs: (options: GetImporterSpecsOptions) => {
10
11
  add: AddImportersDependenciesMap;
11
12
  remove: RemoveImportersDependenciesMap;
12
13
  };
@@ -1 +1 @@
1
- {"version":3,"file":"get-importer-specs.d.ts","sourceRoot":"","sources":["../../../src/ideal/get-importer-specs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAOnB,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GACxD,0BAA0B,GAC1B,uBAAuB,CAAA;AAyBzB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAI1B,uBAAuB;;;CA4FzB,CAAA"}
1
+ {"version":3,"file":"get-importer-specs.d.ts","sourceRoot":"","sources":["../../../src/ideal/get-importer-specs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAMnB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GACxD,0BAA0B,GAC1B,uBAAuB,GACvB,WAAW,CAAA;AAyBb;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,YAClB,uBAAuB;;;CA4FjC,CAAA"}
@@ -22,7 +22,8 @@ class RemoveImportersDependenciesMapImpl extends Map {
22
22
  * dependencies info found in the graph importers and returns the add & remove
23
23
  * results as a Map in which keys are {@link DepID} of each importer node.
24
24
  */
25
- export const getImporterSpecs = ({ add, graph, remove, }) => {
25
+ export const getImporterSpecs = (options) => {
26
+ const { add, graph, remove } = options;
26
27
  const addResult = new AddImportersDependenciesMapImpl();
27
28
  const removeResult = new RemoveImportersDependenciesMapImpl();
28
29
  // traverse the list of importers in the starting graph
@@ -46,11 +47,12 @@ export const getImporterSpecs = ({ add, graph, remove, }) => {
46
47
  const deps = Object.entries(importer.manifest?.[depType] ?? {});
47
48
  for (const [depName, depSpec] of deps) {
48
49
  const edge = importer.edgesOut.get(depName);
50
+ const dependency = asDependency({
51
+ spec: Spec.parse(depName, depSpec, options),
52
+ type: shorten(depType, depName, importer.manifest),
53
+ });
49
54
  if (!edge?.to) {
50
- addDeps.set(depName, asDependency({
51
- spec: Spec.parse(depName, depSpec),
52
- type: shorten(depType, depName, importer.manifest),
53
- }));
55
+ addDeps.set(depName, dependency);
54
56
  }
55
57
  }
56
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-importer-specs.js","sourceRoot":"","sources":["../../../src/ideal/get-importer-specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;A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YAAY;KACrB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport { shorten, asDependency } from '../dependencies.ts'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { removeSatisfiedSpecs } from './remove-satisfied-specs.ts'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n BuildIdealRemoveOptions,\n} from './types.ts'\nimport type { Edge } from '../edge.ts'\nimport type { Node } from '../node.ts'\nimport type { Graph } from '../graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { Spec } from '@vltpkg/spec'\n\nexport type GetImporterSpecsOptions = BuildIdealAddOptions &\n BuildIdealFromGraphOptions &\n BuildIdealRemoveOptions\n\nconst hasDepName = (importer: Node, edge: Edge): boolean => {\n for (const depType of longDependencyTypes) {\n const listedDeps = importer.manifest?.[depType]\n if (listedDeps && Object.hasOwn(listedDeps, edge.name))\n return true\n }\n return false\n}\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\n/**\n * Given a {@link Graph} and a list of {@link Dependency}, merges the\n * dependencies info found in the graph importers and returns the add & remove\n * results as a Map in which keys are {@link DepID} of each importer node.\n */\nexport const getImporterSpecs = ({\n add,\n graph,\n remove,\n}: GetImporterSpecsOptions) => {\n const addResult: AddImportersDependenciesMap =\n new AddImportersDependenciesMapImpl()\n const removeResult: RemoveImportersDependenciesMap =\n new RemoveImportersDependenciesMapImpl()\n\n // traverse the list of importers in the starting graph\n for (const importer of graph.importers) {\n // uses a Map keying to the spec.name in order to easily make sure there's\n // only a single dependency entry for a given dependency for each importer\n const addDeps = new Map<string, Dependency>()\n const removeDeps = new Set<string>()\n // if an edge from the graph is not listed in the manifest,\n // add that edge to the list of dependencies to be removed\n for (const edge of importer.edgesOut.values()) {\n if (\n !hasDepName(importer, edge) &&\n !add.get(importer.id)?.has(edge.name)\n ) {\n removeDeps.add(edge.name)\n removeResult.modifiedDependencies = true\n }\n }\n // if a dependency is listed in the manifest but not in the graph,\n // add that dependency to the list of dependencies to be added\n for (const depType of longDependencyTypes) {\n const deps = Object.entries(importer.manifest?.[depType] ?? {})\n for (const [depName, depSpec] of deps) {\n const edge = importer.edgesOut.get(depName)\n if (!edge?.to) {\n addDeps.set(\n depName,\n asDependency({\n spec: Spec.parse(depName, depSpec),\n type: shorten(depType, depName, importer.manifest),\n }),\n )\n }\n }\n }\n addResult.set(importer.id, addDeps)\n removeResult.set(importer.id, removeDeps)\n }\n\n // merges any provided specs to add to the current found results\n for (const [id, addDeps] of add.entries()) {\n const deps = addResult.get(id)\n if (!deps) {\n throw error('Not an importer', { found: id })\n }\n for (const [name, dep] of addDeps.entries()) {\n deps.set(name, dep)\n }\n }\n\n // Merges results from user-provided `remove` option with any remove\n // results found from comparing the manifest with the loaded graph\n for (const [key, removeSet] of remove) {\n const importerRemoveItem = removeResult.get(key)\n if (importerRemoveItem) {\n for (const depName of removeSet) {\n importerRemoveItem.add(depName)\n }\n }\n }\n\n // Removes any references to an importer that no longer has specs\n for (const [key, removeItem] of removeResult) {\n if (removeItem.size === 0) {\n removeResult.delete(key)\n }\n }\n\n // removes already satisfied dependencies from the dependencies list\n removeSatisfiedSpecs({\n add: addResult,\n graph,\n })\n\n // set the modifiedDependencies flag if any\n // of the importers have modified dependencies\n for (const addDeps of addResult.values()) {\n if (addDeps.size > 0) {\n addResult.modifiedDependencies = true\n break\n }\n }\n\n return {\n add: addResult,\n remove: removeResult,\n }\n}\n"]}
1
+ {"version":3,"file":"get-importer-specs.js","sourceRoot":"","sources":["../../../src/ideal/get-importer-specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,mB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B,SAAS,CAAC,oBAAoB,GAAG,IAAI,CAAA;YACrC,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,EAAE,SAAS;QACd,MAAM,EAAE,YAAY;KACrB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport { shorten, asDependency } from '../dependencies.ts'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { removeSatisfiedSpecs } from './remove-satisfied-specs.ts'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n BuildIdealRemoveOptions,\n} from './types.ts'\nimport type { Edge } from '../edge.ts'\nimport type { Node } from '../node.ts'\nimport type { Graph } from '../graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\n\nexport type GetImporterSpecsOptions = BuildIdealAddOptions &\n BuildIdealFromGraphOptions &\n BuildIdealRemoveOptions &\n SpecOptions\n\nconst hasDepName = (importer: Node, edge: Edge): boolean => {\n for (const depType of longDependencyTypes) {\n const listedDeps = importer.manifest?.[depType]\n if (listedDeps && Object.hasOwn(listedDeps, edge.name))\n return true\n }\n return false\n}\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\n/**\n * Given a {@link Graph} and a list of {@link Dependency}, merges the\n * dependencies info found in the graph importers and returns the add & remove\n * results as a Map in which keys are {@link DepID} of each importer node.\n */\nexport const getImporterSpecs = (\n options: GetImporterSpecsOptions,\n) => {\n const { add, graph, remove } = options\n const addResult: AddImportersDependenciesMap =\n new AddImportersDependenciesMapImpl()\n const removeResult: RemoveImportersDependenciesMap =\n new RemoveImportersDependenciesMapImpl()\n\n // traverse the list of importers in the starting graph\n for (const importer of graph.importers) {\n // uses a Map keying to the spec.name in order to easily make sure there's\n // only a single dependency entry for a given dependency for each importer\n const addDeps = new Map<string, Dependency>()\n const removeDeps = new Set<string>()\n // if an edge from the graph is not listed in the manifest,\n // add that edge to the list of dependencies to be removed\n for (const edge of importer.edgesOut.values()) {\n if (\n !hasDepName(importer, edge) &&\n !add.get(importer.id)?.has(edge.name)\n ) {\n removeDeps.add(edge.name)\n removeResult.modifiedDependencies = true\n }\n }\n // if a dependency is listed in the manifest but not in the graph,\n // add that dependency to the list of dependencies to be added\n for (const depType of longDependencyTypes) {\n const deps = Object.entries(importer.manifest?.[depType] ?? {})\n for (const [depName, depSpec] of deps) {\n const edge = importer.edgesOut.get(depName)\n const dependency = asDependency({\n spec: Spec.parse(depName, depSpec, options),\n type: shorten(depType, depName, importer.manifest),\n })\n if (!edge?.to) {\n addDeps.set(depName, dependency)\n }\n }\n }\n addResult.set(importer.id, addDeps)\n removeResult.set(importer.id, removeDeps)\n }\n\n // merges any provided specs to add to the current found results\n for (const [id, addDeps] of add.entries()) {\n const deps = addResult.get(id)\n if (!deps) {\n throw error('Not an importer', { found: id })\n }\n for (const [name, dep] of addDeps.entries()) {\n deps.set(name, dep)\n }\n }\n\n // Merges results from user-provided `remove` option with any remove\n // results found from comparing the manifest with the loaded graph\n for (const [key, removeSet] of remove) {\n const importerRemoveItem = removeResult.get(key)\n if (importerRemoveItem) {\n for (const depName of removeSet) {\n importerRemoveItem.add(depName)\n }\n }\n }\n\n // Removes any references to an importer that no longer has specs\n for (const [key, removeItem] of removeResult) {\n if (removeItem.size === 0) {\n removeResult.delete(key)\n }\n }\n\n // removes already satisfied dependencies from the dependencies list\n removeSatisfiedSpecs({\n add: addResult,\n graph,\n })\n\n // set the modifiedDependencies flag if any\n // of the importers have modified dependencies\n for (const addDeps of addResult.values()) {\n if (addDeps.size > 0) {\n addResult.modifiedDependencies = true\n break\n }\n }\n\n return {\n add: addResult,\n remove: removeResult,\n }\n}\n"]}
@@ -7,10 +7,12 @@ export * from './visualization/json-output.ts';
7
7
  export * from './visualization/human-readable-output.ts';
8
8
  export * from './visualization/mermaid-output.ts';
9
9
  export * from './stringify-node.ts';
10
- export * from './types.ts';
11
10
  export * from './install.ts';
12
11
  export * from './uninstall.ts';
12
+ export * from './update.ts';
13
13
  export * from './diff.ts';
14
+ export * from './modifiers.ts';
15
+ export * from './virtual-root.ts';
14
16
  import type { LoadOptions as ActualLoadOptions } from './actual/load.ts';
15
17
  export declare const actual: {
16
18
  load: (options: ActualLoadOptions) => import("./graph.ts").Graph;
@@ -18,9 +20,9 @@ export declare const actual: {
18
20
  import type { LoadOptions as LockfileLoadOptions } from './lockfile/load.ts';
19
21
  export declare const lockfile: {
20
22
  load: (options: LockfileLoadOptions) => import("./graph.ts").Graph;
21
- loadEdges: (graph: import("./types.ts").GraphLike, edges: import("./lockfile/types.ts").LockfileData["edges"], options: import("@vltpkg/spec").SpecOptions) => void;
22
- loadNodes: (graph: import("./types.ts").GraphLike, nodes: import("./lockfile/types.ts").LockfileData["nodes"]) => void;
23
- save: (options: import("./lockfile/save.ts").SaveOptions) => void;
23
+ loadEdges: (graph: import("@vltpkg/types").GraphLike, edges: import("./lockfile/types.ts").LockfileData["edges"], options: import("@vltpkg/spec").SpecOptions) => void;
24
+ loadNodes: (graph: import("@vltpkg/types").GraphLike, nodes: import("./lockfile/types.ts").LockfileData["nodes"], options: import("@vltpkg/spec").SpecOptions, actual?: import("@vltpkg/types").GraphLike) => void;
25
+ save: (options: Omit<import("./lockfile/save.ts").SaveOptions, "saveManifests">) => void;
24
26
  };
25
27
  export type { ActualLoadOptions, LockfileLoadOptions };
26
28
  export type { SaveOptions } from './lockfile/save.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACz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ACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AAGjC,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACxE,eAAO,MAAM,MAAM;;CAAuB,CAAA;AAG1C,OAAO,KAAK,EAAE,WAAW,IAAI,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAI5E,eAAO,MAAM,QAAQ;;;;;CAKpB,CAAA;AAED,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAA;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,YAAY,EAAE,iBAAiB,EAAE,CAAA;AACjC,eAAO,MAAM,KAAK;;CAAY,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/esm/index.js CHANGED
@@ -7,10 +7,12 @@ export * from "./visualization/json-output.js";
7
7
  export * from "./visualization/human-readable-output.js";
8
8
  export * from "./visualization/mermaid-output.js";
9
9
  export * from "./stringify-node.js";
10
- export * from "./types.js";
11
10
  export * from "./install.js";
12
11
  export * from "./uninstall.js";
12
+ export * from "./update.js";
13
13
  export * from "./diff.js";
14
+ export * from "./modifiers.js";
15
+ export * from "./virtual-root.js";
14
16
  import { load as actualLoad } from "./actual/load.js";
15
17
  export const actual = { load: actualLoad };
16
18
  import { load as lockfileLoad } from "./lockfile/load.js";