Skip to content

Commit

Permalink
[fix] prettier not working for svelte files in create-svelte projects (
Browse files Browse the repository at this point in the history
…#6866)

Fixes #6804

Also updates the test script for create-svelte to ensure to always install the Vite version that is part of the lock file to prevent type/etc mismatches
  • Loading branch information
dominikg authored Sep 19, 2022
1 parent ec456df commit 434df79
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-eagles-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

[fix] prettier not formatting svelte files
4 changes: 2 additions & 2 deletions packages/create-svelte/shared/+eslint+prettier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"eslint-config-prettier": "^8.3.0"
},
"scripts": {
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
}
}
1 change: 1 addition & 0 deletions packages/create-svelte/shared/+prettier/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
4 changes: 2 additions & 2 deletions packages/create-svelte/shared/-eslint+prettier/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"lint": "prettier --check .",
"format": "prettier --write ."
"lint": "prettier --plugin-search-dir . --check .",
"format": "prettier --plugin-search-dir . --write ."
}
}
15 changes: 12 additions & 3 deletions packages/create-svelte/test/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs';
import { execSync } from 'child_process';
import path from 'path';
import { test } from 'uvu';
import { Writable } from 'stream';
import * as assert from 'uvu/assert';
import { create } from '../index.js';
import { fileURLToPath } from 'url';
Expand All @@ -25,6 +24,16 @@ const overrides = { ...existing_workspace_overrides };
overrides[name] = path.dirname(path.resolve(pkgPath));
});

try {
const kit_dir = fileURLToPath(new URL('../../../packages/kit', import.meta.url));
const ls_vite_result = execSync(`pnpm ls --json vite`, { cwd: kit_dir });
const vite_version = JSON.parse(ls_vite_result)[0].devDependencies.vite.version;
overrides.vite = vite_version;
} catch (e) {
console.error('failed to parse installed vite version from packages/kit');
throw e;
}

test.before(() => {
try {
// prepare test pnpm workspace
Expand Down Expand Up @@ -90,7 +99,7 @@ for (const template of fs.readdirSync('templates')) {
execSync('pnpm install --no-frozen-lockfile', { cwd, stdio: 'ignore' });

// run provided scripts that are non-blocking. All of them should exit with 0
const scripts_to_test = ['prepare', 'check', 'lint', 'build', 'sync'];
const scripts_to_test = ['sync', 'format', 'lint', 'check', 'build'];

// package script requires lib dir
if (fs.existsSync(path.join(cwd, 'src', 'lib'))) {
Expand All @@ -99,7 +108,7 @@ for (const template of fs.readdirSync('templates')) {

// not all templates have all scripts
console.group(`${template}-${types}`);
for (const script of Object.keys(pkg.scripts).filter((s) => scripts_to_test.includes(s))) {
for (const script of scripts_to_test.filter((s) => !!pkg.scripts[s])) {
try {
execSync(`pnpm run ${script}`, { cwd, stdio: 'pipe' });
console.log(`✅ ${script}`);
Expand Down

0 comments on commit 434df79

Please sign in to comment.