mm_machine 2.4.5 → 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 -30
  2. package/mod.js +2 -2
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -428,7 +428,6 @@ Manager.prototype._findFiles = function (dir) {
428
428
  }
429
429
  // 检查目录是否存在
430
430
  if (!dir.hasDir()) {
431
- this.log('warn', '目录不存在', dir);
432
431
  return [];
433
432
  }
434
433
  if (this.config.search_way === 'dir') {
@@ -639,11 +638,11 @@ Manager.prototype.exec = async function (name, method, ...params) {
639
638
  */
640
639
  Manager.prototype._ensureAllModulesLoaded = async function () {
641
640
  let infos = this.getInfos();
642
-
641
+
643
642
  for (let i = 0; i < infos.length; i++) {
644
643
  let info = infos[i];
645
644
  let mod = this.getMod(info.name);
646
-
645
+
647
646
  if (!mod.isLoaded()) {
648
647
  try {
649
648
  await mod.call('loadScript');
@@ -686,7 +685,7 @@ Manager.prototype.runWait = async function (method, ...params) {
686
685
 
687
686
  // 执行方法
688
687
  try {
689
- let ret = await mod.call(method, ...params);
688
+ let ret = await mod.do(method, ...params);
690
689
  if (ret !== null && ret !== undefined) {
691
690
  result = ret;
692
691
  }
@@ -709,23 +708,23 @@ Manager.prototype.runAsync = async function (method, ...params) {
709
708
  if (typeof method !== 'string') {
710
709
  throw new TypeError('方法名称必须是字符串');
711
710
  }
712
-
711
+
713
712
  // 确保所有模块都已加载
714
713
  await this._ensureAllModulesLoaded();
715
-
714
+
716
715
  let infos = this.getInfos();
717
-
716
+
718
717
  // 并发执行所有方法,不等待结果
719
718
  for (let i = 0; i < infos.length; i++) {
720
719
  let info = infos[i];
721
720
  let mod = this.getMod(info.name);
722
721
  try {
723
- mod.call(method, ...params);
722
+ mod.do(method, ...params);
724
723
  } catch (error) {
725
724
  this.log('error', `模块${info.name}执行${method}方法失败`, error);
726
725
  }
727
726
  }
728
-
727
+
729
728
  return true;
730
729
  };
731
730
 
@@ -751,14 +750,12 @@ Manager.prototype.runAll = async function (method, ...params) {
751
750
  for (let i = 0; i < infos.length; i++) {
752
751
  let info = infos[i];
753
752
  let mod = this.getMod(info.name);
754
- if (mod.isLoaded()) {
755
- promises.push(
756
- mod.call(method, ...params).catch(error => {
757
- this.log('error', `模块${info.name}执行${method}方法失败`, error);
758
- return null; // 失败时返回null
759
- })
760
- );
761
- }
753
+ promises.push(
754
+ mod.do(method, ...params).catch(error => {
755
+ this.log('error', `模块${info.name}执行${method}方法失败`, error);
756
+ return null; // 失败时返回null
757
+ })
758
+ );
762
759
  }
763
760
 
764
761
  return await Promise.all(promises);
@@ -775,27 +772,25 @@ Manager.prototype.runRace = async function (method, ...params) {
775
772
  if (typeof method !== 'string') {
776
773
  throw new TypeError('方法名称必须是字符串');
777
774
  }
778
-
775
+
779
776
  // 确保所有模块都已加载
780
777
  await this._ensureAllModulesLoaded();
781
-
778
+
782
779
  const promises = [];
783
780
  let infos = this.getInfos();
784
-
781
+
785
782
  // 竞争执行所有方法
786
783
  for (let i = 0; i < infos.length; i++) {
787
784
  let info = infos[i];
788
785
  let mod = this.getMod(info.name);
789
- if (mod.isLoaded()) {
790
- promises.push(
791
- mod.call(method, ...params).catch(error => {
792
- this.log('error', `模块${info.name}执行${method}方法失败`, error);
793
- throw error; // 竞争执行中,失败应该抛出错误
794
- })
795
- );
796
- }
786
+ promises.push(
787
+ mod.do(method, ...params).catch(error => {
788
+ this.log('error', `模块${info.name}执行${method}方法失败`, error);
789
+ throw error; // 竞争执行中,失败应该抛出错误
790
+ })
791
+ );
797
792
  }
798
-
793
+
799
794
  return await Promise.race(promises);
800
795
  };
801
796
 
@@ -830,7 +825,7 @@ Manager.prototype.runWaterfall = async function (method, result, ...params) {
830
825
 
831
826
  // 执行方法,将前一个结果作为参数传递给下一个
832
827
  try {
833
- let ret = await mod.call(method, result, ...params);
828
+ let ret = await mod.do(method, result, ...params);
834
829
  if (ret !== null && ret !== undefined) {
835
830
  result = ret;
836
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.5",
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": {