@hadss/hmrouter-plugin 1.2.0-beta.3 → 1.2.0-rc.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.
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ HMRouter编译插件是一个基于hvigor的编译插件,用于:
|
|
|
21
21
|
```json5
|
|
22
22
|
{
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@hadss/hmrouter-plugin": "^1.2.0-
|
|
24
|
+
"@hadss/hmrouter-plugin": "^1.2.0-rc.0" // 使用最新版本
|
|
25
25
|
},
|
|
26
26
|
// ...其余配置
|
|
27
27
|
}
|
|
@@ -438,6 +438,10 @@ hvigor 5.7.3及以上
|
|
|
438
438
|
|
|
439
439
|
## 更新日志
|
|
440
440
|
|
|
441
|
+
### 1.2.0-rc.0 (2025.09.02)
|
|
442
|
+
|
|
443
|
+
- [修复多target工程下编译app的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/131)
|
|
444
|
+
|
|
441
445
|
### 1.2.0-beta.1 (2025.07.29)
|
|
442
446
|
|
|
443
447
|
- 修复相同组件名称冲突的问题
|
|
@@ -28,7 +28,7 @@ class PluginExecutionController {
|
|
|
28
28
|
registerHvigorTasks() {
|
|
29
29
|
this.moduleContext.targets((target) => {
|
|
30
30
|
const targetName = target.getTargetName();
|
|
31
|
-
this.registerMainPluginTask(
|
|
31
|
+
this.registerMainPluginTask(target);
|
|
32
32
|
this.registerObfuscationTask(targetName);
|
|
33
33
|
if ((0, utils_1.isHapModule)(this.node) || (0, utils_1.isHspModule)(this.node)) {
|
|
34
34
|
this.registerCopyRouterMapTask(target);
|
|
@@ -48,7 +48,8 @@ class PluginExecutionController {
|
|
|
48
48
|
}
|
|
49
49
|
absoluteSourceRoots = this.getAbsoluteSourceRoots(targetOpt.source.sourceRoots);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
const masterFiles = this.baseContext.getModuleScanFiles();
|
|
52
|
+
return masterFiles.filter((filePath) => {
|
|
52
53
|
const normalizedFilePath = utils_1.PluginFileUtil.normalize(filePath);
|
|
53
54
|
return absoluteSourceRoots.some((sourceRootPath) => {
|
|
54
55
|
return normalizedFilePath.startsWith(sourceRootPath);
|
|
@@ -63,11 +64,14 @@ class PluginExecutionController {
|
|
|
63
64
|
return normalizedPath.endsWith(utils_1.PluginFileUtil.sep) ? normalizedPath : normalizedPath + utils_1.PluginFileUtil.sep;
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
registerMainPluginTask(
|
|
67
|
+
registerMainPluginTask(target) {
|
|
68
|
+
const targetName = target.getTargetName();
|
|
67
69
|
this.node.registerTask({
|
|
68
70
|
name: this.getTaskName(targetName, constants_1.TaskConstants.PLUGIN_TASK),
|
|
69
71
|
run: () => {
|
|
70
|
-
this.
|
|
72
|
+
this.taskManager.context.currentTarget = target;
|
|
73
|
+
const filtered = this.filterScanFilesForTarget(targetName);
|
|
74
|
+
this.baseContext.scanFiles = filtered;
|
|
71
75
|
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ANNOTATION_ANALYSIS);
|
|
72
76
|
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CODE_GENERATION);
|
|
73
77
|
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ROUTER_MAP_BUILDING);
|
|
@@ -5,12 +5,13 @@ export declare class ExtensionContextImpl implements ExtensionContext {
|
|
|
5
5
|
node: HvigorNode;
|
|
6
6
|
moduleContext: OhosModuleContext;
|
|
7
7
|
currentTarget?: Target;
|
|
8
|
-
|
|
8
|
+
private moduleScanFilesMaster;
|
|
9
9
|
private templateMetadata;
|
|
10
|
-
private
|
|
11
|
-
private _currentView;
|
|
12
|
-
private _currentFilePath?;
|
|
10
|
+
private perTargetState;
|
|
13
11
|
constructor(node: HvigorNode, moduleContext: OhosModuleContext);
|
|
12
|
+
private getActiveTargetKey;
|
|
13
|
+
private getOrCreateState;
|
|
14
|
+
getModuleScanFiles(): string[];
|
|
14
15
|
get currentView(): ReadonlyArray<BaseAnalyzeResult>;
|
|
15
16
|
addAnalyzeResults(results: BaseAnalyzeResult | BaseAnalyzeResult[]): void;
|
|
16
17
|
getAnalyzeResults<T extends BaseAnalyzeResult = BaseAnalyzeResult>(): Set<T>;
|
|
@@ -20,4 +21,16 @@ export declare class ExtensionContextImpl implements ExtensionContext {
|
|
|
20
21
|
private validateAnalyzeResult;
|
|
21
22
|
private syncToCurrentView;
|
|
22
23
|
setCurrentFilePath(filePath: string): void;
|
|
24
|
+
get scanFiles(): string[];
|
|
25
|
+
set scanFiles(files: string[]);
|
|
26
|
+
get analyzeResults(): Set<BaseAnalyzeResult>;
|
|
27
|
+
set analyzeResults(v: Set<BaseAnalyzeResult>);
|
|
28
|
+
get _currentView(): BaseAnalyzeResult[];
|
|
29
|
+
set _currentView(v: BaseAnalyzeResult[]);
|
|
30
|
+
get _currentFilePath(): string | undefined;
|
|
31
|
+
set _currentFilePath(v: string | undefined);
|
|
32
|
+
get routerMap(): any[];
|
|
33
|
+
set routerMap(v: any[]);
|
|
34
|
+
get generatedPaths(): Map<string, string>;
|
|
35
|
+
set generatedPaths(v: Map<string, string>);
|
|
23
36
|
}
|
|
@@ -5,24 +5,47 @@ const TemplateMetadataImpl_1 = require("./TemplateMetadataImpl");
|
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
class ExtensionContextImpl {
|
|
7
7
|
constructor(node, moduleContext) {
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this._currentView = [];
|
|
8
|
+
this.moduleScanFilesMaster = [];
|
|
9
|
+
this.perTargetState = new Map();
|
|
11
10
|
this.node = node;
|
|
12
11
|
this.moduleContext = moduleContext;
|
|
13
12
|
this.templateMetadata = new TemplateMetadataImpl_1.TemplateMetadataImpl();
|
|
14
13
|
}
|
|
14
|
+
getActiveTargetKey() {
|
|
15
|
+
return this.currentTarget?.getTargetName() ?? '__global__';
|
|
16
|
+
}
|
|
17
|
+
getOrCreateState(key) {
|
|
18
|
+
let state = this.perTargetState.get(key);
|
|
19
|
+
if (!state) {
|
|
20
|
+
state = {
|
|
21
|
+
scanFiles: [],
|
|
22
|
+
analyzeResults: new Set(),
|
|
23
|
+
currentView: [],
|
|
24
|
+
currentFilePath: undefined,
|
|
25
|
+
routerMap: [],
|
|
26
|
+
generatedPaths: new Map(),
|
|
27
|
+
};
|
|
28
|
+
this.perTargetState.set(key, state);
|
|
29
|
+
}
|
|
30
|
+
return state;
|
|
31
|
+
}
|
|
32
|
+
getModuleScanFiles() {
|
|
33
|
+
return this.moduleScanFilesMaster;
|
|
34
|
+
}
|
|
15
35
|
get currentView() {
|
|
16
|
-
|
|
36
|
+
const key = this.getActiveTargetKey();
|
|
37
|
+
return this.getOrCreateState(key).currentView;
|
|
17
38
|
}
|
|
18
39
|
addAnalyzeResults(results) {
|
|
40
|
+
const key = this.getActiveTargetKey();
|
|
41
|
+
const state = this.getOrCreateState(key);
|
|
19
42
|
if (Array.isArray(results)) {
|
|
20
43
|
results.forEach((result) => {
|
|
21
44
|
if (!this.validateAnalyzeResult(result)) {
|
|
22
45
|
utils_1.Logger.warn(this.node.getNodeName(), `Invalid analyze result: ${JSON.stringify(result)}`);
|
|
23
46
|
return;
|
|
24
47
|
}
|
|
25
|
-
|
|
48
|
+
state.analyzeResults.add(result);
|
|
26
49
|
});
|
|
27
50
|
}
|
|
28
51
|
else {
|
|
@@ -30,12 +53,13 @@ class ExtensionContextImpl {
|
|
|
30
53
|
utils_1.Logger.warn(this.node.getNodeName(), `Invalid analyze result: ${JSON.stringify(results)}`);
|
|
31
54
|
return;
|
|
32
55
|
}
|
|
33
|
-
|
|
56
|
+
state.analyzeResults.add(results);
|
|
34
57
|
}
|
|
35
58
|
this.syncToCurrentView(results);
|
|
36
59
|
}
|
|
37
60
|
getAnalyzeResults() {
|
|
38
|
-
|
|
61
|
+
const key = this.getActiveTargetKey();
|
|
62
|
+
return this.getOrCreateState(key).analyzeResults;
|
|
39
63
|
}
|
|
40
64
|
getTemplateData(componentName) {
|
|
41
65
|
return this.templateMetadata.getTemplateData(componentName);
|
|
@@ -50,15 +74,75 @@ class ExtensionContextImpl {
|
|
|
50
74
|
return result.name !== undefined && result.sourceFilePath !== undefined && result.annotation !== undefined;
|
|
51
75
|
}
|
|
52
76
|
syncToCurrentView(results) {
|
|
53
|
-
|
|
77
|
+
const key = this.getActiveTargetKey();
|
|
78
|
+
const state = this.getOrCreateState(key);
|
|
79
|
+
if (!state.currentFilePath)
|
|
54
80
|
return;
|
|
55
81
|
const resultsArray = Array.isArray(results) ? results : [results];
|
|
56
|
-
const currentFileResults = resultsArray.filter(result => result.sourceFilePath ===
|
|
57
|
-
|
|
82
|
+
const currentFileResults = resultsArray.filter(result => result.sourceFilePath === state.currentFilePath);
|
|
83
|
+
state.currentView.push(...currentFileResults);
|
|
58
84
|
}
|
|
59
85
|
setCurrentFilePath(filePath) {
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
const key = this.getActiveTargetKey();
|
|
87
|
+
const state = this.getOrCreateState(key);
|
|
88
|
+
state.currentFilePath = filePath;
|
|
89
|
+
state.currentView = [];
|
|
90
|
+
}
|
|
91
|
+
get scanFiles() {
|
|
92
|
+
const key = this.getActiveTargetKey();
|
|
93
|
+
if (key === '__global__') {
|
|
94
|
+
return this.moduleScanFilesMaster;
|
|
95
|
+
}
|
|
96
|
+
return this.getOrCreateState(key).scanFiles;
|
|
97
|
+
}
|
|
98
|
+
set scanFiles(files) {
|
|
99
|
+
const key = this.getActiveTargetKey();
|
|
100
|
+
if (key === '__global__') {
|
|
101
|
+
this.moduleScanFilesMaster = files;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.getOrCreateState(key).scanFiles = files;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
get analyzeResults() {
|
|
108
|
+
const key = this.getActiveTargetKey();
|
|
109
|
+
return this.getOrCreateState(key).analyzeResults;
|
|
110
|
+
}
|
|
111
|
+
set analyzeResults(v) {
|
|
112
|
+
const key = this.getActiveTargetKey();
|
|
113
|
+
this.getOrCreateState(key).analyzeResults = v;
|
|
114
|
+
}
|
|
115
|
+
get _currentView() {
|
|
116
|
+
const key = this.getActiveTargetKey();
|
|
117
|
+
return this.getOrCreateState(key).currentView;
|
|
118
|
+
}
|
|
119
|
+
set _currentView(v) {
|
|
120
|
+
const key = this.getActiveTargetKey();
|
|
121
|
+
this.getOrCreateState(key).currentView = v;
|
|
122
|
+
}
|
|
123
|
+
get _currentFilePath() {
|
|
124
|
+
const key = this.getActiveTargetKey();
|
|
125
|
+
return this.getOrCreateState(key).currentFilePath;
|
|
126
|
+
}
|
|
127
|
+
set _currentFilePath(v) {
|
|
128
|
+
const key = this.getActiveTargetKey();
|
|
129
|
+
this.getOrCreateState(key).currentFilePath = v;
|
|
130
|
+
}
|
|
131
|
+
get routerMap() {
|
|
132
|
+
const key = this.getActiveTargetKey();
|
|
133
|
+
return this.getOrCreateState(key).routerMap;
|
|
134
|
+
}
|
|
135
|
+
set routerMap(v) {
|
|
136
|
+
const key = this.getActiveTargetKey();
|
|
137
|
+
this.getOrCreateState(key).routerMap = v;
|
|
138
|
+
}
|
|
139
|
+
get generatedPaths() {
|
|
140
|
+
const key = this.getActiveTargetKey();
|
|
141
|
+
return this.getOrCreateState(key).generatedPaths;
|
|
142
|
+
}
|
|
143
|
+
set generatedPaths(v) {
|
|
144
|
+
const key = this.getActiveTargetKey();
|
|
145
|
+
this.getOrCreateState(key).generatedPaths = v;
|
|
62
146
|
}
|
|
63
147
|
}
|
|
64
148
|
exports.ExtensionContextImpl = ExtensionContextImpl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadss/hmrouter-plugin",
|
|
3
|
-
"version": "1.2.0-
|
|
3
|
+
"version": "1.2.0-rc.0",
|
|
4
4
|
"description": "HMRouter Compiler Plugin",
|
|
5
5
|
"main": "dist/Index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
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
|
-
"release": "tsc && npm publish --access public"
|
|
11
|
+
"release": "rm -rf ./dist && tsc && npm publish --access public"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"hmrouter",
|