@stacksjs/cli 0.70.200 → 0.70.202

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/dist/index.js CHANGED
@@ -494,7 +494,7 @@ var quotes = collect([
494
494
  "Security is mostly a superstition. Life is either a daring adventure or nothing."
495
495
  ]);
496
496
  // package.json
497
- var version = "0.70.200";
497
+ var version = "0.70.202";
498
498
  // src/helpers.ts
499
499
  async function intro(command, options) {
500
500
  return new Promise((resolve) => {
@@ -690,32 +690,62 @@ function getGlobalRl() {
690
690
  process5.emit("SIGINT");
691
691
  });
692
692
  }
693
+ globalRl.once("close", () => {
694
+ globalRl = null;
695
+ });
693
696
  }
694
697
  return globalRl;
695
698
  }
696
- function readLine(prompt) {
699
+ var EOF = Symbol("stdin-eof");
700
+ function readLineOrEof(prompt) {
697
701
  return new Promise((resolve) => {
698
702
  const rl = getGlobalRl();
699
- rl.question(prompt, (answer) => {
703
+ let settled = false;
704
+ const finish = (answer) => {
705
+ if (settled)
706
+ return;
707
+ settled = true;
708
+ rl.off("close", onClose);
700
709
  resolve(answer);
701
- });
710
+ };
711
+ const onClose = () => finish(EOF);
712
+ rl.once("close", onClose);
713
+ try {
714
+ rl.question(prompt, finish);
715
+ } catch {
716
+ finish(EOF);
717
+ }
702
718
  });
703
719
  }
720
+ async function readLine(prompt) {
721
+ const answer = await readLineOrEof(prompt);
722
+ return answer === EOF ? "" : answer;
723
+ }
724
+ function normalizeConfirm(answer, defaultValue) {
725
+ const normalized = answer.toLowerCase().trim();
726
+ if (!normalized)
727
+ return defaultValue;
728
+ if (normalized === "y" || normalized === "yes")
729
+ return true;
730
+ if (normalized === "n" || normalized === "no")
731
+ return false;
732
+ return defaultValue;
733
+ }
734
+ async function confirmOrNull(options) {
735
+ const opts = typeof options === "string" ? { message: options } : options;
736
+ const defaultValue = opts.initial ?? false;
737
+ const suffix = defaultValue ? " (Y/n) " : " (y/N) ";
738
+ const answer = await readLineOrEof(`${opts.message}${suffix}`);
739
+ if (answer === EOF)
740
+ return null;
741
+ return normalizeConfirm(answer, defaultValue);
742
+ }
704
743
  async function confirm(options) {
705
744
  const opts = typeof options === "string" ? { message: options } : options;
706
745
  const defaultValue = opts.initial ?? false;
707
746
  const suffix = defaultValue ? " (Y/n) " : " (y/N) ";
708
747
  const answer = await readLine(`${opts.message}${suffix}`);
709
- const normalized = answer.toLowerCase().trim();
710
- if (!normalized) {
711
- return defaultValue;
712
- } else if (normalized === "y" || normalized === "yes") {
713
- return true;
714
- } else if (normalized === "n" || normalized === "no") {
715
- return false;
716
- } else {
717
- return defaultValue;
718
- }
748
+ return normalizeConfirm(answer, defaultValue);
719
749
  }
720
750
  async function text(options) {
721
751
  const opts = typeof options === "string" ? { message: options } : options;
@@ -993,6 +1023,7 @@ export {
993
1023
  exec,
994
1024
  dim,
995
1025
  cyan,
1026
+ confirmOrNull,
996
1027
  confirm,
997
1028
  colors,
998
1029
  colorize,
package/dist/prompts.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Confirm that reports `null` when stdin ended without an answer, instead of
3
+ * silently returning the default. Use this for any question whose "yes" has
4
+ * side effects the user cannot easily undo.
5
+ */
6
+ declare function confirmOrNull(options: ConfirmOptions | string): Promise<boolean | null>;
1
7
  /**
2
8
  * Simple confirm prompt
3
9
  */
@@ -45,4 +51,4 @@ declare interface SelectOptions {
45
51
  initial?: number
46
52
  }
47
53
  // Also export individual functions
48
- export { confirm, text, select, multiselect, password };
54
+ export { confirm, confirmOrNull, text, select, multiselect, password };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/cli",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.200",
5
+ "version": "0.70.202",
6
6
  "description": "TypeScript framework for CLI artisans. Build beautiful console apps with ease.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -66,14 +66,14 @@
66
66
  "@stacksjs/clapp": "^0.2.12"
67
67
  },
68
68
  "devDependencies": {
69
- "@stacksjs/collections": "0.70.200",
70
- "@stacksjs/config": "0.70.200",
69
+ "@stacksjs/collections": "0.70.202",
70
+ "@stacksjs/config": "0.70.202",
71
71
  "better-dx": "^0.2.17",
72
- "@stacksjs/error-handling": "0.70.200",
73
- "@stacksjs/logging": "0.70.200",
74
- "@stacksjs/path": "0.70.200",
75
- "@stacksjs/types": "0.70.200",
76
- "@stacksjs/utils": "0.70.200",
77
- "@stacksjs/validation": "0.70.200"
72
+ "@stacksjs/error-handling": "0.70.202",
73
+ "@stacksjs/logging": "0.70.202",
74
+ "@stacksjs/path": "0.70.202",
75
+ "@stacksjs/types": "0.70.202",
76
+ "@stacksjs/utils": "0.70.202",
77
+ "@stacksjs/validation": "0.70.202"
78
78
  }
79
79
  }