fix: prettier tailwind path for save on format#112
Conversation
| const roots = []; | ||
|
|
||
| // 1. PWD / VSCODE_CWD env vars — set to the project root by the shell and | ||
| // VSCode, and unlike process.cwd() they survive being reset to '/'. |
There was a problem hiding this comment.
Werkt trouwens ook voor PHPStorm users
There was a problem hiding this comment.
Pull request overview
This PR updates @yardinternet/prettier-config to reliably locate the Tailwind stylesheet when Prettier runs via “format on save” (where process.cwd() may not reflect the project root), ensuring Tailwind class sorting works again in editor integrations.
Changes:
- Add a utility to search for the Tailwind stylesheet from multiple likely project roots (env vars, inferred root from
__dirname, andprocess.cwd()). - Update the Prettier config entrypoint to use this utility and only set
tailwindStylesheetwhen found.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/prettier-config/src/utils/find-tailwind-stylesheet.js | New helper to locate the Tailwind stylesheet from multiple roots. |
| packages/prettier-config/src/index.js | Swaps fixed process.cwd()-based lookup for the new helper and conditionally sets tailwindStylesheet. |
| // 2. Installed normally (no symlink): strip at the first node_modules boundary. | ||
| const nmIndex = __dirname.indexOf( 'node_modules' ); | ||
| if ( nmIndex > 0 ) { | ||
| roots.push( __dirname.substring( 0, nmIndex - 1 ) ); |
There was a problem hiding this comment.
The __dirname.substring( 0, nmIndex - 1 ) calculation can drop the root path separator on Windows when the project lives at the drive root (e.g. C:\node_modules\...), resulting in C: (not C:\) and causing path.resolve() to base the path on the current drive CWD instead of the drive root. Use __dirname.slice( 0, nmIndex ) (optionally followed by a trim of trailing separators that preserves C:\) to reliably get the directory before node_modules across platforms.
| roots.push( __dirname.substring( 0, nmIndex - 1 ) ); | |
| roots.push( __dirname.slice( 0, nmIndex ) ); |
Het sorteren van Tailwind classes met format on save doet het weer. Was gedoe met het resolven van een path in node_modules, maar ook als je 'm hebt gesymlinked om te testen. Claude heeft z'n best moeten doen hiervoor.