Skip to content

Commit

Permalink
fix application freeze on exit with no packages selected
Browse files Browse the repository at this point in the history
## discussion

Node-v10.2 through Node-v14.6 contain a bug which may cause an application
freeze on Windows platforms when 'readline' is closing (see discussion at
<nodejs/node#31762>).

As a work-around, using...

```
const readlineOldClose = readline.Interface.prototype.close;
readline.Interface.prototype.close = function () {
	this.terminal = false;
	readlineOldClose.call(this);
};
```

seems to fix the issue without any obvious negative side effects.

ref: <enquirer/enquirer#245>
ref: <nodejs/node#31762>
  • Loading branch information
rivy committed Nov 4, 2020
1 parent dc55b26 commit 836e732
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
31 changes: 20 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const packageInfo = require('./package.json');
const path = require('path');
const paths = require('xdg-app-paths')(packageInfo.name);
const progress = require('cli-progress');
const readline = require('readline');
const request = require('request');
const sanitizeFilename = require('sanitize-filename');
const url = require('url');
Expand All @@ -41,6 +42,15 @@ const ALLOWED_TYPES = SUPPORTED_PLATFORMS.concat(['all']).sort();

const ALLOWED_SORT_PROPERTIES = ['date', 'name'].sort();

// work-around for "hang" after 'enquirer' <ESCAPE>/cancel() on windows platforms; see <https://github.com/enquirer/enquirer/issues/245>
// * arises from "node" bug after Node-v10.2 thru Node-v14.6 => see <https://github.com/nodejs/node/issues/31762>
// ToDO: keep apprised of any fix for this via `enquirer`
const readlineOldClose = readline.Interface.prototype.close;
readline.Interface.prototype.close = function () {
this.terminal = false;
readlineOldClose.call(this);
};

commander
.version(packageInfo.version)
.option(
Expand Down Expand Up @@ -469,7 +479,7 @@ function displayOrders(next, orders) {

process.stdout.write('\x1Bc'); // Clear console

let prompt = new enquirer.MultiSelect({
const prompt = new enquirer.MultiSelect({
name: 'bundle',
message: 'Select bundles to download',
choices: options,
Expand All @@ -495,19 +505,18 @@ function displayOrders(next, orders) {
}
return this.render();
},
})
});

prompt
.run()
.catch(() => {}) // empty selections throw an `alert()` (with no information) => so, ignore all errors
.then((answers = []) => {
// console.log(answers);
next(
null,
orders.filter((item) => {
return answers.indexOf(item.product.human_name) !== -1;
})
);
})
.catch(() => {
next(null, []);
const o = orders.filter((item) => {
return answers.indexOf(item.product.human_name) !== -1;
});
// console.log(o);
next(null, o);
});
}

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"make-dir": "^3.0.2",
"nasa-keypath": "0.0.1",
"nightmare": "^3.0.2",
"readline": "^1.3.0",
"request": "^2.88.2",
"sanitize-filename": "^1.6.3",
"xdg-app-paths": "^5.3.0"
Expand Down

0 comments on commit 836e732

Please sign in to comment.