Uh oh!
There was an error while loading. Please reload this page.
repl: Enables history for programmatic REPLs. - #5789
Conversation
The commit moves the `setupHistory()` function from `internal/repl.js` to the public facing `REPLServer` API. Default behavior has not changed for either the command line or the programmatic REPL. The `createInternalRepl` function used by `src/node.js` now simply calls `setupHistory()` on the `REPLServer` it creates. History size for the programmatic REPL may be controlled by providing a value for the heretofore undocumented `historySize` in the options for `repl.start()`.
lance
commented
Mar 18, 2016
Not sure if |
claudiorodriguez
commented
Mar 18, 2016
A doc update for either the historySize option, and/or setupHistory will definitely be needed if we're making this part of the REPLServer public API. Also, historySize as an option already features in some tests (test-repl and test-repl-options) |
lance
commented
Mar 18, 2016
Yeah, I started to update the docs prior to the PR, but figured it would be better to work out these details first. |
Fishrock123
commented
Mar 18, 2016
Note: |
lance
commented
Mar 18, 2016
@Fishrock123 I think it's both. Here the default history size is set on the REPL options. That value is used by REPLServer here to set the current in-memory history for |
Fishrock123
commented
Mar 18, 2016
Oh right, true. Still, I think the option should be kept where it is. It's just the nature of how things work that it also influences persistence, but that's hardly unwarranted. |
Fishrock123
commented
Mar 18, 2016
cc @chrisdickinson who originally made this functionality (and kept it private) |
benjamingr
commented
Mar 19, 2016
Are we sure we want to expose this? This is something external repls can implement in userland with a custom eval function and this increases API surface a little. |
victorb
commented
Mar 19, 2016
@benjamingr for me it makes sense to have the ability to use the same functionality no matter if the repl is accessed via the node binary or programmatically in my node program. Otherwise, it makes sense to remove the history from the node cli repl, which would be a loss I think. |
benjamingr
commented
Mar 19, 2016
I disagree, I think it often makes sense to not expose functionality publicly which lets us break internal APIs, make changes and not commit to a particular API. There are many things and internal modules in core that are not exposed to the public - this might be an exception and exposing it might be worth it but it's certainly not a "expose it or remove it" situation. |
| return cmd; | ||
| }; | ||
| REPLServer.prototype.setupHistory = function(historyPath, oldHistoryPath, cb) { |
There was a problem hiding this comment.
At very least, this would have to be refactored so that only the internal one uses oldHistoryPath -- no good in exposing deprecated functionality. :)
Another question this bears is, does the repl try to do this when you create it, or do you have to tell it to? The latter potentially has a race condition I think.
There was a problem hiding this comment.
That makes sense. My first jab at this was to keep the existing functionality as similar as possible, in order to get the discussion going without making assumptions or rocking the boat. FWIW, in this PR, oldHistoryPath is optional, so it wouldn't be required by the end user. But yes, it's cleaner to not expose this.
Currently, this is user controlled after the REPL has been created - similar to how it is now in createInternalRepl. I suppose, exposing it to the user as a post-creation action does introduce the race potential.
Fishrock123
commented
Mar 21, 2016
I'm -0, this isn't really painful to do in useland, but I'm not sure sure I can foresee maintenance problems with it either? Though, maybe it wait until we use proper file locks on the history? I'm not sure if doing that after the fact could be considered a breaking change. |
lance
commented
Mar 21, 2016
@benjamingr@victorbjelkholm I think you both have a valid point. It does make sense to keep the API footprint fairly small and tight. But I agree that providing consistency between the programmatic REPL and the CLI is valid. |
benjamingr
commented
Apr 10, 2016
We need to either move forward or close this. I tend towards not merging at this stage but I don't feel strongly about it and if other collaborators feel strongly I don't want to hold it back. |
lance
commented
Apr 10, 2016
If there is anything else you all want to see addressed in this PR, let me Lance On Sunday, April 10, 2016, Benjamin Gruenbaum notifications@github.com
Lance Ball |
lance
commented
Apr 25, 2016
Merge or close or modify? Tidying up loose ends. |
7da4fd4 to
c7066fbCompareFishrock123
commented
May 2, 2016
Let's close it until there is a stronger need for it? |
joniba
commented
Oct 8, 2018
I know this is really old, but since this PR wasn't merged, could someone provide an example of how to add this functionality on our own? |
Pull Request check-list
Please make sure to review and check all of these items:
make -j8 test(UNIX) orvcbuild test nosign(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
repl
Description of change
Addresses #5730
The commit moves the
setupHistory()function frominternal/repl.jsto the public facing
REPLServerAPI. Default behavior has not changedfor either the command line or the programmatic REPL. The
createInternalReplfunction used bysrc/node.jsnow simply callssetupHistory()on theREPLServerit creates.History size for the programmatic REPL may be controlled by providing a
value for the heretofore undocumented
historySizein the options forrepl.start().