move plugin management from ui-core to server-core
Summary: Follow up of D32665064, this diff moves all plugin management logic from flipper-ui to flipper-server. Things like downloading, installing, querying new plugins. Loading plugins is handled separately in the next diff. Reviewed By: nikoant Differential Revision: D32666537 fbshipit-source-id: 9786b82987f00180bb26200e38735b334dc4d5c3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f9b72ac69e
commit
64747dc417
@@ -14,23 +14,18 @@ import {
|
||||
reportPlatformFailures,
|
||||
reportUsage,
|
||||
InstalledPluginDetails,
|
||||
UpdateResult,
|
||||
UpdatablePluginDetails,
|
||||
} from 'flipper-common';
|
||||
import reloadFlipper from '../../utils/reloadFlipper';
|
||||
import {registerInstalledPlugins} from '../../reducers/plugins';
|
||||
import {
|
||||
UpdateResult,
|
||||
getInstalledPlugins,
|
||||
getUpdatablePlugins,
|
||||
removePlugin,
|
||||
UpdatablePluginDetails,
|
||||
} from 'flipper-plugin-lib';
|
||||
import {installPluginFromNpm} from 'flipper-plugin-lib';
|
||||
import {State as AppState} from '../../reducers';
|
||||
import {connect} from 'react-redux';
|
||||
import {Dispatch, Action} from 'redux';
|
||||
import PluginPackageInstaller from './PluginPackageInstaller';
|
||||
import {Toolbar} from 'flipper-plugin';
|
||||
import {Alert, Button, Input, Tooltip, Typography} from 'antd';
|
||||
import {getRenderHostInstance} from '../../RenderHost';
|
||||
|
||||
const {Text, Link} = Typography;
|
||||
|
||||
@@ -327,8 +322,33 @@ export default connect<PropsFromState, DispatchFromProps, OwnProps, AppState>(
|
||||
}),
|
||||
(dispatch: Dispatch<Action<any>>) => ({
|
||||
refreshInstalledPlugins: async () => {
|
||||
const plugins = await getInstalledPlugins();
|
||||
const plugins = await await getRenderHostInstance().flipperServer!.exec(
|
||||
'plugins-get-installed-plugins',
|
||||
);
|
||||
dispatch(registerInstalledPlugins(plugins));
|
||||
},
|
||||
}),
|
||||
)(PluginInstaller);
|
||||
|
||||
async function installPluginFromNpm(
|
||||
name: string,
|
||||
): Promise<InstalledPluginDetails> {
|
||||
return await getRenderHostInstance().flipperServer!.exec(
|
||||
'plugins-install-from-npm',
|
||||
name,
|
||||
);
|
||||
}
|
||||
|
||||
async function removePlugin(name: string) {
|
||||
return await getRenderHostInstance().flipperServer!.exec(
|
||||
'plugins-remove-plugins',
|
||||
[name],
|
||||
);
|
||||
}
|
||||
|
||||
async function getUpdatablePlugins(query: string | undefined) {
|
||||
return await getRenderHostInstance().flipperServer!.exec(
|
||||
'plugins-get-updatable-plugins',
|
||||
query,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ import {
|
||||
} from '../../ui';
|
||||
import styled from '@emotion/styled';
|
||||
import React, {useState} from 'react';
|
||||
import {installPluginFromFile} from 'flipper-plugin-lib';
|
||||
import {Toolbar, FileSelector} from 'flipper-plugin';
|
||||
import {getRenderHostInstance} from '../../RenderHost';
|
||||
|
||||
const CenteredGlyph = styled(Glyph)({
|
||||
margin: 'auto',
|
||||
@@ -51,7 +51,10 @@ export default function PluginPackageInstaller({
|
||||
setError(undefined);
|
||||
setInProgress(true);
|
||||
try {
|
||||
await installPluginFromFile(path);
|
||||
await getRenderHostInstance().flipperServer!.exec(
|
||||
'plugins-install-from-file',
|
||||
path,
|
||||
);
|
||||
await onInstall();
|
||||
} catch (e) {
|
||||
setError(e);
|
||||
|
||||
@@ -7,19 +7,22 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
jest.mock('flipper-plugin-lib');
|
||||
|
||||
import {default as PluginInstaller} from '../PluginInstaller';
|
||||
import React from 'react';
|
||||
import {render, waitFor} from '@testing-library/react';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import {Provider} from 'react-redux';
|
||||
import type {PluginDetails} from 'flipper-common';
|
||||
import {getUpdatablePlugins, UpdatablePluginDetails} from 'flipper-plugin-lib';
|
||||
import type {PluginDetails, UpdatablePluginDetails} from 'flipper-common';
|
||||
import {Store} from '../../../reducers';
|
||||
import {mocked} from 'ts-jest/utils';
|
||||
import {getRenderHostInstance} from '../../../RenderHost';
|
||||
|
||||
const getUpdatablePluginsMock = mocked(getUpdatablePlugins);
|
||||
let getUpdatablePluginsMock: jest.Mock<any, any>;
|
||||
|
||||
beforeEach(() => {
|
||||
// flipperServer get resets before each test, no need to do so explicitly
|
||||
getUpdatablePluginsMock = getRenderHostInstance().flipperServer!.exec =
|
||||
jest.fn();
|
||||
});
|
||||
|
||||
function getStore(installedPlugins: PluginDetails[] = []): Store {
|
||||
return configureStore([])({
|
||||
@@ -70,10 +73,6 @@ const samplePluginDetails2: UpdatablePluginDetails = {
|
||||
|
||||
const SEARCH_RESULTS = [samplePluginDetails1, samplePluginDetails2];
|
||||
|
||||
afterEach(() => {
|
||||
getUpdatablePluginsMock.mockClear();
|
||||
});
|
||||
|
||||
test('load PluginInstaller list', async () => {
|
||||
getUpdatablePluginsMock.mockReturnValue(Promise.resolve(SEARCH_RESULTS));
|
||||
const component = (
|
||||
|
||||
Reference in New Issue
Block a user