Skip to content

Commit 462df20

Browse files
authored
Support .cjs metro config file (#2103)
* Support .cjs metro config file * Support .cjs metro config file
1 parent 2bc89e2 commit 462df20

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/common/reactNativeProjectHelper.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,19 @@ export class ReactNativeProjectHelper {
128128
);
129129
}
130130

131-
const metroConfigPath = path.join(projectRoot, "metro.config.js");
132-
const content = fs.readFileSync(metroConfigPath, "utf-8");
133-
const isNewMetroConfig = content.includes("getDefaultConfig");
131+
let content = "";
132+
if (fs.existsSync(path.join(projectRoot, "metro.config.js"))) {
133+
content = fs.readFileSync(path.join(projectRoot, "metro.config.js"), "utf-8");
134+
} else if (fs.existsSync(path.join(projectRoot, "metro.config.cjs"))) {
135+
content = fs.readFileSync(path.join(projectRoot, "metro.config.cjs"), "utf-8");
136+
} else {
137+
return;
138+
}
134139

140+
const isNewMetroConfig = content.includes("getDefaultConfig");
135141
if (semver.gte(version.reactNativeVersion, "0.73.0") && !isNewMetroConfig) {
136142
logger.warning(
137-
'The version of "metro.config.js" in current project is deprecated, it may cause project build failure. Please update your "metro.config.js" file according to template: https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
143+
'The version of "metro.config" in current project is deprecated, it may cause project build failure. Please update your "metro.config.js" file according to template: https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
138144
);
139145
}
140146
}

0 commit comments

Comments
 (0)