From c1bb4670136f4ed3c15593c635d826438e158ccb Mon Sep 17 00:00:00 2001 From: Joooye_34 Date: Sat, 9 Dec 2023 07:42:04 +0000 Subject: [PATCH] refactor(core): use debug log replace console when command registry (#5237) --- packages/common/infra/package.json | 1 + packages/common/infra/src/command/registry.ts | 11 +++++++---- packages/common/infra/tsconfig.json | 3 +++ yarn.lock | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/common/infra/package.json b/packages/common/infra/package.json index 5852cffc6e..f3696205f0 100644 --- a/packages/common/infra/package.json +++ b/packages/common/infra/package.json @@ -54,6 +54,7 @@ "dev": "vite build --watch" }, "dependencies": { + "@affine/debug": "workspace:*", "@affine/env": "workspace:*", "@affine/sdk": "workspace:*", "@blocksuite/blocks": "0.11.0-nightly-202312070955-2b5bb47", diff --git a/packages/common/infra/src/command/registry.ts b/packages/common/infra/src/command/registry.ts index 11443a93e1..c77292d4c3 100644 --- a/packages/common/infra/src/command/registry.ts +++ b/packages/common/infra/src/command/registry.ts @@ -1,3 +1,4 @@ +import { DebugLogger } from '@affine/debug'; // @ts-expect-error upstream type is wrong import { tinykeys } from 'tinykeys'; @@ -7,12 +8,14 @@ import { createAffineCommand, } from './command'; +const commandLogger = new DebugLogger('command:registry'); + export const AffineCommandRegistry = new (class { readonly commands: Map = new Map(); register(options: AffineCommandOptions) { if (this.commands.has(options.id)) { - console.warn(`Command ${options.id} already registered.`); + commandLogger.warn(`Command ${options.id} already registered.`); return () => {}; } const command = createAffineCommand(options); @@ -38,17 +41,17 @@ export const AffineCommandRegistry = new (class { }); } - console.debug(`Registered command ${command.id}`); + commandLogger.debug(`Registered command ${command.id}`); return () => { unsubKb?.(); this.commands.delete(command.id); - console.debug(`Unregistered command ${command.id}`); + commandLogger.debug(`Unregistered command ${command.id}`); }; } get(id: string): AffineCommand | undefined { if (!this.commands.has(id)) { - console.warn(`Command ${id} not registered.`); + commandLogger.warn(`Command ${id} not registered.`); return undefined; } return this.commands.get(id); diff --git a/packages/common/infra/tsconfig.json b/packages/common/infra/tsconfig.json index 0941f63e4d..1e81c00cd2 100644 --- a/packages/common/infra/tsconfig.json +++ b/packages/common/infra/tsconfig.json @@ -14,6 +14,9 @@ { "path": "../env" }, + { + "path": "../debug" + }, { "path": "./tsconfig.node.json" } diff --git a/yarn.lock b/yarn.lock index 2bdcf4d680..d6958401ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13795,6 +13795,7 @@ __metadata: resolution: "@toeverything/infra@workspace:packages/common/infra" dependencies: "@affine-test/fixtures": "workspace:*" + "@affine/debug": "workspace:*" "@affine/env": "workspace:*" "@affine/sdk": "workspace:*" "@affine/templates": "workspace:*"