mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-19 16:43:34 -04:00
!846 optimize ts check increment.
Merge pull request !846 from lihong/tscheck_cache
This commit is contained in:
@@ -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<string, CacheFileName>;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 && /(?<!\.d)\.(ets|ts)$/.test(moduleObj.resolvedFileName)) {
|
||||
const file: string = path.resolve(moduleObj.resolvedFileName);
|
||||
const mtimeMs: number = fs.statSync(file).mtimeMs;
|
||||
children.push(file);
|
||||
const value: CacheFileName = cache[file];
|
||||
if (value) {
|
||||
value.mtimeMs = mtimeMs;
|
||||
value.error = error;
|
||||
} else {
|
||||
cache[file] = { mtimeMs, children: [], error };
|
||||
}
|
||||
}
|
||||
});
|
||||
cache[path.resolve(containingFile)] = { mtimeMs: fs.statSync(containingFile).mtimeMs, children, error };
|
||||
}
|
||||
|
||||
export function createWatchCompilerHost(rootFileNames: string[],
|
||||
reportDiagnostic: ts.DiagnosticReporter, delayPrintLogCount: Function, isPipe: boolean = false
|
||||
): ts.WatchCompilerHostOfFilesAndCompilerOptions<ts.BuilderProgram> {
|
||||
|
||||
Reference in New Issue
Block a user