Skip to content

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

Open
mvanhorn wants to merge 1 commit intotailwindlabs:mainfrom
mvanhorn:osc/16784-fix-watch-case-sensitive
Open

Fix case-sensitive file path comparison in watch mode on Windows#19774
mvanhorn wants to merge 1 commit intotailwindlabs:mainfrom
mvanhorn:osc/16784-fix-watch-case-sensitive

Conversation

@mvanhorn
Copy link

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
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

Walkthrough

The PR introduces a new path comparison utility to handle platform-specific path comparisons. A new pathsEqual function is added that performs case-insensitive comparisons on Windows and case-sensitive comparisons on other platforms. The build command is updated to use this utility for comparing file paths instead of strict equality checks, specifically in the watcher debounce logic and full rebuild decision paths. Comprehensive tests are included to verify the utility's behavior across different platforms.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—fixing case-sensitive file path comparison in watch mode on Windows.
Description check ✅ Passed The description is directly related to the changeset, explaining the issue, solution, and testing approach for the path comparison fix.
Linked Issues check ✅ Passed The PR successfully addresses issue #16784 by implementing case-insensitive path comparison on Windows, both for output file identity checks and full rebuild path matching, with appropriate unit tests.
Out of Scope Changes check ✅ Passed All changes are in scope: pathsEqual utility creation and its application to the build command's watcher and rebuild logic, directly addressing the Windows path casing issue.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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

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