Skip to content

Commit

Permalink
Avoid most explicit cross-boundary imports (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Feb 15, 2022
1 parent 81dc794 commit 49c3b06
Show file tree
Hide file tree
Showing 51 changed files with 195 additions and 126 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
const contexts = [
"background",
"contentScript",
"devTools",
"options",
"actionPanel",
// "pageScript", // TODO: After Messenger migration
];

const restrictedZones = [];
for (const exporter of contexts) {
for (const importer of contexts) {
if (exporter !== importer) {
restrictedZones.push({
target: `./src/${importer}/**/*`,
from: `./src/${exporter}`,
except: [
`../${exporter}/messenger/api.ts`,
`../${exporter}/types.ts`,
`../${exporter}/nativeEditor/types.ts`,
],
});
}
}
}

module.exports = {
root: true,
extends: [
// Full config: https://github.com/fregante/eslint-config-pixiebrix/blob/main/index.js
"pixiebrix",
],
rules: {
"import/no-restricted-paths": [
"error",
{
zones: restrictedZones,
},
],

// Only enable this on tsx files
"filenames/match-exported": "off",

Expand Down
8 changes: 5 additions & 3 deletions src/actionPanel/ActionPanelApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ import { Button } from "react-bootstrap";
import logo from "@img/logo.svg";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleDoubleRight, faCog } from "@fortawesome/free-solid-svg-icons";
import { getStore } from "@/actionPanel/native";
// eslint-disable-next-line import/no-restricted-paths -- TODO: This should be called in the content script, but it currently has to be sync
import { getActionPanelStore } from "@/contentScript/actionPanel";
import {
addListener,
removeListener,
StoreListener,
} from "@/actionPanel/protocol";
import DefaultActionPanel from "@/actionPanel/DefaultActionPanel";
import { ToastProvider } from "react-toast-notifications";
// eslint-disable-next-line import/no-restricted-paths -- TODO: move out of @/options or use Messenger
import store, { persistor } from "@/options/store";
import { Provider } from "react-redux";
import Loader from "@/components/Loader";
import { PersistGate } from "redux-persist/integration/react";
import { PanelEntry, FormEntry } from "@/actionPanel/actionPanelTypes";
import { PanelEntry, FormEntry } from "@/actionPanel/types";
import ActionPanelTabs from "@/actionPanel/ActionPanelTabs";
import slice, { blankActionPanelState } from "./actionPanelSlice";
import { AnyAction } from "redux";
Expand All @@ -58,7 +60,7 @@ function getConnectedListener(dispatch: Dispatch<AnyAction>): StoreListener {
const ActionPanelApp: React.FunctionComponent = () => {
const [state, dispatch] = useReducer(slice.reducer, {
...blankActionPanelState,
...getStore(),
...getActionPanelStore(),
});

const listener: StoreListener = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/actionPanel/ActionPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import React, { useCallback, useEffect } from "react";
import { ActionPanelStore, PanelEntry } from "@/actionPanel/actionPanelTypes";
import { ActionPanelStore, PanelEntry } from "@/actionPanel/types";
import { mapTabEventKey } from "@/actionPanel/actionPanelUtils";
import useExtensionMeta from "@/hooks/useExtensionMeta";
import { UUID } from "@/core";
Expand Down
2 changes: 1 addition & 1 deletion src/actionPanel/FormBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import React from "react";
import { FormEntry } from "@/actionPanel/actionPanelTypes";
import { FormEntry } from "@/actionPanel/types";
import { useAsyncState } from "@/hooks/common";
import Loader from "@/components/Loader";
import { getErrorMessage } from "@/errors";
Expand Down
2 changes: 1 addition & 1 deletion src/actionPanel/PanelBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ConsoleLogger from "@/tests/ConsoleLogger";
import ReactShadowRoot from "react-shadow-root";
import { getErrorMessage } from "@/errors";
import { BlockArg, RendererOutput } from "@/core";
import { PanelPayload } from "@/actionPanel/actionPanelTypes";
import { PanelPayload } from "@/actionPanel/types";
import RendererComponent from "@/actionPanel/RendererComponent";

const PanelBody: React.FunctionComponent<{ payload: PanelPayload }> = ({
Expand Down
6 changes: 1 addition & 5 deletions src/actionPanel/actionPanelSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {
ActionPanelStore,
FormEntry,
PanelEntry,
} from "@/actionPanel/actionPanelTypes";
import { ActionPanelStore, FormEntry, PanelEntry } from "@/actionPanel/types";
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import {
defaultEventKey,
Expand Down
2 changes: 1 addition & 1 deletion src/actionPanel/actionPanelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { ActionPanelStore, EntryType } from "@/actionPanel/actionPanelTypes";
import { ActionPanelStore, EntryType } from "@/actionPanel/types";
import { UUID } from "@/core";

export function mapTabEventKey(
Expand Down
2 changes: 1 addition & 1 deletion src/actionPanel/protocol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import reportError from "@/telemetry/reportError";
import { FormEntry, PanelEntry } from "@/actionPanel/actionPanelTypes";
import { FormEntry, PanelEntry } from "@/actionPanel/types";
import { FormDefinition } from "@/blocks/transformers/ephemeralForm/formTypes";
import { UUID } from "@/core";

Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/background/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { RunBlock } from "@/contentScript/executor";
// eslint-disable-next-line import/no-restricted-paths -- Type only
import type { RunBlock } from "@/contentScript/executor";
import browser, { Runtime, Tabs } from "webextension-polyfill";
import { BusinessError } from "@/errors";
import { expectContext } from "@/utils/expectContext";
Expand Down
2 changes: 2 additions & 0 deletions src/background/messenger/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const contextMenus = {
export const services = {
locate: getMethod("LOCATE_SERVICE", bg),
refresh: getMethod("REFRESH_SERVICES", bg),
refreshLocal: getMethod("LOCATOR_REFRESH_LOCAL", bg),
};

export const httpRequest = getMethod("HTTP_REQUEST", bg);
Expand All @@ -110,6 +111,7 @@ export const recordError = getNotifier("RECORD_ERROR", bg);
export const recordEvent = getNotifier("RECORD_EVENT", bg);
export const getLoggingConfig = getMethod("GET_LOGGING_CONFIG", bg);
export const setLoggingConfig = getMethod("SET_LOGGING_CONFIG", bg);
export const clearLogs = getMethod("CLEAR_LOGS", bg);

export const traces = {
addEntry: getNotifier("ADD_TRACE_ENTRY", bg),
Expand Down
5 changes: 5 additions & 0 deletions src/background/messenger/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { getAvailableVersion } from "@/background/installer";
import { locator, refreshServices } from "@/background/locator";
import { reactivateEveryTab } from "@/background/navigation";
import {
clearLogs,
getLoggingConfig,
recordError,
recordLog,
Expand Down Expand Up @@ -98,6 +99,7 @@ declare global {
REGISTRY_FIND: typeof registry.find;
LOCATE_SERVICE: typeof locator.locate;
REFRESH_SERVICES: typeof refreshServices;
LOCATOR_REFRESH_LOCAL: typeof locator.refreshLocal;

REQUEST_RUN_ON_SERVER: typeof requestRunOnServer;
REQUEST_RUN_IN_OPENER: typeof requestRunInOpener;
Expand All @@ -118,6 +120,7 @@ declare global {
RECORD_EVENT: typeof recordEvent;
GET_LOGGING_CONFIG: typeof getLoggingConfig;
SET_LOGGING_CONFIG: typeof setLoggingConfig;
CLEAR_LOGS: typeof clearLogs;

ADD_TRACE_ENTRY: typeof addTraceEntry;
ADD_TRACE_EXIT: typeof addTraceExit;
Expand Down Expand Up @@ -161,6 +164,7 @@ export default function registerMessenger(): void {
REGISTRY_SYNC: registry.syncRemote,
REGISTRY_FIND: registry.find,
LOCATE_SERVICE: locator.locate.bind(locator),
LOCATOR_REFRESH_LOCAL: locator.refreshLocal.bind(locator),
REFRESH_SERVICES: refreshServices,

REQUEST_RUN_ON_SERVER: requestRunOnServer,
Expand All @@ -182,6 +186,7 @@ export default function registerMessenger(): void {
RECORD_EVENT: recordEvent,
GET_LOGGING_CONFIG: getLoggingConfig,
SET_LOGGING_CONFIG: setLoggingConfig,
CLEAR_LOGS: clearLogs,

ADD_TRACE_ENTRY: addTraceEntry,
ADD_TRACE_EXIT: addTraceExit,
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/effects/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Effect } from "@/types";
import { BlockArg, BlockOptions, Logger, Schema } from "@/core";
import { BusinessError } from "@/errors";
import { boolean } from "@/utils";
import { requireSingleElement } from "@/nativeEditor/utils";
import { requireSingleElement } from "@/utils/requireSingleElement";
import { RequireExactlyOne } from "type-fest";

type SetValueData = RequireExactlyOne<
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/effects/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { Effect } from "@/types";
import { Schema } from "@/core";
import { hideActionPanel, showActionPanel } from "@/actionPanel/native";
import { hideActionPanel, showActionPanel } from "@/contentScript/actionPanel";

const NO_PARAMS: Schema = {
$schema: "https://json-schema.org/draft/2019-09/schema#",
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/transformers/ephemeralForm/formTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
hideActionPanelForm,
PANEL_HIDING_EVENT,
showActionPanelForm,
} from "@/actionPanel/native";
} from "@/contentScript/actionPanel";
import { showModal } from "@/blocks/transformers/ephemeralForm/modalUtils";

// The modes for createFrameSrc are different than the location argument for FormTransformer. The mode for the frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { IS_BROWSER } from "@/helpers";
import { reportEvent } from "@/telemetry/events";
import { expectContext } from "@/utils/expectContext";
import { ExtensionRef, UUID } from "@/core";
import {
import type {
ActionPanelStore,
FormEntry,
PanelEntry,
RendererError,
} from "@/actionPanel/actionPanelTypes";
} from "@/actionPanel/types";
import { RendererPayload } from "@/runtime/runtimeTypes";
import { hideForm, renderPanels, showForm } from "@/actionPanel/messenger/api";
import { MAX_Z_INDEX, PANEL_FRAME_ID } from "@/common";
Expand Down Expand Up @@ -188,7 +188,7 @@ export function isActionPanelVisible(): boolean {
return Boolean(document.querySelector(PANEL_CONTAINER_SELECTOR));
}

export function getStore(): ActionPanelStore {
export function getActionPanelStore(): ActionPanelStore {
// `forms` state is managed by the action panel react component
return { panels, forms: [] };
}
Expand Down
3 changes: 2 additions & 1 deletion src/contentScript/devTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ReduceOptions,
} from "@/runtime/reducePipeline";
import { ApiVersion, BlockArgContext, IReader, RegistryId } from "@/core";
// eslint-disable-next-line import/no-restricted-paths -- Custom devTools mechanism to transfer data
import { selectedElement } from "@/devTools/getSelectedElement";
import { isNullOrBlank, resolveObj } from "@/utils";
import { BlockConfig } from "@/blocks/types";
Expand All @@ -36,7 +37,7 @@ import { SerializableResponse } from "@/messaging/protocol";
import apiVersionOptions from "@/runtime/apiVersionOptions";
import { BusinessError } from "@/errors";
import { $safeFind } from "@/helpers";
import { clearDynamicElements } from "@/nativeEditor/dynamic";
import { clearDynamicElements } from "@/contentScript/nativeEditor/dynamic";
import { reactivateTab } from "./lifecycle";
import selection from "@/utils/selectionController";

Expand Down
4 changes: 2 additions & 2 deletions src/contentScript/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { loadOptions } from "@/store/extensionsStorage";
import extensionPointRegistry from "@/extensionPoints/registry";
import { ResolvedExtension, IExtensionPoint, RegistryId, UUID } from "@/core";
import * as context from "@/contentScript/context";
import * as actionPanel from "@/actionPanel/native";
import * as actionPanel from "@/contentScript/actionPanel";
import { PromiseCancelled, sleep } from "@/utils";
import { NAVIGATION_RULES } from "@/contrib/navigationRules";
import { testMatchPatterns } from "@/blocks/available";
Expand All @@ -28,7 +28,7 @@ import browser from "webextension-polyfill";
import { groupBy } from "lodash";
import { resolveDefinitions } from "@/registry/internal";
import { traces } from "@/background/messenger/api";
import { isDeploymentActive } from "@/options/deploymentUtils";
import { isDeploymentActive } from "@/utils/deployment";
import { $safeFind } from "@/helpers";

let _scriptPromise: Promise<void> | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/contentScript/messenger/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const toggleActionPanel = getMethod("TOGGLE_ACTION_PANEL");
export const showActionPanel = getMethod("SHOW_ACTION_PANEL");
export const hideActionPanel = getMethod("HIDE_ACTION_PANEL");
export const removeActionPanel = getMethod("REMOVE_ACTION_PANEL");
export const getActionPanelStore = getMethod("GET_ACTION_PANEL_STORE");
export const insertPanel = getMethod("INSERT_PANEL");
export const insertButton = getMethod("INSERT_BUTTON");

Expand Down
18 changes: 13 additions & 5 deletions src/contentScript/messenger/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ import {
showActionPanel,
toggleActionPanel,
removeExtension as removeActionPanel,
} from "@/actionPanel/native";
import { insertPanel } from "@/nativeEditor/insertPanel";
import { insertButton } from "@/nativeEditor/insertButton";
getActionPanelStore,
} from "@/contentScript/actionPanel";
import { insertPanel } from "@/contentScript/nativeEditor/insertPanel";
import { insertButton } from "@/contentScript/nativeEditor/insertButton";
import {
clearDynamicElements,
disableOverlay,
enableOverlay,
runExtensionPointReader,
updateDynamicElement,
} from "@/nativeEditor/dynamic";
} from "@/contentScript/nativeEditor/dynamic";
import { getProcesses, initRobot } from "@/contentScript/uipath";
import { withDetectFrameworkVersions, withSearchWindow } from "@/common";
import {
Expand All @@ -58,7 +59,10 @@ import {
import { checkAvailable } from "@/blocks/available";
import { showNotification } from "@/contentScript/notify";
import { runBrick } from "@/contentScript/executor";
import { cancelSelect, selectElement } from "@/nativeEditor/selector";
import {
cancelSelect,
selectElement,
} from "@/contentScript/nativeEditor/selector";
import {
runEffectPipeline,
runMapArgs,
Expand All @@ -85,6 +89,8 @@ declare global {
SHOW_ACTION_PANEL: typeof showActionPanel;
HIDE_ACTION_PANEL: typeof hideActionPanel;
REMOVE_ACTION_PANEL: typeof removeActionPanel;
GET_ACTION_PANEL_STORE: typeof getActionPanelStore;

INSERT_PANEL: typeof insertPanel;
INSERT_BUTTON: typeof insertButton;

Expand Down Expand Up @@ -134,6 +140,8 @@ export default function registerMessenger(): void {
SHOW_ACTION_PANEL: showActionPanel,
HIDE_ACTION_PANEL: hideActionPanel,
REMOVE_ACTION_PANEL: removeActionPanel,
GET_ACTION_PANEL_STORE: getActionPanelStore,

INSERT_PANEL: insertPanel,
INSERT_BUTTON: insertButton,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/

import {
EmptyConfig,
IExtension,
IExtensionPoint,
IReader,
ReaderOutput,
Expand All @@ -26,12 +24,7 @@ import {
} from "@/core";
import { clearDynamic, runDynamic } from "@/contentScript/lifecycle";
import { fromJS as extensionPointFactory } from "@/extensionPoints/factory";
import Overlay from "@/nativeEditor/Overlay";
import {
ExtensionPointConfig,
ExtensionPointDefinition,
ExtensionPointType,
} from "@/extensionPoints/types";
import Overlay from "@/vendors/Overlay";
import { resolveDefinitions } from "@/registry/internal";
import { expectContext } from "@/utils/expectContext";
import { ContextMenuExtensionPoint } from "@/extensionPoints/contextMenu";
Expand All @@ -40,15 +33,7 @@ import { $safeFind } from "@/helpers";
import { TriggerDefinition } from "@/extensionPoints/triggerExtension";
import selection from "@/utils/selectionController";
import { ContextMenuReader } from "@/extensionPoints/contextMenuReader";

export interface DynamicDefinition<
TExtensionPoint extends ExtensionPointDefinition = ExtensionPointDefinition,
TExtension extends EmptyConfig = EmptyConfig
> {
type: ExtensionPointType;
extensionPoint: ExtensionPointConfig<TExtensionPoint>;
extension: IExtension<TExtension>;
}
import type { DynamicDefinition } from "@/contentScript/nativeEditor/types";

let _overlay: Overlay | null = null;
const _temporaryExtensions: Map<string, IExtensionPoint> = new Map();
Expand Down
Loading

0 comments on commit 49c3b06

Please sign in to comment.