facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 627 forks source link

preserve require.context call when unstable_disableModuleWrapping is enabled #1129

Open EvanBacon opened 1 year ago

EvanBacon commented 1 year ago

Summary

One possible way to implement tree shaking would require calling collectDependencies with unstable_disableModuleWrapping for a first pass, and invoking it a second time with module wrapping. The issue with this is that the require.context mutation is mutated to a format that wouldn't work on subsequent runs.

This PR will prevent the additional mutation of require.context -> require.

Test plan

Tests continue working

codecov-commenter commented 1 year ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (6151e7e) 83.09% compared to head (3fd29e3) 83.09%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1129 +/- ## ======================================= Coverage 83.09% 83.09% ======================================= Files 206 206 Lines 10547 10548 +1 Branches 2617 2618 +1 ======================================= + Hits 8764 8765 +1 Misses 1783 1783 ``` | [Files](https://app.codecov.io/gh/facebook/metro/pull/1129?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=facebook) | Coverage Δ | | |---|---|---| | [packages/metro-transform-worker/src/index.js](https://app.codecov.io/gh/facebook/metro/pull/1129?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=facebook#diff-cGFja2FnZXMvbWV0cm8tdHJhbnNmb3JtLXdvcmtlci9zcmMvaW5kZXguanM=) | `87.03% <ø> (ø)` | | | [...etro/src/ModuleGraph/worker/collectDependencies.js](https://app.codecov.io/gh/facebook/metro/pull/1129?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=facebook#diff-cGFja2FnZXMvbWV0cm8vc3JjL01vZHVsZUdyYXBoL3dvcmtlci9jb2xsZWN0RGVwZW5kZW5jaWVzLmpz) | `98.46% <100.00%> (+<0.01%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.