Skip to content

Commit

Permalink
Resolve npmPackageName from project root not local paths (#2588)
Browse files Browse the repository at this point in the history
  • Loading branch information
acoates-ms authored Aug 7, 2023
1 parent 6d05950 commit 18c757b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/bright-otters-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/metro-service": patch
"@rnx-kit/metro-config": patch
---

Resolve npmPackageName from project root not local paths
16 changes: 12 additions & 4 deletions packages/metro-config/src/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ const path = require("path");

/**
* @param {PlatformImplementations} availablePlatforms
* @param {string} projectRoot
*/
function getPreludeModules(availablePlatforms) {
function getPreludeModules(availablePlatforms, projectRoot) {
// Include all instances of `InitializeCore` here and let Metro exclude
// the unused ones.
const requireOptions = { paths: [projectRoot] };
const mainModules = new Set([
require.resolve("react-native/Libraries/Core/InitializeCore"),
require.resolve(
"react-native/Libraries/Core/InitializeCore",
requireOptions
),
]);
for (const moduleName of Object.values(availablePlatforms)) {
if (moduleName) {
mainModules.add(
require.resolve(`${moduleName}/Libraries/Core/InitializeCore`)
require.resolve(
`${moduleName}/Libraries/Core/InitializeCore`,
requireOptions
)
);
}
}
Expand Down Expand Up @@ -106,7 +114,7 @@ function getDefaultConfig(projectRoot) {
defaultConfig.resolver.resolveRequest =
outOfTreePlatformResolver(availablePlatforms);

const preludeModules = getPreludeModules(availablePlatforms);
const preludeModules = getPreludeModules(availablePlatforms, projectRoot);
defaultConfig.serializer.getModulesRunBeforeMainModule = () => {
return preludeModules;
};
Expand Down
3 changes: 2 additions & 1 deletion packages/metro-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ function getDefaultConfigInternal(cliConfig: CLIConfig): InputConfigT {
require.resolve(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
`${cliConfig.platforms[platform]
.npmPackageName!}/Libraries/Core/InitializeCore`
.npmPackageName!}/Libraries/Core/InitializeCore`,
{ paths: [cliConfig.root] }
)
),
],
Expand Down

0 comments on commit 18c757b

Please sign in to comment.