@hadss/hmrouter-plugin 1.2.1 → 1.2.2
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.
- package/README.md +6 -2
- package/dist/HMRouterPluginManager.d.ts +2 -1
- package/dist/HMRouterPluginManager.js +7 -4
- package/dist/Index.js +6 -5
- package/dist/framework/core/PluginExecutionController.d.ts +1 -1
- package/dist/framework/core/PluginExecutionController.js +2 -1
- package/dist/framework/extension/context/ExtensionContextImpl.d.ts +1 -0
- package/dist/framework/extension/context/Interface.d.ts +1 -0
- package/dist/hmrouter_extension/HMRouterExtension.js +12 -0
- package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +1 -0
- package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +9 -1
- package/dist/hmrouter_extension/processor/InitializerProcessor.js +4 -0
- package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +8 -1
- package/dist/hmrouter_extension/processor/ResourceProcessor.js +9 -2
- package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +8 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ HMRouter编译插件是一个基于hvigor的编译插件,用于:
|
|
|
21
21
|
```json5
|
|
22
22
|
{
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@hadss/hmrouter-plugin": "^1.2.
|
|
24
|
+
"@hadss/hmrouter-plugin": "^1.2.2" // 使用最新版本
|
|
25
25
|
},
|
|
26
26
|
// ...其余配置
|
|
27
27
|
}
|
|
@@ -438,9 +438,13 @@ hvigor 5.7.3及以上
|
|
|
438
438
|
|
|
439
439
|
## 更新日志
|
|
440
440
|
|
|
441
|
+
### 1.2.2 (2025.10.24)
|
|
442
|
+
|
|
443
|
+
- [修复系统路由表合并异常的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/215)
|
|
444
|
+
|
|
441
445
|
### 1.2.1 (2025.10.20)
|
|
442
446
|
|
|
443
|
-
- [修复低版本IDE
|
|
447
|
+
- [修复低版本IDE编译错误的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/206)
|
|
444
448
|
|
|
445
449
|
### 1.2.0 (2025.09.28)
|
|
446
450
|
|
|
@@ -4,8 +4,9 @@ export declare class HMRouterPluginManager {
|
|
|
4
4
|
private static instance;
|
|
5
5
|
private controllerMap;
|
|
6
6
|
private moduleNodes;
|
|
7
|
+
private nodeIgnored;
|
|
7
8
|
private constructor();
|
|
8
9
|
static getInstance(): HMRouterPluginManager;
|
|
9
10
|
registerPlugin(node: HvigorNode, pluginId: string, options: PluginParam): void;
|
|
10
|
-
addModuleNode(node: HvigorNode): void;
|
|
11
|
+
addModuleNode(node: HvigorNode, isIgnored: boolean): void;
|
|
11
12
|
}
|
|
@@ -9,6 +9,7 @@ class HMRouterPluginManager {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
this.controllerMap = new Map();
|
|
11
11
|
this.moduleNodes = [];
|
|
12
|
+
this.nodeIgnored = new Set();
|
|
12
13
|
framework_1.Logger.info('', 'HMRouterPlugin starting...');
|
|
13
14
|
(0, framework_1.registerPluginExtension)(new HMRouterExtension_1.HMRouterDefaultExtension());
|
|
14
15
|
hvigor_1.hvigor.nodesEvaluated(() => {
|
|
@@ -16,7 +17,6 @@ class HMRouterPluginManager {
|
|
|
16
17
|
if (this.controllerMap.has(node.getNodeName())) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
;
|
|
20
20
|
node.getAllPluginIds().forEach((pluginId) => {
|
|
21
21
|
this.registerPlugin(node, pluginId, {});
|
|
22
22
|
});
|
|
@@ -47,7 +47,7 @@ class HMRouterPluginManager {
|
|
|
47
47
|
if (!moduleContext) {
|
|
48
48
|
throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.ERROR_CONFIG, node.getNodeName(), node.getNodePath());
|
|
49
49
|
}
|
|
50
|
-
const controller = new framework_1.PluginExecutionController(node, moduleContext, options.extensions);
|
|
50
|
+
const controller = new framework_1.PluginExecutionController(node, moduleContext, this.nodeIgnored.has(node.getNodeName()), options.extensions);
|
|
51
51
|
this.controllerMap.set(node.getNodeName(), controller);
|
|
52
52
|
if ((0, framework_1.isHspModule)(node)) {
|
|
53
53
|
let packageJsonPath = framework_1.PluginFileUtil.pathResolve(node.getNodePath(), 'oh-package.json5');
|
|
@@ -63,12 +63,15 @@ class HMRouterPluginManager {
|
|
|
63
63
|
framework_1.PluginStore.getInstance().get('hspModuleNames')?.push(packageJson.name);
|
|
64
64
|
framework_1.PluginStore.getInstance().get('hspModulesInfo')?.push({
|
|
65
65
|
moduleName: node.getNodeName(),
|
|
66
|
-
packageName: packageJson.name
|
|
66
|
+
packageName: packageJson.name,
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
addModuleNode(node) {
|
|
70
|
+
addModuleNode(node, isIgnored) {
|
|
71
71
|
this.moduleNodes.push(node);
|
|
72
|
+
if (isIgnored) {
|
|
73
|
+
this.nodeIgnored.add(node.getNodeName());
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
exports.HMRouterPluginManager = HMRouterPluginManager;
|
package/dist/Index.js
CHANGED
|
@@ -65,16 +65,17 @@ function appPlugin(options) {
|
|
|
65
65
|
if (!options) {
|
|
66
66
|
throw new Error('No options provided');
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
handleNode(options, node);
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
exports.appPlugin = appPlugin;
|
|
73
|
-
function
|
|
74
|
-
node.subNodes(subNode => {
|
|
73
|
+
function handleNode(options, node) {
|
|
74
|
+
node.subNodes((subNode) => {
|
|
75
|
+
let isIgnored = false;
|
|
75
76
|
if (options.ignoreModuleNames.includes(subNode.getNodeName())) {
|
|
76
|
-
|
|
77
|
+
isIgnored = true;
|
|
77
78
|
}
|
|
78
|
-
HMRouterPluginManager_1.HMRouterPluginManager.getInstance().addModuleNode(subNode);
|
|
79
|
+
HMRouterPluginManager_1.HMRouterPluginManager.getInstance().addModuleNode(subNode, isIgnored);
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -7,7 +7,7 @@ export declare class PluginExecutionController {
|
|
|
7
7
|
private readonly taskManager;
|
|
8
8
|
private readonly baseContext;
|
|
9
9
|
private originalBuilderDir?;
|
|
10
|
-
constructor(node: HvigorNode, moduleContext: OhosModuleContext, moduleExtensions?: PluginExtension[]);
|
|
10
|
+
constructor(node: HvigorNode, moduleContext: OhosModuleContext, moduleIgnored: boolean, moduleExtensions?: PluginExtension[]);
|
|
11
11
|
start(): void;
|
|
12
12
|
complete(): void;
|
|
13
13
|
private initializeContext;
|
|
@@ -7,10 +7,11 @@ const constants_1 = require("../constants");
|
|
|
7
7
|
const extension_1 = require("../extension");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
class PluginExecutionController {
|
|
10
|
-
constructor(node, moduleContext, moduleExtensions) {
|
|
10
|
+
constructor(node, moduleContext, moduleIgnored, moduleExtensions) {
|
|
11
11
|
this.node = node;
|
|
12
12
|
this.moduleContext = moduleContext;
|
|
13
13
|
this.baseContext = this.initializeContext();
|
|
14
|
+
this.baseContext.moduleIgnored = moduleIgnored;
|
|
14
15
|
this.taskManager = new TaskManager_1.TaskManager(this.baseContext, moduleExtensions);
|
|
15
16
|
}
|
|
16
17
|
start() {
|
|
@@ -5,6 +5,7 @@ export declare class ExtensionContextImpl implements ExtensionContext {
|
|
|
5
5
|
node: HvigorNode;
|
|
6
6
|
moduleContext: OhosModuleContext;
|
|
7
7
|
currentTarget?: Target;
|
|
8
|
+
moduleIgnored?: boolean;
|
|
8
9
|
private moduleScanFilesMaster;
|
|
9
10
|
private templateMetadata;
|
|
10
11
|
private perTargetState;
|
|
@@ -10,6 +10,7 @@ export interface BaseExtensionContext {
|
|
|
10
10
|
readonly moduleContext: OhosModuleContext;
|
|
11
11
|
readonly currentView: ReadonlyArray<BaseAnalyzeResult>;
|
|
12
12
|
currentTarget?: Target;
|
|
13
|
+
moduleIgnored?: boolean;
|
|
13
14
|
scanFiles: string[];
|
|
14
15
|
}
|
|
15
16
|
export interface ExtensionContext extends BaseExtensionContext {
|
|
@@ -15,6 +15,10 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
15
15
|
initializer.execute();
|
|
16
16
|
}
|
|
17
17
|
afterAnnotationAnalysis(sourceFile, filePath, context) {
|
|
18
|
+
if (context.moduleIgnored) {
|
|
19
|
+
framework_2.Logger.debug(this.name, 'module ignored: annotationAnalysis');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
18
22
|
AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().initialize(context.config.modulePath);
|
|
19
23
|
const analyzers = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getAnalyzers();
|
|
20
24
|
for (const analyzer of analyzers) {
|
|
@@ -78,6 +82,10 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
afterCodeGeneration(context) {
|
|
85
|
+
if (context.moduleIgnored) {
|
|
86
|
+
framework_2.Logger.debug(this.name, 'module ignored: codeGeneration');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
81
89
|
const generator = new processor_1.CodeGenerationProcessor(context);
|
|
82
90
|
generator.execute();
|
|
83
91
|
}
|
|
@@ -90,6 +98,10 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
90
98
|
processor.execute();
|
|
91
99
|
}
|
|
92
100
|
afterObfuscationProcess(context) {
|
|
101
|
+
if (context.moduleIgnored) {
|
|
102
|
+
framework_2.Logger.debug(this.name, 'module ignored: obfuscationProcess');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
93
105
|
const processor = new processor_1.ObfuscationProcessor(context);
|
|
94
106
|
processor.execute();
|
|
95
107
|
}
|
|
@@ -5,13 +5,21 @@ const framework_1 = require("../../framework");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
class ConfigUpdateProcessor {
|
|
7
7
|
constructor(context) {
|
|
8
|
+
this.context = context;
|
|
8
9
|
this.moduleContext = context.moduleContext;
|
|
9
10
|
this.routerMap = context.routerMap;
|
|
10
11
|
this.nodeName = context.node.getNodeName();
|
|
11
12
|
}
|
|
12
13
|
execute() {
|
|
13
14
|
framework_1.Logger.debug(this.nodeName, `Start to update module.json and build profile...`);
|
|
14
|
-
this.
|
|
15
|
+
const isHar = (0, framework_1.isHarModule)(this.context.node);
|
|
16
|
+
if (this.context.moduleIgnored && isHar) {
|
|
17
|
+
framework_1.Logger.info(this.nodeName, `skip update module.json and build profile...`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (this.routerMap.length > 0 || !isHar) {
|
|
21
|
+
this.updateModuleJson();
|
|
22
|
+
}
|
|
15
23
|
this.updateBuildProfile();
|
|
16
24
|
}
|
|
17
25
|
updateModuleJson() {
|
|
@@ -13,6 +13,10 @@ class InitializerProcessor {
|
|
|
13
13
|
this.context.config = this.initConfig(this.context.node);
|
|
14
14
|
this.context.routerMap = [];
|
|
15
15
|
framework_1.Logger.debug(this.context.node.getNodeName(), `read config finished, config: ${this.context.config}`);
|
|
16
|
+
if (this.context.moduleIgnored) {
|
|
17
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `module ignored: initialize`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
16
20
|
this.scanFiles();
|
|
17
21
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Scanned ${this.context.scanFiles.length} files ${this.context.scanFiles}`);
|
|
18
22
|
}
|
|
@@ -9,6 +9,10 @@ class ObfuscationProcessor {
|
|
|
9
9
|
}
|
|
10
10
|
execute() {
|
|
11
11
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to obfuscation...`);
|
|
12
|
+
if (!this.context.routerMap || this.context.routerMap.length === 0) {
|
|
13
|
+
framework_1.Logger.info(this.context.node.getNodeName(), 'Skip generating obfuscation files');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
12
16
|
const buildProfileOpt = this.context.moduleContext?.getBuildProfileOpt();
|
|
13
17
|
if (!this.isEnableObfuscation(buildProfileOpt)) {
|
|
14
18
|
framework_1.Logger.info(this.context.node.getNodeName(), 'This compilation does not turn on code obfuscation, skip hmrouter_obfuscation_rules.txt file generation');
|
|
@@ -20,7 +24,10 @@ class ObfuscationProcessor {
|
|
|
20
24
|
}
|
|
21
25
|
generateObfuscationRuleFile() {
|
|
22
26
|
const obfuscationFilePath = framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OBFUSCATION_FILE_NAME);
|
|
23
|
-
|
|
27
|
+
let routerMap = [];
|
|
28
|
+
if (framework_1.PluginFileUtil.exist(this.context.config.getRouterMapDir())) {
|
|
29
|
+
routerMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(this.context.config.getRouterMapDir()).toString()).routerMap;
|
|
30
|
+
}
|
|
24
31
|
const obfuscationString = this.buildObfuscatedStrings(routerMap);
|
|
25
32
|
framework_1.PluginFileUtil.ensureFileSync(obfuscationFilePath);
|
|
26
33
|
framework_1.PluginFileUtil.writeFileSync(obfuscationFilePath, obfuscationString);
|
|
@@ -9,6 +9,11 @@ class ResourceProcessProcessor {
|
|
|
9
9
|
}
|
|
10
10
|
execute() {
|
|
11
11
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to copy router map to raw file...`);
|
|
12
|
+
const isHar = (0, framework_1.isHarModule)(this.context.node);
|
|
13
|
+
if ((isHar && !this.context.routerMap) || (isHar && this.context.routerMap.length === 0)) {
|
|
14
|
+
framework_1.Logger.info(this.context.node.getNodeName(), 'Skip copy router map');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
12
17
|
this.copyRouterMapToRawFile();
|
|
13
18
|
this.processHspModuleName();
|
|
14
19
|
}
|
|
@@ -16,7 +21,9 @@ class ResourceProcessProcessor {
|
|
|
16
21
|
let routerMapFilePath = framework_1.PluginFileUtil.pathResolve(this.context.currentTarget?.getBuildTargetOutputPath(), constants_1.FilePathConstants.TEMP_ROUTER_MAP_PATH, this.context.currentTarget?.getTargetName(), constants_1.RouterMapConstants.ROUTER_MAP_NAME);
|
|
17
22
|
let rawFilePath = this.context.config.getRawFilePath();
|
|
18
23
|
framework_1.PluginFileUtil.ensureFileSync(rawFilePath);
|
|
19
|
-
framework_1.PluginFileUtil.
|
|
24
|
+
if (framework_1.PluginFileUtil.exist(routerMapFilePath)) {
|
|
25
|
+
framework_1.PluginFileUtil.copyFileSync(routerMapFilePath, rawFilePath);
|
|
26
|
+
}
|
|
20
27
|
framework_1.Logger.info(this.context.node.getNodeName(), `Copy router map to raw file successfully, filePath: ${rawFilePath}`);
|
|
21
28
|
}
|
|
22
29
|
processHspModuleName() {
|
|
@@ -38,7 +45,7 @@ class ResourceProcessProcessor {
|
|
|
38
45
|
for (const remoteName of remoteHspModuleNames) {
|
|
39
46
|
rawFileRouterMap.hspModulesInfo.push({
|
|
40
47
|
moduleName: remoteName,
|
|
41
|
-
packageName: remoteName
|
|
48
|
+
packageName: remoteName,
|
|
42
49
|
});
|
|
43
50
|
}
|
|
44
51
|
framework_1.PluginFileUtil.writeFileSync(rawFilePath, JSON.stringify(rawFileRouterMap));
|
|
@@ -10,10 +10,15 @@ class RouterMapBuildingProcessor {
|
|
|
10
10
|
}
|
|
11
11
|
execute() {
|
|
12
12
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to build router map...`);
|
|
13
|
-
this.readExistingRouterMap();
|
|
14
13
|
for (const result of this.context.getAnalyzeResults()) {
|
|
15
14
|
this.buildRouterMap(result);
|
|
16
15
|
}
|
|
16
|
+
const isHar = (0, framework_1.isHarModule)(this.context.node);
|
|
17
|
+
if ((isHar && !this.context.routerMap) || (isHar && this.context.routerMap.length === 0)) {
|
|
18
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `Skip generating routerMap`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.readExistingRouterMap();
|
|
17
22
|
this.generateRouterMapFile();
|
|
18
23
|
}
|
|
19
24
|
buildRouterMap(result) {
|
|
@@ -103,7 +108,7 @@ class RouterMapBuildingProcessor {
|
|
|
103
108
|
readExistingRouterMap() {
|
|
104
109
|
const moduleJsonOpt = this.context.moduleContext.getModuleJsonOpt();
|
|
105
110
|
if (!moduleJsonOpt?.module.routerMap) {
|
|
106
|
-
framework_1.Logger.
|
|
111
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `No routerMap found in the module configuration`);
|
|
107
112
|
return;
|
|
108
113
|
}
|
|
109
114
|
const routerMapFileName = moduleJsonOpt.module.routerMap.split(':')[1];
|
|
@@ -113,7 +118,7 @@ class RouterMapBuildingProcessor {
|
|
|
113
118
|
const systemRouterMap = routerMapObj[constants_1.RouterMapConstants.ROUTER_MAP_KEY];
|
|
114
119
|
if (systemRouterMap && systemRouterMap.length > 0) {
|
|
115
120
|
this.context.routerMap.unshift(...systemRouterMap);
|
|
116
|
-
framework_1.Logger.
|
|
121
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `System routerMap added to the current routerMap`);
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadss/hmrouter-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "HMRouter Compiler Plugin",
|
|
5
5
|
"main": "dist/Index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha",
|
|
9
9
|
"dev": "tsc && node dist/index.js",
|
|
10
10
|
"build": "tsc",
|
|
11
|
-
"package": "rm -rf ./dist && tsc && npm pack",
|
|
12
|
-
"release": "rm -rf ./dist && npm i && tsc && npm publish --access public"
|
|
11
|
+
"package": "rm -rf ./dist && npm i && npx tsc && npm pack",
|
|
12
|
+
"release": "rm -rf ./dist && npm i && npx tsc && npm publish --access public"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"hmrouter",
|