@velastack/patterns 0.15.1 → 0.15.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 (127) hide show
  1. package/dist/chunks/{_page-Cg7LjaOE.js → _page-BFUn0CG1.js} +2 -2
  2. package/dist/chunks/{_page-Cg7LjaOE.js.map → _page-BFUn0CG1.js.map} +1 -1
  3. package/dist/chunks/{auth-pages-DSBqKjO0.js → auth-pages-D8n8gfCL.js} +2 -2
  4. package/dist/chunks/{auth-pages-DSBqKjO0.js.map → auth-pages-D8n8gfCL.js.map} +1 -1
  5. package/dist/chunks/{collections-D2_2cxWD.js → collections-Daxlnbm0.js} +2 -2
  6. package/dist/chunks/{collections-D2_2cxWD.js.map → collections-Daxlnbm0.js.map} +1 -1
  7. package/dist/chunks/{constants-DbpctM1D.js → constants-E1I-__KI.js} +18 -18
  8. package/dist/chunks/{constants-DbpctM1D.js.map → constants-E1I-__KI.js.map} +1 -1
  9. package/dist/chunks/{currency.server-CFrwmYra.js → currency.server-BkzwY17R.js} +2 -2
  10. package/dist/chunks/{currency.server-CFrwmYra.js.map → currency.server-BkzwY17R.js.map} +1 -1
  11. package/dist/chunks/{env-vars-Dm3Xy4rl.js → env-vars-C3TSZc4f.js} +3 -3
  12. package/dist/chunks/{env-vars-Dm3Xy4rl.js.map → env-vars-C3TSZc4f.js.map} +1 -1
  13. package/dist/chunks/{generate-BMWoD9E2.js → generate-CAYM7OUF.js} +2 -2
  14. package/dist/chunks/{generate-BMWoD9E2.js.map → generate-CAYM7OUF.js.map} +1 -1
  15. package/dist/chunks/{generate-DZ9kT3iC.js → generate-CL7wG0ZC.js} +3 -3
  16. package/dist/chunks/{generate-DZ9kT3iC.js.map → generate-CL7wG0ZC.js.map} +1 -1
  17. package/dist/chunks/{generate-BRTIGlqT.js → generate-CbchamhA.js} +3 -3
  18. package/dist/chunks/{generate-BRTIGlqT.js.map → generate-CbchamhA.js.map} +1 -1
  19. package/dist/chunks/{generate-Cs_fdfD7.js → generate-DI58vuk1.js} +2 -2
  20. package/dist/chunks/{generate-Cs_fdfD7.js.map → generate-DI58vuk1.js.map} +1 -1
  21. package/dist/chunks/{generate-BvQ6VwYH.js → generate-DR2wkVPY.js} +2 -2
  22. package/dist/chunks/{generate-BvQ6VwYH.js.map → generate-DR2wkVPY.js.map} +1 -1
  23. package/dist/chunks/{generate.runtime-1eTnPFmA.js → generate.runtime-B11mOr45.js} +2 -2
  24. package/dist/chunks/{generate.runtime-1eTnPFmA.js.map → generate.runtime-B11mOr45.js.map} +1 -1
  25. package/dist/chunks/{generate.runtime-CjLath7N.js → generate.runtime-B1Y2JrGW.js} +5 -5
  26. package/dist/chunks/{generate.runtime-CjLath7N.js.map → generate.runtime-B1Y2JrGW.js.map} +1 -1
  27. package/dist/chunks/{generate.runtime-CnNtG_x5.js → generate.runtime-B7VubPTW.js} +3 -3
  28. package/dist/chunks/{generate.runtime-CnNtG_x5.js.map → generate.runtime-B7VubPTW.js.map} +1 -1
  29. package/dist/chunks/{generate.runtime-BvHK8IN-.js → generate.runtime-BCv4F1Wm.js} +5 -5
  30. package/dist/chunks/{generate.runtime-BvHK8IN-.js.map → generate.runtime-BCv4F1Wm.js.map} +1 -1
  31. package/dist/chunks/{generate.runtime-D8G8cwCr.js → generate.runtime-BEWp57Y7.js} +2 -2
  32. package/dist/chunks/{generate.runtime-D8G8cwCr.js.map → generate.runtime-BEWp57Y7.js.map} +1 -1
  33. package/dist/chunks/{generate.runtime-B4mQEW54.js → generate.runtime-BH6hHygm.js} +3 -3
  34. package/dist/chunks/{generate.runtime-B4mQEW54.js.map → generate.runtime-BH6hHygm.js.map} +1 -1
  35. package/dist/chunks/{generate.runtime-CfCDLJ6Y.js → generate.runtime-BL6DpWFI.js} +3 -3
  36. package/dist/chunks/{generate.runtime-CfCDLJ6Y.js.map → generate.runtime-BL6DpWFI.js.map} +1 -1
  37. package/dist/chunks/{generate.runtime-BJwSyslL.js → generate.runtime-BRV9hIl5.js} +2 -2
  38. package/dist/chunks/{generate.runtime-BJwSyslL.js.map → generate.runtime-BRV9hIl5.js.map} +1 -1
  39. package/dist/chunks/{generate.runtime-B9nVU5iO.js → generate.runtime-BRcP6sFt.js} +2 -2
  40. package/dist/chunks/{generate.runtime-B9nVU5iO.js.map → generate.runtime-BRcP6sFt.js.map} +1 -1
  41. package/dist/chunks/{generate.runtime-BC1GJUXE.js → generate.runtime-Bhs7ttZS.js} +2 -2
  42. package/dist/chunks/{generate.runtime-BC1GJUXE.js.map → generate.runtime-Bhs7ttZS.js.map} +1 -1
  43. package/dist/chunks/{generate.runtime-Bda2_WK7.js → generate.runtime-BjrtdoYE.js} +2 -2
  44. package/dist/chunks/{generate.runtime-Bda2_WK7.js.map → generate.runtime-BjrtdoYE.js.map} +1 -1
  45. package/dist/chunks/{generate.runtime-DBQvnQmR.js → generate.runtime-Bo_s7gYB.js} +2 -2
  46. package/dist/chunks/{generate.runtime-DBQvnQmR.js.map → generate.runtime-Bo_s7gYB.js.map} +1 -1
  47. package/dist/chunks/{generate.runtime-DQUZRJH8.js → generate.runtime-Bs77Oc8P.js} +3 -3
  48. package/dist/chunks/{generate.runtime-DQUZRJH8.js.map → generate.runtime-Bs77Oc8P.js.map} +1 -1
  49. package/dist/chunks/{generate.runtime-Cd742Yqf.js → generate.runtime-C3IswX7B.js} +2 -2
  50. package/dist/chunks/{generate.runtime-Cd742Yqf.js.map → generate.runtime-C3IswX7B.js.map} +1 -1
  51. package/dist/chunks/{generate.runtime-B-H2F-sH.js → generate.runtime-C90_2L-8.js} +3 -3
  52. package/dist/chunks/{generate.runtime-B-H2F-sH.js.map → generate.runtime-C90_2L-8.js.map} +1 -1
  53. package/dist/chunks/{generate.runtime-B4rG6gSK.js → generate.runtime-CDY0Ot_t.js} +6 -6
  54. package/dist/chunks/{generate.runtime-B4rG6gSK.js.map → generate.runtime-CDY0Ot_t.js.map} +1 -1
  55. package/dist/chunks/{generate.runtime-Doumu0TL.js → generate.runtime-CZMVPVjS.js} +6 -6
  56. package/dist/chunks/{generate.runtime-Doumu0TL.js.map → generate.runtime-CZMVPVjS.js.map} +1 -1
  57. package/dist/chunks/{generate.runtime-liAz2TOE.js → generate.runtime-C_hrLPD4.js} +3 -3
  58. package/dist/chunks/{generate.runtime-liAz2TOE.js.map → generate.runtime-C_hrLPD4.js.map} +1 -1
  59. package/dist/chunks/{generate.runtime-DE-vPcn4.js → generate.runtime-CdZ3GzPS.js} +6 -6
  60. package/dist/chunks/{generate.runtime-DE-vPcn4.js.map → generate.runtime-CdZ3GzPS.js.map} +1 -1
  61. package/dist/chunks/{generate.runtime-BkQPchHe.js → generate.runtime-ChSVP7cD.js} +6 -6
  62. package/dist/chunks/{generate.runtime-BkQPchHe.js.map → generate.runtime-ChSVP7cD.js.map} +1 -1
  63. package/dist/chunks/{generate.runtime-C1HlZnLC.js → generate.runtime-Cs73i6Zf.js} +2 -2
  64. package/dist/chunks/{generate.runtime-C1HlZnLC.js.map → generate.runtime-Cs73i6Zf.js.map} +1 -1
  65. package/dist/chunks/{generate.runtime-GmsldrGj.js → generate.runtime-D7KYlnvb.js} +3 -3
  66. package/dist/chunks/{generate.runtime-GmsldrGj.js.map → generate.runtime-D7KYlnvb.js.map} +1 -1
  67. package/dist/chunks/{generate.runtime-DFSsgOmB.js → generate.runtime-DG9LRwbt.js} +3 -3
  68. package/dist/chunks/{generate.runtime-DFSsgOmB.js.map → generate.runtime-DG9LRwbt.js.map} +1 -1
  69. package/dist/chunks/{generate.runtime-CIOi-XSm.js → generate.runtime-DKL7VAAd.js} +6 -6
  70. package/dist/chunks/{generate.runtime-CIOi-XSm.js.map → generate.runtime-DKL7VAAd.js.map} +1 -1
  71. package/dist/chunks/{generate.runtime-CQ_U4YTJ.js → generate.runtime-DP63Wwea.js} +4 -4
  72. package/dist/chunks/{generate.runtime-CQ_U4YTJ.js.map → generate.runtime-DP63Wwea.js.map} +1 -1
  73. package/dist/chunks/{generate.runtime-C62ChKGg.js → generate.runtime-DRPxOLnB.js} +4 -4
  74. package/dist/chunks/{generate.runtime-C62ChKGg.js.map → generate.runtime-DRPxOLnB.js.map} +1 -1
  75. package/dist/chunks/{generate.runtime-DQI69jkX.js → generate.runtime-DW9bqOtC.js} +2 -2
  76. package/dist/chunks/{generate.runtime-DQI69jkX.js.map → generate.runtime-DW9bqOtC.js.map} +1 -1
  77. package/dist/chunks/{generate.runtime-Dtum580c.js → generate.runtime-DdY44Ulv.js} +6 -6
  78. package/dist/chunks/{generate.runtime-Dtum580c.js.map → generate.runtime-DdY44Ulv.js.map} +1 -1
  79. package/dist/chunks/{generate.runtime-ufoTIUXA.js → generate.runtime-DjEj-n6m.js} +7 -7
  80. package/dist/chunks/{generate.runtime-ufoTIUXA.js.map → generate.runtime-DjEj-n6m.js.map} +1 -1
  81. package/dist/chunks/{generate.runtime-rxzMCECc.js → generate.runtime-DlAJQ5Js.js} +4 -4
  82. package/dist/chunks/{generate.runtime-rxzMCECc.js.map → generate.runtime-DlAJQ5Js.js.map} +1 -1
  83. package/dist/chunks/{generate.runtime-CZA46Ghe.js → generate.runtime-JftBoKYS.js} +5 -5
  84. package/dist/chunks/{generate.runtime-CZA46Ghe.js.map → generate.runtime-JftBoKYS.js.map} +1 -1
  85. package/dist/chunks/{generate.runtime-DNjyaFml.js → generate.runtime-_426A1Ij.js} +3 -3
  86. package/dist/chunks/{generate.runtime-DNjyaFml.js.map → generate.runtime-_426A1Ij.js.map} +1 -1
  87. package/dist/chunks/{generate.runtime-DR8z6DyZ.js → generate.runtime-fs6GEMx-.js} +5 -5
  88. package/dist/chunks/{generate.runtime-DR8z6DyZ.js.map → generate.runtime-fs6GEMx-.js.map} +1 -1
  89. package/dist/chunks/{generate.runtime-Diix70x4.js → generate.runtime-jIlQ2GMh.js} +2 -2
  90. package/dist/chunks/{generate.runtime-Diix70x4.js.map → generate.runtime-jIlQ2GMh.js.map} +1 -1
  91. package/dist/chunks/{generate.runtime-BuQASx9Y.js → generate.runtime-v3KCv1B6.js} +2 -2
  92. package/dist/chunks/{generate.runtime-BuQASx9Y.js.map → generate.runtime-v3KCv1B6.js.map} +1 -1
  93. package/dist/chunks/{generate.runtime-lP4eoera.js → generate.runtime-xrxAElb3.js} +3 -3
  94. package/dist/chunks/{generate.runtime-lP4eoera.js.map → generate.runtime-xrxAElb3.js.map} +1 -1
  95. package/dist/chunks/{gitignore-2XpeEFmr.js → gitignore-CBiWFRif.js} +3 -3
  96. package/dist/chunks/{gitignore-2XpeEFmr.js.map → gitignore-CBiWFRif.js.map} +1 -1
  97. package/dist/chunks/{i18n-CxT1kz8Y.js → i18n-Ho8H91Ze.js} +2 -2
  98. package/dist/chunks/{i18n-CxT1kz8Y.js.map → i18n-Ho8H91Ze.js.map} +1 -1
  99. package/dist/chunks/{modify-file-BX9-aZD1.js → modify-file-BOEKlIDw.js} +2 -2
  100. package/dist/chunks/{modify-file-BX9-aZD1.js.map → modify-file-BOEKlIDw.js.map} +1 -1
  101. package/dist/chunks/{pocketbase-Dq9UdK_j.js → pocketbase-B2ksFrvH.js} +2 -2
  102. package/dist/chunks/{pocketbase-Dq9UdK_j.js.map → pocketbase-B2ksFrvH.js.map} +1 -1
  103. package/dist/chunks/{providers-2UgxXRJW.js → providers-BEjDonyG.js} +2 -2
  104. package/dist/chunks/{providers-2UgxXRJW.js.map → providers-BEjDonyG.js.map} +1 -1
  105. package/dist/chunks/{route-BDhlro0V.js → route-9ZVJZkYu.js} +23 -19
  106. package/dist/chunks/route-9ZVJZkYu.js.map +1 -0
  107. package/dist/chunks/{schema-2frI_BS2.js → schema-DnMqw2Hn.js} +3 -3
  108. package/dist/chunks/{schema-2frI_BS2.js.map → schema-DnMqw2Hn.js.map} +1 -1
  109. package/dist/chunks/{shared-BOFCKWJs.js → shared-CSwGWMcN.js} +2 -2
  110. package/dist/chunks/{shared-BOFCKWJs.js.map → shared-CSwGWMcN.js.map} +1 -1
  111. package/dist/chunks/{shared-DJ4KvhTb.js → shared-Cdwm_-Nl.js} +40 -40
  112. package/dist/chunks/{shared-DJ4KvhTb.js.map → shared-Cdwm_-Nl.js.map} +1 -1
  113. package/dist/chunks/{site-qASrdyUt.js → site-B5zrFba9.js} +2 -2
  114. package/dist/chunks/{site-qASrdyUt.js.map → site-B5zrFba9.js.map} +1 -1
  115. package/dist/chunks/{table-core-s2xjYgRD.js → table-core-ux1xEJxN.js} +2 -2
  116. package/dist/chunks/{table-core-s2xjYgRD.js.map → table-core-ux1xEJxN.js.map} +1 -1
  117. package/dist/chunks/{ui-DZuwcswv.js → ui-CpjUq_lm.js} +3 -3
  118. package/dist/chunks/{ui-DZuwcswv.js.map → ui-CpjUq_lm.js.map} +1 -1
  119. package/dist/chunks/{whatsapp-BytvTPlS.js → whatsapp-DOSZ_zwn.js} +2 -2
  120. package/dist/chunks/{whatsapp-BytvTPlS.js.map → whatsapp-DOSZ_zwn.js.map} +1 -1
  121. package/dist/chunks/{write-result-BhfLWAXf.js → write-result-DlB-id5k.js} +50 -26
  122. package/dist/chunks/write-result-DlB-id5k.js.map +1 -0
  123. package/dist/index.js +1863 -1841
  124. package/dist/index.js.map +1 -1
  125. package/package.json +1 -1
  126. package/dist/chunks/route-BDhlro0V.js.map +0 -1
  127. package/dist/chunks/write-result-BhfLWAXf.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-C1HlZnLC.js","names":["FAILURE_HINT","I18N_MODULES","FAILURE_HINT","FAILURE_HINT","normalize","getLogger","revertOutcomeToFile","modifyOutcomeToFile","probeFirstExisting","resolveConfigTarget","saveTarget","VITE_CONFIG_CANDIDATES","LAYOUT_SERVER_SNIPPET","LOCALES_IMPORTS","LOCALS_MEMBER","LEGACY_LOAD_STATEMENT","LOAD_STATEMENT","LOCALS_COMMENT","withInMemoryScript","pruneUnusedImports","removeNamedImportIfUnused","removeTopLevelStatementByIdentifier","removeStatementWithComments","ensureBlankLineAfterImports","formatLikeSource","isEffectivelyEmpty","removeImportByModuleSpecifier","removePackageImports","dedent","removeHandle","libModule","SvelteFile","findLoadFunction","APP_LAYOUT_PATH","APP_LANGUAGE_SELECT","fs","path","unmodifyGitignore","gitignorePath","original","lines","out","i","line","j","hasWuchale","updated","unmodifyPrettierignore","filePath","at","index","unmodifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","removed","arr","SyntaxKind","el","HINTS","unmodifyLocalesAlias","res","root","aliasProp","target","aliasObj","locales","p","localesModule","escaped","name","pattern","specifier","I18N_HANDLE","FAILURE_HINT$3","I18N_MODULES$1","unmodifyHooksServerI18n","hooksServerPath","stmt","s","moduleSpecifier","DELOCALIZE_HELPER","FAILURE_HINT$2","I18N_MODULES","I18N_ONLY_REROUTE","COMPOSED_REROUTE","unmodifyHooksI18n","hooksPath","helperStatement","rerouteDecl","initText","composed","rerouteStatement","unmodifyAppHtml","appHtmlPath","FAILURE_HINT$1","SIDE_EFFECT_MODULES","BINDING_MODULES","WRITTEN_LOADS","normalize$1","source","unmodifyRootLayoutI18n","layoutPath","loadStatement","d","load","written","unmodifyRootLayoutLanguageSelect","file","sf","normalize","LOCALE_COMMENT","FAILURE_HINT","unmodifyLayoutServerLocale","layoutServerPath","properties","property","object","Node","escape","text","MEMBER","EMPTY_LOCALS","unmodifyAppDts","appDtsPath","unmodifyAppLayoutLanguageSelect","generate","logger","options","modifies","deletes","pushResult","imports","alias","hooksServerRevert","hooksRevert","layoutRevert","layoutServerRevert","appLayoutPath","rootLayoutCandidates","candidate","prettierignorePath","localesDir","entry"],"sources":["../../src/patterns/disable/i18n/modifies/gitignore.ts","../../src/patterns/disable/i18n/modifies/prettierignore.ts","../../src/patterns/disable/i18n/modifies/vite-config.ts","../../src/patterns/disable/i18n/modifies/locales-alias.ts","../../src/patterns/disable/i18n/modifies/locales-module.ts","../../src/patterns/disable/i18n/modifies/hooks.server.ts","../../src/patterns/disable/i18n/modifies/hooks.ts","../../src/patterns/disable/i18n/modifies/app-html.ts","../../src/patterns/disable/i18n/modifies/+layout.ts","../../src/patterns/disable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/disable/i18n/modifies/layout.server.ts","../../src/patterns/disable/i18n/modifies/app-d-ts.ts","../../src/patterns/disable/i18n/modifies/app-layout.svelte.ts","../../src/patterns/disable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (!original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const lines = original.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === \"# Wuchale\") {\n let j = i + 1;\n let hasWuchale = false;\n while (j < lines.length && lines[j].trim() !== \"\") {\n if (lines[j] === \"src/locales/.wuchale\") {\n hasWuchale = true;\n }\n j++;\n }\n if (hasWuchale) {\n i = j;\n continue;\n }\n }\n if (line === \"src/locales/.wuchale\") continue;\n out.push(line);\n }\n\n let updated = out.join(\"\\n\");\n updated = updated.replace(/\\n{3,}/g, \"\\n\\n\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LOCALES_ENTRY,\n PRETTIERIGNORE_HEADER,\n} from \"../../../enable/i18n/modifies/prettierignore\";\n\n/** Removes the block enable-i18n appended; an entry the project wrote itself stays. */\nexport function unmodifyPrettierignore(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n const lines = original.split(\"\\n\");\n const at = lines.findIndex(\n (line, index) =>\n line === PRETTIERIGNORE_HEADER && lines[index + 1] === LOCALES_ENTRY,\n );\n if (at === -1) {\n return { status: \"success\", changed: false };\n }\n\n lines.splice(at, 2);\n // The blank line that set the block apart goes with it.\n if (at > 0 && lines[at - 1] === \"\" && (lines[at] ?? \"\") === \"\") {\n lines.splice(at - 1, 1);\n }\n fs.writeFileSync(filePath, lines.join(\"\\n\"));\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** Remove `wuchale()` from the Vite plugins and its import. */\nexport function unmodifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(viteConfigPath, \"utf8\");\n if (!original.includes(\"wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n // One removal at a time: manipulating the tree invalidates sibling nodes.\n for (;;) {\n let removed = false;\n for (const arr of sourceFile.getDescendantsOfKind(\n SyntaxKind.ArrayLiteralExpression,\n )) {\n const index = arr\n .getElements()\n .findIndex((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n if (index >= 0) {\n arr.removeElement(index);\n removed = true;\n break;\n }\n }\n if (!removed) break;\n }\n\n removeImportByModuleSpecifier(sourceFile, \"wuchale/vite\");\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import { SyntaxKind } from \"ts-morph\";\nimport {\n resolveConfigTarget,\n saveTarget,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst HINTS = {\n notFound: \"No SvelteKit config to revert.\",\n failed:\n \"Remove the $locales alias from the sveltekit() arg in vite.config by hand.\",\n};\n\n/**\n * Remove the `$locales` alias enable-i18n wrote before SvelteKit 3, which\n * `sv migrate sveltekit-3` moves into the inline `sveltekit({...})` arg;\n * `alias` goes too once it is empty. Projects enabled since then map\n * `#locales/*` in package.json `imports` instead.\n */\nexport function unmodifyLocalesAlias(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, HINTS);\n // Nothing to revert in a project without a config.\n if (res.status === \"not-found\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n if (res.status === \"failed\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"failed\", message: res.message },\n };\n }\n\n const { target } = res;\n const aliasProp = target.configObject\n .getProperty(\"alias\")\n ?.asKind(SyntaxKind.PropertyAssignment);\n const aliasObj = aliasProp\n ?.getInitializer()\n ?.asKind(SyntaxKind.ObjectLiteralExpression);\n const locales = aliasObj\n ?.getProperties()\n .find((p) => p.getText().replace(/['\"]/g, \"\").startsWith(\"$locales\"));\n if (aliasProp && aliasObj && locales) {\n locales.remove();\n if (aliasObj.getProperties().length === 0) aliasProp.remove();\n }\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n","/**\n * Matches an import of wuchale's `src/locales/<name>.js` the way enable-i18n\n * writes it (`#locales/main.url.js`), and the `$locales/main.url` alias form\n * it wrote before SvelteKit 3, so disabling works on either.\n */\nexport function localesModule(name: string): (specifier: string) => boolean {\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const pattern = new RegExp(`^[$#]locales/${escaped}(\\\\.js)?$`);\n return (specifier) => pattern.test(specifier);\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n removeNamedImportIfUnused,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\nimport { localesModule } from \"./locales-module\";\n\nconst I18N_HANDLE = \"handleWuchale\";\nconst FAILURE_HINT = dedent`\n Take handleWuchale out of the exported handle in src/hooks.server.ts, then\n remove its declaration, the loadLocales(...) calls and the wuchale and\n #locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/load-utils/server\",\n // Since the handle follows the visitor's preference on pages without a\n // language in their URL; a project enabled before has none of the three.\n \"wuchale/url\",\n libModule(\"url.ts\"),\n libModule(\"locale.ts\"),\n localesModule(\"main.url\"),\n localesModule(\"data\"),\n localesModule(\"main.loader.server.svelte\"),\n localesModule(\"js.loader.server\"),\n];\n\n/**\n * Undo `modifyHooksServerI18n`: drop the locale bootstrap, the wuchale handle\n * and its imports, and unwrap `sequence(handleWuchale, ...)`. A file that\n * enable-i18n created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerI18n(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (!original.includes(I18N_HANDLE) && !original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // loadLocales(...) bootstrap calls, one at a time (removal invalidates siblings).\n for (;;) {\n const stmt = sourceFile\n .getStatements()\n .find(\n (s) =>\n s.getKind() === SyntaxKind.ExpressionStatement &&\n /^loadLocales\\s*\\(/.test(s.getText()),\n );\n if (!stmt) break;\n stmt.remove();\n }\n\n // `export const handle = handleWuchale` goes altogether; a sequence loses\n // the argument, or unwraps to the handle it composed with.\n const removed = removeHandle(sourceFile, I18N_HANDLE);\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, I18N_HANDLE);\n for (const moduleSpecifier of I18N_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"Handle\");\n // A project from before SvelteKit 3 imports it from the package root.\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit\", \"Handle\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst DELOCALIZE_HELPER = \"rerouteDeLocalize\";\n\nconst FAILURE_HINT = dedent`\n Take rerouteDeLocalize out of the exported reroute in src/hooks.ts, then\n remove its declaration and the wuchale and #locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/url\",\n localesModule(\"main.url\"),\n localesModule(\"data\"),\n];\n\n/** The two reroutes `modifyHooksI18n` writes: on its own, and composed. */\nconst I18N_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*url\\.pathname\\s*\\)$/;\nconst COMPOSED_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)\\s*\\)$/;\n\n/**\n * Undo `modifyHooksI18n`: drop the de-localizer and its imports, leaving the\n * negotiation reroute it may have been composed with. A file that enable-i18n\n * created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (!original.includes(DELOCALIZE_HELPER)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const helperStatement = sourceFile\n .getVariableDeclaration(DELOCALIZE_HELPER)\n ?.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n const initText = rerouteDecl?.getInitializer()?.getText() ?? \"\";\n const composed = COMPOSED_REROUTE.test(initText);\n const rerouteStatement =\n composed || I18N_ONLY_REROUTE.test(initText)\n ? rerouteDecl?.getFirstAncestorByKind(SyntaxKind.VariableStatement)\n : undefined;\n\n // Anything else reading the de-localizer is code enable-i18n did not write,\n // so undoing it is the developer's call.\n const otherReaders = sourceFile\n .getStatements()\n .filter(\n (s) =>\n s !== helperStatement &&\n s !== rerouteStatement &&\n s.getText().includes(DELOCALIZE_HELPER),\n );\n if (otherReaders.length > 0) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n if (composed) {\n // content-negotiation's reroute is underneath; it stays.\n rerouteDecl?.setInitializer(\"({ url }) => negotiateReroute(url.pathname)\");\n } else if (rerouteStatement) {\n removeTopLevelStatementByIdentifier(sourceFile, \"reroute\");\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, DELOCALIZE_HELPER);\n pruneUnusedImports(sourceFile, I18N_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty hooks.ts into a\n // delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(hooksPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Put a real language back. `%sveltekit.lang%` is not a SvelteKit\n * placeholder; only the wuchale hook replaced it, so without that hook it\n * would be served literally.\n */\nexport function unmodifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n const updated = original.replace(\n /lang\\s*=\\s*(?:\"%sveltekit\\.lang%\"|'%sveltekit\\.lang%')/g,\n 'lang=\"en\"',\n );\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(appHtmlPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type Statement } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LEGACY_LOAD_STATEMENT,\n LOAD_STATEMENT,\n} from \"../../../enable/i18n/modifies/+layout\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeImportByModuleSpecifier,\n removeStatementWithComments,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.ts still loads wuchale locales. Remove these from it:\n\n import { browser } from '$app/env';\n import { loadLocale } from 'wuchale/load-utils';\n import { getLocale } from '#locales/main.url.js';\n import { hasLocalizedUrl } from '#lib/url.js';\n import '#locales/main.loader.svelte.js';\n import '#locales/js.loader.js';\n\n and the loadLocale(...) call inside load().\n`;\n\nconst SIDE_EFFECT_MODULES = [\n localesModule(\"main.loader.svelte\"),\n localesModule(\"js.loader\"),\n];\nconst BINDING_MODULES: ModuleMatch[] = [\n // `$app/env`, or the module it replaced before SvelteKit 3.\n (specifier) => /^\\$app\\/env(ironment)?$/.test(specifier),\n \"wuchale/load-utils\",\n localesModule(\"main.url\"),\n libModule(\"url.ts\"),\n];\n\n/** The loads enable-i18n has written: today's, and the URL-only one before it. */\nconst WRITTEN_LOADS = [LOAD_STATEMENT, LEGACY_LOAD_STATEMENT];\n\nfunction normalize(source: string): string {\n return source.replace(/[\"']/g, \"'\").replace(/\\s+/g, \"\");\n}\n\n/**\n * Undo `ensureRootLayoutI18n`: drop the wuchale load and its imports, leaving\n * whatever else the file holds. A file enable-i18n wrote whole comes out\n * empty, for the caller to delete.\n */\nexport function unmodifyRootLayoutI18n(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(\"loadLocale\") && !/[$#]locales\\//.test(original)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n const loadStatement: Statement | undefined =\n sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"load\")) ??\n sourceFile.getFunction(\"load\");\n\n if (loadStatement) {\n // A load that grew code of its own needs a hand; only the one enable-i18n\n // wrote is safe to take out wholesale.\n const load = normalize(loadStatement.getText());\n if (!WRITTEN_LOADS.some((written) => normalize(written) === load)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n removeStatementWithComments(sourceFile, loadStatement);\n }\n\n for (const moduleSpecifier of SIDE_EFFECT_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n pruneUnusedImports(sourceFile, BINDING_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty +layout.ts into\n // a delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(layoutPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","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\n/** Take the language select (and the nav item enable-i18n wrapped it in) back out. */\nexport function unmodifyRootLayoutLanguageSelect(\n layoutPath: string,\n): 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(\"LanguageSelect\")) {\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(\n sf,\n libModule(\"components/language-select.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n let updated = file.toString();\n updated = updated.replace(\n /[ \\t]*<Navbar\\.Item>\\s*<LanguageSelect\\s*\\/>\\s*<\\/Navbar\\.Item>[ \\t]*\\r?\\n?/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<LanguageSelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { LAYOUT_SERVER_SNIPPET } from \"../../../enable/i18n/modifies/layout.server\";\nimport { Node, SyntaxKind } from \"ts-morph\";\nimport { findLoadFunction } from \"../../../../runtime/load-function\";\nimport {\n removeUnusedBindingElement,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst normalize = (source: string) =>\n source.replace(/[\"']/g, \"'\").replace(/\\s+/g, \"\");\n\n/** The comment enable-i18n put above the property, on its own lines. */\nconst LOCALE_COMMENT =\n /^[ \\t]*\\/\\/ Decided on the server \\(src\\/hooks\\.server\\.ts\\), because pages without a\\r?\\n[ \\t]*\\/\\/ language in their URL follow the visitor's preference\\.\\r?\\n/m;\n\nconst FAILURE_HINT =\n \"src/routes/+layout.server.ts still returns `locale: locals.locale`. Remove it from the load.\";\n\n/**\n * Undo `modifyLayoutServerLocale`: the root layout's server load stops\n * returning `locale`. A file enable-i18n wrote whole comes out empty, for the\n * caller to delete.\n */\nexport function unmodifyLayoutServerLocale(\n layoutServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (!original.includes(\"locals.locale\")) {\n return { status: \"success\", changed: false };\n }\n\n if (normalize(original) === normalize(LAYOUT_SERVER_SNIPPET)) {\n fs.writeFileSync(layoutServerPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n // The comment first: left above a removed property it would attach itself\n // to whatever follows.\n const { source } = withInMemoryScript(\n original.replace(LOCALE_COMMENT, \"\"),\n (sf) => {\n const load = findLoadFunction(sf);\n const properties = (load ?? sf)\n .getDescendantsOfKind(SyntaxKind.PropertyAssignment)\n .filter(\n (property) =>\n property.getName() === \"locale\" &&\n /(^|\\.)locals\\.locale$/.test(\n property.getInitializer()?.getText() ?? \"\",\n ),\n );\n for (const property of properties) {\n const object = property.getParent();\n property.remove();\n // `return {}` reads worse on three lines than on one.\n if (\n Node.isObjectLiteralExpression(object) &&\n object.getProperties().length === 0\n ) {\n object.replaceWithText(\"{}\");\n }\n }\n removeUnusedBindingElement(sf, \"locals\");\n },\n );\n if (source === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(layoutServerPath, source, \"utf8\");\n return { status: \"success\", changed: source !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LOCALS_COMMENT,\n LOCALS_MEMBER,\n} from \"../../../enable/i18n/modifies/app-d-ts\";\n\nconst escape = (text: string) => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nconst MEMBER = new RegExp(\n `(?:^[ \\\\t]*${escape(LOCALS_COMMENT)}[ \\\\t]*\\\\r?\\\\n)?^[ \\\\t]*${escape(LOCALS_MEMBER)}[ \\\\t]*\\\\r?\\\\n`,\n \"m\",\n);\n\n/** An `interface Locals` left with nothing in it. */\nconst EMPTY_LOCALS = /^([ \\t]*)interface Locals\\s*\\{\\s*\\}/m;\n\n/**\n * Undo `modifyAppDts`: `App.Locals` loses `locale`, and an interface left\n * empty goes back to the comment `sv create` writes.\n */\nexport function unmodifyAppDts(appDtsPath: string): ModifyOutcome {\n if (!fs.existsSync(appDtsPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(appDtsPath, \"utf8\");\n if (!MEMBER.test(original)) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original\n .replace(MEMBER, \"\")\n .replace(EMPTY_LOCALS, \"$1// interface Locals {}\");\n fs.writeFileSync(appDtsPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","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\";\nimport { APP_LANGUAGE_SELECT } from \"../../../enable/i18n/modifies/app-layout.svelte\";\n\n/** Take the language select back out of the signed-in layout's header. */\nexport function unmodifyAppLayoutLanguageSelect(\n layoutPath: string,\n): 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(\"LanguageSelect\")) {\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(\n sf,\n libModule(\"components/language-select.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(APP_LANGUAGE_SELECT, \"\")\n // Moved out of the wrapper by hand: the component alone still goes.\n .replace(/[ \\t]*<LanguageSelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { unmodifyGitignore } from \"./modifies/gitignore\";\nimport { unmodifyPrettierignore } from \"./modifies/prettierignore\";\nimport { unmodifyViteConfig } from \"./modifies/vite-config\";\nimport { unmodifyLocalesAlias } from \"./modifies/locales-alias\";\nimport { removePackageImports } from \"../../../runtime/package-imports\";\nimport { LOCALES_IMPORTS } from \"../../enable/i18n/modifies/package-imports\";\nimport { unmodifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { unmodifyHooksI18n } from \"./modifies/hooks\";\nimport { unmodifyAppHtml } from \"./modifies/app-html\";\nimport { unmodifyRootLayoutI18n } from \"./modifies/+layout\";\nimport { unmodifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { unmodifyLayoutServerLocale } from \"./modifies/layout.server\";\nimport { unmodifyAppDts } from \"./modifies/app-d-ts\";\nimport { unmodifyAppLayoutLanguageSelect } from \"./modifies/app-layout.svelte\";\nimport { APP_LAYOUT_PATH } from \"../../enable/i18n/modifies/app-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 vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, unmodifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Removing #locales from package.json imports\");\n // Only while it still maps where enable-i18n pointed it.\n const imports = removePackageImports(\n options.root,\n Object.keys(LOCALES_IMPORTS),\n LOCALES_IMPORTS,\n );\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n // A project enabled before SvelteKit 3 has the `$locales` alias instead,\n // moved into the sveltekit() arg by `vela migrate sveltekit-3`.\n logger.info(\"Reverting the legacy $locales alias\");\n const alias = unmodifyLocalesAlias(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.outcome));\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n // enable-i18n may have created it; emptied, it goes.\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerI18n(hooksServerPath),\n );\n pushResult(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n logger.info(\"Reverting hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n // The de-localizing reroute may be all it holds; emptied, it goes.\n const hooksRevert = revertOutcomeToFile(\n hooksPath,\n unmodifyHooksI18n(hooksPath),\n );\n pushResult(hooksRevert.modify);\n if (hooksRevert.delete) deletes.push(hooksRevert.delete);\n\n logger.info(\"Reverting app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, unmodifyAppHtml(appHtmlPath)));\n\n logger.info(\"Reverting root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n // enable-i18n may have written the whole file; emptied, it goes.\n const layoutRevert = revertOutcomeToFile(\n layoutPath,\n unmodifyRootLayoutI18n(layoutPath),\n );\n pushResult(layoutRevert.modify);\n if (layoutRevert.delete) deletes.push(layoutRevert.delete);\n\n logger.info(\"Reverting root +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n // enable-i18n may have written the whole file; emptied, it goes.\n const layoutServerRevert = revertOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServerLocale(layoutServerPath),\n );\n pushResult(layoutServerRevert.modify);\n if (layoutServerRevert.delete) deletes.push(layoutServerRevert.delete);\n\n logger.info(\"Reverting app.d.ts\");\n const appDtsPath = path.join(options.root, \"src\", \"app.d.ts\");\n pushResult(modifyOutcomeToFile(appDtsPath, unmodifyAppDts(appDtsPath)));\n\n logger.info(\"Reverting the signed-in layout language select\");\n const appLayoutPath = path.join(options.root, APP_LAYOUT_PATH);\n pushResult(\n modifyOutcomeToFile(\n appLayoutPath,\n unmodifyAppLayoutLanguageSelect(appLayoutPath),\n ),\n );\n\n logger.info(\"Reverting root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n for (const candidate of rootLayoutCandidates) {\n if (!fs.existsSync(candidate)) continue;\n pushResult(\n modifyOutcomeToFile(\n candidate,\n unmodifyRootLayoutLanguageSelect(candidate),\n ),\n );\n }\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, unmodifyGitignore(gitignorePath)),\n );\n\n logger.info(\"Reverting .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n unmodifyPrettierignore(prettierignorePath),\n ),\n );\n\n // wuchale's loaders import the packages this uninstalls, and without the\n // .prettierignore block they would fail the project's lint. The catalogs\n // (.po) beside them are the translations, and stay.\n logger.info(\"Removing wuchale's loaders from src/locales\");\n const localesDir = path.join(options.root, \"src\", \"locales\");\n if (fs.existsSync(localesDir)) {\n for (const entry of fs.readdirSync(localesDir, { withFileTypes: true })) {\n if (!entry.isFile() || !entry.name.endsWith(\".js\")) continue;\n deletes.push({\n path: path.join(localesDir, entry.name),\n language: \"js\",\n content: \"\",\n status: \"success\",\n });\n }\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":";;;;;;;;;;;;;;;;AAGA,SAAgBqC,EAAkB,GAAsC;CACtE,IAAI,CAACF,EAAG,WAAWG,CAAa,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAe,MAAM;CACtD,IAAI,CAACC,EAAS,SAAS,sBAAsB,GAC3C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAQD,EAAS,MAAM,IAAI,GAC3BE,IAAgB,CAAC;CACvB,KAAK,IAAIC,IAAI,GAAGA,IAAIF,EAAM,QAAQ,KAAK;EACrC,IAAMG,IAAOH,EAAME;EACnB,IAAIC,MAAS,aAAa;GACxB,IAAIC,IAAIF,IAAI,GACRG,IAAa;GACjB,OAAOD,IAAIJ,EAAM,UAAUA,EAAMI,EAAE,CAAC,KAAK,MAAM,KAI7C,AAHIJ,EAAMI,OAAO,2BACf,IAAa,KAEf;GAEF,IAAIC,GAAY;IACd,IAAID;IACJ;GACF;EACF;EACA,AAA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ate.runtime-Cs73i6Zf.js","names":["FAILURE_HINT","I18N_MODULES","FAILURE_HINT","FAILURE_HINT","normalize","getLogger","revertOutcomeToFile","modifyOutcomeToFile","probeFirstExisting","resolveConfigTarget","saveTarget","VITE_CONFIG_CANDIDATES","LAYOUT_SERVER_SNIPPET","LOCALES_IMPORTS","LOCALS_MEMBER","LEGACY_LOAD_STATEMENT","LOAD_STATEMENT","LOCALS_COMMENT","withInMemoryScript","pruneUnusedImports","removeNamedImportIfUnused","removeTopLevelStatementByIdentifier","removeStatementWithComments","ensureBlankLineAfterImports","formatLikeSource","isEffectivelyEmpty","removeImportByModuleSpecifier","removePackageImports","dedent","removeHandle","libModule","SvelteFile","findLoadFunction","APP_LAYOUT_PATH","APP_LANGUAGE_SELECT","fs","path","unmodifyGitignore","gitignorePath","original","lines","out","i","line","j","hasWuchale","updated","unmodifyPrettierignore","filePath","at","index","unmodifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","removed","arr","SyntaxKind","el","HINTS","unmodifyLocalesAlias","res","root","aliasProp","target","aliasObj","locales","p","localesModule","escaped","name","pattern","specifier","I18N_HANDLE","FAILURE_HINT$3","I18N_MODULES$1","unmodifyHooksServerI18n","hooksServerPath","stmt","s","moduleSpecifier","DELOCALIZE_HELPER","FAILURE_HINT$2","I18N_MODULES","I18N_ONLY_REROUTE","COMPOSED_REROUTE","unmodifyHooksI18n","hooksPath","helperStatement","rerouteDecl","initText","composed","rerouteStatement","unmodifyAppHtml","appHtmlPath","FAILURE_HINT$1","SIDE_EFFECT_MODULES","BINDING_MODULES","WRITTEN_LOADS","normalize$1","source","unmodifyRootLayoutI18n","layoutPath","loadStatement","d","load","written","unmodifyRootLayoutLanguageSelect","file","sf","normalize","LOCALE_COMMENT","FAILURE_HINT","unmodifyLayoutServerLocale","layoutServerPath","properties","property","object","Node","escape","text","MEMBER","EMPTY_LOCALS","unmodifyAppDts","appDtsPath","unmodifyAppLayoutLanguageSelect","generate","logger","options","modifies","deletes","pushResult","imports","alias","hooksServerRevert","hooksRevert","layoutRevert","layoutServerRevert","appLayoutPath","rootLayoutCandidates","candidate","prettierignorePath","localesDir","entry"],"sources":["../../src/patterns/disable/i18n/modifies/gitignore.ts","../../src/patterns/disable/i18n/modifies/prettierignore.ts","../../src/patterns/disable/i18n/modifies/vite-config.ts","../../src/patterns/disable/i18n/modifies/locales-alias.ts","../../src/patterns/disable/i18n/modifies/locales-module.ts","../../src/patterns/disable/i18n/modifies/hooks.server.ts","../../src/patterns/disable/i18n/modifies/hooks.ts","../../src/patterns/disable/i18n/modifies/app-html.ts","../../src/patterns/disable/i18n/modifies/+layout.ts","../../src/patterns/disable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/disable/i18n/modifies/layout.server.ts","../../src/patterns/disable/i18n/modifies/app-d-ts.ts","../../src/patterns/disable/i18n/modifies/app-layout.svelte.ts","../../src/patterns/disable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (!original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const lines = original.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === \"# Wuchale\") {\n let j = i + 1;\n let hasWuchale = false;\n while (j < lines.length && lines[j].trim() !== \"\") {\n if (lines[j] === \"src/locales/.wuchale\") {\n hasWuchale = true;\n }\n j++;\n }\n if (hasWuchale) {\n i = j;\n continue;\n }\n }\n if (line === \"src/locales/.wuchale\") continue;\n out.push(line);\n }\n\n let updated = out.join(\"\\n\");\n updated = updated.replace(/\\n{3,}/g, \"\\n\\n\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LOCALES_ENTRY,\n PRETTIERIGNORE_HEADER,\n} from \"../../../enable/i18n/modifies/prettierignore\";\n\n/** Removes the block enable-i18n appended; an entry the project wrote itself stays. */\nexport function unmodifyPrettierignore(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n const lines = original.split(\"\\n\");\n const at = lines.findIndex(\n (line, index) =>\n line === PRETTIERIGNORE_HEADER && lines[index + 1] === LOCALES_ENTRY,\n );\n if (at === -1) {\n return { status: \"success\", changed: false };\n }\n\n lines.splice(at, 2);\n // The blank line that set the block apart goes with it.\n if (at > 0 && lines[at - 1] === \"\" && (lines[at] ?? \"\") === \"\") {\n lines.splice(at - 1, 1);\n }\n fs.writeFileSync(filePath, lines.join(\"\\n\"));\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** Remove `wuchale()` from the Vite plugins and its import. */\nexport function unmodifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(viteConfigPath, \"utf8\");\n if (!original.includes(\"wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n // One removal at a time: manipulating the tree invalidates sibling nodes.\n for (;;) {\n let removed = false;\n for (const arr of sourceFile.getDescendantsOfKind(\n SyntaxKind.ArrayLiteralExpression,\n )) {\n const index = arr\n .getElements()\n .findIndex((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n if (index >= 0) {\n arr.removeElement(index);\n removed = true;\n break;\n }\n }\n if (!removed) break;\n }\n\n removeImportByModuleSpecifier(sourceFile, \"wuchale/vite\");\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import { SyntaxKind } from \"ts-morph\";\nimport {\n resolveConfigTarget,\n saveTarget,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst HINTS = {\n notFound: \"No SvelteKit config to revert.\",\n failed:\n \"Remove the $locales alias from the sveltekit() arg in vite.config by hand.\",\n};\n\n/**\n * Remove the `$locales` alias enable-i18n wrote before SvelteKit 3, which\n * `sv migrate sveltekit-3` moves into the inline `sveltekit({...})` arg;\n * `alias` goes too once it is empty. Projects enabled since then map\n * `#locales/*` in package.json `imports` instead.\n */\nexport function unmodifyLocalesAlias(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, HINTS);\n // Nothing to revert in a project without a config.\n if (res.status === \"not-found\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n if (res.status === \"failed\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"failed\", message: res.message },\n };\n }\n\n const { target } = res;\n const aliasProp = target.configObject\n .getProperty(\"alias\")\n ?.asKind(SyntaxKind.PropertyAssignment);\n const aliasObj = aliasProp\n ?.getInitializer()\n ?.asKind(SyntaxKind.ObjectLiteralExpression);\n const locales = aliasObj\n ?.getProperties()\n .find((p) => p.getText().replace(/['\"]/g, \"\").startsWith(\"$locales\"));\n if (aliasProp && aliasObj && locales) {\n locales.remove();\n if (aliasObj.getProperties().length === 0) aliasProp.remove();\n }\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n","/**\n * Matches an import of wuchale's `src/locales/<name>.js` the way enable-i18n\n * writes it (`#locales/main.url.js`), and the `$locales/main.url` alias form\n * it wrote before SvelteKit 3, so disabling works on either.\n */\nexport function localesModule(name: string): (specifier: string) => boolean {\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const pattern = new RegExp(`^[$#]locales/${escaped}(\\\\.js)?$`);\n return (specifier) => pattern.test(specifier);\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n removeNamedImportIfUnused,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\nimport { localesModule } from \"./locales-module\";\n\nconst I18N_HANDLE = \"handleWuchale\";\nconst FAILURE_HINT = dedent`\n Take handleWuchale out of the exported handle in src/hooks.server.ts, then\n remove its declaration, the loadLocales(...) calls and the wuchale and\n #locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/load-utils/server\",\n // Since the handle follows the visitor's preference on pages without a\n // language in their URL; a project enabled before has none of the three.\n \"wuchale/url\",\n libModule(\"url.ts\"),\n libModule(\"locale.ts\"),\n localesModule(\"main.url\"),\n localesModule(\"data\"),\n localesModule(\"main.loader.server.svelte\"),\n localesModule(\"js.loader.server\"),\n];\n\n/**\n * Undo `modifyHooksServerI18n`: drop the locale bootstrap, the wuchale handle\n * and its imports, and unwrap `sequence(handleWuchale, ...)`. A file that\n * enable-i18n created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerI18n(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (!original.includes(I18N_HANDLE) && !original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // loadLocales(...) bootstrap calls, one at a time (removal invalidates siblings).\n for (;;) {\n const stmt = sourceFile\n .getStatements()\n .find(\n (s) =>\n s.getKind() === SyntaxKind.ExpressionStatement &&\n /^loadLocales\\s*\\(/.test(s.getText()),\n );\n if (!stmt) break;\n stmt.remove();\n }\n\n // `export const handle = handleWuchale` goes altogether; a sequence loses\n // the argument, or unwraps to the handle it composed with.\n const removed = removeHandle(sourceFile, I18N_HANDLE);\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, I18N_HANDLE);\n for (const moduleSpecifier of I18N_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"Handle\");\n // A project from before SvelteKit 3 imports it from the package root.\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit\", \"Handle\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst DELOCALIZE_HELPER = \"rerouteDeLocalize\";\n\nconst FAILURE_HINT = dedent`\n Take rerouteDeLocalize out of the exported reroute in src/hooks.ts, then\n remove its declaration and the wuchale and #locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/url\",\n localesModule(\"main.url\"),\n localesModule(\"data\"),\n];\n\n/** The two reroutes `modifyHooksI18n` writes: on its own, and composed. */\nconst I18N_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*url\\.pathname\\s*\\)$/;\nconst COMPOSED_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)\\s*\\)$/;\n\n/**\n * Undo `modifyHooksI18n`: drop the de-localizer and its imports, leaving the\n * negotiation reroute it may have been composed with. A file that enable-i18n\n * created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (!original.includes(DELOCALIZE_HELPER)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const helperStatement = sourceFile\n .getVariableDeclaration(DELOCALIZE_HELPER)\n ?.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n const initText = rerouteDecl?.getInitializer()?.getText() ?? \"\";\n const composed = COMPOSED_REROUTE.test(initText);\n const rerouteStatement =\n composed || I18N_ONLY_REROUTE.test(initText)\n ? rerouteDecl?.getFirstAncestorByKind(SyntaxKind.VariableStatement)\n : undefined;\n\n // Anything else reading the de-localizer is code enable-i18n did not write,\n // so undoing it is the developer's call.\n const otherReaders = sourceFile\n .getStatements()\n .filter(\n (s) =>\n s !== helperStatement &&\n s !== rerouteStatement &&\n s.getText().includes(DELOCALIZE_HELPER),\n );\n if (otherReaders.length > 0) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n if (composed) {\n // content-negotiation's reroute is underneath; it stays.\n rerouteDecl?.setInitializer(\"({ url }) => negotiateReroute(url.pathname)\");\n } else if (rerouteStatement) {\n removeTopLevelStatementByIdentifier(sourceFile, \"reroute\");\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, DELOCALIZE_HELPER);\n pruneUnusedImports(sourceFile, I18N_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty hooks.ts into a\n // delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(hooksPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Put a real language back. `%sveltekit.lang%` is not a SvelteKit\n * placeholder; only the wuchale hook replaced it, so without that hook it\n * would be served literally.\n */\nexport function unmodifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n const updated = original.replace(\n /lang\\s*=\\s*(?:\"%sveltekit\\.lang%\"|'%sveltekit\\.lang%')/g,\n 'lang=\"en\"',\n );\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(appHtmlPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type Statement } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LEGACY_LOAD_STATEMENT,\n LOAD_STATEMENT,\n} from \"../../../enable/i18n/modifies/+layout\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeImportByModuleSpecifier,\n removeStatementWithComments,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.ts still loads wuchale locales. Remove these from it:\n\n import { browser } from '$app/env';\n import { loadLocale } from 'wuchale/load-utils';\n import { getLocale } from '#locales/main.url.js';\n import { hasLocalizedUrl } from '#lib/url.js';\n import '#locales/main.loader.svelte.js';\n import '#locales/js.loader.js';\n\n and the loadLocale(...) call inside load().\n`;\n\nconst SIDE_EFFECT_MODULES = [\n localesModule(\"main.loader.svelte\"),\n localesModule(\"js.loader\"),\n];\nconst BINDING_MODULES: ModuleMatch[] = [\n // `$app/env`, or the module it replaced before SvelteKit 3.\n (specifier) => /^\\$app\\/env(ironment)?$/.test(specifier),\n \"wuchale/load-utils\",\n localesModule(\"main.url\"),\n libModule(\"url.ts\"),\n];\n\n/** The loads enable-i18n has written: today's, and the URL-only one before it. */\nconst WRITTEN_LOADS = [LOAD_STATEMENT, LEGACY_LOAD_STATEMENT];\n\nfunction normalize(source: string): string {\n return source.replace(/[\"']/g, \"'\").replace(/\\s+/g, \"\");\n}\n\n/**\n * Undo `ensureRootLayoutI18n`: drop the wuchale load and its imports, leaving\n * whatever else the file holds. A file enable-i18n wrote whole comes out\n * empty, for the caller to delete.\n */\nexport function unmodifyRootLayoutI18n(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(\"loadLocale\") && !/[$#]locales\\//.test(original)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n const loadStatement: Statement | undefined =\n sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"load\")) ??\n sourceFile.getFunction(\"load\");\n\n if (loadStatement) {\n // A load that grew code of its own needs a hand; only the one enable-i18n\n // wrote is safe to take out wholesale.\n const load = normalize(loadStatement.getText());\n if (!WRITTEN_LOADS.some((written) => normalize(written) === load)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n removeStatementWithComments(sourceFile, loadStatement);\n }\n\n for (const moduleSpecifier of SIDE_EFFECT_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n pruneUnusedImports(sourceFile, BINDING_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty +layout.ts into\n // a delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(layoutPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","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\n/** Take the language select (and the nav item enable-i18n wrapped it in) back out. */\nexport function unmodifyRootLayoutLanguageSelect(\n layoutPath: string,\n): 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(\"LanguageSelect\")) {\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(\n sf,\n libModule(\"components/language-select.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n let updated = file.toString();\n updated = updated.replace(\n /[ \\t]*<Navbar\\.Item>\\s*<LanguageSelect\\s*\\/>\\s*<\\/Navbar\\.Item>[ \\t]*\\r?\\n?/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<LanguageSelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { LAYOUT_SERVER_SNIPPET } from \"../../../enable/i18n/modifies/layout.server\";\nimport { Node, SyntaxKind } from \"ts-morph\";\nimport { findLoadFunction } from \"../../../../runtime/load-function\";\nimport {\n removeUnusedBindingElement,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst normalize = (source: string) =>\n source.replace(/[\"']/g, \"'\").replace(/\\s+/g, \"\");\n\n/** The comment enable-i18n put above the property, on its own lines. */\nconst LOCALE_COMMENT =\n /^[ \\t]*\\/\\/ Decided on the server \\(src\\/hooks\\.server\\.ts\\), because pages without a\\r?\\n[ \\t]*\\/\\/ language in their URL follow the visitor's preference\\.\\r?\\n/m;\n\nconst FAILURE_HINT =\n \"src/routes/+layout.server.ts still returns `locale: locals.locale`. Remove it from the load.\";\n\n/**\n * Undo `modifyLayoutServerLocale`: the root layout's server load stops\n * returning `locale`. A file enable-i18n wrote whole comes out empty, for the\n * caller to delete.\n */\nexport function unmodifyLayoutServerLocale(\n layoutServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (!original.includes(\"locals.locale\")) {\n return { status: \"success\", changed: false };\n }\n\n if (normalize(original) === normalize(LAYOUT_SERVER_SNIPPET)) {\n fs.writeFileSync(layoutServerPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n // The comment first: left above a removed property it would attach itself\n // to whatever follows.\n const { source } = withInMemoryScript(\n original.replace(LOCALE_COMMENT, \"\"),\n (sf) => {\n const load = findLoadFunction(sf);\n const properties = (load ?? sf)\n .getDescendantsOfKind(SyntaxKind.PropertyAssignment)\n .filter(\n (property) =>\n property.getName() === \"locale\" &&\n /(^|\\.)locals\\.locale$/.test(\n property.getInitializer()?.getText() ?? \"\",\n ),\n );\n for (const property of properties) {\n const object = property.getParent();\n property.remove();\n // `return {}` reads worse on three lines than on one.\n if (\n Node.isObjectLiteralExpression(object) &&\n object.getProperties().length === 0\n ) {\n object.replaceWithText(\"{}\");\n }\n }\n removeUnusedBindingElement(sf, \"locals\");\n },\n );\n if (source === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(layoutServerPath, source, \"utf8\");\n return { status: \"success\", changed: source !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LOCALS_COMMENT,\n LOCALS_MEMBER,\n} from \"../../../enable/i18n/modifies/app-d-ts\";\n\nconst escape = (text: string) => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nconst MEMBER = new RegExp(\n `(?:^[ \\\\t]*${escape(LOCALS_COMMENT)}[ \\\\t]*\\\\r?\\\\n)?^[ \\\\t]*${escape(LOCALS_MEMBER)}[ \\\\t]*\\\\r?\\\\n`,\n \"m\",\n);\n\n/** An `interface Locals` left with nothing in it. */\nconst EMPTY_LOCALS = /^([ \\t]*)interface Locals\\s*\\{\\s*\\}/m;\n\n/**\n * Undo `modifyAppDts`: `App.Locals` loses `locale`, and an interface left\n * empty goes back to the comment `sv create` writes.\n */\nexport function unmodifyAppDts(appDtsPath: string): ModifyOutcome {\n if (!fs.existsSync(appDtsPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(appDtsPath, \"utf8\");\n if (!MEMBER.test(original)) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original\n .replace(MEMBER, \"\")\n .replace(EMPTY_LOCALS, \"$1// interface Locals {}\");\n fs.writeFileSync(appDtsPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","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\";\nimport { APP_LANGUAGE_SELECT } from \"../../../enable/i18n/modifies/app-layout.svelte\";\n\n/** Take the language select back out of the signed-in layout's header. */\nexport function unmodifyAppLayoutLanguageSelect(\n layoutPath: string,\n): 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(\"LanguageSelect\")) {\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(\n sf,\n libModule(\"components/language-select.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(APP_LANGUAGE_SELECT, \"\")\n // Moved out of the wrapper by hand: the component alone still goes.\n .replace(/[ \\t]*<LanguageSelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { unmodifyGitignore } from \"./modifies/gitignore\";\nimport { unmodifyPrettierignore } from \"./modifies/prettierignore\";\nimport { unmodifyViteConfig } from \"./modifies/vite-config\";\nimport { unmodifyLocalesAlias } from \"./modifies/locales-alias\";\nimport { removePackageImports } from \"../../../runtime/package-imports\";\nimport { LOCALES_IMPORTS } from \"../../enable/i18n/modifies/package-imports\";\nimport { unmodifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { unmodifyHooksI18n } from \"./modifies/hooks\";\nimport { unmodifyAppHtml } from \"./modifies/app-html\";\nimport { unmodifyRootLayoutI18n } from \"./modifies/+layout\";\nimport { unmodifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { unmodifyLayoutServerLocale } from \"./modifies/layout.server\";\nimport { unmodifyAppDts } from \"./modifies/app-d-ts\";\nimport { unmodifyAppLayoutLanguageSelect } from \"./modifies/app-layout.svelte\";\nimport { APP_LAYOUT_PATH } from \"../../enable/i18n/modifies/app-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 vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, unmodifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Removing #locales from package.json imports\");\n // Only while it still maps where enable-i18n pointed it.\n const imports = removePackageImports(\n options.root,\n Object.keys(LOCALES_IMPORTS),\n LOCALES_IMPORTS,\n );\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n // A project enabled before SvelteKit 3 has the `$locales` alias instead,\n // moved into the sveltekit() arg by `vela migrate sveltekit-3`.\n logger.info(\"Reverting the legacy $locales alias\");\n const alias = unmodifyLocalesAlias(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.outcome));\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n // enable-i18n may have created it; emptied, it goes.\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerI18n(hooksServerPath),\n );\n pushResult(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n logger.info(\"Reverting hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n // The de-localizing reroute may be all it holds; emptied, it goes.\n const hooksRevert = revertOutcomeToFile(\n hooksPath,\n unmodifyHooksI18n(hooksPath),\n );\n pushResult(hooksRevert.modify);\n if (hooksRevert.delete) deletes.push(hooksRevert.delete);\n\n logger.info(\"Reverting app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, unmodifyAppHtml(appHtmlPath)));\n\n logger.info(\"Reverting root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n // enable-i18n may have written the whole file; emptied, it goes.\n const layoutRevert = revertOutcomeToFile(\n layoutPath,\n unmodifyRootLayoutI18n(layoutPath),\n );\n pushResult(layoutRevert.modify);\n if (layoutRevert.delete) deletes.push(layoutRevert.delete);\n\n logger.info(\"Reverting root +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n // enable-i18n may have written the whole file; emptied, it goes.\n const layoutServerRevert = revertOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServerLocale(layoutServerPath),\n );\n pushResult(layoutServerRevert.modify);\n if (layoutServerRevert.delete) deletes.push(layoutServerRevert.delete);\n\n logger.info(\"Reverting app.d.ts\");\n const appDtsPath = path.join(options.root, \"src\", \"app.d.ts\");\n pushResult(modifyOutcomeToFile(appDtsPath, unmodifyAppDts(appDtsPath)));\n\n logger.info(\"Reverting the signed-in layout language select\");\n const appLayoutPath = path.join(options.root, APP_LAYOUT_PATH);\n pushResult(\n modifyOutcomeToFile(\n appLayoutPath,\n unmodifyAppLayoutLanguageSelect(appLayoutPath),\n ),\n );\n\n logger.info(\"Reverting root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n for (const candidate of rootLayoutCandidates) {\n if (!fs.existsSync(candidate)) continue;\n pushResult(\n modifyOutcomeToFile(\n candidate,\n unmodifyRootLayoutLanguageSelect(candidate),\n ),\n );\n }\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, unmodifyGitignore(gitignorePath)),\n );\n\n logger.info(\"Reverting .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n unmodifyPrettierignore(prettierignorePath),\n ),\n );\n\n // wuchale's loaders import the packages this uninstalls, and without the\n // .prettierignore block they would fail the project's lint. The catalogs\n // (.po) beside them are the translations, and stay.\n logger.info(\"Removing wuchale's loaders from src/locales\");\n const localesDir = path.join(options.root, \"src\", \"locales\");\n if (fs.existsSync(localesDir)) {\n for (const entry of fs.readdirSync(localesDir, { withFileTypes: true })) {\n if (!entry.isFile() || !entry.name.endsWith(\".js\")) continue;\n deletes.push({\n path: path.join(localesDir, entry.name),\n language: \"js\",\n content: \"\",\n status: \"success\",\n });\n }\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":";;;;;;;;;;;;;;;;AAGA,SAAgBqC,EAAkB,GAAsC;CACtE,IAAI,CAACF,EAAG,WAAWG,CAAa,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAe,MAAM;CACtD,IAAI,CAACC,EAAS,SAAS,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AAI9F,EAAG,WAAW4G,CAAU,GAC1B,KAAK,IAAMC,KAAS7G,EAAG,YAAY4G,GAAY,EAAE,eAAe,GAAK,CAAC,GACpE,AAAKC,EAAM,OAAO,KAAMA,EAAM,KAAK,SAAS,KAAK,KACjDb,EAAQ,KAAK;EACX,MAAM/F,EAAK,KAAK2G,GAAYC,EAAM,IAAI;EACtC,UAAU;EACV,SAAS;EACT,QAAQ;CACV,CAAC;CAIL,OAAO;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,10 +1,10 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
- import { r as t } from "./modify-file-BX9-aZD1.js";
2
+ import { r as t } from "./modify-file-BOEKlIDw.js";
3
3
  import { t as n } from "./svelte-file-DfplF3BU.js";
4
4
  import { _ as r, f as i, n as a, o, u as s } from "./ts-morph-helpers-B4KZXP44.js";
5
5
  import { t as c } from "./unmodify-load-CdWXJ_Ac.js";
6
6
  import { r as l } from "./lib-specifier-C3M0WTev.js";
7
- import { t as u } from "./shared-BOFCKWJs.js";
7
+ import { t as u } from "./shared-CSwGWMcN.js";
8
8
  import d from "node:fs";
9
9
  import f from "node:path";
10
10
  import { SyntaxKind as p } from "ts-morph";
@@ -139,4 +139,4 @@ async function w(n) {
139
139
  }
140
140
  export { w as generate };
141
141
 
142
- //# sourceMappingURL=generate.runtime-GmsldrGj.js.map
142
+ //# sourceMappingURL=generate.runtime-D7KYlnvb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-GmsldrGj.js","names":["getLogger","modifyOutcomeToFile","SvelteFile","withInMemoryScript","removeNavItemFromScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","removeFromLoad","libModule","planDropsForCollections","fs","path","unmodifyNavUser","navUserPath","source","file","wasRemoved","tryRemove","run","result","src","fn","unmodifyLayoutServer","layoutServerPath","unmodifyAppLayoutSvelte","layoutPath","ORIGINAL_HEADER","LEGACY_NAME","TEAM_IMPORTS","TEAM_PROPS","markupOf","revertAppSidebarScript","out","decl","sf","init","nameNode","SyntaxKind","typeNode","member","literal","before","name","remaining","p","pattern","elements","kept","el","moduleSpecifier","markup","formatLikeSource","unmodifyAppSidebar","appSidebarPath","generate","logger","options","modifies","pushResult","navUserCandidates","appLayoutPath"],"sources":["../../src/patterns/disable/teams/modifies/modify-nav-user.ts","../../src/patterns/disable/teams/modifies/+layout.server.ts","../../src/patterns/disable/teams/modifies/modify-app-layout.ts","../../src/patterns/disable/teams/modifies/modify-app-sidebar.ts","../../src/patterns/disable/teams/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/teams\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Teams\",\n \"@lucide/svelte/icons/users\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\n\n/** Take the team loader back out of the (app) layout's load. */\nexport function unmodifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n return removeFromLoad(layoutServerPath, {\n variables: [\"team\", \"teams\"],\n dependsKeys: [\"app:team\"],\n returnProps: [\"team\", \"teams\"],\n });\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Drop the team props enable-teams passed to <AppSidebar>. */\nexport function unmodifyAppLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n\n file.removeAttribute(\"AppSidebar\", \"team\");\n file.removeAttribute(\"AppSidebar\", \"teams\");\n if (!file.hasChanged()) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\n/** The header enable-auth ships, which the team switcher replaced. */\nconst ORIGINAL_HEADER = `<Sidebar.Header>\n\t\t<Sidebar.Menu>\n\t\t\t<Sidebar.MenuItem>\n\t\t\t\t<Sidebar.MenuButton size=\"lg\">\n\t\t\t\t\t{#snippet child({ props })}\n\t\t\t\t\t\t<a href=\"/dashboard\" {...props}>\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclass=\"bg-sidebar-accent text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img src={favicon} alt=\"logo\" class=\"size-6\" />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class=\"grid flex-1 text-left text-sm leading-tight\">\n\t\t\t\t\t\t\t\t<span class=\"truncate font-medium\">{site.name}</span>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t{/snippet}\n\t\t\t\t</Sidebar.MenuButton>\n\t\t\t</Sidebar.MenuItem>\n\t\t</Sidebar.Menu>\n\t</Sidebar.Header>`;\n\n/**\n * A sidebar from before `#lib/site.js` names the app with a `meta` prop; the\n * header goes back to whichever the team switcher's fallback used.\n */\nconst LEGACY_NAME = \"{meta.appName}\";\n\n/** Imports enable-teams added, dropped once the markup no longer uses them. */\nconst TEAM_IMPORTS: [name: string, module: ModuleMatch][] = [\n [\"TeamSwitcher\", libModule(\"components/team-switcher.svelte\")],\n [\"ChevronsUpDownIcon\", \"@lucide/svelte/icons/chevrons-up-down\"],\n [\"Avatar\", libModule(\"components/ui/avatar\")],\n];\n\nconst TEAM_PROPS = [\"team\", \"teams\"];\n\nfunction markupOf(source: string): string {\n return source.replace(/<script[\\s\\S]*?<\\/script>/g, \"\");\n}\n\nfunction revertAppSidebarScript(source: string, markup: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n\n // Type first: rewriting the binding pattern shifts what follows.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n for (const member of typeNode\n .asKindOrThrow(SyntaxKind.IntersectionType)\n .getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const literal = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const before = literal.getProperties().length;\n for (const name of TEAM_PROPS) {\n literal.getProperty(name)?.remove();\n }\n if (literal.getProperties().length !== before) {\n // Collapse to one line, as enable-auth writes it; prettier keeps\n // whichever shape it finds.\n const remaining = literal\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n literal.replaceWithText(`{ ${remaining.join(\"; \")} }`);\n }\n }\n }\n\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const kept = elements\n .filter((el) => !TEAM_PROPS.includes(el.getName()))\n .map((el) => el.getText());\n if (kept.length !== elements.length) {\n pattern.replaceWithText(`{ ${kept.join(\", \")} }`);\n }\n }\n\n for (const [name, moduleSpecifier] of TEAM_IMPORTS) {\n if (!new RegExp(`\\\\b${name}\\\\b`).test(markup)) {\n removeImportByModuleSpecifier(sf, moduleSpecifier);\n }\n }\n formatLikeSource(sf);\n ensureBlankLineAfterImports(sf);\n });\n return out;\n}\n\n/** Put the plain app-name header back in place of the team switcher. */\nexport function unmodifyAppSidebar(appSidebarPath: string): ModifyOutcome {\n if (!fs.existsSync(appSidebarPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(appSidebarPath);\n if (!file.hasElement(\"TeamSwitcher\")) {\n return { status: \"success\", changed: false };\n }\n\n file.replaceElement(\n \"Sidebar.Header\",\n file.toString().includes(LEGACY_NAME)\n ? ORIGINAL_HEADER.replace(\"{site.name}\", LEGACY_NAME)\n : ORIGINAL_HEADER,\n );\n const markup = markupOf(file.toString());\n file.modifyScript((source) => revertAppSidebarScript(source, markup));\n file.writeTo(appSidebarPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyLayoutServer } from \"./modifies/+layout.server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\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 nav-user.svelte\");\n const navUserCandidates = [\n path.join(options.root, \"src\", \"lib\", \"components\", \"nav-user.svelte\"),\n ];\n const navUserPath =\n navUserCandidates.find((p) => fs.existsSync(p)) ?? navUserCandidates[0];\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting (app) +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServer(layoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, unmodifyAppLayoutSvelte(appLayoutPath)),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n const collectionDrops = await planDropsForCollections(\n // team_users is a view over teams, so it has to go first or PocketBase\n // refuses to drop teams (\"existing reference in team_users\").\n [\n \"team_users\",\n \"team_invite_links\",\n \"team_invites\",\n \"team_memberships\",\n \"teams\",\n ],\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":";;;;;;;;;;;AAKA,SAAgBY,EAAgB,GAAoC;CAClE,IAAI,CAACF,EAAG,WAAWG,CAAW,G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,GACM3C,IACJ8C,EAAkB,MAAM,MAAMjD,EAAG,WAAWkC,CAAC,CAAC,KAAKe,EAAkB;CAGvE,AAFAD,EAAWzD,EAAoBY,GAAaD,EAAgBC,CAAW,CAAC,CAAC,GAEzE0C,EAAO,KAAK,mCAAmC;CAC/C,IAAMhC,IAAmBZ,EAAK,KAC5B6C,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAQA,AAPAE,EACEzD,EACEsB,GACAD,EAAqBC,CAAgB,CACvC,CACF,GAEAgC,EAAO,KAAK,gCAAgC;CAC5C,IAAMK,IAAgBjD,EAAK,KACzB6C,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAKA,AAJAE,EACEzD,EAAoB2D,GAAepC,EAAwBoC,CAAa,CAAC,CAC3E,GAEAL,EAAO,KAAK,8BAA8B;CAC1C,IAAMF,IAAiB1C,EAAK,KAC1B6C,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAkBA,OAjBAE,EACEzD,EAAoBoD,GAAgBD,EAAmBC,CAAc,CAAC,CACxE,GAeO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MArB4B5C,EAG5B;GACE;GACA;GACA;GACA;GACA;EACF,GACA+C,CACF;CAWA;AACF"}
1
+ {"version":3,"file":"generate.runtime-D7KYlnvb.js","names":["getLogger","modifyOutcomeToFile","SvelteFile","withInMemoryScript","removeNavItemFromScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","removeFromLoad","libModule","planDropsForCollections","fs","path","unmodifyNavUser","navUserPath","source","file","wasRemoved","tryRemove","run","result","src","fn","unmodifyLayoutServer","layoutServerPath","unmodifyAppLayoutSvelte","layoutPath","ORIGINAL_HEADER","LEGACY_NAME","TEAM_IMPORTS","TEAM_PROPS","markupOf","revertAppSidebarScript","out","decl","sf","init","nameNode","SyntaxKind","typeNode","member","literal","before","name","remaining","p","pattern","elements","kept","el","moduleSpecifier","markup","formatLikeSource","unmodifyAppSidebar","appSidebarPath","generate","logger","options","modifies","pushResult","navUserCandidates","appLayoutPath"],"sources":["../../src/patterns/disable/teams/modifies/modify-nav-user.ts","../../src/patterns/disable/teams/modifies/+layout.server.ts","../../src/patterns/disable/teams/modifies/modify-app-layout.ts","../../src/patterns/disable/teams/modifies/modify-app-sidebar.ts","../../src/patterns/disable/teams/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/teams\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Teams\",\n \"@lucide/svelte/icons/users\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\n\n/** Take the team loader back out of the (app) layout's load. */\nexport function unmodifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n return removeFromLoad(layoutServerPath, {\n variables: [\"team\", \"teams\"],\n dependsKeys: [\"app:team\"],\n returnProps: [\"team\", \"teams\"],\n });\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Drop the team props enable-teams passed to <AppSidebar>. */\nexport function unmodifyAppLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n\n file.removeAttribute(\"AppSidebar\", \"team\");\n file.removeAttribute(\"AppSidebar\", \"teams\");\n if (!file.hasChanged()) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\n/** The header enable-auth ships, which the team switcher replaced. */\nconst ORIGINAL_HEADER = `<Sidebar.Header>\n\t\t<Sidebar.Menu>\n\t\t\t<Sidebar.MenuItem>\n\t\t\t\t<Sidebar.MenuButton size=\"lg\">\n\t\t\t\t\t{#snippet child({ props })}\n\t\t\t\t\t\t<a href=\"/dashboard\" {...props}>\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclass=\"bg-sidebar-accent text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img src={favicon} alt=\"logo\" class=\"size-6\" />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class=\"grid flex-1 text-left text-sm leading-tight\">\n\t\t\t\t\t\t\t\t<span class=\"truncate font-medium\">{site.name}</span>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t{/snippet}\n\t\t\t\t</Sidebar.MenuButton>\n\t\t\t</Sidebar.MenuItem>\n\t\t</Sidebar.Menu>\n\t</Sidebar.Header>`;\n\n/**\n * A sidebar from before `#lib/site.js` names the app with a `meta` prop; the\n * header goes back to whichever the team switcher's fallback used.\n */\nconst LEGACY_NAME = \"{meta.appName}\";\n\n/** Imports enable-teams added, dropped once the markup no longer uses them. */\nconst TEAM_IMPORTS: [name: string, module: ModuleMatch][] = [\n [\"TeamSwitcher\", libModule(\"components/team-switcher.svelte\")],\n [\"ChevronsUpDownIcon\", \"@lucide/svelte/icons/chevrons-up-down\"],\n [\"Avatar\", libModule(\"components/ui/avatar\")],\n];\n\nconst TEAM_PROPS = [\"team\", \"teams\"];\n\nfunction markupOf(source: string): string {\n return source.replace(/<script[\\s\\S]*?<\\/script>/g, \"\");\n}\n\nfunction revertAppSidebarScript(source: string, markup: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n\n // Type first: rewriting the binding pattern shifts what follows.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n for (const member of typeNode\n .asKindOrThrow(SyntaxKind.IntersectionType)\n .getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const literal = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const before = literal.getProperties().length;\n for (const name of TEAM_PROPS) {\n literal.getProperty(name)?.remove();\n }\n if (literal.getProperties().length !== before) {\n // Collapse to one line, as enable-auth writes it; prettier keeps\n // whichever shape it finds.\n const remaining = literal\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n literal.replaceWithText(`{ ${remaining.join(\"; \")} }`);\n }\n }\n }\n\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const kept = elements\n .filter((el) => !TEAM_PROPS.includes(el.getName()))\n .map((el) => el.getText());\n if (kept.length !== elements.length) {\n pattern.replaceWithText(`{ ${kept.join(\", \")} }`);\n }\n }\n\n for (const [name, moduleSpecifier] of TEAM_IMPORTS) {\n if (!new RegExp(`\\\\b${name}\\\\b`).test(markup)) {\n removeImportByModuleSpecifier(sf, moduleSpecifier);\n }\n }\n formatLikeSource(sf);\n ensureBlankLineAfterImports(sf);\n });\n return out;\n}\n\n/** Put the plain app-name header back in place of the team switcher. */\nexport function unmodifyAppSidebar(appSidebarPath: string): ModifyOutcome {\n if (!fs.existsSync(appSidebarPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(appSidebarPath);\n if (!file.hasElement(\"TeamSwitcher\")) {\n return { status: \"success\", changed: false };\n }\n\n file.replaceElement(\n \"Sidebar.Header\",\n file.toString().includes(LEGACY_NAME)\n ? ORIGINAL_HEADER.replace(\"{site.name}\", LEGACY_NAME)\n : ORIGINAL_HEADER,\n );\n const markup = markupOf(file.toString());\n file.modifyScript((source) => revertAppSidebarScript(source, markup));\n file.writeTo(appSidebarPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyLayoutServer } from \"./modifies/+layout.server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\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 nav-user.svelte\");\n const navUserCandidates = [\n path.join(options.root, \"src\", \"lib\", \"components\", \"nav-user.svelte\"),\n ];\n const navUserPath =\n navUserCandidates.find((p) => fs.existsSync(p)) ?? navUserCandidates[0];\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting (app) +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServer(layoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, unmodifyAppLayoutSvelte(appLayoutPath)),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n const collectionDrops = await planDropsForCollections(\n // team_users is a view over teams, so it has to go first or PocketBase\n // refuses to drop teams (\"existing reference in team_users\").\n [\n \"team_users\",\n \"team_invite_links\",\n \"team_invites\",\n \"team_memberships\",\n \"teams\",\n ],\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":";;;;;;;;;;;AAKA,SAAgBY,EAAgB,GAAoC;CAClE,IAAI,CAACF,EAAG,WAAWG,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAASJ,EAAG,aAAaG,GAAa,MAAM;CAClD,IAAI,CAACC,EAAO,SAAS,QAAQ,GAC3B,OAAO;EAAE,QAAQ;EAAW,SA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AK,mCAAmC;CAC/C,IAAMhC,IAAmBZ,EAAK,KAC5B6C,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAQA,AAPAE,EACEzD,EACEsB,GACAD,EAAqBC,CAAgB,CACvC,CACF,GAEAgC,EAAO,KAAK,gCAAgC;CAC5C,IAAMK,IAAgBjD,EAAK,KACzB6C,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAKA,AAJAE,EACEzD,EAAoB2D,GAAepC,EAAwBoC,CAAa,CAAC,CAC3E,GAEAL,EAAO,KAAK,8BAA8B;CAC1C,IAAMF,IAAiB1C,EAAK,KAC1B6C,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAkBA,OAjBAE,EACEzD,EAAoBoD,GAAgBD,EAAmBC,CAAc,CAAC,CACxE,GAeO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MArB4B5C,EAG5B;GACE;GACA;GACA;GACA;GACA;EACF,GACA+C,CACF;CAWA;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
- import { r as t } from "./modify-file-BX9-aZD1.js";
2
+ import { r as t } from "./modify-file-BOEKlIDw.js";
3
3
  import { a as n, t as r } from "./config-target-DJbVHwHl.js";
4
- import { n as i } from "./generate-BvQ6VwYH.js";
4
+ import { n as i } from "./generate-DR2wkVPY.js";
5
5
  import { _ as a, o, r as s } from "./ts-morph-helpers-B4KZXP44.js";
6
6
  import { t as c } from "./dedent-CCUOcPFW.js";
7
7
  import { a as l, c as u, i as d, l as f, n as p, o as m, r as h, s as g, t as _ } from "./load-function-BFvIVsh7.js";
@@ -297,4 +297,4 @@ async function K(a) {
297
297
  }
298
298
  export { K as generate };
299
299
 
300
- //# sourceMappingURL=generate.runtime-DFSsgOmB.js.map
300
+ //# sourceMappingURL=generate.runtime-DG9LRwbt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-DFSsgOmB.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","resolveMode","withInMemoryScript","ensureImports","dedent","hasProperty","newProject","findLoadFunction","returnedObject","ensureNamedImports","hasSpreadOf","findFinalReturn","inspectEventParameter","ensureImportSpec","SvelteFile","fs","path","FAILURE_HINT$3","NOT_FOUND_HINT$1","elementName","text","modifyViteConfig","call","pluginArgs","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","elements","el","sveltekitIndex","formatLikeSource","DEFAULT_LOCALE","REQUEST_LOCALE","eventName","WUCHALE_LOCALE","cmsSnippet","locale","importLine","parts","spec","createdLayoutServer","imports","snippet","FAILURE_HINT$2","modifyLayoutServer","layoutServerPath","fn","body","Node","event","returned","object","spreadIndex","property","returnIndex","destructuring","typeText","FAILURE_HINT$1","modifyLayoutUniversal","layoutPath","dataExpression","expression","element","IMPORT_SNIPPET","MARKUP_SNIPPET","NOT_FOUND_HINT","FAILURE_HINT","modifyLayoutSvelte","file","out","source","sf","readWuchaleLocales","configPath","root","match","locales","m","vitePluginArgs","mode","list","generate","logger","options","modifies","i18n","pushResult","requestLocale","layoutUniversalPath","layoutSveltePath"],"sources":["../../src/patterns/enable/cms/modifies/vite-config.ts","../../src/patterns/enable/cms/modifies/layout.server.ts","../../src/patterns/enable/cms/modifies/layout.ts","../../src/patterns/enable/cms/modifies/layout.svelte.ts","../../src/patterns/enable/cms/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the CMS plugin to your Vite config, ahead of sveltekit():\",\n \"\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the CMS plugin ahead of sveltekit():\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit()],\",\n \"});\",\n].join(\"\\n\");\n\nfunction elementName(text: string): string {\n return text.replace(/\\s/g, \"\");\n}\n\n/**\n * Registers `cms(...)` from `@velastack/cms/vite` in the Vite plugin list, just\n * ahead of `sveltekit()`. Only the plugin array is touched, so the inline\n * `sveltekit({ ... })` shape the templates use is left alone.\n */\nexport function modifyViteConfig(\n viteConfigPath: string,\n pluginArgs = \"\",\n): ModifyOutcome {\n const call = `cms(${pluginArgs})`;\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"@velastack/cms/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"cms\"],\n moduleSpecifier: \"@velastack/cms/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: `[${call}]`,\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (pluginsProp as PropertyAssignment).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as PropertyAssignment).setInitializer(`[${call}]`);\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as ArrayLiteralExpression;\n const elements = arr.getElements();\n const hasCms = elements.some((el) =>\n elementName(el.getText()).startsWith(\"cms(\"),\n );\n\n if (!hasCms) {\n const sveltekitIndex = elements.findIndex((el) =>\n elementName(el.getText()).startsWith(\"sveltekit(\"),\n );\n arr.insertElement(sveltekitIndex === -1 ? 0 : sveltekitIndex, call);\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n ensureImportSpec,\n ensureNamedImports,\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport interface LayoutServerLocale {\n /**\n * Expression passed as `locale` to `loadCms`, given the name of the load's\n * event parameter: `() => \"'en'\"` or `(event) => \\`getLocale(${event}.url)\\``.\n */\n expression: (eventName: string) => string;\n /** Imports the expression depends on. */\n imports?: ImportSpec[];\n}\n\n/** A single-locale site: the literal default locale. */\nexport const DEFAULT_LOCALE: LayoutServerLocale = {\n expression: () => \"'en'\",\n};\n\n/**\n * A wuchale site: the language enable-i18n's handle chose for the request,\n * from the URL on a public page and the visitor's preference elsewhere, so\n * the content is in the language the rest of the page is in.\n */\nexport const REQUEST_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `${eventName}.locals.locale`,\n};\n\n/**\n * A wuchale site enabled before the handle set `locals.locale`: the locale\n * its reroute resolved from the URL.\n */\nexport const WUCHALE_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `getLocale(${eventName}.url)`,\n imports: [\n { namedImports: [\"getLocale\"], moduleSpecifier: \"#locales/main.url.js\" },\n ],\n};\n\nfunction cmsSnippet(eventName: string, locale: string): string {\n return dedent`\n const { cms, notFound, gone, redirectTo } = await loadCms(${eventName}, { locale: ${locale} });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n `;\n}\n\nfunction importLine(spec: ImportSpec): string {\n const parts: string[] = [];\n if (spec.defaultImport) parts.push(spec.defaultImport);\n if (spec.namespaceImport) parts.push(`* as ${spec.namespaceImport}`);\n if (spec.namedImports?.length)\n parts.push(`{ ${spec.namedImports.join(\", \")} }`);\n return `import ${parts.join(\", \")} from '${spec.moduleSpecifier}';`;\n}\n\n/**\n * A root `+layout.server.ts` written from scratch, for a project that has\n * none — the static template keeps its layout load universal.\n */\nexport function createdLayoutServer(locale: LayoutServerLocale): string {\n const imports = [\n \"import { error, redirect } from '@sveltejs/kit';\",\n \"import { loadCms } from '#lib/cms.js';\",\n ...(locale.imports ?? []).map(importLine),\n \"import type { LayoutServerLoad } from './$types';\",\n ].join(\"\\n\");\n const snippet = cmsSnippet(\"event\", locale.expression(\"event\"))\n .split(\"\\n\")\n .join(\"\\n\\t\");\n\n return dedent`\n ${imports}\n\n export const load: LayoutServerLoad = async (event) => {\n \t${snippet}\n\n \treturn { cms };\n };\n `.concat(\"\\n\");\n}\n\nconst FAILURE_HINT = [\n \"Call loadCms from the root +layout.server.ts load and return `cms`:\",\n \"\",\n createdLayoutServer(DEFAULT_LOCALE).trimEnd(),\n \"\",\n \"loadCms needs the whole event, so a destructured parameter has to become\",\n \"`event` with the destructuring moved into the body.\",\n].join(\"\\n\");\n\n/**\n * Wires `loadCms` into the root `+layout.server.ts`, creating the file when\n * the project has none:\n *\n * - `loadCms` needs the whole request event, so a destructured parameter is\n * renamed to `event` and the destructuring becomes the first statement.\n * - The tombstone triple (`redirectTo`, `gone`, `notFound`) is handled just\n * before the return.\n * - `cms` is added to the returned object, ahead of any spread so nothing\n * later can shadow it.\n *\n * Anything else — no exported `load`, an expression-bodied arrow, several\n * returns, a non-literal return — is reported as `failed` with the snippet to\n * paste, and the file is left exactly as it was.\n */\nexport function modifyLayoutServer(\n layoutServerPath: string,\n locale: LayoutServerLocale = DEFAULT_LOCALE,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, createdLayoutServer(locale));\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"loadCms(\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n\n // --- Inspect everything before touching anything. ---\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"failed\", message: FAILURE_HINT };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n const object = returned && returnedObject(returned);\n if (!returned || !object) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const eventName = event.kind === \"identifier\" ? event.name : \"event\";\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n if (!hasProperty(object, \"cms\")) {\n const spreadIndex = object\n .getProperties()\n .findIndex((property) => Node.isSpreadAssignment(property));\n if (spreadIndex === -1) {\n object.addShorthandPropertyAssignment({ name: \"cms\" });\n } else {\n object.insertShorthandPropertyAssignment(spreadIndex, { name: \"cms\" });\n }\n }\n\n // insertStatements counts comment lines, which getStatements() skips.\n const returnIndex = body.getStatementsWithComments().indexOf(returned);\n body.insertStatements(\n returnIndex,\n `\\n${cmsSnippet(eventName, locale.expression(eventName))}\\n`,\n );\n\n if (event.kind === \"binding\") {\n const destructuring = event.pattern.getText();\n body.insertStatements(0, `const ${destructuring} = ${eventName};`);\n const typeText = event.param.getTypeNode()?.getText();\n event.param.replaceWithText(\n typeText ? `${eventName}: ${typeText}` : eventName,\n );\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: eventName });\n }\n\n if (!fn.isAsync()) fn.setIsAsync(true);\n\n ensureNamedImports(sourceFile, \"@sveltejs/kit\", [\"error\", \"redirect\"]);\n ensureNamedImports(sourceFile, \"#lib/cms.js\", [\"loadCms\"]);\n for (const spec of locale.imports ?? []) {\n ensureImportSpec(sourceFile, spec);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasSpreadOf,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Forward the server load's data through the root +layout.ts, so \\`cms\\` reaches\n the page:\n\n export const load = async ({ url, data }) => {\n // ...existing code...\n return { ...data, /* existing keys */ };\n };\n`;\n\n/**\n * Make a universal root \\`+layout.ts\\` forward its server load's data.\n *\n * SvelteKit hands a universal load the server load's result as \\`data\\`, and\n * only what the universal load returns reaches the page. A layout that\n * returns its own object without spreading \\`data\\` — the static template\n * does — would drop \\`cms\\` on the floor once \\`+layout.server.ts\\` exists.\n *\n * No file, or a file without a \\`load\\`, needs nothing: server data flows\n * through on its own.\n */\nexport function modifyLayoutUniversal(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutPath);\n\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"success\", changed: false };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n if (!returned) return { status: \"failed\", message: FAILURE_HINT };\n\n const dataExpression =\n event.kind === \"identifier\" ? `${event.name}.data` : \"data\";\n\n // `return data;` already forwards everything.\n const expression = returned.getExpression();\n if (expression && expression.getText() === dataExpression) {\n return { status: \"success\", changed: false };\n }\n\n const object = returnedObject(returned);\n if (!object) return { status: \"failed\", message: FAILURE_HINT };\n if (hasSpreadOf(object, dataExpression)) {\n return { status: \"success\", changed: false };\n }\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n // First, so the layout's own keys still win over anything the server sent.\n object.insertSpreadAssignment(0, { expression: dataExpression });\n\n if (event.kind === \"binding\") {\n const hasData = event.pattern\n .getElements()\n .some((element) => element.getName() === \"data\");\n if (!hasData) {\n const text = event.pattern.getText();\n event.pattern.replaceWithText(text.replace(/^\\{\\s*/, \"{ data, \"));\n }\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ data }\" });\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { AdminBar } from '@velastack/cms';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<AdminBar />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <AdminBar /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<AdminBar />` at the top level of the root layout, ahead of\n * `{@render children()}` so the bar is in the DOM before the page content.\n * Falls back to appending when the layout has no render tag or slot.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"AdminBar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { namedImports: [\"AdminBar\"], moduleSpecifier: \"@velastack/cms\" },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { resolveMode, type CmsMode } from \"./generate\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport {\n DEFAULT_LOCALE,\n REQUEST_LOCALE,\n WUCHALE_LOCALE,\n modifyLayoutServer,\n} from \"./modifies/layout.server\";\nimport { modifyLayoutUniversal } from \"./modifies/layout\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\n/** The locale list from `wuchale.config.js`, or null when it cannot be read. */\nexport function readWuchaleLocales(root: string): string[] | null {\n const configPath = path.join(root, \"wuchale.config.js\");\n if (!fs.existsSync(configPath)) return null;\n const match = fs\n .readFileSync(configPath, \"utf8\")\n .match(/locales:\\s*\\[([^\\]]*)\\]/);\n if (!match) return null;\n const locales = [...match[1].matchAll(/['\"]([^'\"]+)['\"]/g)].map((m) => m[1]);\n return locales.length > 0 ? locales : null;\n}\n\n/**\n * Arguments for the `cms()` Vite plugin.\n *\n * A hosted CMS needs the endpoint and locales at build time so media can be\n * downloaded into the prerendered site. An app hosting the backend itself\n * needs nothing: the media steps are no-ops without an endpoint.\n */\nexport function vitePluginArgs(mode: CmsMode, locales: string[]): string {\n if (mode.local) return \"\";\n const list = locales.map((locale) => `'${locale}'`).join(\", \");\n return `{ endpoint: '${mode.endpoint}', locales: [${list}] }`;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const mode = resolveMode(options);\n const i18n = options.features.i18n;\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n const locales = (i18n && readWuchaleLocales(options.root)) || [\"en\"];\n pushResult(\n modifyOutcomeToFile(\n viteConfigPath,\n modifyViteConfig(viteConfigPath, vitePluginArgs(mode, locales)),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n // `src/lib/locale.ts` came with the handle that sets `locals.locale`.\n const requestLocale = fs.existsSync(\n path.join(options.root, \"src\", \"lib\", \"locale.ts\"),\n );\n const locale = !i18n\n ? DEFAULT_LOCALE\n : requestLocale\n ? REQUEST_LOCALE\n : WUCHALE_LOCALE;\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServer(layoutServerPath, locale),\n ),\n );\n\n // A universal root layout has to pass the server load's data along, or\n // `cms` never reaches the page. The static template has one.\n logger.info(\"Modifying src/routes/+layout.ts\");\n const layoutUniversalPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutUniversalPath,\n modifyLayoutUniversal(layoutUniversalPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutSveltePath, modifyLayoutSvelte(layoutSveltePath)),\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":";;;;;;;;;;;;AAYA,IAAMA,IAAe,kNAUfC,IAAiB;AAYvB,SAASyB,EAAY,GAAsB;CACzC,OAAOC,EAAK,QAAQ,OAAO,EAAE;AAC/B;AAOA,SAAgBC,EACd,GACA,IAAa,IACE;CACf,IAAMC,IAAO,OAAOC,EAAW;CAC/B,IAAI,CAACR,EAAG,WAAWS,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS9B;CAAe;CAOxD,IAAM+B,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU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ACF"}
1
+ {"version":3,"file":"generate.runtime-DG9LRwbt.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","resolveMode","withInMemoryScript","ensureImports","dedent","hasProperty","newProject","findLoadFunction","returnedObject","ensureNamedImports","hasSpreadOf","findFinalReturn","inspectEventParameter","ensureImportSpec","SvelteFile","fs","path","FAILURE_HINT$3","NOT_FOUND_HINT$1","elementName","text","modifyViteConfig","call","pluginArgs","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","elements","el","sveltekitIndex","formatLikeSource","DEFAULT_LOCALE","REQUEST_LOCALE","eventName","WUCHALE_LOCALE","cmsSnippet","locale","importLine","parts","spec","createdLayoutServer","imports","snippet","FAILURE_HINT$2","modifyLayoutServer","layoutServerPath","fn","body","Node","event","returned","object","spreadIndex","property","returnIndex","destructuring","typeText","FAILURE_HINT$1","modifyLayoutUniversal","layoutPath","dataExpression","expression","element","IMPORT_SNIPPET","MARKUP_SNIPPET","NOT_FOUND_HINT","FAILURE_HINT","modifyLayoutSvelte","file","out","source","sf","readWuchaleLocales","configPath","root","match","locales","m","vitePluginArgs","mode","list","generate","logger","options","modifies","i18n","pushResult","requestLocale","layoutUniversalPath","layoutSveltePath"],"sources":["../../src/patterns/enable/cms/modifies/vite-config.ts","../../src/patterns/enable/cms/modifies/layout.server.ts","../../src/patterns/enable/cms/modifies/layout.ts","../../src/patterns/enable/cms/modifies/layout.svelte.ts","../../src/patterns/enable/cms/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the CMS plugin to your Vite config, ahead of sveltekit():\",\n \"\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the CMS plugin ahead of sveltekit():\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit()],\",\n \"});\",\n].join(\"\\n\");\n\nfunction elementName(text: string): string {\n return text.replace(/\\s/g, \"\");\n}\n\n/**\n * Registers `cms(...)` from `@velastack/cms/vite` in the Vite plugin list, just\n * ahead of `sveltekit()`. Only the plugin array is touched, so the inline\n * `sveltekit({ ... })` shape the templates use is left alone.\n */\nexport function modifyViteConfig(\n viteConfigPath: string,\n pluginArgs = \"\",\n): ModifyOutcome {\n const call = `cms(${pluginArgs})`;\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"@velastack/cms/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"cms\"],\n moduleSpecifier: \"@velastack/cms/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: `[${call}]`,\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (pluginsProp as PropertyAssignment).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as PropertyAssignment).setInitializer(`[${call}]`);\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as ArrayLiteralExpression;\n const elements = arr.getElements();\n const hasCms = elements.some((el) =>\n elementName(el.getText()).startsWith(\"cms(\"),\n );\n\n if (!hasCms) {\n const sveltekitIndex = elements.findIndex((el) =>\n elementName(el.getText()).startsWith(\"sveltekit(\"),\n );\n arr.insertElement(sveltekitIndex === -1 ? 0 : sveltekitIndex, call);\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n ensureImportSpec,\n ensureNamedImports,\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport interface LayoutServerLocale {\n /**\n * Expression passed as `locale` to `loadCms`, given the name of the load's\n * event parameter: `() => \"'en'\"` or `(event) => \\`getLocale(${event}.url)\\``.\n */\n expression: (eventName: string) => string;\n /** Imports the expression depends on. */\n imports?: ImportSpec[];\n}\n\n/** A single-locale site: the literal default locale. */\nexport const DEFAULT_LOCALE: LayoutServerLocale = {\n expression: () => \"'en'\",\n};\n\n/**\n * A wuchale site: the language enable-i18n's handle chose for the request,\n * from the URL on a public page and the visitor's preference elsewhere, so\n * the content is in the language the rest of the page is in.\n */\nexport const REQUEST_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `${eventName}.locals.locale`,\n};\n\n/**\n * A wuchale site enabled before the handle set `locals.locale`: the locale\n * its reroute resolved from the URL.\n */\nexport const WUCHALE_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `getLocale(${eventName}.url)`,\n imports: [\n { namedImports: [\"getLocale\"], moduleSpecifier: \"#locales/main.url.js\" },\n ],\n};\n\nfunction cmsSnippet(eventName: string, locale: string): string {\n return dedent`\n const { cms, notFound, gone, redirectTo } = await loadCms(${eventName}, { locale: ${locale} });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n `;\n}\n\nfunction importLine(spec: ImportSpec): string {\n const parts: string[] = [];\n if (spec.defaultImport) parts.push(spec.defaultImport);\n if (spec.namespaceImport) parts.push(`* as ${spec.namespaceImport}`);\n if (spec.namedImports?.length)\n parts.push(`{ ${spec.namedImports.join(\", \")} }`);\n return `import ${parts.join(\", \")} from '${spec.moduleSpecifier}';`;\n}\n\n/**\n * A root `+layout.server.ts` written from scratch, for a project that has\n * none — the static template keeps its layout load universal.\n */\nexport function createdLayoutServer(locale: LayoutServerLocale): string {\n const imports = [\n \"import { error, redirect } from '@sveltejs/kit';\",\n \"import { loadCms } from '#lib/cms.js';\",\n ...(locale.imports ?? []).map(importLine),\n \"import type { LayoutServerLoad } from './$types';\",\n ].join(\"\\n\");\n const snippet = cmsSnippet(\"event\", locale.expression(\"event\"))\n .split(\"\\n\")\n .join(\"\\n\\t\");\n\n return dedent`\n ${imports}\n\n export const load: LayoutServerLoad = async (event) => {\n \t${snippet}\n\n \treturn { cms };\n };\n `.concat(\"\\n\");\n}\n\nconst FAILURE_HINT = [\n \"Call loadCms from the root +layout.server.ts load and return `cms`:\",\n \"\",\n createdLayoutServer(DEFAULT_LOCALE).trimEnd(),\n \"\",\n \"loadCms needs the whole event, so a destructured parameter has to become\",\n \"`event` with the destructuring moved into the body.\",\n].join(\"\\n\");\n\n/**\n * Wires `loadCms` into the root `+layout.server.ts`, creating the file when\n * the project has none:\n *\n * - `loadCms` needs the whole request event, so a destructured parameter is\n * renamed to `event` and the destructuring becomes the first statement.\n * - The tombstone triple (`redirectTo`, `gone`, `notFound`) is handled just\n * before the return.\n * - `cms` is added to the returned object, ahead of any spread so nothing\n * later can shadow it.\n *\n * Anything else — no exported `load`, an expression-bodied arrow, several\n * returns, a non-literal return — is reported as `failed` with the snippet to\n * paste, and the file is left exactly as it was.\n */\nexport function modifyLayoutServer(\n layoutServerPath: string,\n locale: LayoutServerLocale = DEFAULT_LOCALE,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, createdLayoutServer(locale));\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"loadCms(\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n\n // --- Inspect everything before touching anything. ---\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"failed\", message: FAILURE_HINT };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n const object = returned && returnedObject(returned);\n if (!returned || !object) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const eventName = event.kind === \"identifier\" ? event.name : \"event\";\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n if (!hasProperty(object, \"cms\")) {\n const spreadIndex = object\n .getProperties()\n .findIndex((property) => Node.isSpreadAssignment(property));\n if (spreadIndex === -1) {\n object.addShorthandPropertyAssignment({ name: \"cms\" });\n } else {\n object.insertShorthandPropertyAssignment(spreadIndex, { name: \"cms\" });\n }\n }\n\n // insertStatements counts comment lines, which getStatements() skips.\n const returnIndex = body.getStatementsWithComments().indexOf(returned);\n body.insertStatements(\n returnIndex,\n `\\n${cmsSnippet(eventName, locale.expression(eventName))}\\n`,\n );\n\n if (event.kind === \"binding\") {\n const destructuring = event.pattern.getText();\n body.insertStatements(0, `const ${destructuring} = ${eventName};`);\n const typeText = event.param.getTypeNode()?.getText();\n event.param.replaceWithText(\n typeText ? `${eventName}: ${typeText}` : eventName,\n );\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: eventName });\n }\n\n if (!fn.isAsync()) fn.setIsAsync(true);\n\n ensureNamedImports(sourceFile, \"@sveltejs/kit\", [\"error\", \"redirect\"]);\n ensureNamedImports(sourceFile, \"#lib/cms.js\", [\"loadCms\"]);\n for (const spec of locale.imports ?? []) {\n ensureImportSpec(sourceFile, spec);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasSpreadOf,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Forward the server load's data through the root +layout.ts, so \\`cms\\` reaches\n the page:\n\n export const load = async ({ url, data }) => {\n // ...existing code...\n return { ...data, /* existing keys */ };\n };\n`;\n\n/**\n * Make a universal root \\`+layout.ts\\` forward its server load's data.\n *\n * SvelteKit hands a universal load the server load's result as \\`data\\`, and\n * only what the universal load returns reaches the page. A layout that\n * returns its own object without spreading \\`data\\` — the static template\n * does — would drop \\`cms\\` on the floor once \\`+layout.server.ts\\` exists.\n *\n * No file, or a file without a \\`load\\`, needs nothing: server data flows\n * through on its own.\n */\nexport function modifyLayoutUniversal(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutPath);\n\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"success\", changed: false };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n if (!returned) return { status: \"failed\", message: FAILURE_HINT };\n\n const dataExpression =\n event.kind === \"identifier\" ? `${event.name}.data` : \"data\";\n\n // `return data;` already forwards everything.\n const expression = returned.getExpression();\n if (expression && expression.getText() === dataExpression) {\n return { status: \"success\", changed: false };\n }\n\n const object = returnedObject(returned);\n if (!object) return { status: \"failed\", message: FAILURE_HINT };\n if (hasSpreadOf(object, dataExpression)) {\n return { status: \"success\", changed: false };\n }\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n // First, so the layout's own keys still win over anything the server sent.\n object.insertSpreadAssignment(0, { expression: dataExpression });\n\n if (event.kind === \"binding\") {\n const hasData = event.pattern\n .getElements()\n .some((element) => element.getName() === \"data\");\n if (!hasData) {\n const text = event.pattern.getText();\n event.pattern.replaceWithText(text.replace(/^\\{\\s*/, \"{ data, \"));\n }\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ data }\" });\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { AdminBar } from '@velastack/cms';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<AdminBar />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <AdminBar /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<AdminBar />` at the top level of the root layout, ahead of\n * `{@render children()}` so the bar is in the DOM before the page content.\n * Falls back to appending when the layout has no render tag or slot.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"AdminBar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { namedImports: [\"AdminBar\"], moduleSpecifier: \"@velastack/cms\" },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { resolveMode, type CmsMode } from \"./generate\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport {\n DEFAULT_LOCALE,\n REQUEST_LOCALE,\n WUCHALE_LOCALE,\n modifyLayoutServer,\n} from \"./modifies/layout.server\";\nimport { modifyLayoutUniversal } from \"./modifies/layout\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\n/** The locale list from `wuchale.config.js`, or null when it cannot be read. */\nexport function readWuchaleLocales(root: string): string[] | null {\n const configPath = path.join(root, \"wuchale.config.js\");\n if (!fs.existsSync(configPath)) return null;\n const match = fs\n .readFileSync(configPath, \"utf8\")\n .match(/locales:\\s*\\[([^\\]]*)\\]/);\n if (!match) return null;\n const locales = [...match[1].matchAll(/['\"]([^'\"]+)['\"]/g)].map((m) => m[1]);\n return locales.length > 0 ? locales : null;\n}\n\n/**\n * Arguments for the `cms()` Vite plugin.\n *\n * A hosted CMS needs the endpoint and locales at build time so media can be\n * downloaded into the prerendered site. An app hosting the backend itself\n * needs nothing: the media steps are no-ops without an endpoint.\n */\nexport function vitePluginArgs(mode: CmsMode, locales: string[]): string {\n if (mode.local) return \"\";\n const list = locales.map((locale) => `'${locale}'`).join(\", \");\n return `{ endpoint: '${mode.endpoint}', locales: [${list}] }`;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const mode = resolveMode(options);\n const i18n = options.features.i18n;\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n const locales = (i18n && readWuchaleLocales(options.root)) || [\"en\"];\n pushResult(\n modifyOutcomeToFile(\n viteConfigPath,\n modifyViteConfig(viteConfigPath, vitePluginArgs(mode, locales)),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n // `src/lib/locale.ts` came with the handle that sets `locals.locale`.\n const requestLocale = fs.existsSync(\n path.join(options.root, \"src\", \"lib\", \"locale.ts\"),\n );\n const locale = !i18n\n ? DEFAULT_LOCALE\n : requestLocale\n ? REQUEST_LOCALE\n : WUCHALE_LOCALE;\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServer(layoutServerPath, locale),\n ),\n );\n\n // A universal root layout has to pass the server load's data along, or\n // `cms` never reaches the page. The static template has one.\n logger.info(\"Modifying src/routes/+layout.ts\");\n const layoutUniversalPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutUniversalPath,\n modifyLayoutUniversal(layoutUniversalPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutSveltePath, modifyLayoutSvelte(layoutSveltePath)),\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":";;;;;;;;;;;;AAYA,IAAMA,IAAe,kNAUfC,IAAiB;AAYvB,SAASyB,EAAY,GAAsB;CACzC,OAAOC,EAAK,QAAQ,OAAO,EAAE;AAC/B;AAOA,SAAgBC,EACd,GACA,IAAa,IACE;CACf,IAAMC,IAAO,OAAOC,EAAW;CAC/B,IAAI,CAACR,EAAG,WAAWS,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS9B;CAAe;CAOxD,IAAM+B,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAA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;CACpB;AACF"}
@@ -1,10 +1,10 @@
1
1
  import { n as e } from "./logger-t1HxmpG2.js";
2
2
  import { n as t } from "./env-AxyRWcC_.js";
3
- import { t as n } from "./modify-file-BX9-aZD1.js";
4
- import { n as r } from "./shared-BOFCKWJs.js";
5
- import { o as i } from "./generate-DZ9kT3iC.js";
6
- import { n as a, r as o, t as s } from "./generate-BRTIGlqT.js";
7
- import { unmodifyEnvVarsFiles as c } from "./env-vars-Dm3Xy4rl.js";
3
+ import { t as n } from "./modify-file-BOEKlIDw.js";
4
+ import { n as r } from "./shared-CSwGWMcN.js";
5
+ import { o as i } from "./generate-CL7wG0ZC.js";
6
+ import { n as a, r as o, t as s } from "./generate-CbchamhA.js";
7
+ import { unmodifyEnvVarsFiles as c } from "./env-vars-C3TSZc4f.js";
8
8
  import l from "node:fs";
9
9
  import u from "node:path";
10
10
  // src/patterns/disable/ai/generate.runtime.ts
@@ -31,4 +31,4 @@ async function d(d) {
31
31
  }
32
32
  export { d as generate };
33
33
 
34
- //# sourceMappingURL=generate.runtime-CIOi-XSm.js.map
34
+ //# sourceMappingURL=generate.runtime-DKL7VAAd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-CIOi-XSm.js","names":["getLogger","modifyEnvRemove","envRevertOutcomeToFile","toDeleteEntry","demoDir","allEnvNames","demoDirs","allEnvEdits","fs","path","generate","logger","options","modifies","deletes","current","dir","page","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/ai/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 { modifyEnvRemove } from \"../../../runtime/env\";\nimport { envRevertOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { demoDir } from \"../../enable/ai/generate\";\nimport { allEnvEdits, allEnvNames, demoDirs } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n // The base result names the page in the current default group; a page\n // generated before auth was enabled sits in the other one.\n const current = demoDir(options);\n for (const dir of demoDirs(options)) {\n const page = `${dir}/+page.svelte`;\n if (dir !== current && fs.existsSync(path.join(options.root, page))) {\n deletes.push(toDeleteEntry(page));\n }\n }\n\n // Which provider was chosen is not recorded, so every one's key goes; the\n // file goes too when these were all it declared.\n logger.info(\"Removing the AI provider's API key from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n if (envVars.modify) modifies.push(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing the AI provider's API key from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n if (env.modify) modifies.push(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":";;;;;;;;;;AAWA,eAAsBU,EAAS,GAAkB;CAC/C,IAAMC,IAASX,EAAUY,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GAInBC,IAAUX,EAAQQ,CAAO;CAC/B,KAAK,IAAMI,KAAOV,EAASM,CAAO,GAAG;EACnC,IAAMK,IAAO,GAAGD,EAAI;EACpB,AAAIA,MAAQD,KAAWP,EAAG,WAAWC,EAAK,KAAKG,EAAQ,MAAMK,CAAI,CAAC,KAChEH,EAAQ,KAAKX,EAAcc,CAAI,CAAC;CAEpC;CAIA,EAAO,KAAK,oDAAoD;CAChE,IAAMC,IAAUC,EAAqBP,EAAQ,MAAMP,EAAY,CAAC;CAIhE,AAHIa,EAAQ,UAAQL,EAAS,KAAKK,EAAQ,MAAM,GAC5CA,EAAQ,UAAQJ,EAAQ,KAAKI,EAAQ,MAAM,GAE/CP,EAAO,KAAK,8CAA8C;CAC1D,IAAMS,IAAUX,EAAK,KAAKG,EAAQ,MAAM,MAAM,GACxCS,IAAMnB,EACVkB,GACAnB,EAAgBmB,GAASb,EAAY,CAAC,CACxC;CAIA,OAHIc,EAAI,UAAQR,EAAS,KAAKQ,EAAI,MAAM,GACpCA,EAAI,UAAQP,EAAQ,KAAKO,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-DKL7VAAd.js","names":["getLogger","modifyEnvRemove","envRevertOutcomeToFile","toDeleteEntry","demoDir","allEnvNames","demoDirs","allEnvEdits","fs","path","generate","logger","options","modifies","deletes","current","dir","page","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/ai/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 { modifyEnvRemove } from \"../../../runtime/env\";\nimport { envRevertOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { demoDir } from \"../../enable/ai/generate\";\nimport { allEnvEdits, allEnvNames, demoDirs } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n // The base result names the page in the current default group; a page\n // generated before auth was enabled sits in the other one.\n const current = demoDir(options);\n for (const dir of demoDirs(options)) {\n const page = `${dir}/+page.svelte`;\n if (dir !== current && fs.existsSync(path.join(options.root, page))) {\n deletes.push(toDeleteEntry(page));\n }\n }\n\n // Which provider was chosen is not recorded, so every one's key goes; the\n // file goes too when these were all it declared.\n logger.info(\"Removing the AI provider's API key from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n if (envVars.modify) modifies.push(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing the AI provider's API key from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n if (env.modify) modifies.push(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":";;;;;;;;;;AAWA,eAAsBU,EAAS,GAAkB;CAC/C,IAAMC,IAASX,EAAUY,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GAInBC,IAAUX,EAAQQ,CAAO;CAC/B,KAAK,IAAMI,KAAOV,EAASM,CAAO,GAAG;EACnC,IAAMK,IAAO,GAAGD,EAAI;EACpB,AAAIA,MAAQD,KAAWP,EAAG,WAAWC,EAAK,KAAKG,EAAQ,MAAMK,CAAI,CAAC,KAChEH,EAAQ,KAAKX,EAAcc,CAAI,CAAC;CAEpC;CAIA,EAAO,KAAK,oDAAoD;CAChE,IAAMC,IAAUC,EAAqBP,EAAQ,MAAMP,EAAY,CAAC;CAIhE,AAHIa,EAAQ,UAAQL,EAAS,KAAKK,EAAQ,MAAM,GAC5CA,EAAQ,UAAQJ,EAAQ,KAAKI,EAAQ,MAAM,GAE/CP,EAAO,KAAK,8CAA8C;CAC1D,IAAMS,IAAUX,EAAK,KAAKG,EAAQ,MAAM,MAAM,GACxCS,IAAMnB,EACVkB,GACAnB,EAAgBmB,GAASb,EAAY,CAAC,CACxC;CAIA,OAHIc,EAAI,UAAQR,EAAS,KAAKQ,EAAI,MAAM,GACpCA,EAAI,UAAQP,EAAQ,KAAKO,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"}