mm_machine 3.2.1 → 3.2.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.
- package/manager.js +14 -16
- package/package.json +1 -1
package/manager.js
CHANGED
|
@@ -260,8 +260,7 @@ Manager.prototype.getMod = function (name) {
|
|
|
260
260
|
for (var i = 0; i < entries.length; i++) {
|
|
261
261
|
if (entries[i].name === name) {
|
|
262
262
|
var entry = entries[i];
|
|
263
|
-
|
|
264
|
-
mod = new ModClass(entry, this);
|
|
263
|
+
mod = new this.Drive(entry, this);
|
|
265
264
|
mod.mode = this.config.mode;
|
|
266
265
|
mod.config_file = entry.config_file;
|
|
267
266
|
if (mod._preset) {
|
|
@@ -343,7 +342,11 @@ Manager.prototype.regMod = function (config_file, config = {}, script = {}) {
|
|
|
343
342
|
|
|
344
343
|
var mod = this.newMod(config_file, cg, script);
|
|
345
344
|
if (!mod) return null;
|
|
346
|
-
|
|
345
|
+
|
|
346
|
+
// 模块已存在时不替换内存实例,避免破坏已初始化的模块
|
|
347
|
+
if (!this.mods[mod.config.name]) {
|
|
348
|
+
this.setMod(mod.config.name, mod);
|
|
349
|
+
}
|
|
347
350
|
|
|
348
351
|
var entry = {
|
|
349
352
|
name: mod.config.name,
|
|
@@ -532,7 +535,6 @@ Manager.prototype._loadFromRegistry = function () {
|
|
|
532
535
|
let lt = this._getInfos();
|
|
533
536
|
if (!lt.length) return false;
|
|
534
537
|
|
|
535
|
-
var mod_class = this.config.mod_type === 'script' ? Mod : this.Drive;
|
|
536
538
|
var mode = this.config.mode;
|
|
537
539
|
var mods = this.mods;
|
|
538
540
|
|
|
@@ -541,7 +543,7 @@ Manager.prototype._loadFromRegistry = function () {
|
|
|
541
543
|
|
|
542
544
|
if (!this.config.lazy_load) {
|
|
543
545
|
// 非懒加载模式:立即实例化
|
|
544
|
-
var mod = new
|
|
546
|
+
var mod = new this.Drive(entry, this);
|
|
545
547
|
mod.mode = mode;
|
|
546
548
|
mod.config_file = entry.config_file;
|
|
547
549
|
if (mod._preset) {
|
|
@@ -591,9 +593,7 @@ Manager.prototype.main = async function (name, method, ...params) {
|
|
|
591
593
|
var entries = this._getInfos();
|
|
592
594
|
var entry = entries.find((o) => { return o.name === name; });
|
|
593
595
|
if (entry && entry.state === 1) {
|
|
594
|
-
var
|
|
595
|
-
mod = new ModClass(entry, this);
|
|
596
|
-
mod.mode = this.config.mode;
|
|
596
|
+
var mod = new this.Drive(entry, this);
|
|
597
597
|
mod.config_file = entry.config_file;
|
|
598
598
|
if (mod._preset) mod._preset();
|
|
599
599
|
this.mods[name] = mod;
|
|
@@ -697,31 +697,29 @@ Manager.prototype.getDir = function () {
|
|
|
697
697
|
* 同时在后台异步扫描文件系统,确保注册表数据为物理最新。
|
|
698
698
|
*/
|
|
699
699
|
Manager.prototype._loadSources = async function () {
|
|
700
|
-
//
|
|
701
|
-
//
|
|
700
|
+
// 启用注册表且有缓存数据时,走内存快路径,快速启动;
|
|
701
|
+
// 后台异步扫描文件系统更新注册表,确保物理最新。
|
|
702
702
|
if (this.config.use_registry) {
|
|
703
|
-
// 只有从注册表成功加载到模块时才跳过文件系统扫描,否则回退到文件系统
|
|
704
703
|
if (this._loadFromRegistry()) {
|
|
705
|
-
// 后台异步扫描文件系统,确保物理最新
|
|
706
704
|
setImmediate(() => this._scanForUpdate(false));
|
|
707
705
|
return;
|
|
708
706
|
}
|
|
709
707
|
}
|
|
710
708
|
|
|
711
|
-
//
|
|
712
|
-
await this._scanForUpdate(
|
|
709
|
+
// 注册表无缓存,同步扫描文件系统
|
|
710
|
+
await this._scanForUpdate();
|
|
713
711
|
};
|
|
714
712
|
|
|
715
713
|
/**
|
|
716
714
|
* 后台扫描文件系统并同步到注册表
|
|
717
715
|
* 不阻塞启动,让注册表始终与磁盘保持同步
|
|
718
716
|
*/
|
|
719
|
-
Manager.prototype._scanForUpdate = async function (clear =
|
|
717
|
+
Manager.prototype._scanForUpdate = async function (clear = true) {
|
|
720
718
|
var base_dir = this.getBaseDir();
|
|
721
719
|
var dir = this.getDir();
|
|
722
720
|
try {
|
|
723
721
|
if (base_dir) {
|
|
724
|
-
await Promise.all([this.call('update', base_dir, clear), this.call('update', dir,
|
|
722
|
+
await Promise.all([this.call('update', base_dir, clear), this.call('update', dir, false)]);
|
|
725
723
|
} else {
|
|
726
724
|
await this.call('update', dir, clear);
|
|
727
725
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.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": {
|