rolldown 0.14.0 → 0.15.0-commit.1265c2c
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/cjs/cli.cjs +960 -966
- package/dist/cjs/experimental-index.cjs +68 -26
- package/dist/cjs/index.cjs +6 -8
- package/dist/cjs/parallel-plugin-worker.cjs +20 -14
- package/dist/cjs/parallel-plugin.cjs +1 -3
- package/dist/esm/cli.mjs +914 -922
- package/dist/esm/experimental-index.mjs +44 -7
- package/dist/esm/index.mjs +2 -4
- package/dist/esm/parallel-plugin-worker.mjs +15 -10
- package/dist/esm/parallel-plugin.mjs +1 -3
- package/dist/shared/{chunk-JoMxl5V2.cjs → chunk-BFvIen8E.cjs} +13 -11
- package/dist/shared/{consola.36c0034f-HcmWcfPe.cjs → consola_36c0034f-B7L-radJ.cjs} +249 -295
- package/dist/shared/{consola.36c0034f-Xyw7SC_7.mjs → consola_36c0034f-D9ce-831.mjs} +221 -286
- package/dist/shared/{prompt-9Ij3R3TG.cjs → prompt-BiXtYIJ2.cjs} +157 -204
- package/dist/shared/{prompt-hoPhcrA-.mjs → prompt-DlQ-08lk.mjs} +125 -174
- package/dist/shared/src-BtX1cCkj.mjs +2851 -0
- package/dist/shared/src-Di4duR8G.cjs +2985 -0
- package/dist/tsconfig.dts.tsbuildinfo +1 -0
- package/dist/types/api/build.d.ts +16 -0
- package/dist/types/api/experimental.d.ts +7 -0
- package/dist/types/api/rolldown/index.d.ts +3 -0
- package/dist/types/api/rolldown/rolldown-build.d.ts +12 -0
- package/dist/types/api/watch/index.d.ts +3 -0
- package/dist/types/{watcher.d.ts → api/watch/watch-emitter.d.ts} +17 -17
- package/dist/types/api/watch/watcher.d.ts +13 -0
- package/dist/types/binding.d.ts +273 -49
- package/dist/types/builtin-plugin/alias-plugin.d.ts +10 -0
- package/dist/types/builtin-plugin/constructors.d.ts +16 -0
- package/dist/types/builtin-plugin/replace-plugin.d.ts +28 -0
- package/dist/types/{options/normalized-ecma-transform-plugin-config.d.ts → builtin-plugin/transform-plugin.d.ts} +2 -1
- package/dist/types/builtin-plugin/utils.d.ts +8 -0
- package/dist/types/cli/arguments/index.d.ts +5 -3
- package/dist/types/cli/arguments/normalize.d.ts +2 -6
- package/dist/types/cli/arguments/schema.d.ts +10 -309
- package/dist/types/cli/colors.d.ts +11 -1
- package/dist/types/cli/load-config.d.ts +3 -0
- package/dist/types/cli/logger.d.ts +5 -0
- package/dist/types/constants/plugin.d.ts +10 -1
- package/dist/types/experimental-index.d.ts +5 -2
- package/dist/types/index.d.ts +13 -10
- package/dist/types/log/logger.d.ts +2 -16
- package/dist/types/log/logging.d.ts +11 -8
- package/dist/types/log/logs.d.ts +3 -0
- package/dist/types/options/input-options-schema.d.ts +4 -0
- package/dist/types/options/input-options.d.ts +89 -430
- package/dist/types/options/normalized-input-options.d.ts +17 -11
- package/dist/types/options/normalized-output-options.d.ts +60 -21
- package/dist/types/options/output-options-schema.d.ts +3 -0
- package/dist/types/options/output-options.d.ts +73 -265
- package/dist/types/options/watch-options.d.ts +5 -0
- package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -11
- package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -5
- package/dist/types/plugin/bindingify-output-hooks.d.ts +13 -16
- package/dist/types/plugin/bindingify-plugin.d.ts +12 -3
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +3 -5
- package/dist/types/plugin/hook-filter.d.ts +1 -1
- package/dist/types/plugin/index.d.ts +21 -18
- package/dist/types/plugin/minimal-plugin-context.d.ts +15 -0
- package/dist/types/plugin/plugin-context-data.d.ts +4 -4
- package/dist/types/plugin/plugin-context.d.ts +9 -4
- package/dist/types/plugin/plugin-driver.d.ts +4 -5
- package/dist/types/plugin/transform-plugin-context.d.ts +4 -3
- package/dist/types/rollup-types.d.ts +1 -1
- package/dist/types/rollup.d.ts +4 -0
- package/dist/types/treeshake/index.d.ts +0 -12
- package/dist/types/treeshake/module-side-effects.d.ts +14 -15
- package/dist/types/types/rolldown-output.d.ts +17 -2
- package/dist/types/types/utils.d.ts +1 -0
- package/dist/types/utils/bindingify-input-options.d.ts +7 -0
- package/dist/types/utils/bindingify-output-options.d.ts +3 -0
- package/dist/types/utils/create-bundler-option.d.ts +11 -0
- package/dist/types/utils/define-config.d.ts +3 -0
- package/dist/types/utils/error.d.ts +2 -0
- package/dist/types/utils/misc.d.ts +1 -0
- package/dist/types/utils/normalize-hook.d.ts +1 -1
- package/dist/types/utils/normalize-plugin-option.d.ts +8 -3
- package/dist/types/{options/utils.d.ts → utils/normalize-string-or-regex.d.ts} +1 -1
- package/dist/types/utils/transform-rendered-chunk.d.ts +4 -0
- package/dist/types/utils/transform-rendered-module.d.ts +3 -0
- package/dist/types/utils/transform-sourcemap.d.ts +2 -0
- package/dist/types/utils/transform-to-rollup-output.d.ts +1 -0
- package/dist/types/utils/zod-ext.d.ts +6 -5
- package/package.json +30 -22
- package/dist/shared/rolldown-binding.wasi.cjs +0 -187
- package/dist/shared/src_index-3pqhEViJ.cjs +0 -2785
- package/dist/shared/src_index-ywYMd4vB.mjs +0 -2786
- package/dist/shared/wasi-worker-browser.mjs +0 -39
- package/dist/shared/wasi-worker.mjs +0 -63
- package/dist/shared/watcher-worker.js +0 -1
- package/dist/types/cli/utils.d.ts +0 -6
- package/dist/types/constants/types.d.ts +0 -1
- package/dist/types/options/bindingify-input-options.d.ts +0 -4
- package/dist/types/options/bindingify-output-options.d.ts +0 -3
- package/dist/types/options/normalized-alias-plugin-config.d.ts +0 -8
- package/dist/types/options/watch-option.d.ts +0 -5
- package/dist/types/plugin/builtin-plugin.d.ts +0 -81
- package/dist/types/rolldown-build.d.ts +0 -10
- package/dist/types/rolldown.d.ts +0 -12
- package/dist/types/types/rendered-module.d.ts +0 -2
- package/dist/types/utils/normalize-input-options.d.ts +0 -3
- package/dist/types/utils/normalize-output-options.d.ts +0 -3
- package/dist/types/utils/normalize-tree-shake.d.ts +0 -3
- /package/dist/types/{utils/type-assert.d.ts → types/assert.d.ts} +0 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
const require = __node_module__.createRequire(import.meta.url)
|
|
3
|
-
import { colors, getDefaultExportFromCjs, isUnicodeSupported } from "./consola.36c0034f-Xyw7SC_7.mjs";
|
|
4
|
-
import "node:path";
|
|
1
|
+
import { colors, getDefaultExportFromCjs, isUnicodeSupported } from "./consola_36c0034f-D9ce-831.mjs";
|
|
5
2
|
import { stdin, stdout } from "node:process";
|
|
6
|
-
import "
|
|
7
|
-
import { WriteStream
|
|
8
|
-
import
|
|
3
|
+
import require$$0 from "tty";
|
|
4
|
+
import { WriteStream } from "node:tty";
|
|
5
|
+
import f from "node:readline";
|
|
9
6
|
|
|
10
7
|
//#region ../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/chunks/prompt.mjs
|
|
11
8
|
const ESC = "\x1B";
|
|
@@ -60,9 +57,9 @@ var src = {
|
|
|
60
57
|
erase,
|
|
61
58
|
beep
|
|
62
59
|
};
|
|
63
|
-
var picocolors = {exports: {}};
|
|
60
|
+
var picocolors = { exports: {} };
|
|
64
61
|
let tty = require$$0;
|
|
65
|
-
let isColorSupported = !("NO_COLOR"in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR"in process.env || process.argv.includes("--color") || process.platform === "win32" || tty.isatty(1) && process.env.TERM !== "dumb" || "CI"in process.env);
|
|
62
|
+
let isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
|
|
66
63
|
let formatter = (open, close, replace = open) => (input) => {
|
|
67
64
|
let string = "" + input;
|
|
68
65
|
let index = string.indexOf(close, open.length);
|
|
@@ -255,11 +252,19 @@ function U() {
|
|
|
255
252
|
hexToRgb: {
|
|
256
253
|
value: (u) => {
|
|
257
254
|
const F = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u.toString(16));
|
|
258
|
-
if (!F) return [
|
|
255
|
+
if (!F) return [
|
|
256
|
+
0,
|
|
257
|
+
0,
|
|
258
|
+
0
|
|
259
|
+
];
|
|
259
260
|
let [e] = F;
|
|
260
|
-
e.length === 3 && (e =
|
|
261
|
+
e.length === 3 && (e = [...e].map((C) => C + C).join(""));
|
|
261
262
|
const s$1 = Number.parseInt(e, 16);
|
|
262
|
-
return [
|
|
263
|
+
return [
|
|
264
|
+
s$1 >> 16 & 255,
|
|
265
|
+
s$1 >> 8 & 255,
|
|
266
|
+
s$1 & 255
|
|
267
|
+
];
|
|
263
268
|
},
|
|
264
269
|
enumerable: !1
|
|
265
270
|
},
|
|
@@ -295,12 +300,12 @@ else {
|
|
|
295
300
|
}
|
|
296
301
|
}), r;
|
|
297
302
|
}
|
|
298
|
-
const q = U(), p = new Set(["\x1B", ""]), J = 39, b = "\x07", W = "[", Q = "]", I = "m", w = `${Q}8;;`, N = (t) => `${
|
|
303
|
+
const q = U(), p = new Set(["\x1B", ""]), J = 39, b = "\x07", W = "[", Q = "]", I = "m", w = `${Q}8;;`, N = (t) => `${p.values().next().value}${W}${t}${I}`, j = (t) => `${p.values().next().value}${w}${t}${b}`, X = (t) => t.split(" ").map((u) => c(u)), _ = (t, u, F) => {
|
|
299
304
|
const e = [...u];
|
|
300
305
|
let s$1 = !1, C = !1, D = c($(t[t.length - 1]));
|
|
301
306
|
for (const [i, o] of e.entries()) {
|
|
302
307
|
const E = c(o);
|
|
303
|
-
if (D + E <= F ? t[t.length - 1] += o : (t.push(o), D = 0), p.has(o) && (s$1 = !0, C =
|
|
308
|
+
if (D + E <= F ? t[t.length - 1] += o : (t.push(o), D = 0), p.has(o) && (s$1 = !0, C = e.slice(i + 1).join("").startsWith(w)), s$1) {
|
|
304
309
|
C ? o === b && (s$1 = !1, C = !1) : o === I && (s$1 = !1);
|
|
305
310
|
continue;
|
|
306
311
|
}
|
|
@@ -311,13 +316,13 @@ const q = U(), p = new Set(["\x1B", ""]), J = 39, b = "\x07", W = "[", Q = "]"
|
|
|
311
316
|
const u = t.split(" ");
|
|
312
317
|
let F = u.length;
|
|
313
318
|
for (; F > 0 && !(c(u[F - 1]) > 0);) F--;
|
|
314
|
-
return F === u.length ? t :
|
|
319
|
+
return F === u.length ? t : u.slice(0, F).join(" ") + u.slice(F).join("");
|
|
315
320
|
}, uD = (t, u, F = {}) => {
|
|
316
321
|
if (F.trim !== !1 && t.trim() === "") return "";
|
|
317
322
|
let e = "", s$1, C;
|
|
318
323
|
const D = X(t);
|
|
319
324
|
let i = [""];
|
|
320
|
-
for (const [E, a] of
|
|
325
|
+
for (const [E, a] of t.split(" ").entries()) {
|
|
321
326
|
F.trim !== !1 && (i[i.length - 1] = i[i.length - 1].trimStart());
|
|
322
327
|
let n = c(i[i.length - 1]);
|
|
323
328
|
if (E !== 0 && (n >= u && (F.wordWrap === !1 || F.trim === !1) && (i.push(""), n = 0), (n > 0 || F.trim === !1) && (i[i.length - 1] += " ", n++)), F.hard && D[E] > u) {
|
|
@@ -343,7 +348,7 @@ const q = U(), p = new Set(["\x1B", ""]), J = 39, b = "\x07", W = "[", Q = "]"
|
|
|
343
348
|
`)];
|
|
344
349
|
for (const [E, a] of o.entries()) {
|
|
345
350
|
if (e += a, p.has(a)) {
|
|
346
|
-
const { groups: B } =
|
|
351
|
+
const { groups: B } = new RegExp(`(?:\\${W}(?<code>\\d+)m|\\${w}(?<uri>.*)${b})`).exec(o.slice(E).join("")) || { groups: {} };
|
|
347
352
|
if (B.code !== void 0) {
|
|
348
353
|
const A = Number.parseFloat(B.code);
|
|
349
354
|
s$1 = A === J ? void 0 : A;
|
|
@@ -357,9 +362,9 @@ const q = U(), p = new Set(["\x1B", ""]), J = 39, b = "\x07", W = "[", Q = "]"
|
|
|
357
362
|
return e;
|
|
358
363
|
};
|
|
359
364
|
function P(t, u, F) {
|
|
360
|
-
return
|
|
361
|
-
`)
|
|
362
|
-
`)
|
|
365
|
+
return String(t).normalize().replace(/\r\n/g, `
|
|
366
|
+
`).split(`
|
|
367
|
+
`).map((e) => uD(e, u, F)).join(`
|
|
363
368
|
`);
|
|
364
369
|
}
|
|
365
370
|
function FD(t, u) {
|
|
@@ -374,8 +379,20 @@ const R = Symbol("clack:cancel");
|
|
|
374
379
|
function g(t, u) {
|
|
375
380
|
t.isTTY && t.setRawMode(u);
|
|
376
381
|
}
|
|
377
|
-
const V = new Map([
|
|
378
|
-
|
|
382
|
+
const V = new Map([
|
|
383
|
+
["k", "up"],
|
|
384
|
+
["j", "down"],
|
|
385
|
+
["h", "left"],
|
|
386
|
+
["l", "right"]
|
|
387
|
+
]), tD = new Set([
|
|
388
|
+
"up",
|
|
389
|
+
"down",
|
|
390
|
+
"left",
|
|
391
|
+
"right",
|
|
392
|
+
"space",
|
|
393
|
+
"enter"
|
|
394
|
+
]);
|
|
395
|
+
var h = class {
|
|
379
396
|
constructor({ render: u, input: F = stdin, output: e = stdout,...s$1 }, C = !0) {
|
|
380
397
|
this._track = !1, this._cursor = 0, this.state = "initial", this.error = "", this.subscribers = new Map(), this._prevFrame = "", this.opts = s$1, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = u.bind(this), this._track = C, this.input = F, this.output = e;
|
|
381
398
|
}
|
|
@@ -399,7 +416,7 @@ class h {
|
|
|
399
416
|
}
|
|
400
417
|
on(u, F) {
|
|
401
418
|
const e = this.subscribers.get(u) ?? [];
|
|
402
|
-
e.push({cb: F}), this.subscribers.set(u, e);
|
|
419
|
+
e.push({ cb: F }), this.subscribers.set(u, e);
|
|
403
420
|
}
|
|
404
421
|
once(u, F) {
|
|
405
422
|
const e = this.subscribers.get(u) ?? [];
|
|
@@ -431,12 +448,12 @@ class h {
|
|
|
431
448
|
`), g(this.input, !1), this.rl.close(), this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
432
449
|
}
|
|
433
450
|
restoreCursor() {
|
|
434
|
-
const u =
|
|
435
|
-
`)
|
|
451
|
+
const u = P(this._prevFrame, process.stdout.columns, { hard: !0 }).split(`
|
|
452
|
+
`).length - 1;
|
|
436
453
|
this.output.write(src.cursor.move(-999, u * -1));
|
|
437
454
|
}
|
|
438
455
|
render() {
|
|
439
|
-
const u = P(this._render(this) ?? "", process.stdout.columns, {hard: !0});
|
|
456
|
+
const u = P(this._render(this) ?? "", process.stdout.columns, { hard: !0 });
|
|
440
457
|
if (u !== this._prevFrame) {
|
|
441
458
|
if (this.state === "initial") this.output.write(src.cursor.hide);
|
|
442
459
|
else {
|
|
@@ -451,8 +468,8 @@ else {
|
|
|
451
468
|
} else if (F && F?.length > 1) {
|
|
452
469
|
const e = F[0];
|
|
453
470
|
this.output.write(src.cursor.move(0, e)), this.output.write(src.erase.down());
|
|
454
|
-
const C =
|
|
455
|
-
`)
|
|
471
|
+
const C = u.split(`
|
|
472
|
+
`).slice(e);
|
|
456
473
|
this.output.write(C.join(`
|
|
457
474
|
`)), this._prevFrame = u;
|
|
458
475
|
return;
|
|
@@ -462,8 +479,8 @@ else {
|
|
|
462
479
|
this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u;
|
|
463
480
|
}
|
|
464
481
|
}
|
|
465
|
-
}
|
|
466
|
-
|
|
482
|
+
};
|
|
483
|
+
var sD = class extends h {
|
|
467
484
|
get cursor() {
|
|
468
485
|
return this.value ? 0 : 1;
|
|
469
486
|
}
|
|
@@ -479,8 +496,8 @@ class sD extends h {
|
|
|
479
496
|
this.value = !this.value;
|
|
480
497
|
});
|
|
481
498
|
}
|
|
482
|
-
}
|
|
483
|
-
|
|
499
|
+
};
|
|
500
|
+
var iD = class extends h {
|
|
484
501
|
constructor(u) {
|
|
485
502
|
super(u, !1), this.cursor = 0, this.options = u.options, this.value = [...u.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: F }) => F === u.cursorAt), 0), this.on("key", (F) => {
|
|
486
503
|
F === "a" && this.toggleAll();
|
|
@@ -511,8 +528,8 @@ class iD extends h {
|
|
|
511
528
|
const u = this.value.includes(this._value);
|
|
512
529
|
this.value = u ? this.value.filter((F) => F !== this._value) : [...this.value, this._value];
|
|
513
530
|
}
|
|
514
|
-
}
|
|
515
|
-
|
|
531
|
+
};
|
|
532
|
+
var ED = class extends h {
|
|
516
533
|
constructor(u) {
|
|
517
534
|
super(u, !1), this.cursor = 0, this.options = u.options, this.cursor = this.options.findIndex(({ value: F }) => F === u.initialValue), this.cursor === -1 && (this.cursor = 0), this.changeValue(), this.on("cursor", (F) => {
|
|
518
535
|
switch (F) {
|
|
@@ -534,8 +551,8 @@ class ED extends h {
|
|
|
534
551
|
changeValue() {
|
|
535
552
|
this.value = this._value.value;
|
|
536
553
|
}
|
|
537
|
-
}
|
|
538
|
-
|
|
554
|
+
};
|
|
555
|
+
var oD = class extends h {
|
|
539
556
|
constructor(u) {
|
|
540
557
|
super(u), this.valueWithCursor = "", this.on("finalize", () => {
|
|
541
558
|
this.value || (this.value = u.defaultValue), this.valueWithCursor = this.value;
|
|
@@ -550,7 +567,7 @@ else {
|
|
|
550
567
|
get cursor() {
|
|
551
568
|
return this._cursor;
|
|
552
569
|
}
|
|
553
|
-
}
|
|
570
|
+
};
|
|
554
571
|
const unicode = isUnicodeSupported();
|
|
555
572
|
const s = (c$1, fallback) => unicode ? c$1 : fallback;
|
|
556
573
|
const S_STEP_ACTIVE = s("❯", ">");
|
|
@@ -567,22 +584,14 @@ const S_CHECKBOX_INACTIVE = s("◻", "[ ]");
|
|
|
567
584
|
const symbol = (state) => {
|
|
568
585
|
switch (state) {
|
|
569
586
|
case "initial":
|
|
570
|
-
case "active":
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
case "
|
|
574
|
-
return colors.red(S_STEP_CANCEL);
|
|
575
|
-
}
|
|
576
|
-
case "error": {
|
|
577
|
-
return colors.yellow(S_STEP_ERROR);
|
|
578
|
-
}
|
|
579
|
-
case "submit": {
|
|
580
|
-
return colors.green(S_STEP_SUBMIT);
|
|
581
|
-
}
|
|
587
|
+
case "active": return colors.cyan(S_STEP_ACTIVE);
|
|
588
|
+
case "cancel": return colors.red(S_STEP_CANCEL);
|
|
589
|
+
case "error": return colors.yellow(S_STEP_ERROR);
|
|
590
|
+
case "submit": return colors.green(S_STEP_SUBMIT);
|
|
582
591
|
}
|
|
583
592
|
};
|
|
584
593
|
const text = (opts) => {
|
|
585
|
-
return
|
|
594
|
+
return new oD({
|
|
586
595
|
validate: opts.validate,
|
|
587
596
|
placeholder: opts.placeholder,
|
|
588
597
|
defaultValue: opts.defaultValue,
|
|
@@ -594,31 +603,23 @@ ${symbol(this.state)} ${opts.message}
|
|
|
594
603
|
const placeholder = opts.placeholder ? colors.inverse(opts.placeholder[0]) + colors.dim(opts.placeholder.slice(1)) : colors.inverse(colors.hidden("_"));
|
|
595
604
|
const value = this.value ? this.valueWithCursor : placeholder;
|
|
596
605
|
switch (this.state) {
|
|
597
|
-
case "error": {
|
|
598
|
-
return `${title.trim()}
|
|
606
|
+
case "error": return `${title.trim()}
|
|
599
607
|
${colors.yellow(S_BAR)} ${value}
|
|
600
608
|
${colors.yellow(S_BAR_END)} ${colors.yellow(this.error)}
|
|
601
609
|
`;
|
|
602
|
-
}
|
|
603
|
-
case "
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
case "cancel": {
|
|
607
|
-
return `${title}${colors.gray(S_BAR)} ${colors.strikethrough(colors.dim(this.value ?? ""))}${this.value?.trim() ? "\n" + colors.gray(S_BAR) : ""}`;
|
|
608
|
-
}
|
|
609
|
-
default: {
|
|
610
|
-
return `${title}${colors.cyan(S_BAR)} ${value}
|
|
610
|
+
case "submit": return `${title}${colors.gray(S_BAR)} ${colors.dim(this.value || opts.placeholder)}`;
|
|
611
|
+
case "cancel": return `${title}${colors.gray(S_BAR)} ${colors.strikethrough(colors.dim(this.value ?? ""))}${this.value?.trim() ? "\n" + colors.gray(S_BAR) : ""}`;
|
|
612
|
+
default: return `${title}${colors.cyan(S_BAR)} ${value}
|
|
611
613
|
${colors.cyan(S_BAR_END)}
|
|
612
614
|
`;
|
|
613
|
-
}
|
|
614
615
|
}
|
|
615
616
|
}
|
|
616
|
-
})
|
|
617
|
+
}).prompt();
|
|
617
618
|
};
|
|
618
619
|
const confirm = (opts) => {
|
|
619
620
|
const active = opts.active ?? "Yes";
|
|
620
621
|
const inactive = opts.inactive ?? "No";
|
|
621
|
-
return
|
|
622
|
+
return new sD({
|
|
622
623
|
active,
|
|
623
624
|
inactive,
|
|
624
625
|
initialValue: opts.initialValue ?? true,
|
|
@@ -628,39 +629,27 @@ ${symbol(this.state)} ${opts.message}
|
|
|
628
629
|
`;
|
|
629
630
|
const value = this.value ? active : inactive;
|
|
630
631
|
switch (this.state) {
|
|
631
|
-
case "submit": {
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
case "cancel": {
|
|
635
|
-
return `${title}${colors.gray(S_BAR)} ${colors.strikethrough(colors.dim(value))}
|
|
632
|
+
case "submit": return `${title}${colors.gray(S_BAR)} ${colors.dim(value)}`;
|
|
633
|
+
case "cancel": return `${title}${colors.gray(S_BAR)} ${colors.strikethrough(colors.dim(value))}
|
|
636
634
|
${colors.gray(S_BAR)}`;
|
|
637
|
-
}
|
|
638
|
-
default: {
|
|
639
|
-
return `${title}${colors.cyan(S_BAR)} ${this.value ? `${colors.green(S_RADIO_ACTIVE)} ${active}` : `${colors.dim(S_RADIO_INACTIVE)} ${colors.dim(active)}`} ${colors.dim("/")} ${this.value ? `${colors.dim(S_RADIO_INACTIVE)} ${colors.dim(inactive)}` : `${colors.green(S_RADIO_ACTIVE)} ${inactive}`}
|
|
635
|
+
default: return `${title}${colors.cyan(S_BAR)} ${this.value ? `${colors.green(S_RADIO_ACTIVE)} ${active}` : `${colors.dim(S_RADIO_INACTIVE)} ${colors.dim(active)}`} ${colors.dim("/")} ${this.value ? `${colors.dim(S_RADIO_INACTIVE)} ${colors.dim(inactive)}` : `${colors.green(S_RADIO_ACTIVE)} ${inactive}`}
|
|
640
636
|
${colors.cyan(S_BAR_END)}
|
|
641
637
|
`;
|
|
642
|
-
}
|
|
643
638
|
}
|
|
644
639
|
}
|
|
645
|
-
})
|
|
640
|
+
}).prompt();
|
|
646
641
|
};
|
|
647
642
|
const select = (opts) => {
|
|
648
643
|
const opt = (option, state) => {
|
|
649
644
|
const label = option.label ?? String(option.value);
|
|
650
645
|
switch (state) {
|
|
651
|
-
case "active": {
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
case "selected": {
|
|
655
|
-
return `${colors.dim(label)}`;
|
|
656
|
-
}
|
|
657
|
-
case "cancelled": {
|
|
658
|
-
return `${colors.strikethrough(colors.dim(label))}`;
|
|
659
|
-
}
|
|
646
|
+
case "active": return `${colors.green(S_RADIO_ACTIVE)} ${label} ${option.hint ? colors.dim(`(${option.hint})`) : ""}`;
|
|
647
|
+
case "selected": return `${colors.dim(label)}`;
|
|
648
|
+
case "cancelled": return `${colors.strikethrough(colors.dim(label))}`;
|
|
660
649
|
}
|
|
661
650
|
return `${colors.dim(S_RADIO_INACTIVE)} ${colors.dim(label)}`;
|
|
662
651
|
};
|
|
663
|
-
return
|
|
652
|
+
return new ED({
|
|
664
653
|
options: opts.options,
|
|
665
654
|
initialValue: opts.initialValue,
|
|
666
655
|
render() {
|
|
@@ -668,140 +657,102 @@ const select = (opts) => {
|
|
|
668
657
|
${symbol(this.state)} ${opts.message}
|
|
669
658
|
`;
|
|
670
659
|
switch (this.state) {
|
|
671
|
-
case "submit": {
|
|
672
|
-
|
|
673
|
-
}
|
|
674
|
-
case "cancel": {
|
|
675
|
-
return `${title}${colors.gray(S_BAR)} ${opt(this.options[this.cursor], "cancelled")}
|
|
660
|
+
case "submit": return `${title}${colors.gray(S_BAR)} ${opt(this.options[this.cursor], "selected")}`;
|
|
661
|
+
case "cancel": return `${title}${colors.gray(S_BAR)} ${opt(this.options[this.cursor], "cancelled")}
|
|
676
662
|
${colors.gray(S_BAR)}`;
|
|
677
|
-
}
|
|
678
|
-
default: {
|
|
679
|
-
return `${title}${colors.cyan(S_BAR)} ${(this.options.map((option, i) => opt(option, i === this.cursor ? "active" : "inactive"))).join(`
|
|
663
|
+
default: return `${title}${colors.cyan(S_BAR)} ${this.options.map((option, i) => opt(option, i === this.cursor ? "active" : "inactive")).join(`
|
|
680
664
|
${colors.cyan(S_BAR)} `)}
|
|
681
665
|
${colors.cyan(S_BAR_END)}
|
|
682
666
|
`;
|
|
683
|
-
}
|
|
684
667
|
}
|
|
685
668
|
}
|
|
686
|
-
})
|
|
669
|
+
}).prompt();
|
|
687
670
|
};
|
|
688
671
|
const multiselect = (opts) => {
|
|
689
672
|
const opt = (option, state) => {
|
|
690
673
|
const label = option.label ?? String(option.value);
|
|
691
674
|
switch (state) {
|
|
692
|
-
case "active": {
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
case "selected": {
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
case "cancelled": {
|
|
699
|
-
return `${colors.strikethrough(colors.dim(label))}`;
|
|
700
|
-
}
|
|
701
|
-
case "active-selected": {
|
|
702
|
-
return `${colors.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? colors.dim(`(${option.hint})`) : ""}`;
|
|
703
|
-
}
|
|
704
|
-
case "submitted": {
|
|
705
|
-
return `${colors.dim(label)}`;
|
|
706
|
-
}
|
|
675
|
+
case "active": return `${colors.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? colors.dim(`(${option.hint})`) : ""}`;
|
|
676
|
+
case "selected": return `${colors.green(S_CHECKBOX_SELECTED)} ${colors.dim(label)}`;
|
|
677
|
+
case "cancelled": return `${colors.strikethrough(colors.dim(label))}`;
|
|
678
|
+
case "active-selected": return `${colors.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? colors.dim(`(${option.hint})`) : ""}`;
|
|
679
|
+
case "submitted": return `${colors.dim(label)}`;
|
|
707
680
|
}
|
|
708
681
|
return `${colors.dim(S_CHECKBOX_INACTIVE)} ${colors.dim(label)}`;
|
|
709
682
|
};
|
|
710
|
-
return
|
|
683
|
+
return new iD({
|
|
711
684
|
options: opts.options,
|
|
712
685
|
initialValues: opts.initialValues,
|
|
713
686
|
required: opts.required ?? true,
|
|
714
687
|
cursorAt: opts.cursorAt,
|
|
715
688
|
validate(selected) {
|
|
716
|
-
if (this.required && selected.length === 0)
|
|
717
|
-
return `Please select at least one option.
|
|
689
|
+
if (this.required && selected.length === 0) return `Please select at least one option.
|
|
718
690
|
${colors.reset(colors.dim(`Press ${colors.gray(colors.bgWhite(colors.inverse(" space ")))} to select, ${colors.gray(colors.bgWhite(colors.inverse(" enter ")))} to submit`))}`;
|
|
719
|
-
}
|
|
720
691
|
},
|
|
721
692
|
render() {
|
|
722
693
|
const title = `${colors.gray(S_BAR)}
|
|
723
694
|
${symbol(this.state)} ${opts.message}
|
|
724
695
|
`;
|
|
725
696
|
switch (this.state) {
|
|
726
|
-
case "submit": {
|
|
727
|
-
return `${title}${colors.gray(S_BAR)} ${((this.options.filter(({ value: value }) => this.value.includes(value))).map((option) => opt(option, "submitted"))).join(colors.dim(", ")) || colors.dim("none")}`;
|
|
728
|
-
}
|
|
697
|
+
case "submit": return `${title}${colors.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(colors.dim(", ")) || colors.dim("none")}`;
|
|
729
698
|
case "cancel": {
|
|
730
|
-
const label =
|
|
699
|
+
const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(colors.dim(", "));
|
|
731
700
|
return `${title}${colors.gray(S_BAR)} ${label.trim() ? `${label}
|
|
732
701
|
${colors.gray(S_BAR)}` : ""}`;
|
|
733
702
|
}
|
|
734
703
|
case "error": {
|
|
735
|
-
const footer =
|
|
736
|
-
return title + colors.yellow(S_BAR) + " " +
|
|
704
|
+
const footer = this.error.split("\n").map((ln, i) => i === 0 ? `${colors.yellow(S_BAR_END)} ${colors.yellow(ln)}` : ` ${ln}`).join("\n");
|
|
705
|
+
return title + colors.yellow(S_BAR) + " " + this.options.map((option, i) => {
|
|
737
706
|
const selected = this.value.includes(option.value);
|
|
738
707
|
const active = i === this.cursor;
|
|
739
|
-
if (active && selected)
|
|
740
|
-
|
|
741
|
-
}
|
|
742
|
-
if (selected) {
|
|
743
|
-
return opt(option, "selected");
|
|
744
|
-
}
|
|
708
|
+
if (active && selected) return opt(option, "active-selected");
|
|
709
|
+
if (selected) return opt(option, "selected");
|
|
745
710
|
return opt(option, active ? "active" : "inactive");
|
|
746
|
-
})
|
|
711
|
+
}).join(`
|
|
747
712
|
${colors.yellow(S_BAR)} `) + "\n" + footer + "\n";
|
|
748
713
|
}
|
|
749
|
-
default: {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
if (selected) {
|
|
757
|
-
return opt(option, "selected");
|
|
758
|
-
}
|
|
759
|
-
return opt(option, active ? "active" : "inactive");
|
|
760
|
-
})).join(`
|
|
714
|
+
default: return `${title}${colors.cyan(S_BAR)} ${this.options.map((option, i) => {
|
|
715
|
+
const selected = this.value.includes(option.value);
|
|
716
|
+
const active = i === this.cursor;
|
|
717
|
+
if (active && selected) return opt(option, "active-selected");
|
|
718
|
+
if (selected) return opt(option, "selected");
|
|
719
|
+
return opt(option, active ? "active" : "inactive");
|
|
720
|
+
}).join(`
|
|
761
721
|
${colors.cyan(S_BAR)} `)}
|
|
762
722
|
${colors.cyan(S_BAR_END)}
|
|
763
723
|
`;
|
|
764
|
-
}
|
|
765
724
|
}
|
|
766
725
|
}
|
|
767
|
-
})
|
|
726
|
+
}).prompt();
|
|
768
727
|
};
|
|
769
728
|
async function prompt(message, opts = {}) {
|
|
770
|
-
if (!opts.type || opts.type === "text") {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
message,
|
|
796
|
-
options: opts.options.map((o) => typeof o === "string" ? {
|
|
797
|
-
value: o,
|
|
798
|
-
label: o
|
|
799
|
-
} : o),
|
|
800
|
-
required: opts.required
|
|
801
|
-
});
|
|
802
|
-
}
|
|
729
|
+
if (!opts.type || opts.type === "text") return await text({
|
|
730
|
+
message,
|
|
731
|
+
defaultValue: opts.default,
|
|
732
|
+
placeholder: opts.placeholder,
|
|
733
|
+
initialValue: opts.initial
|
|
734
|
+
});
|
|
735
|
+
if (opts.type === "confirm") return await confirm({
|
|
736
|
+
message,
|
|
737
|
+
initialValue: opts.initial
|
|
738
|
+
});
|
|
739
|
+
if (opts.type === "select") return await select({
|
|
740
|
+
message,
|
|
741
|
+
options: opts.options.map((o) => typeof o === "string" ? {
|
|
742
|
+
value: o,
|
|
743
|
+
label: o
|
|
744
|
+
} : o)
|
|
745
|
+
});
|
|
746
|
+
if (opts.type === "multiselect") return await multiselect({
|
|
747
|
+
message,
|
|
748
|
+
options: opts.options.map((o) => typeof o === "string" ? {
|
|
749
|
+
value: o,
|
|
750
|
+
label: o
|
|
751
|
+
} : o),
|
|
752
|
+
required: opts.required
|
|
753
|
+
});
|
|
803
754
|
throw new Error(`Unknown prompt type: ${opts.type}`);
|
|
804
755
|
}
|
|
805
756
|
|
|
806
757
|
//#endregion
|
|
807
|
-
export { prompt };
|
|
758
|
+
export { prompt };
|