mm_machine 3.3.1 → 3.3.3
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 +2 -2
- package/lib/drive.js +15 -4
- package/lib/manager.js +1 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Mod } = require('./lib/mod.js');
|
|
2
|
-
const { Drive } = require('./lib/drive.js');
|
|
2
|
+
const { Drive, MODE } = require('./lib/drive.js');
|
|
3
3
|
const { Manager } = require('./lib/manager.js');
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
|
-
Mod, Drive, Manager
|
|
6
|
+
Mod, Drive, Manager, MODE
|
|
7
7
|
};
|
package/lib/drive.js
CHANGED
|
@@ -97,11 +97,11 @@ Drive.prototype._loadConfig = function (file) {
|
|
|
97
97
|
this.config_file = file;
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
|
-
//
|
|
101
|
-
let config =
|
|
100
|
+
// 加载配置(支持热更新)
|
|
101
|
+
let config = this._loadHotReload(this.config_file);
|
|
102
102
|
if (!config) {
|
|
103
103
|
this.newConfig(this.config_file);
|
|
104
|
-
config =
|
|
104
|
+
config = this._loadHotReload(this.config_file);
|
|
105
105
|
}
|
|
106
106
|
this.setConfig(config);
|
|
107
107
|
return config;
|
|
@@ -340,7 +340,7 @@ Drive.prototype.loadScript = function () {
|
|
|
340
340
|
let file = this._getScriptFile();
|
|
341
341
|
if (!file) return null;
|
|
342
342
|
try {
|
|
343
|
-
if (this.mode
|
|
343
|
+
if (this.mode === MODE.HOT_RELOAD || this.mode === MODE.HOT_BOTH) {
|
|
344
344
|
var cs = $.require(file, (mod) => {
|
|
345
345
|
this._setMainMethod(mod);
|
|
346
346
|
});
|
|
@@ -550,7 +550,18 @@ Drive.prototype._findConfigByName = function (config, name) {
|
|
|
550
550
|
* @private
|
|
551
551
|
*/
|
|
552
552
|
Drive.prototype._handleHotReload = function (config) {
|
|
553
|
+
var old_config = { ...this.config };
|
|
553
554
|
this.setConfig(config);
|
|
555
|
+
|
|
556
|
+
// 调用 _onConfigChange 钩子(如果脚本中定义了)
|
|
557
|
+
var on_config_change = this.getMethod('_onConfigChange');
|
|
558
|
+
if (typeof on_config_change === 'function') {
|
|
559
|
+
on_config_change.call(this, old_config, this.config);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// 触发 config:change 事件
|
|
563
|
+
this.emit('config:change', old_config, this.config);
|
|
564
|
+
|
|
554
565
|
this._reloadIfNeeded();
|
|
555
566
|
return config;
|
|
556
567
|
};
|
package/lib/manager.js
CHANGED
|
@@ -318,14 +318,6 @@ Manager.prototype.loadMod = async function (name) {
|
|
|
318
318
|
return null;
|
|
319
319
|
};
|
|
320
320
|
|
|
321
|
-
/**
|
|
322
|
-
* 初始化模块
|
|
323
|
-
* @param {object} mod 模块对象
|
|
324
|
-
*/
|
|
325
|
-
Manager.prototype._initMod = async function (mod) {
|
|
326
|
-
await mod.do('init', this.getParent());
|
|
327
|
-
};
|
|
328
|
-
|
|
329
321
|
/**
|
|
330
322
|
* 卸载模块
|
|
331
323
|
* @param {string} name 模块名
|
|
@@ -739,7 +731,7 @@ Manager.prototype._ensureModLoaded = async function (mod, method) {
|
|
|
739
731
|
}
|
|
740
732
|
if (!mod.isInited()) {
|
|
741
733
|
try {
|
|
742
|
-
await mod.do('init'
|
|
734
|
+
await mod.do('init');
|
|
743
735
|
} catch (error) {
|
|
744
736
|
throw new Error(`模块${mod.config.name}初始化失败,无法执行方法 ${method}`);
|
|
745
737
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
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": {
|