From 6d92391d5ba881fa723c3992d26ec7b1b22bdcfe Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 15 Dec 2016 17:24:17 -0600 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/10296 Reviewed-By: Prince John Wesley Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Jeremiah Senkpiel Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- lib/repl.js | 2 +- .../node_modules/@nodejsscope/index.js | 1 + test/parallel/test-repl-tab-complete.js | 21 ++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/node_modules/@nodejsscope/index.js diff --git a/lib/repl.js b/lib/repl.js index 487dd880743b3a..760182ebe4ebba 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -795,7 +795,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|\$)*)\.?$/; diff --git a/test/fixtures/node_modules/@nodejsscope/index.js b/test/fixtures/node_modules/@nodejsscope/index.js new file mode 100644 index 00000000000000..b42ff442aee734 --- /dev/null +++ b/test/fixtures/node_modules/@nodejsscope/index.js @@ -0,0 +1 @@ +// Not used diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index e8fc5b1863caa3..dfda790c439d97 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -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) => { @@ -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']);