Repository navigation
fix(codemod): escape regex characters in import module - #49842
lakotiasaikiran wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
a762f50 to
c3fe1bf
Compare
Deploy previewBundle size
PerformanceNo regressions in 32 benchmarks · precise to ±9.4% (±15.1% at worst) · ran 4m 15s · details Check out the code infra dashboard for more information about this PR. |
|
I checked the Argos visual comparison. The only changed snapshot is My changes are limited to the The targeted codemod tests are passing locally (3/3). |
|
Thanks for the PR! |
Problem
The top-level-imports codemod constructs a regular expression using the importModule option without escaping special regex characters.
For example, when importModule is @mui/material.js, the codemod incorrectly matches an import from @mui/materialXjs/Button, even though it belongs to a different package.
Solution
Escaped regex metacharacters in importModule before constructing the regular expression. This ensures that the codemod matches the configured package name literally.
Testing
Added a regression test for incorrect package matching.
Verified that the new test fails before the fix.
Verified that all 3 tests pass after the fix.
Checked code formatting using Prettier.
Verified the changes using git diff --check.
Result
Prevents the codemod from rewriting imports belonging to unrelated packages.