mm_machine 2.4.6 → 2.4.8

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