diff --git a/desktop/app/src/electron/initializeElectron.tsx b/desktop/app/src/electron/initializeElectron.tsx index 1be7834fe..725f889d3 100644 --- a/desktop/app/src/electron/initializeElectron.tsx +++ b/desktop/app/src/electron/initializeElectron.tsx @@ -29,12 +29,6 @@ import type {Icon, RenderHost} from 'flipper-ui-core'; import {getLocalIconUrl} from '../utils/icons'; import {getCPUUsage} from 'process'; -declare const electronRequire: { - (name: string): any; - resolve: (module: string) => string; - cache: {[module: string]: any}; -}; - export function initializeElectron( flipperServer: FlipperServer, flipperServerConfig: FlipperServerConfig, @@ -64,7 +58,7 @@ export function initializeElectron( } } - window.FlipperRenderHostInstance = { + FlipperRenderHostInstance = { processId: remote.process.pid, isProduction, readTextFromClipboard() { diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index bab758b56..b205b57a7 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -42,20 +42,6 @@ import fs from 'fs'; enableMapSet(); -declare global { - interface Window { - // We store this as a global, to make sure the renderHost is available - // before flipper-ui-core is loaded and needs those during module initialisation - FlipperRenderHostInstance: RenderHost; - } -} - -declare const electronRequire: { - (name: string): any; - resolve: (module: string) => string; - cache: {[module: string]: any}; -}; - if (process.env.NODE_ENV === 'development' && os.platform() === 'darwin') { // By default Node.JS has its internal certificate storage and doesn't use // the system store. Because of this, it's impossible to access ondemand / devserver diff --git a/desktop/flipper-server-core/src/comms/ServerController.tsx b/desktop/flipper-server-core/src/comms/ServerController.tsx index 02322cbc2..c3891e474 100644 --- a/desktop/flipper-server-core/src/comms/ServerController.tsx +++ b/desktop/flipper-server-core/src/comms/ServerController.tsx @@ -58,7 +58,7 @@ type ClientCsrQuery = { csr_path?: string | undefined; }; -declare interface ServerController { +interface ServerController { on(event: 'error', callback: (err: Error) => void): this; } diff --git a/desktop/flipper-server/src/startWebServerDev.tsx b/desktop/flipper-server/src/startWebServerDev.tsx index eb7afa77a..cebe01ed8 100644 --- a/desktop/flipper-server/src/startWebServerDev.tsx +++ b/desktop/flipper-server/src/startWebServerDev.tsx @@ -70,7 +70,7 @@ export async function startWebServerDev( 'electron-requires.js', ); const stubModules = new Set( - (global as any).electronRequire(electronRequires).BUILTINS, + electronRequire(electronRequires).BUILTINS, ); if (!stubModules.size) { throw new Error('Failed to load list of Node builtins'); diff --git a/desktop/flipper-ui-browser/src/global.ts b/desktop/flipper-ui-browser/src/global.ts index 54b3f5d59..3bd796de8 100644 --- a/desktop/flipper-ui-browser/src/global.ts +++ b/desktop/flipper-ui-browser/src/global.ts @@ -17,8 +17,6 @@ declare global { debug: boolean; }; - FlipperRenderHostInstance: RenderHost; - flipperShowError?(error: string): void; flipperHideError?(): void; } diff --git a/desktop/flipper-ui-browser/src/index.tsx b/desktop/flipper-ui-browser/src/index.tsx index 77d943630..a2848f9a2 100644 --- a/desktop/flipper-ui-browser/src/index.tsx +++ b/desktop/flipper-ui-browser/src/index.tsx @@ -15,7 +15,7 @@ document.getElementById('root')!.innerText = 'flipper-ui-browser started'; async function start() { // @ts-ignore - (global as any).electronRequire = function (path: string) { + electronRequire = function (path: string) { console.error( `[decapitate] Tried to electronRequire ${path}, this module is not available in the browser and will be stubbed`, ); diff --git a/desktop/flipper-ui-browser/src/initializeRenderHost.tsx b/desktop/flipper-ui-browser/src/initializeRenderHost.tsx index fd8cd9996..38f22bee3 100644 --- a/desktop/flipper-ui-browser/src/initializeRenderHost.tsx +++ b/desktop/flipper-ui-browser/src/initializeRenderHost.tsx @@ -14,7 +14,7 @@ export function initializeRenderHost( flipperServer: FlipperServer, flipperServerConfig: FlipperServerConfig, ) { - window.FlipperRenderHostInstance = { + FlipperRenderHostInstance = { readTextFromClipboard() { // TODO: return undefined; diff --git a/desktop/flipper-ui-browser/tsconfig.json b/desktop/flipper-ui-browser/tsconfig.json index c3d94f360..0953a91c9 100644 --- a/desktop/flipper-ui-browser/tsconfig.json +++ b/desktop/flipper-ui-browser/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "outDir": "lib", "rootDir": "src", - "lib": ["dom", "ES2019"] + "lib": ["dom", "ES2019"], + "types": ["../types/flipperGlobals"] }, "references": [ { diff --git a/desktop/flipper-ui-core/src/RenderHost.tsx b/desktop/flipper-ui-core/src/RenderHost.tsx index 0dc5769ab..378da3b2b 100644 --- a/desktop/flipper-ui-core/src/RenderHost.tsx +++ b/desktop/flipper-ui-core/src/RenderHost.tsx @@ -141,8 +141,8 @@ export interface RenderHost { } export function getRenderHostInstance(): RenderHost { - if (!window.FlipperRenderHostInstance) { + if (!FlipperRenderHostInstance) { throw new Error('global FlipperRenderHostInstance was never set'); } - return window.FlipperRenderHostInstance; + return FlipperRenderHostInstance; } diff --git a/desktop/flipper-ui-core/src/global.ts b/desktop/flipper-ui-core/src/global.ts index 5d5c06c31..916e82d1a 100644 --- a/desktop/flipper-ui-core/src/global.ts +++ b/desktop/flipper-ui-core/src/global.ts @@ -19,7 +19,5 @@ declare global { __REDUX_DEVTOOLS_EXTENSION__: | undefined | (StoreEnhancerStoreCreator & StoreEnhancerStateSanitizer); - - FlipperRenderHostInstance: RenderHost; } } diff --git a/desktop/flipper-ui-core/tsconfig.json b/desktop/flipper-ui-core/tsconfig.json index 8d8c059bc..be815009c 100644 --- a/desktop/flipper-ui-core/tsconfig.json +++ b/desktop/flipper-ui-core/tsconfig.json @@ -6,7 +6,7 @@ "esModuleInterop": true, "emitDeclarationOnly": true, "lib": ["dom", "es2019"], - "types": ["../types/ReactDebounceRender"] + "types": ["../types/ReactDebounceRender", "../types/flipperGlobals"] }, "references": [ { diff --git a/desktop/scripts/build-utils.ts b/desktop/scripts/build-utils.ts index 623fd1ad6..3d7ea601a 100644 --- a/desktop/scripts/build-utils.ts +++ b/desktop/scripts/build-utils.ts @@ -125,14 +125,14 @@ async function generateDefaultPluginEntryPoints( const pluginRequres = bundledPlugins .map( (x) => - ` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`, + ` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`, ) .join(',\n'); const generatedIndex = ` /* eslint-disable */ // THIS FILE IS AUTO-GENERATED by function "generateDefaultPluginEntryPoints" in "build-utils.ts". - declare var require: any; + declare const require: any; // This function exists to make sure that if one require fails in its module initialisation, not everything fails function tryRequire(module: string, fn: () => any): any { diff --git a/desktop/types/flipperGlobals.d.ts b/desktop/types/flipperGlobals.d.ts index bf70c740a..96113a7cb 100644 --- a/desktop/types/flipperGlobals.d.ts +++ b/desktop/types/flipperGlobals.d.ts @@ -15,15 +15,4 @@ declare const electronRequire: { cache: {[module: string]: any}; }; -// For Electron -declare module NodeJS { - interface Global { - __REVISION__: string | undefined; - __VERSION__: string; - electronRequire: { - (name: string): any; - resolve: (module: string) => string; - cache: {[module: string]: any}; - }; - } -} +declare let FlipperRenderHostInstance: any /* RenderHost */;