From ea6c293726e54c72f53f51708e9b1f2c22cb9c2e Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Tue, 10 May 2022 05:13:24 -0700 Subject: [PATCH] Set global replacements in flipper-frontend-core Summary: Extract setting global replacements from plugin initialization Reviewed By: mweststrate Differential Revision: D36129749 fbshipit-source-id: 6f5b3e27c1b798124b5f2772e9099899ce521d0a --- .../src/globalObject.tsx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 desktop/flipper-frontend-core/src/globalObject.tsx diff --git a/desktop/flipper-frontend-core/src/globalObject.tsx b/desktop/flipper-frontend-core/src/globalObject.tsx new file mode 100644 index 000000000..105f2a6f2 --- /dev/null +++ b/desktop/flipper-frontend-core/src/globalObject.tsx @@ -0,0 +1,31 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +// this list should match `replace-flipper-requires.tsx` and the `builtInModules` in `desktop/.eslintrc` +export interface GlobalObject { + React: any; + ReactDOM: any; + ReactDOMClient: any; + ReactIs: any; + Flipper: any; + FlipperPlugin: any; + Immer: any; + antd: any; + emotion_styled: any; + antdesign_icons: any; +} + +export const setGlobalObject = (replacements: GlobalObject) => { + const globalObject = (function (this: any) { + return this; + })(); + for (const [name, module] of Object.entries(replacements)) { + globalObject[name] = module; + } +};