From d3ce0d3ea9736e1e1bc3e6b6834bc3170b1fa8eb Mon Sep 17 00:00:00 2001 From: Abishek Ilango Date: Mon, 20 May 2024 21:25:35 +0530 Subject: [PATCH] feat(compiler-healthcheck): Support strict mode check for nextjs apps (#29167) ## Summary Closes #29130 ## How did you test this change? Run the healthcheck in the compiler playground and the nodejs.org repo for the next config with a `.mjs` extension. Sanity with Vite React template. Signed-off-by: abizek --- .../react-compiler-healthcheck/src/checks/strictMode.ts | 8 ++++++-- compiler/packages/react-compiler-healthcheck/src/index.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/packages/react-compiler-healthcheck/src/checks/strictMode.ts b/compiler/packages/react-compiler-healthcheck/src/checks/strictMode.ts index 6bd848fdf0a08..035edf53d900d 100644 --- a/compiler/packages/react-compiler-healthcheck/src/checks/strictMode.ts +++ b/compiler/packages/react-compiler-healthcheck/src/checks/strictMode.ts @@ -8,16 +8,20 @@ import chalk from "chalk"; const JsFileExtensionRE = /(js|ts|jsx|tsx)$/; +const NextConfigFileRE = /^next\.config\.(js|mjs)$/; const StrictModeRE = /<(React\.StrictMode|StrictMode)>/; +const NextStrictModeRE = /reactStrictMode:\s*true/; let StrictModeUsage = false; export default { run(source: string, path: string): void { - if (JsFileExtensionRE.exec(path) === null) { + if (StrictModeUsage) { return; } - if (!StrictModeUsage) { + if (NextConfigFileRE.exec(path) !== null) { + StrictModeUsage = NextStrictModeRE.exec(source) !== null; + } else if (JsFileExtensionRE.exec(path) !== null) { StrictModeUsage = StrictModeRE.exec(source) !== null; } }, diff --git a/compiler/packages/react-compiler-healthcheck/src/index.ts b/compiler/packages/react-compiler-healthcheck/src/index.ts index d19be89fc8bd5..ba828ca0e97e3 100644 --- a/compiler/packages/react-compiler-healthcheck/src/index.ts +++ b/compiler/packages/react-compiler-healthcheck/src/index.ts @@ -20,7 +20,7 @@ async function main() { .option("src", { description: "glob expression matching src files to compile", type: "string", - default: "**/+(*.{js,jsx,ts,tsx}|package.json)", + default: "**/+(*.{js,mjs,jsx,ts,tsx}|package.json)", }) .parseSync();