Skip to content

Commit 6796bf4

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. PR-URL: #10296 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9d0220c commit 6796bf4

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ ArrayStream.prototype.writable = true;
794794
ArrayStream.prototype.resume = function() {};
795795
ArrayStream.prototype.write = function() {};
796796

797-
const requireRE = /\brequire\s*\(['"](([\w./-]+\/)?([\w./-]*))/;
797+
const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?([\w@./-]*))/;
798798
const simpleExpressionRE =
799799
/(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/;
800800

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

+1
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

+18-3
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)