| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3d5bc69 commit 26f0240
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ via the following environment variables: | |||
| 37 | 37 | - `NODE_REPL_HISTORY` - When a valid path is given, persistent REPL history | |
| 38 | 38 | will be saved to the specified file rather than `.node_repl_history` in the | |
| 39 | 39 | user's home directory. Setting this value to `""` will disable persistent | |
| 40 | - REPL history. | ||
| 40 | + REPL history. Whitespace will be trimmed from the value. | ||
| 41 | 41 | - `NODE_REPL_HISTORY_SIZE` - defaults to `1000`. Controls how many lines of | |
| 42 | 42 | history will be persisted if history is available. Must be a positive number. | |
| 43 | 43 | - `NODE_REPL_MODE` - may be any of `sloppy`, `strict`, or `magic`. Defaults | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,15 +55,26 @@ function createRepl(env, opts, cb) { | |||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | const repl = REPL.start(opts); | |
| 58 | - if (opts.terminal && env.NODE_REPL_HISTORY !== '') { | ||
| 58 | + if (opts.terminal) { | ||
| 59 | 59 | return setupHistory(repl, env.NODE_REPL_HISTORY, | |
| 60 | 60 | env.NODE_REPL_HISTORY_FILE, cb); | |
| 61 | 61 | } | |
| 62 | + | ||
| 62 | 63 | repl._historyPrev = _replHistoryMessage; | |
| 63 | 64 | cb(null, repl); | |
| 64 | 65 | } | |
| 65 | 66 | ||
| 66 | 67 | function setupHistory(repl, historyPath, oldHistoryPath, ready) { | |
| 68 | + // Empty string disables persistent history. | ||
| 69 | + | ||
| 70 | + if (typeof historyPath === 'string') | ||
| 71 | + historyPath = historyPath.trim(); | ||
| 72 | + | ||
| 73 | + if (historyPath === '') { | ||
| 74 | + repl._historyPrev = _replHistoryMessage; | ||
| 75 | + return ready(null, repl); | ||
| 76 | + } | ||
| 77 | + | ||
| 67 | 78 | if (!historyPath) { | |
| 68 | 79 | try { | |
| 69 | 80 | historyPath = path.join(os.homedir(), '.node_repl_history'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,6 +85,11 @@ const tests = [ | |||
| 85 | 85 | test: [UP], | |
| 86 | 86 | expected: [prompt, replDisabled, prompt] | |
| 87 | 87 | }, | |
| 88 | + { | ||
| 89 | + env: { NODE_REPL_HISTORY: ' ' }, | ||
| 90 | + test: [UP], | ||
| 91 | + expected: [prompt, replDisabled, prompt] | ||
| 92 | + }, | ||
| 88 | 93 | { | |
| 89 | 94 | env: { NODE_REPL_HISTORY: '', | |
| 90 | 95 | NODE_REPL_HISTORY_FILE: enoentHistoryPath }, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments