Skip to content

Commit

Permalink
feat(compiler-healthcheck): Support strict mode check for nextjs apps (
Browse files Browse the repository at this point in the history
…#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 <[email protected]>
  • Loading branch information
abizek authored May 20, 2024
1 parent 57fbe3b commit d3ce0d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/packages/react-compiler-healthcheck/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d3ce0d3

Please sign in to comment.