1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { initArkProjectConfig } from './common/process_ark_config'; 17import { generateBundleAbc } from './generate_bundle_abc'; 18import { generateModuleAbc, cleanModuleMode } from './generate_module_abc'; 19import { transformForModule } from './transform'; 20import { checkArkCompilerCacheInfo, shouldInvalidCache } from './cache'; 21import { checkIfJsImportingArkts } from './check_import_module'; 22import { cleanSharedModuleSet } from './check_shared_module'; 23import { compilerOptions } from '../../ets_checker'; 24import { ModuleSourceFile } from './module/module_source_file'; 25import { SourceMapGenerator } from './generate_sourcemap'; 26import { cleanUpUtilsObjects, writeDeclarationFiles } from '../../ark_utils'; 27import { cleanUpKitImportObjects } from '../../process_kit_import'; 28import { cleanUpFilesList } from './utils'; 29import { CommonLogger } from './logger'; 30 31export function genAbc() { 32 return { 33 name: 'genAbc', 34 buildStart() { 35 this.share.arkProjectConfig = initArkProjectConfig(this.share); 36 checkArkCompilerCacheInfo(this); 37 //Because calling the method of SourceMapGenerator may not retrieve the rollupObject 38 //it is necessary to assign the rollupObject to SourceMapGenerator in the early stages of build 39 SourceMapGenerator.init(this); 40 }, 41 shouldInvalidCache: shouldInvalidCache, 42 transform: transformForModule, 43 moduleParsed(moduleInfo: moduleInfoType): void { 44 // process single ModuleSourceFile 45 if (this.share.projectConfig.singleFileEmit) { 46 ModuleSourceFile.processSingleModuleSourceFile(this, moduleInfo.id); 47 } 48 }, 49 beforeBuildEnd: { 50 // [pre] means this handler running in first at the stage of beforeBuildEnd. 51 order: 'pre', 52 handler() { 53 if (this.share.projectConfig.singleFileEmit) { 54 writeDeclarationFiles(this.share.arkProjectConfig.compileMode); 55 return; 56 } 57 if (compilerOptions.needDoArkTsLinter) { 58 checkIfJsImportingArkts(this); 59 } 60 if (this.share.projectConfig.needCoverageInsert) { 61 this.share.ModuleSourceFile = ModuleSourceFile.getSourceFiles(); 62 } 63 } 64 }, 65 buildEnd: generateModuleAbc, 66 generateBundle: generateBundleAbc, 67 cleanUp: () => { 68 SourceMapGenerator.cleanSourceMapObject(); 69 cleanUpUtilsObjects(); 70 cleanUpKitImportObjects(); 71 cleanUpFilesList(); 72 cleanModuleMode(); 73 ModuleSourceFile.cleanUpObjects(); 74 cleanSharedModuleSet(); 75 CommonLogger.destroyInstance(); 76 } 77 }; 78} 79 80interface moduleInfoType { 81 id: string; 82};