@vltpkg/graph 1.0.0-rc.14 → 1.0.0-rc.15

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 (58) hide show
  1. package/dist/actual/load.d.ts.map +1 -1
  2. package/dist/actual/load.js +3 -2
  3. package/dist/actual/load.js.map +1 -1
  4. package/dist/fixup-added-names.d.ts +4 -1
  5. package/dist/fixup-added-names.d.ts.map +1 -1
  6. package/dist/fixup-added-names.js +16 -0
  7. package/dist/fixup-added-names.js.map +1 -1
  8. package/dist/graph.d.ts +7 -0
  9. package/dist/graph.d.ts.map +1 -1
  10. package/dist/graph.js +7 -0
  11. package/dist/graph.js.map +1 -1
  12. package/dist/ideal/append-nodes.d.ts +14 -2
  13. package/dist/ideal/append-nodes.d.ts.map +1 -1
  14. package/dist/ideal/append-nodes.js +179 -63
  15. package/dist/ideal/append-nodes.js.map +1 -1
  16. package/dist/ideal/build.d.ts.map +1 -1
  17. package/dist/ideal/build.js +11 -1
  18. package/dist/ideal/build.js.map +1 -1
  19. package/dist/ideal/peers.d.ts +70 -7
  20. package/dist/ideal/peers.d.ts.map +1 -1
  21. package/dist/ideal/peers.js +350 -170
  22. package/dist/ideal/peers.js.map +1 -1
  23. package/dist/ideal/refresh-ideal-graph.d.ts +0 -4
  24. package/dist/ideal/refresh-ideal-graph.d.ts.map +1 -1
  25. package/dist/ideal/refresh-ideal-graph.js +2 -24
  26. package/dist/ideal/refresh-ideal-graph.js.map +1 -1
  27. package/dist/ideal/sorting.d.ts +46 -0
  28. package/dist/ideal/sorting.d.ts.map +1 -0
  29. package/dist/ideal/sorting.js +71 -0
  30. package/dist/ideal/sorting.js.map +1 -0
  31. package/dist/ideal/types.d.ts +1 -5
  32. package/dist/ideal/types.d.ts.map +1 -1
  33. package/dist/ideal/types.js.map +1 -1
  34. package/dist/install.d.ts.map +1 -1
  35. package/dist/install.js +12 -0
  36. package/dist/install.js.map +1 -1
  37. package/dist/lockfile/load.d.ts.map +1 -1
  38. package/dist/lockfile/load.js +21 -0
  39. package/dist/lockfile/load.js.map +1 -1
  40. package/dist/lockfile/save.d.ts.map +1 -1
  41. package/dist/lockfile/save.js +2 -2
  42. package/dist/lockfile/save.js.map +1 -1
  43. package/dist/lockfile/types.d.ts +6 -0
  44. package/dist/lockfile/types.d.ts.map +1 -1
  45. package/dist/lockfile/types.js +6 -0
  46. package/dist/lockfile/types.js.map +1 -1
  47. package/dist/reify/index.d.ts +1 -0
  48. package/dist/reify/index.d.ts.map +1 -1
  49. package/dist/reify/index.js +2 -1
  50. package/dist/reify/index.js.map +1 -1
  51. package/dist/update.d.ts.map +1 -1
  52. package/dist/update.js +1 -0
  53. package/dist/update.js.map +1 -1
  54. package/package.json +22 -22
  55. package/dist/ideal/get-ordered-dependencies.d.ts +0 -10
  56. package/dist/ideal/get-ordered-dependencies.d.ts.map +0 -1
  57. package/dist/ideal/get-ordered-dependencies.js +0 -42
  58. package/dist/ideal/get-ordered-dependencies.js.map +0 -1
@@ -13,17 +13,28 @@ import type { Node } from '../node.ts';
13
13
  */
14
14
  type PeerEdgeCompatResult = {
15
15
  compatible: boolean;
16
- /** When incompatible, entry to add to forked context */
17
- forkEntry?: {
18
- spec: Spec;
16
+ /** When incompatible, entry to add to forked context (target always present) */
17
+ forkEntry?: PeerContextEntryInput & {
19
18
  target: Node;
20
- type: DependencySaveType;
21
19
  };
22
20
  };
23
21
  /**
24
22
  * Check if an existing node's peer edges would still resolve to the same
25
23
  * targets from a new parent's context. Returns incompatible info if any
26
24
  * peer would resolve differently, meaning the node should NOT be reused.
25
+ *
26
+ * This is crucial for avoiding incorrect node reuse that would break peer
27
+ * dependency contracts. Three sources of conflict are checked:
28
+ *
29
+ * 1. **Peer context entries**: The global peer context may have resolved a
30
+ * different version of a peer dependency than what the existing node expects.
31
+ *
32
+ * 2. **Already-placed siblings**: The parent node may already have an edge to
33
+ * a different version of the peer dependency.
34
+ *
35
+ * 3. **Not-yet-placed siblings**: The parent's manifest declares a dependency
36
+ * on the same package, and there's a graph node that would satisfy it but
37
+ * differs from what the existing node expects.
27
38
  */
28
39
  export declare const checkPeerEdgesCompatible: (existingNode: Node, fromNode: Node, peerContext: PeerContext, graph: Graph) => PeerEdgeCompatResult;
29
40
  /**
@@ -34,7 +45,16 @@ export declare const retrievePeerContextHash: (peerContext: PeerContext | undefi
34
45
  * Checks if a given spec is compatible with the specs already
35
46
  * assigned to a peer context entry.
36
47
  *
37
- * Returns true if compatible, false otherwise.
48
+ * Returns true if INCOMPATIBLE, false if compatible.
49
+ *
50
+ * Compatibility rules:
51
+ * - **Registry specs**: Uses semver range intersection. `^18.0.0` and `^18.2.0`
52
+ * intersect (compatible), but `^18.0.0` and `^19.0.0` don't (incompatible).
53
+ * - **Non-registry specs** (git, file, etc.): Requires exact bareSpec match.
54
+ * `github:foo/bar#v1` only matches itself.
55
+ *
56
+ * This is used to determine when peer context forking is needed - if specs
57
+ * are incompatible, a new peer context must be created.
38
58
  */
39
59
  export declare const incompatibleSpecs: (spec: Spec, entry: PeerContextEntry) => boolean;
40
60
  /**
@@ -68,21 +88,47 @@ export declare const startPeerPlacement: (peerContext: PeerContext, manifest: Ma
68
88
  * Ends the peer dependency placement process, returning the functions that
69
89
  * are going to be used to update the peer context set, forking when needed
70
90
  * and resolving peer dependencies if possible.
91
+ *
92
+ * Returns two deferred functions:
93
+ * - `putEntries()`: Adds entries to peer context; returns fork entries if conflict
94
+ * - `resolvePeerDeps()`: Resolves peer deps from context/siblings or adds to nextDeps
95
+ *
96
+ * These are deferred (not executed immediately) so that all siblings at a level
97
+ * can be processed before peer context updates, enabling context reuse optimization.
71
98
  */
72
99
  export declare const endPeerPlacement: (peerContext: PeerContext, nextDeps: Dependency[], nextPeerDeps: Map<string, Dependency> & {
73
100
  id?: number;
74
101
  }, graph: Graph, spec: Spec, fromNode: Node, node: Node, type: DependencySaveType, queuedEntries: PeerContextEntryInput[]) => {
75
102
  /**
76
103
  * Add the new entries to the current peer context set.
104
+ *
105
+ * Two sets of entries are checked:
106
+ * - `prevEntries`: Parent's queued entries + self-reference
107
+ * - `nextEntries`: This node's deps + peer deps (with node as dependent)
108
+ *
109
+ * If either conflicts with the current context, returns ALL entries to be
110
+ * added to a forked context (prevEntries last for priority).
111
+ *
112
+ * Returns `undefined` if no fork needed (entries added directly to context).
77
113
  */
78
- putEntries: () => {
114
+ putEntries: () => (PeerContextEntryInput | {
79
115
  dependent: Node;
80
116
  spec: import("@vltpkg/spec/browser").Spec;
81
117
  type: DependencySaveType;
82
- }[] | undefined;
118
+ } | {
119
+ spec: Spec;
120
+ target: Node;
121
+ type: DependencySaveType;
122
+ })[] | undefined;
83
123
  /**
84
124
  * Try to resolve peer dependencies using already seen target
85
125
  * values from the current peer context set.
126
+ *
127
+ * Resolution priority (highest to lowest):
128
+ * 1. Sibling deps from parent (workspace direct deps take priority)
129
+ * 2. Peer-edge closure of sibling targets (handles peer cycles)
130
+ * 3. Global peer context set entries
131
+ * 4. Add to nextDeps for normal resolution (or create dangling edge for optional)
86
132
  */
87
133
  resolvePeerDeps: () => void;
88
134
  };
@@ -92,6 +138,23 @@ export declare const endPeerPlacement: (peerContext: PeerContext, nextDeps: Depe
92
138
  * dependencies and track peer dependencies in their appropriate peer context
93
139
  * sets, forking as needed and resolving peer dependencies using suitable
94
140
  * nodes already present in the graph if possible.
141
+ *
142
+ * This is the core peer context management algorithm, executed after each
143
+ * BFS level. It runs in three phases:
144
+ *
145
+ * **Phase 1: Collect fork requirements**
146
+ * Call `putEntries()` on each child dep to add entries to peer context.
147
+ * Collect which children need forked contexts (due to conflicts).
148
+ *
149
+ * **Phase 2: Fork or reuse contexts**
150
+ * For children needing forks, try to reuse a sibling's forked context if
151
+ * compatible. This optimization reduces the number of peer contexts created.
152
+ *
153
+ * **Phase 3: Resolve peer deps**
154
+ * With contexts finalized, call `resolvePeerDeps()` to create edges for
155
+ * peers that can be satisfied from context/siblings, or add them to nextDeps.
156
+ *
157
+ * All operations are sorted by `node.id` for deterministic, reproducible builds.
95
158
  */
96
159
  export declare const postPlacementPeerCheck: (graph: Graph, sortedLevelResults: ProcessPlacementResult[]) => void;
97
160
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"peers.d.ts","sourceRoot":"","sources":["../../src/ideal/peers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGnC,OAAO,KAAK,EAEV,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC;;;;GAIG;AACH,KAAK,oBAAoB,GAAG;IAC1B,UAAU,EAAE,OAAO,CAAA;IACnB,wDAAwD;IACxD,SAAS,CAAC,EAAE;QACV,IAAI,EAAE,IAAI,CAAA;QACV,MAAM,EAAE,IAAI,CAAA;QACZ,IAAI,EAAE,kBAAkB,CAAA;KACzB,CAAA;CACF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,iBACrB,IAAI,YACR,IAAI,eACD,WAAW,SACjB,KAAK,KACX,oBAuIF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,gBACrB,WAAW,GAAG,SAAS,KACnC,MAAM,GAAG,SAKX,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,SACtB,IAAI,SACH,gBAAgB,KACtB,OAmBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B,YAC9B,q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