$ show microsoft/vscode-js-debug
This repository is the official JavaScript debugger for Visual Studio Code (js-debug). It implements a full Debug Adapter Protocol (DAP) server that communicates with JavaScript runtimes via the Chrome DevTools Protocol (CDP). The debugger supports Node.js, Chrome, Edge, WebView2, VS Code extension hosts, Blazor, and WebAssembly (with DWARF symbols). The architecture is modular, with a core adapter layer handling breakpoints, source maps, evaluation, and console output; target-specific launchers for Node and browser processes; a UI layer providing VS Code commands, configuration providers, and profiling tools; and extensive telemetry and diagnostics infrastructure. Key entry points include the VS Code extension activation (`src/extension.ts`) and a standalone DAP server (`src/debugServerMain.ts`). The codebase uses dependency injection (Inversify), custom event emitters, and source map management with caching and rename support. External dependencies include `ws` (WebSocket), `got` (HTTP), `acorn`/`astring` (JavaScript parsing/code generation), and `@jridgewell/trace-mapping` (source map resolution). While primarily an application, it includes a diagnostic tool webview and telemetry for operational analysis.
The LLM identified 7 files worth highlighting for reuse:
Provides a custom EventEmitter implementation with listener reference counting, one-shot listeners, and a ListenerMap for typed event sets. The pattern is clean, well-typed, and avoids common pitfalls of Node.js EventEmitter (e.g., untyped events, no easy way to track subscription count). It is used pervasively throughout the debugger and could be extracted as a standalone library for any TypeScript project needing typed event handling with lifecycle awareness.
Implements a Node.js transform stream that splits incoming data on a configurable delimiter (e.g., newlines). It correctly handles partial chunks at the boundaries and emits complete messages. This is a common pattern for parsing line-based or delimiter-separated protocols over streams, and the implementation is clean, testable, and reusable in any Node.js project that processes streaming data.
Contains a collection of well-crafted utility functions: memoize (with cache invalidation and custom key function), debounce (leading/trailing variants), trailingEdgeThrottle, and once. Each function is generic, properly typed with TypeScript generics, and handles edge cases (e.g., clearing timers, promise return values). These are not just wrappers but include non-trivial logic (e.g., debounce returns a promise that resolves after the delay). They could be used in any JavaScript/TypeScript project.
Provides an efficient, streaming glob file finder with an mtime-based cache. Instead of re-scanning the filesystem on every request, it caches the glob results and only invalidates entries when file modification times change. This is a performance-critical optimization for source map discovery in large projects. The implementation is self-contained (imports only common utilities) and demonstrates a sophisticated caching strategy applicable to any filesystem-intensive tool.
Handles parsing and validation of breakpoint conditional expressions (e.g., 'x > 5') using acorn. It transforms user-written expressions into evaluable code by injecting a return statement, handles syntax errors gracefully, and supports environment-specific variable injection. This is a non-trivial example of runtime code manipulation that is isolated from the rest of the debugger; the pattern of parsing, transforming, and error-handling expressions is reusable in any tool that needs to evaluate user-provided conditions.
Provides an abstracted CDP (Chrome DevTools Protocol) connection and session layer. It queues commands while disconnected, replays events to new listeners after reconnection, and supports prefix-based event filtering for efficient routing. The implementation handles asynchronous initialization, error recovery, and lifecycle management. This pattern is reusable for any bidirectional protocol client that needs reliable message ordering and connection resilience.
Converts simple glob patterns (like '**/node_modules/**') into JavaScript RegExp objects. It correctly handles **, *, ?, and character classes, and includes an escape mechanism for special regex characters. The implementation is concise, well-tested, and can be used independently in any project that needs glob pattern matching without pulling in a full glob library.