Content mappers: composite projects report TS6307 for supplemental virtual outputs

Abierto
#64,350 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, typescript
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

🔎 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.

Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 15 h
PR fusionados (30 d)
106

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/TypeScript

Todos los issues de microsoft/TypeScript

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.