Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions packages/community-cli-plugin/src/utils/loadMetroConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,39 @@ function getOverrideConfig(
);
}

// We can include multiple copies of InitializeCore here because metro will
// only add ones that are already part of the bundle
const initializeCorePaths = [
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]},
),
),
];

return {
resolver,
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]},
),
),
],
getModulesRunBeforeMainModule: entrypoint => {
const originalBeforeMainModules =
config.serializer.getModulesRunBeforeMainModule(entrypoint);

// If the InitializeCore path is not specified in the original config,
// add it to the front of the list
const beforeMainModules = [];
for (const modulePath of initializeCorePaths) {
if (!originalBeforeMainModules.includes(modulePath)) {
beforeMainModules.push(modulePath);
}
}

return [...beforeMainModules, ...originalBeforeMainModules];
},
},
};
}
Expand Down
Loading