nodejs / nodejs/node

Add ability to suppress `.command`s in REPL

未关闭
#57,989 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

feature request never-stale repl
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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.)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 lib/repl.js 中链接的 if 语句开始,检查 ReplOptions 的定义以及 repl.commands 的公开方式。跟踪点命令当前的处理方式,然后确定可选的 nativeDotCommands 设置如何允许它们到达自定义 eval,同时不削弱默认行为。当自定义 REPL 能够接收点命令,同时现有的默认处理仍受到保护时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
cli
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。