@velastack/patterns 0.4.3 → 0.6.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-B_DisSfA.js +203 -0
- package/dist/chunks/collections-B_DisSfA.js.map +1 -0
- package/dist/chunks/{constants-Rq8SCXwH.js → constants-iej3WkEa.js} +3 -3
- package/dist/chunks/constants-iej3WkEa.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-cqQU0ECK.js} +32 -20
- package/dist/chunks/env-vars-cqQU0ECK.js.map +1 -0
- package/dist/chunks/generate-8FS2ROOJ.js +170 -0
- package/dist/chunks/generate-8FS2ROOJ.js.map +1 -0
- package/dist/chunks/{generate-CFqpRi9D.js → generate-Bm_jOMtF.js} +4 -4
- package/dist/chunks/{generate-CFqpRi9D.js.map → generate-Bm_jOMtF.js.map} +1 -1
- package/dist/chunks/{generate-Bg0E3eWm.js → generate-CXoQPz7n.js} +4 -4
- package/dist/chunks/{generate-Bg0E3eWm.js.map → generate-CXoQPz7n.js.map} +1 -1
- package/dist/chunks/{generate-B6Odfk5f.js → generate-Cqwa8kD9.js} +2 -2
- package/dist/chunks/{generate-B6Odfk5f.js.map → generate-Cqwa8kD9.js.map} +1 -1
- package/dist/chunks/{generate-CZGHByV3.js → generate-D3mSFPdT.js} +7 -7
- package/dist/chunks/{generate-CZGHByV3.js.map → generate-D3mSFPdT.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-jx5Iuq5w.js +75 -0
- package/dist/chunks/generate-jx5Iuq5w.js.map +1 -0
- package/dist/chunks/{generate.runtime-Djas9UNy.js → generate.runtime-B2r11K7S.js} +4 -4
- package/dist/chunks/{generate.runtime-Djas9UNy.js.map → generate.runtime-B2r11K7S.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bcrht4M9.js → generate.runtime-B4u9C2YH.js} +9 -9
- package/dist/chunks/{generate.runtime-Bcrht4M9.js.map → generate.runtime-B4u9C2YH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DVB7uuht.js → generate.runtime-BRCzUO94.js} +3 -3
- package/dist/chunks/{generate.runtime-DVB7uuht.js.map → generate.runtime-BRCzUO94.js.map} +1 -1
- package/dist/chunks/{generate.runtime-IWEhGhWY.js → generate.runtime-BVavIXtX.js} +6 -6
- package/dist/chunks/{generate.runtime-IWEhGhWY.js.map → generate.runtime-BVavIXtX.js.map} +1 -1
- package/dist/chunks/generate.runtime-Bh9Z2cRN.js +82 -0
- package/dist/chunks/generate.runtime-Bh9Z2cRN.js.map +1 -0
- package/dist/chunks/{generate.runtime-DJHUBL4Z.js → generate.runtime-BxDUtkpT.js} +12 -12
- package/dist/chunks/{generate.runtime-DJHUBL4Z.js.map → generate.runtime-BxDUtkpT.js.map} +1 -1
- package/dist/chunks/{generate.runtime-hTKzxH2M.js → generate.runtime-BxUGDXIK.js} +7 -7
- package/dist/chunks/{generate.runtime-hTKzxH2M.js.map → generate.runtime-BxUGDXIK.js.map} +1 -1
- package/dist/chunks/{generate.runtime-5rIc-RNL.js → generate.runtime-CHb4znYx.js} +66 -66
- package/dist/chunks/{generate.runtime-5rIc-RNL.js.map → generate.runtime-CHb4znYx.js.map} +1 -1
- package/dist/chunks/{generate.runtime-E-zoeSKW.js → generate.runtime-CRhD98rs.js} +7 -7
- package/dist/chunks/{generate.runtime-E-zoeSKW.js.map → generate.runtime-CRhD98rs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BpMN5Uq-.js → generate.runtime-CWnIiXwV.js} +3 -3
- package/dist/chunks/{generate.runtime-BpMN5Uq-.js.map → generate.runtime-CWnIiXwV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-kciwaXxh.js → generate.runtime-CYBs0JgY.js} +4 -4
- package/dist/chunks/{generate.runtime-kciwaXxh.js.map → generate.runtime-CYBs0JgY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CAn1qIQ_.js → generate.runtime-CkmledBw.js} +3 -3
- package/dist/chunks/{generate.runtime-CAn1qIQ_.js.map → generate.runtime-CkmledBw.js.map} +1 -1
- package/dist/chunks/generate.runtime-CyGR8VTx.js +48 -0
- package/dist/chunks/generate.runtime-CyGR8VTx.js.map +1 -0
- package/dist/chunks/{generate.runtime-a3R4hqFy.js → generate.runtime-DCqf7nYM.js} +12 -12
- package/dist/chunks/{generate.runtime-a3R4hqFy.js.map → generate.runtime-DCqf7nYM.js.map} +1 -1
- package/dist/chunks/{generate.runtime-uLUiPgqx.js → generate.runtime-DUo-pLRr.js} +6 -6
- package/dist/chunks/{generate.runtime-uLUiPgqx.js.map → generate.runtime-DUo-pLRr.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CpMKXBkn.js → generate.runtime-DY5vQ3aZ.js} +7 -7
- package/dist/chunks/{generate.runtime-CpMKXBkn.js.map → generate.runtime-DY5vQ3aZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CEqLgLT9.js → generate.runtime-DYdkrHJ1.js} +70 -70
- package/dist/chunks/{generate.runtime-CEqLgLT9.js.map → generate.runtime-DYdkrHJ1.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DHHlYfTD.js → generate.runtime-DdcVnK8J.js} +3 -3
- package/dist/chunks/{generate.runtime-DHHlYfTD.js.map → generate.runtime-DdcVnK8J.js.map} +1 -1
- package/dist/chunks/{generate.runtime-koQxLywh.js → generate.runtime-DeniHg8L.js} +48 -48
- package/dist/chunks/{generate.runtime-koQxLywh.js.map → generate.runtime-DeniHg8L.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DoZJHtZh.js → generate.runtime-Dmob2wFf.js} +6 -6
- package/dist/chunks/{generate.runtime-DoZJHtZh.js.map → generate.runtime-Dmob2wFf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Db0HZyj3.js → generate.runtime-Du4uf98c.js} +2 -2
- package/dist/chunks/{generate.runtime-Db0HZyj3.js.map → generate.runtime-Du4uf98c.js.map} +1 -1
- package/dist/chunks/{generate.runtime-axm9wcQv.js → generate.runtime-Dug2UIhV.js} +4 -4
- package/dist/chunks/{generate.runtime-axm9wcQv.js.map → generate.runtime-Dug2UIhV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-rs1ZOIET.js → generate.runtime-FGYc365Q.js} +15 -15
- package/dist/chunks/{generate.runtime-rs1ZOIET.js.map → generate.runtime-FGYc365Q.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BK3mR0Rj.js → generate.runtime-N1KtAG8C.js} +169 -129
- package/dist/chunks/generate.runtime-N1KtAG8C.js.map +1 -0
- package/dist/chunks/{generate.runtime-CbE9RHcf.js → generate.runtime-_c7daMAw.js} +5 -5
- package/dist/chunks/generate.runtime-_c7daMAw.js.map +1 -0
- package/dist/chunks/generate.runtime-aN5QWygO.js +106 -0
- package/dist/chunks/generate.runtime-aN5QWygO.js.map +1 -0
- package/dist/chunks/{generate.runtime-CZ46nkSL.js → generate.runtime-bpH3DB0t.js} +2 -2
- package/dist/chunks/{generate.runtime-CZ46nkSL.js.map → generate.runtime-bpH3DB0t.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CqncBFNg.js → generate.runtime-gFr2Gsjz.js} +4 -4
- package/dist/chunks/{generate.runtime-CqncBFNg.js.map → generate.runtime-gFr2Gsjz.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CK10Mum5.js → generate.runtime-kpqW3dVO.js} +25 -25
- package/dist/chunks/{generate.runtime-CK10Mum5.js.map → generate.runtime-kpqW3dVO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dl6OQ7pe.js → generate.runtime-wGRE1zwZ.js} +4 -4
- package/dist/chunks/{generate.runtime-Dl6OQ7pe.js.map → generate.runtime-wGRE1zwZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-aQnBmH8D.js → generate.runtime-wziCW3ct.js} +69 -69
- package/dist/chunks/{generate.runtime-aQnBmH8D.js.map → generate.runtime-wziCW3ct.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DJ9MVVPC.js → generate.runtime-x-o4LS8d.js} +123 -110
- package/dist/chunks/generate.runtime-x-o4LS8d.js.map +1 -0
- package/dist/chunks/modify-file-289rStJ2.js +53 -0
- package/dist/chunks/modify-file-289rStJ2.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/{pocketbase-CgwbH1gI.js → pocketbase-B017Cqjq.js} +2 -2
- package/dist/chunks/{pocketbase-CgwbH1gI.js.map → pocketbase-B017Cqjq.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-CN5J5_fY.js +38 -0
- package/dist/chunks/providers-CN5J5_fY.js.map +1 -0
- package/dist/chunks/{shared-Cc_ns5-y.js → shared-BPlAVf-T.js} +2 -2
- package/dist/chunks/{shared-Cc_ns5-y.js.map → shared-BPlAVf-T.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/site-DkU1-VRq.js +108 -0
- package/dist/chunks/site-DkU1-VRq.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/{table-core-DhDqT03G.js → table-core-vXEjJDYP.js} +2 -2
- package/dist/chunks/{table-core-DhDqT03G.js.map → table-core-vXEjJDYP.js.map} +1 -1
- package/dist/chunks/{test-setup-B9fQ5L_-.js → test-setup-CAfgVlwc.js} +3 -3
- package/dist/chunks/{test-setup-B9fQ5L_-.js.map → test-setup-CAfgVlwc.js.map} +1 -1
- package/dist/chunks/{ui-CuCsupFq.js → ui-CTdsenEv.js} +3 -3
- package/dist/chunks/{ui-CuCsupFq.js.map → ui-CTdsenEv.js.map} +1 -1
- package/dist/chunks/{whatsapp-CguKGTtw.js → whatsapp-5qJ_xCV1.js} +2 -2
- package/dist/chunks/{whatsapp-CguKGTtw.js.map → whatsapp-5qJ_xCV1.js.map} +1 -1
- package/dist/chunks/{write-result-DiZsCS_y.js → write-result-0HYIr5a6.js} +4 -4
- package/dist/chunks/write-result-0HYIr5a6.js.map +1 -0
- package/dist/index.d.ts +283 -22
- package/dist/index.js +2233 -2031
- 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/constants-Rq8SCXwH.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/site-lj0CDdQ1.js +0 -55
- package/dist/chunks/site-lj0CDdQ1.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-
|
|
1
|
+
{"version":3,"file":"generate.runtime-BRCzUO94.js","names":["dedent","getLogger","WORKFLOWS_ENV_VARS","formatLikeSource","modifyOutcomeToFile","fs","path","INIT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","ensureNamedImport","existing","sourceFile","d","moduleSpecifier","typeOnly","name","ni","hasInitExport","modifyHooksServerWorkflows","hooksServerPath","Project","QuoteKind","generate","logger","options","creates","modifies","hooksFile","envVars","modifyEnvVarsFiles"],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit/hooks';\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\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 if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"#lib/server/workflows.js\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n // SvelteKit 3 exposes only declared variables; the template declares these\n // already, an older project gets whichever it is missing.\n logger.info(\"Declaring the workflow variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, WORKFLOWS_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAMA,IAAMO,IAAe,CAAM;;;GAKrBC,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;AAS7B,SAASC,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAMC,IAAWC,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAMC,EAAE,wBAAwB,MAAMC,CAAe;CAC9D,IAAI,CAACH,GAAU;EACb,EAAW,qBAAqB;GAC9B,YAAYI;GACZ,cAAc,CAACC,CAAI;GACnB;EACF,CAAC;EACD;CACF;CACA,AAAIL,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAOM,EAAG,QAAQ,MAAMD,CAAI,KAGjEL,EAAS,eACPI,KAAY,CAACJ,E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IAAMK,IAAUC,EAAmBL,EAAQ,MAAMvB,CAAkB;CAInE,OAHI2B,EAAQ,UAAQH,EAAQ,KAAKG,EAAQ,MAAM,GAC3CA,EAAQ,UAAQF,EAAS,KAAKE,EAAQ,MAAM,GAEzC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { n as t, t as n } from "./_page-
|
|
3
|
-
import { t as r } from "./shared-
|
|
2
|
+
import { n as t, t as n } from "./_page-DoPdZgZv.js";
|
|
3
|
+
import { t as r } from "./shared-BPlAVf-T.js";
|
|
4
4
|
import { _ as i, h as a, o, u as s } from "./ts-morph-helpers-Bepc-Es2.js";
|
|
5
|
-
import {
|
|
6
|
-
import { t as l } from "./svelte-file-
|
|
5
|
+
import { r as c } from "./modify-file-289rStJ2.js";
|
|
6
|
+
import { t as l } from "./svelte-file-Dv5-bl79.js";
|
|
7
7
|
import { t as u } from "./unmodify-load-Bl5vXQiL.js";
|
|
8
|
-
import { r as d, t as f } from "./modify-nav-user-
|
|
8
|
+
import { r as d, t as f } from "./modify-nav-user-B8h8WTrM.js";
|
|
9
9
|
import p from "node:fs";
|
|
10
10
|
import m from "node:path";
|
|
11
11
|
import { Project as h, QuoteKind as g, SyntaxKind as _ } from "ts-morph";
|
|
@@ -215,4 +215,4 @@ async function O(i) {
|
|
|
215
215
|
//#endregion
|
|
216
216
|
export { O as generate };
|
|
217
217
|
|
|
218
|
-
//# sourceMappingURL=generate.runtime-
|
|
218
|
+
//# sourceMappingURL=generate.runtime-BVavIXtX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-IWEhGhWY.js","names":["paymentsBillingPageServerTemplate","paymentsBillingPageSvelteTemplate","getLogger","_page_server_default","_page_default","planDropsForCollections","withInMemoryScript","removeTopLevelStatementByIdentifier","removeImportByModuleSpecifier","SvelteFile","removeFromLoad","propsStatement","bindingText","fs","path","SUBSCRIPTION_CASE_VALUES","unmodifyWebhookServer","filePath","original","sf","switchStmt","SyntaxKind","stmt","toRemove","clause","expr","literal","c","spaced","source","unmodifyAppLayoutSvelte","file","updateScript","out","decl","init","nameNode","pattern","elements","hasSub","typeNode","intersection","member","lit","propTexts","p","t","remaining","unmodifyAppSidebar","hasSubPropType","hasSubProp","hasNavUserSubAttr","unmodifyAppLayoutServer","fromLoad","Project","QuoteKind","formatLikeSource","unmodifyNavUser","content","binding","kept","revertByTemplate","current","enabledMarker","stripped","template","unmodifyBillingPageServer","paymentsBillingPageServerTemplate","unmodifyBillingPageSvelte","paymentsBillingPageSvelteTemplate","generate","logger","options","modifies","pushResult","webhookServerPath","modifyOutcomeToFile","appLayoutServerPath","appLayoutSveltePath","appSidebarPath","navUserPath","billingPageServerPath","billingPageSveltePath"],"sources":["../../src/patterns/disable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/disable/subscriptions/modifies/revert-by-template.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/disable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst SUBSCRIPTION_CASE_VALUES = new Set([\n \"customer.subscription.created\",\n \"customer.subscription.updated\",\n \"customer.subscription.deleted\",\n]);\n\nexport function unmodifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n const { source } = withInMemoryScript(original, (sf) => {\n removeImportByModuleSpecifier(sf, \"./subscription/created\");\n removeImportByModuleSpecifier(sf, \"./subscription/updated\");\n removeImportByModuleSpecifier(sf, \"./subscription/deleted\");\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n // Collect matching case clauses first — removing invalidates node refs.\n const toRemove = caseBlock\n .getClauses()\n .filter((clause) => {\n if (clause.getKind() !== SyntaxKind.CaseClause) return false;\n const caseClause = clause.asKindOrThrow(SyntaxKind.CaseClause);\n const expr = caseClause.getExpression();\n const literal =\n expr.asKind(SyntaxKind.StringLiteral) ??\n expr.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);\n if (!literal) return false;\n return SUBSCRIPTION_CASE_VALUES.has(literal.getLiteralValue());\n })\n .map((c) => c.asKindOrThrow(SyntaxKind.CaseClause));\n\n for (const clause of toRemove.reverse()) {\n clause.remove();\n }\n\n formatLikeSource(sf);\n });\n\n // Removing the clauses takes the blank line before `default:` with them.\n const spaced = source.replace(/(break;)\\n(\\s*default:)/, \"$1\\n\\n$2\");\n\n if (spaced === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, spaced, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const removed = file.removeAttribute(\"AppSidebar\", \"subscription\");\n if (!removed) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nfunction updateScript(source: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const hasSub = elements.some((e) => e.getName() === \"subscription\");\n\n // Strip subscription from the props type literal (the specific type\n // added by enable-subscriptions — leave unrelated `subscription` props\n // alone).\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"))\n .filter((t) => !/^\\s*subscription\\??\\s*:/.test(t));\n lit.replaceWithText(\n propTexts.length ? `{ ${propTexts.join(\"; \")}; }` : \"{}\",\n );\n break;\n }\n }\n\n if (hasSub) {\n const remaining = elements\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n pattern.replaceWithText(`{ ${remaining.join(\", \")} }`);\n }\n }\n formatLikeSource(sf);\n });\n return out;\n}\n\nexport function unmodifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(filePath, \"utf8\");\n const hasSubPropType = /subscription\\??\\s*:\\s*\\{/.test(source);\n const hasSubProp = /\\bsubscription\\s*=\\s*null\\b/.test(source);\n\n const file = new SvelteFile(source);\n const hasNavUserSubAttr =\n file.hasElement(\"NavUser\") && file.hasAttribute(\"NavUser\", \"subscription\");\n\n if (!hasSubPropType && !hasSubProp && !hasNavUserSubAttr) {\n return { status: \"success\", changed: false };\n }\n\n if (hasSubPropType || hasSubProp) {\n file.modifyScript(updateScript);\n }\n if (hasNavUserSubAttr) {\n file.removeAttribute(\"NavUser\", \"subscription\");\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\nimport {\n formatLikeSource,\n removeTopLevelStatementByIdentifier,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/**\n * Takes out what enable-subscriptions added to the (app) layout load: the\n * `subscription` it loads and returns, and the `loadActiveSubscription`\n * helper. The rest of the load (what other patterns added) stays.\n */\nexport function unmodifyAppLayoutServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"loadActiveSubscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const fromLoad = removeFromLoad(filePath, {\n variables: [\"subscription\"],\n dependsKeys: [],\n returnProps: [\"subscription\"],\n });\n if (fromLoad.status !== \"success\") return fromLoad;\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sf = project.addSourceFileAtPath(filePath);\n removeTopLevelStatementByIdentifier(sf, \"loadActiveSubscription\");\n formatLikeSource(sf);\n sf.saveSync();\n\n return {\n status: \"success\",\n changed: fs.readFileSync(filePath, \"utf8\") !== original,\n };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n bindingText,\n propsStatement,\n} from \"../../../enable/subscriptions/modifies/modify-nav-user\";\n\n/**\n * Takes the plan label out of nav-user: the lines showing it, `planLabel`\n * and the `subscription` prop. What other patterns added stays.\n */\nexport function unmodifyNavUser(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\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 file.modifyScript(\n (content) =>\n withInMemoryScript(\n // With the blank line enable-subscriptions put before it.\n content.replace(\n /\\n[ \\t]*\\n[ \\t]*const planLabel = \\$derived\\([^\\n]*\\);/,\n \"\",\n ),\n (sf) => {\n const decl = propsStatement(sf)?.getDeclarations()[0];\n const binding = decl\n ?.getNameNode()\n .asKind(SyntaxKind.ObjectBindingPattern);\n const kept = binding\n ?.getElements()\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n if (binding && kept) {\n binding.replaceWithText(bindingText(binding.getText(), kept));\n }\n decl\n ?.getTypeNode()\n ?.asKind(SyntaxKind.TypeLiteral)\n ?.getProperty(\"subscription\")\n ?.remove();\n },\n ).source,\n );\n\n // The lines under the name, with the line break before them.\n const out = file\n .toString()\n .replace(/\\n[ \\t]*<span class=\"[^\"]*\">\\s*\\{planLabel\\}\\s*<\\/span>/g, \"\");\n\n fs.writeFileSync(filePath, out, \"utf8\");\n return { status: \"success\", changed: out !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Rewrites a file to the given `template` if the current content still shows\n * the `enabledMarker` (meaning enable-subscriptions is applied). If the marker\n * is absent (already reverted or never applied), it's a no-op.\n *\n * Strips leading `// [!code highlight:N]` / `<!-- [!code highlight:N] -->`\n * lines so templates can be pulled from `preview-modifies/` directories which\n * use those for documentation highlighting.\n */\nexport function revertByTemplate(\n filePath: string,\n template: string,\n enabledMarker: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (!current.includes(enabledMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageServer(\n filePath: string,\n paymentsBillingPageServerTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageServerTemplate,\n \"selectPlan\",\n );\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageSvelte(\n filePath: string,\n paymentsBillingPageSvelteTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageSvelteTemplate,\n \"availablePlans\",\n );\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { unmodifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { unmodifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { unmodifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Pull the \"post-payments\" state of files that enable-subscriptions fully\n// overwrote. For the billing pages, that's exactly what enable-payments\n// writes in creates-app-mode; for nav-user it's the payments preview-modifies\n// snapshot (with highlight annotations stripped by the revert helper).\nimport paymentsBillingPageServerTemplate from \"../../enable/payments/creates-app-mode/src/routes/(app)/billing/+page.server.ts?raw\";\nimport paymentsBillingPageSvelteTemplate from \"../../enable/payments/creates-app-mode/src/routes/(app)/billing/+page.svelte?raw\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n unmodifyWebhookServer(webhookServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n unmodifyAppLayoutServer(appLayoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n unmodifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n unmodifyBillingPageServer(\n billingPageServerPath,\n paymentsBillingPageServerTemplate,\n ),\n ),\n );\n\n logger.info(\"Reverting billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n unmodifyBillingPageSvelte(\n billingPageSveltePath,\n paymentsBillingPageSvelteTemplate,\n ),\n ),\n );\n\n const collectionDrops = await planDropsForCollections(\n [\"stripe_subscriptions\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AASA,IAAMe,oBAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAgBC,EAAsB,GAAiC;CACrE,IAAI,CAACH,EAAG,WAAWI,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAMC,IAAWL,EAAG,aAAaI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CAAmB,CAC7C,CACF,GAEAP,EAAO,KAAK,8BAA8B;CAC1C,IAAMQ,IAAiBjE,EAAK,KAC1B0D,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAKA,AAJAE,EACEE,EAAoBG,GAAgB/B,EAAmB+B,CAAc,CAAC,CACxE,GAEAR,EAAO,KAAK,2BAA2B;CACvC,IAAMS,IAAclE,EAAK,KACvB0D,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAWE,EAAoBI,GAAavB,EAAgBuB,CAAW,CAAC,CAAC,GAEzET,EAAO,KAAK,mCAAmC;CAC/C,IAAMU,IAAwBnE,EAAK,KACjC0D,EAAQ,MACR,OACA,UACA,SACA,WACA,iBACF;CAWA,AAVAE,EACEE,EACEK,GACAf,EACEe,GACAjF,CACF,CACF,CACF,GAEAuE,EAAO,KAAK,gCAAgC;CAC5C,IAAMW,IAAwBpE,EAAK,KACjC0D,EAAQ,MACR,OACA,UACA,SACA,WACA,cACF;CAgBA,OAfAE,EACEE,EACEM,GACAd,EACEc,GACAjF,CACF,CACF,CACF,GAOO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BI,EAC5B,CAAC,sBAAsB,GACvBmE,CACF;CAWA;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-BVavIXtX.js","names":["paymentsBillingPageServerTemplate","paymentsBillingPageSvelteTemplate","getLogger","_page_server_default","_page_default","planDropsForCollections","withInMemoryScript","removeTopLevelStatementByIdentifier","removeImportByModuleSpecifier","modifyOutcomeToFile","SvelteFile","removeFromLoad","propsStatement","bindingText","fs","path","SUBSCRIPTION_CASE_VALUES","unmodifyWebhookServer","filePath","original","sf","switchStmt","SyntaxKind","stmt","toRemove","clause","expr","literal","c","spaced","source","unmodifyAppLayoutSvelte","file","updateScript","out","decl","init","nameNode","pattern","elements","hasSub","typeNode","intersection","member","lit","propTexts","p","t","remaining","unmodifyAppSidebar","hasSubPropType","hasSubProp","hasNavUserSubAttr","unmodifyAppLayoutServer","fromLoad","Project","QuoteKind","formatLikeSource","unmodifyNavUser","content","binding","kept","revertByTemplate","current","enabledMarker","stripped","template","unmodifyBillingPageServer","paymentsBillingPageServerTemplate","unmodifyBillingPageSvelte","paymentsBillingPageSvelteTemplate","generate","logger","options","modifies","pushResult","webhookServerPath","appLayoutServerPath","appLayoutSveltePath","appSidebarPath","navUserPath","billingPageServerPath","billingPageSveltePath"],"sources":["../../src/patterns/disable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/disable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/disable/subscriptions/modifies/revert-by-template.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/disable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/disable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst SUBSCRIPTION_CASE_VALUES = new Set([\n \"customer.subscription.created\",\n \"customer.subscription.updated\",\n \"customer.subscription.deleted\",\n]);\n\nexport function unmodifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n const { source } = withInMemoryScript(original, (sf) => {\n removeImportByModuleSpecifier(sf, \"./subscription/created\");\n removeImportByModuleSpecifier(sf, \"./subscription/updated\");\n removeImportByModuleSpecifier(sf, \"./subscription/deleted\");\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n // Collect matching case clauses first — removing invalidates node refs.\n const toRemove = caseBlock\n .getClauses()\n .filter((clause) => {\n if (clause.getKind() !== SyntaxKind.CaseClause) return false;\n const caseClause = clause.asKindOrThrow(SyntaxKind.CaseClause);\n const expr = caseClause.getExpression();\n const literal =\n expr.asKind(SyntaxKind.StringLiteral) ??\n expr.asKind(SyntaxKind.NoSubstitutionTemplateLiteral);\n if (!literal) return false;\n return SUBSCRIPTION_CASE_VALUES.has(literal.getLiteralValue());\n })\n .map((c) => c.asKindOrThrow(SyntaxKind.CaseClause));\n\n for (const clause of toRemove.reverse()) {\n clause.remove();\n }\n\n formatLikeSource(sf);\n });\n\n // Removing the clauses takes the blank line before `default:` with them.\n const spaced = source.replace(/(break;)\\n(\\s*default:)/, \"$1\\n\\n$2\");\n\n if (spaced === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, spaced, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const removed = file.removeAttribute(\"AppSidebar\", \"subscription\");\n if (!removed) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n withInMemoryScript,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nfunction updateScript(source: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const hasSub = elements.some((e) => e.getName() === \"subscription\");\n\n // Strip subscription from the props type literal (the specific type\n // added by enable-subscriptions — leave unrelated `subscription` props\n // alone).\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"))\n .filter((t) => !/^\\s*subscription\\??\\s*:/.test(t));\n lit.replaceWithText(\n propTexts.length ? `{ ${propTexts.join(\"; \")}; }` : \"{}\",\n );\n break;\n }\n }\n\n if (hasSub) {\n const remaining = elements\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n pattern.replaceWithText(`{ ${remaining.join(\", \")} }`);\n }\n }\n formatLikeSource(sf);\n });\n return out;\n}\n\nexport function unmodifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(filePath, \"utf8\");\n const hasSubPropType = /subscription\\??\\s*:\\s*\\{/.test(source);\n const hasSubProp = /\\bsubscription\\s*=\\s*null\\b/.test(source);\n\n const file = new SvelteFile(source);\n const hasNavUserSubAttr =\n file.hasElement(\"NavUser\") && file.hasAttribute(\"NavUser\", \"subscription\");\n\n if (!hasSubPropType && !hasSubProp && !hasNavUserSubAttr) {\n return { status: \"success\", changed: false };\n }\n\n if (hasSubPropType || hasSubProp) {\n file.modifyScript(updateScript);\n }\n if (hasNavUserSubAttr) {\n file.removeAttribute(\"NavUser\", \"subscription\");\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\nimport {\n formatLikeSource,\n removeTopLevelStatementByIdentifier,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/**\n * Takes out what enable-subscriptions added to the (app) layout load: the\n * `subscription` it loads and returns, and the `loadActiveSubscription`\n * helper. The rest of the load (what other patterns added) stays.\n */\nexport function unmodifyAppLayoutServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n if (!original.includes(\"loadActiveSubscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const fromLoad = removeFromLoad(filePath, {\n variables: [\"subscription\"],\n dependsKeys: [],\n returnProps: [\"subscription\"],\n });\n if (fromLoad.status !== \"success\") return fromLoad;\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sf = project.addSourceFileAtPath(filePath);\n removeTopLevelStatementByIdentifier(sf, \"loadActiveSubscription\");\n formatLikeSource(sf);\n sf.saveSync();\n\n return {\n status: \"success\",\n changed: fs.readFileSync(filePath, \"utf8\") !== original,\n };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n bindingText,\n propsStatement,\n} from \"../../../enable/subscriptions/modifies/modify-nav-user\";\n\n/**\n * Takes the plan label out of nav-user: the lines showing it, `planLabel`\n * and the `subscription` prop. What other patterns added stays.\n */\nexport function unmodifyNavUser(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\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 file.modifyScript(\n (content) =>\n withInMemoryScript(\n // With the blank line enable-subscriptions put before it.\n content.replace(\n /\\n[ \\t]*\\n[ \\t]*const planLabel = \\$derived\\([^\\n]*\\);/,\n \"\",\n ),\n (sf) => {\n const decl = propsStatement(sf)?.getDeclarations()[0];\n const binding = decl\n ?.getNameNode()\n .asKind(SyntaxKind.ObjectBindingPattern);\n const kept = binding\n ?.getElements()\n .filter((e) => e.getName() !== \"subscription\")\n .map((e) => e.getText());\n if (binding && kept) {\n binding.replaceWithText(bindingText(binding.getText(), kept));\n }\n decl\n ?.getTypeNode()\n ?.asKind(SyntaxKind.TypeLiteral)\n ?.getProperty(\"subscription\")\n ?.remove();\n },\n ).source,\n );\n\n // The lines under the name, with the line break before them.\n const out = file\n .toString()\n .replace(/\\n[ \\t]*<span class=\"[^\"]*\">\\s*\\{planLabel\\}\\s*<\\/span>/g, \"\");\n\n fs.writeFileSync(filePath, out, \"utf8\");\n return { status: \"success\", changed: out !== original };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Rewrites a file to the given `template` if the current content still shows\n * the `enabledMarker` (meaning enable-subscriptions is applied). If the marker\n * is absent (already reverted or never applied), it's a no-op.\n *\n * Strips leading `// [!code highlight:N]` / `<!-- [!code highlight:N] -->`\n * lines so templates can be pulled from `preview-modifies/` directories which\n * use those for documentation highlighting.\n */\nexport function revertByTemplate(\n filePath: string,\n template: string,\n enabledMarker: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (!current.includes(enabledMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageServer(\n filePath: string,\n paymentsBillingPageServerTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageServerTemplate,\n \"selectPlan\",\n );\n}\n","import { revertByTemplate } from \"./revert-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyBillingPageSvelte(\n filePath: string,\n paymentsBillingPageSvelteTemplate: string,\n): ModifyOutcome {\n return revertByTemplate(\n filePath,\n paymentsBillingPageSvelteTemplate,\n \"availablePlans\",\n );\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { unmodifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { unmodifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { unmodifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Pull the \"post-payments\" state of files that enable-subscriptions fully\n// overwrote. For the billing pages, that's exactly what enable-payments\n// writes in creates-app-mode; for nav-user it's the payments preview-modifies\n// snapshot (with highlight annotations stripped by the revert helper).\nimport paymentsBillingPageServerTemplate from \"../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.server.ts?raw\";\nimport paymentsBillingPageSvelteTemplate from \"../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.svelte?raw\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n unmodifyWebhookServer(webhookServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n unmodifyAppLayoutServer(appLayoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n unmodifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n unmodifyBillingPageServer(\n billingPageServerPath,\n paymentsBillingPageServerTemplate,\n ),\n ),\n );\n\n logger.info(\"Reverting billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n unmodifyBillingPageSvelte(\n billingPageSveltePath,\n paymentsBillingPageSvelteTemplate,\n ),\n ),\n );\n\n const collectionDrops = await planDropsForCollections(\n [\"stripe_subscriptions\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AASA,IAAMgB,oBAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAgBC,EAAsB,GAAiC;CACrE,IAAI,CAACH,EAAG,WAAWI,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAMC,IAAWL,EAAG,aAAaI,GAAU,MAAM;CACjD,IAAI,CAACC,EAAS,SAAS,2BAA2B,GAChD,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,cAAWb,EAAmBa,IAAW,MAAO;EAGtD,AAFAX,EAA8BY,GAAI,wBAAwB,GAC1DZ,EAA8BY,GAAI,wBAAwB,GAC1DZ,EAA8BY,GAAI,wBAAwB;EAE1D,IAAMC,IAAaD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ACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAWlE,EAAoBuE,GAAatB,EAAgBsB,CAAW,CAAC,CAAC,GAEzER,EAAO,KAAK,mCAAmC;CAC/C,IAAMS,IAAwBlE,EAAK,KACjC0D,EAAQ,MACR,OACA,UACA,SACA,WACA,iBACF;CAWA,AAVAE,EACElE,EACEwE,GACAd,EACEc,GACAjF,CACF,CACF,CACF,GAEAwE,EAAO,KAAK,gCAAgC;CAC5C,IAAMU,IAAwBnE,EAAK,KACjC0D,EAAQ,MACR,OACA,UACA,SACA,WACA,cACF;CAgBA,OAfAE,EACElE,EACEyE,GACAb,EACEa,GACAjF,CACF,CACF,CACF,GAOO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BI,EAC5B,CAAC,sBAAsB,GACvBoE,CACF;CAWA;AACF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
|
+
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
+
import { _ as n, r } from "./ts-morph-helpers-Bepc-Es2.js";
|
|
4
|
+
import { r as i } from "./modify-file-289rStJ2.js";
|
|
5
|
+
import { t as a } from "./svelte-file-Dv5-bl79.js";
|
|
6
|
+
import o from "node:fs";
|
|
7
|
+
import s from "node:path";
|
|
8
|
+
//#region src/patterns/enable/ecommerce/modifies/root-layout.svelte.ts
|
|
9
|
+
var c = "#lib/components/cart/cart-button.svelte", l = "<Navbar.Item>\n <CartButton />\n</Navbar.Item>", u = `import CartButton from '${c}';`, d = e`
|
|
10
|
+
Add the cart button inside your <Navbar.List> in the root layout.
|
|
11
|
+
|
|
12
|
+
Import to add to the <script> tag:
|
|
13
|
+
|
|
14
|
+
${u}
|
|
15
|
+
|
|
16
|
+
Markup to add inside <Navbar.List>:
|
|
17
|
+
|
|
18
|
+
${l}
|
|
19
|
+
`, f = e`
|
|
20
|
+
Add the cart button to the layout your public pages share.
|
|
21
|
+
|
|
22
|
+
Import for the <script> tag:
|
|
23
|
+
|
|
24
|
+
${u}
|
|
25
|
+
|
|
26
|
+
Markup, wherever your navigation is:
|
|
27
|
+
|
|
28
|
+
<CartButton />
|
|
29
|
+
`;
|
|
30
|
+
function p(e) {
|
|
31
|
+
if (!o.existsSync(e)) return {
|
|
32
|
+
status: "not-found",
|
|
33
|
+
message: f
|
|
34
|
+
};
|
|
35
|
+
let t = a.fromPath(e);
|
|
36
|
+
if (!t.hasElement("Navbar.List")) return {
|
|
37
|
+
status: "failed",
|
|
38
|
+
message: d
|
|
39
|
+
};
|
|
40
|
+
if (t.hasElement("CartButton")) return {
|
|
41
|
+
status: "success",
|
|
42
|
+
changed: !1
|
|
43
|
+
};
|
|
44
|
+
t.modifyScript((e) => {
|
|
45
|
+
let { source: t } = n(e, (e) => {
|
|
46
|
+
r(e, [{
|
|
47
|
+
defaultImport: "CartButton",
|
|
48
|
+
moduleSpecifier: c
|
|
49
|
+
}]);
|
|
50
|
+
});
|
|
51
|
+
return t;
|
|
52
|
+
});
|
|
53
|
+
let i = t.findElementContaining("Navbar.Item", "AuthMenu.Root"), s = t.childElements("Navbar.List", "Navbar.Item"), u = s[s.length - 1];
|
|
54
|
+
return i ? t.insertBeforeElement(i, l) : u ? t.insertAfterElement(u, l) : t.insertBeforeClosingTag("Navbar.List", `\n\t\t${l.replace(/\n/g, "\n ")}\n\t`), t.writeTo(e), {
|
|
55
|
+
status: "success",
|
|
56
|
+
changed: t.hasChanged()
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/patterns/enable/ecommerce/generate.runtime.ts
|
|
61
|
+
function m(e) {
|
|
62
|
+
return o.existsSync(s.join(e, "src", "lib", "server", "stripe-customer.ts"));
|
|
63
|
+
}
|
|
64
|
+
async function h(e) {
|
|
65
|
+
let n = t(e), r = [];
|
|
66
|
+
n.info("Adding the cart to the navbar");
|
|
67
|
+
let a = s.join(e.root, "src", "routes", "(public)", "root-layout.svelte"), o = i(a, p(a));
|
|
68
|
+
return o && r.push(o), {
|
|
69
|
+
creates: [],
|
|
70
|
+
modifies: r,
|
|
71
|
+
deletes: [],
|
|
72
|
+
components: [],
|
|
73
|
+
packages: [],
|
|
74
|
+
collections: [],
|
|
75
|
+
collectionPatches: [],
|
|
76
|
+
collectionDrops: []
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { h as generate, m as hasStripeCustomer };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=generate.runtime-Bh9Z2cRN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-Bh9Z2cRN.js","names":["dedent","getLogger","withInMemoryScript","modifyOutcomeToFile","SvelteFile","fs","path","CART_BUTTON_MODULE","CART_NAVBAR_ITEM","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyRootLayoutSvelte","layoutPath","file","out","source","sf","authItem","items","lastItem","hasStripeCustomer","root","generate","logger","options","modifies"],"sources":["../../src/patterns/enable/ecommerce/modifies/root-layout.svelte.ts","../../src/patterns/enable/ecommerce/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport const CART_BUTTON_MODULE = \"#lib/components/cart/cart-button.svelte\";\n\nconst CART_NAVBAR_ITEM = \"<Navbar.Item>\\n\\t<CartButton />\\n</Navbar.Item>\";\n\nconst IMPORT_SNIPPET = `import CartButton from '${CART_BUTTON_MODULE}';`;\n\nconst FAILURE_HINT = dedent`\n Add the cart button 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 inside <Navbar.List>:\n\n ${CART_NAVBAR_ITEM}\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Add the cart button to the layout your public pages share.\n\n Import for the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup, wherever your navigation is:\n\n <CartButton />\n`;\n\n/**\n * Puts the cart button in the navbar: left of the account menu when auth\n * added one, else after the last item.\n */\nexport function modifyRootLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"CartButton\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { defaultImport: \"CartButton\", moduleSpecifier: CART_BUTTON_MODULE },\n ]);\n });\n return out;\n });\n\n const authItem = file.findElementContaining(\"Navbar.Item\", \"AuthMenu.Root\");\n const items = file.childElements(\"Navbar.List\", \"Navbar.Item\");\n const lastItem = items[items.length - 1];\n if (authItem) {\n file.insertBeforeElement(authItem, CART_NAVBAR_ITEM);\n } else if (lastItem) {\n file.insertAfterElement(lastItem, CART_NAVBAR_ITEM);\n } else {\n file.insertBeforeClosingTag(\n \"Navbar.List\",\n `\\n\\t\\t${CART_NAVBAR_ITEM.replace(/\\n/g, \"\\n\\t\\t\")}\\n\\t`,\n );\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\n\n/** Created by enable-payments for Stripe when auth was already on. */\nexport function hasStripeCustomer(root: string): boolean {\n return fs.existsSync(\n path.join(root, \"src\", \"lib\", \"server\", \"stripe-customer.ts\"),\n );\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Adding the cart to the navbar\");\n const layoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n const file = modifyOutcomeToFile(\n layoutPath,\n modifyRootLayoutSvelte(layoutPath),\n );\n if (file) modifies.push(file);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AASA,IAAaO,IAAqB,2CAE5BC,IAAmB,kDAEnBC,IAAiB,2BAA2BF,EAAmB,KAE/DG,IAAe,CAAM;;;;;IAKvBD,EAAe;;;;IAIfD,EAAiB;GAGfG,IAAiB,CAAM;;;;;IAKzBF,EAAe;;;;;;AAWnB,SAAgBG,EAAuB,GAAmC;CACxE,IAAI,CAACP,EAAG,WAAWQ,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAGxD,IAAMG,IAAOV,EAAW,SAASS,CAAU;CAC3C,IAAI,CAACC,EAAK,WAAW,aAAa,GAChC,OAAO;EAAE,QAAQ;EAAU,SAASJ;CAAa;CAEnD,IAAII,EAAK,WAAW,YAAY,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQC,MAAQb,EAAmBc,IAAS,MAAO;GACzD,EAAcC,GAAI,CAChB;IAAE,eAAe;IAAc,iBAAiBV;GAAmB,CACrE,CAAC;EACH,CAAC;EACD,OAAOQ;CACT,CAAC;CAED,IAAMG,IAAWJ,EAAK,sBAAsB,eAAe,eAAe,GACpEK,IAAQL,EAAK,cAAc,eAAe,aAAa,GACvDM,IAAWD,EAAMA,EAAM,SAAS;CAatC,OAZID,IACFJ,EAAK,oBAAoBI,GAAUV,CAAgB,IAC1CY,IACTN,EAAK,mBAAmBM,GAAUZ,CAAgB,IAElDM,EAAK,uBACH,eACA,SAASN,EAAiB,QAAQ,OAAO,MAAQ,EAAE,KACrD,GAGFM,EAAK,QAAQD,CAAU,GAChB;EAAE,QAAQ;EAAW,SAASC,EAAK,WAAW;CAAE;AACzD;;;ACzEA,SAAgBO,EAAkB,GAAuB;CACvD,OAAOhB,EAAG,WACRC,EAAK,KAAKgB,GAAM,OAAO,OAAO,UAAU,oBAAoB,CAC9D;AACF;AAEA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAmB,CAAC;CAE1B,EAAO,KAAK,+BAA+B;CAC3C,IAAMb,IAAaP,EAAK,KACtBmB,EAAQ,MACR,OACA,UACA,YACA,oBACF,GACMX,IAAOX,EACXU,GACAD,EAAuBC,CAAU,CACnC;CAGA,OAFIC,KAAMY,EAAS,KAAKZ,CAAI,GAErB;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a, i as o, o as s, r as c, t as l } from "./whatsapp-
|
|
2
|
+
import { i as t, n, t as r } from "./pocketbase-B017Cqjq.js";
|
|
3
|
+
import { r as i } from "./modify-file-289rStJ2.js";
|
|
4
|
+
import { a, i as o, o as s, r as c, t as l } from "./whatsapp-5qJ_xCV1.js";
|
|
5
5
|
import { swapAuthPages as u } from "./auth-pages-B52ei-4z.js";
|
|
6
6
|
import d from "node:fs";
|
|
7
7
|
import f from "node:path";
|
|
@@ -33,24 +33,24 @@ function h(e) {
|
|
|
33
33
|
}
|
|
34
34
|
async function g(d) {
|
|
35
35
|
let g = e(d), _ = [];
|
|
36
|
-
await
|
|
36
|
+
await t(d.root, async (e) => {
|
|
37
37
|
if (!await o(e)) throw Error(`This PocketBase has no WhatsApp sign-in. It comes with pocketbase-server ${l} and later: run \`npm install -D pocketbase-server@^${l}\`, then \`vela enable whatsapp\` again.`);
|
|
38
38
|
if (g.info("Adding the phone fields to users and making email optional"), await a(e)) {
|
|
39
|
-
await
|
|
40
|
-
let e =
|
|
39
|
+
await n();
|
|
40
|
+
let e = r("users", "updated", d);
|
|
41
41
|
e && _.push(h(e));
|
|
42
42
|
}
|
|
43
|
-
g.info("Turning on WhatsApp sign-in for users"), await c(e), await
|
|
43
|
+
g.info("Turning on WhatsApp sign-in for users"), await c(e), await n();
|
|
44
44
|
let t = s(d, !0);
|
|
45
45
|
t && _.push(h(t));
|
|
46
46
|
}), g.info("Adding WhatsApp to the login and signup pages");
|
|
47
47
|
let v = [], y = await u(d.root, "enable", (e) => `${f.relative(d.root, e)} is not the page enable-auth wrote, so it was left as it is. Add the WhatsApp option to it by hand: ${m}`);
|
|
48
|
-
for (let [e,
|
|
49
|
-
let
|
|
50
|
-
|
|
48
|
+
for (let [e, t] of y) {
|
|
49
|
+
let n = i(e, t);
|
|
50
|
+
n && v.push(n);
|
|
51
51
|
}
|
|
52
52
|
g.info("Updating test/setup.ts for an optional email");
|
|
53
|
-
let b = f.join(d.root, "test", "setup.ts"), x =
|
|
53
|
+
let b = f.join(d.root, "test", "setup.ts"), x = i(b, p(b));
|
|
54
54
|
return x && v.push(x), {
|
|
55
55
|
creates: _,
|
|
56
56
|
modifies: v,
|
|
@@ -65,4 +65,4 @@ async function g(d) {
|
|
|
65
65
|
//#endregion
|
|
66
66
|
export { g as generate };
|
|
67
67
|
|
|
68
|
-
//# sourceMappingURL=generate.runtime-
|
|
68
|
+
//# sourceMappingURL=generate.runtime-BxDUtkpT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-BxDUtkpT.js","names":["getLogger","withPocketbase","getMigrationFile","modifyOutcomeToFile","hasWhatsAppPlugin","writeWhatsAppConfigMigration","enableWhatsAppAuth","MIN_POCKETBASE_SERVER","fs","path","modifyTestSetup","setupPath","original","content","indent","head","tail","bodyIndent","value","fieldIndent","DOCS_URL","migrationCreate","file","generate","logger","options","creates","pb","setupWhatsAppFields","migrationDelay","configMigration","modifies","outcomes","swapAuthPages","filePath","outcome","testSetup","testSetupFile"],"sources":["../../src/patterns/enable/whatsapp/modifies/modify-test-setup.ts","../../src/patterns/enable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * `email` turns optional on `users`, which the generated types follow, so a\n * test setup from before enable-backend handled that no longer type-checks:\n * its `authenticateUser` takes `{ email: string }` and it signs the test\n * user in with `context.user.email`. Brings those two spots up to the\n * current setup; anything else in the file is the project's own.\n */\nexport function modifyTestSetup(setupPath: string): ModifyOutcome {\n if (!fs.existsSync(setupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(setupPath, \"utf8\");\n let content = original;\n\n content = content.replace(\n /^([ \\t]*)(async function authenticateUser\\(agent: Agent, user: \\{ )email: string( \\}\\) \\{\\n)([ \\t]*)/m,\n (_, indent, head, tail, bodyIndent) =>\n `${indent}${head}email?: string${tail}` +\n `${bodyIndent}// Logs in with the password, so it needs the email (made optional by\\n` +\n `${bodyIndent}// enable-whatsapp, for accounts that sign in with a phone number).\\n` +\n `${bodyIndent}if (!user.email) {\\n` +\n `${bodyIndent}${bodyIndent.includes(\"\\t\") ? \"\\t\" : \" \"}throw new Error('authenticateUser needs a user with an email');\\n` +\n `${bodyIndent}}\\n` +\n bodyIndent,\n );\n\n // The user is made with a known email: sign in with that.\n content = content.replace(\n /^([ \\t]*)context\\.user = await context\\.admin\\.collection\\('users'\\)\\.create\\(\\{\\n([ \\t]*)email: (`test-\\$\\{Math\\.random\\(\\)\\.toString\\(36\\)\\.slice\\(2\\)\\}@example\\.com`),/m,\n (_, indent, fieldIndent, value) =>\n `${indent}const email = ${value};\\n` +\n `${indent}context.user = await context.admin.collection('users').create({\\n` +\n `${fieldIndent}email,`,\n );\n if (content.includes(\"const email = `test-\")) {\n content = content.replace(\n \".authWithPassword(context.user.email, testUserPassword)\",\n \".authWithPassword(email, testUserPassword)\",\n );\n }\n\n if (content === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(setupPath, content, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n MIN_POCKETBASE_SERVER,\n enableWhatsAppAuth,\n hasWhatsAppPlugin,\n setupWhatsAppFields,\n writeWhatsAppConfigMigration,\n} from \"./runtime/whatsapp\";\nimport { swapAuthPages } from \"./modifies/auth-pages\";\nimport { modifyTestSetup } from \"./modifies/modify-test-setup\";\n\nexport const DOCS_URL = \"https://velastack.dev/docs/enable/whatsapp\";\n\nfunction migrationCreate(file: string): File {\n return {\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n };\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n if (!(await hasWhatsAppPlugin(pb))) {\n throw new Error(\n `This PocketBase has no WhatsApp sign-in. It comes with pocketbase-server ${MIN_POCKETBASE_SERVER} and later: run \\`npm install -D pocketbase-server@^${MIN_POCKETBASE_SERVER}\\`, then \\`vela enable whatsapp\\` again.`,\n );\n }\n\n logger.info(\"Adding the phone fields to users and making email optional\");\n if (await setupWhatsAppFields(pb)) {\n await migrationDelay();\n const file = getMigrationFile(\"users\", \"updated\", options);\n if (file) creates.push(migrationCreate(file));\n }\n\n logger.info(\"Turning on WhatsApp sign-in for users\");\n await enableWhatsAppAuth(pb);\n await migrationDelay();\n const configMigration = writeWhatsAppConfigMigration(options, true);\n if (configMigration) creates.push(migrationCreate(configMigration));\n });\n\n logger.info(\"Adding WhatsApp to the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"enable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-auth wrote, so it was left as it is. Add the WhatsApp option to it by hand: ${DOCS_URL}`,\n );\n for (const [filePath, outcome] of outcomes) {\n const file = modifyOutcomeToFile(filePath, outcome);\n if (file) modifies.push(file);\n }\n\n logger.info(\"Updating test/setup.ts for an optional email\");\n const testSetup = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetup,\n modifyTestSetup(testSetup),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAUA,SAAgBU,EAAgB,GAAkC;CAChE,IAAI,CAACF,EAAG,WAAWG,CAAS,GAC1B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAW,MAAM,GAC9CE,IAAUD;CAiCd,OA/BA,IAAUC,EAAQ,QAChB,0GACC,GAAG,GAAQ,GAAM,GAAM,MACtB,GAAGC,IAASC,EAAK,gBAAgBC,IAC9BC,EAAW,yEACXA,EAAW,uEACXA,EAAW,sBACXA,IAAaA,EAAW,SAAS,GAAI,IAAI,MAAO,KAAK,mEACrDA,EAAW,OACdA,CACJ,GAGA,IAAUJ,EAAQ,QAChB,gLACC,GAAG,GAAQ,GAAa,MACvB,GAAGC,EAAO,gBAAgBI,EAAM,KAC7BJ,EAAO,mEACPK,EAAY,OACnB,GACIN,EAAQ,SAAS,sBAA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b,KAAMS,EAAS,KAAKT,CAAI;CAC9B;CAEA,EAAO,KAAK,8CAA8C;CAC1D,IAAMc,IAAY3B,EAAK,KAAKgB,EAAQ,MAAM,QAAQ,UAAU,GACtDY,IAAgBlC,EACpBiC,GACA1B,EAAgB0B,CAAS,CAC3B;CAGA,OAFIC,KAAeN,EAAS,KAAKM,CAAa,GAEvC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { r as e } from "./lib-specifier-Cngo1zF_.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { n, t as r } from "./generate-
|
|
3
|
+
import { n, t as r } from "./generate-CXoQPz7n.js";
|
|
4
4
|
import { n as i } from "./env-BPfk1VAw.js";
|
|
5
5
|
import { _ as a, n as o, u as s } from "./ts-morph-helpers-Bepc-Es2.js";
|
|
6
|
-
import {
|
|
7
|
-
import { unmodifyEnvVarsFiles as u } from "./env-vars-
|
|
8
|
-
import { t as d } from "./svelte-file-
|
|
6
|
+
import { r as c, t as l } from "./modify-file-289rStJ2.js";
|
|
7
|
+
import { unmodifyEnvVarsFiles as u } from "./env-vars-cqQU0ECK.js";
|
|
8
|
+
import { t as d } from "./svelte-file-Dv5-bl79.js";
|
|
9
9
|
import f from "node:fs";
|
|
10
10
|
import p from "node:path";
|
|
11
11
|
//#region src/patterns/disable/analytics/modifies/layout.svelte.ts
|
|
@@ -44,10 +44,10 @@ async function g(e) {
|
|
|
44
44
|
};
|
|
45
45
|
a.info("Reverting src/routes/+layout.svelte");
|
|
46
46
|
let f = p.join(e.root, "src", "routes", "+layout.svelte");
|
|
47
|
-
d(
|
|
47
|
+
d(c(f, h(f))), a.info("Removing analytics variables from src/env.ts");
|
|
48
48
|
let m = u(e.root, n());
|
|
49
49
|
d(m.modify), m.delete && s.push(m.delete), a.info("Removing analytics variables from .env");
|
|
50
|
-
let g = p.join(e.root, ".env"), _ =
|
|
50
|
+
let g = p.join(e.root, ".env"), _ = l(g, i(g, r()));
|
|
51
51
|
return d(_.modify), _.delete && s.push(_.delete), {
|
|
52
52
|
creates: [],
|
|
53
53
|
modifies: o,
|
|
@@ -62,4 +62,4 @@ async function g(e) {
|
|
|
62
62
|
//#endregion
|
|
63
63
|
export { g as generate };
|
|
64
64
|
|
|
65
|
-
//# sourceMappingURL=generate.runtime-
|
|
65
|
+
//# sourceMappingURL=generate.runtime-BxUGDXIK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-BxUGDXIK.js","names":["libModule","getLogger","allEnvEdits","modifyEnvRemove","withInMemoryScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","modifyOutcomeToFile","envRevertOutcomeToFile","SvelteFile","fs","path","MODULE","unmodifyLayoutSvelte","layoutPath","original","file","out","source","sf","updated","generate","logger","options","modifies","deletes","pushResult","envVars","unmodifyEnvVarsFiles","allEnvNames","envPath","env"],"sources":["../../src/patterns/disable/analytics/modifies/layout.svelte.ts","../../src/patterns/disable/analytics/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst MODULE = \"components/analytics/analytics.svelte\";\n\n/**\n * Takes `<Analytics />` and its import back out of the root layout. The\n * element goes with its whole line, since enable-analytics put it on one of\n * its own. A layout without it, or no layout at all, is left alone.\n */\nexport function unmodifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(MODULE) && !original.includes(\"<Analytics\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(sf, libModule(MODULE));\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(/[ \\t]*<Analytics\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyEnvRemove } from \"../../../runtime/env\";\nimport {\n envRevertOutcomeToFile,\n modifyOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { allEnvEdits, allEnvNames } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { unmodifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, unmodifyLayoutSvelte(layoutPath)));\n\n // Which provider was chosen is not recorded, so every one's variables go;\n // the file goes too when these were all it declared.\n logger.info(\"Removing analytics variables from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n pushResult(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing analytics variables from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n pushResult(env.modify);\n if (env.delete) deletes.push(env.delete);\n\n return {\n creates: [],\n modifies,\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAMY,IAAS;AAOf,SAAgBC,EAAqB,GAAmC;CACtE,IAAI,CAACH,EAAG,WAAWI,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWL,EAAG,aAAaI,GAAY,MAAM;CACnD,IAAI,CAACC,EAAS,SAASH,CAAM,KAAK,CAACG,EAAS,SAAS,YAAY,GAC/D,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOP,EAAW,SAASK,CAAU;CAC3C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQG,MAAQb,EAAmBc,IAAS,MAAO;GAEzD,AADAZ,EAA8Ba,GAAInB,EAAUY,CAAM,CAAC,GACnDP,EAA4Bc,CAAE;EAChC,CAAC;EACD,OAAOF;CACT,CAAC;CAED,IAAMG,IAAUJ,EACb,SAAS,CAAC,CACV,QAAQ,uCAAuC,EAAE;CAMpD,OAJII,MAAYL,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAE7CL,EAAG,cAAcI,GAAYM,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;ACjCA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASrB,EAAUsB,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GACnBC,KAAc,MAAsB;EACxC,AAAIV,KAAMQ,EAAS,KAAKR,CAAI;CAC9B;CAEA,EAAO,KAAK,qCAAqC;CACjD,IAAMF,IAAaH,EAAK,KAAKY,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAK5E,AAJAG,EAAWnB,EAAoBO,GAAYD,EAAqBC,CAAU,CAAC,CAAC,GAI5EQ,EAAO,KAAK,8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