From cdae1c4f54a7444a5ed65ce1c922c0464e372699 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 29 May 2024 11:31:07 +0900 Subject: [PATCH] [compiler:babel] Don't read config files when not running as part of user's pipeline When the user app has a babel.config file that is missing the compiler, strange things happen as babel does some strange merging of options from the user's config and in various callsites like in our eslint rule and healthcheck script. To minimize odd behavior, we default to not reading the user's babel.config Fixes #29135 ghstack-source-id: 86daa0bc2390e02682675bc2fccb0bd83b64b7ac Pull Request resolved: https://github.com/facebook/react/pull/29211 --- .../src/Babel/RunReactCompilerBabelPlugin.ts | 2 ++ .../src/rules/ReactCompilerRule.ts | 1 + .../react-compiler-healthcheck/src/checks/reactCompiler.ts | 1 + compiler/packages/snap/src/compiler.ts | 3 +++ scripts/jest/preprocessor.js | 4 +++- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/Babel/RunReactCompilerBabelPlugin.ts b/compiler/packages/babel-plugin-react-compiler/src/Babel/RunReactCompilerBabelPlugin.ts index 7d0248300c97f..8218cf267bb53 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Babel/RunReactCompilerBabelPlugin.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Babel/RunReactCompilerBabelPlugin.ts @@ -36,6 +36,8 @@ export function runBabelPluginReactCompiler( "babel-plugin-fbt-runtime", ], sourceType: "module", + configFile: false, + babelrc: false, }); invariant( result?.code != null, diff --git a/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts b/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts index ae263621722b1..fd33ae0339a1d 100644 --- a/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts +++ b/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts @@ -144,6 +144,7 @@ const rule: Rule.RuleModule = { ], sourceType: "module", configFile: false, + babelrc: false, }); } catch (err) { if (isReactCompilerError(err) && Array.isArray(err.details)) { diff --git a/compiler/packages/react-compiler-healthcheck/src/checks/reactCompiler.ts b/compiler/packages/react-compiler-healthcheck/src/checks/reactCompiler.ts index ce8423d7ef0d1..09c9b9bda64d7 100644 --- a/compiler/packages/react-compiler-healthcheck/src/checks/reactCompiler.ts +++ b/compiler/packages/react-compiler-healthcheck/src/checks/reactCompiler.ts @@ -86,6 +86,7 @@ function runBabelPluginReactCompiler( plugins: [[BabelPluginReactCompiler, options]], sourceType: "module", configFile: false, + babelrc: false, }); if (result?.code == null) { throw new Error( diff --git a/compiler/packages/snap/src/compiler.ts b/compiler/packages/snap/src/compiler.ts index 25234796a0da1..ab2cf5cef8847 100644 --- a/compiler/packages/snap/src/compiler.ts +++ b/compiler/packages/snap/src/compiler.ts @@ -334,6 +334,7 @@ export async function transformFixtureInput( ast: includeEvaluator, cloneInputAst: includeEvaluator, configFile: false, + babelrc: false, }); invariant( forgetResult?.code != null, @@ -357,6 +358,7 @@ export async function transformFixtureInput( presets, filename: virtualFilepath, configFile: false, + babelrc: false, }); if (result?.code == null) { return { @@ -382,6 +384,7 @@ export async function transformFixtureInput( presets, filename: virtualFilepath, configFile: false, + babelrc: false, }); if (result?.code == null) { diff --git a/scripts/jest/preprocessor.js b/scripts/jest/preprocessor.js index f04cd2c3cfc84..d0bf0467db775 100644 --- a/scripts/jest/preprocessor.js +++ b/scripts/jest/preprocessor.js @@ -109,7 +109,9 @@ module.exports = { sourceAst, src, Object.assign( - {filename: path.relative(process.cwd(), filePath)}, + { + filename: path.relative(process.cwd(), filePath), + }, babelOptions, { plugins,