Handle deleted rebuild dependencies in CLI watch#20114
Conversation
WalkthroughThis PR adds delete event handling to the Tailwind CLI watch mode. A new 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
Confidence Score: 5/5The change is narrowly scoped and all existing guard logic correctly handles the new event shape — safe to merge. The core logic change is small and well-contained: one new type, one map replacing a set, and one early-continue for non-tracked deletes. The callback handler already had the right structure to handle delete events correctly, and the test exercises the full error-and-recovery path. No files require special attention. Reviews (2): Last reviewed commit: "Tighten delete event coalescing in CLI w..." | Re-trigger Greptile |
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)
319-323:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPreserve
fullRebuildPathsuntil the reload succeeds.Line 320 clears the tracked full-rebuild dependencies before
createCompiler(...)has succeeded. If that rebuild fails because a config/import/plugin dependency was deleted, recreating the same file no longer triggers a full rebuild, so watch mode stays broken until some other tracked file changes. That’s why the new regression test has to touchsrc/index.css.♻️ Possible fix
clearRequireCache(resolvedFullRebuildPaths) - fullRebuildPaths = inputFilePath ? [inputFilePath] : [] - - // Create a new compiler, given the new `input` - ;[compiler, scanner] = await createCompiler(input, I) + let previousFullRebuildPaths = fullRebuildPaths + fullRebuildPaths = inputFilePath ? [inputFilePath] : [] + + // Create a new compiler, given the new `input` + try { + ;[compiler, scanner] = await createCompiler(input, I) + } catch (error) { + fullRebuildPaths = previousFullRebuildPaths + throw error + }🤖 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 `@packages/`@tailwindcss-cli/src/commands/build/index.ts around lines 319 - 323, The code clears tracked full-rebuild dependencies (clearRequireCache(resolvedFullRebuildPaths) and resetting fullRebuildPaths) before attempting to create a new compiler, which can leave watch mode broken if createCompiler(input, I) fails; change the flow so that you do NOT clearRequireCache or mutate fullRebuildPaths until createCompiler(input, I) has succeeded — either move clearRequireCache(resolvedFullRebuildPaths) and the assignment fullRebuildPaths = inputFilePath ? [inputFilePath] : [] to after the await createCompiler(...) line, or wrap createCompiler(...) in a try/catch and only clear the require cache/assign fullRebuildPaths on success (and restore the old state or leave it untouched on error), keeping references to the existing variables compiler, scanner, inputFilePath, input and resolvedFullRebuildPaths to locate the change.
🤖 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.
Outside diff comments:
In `@packages/`@tailwindcss-cli/src/commands/build/index.ts:
- Around line 319-323: The code clears tracked full-rebuild dependencies
(clearRequireCache(resolvedFullRebuildPaths) and resetting fullRebuildPaths)
before attempting to create a new compiler, which can leave watch mode broken if
createCompiler(input, I) fails; change the flow so that you do NOT
clearRequireCache or mutate fullRebuildPaths until createCompiler(input, I) has
succeeded — either move clearRequireCache(resolvedFullRebuildPaths) and the
assignment fullRebuildPaths = inputFilePath ? [inputFilePath] : [] to after the
await createCompiler(...) line, or wrap createCompiler(...) in a try/catch and
only clear the require cache/assign fullRebuildPaths on success (and restore the
old state or leave it untouched on error), keeping references to the existing
variables compiler, scanner, inputFilePath, input and resolvedFullRebuildPaths
to locate the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 07f53fb2-8a9d-47b7-9f94-2fb50304e18e
📒 Files selected for processing (2)
integrations/cli/config.test.tspackages/@tailwindcss-cli/src/commands/build/index.ts
Fixes #20113.
What changed
Why
The watcher already tracks config/plugin/import dependencies as
fullRebuildPaths, but delete events were being filtered out before that check happened. That meant deleting a tracked dependency could leave the watcher serving stale output until some other full-rebuild file changed.Impact
Deleting a tracked dependency in
--watchmode now behaves like other full-rebuild dependency changes: the watcher rebuilds immediately instead of silently keeping stale state.Validation
pnpm exec vitest --root=./integrations run cli/config.test.tspnpm exec prettier --check packages/@tailwindcss-cli/src/commands/build/index.ts integrations/cli/config.test.tspnpm --dir packages/@tailwindcss-cli lintcurrently reports unrelated repo-wide TypeScript errors outside this change