Pass plugins via ipc instead of env to fix loading of plugins on Windows

Summary: Fixed the issue with empty plugin list on Windows because of env var length limit

Reviewed By: passy

Differential Revision: D19411466

fbshipit-source-id: 7fa390f7dd342e23e965b2135fbeb8e88e5857ef
This commit is contained in:
Anton Nikolaev
2020-01-17 03:48:04 -08:00
committed by Facebook Github Bot
parent 2f3b9e1be9
commit 73e0f9035a
4 changed files with 16 additions and 19 deletions

View File

@@ -20,4 +20,5 @@ module.exports = {
}, },
getCurrentWindow: () => ({isFocused: () => true}), getCurrentWindow: () => ({isFocused: () => true}),
}, },
ipcRenderer: {},
}; };

View File

@@ -14,7 +14,7 @@ import dispatcher, {
requirePlugin, requirePlugin,
} from '../plugins.tsx'; } from '../plugins.tsx';
import path from 'path'; import path from 'path';
import {remote} from 'electron'; import {ipcRenderer, remote} from 'electron';
import {FlipperPlugin} from 'flipper'; import {FlipperPlugin} from 'flipper';
import reducers from '../../reducers/index.tsx'; import reducers from '../../reducers/index.tsx';
import {init as initLogger} from '../../fb-stubs/Logger.tsx'; import {init as initLogger} from '../../fb-stubs/Logger.tsx';
@@ -31,24 +31,20 @@ test('dispatcher dispatches REGISTER_PLUGINS', () => {
expect(actions.map(a => a.type)).toContain('REGISTER_PLUGINS'); expect(actions.map(a => a.type)).toContain('REGISTER_PLUGINS');
}); });
test('getDynamicPlugins returns empty array', () => { test('getDynamicPlugins returns empty array on errors', () => {
// $FlowFixMe process.env not defined in electron API spec ipcRenderer.sendSync = jest.fn();
remote.process.env.PLUGINS = null; ipcRenderer.sendSync.mockImplementation(() => {
console.log('aaa');
throw new Error('ooops');
});
const res = getDynamicPlugins(); const res = getDynamicPlugins();
expect(res).toEqual([]); expect(res).toEqual([]);
}); });
test('getDynamicPlugins returns empty array for invalid JSON', () => { test('getDynamicPlugins from main process via ipc', () => {
// $FlowFixMe process.env not defined in electron API spec
remote.process.env.PLUGINS = 'invalid JOSN }}[]';
const res = getDynamicPlugins();
expect(res).toEqual([]);
});
test('getDynamicPlugins from env', () => {
const plugins = [{name: 'test'}]; const plugins = [{name: 'test'}];
// $FlowFixMe process.env not defined in electron API spec ipcRenderer.sendSync = jest.fn();
remote.process.env.PLUGINS = JSON.stringify(plugins); ipcRenderer.sendSync.mockReturnValue(plugins);
const res = getDynamicPlugins(); const res = getDynamicPlugins();
expect(res).toEqual(plugins); expect(res).toEqual(plugins);
}); });

View File

@@ -21,7 +21,7 @@ import {
addDisabledPlugins, addDisabledPlugins,
addFailedPlugins, addFailedPlugins,
} from '../reducers/plugins'; } from '../reducers/plugins';
import {remote} from 'electron'; import {ipcRenderer} from 'electron';
import GK from '../fb-stubs/GK'; import GK from '../fb-stubs/GK';
import {FlipperBasePlugin} from '../plugin'; import {FlipperBasePlugin} from '../plugin';
import {setupMenuBar} from '../MenuBar'; import {setupMenuBar} from '../MenuBar';
@@ -110,9 +110,7 @@ function getBundledPlugins(): Array<PluginDefinition> {
export function getDynamicPlugins() { export function getDynamicPlugins() {
let dynamicPlugins: Array<PluginDefinition> = []; let dynamicPlugins: Array<PluginDefinition> = [];
try { try {
dynamicPlugins = JSON.parse( dynamicPlugins = ipcRenderer.sendSync('get-dynamic-plugins');
(remote && remote.process.env.PLUGINS) || process.env.PLUGINS || '[]',
);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@@ -111,7 +111,9 @@ compilePlugins(
pluginPaths, pluginPaths,
path.join(flipperDir, 'plugins'), path.join(flipperDir, 'plugins'),
).then(dynamicPlugins => { ).then(dynamicPlugins => {
process.env.PLUGINS = JSON.stringify(dynamicPlugins); ipcMain.on('get-dynamic-plugins', event => {
event.returnValue = dynamicPlugins;
});
pluginsCompiled = true; pluginsCompiled = true;
tryCreateWindow(); tryCreateWindow();
}); });