Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental transformer setting for disabling require() renaming #677

Closed

Conversation

tido64
Copy link
Contributor

@tido64 tido64 commented Jun 14, 2021

Summary

Adds a flag, unstable_disableModuleWrapping, that disables wrapping of JS modules and transforming require(...) calls to $$_REQUIRE(dependencyMap[n], ...). This is required for plugging in third-party bundlers such as esbuild.

Test plan

A test has been added to ensure that require() calls are untouched.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 14, 2021
@tido64
Copy link
Contributor Author

tido64 commented Jun 14, 2021

cc @motiz88

@motiz88
Copy link
Contributor

motiz88 commented Jun 17, 2021

Looks good! Can you share how you tested the getGraphId and transformHelpers changes? They do not seem to be covered by the metro-transform-worker unit test.

@tido64 tido64 force-pushed the tido/disable-require-transforms branch from 1d4dc01 to 57230a9 Compare June 23, 2021 11:03
@motiz88
Copy link
Contributor

motiz88 commented Jun 23, 2021

On reflection, I'm unclear on why the new option needs to live in getTransformOptions() / ExtraTransformOptions which is used for "dynamic" config (i.e. options that can be set during bundling based on querying the dependency graph). It's a degree of freedom that we're trying to remove from Metro and which I don't believe is needed here.

Seems to me that this option should either

  1. be considered part of the bundle request, in which case you can add it to parseOptionsFromUrl and specify it as a URL param; or
  2. be considered part of the "static" config i.e. moved from JsTransformerOptions to JsTransformerConfig and specified directly under the transformer key in metro.config.js.

I'm leaning towards (2) since it matches how you would configure the esbuild "serializer" (I assume) - you need to pass this flag iff you're using esbuild as your serializer, i.e. any extra degree of freedom to set this flag (either in the bundle request or getTransformOptions) could only lead to bugs.

@tido64
Copy link
Contributor Author

tido64 commented Jun 23, 2021

I'm leaning towards (2) since it matches how you would configure the esbuild "serializer" (I assume) - you need to pass this flag iff you're using esbuild as your serializer, i.e. any extra degree of freedom to set this flag (either in the bundle request or getTransformOptions) could only lead to bugs.

Thanks for explaining this to me. It makes a lot of more sense now. I wasn't sure what the difference was, but we definitely want (2). I've made the appropriate changes. Please have another look.

@facebook-github-bot
Copy link
Contributor

@motiz88 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@motiz88 merged this pull request in 598de6f.

facebook-github-bot pushed a commit that referenced this pull request Jul 1, 2021
Summary:
Draft changelog:

* **[Feature]** Add option to use the Hermes parser in the transformer. (6dae163)
* **[Feature]** Update the list of default React Native lazy imports to match the [removal of Picker](facebook/react-native@ad0ccac), which was already deprecated. (7dcb20d)
* **[Feature]** Make the input transform options (e.g. `platform`) available to `experimentalSerializerHook` and `customSerializer`. (#679)
* **[Fix]** Avoid triggering Babel scope caching bugs. (4fea2bd, 1370b7a)
* **[Fix]** Fix Hermes debugger proxy for IPv6. (#662)
* **[Types]** Remove documentation and types for the `postMinifyProcess` option which has been broken since Metro v0.33.0. (5d778de)
* **[Experimental]** Various unstable additions to the transformer config. *These are not covered by semver and can change at any time.* (6482241, 3390274, 5b913fa, #677)

Reviewed By: GijsWeterings

Differential Revision: D29514800

fbshipit-source-id: 89bd4b8a53a701ceaf18867e8e9379fd3401bbbe
@tido64 tido64 deleted the tido/disable-require-transforms branch July 8, 2021 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants