Skip to content

Commit 1080338

Browse files
committed
expose and document loadedModules instead of moduleLoadList
1 parent 635af17 commit 1080338

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

doc/api/process.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,29 +2858,29 @@ console.log(memoryUsage.rss());
28582858
// 35655680
28592859
```
28602860
2861-
## `process.moduleLoadList`
2861+
## `process.loadedModules`
28622862
28632863
<!-- YAML
28642864
added: v0.5.3
28652865
-->
28662866
28672867
* Type: {string\[]}
28682868
2869-
The `process.moduleLoadList` property returns an array of internal bindings and core modules that
2869+
The `process.loadedModules` property returns an array of core modules that
28702870
were loaded during the current Node.js process execution.
28712871
28722872
```mjs
2873-
import { moduleLoadList } from 'node:process';
2873+
import { loadedModules } from 'node:process';
28742874

2875-
console.log(moduleLoadList);
2876-
// ['Internal Binding builtins', 'Internal Binding module_wrap', 'Internal Binding errors', ...]
2875+
console.log(loadedModules);
2876+
// ['events', 'buffer', 'diagnostics_channel', 'async_hooks', ...]
28772877
```
28782878
28792879
```cjs
2880-
const { moduleLoadList } = require('node:process');
2880+
const { loadedModules } = require('node:process');
28812881

2882-
console.log(moduleLoadList);
2883-
// ['Internal Binding builtins', 'Internal Binding module_wrap', 'Internal Binding errors', ...]
2882+
console.log(loadedModules);
2883+
// ['events', 'buffer', 'diagnostics_channel', 'async_hooks', ...]
28842884
```
28852885
28862886
## `process.nextTick(callback[, ...args])`

lib/internal/bootstrap/realm.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ ObjectDefineProperty(process, 'moduleLoadList', {
8080
writable: false,
8181
});
8282

83+
// Set up process.loadedModules
84+
const loadedModules = [];
85+
ObjectDefineProperty(process, 'loadedModules', {
86+
__proto__: null,
87+
get() { return ArrayPrototypeSlice(loadedModules); },
88+
configurable: true,
89+
enumerable: true,
90+
})
8391

8492
// processBindingAllowList contains the name of bindings that are allowed
8593
// for access via process.binding(). This is used to provide a transition
@@ -405,6 +413,9 @@ class BuiltinModule {
405413
// "NativeModule" is a legacy name of "BuiltinModule". We keep it
406414
// here to avoid breaking users who parse process.moduleLoadList.
407415
ArrayPrototypePush(moduleLoadList, `NativeModule ${id}`);
416+
if(!StringPrototypeStartsWith(id, 'internal/')) {
417+
ArrayPrototypePush(loadedModules, id);
418+
}
408419
return this.exports;
409420
}
410421
}

0 commit comments

Comments
 (0)