• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 - 2025 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 fs from 'fs';
17import {fetchDependenciesFromFile, OH_PACKAGE_JSON5} from 'arkanalyzer';
18import Logger, {LOG_MODULE_TYPE} from 'arkanalyzer/lib/utils/logger';
19import path from 'path';
20import {ModuleCategory} from './moduleComponent';
21
22const logger = Logger.getLogger(LOG_MODULE_TYPE.TOOL, 'depGraphUtils');
23
24export const OH_MODULES_DIR = './oh_modules/';
25
26export function getModuleKind(modulePath: string): ModuleCategory {
27    const moduleJson5Path = path.join(modulePath, './src/main/module.json5');
28    const content = fetchDependenciesFromFile(moduleJson5Path);
29    if (!content.type) {
30        switch (content.type as string) {
31            case 'entry':
32                return ModuleCategory.ENTRY;
33            case 'feature':
34                return ModuleCategory.FEATURE;
35            case 'har':
36                return ModuleCategory.HAR;
37            case 'shared':
38                return ModuleCategory.HSP;
39            default:
40                break;
41        }
42    }
43
44    const ohPkgPath = path.join(modulePath, OH_PACKAGE_JSON5);
45    if (!fs.existsSync(ohPkgPath)) {
46        return ModuleCategory.UNKNOWN;
47    }
48    const ohPkgContent = fetchDependenciesFromFile(ohPkgPath);
49    if (ohPkgContent.packageType) {
50        return ModuleCategory.HSP;
51    } else {
52        return ModuleCategory.HAR;
53    }
54}
55