Update: Support NodeJS-v4.2.4 and v5.1.0 that fixed about issue #18.

This commit is contained in:
anseki 2015-12-24 18:32:18 +09:00
parent 2ab19593d8
commit 0e700b21f6
2 changed files with 14 additions and 12 deletions

View file

@ -70,7 +70,7 @@ function _readlineSync(options) {
if (_DBG_checkOptions) { _DBG_checkOptions(options); } if (_DBG_checkOptions) { _DBG_checkOptions(options); }
(function() { // open TTY (function() { // open TTY
var fsB, constants; var fsB, constants, verNum;
function getFsB() { function getFsB() {
if (!fsB) { if (!fsB) {
@ -80,22 +80,24 @@ function _readlineSync(options) {
return fsB; return fsB;
} }
function getVerNum(ver) {
var nums = ver.replace(/^\D+/, '').split('.');
var verNum = 0;
if ((nums[0] = +nums[0])) { verNum += nums[0] * 10000; }
if ((nums[1] = +nums[1])) { verNum += nums[1] * 100; }
if ((nums[2] = +nums[2])) { verNum += nums[2]; }
return verNum;
}
if (typeof fdR !== 'string') { return; } if (typeof fdR !== 'string') { return; }
fdR = null; fdR = null;
if (IS_WIN) { if (IS_WIN) {
// iojs-v2.3.2+ input stream can't read first line. (#18) // iojs-v2.3.2+ input stream can't read first line. (#18)
// ** Don't get process.stdin before check! ** // ** Don't get process.stdin before check! **
if (getVerNum(process.version) < 20302 && process.stdin.isTTY) { // Fixed v5.1.0 https://nodejs.org/en/blog/release/v5.1.0/
// Fixed v4.2.4 (LTS) https://nodejs.org/en/blog/release/v4.2.4/
verNum = (function(ver) { // getVerNum
var nums = ver.replace(/^\D+/, '').split('.');
var verNum = 0;
if ((nums[0] = +nums[0])) { verNum += nums[0] * 10000; }
if ((nums[1] = +nums[1])) { verNum += nums[1] * 100; }
if ((nums[2] = +nums[2])) { verNum += nums[2]; }
return verNum;
})(process.version);
if (!(verNum >= 20302 && verNum < 40204 || verNum >= 50000 && verNum < 50100) &&
process.stdin.isTTY) {
process.stdin.pause(); process.stdin.pause();
fdR = process.stdin.fd; fdR = process.stdin.fd;
ttyR = process.stdin._handle; ttyR = process.stdin._handle;

View file

@ -1,6 +1,6 @@
{ {
"name": "readline-sync", "name": "readline-sync",
"version": "1.2.21", "version": "1.2.22",
"title": "readlineSync", "title": "readlineSync",
"description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).", "description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).",
"keywords": [ "keywords": [