Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
allow incremental type checking to use caching (vercel#24992)
Browse files Browse the repository at this point in the history
emit must be called on build program to leverage caching

While the the current way of calling incremental typescript seem to work, it actually doesn't use caching correct. A difference is only notice-able on larger code bases...
  • Loading branch information
sokra authored May 11, 2021
1 parent 035efd3 commit d09241b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/next/lib/typescript/runTypeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ export async function runTypeCheck(
noEmit: true,
}

let program: import('typescript').Program
let program:
| import('typescript').Program
| import('typescript').BuilderProgram
let incremental = false
if (options.incremental && cacheDir) {
incremental = true
const builderProgram = ts.createIncrementalProgram({
program = ts.createIncrementalProgram({
rootNames: effectiveConfiguration.fileNames,
options: {
...options,
incremental: true,
tsBuildInfoFile: path.join(cacheDir, '.tsbuildinfo'),
},
})
program = builderProgram.getProgram()
} else {
program = ts.createProgram(effectiveConfiguration.fileNames, options)
}
Expand All @@ -73,7 +74,7 @@ export async function runTypeCheck(
//
const regexIgnoredFile = /[\\/]__(?:tests|mocks)__[\\/]|(?<=[\\/.])(?:spec|test)\.[^\\/]+$/
const allDiagnostics = ts
.getPreEmitDiagnostics(program)
.getPreEmitDiagnostics(program as import('typescript').Program)
.concat(result.diagnostics)
.filter((d) => !(d.file && regexIgnoredFile.test(d.file.fileName)))

Expand Down

0 comments on commit d09241b

Please sign in to comment.