From 4104aabfeef96130f9ff017812203e9de28f45d1 Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 17 Sep 2022 21:55:28 +0200 Subject: [PATCH 1/3] fix: prettier not working for svelte files in create-svelte projects --- .changeset/light-eagles-call.md | 5 +++++ .../shared/+eslint+prettier/package.json | 4 ++-- .../create-svelte/shared/+prettier/.prettierrc | 1 + .../shared/-eslint+prettier/package.json | 4 ++-- packages/create-svelte/test/check.js | 15 ++++++++++++--- 5 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 .changeset/light-eagles-call.md diff --git a/.changeset/light-eagles-call.md b/.changeset/light-eagles-call.md new file mode 100644 index 000000000000..6e48381d9ed7 --- /dev/null +++ b/.changeset/light-eagles-call.md @@ -0,0 +1,5 @@ +--- +'create-svelte': patch +--- + +fix prettier not formatting svelte files diff --git a/packages/create-svelte/shared/+eslint+prettier/package.json b/packages/create-svelte/shared/+eslint+prettier/package.json index a8b937b25b10..a6492f3856ab 100644 --- a/packages/create-svelte/shared/+eslint+prettier/package.json +++ b/packages/create-svelte/shared/+eslint+prettier/package.json @@ -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 ." } } diff --git a/packages/create-svelte/shared/+prettier/.prettierrc b/packages/create-svelte/shared/+prettier/.prettierrc index d177cd62dd13..a77fddea9097 100644 --- a/packages/create-svelte/shared/+prettier/.prettierrc +++ b/packages/create-svelte/shared/+prettier/.prettierrc @@ -3,6 +3,7 @@ "singleQuote": true, "trailingComma": "none", "printWidth": 100, + "plugins": ["prettier-plugin-svelte"], "pluginSearchDirs": ["."], "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] } diff --git a/packages/create-svelte/shared/-eslint+prettier/package.json b/packages/create-svelte/shared/-eslint+prettier/package.json index bcdff7cf9402..0193de97cbb4 100644 --- a/packages/create-svelte/shared/-eslint+prettier/package.json +++ b/packages/create-svelte/shared/-eslint+prettier/package.json @@ -1,6 +1,6 @@ { "scripts": { - "lint": "prettier --check .", - "format": "prettier --write ." + "lint": "prettier --plugin-search-dir . --check .", + "format": "prettier --plugin-search-dir . --write ." } } diff --git a/packages/create-svelte/test/check.js b/packages/create-svelte/test/check.js index 5e74a81da785..de4f27982c96 100644 --- a/packages/create-svelte/test/check.js +++ b/packages/create-svelte/test/check.js @@ -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'; @@ -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 @@ -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'))) { @@ -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}`); From 986374840249c2bd9e257b611a45702d8c216811 Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 17 Sep 2022 22:12:14 +0200 Subject: [PATCH 2/3] fix: format --- packages/create-svelte/test/check.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/create-svelte/test/check.js b/packages/create-svelte/test/check.js index de4f27982c96..31d14e7f772b 100644 --- a/packages/create-svelte/test/check.js +++ b/packages/create-svelte/test/check.js @@ -26,9 +26,9 @@ const overrides = { ...existing_workspace_overrides }; 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 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; + overrides.vite = vite_version; } catch (e) { console.error('failed to parse installed vite version from packages/kit'); throw e; @@ -108,7 +108,7 @@ for (const template of fs.readdirSync('templates')) { // not all templates have all scripts console.group(`${template}-${types}`); - for (const script of scripts_to_test.filter(s => !!pkg.scripts[s])) { + for (const script of scripts_to_test.filter((s) => !!pkg.scripts[s])) { try { execSync(`pnpm run ${script}`, { cwd, stdio: 'pipe' }); console.log(`✅ ${script}`); From d55a8bf4b6401e1d1307835a628566a392eb6158 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Mon, 19 Sep 2022 10:59:55 +0200 Subject: [PATCH 3/3] changeset format --- .changeset/light-eagles-call.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/light-eagles-call.md b/.changeset/light-eagles-call.md index 6e48381d9ed7..c5aa2bba6ce6 100644 --- a/.changeset/light-eagles-call.md +++ b/.changeset/light-eagles-call.md @@ -2,4 +2,4 @@ 'create-svelte': patch --- -fix prettier not formatting svelte files +[fix] prettier not formatting svelte files