@powerhousedao/ph-cli 6.2.3 → 6.3.0-dev.2

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 (191) hide show
  1. package/README.md +21 -0
  2. package/dist/build-DEARgWyg.mjs +3063 -0
  3. package/dist/build-DEARgWyg.mjs.map +1 -0
  4. package/dist/build-rj6WVkRW.mjs +4 -0
  5. package/dist/check-C4kc91Oy.mjs +81 -0
  6. package/dist/check-C4kc91Oy.mjs.map +1 -0
  7. package/dist/check-CklNk7AL.mjs +4 -0
  8. package/dist/check-D0b-uWwK.mjs +65 -0
  9. package/dist/check-D0b-uWwK.mjs.map +1 -0
  10. package/dist/classic-args-mH_DVsgC.mjs +48 -0
  11. package/dist/classic-args-mH_DVsgC.mjs.map +1 -0
  12. package/dist/classic-warnings-kQsFGSeA.mjs +179 -0
  13. package/dist/classic-warnings-kQsFGSeA.mjs.map +1 -0
  14. package/dist/{cli-connect-override-b4kKqgOZ.mjs → cli-connect-override-31gBnNxd.mjs} +6 -29
  15. package/dist/cli-connect-override-31gBnNxd.mjs.map +1 -0
  16. package/dist/cli.mjs +46 -1341
  17. package/dist/cli.mjs.map +1 -1
  18. package/dist/compound-CDrU3CLt-gW8JNJQK.mjs +2910 -0
  19. package/dist/compound-CDrU3CLt-gW8JNJQK.mjs.map +1 -0
  20. package/dist/connect-build-8Y-QmOJ5.mjs +322 -0
  21. package/dist/connect-build-8Y-QmOJ5.mjs.map +1 -0
  22. package/dist/{connect-config-_kiSMsbG.mjs → connect-config-Dj3E8CaW.mjs} +5 -5
  23. package/dist/{connect-config-_kiSMsbG.mjs.map → connect-config-Dj3E8CaW.mjs.map} +1 -1
  24. package/dist/connect-preview-CdFvlANO.mjs +49 -0
  25. package/dist/connect-preview-CdFvlANO.mjs.map +1 -0
  26. package/dist/{connect-studio-f3K1qPWd.mjs → connect-studio-BNSe_8PI.mjs} +3 -3
  27. package/dist/connect-studio-CBtduPet.mjs +94 -0
  28. package/dist/connect-studio-CBtduPet.mjs.map +1 -0
  29. package/dist/definitions-worker.d.mts +98 -0
  30. package/dist/definitions-worker.d.mts.map +1 -0
  31. package/dist/definitions-worker.mjs +28 -0
  32. package/dist/definitions-worker.mjs.map +1 -0
  33. package/dist/dist-seTzvoSw.mjs +480 -0
  34. package/dist/dist-seTzvoSw.mjs.map +1 -0
  35. package/dist/evidence-CavwC5YV.mjs +134 -0
  36. package/dist/evidence-CavwC5YV.mjs.map +1 -0
  37. package/dist/explain-DTa32gEY.mjs +230 -0
  38. package/dist/explain-DTa32gEY.mjs.map +1 -0
  39. package/dist/export-YEBE-Gvl.mjs +42 -0
  40. package/dist/export-YEBE-Gvl.mjs.map +1 -0
  41. package/dist/external-M25AgDIE.d.mts +4277 -0
  42. package/dist/external-M25AgDIE.d.mts.map +1 -0
  43. package/dist/files-D6_euBBn.mjs +457 -0
  44. package/dist/files-D6_euBBn.mjs.map +1 -0
  45. package/dist/{generate-all-CIwP-3aa.mjs → generate-all-DKuaLgz1.mjs} +10 -5
  46. package/dist/generate-all-DKuaLgz1.mjs.map +1 -0
  47. package/dist/generate-app-hm6CJ_4O.mjs +72 -0
  48. package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
  49. package/dist/generate-desktop-shell-BovoRsR6.mjs +372 -0
  50. package/dist/generate-desktop-shell-BovoRsR6.mjs.map +1 -0
  51. package/dist/generate-document-model-OQPfeHs-.mjs +118 -0
  52. package/dist/generate-document-model-OQPfeHs-.mjs.map +1 -0
  53. package/dist/generate-editor-DBj_Pxwa.mjs +64 -0
  54. package/dist/generate-editor-DBj_Pxwa.mjs.map +1 -0
  55. package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
  56. package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
  57. package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
  58. package/dist/generate-migration-file-yK8uA70U.mjs +20 -0
  59. package/dist/generate-migration-file-yK8uA70U.mjs.map +1 -0
  60. package/dist/{generate-piece-QTt-ddt2.mjs → generate-piece-5Nyr2UZj.mjs} +18 -10
  61. package/dist/generate-piece-5Nyr2UZj.mjs.map +1 -0
  62. package/dist/{generate-piece-action-C5WTHsqu.mjs → generate-piece-action-DqR8BcoO.mjs} +10 -7
  63. package/dist/generate-piece-action-DqR8BcoO.mjs.map +1 -0
  64. package/dist/{generate-piece-trigger-DR10CPOG.mjs → generate-piece-trigger-CZaDD-cc.mjs} +8 -7
  65. package/dist/generate-piece-trigger-CZaDD-cc.mjs.map +1 -0
  66. package/dist/{generate-processor-DBtTkgo5.mjs → generate-processor-BVjOsfjJ.mjs} +20 -9
  67. package/dist/generate-processor-BVjOsfjJ.mjs.map +1 -0
  68. package/dist/generate-subgraph-DJZCr0Tk.mjs +86 -0
  69. package/dist/generate-subgraph-DJZCr0Tk.mjs.map +1 -0
  70. package/dist/get-version-DATiLAmB.mjs +11 -0
  71. package/dist/get-version-DATiLAmB.mjs.map +1 -0
  72. package/dist/index-Dy3U1WqW.d.mts +192 -0
  73. package/dist/index-Dy3U1WqW.d.mts.map +1 -0
  74. package/dist/{init-CIEMyAug.mjs → init-CJB6RiIy.mjs} +23 -13
  75. package/dist/init-CJB6RiIy.mjs.map +1 -0
  76. package/dist/inspect-CulIpVsF.mjs +52 -0
  77. package/dist/inspect-CulIpVsF.mjs.map +1 -0
  78. package/dist/{inspect-BpCB0TPo.mjs → inspect-zWJnBDMJ.mjs} +4 -4
  79. package/dist/{inspect-BpCB0TPo.mjs.map → inspect-zWJnBDMJ.mjs.map} +1 -1
  80. package/dist/install-added-dependencies-DnZFR3aE.mjs +18 -0
  81. package/dist/install-added-dependencies-DnZFR3aE.mjs.map +1 -0
  82. package/dist/keyframes-bFo9iDhT.mjs +201 -0
  83. package/dist/keyframes-bFo9iDhT.mjs.map +1 -0
  84. package/dist/mcp-BV_EZ15p.mjs +263 -0
  85. package/dist/mcp-BV_EZ15p.mjs.map +1 -0
  86. package/dist/migrate-Bg-HBsYa.mjs +208 -0
  87. package/dist/migrate-Bg-HBsYa.mjs.map +1 -0
  88. package/dist/migrate-subgraphs-Bm3zpsO9.mjs +214 -0
  89. package/dist/migrate-subgraphs-Bm3zpsO9.mjs.map +1 -0
  90. package/dist/migrate-subgraphs-De_rX4Hv.mjs +4 -0
  91. package/dist/module-dir-1avCXsBi.mjs +17 -0
  92. package/dist/module-dir-1avCXsBi.mjs.map +1 -0
  93. package/dist/npm-args-g1Tgel4s.mjs +78 -0
  94. package/dist/npm-args-g1Tgel4s.mjs.map +1 -0
  95. package/dist/offered-routes-imports-CQInWI6y.mjs +4 -0
  96. package/dist/offered-routes-imports-CalXK9dh.mjs +96 -0
  97. package/dist/offered-routes-imports-CalXK9dh.mjs.map +1 -0
  98. package/dist/ph-cli-commands--2HdnZaA.mjs +1787 -0
  99. package/dist/ph-cli-commands--2HdnZaA.mjs.map +1 -0
  100. package/dist/ph-cli-commands-BdA9sXDE.mjs +4 -0
  101. package/dist/render-3M3DwFzO.mjs +4 -0
  102. package/dist/render-SVfj3m8A.mjs +77 -0
  103. package/dist/render-SVfj3m8A.mjs.map +1 -0
  104. package/dist/run--de_-WAz.mjs +112 -0
  105. package/dist/run--de_-WAz.mjs.map +1 -0
  106. package/dist/run-LRGy7zGo.mjs +4 -0
  107. package/dist/run-sugar-ByAIbE2x.mjs +56 -0
  108. package/dist/run-sugar-ByAIbE2x.mjs.map +1 -0
  109. package/dist/runners/connect.d.mts +17 -0
  110. package/dist/runners/connect.d.mts.map +1 -0
  111. package/dist/runners/connect.mjs +83 -0
  112. package/dist/runners/connect.mjs.map +1 -0
  113. package/dist/runners/switchboard.d.mts +24 -0
  114. package/dist/runners/switchboard.d.mts.map +1 -0
  115. package/dist/runners/switchboard.mjs +178 -0
  116. package/dist/runners/switchboard.mjs.map +1 -0
  117. package/dist/schemas-DzgKfQIx.mjs +6024 -0
  118. package/dist/schemas-DzgKfQIx.mjs.map +1 -0
  119. package/dist/scripts/emit-runner-schemas.ts +24 -0
  120. package/dist/scripts/generate-commands-docs.ts +19 -0
  121. package/dist/scripts/manage-environment +0 -0
  122. package/dist/scripts/setup.sh +0 -0
  123. package/dist/subgraph-gate-BJ2PWXVY.mjs +26 -0
  124. package/dist/subgraph-gate-BJ2PWXVY.mjs.map +1 -0
  125. package/dist/subgraph-gate-j9ywj6KA.mjs +4 -0
  126. package/dist/subgraphs-7OYWwP-C.mjs +134 -0
  127. package/dist/subgraphs-7OYWwP-C.mjs.map +1 -0
  128. package/dist/{switchboard-migrate-7JQZM7-5.mjs → switchboard-migrate-BqSdKJ7u.mjs} +4 -5
  129. package/dist/switchboard-migrate-BqSdKJ7u.mjs.map +1 -0
  130. package/dist/switchboard-proxy-CGfMtENM.mjs +37 -0
  131. package/dist/switchboard-proxy-CGfMtENM.mjs.map +1 -0
  132. package/dist/{switchboard-reset-Ctegiqdm.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
  133. package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
  134. package/dist/sync-connect-routes-BtAsFPXN.mjs +4 -0
  135. package/dist/sync-connect-routes-t0Slg-P6.mjs +25 -0
  136. package/dist/sync-connect-routes-t0Slg-P6.mjs.map +1 -0
  137. package/dist/{utils-CvmDmCVd.mjs → utils-9KyRM0mf.mjs} +6 -34
  138. package/dist/{utils-CvmDmCVd.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
  139. package/dist/utils-TO9lB8Xs.mjs +4 -0
  140. package/dist/verify-Go5DrPvf.mjs +71 -0
  141. package/dist/verify-Go5DrPvf.mjs.map +1 -0
  142. package/dist/vetra-CmTg8Lja.mjs +351 -0
  143. package/dist/vetra-CmTg8Lja.mjs.map +1 -0
  144. package/dist/vetra-host-C0Q0oMUW.mjs +79 -0
  145. package/dist/vetra-host-C0Q0oMUW.mjs.map +1 -0
  146. package/dist/vetra-instance-B0bXPj7g.mjs +201 -0
  147. package/dist/vetra-instance-B0bXPj7g.mjs.map +1 -0
  148. package/dist/vetra-launch-T_uLKaR3.mjs +236 -0
  149. package/dist/vetra-launch-T_uLKaR3.mjs.map +1 -0
  150. package/dist/vetra-switchboard-BrkozIm7.mjs +4 -0
  151. package/dist/vetra-switchboard-tzdc14KA.mjs +230 -0
  152. package/dist/vetra-switchboard-tzdc14KA.mjs.map +1 -0
  153. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
  154. package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
  155. package/package.json +40 -14
  156. package/dist/build-CTvPQFMi.mjs +0 -4
  157. package/dist/build-sO3PcZxl.mjs +0 -166
  158. package/dist/build-sO3PcZxl.mjs.map +0 -1
  159. package/dist/cli-connect-override-b4kKqgOZ.mjs.map +0 -1
  160. package/dist/connect-build-BMaR9w4G.mjs +0 -153
  161. package/dist/connect-build-BMaR9w4G.mjs.map +0 -1
  162. package/dist/connect-preview-CzDqR-JN.mjs +0 -32
  163. package/dist/connect-preview-CzDqR-JN.mjs.map +0 -1
  164. package/dist/connect-studio-_-O1-oef.mjs +0 -36
  165. package/dist/connect-studio-_-O1-oef.mjs.map +0 -1
  166. package/dist/generate-all-CIwP-3aa.mjs.map +0 -1
  167. package/dist/generate-app-BTs1u-9l.mjs +0 -50
  168. package/dist/generate-app-BTs1u-9l.mjs.map +0 -1
  169. package/dist/generate-document-model-DhDQ_06X.mjs +0 -44
  170. package/dist/generate-document-model-DhDQ_06X.mjs.map +0 -1
  171. package/dist/generate-editor-CW7Do69u.mjs +0 -50
  172. package/dist/generate-editor-CW7Do69u.mjs.map +0 -1
  173. package/dist/generate-piece-QTt-ddt2.mjs.map +0 -1
  174. package/dist/generate-piece-action-C5WTHsqu.mjs.map +0 -1
  175. package/dist/generate-piece-trigger-DR10CPOG.mjs.map +0 -1
  176. package/dist/generate-processor-DBtTkgo5.mjs.map +0 -1
  177. package/dist/generate-subgraph-Dm27O59o.mjs +0 -42
  178. package/dist/generate-subgraph-Dm27O59o.mjs.map +0 -1
  179. package/dist/init-CIEMyAug.mjs.map +0 -1
  180. package/dist/install-added-dependencies-DVSbzler.mjs +0 -33
  181. package/dist/install-added-dependencies-DVSbzler.mjs.map +0 -1
  182. package/dist/migrate-B6QBYDNX.mjs +0 -83
  183. package/dist/migrate-B6QBYDNX.mjs.map +0 -1
  184. package/dist/switchboard-CgVB4U76.mjs +0 -87
  185. package/dist/switchboard-CgVB4U76.mjs.map +0 -1
  186. package/dist/switchboard-migrate-7JQZM7-5.mjs.map +0 -1
  187. package/dist/switchboard-nHCI3pha.mjs +0 -4
  188. package/dist/switchboard-reset-Ctegiqdm.mjs.map +0 -1
  189. package/dist/utils-C3c5YG6v.mjs +0 -4
  190. package/dist/vetra-s8gWslse.mjs +0 -627
  191. package/dist/vetra-s8gWslse.mjs.map +0 -1
@@ -0,0 +1,24 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { emittedRunnerSchemas } from "../src/runners/emitted-schemas.js";
5
+
6
+ /**
7
+ * Writes the runners' editor JSON Schemas into clis/ph-cli/schemas/. Run
8
+ * `pnpm --filter @powerhousedao/ph-cli emit-schemas` after changing a
9
+ * runner's hostSchema or outputsSchema; the drift test
10
+ * (test/runner-schemas-drift.test.ts) fails while the files are behind.
11
+ */
12
+ const outDir = path.join(
13
+ path.dirname(fileURLToPath(import.meta.url)),
14
+ "..",
15
+ "schemas",
16
+ );
17
+ fs.mkdirSync(outDir, { recursive: true });
18
+ for (const [file, schema] of Object.entries(emittedRunnerSchemas())) {
19
+ fs.writeFileSync(
20
+ path.join(outDir, file),
21
+ `${JSON.stringify(schema, null, 2)}\n`,
22
+ );
23
+ console.log(`emitted schemas/${file}`);
24
+ }
@@ -4,8 +4,10 @@ import { build as buildCmd } from "../src/commands/build.js";
4
4
  import { build, connect, preview, studio } from "../src/commands/connect.js";
5
5
  import { generateAllCmd } from "../src/commands/generate-all.js";
6
6
  import { generateAppCmd } from "../src/commands/generate-app.js";
7
+ import { generateConnectRoutesCmd } from "../src/commands/generate-connect-routes.js";
7
8
  import { generateDocumentModelCmd } from "../src/commands/generate-document-model.js";
8
9
  import { generateEditorCmd } from "../src/commands/generate-editor.js";
10
+ import { generateHostsCmd } from "../src/commands/generate-hosts.js";
9
11
  import { generateMigrationFileCmd } from "../src/commands/generate-migration-file.js";
10
12
  import { generatePieceActionCmd } from "../src/commands/generate-piece-action.js";
11
13
  import { generatePieceTriggerCmd } from "../src/commands/generate-piece-trigger.js";
@@ -13,17 +15,28 @@ import { generatePieceCmd } from "../src/commands/generate-piece.js";
13
15
  import { generateProcessorCmd } from "../src/commands/generate-processor.js";
14
16
  import { generateSubgraphCmd } from "../src/commands/generate-subgraph.js";
15
17
  import { generate } from "../src/commands/generate.js";
18
+ import {
19
+ check as hostCheck,
20
+ exportCmd as hostExport,
21
+ } from "../src/commands/host.js";
16
22
  import { inspect } from "../src/commands/inspect.js";
17
23
  import { install } from "../src/commands/install.js";
24
+ import { keyframes } from "../src/commands/keyframes.js";
18
25
  import { list } from "../src/commands/list.js";
19
26
  import { login } from "../src/commands/login.js";
27
+ import { mcp } from "../src/commands/mcp.js";
20
28
  import { migrate } from "../src/commands/migrate.js";
29
+ import { modelCheck, modelInspect } from "../src/commands/model.js";
21
30
  import { phCli } from "../src/commands/ph-cli.js";
31
+ import { runHost } from "../src/commands/run.js";
22
32
  import { switchboard } from "../src/commands/switchboard.js";
23
33
  import { uninstall } from "../src/commands/uninstall.js";
24
34
  import { vetra } from "../src/commands/vetra.js";
25
35
 
26
36
  const commands = [
37
+ { name: "run", command: runHost },
38
+ { name: "host check", command: hostCheck },
39
+ { name: "host export", command: hostExport },
27
40
  { name: "generate", command: generate },
28
41
  { name: "all", command: generateAllCmd },
29
42
  { name: "document-model", command: generateDocumentModelCmd },
@@ -35,6 +48,8 @@ const commands = [
35
48
  { name: "piece-action", command: generatePieceActionCmd },
36
49
  { name: "piece-trigger", command: generatePieceTriggerCmd },
37
50
  { name: "migration-file", command: generateMigrationFileCmd },
51
+ { name: "connect-routes", command: generateConnectRoutesCmd },
52
+ { name: "hosts", command: generateHostsCmd },
38
53
  { name: "vetra", command: vetra },
39
54
  { name: "build", command: buildCmd },
40
55
  { name: "connect", command: connect },
@@ -43,8 +58,12 @@ const commands = [
43
58
  { name: "connect preview", command: preview },
44
59
  { name: "access token", command: accessToken },
45
60
  { name: "inspect", command: inspect },
61
+ { name: "keyframes", command: keyframes },
46
62
  { name: "list", command: list },
63
+ { name: "mcp", command: mcp },
47
64
  { name: "migrate", command: migrate },
65
+ { name: "model check", command: modelCheck },
66
+ { name: "model inspect", command: modelInspect },
48
67
  { name: "switchboard", command: switchboard },
49
68
  { name: "login", command: login },
50
69
  { name: "install", command: install },
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f0cdc57f-1f84-5df8-b36b-c959c435cfc3")}catch(e){}}();
3
+ import { statSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { subgraphDirStyles } from "@powerhousedao/codegen/utils";
6
+ //#region src/services/model/subgraph-gate.ts
7
+ const SUBGRAPHS_ENTRY = "./subgraphs/index.ts";
8
+ /** A project without `subgraphs/index.ts` serves no subgraph, so it has none. */
9
+ function scanSubgraphs(projectRoot) {
10
+ const entry = join(projectRoot, SUBGRAPHS_ENTRY);
11
+ if (!(statSync(entry, { throwIfNoEntry: false })?.isFile() ?? false)) return {
12
+ hasCodeFirst: false,
13
+ schemaFirstUnits: []
14
+ };
15
+ const dirs = subgraphDirStyles(join(projectRoot, "subgraphs"));
16
+ return {
17
+ hasCodeFirst: dirs.some(({ style }) => style === "code-first"),
18
+ schemaFirstUnits: dirs.filter(({ style }) => style === "schema-first").map(({ dirName }) => dirName)
19
+ };
20
+ }
21
+ const hasCodeFirstSubgraph = (projectRoot) => scanSubgraphs(projectRoot).hasCodeFirst;
22
+ //#endregion
23
+ export { hasCodeFirstSubgraph as n, scanSubgraphs as r, SUBGRAPHS_ENTRY as t };
24
+
25
+ //# sourceMappingURL=subgraph-gate-BJ2PWXVY.mjs.map
26
+ //# debugId=f0cdc57f-1f84-5df8-b36b-c959c435cfc3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph-gate-BJ2PWXVY.mjs","sources":["../src/services/model/subgraph-gate.ts"],"sourcesContent":["import { subgraphDirStyles } from \"@powerhousedao/codegen/utils\";\nimport { statSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nexport const SUBGRAPHS_ENTRY = \"./subgraphs/index.ts\";\n\nexport type SubgraphStyles = {\n readonly hasCodeFirst: boolean;\n readonly schemaFirstUnits: readonly string[];\n};\n\n/** A project without `subgraphs/index.ts` serves no subgraph, so it has none. */\nexport function scanSubgraphs(projectRoot: string): SubgraphStyles {\n const entry = join(projectRoot, SUBGRAPHS_ENTRY);\n if (!(statSync(entry, { throwIfNoEntry: false })?.isFile() ?? false))\n return { hasCodeFirst: false, schemaFirstUnits: [] };\n const dirs = subgraphDirStyles(join(projectRoot, \"subgraphs\"));\n return {\n hasCodeFirst: dirs.some(({ style }) => style === \"code-first\"),\n schemaFirstUnits: dirs\n .filter(({ style }) => style === \"schema-first\")\n .map(({ dirName }) => dirName),\n };\n}\n\nexport const hasCodeFirstSubgraph = (projectRoot: string) =>\n scanSubgraphs(projectRoot).hasCodeFirst;\n"],"names":[],"mappings":";;;;;;AAIA,MAAa,kBAAkB;;AAQ/B,SAAgB,cAAc,aAAqC;CACjE,MAAM,QAAQ,KAAK,aAAa,eAAe;CAC/C,IAAI,EAAE,SAAS,OAAO,EAAE,gBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,KAAK,QAC5D,OAAO;EAAE,cAAc;EAAO,kBAAkB,CAAC;CAAE;CACrD,MAAM,OAAO,kBAAkB,KAAK,aAAa,WAAW,CAAC;CAC7D,OAAO;EACL,cAAc,KAAK,MAAM,EAAE,YAAY,UAAU,YAAY;EAC7D,kBAAkB,KACf,QAAQ,EAAE,YAAY,UAAU,cAAc,CAAC,CAC/C,KAAK,EAAE,cAAc,OAAO;CACjC;AACF;AAEA,MAAa,wBAAwB,gBACnC,cAAc,WAAW,CAAC,CAAC","debug_id":"f0cdc57f-1f84-5df8-b36b-c959c435cfc3"}
@@ -0,0 +1,4 @@
1
+ import { n as hasCodeFirstSubgraph } from "./subgraph-gate-BJ2PWXVY.mjs";
2
+ export { hasCodeFirstSubgraph };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5eaba0b5-4ee9-5473-b64d-7418a6e9e9db")}catch(e){}}();
4
+ //# debugId=5eaba0b5-4ee9-5473-b64d-7418a6e9e9db
@@ -0,0 +1,134 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1d9c1c84-45e5-55d7-970d-52f2a0d6a487")}catch(e){}}();
3
+ import { r as scanSubgraphs, t as SUBGRAPHS_ENTRY } from "./subgraph-gate-BJ2PWXVY.mjs";
4
+ import { readFileSync, statSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { readSubgraphDefinitions, subgraphCheckInput } from "document-model/tooling";
7
+ import { projectSubgraphGraphQL } from "document-model";
8
+ import { parse, print } from "graphql";
9
+ //#region src/services/model/schema-first/sdl-sources.ts
10
+ const SDL_FILES = [
11
+ ["schema.graphql", "graphql"],
12
+ ["schema.ts", "typescript"],
13
+ ["index.ts", "typescript"]
14
+ ];
15
+ const LITERAL_NAME = /\bname(?:\s*:\s*string)?\s*=\s*["'`]([^"'`$]+)["'`]/;
16
+ function readText(path) {
17
+ if (!(statSync(path, { throwIfNoEntry: false })?.isFile() ?? false)) return null;
18
+ return readFileSync(path, "utf8");
19
+ }
20
+ function schemaFirstSource(projectRoot, dir) {
21
+ const unit = `./subgraphs/${dir}/`;
22
+ const name = readText(join(projectRoot, "subgraphs", dir, "index.ts"))?.match(LITERAL_NAME)?.[1] ?? null;
23
+ for (const [file, language] of SDL_FILES) {
24
+ const text = readText(join(projectRoot, "subgraphs", dir, file));
25
+ if (text !== null) return {
26
+ unit,
27
+ name,
28
+ source: { specifier: `${unit}${file}` },
29
+ language,
30
+ text
31
+ };
32
+ }
33
+ return {
34
+ unit,
35
+ name,
36
+ source: { specifier: `${unit}index.ts` },
37
+ language: "typescript",
38
+ text: null
39
+ };
40
+ }
41
+ //#endregion
42
+ //#region src/services/model/subgraphs.ts
43
+ const SCALARS_ENTRY = "./scalars/index.ts";
44
+ /** A module that hangs on a top-level await must not hang `ph model`. */
45
+ const IMPORT_TIMEOUT_MS = 6e4;
46
+ async function importModule(modules, specifier, packageRoot, timeoutMs) {
47
+ let timer;
48
+ const timeout = new Promise((_, reject) => {
49
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`it did not finish loading within ${timeoutMs / 1e3} seconds`)), timeoutMs);
50
+ timer.unref();
51
+ });
52
+ try {
53
+ return {
54
+ ok: true,
55
+ namespace: await Promise.race([modules.importModule(specifier), timeout])
56
+ };
57
+ } catch (error) {
58
+ return {
59
+ ok: false,
60
+ failure: {
61
+ specifier,
62
+ reason: (error instanceof Error ? error.message : String(error)).replaceAll(packageRoot, ".")
63
+ }
64
+ };
65
+ } finally {
66
+ clearTimeout(timer);
67
+ }
68
+ }
69
+ /** The host's admission of the code-first subgraphs, replayed against its built-in subgraphs and the package's document models. */
70
+ async function replayHostAdmission({ subgraphs }, artifacts) {
71
+ if (subgraphs.length === 0) return [];
72
+ const models = new Map(artifacts.map(({ documentType, documentModel }) => [documentType, documentModel.global]));
73
+ const { findPackageSubgraphConflicts } = await import("@powerhousedao/reactor-api/subgraph-types");
74
+ const { conflicts } = await findPackageSubgraphConflicts(subgraphs.map(({ name, definition }) => ({
75
+ name,
76
+ typeDefs: parse(print(projectSubgraphGraphQL(definition)))
77
+ })), [...models.values()]);
78
+ return Array.from(conflicts).flatMap(([subgraph, { nameHeldBy, claims }]) => nameHeldBy === "package" ? [] : [{
79
+ subgraph,
80
+ ...nameHeldBy !== void 0 && { nameHeldBy },
81
+ claims
82
+ }]);
83
+ }
84
+ const usesPackageScalars = ({ subgraphs }) => subgraphs.some(({ definition }) => definition.scalars.some(({ implementation }) => implementation.startsWith("package#")));
85
+ /**
86
+ * `undefined` when the project has no code-first subgraph: then nothing here
87
+ * imports a module, and projects without one keep the reports they had. A
88
+ * module that fails or outlives `timeoutMs` becomes a diagnostic.
89
+ */
90
+ async function readProjectSubgraphs(project, modules, timeoutMs = IMPORT_TIMEOUT_MS) {
91
+ const root = project.packageRoot;
92
+ const styles = scanSubgraphs(root);
93
+ if (!styles.hasCodeFirst) return void 0;
94
+ const schemaFirst = styles.schemaFirstUnits.map((dir) => schemaFirstSource(root, dir));
95
+ const subgraphs = await importModule(modules, SUBGRAPHS_ENTRY, root, timeoutMs);
96
+ if (!subgraphs.ok) return subgraphCheckInput({
97
+ definitions: {
98
+ subgraphs: [],
99
+ diagnostics: []
100
+ },
101
+ schemaFirst,
102
+ importFailures: [subgraphs.failure]
103
+ });
104
+ const definitions = readSubgraphDefinitions(subgraphs.namespace, { specifier: SUBGRAPHS_ENTRY });
105
+ const hostConflicts = await replayHostAdmission(definitions, project.artifacts);
106
+ if (!usesPackageScalars(definitions)) return subgraphCheckInput({
107
+ definitions,
108
+ schemaFirst,
109
+ hostConflicts
110
+ });
111
+ if (!(statSync(join(root, SCALARS_ENTRY), { throwIfNoEntry: false })?.isFile() ?? false)) return subgraphCheckInput({
112
+ definitions,
113
+ schemaFirst,
114
+ hostConflicts,
115
+ scalars: null
116
+ });
117
+ const scalars = await importModule(modules, SCALARS_ENTRY, root, timeoutMs);
118
+ return subgraphCheckInput(scalars.ok ? {
119
+ definitions,
120
+ schemaFirst,
121
+ hostConflicts,
122
+ scalars: scalars.namespace
123
+ } : {
124
+ definitions,
125
+ schemaFirst,
126
+ hostConflicts,
127
+ importFailures: [scalars.failure]
128
+ });
129
+ }
130
+ //#endregion
131
+ export { readProjectSubgraphs as t };
132
+
133
+ //# sourceMappingURL=subgraphs-7OYWwP-C.mjs.map
134
+ //# debugId=1d9c1c84-45e5-55d7-970d-52f2a0d6a487
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraphs-7OYWwP-C.mjs","sources":["../src/services/model/schema-first/sdl-sources.ts","../src/services/model/subgraphs.ts"],"sourcesContent":["import type { SchemaFirstSubgraphSource } from \"document-model/tooling\";\nimport { readFileSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nconst SDL_FILES: readonly (readonly [\n string,\n SchemaFirstSubgraphSource[\"language\"],\n])[] = [\n [\"schema.graphql\", \"graphql\"],\n [\"schema.ts\", \"typescript\"],\n [\"index.ts\", \"typescript\"],\n];\n\nconst LITERAL_NAME = /\\bname(?:\\s*:\\s*string)?\\s*=\\s*[\"'`]([^\"'`$]+)[\"'`]/;\n\nfunction readText(path: string): string | null {\n if (!(statSync(path, { throwIfNoEntry: false })?.isFile() ?? false)) {\n return null;\n }\n return readFileSync(path, \"utf8\");\n}\n\nexport function schemaFirstSource(\n projectRoot: string,\n dir: string,\n): SchemaFirstSubgraphSource {\n const unit = `./subgraphs/${dir}/` as const;\n const index = readText(join(projectRoot, \"subgraphs\", dir, \"index.ts\"));\n const name = index?.match(LITERAL_NAME)?.[1] ?? null;\n for (const [file, language] of SDL_FILES) {\n const text = readText(join(projectRoot, \"subgraphs\", dir, file));\n if (text !== null) {\n return {\n unit,\n name,\n source: { specifier: `${unit}${file}` },\n language,\n text,\n };\n }\n }\n return {\n unit,\n name,\n source: { specifier: `${unit}index.ts` },\n language: \"typescript\",\n text: null,\n };\n}\n","import { projectSubgraphGraphQL } from \"document-model\";\nimport { type DocumentNode, parse, print } from \"graphql\";\nimport {\n type ProjectDefinitions,\n readSubgraphDefinitions,\n subgraphCheckInput,\n type SubgraphCheckInput,\n type SubgraphDefinitions,\n type SubgraphHostConflict,\n type SubgraphImportFailure,\n type SubgraphInventoryEntry,\n} from \"document-model/tooling\";\nimport { statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { ProjectModules } from \"./project.js\";\nimport { schemaFirstSource } from \"./schema-first/sdl-sources.js\";\nimport { scanSubgraphs, SUBGRAPHS_ENTRY } from \"./subgraph-gate.js\";\n\nconst SCALARS_ENTRY = \"./scalars/index.ts\";\n\n/** A module that hangs on a top-level await must not hang `ph model`. */\nconst IMPORT_TIMEOUT_MS = 60_000;\n\nexport type ProjectSubgraphs = {\n readonly input: SubgraphCheckInput;\n readonly inventory: readonly SubgraphInventoryEntry[];\n};\n\ntype Imported =\n | { readonly ok: true; readonly namespace: object }\n | { readonly ok: false; readonly failure: SubgraphImportFailure };\n\nasync function importModule(\n modules: ProjectModules,\n specifier: `./${string}`,\n packageRoot: string,\n timeoutMs: number,\n): Promise<Imported> {\n let timer: NodeJS.Timeout | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(\n () =>\n reject(\n new Error(\n `it did not finish loading within ${timeoutMs / 1000} seconds`,\n ),\n ),\n timeoutMs,\n );\n timer.unref();\n });\n try {\n return {\n ok: true,\n namespace: await Promise.race([modules.importModule(specifier), timeout]),\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n ok: false,\n failure: { specifier, reason: message.replaceAll(packageRoot, \".\") },\n };\n } finally {\n clearTimeout(timer);\n }\n}\n\n/** The host's admission of the code-first subgraphs, replayed against its built-in subgraphs and the package's document models. */\nasync function replayHostAdmission(\n { subgraphs }: SubgraphDefinitions,\n artifacts: ProjectDefinitions[\"artifacts\"],\n): Promise<readonly SubgraphHostConflict[]> {\n if (subgraphs.length === 0) return [];\n const models = new Map(\n artifacts.map(({ documentType, documentModel }) => [\n documentType,\n documentModel.global,\n ]),\n );\n const { findPackageSubgraphConflicts } =\n await import(\"@powerhousedao/reactor-api/subgraph-types\");\n const { conflicts } = await findPackageSubgraphConflicts(\n subgraphs.map(({ name, definition }) => ({\n name,\n // The host serves the printed projection, parsed again.\n typeDefs: parse(\n print(projectSubgraphGraphQL(definition) as unknown as DocumentNode),\n ),\n })),\n [...models.values()],\n );\n return Array.from(conflicts).flatMap(\n ([subgraph, { nameHeldBy, claims }]): SubgraphHostConflict[] =>\n nameHeldBy === \"package\"\n ? []\n : [\n {\n subgraph,\n ...(nameHeldBy !== undefined && { nameHeldBy }),\n claims,\n },\n ],\n );\n}\n\nconst usesPackageScalars = ({ subgraphs }: SubgraphDefinitions) =>\n subgraphs.some(({ definition }) =>\n definition.scalars.some(({ implementation }) =>\n implementation.startsWith(\"package#\"),\n ),\n );\n\n/**\n * `undefined` when the project has no code-first subgraph: then nothing here\n * imports a module, and projects without one keep the reports they had. A\n * module that fails or outlives `timeoutMs` becomes a diagnostic.\n */\nexport async function readProjectSubgraphs(\n project: Pick<ProjectDefinitions, \"packageRoot\" | \"artifacts\">,\n modules: ProjectModules,\n timeoutMs: number = IMPORT_TIMEOUT_MS,\n): Promise<ProjectSubgraphs | undefined> {\n const root = project.packageRoot;\n const styles = scanSubgraphs(root);\n if (!styles.hasCodeFirst) return undefined;\n const schemaFirst = styles.schemaFirstUnits.map((dir) =>\n schemaFirstSource(root, dir),\n );\n const subgraphs = await importModule(\n modules,\n SUBGRAPHS_ENTRY,\n root,\n timeoutMs,\n );\n if (!subgraphs.ok) {\n return subgraphCheckInput({\n definitions: { subgraphs: [], diagnostics: [] },\n schemaFirst,\n importFailures: [subgraphs.failure],\n });\n }\n const definitions = readSubgraphDefinitions(subgraphs.namespace, {\n specifier: SUBGRAPHS_ENTRY,\n });\n const hostConflicts = await replayHostAdmission(\n definitions,\n project.artifacts,\n );\n if (!usesPackageScalars(definitions)) {\n return subgraphCheckInput({ definitions, schemaFirst, hostConflicts });\n }\n if (\n !(\n statSync(join(root, SCALARS_ENTRY), {\n throwIfNoEntry: false,\n })?.isFile() ?? false\n )\n ) {\n return subgraphCheckInput({\n definitions,\n schemaFirst,\n hostConflicts,\n scalars: null,\n });\n }\n const scalars = await importModule(modules, SCALARS_ENTRY, root, timeoutMs);\n return subgraphCheckInput(\n scalars.ok\n ? { definitions, schemaFirst, hostConflicts, scalars: scalars.namespace }\n : {\n definitions,\n schemaFirst,\n hostConflicts,\n importFailures: [scalars.failure],\n },\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAIA,MAAM,YAGC;CACL,CAAC,kBAAkB,SAAS;CAC5B,CAAC,aAAa,YAAY;CAC1B,CAAC,YAAY,YAAY;AAC3B;AAEA,MAAM,eAAe;AAErB,SAAS,SAAS,MAA6B;CAC7C,IAAI,EAAE,SAAS,MAAM,EAAE,gBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,KAAK,QAC3D,OAAO;CAET,OAAO,aAAa,MAAM,MAAM;AAClC;AAEA,SAAgB,kBACd,aACA,KAC2B;CAC3B,MAAM,OAAO,eAAe,IAAI;CAEhC,MAAM,OADQ,SAAS,KAAK,aAAa,aAAa,KAAK,UAAU,CACpD,CAAC,EAAE,MAAM,YAAY,CAAC,GAAG,MAAM;CAChD,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW;EACxC,MAAM,OAAO,SAAS,KAAK,aAAa,aAAa,KAAK,IAAI,CAAC;EAC/D,IAAI,SAAS,MACX,OAAO;GACL;GACA;GACA,QAAQ,EAAE,WAAW,GAAG,OAAO,OAAO;GACtC;GACA;EACF;CAEJ;CACA,OAAO;EACL;EACA;EACA,QAAQ,EAAE,WAAW,GAAG,KAAK,UAAU;EACvC,UAAU;EACV,MAAM;CACR;AACF;;;AC9BA,MAAM,gBAAgB;;AAGtB,MAAM,oBAAoB;AAW1B,eAAe,aACb,SACA,WACA,aACA,WACmB;CACnB,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,GAAG,WAAW;EAChD,QAA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,KAAA;CACjC,MAAM,cAAc,OAAO,iBAAiB,KAAK,QAC/C,kBAAkB,MAAM,GAAG,CAC7B;CACA,MAAM,YAAY,MAAM,aACtB,SACA,iBACA,MACA,SACF;CACA,IAAI,CAAC,UAAU,IACb,OAAO,mBAAmB;EACxB,aAAa;GAAE,WAAW,CAAC;GAAG,aAAa,CAAC;EAAE;EAC9C;EACA,gBAAgB,CAAC,UAAU,OAAO;CACpC,CAAC;CAEH,MAAM,cAAc,wBAAwB,UAAU,WAAW,EAC/D,WAAW,gBACb,CAAC;CACD,MAAM,gBAAgB,MAAM,oBAC1B,aACA,QAAQ,SACV;CACA,IAAI,CAAC,mBAAmB,WAAW,GACjC,OAAO,mBAAmB;EAAE;EAAa;EAAa;CAAc,CAAC;CAEvE,IACE,EACE,SAAS,KAAK,MAAM,aAAa,GAAG,EAClC,gBAAgB,MAClB,CAAC,CAAC,EAAE,OAAO,KAAK,QAGlB,OAAO,mBAAmB;EACxB;EACA;EACA;EACA,SAAS;CACX,CAAC;CAEH,MAAM,UAAU,MAAM,aAAa,SAAS,eAAe,MAAM,SAAS;CAC1E,OAAO,mBACL,QAAQ,KACJ;EAAE;EAAa;EAAa;EAAe,SAAS,QAAQ;CAAU,IACtE;EACE;EACA;EACA;EACA,gBAAgB,CAAC,QAAQ,OAAO;CAClC,CACN;AACF","debug_id":"1d9c1c84-45e5-55d7-970d-52f2a0d6a487"}
@@ -1,8 +1,8 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ee54547-f686-5213-81f6-e06f7bd4b297")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a4590bf9-a7c1-5c1d-acb0-f386667abb71")}catch(e){}}();
3
+ import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
3
4
  import { Kysely, PostgresDialect } from "kysely";
4
5
  import { Pool } from "pg";
5
- import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
6
6
  //#region src/services/switchboard-migrate.ts
7
7
  function isPostgresUrl(url) {
8
8
  return url.startsWith("postgresql://") || url.startsWith("postgres://");
@@ -14,7 +14,6 @@ async function runSwitchboardMigrations(options) {
14
14
  console.log("(PGlite migrations are handled automatically on startup)");
15
15
  return;
16
16
  }
17
- console.log(`Database: ${dbPath}`);
18
17
  const pool = new Pool({ connectionString: dbPath });
19
18
  const db = new Kysely({ dialect: new PostgresDialect({ pool }) });
20
19
  try {
@@ -50,5 +49,5 @@ async function runSwitchboardMigrations(options) {
50
49
  //#endregion
51
50
  export { runSwitchboardMigrations };
52
51
 
53
- //# sourceMappingURL=switchboard-migrate-7JQZM7-5.mjs.map
54
- //# debugId=8ee54547-f686-5213-81f6-e06f7bd4b297
52
+ //# sourceMappingURL=switchboard-migrate-BqSdKJ7u.mjs.map
53
+ //# debugId=a4590bf9-a7c1-5c1d-acb0-f386667abb71
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard-migrate-BqSdKJ7u.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n dbPath?: string;\n statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n options: MigrationOptions,\n): Promise<void> {\n const dbPath =\n options.dbPath ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (options.statusOnly) {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nMigration Status:\");\n console.log(\"=================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;CAEd,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,QAAQ,YAAY;GACtB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ,IAAI,qBAAqB;GACjC,QAAQ,IAAI,mBAAmB;GAE/B,KAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,YAAY,MACrD;IACJ,QAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,MAAM;GAC7C;EACF,OAAO;GACL,QAAQ,IAAI,yBAAyB;GACrC,MAAM,SAAS,MAAM,cAAc,IAAI,cAAc;GAErD,IAAI,CAAC,OAAO,SAAS;IACnB,QAAQ,MAAM,qBAAqB,OAAO,OAAO,OAAO;IACxD,QAAQ,KAAK,CAAC;GAChB;GAEA,IAAI,OAAO,mBAAmB,WAAW,GACvC,QAAQ,IAAI,+CAA+C;QACtD;IACL,QAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,eAC5D;IACA,KAAK,MAAM,QAAQ,OAAO,oBACxB,QAAQ,IAAI,OAAO,MAAM;GAE7B;EACF;CACF,SAAS,OAAO;EACd,QAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;EACA,QAAQ,KAAK,CAAC;CAChB,UAAU;EACR,MAAM,GAAG,QAAQ;CACnB;AACF","debug_id":"a4590bf9-a7c1-5c1d-acb0-f386667abb71"}
@@ -0,0 +1,37 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c5e3cd62-660a-5978-8304-6ea0c3f41894")}catch(e){}}();
3
+ import { SWITCHBOARD_PROXY_PATHS, isHtmlNavigation } from "@powerhousedao/shared/connect/origin-placeholder";
4
+ //#region src/utils/switchboard-proxy.ts
5
+ /**
6
+ * Vite proxy rules (dev and preview servers alike) that send the
7
+ * switchboard's paths to `target`, so a browser on Connect's origin reaches
8
+ * the switchboard through it and the served config can name the switchboard
9
+ * as `${origin}` (runner.proxy on the connect host).
10
+ *
11
+ * `/d/<drive>` is both a switchboard endpoint and one of Connect's own
12
+ * routes: a browser navigation there (it accepts HTML) is left to Connect,
13
+ * every other request on the path goes to the switchboard. GraphQL carries
14
+ * the subscriptions websocket, so that rule upgrades too. The Host header
15
+ * is left as the browser sent it: the switchboard builds the URLs it hands
16
+ * out from it, and on the page's origin is where they must point.
17
+ */
18
+ function switchboardProxy(target) {
19
+ const origin = new URL(target).origin;
20
+ const rules = {};
21
+ for (const prefix of SWITCHBOARD_PROXY_PATHS) {
22
+ const key = prefix.endsWith("/") ? `^${escape(prefix)}` : `^${escape(prefix)}(/|$)`;
23
+ rules[key] = {
24
+ target: origin,
25
+ changeOrigin: false,
26
+ ...prefix === "/graphql" ? { ws: true } : {},
27
+ ...prefix === "/d/" ? { bypass: (req) => isHtmlNavigation(req.headers.accept) ? req.url : void 0 } : {}
28
+ };
29
+ }
30
+ return rules;
31
+ }
32
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
33
+ //#endregion
34
+ export { switchboardProxy as t };
35
+
36
+ //# sourceMappingURL=switchboard-proxy-CGfMtENM.mjs.map
37
+ //# debugId=c5e3cd62-660a-5978-8304-6ea0c3f41894
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard-proxy-CGfMtENM.mjs","sources":["../src/utils/switchboard-proxy.ts"],"sourcesContent":["import {\n isHtmlNavigation,\n SWITCHBOARD_PROXY_PATHS,\n} from \"@powerhousedao/shared/connect/origin-placeholder\";\nimport type { ProxyOptions } from \"vite\";\n\n/**\n * Vite proxy rules (dev and preview servers alike) that send the\n * switchboard's paths to `target`, so a browser on Connect's origin reaches\n * the switchboard through it and the served config can name the switchboard\n * as `${origin}` (runner.proxy on the connect host).\n *\n * `/d/<drive>` is both a switchboard endpoint and one of Connect's own\n * routes: a browser navigation there (it accepts HTML) is left to Connect,\n * every other request on the path goes to the switchboard. GraphQL carries\n * the subscriptions websocket, so that rule upgrades too. The Host header\n * is left as the browser sent it: the switchboard builds the URLs it hands\n * out from it, and on the page's origin is where they must point.\n */\nexport function switchboardProxy(target: string): Record<string, ProxyOptions> {\n const origin = new URL(target).origin;\n const rules: Record<string, ProxyOptions> = {};\n for (const prefix of SWITCHBOARD_PROXY_PATHS) {\n const key = prefix.endsWith(\"/\")\n ? `^${escape(prefix)}`\n : `^${escape(prefix)}(/|$)`;\n rules[key] = {\n target: origin,\n changeOrigin: false,\n ...(prefix === \"/graphql\" ? { ws: true } : {}),\n ...(prefix === \"/d/\"\n ? {\n bypass: (req) =>\n isHtmlNavigation(req.headers.accept) ? req.url : undefined,\n }\n : {}),\n };\n }\n return rules;\n}\n\nconst escape = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,QAA8C;CAC7E,MAAM,SAAS,IAAI,IAAI,MAAM,CAAC,CAAC;CAC/B,MAAM,QAAsC,CAAC;CAC7C,KAAK,MAAM,UAAU,yBAAyB;EAC5C,MAAM,MAAM,OAAO,SAAS,GAAG,IAC3B,IAAI,OAAO,MAAM,MACjB,IAAI,OAAO,MAAM,EAAE;EACvB,MAAM,OAAO;GACX,QAAQ;GACR,cAAc;GACd,GAAI,WAAW,aAAa,EAAE,IAAI,KAAK,IAAI,CAAC;GAC5C,GAAI,WAAW,QACX,EACE,SAAS,QACP,iBAAiB,IAAI,QAAQ,MAAM,IAAI,IAAI,MAAM,KAAA,EACrD,IACA,CAAC;EACP;CACF;CACA,OAAO;AACT;AAEA,MAAM,UAAU,MAAc,EAAE,QAAQ,uBAAuB,MAAM","debug_id":"c5e3cd62-660a-5978-8304-6ea0c3f41894"}
@@ -1,7 +1,8 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="17d56bac-3fa6-5ce5-b8c7-495f6c94c9d7")}catch(e){}}();
3
- import { cyan, green, red, yellow } from "colorette";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="44d0c080-10cc-5316-947d-b0281777aade")}catch(e){}}();
4
3
  import { promises } from "node:fs";
4
+ import { cyan, green, red, yellow } from "colorette";
5
+ import { defaultStoreDirs } from "@powerhousedao/shared/clis/ph-dir";
5
6
  //#region src/services/switchboard-reset.ts
6
7
  const CONFIRMATION_TOKEN = "reset";
7
8
  function isPostgresUrl(url) {
@@ -18,10 +19,11 @@ function isInteractive() {
18
19
  * caller can refuse.
19
20
  */
20
21
  function resolveResetPaths(options, env = process.env) {
22
+ const defaults = defaultStoreDirs(env);
21
23
  const readModelDbPath = options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
22
- const readModelPath = readModelDbPath || ".ph/read-storage";
24
+ const readModelPath = readModelDbPath || defaults.readModel;
23
25
  const reactorDbUrl = options.dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
24
- const reactorPath = reactorDbUrl || "./.ph/reactor-storage";
26
+ const reactorPath = reactorDbUrl || defaults.reactor;
25
27
  const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);
26
28
  const readModelIsPostgres = !!readModelDbPath && isPostgresUrl(readModelDbPath);
27
29
  let postgresUrl = null;
@@ -83,5 +85,5 @@ async function resetSwitchboardDatabase(options) {
83
85
  //#endregion
84
86
  export { resetSwitchboardDatabase };
85
87
 
86
- //# sourceMappingURL=switchboard-reset-Ctegiqdm.mjs.map
87
- //# debugId=17d56bac-3fa6-5ce5-b8c7-495f6c94c9d7
88
+ //# sourceMappingURL=switchboard-reset-MtTB_GAI.mjs.map
89
+ //# debugId=44d0c080-10cc-5316-947d-b0281777aade
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchboard-reset-MtTB_GAI.mjs","sources":["../src/services/switchboard-reset.ts"],"sourcesContent":["import { defaultStoreDirs } from \"@powerhousedao/shared/clis/ph-dir\";\nimport { yellow, red, green, cyan } from \"colorette\";\nimport { promises as fs } from \"node:fs\";\n\nexport interface ResetSwitchboardOptions {\n dbPath?: string;\n yes?: boolean;\n}\n\nexport interface ResolvedResetPaths {\n reactorDir: string | null;\n readModelDir: string | null;\n postgresUrl: string | null;\n}\n\nconst CONFIRMATION_TOKEN = \"reset\";\n\nexport function isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nfunction isInteractive(): boolean {\n return Boolean(process.stdin.isTTY) && !process.env.CI;\n}\n\n/**\n * Resolves the on-disk PGlite directories that `--reset` would delete.\n * Mirrors the resolution in apps/switchboard/src/server.mts so we touch the\n * same paths the running switchboard uses. When a Postgres URL is configured\n * the corresponding directory is null and `postgresUrl` is populated so the\n * caller can refuse.\n */\nexport function resolveResetPaths(\n options: ResetSwitchboardOptions,\n env: NodeJS.ProcessEnv = process.env,\n): ResolvedResetPaths {\n const defaults = defaultStoreDirs(env);\n const readModelDbPath =\n options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;\n const readModelPath = readModelDbPath || defaults.readModel;\n const reactorDbUrl =\n options.dbPath ??\n env.PH_REACTOR_DATABASE_URL ??\n env.PH_SWITCHBOARD_DATABASE_URL;\n const reactorPath = reactorDbUrl || defaults.reactor;\n\n const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);\n const readModelIsPostgres =\n !!readModelDbPath && isPostgresUrl(readModelDbPath);\n\n let postgresUrl: string | null = null;\n if (reactorIsPostgres) postgresUrl = reactorDbUrl as string;\n else if (readModelIsPostgres) postgresUrl = readModelDbPath as string;\n\n return {\n reactorDir: reactorIsPostgres ? null : reactorPath,\n readModelDir: readModelIsPostgres ? null : readModelPath,\n postgresUrl,\n };\n}\n\nasync function promptForConfirmation(): Promise<boolean> {\n const enquirer = await import(\"enquirer\");\n try {\n const answer = await enquirer.default.prompt<{ confirmation: string }>({\n type: \"input\",\n name: \"confirmation\",\n message: `Type \"${CONFIRMATION_TOKEN}\" to confirm wiping the local switchboard databases:`,\n });\n return answer.confirmation.trim() === CONFIRMATION_TOKEN;\n } catch {\n return false;\n }\n}\n\nexport async function resetSwitchboardDatabase(\n options: ResetSwitchboardOptions,\n): Promise<void> {\n const paths = resolveResetPaths(options);\n\n if (paths.postgresUrl) {\n console.error(\n red(\n `Refusing to reset: a PostgreSQL URL is configured (${paths.postgresUrl}).`,\n ),\n );\n console.error(\n yellow(\n \"`ph switchboard --reset` only wipes the local PGlite stores. \" +\n \"To reset a Postgres-backed switchboard, drop/recreate the database manually.\",\n ),\n );\n process.exit(1);\n }\n\n const targets = [paths.reactorDir, paths.readModelDir].filter(\n (d): d is string => d !== null,\n );\n\n if (targets.length === 0) {\n console.error(red(\"No local PGlite directories resolved; nothing to do.\"));\n process.exit(1);\n }\n\n console.log(yellow(\"The following directories will be permanently deleted:\"));\n for (const dir of targets) {\n console.log(` - ${dir}`);\n }\n console.log(\n yellow(\n \"This will wipe all local switchboard state. Migrations will re-run on next `ph switchboard`.\",\n ),\n );\n\n let confirmed = false;\n if (options.yes) {\n confirmed = true;\n } else if (isInteractive()) {\n confirmed = await promptForConfirmation();\n } else {\n console.error(\n red(\n \"Refusing to reset in a non-interactive context without --yes. Re-run with --yes to confirm.\",\n ),\n );\n process.exit(1);\n }\n\n if (!confirmed) {\n console.error(red(\"Aborted: confirmation not provided.\"));\n process.exit(1);\n }\n\n for (const dir of targets) {\n await fs.rm(dir, { recursive: true, force: true });\n console.log(cyan(`Removed ${dir}`));\n }\n\n console.log(\n green(\n \"Switchboard local storage reset. Run `ph switchboard` to re-initialize.\",\n ),\n );\n}\n"],"names":["fs"],"mappings":";;;;;;AAeA,MAAM,qBAAqB;AAE3B,SAAgB,cAAc,KAAsB;CAClD,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,SAAS,gBAAyB;CAChC,OAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,CAAC,QAAQ,IAAI;AACtD;;;;;;;;AASA,SAAgB,kBACd,SACA,MAAyB,QAAQ,KACb;CACpB,MAAM,WAAW,iBAAiB,GAAG;CACrC,MAAM,kBACJ,QAAQ,UAAU,IAAI,gBAAgB,IAAI;CAC5C,MAAM,gBAAgB,mBAAmB,SAAS;CAClD,MAAM,eACJ,QAAQ,UACR,IAAI,2BACJ,IAAI;CACN,MAAM,cAAc,gBAAgB,SAAS;CAE7C,MAAM,oBAAoB,CAAC,CAAC,gBAAgB,cAAc,YAAY;CACtE,MAAM,sBACJ,CAAC,CAAC,mBAAmB,cAAc,eAAe;CAEpD,IAAI,cAA6B;CACjC,IAAI,mBAAmB,cAAc;MAChC,IAAI,qBAAqB,cAAc;CAE5C,OAAO;EACL,YAAY,oBAAoB,OAAO;EACvC,cAAc,sBAAsB,OAAO;EAC3C;CACF;AACF;AAEA,eAAe,wBAA0C;CACvD,MAAM,WAAW,MAAM,OAAO;CAC9B,IAAI;EAMF,QAAO,MALc,SAAS,QAAQ,OAAiC;GACrE,MAAM;GACN,MAAM;GACN,SAAS,SAAS,mBAAmB;EACvC,CAAC,EAAA,CACa,aAAa,KAAK,MAAM;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,QAAQ,kBAAkB,OAAO;CAEvC,IAAI,MAAM,aAAa;EACrB,QAAQ,MACN,IACE,sDAAsD,MAAM,YAAY,GAC1E,CACF;EACA,QAAQ,MACN,OACE,2IAEF,CACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,UAAU,CAAC,MAAM,YAAY,MAAM,YAAY,CAAC,CAAC,QACpD,MAAmB,MAAM,IAC5B;CAEA,IAAI,QAAQ,WAAW,GAAG;EACxB,QAAQ,MAAM,IAAI,sDAAsD,CAAC;EACzE,QAAQ,KAAK,CAAC;CAChB;CAEA,QAAQ,IAAI,OAAO,wDAAwD,CAAC;CAC5E,KAAK,MAAM,OAAO,SAChB,QAAQ,IAAI,OAAO,KAAK;CAE1B,QAAQ,IACN,OACE,8FACF,CACF;CAEA,IAAI,YAAY;CAChB,IAAI,QAAQ,KACV,YAAY;MACP,IAAI,cAAc,GACvB,YAAY,MAAM,sBAAsB;MACnC;EACL,QAAQ,MACN,IACE,6FACF,CACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI,CAAC,WAAW;EACd,QAAQ,MAAM,IAAI,qCAAqC,CAAC;EACxD,QAAQ,KAAK,CAAC;CAChB;CAEA,KAAK,MAAM,OAAO,SAAS;EACzB,MAAMA,SAAG,GAAG,KAAK;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EACjD,QAAQ,IAAI,KAAK,WAAW,KAAK,CAAC;CACpC;CAEA,QAAQ,IACN,MACE,yEACF,CACF;AACF","debug_id":"44d0c080-10cc-5316-947d-b0281777aade"}
@@ -0,0 +1,4 @@
1
+ import { r as syncProjectConnectRoutes } from "./sync-connect-routes-t0Slg-P6.mjs";
2
+ export { syncProjectConnectRoutes };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a0e16059-68ca-5115-9c0e-68e1b5113d9c")}catch(e){}}();
4
+ //# debugId=a0e16059-68ca-5115-9c0e-68e1b5113d9c
@@ -0,0 +1,25 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="635b041c-5cc1-56f7-aac5-714511c1dd4c")}catch(e){}}();
3
+ import { existsSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ //#region src/utils/sync-connect-routes.ts
6
+ const OFFERED_ROUTES_MODULE = ".ph/connect-routes.package.ts";
7
+ const HOST_ROUTES_DIR = "hosts/connect/routes";
8
+ const CONNECT_ROUTES_GEN = ".ph/connect-routes.gen.ts";
9
+ /** Writes the tree hosts/connect/routes/ type-checks against; without the
10
+ * folder, a tree there keeps Connect's routes only. Loads builder-tools only
11
+ * for a project with routes or a tree. */
12
+ async function syncProjectConnectRoutes(projectRoot) {
13
+ if (![
14
+ "hosts/connect/routes",
15
+ CONNECT_ROUTES_GEN,
16
+ ".ph/connect-routes.package.ts"
17
+ ].some((p) => existsSync(join(projectRoot, p)))) return;
18
+ const { resolveConnectRoutesDir, syncConnectRoutes } = await import("@powerhousedao/builder-tools");
19
+ await syncConnectRoutes(projectRoot, resolveConnectRoutesDir(projectRoot));
20
+ }
21
+ //#endregion
22
+ export { OFFERED_ROUTES_MODULE as n, syncProjectConnectRoutes as r, HOST_ROUTES_DIR as t };
23
+
24
+ //# sourceMappingURL=sync-connect-routes-t0Slg-P6.mjs.map
25
+ //# debugId=635b041c-5cc1-56f7-aac5-714511c1dd4c
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-connect-routes-t0Slg-P6.mjs","sources":["../src/utils/sync-connect-routes.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n// builder-tools' PACKAGE_ROUTES_MODULE and HOST_ROUTES_DIR, without loading it\n// for packages with no routes.\nexport const OFFERED_ROUTES_MODULE = \".ph/connect-routes.package.ts\";\nexport const HOST_ROUTES_DIR = \"hosts/connect/routes\";\nconst CONNECT_ROUTES_GEN = \".ph/connect-routes.gen.ts\";\n\n/** Writes the tree hosts/connect/routes/ type-checks against; without the\n * folder, a tree there keeps Connect's routes only. Loads builder-tools only\n * for a project with routes or a tree. */\nexport async function syncProjectConnectRoutes(projectRoot: string) {\n const probes = [HOST_ROUTES_DIR, CONNECT_ROUTES_GEN, OFFERED_ROUTES_MODULE];\n if (!probes.some((p) => existsSync(join(projectRoot, p)))) return;\n const { resolveConnectRoutesDir, syncConnectRoutes } =\n await import(\"@powerhousedao/builder-tools\");\n await syncConnectRoutes(projectRoot, resolveConnectRoutesDir(projectRoot));\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAa,wBAAwB;AACrC,MAAa,kBAAkB;AAC/B,MAAM,qBAAqB;;;;AAK3B,eAAsB,yBAAyB,aAAqB;CAElE,IAAI,CAAC;;EAD4B;;CACvB,CAAC,CAAC,MAAM,MAAM,WAAW,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG;CAC3D,MAAM,EAAE,yBAAyB,sBAC/B,MAAM,OAAO;CACf,MAAM,kBAAkB,aAAa,wBAAwB,WAAW,CAAC;AAC3E","debug_id":"635b041c-5cc1-56f7-aac5-714511c1dd4c"}
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="fa6f49e1-f268-5ae2-8e22-cc7adc8fbfba")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e3fbf59a-7996-5c5c-9db7-c8d207b68849")}catch(e){}}();
3
3
  import fs from "node:fs";
4
4
  import path, { dirname } from "node:path";
5
5
  import crypto from "node:crypto";
@@ -111,36 +111,8 @@ function updateConfigFile(dependencies, projectPath, task = "install", provider
111
111
  fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
112
112
  }
113
113
  /**
114
- * Updates the styles.css file to include imports for newly installed packages
115
- * @param dependencies - Array of dependencies that were installed
116
- * @param projectPath - Path to the project root
117
- */
118
- function updateStylesFile(dependencies, projectPath) {
119
- const stylesPath = path.join(projectPath, "style.css");
120
- if (!fs.existsSync(stylesPath)) {
121
- console.warn("⚠️ Warning: style.css file not found in project root");
122
- return;
123
- }
124
- const currentStyles = fs.readFileSync(stylesPath, "utf-8");
125
- let updatedStyles = currentStyles;
126
- for (const dep of dependencies) {
127
- const cssPath = `./node_modules/${dep.name}/dist/style.css`;
128
- const fullCssPath = path.join(projectPath, cssPath);
129
- const importStatement = `@import '${cssPath}';`;
130
- if (!fs.existsSync(fullCssPath)) {
131
- console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);
132
- continue;
133
- }
134
- if (currentStyles.includes(importStatement)) continue;
135
- const importLines = currentStyles.split("\n").filter((line) => line.trim().startsWith("@import"));
136
- const lastImport = importLines[importLines.length - 1];
137
- if (lastImport) updatedStyles = currentStyles.replace(lastImport, `${lastImport}\n${importStatement}`);
138
- else updatedStyles = `${importStatement}\n${currentStyles}`;
139
- }
140
- if (updatedStyles !== currentStyles) fs.writeFileSync(stylesPath, updatedStyles);
141
- }
142
- /**
143
- * Removes CSS imports for uninstalled packages from styles.css
114
+ * Removes the CSS imports `ph install --local` used to add to style.css for
115
+ * uninstalled packages; Connect now loads a bundled package's CSS with its code.
144
116
  */
145
117
  function removeStylesImports(dependencies, projectPath) {
146
118
  const stylesPath = path.join(projectPath, "style.css");
@@ -159,7 +131,7 @@ function removeStylesImports(dependencies, projectPath) {
159
131
  if (updatedStyles !== currentStyles) fs.writeFileSync(stylesPath, updatedStyles);
160
132
  }
161
133
  //#endregion
162
- export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o, updateStylesFile as p, defaultPathValidation as r, getProjectInfo as s, POWERHOUSE_CONFIG_FILE as t, removeStylesImports as u };
134
+ export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o, defaultPathValidation as r, getProjectInfo as s, POWERHOUSE_CONFIG_FILE as t, removeStylesImports as u };
163
135
 
164
- //# sourceMappingURL=utils-CvmDmCVd.mjs.map
165
- //# debugId=fa6f49e1-f268-5ae2-8e22-cc7adc8fbfba
136
+ //# sourceMappingURL=utils-9KyRM0mf.mjs.map
137
+ //# debugId=e3fbf59a-7996-5c5c-9db7-c8d207b68849
@@ -1 +1 @@
1
- {"version":3,"file":"utils-CvmDmCVd.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { PowerhouseConfig } from \"@powerhousedao/config\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path, { dirname } from \"node:path\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nexport const SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\n\nexport const packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n uninstallCommand: \"bun remove {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n updateCommand: \"bun update {{dependency}}\",\n buildAffected: \"bun run build:affected\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n uninstallCommand: \"pnpm remove {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n updateCommand: \"pnpm update {{dependency}}\",\n buildAffected: \"pnpm run build:affected\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n uninstallCommand: \"yarn remove {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n updateCommand: \"yarn upgrade {{dependency}}\",\n buildAffected: \"yarn run build:affected\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n uninstallCommand: \"npm uninstall {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n updateCommand: \"npm update {{dependency}} --save\",\n buildAffected: \"npm run build:affected\",\n },\n};\n\ntype PathValidation = (dir: string) => boolean;\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n packageManager: PackageManager;\n};\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n packageManager: getPackageManagerFromLockfile(POWERHOUSE_GLOBAL_DIR),\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n packageManager: getPackageManagerFromLockfile(projectPath),\n };\n}\n\n/**\n * Generates a unique drive ID based on the project path.\n * The same project path will always generate the same ID.\n * @param name - The name prefix for the drive ID (e.g., \"vetra\", \"powerhouse\")\n * @returns A unique drive ID in the format \"{name}-{hash}\"\n */\nexport function generateProjectDriveId(name: string): string {\n const projectInfo = getProjectInfo();\n const hash = crypto\n .createHash(\"sha256\")\n .update(projectInfo.path)\n .digest(\"hex\");\n const shortHash = hash.substring(0, 8);\n return `${name}-${shortHash}`;\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function updatePackagesArray(\n currentPackages: PowerhouseConfig[\"packages\"] = [],\n dependencies: { name: string; version: string | undefined }[],\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider,\n }));\n\n if (isInstall) {\n // Overwrite existing package if version is different\n const filteredPackages = currentPackages.filter(\n (pkg) => !dependencies.find((dep) => dep.name === pkg.packageName),\n );\n return [...filteredPackages, ...mappedPackages];\n }\n\n return currentPackages.filter(\n (pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName),\n );\n}\n\n// Modify updateConfigFile to use the new function\nexport function updateConfigFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n registryUrl?: string,\n registryUrlExplicit = false,\n) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: updatePackagesArray(\n config.packages,\n dependencies,\n task,\n provider,\n ),\n };\n\n if (\n task === \"install\" &&\n registryUrl &&\n (registryUrlExplicit || !config.packageRegistryUrl) &&\n dependencies.length > 0\n ) {\n updatedConfig.packageRegistryUrl = registryUrl;\n }\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\n/**\n * Recursively searches for a specific file by traversing up the directory tree.\n * Starting from the given path, it checks each parent directory until it finds\n * the target file or reaches the root directory.\n *\n * @param startPath - The absolute path of the directory to start searching from\n * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')\n * @returns The absolute path of the directory containing the target file, or null if not found\n *\n * @example\n * // Find the workspace root directory\n * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');\n *\n * // Find the nearest package.json\n * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');\n */\nexport const findContainerDirectory = (\n startPath: string,\n targetFile: string,\n): string | null => {\n const filePath = path.join(startPath, targetFile);\n\n if (fs.existsSync(filePath)) {\n return startPath;\n }\n\n const parentDir = path.dirname(startPath);\n\n //reached the root directory and haven't found the file\n if (parentDir === startPath) {\n return null;\n }\n\n return findContainerDirectory(parentDir, targetFile);\n};\n\n/**\n * Updates the styles.css file to include imports for newly installed packages\n * @param dependencies - Array of dependencies that were installed\n * @param projectPath - Path to the project root\n */\nexport function updateStylesFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const fullCssPath = path.join(projectPath, cssPath);\n const importStatement = `@import '${cssPath}';`;\n\n // Check if the CSS file exists\n if (!fs.existsSync(fullCssPath)) {\n console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);\n continue;\n }\n\n // Check if import already exists\n if (currentStyles.includes(importStatement)) {\n continue;\n }\n\n // Find the last @import statement\n const importLines = currentStyles\n .split(\"\\n\")\n .filter((line) => line.trim().startsWith(\"@import\"));\n const lastImport = importLines[importLines.length - 1];\n\n if (lastImport) {\n // Insert new import after the last existing import\n updatedStyles = currentStyles.replace(\n lastImport,\n `${lastImport}\\n${importStatement}`,\n );\n } else {\n // If no imports exist, add at the top of the file\n updatedStyles = `${importStatement}\\n${currentStyles}`;\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n\n/**\n * Removes CSS imports for uninstalled packages from styles.css\n */\nexport function removeStylesImports(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const importStatement = `@import '${cssPath}';`;\n\n // Remove the import line if it exists\n const lines = updatedStyles.split(\"\\n\");\n const filteredLines = lines.filter(\n (line) => !line.trim().includes(importStatement),\n );\n\n if (filteredLines.length !== lines.length) {\n updatedStyles = filteredLines.join(\"\\n\");\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,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IAAI,KAAK,iBACC;EAG5C,MAAM,QAAQ,cAAc,MAAM,IAAI;EACtC,MAAM,gBAAgB,MAAM,QACzB,SAAS,CAAC,KAAK,KAAK,CAAC,CAAC,SAAS,eAAe,CACjD;EAEA,IAAI,cAAc,WAAW,MAAM,QACjC,gBAAgB,cAAc,KAAK,IAAI;CAE3C;CAGA,IAAI,kBAAkB,eACpB,GAAG,cAAc,YAAY,aAAa;AAE9C","debug_id":"fa6f49e1-f268-5ae2-8e22-cc7adc8fbfba"}
1
+ {"version":3,"file":"utils-9KyRM0mf.mjs","sources":["../src/utils.ts"],"sourcesContent":["import type { PowerhouseConfig } from \"@powerhousedao/config\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path, { dirname } from \"node:path\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nexport const SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\n\nexport const packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n uninstallCommand: \"bun remove {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n updateCommand: \"bun update {{dependency}}\",\n buildAffected: \"bun run build:affected\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n uninstallCommand: \"pnpm remove {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n updateCommand: \"pnpm update {{dependency}}\",\n buildAffected: \"pnpm run build:affected\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n uninstallCommand: \"yarn remove {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n updateCommand: \"yarn upgrade {{dependency}}\",\n buildAffected: \"yarn run build:affected\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n uninstallCommand: \"npm uninstall {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n updateCommand: \"npm update {{dependency}} --save\",\n buildAffected: \"npm run build:affected\",\n },\n};\n\ntype PathValidation = (dir: string) => boolean;\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n packageManager: PackageManager;\n};\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n packageManager: getPackageManagerFromLockfile(POWERHOUSE_GLOBAL_DIR),\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n packageManager: getPackageManagerFromLockfile(projectPath),\n };\n}\n\n/**\n * Generates a unique drive ID based on the project path.\n * The same project path will always generate the same ID.\n * @param name - The name prefix for the drive ID (e.g., \"vetra\", \"powerhouse\")\n * @returns A unique drive ID in the format \"{name}-{hash}\"\n */\nexport function generateProjectDriveId(name: string): string {\n const projectInfo = getProjectInfo();\n const hash = crypto\n .createHash(\"sha256\")\n .update(projectInfo.path)\n .digest(\"hex\");\n const shortHash = hash.substring(0, 8);\n return `${name}-${shortHash}`;\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function updatePackagesArray(\n currentPackages: PowerhouseConfig[\"packages\"] = [],\n dependencies: { name: string; version: string | undefined }[],\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider,\n }));\n\n if (isInstall) {\n // Overwrite existing package if version is different\n const filteredPackages = currentPackages.filter(\n (pkg) => !dependencies.find((dep) => dep.name === pkg.packageName),\n );\n return [...filteredPackages, ...mappedPackages];\n }\n\n return currentPackages.filter(\n (pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName),\n );\n}\n\n// Modify updateConfigFile to use the new function\nexport function updateConfigFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n task: \"install\" | \"uninstall\" = \"install\",\n provider: \"registry\" | \"local\" = \"registry\",\n registryUrl?: string,\n registryUrlExplicit = false,\n) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: updatePackagesArray(\n config.packages,\n dependencies,\n task,\n provider,\n ),\n };\n\n if (\n task === \"install\" &&\n registryUrl &&\n (registryUrlExplicit || !config.packageRegistryUrl) &&\n dependencies.length > 0\n ) {\n updatedConfig.packageRegistryUrl = registryUrl;\n }\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\n/**\n * Recursively searches for a specific file by traversing up the directory tree.\n * Starting from the given path, it checks each parent directory until it finds\n * the target file or reaches the root directory.\n *\n * @param startPath - The absolute path of the directory to start searching from\n * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')\n * @returns The absolute path of the directory containing the target file, or null if not found\n *\n * @example\n * // Find the workspace root directory\n * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');\n *\n * // Find the nearest package.json\n * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');\n */\nexport const findContainerDirectory = (\n startPath: string,\n targetFile: string,\n): string | null => {\n const filePath = path.join(startPath, targetFile);\n\n if (fs.existsSync(filePath)) {\n return startPath;\n }\n\n const parentDir = path.dirname(startPath);\n\n //reached the root directory and haven't found the file\n if (parentDir === startPath) {\n return null;\n }\n\n return findContainerDirectory(parentDir, targetFile);\n};\n\n/**\n * Removes the CSS imports `ph install --local` used to add to style.css for\n * uninstalled packages; Connect now loads a bundled package's CSS with its code.\n */\nexport function removeStylesImports(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const importStatement = `@import '${cssPath}';`;\n\n // Remove the import line if it exists\n const lines = updatedStyles.split(\"\\n\");\n const filteredLines = lines.filter(\n (line) => !line.trim().includes(importStatement),\n );\n\n if (filteredLines.length !== lines.length) {\n updatedStyles = filteredLines.join(\"\\n\");\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB,KAAK,KAAK,QAAQ,GAAG,KAAK;AAG/D,MAAa,kBAAkB;CAC7B,KAAK;EACH,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;CACA,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;CACA,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;CACA,KAAK;EACH,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;AACF;AAYA,SAAgB,wBAAwB;CACtC,OAAO;AACT;AAEA,SAAgB,oBAAoB,KAAa;CAC/C,MAAM,uBAAuB,KAAK,KAAK,KAAK,sBAAsB;CAElE,OAAO,GAAG,WAAW,oBAAoB;AAC3C;AAEA,SAAgB,oBACd,KACA,iBAAiC,uBACjC;CACA,MAAM,kBAAkB,KAAK,KAAK,KAAK,cAAc;CAErD,IAAI,GAAG,WAAW,eAAe,KAAK,eAAe,GAAG,GACtD,OAAO;CAGT,MAAM,YAAY,QAAQ,GAAG;CAE7B,IAAI,cAAc,KAChB,OAAO;CAGT,OAAO,oBAAoB,WAAW,cAAc;AACtD;AAEA,SAAgB,eAAe,OAA8B;CAC3D,MAAM,cAAc,QAAQ,IAAI;CAEhC,IAAI,OACF,QAAQ,IAAI,mBAAmB,WAAW;CAG5C,MAAM,cAAc,oBAAoB,aAAa,mBAAmB;CAExE,IAAI,CAAC,aACH,OAAO;EACL,UAAU;EACV,MAAM;EACN,gBAAgB,8BAA8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ClB,GAAG,aAAa,YAAY,OAAO,CACrC;CAEA,MAAM,gBAAkC;EACtC,GAAG;EACH,UAAU,oBACR,OAAO,UACP,cACA,MACA,QACF;CACF;CAEA,IACE,SAAS,aACT,gBACC,uBAAuB,CAAC,OAAO,uBAChC,aAAa,SAAS,GAEtB,cAAc,qBAAqB;CAGrC,GAAG,cAAc,YAAY,KAAK,UAAU,eAAe,MAAM,CAAC,CAAC;AACrE;;;;;AA0CA,SAAgB,oBACd,cACA,aACA;CACA,MAAM,aAAa,KAAK,KAAK,aAAa,WAAW;CAGrD,IAAI,CAAC,GAAG,WAAW,UAAU,GAAG;EAC9B,QAAQ,KAAK,sDAAsD;EACnE;CACF;CAEA,MAAM,gBAAgB,GAAG,aAAa,YAAY,OAAO;CACzD,IAAI,gBAAgB;CAEpB,KAAK,MAAM,OAAO,cAAc;EAE9B,MAAM,kBAAkB,YAAY,kBADF,IAAI,KAAK,iBACC;EAG5C,MAAM,QAAQ,cAAc,MAAM,IAAI;EACtC,MAAM,gBAAgB,MAAM,QACzB,SAAS,CAAC,KAAK,KAAK,CAAC,CAAC,SAAS,eAAe,CACjD;EAEA,IAAI,cAAc,WAAW,MAAM,QACjC,gBAAgB,cAAc,KAAK,IAAI;CAE3C;CAGA,IAAI,kBAAkB,eACpB,GAAG,cAAc,YAAY,aAAa;AAE9C","debug_id":"e3fbf59a-7996-5c5c-9db7-c8d207b68849"}
@@ -0,0 +1,4 @@
1
+ import { d as updateConfigFile, u as removeStylesImports } from "./utils-9KyRM0mf.mjs";
2
+ export { removeStylesImports, updateConfigFile };
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="76be3b2a-b7dc-5775-8844-ce31e31fe2d1")}catch(e){}}();
4
+ //# debugId=76be3b2a-b7dc-5775-8844-ce31e31fe2d1