summaryrefslogtreecommitdiff
path: root/lib/internal/repl.js
AgeCommit message (Collapse)Author
2019-02-11repl: add repl.setupHistory for programmatic replLance Ball
Adds a `repl.setupHistory()` instance method so that programmatic REPLs can also write history to a file. This change also refactors all of the history file management to `lib/internal/repl/history.js`, cleaning up and simplifying `lib/internal/repl.js`. PR-URL: https://github.com/nodejs/node/pull/25895 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2018-12-20lib: remove internal `util._extends()` usageRuben Bridgewater
This removes all internal calls to the deprecated `_extends()` function. It is slower than `Object.assign()` and the object spread notation since V8 6.8 and using the spread notation often also results in shorter code. PR-URL: https://github.com/nodejs/node/pull/25105 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-02-16lib: switch to Number.isNaNRuben Bridgewater
Number.isNaN is now as fast as `val !== val`. Switch to the more readable version. Also switch all `isNaN` to `Number.isNaN`. PR-URL: https://github.com/nodejs/node/pull/18744 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-02-12Revert "repl: refactor tests to not rely on timing"Ruben Bridgewater
This reverts commit de848ac1e0483327a2ce8716c3f8567eaeacb660. The commit broke multiline repl. PR-URL: https://github.com/nodejs/node/pull/18715 Refs: https://github.com/nodejs/node/pull/17828 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-02-12repl: remove deprecated NODE_REPL_HISTORY_FILERuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/13876 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-02-10repl: refactor tests to not rely on timingBradley Farias
Tests relying on synchronous timing have been migrated to use events. PR-URL: https://github.com/nodejs/node/pull/17828 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-12-06doc: use American spellings per style guideRich Trott
PR-URL: https://github.com/nodejs/node/pull/17471 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-10-16lib: use destructuring for some constantsWeijia Wang
This change is to unify the declaration for constants into using destructuring on the top-level-module scope, reducing some redundant code. PR-URL: https://github.com/nodejs/node/pull/16063 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-06-30repl: fix old history error handlingRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/13733 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-06-01errors,repl: migrate to use internal/errors.jssreepurnajasti
PR-URL: https://github.com/nodejs/node/pull/13299 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-05-02repl: fix /dev/null history file regressionBrian White
This fixes a regression from 83887f35fa where ftruncate() fails on a file symlinked to /dev/null. PR-URL: https://github.com/nodejs/node/pull/12762 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-04-20repl: support hidden history file on WindowsBartosz Sosnowski
On Windows when REPL history file has the hidden attribute node will fail when trying to open it in 'w' mode. This changes the mode to 'r+'. The file is guaranteed to exists because of earlier open call with 'a+'. Fixes: https://github.com/nodejs/node/issues/5261 PR-URL: https://github.com/nodejs/node/pull/12207 Reviewed-By: James M Snell <jasnell@gmail.com>
2017-03-06repl: docs-only deprecation of magic modeTimothy Gu
The workaround used in repl to support `let` and `const` in non-strict mode (known as "magic" mode) has been unnecessary since V8 v4.9 / Node.js v6.0.0. This commit doc-deprecate magic mode (which is now entirely equivalent to sloppy mode) in both `repl` module and in `internal/repl`, which is responsible for starting the REPL in `node` interactive mode. PR-URL: https://github.com/nodejs/node/pull/11599 Refs: https://v8project.blogspot.com/2016/01/v8-release-49.html Refs: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V6.md#6.0.0 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
2016-08-08repl: don't override all internal repl defaultscjihrig
The createInternalRepl() module accepts an options object as an argument. However, if one is provided, it overrides all of the default options. This commit applies the options object to the defaults, only changing the values that are explicitly set. PR-URL: https://github.com/nodejs/node/pull/7826 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-07-21repl: default useGlobal to truecjihrig
This is a partial revert of 15157c3c3d7594cefb7f5941cbe925657e7d88bd. This change lead to a regression that broke require() in the CLI REPL, as imported files were evaluated in a different context. Refs: https://github.com/nodejs/node/pull/5703 Fixes: https://github.com/nodejs/node/issues/7788 PR-URL: https://github.com/nodejs/node/pull/7795 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
2016-06-30repl: Default `useGlobal` to false in CLI REPL.Lance Ball
Documentation for REPL states that the default value of `useGlobal` is `false`. It makes no distinction between a REPL that is created programmatically, and the one a user is dropped into on the command line by executing `node` with no arguments. This change ensures that the CLI REPL uses a default value of `false`. Fixes: https://github.com/nodejs/node/issues/5659 Ref: https://github.com/nodejs/node/issues/6802 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> PR-URL: https://github.com/nodejs/node/pull/5703
2016-06-18repl: break on sigint/ctrl+cAnna Henningsen
Adds the ability to stop execution of the current REPL command when receiving SIGINT. This applies only to the default eval function. Fixes: https://github.com/nodejs/node/issues/6612 PR-URL: https://github.com/nodejs/node/pull/6635 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-11benchmark,test,lib: remove extra spacesRich Trott
In preparation for stricter linting, remove extra spaces. PR-URL: https://github.com/nodejs/node/pull/6645 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-05-04repl: create history file with mode 0600Carl Lei
Set the mode bits on the history file to 0o600 instead of leaving it unspecified, which resulted in 0o755 on Unices. Test code mostly written by Trott: https://github.com/nodejs/node/issues/3392#issuecomment-148634126. PR-URL: https://github.com/nodejs/node/pull/3394 Fixes: https://github.com/nodejs/node/issues/3392 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-16repl: make sure historyPath is trimmedEvan Lucas
If one were to set NODE_REPL_HISTORY to a string that contains only a space (" "), then the history file would be created with that name which can cause problems are certain systems. PR-URL: https://github.com/nodejs/node/pull/4539 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-12-26repl: remove unused functionRich Trott
replStart() was defined but never used. The function has been removed. Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-12-22repl: Fixed node repl history edge case.Mudit Ameta
If the deprecated NODE_REPL_HISTORY_FILE is set to default node history file path ($HOME/.node_repl_history) and the file doesn't exist, then node creates the file and then crashes when it tries to parse that file as JSON thinking that it's an older JSON formatted history file. This fixes that bug. This patch also prevents node repl from throwing if the old history file is empty or if $HOME/.node_repl_history is empty. Fixes: https://github.com/nodejs/node/issues/4102 PR-URL: https://github.com/nodejs/node/pull/4108 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-11-03repl: don't crash if cannot open history fileEvan Lucas
Previously, if we are unable to open the history file, an error would be thrown. Now, print an error message that we could not open the history file, but don't fail. Fixes: https://github.com/nodejs/node/issues/3610 PR-URL: https://github.com/nodejs/node/pull/3630 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-10-19repl: limit persistent history correctly on loadJeremiah Senkpiel
Previously the wrong end of the history was limited on load. PR-URL: https://github.com/nodejs/node/pull/2356 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed By: Evan Lucas <evanlucas@me.com>
2015-09-22repl: don't use tty control codes when $TERM is set to "dumb"Salman Aljammaz
This change stops the REPL from using ANSI control codes for colours when the TERM environment variable is set to "dumb". "dumb" is the terminal type with the smallest set of capabilities as described by terminfo. See: http://invisible-island.net/ncurses/terminfo.ti.html#toc-_Specials Related: https://github.com/nodejs/node-v0.x-archive/issues/5344 Related: https://github.com/nodejs/node-v0.x-archive/pull/25506 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> PR-URL: https://github.com/nodejs/node/pull/2712
2015-08-20repl: dont throw ENOENT on NODE_REPL_HISTORY_FILETodd Kennedy
If you have no history file written to disk, but the environment variable set, `fs.readFileSync` will throw an ENOENT error, but there's nothing to convert. The converter should ignore ENOENT on that `fs.readFileSync` call. Fixes: https://github.com/nodejs/node/issues/2449 PR-URL: https://github.com/nodejs/node/pull/2451 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-08-04repl: persist history in plain textJeremiah Senkpiel
Persists the REPL history in plain text using the new NODE_REPL_HISTORY environment variable. Deprecates NODE_REPL_HISTORY_FILE. The REPL will notify the user and automatically convert the history to the new format if files are specified. PR-URL: https://github.com/nodejs/io.js/pull/2224 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2015-08-04repl: default persistence to ~/.node_repl_historyJeremiah Senkpiel
Makes the REPL persistently save history by default to ~/.node_repl_history when in terminal mode. This can be disabled by setting NODE_REPL_HISTORY="". PR-URL: https://github.com/nodejs/io.js/pull/2224 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2015-08-04test: add tests for persistent repl historyJeremiah Senkpiel
PR-URL: https://github.com/nodejs/io.js/pull/2224 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2015-05-04repl: fix for a+ fd clearing the file on readChris Dickinson
The second step of augmenting the internal REPL with persistent history was to re-open the history file with a 'w' handle. This truncated the file. If a user did not enter a new line before closing the REPL, their history would be deleted. PR-URL: https://github.com/iojs/io.js/pull/1605 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-05-04repl: fix _debugger by properly proxying replChris Dickinson
The _debugger module uses the internal REPL module, but expects to receive the userland REPL module. This fixes the breakage that occurs by proxying the userland REPL module through the internal module. It also fixes an unintended in-REPL bug, where require(node-module) was not resolving correctly. PR-URL: https://github.com/iojs/io.js/pull/1605 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-05-03repl: fix persistent history and env variable nameRoman Reiss
Issue #1575 did introduce a check for options.terminal but this variable wasn't able to get truthy, which in turn broke persistent history completely. This changes the variable to get truthy on true terminals. Additionally, the docs and the code did differ on which environment variable was used for history. This changes the code to use NODE_REPL_HISTORY_FILE. PR-URL: https://github.com/iojs/io.js/pull/1593 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-05-02repl: do not save history for non-terminal replFedor Indutny
When running in non-TTY mode - the `repl.history` is `undefined` and is not actually populated. Saving it will result in a crashes of subsequent repl runs. Fix: https://github.com/iojs/io.js/issues/1574 PR-URL: https://github.com/iojs/io.js/pull/1575 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-04-30repl: add mode detection, cli persistent historyChris Dickinson
this creates a new internal module responsible for providing the repl created via "iojs" or "iojs -i," and adds the following options to the readline and repl subsystems: * "repl mode" - determine whether a repl is strict mode, sloppy mode, or auto-detect mode. * historySize - determine the maximum number of lines a repl will store as history. The built-in repl gains persistent history support when the NODE_REPL_HISTORY_FILE environment variable is set. This functionality is not exposed to userland repl instances. PR-URL: https://github.com/iojs/io.js/pull/1513 Reviewed-By: Fedor Indutny <fedor@indutny.com>