@velastack/patterns 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{_layout-Dju9EYqa.js → _layout-xBzFhszN.js} +31 -13
- package/dist/chunks/_layout-xBzFhszN.js.map +1 -0
- package/dist/chunks/{generate.runtime-DGnXHELM.js → generate.runtime-B6FeCL5I.js} +2 -2
- package/dist/chunks/{generate.runtime-DGnXHELM.js.map → generate.runtime-B6FeCL5I.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DHJqOJTr.js → generate.runtime-Bv_16lWi.js} +2 -2
- package/dist/chunks/{generate.runtime-DHJqOJTr.js.map → generate.runtime-Bv_16lWi.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BEmSIAop.js → generate.runtime-C_SdcnRs.js} +2 -2
- package/dist/chunks/{generate.runtime-BEmSIAop.js.map → generate.runtime-C_SdcnRs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DWHoDisZ.js → generate.runtime-CzYArKUA.js} +2 -2
- package/dist/chunks/{generate.runtime-DWHoDisZ.js.map → generate.runtime-CzYArKUA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dtf3tF3-.js → generate.runtime-DLg2CKxQ.js} +96 -71
- package/dist/chunks/generate.runtime-DLg2CKxQ.js.map +1 -0
- package/dist/chunks/{generate.runtime-Cgam_XCc.js → generate.runtime-DaPA2NNL.js} +2 -2
- package/dist/chunks/{generate.runtime-Cgam_XCc.js.map → generate.runtime-DaPA2NNL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DvTbN-no.js → generate.runtime-Dfl-07VS.js} +134 -132
- package/dist/chunks/generate.runtime-Dfl-07VS.js.map +1 -0
- package/dist/chunks/test-setup-cZj1tqaf.js +176 -0
- package/dist/chunks/test-setup-cZj1tqaf.js.map +1 -0
- package/dist/chunks/{ui-Ct6YQuPw.js → ui-IkdkLwmB.js} +2 -2
- package/dist/chunks/{ui-Ct6YQuPw.js.map → ui-IkdkLwmB.js.map} +1 -1
- package/dist/chunks/write-result-C1GYInL8.js +499 -0
- package/dist/chunks/write-result-C1GYInL8.js.map +1 -0
- package/dist/index.js +194 -197
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/_layout-Dju9EYqa.js.map +0 -1
- package/dist/chunks/generate.runtime-Dtf3tF3-.js.map +0 -1
- package/dist/chunks/generate.runtime-DvTbN-no.js.map +0 -1
- package/dist/chunks/test-setup-CbwhAJT4.js +0 -176
- package/dist/chunks/test-setup-CbwhAJT4.js.map +0 -1
- package/dist/chunks/write-result-B5KFCqxw.js +0 -487
- package/dist/chunks/write-result-B5KFCqxw.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-CzYArKUA.js","names":["ADAPTER_STATIC_SPEC","InvalidArgumentError","getLogger","providerEnvVars","resolveProvider","suppliedProviderEnv","modifyEnv","modifyOutcomeToFile","packageName","META","envEditsFor","path","ADAPTER_STATIC","ADAPTER_STATIC$1","STATIC_ADAPTER_MESSAGE","usesStaticAdapter","res","resolveConfigTarget","root","decl","generate","options","logger","provider","creates","modifies","envVars","modifyEnvVarsFiles","envPath","envFile"],"sources":["../../src/patterns/enable/ai/generate.runtime.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { getLogger } from \"../../../core/logger\";\nimport { ADAPTER_STATIC as ADAPTER_STATIC_SPEC } from \"../../../core/constants\";\nimport {\n providerEnvVars,\n resolveProvider,\n suppliedProviderEnv,\n} from \"../../../core/providers\";\nimport { resolveConfigTarget } from \"../../../runtime/config-target\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { packageName } from \"../../../runtime/write-result\";\nimport { envEditsFor, META } from \"./generate\";\n\n// The config imports the package, not the versioned spec the constant installs.\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\n\nexport const STATIC_ADAPTER_MESSAGE = [\n `AI needs a server, and this project builds with ${ADAPTER_STATIC}.`,\n \"The chat endpoint streams each reply from the server with a private API key, which a static site cannot do.\",\n \"Switch to a server adapter first: `vela enable backend` moves the project to @sveltejs/adapter-node.\",\n].join(\"\\n\");\n\n/**\n * Whether the SvelteKit config the project builds with imports\n * adapter-static. A config that cannot be resolved does not count: the\n * pattern only refuses what it can see.\n */\nexport function usesStaticAdapter(root: string): boolean {\n const res = resolveConfigTarget(root);\n if (res.status !== \"resolved\") return false;\n return res.target.sourceFile\n .getImportDeclarations()\n .some((decl) => decl.getModuleSpecifierValue() === ADAPTER_STATIC);\n}\n\nexport async function generate(options: Options) {\n if (usesStaticAdapter(options.root)) {\n throw new InvalidArgumentError(STATIC_ADAPTER_MESSAGE);\n }\n\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n // SvelteKit 3 exposes only declared variables: `src/lib/server/ai.ts`\n // imports the provider's key from `$app/env/private`.\n logger.info(\"Declaring the API key in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, providerEnvVars(provider));\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n const envFile = modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\n );\n if (envFile) modifies.push(envFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAMY,IAAiBJ,EAAYR,CAAmB,GAEzCc,IAAyB;CACpC,mDAAmDF,EAAe;CAClE;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBG,EAAkB,GAAuB;CACvD,IAAMC,IAAMC,EAAoBC,CAAI;CAEpC,OADIF,EAAI,WAAW,cACZA,EAAI,OAAO,WACf,sBAAsB,CAAC,CACvB,MAAM,MAASG,EAAK,wBAAwB,MAAMP,CAAc;AACrE;AAEA,eAAsBQ,EAAS,GAAkB;CAC/C,IAAIL,EAAkBM,EAAQ,IAAI,GAChC,MAAM,IAAIpB,EAAqBa,CAAsB;CAGvD,IAAMQ,IAASpB,EAAUmB,CAAO,GAC1BE,IAAWnB,EAAgBK,GAAMY,CAAO,GACxCG,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAI1B,EAAO,KAAK,qCAAqC;CACjD,IAAMC,IAAUC,EAAmBN,EAAQ,MAAMlB,EAAgBoB,CAAQ,CAAC;CAI1E,AAHIG,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAC3CA,EAAQ,UAAQD,EAAS,KAAKC,EAAQ,MAAM,GAEhDJ,EAAO,KAAK,eAAe;CAC3B,IAAMM,IAAUjB,EAAK,KAAKU,EAAQ,MAAM,MAAM,GACxCQ,IAAUtB,EACdqB,GACAtB,EAAUsB,GAASlB,EAAYa,GAAUlB,EAAoBgB,CAAO,CAAC,CAAC,CACxE;CAGA,OAFIQ,KAASJ,EAAS,KAAKI,CAAO,GAE3B;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
2
|
import { a as t, r as n } from "./modify-file-CRZ_gMg0.js";
|
|
3
3
|
import { a as r, o as i, s as a, t as o } from "./config-target-DJbVHwHl.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { r as
|
|
4
|
+
import { r as s, t as c } from "./_layout-xBzFhszN.js";
|
|
5
|
+
import { _ as l, c as u, d, h as f, m as p, n as m, o as h, s as g, u as _ } from "./ts-morph-helpers-B4KZXP44.js";
|
|
6
|
+
import { r as v } from "./package-imports-CcIIHbp5.js";
|
|
7
7
|
import { t as y } from "./dedent-CCUOcPFW.js";
|
|
8
8
|
import { n as b } from "./compose-handle-Da7m6lV_.js";
|
|
9
9
|
import { t as x } from "./svelte-file-DfplF3BU.js";
|
|
@@ -44,8 +44,23 @@ function O(e) {
|
|
|
44
44
|
changed: !0
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
// src/patterns/disable/i18n/modifies/
|
|
47
|
+
// src/patterns/disable/i18n/modifies/prettierignore.ts
|
|
48
48
|
function k(e) {
|
|
49
|
+
if (!C.existsSync(e)) return {
|
|
50
|
+
status: "success",
|
|
51
|
+
changed: !1
|
|
52
|
+
};
|
|
53
|
+
let t = C.readFileSync(e, "utf8").split("\n"), n = t.findIndex((e, n) => e === "# Wuchale" && t[n + 1] === "src/locales/");
|
|
54
|
+
return n === -1 ? {
|
|
55
|
+
status: "success",
|
|
56
|
+
changed: !1
|
|
57
|
+
} : (t.splice(n, 2), n > 0 && t[n - 1] === "" && (t[n] ?? "") === "" && t.splice(n - 1, 1), C.writeFileSync(e, t.join("\n")), {
|
|
58
|
+
status: "success",
|
|
59
|
+
changed: !0
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// src/patterns/disable/i18n/modifies/vite-config.ts
|
|
63
|
+
function A(e) {
|
|
49
64
|
if (!C.existsSync(e)) return {
|
|
50
65
|
status: "success",
|
|
51
66
|
changed: !1
|
|
@@ -70,18 +85,18 @@ function k(e) {
|
|
|
70
85
|
}
|
|
71
86
|
if (!e) break;
|
|
72
87
|
}
|
|
73
|
-
return
|
|
88
|
+
return _(n, "wuchale/vite"), h(n), n.saveSync(), {
|
|
74
89
|
status: "success",
|
|
75
90
|
changed: n.getFullText() !== t
|
|
76
91
|
};
|
|
77
92
|
}
|
|
78
93
|
// src/patterns/disable/i18n/modifies/locales-alias.ts
|
|
79
|
-
var
|
|
94
|
+
var j = {
|
|
80
95
|
notFound: "No SvelteKit config to revert.",
|
|
81
96
|
failed: "Remove the $locales alias from the sveltekit() arg in vite.config by hand."
|
|
82
97
|
};
|
|
83
|
-
function
|
|
84
|
-
let t = i(e,
|
|
98
|
+
function M(e) {
|
|
99
|
+
let t = i(e, j);
|
|
85
100
|
if (t.status === "not-found") return {
|
|
86
101
|
filePath: t.filePath,
|
|
87
102
|
outcome: {
|
|
@@ -103,29 +118,29 @@ function j(e) {
|
|
|
103
118
|
};
|
|
104
119
|
}
|
|
105
120
|
// src/patterns/disable/i18n/modifies/locales-module.ts
|
|
106
|
-
function
|
|
121
|
+
function N(e) {
|
|
107
122
|
let t = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), n = RegExp(`^[$#]locales/${t}(\\.js)?$`);
|
|
108
123
|
return (e) => n.test(e);
|
|
109
124
|
}
|
|
110
125
|
// src/patterns/disable/i18n/modifies/hooks.server.ts
|
|
111
|
-
var
|
|
126
|
+
var P = "handleWuchale", F = y`
|
|
112
127
|
Take handleWuchale out of the exported handle in src/hooks.server.ts, then
|
|
113
128
|
remove its declaration, the loadLocales(...) calls and the wuchale and
|
|
114
129
|
#locales imports.
|
|
115
|
-
`,
|
|
130
|
+
`, I = [
|
|
116
131
|
"wuchale/load-utils/server",
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
132
|
+
N("main.url"),
|
|
133
|
+
N("data"),
|
|
134
|
+
N("main.loader.server.svelte"),
|
|
135
|
+
N("js.loader.server")
|
|
121
136
|
];
|
|
122
|
-
function
|
|
137
|
+
function L(e) {
|
|
123
138
|
if (!C.existsSync(e)) return {
|
|
124
139
|
status: "success",
|
|
125
140
|
changed: !1
|
|
126
141
|
};
|
|
127
142
|
let t = C.readFileSync(e, "utf8");
|
|
128
|
-
if (!t.includes(
|
|
143
|
+
if (!t.includes(P) && !t.includes("loadLocales(")) return {
|
|
129
144
|
status: "success",
|
|
130
145
|
changed: !1
|
|
131
146
|
};
|
|
@@ -138,53 +153,53 @@ function I(e) {
|
|
|
138
153
|
if (!e) break;
|
|
139
154
|
e.remove();
|
|
140
155
|
}
|
|
141
|
-
if (b(n,
|
|
156
|
+
if (b(n, P).status === "unsupported") return {
|
|
142
157
|
status: "failed",
|
|
143
|
-
message:
|
|
158
|
+
message: F
|
|
144
159
|
};
|
|
145
|
-
|
|
146
|
-
for (let e of
|
|
147
|
-
return
|
|
160
|
+
f(n, P);
|
|
161
|
+
for (let e of I) _(n, e);
|
|
162
|
+
return d(n, "@sveltejs/kit/hooks", "sequence"), d(n, "@sveltejs/kit/hooks", "Handle"), d(n, "@sveltejs/kit", "Handle"), h(n), m(n), n.saveSync(), {
|
|
148
163
|
status: "success",
|
|
149
164
|
changed: n.getFullText() !== t
|
|
150
165
|
};
|
|
151
166
|
}
|
|
152
167
|
// src/patterns/disable/i18n/modifies/hooks.ts
|
|
153
|
-
var
|
|
168
|
+
var R = "rerouteDeLocalize", z = y`
|
|
154
169
|
Take rerouteDeLocalize out of the exported reroute in src/hooks.ts, then
|
|
155
170
|
remove its declaration and the wuchale and #locales imports.
|
|
156
|
-
`,
|
|
171
|
+
`, B = [
|
|
157
172
|
"wuchale/url",
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
],
|
|
161
|
-
function
|
|
173
|
+
N("main.url"),
|
|
174
|
+
N("data")
|
|
175
|
+
], V = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*rerouteDeLocalize\(\s*url\.pathname\s*\)$/, H = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*rerouteDeLocalize\(\s*negotiateReroute\(\s*url\.pathname\s*\)\s*\)$/;
|
|
176
|
+
function U(e) {
|
|
162
177
|
if (!C.existsSync(e)) return {
|
|
163
178
|
status: "success",
|
|
164
179
|
changed: !1
|
|
165
180
|
};
|
|
166
181
|
let t = C.readFileSync(e, "utf8");
|
|
167
|
-
if (!t.includes(
|
|
182
|
+
if (!t.includes(R)) return {
|
|
168
183
|
status: "success",
|
|
169
184
|
changed: !1
|
|
170
185
|
};
|
|
171
186
|
let n = new T({
|
|
172
187
|
compilerOptions: { allowJs: !0 },
|
|
173
188
|
manipulationSettings: { quoteKind: E.Single }
|
|
174
|
-
}).addSourceFileAtPath(e), r = n.getVariableDeclaration(
|
|
175
|
-
return n.getStatements().filter((e) => e !== r && e !== s && e.getText().includes(
|
|
189
|
+
}).addSourceFileAtPath(e), r = n.getVariableDeclaration(R)?.getFirstAncestorByKind(D.VariableStatement), i = n.getVariableDeclaration("reroute"), a = i?.getInitializer()?.getText() ?? "", o = H.test(a), s = o || V.test(a) ? i?.getFirstAncestorByKind(D.VariableStatement) : void 0;
|
|
190
|
+
return n.getStatements().filter((e) => e !== r && e !== s && e.getText().includes(R)).length > 0 ? {
|
|
176
191
|
status: "failed",
|
|
177
|
-
message:
|
|
178
|
-
} : (o ? i?.setInitializer("({ url }) => negotiateReroute(url.pathname)") : s &&
|
|
192
|
+
message: z
|
|
193
|
+
} : (o ? i?.setInitializer("({ url }) => negotiateReroute(url.pathname)") : s && f(n, "reroute"), f(n, R), u(n, B), g(n) ? (C.writeFileSync(e, "", "utf8"), {
|
|
179
194
|
status: "success",
|
|
180
195
|
changed: !0
|
|
181
|
-
}) : (
|
|
196
|
+
}) : (h(n), m(n), n.saveSync(), {
|
|
182
197
|
status: "success",
|
|
183
198
|
changed: n.getFullText() !== t
|
|
184
199
|
}));
|
|
185
200
|
}
|
|
186
201
|
// src/patterns/disable/i18n/modifies/app-html.ts
|
|
187
|
-
function
|
|
202
|
+
function W(e) {
|
|
188
203
|
if (!C.existsSync(e)) return {
|
|
189
204
|
status: "success",
|
|
190
205
|
changed: !1
|
|
@@ -199,7 +214,7 @@ function U(e) {
|
|
|
199
214
|
});
|
|
200
215
|
}
|
|
201
216
|
// src/patterns/disable/i18n/modifies/+layout.ts
|
|
202
|
-
var
|
|
217
|
+
var G = y`
|
|
203
218
|
src/routes/+layout.ts still loads wuchale locales. Remove these from it:
|
|
204
219
|
|
|
205
220
|
import { browser } from '$app/env';
|
|
@@ -209,15 +224,15 @@ var W = y`
|
|
|
209
224
|
import '#locales/js.loader.js';
|
|
210
225
|
|
|
211
226
|
and the loadLocale(...) call inside load().
|
|
212
|
-
`,
|
|
227
|
+
`, K = [N("main.loader.svelte"), N("js.loader")], q = [
|
|
213
228
|
(e) => /^\$app\/env(ironment)?$/.test(e),
|
|
214
229
|
"wuchale/load-utils",
|
|
215
|
-
|
|
230
|
+
N("main.url")
|
|
216
231
|
];
|
|
217
|
-
function
|
|
232
|
+
function J(e) {
|
|
218
233
|
return e.replace(/["']/g, "'").replace(/\s+/g, "");
|
|
219
234
|
}
|
|
220
|
-
function
|
|
235
|
+
function Y(e) {
|
|
221
236
|
if (!C.existsSync(e)) return {
|
|
222
237
|
status: "success",
|
|
223
238
|
changed: !1
|
|
@@ -232,23 +247,23 @@ function J(e) {
|
|
|
232
247
|
manipulationSettings: { quoteKind: E.Single }
|
|
233
248
|
}).addSourceFileAtPath(e), r = n.getVariableStatements().find((e) => e.getDeclarations().some((e) => e.getName() === "load")) ?? n.getFunction("load");
|
|
234
249
|
if (r) {
|
|
235
|
-
if (
|
|
250
|
+
if (J(r.getText()) !== J(c)) return {
|
|
236
251
|
status: "failed",
|
|
237
|
-
message:
|
|
252
|
+
message: G
|
|
238
253
|
};
|
|
239
|
-
|
|
254
|
+
p(n, r);
|
|
240
255
|
}
|
|
241
|
-
for (let e of
|
|
242
|
-
return
|
|
256
|
+
for (let e of K) _(n, e);
|
|
257
|
+
return u(n, q), g(n) ? (C.writeFileSync(e, "", "utf8"), {
|
|
243
258
|
status: "success",
|
|
244
259
|
changed: !0
|
|
245
|
-
}) : (
|
|
260
|
+
}) : (h(n), m(n), n.saveSync(), {
|
|
246
261
|
status: "success",
|
|
247
262
|
changed: n.getFullText() !== t
|
|
248
263
|
});
|
|
249
264
|
}
|
|
250
265
|
// src/patterns/disable/i18n/modifies/root-layout.svelte.ts
|
|
251
|
-
function
|
|
266
|
+
function X(e) {
|
|
252
267
|
if (!C.existsSync(e)) return {
|
|
253
268
|
status: "success",
|
|
254
269
|
changed: !1
|
|
@@ -260,8 +275,8 @@ function Y(e) {
|
|
|
260
275
|
};
|
|
261
276
|
let n = x.fromPath(e);
|
|
262
277
|
n.modifyScript((e) => {
|
|
263
|
-
let { source: t } =
|
|
264
|
-
|
|
278
|
+
let { source: t } = l(e, (e) => {
|
|
279
|
+
_(e, S("components/language-select.svelte")), m(e);
|
|
265
280
|
});
|
|
266
281
|
return t;
|
|
267
282
|
});
|
|
@@ -272,38 +287,48 @@ function Y(e) {
|
|
|
272
287
|
};
|
|
273
288
|
}
|
|
274
289
|
// src/patterns/disable/i18n/generate.runtime.ts
|
|
275
|
-
async function
|
|
276
|
-
let a = e(i),
|
|
277
|
-
e &&
|
|
290
|
+
async function Z(i) {
|
|
291
|
+
let a = e(i), c = [], l = [], u = (e) => {
|
|
292
|
+
e && c.push(e);
|
|
278
293
|
};
|
|
279
294
|
a.info("Reverting vite.config");
|
|
280
|
-
let
|
|
281
|
-
|
|
282
|
-
let
|
|
283
|
-
|
|
284
|
-
let
|
|
285
|
-
|
|
286
|
-
let
|
|
287
|
-
|
|
288
|
-
let
|
|
289
|
-
|
|
295
|
+
let d = r(i.root, o) ?? w.join(i.root, o[0]);
|
|
296
|
+
u(n(d, A(d))), a.info("Removing #locales from package.json imports");
|
|
297
|
+
let f = v(i.root, Object.keys(s), s);
|
|
298
|
+
u(n(f.filePath, f.outcome)), a.info("Reverting the legacy $locales alias");
|
|
299
|
+
let p = M(i.root);
|
|
300
|
+
u(n(p.filePath, p.outcome)), a.info("Reverting hooks.server.ts");
|
|
301
|
+
let m = w.join(i.root, "src", "hooks.server.ts"), h = t(m, L(m));
|
|
302
|
+
u(h.modify), h.delete && l.push(h.delete), a.info("Reverting hooks.ts");
|
|
303
|
+
let g = w.join(i.root, "src", "hooks.ts"), _ = t(g, U(g));
|
|
304
|
+
u(_.modify), _.delete && l.push(_.delete), a.info("Reverting app.html");
|
|
290
305
|
let y = w.join(i.root, "src", "app.html");
|
|
291
|
-
|
|
292
|
-
let b = w.join(i.root, "src", "routes", "+layout.ts"), x = t(b,
|
|
293
|
-
|
|
306
|
+
u(n(y, W(y))), a.info("Reverting root +layout.ts");
|
|
307
|
+
let b = w.join(i.root, "src", "routes", "+layout.ts"), x = t(b, Y(b));
|
|
308
|
+
u(x.modify), x.delete && l.push(x.delete), a.info("Reverting root layout language select");
|
|
294
309
|
let S = [
|
|
295
310
|
w.join(i.root, "src", "routes", "(public)", "root-layout.svelte"),
|
|
296
311
|
w.join(i.root, "src", "routes", "root-layout.svelte"),
|
|
297
312
|
w.join(i.root, "src", "routes", "(public)", "+layout.svelte"),
|
|
298
313
|
w.join(i.root, "src", "routes", "+layout.svelte")
|
|
299
314
|
];
|
|
300
|
-
for (let e of S) C.existsSync(e) &&
|
|
315
|
+
for (let e of S) C.existsSync(e) && u(n(e, X(e)));
|
|
301
316
|
a.info("Reverting .gitignore");
|
|
302
317
|
let T = w.join(i.root, ".gitignore");
|
|
303
|
-
|
|
318
|
+
u(n(T, O(T))), a.info("Reverting .prettierignore");
|
|
319
|
+
let E = w.join(i.root, ".prettierignore");
|
|
320
|
+
u(n(E, k(E))), a.info("Removing wuchale's loaders from src/locales");
|
|
321
|
+
let D = w.join(i.root, "src", "locales");
|
|
322
|
+
if (C.existsSync(D)) for (let e of C.readdirSync(D, { withFileTypes: !0 })) e.isFile() && e.name.endsWith(".js") && l.push({
|
|
323
|
+
path: w.join(D, e.name),
|
|
324
|
+
language: "js",
|
|
325
|
+
content: "",
|
|
326
|
+
status: "success"
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
304
329
|
creates: [],
|
|
305
|
-
modifies:
|
|
306
|
-
deletes:
|
|
330
|
+
modifies: c,
|
|
331
|
+
deletes: l,
|
|
307
332
|
components: [],
|
|
308
333
|
packages: [],
|
|
309
334
|
collections: [],
|
|
@@ -311,6 +336,6 @@ async function X(i) {
|
|
|
311
336
|
collectionDrops: []
|
|
312
337
|
};
|
|
313
338
|
}
|
|
314
|
-
export {
|
|
339
|
+
export { Z as generate };
|
|
315
340
|
|
|
316
|
-
//# sourceMappingURL=generate.runtime-
|
|
341
|
+
//# sourceMappingURL=generate.runtime-DLg2CKxQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-DLg2CKxQ.js","names":["FAILURE_HINT","I18N_MODULES","FAILURE_HINT","getLogger","revertOutcomeToFile","modifyOutcomeToFile","probeFirstExisting","resolveConfigTarget","saveTarget","VITE_CONFIG_CANDIDATES","LOCALES_IMPORTS","LOAD_STATEMENT","withInMemoryScript","pruneUnusedImports","removeTopLevelStatementByIdentifier","removeStatementWithComments","ensureBlankLineAfterImports","formatLikeSource","isEffectivelyEmpty","removeImportByModuleSpecifier","removePackageImports","dedent","removeHandle","SvelteFile","libModule","fs","path","unmodifyGitignore","gitignorePath","original","lines","out","i","line","j","hasWuchale","updated","unmodifyPrettierignore","filePath","at","index","unmodifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","removed","arr","SyntaxKind","el","HINTS","unmodifyLocalesAlias","res","root","aliasProp","target","aliasObj","locales","p","localesModule","escaped","name","pattern","specifier","I18N_HANDLE","FAILURE_HINT$2","I18N_MODULES$1","unmodifyHooksServerI18n","hooksServerPath","stmt","s","moduleSpecifier","removeNamedImportIfUnused","DELOCALIZE_HELPER","FAILURE_HINT$1","I18N_MODULES","I18N_ONLY_REROUTE","COMPOSED_REROUTE","unmodifyHooksI18n","hooksPath","helperStatement","rerouteDecl","initText","composed","rerouteStatement","unmodifyAppHtml","appHtmlPath","FAILURE_HINT","SIDE_EFFECT_MODULES","BINDING_MODULES","normalize","source","unmodifyRootLayoutI18n","layoutPath","loadStatement","d","unmodifyRootLayoutLanguageSelect","file","sf","generate","logger","options","modifies","deletes","pushResult","imports","alias","hooksServerRevert","hooksRevert","layoutRevert","rootLayoutCandidates","candidate","prettierignorePath","localesDir","entry"],"sources":["../../src/patterns/disable/i18n/modifies/gitignore.ts","../../src/patterns/disable/i18n/modifies/prettierignore.ts","../../src/patterns/disable/i18n/modifies/vite-config.ts","../../src/patterns/disable/i18n/modifies/locales-alias.ts","../../src/patterns/disable/i18n/modifies/locales-module.ts","../../src/patterns/disable/i18n/modifies/hooks.server.ts","../../src/patterns/disable/i18n/modifies/hooks.ts","../../src/patterns/disable/i18n/modifies/app-html.ts","../../src/patterns/disable/i18n/modifies/+layout.ts","../../src/patterns/disable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/disable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (!original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const lines = original.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === \"# Wuchale\") {\n let j = i + 1;\n let hasWuchale = false;\n while (j < lines.length && lines[j].trim() !== \"\") {\n if (lines[j] === \"src/locales/.wuchale\") {\n hasWuchale = true;\n }\n j++;\n }\n if (hasWuchale) {\n i = j;\n continue;\n }\n }\n if (line === \"src/locales/.wuchale\") continue;\n out.push(line);\n }\n\n let updated = out.join(\"\\n\");\n updated = updated.replace(/\\n{3,}/g, \"\\n\\n\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n LOCALES_ENTRY,\n PRETTIERIGNORE_HEADER,\n} from \"../../../enable/i18n/modifies/prettierignore\";\n\n/** Removes the block enable-i18n appended; an entry the project wrote itself stays. */\nexport function unmodifyPrettierignore(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n const lines = original.split(\"\\n\");\n const at = lines.findIndex(\n (line, index) =>\n line === PRETTIERIGNORE_HEADER && lines[index + 1] === LOCALES_ENTRY,\n );\n if (at === -1) {\n return { status: \"success\", changed: false };\n }\n\n lines.splice(at, 2);\n // The blank line that set the block apart goes with it.\n if (at > 0 && lines[at - 1] === \"\" && (lines[at] ?? \"\") === \"\") {\n lines.splice(at - 1, 1);\n }\n fs.writeFileSync(filePath, lines.join(\"\\n\"));\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** Remove `wuchale()` from the Vite plugins and its import. */\nexport function unmodifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(viteConfigPath, \"utf8\");\n if (!original.includes(\"wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n // One removal at a time: manipulating the tree invalidates sibling nodes.\n for (;;) {\n let removed = false;\n for (const arr of sourceFile.getDescendantsOfKind(\n SyntaxKind.ArrayLiteralExpression,\n )) {\n const index = arr\n .getElements()\n .findIndex((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n if (index >= 0) {\n arr.removeElement(index);\n removed = true;\n break;\n }\n }\n if (!removed) break;\n }\n\n removeImportByModuleSpecifier(sourceFile, \"wuchale/vite\");\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import { SyntaxKind } from \"ts-morph\";\nimport {\n resolveConfigTarget,\n saveTarget,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst HINTS = {\n notFound: \"No SvelteKit config to revert.\",\n failed:\n \"Remove the $locales alias from the sveltekit() arg in vite.config by hand.\",\n};\n\n/**\n * Remove the `$locales` alias enable-i18n wrote before SvelteKit 3, which\n * `sv migrate sveltekit-3` moves into the inline `sveltekit({...})` arg;\n * `alias` goes too once it is empty. Projects enabled since then map\n * `#locales/*` in package.json `imports` instead.\n */\nexport function unmodifyLocalesAlias(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, HINTS);\n // Nothing to revert in a project without a config.\n if (res.status === \"not-found\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n if (res.status === \"failed\") {\n return {\n filePath: res.filePath,\n outcome: { status: \"failed\", message: res.message },\n };\n }\n\n const { target } = res;\n const aliasProp = target.configObject\n .getProperty(\"alias\")\n ?.asKind(SyntaxKind.PropertyAssignment);\n const aliasObj = aliasProp\n ?.getInitializer()\n ?.asKind(SyntaxKind.ObjectLiteralExpression);\n const locales = aliasObj\n ?.getProperties()\n .find((p) => p.getText().replace(/['\"]/g, \"\").startsWith(\"$locales\"));\n if (aliasProp && aliasObj && locales) {\n locales.remove();\n if (aliasObj.getProperties().length === 0) aliasProp.remove();\n }\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n","/**\n * Matches an import of wuchale's `src/locales/<name>.js` the way enable-i18n\n * writes it (`#locales/main.url.js`), and the `$locales/main.url` alias form\n * it wrote before SvelteKit 3, so disabling works on either.\n */\nexport function localesModule(name: string): (specifier: string) => boolean {\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const pattern = new RegExp(`^[$#]locales/${escaped}(\\\\.js)?$`);\n return (specifier) => pattern.test(specifier);\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n removeNamedImportIfUnused,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst I18N_HANDLE = \"handleWuchale\";\nconst FAILURE_HINT = dedent`\n Take handleWuchale out of the exported handle in src/hooks.server.ts, then\n remove its declaration, the loadLocales(...) calls and the wuchale and\n #locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/load-utils/server\",\n localesModule(\"main.url\"),\n localesModule(\"data\"),\n localesModule(\"main.loader.server.svelte\"),\n localesModule(\"js.loader.server\"),\n];\n\n/**\n * Undo `modifyHooksServerI18n`: drop the locale bootstrap, the wuchale handle\n * and its imports, and unwrap `sequence(handleWuchale, ...)`. A file that\n * enable-i18n created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerI18n(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (!original.includes(I18N_HANDLE) && !original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // loadLocales(...) bootstrap calls, one at a time (removal invalidates siblings).\n for (;;) {\n const stmt = sourceFile\n .getStatements()\n .find(\n (s) =>\n s.getKind() === SyntaxKind.ExpressionStatement &&\n /^loadLocales\\s*\\(/.test(s.getText()),\n );\n if (!stmt) break;\n stmt.remove();\n }\n\n // `export const handle = handleWuchale` goes altogether; a sequence loses\n // the argument, or unwraps to the handle it composed with.\n const removed = removeHandle(sourceFile, I18N_HANDLE);\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, I18N_HANDLE);\n for (const moduleSpecifier of I18N_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"Handle\");\n // A project from before SvelteKit 3 imports it from the package root.\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit\", \"Handle\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst DELOCALIZE_HELPER = \"rerouteDeLocalize\";\n\nconst FAILURE_HINT = dedent`\n Take rerouteDeLocalize out of the exported reroute in src/hooks.ts, then\n remove its declaration and the wuchale and #locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/url\",\n localesModule(\"main.url\"),\n localesModule(\"data\"),\n];\n\n/** The two reroutes `modifyHooksI18n` writes: on its own, and composed. */\nconst I18N_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*url\\.pathname\\s*\\)$/;\nconst COMPOSED_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)\\s*\\)$/;\n\n/**\n * Undo `modifyHooksI18n`: drop the de-localizer and its imports, leaving the\n * negotiation reroute it may have been composed with. A file that enable-i18n\n * created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (!original.includes(DELOCALIZE_HELPER)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const helperStatement = sourceFile\n .getVariableDeclaration(DELOCALIZE_HELPER)\n ?.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n const initText = rerouteDecl?.getInitializer()?.getText() ?? \"\";\n const composed = COMPOSED_REROUTE.test(initText);\n const rerouteStatement =\n composed || I18N_ONLY_REROUTE.test(initText)\n ? rerouteDecl?.getFirstAncestorByKind(SyntaxKind.VariableStatement)\n : undefined;\n\n // Anything else reading the de-localizer is code enable-i18n did not write,\n // so undoing it is the developer's call.\n const otherReaders = sourceFile\n .getStatements()\n .filter(\n (s) =>\n s !== helperStatement &&\n s !== rerouteStatement &&\n s.getText().includes(DELOCALIZE_HELPER),\n );\n if (otherReaders.length > 0) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n if (composed) {\n // content-negotiation's reroute is underneath; it stays.\n rerouteDecl?.setInitializer(\"({ url }) => negotiateReroute(url.pathname)\");\n } else if (rerouteStatement) {\n removeTopLevelStatementByIdentifier(sourceFile, \"reroute\");\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, DELOCALIZE_HELPER);\n pruneUnusedImports(sourceFile, I18N_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty hooks.ts into a\n // delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(hooksPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Put a real language back. `%sveltekit.lang%` is not a SvelteKit\n * placeholder; only the wuchale hook replaced it, so without that hook it\n * would be served literally.\n */\nexport function unmodifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n const updated = original.replace(\n /lang\\s*=\\s*(?:\"%sveltekit\\.lang%\"|'%sveltekit\\.lang%')/g,\n 'lang=\"en\"',\n );\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(appHtmlPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type Statement } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { LOAD_STATEMENT } from \"../../../enable/i18n/modifies/+layout\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeImportByModuleSpecifier,\n removeStatementWithComments,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { localesModule } from \"./locales-module\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.ts still loads wuchale locales. Remove these from it:\n\n import { browser } from '$app/env';\n import { loadLocale } from 'wuchale/load-utils';\n import { getLocale } from '#locales/main.url.js';\n import '#locales/main.loader.svelte.js';\n import '#locales/js.loader.js';\n\n and the loadLocale(...) call inside load().\n`;\n\nconst SIDE_EFFECT_MODULES = [\n localesModule(\"main.loader.svelte\"),\n localesModule(\"js.loader\"),\n];\nconst BINDING_MODULES: ModuleMatch[] = [\n // `$app/env`, or the module it replaced before SvelteKit 3.\n (specifier) => /^\\$app\\/env(ironment)?$/.test(specifier),\n \"wuchale/load-utils\",\n localesModule(\"main.url\"),\n];\n\nfunction normalize(source: string): string {\n return source.replace(/[\"']/g, \"'\").replace(/\\s+/g, \"\");\n}\n\n/**\n * Undo `ensureRootLayoutI18n`: drop the wuchale load and its imports, leaving\n * whatever else the file holds. A file enable-i18n wrote whole comes out\n * empty, for the caller to delete.\n */\nexport function unmodifyRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(\"loadLocale\") && !/[$#]locales\\//.test(original)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n const loadStatement: Statement | undefined =\n sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"load\")) ??\n sourceFile.getFunction(\"load\");\n\n if (loadStatement) {\n // A load that grew code of its own needs a hand; only the one enable-i18n\n // wrote is safe to take out wholesale.\n if (normalize(loadStatement.getText()) !== normalize(LOAD_STATEMENT)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n removeStatementWithComments(sourceFile, loadStatement);\n }\n\n for (const moduleSpecifier of SIDE_EFFECT_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n pruneUnusedImports(sourceFile, BINDING_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty +layout.ts into\n // a delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(layoutPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\n/** Take the language select (and the nav item enable-i18n wrapped it in) back out. */\nexport function unmodifyRootLayoutLanguageSelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(\n sf,\n libModule(\"components/language-select.svelte\"),\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n let updated = file.toString();\n updated = updated.replace(\n /[ \\t]*<Navbar\\.Item>\\s*<LanguageSelect\\s*\\/>\\s*<\\/Navbar\\.Item>[ \\t]*\\r?\\n?/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<LanguageSelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { unmodifyGitignore } from \"./modifies/gitignore\";\nimport { unmodifyPrettierignore } from \"./modifies/prettierignore\";\nimport { unmodifyViteConfig } from \"./modifies/vite-config\";\nimport { unmodifyLocalesAlias } from \"./modifies/locales-alias\";\nimport { removePackageImports } from \"../../../runtime/package-imports\";\nimport { LOCALES_IMPORTS } from \"../../enable/i18n/modifies/package-imports\";\nimport { unmodifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { unmodifyHooksI18n } from \"./modifies/hooks\";\nimport { unmodifyAppHtml } from \"./modifies/app-html\";\nimport { unmodifyRootLayoutI18n } from \"./modifies/+layout\";\nimport { unmodifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, unmodifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Removing #locales from package.json imports\");\n // Only while it still maps where enable-i18n pointed it.\n const imports = removePackageImports(\n options.root,\n Object.keys(LOCALES_IMPORTS),\n LOCALES_IMPORTS,\n );\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n // A project enabled before SvelteKit 3 has the `$locales` alias instead,\n // moved into the sveltekit() arg by `vela migrate sveltekit-3`.\n logger.info(\"Reverting the legacy $locales alias\");\n const alias = unmodifyLocalesAlias(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.outcome));\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n // enable-i18n may have created it; emptied, it goes.\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerI18n(hooksServerPath),\n );\n pushResult(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n logger.info(\"Reverting hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n // The de-localizing reroute may be all it holds; emptied, it goes.\n const hooksRevert = revertOutcomeToFile(\n hooksPath,\n unmodifyHooksI18n(hooksPath),\n );\n pushResult(hooksRevert.modify);\n if (hooksRevert.delete) deletes.push(hooksRevert.delete);\n\n logger.info(\"Reverting app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, unmodifyAppHtml(appHtmlPath)));\n\n logger.info(\"Reverting root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n // enable-i18n may have written the whole file; emptied, it goes.\n const layoutRevert = revertOutcomeToFile(\n layoutPath,\n unmodifyRootLayoutI18n(layoutPath),\n );\n pushResult(layoutRevert.modify);\n if (layoutRevert.delete) deletes.push(layoutRevert.delete);\n\n logger.info(\"Reverting root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n for (const candidate of rootLayoutCandidates) {\n if (!fs.existsSync(candidate)) continue;\n pushResult(\n modifyOutcomeToFile(\n candidate,\n unmodifyRootLayoutLanguageSelect(candidate),\n ),\n );\n }\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, unmodifyGitignore(gitignorePath)),\n );\n\n logger.info(\"Reverting .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n unmodifyPrettierignore(prettierignorePath),\n ),\n );\n\n // wuchale's loaders import the packages this uninstalls, and without the\n // .prettierignore block they would fail the project's lint. The catalogs\n // (.po) beside them are the translations, and stay.\n logger.info(\"Removing wuchale's loaders from src/locales\");\n const localesDir = path.join(options.root, \"src\", \"locales\");\n if (fs.existsSync(localesDir)) {\n for (const entry of fs.readdirSync(localesDir, { withFileTypes: true })) {\n if (!entry.isFile() || !entry.name.endsWith(\".js\")) continue;\n deletes.push({\n path: path.join(localesDir, entry.name),\n language: \"js\",\n content: \"\",\n status: \"success\",\n });\n }\n }\n\n return {\n creates: [],\n modifies,\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;AAGA,SAAgB2B,EAAkB,GAAsC;CACtE,IAAI,CAACF,EAAG,WAAWG,CAAa,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAe,MAAM;CACtD,IAAI,CAACC,EAAS,SAAS,sBAAsB,GAC3C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAQD,EAAS,MAAM,IAAI,GAC3BE,IAAgB,CAAC;CACvB,KAAK,IAAIC,IAAI,GAAGA,IAAIF,EAAM,QAAQ,KAAK;EACrC,IAAMG,IAAOH,EAAME;EACnB,IAAIC,MAAS,aAAa;GACxB,IAAIC,IAAIF,IAAI,GACRG,IAAa;GACjB,OAAOD,IAAIJ,EAAM,UAAUA,EAAMI,EAAE,CAAC,KAAK,MAAM,KAI7C,AAHIJ,EAAMI,OAAO,2BACf,IAAa,KAEf;GAEF,IAAIC,GAAY;IACd,IAAID;IACJ;GACF;EACF;EACA,AAAID,MAAS,0BACbF,EAAI,KAAKE,CAAI;CACf;CAEA,IAAIG,IAAUL,EAAI,KAAK,IAAI;CAQ3B,OAPA,IAAUK,EAAQ,QAAQ,WAAW,MAAM,GAEvCA,MAAYP,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7CJ,EAAG,cAAcG,GAAeQ,CAAO,GAChC;EAAE,QAAQ;EAAW,SAAS;CAAK;AA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AAMA,EAAM,KAAK,SAAS,KAAK,KACjDX,EAAQ,KAAK;EACX,MAAM7E,EAAK,KAAKuF,GAAYC,EAAM,IAAI;EACtC,UAAU;EACV,SAAS;EACT,QAAQ;CACV,CAAC;CAIL,OAAO;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -6,7 +6,7 @@ import { t as a } from "./dedent-CCUOcPFW.js";
|
|
|
6
6
|
import { n as o } from "./compose-handle-Da7m6lV_.js";
|
|
7
7
|
import { c as s, m as c, n as l, o as u } from "./ts-morph-helpers-B4KZXP44.js";
|
|
8
8
|
import { r as d, t as f } from "./lib-specifier-C3M0WTev.js";
|
|
9
|
-
import { a as p, l as m, s as h } from "./test-setup-
|
|
9
|
+
import { a as p, l as m, s as h } from "./test-setup-cZj1tqaf.js";
|
|
10
10
|
import { t as g } from "./env-vars-CUh4mLM_.js";
|
|
11
11
|
import { t as _ } from "./env-vars-T3_7JNSg.js";
|
|
12
12
|
import { unmodifyEnvVarsFiles as v } from "./env-vars-CVn2076k.js";
|
|
@@ -149,4 +149,4 @@ async function P(a) {
|
|
|
149
149
|
}
|
|
150
150
|
export { P as generate };
|
|
151
151
|
|
|
152
|
-
//# sourceMappingURL=generate.runtime-
|
|
152
|
+
//# sourceMappingURL=generate.runtime-DaPA2NNL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-Cgam_XCc.js","names":["getLogger","revertOutcomeToFile","modifyOutcomeToFile","toDeleteEntry","ensureSiteFile","dedent","removeHandle","pruneUnusedImports","removeStatementWithComments","ensureBlankLineAfterImports","formatLikeSource","libModule","isLibSpecifier","unmodifyTestSetup","unmodifySvelteConfig","unmodifyGitignore","BACKEND_ENV_VARS","WORKFLOWS_ENV_VARS","fs","path","HANDLE_HINT","INIT_HINT","BACKEND_MODULES","isStartWorkerCall","node","Node","onlyStartsWorker","fn","body","statements","workerInit","sf","decl","target","unmodifyHooksServerBackend","hooksServerPath","original","sourceFile","Project","QuoteKind","init","FAILURE_HINT","unmodifyLayoutServerMeta","layoutServerPath","updated","withoutParam","m","serverTestFiles","dir","found","entry","full","generate","logger","options","creates","modifies","deletes","revert","svelteConfigFile","hooksServerRevert","hasWorkflows","envVars","unmodifyEnvVarsFiles","spec","gitignorePath","gitignoreFile","layoutServerFile","siteFile","testFile","testSetupPath","testSetupFile"],"sources":["../../src/patterns/disable/backend/modifies/hooks.server.ts","../../src/patterns/disable/backend/modifies/layout-server.ts","../../src/patterns/disable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport {\n Node,\n Project,\n QuoteKind,\n type SourceFile,\n type Statement,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n pruneUnusedImports,\n removeStatementWithComments,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst HANDLE_HINT = dedent`\n Take handlePocketbase(...) out of the exported handle in src/hooks.server.ts,\n and its imports from '@velastack/pocketbase' and '$app/env/private'.\n`;\n\nconst INIT_HINT = dedent`\n The workflows are removed with the backend. Take the startWorker() call out\n of the init hook in src/hooks.server.ts, and its import:\n\n import { startWorker } from '#lib/server/workflows.js';\n`;\n\n/**\n * Modules only the backend's handle and init import from. An import nothing\n * references any more is dropped; a variable other code still reads stays.\n * `$env/dynamic/private` is the `env` object hooks written before SvelteKit 3\n * read the PocketBase variables from.\n */\nconst BACKEND_MODULES: ModuleMatch[] = [\n \"@velastack/pocketbase\",\n \"$app/env/private\",\n \"$env/dynamic/private\",\n libModule(\"server/workflows\"),\n \"@sveltejs/kit\",\n \"@sveltejs/kit/hooks\",\n];\n\n/** `startWorker()`, `await startWorker()` or `return startWorker()`. */\nfunction isStartWorkerCall(node: Node | undefined): boolean {\n if (!node) return false;\n if (Node.isAwaitExpression(node))\n return isStartWorkerCall(node.getExpression());\n if (Node.isExpressionStatement(node) || Node.isReturnStatement(node)) {\n return isStartWorkerCall(node.getExpression());\n }\n return (\n Node.isCallExpression(node) &&\n node.getExpression().getText() === \"startWorker\" &&\n node.getArguments().length === 0\n );\n}\n\n/** A function whose whole body starts the worker. */\nfunction onlyStartsWorker(fn: Node | undefined): boolean {\n if (\n !Node.isArrowFunction(fn) &&\n !Node.isFunctionExpression(fn) &&\n !Node.isFunctionDeclaration(fn)\n ) {\n return false;\n }\n const body = fn.getBody();\n if (!body) return false;\n if (!Node.isBlock(body)) return isStartWorkerCall(body);\n const statements = body.getStatements();\n return statements.length === 1 && isStartWorkerCall(statements[0]);\n}\n\n/**\n * The `init` export when all it does is start the workflow worker, the way\n * the minimal template and enable-workflows write it. `\"custom\"` when an init\n * starts the worker among other things; null when there is nothing to do.\n */\nfunction workerInit(sf: SourceFile): Statement | \"custom\" | null {\n const fn = sf.getFunction(\"init\");\n const decl = sf.getVariableDeclaration(\"init\");\n const target = fn ?? decl?.getVariableStatement();\n if (!target || !target.getText().includes(\"startWorker\")) return null;\n const onlyWorker = fn\n ? onlyStartsWorker(fn)\n : decl?.getVariableStatement()?.getDeclarations().length === 1 &&\n onlyStartsWorker(decl.getInitializer());\n return onlyWorker ? target : \"custom\";\n}\n\n/**\n * Undo what the backend put in `hooks.server.ts`: the PocketBase handle, and\n * the `init` that starts the workflow worker, which is deleted along with the\n * backend. Whatever else the file holds (i18n, content negotiation) stays; a\n * file with nothing else comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (\n !original.includes(\"handlePocketbase\") &&\n !original.includes(\"startWorker\")\n ) {\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 // Checked before anything changes, so a failure leaves the file as it was.\n if (workerInit(sourceFile) === \"custom\") {\n return { status: \"failed\", message: INIT_HINT };\n }\n\n const removed = removeHandle(sourceFile, \"handlePocketbase\");\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: HANDLE_HINT };\n }\n // Looked up again: edits to the file forget the nodes found before them.\n const init = workerInit(sourceFile);\n if (init && init !== \"custom\") removeStatementWithComments(sourceFile, init);\n\n pruneUnusedImports(sourceFile, BACKEND_MODULES);\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { isLibSpecifier } from \"../../../../runtime/lib-specifier\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.server.ts still reads locals.meta, which only the\n PocketBase hook provides. Read the values from a static module instead:\n\n import { site } from '#lib/site.js';\n\n // locals.meta.appName -> site.name\n // locals.meta.appURL -> site.url\n // meta: locals.meta -> meta: { appName: site.name, appURL: site.url }\n`;\n\n/**\n * Point an older root layout's meta at `#lib/site.js` instead of `locals.meta`.\n * Templates from before `src/lib/site.ts` read the app name and URL off the\n * PocketBase hook; without the backend nothing sets them, and `App.Locals` no\n * longer declares them. Current templates read `#lib/site.js` already, so this\n * leaves them alone.\n */\nexport function unmodifyLayoutServerMeta(\n layoutServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (!original.includes(\"locals.meta\")) {\n return { status: \"success\", changed: false };\n }\n\n let updated = original\n .replace(/\\blocals\\.meta\\.appName\\b/g, \"site.name\")\n .replace(/\\blocals\\.meta\\.appURL\\b/g, \"site.url\")\n .replace(\n /\\bmeta:\\s*locals\\.meta\\b/g,\n \"meta: { appName: site.name, appURL: site.url }\",\n );\n\n if (updated.includes(\"locals.meta\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n // `locals` usually only carried meta; drop it from the destructuring when\n // nothing else reads it.\n const withoutParam = updated\n .replace(/\\(\\{\\s*locals\\s*,\\s*/g, \"({ \")\n .replace(/,\\s*locals\\s*\\}/g, \" }\");\n if (!/\\blocals\\b/.test(withoutParam)) {\n updated = withoutParam;\n }\n\n const importsSite = [...updated.matchAll(/from\\s+['\"]([^'\"]+)['\"]/g)].some(\n (m) => isLibSpecifier(m[1], \"site\"),\n );\n if (!importsSite) {\n updated = \"import { site } from '#lib/site.js';\\n\" + updated;\n }\n\n fs.writeFileSync(layoutServerPath, updated, \"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 modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { ensureSiteFile } from \"../../../runtime/site\";\nimport { unmodifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { unmodifyLayoutServerMeta } from \"./modifies/layout-server\";\nimport { unmodifySvelteConfig } from \"../../enable/backend/modifies/svelte-config\";\nimport { unmodifyGitignore } from \"../../enable/backend/modifies/gitignore\";\nimport { unmodifyTestSetup } from \"../../enable/backend/modifies/test-setup\";\nimport { BACKEND_ENV_VARS } from \"../../enable/backend/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"../../enable/workflows/env-vars\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\n\n/** Every server test under a directory; they need the PocketBase test context. */\nfunction serverTestFiles(dir: string): string[] {\n if (!fs.existsSync(dir)) return [];\n const found: string[] = [];\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) found.push(...serverTestFiles(full));\n else if (entry.name === \"server.test.ts\") found.push(full);\n }\n return found;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n logger.info(\"Reverting adapter config\");\n const revert = unmodifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(revert.filePath, revert.outcome);\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // Only the backend's handle and worker come out; handles other patterns\n // composed in stay. The file goes when nothing else was in it.\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerRevert.modify) modifies.push(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n // The file goes when these were all it declared. The workflow runtime\n // (deleted with the backend) is the only reader of its switches, so they\n // go too, but only from a project that has it: `TEST` is a common name.\n const hasWorkflows = fs.existsSync(\n path.join(options.root, \"src\", \"lib\", \"server\", \"workflows.ts\"),\n );\n logger.info(\n hasWorkflows\n ? \"Removing the PocketBase and workflow variables from src/env.ts\"\n : \"Removing the PocketBase variables from src/env.ts\",\n );\n const envVars = unmodifyEnvVarsFiles(\n options.root,\n (hasWorkflows ? WORKFLOWS_ENV_VARS : BACKEND_ENV_VARS).map(\n (spec) => spec.name,\n ),\n );\n if (envVars.modify) modifies.push(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n unmodifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n logger.info(\"Reverting src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n const layoutServerFile = modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServerMeta(layoutServerPath),\n );\n if (layoutServerFile) modifies.push(layoutServerFile);\n\n // The converted layout reads `src/lib/site.ts`. Every template ships it; a\n // project from before that gets one here, named as PocketBase knew it.\n if (layoutServerFile?.status === \"success\") {\n const siteFile = await ensureSiteFile(options);\n if (siteFile) creates.push(siteFile);\n }\n\n // Server tests run against the PocketBase-backed test context that the\n // backend's test/setup.ts provides; without it they neither type-check nor\n // run.\n for (const testFile of serverTestFiles(path.join(options.root, \"src\"))) {\n logger.info(`Removing ${path.relative(options.root, testFile)}`);\n deletes.push(toDeleteEntry(testFile));\n }\n\n logger.info(\"Reverting test/setup.ts\");\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n unmodifyTestSetup(testSetupPath),\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":";;;;;;;;;;;;;;;;AAoBA,IAAMoB,IAAc,CAAM;;;GAKpBC,IAAY,CAAM;;;;;GAalBC,IAAiC;CACrC;CACA;CACA;CACAX,EAAU,kBAAkB;CAC5B;CACA;AACF;AAGA,SAASY,EAAkB,GAAiC;CAO1D,OANKC,IACDC,EAAK,kBAAkBD,CAAI,KAE3BC,EAAK,sBAAsBD,CAAI,KAAKC,EAAK,kBAAkBD,CAAI,IAC1DD,EAAkBC,EAAK,cAAc,CAAC,IAG7CC,EAAK,iBAAiBD,CAAI,KAC1BA,EAAK,cAAc,CAAC,CAAC,QAAQ,MAAM,iBACnCA,EAAK,aAAa,CAAC,CAAC,WAAW,IATf;AAWpB;AAGA,SAASE,EAAiB,GA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,EAAQ,MAAM,YAAY,GACpDY,IAAgBhE,EACpB+D,GACAlD,EAAkBkD,CAAa,CACjC;CAGA,AAFIC,KAAeV,EAAS,KAAKU,CAAa,GAE9Cb,EAAO,KAAK,wCAAwC;CACpD,IAAMV,IAAmBxB,EAAK,KAC5BmC,EAAQ,MACR,OACA,UACA,mBACF,GACMa,IAAmBjE,EACvByC,GACAD,EAAyBC,CAAgB,CAC3C;CAKA,IAJIwB,KAAkBX,EAAS,KAAKW,CAAgB,GAIhDA,GAAkB,WAAW,WAAW;EAC1C,IAAMC,IAAW,MAAMhE,EAAekD,CAAO;EAC7C,AAAIc,KAAUb,EAAQ,KAAKa,CAAQ;CACrC;CAKA,KAAK,IAAMC,KAAYtB,EAAgB5B,EAAK,KAAKmC,EAAQ,MAAM,KAAK,CAAC,GAEnE,AADAD,EAAO,KAAK,YAAYlC,EAAK,SAASmC,EAAQ,MAAMe,CAAQ,GAAG,GAC/DZ,EAAQ,KAAKtD,EAAckE,CAAQ,CAAC;CAGtC,EAAO,KAAK,yBAAyB;CACrC,IAAMC,IAAgBnD,EAAK,KAAKmC,EAAQ,MAAM,QAAQ,UAAU,GAC1DiB,IAAgBrE,EACpBoE,GACAzD,EAAkByD,CAAa,CACjC;CAGA,OAFIC,KAAef,EAAS,KAAKe,CAAa,GAEvC;EACL;EACA;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-DaPA2NNL.js","names":["getLogger","revertOutcomeToFile","modifyOutcomeToFile","toDeleteEntry","ensureSiteFile","dedent","removeHandle","pruneUnusedImports","removeStatementWithComments","ensureBlankLineAfterImports","formatLikeSource","libModule","isLibSpecifier","unmodifyTestSetup","unmodifySvelteConfig","unmodifyGitignore","BACKEND_ENV_VARS","WORKFLOWS_ENV_VARS","fs","path","HANDLE_HINT","INIT_HINT","BACKEND_MODULES","isStartWorkerCall","node","Node","onlyStartsWorker","fn","body","statements","workerInit","sf","decl","target","unmodifyHooksServerBackend","hooksServerPath","original","sourceFile","Project","QuoteKind","init","FAILURE_HINT","unmodifyLayoutServerMeta","layoutServerPath","updated","withoutParam","m","serverTestFiles","dir","found","entry","full","generate","logger","options","creates","modifies","deletes","revert","svelteConfigFile","hooksServerRevert","hasWorkflows","envVars","unmodifyEnvVarsFiles","spec","gitignorePath","gitignoreFile","layoutServerFile","siteFile","testFile","testSetupPath","testSetupFile"],"sources":["../../src/patterns/disable/backend/modifies/hooks.server.ts","../../src/patterns/disable/backend/modifies/layout-server.ts","../../src/patterns/disable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport {\n Node,\n Project,\n QuoteKind,\n type SourceFile,\n type Statement,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n pruneUnusedImports,\n removeStatementWithComments,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst HANDLE_HINT = dedent`\n Take handlePocketbase(...) out of the exported handle in src/hooks.server.ts,\n and its imports from '@velastack/pocketbase' and '$app/env/private'.\n`;\n\nconst INIT_HINT = dedent`\n The workflows are removed with the backend. Take the startWorker() call out\n of the init hook in src/hooks.server.ts, and its import:\n\n import { startWorker } from '#lib/server/workflows.js';\n`;\n\n/**\n * Modules only the backend's handle and init import from. An import nothing\n * references any more is dropped; a variable other code still reads stays.\n * `$env/dynamic/private` is the `env` object hooks written before SvelteKit 3\n * read the PocketBase variables from.\n */\nconst BACKEND_MODULES: ModuleMatch[] = [\n \"@velastack/pocketbase\",\n \"$app/env/private\",\n \"$env/dynamic/private\",\n libModule(\"server/workflows\"),\n \"@sveltejs/kit\",\n \"@sveltejs/kit/hooks\",\n];\n\n/** `startWorker()`, `await startWorker()` or `return startWorker()`. */\nfunction isStartWorkerCall(node: Node | undefined): boolean {\n if (!node) return false;\n if (Node.isAwaitExpression(node))\n return isStartWorkerCall(node.getExpression());\n if (Node.isExpressionStatement(node) || Node.isReturnStatement(node)) {\n return isStartWorkerCall(node.getExpression());\n }\n return (\n Node.isCallExpression(node) &&\n node.getExpression().getText() === \"startWorker\" &&\n node.getArguments().length === 0\n );\n}\n\n/** A function whose whole body starts the worker. */\nfunction onlyStartsWorker(fn: Node | undefined): boolean {\n if (\n !Node.isArrowFunction(fn) &&\n !Node.isFunctionExpression(fn) &&\n !Node.isFunctionDeclaration(fn)\n ) {\n return false;\n }\n const body = fn.getBody();\n if (!body) return false;\n if (!Node.isBlock(body)) return isStartWorkerCall(body);\n const statements = body.getStatements();\n return statements.length === 1 && isStartWorkerCall(statements[0]);\n}\n\n/**\n * The `init` export when all it does is start the workflow worker, the way\n * the minimal template and enable-workflows write it. `\"custom\"` when an init\n * starts the worker among other things; null when there is nothing to do.\n */\nfunction workerInit(sf: SourceFile): Statement | \"custom\" | null {\n const fn = sf.getFunction(\"init\");\n const decl = sf.getVariableDeclaration(\"init\");\n const target = fn ?? decl?.getVariableStatement();\n if (!target || !target.getText().includes(\"startWorker\")) return null;\n const onlyWorker = fn\n ? onlyStartsWorker(fn)\n : decl?.getVariableStatement()?.getDeclarations().length === 1 &&\n onlyStartsWorker(decl.getInitializer());\n return onlyWorker ? target : \"custom\";\n}\n\n/**\n * Undo what the backend put in `hooks.server.ts`: the PocketBase handle, and\n * the `init` that starts the workflow worker, which is deleted along with the\n * backend. Whatever else the file holds (i18n, content negotiation) stays; a\n * file with nothing else comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (\n !original.includes(\"handlePocketbase\") &&\n !original.includes(\"startWorker\")\n ) {\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 // Checked before anything changes, so a failure leaves the file as it was.\n if (workerInit(sourceFile) === \"custom\") {\n return { status: \"failed\", message: INIT_HINT };\n }\n\n const removed = removeHandle(sourceFile, \"handlePocketbase\");\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: HANDLE_HINT };\n }\n // Looked up again: edits to the file forget the nodes found before them.\n const init = workerInit(sourceFile);\n if (init && init !== \"custom\") removeStatementWithComments(sourceFile, init);\n\n pruneUnusedImports(sourceFile, BACKEND_MODULES);\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { isLibSpecifier } from \"../../../../runtime/lib-specifier\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.server.ts still reads locals.meta, which only the\n PocketBase hook provides. Read the values from a static module instead:\n\n import { site } from '#lib/site.js';\n\n // locals.meta.appName -> site.name\n // locals.meta.appURL -> site.url\n // meta: locals.meta -> meta: { appName: site.name, appURL: site.url }\n`;\n\n/**\n * Point an older root layout's meta at `#lib/site.js` instead of `locals.meta`.\n * Templates from before `src/lib/site.ts` read the app name and URL off the\n * PocketBase hook; without the backend nothing sets them, and `App.Locals` no\n * longer declares them. Current templates read `#lib/site.js` already, so this\n * leaves them alone.\n */\nexport function unmodifyLayoutServerMeta(\n layoutServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (!original.includes(\"locals.meta\")) {\n return { status: \"success\", changed: false };\n }\n\n let updated = original\n .replace(/\\blocals\\.meta\\.appName\\b/g, \"site.name\")\n .replace(/\\blocals\\.meta\\.appURL\\b/g, \"site.url\")\n .replace(\n /\\bmeta:\\s*locals\\.meta\\b/g,\n \"meta: { appName: site.name, appURL: site.url }\",\n );\n\n if (updated.includes(\"locals.meta\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n // `locals` usually only carried meta; drop it from the destructuring when\n // nothing else reads it.\n const withoutParam = updated\n .replace(/\\(\\{\\s*locals\\s*,\\s*/g, \"({ \")\n .replace(/,\\s*locals\\s*\\}/g, \" }\");\n if (!/\\blocals\\b/.test(withoutParam)) {\n updated = withoutParam;\n }\n\n const importsSite = [...updated.matchAll(/from\\s+['\"]([^'\"]+)['\"]/g)].some(\n (m) => isLibSpecifier(m[1], \"site\"),\n );\n if (!importsSite) {\n updated = \"import { site } from '#lib/site.js';\\n\" + updated;\n }\n\n fs.writeFileSync(layoutServerPath, updated, \"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 modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { ensureSiteFile } from \"../../../runtime/site\";\nimport { unmodifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { unmodifyLayoutServerMeta } from \"./modifies/layout-server\";\nimport { unmodifySvelteConfig } from \"../../enable/backend/modifies/svelte-config\";\nimport { unmodifyGitignore } from \"../../enable/backend/modifies/gitignore\";\nimport { unmodifyTestSetup } from \"../../enable/backend/modifies/test-setup\";\nimport { BACKEND_ENV_VARS } from \"../../enable/backend/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"../../enable/workflows/env-vars\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\n\n/** Every server test under a directory; they need the PocketBase test context. */\nfunction serverTestFiles(dir: string): string[] {\n if (!fs.existsSync(dir)) return [];\n const found: string[] = [];\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) found.push(...serverTestFiles(full));\n else if (entry.name === \"server.test.ts\") found.push(full);\n }\n return found;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n logger.info(\"Reverting adapter config\");\n const revert = unmodifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(revert.filePath, revert.outcome);\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // Only the backend's handle and worker come out; handles other patterns\n // composed in stay. The file goes when nothing else was in it.\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerRevert.modify) modifies.push(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n // The file goes when these were all it declared. The workflow runtime\n // (deleted with the backend) is the only reader of its switches, so they\n // go too, but only from a project that has it: `TEST` is a common name.\n const hasWorkflows = fs.existsSync(\n path.join(options.root, \"src\", \"lib\", \"server\", \"workflows.ts\"),\n );\n logger.info(\n hasWorkflows\n ? \"Removing the PocketBase and workflow variables from src/env.ts\"\n : \"Removing the PocketBase variables from src/env.ts\",\n );\n const envVars = unmodifyEnvVarsFiles(\n options.root,\n (hasWorkflows ? WORKFLOWS_ENV_VARS : BACKEND_ENV_VARS).map(\n (spec) => spec.name,\n ),\n );\n if (envVars.modify) modifies.push(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n unmodifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n logger.info(\"Reverting src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n const layoutServerFile = modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServerMeta(layoutServerPath),\n );\n if (layoutServerFile) modifies.push(layoutServerFile);\n\n // The converted layout reads `src/lib/site.ts`. Every template ships it; a\n // project from before that gets one here, named as PocketBase knew it.\n if (layoutServerFile?.status === \"success\") {\n const siteFile = await ensureSiteFile(options);\n if (siteFile) creates.push(siteFile);\n }\n\n // Server tests run against the PocketBase-backed test context that the\n // backend's test/setup.ts provides; without it they neither type-check nor\n // run.\n for (const testFile of serverTestFiles(path.join(options.root, \"src\"))) {\n logger.info(`Removing ${path.relative(options.root, testFile)}`);\n deletes.push(toDeleteEntry(testFile));\n }\n\n logger.info(\"Reverting test/setup.ts\");\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n unmodifyTestSetup(testSetupPath),\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":";;;;;;;;;;;;;;;;AAoBA,IAAMoB,IAAc,CAAM;;;GAKpBC,IAAY,CAAM;;;;;GAalBC,IAAiC;CACrC;CACA;CACA;CACAX,EAAU,kBAAkB;CAC5B;CACA;AACF;AAGA,SAASY,EAAkB,GAAiC;CAO1D,OANKC,IACDC,EAAK,kBAAkBD,CAAI,KAE3BC,EAAK,sBAAsBD,CAAI,KAAKC,EAAK,kBAAkBD,CAAI,IAC1DD,EAAkBC,EAAK,cAAc,CAAC,IAG7CC,EAAK,iBAAiBD,CAAI,KAC1BA,EAAK,cAAc,CAAC,CAAC,QAAQ,MAAM,iBACnCA,EAAK,aAAa,CAAC,CAAC,WAAW,IATf;AAWpB;AAGA,SAASE,EA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