nodejs / nodejs/node

Add ability to suppress `.command`s in REPL

Open
#57,989 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request never-stale repl
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

What is the problem this feature will solve?

I'm building a custom shell-like REPL for an application that's written in Javascript. To achieve this, I'm using the REPL module because it's more feature-rich than the readline module (for example, using ctrl+r (and looking through the Node code, I couldn't actually find where this functionality is defined...)). It's also much easier to work with than the readline module.

However, I'm trying to secure the application as best as possible so my users don't fall into holes when trying to execute commands, and so I'm restricting access to the REPL dot commands of .editor, .help, etc. I would also like to take advantage of the .commands in my own eval function so I can also extend the functionality of my REPL too.

Specifically: the problem this feature will solve is to allow .commands through to the eval function. Some guard rails will probably need to be put in place (such as making sure the default eval isn't being used, or writing a warning in the docs).

What is the feature you are proposing to solve the problem?

Add an optional property to the ReplOptions called nativeDotCommands (or whatever fits), and adjust the if statement to account for this property (and likely adjustments to other parts of the codebase)

What alternatives have you considered?

Currently, I'm setting repl.commands = {} to remove all the commands, however of course this is throwing an error from my linter because that property is read-only. I can suppress the error, but that still doesn't allow me to use .commands within my application. So far, this is the best work around I've got (short of rewriting and using the readline module.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/repl.js at the linked if statement and inspect the ReplOptions definition and how repl.commands is exposed. Trace how dot commands are currently handled, then determine how an optional nativeDotCommands setting could allow them to reach a custom eval without weakening the default behavior. Done means custom REPLs can receive dot commands while the existing default handling remains protected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.