• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { ModuleMode } from './module_mode';
17import { isEs2Abc, isTs2Abc } from '../../../ark_utils';
18import { ES2ABC, TS2ABC } from '../common/ark_define';
19
20export class ModuleBuildMode extends ModuleMode {
21  constructor(rollupObject: any) {
22    super(rollupObject);
23  }
24
25  generateAbc(rollupObject: any) {
26    this.prepareForCompilation(rollupObject);
27    this.buildModuleSourceMapInfo();
28    this.executeArkCompiler();
29  }
30
31  executeArkCompiler() {
32    if (isEs2Abc(this.projectConfig)) {
33      this.generateEs2AbcCmd();
34      this.addCacheFileArgs();
35      this.generateMergedAbcOfEs2Abc();
36    } else if (isTs2Abc(this.projectConfig)) {
37      this.filterModulesByHashJson();
38      const splittedModules: any[] = this.getSplittedModulesByNumber();
39      this.invokeTs2AbcWorkersToGenProto(splittedModules);
40      this.processTs2abcWorkersToGenAbc();
41    } else {
42      this.throwArkTsCompilerError(`Invalid projectConfig.pandaMode for module build, should be either
43        "${TS2ABC}" or "${ES2ABC}"`);
44    }
45  }
46}
47