Skip to content

Commit

Permalink
[compiler:babel] Don't read config files when not running as part of
Browse files Browse the repository at this point in the history
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: 5df2597983a0554d4c6698fe59a91ba8bd3f8e10
Pull Request resolved: #29211
  • Loading branch information
poteto committed May 22, 2024
1 parent 3ac551e commit 4a62e9a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function runBabelPluginReactCompiler(
file: string,
language: "flow" | "typescript",
options: Partial<PluginOptions> | null,
includeAst: boolean = false
includeAst: boolean = false,
): BabelCore.BabelFileResult {
const ast = BabelParser.parse(text, {
sourceFilename: file,
Expand All @@ -36,10 +36,11 @@ export function runBabelPluginReactCompiler(
"babel-plugin-fbt-runtime",
],
sourceType: "module",
configFile: false,
});
invariant(
result?.code != null,
`Expected BabelPluginReactForget to codegen successfully, got: ${result}`
`Expected BabelPluginReactForget to codegen successfully, got: ${result}`,
);
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const rule: Rule.RuleModule = {
[BabelPluginReactCompiler, options],
],
sourceType: "module",
configFile: false
});
} catch (err) {
if (isReactCompilerError(err) && Array.isArray(err.details)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function runBabelPluginReactCompiler(
retainLines: true,
plugins: [[BabelPluginReactCompiler, options]],
sourceType: "module",
configFile: false
});
if (result?.code == null) {
throw new Error(
Expand Down Expand Up @@ -140,7 +141,7 @@ export default {
report(): void {
const totalComponents =
SucessfulCompilation.length +
countUniqueLocInEvents(OtherFailures) +
countUniqueLocInEvents(OtherFailures) +
countUniqueLocInEvents(ActionableFailures)
console.log(
chalk.green(
Expand Down
3 changes: 3 additions & 0 deletions compiler/packages/snap/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export function transformFixtureInput(
sourceType: "module",
ast: includeEvaluator,
cloneInputAst: includeEvaluator,
configFile: false
});
invariant(
forgetResult?.code != null,
Expand All @@ -349,6 +350,7 @@ export function transformFixtureInput(
const result = transformFromAstSync(forgetResult.ast, forgetOutput, {
presets,
filename: virtualFilepath,
configFile: false
});
if (result?.code == null) {
return {
Expand All @@ -373,6 +375,7 @@ export function transformFixtureInput(
const result = transformFromAstSync(inputAst, input, {
presets,
filename: virtualFilepath,
configFile: false
});

if (result?.code == null) {
Expand Down
5 changes: 4 additions & 1 deletion scripts/jest/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ module.exports = {
sourceAst,
src,
Object.assign(
{filename: path.relative(process.cwd(), filePath)},
{
filename: path.relative(process.cwd(), filePath),
configFile: false,
},
babelOptions,
{
plugins,
Expand Down

0 comments on commit 4a62e9a

Please sign in to comment.