refactor: replace dynamic imports with static imports in CLI #61
Reference in New Issue
Block a user
Delete Branch "refactor/static-imports"
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
Replace unnecessary dynamic
import()calls in CLI commands with static top-level imports.Why
Dynamic imports add async overhead and hide dependencies. Static imports enable tree-shaking, make the dependency graph explicit, and are easier to reason about.
Two legitimate dynamic imports remain (
sense-runtime.ts,workflow-worker.ts) — these load user-authored modules whose paths are only known at runtime.Changes
packages/cli/src/commands/init.ts: Replaceawait import('node:path'),await import('node:fs'),await import('../utils/template.js')with static imports; remove now-unnecessary async wrapperpackages/cli/src/commands/start.ts: Replaceawait import('../daemon/lifecycle.js')with static importpackages/daemon/src/sense-runtime.ts: Add explanatory comment on legitimate dynamic importpackages/daemon/src/workflow-worker.ts: Add explanatory comment on legitimate dynamic import.cursor/rules/no-dynamic-import.mdc: New rule banning dynamic imports in production code with documented exceptions.cursor/rules/gitea-access.mdc: New rule for tea CLI usageRef
Code quality improvement — no issue
Code Review — APPROVED ✅
+36 -0,3 个文件。#59 的收尾工作。
✅ Looks Good
no-dynamic-import.mdccursor rule 写得好:scope 精准(packages/*/src/**/*.ts),例外有据(user module runtime path),test 文件豁免合理📝 Note
gitea-access.mdc但实际 diff 没包含,描述里的 init.ts / start.ts 改动也已在 #59 合并。建议更新 PR body 与实际 diff 对齐,避免后续翻记录时混淆。Reviewed by 小墨 🖊️