microsoft / microsoft/TypeScript
`tsBuildInfoFile` is not extendable. Add an alternative `tsBuildInfoDir` option
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
π Search Terms
tsBuildInfoFile tsbuildinfo output directory
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β Suggestion
Add a tsBuildInfoDir config option for specifying the output directory for the .tsbuildinfo file.
π Motivating Example
tsconfig/
βββ tsconfig.base.json
βββ tsconfig.client.json
βββ tsconfig.config.json
βββ tsconfig.server.json
tsconfig.json
With a project structure like this, there is no way to have the individual project configs (tsconfig.client.ts etc.) derive their tsBuildInfoFile setting from the base config (tsconfig.base.json). If we set tsBuildInfoFile to some custom value in the base config, the individual project configs all end up having the same output path for their .tsbuildinfo files, which is of course wrong, so we have no better option than to set tsBuildInfoFile for each of the projects individually.
The recently introduced ${configDir} template variable can't help us here since the config files are all located in the same folder. Even if they weren't, it still wouldn't give us enough flexibility.
One possible solution is to rely on the outDir option which also affects where .tsbuildinfo files are placed, but it's only fine if we don't mind them being placed beside other output files, or if there are no other output files because we are using noEmit.
What I suggest is adding a tsBuildInfoDir option for specifying the output directory for the .tsbuildinfo file as an alternative to tsBuildInfoFile. The process of determining how the file is placed within that directory should be identical to that of outDir / declarationDir, meaning that the config file's placement relative to rootDir should be replicated.
With the following tsconfig.base.json,
// tsconfig.base.json
{
"compilerOptions": {
"rootDir": "${configDir}",
"outDir": "${configDir}/dist",
"tsBuildInfoDir": "./node_modules/.tsbuildinfo",
"incremental": true
}
}
this would enable structure as complicated as this one:
client/
βββ dist/
β βββ index.js
βββ index.ts
βββ tsconfig.client.json
node_modules/
βββ .tsbuildinfo/
βββ tsconfig.client.tsbuildinfo
βββ tsconfig.config.tsbuildinfo
βββ tsconfig.server.tsbuildinfo
βββ tsconfig.tsbuildinfo
server/
βββ dist/
β βββ index.js
βββ index.ts
βββ tsconfig.server.json
tsconfig.base.json
tsconfig.config.json
tsconfig.json
vite.config.ts
Here is what I assumed about the other config files:
Click to expand
// client/tsconfig.client.json
{
"include": ["**/*.ts"]
}
// client/tsconfig.server.json
{
"include": ["**/*.ts"]
}
// tsconfig.config.json
{
"compilerOptions": {
"noEmit": true
},
"include": ["*.config.ts"]
}
// tsconfig.json
{
"files": [],
"references": [
{ "path": "./client/tsconfig.client.json" },
{ "path": "./server/tsconfig.server.json" },
{ "path": "./tsconfig.config.json" }
]
}
When both tsBuildInfoDir and tsBuildInfoFile are set, the latter could be interpreted as the desired file name rather than the path (the path is then ${tsBuildInfoDir}/${tsBuildInfoFile}).
π» Use Cases
- What do you want to use this for?
β Putting.tsbuildinfofiles undernode_modules/.tsbuildinfoso that they are not in the way, but I still get the advantages of incremental builds. - What shortcomings exist with current approaches?
β The shortcomings oftsBuildInfoFileandoutDirare described above. - What workarounds are you using in the meantime?
β SettingtsBuildInfoFilefor each project individually :(
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up β it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named. Start by tracing how tsBuildInfoFile, outDir, and declarationDir determine build-info paths and how inherited configuration is resolved. Done means a tsBuildInfoDir option supports the proposed directory layout, preserves existing behavior, and has coverage for the configuration examples and interactions described here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100