@velastack/patterns 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/chunks/{collections-DMdTP6H_.js → collections-B_-NTtLW.js} +2 -2
  2. package/dist/chunks/{collections-DMdTP6H_.js.map → collections-B_-NTtLW.js.map} +1 -1
  3. package/dist/chunks/{constants-Bo85Ke0C.js → constants-CTp-0HKk.js} +18 -28
  4. package/dist/chunks/{constants-Bo85Ke0C.js.map → constants-CTp-0HKk.js.map} +1 -1
  5. package/dist/chunks/{currency.server-CNc9ASqB.js → currency.server-DOX4Rzyb.js} +2 -2
  6. package/dist/chunks/{currency.server-CNc9ASqB.js.map → currency.server-DOX4Rzyb.js.map} +1 -1
  7. package/dist/chunks/{env-vars-ZzWTCtYk.js → env-vars-BbS_mWyP.js} +3 -3
  8. package/dist/chunks/{env-vars-ZzWTCtYk.js.map → env-vars-BbS_mWyP.js.map} +1 -1
  9. package/dist/chunks/{generate-DiKYcuxK.js → generate-4iujJNAW.js} +3 -3
  10. package/dist/chunks/{generate-DiKYcuxK.js.map → generate-4iujJNAW.js.map} +1 -1
  11. package/dist/chunks/{generate-CpWYpXme.js → generate-B4uDCW5D.js} +2 -2
  12. package/dist/chunks/{generate-CpWYpXme.js.map → generate-B4uDCW5D.js.map} +1 -1
  13. package/dist/chunks/{generate-vSMSfoEL.js → generate-BJY8AtAp.js} +2 -2
  14. package/dist/chunks/{generate-vSMSfoEL.js.map → generate-BJY8AtAp.js.map} +1 -1
  15. package/dist/chunks/{generate-DPR1uuZM.js → generate-Bwkx_usZ.js} +2 -2
  16. package/dist/chunks/{generate-DPR1uuZM.js.map → generate-Bwkx_usZ.js.map} +1 -1
  17. package/dist/chunks/{generate-JcPcxodU.js → generate-JkvSNTy-.js} +2 -2
  18. package/dist/chunks/{generate-JcPcxodU.js.map → generate-JkvSNTy-.js.map} +1 -1
  19. package/dist/chunks/{generate.runtime-DMhsz52A.js → generate.runtime-27KTIg_o.js} +3 -3
  20. package/dist/chunks/{generate.runtime-DMhsz52A.js.map → generate.runtime-27KTIg_o.js.map} +1 -1
  21. package/dist/chunks/{generate.runtime-Czu9sahf.js → generate.runtime-B7XOa9_A.js} +3 -3
  22. package/dist/chunks/{generate.runtime-Czu9sahf.js.map → generate.runtime-B7XOa9_A.js.map} +1 -1
  23. package/dist/chunks/{generate.runtime-CTAAJJr6.js → generate.runtime-B8-ORwxT.js} +6 -6
  24. package/dist/chunks/{generate.runtime-CTAAJJr6.js.map → generate.runtime-B8-ORwxT.js.map} +1 -1
  25. package/dist/chunks/{generate.runtime-CZaJ7Uud.js → generate.runtime-BFX_8erf.js} +6 -6
  26. package/dist/chunks/{generate.runtime-CZaJ7Uud.js.map → generate.runtime-BFX_8erf.js.map} +1 -1
  27. package/dist/chunks/{generate.runtime-BbyC1DMB.js → generate.runtime-BROXlbeJ.js} +3 -3
  28. package/dist/chunks/{generate.runtime-BbyC1DMB.js.map → generate.runtime-BROXlbeJ.js.map} +1 -1
  29. package/dist/chunks/{generate.runtime-BBjaUxGz.js → generate.runtime-BU-4sjyu.js} +4 -4
  30. package/dist/chunks/{generate.runtime-BBjaUxGz.js.map → generate.runtime-BU-4sjyu.js.map} +1 -1
  31. package/dist/chunks/{generate.runtime-Dw6umCTf.js → generate.runtime-BXNBWGYr.js} +2 -2
  32. package/dist/chunks/{generate.runtime-Dw6umCTf.js.map → generate.runtime-BXNBWGYr.js.map} +1 -1
  33. package/dist/chunks/{generate.runtime-DD3OVUB5.js → generate.runtime-BlEy2fFF.js} +3 -3
  34. package/dist/chunks/{generate.runtime-DD3OVUB5.js.map → generate.runtime-BlEy2fFF.js.map} +1 -1
  35. package/dist/chunks/{generate.runtime-Jzkg3tWq.js → generate.runtime-CBVcsole.js} +2 -2
  36. package/dist/chunks/{generate.runtime-Jzkg3tWq.js.map → generate.runtime-CBVcsole.js.map} +1 -1
  37. package/dist/chunks/{generate.runtime-Bna36DjV.js → generate.runtime-CCaCaXNu.js} +2 -2
  38. package/dist/chunks/{generate.runtime-Bna36DjV.js.map → generate.runtime-CCaCaXNu.js.map} +1 -1
  39. package/dist/chunks/{generate.runtime-CkqBNJmH.js → generate.runtime-Cm75waRD.js} +2 -2
  40. package/dist/chunks/{generate.runtime-CkqBNJmH.js.map → generate.runtime-Cm75waRD.js.map} +1 -1
  41. package/dist/chunks/{generate.runtime-D7SysNQ9.js → generate.runtime-CuvdtjKc.js} +2 -2
  42. package/dist/chunks/{generate.runtime-D7SysNQ9.js.map → generate.runtime-CuvdtjKc.js.map} +1 -1
  43. package/dist/chunks/{generate.runtime-VXM0eG6V.js → generate.runtime-D0lI3Gt8.js} +4 -4
  44. package/dist/chunks/{generate.runtime-VXM0eG6V.js.map → generate.runtime-D0lI3Gt8.js.map} +1 -1
  45. package/dist/chunks/{generate.runtime-TPgoAXWD.js → generate.runtime-D6l6uLiY.js} +2 -2
  46. package/dist/chunks/{generate.runtime-TPgoAXWD.js.map → generate.runtime-D6l6uLiY.js.map} +1 -1
  47. package/dist/chunks/{generate.runtime-CsfHtEy3.js → generate.runtime-D77ueFKY.js} +5 -5
  48. package/dist/chunks/{generate.runtime-CsfHtEy3.js.map → generate.runtime-D77ueFKY.js.map} +1 -1
  49. package/dist/chunks/{generate.runtime-BufPbKvb.js → generate.runtime-D9OC1RXu.js} +2 -2
  50. package/dist/chunks/{generate.runtime-BufPbKvb.js.map → generate.runtime-D9OC1RXu.js.map} +1 -1
  51. package/dist/chunks/{generate.runtime-CU1Gec33.js → generate.runtime-DLoYscQO.js} +3 -3
  52. package/dist/chunks/{generate.runtime-CU1Gec33.js.map → generate.runtime-DLoYscQO.js.map} +1 -1
  53. package/dist/chunks/{generate.runtime-D50A0Jkc.js → generate.runtime-DhSH1o8H.js} +3 -3
  54. package/dist/chunks/{generate.runtime-D50A0Jkc.js.map → generate.runtime-DhSH1o8H.js.map} +1 -1
  55. package/dist/chunks/{generate.runtime-BSKontB4.js → generate.runtime-DiEiFoxR.js} +3 -3
  56. package/dist/chunks/{generate.runtime-BSKontB4.js.map → generate.runtime-DiEiFoxR.js.map} +1 -1
  57. package/dist/chunks/{generate.runtime-DHFjipkv.js → generate.runtime-Dm7IEo2h.js} +3 -3
  58. package/dist/chunks/{generate.runtime-DHFjipkv.js.map → generate.runtime-Dm7IEo2h.js.map} +1 -1
  59. package/dist/chunks/{generate.runtime-B-FbahJY.js → generate.runtime-Dn0_y2iV.js} +4 -4
  60. package/dist/chunks/{generate.runtime-B-FbahJY.js.map → generate.runtime-Dn0_y2iV.js.map} +1 -1
  61. package/dist/chunks/{generate.runtime-vr8Tp4dr.js → generate.runtime-DuAYqKxl.js} +2 -2
  62. package/dist/chunks/{generate.runtime-vr8Tp4dr.js.map → generate.runtime-DuAYqKxl.js.map} +1 -1
  63. package/dist/chunks/{generate.runtime-C8vGwunw.js → generate.runtime-Duw_JI_b.js} +2 -2
  64. package/dist/chunks/{generate.runtime-C8vGwunw.js.map → generate.runtime-Duw_JI_b.js.map} +1 -1
  65. package/dist/chunks/{generate.runtime-B2TQboJB.js → generate.runtime-DxyQqNpu.js} +4 -4
  66. package/dist/chunks/{generate.runtime-B2TQboJB.js.map → generate.runtime-DxyQqNpu.js.map} +1 -1
  67. package/dist/chunks/{generate.runtime-CDQ3bnRi.js → generate.runtime-PDnSxiek.js} +6 -6
  68. package/dist/chunks/{generate.runtime-CDQ3bnRi.js.map → generate.runtime-PDnSxiek.js.map} +1 -1
  69. package/dist/chunks/{generate.runtime-DL16fW78.js → generate.runtime-RTGpwxcS.js} +5 -5
  70. package/dist/chunks/{generate.runtime-DL16fW78.js.map → generate.runtime-RTGpwxcS.js.map} +1 -1
  71. package/dist/chunks/{generate.runtime-CSusmHj9.js → generate.runtime-TQmspB4Z.js} +4 -4
  72. package/dist/chunks/{generate.runtime-CSusmHj9.js.map → generate.runtime-TQmspB4Z.js.map} +1 -1
  73. package/dist/chunks/{generate.runtime-opwafU4k.js → generate.runtime-UtkANHk1.js} +3 -3
  74. package/dist/chunks/{generate.runtime-opwafU4k.js.map → generate.runtime-UtkANHk1.js.map} +1 -1
  75. package/dist/chunks/{generate.runtime-BL78nWra.js → generate.runtime-VMTLHWLk.js} +7 -7
  76. package/dist/chunks/{generate.runtime-BL78nWra.js.map → generate.runtime-VMTLHWLk.js.map} +1 -1
  77. package/dist/chunks/{generate.runtime-pjRWIwSm.js → generate.runtime-XT_JQlTk.js} +2 -2
  78. package/dist/chunks/{generate.runtime-pjRWIwSm.js.map → generate.runtime-XT_JQlTk.js.map} +1 -1
  79. package/dist/chunks/{generate.runtime-BB2GGj4d.js → generate.runtime-XpYi9SlM.js} +2 -2
  80. package/dist/chunks/{generate.runtime-BB2GGj4d.js.map → generate.runtime-XpYi9SlM.js.map} +1 -1
  81. package/dist/chunks/{generate.runtime-DStnhncj.js → generate.runtime-ZgLxGWuy.js} +3 -3
  82. package/dist/chunks/{generate.runtime-DStnhncj.js.map → generate.runtime-ZgLxGWuy.js.map} +1 -1
  83. package/dist/chunks/{generate.runtime-D50lIHIY.js → generate.runtime-bsuqrKOm.js} +2 -2
  84. package/dist/chunks/{generate.runtime-D50lIHIY.js.map → generate.runtime-bsuqrKOm.js.map} +1 -1
  85. package/dist/chunks/{generate.runtime-CPWxn8rh.js → generate.runtime-nXjFqHyb.js} +4 -4
  86. package/dist/chunks/{generate.runtime-CPWxn8rh.js.map → generate.runtime-nXjFqHyb.js.map} +1 -1
  87. package/dist/chunks/{generate.runtime-BPnFkMKl.js → generate.runtime-sjFAWbZc.js} +6 -6
  88. package/dist/chunks/{generate.runtime-BPnFkMKl.js.map → generate.runtime-sjFAWbZc.js.map} +1 -1
  89. package/dist/chunks/{generate.runtime-7QPUM9c3.js → generate.runtime-wiWdXXPi.js} +4 -4
  90. package/dist/chunks/{generate.runtime-7QPUM9c3.js.map → generate.runtime-wiWdXXPi.js.map} +1 -1
  91. package/dist/chunks/{i18n-D8hsUX_P.js → i18n-mnzzcYhz.js} +2 -2
  92. package/dist/chunks/{i18n-D8hsUX_P.js.map → i18n-mnzzcYhz.js.map} +1 -1
  93. package/dist/chunks/{modify-file-CoFH_Y5n.js → modify-file-CgJIza72.js} +2 -2
  94. package/dist/chunks/{modify-file-CoFH_Y5n.js.map → modify-file-CgJIza72.js.map} +1 -1
  95. package/dist/chunks/{pocketbase-BTLraFEp.js → pocketbase-S8lUt0nI.js} +2 -2
  96. package/dist/chunks/{pocketbase-BTLraFEp.js.map → pocketbase-S8lUt0nI.js.map} +1 -1
  97. package/dist/chunks/{providers-cp9IJLRl.js → providers-CDUFaOeQ.js} +2 -2
  98. package/dist/chunks/{providers-cp9IJLRl.js.map → providers-CDUFaOeQ.js.map} +1 -1
  99. package/dist/chunks/{shared-Be8NptJO.js → shared-BjTRQ5QH.js} +2 -2
  100. package/dist/chunks/{shared-Be8NptJO.js.map → shared-BjTRQ5QH.js.map} +1 -1
  101. package/dist/chunks/{site-BHCX2hbj.js → site-C8Wcg6LT.js} +2 -2
  102. package/dist/chunks/{site-BHCX2hbj.js.map → site-C8Wcg6LT.js.map} +1 -1
  103. package/dist/chunks/{table-core-JdtTKQKA.js → table-core-RvMjoXpT.js} +2 -2
  104. package/dist/chunks/{table-core-JdtTKQKA.js.map → table-core-RvMjoXpT.js.map} +1 -1
  105. package/dist/chunks/{test-setup-SleehT05.js → test-setup-CpjhQSl-.js} +3 -3
  106. package/dist/chunks/{test-setup-SleehT05.js.map → test-setup-CpjhQSl-.js.map} +1 -1
  107. package/dist/chunks/{ui-smOXuMsQ.js → ui-CE-8llQS.js} +3 -3
  108. package/dist/chunks/{ui-smOXuMsQ.js.map → ui-CE-8llQS.js.map} +1 -1
  109. package/dist/chunks/{whatsapp-qMxxv6e0.js → whatsapp-DT10x76l.js} +2 -2
  110. package/dist/chunks/{whatsapp-qMxxv6e0.js.map → whatsapp-DT10x76l.js.map} +1 -1
  111. package/dist/chunks/{write-result-DPM26sZ_.js → write-result-BguSfKV-.js} +4 -4
  112. package/dist/chunks/{write-result-DPM26sZ_.js.map → write-result-BguSfKV-.js.map} +1 -1
  113. package/dist/index.js +97 -97
  114. package/dist/index.js.map +1 -1
  115. package/package.json +3 -3
@@ -1,8 +1,8 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
2
  import { n as t } from "./env-AxyRWcC_.js";
3
- import { r as n, t as r } from "./modify-file-CoFH_Y5n.js";
4
- import { n as i, t as a } from "./generate-DPR1uuZM.js";
5
- import { unmodifyEnvVarsFiles as o } from "./env-vars-ZzWTCtYk.js";
3
+ import { r as n, t as r } from "./modify-file-CgJIza72.js";
4
+ import { n as i, t as a } from "./generate-Bwkx_usZ.js";
5
+ import { unmodifyEnvVarsFiles as o } from "./env-vars-BbS_mWyP.js";
6
6
  import { t as s } from "./svelte-file-DfplF3BU.js";
7
7
  import { _ as c, n as l, u } from "./ts-morph-helpers-B4KZXP44.js";
8
8
  import { r as d } from "./lib-specifier-C3M0WTev.js";
@@ -60,4 +60,4 @@ async function g(s) {
60
60
  }
61
61
  export { g as generate };
62
62
 
63
- //# sourceMappingURL=generate.runtime-CPWxn8rh.js.map
63
+ //# sourceMappingURL=generate.runtime-nXjFqHyb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-CPWxn8rh.js","names":["getLogger","modifyEnvRemove","modifyOutcomeToFile","envRevertOutcomeToFile","allEnvNames","allEnvEdits","SvelteFile","withInMemoryScript","ensureBlankLineAfterImports","libModule","fs","path","MODULE","unmodifyLayoutSvelte","layoutPath","original","file","out","source","removeImportByModuleSpecifier","sf","updated","generate","logger","options","modifies","deletes","pushResult","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/analytics/modifies/layout.svelte.ts","../../src/patterns/disable/analytics/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst MODULE = \"components/analytics/analytics.svelte\";\n\n/**\n * Takes `<Analytics />` and its import back out of the root layout. The\n * element goes with its whole line, since enable-analytics put it on one of\n * its own. A layout without it, or no layout at all, is left alone.\n */\nexport function unmodifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(MODULE) && !original.includes(\"<Analytics\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(sf, libModule(MODULE));\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(/[ \\t]*<Analytics\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyEnvRemove } from \"../../../runtime/env\";\nimport {\n envRevertOutcomeToFile,\n modifyOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { allEnvEdits, allEnvNames } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { unmodifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, unmodifyLayoutSvelte(layoutPath)));\n\n // Which provider was chosen is not recorded, so every one's variables go;\n // the file goes too when these were all it declared.\n logger.info(\"Removing analytics variables from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n pushResult(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing analytics variables from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n pushResult(env.modify);\n if (env.delete) deletes.push(env.delete);\n\n return {\n creates: [],\n modifies,\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAMY,IAAS;AAOf,SAAgBC,EAAqB,GAAmC;CACtE,IAAI,CAACH,EAAG,WAAWI,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWL,EAAG,aAAaI,GAAY,MAAM;CACnD,IAAI,CAACC,EAAS,SAASH,CAAM,KAAK,CAACG,EAAS,SAAS,YAAY,GAC/D,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOV,EAAW,SAASQ,CAAU;CAC3C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQG,MAAQV,EAAmBW,IAAS,MAAO;GAEzD,AADAC,EAA8BC,GAAIX,EAAUG,CAAM,CAAC,GACnDJ,EAA4BY,CAAE;EAChC,CAAC;EACD,OAAOH;CACT,CAAC;CAED,IAAMI,IAAUL,EACb,SAAS,CAAC,CACV,QAAQ,uCAAuC,EAAE;CAMpD,OAJIK,MAAYN,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAE7CL,EAAG,cAAcI,GAAYO,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;ACjCA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GACnBC,KAAc,MAAsB;EACxC,AAAIX,KAAMS,EAAS,KAAKT,CAAI;CAC9B;CAEA,EAAO,KAAK,qCAAqC;CACjD,IAAMF,IAAaH,EAAK,KAAKa,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAK5E,AAJAG,EAAWzB,EAAoBY,GAAYD,EAAqBC,CAAU,CAAC,CAAC,GAI5ES,EAAO,KAAK,8CAA8C;CAC1D,IAAMK,IAAUC,EAAqBL,EAAQ,MAAMpB,EAAY,CAAC;CAIhE,AAHAuB,EAAWC,EAAQ,MAAM,GACrBA,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAE/CL,EAAO,KAAK,wCAAwC;CACpD,IAAMO,IAAUnB,EAAK,KAAKa,EAAQ,MAAM,MAAM,GACxCO,IAAM5B,EACV2B,GACA7B,EAAgB6B,GAASzB,EAAY,CAAC,CACxC;CAIA,OAHAsB,EAAWI,EAAI,MAAM,GACjBA,EAAI,UAAQL,EAAQ,KAAKK,EAAI,MAAM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
1
+ {"version":3,"file":"generate.runtime-nXjFqHyb.js","names":["getLogger","modifyEnvRemove","modifyOutcomeToFile","envRevertOutcomeToFile","allEnvNames","allEnvEdits","SvelteFile","withInMemoryScript","ensureBlankLineAfterImports","libModule","fs","path","MODULE","unmodifyLayoutSvelte","layoutPath","original","file","out","source","removeImportByModuleSpecifier","sf","updated","generate","logger","options","modifies","deletes","pushResult","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/analytics/modifies/layout.svelte.ts","../../src/patterns/disable/analytics/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst MODULE = \"components/analytics/analytics.svelte\";\n\n/**\n * Takes `<Analytics />` and its import back out of the root layout. The\n * element goes with its whole line, since enable-analytics put it on one of\n * its own. A layout without it, or no layout at all, is left alone.\n */\nexport function unmodifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(MODULE) && !original.includes(\"<Analytics\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(sf, libModule(MODULE));\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(/[ \\t]*<Analytics\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyEnvRemove } from \"../../../runtime/env\";\nimport {\n envRevertOutcomeToFile,\n modifyOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { allEnvEdits, allEnvNames } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { unmodifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, unmodifyLayoutSvelte(layoutPath)));\n\n // Which provider was chosen is not recorded, so every one's variables go;\n // the file goes too when these were all it declared.\n logger.info(\"Removing analytics variables from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n pushResult(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing analytics variables from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n pushResult(env.modify);\n if (env.delete) deletes.push(env.delete);\n\n return {\n creates: [],\n modifies,\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAMY,IAAS;AAOf,SAAgBC,EAAqB,GAAmC;CACtE,IAAI,CAACH,EAAG,WAAWI,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWL,EAAG,aAAaI,GAAY,MAAM;CACnD,IAAI,CAACC,EAAS,SAASH,CAAM,KAAK,CAACG,EAAS,SAAS,YAAY,GAC/D,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOV,EAAW,SAASQ,CAAU;CAC3C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQG,MAAQV,EAAmBW,IAAS,MAAO;GAEzD,AADAC,EAA8BC,GAAIX,EAAUG,CAAM,CAAC,GACnDJ,EAA4BY,CAAE;EAChC,CAAC;EACD,OAAOH;CACT,CAAC;CAED,IAAMI,IAAUL,EACb,SAAS,CAAC,CACV,QAAQ,uCAAuC,EAAE;CAMpD,OAJIK,MAAYN,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAE7CL,EAAG,cAAcI,GAAYO,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;ACjCA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GACnBC,KAAc,MAAsB;EACxC,AAAIX,KAAMS,EAAS,KAAKT,CAAI;CAC9B;CAEA,EAAO,KAAK,qCAAqC;CACjD,IAAMF,IAAaH,EAAK,KAAKa,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAK5E,AAJAG,EAAWzB,EAAoBY,GAAYD,EAAqBC,CAAU,CAAC,CAAC,GAI5ES,EAAO,KAAK,8CAA8C;CAC1D,IAAMK,IAAUC,EAAqBL,EAAQ,MAAMpB,EAAY,CAAC;CAIhE,AAHAuB,EAAWC,EAAQ,MAAM,GACrBA,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAE/CL,EAAO,KAAK,wCAAwC;CACpD,IAAMO,IAAUnB,EAAK,KAAKa,EAAQ,MAAM,MAAM,GACxCO,IAAM5B,EACV2B,GACA7B,EAAgB6B,GAASzB,EAAY,CAAC,CACxC;CAIA,OAHAsB,EAAWI,EAAI,MAAM,GACjBA,EAAI,UAAQL,EAAQ,KAAKK,EAAI,MAAM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,13 +1,13 @@
1
1
  import { t as e } from "./errors-DdSUZI8f.js";
2
2
  import { n as t } from "./logger-t1HxmpG2.js";
3
- import { n } from "./constants-Bo85Ke0C.js";
3
+ import { n } from "./constants-CTp-0HKk.js";
4
4
  import { a as r, c as i, l as a } from "./providers-tjlFH5di.js";
5
5
  import { o } from "./config-target-DJbVHwHl.js";
6
6
  import { t as s } from "./env-AxyRWcC_.js";
7
- import { modifyEnvVarsFiles as c } from "./env-vars-ZzWTCtYk.js";
8
- import { r as l } from "./modify-file-CoFH_Y5n.js";
9
- import { c as u } from "./write-result-DPM26sZ_.js";
10
- import { n as d, s as f } from "./generate-JcPcxodU.js";
7
+ import { modifyEnvVarsFiles as c } from "./env-vars-BbS_mWyP.js";
8
+ import { r as l } from "./modify-file-CgJIza72.js";
9
+ import { c as u } from "./write-result-BguSfKV-.js";
10
+ import { n as d, s as f } from "./generate-JkvSNTy-.js";
11
11
  import p from "node:path";
12
12
  // src/patterns/enable/ai/generate.runtime.ts
13
13
  var m = u(n), h = [
@@ -39,4 +39,4 @@ async function _(n) {
39
39
  }
40
40
  export { _ as generate };
41
41
 
42
- //# sourceMappingURL=generate.runtime-BPnFkMKl.js.map
42
+ //# sourceMappingURL=generate.runtime-sjFAWbZc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-BPnFkMKl.js","names":["ADAPTER_STATIC_SPEC","InvalidArgumentError","getLogger","providerEnvVars","resolveProvider","suppliedProviderEnv","modifyEnv","modifyOutcomeToFile","packageName","META","envEditsFor","path","ADAPTER_STATIC","ADAPTER_STATIC$1","STATIC_ADAPTER_MESSAGE","usesStaticAdapter","res","resolveConfigTarget","root","decl","generate","options","logger","provider","creates","modifies","envVars","modifyEnvVarsFiles","envPath","envFile"],"sources":["../../src/patterns/enable/ai/generate.runtime.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { getLogger } from \"../../../core/logger\";\nimport { ADAPTER_STATIC as ADAPTER_STATIC_SPEC } from \"../../../core/constants\";\nimport {\n providerEnvVars,\n resolveProvider,\n suppliedProviderEnv,\n} from \"../../../core/providers\";\nimport { resolveConfigTarget } from \"../../../runtime/config-target\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { packageName } from \"../../../runtime/write-result\";\nimport { envEditsFor, META } from \"./generate\";\n\n// The config imports the package, not the versioned spec the constant installs.\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\n\nexport const STATIC_ADAPTER_MESSAGE = [\n `AI needs a server, and this project builds with ${ADAPTER_STATIC}.`,\n \"The chat endpoint streams each reply from the server with a private API key, which a static site cannot do.\",\n \"Switch to a server adapter first: `vela enable backend` moves the project to @sveltejs/adapter-node.\",\n].join(\"\\n\");\n\n/**\n * Whether the SvelteKit config the project builds with imports\n * adapter-static. A config that cannot be resolved does not count: the\n * pattern only refuses what it can see.\n */\nexport function usesStaticAdapter(root: string): boolean {\n const res = resolveConfigTarget(root);\n if (res.status !== \"resolved\") return false;\n return res.target.sourceFile\n .getImportDeclarations()\n .some((decl) => decl.getModuleSpecifierValue() === ADAPTER_STATIC);\n}\n\nexport async function generate(options: Options) {\n if (usesStaticAdapter(options.root)) {\n throw new InvalidArgumentError(STATIC_ADAPTER_MESSAGE);\n }\n\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n // SvelteKit 3 exposes only declared variables: `src/lib/server/ai.ts`\n // imports the provider's key from `$app/env/private`.\n logger.info(\"Declaring the API key in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, providerEnvVars(provider));\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n const envFile = modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\n );\n if (envFile) modifies.push(envFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAMY,IAAiBJ,EAAYR,CAAmB,GAEzCc,IAAyB;CACpC,mDAAmDF,EAAe;CAClE;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBG,EAAkB,GAAuB;CACvD,IAAMC,IAAMC,EAAoBC,CAAI;CAEpC,OADIF,EAAI,WAAW,cACZA,EAAI,OAAO,WACf,sBAAsB,CAAC,CACvB,MAAM,MAASG,EAAK,wBAAwB,MAAMP,CAAc;AACrE;AAEA,eAAsBQ,EAAS,GAAkB;CAC/C,IAAIL,EAAkBM,EAAQ,IAAI,GAChC,MAAM,IAAIpB,EAAqBa,CAAsB;CAGvD,IAAMQ,IAASpB,EAAUmB,CAAO,GAC1BE,IAAWnB,EAAgBK,GAAMY,CAAO,GACxCG,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAI1B,EAAO,KAAK,qCAAqC;CACjD,IAAMC,IAAUC,EAAmBN,EAAQ,MAAMlB,EAAgBoB,CAAQ,CAAC;CAI1E,AAHIG,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAC3CA,EAAQ,UAAQD,EAAS,KAAKC,EAAQ,MAAM,GAEhDJ,EAAO,KAAK,eAAe;CAC3B,IAAMM,IAAUjB,EAAK,KAAKU,EAAQ,MAAM,MAAM,GACxCQ,IAAUtB,EACdqB,GACAtB,EAAUsB,GAASlB,EAAYa,GAAUlB,EAAoBgB,CAAO,CAAC,CAAC,CACxE;CAGA,OAFIQ,KAASJ,EAAS,KAAKI,CAAO,GAE3B;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
1
+ {"version":3,"file":"generate.runtime-sjFAWbZc.js","names":["ADAPTER_STATIC_SPEC","InvalidArgumentError","getLogger","providerEnvVars","resolveProvider","suppliedProviderEnv","modifyEnv","modifyOutcomeToFile","packageName","META","envEditsFor","path","ADAPTER_STATIC","ADAPTER_STATIC$1","STATIC_ADAPTER_MESSAGE","usesStaticAdapter","res","resolveConfigTarget","root","decl","generate","options","logger","provider","creates","modifies","envVars","modifyEnvVarsFiles","envPath","envFile"],"sources":["../../src/patterns/enable/ai/generate.runtime.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { getLogger } from \"../../../core/logger\";\nimport { ADAPTER_STATIC as ADAPTER_STATIC_SPEC } from \"../../../core/constants\";\nimport {\n providerEnvVars,\n resolveProvider,\n suppliedProviderEnv,\n} from \"../../../core/providers\";\nimport { resolveConfigTarget } from \"../../../runtime/config-target\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { packageName } from \"../../../runtime/write-result\";\nimport { envEditsFor, META } from \"./generate\";\n\n// The config imports the package, not the versioned spec the constant installs.\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\n\nexport const STATIC_ADAPTER_MESSAGE = [\n `AI needs a server, and this project builds with ${ADAPTER_STATIC}.`,\n \"The chat endpoint streams each reply from the server with a private API key, which a static site cannot do.\",\n \"Switch to a server adapter first: `vela enable backend` moves the project to @sveltejs/adapter-node.\",\n].join(\"\\n\");\n\n/**\n * Whether the SvelteKit config the project builds with imports\n * adapter-static. A config that cannot be resolved does not count: the\n * pattern only refuses what it can see.\n */\nexport function usesStaticAdapter(root: string): boolean {\n const res = resolveConfigTarget(root);\n if (res.status !== \"resolved\") return false;\n return res.target.sourceFile\n .getImportDeclarations()\n .some((decl) => decl.getModuleSpecifierValue() === ADAPTER_STATIC);\n}\n\nexport async function generate(options: Options) {\n if (usesStaticAdapter(options.root)) {\n throw new InvalidArgumentError(STATIC_ADAPTER_MESSAGE);\n }\n\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n // SvelteKit 3 exposes only declared variables: `src/lib/server/ai.ts`\n // imports the provider's key from `$app/env/private`.\n logger.info(\"Declaring the API key in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, providerEnvVars(provider));\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n const envFile = modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\n );\n if (envFile) modifies.push(envFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAMY,IAAiBJ,EAAYR,CAAmB,GAEzCc,IAAyB;CACpC,mDAAmDF,EAAe;CAClE;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBG,EAAkB,GAAuB;CACvD,IAAMC,IAAMC,EAAoBC,CAAI;CAEpC,OADIF,EAAI,WAAW,cACZA,EAAI,OAAO,WACf,sBAAsB,CAAC,CACvB,MAAM,MAASG,EAAK,wBAAwB,MAAMP,CAAc;AACrE;AAEA,eAAsBQ,EAAS,GAAkB;CAC/C,IAAIL,EAAkBM,EAAQ,IAAI,GAChC,MAAM,IAAIpB,EAAqBa,CAAsB;CAGvD,IAAMQ,IAASpB,EAAUmB,CAAO,GAC1BE,IAAWnB,EAAgBK,GAAMY,CAAO,GACxCG,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAI1B,EAAO,KAAK,qCAAqC;CACjD,IAAMC,IAAUC,EAAmBN,EAAQ,MAAMlB,EAAgBoB,CAAQ,CAAC;CAI1E,AAHIG,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAC3CA,EAAQ,UAAQD,EAAS,KAAKC,EAAQ,MAAM,GAEhDJ,EAAO,KAAK,eAAe;CAC3B,IAAMM,IAAUjB,EAAK,KAAKU,EAAQ,MAAM,MAAM,GACxCQ,IAAUtB,EACdqB,GACAtB,EAAUsB,GAASlB,EAAYa,GAAUlB,EAAoBgB,CAAO,CAAC,CAAC,CACxE;CAGA,OAFIQ,KAASJ,EAAS,KAAKI,CAAO,GAE3B;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,11 +1,11 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
2
  import { a as t } from "./util-ILWdjRAd.js";
3
- import { r as n } from "./modify-file-CoFH_Y5n.js";
3
+ import { r as n } from "./modify-file-CgJIza72.js";
4
4
  import { t as r } from "./svelte-file-DfplF3BU.js";
5
5
  import { f as i } from "./ts-morph-helpers-B4KZXP44.js";
6
- import { t as a } from "./shared-Be8NptJO.js";
6
+ import { t as a } from "./shared-BjTRQ5QH.js";
7
7
  import { m as o, p as s, t as c } from "./generate-DYq5Oj58.js";
8
- import { SUCCESS_PAGE as l, t as u } from "./generate.runtime-BB2GGj4d.js";
8
+ import { SUCCESS_PAGE as l, t as u } from "./generate.runtime-XpYi9SlM.js";
9
9
  import d from "node:fs";
10
10
  import f from "node:path";
11
11
  // src/patterns/disable/orders/generate.runtime.ts
@@ -60,4 +60,4 @@ async function p(p) {
60
60
  }
61
61
  export { p as generate };
62
62
 
63
- //# sourceMappingURL=generate.runtime-7QPUM9c3.js.map
63
+ //# sourceMappingURL=generate.runtime-wiWdXXPi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-7QPUM9c3.js","names":["successServer","successSvelte","getLogger","languageFromPath","modifyOutcomeToFile","SvelteFile","removeNavItemFromScript","planDropsForCollections","_page_server_default","_page_default","ORDER_COLLECTIONS","unmodifyWebhookServer","fs","path","generate","logger","options","modifies","pushResult","file","dispatchPath","name","content","SUCCESS_PAGE","navUserPath","source","removed","tryRemove","run","result","src","fn","updated"],"sources":["../../src/patterns/disable/orders/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { languageFromPath } from \"../../../core/util\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { SvelteFile } from \"../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../runtime/ts-morph-helpers\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { ORDER_COLLECTIONS } from \"../../enable/orders/generate\";\nimport { SUCCESS_PAGE } from \"../../enable/orders/generate.runtime\";\nimport { unmodifyWebhookServer } from \"../../enable/orders/modifies/modify-webhook-server\";\n// The success page as enable-ecommerce wrote it, before orders rewrote it.\nimport successServer from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.server.ts?raw\";\nimport successSvelte from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.svelte?raw\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting webhooks/stripe/handlers/dispatch.ts\");\n const dispatchPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(dispatchPath, unmodifyWebhookServer(dispatchPath)),\n );\n\n // Back to Stripe's summary alone, as enable-ecommerce wrote the page; a\n // project without the cart has no page to restore.\n logger.info(\"Reverting /checkout/success\");\n for (const [name, content] of [\n [\"+page.server.ts\", successServer],\n [\"+page.svelte\", successSvelte],\n ] as const) {\n const file = path.join(options.root, SUCCESS_PAGE, name);\n if (!fs.existsSync(file) || fs.readFileSync(file, \"utf8\") === content) {\n continue;\n }\n modifies.push({\n path: file,\n language: languageFromPath(file),\n content,\n status: \"success\",\n });\n }\n\n logger.info(\"Removing Orders from the user menu\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n if (fs.existsSync(navUserPath)) {\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (source.includes(\"'/orders'\")) {\n const file = new SvelteFile(source);\n let removed = false;\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (removed) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Orders\",\n \"@lucide/svelte/icons/package\",\n );\n if (result.wasRemoved) removed = true;\n return result.source;\n });\n };\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!removed) tryRemove((fn) => file.modifyScript(fn));\n if (removed) {\n const updated = file.toString();\n fs.writeFileSync(navUserPath, updated, \"utf8\");\n modifies.push({\n path: navUserPath,\n language: languageFromPath(navUserPath),\n content: updated,\n status: \"success\",\n });\n }\n }\n }\n\n // Lines before orders: PocketBase refuses to drop a collection another\n // relation still points at. One never created is planned as missing.\n const collectionDrops = await planDropsForCollections(\n [...ORDER_COLLECTIONS].reverse(),\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,eAAsBc,EAAS,GAAkB;CAC/C,IAAMC,IAASb,EAAUc,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIC,KAAMF,EAAS,KAAKE,CAAI;CAC9B;CAEA,EAAO,KAAK,gDAAgD;CAC5D,IAAMC,IAAeP,EAAK,KACxBG,EAAQ,MACR,OACA,UACA,YACA,UACA,YACA,aACF;CAOA,AANAE,EACEd,EAAoBgB,GAAcT,EAAsBS,CAAY,CAAC,CACvE,GAIAL,EAAO,KAAK,6BAA6B;CACzC,KAAK,IAAM,CAACM,GAAMC,MAAY,CAC5B,CAAC,mBAAmBtB,CAAa,GACjC,CAAC,gBAAgBC,CAAa,CAChC,GAAY;EACV,IAAMkB,IAAON,EAAK,KAAKG,EAAQ,MAAMO,GAAcF,CAAI;EACvD,AAAKT,EAAG,WAAWO,CAAI,KAAKP,EAAG,aAAaO,GAAM,MAAM,MAAMG,KAG9DL,EAAS,KAAK;GACZ,MAAME;GACN,UAAUhB,EAAiBgB,CAAI;GAC/B;GACA,QAAQ;EACV,CAAC;CACH;CAEA,EAAO,KAAK,oCAAoC;CAChD,IAAMK,IAAcX,EAAK,KACvBG,EAAQ,MACR,OACA,OACA,cACA,iBACF;CACA,IAAIJ,EAAG,WAAWY,CAAW,GAAG;EAC9B,IAAMC,IAASb,EAAG,aAAaY,GAAa,MAAM;EAClD,IAAIC,EAAO,SAAS,WAAW,GAAG;GAChC,IAAMN,IAAO,IAAId,EAAWoB,CAAM,GAC9BC,IAAU,IACRC,KAAa,MAAgD;IACjE,AAAID,KACJE,GAAK,MAAQ;KACX,IAAMC,IAASvB,EACbwB,GACA,UACA,8BACF;KAEA,OADID,EAAO,eAAY,IAAU,KAC1BA,EAAO;IAChB,CAAC;GACH;GAGA,IAFAF,GAAW,MAAOR,EAAK,mBAAmBY,CAAE,CAAC,GACxCL,KAASC,GAAW,MAAOR,EAAK,aAAaY,CAAE,CAAC,GACjDL,GAAS;IACX,IAAMM,IAAUb,EAAK,SAAS;IAE9B,AADAP,EAAG,cAAcY,GAAaQ,GAAS,MAAM,GAC7Cf,EAAS,KAAK;KACZ,MAAMO;KACN,UAAUrB,EAAiBqB,CAAW;KACtC,SAASQ;KACT,QAAQ;IACV,CAAC;GACH;EACF;CACF;CASA,OAAO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BzB,EAC5B,CAAC,GAAGG,CAAiB,CAAC,CAAC,QAAQ,GAC/BM,CACF;CAWA;AACF"}
1
+ {"version":3,"file":"generate.runtime-wiWdXXPi.js","names":["successServer","successSvelte","getLogger","languageFromPath","modifyOutcomeToFile","SvelteFile","removeNavItemFromScript","planDropsForCollections","_page_server_default","_page_default","ORDER_COLLECTIONS","unmodifyWebhookServer","fs","path","generate","logger","options","modifies","pushResult","file","dispatchPath","name","content","SUCCESS_PAGE","navUserPath","source","removed","tryRemove","run","result","src","fn","updated"],"sources":["../../src/patterns/disable/orders/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { languageFromPath } from \"../../../core/util\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { SvelteFile } from \"../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../runtime/ts-morph-helpers\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { ORDER_COLLECTIONS } from \"../../enable/orders/generate\";\nimport { SUCCESS_PAGE } from \"../../enable/orders/generate.runtime\";\nimport { unmodifyWebhookServer } from \"../../enable/orders/modifies/modify-webhook-server\";\n// The success page as enable-ecommerce wrote it, before orders rewrote it.\nimport successServer from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.server.ts?raw\";\nimport successSvelte from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.svelte?raw\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting webhooks/stripe/handlers/dispatch.ts\");\n const dispatchPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(dispatchPath, unmodifyWebhookServer(dispatchPath)),\n );\n\n // Back to Stripe's summary alone, as enable-ecommerce wrote the page; a\n // project without the cart has no page to restore.\n logger.info(\"Reverting /checkout/success\");\n for (const [name, content] of [\n [\"+page.server.ts\", successServer],\n [\"+page.svelte\", successSvelte],\n ] as const) {\n const file = path.join(options.root, SUCCESS_PAGE, name);\n if (!fs.existsSync(file) || fs.readFileSync(file, \"utf8\") === content) {\n continue;\n }\n modifies.push({\n path: file,\n language: languageFromPath(file),\n content,\n status: \"success\",\n });\n }\n\n logger.info(\"Removing Orders from the user menu\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n if (fs.existsSync(navUserPath)) {\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (source.includes(\"'/orders'\")) {\n const file = new SvelteFile(source);\n let removed = false;\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (removed) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Orders\",\n \"@lucide/svelte/icons/package\",\n );\n if (result.wasRemoved) removed = true;\n return result.source;\n });\n };\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!removed) tryRemove((fn) => file.modifyScript(fn));\n if (removed) {\n const updated = file.toString();\n fs.writeFileSync(navUserPath, updated, \"utf8\");\n modifies.push({\n path: navUserPath,\n language: languageFromPath(navUserPath),\n content: updated,\n status: \"success\",\n });\n }\n }\n }\n\n // Lines before orders: PocketBase refuses to drop a collection another\n // relation still points at. One never created is planned as missing.\n const collectionDrops = await planDropsForCollections(\n [...ORDER_COLLECTIONS].reverse(),\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,eAAsBc,EAAS,GAAkB;CAC/C,IAAMC,IAASb,EAAUc,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIC,KAAMF,EAAS,KAAKE,CAAI;CAC9B;CAEA,EAAO,KAAK,gDAAgD;CAC5D,IAAMC,IAAeP,EAAK,KACxBG,EAAQ,MACR,OACA,UACA,YACA,UACA,YACA,aACF;CAOA,AANAE,EACEd,EAAoBgB,GAAcT,EAAsBS,CAAY,CAAC,CACvE,GAIAL,EAAO,KAAK,6BAA6B;CACzC,KAAK,IAAM,CAACM,GAAMC,MAAY,CAC5B,CAAC,mBAAmBtB,C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1,5 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
- import { r as t } from "./modify-file-CoFH_Y5n.js";
2
+ import { r as t } from "./modify-file-CgJIza72.js";
3
3
  import { i as n, n as r, r as i, t as a } from "./translations-CiJnl574.js";
4
4
  import { n as o, r as s } from "./app-layout.svelte-CZ0hw-pi.js";
5
5
  import c from "node:fs";
@@ -25,4 +25,4 @@ function u(u) {
25
25
  }
26
26
  export { u as localizeAuthPages };
27
27
 
28
- //# sourceMappingURL=i18n-D8hsUX_P.js.map
28
+ //# sourceMappingURL=i18n-mnzzcYhz.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"i18n-D8hsUX_P.js","names":["getLogger","modifyOutcomeToFile","translateCatalog","entriesInProject","hasSpanish","AUTH_TRANSLATIONS","APP_LAYOUT_PATH","modifyAppLayoutLanguageSelect","fs","path","localizeAuthPages","logger","options","creates","modifies","appLayoutFile","select","translated"],"sources":["../../src/patterns/enable/auth/i18n.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n entriesInProject,\n hasSpanish,\n translateCatalog,\n} from \"../../../runtime/wuchale-catalog\";\nimport {\n APP_LAYOUT_PATH,\n modifyAppLayoutLanguageSelect,\n} from \"../i18n/modifies/app-layout.svelte\";\nimport { AUTH_TRANSLATIONS } from \"./translations\";\n\n/**\n * What enable-i18n would have done to the auth pages had they been in the\n * project when it ran: the language select in the signed-in layout, and the\n * pages' Spanish in the catalog. For enable-auth and enable-auth-remote, in a\n * project that already has i18n; nothing happens in one that does not.\n *\n * Reads the pages from disk, so it runs after the pattern's creates are\n * written. Detected by the files enable-i18n wrote rather than\n * `features.i18n`, so a project that dropped Spanish keeps its catalog as it\n * is.\n */\nexport function localizeAuthPages(options: Options): {\n creates: File[];\n modifies: File[];\n} {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n if (!fs.existsSync(path.join(options.root, \"wuchale.config.js\"))) {\n return { creates, modifies };\n }\n\n logger.info(\"Adding the language select to the signed-in layout\");\n const appLayoutFile = path.join(options.root, APP_LAYOUT_PATH);\n const select = modifyOutcomeToFile(\n appLayoutFile,\n modifyAppLayoutLanguageSelect(appLayoutFile),\n );\n if (select) modifies.push(select);\n\n if (hasSpanish(options.root)) {\n logger.info(\"Translating the sign-in pages into Spanish\");\n const translated = translateCatalog(\n options.root,\n entriesInProject(options.root, AUTH_TRANSLATIONS),\n );\n if (translated.create) creates.push(translated.create);\n if (translated.modify) modifies.push(translated.modify);\n }\n\n return { creates, modifies };\n}\n"],"mappings":";;;;;;;AA2BA,SAAgBU,EAAkB,GAGhC;CACA,IAAMC,IAASX,EAAUY,CAAO,GAC1BC,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAC1B,IAAI,CAACN,EAAG,WAAWC,EAAK,KAAKG,EAAQ,MAAM,mBAAmB,CAAC,GAC7D,OAAO;EAAE;EAAS;CAAS;CAG7B,EAAO,KAAK,oDAAoD;CAChE,IAAMG,IAAgBN,EAAK,KAAKG,EAAQ,MAAMN,CAAe,GACvDU,IAASf,EACbc,GACAR,EAA8BQ,CAAa,CAC7C;CAGA,IAFIC,KAAQF,EAAS,KAAKE,CAAM,GAE5BZ,EAAWQ,EAAQ,IAAI,GAAG;EAC5B,EAAO,KAAK,4CAA4C;EACxD,IAAMK,IAAaf,EACjBU,EAAQ,MACRT,EAAiBS,EAAQ,MAAMP,CAAiB,CAClD;EAEA,AADIY,EAAW,UAAQJ,EAAQ,KAAKI,EAAW,MAAM,GACjDA,EAAW,UAAQH,EAAS,KAAKG,EAAW,MAAM;CACxD;CAEA,OAAO;EAAE;EAAS;CAAS;AAC7B"}
1
+ {"version":3,"file":"i18n-mnzzcYhz.js","names":["getLogger","modifyOutcomeToFile","translateCatalog","entriesInProject","hasSpanish","AUTH_TRANSLATIONS","APP_LAYOUT_PATH","modifyAppLayoutLanguageSelect","fs","path","localizeAuthPages","logger","options","creates","modifies","appLayoutFile","select","translated"],"sources":["../../src/patterns/enable/auth/i18n.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n entriesInProject,\n hasSpanish,\n translateCatalog,\n} from \"../../../runtime/wuchale-catalog\";\nimport {\n APP_LAYOUT_PATH,\n modifyAppLayoutLanguageSelect,\n} from \"../i18n/modifies/app-layout.svelte\";\nimport { AUTH_TRANSLATIONS } from \"./translations\";\n\n/**\n * What enable-i18n would have done to the auth pages had they been in the\n * project when it ran: the language select in the signed-in layout, and the\n * pages' Spanish in the catalog. For enable-auth and enable-auth-remote, in a\n * project that already has i18n; nothing happens in one that does not.\n *\n * Reads the pages from disk, so it runs after the pattern's creates are\n * written. Detected by the files enable-i18n wrote rather than\n * `features.i18n`, so a project that dropped Spanish keeps its catalog as it\n * is.\n */\nexport function localizeAuthPages(options: Options): {\n creates: File[];\n modifies: File[];\n} {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n if (!fs.existsSync(path.join(options.root, \"wuchale.config.js\"))) {\n return { creates, modifies };\n }\n\n logger.info(\"Adding the language select to the signed-in layout\");\n const appLayoutFile = path.join(options.root, APP_LAYOUT_PATH);\n const select = modifyOutcomeToFile(\n appLayoutFile,\n modifyAppLayoutLanguageSelect(appLayoutFile),\n );\n if (select) modifies.push(select);\n\n if (hasSpanish(options.root)) {\n logger.info(\"Translating the sign-in pages into Spanish\");\n const translated = translateCatalog(\n options.root,\n entriesInProject(options.root, AUTH_TRANSLATIONS),\n );\n if (translated.create) creates.push(translated.create);\n if (translated.modify) modifies.push(translated.modify);\n }\n\n return { creates, modifies };\n}\n"],"mappings":";;;;;;;AA2BA,SAAgBU,EAAkB,GAGhC;CACA,IAAMC,IAASX,EAAUY,CAAO,GAC1BC,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAC1B,IAAI,CAACN,EAAG,WAAWC,EAAK,KAAKG,EAAQ,MAAM,mBAAmB,CAAC,GAC7D,OAAO;EAAE;EAAS;CAAS;CAG7B,EAAO,KAAK,oDAAoD;CAChE,IAAMG,IAAgBN,EAAK,KAAKG,EAAQ,MAAMN,CAAe,GACvDU,IAASf,EACbc,GACAR,EAA8BQ,CAAa,CAC7C;CAGA,IAFIC,KAAQF,EAAS,KAAKE,CAAM,GAE5BZ,EAAWQ,EAAQ,IAAI,GAAG;EAC5B,EAAO,KAAK,4CAA4C;EACxD,IAAMK,IAAaf,EACjBU,EAAQ,MACRT,EAAiBS,EAAQ,MAAMP,CAAiB,CAClD;EAEA,AADIY,EAAW,UAAQJ,EAAQ,KAAKI,EAAW,MAAM,GACjDA,EAAW,UAAQH,EAAS,KAAKG,EAAW,MAAM;CACxD;CAEA,OAAO;EAAE;EAAS;CAAS;AAC7B"}
@@ -1,6 +1,6 @@
1
1
  import { n as e } from "./rolldown-runtime-CwxnZyOB.js";
2
2
  import { a as t } from "./util-ILWdjRAd.js";
3
- import { n } from "./shared-Be8NptJO.js";
3
+ import { n } from "./shared-BjTRQ5QH.js";
4
4
  import { _ as r, s as i } from "./ts-morph-helpers-B4KZXP44.js";
5
5
  import a from "node:fs";
6
6
  import o from "node:path";
@@ -47,4 +47,4 @@ function d(e, t) {
47
47
  }
48
48
  export { l as a, s as i, d as n, c as r, u as t };
49
49
 
50
- //# sourceMappingURL=modify-file-CoFH_Y5n.js.map
50
+ //# sourceMappingURL=modify-file-CgJIza72.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modify-file-CoFH_Y5n.js","names":["__exportAll","languageFromPath","withInMemoryScript","isEffectivelyEmpty","fs","path","modify_file_exports","keepMissing","modifyOutcomeToFile","language","filePath","outcome","revertOutcomeToFile","toDeleteEntry","envRevertOutcomeToFile","envPath","creates","root","file"],"sources":["../../src/runtime/modify-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, ModifyOutcome } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { toDeleteEntry } from \"../patterns/destroy/shared\";\nimport { isEffectivelyEmpty, withInMemoryScript } from \"./ts-morph-helpers\";\n\nexport function modifyOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): File | null {\n const language = languageFromPath(filePath);\n\n if (outcome.status === \"success\") {\n if (!outcome.changed) return null;\n return {\n path: filePath,\n language,\n content: fs.readFileSync(filePath, \"utf8\"),\n status: \"success\",\n };\n }\n\n const content =\n outcome.status === \"failed\" && fs.existsSync(filePath)\n ? fs.readFileSync(filePath, \"utf8\")\n : \"\";\n\n return {\n path: filePath,\n language,\n content,\n status: outcome.status,\n message: outcome.message,\n };\n}\n\n/**\n * `modifyOutcomeToFile` for a revert that may have taken out everything the\n * file held: a script left with no statements, only comments and whitespace,\n * is reported as a delete. For hooks files a pattern created, or that ended\n * up holding nothing but what patterns put there.\n */\nexport function revertOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(filePath) &&\n withInMemoryScript(fs.readFileSync(filePath, \"utf8\"), isEffectivelyEmpty)\n .result\n ) {\n return { modify: null, delete: toDeleteEntry(filePath) };\n }\n return { modify: modifyOutcomeToFile(filePath, outcome), delete: null };\n}\n\n/**\n * `modifyOutcomeToFile` for a `.env` revert: a file the revert left empty is\n * reported as a delete. The enable pattern most likely created it, and an\n * empty `.env` holds nothing worth keeping.\n */\nexport function envRevertOutcomeToFile(\n envPath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(envPath) &&\n fs.readFileSync(envPath, \"utf8\").trim() === \"\"\n ) {\n return { modify: null, delete: toDeleteEntry(envPath) };\n }\n return { modify: modifyOutcomeToFile(envPath, outcome), delete: null };\n}\n\n/**\n * Drop any create that already exists on disk.\n *\n * `writeResult` overwrites an existing create whose content differs and\n * reports it as a modify, which would mean a re-run silently resetting a\n * developer's edits, or a create clobbering a file other patterns have\n * already written to. The file is theirs once it exists; a pattern that has\n * something to add to it does so with a modifier.\n */\nexport function keepMissing(creates: File[], root: string): File[] {\n return creates.filter((file) => !fs.existsSync(path.join(root, file.path)));\n}\n"],"mappings":";;;;;;;;;;;AAOA,SAAgBQ,EACd,GACA,GACa;CACb,IAAMC,IAAWR,EAAiBS,CAAQ;CAiB1C,OAfIC,EAAQ,WAAW,YAChBA,EAAQ,UACN;EACL,MAAMD;EACN;EACA,SAASN,EAAG,aAAaM,GAAU,MAAM;EACzC,QAAQ;CACV,IAN6B,OAcxB;EACL,MAAMA;EACN;EACA,SAPAC,EAAQ,WAAW,YAAYP,EAAG,WAAWM,CAAQ,IACjDN,EAAG,aAAaM,GAAU,MAAM,IAChC;EAMJ,QAAQC,EAAQ;EAChB,SAASA,EAAQ;CACnB;AACF;AAQA,SAAgBC,EACd,GACA,GAC8C;CAU9C,OARED,EAAQ,WAAW,aACnBA,EAAQ,WACRP,EAAG,WAAWM,CAAQ,KACtBR,EAAmBE,EAAG,aAAaM,GAAU,MAAM,GAAGP,CAAkB,CAAC,CACtE,SAEI;EAAE,QAAQ;EAAM,QAAQU,EAAcH,CAAQ;CAAE,IAElD;EAAE,QAAQF,EAAoBE,GAAUC,CAAO;EAAG,QAAQ;CAAK;AACxE;AAOA,SAAgBG,EACd,GACA,GAC8C;CAS9C,OAPEH,EAAQ,WAAW,aACnBA,EAAQ,WACRP,EAAG,WAAWW,CAAO,KACrBX,EAAG,aAAaW,GAAS,MAAM,CAAC,CAAC,KAAK,MAAM,KAErC;EAAE,QAAQ;EAAM,QAAQF,EAAcE,CAAO;CAAE,IAEjD;EAAE,QAAQP,EAAoBO,GAASJ,CAAO;EAAG,QAAQ;CAAK;AACvE;AAWA,SAAgBJ,EAAY,GAAiB,GAAsB;CACjE,OAAOS,EAAQ,QAAQ,MAAS,CAACZ,EAAG,WAAWC,EAAK,KAAKY,GAAMC,EAAK,IAAI,CAAC,CAAC;AAC5E"}
1
+ {"version":3,"file":"modify-file-CgJIza72.js","names":["__exportAll","languageFromPath","withInMemoryScript","isEffectivelyEmpty","fs","path","modify_file_exports","keepMissing","modifyOutcomeToFile","language","filePath","outcome","revertOutcomeToFile","toDeleteEntry","envRevertOutcomeToFile","envPath","creates","root","file"],"sources":["../../src/runtime/modify-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, ModifyOutcome } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { toDeleteEntry } from \"../patterns/destroy/shared\";\nimport { isEffectivelyEmpty, withInMemoryScript } from \"./ts-morph-helpers\";\n\nexport function modifyOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): File | null {\n const language = languageFromPath(filePath);\n\n if (outcome.status === \"success\") {\n if (!outcome.changed) return null;\n return {\n path: filePath,\n language,\n content: fs.readFileSync(filePath, \"utf8\"),\n status: \"success\",\n };\n }\n\n const content =\n outcome.status === \"failed\" && fs.existsSync(filePath)\n ? fs.readFileSync(filePath, \"utf8\")\n : \"\";\n\n return {\n path: filePath,\n language,\n content,\n status: outcome.status,\n message: outcome.message,\n };\n}\n\n/**\n * `modifyOutcomeToFile` for a revert that may have taken out everything the\n * file held: a script left with no statements, only comments and whitespace,\n * is reported as a delete. For hooks files a pattern created, or that ended\n * up holding nothing but what patterns put there.\n */\nexport function revertOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(filePath) &&\n withInMemoryScript(fs.readFileSync(filePath, \"utf8\"), isEffectivelyEmpty)\n .result\n ) {\n return { modify: null, delete: toDeleteEntry(filePath) };\n }\n return { modify: modifyOutcomeToFile(filePath, outcome), delete: null };\n}\n\n/**\n * `modifyOutcomeToFile` for a `.env` revert: a file the revert left empty is\n * reported as a delete. The enable pattern most likely created it, and an\n * empty `.env` holds nothing worth keeping.\n */\nexport function envRevertOutcomeToFile(\n envPath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(envPath) &&\n fs.readFileSync(envPath, \"utf8\").trim() === \"\"\n ) {\n return { modify: null, delete: toDeleteEntry(envPath) };\n }\n return { modify: modifyOutcomeToFile(envPath, outcome), delete: null };\n}\n\n/**\n * Drop any create that already exists on disk.\n *\n * `writeResult` overwrites an existing create whose content differs and\n * reports it as a modify, which would mean a re-run silently resetting a\n * developer's edits, or a create clobbering a file other patterns have\n * already written to. The file is theirs once it exists; a pattern that has\n * something to add to it does so with a modifier.\n */\nexport function keepMissing(creates: File[], root: string): File[] {\n return creates.filter((file) => !fs.existsSync(path.join(root, file.path)));\n}\n"],"mappings":";;;;;;;;;;;AAOA,SAAgBQ,EACd,GACA,GACa;CACb,IAAMC,IAAWR,EAAiBS,CAAQ;CAiB1C,OAfIC,EAAQ,WAAW,YAChBA,EAAQ,UACN;EACL,MAAMD;EACN;EACA,SAASN,EAAG,aAAaM,GAAU,MAAM;EACzC,QAAQ;CACV,IAN6B,OAcxB;EACL,MAAMA;EACN;EACA,SAPAC,EAAQ,WAAW,YAAYP,EAAG,WAAWM,CAAQ,IACjDN,EAAG,aAAaM,GAAU,MAAM,IAChC;EAMJ,QAAQC,EAAQ;EAChB,SAASA,EAAQ;CACnB;AACF;AAQA,SAAgBC,EACd,GACA,GAC8C;CAU9C,OARED,EAAQ,WAAW,aACnBA,EAAQ,WACRP,EAAG,WAAWM,CAAQ,KACtBR,EAAmBE,EAAG,aAAaM,GAAU,MAAM,GAAGP,CAAkB,CAAC,CACtE,SAEI;EAAE,QAAQ;EAAM,QAAQU,EAAcH,CAAQ;CAAE,IAElD;EAAE,QAAQF,EAAoBE,GAAUC,CAAO;EAAG,QAAQ;CAAK;AACxE;AAOA,SAAgBG,EACd,GACA,GAC8C;CAS9C,OAPEH,EAAQ,WAAW,aACnBA,EAAQ,WACRP,EAAG,WAAWW,CAAO,KACrBX,EAAG,aAAaW,GAAS,MAAM,CAAC,CAAC,KAAK,MAAM,KAErC;EAAE,QAAQ;EAAM,QAAQF,EAAcE,CAAO;CAAE,IAEjD;EAAE,QAAQP,EAAoBO,GAASJ,CAAO;EAAG,QAAQ;CAAK;AACvE;AAWA,SAAgBJ,EAAY,GAAiB,GAAsB;CACjE,OAAOS,EAAQ,QAAQ,MAAS,CAACZ,EAAG,WAAWC,EAAK,KAAKY,GAAMC,EAAK,IAAI,CAAC,CAAC;AAC5E"}
@@ -1,5 +1,5 @@
1
1
  import { n as e } from "./rolldown-runtime-CwxnZyOB.js";
2
- import { i as t, s as n } from "./constants-Bo85Ke0C.js";
2
+ import { i as t, s as n } from "./constants-CTp-0HKk.js";
3
3
  import { existsSync as r, readFileSync as i, readdirSync as a } from "node:fs";
4
4
  import o from "node:path";
5
5
  import s from "pocketbase";
@@ -216,4 +216,4 @@ function T(e, t) {
216
216
  }
217
217
  export { w as i, b as n, v as r, x as t };
218
218
 
219
- //# sourceMappingURL=pocketbase-BTLraFEp.js.map
219
+ //# sourceMappingURL=pocketbase-S8lUt0nI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pocketbase-BTLraFEp.js","names":["__exportAll","DATA_DIR","MIGRATIONS_DIR","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","withPocketbase","MIGRATION_DELAY_MS","migrationDelay","getMigrationFile","ending","action","collectionName","migrationFile","readdirSync","options","file","getPocketbaseMetadata","metadataPath","cwd","existsSync","readFileSync","authWithRetries","authSuccess","attempt","pb","email","password","dir","migrationsDir","metadata","fn","commandArgs","packageManager","detect","resolveCommand","args","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport { DATA_DIR, MIGRATIONS_DIR } from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const commandArgs = [\n \"pocketbase-server\",\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ];\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(\n packageManager,\n \"execute\",\n commandArgs,\n )!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n // Start the PocketBase server process. The package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `pocketbase-server exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAaO,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACzE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAM;CAAM;CACxE;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CACxE;CAAM;CAAM;AACd,CAAC;AAED,SAASC,EAAe,GAA+B;CACrD,OAAO,IAAI,SAAS,GAAS,MAAW;EACtC,IAAMC,IAASH,EAAI,aAAa;EAGhC,AAFAG,EAAO,MAAM,GACbA,EAAO,KAAK,SAASC,CAAM,GAC3BD,EAAO,OAAO,GAAGE,SAAY;GAC3B,IAAM,EAAE,YAASF,EAAO,QAAQ;GAChC,EAAO,YAAYG,EAAQC,CAAI,CAAC;EAClC,CAAC;CACH,CAAC;AACH;AAQA,eAAsBC,EAAS,GAA+B;CAC5D,SAAS;EACP,IAAMD,IAAO,MAAML,EAAeG,CAAI;EACtC,IAAI,CAACJ,EAAU,IAAIM,CAAI,GAAG,OAAOA;CACnC;AACF;AAIA,SAAgBE,EACd,GACA,GACA,IAAc,IACC;CACf,OAAO,IAAI,SAAS,GAAS,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AASH,CAAI,GAC1B4C,IAAc;EAClB;EACA;EACA;EACAJ;EACA;EACAC;EACA;EACA,GAAGzC,EAAK,GAAGE;CACb,GAEM2C,KAAkB,MAAMC,EAAO,EAAE,OAAI,CAAC,EAAA,EAAI,QAAQ,OAClD,EAAE,YAAS,YAASC,EACxBF,GACA,WACAD,CACF;CAGA,AAAIC,MAAmB,SAAOG,EAAK,QAAQ,OAAO;CAMlD,IAAMC,IAAW,QAAQ,aAAa,SAChCC,IAAgBxD,EAAMyD,GAASH,GAAM;EACzC;EACA,OAAO;EACP;CACF,CAAC,GAIKI,IAAS,IAAI,SAAgB,GAAG,MAAW;EAQ/C,AAPAF,EAAc,KAAK,SAAS,GAAM,MAAW;GAC3C,EACE,gBAAI,MACF,gDAAgDlD,EAAK,GAAGE,EAAK,IAAImD,KAAU,QAAQC,IAAO,EAC5F,CACF;EACF,CAAC,GACDJ,EAAc,KAAK,SAASnD,CAAM;CACpC,CAAC;CAED,IAAI;EAEF,MAAM,QAAQ,KAAK,EAChB,YAAY;GAEX,AADA,MAAMK,EAAYF,GAAMF,CAAI,GAC5B,MAAMY,EAAc,UAAUZ,EAAK,GAAGE,GAAM;EAC9C,EAAA,CAAG,GACHkD,CACF,CAAC;EAED,IAAMf,IAAK,IAAI5C,EAAW,UAAUO,EAAK,GAAGE,GAAM;EAMlD,AALA,MAAMgC,EACJG,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAMM,EAAGN,CAAE;CACb,UAAU;EAER,EAAgBa,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
1
+ {"version":3,"file":"pocketbase-S8lUt0nI.js","names":["__exportAll","DATA_DIR","MIGRATIONS_DIR","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","withPocketbase","MIGRATION_DELAY_MS","migrationDelay","getMigrationFile","ending","action","collectionName","migrationFile","readdirSync","options","file","getPocketbaseMetadata","metadataPath","cwd","existsSync","readFileSync","authWithRetries","authSuccess","attempt","pb","email","password","dir","migrationsDir","metadata","fn","commandArgs","packageManager","detect","resolveCommand","args","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport { DATA_DIR, MIGRATIONS_DIR } from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const commandArgs = [\n \"pocketbase-server\",\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ];\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(\n packageManager,\n \"execute\",\n commandArgs,\n )!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n // Start the PocketBase server process. The package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `pocketbase-server exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAaO,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACzE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAM;CAAM;CACxE;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CACxE;CAAM;CAAM;AACd,CAAC;AAED,SAASC,EAAe,GAA+B;CACrD,OAAO,IAAI,SAAS,GAAS,MAAW;EACtC,IAAMC,IAASH,EAAI,aAAa;EAGhC,AAFAG,EAAO,MAAM,GACbA,EAAO,KAAK,SAASC,CAAM,GAC3BD,EAAO,O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AAMM,EAAGN,CAAE;CACb,UAAU;EAER,EAAgBa,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
@@ -1,5 +1,5 @@
1
1
  import { n as e, s as t } from "./providers-tjlFH5di.js";
2
- import { readEnvVarNames as n } from "./env-vars-ZzWTCtYk.js";
2
+ import { readEnvVarNames as n } from "./env-vars-BbS_mWyP.js";
3
3
  import r from "node:fs";
4
4
  import i from "node:path";
5
5
  // src/runtime/providers.ts
@@ -34,4 +34,4 @@ function s(e) {
34
34
  }
35
35
  export { a as detectProviders };
36
36
 
37
- //# sourceMappingURL=providers-cp9IJLRl.js.map
37
+ //# sourceMappingURL=providers-CDUFaOeQ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"providers-cp9IJLRl.js","names":["capabilityName","providerMarkers","fs","path","detectProviders","detected","present","markerProbe","root","pattern","patterns","ids","provider","capability","envNames","dependencies","marker","readEnvVarNames","readDependencies","file","pkg"],"sources":["../../src/runtime/providers.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { capabilityName, providerMarkers } from \"../core/providers\";\nimport type { DetectedProviders, Pattern, ProviderMarker } from \"../core/types\";\nimport { readEnvVarNames } from \"./env-vars\";\n\ntype DetectablePattern = Pick<\n Pattern,\n \"slug\" | \"providers\" | \"inheritsProvider\"\n>;\n\n/**\n * The provider in use for each capability, read from what the providers left\n * in the project. Nothing records the choice, so this is the only way to know\n * it. A pattern that inherits its provider is skipped: its files say nothing\n * the capability it is built on doesn't already.\n *\n * The registry is passed in rather than imported, so this module and the\n * package entry don't import each other.\n */\nexport function detectProviders(\n root: string,\n patterns: readonly DetectablePattern[],\n): DetectedProviders {\n const detected: DetectedProviders = { providers: {}, ambiguous: [] };\n const present = markerProbe(root);\n\n for (const pattern of patterns) {\n if (!pattern.providers?.length || pattern.inheritsProvider) continue;\n const ids = pattern.providers\n .filter((provider) => providerMarkers(provider).some(present))\n .map((provider) => provider.id);\n\n const capability = capabilityName(pattern.slug);\n if (ids.length === 1) detected.providers[capability] = ids[0];\n if (ids.length > 1) detected.ambiguous.push({ capability, ids });\n }\n\n return detected;\n}\n\n/** Checks one marker against the project; `src/env.ts` and `package.json` are read once. */\nfunction markerProbe(root: string): (marker: ProviderMarker) => boolean {\n let envNames: Set<string> | undefined;\n let dependencies: Set<string> | undefined;\n\n return (marker) => {\n if (\"env\" in marker) {\n envNames ??= readEnvVarNames(root);\n return envNames.has(marker.env);\n }\n if (\"path\" in marker) {\n return fs.existsSync(path.join(root, marker.path));\n }\n dependencies ??= readDependencies(root);\n return dependencies.has(marker.dependency);\n };\n}\n\nfunction readDependencies(root: string): Set<string> {\n const file = path.join(root, \"package.json\");\n if (!fs.existsSync(file)) return new Set();\n try {\n const pkg = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n } catch {\n return new Set();\n }\n}\n"],"mappings":";;;;;AAoBA,SAAgBI,EACd,GACA,GACmB;CACnB,IAAMC,IAA8B;EAAE,WAAW,CAAC;EAAG,WAAW,CAAC;CAAE,GAC7DC,IAAUC,EAAYC,CAAI;CAEhC,KAAK,IAAMC,KAAWC,GAAU;EAC9B,IAAI,CAACD,EAAQ,WAAW,UAAUA,EAAQ,kBAAkB;EAC5D,IAAME,IAAMF,EAAQ,UACjB,QAAQ,MAAaR,EAAgBW,CAAQ,CAAC,CAAC,KAAKN,CAAO,CAAC,CAAC,CAC7D,KAAK,MAAaM,EAAS,EAAE,GAE1BC,IAAab,EAAeS,EAAQ,IAAI;EAE9C,AADIE,EAAI,WAAW,MAAG,EAAS,UAAUE,KAAcF,EAAI,KACvDA,EAAI,SAAS,KAAGN,EAAS,UAAU,KAAK;GAAE;GAAY;EAAI,CAAC;CACjE;CAEA,OAAOA;AACT;AAGA,SAASE,EAAY,GAAmD;CACtE,IAAIO,GACAC;CAEJ,QAAQ,MACF,SAASC,KACX,MAAaC,EAAgBT,CAAI,GAC1BM,EAAS,IAAIE,EAAO,GAAG,KAE5B,UAAUA,IACLd,EAAG,WAAWC,EAAK,KAAKK,GAAMQ,EAAO,IAAI,CAAC,KAEnD,MAAiBE,EAAiBV,CAAI,GAC/BO,EAAa,IAAIC,EAAO,UAAU;AAE7C;AAEA,SAASE,EAAiB,GAA2B;CACnD,IAAMC,IAAOhB,EAAK,KAAKK,GAAM,cAAc;CAC3C,IAAI,CAACN,EAAG,WAAWiB,CAAI,GAAG,uBAAO,IAAI,IAAI;CACzC,IAAI;EACF,IAAMC,IAAM,KAAK,MAAMlB,EAAG,aAAaiB,GAAM,MAAM,CAAC;EAIpD,uBAAO,IAAI,IAAI,CACb,GAAG,OAAO,KAAKC,EAAI,gBAAgB,CAAC,CAAC,GACrC,GAAG,OAAO,KAAKA,EAAI,mBAAmB,CAAC,CAAC,CAC1C,CAAC;CACH,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF"}
1
+ {"version":3,"file":"providers-CDUFaOeQ.js","names":["capabilityName","providerMarkers","fs","path","detectProviders","detected","present","markerProbe","root","pattern","patterns","ids","provider","capability","envNames","dependencies","marker","readEnvVarNames","readDependencies","file","pkg"],"sources":["../../src/runtime/providers.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { capabilityName, providerMarkers } from \"../core/providers\";\nimport type { DetectedProviders, Pattern, ProviderMarker } from \"../core/types\";\nimport { readEnvVarNames } from \"./env-vars\";\n\ntype DetectablePattern = Pick<\n Pattern,\n \"slug\" | \"providers\" | \"inheritsProvider\"\n>;\n\n/**\n * The provider in use for each capability, read from what the providers left\n * in the project. Nothing records the choice, so this is the only way to know\n * it. A pattern that inherits its provider is skipped: its files say nothing\n * the capability it is built on doesn't already.\n *\n * The registry is passed in rather than imported, so this module and the\n * package entry don't import each other.\n */\nexport function detectProviders(\n root: string,\n patterns: readonly DetectablePattern[],\n): DetectedProviders {\n const detected: DetectedProviders = { providers: {}, ambiguous: [] };\n const present = markerProbe(root);\n\n for (const pattern of patterns) {\n if (!pattern.providers?.length || pattern.inheritsProvider) continue;\n const ids = pattern.providers\n .filter((provider) => providerMarkers(provider).some(present))\n .map((provider) => provider.id);\n\n const capability = capabilityName(pattern.slug);\n if (ids.length === 1) detected.providers[capability] = ids[0];\n if (ids.length > 1) detected.ambiguous.push({ capability, ids });\n }\n\n return detected;\n}\n\n/** Checks one marker against the project; `src/env.ts` and `package.json` are read once. */\nfunction markerProbe(root: string): (marker: ProviderMarker) => boolean {\n let envNames: Set<string> | undefined;\n let dependencies: Set<string> | undefined;\n\n return (marker) => {\n if (\"env\" in marker) {\n envNames ??= readEnvVarNames(root);\n return envNames.has(marker.env);\n }\n if (\"path\" in marker) {\n return fs.existsSync(path.join(root, marker.path));\n }\n dependencies ??= readDependencies(root);\n return dependencies.has(marker.dependency);\n };\n}\n\nfunction readDependencies(root: string): Set<string> {\n const file = path.join(root, \"package.json\");\n if (!fs.existsSync(file)) return new Set();\n try {\n const pkg = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n } catch {\n return new Set();\n }\n}\n"],"mappings":";;;;;AAoBA,SAAgBI,EACd,GACA,GACmB;CACnB,IAAMC,IAA8B;EAAE,WAAW,CAAC;EAAG,WAAW,CAAC;CAAE,GAC7DC,IAAUC,EAAYC,CAAI;CAEhC,KAAK,IAAMC,KAAWC,GAAU;EAC9B,IAAI,CAACD,EAAQ,WAAW,UAAUA,EAAQ,kBAAkB;EAC5D,IAAME,IAAMF,EAAQ,UACjB,QAAQ,MAAaR,EAAgBW,CAAQ,CAAC,CAAC,KAAKN,CAAO,CAAC,CAAC,CAC7D,KAAK,MAAaM,EAAS,EAAE,GAE1BC,IAAab,EAAeS,EAAQ,IAAI;EAE9C,AADIE,EAAI,WAAW,MAAG,EAAS,UAAUE,KAAcF,EAAI,KACvDA,EAAI,SAAS,KAAGN,EAAS,UAAU,KAAK;GAAE;GAAY;EAAI,CAAC;CACjE;CAEA,OAAOA;AACT;AAGA,SAASE,EAAY,GAAmD;CACtE,IAAIO,GACAC;CAEJ,QAAQ,MACF,SAASC,KACX,MAAaC,EAAgBT,CAAI,GAC1BM,EAAS,IAAIE,EAAO,GAAG,KAE5B,UAAUA,IACLd,EAAG,WAAWC,EAAK,KAAKK,GAAMQ,EAAO,IAAI,CAAC,KAEnD,MAAiBE,EAAiBV,CAAI,GAC/BO,EAAa,IAAIC,EAAO,UAAU;AAE7C;AAEA,SAASE,EAAiB,GAA2B;CACnD,IAAMC,IAAOhB,EAAK,KAAKK,GAAM,cAAc;CAC3C,IAAI,CAACN,EAAG,WAAWiB,CAAI,GAAG,uBAAO,IAAI,IAAI;CACzC,IAAI;EACF,IAAMC,IAAM,KAAK,MAAMlB,EAAG,aAAaiB,GAAM,MAAM,CAAC;EAIpD,uBAAO,IAAI,IAAI,CACb,GAAG,OAAO,KAAKC,EAAI,gBAAgB,CAAC,CAAC,GACrC,GAAG,OAAO,KAAKA,EAAI,mBAAmB,CAAC,CAAC,CAC1C,CAAC;CACH,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF"}
@@ -15,7 +15,7 @@ async function n(e, t) {
15
15
  exists: !0,
16
16
  rowCount: 0
17
17
  }));
18
- let { withPocketbase: n } = await import("./pocketbase-BTLraFEp.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-DMdTP6H_.js").then((e) => e.n), i = [];
18
+ let { withPocketbase: n } = await import("./pocketbase-S8lUt0nI.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-B_-NTtLW.js").then((e) => e.n), i = [];
19
19
  return await n(t.root, async (t) => {
20
20
  let n = await r(t, e);
21
21
  i.push(...n);
@@ -23,4 +23,4 @@ async function n(e, t) {
23
23
  }
24
24
  export { t as n, n as t };
25
25
 
26
- //# sourceMappingURL=shared-Be8NptJO.js.map
26
+ //# sourceMappingURL=shared-BjTRQ5QH.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-Be8NptJO.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
1
+ {"version":3,"file":"shared-BjTRQ5QH.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
2
  import { a as t } from "./util-ILWdjRAd.js";
3
- import { i as n } from "./pocketbase-BTLraFEp.js";
3
+ import { i as n } from "./pocketbase-S8lUt0nI.js";
4
4
  import r from "node:fs";
5
5
  import i from "node:path";
6
6
  // src/runtime/site.ts
@@ -145,4 +145,4 @@ async function b(n, i) {
145
145
  }
146
146
  export { d as a, p as i, y as n, s as o, f as r, a as s, b as t };
147
147
 
148
- //# sourceMappingURL=site-BHCX2hbj.js.map
148
+ //# sourceMappingURL=site-C8Wcg6LT.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"site-BHCX2hbj.js","names":["getLogger","languageFromPath","withPocketbase","fs","path","sitePath","root","BUSINESS_KEYS","siteModule","declared","business","lines","key","propertyLines","properties","quote","name","url","entry","i","ensureComma","value","SUPPORTED_CURRENCIES","normalizeCurrency","raw","code","normalizeCountry","normalizeCurrencies","entries","codes","home","SITE_OBJECT","withSiteProperty","match","source","body","siteBusiness","text","shape","list","currency","country","m","existingName","options","appName","pb","pkg","ensureSiteFile","file","ensureSiteBusiness","wanted","existing","added","next"],"sources":["../../src/runtime/site.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options } from \"../core/types\";\nimport { getLogger } from \"../core/logger\";\nimport { languageFromPath } from \"../core/util\";\nimport { withPocketbase } from \"./pocketbase\";\n\n/** Where every VelaStack app keeps its name and public URL. */\nexport function sitePath(root: string): string {\n return path.join(root, \"src\", \"lib\", \"site.ts\");\n}\n\n/**\n * What a business declares about itself in `src/lib/site.ts`, next to the\n * app's name: the currency it prices in and is paid in, the country it is in\n * (prices format for it: `es-MX`, not `es`) and the other currencies it shows\n * prices in, as estimates. Every property is optional; a payments provider\n * asks for what it needs.\n */\nexport interface SiteBusiness {\n /** ISO 4217, e.g. `MXN`. */\n currency?: string;\n /** ISO 3166-1 alpha-2, e.g. `MX`. */\n country?: string;\n /** ISO 4217 codes the site also shows prices in; empty means the home currency only. */\n currencies?: string[];\n}\n\ntype BusinessKey = keyof SiteBusiness;\n\nconst BUSINESS_KEYS: BusinessKey[] = [\"currency\", \"country\", \"currencies\"];\n\n/**\n * `src/lib/site.ts` as the CLI templates ship it (`site.template.ts`), with\n * the placeholders filled in, plus whatever the business declares.\n */\nexport function siteModule(\n name: string,\n url = \"http://localhost:5173\",\n business: SiteBusiness | string = {},\n): string {\n // The old third argument was the currency alone.\n const declared: SiteBusiness =\n typeof business === \"string\" ? { currency: business } : business;\n const lines = BUSINESS_KEYS.filter((key) => declared[key] !== undefined).map(\n (key) => propertyLines(key, declared[key]!),\n );\n const properties = [\n `\\tname: ${quote(name)},`,\n `\\turl: ${quote(url)}`,\n ...lines.map((entry) => entry.join(\"\\n\")),\n ];\n return [\n \"/**\",\n \" * Site-wide metadata, and the one place the app's name and public URL live.\",\n \" *\",\n \" * Set `url` to where the site is deployed: canonical links, Open Graph images\",\n \" * and feeds are built from it, including in prerendered pages. With a backend,\",\n \" * `vela dev` and `vela deploy` copy `name` into PocketBase's application name\",\n \" * for the emails it sends, so change it here rather than in the admin panel.\",\n \" */\",\n \"export const site = {\",\n // Every property but the last ends in a comma.\n ...properties.map((entry, i) =>\n i < properties.length - 1 ? ensureComma(entry) : entry,\n ),\n \"};\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction ensureComma(entry: string): string {\n return entry.endsWith(\",\") ? entry : `${entry},`;\n}\n\n/** A property's lines: its doc comment, then `key: value` with no trailing comma. */\nfunction propertyLines(key: BusinessKey, value: string | string[]): string[] {\n switch (key) {\n case \"currency\":\n return [\n \"\\t/** ISO 4217: the currency the business prices in and is paid in. */\",\n `\\tcurrency: ${quote(value as string)}`,\n ];\n case \"country\":\n return [\n \"\\t/** ISO 3166-1: the country the business is in; prices format for it. */\",\n `\\tcountry: ${quote(value as string)}`,\n ];\n case \"currencies\":\n return [\n \"\\t/** Other currencies prices are shown in, as estimates at the day's rate. */\",\n `\\tcurrencies: [${(value as string[]).map(quote).join(\", \")}]`,\n ];\n }\n}\n\nconst SUPPORTED_CURRENCIES = (\n Intl as unknown as {\n supportedValuesOf: (key: \"currency\") => string[];\n }\n).supportedValuesOf(\"currency\");\n\n/** A three-letter code `Intl` knows, upper-cased; anything else is refused. */\nexport function normalizeCurrency(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{3}$/.test(code)) return null;\n // Any well-formed code formats, so ask for the list of real ones. Node has\n // had it since 18; the repo's ES2020 lib types just don't declare it.\n return SUPPORTED_CURRENCIES.includes(code) ? code : null;\n}\n\n/** A two-letter ISO 3166-1 code, upper-cased; anything else is refused. */\nexport function normalizeCountry(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{2}$/.test(code)) return null;\n // `Intl.DisplayNames` knows every region; an unknown one comes back as is.\n const names = new Intl.DisplayNames([\"en\"], { type: \"region\" });\n return names.of(code) !== code ? code : null;\n}\n\n/**\n * A list of currency codes, from an array or a comma-separated string,\n * upper-cased and deduplicated; `null` when any entry is not a currency.\n * `home` is left out: the business's own currency is never a display one.\n */\nexport function normalizeCurrencies(\n raw: unknown,\n home?: string,\n): string[] | null {\n const entries = Array.isArray(raw)\n ? raw\n : typeof raw === \"string\"\n ? raw.split(/[,\\s]+/)\n : null;\n if (!entries) return null;\n const codes: string[] = [];\n for (const entry of entries) {\n if (entry === \"\" || entry === undefined) continue;\n const code = normalizeCurrency(entry);\n if (!code) return null;\n if (code !== home && !codes.includes(code)) codes.push(code);\n }\n return codes;\n}\n\nconst SITE_OBJECT = /export const site = \\{\\n([\\s\\S]*?)\\n\\};/;\n\n/**\n * `src/lib/site.ts` with `key` added as the object's last property, or\n * `null` when it already has one (a project's declaration is never changed\n * behind its back) or has no `export const site = { ... };` to add it to.\n */\nexport function withSiteProperty(\n source: string,\n key: BusinessKey,\n value: string | string[],\n): string | null {\n const match = SITE_OBJECT.exec(source);\n if (!match || new RegExp(`^\\\\s*${key}\\\\s*:`, \"m\").test(match[1])) return null;\n const body = match[1].replace(/,?\\s*$/, \",\");\n return source.replace(\n match[0],\n `export const site = {\\n${body}\\n${propertyLines(key, value).join(\"\\n\")}\\n};`,\n );\n}\n\n/** `withSiteProperty` for the currency, as the Phase 1.5 code called it. */\nexport function withSiteCurrency(\n source: string,\n currency: string,\n): string | null {\n return withSiteProperty(source, \"currency\", currency);\n}\n\n/** What `src/lib/site.ts` declares about the business, if anything. */\nexport function siteBusiness(root: string): SiteBusiness {\n let source: string;\n try {\n source = fs.readFileSync(sitePath(root), \"utf8\");\n } catch {\n return {};\n }\n const text = (key: string, shape: string) =>\n new RegExp(`^\\\\s*${key}\\\\s*:\\\\s*['\"](${shape})['\"]`, \"m\").exec(source)?.[1];\n const list = /^\\s*currencies\\s*:\\s*\\[([^\\]]*)\\]/m.exec(source)?.[1];\n const business: SiteBusiness = {};\n const currency = text(\"currency\", \"[A-Za-z]{3}\");\n if (currency) business.currency = currency;\n const country = text(\"country\", \"[A-Za-z]{2}\");\n if (country) business.country = country;\n if (list !== undefined) {\n business.currencies = [...list.matchAll(/['\"]([A-Za-z]{3})['\"]/g)].map(\n (m) => m[1],\n );\n }\n return business;\n}\n\n/** The currency `src/lib/site.ts` declares, if any. */\nexport function siteCurrency(root: string): string | null {\n return siteBusiness(root).currency ?? null;\n}\n\n/** Single-quoted, as the templates write their strings. */\nfunction quote(value: string): string {\n return `'${value.replace(/\\\\/g, \"\\\\\\\\\").replace(/'/g, \"\\\\'\")}'`;\n}\n\n/**\n * The name a project created before `site.ts` existed already goes by.\n *\n * Those projects kept it in PocketBase's settings, so that is asked first; the\n * package name is the fallback for a project without a backend, or one whose\n * database can't be reached.\n */\nasync function existingName(options: Options): Promise<string> {\n if (options.features.backend) {\n try {\n let appName: unknown;\n await withPocketbase(options.root, async (pb) => {\n const settings = (await pb.settings.getAll()) as {\n meta?: { appName?: unknown };\n };\n appName = settings.meta?.appName;\n });\n if (typeof appName === \"string\" && appName.trim()) return appName;\n } catch {\n // No database to ask; fall through to package.json.\n }\n }\n\n try {\n const pkg = JSON.parse(\n fs.readFileSync(path.join(options.root, \"package.json\"), \"utf8\"),\n ) as { name?: unknown };\n if (typeof pkg.name === \"string\" && pkg.name.trim()) return pkg.name;\n } catch {\n // No package.json to name the site after; the placeholder stands.\n }\n return \"My App\";\n}\n\n/**\n * Create `src/lib/site.ts` for a pattern whose files import `#lib/site.js`, when\n * the project doesn't have one yet. Every template ships it; projects created\n * before that read the app name from `locals.meta` instead.\n *\n * Returns null when the file exists, so an existing one is never overwritten.\n */\nexport async function ensureSiteFile(options: Options): Promise<File | null> {\n const file = sitePath(options.root);\n if (fs.existsSync(file)) return null;\n\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options)),\n status: \"success\",\n };\n}\n\n/**\n * Make `src/lib/site.ts` declare what the business says about itself: create\n * the file with it, or add the properties an existing one lacks. A property\n * already there is kept, whatever `business` says; the result says what the\n * file declares after the call, and the file to write, if anything changed.\n */\nexport async function ensureSiteBusiness(\n options: Options,\n business: SiteBusiness,\n): Promise<{ file: File | null; business: SiteBusiness }> {\n const file = sitePath(options.root);\n const wanted = BUSINESS_KEYS.filter((key) => business[key] !== undefined);\n if (!fs.existsSync(file)) {\n if (wanted.length === 0) return { file: null, business: {} };\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options), undefined, business),\n status: \"success\",\n },\n business,\n };\n }\n\n const existing = siteBusiness(options.root);\n let source = fs.readFileSync(file, \"utf8\");\n const added: string[] = [];\n for (const key of wanted) {\n if (existing[key] !== undefined) continue;\n const next = withSiteProperty(source, key, business[key]!);\n if (next === null) continue;\n source = next;\n added.push(key);\n (existing as Record<string, unknown>)[key] = business[key];\n }\n if (added.length === 0) return { file: null, business: existing };\n getLogger(options).info(`Adding ${added.join(\", \")} to src/lib/site.ts`);\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: source,\n status: \"success\",\n },\n business: existing,\n };\n}\n\n/** `ensureSiteBusiness` for the currency alone, as the Phase 1.5 code called it. */\nexport async function ensureSiteCurrency(\n options: Options,\n currency: string,\n): Promise<{ file: File | null; currency: string }> {\n const { file, business } = await ensureSiteBusiness(options, { currency });\n return { file, currency: business.currency ?? currency };\n}\n"],"mappings":";;;;;;AAQA,SAAgBK,EAAS,GAAsB;CAC7C,OAAOD,EAAK,KAAKE,GAAM,OAAO,OAAO,SAAS;AAChD;AAoBA,IAAMC,IAA+B;CAAC;CAAY;CAAW;AAAY;AAMzE,SAAgBC,EACd,GACA,IAAM,yBACN,IAAkC,CAAC,GAC3B;CAER,IAAMC,IACJ,OAAOC,KAAa,WAAW,EAAE,UAAUA,EAAS,IAAIA,GACpDC,IAAQJ,EAAc,QAAQ,MAAQE,EAASG,OAAS,KAAA,CAAS,CAAC,CAAC,KACtE,MAAQC,EAAcD,GAAKH,EAASG,EAAK,CAC5C,GACME,IAAa;EACjB,WAAWC,EAAMC,CAAI,EAAE;EACvB,UAAUD,EAAME,CA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,CAAC,CAAC,KAAK,0BAA0B,GAC3C;EACL,MAAM;GACJ,MAAMK;GACN,UAAUhD,EAAiBgD,CAAI;GAC/B,SAASzC,EAAW,MAAMmC,EAAaC,CAAO,GAAG,KAAA,GAAWlC,CAAQ;GACpE,QAAQ;EACV;EACA;CACF;CAGF,IAAM0C,IAAWhB,EAAaQ,EAAQ,IAAI,GACtCV,IAAS/B,EAAG,aAAa8C,GAAM,MAAM,GACnCI,IAAkB,CAAC;CACzB,KAAK,IAAMzC,KAAOuC,GAAQ;EACxB,IAAIC,EAASxC,OAAS,KAAA,GAAW;EACjC,IAAM0C,IAAOtB,EAAiBE,GAAQtB,GAAKF,EAASE,EAAK;EACzD,AAAI0C,MAAS,SACb,IAASA,GACTD,EAAM,KAAKzC,CAAG,GACd,EAAsCA,KAAOF,EAASE;CACxD;CAGA,OAFIyC,EAAM,WAAW,IAAU;EAAE,MAAM;EAAM,UAAUD;CAAS,KAChEpD,EAAU4C,CAAO,CAAC,CAAC,KAAK,UAAUS,EAAM,KAAK,IAAI,EAAE,oBAAoB,GAChE;EACL,MAAM;GACJ,MAAMJ;GACN,UAAUhD,EAAiBgD,CAAI;GAC/B,SAASf;GACT,QAAQ;EACV;EACA,UAAUkB;CACZ;AACF"}
1
+ {"version":3,"file":"site-C8Wcg6LT.js","names":["getLogger","languageFromPath","withPocketbase","fs","path","sitePath","root","BUSINESS_KEYS","siteModule","declared","business","lines","key","propertyLines","properties","quote","name","url","entry","i","ensureComma","value","SUPPORTED_CURRENCIES","normalizeCurrency","raw","code","normalizeCountry","normalizeCurrencies","entries","codes","home","SITE_OBJECT","withSiteProperty","match","source","body","siteBusiness","text","shape","list","currency","country","m","existingName","options","appName","pb","pkg","ensureSiteFile","file","ensureSiteBusiness","wanted","existing","added","next"],"sources":["../../src/runtime/site.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options } from \"../core/types\";\nimport { getLogger } from \"../core/logger\";\nimport { languageFromPath } from \"../core/util\";\nimport { withPocketbase } from \"./pocketbase\";\n\n/** Where every VelaStack app keeps its name and public URL. */\nexport function sitePath(root: string): string {\n return path.join(root, \"src\", \"lib\", \"site.ts\");\n}\n\n/**\n * What a business declares about itself in `src/lib/site.ts`, next to the\n * app's name: the currency it prices in and is paid in, the country it is in\n * (prices format for it: `es-MX`, not `es`) and the other currencies it shows\n * prices in, as estimates. Every property is optional; a payments provider\n * asks for what it needs.\n */\nexport interface SiteBusiness {\n /** ISO 4217, e.g. `MXN`. */\n currency?: string;\n /** ISO 3166-1 alpha-2, e.g. `MX`. */\n country?: string;\n /** ISO 4217 codes the site also shows prices in; empty means the home currency only. */\n currencies?: string[];\n}\n\ntype BusinessKey = keyof SiteBusiness;\n\nconst BUSINESS_KEYS: BusinessKey[] = [\"currency\", \"country\", \"currencies\"];\n\n/**\n * `src/lib/site.ts` as the CLI templates ship it (`site.template.ts`), with\n * the placeholders filled in, plus whatever the business declares.\n */\nexport function siteModule(\n name: string,\n url = \"http://localhost:5173\",\n business: SiteBusiness | string = {},\n): string {\n // The old third argument was the currency alone.\n const declared: SiteBusiness =\n typeof business === \"string\" ? { currency: business } : business;\n const lines = BUSINESS_KEYS.filter((key) => declared[key] !== undefined).map(\n (key) => propertyLines(key, declared[key]!),\n );\n const properties = [\n `\\tname: ${quote(name)},`,\n `\\turl: ${quote(url)}`,\n ...lines.map((entry) => entry.join(\"\\n\")),\n ];\n return [\n \"/**\",\n \" * Site-wide metadata, and the one place the app's name and public URL live.\",\n \" *\",\n \" * Set `url` to where the site is deployed: canonical links, Open Graph images\",\n \" * and feeds are built from it, including in prerendered pages. With a backend,\",\n \" * `vela dev` and `vela deploy` copy `name` into PocketBase's application name\",\n \" * for the emails it sends, so change it here rather than in the admin panel.\",\n \" */\",\n \"export const site = {\",\n // Every property but the last ends in a comma.\n ...properties.map((entry, i) =>\n i < properties.length - 1 ? ensureComma(entry) : entry,\n ),\n \"};\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction ensureComma(entry: string): string {\n return entry.endsWith(\",\") ? entry : `${entry},`;\n}\n\n/** A property's lines: its doc comment, then `key: value` with no trailing comma. */\nfunction propertyLines(key: BusinessKey, value: string | string[]): string[] {\n switch (key) {\n case \"currency\":\n return [\n \"\\t/** ISO 4217: the currency the business prices in and is paid in. */\",\n `\\tcurrency: ${quote(value as string)}`,\n ];\n case \"country\":\n return [\n \"\\t/** ISO 3166-1: the country the business is in; prices format for it. */\",\n `\\tcountry: ${quote(value as string)}`,\n ];\n case \"currencies\":\n return [\n \"\\t/** Other currencies prices are shown in, as estimates at the day's rate. */\",\n `\\tcurrencies: [${(value as string[]).map(quote).join(\", \")}]`,\n ];\n }\n}\n\nconst SUPPORTED_CURRENCIES = (\n Intl as unknown as {\n supportedValuesOf: (key: \"currency\") => string[];\n }\n).supportedValuesOf(\"currency\");\n\n/** A three-letter code `Intl` knows, upper-cased; anything else is refused. */\nexport function normalizeCurrency(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{3}$/.test(code)) return null;\n // Any well-formed code formats, so ask for the list of real ones. Node has\n // had it since 18; the repo's ES2020 lib types just don't declare it.\n return SUPPORTED_CURRENCIES.includes(code) ? code : null;\n}\n\n/** A two-letter ISO 3166-1 code, upper-cased; anything else is refused. */\nexport function normalizeCountry(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{2}$/.test(code)) return null;\n // `Intl.DisplayNames` knows every region; an unknown one comes back as is.\n const names = new Intl.DisplayNames([\"en\"], { type: \"region\" });\n return names.of(code) !== code ? code : null;\n}\n\n/**\n * A list of currency codes, from an array or a comma-separated string,\n * upper-cased and deduplicated; `null` when any entry is not a currency.\n * `home` is left out: the business's own currency is never a display one.\n */\nexport function normalizeCurrencies(\n raw: unknown,\n home?: string,\n): string[] | null {\n const entries = Array.isArray(raw)\n ? raw\n : typeof raw === \"string\"\n ? raw.split(/[,\\s]+/)\n : null;\n if (!entries) return null;\n const codes: string[] = [];\n for (const entry of entries) {\n if (entry === \"\" || entry === undefined) continue;\n const code = normalizeCurrency(entry);\n if (!code) return null;\n if (code !== home && !codes.includes(code)) codes.push(code);\n }\n return codes;\n}\n\nconst SITE_OBJECT = /export const site = \\{\\n([\\s\\S]*?)\\n\\};/;\n\n/**\n * `src/lib/site.ts` with `key` added as the object's last property, or\n * `null` when it already has one (a project's declaration is never changed\n * behind its back) or has no `export const site = { ... };` to add it to.\n */\nexport function withSiteProperty(\n source: string,\n key: BusinessKey,\n value: string | string[],\n): string | null {\n const match = SITE_OBJECT.exec(source);\n if (!match || new RegExp(`^\\\\s*${key}\\\\s*:`, \"m\").test(match[1])) return null;\n const body = match[1].replace(/,?\\s*$/, \",\");\n return source.replace(\n match[0],\n `export const site = {\\n${body}\\n${propertyLines(key, value).join(\"\\n\")}\\n};`,\n );\n}\n\n/** `withSiteProperty` for the currency, as the Phase 1.5 code called it. */\nexport function withSiteCurrency(\n source: string,\n currency: string,\n): string | null {\n return withSiteProperty(source, \"currency\", currency);\n}\n\n/** What `src/lib/site.ts` declares about the business, if anything. */\nexport function siteBusiness(root: string): SiteBusiness {\n let source: string;\n try {\n source = fs.readFileSync(sitePath(root), \"utf8\");\n } catch {\n return {};\n }\n const text = (key: string, shape: string) =>\n new RegExp(`^\\\\s*${key}\\\\s*:\\\\s*['\"](${shape})['\"]`, \"m\").exec(source)?.[1];\n const list = /^\\s*currencies\\s*:\\s*\\[([^\\]]*)\\]/m.exec(source)?.[1];\n const business: SiteBusiness = {};\n const currency = text(\"currency\", \"[A-Za-z]{3}\");\n if (currency) business.currency = currency;\n const country = text(\"country\", \"[A-Za-z]{2}\");\n if (country) business.country = country;\n if (list !== undefined) {\n business.currencies = [...list.matchAll(/['\"]([A-Za-z]{3})['\"]/g)].map(\n (m) => m[1],\n );\n }\n return business;\n}\n\n/** The currency `src/lib/site.ts` declares, if any. */\nexport function siteCurrency(root: string): string | null {\n return siteBusiness(root).currency ?? null;\n}\n\n/** Single-quoted, as the templates write their strings. */\nfunction quote(value: string): string {\n return `'${value.replace(/\\\\/g, \"\\\\\\\\\").replace(/'/g, \"\\\\'\")}'`;\n}\n\n/**\n * The name a project created before `site.ts` existed already goes by.\n *\n * Those projects kept it in PocketBase's settings, so that is asked first; the\n * package name is the fallback for a project without a backend, or one whose\n * database can't be reached.\n */\nasync function existingName(options: Options): Promise<string> {\n if (options.features.backend) {\n try {\n let appName: unknown;\n await withPocketbase(options.root, async (pb) => {\n const settings = (await pb.settings.getAll()) as {\n meta?: { appName?: unknown };\n };\n appName = settings.meta?.appName;\n });\n if (typeof appName === \"string\" && appName.trim()) return appName;\n } catch {\n // No database to ask; fall through to package.json.\n }\n }\n\n try {\n const pkg = JSON.parse(\n fs.readFileSync(path.join(options.root, \"package.json\"), \"utf8\"),\n ) as { name?: unknown };\n if (typeof pkg.name === \"string\" && pkg.name.trim()) return pkg.name;\n } catch {\n // No package.json to name the site after; the placeholder stands.\n }\n return \"My App\";\n}\n\n/**\n * Create `src/lib/site.ts` for a pattern whose files import `#lib/site.js`, when\n * the project doesn't have one yet. Every template ships it; projects created\n * before that read the app name from `locals.meta` instead.\n *\n * Returns null when the file exists, so an existing one is never overwritten.\n */\nexport async function ensureSiteFile(options: Options): Promise<File | null> {\n const file = sitePath(options.root);\n if (fs.existsSync(file)) return null;\n\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options)),\n status: \"success\",\n };\n}\n\n/**\n * Make `src/lib/site.ts` declare what the business says about itself: create\n * the file with it, or add the properties an existing one lacks. A property\n * already there is kept, whatever `business` says; the result says what the\n * file declares after the call, and the file to write, if anything changed.\n */\nexport async function ensureSiteBusiness(\n options: Options,\n business: SiteBusiness,\n): Promise<{ file: File | null; business: SiteBusiness }> {\n const file = sitePath(options.root);\n const wanted = BUSINESS_KEYS.filter((key) => business[key] !== undefined);\n if (!fs.existsSync(file)) {\n if (wanted.length === 0) return { file: null, business: {} };\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options), undefined, business),\n status: \"success\",\n },\n business,\n };\n }\n\n const existing = siteBusiness(options.root);\n let source = fs.readFileSync(file, \"utf8\");\n const added: string[] = [];\n for (const key of wanted) {\n if (existing[key] !== undefined) continue;\n const next = withSiteProperty(source, key, business[key]!);\n if (next === null) continue;\n source = next;\n added.push(key);\n (existing as Record<string, unknown>)[key] = business[key];\n }\n if (added.length === 0) return { file: null, business: existing };\n getLogger(options).info(`Adding ${added.join(\", \")} to src/lib/site.ts`);\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: source,\n status: \"success\",\n },\n business: existing,\n };\n}\n\n/** `ensureSiteBusiness` for the currency alone, as the Phase 1.5 code called it. */\nexport async function ensureSiteCurrency(\n options: Options,\n currency: string,\n): Promise<{ file: File | null; currency: string }> {\n const { file, business } = await ensureSiteBusiness(options, { currency });\n return { file, currency: business.currency ?? currency };\n}\n"],"mappings":";;;;;;AAQA,SAAgBK,EAAS,GAAsB;CAC7C,OAAOD,EAAK,KAAKE,GAAM,OAAO,OAAO,SAAS;AAChD;AAoBA,IAAMC,IAA+B;CAAC;CAAY;CAAW;AAAY;AAMzE,SAAgBC,EACd,GACA,IAAM,yBACN,IAAkC,CAAC,GAC3B;CAER,IAAMC,IACJ,OAAOC,KAAa,WAAW,EAAE,UAAUA,EAAS,IAAIA,GACpDC,IAAQJ,EAAc,QAAQ,MAAQE,EAASG,OAAS,KAAA,CAAS,CAAC,CAAC,KACtE,MAAQC,EAAcD,GAAKH,EAASG,EAAK,CAC5C,GACME,IAAa;EACjB,WAAWC,EAAMC,CAAI,EAAE;EACvB,UAAUD,EAAME,CAAG;EACnB,GAAGN,EAAM,KAAK,MAAUO,EAAM,KAAK,IAAI,CAAC;CAC1C;CACA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA,G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,GAAG,KAAA,GAAWlC,CAAQ;GACpE,QAAQ;EACV;EACA;CACF;CAGF,IAAM0C,IAAWhB,EAAaQ,EAAQ,IAAI,GACtCV,IAAS/B,EAAG,aAAa8C,GAAM,MAAM,GACnCI,IAAkB,CAAC;CACzB,KAAK,IAAMzC,KAAOuC,GAAQ;EACxB,IAAIC,EAASxC,OAAS,KAAA,GAAW;EACjC,IAAM0C,IAAOtB,EAAiBE,GAAQtB,GAAKF,EAASE,EAAK;EACzD,AAAI0C,MAAS,SACb,IAASA,GACTD,EAAM,KAAKzC,CAAG,GACd,EAAsCA,KAAOF,EAASE;CACxD;CAGA,OAFIyC,EAAM,WAAW,IAAU;EAAE,MAAM;EAAM,UAAUD;CAAS,KAChEpD,EAAU4C,CAAO,CAAC,CAAC,KAAK,UAAUS,EAAM,KAAK,IAAI,EAAE,oBAAoB,GAChE;EACL,MAAM;GACJ,MAAMJ;GACN,UAAUhD,EAAiBgD,CAAI;GAC/B,SAASf;GACT,QAAQ;EACV;EACA,UAAUkB;CACZ;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { n as e } from "./rolldown-runtime-CwxnZyOB.js";
2
- import { m as t, p as n } from "./constants-Bo85Ke0C.js";
2
+ import { m as t, p as n } from "./constants-CTp-0HKk.js";
3
3
  import { r, t as i } from "./errors-DdSUZI8f.js";
4
4
  import { n as a } from "./lib-specifier-C3M0WTev.js";
5
5
  import { existsSync as o, readFileSync as s } from "node:fs";
@@ -127,4 +127,4 @@ function O(e) {
127
127
  }
128
128
  export { d as a, v as i, E as n, p as o, y as r, O as t };
129
129
 
130
- //# sourceMappingURL=table-core-JdtTKQKA.js.map
130
+ //# sourceMappingURL=table-core-RvMjoXpT.js.map