next-anteater 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/lib/ui.mjs +41 -9
  2. package/package.json +1 -1
package/lib/ui.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * Terminal UI helpers — zero dependencies.
3
3
  *
4
- * Uses a single shared readline interface so piped input works correctly.
5
- * Creating multiple interfaces on the same stdin consumes the buffer on
6
- * the first close, breaking subsequent reads.
4
+ * Handles both interactive (TTY) and piped (file/pipe) input.
5
+ * When stdin is piped, pre-reads all lines and serves them sequentially.
7
6
  */
8
7
  import * as readline from "node:readline";
9
8
 
@@ -23,9 +22,34 @@ export const info = (msg) => console.log(` ${dim(msg)}`);
23
22
  export const heading = (msg) => console.log(`\n ${bold(msg)}\n ${"─".repeat(msg.length)}`);
24
23
  export const blank = () => console.log();
25
24
 
26
- /**
27
- * Shared readline interface created lazily, closed once at process exit.
28
- */
25
+ // ─── Piped input support ────────────────────────────────────────
26
+ // When stdin is piped (not a TTY), pre-read all lines into a queue.
27
+ // This avoids readline issues where EOF closes the interface mid-setup.
28
+
29
+ let _pipedLines = null;
30
+ let _pipedReady = null;
31
+
32
+ if (!process.stdin.isTTY) {
33
+ _pipedLines = [];
34
+ _pipedReady = new Promise((resolve) => {
35
+ const rl = readline.createInterface({ input: process.stdin });
36
+ rl.on("line", (line) => _pipedLines.push(line));
37
+ rl.on("close", resolve);
38
+ });
39
+ }
40
+
41
+ let _pipedIdx = 0;
42
+
43
+ async function nextPipedLine() {
44
+ await _pipedReady;
45
+ if (_pipedIdx < _pipedLines.length) {
46
+ return _pipedLines[_pipedIdx++];
47
+ }
48
+ return "";
49
+ }
50
+
51
+ // ─── Interactive readline (TTY only) ────────────────────────────
52
+
29
53
  let _rl = null;
30
54
 
31
55
  function getRL() {
@@ -34,13 +58,10 @@ function getRL() {
34
58
  input: process.stdin,
35
59
  output: process.stdout,
36
60
  });
37
- // Don't let the readline keep the process alive
38
- _rl.on("close", () => { _rl = null; });
39
61
  }
40
62
  return _rl;
41
63
  }
42
64
 
43
- /** Close the shared readline (call at end of setup). */
44
65
  export function closeRL() {
45
66
  if (_rl) {
46
67
  _rl.close();
@@ -52,6 +73,17 @@ export function closeRL() {
52
73
  * Prompt the user for text input.
53
74
  */
54
75
  export function ask(question, { mask = false } = {}) {
76
+ // Piped mode — read next line from pre-buffered input
77
+ if (_pipedLines) {
78
+ const prompt = ` ${cyan("?")} ${question} `;
79
+ process.stdout.write(prompt);
80
+ return nextPipedLine().then((line) => {
81
+ process.stdout.write("\n");
82
+ return line.trim();
83
+ });
84
+ }
85
+
86
+ // Interactive mode — use readline
55
87
  return new Promise((resolve) => {
56
88
  const rl = getRL();
57
89
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-anteater",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "AI-powered live editing for your Next.js app",
5
5
  "bin": {
6
6
  "anteater": "bin/setup-anteater.mjs",