Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/void/src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
SCAFFOLD_FRAMEWORKS,
SCAFFOLD_FRAMEWORK_OPTIONS,
SCAFFOLD_GITIGNORE_LINES,
SCAFFOLD_SVELTE_CONFIG,
SCAFFOLD_TOOLCHAIN_OPTIONS,
} from './template.ts';
import type { ScaffoldFramework, ScaffoldStarterMode, ScaffoldToolchain } from './template.ts';
Expand Down Expand Up @@ -582,6 +583,15 @@ export function isScaffoldableEmptyProject(root: string): boolean {
if (entry.name === 'pnpm-workspace.yaml' && isEmptyProjectAllowedPnpmWorkspaceFile(root)) {
continue;
}
if (entry.name === SCAFFOLD_SVELTE_CONFIG.filename && entry.isFile()) {
try {
if (readFileSync(join(root, entry.name), 'utf8') === SCAFFOLD_SVELTE_CONFIG.content) {
continue;
}
} catch {
return false;
}
}
if (entry.name.startsWith('README')) {
continue;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/void/src/cli/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const SCAFFOLD_GITIGNORE_LINES = [
'.DS_Store',
] as const;

export const SCAFFOLD_SVELTE_CONFIG = {
filename: 'svelte.config.mjs',
content: 'export default {};\n',
} as const;

export type ScaffoldFramework = 'react' | 'vue' | 'svelte' | 'solid';
export type ScaffoldStarterMode = 'sqlite' | 'postgresql' | 'mysql' | 'static';
export type ScaffoldToolchain = 'vite-plus' | 'vite';
Expand Down Expand Up @@ -221,6 +226,10 @@ export function createPagesStarterTemplate(options: {
'public/icons.svg': readFileSync(join(assets, 'icons.svg'), 'utf8'),
};

if (framework === 'svelte') {
files[SCAFFOLD_SVELTE_CONFIG.filename] = SCAFFOLD_SVELTE_CONFIG.content;
}

if (starterMode !== 'static') {
files['pages/index.server.ts'] = getIndexServer();
files['routes/api/hello.ts'] = getHelloRoute(config.label, starterMode);
Expand Down
49 changes: 48 additions & 1 deletion packages/void/test/unit/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ describe('isScaffoldableEmptyProject', () => {
});
});

it('replaces stale vp starter scripts when plain Vite is selected', async () => {
it('replaces Vite+ starter scripts when plain Vite is selected', async () => {
const root = mkdtempSync(join(tmpdir(), 'void-init-'));
try {
writeFileSync(
Expand Down Expand Up @@ -2291,6 +2291,7 @@ describe('isScaffoldableEmptyProject', () => {
expect(pkg.devDependencies.vite).toBe('^8.0.10');
expect(pkg.devDependencies['vite-plus']).toBeUndefined();
expect(pkg.devDependencies['@cloudflare/oxlint-config']).toBeUndefined();
expect(readFileSync(join(root, 'svelte.config.mjs'), 'utf8')).toBe('export default {};\n');
const viteConfig = readFileSync(join(root, 'vite.config.ts'), 'utf8');
expect(viteConfig).toContain('from "vite"');
expect(viteConfig).not.toContain('lint:');
Expand All @@ -2300,6 +2301,52 @@ describe('isScaffoldableEmptyProject', () => {
}
});

it('re-scaffolds a Svelte workspace starter when its generated config remains', async () => {
await withTempDirAsync(async (workspace) => {
writeFileSync(join(workspace, 'pnpm-workspace.yaml'), "packages:\n - 'apps/*'\n");
const root = join(workspace, 'apps', 'site');
mkdirSync(root, { recursive: true });
writeFileSync(join(root, 'package.json'), JSON.stringify({ name: 'site', type: 'commonjs' }));
const args = parseInitArgs([
'--toolchain',
'vite-plus',
'--framework',
'svelte',
'--starter',
'static',
'--deploy',
'none',
]);
await runInitCommand(root, args);

for (const entry of [
'pages',
'public',
'vite.config.mts',
'void.config.ts',
'.void-wrangler.jsonc',
]) {
rmSync(join(root, entry), { recursive: true, force: true });
}
expect(isScaffoldableEmptyProject(root)).toBe(true);
await runInitCommand(root, args);

expect(existsSync(join(root, 'pages', 'index.svelte'))).toBe(true);
expect(readFileSync(join(root, 'vite.config.mts'), 'utf8')).toContain('@void/svelte/plugin');
});
});

it('returns false when the Svelte config has user content', () => {
withTempDir((root) => {
writeFileSync(
join(root, 'svelte.config.mjs'),
'export default { compilerOptions: { dev: true } };\n',
);

expect(isScaffoldableEmptyProject(root)).toBe(false);
});
});

it('returns false when app files already exist', () => {
withTempDir((root) => {
mkdirSync(join(root, 'src'), { recursive: true });
Expand Down