Move FlipperServer initialisation out of flipper-core
Summary: This diff makes sure flipper-ui-core no longer depends on flipper-server-core. Currently server config is still transferred from UI to server, which doesn't really make sense in future scenarios where server might start before client, but will address that separately Reviewed By: timur-valiev, aigoncharov Differential Revision: D32462835 fbshipit-source-id: 498a944256ba1aabbf963b896953e64d11e27214
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d48f22b8dc
commit
eed19b3a3d
@@ -34,7 +34,6 @@
|
||||
"flipper-doctor": "0.0.0",
|
||||
"flipper-plugin": "0.0.0",
|
||||
"flipper-plugin-lib": "0.0.0",
|
||||
"flipper-server-core": "0.0.0",
|
||||
"flipper-ui-core": "0.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"immer": "^9.0.6",
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
import type {NotificationEvents} from './dispatcher/notifications';
|
||||
import type {PluginNotification} from './reducers/notifications';
|
||||
import type {NotificationConstructorOptions} from 'electron';
|
||||
import type {FlipperLib} from 'flipper-plugin';
|
||||
import {FlipperLib, TestUtils} from 'flipper-plugin';
|
||||
import path from 'path';
|
||||
import {FlipperServer, Logger} from 'flipper-common';
|
||||
|
||||
type ENVIRONMENT_VARIABLES = 'NODE_ENV' | 'DEV_SERVER_URL' | 'CONFIG';
|
||||
type ENVIRONMENT_PATHS =
|
||||
@@ -106,6 +107,16 @@ export interface RenderHost {
|
||||
paths: Record<ENVIRONMENT_PATHS, string>;
|
||||
openLink(url: string): void;
|
||||
loadDefaultPlugins(): Record<string, any>;
|
||||
startFlipperServer(config: {
|
||||
// TODO: this config is temporarily, settings should be loaded/stored by server, not client
|
||||
logger: Logger;
|
||||
enableAndroid: boolean;
|
||||
androidHome: string;
|
||||
enableIOS: boolean;
|
||||
enablePhysicalIOS: boolean;
|
||||
idbPath: string;
|
||||
validWebSocketOrigins: string[];
|
||||
}): FlipperServer;
|
||||
}
|
||||
|
||||
export function getRenderHostInstance(): RenderHost {
|
||||
@@ -154,5 +165,6 @@ if (process.env.NODE_ENV === 'test') {
|
||||
loadDefaultPlugins() {
|
||||
return {};
|
||||
},
|
||||
startFlipperServer: () => TestUtils.createFlipperServerMock(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ Object {
|
||||
"exec": [MockFunction],
|
||||
"off": [MockFunction],
|
||||
"on": [MockFunction],
|
||||
"start": [Function],
|
||||
},
|
||||
"pluginMenuEntries": Array [],
|
||||
"selectedAppId": "TestApp#Android#MockAndroidDevice#serial",
|
||||
|
||||
@@ -26,6 +26,7 @@ export default class ArchivedDevice extends BaseDevice {
|
||||
}) {
|
||||
super(
|
||||
{
|
||||
async start() {},
|
||||
close() {},
|
||||
exec(command, ..._args: any[]) {
|
||||
throw new Error(
|
||||
|
||||
@@ -14,15 +14,12 @@ import {
|
||||
Logger,
|
||||
NoLongerConnectedToClientError,
|
||||
} from 'flipper-common';
|
||||
import {FlipperServerImpl} from 'flipper-server-core';
|
||||
import {selectClient} from '../reducers/connections';
|
||||
import Client from '../Client';
|
||||
import {notification} from 'antd';
|
||||
import BaseDevice from '../devices/BaseDevice';
|
||||
import {ClientDescription, timeout} from 'flipper-common';
|
||||
import {reportPlatformFailures} from 'flipper-common';
|
||||
import {sideEffect} from '../utils/sideEffect';
|
||||
import {getStaticPath} from '../utils/pathUtils';
|
||||
import constants from '../fb-stubs/constants';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
|
||||
@@ -30,19 +27,15 @@ export default async (store: Store, logger: Logger) => {
|
||||
const {enableAndroid, androidHome, idbPath, enableIOS, enablePhysicalIOS} =
|
||||
store.getState().settingsState;
|
||||
|
||||
const server = new FlipperServerImpl(
|
||||
{
|
||||
enableAndroid,
|
||||
androidHome,
|
||||
idbPath,
|
||||
enableIOS,
|
||||
enablePhysicalIOS,
|
||||
staticPath: getStaticPath(),
|
||||
tmpPath: getRenderHostInstance().paths.tempPath,
|
||||
validWebSocketOrigins: constants.VALID_WEB_SOCKET_REQUEST_ORIGIN_PREFIXES,
|
||||
},
|
||||
const server = getRenderHostInstance().startFlipperServer({
|
||||
logger,
|
||||
);
|
||||
enableAndroid,
|
||||
androidHome,
|
||||
idbPath,
|
||||
enableIOS,
|
||||
enablePhysicalIOS,
|
||||
validWebSocketOrigins: constants.VALID_WEB_SOCKET_REQUEST_ORIGIN_PREFIXES,
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'SET_FLIPPER_SERVER',
|
||||
|
||||
@@ -14,12 +14,11 @@ import {createStore} from 'redux';
|
||||
import {LaunchEmulatorDialog} from '../LaunchEmulator';
|
||||
|
||||
import {createRootReducer} from '../../../reducers';
|
||||
import {sleep} from 'flipper-plugin';
|
||||
import {createFlipperServerMock} from '../../../test-utils/createFlipperServerMock';
|
||||
import {sleep, TestUtils} from 'flipper-plugin';
|
||||
|
||||
test('Can render and launch android apps - empty', async () => {
|
||||
const store = createStore(createRootReducer());
|
||||
const mockServer = createFlipperServerMock({
|
||||
const mockServer = TestUtils.createFlipperServerMock({
|
||||
'ios-get-simulators': () => Promise.resolve([]),
|
||||
'android-get-emulators': () => Promise.resolve([]),
|
||||
});
|
||||
@@ -49,7 +48,7 @@ test('Can render and launch android apps', async () => {
|
||||
|
||||
const store = createStore(createRootReducer());
|
||||
const launch = jest.fn().mockImplementation(() => Promise.resolve());
|
||||
const mockServer = createFlipperServerMock({
|
||||
const mockServer = TestUtils.createFlipperServerMock({
|
||||
'ios-get-simulators': () => Promise.resolve([]),
|
||||
'android-get-emulators': () =>
|
||||
(p = Promise.resolve(['emulator1', 'emulator2'])),
|
||||
|
||||
@@ -27,8 +27,8 @@ import {PluginDetails} from 'flipper-plugin-lib';
|
||||
import ArchivedDevice from '../devices/ArchivedDevice';
|
||||
import {ClientQuery, DeviceOS} from 'flipper-common';
|
||||
import {TestDevice} from './TestDevice';
|
||||
import {createFlipperServerMock} from './createFlipperServerMock';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
import {TestUtils} from 'flipper-plugin';
|
||||
|
||||
export interface AppOptions {
|
||||
plugins?: PluginDefinition[];
|
||||
@@ -58,7 +58,7 @@ export default class MockFlipper {
|
||||
private _clients: Client[] = [];
|
||||
private _deviceCounter: number = 0;
|
||||
private _clientCounter: number = 0;
|
||||
flipperServer: FlipperServer = createFlipperServerMock();
|
||||
flipperServer: FlipperServer = TestUtils.createFlipperServerMock();
|
||||
|
||||
public get store(): Store {
|
||||
return this._store;
|
||||
|
||||
@@ -21,6 +21,7 @@ export class TestDevice extends BaseDevice {
|
||||
) {
|
||||
super(
|
||||
{
|
||||
async start() {},
|
||||
on: jest.fn(),
|
||||
off: jest.fn(),
|
||||
exec: jest.fn(),
|
||||
|
||||
@@ -1,32 +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
|
||||
*/
|
||||
|
||||
import {FlipperServer, FlipperServerCommands} from 'flipper-common';
|
||||
|
||||
export function createFlipperServerMock(
|
||||
overrides?: Partial<FlipperServerCommands>,
|
||||
): FlipperServer {
|
||||
return {
|
||||
on: jest.fn(),
|
||||
off: jest.fn(),
|
||||
exec: jest
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
(cmd: keyof FlipperServerCommands, ...args: any[]) => {
|
||||
if (overrides?.[cmd]) {
|
||||
return (overrides[cmd] as any)(...args);
|
||||
}
|
||||
return Promise.reject(
|
||||
new Error(`FlipperServerMock exec not implemented: ${cmd}}`),
|
||||
);
|
||||
},
|
||||
),
|
||||
close: jest.fn(),
|
||||
};
|
||||
}
|
||||
@@ -16,9 +16,6 @@
|
||||
{
|
||||
"path": "../flipper-plugin"
|
||||
},
|
||||
{
|
||||
"path": "../flipper-server-core"
|
||||
},
|
||||
{
|
||||
"path": "../plugin-lib"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user