From d78f505d0574f862d6ba634036a6f77d90e206b7 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Wed, 22 Jul 2015 09:45:41 -0700 Subject: [PATCH] repl: save to a default file in the home tmp directory --- lib/internal/repl.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/internal/repl.js b/lib/internal/repl.js index f56068345e412a..34707278088258 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -3,6 +3,7 @@ const Interface = require('readline').Interface; const REPL = require('repl'); const path = require('path'); +const fs = require('fs'); const os = require('os'); module.exports = Object.create(REPL); @@ -52,7 +53,7 @@ function createRepl(env, cb) { } const repl = REPL.start(opts); - if (opts.terminal && env.NODE_REPL_HISTORY_FILE) { + if (opts.terminal) { return setupHistory(repl, env.NODE_REPL_HISTORY_FILE, cb); } repl._historyPrev = _replHistoryMessage; @@ -60,7 +61,17 @@ function createRepl(env, cb) { } function setupHistory(repl, historyPath, ready) { - const fs = require('fs'); + // default to using /tmp/node_history_file + if (typeof historyPath !== 'string') { + const tmpdir = path.join(os.homedir(), 'tmp') + try { + fs.mkdirSync(tmpdir); + } catch (err) { + if (err.code !== 'EEXIST') throw err; + } + historyPath = path.join(tmpdir, 'node_repl_history'); + } + var timer = null; var writing = false; var pending = false;