fix: make dev-build sourcemaps debuggable (closes #304) - #415
Merged
Conversation
Contributors attaching a debugger to tsserver could only bind breakpoints in dist/graphqlsp.js, never in packages/graphqlsp/src, because: 1. The emitted sourcemaps use relative sources (e.g. ../src/index.ts), which resolve against wherever pnpm materialized the built package (a symlink target or a hard-linked copy under node_modules/.pnpm), never matching the real files under packages/graphqlsp/src that breakpoints are set in. 2. The attach configuration in .vscode/launch.json relied on js-debug's default resolveSourceMapLocations, which excludes **/node_modules/** — exactly where tsserver loads the plugin from — so the sourcemaps were ignored outright. Development builds (NODE_ENV=development, i.e. `pnpm dev`) now rewrite sourcemap sources to absolute paths via sourcemapPathTransform and skip terser so mappings stay pristine. Production output is unchanged (verified byte-identical). The launch config now enables sourceMaps, widens resolveSourceMapLocations, and points outFiles at the plugin's dist output; README documents the debugging flow. Refs #304 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
Two independent problems prevented breakpoints in
packages/graphqlsp/src/*.tsfrom binding when attaching to tsserver (TSS_DEBUG_BRK=9559):sourcesare relative and resolve to the wrong place. The build emitssourceslike../src/index.ts, relative todist/. But tsserver loads the plugin from the example project'snode_modules, where pnpm has either symlinked or hard-link-copied the package (e.g.node_modules/.pnpm/file+packages+graphqlsp.../node_modules/@0no-co/graphqlsp/dist/graphqlsp.js, as in the issue). Resolved from there,../src/index.tspoints at a nonexistent path or at the pnpm copy of the sources — never at the realpackages/graphqlsp/src/index.tsthe contributor set breakpoints in. Breakpoint binding is by path, so they stay unbound. (sourcesContentwas already complete — that was not the problem.)node_modules. The repo's.vscode/launch.jsonattach configuration only setport: 9559, so vscode-js-debug's defaultresolveSourceMapLocations(["${workspaceFolder}/**", "!**/node_modules/**"]) applied — which excludes exactly the location the plugin is loaded from. This is the "sourcemaps are ignored" part of the issue and it's a js-debug default, not something the build can fix; it has to be configured away inlaunch.json.Fix
scripts/rollup.config.mjs: whenNODE_ENV=development(i.e.pnpm --filter @0no-co/graphqlsp dev):sourcemapPathTransformrewrites every sourcemap source to an absolute path, so maps resolve to the real files inpackages/graphqlsp/srcno matter where pnpm materializes the built package;.vscode/launch.json: the attach config now setssourceMaps: true,resolveSourceMapLocations: ["${workspaceFolder}/**"](nonode_modulesexclusion), andoutFilescoveringpackages/graphqlsp/distand the plugin's dist inside anynode_modules.Production/publish output is unchanged — verified byte-identical (see below). No new
.mapfiles are shipped:dist/*.mapwas already published before this change, with identical content. Hence no changeset: published artifacts are unaffected; only dev-build behavior and docs changed. Absolute (machine-specific) source paths only ever appear in local dev builds.What was verified
NODE_ENV=development pnpm --filter @0no-co/graphqlsp build, then a Node script overdist/graphqlsp.js.mapanddist/chunks/api-chunk.js.map:sources(14 + 20) are absolute paths to existing files;sourcesContentpresent for every source;source-mappackage (originalPositionFor):create(info)indist/graphqlsp.js4135:9 →packages/graphqlsp/src/index.ts42:9 (function create(info: ts.server.PluginCreateInfo) {)getGraphQLDiagnosticsdecl indist/chunks/api-chunk.js4569:9 →packages/graphqlsp/src/diagnostics.ts215:16findAllCallExpressionsdecl →packages/graphqlsp/src/ast/index.ts137:16dist/from a pre-changepnpm --filter @0no-co/graphqlsp run build, rebuilt after the change,diff -rreports byte-identical output (including.mapfiles).pnpm run test:e2e: 11 files, 52/52 tests passed.What was not verified: the interactive VS Code attach flow itself (two editor windows +
TSS_DEBUG_BRK) — that can't be reproduced headlessly here. The verification above proves the two identified root causes are gone (maps resolve to real, existingsrcfiles from the loaded location; the launch config no longer excludes them), which is precisely what js-debug needs to bind the breakpoints from the issue.Docs changes
README "Local development" gains a "Debugging with breakpoints" walkthrough: run the dev build (
pnpm --filter @0no-co/graphqlsp dev), open the example withTSS_DEBUG_BRK=9559, attach via the provided launch configuration from the root window, plus a note that production builds' relative-path sourcemaps won't bind breakpoints.Closes #304
🤖 Generated with Claude Code