Skip to content

Commit

Permalink
repl: allow autocompletion for scoped packages
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
evanlucas committed Jan 3, 2017
1 parent 456248d commit a402652
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ ArrayStream.prototype.writable = true;
ArrayStream.prototype.resume = function() {};
ArrayStream.prototype.write = function() {};

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

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/node_modules/@nodejsscope/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use strict';

var common = require('../common');
var assert = require('assert');
var repl = require('repl');
const common = require('../common');
const assert = require('assert');

// We have to change the directory to ../fixtures before requiring repl
// in order to make the tests for completion of node_modules work properly
// since repl modifies module.paths.
process.chdir(common.fixturesDir);

const repl = require('repl');

function getNoResultsFunction() {
return common.mustCall((err, data) => {
Expand Down Expand Up @@ -196,6 +202,15 @@ testMe.complete('require(\'n', common.mustCall(function(error, data) {
});
}));

{
const expected = ['@nodejsscope', '@nodejsscope/'];
putIn.run(['.clear']);
testMe.complete('require(\'@nodejs', common.mustCall((err, data) => {
assert.strictEqual(err, null);
assert.deepStrictEqual(data, [expected, '@nodejs']);
}));
}

// Make sure tab completion works on context properties
putIn.run(['.clear']);

Expand Down

0 comments on commit a402652

Please sign in to comment.