@velastack/patterns 0.4.2 → 0.5.0
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.
- package/README.md +22 -2
- package/dist/chunks/{_page-e_I-fdSR.js → _page-DoPdZgZv.js} +2 -2
- package/dist/chunks/_page-DoPdZgZv.js.map +1 -0
- package/dist/chunks/collections-Cpjo2OiQ.js +203 -0
- package/dist/chunks/collections-Cpjo2OiQ.js.map +1 -0
- package/dist/chunks/dispatch-BIvOwbKN.js +6 -0
- package/dist/chunks/dispatch-BIvOwbKN.js.map +1 -0
- package/dist/chunks/{env-vars-CcE6ODqC.js → env-vars-Bj41Nccm.js} +32 -20
- package/dist/chunks/env-vars-Bj41Nccm.js.map +1 -0
- package/dist/chunks/generate-BClgUH4J.js +137 -0
- package/dist/chunks/generate-BClgUH4J.js.map +1 -0
- package/dist/chunks/{generate-CZGHByV3.js → generate-DjBMRzsB.js} +6 -6
- package/dist/chunks/{generate-CZGHByV3.js.map → generate-DjBMRzsB.js.map} +1 -1
- package/dist/chunks/{generate-DetW_gbr.js → generate-DyV5R8NP.js} +7 -7
- package/dist/chunks/{generate-DetW_gbr.js.map → generate-DyV5R8NP.js.map} +1 -1
- package/dist/chunks/generate-ZIOVLH6Q.js +72 -0
- package/dist/chunks/generate-ZIOVLH6Q.js.map +1 -0
- package/dist/chunks/{generate-Bg0E3eWm.js → generate-dNlBII84.js} +4 -4
- package/dist/chunks/{generate-Bg0E3eWm.js.map → generate-dNlBII84.js.map} +1 -1
- package/dist/chunks/{generate-CFqpRi9D.js → generate-yi8AP3xH.js} +4 -4
- package/dist/chunks/{generate-CFqpRi9D.js.map → generate-yi8AP3xH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CpMKXBkn.js → generate.runtime-B4QoBn5v.js} +6 -6
- package/dist/chunks/{generate.runtime-CpMKXBkn.js.map → generate.runtime-B4QoBn5v.js.map} +1 -1
- package/dist/chunks/{generate.runtime-aQnBmH8D.js → generate.runtime-BKINIJ2c.js} +3 -3
- package/dist/chunks/{generate.runtime-aQnBmH8D.js.map → generate.runtime-BKINIJ2c.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dl6OQ7pe.js → generate.runtime-BKTkVCEm.js} +4 -4
- package/dist/chunks/{generate.runtime-Dl6OQ7pe.js.map → generate.runtime-BKTkVCEm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CAn1qIQ_.js → generate.runtime-BXZDKLbA.js} +3 -3
- package/dist/chunks/{generate.runtime-CAn1qIQ_.js.map → generate.runtime-BXZDKLbA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-hTKzxH2M.js → generate.runtime-BYfyZHhs.js} +7 -7
- package/dist/chunks/{generate.runtime-hTKzxH2M.js.map → generate.runtime-BYfyZHhs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DoZJHtZh.js → generate.runtime-BavEh01F.js} +6 -6
- package/dist/chunks/{generate.runtime-DoZJHtZh.js.map → generate.runtime-BavEh01F.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DJ9MVVPC.js → generate.runtime-BcgjZJug.js} +123 -110
- package/dist/chunks/generate.runtime-BcgjZJug.js.map +1 -0
- package/dist/chunks/generate.runtime-BdHv7Jp1.js +82 -0
- package/dist/chunks/generate.runtime-BdHv7Jp1.js.map +1 -0
- package/dist/chunks/{generate.runtime-CqncBFNg.js → generate.runtime-BdmoAVJK.js} +4 -4
- package/dist/chunks/{generate.runtime-CqncBFNg.js.map → generate.runtime-BdmoAVJK.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BpMN5Uq-.js → generate.runtime-Bdpu4rX0.js} +3 -3
- package/dist/chunks/{generate.runtime-BpMN5Uq-.js.map → generate.runtime-Bdpu4rX0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-uLUiPgqx.js → generate.runtime-C7s1Mx5L.js} +6 -6
- package/dist/chunks/{generate.runtime-uLUiPgqx.js.map → generate.runtime-C7s1Mx5L.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CEqLgLT9.js → generate.runtime-CCV4O6_I.js} +3 -3
- package/dist/chunks/{generate.runtime-CEqLgLT9.js.map → generate.runtime-CCV4O6_I.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CK10Mum5.js → generate.runtime-CSUnP0l-.js} +10 -10
- package/dist/chunks/{generate.runtime-CK10Mum5.js.map → generate.runtime-CSUnP0l-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-koQxLywh.js → generate.runtime-CV4soy2n.js} +6 -6
- package/dist/chunks/{generate.runtime-koQxLywh.js.map → generate.runtime-CV4soy2n.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Db0HZyj3.js → generate.runtime-CWgZhxQt.js} +2 -2
- package/dist/chunks/{generate.runtime-Db0HZyj3.js.map → generate.runtime-CWgZhxQt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-IWEhGhWY.js → generate.runtime-CcPCAEV0.js} +6 -6
- package/dist/chunks/{generate.runtime-IWEhGhWY.js.map → generate.runtime-CcPCAEV0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DG2z6kqH.js → generate.runtime-D-qtaVdq.js} +3 -3
- package/dist/chunks/{generate.runtime-DG2z6kqH.js.map → generate.runtime-D-qtaVdq.js.map} +1 -1
- package/dist/chunks/{generate.runtime-E-zoeSKW.js → generate.runtime-DBBtYTAa.js} +7 -7
- package/dist/chunks/{generate.runtime-E-zoeSKW.js.map → generate.runtime-DBBtYTAa.js.map} +1 -1
- package/dist/chunks/{generate.runtime-5rIc-RNL.js → generate.runtime-DRRyPa-e.js} +6 -6
- package/dist/chunks/{generate.runtime-5rIc-RNL.js.map → generate.runtime-DRRyPa-e.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BK3mR0Rj.js → generate.runtime-DaRVyiSg.js} +148 -127
- package/dist/chunks/generate.runtime-DaRVyiSg.js.map +1 -0
- package/dist/chunks/{generate.runtime-DVB7uuht.js → generate.runtime-DetYynf4.js} +3 -3
- package/dist/chunks/{generate.runtime-DVB7uuht.js.map → generate.runtime-DetYynf4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-a3R4hqFy.js → generate.runtime-DjCzW3zU.js} +12 -12
- package/dist/chunks/{generate.runtime-a3R4hqFy.js.map → generate.runtime-DjCzW3zU.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Djas9UNy.js → generate.runtime-DlbG-8Xm.js} +4 -4
- package/dist/chunks/{generate.runtime-Djas9UNy.js.map → generate.runtime-DlbG-8Xm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CbE9RHcf.js → generate.runtime-DmsOEsJV.js} +5 -5
- package/dist/chunks/generate.runtime-DmsOEsJV.js.map +1 -0
- package/dist/chunks/{generate.runtime-axm9wcQv.js → generate.runtime-MjWwR2Bd.js} +3 -3
- package/dist/chunks/{generate.runtime-axm9wcQv.js.map → generate.runtime-MjWwR2Bd.js.map} +1 -1
- package/dist/chunks/generate.runtime-NaSIZlP5.js +48 -0
- package/dist/chunks/generate.runtime-NaSIZlP5.js.map +1 -0
- package/dist/chunks/{generate.runtime-CZ46nkSL.js → generate.runtime-OEgsdWRP.js} +2 -2
- package/dist/chunks/{generate.runtime-CZ46nkSL.js.map → generate.runtime-OEgsdWRP.js.map} +1 -1
- package/dist/chunks/{generate.runtime-rs1ZOIET.js → generate.runtime-QbmCPT42.js} +3 -3
- package/dist/chunks/{generate.runtime-rs1ZOIET.js.map → generate.runtime-QbmCPT42.js.map} +1 -1
- package/dist/chunks/generate.runtime-azOvp6tl.js +106 -0
- package/dist/chunks/generate.runtime-azOvp6tl.js.map +1 -0
- package/dist/chunks/{generate.runtime-kciwaXxh.js → generate.runtime-b2RtuPy4.js} +4 -4
- package/dist/chunks/{generate.runtime-kciwaXxh.js.map → generate.runtime-b2RtuPy4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dp7SsCQG.js → generate.runtime-pMpn0Pbf.js} +3 -3
- package/dist/chunks/{generate.runtime-Dp7SsCQG.js.map → generate.runtime-pMpn0Pbf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DHHlYfTD.js → generate.runtime-utFLS6Jz.js} +3 -3
- package/dist/chunks/{generate.runtime-DHHlYfTD.js.map → generate.runtime-utFLS6Jz.js.map} +1 -1
- package/dist/chunks/modify-file-Bbhyfiy_.js +53 -0
- package/dist/chunks/modify-file-Bbhyfiy_.js.map +1 -0
- package/dist/chunks/{modify-nav-user-BLyrW2sK.js → modify-nav-user-B8h8WTrM.js} +2 -2
- package/dist/chunks/{modify-nav-user-BLyrW2sK.js.map → modify-nav-user-B8h8WTrM.js.map} +1 -1
- package/dist/chunks/providers-CL9kQ4hp.js +98 -0
- package/dist/chunks/providers-CL9kQ4hp.js.map +1 -0
- package/dist/chunks/providers-DwbwccSW.js +38 -0
- package/dist/chunks/providers-DwbwccSW.js.map +1 -0
- package/dist/chunks/{shared-Cc_ns5-y.js → shared-D5GOS97l.js} +2 -2
- package/dist/chunks/{shared-Cc_ns5-y.js.map → shared-D5GOS97l.js.map} +1 -1
- package/dist/chunks/shopify-page-D-VFwGxI.js +11 -0
- package/dist/chunks/shopify-page-D-VFwGxI.js.map +1 -0
- package/dist/chunks/stripe-customer-B3tP8gtD.js +6 -0
- package/dist/chunks/stripe-customer-B3tP8gtD.js.map +1 -0
- package/dist/chunks/{svelte-file-B3RfgVdt.js → svelte-file-Dv5-bl79.js} +37 -2
- package/dist/chunks/svelte-file-Dv5-bl79.js.map +1 -0
- package/dist/chunks/{test-setup-B9fQ5L_-.js → test-setup-DZoyF8Ak.js} +2 -2
- package/dist/chunks/{test-setup-B9fQ5L_-.js.map → test-setup-DZoyF8Ak.js.map} +1 -1
- package/dist/chunks/{ui-CuCsupFq.js → ui-BuocThuh.js} +2 -2
- package/dist/chunks/{ui-CuCsupFq.js.map → ui-BuocThuh.js.map} +1 -1
- package/dist/chunks/{write-result-DiZsCS_y.js → write-result-Cq-9A7Zy.js} +2 -2
- package/dist/chunks/write-result-Cq-9A7Zy.js.map +1 -0
- package/dist/index.d.ts +284 -22
- package/dist/index.js +2199 -2035
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/_page-e_I-fdSR.js.map +0 -1
- package/dist/chunks/collections-zzZ_HQxB.js +0 -192
- package/dist/chunks/collections-zzZ_HQxB.js.map +0 -1
- package/dist/chunks/dispatch-D4TN9pdW.js +0 -6
- package/dist/chunks/dispatch-D4TN9pdW.js.map +0 -1
- package/dist/chunks/env-vars-CcE6ODqC.js.map +0 -1
- package/dist/chunks/env-vars-De0Xs0L2.js +0 -20
- package/dist/chunks/env-vars-De0Xs0L2.js.map +0 -1
- package/dist/chunks/generate.runtime-BK3mR0Rj.js.map +0 -1
- package/dist/chunks/generate.runtime-CbE9RHcf.js.map +0 -1
- package/dist/chunks/generate.runtime-DJ9MVVPC.js.map +0 -1
- package/dist/chunks/generate.runtime-EQnytCFL.js +0 -122
- package/dist/chunks/generate.runtime-EQnytCFL.js.map +0 -1
- package/dist/chunks/modify-file-DK-tCH9k.js +0 -46
- package/dist/chunks/modify-file-DK-tCH9k.js.map +0 -1
- package/dist/chunks/providers-BHR6-XZ7.js +0 -76
- package/dist/chunks/providers-BHR6-XZ7.js.map +0 -1
- package/dist/chunks/svelte-file-B3RfgVdt.js.map +0 -1
- package/dist/chunks/write-result-DiZsCS_y.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-DHHlYfTD.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","FAILURE_HINT","NOT_FOUND_HINT","NOT_FOUND_HINT","dedent","withInMemoryScript","formatLikeSource","ensureImports","SvelteFile","addHandle","probeFirstExisting","VITE_CONFIG_CANDIDATES","modifyPackageImportsI18n","ensureRootLayoutI18n","fs","path","FAILURE_HINT$4","NOT_FOUND_HINT$3","modifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","el","I18N_HANDLE","FAILURE_HINT$3","HOOKS_SERVER_SNIPPET","ensureNamespaceImport","moduleSpecifier","ns","modifyHooksServerI18n","hooksServerPath","original","composed","handleStmt","ensureNamedImport","startupSnippet","i18nHandleSnippet","DELOCALIZE_HELPER","HOOKS_SNIPPET","FAILURE_HINT$2","NEGOTIATE_ONLY_REROUTE","hasOtherReroute","n","ensureDeLocalizeImports","modifyHooksI18n","hooksPath","rerouteDecl","init","target","s","FAILURE_HINT$1","NOT_FOUND_HINT$2","modifyAppHtml","appHtmlPath","updated","match","NOT_FOUND_HINT$1","modifyGitignore","gitignorePath","block","LANGUAGE_SELECT_SNIPPET","PLAIN_LANGUAGE_SELECT_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","PLAIN_FAILURE_HINT","PLAIN_NOT_FOUND_HINT","addImport","out","source","sf","modifyRootLayoutLanguageSelect","plain","ui","layoutPath","file","PAGE_PATH","CATALOG_PATH","WELCOME_PAGE","PAGE_ENTRIES","PLAIN_SELECT_ENTRY","HEADER","normalize","welcomePageCatalog","root","pagePath","entry","generate","logger","getLogger","options","modifies","pushResult","modifyOutcomeToFile","imports","rootLayoutCandidates","resolveUi","rootLayoutPath","p","catalog"],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/hooks.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/welcome-catalog.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\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() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/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 import(\"ts-morph\").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: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\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 { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\n`;\n\n/**\n * The whole file, for a project that had no server hooks: a fresh `sv create`\n * app or a static site. `disable-i18n` deletes it again once the i18n handle\n * is all that is left.\n */\nexport const HOOKS_SERVER_SNIPPET = dedent`\n import type { Handle } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale: Handle = async ({ event, resolve }) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }) => html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n\n export const handle = handleWuchale;\n`;\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || 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 // Composed first: an unsupported handle leaves the file untouched.\n const composed = addHandle(sourceFile, { expression: I18N_HANDLE });\n if (composed.status === \"unsupported\" || !composed.statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const handleStmt = composed.statement;\n\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"getLocale\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n ensureNamespaceImport(\n sourceFile,\n \"#locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"#locales/js.loader.server.js\", \"js\");\n\n const startupSnippet = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${I18N_HANDLE} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\n\n // Above the handle and its JSDoc, so `handleWuchale` is declared before\n // the handle reads it.\n sourceFile.insertText(\n handleStmt.getStart(true),\n `${startupSnippet}\\n\\n${i18nHandleSnippet}\\n\\n`,\n );\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = dedent`\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n`;\n\n/**\n * The whole file, for a project that had no universal hooks. `disable-i18n`\n * deletes it again once the de-localizing reroute is all that is left.\n */\nexport const HOOKS_SNIPPET = dedent`\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:\n\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));\n`;\n\n/** What `enable-content-negotiation` leaves behind, to the whitespace. */\nconst NEGOTIATE_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)$/;\n\n/** A `reroute` this modifier cannot compose with: not a variable declaration. */\nfunction hasOtherReroute(sourceFile: SourceFile): boolean {\n if (sourceFile.getFunction(\"reroute\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) =>\n d\n .getNamedExports()\n .some(\n (n) => (n.getAliasNode()?.getText() ?? n.getName()) === \"reroute\",\n ),\n );\n}\n\nfunction ensureDeLocalizeImports(sourceFile: SourceFile) {\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n}\n\n/**\n * Add the de-localizing reroute to `src/hooks.ts`, composing with the one\n * `enable-content-negotiation` wrote rather than replacing the file: either\n * pattern may be enabled first, and negotiation's `modifyHooksNegotiate`\n * composes the other way round.\n */\nexport function modifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, HOOKS_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"rerouteDeLocalize\")) {\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 rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n // A reroute in a shape ts-morph cannot rewrite (a function declaration,\n // a re-export) would collide with the one added below.\n if (hasOtherReroute(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n ensureDeLocalizeImports(sourceFile);\n sourceFile.addStatements(\n `\\n${DELOCALIZE_HELPER}\\n\\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init || !NEGOTIATE_ONLY_REROUTE.test(init.getText())) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureDeLocalizeImports(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n\n // Last: inserting text forgets the nodes above, and the helper has to be\n // declared before the reroute that reads it.\n const target = sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"reroute\"))!;\n sourceFile.insertText(target.getStart(true), `${DELOCALIZE_HELPER}\\n\\n`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n // A static lang (the templates ship lang=\"en\") is replaced by the\n // placeholder so the server hook can fill in the negotiated locale.\n if (/\\slang\\s*=/i.test(match)) {\n return match.replace(\n /\\slang\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n ' lang=\"%sveltekit.lang%\"',\n );\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\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 block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\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\";\nimport type { Ui } from \"../../../../core/field/ui\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst PLAIN_LANGUAGE_SELECT_SNIPPET = \"<LanguageSelect />\";\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '#lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_FAILURE_HINT = [\n \"Add the language select to your root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add wherever it should render, e.g. above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_NOT_FOUND_HINT = [\n \"Create a root layout that includes the language select.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nfunction addImport(file: SvelteFile): void {\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"#lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n}\n\n/**\n * A vela layout gets the select as the last `<Navbar.List>` item. A plain one\n * (a project vela did not create) has no navbar, so the select goes above the\n * layout's children.\n */\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n ui: Ui = \"shadcn\",\n): ModifyOutcome {\n const plain = ui === \"plain\";\n if (!fs.existsSync(layoutPath)) {\n return {\n status: \"not-found\",\n message: plain ? PLAIN_NOT_FOUND_HINT : NOT_FOUND_HINT,\n };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n if (plain) {\n // Without a <script> the import has nowhere to go, and the markup alone\n // would not compile.\n if (!file.getScript()) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n if (!file.insertBeforeChildren(PLAIN_LANGUAGE_SELECT_SNIPPET)) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n addImport(file);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n }\n\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n addImport(file);\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\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 } from \"../../../core/types\";\nimport type { Ui } from \"../../../core/field/ui\";\n\nconst PAGE_PATH = \"src/routes/+page.svelte\";\nconst CATALOG_PATH = \"src/locales/es.po\";\n\n/** `src/routes/+page.svelte` as `sv create` writes it. */\nconst WELCOME_PAGE = [\n \"<h1>Welcome to SvelteKit</h1>\",\n '<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>',\n].join(\"\\n\");\n\ninterface Entry {\n reference: string;\n msgid: string;\n msgstr: string;\n}\n\nconst PAGE_ENTRIES: Entry[] = [\n {\n reference: PAGE_PATH,\n msgid: \"Welcome to SvelteKit\",\n msgstr: \"Bienvenido a SvelteKit\",\n },\n {\n reference: PAGE_PATH,\n msgid: \"Visit <0>svelte.dev/docs/kit</0> to read the documentation\",\n msgstr: \"Visita <0>svelte.dev/docs/kit</0> para leer la documentación\",\n },\n];\n\n// The native <select>'s aria-label. The shadcn select has no text of its own:\n// locale names come from Intl.DisplayNames.\nconst PLAIN_SELECT_ENTRY: Entry = {\n reference: \"src/lib/components/language-select.svelte\",\n msgid: \"Language\",\n msgstr: \"Idioma\",\n};\n\n// What wuchale writes for `es`. It rewrites the file on the first extraction,\n// keeping these translations and adding the source locale's catalog.\nconst HEADER = [\n 'msgid \"\"',\n 'msgstr \"\"',\n '\"Source-Language: en\\\\n\"',\n '\"Language: es\\\\n\"',\n '\"MIME-Version: 1.0\\\\n\"',\n '\"Content-Type: text/plain; charset=utf-8\\\\n\"',\n '\"Content-Transfer-Encoding: 8bit\\\\n\"',\n '\"Plural-Forms: nplurals=3\\\\n\"',\n '\"X-Plurals-Order: one, many, other\\\\n\"',\n].join(\"\\n\");\n\n// Whitespace is ignored so a page prettier has rewrapped still counts.\nconst normalize = (source: string) => source.replace(/\\s+/g, \"\");\n\n/**\n * A Spanish catalog for the `sv create` welcome page, so the language select\n * visibly does something on a fresh project. Anything else in the project is\n * left for the user to translate. Null unless the page is untouched, and never\n * over an existing catalog.\n */\nexport function welcomePageCatalog(root: string, ui: Ui): File | null {\n if (fs.existsSync(path.join(root, CATALOG_PATH))) return null;\n\n const pagePath = path.join(root, PAGE_PATH);\n if (!fs.existsSync(pagePath)) return null;\n const page = fs.readFileSync(pagePath, \"utf8\");\n if (normalize(page) !== normalize(WELCOME_PAGE)) return null;\n\n const entries =\n ui === \"plain\" ? [...PAGE_ENTRIES, PLAIN_SELECT_ENTRY] : PAGE_ENTRIES;\n const blocks = entries.map((entry) =>\n [\n `#: ${entry.reference}`,\n `msgid \"${entry.msgid}\"`,\n `msgstr \"${entry.msgstr}\"`,\n ].join(\"\\n\"),\n );\n\n return {\n path: CATALOG_PATH,\n language: \"text\",\n content: [HEADER, ...blocks].join(\"\\n\\n\") + \"\\n\",\n status: \"success\",\n };\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 { resolveUi } from \"../../../core/field/ui\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifyPackageImportsI18n } from \"./modifies/package-imports\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\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 pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Adding #locales to package.json imports\");\n const imports = modifyPackageImportsI18n(options.root);\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksI18n(hooksPath)));\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying 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 const ui = resolveUi(options);\n // With no layout at all, a plain project's not-found hint names the\n // +layout.svelte it would have rather than vela's root-layout.svelte.\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n (ui === \"plain\" ? rootLayoutCandidates[3] : rootLayoutCandidates[0]);\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath, ui),\n ),\n );\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n return {\n creates: catalog ? [catalog] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAMA,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgBoB,EAAiB,GAAuC;CACtE,IAAI,CAACJ,EAAG,WAAWK,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAASrB;CAAe;CAOxD,IAAMsB,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBH,CAAc,GAEzDI,IAAU,IACVC,IAAS;CAMb,AAJkBJ,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAMK,EAAE,wBAAwB,MAAM,cAE1C,MACHL,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,CAAC,GACD,IAAU;CAOZ,IAAMM,IAJmBN,EACtB,qBAAqBO,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,cAE/B,CAAA,EAAkB,aAAa,CAAC,GAAG,IAC/CC,IACJH,GAAW,QAAQ,MAAMC,EAAW,0BAC/BD,IACD;CAEN,IAAI,CAACG,GACH,IAAS;MACJ;EACL,IAAMC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oryScript","formatLikeSource","ensureImports","modifyOutcomeToFile","SvelteFile","addHandle","probeFirstExisting","VITE_CONFIG_CANDIDATES","modifyPackageImportsI18n","ensureRootLayoutI18n","fs","path","FAILURE_HINT$4","NOT_FOUND_HINT$3","modifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","el","I18N_HANDLE","FAILURE_HINT$3","HOOKS_SERVER_SNIPPET","ensureNamespaceImport","moduleSpecifier","ns","modifyHooksServerI18n","hooksServerPath","original","composed","handleStmt","ensureNamedImport","startupSnippet","i18nHandleSnippet","DELOCALIZE_HELPER","HOOKS_SNIPPET","FAILURE_HINT$2","NEGOTIATE_ONLY_REROUTE","hasOtherReroute","n","ensureDeLocalizeImports","modifyHooksI18n","hooksPath","rerouteDecl","init","target","s","FAILURE_HINT$1","NOT_FOUND_HINT$2","modifyAppHtml","appHtmlPath","updated","match","NOT_FOUND_HINT$1","modifyGitignore","gitignorePath","block","LANGUAGE_SELECT_SNIPPET","PLAIN_LANGUAGE_SELECT_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","PLAIN_FAILURE_HINT","PLAIN_NOT_FOUND_HINT","addImport","out","source","sf","modifyRootLayoutLanguageSelect","plain","ui","layoutPath","file","PAGE_PATH","CATALOG_PATH","WELCOME_PAGE","PAGE_ENTRIES","PLAIN_SELECT_ENTRY","HEADER","normalize","welcomePageCatalog","root","pagePath","entry","generate","logger","getLogger","options","modifies","pushResult","imports","rootLayoutCandidates","resolveUi","rootLayoutPath","p","catalog"],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/hooks.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/welcome-catalog.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\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() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/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 import(\"ts-morph\").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: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\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 { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\n`;\n\n/**\n * The whole file, for a project that had no server hooks: a fresh `sv create`\n * app or a static site. `disable-i18n` deletes it again once the i18n handle\n * is all that is left.\n */\nexport const HOOKS_SERVER_SNIPPET = dedent`\n import type { Handle } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale: Handle = async ({ event, resolve }) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }) => html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n\n export const handle = handleWuchale;\n`;\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || 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 // Composed first: an unsupported handle leaves the file untouched.\n const composed = addHandle(sourceFile, { expression: I18N_HANDLE });\n if (composed.status === \"unsupported\" || !composed.statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const handleStmt = composed.statement;\n\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"getLocale\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n ensureNamespaceImport(\n sourceFile,\n \"#locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"#locales/js.loader.server.js\", \"js\");\n\n const startupSnippet = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${I18N_HANDLE} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\n\n // Above the handle and its JSDoc, so `handleWuchale` is declared before\n // the handle reads it.\n sourceFile.insertText(\n handleStmt.getStart(true),\n `${startupSnippet}\\n\\n${i18nHandleSnippet}\\n\\n`,\n );\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = dedent`\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n`;\n\n/**\n * The whole file, for a project that had no universal hooks. `disable-i18n`\n * deletes it again once the de-localizing reroute is all that is left.\n */\nexport const HOOKS_SNIPPET = dedent`\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:\n\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));\n`;\n\n/** What `enable-content-negotiation` leaves behind, to the whitespace. */\nconst NEGOTIATE_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)$/;\n\n/** A `reroute` this modifier cannot compose with: not a variable declaration. */\nfunction hasOtherReroute(sourceFile: SourceFile): boolean {\n if (sourceFile.getFunction(\"reroute\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) =>\n d\n .getNamedExports()\n .some(\n (n) => (n.getAliasNode()?.getText() ?? n.getName()) === \"reroute\",\n ),\n );\n}\n\nfunction ensureDeLocalizeImports(sourceFile: SourceFile) {\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n}\n\n/**\n * Add the de-localizing reroute to `src/hooks.ts`, composing with the one\n * `enable-content-negotiation` wrote rather than replacing the file: either\n * pattern may be enabled first, and negotiation's `modifyHooksNegotiate`\n * composes the other way round.\n */\nexport function modifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, HOOKS_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"rerouteDeLocalize\")) {\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 rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n // A reroute in a shape ts-morph cannot rewrite (a function declaration,\n // a re-export) would collide with the one added below.\n if (hasOtherReroute(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n ensureDeLocalizeImports(sourceFile);\n sourceFile.addStatements(\n `\\n${DELOCALIZE_HELPER}\\n\\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init || !NEGOTIATE_ONLY_REROUTE.test(init.getText())) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureDeLocalizeImports(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n\n // Last: inserting text forgets the nodes above, and the helper has to be\n // declared before the reroute that reads it.\n const target = sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"reroute\"))!;\n sourceFile.insertText(target.getStart(true), `${DELOCALIZE_HELPER}\\n\\n`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n // A static lang (the templates ship lang=\"en\") is replaced by the\n // placeholder so the server hook can fill in the negotiated locale.\n if (/\\slang\\s*=/i.test(match)) {\n return match.replace(\n /\\slang\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n ' lang=\"%sveltekit.lang%\"',\n );\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\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 block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\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\";\nimport type { Ui } from \"../../../../core/field/ui\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst PLAIN_LANGUAGE_SELECT_SNIPPET = \"<LanguageSelect />\";\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '#lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_FAILURE_HINT = [\n \"Add the language select to your root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add wherever it should render, e.g. above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_NOT_FOUND_HINT = [\n \"Create a root layout that includes the language select.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nfunction addImport(file: SvelteFile): void {\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"#lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n}\n\n/**\n * A vela layout gets the select as the last `<Navbar.List>` item. A plain one\n * (a project vela did not create) has no navbar, so the select goes above the\n * layout's children.\n */\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n ui: Ui = \"shadcn\",\n): ModifyOutcome {\n const plain = ui === \"plain\";\n if (!fs.existsSync(layoutPath)) {\n return {\n status: \"not-found\",\n message: plain ? PLAIN_NOT_FOUND_HINT : NOT_FOUND_HINT,\n };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n if (plain) {\n // Without a <script> the import has nowhere to go, and the markup alone\n // would not compile.\n if (!file.getScript()) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n if (!file.insertBeforeChildren(PLAIN_LANGUAGE_SELECT_SNIPPET)) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n addImport(file);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n }\n\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n addImport(file);\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\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 } from \"../../../core/types\";\nimport type { Ui } from \"../../../core/field/ui\";\n\nconst PAGE_PATH = \"src/routes/+page.svelte\";\nconst CATALOG_PATH = \"src/locales/es.po\";\n\n/** `src/routes/+page.svelte` as `sv create` writes it. */\nconst WELCOME_PAGE = [\n \"<h1>Welcome to SvelteKit</h1>\",\n '<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>',\n].join(\"\\n\");\n\ninterface Entry {\n reference: string;\n msgid: string;\n msgstr: string;\n}\n\nconst PAGE_ENTRIES: Entry[] = [\n {\n reference: PAGE_PATH,\n msgid: \"Welcome to SvelteKit\",\n msgstr: \"Bienvenido a SvelteKit\",\n },\n {\n reference: PAGE_PATH,\n msgid: \"Visit <0>svelte.dev/docs/kit</0> to read the documentation\",\n msgstr: \"Visita <0>svelte.dev/docs/kit</0> para leer la documentación\",\n },\n];\n\n// The native <select>'s aria-label. The shadcn select has no text of its own:\n// locale names come from Intl.DisplayNames.\nconst PLAIN_SELECT_ENTRY: Entry = {\n reference: \"src/lib/components/language-select.svelte\",\n msgid: \"Language\",\n msgstr: \"Idioma\",\n};\n\n// What wuchale writes for `es`. It rewrites the file on the first extraction,\n// keeping these translations and adding the source locale's catalog.\nconst HEADER = [\n 'msgid \"\"',\n 'msgstr \"\"',\n '\"Source-Language: en\\\\n\"',\n '\"Language: es\\\\n\"',\n '\"MIME-Version: 1.0\\\\n\"',\n '\"Content-Type: text/plain; charset=utf-8\\\\n\"',\n '\"Content-Transfer-Encoding: 8bit\\\\n\"',\n '\"Plural-Forms: nplurals=3\\\\n\"',\n '\"X-Plurals-Order: one, many, other\\\\n\"',\n].join(\"\\n\");\n\n// Whitespace is ignored so a page prettier has rewrapped still counts.\nconst normalize = (source: string) => source.replace(/\\s+/g, \"\");\n\n/**\n * A Spanish catalog for the `sv create` welcome page, so the language select\n * visibly does something on a fresh project. Anything else in the project is\n * left for the user to translate. Null unless the page is untouched, and never\n * over an existing catalog.\n */\nexport function welcomePageCatalog(root: string, ui: Ui): File | null {\n if (fs.existsSync(path.join(root, CATALOG_PATH))) return null;\n\n const pagePath = path.join(root, PAGE_PATH);\n if (!fs.existsSync(pagePath)) return null;\n const page = fs.readFileSync(pagePath, \"utf8\");\n if (normalize(page) !== normalize(WELCOME_PAGE)) return null;\n\n const entries =\n ui === \"plain\" ? [...PAGE_ENTRIES, PLAIN_SELECT_ENTRY] : PAGE_ENTRIES;\n const blocks = entries.map((entry) =>\n [\n `#: ${entry.reference}`,\n `msgid \"${entry.msgid}\"`,\n `msgstr \"${entry.msgstr}\"`,\n ].join(\"\\n\"),\n );\n\n return {\n path: CATALOG_PATH,\n language: \"text\",\n content: [HEADER, ...blocks].join(\"\\n\\n\") + \"\\n\",\n status: \"success\",\n };\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 { resolveUi } from \"../../../core/field/ui\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifyPackageImportsI18n } from \"./modifies/package-imports\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\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 pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Adding #locales to package.json imports\");\n const imports = modifyPackageImportsI18n(options.root);\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksI18n(hooksPath)));\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying 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 const ui = resolveUi(options);\n // With no layout at all, a plain project's not-found hint names the\n // +layout.svelte it would have rather than vela's root-layout.svelte.\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n (ui === \"plain\" ? rootLayoutCandidates[3] : rootLayoutCandidates[0]);\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath, ui),\n ),\n );\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n return {\n creates: catalog ? [catalog] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAMA,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgBqB,EAAiB,GAAuC;CACtE,IAAI,CAACJ,EAAG,WAAWK,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAStB;CAAe;CAOxD,IAAMuB,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBH,CAAc,GAEzDI,IAAU,IACVC,IAAS;CAMb,AAJkBJ,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAMK,EAAE,wBAAwB,MAAM,cAE1C,MACHL,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,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;EAChC;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { n as e } from "./rolldown-runtime-DArdT4gl.js";
|
|
2
|
+
import { a as t } from "./util-BLYliuUK.js";
|
|
3
|
+
import { n } from "./shared-D5GOS97l.js";
|
|
4
|
+
import { _ as r, s as i } from "./ts-morph-helpers-Bepc-Es2.js";
|
|
5
|
+
import a from "node:fs";
|
|
6
|
+
import o from "node:path";
|
|
7
|
+
//#region src/runtime/modify-file.ts
|
|
8
|
+
var s = /* @__PURE__ */ e({
|
|
9
|
+
envRevertOutcomeToFile: () => u,
|
|
10
|
+
keepMissing: () => d,
|
|
11
|
+
modifyOutcomeToFile: () => c,
|
|
12
|
+
revertOutcomeToFile: () => l
|
|
13
|
+
});
|
|
14
|
+
function c(e, n) {
|
|
15
|
+
let r = t(e);
|
|
16
|
+
return n.status === "success" ? n.changed ? {
|
|
17
|
+
path: e,
|
|
18
|
+
language: r,
|
|
19
|
+
content: a.readFileSync(e, "utf8"),
|
|
20
|
+
status: "success"
|
|
21
|
+
} : null : {
|
|
22
|
+
path: e,
|
|
23
|
+
language: r,
|
|
24
|
+
content: n.status === "failed" && a.existsSync(e) ? a.readFileSync(e, "utf8") : "",
|
|
25
|
+
status: n.status,
|
|
26
|
+
message: n.message
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function l(e, t) {
|
|
30
|
+
return t.status === "success" && t.changed && a.existsSync(e) && r(a.readFileSync(e, "utf8"), i).result ? {
|
|
31
|
+
modify: null,
|
|
32
|
+
delete: n(e)
|
|
33
|
+
} : {
|
|
34
|
+
modify: c(e, t),
|
|
35
|
+
delete: null
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function u(e, t) {
|
|
39
|
+
return t.status === "success" && t.changed && a.existsSync(e) && a.readFileSync(e, "utf8").trim() === "" ? {
|
|
40
|
+
modify: null,
|
|
41
|
+
delete: n(e)
|
|
42
|
+
} : {
|
|
43
|
+
modify: c(e, t),
|
|
44
|
+
delete: null
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function d(e, t) {
|
|
48
|
+
return e.filter((e) => !a.existsSync(o.join(t, e.path)));
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { l as a, s as i, d as n, c as r, u as t };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=modify-file-Bbhyfiy_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modify-file-Bbhyfiy_.js","names":["__exportAll","languageFromPath","withInMemoryScript","isEffectivelyEmpty","fs","path","modify_file_exports","envRevertOutcomeToFile","keepMissing","modifyOutcomeToFile","revertOutcomeToFile","language","filePath","outcome","toDeleteEntry","envPath","creates","root","file"],"sources":["../../src/runtime/modify-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, ModifyOutcome } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { toDeleteEntry } from \"../patterns/destroy/shared\";\nimport { isEffectivelyEmpty, withInMemoryScript } from \"./ts-morph-helpers\";\n\nexport function modifyOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): File | null {\n const language = languageFromPath(filePath);\n\n if (outcome.status === \"success\") {\n if (!outcome.changed) return null;\n return {\n path: filePath,\n language,\n content: fs.readFileSync(filePath, \"utf8\"),\n status: \"success\",\n };\n }\n\n const content =\n outcome.status === \"failed\" && fs.existsSync(filePath)\n ? fs.readFileSync(filePath, \"utf8\")\n : \"\";\n\n return {\n path: filePath,\n language,\n content,\n status: outcome.status,\n message: outcome.message,\n };\n}\n\n/**\n * `modifyOutcomeToFile` for a revert that may have taken out everything the\n * file held: a script left with no statements, only comments and whitespace,\n * is reported as a delete. For hooks files a pattern created, or that ended\n * up holding nothing but what patterns put there.\n */\nexport function revertOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(filePath) &&\n withInMemoryScript(fs.readFileSync(filePath, \"utf8\"), isEffectivelyEmpty)\n .result\n ) {\n return { modify: null, delete: toDeleteEntry(filePath) };\n }\n return { modify: modifyOutcomeToFile(filePath, outcome), delete: null };\n}\n\n/**\n * `modifyOutcomeToFile` for a `.env` revert: a file the revert left empty is\n * reported as a delete. The enable pattern most likely created it, and an\n * empty `.env` holds nothing worth keeping.\n */\nexport function envRevertOutcomeToFile(\n envPath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(envPath) &&\n fs.readFileSync(envPath, \"utf8\").trim() === \"\"\n ) {\n return { modify: null, delete: toDeleteEntry(envPath) };\n }\n return { modify: modifyOutcomeToFile(envPath, outcome), delete: null };\n}\n\n/**\n * Drop any create that already exists on disk.\n *\n * `writeResult` overwrites an existing create whose content differs and\n * reports it as a modify, which would mean a re-run silently resetting a\n * developer's edits, or a create clobbering a file other patterns have\n * already written to. The file is theirs once it exists; a pattern that has\n * something to add to it does so with a modifier.\n */\nexport function keepMissing(creates: File[], root: string): File[] {\n return creates.filter((file) => !fs.existsSync(path.join(root, file.path)));\n}\n"],"mappings":";;;;;;;;;;;;;AAOA,SAAgBS,EACd,GACA,GACa;CACb,IAAME,IAAWV,EAAiBW,CAAQ;CAiB1C,OAfIC,EAAQ,WAAW,YAChBA,EAAQ,UACN;EACL,MAAMD;EACN;EACA,SAASR,EAAG,aAAaQ,GAAU,MAAM;EACzC,QAAQ;CACV,IAN6B,OAcxB;EACL,MAAMA;EACN;EACA,SAPAC,EAAQ,WAAW,YAAYT,EAAG,WAAWQ,CAAQ,IACjDR,EAAG,aAAaQ,GAAU,MAAM,IAChC;EAMJ,QAAQC,EAAQ;EAChB,SAASA,EAAQ;CACnB;AACF;AAQA,SAAgBH,EACd,GACA,GAC8C;CAU9C,OAREG,EAAQ,WAAW,aACnBA,EAAQ,WACRT,EAAG,WAAWQ,CAAQ,KACtBV,EAAmBE,EAAG,aAAaQ,GAAU,MAAM,GAAGT,CAAkB,CAAC,CACtE,SAEI;EAAE,QAAQ;EAAM,QAAQW,EAAcF,CAAQ;CAAE,IAElD;EAAE,QAAQH,EAAoBG,GAAUC,CAAO;EAAG,QAAQ;CAAK;AACxE;AAOA,SAAgBN,EACd,GACA,GAC8C;CAS9C,OAPEM,EAAQ,WAAW,aACnBA,EAAQ,WACRT,EAAG,WAAWW,CAAO,KACrBX,EAAG,aAAaW,GAAS,MAAM,CAAC,CAAC,KAAK,MAAM,KAErC;EAAE,QAAQ;EAAM,QAAQD,EAAcC,CAAO;CAAE,IAEjD;EAAE,QAAQN,EAAoBM,GAASF,CAAO;EAAG,QAAQ;CAAK;AACvE;AAWA,SAAgBL,EAAY,GAAiB,GAAsB;CACjE,OAAOQ,EAAQ,QAAQ,MAAS,CAACZ,EAAG,WAAWC,EAAK,KAAKY,GAAMC,EAAK,IAAI,CAAC,CAAC;AAC5E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as e } from "./ts-morph-helpers-Bepc-Es2.js";
|
|
2
|
-
import { t } from "./svelte-file-
|
|
2
|
+
import { t } from "./svelte-file-Dv5-bl79.js";
|
|
3
3
|
import n from "node:fs";
|
|
4
4
|
import { SyntaxKind as r } from "ts-morph";
|
|
5
5
|
//#region src/patterns/enable/subscriptions/modifies/modify-nav-user.ts
|
|
@@ -68,4 +68,4 @@ function f(r) {
|
|
|
68
68
|
//#endregion
|
|
69
69
|
export { f as n, l as r, u as t };
|
|
70
70
|
|
|
71
|
-
//# sourceMappingURL=modify-nav-user-
|
|
71
|
+
//# sourceMappingURL=modify-nav-user-B8h8WTrM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-nav-user-
|
|
1
|
+
{"version":3,"file":"modify-nav-user-B8h8WTrM.js","names":["withInMemoryScript","fs","NOT_FOUND_HINT","FAILURE_HINT","SUBSCRIPTION_TYPE","PLAN_LABEL","PLAN_LINES","propsStatement","sf","s","d","SyntaxKind","bindingText","current","texts","indent","close","t","addSubscriptionProp","statement","decl","binding","type","rest","writer","modifyNavUser","filePath","original","file","SvelteFile","added","content","source","markupStart","names","out","i","match","end"],"sources":["../../src/patterns/enable/subscriptions/modifies/modify-nav-user.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind, type SourceFile, type VariableStatement } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\n\nconst NOT_FOUND_HINT = [\n \"src/lib/components/nav-user.svelte is missing.\",\n \"Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user.\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Could not find the props and the name lines in nav-user.svelte. Show the plan by hand:\",\n \"\",\n \"let { user, subscription = null }: { ...; subscription?: { id: string; productName: string | null } | null } = $props();\",\n \"const planLabel = $derived(subscription?.productName ?? 'Free');\",\n \"\",\n \"<!-- Under the name, in the trigger and in the dropdown label: -->\",\n '<span class=\"truncate text-xs text-muted-foreground\">{planLabel}</span>',\n].join(\"\\n\");\n\nconst SUBSCRIPTION_TYPE = \"{ id: string; productName: string | null } | null\";\nconst PLAN_LABEL =\n \"const planLabel = $derived(subscription?.productName ?? 'Free');\";\n\n/** The line under the name: muted in the trigger, plain in the dropdown label. */\nconst PLAN_LINES = [\n '<span class=\"truncate text-xs text-muted-foreground\">{planLabel}</span>',\n '<span class=\"truncate text-xs\">{planLabel}</span>',\n];\n\n/** `let { ... }: { ... } = $props();` */\nexport function propsStatement(sf: SourceFile): VariableStatement | undefined {\n return sf\n .getVariableStatements()\n .find((s) =>\n s\n .getDeclarations()\n .some(\n (d) =>\n d.getInitializer()?.getText() === \"$props()\" &&\n d.getNameNode().getKind() === SyntaxKind.ObjectBindingPattern,\n ),\n );\n}\n\n/** `{ a, b }` with `texts` as its elements, one per line if it was. */\nexport function bindingText(current: string, texts: string[]): string {\n if (!current.includes(\"\\n\")) return `{ ${texts.join(\", \")} }`;\n const indent = current.match(/\\n([ \\t]+)\\S/)?.[1] ?? \"\\t\";\n const close = current.match(/\\n([ \\t]*)\\}$/)?.[1] ?? \"\";\n return `{\\n${texts.map((t) => indent + t).join(\",\\n\")}\\n${close}}`;\n}\n\nfunction addSubscriptionProp(sf: SourceFile): boolean {\n const statement = propsStatement(sf);\n const decl = statement?.getDeclarations()[0];\n const binding = decl?.getNameNode().asKind(SyntaxKind.ObjectBindingPattern);\n const type = decl?.getTypeNode()?.asKind(SyntaxKind.TypeLiteral);\n if (!statement || !decl || !binding || !type) return false;\n\n if (!binding.getElements().some((e) => e.getName() === \"subscription\")) {\n const texts = binding.getElements().map((e) => e.getText());\n const rest = binding.getElements().findIndex((e) => e.getDotDotDotToken());\n texts.splice(rest === -1 ? texts.length : rest, 0, \"subscription = null\");\n binding.replaceWithText(bindingText(binding.getText(), texts));\n }\n if (!type.getProperty(\"subscription\")) {\n type.addProperty({\n name: \"subscription\",\n hasQuestionToken: true,\n type: SUBSCRIPTION_TYPE,\n });\n }\n sf.insertStatements(sf.getStatements().indexOf(statement) + 1, (writer) =>\n writer.blankLine().write(PLAN_LABEL),\n );\n return true;\n}\n\n/**\n * Shows the user's plan under their name in nav-user: a `subscription` prop\n * (the (app) layout passes it), `planLabel` from it, and a line under each\n * name. Edits the file rather than replacing it, so the items other patterns\n * added to the menu (teams, API keys) stay.\n */\nexport function modifyNavUser(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (original.includes(\"planLabel\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n let added = false;\n file.modifyScript(\n (content) =>\n withInMemoryScript(content, (sf) => {\n added = addSubscriptionProp(sf);\n }).source,\n );\n if (!added) return { status: \"failed\", message: FAILURE_HINT };\n\n // The name lines, in the markup after the script.\n const source = file.toString();\n const markupStart = source.indexOf(\"</script>\");\n const names = [\n ...source\n .slice(markupStart)\n .matchAll(\n /^([ \\t]*)<span class=\"truncate font-medium\">[\\s\\S]*?<\\/span>/gm,\n ),\n ];\n if (names.length < 2) return { status: \"failed\", message: FAILURE_HINT };\n\n let out = source;\n // From the last, so the earlier offsets stay put.\n for (const [i, match] of [...names.slice(0, 2).entries()].reverse()) {\n const end = markupStart + match.index! + match[0].length;\n out = `${out.slice(0, end)}\\n${match[1]}${PLAN_LINES[i]}${out.slice(end)}`;\n }\n\n fs.writeFileSync(filePath, out, \"utf8\");\n return { status: \"success\", changed: true };\n}\n"],"mappings":";;;;;AAMA,IAAME,IAAiB,CACrB,kDACA,oGACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAoB,qDACpBC,IACJ,oEAGIC,IAAa,CACjB,6EACA,qDACF;AAGA,SAAgBC,EAAe,GAA+C;CAC5E,OAAOC,EACJ,sBAAsB,CAAC,CACvB,MAAM,MACLC,EACG,gBAAgB,CAAC,CACjB,MACE,MACCC,EAAE,eAAe,CAAC,EAAE,QAAQ,MAAM,cAClCA,EAAE,YAAY,CAAC,CAAC,QAAQ,MAAMC,EAAW,oBAC7C,CACJ;AACJ;AAGA,SAAgBC,EAAY,GAAiB,GAAyB;CACpE,IAAI,CAACC,EAAQ,SAAS,IAAI,GAAG,OAAO,KAAKC,EAAM,KAAK,IAAI,EAAE;CAC1D,IAAMC,IAASF,EAAQ,MAAM,cAAc,CAAC,GAAG,MAAM,KAC/CG,IAAQH,EAAQ,MAAM,eAAe,CAAC,GAAG,MAAM;CACrD,OAAO,MAAMC,EAAM,KAAK,MAAMC,IAASE,CAAC,C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Q,GAChCG,IAAQ;CAOZ,IANAF,EAAK,cACF,MACC5B,EAAmB+B,IAAU,MAAO;EAClC,IAAQb,EAAoBV,CAAE;CAChC,CAAC,CAAC,CAAC,MACP,GACI,CAACsB,GAAO,OAAO;EAAE,QAAQ;EAAU,SAAS3B;CAAa;CAG7D,IAAM6B,IAASJ,EAAK,SAAS,GACvBK,IAAcD,EAAO,QAAQ,YAAW,GACxCE,IAAQ,CACZ,GAAGF,EACA,MAAMC,CAAW,CAAC,CAClB,SACC,gEACF,CACJ;CACA,IAAIC,EAAM,SAAS,GAAG,OAAO;EAAE,QAAQ;EAAU,SAAS/B;CAAa;CAEvE,IAAIgC,IAAMH;CAEV,KAAK,IAAM,CAACI,GAAGC,MAAU,CAAC,GAAGH,EAAM,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG;EACnE,IAAMI,IAAML,IAAcI,EAAM,QAASA,EAAM,EAAE,CAAC;EAClD,IAAM,GAAGF,EAAI,MAAM,GAAGG,CAAG,EAAE,IAAID,EAAM,KAAK/B,EAAW8B,KAAKD,EAAI,MAAMG,CAAG;CACzE;CAGA,OADArC,EAAG,cAAcyB,GAAUS,GAAK,MAAM,GAC/B;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { t as e } from "./errors-DR3gF_7a.js";
|
|
2
|
+
import { i as t } from "./util-BLYliuUK.js";
|
|
3
|
+
//#region src/core/providers.ts
|
|
4
|
+
function n(e) {
|
|
5
|
+
return e.replace(/^enable-/, "");
|
|
6
|
+
}
|
|
7
|
+
function r(e) {
|
|
8
|
+
for (let t = 0; t < e.length; t++) {
|
|
9
|
+
let n = e[t];
|
|
10
|
+
if (n === "--provider") return e[t + 1];
|
|
11
|
+
if (n.startsWith("--provider=")) return n.slice(11);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function i(e, t, n) {
|
|
15
|
+
return [
|
|
16
|
+
`Unknown provider "${t}" for ${e}.`,
|
|
17
|
+
"",
|
|
18
|
+
"Available providers:",
|
|
19
|
+
...n.map((e) => ` ${e.id}`)
|
|
20
|
+
].join("\n");
|
|
21
|
+
}
|
|
22
|
+
function a(e) {
|
|
23
|
+
return `--provider <${e.map((e) => e.id).join("|")}>`;
|
|
24
|
+
}
|
|
25
|
+
function o(e) {
|
|
26
|
+
if (e.markers) return e.markers;
|
|
27
|
+
let t = e.env?.[0];
|
|
28
|
+
return t ? [{ env: t.key }] : [];
|
|
29
|
+
}
|
|
30
|
+
function s(t, o) {
|
|
31
|
+
let s = t.providers ?? [], l = n(t.slug);
|
|
32
|
+
if (s.length === 0) throw Error(`${t.slug} declares no providers.`);
|
|
33
|
+
let u = typeof o.input.provider == "string" ? o.input.provider : r(o.argv);
|
|
34
|
+
if (t.inheritsProvider) return c(t.inheritsProvider, l, s, u, o);
|
|
35
|
+
if (u === void 0 || u === "") {
|
|
36
|
+
if (o.env === "preview") return s[0];
|
|
37
|
+
throw new e(`Choose a provider for ${l}: ${a(s)}`);
|
|
38
|
+
}
|
|
39
|
+
let d = s.find((e) => e.id === u);
|
|
40
|
+
if (!d) throw new e(i(l, u, s));
|
|
41
|
+
return d;
|
|
42
|
+
}
|
|
43
|
+
function c(t, n, r, a, o) {
|
|
44
|
+
let s = o.providers?.[t];
|
|
45
|
+
if (s === void 0) {
|
|
46
|
+
if (o.env === "preview") {
|
|
47
|
+
if (a === void 0 || a === "") return r[0];
|
|
48
|
+
let t = r.find((e) => e.id === a);
|
|
49
|
+
if (t) return t;
|
|
50
|
+
throw new e(i(n, a, r));
|
|
51
|
+
}
|
|
52
|
+
throw new e(`${n} is built on ${t}, and this project has none. Run \`vela enable ${t}\` first.`);
|
|
53
|
+
}
|
|
54
|
+
let c = r.find((e) => e.id === s);
|
|
55
|
+
if (!c) throw new e(`${n} does not support "${s}" ${t} yet. Supported: ${r.map((e) => e.id).join(", ")}.`);
|
|
56
|
+
if (a !== void 0 && a !== "" && a !== s) throw new e(`This project uses ${c.label} ${t}, and ${n} follows it. Leave out --provider, or pass --provider ${s}.`);
|
|
57
|
+
return c;
|
|
58
|
+
}
|
|
59
|
+
function l(e, t, n = {}) {
|
|
60
|
+
return [{
|
|
61
|
+
type: "comment",
|
|
62
|
+
key: t
|
|
63
|
+
}, ...(e.env ?? []).map((e) => ({
|
|
64
|
+
type: "var",
|
|
65
|
+
key: e.key,
|
|
66
|
+
value: n[e.key]?.trim() || e.default || ""
|
|
67
|
+
}))];
|
|
68
|
+
}
|
|
69
|
+
function u(e) {
|
|
70
|
+
return (e.env ?? []).map((e) => ({
|
|
71
|
+
name: e.key,
|
|
72
|
+
...e.public ? { public: !0 } : {},
|
|
73
|
+
description: e.description ?? e.label
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
function d(e) {
|
|
77
|
+
let t = e.input.providerEnv;
|
|
78
|
+
if (!t || typeof t != "object") return {};
|
|
79
|
+
let n = {};
|
|
80
|
+
for (let [e, r] of Object.entries(t)) typeof r == "string" && (n[e] = r);
|
|
81
|
+
return n;
|
|
82
|
+
}
|
|
83
|
+
function f(e, t) {
|
|
84
|
+
let n = /* @__PURE__ */ new Set();
|
|
85
|
+
for (let r of Object.keys(e)) {
|
|
86
|
+
let e = r.match(/\/providers(?:-[^/]+)?\/([^/]+)\/(.+)$/);
|
|
87
|
+
e && (t === void 0 || e[1] === t) && n.add(e[2]);
|
|
88
|
+
}
|
|
89
|
+
return [...n].sort();
|
|
90
|
+
}
|
|
91
|
+
function p(e, n, r = "./providers/") {
|
|
92
|
+
let i = t(e, `${r}${n}/`);
|
|
93
|
+
return Object.values(i).sort((e, t) => e.path.localeCompare(t.path));
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { u as a, s as c, l as i, d as l, n, r as o, p as r, o as s, f as t, i as u };
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=providers-CL9kQ4hp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers-CL9kQ4hp.js","names":["InvalidArgumentError","filesUnderPrefix","capabilityName","slug","providerFromArgv","i","argv","arg","unknownProviderMessage","raw","name","providers","provider","providerChoices","providerMarkers","first","resolveProvider","pattern","options","resolveInheritedProvider","candidate","detectedId","capability","detected","providerEnvEdits","heading","variable","supplied","providerEnvVars","suppliedProviderEnv","values","key","value","allProviderPaths","paths","providersRaw","match","id","providerCreates","files","root","a","b"],"sources":["../../src/core/providers.ts"],"sourcesContent":["import type { EnvEdit } from \"../runtime/env\";\nimport type { EnvVarSpec } from \"../runtime/env-vars-file\";\nimport { InvalidArgumentError } from \"./errors\";\nimport type { File, Options, Pattern, Provider, ProviderMarker } from \"./types\";\nimport { filesUnderPrefix } from \"./util\";\n\ntype ProviderPattern = Pick<Pattern, \"slug\" | \"providers\" | \"inheritsProvider\">;\n\n/** `analytics` for `enable-analytics`: how the capability is named to users. */\nexport function capabilityName(slug: string): string {\n return slug.replace(/^enable-/, \"\");\n}\n\n/** `--provider <id>` or `--provider=<id>`, for callers that hand flags through in argv. */\nexport function providerFromArgv(argv: string[]): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--provider\") return argv[i + 1];\n if (arg.startsWith(\"--provider=\")) return arg.slice(\"--provider=\".length);\n }\n return undefined;\n}\n\nexport function unknownProviderMessage(\n name: string,\n raw: string,\n providers: Provider[],\n): string {\n return [\n `Unknown provider \"${raw}\" for ${name}.`,\n \"\",\n \"Available providers:\",\n ...providers.map((provider) => ` ${provider.id}`),\n ].join(\"\\n\");\n}\n\nexport function providerChoices(providers: Provider[]): string {\n return `--provider <${providers.map((provider) => provider.id).join(\"|\")}>`;\n}\n\n/**\n * What `detectProviders` looks for: the declared markers, else the first env\n * key's declaration in `src/env.ts`. Empty for a provider with neither, which\n * can't be detected.\n */\nexport function providerMarkers(provider: Provider): ProviderMarker[] {\n if (provider.markers) return provider.markers;\n const first = provider.env?.[0];\n return first ? [{ env: first.key }] : [];\n}\n\n/**\n * The provider a generate call should produce, from `input.provider` or\n * `--provider` in argv.\n *\n * An unknown id is rejected with the list of known ones. With no provider at\n * all, a runtime call is rejected too: the CLI always supplies one, so this\n * is a caller bug. A preview call falls back to the first declared provider,\n * because the website loads patterns with argv only.\n *\n * A pattern with `inheritsProvider` takes the provider detected for that\n * capability instead; see `resolveInheritedProvider`.\n */\nexport function resolveProvider(\n pattern: ProviderPattern,\n options: Pick<Options, \"input\" | \"argv\" | \"env\" | \"providers\">,\n): Provider {\n const providers = pattern.providers ?? [];\n const name = capabilityName(pattern.slug);\n if (providers.length === 0) {\n throw new Error(`${pattern.slug} declares no providers.`);\n }\n\n const raw =\n typeof options.input.provider === \"string\"\n ? options.input.provider\n : providerFromArgv(options.argv);\n\n if (pattern.inheritsProvider) {\n return resolveInheritedProvider(\n pattern.inheritsProvider,\n name,\n providers,\n raw,\n options,\n );\n }\n\n if (raw === undefined || raw === \"\") {\n if (options.env === \"preview\") return providers[0];\n throw new InvalidArgumentError(\n `Choose a provider for ${name}: ${providerChoices(providers)}`,\n );\n }\n\n const provider = providers.find((candidate) => candidate.id === raw);\n if (!provider) {\n throw new InvalidArgumentError(\n unknownProviderMessage(name, raw, providers),\n );\n }\n return provider;\n}\n\n/**\n * A pattern built on another capability uses that capability's provider:\n * enable-ecommerce on a project with Shopify payments generates the Shopify\n * cart. A `--provider` that repeats the detected one is accepted; a different\n * one is an error, because switching means disabling the capability first.\n *\n * In preview nothing is detected, so it falls back like `resolveProvider`.\n */\nfunction resolveInheritedProvider(\n capability: string,\n name: string,\n providers: Provider[],\n raw: string | undefined,\n options: Pick<Options, \"env\" | \"providers\">,\n): Provider {\n const detectedId = options.providers?.[capability];\n\n if (detectedId === undefined) {\n if (options.env === \"preview\") {\n if (raw === undefined || raw === \"\") return providers[0];\n const provider = providers.find((candidate) => candidate.id === raw);\n if (provider) return provider;\n throw new InvalidArgumentError(\n unknownProviderMessage(name, raw, providers),\n );\n }\n throw new InvalidArgumentError(\n `${name} is built on ${capability}, and this project has none. ` +\n `Run \\`vela enable ${capability}\\` first.`,\n );\n }\n\n const detected = providers.find((candidate) => candidate.id === detectedId);\n if (!detected) {\n throw new InvalidArgumentError(\n `${name} does not support \"${detectedId}\" ${capability} yet. ` +\n `Supported: ${providers.map((provider) => provider.id).join(\", \")}.`,\n );\n }\n\n if (raw !== undefined && raw !== \"\" && raw !== detectedId) {\n throw new InvalidArgumentError(\n `This project uses ${detected.label} ${capability}, and ${name} follows it. ` +\n `Leave out --provider, or pass --provider ${detectedId}.`,\n );\n }\n\n return detected;\n}\n\n/**\n * The `.env` lines for a provider: `# heading`, then one `KEY=value` per\n * declared env var. `supplied` holds what the CLI collected; a blank value\n * falls back to the provider's default, else an empty assignment the\n * developer fills in later. Prompt placeholders are never written.\n */\nexport function providerEnvEdits(\n provider: Provider,\n heading: string,\n supplied: Record<string, string> = {},\n): EnvEdit[] {\n return [\n { type: \"comment\", key: heading },\n ...(provider.env ?? []).map((variable): EnvEdit => ({\n type: \"var\",\n key: variable.key,\n value: supplied[variable.key]?.trim() || variable.default || \"\",\n })),\n ];\n}\n\n/**\n * The `src/env.ts` declarations for a provider's env vars: optional, so an\n * empty `.env` still builds, and public only where the provider says so.\n */\nexport function providerEnvVars(provider: Provider): EnvVarSpec[] {\n return (provider.env ?? []).map((variable) => ({\n name: variable.key,\n ...(variable.public ? { public: true } : {}),\n description: variable.description ?? variable.label,\n }));\n}\n\n/** The string values of `input.providerEnv`, as the CLI collected them. */\nexport function suppliedProviderEnv(\n options: Pick<Options, \"input\">,\n): Record<string, string> {\n const raw = options.input.providerEnv;\n if (!raw || typeof raw !== \"object\") return {};\n const values: Record<string, string> = {};\n for (const [key, value] of Object.entries(raw)) {\n if (typeof value === \"string\") values[key] = value;\n }\n return values;\n}\n\n/**\n * Every app-relative path the providers create, sorted, for a disable pattern\n * that removes the files whichever provider was chosen. Works on a glob taken\n * from anywhere (`../../enable/<x>/providers/**`): only the part after\n * `providers/<id>/` (or `providers-<variant>/<id>/`) counts. `id` limits it to\n * one provider's files.\n */\nexport function allProviderPaths(\n providersRaw: Record<string, string>,\n id?: string,\n): string[] {\n const paths = new Set<string>();\n for (const key of Object.keys(providersRaw)) {\n const match = key.match(/\\/providers(?:-[^/]+)?\\/([^/]+)\\/(.+)$/);\n if (match && (id === undefined || match[1] === id)) paths.add(match[2]);\n }\n return [...paths].sort();\n}\n\n/**\n * The files under `providers/<id>/**` of a pattern, as creates. The glob map\n * is one `import.meta.glob(\"./providers/**\")` covering every provider. `root`\n * names a sibling tree for a variant of the provider's files, such as\n * `./providers-app-mode/`.\n */\nexport function providerCreates(\n providersRaw: Record<string, string>,\n id: string,\n root = \"./providers/\",\n): File[] {\n const files = filesUnderPrefix(providersRaw, `${root}${id}/`);\n return Object.values(files).sort((a, b) => a.path.localeCompare(b.path));\n}\n"],"mappings":";;;AASA,SAAgBE,EAAe,GAAsB;CACnD,OAAOC,EAAK,QAAQ,YAAY,EAAE;AACpC;AAGA,SAAgBC,EAAiB,GAAoC;CACnE,KAAK,IAAIC,IAAI,GAAGA,IAAIC,EAAK,QAAQ,KAAK;EACpC,IAAMC,IAAMD,EAAKD;EACjB,IAAIE,MAAQ,cAAc,OAAOD,EAAKD,IAAI;EAC1C,IAAIE,EAAI,WAAW,aAAa,GAAG,OAAOA,EAAI,MAAM,EAAoB;CAC1E;AAEF;AAEA,SAAgBC,EACd,GACA,GACA,GACQ;CACR,OAAO;EACL,qBAAqBC,EAAI,QAAQC,EAAK;EACtC;EACA;EACA,GAAGC,EAAU,KAAK,MAAa,KAAKC,EAAS,IAAI;CACnD,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAgBC,EAAgB,GAA+B;CAC7D,OAAO,eAAeF,EAAU,KAAK,MAAaC,EAAS,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE;AAC3E;AAOA,SAAgBE,EAAgB,GAAsC;CACpE,IAAIF,EAAS,SAAS,OAAOA,EAAS;CACtC,IAAMG,IAAQH,EA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,EAAI,MAAM,wCAAwC;EAChE,AAAIK,MAAUC,MAAO,KAAA,KAAaD,EAAM,OAAOC,MAAKH,EAAM,IAAIE,EAAM,EAAE;CACxE;CACA,OAAO,CAAC,GAAGF,CAAK,CAAC,CAAC,KAAK;AACzB;AAQA,SAAgBI,EACd,GACA,GACA,IAAO,gBACC;CACR,IAAMC,IAAQtC,EAAiBkC,GAAc,GAAGK,IAAOH,EAAG,EAAE;CAC5D,OAAO,OAAO,OAAOE,CAAK,CAAC,CAAC,MAAM,GAAG,MAAME,EAAE,KAAK,cAAcC,EAAE,IAAI,CAAC;AACzE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { n as e, s as t } from "./providers-CL9kQ4hp.js";
|
|
2
|
+
import { readEnvVarNames as n } from "./env-vars-Bj41Nccm.js";
|
|
3
|
+
import r from "node:fs";
|
|
4
|
+
import i from "node:path";
|
|
5
|
+
//#region src/runtime/providers.ts
|
|
6
|
+
function a(n, r) {
|
|
7
|
+
let i = {
|
|
8
|
+
providers: {},
|
|
9
|
+
ambiguous: []
|
|
10
|
+
}, a = o(n);
|
|
11
|
+
for (let n of r) {
|
|
12
|
+
if (!n.providers?.length || n.inheritsProvider) continue;
|
|
13
|
+
let r = n.providers.filter((e) => t(e).some(a)).map((e) => e.id), o = e(n.slug);
|
|
14
|
+
r.length === 1 && (i.providers[o] = r[0]), r.length > 1 && i.ambiguous.push({
|
|
15
|
+
capability: o,
|
|
16
|
+
ids: r
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
function o(e) {
|
|
22
|
+
let t, a;
|
|
23
|
+
return (o) => "env" in o ? (t ??= n(e), t.has(o.env)) : "path" in o ? r.existsSync(i.join(e, o.path)) : (a ??= s(e), a.has(o.dependency));
|
|
24
|
+
}
|
|
25
|
+
function s(e) {
|
|
26
|
+
let t = i.join(e, "package.json");
|
|
27
|
+
if (!r.existsSync(t)) return /* @__PURE__ */ new Set();
|
|
28
|
+
try {
|
|
29
|
+
let e = JSON.parse(r.readFileSync(t, "utf8"));
|
|
30
|
+
return /* @__PURE__ */ new Set([...Object.keys(e.dependencies ?? {}), ...Object.keys(e.devDependencies ?? {})]);
|
|
31
|
+
} catch {
|
|
32
|
+
return /* @__PURE__ */ new Set();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { a as detectProviders };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=providers-DwbwccSW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers-DwbwccSW.js","names":["capabilityName","providerMarkers","fs","path","detectProviders","detected","present","markerProbe","root","pattern","patterns","ids","provider","capability","envNames","dependencies","marker","readEnvVarNames","readDependencies","file","pkg"],"sources":["../../src/runtime/providers.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { capabilityName, providerMarkers } from \"../core/providers\";\nimport type { DetectedProviders, Pattern, ProviderMarker } from \"../core/types\";\nimport { readEnvVarNames } from \"./env-vars\";\n\ntype DetectablePattern = Pick<\n Pattern,\n \"slug\" | \"providers\" | \"inheritsProvider\"\n>;\n\n/**\n * The provider in use for each capability, read from what the providers left\n * in the project. Nothing records the choice, so this is the only way to know\n * it. A pattern that inherits its provider is skipped: its files say nothing\n * the capability it is built on doesn't already.\n *\n * The registry is passed in rather than imported, so this module and the\n * package entry don't import each other.\n */\nexport function detectProviders(\n root: string,\n patterns: readonly DetectablePattern[],\n): DetectedProviders {\n const detected: DetectedProviders = { providers: {}, ambiguous: [] };\n const present = markerProbe(root);\n\n for (const pattern of patterns) {\n if (!pattern.providers?.length || pattern.inheritsProvider) continue;\n const ids = pattern.providers\n .filter((provider) => providerMarkers(provider).some(present))\n .map((provider) => provider.id);\n\n const capability = capabilityName(pattern.slug);\n if (ids.length === 1) detected.providers[capability] = ids[0];\n if (ids.length > 1) detected.ambiguous.push({ capability, ids });\n }\n\n return detected;\n}\n\n/** Checks one marker against the project; `src/env.ts` and `package.json` are read once. */\nfunction markerProbe(root: string): (marker: ProviderMarker) => boolean {\n let envNames: Set<string> | undefined;\n let dependencies: Set<string> | undefined;\n\n return (marker) => {\n if (\"env\" in marker) {\n envNames ??= readEnvVarNames(root);\n return envNames.has(marker.env);\n }\n if (\"path\" in marker) {\n return fs.existsSync(path.join(root, marker.path));\n }\n dependencies ??= readDependencies(root);\n return dependencies.has(marker.dependency);\n };\n}\n\nfunction readDependencies(root: string): Set<string> {\n const file = path.join(root, \"package.json\");\n if (!fs.existsSync(file)) return new Set();\n try {\n const pkg = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return new Set([\n ...Object.keys(pkg.dependencies ?? {}),\n ...Object.keys(pkg.devDependencies ?? {}),\n ]);\n } catch {\n return new Set();\n }\n}\n"],"mappings":";;;;;AAoBA,SAAgBI,EACd,GACA,GACmB;CACnB,IAAMC,IAA8B;EAAE,WAAW,CAAC;EAAG,WAAW,CAAC;CAAE,GAC7DC,IAAUC,EAAYC,CAAI;CAEhC,KAAK,IAAMC,KAAWC,GAAU;EAC9B,IAAI,CAACD,EAAQ,WAAW,UAAUA,EAAQ,kBAAkB;EAC5D,IAAME,IAAMF,EAAQ,UACjB,QAAQ,MAAaR,EAAgBW,CAAQ,CAAC,CAAC,KAAKN,CAAO,CAAC,CAAC,CAC7D,KAAK,MAAaM,EAAS,EAAE,GAE1BC,IAAab,EAAeS,EAAQ,IAAI;EAE9C,AADIE,EAAI,WAAW,MAAG,EAAS,UAAUE,KAAcF,EAAI,KACvDA,EAAI,SAAS,KAAGN,EAAS,UAAU,KAAK;GAAE;GAAY;EAAI,CAAC;CACjE;CAEA,OAAOA;AACT;AAGA,SAASE,EAAY,GAAmD;CACtE,IAAIO,GACAC;CAEJ,QAAQ,MACF,SAASC,KACX,MAAaC,EAAgBT,CAAI,GAC1BM,EAAS,IAAIE,EAAO,GAAG,KAE5B,UAAUA,IACLd,EAAG,WAAWC,EAAK,KAAKK,GAAMQ,EAAO,IAAI,CAAC,KAEnD,MAAiBE,EAAiBV,CAAI,GAC/BO,EAAa,IAAIC,EAAO,UAAU;AAE7C;AAEA,SAASE,EAAiB,GAA2B;CACnD,IAAMC,IAAOhB,EAAK,KAAKK,GAAM,cAAc;CAC3C,IAAI,CAACN,EAAG,WAAWiB,CAAI,GAAG,uBAAO,IAAI,IAAI;CACzC,IAAI;EACF,IAAMC,IAAM,KAAK,MAAMlB,EAAG,aAAaiB,GAAM,MAAM,CAAC;EAIpD,uBAAO,IAAI,IAAI,CACb,GAAG,OAAO,KAAKC,EAAI,gBAAgB,CAAC,CAAC,GACrC,GAAG,OAAO,KAAKA,EAAI,mBAAmB,CAAC,CAAC,CAC1C,CAAC;CACH,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF"}
|
|
@@ -15,7 +15,7 @@ async function n(e, t) {
|
|
|
15
15
|
exists: !0,
|
|
16
16
|
rowCount: 0
|
|
17
17
|
}));
|
|
18
|
-
let { withPocketbase: n } = await import("./pocketbase-CgwbH1gI.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-
|
|
18
|
+
let { withPocketbase: n } = await import("./pocketbase-CgwbH1gI.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-Cpjo2OiQ.js").then((e) => e.n), i = [];
|
|
19
19
|
return await n(t.root, async (t) => {
|
|
20
20
|
let n = await r(t, e);
|
|
21
21
|
i.push(...n);
|
|
@@ -24,4 +24,4 @@ async function n(e, t) {
|
|
|
24
24
|
//#endregion
|
|
25
25
|
export { t as n, n as t };
|
|
26
26
|
|
|
27
|
-
//# sourceMappingURL=shared-
|
|
27
|
+
//# sourceMappingURL=shared-D5GOS97l.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-D5GOS97l.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
|
+
import { t } from "./taggedTemplateLiteral-CswN2AAa.js";
|
|
3
|
+
//#region src/patterns/enable/payments/shopify-page.ts
|
|
4
|
+
var n;
|
|
5
|
+
function r(r) {
|
|
6
|
+
return e(n ||= t(["\n <script lang=\"ts\">\n import BuyButton from '#lib/components/payments/buy-button.svelte';\n <\/script>\n\n <section data-role=\"content\">\n <BuyButton variantId=\"", "\" />\n </section>\n "]), r);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { r as t };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=shopify-page-D-VFwGxI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shopify-page-D-VFwGxI.js","names":["dedent","_templateObject","buyPageSnippet","_taggedTemplateLiteral","variantId"],"sources":["../../src/patterns/enable/payments/shopify-page.ts"],"sourcesContent":["import dedent from \"dedent\";\n\n/** The demo page: one Buy button for the variant named on the command line. */\nexport function buyPageSnippet(variantId: string): string {\n return dedent`\n <script lang=\"ts\">\n import BuyButton from '#lib/components/payments/buy-button.svelte';\n </script>\n\n <section data-role=\"content\">\n <BuyButton variantId=\"${variantId}\" />\n </section>\n `;\n}\n"],"mappings":";;;;AAGA,SAAgBE,EAAe,GAA2B;CACxD,OAAOF,EAAA,AAAAC,MAAAE,EAAA,CAAA,+LAAA,2BAAA,CAAA,GAMqBC,CAE5B;AACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/patterns/enable/payments/providers-app-mode/stripe/src/lib/server/stripe-customer.ts?raw
|
|
2
|
+
var e = "import { linkStripeCustomer } from '#lib/workflows/link-stripe-customer.js';\n\n/**\n * The user's Stripe customer id. Signup starts link-stripe-customer in the\n * background, so a user can get here before it finishes, or without it ever\n * starting (a one-time-code signup, an import). Either way this starts or\n * joins that same run (the user's id is its idempotency key, so there is still\n * one customer) and waits a little for it.\n *\n * Throws when the customer is not there in time; the caller decides whether to\n * say \"try again shortly\" or fail.\n */\nexport async function getStripeCustomerId(\n admin: App.Locals['admin'],\n user: { id: string; email?: string },\n timeoutMs = 10_000\n): Promise<string> {\n try {\n const customer = await admin\n .collection('stripe_customers')\n .getFirstListItem(admin.filter('user = {:user}', { user: user.id }));\n return customer.id;\n } catch {\n // Not linked yet.\n }\n\n const handle = await linkStripeCustomer.run(\n { userId: user.id, email: user.email || undefined },\n { idempotencyKey: user.id }\n );\n const { customerId } = await handle.result({ timeoutMs });\n return customerId;\n}\n";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as t };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=stripe-customer-B3tP8gtD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-customer-B3tP8gtD.js","names":["stripe_customer_default"],"sources":[],"mappings":""}
|