@vltpkg/graph 0.0.0-9 → 1.0.0-rc.10

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 (203) hide show
  1. package/README.md +136 -1
  2. package/dist/esm/actual/load.d.ts +49 -3
  3. package/dist/esm/actual/load.d.ts.map +1 -1
  4. package/dist/esm/actual/load.js +146 -74
  5. package/dist/esm/actual/load.js.map +1 -1
  6. package/dist/esm/browser.d.ts +8 -4
  7. package/dist/esm/browser.d.ts.map +1 -1
  8. package/dist/esm/browser.js +6 -2
  9. package/dist/esm/browser.js.map +1 -1
  10. package/dist/esm/build.d.ts +29 -0
  11. package/dist/esm/build.d.ts.map +1 -0
  12. package/dist/esm/build.js +79 -0
  13. package/dist/esm/build.js.map +1 -0
  14. package/dist/esm/dependencies.d.ts +10 -3
  15. package/dist/esm/dependencies.d.ts.map +1 -1
  16. package/dist/esm/dependencies.js +63 -0
  17. package/dist/esm/dependencies.js.map +1 -1
  18. package/dist/esm/diff.d.ts +69 -0
  19. package/dist/esm/diff.d.ts.map +1 -1
  20. package/dist/esm/diff.js +25 -0
  21. package/dist/esm/diff.js.map +1 -1
  22. package/dist/esm/edge.d.ts +8 -2
  23. package/dist/esm/edge.d.ts.map +1 -1
  24. package/dist/esm/edge.js +12 -0
  25. package/dist/esm/edge.js.map +1 -1
  26. package/dist/esm/fixup-added-names.d.ts +16 -0
  27. package/dist/esm/fixup-added-names.d.ts.map +1 -0
  28. package/dist/esm/fixup-added-names.js +31 -0
  29. package/dist/esm/fixup-added-names.js.map +1 -0
  30. package/dist/esm/graph.d.ts +34 -10
  31. package/dist/esm/graph.d.ts.map +1 -1
  32. package/dist/esm/graph.js +150 -24
  33. package/dist/esm/graph.js.map +1 -1
  34. package/dist/esm/ideal/append-nodes.d.ts +12 -1
  35. package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
  36. package/dist/esm/ideal/append-nodes.js +303 -53
  37. package/dist/esm/ideal/append-nodes.js.map +1 -1
  38. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +4 -4
  39. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
  40. package/dist/esm/ideal/build-ideal-from-starting-graph.js +35 -16
  41. package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
  42. package/dist/esm/ideal/build.d.ts +9 -0
  43. package/dist/esm/ideal/build.d.ts.map +1 -1
  44. package/dist/esm/ideal/build.js +31 -1
  45. package/dist/esm/ideal/build.js.map +1 -1
  46. package/dist/esm/ideal/get-importer-specs.d.ts +11 -3
  47. package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
  48. package/dist/esm/ideal/get-importer-specs.js +86 -9
  49. package/dist/esm/ideal/get-importer-specs.js.map +1 -1
  50. package/dist/esm/ideal/get-ordered-dependencies.d.ts +10 -0
  51. package/dist/esm/ideal/get-ordered-dependencies.d.ts.map +1 -0
  52. package/dist/esm/ideal/get-ordered-dependencies.js +42 -0
  53. package/dist/esm/ideal/get-ordered-dependencies.js.map +1 -0
  54. package/dist/esm/ideal/peers.d.ts +71 -0
  55. package/dist/esm/ideal/peers.d.ts.map +1 -0
  56. package/dist/esm/ideal/peers.js +318 -0
  57. package/dist/esm/ideal/peers.js.map +1 -0
  58. package/dist/esm/ideal/refresh-ideal-graph.d.ts +48 -0
  59. package/dist/esm/ideal/refresh-ideal-graph.d.ts.map +1 -0
  60. package/dist/esm/ideal/refresh-ideal-graph.js +79 -0
  61. package/dist/esm/ideal/refresh-ideal-graph.js.map +1 -0
  62. package/dist/esm/ideal/types.d.ts +78 -1
  63. package/dist/esm/ideal/types.d.ts.map +1 -1
  64. package/dist/esm/ideal/types.js.map +1 -1
  65. package/dist/esm/index.d.ts +9 -4
  66. package/dist/esm/index.d.ts.map +1 -1
  67. package/dist/esm/index.js +5 -1
  68. package/dist/esm/index.js.map +1 -1
  69. package/dist/esm/install.d.ts +10 -4
  70. package/dist/esm/install.d.ts.map +1 -1
  71. package/dist/esm/install.js +191 -20
  72. package/dist/esm/install.js.map +1 -1
  73. package/dist/esm/lockfile/load-edges.d.ts +8 -1
  74. package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
  75. package/dist/esm/lockfile/load-edges.js +80 -15
  76. package/dist/esm/lockfile/load-edges.js.map +1 -1
  77. package/dist/esm/lockfile/load-nodes.d.ts +3 -2
  78. package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
  79. package/dist/esm/lockfile/load-nodes.js +85 -13
  80. package/dist/esm/lockfile/load-nodes.js.map +1 -1
  81. package/dist/esm/lockfile/load.d.ts +18 -5
  82. package/dist/esm/lockfile/load.d.ts.map +1 -1
  83. package/dist/esm/lockfile/load.js +28 -20
  84. package/dist/esm/lockfile/load.js.map +1 -1
  85. package/dist/esm/lockfile/save.d.ts +16 -3
  86. package/dist/esm/lockfile/save.d.ts.map +1 -1
  87. package/dist/esm/lockfile/save.js +64 -17
  88. package/dist/esm/lockfile/save.js.map +1 -1
  89. package/dist/esm/lockfile/types.d.ts +34 -4
  90. package/dist/esm/lockfile/types.d.ts.map +1 -1
  91. package/dist/esm/lockfile/types.js +31 -0
  92. package/dist/esm/lockfile/types.js.map +1 -1
  93. package/dist/esm/modifiers.d.ts +189 -0
  94. package/dist/esm/modifiers.d.ts.map +1 -0
  95. package/dist/esm/modifiers.js +330 -0
  96. package/dist/esm/modifiers.js.map +1 -0
  97. package/dist/esm/node.d.ts +91 -6
  98. package/dist/esm/node.d.ts.map +1 -1
  99. package/dist/esm/node.js +119 -5
  100. package/dist/esm/node.js.map +1 -1
  101. package/dist/esm/reify/add-edge.d.ts +1 -2
  102. package/dist/esm/reify/add-edge.d.ts.map +1 -1
  103. package/dist/esm/reify/add-edge.js +29 -18
  104. package/dist/esm/reify/add-edge.js.map +1 -1
  105. package/dist/esm/reify/add-edges.d.ts +1 -2
  106. package/dist/esm/reify/add-edges.d.ts.map +1 -1
  107. package/dist/esm/reify/add-edges.js +3 -3
  108. package/dist/esm/reify/add-edges.js.map +1 -1
  109. package/dist/esm/reify/add-nodes.d.ts.map +1 -1
  110. package/dist/esm/reify/add-nodes.js +4 -27
  111. package/dist/esm/reify/add-nodes.js.map +1 -1
  112. package/dist/esm/reify/bin-chmod.d.ts +11 -0
  113. package/dist/esm/reify/bin-chmod.d.ts.map +1 -0
  114. package/dist/esm/reify/bin-chmod.js +39 -0
  115. package/dist/esm/reify/bin-chmod.js.map +1 -0
  116. package/dist/esm/reify/build.d.ts +10 -1
  117. package/dist/esm/reify/build.d.ts.map +1 -1
  118. package/dist/esm/reify/build.js +36 -23
  119. package/dist/esm/reify/build.js.map +1 -1
  120. package/dist/esm/reify/calculate-save-value.d.ts +3 -0
  121. package/dist/esm/reify/calculate-save-value.d.ts.map +1 -0
  122. package/dist/esm/reify/calculate-save-value.js +45 -0
  123. package/dist/esm/reify/calculate-save-value.js.map +1 -0
  124. package/dist/esm/reify/check-needed-build.d.ts +25 -0
  125. package/dist/esm/reify/check-needed-build.d.ts.map +1 -0
  126. package/dist/esm/reify/check-needed-build.js +50 -0
  127. package/dist/esm/reify/check-needed-build.js.map +1 -0
  128. package/dist/esm/reify/delete-edge.d.ts.map +1 -1
  129. package/dist/esm/reify/delete-edge.js +3 -4
  130. package/dist/esm/reify/delete-edge.js.map +1 -1
  131. package/dist/esm/reify/extract-node.d.ts +24 -0
  132. package/dist/esm/reify/extract-node.d.ts.map +1 -0
  133. package/dist/esm/reify/extract-node.js +84 -0
  134. package/dist/esm/reify/extract-node.js.map +1 -0
  135. package/dist/esm/reify/index.d.ts +18 -1
  136. package/dist/esm/reify/index.d.ts.map +1 -1
  137. package/dist/esm/reify/index.js +85 -15
  138. package/dist/esm/reify/index.js.map +1 -1
  139. package/dist/esm/reify/internal-hoist.d.ts +9 -0
  140. package/dist/esm/reify/internal-hoist.d.ts.map +1 -0
  141. package/dist/esm/reify/internal-hoist.js +134 -0
  142. package/dist/esm/reify/internal-hoist.js.map +1 -0
  143. package/dist/esm/reify/update-importers-package-json.d.ts +1 -1
  144. package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
  145. package/dist/esm/reify/update-importers-package-json.js +33 -24
  146. package/dist/esm/reify/update-importers-package-json.js.map +1 -1
  147. package/dist/esm/remove-optional-subgraph.js +1 -1
  148. package/dist/esm/remove-optional-subgraph.js.map +1 -1
  149. package/dist/esm/resolve-save-type.d.ts +1 -2
  150. package/dist/esm/resolve-save-type.d.ts.map +1 -1
  151. package/dist/esm/resolve-save-type.js.map +1 -1
  152. package/dist/esm/stringify-node.d.ts +1 -1
  153. package/dist/esm/stringify-node.d.ts.map +1 -1
  154. package/dist/esm/stringify-node.js +10 -1
  155. package/dist/esm/stringify-node.js.map +1 -1
  156. package/dist/esm/transfer-data/load.d.ts +44 -0
  157. package/dist/esm/transfer-data/load.d.ts.map +1 -0
  158. package/dist/esm/transfer-data/load.js +176 -0
  159. package/dist/esm/transfer-data/load.js.map +1 -0
  160. package/dist/esm/uninstall.d.ts +5 -4
  161. package/dist/esm/uninstall.d.ts.map +1 -1
  162. package/dist/esm/uninstall.js +61 -19
  163. package/dist/esm/uninstall.js.map +1 -1
  164. package/dist/esm/update.d.ts +13 -0
  165. package/dist/esm/update.d.ts.map +1 -0
  166. package/dist/esm/update.js +73 -0
  167. package/dist/esm/update.js.map +1 -0
  168. package/dist/esm/virtual-root.d.ts +16 -0
  169. package/dist/esm/virtual-root.d.ts.map +1 -0
  170. package/dist/esm/virtual-root.js +79 -0
  171. package/dist/esm/virtual-root.js.map +1 -0
  172. package/dist/esm/visualization/human-readable-output.d.ts +4 -5
  173. package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
  174. package/dist/esm/visualization/human-readable-output.js +47 -19
  175. package/dist/esm/visualization/human-readable-output.js.map +1 -1
  176. package/dist/esm/visualization/json-output.d.ts +7 -2
  177. package/dist/esm/visualization/json-output.d.ts.map +1 -1
  178. package/dist/esm/visualization/json-output.js +35 -12
  179. package/dist/esm/visualization/json-output.js.map +1 -1
  180. package/dist/esm/visualization/mermaid-output.d.ts +7 -1
  181. package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
  182. package/dist/esm/visualization/mermaid-output.js +110 -14
  183. package/dist/esm/visualization/mermaid-output.js.map +1 -1
  184. package/dist/esm/visualization/object-like-output.d.ts +1 -1
  185. package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
  186. package/dist/esm/visualization/object-like-output.js.map +1 -1
  187. package/package.json +35 -29
  188. package/dist/esm/ideal/add-nodes.d.ts +0 -19
  189. package/dist/esm/ideal/add-nodes.d.ts.map +0 -1
  190. package/dist/esm/ideal/add-nodes.js +0 -32
  191. package/dist/esm/ideal/add-nodes.js.map +0 -1
  192. package/dist/esm/ideal/remove-nodes.d.ts +0 -7
  193. package/dist/esm/ideal/remove-nodes.d.ts.map +0 -1
  194. package/dist/esm/ideal/remove-nodes.js +0 -19
  195. package/dist/esm/ideal/remove-nodes.js.map +0 -1
  196. package/dist/esm/reify/bin-paths.d.ts +0 -4
  197. package/dist/esm/reify/bin-paths.d.ts.map +0 -1
  198. package/dist/esm/reify/bin-paths.js +0 -23
  199. package/dist/esm/reify/bin-paths.js.map +0 -1
  200. package/dist/esm/types.d.ts +0 -42
  201. package/dist/esm/types.d.ts.map +0 -1
  202. package/dist/esm/types.js +0 -2
  203. package/dist/esm/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAM3C,uDAAuD;AACvD,6EAA6E;AAC7E,4BAA4B;AAC5B,wBAAwB;AAExB,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,IAAI;IACf,IAAI,CAAO;IACX,EAAE,CAAO;IAET,WAAW,CAAQ;IAEnB;;;OAGG;IACH,mBAAmB,GAAG,KAAK,CAAA;IAE3B;;OAEG;IACH,KAAK,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YACrC,oBAAoB;YACpB,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;YAC5B,KAAK,CAAC,IAAI,CACR,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAC3D,CAAA;QACH,CAAC;QACD,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAmB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC1D,MAAM,KAAK,GACT,OAAO,EAAE,MAAM,CAAC,CAAC;YACf,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;YACzD,CAAC,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAA;QAEpB,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;EACpC,KAAK;aACJ,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aAClE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;aACzB,IAAI,CAAC,IAAI,CAAC;EACX,CAAA;IACA,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { InspectOptions } from 'node:util'\nimport type { Edge } from './edge.ts'\nimport type { Graph } from './graph.ts'\nimport type { Node } from './node.ts'\n\n// XXX should file deps *always* be considered changed?\n// unless the thing containing it wasn't possibly changed because it's inside\n// a dep that didn't change?\n// Same with remote deps\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\n/**\n * A Diff object is a representation of a set of changes from one\n * graph to another, typically from the actual graph as it is reified\n * on disk, to an intended ideal graph.\n *\n * The naming convention can get a bit confusing here, because it's a\n * set of directed changes from one set of directed objects to another.\n *\n * Within the context the Diff object, `from` is the Graph we're coming from,\n * and `to` is the Graph we're trying to create.\n */\nexport class Diff {\n from: Graph\n to: Graph\n\n projectRoot: string\n\n /**\n * If changes need to be made later for failures of optional nodes,\n * set this flag so that we know to call graph.gc() at the appropriate time.\n */\n hadOptionalFailures = false\n\n /**\n * Collection of nodes to add and delete\n */\n nodes = {\n /** Nodes in the `to` graph that are not in the `from` graph */\n add: new Set<Node>(),\n /** Nodes in the `from` graph that are not in the `to` graph */\n delete: new Set<Node>(),\n }\n\n /**\n * Collection of nodes to add and delete\n */\n edges = {\n /** Edges in the `to` graph that are not found in the `from` graph */\n add: new Set<Edge>(),\n /** Edges in the `from` graph that are not found in the `to` graph */\n delete: new Set<Edge>(),\n }\n\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Diff'\n }\n\n constructor(from: Graph, to: Graph) {\n this.from = from\n this.to = to\n this.projectRoot = from.projectRoot\n if (to.projectRoot !== from.projectRoot) {\n throw error('projectRoot mismatch in Graph diff', {\n wanted: from.projectRoot,\n found: to.projectRoot,\n })\n }\n\n for (const [id, node] of this.from.nodes) {\n if (!this.to.nodes.get(id)?.equals(node)) {\n this.nodes.delete.add(node)\n }\n }\n\n for (const [id, node] of this.to.nodes) {\n if (!this.from.nodes.get(id)?.equals(node)) {\n this.nodes.add.add(node)\n }\n }\n\n for (const edge of this.to.edges) {\n // the node with this dep, in the from graph\n const fromNode = this.from.nodes.get(edge.from.id)\n const fromEdge = fromNode?.edgesOut.get(edge.spec.name)\n if (fromEdge?.to?.id === edge.to?.id) continue\n if (fromEdge?.to) this.edges.delete.add(fromEdge)\n if (edge.to) this.edges.add.add(edge)\n }\n for (const edge of this.from.edges) {\n // the node with this dep, in the to graph\n const toNode = this.to.nodes.get(edge.from.id)\n const toEdge = toNode?.edgesOut.get(edge.spec.name)\n if (toEdge?.to?.id === edge.to?.id) continue\n if (edge.to) this.edges.delete.add(edge)\n if (toEdge?.to) this.edges.add.add(toEdge)\n }\n }\n\n [kCustomInspect](_: number, options?: InspectOptions): string {\n const red: [string, string] =\n options?.colors ? ['\\x1b[31m', '\\x1b[m'] : ['', '']\n const green: [string, string] =\n options?.colors ? ['\\x1b[32m', '\\x1b[m'] : ['', '']\n const lines: string[] = []\n for (const node of this.nodes.add) {\n lines.push(`+ ${node.id}`)\n }\n for (const node of this.nodes.delete) {\n lines.push(`- ${node.id}`)\n }\n for (const edge of this.edges.add) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `+ ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n for (const edge of this.edges.delete) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `- ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n const wrap = (s: string, c: [string, string]) => c.join(s)\n const color =\n options?.colors ?\n (s: string) => wrap(s, s.startsWith('+') ? green : red)\n : (s: string) => s\n\n return `${this[Symbol.toStringTag]} {\n${lines\n .sort((a, b) => a.substring(1).localeCompare(b.substring(1), 'en'))\n .map(s => ' ' + color(s))\n .join('\\n')}\n}`\n }\n}\n"]}
1
+ {"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAM3C,uDAAuD;AACvD,6EAA6E;AAC7E,4BAA4B;AAC5B,wBAAwB;AAExB,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,IAAI;IACf,IAAI,CAAO;IACX,EAAE,CAAO;IAET,WAAW,CAAQ;IAEnB;;;OAGG;IACH,mBAAmB,G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I,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAC3B,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE;gBACL,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACnD,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;aAC1D;YACD,KAAK,EAAE;gBACL,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACnD,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;aAC1D;SACF,CAAA;IACH,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { InspectOptions } from 'node:util'\nimport type { Edge } from './edge.ts'\nimport type { Graph } from './graph.ts'\nimport type { Node } from './node.ts'\n\n// XXX should file deps *always* be considered changed?\n// unless the thing containing it wasn't possibly changed because it's inside\n// a dep that didn't change?\n// Same with remote deps\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\n/**\n * A Diff object is a representation of a set of changes from one\n * graph to another, typically from the actual graph as it is reified\n * on disk, to an intended ideal graph.\n *\n * The naming convention can get a bit confusing here, because it's a\n * set of directed changes from one set of directed objects to another.\n *\n * Within the context the Diff object, `from` is the Graph we're coming from,\n * and `to` is the Graph we're trying to create.\n */\nexport class Diff {\n from: Graph\n to: Graph\n\n projectRoot: string\n\n /**\n * If changes need to be made later for failures of optional nodes,\n * set this flag so that we know to call graph.gc() at the appropriate time.\n */\n hadOptionalFailures = false\n\n /**\n * Collection of nodes to add and delete\n */\n nodes = {\n /** Nodes in the `to` graph that are not in the `from` graph */\n add: new Set<Node>(),\n /** Nodes in the `from` graph that are not in the `to` graph */\n delete: new Set<Node>(),\n }\n\n /**\n * Collection of nodes to add and delete\n */\n edges = {\n /** Edges in the `to` graph that are not found in the `from` graph */\n add: new Set<Edge>(),\n /** Edges in the `from` graph that are not found in the `to` graph */\n delete: new Set<Edge>(),\n }\n\n /**\n * True if the diff only contains optional nodes (computed during construction)\n */\n optionalOnly = true\n\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Diff'\n }\n\n constructor(from: Graph, to: Graph) {\n this.from = from\n this.to = to\n this.projectRoot = from.projectRoot\n if (to.projectRoot !== from.projectRoot) {\n throw error('projectRoot mismatch in Graph diff', {\n wanted: from.projectRoot,\n found: to.projectRoot,\n })\n }\n\n for (const [id, node] of this.from.nodes) {\n if (!this.to.nodes.get(id)?.equals(node)) {\n this.nodes.delete.add(node)\n }\n }\n\n for (const [id, node] of this.to.nodes) {\n if (!this.from.nodes.get(id)?.equals(node)) {\n this.nodes.add.add(node)\n if (!node.optional) {\n this.optionalOnly = false\n }\n }\n }\n\n for (const edge of this.to.edges) {\n // the node with this dep, in the from graph\n const fromNode = this.from.nodes.get(edge.from.id)\n const fromEdge = fromNode?.edgesOut.get(edge.spec.name)\n if (fromEdge?.to?.id === edge.to?.id) continue\n if (fromEdge?.to) this.edges.delete.add(fromEdge)\n if (edge.to) this.edges.add.add(edge)\n }\n for (const edge of this.from.edges) {\n // the node with this dep, in the to graph\n const toNode = this.to.nodes.get(edge.from.id)\n const toEdge = toNode?.edgesOut.get(edge.spec.name)\n if (toEdge?.to?.id === edge.to?.id) continue\n if (edge.to) this.edges.delete.add(edge)\n if (toEdge?.to) this.edges.add.add(toEdge)\n }\n }\n\n [kCustomInspect](_: number, options?: InspectOptions): string {\n const red: [string, string] =\n options?.colors ? ['\\x1b[31m', '\\x1b[m'] : ['', '']\n const green: [string, string] =\n options?.colors ? ['\\x1b[32m', '\\x1b[m'] : ['', '']\n const lines: string[] = []\n for (const node of this.nodes.add) {\n lines.push(`+ ${node.id}`)\n }\n for (const node of this.nodes.delete) {\n lines.push(`- ${node.id}`)\n }\n for (const edge of this.edges.add) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `+ ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n for (const edge of this.edges.delete) {\n /* c8 ignore next */\n const to = edge.to?.id ?? ''\n lines.push(\n `- ${edge.from.id} ${edge.type} ${edge.spec} ${to}`.trim(),\n )\n }\n const wrap = (s: string, c: [string, string]) => c.join(s)\n const color =\n options?.colors ?\n (s: string) => wrap(s, s.startsWith('+') ? green : red)\n : (s: string) => s\n\n return `${this[Symbol.toStringTag]} {\n${lines\n .sort((a, b) => a.substring(1).localeCompare(b.substring(1), 'en'))\n .map(s => ' ' + color(s))\n .join('\\n')}\n}`\n }\n\n hasChanges(): boolean {\n return (\n this.nodes.add.size > 0 ||\n this.nodes.delete.size > 0 ||\n this.edges.add.size > 0 ||\n this.edges.delete.size > 0\n )\n }\n\n toJSON() {\n return {\n nodes: {\n add: [...this.nodes.add].map(node => node.toJSON()),\n delete: [...this.nodes.delete].map(node => node.toJSON()),\n },\n edges: {\n add: [...this.edges.add].map(edge => edge.toJSON()),\n delete: [...this.edges.delete].map(edge => edge.toJSON()),\n },\n }\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  import type { Spec } from '@vltpkg/spec';
2
2
  import type { InspectOptions } from 'node:util';
3
- import type { DependencyTypeShort } from '@vltpkg/types';
3
+ import type { DependencyTypeShort, EdgeLike } from '@vltpkg/types';
4
4
  import type { Node } from './node.ts';
5
- import type { EdgeLike } from './types.ts';
6
5
  declare const kCustomInspect: unique symbol;
7
6
  export declare class Edge implements EdgeLike {
8
7
  get [Symbol.toStringTag](): string;
@@ -36,6 +35,13 @@ export declare class Edge implements EdgeLike {
36
35
  get peer(): boolean;
37
36
  get peerOptional(): boolean;
38
37
  valid(): boolean;
38
+ toJSON(): {
39
+ from: import("@vltpkg/dep-id").DepID;
40
+ to: import("@vltpkg/dep-id").DepID | undefined;
41
+ type: DependencyTypeShort;
42
+ spec: string;
43
+ };
44
+ toString(): string;
39
45
  }
40
46
  export {};
41
47
  //# sourceMappingURL=edge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"edge.d.ts","sourceRoot":"","sources":["../../src/edge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,QAAA,MAAM,cAAc,eAA2C,CAAA;AAE/D,qBAAa,IAAK,YAAW,QAAQ;IACnC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;IAanD;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IAEV;;OAEG;IACH,EAAE,CAAC,EAAE,IAAI,CAAA;IAET;;OAEG;IACH,IAAI,EAAE,mBAAmB,CAAA;IAEzB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;gBAGR,IAAI,EAAE,mBAAmB,EACzB,IAAI,EAAE,IAAI,EACV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AE1B;IAED,KAAK,IAAI,OAAO;IAWhB,MAAM;;;;;;IASN,QAAQ;CAIT"}
package/dist/esm/edge.js CHANGED
@@ -62,5 +62,17 @@ export class Edge {
62
62
  this.optional
63
63
  : satisfies(this.to.id, this.spec, this.from.location, this.from.projectRoot);
64
64
  }
65
+ toJSON() {
66
+ return {
67
+ from: this.from.id,
68
+ to: this.to?.id,
69
+ type: this.type,
70
+ spec: String(this.spec),
71
+ };
72
+ }
73
+ toString() {
74
+ const to = `${this.name}${this.to ? '' : ' (missing)'}`;
75
+ return `Edge from: ${this.from.id} --|${this.type}|--> ${to}`;
76
+ }
65
77
  }
66
78
  //# sourceMappingURL=edge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"edge.js","sourceRoot":"","sources":["../../src/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IAED,CAAC,cAAc,CAAC,CAAC,CAAS,EAAE,OAAuB;QACjD,MAAM,GAAG,GAAG,OAAO,CACjB;YACE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YACvB,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE;SAChB,EACD,OAAO,CACR,CAAA;QACD,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,GAAG,EAAE,CAAA;IAC7C,CAAC;IAED;;OAEG;IACH,IAAI,CAAM;IAEV;;OAEG;IACH,EAAE,CAAO;IAET;;OAEG;IACH,IAAI,CAAqB;IAEzB;;OAEG;IACH,IAAI,CAAM;IAEV,YACE,IAAyB,EACzB,IAAU,EACV,IAAU,EACV,EAAS;QAET,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAA;IAC5B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;IACjE,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAA;IAC7D,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAA;IACrC,CAAC;IAED,KAAK;QACH,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,IAAI,CAAC,QAAQ;YACf,CAAC,CAAC,SAAS,CACP,IAAI,CAAC,EAAE,CAAC,EAAE,EACV,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAClB,IAAI,CAAC,IAAI,CAAC,WAAW,CACtB,CAAA;IACP,CAAC;CACF","sourcesContent":["import { satisfies } from '@vltpkg/satisfies'\nimport type { Spec } from '@vltpkg/spec'\nimport { inspect } from 'node:util'\nimport type { InspectOptions } from 'node:util'\nimport type { DependencyTypeShort } from '@vltpkg/types'\nimport type { Node } from './node.ts'\nimport type { EdgeLike } from './types.ts'\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport class Edge implements EdgeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Edge'\n }\n\n [kCustomInspect](_: number, options: InspectOptions) {\n const str = inspect(\n {\n from: this.from.id,\n type: this.type,\n spec: String(this.spec),\n to: this.to?.id,\n },\n options,\n )\n return `${this[Symbol.toStringTag]} ${str}`\n }\n\n /**\n * The Node this Edge is connecting from, this is usually the dependent.\n */\n from: Node\n\n /**\n * The node this Edge is connecting to, this is usually a direct dependency.\n */\n to?: Node\n\n /**\n * What type of dependency relationship `from` and `to` nodes have.\n */\n type: DependencyTypeShort\n\n /**\n * The defined spec value for `to` as parsed from the dependent metadata.\n */\n spec: Spec\n\n constructor(\n type: DependencyTypeShort,\n spec: Spec,\n from: Node,\n to?: Node,\n ) {\n this.from = from\n this.to = to\n this.type = type\n this.spec = spec\n }\n\n /**\n * The name of the dependency `to` as defined in the dependent metadata.\n */\n get name() {\n return this.spec.name\n }\n\n /**\n * This edge was defined as part of a `devDependencies` in `package.json`\n */\n get dev(): boolean {\n return this.type === 'dev'\n }\n\n get optional(): boolean {\n return this.type === 'peerOptional' || this.type === 'optional'\n }\n\n get peer(): boolean {\n return this.type === 'peer' || this.type === 'peerOptional'\n }\n\n get peerOptional(): boolean {\n return this.type === 'peerOptional'\n }\n\n valid(): boolean {\n return !this.to ?\n this.optional\n : satisfies(\n this.to.id,\n this.spec,\n this.from.location,\n this.from.projectRoot,\n )\n }\n}\n"]}
1
+ {"version":3,"file":"edge.js","sourceRoot":"","sources":["../../src/edge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;AAE/D,MAAM,OAAO,IAAI;IACf,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,oBAAoB,CAA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IAED,KAAK;QACH,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACb,IAAI,CAAC,QAAQ;YACf,CAAC,CAAC,SAAS,CACP,IAAI,CAAC,EAAE,CAAC,EAAE,EACV,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,CAAC,QAAQ,EAClB,IAAI,CAAC,IAAI,CAAC,WAAW,CACtB,CAAA;IACP,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YAClB,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;SACxB,CAAA;IACH,CAAC;IAED,QAAQ;QACN,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAA;QACvD,OAAO,cAAc,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI,CAAC,IAAI,QAAQ,EAAE,EAAE,CAAA;IAC/D,CAAC;CACF","sourcesContent":["import { satisfies } from '@vltpkg/satisfies'\nimport type { Spec } from '@vltpkg/spec'\nimport { inspect } from 'node:util'\nimport type { InspectOptions } from 'node:util'\nimport type { DependencyTypeShort, EdgeLike } from '@vltpkg/types'\nimport type { Node } from './node.ts'\n\nconst kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport class Edge implements EdgeLike {\n get [Symbol.toStringTag]() {\n return '@vltpkg/graph.Edge'\n }\n\n [kCustomInspect](_: number, options: InspectOptions) {\n const str = inspect(\n {\n from: this.from.id,\n type: this.type,\n spec: String(this.spec),\n to: this.to?.id,\n },\n options,\n )\n return `${this[Symbol.toStringTag]} ${str}`\n }\n\n /**\n * The Node this Edge is connecting from, this is usually the dependent.\n */\n from: Node\n\n /**\n * The node this Edge is connecting to, this is usually a direct dependency.\n */\n to?: Node\n\n /**\n * What type of dependency relationship `from` and `to` nodes have.\n */\n type: DependencyTypeShort\n\n /**\n * The defined spec value for `to` as parsed from the dependent metadata.\n */\n spec: Spec\n\n constructor(\n type: DependencyTypeShort,\n spec: Spec,\n from: Node,\n to?: Node,\n ) {\n this.from = from\n this.to = to\n this.type = type\n this.spec = spec\n }\n\n /**\n * The name of the dependency `to` as defined in the dependent metadata.\n */\n get name() {\n return this.spec.name\n }\n\n /**\n * This edge was defined as part of a `devDependencies` in `package.json`\n */\n get dev(): boolean {\n return this.type === 'dev'\n }\n\n get optional(): boolean {\n return this.type === 'peerOptional' || this.type === 'optional'\n }\n\n get peer(): boolean {\n return this.type === 'peer' || this.type === 'peerOptional'\n }\n\n get peerOptional(): boolean {\n return this.type === 'peerOptional'\n }\n\n valid(): boolean {\n return !this.to ?\n this.optional\n : satisfies(\n this.to.id,\n this.spec,\n this.from.location,\n this.from.projectRoot,\n )\n }\n\n toJSON() {\n return {\n from: this.from.id,\n to: this.to?.id,\n type: this.type,\n spec: String(this.spec),\n }\n }\n\n toString() {\n const to = `${this.name}${this.to ? '' : ' (missing)'}`\n return `Edge from: ${this.from.id} --|${this.type}|--> ${to}`\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { Spec } from '@vltpkg/spec';
2
+ import type { Dependency } from './dependencies.ts';
3
+ import type { Manifest } from '@vltpkg/types';
4
+ import type { SpecOptions } from '@vltpkg/spec';
5
+ /**
6
+ * When adding new dependencies, it's very common to not have a dependency
7
+ * name directly available to reference, e.g: `file:local/folder` or
8
+ * `remote:tarball-url.tgz`. In these cases, a placeholder `(unknown)` name
9
+ * is used in the `Spec` object and the `add` Map structure that holds
10
+ * references to added dependencies will use the stringified spec as a key.
11
+ *
12
+ * This helper function fixes unknown names in the `add` map by replacing
13
+ * placeholder specs with the correct names from the provided manifest.
14
+ */
15
+ export declare const fixupAddedNames: (add: Map<string, Dependency> | undefined, manifest: Pick<Manifest, "name"> | undefined, options: SpecOptions, spec: Spec) => Spec;
16
+ //# sourceMappingURL=fixup-added-names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixup-added-names.d.ts","sourceRoot":"","sources":["../../src/fixup-added-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,QACrB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,YAC9B,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,SAAS,WACnC,WAAW,QACd,IAAI,KACT,IAkBF,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { Spec } from '@vltpkg/spec';
2
+ /**
3
+ * When adding new dependencies, it's very common to not have a dependency
4
+ * name directly available to reference, e.g: `file:local/folder` or
5
+ * `remote:tarball-url.tgz`. In these cases, a placeholder `(unknown)` name
6
+ * is used in the `Spec` object and the `add` Map structure that holds
7
+ * references to added dependencies will use the stringified spec as a key.
8
+ *
9
+ * This helper function fixes unknown names in the `add` map by replacing
10
+ * placeholder specs with the correct names from the provided manifest.
11
+ */
12
+ export const fixupAddedNames = (add, manifest, options, spec) => {
13
+ // Handle nameless dependencies
14
+ if (add && manifest?.name && spec.name === '(unknown)') {
15
+ const s = add.get(String(spec));
16
+ if (s) {
17
+ // removes the previous, placeholder entry key
18
+ add.delete(String(spec));
19
+ // replaces spec with a version with the correct name
20
+ spec = Spec.parse(manifest.name, spec.bareSpec, options);
21
+ // updates the add map with the fixed up spec
22
+ const n = {
23
+ type: s.type,
24
+ spec,
25
+ };
26
+ add.set(manifest.name, n);
27
+ }
28
+ }
29
+ return spec;
30
+ };
31
+ //# sourceMappingURL=fixup-added-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixup-added-names.js","sourceRoot":"","sources":["../../src/fixup-added-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAKnC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAAwC,EACxC,QAA4C,EAC5C,OAAoB,EACpB,IAAU,EACJ,EAAE;IACR,+BAA+B;IAC/B,IAAI,GAAG,IAAI,QAAQ,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACvD,MAAM,CAAC,GAA2B,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;QACvD,IAAI,CAAC,EAAE,CAAC;YACN,8CAA8C;YAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;YACxB,qDAAqD;YACrD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YACxD,6CAA6C;YAC7C,MAAM,CAAC,GAAG;gBACR,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,IAAI;aACL,CAAA;YACD,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QAC3B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { Spec } from '@vltpkg/spec'\nimport type { Dependency } from './dependencies.ts'\nimport type { Manifest } from '@vltpkg/types'\nimport type { SpecOptions } from '@vltpkg/spec'\n\n/**\n * When adding new dependencies, it's very common to not have a dependency\n * name directly available to reference, e.g: `file:local/folder` or\n * `remote:tarball-url.tgz`. In these cases, a placeholder `(unknown)` name\n * is used in the `Spec` object and the `add` Map structure that holds\n * references to added dependencies will use the stringified spec as a key.\n *\n * This helper function fixes unknown names in the `add` map by replacing\n * placeholder specs with the correct names from the provided manifest.\n */\nexport const fixupAddedNames = (\n add: Map<string, Dependency> | undefined,\n manifest: Pick<Manifest, 'name'> | undefined,\n options: SpecOptions,\n spec: Spec,\n): Spec => {\n // Handle nameless dependencies\n if (add && manifest?.name && spec.name === '(unknown)') {\n const s: Dependency | undefined = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(manifest.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = {\n type: s.type,\n spec,\n }\n add.set(manifest.name, n)\n }\n }\n return spec\n}\n"]}
@@ -1,19 +1,19 @@
1
1
  import type { DepID } from '@vltpkg/dep-id';
2
2
  import { Spec } from '@vltpkg/spec';
3
3
  import type { SpecOptions } from '@vltpkg/spec';
4
- import type { Manifest, DependencySaveType } from '@vltpkg/types';
4
+ import type { GraphLike, NodeLike, NormalizedManifest, DependencySaveType } from '@vltpkg/types';
5
5
  import type { Monorepo } from '@vltpkg/workspaces';
6
6
  import type { InspectOptions } from 'node:util';
7
- import type { Edge } from './edge.ts';
7
+ import { Edge } from './edge.ts';
8
8
  import { Node } from './node.ts';
9
- import type { GraphLike, NodeLike } from './types.ts';
9
+ import type { PeerContext } from './ideal/types.ts';
10
10
  declare const kCustomInspect: unique symbol;
11
- export type ManifestInventory = Map<DepID, Manifest>;
11
+ export type ManifestInventory = Map<DepID, NormalizedManifest>;
12
12
  export type GraphOptions = SpecOptions & {
13
13
  /**
14
14
  * The main importer manifest info.
15
15
  */
16
- mainManifest: Manifest;
16
+ mainManifest: NormalizedManifest;
17
17
  /**
18
18
  * An inventory of seen manifests.
19
19
  */
@@ -74,9 +74,21 @@ export declare class Graph implements GraphLike {
74
74
  * The root of the project this graph represents
75
75
  */
76
76
  projectRoot: string;
77
+ /**
78
+ * The peer context sets used to resolve peer dependencies within this graph.
79
+ */
80
+ peerContexts: PeerContext[];
81
+ /**
82
+ * Tracks the current peer context index.
83
+ */
84
+ currentPeerContextIndex: number;
77
85
  constructor(options: GraphOptions);
78
86
  /**
79
- * Delete all nodes that are unreachable from the importers.
87
+ * Get the next peer context index.
88
+ */
89
+ nextPeerContextIndex(): number;
90
+ /**
91
+ * Delete all nodes and edges that are unreachable from the importers.
80
92
  * The collection of deleted nodes is returned.
81
93
  *
82
94
  * NOTE: This can be extremely slow for large graphs, and is almost always
@@ -94,11 +106,11 @@ export declare class Graph implements GraphLike {
94
106
  /**
95
107
  * Find an existing node to satisfy a dependency
96
108
  */
97
- findResolution(spec: Spec, fromNode: Node): Node | undefined;
109
+ findResolution(spec: Spec, fromNode: Node, extra?: string): Node | undefined;
98
110
  /**
99
111
  * Create a new node in the graph.
100
112
  */
101
- addNode(id?: DepID, manifest?: Manifest, spec?: Spec, name?: string, version?: string): Node;
113
+ addNode(id?: DepID, manifest?: NormalizedManifest, spec?: Spec, name?: string, version?: string): Node;
102
114
  /**
103
115
  * Place a new package into the graph representation, creating the new
104
116
  * edges and possibly new nodes that are to be expected when traversing
@@ -107,15 +119,27 @@ export declare class Graph implements GraphLike {
107
119
  * For different uses that are not a direct top-down traversal of the graph
108
120
  * consider using `addNode()` and `addEdge()` instead.
109
121
  */
110
- placePackage(fromNode: Node, depType: DependencySaveType, spec: Spec, manifest?: Manifest, id?: DepID): Node | undefined;
122
+ placePackage(fromNode: Node, depType: DependencySaveType, spec: Spec, manifest?: NormalizedManifest, id?: DepID, extra?: string): Node | undefined;
111
123
  /**
112
124
  * Removes a node and its relevant edges from the graph.
113
125
  *
126
+ * Use the `keepEdges` option to keep the edges that were pointing to
127
+ * this node and only removes their `to` property value.
128
+ *
114
129
  * If a replacement is provided, then any edges that were previously
115
130
  * pointing to the removed node will be directed to the replacement,
116
131
  * if it is valid to do so.
117
132
  */
118
- removeNode(node: Node, replacement?: Node): void;
133
+ removeNode(node: Node, replacement?: Node, keepEdges?: boolean): void;
134
+ /**
135
+ * Removes the resolved node of a given edge.
136
+ */
137
+ removeEdgeResolution(edge: Edge, extra?: string): void;
138
+ /**
139
+ * Remove all edges from the graph while preserving nodes and resolution caches.
140
+ * This allows the graph to be reconstructed efficiently using the existing nodes.
141
+ */
142
+ resetEdges(): void;
119
143
  toJSON(): import("./index.ts").LockfileData;
120
144
  [kCustomInspect](_: number, options: InspectOptions): string;
121
145
  }
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/graph.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAG3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrD,QAAA,MAAM,cAAc,eAA2C,CAAA;AAM/D,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAKpD,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACvC;;OAEG;IACH,YAAY,EAAE,QAAQ,CAAA;IACtB;;OAEG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,KAAM,YAAW,SAAS;;IACrC,IAAI,CAAC,M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IAiBV,MAAM;IAQN,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;CAIpD"}
package/dist/esm/graph.js CHANGED
@@ -1,16 +1,37 @@
1
- import { getId, joinDepIDTuple } from '@vltpkg/dep-id';
1
+ import { getId, joinDepIDTuple, splitExtra } from '@vltpkg/dep-id';
2
2
  import { error } from '@vltpkg/error-cause';
3
3
  import { satisfies } from '@vltpkg/satisfies';
4
- import { Spec } from '@vltpkg/spec';
4
+ import { getOptions, Spec } from '@vltpkg/spec';
5
5
  import { inspect } from 'node:util';
6
6
  import { lockfileData } from "./lockfile/save.js";
7
+ import { Edge } from "./edge.js";
7
8
  import { Node } from "./node.js";
8
9
  import { resolveSaveType } from "./resolve-save-type.js";
9
10
  const kCustomInspect = Symbol.for('nodejs.util.inspect.custom');
11
+ const cacheKeySeparator = '│';
10
12
  // this is always the same, but we don't hard code it as a string,
11
13
  // in case the DepID module needs to change its delimiter again ever.
12
14
  const mainDepID = joinDepIDTuple(['file', '.']);
13
15
  const getMap = (m) => m ?? new Map();
16
+ /**
17
+ * Get a cache key for a resolution based on the
18
+ * spec, location and query modifier.
19
+ */
20
+ const getResolutionCacheKey = (spec, location, extra) => {
21
+ const f = spec.final;
22
+ // if it's a file: dep, then the fromNode location matters
23
+ const fromPrefix = f.type === 'file' ? location + ' : ' : '';
24
+ // the unique key should also precise what is the type of the spec,
25
+ // and in the case of a registry, what registry it is from.
26
+ const typePrecisionKey = f.registry ?
27
+ `${cacheKeySeparator}registry` +
28
+ `${cacheKeySeparator}${f.registry}`
29
+ : f.gitRemote ?
30
+ `${cacheKeySeparator}git` + `${cacheKeySeparator}${f.gitRemote}`
31
+ : `${cacheKeySeparator}${f.type}`;
32
+ const modifierSuffix = `${cacheKeySeparator}${extra}`;
33
+ return fromPrefix + String(f) + typePrecisionKey + modifierSuffix;
34
+ };
14
35
  export class Graph {
15
36
  get [Symbol.toStringTag]() {
16
37
  return '@vltpkg/graph.Graph';
@@ -61,13 +82,33 @@ export class Graph {
61
82
  * The root of the project this graph represents
62
83
  */
63
84
  projectRoot;
85
+ /**
86
+ * The peer context sets used to resolve peer dependencies within this graph.
87
+ */
88
+ peerContexts;
89
+ /**
90
+ * Tracks the current peer context index.
91
+ */
92
+ currentPeerContextIndex = 0;
64
93
  constructor(options) {
65
94
  const { mainManifest, monorepo } = options;
66
95
  this.#options = options;
96
+ // hydrate spec options to their full contents, including defaults
97
+ const specOptions = getOptions({
98
+ registry: options.registry,
99
+ registries: options.registries,
100
+ 'git-hosts': options['git-hosts'],
101
+ 'git-host-archives': options['git-host-archives'],
102
+ 'scope-registries': options['scope-registries'],
103
+ 'jsr-registries': options['jsr-registries'],
104
+ catalog: options.catalog,
105
+ catalogs: options.catalogs,
106
+ });
67
107
  this.manifests = getMap(options.manifests);
68
108
  this.projectRoot = options.projectRoot;
69
109
  this.#nodeOptions = {
70
110
  ...this.#options,
111
+ ...specOptions,
71
112
  graph: this,
72
113
  };
73
114
  // add the project root node
@@ -77,6 +118,7 @@ export class Graph {
77
118
  mainImporter.setImporterLocation(mainImporterLocation);
78
119
  mainImporter.mainImporter = true;
79
120
  this.mainImporter = mainImporter;
121
+ this.mainImporter.workspaces = new Map();
80
122
  this.importers.add(mainImporter);
81
123
  this.manifests.set(mainImporter.id, mainManifest);
82
124
  // uses the monorepo instance in order to retrieve info on
@@ -90,11 +132,24 @@ export class Graph {
90
132
  this.manifests.set(wsNode.id, wsNode.manifest);
91
133
  }
92
134
  this.importers.add(wsNode);
135
+ // creates a virtual edge to connect the workspaces to the root node
136
+ const edge = new Edge('prod', Spec.parse(wsNode.name, 'workspace:*', this.#options), this.mainImporter, wsNode);
137
+ this.mainImporter.workspaces.set(wsNode.name, edge);
93
138
  }
94
139
  }
140
+ // initializes the peer context set collection
141
+ const initialPeerContext = new Map();
142
+ initialPeerContext.index = this.currentPeerContextIndex;
143
+ this.peerContexts = [initialPeerContext];
144
+ }
145
+ /**
146
+ * Get the next peer context index.
147
+ */
148
+ nextPeerContextIndex() {
149
+ return ++this.currentPeerContextIndex;
95
150
  }
96
151
  /**
97
- * Delete all nodes that are unreachable from the importers.
152
+ * Delete all nodes and edges that are unreachable from the importers.
98
153
  * The collection of deleted nodes is returned.
99
154
  *
100
155
  * NOTE: This can be extremely slow for large graphs, and is almost always
@@ -104,13 +159,16 @@ export class Graph {
104
159
  */
105
160
  gc() {
106
161
  const { nodes } = this;
162
+ this.edges.clear();
107
163
  this.nodes = new Map();
108
164
  const marked = new Set(this.importers);
109
165
  for (const imp of marked) {
110
166
  // don't delete the importer!
111
167
  nodes.delete(imp.id);
112
168
  this.nodes.set(imp.id, imp);
113
- for (const { to } of imp.edgesOut.values()) {
169
+ for (const edge of imp.edgesOut.values()) {
170
+ this.edges.add(edge);
171
+ const { to } = edge;
114
172
  if (!to || marked.has(to))
115
173
  continue;
116
174
  marked.add(to);
@@ -145,6 +203,9 @@ export class Graph {
145
203
  if (edge.type === type &&
146
204
  edge.spec.bareSpec === spec.bareSpec) {
147
205
  if (to && to !== edge.to) {
206
+ // removes this edge from its destination edgesIn ref
207
+ edge.to?.edgesIn.delete(edge);
208
+ // now swap the destination to the new one
148
209
  edge.to = to;
149
210
  edge.to.edgesIn.add(edge);
150
211
  }
@@ -160,11 +221,9 @@ export class Graph {
160
221
  /**
161
222
  * Find an existing node to satisfy a dependency
162
223
  */
163
- findResolution(spec, fromNode) {
224
+ findResolution(spec, fromNode, extra = '') {
164
225
  const f = spec.final;
165
- // if it's a file: dep, then the fromNode location matters
166
- const fromPref = f.type === 'file' ? fromNode.location + ' : ' : '';
167
- const sf = fromPref + String(f);
226
+ const sf = getResolutionCacheKey(f, fromNode.location, extra);
168
227
  const cached = this.resolutions.get(sf);
169
228
  if (cached)
170
229
  return cached;
@@ -188,18 +247,10 @@ export class Graph {
188
247
  this.nodes.set(node.id, node);
189
248
  const nbn = this.nodesByName.get(node.name) ?? new Set();
190
249
  nbn.add(node);
191
- this.nodesByName.set(node.name, nbn);
192
- if (spec) {
193
- const f = String(spec.final);
194
- // if it's a file: type, then that is fromNode-specific,
195
- // so we can't shortcut add it here.
196
- if (spec.final.type !== 'file') {
197
- this.resolutions.set(f, node);
198
- const rrev = this.resolutionsReverse.get(node) ?? new Set();
199
- rrev.add(f);
200
- this.resolutionsReverse.set(node, rrev);
201
- }
202
- }
250
+ // ensure the nodes by name set is always sorted, this will help
251
+ // keeping a deterministic graph resolution when reusing nodes
252
+ const newByNameSet = new Set([...nbn].sort((a, b) => a.id.localeCompare(b.id)));
253
+ this.nodesByName.set(node.name, newByNameSet);
203
254
  if (manifest) {
204
255
  this.manifests.set(node.id, manifest);
205
256
  }
@@ -213,7 +264,7 @@ export class Graph {
213
264
  * For different uses that are not a direct top-down traversal of the graph
214
265
  * consider using `addNode()` and `addEdge()` instead.
215
266
  */
216
- placePackage(fromNode, depType, spec, manifest, id) {
267
+ placePackage(fromNode, depType, spec, manifest, id, extra) {
217
268
  // if no manifest is available, then create an edge that has no
218
269
  // reference to any other node, representing a missing dependency
219
270
  if (!manifest && !id) {
@@ -227,7 +278,7 @@ export class Graph {
227
278
  depType === 'optional' ||
228
279
  depType === 'peerOptional',
229
280
  };
230
- const depId = id || (manifest && getId(spec, manifest));
281
+ const depId = id || (manifest && getId(spec, manifest, extra));
231
282
  /* c8 ignore start - should not be possible */
232
283
  if (!depId) {
233
284
  throw error('Could not find dep id when placing package', {
@@ -243,26 +294,62 @@ export class Graph {
243
294
  this.addEdge(depType, spec, fromNode, toFoundNode);
244
295
  // the current only stays dev/optional if this dep lets it remain so
245
296
  // if it's not already, we don't make it dev or optional.
297
+ toFoundNode.detached = false;
246
298
  toFoundNode.dev &&= flags.dev;
247
299
  toFoundNode.optional &&= flags.optional;
248
300
  return toFoundNode;
249
301
  }
250
302
  // creates a new node and edges to its parent
251
- const toNode = this.addNode(depId, manifest);
303
+ const toNode = this.addNode(depId, manifest, spec);
252
304
  toNode.registry = spec.registry;
253
305
  toNode.dev = flags.dev;
254
306
  toNode.optional = flags.optional;
307
+ // split extra into modifier and peerSetHash
308
+ if (extra) {
309
+ const { modifier, peerSetHash } = splitExtra(extra);
310
+ toNode.modifier = modifier;
311
+ toNode.peerSetHash = peerSetHash;
312
+ }
313
+ // add extra manifest info if available
314
+ if (manifest) {
315
+ const { bin, engines, os, cpu } = manifest;
316
+ // add platform info if available
317
+ if (engines || os || cpu) {
318
+ const platform = {};
319
+ if (engines)
320
+ platform.engines = engines;
321
+ if (os)
322
+ platform.os = os;
323
+ if (cpu)
324
+ platform.cpu = cpu;
325
+ toNode.platform = platform;
326
+ }
327
+ // add bin info if available
328
+ if (bin) {
329
+ toNode.bins = bin;
330
+ }
331
+ }
332
+ toNode.maybeSetConfusedManifest(spec, manifest);
255
333
  this.addEdge(depType, spec, fromNode, toNode);
334
+ // populate resolution cache if applicable
335
+ const f = getResolutionCacheKey(spec.final, fromNode.location, extra || '');
336
+ this.resolutions.set(f, toNode);
337
+ const rrev = this.resolutionsReverse.get(toNode) ?? new Set();
338
+ rrev.add(f);
339
+ this.resolutionsReverse.set(toNode, rrev);
256
340
  return toNode;
257
341
  }
258
342
  /**
259
343
  * Removes a node and its relevant edges from the graph.
260
344
  *
345
+ * Use the `keepEdges` option to keep the edges that were pointing to
346
+ * this node and only removes their `to` property value.
347
+ *
261
348
  * If a replacement is provided, then any edges that were previously
262
349
  * pointing to the removed node will be directed to the replacement,
263
350
  * if it is valid to do so.
264
351
  */
265
- removeNode(node, replacement) {
352
+ removeNode(node, replacement, keepEdges) {
266
353
  this.nodes.delete(node.id);
267
354
  const nbn = this.nodesByName.get(node.name);
268
355
  // if it's the last one, just remove the set
@@ -283,12 +370,51 @@ export class Graph {
283
370
  satisfies(replacement.id, edge.spec, edge.from.location, this.projectRoot, this.monorepo)) {
284
371
  edge.to = replacement;
285
372
  }
373
+ else if (keepEdges) {
374
+ edge.to = undefined;
375
+ }
286
376
  else {
287
377
  edge.from.edgesOut.delete(edge.spec.name);
288
378
  this.edges.delete(edge);
289
379
  }
290
380
  }
291
381
  }
382
+ /**
383
+ * Removes the resolved node of a given edge.
384
+ */
385
+ removeEdgeResolution(edge, extra = '') {
386
+ const node = edge.to;
387
+ const resolutionKey = getResolutionCacheKey(edge.spec, edge.from.location, extra);
388
+ if (node) {
389
+ edge.to = undefined;
390
+ this.resolutions.delete(resolutionKey);
391
+ this.resolutionsReverse.get(node)?.delete(resolutionKey);
392
+ this.nodesByName.delete(node.name);
393
+ node.edgesIn.delete(edge);
394
+ if (node.edgesIn.size === 0) {
395
+ this.nodes.delete(node.id);
396
+ }
397
+ }
398
+ }
399
+ /**
400
+ * Remove all edges from the graph while preserving nodes and resolution caches.
401
+ * This allows the graph to be reconstructed efficiently using the existing nodes.
402
+ */
403
+ resetEdges() {
404
+ // Clear the global edges set
405
+ this.edges.clear();
406
+ // Clear all node edge relationships
407
+ for (const node of this.nodes.values()) {
408
+ // marking nodes as detached needs to be restricted to only those
409
+ // that had a manifest, otherwise we'd be skipping fetching manifest
410
+ // for nodes we don't have a manifest during the ideal build phase
411
+ if (node.manifest)
412
+ node.detached = true;
413
+ // detaches all edges from this node
414
+ node.edgesOut.clear();
415
+ node.edgesIn.clear();
416
+ }
417
+ }
292
418
  toJSON() {
293
419
  return lockfileData({
294
420
  ...this.#options,