Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve metro config verification logic #2100

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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