@geekmidas/cli 10.0.0-alpha.65 → 10.0.0-alpha.67

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 (229) hide show
  1. package/README.md +123 -177
  2. package/dist/{HostingerProvider-x9gQTAGZ.mjs → HostingerProvider-D85ayzTi.mjs} +4 -4
  3. package/dist/HostingerProvider-D85ayzTi.mjs.map +1 -0
  4. package/dist/{HostingerProvider-Dlmbfass.cjs → HostingerProvider-dxkwynSs.cjs} +4 -4
  5. package/dist/HostingerProvider-dxkwynSs.cjs.map +1 -0
  6. package/dist/{LegacyStateStore-BGoo__sO.cjs → LegacyStateStore-BZiO9-Lw.cjs} +2 -2
  7. package/dist/{LegacyStateStore-BGoo__sO.cjs.map → LegacyStateStore-BZiO9-Lw.cjs.map} +1 -1
  8. package/dist/{LegacyStateStore-BUu1nQ5u.mjs → LegacyStateStore-C39UKwmf.mjs} +2 -2
  9. package/dist/{LegacyStateStore-BUu1nQ5u.mjs.map → LegacyStateStore-C39UKwmf.mjs.map} +1 -1
  10. package/dist/{LocalStateStore-93urXyQe.cjs → LocalStateStore-DHVsZLyF.cjs} +2 -2
  11. package/dist/{LocalStateStore-93urXyQe.cjs.map → LocalStateStore-DHVsZLyF.cjs.map} +1 -1
  12. package/dist/{LocalStateStore-BRhMQRuy.mjs → LocalStateStore-Dk3Wbvzk.mjs} +2 -2
  13. package/dist/{LocalStateStore-BRhMQRuy.mjs.map → LocalStateStore-Dk3Wbvzk.mjs.map} +1 -1
  14. package/dist/{OpenApiTsGenerator-BWuDRHe9.cjs → OpenApiTsGenerator-B2zrdyP4.cjs} +2 -2
  15. package/dist/{OpenApiTsGenerator-BWuDRHe9.cjs.map → OpenApiTsGenerator-B2zrdyP4.cjs.map} +1 -1
  16. package/dist/{OpenApiTsGenerator-C6v-IeHt.mjs → OpenApiTsGenerator-BmUAcR7d.mjs} +2 -2
  17. package/dist/{OpenApiTsGenerator-C6v-IeHt.mjs.map → OpenApiTsGenerator-BmUAcR7d.mjs.map} +1 -1
  18. package/dist/{Route53Provider-DVILBsvV.cjs → Route53Provider-Bllus2NR.cjs} +2 -2
  19. package/dist/Route53Provider-Bllus2NR.cjs.map +1 -0
  20. package/dist/{Route53Provider-Cvj40A8I.mjs → Route53Provider-QXxjkZO1.mjs} +2 -2
  21. package/dist/Route53Provider-QXxjkZO1.mjs.map +1 -0
  22. package/dist/{S3StateStore-F4dxw6kS.cjs → S3StateStore--4tYVMAL.cjs} +2 -2
  23. package/dist/{S3StateStore-F4dxw6kS.cjs.map → S3StateStore--4tYVMAL.cjs.map} +1 -1
  24. package/dist/{S3StateStore-pw1GhWwt.mjs → S3StateStore-B_ZF9eHt.mjs} +2 -2
  25. package/dist/{S3StateStore-pw1GhWwt.mjs.map → S3StateStore-B_ZF9eHt.mjs.map} +1 -1
  26. package/dist/{SSMStateStore-Bt9acuAF.cjs → SSMStateStore-ACZ8hRvZ.cjs} +2 -2
  27. package/dist/{SSMStateStore-Bt9acuAF.cjs.map → SSMStateStore-ACZ8hRvZ.cjs.map} +1 -1
  28. package/dist/{SSMStateStore-Dmj7zzFO.mjs → SSMStateStore-DjPuKqrm.mjs} +2 -2
  29. package/dist/{SSMStateStore-Dmj7zzFO.mjs.map → SSMStateStore-DjPuKqrm.mjs.map} +1 -1
  30. package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
  31. package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
  32. package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
  33. package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
  34. package/dist/{bundler-D_14JLZF.mjs → bundler-Bq3HaLOZ.mjs} +20 -5
  35. package/dist/bundler-Bq3HaLOZ.mjs.map +1 -0
  36. package/dist/{bundler-D6MlIfBT.cjs → bundler-pyLj-gS0.cjs} +20 -5
  37. package/dist/bundler-pyLj-gS0.cjs.map +1 -0
  38. package/dist/{cli-P56vvrDQ.mjs → cli-C2Tjbn27.mjs} +6 -5
  39. package/dist/cli-C2Tjbn27.mjs.map +1 -0
  40. package/dist/{cli-BfH1deAT.cjs → cli-DR7B2_fX.cjs} +6 -5
  41. package/dist/cli-DR7B2_fX.cjs.map +1 -0
  42. package/dist/{compose-391oEKj1.cjs → compose-5oNHAKNT.cjs} +137 -667
  43. package/dist/compose-5oNHAKNT.cjs.map +1 -0
  44. package/dist/{compose-DprE3ASm.mjs → compose-BjToENzG.mjs} +130 -569
  45. package/dist/compose-BjToENzG.mjs.map +1 -0
  46. package/dist/{config-V_X_BMpm.d.cts → config-4XFxX1al.d.cts} +3 -3
  47. package/dist/{config-BonvTW8p.d.mts.map → config-4XFxX1al.d.cts.map} +1 -1
  48. package/dist/{config-BonvTW8p.d.mts → config-UtKzhpFb.d.mts} +3 -3
  49. package/dist/{config-V_X_BMpm.d.cts.map → config-UtKzhpFb.d.mts.map} +1 -1
  50. package/dist/config.cjs +3 -3
  51. package/dist/config.d.cts +3 -3
  52. package/dist/config.d.mts +3 -3
  53. package/dist/config.mjs +3 -3
  54. package/dist/{credentials-Bzbg23n8.cjs → credentials-BVs7mrtw.cjs} +239 -3
  55. package/dist/credentials-BVs7mrtw.cjs.map +1 -0
  56. package/dist/{credentials-Dq1MnWQf.mjs → credentials-pAtB70k3.mjs} +223 -5
  57. package/dist/credentials-pAtB70k3.mjs.map +1 -0
  58. package/dist/databases-C2p5LGAp.cjs +419 -0
  59. package/dist/databases-C2p5LGAp.cjs.map +1 -0
  60. package/dist/databases-hUHTuwhx.mjs +346 -0
  61. package/dist/databases-hUHTuwhx.mjs.map +1 -0
  62. package/dist/deploy/public.cjs +37 -28
  63. package/dist/deploy/public.cjs.map +1 -1
  64. package/dist/deploy/public.d.cts +136 -19
  65. package/dist/deploy/public.d.cts.map +1 -1
  66. package/dist/deploy/public.d.mts +136 -19
  67. package/dist/deploy/public.d.mts.map +1 -1
  68. package/dist/deploy/public.mjs +11 -11
  69. package/dist/deploy-BucRfbvX.cjs +511 -0
  70. package/dist/deploy-BucRfbvX.cjs.map +1 -0
  71. package/dist/deploy-DRAwTG72.mjs +488 -0
  72. package/dist/deploy-DRAwTG72.mjs.map +1 -0
  73. package/dist/{discover-LMrqsWSU.mjs → discover-BFoJWKGD.mjs} +4 -2
  74. package/dist/discover-BFoJWKGD.mjs.map +1 -0
  75. package/dist/{discover-DHdECueV.cjs → discover-OEfZ9OkA.cjs} +4 -2
  76. package/dist/discover-OEfZ9OkA.cjs.map +1 -0
  77. package/dist/dokploy-DIt1IZl1.mjs +38 -0
  78. package/dist/dokploy-DIt1IZl1.mjs.map +1 -0
  79. package/dist/dokploy-m345Zx02.cjs +38 -0
  80. package/dist/dokploy-m345Zx02.cjs.map +1 -0
  81. package/dist/{encryption-DF_hgIpl.mjs → encryption-Ccbahik7.mjs} +3 -5
  82. package/dist/{encryption-DF_hgIpl.mjs.map → encryption-Ccbahik7.mjs.map} +1 -1
  83. package/dist/{encryption-B1wJwgae.cjs → encryption-rZ3BghXy.cjs} +5 -7
  84. package/dist/{encryption-B1wJwgae.cjs.map → encryption-rZ3BghXy.cjs.map} +1 -1
  85. package/dist/{deploy-Cy8igpQF.cjs → engine-Cx_dvx9q.cjs} +1491 -1260
  86. package/dist/engine-Cx_dvx9q.cjs.map +1 -0
  87. package/dist/{deploy-CZ5nlpsu.mjs → engine-Gs0abjuj.mjs} +1450 -1261
  88. package/dist/engine-Gs0abjuj.mjs.map +1 -0
  89. package/dist/{github-B0YYE98x.mjs → github-CJANTYqi.mjs} +3 -3
  90. package/dist/{github-B0YYE98x.mjs.map → github-CJANTYqi.mjs.map} +1 -1
  91. package/dist/{github-CYcmTdFs.cjs → github-CrcGFkfD.cjs} +7 -7
  92. package/dist/{github-CYcmTdFs.cjs.map → github-CrcGFkfD.cjs.map} +1 -1
  93. package/dist/{index-DPUAGJaK.d.cts → index-CyApaHVe.d.cts} +2 -2
  94. package/dist/{index-DPUAGJaK.d.cts.map → index-CyApaHVe.d.cts.map} +1 -1
  95. package/dist/{index-DwKD_8lt.d.mts → index-DD1FfUHh.d.mts} +2 -2
  96. package/dist/{index-DwKD_8lt.d.mts.map → index-DD1FfUHh.d.mts.map} +1 -1
  97. package/dist/index.cjs +285 -91
  98. package/dist/index.cjs.map +1 -1
  99. package/dist/index.mjs +258 -68
  100. package/dist/index.mjs.map +1 -1
  101. package/dist/{migrate-q4pPAXtO.cjs → migrate-CQdSpttI.cjs} +16 -16
  102. package/dist/{migrate-q4pPAXtO.cjs.map → migrate-CQdSpttI.cjs.map} +1 -1
  103. package/dist/{migrate-B2qL5wj4.mjs → migrate-DCVo5gLS.mjs} +6 -6
  104. package/dist/{migrate-B2qL5wj4.mjs.map → migrate-DCVo5gLS.mjs.map} +1 -1
  105. package/dist/openapi.cjs +1 -1
  106. package/dist/openapi.d.cts +1 -1
  107. package/dist/openapi.d.mts +1 -1
  108. package/dist/openapi.mjs +1 -1
  109. package/dist/provider-B3Sv_a74.cjs +173 -0
  110. package/dist/provider-B3Sv_a74.cjs.map +1 -0
  111. package/dist/provider-D7rQzzzf.mjs +138 -0
  112. package/dist/provider-D7rQzzzf.mjs.map +1 -0
  113. package/dist/{ready-bQfu9GES.mjs → ready-2s3-CndS.mjs} +3 -3
  114. package/dist/{ready-bQfu9GES.mjs.map → ready-2s3-CndS.mjs.map} +1 -1
  115. package/dist/{ready-brEhh68f.cjs → ready-B6uHr4sm.cjs} +3 -3
  116. package/dist/{ready-brEhh68f.cjs.map → ready-B6uHr4sm.cjs.map} +1 -1
  117. package/dist/reconcile/public.cjs +1 -1
  118. package/dist/reconcile/public.d.cts +1 -1
  119. package/dist/reconcile/public.d.mts +1 -1
  120. package/dist/reconcile/public.mjs +1 -1
  121. package/dist/{resolve-N_i4XNd-.cjs → resolve-BexmDcsN.cjs} +4 -4
  122. package/dist/{resolve-N_i4XNd-.cjs.map → resolve-BexmDcsN.cjs.map} +1 -1
  123. package/dist/{resolve-DLkIXTct.mjs → resolve-DhZgtvZe.mjs} +4 -4
  124. package/dist/{resolve-DLkIXTct.mjs.map → resolve-DhZgtvZe.mjs.map} +1 -1
  125. package/dist/rollback-BnY7KuG_.cjs +161 -0
  126. package/dist/rollback-BnY7KuG_.cjs.map +1 -0
  127. package/dist/rollback-m4Yeym5x.mjs +132 -0
  128. package/dist/rollback-m4Yeym5x.mjs.map +1 -0
  129. package/dist/run-BJLIerMM.mjs +133 -0
  130. package/dist/run-BJLIerMM.mjs.map +1 -0
  131. package/dist/run-fVZ-rLnc.cjs +174 -0
  132. package/dist/run-fVZ-rLnc.cjs.map +1 -0
  133. package/dist/{runtime-BnD7Nn96.d.cts → runtime-BRqFOvPM.d.cts} +2 -2
  134. package/dist/{runtime-BnD7Nn96.d.cts.map → runtime-BRqFOvPM.d.cts.map} +1 -1
  135. package/dist/{runtime-j-tmFL65.d.mts → runtime-CEk5n4VH.d.mts} +2 -2
  136. package/dist/{runtime-j-tmFL65.d.mts.map → runtime-CEk5n4VH.d.mts.map} +1 -1
  137. package/dist/sandbox/discover-worker.cjs +1 -1
  138. package/dist/sandbox/discover-worker.mjs +1 -1
  139. package/dist/sandbox/migrate-worker.cjs +61 -0
  140. package/dist/sandbox/migrate-worker.cjs.map +1 -0
  141. package/dist/sandbox/migrate-worker.d.cts +1 -0
  142. package/dist/sandbox/migrate-worker.d.mts +1 -0
  143. package/dist/sandbox/migrate-worker.mjs +62 -0
  144. package/dist/sandbox/migrate-worker.mjs.map +1 -0
  145. package/dist/{schemas-D2LCF689.mjs → schemas-Cfhtpdo0.mjs} +10 -2
  146. package/dist/{schemas-Ckm_aBnF.cjs.map → schemas-Cfhtpdo0.mjs.map} +1 -1
  147. package/dist/{schemas-Ckm_aBnF.cjs → schemas-RUlKHu27.cjs} +15 -1
  148. package/dist/{schemas-D2LCF689.mjs.map → schemas-RUlKHu27.cjs.map} +1 -1
  149. package/dist/{sniffer-BZ-OJO4Y.mjs → sniffer-BdFeLSmA.mjs} +97 -600
  150. package/dist/sniffer-BdFeLSmA.mjs.map +1 -0
  151. package/dist/{sniffer-BSwaL-dX.cjs → sniffer-D66HIvi9.cjs} +110 -674
  152. package/dist/sniffer-D66HIvi9.cjs.map +1 -0
  153. package/dist/{sst-B2HbrDR3.mjs → sst-DRi3H5TB.mjs} +3 -3
  154. package/dist/{sst-B2HbrDR3.mjs.map → sst-DRi3H5TB.mjs.map} +1 -1
  155. package/dist/{sst-DcfsVH6x.cjs → sst-hBrKouBy.cjs} +5 -5
  156. package/dist/{sst-DcfsVH6x.cjs.map → sst-hBrKouBy.cjs.map} +1 -1
  157. package/dist/{state-DF26e_lo.cjs → state-DgmM4EKq.cjs} +2787 -1890
  158. package/dist/state-DgmM4EKq.cjs.map +1 -0
  159. package/dist/{state-B8YwmUZU.mjs → state-DkUStoqJ.mjs} +2813 -2084
  160. package/dist/state-DkUStoqJ.mjs.map +1 -0
  161. package/dist/target/public.cjs +1 -1
  162. package/dist/target/public.d.cts +2 -2
  163. package/dist/target/public.d.mts +2 -2
  164. package/dist/target/public.mjs +1 -1
  165. package/dist/{terminal-CfbiYUbZ.mjs → terminal-C3cv-OQu.mjs} +5 -5
  166. package/dist/{terminal-CfbiYUbZ.mjs.map → terminal-C3cv-OQu.mjs.map} +1 -1
  167. package/dist/{terminal-Bs5E1oxm.cjs → terminal-DjzgLu6m.cjs} +12 -16
  168. package/dist/{terminal-Bs5E1oxm.cjs.map → terminal-DjzgLu6m.cjs.map} +1 -1
  169. package/dist/{types-ByMWkXKP.d.cts → types-CSw2w69a.d.mts} +68 -10
  170. package/dist/types-CSw2w69a.d.mts.map +1 -0
  171. package/dist/{types-BCzMWBb6.d.mts → types-D5WIxRDP.d.cts} +69 -9
  172. package/dist/types-D5WIxRDP.d.cts.map +1 -0
  173. package/dist/vitest.cjs +1 -1
  174. package/dist/vitest.mjs +1 -1
  175. package/dist/workspace/index.cjs +1 -1
  176. package/dist/workspace/index.d.cts +2 -2
  177. package/dist/workspace/index.d.mts +2 -2
  178. package/dist/workspace/index.mjs +1 -1
  179. package/dist/{workspace-C06_pW4g.mjs → workspace-Be6uBhlF.mjs} +10 -3
  180. package/dist/workspace-Be6uBhlF.mjs.map +1 -0
  181. package/dist/{workspace-BewAHZIo.cjs → workspace-ON-bqiJz.cjs} +10 -3
  182. package/dist/workspace-ON-bqiJz.cjs.map +1 -0
  183. package/package.json +13 -13
  184. package/dist/HostingerProvider-Dlmbfass.cjs.map +0 -1
  185. package/dist/HostingerProvider-x9gQTAGZ.mjs.map +0 -1
  186. package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
  187. package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
  188. package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
  189. package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
  190. package/dist/bundler-D6MlIfBT.cjs.map +0 -1
  191. package/dist/bundler-D_14JLZF.mjs.map +0 -1
  192. package/dist/cli-BfH1deAT.cjs.map +0 -1
  193. package/dist/cli-P56vvrDQ.mjs.map +0 -1
  194. package/dist/compose-391oEKj1.cjs.map +0 -1
  195. package/dist/compose-DprE3ASm.mjs.map +0 -1
  196. package/dist/credentials-Bzbg23n8.cjs.map +0 -1
  197. package/dist/credentials-Dq1MnWQf.mjs.map +0 -1
  198. package/dist/deploy-9MBG_QLd.mjs +0 -137
  199. package/dist/deploy-9MBG_QLd.mjs.map +0 -1
  200. package/dist/deploy-B80idPUZ.cjs +0 -142
  201. package/dist/deploy-B80idPUZ.cjs.map +0 -1
  202. package/dist/deploy-CZ5nlpsu.mjs.map +0 -1
  203. package/dist/deploy-Cy8igpQF.cjs.map +0 -1
  204. package/dist/discover-DHdECueV.cjs.map +0 -1
  205. package/dist/discover-LMrqsWSU.mjs.map +0 -1
  206. package/dist/dokploy-BdtBePjp.mjs +0 -32
  207. package/dist/dokploy-BdtBePjp.mjs.map +0 -1
  208. package/dist/dokploy-iFY8MY-L.cjs +0 -32
  209. package/dist/dokploy-iFY8MY-L.cjs.map +0 -1
  210. package/dist/local-BdH4XN0E.cjs +0 -409
  211. package/dist/local-BdH4XN0E.cjs.map +0 -1
  212. package/dist/local-CWR4Y_kW.mjs +0 -350
  213. package/dist/local-CWR4Y_kW.mjs.map +0 -1
  214. package/dist/sniffer-BSwaL-dX.cjs.map +0 -1
  215. package/dist/sniffer-BZ-OJO4Y.mjs.map +0 -1
  216. package/dist/state-B8YwmUZU.mjs.map +0 -1
  217. package/dist/state-DF26e_lo.cjs.map +0 -1
  218. package/dist/storage-BzaUxmqe.mjs +0 -124
  219. package/dist/storage-BzaUxmqe.mjs.map +0 -1
  220. package/dist/storage-CSGoC3bK.cjs +0 -152
  221. package/dist/storage-CSGoC3bK.cjs.map +0 -1
  222. package/dist/store-CJF1Tqkq.cjs +0 -510
  223. package/dist/store-CJF1Tqkq.cjs.map +0 -1
  224. package/dist/store-CLiHnqOY.mjs +0 -415
  225. package/dist/store-CLiHnqOY.mjs.map +0 -1
  226. package/dist/types-BCzMWBb6.d.mts.map +0 -1
  227. package/dist/types-ByMWkXKP.d.cts.map +0 -1
  228. package/dist/workspace-BewAHZIo.cjs.map +0 -1
  229. package/dist/workspace-C06_pW4g.mjs.map +0 -1
@@ -0,0 +1,161 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
+ const require_credentials = require("./credentials-BVs7mrtw.cjs");
3
+ const require_sandbox = require("./sandbox-CL--ZDui.cjs");
4
+ const require_workspace = require("./workspace-ON-bqiJz.cjs");
5
+ const require_config = require("./config.cjs");
6
+ const require_state = require("./state-DgmM4EKq.cjs");
7
+ const require_sniffer = require("./sniffer-D66HIvi9.cjs");
8
+ const require_engine = require("./engine-Cx_dvx9q.cjs");
9
+ let node_path = require("node:path");
10
+ //#region src/target/dokploy/rollback.ts
11
+ /**
12
+ * `gkm deploy:rollback`: a stage's apps put back on the release before the
13
+ * one they run, by hand — for a release that passed its checks and turned out
14
+ * wrong anyway.
15
+ *
16
+ * One app by default, because an app is what usually broke: rolling the API
17
+ * back over a site fix that shipped beside it undoes the fix too. `atomic`
18
+ * rolls back every app that has a release to go back to, for apps that only
19
+ * work together — an API and the site built against its newer contract.
20
+ *
21
+ * It restores images and nothing else. The environment an app runs with is
22
+ * the stage's, resolved on every deploy, and migrations are forward-only: a
23
+ * migration that the older code cannot run against is undone by a new
24
+ * migration, never by a rollback.
25
+ */
26
+ var rollback_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
27
+ NothingToRollBack: () => NothingToRollBack,
28
+ RollbackNeedsApp: () => RollbackNeedsApp,
29
+ StageNeverDeployed: () => StageNeverDeployed,
30
+ rollbackStage: () => rollbackStage
31
+ });
32
+ /** Neither an app nor every app was asked for. */
33
+ var RollbackNeedsApp = class extends Error {
34
+ stage;
35
+ apps;
36
+ constructor(stage, apps) {
37
+ super(`Say what to roll back: --app <name> for one app (${apps.join(", ") || "none has an earlier release"}), or --atomic for every app of "${stage}" together.`);
38
+ this.stage = stage;
39
+ this.apps = apps;
40
+ this.name = "RollbackNeedsApp";
41
+ }
42
+ };
43
+ /** An app has no release before the one it runs. */
44
+ var NothingToRollBack = class extends Error {
45
+ stage;
46
+ app;
47
+ constructor(stage, app) {
48
+ super(`"${app}" has no earlier release on "${stage}" to roll back to: it has been released once, or every earlier release was itself rolled back. Deploy the version you want instead.`);
49
+ this.stage = stage;
50
+ this.app = app;
51
+ this.name = "NothingToRollBack";
52
+ }
53
+ };
54
+ /** The stage was never deployed through Dokploy from this state. */
55
+ var StageNeverDeployed = class extends Error {
56
+ stage;
57
+ constructor(stage) {
58
+ super(`"${stage}" has no deploy state, so there is nothing to roll back. Check the stage name, and that \`state\` in gkm.config.ts points at the store the deploys write to.`);
59
+ this.stage = stage;
60
+ this.name = "StageNeverDeployed";
61
+ }
62
+ };
63
+ /**
64
+ * Roll a stage's app — or, `atomic`, all of them — back to its previous
65
+ * release, holding the stage's lock as a deploy does.
66
+ */
67
+ async function rollbackStage(input) {
68
+ const signal = input.signal ?? new AbortController().signal;
69
+ const log = input.log ?? (() => {});
70
+ const credentials = input.credentials ?? require_credentials.storedCredentials();
71
+ const sandbox = input.sandbox ?? new require_credentials.LocalSandbox({ root: require_config.findWorkspaceRoot((0, node_path.resolve)(input.cwd)) });
72
+ return require_sandbox.withSandbox(sandbox, async () => {
73
+ const { workspace } = await require_config.loadWorkspaceConfig((0, node_path.resolve)(input.cwd), { sandbox });
74
+ require_workspace.assertDeployedStage(workspace.stages, input.stage);
75
+ const store = await require_sniffer.createStateStore({
76
+ config: workspace.state,
77
+ workspaceRoot: workspace.root,
78
+ workspaceName: workspace.name
79
+ });
80
+ if (!await store.read(input.stage)) throw new StageNeverDeployed(input.stage);
81
+ const lock = await store.lock(input.stage, { operation: "rollback" });
82
+ try {
83
+ const journal = await require_state.DeployJournal.open(store, input.stage, () => require_state.createEmptyState(input.stage, "", ""));
84
+ const { state } = journal;
85
+ const releases = state.releases ?? {};
86
+ const restorable = Object.keys(releases).filter((app) => releases[app].previous);
87
+ let apps;
88
+ if (input.atomic) {
89
+ apps = restorable;
90
+ if (apps.length === 0) throw new RollbackNeedsApp(input.stage, restorable);
91
+ } else if (input.app) {
92
+ if (!releases[input.app]?.previous) throw new NothingToRollBack(input.stage, input.app);
93
+ apps = [input.app];
94
+ } else throw new RollbackNeedsApp(input.stage, restorable);
95
+ const { api } = await require_engine.dokployApi(workspace, {
96
+ credentials,
97
+ signal
98
+ });
99
+ const verify = require_engine.verifySettings(workspace.deploy.dokploy?.verify);
100
+ const rolled = [];
101
+ for (const app of apps) {
102
+ signal.throwIfAborted();
103
+ const { current, previous } = releases[app];
104
+ const applicationId = state.applications[app];
105
+ if (!previous || !applicationId) throw new NothingToRollBack(input.stage, app);
106
+ log(`⏪ ${app}: ${current.ref} → ${previous.ref}`);
107
+ await require_engine.restoreImage(api, {
108
+ applicationId,
109
+ image: previous,
110
+ registryId: state.registryId,
111
+ verify,
112
+ signal
113
+ });
114
+ require_state.recordRollback(state, app, previous);
115
+ await journal.save();
116
+ log(` ✓ ${app} is running ${previous.ref}`);
117
+ rolled.push({
118
+ app,
119
+ from: current,
120
+ to: previous
121
+ });
122
+ }
123
+ return rolled;
124
+ } finally {
125
+ await lock.release();
126
+ }
127
+ });
128
+ }
129
+ //#endregion
130
+ Object.defineProperty(exports, "NothingToRollBack", {
131
+ enumerable: true,
132
+ get: function() {
133
+ return NothingToRollBack;
134
+ }
135
+ });
136
+ Object.defineProperty(exports, "RollbackNeedsApp", {
137
+ enumerable: true,
138
+ get: function() {
139
+ return RollbackNeedsApp;
140
+ }
141
+ });
142
+ Object.defineProperty(exports, "StageNeverDeployed", {
143
+ enumerable: true,
144
+ get: function() {
145
+ return StageNeverDeployed;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, "rollbackStage", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return rollbackStage;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, "rollback_exports", {
155
+ enumerable: true,
156
+ get: function() {
157
+ return rollback_exports;
158
+ }
159
+ });
160
+
161
+ //# sourceMappingURL=rollback-BnY7KuG_.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollback-BnY7KuG_.cjs","names":["storedCredentials","LocalSandbox","findWorkspaceRoot","resolve","withSandbox","loadWorkspaceConfig","createStateStore","DeployJournal","createEmptyState","dokployApi","verifySettings","restoreImage"],"sources":["../src/target/dokploy/rollback.ts"],"sourcesContent":["/**\n * `gkm deploy:rollback`: a stage's apps put back on the release before the\n * one they run, by hand — for a release that passed its checks and turned out\n * wrong anyway.\n *\n * One app by default, because an app is what usually broke: rolling the API\n * back over a site fix that shipped beside it undoes the fix too. `atomic`\n * rolls back every app that has a release to go back to, for apps that only\n * work together — an API and the site built against its newer contract.\n *\n * It restores images and nothing else. The environment an app runs with is\n * the stage's, resolved on every deploy, and migrations are forward-only: a\n * migration that the older code cannot run against is undone by a new\n * migration, never by a rollback.\n */\n\nimport { resolve } from 'node:path';\nimport { findWorkspaceRoot, loadWorkspaceConfig } from '../../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../../deploy/credentials';\nimport { DeployJournal } from '../../deploy/journal';\nimport { createStateStore } from '../../deploy/StateStore';\nimport {\n\tcreateEmptyState,\n\ttype ReleasedImage,\n\trecordRollback,\n} from '../../deploy/state';\nimport { LocalSandbox } from '../../sandbox/local';\nimport { type Sandbox, withSandbox } from '../../sandbox/sandbox';\nimport { assertDeployedStage } from '../../workspace/stages';\nimport { dokployApi, restoreImage, verifySettings } from './engine';\n\nexport interface RollbackInput {\n\t/** The project: the directory holding `gkm.config.ts`, or one inside it. */\n\tcwd: string;\n\tstage: string;\n\t/** The app to roll back. */\n\tapp?: string;\n\t/** Every app with an earlier release, instead of one. */\n\tatomic?: boolean;\n\t/** Defaults to the environment, then the logins `gkm login` stored. */\n\tcredentials?: CredentialProvider;\n\tsignal?: AbortSignal;\n\t/** Each progress line. Defaults to none. */\n\tlog?: (line: string) => void;\n\t/** Where the config is loaded. Defaults to a `LocalSandbox` on the project. */\n\tsandbox?: Sandbox;\n}\n\n/** One app rolled back. */\nexport interface RolledBack {\n\tapp: string;\n\tfrom: ReleasedImage;\n\tto: ReleasedImage;\n}\n\n/** Neither an app nor every app was asked for. */\nexport class RollbackNeedsApp extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The apps that have a release to go back to. */\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Say what to roll back: --app <name> for one app (${apps.join(', ') || 'none has an earlier release'}), ` +\n\t\t\t\t`or --atomic for every app of \"${stage}\" together.`,\n\t\t);\n\t\tthis.name = 'RollbackNeedsApp';\n\t}\n}\n\n/** An app has no release before the one it runs. */\nexport class NothingToRollBack extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`\"${app}\" has no earlier release on \"${stage}\" to roll back to: it has been released once, ` +\n\t\t\t\t'or every earlier release was itself rolled back. Deploy the version you want instead.',\n\t\t);\n\t\tthis.name = 'NothingToRollBack';\n\t}\n}\n\n/** The stage was never deployed through Dokploy from this state. */\nexport class StageNeverDeployed extends Error {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`\"${stage}\" has no deploy state, so there is nothing to roll back. ` +\n\t\t\t\t'Check the stage name, and that `state` in gkm.config.ts points at the store the deploys write to.',\n\t\t);\n\t\tthis.name = 'StageNeverDeployed';\n\t}\n}\n\n/**\n * Roll a stage's app — or, `atomic`, all of them — back to its previous\n * release, holding the stage's lock as a deploy does.\n */\nexport async function rollbackStage(\n\tinput: RollbackInput,\n): Promise<RolledBack[]> {\n\tconst signal = input.signal ?? new AbortController().signal;\n\tconst log = input.log ?? (() => {});\n\tconst credentials = input.credentials ?? storedCredentials();\n\tconst sandbox =\n\t\tinput.sandbox ??\n\t\tnew LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });\n\n\treturn withSandbox(sandbox, async () => {\n\t\tconst { workspace } = await loadWorkspaceConfig(resolve(input.cwd), {\n\t\t\tsandbox,\n\t\t});\n\t\tassertDeployedStage(workspace.stages, input.stage);\n\n\t\tconst store = await createStateStore({\n\t\t\tconfig: workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t});\n\t\tif (!(await store.read(input.stage))) {\n\t\t\tthrow new StageNeverDeployed(input.stage);\n\t\t}\n\n\t\tconst lock = await store.lock(input.stage, { operation: 'rollback' });\n\t\ttry {\n\t\t\tconst journal = await DeployJournal.open(store, input.stage, () =>\n\t\t\t\tcreateEmptyState(input.stage, '', ''),\n\t\t\t);\n\t\t\tconst { state } = journal;\n\t\t\tconst releases = state.releases ?? {};\n\t\t\tconst restorable = Object.keys(releases).filter(\n\t\t\t\t(app) => releases[app]!.previous,\n\t\t\t);\n\n\t\t\tlet apps: string[];\n\t\t\tif (input.atomic) {\n\t\t\t\tapps = restorable;\n\t\t\t\tif (apps.length === 0) {\n\t\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t\t}\n\t\t\t} else if (input.app) {\n\t\t\t\tif (!releases[input.app]?.previous) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, input.app);\n\t\t\t\t}\n\t\t\t\tapps = [input.app];\n\t\t\t} else {\n\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t}\n\n\t\t\tconst { api } = await dokployApi(workspace, { credentials, signal });\n\t\t\tconst verify = verifySettings(workspace.deploy.dokploy?.verify);\n\t\t\tconst rolled: RolledBack[] = [];\n\n\t\t\tfor (const app of apps) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst { current, previous } = releases[app]!;\n\t\t\t\tconst applicationId = state.applications[app];\n\t\t\t\tif (!previous || !applicationId) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, app);\n\t\t\t\t}\n\n\t\t\t\tlog(`⏪ ${app}: ${current.ref} → ${previous.ref}`);\n\t\t\t\tawait restoreImage(api, {\n\t\t\t\t\tapplicationId,\n\t\t\t\t\timage: previous,\n\t\t\t\t\tregistryId: state.registryId,\n\t\t\t\t\tverify,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\trecordRollback(state, app, previous);\n\t\t\t\tawait journal.save();\n\t\t\t\tlog(` ✓ ${app} is running ${previous.ref}`);\n\t\t\t\trolled.push({ app, from: current, to: previous });\n\t\t\t}\n\n\t\t\treturn rolled;\n\t\t} finally {\n\t\t\tawait lock.release();\n\t\t}\n\t});\n}\n"],"mappings":"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"}
@@ -0,0 +1,132 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
+ import { i as LocalSandbox, r as storedCredentials } from "./credentials-pAtB70k3.mjs";
3
+ import { c as withSandbox } from "./sandbox-Dm247NGx.mjs";
4
+ import { k as assertDeployedStage } from "./workspace-Be6uBhlF.mjs";
5
+ import { findWorkspaceRoot, loadWorkspaceConfig } from "./config.mjs";
6
+ import { o as recordRollback, p as DeployJournal, t as createEmptyState } from "./state-DkUStoqJ.mjs";
7
+ import { g as createStateStore } from "./sniffer-BdFeLSmA.mjs";
8
+ import { i as dokployApi, l as restoreImage, p as verifySettings } from "./engine-Gs0abjuj.mjs";
9
+ import { resolve } from "node:path";
10
+ //#region src/target/dokploy/rollback.ts
11
+ /**
12
+ * `gkm deploy:rollback`: a stage's apps put back on the release before the
13
+ * one they run, by hand — for a release that passed its checks and turned out
14
+ * wrong anyway.
15
+ *
16
+ * One app by default, because an app is what usually broke: rolling the API
17
+ * back over a site fix that shipped beside it undoes the fix too. `atomic`
18
+ * rolls back every app that has a release to go back to, for apps that only
19
+ * work together — an API and the site built against its newer contract.
20
+ *
21
+ * It restores images and nothing else. The environment an app runs with is
22
+ * the stage's, resolved on every deploy, and migrations are forward-only: a
23
+ * migration that the older code cannot run against is undone by a new
24
+ * migration, never by a rollback.
25
+ */
26
+ var rollback_exports = /* @__PURE__ */ __exportAll({
27
+ NothingToRollBack: () => NothingToRollBack,
28
+ RollbackNeedsApp: () => RollbackNeedsApp,
29
+ StageNeverDeployed: () => StageNeverDeployed,
30
+ rollbackStage: () => rollbackStage
31
+ });
32
+ /** Neither an app nor every app was asked for. */
33
+ var RollbackNeedsApp = class extends Error {
34
+ stage;
35
+ apps;
36
+ constructor(stage, apps) {
37
+ super(`Say what to roll back: --app <name> for one app (${apps.join(", ") || "none has an earlier release"}), or --atomic for every app of "${stage}" together.`);
38
+ this.stage = stage;
39
+ this.apps = apps;
40
+ this.name = "RollbackNeedsApp";
41
+ }
42
+ };
43
+ /** An app has no release before the one it runs. */
44
+ var NothingToRollBack = class extends Error {
45
+ stage;
46
+ app;
47
+ constructor(stage, app) {
48
+ super(`"${app}" has no earlier release on "${stage}" to roll back to: it has been released once, or every earlier release was itself rolled back. Deploy the version you want instead.`);
49
+ this.stage = stage;
50
+ this.app = app;
51
+ this.name = "NothingToRollBack";
52
+ }
53
+ };
54
+ /** The stage was never deployed through Dokploy from this state. */
55
+ var StageNeverDeployed = class extends Error {
56
+ stage;
57
+ constructor(stage) {
58
+ super(`"${stage}" has no deploy state, so there is nothing to roll back. Check the stage name, and that \`state\` in gkm.config.ts points at the store the deploys write to.`);
59
+ this.stage = stage;
60
+ this.name = "StageNeverDeployed";
61
+ }
62
+ };
63
+ /**
64
+ * Roll a stage's app — or, `atomic`, all of them — back to its previous
65
+ * release, holding the stage's lock as a deploy does.
66
+ */
67
+ async function rollbackStage(input) {
68
+ const signal = input.signal ?? new AbortController().signal;
69
+ const log = input.log ?? (() => {});
70
+ const credentials = input.credentials ?? storedCredentials();
71
+ const sandbox = input.sandbox ?? new LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });
72
+ return withSandbox(sandbox, async () => {
73
+ const { workspace } = await loadWorkspaceConfig(resolve(input.cwd), { sandbox });
74
+ assertDeployedStage(workspace.stages, input.stage);
75
+ const store = await createStateStore({
76
+ config: workspace.state,
77
+ workspaceRoot: workspace.root,
78
+ workspaceName: workspace.name
79
+ });
80
+ if (!await store.read(input.stage)) throw new StageNeverDeployed(input.stage);
81
+ const lock = await store.lock(input.stage, { operation: "rollback" });
82
+ try {
83
+ const journal = await DeployJournal.open(store, input.stage, () => createEmptyState(input.stage, "", ""));
84
+ const { state } = journal;
85
+ const releases = state.releases ?? {};
86
+ const restorable = Object.keys(releases).filter((app) => releases[app].previous);
87
+ let apps;
88
+ if (input.atomic) {
89
+ apps = restorable;
90
+ if (apps.length === 0) throw new RollbackNeedsApp(input.stage, restorable);
91
+ } else if (input.app) {
92
+ if (!releases[input.app]?.previous) throw new NothingToRollBack(input.stage, input.app);
93
+ apps = [input.app];
94
+ } else throw new RollbackNeedsApp(input.stage, restorable);
95
+ const { api } = await dokployApi(workspace, {
96
+ credentials,
97
+ signal
98
+ });
99
+ const verify = verifySettings(workspace.deploy.dokploy?.verify);
100
+ const rolled = [];
101
+ for (const app of apps) {
102
+ signal.throwIfAborted();
103
+ const { current, previous } = releases[app];
104
+ const applicationId = state.applications[app];
105
+ if (!previous || !applicationId) throw new NothingToRollBack(input.stage, app);
106
+ log(`⏪ ${app}: ${current.ref} → ${previous.ref}`);
107
+ await restoreImage(api, {
108
+ applicationId,
109
+ image: previous,
110
+ registryId: state.registryId,
111
+ verify,
112
+ signal
113
+ });
114
+ recordRollback(state, app, previous);
115
+ await journal.save();
116
+ log(` ✓ ${app} is running ${previous.ref}`);
117
+ rolled.push({
118
+ app,
119
+ from: current,
120
+ to: previous
121
+ });
122
+ }
123
+ return rolled;
124
+ } finally {
125
+ await lock.release();
126
+ }
127
+ });
128
+ }
129
+ //#endregion
130
+ export { rollback_exports as a, rollbackStage as i, RollbackNeedsApp as n, StageNeverDeployed as r, NothingToRollBack as t };
131
+
132
+ //# sourceMappingURL=rollback-m4Yeym5x.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollback-m4Yeym5x.mjs","names":[],"sources":["../src/target/dokploy/rollback.ts"],"sourcesContent":["/**\n * `gkm deploy:rollback`: a stage's apps put back on the release before the\n * one they run, by hand — for a release that passed its checks and turned out\n * wrong anyway.\n *\n * One app by default, because an app is what usually broke: rolling the API\n * back over a site fix that shipped beside it undoes the fix too. `atomic`\n * rolls back every app that has a release to go back to, for apps that only\n * work together — an API and the site built against its newer contract.\n *\n * It restores images and nothing else. The environment an app runs with is\n * the stage's, resolved on every deploy, and migrations are forward-only: a\n * migration that the older code cannot run against is undone by a new\n * migration, never by a rollback.\n */\n\nimport { resolve } from 'node:path';\nimport { findWorkspaceRoot, loadWorkspaceConfig } from '../../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../../deploy/credentials';\nimport { DeployJournal } from '../../deploy/journal';\nimport { createStateStore } from '../../deploy/StateStore';\nimport {\n\tcreateEmptyState,\n\ttype ReleasedImage,\n\trecordRollback,\n} from '../../deploy/state';\nimport { LocalSandbox } from '../../sandbox/local';\nimport { type Sandbox, withSandbox } from '../../sandbox/sandbox';\nimport { assertDeployedStage } from '../../workspace/stages';\nimport { dokployApi, restoreImage, verifySettings } from './engine';\n\nexport interface RollbackInput {\n\t/** The project: the directory holding `gkm.config.ts`, or one inside it. */\n\tcwd: string;\n\tstage: string;\n\t/** The app to roll back. */\n\tapp?: string;\n\t/** Every app with an earlier release, instead of one. */\n\tatomic?: boolean;\n\t/** Defaults to the environment, then the logins `gkm login` stored. */\n\tcredentials?: CredentialProvider;\n\tsignal?: AbortSignal;\n\t/** Each progress line. Defaults to none. */\n\tlog?: (line: string) => void;\n\t/** Where the config is loaded. Defaults to a `LocalSandbox` on the project. */\n\tsandbox?: Sandbox;\n}\n\n/** One app rolled back. */\nexport interface RolledBack {\n\tapp: string;\n\tfrom: ReleasedImage;\n\tto: ReleasedImage;\n}\n\n/** Neither an app nor every app was asked for. */\nexport class RollbackNeedsApp extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The apps that have a release to go back to. */\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Say what to roll back: --app <name> for one app (${apps.join(', ') || 'none has an earlier release'}), ` +\n\t\t\t\t`or --atomic for every app of \"${stage}\" together.`,\n\t\t);\n\t\tthis.name = 'RollbackNeedsApp';\n\t}\n}\n\n/** An app has no release before the one it runs. */\nexport class NothingToRollBack extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`\"${app}\" has no earlier release on \"${stage}\" to roll back to: it has been released once, ` +\n\t\t\t\t'or every earlier release was itself rolled back. Deploy the version you want instead.',\n\t\t);\n\t\tthis.name = 'NothingToRollBack';\n\t}\n}\n\n/** The stage was never deployed through Dokploy from this state. */\nexport class StageNeverDeployed extends Error {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`\"${stage}\" has no deploy state, so there is nothing to roll back. ` +\n\t\t\t\t'Check the stage name, and that `state` in gkm.config.ts points at the store the deploys write to.',\n\t\t);\n\t\tthis.name = 'StageNeverDeployed';\n\t}\n}\n\n/**\n * Roll a stage's app — or, `atomic`, all of them — back to its previous\n * release, holding the stage's lock as a deploy does.\n */\nexport async function rollbackStage(\n\tinput: RollbackInput,\n): Promise<RolledBack[]> {\n\tconst signal = input.signal ?? new AbortController().signal;\n\tconst log = input.log ?? (() => {});\n\tconst credentials = input.credentials ?? storedCredentials();\n\tconst sandbox =\n\t\tinput.sandbox ??\n\t\tnew LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });\n\n\treturn withSandbox(sandbox, async () => {\n\t\tconst { workspace } = await loadWorkspaceConfig(resolve(input.cwd), {\n\t\t\tsandbox,\n\t\t});\n\t\tassertDeployedStage(workspace.stages, input.stage);\n\n\t\tconst store = await createStateStore({\n\t\t\tconfig: workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t});\n\t\tif (!(await store.read(input.stage))) {\n\t\t\tthrow new StageNeverDeployed(input.stage);\n\t\t}\n\n\t\tconst lock = await store.lock(input.stage, { operation: 'rollback' });\n\t\ttry {\n\t\t\tconst journal = await DeployJournal.open(store, input.stage, () =>\n\t\t\t\tcreateEmptyState(input.stage, '', ''),\n\t\t\t);\n\t\t\tconst { state } = journal;\n\t\t\tconst releases = state.releases ?? {};\n\t\t\tconst restorable = Object.keys(releases).filter(\n\t\t\t\t(app) => releases[app]!.previous,\n\t\t\t);\n\n\t\t\tlet apps: string[];\n\t\t\tif (input.atomic) {\n\t\t\t\tapps = restorable;\n\t\t\t\tif (apps.length === 0) {\n\t\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t\t}\n\t\t\t} else if (input.app) {\n\t\t\t\tif (!releases[input.app]?.previous) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, input.app);\n\t\t\t\t}\n\t\t\t\tapps = [input.app];\n\t\t\t} else {\n\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t}\n\n\t\t\tconst { api } = await dokployApi(workspace, { credentials, signal });\n\t\t\tconst verify = verifySettings(workspace.deploy.dokploy?.verify);\n\t\t\tconst rolled: RolledBack[] = [];\n\n\t\t\tfor (const app of apps) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst { current, previous } = releases[app]!;\n\t\t\t\tconst applicationId = state.applications[app];\n\t\t\t\tif (!previous || !applicationId) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, app);\n\t\t\t\t}\n\n\t\t\t\tlog(`⏪ ${app}: ${current.ref} → ${previous.ref}`);\n\t\t\t\tawait restoreImage(api, {\n\t\t\t\t\tapplicationId,\n\t\t\t\t\timage: previous,\n\t\t\t\t\tregistryId: state.registryId,\n\t\t\t\t\tverify,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\trecordRollback(state, app, previous);\n\t\t\t\tawait journal.save();\n\t\t\t\tlog(` ✓ ${app} is running ${previous.ref}`);\n\t\t\t\trolled.push({ app, from: current, to: previous });\n\t\t\t}\n\n\t\t\treturn rolled;\n\t\t} finally {\n\t\t\tawait lock.release();\n\t\t}\n\t});\n}\n"],"mappings":"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"}
@@ -0,0 +1,133 @@
1
+ import { join, resolve } from "node:path";
2
+ import { homedir } from "node:os";
3
+ import { spawn } from "node:child_process";
4
+ //#region src/home.ts
5
+ /**
6
+ * Where the CLI keeps what belongs to a person rather than a project: stage
7
+ * keys and stored provider credentials.
8
+ *
9
+ * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give
10
+ * every run its own instead of reaching into whoever's home directory the
11
+ * process happens to have. Unset, it is `~/.gkm`, where it has always been.
12
+ */
13
+ /** The environment variable that moves the CLI's home. */
14
+ const GKM_HOME_ENV = "GKM_HOME";
15
+ /** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */
16
+ function gkmHome(env = process.env) {
17
+ const configured = env[GKM_HOME_ENV];
18
+ return configured ? resolve(configured) : join(homedir(), ".gkm");
19
+ }
20
+ //#endregion
21
+ //#region src/run.ts
22
+ /**
23
+ * Start a program with an argument array, never a shell string.
24
+ *
25
+ * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the
26
+ * workspace — image refs, tags, build args, package names — to `docker` and
27
+ * `turbo`. Joined into a string and handed to a shell, a package named
28
+ * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which
29
+ * matters most where the CLI builds a repository it didn't write: a CI job for a
30
+ * fork, a shared build runner. Here every value reaches the program as one
31
+ * `argv` element, whatever it contains.
32
+ */
33
+ /** Long enough for a cold image build; short enough that a hung one ends. */
34
+ const DEFAULT_TIMEOUT_MS = 18e5;
35
+ /** How long a timed-out child has to exit on SIGTERM before it is killed. */
36
+ const KILL_GRACE_MS = 5e3;
37
+ /** The command line as a person would read it — for messages, never to run. */
38
+ function display(command, args) {
39
+ return [command, ...args].join(" ");
40
+ }
41
+ /** The program ran and exited unsuccessfully; its own output said why. */
42
+ var CommandFailed = class extends Error {
43
+ command;
44
+ args;
45
+ exitCode;
46
+ signal;
47
+ constructor(command, args, exitCode, signal) {
48
+ super(`\`${display(command, args)}\` ${exitCode === null ? `was stopped by ${signal ?? "a signal"}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`);
49
+ this.command = command;
50
+ this.args = args;
51
+ this.exitCode = exitCode;
52
+ this.signal = signal;
53
+ this.name = "CommandFailed";
54
+ }
55
+ };
56
+ /** The program ran past its timeout and was killed. */
57
+ var CommandTimedOut = class extends Error {
58
+ command;
59
+ args;
60
+ timeoutMs;
61
+ constructor(command, args, timeoutMs) {
62
+ super(`\`${display(command, args)}\` was still running after ${Math.round(timeoutMs / 1e3)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`);
63
+ this.command = command;
64
+ this.args = args;
65
+ this.timeoutMs = timeoutMs;
66
+ this.name = "CommandTimedOut";
67
+ }
68
+ };
69
+ /**
70
+ * Run `command` with `args`, resolving when it exits 0.
71
+ *
72
+ * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}
73
+ * once `timeoutMs` passes (after the child is gone), and with the spawn error
74
+ * itself when the program cannot be started at all — `ENOENT` already names it.
75
+ */
76
+ async function run(command, args, options = {}) {
77
+ await spawnChild(command, args, options, false);
78
+ }
79
+ /**
80
+ * {@link run}, resolving with what the program wrote to stdout — for a value
81
+ * the CLI reads back, such as the digest `docker inspect` reports. stderr still
82
+ * reaches the terminal, so a failure explains itself the same way.
83
+ */
84
+ function runOutput(command, args, options = {}) {
85
+ return spawnChild(command, args, options, true);
86
+ }
87
+ function spawnChild(command, args, options, capture) {
88
+ const { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;
89
+ return new Promise((resolve, reject) => {
90
+ const child = spawn(command, [...args], {
91
+ stdio: "inherit",
92
+ ...spawnOptions,
93
+ ...capture ? { stdio: [
94
+ "ignore",
95
+ "pipe",
96
+ "inherit"
97
+ ] } : {},
98
+ shell: false
99
+ });
100
+ let stdout = "";
101
+ child.stdout?.on("data", (chunk) => {
102
+ stdout += chunk.toString();
103
+ });
104
+ let timedOut = false;
105
+ let killer;
106
+ const timer = setTimeout(() => {
107
+ timedOut = true;
108
+ child.kill("SIGTERM");
109
+ killer = setTimeout(() => child.kill("SIGKILL"), KILL_GRACE_MS);
110
+ killer.unref?.();
111
+ }, timeoutMs);
112
+ timer.unref?.();
113
+ const settle = () => {
114
+ clearTimeout(timer);
115
+ if (killer) clearTimeout(killer);
116
+ };
117
+ child.on("error", (error) => {
118
+ settle();
119
+ reject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);
120
+ });
121
+ child.on("close", (code, signal) => {
122
+ settle();
123
+ if (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);
124
+ else if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));
125
+ else if (code === 0) resolve(stdout);
126
+ else reject(new CommandFailed(command, args, code, signal));
127
+ });
128
+ });
129
+ }
130
+ //#endregion
131
+ export { runOutput as a, run as i, CommandTimedOut as n, GKM_HOME_ENV as o, DEFAULT_TIMEOUT_MS as r, gkmHome as s, CommandFailed as t };
132
+
133
+ //# sourceMappingURL=run-BJLIerMM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-BJLIerMM.mjs","names":[],"sources":["../src/home.ts","../src/run.ts"],"sourcesContent":["/**\n * Where the CLI keeps what belongs to a person rather than a project: stage\n * keys and stored provider credentials.\n *\n * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give\n * every run its own instead of reaching into whoever's home directory the\n * process happens to have. Unset, it is `~/.gkm`, where it has always been.\n */\n\nimport { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\n/** The environment variable that moves the CLI's home. */\nexport const GKM_HOME_ENV = 'GKM_HOME';\n\n/** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */\nexport function gkmHome(env: NodeJS.ProcessEnv = process.env): string {\n\tconst configured = env[GKM_HOME_ENV];\n\treturn configured ? resolve(configured) : join(homedir(), '.gkm');\n}\n","/**\n * Start a program with an argument array, never a shell string.\n *\n * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the\n * workspace — image refs, tags, build args, package names — to `docker` and\n * `turbo`. Joined into a string and handed to a shell, a package named\n * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which\n * matters most where the CLI builds a repository it didn't write: a CI job for a\n * fork, a shared build runner. Here every value reaches the program as one\n * `argv` element, whatever it contains.\n */\n\nimport { type SpawnOptions, spawn } from 'node:child_process';\n\n/** Long enough for a cold image build; short enough that a hung one ends. */\nexport const DEFAULT_TIMEOUT_MS = 30 * 60_000;\n\n/** How long a timed-out child has to exit on SIGTERM before it is killed. */\nconst KILL_GRACE_MS = 5_000;\n\nexport interface RunOptions {\n\tcwd?: string;\n\tenv?: NodeJS.ProcessEnv;\n\tstdio?: SpawnOptions['stdio'];\n\t/** Kill the child after this long. Defaults to {@link DEFAULT_TIMEOUT_MS}. */\n\ttimeoutMs?: number;\n\t/**\n\t * Kills the child when aborted, and rejects with the signal's reason — the\n\t * same as a stopped deploy's other calls.\n\t */\n\tsignal?: AbortSignal;\n}\n\n/** The command line as a person would read it — for messages, never to run. */\nfunction display(command: string, args: readonly string[]): string {\n\treturn [command, ...args].join(' ');\n}\n\n/** The program ran and exited unsuccessfully; its own output said why. */\nexport class CommandFailed extends Error {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly args: readonly string[],\n\t\treadonly exitCode: number | null,\n\t\treadonly signal: NodeJS.Signals | null,\n\t) {\n\t\tsuper(\n\t\t\t`\\`${display(command, args)}\\` ${exitCode === null ? `was stopped by ${signal ?? 'a signal'}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`,\n\t\t);\n\t\tthis.name = 'CommandFailed';\n\t}\n}\n\n/** The program ran past its timeout and was killed. */\nexport class CommandTimedOut extends Error {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly args: readonly string[],\n\t\treadonly timeoutMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`\\`${display(command, args)}\\` was still running after ${Math.round(timeoutMs / 1000)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`,\n\t\t);\n\t\tthis.name = 'CommandTimedOut';\n\t}\n}\n\n/**\n * Run `command` with `args`, resolving when it exits 0.\n *\n * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}\n * once `timeoutMs` passes (after the child is gone), and with the spawn error\n * itself when the program cannot be started at all — `ENOENT` already names it.\n */\nexport async function run(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: RunOptions = {},\n): Promise<void> {\n\tawait spawnChild(command, args, options, false);\n}\n\n/**\n * {@link run}, resolving with what the program wrote to stdout — for a value\n * the CLI reads back, such as the digest `docker inspect` reports. stderr still\n * reaches the terminal, so a failure explains itself the same way.\n */\nexport function runOutput(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: Omit<RunOptions, 'stdio'> = {},\n): Promise<string> {\n\treturn spawnChild(command, args, options, true);\n}\n\nfunction spawnChild(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: RunOptions,\n\tcapture: boolean,\n): Promise<string> {\n\tconst { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;\n\n\treturn new Promise<string>((resolve, reject) => {\n\t\tconst child = spawn(command, [...args], {\n\t\t\tstdio: 'inherit',\n\t\t\t...spawnOptions,\n\t\t\t...(capture ? { stdio: ['ignore', 'pipe', 'inherit'] } : {}),\n\t\t\tshell: false,\n\t\t});\n\n\t\tlet stdout = '';\n\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\tstdout += chunk.toString();\n\t\t});\n\n\t\tlet timedOut = false;\n\t\tlet killer: NodeJS.Timeout | undefined;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tchild.kill('SIGTERM');\n\t\t\t// A child that ignores SIGTERM would hold the deploy open forever.\n\t\t\tkiller = setTimeout(() => child.kill('SIGKILL'), KILL_GRACE_MS);\n\t\t\tkiller.unref?.();\n\t\t}, timeoutMs);\n\t\ttimer.unref?.();\n\n\t\tconst settle = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (killer) clearTimeout(killer);\n\t\t};\n\n\t\tchild.on('error', (error) => {\n\t\t\tsettle();\n\t\t\t// Node reports an abort as its own `AbortError`; the caller asked\n\t\t\t// with a reason, and that is what it should get back.\n\t\t\treject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);\n\t\t});\n\n\t\tchild.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n\t\t\tsettle();\n\t\t\tif (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);\n\t\t\telse if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));\n\t\t\telse if (code === 0) resolve(stdout);\n\t\t\telse reject(new CommandFailed(command, args, code, signal));\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,eAAe;;AAG5B,SAAgB,QAAQ,MAAyB,QAAQ,KAAa;CACrE,MAAM,aAAa,IAAI;CACvB,OAAO,aAAa,QAAQ,UAAU,IAAI,KAAK,QAAQ,GAAG,MAAM;AACjE;;;;;;;;;;;;;;;ACJA,MAAa,qBAAqB;;AAGlC,MAAM,gBAAgB;;AAgBtB,SAAS,QAAQ,SAAiB,MAAiC;CAClE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,KAAK,GAAG;AACnC;;AAGA,IAAa,gBAAb,cAAmC,MAAM;CAE9B;CACA;CACA;CACA;CAJV,YACC,SACA,MACA,UACA,QACC;EACD,MACC,KAAK,QAAQ,SAAS,IAAI,EAAE,KAAK,aAAa,OAAO,kBAAkB,UAAU,eAAe,oBAAoB,WAAW,6DAChI;EAPS,KAAA,UAAA;EACA,KAAA,OAAA;EACA,KAAA,WAAA;EACA,KAAA,SAAA;EAKT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAEhC;CACA;CACA;CAHV,YACC,SACA,MACA,WACC;EACD,MACC,KAAK,QAAQ,SAAS,IAAI,EAAE,6BAA6B,KAAK,MAAM,YAAY,GAAI,EAAE,8GACvF;EANS,KAAA,UAAA;EACA,KAAA,OAAA;EACA,KAAA,YAAA;EAKT,KAAK,OAAO;CACb;AACD;;;;;;;;AASA,eAAsB,IACrB,SACA,MACA,UAAsB,CAAC,GACP;CAChB,MAAM,WAAW,SAAS,MAAM,SAAS,KAAK;AAC/C;;;;;;AAOA,SAAgB,UACf,SACA,MACA,UAAqC,CAAC,GACpB;CAClB,OAAO,WAAW,SAAS,MAAM,SAAS,IAAI;AAC/C;AAEA,SAAS,WACR,SACA,MACA,SACA,SACkB;CAClB,MAAM,EAAE,YAAY,oBAAoB,GAAG,iBAAiB;CAE5D,OAAO,IAAI,SAAiB,SAAS,WAAW;EAC/C,MAAM,QAAQ,MAAM,SAAS,CAAC,GAAG,IAAI,GAAG;GACvC,OAAO;GACP,GAAG;GACH,GAAI,UAAU,EAAE,OAAO;IAAC;IAAU;IAAQ;GAAS,EAAE,IAAI,CAAC;GAC1D,OAAO;EACR,CAAC;EAED,IAAI,SAAS;EACb,MAAM,QAAQ,GAAG,SAAS,UAAkB;GAC3C,UAAU,MAAM,SAAS;EAC1B,CAAC;EAED,IAAI,WAAW;EACf,IAAI;EACJ,MAAM,QAAQ,iBAAiB;GAC9B,WAAW;GACX,MAAM,KAAK,SAAS;GAEpB,SAAS,iBAAiB,MAAM,KAAK,SAAS,GAAG,aAAa;GAC9D,OAAO,QAAQ;EAChB,GAAG,SAAS;EACZ,MAAM,QAAQ;EAEd,MAAM,eAAe;GACpB,aAAa,KAAK;GAClB,IAAI,QAAQ,aAAa,MAAM;EAChC;EAEA,MAAM,GAAG,UAAU,UAAU;GAC5B,OAAO;GAGP,OAAO,aAAa,QAAQ,UAAU,aAAa,OAAO,SAAS,KAAK;EACzE,CAAC;EAED,MAAM,GAAG,UAAU,MAAqB,WAAkC;GACzE,OAAO;GACP,IAAI,aAAa,QAAQ,SAAS,OAAO,aAAa,OAAO,MAAM;QAC9D,IAAI,UAAU,OAAO,IAAI,gBAAgB,SAAS,MAAM,SAAS,CAAC;QAClE,IAAI,SAAS,GAAG,QAAQ,MAAM;QAC9B,OAAO,IAAI,cAAc,SAAS,MAAM,MAAM,MAAM,CAAC;EAC3D,CAAC;CACF,CAAC;AACF"}
@@ -0,0 +1,174 @@
1
+ let node_path = require("node:path");
2
+ let node_os = require("node:os");
3
+ let node_child_process = require("node:child_process");
4
+ //#region src/home.ts
5
+ /**
6
+ * Where the CLI keeps what belongs to a person rather than a project: stage
7
+ * keys and stored provider credentials.
8
+ *
9
+ * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give
10
+ * every run its own instead of reaching into whoever's home directory the
11
+ * process happens to have. Unset, it is `~/.gkm`, where it has always been.
12
+ */
13
+ /** The environment variable that moves the CLI's home. */
14
+ const GKM_HOME_ENV = "GKM_HOME";
15
+ /** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */
16
+ function gkmHome(env = process.env) {
17
+ const configured = env[GKM_HOME_ENV];
18
+ return configured ? (0, node_path.resolve)(configured) : (0, node_path.join)((0, node_os.homedir)(), ".gkm");
19
+ }
20
+ //#endregion
21
+ //#region src/run.ts
22
+ /**
23
+ * Start a program with an argument array, never a shell string.
24
+ *
25
+ * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the
26
+ * workspace — image refs, tags, build args, package names — to `docker` and
27
+ * `turbo`. Joined into a string and handed to a shell, a package named
28
+ * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which
29
+ * matters most where the CLI builds a repository it didn't write: a CI job for a
30
+ * fork, a shared build runner. Here every value reaches the program as one
31
+ * `argv` element, whatever it contains.
32
+ */
33
+ /** Long enough for a cold image build; short enough that a hung one ends. */
34
+ const DEFAULT_TIMEOUT_MS = 18e5;
35
+ /** How long a timed-out child has to exit on SIGTERM before it is killed. */
36
+ const KILL_GRACE_MS = 5e3;
37
+ /** The command line as a person would read it — for messages, never to run. */
38
+ function display(command, args) {
39
+ return [command, ...args].join(" ");
40
+ }
41
+ /** The program ran and exited unsuccessfully; its own output said why. */
42
+ var CommandFailed = class extends Error {
43
+ command;
44
+ args;
45
+ exitCode;
46
+ signal;
47
+ constructor(command, args, exitCode, signal) {
48
+ super(`\`${display(command, args)}\` ${exitCode === null ? `was stopped by ${signal ?? "a signal"}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`);
49
+ this.command = command;
50
+ this.args = args;
51
+ this.exitCode = exitCode;
52
+ this.signal = signal;
53
+ this.name = "CommandFailed";
54
+ }
55
+ };
56
+ /** The program ran past its timeout and was killed. */
57
+ var CommandTimedOut = class extends Error {
58
+ command;
59
+ args;
60
+ timeoutMs;
61
+ constructor(command, args, timeoutMs) {
62
+ super(`\`${display(command, args)}\` was still running after ${Math.round(timeoutMs / 1e3)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`);
63
+ this.command = command;
64
+ this.args = args;
65
+ this.timeoutMs = timeoutMs;
66
+ this.name = "CommandTimedOut";
67
+ }
68
+ };
69
+ /**
70
+ * Run `command` with `args`, resolving when it exits 0.
71
+ *
72
+ * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}
73
+ * once `timeoutMs` passes (after the child is gone), and with the spawn error
74
+ * itself when the program cannot be started at all — `ENOENT` already names it.
75
+ */
76
+ async function run(command, args, options = {}) {
77
+ await spawnChild(command, args, options, false);
78
+ }
79
+ /**
80
+ * {@link run}, resolving with what the program wrote to stdout — for a value
81
+ * the CLI reads back, such as the digest `docker inspect` reports. stderr still
82
+ * reaches the terminal, so a failure explains itself the same way.
83
+ */
84
+ function runOutput(command, args, options = {}) {
85
+ return spawnChild(command, args, options, true);
86
+ }
87
+ function spawnChild(command, args, options, capture) {
88
+ const { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;
89
+ return new Promise((resolve, reject) => {
90
+ const child = (0, node_child_process.spawn)(command, [...args], {
91
+ stdio: "inherit",
92
+ ...spawnOptions,
93
+ ...capture ? { stdio: [
94
+ "ignore",
95
+ "pipe",
96
+ "inherit"
97
+ ] } : {},
98
+ shell: false
99
+ });
100
+ let stdout = "";
101
+ child.stdout?.on("data", (chunk) => {
102
+ stdout += chunk.toString();
103
+ });
104
+ let timedOut = false;
105
+ let killer;
106
+ const timer = setTimeout(() => {
107
+ timedOut = true;
108
+ child.kill("SIGTERM");
109
+ killer = setTimeout(() => child.kill("SIGKILL"), KILL_GRACE_MS);
110
+ killer.unref?.();
111
+ }, timeoutMs);
112
+ timer.unref?.();
113
+ const settle = () => {
114
+ clearTimeout(timer);
115
+ if (killer) clearTimeout(killer);
116
+ };
117
+ child.on("error", (error) => {
118
+ settle();
119
+ reject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);
120
+ });
121
+ child.on("close", (code, signal) => {
122
+ settle();
123
+ if (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);
124
+ else if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));
125
+ else if (code === 0) resolve(stdout);
126
+ else reject(new CommandFailed(command, args, code, signal));
127
+ });
128
+ });
129
+ }
130
+ //#endregion
131
+ Object.defineProperty(exports, "CommandFailed", {
132
+ enumerable: true,
133
+ get: function() {
134
+ return CommandFailed;
135
+ }
136
+ });
137
+ Object.defineProperty(exports, "CommandTimedOut", {
138
+ enumerable: true,
139
+ get: function() {
140
+ return CommandTimedOut;
141
+ }
142
+ });
143
+ Object.defineProperty(exports, "DEFAULT_TIMEOUT_MS", {
144
+ enumerable: true,
145
+ get: function() {
146
+ return DEFAULT_TIMEOUT_MS;
147
+ }
148
+ });
149
+ Object.defineProperty(exports, "GKM_HOME_ENV", {
150
+ enumerable: true,
151
+ get: function() {
152
+ return GKM_HOME_ENV;
153
+ }
154
+ });
155
+ Object.defineProperty(exports, "gkmHome", {
156
+ enumerable: true,
157
+ get: function() {
158
+ return gkmHome;
159
+ }
160
+ });
161
+ Object.defineProperty(exports, "run", {
162
+ enumerable: true,
163
+ get: function() {
164
+ return run;
165
+ }
166
+ });
167
+ Object.defineProperty(exports, "runOutput", {
168
+ enumerable: true,
169
+ get: function() {
170
+ return runOutput;
171
+ }
172
+ });
173
+
174
+ //# sourceMappingURL=run-fVZ-rLnc.cjs.map