From c3e4f1618884c8088f8039c8998934c82c950ce7 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 25 Oct 2018 12:52:25 -0700 Subject: [PATCH] Restructure modules to reduce import-time side effects Summary: `flipper` does a lot of stuff at import time. I copied the `styled` reexport to the UI module, so it's possible to just depend on that. `remote` is another one of those pot holes that can easily ruin your journey if you aren't careful navigating around it. Added some defensive fallbacks here which ultimately allows the lint test to run (and pass) without Electron. Reviewed By: danielbuechele Differential Revision: D10507655 fbshipit-source-id: 6dad5665ba15b5cb73caa4ea46262cf337173eb8 --- src/plugins/index.js | 8 ++++---- src/ui/components/Interactive.js | 2 +- src/ui/index.js | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/index.js b/src/plugins/index.js index 209d68429..47ced6374 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -17,8 +17,6 @@ import { import {remote} from 'electron'; const plugins = new Map(); -// $FlowFixMe process.env not defined in electron API spec -const remoteEnv = remote.process.env; // expose Flipper and exact globally for dynamically loaded plugins window.React = React; @@ -33,14 +31,16 @@ const addIfNotAdded = plugin => { let disabledPlugins = []; try { - disabledPlugins = JSON.parse(remoteEnv.CONFIG || '{}').disabledPlugins || []; + // $FlowFixMe process.env not defined in electron API spec + disabledPlugins = JSON.parse(remote?.process.env.CONFIG || '{}').disabledPlugins || []; } catch (e) { console.error(e); } // Load dynamic plugins try { - JSON.parse(remoteEnv.PLUGINS || '[]').forEach(addIfNotAdded); + // $FlowFixMe process.env not defined in electron API spec + JSON.parse(remote?.process.env.PLUGINS || '[]').forEach(addIfNotAdded); } catch (e) { console.error(e); } diff --git a/src/ui/components/Interactive.js b/src/ui/components/Interactive.js index cb156d262..c3c17ac44 100644 --- a/src/ui/components/Interactive.js +++ b/src/ui/components/Interactive.js @@ -13,7 +13,7 @@ import { maybeSnapTop, SNAP_SIZE, } from '../../utils/snap.js'; -import {styled} from 'flipper'; +import {styled} from '../../ui'; const invariant = require('invariant'); const React = require('react'); diff --git a/src/ui/index.js b/src/ui/index.js index 045e1b167..f1ae73371 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -5,6 +5,7 @@ * @format */ +export {default as styled} from 'react-emotion'; export {default as Button} from './components/Button.js'; export {default as ToggleButton} from './components/ToggleSwitch.js'; export {