@vltpkg/graph 1.0.0-rc.1 → 1.0.0-rc.11

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 (329) hide show
  1. package/dist/actual/load.d.ts.map +1 -0
  2. package/dist/{esm/actual → actual}/load.js +35 -14
  3. package/dist/actual/load.js.map +1 -0
  4. package/dist/{esm/browser.d.ts → browser.d.ts} +1 -1
  5. package/dist/browser.d.ts.map +1 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/build.d.ts.map +1 -0
  8. package/dist/build.js.map +1 -0
  9. package/dist/dependencies.d.ts.map +1 -0
  10. package/dist/dependencies.js.map +1 -0
  11. package/dist/{esm/diff.d.ts → diff.d.ts} +2 -0
  12. package/dist/diff.d.ts.map +1 -0
  13. package/dist/diff.js.map +1 -0
  14. package/dist/{esm/edge.d.ts → edge.d.ts} +1 -0
  15. package/dist/edge.d.ts.map +1 -0
  16. package/dist/{esm/edge.js → edge.js} +4 -0
  17. package/dist/edge.js.map +1 -0
  18. package/dist/fixup-added-names.d.ts +16 -0
  19. package/dist/fixup-added-names.d.ts.map +1 -0
  20. package/dist/fixup-added-names.js +31 -0
  21. package/dist/fixup-added-names.js.map +1 -0
  22. package/dist/{esm/graph.d.ts → graph.d.ts} +18 -4
  23. package/dist/graph.d.ts.map +1 -0
  24. package/dist/{esm/graph.js → graph.js} +63 -40
  25. package/dist/graph.js.map +1 -0
  26. package/dist/{esm/ideal → ideal}/append-nodes.d.ts +2 -1
  27. package/dist/ideal/append-nodes.d.ts.map +1 -0
  28. package/dist/ideal/append-nodes.js +395 -0
  29. package/dist/ideal/append-nodes.js.map +1 -0
  30. package/dist/{esm/ideal → ideal}/build-ideal-from-starting-graph.d.ts +4 -4
  31. package/dist/ideal/build-ideal-from-starting-graph.d.ts.map +1 -0
  32. package/dist/ideal/build-ideal-from-starting-graph.js +70 -0
  33. package/dist/ideal/build-ideal-from-starting-graph.js.map +1 -0
  34. package/dist/ideal/build.d.ts.map +1 -0
  35. package/dist/{esm/ideal → ideal}/build.js +29 -2
  36. package/dist/ideal/build.js.map +1 -0
  37. package/dist/{esm/ideal → ideal}/get-importer-specs.d.ts +9 -2
  38. package/dist/ideal/get-importer-specs.d.ts.map +1 -0
  39. package/dist/{esm/ideal → ideal}/get-importer-specs.js +80 -5
  40. package/dist/ideal/get-importer-specs.js.map +1 -0
  41. package/dist/ideal/get-ordered-dependencies.d.ts +10 -0
  42. package/dist/ideal/get-ordered-dependencies.d.ts.map +1 -0
  43. package/dist/ideal/get-ordered-dependencies.js +42 -0
  44. package/dist/ideal/get-ordered-dependencies.js.map +1 -0
  45. package/dist/ideal/peers.d.ts +76 -0
  46. package/dist/ideal/peers.d.ts.map +1 -0
  47. package/dist/ideal/peers.js +340 -0
  48. package/dist/ideal/peers.js.map +1 -0
  49. package/dist/ideal/refresh-ideal-graph.d.ts +48 -0
  50. package/dist/ideal/refresh-ideal-graph.d.ts.map +1 -0
  51. package/dist/ideal/refresh-ideal-graph.js +79 -0
  52. package/dist/ideal/refresh-ideal-graph.js.map +1 -0
  53. package/dist/ideal/remove-satisfied-specs.d.ts.map +1 -0
  54. package/dist/ideal/remove-satisfied-specs.js.map +1 -0
  55. package/dist/ideal/types.d.ts +112 -0
  56. package/dist/ideal/types.d.ts.map +1 -0
  57. package/dist/ideal/types.js.map +1 -0
  58. package/dist/{esm/index.d.ts → index.d.ts} +2 -1
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/{esm/index.js → index.js} +1 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/{esm/install.d.ts → install.d.ts} +3 -2
  63. package/dist/install.d.ts.map +1 -0
  64. package/dist/{esm/install.js → install.js} +30 -6
  65. package/dist/install.js.map +1 -0
  66. package/dist/lockfile/load-edges.d.ts.map +1 -0
  67. package/dist/{esm/lockfile → lockfile}/load-edges.js +4 -3
  68. package/dist/lockfile/load-edges.js.map +1 -0
  69. package/dist/{esm/lockfile → lockfile}/load-nodes.d.ts +1 -1
  70. package/dist/lockfile/load-nodes.d.ts.map +1 -0
  71. package/dist/{esm/lockfile → lockfile}/load-nodes.js +16 -4
  72. package/dist/lockfile/load-nodes.js.map +1 -0
  73. package/dist/{esm/lockfile → lockfile}/load.d.ts +2 -2
  74. package/dist/lockfile/load.d.ts.map +1 -0
  75. package/dist/{esm/lockfile → lockfile}/load.js +6 -29
  76. package/dist/lockfile/load.js.map +1 -0
  77. package/dist/{esm/lockfile → lockfile}/save.d.ts +5 -1
  78. package/dist/lockfile/save.d.ts.map +1 -0
  79. package/dist/{esm/lockfile → lockfile}/save.js +23 -9
  80. package/dist/lockfile/save.js.map +1 -0
  81. package/dist/lockfile/types.d.ts.map +1 -0
  82. package/dist/lockfile/types.js.map +1 -0
  83. package/dist/modifiers.d.ts.map +1 -0
  84. package/dist/modifiers.js.map +1 -0
  85. package/dist/{esm/node.d.ts → node.d.ts} +14 -0
  86. package/dist/node.d.ts.map +1 -0
  87. package/dist/{esm/node.js → node.js} +21 -0
  88. package/dist/node.js.map +1 -0
  89. package/dist/non-empty-list.d.ts.map +1 -0
  90. package/dist/non-empty-list.js.map +1 -0
  91. package/dist/reify/add-edge.d.ts.map +1 -0
  92. package/dist/reify/add-edge.js.map +1 -0
  93. package/dist/{esm/reify → reify}/add-edges.d.ts +1 -1
  94. package/dist/reify/add-edges.d.ts.map +1 -0
  95. package/dist/{esm/reify → reify}/add-edges.js +2 -1
  96. package/dist/reify/add-edges.js.map +1 -0
  97. package/dist/reify/add-nodes.d.ts.map +1 -0
  98. package/dist/reify/add-nodes.js.map +1 -0
  99. package/dist/reify/bin-chmod.d.ts.map +1 -0
  100. package/dist/reify/bin-chmod.js.map +1 -0
  101. package/dist/reify/build.d.ts.map +1 -0
  102. package/dist/{esm/reify → reify}/build.js +1 -1
  103. package/dist/reify/build.js.map +1 -0
  104. package/dist/reify/calculate-save-value.d.ts.map +1 -0
  105. package/dist/reify/calculate-save-value.js.map +1 -0
  106. package/dist/reify/check-needed-build.d.ts.map +1 -0
  107. package/dist/reify/check-needed-build.js.map +1 -0
  108. package/dist/reify/delete-edge.d.ts.map +1 -0
  109. package/dist/reify/delete-edge.js.map +1 -0
  110. package/dist/reify/delete-edges.d.ts.map +1 -0
  111. package/dist/reify/delete-edges.js.map +1 -0
  112. package/dist/reify/delete-nodes.d.ts.map +1 -0
  113. package/dist/reify/delete-nodes.js.map +1 -0
  114. package/dist/reify/extract-node.d.ts.map +1 -0
  115. package/dist/{esm/reify → reify}/extract-node.js +10 -2
  116. package/dist/reify/extract-node.js.map +1 -0
  117. package/dist/reify/index.d.ts.map +1 -0
  118. package/dist/{esm/reify → reify}/index.js +1 -1
  119. package/dist/reify/index.js.map +1 -0
  120. package/dist/reify/internal-hoist.d.ts.map +1 -0
  121. package/dist/reify/internal-hoist.js.map +1 -0
  122. package/dist/reify/optional-fail.d.ts.map +1 -0
  123. package/dist/reify/optional-fail.js.map +1 -0
  124. package/dist/reify/rollback.d.ts.map +1 -0
  125. package/dist/reify/rollback.js.map +1 -0
  126. package/dist/{esm/reify → reify}/update-importers-package-json.d.ts +1 -1
  127. package/dist/reify/update-importers-package-json.d.ts.map +1 -0
  128. package/dist/{esm/reify → reify}/update-importers-package-json.js +19 -16
  129. package/dist/reify/update-importers-package-json.js.map +1 -0
  130. package/dist/remove-optional-subgraph.d.ts.map +1 -0
  131. package/dist/remove-optional-subgraph.js.map +1 -0
  132. package/dist/resolve-save-type.d.ts.map +1 -0
  133. package/dist/resolve-save-type.js.map +1 -0
  134. package/dist/stringify-node.d.ts.map +1 -0
  135. package/dist/{esm/stringify-node.js → stringify-node.js} +10 -1
  136. package/dist/stringify-node.js.map +1 -0
  137. package/dist/transfer-data/load.d.ts.map +1 -0
  138. package/dist/transfer-data/load.js.map +1 -0
  139. package/dist/uninstall.d.ts.map +1 -0
  140. package/dist/{esm/uninstall.js → uninstall.js} +10 -0
  141. package/dist/uninstall.js.map +1 -0
  142. package/dist/update.d.ts.map +1 -0
  143. package/dist/{esm/update.js → update.js} +10 -0
  144. package/dist/update.js.map +1 -0
  145. package/dist/virtual-root.d.ts.map +1 -0
  146. package/dist/virtual-root.js.map +1 -0
  147. package/dist/visualization/human-readable-output.d.ts.map +1 -0
  148. package/dist/{esm/visualization → visualization}/human-readable-output.js +7 -2
  149. package/dist/visualization/human-readable-output.js.map +1 -0
  150. package/dist/{esm/visualization → visualization}/json-output.d.ts +2 -1
  151. package/dist/visualization/json-output.d.ts.map +1 -0
  152. package/dist/{esm/visualization → visualization}/json-output.js +2 -2
  153. package/dist/visualization/json-output.js.map +1 -0
  154. package/dist/visualization/mermaid-output.d.ts.map +1 -0
  155. package/dist/{esm/visualization → visualization}/mermaid-output.js +57 -16
  156. package/dist/visualization/mermaid-output.js.map +1 -0
  157. package/dist/visualization/object-like-output.d.ts.map +1 -0
  158. package/dist/visualization/object-like-output.js.map +1 -0
  159. package/package.json +34 -50
  160. package/dist/esm/actual/load.d.ts.map +0 -1
  161. package/dist/esm/actual/load.js.map +0 -1
  162. package/dist/esm/browser.d.ts.map +0 -1
  163. package/dist/esm/browser.js.map +0 -1
  164. package/dist/esm/build.d.ts.map +0 -1
  165. package/dist/esm/build.js.map +0 -1
  166. package/dist/esm/dependencies.d.ts.map +0 -1
  167. package/dist/esm/dependencies.js.map +0 -1
  168. package/dist/esm/diff.d.ts.map +0 -1
  169. package/dist/esm/diff.js.map +0 -1
  170. package/dist/esm/edge.d.ts.map +0 -1
  171. package/dist/esm/edge.js.map +0 -1
  172. package/dist/esm/graph.d.ts.map +0 -1
  173. package/dist/esm/graph.js.map +0 -1
  174. package/dist/esm/ideal/add-nodes.d.ts +0 -34
  175. package/dist/esm/ideal/add-nodes.d.ts.map +0 -1
  176. package/dist/esm/ideal/add-nodes.js +0 -39
  177. package/dist/esm/ideal/add-nodes.js.map +0 -1
  178. package/dist/esm/ideal/append-nodes.d.ts.map +0 -1
  179. package/dist/esm/ideal/append-nodes.js +0 -288
  180. package/dist/esm/ideal/append-nodes.js.map +0 -1
  181. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +0 -1
  182. package/dist/esm/ideal/build-ideal-from-starting-graph.js +0 -55
  183. package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +0 -1
  184. package/dist/esm/ideal/build.d.ts.map +0 -1
  185. package/dist/esm/ideal/build.js.map +0 -1
  186. package/dist/esm/ideal/get-importer-specs.d.ts.map +0 -1
  187. package/dist/esm/ideal/get-importer-specs.js.map +0 -1
  188. package/dist/esm/ideal/remove-nodes.d.ts +0 -7
  189. package/dist/esm/ideal/remove-nodes.d.ts.map +0 -1
  190. package/dist/esm/ideal/remove-nodes.js +0 -19
  191. package/dist/esm/ideal/remove-nodes.js.map +0 -1
  192. package/dist/esm/ideal/remove-satisfied-specs.d.ts.map +0 -1
  193. package/dist/esm/ideal/remove-satisfied-specs.js.map +0 -1
  194. package/dist/esm/ideal/types.d.ts +0 -35
  195. package/dist/esm/ideal/types.d.ts.map +0 -1
  196. package/dist/esm/ideal/types.js.map +0 -1
  197. package/dist/esm/index.d.ts.map +0 -1
  198. package/dist/esm/index.js.map +0 -1
  199. package/dist/esm/install.d.ts.map +0 -1
  200. package/dist/esm/install.js.map +0 -1
  201. package/dist/esm/lockfile/load-edges.d.ts.map +0 -1
  202. package/dist/esm/lockfile/load-edges.js.map +0 -1
  203. package/dist/esm/lockfile/load-nodes.d.ts.map +0 -1
  204. package/dist/esm/lockfile/load-nodes.js.map +0 -1
  205. package/dist/esm/lockfile/load.d.ts.map +0 -1
  206. package/dist/esm/lockfile/load.js.map +0 -1
  207. package/dist/esm/lockfile/save.d.ts.map +0 -1
  208. package/dist/esm/lockfile/save.js.map +0 -1
  209. package/dist/esm/lockfile/types.d.ts.map +0 -1
  210. package/dist/esm/lockfile/types.js.map +0 -1
  211. package/dist/esm/modifiers.d.ts.map +0 -1
  212. package/dist/esm/modifiers.js.map +0 -1
  213. package/dist/esm/node.d.ts.map +0 -1
  214. package/dist/esm/node.js.map +0 -1
  215. package/dist/esm/non-empty-list.d.ts.map +0 -1
  216. package/dist/esm/non-empty-list.js.map +0 -1
  217. package/dist/esm/package.json +0 -3
  218. package/dist/esm/reify/add-edge.d.ts.map +0 -1
  219. package/dist/esm/reify/add-edge.js.map +0 -1
  220. package/dist/esm/reify/add-edges.d.ts.map +0 -1
  221. package/dist/esm/reify/add-edges.js.map +0 -1
  222. package/dist/esm/reify/add-nodes.d.ts.map +0 -1
  223. package/dist/esm/reify/add-nodes.js.map +0 -1
  224. package/dist/esm/reify/bin-chmod.d.ts.map +0 -1
  225. package/dist/esm/reify/bin-chmod.js.map +0 -1
  226. package/dist/esm/reify/build.d.ts.map +0 -1
  227. package/dist/esm/reify/build.js.map +0 -1
  228. package/dist/esm/reify/calculate-save-value.d.ts.map +0 -1
  229. package/dist/esm/reify/calculate-save-value.js.map +0 -1
  230. package/dist/esm/reify/check-needed-build.d.ts.map +0 -1
  231. package/dist/esm/reify/check-needed-build.js.map +0 -1
  232. package/dist/esm/reify/delete-edge.d.ts.map +0 -1
  233. package/dist/esm/reify/delete-edge.js.map +0 -1
  234. package/dist/esm/reify/delete-edges.d.ts.map +0 -1
  235. package/dist/esm/reify/delete-edges.js.map +0 -1
  236. package/dist/esm/reify/delete-nodes.d.ts.map +0 -1
  237. package/dist/esm/reify/delete-nodes.js.map +0 -1
  238. package/dist/esm/reify/extract-node.d.ts.map +0 -1
  239. package/dist/esm/reify/extract-node.js.map +0 -1
  240. package/dist/esm/reify/index.d.ts.map +0 -1
  241. package/dist/esm/reify/index.js.map +0 -1
  242. package/dist/esm/reify/internal-hoist.d.ts.map +0 -1
  243. package/dist/esm/reify/internal-hoist.js.map +0 -1
  244. package/dist/esm/reify/optional-fail.d.ts.map +0 -1
  245. package/dist/esm/reify/optional-fail.js.map +0 -1
  246. package/dist/esm/reify/rollback.d.ts.map +0 -1
  247. package/dist/esm/reify/rollback.js.map +0 -1
  248. package/dist/esm/reify/update-importers-package-json.d.ts.map +0 -1
  249. package/dist/esm/reify/update-importers-package-json.js.map +0 -1
  250. package/dist/esm/remove-optional-subgraph.d.ts.map +0 -1
  251. package/dist/esm/remove-optional-subgraph.js.map +0 -1
  252. package/dist/esm/resolve-save-type.d.ts.map +0 -1
  253. package/dist/esm/resolve-save-type.js.map +0 -1
  254. package/dist/esm/stringify-node.d.ts.map +0 -1
  255. package/dist/esm/stringify-node.js.map +0 -1
  256. package/dist/esm/transfer-data/load.d.ts.map +0 -1
  257. package/dist/esm/transfer-data/load.js.map +0 -1
  258. package/dist/esm/uninstall.d.ts.map +0 -1
  259. package/dist/esm/uninstall.js.map +0 -1
  260. package/dist/esm/update.d.ts.map +0 -1
  261. package/dist/esm/update.js.map +0 -1
  262. package/dist/esm/virtual-root.d.ts.map +0 -1
  263. package/dist/esm/virtual-root.js.map +0 -1
  264. package/dist/esm/visualization/human-readable-output.d.ts.map +0 -1
  265. package/dist/esm/visualization/human-readable-output.js.map +0 -1
  266. package/dist/esm/visualization/json-output.d.ts.map +0 -1
  267. package/dist/esm/visualization/json-output.js.map +0 -1
  268. package/dist/esm/visualization/mermaid-output.d.ts.map +0 -1
  269. package/dist/esm/visualization/mermaid-output.js.map +0 -1
  270. package/dist/esm/visualization/object-like-output.d.ts.map +0 -1
  271. package/dist/esm/visualization/object-like-output.js.map +0 -1
  272. /package/dist/{esm/actual → actual}/load.d.ts +0 -0
  273. /package/dist/{esm/browser.js → browser.js} +0 -0
  274. /package/dist/{esm/build.d.ts → build.d.ts} +0 -0
  275. /package/dist/{esm/build.js → build.js} +0 -0
  276. /package/dist/{esm/dependencies.d.ts → dependencies.d.ts} +0 -0
  277. /package/dist/{esm/dependencies.js → dependencies.js} +0 -0
  278. /package/dist/{esm/diff.js → diff.js} +0 -0
  279. /package/dist/{esm/ideal → ideal}/build.d.ts +0 -0
  280. /package/dist/{esm/ideal → ideal}/remove-satisfied-specs.d.ts +0 -0
  281. /package/dist/{esm/ideal → ideal}/remove-satisfied-specs.js +0 -0
  282. /package/dist/{esm/ideal → ideal}/types.js +0 -0
  283. /package/dist/{esm/lockfile → lockfile}/load-edges.d.ts +0 -0
  284. /package/dist/{esm/lockfile → lockfile}/types.d.ts +0 -0
  285. /package/dist/{esm/lockfile → lockfile}/types.js +0 -0
  286. /package/dist/{esm/modifiers.d.ts → modifiers.d.ts} +0 -0
  287. /package/dist/{esm/modifiers.js → modifiers.js} +0 -0
  288. /package/dist/{esm/non-empty-list.d.ts → non-empty-list.d.ts} +0 -0
  289. /package/dist/{esm/non-empty-list.js → non-empty-list.js} +0 -0
  290. /package/dist/{esm/reify → reify}/add-edge.d.ts +0 -0
  291. /package/dist/{esm/reify → reify}/add-edge.js +0 -0
  292. /package/dist/{esm/reify → reify}/add-nodes.d.ts +0 -0
  293. /package/dist/{esm/reify → reify}/add-nodes.js +0 -0
  294. /package/dist/{esm/reify → reify}/bin-chmod.d.ts +0 -0
  295. /package/dist/{esm/reify → reify}/bin-chmod.js +0 -0
  296. /package/dist/{esm/reify → reify}/build.d.ts +0 -0
  297. /package/dist/{esm/reify → reify}/calculate-save-value.d.ts +0 -0
  298. /package/dist/{esm/reify → reify}/calculate-save-value.js +0 -0
  299. /package/dist/{esm/reify → reify}/check-needed-build.d.ts +0 -0
  300. /package/dist/{esm/reify → reify}/check-needed-build.js +0 -0
  301. /package/dist/{esm/reify → reify}/delete-edge.d.ts +0 -0
  302. /package/dist/{esm/reify → reify}/delete-edge.js +0 -0
  303. /package/dist/{esm/reify → reify}/delete-edges.d.ts +0 -0
  304. /package/dist/{esm/reify → reify}/delete-edges.js +0 -0
  305. /package/dist/{esm/reify → reify}/delete-nodes.d.ts +0 -0
  306. /package/dist/{esm/reify → reify}/delete-nodes.js +0 -0
  307. /package/dist/{esm/reify → reify}/extract-node.d.ts +0 -0
  308. /package/dist/{esm/reify → reify}/index.d.ts +0 -0
  309. /package/dist/{esm/reify → reify}/internal-hoist.d.ts +0 -0
  310. /package/dist/{esm/reify → reify}/internal-hoist.js +0 -0
  311. /package/dist/{esm/reify → reify}/optional-fail.d.ts +0 -0
  312. /package/dist/{esm/reify → reify}/optional-fail.js +0 -0
  313. /package/dist/{esm/reify → reify}/rollback.d.ts +0 -0
  314. /package/dist/{esm/reify → reify}/rollback.js +0 -0
  315. /package/dist/{esm/remove-optional-subgraph.d.ts → remove-optional-subgraph.d.ts} +0 -0
  316. /package/dist/{esm/remove-optional-subgraph.js → remove-optional-subgraph.js} +0 -0
  317. /package/dist/{esm/resolve-save-type.d.ts → resolve-save-type.d.ts} +0 -0
  318. /package/dist/{esm/resolve-save-type.js → resolve-save-type.js} +0 -0
  319. /package/dist/{esm/stringify-node.d.ts → stringify-node.d.ts} +0 -0
  320. /package/dist/{esm/transfer-data → transfer-data}/load.d.ts +0 -0
  321. /package/dist/{esm/transfer-data → transfer-data}/load.js +0 -0
  322. /package/dist/{esm/uninstall.d.ts → uninstall.d.ts} +0 -0
  323. /package/dist/{esm/update.d.ts → update.d.ts} +0 -0
  324. /package/dist/{esm/virtual-root.d.ts → virtual-root.d.ts} +0 -0
  325. /package/dist/{esm/virtual-root.js → virtual-root.js} +0 -0
  326. /package/dist/{esm/visualization → visualization}/human-readable-output.d.ts +0 -0
  327. /package/dist/{esm/visualization → visualization}/mermaid-output.d.ts +0 -0
  328. /package/dist/{esm/visualization → visualization}/object-like-output.d.ts +0 -0
  329. /package/dist/{esm/visualization → visualization}/object-like-output.js +0 -0
@@ -0,0 +1,340 @@
1
+ // helpers for managing peer dependency resolution
2
+ // during the ideal graph building process.
3
+ import { intersects } from '@vltpkg/semver';
4
+ import { satisfies } from '@vltpkg/satisfies';
5
+ import { getDependencies } from "../dependencies.js";
6
+ import { getOrderedDependencies } from "./get-ordered-dependencies.js";
7
+ /**
8
+ * Retrieve a unique hash value for a given peer context set.
9
+ */
10
+ export const retrievePeerContextHash = (peerContext) => {
11
+ // skips creating the initial peer context ref
12
+ if (!peerContext?.index)
13
+ return undefined;
14
+ return `ṗ:${peerContext.index}`;
15
+ };
16
+ /**
17
+ * Checks if a given spec is compatible with the specs already
18
+ * assigned to a peer context entry.
19
+ *
20
+ * Returns true if compatible, false otherwise.
21
+ */
22
+ export const incompatibleSpecs = (spec, entry) => {
23
+ if (entry.specs.size > 0) {
24
+ for (const s of entry.specs) {
25
+ if (
26
+ // only able to check range intersections for registry types
27
+ (spec.type === 'registry' &&
28
+ (!spec.range ||
29
+ !s.range ||
30
+ !intersects(spec.range, s.range))) ||
31
+ // also support types other than registry in case
32
+ // they use the very same bareSpec value
33
+ (spec.type !== 'registry' && spec.bareSpec !== s.bareSpec)) {
34
+ return true;
35
+ }
36
+ }
37
+ }
38
+ return false;
39
+ };
40
+ /**
41
+ * Sort peer context entry inputs for deterministic processing.
42
+ * Orders: non-peer dependencies first, then peer dependencies, alphabetically by name.
43
+ */
44
+ export const getOrderedPeerContextEntries = (entries) => [...entries].sort((a, b) => {
45
+ const aIsPeer = a.type === 'peer' || a.type === 'peerOptional' ? 1 : 0;
46
+ const bIsPeer = b.type === 'peer' || b.type === 'peerOptional' ? 1 : 0;
47
+ if (aIsPeer !== bIsPeer)
48
+ return aIsPeer - bIsPeer;
49
+ const aName = a.target?.name ?? a.spec.name;
50
+ const bName = b.target?.name ?? b.spec.name;
51
+ return aName.localeCompare(bName, 'en');
52
+ });
53
+ /*
54
+ * Checks if there are any conflicting versions for a given dependency
55
+ * to be added to a peer context set which will require forking.
56
+ *
57
+ * Returns true if forking is needed, false otherwise.
58
+ */
59
+ export const checkEntriesToPeerContext = (peerContext, entries) => {
60
+ // check on compatibility of new entries
61
+ for (const { spec, target } of entries) {
62
+ const name = target?.name ?? spec.final.name;
63
+ // skip any inactive entry
64
+ const entry = peerContext.get(name);
65
+ if (!entry?.active)
66
+ continue;
67
+ // validate if the provided spec is compatible with existing specs
68
+ if (incompatibleSpecs(spec, entry)) {
69
+ return true;
70
+ }
71
+ }
72
+ return false;
73
+ };
74
+ /**
75
+ * Add or update dependencies in a given peer context making sure to check
76
+ * for compatibility with existing dependencies already resolved by a given
77
+ * peer context set. Extra info such as a target or dependent nodes is
78
+ * optional.
79
+ *
80
+ * Returns true if forking is needed, false otherwise.
81
+ */
82
+ export const addEntriesToPeerContext = (peerContext, entries, fromNode, monorepo) => {
83
+ // pre check to see if any of the new entries to be added to the
84
+ // provided peer context set conflicts with existing ones
85
+ // if that's already the case we can skip processing them and
86
+ // will return that a fork is needed right away
87
+ if (checkEntriesToPeerContext(peerContext, entries))
88
+ return true;
89
+ // iterate on every entry to be added to the peer context set
90
+ for (const { dependent, spec, target, type } of entries) {
91
+ const name = target?.name ?? spec.final.name;
92
+ // if there's no existing entry, create one
93
+ let entry = peerContext.get(name);
94
+ if (!entry) {
95
+ entry = {
96
+ active: true,
97
+ specs: new Set([spec]),
98
+ target,
99
+ type,
100
+ contextDependents: new Set(),
101
+ };
102
+ peerContext.set(name, entry);
103
+ if (dependent)
104
+ entry.contextDependents.add(dependent);
105
+ continue;
106
+ }
107
+ // perform an extra check that confirms the new spec does not
108
+ // conflicts with existing specs in this entry, this handles the
109
+ // case of adding sibling deps that conflicts with one another
110
+ if (incompatibleSpecs(spec, entry))
111
+ return true;
112
+ if (target &&
113
+ [...entry.specs].every(s => satisfies(target.id, s, fromNode.location, fromNode.projectRoot, monorepo))) {
114
+ if (target.id !== entry.target?.id &&
115
+ target.version !== entry.target?.version) {
116
+ // we have a compatible entry that has a new, compatible target
117
+ // so we need to update all dependents to point to the new target
118
+ for (const dependents of entry.contextDependents) {
119
+ const edge = dependents.edgesOut.get(name);
120
+ if (edge?.to && edge.to !== target) {
121
+ edge.to.edgesIn.delete(edge);
122
+ edge.to = target;
123
+ target.edgesIn.add(edge);
124
+ }
125
+ }
126
+ entry.target = target;
127
+ }
128
+ // otherwise sets the value in case it was nullish
129
+ entry.target ??= target;
130
+ }
131
+ // update specs and dependents values
132
+ entry.specs.add(spec);
133
+ if (dependent)
134
+ entry.contextDependents.add(dependent);
135
+ }
136
+ return false;
137
+ };
138
+ /**
139
+ * Create and returns a forked copy of a given peer context set.
140
+ */
141
+ export const forkPeerContext = (graph, peerContext, entries) => {
142
+ // create a new peer context set
143
+ const nextPeerContext = new Map();
144
+ nextPeerContext.index = graph.nextPeerContextIndex();
145
+ // register it in the graph
146
+ graph.peerContexts[nextPeerContext.index] = nextPeerContext;
147
+ // copy existing entries marking them as inactive, it's also important
148
+ // to note that specs and contextDependents are new objects so that changes
149
+ // to those in the new context do not affect the previous one
150
+ for (const [name, entry] of peerContext.entries()) {
151
+ nextPeerContext.set(name, {
152
+ active: false,
153
+ specs: new Set(entry.specs),
154
+ target: undefined,
155
+ type: entry.type,
156
+ contextDependents: new Set(entry.contextDependents),
157
+ });
158
+ }
159
+ // add the new entries to this peer context set, marking them as active
160
+ // these are the entries that were incompatible with the previous context set
161
+ for (const entry of entries) {
162
+ const { dependent, spec, target, type } = entry;
163
+ const name = target?.name /* c8 ignore next */ ?? spec.final.name;
164
+ const newEntry = {
165
+ active: true,
166
+ specs: new Set([spec]),
167
+ target,
168
+ type,
169
+ contextDependents: dependent ? new Set([dependent]) : new Set(),
170
+ };
171
+ nextPeerContext.set(name, newEntry);
172
+ }
173
+ return nextPeerContext;
174
+ };
175
+ /**
176
+ * Starts the peer dependency placement process
177
+ * for a given node being processed and placed.
178
+ */
179
+ export const startPeerPlacement = (peerContext, manifest, fromNode, options) => {
180
+ // queue entries so that they can be added at the end of the placement
181
+ // process, use a map to ensure deduplication between read json dep
182
+ // values and the resolved edges in the graph
183
+ const queueMap = new Map();
184
+ let peerSetHash;
185
+ if (manifest.peerDependencies &&
186
+ Object.keys(manifest.peerDependencies).length > 0) {
187
+ // generates a peer context set hash for nodes that
188
+ // have peer dependencies to be resolved
189
+ peerSetHash = retrievePeerContextHash(peerContext);
190
+ // get any potential sibling dependency from the
191
+ // parent node that might have not been parsed yet
192
+ const siblingDeps = getDependencies(fromNode, {
193
+ ...options,
194
+ registry: fromNode.registry,
195
+ });
196
+ for (const [depName, dep] of siblingDeps) {
197
+ queueMap.set(depName, dep);
198
+ }
199
+ // collect the already parsed nodes and add those to the
200
+ // list of entries to be added to the peer context set
201
+ for (const edge of fromNode.edgesOut.values()) {
202
+ queueMap.set(edge.name, {
203
+ spec: edge.spec,
204
+ target: edge.to,
205
+ type: edge.type,
206
+ });
207
+ }
208
+ }
209
+ return {
210
+ peerSetHash,
211
+ // Sort queuedEntries for deterministic order
212
+ queuedEntries: getOrderedPeerContextEntries([
213
+ ...queueMap.values(),
214
+ ]),
215
+ };
216
+ };
217
+ /**
218
+ * Ends the peer dependency placement process, returning the functions that
219
+ * are going to be used to update the peer context set, forking when needed
220
+ * and resolving peer dependencies if possible.
221
+ */
222
+ export const endPeerPlacement = (peerContext, nextDeps, nextPeerDeps, graph, spec, fromNode, node, type, queuedEntries) => ({
223
+ /**
224
+ * Add the new entries to the current peer context set.
225
+ */
226
+ putEntries: () => {
227
+ // keep track of whether we need to fork the current peer context set
228
+ let needsToForkPeerContext = false;
229
+ // add queued entries from this node parents along
230
+ // with a self-ref to the current peer context set
231
+ const prevEntries = [
232
+ ...queuedEntries,
233
+ /* ref itself */ {
234
+ spec,
235
+ target: node,
236
+ type,
237
+ },
238
+ ];
239
+ addEntriesToPeerContext(peerContext, prevEntries, fromNode, graph.monorepo);
240
+ // add this node's direct dependencies next
241
+ const nextEntries = [
242
+ ...nextDeps.map(dep => ({ ...dep, dependent: node })),
243
+ ...[...nextPeerDeps.values()].map(dep => ({
244
+ ...dep,
245
+ dependent: node,
246
+ })),
247
+ ];
248
+ if (nextEntries.length > 0) {
249
+ needsToForkPeerContext = addEntriesToPeerContext(peerContext, nextEntries, node, graph.monorepo);
250
+ }
251
+ // returns all entries that need to be added to a forked
252
+ // context or undefined if the current context was updated directly
253
+ return needsToForkPeerContext ? nextEntries : undefined;
254
+ },
255
+ /**
256
+ * Try to resolve peer dependencies using already seen target
257
+ * values from the current peer context set.
258
+ */
259
+ resolvePeerDeps: () => {
260
+ // iterate on the set of peer dependencies of the current node
261
+ // and try to resolve them from the existing peer context set,
262
+ // when possible, add them as edges in the graph right away, if not,
263
+ // then we move them back to the `nextDeps` list for processing
264
+ // along with the rest of the regular dependencies
265
+ for (const nextDep of nextPeerDeps.values()) {
266
+ const { spec, type } = nextDep;
267
+ if (type === 'peer' || type === 'peerOptional') {
268
+ // try to retrieve an entry for that peer dep from
269
+ // the current peer context set
270
+ const entry = peerContext.get(spec.final.name);
271
+ if (!node.edgesOut.has(spec.final.name) &&
272
+ entry?.target &&
273
+ satisfies(entry.target.id, spec, fromNode.location, fromNode.projectRoot, graph.monorepo)) {
274
+ // entry satisfied, create edge in the graph
275
+ graph.addEdge(type, spec, node, entry.target);
276
+ entry.specs.add(spec.final);
277
+ }
278
+ else if (type === 'peerOptional') {
279
+ // skip unsatisfied peerOptional dependencies,
280
+ // just create a dangling edge
281
+ graph.addEdge(type, spec, node);
282
+ }
283
+ else {
284
+ // could not satisfy from peer context, add to next deps
285
+ nextDeps.push(nextDep);
286
+ }
287
+ }
288
+ }
289
+ },
290
+ });
291
+ /**
292
+ * Given an array of processed results for the current level dependencies
293
+ * being placed in the currently building ideal graph, traverse its direct
294
+ * dependencies and track peer dependencies in their appropriate peer context
295
+ * sets, forking as needed and resolving peer dependencies using suitable
296
+ * nodes already present in the graph if possible.
297
+ */
298
+ export const postPlacementPeerCheck = (graph, sortedLevelResults) => {
299
+ // Update peer contexts in a sorted manner after processing all nodes
300
+ // at a given level to ensure deterministic behavior when it comes to
301
+ // forking new peer contexts
302
+ for (const childDepsToProcess of sortedLevelResults) {
303
+ // Sort childDepsToProcess deterministically by node.id
304
+ const sortedChildDeps = [...childDepsToProcess].sort((a, b) => a.node.id.localeCompare(b.node.id, 'en'));
305
+ const needsForking = new Map();
306
+ // first iterate on all child deps, adding entries to the current
307
+ // context and collect the information on which ones need forking
308
+ for (const childDep of sortedChildDeps) {
309
+ const needsFork = childDep.updateContext.putEntries();
310
+ if (needsFork) {
311
+ needsForking.set(childDep, needsFork);
312
+ }
313
+ }
314
+ // Sort needsForking entries before iterating (Map iteration order = insertion order)
315
+ const sortedNeedsForkingEntries = [
316
+ ...needsForking.entries(),
317
+ ].sort(([a], [b]) => a.node.id.localeCompare(b.node.id, 'en'));
318
+ // then iterate again, forking contexts as needed but also try to
319
+ // reuse the context of the previous sibling if possible
320
+ let prevContext;
321
+ for (const [childDep, nextEntries] of sortedNeedsForkingEntries) {
322
+ if (prevContext &&
323
+ !checkEntriesToPeerContext(prevContext, nextEntries)) {
324
+ // the context of the previous sibling can be reused
325
+ addEntriesToPeerContext(prevContext, nextEntries, childDep.node, graph.monorepo);
326
+ childDep.peerContext = prevContext;
327
+ continue;
328
+ }
329
+ childDep.peerContext = forkPeerContext(graph, childDep.peerContext, nextEntries);
330
+ prevContext = childDep.peerContext;
331
+ }
332
+ // try to resolve peer dependencies now that
333
+ // the context is fully set up
334
+ for (const childDep of sortedChildDeps) {
335
+ childDep.updateContext.resolvePeerDeps();
336
+ childDep.deps = getOrderedDependencies(childDep.deps);
337
+ }
338
+ }
339
+ };
340
+ //# sourceMappingURL=peers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peers.js","sourceRoot":"","sources":["../../src/ideal/peers.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,2CAA2C;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAetE;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,WAAoC,EAChB,EAAE;IACtB,8CAA8C;IAC9C,IAAI,CAAC,WAAW,EAAE,KAAK;QAAE,OAAO,SAAS,CAAA;IAEzC,OAAO,KAAK,WAAW,CAAC,KAAK,EAAE,CAAA;AACjC,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,IAAU,EACV,KAAuB,EACd,EAAE;IACX,IAAI,KAA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AAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAA;QAE9D,iEAAiE;QACjE,wDAAwD;QACxD,IAAI,WAAW,CAAA;QACf,KAAK,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,yBAAyB,EAAE,CAAC;YAChE,IACE,WAAW;gBACX,CAAC,yBAAyB,CAAC,WAAW,EAAE,WAAW,CAAC,EACpD,CAAC;gBACD,oDAAoD;gBACpD,uBAAuB,CACrB,WAAW,EACX,WAAW,EACX,QAAQ,CAAC,IAAI,EACb,KAAK,CAAC,QAAQ,CACf,CAAA;gBACD,QAAQ,CAAC,WAAW,GAAG,WAAW,CAAA;gBAClC,SAAQ;YACV,CAAC;YACD,QAAQ,CAAC,WAAW,GAAG,eAAe,CACpC,KAAK,EACL,QAAQ,CAAC,WAAW,EACpB,WAAW,CACZ,CAAA;YACD,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAA;QACpC,CAAC;QACD,4CAA4C;QAC5C,8BAA8B;QAC9B,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,aAAa,CAAC,eAAe,EAAE,CAAA;YACxC,QAAQ,CAAC,IAAI,GAAG,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["// helpers for managing peer dependency resolution\n// during the ideal graph building process.\n\nimport { intersects } from '@vltpkg/semver'\nimport { satisfies } from '@vltpkg/satisfies'\nimport { getDependencies } from '../dependencies.ts'\nimport { getOrderedDependencies } from './get-ordered-dependencies.ts'\nimport type {\n ProcessPlacementResultEntry,\n PeerContext,\n PeerContextEntry,\n PeerContextEntryInput,\n ProcessPlacementResult,\n} from './types.ts'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type { DependencySaveType, Manifest } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\n\n/**\n * Retrieve a unique hash value for a given peer context set.\n */\nexport const retrievePeerContextHash = (\n peerContext: PeerContext | undefined,\n): string | undefined => {\n // skips creating the initial peer context ref\n if (!peerContext?.index) return undefined\n\n return `ṗ:${peerContext.index}`\n}\n\n/**\n * Checks if a given spec is compatible with the specs already\n * assigned to a peer context entry.\n *\n * Returns true if compatible, false otherwise.\n */\nexport const incompatibleSpecs = (\n spec: Spec,\n entry: PeerContextEntry,\n): boolean => {\n if (entry.specs.size > 0) {\n for (const s of entry.specs) {\n if (\n // only able to check range intersections for registry types\n (spec.type === 'registry' &&\n (!spec.range ||\n !s.range ||\n !intersects(spec.range, s.range))) ||\n // also support types other than registry in case\n // they use the very same bareSpec value\n (spec.type !== 'registry' && spec.bareSpec !== s.bareSpec)\n ) {\n return true\n }\n }\n }\n return false\n}\n\n/**\n * Sort peer context entry inputs for deterministic processing.\n * Orders: non-peer dependencies first, then peer dependencies, alphabetically by name.\n */\nexport const getOrderedPeerContextEntries = (\n entries: PeerContextEntryInput[],\n): PeerContextEntryInput[] =>\n [...entries].sort((a, b) => {\n const aIsPeer =\n a.type === 'peer' || a.type === 'peerOptional' ? 1 : 0\n const bIsPeer =\n b.type === 'peer' || b.type === 'peerOptional' ? 1 : 0\n if (aIsPeer !== bIsPeer) return aIsPeer - bIsPeer\n const aName = a.target?.name ?? a.spec.name\n const bName = b.target?.name ?? b.spec.name\n return aName.localeCompare(bName, 'en')\n })\n\n/*\n * Checks if there are any conflicting versions for a given dependency\n * to be added to a peer context set which will require forking.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const checkEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): boolean => {\n // check on compatibility of new entries\n for (const { spec, target } of entries) {\n const name = target?.name ?? spec.final.name\n\n // skip any inactive entry\n const entry = peerContext.get(name)\n if (!entry?.active) continue\n\n // validate if the provided spec is compatible with existing specs\n if (incompatibleSpecs(spec, entry)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Add or update dependencies in a given peer context making sure to check\n * for compatibility with existing dependencies already resolved by a given\n * peer context set. Extra info such as a target or dependent nodes is\n * optional.\n *\n * Returns true if forking is needed, false otherwise.\n */\nexport const addEntriesToPeerContext = (\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n fromNode: Node,\n monorepo?: Monorepo,\n): boolean => {\n // pre check to see if any of the new entries to be added to the\n // provided peer context set conflicts with existing ones\n // if that's already the case we can skip processing them and\n // will return that a fork is needed right away\n if (checkEntriesToPeerContext(peerContext, entries)) return true\n\n // iterate on every entry to be added to the peer context set\n for (const { dependent, spec, target, type } of entries) {\n const name = target?.name ?? spec.final.name\n\n // if there's no existing entry, create one\n let entry = peerContext.get(name)\n if (!entry) {\n entry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents: new Set(),\n }\n peerContext.set(name, entry)\n if (dependent) entry.contextDependents.add(dependent)\n continue\n }\n\n // perform an extra check that confirms the new spec does not\n // conflicts with existing specs in this entry, this handles the\n // case of adding sibling deps that conflicts with one another\n if (incompatibleSpecs(spec, entry)) return true\n\n if (\n target &&\n [...entry.specs].every(s =>\n satisfies(\n target.id,\n s,\n fromNode.location,\n fromNode.projectRoot,\n monorepo,\n ),\n )\n ) {\n if (\n target.id !== entry.target?.id &&\n target.version !== entry.target?.version\n ) {\n // we have a compatible entry that has a new, compatible target\n // so we need to update all dependents to point to the new target\n for (const dependents of entry.contextDependents) {\n const edge = dependents.edgesOut.get(name)\n if (edge?.to && edge.to !== target) {\n edge.to.edgesIn.delete(edge)\n edge.to = target\n target.edgesIn.add(edge)\n }\n }\n entry.target = target\n }\n\n // otherwise sets the value in case it was nullish\n entry.target ??= target\n }\n\n // update specs and dependents values\n entry.specs.add(spec)\n if (dependent) entry.contextDependents.add(dependent)\n }\n\n return false\n}\n\n/**\n * Create and returns a forked copy of a given peer context set.\n */\nexport const forkPeerContext = (\n graph: Graph,\n peerContext: PeerContext,\n entries: PeerContextEntryInput[],\n): PeerContext => {\n // create a new peer context set\n const nextPeerContext: PeerContext = new Map()\n nextPeerContext.index = graph.nextPeerContextIndex()\n // register it in the graph\n graph.peerContexts[nextPeerContext.index] = nextPeerContext\n\n // copy existing entries marking them as inactive, it's also important\n // to note that specs and contextDependents are new objects so that changes\n // to those in the new context do not affect the previous one\n for (const [name, entry] of peerContext.entries()) {\n nextPeerContext.set(name, {\n active: false,\n specs: new Set(entry.specs),\n target: undefined,\n type: entry.type,\n contextDependents: new Set(entry.contextDependents),\n })\n }\n\n // add the new entries to this peer context set, marking them as active\n // these are the entries that were incompatible with the previous context set\n for (const entry of entries) {\n const { dependent, spec, target, type } = entry\n const name = target?.name /* c8 ignore next */ ?? spec.final.name\n const newEntry = {\n active: true,\n specs: new Set([spec]),\n target,\n type,\n contextDependents:\n dependent ? new Set([dependent]) : new Set<Node>(),\n }\n nextPeerContext.set(name, newEntry)\n }\n\n return nextPeerContext\n}\n\n/**\n * Starts the peer dependency placement process\n * for a given node being processed and placed.\n */\nexport const startPeerPlacement = (\n peerContext: PeerContext,\n manifest: Manifest,\n fromNode: Node,\n options: SpecOptions,\n) => {\n // queue entries so that they can be added at the end of the placement\n // process, use a map to ensure deduplication between read json dep\n // values and the resolved edges in the graph\n const queueMap = new Map<string, PeerContextEntryInput>()\n let peerSetHash: string | undefined\n\n if (\n manifest.peerDependencies &&\n Object.keys(manifest.peerDependencies).length > 0\n ) {\n // generates a peer context set hash for nodes that\n // have peer dependencies to be resolved\n peerSetHash = retrievePeerContextHash(peerContext)\n\n // get any potential sibling dependency from the\n // parent node that might have not been parsed yet\n const siblingDeps = getDependencies(fromNode, {\n ...options,\n registry: fromNode.registry,\n })\n for (const [depName, dep] of siblingDeps) {\n queueMap.set(depName, dep)\n }\n\n // collect the already parsed nodes and add those to the\n // list of entries to be added to the peer context set\n for (const edge of fromNode.edgesOut.values()) {\n queueMap.set(edge.name, {\n spec: edge.spec,\n target: edge.to,\n type: edge.type,\n })\n }\n }\n\n return {\n peerSetHash,\n // Sort queuedEntries for deterministic order\n queuedEntries: getOrderedPeerContextEntries([\n ...queueMap.values(),\n ]),\n }\n}\n\n/**\n * Ends the peer dependency placement process, returning the functions that\n * are going to be used to update the peer context set, forking when needed\n * and resolving peer dependencies if possible.\n */\nexport const endPeerPlacement = (\n peerContext: PeerContext,\n nextDeps: Dependency[],\n nextPeerDeps: Map<string, Dependency> & { id?: number },\n graph: Graph,\n spec: Spec,\n fromNode: Node,\n node: Node,\n type: DependencySaveType,\n queuedEntries: PeerContextEntryInput[],\n) => ({\n /**\n * Add the new entries to the current peer context set.\n */\n putEntries: () => {\n // keep track of whether we need to fork the current peer context set\n let needsToForkPeerContext = false\n // add queued entries from this node parents along\n // with a self-ref to the current peer context set\n const prevEntries = [\n ...queuedEntries,\n /* ref itself */ {\n spec,\n target: node,\n type,\n },\n ]\n addEntriesToPeerContext(\n peerContext,\n prevEntries,\n fromNode,\n graph.monorepo,\n )\n\n // add this node's direct dependencies next\n const nextEntries = [\n ...nextDeps.map(dep => ({ ...dep, dependent: node })),\n ...[...nextPeerDeps.values()].map(dep => ({\n ...dep,\n dependent: node,\n })),\n ]\n if (nextEntries.length > 0) {\n needsToForkPeerContext = addEntriesToPeerContext(\n peerContext,\n nextEntries,\n node,\n graph.monorepo,\n )\n }\n\n // returns all entries that need to be added to a forked\n // context or undefined if the current context was updated directly\n return needsToForkPeerContext ? nextEntries : undefined\n },\n\n /**\n * Try to resolve peer dependencies using already seen target\n * values from the current peer context set.\n */\n resolvePeerDeps: () => {\n // iterate on the set of peer dependencies of the current node\n // and try to resolve them from the existing peer context set,\n // when possible, add them as edges in the graph right away, if not,\n // then we move them back to the `nextDeps` list for processing\n // along with the rest of the regular dependencies\n for (const nextDep of nextPeerDeps.values()) {\n const { spec, type } = nextDep\n if (type === 'peer' || type === 'peerOptional') {\n // try to retrieve an entry for that peer dep from\n // the current peer context set\n const entry = peerContext.get(spec.final.name)\n if (\n !node.edgesOut.has(spec.final.name) &&\n entry?.target &&\n satisfies(\n entry.target.id,\n spec,\n fromNode.location,\n fromNode.projectRoot,\n graph.monorepo,\n )\n ) {\n // entry satisfied, create edge in the graph\n graph.addEdge(type, spec, node, entry.target)\n entry.specs.add(spec.final)\n } else if (type === 'peerOptional') {\n // skip unsatisfied peerOptional dependencies,\n // just create a dangling edge\n graph.addEdge(type, spec, node)\n } else {\n // could not satisfy from peer context, add to next deps\n nextDeps.push(nextDep)\n }\n }\n }\n },\n})\n\n/**\n * Given an array of processed results for the current level dependencies\n * being placed in the currently building ideal graph, traverse its direct\n * dependencies and track peer dependencies in their appropriate peer context\n * sets, forking as needed and resolving peer dependencies using suitable\n * nodes already present in the graph if possible.\n */\nexport const postPlacementPeerCheck = (\n graph: Graph,\n sortedLevelResults: ProcessPlacementResult[],\n) => {\n // Update peer contexts in a sorted manner after processing all nodes\n // at a given level to ensure deterministic behavior when it comes to\n // forking new peer contexts\n for (const childDepsToProcess of sortedLevelResults) {\n // Sort childDepsToProcess deterministically by node.id\n const sortedChildDeps = [...childDepsToProcess].sort((a, b) =>\n a.node.id.localeCompare(b.node.id, 'en'),\n )\n\n const needsForking = new Map<\n ProcessPlacementResultEntry,\n {\n dependent: Node\n spec: Spec\n type: DependencySaveType\n }[]\n >()\n // first iterate on all child deps, adding entries to the current\n // context and collect the information on which ones need forking\n for (const childDep of sortedChildDeps) {\n const needsFork = childDep.updateContext.putEntries()\n if (needsFork) {\n needsForking.set(childDep, needsFork)\n }\n }\n\n // Sort needsForking entries before iterating (Map iteration order = insertion order)\n const sortedNeedsForkingEntries = [\n ...needsForking.entries(),\n ].sort(([a], [b]) => a.node.id.localeCompare(b.node.id, 'en'))\n\n // then iterate again, forking contexts as needed but also try to\n // reuse the context of the previous sibling if possible\n let prevContext\n for (const [childDep, nextEntries] of sortedNeedsForkingEntries) {\n if (\n prevContext &&\n !checkEntriesToPeerContext(prevContext, nextEntries)\n ) {\n // the context of the previous sibling can be reused\n addEntriesToPeerContext(\n prevContext,\n nextEntries,\n childDep.node,\n graph.monorepo,\n )\n childDep.peerContext = prevContext\n continue\n }\n childDep.peerContext = forkPeerContext(\n graph,\n childDep.peerContext,\n nextEntries,\n )\n prevContext = childDep.peerContext\n }\n // try to resolve peer dependencies now that\n // the context is fully set up\n for (const childDep of sortedChildDeps) {\n childDep.updateContext.resolvePeerDeps()\n childDep.deps = getOrderedDependencies(childDep.deps)\n }\n }\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import type { PathScurry } from 'path-scurry';
2
+ import type { PackageInfoClient } from '@vltpkg/package-info';
3
+ import type { SpecOptions } from '@vltpkg/spec';
4
+ import type { RollbackRemove } from '@vltpkg/rollback-remove';
5
+ import type { BuildIdealAddOptions, BuildIdealFromGraphOptions, BuildIdealRemoveOptions, TransientAddMap, TransientRemoveMap } from './types.ts';
6
+ import type { GraphModifier } from '../modifiers.ts';
7
+ import type { Graph } from '../graph.ts';
8
+ export type RefreshIdealGraphOptions = BuildIdealAddOptions & BuildIdealRemoveOptions & BuildIdealFromGraphOptions & SpecOptions & {
9
+ /**
10
+ * The graph modifiers helper object.
11
+ */
12
+ modifiers?: GraphModifier;
13
+ /**
14
+ * A {@link PathScurry} instance based on the `projectRoot` path
15
+ */
16
+ scurry: PathScurry;
17
+ /**
18
+ * A {@link PackageInfoClient} instance to read manifest info from.
19
+ */
20
+ packageInfo: PackageInfoClient;
21
+ /**
22
+ * The actual graph to compare against for early extraction
23
+ */
24
+ actual?: Graph;
25
+ /**
26
+ * A {@link RollbackRemove} instance to handle extraction rollbacks
27
+ */
28
+ remover: RollbackRemove;
29
+ /**
30
+ * Dependencies to be added to non-importer nodes when they are placed.
31
+ * Used for nested folder dependencies that are not importers.
32
+ */
33
+ transientAdd?: TransientAddMap;
34
+ /**
35
+ * Dependencies to be removed from non-importer nodes when they are placed.
36
+ * Used for nested folder dependencies that are not importers.
37
+ */
38
+ transientRemove?: TransientRemoveMap;
39
+ };
40
+ /**
41
+ * Rebuilds the provided ideal graph.
42
+ */
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh-ideal-graph.d.ts","sourceRoot":"","sources":["../../src/ideal/refresh-ideal-graph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,EACf,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,GACzD,uBAAuB,GACvB,0BAA0B,GAC1B,WAAW,GAAG;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB;;OAEG;IACH,MAAM,EAAE,UAAU,CAAA;IAElB;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IAEd;;OAEG;IACH,OAAO,EAAE,cAAc,CAAA;IAEvB;;;OAGG;IACH,YAAY,CAAC,EAAE,eAAe,CAAA;IAE9B;;;OAGG;IACH,eAAe,CAAC,EAAE,kBAAkB,CAAA;CACrC,CAAA;AAkCH;;GAEG;AACH,eAAO,MAAM,iBAAiB,2HAY3B,wBAAwB,kBAkE1B,CAAA;AAMD;;GAEG;AACH,eAAO,MAAM,oBAAoB,cAA2B,CAAA"}
@@ -0,0 +1,79 @@
1
+ import { appendNodes } from "./append-nodes.js";
2
+ import { getNodeOrderedDependencies } from "./get-ordered-dependencies.js";
3
+ /**
4
+ * Returns an ordered list of importer nodes.
5
+ */
6
+ const getOrderedImporters = (graph) => {
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');
23
+ });
24
+ return orderedImporters;
25
+ };
26
+ /**
27
+ * Rebuilds the provided ideal graph.
28
+ */
29
+ export const refreshIdealGraph = async ({ add, graph, modifiers, packageInfo, scurry, actual, remove, remover, transientAdd, transientRemove, ...specOptions }) => {
30
+ const seen = new Set();
31
+ const extractPromises = [];
32
+ const seenExtracted = new Set();
33
+ // gets an ordered list of importers to ensure deterministic processing
34
+ const orderedImporters = getOrderedImporters(graph);
35
+ const depsPerImporter = new Map();
36
+ for (const importer of orderedImporters) {
37
+ // gets an ordered list of dependencies for this importer
38
+ // while also taking into account additions and removals
39
+ const deps = getNodeOrderedDependencies(importer, { add, remove });
40
+ depsPerImporter.set(importer, deps);
41
+ }
42
+ // removes all edges to start recalculating the graph
43
+ if (add.modifiedDependencies || remove.modifiedDependencies) {
44
+ graph.resetEdges();
45
+ }
46
+ // iterates on the list of dependencies per importer updating
47
+ // the graph using metadata fetch from the registry manifest files
48
+ for (const importer of orderedImporters) {
49
+ modifiers?.tryImporter(importer);
50
+ // gets a ref to the map of dependencies being added to this importer
51
+ const addedDeps = add.get(importer.id);
52
+ const deps = depsPerImporter.get(importer);
53
+ /* c8 ignore next */
54
+ if (!deps)
55
+ continue;
56
+ // gets a ref to the list of modifier functions for this set of deps
57
+ const modifierRefs = modifiers?.tryDependencies(importer, deps);
58
+ // Add new nodes for packages defined in the dependencies list fetching
59
+ // metadata from the registry manifests and updating the graph
60
+ await appendNodes(packageInfo, graph, importer, deps, scurry, specOptions, seen, addedDeps, modifiers, modifierRefs, extractPromises, actual, seenExtracted, remover, transientAdd, transientRemove);
61
+ }
62
+ // set default node locations, if possible
63
+ for (const node of graph.nodes.values()) {
64
+ node.setDefaultLocation();
65
+ }
66
+ // Wait for all extraction promises to complete
67
+ if (extractPromises.length > 0) {
68
+ await Promise.all(extractPromises);
69
+ }
70
+ };
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh-ideal-graph.js","sourceRoot":"","sources":["../../src/ideal/refresh-ideal-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AA4D1E;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,KAAY,EAAU,EAAE;IACnD,MAAM,gBAAgB,GAAG,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,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A+C;IAC/C,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IACpC,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,IAAI,gBAAgB,GAAG,CAAC,CAAA;AACxB;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAA","sourcesContent":["import { appendNodes } from './append-nodes.ts'\nimport { getNodeOrderedDependencies } from './get-ordered-dependencies.ts'\nimport type { PathScurry } from 'path-scurry'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n BuildIdealRemoveOptions,\n TransientAddMap,\n TransientRemoveMap,\n} from './types.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { GraphModifier } from '../modifiers.ts'\nimport type { ExtractResult } from '../reify/extract-node.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\n\nexport type RefreshIdealGraphOptions = BuildIdealAddOptions &\n BuildIdealRemoveOptions &\n BuildIdealFromGraphOptions &\n SpecOptions & {\n /**\n * The graph modifiers helper object.\n */\n modifiers?: GraphModifier\n /**\n * A {@link PathScurry} instance based on the `projectRoot` path\n */\n scurry: PathScurry\n\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n\n /**\n * The actual graph to compare against for early extraction\n */\n actual?: Graph\n\n /**\n * A {@link RollbackRemove} instance to handle extraction rollbacks\n */\n remover: RollbackRemove\n\n /**\n * Dependencies to be added to non-importer nodes when they are placed.\n * Used for nested folder dependencies that are not importers.\n */\n transientAdd?: TransientAddMap\n\n /**\n * Dependencies to be removed from non-importer nodes when they are placed.\n * Used for nested folder dependencies that are not importers.\n */\n transientRemove?: TransientRemoveMap\n }\n\n/**\n * Returns an ordered list of importer nodes.\n */\nconst getOrderedImporters = (graph: Graph): Node[] => {\n const orderedImporters = [...graph.importers].sort((a, b) => {\n // sorts importers first by usage of peer deps\n const aIsPeer =\n (\n a.manifest?.peerDependencies &&\n Object.keys(a.manifest.peerDependencies).length > 0\n ) ?\n 1\n : 0\n const bIsPeer =\n (\n b.manifest?.peerDependencies &&\n Object.keys(b.manifest.peerDependencies).length > 0\n ) ?\n 1\n : 0\n\n // importers with regular deps only first, with peer deps last\n if (aIsPeer !== bIsPeer) {\n return aIsPeer - bIsPeer\n }\n\n // if both are in the same group, sort alphabetically by manifest name\n return a.name.localeCompare(b.name, 'en')\n })\n return orderedImporters\n}\n\n/**\n * Rebuilds the provided ideal graph.\n */\nexport const refreshIdealGraph = async ({\n add,\n graph,\n modifiers,\n packageInfo,\n scurry,\n actual,\n remove,\n remover,\n transientAdd,\n transientRemove,\n ...specOptions\n}: RefreshIdealGraphOptions) => {\n const seen = new Set<DepID>()\n const extractPromises: Promise<ExtractResult>[] = []\n const seenExtracted = new Set<DepID>()\n\n // gets an ordered list of importers to ensure deterministic processing\n const orderedImporters = getOrderedImporters(graph)\n const depsPerImporter = new Map<Node, Dependency[]>()\n for (const importer of orderedImporters) {\n // gets an ordered list of dependencies for this importer\n // while also taking into account additions and removals\n const deps = getNodeOrderedDependencies(importer, { add, remove })\n depsPerImporter.set(importer, deps)\n }\n\n // removes all edges to start recalculating the graph\n if (add.modifiedDependencies || remove.modifiedDependencies) {\n graph.resetEdges()\n }\n\n // iterates on the list of dependencies per importer updating\n // the graph using metadata fetch from the registry manifest files\n for (const importer of orderedImporters) {\n modifiers?.tryImporter(importer)\n\n // gets a ref to the map of dependencies being added to this importer\n const addedDeps = add.get(importer.id)\n\n const deps = depsPerImporter.get(importer)\n /* c8 ignore next */\n if (!deps) continue\n\n // gets a ref to the list of modifier functions for this set of deps\n const modifierRefs = modifiers?.tryDependencies(importer, deps)\n\n // Add new nodes for packages defined in the dependencies list fetching\n // metadata from the registry manifests and updating the graph\n await appendNodes(\n packageInfo,\n graph,\n importer,\n deps,\n scurry,\n specOptions,\n seen,\n addedDeps,\n modifiers,\n modifierRefs,\n extractPromises,\n actual,\n seenExtracted,\n remover,\n transientAdd,\n transientRemove,\n )\n }\n\n // set default node locations, if possible\n for (const node of graph.nodes.values()) {\n node.setDefaultLocation()\n }\n\n // Wait for all extraction promises to complete\n if (extractPromises.length > 0) {\n await Promise.all(extractPromises)\n }\n}\n\n/**\n * Global index to assign unique ids used to track peer context sets.\n */\nlet peerContextIndex = 0\n/**\n * Retrieve the next unique index for a peer context set.\n */\nexport const nextPeerContextIndex = () => peerContextIndex++\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-satisfied-specs.d.ts","sourceRoot":"","sources":["../../src/ideal/remove-satisfied-specs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAC5D,0BAA0B,CAAA;AAE5B;;;GAGG;AACH,eAAO,MAAM,oBAAoB,oBAG9B,2BAA2B,SAqC7B,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-satisfied-specs.js","sourceRoot":"","sources":["../../src/ideal/remove-satisfied-specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAS7C;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EACnC,GAAG,EACH,KAAK,GACuB,EAAE,EAAE;IAChC,KAAK,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACvC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,8CAA8C,EAAE;gBAC1D,KAAK,EAAE,KAAK;aACb,CAAC,CAAA;QACJ,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,YAAY,EAAE,CAAC;YAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YACxC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,6BAA6B;gBAC7B,SAAQ;YACV,CAAC;YAED,kEAAkE;YAClE,kEAAkE;YAClE,IACE,SAAS,CACP,IAAI,CAAC,EAAE,EAAE,EAAE,EACX,UAAU,CAAC,IAAI,EACf,IAAI,CAAC,IAAI,CAAC,QAAQ,EAClB,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,QAAQ,CACf,EACD,CAAC;gBACD,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,iEAAiE;IACjE,KAAK,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,IAAI,YAAY,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC5B,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { satisfies } from '@vltpkg/satisfies'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n} from './types.ts'\n\nexport type RemoveSatisfiedSpecsOptions = BuildIdealAddOptions &\n BuildIdealFromGraphOptions\n\n/**\n * Traverse the objects defined in `add` and removes any references to specs\n * that are already satisfied by the contents of the actual `graph`.\n */\nexport const removeSatisfiedSpecs = ({\n add,\n graph,\n}: RemoveSatisfiedSpecsOptions) => {\n for (const [depID, dependencies] of add.entries()) {\n const importer = graph.nodes.get(depID)\n if (!importer) {\n throw error('Referred importer node id could not be found', {\n found: depID,\n })\n }\n for (const [name, dependency] of dependencies) {\n const edge = importer.edgesOut.get(name)\n if (!edge) {\n // brand new edge being added\n continue\n }\n\n // If the current graph edge is already valid, then we remove that\n // dependency item from the list of items to be added to the graph\n if (\n satisfies(\n edge.to?.id,\n dependency.spec,\n edge.from.location,\n graph.projectRoot,\n graph.monorepo,\n )\n ) {\n dependencies.delete(name)\n }\n }\n }\n\n // Removes any references to an importer that no longer has specs\n for (const [depID, dependencies] of add.entries()) {\n if (dependencies.size === 0) {\n add.delete(depID)\n }\n }\n}\n"]}