You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix content mapper's virtual file module format - #65432
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.
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.
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.
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.
… 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/.
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
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.
Fixes #65135
Also issues a diagnostic when the
extensionprovided 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.mtsfile, then either your package.json must have"type": "module"or your configuredoutputExtensionsmust map your custom file extension to a.mjsoutput. This is because the module format of a declaration file name likeApp.d.svelte.tsis always determined by the package.json, so it would create problems if that decision disagrees with what the virtual file claims to be.