Skip to content

Commit 051d482

Browse files
repl: fix _debugger by properly proxying repl
The _debugger module uses the internal REPL module, but expects to receive the userland REPL module. This fixes the breakage that occurs by proxying the userland REPL module through the internal module. It also fixes an unintended in-REPL bug, where require(node-module) was not resolving correctly. PR-URL: #1605 Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent e67542a commit 051d482

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

lib/internal/repl.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
'use strict';
22

3-
module.exports = {createRepl: createRepl};
4-
53
const Interface = require('readline').Interface;
64
const REPL = require('repl');
75
const path = require('path');
86

7+
module.exports = Object.create(REPL);
8+
module.exports.createInternalRepl = createRepl;
9+
910
// XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary.
1011
// The debounce is to guard against code pasted into the REPL.
1112
const kDebounceHistoryMS = 15;
1213

13-
try {
14-
// hack for require.resolve("./relative") to work properly.
15-
module.filename = path.resolve('repl');
16-
} catch (e) {
17-
// path.resolve('repl') fails when the current working directory has been
18-
// deleted. Fall back to the directory name of the (absolute) executable
19-
// path. It's not really correct but what are the alternatives?
20-
const dirname = path.dirname(process.execPath);
21-
module.filename = path.resolve(dirname, 'repl');
14+
// XXX(chrisdickinson): hack to make sure that the internal debugger
15+
// uses the original repl.
16+
function replStart() {
17+
return REPL.start.apply(REPL, arguments);
2218
}
2319

24-
// hack for repl require to work properly with node_modules folders
25-
module.paths = require('module')._nodeModulePaths(module.filename);
26-
2720
function createRepl(env, cb) {
2821
const opts = {
2922
ignoreUndefined: false,

lib/repl.js

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ const Console = require('console').Console;
3232
const domain = require('domain');
3333
const debug = util.debuglog('repl');
3434

35+
try {
36+
// hack for require.resolve("./relative") to work properly.
37+
module.filename = path.resolve('repl');
38+
} catch (e) {
39+
// path.resolve('repl') fails when the current working directory has been
40+
// deleted. Fall back to the directory name of the (absolute) executable
41+
// path. It's not really correct but what are the alternatives?
42+
const dirname = path.dirname(process.execPath);
43+
module.filename = path.resolve(dirname, 'repl');
44+
}
45+
46+
// hack for repl require to work properly with node_modules folders
47+
module.paths = require('module')._nodeModulePaths(module.filename);
48+
3549
// If obj.hasOwnProperty has been overridden, then calling
3650
// obj.hasOwnProperty(prop) will break.
3751
// See: https://github.com/joyent/node/issues/1707

src/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
// If -i or --interactive were passed, or stdin is a TTY.
131131
if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
132132
// REPL
133-
Module.requireRepl().createRepl(process.env, function(err, repl) {
133+
Module.requireRepl().createInternalRepl(process.env, function(err, repl) {
134134
if (err) {
135135
throw err;
136136
}

0 commit comments

Comments
 (0)