-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: History file locking and other improvements #7005
Changes from 4 commits
30e2048
be19adf
ffc9cb2
a74ca07
f5302b4
3741889
45d7504
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,7 @@ const tests = [ | |
env: {}, | ||
test: [UP, UP, ENTER], | ||
expected: [prompt, prompt + '\'42\'', prompt + '\'=^.^=\'', '\'=^.^=\'\n', | ||
prompt] | ||
prompt] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could you undo this whitespace change? |
||
}, | ||
{ | ||
env: { NODE_REPL_HISTORY: historyPath, | ||
|
@@ -189,7 +189,6 @@ const tests = [ | |
]; | ||
const numtests = tests.length; | ||
|
||
|
||
var testsNotRan = tests.length; | ||
|
||
process.on('beforeExit', () => | ||
|
@@ -209,7 +208,7 @@ function cleanupTmpFile() { | |
|
||
// Copy our fixture to the tmp directory | ||
fs.createReadStream(historyFixturePath) | ||
.pipe(fs.createWriteStream(historyPath)).on('unpipe', () => runTest()); | ||
.pipe(fs.createWriteStream(historyPath)).on('unpipe', runTest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have a |
||
|
||
function runTest(assertCleaned) { | ||
const opts = tests.shift(); | ||
|
@@ -247,7 +246,7 @@ function runTest(assertCleaned) { | |
try { | ||
assert.strictEqual(output, expected.shift()); | ||
} catch (err) { | ||
console.error(`Failed test # ${numtests - tests.length}`); | ||
console.error(`Failed test # ${numtests - tests.length}. ${err}`); | ||
throw err; | ||
} | ||
next(); | ||
|
@@ -262,16 +261,9 @@ function runTest(assertCleaned) { | |
throw err; | ||
} | ||
|
||
repl.once('close', () => { | ||
if (repl._flushing) { | ||
repl.once('flushHistory', onClose); | ||
return; | ||
} | ||
|
||
onClose(); | ||
}); | ||
repl.once('exit', onExit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto for |
||
|
||
function onClose() { | ||
function onExit() { | ||
const cleaned = after ? after() : cleanupTmpFile(); | ||
|
||
try { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’ll want to append an extra newline, otherwise the first entry of the current session is added to the last entry of the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax that's not actually the case. Since the history file is read in its entirety and rewritten each time, a trailing newline is not necessary. The pattern is:
No newline required! Also, note that the final
fs.openSync
used to write the history file is opened with thea
flag, to get around the Windows issues with hidden files. When I do the subsequentfs.write
, the write just begins at position0
in the file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, I ran 3 simultaneous REPLs and observed correct behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m going to try this again, but wouldn’t that mean that the
a
flag should not be used here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eek. Also, I personally consider it good practice to have all text files terminate with newlines. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right on all points. I have been using ^D to exit the REPL in my tests
which must account for the difference. I will address this.
On Tue, Jul 26, 2016 at 6:14 PM Anna Henningsen [email protected]
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax this is strange. I am not seeing this. I'll grant you that a newline terminating the file is good practice, and will address that. But for the record, I am not seeing the behavior you show above. I don't know why.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird – I still can’t reproduce the behaviour it has for you… without much deeper digging, I’d assume that the
a
flag in this line is the reason for the doubling in my repl history file; is that wrong?