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
5 changes: 5 additions & 0 deletions .changeset/format-created-project-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix: format all created project files when using the prettier add-on
7 changes: 5 additions & 2 deletions packages/sv/src/cli/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const create = new Command('create')
})
.showHelpAfterError(true);

async function createProject(cwd: ProjectPath, options: Options) {
export async function createProject(cwd: ProjectPath, options: Options) {
if (options.fromPlayground) {
p.log.warn(
'Svelte maintainers have not reviewed playgrounds for malicious code! Use at your discretion.'
Expand Down Expand Up @@ -415,7 +415,10 @@ async function createProject(cwd: ProjectPath, options: Options) {
if (packageManager) {
depsInstalled = await installDependencies(packageManager, projectPath);
if (depsInstalled) {
await formatFiles({ packageManager, cwd: projectPath, filesToFormat: addOnFilesToFormat });
const filesToFormat = addOnSuccessfulAddons.some((addon) => addon.addon.id === 'prettier')
? ['.']
: addOnFilesToFormat;
await formatFiles({ packageManager, cwd: projectPath, filesToFormat });
}
}

Expand Down
28 changes: 26 additions & 2 deletions packages/sv/src/create/tests/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { promisify } from 'node:util';
import { exec } from 'tinyexec';
import { beforeAll, describe, expect, test } from 'vitest';
import { add, officialAddons } from '../../../../sv/src/index.ts';
import { createProject } from '../../cli/create.ts';
import { type LanguageType, type TemplateType, create } from '../index.ts';

// Resolve the given path relative to the current file
Expand Down Expand Up @@ -48,8 +49,31 @@ for (const template of templates.filter((t) => t !== 'addon')) {
const cwd = path.join(test_workspace_dir, `${template}-${types}`);
fs.rmSync(cwd, { recursive: true, force: true });

create({ cwd, name: `create-svelte-test-${template}-${types}`, template, types });
await add({ cwd, addons: { eslint: officialAddons.eslint }, options: { eslint: {} } });
if (template === 'demo' && types === 'typescript') {
const ignoredArtifact = path.join(cwd, 'static', 'ignored.json');
fs.mkdirSync(path.dirname(ignoredArtifact), { recursive: true });
fs.writeFileSync(ignoredArtifact, '{"ignored":true}');

await createProject(cwd, {
types,
addOns: true,
add: ['prettier', 'eslint'],
install: 'pnpm',
template,
fromPlayground: undefined,
dirCheck: false,
downloadCheck: false
});

describe('prettier ignore', () => {
test(`${template}-${types}`, () => {
expect(fs.readFileSync(ignoredArtifact, 'utf-8')).toBe('{"ignored":true}');
});
});
} else {
create({ cwd, name: `create-svelte-test-${template}-${types}`, template, types });
await add({ cwd, addons: { eslint: officialAddons.eslint }, options: { eslint: {} } });
}

const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'));

Expand Down