Skip to content

fix: stop shipping declaration source maps that reference unshipped src/#2495

Draft
claude[bot] wants to merge 1 commit into
mainfrom
claude/fix-2233-declaration-maps
Draft

fix: stop shipping declaration source maps that reference unshipped src/#2495
claude[bot] wants to merge 1 commit into
mainfrom
claude/fix-2233-declaration-maps

Conversation

@claude

@claude claude Bot commented Jul 14, 2026

Copy link
Copy Markdown

Requested by Felix Weinberger · Slack thread

Before / After

Before: every published v2 package (verified on @modelcontextprotocol/{core,client,server}@2.0.0-beta.4) ships dist/**/*.d.mts.map / *.d.cts.map declaration maps whose sources point at ../src/*.ts — and, for the packages that bundle it, at ../../core-internal/src/*.ts, a private: true workspace package that is never published. Since the tarballs contain only dist/ ("files": ["dist"]) and the maps carry no usable sourcesContent, 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.cts files carry no //# sourceMappingURL= reference — editors fall back to the normal .d.ts navigation instead of chasing a map that cannot resolve. The runtime JS source maps (.mjs.map/.cjs.map), which do embed sourcesContent and 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.map files in any tarball, 0 declaration files referencing a map, and every sources entry of every remaining shipped .map has embedded sourcesContent (no ../src or core-internal references left).

How

  • packages/{core,client,server,server-legacy,codemod}/tsdown.config.ts, packages/middleware/{express,fastify,hono,node}/tsdown.config.ts: set dts.sourcemap: false, which turns off declarationMap for the dts pass and drops the .d.*ts.map assets from the bundle.
  • common/tsdown/stripDtsSourceMappingUrl.mjs (+ .d.mts for typecheck): a shared inputOptions hook that strips the trailing //# sourceMappingURL= comment rolldown still appends to the (now map-less) declaration chunks. It is wired through inputOptions rather than plugins because tsdown does not forward user plugins to the extra CJS dts pass that emits the .d.cts files. Plain .mjs so 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 inlineSources equivalent for declaration maps (microsoft/TypeScript#38966), which is exactly why the JS maps are fine on main while the declaration maps dangle. Shipping src/ would fix each package's own ../src references but not the ../../core-internal/src ones (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.map side of #2233 as originally reported against v1.x does not affect main — the tsdown/rolldown build already embeds sourcesContent into the runtime JS maps. The declaration maps were the remaining unresolvable piece on main, 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 with skipLibCheck: 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

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-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 75313b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@modelcontextprotocol/core Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/fastify Patch
@modelcontextprotocol/hono Patch
@modelcontextprotocol/node Patch
@modelcontextprotocol/core-internal Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2495

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2495

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2495

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2495

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2495

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2495

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2495

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2495

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2495

commit: 75313b5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant