Skip to content

Commit 65c8b72

Browse files
committed
refactor(cli): convert dynamic import to static import in osc-subprocess
Moves the await import() call to a static import at the top of the file and documents import guidelines in cli/knowledge.md. - Replace dynamic import with static import for terminal-color-detection - Add Import Guidelines section to cli/knowledge.md - Document exceptions for WASM, client-side libs, and test utilities
1 parent e8349c8 commit 65c8b72

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

cli/knowledge.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# CLI Package Knowledge
22

3+
## Import Guidelines
4+
5+
**Never use dynamic `await import()` calls.** Always use static imports at the top of the file.
6+
7+
```typescript
8+
// ❌ WRONG: Dynamic import
9+
const { someFunction } = await import('./some-module')
10+
11+
// ✅ CORRECT: Static import at top of file
12+
import { someFunction } from './some-module'
13+
```
14+
15+
Dynamic imports make code harder to analyze, break tree-shaking, and can hide circular dependency issues. If you need conditional loading, reconsider the architecture instead.
16+
17+
**Exceptions** (where dynamic imports are acceptable):
18+
- **WASM modules**: Heavy WASM binaries that need lazy loading (e.g., QuickJS)
19+
- **Client-side only libraries in Next.js**: Libraries like Stripe that must only load in the browser
20+
- **Test utilities**: Mock module helpers that intentionally use dynamic imports
21+
322
## Test Naming Conventions
423

524
**IMPORTANT**: Follow these naming patterns for automatic dependency detection:

cli/src/init/osc-subprocess.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
detectTerminalTheme,
3+
terminalSupportsOSC,
4+
} from '../utils/terminal-color-detection'
5+
16
const OSC_DEBUG_ENABLED = process.env.CODEBUFF_OSC_DEBUG === '1'
27

38
function logOscDebug(message: string, data?: Record<string, unknown>) {
@@ -15,11 +20,6 @@ export async function runOscDetectionSubprocess(): Promise<void> {
1520
}
1621
logOscDebug('Starting OSC detection flag run')
1722

18-
// Avoid importing logger or other modules that produce output
19-
const { detectTerminalTheme, terminalSupportsOSC } = await import(
20-
'../utils/terminal-color-detection'
21-
)
22-
2323
const oscSupported = terminalSupportsOSC()
2424
logOscDebug('terminalSupportsOSC result', { oscSupported })
2525

0 commit comments

Comments
 (0)