@hadss/hmrouter-plugin 1.2.0-beta.2 → 1.2.0-beta.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.
@@ -5,4 +5,5 @@ export declare class TaskConstants {
5
5
  static readonly PLUGIN_TASK = "@HMRouterPluginTask";
6
6
  static readonly COPY_ROUTER_MAP_TASK = "@HMRouterCopyRouterMapToRawFileTask";
7
7
  static readonly GENERATE_OBFUSCATION_TASK = "@HMRouterGenerateObfuscationFileTask";
8
+ static readonly DEFAULT_SOURCE_ROOT = "./src/main";
8
9
  }
@@ -10,3 +10,4 @@ TaskConstants.PROCESS_RESOURCE = '@ProcessResource';
10
10
  TaskConstants.PLUGIN_TASK = '@HMRouterPluginTask';
11
11
  TaskConstants.COPY_ROUTER_MAP_TASK = '@HMRouterCopyRouterMapToRawFileTask';
12
12
  TaskConstants.GENERATE_OBFUSCATION_TASK = '@HMRouterGenerateObfuscationFileTask';
13
+ TaskConstants.DEFAULT_SOURCE_ROOT = './src/main';
@@ -6,7 +6,6 @@ export declare class PluginExecutionController {
6
6
  private readonly moduleContext;
7
7
  private readonly taskManager;
8
8
  private readonly baseContext;
9
- private extensionContextCache;
10
9
  private originalBuilderDir?;
11
10
  constructor(node: HvigorNode, moduleContext: OhosModuleContext, moduleExtensions?: PluginExtension[]);
12
11
  start(): void;
@@ -14,11 +13,7 @@ export declare class PluginExecutionController {
14
13
  private initializeContext;
15
14
  private registerHvigorTasks;
16
15
  private filterScanFilesForTarget;
17
- private backupScanFiles;
18
- private restoreScanFiles;
19
- private backupConfig;
20
- private restoreConfig;
21
- private adjustConfigForTarget;
16
+ private getAbsoluteSourceRoots;
22
17
  private registerMainPluginTask;
23
18
  private registerObfuscationTask;
24
19
  private registerCopyRouterMapTask;
@@ -8,7 +8,6 @@ const extension_1 = require("../extension");
8
8
  const utils_1 = require("../utils");
9
9
  class PluginExecutionController {
10
10
  constructor(node, moduleContext, moduleExtensions) {
11
- this.extensionContextCache = new Map();
12
11
  this.node = node;
13
12
  this.moduleContext = moduleContext;
14
13
  this.baseContext = this.initializeContext();
@@ -29,30 +28,26 @@ class PluginExecutionController {
29
28
  registerHvigorTasks() {
30
29
  this.moduleContext.targets((target) => {
31
30
  const targetName = target.getTargetName();
32
- this.taskManager.context.currentTarget = target;
33
31
  this.registerMainPluginTask(targetName);
34
32
  this.registerObfuscationTask(targetName);
35
33
  if ((0, utils_1.isHapModule)(this.node) || (0, utils_1.isHspModule)(this.node)) {
36
- this.registerCopyRouterMapTask(targetName);
34
+ this.registerCopyRouterMapTask(target);
37
35
  }
38
36
  });
39
37
  }
40
- filterScanFilesForTarget() {
41
- const currentTargetName = this.taskManager.context.currentTarget?.getTargetName();
42
- if (!currentTargetName) {
43
- return;
44
- }
38
+ filterScanFilesForTarget(currentTargetName) {
45
39
  const buildProfileTargets = this.moduleContext.getBuildProfileOpt().targets || [];
46
40
  const targetOpt = buildProfileTargets.find((target) => target.name === currentTargetName);
41
+ let absoluteSourceRoots;
47
42
  if (!targetOpt?.source?.sourceRoots || targetOpt.source.sourceRoots.length === 0) {
48
- return;
43
+ absoluteSourceRoots = this.getAbsoluteSourceRoots([constants_1.TaskConstants.DEFAULT_SOURCE_ROOT]);
44
+ }
45
+ else {
46
+ if (!targetOpt.source.sourceRoots.find((value) => value === constants_1.TaskConstants.DEFAULT_SOURCE_ROOT)) {
47
+ targetOpt.source.sourceRoots.push(constants_1.TaskConstants.DEFAULT_SOURCE_ROOT);
48
+ }
49
+ absoluteSourceRoots = this.getAbsoluteSourceRoots(targetOpt.source.sourceRoots);
49
50
  }
50
- const moduleRoot = this.moduleContext.getModulePath();
51
- const absoluteSourceRoots = targetOpt.source.sourceRoots.map((sourceRoot) => {
52
- const absolutePath = utils_1.PluginFileUtil.resolve(moduleRoot, sourceRoot);
53
- const normalizedPath = utils_1.PluginFileUtil.normalize(absolutePath);
54
- return normalizedPath.endsWith(utils_1.PluginFileUtil.sep) ? normalizedPath : normalizedPath + utils_1.PluginFileUtil.sep;
55
- });
56
51
  this.baseContext.scanFiles = this.baseContext.scanFiles.filter((filePath) => {
57
52
  const normalizedFilePath = utils_1.PluginFileUtil.normalize(filePath);
58
53
  return absoluteSourceRoots.some((sourceRootPath) => {
@@ -60,63 +55,23 @@ class PluginExecutionController {
60
55
  });
61
56
  });
62
57
  }
63
- backupScanFiles() {
64
- return [...this.baseContext.scanFiles];
65
- }
66
- restoreScanFiles(backup) {
67
- this.baseContext.scanFiles = backup;
68
- }
69
- backupConfig() {
70
- const hmrouterContext = this.taskManager.context;
71
- if (hmrouterContext.config && hmrouterContext.config.builderDir) {
72
- this.originalBuilderDir = hmrouterContext.config.builderDir;
73
- }
74
- }
75
- restoreConfig() {
76
- if (this.originalBuilderDir) {
77
- const hmrouterContext = this.taskManager.context;
78
- if (hmrouterContext.config) {
79
- hmrouterContext.config.builderDir = this.originalBuilderDir;
80
- }
81
- this.originalBuilderDir = undefined;
82
- }
83
- }
84
- adjustConfigForTarget() {
85
- const currentTargetName = this.taskManager.context.currentTarget?.getTargetName();
86
- if (!currentTargetName) {
87
- return;
88
- }
89
- const buildProfileTargets = this.moduleContext.getBuildProfileOpt().targets || [];
90
- const targetOpt = buildProfileTargets.find((target) => target.name === currentTargetName);
91
- if (!targetOpt?.source?.sourceRoots || targetOpt.source.sourceRoots.length === 0) {
92
- return;
93
- }
94
- const hmrouterContext = this.taskManager.context;
95
- if (!hmrouterContext.config || !hmrouterContext.config.builderDir) {
96
- return;
97
- }
98
- const firstSourceRoot = targetOpt.source.sourceRoots[0];
99
- const cleanSourceRoot = firstSourceRoot.replace(/^\.\//, '');
100
- hmrouterContext.config.builderDir = `${cleanSourceRoot}/ets/generated`;
58
+ getAbsoluteSourceRoots(sourceRoots) {
59
+ const moduleRoot = this.moduleContext.getModulePath();
60
+ return sourceRoots.map((sourceRoot) => {
61
+ const absolutePath = utils_1.PluginFileUtil.resolve(moduleRoot, sourceRoot);
62
+ const normalizedPath = utils_1.PluginFileUtil.normalize(absolutePath);
63
+ return normalizedPath.endsWith(utils_1.PluginFileUtil.sep) ? normalizedPath : normalizedPath + utils_1.PluginFileUtil.sep;
64
+ });
101
65
  }
102
66
  registerMainPluginTask(targetName) {
103
67
  this.node.registerTask({
104
68
  name: this.getTaskName(targetName, constants_1.TaskConstants.PLUGIN_TASK),
105
69
  run: () => {
106
- const scanFilesBackup = this.backupScanFiles();
107
- try {
108
- this.backupConfig();
109
- this.filterScanFilesForTarget();
110
- this.adjustConfigForTarget();
111
- this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ANNOTATION_ANALYSIS);
112
- this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CODE_GENERATION);
113
- this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ROUTER_MAP_BUILDING);
114
- this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CONFIG_UPDATE);
115
- }
116
- finally {
117
- this.restoreConfig();
118
- this.restoreScanFiles(scanFilesBackup);
119
- }
70
+ this.filterScanFilesForTarget(targetName);
71
+ this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ANNOTATION_ANALYSIS);
72
+ this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CODE_GENERATION);
73
+ this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ROUTER_MAP_BUILDING);
74
+ this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CONFIG_UPDATE);
120
75
  },
121
76
  dependencies: [],
122
77
  postDependencies: [this.getTaskName(targetName, constants_1.TaskConstants.PRE_BUILD)],
@@ -126,37 +81,19 @@ class PluginExecutionController {
126
81
  this.node.registerTask({
127
82
  name: this.getTaskName(targetName, constants_1.TaskConstants.GENERATE_OBFUSCATION_TASK),
128
83
  run: () => {
129
- const scanFilesBackup = this.backupScanFiles();
130
- try {
131
- this.backupConfig();
132
- this.filterScanFilesForTarget();
133
- this.adjustConfigForTarget();
134
- this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_OBFUSCATION_PROCESS);
135
- }
136
- finally {
137
- this.restoreConfig();
138
- this.restoreScanFiles(scanFilesBackup);
139
- }
84
+ this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_OBFUSCATION_PROCESS);
140
85
  },
141
86
  dependencies: [this.getTaskName(targetName, constants_1.TaskConstants.PLUGIN_TASK)],
142
87
  postDependencies: [this.getTaskName(targetName, constants_1.TaskConstants.PRE_BUILD)],
143
88
  });
144
89
  }
145
- registerCopyRouterMapTask(targetName) {
90
+ registerCopyRouterMapTask(target) {
91
+ const targetName = target.getTargetName();
146
92
  this.node.registerTask({
147
93
  name: this.getTaskName(targetName, constants_1.TaskConstants.COPY_ROUTER_MAP_TASK),
148
94
  run: () => {
149
- const scanFilesBackup = this.backupScanFiles();
150
- try {
151
- this.backupConfig();
152
- this.filterScanFilesForTarget();
153
- this.adjustConfigForTarget();
154
- this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_RESOURCE_PROCESS);
155
- }
156
- finally {
157
- this.restoreConfig();
158
- this.restoreScanFiles(scanFilesBackup);
159
- }
95
+ this.taskManager.context.currentTarget = target;
96
+ this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_RESOURCE_PROCESS);
160
97
  },
161
98
  dependencies: [this.getTaskName(targetName, constants_1.TaskConstants.PROCESS_ROUTER_MAP)],
162
99
  postDependencies: [this.getTaskName(targetName, constants_1.TaskConstants.PROCESS_RESOURCE)],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hadss/hmrouter-plugin",
3
- "version": "1.2.0-beta.2",
3
+ "version": "1.2.0-beta.3",
4
4
  "description": "HMRouter Compiler Plugin",
5
5
  "main": "dist/Index.js",
6
6
  "scripts": {