@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":"append-nodes.js","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAGnD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAQvE;;;GAGG;A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MAAM,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAChB,WAAW,CACT,GAAG,EACH,WAAW,EACX,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,CACL,CACF,CAAA;QACH,CAAC;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport type { DependencyTypeLong } from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { asDependency, shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\nexport const appendNodes = async (\n add: Map<string, Dependency>,\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n await Promise.all(\n deps.map(async ({ spec, type }) => {\n // see if there's a satisfying node in the graph currently\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const existingNode = graph.findResolution(spec, fromNode)\n if (existingNode) {\n graph.addEdge(type, spec, fromNode, existingNode)\n return\n }\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n const mani = await packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n // when an user is adding a nameless dependency, e.g: `github:foo/bar`,\n // `file:./foo/bar`, we need to update the `add` option value to set the\n // correct name once we have it, so that it can properly be stored in\n // the `package.json` file at the end of reify.\n if (mani?.name && spec.name === '(unknown)') {\n const s = add.get(String(spec))\n if (s) {\n // removes the previous, placeholder entry key\n add.delete(String(spec))\n // replaces spec with a version with the correct name\n spec = Spec.parse(mani.name, spec.bareSpec, options)\n // updates the add map with the fixed up spec\n const n = asDependency({\n ...s,\n spec,\n })\n add.set(mani.name, n)\n }\n }\n\n if (!mani) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n return\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n return\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n mani,\n fileTypeInfo?.id,\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n const nestedAppends: Promise<unknown>[] = []\n\n const bundleDeps = node.manifest?.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n const nextDeps: Dependency[] = []\n\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n mani[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n if (bundled.has(name)) continue\n nextDeps.push({\n type: shorten(depTypeName, name, mani),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n })\n }\n }\n }\n\n if (nextDeps.length) {\n nestedAppends.push(\n appendNodes(\n add,\n packageInfo,\n graph,\n node,\n nextDeps,\n scurry,\n options,\n seen,\n ),\n )\n }\n await Promise.all(nestedAppends)\n }),\n )\n}\n"]}
1
+ {"version":3,"file":"append-nodes.js","sourceRoot":"","sources":["../../../src/ideal/append-nodes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAOtE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAA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oBACpD,aAAa,CAAC,IAAI,CAAC;wBACjB,GAAG,QAAQ;wBACX,KAAK,EAAE,YAAY,GAAG,CAAC;qBACxB,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,gBAAgB,GAAG,aAAa,CAAA;IAClC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { joinDepIDTuple, joinExtra } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { longDependencyTypes, normalizeManifest } from '@vltpkg/types'\nimport type {\n DependencyTypeLong,\n DependencySaveType,\n Manifest,\n} from '@vltpkg/types'\nimport type { PathScurry } from 'path-scurry'\nimport { fixupAddedNames } from '../fixup-added-names.ts'\nimport { shorten } from '../dependencies.ts'\nimport type { Dependency } from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport type { Node } from '../node.ts'\nimport { removeOptionalSubgraph } from '../remove-optional-subgraph.ts'\nimport type {\n GraphModifier,\n ModifierActiveEntry,\n} from '../modifiers.ts'\nimport type { ExtractResult } from '../reify/extract-node.ts'\nimport { extractNode } from '../reify/extract-node.ts'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport {\n endPeerPlacement,\n postPlacementPeerCheck,\n startPeerPlacement,\n} from './peers.ts'\nimport type {\n PeerContext,\n AppendNodeEntry,\n ProcessPlacementResult,\n TransientAddMap,\n TransientRemoveMap,\n} from './types.ts'\n\ntype FileTypeInfo = {\n id: DepID\n path: string\n isDirectory: boolean\n}\n\n/**\n * Only install devDeps for git dependencies and importers\n * Everything else always gets installed\n */\nconst shouldInstallDepType = (\n node: Node,\n depType: DependencyTypeLong,\n) =>\n depType !== 'devDependencies' ||\n node.importer ||\n node.id.startsWith('git')\n\n/**\n * Retrieve the {@link DepID} and location for a `file:` type {@link Node}.\n */\nconst getFileTypeInfo = (\n spec: Spec,\n fromNode: Node,\n scurry: PathScurry,\n): FileTypeInfo | undefined => {\n const f = spec.final\n if (f.type !== 'file') return\n\n /* c8 ignore start - should be impossible */\n if (!f.file) {\n throw error('no path on file specifier', { spec })\n }\n /* c8 ignore stop */\n\n // Given that both linked folders and local tarballs (both defined with\n // usage of the `file:` spec prefix) location needs to be relative to their\n // parents, build the expected path and use it for both location and id\n const target = scurry.cwd.resolve(fromNode.location).resolve(f.file)\n const path = target.relativePosix()\n const id = joinDepIDTuple(['file', path])\n\n return {\n path,\n id,\n isDirectory: !!target.lstatSync()?.isDirectory(),\n }\n}\n\nconst isStringArray = (a: unknown): a is string[] =>\n Array.isArray(a) && !a.some(b => typeof b !== 'string')\n\n/**\n * Represents a manifest fetch operation with all the context needed.\n */\ntype ManifestFetchTask = {\n spec: Spec\n type: DependencySaveType\n fromNode: Node\n fileTypeInfo?: FileTypeInfo\n activeModifier?: ModifierActiveEntry\n queryModifier?: string\n edgeOptional: boolean\n manifestPromise: Promise<Manifest | undefined>\n depth: number\n peerContext: PeerContext\n}\n\n/**\n * Represents a node placement operation that depends on a resolved manifest.\n */\ntype NodePlacementTask = {\n fetchTask: ManifestFetchTask\n manifest: Manifest | undefined\n node?: Node\n childDeps?: Dependency[]\n childModifierRefs?: Map<string, ModifierActiveEntry>\n childPeerContext?: PeerContext\n}\n\n/**\n * Fetch manifests for dependencies and create placement tasks.\n */\nconst fetchManifestsForDeps = async (\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n peerContext: PeerContext,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n depth = 0,\n): Promise<NodePlacementTask[]> => {\n // Create fetch tasks for all dependencies at this level\n const fetchTasks: ManifestFetchTask[] = []\n const placementTasks: NodePlacementTask[] = []\n\n for (const { spec: originalSpec, type } of deps) {\n let spec = originalSpec\n const fileTypeInfo = getFileTypeInfo(spec, fromNode, scurry)\n const activeModifier = modifierRefs?.get(spec.name)\n\n // here is the place we swap specs if a edge modifier was defined\n const queryModifier = activeModifier?.modifier.query\n const completeModifier =\n activeModifier &&\n activeModifier.interactiveBreadcrumb.current ===\n activeModifier.modifier.breadcrumb.last\n if (\n queryModifier &&\n completeModifier &&\n 'spec' in activeModifier.modifier\n ) {\n spec = activeModifier.modifier.spec\n if (spec.bareSpec === '-') {\n continue\n }\n }\n\n const peer = type === 'peer' || type === 'peerOptional'\n\n // skip reusing nodes for peer deps since their reusability\n // is handled ahead-of-time during its parent's placement\n const existingNode = graph.findResolution(\n spec,\n fromNode,\n queryModifier,\n )\n // defines what nodes are eligible to be reused\n const validExistingNode =\n existingNode &&\n !existingNode.detached &&\n // Regular deps can always reuse\n /* c8 ignore start */\n (!peer ||\n // otherwise reusing peer deps only in case of a peerSetHash matche\n existingNode.peerSetHash === fromNode.peerSetHash)\n /* c8 ignore stop */\n\n if (\n validExistingNode ||\n // importers are handled at the ./add-nodes.ts top-level\n // so we should just skip whenever we find one\n existingNode?.importer\n ) {\n graph.addEdge(type, spec, fromNode, existingNode)\n continue\n }\n\n // is the current edge pointint go an optional dependency?\n const edgeOptional =\n type === 'optional' || type === 'peerOptional'\n\n // Start manifest fetch immediately for parallel processing\n const manifestPromise =\n // the \"detached\" node state means that it has already been load as\n // part of a graph (either lockfile or actual) and it has valid manifest\n // data so we shortcut the package info manifest fetch here\n existingNode?.detached ?\n Promise.resolve(existingNode.manifest as Manifest | undefined)\n // this is the entry point to fetch calls to retrieve manifests\n // from the build ideal graph point of view\n : packageInfo\n .manifest(spec, { from: scurry.resolve(fromNode.location) })\n .then(manifest => manifest as Manifest | undefined)\n .catch((er: unknown) => {\n // optional deps ignored if inaccessible\n if (edgeOptional || fromNode.optional) {\n return undefined\n }\n throw er\n })\n\n const fetchTask: ManifestFetchTask = {\n spec,\n type,\n fromNode,\n fileTypeInfo,\n activeModifier,\n queryModifier,\n edgeOptional,\n manifestPromise,\n depth,\n peerContext,\n }\n\n fetchTasks.push(fetchTask)\n }\n\n // Create placement tasks from fetch tasks\n for (const fetchTask of fetchTasks) {\n const manifest = await fetchTask.manifestPromise\n\n placementTasks.push({\n fetchTask,\n manifest,\n })\n }\n\n // sort placement tasks: non-peer dependencies first, then peer dependencies\n // so that peer dependencies can easily reuse already placed regular\n // dependencies as part of peer context set resolution also makes sure to\n // sort by the manifest name for deterministic order.\n placementTasks.sort((a, b) => {\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 // regular dependencies first, peer dependencies last\n if (aIsPeer !== bIsPeer) {\n return aIsPeer - bIsPeer\n }\n\n // if both are in the same group,\n // sort alphabetically by manifest name (fallback to spec.name)\n const aName =\n a.manifest?.name /* c8 ignore next */ || a.fetchTask.spec.name\n const bName = b.manifest?.name || b.fetchTask.spec.name\n return aName.localeCompare(bName, 'en')\n })\n\n return placementTasks\n}\n\n/**\n * Process placement tasks and collect child dependencies, this is the\n * second step of the appendNodes operation after manifest fetching in\n * which the final graph data structure is actually built.\n */\nconst processPlacementTasks = async (\n graph: Graph,\n options: SpecOptions,\n placementTasks: NodePlacementTask[],\n add?: Map<string, Dependency>,\n modifiers?: GraphModifier,\n scurry?: PathScurry,\n packageInfo?: PackageInfoClient,\n extractPromises?: Promise<ExtractResult>[],\n actual?: Graph,\n seenExtracted?: Set<DepID>,\n remover?: RollbackRemove,\n transientAdd?: TransientAddMap,\n transientRemove?: TransientRemoveMap,\n): Promise<ProcessPlacementResult> => {\n const childDepsToProcess: ProcessPlacementResult = []\n\n for (const placementTask of placementTasks) {\n const { fetchTask, manifest } = placementTask\n let {\n activeModifier,\n edgeOptional,\n fileTypeInfo,\n fromNode,\n peerContext,\n queryModifier,\n spec,\n type,\n } = fetchTask\n\n // fix the name in the `add` map when needed. This allows the upcoming\n // reify step to properly update the package.json file dependencies\n // using the correct names retrieved from the manifest data\n const additiveMap =\n fromNode.importer ? add : transientAdd?.get(fromNode.id)\n spec = fixupAddedNames(additiveMap, manifest, options, spec)\n\n // handles missing manifest resolution\n if (!manifest) {\n if (!edgeOptional && fromNode.isOptional()) {\n // failed resolution of a non-optional dep of an optional node\n // have to clean up the dependents\n removeOptionalSubgraph(graph, fromNode)\n continue\n } else if (edgeOptional) {\n // failed resolution of an optional dep, just ignore it,\n // nothing to prune because we never added it in the first place.\n continue\n } else {\n throw error('failed to resolve dependency', {\n spec,\n from: fromNode.location,\n })\n }\n }\n\n // start peer deps placement process, populating the peer context with\n // dependency data; adding the parent node deps and this manifest's\n // peer deps references to the current peer context set\n const peerPlacement = startPeerPlacement(\n peerContext,\n manifest,\n fromNode,\n options,\n )\n const peerSetHash = peerPlacement.peerSetHash\n const queuedEntries = peerPlacement.queuedEntries\n\n // places a new node in the graph representing a newly seen dependency\n const node = graph.placePackage(\n fromNode,\n type,\n spec,\n normalizeManifest(manifest),\n fileTypeInfo?.id,\n joinExtra({ peerSetHash, modifier: queryModifier }),\n )\n\n /* c8 ignore start - not possible, already ensured manifest */\n if (!node) {\n throw error('failed to place package', {\n from: fromNode.location,\n spec,\n })\n }\n /* c8 ignore stop */\n\n // update the node modifier tracker\n if (activeModifier) {\n modifiers?.updateActiveEntry(node, activeModifier)\n }\n\n const eligibleForExtraction =\n type !== 'peer' &&\n type !== 'peerOptional' &&\n remover &&\n extractPromises &&\n actual &&\n scurry &&\n packageInfo &&\n node.inVltStore() &&\n !node.isOptional() &&\n // this fixes an issue with installing `file:pathname` specs\n /* c8 ignore next */ !fileTypeInfo?.isDirectory &&\n !node.importer\n\n // extract the node if it meets the criteria for early extraction\n if (eligibleForExtraction) {\n /* c8 ignore start */\n if (seenExtracted?.has(node.id)) {\n continue\n }\n /* c8 ignore stop */\n seenExtracted?.add(node.id)\n const actualNode = actual.nodes.get(node.id)\n if (!actualNode?.equals(node)) {\n // extract the node without awaiting - push the promise to the array\n const extractPromise = extractNode(\n node,\n scurry,\n remover,\n options,\n packageInfo,\n )\n extractPromises.push(extractPromise)\n }\n }\n\n // updates graph node information\n if (fileTypeInfo?.path && fileTypeInfo.isDirectory) {\n node.location = fileTypeInfo.path\n }\n node.setResolved()\n\n // collect child dependencies for processing in the next level\n const nextPeerDeps = new Map<string, Dependency>()\n\n // compute deps normally\n const bundleDeps = manifest.bundleDependencies\n const bundled = new Set<string>(\n (\n node.id.startsWith('git') ||\n node.importer ||\n !isStringArray(bundleDeps)\n ) ?\n []\n : bundleDeps,\n )\n\n // setup next level to process all child dependencies in the manifest\n const nextDeps: Dependency[] = []\n\n // traverse actual dependency declarations in the manifest\n // creating dependency entries for them\n for (const depTypeName of longDependencyTypes) {\n const depRecord: Record<string, string> | undefined =\n manifest[depTypeName]\n\n if (depRecord && shouldInstallDepType(node, depTypeName)) {\n for (const [name, bareSpec] of Object.entries(depRecord)) {\n // might need to skip already placed peer deps here\n if (bundled.has(name)) continue\n const dep = {\n type: shorten(depTypeName, name, manifest),\n spec: Spec.parse(name, bareSpec, {\n ...options,\n registry: spec.registry,\n }),\n }\n if (depTypeName === 'peerDependencies') {\n nextPeerDeps.set(name, dep)\n } else {\n nextDeps.push(dep)\n }\n }\n }\n }\n\n // Inject transient dependencies for non-importer nodes (nested folders)\n // These are deps that were added from a nested folder context using\n // relative file: specs that should resolve relative to that folder\n const transientDeps = transientAdd?.get(node.id)\n if (transientDeps) {\n for (const [, dep] of transientDeps) {\n if (dep.type === 'peer' || dep.type === 'peerOptional') {\n nextPeerDeps.set(dep.spec.name, dep)\n continue\n }\n\n // remove the dependency from nextDeps if it already exists\n const index = nextDeps.findIndex(\n d => d.spec.name === dep.spec.name,\n )\n if (index !== -1) {\n nextDeps.splice(index, 1)\n }\n\n nextDeps.push(dep)\n }\n }\n\n // Remove transient removals when needed\n const transientRemovals = transientRemove?.get(node.id)\n if (transientRemovals) {\n for (const depName of transientRemovals) {\n const index = nextDeps.findIndex(\n dep => dep.spec.name === depName,\n )\n if (index !== -1) {\n nextDeps.splice(index, 1)\n continue\n }\n\n if (nextPeerDeps.has(depName)) {\n nextPeerDeps.delete(depName)\n }\n }\n }\n\n // finish peer placement for this node, resolving satisfied peers\n // to seen nodes from the peer context and adding unsatisfied peers\n // to `nextDeps` so they get processed along regular dependencies\n const updateContext = endPeerPlacement(\n peerContext,\n nextDeps,\n nextPeerDeps,\n graph,\n spec,\n fromNode,\n node,\n type,\n queuedEntries,\n )\n\n childDepsToProcess.push({\n node,\n deps: nextDeps,\n modifierRefs: modifiers?.tryDependencies(node, nextDeps),\n peerContext,\n updateContext,\n })\n }\n\n return childDepsToProcess\n}\n\n/**\n * Append new nodes in the given `graph` for dependencies specified at `add`\n * and missing dependencies from the `deps` parameter.\n *\n * It also applies any modifiers that applies to a given node as it processes\n * and builds the graph.\n */\nexport const appendNodes = async (\n packageInfo: PackageInfoClient,\n graph: Graph,\n fromNode: Node,\n deps: Dependency[],\n scurry: PathScurry,\n options: SpecOptions,\n seen: Set<DepID>,\n add?: Map<string, Dependency>,\n modifiers?: GraphModifier,\n modifierRefs?: Map<string, ModifierActiveEntry>,\n extractPromises?: Promise<ExtractResult>[],\n actual?: Graph,\n seenExtracted?: Set<DepID>,\n remover?: RollbackRemove,\n transientAdd?: TransientAddMap,\n transientRemove?: TransientRemoveMap,\n) => {\n /* c8 ignore next */\n if (seen.has(fromNode.id)) return\n seen.add(fromNode.id)\n\n // Get the initial peer context from the graph\n const [initialPeerContext] = graph.peerContexts\n /* c8 ignore start - impossible */\n if (!initialPeerContext) {\n throw error('no initial peer context found in graph')\n }\n /* c8 ignore stop */\n\n // Use a queue for breadth-first processing\n let currentLevelDeps: AppendNodeEntry[] = [\n {\n node: fromNode,\n deps,\n modifierRefs,\n depth: 0,\n peerContext: initialPeerContext,\n /* c8 ignore start */\n updateContext: {\n putEntries: () => undefined,\n resolvePeerDeps: () => {},\n },\n /* c8 ignore stop */\n },\n ]\n\n while (currentLevelDeps.length > 0) {\n const nextLevelDeps: AppendNodeEntry[] = []\n\n // Process all nodes at the current level in parallel\n const levelResults = await Promise.all(\n currentLevelDeps.map(\n async ({\n node,\n deps: nodeDeps,\n modifierRefs: nodeModifierRefs,\n peerContext,\n depth,\n }: AppendNodeEntry) => {\n // Mark node as seen when we start processing its dependencies\n seen.add(node.id)\n\n // Fetch manifests for this node's dependencies\n const placementTasks = await fetchManifestsForDeps(\n packageInfo,\n graph,\n node,\n // Sort dependencies by spec.name for deterministic ordering\n nodeDeps.sort((a, b) =>\n a.spec.name.localeCompare(b.spec.name, 'en'),\n ),\n scurry,\n peerContext,\n nodeModifierRefs,\n depth,\n )\n\n // Process the placement tasks and get child dependencies\n return await processPlacementTasks(\n graph,\n options,\n placementTasks,\n add,\n modifiers,\n scurry,\n packageInfo,\n extractPromises,\n actual,\n seenExtracted,\n remover,\n transientAdd,\n transientRemove,\n )\n },\n ),\n )\n\n // Traverse the queued up children dependencies, adding and tracking\n // dependencies on the peer context set, forking the context as needed\n // and resolving any peer dependency that is able to be resolved using\n // the current peer context set\n postPlacementPeerCheck(graph, levelResults)\n\n // Collect all child dependencies for the next level\n for (const childDepsToProcess of levelResults) {\n for (const childDep of childDepsToProcess) {\n if (!seen.has(childDep.node.id)) {\n /* c8 ignore next */\n const currentDepth = currentLevelDeps[0]?.depth ?? 0\n nextLevelDeps.push({\n ...childDep,\n depth: currentDepth + 1,\n })\n }\n }\n }\n\n // Move to the next level\n currentLevelDeps = nextLevelDeps\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
+ import type { PackageJson } from '@vltpkg/package-json';
2
+ import type { RefreshIdealGraphOptions } from './refresh-ideal-graph.ts';
1
3
  import type { Graph } from '../graph.ts';
2
- import type { AddNodesOptions } from './add-nodes.ts';
3
- import type { RemoveNodesOptions } from './remove-nodes.ts';
4
- export type BuildIdealFromStartingGraphOptions = AddNodesOptions & RemoveNodesOptions & {
5
- projectRoot: string;
4
+ export type BuildIdealFromStartingGraphOptions = RefreshIdealGraphOptions & {
5
+ packageJson: PackageJson;
6
6
  };
7
7
  /**
8
8
  * Builds an ideal {@link Graph} representing the dependencies that
@@ -1 +1 @@
1
- {"version":3,"file":"build-ideal-from-starting-graph.d.ts","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,MAAM,MAAM,kCAAkC,GAAG,eAAe,GAC9D,kBAAkB,GAAG;IACnB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,YAC7B,kCAAkC,KAC1C,OAAO,CAAC,KAAK,CA+Cf,CAAA"}
1
+ {"version":3,"file":"build-ideal-from-starting-graph.d.ts","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,MAAM,kCAAkC,GAC5C,wBAAwB,GAAG;IACzB,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,YAC7B,kCAAkC,KAC1C,OAAO,CAAC,KAAK,CAmEf,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { getImporterSpecs } from "./get-importer-specs.js";
2
- import { addNodes } from "./add-nodes.js";
3
- import { removeNodes } from "./remove-nodes.js";
2
+ import { refreshIdealGraph } from "./refresh-ideal-graph.js";
3
+ import { resolveSaveType } from "../resolve-save-type.js";
4
4
  /**
5
5
  * Builds an ideal {@link Graph} representing the dependencies that
6
6
  * should be present in order to fulfill the requirements defined
@@ -21,30 +21,49 @@ export const buildIdealFromStartingGraph = async (options) => {
21
21
  options.remove.modifiedDependencies =
22
22
  options.remove.modifiedDependencies ||
23
23
  importerSpecs.remove.modifiedDependencies;
24
- // merge values found on importer specs with
24
+ // merge values found on node specs with
25
25
  // user-provided values from `options.add`
26
- for (const [importerId, deps] of importerSpecs.add) {
27
- if (!options.add.has(importerId)) {
28
- options.add.set(importerId, deps);
26
+ for (const [nodeId, deps] of importerSpecs.add) {
27
+ const node = options.graph.nodes.get(nodeId);
28
+ /* c8 ignore next - impossible */
29
+ if (!node)
30
+ continue;
31
+ if (!options.add.has(nodeId)) {
32
+ options.add.set(nodeId, deps);
29
33
  continue;
30
34
  }
31
- // merge any deps found when reading the importers manifest
35
+ // merge any deps found when reading the nodes manifest
32
36
  // with the ones provided by the user in the `add` options,
33
37
  // user-provided deps should take precedence
34
38
  for (const [depName, dep] of deps) {
35
- if (!options.add.get(importerId)?.has(depName)) {
36
- options.add.get(importerId)?.set(depName, dep);
39
+ if (!options.add.get(nodeId)?.has(depName)) {
40
+ options.add.get(nodeId)?.set(depName, dep);
37
41
  }
42
+ // update the save type for deps when using an implicit type
43
+ dep.type = resolveSaveType(node, depName, dep.type);
38
44
  }
39
45
  }
40
- // add nodes, fetching remote manifests for each dependency to be added
41
- await addNodes(options);
42
- // move things into their default locations, if possible
43
- for (const node of options.graph.nodes.values()) {
44
- node.setDefaultLocation();
46
+ // merge values found on node specs with
47
+ // user-provided values from `options.remove`
48
+ for (const [nodeId, deps] of importerSpecs.remove) {
49
+ if (!options.remove.has(nodeId)) {
50
+ options.remove.set(nodeId, deps);
51
+ continue;
52
+ }
53
+ // merge any deps found when reading the nodes manifest
54
+ // with the ones provided by the user in the `remove` options
55
+ for (const depName of deps) {
56
+ options.remove.get(nodeId)?.add(depName);
57
+ }
45
58
  }
46
- // removes any dependencies that are listed in the `remove` option
47
- removeNodes({ ...options, remove: importerSpecs.remove });
59
+ // refreshs the current graph adding the nodes marked for addition
60
+ // and removing the ones marked for removal, while also recalculating
61
+ // peer dependencies and default locations
62
+ await refreshIdealGraph({
63
+ ...options,
64
+ transientAdd: importerSpecs.transientAdd,
65
+ transientRemove: importerSpecs.transientRemove,
66
+ });
48
67
  options.graph.gc();
49
68
  return options.graph;
50
69
  };
@@ -1 +1 @@
1
- {"version":3,"file":"build-ideal-from-starting-graph.js","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAQ/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,OAA2C,EAC3B,EAAE;IAClB,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,oDAAoD;IACpD,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAE/C,mCAAmC;IACnC,OAAO,CAAC,GAAG,CAAC,oBAAoB;QAC9B,OAAO,CAAC,GAAG,CAAC,oBAAoB;YAChC,aAAa,CAAC,GAAG,CAAC,oBAAoB,CAAA;IACxC,OAAO,CAAC,MAAM,CAAC,oBAAoB;QACjC,OAAO,CAAC,MAAM,CAAC,oBAAoB;YACnC,aAAa,CAAC,MAAM,CAAC,oBAAoB,CAAA;IAE3C,4CAA4C;IAC5C,0CAA0C;IAC1C,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,aAAa,CAAC,GAAG,EAAE,CAAC;QACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;YACjC,SAAQ;QACV,CAAC;QAED,2DAA2D;QAC3D,2DAA2D;QAC3D,4CAA4C;QAC5C,KAAK,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,uEAAuE;IACvE,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAA;IAEvB,wDAAwD;IACxD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QAChD,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC3B,CAAC;IAED,kEAAkE;IAClE,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;IAEzD,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;IAElB,OAAO,OAAO,CAAC,KAAK,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import type { Graph } from '../graph.ts'\nimport { getImporterSpecs } from './get-importer-specs.ts'\nimport { addNodes } from './add-nodes.ts'\nimport type { AddNodesOptions } from './add-nodes.ts'\nimport { removeNodes } from './remove-nodes.ts'\nimport type { RemoveNodesOptions } from './remove-nodes.ts'\n\nexport type BuildIdealFromStartingGraphOptions = AddNodesOptions &\n RemoveNodesOptions & {\n projectRoot: string\n }\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using the `graph` set\n * in options as a starting point. Also add / remove any dependencies\n * listed in the `add` and `remove` properties.\n */\nexport const buildIdealFromStartingGraph = async (\n options: BuildIdealFromStartingGraphOptions,\n): Promise<Graph> => {\n // Gets a map of dependencies that are keyed to its importer node ids,\n // merging values already found in the graph with user specified values.\n // Any dependencies that are already satisfied in the starting `graph`\n // are going to be pruned from the resulting object.\n const importerSpecs = getImporterSpecs(options)\n\n // merge modifiedDependencies flags\n options.add.modifiedDependencies =\n options.add.modifiedDependencies ||\n importerSpecs.add.modifiedDependencies\n options.remove.modifiedDependencies =\n options.remove.modifiedDependencies ||\n importerSpecs.remove.modifiedDependencies\n\n // merge values found on importer specs with\n // user-provided values from `options.add`\n for (const [importerId, deps] of importerSpecs.add) {\n if (!options.add.has(importerId)) {\n options.add.set(importerId, deps)\n continue\n }\n\n // merge any deps found when reading the importers manifest\n // with the ones provided by the user in the `add` options,\n // user-provided deps should take precedence\n for (const [depName, dep] of deps) {\n if (!options.add.get(importerId)?.has(depName)) {\n options.add.get(importerId)?.set(depName, dep)\n }\n }\n }\n\n // add nodes, fetching remote manifests for each dependency to be added\n await addNodes(options)\n\n // move things into their default locations, if possible\n for (const node of options.graph.nodes.values()) {\n node.setDefaultLocation()\n }\n\n // removes any dependencies that are listed in the `remove` option\n removeNodes({ ...options, remove: importerSpecs.remove })\n\n options.graph.gc()\n\n return options.graph\n}\n"]}
1
+ {"version":3,"file":"build-ideal-from-starting-graph.js","sourceRoot":"","sources":["../../../src/ideal/build-ideal-from-starting-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAUzD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,OAA2C,EAC3B,EAAE;IAClB,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,oDAAoD;IACpD,MAAM,aAAa,GAAG,gBAAgB,CAAC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K,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;QAClD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;YAChC,SAAQ;QACV,CAAC;QAED,uDAAuD;QACvD,6DAA6D;QAC7D,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;IAED,kEAAkE;IAClE,qEAAqE;IACrE,0CAA0C;IAC1C,MAAM,iBAAiB,CAAC;QACtB,GAAG,OAAO;QACV,YAAY,EAAE,aAAa,CAAC,YAAY;QACxC,eAAe,EAAE,aAAa,CAAC,eAAe;KAC/C,CAAC,CAAA;IAEF,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;IAElB,OAAO,OAAO,CAAC,KAAK,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import { getImporterSpecs } from './get-importer-specs.ts'\nimport { refreshIdealGraph } from './refresh-ideal-graph.ts'\nimport { resolveSaveType } from '../resolve-save-type.ts'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type { RefreshIdealGraphOptions } from './refresh-ideal-graph.ts'\nimport type { Graph } from '../graph.ts'\n\nexport type BuildIdealFromStartingGraphOptions =\n RefreshIdealGraphOptions & {\n packageJson: PackageJson\n }\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using the `graph` set\n * in options as a starting point. Also add / remove any dependencies\n * listed in the `add` and `remove` properties.\n */\nexport const buildIdealFromStartingGraph = async (\n options: BuildIdealFromStartingGraphOptions,\n): Promise<Graph> => {\n // Gets a map of dependencies that are keyed to its importer node ids,\n // merging values already found in the graph with user specified values.\n // Any dependencies that are already satisfied in the starting `graph`\n // are going to be pruned from the resulting object.\n const importerSpecs = getImporterSpecs(options)\n\n // merge modifiedDependencies flags\n options.add.modifiedDependencies =\n options.add.modifiedDependencies ||\n importerSpecs.add.modifiedDependencies\n options.remove.modifiedDependencies =\n options.remove.modifiedDependencies ||\n importerSpecs.remove.modifiedDependencies\n\n // merge values found on node specs with\n // user-provided values from `options.add`\n for (const [nodeId, deps] of importerSpecs.add) {\n const node = options.graph.nodes.get(nodeId)\n /* c8 ignore next - impossible */\n if (!node) continue\n\n if (!options.add.has(nodeId)) {\n options.add.set(nodeId, deps)\n continue\n }\n\n // merge any deps found when reading the nodes manifest\n // with the ones provided by the user in the `add` options,\n // user-provided deps should take precedence\n for (const [depName, dep] of deps) {\n if (!options.add.get(nodeId)?.has(depName)) {\n options.add.get(nodeId)?.set(depName, dep)\n }\n\n // update the save type for deps when using an implicit type\n dep.type = resolveSaveType(node, depName, dep.type)\n }\n }\n\n // merge values found on node specs with\n // user-provided values from `options.remove`\n for (const [nodeId, deps] of importerSpecs.remove) {\n if (!options.remove.has(nodeId)) {\n options.remove.set(nodeId, deps)\n continue\n }\n\n // merge any deps found when reading the nodes manifest\n // with the ones provided by the user in the `remove` options\n for (const depName of deps) {\n options.remove.get(nodeId)?.add(depName)\n }\n }\n\n // refreshs the current graph adding the nodes marked for addition\n // and removing the ones marked for removal, while also recalculating\n // peer dependencies and default locations\n await refreshIdealGraph({\n ...options,\n transientAdd: importerSpecs.transientAdd,\n transientRemove: importerSpecs.transientRemove,\n })\n\n options.graph.gc()\n\n return options.graph\n}\n"]}
@@ -2,7 +2,12 @@ import type { PackageInfoClient } from '@vltpkg/package-info';
2
2
  import type { LoadOptions as LoadActualOptions } from '../actual/load.ts';
3
3
  import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '../dependencies.ts';
4
4
  import type { Graph } from '../graph.ts';
5
+ import type { RollbackRemove } from '@vltpkg/rollback-remove';
5
6
  export type BuildIdealOptions = LoadActualOptions & {
7
+ /**
8
+ * An actual graph
9
+ */
10
+ actual?: Graph;
6
11
  /**
7
12
  * A `Map` in which keys are {@link DepID} linking to another `Map` in which
8
13
  * keys are the dependency names and values are {@link Dependency}. This
@@ -16,6 +21,10 @@ export type BuildIdealOptions = LoadActualOptions & {
16
21
  * dependency names to be removed from its dependency list.
17
22
  */
18
23
  remove?: RemoveImportersDependenciesMap;
24
+ /**
25
+ * A {@link RollbackRemove} instance to handle extraction rollbacks
26
+ */
27
+ remover: RollbackRemove;
19
28
  /**
20
29
  * A {@link PackageInfoClient} instance to read manifest info from.
21
30
  */
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAE/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AASxC,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAClD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP,iBAAiB,KACzB,OAAO,CAAC,KAAK,CAiCf,CAAA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,KAAK,EACV,2BAA2B,EAC3B,8BAA8B,EAE/B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAK7D,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAClD;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IACd;;;;;OAKG;IACH,GAAG,CAAC,EAAE,2BAA2B,CAAA;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,8BAA8B,CAAA;IACvC;;OAEG;IACH,OAAO,EAAE,cAAc,CAAA;IACvB;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAmBD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YACP,iBAAiB,KACzB,OAAO,CAAC,KAAK,CAgDf,CAAA"}
@@ -1,8 +1,23 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { graphStep } from '@vltpkg/output';
1
3
  import { load as loadActual } from "../actual/load.js";
2
4
  import { load as loadVirtual } from "../lockfile/load.js";
3
5
  import { buildIdealFromStartingGraph } from "./build-ideal-from-starting-graph.js";
4
- import { graphStep } from '@vltpkg/output';
6
+ import { splitDepID } from '@vltpkg/dep-id';
5
7
  const getMap = (m) => m ?? new Map();
8
+ /**
9
+ * Validates that a file dependency node exists in the graph after
10
+ * a successful graph build. This helps providing an actionable error
11
+ * message in case the current working directory is a linked nested
12
+ * folder that hasn't yet been added as a dependency to an importer
13
+ * in the project.
14
+ */
15
+ const validateFileDepNode = (graph, id) => {
16
+ const [type, path] = splitDepID(id);
17
+ if (type === 'file' && !graph.nodes.get(id)) {
18
+ throw error('The current working dir is not a dependency of this project', { path });
19
+ }
20
+ };
6
21
  /**
7
22
  * Builds an ideal {@link Graph} representing the dependencies that
8
23
  * should be present in order to fulfill the requirements defined
@@ -38,8 +53,23 @@ export const build = async (options) => {
38
53
  graph,
39
54
  packageInfo,
40
55
  remove: getMap(options.remove),
56
+ actual: options.actual,
41
57
  });
42
58
  done();
59
+ // when adding or removing a new dependency from a file dep,
60
+ // validate the receiver node was present in the graph
61
+ if (options.add) {
62
+ for (const [addKey, value] of options.add.entries()) {
63
+ if (value.size)
64
+ validateFileDepNode(res, addKey);
65
+ }
66
+ }
67
+ if (options.remove) {
68
+ for (const [removeKey, value] of options.remove.entries()) {
69
+ if (value.size)
70
+ validateFileDepNode(res, removeKey);
71
+ }
72
+ }
43
73
  return res;
44
74
  };
45
75
  //# sourceMappingURL=build.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQtD,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAA;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,MAAM,MAAM,GAAG,CAA0B,CAAK,EAAE,EAAE,CAChD,CAAC,IAAK,IAAI,GAAG,EAAQ,CAAA;AAsBvB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,OAA0B,EACV,EAAE;IAClB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAE/B,yDAAyD;IACzD,iDAAiD;IACjD,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAC9D,MAAM,YAAY,GAChB,OAAO,CAAC,YAAY,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC/D,IAAI,KAAK,CAAA;IACT,IAAI,CAAC;QACH,KAAK,GAAG,WAAW,CAAC;YAClB,GAAG,OAAO;YACV,YAAY;YACZ,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,KAAK,GAAG,UAAU,CAAC;YACjB,GAAG,OAAO;YACV,YAAY;YACZ,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,2BAA2B,CAAC;QAC5C,GAAG,OAAO;QACV,MAAM;QACN,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QACxB,KAAK;QACL,WAAW;QACX,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;KAC/B,CAAC,CAAA;IACF,IAAI,EAAE,CAAA;IACN,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import type { PackageInfoClient } from '@vltpkg/package-info'\nimport { load as loadActual } from '../actual/load.ts'\nimport type { LoadOptions as LoadActualOptions } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n Dependency,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { load as loadVirtual } from '../lockfile/load.ts'\nimport { buildIdealFromStartingGraph } from './build-ideal-from-starting-graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { graphStep } from '@vltpkg/output'\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\nexport type BuildIdealOptions = LoadActualOptions & {\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n}\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using either the\n * virtual or actual graph as a starting point. Also add / remove any\n * dependencies listed in the `add` and `remove` properties.\n */\nexport const build = async (\n options: BuildIdealOptions,\n): Promise<Graph> => {\n const done = graphStep('build')\n\n // Creates the shared instances that are going to be used\n // in both the loader methods and the build graph\n const { packageInfo, packageJson, scurry, monorepo } = options\n const mainManifest =\n options.mainManifest ?? packageJson.read(options.projectRoot)\n let graph\n try {\n graph = loadVirtual({\n ...options,\n mainManifest,\n monorepo,\n })\n } catch {\n graph = loadActual({\n ...options,\n mainManifest,\n monorepo,\n })\n }\n\n const res = await buildIdealFromStartingGraph({\n ...options,\n scurry,\n add: getMap(options.add),\n graph,\n packageInfo,\n remove: getMap(options.remove),\n })\n done()\n return res\n}\n"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/ideal/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAA;AASlF,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,MAAM,MAAM,GAAG,CAA0B,CAAK,EAAE,EAAE,CAChD,CAAC,IAAK,IAAI,GAAG,EAAQ,CAAA;AA8BvB;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,KAAY,EAAE,EAAS,EAAE,EAAE;IACtD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAA;IACnC,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC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,CAAC,IAAI;gBAAE,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAC1D,IAAI,KAAK,CAAC,IAAI;gBAAE,mBAAmB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;QACrD,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { graphStep } from '@vltpkg/output'\nimport { load as loadActual } from '../actual/load.ts'\nimport { load as loadVirtual } from '../lockfile/load.ts'\nimport { buildIdealFromStartingGraph } from './build-ideal-from-starting-graph.ts'\nimport type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { LoadOptions as LoadActualOptions } from '../actual/load.ts'\nimport type {\n AddImportersDependenciesMap,\n RemoveImportersDependenciesMap,\n Dependency,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { splitDepID } from '@vltpkg/dep-id'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { RollbackRemove } from '@vltpkg/rollback-remove'\n\nconst getMap = <T extends Map<any, any>>(m?: T) =>\n m ?? (new Map() as T)\n\nexport type BuildIdealOptions = LoadActualOptions & {\n /**\n * An actual graph\n */\n actual?: Graph\n /**\n * A `Map` in which keys are {@link DepID} linking to another `Map` in which\n * keys are the dependency names and values are {@link Dependency}. This\n * structure represents dependencies that need to be added to the importer\n * represented by {@link DepID}.\n */\n add?: AddImportersDependenciesMap\n /**\n * A `Map` object representing nodes to be removed from the ideal graph.\n * Each {@link DepID} key represents an importer node and the `Set` of\n * dependency names to be removed from its dependency list.\n */\n remove?: RemoveImportersDependenciesMap\n /**\n * A {@link RollbackRemove} instance to handle extraction rollbacks\n */\n remover: RollbackRemove\n /**\n * A {@link PackageInfoClient} instance to read manifest info from.\n */\n packageInfo: PackageInfoClient\n}\n\n/**\n * Validates that a file dependency node exists in the graph after\n * a successful graph build. This helps providing an actionable error\n * message in case the current working directory is a linked nested\n * folder that hasn't yet been added as a dependency to an importer\n * in the project.\n */\nconst validateFileDepNode = (graph: Graph, id: DepID) => {\n const [type, path] = splitDepID(id)\n if (type === 'file' && !graph.nodes.get(id)) {\n throw error(\n 'The current working dir is not a dependency of this project',\n { path },\n )\n }\n}\n\n/**\n * Builds an ideal {@link Graph} representing the dependencies that\n * should be present in order to fulfill the requirements defined\n * by the `package.json` and `vlt-lock.json` files using either the\n * virtual or actual graph as a starting point. Also add / remove any\n * dependencies listed in the `add` and `remove` properties.\n */\nexport const build = async (\n options: BuildIdealOptions,\n): Promise<Graph> => {\n const done = graphStep('build')\n\n // Creates the shared instances that are going to be used\n // in both the loader methods and the build graph\n const { packageInfo, packageJson, scurry, monorepo } = options\n const mainManifest =\n options.mainManifest ?? packageJson.read(options.projectRoot)\n let graph\n try {\n graph = loadVirtual({\n ...options,\n mainManifest,\n monorepo,\n })\n } catch {\n graph = loadActual({\n ...options,\n mainManifest,\n monorepo,\n })\n }\n\n const res = await buildIdealFromStartingGraph({\n ...options,\n scurry,\n add: getMap(options.add),\n graph,\n packageInfo,\n remove: getMap(options.remove),\n actual: options.actual,\n })\n done()\n\n // when adding or removing a new dependency from a file dep,\n // validate the receiver node was present in the graph\n if (options.add) {\n for (const [addKey, value] of options.add.entries()) {\n if (value.size) validateFileDepNode(res, addKey)\n }\n }\n if (options.remove) {\n for (const [removeKey, value] of options.remove.entries()) {\n if (value.size) validateFileDepNode(res, removeKey)\n }\n }\n\n return res\n}\n"]}
@@ -1,13 +1,21 @@
1
1
  import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '../dependencies.ts';
2
- import type { BuildIdealAddOptions, BuildIdealFromGraphOptions, BuildIdealRemoveOptions } from './types.ts';
3
- export type GetImporterSpecsOptions = BuildIdealAddOptions & BuildIdealFromGraphOptions & BuildIdealRemoveOptions;
2
+ import type { BuildIdealAddOptions, BuildIdealFromGraphOptions, BuildIdealRemoveOptions, TransientAddMap, TransientRemoveMap } from './types.ts';
3
+ import type { SpecOptions } from '@vltpkg/spec';
4
+ import type { PackageJson } from '@vltpkg/package-json';
5
+ import type { PathScurry } from 'path-scurry';
6
+ export type GetImporterSpecsOptions = BuildIdealAddOptions & BuildIdealFromGraphOptions & BuildIdealRemoveOptions & SpecOptions & {
7
+ scurry: PathScurry;
8
+ packageJson: PackageJson;
9
+ };
4
10
  /**
5
11
  * Given a {@link Graph} and a list of {@link Dependency}, merges the
6
12
  * dependencies info found in the graph importers and returns the add & remove
7
13
  * results as a Map in which keys are {@link DepID} of each importer node.
8
14
  */
9
- export declare const getImporterSpecs: ({ add, graph, remove, }: GetImporterSpecsOptions) => {
15
+ export declare const getImporterSpecs: (options: GetImporterSpecsOptions) => {
10
16
  add: AddImportersDependenciesMap;
11
17
  remove: RemoveImportersDependenciesMap;
18
+ transientAdd: TransientAddMap;
19
+ transientRemove: TransientRemoveMap;
12
20
  };
13
21
  //# sourceMappingURL=get-importer-specs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-importer-specs.d.ts","sourceRoot":"","sources":["../../../src/ideal/get-importer-specs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAOnB,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GACxD,0BAA0B,GAC1B,uBAAuB,CAAA;AAyBzB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,4BAI1B,uBAAuB;;;CA4FzB,CAAA"}
1
+ {"version":3,"file":"get-importer-specs.d.ts","sourceRoot":"","sources":["../../../src/ideal/get-importer-specs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,EACf,kBAAkB,EACnB,MAAM,YAAY,CAAA;AAMnB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GACxD,0BAA0B,GAC1B,uBAAuB,GACvB,WAAW,GAAG;IACZ,MAAM,EAAE,UAAU,CAAA;IAClB,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AAyBH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,YAClB,uBAAuB;;;;;CAoLjC,CAAA"}
@@ -1,4 +1,3 @@
1
- import { error } from '@vltpkg/error-cause';
2
1
  import { longDependencyTypes } from '@vltpkg/types';
3
2
  import { shorten, asDependency } from "../dependencies.js";
4
3
  import { removeSatisfiedSpecs } from "./remove-satisfied-specs.js";
@@ -22,7 +21,8 @@ class RemoveImportersDependenciesMapImpl extends Map {
22
21
  * dependencies info found in the graph importers and returns the add & remove
23
22
  * results as a Map in which keys are {@link DepID} of each importer node.
24
23
  */
25
- export const getImporterSpecs = ({ add, graph, remove, }) => {
24
+ export const getImporterSpecs = (options) => {
25
+ const { add, graph, remove } = options;
26
26
  const addResult = new AddImportersDependenciesMapImpl();
27
27
  const removeResult = new RemoveImportersDependenciesMapImpl();
28
28
  // traverse the list of importers in the starting graph
@@ -46,22 +46,85 @@ export const getImporterSpecs = ({ add, graph, remove, }) => {
46
46
  const deps = Object.entries(importer.manifest?.[depType] ?? {});
47
47
  for (const [depName, depSpec] of deps) {
48
48
  const edge = importer.edgesOut.get(depName);
49
- if (!edge?.to) {
50
- addDeps.set(depName, asDependency({
51
- spec: Spec.parse(depName, depSpec),
52
- type: shorten(depType, depName, importer.manifest),
53
- }));
54
- }
49
+ // skip if the edge exists and already uses the same spec
50
+ if (edge?.to && depSpec === edge.spec.bareSpec)
51
+ continue;
52
+ const dependency = asDependency({
53
+ spec: Spec.parse(depName, depSpec, options),
54
+ type: shorten(depType, depName, importer.manifest),
55
+ });
56
+ addDeps.set(depName, dependency);
55
57
  }
56
58
  }
57
59
  addResult.set(importer.id, addDeps);
58
60
  removeResult.set(importer.id, removeDeps);
59
61
  }
62
+ // Maps to store dependencies targeting non-importer nodes (e.g., nested folders)
63
+ // These will be injected when the target node is placed in the graph
64
+ const transientAdd = new Map();
65
+ const transientRemove = new Map();
66
+ // Traverse all nodes in the graph to find file type dependencies that are directories
67
+ // and populate transientAdd/transientRemove with their manifest dependencies
68
+ // Only process when scurry and packageJson are available
69
+ for (const node of graph.nodes.values()) {
70
+ // Skip importers as they're already handled above and also skip
71
+ // any non-file type dependencies
72
+ if (graph.importers.has(node) || !node.id.startsWith('file'))
73
+ continue;
74
+ // check if this is a file type dependency that is a directory
75
+ const nodePath = options.scurry.cwd.resolve(node.location);
76
+ const stat = nodePath.lstatSync();
77
+ if (stat?.isDirectory()) {
78
+ // load the manifest for this directory (throw if it does not exist)
79
+ const manifest = options.packageJson.read(nodePath.fullpath());
80
+ // should always set the manifest to the read manifest
81
+ node.manifest = manifest;
82
+ // create a map of dependencies from the manifest
83
+ const addDeps = new Map();
84
+ // check for edges not in manifest (should be removed)
85
+ const removeDeps = new Set();
86
+ for (const edge of node.edgesOut.values()) {
87
+ if (!hasDepName(node, edge) &&
88
+ !add.get(node.id)?.has(edge.name)) {
89
+ removeDeps.add(edge.name);
90
+ }
91
+ }
92
+ // iterate over manifest dependencies to add them if
93
+ // they're missing from the graph
94
+ for (const depType of longDependencyTypes) {
95
+ const deps = Object.entries(manifest[depType] ?? {});
96
+ for (const [depName, depSpec] of deps) {
97
+ const edge = node.edgesOut.get(depName);
98
+ // skip if the edge exists and already uses the same spec
99
+ if (edge?.to && depSpec === edge.spec.bareSpec)
100
+ continue;
101
+ // add the dependency to the addDeps map
102
+ const dependency = asDependency({
103
+ spec: Spec.parse(depName, depSpec, options),
104
+ type: shorten(depType, depName, manifest),
105
+ });
106
+ addDeps.set(depName, dependency);
107
+ }
108
+ }
109
+ // store in transientAdd if there are any dependencies
110
+ if (addDeps.size > 0) {
111
+ transientAdd.set(node.id, addDeps);
112
+ }
113
+ // store in transientRemove if there are any to remove
114
+ if (removeDeps.size > 0) {
115
+ transientRemove.set(node.id, removeDeps);
116
+ }
117
+ }
118
+ }
60
119
  // merges any provided specs to add to the current found results
61
120
  for (const [id, addDeps] of add.entries()) {
62
121
  const deps = addResult.get(id);
63
122
  if (!deps) {
64
- throw error('Not an importer', { found: id });
123
+ // Not an importer - only store file-type deps for later injection
124
+ if (id.startsWith('file')) {
125
+ transientAdd.set(id, addDeps);
126
+ }
127
+ continue;
65
128
  }
66
129
  for (const [name, dep] of addDeps.entries()) {
67
130
  deps.set(name, dep);
@@ -76,6 +139,18 @@ export const getImporterSpecs = ({ add, graph, remove, }) => {
76
139
  importerRemoveItem.add(depName);
77
140
  }
78
141
  }
142
+ else if (key.startsWith('file')) {
143
+ // Not an importer - only store file-type deps in transientRemove
144
+ const existing = transientRemove.get(key);
145
+ if (existing) {
146
+ for (const depName of removeSet) {
147
+ existing.add(depName);
148
+ }
149
+ }
150
+ else {
151
+ transientRemove.set(key, new Set(removeSet));
152
+ }
153
+ }
79
154
  }
80
155
  // Removes any references to an importer that no longer has specs
81
156
  for (const [key, removeItem] of removeResult) {
@@ -99,6 +174,8 @@ export const getImporterSpecs = ({ add, graph, remove, }) => {
99
174
  return {
100
175
  add: addResult,
101
176
  remove: removeResult,
177
+ transientAdd,
178
+ transientRemove,
102
179
  };
103
180
  };
104
181
  //# sourceMappingURL=get-importer-specs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-importer-specs.js","sourceRoot":"","sources":["../../../src/ideal/get-importer-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B,SAAS,CAAC,oBAAoB,GAAG,IAAI,CAAA;YACrC,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,EAAE,SAAS;QACd,MAAM,EAAE,YAAY;KACrB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport { shorten, asDependency } from '../dependencies.ts'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { removeSatisfiedSpecs } from './remove-satisfied-specs.ts'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n BuildIdealRemoveOptions,\n} from './types.ts'\nimport type { Edge } from '../edge.ts'\nimport type { Node } from '../node.ts'\nimport type { Graph } from '../graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { Spec } from '@vltpkg/spec'\n\nexport type GetImporterSpecsOptions = BuildIdealAddOptions &\n BuildIdealFromGraphOptions &\n BuildIdealRemoveOptions\n\nconst hasDepName = (importer: Node, edge: Edge): boolean => {\n for (const depType of longDependencyTypes) {\n const listedDeps = importer.manifest?.[depType]\n if (listedDeps && Object.hasOwn(listedDeps, edge.name))\n return true\n }\n return false\n}\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\n/**\n * Given a {@link Graph} and a list of {@link Dependency}, merges the\n * dependencies info found in the graph importers and returns the add & remove\n * results as a Map in which keys are {@link DepID} of each importer node.\n */\nexport const getImporterSpecs = ({\n add,\n graph,\n remove,\n}: GetImporterSpecsOptions) => {\n const addResult: AddImportersDependenciesMap =\n new AddImportersDependenciesMapImpl()\n const removeResult: RemoveImportersDependenciesMap =\n new RemoveImportersDependenciesMapImpl()\n\n // traverse the list of importers in the starting graph\n for (const importer of graph.importers) {\n // uses a Map keying to the spec.name in order to easily make sure there's\n // only a single dependency entry for a given dependency for each importer\n const addDeps = new Map<string, Dependency>()\n const removeDeps = new Set<string>()\n // if an edge from the graph is not listed in the manifest,\n // add that edge to the list of dependencies to be removed\n for (const edge of importer.edgesOut.values()) {\n if (\n !hasDepName(importer, edge) &&\n !add.get(importer.id)?.has(edge.name)\n ) {\n removeDeps.add(edge.name)\n removeResult.modifiedDependencies = true\n }\n }\n // if a dependency is listed in the manifest but not in the graph,\n // add that dependency to the list of dependencies to be added\n for (const depType of longDependencyTypes) {\n const deps = Object.entries(importer.manifest?.[depType] ?? {})\n for (const [depName, depSpec] of deps) {\n const edge = importer.edgesOut.get(depName)\n if (!edge?.to) {\n addDeps.set(\n depName,\n asDependency({\n spec: Spec.parse(depName, depSpec),\n type: shorten(depType, depName, importer.manifest),\n }),\n )\n }\n }\n }\n addResult.set(importer.id, addDeps)\n removeResult.set(importer.id, removeDeps)\n }\n\n // merges any provided specs to add to the current found results\n for (const [id, addDeps] of add.entries()) {\n const deps = addResult.get(id)\n if (!deps) {\n throw error('Not an importer', { found: id })\n }\n for (const [name, dep] of addDeps.entries()) {\n deps.set(name, dep)\n }\n }\n\n // Merges results from user-provided `remove` option with any remove\n // results found from comparing the manifest with the loaded graph\n for (const [key, removeSet] of remove) {\n const importerRemoveItem = removeResult.get(key)\n if (importerRemoveItem) {\n for (const depName of removeSet) {\n importerRemoveItem.add(depName)\n }\n }\n }\n\n // Removes any references to an importer that no longer has specs\n for (const [key, removeItem] of removeResult) {\n if (removeItem.size === 0) {\n removeResult.delete(key)\n }\n }\n\n // removes already satisfied dependencies from the dependencies list\n removeSatisfiedSpecs({\n add: addResult,\n graph,\n })\n\n // set the modifiedDependencies flag if any\n // of the importers have modified dependencies\n for (const addDeps of addResult.values()) {\n if (addDeps.size > 0) {\n addResult.modifiedDependencies = true\n break\n }\n }\n\n return {\n add: addResult,\n remove: removeResult,\n }\n}\n"]}
1
+ {"version":3,"file":"get-importer-specs.js","s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SAAS,CAAC,CAAC,CAAA;YAC9C,CAAC;QACH,CAAC;IACH,CAAC;IAED,iEAAiE;IACjE,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,YAAY,EAAE,CAAC;QAC7C,IAAI,UAAU,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC1B,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;IAED,oEAAoE;IACpE,oBAAoB,CAAC;QACnB,GAAG,EAAE,SAAS;QACd,KAAK;KACN,CAAC,CAAA;IAEF,2CAA2C;IAC3C,8CAA8C;IAC9C,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACzC,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACrB,SAAS,CAAC,oBAAoB,GAAG,IAAI,CAAA;YACrC,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,EAAE,SAAS;QACd,MAAM,EAAE,YAAY;QACpB,YAAY;QACZ,eAAe;KAChB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { longDependencyTypes } from '@vltpkg/types'\nimport { shorten, asDependency } from '../dependencies.ts'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport { removeSatisfiedSpecs } from './remove-satisfied-specs.ts'\nimport type {\n BuildIdealAddOptions,\n BuildIdealFromGraphOptions,\n BuildIdealRemoveOptions,\n TransientAddMap,\n TransientRemoveMap,\n} from './types.ts'\nimport type { Edge } from '../edge.ts'\nimport type { Node } from '../node.ts'\nimport type { Graph } from '../graph.ts'\nimport type { DepID } from '@vltpkg/dep-id'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type { PathScurry } from 'path-scurry'\n\nexport type GetImporterSpecsOptions = BuildIdealAddOptions &\n BuildIdealFromGraphOptions &\n BuildIdealRemoveOptions &\n SpecOptions & {\n scurry: PathScurry\n packageJson: PackageJson\n }\n\nconst hasDepName = (importer: Node, edge: Edge): boolean => {\n for (const depType of longDependencyTypes) {\n const listedDeps = importer.manifest?.[depType]\n if (listedDeps && Object.hasOwn(listedDeps, edge.name))\n return true\n }\n return false\n}\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\n/**\n * Given a {@link Graph} and a list of {@link Dependency}, merges the\n * dependencies info found in the graph importers and returns the add & remove\n * results as a Map in which keys are {@link DepID} of each importer node.\n */\nexport const getImporterSpecs = (\n options: GetImporterSpecsOptions,\n) => {\n const { add, graph, remove } = options\n const addResult: AddImportersDependenciesMap =\n new AddImportersDependenciesMapImpl()\n const removeResult: RemoveImportersDependenciesMap =\n new RemoveImportersDependenciesMapImpl()\n\n // traverse the list of importers in the starting graph\n for (const importer of graph.importers) {\n // uses a Map keying to the spec.name in order to easily make sure there's\n // only a single dependency entry for a given dependency for each importer\n const addDeps = new Map<string, Dependency>()\n const removeDeps = new Set<string>()\n // if an edge from the graph is not listed in the manifest,\n // add that edge to the list of dependencies to be removed\n for (const edge of importer.edgesOut.values()) {\n if (\n !hasDepName(importer, edge) &&\n !add.get(importer.id)?.has(edge.name)\n ) {\n removeDeps.add(edge.name)\n removeResult.modifiedDependencies = true\n }\n }\n // if a dependency is listed in the manifest but not in the graph,\n // add that dependency to the list of dependencies to be added\n for (const depType of longDependencyTypes) {\n const deps = Object.entries(importer.manifest?.[depType] ?? {})\n for (const [depName, depSpec] of deps) {\n const edge = importer.edgesOut.get(depName)\n\n // skip if the edge exists and already uses the same spec\n if (edge?.to && depSpec === edge.spec.bareSpec) continue\n\n const dependency = asDependency({\n spec: Spec.parse(depName, depSpec, options),\n type: shorten(depType, depName, importer.manifest),\n })\n addDeps.set(depName, dependency)\n }\n }\n addResult.set(importer.id, addDeps)\n removeResult.set(importer.id, removeDeps)\n }\n\n // Maps to store dependencies targeting non-importer nodes (e.g., nested folders)\n // These will be injected when the target node is placed in the graph\n const transientAdd = new Map() as TransientAddMap\n const transientRemove = new Map() as TransientRemoveMap\n\n // Traverse all nodes in the graph to find file type dependencies that are directories\n // and populate transientAdd/transientRemove with their manifest dependencies\n // Only process when scurry and packageJson are available\n for (const node of graph.nodes.values()) {\n // Skip importers as they're already handled above and also skip\n // any non-file type dependencies\n if (graph.importers.has(node) || !node.id.startsWith('file'))\n continue\n\n // check if this is a file type dependency that is a directory\n const nodePath = options.scurry.cwd.resolve(node.location)\n const stat = nodePath.lstatSync()\n\n if (stat?.isDirectory()) {\n // load the manifest for this directory (throw if it does not exist)\n const manifest = options.packageJson.read(nodePath.fullpath())\n\n // should always set the manifest to the read manifest\n node.manifest = manifest\n\n // create a map of dependencies from the manifest\n const addDeps = new Map<string, Dependency>()\n\n // check for edges not in manifest (should be removed)\n const removeDeps = new Set<string>()\n for (const edge of node.edgesOut.values()) {\n if (\n !hasDepName(node, edge) &&\n !add.get(node.id)?.has(edge.name)\n ) {\n removeDeps.add(edge.name)\n }\n }\n\n // iterate over manifest dependencies to add them if\n // they're missing from the graph\n for (const depType of longDependencyTypes) {\n const deps = Object.entries(manifest[depType] ?? {})\n for (const [depName, depSpec] of deps) {\n const edge = node.edgesOut.get(depName)\n\n // skip if the edge exists and already uses the same spec\n if (edge?.to && depSpec === edge.spec.bareSpec) continue\n\n // add the dependency to the addDeps map\n const dependency = asDependency({\n spec: Spec.parse(depName, depSpec, options),\n type: shorten(depType, depName, manifest),\n })\n addDeps.set(depName, dependency)\n }\n }\n\n // store in transientAdd if there are any dependencies\n if (addDeps.size > 0) {\n transientAdd.set(node.id, addDeps)\n }\n\n // store in transientRemove if there are any to remove\n if (removeDeps.size > 0) {\n transientRemove.set(node.id, removeDeps)\n }\n }\n }\n\n // merges any provided specs to add to the current found results\n for (const [id, addDeps] of add.entries()) {\n const deps = addResult.get(id)\n if (!deps) {\n // Not an importer - only store file-type deps for later injection\n if (id.startsWith('file')) {\n transientAdd.set(id, addDeps)\n }\n continue\n }\n for (const [name, dep] of addDeps.entries()) {\n deps.set(name, dep)\n }\n }\n\n // Merges results from user-provided `remove` option with any remove\n // results found from comparing the manifest with the loaded graph\n for (const [key, removeSet] of remove) {\n const importerRemoveItem = removeResult.get(key)\n if (importerRemoveItem) {\n for (const depName of removeSet) {\n importerRemoveItem.add(depName)\n }\n } else if (key.startsWith('file')) {\n // Not an importer - only store file-type deps in transientRemove\n const existing = transientRemove.get(key)\n if (existing) {\n for (const depName of removeSet) {\n existing.add(depName)\n }\n } else {\n transientRemove.set(key, new Set(removeSet))\n }\n }\n }\n\n // Removes any references to an importer that no longer has specs\n for (const [key, removeItem] of removeResult) {\n if (removeItem.size === 0) {\n removeResult.delete(key)\n }\n }\n\n // removes already satisfied dependencies from the dependencies list\n removeSatisfiedSpecs({\n add: addResult,\n graph,\n })\n\n // set the modifiedDependencies flag if any\n // of the importers have modified dependencies\n for (const addDeps of addResult.values()) {\n if (addDeps.size > 0) {\n addResult.modifiedDependencies = true\n break\n }\n }\n\n return {\n add: addResult,\n remove: removeResult,\n transientAdd,\n transientRemove,\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Node } from '../node.ts';
2
+ import type { Dependency } from '../dependencies.ts';
3
+ import type { BuildIdealAddOptions, BuildIdealRemoveOptions } from './types.ts';
4
+ /**
5
+ * Computes the ordered list of dependencies for an given node,
6
+ * taking into account additions and removals.
7
+ */
8
+ export declare const getNodeOrderedDependencies: (fromNode: Node, options?: BuildIdealAddOptions & BuildIdealRemoveOptions) => Dependency[];
9
+ export declare const getOrderedDependencies: (deps: Dependency[]) => Dependency[];
10
+ //# sourceMappingURL=get-ordered-dependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-ordered-dependencies.d.ts","sourceRoot":"","sources":["../../../src/ideal/get-ordered-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EACV,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB;;;GAGG;AACH,eAAO,MAAM,0BAA0B,aAC3B,IAAI,YACJ,oBAAoB,GAAG,uBAAuB,KACvD,UAAU,EAyBZ,CAAA;AAED,eAAO,MAAM,sBAAsB,SAC3B,UAAU,EAAE,KACjB,UAAU,EAiBZ,CAAA"}