Files
flipper/desktop/flipper-common/src/plugin-external-modules.tsx
Andrey Goncharov 9597e672a1 Provide @emotion/css to plugins
Summary: Changelog: Provide `emotion/css` to plugins

Reviewed By: antonk52

Differential Revision: D40057817

fbshipit-source-id: 1e931eb8527d62dd4312556a6d493fdf3e17b45a
2022-10-04 05:07:36 -07:00

42 lines
1.3 KiB
TypeScript

/**
* 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 `flipper-frontend-core/src/globalObject.tsx` and `builtInModules` in `desktop/.eslintrc.js`
export const pluginExternalModules = {
flipper: 'Flipper',
'flipper-plugin': 'FlipperPlugin',
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/client': 'ReactDOMClient',
'react-is': 'ReactIs',
antd: 'antd',
immer: 'Immer',
'@emotion/styled': 'emotion_styled',
'@emotion/css': 'emotion_css',
'@ant-design/icons': 'antdesign_icons',
// Used by "bloks-logger" (see its bundle's content)
'react/jsx-runtime': 'ReactJsxRuntime',
};
export const wrapRequire = <T extends (path: string) => any>(require: T): T =>
new Proxy(require, {
apply(target, thisArg, argumentsList) {
const moduleName = argumentsList[0];
const replacementName = (
pluginExternalModules as Record<string, string | undefined>
)[moduleName];
if (replacementName && replacementName in globalThis) {
return (globalThis as any)[replacementName];
}
return Reflect.apply(target, thisArg, argumentsList);
},
});