Skip to content
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

feat: command history #757

Closed
wants to merge 2 commits into from
Closed

Conversation

aleclarson
Copy link

@aleclarson aleclarson commented Jan 21, 2019

Try upgrading to the latest Node 11 if you experience any issues. Looks like they had to revert a buggy feature in 11.4.0 (nodejs/node#24804).

Nothing crazy going on here. Just basic history support! 😄

  • The file path defaults to ~/.ts_node_history
  • The size limit defaults to 1000
  • $TS_NODE_HISTORY can be used to customize the file path
  • $TS_NODE_HISTORY_SIZE can be used to limit the number of saved lines
  • When $TS_NODE_HISTORY is an empty string, history is disabled
  • When $TS_NODE_HISTORY_SIZE is zero, history is disabled

Closes #259

Try upgrading to the latest Node 11 if you experience any issues.

Closes TypeStrong#259
@coveralls
Copy link

Coverage Status

Coverage remained the same at 84.946% when pulling c575d04 on aleclarson:history into d58488b on TypeStrong:master.

repl.history = fs.readFileSync(file, 'utf8').split(os.EOL)
}
repl.on('exit', () => {
fs.writeFileSync(file, repl.history.join(os.EOL))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work with two processes running? It seems like one would just overwrite the other's history?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's how the node repl works. We could re-read the file in the exit listener and prepend/dedupe the repl.history, but I'd prefer someone else add that in another PR.

@aleclarson aleclarson mentioned this pull request Jan 21, 2019

// TODO: Use `repl: REPLServer` when history-related properties are added to @types/node
export function useHistory (repl: any) {
repl.historySize = process.env.TS_NODE_HISTORY !== ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a place for configuration loaded from environment variables, we should re-use that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer edits are enabled, if you want to help out.

@blakeembrey
Copy link
Member

Opted for the native implementation using https://nodejs.org/api/repl.html#repl_replserver_setuphistory_historypath_callback in 35d8a0c.

@blakeembrey blakeembrey closed this Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command history support
3 participants