refactor: replace unnecessary dynamic imports with static imports in CLI package #57
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
packages/cli/src/commands/init.tsandpackages/cli/src/commands/start.tsuseawait import()to load Node built-in modules and project-internal modules. These should be static top-level imports.Why
Dynamic import of Node built-ins (
node:child_process,node:util) and project modules (../workspace.js) has no benefit here — they're always available and don't need lazy loading. Static imports are clearer, enable better tree-shaking, and avoid unnecessary async overhead.Changes needed
packages/cli/src/commands/init.ts(4 places):await import("node:child_process")inrunCommand()→ top-levelimport { spawn, execFile } from "node:child_process"await import("node:util")indetectPackageManager()andtryRequireSqlite()→ top-levelimport { promisify } from "node:util"packages/cli/src/commands/start.ts(2 places):await import("node:child_process")→ top-level importawait import("../workspace.js")→ top-level importNOT to change
sense-runtime.ts/workflow-worker.ts— load user modules at runtime, must stay dynamicvi.mock(), standard vitest pattern