diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 965a083..50dcce1 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -68,6 +68,19 @@ interface Info { }; } +export interface CacheFileName { + mtimeMs: number, + children: string[], + error: boolean +} + +interface NeedUpdateFlag { + flag: boolean; +} + +export let cache: Cache; +type Cache = Record; + export class ResultStates { private mStats: Stats; private mErrorCount: number = 0; @@ -186,7 +199,10 @@ export class ResultStates { createWatchCompilerHost(rootFileNames, this.printDiagnostic.bind(this), this.delayPrintLogCount.bind(this))); } else { - const languageService: ts.LanguageService = createLanguageService(rootFileNames); + const cacheFile = path.resolve(projectConfig.cachePath, '../.ts_checker_cache'); + cache = fs.existsSync(cacheFile) ? JSON.parse(fs.readFileSync(cacheFile).toString()) : {}; + const filterFiles: string[] = filterInput(rootFileNames); + const languageService: ts.LanguageService = createLanguageService(filterFiles); globalProgram.program = languageService.getProgram(); const allDiagnostics: ts.Diagnostic[] = globalProgram.program .getSyntacticDiagnostics() @@ -195,6 +211,7 @@ export class ResultStates { allDiagnostics.forEach((diagnostic: ts.Diagnostic) => { this.printDiagnostic(diagnostic); }); + fs.writeFileSync(cacheFile, JSON.stringify(cache, null, 2)); } }); @@ -219,6 +236,9 @@ export class ResultStates { private printDiagnostic(diagnostic: ts.Diagnostic): void { const message: string = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); if (this.validateError(message)) { + if (process.env.watchMode !== 'true') { + updateErrorFileCache(diagnostic); + } this.mErrorCount += 1; if (diagnostic.file) { const { line, character }: ts.LineAndCharacter = @@ -411,3 +431,38 @@ export class ResultStates { return message; } } + +function updateErrorFileCache(diagnostic: ts.Diagnostic): void { + if (diagnostic.file && cache[path.resolve(diagnostic.file.fileName)]) { + cache[path.resolve(diagnostic.file.fileName)].error = true; + } +} + +function filterInput(rootFileNames: string[]): string[] { + return rootFileNames.filter((file: string) => { + const needUpdate: NeedUpdateFlag = { flag: false }; + checkNeedUpdateFiles(path.resolve(file), needUpdate); + return needUpdate.flag; + }); +} + +function checkNeedUpdateFiles(file: string, needUpdate: NeedUpdateFlag): void { + if (needUpdate.flag) { + return; + } + + const value: CacheFileName = cache[file]; + const mtimeMs: number = fs.statSync(file).mtimeMs; + if (value) { + if (value.error || value.mtimeMs !== mtimeMs) { + needUpdate.flag = true; + return; + } + for (let i = 0; i < value.children.length; ++i) { + checkNeedUpdateFiles(value.children[i], needUpdate); + } + } else { + cache[file] = { mtimeMs, children: [], error: false }; + needUpdate.flag = true; + } +} diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index 587da55..903d509 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -41,6 +41,10 @@ import { getName } from './process_component_build'; import { INNER_COMPONENT_NAMES } from './component_map'; import { props } from './compile_info'; import { resolveSourceFile } from './resolve_ohm_url'; +import { + CacheFileName, + cache +} from './compile_info'; function readDeaclareFiles(): string[] { const declarationsFileNames: string[] = []; @@ -182,9 +186,32 @@ function resolveModuleNames(moduleNames: string[], containingFile: string): ts.R } } } + if (process.env.watchMode !== 'true') { + createOrUpdateCache(resolvedModules, containingFile); + } return resolvedModules; } +function createOrUpdateCache(resolvedModules: ts.ResolvedModuleFull[], containingFile: string): void { + const children: string[] = []; + const error: boolean = false; + resolvedModules.forEach(moduleObj => { + if (moduleObj && moduleObj.resolvedFileName && /(? {