diff --git a/lib/repl.js b/lib/repl.js index d5d9371de34428..78274b6af1daea 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -126,6 +126,8 @@ let _builtinLibs = ArrayPrototypeFilter( CJSModule.builtinModules, (e) => !StringPrototypeStartsWith(e, '_') && !StringPrototypeIncludes(e, '/') ); +const nodeSchemeBuiltinLibs = ArrayPrototypeMap( + _builtinLibs, (lib) => `node:${lib}`); const domain = require('domain'); let debug = require('internal/util/debuglog').debuglog('repl', (fn) => { debug = fn; @@ -1105,7 +1107,7 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) { ReflectApply(Interface.prototype.setPrompt, this, [prompt]); }; -const requireRE = /\brequire\s*\(\s*['"`](([\w@./-]+\/)?(?:[\w@./-]*))(?![^'"`])$/; +const requireRE = /\brequire\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])$/; const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/; const simpleExpressionRE = /(?:[a-zA-Z_$](?:\w|\$)*\??\.)*[a-zA-Z_$](?:\w|\$)*\??\.?$/; @@ -1267,7 +1269,7 @@ function complete(line, callback) { } if (!subdir) { - ArrayPrototypePush(completionGroups, _builtinLibs); + ArrayPrototypePush(completionGroups, _builtinLibs, nodeSchemeBuiltinLibs); } } else if (RegExpPrototypeTest(fsAutoCompleteRE, line) && this.allowBlockingCompletions) { diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index bfcf810ddd6125..9a98f94c021354 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -31,6 +31,10 @@ const assert = require('assert'); const path = require('path'); const fixtures = require('../common/fixtures'); const { builtinModules } = require('module'); +const publicModules = builtinModules.filter( + (lib) => !lib.startsWith('_') && !lib.includes('/'), +); + const hasInspector = process.features.inspector; if (!common.isMainThread) @@ -239,9 +243,9 @@ putIn.run(['.clear']); testMe.complete('require(\'', common.mustCall(function(error, data) { assert.strictEqual(error, null); - builtinModules.forEach((lib) => { + publicModules.forEach((lib) => { assert( - data[0].includes(lib) || lib.startsWith('_') || lib.includes('/'), + data[0].includes(lib) && data[0].includes(`node:${lib}`), `${lib} not found` ); }); @@ -258,6 +262,10 @@ testMe.complete("require\t( 'n", common.mustCall(function(error, data) { assert.strictEqual(error, null); assert.strictEqual(data.length, 2); assert.strictEqual(data[1], 'n'); + // require(...) completions include `node:`-prefixed modules: + publicModules.forEach((lib, index) => + assert.strictEqual(data[0][index], `node:${lib}`)); + assert.strictEqual(data[0][publicModules.length], ''); // There is only one Node.js module that starts with n: assert.strictEqual(data[0][0], 'net'); assert.strictEqual(data[0][1], '');