6cc8833b2a
- Add .cursor/rules/no-dynamic-import.mdc: ban dynamic import() in production code with documented exceptions - Add .cursor/rules/gitea-access.mdc: tea CLI usage guide - Add explanatory comments on the 2 legitimate dynamic imports in sense-runtime.ts and workflow-worker.ts
35 lines
1.1 KiB
Plaintext
35 lines
1.1 KiB
Plaintext
---
|
|
description: Ban dynamic import() in production code — use static imports instead
|
|
globs: packages/*/src/**/*.ts
|
|
alwaysApply: true
|
|
---
|
|
|
|
# No Dynamic Import in Production Code
|
|
|
|
## Rule
|
|
|
|
Do NOT use `await import()` or dynamic `import()` expressions in production source code.
|
|
Always use static top-level `import` statements.
|
|
|
|
## Why
|
|
|
|
- Static imports enable tree-shaking and bundler optimizations
|
|
- They make dependencies explicit and discoverable at a glance
|
|
- Dynamic imports of Node built-ins or project modules add unnecessary async overhead
|
|
|
|
## Exceptions (must include a comment explaining why)
|
|
|
|
1. **`sense-runtime.ts`** — loads user-authored sense modules whose paths are only known at runtime
|
|
2. **`workflow-worker.ts`** — loads user-authored workflow modules whose paths are only known at runtime
|
|
|
|
When suppressing, add a comment directly above:
|
|
|
|
```ts
|
|
// Dynamic import required: user module path resolved at runtime
|
|
const mod = await import(senseIndexPath);
|
|
```
|
|
|
|
## Test Files
|
|
|
|
Test files (`__tests__/**`) are exempt — dynamic import after `vi.mock()` is standard vitest practice.
|