vite-plus 0.2.1 → 0.2.2
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/bin/oxfmt +6 -3
- package/bin/oxlint +6 -3
- package/bin/vpr +9 -0
- package/binding/index.cjs +53 -53
- package/binding/index.d.cts +86 -144
- package/dist/agent-D7O7mSeO.js +9456 -0
- package/dist/bin.js +10 -7
- package/dist/{cli-truncate-CWsmbK3p.js → cli-truncate-BVOlIIPy.js} +1 -1
- package/dist/config/bin.js +2 -2
- package/dist/{constants-CrfJQIUX.js → constants-NeTOxrzV.js} +7 -3
- package/dist/create/bin.js +22 -60
- package/dist/{define-config-2tfJoXr1.d.ts → define-config-BuMs_LKa.d.ts} +64 -9
- package/dist/{define-config-DJUehepE.js → define-config-CSgy0zML.js} +43 -18
- package/dist/{define-config-BGSjF6Xp.cjs → define-config-CrA3lZhQ.cjs} +61 -22
- package/dist/define-config.cjs +2 -1
- package/dist/define-config.d.ts +2 -2
- package/dist/define-config.js +2 -2
- package/dist/{dist-Oxo16Y0q.js → dist-CKz3vcoG.js} +4 -4
- package/dist/dist-CtM2JRbM.js +3 -0
- package/dist/editor-CPzssglc.js +584 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{json-Dn87fvjk.js → json-DiRs8ceZ.js} +13 -1
- package/dist/{log-update-lyIiuflf.js → log-update-DHZRyJ2m.js} +2 -2
- package/dist/migration/bin.d.ts +1 -10
- package/dist/migration/bin.js +531 -170
- package/dist/migration/compat/worker.d.ts +1 -0
- package/dist/migration/compat/worker.js +35 -0
- package/dist/{oxlint-plugin-config-q8a5PFch.js → oxlint-plugin-config-C2Rqc_WQ.js} +1 -1
- package/dist/oxlint-plugin.js +78 -9
- package/dist/pack-bin.js +1 -1
- package/dist/{package-BHirM1_v.js → package-CU2g7URl.js} +52 -3
- package/dist/protocol-D99W10Qi.js +4 -0
- package/dist/{report-BHSkWqRR.js → report-BS7ULx7A.js} +2 -0
- package/dist/{resolve-vite-config-CmdsfQzS.js → resolve-vite-config-r91rIaPs.js} +14 -10
- package/dist/{rolldown-runtime-DnnnRqeS.js → rolldown-runtime-C7HZzL1F.js} +1 -1
- package/dist/staged/bin.js +23 -19
- package/dist/{tsconfig-BWQPmGKz.js → tsconfig-fvpxgUq2.js} +395 -200
- package/dist/version.js +2 -5
- package/dist/versions.js +5 -5
- package/dist/{wrap-ansi-k7Dn4VtV.js → wrap-ansi-DNjkuBEp.js} +1 -1
- package/dist/wrap-ansi-DUi52C6W.js +2 -0
- package/docs/_data/team.ts +9 -0
- package/docs/config/check.md +35 -0
- package/docs/config/index.md +2 -0
- package/docs/config/run.md +61 -12
- package/docs/guide/automatic-data-tracking.md +145 -0
- package/docs/guide/cache.md +14 -35
- package/docs/guide/check.md +16 -0
- package/docs/guide/ci.md +4 -0
- package/docs/guide/docker.md +175 -0
- package/docs/guide/env.md +12 -0
- package/docs/guide/github-actions-cache.md +165 -0
- package/docs/guide/install.md +12 -2
- package/docs/guide/migrate-rules.md +347 -0
- package/docs/guide/migrate.md +14 -0
- package/docs/guide/pack.md +8 -0
- package/docs/guide/run.md +33 -3
- package/docs/guide/troubleshooting.md +1 -1
- package/docs/guide/upgrade.md +43 -21
- package/docs/package.json +1 -1
- package/package.json +20 -19
- package/dist/agent--cKmgD_n.js +0 -3341
- package/dist/compat-Cql3K40m.js +0 -14
- package/dist/dist-DRJUd9bL.js +0 -3
- package/dist/workspace-D0AVy4fu.js +0 -5830
- package/dist/wrap-ansi-CeQuiQ31.js +0 -2
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { n as __require, r as __toESM, t as __commonJSMin } from "./rolldown-runtime-
|
|
2
|
-
import { l as
|
|
1
|
+
import { n as __require, r as __toESM, t as __commonJSMin } from "./rolldown-runtime-C7HZzL1F.js";
|
|
2
|
+
import { l as VITE_PLUS_VERSION, t as BASEURL_TSCONFIG_FIX_PACKAGE, u as createBaseUrlTsconfigFixArgs } from "./constants-NeTOxrzV.js";
|
|
3
3
|
import { t as accent } from "./terminal-uTv0ZaMr.js";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as writeJsonFile, c as parse, i as readJsonFile, o as applyEdits, s as modify } from "./json-DiRs8ceZ.js";
|
|
5
|
+
import { t as require_dist } from "./dist-CKz3vcoG.js";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { downloadPackageManager } from "../binding/index.js";
|
|
7
8
|
import fs from "node:fs";
|
|
8
9
|
import { stripVTControlCharacters, styleText } from "node:util";
|
|
9
10
|
import process$1, { stdin, stdout } from "node:process";
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
11
|
+
import * as l from "node:readline";
|
|
12
|
+
import l__default from "node:readline";
|
|
12
13
|
import { ReadStream } from "node:tty";
|
|
13
14
|
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
|
|
14
15
|
var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -146,7 +147,8 @@ var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
146
147
|
const ppRaw = pathEnv[i];
|
|
147
148
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
148
149
|
const pCmd = path$3.join(pathPart, cmd);
|
|
149
|
-
|
|
150
|
+
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
151
|
+
resolve(subStep(p, i, 0));
|
|
150
152
|
});
|
|
151
153
|
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
152
154
|
if (ii === pathExt.length) return resolve(step(i + 1));
|
|
@@ -421,6 +423,12 @@ async function runCommandSilently(options) {
|
|
|
421
423
|
return await new Promise((resolve, reject) => {
|
|
422
424
|
const stdout = [];
|
|
423
425
|
const stderr = [];
|
|
426
|
+
let timedOut = false;
|
|
427
|
+
const timer = options.timeoutMs === void 0 ? void 0 : setTimeout(() => {
|
|
428
|
+
timedOut = true;
|
|
429
|
+
child.kill("SIGKILL");
|
|
430
|
+
}, options.timeoutMs);
|
|
431
|
+
timer?.unref();
|
|
424
432
|
child.stdout?.on("data", (data) => {
|
|
425
433
|
stdout.push(data);
|
|
426
434
|
});
|
|
@@ -428,6 +436,11 @@ async function runCommandSilently(options) {
|
|
|
428
436
|
stderr.push(data);
|
|
429
437
|
});
|
|
430
438
|
child.on("close", (code) => {
|
|
439
|
+
clearTimeout(timer);
|
|
440
|
+
if (timedOut) {
|
|
441
|
+
reject(/* @__PURE__ */ new Error(`Command timed out after ${options.timeoutMs}ms: ${options.command}`));
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
431
444
|
resolve({
|
|
432
445
|
exitCode: code ?? 0,
|
|
433
446
|
stdout: Buffer.concat(stdout),
|
|
@@ -435,6 +448,7 @@ async function runCommandSilently(options) {
|
|
|
435
448
|
});
|
|
436
449
|
});
|
|
437
450
|
child.on("error", (err) => {
|
|
451
|
+
clearTimeout(timer);
|
|
438
452
|
reject(err);
|
|
439
453
|
});
|
|
440
454
|
});
|
|
@@ -737,7 +751,7 @@ function wrapAnsi$1(string, columns, options) {
|
|
|
737
751
|
return String(string).normalize().split(CRLF_OR_LF$1).map((line) => exec$1(line, columns, options)).join("\n");
|
|
738
752
|
}
|
|
739
753
|
//#endregion
|
|
740
|
-
//#region ../../node_modules/.pnpm/@clack+core@1.4.
|
|
754
|
+
//#region ../../node_modules/.pnpm/@clack+core@1.4.2/node_modules/@clack/core/dist/index.mjs
|
|
741
755
|
var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
742
756
|
const ESC = "\x1B";
|
|
743
757
|
const CSI = `${ESC}[`;
|
|
@@ -790,13 +804,13 @@ var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
790
804
|
beep
|
|
791
805
|
};
|
|
792
806
|
})))();
|
|
793
|
-
function
|
|
794
|
-
if (!
|
|
795
|
-
const
|
|
796
|
-
return
|
|
807
|
+
function findCursor(s, o, l) {
|
|
808
|
+
if (!l.some((r) => !r.disabled)) return s;
|
|
809
|
+
const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t;
|
|
810
|
+
return l[e].disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e;
|
|
797
811
|
}
|
|
798
|
-
const
|
|
799
|
-
actions: new Set([
|
|
812
|
+
const settings = {
|
|
813
|
+
actions: /* @__PURE__ */ new Set([
|
|
800
814
|
"up",
|
|
801
815
|
"down",
|
|
802
816
|
"left",
|
|
@@ -805,7 +819,7 @@ const h = {
|
|
|
805
819
|
"enter",
|
|
806
820
|
"cancel"
|
|
807
821
|
]),
|
|
808
|
-
aliases: new Map([
|
|
822
|
+
aliases: /* @__PURE__ */ new Map([
|
|
809
823
|
["k", "up"],
|
|
810
824
|
["j", "down"],
|
|
811
825
|
["h", "left"],
|
|
@@ -817,7 +831,7 @@ const h = {
|
|
|
817
831
|
cancel: "Canceled",
|
|
818
832
|
error: "Something went wrong"
|
|
819
833
|
},
|
|
820
|
-
withGuide:
|
|
834
|
+
withGuide: true,
|
|
821
835
|
date: {
|
|
822
836
|
monthNames: [...[
|
|
823
837
|
"January",
|
|
@@ -836,95 +850,96 @@ const h = {
|
|
|
836
850
|
messages: {
|
|
837
851
|
required: "Please enter a valid date",
|
|
838
852
|
invalidMonth: "There are only 12 months in a year",
|
|
839
|
-
invalidDay: (
|
|
840
|
-
afterMin: (
|
|
841
|
-
beforeMax: (
|
|
853
|
+
invalidDay: (n, e) => `There are only ${n} days in ${e}`,
|
|
854
|
+
afterMin: (n) => `Date must be on or after ${n.toISOString().slice(0, 10)}`,
|
|
855
|
+
beforeMax: (n) => `Date must be on or before ${n.toISOString().slice(0, 10)}`
|
|
842
856
|
}
|
|
843
857
|
}
|
|
844
858
|
};
|
|
845
|
-
function
|
|
846
|
-
if (typeof
|
|
847
|
-
for (const s of
|
|
848
|
-
return
|
|
859
|
+
function isActionKey(n, e) {
|
|
860
|
+
if (typeof n == "string") return settings.aliases.get(n) === e;
|
|
861
|
+
for (const s of n) if (s !== void 0 && isActionKey(s, e)) return true;
|
|
862
|
+
return false;
|
|
849
863
|
}
|
|
850
|
-
function
|
|
851
|
-
if (
|
|
852
|
-
const
|
|
853
|
-
`),
|
|
854
|
-
`),
|
|
855
|
-
for (let
|
|
864
|
+
function diffLines(i, s) {
|
|
865
|
+
if (i === s) return;
|
|
866
|
+
const e = i.split(`
|
|
867
|
+
`), t = s.split(`
|
|
868
|
+
`), r = Math.max(e.length, t.length), f = [];
|
|
869
|
+
for (let n = 0; n < r; n++) e[n] !== t[n] && f.push(n);
|
|
856
870
|
return {
|
|
857
|
-
lines:
|
|
858
|
-
numLinesBefore:
|
|
859
|
-
numLinesAfter:
|
|
860
|
-
numLines:
|
|
871
|
+
lines: f,
|
|
872
|
+
numLinesBefore: e.length,
|
|
873
|
+
numLinesAfter: t.length,
|
|
874
|
+
numLines: r
|
|
861
875
|
};
|
|
862
876
|
}
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
|
|
877
|
+
const R = globalThis.process.platform.startsWith("win");
|
|
878
|
+
const CANCEL_SYMBOL = Symbol("clack:cancel");
|
|
879
|
+
function isCancel(e) {
|
|
880
|
+
return e === CANCEL_SYMBOL;
|
|
866
881
|
}
|
|
867
|
-
function
|
|
868
|
-
const
|
|
869
|
-
|
|
882
|
+
function setRawMode(e, r) {
|
|
883
|
+
const o = e;
|
|
884
|
+
o.isTTY && o.setRawMode(r);
|
|
870
885
|
}
|
|
871
|
-
function
|
|
872
|
-
const
|
|
873
|
-
input:
|
|
874
|
-
output:
|
|
886
|
+
function block({ input: e = stdin, output: r = stdout, overwrite: o = true, hideCursor: t = true } = {}) {
|
|
887
|
+
const s = l.createInterface({
|
|
888
|
+
input: e,
|
|
889
|
+
output: r,
|
|
875
890
|
prompt: "",
|
|
876
891
|
tabSize: 1
|
|
877
892
|
});
|
|
878
|
-
|
|
879
|
-
const n = (
|
|
880
|
-
if (
|
|
881
|
-
String(
|
|
882
|
-
|
|
883
|
-
|
|
893
|
+
l.emitKeypressEvents(e, s), e instanceof ReadStream && e.isTTY && e.setRawMode(true);
|
|
894
|
+
const n = (f, { name: a, sequence: p }) => {
|
|
895
|
+
if (isActionKey([
|
|
896
|
+
String(f),
|
|
897
|
+
a,
|
|
898
|
+
p
|
|
884
899
|
], "cancel")) {
|
|
885
|
-
|
|
900
|
+
t && r.write(import_src.cursor.show), process.exit(0);
|
|
886
901
|
return;
|
|
887
902
|
}
|
|
888
|
-
if (!
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
903
|
+
if (!o) return;
|
|
904
|
+
const i = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
|
|
905
|
+
l.moveCursor(r, i, m, () => {
|
|
906
|
+
l.clearLine(r, 1, () => {
|
|
907
|
+
e.once("keypress", n);
|
|
893
908
|
});
|
|
894
909
|
});
|
|
895
910
|
};
|
|
896
|
-
return
|
|
897
|
-
|
|
911
|
+
return t && r.write(import_src.cursor.hide), e.once("keypress", n), () => {
|
|
912
|
+
e.off("keypress", n), t && r.write(import_src.cursor.show), e instanceof ReadStream && e.isTTY && !R && e.setRawMode(false), s.terminal = false, s.close();
|
|
898
913
|
};
|
|
899
914
|
}
|
|
900
|
-
const
|
|
901
|
-
function
|
|
902
|
-
return wrapAnsi$1(
|
|
903
|
-
hard:
|
|
904
|
-
trim:
|
|
915
|
+
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;
|
|
916
|
+
function wrapTextWithPrefix(e, r, o, t = o, s = o, n) {
|
|
917
|
+
return wrapAnsi$1(r, getColumns(e ?? stdout) - o.length, {
|
|
918
|
+
hard: true,
|
|
919
|
+
trim: false
|
|
905
920
|
}).split(`
|
|
906
|
-
`).map((
|
|
907
|
-
const
|
|
908
|
-
return
|
|
921
|
+
`).map((c, i, m) => {
|
|
922
|
+
const d = n ? n(c, i) : c;
|
|
923
|
+
return i === 0 ? `${t}${d}` : i === m.length - 1 ? `${s}${d}` : `${o}${d}`;
|
|
909
924
|
}).join(`
|
|
910
925
|
`);
|
|
911
926
|
}
|
|
912
|
-
function
|
|
913
|
-
if ("~standard" in
|
|
914
|
-
const
|
|
915
|
-
if (
|
|
916
|
-
return
|
|
927
|
+
function runValidation(e, n) {
|
|
928
|
+
if ("~standard" in e) {
|
|
929
|
+
const a = e["~standard"].validate(n);
|
|
930
|
+
if (a instanceof Promise) throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
931
|
+
return a.issues?.at(0)?.message;
|
|
917
932
|
}
|
|
918
|
-
return
|
|
933
|
+
return e(n);
|
|
919
934
|
}
|
|
920
|
-
var
|
|
935
|
+
var V = class {
|
|
921
936
|
input;
|
|
922
937
|
output;
|
|
923
938
|
_abortSignal;
|
|
924
939
|
rl;
|
|
925
940
|
opts;
|
|
926
941
|
_render;
|
|
927
|
-
_track =
|
|
942
|
+
_track = false;
|
|
928
943
|
_prevFrame = "";
|
|
929
944
|
_subscribers = /* @__PURE__ */ new Map();
|
|
930
945
|
_cursor = 0;
|
|
@@ -932,131 +947,153 @@ var m = class {
|
|
|
932
947
|
error = "";
|
|
933
948
|
value;
|
|
934
949
|
userInput = "";
|
|
935
|
-
constructor(t,
|
|
936
|
-
const { input:
|
|
937
|
-
this.opts =
|
|
950
|
+
constructor(t, e = true) {
|
|
951
|
+
const { input: i = stdin, output: n = stdout, render: s, signal: r, ...o } = t;
|
|
952
|
+
this.opts = o, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = s.bind(this), this._track = e, this._abortSignal = r, this.input = i, this.output = n;
|
|
938
953
|
}
|
|
954
|
+
/**
|
|
955
|
+
* Unsubscribe all listeners
|
|
956
|
+
*/
|
|
939
957
|
unsubscribe() {
|
|
940
958
|
this._subscribers.clear();
|
|
941
959
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
960
|
+
/**
|
|
961
|
+
* Set a subscriber with opts
|
|
962
|
+
* @param event - The event name
|
|
963
|
+
*/
|
|
964
|
+
setSubscriber(t, e) {
|
|
965
|
+
const i = this._subscribers.get(t) ?? [];
|
|
966
|
+
i.push(e), this._subscribers.set(t, i);
|
|
945
967
|
}
|
|
946
|
-
|
|
947
|
-
|
|
968
|
+
/**
|
|
969
|
+
* Subscribe to an event
|
|
970
|
+
* @param event - The event name
|
|
971
|
+
* @param cb - The callback
|
|
972
|
+
*/
|
|
973
|
+
on(t, e) {
|
|
974
|
+
this.setSubscriber(t, { cb: e });
|
|
948
975
|
}
|
|
949
|
-
|
|
976
|
+
/**
|
|
977
|
+
* Subscribe to an event once
|
|
978
|
+
* @param event - The event name
|
|
979
|
+
* @param cb - The callback
|
|
980
|
+
*/
|
|
981
|
+
once(t, e) {
|
|
950
982
|
this.setSubscriber(t, {
|
|
951
|
-
cb:
|
|
952
|
-
once:
|
|
983
|
+
cb: e,
|
|
984
|
+
once: true
|
|
953
985
|
});
|
|
954
986
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
987
|
+
/**
|
|
988
|
+
* Emit an event with data
|
|
989
|
+
* @param event - The event name
|
|
990
|
+
* @param data - The data to pass to the callback
|
|
991
|
+
*/
|
|
992
|
+
emit(t, ...e) {
|
|
993
|
+
const i = this._subscribers.get(t) ?? [], n = [];
|
|
994
|
+
for (const s of i) s.cb(...e), s.once && n.push(() => i.splice(i.indexOf(s), 1));
|
|
995
|
+
for (const s of n) s();
|
|
959
996
|
}
|
|
960
997
|
prompt() {
|
|
961
998
|
return new Promise((t) => {
|
|
962
999
|
if (this._abortSignal) {
|
|
963
|
-
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(
|
|
1000
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(CANCEL_SYMBOL);
|
|
964
1001
|
this._abortSignal.addEventListener("abort", () => {
|
|
965
1002
|
this.state = "cancel", this.close();
|
|
966
|
-
}, { once:
|
|
1003
|
+
}, { once: true });
|
|
967
1004
|
}
|
|
968
|
-
this.rl =
|
|
1005
|
+
this.rl = l__default.createInterface({
|
|
969
1006
|
input: this.input,
|
|
970
1007
|
tabSize: 2,
|
|
971
1008
|
prompt: "",
|
|
972
1009
|
escapeCodeTimeout: 50,
|
|
973
|
-
terminal:
|
|
974
|
-
}), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput,
|
|
975
|
-
this.output.write(import_src.cursor.show), this.output.off("resize", this.render),
|
|
1010
|
+
terminal: true
|
|
1011
|
+
}), 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", () => {
|
|
1012
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(this.value);
|
|
976
1013
|
}), this.once("cancel", () => {
|
|
977
|
-
this.output.write(import_src.cursor.show), this.output.off("resize", this.render),
|
|
1014
|
+
this.output.write(import_src.cursor.show), this.output.off("resize", this.render), setRawMode(this.input, false), t(CANCEL_SYMBOL);
|
|
978
1015
|
});
|
|
979
1016
|
});
|
|
980
1017
|
}
|
|
981
|
-
_isActionKey(t,
|
|
1018
|
+
_isActionKey(t, e) {
|
|
982
1019
|
return t === " ";
|
|
983
1020
|
}
|
|
984
|
-
_shouldSubmit(t,
|
|
985
|
-
return
|
|
1021
|
+
_shouldSubmit(t, e) {
|
|
1022
|
+
return true;
|
|
986
1023
|
}
|
|
987
1024
|
_setValue(t) {
|
|
988
1025
|
this.value = t, this.emit("value", this.value);
|
|
989
1026
|
}
|
|
990
|
-
_setUserInput(t,
|
|
991
|
-
this.userInput = t ?? "", this.emit("userInput", this.userInput),
|
|
1027
|
+
_setUserInput(t, e) {
|
|
1028
|
+
this.userInput = t ?? "", this.emit("userInput", this.userInput), e && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
|
|
992
1029
|
}
|
|
993
1030
|
_clearUserInput() {
|
|
994
1031
|
this.rl?.write(null, {
|
|
995
|
-
ctrl:
|
|
1032
|
+
ctrl: true,
|
|
996
1033
|
name: "u"
|
|
997
1034
|
}), this._setUserInput("");
|
|
998
1035
|
}
|
|
999
|
-
onKeypress(t,
|
|
1000
|
-
if (this._track &&
|
|
1001
|
-
ctrl:
|
|
1036
|
+
onKeypress(t, e) {
|
|
1037
|
+
if (this._track && e.name !== "return" && (e.name && this._isActionKey(t, e) && this.rl?.write(null, {
|
|
1038
|
+
ctrl: true,
|
|
1002
1039
|
name: "h"
|
|
1003
|
-
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"),
|
|
1040
|
+
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), e?.name && (!this._track && settings.aliases.has(e.name) && this.emit("cursor", settings.aliases.get(e.name)), settings.actions.has(e.name) && this.emit("cursor", e.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, e), e?.name === "return" && this._shouldSubmit(t, e)) {
|
|
1004
1041
|
if (this.opts.validate) {
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1042
|
+
const i = runValidation(this.opts.validate, this.value);
|
|
1043
|
+
i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
|
|
1007
1044
|
}
|
|
1008
1045
|
this.state !== "error" && (this.state = "submit");
|
|
1009
1046
|
}
|
|
1010
|
-
|
|
1047
|
+
isActionKey([
|
|
1011
1048
|
t,
|
|
1012
|
-
|
|
1013
|
-
|
|
1049
|
+
e?.name,
|
|
1050
|
+
e?.sequence
|
|
1014
1051
|
], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
1015
1052
|
}
|
|
1016
1053
|
close() {
|
|
1017
1054
|
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
1018
|
-
`),
|
|
1055
|
+
`), setRawMode(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
1019
1056
|
}
|
|
1020
1057
|
restoreCursor() {
|
|
1021
1058
|
const t = wrapAnsi$1(this._prevFrame, process.stdout.columns, {
|
|
1022
|
-
hard:
|
|
1023
|
-
trim:
|
|
1059
|
+
hard: true,
|
|
1060
|
+
trim: false
|
|
1024
1061
|
}).split(`
|
|
1025
1062
|
`).length - 1;
|
|
1026
1063
|
this.output.write(import_src.cursor.move(-999, t * -1));
|
|
1027
1064
|
}
|
|
1028
1065
|
render() {
|
|
1029
1066
|
const t = wrapAnsi$1(this._render(this) ?? "", process.stdout.columns, {
|
|
1030
|
-
hard:
|
|
1031
|
-
trim:
|
|
1067
|
+
hard: true,
|
|
1068
|
+
trim: false
|
|
1032
1069
|
});
|
|
1033
1070
|
if (t !== this._prevFrame) {
|
|
1034
1071
|
if (this.state === "initial") this.output.write(import_src.cursor.hide);
|
|
1035
1072
|
else {
|
|
1036
|
-
const
|
|
1037
|
-
if (this.restoreCursor(),
|
|
1038
|
-
const
|
|
1039
|
-
let
|
|
1040
|
-
if (
|
|
1073
|
+
const e = diffLines(this._prevFrame, t), i = getRows(this.output);
|
|
1074
|
+
if (this.restoreCursor(), e) {
|
|
1075
|
+
const n = Math.max(0, e.numLinesAfter - i), s = Math.max(0, e.numLinesBefore - i);
|
|
1076
|
+
let r = e.lines.find((o) => o >= n);
|
|
1077
|
+
if (r === void 0) {
|
|
1041
1078
|
this._prevFrame = t;
|
|
1042
1079
|
return;
|
|
1043
1080
|
}
|
|
1044
|
-
if (
|
|
1045
|
-
this.output.write(import_src.cursor.move(0,
|
|
1046
|
-
const
|
|
1081
|
+
if (e.lines.length === 1) {
|
|
1082
|
+
this.output.write(import_src.cursor.move(0, r - s)), this.output.write(import_src.erase.lines(1));
|
|
1083
|
+
const o = t.split(`
|
|
1047
1084
|
`);
|
|
1048
|
-
this.output.write(
|
|
1085
|
+
this.output.write(o[r]), this._prevFrame = t, this.output.write(import_src.cursor.move(0, o.length - r - 1));
|
|
1049
1086
|
return;
|
|
1050
|
-
} else if (
|
|
1051
|
-
if (
|
|
1087
|
+
} else if (e.lines.length > 1) {
|
|
1088
|
+
if (n < s) r = n;
|
|
1052
1089
|
else {
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1090
|
+
const h = r - s;
|
|
1091
|
+
h > 0 && this.output.write(import_src.cursor.move(0, h));
|
|
1055
1092
|
}
|
|
1056
1093
|
this.output.write(import_src.erase.down());
|
|
1057
|
-
const
|
|
1058
|
-
`).slice(
|
|
1059
|
-
this.output.write(
|
|
1094
|
+
const f = t.split(`
|
|
1095
|
+
`).slice(r);
|
|
1096
|
+
this.output.write(f.join(`
|
|
1060
1097
|
`)), this._prevFrame = t;
|
|
1061
1098
|
return;
|
|
1062
1099
|
}
|
|
@@ -1067,7 +1104,7 @@ var m = class {
|
|
|
1067
1104
|
}
|
|
1068
1105
|
}
|
|
1069
1106
|
};
|
|
1070
|
-
var
|
|
1107
|
+
var r = class extends V {
|
|
1071
1108
|
get cursor() {
|
|
1072
1109
|
return this.value ? 0 : 1;
|
|
1073
1110
|
}
|
|
@@ -1075,53 +1112,53 @@ var Z = class extends m {
|
|
|
1075
1112
|
return this.cursor === 0;
|
|
1076
1113
|
}
|
|
1077
1114
|
constructor(t) {
|
|
1078
|
-
super(t,
|
|
1115
|
+
super(t, false), this.value = !!t.initialValue, this.on("userInput", () => {
|
|
1079
1116
|
this.value = this._value;
|
|
1080
|
-
}), this.on("confirm", (
|
|
1081
|
-
this.output.write(import_src.cursor.move(0, -1)), this.value =
|
|
1117
|
+
}), this.on("confirm", (i) => {
|
|
1118
|
+
this.output.write(import_src.cursor.move(0, -1)), this.value = i, this.state = "submit", this.close();
|
|
1082
1119
|
}), this.on("cursor", () => {
|
|
1083
1120
|
this.value = !this.value;
|
|
1084
1121
|
});
|
|
1085
1122
|
}
|
|
1086
1123
|
};
|
|
1087
|
-
let
|
|
1124
|
+
let a$1 = class a extends V {
|
|
1088
1125
|
options;
|
|
1089
1126
|
cursor = 0;
|
|
1090
1127
|
get _value() {
|
|
1091
1128
|
return this.options[this.cursor].value;
|
|
1092
1129
|
}
|
|
1093
1130
|
get _enabledOptions() {
|
|
1094
|
-
return this.options.filter((
|
|
1131
|
+
return this.options.filter((e) => e.disabled !== true);
|
|
1095
1132
|
}
|
|
1096
1133
|
toggleAll() {
|
|
1097
|
-
const
|
|
1098
|
-
this.value =
|
|
1134
|
+
const e = this._enabledOptions, i = this.value !== void 0 && this.value.length === e.length;
|
|
1135
|
+
this.value = i ? [] : e.map((t) => t.value);
|
|
1099
1136
|
}
|
|
1100
1137
|
toggleInvert() {
|
|
1101
|
-
const
|
|
1102
|
-
if (!
|
|
1103
|
-
const
|
|
1104
|
-
this.value =
|
|
1138
|
+
const e = this.value;
|
|
1139
|
+
if (!e) return;
|
|
1140
|
+
const i = this._enabledOptions.filter((t) => !e.includes(t.value));
|
|
1141
|
+
this.value = i.map((t) => t.value);
|
|
1105
1142
|
}
|
|
1106
1143
|
toggleValue() {
|
|
1107
1144
|
this.value === void 0 && (this.value = []);
|
|
1108
|
-
const
|
|
1109
|
-
this.value =
|
|
1145
|
+
const e = this.value.includes(this._value);
|
|
1146
|
+
this.value = e ? this.value.filter((i) => i !== this._value) : [...this.value, this._value];
|
|
1110
1147
|
}
|
|
1111
|
-
constructor(
|
|
1112
|
-
super(
|
|
1113
|
-
const
|
|
1114
|
-
this.cursor = this.options[
|
|
1115
|
-
|
|
1116
|
-
}), this.on("cursor", (
|
|
1117
|
-
switch (
|
|
1148
|
+
constructor(e) {
|
|
1149
|
+
super(e, false), this.options = e.options, this.value = [...e.initialValues ?? []];
|
|
1150
|
+
const i = Math.max(this.options.findIndex(({ value: t }) => t === e.cursorAt), 0);
|
|
1151
|
+
this.cursor = this.options[i].disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => {
|
|
1152
|
+
l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert();
|
|
1153
|
+
}), this.on("cursor", (t) => {
|
|
1154
|
+
switch (t) {
|
|
1118
1155
|
case "left":
|
|
1119
1156
|
case "up":
|
|
1120
|
-
this.cursor =
|
|
1157
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1121
1158
|
break;
|
|
1122
1159
|
case "down":
|
|
1123
1160
|
case "right":
|
|
1124
|
-
this.cursor =
|
|
1161
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1125
1162
|
break;
|
|
1126
1163
|
case "space":
|
|
1127
1164
|
this.toggleValue();
|
|
@@ -1130,7 +1167,7 @@ let ut = class extends m {
|
|
|
1130
1167
|
});
|
|
1131
1168
|
}
|
|
1132
1169
|
};
|
|
1133
|
-
var
|
|
1170
|
+
var a = class extends V {
|
|
1134
1171
|
options;
|
|
1135
1172
|
cursor = 0;
|
|
1136
1173
|
get _selectedValue() {
|
|
@@ -1140,30 +1177,30 @@ var ht = class extends m {
|
|
|
1140
1177
|
this.value = this._selectedValue.value;
|
|
1141
1178
|
}
|
|
1142
1179
|
constructor(t) {
|
|
1143
|
-
super(t,
|
|
1144
|
-
const
|
|
1145
|
-
this.cursor = this.options[e].disabled ?
|
|
1146
|
-
switch (
|
|
1180
|
+
super(t, false), this.options = t.options;
|
|
1181
|
+
const i = this.options.findIndex(({ value: s }) => s === t.initialValue), e = i === -1 ? 0 : i;
|
|
1182
|
+
this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => {
|
|
1183
|
+
switch (s) {
|
|
1147
1184
|
case "left":
|
|
1148
1185
|
case "up":
|
|
1149
|
-
this.cursor =
|
|
1186
|
+
this.cursor = findCursor(this.cursor, -1, this.options);
|
|
1150
1187
|
break;
|
|
1151
1188
|
case "down":
|
|
1152
1189
|
case "right":
|
|
1153
|
-
this.cursor =
|
|
1190
|
+
this.cursor = findCursor(this.cursor, 1, this.options);
|
|
1154
1191
|
break;
|
|
1155
1192
|
}
|
|
1156
1193
|
this.changeValue();
|
|
1157
1194
|
});
|
|
1158
1195
|
}
|
|
1159
1196
|
};
|
|
1160
|
-
var
|
|
1197
|
+
var n = class extends V {
|
|
1161
1198
|
get userInputWithCursor() {
|
|
1162
1199
|
if (this.state === "submit") return this.userInput;
|
|
1163
1200
|
const t = this.userInput;
|
|
1164
1201
|
if (this.cursor >= t.length) return `${this.userInput}\u2588`;
|
|
1165
|
-
const
|
|
1166
|
-
return `${
|
|
1202
|
+
const e = t.slice(0, this.cursor), [s, ...r] = t.slice(this.cursor);
|
|
1203
|
+
return `${e}${styleText("inverse", s)}${r.join("")}`;
|
|
1167
1204
|
}
|
|
1168
1205
|
get cursor() {
|
|
1169
1206
|
return this._cursor;
|
|
@@ -1172,8 +1209,8 @@ var ct = class extends m {
|
|
|
1172
1209
|
super({
|
|
1173
1210
|
...t,
|
|
1174
1211
|
initialUserInput: t.initialUserInput ?? t.initialValue
|
|
1175
|
-
}), this.on("userInput", (
|
|
1176
|
-
this._setValue(
|
|
1212
|
+
}), this.on("userInput", (e) => {
|
|
1213
|
+
this._setValue(e);
|
|
1177
1214
|
}), this.on("finalize", () => {
|
|
1178
1215
|
this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
|
|
1179
1216
|
});
|
|
@@ -1583,11 +1620,11 @@ const trimLines = (groups, initialLineCount, startIndex, endIndex, maxLines) =>
|
|
|
1583
1620
|
const limitOptions = (params) => {
|
|
1584
1621
|
const { cursor, options, style } = params;
|
|
1585
1622
|
const output = params.output ?? process.stdout;
|
|
1586
|
-
const columns =
|
|
1623
|
+
const columns = getColumns(output);
|
|
1587
1624
|
const columnPadding = params.columnPadding ?? 0;
|
|
1588
1625
|
const rowPadding = params.rowPadding ?? 4;
|
|
1589
1626
|
const maxWidth = columns - columnPadding;
|
|
1590
|
-
const rows =
|
|
1627
|
+
const rows = getRows(output);
|
|
1591
1628
|
const overflowFormat = import_picocolors.default.dim("...");
|
|
1592
1629
|
const paramMaxItems = params.maxItems ?? Number.POSITIVE_INFINITY;
|
|
1593
1630
|
const outputMaxItems = Math.max(rows - rowPadding, 0);
|
|
@@ -1642,7 +1679,7 @@ const limitOptions = (params) => {
|
|
|
1642
1679
|
const confirm = (opts) => {
|
|
1643
1680
|
const active = opts.active ?? "Yes";
|
|
1644
1681
|
const inactive = opts.inactive ?? "No";
|
|
1645
|
-
return new
|
|
1682
|
+
return new r({
|
|
1646
1683
|
active,
|
|
1647
1684
|
inactive,
|
|
1648
1685
|
signal: opts.signal,
|
|
@@ -1752,7 +1789,7 @@ const multiselect = (opts) => {
|
|
|
1752
1789
|
};
|
|
1753
1790
|
const required = opts.required ?? true;
|
|
1754
1791
|
const hint = " " + import_picocolors.default.reset(import_picocolors.default.dim(`Press ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" space ")))} to select, ${import_picocolors.default.gray(import_picocolors.default.bgWhite(import_picocolors.default.inverse(" enter ")))} to submit`));
|
|
1755
|
-
return new
|
|
1792
|
+
return new a$1({
|
|
1756
1793
|
options: opts.options,
|
|
1757
1794
|
signal: opts.signal,
|
|
1758
1795
|
input: opts.input,
|
|
@@ -1769,7 +1806,7 @@ const multiselect = (opts) => {
|
|
|
1769
1806
|
const formatMessageLines = (message) => {
|
|
1770
1807
|
return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
|
|
1771
1808
|
};
|
|
1772
|
-
const wrappedMessage = hasGuide ?
|
|
1809
|
+
const wrappedMessage = hasGuide ? wrapTextWithPrefix(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
|
|
1773
1810
|
const title = `${hasGuide ? `${import_picocolors.default.gray(S_BAR)}\n` : ""}${wrappedMessage}\n`;
|
|
1774
1811
|
const value = this.value ?? [];
|
|
1775
1812
|
const styleOption = (option, active) => {
|
|
@@ -1783,13 +1820,13 @@ const multiselect = (opts) => {
|
|
|
1783
1820
|
case "submit": {
|
|
1784
1821
|
const submitText = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "submitted")).join(import_picocolors.default.dim(", ")) || import_picocolors.default.dim("none");
|
|
1785
1822
|
const submitPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
1786
|
-
return `${title}${
|
|
1823
|
+
return `${title}${wrapTextWithPrefix(opts.output, submitText, submitPrefix)}\n`;
|
|
1787
1824
|
}
|
|
1788
1825
|
case "cancel": {
|
|
1789
1826
|
const label = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "cancelled")).join(import_picocolors.default.dim(", "));
|
|
1790
1827
|
if (label.trim() === "") return hasGuide ? `${title}${import_picocolors.default.gray(S_BAR)}\n` : `${title.trimEnd()}\n`;
|
|
1791
1828
|
const cancelPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
1792
|
-
const wrappedLabel =
|
|
1829
|
+
const wrappedLabel = wrapTextWithPrefix(opts.output, label, cancelPrefix);
|
|
1793
1830
|
return hasGuide ? `${title}${wrappedLabel}\n${import_picocolors.default.gray(S_BAR)}\n` : `${title}${wrappedLabel}\n`;
|
|
1794
1831
|
}
|
|
1795
1832
|
case "error": {
|
|
@@ -1855,14 +1892,14 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1855
1892
|
let _prevMessage;
|
|
1856
1893
|
let _origin = performance.now();
|
|
1857
1894
|
let _elapsedMs = 0;
|
|
1858
|
-
const columns =
|
|
1895
|
+
const columns = getColumns(output);
|
|
1859
1896
|
const styleFn = opts?.styleFrame ?? defaultStyleFn;
|
|
1860
1897
|
const getElapsedMs = () => {
|
|
1861
1898
|
if (!isSpinnerActive) return _elapsedMs;
|
|
1862
1899
|
return _elapsedMs + (performance.now() - _origin);
|
|
1863
1900
|
};
|
|
1864
1901
|
const handleExit = (code) => {
|
|
1865
|
-
const msg = code > 1 ? errorMessage ??
|
|
1902
|
+
const msg = code > 1 ? errorMessage ?? settings.messages.error : cancelMessage ?? settings.messages.cancel;
|
|
1866
1903
|
isCancelled = code === 1;
|
|
1867
1904
|
if (isSpinnerActive) {
|
|
1868
1905
|
_stop(msg, code);
|
|
@@ -1901,14 +1938,14 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1901
1938
|
const hasGuide = opts.withGuide ?? false;
|
|
1902
1939
|
const startLoop = () => {
|
|
1903
1940
|
isSpinnerActive = true;
|
|
1904
|
-
unblock =
|
|
1941
|
+
unblock = block({ output });
|
|
1905
1942
|
_origin = performance.now();
|
|
1906
1943
|
_prevMessage = void 0;
|
|
1907
1944
|
if (hasGuide) output.write(`${import_picocolors.default.gray(S_BAR)}\n`);
|
|
1908
1945
|
let frameIndex = 0;
|
|
1909
1946
|
let indicatorTimer = 0;
|
|
1910
1947
|
registerHooks();
|
|
1911
|
-
|
|
1948
|
+
const renderFrame = () => {
|
|
1912
1949
|
if (isCI$1 && _message === _prevMessage) return;
|
|
1913
1950
|
clearPrevMessage();
|
|
1914
1951
|
_prevMessage = _message;
|
|
@@ -1927,7 +1964,9 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1927
1964
|
output.write(wrapped);
|
|
1928
1965
|
frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0;
|
|
1929
1966
|
indicatorTimer = indicatorTimer < 4 ? indicatorTimer + .125 : 0;
|
|
1930
|
-
}
|
|
1967
|
+
};
|
|
1968
|
+
renderFrame();
|
|
1969
|
+
loop = setInterval(renderFrame, delay);
|
|
1931
1970
|
};
|
|
1932
1971
|
const start = (msg = "") => {
|
|
1933
1972
|
_elapsedMs = 0;
|
|
@@ -2002,7 +2041,7 @@ const select = (opts) => {
|
|
|
2002
2041
|
default: return withMarker(import_picocolors.default.dim(" "), label, (text) => text, hint);
|
|
2003
2042
|
}
|
|
2004
2043
|
};
|
|
2005
|
-
return new
|
|
2044
|
+
return new a({
|
|
2006
2045
|
options: opts.options,
|
|
2007
2046
|
signal: opts.signal,
|
|
2008
2047
|
input: opts.input,
|
|
@@ -2015,16 +2054,16 @@ const select = (opts) => {
|
|
|
2015
2054
|
return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
|
|
2016
2055
|
};
|
|
2017
2056
|
const hasMessage = opts.message.trim().length > 0;
|
|
2018
|
-
const messageLines = !hasMessage ? "" : hasGuide ?
|
|
2057
|
+
const messageLines = !hasMessage ? "" : hasGuide ? wrapTextWithPrefix(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
|
|
2019
2058
|
const title = hasMessage ? `${hasGuide ? `${import_picocolors.default.gray(S_BAR)}\n` : ""}${messageLines}\n` : "";
|
|
2020
2059
|
switch (this.state) {
|
|
2021
2060
|
case "submit": {
|
|
2022
2061
|
const submitPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
2023
|
-
return `${title}${
|
|
2062
|
+
return `${title}${wrapTextWithPrefix(opts.output, opt(this.options[this.cursor], "selected"), submitPrefix)}\n`;
|
|
2024
2063
|
}
|
|
2025
2064
|
case "cancel": {
|
|
2026
2065
|
const cancelPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
2027
|
-
return `${title}${
|
|
2066
|
+
return `${title}${wrapTextWithPrefix(opts.output, opt(this.options[this.cursor], "cancelled"), cancelPrefix)}${hasGuide ? `\n${import_picocolors.default.gray(S_BAR)}` : ""}\n`;
|
|
2028
2067
|
}
|
|
2029
2068
|
default: {
|
|
2030
2069
|
const prefix = hasGuide ? `${import_picocolors.default.blue(S_BAR)} ` : nestedPrefix;
|
|
@@ -2046,7 +2085,7 @@ const select = (opts) => {
|
|
|
2046
2085
|
}).prompt();
|
|
2047
2086
|
};
|
|
2048
2087
|
const text = (opts) => {
|
|
2049
|
-
return new
|
|
2088
|
+
return new n({
|
|
2050
2089
|
validate: opts.validate,
|
|
2051
2090
|
placeholder: opts.placeholder,
|
|
2052
2091
|
defaultValue: opts.defaultValue,
|
|
@@ -2664,7 +2703,11 @@ var require_coerce = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2664
2703
|
}
|
|
2665
2704
|
if (match === null) return null;
|
|
2666
2705
|
const major = match[2];
|
|
2667
|
-
|
|
2706
|
+
const minor = match[3] || "0";
|
|
2707
|
+
const patch = match[4] || "0";
|
|
2708
|
+
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
|
|
2709
|
+
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
2710
|
+
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
2668
2711
|
};
|
|
2669
2712
|
module.exports = coerce;
|
|
2670
2713
|
}));
|
|
@@ -2680,7 +2723,8 @@ var require_truncate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2680
2723
|
return clonedVersion && doTruncation(clonedVersion, truncation);
|
|
2681
2724
|
};
|
|
2682
2725
|
const cloneInputVersion = (version, options) => {
|
|
2683
|
-
|
|
2726
|
+
const versionStringToParse = version instanceof SemVer ? version.version : version;
|
|
2727
|
+
return parse(versionStringToParse, options);
|
|
2684
2728
|
};
|
|
2685
2729
|
const doTruncation = (version, truncation) => {
|
|
2686
2730
|
if (isPrerelease(truncation)) return version.version;
|
|
@@ -3664,7 +3708,7 @@ function pnpmSupportsPositionalApprove(version) {
|
|
|
3664
3708
|
return Number.isNaN(major) || major >= 11;
|
|
3665
3709
|
}
|
|
3666
3710
|
/** Package managers that gate build scripts and expose an approval workflow. */
|
|
3667
|
-
const GATED_BUILD_PACKAGE_MANAGERS = new Set([
|
|
3711
|
+
const GATED_BUILD_PACKAGE_MANAGERS = /* @__PURE__ */ new Set([
|
|
3668
3712
|
PackageManager.pnpm,
|
|
3669
3713
|
PackageManager.bun,
|
|
3670
3714
|
PackageManager.yarn
|
|
@@ -3826,7 +3870,7 @@ async function approveBuilds(options) {
|
|
|
3826
3870
|
initialValues: [],
|
|
3827
3871
|
required: false
|
|
3828
3872
|
});
|
|
3829
|
-
selected =
|
|
3873
|
+
selected = isCancel(answer) ? [] : answer;
|
|
3830
3874
|
} else selected = [];
|
|
3831
3875
|
if (selected.length === 0) {
|
|
3832
3876
|
printApproveBuildsGuidance(targets, packageManager);
|
|
@@ -3844,6 +3888,148 @@ async function approveBuilds(options) {
|
|
|
3844
3888
|
], cwd, selected, interactive, silent);
|
|
3845
3889
|
}
|
|
3846
3890
|
//#endregion
|
|
3891
|
+
//#region src/utils/yaml.ts
|
|
3892
|
+
var import_dist = require_dist();
|
|
3893
|
+
function readYamlFile(file) {
|
|
3894
|
+
return (0, import_dist.parse)(fs.readFileSync(file, "utf-8"));
|
|
3895
|
+
}
|
|
3896
|
+
function editYamlFile(file, callback) {
|
|
3897
|
+
const doc = (0, import_dist.parseDocument)(fs.readFileSync(file, "utf-8"));
|
|
3898
|
+
callback(doc);
|
|
3899
|
+
fs.writeFileSync(file, doc.toString({ singleQuote: true }), "utf-8");
|
|
3900
|
+
}
|
|
3901
|
+
function scalarString(value) {
|
|
3902
|
+
return new import_dist.Scalar(value);
|
|
3903
|
+
}
|
|
3904
|
+
//#endregion
|
|
3905
|
+
//#region src/utils/preview-registry.ts
|
|
3906
|
+
const DEFAULT_BRIDGE_REGISTRY = "https://registry-bridge.viteplus.dev/";
|
|
3907
|
+
const REGISTRY_MARKER = "# vite-plus preview build registry bridge (auto-added by vp)";
|
|
3908
|
+
const BRIDGE_HOST = "registry-bridge.viteplus.dev";
|
|
3909
|
+
/**
|
|
3910
|
+
* Registry bridge that serves pkg.pr.new builds as ordinary `0.0.0-commit.<sha>`
|
|
3911
|
+
* versions (and proxies everything else to npmjs). Only ever used for preview
|
|
3912
|
+
* builds (see {@link isPreviewVitePlusVersion}); real releases never resolve
|
|
3913
|
+
* through it. Overridable via `VP_REGISTRY_BRIDGE` for testing or an alternate
|
|
3914
|
+
* bridge host; read at call time so the override applies per process.
|
|
3915
|
+
*/
|
|
3916
|
+
function bridgeRegistry() {
|
|
3917
|
+
return process.env.VP_REGISTRY_BRIDGE || DEFAULT_BRIDGE_REGISTRY;
|
|
3918
|
+
}
|
|
3919
|
+
/**
|
|
3920
|
+
* A preview / test build is published as `0.0.0-commit.<sha>` (and, generally,
|
|
3921
|
+
* any `0.0.0-<prerelease>`). A real release is never `0.0.0`, so this reliably
|
|
3922
|
+
* flags a build under test with no false positives on real-user migrations.
|
|
3923
|
+
*/
|
|
3924
|
+
function isPreviewVitePlusVersion(version = process.env.VP_VERSION || VITE_PLUS_VERSION) {
|
|
3925
|
+
return version.startsWith("0.0.0-");
|
|
3926
|
+
}
|
|
3927
|
+
/**
|
|
3928
|
+
* Berry reads `.yarnrc.yml` and ignores `.npmrc`, so the registry must be
|
|
3929
|
+
* written to the right file. Detect Berry without an install: a `.yarnrc.yml`
|
|
3930
|
+
* is Berry-only, a Berry lockfile carries a `__metadata:` block, and a
|
|
3931
|
+
* `packageManager: "yarn@>=2"` pin selects Berry up front.
|
|
3932
|
+
*/
|
|
3933
|
+
function isYarnBerryProject(projectRoot) {
|
|
3934
|
+
if (fs.existsSync(path.join(projectRoot, ".yarnrc.yml"))) return true;
|
|
3935
|
+
const yarnLock = path.join(projectRoot, "yarn.lock");
|
|
3936
|
+
if (fs.existsSync(yarnLock)) try {
|
|
3937
|
+
if (fs.readFileSync(yarnLock, "utf8").includes("__metadata:")) return true;
|
|
3938
|
+
} catch {}
|
|
3939
|
+
try {
|
|
3940
|
+
const pkg = readJsonFile(path.join(projectRoot, "package.json"));
|
|
3941
|
+
const pm = typeof pkg.packageManager === "string" ? pkg.packageManager : "";
|
|
3942
|
+
const major = /^yarn@(\d+)/.exec(pm)?.[1];
|
|
3943
|
+
if (major && Number(major) >= 2) return true;
|
|
3944
|
+
} catch {}
|
|
3945
|
+
return false;
|
|
3946
|
+
}
|
|
3947
|
+
function ensureNpmrcRegistry(projectRoot) {
|
|
3948
|
+
const npmrc = path.join(projectRoot, ".npmrc");
|
|
3949
|
+
const bridge = bridgeRegistry();
|
|
3950
|
+
let content = "";
|
|
3951
|
+
if (fs.existsSync(npmrc)) {
|
|
3952
|
+
content = fs.readFileSync(npmrc, "utf8");
|
|
3953
|
+
if (content.includes(REGISTRY_MARKER) || content.includes(bridge)) return;
|
|
3954
|
+
}
|
|
3955
|
+
const prefix = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
3956
|
+
fs.appendFileSync(npmrc, `${prefix}${REGISTRY_MARKER}\nregistry=${bridge}\n`);
|
|
3957
|
+
}
|
|
3958
|
+
const YARN_ORIGINAL_REGISTRY_COMMENT_PREFIX = " vite-plus preview bridge (auto-added by vp); original npmRegistryServer: ";
|
|
3959
|
+
function ensureYarnBerryRegistry(projectRoot) {
|
|
3960
|
+
const yarnrc = path.join(projectRoot, ".yarnrc.yml");
|
|
3961
|
+
if (!fs.existsSync(yarnrc)) fs.writeFileSync(yarnrc, "");
|
|
3962
|
+
editYamlFile(yarnrc, (doc) => {
|
|
3963
|
+
const current = doc.get("npmRegistryServer");
|
|
3964
|
+
if (current === bridgeRegistry()) return;
|
|
3965
|
+
doc.set("npmRegistryServer", bridgeRegistry());
|
|
3966
|
+
const node = doc.get("npmRegistryServer", true);
|
|
3967
|
+
if (node instanceof import_dist.Scalar && typeof current === "string" && !current.includes(BRIDGE_HOST)) node.comment = `${YARN_ORIGINAL_REGISTRY_COMMENT_PREFIX}${current}`;
|
|
3968
|
+
});
|
|
3969
|
+
}
|
|
3970
|
+
function clearNpmrcRegistry(projectRoot) {
|
|
3971
|
+
const npmrc = path.join(projectRoot, ".npmrc");
|
|
3972
|
+
if (!fs.existsSync(npmrc)) return false;
|
|
3973
|
+
const original = fs.readFileSync(npmrc, "utf8");
|
|
3974
|
+
if (!original.includes(REGISTRY_MARKER)) return false;
|
|
3975
|
+
const lines = original.split("\n");
|
|
3976
|
+
const kept = [];
|
|
3977
|
+
for (let i = 0; i < lines.length; i++) {
|
|
3978
|
+
if (lines[i].trim() === REGISTRY_MARKER) {
|
|
3979
|
+
if (lines[i + 1]?.startsWith("registry=")) i++;
|
|
3980
|
+
continue;
|
|
3981
|
+
}
|
|
3982
|
+
kept.push(lines[i]);
|
|
3983
|
+
}
|
|
3984
|
+
const result = kept.join("\n").replace(/\n{2,}$/, "\n");
|
|
3985
|
+
if (result.trim() === "") fs.rmSync(npmrc);
|
|
3986
|
+
else fs.writeFileSync(npmrc, result.endsWith("\n") ? result : `${result}\n`);
|
|
3987
|
+
return true;
|
|
3988
|
+
}
|
|
3989
|
+
function clearYarnBerryRegistry(projectRoot) {
|
|
3990
|
+
const yarnrc = path.join(projectRoot, ".yarnrc.yml");
|
|
3991
|
+
if (!fs.existsSync(yarnrc)) return false;
|
|
3992
|
+
const content = fs.readFileSync(yarnrc, "utf8");
|
|
3993
|
+
if (!content.includes(BRIDGE_HOST) && !content.includes(bridgeRegistry())) return false;
|
|
3994
|
+
let cleared = false;
|
|
3995
|
+
editYamlFile(yarnrc, (doc) => {
|
|
3996
|
+
const current = doc.get("npmRegistryServer");
|
|
3997
|
+
if (typeof current === "string" && (current.includes(BRIDGE_HOST) || current === bridgeRegistry())) {
|
|
3998
|
+
const node = doc.get("npmRegistryServer", true);
|
|
3999
|
+
const original = (node instanceof import_dist.Scalar ? node.comment : void 0)?.split(YARN_ORIGINAL_REGISTRY_COMMENT_PREFIX.trimStart())[1]?.trim();
|
|
4000
|
+
if (original) {
|
|
4001
|
+
doc.set("npmRegistryServer", original);
|
|
4002
|
+
const restored = doc.get("npmRegistryServer", true);
|
|
4003
|
+
if (restored instanceof import_dist.Scalar) restored.comment = void 0;
|
|
4004
|
+
} else doc.delete("npmRegistryServer");
|
|
4005
|
+
cleared = true;
|
|
4006
|
+
}
|
|
4007
|
+
});
|
|
4008
|
+
return cleared;
|
|
4009
|
+
}
|
|
4010
|
+
/**
|
|
4011
|
+
* Reconcile the project's registry config with the running build:
|
|
4012
|
+
*
|
|
4013
|
+
* - Preview / test build: point the project at the registry bridge (`.npmrc`, or
|
|
4014
|
+
* `.yarnrc.yml` for Yarn Berry) so the `0.0.0-commit.<sha>` versions that
|
|
4015
|
+
* migrate/create just pinned resolve during this install and in the project's
|
|
4016
|
+
* own CI.
|
|
4017
|
+
* - Real release: remove any bridge registry a PRIOR preview run left behind, so
|
|
4018
|
+
* real installs resolve from npmjs instead of the test bridge.
|
|
4019
|
+
*
|
|
4020
|
+
* No-op and idempotent in the common case. Returns true when it changed config.
|
|
4021
|
+
*/
|
|
4022
|
+
function reconcilePreviewBridgeRegistry(projectRoot, version = process.env.VP_VERSION || VITE_PLUS_VERSION, packageManager) {
|
|
4023
|
+
if (isPreviewVitePlusVersion(version)) {
|
|
4024
|
+
if (packageManager === PackageManager.yarn ? isYarnBerryProject(projectRoot) : packageManager === void 0 && isYarnBerryProject(projectRoot)) ensureYarnBerryRegistry(projectRoot);
|
|
4025
|
+
else ensureNpmrcRegistry(projectRoot);
|
|
4026
|
+
return true;
|
|
4027
|
+
}
|
|
4028
|
+
const clearedNpmrc = clearNpmrcRegistry(projectRoot);
|
|
4029
|
+
const clearedYarnrc = clearYarnBerryRegistry(projectRoot);
|
|
4030
|
+
return clearedNpmrc || clearedYarnrc;
|
|
4031
|
+
}
|
|
4032
|
+
//#endregion
|
|
3847
4033
|
//#region src/utils/prompts.ts
|
|
3848
4034
|
/**
|
|
3849
4035
|
* pnpm v11 promoted `ERR_PNPM_IGNORED_BUILDS` from a warning to a hard
|
|
@@ -3878,7 +4064,7 @@ async function selectPackageManager(interactive, silent = false) {
|
|
|
3878
4064
|
],
|
|
3879
4065
|
initialValue: PackageManager.pnpm
|
|
3880
4066
|
});
|
|
3881
|
-
if (
|
|
4067
|
+
if (isCancel(selected)) cancelAndExit();
|
|
3882
4068
|
return selected;
|
|
3883
4069
|
} else {
|
|
3884
4070
|
if (!silent) log.info(`Using default package manager: ${accent(PackageManager.pnpm)}`);
|
|
@@ -3896,6 +4082,7 @@ async function downloadPackageManager$1(packageManager, version, interactive, si
|
|
|
3896
4082
|
return downloadResult;
|
|
3897
4083
|
}
|
|
3898
4084
|
async function runViteInstall(cwd, interactive, extraArgs, options) {
|
|
4085
|
+
reconcilePreviewBridgeRegistry(cwd, void 0, options?.packageManager);
|
|
3899
4086
|
if (process.env.VP_SKIP_INSTALL) return {
|
|
3900
4087
|
durationMs: 0,
|
|
3901
4088
|
status: "skipped"
|
|
@@ -3940,10 +4127,10 @@ async function runViteFmt(cwd, interactive, paths, options) {
|
|
|
3940
4127
|
const startTime = Date.now();
|
|
3941
4128
|
spinner.start(`Formatting code...`);
|
|
3942
4129
|
const { exitCode, stderr, stdout } = await runCommandSilently({
|
|
3943
|
-
command: process.env.VP_CLI_BIN ?? "vp",
|
|
4130
|
+
command: options?.command ?? process.env.VP_CLI_BIN ?? "vp",
|
|
3944
4131
|
args: [
|
|
4132
|
+
...options?.commandArgs ?? [],
|
|
3945
4133
|
"fmt",
|
|
3946
|
-
"--write",
|
|
3947
4134
|
...paths ?? []
|
|
3948
4135
|
],
|
|
3949
4136
|
cwd,
|
|
@@ -3960,8 +4147,9 @@ async function runViteFmt(cwd, interactive, paths, options) {
|
|
|
3960
4147
|
spinner.stop(`Format failed`);
|
|
3961
4148
|
log.info(stdout.toString());
|
|
3962
4149
|
log.error(stderr.toString());
|
|
3963
|
-
const
|
|
3964
|
-
|
|
4150
|
+
const joinedPaths = (paths ?? []).join(" ");
|
|
4151
|
+
const hint = joinedPaths.length === 0 ? `You may need to run "vp fmt" manually in ${cwd}` : joinedPaths.length <= 256 ? `You may need to run "vp fmt ${joinedPaths}" manually in ${cwd}` : `You may need to run "vp fmt" manually on the ${paths?.length} changed files in ${cwd}`;
|
|
4152
|
+
log.info(hint);
|
|
3965
4153
|
return {
|
|
3966
4154
|
durationMs: Date.now() - startTime,
|
|
3967
4155
|
exitCode,
|
|
@@ -3997,7 +4185,7 @@ async function promptGitHooks(options) {
|
|
|
3997
4185
|
message: "Set up pre-commit hooks to run formatting, linting, and type checking with auto-fixes?",
|
|
3998
4186
|
initialValue: true
|
|
3999
4187
|
});
|
|
4000
|
-
if (
|
|
4188
|
+
if (isCancel(selected)) {
|
|
4001
4189
|
cancelAndExit();
|
|
4002
4190
|
return false;
|
|
4003
4191
|
}
|
|
@@ -4010,10 +4198,10 @@ async function promptGitInit(options) {
|
|
|
4010
4198
|
if (options.git === true) return true;
|
|
4011
4199
|
if (options.interactive) {
|
|
4012
4200
|
const selected = await confirm({
|
|
4013
|
-
message: "Initialize a git repository
|
|
4201
|
+
message: "Initialize a git repository?",
|
|
4014
4202
|
initialValue: true
|
|
4015
4203
|
});
|
|
4016
|
-
if (
|
|
4204
|
+
if (isCancel(selected)) {
|
|
4017
4205
|
cancelAndExit();
|
|
4018
4206
|
return false;
|
|
4019
4207
|
}
|
|
@@ -4063,7 +4251,7 @@ async function confirmBaseUrlFix(interactive) {
|
|
|
4063
4251
|
message: "Your tsconfig contains `baseUrl`, which prevents enabling type-aware linting.\n " + styleText("gray", "`baseUrl` is deprecated in TypeScript 6.0 and removed in TypeScript 7.0.") + `\n Download and run the external \`${BASEURL_TSCONFIG_FIX_PACKAGE}\` fixer now?\n ` + styleText("gray", `Equivalent command: \`vp dlx ${command}\``),
|
|
4064
4252
|
initialValue: true
|
|
4065
4253
|
});
|
|
4066
|
-
if (
|
|
4254
|
+
if (isCancel(confirmed)) cancelAndExit();
|
|
4067
4255
|
return confirmed;
|
|
4068
4256
|
}
|
|
4069
4257
|
async function fixBaseUrlInTsconfig(projectPath, options) {
|
|
@@ -4123,10 +4311,7 @@ function removeDeprecatedTsconfigFalseOption(filePath, optionName) {
|
|
|
4123
4311
|
fs.writeFileSync(filePath, newText);
|
|
4124
4312
|
return true;
|
|
4125
4313
|
}
|
|
4126
|
-
const TSCONFIG_TYPE_REPLACEMENTS = {
|
|
4127
|
-
"tsdown/client": "vite-plus/pack/client",
|
|
4128
|
-
"vite/client": "vite-plus/client"
|
|
4129
|
-
};
|
|
4314
|
+
const TSCONFIG_TYPE_REPLACEMENTS = { "tsdown/client": "vite-plus/pack/client" };
|
|
4130
4315
|
function hasTypesToRewriteInTsconfig(filePath) {
|
|
4131
4316
|
let text;
|
|
4132
4317
|
try {
|
|
@@ -4137,6 +4322,16 @@ function hasTypesToRewriteInTsconfig(filePath) {
|
|
|
4137
4322
|
const types = parse(text)?.compilerOptions?.types;
|
|
4138
4323
|
return Array.isArray(types) && types.some((t) => typeof t === "string" && t in TSCONFIG_TYPE_REPLACEMENTS);
|
|
4139
4324
|
}
|
|
4325
|
+
function hasVitestTypesInTsconfig(filePath) {
|
|
4326
|
+
let text;
|
|
4327
|
+
try {
|
|
4328
|
+
text = fs.readFileSync(filePath, "utf-8");
|
|
4329
|
+
} catch {
|
|
4330
|
+
return false;
|
|
4331
|
+
}
|
|
4332
|
+
const types = parse(text)?.compilerOptions?.types;
|
|
4333
|
+
return Array.isArray(types) && types.some((type) => typeof type === "string" ? type === "vitest" || type.startsWith("vitest/") : false);
|
|
4334
|
+
}
|
|
4140
4335
|
function rewriteTypesInTsconfig(filePath) {
|
|
4141
4336
|
let text;
|
|
4142
4337
|
try {
|
|
@@ -4165,4 +4360,4 @@ function rewriteTypesInTsconfig(filePath) {
|
|
|
4165
4360
|
return true;
|
|
4166
4361
|
}
|
|
4167
4362
|
//#endregion
|
|
4168
|
-
export {
|
|
4363
|
+
export { intro as A, runCommandSilently as B, resolveApproveBuildTargets as C, require_semver as D, PackageManager as E, spinner as F, text as I, require_picocolors as L, multiselect as M, outro as N, cancel as O, select as P, isCancel as R, detectGatedBuilds as S, DependencyType as T, require_cross_spawn as V, upgradeYarn as _, hasTypesToRewriteInTsconfig as a, scalarString as b, rewriteTypesInTsconfig as c, downloadPackageManager$1 as d, promptGitHooks as f, selectPackageManager as g, runViteInstall as h, hasBaseUrlInTsconfig as i, log as j, confirm as k, cancelAndExit as l, runViteFmt as m, findTsconfigFiles as n, hasVitestTypesInTsconfig as o, resolveGitInit as p, fixBaseUrlInTsconfig as r, removeDeprecatedTsconfigFalseOption as s, confirmBaseUrlFix as t, defaultInteractive as u, editYamlFile as v, getSpinner as w, approveBuilds as x, readYamlFile as y, runCommand$1 as z };
|