vite-esbuild-typescript-checker
Version:
* Speeds up [TypeScript](https://github.com/Microsoft/TypeScript) type checking * Supports [Vue Single File Component](https://vuejs.org/v2/guide/single-file-components.html) * Displays nice error messages with the [code frame](https://babeljs.io/docs/en/
46 lines (45 loc) • 1.91 kB
JavaScript
import ts from 'typescript';
import { createWatchCompilerHost } from '../host/watch-compiler-host.js';
import { getParsedConfig } from '../config.js';
import { afterProgramEmitAndDiagnostics } from '../functions.js';
let watchCompilerHost;
let watchProgram;
let shouldUpdateRootFiles = false;
export function useWatchProgram(port) {
if (!watchCompilerHost) {
const parsedConfig = getParsedConfig();
watchCompilerHost = createWatchCompilerHost(parsedConfig, (rootNames, compilerOptions, host, oldProgram, configFileParsingDiagnostics, projectReferences)=>{
// if (compilerOptions) {
// startTracingIfNeeded(compilerOptions);
// }
return ts.createSemanticDiagnosticsBuilderProgram(rootNames, compilerOptions, host, oldProgram, configFileParsingDiagnostics, projectReferences);
}, undefined, undefined, (builderProgram)=>{
afterProgramEmitAndDiagnostics(builderProgram, port);
// updateDiagnostics(
// getConfigFilePathFromBuilderProgram(builderProgram),
// getDiagnosticsOfProgram(builderProgram)
// );
// emitDtsIfNeeded(builderProgram);
// emitTsBuildInfoIfNeeded(builderProgram);
// stopTracingIfNeeded(builderProgram);
});
watchProgram = undefined;
}
if (!watchProgram) {
watchProgram = ts.createWatchProgram(watchCompilerHost);
}
if (shouldUpdateRootFiles) {
// we have to update root files manually as don't use config file as a program input
// watchProgram.updateRootFileNames(getDependencies().files);
shouldUpdateRootFiles = false;
}
}
export function invalidateWatchProgram(withHost = false) {
if (withHost) {
watchCompilerHost = undefined;
}
watchProgram = undefined;
}
export function invalidateWatchProgramRootFileNames() {
shouldUpdateRootFiles = true;
}