TypeScript 增量编译不支持相对路径的outDir和tsBuildInfoFile,

00jrzges  于 6个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(43)

TypeScript版本: 4.2.0-dev.20201124
搜索词:

增量相对绝对outdir

代码

https://github.com/perbergland/typescript-incremental-watch-bug

let triggerBug = false;

const myResolvePath = (s: string) => (triggerBug ? s : system.resolvePath(s));

const compilerOptions = (): ts.CompilerOptions => ({
  tsBuildInfoFile: myResolvePath(`${cachePath}/buildfile.tsbuildinfo`),
  incremental: true,
  noEmit: false,
  outDir: myResolvePath(`${cachePath}/out`),
  sourceMap: true,
});
...
const config = ts.getParsedCommandLineOfConfigFile(
    configPath,
    /*optionsToExtend*/ compilerOptions(),
    /*host*/ {
      ...ts.sys,
      onUnRecoverableConfigFileDiagnostic: (d) => writeDiagnosticMessage(d),
    }
  );

  const host = ts.createIncrementalCompilerHost(config.options, system);
  const program = ts.createIncrementalProgram({
...

预期行为:

当outDir和tsBuildInfoFile是相对路径时,增量编译应该正常工作。

实际行为:

当outDir和tsBuildInfoFile是相对路径时,增量编译无法正常工作,源文件每次都会被重新生成。我已经将问题简化为上述代码,如果我将outDir和tsBuildInfoFile作为相对路径传递,可以看到program.emit(undefined, ...)会在每次调用时重新生成所有源文件。如果我将这些路径作为已解析的绝对路径传递,它将按预期工作。

./node_modules/.bin/ts-node-script compileTypescript.ts triggerbug
Typescript 4.2.0-dev.20201124
Triggering the bug by not resolving paths
reading buildinfo from output/buildfile.tsbuildinfo
emitAllAffectedFiles invoked
emitting output/out/Hello.js.map for /Users/per.bergland/Projects/typescript-incremental-watch-bug/src/Hello.tsx
emitting output/out/Hello.js for /Users/per.bergland/Projects/typescript-incremental-watch-bug/src/Hello.tsx
emitting output/buildfile.tsbuildinfo for ??
Emitting complete

./node_modules/.bin/ts-node-script compileTypescript.ts 
Typescript 4.2.0-dev.20201124
reading buildinfo from /Users/per.bergland/Projects/typescript-incremental-watch-bug/output/buildfile.tsbuildinfo
emitAllAffectedFiles invoked
Emitting complete
watbbzwu

watbbzwu1#

我无法使用TypeScript的下一个版本重现这个问题。

相关问题