From b918eaf8917ebcf45814de524f056a4c255f9758 Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Mon, 4 May 2015 01:40:40 -0700 Subject: [PATCH 1/3] repl: fix _debugger by properly proxying repl --- lib/internal/repl.js | 21 +++++++-------------- lib/repl.js | 14 ++++++++++++++ src/node.js | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 5faecae53fe5a5..65c3f77ed6abb9 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -1,29 +1,22 @@ 'use strict'; -module.exports = {createRepl: createRepl}; - const Interface = require('readline').Interface; const REPL = require('repl'); const path = require('path'); +module.exports = Object.create(REPL); +module.exports.createInternalRepl = createRepl; + // XXX(chrisdickinson): The 15ms debounce value is somewhat arbitrary. // The debounce is to guard against code pasted into the REPL. const kDebounceHistoryMS = 15; -try { - // hack for require.resolve("./relative") to work properly. - module.filename = path.resolve('repl'); -} catch (e) { - // path.resolve('repl') fails when the current working directory has been - // deleted. Fall back to the directory name of the (absolute) executable - // path. It's not really correct but what are the alternatives? - const dirname = path.dirname(process.execPath); - module.filename = path.resolve(dirname, 'repl'); +// XXX(chrisdickinson): hack to make sure that the internal debugger +// uses the original repl. +function replStart() { + return REPL.start.apply(REPL, arguments); } -// hack for repl require to work properly with node_modules folders -module.paths = require('module')._nodeModulePaths(module.filename); - function createRepl(env, cb) { const opts = { ignoreUndefined: false, diff --git a/lib/repl.js b/lib/repl.js index 95a30c05fc07f5..45bc49b513be52 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -32,6 +32,20 @@ const Console = require('console').Console; const domain = require('domain'); const debug = util.debuglog('repl'); +try { + // hack for require.resolve("./relative") to work properly. + module.filename = path.resolve('repl'); +} catch (e) { + // path.resolve('repl') fails when the current working directory has been + // deleted. Fall back to the directory name of the (absolute) executable + // path. It's not really correct but what are the alternatives? + const dirname = path.dirname(process.execPath); + module.filename = path.resolve(dirname, 'repl'); +} + +// hack for repl require to work properly with node_modules folders +module.paths = require('module')._nodeModulePaths(module.filename); + // If obj.hasOwnProperty has been overridden, then calling // obj.hasOwnProperty(prop) will break. // See: https://github.com/joyent/node/issues/1707 diff --git a/src/node.js b/src/node.js index 5cf56f624225ee..2d6ce45a928d29 100644 --- a/src/node.js +++ b/src/node.js @@ -130,7 +130,7 @@ // If -i or --interactive were passed, or stdin is a TTY. if (process._forceRepl || NativeModule.require('tty').isatty(0)) { // REPL - Module.requireRepl().createRepl(process.env, function(err, repl) { + Module.requireRepl().createInternalRepl(process.env, function(err, repl) { if (err) { throw err; } From cba0b28b1848e01d8716bac38dc8f4bc2478ba21 Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Mon, 4 May 2015 08:56:14 -0700 Subject: [PATCH 2/3] repl: hacky fix for a+ fd clearing the file on read --- lib/internal/repl.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 65c3f77ed6abb9..902e81f495573c 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -107,8 +107,13 @@ function setupHistory(repl, historyPath, ready) { } repl._historyHandle = hnd; repl.on('line', online); - repl.resume(); - return ready(null, repl); + + // reading the file data out erases it + repl.once('flushHistory', function() { + repl.resume(); + ready(null, repl); + }); + flushHistory(); } // ------ history listeners ------ From e43fa1824874bd055c85fff3082f5f3bb305295f Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Mon, 4 May 2015 09:11:55 -0700 Subject: [PATCH 3/3] fix line length --- src/node.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index 2d6ce45a928d29..bd8ef5b04ef8a2 100644 --- a/src/node.js +++ b/src/node.js @@ -130,7 +130,8 @@ // If -i or --interactive were passed, or stdin is a TTY. if (process._forceRepl || NativeModule.require('tty').isatty(0)) { // REPL - Module.requireRepl().createInternalRepl(process.env, function(err, repl) { + var cliRepl = Module.requireRepl(); + cliRepl.createInternalRepl(process.env, function(err, repl) { if (err) { throw err; }