Fix Vite resolution for bare CSS imports#20056
Conversation
Confidence Score: 5/5Safe to merge — the fallback is strictly additive, only fires after all Vite resolvers have already failed, and is guarded by multiple narrow conditions that prevent it from intercepting legitimate package imports. The fallback logic is well-constrained: it requires a bare filename with no path separators, no leading dot, a non-absolute path, a passing filter, and actual filesystem presence — all of which must be true before the fallback activates. The existing resolver chain is completely unchanged; this only runs when every upstream resolver returns nothing. Both build and dev-mode integration tests are included and mirror the pattern used throughout the file. No files require special attention. Reviews (2): Last reviewed commit: "test(vite): cover bare css imports in de..." | Re-trigger Greptile |
WalkthroughAdds a fallback in packages/@tailwindcss-vite/src/index.ts so createCustomResolver resolves non-relative, non-absolute CSS imports like "components.css" by checking path.resolve(base, id) and returning it when the file exists. Adds two Vitest integration tests in integrations/vite/resolvers.test.ts: one verifies the behavior during a production build by snapshotting emitted CSS, the other verifies the behavior in dev mode by fetching the compiled stylesheet and asserting the expected rules and declarations. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
integrations/vite/resolvers.test.ts (1)
587-647: ⚡ Quick winAdd a dev-mode companion test for this regression.
This case reproduces in build, but the reported failure path is
@tailwindcss/vite:generate:serve. Please add apnpm vite devvariant of the same fixture/assertion to lock coverage on the serve resolver path too.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@integrations/vite/resolvers.test.ts` around lines 587 - 647, Duplicate the existing "resolve bare CSS imports in the same folder" test as a dev-mode variant that runs the dev server instead of build: use the same fs fixture and vite.config.ts, call exec('pnpm vite dev') (or appropriate command the test harness uses for starting dev) and wait for the dev server to finish startup; then assert the served/generated CSS matches the same expected content (the .component-style CSS) to exercise the `@tailwindcss/vite`:generate:serve code path. Ensure the new test name indicates it's a dev-mode variant and reuse the same assertions/normalization (e.g. replacing hashed names) so coverage hits the serve resolver path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@integrations/vite/resolvers.test.ts`:
- Around line 587-647: Duplicate the existing "resolve bare CSS imports in the
same folder" test as a dev-mode variant that runs the dev server instead of
build: use the same fs fixture and vite.config.ts, call exec('pnpm vite dev')
(or appropriate command the test harness uses for starting dev) and wait for the
dev server to finish startup; then assert the served/generated CSS matches the
same expected content (the .component-style CSS) to exercise the
`@tailwindcss/vite`:generate:serve code path. Ensure the new test name indicates
it's a dev-mode variant and reuse the same assertions/normalization (e.g.
replacing hashed names) so coverage hits the serve resolver path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 609e9053-645e-4573-934b-99afc06dc96c
📒 Files selected for processing (2)
integrations/vite/resolvers.test.tspackages/@tailwindcss-vite/src/index.ts
Summary
Fixes #19719.
When Vite's CSS resolver treats a same-folder import like
@import "components.css"as a package import, Tailwind currently reports that the file cannot be resolved. This keeps the existing Vite resolver flow first, then adds a narrow fallback for bare.cssfilenames that exist next to the importing stylesheet.Test plan
pnpm buildpnpm run test:integrations vite/resolvers.test.ts -t "resolve bare CSS imports in the same folder"git diff --checkpnpm exec prettier --check packages/@tailwindcss-vite/src/index.ts