Skip to content

Commit 2b1777e

Browse files
committed
feat: favor expo's metro config package
1 parent b7f4871 commit 2b1777e

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

packages/metro/src/moduleSystem.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,31 @@ const optionalResolve = (path: string, from: string): string | null => {
88
}
99
};
1010

11-
const getMetroDefaultsPath = (): string => {
12-
const reactNativeMetroConfigPath = require.resolve(
11+
const getMetroConfigPath = (): string => {
12+
const expoConfigPath = optionalResolve('@expo/metro-config', process.cwd());
13+
14+
if (expoConfigPath) {
15+
return expoConfigPath;
16+
}
17+
18+
const reactNativeMetroConfigPath = optionalResolve(
1319
'@react-native/metro-config',
14-
{ paths: [process.cwd()] }
20+
process.cwd()
1521
);
1622

23+
if (reactNativeMetroConfigPath) {
24+
return reactNativeMetroConfigPath;
25+
}
26+
27+
throw new CouldNotPatchModuleSystemError();
28+
};
29+
30+
const getMetroDefaultsPath = (): string => {
31+
const metroConfigPath = getMetroConfigPath();
32+
1733
const preExportsDefaults = optionalResolve(
1834
'metro-config/src/defaults/defaults',
19-
reactNativeMetroConfigPath
35+
metroConfigPath
2036
);
2137

2238
if (preExportsDefaults) {
@@ -25,7 +41,7 @@ const getMetroDefaultsPath = (): string => {
2541

2642
const privateDefaults = optionalResolve(
2743
'metro-config/private/defaults/defaults',
28-
reactNativeMetroConfigPath
44+
metroConfigPath
2945
);
3046

3147
if (privateDefaults) {

0 commit comments

Comments
 (0)