Skip to content

Fix content mapper's virtual file module format - #65432

Merged
Andrew Branch (andrewbranch) merged 5 commits into
microsoft:mainfrom
andrewbranch:content-mapper-file-format
Nov 10, 2026
Merged

Andrew Branch (andrewbranch) merged 5 commits into
microsoft:mainfrom
andrewbranch:content-mapper-file-format

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

Fixes #65135

Also issues a diagnostic when the extension provided in a Transform response implies a module format that disagrees with the module format that will be assigned to the declaration file output. For example, if you respond to Transform as a .mts file, then either your package.json must have "type": "module" or your configured outputExtensions must map your custom file extension to a .mjs output. This is because the module format of a declaration file name like App.d.svelte.ts is always determined by the package.json, so it would create problems if that decision disagrees with what the virtual file claims to be.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 17:57
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 10, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Incremental program reuse bypasses validation, allowing edits to clear TS18125 and admit incompatible mapped sources.

4 open issues
2 files not reviewed
  • tsc/internal/diagnostics/diagnostics_generated.go: Generated file
  • tsc/testdata/baselines/reference/compiler/contentMapperOutputExtensions.js: Generated file
What changed in this PR

Fixes #65135 by making the native compiler use content-mapped virtual filenames when determining module format and resolution modes. It also adds a diagnostic when a virtual file’s format conflicts with its declaration output.

Changes:

  • Use virtual filenames consistently in module-format and resolution helpers.
  • Validate declaration-format compatibility and document the mapper contract.
  • Expand compiler and language-server tests, update baselines, and preserve original test inputs when preparing transformed baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​contentMapperOutputExtensionsOverlap.ts Specify the expected virtual module extension.
tsc/​testdata/​tests/​cases/​compiler/​contentMapperOutputExtensions.ts Align the virtual extension with declaration output.
tsc/​testdata/​tests/​cases/​compiler/​contentMapperModuleFormat.ts Add module-format mismatch cases.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensionsOverlap.types Update transformed-source type baseline.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensionsOverlap.symbols Update symbol positions.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensionsOverlap.js Reflect the added mapper directive.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensionsOverlap.contentmapper Update original and transformed text.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensions.types Update transformed-source type baseline.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensions.symbols Update symbol positions.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensions.sourcemap.txt Adjust declaration source positions.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensions.js.map Update declaration source mappings.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensions.js Reflect the added mapper directive.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperOutputExtensions.contentmapper Update mapper text baseline.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperModuleFormat.js Record declaration output for rejected transforms.
tsc/​testdata/​baselines/​reference/​compiler/​contentMapperModuleFormat.contentmapper Record module-format mismatch diagnostics.
tsc/​internal/​testrunner/​compiler_runner.go Copy test files before substituting transformed text.
tsc/​internal/​project/​contentmapper_test.go Cover format rejection and configuration recovery.
tsc/​internal/​fourslash/​tests/​contentMapperOutputExtensions_test.go Test source and declaration redirects across formats.
tsc/​internal/​diagnostics/​diagnostics_generated.go Register the generated mismatch diagnostic.
tsc/​internal/​diagnostics/​diagnosticMessages.json Define diagnostic TS18125.
tsc/​internal/​diagnostics/​diagnosticMessages.generated.json Add the generated diagnostic message.
tsc/​internal/​contentmapper/​host.go Document virtual-extension format compatibility.
tsc/​internal/​contentmapper/​contentmapper.go Clarify output-extension format requirements.
tsc/​internal/​compiler/​program.go Use virtual filenames in module-format helpers.
tsc/​internal/​compiler/​fileloader.go Validate formats and use virtual names during resolution.
tsc/​internal/​compiler/​contentmapper_test.go Expand format and package-scope coverage.

Review effort: Balanced

Comment thread tsc/internal/compiler/fileloader.go Resolved
Comment thread tsc/internal/compiler/fileloader.go Resolved
Comment thread tsc/internal/compiler/fileloader.go Resolved
Comment thread tsc/internal/compiler/fileloader.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The diagnostic can remain stale after package.json changes because dependencies are not tracked, and it incorrectly reports declaration-format conflicts for JSON sources that emit no declarations.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Skip JSON source files in declaration-format checks

tsc/​internal/​compiler/​program.go:828

A canonical mapper result with the supported .json virtual extension will always receive TS18125 here: GetImpliedNodeFormatForFile returns ResolutionModeNone for JSON, whereas the synthesized declaration filename has CommonJS or ESM format. JSON source files do not produce declarations (GetOutputPathsFor already excludes them), so there is no declaration-format conflict to report. Please skip JSON source files in this guard.

4 resolved since last review
2 files not reviewed
  • tsc/internal/diagnostics/diagnostics_generated.go: Generated file
  • tsc/testdata/baselines/reference/compiler/contentMapperOutputExtensions.js: Generated file

Review effort: Balanced

Comment thread tsc/internal/compiler/program.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the changes to virtual-filename module-format detection and resolution.

No open issues 🎉

1 resolved since last review
2 files not reviewed
  • tsc/internal/diagnostics/diagnostics_generated.go: Generated file
  • tsc/testdata/baselines/reference/compiler/contentMapperOutputExtensions.js: Generated file

Review effort: Balanced

@andrewbranch

Copy link
Copy Markdown
Member Author

This is a technically a breaking change for content mapper implementers since the beta that should be called out in the RC blog post.

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 10, 2026
@andrewbranch
Andrew Branch (andrewbranch) added this pull request to the merge queue Nov 10, 2026
Merged via the queue into microsoft:main with commit 753fc92 Nov 10, 2026
34 checks passed
@andrewbranch
Andrew Branch (andrewbranch) deleted the content-mapper-file-format branch November 10, 2026 20:34
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Nov 10, 2026
Colin McDonnell (colinhacks) added a commit to colinhacks/motherload that referenced this pull request Nov 22, 2026
… a project's tsconfig entry names the package alone, "contentMappers": [{ "package": "motherload" }], and the docs, the agent prompt and the examples show that entry and install typescript@next in place of typescript@beta. TypeScript reads a manifest's typescript.contentMapper.extensions from 7.1.0-dev.20261112.1 on (microsoft/TypeScript#65047); 7.1.0-beta ignores it and refuses the short entry with TS5024, while the long entry keeps working on both. An entry's own extensions replace the manifest's, so the docs show listing some formats, and adding .env.local beside every format.

The repository and the examples pin typescript@7.1.0-dev.20261118.1. On that nightly a mapper that reports its module as .mts fails with TS18125 in every package without "type": "module", under nodenext, node20, bundler resolution and preserve alike, since microsoft/TypeScript#65432 holds a mapped module to the format of the declaration file TypeScript would write for it. The mapper now reports .ts, so a data file takes its package's format; the one case that loses is an .mts importer under nodenext in a package with no "type", whose default import is the CommonJS module (TS2339). Next.js moves from 16.4.2 to 16.4.6 in lab/nextjs and examples/nextjs, since 16.4.2's next build stops on a security advisory. DESIGN.md's new "The tsconfig entry" section, its module bullet and its pins, and PLAN.md, record it.

Verified: tests/packages.test.ts holds each manifest's list to its loader's and to the docs' table of packages; a test in tests/lab.test.ts checks that an entry's own list wins; tests/fixtures/commonjs checks the three module-format cases; scripts/build.ts refuses a published mapper with no extensions, and every dist manifest carries its list; scripts/check-dist.ts type-checks the installed lab/basic with the short entry and finds a broken .toml file's error placed in it. nub run typecheck; nub run test, 98 passed, none skipped; nub run build and nub run check-dist; nub run build in site/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team Breaking Change Would introduce errors in existing code For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Native tsc: GetEmitModuleFormatOfFile ignores content-mapper VirtualFileName (*.mts treated as CJS under module:commonjs)

3 participants