Skip to content

Commit

Permalink
Improve metro config verification logic (#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
EzioLi01 committed Jan 29, 2024
1 parent 7f5a843 commit 1db42be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
11 changes: 4 additions & 7 deletions src/common/reactNativeProjectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as fs from "fs";
import * as path from "path";
import * as semver from "semver";
import { OutputChannelLogger } from "../extension/log/OutputChannelLogger";
import { ProjectVersionHelper } from "./projectVersionHelper";
import { FileSystem } from "./node/fileSystem";
Expand Down Expand Up @@ -130,15 +131,11 @@ export class ReactNativeProjectHelper {
const metroConfigPath = path.join(projectRoot, "metro.config.js");
const content = fs.readFileSync(metroConfigPath, "utf-8");
const isNewMetroConfig = content.includes("getDefaultConfig");
if (parseInt(version.reactNativeVersion.substring(2, 4)) <= 72 && !isNewMetroConfig) {

if (semver.gte(version.reactNativeVersion, "0.73.0") && !isNewMetroConfig) {
logger.warning(
'The version of "metro.config.js" in current project will be deprecated from rn 0.73, 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',
'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',
);
} else if (parseInt(version.reactNativeVersion.substring(2, 4)) > 72 && !isNewMetroConfig) {
// As official mentioned, the new version of metro config will be required from 0.73, will enable this once the old version of config is totally disabled.
// throw new Error(
// 'The version of "metro.config.js" in current project is deprecated, 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',
// );
}
}
}
8 changes: 0 additions & 8 deletions src/debugger/direct/directDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { TipNotificationService } from "../../extension/services/tipsNotificatio
import { RNSession } from "../debugSessionWrapper";
import { SettingsHelper } from "../../extension/settingsHelper";
import { ReactNativeProjectHelper } from "../../common/reactNativeProjectHelper";
import { ExponentHelper } from "../../extension/exponent/exponentHelper";
import { IWDPHelper } from "./IWDPHelper";

nls.config({
Expand Down Expand Up @@ -144,13 +143,6 @@ export class DirectDebugSession extends DebugSessionBase {
this.previousAttachArgs = attachArgs;

try {
if (attachArgs.request === "attach") {
const expoHelper = new ExponentHelper(attachArgs.cwd, attachArgs.cwd);
const isExpo = await expoHelper.isExpoManagedApp(true);
if (!isExpo) {
await ReactNativeProjectHelper.verifyMetroConfigFile(attachArgs.cwd);
}
}
await this.initializeSettings(attachArgs);

const packager = this.appLauncher.getPackager();
Expand Down
8 changes: 0 additions & 8 deletions src/debugger/rnDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { RnCDPMessageHandler } from "../cdp-proxy/CDPMessageHandlers/rnCDPMessag
import { ErrorHelper } from "../common/error/errorHelper";
import { InternalErrorCode } from "../common/error/internalErrorCode";
import { ReactNativeProjectHelper } from "../common/reactNativeProjectHelper";
import { ExponentHelper } from "../extension/exponent/exponentHelper";
import { MultipleLifetimesAppWorker } from "./appWorker";
import {
DebugSessionBase,
Expand Down Expand Up @@ -103,13 +102,6 @@ export class RNDebugSession extends DebugSessionBase {

return new Promise<void>(async (resolve, reject) => {
try {
if (attachArgs.request === "attach") {
const expoHelper = new ExponentHelper(attachArgs.cwd, attachArgs.cwd);
const isExpo = await expoHelper.isExpoManagedApp(true);
if (!isExpo) {
await ReactNativeProjectHelper.verifyMetroConfigFile(attachArgs.cwd);
}
}
await this.initializeSettings(attachArgs);
logger.log("Attaching to the application");
logger.verbose(
Expand Down

0 comments on commit 1db42be

Please sign in to comment.