Typescript: Incorrect place of tsbuildinfo file when rootDir option is specified

Created on 14 Apr 2019  路  7Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.5.0-dev.20190413, 3.4.3


Search Terms:

tsbuildinfo, incremental build, rootDir

Code

For reproduce test project https://github.com/ikokostya/ts-bugs can be used:

git clone https://github.com/ikokostya/ts-bugs
cd ts-bugs
npm install
npx tsc

The test project has the following file structure:

src/
    lib/
        foo.ts
    tests/
        foo.test.ts
tsconfig.json

tsconfig.json content:

{
    "compilerOptions": {
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "es2017",
        "lib": ["es2017"],
        "strict": true,
        "noEmitOnError": true,
        "sourceMap": true,
        "rootDir": "src",
        "incremental": true,
        "outDir": "out"
    },
    "include": [
        "src/**/*"
    ]
}

Expected behavior:

After compilation tsbuildinfo file will be placed in out directory, i.e. ./out/tsconfig.tsbuildinfo.

Actual behavior:

tsbuildinfo file is placed in project root directory, i.e. ./tsconfig.tsbuildinfo.

Playground Link:

Related Issues:
https://github.com/Microsoft/TypeScript/pull/29161
https://github.com/Microsoft/TypeScript/issues/30457

Working as Intended

Most helpful comment

This is correct since the output is relative to rootDir when specified. Since configFile is in parent directory relative to rootDir, the tsbuildinfo file goes in parent folder to outDir.

From d53efdf38058e37d52e794b6650689294e69b185
tsbuild info is generated at:

  • If composite or incremental then only the .tsbuildinfo will be generated
  • if --out or --outFile the file is outputFile.tsbuildinfo
  • if rootDir and outDir then outdir/relativePathOfConfigFromRootDir/configname.tsbuildinfo
  • if just outDir then outDir/configname.tsbuild
  • otherwise config.tsbuildinfo next to configFile

All 7 comments

This is correct since the output is relative to rootDir when specified. Since configFile is in parent directory relative to rootDir, the tsbuildinfo file goes in parent folder to outDir.

From d53efdf38058e37d52e794b6650689294e69b185
tsbuild info is generated at:

  • If composite or incremental then only the .tsbuildinfo will be generated
  • if --out or --outFile the file is outputFile.tsbuildinfo
  • if rootDir and outDir then outdir/relativePathOfConfigFromRootDir/configname.tsbuildinfo
  • if just outDir then outDir/configname.tsbuild
  • otherwise config.tsbuildinfo next to configFile

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@sheetalkamat this part was very much not obvious, and not mentioned in the original #29813 spec

if rootDir and outDir then outdir/relativePathOfConfigFromRootDir/configname.tsbuildinfo

This has left me needing to specify tsBuildInfoFile, which is a bit of a problem as we're only trial migrating between version 3.3 and 3.4 due to a breaking change and if I accidentally leave this setting in when running 3.3 I get an Unknown compiler option error.

Is there something other than rootDir that I can use to control the directory structure within outDir? That's the only reason I specified rootDir at all, rather than use the automatic common root directory.

This is definitely not obvious. I spent quite a while to figure out, why after adding a composite: true to one of my module, TS reports tsconfig.tsbuildinfo will be overwritten under the output dir root, and refuse to compile.

The reason is my project layout is having a src folder under each module (which is quite common I assume), and because of rule 3 mentioned above, the tsbuildinfo will go into the parent folder. Resulting in, having multiple composite project will step on each other with the tsbuildinfo file.

Putting the spec mentioned above in the doc would be helpful for sure.

Another thing can be done is changing configname to something like project name, since configname IMU is the base name of the project file, which is pretty much always going to be tsconfig.json, and that's why the conflict is happening.

At the end of the day needing to add tsBuildInfoFile to the config when switching to TS3.4 is not a _huge_ deal, it's just surprising (and a little annoying).

Sure. Solving the issue is not hard, finding out why is really time consuming OTOH.

I hit this situation the other day, and had to add tsBuildInfoFile to my tsconfig file.

    "rootDir": "src",
    "outDir": "."

The tsbuildinfo was emitting one level up, outside of my project's directory. This matches the description here https://github.com/Microsoft/TypeScript/issues/30925#issuecomment-483371766 but was initially confusing.

I guess it's done this way because the .tsbuildinfo is an artifact of my tsconfig file, similar to how .js and .d.ts files are artifacts of the .ts source code.

Alternative to specifying tsBuildInfoFile, I could move my tsconfig file into the src directory and create a root tsconfig with a "references" to it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kyasbal-1994 picture kyasbal-1994  路  3Comments

siddjain picture siddjain  路  3Comments

dlaberge picture dlaberge  路  3Comments

weswigham picture weswigham  路  3Comments

jbondc picture jbondc  路  3Comments