mm_machine 2.4.6 → 2.4.7

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 (3) hide show
  1. package/index.js +25 -29
  2. package/mod.js +2 -2
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -638,11 +638,11 @@ Manager.prototype.exec = async function (name, method, ...params) {
638
638
  */
639
639
  Manager.prototype._ensureAllModulesLoaded = async function () {
640
640
  let infos = this.getInfos();
641
-
641
+
642
642
  for (let i = 0; i < infos.length; i++) {
643
643
  let info = infos[i];
644
644
  let mod = this.getMod(info.name);
645
-
645
+
646
646
  if (!mod.isLoaded()) {
647
647
  try {
648
648
  await mod.call('loadScript');
@@ -685,7 +685,7 @@ Manager.prototype.runWait = async function (method, ...params) {
685
685
 
686
686
  // 执行方法
687
687
  try {
688
- let ret = await mod.call(method, ...params);
688
+ let ret = await mod.do(method, ...params);
689
689
  if (ret !== null && ret !== undefined) {
690
690
  result = ret;
691
691
  }
@@ -708,23 +708,23 @@ Manager.prototype.runAsync = async function (method, ...params) {
708
708
  if (typeof method !== 'string') {
709
709
  throw new TypeError('方法名称必须是字符串');
710
710
  }
711
-
711
+
712
712
  // 确保所有模块都已加载
713
713
  await this._ensureAllModulesLoaded();
714
-
714
+
715
715
  let infos = this.getInfos();
716
-
716
+
717
717
  // 并发执行所有方法,不等待结果
718
718
  for (let i = 0; i < infos.length; i++) {
719
719
  let info = infos[i];
720
720
  let mod = this.getMod(info.name);
721
721
  try {
722
- mod.call(method, ...params);
722
+ mod.do(method, ...params);
723
723
  } catch (error) {
724
724
  this.log('error', `模块${info.name}执行${method}方法失败`, error);
725
725
  }
726
726
  }
727
-
727
+
728
728
  return true;
729
729
  };
730
730
 
@@ -750,14 +750,12 @@ Manager.prototype.runAll = async function (method, ...params) {
750
750
  for (let i = 0; i < infos.length; i++) {
751
751
  let info = infos[i];
752
752
  let mod = this.getMod(info.name);
753
- if (mod.isLoaded()) {
754
- promises.push(
755
- mod.call(method, ...params).catch(error => {
756
- this.log('error', `模块${info.name}执行${method}方法失败`, error);
757
- return null; // 失败时返回null
758
- })
759
- );
760
- }
753
+ promises.push(
754
+ mod.do(method, ...params).catch(error => {
755
+ this.log('error', `模块${info.name}执行${method}方法失败`, error);
756
+ return null; // 失败时返回null
757
+ })
758
+ );
761
759
  }
762
760
 
763
761
  return await Promise.all(promises);
@@ -774,27 +772,25 @@ Manager.prototype.runRace = async function (method, ...params) {
774
772
  if (typeof method !== 'string') {
775
773
  throw new TypeError('方法名称必须是字符串');
776
774
  }
777
-
775
+
778
776
  // 确保所有模块都已加载
779
777
  await this._ensureAllModulesLoaded();
780
-
778
+
781
779
  const promises = [];
782
780
  let infos = this.getInfos();
783
-
781
+
784
782
  // 竞争执行所有方法
785
783
  for (let i = 0; i < infos.length; i++) {
786
784
  let info = infos[i];
787
785
  let mod = this.getMod(info.name);
788
- if (mod.isLoaded()) {
789
- promises.push(
790
- mod.call(method, ...params).catch(error => {
791
- this.log('error', `模块${info.name}执行${method}方法失败`, error);
792
- throw error; // 竞争执行中,失败应该抛出错误
793
- })
794
- );
795
- }
786
+ promises.push(
787
+ mod.do(method, ...params).catch(error => {
788
+ this.log('error', `模块${info.name}执行${method}方法失败`, error);
789
+ throw error; // 竞争执行中,失败应该抛出错误
790
+ })
791
+ );
796
792
  }
797
-
793
+
798
794
  return await Promise.race(promises);
799
795
  };
800
796
 
@@ -829,7 +825,7 @@ Manager.prototype.runWaterfall = async function (method, result, ...params) {
829
825
 
830
826
  // 执行方法,将前一个结果作为参数传递给下一个
831
827
  try {
832
- let ret = await mod.call(method, result, ...params);
828
+ let ret = await mod.do(method, result, ...params);
833
829
  if (ret !== null && ret !== undefined) {
834
830
  result = ret;
835
831
  }
package/mod.js CHANGED
@@ -479,7 +479,7 @@ Mod.prototype._callBefore = async function (method, params) {
479
479
  if (!before_func) return undefined;
480
480
 
481
481
  try {
482
- let result = await before_func.call(this._mod || this, ...params);
482
+ let result = await before_func.call(this, ...params);
483
483
  return result;
484
484
  } catch (err) {
485
485
  this.log('error', `执行前置钩子 ${before_method} 失败: `, err);
@@ -514,7 +514,7 @@ Mod.prototype._callAfter = async function (method, params, result) {
514
514
  if (!after_func) return result;
515
515
 
516
516
  try {
517
- let after = await after_func.call(this._mod || this, result, ...params);
517
+ let after = await after_func.call(this, result, ...params);
518
518
  return after !== undefined ? after : result;
519
519
  } catch (err) {
520
520
  this.log('error', `执行后置钩子 ${after_method} 失败: `, err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.4.6",
3
+ "version": "2.4.7",
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": {