From f5ce27b8cb1adf78ab275528660f14d22f763d2c Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sat, 22 Nov 2025 22:06:52 +0800 Subject: [PATCH 01/14] fix typo --- packages/cli/commands/add/workspace.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/commands/add/workspace.ts b/packages/cli/commands/add/workspace.ts index b00d13c2..a4d0835f 100644 --- a/packages/cli/commands/add/workspace.ts +++ b/packages/cli/commands/add/workspace.ts @@ -28,8 +28,8 @@ export async function createWorkspace({ const viteConfig = fs.existsSync(viteConfigPath) ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig; - const sveteConfigPath = path.join(resolvedCwd, commonFilePaths.svelteConfigTS); - const svelteConfig = fs.existsSync(sveteConfigPath) + const svelteConfigPath = path.join(resolvedCwd, commonFilePaths.svelteConfigTS); + const svelteConfig = fs.existsSync(svelteConfigPath) ? commonFilePaths.svelteConfigTS : commonFilePaths.svelteConfig; From 63399b4d4e0c9a10e733ed27c04efe8c02fd246e Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sat, 22 Nov 2025 22:51:36 +0800 Subject: [PATCH 02/14] initial attempt --- packages/cli/commands/add/workspace.ts | 7 ++++++- packages/cli/commands/create.ts | 8 -------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/cli/commands/add/workspace.ts b/packages/cli/commands/add/workspace.ts index a4d0835f..c3d41a91 100644 --- a/packages/cli/commands/add/workspace.ts +++ b/packages/cli/commands/add/workspace.ts @@ -59,7 +59,12 @@ export async function createWorkspace({ dependencies[key] = value.replaceAll(/[^\d|.]/g, ''); } - const kit = dependencies['@sveltejs/kit'] ? parseKitOptions(resolvedCwd) : undefined; + // dependencies['@sveltejs/kit'] is always undefined + const kit = dependencies['@sveltejs/kit'] ? parseKitOptions(resolvedCwd) : { + routesDirectory: 'src/routes', + libDirectory: 'src/lib' + }; + const stylesheet: `${string}/layout.css` | 'src/app.css' = kit ? `${kit.routesDirectory}/layout.css` : 'src/app.css'; diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index ddf6e3ba..7ecb3110 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -359,7 +359,6 @@ interface CreateVirtualWorkspaceOptions { export async function createVirtualWorkspace({ cwd, - template, packageManager, type }: CreateVirtualWorkspaceOptions): Promise { @@ -373,16 +372,9 @@ export async function createVirtualWorkspace({ svelteConfig: type === 'typescript' ? commonFilePaths.svelteConfigTS : commonFilePaths.svelteConfig }, - kit: undefined, dependencyVersion: () => undefined }; - if (template === 'minimal' || template === 'demo' || template === 'library') { - virtualWorkspace.kit = { - routesDirectory: 'src/routes', - libDirectory: 'src/lib' - }; - } return virtualWorkspace; } From 9c45643f552279a143dc3f669723b731ba1f849c Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sat, 22 Nov 2025 22:58:51 +0800 Subject: [PATCH 03/14] reuse stylesheet variable --- packages/addons/prettier/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/addons/prettier/index.ts b/packages/addons/prettier/index.ts index 813345c0..39de2119 100644 --- a/packages/addons/prettier/index.ts +++ b/packages/addons/prettier/index.ts @@ -7,7 +7,7 @@ export default defineAddon({ shortDescription: 'formatter', homepage: 'https://prettier.io', options: {}, - run: ({ sv, dependencyVersion, kit, files }) => { + run: ({ sv, dependencyVersion, files }) => { const tailwindcssInstalled = Boolean(dependencyVersion('tailwindcss')); if (tailwindcssInstalled) sv.devDependency('prettier-plugin-tailwindcss', '^0.7.1'); @@ -53,7 +53,7 @@ export default defineAddon({ if (!plugins.includes('prettier-plugin-tailwindcss')) { data.plugins.unshift('prettier-plugin-tailwindcss'); } - data.tailwindStylesheet ??= kit ? `${kit?.routesDirectory}/layout.css` : './src/app.css'; + data.tailwindStylesheet ??= files.getRelative({ to: files.stylesheet }); } if (!plugins.includes('prettier-plugin-svelte')) { data.plugins.unshift('prettier-plugin-svelte'); From ba437a829cea5014641b22dc77d4c226a3eae4aa Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sat, 22 Nov 2025 23:06:04 +0800 Subject: [PATCH 04/14] cleanup --- packages/cli/commands/add/workspace.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/cli/commands/add/workspace.ts b/packages/cli/commands/add/workspace.ts index c3d41a91..861056df 100644 --- a/packages/cli/commands/add/workspace.ts +++ b/packages/cli/commands/add/workspace.ts @@ -59,15 +59,10 @@ export async function createWorkspace({ dependencies[key] = value.replaceAll(/[^\d|.]/g, ''); } - // dependencies['@sveltejs/kit'] is always undefined const kit = dependencies['@sveltejs/kit'] ? parseKitOptions(resolvedCwd) : { routesDirectory: 'src/routes', libDirectory: 'src/lib' }; - - const stylesheet: `${string}/layout.css` | 'src/app.css' = kit - ? `${kit.routesDirectory}/layout.css` - : 'src/app.css'; return { cwd: resolvedCwd, @@ -76,7 +71,7 @@ export async function createWorkspace({ files: { viteConfig, svelteConfig, - stylesheet, + stylesheet: kit ? `${kit.routesDirectory}/layout.css` : 'src/app.css', package: 'package.json', gitignore: '.gitignore', prettierignore: '.prettierignore', From 2d6922913f0c8a5152bfedee2aca71c59036f578 Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sat, 22 Nov 2025 23:06:20 +0800 Subject: [PATCH 05/14] lint --- packages/cli/commands/add/workspace.ts | 10 ++++++---- packages/cli/commands/create.ts | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/cli/commands/add/workspace.ts b/packages/cli/commands/add/workspace.ts index 861056df..c04e8479 100644 --- a/packages/cli/commands/add/workspace.ts +++ b/packages/cli/commands/add/workspace.ts @@ -59,10 +59,12 @@ export async function createWorkspace({ dependencies[key] = value.replaceAll(/[^\d|.]/g, ''); } - const kit = dependencies['@sveltejs/kit'] ? parseKitOptions(resolvedCwd) : { - routesDirectory: 'src/routes', - libDirectory: 'src/lib' - }; + const kit = dependencies['@sveltejs/kit'] + ? parseKitOptions(resolvedCwd) + : { + routesDirectory: 'src/routes', + libDirectory: 'src/lib' + }; return { cwd: resolvedCwd, diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index 7ecb3110..15085498 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -375,6 +375,5 @@ export async function createVirtualWorkspace({ dependencyVersion: () => undefined }; - return virtualWorkspace; } From e41cf949c92e7c17b8e39e0251f95703335d426c Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sun, 23 Nov 2025 01:43:36 +0800 Subject: [PATCH 06/14] rerun test From 5b760cd3af9f8e7c860484a83e249d1b0932fe29 Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sun, 23 Nov 2025 01:54:07 +0800 Subject: [PATCH 07/14] . --- packages/cli/commands/create.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index 15085498..8830fc8f 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -359,6 +359,7 @@ interface CreateVirtualWorkspaceOptions { export async function createVirtualWorkspace({ cwd, + template, packageManager, type }: CreateVirtualWorkspaceOptions): Promise { @@ -372,8 +373,16 @@ export async function createVirtualWorkspace({ svelteConfig: type === 'typescript' ? commonFilePaths.svelteConfigTS : commonFilePaths.svelteConfig }, + kit: undefined, dependencyVersion: () => undefined }; + // check if it is a kit project + if (template === 'minimal' || template === 'demo' || template === 'library') { + virtualWorkspace.kit = { + routesDirectory: 'src/routes', + libDirectory: 'src/lib' + }; + } return virtualWorkspace; } From d0d9cbcd20cb364680539de15630482190009c90 Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sun, 23 Nov 2025 01:58:18 +0800 Subject: [PATCH 08/14] lint --- packages/cli/commands/create.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index 8830fc8f..572d100a 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -376,7 +376,7 @@ export async function createVirtualWorkspace({ kit: undefined, dependencyVersion: () => undefined }; - // check if it is a kit project + // check if it is a kit project if (template === 'minimal' || template === 'demo' || template === 'library') { virtualWorkspace.kit = { routesDirectory: 'src/routes', From 0ec89fa43ba8b7bf246029bd7fbd8358b4081ecc Mon Sep 17 00:00:00 2001 From: jycouet Date: Sat, 22 Nov 2025 21:54:10 +0100 Subject: [PATCH 09/14] option to override for virtual workspace --- packages/cli/commands/add/workspace.ts | 23 +++++++++++++++-------- packages/cli/commands/create.ts | 24 +++++++++++++----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/packages/cli/commands/add/workspace.ts b/packages/cli/commands/add/workspace.ts index c04e8479..4cb47cb5 100644 --- a/packages/cli/commands/add/workspace.ts +++ b/packages/cli/commands/add/workspace.ts @@ -11,10 +11,14 @@ import { getUserAgent } from '../../utils/package-manager.ts'; type CreateWorkspaceOptions = { cwd: string; packageManager?: PackageManager; + override?: { + kit?: Workspace['kit']; + }; }; export async function createWorkspace({ cwd, - packageManager + packageManager, + override }: CreateWorkspaceOptions): Promise { const resolvedCwd = path.resolve(cwd); @@ -59,12 +63,15 @@ export async function createWorkspace({ dependencies[key] = value.replaceAll(/[^\d|.]/g, ''); } - const kit = dependencies['@sveltejs/kit'] - ? parseKitOptions(resolvedCwd) - : { - routesDirectory: 'src/routes', - libDirectory: 'src/lib' - }; + const kit = override?.kit + ? override.kit + : dependencies['@sveltejs/kit'] + ? parseKitOptions(resolvedCwd) + : undefined; + + const stylesheet: `${string}/layout.css` | 'src/app.css' = kit + ? `${kit.routesDirectory}/layout.css` + : 'src/app.css'; return { cwd: resolvedCwd, @@ -73,7 +80,7 @@ export async function createWorkspace({ files: { viteConfig, svelteConfig, - stylesheet: kit ? `${kit.routesDirectory}/layout.css` : 'src/app.css', + stylesheet, package: 'package.json', gitignore: '.gitignore', prettierignore: '.prettierignore', diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index 572d100a..8bb2c31b 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -363,7 +363,18 @@ export async function createVirtualWorkspace({ packageManager, type }: CreateVirtualWorkspaceOptions): Promise { - const tentativeWorkspace = await createWorkspace({ cwd, packageManager }); + let kit: Workspace['kit'] | undefined = undefined; + + // These are our default project structure so we know that it's a kit project + if (template === 'minimal' || template === 'demo' || template === 'library') { + kit = { + routesDirectory: 'src/routes', + libDirectory: 'src/lib' + }; + } + + const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override: { kit } }); + const virtualWorkspace: Workspace = { ...tentativeWorkspace, typescript: type === 'typescript', @@ -372,17 +383,8 @@ export async function createVirtualWorkspace({ viteConfig: type === 'typescript' ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig, svelteConfig: type === 'typescript' ? commonFilePaths.svelteConfigTS : commonFilePaths.svelteConfig - }, - kit: undefined, - dependencyVersion: () => undefined + } }; - // check if it is a kit project - if (template === 'minimal' || template === 'demo' || template === 'library') { - virtualWorkspace.kit = { - routesDirectory: 'src/routes', - libDirectory: 'src/lib' - }; - } return virtualWorkspace; } From b35d736ba886a9c5a53996e0ca2e24ea4e7c0a6f Mon Sep 17 00:00:00 2001 From: jycouet Date: Sat, 22 Nov 2025 22:15:00 +0100 Subject: [PATCH 10/14] adding a cli test will all addons --- packages/cli/tests/cli.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/cli/tests/cli.ts b/packages/cli/tests/cli.ts index e93a21c4..156674de 100644 --- a/packages/cli/tests/cli.ts +++ b/packages/cli/tests/cli.ts @@ -16,9 +16,32 @@ beforeAll(() => { }); describe('cli', () => { - it('should be able to create a new project with cli command', async () => { + const testCases = [ + { projectName: 'create-only', args: ['--no-add-ons'] }, + { + projectName: 'create-with-all-addons', + args: [ + '--add', + 'prettier', + 'eslint', + 'vitest=usages:unit,component', + 'playwright', + 'tailwindcss=plugins:typography,forms', + 'sveltekit-adapter=adapter:node', + 'devtools-json', + 'drizzle=database:sqlite+sqlite:libsql', + 'lucia=demo:yes', + 'mdsvex', + 'paraglide=languageTags:en,es+demo:yes', + 'mcp=ide:claude-code,cursor,gemini,opencode,vscode,other+setup:local' + ] + } + ]; + + it.for(testCases)('should create a new project with name $projectName', async (testCase) => { + const { projectName, args } = testCase; const svBinPath = path.resolve(monoRepoPath, 'packages', 'cli', 'dist', 'bin.js'); - const testOutputPath = path.resolve(monoRepoPath, '.test-output', 'cli', 'test-project'); + const testOutputPath = path.resolve(monoRepoPath, '.test-output', 'cli', projectName); const result = await exec( 'node', @@ -31,7 +54,7 @@ describe('cli', () => { '--types', 'ts', '--no-install', - '--no-add-ons' + ...args ], { nodeOptions: { stdio: 'ignore' } } ); @@ -45,6 +68,6 @@ describe('cli', () => { // package.json has a name const packageJsonPath = path.resolve(testOutputPath, 'package.json'); const packageJson = parseJson(fs.readFileSync(packageJsonPath, 'utf-8')); - expect(packageJson.name).toBe('test-project'); + expect(packageJson.name).toBe(projectName); }); }); From 98d7fe033b05c56c5fa5ebd086d25ab3e9b45cc4 Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sun, 23 Nov 2025 11:30:23 +0800 Subject: [PATCH 11/14] make it an object --- packages/cli/commands/create.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index 8bb2c31b..c6fd624d 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -363,17 +363,17 @@ export async function createVirtualWorkspace({ packageManager, type }: CreateVirtualWorkspaceOptions): Promise { - let kit: Workspace['kit'] | undefined = undefined; + const override: { kit?: Workspace['kit'] } = {}; // These are our default project structure so we know that it's a kit project if (template === 'minimal' || template === 'demo' || template === 'library') { - kit = { + override.kit = { routesDirectory: 'src/routes', libDirectory: 'src/lib' }; } - const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override: { kit } }); + const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override }); const virtualWorkspace: Workspace = { ...tentativeWorkspace, From 7ec105aa8acd84aced0cbd43de00786cdeabe9c7 Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sun, 23 Nov 2025 11:44:33 +0800 Subject: [PATCH 12/14] Revert "make it an object" This reverts commit 98d7fe033b05c56c5fa5ebd086d25ab3e9b45cc4. --- packages/cli/commands/create.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index c6fd624d..8bb2c31b 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -363,17 +363,17 @@ export async function createVirtualWorkspace({ packageManager, type }: CreateVirtualWorkspaceOptions): Promise { - const override: { kit?: Workspace['kit'] } = {}; + let kit: Workspace['kit'] | undefined = undefined; // These are our default project structure so we know that it's a kit project if (template === 'minimal' || template === 'demo' || template === 'library') { - override.kit = { + kit = { routesDirectory: 'src/routes', libDirectory: 'src/lib' }; } - const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override }); + const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override: { kit } }); const virtualWorkspace: Workspace = { ...tentativeWorkspace, From 45bbc7cd56c5b1f648698f2a6a2f0d59fbe6f09a Mon Sep 17 00:00:00 2001 From: Scott Wu Date: Sun, 23 Nov 2025 12:00:34 +0800 Subject: [PATCH 13/14] Reapply "make it an object" This reverts commit 7ec105aa8acd84aced0cbd43de00786cdeabe9c7. --- packages/cli/commands/create.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/commands/create.ts b/packages/cli/commands/create.ts index 8bb2c31b..c6fd624d 100644 --- a/packages/cli/commands/create.ts +++ b/packages/cli/commands/create.ts @@ -363,17 +363,17 @@ export async function createVirtualWorkspace({ packageManager, type }: CreateVirtualWorkspaceOptions): Promise { - let kit: Workspace['kit'] | undefined = undefined; + const override: { kit?: Workspace['kit'] } = {}; // These are our default project structure so we know that it's a kit project if (template === 'minimal' || template === 'demo' || template === 'library') { - kit = { + override.kit = { routesDirectory: 'src/routes', libDirectory: 'src/lib' }; } - const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override: { kit } }); + const tentativeWorkspace = await createWorkspace({ cwd, packageManager, override }); const virtualWorkspace: Workspace = { ...tentativeWorkspace, From b38a2115fbfe543ca8aa6256fa011aea0f5ca917 Mon Sep 17 00:00:00 2001 From: Manuel <30698007+manuel3108@users.noreply.github.com> Date: Sun, 23 Nov 2025 07:21:33 +0100 Subject: [PATCH 14/14] Create proud-baboons-cheat.md --- .changeset/proud-baboons-cheat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/proud-baboons-cheat.md diff --git a/.changeset/proud-baboons-cheat.md b/.changeset/proud-baboons-cheat.md new file mode 100644 index 00000000..444101ba --- /dev/null +++ b/.changeset/proud-baboons-cheat.md @@ -0,0 +1,5 @@ +--- +"sv": patch +--- + +fix(cli): `kit` projects were detected incorrectly