-
Notifications
You must be signed in to change notification settings - Fork 24.6k
feat(CLI): deep merge Metro serializer #50783
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
base: main
Are you sure you want to change the base?
Conversation
I'm curious which Conceptually, this seems right if there's a clear need — we'd been moving towards |
I don't utilize Speaking of |
@tjzel Interesting. I guess we could merge more correctly, e.g. this: Looks like serializer: {
// We can include multiple copies of InitializeCore here because metro will
// only add ones that are already part of the bundle
getModulesRunBeforeMainModule: () => [
require.resolve(
path.join(ctx.reactNativePath, 'Libraries/Core/InitializeCore'),
{paths: [ctx.root]},
),
...outOfTreePlatforms.map(platform =>
require.resolve(
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`,
{paths: [ctx.root]},
),
),
+ ...(config.serializer.getModulesRunBeforeMainModule() ?? []),
],
}, |
A deep merge would be good too. I tested it for my use case and it worked, I only had to change the order so React Native's initializer wouldn't be first. Although it makes more sense in this case to be able to choose if you want your initializer to be prepended or appended. --- a/dist/utils/loadMetroConfig.js
+++ b/dist/utils/loadMetroConfig.js
@@ -33,6 +33,7 @@ function getOverrideConfig(ctx, config) {
resolver,
serializer: {
getModulesRunBeforeMainModule: () => [
+ ...(config.serializer.getModulesRunBeforeMainModule() ?? []),
require.resolve(
_path.default.join(
ctx.reactNativePath, |
I'd recommend against this in general. It's not a good idea for transforms to have side-effects (or untracked inputs) because there are no guarantees that your new files will stay in sync. What are you working on? There might be a better way, or it might fit the virtual module system in development atm. |
@robhogan I opened a separate issue for the file creation problem facebook/metro#1488 To put it simply, I want to generate web-worker like environment implicitly for the user - that meaning, creating a separate file for any function that could be used on a separate Hermes Runtime, beside the one spawned by React Native. I figured that to support hot reloads I need to hook into Metro bundling process - build step doesn't seem to be an option here. |
Hey @huntie, so what's the direction we want to follow in this PR? |
@tjzel Let's go for the |
@huntie I added deep merging, but |
Summary:
Running metro via community CLI's
start
command triggers overriding of the Metro config, namelyresolver
andserializer
. While developingreact-native-worklets
library I found it useful to add custom logic toresolver
andserializer
to enable more advanced features. The config will remain overridden by default and can be explicitly disabled by the user.Adding this to the CLI plugin might be too high up in the logic, if you think it would be better to apply this change somewhere else, please guide me 🙏
Changelog:
[GENERAL] [ADDED] - Add option to disable Metro config override on demand
Test Plan:
You can run
yarn start
andyarn react-native bundle
with and without--disable-config-override
in the RNTester app and see that it works well.