@voidzero-dev/vite-plus-prompts 1.5.1 → 1.7.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.
Files changed (2) hide show
  1. package/dist/index.mjs +72 -6
  2. package/package.json +3 -2
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { AutocompletePrompt, CANCEL_SYMBOL, ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, SelectKeyPrompt, SelectPrompt, TextPrompt, block, getColumns, getRows, isAccessible, isCancel, isCancel as isCancel$1, runValidation, settings, settings as settings$1, updateSettings, updateSettings as updateSettings$1 } from "@clack/core";
1
+ import { AutocompletePrompt, CANCEL_SYMBOL, ConfirmPrompt, GroupMultiSelectPrompt, MultiSelectPrompt, PasswordPrompt, SelectKeyPrompt, SelectPrompt, TextPrompt, getColumns, getRows, isAccessible, isCancel, isCancel as isCancel$1, runValidation, settings, settings as settings$1, updateSettings, updateSettings as updateSettings$1 } from "@clack/core";
2
2
  import color from "picocolors";
3
3
  import process$1 from "node:process";
4
4
  import { stripVTControlCharacters } from "node:util";
5
5
  import { randomBytes } from "node:crypto";
6
6
  import { existsSync, lstatSync, readdirSync } from "node:fs";
7
7
  import { dirname, join } from "node:path";
8
+ import readline from "node:readline";
8
9
  import { cursor, erase } from "sisteransi";
9
10
  // ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
10
11
  const getCodePointsLength = (() => {
@@ -1195,6 +1196,45 @@ const formatTimer = (durationMs) => {
1195
1196
  const secs = Math.floor(duration % 60);
1196
1197
  return color.gray(min > 0 ? `(${min}m ${secs}s)` : `(${secs}s)`);
1197
1198
  };
1199
+ const PROCESS_SIGNALS = ["SIGINT", "SIGTERM"];
1200
+ const spinnerSignalListeners = /* @__PURE__ */ new Set();
1201
+ const endBySignal = (signal, pid) => {
1202
+ if (process.platform === "win32") process.exit(signal === "SIGINT" ? 130 : 143);
1203
+ else process.kill(pid, signal);
1204
+ };
1205
+ let inputBlocked = false;
1206
+ const blockInput = (output, onInterrupt) => {
1207
+ if (inputBlocked) return () => {};
1208
+ inputBlocked = true;
1209
+ const input = process.stdin;
1210
+ const rl = readline.createInterface({
1211
+ input,
1212
+ output,
1213
+ prompt: "",
1214
+ tabSize: 1
1215
+ });
1216
+ readline.emitKeypressEvents(input, rl);
1217
+ if (input.isTTY) input.setRawMode(true);
1218
+ const onKeypress = (_char, { name, sequence }) => {
1219
+ if (sequence === "") {
1220
+ onInterrupt();
1221
+ return;
1222
+ }
1223
+ const [dx, dy] = name === "return" ? [0, -1] : [-1, 0];
1224
+ readline.moveCursor(output, dx, dy);
1225
+ readline.clearLine(output, 1);
1226
+ };
1227
+ output.write(cursor.hide);
1228
+ input.on("keypress", onKeypress);
1229
+ return () => {
1230
+ inputBlocked = false;
1231
+ input.off("keypress", onKeypress);
1232
+ output.write(cursor.show);
1233
+ if (input.isTTY && process.platform !== "win32") input.setRawMode(false);
1234
+ rl.terminal = false;
1235
+ rl.close();
1236
+ };
1237
+ };
1198
1238
  const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancelMessage, errorMessage, frames = unicode ? [
1199
1239
  "◒",
1200
1240
  "◐",
@@ -1231,19 +1271,45 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
1231
1271
  };
1232
1272
  const errorEventHandler = () => handleExit(2);
1233
1273
  const signalEventHandler = () => handleExit(1);
1274
+ const removedInDelivery = /* @__PURE__ */ new Set();
1275
+ const trackRemoval = (event, listener) => {
1276
+ if (!spinnerSignalListeners.has(listener)) {
1277
+ removedInDelivery.add(event);
1278
+ process.nextTick(() => removedInDelivery.delete(event));
1279
+ }
1280
+ };
1281
+ const ownedByAnother = (processSignal) => removedInDelivery.has(processSignal) || process.listeners(processSignal).some((listener) => !spinnerSignalListeners.has(listener));
1282
+ const processSignalHandlers = PROCESS_SIGNALS.map((processSignal) => {
1283
+ const handler = (received) => {
1284
+ const raise = received === processSignal && !ownedByAnother(processSignal);
1285
+ handleExit(1);
1286
+ if (raise) endBySignal(processSignal, process.pid);
1287
+ };
1288
+ return [processSignal, handler];
1289
+ });
1290
+ const interrupt = () => {
1291
+ handleExit(1);
1292
+ endBySignal("SIGINT", 0);
1293
+ };
1234
1294
  const registerHooks = () => {
1235
1295
  process.on("uncaughtExceptionMonitor", errorEventHandler);
1236
1296
  process.on("unhandledRejection", errorEventHandler);
1237
- process.on("SIGINT", signalEventHandler);
1238
- process.on("SIGTERM", signalEventHandler);
1297
+ for (const [processSignal, handler] of processSignalHandlers) {
1298
+ spinnerSignalListeners.add(handler);
1299
+ process.prependListener(processSignal, handler);
1300
+ }
1239
1301
  process.on("exit", handleExit);
1302
+ process.on("removeListener", trackRemoval);
1240
1303
  if (signal) signal.addEventListener("abort", signalEventHandler);
1241
1304
  };
1242
1305
  const clearHooks = () => {
1243
1306
  process.removeListener("uncaughtExceptionMonitor", errorEventHandler);
1244
1307
  process.removeListener("unhandledRejection", errorEventHandler);
1245
- process.removeListener("SIGINT", signalEventHandler);
1246
- process.removeListener("SIGTERM", signalEventHandler);
1308
+ process.removeListener("removeListener", trackRemoval);
1309
+ for (const [processSignal, handler] of processSignalHandlers) {
1310
+ process.removeListener(processSignal, handler);
1311
+ spinnerSignalListeners.delete(handler);
1312
+ }
1247
1313
  process.removeListener("exit", handleExit);
1248
1314
  if (signal) signal.removeEventListener("abort", signalEventHandler);
1249
1315
  };
@@ -1261,7 +1327,7 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
1261
1327
  const hasGuide = getGuide(opts);
1262
1328
  const startLoop = () => {
1263
1329
  isSpinnerActive = true;
1264
- unblock = isCI$1 ? () => {} : block({ output });
1330
+ unblock = isCI$1 ? () => {} : blockInput(output, interrupt);
1265
1331
  _origin = performance.now();
1266
1332
  _prevMessage = void 0;
1267
1333
  if (hasGuide) output.write(`${color.gray(S_BAR)}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voidzero-dev/vite-plus-prompts",
3
- "version": "1.5.1",
3
+ "version": "1.7.0",
4
4
  "description": "The Unified Toolchain for the Web",
5
5
  "homepage": "https://viteplus.dev/guide",
6
6
  "bugs": {
@@ -32,7 +32,8 @@
32
32
  "fast-string-width": "^3.0.0",
33
33
  "fast-wrap-ansi": "^0.2.0",
34
34
  "is-unicode-supported": "^2.0.0",
35
- "tsdown": "^0.23.4"
35
+ "signal-exit": "4.1.0",
36
+ "tsdown": "=0.23.4"
36
37
  },
37
38
  "scripts": {
38
39
  "build": "tsdown"