mm_machine 2.6.9 → 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.
- package/index.js +23 -20
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -529,7 +529,7 @@ Manager.prototype.main = async function (name, method, ...params) {
|
|
|
529
529
|
if (name) {
|
|
530
530
|
let mod = this.getMod(name);
|
|
531
531
|
if (mod && mod.config?.state === 1) {
|
|
532
|
-
result = await this.
|
|
532
|
+
result = await this._runMod(mod, method, ...params);
|
|
533
533
|
}
|
|
534
534
|
} else if (name === null) {
|
|
535
535
|
result = await this._runAllEnabled(method, ...params);
|
|
@@ -550,7 +550,12 @@ Manager.prototype._runAllEnabled = async function (method, ...params) {
|
|
|
550
550
|
let config = this.infos[i];
|
|
551
551
|
let mod = this.getMod(config.name);
|
|
552
552
|
if (mod && mod.config?.state === 1) {
|
|
553
|
-
var ret =
|
|
553
|
+
var ret = null;
|
|
554
|
+
try {
|
|
555
|
+
ret = await this._runMod(mod, method, ...params);
|
|
556
|
+
} catch (err) {
|
|
557
|
+
$.log.error(`执行模块方法失败: `, err);
|
|
558
|
+
}
|
|
554
559
|
if (ret !== null && ret !== undefined) {
|
|
555
560
|
result = ret;
|
|
556
561
|
// 如果结果不为空且有结束标志,则停止迭代
|
|
@@ -571,27 +576,27 @@ Manager.prototype._runAllEnabled = async function (method, ...params) {
|
|
|
571
576
|
* @returns {Promise<any>} 执行结果
|
|
572
577
|
* @private
|
|
573
578
|
*/
|
|
574
|
-
Manager.prototype.
|
|
579
|
+
Manager.prototype._runMod = async function (mod, method, ...params) {
|
|
575
580
|
if (!mod || !method) return null;
|
|
576
581
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
582
|
+
// 确保模块已加载
|
|
583
|
+
if (!mod.isLoaded()) {
|
|
584
|
+
try {
|
|
580
585
|
await mod.call('loadScript');
|
|
581
586
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
let ret = await mod.call(method, ...params);
|
|
585
|
-
// 根据模式决定是否重载
|
|
586
|
-
if (this.mode >= 4) {
|
|
587
|
-
mod.do('reload');
|
|
587
|
+
catch (err) {
|
|
588
|
+
$.log.error(`加载模块脚本失败: `, err);
|
|
588
589
|
}
|
|
589
|
-
|
|
590
|
-
return ret;
|
|
591
|
-
} catch (err) {
|
|
592
|
-
$.log.error(`执行模块方法失败: `, err);
|
|
593
|
-
return null;
|
|
594
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;
|
|
595
600
|
};
|
|
596
601
|
|
|
597
602
|
/**
|
|
@@ -904,7 +909,7 @@ Manager.prototype.runWaterfall = async function (method, result, ...params) {
|
|
|
904
909
|
* @param {...any} params 事件参数
|
|
905
910
|
* @returns {Promise} 事件触发结果
|
|
906
911
|
*/
|
|
907
|
-
Manager.prototype.
|
|
912
|
+
Manager.prototype.runSubMod = async function (name, method, ...params) {
|
|
908
913
|
// 参数校验
|
|
909
914
|
if (typeof method !== 'string') {
|
|
910
915
|
throw new TypeError('方法名称必须是字符串');
|
|
@@ -913,8 +918,6 @@ Manager.prototype.runSub = async function (name, method, ...params) {
|
|
|
913
918
|
if (!mod) {
|
|
914
919
|
throw new Error(`模块${name}不存在`);
|
|
915
920
|
}
|
|
916
|
-
|
|
917
|
-
await mod.call('loadScript');
|
|
918
921
|
return await mod.do(method, ...params);
|
|
919
922
|
};
|
|
920
923
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "2.
|
|
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": {
|