From 1dcf1980719bc45b867a7afd3da4d9fdd09c1a28 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 10 Oct 2022 09:06:01 -0400 Subject: [PATCH] Move background to top-level --- extension/src/app/api/importState.ts | 2 +- extension/src/app/api/index.ts | 6 +++--- extension/src/app/api/openWindow.ts | 2 +- extension/src/app/containers/Actions.tsx | 2 +- extension/src/app/middlewares/windowSync.ts | 4 ++-- extension/src/app/stores/windowStore.ts | 9 ++++++--- .../extension => }/background/contextMenus.ts | 0 .../extension => }/background/index.ts | 8 +++----- .../extension => }/background/logging.ts | 0 .../extension => }/background/openWindow.ts | 0 .../store/apiMiddleware.ts} | 19 +++++++------------ .../store/backgroundReducer.ts} | 2 +- .../store}/backgroundStore.ts | 4 ++-- .../src/browser/extension/devpanel/index.tsx | 2 +- .../browser/extension/inject/contentScript.ts | 2 +- .../src/browser/extension/window/index.tsx | 2 +- extension/webpack/base.config.js | 2 +- 17 files changed, 31 insertions(+), 35 deletions(-) rename extension/src/{browser/extension => }/background/contextMenus.ts (100%) rename extension/src/{browser/extension => }/background/index.ts (82%) rename extension/src/{browser/extension => }/background/logging.ts (100%) rename extension/src/{browser/extension => }/background/openWindow.ts (100%) rename extension/src/{app/middlewares/api.ts => background/store/apiMiddleware.ts} (97%) rename extension/src/{app/reducers/background/index.ts => background/store/backgroundReducer.ts} (84%) rename extension/src/{app/stores => background/store}/backgroundStore.ts (93%) diff --git a/extension/src/app/api/importState.ts b/extension/src/app/api/importState.ts index 70bda05e..21e587e2 100644 --- a/extension/src/app/api/importState.ts +++ b/extension/src/app/api/importState.ts @@ -1,6 +1,6 @@ import jsan from 'jsan'; import { immutableSerialize } from '@redux-devtools/serialize'; -import { +import type { Config, SerializeWithImmutable, } from '../../browser/extension/inject/pageScript'; diff --git a/extension/src/app/api/index.ts b/extension/src/app/api/index.ts index e0e6c3a9..47ba7d5c 100644 --- a/extension/src/app/api/index.ts +++ b/extension/src/app/api/index.ts @@ -5,15 +5,15 @@ import { getActionsArray, getLocalFilter } from '@redux-devtools/utils'; import { isFiltered, PartialLiftedState } from './filters'; import importState from './importState'; import generateId from './generateInstanceId'; -import { Config } from '../../browser/extension/inject/pageScript'; +import type { Config } from '../../browser/extension/inject/pageScript'; import { Action } from 'redux'; import { LiftedState, PerformAction } from '@redux-devtools/instrument'; import { LibConfig } from '@redux-devtools/app'; -import { +import type { ContentScriptToPageScriptMessage, ListenerMessage, } from '../../browser/extension/inject/contentScript'; -import { Position } from './openWindow'; +import type { Position } from './openWindow'; const listeners: { [instanceId: string]: diff --git a/extension/src/app/api/openWindow.ts b/extension/src/app/api/openWindow.ts index 51f9d145..53704b58 100644 --- a/extension/src/app/api/openWindow.ts +++ b/extension/src/app/api/openWindow.ts @@ -1,5 +1,5 @@ import { Action } from 'redux'; -import { PageScriptToContentScriptMessage } from './index'; +import type { PageScriptToContentScriptMessage } from './index'; export type Position = 'left' | 'right' | 'bottom' | 'panel' | 'remote'; diff --git a/extension/src/app/containers/Actions.tsx b/extension/src/app/containers/Actions.tsx index c821afe4..987a1459 100644 --- a/extension/src/app/containers/Actions.tsx +++ b/extension/src/app/containers/Actions.tsx @@ -20,7 +20,7 @@ import { import { GoRadioTower } from 'react-icons/go'; import { MdBorderBottom, MdBorderLeft, MdBorderRight } from 'react-icons/md'; import { Position } from '../api/openWindow'; -import { SingleMessage } from '../middlewares/api'; +import type { SingleMessage } from '../../background/store/apiMiddleware'; type StateProps = ReturnType; type DispatchProps = ResolveThunks; diff --git a/extension/src/app/middlewares/windowSync.ts b/extension/src/app/middlewares/windowSync.ts index e6c2c599..fbd4a719 100644 --- a/extension/src/app/middlewares/windowSync.ts +++ b/extension/src/app/middlewares/windowSync.ts @@ -7,9 +7,9 @@ import { UPDATE_STATE, } from '@redux-devtools/app'; import { Dispatch, MiddlewareAPI, Store } from 'redux'; -import { BackgroundState } from '../reducers/background'; +import type { BackgroundState } from '../../background/store/backgroundReducer'; import { WindowStoreAction } from '../stores/windowStore'; -import { BackgroundAction } from '../stores/backgroundStore'; +import type { BackgroundAction } from '../../background/store/backgroundStore'; const syncStores = (baseStore: Store) => diff --git a/extension/src/app/stores/windowStore.ts b/extension/src/app/stores/windowStore.ts index 186203ab..e3622a23 100644 --- a/extension/src/app/stores/windowStore.ts +++ b/extension/src/app/stores/windowStore.ts @@ -20,9 +20,12 @@ import { import syncStores from '../middlewares/windowSync'; import instanceSelector from '../middlewares/instanceSelector'; import rootReducer from '../reducers/window'; -import { BackgroundState } from '../reducers/background'; -import { BackgroundAction } from './backgroundStore'; -import { EmptyUpdateStateAction, NAAction } from '../middlewares/api'; +import type { BackgroundState } from '../../background/store/backgroundReducer'; +import type { BackgroundAction } from '../../background/store/backgroundStore'; +import type { + EmptyUpdateStateAction, + NAAction, +} from '../../background/store/apiMiddleware'; export interface ExpandedUpdateStateAction extends UpdateStateAction { readonly instances: InstancesState; diff --git a/extension/src/browser/extension/background/contextMenus.ts b/extension/src/background/contextMenus.ts similarity index 100% rename from extension/src/browser/extension/background/contextMenus.ts rename to extension/src/background/contextMenus.ts diff --git a/extension/src/browser/extension/background/index.ts b/extension/src/background/index.ts similarity index 82% rename from extension/src/browser/extension/background/index.ts rename to extension/src/background/index.ts index 165b1af0..57c58d6e 100644 --- a/extension/src/browser/extension/background/index.ts +++ b/extension/src/background/index.ts @@ -1,11 +1,9 @@ import { Store } from 'redux'; -import configureStore, { - BackgroundAction, -} from '../../../app/stores/backgroundStore'; +import configureStore, { BackgroundAction } from './store/backgroundStore'; import openDevToolsWindow, { DevToolsPosition } from './openWindow'; import { createMenu, removeMenu } from './contextMenus'; -import syncOptions from '../options/syncOptions'; -import { BackgroundState } from '../../../app/reducers/background'; +import syncOptions from '../browser/extension/options/syncOptions'; +import { BackgroundState } from './store/backgroundReducer'; declare global { interface Window { diff --git a/extension/src/browser/extension/background/logging.ts b/extension/src/background/logging.ts similarity index 100% rename from extension/src/browser/extension/background/logging.ts rename to extension/src/background/logging.ts diff --git a/extension/src/browser/extension/background/openWindow.ts b/extension/src/background/openWindow.ts similarity index 100% rename from extension/src/browser/extension/background/openWindow.ts rename to extension/src/background/openWindow.ts diff --git a/extension/src/app/middlewares/api.ts b/extension/src/background/store/apiMiddleware.ts similarity index 97% rename from extension/src/app/middlewares/api.ts rename to extension/src/background/store/apiMiddleware.ts index c8cb8937..3209228e 100644 --- a/extension/src/app/middlewares/api.ts +++ b/extension/src/background/store/apiMiddleware.ts @@ -16,27 +16,22 @@ import syncOptions, { OptionsMessage, SyncOptions, } from '../../browser/extension/options/syncOptions'; -import openDevToolsWindow, { - DevToolsPosition, -} from '../../browser/extension/background/openWindow'; -import { getReport } from '../../browser/extension/background/logging'; +import openDevToolsWindow, { DevToolsPosition } from '../openWindow'; +import { getReport } from '../logging'; import { Action, Dispatch, MiddlewareAPI } from 'redux'; import { ContentScriptToBackgroundMessage, SplitMessage, } from '../../browser/extension/inject/contentScript'; -import { +import type { ErrorMessage, PageScriptToContentScriptMessageForwardedToMonitors, PageScriptToContentScriptMessageWithoutDisconnectOrInitInstance, -} from '../api'; +} from '../../app/api'; import { LiftedState } from '@redux-devtools/instrument'; -import { - BackgroundAction, - LiftedActionAction, -} from '../stores/backgroundStore'; -import { Position } from '../api/openWindow'; -import { BackgroundState } from '../reducers/background'; +import type { BackgroundAction, LiftedActionAction } from './backgroundStore'; +import type { Position } from '../../app/api/openWindow'; +import type { BackgroundState } from './backgroundReducer'; interface TabMessageBase { readonly type: string; diff --git a/extension/src/app/reducers/background/index.ts b/extension/src/background/store/backgroundReducer.ts similarity index 84% rename from extension/src/app/reducers/background/index.ts rename to extension/src/background/store/backgroundReducer.ts index bea610c0..01ca5a02 100644 --- a/extension/src/app/reducers/background/index.ts +++ b/extension/src/background/store/backgroundReducer.ts @@ -1,6 +1,6 @@ import { combineReducers, Reducer } from 'redux'; import { instances, InstancesState } from '@redux-devtools/app'; -import { BackgroundAction } from '../../stores/backgroundStore'; +import type { BackgroundAction } from './backgroundStore'; export interface BackgroundState { readonly instances: InstancesState; diff --git a/extension/src/app/stores/backgroundStore.ts b/extension/src/background/store/backgroundStore.ts similarity index 93% rename from extension/src/app/stores/backgroundStore.ts rename to extension/src/background/store/backgroundStore.ts index 55eed9e4..da72bdd4 100644 --- a/extension/src/app/stores/backgroundStore.ts +++ b/extension/src/background/store/backgroundStore.ts @@ -5,8 +5,8 @@ import { LIFTED_ACTION, StoreActionWithoutLiftedAction, } from '@redux-devtools/app'; -import rootReducer, { BackgroundState } from '../reducers/background'; -import api, { CONNECTED, DISCONNECTED } from '../middlewares/api'; +import rootReducer, { BackgroundState } from './backgroundReducer'; +import api, { CONNECTED, DISCONNECTED } from './apiMiddleware'; interface LiftedActionActionBase { action?: DispatchAction | string | CustomAction; diff --git a/extension/src/browser/extension/devpanel/index.tsx b/extension/src/browser/extension/devpanel/index.tsx index af4fbfc3..ae740870 100644 --- a/extension/src/browser/extension/devpanel/index.tsx +++ b/extension/src/browser/extension/devpanel/index.tsx @@ -8,7 +8,7 @@ import configureStore from '../../../app/stores/panelStore'; import '../../views/devpanel.pug'; import { Action, Store } from 'redux'; -import { PanelMessage } from '../../../app/middlewares/api'; +import type { PanelMessage } from '../../../background/store/apiMiddleware'; import { StoreStateWithoutSocket } from '../../../app/reducers/panel'; import { PersistGate } from 'redux-persist/integration/react'; diff --git a/extension/src/browser/extension/inject/contentScript.ts b/extension/src/browser/extension/inject/contentScript.ts index 61c49e85..b9a71c4a 100644 --- a/extension/src/browser/extension/inject/contentScript.ts +++ b/extension/src/browser/extension/inject/contentScript.ts @@ -3,7 +3,7 @@ import { getOptionsFromBg, isAllowed, } from '../options/syncOptions'; -import { TabMessage } from '../../../app/middlewares/api'; +import type { TabMessage } from '../../../background/store/apiMiddleware'; import { PageScriptToContentScriptMessage, PageScriptToContentScriptMessageWithoutDisconnect, diff --git a/extension/src/browser/extension/window/index.tsx b/extension/src/browser/extension/window/index.tsx index 41b72b08..d8d41323 100644 --- a/extension/src/browser/extension/window/index.tsx +++ b/extension/src/browser/extension/window/index.tsx @@ -5,7 +5,7 @@ import { PersistGate } from 'redux-persist/integration/react'; import { UPDATE_STATE } from '@redux-devtools/app'; import App from '../../../app/containers/App'; import configureStore from '../../../app/stores/windowStore'; -import { MonitorMessage } from '../../../app/middlewares/api'; +import type { MonitorMessage } from '../../../background/store/apiMiddleware'; import '../../views/window.pug'; diff --git a/extension/webpack/base.config.js b/extension/webpack/base.config.js index b320b890..545ae745 100644 --- a/extension/webpack/base.config.js +++ b/extension/webpack/base.config.js @@ -10,7 +10,7 @@ const baseConfig = (params) => ({ // devtool: 'source-map', mode: params.mode, entry: params.input || { - background: [mock, `${extpath}background/index`], + background: [mock, '../src/background/index'], options: [mock, `${extpath}options/index`], window: [`${extpath}window/index`], remote: [`${extpath}window/remote`],