From a9f3d4907b4657fac0ba0eb46904b732a276fbd9 Mon Sep 17 00:00:00 2001 From: luobohua Date: Wed, 16 Jul 2025 16:51:42 +0800 Subject: [PATCH] 1.1 count the number of files (including declgen) Issue: https://gitee.com/openharmony/developtools_ace_ets2bundle/issues/ICMR7K Signed-off-by: luobohua --- compiler/src/ets_checker.ts | 3 ++ .../ets_ui/rollup-plugin-ets-checker.ts | 10 +++-- .../ets_ui/rollup-plugin-ets-typescript.ts | 45 +++++++++++-------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index ba9ce1ee5..975e6d18f 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -664,6 +664,7 @@ export function collectAllFiles(program?: ts.Program, rollupFileList?: IterableI collectTscFiles(program, rollupShareObject); return; } + console.log('rollupFileList', rollupFileList); mergeRollUpFiles(rollupFileList, rollupObject); } @@ -678,6 +679,8 @@ export function collectTscFiles(program: ts.Program, rollupShareObject: Object = const recordInfo = MemoryMonitor.recordStage(MemoryDefine.COLLECT_TSC_FILES_ALL_RESOLVED_MODULES); programAllFiles.forEach(sourceFile => { const fileName = toUnixPath(sourceFile.fileName); + console.log('programAllFile', fileName); + fs.appendFileSync('programAllFile.txt', `${fileName}\n`); // @ts-ignore sourceFileDependencies.set(fileName, sourceFile.resolvedModules); if (!(fileName.startsWith(projectRootPath + '/') || isOtherProjectResolvedModulesFilePaths(rollupShareObject, fileName))) { diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts index 519808aae..aed25682a 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-checker.ts @@ -33,11 +33,11 @@ import { TSC_SYSTEM_CODE, traverseProgramSourceFiles, arkTsEvolutionModuleMap, - cleanUpArkTsEvolutionModuleMap, + cleanUpArkTsEvolutionModuleMap } from '../../ets_checker'; import { TS_WATCH_END_MSG } from '../../pre_define'; import { - setChecker, + setChecker } from '../../utils'; import { configureSyscapInfo, @@ -62,7 +62,7 @@ import { isMixCompile } from '../ark_compiler/interop/interop_manager'; -export let tsWatchEmitter: EventEmitter | undefined = undefined; +export let tsWatchEmitter: EventEmitter | undefined; export let tsWatchEndPromise: Promise; export function etsChecker() { @@ -70,6 +70,7 @@ export function etsChecker() { return { name: 'etsChecker', buildStart() { + console.log('buildStart'); if (isMixCompile()) { collectArkTSEvolutionModuleInfo(this.share); } @@ -153,6 +154,7 @@ export function etsChecker() { fastBuildLogger.debug(TS_WATCH_END_MSG); tsWatchEmitter.emit(TS_WATCH_END_MSG); } else { + console.log('rootFileNames', rootFileNames); serviceChecker(rootFileNames, logger, resolveModulePaths, eventServiceChecker, this.share); } setChecker(); @@ -189,4 +191,4 @@ function rootFileNamesCollect(rootFileNames: string[], sharedObj: Object): void } rootFileNames.push(path.resolve(fileName)); }); -} \ No newline at end of file +} diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index 3b63b205f..3b4fb390a 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-lines-per-function */ /* * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -123,7 +124,7 @@ import { interopTransform } from '../ark_compiler/interop/process_arkts_evolution'; -let switchTsAst: boolean = true; +const switchTsAst: boolean = true; const filter: any = createFilter(/(? = new WeakMap(); function getArkoalaTsProgram(program: ts.Program): ts.Program { @@ -374,10 +376,12 @@ function getArkoalaTsProgram(program: ts.Program): ts.Program { // Probably we can use the reported diagnostics in the output const pluginTransformExtras: Object = { diagnostics: [], - addDiagnostic(): number {return 0}, + addDiagnostic(): number { + return 0; + }, removeDiagnostic(): void {}, ts: ts, - library: 'typescript', + library: 'typescript' }; extendedProgram = arkoalaProgramTransform(program, compilerHost, pluginOptions, pluginTransformExtras); arkoalaTsProgramCache.set(program, extendedProgram); @@ -399,7 +403,7 @@ async function transform(code: string, id: string) { if (projectConfig.compileMode !== 'esmodule') { const eventEtsTransformForJsbundle = createAndStartEvent(hookEventFactory, 'transform for jsbundle'); - let compilerOptions = ts.readConfigFile( + const compilerOptions = ts.readConfigFile( path.resolve(__dirname, '../../../tsconfig.json'), ts.sys.readFile).config.compilerOptions; const componentPaths: string[] | undefined = getExternalComponentPaths(); if (componentPaths) { @@ -447,12 +451,13 @@ async function transform(code: string, id: string) { // 2. .ets/.ts imported by .js file with same name '.d.ts' file which is prior to .js by tsc default resolving if (!targetSourceFile) { await processNoTargetSourceFile(id, code, eventEtsTransformForEsmodule); - const recordInfo = MemoryMonitor.recordStage(MemoryDefine.GLOBAL_PROGRAM_GET_CHECKER); + const recordInfo = MemoryMonitor.recordStage(MemoryDefine.GLOBAL_PROGRAM_GET_CHECKER); // init TypeChecker to run binding globalProgram.checker = tsProgram.getTypeChecker(); globalProgram.strictChecker = tsProgram.getLinterTypeChecker(); MemoryMonitor.stopRecordStage(recordInfo); targetSourceFile = tsProgram.getSourceFile(id)!; + console.log('there is no targetSourceFile'); storedFileInfo.reUseProgram = false; collectAllFiles(tsProgram); } else { @@ -464,6 +469,8 @@ async function transform(code: string, id: string) { } storedFileInfo.reUseProgram = true; } + console.log('targetSourceFile', targetSourceFile); + fs.appendFileSync('targetSourceFile.txt', `${targetSourceFile}\n`); setPkgNameForFile(this.getModuleInfo(id)); const eventValidateEts = createAndStartEvent(eventEtsTransformForEsmodule, 'validateEts'); validateEts(code, id, this.getModuleInfo(id).isEntry, logger, targetSourceFile, hvigorLogger); @@ -654,7 +661,7 @@ function setPkgNameForFile(moduleInfo: Object): void { } } -function validateEts(code: string, id: string, isEntry: boolean, logger: Object, sourceFile: ts.SourceFile, +function validateEts(code: string, id: string, isEntry: boolean, logger: Object, sourceFile: ts.SourceFile, hvigorLogger: Object | undefined = undefined): void { if (/\.ets$/.test(id)) { clearCollection(); @@ -666,7 +673,7 @@ function validateEts(code: string, id: string, isEntry: boolean, logger: Object, } } -function jsBundlePreProcess(code: string, id: string, isEntry: boolean, logger: Object, +function jsBundlePreProcess(code: string, id: string, isEntry: boolean, logger: Object, hvigorLogger: Object | undefined = undefined): string { if (/\.ets$/.test(id)) { clearCollection(); @@ -736,7 +743,7 @@ function findArkoalaRoot(): string { function isDir(filePath: string): boolean { try { - let stat: fs.Stats = fs.statSync(filePath); + const stat: fs.Stats = fs.statSync(filePath); return stat.isDirectory(); } catch (e) { return false; @@ -748,15 +755,15 @@ function setIncrementalFileInHar(cacheFilePath: string, buildFilePath: string, a allFilesInHar.set(cacheFilePath, buildFilePath); return; } - let extName = projectConfig.useTsHar ? '.ts' : '.js'; + const extName = projectConfig.useTsHar ? '.ts' : '.js'; allFilesInHar.set(cacheFilePath.replace(/\.ets$/, '.d.ets').replace(/\.ts$/, '.d.ts'), buildFilePath.replace(/\.ets$/, '.d.ets').replace(/\.ts$/, '.d.ts')); allFilesInHar.set(cacheFilePath.replace(/\.e?ts$/, extName), buildFilePath.replace(/\.e?ts$/, extName)); } function checkRelateToConstEnum(id: string): boolean { - let tsProgram: ts.Program = globalProgram.builderProgram; - let targetSourceFile: ts.SourceFile | undefined = tsProgram ? tsProgram.getSourceFile(id) : undefined; + const tsProgram: ts.Program = globalProgram.builderProgram; + const targetSourceFile: ts.SourceFile | undefined = tsProgram ? tsProgram.getSourceFile(id) : undefined; if (!targetSourceFile) { return false; } @@ -768,16 +775,16 @@ function checkRelateToConstEnum(id: string): boolean { interface moduleInfoType { id: string; -}; +} interface optionsType { id: string; -}; +} interface newSourceFileType { id: string; code: string; -}; +} class CreateProgramMoment { static transFileCollect: Set = new Set(); -- Gitee