Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1610,6 +1610,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,
Expand Down
13 changes: 11 additions & 2 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,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) {
Expand Down