@velastack/patterns 0.0.35 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/chunks/{collections-DRN-8nW0.js → collections-DcCZ0dam.js} +73 -5
  2. package/dist/chunks/collections-DcCZ0dam.js.map +1 -0
  3. package/dist/chunks/env-DfA_NCKk.js +67 -0
  4. package/dist/chunks/env-DfA_NCKk.js.map +1 -0
  5. package/dist/chunks/{env.preview-BZwjhgoi.js → env.preview-7Cc9KCgc.js} +1 -1
  6. package/dist/chunks/{env.preview-BZwjhgoi.js.map → env.preview-7Cc9KCgc.js.map} +1 -1
  7. package/dist/chunks/{env.runtime-BEdollKV.js → env.runtime-l1ssTZog.js} +1 -1
  8. package/dist/chunks/{env.runtime-BEdollKV.js.map → env.runtime-l1ssTZog.js.map} +1 -1
  9. package/dist/chunks/{generate.runtime-Caqa5ndO.js → generate.runtime-BB0XISiq.js} +4 -3
  10. package/dist/chunks/{generate.runtime-Caqa5ndO.js.map → generate.runtime-BB0XISiq.js.map} +1 -1
  11. package/dist/chunks/generate.runtime-Bag8x62P.js +37 -0
  12. package/dist/chunks/generate.runtime-Bag8x62P.js.map +1 -0
  13. package/dist/chunks/generate.runtime-Bu5bO86n.js +60 -0
  14. package/dist/chunks/generate.runtime-Bu5bO86n.js.map +1 -0
  15. package/dist/chunks/{generate.runtime-DTZ1PeDS.js → generate.runtime-CKouBODu.js} +27 -26
  16. package/dist/chunks/{generate.runtime-DTZ1PeDS.js.map → generate.runtime-CKouBODu.js.map} +1 -1
  17. package/dist/chunks/{generate.runtime-D7ksYerH.js → generate.runtime-CS55berV.js} +7 -6
  18. package/dist/chunks/{generate.runtime-D7ksYerH.js.map → generate.runtime-CS55berV.js.map} +1 -1
  19. package/dist/chunks/generate.runtime-CVsBIZm4.js +37 -0
  20. package/dist/chunks/generate.runtime-CVsBIZm4.js.map +1 -0
  21. package/dist/chunks/{generate.runtime--31y_UK2.js → generate.runtime-Cy56Ypws.js} +27 -26
  22. package/dist/chunks/{generate.runtime--31y_UK2.js.map → generate.runtime-Cy56Ypws.js.map} +1 -1
  23. package/dist/chunks/generate.runtime-D3H_yNZA.js +210 -0
  24. package/dist/chunks/generate.runtime-D3H_yNZA.js.map +1 -0
  25. package/dist/chunks/generate.runtime-D8DxU99S.js +93 -0
  26. package/dist/chunks/generate.runtime-D8DxU99S.js.map +1 -0
  27. package/dist/chunks/generate.runtime-DPbHzukR.js +116 -0
  28. package/dist/chunks/generate.runtime-DPbHzukR.js.map +1 -0
  29. package/dist/chunks/{generate.runtime-BVss5za4.js → generate.runtime-DV9S4KW_.js} +106 -131
  30. package/dist/chunks/generate.runtime-DV9S4KW_.js.map +1 -0
  31. package/dist/chunks/generate.runtime-GmszNklA.js +56 -0
  32. package/dist/chunks/generate.runtime-GmszNklA.js.map +1 -0
  33. package/dist/chunks/generate.runtime-NdlYevoh.js +65 -0
  34. package/dist/chunks/generate.runtime-NdlYevoh.js.map +1 -0
  35. package/dist/chunks/{generate.runtime-Cbq2649r.js → generate.runtime-eYyscad0.js} +29 -28
  36. package/dist/chunks/{generate.runtime-Cbq2649r.js.map → generate.runtime-eYyscad0.js.map} +1 -1
  37. package/dist/chunks/{generate.runtime-CZKIdbEC.js → generate.runtime-mPNuFTCh.js} +54 -53
  38. package/dist/chunks/{generate.runtime-CZKIdbEC.js.map → generate.runtime-mPNuFTCh.js.map} +1 -1
  39. package/dist/chunks/hooks.server-CPVyj3rv.js +75 -0
  40. package/dist/chunks/hooks.server-CPVyj3rv.js.map +1 -0
  41. package/dist/chunks/{modify-file-DT_1_kvI.js → modify-file-Bi-4GRwL.js} +2 -2
  42. package/dist/chunks/{modify-file-DT_1_kvI.js.map → modify-file-Bi-4GRwL.js.map} +1 -1
  43. package/dist/chunks/{modify-svelte-config-remote-CFsA9Mom.js → modify-svelte-config-remote-B-jnjYqs.js} +1 -1
  44. package/dist/chunks/{modify-svelte-config-remote-CFsA9Mom.js.map → modify-svelte-config-remote-B-jnjYqs.js.map} +1 -1
  45. package/dist/chunks/{pocketbase-iFJBbNJu.js → pocketbase-CT78tKFG.js} +1 -1
  46. package/dist/chunks/{pocketbase-iFJBbNJu.js.map → pocketbase-CT78tKFG.js.map} +1 -1
  47. package/dist/chunks/shared-D9iYuKxV.js +27 -0
  48. package/dist/chunks/shared-D9iYuKxV.js.map +1 -0
  49. package/dist/chunks/{ts-morph-helpers-C0HeJDjR.js → ts-morph-helpers-B0oxeDUU.js} +47 -3
  50. package/dist/chunks/ts-morph-helpers-B0oxeDUU.js.map +1 -0
  51. package/dist/chunks/{util-C064WO8o.js → util-CLl3VxaE.js} +4 -3
  52. package/dist/chunks/util-CLl3VxaE.js.map +1 -0
  53. package/dist/chunks/{write-result-CqSY1Bww.js → write-result-CRq0kUvL.js} +12 -7
  54. package/dist/chunks/{write-result-CqSY1Bww.js.map → write-result-CRq0kUvL.js.map} +1 -1
  55. package/dist/index.d.ts +912 -209
  56. package/dist/index.js +1868 -871
  57. package/dist/index.js.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/chunks/collections-DRN-8nW0.js.map +0 -1
  60. package/dist/chunks/generate.runtime-BVss5za4.js.map +0 -1
  61. package/dist/chunks/ts-morph-helpers-C0HeJDjR.js.map +0 -1
  62. package/dist/chunks/util-C064WO8o.js.map +0 -1
@@ -0,0 +1,210 @@
1
+ import { t as e } from "./dedent-C4qKBQXh.js";
2
+ import { n as t } from "./logger-BpgCb-ZG.js";
3
+ import { modifyOutcomeToFile as n } from "./modify-file-Bi-4GRwL.js";
4
+ import { a as r, n as i, o as a } from "./ts-morph-helpers-B0oxeDUU.js";
5
+ import o from "node:fs";
6
+ import s from "node:path";
7
+ import { Project as c, QuoteKind as l, SyntaxKind as u } from "ts-morph";
8
+ //#region src/patterns/enable/content-negotiation/modifies/hooks.server.ts
9
+ var d = e`
10
+ Wrap your exported handle with the negotiation handler:
11
+
12
+ import { sequence } from '@sveltejs/kit/hooks';
13
+ import { handle as handleNegotiate } from '$lib/negotiate';
14
+
15
+ export const handle = sequence(handleNegotiate, /* your existing handle */);
16
+ `, f = e`
17
+ Create src/hooks.server.ts with a negotiation handle:
18
+
19
+ export { handle } from '$lib/negotiate';
20
+ `;
21
+ function p(e) {
22
+ let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "@sveltejs/kit/hooks");
23
+ if (t) {
24
+ t.getNamedImports().some((e) => e.getName() === "sequence") || t.addNamedImport("sequence");
25
+ return;
26
+ }
27
+ e.addImportDeclaration({
28
+ namedImports: ["sequence"],
29
+ moduleSpecifier: "@sveltejs/kit/hooks"
30
+ });
31
+ }
32
+ function m(e) {
33
+ let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/negotiate");
34
+ if (t) {
35
+ t.getNamedImports().some((e) => e.getName() === "handle" && e.getAliasNode()?.getText() === "handleNegotiate") || t.addNamedImport({
36
+ name: "handle",
37
+ alias: "handleNegotiate"
38
+ });
39
+ return;
40
+ }
41
+ e.addImportDeclaration({
42
+ namedImports: [{
43
+ name: "handle",
44
+ alias: "handleNegotiate"
45
+ }],
46
+ moduleSpecifier: "$lib/negotiate"
47
+ });
48
+ }
49
+ function h(e) {
50
+ if (!o.existsSync(e)) return {
51
+ status: "not-found",
52
+ message: f
53
+ };
54
+ if (o.readFileSync(e, "utf8").includes("handleNegotiate")) return {
55
+ status: "success",
56
+ changed: !1
57
+ };
58
+ let t = new c({
59
+ compilerOptions: { allowJs: !0 },
60
+ manipulationSettings: { quoteKind: l.Single }
61
+ }).addSourceFileAtPath(e), n = t.getVariableDeclaration("handle");
62
+ if (!n || !n.getFirstAncestorByKind(u.VariableStatement)?.hasExportKeyword()) return {
63
+ status: "failed",
64
+ message: d
65
+ };
66
+ let r = n.getInitializer();
67
+ if (!r) return {
68
+ status: "failed",
69
+ message: d
70
+ };
71
+ if (m(t), r.getKind() === u.CallExpression) {
72
+ let e = r.asKindOrThrow(u.CallExpression);
73
+ if (e.getExpression().getText() === "sequence") return e.insertArgument(0, "handleNegotiate"), t.formatText(), t.saveSync(), {
74
+ status: "success",
75
+ changed: !0
76
+ };
77
+ }
78
+ return p(t), n.setInitializer(`sequence(handleNegotiate, ${r.getText()})`), t.formatText(), t.saveSync(), {
79
+ status: "success",
80
+ changed: !0
81
+ };
82
+ }
83
+ //#endregion
84
+ //#region src/patterns/enable/content-negotiation/modifies/hooks.ts
85
+ var g = e`
86
+ import { reroute as negotiateReroute } from '$lib/negotiate';
87
+
88
+ export const reroute = ({ url }) => negotiateReroute(url.pathname);
89
+ `, _ = e`
90
+ Compose your existing reroute in src/hooks.ts with the negotiation reroute:
91
+
92
+ import { reroute as negotiateReroute } from '$lib/negotiate';
93
+
94
+ export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));
95
+ `;
96
+ function v(e) {
97
+ let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/negotiate");
98
+ if (t) {
99
+ t.getNamedImports().some((e) => e.getName() === "reroute" && e.getAliasNode()?.getText() === "negotiateReroute") || t.addNamedImport({
100
+ name: "reroute",
101
+ alias: "negotiateReroute"
102
+ });
103
+ return;
104
+ }
105
+ e.addImportDeclaration({
106
+ namedImports: [{
107
+ name: "reroute",
108
+ alias: "negotiateReroute"
109
+ }],
110
+ moduleSpecifier: "$lib/negotiate"
111
+ });
112
+ }
113
+ function y(e) {
114
+ if (!o.existsSync(e)) return o.mkdirSync(s.dirname(e), { recursive: !0 }), o.writeFileSync(e, g + "\n"), {
115
+ status: "success",
116
+ changed: !0
117
+ };
118
+ if (o.readFileSync(e, "utf8").includes("negotiateReroute")) return {
119
+ status: "success",
120
+ changed: !1
121
+ };
122
+ let t = new c({
123
+ compilerOptions: { allowJs: !0 },
124
+ manipulationSettings: { quoteKind: l.Single }
125
+ }).addSourceFileAtPath(e), n = t.getVariableDeclaration("reroute");
126
+ if (!n) return v(t), t.addStatements("\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\n"), t.formatText(), t.saveSync(), {
127
+ status: "success",
128
+ changed: !0
129
+ };
130
+ if (!n.getFirstAncestorByKind(u.VariableStatement)?.hasExportKeyword()) return {
131
+ status: "failed",
132
+ message: _
133
+ };
134
+ let r = n.getInitializer();
135
+ if (!r) return {
136
+ status: "failed",
137
+ message: _
138
+ };
139
+ let i = t.getVariableDeclarations().some((e) => e.getName() === "rerouteDeLocalize"), a = r.getText();
140
+ return i && a.includes("rerouteDeLocalize") ? (v(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))"), t.formatText(), t.saveSync(), {
141
+ status: "success",
142
+ changed: !0
143
+ }) : {
144
+ status: "failed",
145
+ message: _
146
+ };
147
+ }
148
+ //#endregion
149
+ //#region src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts
150
+ var b = e`
151
+ import { Negotiate } from '$lib/negotiate';
152
+ `, x = "\n<Negotiate />\n", S = [
153
+ "Create the root +layout.svelte and mount <Negotiate /> inside it.",
154
+ "",
155
+ "Import for the <script> tag:",
156
+ "",
157
+ b,
158
+ "",
159
+ "Markup to add at the top level of the layout:",
160
+ x.trim()
161
+ ].join("\n");
162
+ function C(e) {
163
+ if (!o.existsSync(e)) return {
164
+ status: "not-found",
165
+ message: S
166
+ };
167
+ let t = a.fromPath(e);
168
+ return t.hasElement("Negotiate") ? {
169
+ status: "success",
170
+ changed: !1
171
+ } : (t.modifyScript((e) => {
172
+ let { source: t } = r(e, (e) => {
173
+ i(e, [{
174
+ namedImports: ["Negotiate"],
175
+ moduleSpecifier: "$lib/negotiate"
176
+ }]);
177
+ });
178
+ return t;
179
+ }), t.appendMarkup(x), t.writeTo(e), {
180
+ status: "success",
181
+ changed: t.hasChanged()
182
+ });
183
+ }
184
+ //#endregion
185
+ //#region src/patterns/enable/content-negotiation/generate.runtime.ts
186
+ async function w(e) {
187
+ let r = t(e), i = [], a = (e) => {
188
+ e && i.push(e);
189
+ };
190
+ r.info("Modifying hooks.server.ts");
191
+ let o = s.join(e.root, "src", "hooks.server.ts");
192
+ a(n(o, h(o))), r.info("Modifying hooks.ts");
193
+ let c = s.join(e.root, "src", "hooks.ts");
194
+ a(n(c, y(c))), r.info("Modifying src/routes/+layout.svelte");
195
+ let l = s.join(e.root, "src", "routes", "+layout.svelte");
196
+ return a(n(l, C(l))), {
197
+ creates: [],
198
+ modifies: i,
199
+ deletes: [],
200
+ components: [],
201
+ packages: [],
202
+ collections: [],
203
+ collectionPatches: [],
204
+ collectionDrops: []
205
+ };
206
+ }
207
+ //#endregion
208
+ export { w as generate };
209
+
210
+ //# sourceMappingURL=generate.runtime-D3H_yNZA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-D3H_yNZA.js","names":[],"sources":["../../src/patterns/enable/content-negotiation/modifies/hooks.server.ts","../../src/patterns/enable/content-negotiation/modifies/hooks.ts","../../src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts","../../src/patterns/enable/content-negotiation/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type SourceFile,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the negotiation handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = sequence(handleNegotiate, /* your existing handle */);\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with a negotiation handle:\n\n export { handle } from '$lib/negotiate';\n`;\n\nfunction ensureSequenceImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"@sveltejs/kit/hooks\");\n if (existing) {\n const has = existing\n .getNamedImports()\n .some((ni) => ni.getName() === \"sequence\");\n if (!has) existing.addNamedImport(\"sequence\");\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [\"sequence\"],\n moduleSpecifier: \"@sveltejs/kit/hooks\",\n });\n}\n\nfunction ensureNegotiateHandleImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"handle\" &&\n ni.getAliasNode()?.getText() === \"handleNegotiate\"\n );\n });\n if (!has) existing.addNamedImport({ name: \"handle\", alias: \"handleNegotiate\" });\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"handle\", alias: \"handleNegotiate\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksServerNegotiate(\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(\"handleNegotiate\")) {\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 const handleDecl = sourceFile.getVariableDeclaration(\"handle\");\n if (!handleDecl) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const handleStmt = handleDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!handleStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = handleDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNegotiateHandleImport(sourceFile);\n\n if (init.getKind() === SyntaxKind.CallExpression) {\n const call = init.asKindOrThrow(SyntaxKind.CallExpression);\n if (call.getExpression().getText() === \"sequence\") {\n call.insertArgument(0, \"handleNegotiate\");\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n }\n\n ensureSequenceImport(sourceFile);\n handleDecl.setInitializer(`sequence(handleNegotiate, ${init.getText()})`);\n sourceFile.formatText();\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 {\n Project,\n QuoteKind,\n SyntaxKind,\n type SourceFile,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NEGOTIATE_ONLY_SNIPPET = dedent`\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => negotiateReroute(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the negotiation reroute:\n\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));\n`;\n\nfunction ensureNegotiateImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"reroute\" &&\n ni.getAliasNode()?.getText() === \"negotiateReroute\"\n );\n });\n if (!has) {\n existing.addNamedImport({ name: \"reroute\", alias: \"negotiateReroute\" });\n }\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"reroute\", alias: \"negotiateReroute\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksNegotiate(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, NEGOTIATE_ONLY_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"negotiateReroute\")) {\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 ensureNegotiateImport(sourceFile);\n sourceFile.addStatements(\n `\\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\\n`,\n );\n sourceFile.formatText();\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) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const hasI18nHelper = sourceFile\n .getVariableDeclarations()\n .some((d) => d.getName() === \"rerouteDeLocalize\");\n const initText = init.getText();\n\n if (hasI18nHelper && initText.includes(\"rerouteDeLocalize\")) {\n ensureNegotiateImport(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n return { status: \"failed\", message: FAILURE_HINT };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { Negotiate } from '$lib/negotiate';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<Negotiate />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root +layout.svelte and mount <Negotiate /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nexport function modifyRootLayoutNegotiate(\n layoutPath: string,\n): 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(\"Negotiate\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"Negotiate\"],\n moduleSpecifier: \"$lib/negotiate\",\n },\n ]);\n });\n return out;\n });\n\n file.appendMarkup(MARKUP_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\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 { modifyHooksServerNegotiate } from \"./modifies/hooks.server\";\nimport { modifyHooksNegotiate } from \"./modifies/hooks\";\nimport { modifyRootLayoutNegotiate } from \"./modifies/root-layout.svelte\";\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 hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerNegotiate(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(\n modifyOutcomeToFile(hooksPath, modifyHooksNegotiate(hooksPath)),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const rootLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutNegotiate(rootLayoutPath),\n ),\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAUA,IAAM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G9C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQ,MAAQ,EAAmB,IAAS,MAAO;AACzD,KAAc,GAAI,CAChB;IACE,cAAc,CAAC,YAAY;IAC3B,iBAAiB;IAClB,CACF,CAAC;IACF;AACF,SAAO;GACP,EAEF,EAAK,aAAa,EAAe,EACjC,EAAK,QAAQ,EAAW,EACjB;EAAE,QAAQ;EAAW,SAAS,EAAK,YAAY;EAAE;;;;AC5C1D,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,EAAQ,EAC3B,IAAmB,EAAE,EAErB,KAAc,MAAsB;AACxC,EAAI,KAAM,EAAS,KAAK,EAAK;;AAG/B,GAAO,KAAK,4BAA4B;CACxC,IAAM,IAAkB,EAAK,KAAK,EAAQ,MAAM,OAAO,kBAAkB;AAQzE,CAPA,EACE,EACE,GACA,EAA2B,EAAgB,CAC5C,CACF,EAED,EAAO,KAAK,qBAAqB;CACjC,IAAM,IAAY,EAAK,KAAK,EAAQ,MAAM,OAAO,WAAW;AAK5D,CAJA,EACE,EAAoB,GAAW,EAAqB,EAAU,CAAC,CAChE,EAED,EAAO,KAAK,sCAAsC;CAClD,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,UACA,iBACD;AAQD,QAPA,EACE,EACE,GACA,EAA0B,EAAe,CAC1C,CACF,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
@@ -0,0 +1,93 @@
1
+ import { n as e } from "./logger-BpgCb-ZG.js";
2
+ import { t } from "./shared-D9iYuKxV.js";
3
+ import { modifyOutcomeToFile as n } from "./modify-file-Bi-4GRwL.js";
4
+ import { i as r, o as i } from "./ts-morph-helpers-B0oxeDUU.js";
5
+ import a from "node:fs";
6
+ import o from "node:path";
7
+ import { Project as s, SyntaxKind as c } from "ts-morph";
8
+ //#region src/patterns/disable/api-keys/modifies/hooks.server.ts
9
+ function l(e) {
10
+ if (!a.existsSync(e)) return {
11
+ status: "success",
12
+ changed: !1
13
+ };
14
+ let t = a.readFileSync(e, "utf8"), n = new s().addSourceFileAtPath(e), r = n.getDescendantsOfKind(c.CallExpression).find((e) => e.getExpression().getText() === "handlePocketbase");
15
+ if (!r) return {
16
+ status: "success",
17
+ changed: !1
18
+ };
19
+ let [i] = r.getArguments();
20
+ if (!i || i.getKind() !== c.ObjectLiteralExpression) return {
21
+ status: "success",
22
+ changed: !1
23
+ };
24
+ let o = i.asKindOrThrow(c.ObjectLiteralExpression).getProperty("api");
25
+ if (!o || o.getKind() !== c.PropertyAssignment) return {
26
+ status: "success",
27
+ changed: !1
28
+ };
29
+ let l = o.getInitializer();
30
+ if (!l || l.getKind() !== c.ObjectLiteralExpression) return {
31
+ status: "success",
32
+ changed: !1
33
+ };
34
+ let u = l.getProperty("apiKeys");
35
+ return u ? (u.remove(), n.formatText(), n.saveSync(), {
36
+ status: "success",
37
+ changed: n.getFullText() !== t
38
+ }) : {
39
+ status: "success",
40
+ changed: !1
41
+ };
42
+ }
43
+ //#endregion
44
+ //#region src/patterns/disable/api-keys/modifies/nav-user.svelte.ts
45
+ function u(e) {
46
+ if (!a.existsSync(e)) return {
47
+ status: "success",
48
+ changed: !1
49
+ };
50
+ let t = a.readFileSync(e, "utf8");
51
+ if (!t.includes("/api-keys")) return {
52
+ status: "success",
53
+ changed: !1
54
+ };
55
+ let n = new i(t), o = !1, s = (e) => {
56
+ o || e((e) => {
57
+ let t = r(e, "API Keys", "@lucide/svelte/icons/key-round");
58
+ return t.wasRemoved && (o = !0), t.source;
59
+ });
60
+ };
61
+ return s((e) => n.modifyModuleScript(e)), o || s((e) => n.modifyScript(e)), o ? (a.writeFileSync(e, n.toString(), "utf8"), {
62
+ status: "success",
63
+ changed: !0
64
+ }) : {
65
+ status: "success",
66
+ changed: !1
67
+ };
68
+ }
69
+ //#endregion
70
+ //#region src/patterns/disable/api-keys/generate.runtime.ts
71
+ async function d(r) {
72
+ let i = e(r), a = [], s = (e) => {
73
+ e && a.push(e);
74
+ };
75
+ i.info("Reverting hooks.server.ts");
76
+ let c = o.join(r.root, "src", "hooks.server.ts");
77
+ s(n(c, l(c))), i.info("Reverting nav-user.svelte");
78
+ let d = o.join(r.root, "src", "lib", "components", "nav-user.svelte");
79
+ return s(n(d, u(d))), {
80
+ creates: [],
81
+ modifies: a,
82
+ deletes: [],
83
+ components: [],
84
+ packages: [],
85
+ collections: [],
86
+ collectionPatches: [],
87
+ collectionDrops: await t(["api_keys"], r)
88
+ };
89
+ }
90
+ //#endregion
91
+ export { d as generate };
92
+
93
+ //# sourceMappingURL=generate.runtime-D8DxU99S.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-D8DxU99S.js","names":[],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\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 const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\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":";;;;;;;;AAIA,SAAgB,EAAoB,GAAwC;AAC1E,KAAI,CAAC,EAAG,WAAW,EAAgB,CACjC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAiB,EAAG,aAAa,GAAiB,OAAO,EAEzD,IADU,IAAI,GAAS,CACF,oBAAoB,EAAgB,EAEzD,IAAW,EACd,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,mBAAmB;AACpE,KAAI,CAAC,EAAU,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAE3D,IAAM,CAAC,KAAY,EAAS,cAAc;AAC1C,KAAI,CAAC,KAAY,EAAS,SAAS,KAAK,EAAW,wBACjD,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAI9C,IAAM,IADa,EAAS,cAAc,EAAW,wBAAwB,CAClD,YAAY,MAAM;AAC7C,KAAI,CAAC,KAAW,EAAQ,SAAS,KAAK,EAAW,mBAC/C,QAAO;EAAE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CAJA,EACE,EAAoB,GAAiB,EAAoB,EAAgB,CAAC,CAC3E,EAED,EAAO,KAAK,4BAA4B;CACxC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,kBACD;AAKD,QAJA,EAAW,EAAoB,GAAa,EAAgB,EAAY,CAAC,CAAC,EAInE;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAVsB,MAAM,EAAwB,CAAC,WAAW,EAAE,EAAQ;EAW3E"}
@@ -0,0 +1,116 @@
1
+ import { n as e } from "./logger-BpgCb-ZG.js";
2
+ import { t } from "./shared-D9iYuKxV.js";
3
+ import { modifyOutcomeToFile as n } from "./modify-file-Bi-4GRwL.js";
4
+ import { i as r, o as i } from "./ts-morph-helpers-B0oxeDUU.js";
5
+ import { n as a } from "./env-DfA_NCKk.js";
6
+ import o from "node:fs";
7
+ import s from "node:path";
8
+ import { Project as c, QuoteKind as l, SyntaxKind as u } from "ts-morph";
9
+ //#region src/patterns/disable/payments/modifies/modify-nav-user.ts
10
+ function d(e) {
11
+ if (!o.existsSync(e)) return {
12
+ status: "success",
13
+ changed: !1
14
+ };
15
+ let t = o.readFileSync(e, "utf8");
16
+ if (!t.includes("/billing")) return {
17
+ status: "success",
18
+ changed: !1
19
+ };
20
+ let n = new i(t), a = !1, s = (e) => {
21
+ a || e((e) => {
22
+ let t = r(e, "Billing", "@lucide/svelte/icons/credit-card");
23
+ return t.wasRemoved && (a = !0), t.source;
24
+ });
25
+ };
26
+ return s((e) => n.modifyModuleScript(e)), a || s((e) => n.modifyScript(e)), a ? (o.writeFileSync(e, n.toString(), "utf8"), {
27
+ status: "success",
28
+ changed: !0
29
+ }) : {
30
+ status: "success",
31
+ changed: !1
32
+ };
33
+ }
34
+ //#endregion
35
+ //#region src/patterns/disable/payments/modifies/modify-user-signup.ts
36
+ function f(e) {
37
+ if (!o.existsSync(e)) return {
38
+ status: "success",
39
+ changed: !1
40
+ };
41
+ let t = o.readFileSync(e, "utf8");
42
+ if (!t.includes("linkStripeCustomer")) return {
43
+ status: "success",
44
+ changed: !1
45
+ };
46
+ let n = new c({ manipulationSettings: { quoteKind: l.Single } }).addSourceFileAtPath(e), r = n.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/stripe");
47
+ r && r.remove();
48
+ let i = n.getVariableStatement((e) => e.getDeclarations().some((e) => e.getName() === "linkStripeCustomer"));
49
+ i && i.remove();
50
+ let a = n.getDescendantsOfKind(u.CallExpression).filter((e) => e.getExpression().getText() === "linkStripeCustomer");
51
+ for (let e of a) {
52
+ let t = e.getFirstAncestorByKind(u.ExpressionStatement);
53
+ t && t.remove();
54
+ }
55
+ return n.formatText(), n.saveSync(), {
56
+ status: "success",
57
+ changed: n.getFullText() !== t
58
+ };
59
+ }
60
+ //#endregion
61
+ //#region src/patterns/disable/payments/generate.runtime.ts
62
+ async function p(r) {
63
+ let i = r.features.auth, o = e(r), c = [], l = (e) => {
64
+ e && c.push(e);
65
+ };
66
+ o.info("Stripping Stripe credentials from .env");
67
+ let u = [
68
+ {
69
+ type: "comment",
70
+ key: "Stripe credentials"
71
+ },
72
+ {
73
+ type: "var",
74
+ key: "STRIPE_SECRET_KEY"
75
+ },
76
+ {
77
+ type: "var",
78
+ key: "PUBLIC_STRIPE_PUBLISHABLE_KEY"
79
+ },
80
+ {
81
+ type: "var",
82
+ key: "STRIPE_WEBHOOK_SECRET"
83
+ },
84
+ {
85
+ type: "var",
86
+ key: "INTERNAL_JOB_SECRET"
87
+ }
88
+ ], p = s.join(r.root, ".env");
89
+ if (l(n(p, a(p, u))), i) {
90
+ o.info("Reverting nav-user.svelte");
91
+ let e = s.join(r.root, "src", "lib", "components", "nav-user.svelte");
92
+ l(n(e, d(e))), o.info("Reverting signup +page.server.ts");
93
+ let t = s.join(r.root, "src", "routes", "(public)", "signup", "+page.server.ts");
94
+ l(n(t, f(t)));
95
+ }
96
+ return {
97
+ creates: [],
98
+ modifies: c,
99
+ deletes: [],
100
+ components: [],
101
+ packages: [],
102
+ collections: [],
103
+ collectionPatches: [],
104
+ collectionDrops: await t(i ? [
105
+ "transactions",
106
+ "stripe_payment_methods",
107
+ "stripe_customers",
108
+ "stripe_prices",
109
+ "stripe_products"
110
+ ] : ["stripe_prices", "stripe_products"], r)
111
+ };
112
+ }
113
+ //#endregion
114
+ export { p as generate };
115
+
116
+ //# sourceMappingURL=generate.runtime-DPbHzukR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-DPbHzukR.js","names":[],"sources":["../../src/patterns/disable/payments/modifies/modify-nav-user.ts","../../src/patterns/disable/payments/modifies/modify-user-signup.ts","../../src/patterns/disable/payments/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/billing\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Billing\",\n \"@lucide/svelte/icons/credit-card\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyUserSignup(userSignupPath: string): ModifyOutcome {\n if (!fs.existsSync(userSignupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(userSignupPath, \"utf8\");\n if (!originalSource.includes(\"linkStripeCustomer\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n const stripeImport = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/stripe\");\n if (stripeImport) stripeImport.remove();\n\n const linkFn = sourceFile.getVariableStatement((s) =>\n s.getDeclarations().some((d) => d.getName() === \"linkStripeCustomer\"),\n );\n if (linkFn) linkFn.remove();\n\n const callStatements = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => ce.getExpression().getText() === \"linkStripeCustomer\");\n for (const call of callStatements) {\n const stmt = call.getFirstAncestorByKind(SyntaxKind.ExpressionStatement);\n if (stmt) stmt.remove();\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\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 { modifyEnvRemove, type EnvEdit } from \"../../../runtime/env\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyUserSignup } from \"./modifies/modify-user-signup\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const isAppMode = options.features.auth;\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(\"Stripping Stripe credentials from .env\");\n const envEdits: EnvEdit[] = [\n { type: \"comment\", key: \"Stripe credentials\" },\n { type: \"var\", key: \"STRIPE_SECRET_KEY\" },\n { type: \"var\", key: \"PUBLIC_STRIPE_PUBLISHABLE_KEY\" },\n { type: \"var\", key: \"STRIPE_WEBHOOK_SECRET\" },\n { type: \"var\", key: \"INTERNAL_JOB_SECRET\" },\n ];\n const envPath = path.join(options.root, \".env\");\n pushResult(modifyOutcomeToFile(envPath, modifyEnvRemove(envPath, envEdits)));\n\n if (isAppMode) {\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 signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"signup\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(userSignupPath, unmodifyUserSignup(userSignupPath)),\n );\n }\n\n const collectionNames = [\n \"transactions\",\n \"stripe_payment_methods\",\n \"stripe_customers\",\n \"stripe_prices\",\n \"stripe_products\",\n ];\n const collectionDrops = await planDropsForCollections(\n isAppMode ? collectionNames : [\"stripe_prices\", \"stripe_products\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgB,EAAgB,GAAoC;AAClE,KAAI,CAAC,EAAG,WAAW,EAAY,CAC7B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAS,EAAG,aAAa,GAAa,OAAO;AACnD,KAAI,CAAC,EAAO,SAAS,WAAW,CAC9B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAO,IAAI,EAAW,EAAO,EAC/B,IAAa,IAEX,KAAa,MAAgD;AAC7D,OACJ,GAAK,MAAQ;GACX,IAAM,IAAS,EACb,GACA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