Prevent @tailwindcss/upgrade from rewriting files inside node_modules when run from a workspace subpackage - #20329
Conversation
WalkthroughThe upgrade analyzer now accepts its working-directory base, resolves the Git repository root, and uses that root when checking 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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: 4/5The CSS analysis path is correctly fixed, but the identical The template migration code in
Reviews (3): Last reviewed commit: "update CHANGELOG" | Re-trigger Greptile |
|
Thanks @greptile-apps — good catch on the self-documentation. Test now declares the root |
|
Agreed — the comment you added in the That's exactly the right call. A future reader who removes or modifies that Tip: You can customize Greptile's behavior for this repo with |
…les` when run from a workspace subpackage
Notes by Robin Malfait: Split the commit in 2, because I want to be able to see the test fail _before_ we apply the fix.
cff1356 to
b8ede71
Compare
b8ede71 to
eb97c9a
Compare
RobinMalfait
left a comment
There was a problem hiding this comment.
Thanks! Made a few small changes, and split your original commit such that I could see the test fail before we apply the fix. The test did indeed fail and passed afterwards 💪
Once CI passes (running on Linux / macOS / Windows), this will be merged and will be available in the next release. Thanks!
Forgot this as part of #20329
Fixes #20328.
What changed
When
@tailwindcss/upgradeis invoked from a subpackage of a workspace (e.g.pnpm --filter …orcd packages/foo && pnpm exec upgrade), it traverses../../node_modules/…and applies its v3 → v4 migration transform (@tailwind utilities;→@import 'tailwindcss/utilities' layer(utilities);) to files inside the installedtailwindcsspackage itself — a self-referential import that later detonates as an infinite CSS-resolution loop and reads like a "cache corruption" bug (matches the report in #19726 / #20328).Root cause:
globby'sisGitIgnoredonly walks.gitignorefiles at or below itscwd. When invoked from a subpackage, the workspace-root.gitignore(which almost always listsnode_modules) is never consulted, and../../node_modules/…paths come back as not ignored.The fix anchors
isGitIgnoredat the git repository root instead of the subpackage:gitRoot(cwd)insrc/utils/git.ts— thin wrapper overgit rev-parse --show-toplevel.analyze(stylesheets, { base })insrc/codemods/css/analyze.tsnow callsisGitIgnored({ cwd: gitRoot(base) ?? base }). Falls back to the previous behavior when not inside a git repository or whengitis unavailable.Test
Added an integration test that reproduces the exact scenario: a pnpm workspace with a subpackage that imports
tailwindcss/utilities.css, upgrade run from the subpackage, then assertspackages/css/node_modules/tailwindcss/utilities.cssstill holds the pristine@tailwind utilities;directive.Verified the test fails on
mainand passes with this change.The 415 existing upgrade unit tests still pass. Two npm-related snapshot failures in
upgrade-errors.test.ts(half-upgraded v3 project to v4 (bun|npm)) pre-exist this change — they're about newer npm'snpm notice runoutput that isn't in the snapshots, unrelated to what this PR touches.Edit by @RobinMalfait: going to run on all [ci-all] so we can make sure it works on Windows as well.