npq 3.11.6 → 3.12.0

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.
@@ -70,35 +70,113 @@ async function prompt(options = {}) {
70
70
  }
71
71
 
72
72
  async function autoContinue({ name, message, timeInSeconds = 5 } = {}) {
73
- // Show initial message with countdown
74
- process.stdout.write(`${message}${timeInSeconds}`)
73
+ let aborted = false
74
+ let userProceeded = false
75
+
76
+ // Setup stdin to capture keypresses during countdown
77
+ if (process.stdin.isTTY) {
78
+ process.stdin.setRawMode(true)
79
+ process.stdin.resume()
80
+
81
+ // Handle keypresses during countdown
82
+ const onKeypress = (chunk) => {
83
+ // Check for Ctrl+C (ASCII 3)
84
+ if (chunk && chunk.length === 1 && chunk[0] === 3) {
85
+ aborted = true
86
+ }
87
+ // Check for 'y' or 'Y' (ASCII 121 or 89)
88
+ else if (chunk && chunk.length === 1 && (chunk[0] === 121 || chunk[0] === 89)) {
89
+ userProceeded = true
90
+ }
91
+ // Ignore all other keypresses during countdown
92
+ }
75
93
 
76
- // Count down from timeInSeconds-1 to 1
77
- for (let i = timeInSeconds - 1; i > 0; i--) {
78
- await setTimeout(1000)
94
+ process.stdin.on('data', onKeypress)
79
95
 
80
- // Calculate how many characters to backspace (previous number length)
81
- const prevNumber = i + 1
82
- const prevLength = prevNumber.toString().length
83
- const currentLength = i.toString().length
96
+ // Cleanup function
97
+ const cleanup = () => {
98
+ process.stdin.removeListener('data', onKeypress)
99
+ if (process.stdin.isTTY) {
100
+ process.stdin.setRawMode(false)
101
+ process.stdin.pause()
102
+ }
103
+ }
84
104
 
85
- // Backspace to beginning of number
86
- const backspaces = '\b'.repeat(prevLength)
105
+ try {
106
+ // Show countdown message with instruction in parentheses
107
+ process.stdout.write(`${message}${timeInSeconds} (press 'y' to proceed)`)
87
108
 
88
- // Write new number and pad with spaces if needed to clear any remaining digits
89
- const padding = ' '.repeat(Math.max(0, prevLength - currentLength))
90
- const moveBack = '\b'.repeat(Math.max(0, prevLength - currentLength))
109
+ let currentNumber = timeInSeconds
91
110
 
92
- process.stdout.write(`${backspaces}${i}${padding}${moveBack}`)
93
- }
111
+ // Count down from timeInSeconds-1 to 1
112
+ for (let i = timeInSeconds - 1; i > 0 && !aborted && !userProceeded; i--) {
113
+ await setTimeout(1000)
114
+
115
+ if (aborted || userProceeded) break
116
+
117
+ // Update the countdown number using backspace
118
+ // We need to backspace over both the number AND the instruction text
119
+ const instructionText = " (press 'y' to proceed)"
120
+ const totalTextLength = currentNumber.toString().length + instructionText.length
121
+
122
+ // Backspace over everything, write new number and instruction
123
+ const backspaces = '\b'.repeat(totalTextLength)
124
+ process.stdout.write(`${backspaces}${i}${instructionText}`)
125
+
126
+ currentNumber = i
127
+ }
128
+
129
+ if (!aborted && !userProceeded) {
130
+ // Wait for the final second
131
+ await setTimeout(1000)
132
+ }
94
133
 
95
- // Wait for the final second
96
- await setTimeout(1000)
134
+ // Move to a clean new line for any follow-up output
135
+ if (!aborted) {
136
+ console.log('') // Just move to next line
137
+ }
97
138
 
98
- // Move to next line after countdown completes
99
- console.log()
139
+ cleanup()
100
140
 
101
- return { [name]: true }
141
+ if (aborted) {
142
+ const abortError = new Error('Operation aborted by user')
143
+ abortError.code = 'USER_ABORT'
144
+ abortError.exitCode = 1
145
+ throw abortError
146
+ }
147
+
148
+ return { [name]: true }
149
+ } catch (error) {
150
+ cleanup()
151
+ throw error
152
+ }
153
+ } else {
154
+ // Fallback for non-TTY environments (tests, etc.)
155
+ // Show countdown message with instruction
156
+ process.stdout.write(`${message}${timeInSeconds} (press 'y' to proceed)`)
157
+
158
+ // Count down from timeInSeconds-1 to 1
159
+ for (let i = timeInSeconds - 1; i > 0; i--) {
160
+ await setTimeout(1000)
161
+
162
+ // Update similar to TTY version - backspace over number and instruction
163
+ const instructionText = " (press 'y' to proceed)"
164
+ const prevNumber = i + 1
165
+ const totalTextLength = prevNumber.toString().length + instructionText.length
166
+
167
+ // Backspace over everything, write new number and instruction
168
+ const backspaces = '\b'.repeat(totalTextLength)
169
+ process.stdout.write(`${backspaces}${i}${instructionText}`)
170
+ }
171
+
172
+ // Wait for the final second
173
+ await setTimeout(1000)
174
+
175
+ // Move to next line after countdown completes
176
+ console.log('')
177
+
178
+ return { [name]: true }
179
+ }
102
180
  }
103
181
 
104
182
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npq",
3
- "version": "3.11.6",
3
+ "version": "3.12.0",
4
4
  "description": "marshall your npm/npm package installs with high quality and class 🎖",
5
5
  "bin": {
6
6
  "npq": "./bin/npq.js",