Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Make dispatcher/plugins strict
Browse files Browse the repository at this point in the history
Summary: _typescript_

Reviewed By: jknoxville

Differential Revision: D17258265

fbshipit-source-id: 875d434120422c782074d4c345f765684533e399
  • Loading branch information
passy authored and facebook-github-bot committed Sep 9, 2019
1 parent c506cc5 commit 71bb121
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/dispatcher/plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {setupMenuBar} from '../MenuBar';
import path from 'path';
import {default as config} from '../utils/processConfig';
import isProduction from '../utils/isProduction';
import {notNull} from '../utils/typeUtils';

export type PluginDefinition = {
id?: string;
Expand All @@ -51,7 +52,7 @@ export default (store: Store, logger: Logger) => {
.filter(checkDisabled(disabledPlugins))
.filter(checkGK(gatekeepedPlugins))
.map(requirePlugin(failedPlugins))
.filter(Boolean);
.filter(notNull);

store.dispatch(addGatekeepedPlugins(gatekeepedPlugins));
store.dispatch(addDisabledPlugins(disabledPlugins));
Expand Down Expand Up @@ -87,18 +88,19 @@ function getBundledPlugins(): Array<PluginDefinition> {

let bundledPlugins: Array<PluginDefinition> = [];
try {
// TODO We can probably define this in the globals file.
bundledPlugins = (global as any).electronRequire(
bundledPlugins = global.electronRequire(
path.join(pluginPath, 'index.json'),
);
} catch (e) {
console.error(e);
}

return bundledPlugins.map(plugin => ({
...plugin,
out: path.join(pluginPath, plugin.out),
}));
return bundledPlugins
.filter(plugin => notNull(plugin.out))
.map(plugin => ({
...plugin,
out: path.join(pluginPath, plugin.out!),
}));
}

export function getDynamicPlugins() {
Expand Down Expand Up @@ -146,11 +148,11 @@ export const checkDisabled = (disabledPlugins: Array<PluginDefinition>) => (

export const requirePlugin = (
failedPlugins: Array<[PluginDefinition, string]>,
reqFn: Function = (global as any).electronRequire,
reqFn: Function = global.electronRequire,
) => {
return (
pluginDefinition: PluginDefinition,
): typeof FlipperPlugin | typeof FlipperDevicePlugin => {
): typeof FlipperPlugin | typeof FlipperDevicePlugin | null => {
try {
let plugin = reqFn(pluginDefinition.out);
if (plugin.default) {
Expand All @@ -169,7 +171,8 @@ export const requirePlugin = (
'Field "id" not allowed in package.json. The plugin\'s name will be used as ID"',
);
} else {
plugin[key] = plugin[key] || pluginDefinition[key];
plugin[key] =
plugin[key] || pluginDefinition[key as keyof PluginDefinition];
}
});

Expand Down
2 changes: 1 addition & 1 deletion types/nodejs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare module NodeJS {
interface Global {
__REVISION__: string | undefined;
__VERSION__: string;
electronRequire: (name: string) => void;
electronRequire: (name: string) => any;
window: Window | undefined;
WebSocket: any;
fetch: any;
Expand Down

0 comments on commit 71bb121

Please sign in to comment.