From 3447603d5aa7db9b3b81c5743c814aafb1b67854 Mon Sep 17 00:00:00 2001 From: EzioLi Date: Thu, 25 Jan 2024 19:50:09 +0800 Subject: [PATCH] Improve metro config verification logic --- src/common/reactNativeProjectHelper.ts | 11 ++++------- src/debugger/direct/directDebugSession.ts | 8 -------- src/debugger/rnDebugSession.ts | 8 -------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/common/reactNativeProjectHelper.ts b/src/common/reactNativeProjectHelper.ts index f32ccc93a..d618e6259 100644 --- a/src/common/reactNativeProjectHelper.ts +++ b/src/common/reactNativeProjectHelper.ts @@ -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"; @@ -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', - // ); } } } diff --git a/src/debugger/direct/directDebugSession.ts b/src/debugger/direct/directDebugSession.ts index d3fee7509..bb7343b57 100644 --- a/src/debugger/direct/directDebugSession.ts +++ b/src/debugger/direct/directDebugSession.ts @@ -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({ @@ -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(); diff --git a/src/debugger/rnDebugSession.ts b/src/debugger/rnDebugSession.ts index 6f8aa2f79..92a4854ff 100644 --- a/src/debugger/rnDebugSession.ts +++ b/src/debugger/rnDebugSession.ts @@ -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, @@ -103,13 +102,6 @@ export class RNDebugSession extends DebugSessionBase { return new Promise(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(