From 4c22d6eaa1aba14b199f929bb8cf3d8b4759d021 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Fri, 1 Feb 2019 12:49:16 -0500 Subject: [PATCH] repl: add repl.setupHistory for programmatic repl Adds a `repl.setupHistory()` instance method so that programmatic REPLs can also write history to a file. This change also refactors all of the history file management to `lib/internal/repl/history.js`, cleaning up and simplifying `lib/internal/repl.js`. PR-URL: https://github.com/nodejs/node/pull/25895 Reviewed-By: Daniel Bevenius --- doc/api/repl.md | 16 ++ lib/internal/repl.js | 160 +----------- lib/internal/repl/history.js | 153 +++++++++++ lib/repl.js | 5 + node.gyp | 1 + .../test-repl-programmatic-history.js | 245 ++++++++++++++++++ 6 files changed, 422 insertions(+), 158 deletions(-) create mode 100644 lib/internal/repl/history.js create mode 100644 test/parallel/test-repl-programmatic-history.js diff --git a/doc/api/repl.md b/doc/api/repl.md index 60adbf641d1592..4395193de20326 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -448,6 +448,22 @@ deprecated: v9.0.0 An internal method used to parse and execute `REPLServer` keywords. Returns `true` if `keyword` is a valid keyword, otherwise `false`. +### replServer.setupHistory(historyPath, callback) + + +* `historyPath` {string} the path to the history file +* `callback` {Function} called when history writes are ready or upon error + * `err` {Error} + * `repl` {repl.REPLServer} + +Initializes a history log file for the REPL instance. When executing the +Node.js binary and using the command line REPL, a history file is initialized +by default. However, this is not the case when creating a REPL +programmatically. Use this method to initialize a history log file when working +with REPL instances programmatically. + ## repl.start([options])