fix: trigger full rebuild when a tracked dependency is deleted#20133
fix: trigger full rebuild when a tracked dependency is deleted#20133godfengliang wants to merge 2 commits into
Conversation
Fixes tailwindlabs#20113 Previously, all delete events were unconditionally dropped in the CLI watcher. This meant that deleting a config/plugin dependency file would not trigger a rebuild, leaving stale CSS output. Now, deleted file paths are still added to the tracked files set so the handle callback can detect them as full-rebuild paths and trigger a rebuild that surfaces the missing dependency error.
Confidence Score: 5/5Safe to merge — the change is a single-line addition inside the delete-event branch of the watcher, and all existing paths for non-delete events are untouched. The fix is minimal and surgical: it adds a deleted file's path to the batch set before the early return, then relies entirely on the already-correct No files require special attention. Reviews (2): Last reviewed commit: "fix: correct comment about deleted file ..." | Re-trigger Greptile |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe PR updates the build command's file watcher so delete events add the deleted path to the tracked files set instead of being ignored. Deleted content files still hit the candidate cache; deleted config/plugin dependencies are now tracked so a later full rebuild can detect and report missing-file errors. 🚥 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 |
|
Hey! Closing this in favor of #20137 where we also make sure that we can recover if you re-add the same file without requiring the write to the Thanks for the PR! |
…cy (tailwindlabs#20137) This PR fixes an issue where the `@tailwindcss/cli` can get into a non-recoverable state when any of the transitive dependencies break. Tailwind CSS has 2 kinds of dependencies: 1. All your templates 2. All dependencies that contribute to your configuration such as the `input.css`, any plugins, any `tailwind.config.js` files and so on. When a template changes, we just have to scan for new Tailwind CSS classes and emit a new CSS file. But when the `input.css` file, or any of its dependencies changes, then we want to perform a full rebuild. The idea is that your `@theme` might have changed, or new plugins have been added, or old plugins have been removed. If you have an `input.css` file: ```css @import "tailwindcss"; @config "./tailwind.config.js"; ``` That relies on a custom config: `tailwind.config.js`: ```js const theme = require('./my-custom-theme.js'); module.exports = { theme } ``` If that file relies on yet another file: `./my-custom-theme.js`, then changes there should also trigger a full rebuild. Since we're dealing with JavaScript here, we want to clear the require cache and rebuild the dependency tree such that another change to any of these files triggers a full fresh build. However, if any of those (transitive) dependencies are deleted, then we will end up in an invalid state. Creating a new compiler will result in a build error. The compiler won't be able to figure out the entire dependency tree, and we're stuck. Once the user fixes the potentially missing dependency, the watchers will not be watching any of those files because we created a fresh compiler. With this PR, we fix that by keeping track of old paths and using those while we are still in an invalid state. The moment everything is fixed, a fresh dependency tree is created and everything starts working again without you having to restart the `@tailwindcss/cli` command. Fixes: tailwindlabs#20113 Closes: tailwindlabs#20114 Closes: tailwindlabs#20133 ## Test plan - Added an integration test that removes the transitive dependency. Re-adding that file later will recover the CLI state.
Fix
Fixes #20113
Problem
When a file in the CLI watcher's tracked full-rebuild dependency set (e.g., a config dependency like
my-color.js) is deleted, the watcher does not trigger a rebuild. This happens because all delete events are unconditionally dropped at L485:This means deleting
my-color.js(which is imported bytailwind.config.js) silently keeps the stale CSS output instead of surfacing the missing dependency error.Solution
Instead of unconditionally returning on delete events, add the deleted file path to the tracked files set before returning:
This allows the
handlecallback (L260-346) to properly detect deleted files that are infullRebuildPathsand trigger a full rebuild. The full rebuild will then fail with the appropriate "missing module" error, alerting the user.Test Plan
Follow the reproduction steps from #20113:
tailwind.config.jsimportingmy-color.jstailwindcss --input src/index.css --output dist/out.css --watchmy-color.jsBefore fix: No rebuild triggered, stale CSS kept.
After fix: Full rebuild triggered, error about missing
my-color.jsis shown.