From 18ed5b67f92392d2325209a684788194268d426d Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Mon, 30 Mar 2026 17:11:35 +0800 Subject: [PATCH 1/8] . --- packages/sv-utils/src/tooling/transforms.ts | 18 +- packages/sv/src/addons/better-auth.ts | 176 +++++++++----------- packages/sv/src/addons/common.ts | 10 +- packages/sv/src/addons/drizzle.ts | 176 ++++++++++---------- packages/sv/src/addons/mcp.ts | 19 +-- packages/sv/src/addons/paraglide.ts | 6 +- packages/sv/src/addons/sveltekit-adapter.ts | 39 ++--- packages/sv/src/addons/tailwindcss.ts | 24 ++- packages/sv/src/addons/vitest-addon.ts | 15 +- 9 files changed, 224 insertions(+), 259 deletions(-) diff --git a/packages/sv-utils/src/tooling/transforms.ts b/packages/sv-utils/src/tooling/transforms.ts index 82f92b0c9..9b71a2f11 100644 --- a/packages/sv-utils/src/tooling/transforms.ts +++ b/packages/sv-utils/src/tooling/transforms.ts @@ -69,7 +69,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ script( - cb: (args: { + cb: (file: { ast: TsEstree.Program; comments: Comments; content: string; @@ -92,7 +92,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ svelte( - cb: (args: { + cb: (file: { ast: SvelteAst.Root; content: string; svelte: typeof svelteNs; @@ -119,7 +119,7 @@ export const transforms = { */ svelteScript( scriptOptions: { language: 'ts' | 'js' }, - cb: (args: { + cb: (file: { ast: RootWithInstance; content: string; svelte: typeof svelteNs; @@ -148,7 +148,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ css( - cb: (args: { + cb: (file: { ast: Omit; content: string; css: typeof cssNs; @@ -170,7 +170,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ json( - cb: (args: { data: T; content: string; json: typeof jsonNs }) => void | false, + cb: (file: { data: T; content: string; json: typeof jsonNs }) => void | false, options?: TransformOptions ): (content: string) => string { return (content) => { @@ -188,7 +188,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ yaml( - cb: (args: { data: ReturnType['data']; content: string }) => void | false, + cb: (file: { data: ReturnType['data']; content: string }) => void | false, options?: TransformOptions ): (content: string) => string { return (content) => { @@ -206,7 +206,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ toml( - cb: (args: { data: TomlTable; content: string }) => void | false, + cb: (file: { data: TomlTable; content: string }) => void | false, options?: TransformOptions ): (content: string) => string { return (content) => { @@ -224,7 +224,7 @@ export const transforms = { * Return `false` from the callback to abort - the original content is returned unchanged. */ html( - cb: (args: { ast: SvelteAst.Fragment; content: string; html: typeof htmlNs }) => void | false, + cb: (file: { ast: SvelteAst.Fragment; content: string; html: typeof htmlNs }) => void | false, options?: TransformOptions ): (content: string) => string { return (content) => { @@ -243,7 +243,7 @@ export const transforms = { * Return the new content, or `false` to abort (original content is returned unchanged). */ text( - cb: (args: { content: string; text: typeof textNs }) => string | false + cb: (file: { content: string; text: typeof textNs }) => string | false ): (content: string) => string { return (content) => { const result = cb({ content, text: textNs }); diff --git a/packages/sv/src/addons/better-auth.ts b/packages/sv/src/addons/better-auth.ts index 22094f2ec..4edd6240b 100644 --- a/packages/sv/src/addons/better-auth.ts +++ b/packages/sv/src/addons/better-auth.ts @@ -4,7 +4,6 @@ import { Walker, color, dedent, - text, transforms, resolveCommand, createPrinter @@ -86,14 +85,8 @@ export default defineAddon({ }) ); - sv.file( - '.env', - transforms.text(({ content }) => generateEnvFileContent(content, demoGithub, false)) - ); - sv.file( - '.env.example', - transforms.text(({ content }) => generateEnvFileContent(content, demoGithub, true)) - ); + sv.file('.env', generateEnvFileContent(demoGithub, false)); + sv.file('.env.example', generateEnvFileContent(demoGithub, true)); sv.file( `${directory.lib}/server/auth.${language}`, @@ -296,11 +289,11 @@ export default defineAddon({ sv.file( `${directory.kitRoutes}/demo/better-auth/login/+page.server.${language}`, - transforms.text(({ content }) => { + (content) => { if (content) { const filePath = `${directory.kitRoutes}/demo/better-auth/login/+page.server.${language}`; log.warn(`Existing ${color.warning(filePath)} file. Could not update.`); - return false; + return content; } const [ts] = createPrinter(language === 'ts'); @@ -397,31 +390,29 @@ export default defineAddon({ export const actions${ts(': Actions')} = {${signInEmailAction}${signInSocialAction} }; `; - }) + } ); - sv.file( - `${directory.kitRoutes}/demo/better-auth/login/+page.svelte`, - transforms.text(({ content }) => { - if (content) { - const filePath = `${directory.kitRoutes}/demo/better-auth/login/+page.svelte`; - log.warn(`Existing ${color.warning(filePath)} file. Could not update.`); - return false; - } + sv.file(`${directory.kitRoutes}/demo/better-auth/login/+page.svelte`, (content) => { + if (content) { + const filePath = `${directory.kitRoutes}/demo/better-auth/login/+page.svelte`; + log.warn(`Existing ${color.warning(filePath)} file. Could not update.`); + return content; + } - const tailwind = dependencyVersion('@tailwindcss/vite') !== undefined; - const input = tailwind - ? ' class="mt-1 px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"' - : ''; - const btn = tailwind - ? ' class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition"' - : ''; + const tailwind = dependencyVersion('@tailwindcss/vite') !== undefined; + const input = tailwind + ? ' class="mt-1 px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"' + : ''; + const btn = tailwind + ? ' class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition"' + : ''; - const svelte5 = !!dependencyVersion('svelte')?.startsWith('5'); - const [ts, s5] = createPrinter(language === 'ts', svelte5); + const svelte5 = !!dependencyVersion('svelte')?.startsWith('5'); + const [ts, s5] = createPrinter(language === 'ts', svelte5); - const passwordForm = demoPassword - ? ` + const passwordForm = demoPassword + ? `