From a59fc2c032940f14a07ee36cfbf2172e5c0e3c52 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Mon, 3 Jun 2024 13:57:59 -0700 Subject: [PATCH 1/3] compiler: Allow opting out of installed library check [ghstack-poisoned] --- .../babel-plugin-react-compiler/src/Babel/BabelPlugin.ts | 5 ++++- .../babel-plugin-react-compiler/src/Entrypoint/Options.ts | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts b/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts index 88731a8496594..a3b64327643c4 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts @@ -30,7 +30,10 @@ export default function BabelPluginReactCompiler( */ Program(prog, pass): void { let opts = parsePluginOptions(pass.opts); - if (pipelineUsesReanimatedPlugin(pass.file.opts.plugins)) { + if ( + opts.disableCheckForSupportedLibraries !== false && + pipelineUsesReanimatedPlugin(pass.file.opts.plugins) + ) { opts = injectReanimatedFlag(opts); } if (process.env["NODE_ENV"] === "development") { diff --git a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts index db305ea5c83c3..8354f8881f19c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts @@ -111,6 +111,13 @@ export type PluginOptions = { ignoreUseNoForget: boolean; sources?: Array | ((filename: string) => boolean) | null; + + /** + * The compiler has customized support for some popular React libraries (to provide even more optimized output). + * By default the compiler checks for the presence of these libraries via a `try { require(...) }` call. Set this + * flag to disable the automatic check. + */ + disableCheckForSupportedLibraries?: boolean; }; const CompilationModeSchema = z.enum([ From f2934fab2db1762599b42c93295ad75e69bac591 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Mon, 3 Jun 2024 14:02:03 -0700 Subject: [PATCH 2/3] Update on "compiler: Allow opting out of installed library check" [ghstack-poisoned] --- .../babel-plugin-react-compiler/src/Babel/BabelPlugin.ts | 2 +- .../babel-plugin-react-compiler/src/Entrypoint/Options.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts b/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts index a3b64327643c4..0945f178c362d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Babel/BabelPlugin.ts @@ -31,7 +31,7 @@ export default function BabelPluginReactCompiler( Program(prog, pass): void { let opts = parsePluginOptions(pass.opts); if ( - opts.disableCheckForSupportedLibraries !== false && + opts.enableReanimatedCheck === true && pipelineUsesReanimatedPlugin(pass.file.opts.plugins) ) { opts = injectReanimatedFlag(opts); diff --git a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts index 8354f8881f19c..262e9b1001dee 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts @@ -113,11 +113,10 @@ export type PluginOptions = { sources?: Array | ((filename: string) => boolean) | null; /** - * The compiler has customized support for some popular React libraries (to provide even more optimized output). - * By default the compiler checks for the presence of these libraries via a `try { require(...) }` call. Set this - * flag to disable the automatic check. + * The compiler has customized support for react-native-reanimated, intended as a temporary workaround. + * Set this flag (on by default) to automatically check for this library and activate the support. */ - disableCheckForSupportedLibraries?: boolean; + enableReanimatedCheck: boolean; }; const CompilationModeSchema = z.enum([ @@ -195,6 +194,7 @@ export const defaultOptions: PluginOptions = { sources: (filename) => { return filename.indexOf("node_modules") === -1; }, + enableReanimatedCheck: true, } as const; export function parsePluginOptions(obj: unknown): PluginOptions { From 8fcda799a6143d0487163a529a871c90a1ed33eb Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Mon, 3 Jun 2024 14:20:40 -0700 Subject: [PATCH 3/3] Update on "compiler: Allow opting out of installed library check" [ghstack-poisoned] --- compiler/packages/snap/src/compiler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/packages/snap/src/compiler.ts b/compiler/packages/snap/src/compiler.ts index a664657097203..8d6671d0c286e 100644 --- a/compiler/packages/snap/src/compiler.ts +++ b/compiler/packages/snap/src/compiler.ts @@ -191,6 +191,7 @@ function makePluginOptions( eslintSuppressionRules, flowSuppressions, ignoreUseNoForget, + enableReanimatedCheck: false, }; }