fix: resolve tailwindcss from file directory in monorepo setups#365
Open
hirbod wants to merge 1 commit intoschoero:mainfrom
Open
fix: resolve tailwindcss from file directory in monorepo setups#365hirbod wants to merge 1 commit intoschoero:mainfrom
hirbod wants to merge 1 commit intoschoero:mainfrom
Conversation
When the linter process runs from a different directory than where tailwindcss is installed (common with IDE extensions in monorepos), the plugin now falls back to resolving from the file being linted and walks up the directory tree. Also fixes resolveJson to return undefined on failure instead of the input path, which previously caused ENOENT errors instead of the graceful "not installed" fallback. Closes schoero#361
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In monorepos, IDE extensions (e.g. VS Code oxlint/eslint) run the linter from the repository root, while
tailwindcssis installed in a workspace subdirectory. The plugin only looked fortailwindcssrelative toctx.cwd(the linter process directory), causing:resolveJsonreturned the raw input path on failure instead ofundefined, bypassing the "not installed" guard and crashing withENOENT: no such file or directory, open 'tailwindcss/package.json'cwdoption from fix: remove auto detection of project root #364, no single relative path works for both IDE (repo root) and CLI (package directory) contextsSee #361 and this comment for the original report.
Fix
resolveJson: Returnundefinedon resolution failure instead of the input path. This ensures theif(!packageJsonPath)guard increateRuleworks correctly.createRule: Whentailwindcssis not found at the configuredcwd, fall back to resolving from the directory of the file being linted. The enhanced-resolve walker findstailwindcssby walking up the directory tree from the file, which always works regardless of where the linter process started. The resolved package location is then used to derive the correctcwdfor downstream resolution (entryPoint,theme.css, etc.).This makes most monorepo setups work without any
cwdconfiguration.Changes
src/async-utils/resolvers.ts—resolveJsonreturnsundefinedon failuresrc/utils/rule.ts— file-directory fallback whentailwindcssis not found atcwdtests/unit/monorepo-resolution.test.ts— tests for monorepo root and workspace cwd scenariosdocs/settings/settings.md— improvedcwddocs with monorepo explanation