refactor: replace unnecessary dynamic imports with static imports in CLI package #57

Closed
opened 2026-04-23 06:43:29 +00:00 by xingyue · 0 comments
Owner

What

packages/cli/src/commands/init.ts and packages/cli/src/commands/start.ts use await 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") in runCommand() → top-level import { spawn, execFile } from "node:child_process"
  • await import("node:util") in detectPackageManager() and tryRequireSqlite() → top-level import { promisify } from "node:util"

packages/cli/src/commands/start.ts (2 places):

  • await import("node:child_process") → top-level import
  • await import("../workspace.js") → top-level import

NOT to change

  • sense-runtime.ts / workflow-worker.ts — load user modules at runtime, must stay dynamic
  • Test files — need dynamic import after vi.mock(), standard vitest pattern
## What `packages/cli/src/commands/init.ts` and `packages/cli/src/commands/start.ts` use `await 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")` in `runCommand()` → top-level `import { spawn, execFile } from "node:child_process"` - `await import("node:util")` in `detectPackageManager()` and `tryRequireSqlite()` → top-level `import { promisify } from "node:util"` **`packages/cli/src/commands/start.ts`** (2 places): - `await import("node:child_process")` → top-level import - `await import("../workspace.js")` → top-level import ## NOT to change - `sense-runtime.ts` / `workflow-worker.ts` — load user modules at runtime, must stay dynamic - Test files — need dynamic import after `vi.mock()`, standard vitest pattern
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#57