create-forgeon 0.1.0 → 0.1.2

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.
@@ -10,6 +10,12 @@ const task =
10
10
  ? runAddModule(args.slice(1))
11
11
  : runCreateForgeon(args);
12
12
 
13
+ task.then(() => {
14
+ if (typeof process.stdin.pause === 'function') {
15
+ process.stdin.pause();
16
+ }
17
+ });
18
+
13
19
  task.catch((error) => {
14
20
  console.error(error instanceof Error ? error.message : error);
15
21
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-forgeon",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Forgeon project generator CLI",
5
5
  "license": "MIT",
6
6
  "author": "Forgeon",
@@ -23,6 +23,10 @@ export async function promptSelect({
23
23
 
24
24
  const canSetRawMode = typeof inputStream.setRawMode === 'function';
25
25
  const wasRawModeEnabled = Boolean(inputStream.isRaw);
26
+ const canResume = typeof inputStream.resume === 'function';
27
+ const canPause = typeof inputStream.pause === 'function';
28
+ if (canResume) inputStream.resume();
29
+
26
30
  if (canSetRawMode && !wasRawModeEnabled) {
27
31
  inputStream.setRawMode(true);
28
32
  }
@@ -52,6 +56,7 @@ export async function promptSelect({
52
56
  if (canSetRawMode && !wasRawModeEnabled) {
53
57
  inputStream.setRawMode(false);
54
58
  }
59
+ if (canPause) inputStream.pause();
55
60
  outputStream.write('\n');
56
61
  };
57
62
 
@@ -1,5 +1,6 @@
1
1
  import { describe, it } from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
+ import { EventEmitter } from 'node:events';
3
4
  import { promptSelect } from './prompt-select.mjs';
4
5
 
5
6
  describe('promptSelect', () => {
@@ -31,4 +32,117 @@ describe('promptSelect', () => {
31
32
  /requires at least one choice/,
32
33
  );
33
34
  });
35
+
36
+ it('restores paused stdin state after interactive selection', async () => {
37
+ class MockInput extends EventEmitter {
38
+ constructor() {
39
+ super();
40
+ this.isTTY = true;
41
+ this.isRaw = false;
42
+ this._paused = true;
43
+ }
44
+
45
+ setRawMode(value) {
46
+ this.isRaw = value;
47
+ }
48
+
49
+ pause() {
50
+ this._paused = true;
51
+ }
52
+
53
+ resume() {
54
+ this._paused = false;
55
+ }
56
+
57
+ isPaused() {
58
+ return this._paused;
59
+ }
60
+ }
61
+
62
+ class MockOutput {
63
+ constructor() {
64
+ this.isTTY = true;
65
+ }
66
+
67
+ write() {}
68
+ }
69
+
70
+ const inputStream = new MockInput();
71
+ const outputStream = new MockOutput();
72
+
73
+ const selectionPromise = promptSelect({
74
+ message: 'Pick one',
75
+ defaultValue: 'a',
76
+ choices: [
77
+ { label: 'A', value: 'a' },
78
+ { label: 'B', value: 'b' },
79
+ ],
80
+ inputStream,
81
+ outputStream,
82
+ });
83
+
84
+ inputStream.emit('keypress', '', { name: 'down' });
85
+ inputStream.emit('keypress', '', { name: 'return' });
86
+
87
+ const value = await selectionPromise;
88
+
89
+ assert.equal(value, 'b');
90
+ assert.equal(inputStream.isPaused(), true);
91
+ assert.equal(inputStream.isRaw, false);
92
+ });
93
+
94
+ it('pauses stdin after interactive selection even when initially resumed', async () => {
95
+ class MockInput extends EventEmitter {
96
+ constructor() {
97
+ super();
98
+ this.isTTY = true;
99
+ this.isRaw = false;
100
+ this._paused = false;
101
+ }
102
+
103
+ setRawMode(value) {
104
+ this.isRaw = value;
105
+ }
106
+
107
+ pause() {
108
+ this._paused = true;
109
+ }
110
+
111
+ resume() {
112
+ this._paused = false;
113
+ }
114
+
115
+ isPaused() {
116
+ return this._paused;
117
+ }
118
+ }
119
+
120
+ class MockOutput {
121
+ constructor() {
122
+ this.isTTY = true;
123
+ }
124
+
125
+ write() {}
126
+ }
127
+
128
+ const inputStream = new MockInput();
129
+ const outputStream = new MockOutput();
130
+
131
+ const selectionPromise = promptSelect({
132
+ message: 'Pick one',
133
+ defaultValue: 'a',
134
+ choices: [
135
+ { label: 'A', value: 'a' },
136
+ { label: 'B', value: 'b' },
137
+ ],
138
+ inputStream,
139
+ outputStream,
140
+ });
141
+
142
+ inputStream.emit('keypress', '', { name: 'return' });
143
+ const value = await selectionPromise;
144
+
145
+ assert.equal(value, 'a');
146
+ assert.equal(inputStream.isPaused(), true);
147
+ });
34
148
  });