mm_machine 2.6.8 → 2.7.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 (2) hide show
  1. package/index.js +48 -18
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -103,6 +103,10 @@ class Manager extends Mod {
103
103
  this.Drive = Drive;
104
104
  }
105
105
  }
106
+
107
+ get list() {
108
+ return this.getList();
109
+ }
106
110
  }
107
111
 
108
112
  /**
@@ -525,7 +529,7 @@ Manager.prototype.main = async function (name, method, ...params) {
525
529
  if (name) {
526
530
  let mod = this.getMod(name);
527
531
  if (mod && mod.config?.state === 1) {
528
- result = await this._run(mod, method, ...params);
532
+ result = await this._runMod(mod, method, ...params);
529
533
  }
530
534
  } else if (name === null) {
531
535
  result = await this._runAllEnabled(method, ...params);
@@ -546,7 +550,12 @@ Manager.prototype._runAllEnabled = async function (method, ...params) {
546
550
  let config = this.infos[i];
547
551
  let mod = this.getMod(config.name);
548
552
  if (mod && mod.config?.state === 1) {
549
- var ret = await this._run(mod, method, ...params);
553
+ var ret = null;
554
+ try {
555
+ ret = await this._runMod(mod, method, ...params);
556
+ } catch (err) {
557
+ $.log.error(`执行模块方法失败: `, err);
558
+ }
550
559
  if (ret !== null && ret !== undefined) {
551
560
  result = ret;
552
561
  // 如果结果不为空且有结束标志,则停止迭代
@@ -567,27 +576,27 @@ Manager.prototype._runAllEnabled = async function (method, ...params) {
567
576
  * @returns {Promise<any>} 执行结果
568
577
  * @private
569
578
  */
570
- Manager.prototype._run = async function (mod, method, ...params) {
579
+ Manager.prototype._runMod = async function (mod, method, ...params) {
571
580
  if (!mod || !method) return null;
572
581
 
573
- try {
574
- // 确保模块已加载
575
- if (!mod.isLoaded()) {
582
+ // 确保模块已加载
583
+ if (!mod.isLoaded()) {
584
+ try {
576
585
  await mod.call('loadScript');
577
586
  }
578
-
579
- // 执行方法
580
- let ret = await mod.call(method, ...params);
581
- // 根据模式决定是否重载
582
- if (this.mode >= 4) {
583
- mod.do('reload');
587
+ catch (err) {
588
+ $.log.error(`加载模块脚本失败: `, err);
584
589
  }
585
-
586
- return ret;
587
- } catch (err) {
588
- $.log.error(`执行模块方法失败: `, err);
589
- return null;
590
590
  }
591
+
592
+ // 执行方法
593
+ let ret = await mod.call(method, ...params);
594
+ // 根据模式决定是否重载
595
+ if (this.mode >= 4) {
596
+ mod.do('reload');
597
+ }
598
+
599
+ return ret;
591
600
  };
592
601
 
593
602
  /**
@@ -726,7 +735,9 @@ Manager.prototype.runWait = async function (method, ...params) {
726
735
  for (let i = 0; i < infos.length; i++) {
727
736
  let info = infos[i];
728
737
  let mod = this.getMod(info.name);
729
-
738
+ if (!mod) {
739
+ continue; // 跳过不存在的模块
740
+ }
730
741
  // 确保模块已加载
731
742
  if (!mod.isLoaded()) {
732
743
  try {
@@ -891,6 +902,25 @@ Manager.prototype.runWaterfall = async function (method, result, ...params) {
891
902
  return result;
892
903
  };
893
904
 
905
+ /**
906
+ * 异步触发事件,子模块执行
907
+ * @param {string} name 子模块名称
908
+ * @param {string} method 方法名称
909
+ * @param {...any} params 事件参数
910
+ * @returns {Promise} 事件触发结果
911
+ */
912
+ Manager.prototype.runSubMod = async function (name, method, ...params) {
913
+ // 参数校验
914
+ if (typeof method !== 'string') {
915
+ throw new TypeError('方法名称必须是字符串');
916
+ }
917
+ let mod = this.getMod(name);
918
+ if (!mod) {
919
+ throw new Error(`模块${name}不存在`);
920
+ }
921
+ return await mod.do(method, ...params);
922
+ };
923
+
894
924
  /**
895
925
  * 触发事件
896
926
  * @param {string} event 事件名
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.6.8",
3
+ "version": "2.7.0",
4
4
  "description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,11 +35,11 @@
35
35
  "dependencies": {
36
36
  "@prettier/sync": "^0.6.1",
37
37
  "mm_config": "^2.3.6",
38
- "mm_hot_reload": "^1.3.2",
39
- "mm_tpl": "^2.5.4"
38
+ "mm_hot_reload": "^1.3.3",
39
+ "mm_tpl": "^2.5.5"
40
40
  },
41
41
  "devDependencies": {
42
- "eslint": "^10.2.1",
42
+ "eslint": "^10.3.0",
43
43
  "eslint-plugin-jsdoc": "^62.9.0",
44
44
  "mm_eslint": "^1.7.1"
45
45
  }