From d0402d7268f6a7cc8da6bba7580ef0df0b0ea9a6 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 8 Dec 2021 04:25:28 -0800 Subject: [PATCH] Move unloadModule to RenderHost Summary: Define unload module on RenderHost. Not sure how to do that the browser and not sure how meaning full it is in a browser context. Reviewed By: nikoant Differential Revision: D32827050 fbshipit-source-id: 87025c6f5c2b950880712bff8df1c92a044a222e --- desktop/app/src/electron/initializeElectron.tsx | 7 +++++++ desktop/flipper-ui-core/src/RenderHost.tsx | 2 +- .../dispatcher/__tests__/pluginManager.node.tsx | 1 - .../src/dispatcher/pluginManager.tsx | 3 +-- .../src/utils/electronModuleCache.tsx | 16 ---------------- 5 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 desktop/flipper-ui-core/src/utils/electronModuleCache.tsx diff --git a/desktop/app/src/electron/initializeElectron.tsx b/desktop/app/src/electron/initializeElectron.tsx index 4eb40b4be..2dd1c921d 100644 --- a/desktop/app/src/electron/initializeElectron.tsx +++ b/desktop/app/src/electron/initializeElectron.tsx @@ -195,6 +195,13 @@ export function initializeElectron( !flipperServerConfig.environmentInfo.isProduction, ); }, + unloadModule(path: string) { + const resolvedPath = global.electronRequire.resolve(path); + if (!resolvedPath || !global.electronRequire.cache[resolvedPath]) { + return; + } + delete global.electronRequire.cache[resolvedPath]; + }, } as RenderHost; setupMenuBar(); diff --git a/desktop/flipper-ui-core/src/RenderHost.tsx b/desktop/flipper-ui-core/src/RenderHost.tsx index 53d3e509d..56ca12ccb 100644 --- a/desktop/flipper-ui-core/src/RenderHost.tsx +++ b/desktop/flipper-ui-core/src/RenderHost.tsx @@ -12,7 +12,6 @@ import type {PluginNotification} from './reducers/notifications'; import type {NotificationConstructorOptions} from 'electron'; import {FlipperLib} from 'flipper-plugin'; import {FlipperServer, FlipperServerConfig} from 'flipper-common'; -import {IconSize} from './ui/components/Glyph'; import {Icon} from './utils/icons'; // Events that are emitted from the main.ts ovr the IPC process bridge in Electron @@ -102,6 +101,7 @@ export interface RenderHost { getStaticResourceUrl(relativePath: string): string; // given the requested icon and proposed public url of the icon, rewrite it to a local icon if needed getLocalIconUrl?(icon: Icon, publicUrl: string): string; + unloadModule?(path: string): void; } export function getRenderHostInstance(): RenderHost { diff --git a/desktop/flipper-ui-core/src/dispatcher/__tests__/pluginManager.node.tsx b/desktop/flipper-ui-core/src/dispatcher/__tests__/pluginManager.node.tsx index 5cc630bf3..8dcf88095 100644 --- a/desktop/flipper-ui-core/src/dispatcher/__tests__/pluginManager.node.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/__tests__/pluginManager.node.tsx @@ -8,7 +8,6 @@ */ jest.mock('../plugins'); -jest.mock('../../utils/electronModuleCache'); import { loadPlugin, switchPlugin, diff --git a/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx b/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx index ed150cce4..a3959d6f9 100644 --- a/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/pluginManager.tsx @@ -22,7 +22,6 @@ import {requirePlugin} from './plugins'; import {showErrorNotification} from '../utils/notifications'; import {PluginDefinition} from '../plugin'; import type Client from '../Client'; -import {unloadModule} from '../utils/electronModuleCache'; import { pluginLoaded, pluginUninstalled, @@ -373,5 +372,5 @@ function unloadPluginModule(plugin: ActivatablePluginDetails) { // We cannot unload bundled plugin. return; } - unloadModule(plugin.entry); + getRenderHostInstance().unloadModule?.(plugin.entry); } diff --git a/desktop/flipper-ui-core/src/utils/electronModuleCache.tsx b/desktop/flipper-ui-core/src/utils/electronModuleCache.tsx deleted file mode 100644 index 06a1c300f..000000000 --- a/desktop/flipper-ui-core/src/utils/electronModuleCache.tsx +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -export function unloadModule(path: string) { - const resolvedPath = global.electronRequire.resolve(path); - if (!resolvedPath || !global.electronRequire.cache[resolvedPath]) { - return; - } - delete global.electronRequire.cache[resolvedPath]; -}