@vltpkg/graph 1.0.0-rc.9 → 1.0.2

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 (228) hide show
  1. package/README.md +101 -22
  2. package/dist/{esm/actual → actual}/load.d.ts +8 -1
  3. package/dist/{esm/actual → actual}/load.js +29 -6
  4. package/dist/{esm/browser.d.ts → browser.d.ts} +0 -1
  5. package/dist/{esm/browser.js → browser.js} +0 -1
  6. package/dist/{esm/build.d.ts → build.d.ts} +0 -1
  7. package/dist/{esm/build.js → build.js} +0 -1
  8. package/dist/{esm/dependencies.d.ts → dependencies.d.ts} +0 -1
  9. package/dist/{esm/dependencies.js → dependencies.js} +3 -2
  10. package/dist/{esm/diff.d.ts → diff.d.ts} +2 -1
  11. package/dist/{esm/diff.js → diff.js} +5 -2
  12. package/dist/{esm/edge.d.ts → edge.d.ts} +0 -1
  13. package/dist/{esm/edge.js → edge.js} +0 -1
  14. package/dist/{esm/fixup-added-names.d.ts → fixup-added-names.d.ts} +4 -2
  15. package/dist/{esm/fixup-added-names.js → fixup-added-names.js} +16 -1
  16. package/dist/{esm/graph.d.ts → graph.d.ts} +13 -1
  17. package/dist/{esm/graph.js → graph.js} +49 -12
  18. package/dist/{esm/ideal → ideal}/append-nodes.d.ts +14 -3
  19. package/dist/{esm/ideal → ideal}/append-nodes.js +252 -64
  20. package/dist/{esm/ideal → ideal}/build-ideal-from-starting-graph.d.ts +0 -1
  21. package/dist/{esm/ideal → ideal}/build-ideal-from-starting-graph.js +0 -1
  22. package/dist/{esm/ideal → ideal}/build.d.ts +0 -1
  23. package/dist/{esm/ideal → ideal}/build.js +15 -2
  24. package/dist/{esm/ideal → ideal}/get-importer-specs.d.ts +0 -1
  25. package/dist/{esm/ideal → ideal}/get-importer-specs.js +13 -2
  26. package/dist/ideal/peers.d.ts +160 -0
  27. package/dist/ideal/peers.js +696 -0
  28. package/dist/{esm/ideal → ideal}/refresh-ideal-graph.d.ts +0 -5
  29. package/dist/{esm/ideal → ideal}/refresh-ideal-graph.js +11 -26
  30. package/dist/{esm/ideal → ideal}/remove-satisfied-specs.d.ts +0 -1
  31. package/dist/{esm/ideal → ideal}/remove-satisfied-specs.js +8 -1
  32. package/dist/ideal/sorting.d.ts +45 -0
  33. package/dist/ideal/sorting.js +70 -0
  34. package/dist/{esm/ideal → ideal}/types.d.ts +1 -6
  35. package/dist/ideal/types.js +1 -0
  36. package/dist/{esm/index.d.ts → index.d.ts} +0 -1
  37. package/dist/{esm/index.js → index.js} +0 -1
  38. package/dist/{esm/install.d.ts → install.d.ts} +2 -1
  39. package/dist/{esm/install.js → install.js} +24 -4
  40. package/dist/{esm/lockfile → lockfile}/load-edges.d.ts +0 -1
  41. package/dist/{esm/lockfile → lockfile}/load-edges.js +16 -6
  42. package/dist/{esm/lockfile → lockfile}/load-nodes.d.ts +0 -1
  43. package/dist/{esm/lockfile → lockfile}/load-nodes.js +6 -3
  44. package/dist/{esm/lockfile → lockfile}/load.d.ts +0 -1
  45. package/dist/lockfile/load.js +171 -0
  46. package/dist/{esm/lockfile → lockfile}/save.d.ts +1 -2
  47. package/dist/{esm/lockfile → lockfile}/save.js +17 -11
  48. package/dist/{esm/lockfile → lockfile}/types.d.ts +7 -1
  49. package/dist/{esm/lockfile → lockfile}/types.js +6 -1
  50. package/dist/{esm/modifiers.d.ts → modifiers.d.ts} +0 -1
  51. package/dist/{esm/modifiers.js → modifiers.js} +0 -1
  52. package/dist/{esm/node.d.ts → node.d.ts} +2 -1
  53. package/dist/{esm/node.js → node.js} +5 -1
  54. package/dist/{esm/non-empty-list.d.ts → non-empty-list.d.ts} +0 -1
  55. package/dist/{esm/non-empty-list.js → non-empty-list.js} +0 -1
  56. package/dist/path-security-error.d.ts +5 -0
  57. package/dist/path-security-error.js +13 -0
  58. package/dist/{esm/reify → reify}/add-edge.d.ts +0 -1
  59. package/dist/{esm/reify → reify}/add-edge.js +10 -4
  60. package/dist/{esm/reify → reify}/add-edges.d.ts +0 -1
  61. package/dist/{esm/reify → reify}/add-edges.js +0 -1
  62. package/dist/{esm/reify → reify}/add-nodes.d.ts +0 -1
  63. package/dist/{esm/reify → reify}/add-nodes.js +0 -1
  64. package/dist/{esm/reify → reify}/bin-chmod.d.ts +0 -1
  65. package/dist/{esm/reify → reify}/bin-chmod.js +0 -1
  66. package/dist/{esm/reify → reify}/build.d.ts +0 -1
  67. package/dist/{esm/reify → reify}/build.js +12 -4
  68. package/dist/{esm/reify → reify}/calculate-save-value.d.ts +1 -2
  69. package/dist/{esm/reify → reify}/calculate-save-value.js +11 -5
  70. package/dist/{esm/reify → reify}/check-needed-build.d.ts +10 -1
  71. package/dist/reify/check-needed-build.js +71 -0
  72. package/dist/{esm/reify → reify}/delete-edge.d.ts +0 -1
  73. package/dist/{esm/reify → reify}/delete-edge.js +0 -1
  74. package/dist/{esm/reify → reify}/delete-edges.d.ts +0 -1
  75. package/dist/{esm/reify → reify}/delete-edges.js +0 -1
  76. package/dist/{esm/reify → reify}/delete-nodes.d.ts +0 -1
  77. package/dist/{esm/reify → reify}/delete-nodes.js +0 -1
  78. package/dist/{esm/reify → reify}/extract-node.d.ts +0 -1
  79. package/dist/{esm/reify → reify}/extract-node.js +10 -3
  80. package/dist/{esm/reify → reify}/index.d.ts +3 -1
  81. package/dist/{esm/reify → reify}/index.js +25 -5
  82. package/dist/{esm/reify → reify}/internal-hoist.d.ts +0 -1
  83. package/dist/{esm/reify → reify}/internal-hoist.js +0 -1
  84. package/dist/{esm/reify → reify}/optional-fail.d.ts +0 -1
  85. package/dist/{esm/reify → reify}/optional-fail.js +0 -1
  86. package/dist/{esm/reify → reify}/rollback.d.ts +0 -1
  87. package/dist/{esm/reify → reify}/rollback.js +0 -1
  88. package/dist/{esm/reify → reify}/update-importers-package-json.d.ts +11 -2
  89. package/dist/{esm/reify → reify}/update-importers-package-json.js +4 -5
  90. package/dist/{esm/remove-optional-subgraph.d.ts → remove-optional-subgraph.d.ts} +0 -1
  91. package/dist/{esm/remove-optional-subgraph.js → remove-optional-subgraph.js} +0 -1
  92. package/dist/{esm/resolve-save-type.d.ts → resolve-save-type.d.ts} +0 -1
  93. package/dist/{esm/resolve-save-type.js → resolve-save-type.js} +0 -1
  94. package/dist/{esm/stringify-node.d.ts → stringify-node.d.ts} +0 -1
  95. package/dist/{esm/stringify-node.js → stringify-node.js} +0 -1
  96. package/dist/{esm/transfer-data → transfer-data}/load.d.ts +0 -1
  97. package/dist/{esm/transfer-data → transfer-data}/load.js +8 -5
  98. package/dist/{esm/uninstall.d.ts → uninstall.d.ts} +0 -1
  99. package/dist/{esm/uninstall.js → uninstall.js} +17 -7
  100. package/dist/{esm/update.d.ts → update.d.ts} +0 -1
  101. package/dist/{esm/update.js → update.js} +1 -1
  102. package/dist/{esm/virtual-root.d.ts → virtual-root.d.ts} +0 -1
  103. package/dist/{esm/virtual-root.js → virtual-root.js} +0 -1
  104. package/dist/{esm/visualization → visualization}/human-readable-output.d.ts +0 -1
  105. package/dist/{esm/visualization → visualization}/human-readable-output.js +0 -1
  106. package/dist/{esm/visualization → visualization}/json-output.d.ts +0 -1
  107. package/dist/{esm/visualization → visualization}/json-output.js +0 -1
  108. package/dist/{esm/visualization → visualization}/mermaid-output.d.ts +2 -2
  109. package/dist/{esm/visualization → visualization}/mermaid-output.js +27 -21
  110. package/dist/{esm/visualization → visualization}/object-like-output.d.ts +0 -1
  111. package/dist/{esm/visualization → visualization}/object-like-output.js +0 -1
  112. package/package.json +57 -62
  113. package/dist/esm/actual/load.d.ts.map +0 -1
  114. package/dist/esm/actual/load.js.map +0 -1
  115. package/dist/esm/browser.d.ts.map +0 -1
  116. package/dist/esm/browser.js.map +0 -1
  117. package/dist/esm/build.d.ts.map +0 -1
  118. package/dist/esm/build.js.map +0 -1
  119. package/dist/esm/dependencies.d.ts.map +0 -1
  120. package/dist/esm/dependencies.js.map +0 -1
  121. package/dist/esm/diff.d.ts.map +0 -1
  122. package/dist/esm/diff.js.map +0 -1
  123. package/dist/esm/edge.d.ts.map +0 -1
  124. package/dist/esm/edge.js.map +0 -1
  125. package/dist/esm/fixup-added-names.d.ts.map +0 -1
  126. package/dist/esm/fixup-added-names.js.map +0 -1
  127. package/dist/esm/graph.d.ts.map +0 -1
  128. package/dist/esm/graph.js.map +0 -1
  129. package/dist/esm/ideal/append-nodes.d.ts.map +0 -1
  130. package/dist/esm/ideal/append-nodes.js.map +0 -1
  131. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +0 -1
  132. package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +0 -1
  133. package/dist/esm/ideal/build.d.ts.map +0 -1
  134. package/dist/esm/ideal/build.js.map +0 -1
  135. package/dist/esm/ideal/get-importer-specs.d.ts.map +0 -1
  136. package/dist/esm/ideal/get-importer-specs.js.map +0 -1
  137. package/dist/esm/ideal/get-ordered-dependencies.d.ts +0 -10
  138. package/dist/esm/ideal/get-ordered-dependencies.d.ts.map +0 -1
  139. package/dist/esm/ideal/get-ordered-dependencies.js +0 -42
  140. package/dist/esm/ideal/get-ordered-dependencies.js.map +0 -1
  141. package/dist/esm/ideal/peers.d.ts +0 -71
  142. package/dist/esm/ideal/peers.d.ts.map +0 -1
  143. package/dist/esm/ideal/peers.js +0 -318
  144. package/dist/esm/ideal/peers.js.map +0 -1
  145. package/dist/esm/ideal/refresh-ideal-graph.d.ts.map +0 -1
  146. package/dist/esm/ideal/refresh-ideal-graph.js.map +0 -1
  147. package/dist/esm/ideal/remove-satisfied-specs.d.ts.map +0 -1
  148. package/dist/esm/ideal/remove-satisfied-specs.js.map +0 -1
  149. package/dist/esm/ideal/types.d.ts.map +0 -1
  150. package/dist/esm/ideal/types.js +0 -2
  151. package/dist/esm/ideal/types.js.map +0 -1
  152. package/dist/esm/index.d.ts.map +0 -1
  153. package/dist/esm/index.js.map +0 -1
  154. package/dist/esm/install.d.ts.map +0 -1
  155. package/dist/esm/install.js.map +0 -1
  156. package/dist/esm/lockfile/load-edges.d.ts.map +0 -1
  157. package/dist/esm/lockfile/load-edges.js.map +0 -1
  158. package/dist/esm/lockfile/load-nodes.d.ts.map +0 -1
  159. package/dist/esm/lockfile/load-nodes.js.map +0 -1
  160. package/dist/esm/lockfile/load.d.ts.map +0 -1
  161. package/dist/esm/lockfile/load.js +0 -64
  162. package/dist/esm/lockfile/load.js.map +0 -1
  163. package/dist/esm/lockfile/save.d.ts.map +0 -1
  164. package/dist/esm/lockfile/save.js.map +0 -1
  165. package/dist/esm/lockfile/types.d.ts.map +0 -1
  166. package/dist/esm/lockfile/types.js.map +0 -1
  167. package/dist/esm/modifiers.d.ts.map +0 -1
  168. package/dist/esm/modifiers.js.map +0 -1
  169. package/dist/esm/node.d.ts.map +0 -1
  170. package/dist/esm/node.js.map +0 -1
  171. package/dist/esm/non-empty-list.d.ts.map +0 -1
  172. package/dist/esm/non-empty-list.js.map +0 -1
  173. package/dist/esm/package.json +0 -3
  174. package/dist/esm/reify/add-edge.d.ts.map +0 -1
  175. package/dist/esm/reify/add-edge.js.map +0 -1
  176. package/dist/esm/reify/add-edges.d.ts.map +0 -1
  177. package/dist/esm/reify/add-edges.js.map +0 -1
  178. package/dist/esm/reify/add-nodes.d.ts.map +0 -1
  179. package/dist/esm/reify/add-nodes.js.map +0 -1
  180. package/dist/esm/reify/bin-chmod.d.ts.map +0 -1
  181. package/dist/esm/reify/bin-chmod.js.map +0 -1
  182. package/dist/esm/reify/build.d.ts.map +0 -1
  183. package/dist/esm/reify/build.js.map +0 -1
  184. package/dist/esm/reify/calculate-save-value.d.ts.map +0 -1
  185. package/dist/esm/reify/calculate-save-value.js.map +0 -1
  186. package/dist/esm/reify/check-needed-build.d.ts.map +0 -1
  187. package/dist/esm/reify/check-needed-build.js +0 -50
  188. package/dist/esm/reify/check-needed-build.js.map +0 -1
  189. package/dist/esm/reify/delete-edge.d.ts.map +0 -1
  190. package/dist/esm/reify/delete-edge.js.map +0 -1
  191. package/dist/esm/reify/delete-edges.d.ts.map +0 -1
  192. package/dist/esm/reify/delete-edges.js.map +0 -1
  193. package/dist/esm/reify/delete-nodes.d.ts.map +0 -1
  194. package/dist/esm/reify/delete-nodes.js.map +0 -1
  195. package/dist/esm/reify/extract-node.d.ts.map +0 -1
  196. package/dist/esm/reify/extract-node.js.map +0 -1
  197. package/dist/esm/reify/index.d.ts.map +0 -1
  198. package/dist/esm/reify/index.js.map +0 -1
  199. package/dist/esm/reify/internal-hoist.d.ts.map +0 -1
  200. package/dist/esm/reify/internal-hoist.js.map +0 -1
  201. package/dist/esm/reify/optional-fail.d.ts.map +0 -1
  202. package/dist/esm/reify/optional-fail.js.map +0 -1
  203. package/dist/esm/reify/rollback.d.ts.map +0 -1
  204. package/dist/esm/reify/rollback.js.map +0 -1
  205. package/dist/esm/reify/update-importers-package-json.d.ts.map +0 -1
  206. package/dist/esm/reify/update-importers-package-json.js.map +0 -1
  207. package/dist/esm/remove-optional-subgraph.d.ts.map +0 -1
  208. package/dist/esm/remove-optional-subgraph.js.map +0 -1
  209. package/dist/esm/resolve-save-type.d.ts.map +0 -1
  210. package/dist/esm/resolve-save-type.js.map +0 -1
  211. package/dist/esm/stringify-node.d.ts.map +0 -1
  212. package/dist/esm/stringify-node.js.map +0 -1
  213. package/dist/esm/transfer-data/load.d.ts.map +0 -1
  214. package/dist/esm/transfer-data/load.js.map +0 -1
  215. package/dist/esm/uninstall.d.ts.map +0 -1
  216. package/dist/esm/uninstall.js.map +0 -1
  217. package/dist/esm/update.d.ts.map +0 -1
  218. package/dist/esm/update.js.map +0 -1
  219. package/dist/esm/virtual-root.d.ts.map +0 -1
  220. package/dist/esm/virtual-root.js.map +0 -1
  221. package/dist/esm/visualization/human-readable-output.d.ts.map +0 -1
  222. package/dist/esm/visualization/human-readable-output.js.map +0 -1
  223. package/dist/esm/visualization/json-output.d.ts.map +0 -1
  224. package/dist/esm/visualization/json-output.js.map +0 -1
  225. package/dist/esm/visualization/mermaid-output.d.ts.map +0 -1
  226. package/dist/esm/visualization/mermaid-output.js.map +0 -1
  227. package/dist/esm/visualization/object-like-output.d.ts.map +0 -1
  228. package/dist/esm/visualization/object-like-output.js.map +0 -1
@@ -41,8 +41,3 @@ export type RefreshIdealGraphOptions = BuildIdealAddOptions & BuildIdealRemoveOp
41
41
  * Rebuilds the provided ideal graph.
42
42
  */
43
43
  export declare const refreshIdealGraph: ({ add, graph, modifiers, packageInfo, scurry, actual, remove, remover, transientAdd, transientRemove, ...specOptions }: RefreshIdealGraphOptions) => Promise<void>;
44
- /**
45
- * Retrieve the next unique index for a peer context set.
46
- */
47
- export declare const nextPeerContextIndex: () => number;
48
- //# sourceMappingURL=refresh-ideal-graph.d.ts.map
@@ -1,25 +1,17 @@
1
1
  import { appendNodes } from "./append-nodes.js";
2
- import { getNodeOrderedDependencies } from "./get-ordered-dependencies.js";
2
+ import { compareByHasPeerDeps, getNodeOrderedDependencies, } from "./sorting.js";
3
3
  /**
4
4
  * Returns an ordered list of importer nodes.
5
5
  */
6
6
  const getOrderedImporters = (graph) => {
7
7
  const orderedImporters = [...graph.importers].sort((a, b) => {
8
- // sorts importers first by usage of peer deps
9
- const aIsPeer = (a.manifest?.peerDependencies &&
10
- Object.keys(a.manifest.peerDependencies).length > 0) ?
11
- 1
12
- : 0;
13
- const bIsPeer = (b.manifest?.peerDependencies &&
14
- Object.keys(b.manifest.peerDependencies).length > 0) ?
15
- 1
16
- : 0;
17
- // importers with regular deps only first, with peer deps last
18
- if (aIsPeer !== bIsPeer) {
19
- return aIsPeer - bIsPeer;
20
- }
21
- // if both are in the same group, sort alphabetically by manifest name
22
- return a.name.localeCompare(b.name, 'en');
8
+ // mainImporter always comes first
9
+ /* c8 ignore next */
10
+ if (a === graph.mainImporter)
11
+ return -1;
12
+ if (b === graph.mainImporter)
13
+ return 1;
14
+ return compareByHasPeerDeps({ manifest: a.manifest }, { manifest: b.manifest });
23
15
  });
24
16
  return orderedImporters;
25
17
  };
@@ -40,7 +32,9 @@ export const refreshIdealGraph = async ({ add, graph, modifiers, packageInfo, sc
40
32
  depsPerImporter.set(importer, deps);
41
33
  }
42
34
  // removes all edges to start recalculating the graph
43
- if (add.modifiedDependencies || remove.modifiedDependencies) {
35
+ if (add.modifiedDependencies ||
36
+ remove.modifiedDependencies ||
37
+ graph.optionsChanged) {
44
38
  graph.resetEdges();
45
39
  }
46
40
  // iterates on the list of dependencies per importer updating
@@ -68,12 +62,3 @@ export const refreshIdealGraph = async ({ add, graph, modifiers, packageInfo, sc
68
62
  await Promise.all(extractPromises);
69
63
  }
70
64
  };
71
- /**
72
- * Global index to assign unique ids used to track peer context sets.
73
- */
74
- let peerContextIndex = 0;
75
- /**
76
- * Retrieve the next unique index for a peer context set.
77
- */
78
- export const nextPeerContextIndex = () => peerContextIndex++;
79
- //# sourceMappingURL=refresh-ideal-graph.js.map
@@ -5,4 +5,3 @@ export type RemoveSatisfiedSpecsOptions = BuildIdealAddOptions & BuildIdealFromG
5
5
  * that are already satisfied by the contents of the actual `graph`.
6
6
  */
7
7
  export declare const removeSatisfiedSpecs: ({ add, graph, }: RemoveSatisfiedSpecsOptions) => void;
8
- //# sourceMappingURL=remove-satisfied-specs.d.ts.map
@@ -18,6 +18,14 @@ export const removeSatisfiedSpecs = ({ add, graph, }) => {
18
18
  // brand new edge being added
19
19
  continue;
20
20
  }
21
+ // If the spec type has changed (e.g., from "registry" to
22
+ // "catalog" or vice versa), keep it in the add list so the
23
+ // edge gets rebuilt with the updated spec, even if the
24
+ // resolved node is the same.
25
+ const edgeIsCatalog = edge.spec.type === 'catalog';
26
+ const depIsCatalog = dependency.spec.type === 'catalog';
27
+ if (edgeIsCatalog !== depIsCatalog)
28
+ continue;
21
29
  // If the current graph edge is already valid, then we remove that
22
30
  // dependency item from the list of items to be added to the graph
23
31
  if (satisfies(edge.to?.id, dependency.spec, edge.from.location, graph.projectRoot, graph.monorepo)) {
@@ -32,4 +40,3 @@ export const removeSatisfiedSpecs = ({ add, graph, }) => {
32
40
  }
33
41
  }
34
42
  };
35
- //# sourceMappingURL=remove-satisfied-specs.js.map
@@ -0,0 +1,45 @@
1
+ import type { BuildIdealAddOptions, BuildIdealRemoveOptions } from './types.ts';
2
+ import type { Spec } from '@vltpkg/spec';
3
+ import type { Manifest, NormalizedManifest } from '@vltpkg/types';
4
+ import type { Node } from '../node.ts';
5
+ import type { Dependency } from '../dependencies.ts';
6
+ type SortableByHasPeerDeps = {
7
+ /** Package manifest containing dependency information */
8
+ manifest?: Manifest | NormalizedManifest;
9
+ /** Package name */
10
+ name?: string;
11
+ /** Package specifier */
12
+ spec?: Spec;
13
+ };
14
+ type SortableByType = {
15
+ /** Dependency type (e.g., 'prod', 'dev', 'peer', 'peerOptional') */
16
+ type: string;
17
+ /** Target node with package name */
18
+ target?: {
19
+ name: string;
20
+ };
21
+ /** Package specifier */
22
+ spec?: Spec;
23
+ };
24
+ /**
25
+ * Checks if a dependency type is a peer dependency.
26
+ */
27
+ export declare const isPeerType: (type: string) => type is "peer" | "peerOptional";
28
+ /**
29
+ * Sorts a list of dependencies by whether they have peer dependencies.
30
+ */
31
+ export declare const compareByHasPeerDeps: (a: SortableByHasPeerDeps, b: SortableByHasPeerDeps) => number;
32
+ /**
33
+ * Sorts a list of dependencies by type and name.
34
+ */
35
+ export declare const compareByType: (a: SortableByType, b: SortableByType) => number;
36
+ /**
37
+ * Computes the ordered list of dependencies for an given node,
38
+ * taking into account additions and removals.
39
+ */
40
+ export declare const getNodeOrderedDependencies: (fromNode: Node, options?: BuildIdealAddOptions & BuildIdealRemoveOptions) => Dependency[];
41
+ /**
42
+ * Sorts a list of dependencies by type.
43
+ */
44
+ export declare const getOrderedDependencies: (deps: Dependency[]) => Dependency[];
45
+ export {};
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Checks if a dependency type is a peer dependency.
3
+ */
4
+ export const isPeerType = (type) => type === 'peer' || type === 'peerOptional';
5
+ /**
6
+ * Sorts a list of dependencies by whether they have peer dependencies.
7
+ */
8
+ export const compareByHasPeerDeps = (a, b) => {
9
+ const aHasPeer = (a.manifest?.peerDependencies &&
10
+ Object.keys(a.manifest.peerDependencies).length > 0) ?
11
+ 1
12
+ : 0;
13
+ const bHasPeer = (b.manifest?.peerDependencies &&
14
+ Object.keys(b.manifest.peerDependencies).length > 0) ?
15
+ 1
16
+ : 0;
17
+ if (aHasPeer !== bHasPeer)
18
+ return aHasPeer - bHasPeer;
19
+ const aName = a.manifest?.name || a.spec?.name || a.name || '';
20
+ const bName = b.manifest?.name ||
21
+ /* c8 ignore next - very hard to test */ b.spec?.name ||
22
+ b.name ||
23
+ '';
24
+ return aName.localeCompare(bName, 'en');
25
+ };
26
+ /**
27
+ * Sorts a list of dependencies by type and name.
28
+ */
29
+ export const compareByType = (a, b) => {
30
+ const aIsPeer = isPeerType(a.type) ? 1 : 0;
31
+ const bIsPeer = isPeerType(b.type) ? 1 : 0;
32
+ if (aIsPeer !== bIsPeer)
33
+ return aIsPeer - bIsPeer;
34
+ const aName = a.target?.name ?? a.spec?.name ?? '';
35
+ const bName = b.target?.name ?? b.spec?.name ?? '';
36
+ return aName.localeCompare(bName, 'en');
37
+ };
38
+ /**
39
+ * Computes the ordered list of dependencies for an given node,
40
+ * taking into account additions and removals.
41
+ */
42
+ export const getNodeOrderedDependencies = (fromNode, options) => {
43
+ // using a map here instead of an array helps us get simpler
44
+ // deduplication while iterating through all the items at hand:
45
+ // existing dependencies in the graph, dependencies to be added, etc.
46
+ const deps = new Map();
47
+ for (const [name, { spec, type }] of fromNode.edgesOut.entries()) {
48
+ deps.set(name, { spec, type });
49
+ }
50
+ // next iterate through the list of dependencies to be added
51
+ const addedDeps = options?.add.get(fromNode.id);
52
+ if (addedDeps) {
53
+ for (const [name, { spec, type }] of addedDeps.entries()) {
54
+ deps.set(name, { spec, type });
55
+ }
56
+ }
57
+ // finally iterate through the list of dependencies to be removed
58
+ const removedDeps = options?.remove.get(fromNode.id);
59
+ if (removedDeps) {
60
+ for (const name of removedDeps) {
61
+ deps.delete(name);
62
+ }
63
+ }
64
+ // now turn the map into a sorted array
65
+ return getOrderedDependencies([...deps.values()]);
66
+ };
67
+ /**
68
+ * Sorts a list of dependencies by type.
69
+ */
70
+ export const getOrderedDependencies = (deps) => [...deps].sort(compareByType);
@@ -59,11 +59,7 @@ export type AppendNodeEntry = {
59
59
  depth: number;
60
60
  peerContext: PeerContext;
61
61
  updateContext: {
62
- putEntries: () => {
63
- dependent: Node;
64
- spec: Spec;
65
- type: DependencySaveType;
66
- }[] | undefined;
62
+ putEntries: () => PeerContextEntryInput[] | undefined;
67
63
  resolvePeerDeps: () => void;
68
64
  };
69
65
  };
@@ -109,4 +105,3 @@ export type PeerContextEntryInput = {
109
105
  export type PeerContext = Map<string, PeerContextEntry> & {
110
106
  index?: number;
111
107
  };
112
- //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -36,4 +36,3 @@ export declare const ideal: {
36
36
  export { reify } from './reify/index.ts';
37
37
  export type { ReifyOptions } from './reify/index.ts';
38
38
  export type { BuildResult } from './reify/build.ts';
39
- //# sourceMappingURL=index.d.ts.map
@@ -30,4 +30,3 @@ export const lockfile = {
30
30
  import { build } from "./ideal/build.js";
31
31
  export const ideal = { build };
32
32
  export { reify } from "./reify/index.js";
33
- //# sourceMappingURL=index.js.map
@@ -7,6 +7,8 @@ export type InstallOptions = LoadOptions & {
7
7
  packageInfo: PackageInfoClient;
8
8
  cleanInstall?: boolean;
9
9
  allowScripts: string;
10
+ saveExact?: boolean;
11
+ savePrefix?: string;
10
12
  };
11
13
  export declare const install: (options: InstallOptions, add?: AddImportersDependenciesMap) => Promise<{
12
14
  graph: Graph;
@@ -17,4 +19,3 @@ export declare const install: (options: InstallOptions, add?: AddImportersDepend
17
19
  graph: Graph;
18
20
  diff: import("./diff.ts").Diff;
19
21
  }>;
20
- //# sourceMappingURL=install.d.ts.map
@@ -13,6 +13,7 @@ import { load as loadVirtual } from "./lockfile/load.js";
13
13
  import { getImporterSpecs } from "./ideal/get-importer-specs.js";
14
14
  import { lockfile } from "./index.js";
15
15
  import { updatePackageJson } from "./reify/update-importers-package-json.js";
16
+ import { Monorepo } from '@vltpkg/workspaces';
16
17
  export const install = async (options, add) => {
17
18
  // Validate incompatible options
18
19
  if (options.lockfileOnly && options.cleanInstall) {
@@ -41,6 +42,14 @@ export const install = async (options, add) => {
41
42
  throw err;
42
43
  }
43
44
  }
45
+ // Load an unfiltered monorepo to ensure all workspace importers are
46
+ // included in the graph. This is necessary because the options.monorepo
47
+ // may be filtered by -w/--workspace flags, which would cause nodes/edges
48
+ // from other workspaces to be lost during graph construction.
49
+ const fullMonorepo = Monorepo.maybeLoad(options.projectRoot, {
50
+ packageJson: options.packageJson,
51
+ scurry: options.scurry,
52
+ });
44
53
  if (options.frozenLockfile) {
45
54
  // validates no add/remove operations are requested
46
55
  if (add?.modifiedDependencies) {
@@ -55,6 +64,7 @@ export const install = async (options, add) => {
55
64
  const lockfileGraph = loadVirtual({
56
65
  ...options,
57
66
  mainManifest,
67
+ monorepo: fullMonorepo,
58
68
  });
59
69
  const emptyAdd = Object.assign(new Map(), { modifiedDependencies: false });
60
70
  const emptyRemove = Object.assign(new Map(), {
@@ -84,8 +94,12 @@ export const install = async (options, add) => {
84
94
  }
85
95
  if (importerSpecs.add.modifiedDependencies ||
86
96
  importerSpecs.remove.modifiedDependencies ||
87
- specChanges.length > 0) {
97
+ specChanges.length > 0 ||
98
+ lockfileGraph.optionsChanged) {
88
99
  const details = [];
100
+ if (lockfileGraph.optionsChanged) {
101
+ details.push(' Configuration options have changed (e.g. modifiers, registries, catalogs)');
102
+ }
89
103
  if (specChanges.length > 0) {
90
104
  details.push(...specChanges);
91
105
  }
@@ -134,6 +148,7 @@ export const install = async (options, add) => {
134
148
  mainManifest,
135
149
  loadManifests: true,
136
150
  modifiers: undefined, // modifiers should not be used here
151
+ monorepo: fullMonorepo,
137
152
  });
138
153
  // if the actual graph has no dependencies, it's simpler to ignore it
139
154
  // this allows us to check for its availability later on for properly
@@ -150,11 +165,17 @@ export const install = async (options, add) => {
150
165
  modifiers,
151
166
  remove,
152
167
  remover,
168
+ monorepo: fullMonorepo,
153
169
  });
154
170
  // If lockfileOnly is enabled, skip reify and only save the lockfile
155
171
  if (options.lockfileOnly) {
156
- // Save only the main lockfile, skip all filesystem operations
157
- lockfile.save({ graph, modifiers });
172
+ // Save only the main lockfile, skip all filesystem operations.
173
+ // Spread `options` so that spec-level config (registry,
174
+ // scoped-registries, git-hosts, catalogs, etc.) round-trips
175
+ // through the lockfile - otherwise subsequent installs lose
176
+ // the configured registry and rewrite node/edge DepIDs back
177
+ // to the default npm registry. (See vltpkg/vltpkg#1580.)
178
+ lockfile.save({ ...options, graph, modifiers });
158
179
  const saveImportersPackageJson =
159
180
  /* c8 ignore next */
160
181
  add?.modifiedDependencies || remove.modifiedDependencies ?
@@ -194,4 +215,3 @@ export const install = async (options, add) => {
194
215
  throw err;
195
216
  }
196
217
  };
197
- //# sourceMappingURL=install.js.map
@@ -9,4 +9,3 @@ export type ProcessingEdge = {
9
9
  spec: Spec;
10
10
  };
11
11
  export declare const loadEdges: (graph: GraphLike, edges: LockfileData["edges"], options: SpecOptions) => void;
12
- //# sourceMappingURL=load-edges.d.ts.map
@@ -7,6 +7,11 @@ import { isDependencyTypeShort } from "../dependencies.js";
7
7
  const retrieveNodeFromGraph = (key, value, graph, fromId, seenNodes) => {
8
8
  const foundNode = graph.nodes.get(asDepID(fromId));
9
9
  if (!foundNode) {
10
+ // workspace or file nodes may be missing if the folder was removed
11
+ // while still referenced in the lockfile — skip gracefully
12
+ if (fromId.startsWith('workspace') || fromId.startsWith('file')) {
13
+ return undefined;
14
+ }
10
15
  throw error('Edge info missing its `from` node', {
11
16
  found: {
12
17
  nodes: [...graph.nodes].map(([id]) => id),
@@ -59,6 +64,9 @@ export const loadEdges = (graph, edges, options) => {
59
64
  else {
60
65
  fromNode = retrieveNodeFromGraph(key, value, graph, fromId);
61
66
  }
67
+ // skip edges from workspace nodes that no longer exist
68
+ if (!fromNode)
69
+ continue;
62
70
  const toId = valRest.substring(vrSplit + 1);
63
71
  let toNode = undefined;
64
72
  if (toId !== 'MISSING') {
@@ -78,11 +86,14 @@ export const loadEdges = (graph, edges, options) => {
78
86
  toNode = graph.nodes.get(asDepID(toId));
79
87
  }
80
88
  }
81
- // Parse spec once we know the nodes are valid
82
- const spec = Spec.parse(specName, valRest.substring(0, vrSplit), {
83
- ...options,
84
- registry: fromNode.registry,
85
- });
89
+ // Use the merged options directly — they already carry the
90
+ // correct registry from the lockfile's `options` + caller config.
91
+ // `fromNode.registry` is not populated yet at this point (the
92
+ // post-load hydration loop in load.ts sets it *after* edges are
93
+ // loaded), so overriding here would always inject `undefined`
94
+ // and silently revert to the default npm registry.
95
+ // See vltpkg/vltpkg#1580.
96
+ const spec = Spec.parse(specName, valRest.substring(0, vrSplit), options);
86
97
  if (useOptimizations) {
87
98
  edgeProcessingQueue.push({
88
99
  fromNode,
@@ -103,4 +114,3 @@ export const loadEdges = (graph, edges, options) => {
103
114
  }
104
115
  }
105
116
  };
106
- //# sourceMappingURL=load-edges.js.map
@@ -2,4 +2,3 @@ import type { LockfileData } from './types.ts';
2
2
  import type { GraphLike } from '@vltpkg/types';
3
3
  import type { SpecOptions } from '@vltpkg/spec/browser';
4
4
  export declare const loadNodes: (graph: GraphLike, nodes: LockfileData["nodes"], options: SpecOptions, actual?: GraphLike, throwOnMissingManifest?: boolean) => void;
5
- //# sourceMappingURL=load-nodes.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { error } from '@vltpkg/error-cause';
2
- import { splitDepID, splitExtra } from '@vltpkg/dep-id/browser';
2
+ import { asDepID, splitDepID, splitExtra, } from '@vltpkg/dep-id/browser';
3
3
  import { getBooleanFlagsFromNum, getBuildStateFromNum, } from "./types.js";
4
4
  export const loadNodes = (graph, nodes, options, actual, throwOnMissingManifest) => {
5
5
  const entries = Object.entries(nodes);
@@ -8,6 +8,9 @@ export const loadNodes = (graph, nodes, options, actual, throwOnMissingManifest)
8
8
  // Only used for non-trivial graphs
9
9
  const registryVersionCache = nodeCount > 50 ? new Map() : null;
10
10
  for (const [id, lockfileNode] of entries) {
11
+ // lockfile keys have never been through `encode`, so they can hold
12
+ // anything, and the id is the store directory name
13
+ asDepID(id);
11
14
  const [flags, name, integrity, resolved, location, manifest, rawManifest, platform, bins, buildState,] = lockfileNode;
12
15
  // workspace nodes and the project root node are already part of the
13
16
  // graph and it should not create new nodes if an existing one is there
@@ -68,7 +71,8 @@ export const loadNodes = (graph, nodes, options, actual, throwOnMissingManifest)
68
71
  node.dev = dev;
69
72
  node.optional = optional;
70
73
  node.integrity = integrity ?? referenceNode?.integrity;
71
- node.resolved = resolved ?? referenceNode?.resolved;
74
+ node.resolved =
75
+ type === 'remote' ? filepath : ((resolved ?? referenceNode?.resolved));
72
76
  node.projectRoot = graph.projectRoot;
73
77
  if (!node.resolved)
74
78
  node.setResolved();
@@ -98,4 +102,3 @@ export const loadNodes = (graph, nodes, options, actual, throwOnMissingManifest)
98
102
  }
99
103
  }
100
104
  };
101
- //# sourceMappingURL=load-nodes.js.map
@@ -43,4 +43,3 @@ export type LoadOptions = SpecOptions & {
43
43
  export declare const load: (options: LoadOptions) => Graph;
44
44
  export declare const loadHidden: (options: LoadOptions) => Graph;
45
45
  export declare const loadObject: (options: LoadOptions, lockfileData: Omit<LockfileData, "options" | "lockfileVersion"> & Partial<Pick<LockfileData, "options" | "lockfileVersion">>) => Graph;
46
- //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1,171 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { PackageJson } from '@vltpkg/package-json';
3
+ import { defaultGitHostArchives, defaultGitHosts, defaultJsrRegistries, defaultRegistries, defaultRegistryName, defaultScopeRegistries, } from '@vltpkg/spec';
4
+ import { isRecordStringString } from '@vltpkg/types';
5
+ import { Monorepo } from '@vltpkg/workspaces';
6
+ import { readFileSync } from 'node:fs';
7
+ import { resolve } from 'node:path';
8
+ import { loadEdges } from "./load-edges.js";
9
+ import { loadNodes } from "./load-nodes.js";
10
+ import { Graph } from "../graph.js";
11
+ import { LOCKFILE_VERSION } from "./types.js";
12
+ const loadLockfile = (projectRoot, lockfilePath) => JSON.parse(readFileSync(resolve(projectRoot, lockfilePath), {
13
+ encoding: 'utf8',
14
+ }));
15
+ export const load = (options) => {
16
+ const { projectRoot } = options;
17
+ return loadObject(options, loadLockfile(projectRoot, 'vlt-lock.json'));
18
+ };
19
+ export const loadHidden = (options) => {
20
+ const { projectRoot } = options;
21
+ // Ensure that missing manifests throw an error when loading hidden lockfiles
22
+ options.throwOnMissingManifest = true;
23
+ return loadObject(options, loadLockfile(projectRoot, 'node_modules/.vlt-lock.json'));
24
+ };
25
+ /**
26
+ * Removes entries from `items` that match the corresponding
27
+ * entry in `defaultItems`, returning only non-default values.
28
+ */
29
+ const removeDefaultItems = (defaultItems, items) => {
30
+ const res = {};
31
+ for (const [key, value] of Object.entries(items)) {
32
+ if (!defaultItems[key] || defaultItems[key] !== value) {
33
+ res[key] = value;
34
+ }
35
+ }
36
+ return res;
37
+ };
38
+ /**
39
+ * Builds a normalized options object from the current runtime config
40
+ * using the same cleaning logic as `lockfile/save.ts` so that it can
41
+ * be compared directly against the options stored in a lockfile.
42
+ */
43
+ const buildCurrentOptions = (options) => {
44
+ const hasItems = (o) => o && Object.keys(o).length > 0;
45
+ const cleanModifiers = (options.modifiers &&
46
+ isRecordStringString(options.modifiers.config)) ?
47
+ options.modifiers.config
48
+ : undefined;
49
+ const cleanRegistries = isRecordStringString(options.registries) ?
50
+ removeDefaultItems(defaultRegistries, options.registries)
51
+ : undefined;
52
+ const cleanScopeRegistries = isRecordStringString(options['scoped-registries']) ?
53
+ removeDefaultItems(defaultScopeRegistries, options['scoped-registries'])
54
+ : undefined;
55
+ const cleanJsrRegistries = isRecordStringString(options['jsr-registries']) ?
56
+ removeDefaultItems(defaultJsrRegistries, options['jsr-registries'])
57
+ : undefined;
58
+ const cleanGitHosts = isRecordStringString(options['git-hosts']) ?
59
+ removeDefaultItems(defaultGitHosts, options['git-hosts'])
60
+ : undefined;
61
+ const cleanGitHostArchives = isRecordStringString(options['git-host-archives']) ?
62
+ removeDefaultItems(defaultGitHostArchives, options['git-host-archives'])
63
+ : undefined;
64
+ return {
65
+ ...(hasItems(cleanModifiers) ?
66
+ { modifiers: cleanModifiers }
67
+ : {}),
68
+ ...(hasItems(options.catalog) ?
69
+ { catalog: options.catalog }
70
+ : {}),
71
+ ...(hasItems(options.catalogs) ?
72
+ { catalogs: options.catalogs }
73
+ : {}),
74
+ ...(hasItems(cleanScopeRegistries) ?
75
+ { 'scoped-registries': cleanScopeRegistries }
76
+ : undefined),
77
+ ...(hasItems(cleanJsrRegistries) ?
78
+ { 'jsr-registries': cleanJsrRegistries }
79
+ : undefined),
80
+ ...(options.registry !== undefined ?
81
+ { registry: options.registry }
82
+ : undefined),
83
+ ...((options['default-registry-alias'] !== undefined &&
84
+ options['default-registry-alias'] !== defaultRegistryName) ?
85
+ { 'default-registry-alias': options['default-registry-alias'] }
86
+ : undefined),
87
+ ...(hasItems(cleanRegistries) ?
88
+ { registries: cleanRegistries }
89
+ : undefined),
90
+ ...(hasItems(cleanGitHosts) ?
91
+ { 'git-hosts': cleanGitHosts }
92
+ : undefined),
93
+ ...(hasItems(cleanGitHostArchives) ?
94
+ { 'git-host-archives': cleanGitHostArchives }
95
+ : undefined),
96
+ };
97
+ };
98
+ export const loadObject = (options, lockfileData) => {
99
+ const version = lockfileData.lockfileVersion;
100
+ // Lockfile version is required, likely a corrupted lockfile if missing
101
+ if (version == null) {
102
+ throw error('Missing lockfile version', {
103
+ code: 'ELOCKFILEVERSION',
104
+ found: version,
105
+ wanted: LOCKFILE_VERSION,
106
+ });
107
+ }
108
+ // Lockfile version must match current version
109
+ if (version !== LOCKFILE_VERSION) {
110
+ throw error(`Unsupported lockfile version.
111
+
112
+ Run: \`vlt update\` to start a new, supported lockfile.`, {
113
+ code: 'ELOCKFILEVERSION',
114
+ found: version,
115
+ wanted: LOCKFILE_VERSION,
116
+ });
117
+ }
118
+ const { mainManifest, scurry } = options;
119
+ const packageJson = options.packageJson ?? new PackageJson();
120
+ const monorepo = options.monorepo ??
121
+ Monorepo.maybeLoad(options.projectRoot, { packageJson, scurry });
122
+ const { catalog = {}, catalogs = {}, 'scoped-registries': scopedRegistriesOption, registry, registries, 'default-registry-alias': defaultRegistryAlias, 'git-hosts': gitHosts, 'git-host-archives': gitHostArchives,
123
+ /* c8 ignore next */
124
+ } = lockfileData.options ?? {};
125
+ // backwards-compat: legacy lockfiles wrote this field as `scope-registries`
126
+ const scopeRegistries = scopedRegistriesOption ??
127
+ lockfileData.options['scope-registries'];
128
+ // Detect whether the current config options differ from those
129
+ // stored in the lockfile. When they do the ideal builder must
130
+ // reset edges and rebuild the graph.
131
+ const currentOptions = buildCurrentOptions(options);
132
+ /* c8 ignore next */
133
+ const lockfileOptions = lockfileData.options ?? {};
134
+ const optionsChanged = JSON.stringify(currentOptions) !== JSON.stringify(lockfileOptions);
135
+ // Optimize options merging - only create new objects when needed
136
+ const mergedOptions = {
137
+ ...options,
138
+ catalog,
139
+ catalogs,
140
+ 'scoped-registries': scopeRegistries ?
141
+ { ...options['scoped-registries'], ...scopeRegistries }
142
+ : options['scoped-registries'],
143
+ registry: registry ?? options.registry,
144
+ 'default-registry-alias': defaultRegistryAlias ?? options['default-registry-alias'],
145
+ registries: registries ?
146
+ { ...options.registries, ...registries }
147
+ : options.registries,
148
+ 'git-hosts': gitHosts ?
149
+ { ...options['git-hosts'], ...gitHosts }
150
+ : options['git-hosts'],
151
+ 'git-host-archives': gitHostArchives ?
152
+ { ...options['git-host-archives'], ...gitHostArchives }
153
+ : options['git-host-archives'],
154
+ };
155
+ const graph = new Graph({
156
+ ...mergedOptions,
157
+ mainManifest,
158
+ monorepo,
159
+ });
160
+ graph.optionsChanged = optionsChanged;
161
+ loadNodes(graph, lockfileData.nodes, mergedOptions, options.actual, options.throwOnMissingManifest);
162
+ loadEdges(graph, lockfileData.edges, mergedOptions);
163
+ // hydrate missing node-level registry data
164
+ for (const node of graph.nodes.values()) {
165
+ const [firstEdge] = node.edgesIn;
166
+ if (firstEdge?.spec.registry) {
167
+ node.registry = firstEdge.spec.registry;
168
+ }
169
+ }
170
+ return graph;
171
+ };
@@ -24,8 +24,7 @@ export type SaveOptions = SpecOptions & {
24
24
  */
25
25
  throwOnMissingManifest?: boolean;
26
26
  };
27
- export declare const lockfileData: ({ graph, catalog, catalogs, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, modifiers, registry, registries, saveManifests, saveBuildData, "scope-registries": scopeRegistries, "jsr-registries": jsrRegistries, throwOnMissingManifest, }: SaveOptions) => LockfileData;
27
+ export declare const lockfileData: ({ graph, catalog, catalogs, "git-hosts": gitHosts, "git-host-archives": gitHostArchives, modifiers, registry, registries, "default-registry-alias": defaultRegistryAlias, saveManifests, saveBuildData, "scoped-registries": scopeRegistries, "jsr-registries": jsrRegistries, throwOnMissingManifest, }: SaveOptions) => LockfileData;
28
28
  export declare const saveData: (data: LockfileData, fileName: string, saveManifests?: boolean) => void;
29
29
  export declare const save: (options: Omit<SaveOptions, "saveManifests">) => void;
30
30
  export declare const saveHidden: (options: Omit<SaveOptions, "saveManifests" | "saveBuildData">) => void;
31
- //# sourceMappingURL=save.d.ts.map