Pass globalPrefix through to serializer and expose to getRunModuleStatement#1566
Closed
Pass globalPrefix through to serializer and expose to getRunModuleStatement#1566
globalPrefix through to serializer and expose to getRunModuleStatement#1566Conversation
…Statement` Summary: To allow prefixing the global function `__r` (e.g., #1512), expose the prefix to the configured [`getRunModuleStatement`](https://metrobundler.dev/docs/configuration/#getrunmodulestatement), which returns the `__r()` call as a string. ``` - **[Feature]** Expose `globalPrefix` to `getRunModuleStatement` ``` ## Alternative? Runtime prefixing We could alternatively add prefix at runtime by emitting: ``` 'globalThis[__METRO_GLOBAL_PREFIX__ + '__r'](/*...*/)' ``` There are a couple of downsides - - These runModule statements are currently outside IIFEs that inject `global` based on (something like) `global = globalThis ?? global ?? window` - we don't rely on the existence of `globalThis` elsewhere (though it's probably safe to now - that's a separate breaking change). - Concatenation/interpolation + object access is more verbose and slightly slower, and there's just no need for it in code emitted by Metro itself (as opposed to framework/userland code, which must use it). Differential Revision: D81476621
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D81476621 |
Contributor
|
This pull request has been merged in db241c9. |
Contributor
|
this is perfect, thank you @robhogan 🙌 |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
To allow prefixing the global function
__r(e.g., #1512), expose the prefix to the configuredgetRunModuleStatement, which returns the__r()call as a string.Alternative? Runtime prefixing
We could alternatively add prefix at runtime by emitting:
There are a couple of downsides -
globalbased on (something like)global = globalThis ?? global ?? window- we don't rely on the existence ofglobalThiselsewhere (though it's probably safe to now - that's a separate breaking change).Differential Revision: D81476621