repl: add builtinModules

This adds an alias to `_builtinLibs` that is documented and should
as such also be accessed publicly. It does not contain any
underscored modules.

Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>

PR-URL: https://github.com/nodejs/node/pull/33295
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Ruben Bridgewater authored and Shelley Vohr committed 2020-06-30 09:33:37 -07:00
1 parent f98e927523
commit 36f3ccda1f
3 files changed
+28 -3

No files matched your search

+9
View File
@@ -540,6 +540,15 @@ by default. However, this is not the case when creating a REPL
programmatically. Use this method to initialize a history log file when working
with REPL instances programmatically.
## `repl.builtinModules`
<!-- YAML
added: REPLACEME
-->
* {string[]}
A list of the names of all Node.js modules, e.g., `'http'`.
## `repl.start([options])`
<!-- YAML
added: v0.1.91
+8 -1
View File
@@ -86,7 +86,7 @@ const {
const { Console } = require('console');
const CJSModule = require('internal/modules/cjs/loader').Module;
let _builtinLibs = [...CJSModule.builtinModules]
.filter((e) => !e.startsWith('_'));
.filter((e) => !e.startsWith('_') && !e.includes('/'));
const domain = require('domain');
const debug = require('internal/util/debuglog').debuglog('repl');
const {
@@ -1593,6 +1593,13 @@ module.exports = {
Recoverable
};
ObjectDefineProperty(module.exports, 'builtinModules', {
get: () => _builtinLibs,
set: (val) => _builtinLibs = val,
enumerable: true,
configurable: true
});
ObjectDefineProperty(module.exports, '_builtinLibs', {
get: pendingDeprecation ? deprecate(
() => _builtinLibs,
+11 -2
View File
@@ -237,9 +237,18 @@ putIn.run(['.clear']);
testMe.complete('require(\'', common.mustCall(function(error, data) {
assert.strictEqual(error, null);
builtinModules.forEach((lib) => {
if (!lib.startsWith('_'))
assert(data[0].includes(lib), `${lib} not found`);
assert(
data[0].includes(lib) || lib.startsWith('_') || lib.includes('/'),
`${lib} not found`
);
});
const newModule = 'foobar';
assert(!builtinModules.includes(newModule));
repl.builtinModules.push(newModule);
testMe.complete('require(\'', common.mustCall((_, [modules]) => {
assert.strictEqual(data[0].length + 1, modules.length);
assert(modules.includes(newModule));
}));
}));
testMe.complete("require\t( 'n", common.mustCall(function(error, data) {