Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .changeset/fix-babel-compiler-detection-1448.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@react-doctor/core": patch
"react-doctor": patch
---

Detect React Compiler in babel config files and package.json babel field. Previously, projects using babel-plugin-react-compiler in package.json babel config or babel config files would fail detection, causing React Compiler-gated rules like context-provider-value-from-unmemoized-local-literal to incorrectly fire. Fixes #1448.
4 changes: 2 additions & 2 deletions packages/core/src/project-info/detectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ const analyzeConfigNode = (
};

const hasCompilerInConfigFile = (filePath: string): boolean =>
analyzeConfigModuleExport(filePath, "default", false, 0, new Set<string>());
analyzeConfigModuleExport(filePath, "default", true, 0, new Set<string>());

const hasCompilerInConfigFiles = (directory: string, filenames: string[]): boolean =>
filenames.some((filename) => hasCompilerInConfigFile(path.join(directory, filename)));
Expand All @@ -2014,7 +2014,7 @@ const hasCompilerInPackageJsonConfig = (packageJson: PackageJson): boolean =>
ts.parseJsonText("package.json", JSON.stringify(packageJson.babel)),
"package.json#babel",
"default",
false,
true,
0,
new Set<string>(),
);
Expand Down
17 changes: 17 additions & 0 deletions packages/core/tests/discover-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,23 @@ describe("discoverProject", () => {
expect(discoverProject(projectDirectory).hasReactCompiler).toBe(true);
});

it("detects React Compiler from package.json babel config", () => {
const projectDirectory = path.join(tempDirectory, "package-json-babel-react-compiler");
fs.mkdirSync(projectDirectory, { recursive: true });
fs.writeFileSync(
path.join(projectDirectory, "package.json"),
JSON.stringify({
name: "package-json-babel-react-compiler",
dependencies: { react: "^18.0.0" },
babel: {
plugins: ["babel-plugin-react-compiler"],
},
}),
);

expect(discoverProject(projectDirectory).hasReactCompiler).toBe(true);
});

it("detects React Compiler from its compatibility runtime", () => {
const projectDirectory = path.join(tempDirectory, "runtime-react-compiler");
fs.mkdirSync(projectDirectory, { recursive: true });
Expand Down
Loading