From 3353b7154007addb33c87884eff4f6f3e5403891 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 11 Mar 2023 21:44:06 +0900 Subject: [PATCH 1/2] rename directories --- src/background/Application.ts | 4 ++-- src/background/controllers/CommandController.ts | 2 +- src/background/controllers/ConsoleController.ts | 2 +- src/background/controllers/FindController.ts | 2 +- src/background/controllers/KeyController.ts | 2 +- src/background/controllers/LinkController.ts | 2 +- src/background/controllers/OperationController.ts | 2 +- src/background/controllers/SettingsController.ts | 2 +- src/background/{infrastructures => db}/MemoryStorage.ts | 0 .../BackgroundMessageListener.ts | 0 .../{infrastructures => messaging}/FindPortListener.ts | 0 .../{infrastructures => messaging}/RequestContext.ts | 0 src/background/repositories/AddonEnabledRepository.ts | 2 +- src/background/repositories/FindRepository.ts | 2 +- src/background/repositories/FollowRepository.ts | 2 +- src/background/repositories/MarkModeRepository.ts | 2 +- src/background/repositories/MarkRepository.ts | 2 +- src/background/repositories/ReadyFrameRepository.ts | 2 +- src/background/repositories/RepeatRepository.ts | 2 +- src/background/settings/SettingsRepository.ts | 2 +- src/background/usecases/CommandUseCase.ts | 2 +- src/background/usecases/OperationUseCase.ts | 2 +- test/background/{infrastructures => db}/MemoryStorage.test.ts | 2 +- test/background/mock/MockConsoleClient.ts | 2 +- 24 files changed, 21 insertions(+), 21 deletions(-) rename src/background/{infrastructures => db}/MemoryStorage.ts (100%) rename src/background/{infrastructures => messaging}/BackgroundMessageListener.ts (100%) rename src/background/{infrastructures => messaging}/FindPortListener.ts (100%) rename src/background/{infrastructures => messaging}/RequestContext.ts (100%) rename test/background/{infrastructures => db}/MemoryStorage.test.ts (96%) diff --git a/src/background/Application.ts b/src/background/Application.ts index ce63cd09..70f10237 100644 --- a/src/background/Application.ts +++ b/src/background/Application.ts @@ -1,6 +1,6 @@ import { injectable, inject } from "inversify"; -import BackgroundMessageListener from "./infrastructures/BackgroundMessageListener"; -import FindPortListener from "./infrastructures/FindPortListener"; +import BackgroundMessageListener from "./messaging/BackgroundMessageListener"; +import FindPortListener from "./messaging/FindPortListener"; import VersionUseCase from "./usecases/VersionUseCase"; import FindRepositoryImpl from "./repositories/FindRepository"; import ReadyFrameRepository from "./repositories/ReadyFrameRepository"; diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts index b550cf15..2248f01a 100644 --- a/src/background/controllers/CommandController.ts +++ b/src/background/controllers/CommandController.ts @@ -1,7 +1,7 @@ import { injectable, inject } from "inversify"; import { Completions } from "../../shared/Completions"; import CommandUseCase from "../usecases/CommandUseCase"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class CommandController { diff --git a/src/background/controllers/ConsoleController.ts b/src/background/controllers/ConsoleController.ts index 7f3c75df..ffaf4ef8 100644 --- a/src/background/controllers/ConsoleController.ts +++ b/src/background/controllers/ConsoleController.ts @@ -1,6 +1,6 @@ import { injectable, inject } from "inversify"; import ConsoleUseCase from "../usecases/ConsoleUseCase"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class ConsoleController { diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts index 69326342..528b6023 100644 --- a/src/background/controllers/FindController.ts +++ b/src/background/controllers/FindController.ts @@ -1,6 +1,6 @@ import { injectable, inject } from "inversify"; import StartFindUseCase from "../usecases/StartFindUseCase"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class FindController { diff --git a/src/background/controllers/KeyController.ts b/src/background/controllers/KeyController.ts index 0095af57..c9c904e1 100644 --- a/src/background/controllers/KeyController.ts +++ b/src/background/controllers/KeyController.ts @@ -1,5 +1,5 @@ import { injectable, inject } from "inversify"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; import MarkJumpUseCase from "../usecases/MarkJumpUseCase"; import MarkSetUseCase from "../usecases/MarkSetUseCase"; import MarkModeUseCase from "../usecases/MarkModeUseCase"; diff --git a/src/background/controllers/LinkController.ts b/src/background/controllers/LinkController.ts index 9bf09c1c..02e7cf7d 100644 --- a/src/background/controllers/LinkController.ts +++ b/src/background/controllers/LinkController.ts @@ -1,6 +1,6 @@ import { injectable, inject } from "inversify"; import LinkUseCase from "../usecases/LinkUseCase"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class LinkController { diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index 657cc9ba..8a284558 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -1,6 +1,6 @@ import { inject, injectable } from "inversify"; import OperationUseCase from "../usecases/OperationUseCase"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class OperationController { diff --git a/src/background/controllers/SettingsController.ts b/src/background/controllers/SettingsController.ts index 0f482997..570e3d8e 100644 --- a/src/background/controllers/SettingsController.ts +++ b/src/background/controllers/SettingsController.ts @@ -1,6 +1,6 @@ import { injectable, inject } from "inversify"; import SettingsUseCase from "../usecases/SettingsUseCase"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class SettingsController { diff --git a/src/background/infrastructures/MemoryStorage.ts b/src/background/db/MemoryStorage.ts similarity index 100% rename from src/background/infrastructures/MemoryStorage.ts rename to src/background/db/MemoryStorage.ts diff --git a/src/background/infrastructures/BackgroundMessageListener.ts b/src/background/messaging/BackgroundMessageListener.ts similarity index 100% rename from src/background/infrastructures/BackgroundMessageListener.ts rename to src/background/messaging/BackgroundMessageListener.ts diff --git a/src/background/infrastructures/FindPortListener.ts b/src/background/messaging/FindPortListener.ts similarity index 100% rename from src/background/infrastructures/FindPortListener.ts rename to src/background/messaging/FindPortListener.ts diff --git a/src/background/infrastructures/RequestContext.ts b/src/background/messaging/RequestContext.ts similarity index 100% rename from src/background/infrastructures/RequestContext.ts rename to src/background/messaging/RequestContext.ts diff --git a/src/background/repositories/AddonEnabledRepository.ts b/src/background/repositories/AddonEnabledRepository.ts index 73c01d22..36f64bdc 100644 --- a/src/background/repositories/AddonEnabledRepository.ts +++ b/src/background/repositories/AddonEnabledRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; export default interface AddonEnabledRepository { enable(): void; diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts index 6074ba06..7505a297 100644 --- a/src/background/repositories/FindRepository.ts +++ b/src/background/repositories/FindRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; export type FindState = { keyword: string; diff --git a/src/background/repositories/FollowRepository.ts b/src/background/repositories/FollowRepository.ts index a5efac81..9f06b6a6 100644 --- a/src/background/repositories/FollowRepository.ts +++ b/src/background/repositories/FollowRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; export default interface FollowRepository { startFollowMode( diff --git a/src/background/repositories/MarkModeRepository.ts b/src/background/repositories/MarkModeRepository.ts index ac43e8d0..a75dda46 100644 --- a/src/background/repositories/MarkModeRepository.ts +++ b/src/background/repositories/MarkModeRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; export default interface MarkModeRepository { enableSetMode(): void; diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts index ec62ac8b..0eb4c9fe 100644 --- a/src/background/repositories/MarkRepository.ts +++ b/src/background/repositories/MarkRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; import GlobalMark from "../domains/GlobalMark"; import LocalMark from "../domains/LocalMark"; diff --git a/src/background/repositories/ReadyFrameRepository.ts b/src/background/repositories/ReadyFrameRepository.ts index 76bb24f7..94d6eae6 100644 --- a/src/background/repositories/ReadyFrameRepository.ts +++ b/src/background/repositories/ReadyFrameRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; type State = { [tabId: number]: { [frameId: number]: number } }; diff --git a/src/background/repositories/RepeatRepository.ts b/src/background/repositories/RepeatRepository.ts index 64b5428f..b61ea21e 100644 --- a/src/background/repositories/RepeatRepository.ts +++ b/src/background/repositories/RepeatRepository.ts @@ -1,5 +1,5 @@ import { injectable } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; import { Operation } from "../../shared/operations2"; export default interface RepeatRepository { diff --git a/src/background/settings/SettingsRepository.ts b/src/background/settings/SettingsRepository.ts index 649cfd2a..add1b3d3 100644 --- a/src/background/settings/SettingsRepository.ts +++ b/src/background/settings/SettingsRepository.ts @@ -1,5 +1,5 @@ import { injectable, inject } from "inversify"; -import MemoryStorage from "../infrastructures/MemoryStorage"; +import MemoryStorage from "../db/MemoryStorage"; import { defaultSettings, serialize, deserialize } from "../../settings"; import Settings from "../../shared/Settings"; import { SerializedSettings } from "../../settings/schema"; diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index 078247d0..e5cc128d 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -2,7 +2,7 @@ import { Completions } from "../../shared/Completions"; import { injectable, inject } from "inversify"; import CommandRegistry from "../command/CommandRegistry"; import { parseCommand, onCommandInputting } from "./parser"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; import { CommandContext } from "../command/Command"; @injectable() diff --git a/src/background/usecases/OperationUseCase.ts b/src/background/usecases/OperationUseCase.ts index 7ef4ed99..ba5c46fe 100644 --- a/src/background/usecases/OperationUseCase.ts +++ b/src/background/usecases/OperationUseCase.ts @@ -2,7 +2,7 @@ import { inject, injectable } from "inversify"; import type { Props, OperatorContext } from "../operators/Operator"; import OperatorRegistory from "../operators/OperatorRegistory"; import RepeatRepository from "../repositories/RepeatRepository"; -import RequestContext from "../infrastructures/RequestContext"; +import RequestContext from "../messaging/RequestContext"; @injectable() export default class OperationUseCase { diff --git a/test/background/infrastructures/MemoryStorage.test.ts b/test/background/db/MemoryStorage.test.ts similarity index 96% rename from test/background/infrastructures/MemoryStorage.test.ts rename to test/background/db/MemoryStorage.test.ts index f0d33563..9e9aa5b4 100644 --- a/test/background/infrastructures/MemoryStorage.test.ts +++ b/test/background/db/MemoryStorage.test.ts @@ -1,4 +1,4 @@ -import MemoryStorage from "../../../src/background/infrastructures/MemoryStorage"; +import MemoryStorage from "../../../src/background/db/MemoryStorage"; describe("MemoryStorage", () => { it("stores string value", () => { diff --git a/test/background/mock/MockConsoleClient.ts b/test/background/mock/MockConsoleClient.ts index d1f8fc32..bd9161fc 100644 --- a/test/background/mock/MockConsoleClient.ts +++ b/test/background/mock/MockConsoleClient.ts @@ -1,4 +1,4 @@ -import ConsoleClient from "../../../src/background/infrastructures/ConsoleClient"; +import ConsoleClient from "../../../src/background/clients/ConsoleClient"; export default class MockConsoleClient implements ConsoleClient { hide(_tabId: number): Promise { From 4bc42d7edd9623e1508cdd9c012cea670ca78e5e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 11 Mar 2023 22:51:56 +0900 Subject: [PATCH 2/2] print debug logs --- package.json | 5 ++++- script/build | 3 +++ src/background/clients/ConsoleMessageSender.ts | 5 +++++ src/background/clients/ContentMessageSender.ts | 6 ++++++ src/background/messaging/BackgroundMessageListener.ts | 4 ++++ src/content/client/BackgroundMessageSender.ts | 5 +++++ src/content/messaging/ContentMessageListener.ts | 5 +++++ 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a7212033..a201b1da 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,11 @@ "description": "vimmatic", "version": "0.0.1", "scripts": { - "start": "nodemon --watch ./src --ext js,jsx,ts,tsx,css,html,json script/build", + "start": "NODE_ENV=development nodemon --watch ./src --ext js,jsx,ts,tsx,css,html,json script/build", + "clean": "rm -rf ./dist", + "prebuild": "yarn clean", "build": "script/build", + "prepackage": "yarn build", "package": "yarn build && script/package", "lint": "eslint --ext .ts,.tsx .", "lint:fix": "eslint --ext .ts,.tsx . --fix", diff --git a/script/build b/script/build index 24272dbf..a059370e 100755 --- a/script/build +++ b/script/build @@ -10,6 +10,9 @@ const targets = { const buildScripts = async (browser) => { await build({ + define: { + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), + }, entryPoints: { console: "src/console/index.tsx", content: "src/content/index.ts", diff --git a/src/background/clients/ConsoleMessageSender.ts b/src/background/clients/ConsoleMessageSender.ts index 7ed9ac37..0712271f 100644 --- a/src/background/clients/ConsoleMessageSender.ts +++ b/src/background/clients/ConsoleMessageSender.ts @@ -5,6 +5,11 @@ type ConsoleMessageSender = Sender; export const newSender = (tabId: number, frameId?: number) => { const sender = new Sender((type: Key, args: Request) => { + if (process.env.NODE_ENV === "development") { + const style = "background-color: green; color: white; padding: 4px;"; + console.debug("%cSEND%c %s %o", style, "", type, args); + } + const msg = { type, args: args ?? {} }; return chrome.tabs.sendMessage(tabId, msg, { frameId }); }); diff --git a/src/background/clients/ContentMessageSender.ts b/src/background/clients/ContentMessageSender.ts index 6d1622e7..3d47cc42 100644 --- a/src/background/clients/ContentMessageSender.ts +++ b/src/background/clients/ContentMessageSender.ts @@ -5,6 +5,12 @@ type ContentMessageSender = Sender; export const newSender = (tabId: number, frameId?: number) => { const sender = new Sender((type: Key, args: Request) => { + if (process.env.NODE_ENV === "development") { + const style = "background-color: green; color: white; padding: 4px;"; + const reset = "background-color: unset; color: unset; padding: unset;"; + console.debug("%cSEND%c %s %o", style, reset, type, args); + } + const msg = { type, args: args ?? {} }; return chrome.tabs.sendMessage(tabId, msg, { frameId }); }); diff --git a/src/background/messaging/BackgroundMessageListener.ts b/src/background/messaging/BackgroundMessageListener.ts index d0d4dd65..9d0ca3e4 100644 --- a/src/background/messaging/BackgroundMessageListener.ts +++ b/src/background/messaging/BackgroundMessageListener.ts @@ -89,6 +89,10 @@ export default class BackgroundMessageListener { return; } + if (process.env.NODE_ENV === "development") { + const style = "background-color: purple; color: white; padding: 4px;"; + console.debug("%cRECEIVE%c %s %o", style, "", type, args); + } const ret = this.receiver.receive(ctx, type, args); Promise.resolve(ret) .then(sendResponse) diff --git a/src/content/client/BackgroundMessageSender.ts b/src/content/client/BackgroundMessageSender.ts index d7c17e5e..27c1945d 100644 --- a/src/content/client/BackgroundMessageSender.ts +++ b/src/content/client/BackgroundMessageSender.ts @@ -5,6 +5,11 @@ type BackgroundMessageSender = Sender; export const newSender = () => { const sender = new Sender((type: Key, args: Request) => { + if (process.env.NODE_ENV === "development") { + const style = "background-color: green; color: white; padding: 4px;"; + console.debug("%cSEND%c %s %o", style, "", type, args); + } + return chrome.runtime.sendMessage({ type, args: args ?? {}, diff --git a/src/content/messaging/ContentMessageListener.ts b/src/content/messaging/ContentMessageListener.ts index b545d83b..cea3bcc0 100644 --- a/src/content/messaging/ContentMessageListener.ts +++ b/src/content/messaging/ContentMessageListener.ts @@ -155,6 +155,11 @@ export default class ContentMessageListener { return; } + if (process.env.NODE_ENV === "development") { + const style = "background-color: purple; color: white; padding: 4px;"; + console.debug("%cRECEIVE%c %s %o", style, "", type, args); + } + const ret = this.receiver.receive(type, args); Promise.resolve(ret) .then(sendResponse)