fix: prettier not working for svelte files in create-svelte projects#6866
fix: prettier not working for svelte files in create-svelte projects#6866dummdidumm merged 3 commits intosveltejs:masterfrom
Conversation
🦋 Changeset detectedLatest commit: d55a8bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| "plugins": ["prettier-plugin-svelte"], | ||
| "pluginSearchDirs": ["."], |
There was a problem hiding this comment.
Maybe we should do
| "plugins": ["prettier-plugin-svelte"], | |
| "pluginSearchDirs": ["."], | |
| "plugins": ["./node_modules/prettier-plugin-svelte"], |
instead? I'm using this hack for all my projects which works well when running prettier through the CLI or VSCode extension. The --plugin-search-dir . can also be removed too.
I made a comment at sveltejs/prettier-plugin-svelte#155 (comment)
There was a problem hiding this comment.
would that work with yarn? also the search dir setting is likely needed if the users add more prettier plugins.
There was a problem hiding this comment.
Hmm yeah my suggestion doesn't seem to work with yarn pnp (pnp also messes up vscode prettier plugin with this PR change and before). I guess we can go with this PR change still to have it partially working for yarn pnp.
also the search dir setting is likely needed if the users add more prettier plugins.
Since they'd have to still add them in plugins with this PR, e.g. "plugins": ["prettier-plugin-svelte", "prettier-plugin-something"], I don't think the plugin-search-dir would make a difference, besides not needing the ./node_modules/ part of my suggestion.
There was a problem hiding this comment.
i prefer not having node_modules listed explicitly. I'd love to get rid of the --plugin-search-dir . on the cli though so it's a tough one. Ultimately this PR uses multiple ways to try and ensure the plugin is found. The only other option i know would be to use prettierrc.cjs and require('prettier-plugin-svelte') to take resolving out of prettiers own hands. But thats also ugly.
I think the way this PR uses both json rc and cli option to ensure the plugin is found during api and cli use is working and has only one duplication, which is unfortunate but not that bad.
There was a problem hiding this comment.
Let's go with this solution then
fixes #6804
i'm not sure why this is needed again, it was previously removed in favor of the
pluginSearchDirssetting in prettierrc.Now we use both.
Note: the tests for create-svelte received 2 updates
pnpm checkduring testsformat, removeprepareand sort them differentlyPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0