inclusion-md 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/prompt.js +18 -5
- package/package.json +1 -1
package/lib/prompt.js
CHANGED
|
@@ -17,13 +17,26 @@ function createPrompter({ acceptDefaults = false } = {}) {
|
|
|
17
17
|
throw err;
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
// Track the in-flight ask() so a single 'close' listener can reject it.
|
|
21
|
+
// Registering rl.once("close", ...) inside ask() leaked one listener per
|
|
22
|
+
// prompt and triggered MaxListenersExceededWarning around question ~11.
|
|
23
|
+
let pendingReject = null;
|
|
24
|
+
rl.on("close", () => {
|
|
25
|
+
if (pendingReject) {
|
|
26
|
+
const err = new Error("Cancelled by user");
|
|
27
|
+
err.code = "USER_CANCELLED";
|
|
28
|
+
const reject = pendingReject;
|
|
29
|
+
pendingReject = null;
|
|
30
|
+
reject(err);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
20
34
|
function ask(question) {
|
|
21
35
|
return new Promise((resolve, reject) => {
|
|
22
|
-
|
|
23
|
-
rl.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
reject(err);
|
|
36
|
+
pendingReject = reject;
|
|
37
|
+
rl.question(question, (answer) => {
|
|
38
|
+
pendingReject = null;
|
|
39
|
+
resolve(answer);
|
|
27
40
|
});
|
|
28
41
|
});
|
|
29
42
|
}
|
package/package.json
CHANGED