mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
- 修复所有 33 个原始 tsc 编译错误(ink JSX 声明、类型不匹配、null check 等) - 清理 176 处 `: any` 类型标注,全部替换为具体推断类型 - 修复清理过程中引入的 41 个回归错误 - 最终结果:0 tsc 错误,0 个非注释 any 标注 - Build 验证通过(25.75MB bundle) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
// highlight.js's type defs carry `/// <reference lib="dom" />`. SSETransport,
|
|
// mcp/client, ssh, dumpPrompts use DOM types (TextDecodeOptions, RequestInfo)
|
|
// that only typecheck because this file's `typeof import('highlight.js')` pulls
|
|
// lib.dom in. tsconfig has lib: ["ESNext"] only — fixing the actual DOM-type
|
|
// deps is a separate sweep; this ref preserves the status quo.
|
|
/// <reference lib="dom" />
|
|
|
|
import { extname } from 'path'
|
|
|
|
export type CliHighlight = {
|
|
highlight: typeof import('cli-highlight').highlight
|
|
supportsLanguage: typeof import('cli-highlight').supportsLanguage
|
|
}
|
|
|
|
// One promise shared by Fallback.tsx, markdown.ts, events.ts, getLanguageName.
|
|
// The highlight.js import piggybacks: cli-highlight has already pulled it into
|
|
// the module cache, so the second import() is a cache hit — no extra bytes
|
|
// faulted in.
|
|
let cliHighlightPromise: Promise<CliHighlight | null> | undefined
|
|
|
|
let loadedGetLanguage: ((name: string) => { name: string } | undefined) | undefined
|
|
|
|
async function loadCliHighlight(): Promise<CliHighlight | null> {
|
|
try {
|
|
const cliHighlight = await import('cli-highlight')
|
|
// cache hit — cli-highlight already loaded highlight.js
|
|
const highlightJs = await import('highlight.js')
|
|
loadedGetLanguage = (highlightJs as { getLanguage?: typeof loadedGetLanguage }).getLanguage
|
|
return {
|
|
highlight: cliHighlight.highlight,
|
|
supportsLanguage: cliHighlight.supportsLanguage,
|
|
}
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function getCliHighlightPromise(): Promise<CliHighlight | null> {
|
|
cliHighlightPromise ??= loadCliHighlight()
|
|
return cliHighlightPromise
|
|
}
|
|
|
|
/**
|
|
* eg. "foo/bar.ts" → "TypeScript". Awaits the shared cli-highlight load,
|
|
* then reads highlight.js's language registry. All callers are telemetry
|
|
* (OTel counter attributes, permission-dialog unary events) — none block
|
|
* on this, they fire-and-forget or the consumer already handles Promise<string>.
|
|
*/
|
|
export async function getLanguageName(file_path: string): Promise<string> {
|
|
await getCliHighlightPromise()
|
|
const ext = extname(file_path).slice(1)
|
|
if (!ext) return 'unknown'
|
|
return loadedGetLanguage?.(ext)?.name ?? 'unknown'
|
|
}
|