Content mappers: composite projects report TS6307 for supplemental virtual outputs

オープン
#64,350 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, typescript
領域
compilers

調査の方向性

Start in program.go at verifyCompilerOptions, especially the rootPaths loop that reports TS6307, and reproduce the failure with the content mapper setup and tsc --runExternalCode -p lib --pretty false. Done means supplemental virtual files belonging to a listed source no longer trigger TS6307, while composite project builds and referenced-project checks still pass.

索引モデルが issue の本文から書いたものです。

説明

🔎 Search Terms
  • content mapper supplemental composite TS6307
  • Supplemental virtual file produced by the content mapper
  • is not listed within the file list of project
🕗 Version & Regression Information
  • 7.1.0-dev.20260918.1 and 7.1.0-dev.20260919.1 (@typescript/typescript-darwin-x64), macOS 26.6 x64
  • Content mappers are new in 7.1, so no earlier version to compare against
⏯ Playground Link

n/a (needs a content mapper)

💻 Code

A content mapper that returns a supplemental output makes every composite project fail with TS6307, because the supplemental virtual file (greet.foo.0.mts below) is never part of the project's file list. There is no files or include value that can list it: include globs are matched against the disk, and naming it in files gives TS6053 (file not found). Since referenced projects must be composite, a mapper that uses supplemental outputs cannot be used in a tsc --build graph at all.

Minimal mapper (node_modules/foo-mapper), no dependencies. It treats .foo files as plain TypeScript and returns one supplemental .mts output per file (the real use case is a <script> block inside a single-file component):

node_modules/foo-mapper/package.json

{
  "name": "foo-mapper",
  "version": "0.0.0",
  "type": "module",
  "typescript": { "contentMapper": { "exec": ["node", "mapper.mjs"] } }
}

node_modules/foo-mapper/mapper.mjs

let buffered = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', (chunk) => {
  buffered += chunk;
  for (;;) {
    const end = buffered.indexOf('\r\n\r\n');
    if (end < 0) return;
    const length = Number(/Content-Length:\s*(\d+)/i.exec(buffered.slice(0, end))[1]);
    if (buffered.length < end + 4 + length) return;
    const message = JSON.parse(buffered.slice(end + 4, end + 4 + length));
    buffered = buffered.slice(end + 4 + length);
    if (message.id == null) continue;
    let result = null;
    if (message.method === 'initialize') result = { positionEncoding: 'utf-16', diagnosticSource: 'foo' };
    if (message.method === 'openProject') result = {};
    if (message.method === 'transform') {
      const { content } = message.params;
      result = {
        text: content,
        extension: '.ts',
        mappings: [[0, content.length, 0, content.length, 0, 0]],
        supplemental: [{ text: 'export {};\n', extension: '.mts', mappings: [] }],
      };
    }
    const body = JSON.stringify({ jsonrpc: '2.0', id: message.id, result });
    process.stdout.write(`Content-Length: ${Buffer.byteLength(body)}\r\n\r\n${body}`);
  }
});
process.stdin.on('end', () => process.exit(0));

lib/tsconfig.json

{
  "contentMappers": [{ "package": "foo-mapper", "extensions": [".foo"] }],
  "compilerOptions": {
    "composite": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "outDir": "dist",
    "rootDir": ".",
    "module": "esnext",
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "strict": true,
    "types": []
  },
  "include": ["index.ts", "*.foo"]
}

lib/greet.foo

export function greet(name: string): string {
  return `hello ${name}`;
}

lib/index.ts

export { greet } from './greet.foo';

Run:

tsc --runExternalCode -p lib --pretty false
🙁 Actual behavior
error TS6307: File '/repro/lib/greet.foo.0.mts' is not listed within the file list of project '/repro/lib/tsconfig.json'. Projects must list all files or use an 'include' pattern.
  The file is in the program because:
    Supplemental virtual file produced by the content mapper for file '/repro/lib/greet.foo'.

Exit code 2. tsc --build of a project that references lib reports the same error. Variations that do not help:

  • "include": ["index.ts", "*.foo", "*.foo.*.mts"]: same TS6307 (the glob is matched against the disk, where the virtual file does not exist)
  • "files": ["index.ts", "greet.foo", "greet.foo.0.mts"]: error TS6053: File '/repro/lib/greet.foo.0.mts' not found.
  • "composite": false: emits dist/greet.d.foo.ts, dist/greet.foo.0.d.mts and dist/index.d.ts without errors, but a non-composite project cannot be referenced (TS6306)
🙂 Expected behavior

No TS6307. A supplemental output belongs to its original file: if greet.foo is a root file of the project, greet.foo.0.mts should count as listed too. In program.go the composite check (verifyCompilerOptions, the rootPaths loop that reports File_0_is_not_listed_within_the_file_list_of_project_1_...) could skip files whose CanonicalSourceFile() is set, or check rootPaths against file.OriginalFileName() instead of file.FileName().

Additional information about the issue

Found while building the .tsrx content mapper for TSRX (tsrx-org/tsrx#41); the repro above is the same shape without the framework. Tested on 7.1.0-dev.20260918.1 and 7.1.0-dev.20260919.1.

主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 15時間
マージ済み PR(30日)
106

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。