Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect place of tsbuildinfo file when rootDir option is specified #30925

Closed
ikokostya opened this issue Apr 14, 2019 · 8 comments
Closed

Incorrect place of tsbuildinfo file when rootDir option is specified #30925

ikokostya opened this issue Apr 14, 2019 · 8 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ikokostya
Copy link
Contributor

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:
#29161
#30457

@sheetalkamat
Copy link
Member

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 d53efdf
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

@sheetalkamat sheetalkamat added the Working as Intended The behavior described is the intended behavior; this is not a bug label Apr 15, 2019
@typescript-bot
Copy link
Collaborator

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

@TheSpyder
Copy link

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

@zen0wu
Copy link

zen0wu commented May 9, 2019

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.

@TheSpyder
Copy link

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

@zen0wu
Copy link

zen0wu commented May 10, 2019

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

@cspotcode
Copy link

cspotcode commented Aug 21, 2019

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 #30925 (comment) 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.

@ajaska
Copy link

ajaska commented Aug 16, 2022

I've encountered this odd behavior when working under Bazel:

rootDir: /home/user/project/subdir1/subdir2/rootdir/
tsconfig: /home/user/project/tsconfig/tsconfig.json
outDir: /home/user/project/outdir/

This results in this behavior:

Relative path from rootDir to tsconfig: ../../../tsconfig

Computed path to tsBuildInfo: /home/user/project/outdir/../../../tsconfig = /home/tsconfig/tsconfig.json
(outdir/relativePathOfConfigFromRootDir/configname.tsbuildinfo)

This is outside the outDir and in a bit of a nonsense location! 🤯 (My file system complains about this 😛)

I'm not sure what the "ideal" behavior is, but it's certainly at least a little unexpected. Perhaps if the path is relative we could remove any leading ..s?

everett1992 pushed a commit to everett1992/TypeScript-Website that referenced this issue Mar 1, 2023
I was going to report a bug because the actual default of tsbuildinfo
does not match the docs for --tsBuildInfoFile. I found [this issue] was
already reported and closed as 'working as intended'.

So I decided to add @sheetalkamat's response to the docs.

[this issue]: microsoft/TypeScript#30925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

7 participants