-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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()`.
Not sure if |
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) |
Yeah, I started to update the docs prior to the PR, but figured it would be better to work out these details first. |
Note: |
@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 |
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. |
cc @chrisdickinson who originally made this functionality (and kept it private) |
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. |
@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. |
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. |
@@ -1141,6 +1141,165 @@ REPLServer.prototype.convertToContext = function(cmd) { | |||
return cmd; | |||
}; | |||
|
|||
REPLServer.prototype.setupHistory = function(historyPath, oldHistoryPath, cb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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. |
@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. |
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. |
If there is anything else you all want to see addressed in this PR, let me Lance On Sunday, April 10, 2016, Benjamin Gruenbaum [email protected]
Lance Ball |
Merge or close or modify? Tidying up loose ends. |
7da4fd4
to
c7066fb
Compare
Let's close it until there is a stronger need for it? |
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.js
to the public facing
REPLServer
API. Default behavior has not changedfor either the command line or the programmatic REPL. The
createInternalRepl
function used bysrc/node.js
now simply callssetupHistory()
on theREPLServer
it creates.History size for the programmatic REPL may be controlled by providing a
value for the heretofore undocumented
historySize
in the options forrepl.start()
.