repl: add repl.setupHistory for programmatic repl
Adds a repl.setupHistory()
instance method so that programmatic REPLs can also write history to a file without the need to implement this functionality in userland.
This change also refactors all of the history file management to lib/internal/repl/history.js
, cleaning up and simplifying lib/internal/repl.js
.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines
This has been done and rejected in the past in https://github.com/nodejs/node/pull/5789. The PR was rejected due to a desire to keep the surface area of the REPL API small. However, there have been additional requests to have this issue reopened here, and I thought I'd give it another go.
If there is consensus on moving forward with this, I will add documentation.
If, ultimately, we decide not to merge this, I think the refactoring of the history file functionality into lib/internal/repl/history.js
is worthwhile, makes the code easier to read, and does not change the API.
EDIT documentation has been added to repl.md
. I'm not sure what to put for the version number in the documentation YAML. I've made it v11.9.1, but not sure if this just gets modified when landing. I couldn't find anything in the collaborator's guide which addresses this issue.