Skip to content

fix: prettier tailwind path for save on format#112

Merged
YvetteNikolov merged 1 commit into
mainfrom
fix/tailwind-path-for-save-on-format
Apr 15, 2026
Merged

fix: prettier tailwind path for save on format#112
YvetteNikolov merged 1 commit into
mainfrom
fix/tailwind-path-for-save-on-format

Conversation

@YvetteNikolov
Copy link
Copy Markdown
Contributor

@YvetteNikolov YvetteNikolov commented Apr 15, 2026

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.

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 '/'.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Werkt trouwens ook voor PHPStorm users

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and process.cwd()).
  • Update the Prettier config entrypoint to use this utility and only set tailwindStylesheet when 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 ) );
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
roots.push( __dirname.substring( 0, nmIndex - 1 ) );
roots.push( __dirname.slice( 0, nmIndex ) );

Copilot uses AI. Check for mistakes.
@YvetteNikolov YvetteNikolov merged commit c76085b into main Apr 15, 2026
5 checks passed
@YvetteNikolov YvetteNikolov deleted the fix/tailwind-path-for-save-on-format branch April 15, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants