Make dispatcher/plugins strict
Summary: _typescript_ Reviewed By: jknoxville Differential Revision: D17258265 fbshipit-source-id: 875d434120422c782074d4c345f765684533e399
This commit is contained in:
committed by
Facebook Github Bot
parent
c506cc57b1
commit
71bb121ab8
@@ -25,6 +25,7 @@ import {setupMenuBar} from '../MenuBar';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {default as config} from '../utils/processConfig';
|
import {default as config} from '../utils/processConfig';
|
||||||
import isProduction from '../utils/isProduction';
|
import isProduction from '../utils/isProduction';
|
||||||
|
import {notNull} from '../utils/typeUtils';
|
||||||
|
|
||||||
export type PluginDefinition = {
|
export type PluginDefinition = {
|
||||||
id?: string;
|
id?: string;
|
||||||
@@ -51,7 +52,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
.filter(checkDisabled(disabledPlugins))
|
.filter(checkDisabled(disabledPlugins))
|
||||||
.filter(checkGK(gatekeepedPlugins))
|
.filter(checkGK(gatekeepedPlugins))
|
||||||
.map(requirePlugin(failedPlugins))
|
.map(requirePlugin(failedPlugins))
|
||||||
.filter(Boolean);
|
.filter(notNull);
|
||||||
|
|
||||||
store.dispatch(addGatekeepedPlugins(gatekeepedPlugins));
|
store.dispatch(addGatekeepedPlugins(gatekeepedPlugins));
|
||||||
store.dispatch(addDisabledPlugins(disabledPlugins));
|
store.dispatch(addDisabledPlugins(disabledPlugins));
|
||||||
@@ -87,17 +88,18 @@ function getBundledPlugins(): Array<PluginDefinition> {
|
|||||||
|
|
||||||
let bundledPlugins: Array<PluginDefinition> = [];
|
let bundledPlugins: Array<PluginDefinition> = [];
|
||||||
try {
|
try {
|
||||||
// TODO We can probably define this in the globals file.
|
bundledPlugins = global.electronRequire(
|
||||||
bundledPlugins = (global as any).electronRequire(
|
|
||||||
path.join(pluginPath, 'index.json'),
|
path.join(pluginPath, 'index.json'),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bundledPlugins.map(plugin => ({
|
return bundledPlugins
|
||||||
|
.filter(plugin => notNull(plugin.out))
|
||||||
|
.map(plugin => ({
|
||||||
...plugin,
|
...plugin,
|
||||||
out: path.join(pluginPath, plugin.out),
|
out: path.join(pluginPath, plugin.out!),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,11 +148,11 @@ export const checkDisabled = (disabledPlugins: Array<PluginDefinition>) => (
|
|||||||
|
|
||||||
export const requirePlugin = (
|
export const requirePlugin = (
|
||||||
failedPlugins: Array<[PluginDefinition, string]>,
|
failedPlugins: Array<[PluginDefinition, string]>,
|
||||||
reqFn: Function = (global as any).electronRequire,
|
reqFn: Function = global.electronRequire,
|
||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
pluginDefinition: PluginDefinition,
|
pluginDefinition: PluginDefinition,
|
||||||
): typeof FlipperPlugin | typeof FlipperDevicePlugin => {
|
): typeof FlipperPlugin | typeof FlipperDevicePlugin | null => {
|
||||||
try {
|
try {
|
||||||
let plugin = reqFn(pluginDefinition.out);
|
let plugin = reqFn(pluginDefinition.out);
|
||||||
if (plugin.default) {
|
if (plugin.default) {
|
||||||
@@ -169,7 +171,8 @@ export const requirePlugin = (
|
|||||||
'Field "id" not allowed in package.json. The plugin\'s name will be used as ID"',
|
'Field "id" not allowed in package.json. The plugin\'s name will be used as ID"',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
plugin[key] = plugin[key] || pluginDefinition[key];
|
plugin[key] =
|
||||||
|
plugin[key] || pluginDefinition[key as keyof PluginDefinition];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ declare module NodeJS {
|
|||||||
interface Global {
|
interface Global {
|
||||||
__REVISION__: string | undefined;
|
__REVISION__: string | undefined;
|
||||||
__VERSION__: string;
|
__VERSION__: string;
|
||||||
electronRequire: (name: string) => void;
|
electronRequire: (name: string) => any;
|
||||||
window: Window | undefined;
|
window: Window | undefined;
|
||||||
WebSocket: any;
|
WebSocket: any;
|
||||||
fetch: any;
|
fetch: any;
|
||||||
|
|||||||
Reference in New Issue
Block a user