1/* 2 * Copyright (c) 2021 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 { BUILD_OFF, ESMODULE, JSBUNDLE } from './pre_define'; 17import { 18 resetLog, 19 transformLog 20} from './process_ui_syntax'; 21import { 22 propertyCollection, 23 linkCollection, 24 processSystemApi 25} from './validate_ui_syntax'; 26import { 27 emitLogInfo, 28 componentInfo, 29 generateSourceFilesInHar, 30 getTransformLog 31} from './utils'; 32import { generateSourceFilesToTemporary } from './ark_utils'; 33import { resetComponentCollection } from './validate_ui_syntax'; 34import { abilityConfig, projectConfig } from '../main'; 35import { logger } from './compile_info'; 36import processStructComponentV2 from './process_struct_componentV2'; 37 38module.exports = function resultProcess(source: string, map: any): void { 39 process.env.compiler = BUILD_OFF; 40 source = processSystemApi(source, true, this.resourcePath); 41 if (/\.(ets|ts)$/.test(this.resourcePath)) { 42 componentInfo.id = 0; 43 propertyCollection.clear(); 44 linkCollection.clear(); 45 resetComponentCollection(); 46 processStructComponentV2.resetStructMapInEts(); 47 if (transformLog && transformLog.errors.length) { 48 emitLogInfo(this, getTransformLog(transformLog)); 49 resetLog(); 50 } 51 } 52 if (projectConfig.compileMode === JSBUNDLE && 53 [abilityConfig.abilityEntryFile].concat(abilityConfig.projectAbilityPath).concat(abilityConfig.testRunnerFile).includes(this.resourcePath)) { 54 source = source.replace(/exports\.default/, 'globalThis.exports.default'); 55 } 56 57 if (projectConfig.compileMode === ESMODULE && projectConfig.processTs === false && 58 process.env.compilerType && process.env.compilerType === 'ark' && !projectConfig.compileHar) { 59 generateSourceFilesToTemporary(this.resourcePath, source, map, projectConfig, logger); 60 } 61 62 if (projectConfig.compileHar) { 63 generateSourceFilesInHar(this.resourcePath, source, '.js', projectConfig); 64 } 65 66 this.callback(null, source, map); 67}; 68