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'; 29 30export function genAbc() { 31 return { 32 name: 'genAbc', 33 buildStart() { 34 this.share.arkProjectConfig = initArkProjectConfig(this.share); 35 checkArkCompilerCacheInfo(this); 36 //Because calling the method of SourceMapGenerator may not retrieve the rollupObject 37 //it is necessary to assign the rollupObject to SourceMapGenerator in the early stages of build 38 SourceMapGenerator.init(this); 39 }, 40 shouldInvalidCache: shouldInvalidCache, 41 transform: transformForModule, 42 moduleParsed(moduleInfo: moduleInfoType): void { 43 // process single ModuleSourceFile 44 if (this.share.projectConfig.singleFileEmit) { 45 ModuleSourceFile.processSingleModuleSourceFile(this, moduleInfo.id); 46 } 47 }, 48 beforeBuildEnd: { 49 // [pre] means this handler running in first at the stage of beforeBuildEnd. 50 order: 'pre', 51 handler() { 52 if (this.share.projectConfig.singleFileEmit) { 53 writeDeclarationFiles(this.share.arkProjectConfig.compileMode); 54 return; 55 } 56 if (compilerOptions.needDoArkTsLinter) { 57 checkIfJsImportingArkts(this); 58 } 59 if (this.share.projectConfig.needCoverageInsert) { 60 this.share.ModuleSourceFile = ModuleSourceFile.getSourceFiles(); 61 } 62 } 63 }, 64 buildEnd: generateModuleAbc, 65 generateBundle: generateBundleAbc, 66 cleanUp: () => { 67 SourceMapGenerator.cleanSourceMapObject(); 68 cleanUpUtilsObjects(); 69 cleanUpKitImportObjects(); 70 cleanUpFilesList(); 71 cleanModuleMode(); 72 ModuleSourceFile.cleanUpObjects(); 73 cleanSharedModuleSet(); 74 } 75 }; 76} 77 78interface moduleInfoType { 79 id: string; 80};