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";
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;
}
},

View File

@ -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();