Summary: The build process for the server was a simple ts-node that compiled all deps. However, that didn't do any source transformations we need, like replacing `fb-stubs` with `fb` in facebook builds. This diff works out the dev build process to align more with how other parts of the code base is build, by starting metro to build and bundle the server (only the sources of flipper-server, flipper-server-core and other flipper packages are bundled, node-deps are left as is). To achieve this, since metro doesn't have support for 'external' packages like any arbitrarily other bundler, we recycle the electronRequire work around that is used in the desktop app as well Reviewed By: aigoncharov Differential Revision: D32949677 fbshipit-source-id: 00d326bb17b68aece6fb43af98d0def13b335e74
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
/**
|
|
* 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
|
|
*/
|
|
|
|
import {FlipperServer, FlipperServerConfig} from 'flipper-common';
|
|
import {RenderHost} from 'flipper-ui-core';
|
|
|
|
export function initializeRenderHost(
|
|
flipperServer: FlipperServer,
|
|
flipperServerConfig: FlipperServerConfig,
|
|
) {
|
|
window.FlipperRenderHostInstance = {
|
|
readTextFromClipboard() {
|
|
// TODO:
|
|
return undefined;
|
|
},
|
|
writeTextToClipboard(_text: string) {
|
|
// TODO:
|
|
},
|
|
async importFile() {
|
|
throw new Error('Not implemented');
|
|
},
|
|
async exportFile() {
|
|
throw new Error('Not implemented');
|
|
},
|
|
openLink(url: string) {
|
|
window.open(url, '_blank');
|
|
},
|
|
registerShortcut(_shortcut, _callback) {
|
|
// TODO:
|
|
return () => {};
|
|
},
|
|
hasFocus() {
|
|
return document.hasFocus();
|
|
},
|
|
onIpcEvent(_event) {
|
|
// no-op
|
|
},
|
|
sendIpcEvent(_event, ..._args: any[]) {
|
|
// no-op
|
|
},
|
|
shouldUseDarkColors() {
|
|
return !!(
|
|
window.flipperConfig.theme === 'dark' ||
|
|
(window.flipperConfig.theme === 'system' &&
|
|
window.matchMedia?.('(prefers-color-scheme: dark)'))
|
|
);
|
|
},
|
|
restartFlipper() {
|
|
window.flipperShowError!(
|
|
'Flipper settings have changed, please restart flipper server for the changes to take effect',
|
|
);
|
|
},
|
|
loadDefaultPlugins: getDefaultPluginsIndex,
|
|
serverConfig: flipperServerConfig,
|
|
GK(gatekeeper) {
|
|
return flipperServerConfig.gatekeepers[gatekeeper] ?? false;
|
|
},
|
|
flipperServer,
|
|
async requirePlugin(path) {
|
|
// TODO: use `await import(path)`?
|
|
const source = await flipperServer.exec('plugin-source', path);
|
|
// eslint-disable-next-line no-eval
|
|
return eval(source);
|
|
},
|
|
getStaticResourceUrl(path): string {
|
|
// the 'static' folder is mounted as static middleware in Express at the root
|
|
return '/' + path;
|
|
},
|
|
} as RenderHost;
|
|
}
|
|
|
|
function getDefaultPluginsIndex() {
|
|
// TODO:
|
|
return {};
|
|
// eslint-disable-next-line import/no-unresolved
|
|
// const index = require('../defaultPlugins');
|
|
// return index.default || index;
|
|
}
|