@hadss/hmrouter-plugin 1.2.3-rc.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +83 -2
  2. package/dist/HMRouterPluginManager.d.ts +1 -1
  3. package/dist/HMRouterPluginManager.js +17 -28
  4. package/dist/Index.js +6 -3
  5. package/dist/framework/constants/TaskConstants.d.ts +4 -1
  6. package/dist/framework/constants/TaskConstants.js +4 -1
  7. package/dist/framework/core/PluginExecutionController.d.ts +6 -1
  8. package/dist/framework/core/PluginExecutionController.js +70 -11
  9. package/dist/framework/core/TaskManager.d.ts +16 -0
  10. package/dist/framework/core/TaskManager.js +282 -8
  11. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +3 -2
  12. package/dist/framework/extension/context/Interface.d.ts +1 -0
  13. package/dist/framework/utils/ModuleTypeUtil.d.ts +1 -0
  14. package/dist/framework/utils/ModuleTypeUtil.js +10 -1
  15. package/dist/framework/utils/ObjectUtils.d.ts +1 -1
  16. package/dist/framework/utils/PluginStore.d.ts +1 -1
  17. package/dist/framework/utils/StringUtil.d.ts +1 -0
  18. package/dist/framework/utils/StringUtil.js +13 -0
  19. package/dist/framework/utils/index.d.ts +0 -1
  20. package/dist/framework/utils/index.js +0 -1
  21. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +1 -0
  22. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +2 -0
  23. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +11 -0
  24. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +139 -4
  25. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +14 -8
  26. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +93 -23
  27. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +10 -0
  28. package/dist/hmrouter_extension/constants/FilePathConstants.js +10 -0
  29. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +2 -0
  30. package/dist/hmrouter_extension/constants/PluginConstants.js +2 -0
  31. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +1 -0
  32. package/dist/hmrouter_extension/model/TemplateModel.d.ts +1 -1
  33. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +1 -9
  34. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +29 -148
  35. package/dist/hmrouter_extension/processor/CompletionProcessor.js +5 -5
  36. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +1 -0
  37. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +29 -2
  38. package/dist/hmrouter_extension/processor/InitializerProcessor.js +0 -10
  39. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +10 -4
  40. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +1 -0
  41. package/dist/hmrouter_extension/processor/ResourceProcessor.js +31 -19
  42. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +0 -3
  43. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +0 -81
  44. package/package.json +2 -3
  45. package/dist/framework/utils/ArkAnalyzerUtil.d.ts +0 -24
  46. package/dist/framework/utils/ArkAnalyzerUtil.js +0 -208
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.ObfuscationProcessor = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const framework_1 = require("../../framework");
5
9
  const constants_1 = require("../constants");
6
10
  class ObfuscationProcessor {
@@ -23,7 +27,7 @@ class ObfuscationProcessor {
23
27
  this.context.moduleContext?.setBuildProfileOpt(buildProfileOpt);
24
28
  }
25
29
  generateObfuscationRuleFile() {
26
- const obfuscationFilePath = framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OBFUSCATION_FILE_NAME);
30
+ const obfuscationFilePath = this.context.config.getObfuscationFilePath();
27
31
  let routerMap = [];
28
32
  if (framework_1.PluginFileUtil.exist(this.context.config.getRouterMapDir())) {
29
33
  routerMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(this.context.config.getRouterMapDir()).toString()).routerMap;
@@ -36,7 +40,7 @@ class ObfuscationProcessor {
36
40
  }
37
41
  handleHarPackageLogic(obfuscationString) {
38
42
  if (this.context.moduleContext.getModuleType() === constants_1.PluginConstants.HAR_MODULE_NAME) {
39
- const consumerRulesPath = framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.CONSUMER_FILE_NAME);
43
+ const consumerRulesPath = this.context.config.getConsumerRulesFilePath();
40
44
  framework_1.PluginFileUtil.ensureFileSync(consumerRulesPath);
41
45
  framework_1.PluginFileUtil.writeFileSync(consumerRulesPath, obfuscationString);
42
46
  }
@@ -77,10 +81,12 @@ class ObfuscationProcessor {
77
81
  return true;
78
82
  }
79
83
  addHMRouterObfuscationRules(ruleOptions, obfuscationOptions) {
80
- const obfuscationFilePath = constants_1.FilePathConstants.CURRENT_DELIMITER + constants_1.FilePathConstants.OBFUSCATION_FILE_NAME;
84
+ let obfuscationFilePath = path_1.default.relative(this.context.config.modulePath, this.context.config.getObfuscationFilePath());
85
+ obfuscationFilePath = constants_1.FilePathConstants.CURRENT_DELIMITER + obfuscationFilePath;
81
86
  ruleOptions.files = this.appendFilePathSafely(ruleOptions.files, obfuscationFilePath);
82
87
  if (this.context.moduleContext.getModuleType() === constants_1.PluginConstants.HAR_MODULE_NAME) {
83
- const consumerRulesPath = constants_1.FilePathConstants.CURRENT_DELIMITER + constants_1.FilePathConstants.CONSUMER_FILE_NAME;
88
+ let consumerRulesPath = path_1.default.relative(this.context.config.modulePath, this.context.config.getConsumerRulesFilePath());
89
+ consumerRulesPath = constants_1.FilePathConstants.CURRENT_DELIMITER + consumerRulesPath;
84
90
  obfuscationOptions.consumerFiles = this.appendFilePathSafely(obfuscationOptions.consumerFiles, consumerRulesPath);
85
91
  }
86
92
  }
@@ -1,6 +1,7 @@
1
1
  import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
2
2
  export declare class ResourceProcessProcessor {
3
3
  private context;
4
+ private rawFileContent;
4
5
  constructor(context: HMRouterExtensionContext);
5
6
  execute(): void;
6
7
  private copyRouterMapToRawFile;
@@ -5,6 +5,7 @@ const framework_1 = require("../../framework");
5
5
  const constants_1 = require("../constants");
6
6
  class ResourceProcessProcessor {
7
7
  constructor(context) {
8
+ this.rawFileContent = '';
8
9
  this.context = context;
9
10
  }
10
11
  execute() {
@@ -22,33 +23,44 @@ class ResourceProcessProcessor {
22
23
  let rawFilePath = this.context.config.getRawFilePath();
23
24
  framework_1.PluginFileUtil.ensureFileSync(rawFilePath);
24
25
  if (framework_1.PluginFileUtil.exist(routerMapFilePath)) {
25
- framework_1.PluginFileUtil.copyFileSync(routerMapFilePath, rawFilePath);
26
+ this.rawFileContent = framework_1.PluginFileUtil.readFileSync(routerMapFilePath).toString();
26
27
  }
27
- framework_1.Logger.info(this.context.node.getNodeName(), `Copy router map to raw file successfully, filePath: ${rawFilePath}`);
28
28
  }
29
29
  processHspModuleName() {
30
- if (!(0, framework_1.isHapModule)(this.context.node)) {
30
+ let rawFilePath = this.context.config.getRawFilePath();
31
+ const oldcontent = framework_1.PluginFileUtil.readFileSync(rawFilePath).toString();
32
+ let content = this.rawFileContent;
33
+ if (!content) {
34
+ framework_1.Logger.warn(this.context.node.getNodeName(), `Raw file is empty, filePath: ${rawFilePath}`);
31
35
  return;
32
36
  }
33
- let rawFilePath = this.context.config.getRawFilePath();
34
- let rawFileRouterMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(rawFilePath).toString());
35
- rawFileRouterMap.hspModuleNames = [...new Set(framework_1.PluginStore.getInstance().get('hspModuleNames'))];
36
- rawFileRouterMap.hspModuleNames.push(...this.getRemoteHspModuleNames(this.context.node.getAllPluginIds()));
37
- let hspModulesInfo = framework_1.PluginStore.getInstance().get('hspModulesInfo');
38
- if (hspModulesInfo && hspModulesInfo.length > 0) {
39
- rawFileRouterMap.hspModulesInfo = hspModulesInfo;
37
+ if ((0, framework_1.isHapModule)(this.context.node)) {
38
+ let rawFileRouterMap = JSON.parse(content);
39
+ rawFileRouterMap.hspModuleNames = [...new Set(framework_1.PluginStore.getInstance().get('hspModuleNames'))];
40
+ rawFileRouterMap.hspModuleNames.push(...this.getRemoteHspModuleNames(this.context.node.getAllPluginIds()));
41
+ let hspModulesInfo = framework_1.PluginStore.getInstance().get('hspModulesInfo');
42
+ if (hspModulesInfo && hspModulesInfo.length > 0) {
43
+ rawFileRouterMap.hspModulesInfo = hspModulesInfo;
44
+ }
45
+ else {
46
+ rawFileRouterMap.hspModulesInfo = [];
47
+ }
48
+ let remoteHspModuleNames = this.getRemoteHspModuleNames(this.context.node.getAllPluginIds());
49
+ for (const remoteName of remoteHspModuleNames) {
50
+ rawFileRouterMap.hspModulesInfo.push({
51
+ moduleName: remoteName,
52
+ packageName: remoteName,
53
+ });
54
+ }
55
+ content = JSON.stringify(rawFileRouterMap);
40
56
  }
41
- else {
42
- rawFileRouterMap.hspModulesInfo = [];
57
+ if (oldcontent !== content) {
58
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Raw file content has been updated, filePath: ${rawFilePath}`);
59
+ framework_1.PluginFileUtil.writeFileSync(rawFilePath, content);
43
60
  }
44
- let remoteHspModuleNames = this.getRemoteHspModuleNames(this.context.node.getAllPluginIds());
45
- for (const remoteName of remoteHspModuleNames) {
46
- rawFileRouterMap.hspModulesInfo.push({
47
- moduleName: remoteName,
48
- packageName: remoteName,
49
- });
61
+ else {
62
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Raw file is not changed, filePath: ${rawFilePath}`);
50
63
  }
51
- framework_1.PluginFileUtil.writeFileSync(rawFilePath, JSON.stringify(rawFileRouterMap));
52
64
  }
53
65
  getRemoteHspModuleNames(pluginIds) {
54
66
  let remoteHspModuleNames = [];
@@ -3,8 +3,5 @@ export declare class RouterMapBuildingProcessor {
3
3
  private context;
4
4
  constructor(context: HMRouterExtensionContext);
5
5
  execute(): void;
6
- private buildRouterMap;
7
- private useAnnotationConfig;
8
6
  private generateRouterMapFile;
9
- private readExistingRouterMap;
10
7
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RouterMapBuildingProcessor = void 0;
4
4
  const framework_1 = require("../../framework");
5
- const constants_1 = require("../constants");
6
5
  const PluginError_1 = require("../error/PluginError");
7
6
  class RouterMapBuildingProcessor {
8
7
  constructor(context) {
@@ -10,76 +9,13 @@ class RouterMapBuildingProcessor {
10
9
  }
11
10
  execute() {
12
11
  framework_1.Logger.debug(this.context.node.getNodeName(), `Start to build router map...`);
13
- for (const result of this.context.getAnalyzeResults()) {
14
- this.buildRouterMap(result);
15
- }
16
12
  const isHar = (0, framework_1.isHarModule)(this.context.node);
17
13
  if ((isHar && !this.context.routerMap) || (isHar && this.context.routerMap.length === 0)) {
18
14
  framework_1.Logger.info(this.context.node.getNodeName(), `Skip generating routerMap`);
19
15
  return;
20
16
  }
21
- this.readExistingRouterMap();
22
17
  this.generateRouterMapFile();
23
18
  }
24
- buildRouterMap(result) {
25
- if (!result.sourceFilePath) {
26
- throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.ERROR_PAGE_SOURCE_FILE, this.context.config.moduleName, result.sourceFilePath);
27
- }
28
- let pageSourceFile = this.context.config
29
- .getRelativeSourcePath(result.sourceFilePath)
30
- .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER);
31
- if (result.annotation === constants_1.AnnotationConstants.ROUTER_ANNOTATION) {
32
- let pageUrl = result.pageUrl;
33
- let uniqueKey = `${result.name}#${pageUrl}`;
34
- let builderPath = this.context.generatedPaths.get(uniqueKey) || '';
35
- this.context.routerMap.push({
36
- name: pageUrl,
37
- pageSourceFile: builderPath,
38
- buildFunction: result.name + 'Builder',
39
- customData: result,
40
- });
41
- return;
42
- }
43
- this.useAnnotationConfig(result, pageSourceFile);
44
- }
45
- useAnnotationConfig(result, pageSourceFile) {
46
- const annotationConfig = {
47
- [constants_1.AnnotationConstants.ANIMATOR_ANNOTATION]: {
48
- prefix: constants_1.PrefixConstants.ANIMATOR_PREFIX,
49
- propertyName: 'animatorName',
50
- resultType: 'HMAnimatorResult',
51
- },
52
- [constants_1.AnnotationConstants.INTERCEPTOR_ANNOTATION]: {
53
- prefix: constants_1.PrefixConstants.INTERCEPTOR_PREFIX,
54
- propertyName: 'interceptorName',
55
- resultType: 'HMInterceptorResult',
56
- },
57
- [constants_1.AnnotationConstants.LIFECYCLE_ANNOTATION]: {
58
- prefix: constants_1.PrefixConstants.LIFECYCLE_PREFIX,
59
- propertyName: 'lifecycleName',
60
- resultType: 'HMLifecycleResult',
61
- },
62
- [constants_1.AnnotationConstants.SERVICE_ANNOTATION]: {
63
- prefix: constants_1.PrefixConstants.SERVICE_PREFIX,
64
- propertyName: 'serviceName',
65
- resultType: 'HMServiceResult',
66
- },
67
- [constants_1.AnnotationConstants.SERVICE_PROVIDE_ANNOTATION]: {
68
- prefix: constants_1.PrefixConstants.SERVICE_PROVIDE_PREFIX,
69
- propertyName: 'serviceName',
70
- resultType: 'HMServiceResult',
71
- },
72
- };
73
- const config = annotationConfig[result.annotation];
74
- const nameValue = result[config.propertyName];
75
- const fullName = config.prefix + nameValue;
76
- this.context.routerMap.push({
77
- name: fullName,
78
- pageSourceFile: pageSourceFile,
79
- buildFunction: '',
80
- customData: result,
81
- });
82
- }
83
19
  generateRouterMapFile() {
84
20
  let set = new Set();
85
21
  this.context.routerMap.forEach((item) => {
@@ -105,22 +41,5 @@ class RouterMapBuildingProcessor {
105
41
  framework_1.PluginFileUtil.writeFileSync(routerMapFilePath, routerMapJsonStr);
106
42
  framework_1.Logger.info(this.context.node.getNodeName(), `hm_router_map.json has been generated in ${routerMapFilePath}`);
107
43
  }
108
- readExistingRouterMap() {
109
- const moduleJsonOpt = this.context.moduleContext.getModuleJsonOpt();
110
- if (!moduleJsonOpt?.module.routerMap) {
111
- framework_1.Logger.info(this.context.node.getNodeName(), `No routerMap found in the module configuration`);
112
- return;
113
- }
114
- const routerMapFileName = moduleJsonOpt.module.routerMap.split(':')[1];
115
- if (routerMapFileName !== 'hm_router_map') {
116
- const routerMapFilePath = this.context.config.getModuleRouterMapFilePath(routerMapFileName);
117
- const routerMapObj = framework_1.PluginFileUtil.readJson5(routerMapFilePath);
118
- const systemRouterMap = routerMapObj[constants_1.RouterMapConstants.ROUTER_MAP_KEY];
119
- if (systemRouterMap && systemRouterMap.length > 0) {
120
- this.context.routerMap.unshift(...systemRouterMap);
121
- framework_1.Logger.info(this.context.node.getNodeName(), `System routerMap added to the current routerMap`);
122
- }
123
- }
124
- }
125
44
  }
126
45
  exports.RouterMapBuildingProcessor = RouterMapBuildingProcessor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hadss/hmrouter-plugin",
3
- "version": "1.2.3-rc.1",
3
+ "version": "1.2.3",
4
4
  "description": "HMRouter Compiler Plugin",
5
5
  "main": "dist/Index.js",
6
6
  "scripts": {
@@ -21,8 +21,7 @@
21
21
  "dependencies": {
22
22
  "ejs": "^3.1.10",
23
23
  "micromatch": "^4.0.8",
24
- "ts-morph": "^23.0.0",
25
- "arkanalyzer": "^1.0.79"
24
+ "ts-morph": "^23.0.0"
26
25
  },
27
26
  "devDependencies": {
28
27
  "@ohos/hvigor": "^5.8.9",
@@ -1,24 +0,0 @@
1
- export declare class ArkAnalyzerUtil {
2
- private static instance;
3
- private scene;
4
- private isInitialized;
5
- private constructor();
6
- static getInstance(): ArkAnalyzerUtil;
7
- init(projectRoot: string): boolean;
8
- isReady(): boolean;
9
- findVariableFilePath(moduleName: string, variableName: string): string | undefined;
10
- private findModuleSceneByName;
11
- private getAllModuleScenes;
12
- private findInModuleScene;
13
- private findInAllFiles;
14
- private isModuleMatch;
15
- private findExportInFile;
16
- private traceToDefinition;
17
- private findFileByPath;
18
- private normalizeModuleName;
19
- clear(): void;
20
- static isReady(): boolean;
21
- static findVariableFilePath(moduleName: string, variableName: string): string | undefined;
22
- static initialize(projectRoot: string): void;
23
- static clear(): void;
24
- }
@@ -1,208 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ArkAnalyzerUtil = void 0;
7
- const arkanalyzer_1 = require("arkanalyzer");
8
- const Logger_1 = require("./Logger");
9
- const path_1 = __importDefault(require("path"));
10
- class ArkAnalyzerUtil {
11
- constructor() {
12
- this.scene = null;
13
- this.isInitialized = false;
14
- }
15
- static getInstance() {
16
- if (!ArkAnalyzerUtil.instance) {
17
- ArkAnalyzerUtil.instance = new ArkAnalyzerUtil();
18
- }
19
- return ArkAnalyzerUtil.instance;
20
- }
21
- init(projectRoot) {
22
- if (this.isInitialized) {
23
- return true;
24
- }
25
- try {
26
- this.scene = new arkanalyzer_1.Scene();
27
- const options = {
28
- supportFileExts: ['.ets', '.d.ets'],
29
- projectName: 'HMRouterProject'
30
- };
31
- const config = new arkanalyzer_1.SceneConfig(options);
32
- config.buildFromProjectDir(projectRoot);
33
- this.scene.buildSceneFromProjectDir(config);
34
- this.scene.buildScene4HarmonyProject();
35
- this.scene.inferTypes();
36
- this.isInitialized = true;
37
- Logger_1.Logger.info('ArkAnalyzerUtil', 'Initialized successfully');
38
- return true;
39
- }
40
- catch (e) {
41
- Logger_1.Logger.error('ArkAnalyzerUtil', `Failed to initialize: ${e}`);
42
- return false;
43
- }
44
- }
45
- isReady() {
46
- return this.isInitialized && this.scene !== null;
47
- }
48
- findVariableFilePath(moduleName, variableName) {
49
- if (!this.scene) {
50
- throw new Error('ArkAnalyzer scene not initialized');
51
- }
52
- const moduleScene = this.findModuleSceneByName(moduleName);
53
- if (moduleScene) {
54
- const result = this.findInModuleScene(moduleScene, variableName);
55
- if (result) {
56
- return result;
57
- }
58
- }
59
- return this.findInAllFiles(moduleName, variableName);
60
- }
61
- findModuleSceneByName(moduleName) {
62
- if (!this.scene) {
63
- return undefined;
64
- }
65
- let moduleScene = this.scene.getModuleScene(moduleName);
66
- if (moduleScene) {
67
- return moduleScene;
68
- }
69
- const allScenes = this.getAllModuleScenes();
70
- moduleScene = allScenes.find(scene => scene.getModuleName().toLowerCase() === moduleName.toLowerCase());
71
- if (moduleScene) {
72
- return moduleScene;
73
- }
74
- const normalizedModuleName = this.normalizeModuleName(moduleName);
75
- if (normalizedModuleName !== moduleName) {
76
- moduleScene = allScenes.find(scene => {
77
- const sceneName = scene.getModuleName();
78
- const normalizedSceneName = this.normalizeModuleName(sceneName);
79
- return normalizedSceneName.toLowerCase() === normalizedModuleName.toLowerCase();
80
- });
81
- }
82
- return moduleScene;
83
- }
84
- getAllModuleScenes() {
85
- if (!this.scene) {
86
- return [];
87
- }
88
- const scenes = [];
89
- const files = this.scene.getFiles();
90
- const seenScenes = new Set();
91
- for (const file of files) {
92
- const moduleScene = file.getModuleScene();
93
- if (moduleScene && !seenScenes.has(moduleScene)) {
94
- seenScenes.add(moduleScene);
95
- scenes.push(moduleScene);
96
- }
97
- }
98
- return scenes;
99
- }
100
- findInModuleScene(moduleScene, variableName) {
101
- const filesMap = moduleScene.getModuleFilesMap();
102
- for (const [, arkFile] of filesMap) {
103
- const exportInfos = arkFile.getExportInfos();
104
- for (const exportInfo of exportInfos) {
105
- if (exportInfo.getExportClauseName() === variableName) {
106
- return this.traceToDefinition(exportInfo, arkFile);
107
- }
108
- }
109
- }
110
- return undefined;
111
- }
112
- findInAllFiles(moduleName, variableName) {
113
- const normalizedModuleName = this.normalizeModuleName(moduleName);
114
- const files = this.scene.getFiles();
115
- for (const arkFile of files) {
116
- if (!this.isModuleMatch(arkFile, moduleName, normalizedModuleName)) {
117
- continue;
118
- }
119
- const result = this.findExportInFile(arkFile, variableName);
120
- if (result) {
121
- return result;
122
- }
123
- }
124
- return undefined;
125
- }
126
- isModuleMatch(arkFile, moduleName, normalizedModuleName) {
127
- const fileModuleName = arkFile.getModuleName() || arkFile.getModuleScene()?.getModuleName() || '';
128
- const normalizedFileModule = this.normalizeModuleName(fileModuleName);
129
- if (fileModuleName === moduleName) {
130
- return true;
131
- }
132
- if (fileModuleName.toLowerCase() === moduleName.toLowerCase()) {
133
- return true;
134
- }
135
- if (normalizedFileModule.toLowerCase() === normalizedModuleName.toLowerCase()) {
136
- return true;
137
- }
138
- return false;
139
- }
140
- findExportInFile(arkFile, variableName) {
141
- const exportInfos = arkFile.getExportInfos();
142
- for (const exportInfo of exportInfos) {
143
- if (exportInfo.getExportClauseName() === variableName) {
144
- return this.traceToDefinition(exportInfo, arkFile);
145
- }
146
- }
147
- return undefined;
148
- }
149
- traceToDefinition(exportInfo, currentFile) {
150
- const fromPath = exportInfo.getFrom();
151
- if (!fromPath) {
152
- return currentFile.getFilePath();
153
- }
154
- const currentDir = path_1.default.dirname(currentFile.getFilePath());
155
- let targetPath = path_1.default.resolve(currentDir, fromPath);
156
- if (!targetPath.endsWith('.ets') && !targetPath.endsWith('.d.ets')) {
157
- targetPath += '.ets';
158
- }
159
- const targetFile = this.findFileByPath(targetPath);
160
- if (!targetFile) {
161
- return currentFile.getFilePath();
162
- }
163
- const variableName = exportInfo.getNameBeforeAs() || exportInfo.getExportClauseName();
164
- const targetExports = targetFile.getExportInfos();
165
- for (const targetExport of targetExports) {
166
- if (targetExport.getExportClauseName() === variableName) {
167
- return this.traceToDefinition(targetExport, targetFile);
168
- }
169
- }
170
- return targetFile.getFilePath();
171
- }
172
- findFileByPath(filePath) {
173
- const files = this.scene.getFiles();
174
- for (const arkFile of files) {
175
- if (arkFile.getFilePath() === filePath) {
176
- return arkFile;
177
- }
178
- }
179
- return undefined;
180
- }
181
- normalizeModuleName(moduleName) {
182
- if (moduleName.startsWith('@')) {
183
- const parts = moduleName.split('/');
184
- return parts.length >= 2 ? parts[1] : moduleName;
185
- }
186
- return moduleName;
187
- }
188
- clear() {
189
- if (this.scene) {
190
- this.scene.dispose();
191
- this.scene = null;
192
- }
193
- this.isInitialized = false;
194
- }
195
- static isReady() {
196
- return ArkAnalyzerUtil.getInstance().isReady();
197
- }
198
- static findVariableFilePath(moduleName, variableName) {
199
- return ArkAnalyzerUtil.getInstance().findVariableFilePath(moduleName, variableName);
200
- }
201
- static initialize(projectRoot) {
202
- ArkAnalyzerUtil.getInstance().init(projectRoot);
203
- }
204
- static clear() {
205
- ArkAnalyzerUtil.getInstance().clear();
206
- }
207
- }
208
- exports.ArkAnalyzerUtil = ArkAnalyzerUtil;