Skip to content

Commit d04b6ff

Browse files
committed
repl: allow autocompletion for scoped packages
Previously, autocompletion of scoped packages was not supported by the repl due to not including the `@` character in the regular expression.
1 parent 0cd1f54 commit d04b6ff

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ ArrayStream.prototype.writable = true;
788788
ArrayStream.prototype.resume = function() {};
789789
ArrayStream.prototype.write = function() {};
790790

791-
const requireRE = /\brequire\s*\(['"](([\w./-]+\/)?([\w./-]*))/;
791+
const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?([\w@./-]*))/;
792792
const simpleExpressionRE =
793793
/(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/;
794794

test/fixtures/node_modules/@nodejsscope/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/parallel/test-repl-tab-complete.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
'use strict';
22

3-
var common = require('../common');
4-
var assert = require('assert');
5-
var repl = require('repl');
3+
const common = require('../common');
4+
const assert = require('assert');
5+
6+
// We have to change the directory to ../fixtures before requiring repl
7+
// in order to make the tests for completion of node_modules work properly
8+
// since repl modifies module.paths.
9+
process.chdir(common.fixturesDir);
10+
11+
const repl = require('repl');
612

713
function getNoResultsFunction() {
814
return common.mustCall((err, data) => {
@@ -196,6 +202,15 @@ testMe.complete('require(\'n', common.mustCall(function(error, data) {
196202
});
197203
}));
198204

205+
{
206+
const expected = ['@nodejsscope', '@nodejsscope/'];
207+
putIn.run(['.clear']);
208+
testMe.complete('require(\'@nodejs', common.mustCall((err, data) => {
209+
assert.strictEqual(err, null);
210+
assert.deepStrictEqual(data, [expected, '@nodejs']);
211+
}));
212+
}
213+
199214
// Make sure tab completion works on context properties
200215
putIn.run(['.clear']);
201216

0 commit comments

Comments
 (0)