@hadss/hmrouter-plugin 1.0.0-rc.9 → 1.1.1-alpha.0

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 (147) hide show
  1. package/LICENSE +176 -77
  2. package/NOTICE +1365 -0
  3. package/README.md +254 -71
  4. package/dist/HMRouterAnalyzer.d.ts +24 -1
  5. package/dist/HMRouterAnalyzer.js +154 -55
  6. package/dist/HMRouterHvigorPlugin.js +23 -4
  7. package/dist/HMRouterPluginConfig.d.ts +1 -0
  8. package/dist/HMRouterPluginConfig.js +7 -3
  9. package/dist/HMRouterPluginHandle.d.ts +1 -0
  10. package/dist/HMRouterPluginHandle.js +81 -55
  11. package/dist/HMRouterPluginManager.d.ts +9 -0
  12. package/dist/HMRouterPluginManager.js +55 -0
  13. package/dist/Index.d.ts +9 -3
  14. package/dist/Index.js +33 -103
  15. package/dist/common/Logger.js +1 -1
  16. package/dist/common/PluginModel.d.ts +4 -1
  17. package/dist/common/PluginModel.js +2 -1
  18. package/dist/constants/CommonConstants.d.ts +10 -5
  19. package/dist/constants/CommonConstants.js +11 -6
  20. package/dist/constants/ConfigConstants.d.ts +2 -1
  21. package/dist/constants/ConfigConstants.js +3 -2
  22. package/dist/constants/TaskConstants.js +1 -1
  23. package/dist/framework/constants/TaskConstants.d.ts +8 -0
  24. package/dist/framework/constants/TaskConstants.js +12 -0
  25. package/dist/framework/constants/index.d.ts +1 -0
  26. package/dist/framework/constants/index.js +17 -0
  27. package/dist/framework/core/PluginExecutionController.d.ts +15 -0
  28. package/dist/framework/core/PluginExecutionController.js +62 -0
  29. package/dist/framework/core/TaskManager.d.ts +12 -0
  30. package/dist/framework/core/TaskManager.js +67 -0
  31. package/dist/framework/core/TaskStage.d.ts +10 -0
  32. package/dist/framework/core/TaskStage.js +14 -0
  33. package/dist/framework/core/index.d.ts +3 -0
  34. package/dist/framework/core/index.js +19 -0
  35. package/dist/framework/extension/ExtensionManager.d.ts +11 -0
  36. package/dist/framework/extension/ExtensionManager.js +33 -0
  37. package/dist/framework/extension/PluginExtension.d.ts +13 -0
  38. package/dist/framework/extension/PluginExtension.js +6 -0
  39. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +23 -0
  40. package/dist/framework/extension/context/ExtensionContextImpl.js +64 -0
  41. package/dist/framework/extension/context/Interface.d.ts +21 -0
  42. package/dist/framework/extension/context/Interface.js +2 -0
  43. package/dist/framework/extension/context/TemplateMetadataImpl.d.ts +12 -0
  44. package/dist/framework/extension/context/TemplateMetadataImpl.js +22 -0
  45. package/dist/framework/extension/index.d.ts +4 -0
  46. package/dist/framework/extension/index.js +20 -0
  47. package/dist/framework/index.d.ts +4 -0
  48. package/dist/framework/index.js +20 -0
  49. package/dist/framework/utils/FileUtil.d.ts +13 -0
  50. package/dist/framework/utils/FileUtil.js +20 -0
  51. package/dist/framework/utils/Logger.d.ts +12 -0
  52. package/dist/framework/utils/Logger.js +31 -0
  53. package/dist/framework/utils/ModuleTypeUtil.d.ts +4 -0
  54. package/dist/framework/utils/ModuleTypeUtil.js +16 -0
  55. package/dist/framework/utils/ObjectUtils.d.ts +3 -0
  56. package/dist/framework/utils/ObjectUtils.js +14 -0
  57. package/dist/framework/utils/PluginStore.d.ts +10 -0
  58. package/dist/framework/utils/PluginStore.js +29 -0
  59. package/dist/framework/utils/StringUtil.d.ts +3 -0
  60. package/dist/framework/utils/StringUtil.js +18 -0
  61. package/dist/framework/utils/TsAstUtil.d.ts +6 -0
  62. package/dist/framework/utils/TsAstUtil.js +19 -0
  63. package/dist/framework/utils/index.d.ts +7 -0
  64. package/dist/framework/utils/index.js +23 -0
  65. package/dist/hmrouter_extension/HMRouterExtension.d.ts +14 -0
  66. package/dist/hmrouter_extension/HMRouterExtension.js +47 -0
  67. package/dist/hmrouter_extension/HMRouterExtensionContext.d.ts +8 -0
  68. package/dist/hmrouter_extension/HMRouterExtensionContext.js +2 -0
  69. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +14 -0
  70. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +45 -0
  71. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.d.ts +12 -0
  72. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.js +52 -0
  73. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.d.ts +11 -0
  74. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +79 -0
  75. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.d.ts +9 -0
  76. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.js +9 -0
  77. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +7 -0
  78. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.js +2 -0
  79. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.d.ts +9 -0
  80. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.js +32 -0
  81. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +15 -0
  82. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +217 -0
  83. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.d.ts +7 -0
  84. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.js +41 -0
  85. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.d.ts +4 -0
  86. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.js +35 -0
  87. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +38 -0
  88. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +64 -0
  89. package/dist/hmrouter_extension/constants/AnnotationConstants.d.ts +8 -0
  90. package/dist/hmrouter_extension/constants/AnnotationConstants.js +11 -0
  91. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +19 -0
  92. package/dist/hmrouter_extension/constants/FilePathConstants.js +26 -0
  93. package/dist/hmrouter_extension/constants/ObfuscationConstants.d.ts +5 -0
  94. package/dist/hmrouter_extension/constants/ObfuscationConstants.js +8 -0
  95. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +6 -0
  96. package/dist/hmrouter_extension/constants/PluginConstants.js +9 -0
  97. package/dist/hmrouter_extension/constants/PrefixConstants.d.ts +8 -0
  98. package/dist/hmrouter_extension/constants/PrefixConstants.js +11 -0
  99. package/dist/hmrouter_extension/constants/RouterMapConstants.d.ts +5 -0
  100. package/dist/hmrouter_extension/constants/RouterMapConstants.js +8 -0
  101. package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +6 -0
  102. package/dist/hmrouter_extension/constants/TemplateConstants.js +9 -0
  103. package/dist/hmrouter_extension/constants/VersionConstants.d.ts +6 -0
  104. package/dist/hmrouter_extension/constants/VersionConstants.js +9 -0
  105. package/dist/hmrouter_extension/constants/index.d.ts +8 -0
  106. package/dist/hmrouter_extension/constants/index.js +22 -0
  107. package/dist/hmrouter_extension/error/PluginError.d.ts +29 -0
  108. package/dist/hmrouter_extension/error/PluginError.js +75 -0
  109. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +28 -0
  110. package/dist/hmrouter_extension/model/HMAnnotationModel.js +2 -0
  111. package/dist/hmrouter_extension/model/RouterInfo.d.ts +6 -0
  112. package/dist/hmrouter_extension/model/RouterInfo.js +2 -0
  113. package/dist/hmrouter_extension/model/TemplateModel.d.ts +8 -0
  114. package/dist/hmrouter_extension/model/TemplateModel.js +2 -0
  115. package/dist/hmrouter_extension/model/index.d.ts +3 -0
  116. package/dist/hmrouter_extension/model/index.js +19 -0
  117. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +13 -0
  118. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +117 -0
  119. package/dist/hmrouter_extension/processor/CompletionProcessor.d.ts +11 -0
  120. package/dist/hmrouter_extension/processor/CompletionProcessor.js +59 -0
  121. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +11 -0
  122. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +53 -0
  123. package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +15 -0
  124. package/dist/hmrouter_extension/processor/InitializerProcessor.js +95 -0
  125. package/dist/hmrouter_extension/processor/ObfuscationProcessor.d.ts +13 -0
  126. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +121 -0
  127. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +9 -0
  128. package/dist/hmrouter_extension/processor/ResourceProcessor.js +53 -0
  129. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +9 -0
  130. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +122 -0
  131. package/dist/hmrouter_extension/processor/index.d.ts +7 -0
  132. package/dist/hmrouter_extension/processor/index.js +23 -0
  133. package/dist/store/PluginStore.d.ts +14 -0
  134. package/dist/store/PluginStore.js +20 -0
  135. package/dist/utils/FileUtil.d.ts +2 -0
  136. package/dist/utils/ObfuscationUtil.js +7 -1
  137. package/dist/utils/TsAstUtil.d.ts +3 -2
  138. package/dist/utils/TsAstUtil.js +51 -11
  139. package/examples/CustomExtension.ts +256 -0
  140. package/package.json +8 -7
  141. package/template/customBuilder.ejs +25 -0
  142. package/template/viewBuilder.ejs +51 -0
  143. package/{viewBuilder.ejs → template/viewBuilder_v1.ejs} +11 -4
  144. package/dist/common/Constant.d.ts +0 -27
  145. package/dist/common/Constant.js +0 -35
  146. package/dist/utils/ConfusionUtil.d.ts +0 -4
  147. package/dist/utils/ConfusionUtil.js +0 -27
@@ -3,12 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AnalyzerController = void 0;
6
+ exports.AnalyzerService = exports.AnalyzerController = void 0;
7
7
  const ts_morph_1 = require("ts-morph");
8
8
  const Logger_1 = require("./common/Logger");
9
- const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
10
9
  const TsAstUtil_1 = require("./utils/TsAstUtil");
10
+ const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
11
11
  const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
12
+ const ConfigConstants_1 = __importDefault(require("./constants/ConfigConstants"));
13
+ const PluginStore_1 = __importDefault(require("./store/PluginStore"));
12
14
  class AnalyzerController {
13
15
  constructor() {
14
16
  this.analyzeResult = new Set();
@@ -20,31 +22,55 @@ class AnalyzerController {
20
22
  item.pageSourceFile = sourceFilePath;
21
23
  this.analyzeResult.add(item);
22
24
  });
23
- this.parsePageUrl();
25
+ this.parseConstants();
24
26
  }
25
- parsePageUrl() {
27
+ parseConstants() {
26
28
  this.analyzeResult.forEach((item) => {
27
- if (item.annotation !== 'HMRouter') {
28
- return;
29
+ Object.getOwnPropertyNames(item).forEach((key) => {
30
+ let propertyValue = Reflect.get(item, key);
31
+ propertyValue = this.parsePropertyValue(propertyValue);
32
+ if (propertyValue === '') {
33
+ Logger_1.Logger.error(Logger_1.PluginError.ERR_NOT_EMPTY_STRING);
34
+ throw new Error('constants value cannot be an empty string, filePath:' + item.pageSourceFile);
35
+ }
36
+ Reflect.set(item, key, propertyValue);
37
+ });
38
+ });
39
+ }
40
+ parsePropertyValue(propertyValue) {
41
+ if (propertyValue.type === 'constant') {
42
+ try {
43
+ return TsAstUtil_1.TsAstUtil.parseConstantValue(TsAstUtil_1.TsAstUtil.getSourceFile(propertyValue.variableFilePath), propertyValue.variableName);
29
44
  }
30
- let pageUrl = item.pageUrl;
31
- if (pageUrl.type === 'constant') {
32
- pageUrl =
33
- TsAstUtil_1.TsAstUtil.parseConstantValue(TsAstUtil_1.project.addSourceFileAtPath(pageUrl.variableFilePath), pageUrl.variableName);
45
+ catch (error) {
46
+ Logger_1.Logger.error(`Failed to parse constant ${propertyValue.variableName}: ${error.message}`);
47
+ throw new Error(`Failed to parse constant ${propertyValue.variableName}: ${error.message}`);
34
48
  }
35
- else if (pageUrl.type === 'object') {
36
- pageUrl = TsAstUtil_1.TsAstUtil.parseConstantValue(TsAstUtil_1.project.addSourceFileAtPath(pageUrl.variableFilePath), pageUrl.variableName, pageUrl.propertyName);
49
+ }
50
+ else if (propertyValue.type === 'object') {
51
+ try {
52
+ return TsAstUtil_1.TsAstUtil.parseConstantValue(TsAstUtil_1.TsAstUtil.getSourceFile(propertyValue.variableFilePath), propertyValue.variableName, propertyValue.propertyName);
37
53
  }
38
- if (pageUrl === '') {
39
- Logger_1.Logger.error(Logger_1.PluginError.ERR_NOT_EMPTY_STRING);
40
- throw new Error('constant value cannot be an empty string');
54
+ catch (error) {
55
+ Logger_1.Logger.error(`Failed to parse object property ${propertyValue.variableName}.${propertyValue.propertyName}: ${error.message}`);
56
+ throw new Error(`Failed to parse object property ${propertyValue.variableName}.${propertyValue.propertyName}: ${error.message}`);
41
57
  }
42
- item.pageUrl = pageUrl;
43
- });
58
+ }
59
+ else if (propertyValue.type === 'array') {
60
+ return propertyValue.value.map((item) => {
61
+ return this.parsePropertyValue(item);
62
+ });
63
+ }
64
+ else {
65
+ return propertyValue;
66
+ }
44
67
  }
45
68
  getAnalyzeResultSet() {
46
69
  return this.analyzeResult;
47
70
  }
71
+ clearAnalyzeResultSet() {
72
+ this.analyzeResult.clear();
73
+ }
48
74
  }
49
75
  exports.AnalyzerController = AnalyzerController;
50
76
  class AnalyzerService {
@@ -75,9 +101,9 @@ class AnalyzerService {
75
101
  return this.analyzerResultSet;
76
102
  }
77
103
  analyzeImport() {
78
- this.sourceFile.getImportDeclarations().forEach(importDeclaration => {
104
+ this.sourceFile.getImportDeclarations().forEach((importDeclaration) => {
79
105
  const moduleSpecifier = importDeclaration.getModuleSpecifierValue();
80
- const namedImports = importDeclaration.getNamedImports().map(namedImport => namedImport.getName());
106
+ const namedImports = importDeclaration.getNamedImports().map((namedImport) => namedImport.getName());
81
107
  const defaultImport = importDeclaration.getDefaultImport()?.getText();
82
108
  const namespaceImport = importDeclaration.getNamespaceImport()?.getText();
83
109
  const importNames = [];
@@ -91,20 +117,23 @@ class AnalyzerService {
91
117
  importNames.push(namespaceImport);
92
118
  }
93
119
  if (importNames.length > 0) {
94
- let variableFilePath = FileUtil_1.default.pathResolve(this.config.modulePath, moduleSpecifier);
95
- importNames.forEach((item) => {
96
- if (FileUtil_1.default.exist(variableFilePath)) {
97
- TsAstUtil_1.importVariableCache.set(variableFilePath + CommonConstants_1.default.VARIABLE_SEPARATOR + item, '');
98
- }
99
- });
100
- this.importMap.set(moduleSpecifier, importNames);
120
+ if (this.importMap.has(moduleSpecifier)) {
121
+ const existingImports = this.importMap.get(moduleSpecifier);
122
+ this.importMap.set(moduleSpecifier, [...new Set([...existingImports, ...importNames])]);
123
+ }
124
+ else {
125
+ this.importMap.set(moduleSpecifier, importNames);
126
+ }
101
127
  }
102
128
  });
103
129
  }
104
130
  analyzeRouter() {
105
- let viewNameArr = this.sourceFile.getChildrenOfKind(ts_morph_1.SyntaxKind.ExpressionStatement).map((node) => {
131
+ let viewNameArr = this.sourceFile
132
+ .getChildrenOfKind(ts_morph_1.SyntaxKind.ExpressionStatement)
133
+ .map((node) => {
106
134
  return node.getText();
107
- }).filter((text) => {
135
+ })
136
+ .filter((text) => {
108
137
  return text != 'struct';
109
138
  });
110
139
  this.sourceFile.getChildrenOfKind(ts_morph_1.SyntaxKind.MissingDeclaration).forEach((node, index) => {
@@ -112,23 +141,42 @@ class AnalyzerService {
112
141
  this.addToResultSet(decorator, viewNameArr[index]);
113
142
  });
114
143
  });
144
+ this.sourceFile.getExportAssignments().forEach((exportAssignment, index) => {
145
+ exportAssignment.getDescendantsOfKind(ts_morph_1.SyntaxKind.Decorator).forEach((decorator) => {
146
+ let result = this.addToResultSet(decorator, viewNameArr[index]);
147
+ result.isDefaultExport = true;
148
+ });
149
+ });
115
150
  }
116
151
  parseFileByLineOrder() {
117
152
  const statements = this.sourceFile.getStatements();
118
153
  const sortedStatements = statements.sort((a, b) => a.getStart() - b.getStart());
119
154
  let HMRouterExists = false;
120
- sortedStatements.forEach(statement => {
155
+ let useNavDst = false;
156
+ sortedStatements.forEach((statement) => {
121
157
  if (statement.getKind() === ts_morph_1.SyntaxKind.MissingDeclaration && statement.getText().includes('HMRouter')) {
122
158
  HMRouterExists = true;
159
+ useNavDst = false;
160
+ const text = statement.getText();
161
+ if (/(useNavDst\s*:\s*true)/.test(text)) {
162
+ useNavDst = true;
163
+ Logger_1.Logger.info('Found HMRouter with useNavDst=true, skipping NavDestination check');
164
+ }
123
165
  }
124
166
  if (statement.getKind() === ts_morph_1.SyntaxKind.Block && HMRouterExists) {
125
167
  HMRouterExists = false;
126
- statement.getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier).forEach((node) => {
127
- if (node.getText() === 'NavDestination') {
128
- Logger_1.Logger.error(Logger_1.PluginError.ERR_WRONG_DECORATION);
129
- throw new Error('NavDestination is not allowed in HMRouter, filePath:' + this.sourceFilePath);
130
- }
131
- });
168
+ if (useNavDst) {
169
+ return;
170
+ }
171
+ let reg = new RegExp(/NavDestination\s*\(\s*\)/);
172
+ let text = statement.getText();
173
+ const cleanedCodeBlock = text
174
+ .replace(/(["'`]).*?\1/g, '')
175
+ .replace(/\/\/.*|\/\*[\s\S]*?\*\//g, '');
176
+ if (reg.test(cleanedCodeBlock)) {
177
+ Logger_1.Logger.error(Logger_1.PluginError.ERR_WRONG_DECORATION);
178
+ throw new Error('NavDestination is not allowed in HMRouter, filePath:' + this.sourceFilePath);
179
+ }
132
180
  }
133
181
  });
134
182
  }
@@ -167,45 +215,57 @@ class AnalyzerService {
167
215
  }
168
216
  parseDecoratorArguments(decorator) {
169
217
  let argResult = {};
170
- decorator.getArguments().map(arg => {
218
+ decorator.getArguments().map((arg) => {
171
219
  const objLiteral = arg.asKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
172
220
  if (objLiteral) {
173
221
  objLiteral.getProperties().forEach((prop) => {
174
222
  let propertyName = prop.getName();
175
- let propertyValue = propertyName === CommonConstants_1.default.PAGE_URL ?
176
- this.parsePageUrlValue(prop.getInitializer()) :
177
- this.parsePropertyValue(prop.getInitializer());
223
+ let propertyValue = this.parseIdentifierPropertyValue(prop.getInitializer());
178
224
  Reflect.set(argResult, propertyName, propertyValue);
179
225
  });
180
226
  }
181
227
  });
182
228
  return argResult;
183
229
  }
184
- parsePageUrlValue(value) {
230
+ parseIdentifierPropertyValue(value) {
185
231
  switch (value.getKind()) {
186
232
  case ts_morph_1.SyntaxKind.Identifier:
233
+ if (value.getText() === 'undefined') {
234
+ throw new Error(`Invalid property value, in ${this.sourceFilePath}`);
235
+ }
187
236
  return {
188
237
  type: 'constant',
189
238
  variableName: value.getText(),
190
- variableFilePath: this.getVariableFilePath(value.getText())
239
+ variableFilePath: this.getVariableFilePath(value.getText()),
191
240
  };
192
241
  case ts_morph_1.SyntaxKind.PropertyAccessExpression:
193
242
  return {
194
243
  type: 'object',
195
244
  variableName: value.getExpression().getText(),
196
245
  propertyName: value?.getName(),
197
- variableFilePath: this.getVariableFilePath(value?.getExpression().getText())
246
+ variableFilePath: this.getVariableFilePath(value?.getExpression().getText()),
247
+ };
248
+ case ts_morph_1.SyntaxKind.ArrayLiteralExpression:
249
+ return {
250
+ type: 'array',
251
+ value: value
252
+ .asKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression)
253
+ ?.getElements()
254
+ .map((item) => this.parseIdentifierPropertyValue(item)),
198
255
  };
199
256
  default:
200
- return this.parsePropertyValue(value);
257
+ return this.parsePrimitiveValue(value);
201
258
  }
202
259
  }
203
- parsePropertyValue(value) {
260
+ parsePrimitiveValue(value) {
204
261
  let propertyValue;
205
262
  switch (value.getKind()) {
206
263
  case ts_morph_1.SyntaxKind.StringLiteral:
207
264
  propertyValue = value.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue();
208
265
  break;
266
+ case ts_morph_1.SyntaxKind.NumericLiteral:
267
+ propertyValue = value.asKind(ts_morph_1.SyntaxKind.NumericLiteral)?.getLiteralValue();
268
+ break;
209
269
  case ts_morph_1.SyntaxKind.TrueKeyword:
210
270
  propertyValue = true;
211
271
  break;
@@ -213,13 +273,16 @@ class AnalyzerService {
213
273
  propertyValue = false;
214
274
  break;
215
275
  case ts_morph_1.SyntaxKind.ArrayLiteralExpression:
216
- propertyValue = value.asKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression)?.getElements()
217
- .map(item => item.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue());
276
+ propertyValue = value
277
+ .asKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression)
278
+ ?.getElements()
279
+ .map((item) => item.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue());
218
280
  break;
219
281
  }
220
282
  return propertyValue;
221
283
  }
222
284
  getVariableFilePath(variableName) {
285
+ let filePath = '';
223
286
  let classesNames = this.sourceFile.getClasses().map((classes) => {
224
287
  return classes.getName();
225
288
  });
@@ -229,16 +292,52 @@ class AnalyzerService {
229
292
  if (classesNames.includes(variableName) || variableNames.includes(variableName)) {
230
293
  return this.sourceFilePath;
231
294
  }
232
- else {
233
- let filePath = '';
234
- this.importMap.forEach((value, key) => {
235
- if (value.includes(variableName)) {
236
- filePath =
237
- FileUtil_1.default.pathResolve(this.sourceFilePath.split(CommonConstants_1.default.FILE_SEPARATOR).slice(0, -1)
238
- .join(CommonConstants_1.default.FILE_SEPARATOR), key) + CommonConstants_1.default.VIEW_NAME_SUFFIX;
295
+ for (const [importPath, importNames] of this.importMap.entries()) {
296
+ if (importNames.includes(variableName)) {
297
+ try {
298
+ let currentDir = FileUtil_1.default.pathResolve(this.sourceFilePath, CommonConstants_1.default.PARENT_DELIMITER);
299
+ let tempFilePath = FileUtil_1.default.pathResolve(currentDir, importPath + CommonConstants_1.default.ETS_SUFFIX);
300
+ if (FileUtil_1.default.exist(tempFilePath)) {
301
+ filePath = tempFilePath;
302
+ }
303
+ else {
304
+ try {
305
+ filePath = this.getOtherModuleVariableFilePath(importPath, variableName);
306
+ }
307
+ catch (error) {
308
+ Logger_1.Logger.warn(`Cannot find variable ${variableName} in module ${importPath}: ${error.message}`);
309
+ }
310
+ }
239
311
  }
240
- });
241
- return filePath;
312
+ catch (error) {
313
+ Logger_1.Logger.warn(`Error parsing import path ${importPath}: ${error.message}`);
314
+ }
315
+ }
316
+ }
317
+ if (!filePath) {
318
+ Logger_1.Logger.warn(`Cannot find file path for variable ${variableName}`);
319
+ }
320
+ return filePath;
321
+ }
322
+ getOtherModuleVariableFilePath(moduleName, variableName) {
323
+ let moduleFilePath = FileUtil_1.default.pathResolve(this.config.modulePath, CommonConstants_1.default.OH_MODULE_PATH, moduleName, ConfigConstants_1.default.DEFAULT_SCAN_DIR);
324
+ if (!FileUtil_1.default.exist(moduleFilePath)) {
325
+ moduleFilePath = FileUtil_1.default.pathResolve(PluginStore_1.default.getInstance().projectFilePath, CommonConstants_1.default.OH_MODULE_PATH, moduleName, ConfigConstants_1.default.DEFAULT_SCAN_DIR);
326
+ }
327
+ let variableMap;
328
+ if (PluginStore_1.default.getInstance().variableCache.has(moduleName)) {
329
+ variableMap = PluginStore_1.default.getInstance().variableCache.get(moduleName);
330
+ }
331
+ else {
332
+ variableMap = TsAstUtil_1.TsAstUtil.parseCrossModuleVariable(moduleFilePath);
333
+ PluginStore_1.default.getInstance().variableCache.set(moduleName, variableMap);
334
+ }
335
+ for (let [key, value] of variableMap) {
336
+ if (value.includes(variableName)) {
337
+ return key;
338
+ }
242
339
  }
340
+ throw new Error(`Unknown variable ${variableName} in ${moduleName}`);
243
341
  }
244
342
  }
343
+ exports.AnalyzerService = AnalyzerService;
@@ -26,7 +26,7 @@ class HMRouterHvigorPlugin {
26
26
  });
27
27
  Logger_1.Logger.info(`Scanned ${this.scanFiles.length} files`, this.scanFiles);
28
28
  this.scanFiles.forEach((filePath) => {
29
- if (filePath.endsWith(CommonConstants_1.default.VIEW_NAME_SUFFIX)) {
29
+ if (filePath.endsWith(CommonConstants_1.default.ETS_SUFFIX)) {
30
30
  this.analyzerController.analyzeFile(filePath, this.config);
31
31
  }
32
32
  });
@@ -50,15 +50,17 @@ class HMRouterHvigorPlugin {
50
50
  if (item.customData && item.customData.annotation) {
51
51
  delete item.customData.annotation;
52
52
  delete item.customData.pageSourceFile;
53
+ delete item.customData.isDefaultExport;
53
54
  }
54
55
  return item;
55
- }),
56
+ })
56
57
  };
57
58
  const routerMapJsonStr = JSON.stringify(routerMap, null, 2);
58
59
  const routerMapFilePath = this.config.getRouterMapDir();
59
60
  FileUtil_1.default.ensureFileSync(routerMapFilePath);
60
61
  FileUtil_1.default.writeFileSync(routerMapFilePath, routerMapJsonStr);
61
62
  Logger_1.Logger.info(`hm_router_map.json has been generated in ${routerMapFilePath}`);
63
+ this.analyzerController.clearAnalyzeResultSet();
62
64
  }
63
65
  matchedPath(filePath, customPageTemplate, defaultTplFilePath) {
64
66
  for (const template of customPageTemplate) {
@@ -94,17 +96,34 @@ class HMRouterHvigorPlugin {
94
96
  let serviceName = CommonConstants_1.default.SERVICE_PREFIX + analyzeResult.serviceName;
95
97
  this.routerMap.push(new PluginModel_1.RouterInfo(serviceName, pageSourceFile, '', analyzeResult));
96
98
  break;
99
+ case CommonConstants_1.default.SERVICE_PROVIDE_ANNOTATION:
100
+ let className = CommonConstants_1.default.SERVICE_PROVIDE_PREFIX + analyzeResult.serviceName;
101
+ this.routerMap.push(new PluginModel_1.RouterInfo(className, pageSourceFile, '', analyzeResult));
102
+ break;
97
103
  }
98
104
  }
99
105
  generateBuilder(analyzeResult, pageSourceFile, tempFilePath) {
100
106
  let importPath = this.config
101
107
  .getRelativeBuilderPath(pageSourceFile)
102
108
  .replaceAll(CommonConstants_1.default.FILE_SEPARATOR, CommonConstants_1.default.DELIMITER)
103
- .replaceAll(CommonConstants_1.default.VIEW_NAME_SUFFIX, '');
109
+ .replaceAll(CommonConstants_1.default.ETS_SUFFIX, '');
104
110
  let generatorViewName = CommonConstants_1.default.VIEW_NAME_PREFIX +
105
111
  analyzeResult.name +
106
112
  StringUtil_1.StringUtil.stringToHashCode(analyzeResult.pageUrl);
107
- const templateModel = new PluginModel_1.TemplateModel(analyzeResult.pageUrl, importPath, analyzeResult.name, !!analyzeResult.dialog, generatorViewName);
113
+ const templateModel = new PluginModel_1.TemplateModel(analyzeResult.pageUrl, importPath, analyzeResult.name, !!analyzeResult.dialog, generatorViewName, analyzeResult.isDefaultExport);
114
+ if (analyzeResult.useNavDst === true) {
115
+ Logger_1.Logger.info(`Using custom template for ${analyzeResult.name} with useNavDst=true`);
116
+ const customTplPath = FileUtil_1.default.pathResolve(__dirname, CommonConstants_1.default.PARENT_DELIMITER + CommonConstants_1.default.CUSTOM_BUILDER_TEMPLATE);
117
+ if (FileUtil_1.default.exist(customTplPath)) {
118
+ tempFilePath = customTplPath;
119
+ }
120
+ else {
121
+ Logger_1.Logger.info(`Custom template not found at ${customTplPath}, falling back to default template`);
122
+ }
123
+ }
124
+ if (!FileUtil_1.default.exist(tempFilePath)) {
125
+ throw new Error('Invalid template path: ' + tempFilePath);
126
+ }
108
127
  const tpl = FileUtil_1.default.readFileSync(tempFilePath).toString();
109
128
  const templateStr = ejs_1.default.render(tpl, templateModel);
110
129
  const generatorFilePath = this.config.getGeneratedFilePath(templateModel.generatorViewName);
@@ -22,6 +22,7 @@ export declare class HMRouterPluginConfig {
22
22
  getRawFilePath(): string;
23
23
  getDefaultTplFilePath(): string;
24
24
  getObfuscationFilePath(): string;
25
+ getConsumerRulesFilePath(): string;
25
26
  }
26
27
  export interface HMRouterPluginConfigParam {
27
28
  scanDir?: string[];
@@ -21,7 +21,8 @@ class HMRouterPluginConfig {
21
21
  ConfigConstants_1.default.ANIMATOR_ANNOTATION,
22
22
  ConfigConstants_1.default.INTERCEPTOR_ANNOTATION,
23
23
  ConfigConstants_1.default.LIFECYCLE_ANNOTATION,
24
- ConfigConstants_1.default.SERVICE_ANNOTATION
24
+ ConfigConstants_1.default.SERVICE_ANNOTATION,
25
+ ConfigConstants_1.default.SERVICE_PROVIDE_ANNOTATION
25
26
  ];
26
27
  this.defaultPageTemplate =
27
28
  param.defaultPageTemplate ? param.defaultPageTemplate : ConfigConstants_1.default.DEFAULT_BUILD_TPL;
@@ -39,13 +40,13 @@ class HMRouterPluginConfig {
39
40
  return path_1.default.relative(this.builderDir, filePath);
40
41
  }
41
42
  getGeneratedFilePath(generatorViewName) {
42
- return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir, generatorViewName + CommonConstants_1.default.VIEW_NAME_SUFFIX);
43
+ return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir, generatorViewName + CommonConstants_1.default.ETS_SUFFIX);
43
44
  }
44
45
  getBuilderDir() {
45
46
  return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir);
46
47
  }
47
48
  getBuilderFilePath(generatorViewName) {
48
- return path_1.default.join(this.builderDir, generatorViewName + CommonConstants_1.default.VIEW_NAME_SUFFIX);
49
+ return path_1.default.join(this.builderDir, generatorViewName + CommonConstants_1.default.ETS_SUFFIX);
49
50
  }
50
51
  getRouterMapDir() {
51
52
  return FileUtil_1.default.pathResolve(this.modulePath, this.routerMapDir, CommonConstants_1.default.ROUTER_MAP_NAME);
@@ -66,5 +67,8 @@ class HMRouterPluginConfig {
66
67
  getObfuscationFilePath() {
67
68
  return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.OBFUSCATION_FILE_NAME);
68
69
  }
70
+ getConsumerRulesFilePath() {
71
+ return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.CONSUMER_FILE_NAME);
72
+ }
69
73
  }
70
74
  exports.HMRouterPluginConfig = HMRouterPluginConfig;
@@ -13,6 +13,7 @@ export declare class HMRouterPluginHandle {
13
13
  private isEnableObfuscation;
14
14
  private copyRouterMapToRawFileTask;
15
15
  private writeHspModuleName;
16
+ private getRemoteHspModuleNames;
16
17
  private taskExec;
17
18
  private updateModuleJsonOpt;
18
19
  private updateBuildProfileOpt;