mm_machine 3.3.1 → 3.3.2

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 +2 -2
  2. package/lib/drive.js +15 -4
  3. 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 = $.loadJson(this.config_file);
100
+ // 加载配置(支持热更新)
101
+ let config = this._loadHotReload(this.config_file);
102
102
  if (!config) {
103
103
  this.newConfig(this.config_file);
104
- config = $.loadJson(this.config_file);
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 >= MODE.HOT_RELOAD) {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
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": {