@geekmidas/cli 10.0.0-alpha.153 → 10.0.0-alpha.155

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 (163) hide show
  1. package/dist/{GoDaddyProvider-DHDuEgOS.mjs → GoDaddyProvider-CQ4YrB5P.mjs} +2 -2
  2. package/dist/{GoDaddyProvider-DHDuEgOS.mjs.map → GoDaddyProvider-CQ4YrB5P.mjs.map} +1 -1
  3. package/dist/{GoDaddyProvider-F9XB8Od5.cjs → GoDaddyProvider-H59_cXa0.cjs} +2 -2
  4. package/dist/{GoDaddyProvider-F9XB8Od5.cjs.map → GoDaddyProvider-H59_cXa0.cjs.map} +1 -1
  5. package/dist/{HostingerProvider-C0ZbaQBj.mjs → HostingerProvider-DBfHH0qT.mjs} +2 -2
  6. package/dist/{HostingerProvider-C0ZbaQBj.mjs.map → HostingerProvider-DBfHH0qT.mjs.map} +1 -1
  7. package/dist/{HostingerProvider-Cf8JZHII.cjs → HostingerProvider-DecF9ELH.cjs} +2 -2
  8. package/dist/{HostingerProvider-Cf8JZHII.cjs.map → HostingerProvider-DecF9ELH.cjs.map} +1 -1
  9. package/dist/{LegacyStateStore-CL8pSB1w.mjs → LegacyStateStore-Cz1ORtCx.mjs} +2 -2
  10. package/dist/{LegacyStateStore-CL8pSB1w.mjs.map → LegacyStateStore-Cz1ORtCx.mjs.map} +1 -1
  11. package/dist/{LegacyStateStore-CgNi3XJ_.cjs → LegacyStateStore-DwsnVS-2.cjs} +2 -2
  12. package/dist/{LegacyStateStore-CgNi3XJ_.cjs.map → LegacyStateStore-DwsnVS-2.cjs.map} +1 -1
  13. package/dist/{LocalStateStore-rtHfw0BF.cjs → LocalStateStore-BZ5b3sw4.cjs} +2 -2
  14. package/dist/{LocalStateStore-rtHfw0BF.cjs.map → LocalStateStore-BZ5b3sw4.cjs.map} +1 -1
  15. package/dist/{LocalStateStore-CY_Bry1E.mjs → LocalStateStore-dz7OkMGm.mjs} +2 -2
  16. package/dist/{LocalStateStore-CY_Bry1E.mjs.map → LocalStateStore-dz7OkMGm.mjs.map} +1 -1
  17. package/dist/{S3StateStore-CQcXWoxu.mjs → S3StateStore-Bda3aGqz.mjs} +4 -4
  18. package/dist/{S3StateStore-CQcXWoxu.mjs.map → S3StateStore-Bda3aGqz.mjs.map} +1 -1
  19. package/dist/{S3StateStore-DSL1gtik.cjs → S3StateStore-Dw9Dx_vy.cjs} +4 -4
  20. package/dist/{S3StateStore-DSL1gtik.cjs.map → S3StateStore-Dw9Dx_vy.cjs.map} +1 -1
  21. package/dist/{SSMStateStore-BqbVN9Xg.mjs → SSMStateStore-CcT6YJFd.mjs} +2 -2
  22. package/dist/{SSMStateStore-BqbVN9Xg.mjs.map → SSMStateStore-CcT6YJFd.mjs.map} +1 -1
  23. package/dist/{SSMStateStore-bzGNUN8_.cjs → SSMStateStore-DPZpYnda.cjs} +2 -2
  24. package/dist/{SSMStateStore-bzGNUN8_.cjs.map → SSMStateStore-DPZpYnda.cjs.map} +1 -1
  25. package/dist/{add-UREEeMOa.cjs → add-Bwek61Bv.cjs} +4 -4
  26. package/dist/{add-UREEeMOa.cjs.map → add-Bwek61Bv.cjs.map} +1 -1
  27. package/dist/{add-CCtY1DrL.mjs → add-Feiof1dz.mjs} +4 -4
  28. package/dist/{add-CCtY1DrL.mjs.map → add-Feiof1dz.mjs.map} +1 -1
  29. package/dist/{apps-BBo5-LK0.mjs → apps-C0kZVQpf.mjs} +98 -11
  30. package/dist/apps-C0kZVQpf.mjs.map +1 -0
  31. package/dist/{apps-CbIWhlye.cjs → apps-CrQhJueV.cjs} +109 -10
  32. package/dist/apps-CrQhJueV.cjs.map +1 -0
  33. package/dist/{bundler-Bn2HX4nE.cjs → bundler-CV-UpPpb.cjs} +6 -6
  34. package/dist/{bundler-Bn2HX4nE.cjs.map → bundler-CV-UpPpb.cjs.map} +1 -1
  35. package/dist/{bundler-CffmpkV3.mjs → bundler-o10_P4d9.mjs} +6 -6
  36. package/dist/{bundler-CffmpkV3.mjs.map → bundler-o10_P4d9.mjs.map} +1 -1
  37. package/dist/{cli-DvtRusay.cjs → cli-BO4qIuTd.cjs} +4 -4
  38. package/dist/{cli-DvtRusay.cjs.map → cli-BO4qIuTd.cjs.map} +1 -1
  39. package/dist/{cli-BLfIYaB3.mjs → cli-KFbKAyaH.mjs} +4 -4
  40. package/dist/{cli-BLfIYaB3.mjs.map → cli-KFbKAyaH.mjs.map} +1 -1
  41. package/dist/{compose-DSBTDhk5.mjs → compose-C-k9AoH0.mjs} +128 -17
  42. package/dist/compose-C-k9AoH0.mjs.map +1 -0
  43. package/dist/{compose-CGP0Nw2v.cjs → compose-CyGZOLcK.cjs} +128 -17
  44. package/dist/compose-CyGZOLcK.cjs.map +1 -0
  45. package/dist/{compose-DDJhIyfw.mjs → compose-D8fn0ebx.mjs} +4 -4
  46. package/dist/{compose-DDJhIyfw.mjs.map → compose-D8fn0ebx.mjs.map} +1 -1
  47. package/dist/{compose-Cdx-M3-g.cjs → compose-djwQcfQD.cjs} +4 -4
  48. package/dist/{compose-Cdx-M3-g.cjs.map → compose-djwQcfQD.cjs.map} +1 -1
  49. package/dist/{credentials-wid61zD2.mjs → credentials-DY_Cu5Ht.mjs} +5 -5
  50. package/dist/{credentials-wid61zD2.mjs.map → credentials-DY_Cu5Ht.mjs.map} +1 -1
  51. package/dist/{credentials-BryyjZPs.cjs → credentials-DixsjQcu.cjs} +5 -5
  52. package/dist/{credentials-BryyjZPs.cjs.map → credentials-DixsjQcu.cjs.map} +1 -1
  53. package/dist/deploy/public.cjs +10 -10
  54. package/dist/deploy/public.mjs +10 -10
  55. package/dist/{deploy-CDNFAKqC.mjs → deploy-DsWQ8kTC.mjs} +11 -11
  56. package/dist/{deploy-CDNFAKqC.mjs.map → deploy-DsWQ8kTC.mjs.map} +1 -1
  57. package/dist/{deploy-DCFfSmMK.cjs → deploy-DzYn1rNl.cjs} +11 -11
  58. package/dist/{deploy-DCFfSmMK.cjs.map → deploy-DzYn1rNl.cjs.map} +1 -1
  59. package/dist/{docker-MENEje7d.mjs → docker-CobK4rVH.mjs} +6 -5
  60. package/dist/{docker-MENEje7d.mjs.map → docker-CobK4rVH.mjs.map} +1 -1
  61. package/dist/{docker-D_cDbA9A.cjs → docker-DDHfNbM8.cjs} +6 -5
  62. package/dist/{docker-D_cDbA9A.cjs.map → docker-DDHfNbM8.cjs.map} +1 -1
  63. package/dist/{dokploy-iUWcPZvQ.mjs → dokploy-2bH8IDTX.mjs} +2 -2
  64. package/dist/{dokploy-iUWcPZvQ.mjs.map → dokploy-2bH8IDTX.mjs.map} +1 -1
  65. package/dist/{dokploy-Ds9KMB6j.cjs → dokploy-CCgBM22f.cjs} +2 -2
  66. package/dist/{dokploy-Ds9KMB6j.cjs.map → dokploy-CCgBM22f.cjs.map} +1 -1
  67. package/dist/{eas-C5jrsZeF.cjs → eas-8X90Y3ks.cjs} +2 -2
  68. package/dist/{eas-C5jrsZeF.cjs.map → eas-8X90Y3ks.cjs.map} +1 -1
  69. package/dist/{eas-Bv7SZlrg.mjs → eas-CYs_Grue.mjs} +2 -2
  70. package/dist/{eas-Bv7SZlrg.mjs.map → eas-CYs_Grue.mjs.map} +1 -1
  71. package/dist/{encryption-Bug_342m.cjs → encryption-BlvEsxDL.cjs} +2 -2
  72. package/dist/{encryption-Bug_342m.cjs.map → encryption-BlvEsxDL.cjs.map} +1 -1
  73. package/dist/{encryption-Bagl9knS.mjs → encryption-Bm9pJAlv.mjs} +2 -2
  74. package/dist/{encryption-Bagl9knS.mjs.map → encryption-Bm9pJAlv.mjs.map} +1 -1
  75. package/dist/{engine-B7Hm6yHL.cjs → engine-BL_34-M8.cjs} +8 -8
  76. package/dist/{engine-B7Hm6yHL.cjs.map → engine-BL_34-M8.cjs.map} +1 -1
  77. package/dist/{engine-CkJFeGuu.mjs → engine-CVgtgVgf.mjs} +8 -8
  78. package/dist/{engine-CkJFeGuu.mjs.map → engine-CVgtgVgf.mjs.map} +1 -1
  79. package/dist/{github--cBRadD-.cjs → github-Ci0PUjjW.cjs} +6 -6
  80. package/dist/{github--cBRadD-.cjs.map → github-Ci0PUjjW.cjs.map} +1 -1
  81. package/dist/{github-COo0o_dI.mjs → github-j9ytVxlm.mjs} +6 -6
  82. package/dist/{github-COo0o_dI.mjs.map → github-j9ytVxlm.mjs.map} +1 -1
  83. package/dist/{googlePlay-CkE6OZml.mjs → googlePlay-CvYKw65D.mjs} +4 -4
  84. package/dist/{googlePlay-CkE6OZml.mjs.map → googlePlay-CvYKw65D.mjs.map} +1 -1
  85. package/dist/{googlePlay-CmSg_6bz.cjs → googlePlay-jR8oRAzy.cjs} +4 -4
  86. package/dist/{googlePlay-CmSg_6bz.cjs.map → googlePlay-jR8oRAzy.cjs.map} +1 -1
  87. package/dist/index.cjs +59 -59
  88. package/dist/index.cjs.map +1 -1
  89. package/dist/index.mjs +59 -59
  90. package/dist/index.mjs.map +1 -1
  91. package/dist/{local-BjSgGOpF.cjs → local-5DkpRnl2.cjs} +2 -2
  92. package/dist/{local-BjSgGOpF.cjs.map → local-5DkpRnl2.cjs.map} +1 -1
  93. package/dist/{local-D4YcMzMd.mjs → local-pFyO21et.mjs} +2 -2
  94. package/dist/{local-D4YcMzMd.mjs.map → local-pFyO21et.mjs.map} +1 -1
  95. package/dist/{migrate-Bgw27ucL.mjs → migrate-C1SSvzNZ.mjs} +2 -2
  96. package/dist/{migrate-Bgw27ucL.mjs.map → migrate-C1SSvzNZ.mjs.map} +1 -1
  97. package/dist/{migrate-C8FXW2vU.cjs → migrate-CPoStsvd.cjs} +4 -4
  98. package/dist/{migrate-C8FXW2vU.cjs.map → migrate-CPoStsvd.cjs.map} +1 -1
  99. package/dist/{migrate-C6PbVtPI.cjs → migrate-DKep6Tol.cjs} +2 -2
  100. package/dist/{migrate-C6PbVtPI.cjs.map → migrate-DKep6Tol.cjs.map} +1 -1
  101. package/dist/{migrate-DaxK8mbZ.mjs → migrate-Dv8Qk0jw.mjs} +4 -4
  102. package/dist/{migrate-DaxK8mbZ.mjs.map → migrate-Dv8Qk0jw.mjs.map} +1 -1
  103. package/dist/{notes-D2fjIErC.cjs → notes-CFCdqMQ4.cjs} +2 -2
  104. package/dist/{notes-D2fjIErC.cjs.map → notes-CFCdqMQ4.cjs.map} +1 -1
  105. package/dist/{notes-B05dtIdF.mjs → notes-Dwz8jmoh.mjs} +2 -2
  106. package/dist/{notes-B05dtIdF.mjs.map → notes-Dwz8jmoh.mjs.map} +1 -1
  107. package/dist/{projectBucket-DW1QMOLF.mjs → projectBucket-Daak2eUn.mjs} +2 -2
  108. package/dist/{projectBucket-DW1QMOLF.mjs.map → projectBucket-Daak2eUn.mjs.map} +1 -1
  109. package/dist/{projectBucket-BkdKxCQ9.cjs → projectBucket-UCuebUhW.cjs} +2 -2
  110. package/dist/{projectBucket-BkdKxCQ9.cjs.map → projectBucket-UCuebUhW.cjs.map} +1 -1
  111. package/dist/{publish-De0WIoeb.cjs → publish-CBuMAY04.cjs} +2 -2
  112. package/dist/{publish-De0WIoeb.cjs.map → publish-CBuMAY04.cjs.map} +1 -1
  113. package/dist/{publish-p23AqJV9.mjs → publish-DibqEZ2a.mjs} +2 -2
  114. package/dist/{publish-p23AqJV9.mjs.map → publish-DibqEZ2a.mjs.map} +1 -1
  115. package/dist/{resolve-CLAv6ugd.mjs → resolve-BF4-f30m.mjs} +4 -4
  116. package/dist/{resolve-CLAv6ugd.mjs.map → resolve-BF4-f30m.mjs.map} +1 -1
  117. package/dist/{resolve-cgPmnYYs.cjs → resolve-BjgqLxcZ.cjs} +4 -4
  118. package/dist/{resolve-cgPmnYYs.cjs.map → resolve-BjgqLxcZ.cjs.map} +1 -1
  119. package/dist/{rollback-BSwqHG7-.cjs → rollback-BXkzAkAh.cjs} +5 -5
  120. package/dist/{rollback-BSwqHG7-.cjs.map → rollback-BXkzAkAh.cjs.map} +1 -1
  121. package/dist/{rollback-Kfu-u1Ja.mjs → rollback-DBewZGz9.mjs} +5 -5
  122. package/dist/{rollback-Kfu-u1Ja.mjs.map → rollback-DBewZGz9.mjs.map} +1 -1
  123. package/dist/{s3-B_Y8YIBy.mjs → s3-CR8gEP-7.mjs} +2 -2
  124. package/dist/{s3-B_Y8YIBy.mjs.map → s3-CR8gEP-7.mjs.map} +1 -1
  125. package/dist/{s3-SZo3_eJV.cjs → s3-Cp2eA2v_.cjs} +2 -2
  126. package/dist/{s3-SZo3_eJV.cjs.map → s3-Cp2eA2v_.cjs.map} +1 -1
  127. package/dist/{serverSetup-Cqg1RFGl.cjs → serverSetup-0eV8bl75.cjs} +5 -5
  128. package/dist/{serverSetup-Cqg1RFGl.cjs.map → serverSetup-0eV8bl75.cjs.map} +1 -1
  129. package/dist/{serverSetup-B1Vh7ZtI.mjs → serverSetup-B9BPzpUQ.mjs} +5 -5
  130. package/dist/{serverSetup-B1Vh7ZtI.mjs.map → serverSetup-B9BPzpUQ.mjs.map} +1 -1
  131. package/dist/{sniffer-DK40zMnG.cjs → sniffer-0wN20Fuy.cjs} +6 -6
  132. package/dist/{sniffer-DK40zMnG.cjs.map → sniffer-0wN20Fuy.cjs.map} +1 -1
  133. package/dist/{sniffer-CZAwpkah.mjs → sniffer-C2yPOlOW.mjs} +6 -6
  134. package/dist/{sniffer-CZAwpkah.mjs.map → sniffer-C2yPOlOW.mjs.map} +1 -1
  135. package/dist/{snsSubscriptions-Cp7doA_C.mjs → snsSubscriptions-CtOrP15M.mjs} +2 -2
  136. package/dist/{snsSubscriptions-Cp7doA_C.mjs.map → snsSubscriptions-CtOrP15M.mjs.map} +1 -1
  137. package/dist/{snsSubscriptions-D8YYmNcf.cjs → snsSubscriptions-DR3drFJK.cjs} +2 -2
  138. package/dist/{snsSubscriptions-D8YYmNcf.cjs.map → snsSubscriptions-DR3drFJK.cjs.map} +1 -1
  139. package/dist/{sst-Bf5FZC12.mjs → sst-BF85FnBg.mjs} +4 -4
  140. package/dist/{sst-Bf5FZC12.mjs.map → sst-BF85FnBg.mjs.map} +1 -1
  141. package/dist/{sst-Bj5x4qtW.cjs → sst-fbVtyw_h.cjs} +4 -4
  142. package/dist/{sst-Bj5x4qtW.cjs.map → sst-fbVtyw_h.cjs.map} +1 -1
  143. package/dist/{stack-C0V1Jm57.cjs → stack-CB0U6NiV.cjs} +38 -9
  144. package/dist/stack-CB0U6NiV.cjs.map +1 -0
  145. package/dist/{stack-DyKwnVrO.mjs → stack-ZV2le8OB.mjs} +38 -9
  146. package/dist/stack-ZV2le8OB.mjs.map +1 -0
  147. package/dist/{stage-jweO7ZpZ.cjs → stage-B6bQKczF.cjs} +5 -5
  148. package/dist/{stage-jweO7ZpZ.cjs.map → stage-B6bQKczF.cjs.map} +1 -1
  149. package/dist/{stage-4jY7016s.mjs → stage-CPtCIwru.mjs} +5 -5
  150. package/dist/{stage-4jY7016s.mjs.map → stage-CPtCIwru.mjs.map} +1 -1
  151. package/dist/target/public.cjs +1 -1
  152. package/dist/target/public.mjs +1 -1
  153. package/dist/{terminal-CKfjtEyy.cjs → terminal-CyB5bRPt.cjs} +2 -2
  154. package/dist/{terminal-CKfjtEyy.cjs.map → terminal-CyB5bRPt.cjs.map} +1 -1
  155. package/dist/{terminal-CKuv6CB4.mjs → terminal-b_4H0MHd.mjs} +2 -2
  156. package/dist/{terminal-CKuv6CB4.mjs.map → terminal-b_4H0MHd.mjs.map} +1 -1
  157. package/package.json +15 -15
  158. package/dist/apps-BBo5-LK0.mjs.map +0 -1
  159. package/dist/apps-CbIWhlye.cjs.map +0 -1
  160. package/dist/compose-CGP0Nw2v.cjs.map +0 -1
  161. package/dist/compose-DSBTDhk5.mjs.map +0 -1
  162. package/dist/stack-C0V1Jm57.cjs.map +0 -1
  163. package/dist/stack-DyKwnVrO.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- const require_credentials = require("./credentials-BryyjZPs.cjs");
1
+ const require_credentials = require("./credentials-DixsjQcu.cjs");
2
2
  let node_path = require("node:path");
3
3
  let node_fs = require("node:fs");
4
4
  let node_fs_promises = require("node:fs/promises");
@@ -97,10 +97,10 @@ async function bundleServer(options) {
97
97
  for (const ext of Object.keys(candidates)) args.push(`--external:${ext}`);
98
98
  let masterKey;
99
99
  if (stage) {
100
- const { toEmbeddableSecrets, validateEnvironmentVariables, initStageSecrets } = await Promise.resolve().then(() => require("./credentials-BryyjZPs.cjs")).then((n) => n.storage_exports);
101
- const { FileSecretsStore, secretsStoreFor } = await Promise.resolve().then(() => require("./credentials-BryyjZPs.cjs")).then((n) => n.store_exports);
100
+ const { toEmbeddableSecrets, validateEnvironmentVariables, initStageSecrets } = await Promise.resolve().then(() => require("./credentials-DixsjQcu.cjs")).then((n) => n.storage_exports);
101
+ const { FileSecretsStore, secretsStoreFor } = await Promise.resolve().then(() => require("./credentials-DixsjQcu.cjs")).then((n) => n.store_exports);
102
102
  const { ConfigNotFound, loadWorkspaceSettings } = await Promise.resolve().then(() => require("./config.cjs"));
103
- const { encryptSecrets, generateDefineOptions } = await Promise.resolve().then(() => require("./sniffer-DK40zMnG.cjs")).then((n) => n.encryption_exports);
103
+ const { encryptSecrets, generateDefineOptions } = await Promise.resolve().then(() => require("./sniffer-0wN20Fuy.cjs")).then((n) => n.encryption_exports);
104
104
  const store = await loadWorkspaceSettings().then((workspace) => secretsStoreFor(workspace, stage), (error) => {
105
105
  if (error instanceof ConfigNotFound) return new FileSecretsStore(process.cwd());
106
106
  throw error;
@@ -148,7 +148,7 @@ async function bundleServer(options) {
148
148
  const encryptedPath = (0, node_path.join)(gkmDir, "credentials.enc");
149
149
  const ivPath = (0, node_path.join)(gkmDir, "credentials.iv");
150
150
  if ((0, node_fs.existsSync)(encryptedPath) && (0, node_fs.existsSync)(ivPath)) {
151
- const { generateDefineOptions } = await Promise.resolve().then(() => require("./sniffer-DK40zMnG.cjs")).then((n) => n.encryption_exports);
151
+ const { generateDefineOptions } = await Promise.resolve().then(() => require("./sniffer-0wN20Fuy.cjs")).then((n) => n.encryption_exports);
152
152
  const defines = generateDefineOptions({
153
153
  encrypted: (0, node_fs.readFileSync)(encryptedPath, "utf-8").trim(),
154
154
  iv: (0, node_fs.readFileSync)(ivPath, "utf-8").trim(),
@@ -190,4 +190,4 @@ async function bundleServer(options) {
190
190
  //#endregion
191
191
  exports.bundleServer = bundleServer;
192
192
 
193
- //# sourceMappingURL=bundler-Bn2HX4nE.cjs.map
193
+ //# sourceMappingURL=bundler-CV-UpPpb.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundler-Bn2HX4nE.cjs","names":["dirname","existsSync","join","require","createRequire","mkdir","bundleExternals","readFileSync","spawnSync","writeFile","importedPackages","rm","externalsManifestName"],"sources":["../src/build/bundler.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { Construct } from '@geekmidas/constructs';\nimport {\n\tbundleExternals,\n\texternalsManifestName,\n\timportedPackages,\n} from './native';\n\n/**\n * Banner to inject into ESM bundle for CJS compatibility.\n * Creates a `require` function using Node's createRequire for packages\n * that internally use CommonJS require() for Node builtins.\n */\nconst ESM_CJS_COMPAT_BANNER =\n\t'import { createRequire } from \"module\"; const require = createRequire(import.meta.url);';\n\nexport interface BundleOptions {\n\t/** Entry point file (e.g., .gkm/server/server.ts) */\n\tentryPoint: string;\n\t/** Output directory for bundled files */\n\toutputDir: string;\n\t/** The bundle's file name in `outputDir`. Defaults to `server.mjs`. */\n\toutfile?: string;\n\t/** Minify the output (default: true) */\n\tminify: boolean;\n\t/** Generate sourcemaps (default: false) */\n\tsourcemap: boolean;\n\t/**\n\t * Packages to leave out of the bundle besides its native ones, which are\n\t * always left out and recorded beside it — see `externalsManifestName`.\n\t */\n\texternal: string[];\n\t/** Stage for secrets injection (optional) */\n\tstage?: string;\n\t/** Constructs to validate environment variables for */\n\tconstructs?: Construct[];\n}\n\nexport interface BundleResult {\n\t/** Path to the bundled output */\n\toutputPath: string;\n\t/** Ephemeral master key for deployment (only if stage was provided) */\n\tmasterKey?: string;\n\t/** What the bundle left out, at the version to install beside it. */\n\texternals: Record<string, string>;\n}\n\n/** The app a bundle is built for: the nearest `package.json` above its entry. */\nfunction appRootOf(entryPoint: string): string {\n\tlet dir = dirname(entryPoint);\n\twhile (!existsSync(join(dir, 'package.json'))) {\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) return dirname(entryPoint);\n\t\tdir = parent;\n\t}\n\treturn dir;\n}\n\n/**\n * The esbuild binary, resolved from this package rather than from PATH.\n *\n * It used to be `npx esbuild`, which is two assumptions: that esbuild is\n * installed somewhere npx can find, and that the *app's* directory is where to\n * look. Neither holds — the CLI did not depend on esbuild at all, so a deploy\n * run from an app that had not installed it failed at the bundle step with\n * `sh: esbuild: command not found`, after provisioning had already happened.\n *\n * The same fix `bin/gkm.mjs` makes for tsx: resolve from this package's own\n * `node_modules`, so the tool the CLI shells out to is the one it depends on.\n */\nfunction esbuildBinary(): string {\n\tconst require = createRequire(import.meta.url);\n\n\ttry {\n\t\t// The package root, then its bin — `require.resolve('esbuild')` gives the\n\t\t// JS entry point, which is a library rather than the CLI.\n\t\tconst pkg = require.resolve('esbuild/package.json');\n\t\treturn join(dirname(pkg), 'bin', 'esbuild');\n\t} catch {\n\t\t// Better a PATH lookup than a hard failure: a project that installed\n\t\t// esbuild itself still works.\n\t\treturn 'esbuild';\n\t}\n}\n\n/**\n * Collect the environment variables a build cannot proceed without.\n *\n * Uses the SnifferEnvironmentParser to detect which env vars each service\n * reads, and keeps only the ones it cannot do without. `markOptional` is what\n * separates them: the sniffer already knows which reads went through\n * `.optional()` or `.default()`, and asking for that distinction is the\n * difference between a build that stops and one that proceeds correctly.\n *\n * Without it, a key that is *absent by design* failed the build. A surface\n * publishes `AUTH_COOKIE_DOMAIN` only when there is a domain to widen a cookie\n * to — one host has nothing to share it with, so the derivation correctly\n * yields nothing, and Better Auth reads it as optional for exactly that\n * reason. Treating every sniffed read as required made the honest answer\n * indistinguishable from a missing secret.\n *\n * @param constructs - Array of constructs to analyze\n * @returns Deduplicated, sorted names of the required variables\n */\nasync function collectRequiredEnvVars(\n\tconstructs: Construct[],\n): Promise<string[]> {\n\t// A key read optionally by one construct and required by another stays\n\t// required: the strictest read is the one that fails at runtime, and taking\n\t// the union of the required reads is what says so.\n\tconst required = new Set<string>();\n\n\tfor (const construct of constructs) {\n\t\tfor (const name of await construct.getEnvironment({ markOptional: true })) {\n\t\t\tif (!name.endsWith('?')) required.add(name);\n\t\t}\n\t}\n\n\treturn Array.from(required).sort();\n}\n\n/**\n * Bundle the server application using esbuild.\n * Creates a fully standalone bundle with all dependencies included.\n *\n * @param options - Bundle configuration options\n * @returns Bundle result with output path and optional master key\n */\n\nexport async function bundleServer(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tentryPoint,\n\t\toutputDir,\n\t\tminify,\n\t\tsourcemap,\n\t\texternal,\n\t\tstage,\n\t\tconstructs,\n\t} = options;\n\n\t// Ensure output directory exists\n\tawait mkdir(outputDir, { recursive: true });\n\n\tconst outfile = options.outfile ?? 'server.mjs';\n\tconst mjsOutput = join(outputDir, outfile);\n\n\t// A package with native code loads a binary from beside its own source,\n\t// built for the platform it was installed on: inlined, it finds neither.\n\t// Every one the app could reach stays out of the bundle, and the ones the\n\t// bundle imports are installed for the image's platform at this version.\n\tconst candidates = bundleExternals(appRootOf(entryPoint), external);\n\tconst metafile = join(outputDir, `.${outfile}.meta.json`);\n\n\t// Build command-line arguments for esbuild\n\tconst args = [\n\t\tesbuildBinary(),\n\t\tentryPoint,\n\t\t'--bundle',\n\t\t'--platform=node',\n\t\t'--target=node22',\n\t\t'--format=esm',\n\t\t`--outfile=${mjsOutput}`,\n\t\t'--packages=bundle', // Bundle all dependencies for standalone output\n\t\t`--banner:js=${ESM_CJS_COMPAT_BANNER}`, // CJS compatibility for packages like pino\n\t\t`--metafile=${metafile}`,\n\t];\n\n\tif (minify) {\n\t\t// Names kept: an error's class name is what a log line's `err.type` and\n\t\t// a response's `name` say, and minified they read `_6`.\n\t\targs.push('--minify', '--keep-names');\n\t}\n\n\tif (sourcemap) {\n\t\targs.push('--sourcemap');\n\t}\n\n\tfor (const ext of Object.keys(candidates)) {\n\t\targs.push(`--external:${ext}`);\n\t}\n\n\t// Handle secrets injection if stage is provided\n\tlet masterKey: string | undefined;\n\n\tif (stage) {\n\t\tconst {\n\t\t\ttoEmbeddableSecrets,\n\t\t\tvalidateEnvironmentVariables,\n\t\t\tinitStageSecrets,\n\t\t} = await import('../secrets/storage');\n\t\tconst { FileSecretsStore, secretsStoreFor } = await import(\n\t\t\t'../secrets/store'\n\t\t);\n\t\tconst { ConfigNotFound, loadWorkspaceSettings } = await import('../config');\n\t\tconst { encryptSecrets, generateDefineOptions } = await import(\n\t\t\t'../secrets/encryption'\n\t\t);\n\n\t\t// The stage's own store — SSM or Secrets Manager for a deployed stage\n\t\t// kept there. Outside\n\t\t// any workspace nothing names one, so it is the file.\n\t\tconst store = await loadWorkspaceSettings().then(\n\t\t\t(workspace) => secretsStoreFor(workspace, stage),\n\t\t\t(error) => {\n\t\t\t\tif (error instanceof ConfigNotFound) {\n\t\t\t\t\treturn new FileSecretsStore(process.cwd());\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tlet secrets = await store.read(stage);\n\n\t\tif (!secrets) {\n\t\t\t// Auto-initialize secrets for the stage\n\t\t\tconsole.log(` Initializing secrets for stage \"${stage}\"...`);\n\t\t\tsecrets = initStageSecrets(stage);\n\t\t\tawait store.write(stage, secrets);\n\t\t\tconsole.log(` ✓ Created the \"${stage}\" secrets (${store.name})`);\n\t\t}\n\n\t\t// Validate environment variables if constructs are provided\n\t\tif (constructs && constructs.length > 0) {\n\t\t\tconsole.log(' Analyzing environment variable requirements...');\n\t\t\tconst requiredVars = await collectRequiredEnvVars(constructs);\n\n\t\t\tif (requiredVars.length > 0) {\n\t\t\t\tconst validation = validateEnvironmentVariables(requiredVars, secrets);\n\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst errorMessage = [\n\t\t\t\t\t\t`Missing environment variables for stage \"${stage}\":`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t...validation.missing.map((v) => ` ❌ ${v}`),\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'To fix this, either:',\n\t\t\t\t\t\t` 1. Add the missing variables to the \"${stage}\" secrets using:`,\n\t\t\t\t\t\t` gkm secrets:set <KEY> <VALUE> --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t` 2. Or import from a JSON file:`,\n\t\t\t\t\t\t` gkm secrets:import secrets.json --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'Required variables:',\n\t\t\t\t\t\t...validation.required.map((v) =>\n\t\t\t\t\t\t\tvalidation.missing.includes(v) ? ` ❌ ${v}` : ` ✓ ${v}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t].join('\\n');\n\n\t\t\t\t\tthrow new Error(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t` ✓ All ${requiredVars.length} required environment variables found`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Convert to embeddable format and encrypt\n\t\tconst embeddable = toEmbeddableSecrets(secrets);\n\t\tconst encrypted = encryptSecrets(embeddable);\n\t\tmasterKey = encrypted.masterKey;\n\n\t\t// Add define options for build-time injection using esbuild's --define:KEY=VALUE format\n\t\tconst defines = generateDefineOptions(encrypted);\n\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t// `value` is already a JS string literal; quoting it again would\n\t\t\t// embed the quotes, and the IV would not parse as hex.\n\t\t\targs.push(`--define:${key}=${value}`);\n\t\t}\n\n\t\tconsole.log(` Secrets encrypted for stage \"${stage}\"`);\n\t} else {\n\t\t// Credentials encrypted elsewhere — an image build hands them in as a\n\t\t// BuildKit secret and writes them beside the app's `.gkm/server` — are\n\t\t// embedded as they are; whoever encrypted them holds the key.\n\t\tconst gkmDir = join(outputDir, '..', '..');\n\t\tconst encryptedPath = join(gkmDir, 'credentials.enc');\n\t\tconst ivPath = join(gkmDir, 'credentials.iv');\n\t\tif (existsSync(encryptedPath) && existsSync(ivPath)) {\n\t\t\tconst { generateDefineOptions } = await import('../secrets/encryption');\n\t\t\tconst defines = generateDefineOptions({\n\t\t\t\tencrypted: readFileSync(encryptedPath, 'utf-8').trim(),\n\t\t\t\tiv: readFileSync(ivPath, 'utf-8').trim(),\n\t\t\t\tmasterKey: '',\n\t\t\t});\n\t\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t\targs.push(`--define:${key}=${value}`);\n\t\t\t}\n\t\t\tconsole.log(' Embedded the encrypted credentials the build was given');\n\t\t}\n\t}\n\n\ttry {\n\t\t// Run esbuild with command-line arguments\n\t\tconst [cmd, ...cmdArgs] = args as [string, ...string[]];\n\t\tconst result = spawnSync(cmd, cmdArgs, {\n\t\t\tcwd: process.cwd(),\n\t\t\tstdio: 'inherit',\n\t\t\tshell: process.platform === 'win32', // Only use shell on Windows for npx resolution\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tthrow result.error;\n\t\t}\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(`esbuild exited with code ${result.status}`);\n\t\t}\n\n\t\t// Add shebang to the bundled file\n\t\tconst { readFile } = await import('node:fs/promises');\n\t\tconst content = await readFile(mjsOutput, 'utf-8');\n\t\tif (!content.startsWith('#!')) {\n\t\t\tawait writeFile(mjsOutput, `#!/usr/bin/env node\\n${content}`);\n\t\t}\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to bundle server: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t);\n\t}\n\n\t// Declared ones always; a native package only where the bundle imports it\n\t// — an app that depends on `@geekmidas/cli` reaches esbuild, and never\n\t// runs it.\n\tconst imported = importedPackages(metafile);\n\tawait rm(metafile, { force: true });\n\tconst externals = Object.fromEntries(\n\t\tObject.entries(candidates).filter(\n\t\t\t([name]) => external.includes(name) || imported.has(name),\n\t\t),\n\t);\n\tawait writeFile(\n\t\tjoin(outputDir, externalsManifestName(outfile)),\n\t\t`${JSON.stringify({ private: true, dependencies: externals }, null, 2)}\\n`,\n\t);\n\tif (Object.keys(externals).length > 0) {\n\t\tconsole.log(\n\t\t\t` Left out of the bundle, installed beside it: ${Object.keys(externals).join(', ')}`,\n\t\t);\n\t}\n\n\treturn {\n\t\toutputPath: mjsOutput,\n\t\tmasterKey,\n\t\texternals,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,wBACL;;AAkCD,SAAS,UAAU,YAA4B;CAC9C,IAAI,OAAA,GAAMA,UAAAA,QAAAA,CAAQ,UAAU;CAC5B,OAAO,EAAA,GAACC,QAAAA,WAAAA,EAAAA,GAAWC,UAAAA,KAAAA,CAAK,KAAK,cAAc,CAAC,GAAG;EAC9C,MAAM,UAAA,GAASF,UAAAA,QAAAA,CAAQ,GAAG;EAC1B,IAAI,WAAW,KAAK,QAAA,GAAOA,UAAAA,QAAAA,CAAQ,UAAU;EAC7C,MAAM;CACP;CACA,OAAO;AACR;;;;;;;;;;;;;AAcA,SAAS,gBAAwB;CAChC,MAAMG,aAAAA,GAAUC,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;CAE7C,IAAI;EAGH,MAAM,MAAMD,UAAQ,QAAQ,sBAAsB;EAClD,QAAA,GAAOD,UAAAA,KAAAA,EAAAA,GAAKF,UAAAA,QAAAA,CAAQ,GAAG,GAAG,OAAO,SAAS;CAC3C,QAAQ;EAGP,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;;AAqBA,eAAe,uBACd,YACoB;CAIpB,MAAM,2BAAW,IAAI,IAAY;CAEjC,KAAK,MAAM,aAAa,YACvB,KAAK,MAAM,QAAQ,MAAM,UAAU,eAAe,EAAE,cAAc,KAAK,CAAC,GACvE,IAAI,CAAC,KAAK,SAAS,GAAG,GAAG,SAAS,IAAI,IAAI;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AM,UAAU,iBACtE;CACD;CAKA,MAAM,WAAWC,oBAAAA,iBAAiB,QAAQ;CAC1C,OAAA,GAAMC,iBAAAA,GAAAA,CAAG,UAAU,EAAE,OAAO,KAAK,CAAC;CAClC,MAAM,YAAY,OAAO,YACxB,OAAO,QAAQ,UAAU,CAAC,CAAC,QACzB,CAAC,UAAU,SAAS,SAAS,IAAI,KAAK,SAAS,IAAI,IAAI,CACzD,CACD;CACA,OAAA,GAAMF,iBAAAA,UAAAA,EAAAA,GACLP,UAAAA,KAAAA,CAAK,WAAWU,oBAAAA,sBAAsB,OAAO,CAAC,GAC9C,GAAG,KAAK,UAAU;EAAE,SAAS;EAAM,cAAc;CAAU,GAAG,MAAM,CAAC,EAAE,GACxE;CACA,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS,GACnC,QAAQ,IACP,kDAAkD,OAAO,KAAK,SAAS,CAAC,CAAC,KAAK,IAAI,GACnF;CAGD,OAAO;EACN,YAAY;EACZ;EACA;CACD;AACD"}
1
+ {"version":3,"file":"bundler-CV-UpPpb.cjs","names":["dirname","existsSync","join","require","createRequire","mkdir","bundleExternals","readFileSync","spawnSync","writeFile","importedPackages","rm","externalsManifestName"],"sources":["../src/build/bundler.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { Construct } from '@geekmidas/constructs';\nimport {\n\tbundleExternals,\n\texternalsManifestName,\n\timportedPackages,\n} from './native';\n\n/**\n * Banner to inject into ESM bundle for CJS compatibility.\n * Creates a `require` function using Node's createRequire for packages\n * that internally use CommonJS require() for Node builtins.\n */\nconst ESM_CJS_COMPAT_BANNER =\n\t'import { createRequire } from \"module\"; const require = createRequire(import.meta.url);';\n\nexport interface BundleOptions {\n\t/** Entry point file (e.g., .gkm/server/server.ts) */\n\tentryPoint: string;\n\t/** Output directory for bundled files */\n\toutputDir: string;\n\t/** The bundle's file name in `outputDir`. Defaults to `server.mjs`. */\n\toutfile?: string;\n\t/** Minify the output (default: true) */\n\tminify: boolean;\n\t/** Generate sourcemaps (default: false) */\n\tsourcemap: boolean;\n\t/**\n\t * Packages to leave out of the bundle besides its native ones, which are\n\t * always left out and recorded beside it — see `externalsManifestName`.\n\t */\n\texternal: string[];\n\t/** Stage for secrets injection (optional) */\n\tstage?: string;\n\t/** Constructs to validate environment variables for */\n\tconstructs?: Construct[];\n}\n\nexport interface BundleResult {\n\t/** Path to the bundled output */\n\toutputPath: string;\n\t/** Ephemeral master key for deployment (only if stage was provided) */\n\tmasterKey?: string;\n\t/** What the bundle left out, at the version to install beside it. */\n\texternals: Record<string, string>;\n}\n\n/** The app a bundle is built for: the nearest `package.json` above its entry. */\nfunction appRootOf(entryPoint: string): string {\n\tlet dir = dirname(entryPoint);\n\twhile (!existsSync(join(dir, 'package.json'))) {\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) return dirname(entryPoint);\n\t\tdir = parent;\n\t}\n\treturn dir;\n}\n\n/**\n * The esbuild binary, resolved from this package rather than from PATH.\n *\n * It used to be `npx esbuild`, which is two assumptions: that esbuild is\n * installed somewhere npx can find, and that the *app's* directory is where to\n * look. Neither holds — the CLI did not depend on esbuild at all, so a deploy\n * run from an app that had not installed it failed at the bundle step with\n * `sh: esbuild: command not found`, after provisioning had already happened.\n *\n * The same fix `bin/gkm.mjs` makes for tsx: resolve from this package's own\n * `node_modules`, so the tool the CLI shells out to is the one it depends on.\n */\nfunction esbuildBinary(): string {\n\tconst require = createRequire(import.meta.url);\n\n\ttry {\n\t\t// The package root, then its bin — `require.resolve('esbuild')` gives the\n\t\t// JS entry point, which is a library rather than the CLI.\n\t\tconst pkg = require.resolve('esbuild/package.json');\n\t\treturn join(dirname(pkg), 'bin', 'esbuild');\n\t} catch {\n\t\t// Better a PATH lookup than a hard failure: a project that installed\n\t\t// esbuild itself still works.\n\t\treturn 'esbuild';\n\t}\n}\n\n/**\n * Collect the environment variables a build cannot proceed without.\n *\n * Uses the SnifferEnvironmentParser to detect which env vars each service\n * reads, and keeps only the ones it cannot do without. `markOptional` is what\n * separates them: the sniffer already knows which reads went through\n * `.optional()` or `.default()`, and asking for that distinction is the\n * difference between a build that stops and one that proceeds correctly.\n *\n * Without it, a key that is *absent by design* failed the build. A surface\n * publishes `AUTH_COOKIE_DOMAIN` only when there is a domain to widen a cookie\n * to — one host has nothing to share it with, so the derivation correctly\n * yields nothing, and Better Auth reads it as optional for exactly that\n * reason. Treating every sniffed read as required made the honest answer\n * indistinguishable from a missing secret.\n *\n * @param constructs - Array of constructs to analyze\n * @returns Deduplicated, sorted names of the required variables\n */\nasync function collectRequiredEnvVars(\n\tconstructs: Construct[],\n): Promise<string[]> {\n\t// A key read optionally by one construct and required by another stays\n\t// required: the strictest read is the one that fails at runtime, and taking\n\t// the union of the required reads is what says so.\n\tconst required = new Set<string>();\n\n\tfor (const construct of constructs) {\n\t\tfor (const name of await construct.getEnvironment({ markOptional: true })) {\n\t\t\tif (!name.endsWith('?')) required.add(name);\n\t\t}\n\t}\n\n\treturn Array.from(required).sort();\n}\n\n/**\n * Bundle the server application using esbuild.\n * Creates a fully standalone bundle with all dependencies included.\n *\n * @param options - Bundle configuration options\n * @returns Bundle result with output path and optional master key\n */\n\nexport async function bundleServer(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tentryPoint,\n\t\toutputDir,\n\t\tminify,\n\t\tsourcemap,\n\t\texternal,\n\t\tstage,\n\t\tconstructs,\n\t} = options;\n\n\t// Ensure output directory exists\n\tawait mkdir(outputDir, { recursive: true });\n\n\tconst outfile = options.outfile ?? 'server.mjs';\n\tconst mjsOutput = join(outputDir, outfile);\n\n\t// A package with native code loads a binary from beside its own source,\n\t// built for the platform it was installed on: inlined, it finds neither.\n\t// Every one the app could reach stays out of the bundle, and the ones the\n\t// bundle imports are installed for the image's platform at this version.\n\tconst candidates = bundleExternals(appRootOf(entryPoint), external);\n\tconst metafile = join(outputDir, `.${outfile}.meta.json`);\n\n\t// Build command-line arguments for esbuild\n\tconst args = [\n\t\tesbuildBinary(),\n\t\tentryPoint,\n\t\t'--bundle',\n\t\t'--platform=node',\n\t\t'--target=node22',\n\t\t'--format=esm',\n\t\t`--outfile=${mjsOutput}`,\n\t\t'--packages=bundle', // Bundle all dependencies for standalone output\n\t\t`--banner:js=${ESM_CJS_COMPAT_BANNER}`, // CJS compatibility for packages like pino\n\t\t`--metafile=${metafile}`,\n\t];\n\n\tif (minify) {\n\t\t// Names kept: an error's class name is what a log line's `err.type` and\n\t\t// a response's `name` say, and minified they read `_6`.\n\t\targs.push('--minify', '--keep-names');\n\t}\n\n\tif (sourcemap) {\n\t\targs.push('--sourcemap');\n\t}\n\n\tfor (const ext of Object.keys(candidates)) {\n\t\targs.push(`--external:${ext}`);\n\t}\n\n\t// Handle secrets injection if stage is provided\n\tlet masterKey: string | undefined;\n\n\tif (stage) {\n\t\tconst {\n\t\t\ttoEmbeddableSecrets,\n\t\t\tvalidateEnvironmentVariables,\n\t\t\tinitStageSecrets,\n\t\t} = await import('../secrets/storage');\n\t\tconst { FileSecretsStore, secretsStoreFor } = await import(\n\t\t\t'../secrets/store'\n\t\t);\n\t\tconst { ConfigNotFound, loadWorkspaceSettings } = await import('../config');\n\t\tconst { encryptSecrets, generateDefineOptions } = await import(\n\t\t\t'../secrets/encryption'\n\t\t);\n\n\t\t// The stage's own store — SSM or Secrets Manager for a deployed stage\n\t\t// kept there. Outside\n\t\t// any workspace nothing names one, so it is the file.\n\t\tconst store = await loadWorkspaceSettings().then(\n\t\t\t(workspace) => secretsStoreFor(workspace, stage),\n\t\t\t(error) => {\n\t\t\t\tif (error instanceof ConfigNotFound) {\n\t\t\t\t\treturn new FileSecretsStore(process.cwd());\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tlet secrets = await store.read(stage);\n\n\t\tif (!secrets) {\n\t\t\t// Auto-initialize secrets for the stage\n\t\t\tconsole.log(` Initializing secrets for stage \"${stage}\"...`);\n\t\t\tsecrets = initStageSecrets(stage);\n\t\t\tawait store.write(stage, secrets);\n\t\t\tconsole.log(` ✓ Created the \"${stage}\" secrets (${store.name})`);\n\t\t}\n\n\t\t// Validate environment variables if constructs are provided\n\t\tif (constructs && constructs.length > 0) {\n\t\t\tconsole.log(' Analyzing environment variable requirements...');\n\t\t\tconst requiredVars = await collectRequiredEnvVars(constructs);\n\n\t\t\tif (requiredVars.length > 0) {\n\t\t\t\tconst validation = validateEnvironmentVariables(requiredVars, secrets);\n\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst errorMessage = [\n\t\t\t\t\t\t`Missing environment variables for stage \"${stage}\":`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t...validation.missing.map((v) => ` ❌ ${v}`),\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'To fix this, either:',\n\t\t\t\t\t\t` 1. Add the missing variables to the \"${stage}\" secrets using:`,\n\t\t\t\t\t\t` gkm secrets:set <KEY> <VALUE> --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t` 2. Or import from a JSON file:`,\n\t\t\t\t\t\t` gkm secrets:import secrets.json --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'Required variables:',\n\t\t\t\t\t\t...validation.required.map((v) =>\n\t\t\t\t\t\t\tvalidation.missing.includes(v) ? ` ❌ ${v}` : ` ✓ ${v}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t].join('\\n');\n\n\t\t\t\t\tthrow new Error(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t` ✓ All ${requiredVars.length} required environment variables found`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Convert to embeddable format and encrypt\n\t\tconst embeddable = toEmbeddableSecrets(secrets);\n\t\tconst encrypted = encryptSecrets(embeddable);\n\t\tmasterKey = encrypted.masterKey;\n\n\t\t// Add define options for build-time injection using esbuild's --define:KEY=VALUE format\n\t\tconst defines = generateDefineOptions(encrypted);\n\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t// `value` is already a JS string literal; quoting it again would\n\t\t\t// embed the quotes, and the IV would not parse as hex.\n\t\t\targs.push(`--define:${key}=${value}`);\n\t\t}\n\n\t\tconsole.log(` Secrets encrypted for stage \"${stage}\"`);\n\t} else {\n\t\t// Credentials encrypted elsewhere — an image build hands them in as a\n\t\t// BuildKit secret and writes them beside the app's `.gkm/server` — are\n\t\t// embedded as they are; whoever encrypted them holds the key.\n\t\tconst gkmDir = join(outputDir, '..', '..');\n\t\tconst encryptedPath = join(gkmDir, 'credentials.enc');\n\t\tconst ivPath = join(gkmDir, 'credentials.iv');\n\t\tif (existsSync(encryptedPath) && existsSync(ivPath)) {\n\t\t\tconst { generateDefineOptions } = await import('../secrets/encryption');\n\t\t\tconst defines = generateDefineOptions({\n\t\t\t\tencrypted: readFileSync(encryptedPath, 'utf-8').trim(),\n\t\t\t\tiv: readFileSync(ivPath, 'utf-8').trim(),\n\t\t\t\tmasterKey: '',\n\t\t\t});\n\t\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t\targs.push(`--define:${key}=${value}`);\n\t\t\t}\n\t\t\tconsole.log(' Embedded the encrypted credentials the build was given');\n\t\t}\n\t}\n\n\ttry {\n\t\t// Run esbuild with command-line arguments\n\t\tconst [cmd, ...cmdArgs] = args as [string, ...string[]];\n\t\tconst result = spawnSync(cmd, cmdArgs, {\n\t\t\tcwd: process.cwd(),\n\t\t\tstdio: 'inherit',\n\t\t\tshell: process.platform === 'win32', // Only use shell on Windows for npx resolution\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tthrow result.error;\n\t\t}\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(`esbuild exited with code ${result.status}`);\n\t\t}\n\n\t\t// Add shebang to the bundled file\n\t\tconst { readFile } = await import('node:fs/promises');\n\t\tconst content = await readFile(mjsOutput, 'utf-8');\n\t\tif (!content.startsWith('#!')) {\n\t\t\tawait writeFile(mjsOutput, `#!/usr/bin/env node\\n${content}`);\n\t\t}\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to bundle server: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t);\n\t}\n\n\t// Declared ones always; a native package only where the bundle imports it\n\t// — an app that depends on `@geekmidas/cli` reaches esbuild, and never\n\t// runs it.\n\tconst imported = importedPackages(metafile);\n\tawait rm(metafile, { force: true });\n\tconst externals = Object.fromEntries(\n\t\tObject.entries(candidates).filter(\n\t\t\t([name]) => external.includes(name) || imported.has(name),\n\t\t),\n\t);\n\tawait writeFile(\n\t\tjoin(outputDir, externalsManifestName(outfile)),\n\t\t`${JSON.stringify({ private: true, dependencies: externals }, null, 2)}\\n`,\n\t);\n\tif (Object.keys(externals).length > 0) {\n\t\tconsole.log(\n\t\t\t` Left out of the bundle, installed beside it: ${Object.keys(externals).join(', ')}`,\n\t\t);\n\t}\n\n\treturn {\n\t\toutputPath: mjsOutput,\n\t\tmasterKey,\n\t\texternals,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,wBACL;;AAkCD,SAAS,UAAU,YAA4B;CAC9C,IAAI,OAAA,GAAMA,UAAAA,QAAAA,CAAQ,UAAU;CAC5B,OAAO,EAAA,GAACC,QAAAA,WAAAA,EAAAA,GAAWC,UAAAA,KAAAA,CAAK,KAAK,cAAc,CAAC,GAAG;EAC9C,MAAM,UAAA,GAASF,UAAAA,QAAAA,CAAQ,GAAG;EAC1B,IAAI,WAAW,KAAK,QAAA,GAAOA,UAAAA,QAAAA,CAAQ,UAAU;EAC7C,MAAM;CACP;CACA,OAAO;AACR;;;;;;;;;;;;;AAcA,SAAS,gBAAwB;CAChC,MAAMG,aAAAA,GAAUC,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;CAE7C,IAAI;EAGH,MAA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B,OAAO;GACP,OAAO,QAAQ,aAAa;EAC7B,CAAC;EAED,IAAI,OAAO,OACV,MAAM,OAAO;EAEd,IAAI,OAAO,WAAW,GACrB,MAAM,IAAI,MAAM,4BAA4B,OAAO,QAAQ;EAI5D,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,UAAU,MAAM,SAAS,WAAW,OAAO;EACjD,IAAI,CAAC,QAAQ,WAAW,IAAI,GAC3B,OAAA,GAAMC,iBAAAA,UAAAA,CAAU,WAAW,wBAAwB,SAAS;CAE9D,SAAS,OAAO;EACf,MAAM,IAAI,MACT,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,iBACtE;CACD;CAKA,MAAM,WAAWC,oBAAAA,iBAAiB,QAAQ;CAC1C,OAAA,GAAMC,iBAAAA,GAAAA,CAAG,UAAU,EAAE,OAAO,KAAK,CAAC;CAClC,MAAM,YAAY,OAAO,YACxB,OAAO,QAAQ,UAAU,CAAC,CAAC,QACzB,CAAC,UAAU,SAAS,SAAS,IAAI,KAAK,SAAS,IAAI,IAAI,CACzD,CACD;CACA,OAAA,GAAMF,iBAAAA,UAAAA,EAAAA,GACLP,UAAAA,KAAAA,CAAK,WAAWU,oBAAAA,sBAAsB,OAAO,CAAC,GAC9C,GAAG,KAAK,UAAU;EAAE,SAAS;EAAM,cAAc;CAAU,GAAG,MAAM,CAAC,EAAE,GACxE;CACA,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS,GACnC,QAAQ,IACP,kDAAkD,OAAO,KAAK,SAAS,CAAC,CAAC,KAAK,IAAI,GACnF;CAGD,OAAO;EACN,YAAY;EACZ;EACA;CACD;AACD"}
@@ -1,4 +1,4 @@
1
- import { L as bundleExternals, R as externalsManifestName, z as importedPackages } from "./credentials-wid61zD2.mjs";
1
+ import { L as bundleExternals, R as externalsManifestName, z as importedPackages } from "./credentials-DY_Cu5Ht.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { dirname, join } from "node:path";
4
4
  import { existsSync, readFileSync } from "node:fs";
@@ -97,10 +97,10 @@ async function bundleServer(options) {
97
97
  for (const ext of Object.keys(candidates)) args.push(`--external:${ext}`);
98
98
  let masterKey;
99
99
  if (stage) {
100
- const { toEmbeddableSecrets, validateEnvironmentVariables, initStageSecrets } = await import("./credentials-wid61zD2.mjs").then((n) => n.P);
101
- const { FileSecretsStore, secretsStoreFor } = await import("./credentials-wid61zD2.mjs").then((n) => n.j);
100
+ const { toEmbeddableSecrets, validateEnvironmentVariables, initStageSecrets } = await import("./credentials-DY_Cu5Ht.mjs").then((n) => n.P);
101
+ const { FileSecretsStore, secretsStoreFor } = await import("./credentials-DY_Cu5Ht.mjs").then((n) => n.j);
102
102
  const { ConfigNotFound, loadWorkspaceSettings } = await import("./config.mjs");
103
- const { encryptSecrets, generateDefineOptions } = await import("./sniffer-CZAwpkah.mjs").then((n) => n.O);
103
+ const { encryptSecrets, generateDefineOptions } = await import("./sniffer-C2yPOlOW.mjs").then((n) => n.O);
104
104
  const store = await loadWorkspaceSettings().then((workspace) => secretsStoreFor(workspace, stage), (error) => {
105
105
  if (error instanceof ConfigNotFound) return new FileSecretsStore(process.cwd());
106
106
  throw error;
@@ -148,7 +148,7 @@ async function bundleServer(options) {
148
148
  const encryptedPath = join(gkmDir, "credentials.enc");
149
149
  const ivPath = join(gkmDir, "credentials.iv");
150
150
  if (existsSync(encryptedPath) && existsSync(ivPath)) {
151
- const { generateDefineOptions } = await import("./sniffer-CZAwpkah.mjs").then((n) => n.O);
151
+ const { generateDefineOptions } = await import("./sniffer-C2yPOlOW.mjs").then((n) => n.O);
152
152
  const defines = generateDefineOptions({
153
153
  encrypted: readFileSync(encryptedPath, "utf-8").trim(),
154
154
  iv: readFileSync(ivPath, "utf-8").trim(),
@@ -190,4 +190,4 @@ async function bundleServer(options) {
190
190
  //#endregion
191
191
  export { bundleServer };
192
192
 
193
- //# sourceMappingURL=bundler-CffmpkV3.mjs.map
193
+ //# sourceMappingURL=bundler-o10_P4d9.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundler-CffmpkV3.mjs","names":[],"sources":["../src/build/bundler.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { Construct } from '@geekmidas/constructs';\nimport {\n\tbundleExternals,\n\texternalsManifestName,\n\timportedPackages,\n} from './native';\n\n/**\n * Banner to inject into ESM bundle for CJS compatibility.\n * Creates a `require` function using Node's createRequire for packages\n * that internally use CommonJS require() for Node builtins.\n */\nconst ESM_CJS_COMPAT_BANNER =\n\t'import { createRequire } from \"module\"; const require = createRequire(import.meta.url);';\n\nexport interface BundleOptions {\n\t/** Entry point file (e.g., .gkm/server/server.ts) */\n\tentryPoint: string;\n\t/** Output directory for bundled files */\n\toutputDir: string;\n\t/** The bundle's file name in `outputDir`. Defaults to `server.mjs`. */\n\toutfile?: string;\n\t/** Minify the output (default: true) */\n\tminify: boolean;\n\t/** Generate sourcemaps (default: false) */\n\tsourcemap: boolean;\n\t/**\n\t * Packages to leave out of the bundle besides its native ones, which are\n\t * always left out and recorded beside it — see `externalsManifestName`.\n\t */\n\texternal: string[];\n\t/** Stage for secrets injection (optional) */\n\tstage?: string;\n\t/** Constructs to validate environment variables for */\n\tconstructs?: Construct[];\n}\n\nexport interface BundleResult {\n\t/** Path to the bundled output */\n\toutputPath: string;\n\t/** Ephemeral master key for deployment (only if stage was provided) */\n\tmasterKey?: string;\n\t/** What the bundle left out, at the version to install beside it. */\n\texternals: Record<string, string>;\n}\n\n/** The app a bundle is built for: the nearest `package.json` above its entry. */\nfunction appRootOf(entryPoint: string): string {\n\tlet dir = dirname(entryPoint);\n\twhile (!existsSync(join(dir, 'package.json'))) {\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) return dirname(entryPoint);\n\t\tdir = parent;\n\t}\n\treturn dir;\n}\n\n/**\n * The esbuild binary, resolved from this package rather than from PATH.\n *\n * It used to be `npx esbuild`, which is two assumptions: that esbuild is\n * installed somewhere npx can find, and that the *app's* directory is where to\n * look. Neither holds — the CLI did not depend on esbuild at all, so a deploy\n * run from an app that had not installed it failed at the bundle step with\n * `sh: esbuild: command not found`, after provisioning had already happened.\n *\n * The same fix `bin/gkm.mjs` makes for tsx: resolve from this package's own\n * `node_modules`, so the tool the CLI shells out to is the one it depends on.\n */\nfunction esbuildBinary(): string {\n\tconst require = createRequire(import.meta.url);\n\n\ttry {\n\t\t// The package root, then its bin — `require.resolve('esbuild')` gives the\n\t\t// JS entry point, which is a library rather than the CLI.\n\t\tconst pkg = require.resolve('esbuild/package.json');\n\t\treturn join(dirname(pkg), 'bin', 'esbuild');\n\t} catch {\n\t\t// Better a PATH lookup than a hard failure: a project that installed\n\t\t// esbuild itself still works.\n\t\treturn 'esbuild';\n\t}\n}\n\n/**\n * Collect the environment variables a build cannot proceed without.\n *\n * Uses the SnifferEnvironmentParser to detect which env vars each service\n * reads, and keeps only the ones it cannot do without. `markOptional` is what\n * separates them: the sniffer already knows which reads went through\n * `.optional()` or `.default()`, and asking for that distinction is the\n * difference between a build that stops and one that proceeds correctly.\n *\n * Without it, a key that is *absent by design* failed the build. A surface\n * publishes `AUTH_COOKIE_DOMAIN` only when there is a domain to widen a cookie\n * to — one host has nothing to share it with, so the derivation correctly\n * yields nothing, and Better Auth reads it as optional for exactly that\n * reason. Treating every sniffed read as required made the honest answer\n * indistinguishable from a missing secret.\n *\n * @param constructs - Array of constructs to analyze\n * @returns Deduplicated, sorted names of the required variables\n */\nasync function collectRequiredEnvVars(\n\tconstructs: Construct[],\n): Promise<string[]> {\n\t// A key read optionally by one construct and required by another stays\n\t// required: the strictest read is the one that fails at runtime, and taking\n\t// the union of the required reads is what says so.\n\tconst required = new Set<string>();\n\n\tfor (const construct of constructs) {\n\t\tfor (const name of await construct.getEnvironment({ markOptional: true })) {\n\t\t\tif (!name.endsWith('?')) required.add(name);\n\t\t}\n\t}\n\n\treturn Array.from(required).sort();\n}\n\n/**\n * Bundle the server application using esbuild.\n * Creates a fully standalone bundle with all dependencies included.\n *\n * @param options - Bundle configuration options\n * @returns Bundle result with output path and optional master key\n */\n\nexport async function bundleServer(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tentryPoint,\n\t\toutputDir,\n\t\tminify,\n\t\tsourcemap,\n\t\texternal,\n\t\tstage,\n\t\tconstructs,\n\t} = options;\n\n\t// Ensure output directory exists\n\tawait mkdir(outputDir, { recursive: true });\n\n\tconst outfile = options.outfile ?? 'server.mjs';\n\tconst mjsOutput = join(outputDir, outfile);\n\n\t// A package with native code loads a binary from beside its own source,\n\t// built for the platform it was installed on: inlined, it finds neither.\n\t// Every one the app could reach stays out of the bundle, and the ones the\n\t// bundle imports are installed for the image's platform at this version.\n\tconst candidates = bundleExternals(appRootOf(entryPoint), external);\n\tconst metafile = join(outputDir, `.${outfile}.meta.json`);\n\n\t// Build command-line arguments for esbuild\n\tconst args = [\n\t\tesbuildBinary(),\n\t\tentryPoint,\n\t\t'--bundle',\n\t\t'--platform=node',\n\t\t'--target=node22',\n\t\t'--format=esm',\n\t\t`--outfile=${mjsOutput}`,\n\t\t'--packages=bundle', // Bundle all dependencies for standalone output\n\t\t`--banner:js=${ESM_CJS_COMPAT_BANNER}`, // CJS compatibility for packages like pino\n\t\t`--metafile=${metafile}`,\n\t];\n\n\tif (minify) {\n\t\t// Names kept: an error's class name is what a log line's `err.type` and\n\t\t// a response's `name` say, and minified they read `_6`.\n\t\targs.push('--minify', '--keep-names');\n\t}\n\n\tif (sourcemap) {\n\t\targs.push('--sourcemap');\n\t}\n\n\tfor (const ext of Object.keys(candidates)) {\n\t\targs.push(`--external:${ext}`);\n\t}\n\n\t// Handle secrets injection if stage is provided\n\tlet masterKey: string | undefined;\n\n\tif (stage) {\n\t\tconst {\n\t\t\ttoEmbeddableSecrets,\n\t\t\tvalidateEnvironmentVariables,\n\t\t\tinitStageSecrets,\n\t\t} = await import('../secrets/storage');\n\t\tconst { FileSecretsStore, secretsStoreFor } = await import(\n\t\t\t'../secrets/store'\n\t\t);\n\t\tconst { ConfigNotFound, loadWorkspaceSettings } = await import('../config');\n\t\tconst { encryptSecrets, generateDefineOptions } = await import(\n\t\t\t'../secrets/encryption'\n\t\t);\n\n\t\t// The stage's own store — SSM or Secrets Manager for a deployed stage\n\t\t// kept there. Outside\n\t\t// any workspace nothing names one, so it is the file.\n\t\tconst store = await loadWorkspaceSettings().then(\n\t\t\t(workspace) => secretsStoreFor(workspace, stage),\n\t\t\t(error) => {\n\t\t\t\tif (error instanceof ConfigNotFound) {\n\t\t\t\t\treturn new FileSecretsStore(process.cwd());\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tlet secrets = await store.read(stage);\n\n\t\tif (!secrets) {\n\t\t\t// Auto-initialize secrets for the stage\n\t\t\tconsole.log(` Initializing secrets for stage \"${stage}\"...`);\n\t\t\tsecrets = initStageSecrets(stage);\n\t\t\tawait store.write(stage, secrets);\n\t\t\tconsole.log(` ✓ Created the \"${stage}\" secrets (${store.name})`);\n\t\t}\n\n\t\t// Validate environment variables if constructs are provided\n\t\tif (constructs && constructs.length > 0) {\n\t\t\tconsole.log(' Analyzing environment variable requirements...');\n\t\t\tconst requiredVars = await collectRequiredEnvVars(constructs);\n\n\t\t\tif (requiredVars.length > 0) {\n\t\t\t\tconst validation = validateEnvironmentVariables(requiredVars, secrets);\n\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst errorMessage = [\n\t\t\t\t\t\t`Missing environment variables for stage \"${stage}\":`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t...validation.missing.map((v) => ` ❌ ${v}`),\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'To fix this, either:',\n\t\t\t\t\t\t` 1. Add the missing variables to the \"${stage}\" secrets using:`,\n\t\t\t\t\t\t` gkm secrets:set <KEY> <VALUE> --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t` 2. Or import from a JSON file:`,\n\t\t\t\t\t\t` gkm secrets:import secrets.json --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'Required variables:',\n\t\t\t\t\t\t...validation.required.map((v) =>\n\t\t\t\t\t\t\tvalidation.missing.includes(v) ? ` ❌ ${v}` : ` ✓ ${v}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t].join('\\n');\n\n\t\t\t\t\tthrow new Error(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t` ✓ All ${requiredVars.length} required environment variables found`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Convert to embeddable format and encrypt\n\t\tconst embeddable = toEmbeddableSecrets(secrets);\n\t\tconst encrypted = encryptSecrets(embeddable);\n\t\tmasterKey = encrypted.masterKey;\n\n\t\t// Add define options for build-time injection using esbuild's --define:KEY=VALUE format\n\t\tconst defines = generateDefineOptions(encrypted);\n\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t// `value` is already a JS string literal; quoting it again would\n\t\t\t// embed the quotes, and the IV would not parse as hex.\n\t\t\targs.push(`--define:${key}=${value}`);\n\t\t}\n\n\t\tconsole.log(` Secrets encrypted for stage \"${stage}\"`);\n\t} else {\n\t\t// Credentials encrypted elsewhere — an image build hands them in as a\n\t\t// BuildKit secret and writes them beside the app's `.gkm/server` — are\n\t\t// embedded as they are; whoever encrypted them holds the key.\n\t\tconst gkmDir = join(outputDir, '..', '..');\n\t\tconst encryptedPath = join(gkmDir, 'credentials.enc');\n\t\tconst ivPath = join(gkmDir, 'credentials.iv');\n\t\tif (existsSync(encryptedPath) && existsSync(ivPath)) {\n\t\t\tconst { generateDefineOptions } = await import('../secrets/encryption');\n\t\t\tconst defines = generateDefineOptions({\n\t\t\t\tencrypted: readFileSync(encryptedPath, 'utf-8').trim(),\n\t\t\t\tiv: readFileSync(ivPath, 'utf-8').trim(),\n\t\t\t\tmasterKey: '',\n\t\t\t});\n\t\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t\targs.push(`--define:${key}=${value}`);\n\t\t\t}\n\t\t\tconsole.log(' Embedded the encrypted credentials the build was given');\n\t\t}\n\t}\n\n\ttry {\n\t\t// Run esbuild with command-line arguments\n\t\tconst [cmd, ...cmdArgs] = args as [string, ...string[]];\n\t\tconst result = spawnSync(cmd, cmdArgs, {\n\t\t\tcwd: process.cwd(),\n\t\t\tstdio: 'inherit',\n\t\t\tshell: process.platform === 'win32', // Only use shell on Windows for npx resolution\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tthrow result.error;\n\t\t}\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(`esbuild exited with code ${result.status}`);\n\t\t}\n\n\t\t// Add shebang to the bundled file\n\t\tconst { readFile } = await import('node:fs/promises');\n\t\tconst content = await readFile(mjsOutput, 'utf-8');\n\t\tif (!content.startsWith('#!')) {\n\t\t\tawait writeFile(mjsOutput, `#!/usr/bin/env node\\n${content}`);\n\t\t}\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to bundle server: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t);\n\t}\n\n\t// Declared ones always; a native package only where the bundle imports it\n\t// — an app that depends on `@geekmidas/cli` reaches esbuild, and never\n\t// runs it.\n\tconst imported = importedPackages(metafile);\n\tawait rm(metafile, { force: true });\n\tconst externals = Object.fromEntries(\n\t\tObject.entries(candidates).filter(\n\t\t\t([name]) => external.includes(name) || imported.has(name),\n\t\t),\n\t);\n\tawait writeFile(\n\t\tjoin(outputDir, externalsManifestName(outfile)),\n\t\t`${JSON.stringify({ private: true, dependencies: externals }, null, 2)}\\n`,\n\t);\n\tif (Object.keys(externals).length > 0) {\n\t\tconsole.log(\n\t\t\t` Left out of the bundle, installed beside it: ${Object.keys(externals).join(', ')}`,\n\t\t);\n\t}\n\n\treturn {\n\t\toutputPath: mjsOutput,\n\t\tmasterKey,\n\t\texternals,\n\t};\n}\n"],"mappings":";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D,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,UAAU,MAAM,SAAS,WAAW,OAAO;EACjD,IAAI,CAAC,QAAQ,WAAW,IAAI,GAC3B,MAAM,UAAU,WAAW,wBAAwB,SAAS;CAE9D,SAAS,OAAO;EACf,MAAM,IAAI,MACT,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,iBACtE;CACD;CAKA,MAAM,WAAW,iBAAiB,QAAQ;CAC1C,MAAM,GAAG,UAAU,EAAE,OAAO,KAAK,CAAC;CAClC,MAAM,YAAY,OAAO,YACxB,OAAO,QAAQ,UAAU,CAAC,CAAC,QACzB,CAAC,UAAU,SAAS,SAAS,IAAI,KAAK,SAAS,IAAI,IAAI,CACzD,CACD;CACA,MAAM,UACL,KAAK,WAAW,sBAAsB,OAAO,CAAC,GAC9C,GAAG,KAAK,UAAU;EAAE,SAAS;EAAM,cAAc;CAAU,GAAG,MAAM,CAAC,EAAE,GACxE;CACA,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS,GACnC,QAAQ,IACP,kDAAkD,OAAO,KAAK,SAAS,CAAC,CAAC,KAAK,IAAI,GACnF;CAGD,OAAO;EACN,YAAY;EACZ;EACA;CACD;AACD"}
1
+ {"version":3,"file":"bundler-o10_P4d9.mjs","names":[],"sources":["../src/build/bundler.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { mkdir, rm, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { Construct } from '@geekmidas/constructs';\nimport {\n\tbundleExternals,\n\texternalsManifestName,\n\timportedPackages,\n} from './native';\n\n/**\n * Banner to inject into ESM bundle for CJS compatibility.\n * Creates a `require` function using Node's createRequire for packages\n * that internally use CommonJS require() for Node builtins.\n */\nconst ESM_CJS_COMPAT_BANNER =\n\t'import { createRequire } from \"module\"; const require = createRequire(import.meta.url);';\n\nexport interface BundleOptions {\n\t/** Entry point file (e.g., .gkm/server/server.ts) */\n\tentryPoint: string;\n\t/** Output directory for bundled files */\n\toutputDir: string;\n\t/** The bundle's file name in `outputDir`. Defaults to `server.mjs`. */\n\toutfile?: string;\n\t/** Minify the output (default: true) */\n\tminify: boolean;\n\t/** Generate sourcemaps (default: false) */\n\tsourcemap: boolean;\n\t/**\n\t * Packages to leave out of the bundle besides its native ones, which are\n\t * always left out and recorded beside it — see `externalsManifestName`.\n\t */\n\texternal: string[];\n\t/** Stage for secrets injection (optional) */\n\tstage?: string;\n\t/** Constructs to validate environment variables for */\n\tconstructs?: Construct[];\n}\n\nexport interface BundleResult {\n\t/** Path to the bundled output */\n\toutputPath: string;\n\t/** Ephemeral master key for deployment (only if stage was provided) */\n\tmasterKey?: string;\n\t/** What the bundle left out, at the version to install beside it. */\n\texternals: Record<string, string>;\n}\n\n/** The app a bundle is built for: the nearest `package.json` above its entry. */\nfunction appRootOf(entryPoint: string): string {\n\tlet dir = dirname(entryPoint);\n\twhile (!existsSync(join(dir, 'package.json'))) {\n\t\tconst parent = dirname(dir);\n\t\tif (parent === dir) return dirname(entryPoint);\n\t\tdir = parent;\n\t}\n\treturn dir;\n}\n\n/**\n * The esbuild binary, resolved from this package rather than from PATH.\n *\n * It used to be `npx esbuild`, which is two assumptions: that esbuild is\n * installed somewhere npx can find, and that the *app's* directory is where to\n * look. Neither holds — the CLI did not depend on esbuild at all, so a deploy\n * run from an app that had not installed it failed at the bundle step with\n * `sh: esbuild: command not found`, after provisioning had already happened.\n *\n * The same fix `bin/gkm.mjs` makes for tsx: resolve from this package's own\n * `node_modules`, so the tool the CLI shells out to is the one it depends on.\n */\nfunction esbuildBinary(): string {\n\tconst require = createRequire(import.meta.url);\n\n\ttry {\n\t\t// The package root, then its bin — `require.resolve('esbuild')` gives the\n\t\t// JS entry point, which is a library rather than the CLI.\n\t\tconst pkg = require.resolve('esbuild/package.json');\n\t\treturn join(dirname(pkg), 'bin', 'esbuild');\n\t} catch {\n\t\t// Better a PATH lookup than a hard failure: a project that installed\n\t\t// esbuild itself still works.\n\t\treturn 'esbuild';\n\t}\n}\n\n/**\n * Collect the environment variables a build cannot proceed without.\n *\n * Uses the SnifferEnvironmentParser to detect which env vars each service\n * reads, and keeps only the ones it cannot do without. `markOptional` is what\n * separates them: the sniffer already knows which reads went through\n * `.optional()` or `.default()`, and asking for that distinction is the\n * difference between a build that stops and one that proceeds correctly.\n *\n * Without it, a key that is *absent by design* failed the build. A surface\n * publishes `AUTH_COOKIE_DOMAIN` only when there is a domain to widen a cookie\n * to — one host has nothing to share it with, so the derivation correctly\n * yields nothing, and Better Auth reads it as optional for exactly that\n * reason. Treating every sniffed read as required made the honest answer\n * indistinguishable from a missing secret.\n *\n * @param constructs - Array of constructs to analyze\n * @returns Deduplicated, sorted names of the required variables\n */\nasync function collectRequiredEnvVars(\n\tconstructs: Construct[],\n): Promise<string[]> {\n\t// A key read optionally by one construct and required by another stays\n\t// required: the strictest read is the one that fails at runtime, and taking\n\t// the union of the required reads is what says so.\n\tconst required = new Set<string>();\n\n\tfor (const construct of constructs) {\n\t\tfor (const name of await construct.getEnvironment({ markOptional: true })) {\n\t\t\tif (!name.endsWith('?')) required.add(name);\n\t\t}\n\t}\n\n\treturn Array.from(required).sort();\n}\n\n/**\n * Bundle the server application using esbuild.\n * Creates a fully standalone bundle with all dependencies included.\n *\n * @param options - Bundle configuration options\n * @returns Bundle result with output path and optional master key\n */\n\nexport async function bundleServer(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tentryPoint,\n\t\toutputDir,\n\t\tminify,\n\t\tsourcemap,\n\t\texternal,\n\t\tstage,\n\t\tconstructs,\n\t} = options;\n\n\t// Ensure output directory exists\n\tawait mkdir(outputDir, { recursive: true });\n\n\tconst outfile = options.outfile ?? 'server.mjs';\n\tconst mjsOutput = join(outputDir, outfile);\n\n\t// A package with native code loads a binary from beside its own source,\n\t// built for the platform it was installed on: inlined, it finds neither.\n\t// Every one the app could reach stays out of the bundle, and the ones the\n\t// bundle imports are installed for the image's platform at this version.\n\tconst candidates = bundleExternals(appRootOf(entryPoint), external);\n\tconst metafile = join(outputDir, `.${outfile}.meta.json`);\n\n\t// Build command-line arguments for esbuild\n\tconst args = [\n\t\tesbuildBinary(),\n\t\tentryPoint,\n\t\t'--bundle',\n\t\t'--platform=node',\n\t\t'--target=node22',\n\t\t'--format=esm',\n\t\t`--outfile=${mjsOutput}`,\n\t\t'--packages=bundle', // Bundle all dependencies for standalone output\n\t\t`--banner:js=${ESM_CJS_COMPAT_BANNER}`, // CJS compatibility for packages like pino\n\t\t`--metafile=${metafile}`,\n\t];\n\n\tif (minify) {\n\t\t// Names kept: an error's class name is what a log line's `err.type` and\n\t\t// a response's `name` say, and minified they read `_6`.\n\t\targs.push('--minify', '--keep-names');\n\t}\n\n\tif (sourcemap) {\n\t\targs.push('--sourcemap');\n\t}\n\n\tfor (const ext of Object.keys(candidates)) {\n\t\targs.push(`--external:${ext}`);\n\t}\n\n\t// Handle secrets injection if stage is provided\n\tlet masterKey: string | undefined;\n\n\tif (stage) {\n\t\tconst {\n\t\t\ttoEmbeddableSecrets,\n\t\t\tvalidateEnvironmentVariables,\n\t\t\tinitStageSecrets,\n\t\t} = await import('../secrets/storage');\n\t\tconst { FileSecretsStore, secretsStoreFor } = await import(\n\t\t\t'../secrets/store'\n\t\t);\n\t\tconst { ConfigNotFound, loadWorkspaceSettings } = await import('../config');\n\t\tconst { encryptSecrets, generateDefineOptions } = await import(\n\t\t\t'../secrets/encryption'\n\t\t);\n\n\t\t// The stage's own store — SSM or Secrets Manager for a deployed stage\n\t\t// kept there. Outside\n\t\t// any workspace nothing names one, so it is the file.\n\t\tconst store = await loadWorkspaceSettings().then(\n\t\t\t(workspace) => secretsStoreFor(workspace, stage),\n\t\t\t(error) => {\n\t\t\t\tif (error instanceof ConfigNotFound) {\n\t\t\t\t\treturn new FileSecretsStore(process.cwd());\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tlet secrets = await store.read(stage);\n\n\t\tif (!secrets) {\n\t\t\t// Auto-initialize secrets for the stage\n\t\t\tconsole.log(` Initializing secrets for stage \"${stage}\"...`);\n\t\t\tsecrets = initStageSecrets(stage);\n\t\t\tawait store.write(stage, secrets);\n\t\t\tconsole.log(` ✓ Created the \"${stage}\" secrets (${store.name})`);\n\t\t}\n\n\t\t// Validate environment variables if constructs are provided\n\t\tif (constructs && constructs.length > 0) {\n\t\t\tconsole.log(' Analyzing environment variable requirements...');\n\t\t\tconst requiredVars = await collectRequiredEnvVars(constructs);\n\n\t\t\tif (requiredVars.length > 0) {\n\t\t\t\tconst validation = validateEnvironmentVariables(requiredVars, secrets);\n\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst errorMessage = [\n\t\t\t\t\t\t`Missing environment variables for stage \"${stage}\":`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t...validation.missing.map((v) => ` ❌ ${v}`),\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'To fix this, either:',\n\t\t\t\t\t\t` 1. Add the missing variables to the \"${stage}\" secrets using:`,\n\t\t\t\t\t\t` gkm secrets:set <KEY> <VALUE> --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t` 2. Or import from a JSON file:`,\n\t\t\t\t\t\t` gkm secrets:import secrets.json --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'Required variables:',\n\t\t\t\t\t\t...validation.required.map((v) =>\n\t\t\t\t\t\t\tvalidation.missing.includes(v) ? ` ❌ ${v}` : ` ✓ ${v}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t].join('\\n');\n\n\t\t\t\t\tthrow new Error(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t` ✓ All ${requiredVars.length} required environment variables found`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Convert to embeddable format and encrypt\n\t\tconst embeddable = toEmbeddableSecrets(secrets);\n\t\tconst encrypted = encryptSecrets(embeddable);\n\t\tmasterKey = encrypted.masterKey;\n\n\t\t// Add define options for build-time injection using esbuild's --define:KEY=VALUE format\n\t\tconst defines = generateDefineOptions(encrypted);\n\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t// `value` is already a JS string literal; quoting it again would\n\t\t\t// embed the quotes, and the IV would not parse as hex.\n\t\t\targs.push(`--define:${key}=${value}`);\n\t\t}\n\n\t\tconsole.log(` Secrets encrypted for stage \"${stage}\"`);\n\t} else {\n\t\t// Credentials encrypted elsewhere — an image build hands them in as a\n\t\t// BuildKit secret and writes them beside the app's `.gkm/server` — are\n\t\t// embedded as they are; whoever encrypted them holds the key.\n\t\tconst gkmDir = join(outputDir, '..', '..');\n\t\tconst encryptedPath = join(gkmDir, 'credentials.enc');\n\t\tconst ivPath = join(gkmDir, 'credentials.iv');\n\t\tif (existsSync(encryptedPath) && existsSync(ivPath)) {\n\t\t\tconst { generateDefineOptions } = await import('../secrets/encryption');\n\t\t\tconst defines = generateDefineOptions({\n\t\t\t\tencrypted: readFileSync(encryptedPath, 'utf-8').trim(),\n\t\t\t\tiv: readFileSync(ivPath, 'utf-8').trim(),\n\t\t\t\tmasterKey: '',\n\t\t\t});\n\t\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t\targs.push(`--define:${key}=${value}`);\n\t\t\t}\n\t\t\tconsole.log(' Embedded the encrypted credentials the build was given');\n\t\t}\n\t}\n\n\ttry {\n\t\t// Run esbuild with command-line arguments\n\t\tconst [cmd, ...cmdArgs] = args as [string, ...string[]];\n\t\tconst result = spawnSync(cmd, cmdArgs, {\n\t\t\tcwd: process.cwd(),\n\t\t\tstdio: 'inherit',\n\t\t\tshell: process.platform === 'win32', // Only use shell on Windows for npx resolution\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tthrow result.error;\n\t\t}\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(`esbuild exited with code ${result.status}`);\n\t\t}\n\n\t\t// Add shebang to the bundled file\n\t\tconst { readFile } = await import('node:fs/promises');\n\t\tconst content = await readFile(mjsOutput, 'utf-8');\n\t\tif (!content.startsWith('#!')) {\n\t\t\tawait writeFile(mjsOutput, `#!/usr/bin/env node\\n${content}`);\n\t\t}\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to bundle server: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t);\n\t}\n\n\t// Declared ones always; a native package only where the bundle imports it\n\t// — an app that depends on `@geekmidas/cli` reaches esbuild, and never\n\t// runs it.\n\tconst imported = importedPackages(metafile);\n\tawait rm(metafile, { force: true });\n\tconst externals = Object.fromEntries(\n\t\tObject.entries(candidates).filter(\n\t\t\t([name]) => external.includes(name) || imported.has(name),\n\t\t),\n\t);\n\tawait writeFile(\n\t\tjoin(outputDir, externalsManifestName(outfile)),\n\t\t`${JSON.stringify({ private: true, dependencies: externals }, null, 2)}\\n`,\n\t);\n\tif (Object.keys(externals).length > 0) {\n\t\tconsole.log(\n\t\t\t` Left out of the bundle, installed beside it: ${Object.keys(externals).join(', ')}`,\n\t\t);\n\t}\n\n\treturn {\n\t\toutputPath: mjsOutput,\n\t\tmasterKey,\n\t\texternals,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAM,wBACL;;AAkCD,SAAS,UAAU,YAA4B;CAC9C,IAAI,MAAM,QAAQ,UAAU;CAC5B,OAAO,CAAC,WAAW,KAAK,KAAK,cAAc,CAAC,GAAG;EAC9C,MAAM,SAAS,QAAQ,GAAG;EAC1B,IAAI,WAAW,KAAK,OAAO,QAAQ,UAAU;EAC7C,MAAM;CACP;CACA,OAAO;AACR;;;;;;;;;;;;;AAcA,SAAS,gBAAwB;CAChC,MAAM,UAAU,cAAc,YAAY,GAAG;CAE7C,IAAI;EAGH,MAAM,MAAM,QAAQ,QAAQ,sBAAsB;EAClD,OAAO,KAAK,QAAQ,GAAG,GAAG,OAAO,SAAS;CAC3C,QAAQ;EAGP,OAAO;CACR;AACD;;;;;;;;;;;;;;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BAAsB,OAAO,CAAC,GAC9C,GAAG,KAAK,UAAU;EAAE,SAAS;EAAM,cAAc;CAAU,GAAG,MAAM,CAAC,EAAE,GACxE;CACA,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS,GACnC,QAAQ,IACP,kDAAkD,OAAO,KAAK,SAAS,CAAC,CAAC,KAAK,IAAI,GACnF;CAGD,OAAO;EACN,YAAY;EACZ;EACA;CACD;AACD"}
@@ -1,8 +1,8 @@
1
- const require_credentials = require("./credentials-BryyjZPs.cjs");
2
- const require_deploy = require("./deploy-DCFfSmMK.cjs");
1
+ const require_credentials = require("./credentials-DixsjQcu.cjs");
2
+ const require_deploy = require("./deploy-DzYn1rNl.cjs");
3
3
  const require_index = require("./index.cjs");
4
4
  const require_provider = require("./provider-BqpjG9QM.cjs");
5
- const require_terminal = require("./terminal-CKfjtEyy.cjs");
5
+ const require_terminal = require("./terminal-CyB5bRPt.cjs");
6
6
  //#region src/deploy/cli.ts
7
7
  /**
8
8
  * `gkm deploy`: the terminal around `deploy()`. CLI layer only.
@@ -68,4 +68,4 @@ async function deployCli(options, streams = { stdout: process.stdout }) {
68
68
  //#endregion
69
69
  exports.deployCli = deployCli;
70
70
 
71
- //# sourceMappingURL=cli-DvtRusay.cjs.map
71
+ //# sourceMappingURL=cli-BO4qIuTd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-DvtRusay.cjs","names":["targetForProvider","formatError","deploy","storedCredentials","terminalCredentials"],"sources":["../src/deploy/cli.ts"],"sourcesContent":["/**\n * `gkm deploy`: the terminal around `deploy()`. CLI layer only.\n *\n * Everything that belongs to a person at a terminal lives here and nowhere\n * below it: prompting for a missing login (and storing it), printing progress,\n * and turning the outcome into an exit code. The deploy itself is the same\n * `deploy()` a host calls.\n */\n\nimport { formatError } from '../debug';\nimport { targetForProvider } from '../target/provider';\nimport { storedCredentials } from './credentials';\nimport { deploy } from './deploy';\nimport { terminalCredentials } from './terminal';\n\nexport interface DeployCliOptions {\n\t/** The project directory: `--cwd`, else where the command was run. */\n\tcwd: string;\n\t/** `--target`: where to deploy. Defaults to `deploy.default`. */\n\ttarget?: string;\n\t/** `--provider`, deprecated: `dokploy` means `--target dokploy`. */\n\tprovider?: string;\n\tstage: string;\n\ttag?: string;\n\t/**\n\t * Print each event as one JSON object per line on stdout, instead of the\n\t * progress lines. Nothing prompts: a missing credential fails the run.\n\t */\n\tjson?: boolean;\n\t/** Plan only: create, change, build and push nothing. */\n\tdryRun?: boolean;\n\t/** On a failed release, roll back every app, not only the failed ones. */\n\tatomic?: boolean;\n\t/** `--allow-dev-services`. */\n\tallowDevServices?: boolean;\n\t/** `--skip-dns`. */\n\tskipDns?: boolean;\n\t/** `--rotate-keys`. */\n\trotateKeys?: boolean;\n\t/** `--retire-old-keys`. */\n\tretireOldKeys?: boolean;\n}\n\n/** Where the command writes. The process's own streams, outside tests. */\nexport interface DeployCliStreams {\n\tstdout: Pick<NodeJS.WriteStream, 'write'>;\n}\n\n/**\n * Run `gkm deploy` and resolve with its exit code: 0 when the run finished,\n * 1 when anything stopped it.\n */\nexport async function deployCli(\n\toptions: DeployCliOptions,\n\tstreams: DeployCliStreams = { stdout: process.stdout },\n): Promise<number> {\n\tlet target = options.target;\n\tif (options.provider !== undefined && target === undefined) {\n\t\ttry {\n\t\t\t// On stderr, so a `--json` run's stdout still carries only events.\n\t\t\ttarget = targetForProvider(options.provider, (message) =>\n\t\t\t\tconsole.warn(message),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(formatError(error));\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tconst input = {\n\t\tcwd: options.cwd,\n\t\tstage: options.stage,\n\t\t...(target ? { target } : {}),\n\t\t...(options.tag ? { tag: options.tag } : {}),\n\t\t...(options.dryRun ? { dryRun: true } : {}),\n\t\t...(options.atomic ? { atomic: true } : {}),\n\t\t...(options.allowDevServices ? { allowDevServices: true } : {}),\n\t\t...(options.skipDns ? { skipDns: true } : {}),\n\t\t...(options.rotateKeys ? { rotateKeys: true } : {}),\n\t\t...(options.retireOldKeys ? { retireOldKeys: true } : {}),\n\t};\n\n\tif (options.json) {\n\t\t// stdout carries the events and nothing else: docker's own output goes\n\t\t// to stderr, and nobody is asked anything — a prompt would be written\n\t\t// into the stream a program is parsing.\n\t\tconst run = deploy({\n\t\t\t...input,\n\t\t\tcredentials: storedCredentials(),\n\t\t\tchildOutput: 'stderr',\n\t\t});\n\t\tfor await (const event of run) {\n\t\t\tstreams.stdout.write(`${JSON.stringify(event)}\\n`);\n\t\t}\n\t\treturn run.result.then(\n\t\t\t() => 0,\n\t\t\t(error) => {\n\t\t\t\tconsole.error(formatError(error));\n\t\t\t\treturn 1;\n\t\t\t},\n\t\t);\n\t}\n\n\t// The lines arrive as they are written, rather than as events read back a\n\t// tick later, so they interleave with a prompt exactly as they always did.\n\tconst run = deploy({\n\t\t...input,\n\t\tcredentials: terminalCredentials(storedCredentials()),\n\t\tlogger: {\n\t\t\tinfo: (message) => console.log(message),\n\t\t\twarn: (message) => console.warn(message),\n\t\t\terror: (message) => console.error(message),\n\t\t},\n\t});\n\n\ttry {\n\t\tawait run.result;\n\t\treturn 0;\n\t} catch (error) {\n\t\tconsole.error(formatError(error));\n\t\treturn 1;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,eAAsB,UACrB,SACA,UAA4B,EAAE,QAAQ,QAAQ,OAAO,GACnC;CAClB,IAAI,SAAS,QAAQ;CACrB,IAAI,QAAQ,aAAa,KAAA,KAAa,WAAW,KAAA,GAChD,IAAI;EAEH,SAASA,iBAAAA,kBAAkB,QAAQ,WAAW,YAC7C,QAAQ,KAAK,OAAO,CACrB;CACD,SAAS,OAAO;EACf,QAAQ,MAAMC,cAAAA,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;CAGD,MAAM,QAAQ;EACb,KAAK,QAAQ;EACb,OAAO,QAAQ;EACf,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;EAC3B,GAAI,QAAQ,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC;EAC1C,GAAI,QAAQ,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;EACzC,GAAI,QAAQ,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;EACzC,GAAI,QAAQ,mBAAmB,EAAE,kBAAkB,KAAK,IAAI,CAAC;EAC7D,GAAI,QAAQ,UAAU,EAAE,SAAS,KAAK,IAAI,CAAC;EAC3C,GAAI,QAAQ,aAAa,EAAE,YAAY,KAAK,IAAI,CAAC;EACjD,GAAI,QAAQ,gBAAgB,EAAE,eAAe,KAAK,IAAI,CAAC;CACxD;CAEA,IAAI,QAAQ,MAAM;EAIjB,MAAM,MAAMC,eAAAA,OAAO;GAClB,GAAG;GACH,aAAaC,oBAAAA,kBAAkB;GAC/B,aAAa;EACd,CAAC;EACD,WAAW,MAAM,SAAS,KACzB,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,KAAK,EAAE,GAAG;EAElD,OAAO,IAAI,OAAO,WACX,IACL,UAAU;GACV,QAAQ,MAAMF,cAAAA,YAAY,KAAK,CAAC;GAChC,OAAO;EACR,CACD;CACD;CAIA,MAAM,MAAMC,eAAAA,OAAO;EAClB,GAAG;EACH,aAAaE,iBAAAA,oBAAoBD,oBAAAA,kBAAkB,CAAC;EACpD,QAAQ;GACP,OAAO,YAAY,QAAQ,IAAI,OAAO;GACtC,OAAO,YAAY,QAAQ,KAAK,OAAO;GACvC,QAAQ,YAAY,QAAQ,MAAM,OAAO;EAC1C;CACD,CAAC;CAED,IAAI;EACH,MAAM,IAAI;EACV,OAAO;CACR,SAAS,OAAO;EACf,QAAQ,MAAMF,cAAAA,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"cli-BO4qIuTd.cjs","names":["targetForProvider","formatError","deploy","storedCredentials","terminalCredentials"],"sources":["../src/deploy/cli.ts"],"sourcesContent":["/**\n * `gkm deploy`: the terminal around `deploy()`. CLI layer only.\n *\n * Everything that belongs to a person at a terminal lives here and nowhere\n * below it: prompting for a missing login (and storing it), printing progress,\n * and turning the outcome into an exit code. The deploy itself is the same\n * `deploy()` a host calls.\n */\n\nimport { formatError } from '../debug';\nimport { targetForProvider } from '../target/provider';\nimport { storedCredentials } from './credentials';\nimport { deploy } from './deploy';\nimport { terminalCredentials } from './terminal';\n\nexport interface DeployCliOptions {\n\t/** The project directory: `--cwd`, else where the command was run. */\n\tcwd: string;\n\t/** `--target`: where to deploy. Defaults to `deploy.default`. */\n\ttarget?: string;\n\t/** `--provider`, deprecated: `dokploy` means `--target dokploy`. */\n\tprovider?: string;\n\tstage: string;\n\ttag?: string;\n\t/**\n\t * Print each event as one JSON object per line on stdout, instead of the\n\t * progress lines. Nothing prompts: a missing credential fails the run.\n\t */\n\tjson?: boolean;\n\t/** Plan only: create, change, build and push nothing. */\n\tdryRun?: boolean;\n\t/** On a failed release, roll back every app, not only the failed ones. */\n\tatomic?: boolean;\n\t/** `--allow-dev-services`. */\n\tallowDevServices?: boolean;\n\t/** `--skip-dns`. */\n\tskipDns?: boolean;\n\t/** `--rotate-keys`. */\n\trotateKeys?: boolean;\n\t/** `--retire-old-keys`. */\n\tretireOldKeys?: boolean;\n}\n\n/** Where the command writes. The process's own streams, outside tests. */\nexport interface DeployCliStreams {\n\tstdout: Pick<NodeJS.WriteStream, 'write'>;\n}\n\n/**\n * Run `gkm deploy` and resolve with its exit code: 0 when the run finished,\n * 1 when anything stopped it.\n */\nexport async function deployCli(\n\toptions: DeployCliOptions,\n\tstreams: DeployCliStreams = { stdout: process.stdout },\n): Promise<number> {\n\tlet target = options.target;\n\tif (options.provider !== undefined && target === undefined) {\n\t\ttry {\n\t\t\t// On stderr, so a `--json` run's stdout still carries only events.\n\t\t\ttarget = targetForProvider(options.provider, (message) =>\n\t\t\t\tconsole.warn(message),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(formatError(error));\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tconst input = {\n\t\tcwd: options.cwd,\n\t\tstage: options.stage,\n\t\t...(target ? { target } : {}),\n\t\t...(options.tag ? { tag: options.tag } : {}),\n\t\t...(options.dryRun ? { dryRun: true } : {}),\n\t\t...(options.atomic ? { atomic: true } : {}),\n\t\t...(options.allowDevServices ? { allowDevServices: true } : {}),\n\t\t...(options.skipDns ? { skipDns: true } : {}),\n\t\t...(options.rotateKeys ? { rotateKeys: true } : {}),\n\t\t...(options.retireOldKeys ? { retireOldKeys: true } : {}),\n\t};\n\n\tif (options.json) {\n\t\t// stdout carries the events and nothing else: docker's own output goes\n\t\t// to stderr, and nobody is asked anything — a prompt would be written\n\t\t// into the stream a program is parsing.\n\t\tconst run = deploy({\n\t\t\t...input,\n\t\t\tcredentials: storedCredentials(),\n\t\t\tchildOutput: 'stderr',\n\t\t});\n\t\tfor await (const event of run) {\n\t\t\tstreams.stdout.write(`${JSON.stringify(event)}\\n`);\n\t\t}\n\t\treturn run.result.then(\n\t\t\t() => 0,\n\t\t\t(error) => {\n\t\t\t\tconsole.error(formatError(error));\n\t\t\t\treturn 1;\n\t\t\t},\n\t\t);\n\t}\n\n\t// The lines arrive as they are written, rather than as events read back a\n\t// tick later, so they interleave with a prompt exactly as they always did.\n\tconst run = deploy({\n\t\t...input,\n\t\tcredentials: terminalCredentials(storedCredentials()),\n\t\tlogger: {\n\t\t\tinfo: (message) => console.log(message),\n\t\t\twarn: (message) => console.warn(message),\n\t\t\terror: (message) => console.error(message),\n\t\t},\n\t});\n\n\ttry {\n\t\tawait run.result;\n\t\treturn 0;\n\t} catch (error) {\n\t\tconsole.error(formatError(error));\n\t\treturn 1;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,eAAsB,UACrB,SACA,UAA4B,EAAE,QAAQ,QAAQ,OAAO,GACnC;CAClB,IAAI,SAAS,QAAQ;CACrB,IAAI,QAAQ,aAAa,KAAA,KAAa,WAAW,KAAA,GAChD,IAAI;EAEH,SAASA,iBAAAA,kBAAkB,QAAQ,W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AS,OAAO;EACf,QAAQ,MAAMF,cAAAA,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;AACD"}
@@ -1,8 +1,8 @@
1
- import { r as storedCredentials } from "./credentials-wid61zD2.mjs";
2
- import { t as deploy } from "./deploy-CDNFAKqC.mjs";
1
+ import { r as storedCredentials } from "./credentials-DY_Cu5Ht.mjs";
2
+ import { t as deploy } from "./deploy-DsWQ8kTC.mjs";
3
3
  import { s as formatError } from "./index.mjs";
4
4
  import { n as targetForProvider } from "./provider-CEOKk8NS.mjs";
5
- import { terminalCredentials } from "./terminal-CKuv6CB4.mjs";
5
+ import { terminalCredentials } from "./terminal-b_4H0MHd.mjs";
6
6
  //#region src/deploy/cli.ts
7
7
  /**
8
8
  * `gkm deploy`: the terminal around `deploy()`. CLI layer only.
@@ -68,4 +68,4 @@ async function deployCli(options, streams = { stdout: process.stdout }) {
68
68
  //#endregion
69
69
  export { deployCli };
70
70
 
71
- //# sourceMappingURL=cli-BLfIYaB3.mjs.map
71
+ //# sourceMappingURL=cli-KFbKAyaH.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-BLfIYaB3.mjs","names":[],"sources":["../src/deploy/cli.ts"],"sourcesContent":["/**\n * `gkm deploy`: the terminal around `deploy()`. CLI layer only.\n *\n * Everything that belongs to a person at a terminal lives here and nowhere\n * below it: prompting for a missing login (and storing it), printing progress,\n * and turning the outcome into an exit code. The deploy itself is the same\n * `deploy()` a host calls.\n */\n\nimport { formatError } from '../debug';\nimport { targetForProvider } from '../target/provider';\nimport { storedCredentials } from './credentials';\nimport { deploy } from './deploy';\nimport { terminalCredentials } from './terminal';\n\nexport interface DeployCliOptions {\n\t/** The project directory: `--cwd`, else where the command was run. */\n\tcwd: string;\n\t/** `--target`: where to deploy. Defaults to `deploy.default`. */\n\ttarget?: string;\n\t/** `--provider`, deprecated: `dokploy` means `--target dokploy`. */\n\tprovider?: string;\n\tstage: string;\n\ttag?: string;\n\t/**\n\t * Print each event as one JSON object per line on stdout, instead of the\n\t * progress lines. Nothing prompts: a missing credential fails the run.\n\t */\n\tjson?: boolean;\n\t/** Plan only: create, change, build and push nothing. */\n\tdryRun?: boolean;\n\t/** On a failed release, roll back every app, not only the failed ones. */\n\tatomic?: boolean;\n\t/** `--allow-dev-services`. */\n\tallowDevServices?: boolean;\n\t/** `--skip-dns`. */\n\tskipDns?: boolean;\n\t/** `--rotate-keys`. */\n\trotateKeys?: boolean;\n\t/** `--retire-old-keys`. */\n\tretireOldKeys?: boolean;\n}\n\n/** Where the command writes. The process's own streams, outside tests. */\nexport interface DeployCliStreams {\n\tstdout: Pick<NodeJS.WriteStream, 'write'>;\n}\n\n/**\n * Run `gkm deploy` and resolve with its exit code: 0 when the run finished,\n * 1 when anything stopped it.\n */\nexport async function deployCli(\n\toptions: DeployCliOptions,\n\tstreams: DeployCliStreams = { stdout: process.stdout },\n): Promise<number> {\n\tlet target = options.target;\n\tif (options.provider !== undefined && target === undefined) {\n\t\ttry {\n\t\t\t// On stderr, so a `--json` run's stdout still carries only events.\n\t\t\ttarget = targetForProvider(options.provider, (message) =>\n\t\t\t\tconsole.warn(message),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(formatError(error));\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tconst input = {\n\t\tcwd: options.cwd,\n\t\tstage: options.stage,\n\t\t...(target ? { target } : {}),\n\t\t...(options.tag ? { tag: options.tag } : {}),\n\t\t...(options.dryRun ? { dryRun: true } : {}),\n\t\t...(options.atomic ? { atomic: true } : {}),\n\t\t...(options.allowDevServices ? { allowDevServices: true } : {}),\n\t\t...(options.skipDns ? { skipDns: true } : {}),\n\t\t...(options.rotateKeys ? { rotateKeys: true } : {}),\n\t\t...(options.retireOldKeys ? { retireOldKeys: true } : {}),\n\t};\n\n\tif (options.json) {\n\t\t// stdout carries the events and nothing else: docker's own output goes\n\t\t// to stderr, and nobody is asked anything — a prompt would be written\n\t\t// into the stream a program is parsing.\n\t\tconst run = deploy({\n\t\t\t...input,\n\t\t\tcredentials: storedCredentials(),\n\t\t\tchildOutput: 'stderr',\n\t\t});\n\t\tfor await (const event of run) {\n\t\t\tstreams.stdout.write(`${JSON.stringify(event)}\\n`);\n\t\t}\n\t\treturn run.result.then(\n\t\t\t() => 0,\n\t\t\t(error) => {\n\t\t\t\tconsole.error(formatError(error));\n\t\t\t\treturn 1;\n\t\t\t},\n\t\t);\n\t}\n\n\t// The lines arrive as they are written, rather than as events read back a\n\t// tick later, so they interleave with a prompt exactly as they always did.\n\tconst run = deploy({\n\t\t...input,\n\t\tcredentials: terminalCredentials(storedCredentials()),\n\t\tlogger: {\n\t\t\tinfo: (message) => console.log(message),\n\t\t\twarn: (message) => console.warn(message),\n\t\t\terror: (message) => console.error(message),\n\t\t},\n\t});\n\n\ttry {\n\t\tawait run.result;\n\t\treturn 0;\n\t} catch (error) {\n\t\tconsole.error(formatError(error));\n\t\treturn 1;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,eAAsB,UACrB,SACA,UAA4B,EAAE,QAAQ,QAAQ,OAAO,GACnC;CAClB,IAAI,SAAS,QAAQ;CACrB,IAAI,QAAQ,aAAa,KAAA,KAAa,WAAW,KAAA,GAChD,IAAI;EAEH,SAAS,kBAAkB,QAAQ,WAAW,YAC7C,QAAQ,KAAK,OAAO,CACrB;CACD,SAAS,OAAO;EACf,QAAQ,MAAM,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;CAGD,MAAM,QAAQ;EACb,KAAK,QAAQ;EACb,OAAO,QAAQ;EACf,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;EAC3B,GAAI,QAAQ,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC;EAC1C,GAAI,QAAQ,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;EACzC,GAAI,QAAQ,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;EACzC,GAAI,QAAQ,mBAAmB,EAAE,kBAAkB,KAAK,IAAI,CAAC;EAC7D,GAAI,QAAQ,UAAU,EAAE,SAAS,KAAK,IAAI,CAAC;EAC3C,GAAI,QAAQ,aAAa,EAAE,YAAY,KAAK,IAAI,CAAC;EACjD,GAAI,QAAQ,gBAAgB,EAAE,eAAe,KAAK,IAAI,CAAC;CACxD;CAEA,IAAI,QAAQ,MAAM;EAIjB,MAAM,MAAM,OAAO;GAClB,GAAG;GACH,aAAa,kBAAkB;GAC/B,aAAa;EACd,CAAC;EACD,WAAW,MAAM,SAAS,KACzB,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,KAAK,EAAE,GAAG;EAElD,OAAO,IAAI,OAAO,WACX,IACL,UAAU;GACV,QAAQ,MAAM,YAAY,KAAK,CAAC;GAChC,OAAO;EACR,CACD;CACD;CAIA,MAAM,MAAM,OAAO;EAClB,GAAG;EACH,aAAa,oBAAoB,kBAAkB,CAAC;EACpD,QAAQ;GACP,OAAO,YAAY,QAAQ,IAAI,OAAO;GACtC,OAAO,YAAY,QAAQ,KAAK,OAAO;GACvC,QAAQ,YAAY,QAAQ,MAAM,OAAO;EAC1C;CACD,CAAC;CAED,IAAI;EACH,MAAM,IAAI;EACV,OAAO;CACR,SAAS,OAAO;EACf,QAAQ,MAAM,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"cli-KFbKAyaH.mjs","names":[],"sources":["../src/deploy/cli.ts"],"sourcesContent":["/**\n * `gkm deploy`: the terminal around `deploy()`. CLI layer only.\n *\n * Everything that belongs to a person at a terminal lives here and nowhere\n * below it: prompting for a missing login (and storing it), printing progress,\n * and turning the outcome into an exit code. The deploy itself is the same\n * `deploy()` a host calls.\n */\n\nimport { formatError } from '../debug';\nimport { targetForProvider } from '../target/provider';\nimport { storedCredentials } from './credentials';\nimport { deploy } from './deploy';\nimport { terminalCredentials } from './terminal';\n\nexport interface DeployCliOptions {\n\t/** The project directory: `--cwd`, else where the command was run. */\n\tcwd: string;\n\t/** `--target`: where to deploy. Defaults to `deploy.default`. */\n\ttarget?: string;\n\t/** `--provider`, deprecated: `dokploy` means `--target dokploy`. */\n\tprovider?: string;\n\tstage: string;\n\ttag?: string;\n\t/**\n\t * Print each event as one JSON object per line on stdout, instead of the\n\t * progress lines. Nothing prompts: a missing credential fails the run.\n\t */\n\tjson?: boolean;\n\t/** Plan only: create, change, build and push nothing. */\n\tdryRun?: boolean;\n\t/** On a failed release, roll back every app, not only the failed ones. */\n\tatomic?: boolean;\n\t/** `--allow-dev-services`. */\n\tallowDevServices?: boolean;\n\t/** `--skip-dns`. */\n\tskipDns?: boolean;\n\t/** `--rotate-keys`. */\n\trotateKeys?: boolean;\n\t/** `--retire-old-keys`. */\n\tretireOldKeys?: boolean;\n}\n\n/** Where the command writes. The process's own streams, outside tests. */\nexport interface DeployCliStreams {\n\tstdout: Pick<NodeJS.WriteStream, 'write'>;\n}\n\n/**\n * Run `gkm deploy` and resolve with its exit code: 0 when the run finished,\n * 1 when anything stopped it.\n */\nexport async function deployCli(\n\toptions: DeployCliOptions,\n\tstreams: DeployCliStreams = { stdout: process.stdout },\n): Promise<number> {\n\tlet target = options.target;\n\tif (options.provider !== undefined && target === undefined) {\n\t\ttry {\n\t\t\t// On stderr, so a `--json` run's stdout still carries only events.\n\t\t\ttarget = targetForProvider(options.provider, (message) =>\n\t\t\t\tconsole.warn(message),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(formatError(error));\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tconst input = {\n\t\tcwd: options.cwd,\n\t\tstage: options.stage,\n\t\t...(target ? { target } : {}),\n\t\t...(options.tag ? { tag: options.tag } : {}),\n\t\t...(options.dryRun ? { dryRun: true } : {}),\n\t\t...(options.atomic ? { atomic: true } : {}),\n\t\t...(options.allowDevServices ? { allowDevServices: true } : {}),\n\t\t...(options.skipDns ? { skipDns: true } : {}),\n\t\t...(options.rotateKeys ? { rotateKeys: true } : {}),\n\t\t...(options.retireOldKeys ? { retireOldKeys: true } : {}),\n\t};\n\n\tif (options.json) {\n\t\t// stdout carries the events and nothing else: docker's own output goes\n\t\t// to stderr, and nobody is asked anything — a prompt would be written\n\t\t// into the stream a program is parsing.\n\t\tconst run = deploy({\n\t\t\t...input,\n\t\t\tcredentials: storedCredentials(),\n\t\t\tchildOutput: 'stderr',\n\t\t});\n\t\tfor await (const event of run) {\n\t\t\tstreams.stdout.write(`${JSON.stringify(event)}\\n`);\n\t\t}\n\t\treturn run.result.then(\n\t\t\t() => 0,\n\t\t\t(error) => {\n\t\t\t\tconsole.error(formatError(error));\n\t\t\t\treturn 1;\n\t\t\t},\n\t\t);\n\t}\n\n\t// The lines arrive as they are written, rather than as events read back a\n\t// tick later, so they interleave with a prompt exactly as they always did.\n\tconst run = deploy({\n\t\t...input,\n\t\tcredentials: terminalCredentials(storedCredentials()),\n\t\tlogger: {\n\t\t\tinfo: (message) => console.log(message),\n\t\t\twarn: (message) => console.warn(message),\n\t\t\terror: (message) => console.error(message),\n\t\t},\n\t});\n\n\ttry {\n\t\tawait run.result;\n\t\treturn 0;\n\t} catch (error) {\n\t\tconsole.error(formatError(error));\n\t\treturn 1;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,eAAsB,UACrB,SACA,UAA4B,EAAE,QAAQ,QAAQ,OAAO,GACnC;CAClB,IAAI,SAAS,QAAQ;CACrB,IAAI,QAAQ,aAAa,KAAA,KAAa,WAAW,KAAA,GAChD,IAAI;EAEH,SAAS,kBAAkB,QAAQ,WAAW,YAC7C,QAAQ,KAAK,OAAO,CACrB;CACD,SAAS,OAAO;EACf,QAAQ,MAAM,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;CAGD,MAAM,QAAQ;EACb,KAAK,QAAQ;EACb,OAAO,QAAQ;EACf,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;EAC3B,GAAI,QAAQ,MAAM,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC;EAC1C,GAAI,QAAQ,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;EACzC,GAAI,QAAQ,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;EACzC,GAAI,QAAQ,mBAAmB,EAAE,kBAAkB,KAAK,IAAI,CAAC;EAC7D,GAAI,QAAQ,UAAU,EAAE,SAAS,KAAK,IAAI,CAAC;EAC3C,GAAI,QAAQ,aAAa,EAAE,YAAY,KAAK,IAAI,CAAC;EACjD,GAAI,QAAQ,gBAAgB,EAAE,eAAe,KAAK,IAAI,CAAC;CACxD;CAEA,IAAI,QAAQ,MAAM;EAIjB,MAAM,MAAM,OAAO;GAClB,GAAG;GACH,aAAa,kBAAkB;GAC/B,aAAa;EACd,CAAC;EACD,WAAW,MAAM,SAAS,KACzB,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,KAAK,EAAE,GAAG;EAElD,OAAO,IAAI,OAAO,WACX,IACL,UAAU;GACV,QAAQ,MAAM,YAAY,KAAK,CAAC;GAChC,OAAO;EACR,CACD;CACD;CAIA,MAAM,MAAM,OAAO;EAClB,GAAG;EACH,aAAa,oBAAoB,kBAAkB,CAAC;EACpD,QAAQ;GACP,OAAO,YAAY,QAAQ,IAAI,OAAO;GACtC,OAAO,YAAY,QAAQ,KAAK,OAAO;GACvC,QAAQ,YAAY,QAAQ,MAAM,OAAO;EAC1C;CACD,CAAC;CAED,IAAI;EACH,MAAM,IAAI;EACV,OAAO;CACR,SAAS,OAAO;EACf,QAAQ,MAAM,YAAY,KAAK,CAAC;EAChC,OAAO;CACR;AACD"}
@@ -1,14 +1,14 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
2
2
  import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
3
- import { F as toEmbeddableSecrets, M as initStageSecrets, Q as imageRef, a as findRootDomain, m as createComposeState, o as normalizeDnsConfig, ot as run, st as runOutput, v as recordRelease } from "./credentials-wid61zD2.mjs";
3
+ import { F as toEmbeddableSecrets, M as initStageSecrets, Q as imageRef, a as findRootDomain, m as createComposeState, o as normalizeDnsConfig, ot as run, st as runOutput, v as recordRelease } from "./credentials-DY_Cu5Ht.mjs";
4
4
  import { L as resolveStageTelemetry, ct as ComposeTlsFileMissing, gt as SERVER_IPV4_KEY, yt as isReservedStageKey } from "./workspace-DFGsrjGD.mjs";
5
- import { B as findBuildRoot, C as ensureLocalCertificate, Dt as stageEnv, E as readLocalAuthority, F as imageLayout, Lt as usesTelemetry, P as fromBuildRoot, S as ensureLocalAuthority, St as postgresStatements, T as localCertificateNames, Tt as envFor, Y as nextPrerenderManifest, _t as applyPolicies, b as bucketClient, ct as BACKUPS_SERVICE, d as backendsOf, dt as backupsRoleStatements, f as constructGlobs, gt as applyNotifications, ht as applyLifecycles, l as workerEnvKeys, mt as applyBuckets, t as appEnvKeys, v as LEGACY_LOCAL_LOGIN, vt as applyPostgres, x as pgClient, y as ensurePostgresLogin } from "./apps-BBo5-LK0.mjs";
5
+ import { C as ensureLocalCertificate, Dt as envFor, E as readLocalAuthority, F as imageLayout, H as findBuildRoot, P as fromBuildRoot, S as ensureLocalAuthority, T as localCertificateNames, Z as nextPrerenderManifest, _t as applyLifecycles, b as bucketClient, bt as applyPostgres, d as backendsOf, f as constructGlobs, gt as applyBuckets, kt as stageEnv, l as workerEnvKeys, pt as backupsRoleStatements, t as appEnvKeys, ut as BACKUPS_SERVICE, v as LEGACY_LOCAL_LOGIN, vt as applyNotifications, wt as postgresStatements, x as pgClient, y as ensurePostgresLogin, yt as applyPolicies, zt as usesTelemetry } from "./apps-C0kZVQpf.mjs";
6
6
  import { t as defineTarget } from "./define-6poNqm5O.mjs";
7
- import { E as withRedisPassword, W as primaryPortKey, X as LOGS_SERVICE, Z as logsAccess, m as loadLocalCredentials, tt as withLogsPassword, w as runsRedis, x as REDIS_SERVICE, y as withGeneratedSecrets } from "./compose-DDJhIyfw.mjs";
7
+ import { E as withRedisPassword, W as primaryPortKey, X as LOGS_SERVICE, Z as logsAccess, m as loadLocalCredentials, tt as withLogsPassword, w as runsRedis, x as REDIS_SERVICE, y as withGeneratedSecrets } from "./compose-D8fn0ebx.mjs";
8
8
  import { i as discover } from "./discover-DbDrCQ8h.mjs";
9
- import { C as traefikStaticFile, E as assertImagesExist, O as pinImages, S as readEdgeClaims, T as RegistryRequired, _ as EDGE_NETWORK, a as composeProject, b as claimsOverlap, d as stackDir, g as EDGE_DYNAMIC_DIR, h as EDGE_CERTS_DIR, i as LOOPBACK_SERVICES, l as envFile, m as EDGE_AWS_CREDENTIALS, n as LOGS_PORT_ENV, o as composeStack, p as withCaddyConfigs, r as LOG_ROTATION, t as EDGE_PORT_ENV, u as replicaNames, v as EDGE_PROJECT, x as edgeComposeFile, y as EDGE_SERVICE } from "./stack-DyKwnVrO.mjs";
10
- import { a as ensureDockerignore } from "./docker-MENEje7d.mjs";
11
- import { a as subscriptionKey, c as HostNotPointingAtServer, f as requiredServerAddress, g as stageDns, h as stackHosts, i as recordedPushSubscriptions, n as SUBSCRIPTION_TYPE, o as subscriptionResource, p as serverAddressHint, r as confirmPendingSubscriptions, s as topicConnection, t as PushSubscriptionsUnconfirmed, u as isLocalHost, v as systemLookup } from "./snsSubscriptions-Cp7doA_C.mjs";
9
+ import { C as traefikStaticFile, E as assertImagesExist, O as pinImages, S as readEdgeClaims, T as RegistryRequired, _ as EDGE_NETWORK, a as composeProject, b as claimsOverlap, d as stackDir, g as EDGE_DYNAMIC_DIR, h as EDGE_CERTS_DIR, i as LOOPBACK_SERVICES, l as envFile, m as EDGE_AWS_CREDENTIALS, n as LOGS_PORT_ENV, o as composeStack, p as withCaddyConfigs, r as LOG_ROTATION, t as EDGE_PORT_ENV, u as replicaNames, v as EDGE_PROJECT, x as edgeComposeFile, y as EDGE_SERVICE } from "./stack-ZV2le8OB.mjs";
10
+ import { a as ensureDockerignore } from "./docker-CobK4rVH.mjs";
11
+ import { a as subscriptionKey, c as HostNotPointingAtServer, f as requiredServerAddress, g as stageDns, h as stackHosts, i as recordedPushSubscriptions, n as SUBSCRIPTION_TYPE, o as subscriptionResource, p as serverAddressHint, r as confirmPendingSubscriptions, s as topicConnection, t as PushSubscriptionsUnconfirmed, u as isLocalHost, v as systemLookup } from "./snsSubscriptions-CtOrP15M.mjs";
12
12
  import { i as installedFrom } from "./drivers-uxLBq3e3.mjs";
13
13
  import { a as dnsResources, c as currentActor, d as DeployJournal, n as reportDatabaseRuns, o as forgetDnsResource, r as reportPlannedSeeds, s as recordDnsChanges, t as DeploySeedsFailed } from "./seeds-BCC8vAXR.mjs";
14
14
  import { f as plannedSeeds, o as SeedFailed, p as seedDatabases, u as migrateDatabases } from "./databases-mzSUFBTw.mjs";
@@ -1566,6 +1566,24 @@ var EdgePortInvalid = class extends GkmError {
1566
1566
  this.name = "EdgePortInvalid";
1567
1567
  }
1568
1568
  };
1569
+ /**
1570
+ * A site that pre-renders against its stage (`prerender: 'stage'`) whose
1571
+ * APIs do not answer, so it is not built: pages built without their data
1572
+ * would ship, and nothing at runtime could fill them.
1573
+ */
1574
+ var SitePrerenderApisDown = class extends GkmError {
1575
+ site;
1576
+ apis;
1577
+ via;
1578
+ constructor(site, apis, via) {
1579
+ const lines = apis.map(({ app, url, last }) => via === "docker" ? ` - ${app}: Docker reports it ${last}` : ` - ${url}: ${last}`).join("\n");
1580
+ super(`'${site}' pre-renders from its stage's APIs (prerender: 'stage'), and ${apis.length === 1 ? "this one does" : "these do"} not answer, so it was not built:\n${lines}\n` + (via === "push" ? "An image pushed for it is built against the stage as it runs now: deploy the stage first, then build and push the site." : "Fix the API and deploy again."));
1581
+ this.site = site;
1582
+ this.apis = apis;
1583
+ this.via = via;
1584
+ this.name = "SitePrerenderApisDown";
1585
+ }
1586
+ };
1569
1587
  /** A build with no commit to tag its images with. */
1570
1588
  var NoGitRevision = class extends GkmError {
1571
1589
  root;
@@ -1677,7 +1695,8 @@ async function validateCompose(ctx, deps, options = {}) {
1677
1695
  allowDevServices: ctx.allowDevServices,
1678
1696
  ports: edgePorts(deps.env),
1679
1697
  ...layout ? { layout } : {},
1680
- ...push ? { buildOnly: true } : {}
1698
+ ...push ? { buildOnly: true } : {},
1699
+ ...mode === "build" ? { prerenderRun: (/* @__PURE__ */ new Date()).toISOString() } : {}
1681
1700
  };
1682
1701
  const recordedArns = recordedPushSubscriptions(recorded?.resources);
1683
1702
  const planned = push ? void 0 : composeStack({
@@ -2302,14 +2321,27 @@ async function buildCompose(ctx, run, deps) {
2302
2321
  run.files = await writeStack(ctx.cwd, run.dir, stack);
2303
2322
  printPlan(ctx, run);
2304
2323
  }
2324
+ const prerendered = prerenderedHere(run);
2325
+ if (run.push) await stageAnswers(ctx, run, deps, prerendered);
2326
+ const held = new Set(run.push ? [] : prerendered.map(({ app }) => app));
2327
+ const now = images.filter((image) => !held.has(image.app));
2305
2328
  if (run.mode === "build") {
2306
2329
  ctx.logger.info("\n🐳 Building images…");
2307
- await deps.docker.build(ref, apps);
2330
+ await deps.docker.build(ref, now.map((image) => image.app));
2308
2331
  } else {
2309
2332
  ctx.logger.info(`\n🐳 Pulling ${ctx.tag}…`);
2310
2333
  await deps.docker.pull(ref, apps);
2311
2334
  }
2312
2335
  if (run.push) ctx.logger.info("\n📤 Pushing images…");
2336
+ await recordBuilt(ctx, run, deps, now);
2337
+ }
2338
+ /**
2339
+ * Each image's tag as it resolved — the registry's digest for a pushed or
2340
+ * pulled image, or, for one built here and never pushed, its content id —
2341
+ * in the run, and said.
2342
+ */
2343
+ async function recordBuilt(ctx, run, deps, images) {
2344
+ const { ref } = run;
2313
2345
  for (const image of images) {
2314
2346
  const digest = run.push ? await deps.docker.push(ref, image.ref) : await deps.docker.digest(ref, image.ref);
2315
2347
  if (run.push) ctx.logger.info(` ${image.app.padEnd(12)} ${image.ref}@${digest}`);
@@ -2347,6 +2379,8 @@ async function releaseCompose(ctx, run, deps) {
2347
2379
  const written = await writeEdgeRoutes(deps.docker, edge, stack.project, stack.traefik, await edgeCertificate(run.dir, stack));
2348
2380
  ctx.logger.info(`🌐 Registered ${stack.routes.length} route(s) with ${EDGE_PROJECT}: ${written.at(-1)}`);
2349
2381
  } else if (!stack.local || existsSync(edgeFile(run))) await removeEdgeRoutes(deps.docker, edge, stack.project);
2382
+ const prerendered = prerenderedHere(run);
2383
+ if (prerendered.length > 0) await buildAgainstStage(ctx, run, deps, prerendered);
2350
2384
  ctx.logger.info("\n🚀 Starting the stack…");
2351
2385
  const down = await deps.docker.up(ref).then(() => [], (error) => unhealthyAfterUp(ctx, run, deps, error));
2352
2386
  const isDown = new Set(down.map(({ app }) => app));
@@ -2403,13 +2437,13 @@ async function releaseCompose(ctx, run, deps) {
2403
2437
  * as `--wait` stops at the first that is not. None means the failure was not
2404
2438
  * health's, and it is thrown as it was.
2405
2439
  */
2406
- async function unhealthyAfterUp(ctx, run, deps, error) {
2440
+ async function unhealthyAfterUp(ctx, run, deps, error, except = /* @__PURE__ */ new Set()) {
2407
2441
  const { stack } = run;
2408
2442
  const services = [
2409
2443
  ...stack.apps.flatMap(replicaNames),
2410
2444
  ...stack.workers.map((worker) => worker.name),
2411
2445
  ...stack.processors.map((unit) => unit.name)
2412
- ];
2446
+ ].filter((service) => !except.has(service));
2413
2447
  const down = (await Promise.all(services.map(async (service) => {
2414
2448
  let last;
2415
2449
  for (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {
@@ -2433,6 +2467,82 @@ async function unhealthyAfterUp(ctx, run, deps, error) {
2433
2467
  return down;
2434
2468
  }
2435
2469
  /**
2470
+ * Where a check through the edge connects: this machine for the local stage,
2471
+ * a deployed stage's server on its published port — or, for a push, which
2472
+ * has no server, wherever the host resolves.
2473
+ */
2474
+ function edgeTarget(run, deps) {
2475
+ if (run.stack.local) return { connectTo: "127.0.0.1" };
2476
+ if (run.server) return {
2477
+ connectTo: run.server.host,
2478
+ connectPort: edgePorts(deps.env).https
2479
+ };
2480
+ }
2481
+ /**
2482
+ * The sites this run builds against their stage's running APIs
2483
+ * (`prerender: 'stage'`). None for a run that pulls: a pulled image was built
2484
+ * against the stage when it was pushed.
2485
+ */
2486
+ function prerenderedHere(run) {
2487
+ if (run.mode !== "build") return [];
2488
+ return run.stack.apps.filter((app) => app.prerender && app.build);
2489
+ }
2490
+ /**
2491
+ * A site that pre-renders against its stage, built once its APIs answer:
2492
+ * every service of the stack started but those sites — `up --wait`, so each
2493
+ * is healthy by its own check — then each API the site depends on asked
2494
+ * through the edge, as a browser reaches it, and only then the site built.
2495
+ * The full `up` that follows starts it.
2496
+ */
2497
+ async function buildAgainstStage(ctx, run, deps, sites) {
2498
+ const { stack, ref } = run;
2499
+ const held = new Set(sites.flatMap(replicaNames));
2500
+ const services = Object.keys(stack.compose.services).filter((service) => !held.has(service));
2501
+ ctx.logger.info(`\n🚀 Starting the stack, but ${listNames(sites)}, built once its APIs answer…`);
2502
+ const down = await deps.docker.up(ref, services).then(() => [], (error) => unhealthyAfterUp(ctx, run, deps, error, held));
2503
+ for (const site of sites) {
2504
+ const against = new Set(site.prerender?.against);
2505
+ const blocking = down.filter(({ app }) => against.has(app));
2506
+ if (blocking.length > 0) throw new SitePrerenderApisDown(site.name, blocking, "docker");
2507
+ }
2508
+ await stageAnswers(ctx, run, deps, sites);
2509
+ ctx.logger.info(`\n🐳 Building ${listNames(sites)} against the stage's APIs…`);
2510
+ await deps.docker.build(ref, sites.map((site) => site.app));
2511
+ await recordBuilt(ctx, run, deps, sites);
2512
+ }
2513
+ /** `web` — or `docs and web`. */
2514
+ function listNames(apps) {
2515
+ const names = apps.map(({ name }) => name);
2516
+ return names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names[0] ?? "";
2517
+ }
2518
+ /**
2519
+ * Each API a site pre-rendered against its stage depends on, asked through
2520
+ * the edge as `verify` asks it — the address the site's build fetches from.
2521
+ * Any that does not answer fails the run before the site is built: a build
2522
+ * that cannot reach them bakes in pages without their data.
2523
+ */
2524
+ async function stageAnswers(ctx, run, deps, sites) {
2525
+ const { stack } = run;
2526
+ const names = new Set(sites.flatMap((site) => site.prerender?.against ?? []));
2527
+ const apps = stack.apps.filter((app) => names.has(app.name));
2528
+ if (apps.length === 0) return;
2529
+ ctx.logger.info(`\n🩺 Checking the APIs ${listNames(sites)} ${sites.length > 1 ? "pre-render" : "pre-renders"} from…`);
2530
+ const ca = await verifyAuthority(stack);
2531
+ const edge = edgeTarget(run, deps);
2532
+ const results = await Promise.all(apps.map((app) => app.id === stack.wildcard?.site && !run.push ? checkContainer(ctx, run, deps, app.name) : checkApp(ctx, app, deps, {
2533
+ ca,
2534
+ edge
2535
+ })));
2536
+ const down = new Map(results.filter((r) => !r.healthy).map((r) => [r.app, r]));
2537
+ for (const site of sites) {
2538
+ const blocking = (site.prerender?.against ?? []).flatMap((name) => {
2539
+ const result = down.get(name);
2540
+ return result ? [result] : [];
2541
+ });
2542
+ if (blocking.length > 0) throw new SitePrerenderApisDown(site.name, blocking, run.push ? "push" : "edge");
2543
+ }
2544
+ }
2545
+ /**
2436
2546
  * Each app's image in the stage's state — the same `images` a Dokploy deploy
2437
2547
  * records: the ref it runs, the tag it was released under, and the digest
2438
2548
  * the tag resolved to.
@@ -2465,10 +2575,7 @@ async function verifyCompose(ctx, run, deps) {
2465
2575
  if (run.push) return;
2466
2576
  const ca = await verifyAuthority(stack);
2467
2577
  ctx.logger.info(`\n🩺 Checking each app through ${stack.proxy === "caddy" ? "Caddy" : "the shared edge"}…`);
2468
- const edge = stack.local ? { connectTo: "127.0.0.1" } : run.server ? {
2469
- connectTo: run.server.host,
2470
- connectPort: edgePorts(deps.env).https
2471
- } : void 0;
2578
+ const edge = edgeTarget(run, deps);
2472
2579
  const results = await Promise.all(stack.apps.map((app) => app.id === stack.wildcard?.site ? checkContainer(ctx, run, deps, app.name) : checkApp(ctx, app, deps, {
2473
2580
  ca,
2474
2581
  edge
@@ -2897,8 +3004,12 @@ function printPlan(ctx, run) {
2897
3004
  * - `provision`: generated secrets kept, files written, infrastructure up,
2898
3005
  * databases, roles, grants and migrations
2899
3006
  * - `build`: each backend bundled on the host and every image built — or, for
2900
- * a tag, pulled
2901
- * - `release`: the stack's routes on the shared edge, then `up --wait
3007
+ * a tag, pulled. A site that pre-renders against its stage
3008
+ * (`prerender: 'stage'`) is held back, but for a push, which first asks the
3009
+ * running stage's APIs and builds it against them
3010
+ * - `release`: the stack's routes on the shared edge; a held-back site built
3011
+ * once the rest of the stack is up and its APIs answer through the edge;
3012
+ * then `up --wait
2902
3013
  * --remove-orphans`, and each app's image, tag and digest in the stage's
2903
3014
  * state — an app that never turns healthy fails it only once the rest is
2904
3015
  * released and routed
@@ -2954,4 +3065,4 @@ function composeTarget(options = {}) {
2954
3065
  //#endregion
2955
3066
  export { edgePorts as a, edgeRef as c, dockerHost as d, sshAccess as f, projectNetwork as h, ComposePushNeedsBuild as i, removeEdgeRoutes as l, dockerCompose as m, compose_exports as n, stackOverrideFile as o, sshTarget as p, ComposePinNeedsPull as r, deployedStackSecrets as s, composeTarget as t, composeServer as u };
2956
3067
 
2957
- //# sourceMappingURL=compose-DSBTDhk5.mjs.map
3068
+ //# sourceMappingURL=compose-C-k9AoH0.mjs.map