Skip to content

Commit 7c4cdd1

Browse files
committed
refactor(cli-v2): improve dependency injection initialization in command handling
Updated the command registration process to initialize dependency injection only once, triggered by a preAction hook. This change enhances performance and ensures that the DI setup is not repeated unnecessarily for each command execution.
1 parent 5a60213 commit 7c4cdd1

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/commands/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,24 @@ import { addDbCommands } from "../cli/groups/db";
1818
import { addInitCommand } from "../cli/groups/init";
1919

2020
export const AddCommands = (program: Command): void => {
21-
EnvToDI();
22-
DefaultDI();
21+
let diInitialized = false;
2322

24-
getTaskQueueRegistry().registerQueue({
25-
server: SecJobQueueServer,
26-
client: SecJobQueueClient,
27-
storage: SecJobQueueStorage,
23+
program.hook("preAction", (_thisCommand, actionCommand) => {
24+
const commandName = actionCommand.name();
25+
if (commandName === "init") return;
26+
if (diInitialized) return;
27+
diInitialized = true;
28+
29+
EnvToDI();
30+
DefaultDI();
31+
32+
getTaskQueueRegistry().registerQueue({
33+
server: SecJobQueueServer,
34+
client: SecJobQueueClient,
35+
storage: SecJobQueueStorage,
36+
});
37+
SecJobQueueServer.start();
2838
});
29-
SecJobQueueServer.start();
3039

3140
addBootstrapCommands(program);
3241
addSyncCommand(program);

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"declarationMap": true,
1919
"types": ["@types/bun"],
2020
"outDir": "dist",
21-
"baseUrl": "./src",
2221
"rootDir": "./src",
2322
"jsx": "react-jsx",
2423
"module": "preserve",

0 commit comments

Comments
 (0)