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 <abishekilango@protonmail.com>
This commit is contained in:
Abishek Ilango 2024-05-20 21:25:35 +05:30 committed by GitHub
parent 57fbe3ba37
commit d3ce0d3ea9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -8,16 +8,20 @@
import chalk from "chalk"; import chalk from "chalk";
const JsFileExtensionRE = /(js|ts|jsx|tsx)$/; const JsFileExtensionRE = /(js|ts|jsx|tsx)$/;
const NextConfigFileRE = /^next\.config\.(js|mjs)$/;
const StrictModeRE = /<(React\.StrictMode|StrictMode)>/; const StrictModeRE = /<(React\.StrictMode|StrictMode)>/;
const NextStrictModeRE = /reactStrictMode:\s*true/;
let StrictModeUsage = false; let StrictModeUsage = false;
export default { export default {
run(source: string, path: string): void { run(source: string, path: string): void {
if (JsFileExtensionRE.exec(path) === null) { if (StrictModeUsage) {
return; return;
} }
if (!StrictModeUsage) { if (NextConfigFileRE.exec(path) !== null) {
StrictModeUsage = NextStrictModeRE.exec(source) !== null;
} else if (JsFileExtensionRE.exec(path) !== null) {
StrictModeUsage = StrictModeRE.exec(source) !== null; StrictModeUsage = StrictModeRE.exec(source) !== null;
} }
}, },

View File

@ -20,7 +20,7 @@ async function main() {
.option("src", { .option("src", {
description: "glob expression matching src files to compile", description: "glob expression matching src files to compile",
type: "string", type: "string",
default: "**/+(*.{js,jsx,ts,tsx}|package.json)", default: "**/+(*.{js,mjs,jsx,ts,tsx}|package.json)",
}) })
.parseSync(); .parseSync();