GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — claude-code-source-code/src/utils/cliHighlight.ts at main · fword/claude-code-source-code Expand file tree/ Copy pathcliHighlight.tsMore file actions 54 lines (47 loc) · 2.09 KB / Copy pathcliHighlight.tsFile metadata and controls54 lines (47 loc) · 2.09 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 // 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: typeof import('highlight.js').getLanguage | 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.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' } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |