mm_machine 3.5.1 → 3.5.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.
@@ -1,6 +1,8 @@
1
1
  require('mm_hot_reload');
2
2
 
3
3
  const _AUTO_INST = {};
4
+ // 内置模块名集合
5
+ const BUILTIN_MODULES = new Set(require('module').builtinModules);
4
6
 
5
7
  /**
6
8
  * 从模块标识符中提取npm包名
@@ -36,6 +38,16 @@ function _isLocal(name) {
36
38
  return name.startsWith('.') || name.startsWith('/') || /^[a-zA-Z]:/.test(name);
37
39
  }
38
40
 
41
+ /**
42
+ * 是否为Node内置模块
43
+ * @param {string} name 模块名
44
+ * @returns {boolean} 是否为内置模块
45
+ */
46
+ function _isBuiltin(name) {
47
+ let raw_name = name.startsWith('node:') ? name.slice(5) : name;
48
+ return BUILTIN_MODULES.has(raw_name);
49
+ }
50
+
39
51
  /**
40
52
  * 清除指定包的require缓存
41
53
  * @param {string} name 包名
@@ -83,7 +95,7 @@ function _tryInstall(file) {
83
95
  return false;
84
96
  }
85
97
  let raw_name = _extractErrName(e);
86
- if (!raw_name || _isLocal(raw_name)) {
98
+ if (!raw_name || _isLocal(raw_name) || _isBuiltin(raw_name)) {
87
99
  return false;
88
100
  }
89
101
  let pkg_name = _extractPkgName(raw_name);
@@ -113,6 +125,10 @@ $.require = function (file, func) {
113
125
  throw new TypeError('第二个参数(func)必须是函数');
114
126
  }
115
127
 
128
+ if (_isBuiltin(file)) {
129
+ return require(file);
130
+ }
131
+
116
132
  let mod = $.mod.load(file, func);
117
133
  if (mod !== null) {
118
134
  return mod;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.5.1",
3
+ "version": "3.5.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": {