Fix case-sensitive file path comparison in watch mode on Windows#19774
Fix case-sensitive file path comparison in watch mode on Windows#19774mvanhorn wants to merge 1 commit intotailwindlabs:mainfrom
Conversation
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>
WalkthroughThe PR introduces a new path comparison utility to handle platform-specific path comparisons. A new 🚥 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.
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 | 🟠 MajorUse
pathsEqualin the input/output self-overwrite guard too.This check is still case-sensitive, so on Windows
--inputand--outputcan 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
📒 Files selected for processing (3)
packages/@tailwindcss-cli/src/commands/build/index.tspackages/@tailwindcss-cli/src/utils/paths-equal.test.tspackages/@tailwindcss-cli/src/utils/paths-equal.ts
Summary
Fixes #16784
On Windows (case-insensitive filesystem), the CLI
--watchmode doesn't rebuild when the input file path casing differs from what exists on disk. For example, if the file issrc/Input.cssbut the watcher reportssrc/input.css, the comparison fails silently.The fix adds a
pathsEqual()helper that uses case-insensitive comparison onprocess.platform === 'win32'. This is applied to:[ci-all]
Test plan
pathsEqual()verifying identical paths match, different paths don't, and platform-appropriate case sensitivitypnpm build && pnpm testpassesThis contribution was developed with AI assistance (Claude Code).