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'; 36 37module.exports = function resultProcess(source: string, map: any): void { 38 process.env.compiler = BUILD_OFF; 39 source = processSystemApi(source, true, this.resourcePath); 40 if (/\.(ets|ts)$/.test(this.resourcePath)) { 41 componentInfo.id = 0; 42 propertyCollection.clear(); 43 linkCollection.clear(); 44 resetComponentCollection(); 45 if (transformLog && transformLog.errors.length) { 46 emitLogInfo(this, getTransformLog(transformLog)); 47 resetLog(); 48 } 49 } 50 if (projectConfig.compileMode == JSBUNDLE && 51 [abilityConfig.abilityEntryFile].concat(abilityConfig.projectAbilityPath).concat(abilityConfig.testRunnerFile).includes(this.resourcePath)) { 52 source = source.replace(/exports\.default/, 'globalThis.exports.default'); 53 } 54 55 if (projectConfig.compileMode == ESMODULE && projectConfig.processTs === false 56 && process.env.compilerType && process.env.compilerType === 'ark' && !projectConfig.compileHar) { 57 generateSourceFilesToTemporary(this.resourcePath, source, map, projectConfig, logger); 58 } 59 60 if (projectConfig.compileHar) { 61 generateSourceFilesInHar(this.resourcePath, source, '.js', projectConfig); 62 } 63 64 this.callback(null, source, map); 65}; 66