fix: stop shipping declaration source maps that reference unshipped src/#2495
Draft
claude[bot] wants to merge 1 commit into
Draft
fix: stop shipping declaration source maps that reference unshipped src/#2495claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
The published packages include only dist/, but the tsc-emitted .d.mts.map/.d.cts.map files referenced ../src (and the private core-internal workspace package's src/) with no embedded sourcesContent, so declaration-map-aware tooling (e.g. TypeScript's go-to-source-definition) could never resolve them on a consumer's machine, and the maps leaked internal workspace paths. tsc has no inlineSources equivalent for declaration maps (microsoft/TypeScript#38966), so stop emitting them instead: - set dts.sourcemap: false in every published package's tsdown.config.ts, which disables declarationMap in the dts pass and drops the .d.*ts.map assets from the bundle - add a shared inputOptions hook (common/tsdown/) that strips the dangling '//# sourceMappingURL=' comment rolldown still appends to the declaration chunks; registered via inputOptions because tsdown does not forward user plugins to the CJS dts pass Runtime JS source maps (.mjs.map/.cjs.map), which do embed sourcesContent, are unchanged. Fixes #2233 Fixes #2491 Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016gag9FFr6udcsF8qvMvMV8
🦋 Changeset detectedLatest commit: 75313b5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Requested by Felix Weinberger · Slack thread
Before / After
Before: every published v2 package (verified on
@modelcontextprotocol/{core,client,server}@2.0.0-beta.4) shipsdist/**/*.d.mts.map/*.d.cts.mapdeclaration maps whosesourcespoint at../src/*.ts— and, for the packages that bundle it, at../../core-internal/src/*.ts, aprivate: trueworkspace package that is never published. Since the tarballs contain onlydist/("files": ["dist"]) and the maps carry no usablesourcesContent, none of those references can resolve on a consumer's machine: declaration-map-aware tooling (e.g. TypeScript's "Go to Source Definition") loads the map and lands nowhere, ~0.9 MB of dead-weight maps ship per install, and the maps leak internal monorepo paths.After: the packages ship no declaration maps and the
.d.mts/.d.ctsfiles carry no//# sourceMappingURL=reference — editors fall back to the normal.d.tsnavigation instead of chasing a map that cannot resolve. The runtime JS source maps (.mjs.map/.cjs.map), which do embedsourcesContentand resolve fine, are unchanged.Verified by
pnpm pack-ing all nine published packages (core,client,server,server-legacy,codemod,express,fastify,hono,node): 0.d.*ts.mapfiles in any tarball, 0 declaration files referencing a map, and everysourcesentry of every remaining shipped.maphas embeddedsourcesContent(no../srcorcore-internalreferences left).How
packages/{core,client,server,server-legacy,codemod}/tsdown.config.ts,packages/middleware/{express,fastify,hono,node}/tsdown.config.ts: setdts.sourcemap: false, which turns offdeclarationMapfor the dts pass and drops the.d.*ts.mapassets from the bundle.common/tsdown/stripDtsSourceMappingUrl.mjs(+.d.mtsfor typecheck): a sharedinputOptionshook that strips the trailing//# sourceMappingURL=comment rolldown still appends to the (now map-less) declaration chunks. It is wired throughinputOptionsrather thanpluginsbecause tsdown does not forward user plugins to the extra CJS dts pass that emits the.d.ctsfiles. Plain.mjsso tsdown's native config loader can import it on every supported Node version (Node 20 cannot natively import.ts)..changeset/no-dangling-declaration-maps.md: patch bump for all nine published packages.Rejected alternatives: embedding sources is not possible — tsc has no
inlineSourcesequivalent for declaration maps (microsoft/TypeScript#38966), which is exactly why the JS maps are fine on main while the declaration maps dangle. Shippingsrc/would fix each package's own../srcreferences but not the../../core-internal/srcones (private, unpublished, and bundled), would grow every tarball, and would still expose internal layout. Dropping the maps is the only option that leaves nothing unresolvable.For the record: the
.js.mapside of #2233 as originally reported against v1.x does not affectmain— the tsdown/rolldown build already embedssourcesContentinto the runtime JS maps. The declaration maps were the remaining unresolvable piece onmain, as flagged in the #2233 thread and reported in detail in #2491 (this implements its option 2).Verification run:
pnpm -r build,pnpm typecheck:all,node scripts/smoke-dist-types.mjs(clean withskipLibCheck: false), tests for all nine affected packages, and lint/prettier — all passing.Fixes #2233
Fixes #2491
🤖 Generated with Claude Code
https://claude.ai/code/session_016gag9FFr6udcsF8qvMvMV8
Generated by Claude Code