inquirerer 4.8.0 → 4.9.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.
package/commander.js CHANGED
@@ -8,11 +8,21 @@ const deepmerge_1 = __importDefault(require("deepmerge"));
8
8
  const minimist_1 = __importDefault(require("minimist"));
9
9
  const prompt_1 = require("./prompt");
10
10
  const utils_1 = require("./utils");
11
+ // NOTE: `input` and `output` are lazy getters rather than plain properties.
12
+ // `process.stdin` / `process.stdout` are Node getters that lazy-construct
13
+ // streams on first access. When fd 0 is a pipe (e.g. a Jest worker or any
14
+ // spawned child), constructing stdin registers a libuv PIPEWRAP handle
15
+ // that the runtime must close before the process can exit. Evaluating
16
+ // these defaults eagerly as object properties meant that merely
17
+ // `require('inquirerer')` — even via a transitive dep that never
18
+ // constructs `CLI` — would open stdin and produce a spurious open-handle
19
+ // warning under `jest --detectOpenHandles`. Deferring the access to
20
+ // read-time keeps the module side-effect free.
11
21
  exports.defaultCLIOptions = {
12
22
  version: `inquirerer@${(0, utils_1.getVersion)()}`,
13
23
  noTty: false,
14
- input: process.stdin,
15
- output: process.stdout,
24
+ get input() { return process.stdin; },
25
+ get output() { return process.stdout; },
16
26
  minimistOpts: {
17
27
  alias: {
18
28
  v: 'version'
package/esm/commander.js CHANGED
@@ -2,11 +2,21 @@ import deepmerge from 'deepmerge';
2
2
  import minimist from 'minimist';
3
3
  import { Inquirerer } from './prompt';
4
4
  import { getVersion } from './utils';
5
+ // NOTE: `input` and `output` are lazy getters rather than plain properties.
6
+ // `process.stdin` / `process.stdout` are Node getters that lazy-construct
7
+ // streams on first access. When fd 0 is a pipe (e.g. a Jest worker or any
8
+ // spawned child), constructing stdin registers a libuv PIPEWRAP handle
9
+ // that the runtime must close before the process can exit. Evaluating
10
+ // these defaults eagerly as object properties meant that merely
11
+ // `require('inquirerer')` — even via a transitive dep that never
12
+ // constructs `CLI` — would open stdin and produce a spurious open-handle
13
+ // warning under `jest --detectOpenHandles`. Deferring the access to
14
+ // read-time keeps the module side-effect free.
5
15
  export const defaultCLIOptions = {
6
16
  version: `inquirerer@${getVersion()}`,
7
17
  noTty: false,
8
- input: process.stdin,
9
- output: process.stdout,
18
+ get input() { return process.stdin; },
19
+ get output() { return process.stdout; },
10
20
  minimistOpts: {
11
21
  alias: {
12
22
  v: 'version'
package/esm/prompt.js CHANGED
@@ -134,6 +134,17 @@ function generatePromptMessage(question, ctx) {
134
134
  }
135
135
  return lines.join('\n') + '\n';
136
136
  }
137
+ export class PromptTimeoutError extends Error {
138
+ currentQuestion;
139
+ allQuestions;
140
+ constructor(message, currentQuestion, allQuestions) {
141
+ super(message);
142
+ this.name = 'PromptTimeoutError';
143
+ this.currentQuestion = currentQuestion;
144
+ this.allQuestions = allQuestions;
145
+ }
146
+ }
147
+ const DEFAULT_NON_TTY_TIMEOUT = 15_000;
137
148
  export class Inquirerer {
138
149
  rl;
139
150
  keypress;
@@ -144,9 +155,13 @@ export class Inquirerer {
144
155
  globalMaxLines;
145
156
  mutateArgs;
146
157
  resolverRegistry;
158
+ timeout;
159
+ _inactivityTimer = null;
160
+ _inactivityReject = null;
161
+ _inactivityContext = null;
147
162
  handledKeys = new Set();
148
163
  constructor(options) {
149
- const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false, globalMaxLines = 10, mutateArgs = true, resolverRegistry = globalResolverRegistry } = options ?? {};
164
+ const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false, globalMaxLines = 10, mutateArgs = true, resolverRegistry = globalResolverRegistry, timeout } = options ?? {};
150
165
  this.useDefaults = useDefaults;
151
166
  this.noTty = noTty;
152
167
  this.output = output;
@@ -154,6 +169,12 @@ export class Inquirerer {
154
169
  this.input = input;
155
170
  this.globalMaxLines = globalMaxLines;
156
171
  this.resolverRegistry = resolverRegistry;
172
+ if (timeout !== undefined) {
173
+ this.timeout = timeout;
174
+ }
175
+ else if (!noTty && !input.isTTY) {
176
+ this.timeout = DEFAULT_NON_TTY_TIMEOUT;
177
+ }
157
178
  if (!noTty) {
158
179
  this.rl = readline.createInterface({
159
180
  input,
@@ -383,7 +404,18 @@ export class Inquirerer {
383
404
  continue; // Skip to the next question since the default is applied
384
405
  }
385
406
  while (ctx.needsInput) {
386
- obj[question.name] = await this.handleQuestionType(question, ctx);
407
+ const timeoutPromise = this.startInactivityTimeout(question, ordered);
408
+ const removeActivityListener = this.setupInputActivityListener();
409
+ try {
410
+ const questionPromise = this.handleQuestionType(question, ctx);
411
+ obj[question.name] = timeoutPromise
412
+ ? await Promise.race([questionPromise, timeoutPromise])
413
+ : await questionPromise;
414
+ }
415
+ finally {
416
+ removeActivityListener();
417
+ this.clearInactivityTimeout();
418
+ }
387
419
  if (!this.isValid(question, obj, ctx)) {
388
420
  if (this.noTty) {
389
421
  // If you're not valid and here with noTty, you're out!
@@ -1177,6 +1209,91 @@ export class Inquirerer {
1177
1209
  // }
1178
1210
  return Math.min(this.globalMaxLines, defaultLength);
1179
1211
  }
1212
+ startInactivityTimeout(question, allQuestions) {
1213
+ if (this.timeout === undefined)
1214
+ return null;
1215
+ const ms = this.timeout;
1216
+ this._inactivityContext = { question, allQuestions, ms };
1217
+ return new Promise((_, reject) => {
1218
+ this._inactivityReject = reject;
1219
+ this._inactivityTimer = setTimeout(() => {
1220
+ reject(new PromptTimeoutError(this.formatTimeoutError(question, allQuestions, ms), question, allQuestions));
1221
+ }, ms);
1222
+ });
1223
+ }
1224
+ resetInactivityTimeout() {
1225
+ if (this._inactivityTimer === null || this._inactivityReject === null || this._inactivityContext === null)
1226
+ return;
1227
+ clearTimeout(this._inactivityTimer);
1228
+ const { question, allQuestions, ms } = this._inactivityContext;
1229
+ const rejectFn = this._inactivityReject;
1230
+ this._inactivityTimer = setTimeout(() => {
1231
+ rejectFn(new PromptTimeoutError(this.formatTimeoutError(question, allQuestions, ms), question, allQuestions));
1232
+ }, ms);
1233
+ }
1234
+ clearInactivityTimeout() {
1235
+ if (this._inactivityTimer !== null) {
1236
+ clearTimeout(this._inactivityTimer);
1237
+ this._inactivityTimer = null;
1238
+ }
1239
+ this._inactivityReject = null;
1240
+ this._inactivityContext = null;
1241
+ }
1242
+ setupInputActivityListener() {
1243
+ if (this.timeout === undefined)
1244
+ return () => { };
1245
+ const onData = () => this.resetInactivityTimeout();
1246
+ this.input.on('data', onData);
1247
+ return () => this.input.removeListener('data', onData);
1248
+ }
1249
+ formatTimeoutError(currentQuestion, allQuestions, ms) {
1250
+ const seconds = Math.round(ms / 1000);
1251
+ const lines = [];
1252
+ lines.push('');
1253
+ lines.push(`PROMPT TIMEOUT: No input received for "${currentQuestion.name}" after ${seconds}s.`);
1254
+ lines.push('');
1255
+ lines.push('This usually happens when running in a non-interactive environment');
1256
+ lines.push('(CI, scripts, AI agents) without the proper flags.');
1257
+ lines.push('');
1258
+ lines.push('REQUIRED ARGUMENTS:');
1259
+ for (const q of allQuestions) {
1260
+ const flag = `--${q.name}`;
1261
+ const aliases = q.alias
1262
+ ? (Array.isArray(q.alias) ? q.alias : [q.alias])
1263
+ .map(a => a.length === 1 ? `-${a}` : `--${a}`)
1264
+ .join(', ')
1265
+ : '';
1266
+ const aliasStr = aliases ? ` (${aliases})` : '';
1267
+ const label = q.message || q.name;
1268
+ const req = q.required ? ' [REQUIRED]' : '';
1269
+ const def = 'default' in q && q.default !== undefined ? ` (default: ${JSON.stringify(q.default)})` : '';
1270
+ lines.push(` ${flag}${aliasStr} ${label}${req}${def}`);
1271
+ }
1272
+ lines.push('');
1273
+ lines.push('HOW TO FIX:');
1274
+ lines.push(' 1. Pass all required arguments as CLI flags:');
1275
+ const requiredFlags = allQuestions
1276
+ .filter(q => q.required)
1277
+ .map(q => `--${q.name} <value>`);
1278
+ if (requiredFlags.length > 0) {
1279
+ lines.push(` $ command ${requiredFlags.join(' ')}`);
1280
+ }
1281
+ else {
1282
+ lines.push(' $ command --flag1 <value> --flag2 <value>');
1283
+ }
1284
+ lines.push('');
1285
+ lines.push(' 2. Or enable non-interactive mode:');
1286
+ lines.push(' new Inquirerer({ noTty: true, useDefaults: true })');
1287
+ lines.push('');
1288
+ lines.push(' 3. Or pass --no-tty if the CLI supports it.');
1289
+ lines.push('');
1290
+ lines.push('WHY THIS HAPPENED:');
1291
+ lines.push(' The prompt expected interactive TTY input (keyboard), but no input');
1292
+ lines.push(' was received. AI agents and CI pipelines must pass arguments via');
1293
+ lines.push(' CLI flags instead of interactive prompts.');
1294
+ lines.push('');
1295
+ return lines.join('\n');
1296
+ }
1180
1297
  // Method to cleanly close the readline interface
1181
1298
  // NOTE: use exit() to close!
1182
1299
  close() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inquirerer",
3
- "version": "4.8.0",
3
+ "version": "4.9.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "TypeScript-first library for building beautiful CLI interfaces with interactive prompts",
6
6
  "main": "index.js",
@@ -46,5 +46,5 @@
46
46
  "makage": "0.1.10",
47
47
  "string-width": "4.2.3"
48
48
  },
49
- "gitHead": "d0e1a1b963e849c3e65a83e1cd7a183d9b5928a0"
49
+ "gitHead": "76f01d32d05f29d9a53a30b516951fc373655ae2"
50
50
  }
package/prompt.d.ts CHANGED
@@ -22,6 +22,11 @@ declare class PromptContext {
22
22
  nextQuestion(): void;
23
23
  process(validation: Validation | boolean): Validation;
24
24
  }
25
+ export declare class PromptTimeoutError extends Error {
26
+ readonly currentQuestion: Question;
27
+ readonly allQuestions: Question[];
28
+ constructor(message: string, currentQuestion: Question, allQuestions: Question[]);
29
+ }
25
30
  export interface InquirererOptions {
26
31
  noTty?: boolean;
27
32
  input?: Readable;
@@ -30,6 +35,7 @@ export interface InquirererOptions {
30
35
  globalMaxLines?: number;
31
36
  mutateArgs?: boolean;
32
37
  resolverRegistry?: DefaultResolverRegistry;
38
+ timeout?: number;
33
39
  }
34
40
  export declare class Inquirerer {
35
41
  private rl;
@@ -41,6 +47,10 @@ export declare class Inquirerer {
41
47
  private globalMaxLines;
42
48
  private mutateArgs;
43
49
  private resolverRegistry;
50
+ private timeout;
51
+ private _inactivityTimer;
52
+ private _inactivityReject;
53
+ private _inactivityContext;
44
54
  private handledKeys;
45
55
  constructor(options?: InquirererOptions);
46
56
  private clearScreen;
@@ -119,6 +129,11 @@ export declare class Inquirerer {
119
129
  private sanitizeOptions;
120
130
  private filterOptions;
121
131
  private getMaxLines;
132
+ private startInactivityTimeout;
133
+ private resetInactivityTimeout;
134
+ private clearInactivityTimeout;
135
+ private setupInputActivityListener;
136
+ private formatTimeoutError;
122
137
  close(): void;
123
138
  }
124
139
  export {};
package/prompt.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Inquirerer = void 0;
6
+ exports.Inquirerer = exports.PromptTimeoutError = void 0;
7
7
  exports.reorderQuestionsByDeps = reorderQuestionsByDeps;
8
8
  const yanse_1 = require("yanse");
9
9
  const readline_1 = __importDefault(require("readline"));
@@ -141,6 +141,18 @@ function generatePromptMessage(question, ctx) {
141
141
  }
142
142
  return lines.join('\n') + '\n';
143
143
  }
144
+ class PromptTimeoutError extends Error {
145
+ currentQuestion;
146
+ allQuestions;
147
+ constructor(message, currentQuestion, allQuestions) {
148
+ super(message);
149
+ this.name = 'PromptTimeoutError';
150
+ this.currentQuestion = currentQuestion;
151
+ this.allQuestions = allQuestions;
152
+ }
153
+ }
154
+ exports.PromptTimeoutError = PromptTimeoutError;
155
+ const DEFAULT_NON_TTY_TIMEOUT = 15_000;
144
156
  class Inquirerer {
145
157
  rl;
146
158
  keypress;
@@ -151,9 +163,13 @@ class Inquirerer {
151
163
  globalMaxLines;
152
164
  mutateArgs;
153
165
  resolverRegistry;
166
+ timeout;
167
+ _inactivityTimer = null;
168
+ _inactivityReject = null;
169
+ _inactivityContext = null;
154
170
  handledKeys = new Set();
155
171
  constructor(options) {
156
- const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false, globalMaxLines = 10, mutateArgs = true, resolverRegistry = resolvers_1.globalResolverRegistry } = options ?? {};
172
+ const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false, globalMaxLines = 10, mutateArgs = true, resolverRegistry = resolvers_1.globalResolverRegistry, timeout } = options ?? {};
157
173
  this.useDefaults = useDefaults;
158
174
  this.noTty = noTty;
159
175
  this.output = output;
@@ -161,6 +177,12 @@ class Inquirerer {
161
177
  this.input = input;
162
178
  this.globalMaxLines = globalMaxLines;
163
179
  this.resolverRegistry = resolverRegistry;
180
+ if (timeout !== undefined) {
181
+ this.timeout = timeout;
182
+ }
183
+ else if (!noTty && !input.isTTY) {
184
+ this.timeout = DEFAULT_NON_TTY_TIMEOUT;
185
+ }
164
186
  if (!noTty) {
165
187
  this.rl = readline_1.default.createInterface({
166
188
  input,
@@ -390,7 +412,18 @@ class Inquirerer {
390
412
  continue; // Skip to the next question since the default is applied
391
413
  }
392
414
  while (ctx.needsInput) {
393
- obj[question.name] = await this.handleQuestionType(question, ctx);
415
+ const timeoutPromise = this.startInactivityTimeout(question, ordered);
416
+ const removeActivityListener = this.setupInputActivityListener();
417
+ try {
418
+ const questionPromise = this.handleQuestionType(question, ctx);
419
+ obj[question.name] = timeoutPromise
420
+ ? await Promise.race([questionPromise, timeoutPromise])
421
+ : await questionPromise;
422
+ }
423
+ finally {
424
+ removeActivityListener();
425
+ this.clearInactivityTimeout();
426
+ }
394
427
  if (!this.isValid(question, obj, ctx)) {
395
428
  if (this.noTty) {
396
429
  // If you're not valid and here with noTty, you're out!
@@ -1184,6 +1217,91 @@ class Inquirerer {
1184
1217
  // }
1185
1218
  return Math.min(this.globalMaxLines, defaultLength);
1186
1219
  }
1220
+ startInactivityTimeout(question, allQuestions) {
1221
+ if (this.timeout === undefined)
1222
+ return null;
1223
+ const ms = this.timeout;
1224
+ this._inactivityContext = { question, allQuestions, ms };
1225
+ return new Promise((_, reject) => {
1226
+ this._inactivityReject = reject;
1227
+ this._inactivityTimer = setTimeout(() => {
1228
+ reject(new PromptTimeoutError(this.formatTimeoutError(question, allQuestions, ms), question, allQuestions));
1229
+ }, ms);
1230
+ });
1231
+ }
1232
+ resetInactivityTimeout() {
1233
+ if (this._inactivityTimer === null || this._inactivityReject === null || this._inactivityContext === null)
1234
+ return;
1235
+ clearTimeout(this._inactivityTimer);
1236
+ const { question, allQuestions, ms } = this._inactivityContext;
1237
+ const rejectFn = this._inactivityReject;
1238
+ this._inactivityTimer = setTimeout(() => {
1239
+ rejectFn(new PromptTimeoutError(this.formatTimeoutError(question, allQuestions, ms), question, allQuestions));
1240
+ }, ms);
1241
+ }
1242
+ clearInactivityTimeout() {
1243
+ if (this._inactivityTimer !== null) {
1244
+ clearTimeout(this._inactivityTimer);
1245
+ this._inactivityTimer = null;
1246
+ }
1247
+ this._inactivityReject = null;
1248
+ this._inactivityContext = null;
1249
+ }
1250
+ setupInputActivityListener() {
1251
+ if (this.timeout === undefined)
1252
+ return () => { };
1253
+ const onData = () => this.resetInactivityTimeout();
1254
+ this.input.on('data', onData);
1255
+ return () => this.input.removeListener('data', onData);
1256
+ }
1257
+ formatTimeoutError(currentQuestion, allQuestions, ms) {
1258
+ const seconds = Math.round(ms / 1000);
1259
+ const lines = [];
1260
+ lines.push('');
1261
+ lines.push(`PROMPT TIMEOUT: No input received for "${currentQuestion.name}" after ${seconds}s.`);
1262
+ lines.push('');
1263
+ lines.push('This usually happens when running in a non-interactive environment');
1264
+ lines.push('(CI, scripts, AI agents) without the proper flags.');
1265
+ lines.push('');
1266
+ lines.push('REQUIRED ARGUMENTS:');
1267
+ for (const q of allQuestions) {
1268
+ const flag = `--${q.name}`;
1269
+ const aliases = q.alias
1270
+ ? (Array.isArray(q.alias) ? q.alias : [q.alias])
1271
+ .map(a => a.length === 1 ? `-${a}` : `--${a}`)
1272
+ .join(', ')
1273
+ : '';
1274
+ const aliasStr = aliases ? ` (${aliases})` : '';
1275
+ const label = q.message || q.name;
1276
+ const req = q.required ? ' [REQUIRED]' : '';
1277
+ const def = 'default' in q && q.default !== undefined ? ` (default: ${JSON.stringify(q.default)})` : '';
1278
+ lines.push(` ${flag}${aliasStr} ${label}${req}${def}`);
1279
+ }
1280
+ lines.push('');
1281
+ lines.push('HOW TO FIX:');
1282
+ lines.push(' 1. Pass all required arguments as CLI flags:');
1283
+ const requiredFlags = allQuestions
1284
+ .filter(q => q.required)
1285
+ .map(q => `--${q.name} <value>`);
1286
+ if (requiredFlags.length > 0) {
1287
+ lines.push(` $ command ${requiredFlags.join(' ')}`);
1288
+ }
1289
+ else {
1290
+ lines.push(' $ command --flag1 <value> --flag2 <value>');
1291
+ }
1292
+ lines.push('');
1293
+ lines.push(' 2. Or enable non-interactive mode:');
1294
+ lines.push(' new Inquirerer({ noTty: true, useDefaults: true })');
1295
+ lines.push('');
1296
+ lines.push(' 3. Or pass --no-tty if the CLI supports it.');
1297
+ lines.push('');
1298
+ lines.push('WHY THIS HAPPENED:');
1299
+ lines.push(' The prompt expected interactive TTY input (keyboard), but no input');
1300
+ lines.push(' was received. AI agents and CI pipelines must pass arguments via');
1301
+ lines.push(' CLI flags instead of interactive prompts.');
1302
+ lines.push('');
1303
+ return lines.join('\n');
1304
+ }
1187
1305
  // Method to cleanly close the readline interface
1188
1306
  // NOTE: use exit() to close!
1189
1307
  close() {