Skip to content

Fix case-sensitive file path comparison in watch mode on Windows - #19774

Open
mvanhorn wants to merge 5 commits into
tailwindlabs:mainfrom
mvanhorn:osc/16784-fix-watch-case-sensitive
Open

mvanhorn wants to merge 5 commits into
tailwindlabs:mainfrom
mvanhorn:osc/16784-fix-watch-case-sensitive

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Fixes #16784

On Windows (case-insensitive filesystem), the CLI --watch mode doesn't rebuild when the input file path casing differs from what exists on disk. For example, if the file is src/Input.css but the watcher reports src/input.css, the comparison fails silently.

The fix adds a pathsEqual() helper that uses case-insensitive comparison on process.platform === 'win32'. This is applied to:

  • Output file identity check (preventing infinite rebuild loops)
  • Full rebuild path matching (detecting when input CSS or config files change)

[ci-all]

Test plan

  • Added unit tests for pathsEqual() verifying identical paths match, different paths don't, and platform-appropriate case sensitivity
  • All 4623 existing tests pass
  • pnpm build && pnpm test passes

This contribution was developed with AI assistance (Claude Code).

On Windows (case-insensitive filesystem), file paths reported by the
watcher may differ in casing from the resolved input/output paths. This
caused watch mode to miss full rebuilds when the input CSS path had
different casing, and could also cause infinite rebuild loops when the
output file path casing didn't match.

Add a `pathsEqual()` helper that normalizes case on Windows and use it
for the two path comparisons in the watch handler:
- `resolvedFullRebuildPaths` membership check
- output file identity check

Closes tailwindlabs#16784

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mvanhorn
mvanhorn requested a review from a team as a code owner March 10, 2026 07:53
@coderabbitai

coderabbitai Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b18d9d8-b289-4b1b-9bc8-39b77ffab5a2
Commits

Reviewing files that changed from the base of the PR and between a1a6f10 and 6a030fc.

Files selected for processing: 1
  • integrations/cli/index.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The PR adds pathsEqual, which compares paths case-insensitively on Windows and case-sensitively on other platforms. The build command uses it for input/output collision checks, watcher and polling exclusions, and rebuild decisions. Tests cover path equality and rebuild behavior across operating systems. A Windows-only integration test checks that watch mode rebuilds when the input path casing differs from the on-disk path.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 6a030

The change addresses Windows path casing, with no merge-blocking issue identified. Windows CI has not yet run.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: fixing case-sensitive path comparisons in Windows watch mode.
Description check Passed The description is directly related to the changeset. It explains the Windows watch-mode issue, the pathsEqual() fix, affected comparisons, and test coverage.
Linked Issues check Passed [#16784] requires CLI --watch to rebuild on Windows when the input path casing differs from the on-disk casing. pathsEqual() performs case-insensitive comparison for win32. `getRebuildStrategy()…
Out of Scope Changes check Passed The changes support [#16784]. They add the path helper, apply it to watch-mode identity and rebuild checks, and add focused unit and Windows integration tests. The getRebuildStrategy extraction supp…
Full details: Linked Issues check

Explanation

[#16784] requires CLI --watch to rebuild on Windows when the input path casing differs from the on-disk casing. pathsEqual() performs case-insensitive comparison for win32. getRebuildStrategy() uses it for full-rebuild path matching. The CLI watcher uses this strategy. The Windows-only integration test starts with Src/Index.css while the file is src/index.css, then verifies that a theme change rebuilds the output. Unit tests also cover platform-specific path behavior. Output identity checks use the same helper.

Full details: Out of Scope Changes check

Explanation

The changes support [#16784]. They add the path helper, apply it to watch-mode identity and rebuild checks, and add focused unit and Windows integration tests. The getRebuildStrategy extraction supports isolated testing. The changelog entry documents the fix. The polling exclusion for the configured map path supports the watcher's output self-trigger guard. No unrelated change is demonstrated.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/@tailwindcss-cli/src/commands/build/index.ts (1)

113-119: ⚠️ Potential issue | 🟠 Major

Use pathsEqual in the input/output self-overwrite guard too.

This check is still case-sensitive, so on Windows --input and --output can point at the same file with different casing and bypass the safety check.

Suggested fix
-  if (args['--input'] === args['--output'] && args['--input'] !== '-') {
+  if (
+    args['--input'] !== '-' &&
+    args['--output'] !== '-' &&
+    args['--input'] &&
+    args['--output'] &&
+    pathsEqual(args['--input'], args['--output'])
+  ) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/`@tailwindcss-cli/src/commands/build/index.ts around lines 113 -
119, Replace the strict equality check for input/output with the platform-aware
comparator: instead of if (args['--input'] === args['--output'] &&
args['--input'] !== '-') use pathsEqual(args['--input'], args['--output']) &&
args['--input'] !== '-'; ensure pathsEqual is imported/available in this module
and keep the existing eprintln(...) and process.exit(1) behavior (still compute
highlighted relative paths with relative(args['--input']) /
relative(args['--output'])).
🧹 Nitpick comments (1)
packages/@tailwindcss-cli/src/utils/paths-equal.test.ts (1)

25-35: Exercise both branches in every test run.

This conditional only validates the current host platform, so a non-Windows CI job never executes the Windows behavior this PR is fixing. I’d make the platform choice injectable (or factor the branch into a helper) so both cases are asserted everywhere.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/`@tailwindcss-cli/src/utils/paths-equal.test.ts around lines 25 -
35, The test currently only runs the branch for the host OS; update the tests to
exercise both branches by making the platform decision injectable or by
factoring the logic into a helper so you can force the platform in tests.
Specifically, modify the implementation of pathsEqual (or export a helper) so it
accepts a platform flag (or expose an isCaseSensitive/platform helper) and then
in paths-equal.test.ts call pathsEqual with both 'win32' and a non-Windows
platform to assert true and false respectively; reference the pathsEqual
function (and the new injectable/platform helper) so both behaviors are asserted
on every CI run.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/`@tailwindcss-cli/src/commands/build/index.ts:
- Around line 113-119: Replace the strict equality check for input/output with
the platform-aware comparator: instead of if (args['--input'] ===
args['--output'] && args['--input'] !== '-') use pathsEqual(args['--input'],
args['--output']) && args['--input'] !== '-'; ensure pathsEqual is
imported/available in this module and keep the existing eprintln(...) and
process.exit(1) behavior (still compute highlighted relative paths with
relative(args['--input']) / relative(args['--output'])).

---

Nitpick comments:
In `@packages/`@tailwindcss-cli/src/utils/paths-equal.test.ts:
- Around line 25-35: The test currently only runs the branch for the host OS;
update the tests to exercise both branches by making the platform decision
injectable or by factoring the logic into a helper so you can force the platform
in tests. Specifically, modify the implementation of pathsEqual (or export a
helper) so it accepts a platform flag (or expose an isCaseSensitive/platform
helper) and then in paths-equal.test.ts call pathsEqual with both 'win32' and a
non-Windows platform to assert true and false respectively; reference the
pathsEqual function (and the new injectable/platform helper) so both behaviors
are asserted on every CI run.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ea04a4d8-0679-484c-8a3c-6bed62d84a6a

📥 Commits

Reviewing files that changed from the base of the PR and between c586bd6 and 8021b80.

📒 Files selected for processing (3)
  • packages/@tailwindcss-cli/src/commands/build/index.ts
  • packages/@tailwindcss-cli/src/utils/paths-equal.test.ts
  • packages/@tailwindcss-cli/src/utils/paths-equal.ts

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous test-coverage finding addressed.

Reviews (3) · Last reviewed commit: "Add a Windows watch mode test for differ..." · Reviewed by Greptile

Move getRebuildStrategy next to the other build helpers so a test can reach it
without loading the native scanner, and let it take the platform. The new tests
fail if the rebuild check goes back to a case-sensitive comparison.

Also add the changelog entry for this fix.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Pushed a1a6f10 for the review note that watch behavior stayed untested. I added unit coverage rather than the end-to-end test it asked for.

The rebuild decision moved into getRebuildStrategy in commands/build/utils.ts, which takes the platform as an argument. utils.test.ts covers a differently cased input file on win32 (full rebuild), the same paths on linux (incremental), and a non-rebuild file on win32 (incremental). Swapping the comparison back to === fails the win32 test.

I did not add a test that starts the CLI with differently cased paths, since I have no Windows host to run it on, so that review thread is still open.

Tested on macOS with Node 24.18 and Rust 1.95: vitest passes (5664 passed, 1 skipped) and cargo test passes. pnpm run lint fails here the same way on the base commit, on wasm build output and type errors outside these files; tracked files pass prettier. CI is waiting for workflow approval, so nothing has run on Windows yet. The PR body has [ci-all], so the Windows jobs will run once it is approved.

Starts the CLI with --input Src/Index.css while the file on disk is
src/index.css, then changes the theme in that file. The theme change only
lands through a full rebuild, so the test fails if watch mode stops
recognizing the input file.
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.

npx watch is case sensitve

1 participant