nodejs / repl Goto Github PK
View Code? Open in Web Editor NEWREPL rewrite for Node.js โจ๐ข๐โจ
License: MIT License
REPL rewrite for Node.js โจ๐ข๐โจ
License: MIT License
I am a little surprised that autocomplete
works differently from any other major implementation like Bash, ZSH etc.
The only way to use a suggested completion is press "right" key which is located to the side of the keyboard and requires a very inconvenient hand move.
Don't you want to really complete the expression when there is only one variant or otherwise list variants like in Bash?
That's a shortcut that works in the default repl, in bash and most editors
I tried to implement it, but couldn't detect Fn there https://github.com/nodejs/repl/blob/master/src/tty.js#L156
Should we make it clear that this is not designed to work on Node.js builds with inspector disabled? Or should we try to make it work? (I fear that a REPL that doesn't work with some Node.js configurations may be difficult to be accepted to core.)
Attempting to run
C:\Users\username>node-prototype-repl
On Windows 10 with Node.js v8.12.0
, the latest Node.js LTS version (as of writing), results in this fatal error:
C:\Users\username\AppData\Roaming\npm\node_modules\@nodejs\repl\src\repl.js:227
} catch {} // eslint-disable-line no-empty
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\username\AppData\Roaming\npm\node_modules\@nodejs\repl\src\index.js:7:14)
I am sorry if this is the wrong place to ask, but I couldn't find a relevant mailing list / forum.
[Attempts to get an answer on Discord and Reddit failed.]
I am using using Node in terminal with the Solarized Dark theme.
Invoking Node with node
, that is, I am using the standard repl fromlib/repl.js
I am quite happy with the colors, except the colors for completions
(the last, black line in the image show such a completion)
and the colors for stack traces. The black color used for completions and
traces are difficult to read on the dark background.
Now since I am not the only one using a dark theme in the terminal,
I thought, I could easily lookup how to change the colors.
According to the manual for lib/repl.js
something called "styles" are supported,
but I can't figure out which style is used for completions.
The standard color my terminal is gray, so somewhere in the code for lib/repl.js
there must be a color change to black.
Have I overlooked a simple solution?
If not, can you point me to the relevant section of code in lib/repl.js
?
Because oneLineEval()
returns undefined
, and then onAutocomplete()
will return [undefined]
.
node's default repl can autocomplete in a require('
I might give it a try
This is a feature I've been eagerly searching for in a Node REPL.
I have found readline-vim, which provides Vim keybindings support for the readline module, but it doesn't look like this project uses that?
For reference, GNU Readline supports vi mode, as does Python's prompt_toolkit, and Zsh's Zsh Line Editor.
Thanks!
all the things need to be tested.
Could you explain how to point NODE_REPL_EXTERNAL_MODULE
to which node-prototype-repl
?
In the existing node
REPL (which uses readline, I think), pressing the left/right arrow keys while holding down control jumps the cursor to the end or beginning of a word, or to the next or previous word. (Take that sentence with a grain of salt; I don't know exactly how it works, but it's still a feature I make frequent use of.) See the following diagram for an example; each |
is a stop where the cursor moves to when you press ctrl-left/right:
console.log("Hello, world!")
| || | | | | | |
The same stops are used when pressing left or right.
By the looks of it, the stops are placed at the first character of every word (which are alphanumeric, I think) and the first character of a chunk of symbols (e.g. .
, ("
, ,
, !)"
).
Repeated tabbing isn't the best way, and we also don't currently have a way to go back up in the list of completions (Shift-Tab).
This is a feature request to implement a similar existing feature In the chrome console on NodeJs REPL.
> asyncTaskThatResolvesNumber();
Promise<pending>
// chrome console
> await asyncTaskThatResolvesNumber();
123
// nodejs repl
> await asyncTaskThatResolvesNumber();
await asyncTaskThatResolvesNumber()
^^^^^
Uncaught:
SyntaxError: await is only valid in async functions and the top level bodies of modules
I think this can be very helpful for debugging or just quick trying out stuff. Current workaround I use is
> asyncTaskThatResolvesNumber().then(console.log)
And can't visit the page: https://www.npmjs.com/package/@nodejs/repl .
But I can install via npm.
See Runtime.releaseObjectGroup
. DevTools uses it for autocompletion.
I'm currently working with big files and try to manipulate them with a few JS lines here and there and sometimes the REPL crashes because it's running out of memory - which is fine, that's just the way it is.
But what I noticed here is that it's not saving the executed line to the history unless it's still alive after (so I pretty much lose the line that caused the termination).
I would like to propose a change so that it first appends to history (and saves the file?) and then executes the input.
๐ Hi @devsnek. I'm curious what the status of this project is โ I've been poking around improving the existing node REPL a bit, and came across this repo. Is there a plan to eventually move it into mainline node? If yes, do you have an idea of the features that are missing/work that remains to be done in your opinion before heading in that direction? And, how much latitude do you feel there is to break the existing REPLServer interface?
Directly evaluating Number.MIN_VALUE
should return the value 5e-324
.
Operating on Number.MIN_VALUE
should return the correct result.
Directly evaluating Number.MIN_VALUE
instantly kills / exits the REPL process. No stacktrace or output is printed. This only occurs when evaluated directly, ie. console.log(Number.MIN_VALUE)
prints correctly without exiting.
The automatic evaluation that prints as a comment on the same line before pressing enter still displays correctly (> Number.MIN_VALUE // 5e-324
).
Performing addition, subtraction, and division operations on Number.MIN_VALUE
returns incorrect results. Performing multiplication on Number.MIN_VALUE
causes the REPL process to exit as well.
Concatenating a string with Number.MIN_VALUE
does return the correct result without exiting.
This behavior only occurs with Number.MIN_VALUE
, evaluating and operating on Number.MAX_VALUE
returns correctly.
Exit on evaluation:
$ node-prototype-repl
Node.js v12.8.1 (V8 7.5.288.22-node.16)
Prototype REPL - https://github.com/nodejs/repl
> Number.MIN_VALUE // 5e-324
$
Incorrect arithmetic results and exiting on multiplication:
$ node-prototype-repl
Node.js v12.8.1 (V8 7.5.288.22-node.16)
Prototype REPL - https://github.com/nodejs/repl
> Number.MIN_VALUE + 100 // 100
100
> Number.MIN_VALUE - 100 // -100
-100
> Number.MIN_VALUE / 100 // 0
0
> Number.MIN_VALUE * 100 // 4.94e-322
$
Correct evaluation when concatenating with a string:
$ node-prototype-repl
Node.js v12.8.1 (V8 7.5.288.22-node.16)
Prototype REPL - https://github.com/nodejs/repl
> Number.MIN_VALUE + 'Test' // '5e-324Test'
'5e-324Test'
Currently node's repl is pretty painful when dealing with multiline expressions/statements like:
Point = class {
x; y;
constructor(x, y) {
this.x = x;
this.yy = y;
}
}
After entering such an expression often you'll notice is has an error somewhere, however to fix the error it'll generally involve going back to each line in order and entering it again e.g.:
https://1drv.ms/v/s!AqOK_5mhCFkag7VLMCfWVeCX_IFTtA?e=I6ikhd
Now chrome devtools/ndb has a nice feature in that a single up arrow goes to the last set of statements evaluated and be navigated entirely using a keyboard using Enter
and Shift-Enter
to navigate e.g.:
https://1drv.ms/v/s!AqOK_5mhCFkag7VMdWd_CJqhe_X9Ig?e=Gm86DL
I'd like to propose doing the same with Node's REPL.
It's a lot easier to work with as you don't need to do a bunch of up-arrows to re-enter every single line of the previous expression in order to fix it. The current behavior is also pretty error prone, especially for functions where you might accidentally re-order statements creating new errors and hence having to redo them all over again.
Hello,
Looks like the current repl doesn't support multiline expression. I was looking at the source code, guess we are passing the expression to Runtime.evaluate
over here : https://github.com/nodejs/repl/blob/master/src/repl.js#L68
Not sure, whether the session's Runtime.evaluate
supports multilines. But looking at the protocol from here: https://chromium.googlesource.com/v8/v8/+/master/src/inspector/js_protocol.json, I doubt it has the support.
Still trying to find a reliable way to reproduce but this has happened a few times.
Most repl's I've used before allow you to quickly get a previous command back by using the Ctrl+r key to search the command history. It makes life so much easier when you're testing stuff out. Any chance this could be implemented for the nodejs repl?
Version: Node.js 17.6.0 (V8 9.6.180.15-node.13)
on iTerm2, Build 3.4.16.
System: Darwin MacPro.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101 arm64
It's exactly the same issue as the one described here. https://jira.mongodb.org/browse/MONGOSH-730
Quoted the problem description:
When I type at the prompt I can see the cursor going to the beginning of the line and come back, causing a very annoying and distracting flicker. I'm using mongosh 0.12.0, MacOS Catalina and iTerm2 3.4.5
I can still reproduce the same problem while using iTerm2 shell with node-prototype-repl
. Any ideas to fix this issue?
Missing package version
bin:
key in the package.json so that a shell command can be exported?We are going through all of the node.js repositories to rename the primary branch to main. Please see nodejs/node#33864 for more context.
I don't see any references to the master branch so I don't think the rename will cause any issues.
Please let me know if you have any concerns by June 26th, otherwise I'll go ahead with the rename.
Any plans for supporting older versions of Node? Looks like Node 8 is failing because of generator syntax usage.
Thanks!
getProperties
doesn't allow any sort of timeout, so it will take forever for an object like Array(1000000).fill(0)
Hello,
I guess with this commit : e06c75c
Error stacktrace is missing outside repl context too. For example, when I was working on this PR : #17
I noticed when assertions failed, the stack trace was missing. I saw only the below:
assert.js:269
throw err;
^
AssertionError [ERR_ASSERTION]: should throw syntax error
at
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.