@vltpkg/graph 0.0.0-0.1730724342581 → 0.0.0-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/README.md +13 -12
  2. package/dist/esm/actual/load.d.ts +6 -6
  3. package/dist/esm/actual/load.d.ts.map +1 -1
  4. package/dist/esm/actual/load.js +8 -4
  5. package/dist/esm/actual/load.js.map +1 -1
  6. package/dist/esm/browser.d.ts +8 -6
  7. package/dist/esm/browser.d.ts.map +1 -1
  8. package/dist/esm/browser.js +8 -6
  9. package/dist/esm/browser.js.map +1 -1
  10. package/dist/esm/dependencies.d.ts +19 -29
  11. package/dist/esm/dependencies.d.ts.map +1 -1
  12. package/dist/esm/dependencies.js +4 -31
  13. package/dist/esm/dependencies.js.map +1 -1
  14. package/dist/esm/diff.d.ts +4 -4
  15. package/dist/esm/diff.d.ts.map +1 -1
  16. package/dist/esm/diff.js.map +1 -1
  17. package/dist/esm/edge.d.ts +5 -5
  18. package/dist/esm/edge.d.ts.map +1 -1
  19. package/dist/esm/edge.js +1 -1
  20. package/dist/esm/edge.js.map +1 -1
  21. package/dist/esm/graph.d.ts +12 -12
  22. package/dist/esm/graph.d.ts.map +1 -1
  23. package/dist/esm/graph.js +8 -6
  24. package/dist/esm/graph.js.map +1 -1
  25. package/dist/esm/ideal/add-nodes.d.ts +4 -4
  26. package/dist/esm/ideal/add-nodes.d.ts.map +1 -1
  27. package/dist/esm/ideal/add-nodes.js +8 -4
  28. package/dist/esm/ideal/add-nodes.js.map +1 -1
  29. package/dist/esm/ideal/append-nodes.d.ts +8 -8
  30. package/dist/esm/ideal/append-nodes.d.ts.map +1 -1
  31. package/dist/esm/ideal/append-nodes.js +37 -15
  32. package/dist/esm/ideal/append-nodes.js.map +1 -1
  33. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts +3 -3
  34. package/dist/esm/ideal/build-ideal-from-starting-graph.d.ts.map +1 -1
  35. package/dist/esm/ideal/build-ideal-from-starting-graph.js +28 -5
  36. package/dist/esm/ideal/build-ideal-from-starting-graph.js.map +1 -1
  37. package/dist/esm/ideal/build.d.ts +4 -4
  38. package/dist/esm/ideal/build.d.ts.map +1 -1
  39. package/dist/esm/ideal/build.js +8 -4
  40. package/dist/esm/ideal/build.js.map +1 -1
  41. package/dist/esm/ideal/get-importer-specs.d.ts +2 -2
  42. package/dist/esm/ideal/get-importer-specs.d.ts.map +1 -1
  43. package/dist/esm/ideal/get-importer-specs.js +39 -11
  44. package/dist/esm/ideal/get-importer-specs.js.map +1 -1
  45. package/dist/esm/ideal/remove-nodes.d.ts +1 -1
  46. package/dist/esm/ideal/remove-nodes.d.ts.map +1 -1
  47. package/dist/esm/ideal/remove-nodes.js.map +1 -1
  48. package/dist/esm/ideal/remove-satisfied-specs.d.ts +1 -1
  49. package/dist/esm/ideal/remove-satisfied-specs.d.ts.map +1 -1
  50. package/dist/esm/ideal/remove-satisfied-specs.js.map +1 -1
  51. package/dist/esm/ideal/types.d.ts +3 -3
  52. package/dist/esm/ideal/types.d.ts.map +1 -1
  53. package/dist/esm/ideal/types.js.map +1 -1
  54. package/dist/esm/index.d.ts +25 -22
  55. package/dist/esm/index.d.ts.map +1 -1
  56. package/dist/esm/index.js +20 -17
  57. package/dist/esm/index.js.map +1 -1
  58. package/dist/esm/install.d.ts +11 -0
  59. package/dist/esm/install.d.ts.map +1 -0
  60. package/dist/esm/install.js +26 -0
  61. package/dist/esm/install.js.map +1 -0
  62. package/dist/esm/lockfile/load-edges.d.ts +3 -3
  63. package/dist/esm/lockfile/load-edges.d.ts.map +1 -1
  64. package/dist/esm/lockfile/load-edges.js +2 -1
  65. package/dist/esm/lockfile/load-edges.js.map +1 -1
  66. package/dist/esm/lockfile/load-nodes.d.ts +2 -2
  67. package/dist/esm/lockfile/load-nodes.d.ts.map +1 -1
  68. package/dist/esm/lockfile/load-nodes.js +7 -2
  69. package/dist/esm/lockfile/load-nodes.js.map +1 -1
  70. package/dist/esm/lockfile/load.d.ts +5 -5
  71. package/dist/esm/lockfile/load.d.ts.map +1 -1
  72. package/dist/esm/lockfile/load.js +6 -4
  73. package/dist/esm/lockfile/load.js.map +1 -1
  74. package/dist/esm/lockfile/save.d.ts +5 -5
  75. package/dist/esm/lockfile/save.d.ts.map +1 -1
  76. package/dist/esm/lockfile/save.js +6 -3
  77. package/dist/esm/lockfile/save.js.map +1 -1
  78. package/dist/esm/lockfile/types.d.ts +5 -5
  79. package/dist/esm/lockfile/types.d.ts.map +1 -1
  80. package/dist/esm/lockfile/types.js.map +1 -1
  81. package/dist/esm/node.d.ts +34 -15
  82. package/dist/esm/node.d.ts.map +1 -1
  83. package/dist/esm/node.js +57 -17
  84. package/dist/esm/node.js.map +1 -1
  85. package/dist/esm/reify/add-edge.d.ts +4 -4
  86. package/dist/esm/reify/add-edge.d.ts.map +1 -1
  87. package/dist/esm/reify/add-edge.js +22 -11
  88. package/dist/esm/reify/add-edge.js.map +1 -1
  89. package/dist/esm/reify/add-edges.d.ts +4 -4
  90. package/dist/esm/reify/add-edges.d.ts.map +1 -1
  91. package/dist/esm/reify/add-edges.js +2 -2
  92. package/dist/esm/reify/add-edges.js.map +1 -1
  93. package/dist/esm/reify/add-nodes.d.ts +5 -5
  94. package/dist/esm/reify/add-nodes.d.ts.map +1 -1
  95. package/dist/esm/reify/add-nodes.js +10 -7
  96. package/dist/esm/reify/add-nodes.js.map +1 -1
  97. package/dist/esm/reify/bin-paths.d.ts +1 -1
  98. package/dist/esm/reify/bin-paths.d.ts.map +1 -1
  99. package/dist/esm/reify/bin-paths.js.map +1 -1
  100. package/dist/esm/reify/build.d.ts +3 -3
  101. package/dist/esm/reify/build.d.ts.map +1 -1
  102. package/dist/esm/reify/build.js +9 -9
  103. package/dist/esm/reify/build.js.map +1 -1
  104. package/dist/esm/reify/delete-edge.d.ts +3 -3
  105. package/dist/esm/reify/delete-edge.d.ts.map +1 -1
  106. package/dist/esm/reify/delete-edge.js +3 -3
  107. package/dist/esm/reify/delete-edge.js.map +1 -1
  108. package/dist/esm/reify/delete-edges.d.ts +3 -3
  109. package/dist/esm/reify/delete-edges.d.ts.map +1 -1
  110. package/dist/esm/reify/delete-edges.js +1 -1
  111. package/dist/esm/reify/delete-edges.js.map +1 -1
  112. package/dist/esm/reify/delete-nodes.d.ts +3 -3
  113. package/dist/esm/reify/delete-nodes.d.ts.map +1 -1
  114. package/dist/esm/reify/delete-nodes.js +4 -0
  115. package/dist/esm/reify/delete-nodes.js.map +1 -1
  116. package/dist/esm/reify/index.d.ts +6 -5
  117. package/dist/esm/reify/index.d.ts.map +1 -1
  118. package/dist/esm/reify/index.js +25 -19
  119. package/dist/esm/reify/index.js.map +1 -1
  120. package/dist/esm/reify/optional-fail.d.ts +2 -2
  121. package/dist/esm/reify/optional-fail.d.ts.map +1 -1
  122. package/dist/esm/reify/optional-fail.js +1 -1
  123. package/dist/esm/reify/optional-fail.js.map +1 -1
  124. package/dist/esm/reify/rollback.d.ts +2 -2
  125. package/dist/esm/reify/rollback.d.ts.map +1 -1
  126. package/dist/esm/reify/rollback.js +1 -1
  127. package/dist/esm/reify/rollback.js.map +1 -1
  128. package/dist/esm/reify/update-importers-package-json.d.ts +3 -3
  129. package/dist/esm/reify/update-importers-package-json.d.ts.map +1 -1
  130. package/dist/esm/reify/update-importers-package-json.js +25 -6
  131. package/dist/esm/reify/update-importers-package-json.js.map +1 -1
  132. package/dist/esm/remove-optional-subgraph.d.ts +2 -2
  133. package/dist/esm/remove-optional-subgraph.d.ts.map +1 -1
  134. package/dist/esm/remove-optional-subgraph.js.map +1 -1
  135. package/dist/esm/resolve-save-type.d.ts +7 -0
  136. package/dist/esm/resolve-save-type.d.ts.map +1 -0
  137. package/dist/esm/resolve-save-type.js +5 -0
  138. package/dist/esm/resolve-save-type.js.map +1 -0
  139. package/dist/esm/stringify-node.d.ts +1 -1
  140. package/dist/esm/stringify-node.d.ts.map +1 -1
  141. package/dist/esm/stringify-node.js.map +1 -1
  142. package/dist/esm/types.d.ts +13 -4
  143. package/dist/esm/types.d.ts.map +1 -1
  144. package/dist/esm/types.js.map +1 -1
  145. package/dist/esm/uninstall.d.ts +11 -0
  146. package/dist/esm/uninstall.d.ts.map +1 -0
  147. package/dist/esm/uninstall.js +26 -0
  148. package/dist/esm/uninstall.js.map +1 -0
  149. package/dist/esm/visualization/human-readable-output.d.ts +7 -7
  150. package/dist/esm/visualization/human-readable-output.d.ts.map +1 -1
  151. package/dist/esm/visualization/human-readable-output.js +35 -21
  152. package/dist/esm/visualization/human-readable-output.js.map +1 -1
  153. package/dist/esm/visualization/json-output.d.ts +4 -4
  154. package/dist/esm/visualization/json-output.d.ts.map +1 -1
  155. package/dist/esm/visualization/json-output.js +1 -1
  156. package/dist/esm/visualization/json-output.js.map +1 -1
  157. package/dist/esm/visualization/mermaid-output.d.ts +3 -3
  158. package/dist/esm/visualization/mermaid-output.d.ts.map +1 -1
  159. package/dist/esm/visualization/mermaid-output.js +2 -2
  160. package/dist/esm/visualization/mermaid-output.js.map +1 -1
  161. package/dist/esm/visualization/object-like-output.d.ts +1 -1
  162. package/dist/esm/visualization/object-like-output.d.ts.map +1 -1
  163. package/dist/esm/visualization/object-like-output.js.map +1 -1
  164. package/package.json +34 -28
@@ -1,6 +1,7 @@
1
1
  import { splitDepID } from '@vltpkg/dep-id';
2
2
  import { error } from '@vltpkg/error-cause';
3
- import { longDependencyTypes, } from '../dependencies.js';
3
+ import { longDependencyTypes } from '@vltpkg/types';
4
+ import { resolveSaveType } from "../resolve-save-type.js";
4
5
  const SAVE_PREFIX = '^';
5
6
  const depTypesMap = new Map([
6
7
  ['prod', 'dependencies'],
@@ -34,18 +35,22 @@ const addOrRemoveDeps = (importerId, graph, addOrRemove) => {
34
35
  for (const deleteNameOrAddItem of deps) {
35
36
  if (typeof deleteNameOrAddItem === 'string') {
36
37
  const name = deleteNameOrAddItem;
37
- // TODO: needs to also remove any possible peerDependenciesMeta
38
38
  for (const depType of longDependencyTypes) {
39
39
  if (manifest[depType]?.[name]) {
40
40
  delete manifest[depType][name];
41
41
  manifestChanged = true;
42
42
  }
43
43
  }
44
+ if (manifest.peerDependenciesMeta?.[name]) {
45
+ delete manifest.peerDependenciesMeta[name];
46
+ manifestChanged = true;
47
+ }
44
48
  }
45
49
  else {
46
50
  const [name, dep] = deleteNameOrAddItem;
47
- // TODO: peerOptional also needs to add peerDependenciesMeta entry
48
- const depType = depTypesMap.get(dep.type);
51
+ // peerOptional also needs to add peerDependenciesMeta entry
52
+ const depTypeShort = resolveSaveType(importer, name, dep.type);
53
+ const depType = depTypesMap.get(depTypeShort);
49
54
  if (!depType) {
50
55
  throw error('Failed to retrieve dependency type', {
51
56
  validOptions: [...depTypesMap.keys()],
@@ -57,11 +62,25 @@ const addOrRemoveDeps = (importerId, graph, addOrRemove) => {
57
62
  throw error('Dependency node could not be found');
58
63
  }
59
64
  const [nodeType] = splitDepID(node.id);
65
+ for (const dtype of longDependencyTypes) {
66
+ if (dtype === depType || !manifest[dtype])
67
+ continue;
68
+ delete manifest[dtype][name];
69
+ }
70
+ if (depTypeShort === 'peerOptional') {
71
+ manifest.peerDependenciesMeta ??= {};
72
+ manifest.peerDependenciesMeta[name] = { optional: true };
73
+ }
74
+ else if (manifest.peerDependenciesMeta?.[name]) {
75
+ delete manifest.peerDependenciesMeta[name];
76
+ }
60
77
  const dependencies = manifest[depType] ?? (manifest[depType] = {});
61
78
  dependencies[name] =
62
79
  (nodeType === 'registry' &&
63
- (!dep.spec.semver || dep.spec.range?.isSingle)) ?
64
- `${SAVE_PREFIX}${node.version}`
80
+ (!dep.spec.final.semver || !dep.spec.final.range)) ?
81
+ dep.spec.subspec && dep.spec.namedRegistry ?
82
+ `${dep.spec.final.namedRegistry}:${dep.spec.final.name}@${SAVE_PREFIX}${node.version}`
83
+ : `${SAVE_PREFIX}${node.version}`
65
84
  : dep.spec.bareSpec;
66
85
  manifestChanged = true;
67
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"update-importers-package-json.js","sourceRoot":"","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ageJson } from '@vltpkg/package-json'\nimport { type Manifest } from '@vltpkg/types'\nimport { type Graph } from '../graph.js'\nimport {\n type AddImportersDependenciesMap,\n type RemoveImportersDependenciesMap,\n type DependencyTypeLong,\n type DependencyTypeShort,\n longDependencyTypes,\n type Dependency,\n} from '../dependencies.js'\n\nconst SAVE_PREFIX = '^'\n\nconst depTypesMap = new Map<DependencyTypeShort, DependencyTypeLong>([\n ['prod', 'dependencies'],\n ['dev', 'devDependencies'],\n ['peer', 'peerDependencies'],\n ['peerOptional', 'peerDependencies'],\n ['optional', 'optionalDependencies'],\n])\n\nexport type UpdatePackageJsonOptions = {\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 * The {@link Graph} instance that contain the importer nodes to which\n * the manifest data (and it's corresponding `package.json` file) are\n * going to be updated.\n */\n graph: Graph\n /**\n * An instance of {@link PackageJson} to use when writing updated manifest\n * data to `package.json` files. It's necessary that this is the same\n * instance used to load these `package.json` files previously.\n */\n packageJson: PackageJson\n}\n\nconst addOrRemoveDeps = (\n importerId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): Manifest | undefined => {\n const importer = graph.nodes.get(importerId)\n if (!importer) {\n throw error('Failed to retrieve importer node', {\n found: importerId,\n })\n }\n const manifest = importer.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: importerId,\n })\n }\n const deps = addOrRemove?.get(importerId)\n /* c8 ignore start -- impossible but TS doesn't know that */\n if (!deps) {\n throw error('Failed to retrieve added deps info', {\n manifest,\n })\n }\n let manifestChanged = false\n /* c8 ignore stop */\n for (const deleteNameOrAddItem of deps) {\n if (typeof deleteNameOrAddItem === 'string') {\n const name = deleteNameOrAddItem\n // TODO: needs to also remove any possible peerDependenciesMeta\n for (const depType of longDependencyTypes) {\n if (manifest[depType]?.[name]) {\n delete manifest[depType][name]\n manifestChanged = true\n }\n }\n } else {\n const [name, dep] = deleteNameOrAddItem\n // TODO: peerOptional also needs to add peerDependenciesMeta entry\n const depType = depTypesMap.get(dep.type)\n if (!depType) {\n throw error('Failed to retrieve dependency type', {\n validOptions: [...depTypesMap.keys()],\n found: dep.type,\n })\n }\n const node = importer.edgesOut.get(name)?.to\n if (!node) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(node.id)\n const dependencies =\n manifest[depType] ?? (manifest[depType] = {})\n dependencies[name] =\n (\n nodeType === 'registry' &&\n (!dep.spec.semver || dep.spec.range?.isSingle)\n ) ?\n `${SAVE_PREFIX}${node.version}`\n : dep.spec.bareSpec\n manifestChanged = true\n }\n }\n return manifestChanged ? manifest : undefined\n}\n\n/**\n * Updates the importers of a provided {@link Graph} accordingly to the\n * provided add or remove arguments.\n */\nexport const updatePackageJson = ({\n add,\n graph,\n packageJson,\n remove,\n}: UpdatePackageJsonOptions) => {\n const manifestsToUpdate = new Set<Manifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n for (const importerId of operation.keys()) {\n const manifest = addOrRemoveDeps(importerId, graph, operation)\n if (manifest) {\n manifestsToUpdate.add(manifest)\n }\n }\n }\n }\n\n const commit = () => {\n for (const manifest of manifestsToUpdate) {\n packageJson.save(manifest)\n }\n }\n\n return commit\n}\n"]}
1
+ {"version":3,"file":"update-importers-package-json.js","sourceRoot":"","sources":["../../../src/reify/update-importers-package-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAO3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAO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;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,GAAG,EACH,KAAK,EACL,WAAW,EACX,MAAM,GACmB,EAAE,EAAE;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAY,CAAA;IAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;IAEzC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,EAAE,CAAC;YACd,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC1C,MAAM,QAAQ,GAAG,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;gBAC9D,IAAI,QAAQ,EAAE,CAAC;oBACb,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACzC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { splitDepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type {\n DependencyTypeLong,\n DependencyTypeShort,\n Manifest,\n} from '@vltpkg/types'\nimport { longDependencyTypes } from '@vltpkg/types'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '../dependencies.ts'\nimport type { Graph } from '../graph.ts'\nimport { resolveSaveType } from '../resolve-save-type.ts'\n\nconst SAVE_PREFIX = '^'\n\nconst depTypesMap = new Map<DependencyTypeShort, DependencyTypeLong>([\n ['prod', 'dependencies'],\n ['dev', 'devDependencies'],\n ['peer', 'peerDependencies'],\n ['peerOptional', 'peerDependencies'],\n ['optional', 'optionalDependencies'],\n])\n\nexport type UpdatePackageJsonOptions = {\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 * The {@link Graph} instance that contain the importer nodes to which\n * the manifest data (and it's corresponding `package.json` file) are\n * going to be updated.\n */\n graph: Graph\n /**\n * An instance of {@link PackageJson} to use when writing updated manifest\n * data to `package.json` files. It's necessary that this is the same\n * instance used to load these `package.json` files previously.\n */\n packageJson: PackageJson\n}\n\nconst addOrRemoveDeps = (\n importerId: DepID,\n graph: Graph,\n addOrRemove?:\n | AddImportersDependenciesMap\n | RemoveImportersDependenciesMap,\n): Manifest | undefined => {\n const importer = graph.nodes.get(importerId)\n if (!importer) {\n throw error('Failed to retrieve importer node', {\n found: importerId,\n })\n }\n const manifest = importer.manifest\n if (!manifest) {\n throw error('Could not find manifest data for node', {\n found: importerId,\n })\n }\n const deps = addOrRemove?.get(importerId)\n /* c8 ignore start -- impossible but TS doesn't know that */\n if (!deps) {\n throw error('Failed to retrieve added deps info', {\n manifest,\n })\n }\n let manifestChanged = false\n /* c8 ignore stop */\n for (const deleteNameOrAddItem of deps) {\n if (typeof deleteNameOrAddItem === 'string') {\n const name = deleteNameOrAddItem\n for (const depType of longDependencyTypes) {\n if (manifest[depType]?.[name]) {\n delete manifest[depType][name]\n manifestChanged = true\n }\n }\n if (manifest.peerDependenciesMeta?.[name]) {\n delete manifest.peerDependenciesMeta[name]\n manifestChanged = true\n }\n } else {\n const [name, dep] = deleteNameOrAddItem\n // peerOptional also needs to add peerDependenciesMeta entry\n const depTypeShort = resolveSaveType(importer, name, dep.type)\n const depType = depTypesMap.get(depTypeShort)\n if (!depType) {\n throw error('Failed to retrieve dependency type', {\n validOptions: [...depTypesMap.keys()],\n found: dep.type,\n })\n }\n const node = importer.edgesOut.get(name)?.to\n if (!node) {\n throw error('Dependency node could not be found')\n }\n const [nodeType] = splitDepID(node.id)\n\n for (const dtype of longDependencyTypes) {\n if (dtype === depType || !manifest[dtype]) continue\n delete manifest[dtype][name]\n }\n if (depTypeShort === 'peerOptional') {\n manifest.peerDependenciesMeta ??= {}\n manifest.peerDependenciesMeta[name] = { optional: true }\n } else if (manifest.peerDependenciesMeta?.[name]) {\n delete manifest.peerDependenciesMeta[name]\n }\n\n const dependencies =\n manifest[depType] ?? (manifest[depType] = {})\n dependencies[name] =\n (\n nodeType === 'registry' &&\n (!dep.spec.final.semver || !dep.spec.final.range)\n ) ?\n dep.spec.subspec && dep.spec.namedRegistry ?\n `${dep.spec.final.namedRegistry}:${dep.spec.final.name}@${SAVE_PREFIX}${node.version}`\n : `${SAVE_PREFIX}${node.version}`\n : dep.spec.bareSpec\n manifestChanged = true\n }\n }\n return manifestChanged ? manifest : undefined\n}\n\n/**\n * Updates the importers of a provided {@link Graph} accordingly to the\n * provided add or remove arguments.\n */\nexport const updatePackageJson = ({\n add,\n graph,\n packageJson,\n remove,\n}: UpdatePackageJsonOptions) => {\n const manifestsToUpdate = new Set<Manifest>()\n const operations = new Set([add, remove])\n\n for (const operation of operations) {\n if (operation) {\n for (const importerId of operation.keys()) {\n const manifest = addOrRemoveDeps(importerId, graph, operation)\n if (manifest) {\n manifestsToUpdate.add(manifest)\n }\n }\n }\n }\n\n const commit = () => {\n for (const manifest of manifestsToUpdate) {\n packageJson.save(manifest)\n }\n }\n\n return commit\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { type Graph } from './graph.js';
2
- import { type Node } from './node.js';
1
+ import type { Graph } from './graph.ts';
2
+ import type { Node } from './node.ts';
3
3
  /**
4
4
  * Remove the affected optional nodes starting from a given optional node
5
5
  * that failed to resolve/install.
@@ -1 +1 @@
1
- {"version":3,"file":"remove-optional-subgraph.d.ts","sourceRoot":"","sources":["../../src/remove-optional-subgraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,UAC1B,KAAK,gBACE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,cAQxC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAiB,oBAAoB,CACnC,IAAI,EAAE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,EAC/B,IAAI;cAA8B,IAAI;EAAK,GAC1C,SAAS,CAAC,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,EAAE,IAAI,CAAC,CAiB5C"}
1
+ {"version":3,"file":"remove-optional-subgraph.d.ts","sourceRoot":"","sources":["../../src/remove-optional-subgraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,UAC1B,KAAK,gBACE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,cAQxC,CAAA;AAED;;;;;;;GAOG;AACH,wBAAiB,oBAAoB,CACnC,IAAI,EAAE,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,EAC/B,IAAI;cAA8B,IAAI;EAAK,GAC1C,SAAS,CAAC,IAAI,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,EAAE,IAAI,CAAC,CAiB5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"remove-optional-subgraph.js","sourceRoot":"","sources":["../../src/remove-optional-subgraph.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,KAAY,EACZ,YAAuC,EACvC,EAAE;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAQ,CAAA;IAC/B,KAAK,MAAM,IAAI,IAAI,oBAAoB,CAAC,YAAY,CAAC,EAAE,CAAC;QACtD,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACnB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,oBAAoB,CACnC,IAA+B,EAC/B,OAAO,IAAI,GAAG,EAA6B;IAE3C,mCAAmC;IACnC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAM;IAE1B,qDAAqD;IACrD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACd,MAAM,IAAI,CAAA;IAEV,mDAAmD;IACnD,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9C,qEAAqE;QACrE,oEAAoE;QACpE,2CAA2C;QAC3C,IAAI,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,KAAK,MAAM,GAAG,IAAI,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC;gBAAE,MAAM,GAAG,CAAA;QAC/D,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { type Graph } from './graph.js'\nimport { type Node } from './node.js'\n\n/**\n * Remove the affected optional nodes starting from a given optional node\n * that failed to resolve/install.\n *\n * Removing these dependents will frequently leave optional *dependencies*\n * behind that are made unreachable from any project importer. For performance\n * reasons, `graph.gc()` is not called automatically by this method, since\n * multiple optional subgraphs may need to be removed in a single operation,\n * and the mark-and-sweep garbage collection (a) can be excessively expensive,\n * and (b) may need to communicate the set of garbage-collected nodes\n * for cleanup (as in the case of optional node build failures during\n * reification).\n */\nexport const removeOptionalSubgraph = (\n graph: Graph,\n startingNode: Node & { optional: true },\n) => {\n const removed = new Set<Node>()\n for (const node of findOptionalSubgraph(startingNode)) {\n graph.removeNode(node)\n removed.add(node)\n }\n return removed\n}\n\n/**\n * Given a starting node, this generator will walk back from the optional node\n * to all of its optional dependents, emitting each one, and skipping any\n * cycles.\n *\n * Note that when these are removed, it may create unreachable nodes in the\n * graph! Be sure to call `graph.gc()` if these are removed.\n */\nexport function* findOptionalSubgraph(\n node: Node & { optional: true },\n seen = new Set<Node & { optional: true }>(),\n): Generator<Node & { optional: true }, void> {\n // already visited, prevent looping\n if (seen.has(node)) return\n\n // the node itself is part of the subgraph, of course\n seen.add(node)\n yield node\n\n // and any of its dependents that are also optional\n for (const { from, optional } of node.edgesIn) {\n // if it's an optional *edge*, we don't need to remove it, because it\n // doesn't need the node anyway. But if the node is optional and the\n // dep isn't, then we do need to remove it.\n if (from.isOptional() && !optional) {\n for (const dep of findOptionalSubgraph(from, seen)) yield dep\n }\n }\n}\n"]}
1
+ {"version":3,"file":"remove-optional-subgraph.js","sourceRoot":"","sources":["../../src/remove-optional-subgraph.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,KAAY,EACZ,YAAuC,EACvC,EAAE;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAQ,CAAA;IAC/B,KAAK,MAAM,IAAI,IAAI,oBAAoB,CAAC,YAAY,CAAC,EAAE,CAAC;QACtD,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACnB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,oBAAoB,CACnC,IAA+B,EAC/B,OAAO,IAAI,GAAG,EAA6B;IAE3C,mCAAmC;IACnC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAM;IAE1B,qDAAqD;IACrD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACd,MAAM,IAAI,CAAA;IAEV,mDAAmD;IACnD,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9C,qEAAqE;QACrE,oEAAoE;QACpE,2CAA2C;QAC3C,IAAI,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,KAAK,MAAM,GAAG,IAAI,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC;gBAAE,MAAM,GAAG,CAAA;QAC/D,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Graph } from './graph.ts'\nimport type { Node } from './node.ts'\n\n/**\n * Remove the affected optional nodes starting from a given optional node\n * that failed to resolve/install.\n *\n * Removing these dependents will frequently leave optional *dependencies*\n * behind that are made unreachable from any project importer. For performance\n * reasons, `graph.gc()` is not called automatically by this method, since\n * multiple optional subgraphs may need to be removed in a single operation,\n * and the mark-and-sweep garbage collection (a) can be excessively expensive,\n * and (b) may need to communicate the set of garbage-collected nodes\n * for cleanup (as in the case of optional node build failures during\n * reification).\n */\nexport const removeOptionalSubgraph = (\n graph: Graph,\n startingNode: Node & { optional: true },\n) => {\n const removed = new Set<Node>()\n for (const node of findOptionalSubgraph(startingNode)) {\n graph.removeNode(node)\n removed.add(node)\n }\n return removed\n}\n\n/**\n * Given a starting node, this generator will walk back from the optional node\n * to all of its optional dependents, emitting each one, and skipping any\n * cycles.\n *\n * Note that when these are removed, it may create unreachable nodes in the\n * graph! Be sure to call `graph.gc()` if these are removed.\n */\nexport function* findOptionalSubgraph(\n node: Node & { optional: true },\n seen = new Set<Node & { optional: true }>(),\n): Generator<Node & { optional: true }, void> {\n // already visited, prevent looping\n if (seen.has(node)) return\n\n // the node itself is part of the subgraph, of course\n seen.add(node)\n yield node\n\n // and any of its dependents that are also optional\n for (const { from, optional } of node.edgesIn) {\n // if it's an optional *edge*, we don't need to remove it, because it\n // doesn't need the node anyway. But if the node is optional and the\n // dep isn't, then we do need to remove it.\n if (from.isOptional() && !optional) {\n for (const dep of findOptionalSubgraph(from, seen)) yield dep\n }\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { DependencySaveType, DependencyTypeShort } from '@vltpkg/types';
2
+ import type { NodeLike } from './types.ts';
3
+ /**
4
+ * Resolve a {@link DependencySaveType} to a {@link DependencyTypeShort}
5
+ */
6
+ export declare const resolveSaveType: (node: NodeLike, name: string, saveType: DependencySaveType) => DependencyTypeShort;
7
+ //# sourceMappingURL=resolve-save-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-save-type.d.ts","sourceRoot":"","sources":["../../src/resolve-save-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C;;GAEG;AACH,eAAO,MAAM,eAAe,SACpB,QAAQ,QACR,MAAM,YACF,kBAAkB,KAC3B,mBAGA,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Resolve a {@link DependencySaveType} to a {@link DependencyTypeShort}
3
+ */
4
+ export const resolveSaveType = (node, name, saveType) => saveType !== 'implicit' ? saveType : ((node.edgesOut.get(name)?.type ?? 'prod'));
5
+ //# sourceMappingURL=resolve-save-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-save-type.js","sourceRoot":"","sources":["../../src/resolve-save-type.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,IAAc,EACd,IAAY,EACZ,QAA4B,EACP,EAAE,CACvB,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CACnC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,MAAM,CAAC,CAC1C,CAAA","sourcesContent":["import type {\n DependencySaveType,\n DependencyTypeShort,\n} from '@vltpkg/types'\nimport type { NodeLike } from './types.ts'\n\n/**\n * Resolve a {@link DependencySaveType} to a {@link DependencyTypeShort}\n */\nexport const resolveSaveType = (\n node: NodeLike,\n name: string,\n saveType: DependencySaveType,\n): DependencyTypeShort =>\n saveType !== 'implicit' ? saveType : (\n (node.edgesOut.get(name)?.type ?? 'prod')\n )\n"]}
@@ -1,3 +1,3 @@
1
- import { type NodeLike } from './types.js';
1
+ import type { NodeLike } from './types.ts';
2
2
  export declare const stringifyNode: (node?: NodeLike) => string;
3
3
  //# sourceMappingURL=stringify-node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-node.d.ts","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,eAAO,MAAM,aAAa,UAAW,QAAQ,WAmB5C,CAAA"}
1
+ {"version":3,"file":"stringify-node.d.ts","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,eAAO,MAAM,aAAa,UAAW,QAAQ,WAmB5C,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"stringify-node.js","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGnD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAe,EAAE,EAAE;IAC/C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEpD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;QACvC,OAAO,GAAG,MAAM,GAAG,WAAW,EAAE,CAAA;IAClC,CAAC;SAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAA;IACjC,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QAChD,OAAO,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,yEAAyE;QACzE,MAAM,WAAW,GACf,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACxD,OAAO,GAAG,IAAI,IAAI,GAAG,IAAI,WAAW,EAAE,CAAA;IACxC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport { type NodeLike } from './types.js'\n\nexport const stringifyNode = (node?: NodeLike) => {\n if (!node) return ''\n const version = node.version ? `@${node.version}` : ''\n const [type, ref, nameVersion] = splitDepID(node.id)\n\n if (type === 'registry') {\n const prefix = ref ? `${ref}:` : 'npm:'\n return `${prefix}${nameVersion}`\n } else if (type === 'workspace') {\n return `workspace:${node.name}`\n } else if (type === 'file' && node.mainImporter) {\n return `root:${node.name}`\n } else {\n // node.name getter will return the id if the package has no name\n // property so here we check for that in order to return `type(ref)` only\n const nameVersion =\n node.name !== node.id ? `:${node.name}${version}` : ''\n return `${type}(${ref})${nameVersion}`\n }\n}\n"]}
1
+ {"version":3,"file":"stringify-node.js","sourceRoot":"","sources":["../../src/stringify-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAGnD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAe,EAAE,EAAE;IAC/C,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtD,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEpD,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;QACvC,OAAO,GAAG,MAAM,GAAG,WAAW,EAAE,CAAA;IAClC,CAAC;SAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAA;IACjC,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QAChD,OAAO,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,yEAAyE;QACzE,MAAM,WAAW,GACf,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QACxD,OAAO,GAAG,IAAI,IAAI,GAAG,IAAI,WAAW,EAAE,CAAA;IACxC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id/browser'\nimport type { NodeLike } from './types.ts'\n\nexport const stringifyNode = (node?: NodeLike) => {\n if (!node) return ''\n const version = node.version ? `@${node.version}` : ''\n const [type, ref, nameVersion] = splitDepID(node.id)\n\n if (type === 'registry') {\n const prefix = ref ? `${ref}:` : 'npm:'\n return `${prefix}${nameVersion}`\n } else if (type === 'workspace') {\n return `workspace:${node.name}`\n } else if (type === 'file' && node.mainImporter) {\n return `root:${node.name}`\n } else {\n // node.name getter will return the id if the package has no name\n // property so here we check for that in order to return `type(ref)` only\n const nameVersion =\n node.name !== node.id ? `:${node.name}${version}` : ''\n return `${type}(${ref})${nameVersion}`\n }\n}\n"]}
@@ -1,13 +1,14 @@
1
- import { type DepID } from '@vltpkg/dep-id';
2
- import { type Manifest } from '@vltpkg/types';
3
- import { type Spec, type SpecLikeBase } from '@vltpkg/spec';
4
- import { type DependencyTypeShort } from './dependencies.js';
1
+ import type { DepID } from '@vltpkg/dep-id';
2
+ import type { Manifest, DependencyTypeShort } from '@vltpkg/types';
3
+ import type { Spec, SpecLikeBase } from '@vltpkg/spec';
5
4
  export type EdgeLike = {
6
5
  name: string;
7
6
  from: NodeLike;
8
7
  spec: SpecLikeBase;
9
8
  to?: NodeLike;
10
9
  type: DependencyTypeShort;
10
+ optional?: boolean;
11
+ peer?: boolean;
11
12
  };
12
13
  export type GraphLike = {
13
14
  importers: Set<NodeLike>;
@@ -20,10 +21,12 @@ export type GraphLike = {
20
21
  };
21
22
  export type NodeLike = {
22
23
  id: DepID;
24
+ confused: boolean;
23
25
  edgesIn: Set<EdgeLike>;
24
26
  edgesOut: Map<string, EdgeLike>;
25
27
  location?: string;
26
28
  manifest?: Manifest | null;
29
+ rawManifest?: Manifest | null;
27
30
  name?: string | null;
28
31
  version?: string | null;
29
32
  integrity?: string | null;
@@ -34,5 +37,11 @@ export type NodeLike = {
34
37
  projectRoot: string;
35
38
  dev: boolean;
36
39
  optional: boolean;
40
+ toJSON: () => Pick<NodeLike, 'id' | 'name' | 'version' | 'location' | 'importer' | 'manifest' | 'projectRoot' | 'integrity' | 'resolved' | 'dev' | 'optional' | 'confused'> & {
41
+ rawManifest?: NodeLike['manifest'];
42
+ };
43
+ toString(): string;
44
+ setResolved(): void;
45
+ setConfusedManifest(fixed: Manifest, confused?: Manifest): void;
37
46
  };
38
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE5D,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,YAAY,CAAA;IAClB,EAAE,CAAC,EAAE,QAAQ,CAAA;IACb,IAAI,EAAE,mBAAmB,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,YAAY,EAAE,QAAQ,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC3B,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACpB,OAAO,EAAE,CACP,IAAI,EAAE,mBAAmB,EACzB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,QAAQ,EACd,EAAE,CAAC,EAAE,QAAQ,KACV,Q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;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,SAAS,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,OAAO,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,MAAM,IAAI,CAChB,QAAQ,EACN,IAAI,GACJ,MAAM,GACN,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,aAAa,GACb,WAAW,GACX,UAAU,GACV,KAAK,GACL,UAAU,GACV,UAAU,CACb,GAAG;QACF,WAAW,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;KACnC,CAAA;IACD,QAAQ,IAAI,MAAM,CAAA;IAClB,WAAW,IAAI,IAAI,CAAA;IACnB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;CAChE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { type DepID } from '@vltpkg/dep-id'\nimport { type Manifest } from '@vltpkg/types'\nimport { type Spec, type SpecLikeBase } from '@vltpkg/spec'\nimport { type DependencyTypeShort } from './dependencies.js'\n\nexport type EdgeLike = {\n name: string\n from: NodeLike\n spec: SpecLikeBase\n to?: NodeLike\n type: DependencyTypeShort\n}\n\nexport type GraphLike = {\n importers: Set<NodeLike>\n mainImporter: NodeLike\n projectRoot: string\n nodes: Map<DepID, NodeLike>\n edges: Set<EdgeLike>\n addEdge: (\n type: DependencyTypeShort,\n spec: Spec,\n from: NodeLike,\n to?: NodeLike,\n ) => EdgeLike\n addNode: (\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) => NodeLike\n}\n\nexport type NodeLike = {\n id: DepID\n edgesIn: Set<EdgeLike>\n edgesOut: Map<string, EdgeLike>\n location?: string\n manifest?: Manifest | null\n name?: string | null\n version?: string | null\n integrity?: string | null\n resolved?: string | null\n importer: boolean\n graph: GraphLike\n mainImporter: boolean\n projectRoot: string\n dev: boolean\n optional: boolean\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { Manifest, DependencyTypeShort } from '@vltpkg/types'\nimport type { Spec, SpecLikeBase } from '@vltpkg/spec'\n\nexport type EdgeLike = {\n name: string\n from: NodeLike\n spec: SpecLikeBase\n to?: NodeLike\n type: DependencyTypeShort\n optional?: boolean\n peer?: boolean\n}\n\nexport type GraphLike = {\n importers: Set<NodeLike>\n mainImporter: NodeLike\n projectRoot: string\n nodes: Map<DepID, NodeLike>\n edges: Set<EdgeLike>\n addEdge: (\n type: DependencyTypeShort,\n spec: Spec,\n from: NodeLike,\n to?: NodeLike,\n ) => EdgeLike\n addNode: (\n id?: DepID,\n manifest?: Manifest,\n spec?: Spec,\n name?: string,\n version?: string,\n ) => NodeLike\n}\n\nexport type NodeLike = {\n id: DepID\n confused: boolean\n edgesIn: Set<EdgeLike>\n edgesOut: Map<string, EdgeLike>\n location?: string\n manifest?: Manifest | null\n rawManifest?: Manifest | null\n name?: string | null\n version?: string | null\n integrity?: string | null\n resolved?: string | null\n importer: boolean\n graph: GraphLike\n mainImporter: boolean\n projectRoot: string\n dev: boolean\n optional: boolean\n toJSON: () => Pick<\n NodeLike,\n | 'id'\n | 'name'\n | 'version'\n | 'location'\n | 'importer'\n | 'manifest'\n | 'projectRoot'\n | 'integrity'\n | 'resolved'\n | 'dev'\n | 'optional'\n | 'confused'\n > & {\n rawManifest?: NodeLike['manifest']\n }\n toString(): string\n setResolved(): void\n setConfusedManifest(fixed: Manifest, confused?: Manifest): void\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import type { PackageInfoClient } from '@vltpkg/package-info';
2
+ import type { LoadOptions } from './actual/load.ts';
3
+ import type { RemoveImportersDependenciesMap } from './dependencies.ts';
4
+ export type UninstallOptions = LoadOptions & {
5
+ packageInfo: PackageInfoClient;
6
+ };
7
+ export declare const uninstall: (options: UninstallOptions, remove?: RemoveImportersDependenciesMap) => Promise<{
8
+ graph: import("./graph.ts").Graph;
9
+ diff: import("./diff.ts").Diff;
10
+ }>;
11
+ //# sourceMappingURL=uninstall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.d.ts","sourceRoot":"","sources":["../../src/uninstall.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAA;AAIvE,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAC3C,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED,eAAO,MAAM,SAAS,YACX,gBAAgB,WAChB,8BAA8B;;;EAwBxC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { load as actualLoad } from "./actual/load.js";
2
+ import { build as idealBuild } from "./ideal/build.js";
3
+ import { reify } from "./reify/index.js";
4
+ export const uninstall = async (options, remove) => {
5
+ const mainManifest = options.packageJson.read(options.projectRoot);
6
+ const graph = await idealBuild({
7
+ ...options,
8
+ remove,
9
+ mainManifest,
10
+ loadManifests: true,
11
+ });
12
+ const act = actualLoad({
13
+ ...options,
14
+ mainManifest,
15
+ loadManifests: true,
16
+ });
17
+ const diff = await reify({
18
+ ...options,
19
+ remove,
20
+ actual: act,
21
+ graph,
22
+ loadManifests: true,
23
+ });
24
+ return { graph, diff };
25
+ };
26
+ //# sourceMappingURL=uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../src/uninstall.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAMxC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,OAAyB,EACzB,MAAuC,EACvC,EAAE;IACF,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAElE,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC;QAC7B,GAAG,OAAO;QACV,MAAM;QACN,YAAY;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC,CAAA;IACF,MAAM,GAAG,GAAG,UAAU,CAAC;QACrB,GAAG,OAAO;QACV,YAAY;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC,CAAA;IACF,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC;QACvB,GAAG,OAAO;QACV,MAAM;QACN,MAAM,EAAE,GAAG;QACX,KAAK;QACL,aAAa,EAAE,IAAI;KACpB,CAAC,CAAA;IAEF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AACxB,CAAC,CAAA","sourcesContent":["import type { PackageInfoClient } from '@vltpkg/package-info'\nimport type { LoadOptions } from './actual/load.ts'\nimport { load as actualLoad } from './actual/load.ts'\nimport type { RemoveImportersDependenciesMap } from './dependencies.ts'\nimport { build as idealBuild } from './ideal/build.ts'\nimport { reify } from './reify/index.ts'\n\nexport type UninstallOptions = LoadOptions & {\n packageInfo: PackageInfoClient\n}\n\nexport const uninstall = async (\n options: UninstallOptions,\n remove?: RemoveImportersDependenciesMap,\n) => {\n const mainManifest = options.packageJson.read(options.projectRoot)\n\n const graph = await idealBuild({\n ...options,\n remove,\n mainManifest,\n loadManifests: true,\n })\n const act = actualLoad({\n ...options,\n mainManifest,\n loadManifests: true,\n })\n const diff = await reify({\n ...options,\n remove,\n actual: act,\n graph,\n loadManifests: true,\n })\n\n return { graph, diff }\n}\n"]}
@@ -1,5 +1,4 @@
1
- import { type EdgeLike, type NodeLike } from '../types.js';
2
- import { type ChalkInstance } from 'chalk';
1
+ import type { EdgeLike, NodeLike } from '../types.ts';
3
2
  export type TreeItem = {
4
3
  name?: string | null;
5
4
  edge: EdgeLike | undefined;
@@ -7,21 +6,22 @@ export type TreeItem = {
7
6
  prefix: string;
8
7
  padding: string;
9
8
  hasSibling: boolean;
10
- deduped: boolean;
9
+ seen: boolean;
11
10
  include: boolean;
12
11
  parent: TreeItem | undefined;
13
12
  };
14
- export type HumanReadableOutputOptions = {
13
+ export type HumanReadableOutputGraph = {
15
14
  edges: EdgeLike[];
16
15
  importers: Set<NodeLike>;
17
16
  nodes: NodeLike[];
18
- colors?: ChalkInstance;
19
- highlightSelection: boolean;
17
+ highlightSelection?: boolean;
20
18
  };
21
19
  export type EdgeMap = Map<NodeLike | undefined, TreeItem>;
22
20
  export type TreeMap = Map<EdgeLike | undefined, EdgeMap>;
23
21
  /**
24
22
  * Returns a human-readable output of the graph.
25
23
  */
26
- export declare function humanReadableOutput(options: HumanReadableOutputOptions): string | null | undefined;
24
+ export declare function humanReadableOutput(options: HumanReadableOutputGraph, { colors }: {
25
+ colors?: boolean;
26
+ }): string;
27
27
  //# sourceMappingURL=human-readable-output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"human-readable-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAY1C,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC1B,IAAI,EAAE,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7B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAA;AAEzD,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,SAAS,EAAE,OAAO,CAAC,CAAA;AA2DxD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,wBAAwB,EACjC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,UA6GjC"}
@@ -1,4 +1,9 @@
1
1
  import { splitDepID } from '@vltpkg/dep-id';
2
+ import { styleText as utilStyleText } from 'node:util';
3
+ const styleText = (format, s) => {
4
+ // @ts-expect-error -- styleText 3rd argument is not in types/node
5
+ return utilStyleText(format, s, { validateStream: false });
6
+ };
2
7
  const chars = new Map(Object.entries({
3
8
  connection: '─',
4
9
  down: '│',
@@ -18,7 +23,7 @@ const getTreeItems = (initialItems, options) => {
18
23
  for (const item of traverse) {
19
24
  if (item.node) {
20
25
  if (seenNodes.has(item.node)) {
21
- item.deduped = true;
26
+ item.seen = true;
22
27
  continue;
23
28
  }
24
29
  seenNodes.add(item.node);
@@ -31,7 +36,7 @@ const getTreeItems = (initialItems, options) => {
31
36
  hasSibling: false,
32
37
  padding: '',
33
38
  prefix: '',
34
- deduped: false,
39
+ seen: false,
35
40
  include: isSelected(options, edge, edge.to),
36
41
  parent: item,
37
42
  };
@@ -51,10 +56,13 @@ const getTreeItems = (initialItems, options) => {
51
56
  /**
52
57
  * Returns a human-readable output of the graph.
53
58
  */
54
- export function humanReadableOutput(options) {
55
- const { colors, importers } = options;
56
- const noop = (s) => s;
57
- const { dim = noop, red = noop, reset = noop, yellow = noop, } = colors ?? {};
59
+ export function humanReadableOutput(options, { colors }) {
60
+ const { importers } = options;
61
+ const createStyleText = (style) => (s) => colors ? styleText(style, s) : s;
62
+ const dim = createStyleText('dim');
63
+ const red = createStyleText('red');
64
+ const reset = createStyleText('reset');
65
+ const yellow = createStyleText('yellow');
58
66
  const initialItems = new Set();
59
67
  for (const importer of importers) {
60
68
  initialItems.add({
@@ -64,7 +72,7 @@ export function humanReadableOutput(options) {
64
72
  prefix: '',
65
73
  padding: '',
66
74
  hasSibling: false,
67
- deduped: false,
75
+ seen: false,
68
76
  include: isSelected(options, undefined, importer),
69
77
  parent: undefined,
70
78
  });
@@ -74,11 +82,10 @@ export function humanReadableOutput(options) {
74
82
  const traverse = (item) => {
75
83
  let header = '';
76
84
  let content = '';
77
- const depIdTuple = item.node?.id && splitDepID(item.node.id);
78
- const hasCustomReg = depIdTuple?.[0] === 'registry' && depIdTuple[1];
79
- const name = hasCustomReg ? `${depIdTuple[1]}:${item.name}` : item.name;
85
+ const name = item.name;
80
86
  const decoratedName = (options.highlightSelection &&
81
- isSelected(options, item.edge, item.node)) ?
87
+ isSelected(options, item.edge, item.node) &&
88
+ name) ?
82
89
  yellow(name)
83
90
  : name;
84
91
  if (!item.node && item.include) {
@@ -87,10 +94,9 @@ export function humanReadableOutput(options) {
87
94
  : red('(missing)');
88
95
  return `${item.padding}${item.prefix}${decoratedName} ${missing}\n`;
89
96
  }
90
- const deduped = item.deduped ? ` ${dim('(deduped)')}` : '';
91
- header += `${item.padding}${item.prefix}${decoratedName}${deduped}\n`;
92
- // deduped items need not to be printed or traversed
93
- if (!item.deduped) {
97
+ header += `${item.padding}${item.prefix}${decoratedName}\n`;
98
+ // seen items need not to be printed or traversed
99
+ if (!item.seen) {
94
100
  const edges = item.node ? [...item.node.edgesOut.values()] : [];
95
101
  const nextItems = edges.map(i => treeItems.get(i)?.get(i.to));
96
102
  const includedItems = nextItems.filter(i => i?.include);
@@ -100,15 +106,23 @@ export function humanReadableOutput(options) {
100
106
  continue;
101
107
  const parent = item;
102
108
  const isLast = includedItems.indexOf(nextItem) === includedItems.length - 1;
103
- const toName = nextItem.node?.version ?
104
- `${nextItem.node.name}@${nextItem.node.version}`
109
+ // prefixes the node name with the registry name
110
+ // if a custom registry name is found
111
+ const depIdTuple = nextItem.node?.id && splitDepID(nextItem.node.id);
112
+ const hasCustomReg = depIdTuple?.[0] === 'registry' && depIdTuple[1];
113
+ const nodeName = hasCustomReg ?
114
+ `${depIdTuple[1]}:${nextItem.node?.name}`
105
115
  : nextItem.node?.name;
116
+ const toName = nextItem.node?.version ?
117
+ `${nodeName}@${nextItem.node.version}`
118
+ : nodeName;
106
119
  const nextChar = isLast ? 'last-child' : 'middle-child';
107
120
  nextItem.name =
108
- (nextItem.node?.name &&
109
- nextItem.edge?.name !== nextItem.edge?.to?.name) ?
110
- `${nextItem.edge?.name} (${toName})`
111
- : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`;
121
+ nextItem.node?.confused ?
122
+ `${nextItem.edge?.name} ${red('(confused)')}`
123
+ : nextItem.node?.name && nextItem.edge?.name !== nodeName ?
124
+ `${nextItem.edge?.name} (${toName})`
125
+ : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`;
112
126
  nextItem.padding =
113
127
  parent.prefix.length ?
114
128
  `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `
@@ -1 +1 @@
1
- {"version":3,"file":"human-readable-output.js","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,OAAO,CAAC;IACb,UAAU,EAAE,GAAG;IACf,IAAI,EAAE,GAAG;IACT,YAAY,EAAE,GAAG;IACjB,cAAc,EAAE,GAAG;IACnB,CAAC,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AAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACjB,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE;YACvF,CAAC,CAAC,EAAE,CAAA;IACR,CAAC,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport { type EdgeLike, type NodeLike } from '../types.js'\nimport { type ChalkInstance } from 'chalk'\n\nconst chars = new Map(\n Object.entries({\n connection: '─',\n down: '│',\n 'last-child': '└',\n 'middle-child': '├',\n t: '┬',\n }),\n)\n\nexport type TreeItem = {\n name?: string | null\n edge: EdgeLike | undefined\n node: NodeLike | undefined\n prefix: string\n padding: string\n hasSibling: boolean\n deduped: boolean\n include: boolean\n parent: TreeItem | undefined\n}\n\nexport type HumanReadableOutputOptions = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n colors?: ChalkInstance\n highlightSelection: boolean\n}\n\nexport type EdgeMap = Map<NodeLike | undefined, TreeItem>\n\nexport type TreeMap = Map<EdgeLike | undefined, EdgeMap>\n\nconst isSelected = (\n options: HumanReadableOutputOptions,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n !!(\n (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\n )\n\n/**\n * Returns a map of tree items to be printed.\n */\nconst getTreeItems = (\n initialItems: Set<TreeItem>,\n options: HumanReadableOutputOptions,\n) => {\n const seenNodes = new Set<NodeLike>()\n const treeItems: TreeMap = new Map()\n const traverse = new Set<TreeItem>(initialItems)\n for (const item of traverse) {\n if (item.node) {\n if (seenNodes.has(item.node)) {\n item.deduped = true\n continue\n }\n seenNodes.add(item.node)\n const edges = [...item.node.edgesOut.values()].sort(i =>\n Number(i.to?.importer),\n )\n for (const edge of edges) {\n const toItems: EdgeMap =\n treeItems.get(edge) ?? (new Map() as EdgeMap)\n const nextItem: TreeItem = {\n edge,\n node: edge.to,\n hasSibling: false,\n padding: '',\n prefix: '',\n deduped: false,\n include: isSelected(options, edge, edge.to),\n parent: item,\n }\n toItems.set(edge.to, nextItem)\n treeItems.set(edge, toItems)\n traverse.add(nextItem)\n }\n }\n }\n for (const item of [...traverse].reverse()) {\n if (item.include && item.parent) {\n item.parent.include = true\n }\n }\n return treeItems\n}\n\n/**\n * Returns a human-readable output of the graph.\n */\nexport function humanReadableOutput(\n options: HumanReadableOutputOptions,\n) {\n const { colors, importers } = options\n const noop = (s?: string | null) => s\n const {\n dim = noop,\n red = noop,\n reset = noop,\n yellow = noop,\n } = colors ?? {}\n const initialItems = new Set<TreeItem>()\n for (const importer of importers) {\n initialItems.add({\n name: importer.name,\n edge: undefined,\n node: importer,\n prefix: '',\n padding: '',\n hasSibling: false,\n deduped: false,\n include: isSelected(options, undefined, importer),\n parent: undefined,\n })\n }\n const treeItems = getTreeItems(initialItems, options)\n\n let res = ''\n const traverse = (item: TreeItem) => {\n let header = ''\n let content = ''\n\n const depIdTuple = item.node?.id && splitDepID(item.node.id)\n const hasCustomReg =\n depIdTuple?.[0] === 'registry' && depIdTuple[1]\n const name =\n hasCustomReg ? `${depIdTuple[1]}:${item.name}` : item.name\n const decoratedName =\n (\n options.highlightSelection &&\n isSelected(options, item.edge, item.node)\n ) ?\n yellow(name)\n : name\n if (!item.node && item.include) {\n const missing =\n item.edge?.type.endsWith('ptional') ?\n dim('(missing optional)')\n : red('(missing)')\n return `${item.padding}${item.prefix}${decoratedName} ${missing}\\n`\n }\n\n const deduped = item.deduped ? ` ${dim('(deduped)')}` : ''\n header += `${item.padding}${item.prefix}${decoratedName}${deduped}\\n`\n\n // deduped items need not to be printed or traversed\n if (!item.deduped) {\n const edges = item.node ? [...item.node.edgesOut.values()] : []\n const nextItems = edges.map(i => treeItems.get(i)?.get(i.to))\n const includedItems = nextItems.filter(i => i?.include)\n\n for (const nextItem of nextItems) {\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!nextItem) continue\n\n const parent = item\n const isLast =\n includedItems.indexOf(nextItem) === includedItems.length - 1\n const toName =\n nextItem.node?.version ?\n `${nextItem.node.name}@${nextItem.node.version}`\n : nextItem.node?.name\n const nextChar = isLast ? 'last-child' : 'middle-child'\n\n nextItem.name =\n (\n nextItem.node?.name &&\n nextItem.edge?.name !== nextItem.edge?.to?.name\n ) ?\n `${nextItem.edge?.name} (${toName})`\n : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`\n nextItem.padding =\n parent.prefix.length ?\n `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `\n : ''\n nextItem.prefix = `${chars.get(nextChar)}${chars.get('connection')}${chars.get('connection')} `\n nextItem.hasSibling = !isLast\n\n content += traverse(nextItem)\n }\n }\n\n const regularConnection = `${chars.get('connection')} `\n const parentConnection = `${chars.get('t')} `\n return item.include ?\n `${content ? header.replace(regularConnection, parentConnection) : header}${content}`\n : ''\n }\n\n for (const item of initialItems) {\n res += traverse(item)\n }\n return reset(res)\n}\n"]}
1
+ {"version":3,"file":"human-readable-output.js","sourceRoot":"","sources":["../../../src/visualization/human-readable-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAA;AAEtD,MAAM,SAAS,GAAG,CAChB,MAA2C,EAC3C,CAAS,EACT,EAAE;IACF,kEAAkE;IAClE,OAAO,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;AAC5D,CAAC,CA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A;gBACN,QAAQ,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;gBAC/F,QAAQ,CAAC,UAAU,GAAG,CAAC,MAAM,CAAA;gBAE7B,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAA;QACvD,MAAM,gBAAgB,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAA;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACjB,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,EAAE;YACvF,CAAC,CAAC,EAAE,CAAA;IACR,CAAC,CAAA;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnB,CAAC","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '../types.ts'\nimport { styleText as utilStyleText } from 'node:util'\n\nconst styleText = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => {\n // @ts-expect-error -- styleText 3rd argument is not in types/node\n return utilStyleText(format, s, { validateStream: false })\n}\n\nconst chars = new Map(\n Object.entries({\n connection: '─',\n down: '│',\n 'last-child': '└',\n 'middle-child': '├',\n t: '┬',\n }),\n)\n\nexport type TreeItem = {\n name?: string | null\n edge: EdgeLike | undefined\n node: NodeLike | undefined\n prefix: string\n padding: string\n hasSibling: boolean\n seen: boolean\n include: boolean\n parent: TreeItem | undefined\n}\n\nexport type HumanReadableOutputGraph = {\n edges: EdgeLike[]\n importers: Set<NodeLike>\n nodes: NodeLike[]\n highlightSelection?: boolean\n}\n\nexport type EdgeMap = Map<NodeLike | undefined, TreeItem>\n\nexport type TreeMap = Map<EdgeLike | undefined, EdgeMap>\n\nconst isSelected = (\n options: HumanReadableOutputGraph,\n edge?: EdgeLike,\n node?: NodeLike,\n) =>\n !!(\n (!node || options.nodes.includes(node)) &&\n (!edge || options.edges.includes(edge))\n )\n\n/**\n * Returns a map of tree items to be printed.\n */\nconst getTreeItems = (\n initialItems: Set<TreeItem>,\n options: HumanReadableOutputGraph,\n) => {\n const seenNodes = new Set<NodeLike>()\n const treeItems: TreeMap = new Map()\n const traverse = new Set<TreeItem>(initialItems)\n for (const item of traverse) {\n if (item.node) {\n if (seenNodes.has(item.node)) {\n item.seen = true\n continue\n }\n seenNodes.add(item.node)\n const edges = [...item.node.edgesOut.values()].sort(i =>\n Number(i.to?.importer),\n )\n for (const edge of edges) {\n const toItems: EdgeMap =\n treeItems.get(edge) ?? (new Map() as EdgeMap)\n const nextItem: TreeItem = {\n edge,\n node: edge.to,\n hasSibling: false,\n padding: '',\n prefix: '',\n seen: false,\n include: isSelected(options, edge, edge.to),\n parent: item,\n }\n toItems.set(edge.to, nextItem)\n treeItems.set(edge, toItems)\n traverse.add(nextItem)\n }\n }\n }\n for (const item of [...traverse].reverse()) {\n if (item.include && item.parent) {\n item.parent.include = true\n }\n }\n return treeItems\n}\n\n/**\n * Returns a human-readable output of the graph.\n */\nexport function humanReadableOutput(\n options: HumanReadableOutputGraph,\n { colors }: { colors?: boolean },\n) {\n const { importers } = options\n const createStyleText =\n (style: Parameters<typeof styleText>[0]) => (s: string) =>\n colors ? styleText(style, s) : s\n const dim = createStyleText('dim')\n const red = createStyleText('red')\n const reset = createStyleText('reset')\n const yellow = createStyleText('yellow')\n const initialItems = new Set<TreeItem>()\n for (const importer of importers) {\n initialItems.add({\n name: importer.name,\n edge: undefined,\n node: importer,\n prefix: '',\n padding: '',\n hasSibling: false,\n seen: false,\n include: isSelected(options, undefined, importer),\n parent: undefined,\n })\n }\n const treeItems = getTreeItems(initialItems, options)\n\n let res = ''\n const traverse = (item: TreeItem) => {\n let header = ''\n let content = ''\n\n const name = item.name\n const decoratedName =\n (\n options.highlightSelection &&\n isSelected(options, item.edge, item.node) &&\n name\n ) ?\n yellow(name)\n : name\n if (!item.node && item.include) {\n const missing =\n item.edge?.type.endsWith('ptional') ?\n dim('(missing optional)')\n : red('(missing)')\n return `${item.padding}${item.prefix}${decoratedName} ${missing}\\n`\n }\n\n header += `${item.padding}${item.prefix}${decoratedName}\\n`\n\n // seen items need not to be printed or traversed\n if (!item.seen) {\n const edges = item.node ? [...item.node.edgesOut.values()] : []\n const nextItems = edges.map(i => treeItems.get(i)?.get(i.to))\n const includedItems = nextItems.filter(i => i?.include)\n\n for (const nextItem of nextItems) {\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!nextItem) continue\n\n const parent = item\n const isLast =\n includedItems.indexOf(nextItem) === includedItems.length - 1\n\n // prefixes the node name with the registry name\n // if a custom registry name is found\n const depIdTuple =\n nextItem.node?.id && splitDepID(nextItem.node.id)\n const hasCustomReg =\n depIdTuple?.[0] === 'registry' && depIdTuple[1]\n const nodeName =\n hasCustomReg ?\n `${depIdTuple[1]}:${nextItem.node?.name}`\n : nextItem.node?.name\n\n const toName =\n nextItem.node?.version ?\n `${nodeName}@${nextItem.node.version}`\n : nodeName\n const nextChar = isLast ? 'last-child' : 'middle-child'\n\n nextItem.name =\n nextItem.node?.confused ?\n `${nextItem.edge?.name} ${red('(confused)')}`\n : nextItem.node?.name && nextItem.edge?.name !== nodeName ?\n `${nextItem.edge?.name} (${toName})`\n : `${nextItem.edge?.name}@${nextItem.node?.version || nextItem.edge?.spec.bareSpec}`\n nextItem.padding =\n parent.prefix.length ?\n `${parent.padding}${parent.hasSibling ? chars.get('down') : ' '} `\n : ''\n nextItem.prefix = `${chars.get(nextChar)}${chars.get('connection')}${chars.get('connection')} `\n nextItem.hasSibling = !isLast\n\n content += traverse(nextItem)\n }\n }\n\n const regularConnection = `${chars.get('connection')} `\n const parentConnection = `${chars.get('t')} `\n return item.include ?\n `${content ? header.replace(regularConnection, parentConnection) : header}${content}`\n : ''\n }\n\n for (const item of initialItems) {\n res += traverse(item)\n }\n return reset(res)\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { type DepID } from '@vltpkg/dep-id';
2
- import { type EdgeLike, type NodeLike } from '../types.js';
1
+ import type { DepID } from '@vltpkg/dep-id';
2
+ import type { EdgeLike, NodeLike } from '../types.ts';
3
3
  /**
4
4
  * A JSON output item describes a package that is present in the install
5
5
  * graph. It represents an edge plus it's linking Node.
@@ -26,12 +26,12 @@ export type JSONOutputItem = {
26
26
  */
27
27
  to?: NodeLike;
28
28
  };
29
- export type JSONOutputOptions = {
29
+ export type JSONOutputGraph = {
30
30
  edges: EdgeLike[];
31
31
  nodes: NodeLike[];
32
32
  };
33
33
  /**
34
34
  * Returns a JSON string representation of the graph.
35
35
  */
36
- export declare function jsonOutput({ edges, nodes }: JSONOutputOptions): string;
36
+ export declare function jsonOutput({ edges, nodes }: JSONOutputGraph): JSONOutputItem[];
37
37
  //# sourceMappingURL=json-output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/json-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE1D;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvB;;OAEG;IACH,EAAE,CAAC,EAAE,QAAQ,CAAA;CACd,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,iBAAiB,UA0B7D"}
1
+ {"version":3,"file":"json-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/json-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAErD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACvB;;OAEG;IACH,EAAE,CAAC,EAAE,QAAQ,CAAA;CACd,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,eAAe,oBA0B3D"}
@@ -23,6 +23,6 @@ export function jsonOutput({ edges, nodes }) {
23
23
  to: edge.to,
24
24
  });
25
25
  }
26
- return JSON.stringify(res, null, 2);
26
+ return res;
27
27
  }
28
28
  //# sourceMappingURL=json-output.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-output.js","sourceRoot":"","sources":["../../../src/visualization/json-output.ts"],"names":[],"mappings":"AAmCA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAqB;IAC5D,MAAM,GAAG,GAAqB,EAAE,CAAA;IAEhC,wDAAwD;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,GAAG,CAAC,IAAI,CAAC;gBACP,8DAA8D;gBAC9D,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE;gBAC1B,EAAE,EAAE,IAAI;aACT,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,yDAAyD;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,GAAG,CAAC,IAAI,CAAC;YACP,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YACpB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,EAAE,EAAE,IAAI,CAAC,EAAE;SACZ,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import { type DepID } from '@vltpkg/dep-id'\nimport { type EdgeLike, type NodeLike } from '../types.js'\n\n/**\n * A JSON output item describes a package that is present in the install\n * graph. It represents an edge plus it's linking Node.\n */\nexport type JSONOutputItem = {\n /**\n * The name of the package.\n */\n name: string\n /**\n * A reference to the id of the Node that this package is linked from.\n */\n fromID?: DepID\n /**\n * The dependency spec definition for this package.\n */\n spec?: string\n /**\n * The package type.\n */\n type?: EdgeLike['type']\n /**\n * A representation of the package object that fulfills this dependency.\n */\n to?: NodeLike\n}\n\nexport type JSONOutputOptions = {\n edges: EdgeLike[]\n nodes: NodeLike[]\n}\n\n/**\n * Returns a JSON string representation of the graph.\n */\nexport function jsonOutput({ edges, nodes }: JSONOutputOptions) {\n const res: JSONOutputItem[] = []\n\n // Collects importer nodes as edgeless json output items\n for (const node of nodes) {\n if (node.importer) {\n res.push({\n /* c8 ignore next - name can't be missing but ts won't know */\n name: node.name || node.id,\n to: node,\n })\n }\n }\n\n // Collects edge & it's linked nodes as json output items\n for (const edge of edges) {\n res.push({\n name: edge.name,\n fromID: edge.from.id,\n spec: String(edge.spec),\n type: edge.type,\n to: edge.to,\n })\n }\n\n return JSON.stringify(res, null, 2)\n}\n"]}
1
+ {"version":3,"file":"json-output.js","sourceRoot":"","sources":["../../../src/visualization/json-output.ts"],"names":[],"mappings":"AAmCA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAmB;IAC1D,MAAM,GAAG,GAAqB,EAAE,CAAA;IAEhC,wDAAwD;IACxD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,GAAG,CAAC,IAAI,CAAC;gBACP,8DAA8D;gBAC9D,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE;gBAC1B,EAAE,EAAE,IAAI;aACT,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,yDAAyD;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,GAAG,CAAC,IAAI,CAAC;YACP,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YACpB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,EAAE,EAAE,IAAI,CAAC,EAAE;SACZ,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '../types.ts'\n\n/**\n * A JSON output item describes a package that is present in the install\n * graph. It represents an edge plus it's linking Node.\n */\nexport type JSONOutputItem = {\n /**\n * The name of the package.\n */\n name: string\n /**\n * A reference to the id of the Node that this package is linked from.\n */\n fromID?: DepID\n /**\n * The dependency spec definition for this package.\n */\n spec?: string\n /**\n * The package type.\n */\n type?: EdgeLike['type']\n /**\n * A representation of the package object that fulfills this dependency.\n */\n to?: NodeLike\n}\n\nexport type JSONOutputGraph = {\n edges: EdgeLike[]\n nodes: NodeLike[]\n}\n\n/**\n * Returns a JSON string representation of the graph.\n */\nexport function jsonOutput({ edges, nodes }: JSONOutputGraph) {\n const res: JSONOutputItem[] = []\n\n // Collects importer nodes as edgeless json output items\n for (const node of nodes) {\n if (node.importer) {\n res.push({\n /* c8 ignore next - name can't be missing but ts won't know */\n name: node.name || node.id,\n to: node,\n })\n }\n }\n\n // Collects edge & it's linked nodes as json output items\n for (const edge of edges) {\n res.push({\n name: edge.name,\n fromID: edge.from.id,\n spec: String(edge.spec),\n type: edge.type,\n to: edge.to,\n })\n }\n\n return res\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { type EdgeLike, type NodeLike } from '../types.js';
2
- export type MermaidOutputOptions = {
1
+ import type { EdgeLike, NodeLike } from '../types.ts';
2
+ export type MermaidOutputGraph = {
3
3
  edges: EdgeLike[];
4
4
  importers: Set<NodeLike>;
5
5
  nodes: NodeLike[];
@@ -7,5 +7,5 @@ export type MermaidOutputOptions = {
7
7
  /**
8
8
  * Returns a mermaid string representation of the graph.
9
9
  */
10
- export declare function mermaidOutput({ edges, importers, nodes, }: MermaidOutputOptions): string;
10
+ export declare function mermaidOutput({ edges, importers, nodes, }: MermaidOutputGraph): string;
11
11
  //# sourceMappingURL=mermaid-output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mermaid-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE1D,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB,CAAA;AAsDD;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,SAAS,EACT,KAAK,GACN,EAAE,oBAAoB,UA0CtB"}
1
+ {"version":3,"file":"mermaid-output.d.ts","sourceRoot":"","sources":["../../../src/visualization/mermaid-output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB,CAAA;AAsDD;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,SAAS,EACT,KAAK,GACN,EAAE,kBAAkB,UA0CpB"}