create-ts-monorepo-starter 0.1.0 → 0.2.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/dist/cli.js CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { cp, rename, rm, readdir, rmdir, readFile, writeFile, open, stat, mkdir, realpath, lstat } from 'node:fs/promises';
3
- import { isAbsolute, dirname, basename, resolve, join, relative, sep } from 'node:path';
2
+ import { mkdtemp, writeFile, rm, access, cp, rename, readdir, rmdir, readFile, open, stat, mkdir, realpath, lstat } from 'node:fs/promises';
3
+ import { join, isAbsolute, dirname, basename, resolve, relative, sep } from 'node:path';
4
4
  import { parseArgs, styleText, stripVTControlCharacters } from 'node:util';
5
5
  import { spawn } from 'node:child_process';
6
6
  import { constants, tmpdir } from 'node:os';
7
7
  import { readFileSync, existsSync, lstatSync, readdirSync, rmSync } from 'node:fs';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import process$1, { stdout, stdin } from 'node:process';
10
- import * as l from 'node:readline';
11
- import l__default from 'node:readline';
10
+ import * as f$1 from 'node:readline';
11
+ import f$1__default from 'node:readline';
12
12
  import { ReadStream } from 'node:tty';
13
13
  import { randomBytes } from 'node:crypto';
14
14
 
@@ -64,6 +64,7 @@ function parseArgv(argv) {
64
64
  yes: values.yes ?? false,
65
65
  help: values.help ?? false,
66
66
  version: values.version ?? false,
67
+ check: values.check ?? false,
67
68
  };
68
69
  if (positionals[0] !== undefined)
69
70
  options.folder = positionals[0];
@@ -92,6 +93,7 @@ function parse(argv) {
92
93
  yes: { type: 'boolean', short: 'y' },
93
94
  help: { type: 'boolean', short: 'h' },
94
95
  version: { type: 'boolean', short: 'v' },
96
+ check: { type: 'boolean' },
95
97
  },
96
98
  });
97
99
  }
@@ -286,6 +288,61 @@ async function detectPnpm(exec = defaultExec, cwd = tmpdir()) {
286
288
  const [major, minor] = [Number(match[1]), Number(match[2])];
287
289
  return { kind: major < 10 || (major === 10 && minor < 26) ? 'old' : 'ok', version };
288
290
  }
291
+ /** A toolchain problem the user has to fix before anything is created; `lines` say how. */
292
+ class ToolchainError extends Error {
293
+ lines;
294
+ constructor(message, lines) {
295
+ super(message);
296
+ this.lines = lines;
297
+ this.name = 'ToolchainError';
298
+ }
299
+ }
300
+ const PNPM_HELP = 'https://github.com/prosdevlab/create-ts-monorepo-starter#pnpm';
301
+ const fileExists = (path) => access(path).then(() => true, () => false);
302
+ /**
303
+ * Runs `pnpm --version` in an empty folder pinned to `spec` (`pnpm@12.15.0`), where pnpm switches
304
+ * itself to that version as the install will. Throws a ToolchainError when the switch fails.
305
+ */
306
+ async function checkSwitch(spec, found, exec = defaultExec, root = tmpdir(), exists = fileExists) {
307
+ const dir = await mkdtemp(join(root, 'ctms-pnpm-'));
308
+ try {
309
+ await writeFile(join(dir, 'package.json'), `${JSON.stringify({ packageManager: spec })}\n`);
310
+ const result = await exec('pnpm', ['--version'], { cwd: dir }).catch(() => null);
311
+ if (result?.code === 0)
312
+ return;
313
+ const output = result ? `${result.stdout}\n${result.stderr}` : '';
314
+ const installer = switchInstaller(output);
315
+ const runnable = installer !== undefined && (await exists(installer));
316
+ throw switchFailure(spec, found, output, runnable ? installer : undefined);
317
+ }
318
+ finally {
319
+ await rm(dir, { recursive: true, force: true });
320
+ }
321
+ }
322
+ /**
323
+ * The install script of the pnpm a failed switch downloaded, read from pnpm's error: it says the CLI
324
+ * "is missing at <tools>/bin" when the script that puts the binary there never ran.
325
+ */
326
+ function switchInstaller(output) {
327
+ const tools = /missing at "([^"]+?)[\\/]bin"/.exec(output)?.[1];
328
+ return tools === undefined ? undefined : join(tools, 'node_modules', 'pnpm', 'install.js');
329
+ }
330
+ /** The stop for a failed switch: pnpm's words, the fix (`installer`, or the README), and a retry. */
331
+ function switchFailure(spec, found, output, installer) {
332
+ const version = spec.slice('pnpm@'.length);
333
+ const said = output
334
+ .split(/\r?\n/)
335
+ .map((line) => line.trim())
336
+ .filter(Boolean)
337
+ .slice(0, 2);
338
+ return new ToolchainError(`pnpm ${found} couldn't switch to pnpm ${version}, which this project needs`, [
339
+ ...said.map((line) => `pnpm: ${line}`),
340
+ installer
341
+ ? `Fix: node ${installer}`
342
+ : `Fix your pnpm so it can switch to ${version}: ${PNPM_HELP}`,
343
+ 'Then run this command again. Nothing was created.',
344
+ ]);
345
+ }
289
346
  /** The install command for `dir`, or null when pnpm is too old to use. */
290
347
  function installCommand(status, dir, lockfileOnly) {
291
348
  if (!isAbsolute(dir))
@@ -739,8 +796,8 @@ const fastStringWidth = (input, options = {}) => {
739
796
  return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
740
797
  };
741
798
 
742
- const ESC = '\x1B';
743
- const CSI = '\x9B';
799
+ const ESC$1 = '\x1B';
800
+ const CSI$1 = '\x9B';
744
801
  const END_CODE = 39;
745
802
  const ANSI_ESCAPE_BELL = '\u0007';
746
803
  const ANSI_CSI = '[';
@@ -773,8 +830,8 @@ const getClosingCode = (openingCode) => {
773
830
  return 0;
774
831
  return undefined;
775
832
  };
776
- const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
777
- const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
833
+ const wrapAnsiCode = (code) => `${ESC$1}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
834
+ const wrapAnsiHyperlink = (url) => `${ESC$1}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
778
835
  const wrapWord = (rows, word, columns) => {
779
836
  const characters = word[Symbol.iterator]();
780
837
  let isInsideEscape = false;
@@ -794,7 +851,7 @@ const wrapWord = (rows, word, columns) => {
794
851
  rows.push(character);
795
852
  visible = 0;
796
853
  }
797
- if (character === ESC || character === CSI) {
854
+ if (character === ESC$1 || character === CSI$1) {
798
855
  isInsideEscape = true;
799
856
  isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
800
857
  }
@@ -916,7 +973,7 @@ const exec = (string, columns, options = {}) => {
916
973
  else {
917
974
  inSurrogate = false;
918
975
  }
919
- if (character === ESC || character === CSI) {
976
+ if (character === ESC$1 || character === CSI$1) {
920
977
  GROUP_REGEX.lastIndex = i + 1;
921
978
  const groupsResult = GROUP_REGEX.exec(preString);
922
979
  const groups = groupsResult?.groups;
@@ -957,90 +1014,71 @@ function wrapAnsi(string, columns, options) {
957
1014
  .join('\n');
958
1015
  }
959
1016
 
960
- var src;
961
- var hasRequiredSrc;
962
-
963
- function requireSrc () {
964
- if (hasRequiredSrc) return src;
965
- hasRequiredSrc = 1;
966
-
967
- const ESC = '\x1B';
968
- const CSI = `${ESC}[`;
969
- const beep = '\u0007';
970
-
971
- const cursor = {
972
- to(x, y) {
973
- if (!y) return `${CSI}${x + 1}G`;
974
- return `${CSI}${y + 1};${x + 1}H`;
975
- },
976
- move(x, y) {
977
- let ret = '';
978
-
979
- if (x < 0) ret += `${CSI}${-x}D`;
980
- else if (x > 0) ret += `${CSI}${x}C`;
981
-
982
- if (y < 0) ret += `${CSI}${-y}A`;
983
- else if (y > 0) ret += `${CSI}${y}B`;
984
-
985
- return ret;
986
- },
987
- up: (count = 1) => `${CSI}${count}A`,
988
- down: (count = 1) => `${CSI}${count}B`,
989
- forward: (count = 1) => `${CSI}${count}C`,
990
- backward: (count = 1) => `${CSI}${count}D`,
991
- nextLine: (count = 1) => `${CSI}E`.repeat(count),
992
- prevLine: (count = 1) => `${CSI}F`.repeat(count),
993
- left: `${CSI}G`,
994
- hide: `${CSI}?25l`,
995
- show: `${CSI}?25h`,
996
- save: `${ESC}7`,
997
- restore: `${ESC}8`
998
- };
999
-
1000
- const scroll = {
1001
- up: (count = 1) => `${CSI}S`.repeat(count),
1002
- down: (count = 1) => `${CSI}T`.repeat(count)
1003
- };
1004
-
1005
- const erase = {
1006
- screen: `${CSI}2J`,
1007
- up: (count = 1) => `${CSI}1J`.repeat(count),
1008
- down: (count = 1) => `${CSI}J`.repeat(count),
1009
- line: `${CSI}2K`,
1010
- lineEnd: `${CSI}K`,
1011
- lineStart: `${CSI}1K`,
1012
- lines(count) {
1013
- let clear = '';
1014
- for (let i = 0; i < count; i++)
1015
- clear += this.line + (i < count - 1 ? cursor.up() : '');
1016
- if (count)
1017
- clear += cursor.left;
1018
- return clear;
1019
- }
1020
- };
1021
-
1022
- src = { cursor, scroll, erase, beep };
1023
- return src;
1024
- }
1025
-
1026
- var srcExports = requireSrc();
1017
+ const ESC = '\x1B';
1018
+ const CSI = `${ESC}[`;
1019
+ const cursor = {
1020
+ to(x, y) {
1021
+ if (!y)
1022
+ return `${CSI}${x + 1}G`;
1023
+ return `${CSI}${y + 1};${x + 1}H`;
1024
+ },
1025
+ move(x, y) {
1026
+ let ret = '';
1027
+ if (x < 0)
1028
+ ret += `${CSI}${-x}D`;
1029
+ else if (x > 0)
1030
+ ret += `${CSI}${x}C`;
1031
+ if (y < 0)
1032
+ ret += `${CSI}${-y}A`;
1033
+ else if (y > 0)
1034
+ ret += `${CSI}${y}B`;
1035
+ return ret;
1036
+ },
1037
+ up: (count = 1) => `${CSI}${count}A`,
1038
+ down: (count = 1) => `${CSI}${count}B`,
1039
+ forward: (count = 1) => `${CSI}${count}C`,
1040
+ backward: (count = 1) => `${CSI}${count}D`,
1041
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
1042
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
1043
+ left: `${CSI}G`,
1044
+ hide: `${CSI}?25l`,
1045
+ show: `${CSI}?25h`,
1046
+ save: `${ESC}7`,
1047
+ restore: `${ESC}8`
1048
+ };
1049
+ const erase = {
1050
+ screen: `${CSI}2J`,
1051
+ up: (count = 1) => `${CSI}1J`.repeat(count),
1052
+ down: (count = 1) => `${CSI}J`.repeat(count),
1053
+ line: `${CSI}2K`,
1054
+ lineEnd: `${CSI}K`,
1055
+ lineStart: `${CSI}1K`,
1056
+ lines(count) {
1057
+ let clear = '';
1058
+ for (let i = 0; i < count; i++)
1059
+ clear += this.line + (i < count - 1 ? cursor.up() : '');
1060
+ if (count)
1061
+ clear += cursor.left;
1062
+ return clear;
1063
+ }
1064
+ };
1027
1065
 
1028
- function findCursor(s, o, l) {
1066
+ function findCursor(o, s, l) {
1029
1067
  if (!l.some((r) => !r.disabled))
1030
- return s;
1031
- const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
1032
- return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
1068
+ return o;
1069
+ const t = o + s, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
1070
+ return l[e]?.disabled ? findCursor(e, s < 0 ? -1 : 1, l) : e;
1033
1071
  }
1034
- function findTextCursor(s, o, l, i) {
1072
+ function findTextCursor(o, s, l, i) {
1035
1073
  const t = i.split(`
1036
1074
  `);
1037
- let n = 0, e = s;
1075
+ let n = 0, e = o;
1038
1076
  for (const r of t) {
1039
1077
  if (e <= r.length)
1040
1078
  break;
1041
1079
  e -= r.length + 1, n++;
1042
1080
  }
1043
- for (n = Math.max(0, Math.min(t.length - 1, n + l)), e = Math.min(e, t[n].length) + o; e < 0 && n > 0; )
1081
+ for (n = Math.max(0, Math.min(t.length - 1, n + l)), e = Math.min(e, t[n].length) + s; e < 0 && n > 0; )
1044
1082
  n--, e += t[n].length + 1;
1045
1083
  for (; e > t[n].length && n < t.length - 1; )
1046
1084
  e -= t[n].length + 1, n++;
@@ -1157,41 +1195,41 @@ function block({
1157
1195
  overwrite: o = true,
1158
1196
  hideCursor: n = true
1159
1197
  } = {}) {
1160
- const s = l.createInterface({
1198
+ const s = f$1.createInterface({
1161
1199
  input: e,
1162
1200
  output: r,
1163
1201
  prompt: "",
1164
1202
  tabSize: 1
1165
1203
  });
1166
- l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
1167
- const t = (f, { name: a, sequence: w }) => {
1168
- const c = String(f);
1169
- if (isActionKey([c, a, w], "cancel")) {
1170
- n && r.write(srcExports.cursor.show), process.exit(0);
1204
+ f$1.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
1205
+ const t = (l, { name: i, sequence: p }) => {
1206
+ const w = String(l);
1207
+ if (isActionKey([w, i, p], "cancel")) {
1208
+ n && r.write(cursor.show), process.exit(0);
1171
1209
  return;
1172
1210
  }
1173
1211
  if (!o) return;
1174
- const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
1175
- l.moveCursor(r, i, m, () => {
1176
- l.clearLine(r, 1, () => {
1212
+ const c = i === "return" ? 0 : -1, a = i === "return" ? -1 : 0;
1213
+ f$1.moveCursor(r, c, a, () => {
1214
+ f$1.clearLine(r, 1, () => {
1177
1215
  e.once("keypress", t);
1178
1216
  });
1179
1217
  });
1180
1218
  };
1181
- return n && r.write(srcExports.cursor.hide), e.once("keypress", t), () => {
1182
- e.off("keypress", t), n && r.write(srcExports.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
1219
+ return n && r.write(cursor.hide), e.once("keypress", t), () => {
1220
+ e.off("keypress", t), n && r.write(cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
1183
1221
  };
1184
1222
  }
1185
1223
  const getColumns = (e) => "columns" in e && typeof e.columns == "number" ? e.columns : 80, getRows = (e) => "rows" in e && typeof e.rows == "number" ? e.rows : 20;
1186
1224
  function wrapTextWithPrefix(e, r, o, n = o, s = o, t) {
1187
- const f = getColumns(e ?? stdout);
1188
- return wrapAnsi(r, f - o.length, {
1225
+ const l = getColumns(e ?? stdout), i = fastStringWidth(o);
1226
+ return wrapAnsi(r, l - i, {
1189
1227
  hard: true,
1190
1228
  trim: false
1191
1229
  }).split(`
1192
- `).map((c, i, m) => {
1193
- const d = t ? t(c, i) : c;
1194
- return i === 0 ? `${n}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
1230
+ `).map((c, a, g) => {
1231
+ const m = t ? t(c, a) : c;
1232
+ return a === 0 ? `${n}${m}` : a === g.length - 1 ? `${s}${m}` : `${o}${m}`;
1195
1233
  }).join(`
1196
1234
  `);
1197
1235
  }
@@ -1204,7 +1242,7 @@ function runValidation(e, a) {
1204
1242
  return e(a);
1205
1243
  }
1206
1244
 
1207
- class y {
1245
+ let C$1 = class C {
1208
1246
  input;
1209
1247
  output;
1210
1248
  _abortSignal;
@@ -1286,16 +1324,16 @@ class y {
1286
1324
  { once: true }
1287
1325
  );
1288
1326
  }
1289
- this.rl = l__default.createInterface({
1327
+ this.rl = f$1__default.createInterface({
1290
1328
  input: this.input,
1291
1329
  tabSize: 2,
1292
1330
  prompt: "",
1293
1331
  escapeCodeTimeout: 50,
1294
1332
  terminal: true
1295
1333
  }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), setRawMode(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
1296
- this.output.write(srcExports.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
1334
+ this.output.write(cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
1297
1335
  }), this.once("cancel", () => {
1298
- this.output.write(srcExports.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
1336
+ this.output.write(cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
1299
1337
  });
1300
1338
  });
1301
1339
  }
@@ -1332,18 +1370,18 @@ class y {
1332
1370
  `), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
1333
1371
  }
1334
1372
  restoreCursor() {
1335
- const t = wrapAnsi(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
1373
+ const t = wrapAnsi(this._prevFrame, getColumns(this.output), { hard: true, trim: false }).split(`
1336
1374
  `).length - 1;
1337
- this.output.write(srcExports.cursor.move(-999, t * -1));
1375
+ this.output.write(cursor.move(-999, t * -1));
1338
1376
  }
1339
1377
  render() {
1340
- const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
1378
+ const t = wrapAnsi(this._render(this) ?? "", getColumns(this.output), {
1341
1379
  hard: true,
1342
1380
  trim: false
1343
1381
  });
1344
1382
  if (t !== this._prevFrame) {
1345
1383
  if (this.state === "initial")
1346
- this.output.write(srcExports.cursor.hide);
1384
+ this.output.write(cursor.hide);
1347
1385
  else {
1348
1386
  const e = diffLines(this._prevFrame, t), i = getRows(this.output);
1349
1387
  if (this.restoreCursor(), e) {
@@ -1354,32 +1392,32 @@ class y {
1354
1392
  return;
1355
1393
  }
1356
1394
  if (e.lines.length === 1) {
1357
- this.output.write(srcExports.cursor.move(0, n - r)), this.output.write(srcExports.erase.lines(1));
1395
+ this.output.write(cursor.move(0, n - r)), this.output.write(erase.lines(1));
1358
1396
  const o = t.split(`
1359
1397
  `);
1360
- this.output.write(o[n]), this._prevFrame = t, this.output.write(srcExports.cursor.move(0, o.length - n - 1));
1398
+ this.output.write(o[n]), this._prevFrame = t, this.output.write(cursor.move(0, o.length - n - 1));
1361
1399
  return;
1362
1400
  } else if (e.lines.length > 1) {
1363
1401
  if (s < r)
1364
1402
  n = s;
1365
1403
  else {
1366
1404
  const h = n - r;
1367
- h > 0 && this.output.write(srcExports.cursor.move(0, h));
1405
+ h > 0 && this.output.write(cursor.move(0, h));
1368
1406
  }
1369
- this.output.write(srcExports.erase.down());
1370
- const f = t.split(`
1407
+ this.output.write(erase.down());
1408
+ const m = t.split(`
1371
1409
  `).slice(n);
1372
- this.output.write(f.join(`
1410
+ this.output.write(m.join(`
1373
1411
  `)), this._prevFrame = t;
1374
1412
  return;
1375
1413
  }
1376
1414
  }
1377
- this.output.write(srcExports.erase.down());
1415
+ this.output.write(erase.down());
1378
1416
  }
1379
1417
  this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
1380
1418
  }
1381
1419
  }
1382
- }
1420
+ };
1383
1421
 
1384
1422
  function p$1$1(l, e) {
1385
1423
  if (l === void 0 || e.length === 0)
@@ -1394,7 +1432,7 @@ function g(l, e) {
1394
1432
  if (e)
1395
1433
  return l ? e : e[0];
1396
1434
  }
1397
- let T$1 = class T extends y {
1435
+ let T$1 = class T extends C$1 {
1398
1436
  filteredOptions;
1399
1437
  multiple;
1400
1438
  isNavigating = false;
@@ -1469,7 +1507,7 @@ let T$1 = class T extends y {
1469
1507
  }
1470
1508
  };
1471
1509
 
1472
- class r extends y {
1510
+ class r extends C$1 {
1473
1511
  get cursor() {
1474
1512
  return this.value ? 0 : 1;
1475
1513
  }
@@ -1480,7 +1518,7 @@ class r extends y {
1480
1518
  super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
1481
1519
  this.value = this._value;
1482
1520
  }), this.on("confirm", (i) => {
1483
- this.output.write(srcExports.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
1521
+ this.output.write(cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
1484
1522
  }), this.on("cursor", () => {
1485
1523
  this.value = !this.value;
1486
1524
  });
@@ -1526,7 +1564,7 @@ function b$1(r) {
1526
1564
  if (!(n.getUTCFullYear() !== t || n.getUTCMonth() !== i - 1 || n.getUTCDate() !== s))
1527
1565
  return { year: t, month: i, day: s };
1528
1566
  }
1529
- function C$1(r) {
1567
+ function C$2(r) {
1530
1568
  const t = b$1(r);
1531
1569
  return t ? new Date(Date.UTC(t.year, t.month - 1, t.day)) : void 0;
1532
1570
  }
@@ -1548,7 +1586,7 @@ function T(r, t, i, s) {
1548
1586
  max: e && t.year === e.year && t.month === e.month ? e.day : c$1(t.year, t.month)
1549
1587
  };
1550
1588
  }
1551
- let U$1 = class U extends y {
1589
+ let U$1 = class U extends C$1 {
1552
1590
  #i;
1553
1591
  #o;
1554
1592
  #t;
@@ -1577,7 +1615,7 @@ let U$1 = class U extends y {
1577
1615
  return this.#i.map((i) => t[i.type]).join(this.#o);
1578
1616
  }
1579
1617
  #r() {
1580
- this._setUserInput(this.#l(this.#t)), this._setValue(C$1(this.#t) ?? void 0);
1618
+ this._setUserInput(this.#l(this.#t)), this._setValue(C$2(this.#t) ?? void 0);
1581
1619
  }
1582
1620
  constructor(t) {
1583
1621
  const i = t.format ? { segments: M(t.format), separator: t.separator ?? "/" } : P$1(t.locale), s = t.separator ?? i.separator, n = t.format ? M(t.format) : i.segments, e = t.initialValue ?? t.defaultValue, m = e ? {
@@ -1710,57 +1748,59 @@ let U$1 = class U extends y {
1710
1748
  day: String(Math.min(n, e)).padStart(2, "0")
1711
1749
  };
1712
1750
  }
1713
- this.value = C$1(this.#t) ?? t.defaultValue ?? void 0;
1751
+ this.value = C$2(this.#t) ?? t.defaultValue ?? void 0;
1714
1752
  }
1715
1753
  };
1716
1754
 
1717
- let u$2 = class u extends y {
1755
+ let u$1 = class u extends C$1 {
1718
1756
  options;
1719
1757
  cursor = 0;
1720
- #t;
1758
+ #e;
1721
1759
  getGroupItems(t) {
1722
- return this.options.filter((r) => r.group === t);
1760
+ return this.options.filter((i) => i.group === t);
1723
1761
  }
1724
1762
  isGroupSelected(t) {
1725
- const r = this.getGroupItems(t), e = this.value;
1726
- return e === void 0 ? false : r.every((s) => e.includes(s.value));
1763
+ const i = this.getGroupItems(t), e = this.value;
1764
+ return e === void 0 ? false : i.every((s) => e.includes(s.value));
1727
1765
  }
1728
1766
  toggleValue() {
1729
1767
  const t = this.options[this.cursor];
1730
1768
  if (t !== void 0)
1731
1769
  if (this.value === void 0 && (this.value = []), t.group === true) {
1732
- const r = t.value, e = this.getGroupItems(r);
1733
- this.isGroupSelected(r) ? this.value = this.value.filter(
1734
- (s) => e.findIndex((i) => i.value === s) === -1
1770
+ const i = t.value, e = this.getGroupItems(i);
1771
+ this.isGroupSelected(i) ? this.value = this.value.filter(
1772
+ (s) => e.findIndex((r) => r.value === s) === -1
1735
1773
  ) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value));
1736
1774
  } else {
1737
- const r = this.value.includes(t.value);
1738
- this.value = r ? this.value.filter((e) => e !== t.value) : [...this.value, t.value];
1775
+ const i = this.value.includes(t.value);
1776
+ this.value = i ? this.value.filter((e) => e !== t.value) : [...this.value, t.value];
1739
1777
  }
1740
1778
  }
1741
1779
  constructor(t) {
1742
1780
  super(t, false);
1743
- const { options: r } = t;
1744
- this.#t = t.selectableGroups !== false, this.options = Object.entries(r).flatMap(([e, s]) => [
1781
+ const { options: i } = t;
1782
+ this.#e = t.selectableGroups !== false, this.options = Object.entries(i).flatMap(([e, s]) => [
1745
1783
  { value: e, group: true, label: e },
1746
- ...s.map((i) => ({ ...i, group: e }))
1784
+ ...s.map((r) => ({ ...r, group: e }))
1747
1785
  ]), this.value = [...t.initialValues ?? []], this.cursor = Math.max(
1748
1786
  this.options.findIndex(({ value: e }) => e === t.cursorAt),
1749
- this.#t ? 0 : 1
1750
- ), this.on("cursor", (e) => {
1787
+ this.#e ? 0 : 1
1788
+ ), this.on("key", (e, s) => {
1789
+ s.name === void 0 && e === "\u3000" && this.toggleValue();
1790
+ }), this.on("cursor", (e) => {
1751
1791
  switch (e) {
1752
1792
  case "left":
1753
1793
  case "up": {
1754
1794
  this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
1755
1795
  const s = this.options[this.cursor]?.group === true;
1756
- !this.#t && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
1796
+ !this.#e && s && (this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1);
1757
1797
  break;
1758
1798
  }
1759
1799
  case "down":
1760
1800
  case "right": {
1761
1801
  this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
1762
1802
  const s = this.options[this.cursor]?.group === true;
1763
- !this.#t && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
1803
+ !this.#e && s && (this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1);
1764
1804
  break;
1765
1805
  }
1766
1806
  case "space":
@@ -1772,7 +1812,7 @@ let u$2 = class u extends y {
1772
1812
  };
1773
1813
 
1774
1814
  const o = /* @__PURE__ */ new Set(["up", "down", "left", "right"]);
1775
- class h extends y {
1815
+ class h extends C$1 {
1776
1816
  #t = false;
1777
1817
  #s;
1778
1818
  focused = "editor";
@@ -1867,7 +1907,7 @@ ${i}` : `${s}${styleText("inverse", r)}${i}`;
1867
1907
  }
1868
1908
  }
1869
1909
 
1870
- class a extends y {
1910
+ class a extends C$1 {
1871
1911
  options;
1872
1912
  cursor = 0;
1873
1913
  get _value() {
@@ -1898,8 +1938,8 @@ class a extends y {
1898
1938
  this.options.findIndex(({ value: t }) => t === e.cursorAt),
1899
1939
  0
1900
1940
  );
1901
- this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => {
1902
- l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
1941
+ this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, s) => {
1942
+ s.name === "a" && this.toggleAll(), s.name === "i" && this.toggleInvert(), s.name === void 0 && t === "\u3000" && this.toggleValue();
1903
1943
  }), this.on("cursor", (t) => {
1904
1944
  switch (t) {
1905
1945
  case "left":
@@ -1918,7 +1958,7 @@ class a extends y {
1918
1958
  }
1919
1959
  }
1920
1960
 
1921
- let u$1 = class u extends y {
1961
+ let u$2 = class u extends C$1 {
1922
1962
  _mask = "\u2022";
1923
1963
  get cursor() {
1924
1964
  return this._cursor;
@@ -1947,7 +1987,7 @@ let u$1 = class u extends y {
1947
1987
  }
1948
1988
  };
1949
1989
 
1950
- let n$1 = class n extends y {
1990
+ let n$1 = class n extends C$1 {
1951
1991
  options;
1952
1992
  cursor = 0;
1953
1993
  get _selectedValue() {
@@ -1976,25 +2016,25 @@ let n$1 = class n extends y {
1976
2016
  }
1977
2017
  };
1978
2018
 
1979
- let u$3 = class u extends y {
2019
+ let c$2 = class c extends C$1 {
1980
2020
  options;
1981
2021
  cursor = 0;
1982
2022
  constructor(t) {
1983
2023
  super(t, false), this.options = t.options;
1984
- const s = t.caseSensitive === true, i = this.options.map(({ value: [e] }) => s ? e : e?.toLowerCase());
1985
- this.cursor = Math.max(i.indexOf(t.initialValue), 0), this.on("key", (e) => {
2024
+ const s = t.caseSensitive === true, i = this.options.map(({ value: [e] }) => s ? e : e?.toLowerCase()), n = Math.max(i.indexOf(t.initialValue), 0);
2025
+ this.cursor = this.options[n]?.disabled ? 0 : n, this.on("key", (e) => {
1986
2026
  if (!e)
1987
2027
  return;
1988
2028
  const o = s ? e : e.toLowerCase();
1989
2029
  if (!i.includes(o))
1990
2030
  return;
1991
- const n = this.options.find(({ value: [r] }) => s ? r === o : r?.toLowerCase() === o);
1992
- n && (this.value = n.value, this.state = "submit", this.emit("submit"));
2031
+ const r = this.options.find(({ value: [a], disabled: u }) => u ? false : s ? a === o : a?.toLowerCase() === o);
2032
+ r && (this.value = r.value, this.state = "submit", this.emit("submit"));
1993
2033
  });
1994
2034
  }
1995
2035
  };
1996
2036
 
1997
- class n extends y {
2037
+ class n extends C$1 {
1998
2038
  get userInputWithCursor() {
1999
2039
  if (this.state === "submit")
2000
2040
  return this.userInput;
@@ -2035,8 +2075,8 @@ function isUnicodeSupported() {
2035
2075
  || process$1.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
2036
2076
  }
2037
2077
 
2038
- const unicode = isUnicodeSupported(), isCI = () => process.env.CI === "true", isTTY = (o) => o.isTTY === true, unicodeOr = (o, e) => unicode ? o : e, S_STEP_ACTIVE = unicodeOr("\u25C6", "*"), S_STEP_CANCEL = unicodeOr("\u25A0", "x"), S_STEP_ERROR = unicodeOr("\u25B2", "x"), S_STEP_SUBMIT = unicodeOr("\u25C7", "o"), S_BAR_START = unicodeOr("\u250C", "T"), S_BAR = unicodeOr("\u2502", "|"), S_BAR_END = unicodeOr("\u2514", "\u2014"), S_BAR_START_RIGHT = unicodeOr("\u2510", "T"), S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014"), S_RADIO_ACTIVE = unicodeOr("\u25CF", ">"), S_RADIO_INACTIVE = unicodeOr("\u25CB", " "), S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]"), S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]"), S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]"), S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022"), S_BAR_H = unicodeOr("\u2500", "-"), S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+"), S_CONNECT_LEFT = unicodeOr("\u251C", "+"), S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+"), S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+"), S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+"), S_INFO = unicodeOr("\u25CF", "\u2022"), S_SUCCESS = unicodeOr("\u25C6", "*"), S_WARN = unicodeOr("\u25B2", "!"), S_ERROR = unicodeOr("\u25A0", "x"), symbol = (o) => {
2039
- switch (o) {
2078
+ const unicode = isUnicodeSupported(), isCI = () => process.env.CI === "true", isTTY = (e) => e.isTTY === true, unicodeOr = (e, o) => unicode ? e : o, S_STEP_ACTIVE = unicodeOr("\u25C6", "*"), S_STEP_CANCEL = unicodeOr("\u25A0", "x"), S_STEP_ERROR = unicodeOr("\u25B2", "x"), S_STEP_SUBMIT = unicodeOr("\u25C7", "o"), S_BAR_START = unicodeOr("\u250C", "T"), S_BAR = unicodeOr("\u2502", "|"), S_BAR_END = unicodeOr("\u2514", "\u2014"), S_BAR_START_RIGHT = unicodeOr("\u2510", "T"), S_BAR_END_RIGHT = unicodeOr("\u2518", "\u2014"), S_RADIO_ACTIVE = unicodeOr("\u25CF", ">"), S_RADIO_INACTIVE = unicodeOr("\u25CB", " "), S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]"), S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]"), S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]"), S_PASSWORD_MASK = unicodeOr("\u25AA", "\u2022"), S_BAR_H = unicodeOr("\u2500", "-"), S_CORNER_TOP_RIGHT = unicodeOr("\u256E", "+"), S_CONNECT_LEFT = unicodeOr("\u251C", "+"), S_CORNER_BOTTOM_RIGHT = unicodeOr("\u256F", "+"), S_CORNER_BOTTOM_LEFT = unicodeOr("\u2570", "+"), S_CORNER_TOP_LEFT = unicodeOr("\u256D", "+"), S_INFO = unicodeOr("\u25CF", "\u2022"), S_SUCCESS = unicodeOr("\u25C6", "*"), S_WARN = unicodeOr("\u25B2", "!"), S_ERROR = unicodeOr("\u25A0", "x"), symbol = (e) => {
2079
+ switch (e) {
2040
2080
  case "initial":
2041
2081
  case "active":
2042
2082
  return styleText("cyan", S_STEP_ACTIVE);
@@ -2049,8 +2089,8 @@ const unicode = isUnicodeSupported(), isCI = () => process.env.CI === "true", is
2049
2089
  case "validating":
2050
2090
  return styleText("dim", S_STEP_ACTIVE);
2051
2091
  }
2052
- }, symbolBar = (o) => {
2053
- switch (o) {
2092
+ }, symbolBar = (e) => {
2093
+ switch (e) {
2054
2094
  case "initial":
2055
2095
  case "active":
2056
2096
  return styleText("cyan", S_BAR);
@@ -2062,12 +2102,13 @@ const unicode = isUnicodeSupported(), isCI = () => process.env.CI === "true", is
2062
2102
  return styleText("green", S_BAR);
2063
2103
  }
2064
2104
  };
2065
- function formatInstructionFooter(o, e) {
2066
- const r = [`${e ? `${styleText("cyan", S_BAR)} ` : ""}${o.join(" \u2022 ")}`];
2067
- return e && r.push(styleText("cyan", S_BAR_END)), r;
2105
+ function formatInstructionFooter(e, o, r) {
2106
+ const s = r ? `${styleText("cyan", S_BAR)} ` : "", n = wrapTextWithPrefix(e, o.join(" \u2022 "), s).split(`
2107
+ `);
2108
+ return r && n.push(styleText("cyan", S_BAR_END)), n;
2068
2109
  }
2069
2110
 
2070
- const I = (l, e, w, p, b, C = false) => {
2111
+ const E$1 = (l, e, w, p, b, C = false) => {
2071
2112
  let r = e, O = 0;
2072
2113
  if (C)
2073
2114
  for (let i = p - 1; i >= w; i--) {
@@ -2097,15 +2138,15 @@ const limitOptions = ({
2097
2138
  0
2098
2139
  ));
2099
2140
  let d = a < e.length && f > 0, c = a < e.length && f + a < e.length;
2100
- const W = Math.min(
2141
+ const I = Math.min(
2101
2142
  f + a,
2102
2143
  e.length
2103
2144
  ), s = [];
2104
2145
  let g = 0;
2105
2146
  d && g++, c && g++;
2106
- const T = f + (d ? 1 : 0), y = W - (c ? 1 : 0);
2107
- for (let t = T; t < y; t++) {
2108
- const n = e[t], o = n ? w(n, t === l) : "", h = wrapAnsi(o, i, {
2147
+ const T = f + (d ? 1 : 0), W = I - (c ? 1 : 0);
2148
+ for (let t = T; t < W; t++) {
2149
+ const n = e[t], o = n !== void 0 ? w(n, t === l) : "", h = wrapAnsi(o, i, {
2109
2150
  hard: true,
2110
2151
  trim: false
2111
2152
  }).split(`
@@ -2116,7 +2157,7 @@ const limitOptions = ({
2116
2157
  let t = 0, n = 0, o = g;
2117
2158
  const h = l - T;
2118
2159
  let u = v;
2119
- const L = () => I(s, o, 0, h, u), E = () => I(
2160
+ const L = () => E$1(s, o, 0, h, u), y = () => E$1(
2120
2161
  s,
2121
2162
  o,
2122
2163
  h + 1,
@@ -2124,7 +2165,7 @@ const limitOptions = ({
2124
2165
  u,
2125
2166
  true
2126
2167
  );
2127
- d ? ({ lineCount: o, removals: t } = L(), o > u && (c || (u -= 1), { lineCount: o, removals: n } = E())) : (c || (u -= 1), { lineCount: o, removals: n } = E(), o > u && (u -= 1, { lineCount: o, removals: t } = L())), t > 0 && (d = true, s.splice(0, t)), n > 0 && (c = true, s.splice(s.length - n, n));
2168
+ d ? ({ lineCount: o, removals: t } = L(), o > u && (c || (u -= 1), { lineCount: o, removals: n } = y())) : (c || (u -= 1), { lineCount: o, removals: n } = y(), o > u && (u -= 1, { lineCount: o, removals: t } = L())), t > 0 && (d = true, s.splice(0, t)), n > 0 && (c = true, s.splice(s.length - n, n));
2128
2169
  }
2129
2170
  const x = [];
2130
2171
  d && x.push(M);
@@ -2151,7 +2192,7 @@ function j(t, c) {
2151
2192
  }
2152
2193
  const autocomplete = (t) => new T$1({
2153
2194
  options: t.options,
2154
- initialValue: t.initialValue ? [t.initialValue] : void 0,
2195
+ initialValue: t.initialValue !== void 0 ? [t.initialValue] : void 0,
2155
2196
  initialUserInput: t.initialUserInput,
2156
2197
  placeholder: t.placeholder,
2157
2198
  completeOnTab: t.completeOnTab,
@@ -2481,22 +2522,22 @@ const MULTISELECT_INSTRUCTIONS = [
2481
2522
  `${styleText("dim", "Space:")} select`,
2482
2523
  `${styleText("dim", "Enter:")} confirm`
2483
2524
  ];
2484
- const m = (i, u) => i.split(`
2525
+ const m = (n, u) => n.split(`
2485
2526
  `).map((d) => u(d)).join(`
2486
2527
  `);
2487
- const multiselect = (i) => {
2528
+ const multiselect = (n) => {
2488
2529
  const u = (t, a) => {
2489
2530
  const r = t.label ?? String(t.value);
2490
2531
  return a === "disabled" ? `${styleText("gray", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText(["strikethrough", "gray"], o))}${t.hint ? ` ${styleText("dim", `(${t.hint ?? "disabled"})`)}` : ""}` : a === "active" ? `${styleText("cyan", S_CHECKBOX_ACTIVE)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${m(r, (o) => styleText("dim", o))}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "cancelled" ? `${m(r, (o) => styleText(["strikethrough", "dim"], o))}` : a === "active-selected" ? `${styleText("green", S_CHECKBOX_SELECTED)} ${r}${t.hint ? ` ${styleText("dim", `(${t.hint})`)}` : ""}` : a === "submitted" ? `${m(r, (o) => styleText("dim", o))}` : `${styleText("dim", S_CHECKBOX_INACTIVE)} ${m(r, (o) => styleText("dim", o))}`;
2491
- }, d = i.required ?? true, x = i.showInstructions ?? true;
2532
+ }, d = n.required ?? true, x = n.showInstructions ?? true;
2492
2533
  return new a({
2493
- options: i.options,
2494
- signal: i.signal,
2495
- input: i.input,
2496
- output: i.output,
2497
- initialValues: i.initialValues,
2534
+ options: n.options,
2535
+ signal: n.signal,
2536
+ input: n.input,
2537
+ output: n.output,
2538
+ initialValues: n.initialValues,
2498
2539
  required: d,
2499
- cursorAt: i.cursorAt,
2540
+ cursorAt: n.cursorAt,
2500
2541
  validate(t) {
2501
2542
  if (d && (t === void 0 || t.length === 0))
2502
2543
  return `Please select at least one option.
@@ -2512,75 +2553,75 @@ ${styleText(
2512
2553
  )}`;
2513
2554
  },
2514
2555
  render() {
2515
- const t = i.withGuide ?? settings.withGuide, a = wrapTextWithPrefix(
2516
- i.output,
2517
- i.message,
2556
+ const t = n.withGuide ?? settings.withGuide, a = wrapTextWithPrefix(
2557
+ n.output,
2558
+ n.message,
2518
2559
  t ? `${symbolBar(this.state)} ` : "",
2519
2560
  `${symbol(this.state)} `
2520
2561
  ), r = `${t ? `${styleText("gray", S_BAR)}
2521
2562
  ` : ""}${a}
2522
- `, o = this.value ?? [], g = (n, l) => {
2523
- if (n.disabled)
2524
- return u(n, "disabled");
2525
- const s = o.includes(n.value);
2526
- return l && s ? u(n, "active-selected") : s ? u(n, "selected") : u(n, l ? "active" : "inactive");
2563
+ `, o = this.value ?? [], g = (i, l) => {
2564
+ if (i.disabled)
2565
+ return u(i, "disabled");
2566
+ const s = o.includes(i.value);
2567
+ return l && s ? u(i, "active-selected") : s ? u(i, "selected") : u(i, l ? "active" : "inactive");
2527
2568
  };
2528
2569
  switch (this.state) {
2529
2570
  case "submit": {
2530
- const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none"), l = wrapTextWithPrefix(
2531
- i.output,
2532
- n,
2571
+ const i = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "submitted")).join(styleText("dim", ", ")) || styleText("dim", "none"), l = wrapTextWithPrefix(
2572
+ n.output,
2573
+ i,
2533
2574
  t ? `${styleText("gray", S_BAR)} ` : ""
2534
2575
  );
2535
2576
  return `${r}${l}`;
2536
2577
  }
2537
2578
  case "cancel": {
2538
- const n = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "cancelled")).join(styleText("dim", ", "));
2539
- if (n.trim() === "")
2579
+ const i = this.options.filter(({ value: s }) => o.includes(s)).map((s) => u(s, "cancelled")).join(styleText("dim", ", "));
2580
+ if (i.trim() === "")
2540
2581
  return `${r}${styleText("gray", S_BAR)}`;
2541
2582
  const l = wrapTextWithPrefix(
2542
- i.output,
2543
- n,
2583
+ n.output,
2584
+ i,
2544
2585
  t ? `${styleText("gray", S_BAR)} ` : ""
2545
2586
  );
2546
2587
  return `${r}${l}${t ? `
2547
2588
  ${styleText("gray", S_BAR)}` : ""}`;
2548
2589
  }
2549
2590
  case "error": {
2550
- const n = t ? `${styleText("yellow", S_BAR)} ` : "", l = this.error.split(`
2591
+ const i = t ? `${styleText("yellow", S_BAR)} ` : "", l = this.error.split(`
2551
2592
  `).map(
2552
2593
  ($, v) => v === 0 ? `${t ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", $)}` : ` ${$}`
2553
2594
  ).join(`
2554
2595
  `), s = r.split(`
2555
2596
  `).length, h = l.split(`
2556
2597
  `).length + 1;
2557
- return `${r}${n}${limitOptions({
2558
- output: i.output,
2598
+ return `${r}${i}${limitOptions({
2599
+ output: n.output,
2559
2600
  options: this.options,
2560
2601
  cursor: this.cursor,
2561
- maxItems: i.maxItems,
2562
- columnPadding: n.length,
2602
+ maxItems: n.maxItems,
2603
+ columnPadding: i.length,
2563
2604
  rowPadding: s + h,
2564
2605
  style: g
2565
2606
  }).join(`
2566
- ${n}`)}
2607
+ ${i}`)}
2567
2608
  ${l}
2568
2609
  `;
2569
2610
  }
2570
2611
  default: {
2571
- const n = t ? `${styleText("cyan", S_BAR)} ` : "", l = r.split(`
2572
- `).length, s = x ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, t) : t ? [styleText("cyan", S_BAR_END)] : [], h = s.join(`
2612
+ const i = t ? `${styleText("cyan", S_BAR)} ` : "", l = r.split(`
2613
+ `).length, s = x ? formatInstructionFooter(n.output, MULTISELECT_INSTRUCTIONS, t) : t ? [styleText("cyan", S_BAR_END)] : [], h = s.join(`
2573
2614
  `), $ = s.length + 1;
2574
- return `${r}${n}${limitOptions({
2575
- output: i.output,
2615
+ return `${r}${i}${limitOptions({
2616
+ output: n.output,
2576
2617
  options: this.options,
2577
2618
  cursor: this.cursor,
2578
- maxItems: i.maxItems,
2579
- columnPadding: n.length,
2619
+ maxItems: n.maxItems,
2620
+ columnPadding: i.length,
2580
2621
  rowPadding: l + $,
2581
2622
  style: g
2582
2623
  }).join(`
2583
- ${n}`)}
2624
+ ${i}`)}
2584
2625
  ${h}
2585
2626
  `;
2586
2627
  }
@@ -2589,46 +2630,46 @@ ${h}
2589
2630
  }).prompt();
2590
2631
  };
2591
2632
 
2592
- const groupMultiselect = (o) => {
2593
- const { selectableGroups: f = true, groupSpacing: x = 0 } = o, d = (n, l, p = []) => {
2594
- const a = n.label ?? String(n.value), t = typeof n.group == "string", s = t && (p[p.indexOf(n) + 1] ?? { group: true }), u = t && s && s.group === true;
2595
- let r = "", c = "";
2596
- t && (f ? (r = u ? `${S_BAR_END} ` : `${S_BAR} `, c = u ? " " : `${S_BAR} `) : r = " ");
2633
+ const groupMultiselect = (r) => {
2634
+ const { selectableGroups: f = true, groupSpacing: x = 0 } = r, d = (n, l, p = []) => {
2635
+ const a = n.label ?? String(n.value), t = typeof n.group == "string", u = t && (p[p.indexOf(n) + 1] ?? { group: true }), s = t && u && u.group === true;
2636
+ let o = "", c = "";
2637
+ t && (f ? (o = s ? `${S_BAR_END} ` : `${S_BAR} `, c = s ? " " : `${S_BAR} `) : o = " ");
2597
2638
  let i = "";
2598
2639
  if (x > 0 && !t && (i = `
2599
2640
  `.repeat(x)), l === "active")
2600
2641
  return wrapTextWithPrefix(
2601
- o.output,
2642
+ r.output,
2602
2643
  `${a}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`,
2603
- `${i}${styleText("dim", r)} `,
2604
- `${i}${styleText("dim", r)}${styleText("cyan", S_CHECKBOX_ACTIVE)} `,
2644
+ `${i}${styleText("dim", o)} `,
2645
+ `${i}${styleText("dim", o)}${styleText("cyan", S_CHECKBOX_ACTIVE)} `,
2605
2646
  `${i}${styleText("dim", c)} `
2606
2647
  );
2607
2648
  if (l === "group-active")
2608
2649
  return wrapTextWithPrefix(
2609
- o.output,
2650
+ r.output,
2610
2651
  a,
2611
- `${i}${r} `,
2612
- `${i}${r}${styleText("cyan", S_CHECKBOX_ACTIVE)} `,
2652
+ `${i}${o} `,
2653
+ `${i}${o}${styleText("cyan", S_CHECKBOX_ACTIVE)} `,
2613
2654
  `${i}${c} `,
2614
2655
  (m) => styleText("dim", m)
2615
2656
  );
2616
2657
  if (l === "group-active-selected")
2617
2658
  return wrapTextWithPrefix(
2618
- o.output,
2659
+ r.output,
2619
2660
  a,
2620
- `${i}${r} `,
2621
- `${i}${r}${styleText("green", S_CHECKBOX_SELECTED)} `,
2661
+ `${i}${o} `,
2662
+ `${i}${o}${styleText("green", S_CHECKBOX_SELECTED)} `,
2622
2663
  `${i}${c} `,
2623
2664
  (m) => styleText("dim", m)
2624
2665
  );
2625
2666
  if (l === "selected") {
2626
2667
  const m = t || f ? styleText("green", S_CHECKBOX_SELECTED) : "";
2627
2668
  return wrapTextWithPrefix(
2628
- o.output,
2669
+ r.output,
2629
2670
  `${a}${n.hint ? ` (${n.hint})` : ""}`,
2630
- `${i}${styleText("dim", r)} `,
2631
- `${i}${styleText("dim", r)}${m} `,
2671
+ `${i}${styleText("dim", o)} `,
2672
+ `${i}${styleText("dim", o)}${m} `,
2632
2673
  `${i}${styleText("dim", c)} `,
2633
2674
  (I) => styleText("dim", I)
2634
2675
  );
@@ -2637,32 +2678,32 @@ const groupMultiselect = (o) => {
2637
2678
  return `${styleText(["strikethrough", "dim"], a)}`;
2638
2679
  if (l === "active-selected")
2639
2680
  return wrapTextWithPrefix(
2640
- o.output,
2681
+ r.output,
2641
2682
  `${a}${n.hint ? ` ${styleText("dim", `(${n.hint})`)}` : ""}`,
2642
- `${i}${styleText("dim", r)} `,
2643
- `${i}${styleText("dim", r)}${styleText("green", S_CHECKBOX_SELECTED)} `,
2683
+ `${i}${styleText("dim", o)} `,
2684
+ `${i}${styleText("dim", o)}${styleText("green", S_CHECKBOX_SELECTED)} `,
2644
2685
  `${i}${styleText("dim", c)} `
2645
2686
  );
2646
2687
  if (l === "submitted")
2647
2688
  return `${styleText("dim", a)}`;
2648
2689
  const h = t || f ? styleText("dim", S_CHECKBOX_INACTIVE) : "";
2649
2690
  return wrapTextWithPrefix(
2650
- o.output,
2691
+ r.output,
2651
2692
  a,
2652
- `${i}${styleText("dim", r)} `,
2653
- `${i}${styleText("dim", r)}${h} `,
2693
+ `${i}${styleText("dim", o)} `,
2694
+ `${i}${styleText("dim", o)}${h} `,
2654
2695
  `${i}${styleText("dim", c)} `,
2655
2696
  (m) => styleText("dim", m)
2656
2697
  );
2657
- }, y = o.required ?? true, S = o.showInstructions ?? true;
2658
- return new u$2({
2659
- options: o.options,
2660
- signal: o.signal,
2661
- input: o.input,
2662
- output: o.output,
2663
- initialValues: o.initialValues,
2698
+ }, y = r.required ?? true, S = r.showInstructions ?? true;
2699
+ return new u$1({
2700
+ options: r.options,
2701
+ signal: r.signal,
2702
+ input: r.input,
2703
+ output: r.output,
2704
+ initialValues: r.initialValues,
2664
2705
  required: y,
2665
- cursorAt: o.cursorAt,
2706
+ cursorAt: r.cursorAt,
2666
2707
  selectableGroups: f,
2667
2708
  validate(n) {
2668
2709
  if (y && (n === void 0 || n.length === 0))
@@ -2679,58 +2720,58 @@ ${styleText(
2679
2720
  )}`;
2680
2721
  },
2681
2722
  render() {
2682
- const n = o.withGuide ?? settings.withGuide, l = `${n ? `${styleText("gray", S_BAR)}
2683
- ` : ""}${symbol(this.state)} ${o.message}
2684
- `, p = this.value ?? [], a = (t, s) => {
2685
- const u = this.options, r = p.includes(t.value) || t.group === true && this.isGroupSelected(`${t.value}`);
2686
- return !s && typeof t.group == "string" && this.options[this.cursor]?.value === t.group ? d(t, r ? "group-active-selected" : "group-active", u) : s && r ? d(t, "active-selected", u) : r ? d(t, "selected", u) : d(t, s ? "active" : "inactive", u);
2723
+ const n = r.withGuide ?? settings.withGuide, l = `${n ? `${styleText("gray", S_BAR)}
2724
+ ` : ""}${symbol(this.state)} ${r.message}
2725
+ `, p = this.value ?? [], a = (t, u) => {
2726
+ const s = this.options, o = p.includes(t.value) || t.group === true && this.isGroupSelected(`${t.value}`);
2727
+ return !u && typeof t.group == "string" && this.options[this.cursor]?.value === t.group ? d(t, o ? "group-active-selected" : "group-active", s) : u && o ? d(t, "active-selected", s) : o ? d(t, "selected", s) : d(t, u ? "active" : "inactive", s);
2687
2728
  };
2688
2729
  switch (this.state) {
2689
2730
  case "submit": {
2690
- const t = this.options.filter(({ value: u }) => p.includes(u)).map((u) => d(u, "submitted")), s = t.length === 0 ? "" : ` ${t.join(styleText("dim", ", "))}`;
2691
- return `${l}${n ? styleText("gray", S_BAR) : ""}${s}`;
2731
+ const t = this.options.filter(({ value: s }) => p.includes(s)).map((s) => d(s, "submitted")), u = t.length === 0 ? "" : ` ${t.join(styleText("dim", ", "))}`;
2732
+ return `${l}${n ? styleText("gray", S_BAR) : ""}${u}`;
2692
2733
  }
2693
2734
  case "cancel": {
2694
- const t = this.options.filter(({ value: s }) => p.includes(s)).map((s) => d(s, "cancelled")).join(styleText("dim", ", "));
2735
+ const t = this.options.filter(({ value: u }) => p.includes(u)).map((u) => d(u, "cancelled")).join(styleText("dim", ", "));
2695
2736
  return `${l}${n ? `${styleText("gray", S_BAR)} ` : ""}${t.trim() ? `${t}${n ? `
2696
2737
  ${styleText("gray", S_BAR)}` : ""}` : ""}`;
2697
2738
  }
2698
2739
  case "error": {
2699
- const t = n ? `${styleText("yellow", S_BAR)} ` : "", s = this.error.split(`
2740
+ const t = n ? `${styleText("yellow", S_BAR)} ` : "", u = this.error.split(`
2700
2741
  `).map(
2701
2742
  (i, h) => h === 0 ? `${n ? `${styleText("yellow", S_BAR_END)} ` : ""}${styleText("yellow", i)}` : ` ${i}`
2702
2743
  ).join(`
2703
- `), u = l.split(`
2704
- `).length, r = s.split(`
2744
+ `), s = l.split(`
2745
+ `).length, o = u.split(`
2705
2746
  `).length + 1, c = limitOptions({
2706
- output: o.output,
2747
+ output: r.output,
2707
2748
  options: this.options,
2708
2749
  cursor: this.cursor,
2709
- maxItems: o.maxItems,
2750
+ maxItems: r.maxItems,
2710
2751
  columnPadding: t.length,
2711
- rowPadding: u + r,
2752
+ rowPadding: s + o,
2712
2753
  style: a
2713
2754
  }).join(`
2714
2755
  ${t}`);
2715
2756
  return `${l}${t}${c}
2716
- ${s}
2757
+ ${u}
2717
2758
  `;
2718
2759
  }
2719
2760
  default: {
2720
- const t = n ? `${styleText("cyan", S_BAR)} ` : "", s = l.split(`
2721
- `).length, u = S ? formatInstructionFooter(MULTISELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], r = u.join(`
2722
- `), c = u.length + 1, i = limitOptions({
2723
- output: o.output,
2761
+ const t = n ? `${styleText("cyan", S_BAR)} ` : "", u = l.split(`
2762
+ `).length, s = S ? formatInstructionFooter(r.output, MULTISELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], o = s.join(`
2763
+ `), c = s.length + 1, i = limitOptions({
2764
+ output: r.output,
2724
2765
  options: this.options,
2725
2766
  cursor: this.cursor,
2726
- maxItems: o.maxItems,
2767
+ maxItems: r.maxItems,
2727
2768
  columnPadding: t.length,
2728
- rowPadding: s + c,
2769
+ rowPadding: u + c,
2729
2770
  style: a
2730
2771
  }).join(`
2731
2772
  ${t}`);
2732
2773
  return `${l}${t}${i}
2733
- ${r}
2774
+ ${o}
2734
2775
  `;
2735
2776
  }
2736
2777
  }
@@ -2855,7 +2896,7 @@ ${r}${d}
2855
2896
  }
2856
2897
  }).prompt();
2857
2898
 
2858
- const W$1 = (o) => o, C = (o, e, s) => {
2899
+ const W = (o) => o, C = (o, e, s) => {
2859
2900
  const a = {
2860
2901
  hard: true,
2861
2902
  trim: false
@@ -2864,7 +2905,7 @@ const W$1 = (o) => o, C = (o, e, s) => {
2864
2905
  return wrapAnsi(o, g, a);
2865
2906
  };
2866
2907
  const note = (o = "", e = "", s) => {
2867
- const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W$1, g = ["", ...C(o, getColumns(a) - 6, c).split(`
2908
+ const a = s?.output ?? process$1.stdout, i = s?.withGuide ?? settings.withGuide, c = s?.format ?? W, g = ["", ...C(o, getColumns(a) - 6, c).split(`
2868
2909
  `).map(c), ""], n = fastStringWidth(e), t = Math.max(
2869
2910
  g.reduce((m, F) => {
2870
2911
  const O = fastStringWidth(F);
@@ -2887,7 +2928,7 @@ ${styleText("gray", l$1 + S_BAR_H.repeat(t + 2) + S_CORNER_BOTTOM_RIGHT)}
2887
2928
  );
2888
2929
  };
2889
2930
 
2890
- const password = (e) => new u$1({
2931
+ const password = (e) => new u$2({
2891
2932
  validate: e.validate,
2892
2933
  mask: e.mask ?? S_PASSWORD_MASK,
2893
2934
  signal: e.signal,
@@ -2945,17 +2986,18 @@ const path = (e) => {
2945
2986
  return [];
2946
2987
  try {
2947
2988
  let i;
2948
- existsSync(t) ? lstatSync(t).isDirectory() && (!e.directory || t.endsWith("/")) ? i = t : i = dirname(t) : i = dirname(t);
2949
- const c = t.length > 1 && t.endsWith("/") ? t.slice(0, -1) : t;
2989
+ const o = t.endsWith("/") || t.endsWith("\\");
2990
+ existsSync(t) ? lstatSync(t).isDirectory() && (!e.directory || o) ? i = t : i = dirname(t) : i = dirname(t);
2991
+ const m = t.length > 1 && o ? t.slice(0, -1) : t;
2950
2992
  return readdirSync(i).map((r) => {
2951
- const n = join(i, r), m = lstatSync(n);
2993
+ const n = join(i, r), l = lstatSync(n);
2952
2994
  return {
2953
2995
  name: r,
2954
2996
  path: n,
2955
- isDirectory: m.isDirectory()
2997
+ isDirectory: l.isDirectory()
2956
2998
  };
2957
2999
  }).filter(
2958
- ({ path: r, isDirectory: n }) => r.startsWith(c) && (n || !e.directory)
3000
+ ({ path: r, isDirectory: n }) => r.startsWith(m) && (n || !e.directory)
2959
3001
  ).map((r) => ({
2960
3002
  value: r.path
2961
3003
  }));
@@ -2966,83 +3008,101 @@ const path = (e) => {
2966
3008
  });
2967
3009
  };
2968
3010
 
2969
- const W = (l) => styleText("magenta", l);
3011
+ const Y = 3e4, Z = (c) => styleText("magenta", c);
2970
3012
  const spinner = ({
2971
- indicator: l = "dots",
2972
- onCancel: h,
3013
+ indicator: c = "dots",
3014
+ onCancel: b,
2973
3015
  output: n = process.stdout,
2974
- cancelMessage: G,
2975
- errorMessage: O,
2976
- frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
2977
- delay: F = unicode ? 80 : 120,
2978
- signal: m,
2979
- ...I
3016
+ cancelMessage: _,
3017
+ errorMessage: C,
3018
+ frames: M = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
3019
+ delay: O = unicode ? 80 : 120,
3020
+ signal: g,
3021
+ ...E
2980
3022
  } = {}) => {
2981
- const u = isCI();
2982
- let M, T, d = false, S = false, s = "", p, w = performance.now();
2983
- const x = getColumns(n), k = I?.styleFrame ?? W, g = (e) => {
2984
- const r = e > 1 ? O ?? settings.messages.error : G ?? settings.messages.cancel;
2985
- S = e === 1, d && (a(r, e), S && typeof h == "function" && h());
2986
- }, f = () => g(2), i = () => g(1), A = () => {
2987
- process.on("uncaughtExceptionMonitor", f), process.on("unhandledRejection", f), process.on("SIGINT", i), process.on("SIGTERM", i), process.on("exit", g), m && m.addEventListener("abort", i);
2988
- }, H = () => {
2989
- process.removeListener("uncaughtExceptionMonitor", f), process.removeListener("unhandledRejection", f), process.removeListener("SIGINT", i), process.removeListener("SIGTERM", i), process.removeListener("exit", g), m && m.removeEventListener("abort", i);
2990
- }, y = () => {
2991
- if (p === void 0) return;
3023
+ const u = isCI(), h = isAccessible(E.accessible);
3024
+ let x, I, p = false, l = false, r = "", v, w = performance.now();
3025
+ const y = getColumns(n), F = E?.styleFrame ?? Z, S = (e) => {
3026
+ const s = e > 1 ? C ?? settings.messages.error : _ ?? settings.messages.cancel;
3027
+ l = e === 1, p && (m(s, e), l && typeof b == "function" && b());
3028
+ }, $ = () => S(2), a = () => S(1), H = () => {
3029
+ process.on("uncaughtExceptionMonitor", $), process.on("unhandledRejection", $), process.on("SIGINT", a), process.on("SIGTERM", a), process.on("exit", S), g && g.addEventListener("abort", a);
3030
+ }, B = () => {
3031
+ process.removeListener("uncaughtExceptionMonitor", $), process.removeListener("unhandledRejection", $), process.removeListener("SIGINT", a), process.removeListener("SIGTERM", a), process.removeListener("exit", S), g && g.removeEventListener("abort", a);
3032
+ }, R = () => {
3033
+ if (v === void 0) return;
2992
3034
  u && n.write(`
2993
3035
  `);
2994
- const r = wrapAnsi(p, x, {
3036
+ const s = wrapAnsi(v, y, {
2995
3037
  hard: true,
2996
3038
  trim: false
2997
3039
  }).split(`
2998
3040
  `);
2999
- r.length > 1 && n.write(srcExports.cursor.up(r.length - 1)), n.write(srcExports.cursor.to(0)), n.write(srcExports.erase.down());
3000
- }, C = (e) => e.replace(/\.+$/, ""), _ = (e) => {
3001
- const r = (performance.now() - e) / 1e3, t = Math.floor(r / 60), o = Math.floor(r % 60);
3002
- return t > 0 ? `[${t}m ${o}s]` : `[${o}s]`;
3003
- }, N = I.withGuide ?? settings.withGuide, P = (e = "") => {
3004
- d = true, M = block({ output: n }), s = C(e), w = performance.now(), N && n.write(`${styleText("gray", S_BAR)}
3041
+ s.length > 1 && n.write(cursor.up(s.length - 1)), n.write(cursor.to(0)), n.write(erase.down());
3042
+ }, L = (e) => e.replace(/\.+$/, ""), T = (e) => {
3043
+ const s = (performance.now() - e) / 1e3, i = Math.floor(s / 60), t = Math.floor(s % 60);
3044
+ return i > 0 ? `[${i}m ${t}s]` : `[${t}s]`;
3045
+ }, N = E.withGuide ?? settings.withGuide, P = (e = "") => {
3046
+ if (p = true, l = false, r = L(e), w = performance.now(), H(), h) {
3047
+ r !== "" && n.write(`${r}
3048
+ `), I = setInterval(() => {
3049
+ n.write(r === "" ? `still working
3050
+ ` : `still working: ${r}
3005
3051
  `);
3006
- let r = 0, t = 0;
3007
- A(), T = setInterval(() => {
3008
- if (u && s === p)
3052
+ }, Y);
3053
+ return;
3054
+ }
3055
+ x = block({ output: n }), N && n.write(`${styleText("gray", S_BAR)}
3056
+ `);
3057
+ let s = 0, i = 0;
3058
+ I = setInterval(() => {
3059
+ if (u && r === v)
3009
3060
  return;
3010
- y(), p = s;
3011
- const o = k(E[r]);
3012
- let v;
3061
+ R(), v = r;
3062
+ const t = F(M[s]);
3063
+ let o;
3013
3064
  if (u)
3014
- v = `${o} ${s}...`;
3015
- else if (l === "timer")
3016
- v = `${o} ${s} ${_(w)}`;
3065
+ o = `${t} ${r}...`;
3066
+ else if (c === "timer")
3067
+ o = `${t} ${r} ${T(w)}`;
3017
3068
  else {
3018
- const B = ".".repeat(Math.floor(t)).slice(0, 3);
3019
- v = `${o} ${s}${B}`;
3069
+ const j = ".".repeat(Math.floor(i)).slice(0, 3);
3070
+ o = `${t} ${r}${j}`;
3020
3071
  }
3021
- const j = wrapAnsi(v, x, {
3072
+ const D = wrapAnsi(o, y, {
3022
3073
  hard: true,
3023
3074
  trim: false
3024
3075
  });
3025
- n.write(j), r = r + 1 < E.length ? r + 1 : 0, t = t < 4 ? t + 0.125 : 0;
3026
- }, F);
3027
- }, a = (e = "", r = 0, t = false) => {
3028
- if (!d) return;
3029
- d = false, clearInterval(T), y();
3030
- const o = r === 0 ? styleText("green", S_STEP_SUBMIT) : r === 1 ? styleText("red", S_STEP_CANCEL) : styleText("red", S_STEP_ERROR);
3031
- s = e ?? s, t || (l === "timer" ? n.write(`${o} ${s} ${_(w)}
3032
- `) : n.write(`${o} ${s}
3033
- `)), H(), M();
3076
+ n.write(D), s = s + 1 < M.length ? s + 1 : 0, i = i < 4 ? i + 0.125 : 0;
3077
+ }, O);
3078
+ }, m = (e = "", s = 0, i = false) => {
3079
+ if (p) {
3080
+ if (p = false, l = s === 1, clearInterval(I), h || R(), r = e ?? r, !i)
3081
+ if (h) {
3082
+ const t = s === 1 ? _ ?? settings.messages.cancel : s === 2 ? C ?? settings.messages.error : "Done", o = r || t;
3083
+ c === "timer" ? n.write(`${o} ${T(w)}
3084
+ `) : n.write(`${o}
3085
+ `);
3086
+ } else {
3087
+ const t = s === 0 ? styleText("green", S_STEP_SUBMIT) : s === 1 ? styleText("red", S_STEP_CANCEL) : styleText("red", S_STEP_ERROR);
3088
+ c === "timer" ? n.write(`${t} ${r} ${T(w)}
3089
+ `) : n.write(`${t} ${r}
3090
+ `);
3091
+ }
3092
+ B(), x?.();
3093
+ }
3034
3094
  };
3035
3095
  return {
3036
3096
  start: P,
3037
- stop: (e = "") => a(e, 0),
3097
+ stop: (e = "") => m(e, 0),
3038
3098
  message: (e = "") => {
3039
- s = C(e ?? s);
3099
+ r = L(e ?? r);
3040
3100
  },
3041
- cancel: (e = "") => a(e, 1),
3042
- error: (e = "") => a(e, 2),
3043
- clear: () => a("", 0, true),
3101
+ cancel: (e = "") => m(e, 1),
3102
+ error: (e = "") => m(e, 2),
3103
+ clear: () => m("", 0, true),
3044
3104
  get isCancelled() {
3045
- return S;
3105
+ return l;
3046
3106
  }
3047
3107
  };
3048
3108
  };
@@ -3088,7 +3148,9 @@ function progress({
3088
3148
  error: r.error,
3089
3149
  clear: r.clear,
3090
3150
  advance: g,
3091
- isCancelled: r.isCancelled,
3151
+ get isCancelled() {
3152
+ return r.isCancelled;
3153
+ },
3092
3154
  message: (t) => g(0, t)
3093
3155
  };
3094
3156
  }
@@ -3154,7 +3216,7 @@ ${styleText("gray", S_BAR)}` : ""}`;
3154
3216
  }
3155
3217
  default: {
3156
3218
  const r = n ? `${styleText("cyan", S_BAR)} ` : "", a = u.split(`
3157
- `).length, p = d ? formatInstructionFooter(SELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], f = p.join(`
3219
+ `).length, p = d ? formatInstructionFooter(t.output, SELECT_INSTRUCTIONS, n) : n ? [styleText("cyan", S_BAR_END)] : [], f = p.join(`
3158
3220
  `), b = p.length + 1;
3159
3221
  return `${u}${r}${limitOptions({
3160
3222
  output: t.output,
@@ -3174,36 +3236,36 @@ ${f}
3174
3236
  }).prompt();
3175
3237
  };
3176
3238
 
3177
- const selectKey = (t) => {
3239
+ const selectKey = (i) => {
3178
3240
  const c = (e, a = "inactive") => {
3179
3241
  if (e === void 0)
3180
3242
  return "";
3181
3243
  const n = e.label ?? String(e.value);
3182
- return a === "selected" ? `${styleText("dim", n)}` : a === "cancelled" ? `${styleText(["strikethrough", "dim"], n)}` : a === "active" ? `${styleText(["bgCyan", "gray"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}` : `${styleText(["gray", "bgWhite", "inverse"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}`;
3244
+ return a === "disabled" ? `${styleText("dim", ` ${e.value} `)} ${styleText("gray", n)}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}` : a === "selected" ? `${styleText("dim", n)}` : a === "cancelled" ? `${styleText(["strikethrough", "dim"], n)}` : a === "active" ? `${styleText(["bgCyan", "gray"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}` : `${styleText(["gray", "bgWhite", "inverse"], ` ${e.value} `)} ${n}${e.hint ? ` ${styleText("dim", `(${e.hint})`)}` : ""}`;
3183
3245
  };
3184
- return new u$3({
3185
- options: t.options,
3186
- signal: t.signal,
3187
- input: t.input,
3188
- output: t.output,
3189
- initialValue: t.initialValue,
3190
- caseSensitive: t.caseSensitive,
3246
+ return new c$2({
3247
+ options: i.options,
3248
+ signal: i.signal,
3249
+ input: i.input,
3250
+ output: i.output,
3251
+ initialValue: i.initialValue,
3252
+ caseSensitive: i.caseSensitive,
3191
3253
  render() {
3192
- const e = t.withGuide ?? settings.withGuide, a = `${e ? `${styleText("gray", S_BAR)}
3193
- ` : ""}${symbol(this.state)} ${t.message}
3254
+ const e = i.withGuide ?? settings.withGuide, a = `${e ? `${styleText("gray", S_BAR)}
3255
+ ` : ""}${symbol(this.state)} ${i.message}
3194
3256
  `;
3195
3257
  switch (this.state) {
3196
3258
  case "submit": {
3197
- const n = e ? `${styleText("gray", S_BAR)} ` : "", r = this.options.find((u) => u.value === this.value) ?? t.options[0], l = wrapTextWithPrefix(
3198
- t.output,
3259
+ const n = e ? `${styleText("gray", S_BAR)} ` : "", r = this.options.find((l) => l.value === this.value) ?? i.options[0], u = wrapTextWithPrefix(
3260
+ i.output,
3199
3261
  c(r, "selected"),
3200
3262
  n
3201
3263
  );
3202
- return `${a}${l}`;
3264
+ return `${a}${u}`;
3203
3265
  }
3204
3266
  case "cancel": {
3205
3267
  const n = e ? `${styleText("gray", S_BAR)} ` : "", r = wrapTextWithPrefix(
3206
- t.output,
3268
+ i.output,
3207
3269
  c(this.options[0], "cancelled"),
3208
3270
  n
3209
3271
  );
@@ -3211,15 +3273,18 @@ const selectKey = (t) => {
3211
3273
  ${styleText("gray", S_BAR)}` : ""}`;
3212
3274
  }
3213
3275
  default: {
3214
- const n = e ? `${styleText("cyan", S_BAR)} ` : "", r = e ? styleText("cyan", S_BAR_END) : "", l = this.options.map(
3215
- (u, d) => wrapTextWithPrefix(
3216
- t.output,
3217
- c(u, d === this.cursor ? "active" : "inactive"),
3276
+ const n = e ? `${styleText("cyan", S_BAR)} ` : "", r = e ? styleText("cyan", S_BAR_END) : "", u = this.options.map(
3277
+ (l, $) => wrapTextWithPrefix(
3278
+ i.output,
3279
+ c(
3280
+ l,
3281
+ l.disabled ? "disabled" : $ === this.cursor ? "active" : "inactive"
3282
+ ),
3218
3283
  n
3219
3284
  )
3220
3285
  ).join(`
3221
3286
  `);
3222
- return `${a}${l}
3287
+ return `${a}${u}
3223
3288
  ${r}
3224
3289
  `;
3225
3290
  }
@@ -3297,7 +3362,7 @@ ${t.header}`);
3297
3362
  `).reduce((b, w) => w === "" ? b + 1 : b + Math.ceil((w.length + k) / O), 0);
3298
3363
  s += E;
3299
3364
  }
3300
- s > 0 && (s += 1, r.write(srcExports.erase.lines(s)));
3365
+ s > 0 && (s += 1, r.write(erase.lines(s)));
3301
3366
  }, h = (e, s, t) => {
3302
3367
  const o = t ? `${e.full}
3303
3368
  ${e.value}` : e.value;
@@ -3528,6 +3593,7 @@ Options
3528
3593
  --no-install don't install dependencies
3529
3594
  --force move a non-empty folder aside first
3530
3595
  -y, --yes accept every default, ask nothing
3596
+ --check check that pnpm is ready, create nothing
3531
3597
  -h, --help show this help
3532
3598
  -v, --version show the CLI and template versions
3533
3599
 
@@ -4040,6 +4106,12 @@ async function run(plan, ui, deps = {}) {
4040
4106
  },
4041
4107
  });
4042
4108
  try {
4109
+ // pnpm first: a pnpm that can't switch to the template's version stops the run before any file.
4110
+ const spec = pnpmSpec(await readFile(join(from, 'package.json'), 'utf8'));
4111
+ const pin = spec.slice('pnpm@'.length);
4112
+ const pnpm = await detectPnpm(exec);
4113
+ if (pnpm.kind === 'ok')
4114
+ await checkSwitch(spec, pnpm.version, exec);
4043
4115
  await (deps.generate ?? generate)({
4044
4116
  from,
4045
4117
  to: temp,
@@ -4075,8 +4147,6 @@ async function run(plan, ui, deps = {}) {
4075
4147
  }
4076
4148
  }
4077
4149
  }
4078
- const pin = pnpmSpec(await readFile(join(from, 'package.json'), 'utf8')).slice('pnpm@'.length);
4079
- const pnpm = await detectPnpm(exec);
4080
4150
  const command = installCommand(pnpm, temp, !plan.install);
4081
4151
  let installed = false;
4082
4152
  let seconds = 0;
@@ -4120,7 +4190,7 @@ async function run(plan, ui, deps = {}) {
4120
4190
  outcome = await initAndCommit(temp, message, exec);
4121
4191
  }
4122
4192
  catch (error) {
4123
- // Ruling 11: the files are generated and correct, so a failed commit only warns.
4193
+ // The files are generated and correct, so a failed commit only warns.
4124
4194
  outcome = 'failed';
4125
4195
  ui.warn("Couldn't make the first commit", [
4126
4196
  firstLine(error),
@@ -4175,6 +4245,8 @@ async function run(plan, ui, deps = {}) {
4175
4245
 
4176
4246
  const USAGE = 2;
4177
4247
  const FAILURE = 1;
4248
+ /** The machine needs fixing first (pnpm can't switch versions, or is too old); nothing was created. */
4249
+ const TOOLCHAIN = 3;
4178
4250
  const INTERRUPTED = 130;
4179
4251
  const usage = (message) => {
4180
4252
  process.stderr.write(`${message}\n`);
@@ -4237,6 +4309,10 @@ function report(ui, error) {
4237
4309
  ui.fail(CANCELLED, []);
4238
4310
  return INTERRUPTED;
4239
4311
  }
4312
+ if (error instanceof ToolchainError) {
4313
+ ui.fail(error.message, error.lines);
4314
+ return TOOLCHAIN;
4315
+ }
4240
4316
  if (error instanceof RunError) {
4241
4317
  ui.fail(error.message, error.lines);
4242
4318
  return FAILURE;
@@ -4245,6 +4321,38 @@ function report(ui, error) {
4245
4321
  ui.fail(title, lines);
4246
4322
  return FAILURE;
4247
4323
  }
4324
+ /** `--check`: is this machine's pnpm ready for the template's? Creates nothing. */
4325
+ async function check(ui, exec) {
4326
+ const spec = pnpmSpec();
4327
+ const version = spec.slice('pnpm@'.length);
4328
+ ui.intro();
4329
+ const pnpm = await detectPnpm(exec);
4330
+ if (pnpm.kind === 'none') {
4331
+ ui.warn("pnpm isn't installed", [
4332
+ `Creating works: the install uses a temporary pnpm ${version} (npm exec).`,
4333
+ `Working in the project needs pnpm 10.26 or newer: https://pnpm.io/installation`,
4334
+ ]);
4335
+ return 0;
4336
+ }
4337
+ if (pnpm.kind === 'old') {
4338
+ ui.fail(`pnpm ${pnpm.version} is too old for this project`, [
4339
+ `This project needs pnpm 10.26 or newer, which switches itself to pnpm ${version}.`,
4340
+ 'Upgrade pnpm (https://pnpm.io/installation), then run --check again.',
4341
+ ]);
4342
+ return TOOLCHAIN;
4343
+ }
4344
+ try {
4345
+ await checkSwitch(spec, pnpm.version, exec);
4346
+ }
4347
+ catch (error) {
4348
+ if (!(error instanceof ToolchainError))
4349
+ throw error;
4350
+ ui.fail(error.message, error.lines);
4351
+ return TOOLCHAIN;
4352
+ }
4353
+ ui.step(`Ready: pnpm ${pnpm.version} switches to pnpm ${version} for this project`);
4354
+ return 0;
4355
+ }
4248
4356
  /** Runs the command and resolves with its exit code. */
4249
4357
  async function main(argv, io = {}) {
4250
4358
  const parsed = parseArgv(argv);
@@ -4259,6 +4367,8 @@ async function main(argv, io = {}) {
4259
4367
  process.stdout.write(`${versionText()}\n`);
4260
4368
  return 0;
4261
4369
  }
4370
+ if (options.check)
4371
+ return check(io.ui ?? plainUi(), io.exec);
4262
4372
  const cwd = io.cwd ?? process.cwd();
4263
4373
  const interactive = !options.yes && (io.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY));
4264
4374
  // A bad flag fails at once, before any question.