vite-plus 0.1.22 → 0.1.24
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/binding/index.cjs +119 -52
- package/binding/index.d.cts +3222 -2
- package/dist/agent-Nuk-9l77.js +2470 -0
- package/dist/bin.js +13 -8
- package/dist/cli-truncate-CWsmbK3p.js +867 -0
- package/dist/{compat-OlmU9EQz.js → compat-DXZgnEyq.js} +1 -1
- package/dist/config/bin.js +18 -5
- package/dist/{constants-kDaYqyWd.js → constants-DCBWlNrn.js} +7 -2
- package/dist/create/bin.d.ts +1 -1
- package/dist/create/bin.js +194 -87
- package/dist/{define-config-IMCGDS2K.d.ts → define-config-COdn-tsn.d.ts} +7 -5
- package/dist/define-config.cjs +1 -1
- package/dist/define-config.d.ts +1 -1
- package/dist/define-config.js +1 -1
- package/dist/dist-Bapm49IR.js +3 -0
- package/dist/{dist-owlRxmBM.js → dist-BgQuvbtq.js} +136 -110
- package/dist/fmt.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/is-fullwidth-code-point-BUNlIICg.js +8 -0
- package/dist/lint.d.ts +1 -1
- package/dist/{log-update-NRrY6krx.js → log-update-lyIiuflf.js} +111 -24
- package/dist/migration/bin.js +81 -39
- package/dist/{oxlint-plugin-config-BkQeR4FR.js → oxlint-plugin-config-B89iKTKN.js} +1 -1
- package/dist/oxlint-plugin.d.ts +2 -4
- package/dist/oxlint-plugin.js +1 -1
- package/dist/pack-bin.js +1 -1
- package/dist/pack.d.ts +1 -1
- package/dist/{package-BoLLED6j.js → package-PmBUZ-ve.js} +2 -2
- package/dist/staged/bin.js +157 -424
- package/dist/strip-ansi-C3wrWz9t.js +853 -0
- package/dist/{agent-BWLe0i9g.js → tsconfig-DFb5BKyT.js} +681 -2114
- package/dist/version.js +5 -5
- package/dist/versions.js +7 -7
- package/dist/{workspace-Bi_9spVt.js → workspace-NL-m9wgM.js} +22 -21
- package/dist/wrap-ansi-CeQuiQ31.js +2 -0
- package/dist/{wrap-ansi-DtUeUCjE.js → wrap-ansi-k7Dn4VtV.js} +1 -1
- package/docs/_data/team.ts +3 -3
- package/docs/config/run.md +39 -4
- package/docs/guide/cache.md +10 -1
- package/docs/guide/env.md +3 -0
- package/docs/guide/ide-integration.md +2 -2
- package/docs/guide/index.md +4 -0
- package/docs/guide/install.md +19 -0
- package/docs/guide/migrate.md +1 -1
- package/docs/guide/run.md +2 -0
- package/docs/guide/troubleshooting.md +6 -29
- package/docs/guide/upgrade.md +12 -1
- package/package.json +20 -20
- package/templates/monorepo/_gitignore +1 -0
- package/dist/cli-truncate-B62YnW2m.js +0 -138
- package/dist/dist-DZfItHAr.js +0 -3
- package/dist/slice-ansi-e4todZeH.js +0 -113
- package/dist/strip-ansi-D-eYYcD2.js +0 -198
- package/dist/tsconfig-BVyzXJ_o.js +0 -517
- package/dist/wrap-ansi-3S3qJ7j8.js +0 -2
- /package/dist/{chunk-q7NCDQ7-.js → chunk-DnnnRqeS.js} +0 -0
- /package/dist/{define-config-GqLoRwH9.cjs → define-config-BR1Y88zz.cjs} +0 -0
- /package/dist/{define-config-CzWdQTt2.js → define-config-BRC7qPNE.js} +0 -0
- /package/dist/{help-DK5wuu34.js → help-YP84FSEz.js} +0 -0
- /package/dist/{lib-DpwyUJWo.js → lib-L3DWSRQp.js} +0 -0
- /package/dist/{main-DhsO6ndq.js → main-DpJl3LoU.js} +0 -0
- /package/dist/{pack-K7H72Cum.d.ts → pack-Ciiho0Tq.d.ts} +0 -0
- /package/dist/{report-CYPv1VK1.js → report-DgSBQUdz.js} +0 -0
- /package/dist/{resolve-vite-config-C5AjksTj.js → resolve-vite-config-TTvhycU1.js} +0 -0
- /package/dist/{terminal-D_Kg-AA6.js → terminal-uTv0ZaMr.js} +0 -0
|
@@ -1,20 +1,460 @@
|
|
|
1
|
-
import { r as __toESM, t as __commonJSMin } from "./chunk-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as accent } from "./terminal-D_Kg-AA6.js";
|
|
6
|
-
import { t as require_dist } from "./dist-owlRxmBM.js";
|
|
7
|
-
import { c as editJsonFile, l as isJsonFile, n as detectPackageMetadata, u as readJsonFile } from "./package-BoLLED6j.js";
|
|
8
|
-
import { n as addMigrationWarning, t as addManualStep } from "./report-CYPv1VK1.js";
|
|
1
|
+
import { n as __require, r as __toESM, t as __commonJSMin } from "./chunk-DnnnRqeS.js";
|
|
2
|
+
import { s as createBaseUrlTsconfigFixArgs, t as BASEURL_TSCONFIG_FIX_PACKAGE } from "./constants-DCBWlNrn.js";
|
|
3
|
+
import { t as accent } from "./terminal-uTv0ZaMr.js";
|
|
4
|
+
import { n as modify, r as parse, t as applyEdits } from "./main-DpJl3LoU.js";
|
|
9
5
|
import path from "node:path";
|
|
10
|
-
import { downloadPackageManager
|
|
6
|
+
import { downloadPackageManager } from "../binding/index.js";
|
|
11
7
|
import fs from "node:fs";
|
|
12
8
|
import { styleText } from "node:util";
|
|
13
9
|
import process$1, { stdin, stdout } from "node:process";
|
|
14
10
|
import * as b from "node:readline";
|
|
15
|
-
import
|
|
11
|
+
import G from "node:readline";
|
|
16
12
|
import { ReadStream } from "node:tty";
|
|
17
|
-
|
|
13
|
+
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
|
|
14
|
+
var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
15
|
+
module.exports = isexe;
|
|
16
|
+
isexe.sync = sync;
|
|
17
|
+
var fs$3 = __require("fs");
|
|
18
|
+
function checkPathExt(path, options) {
|
|
19
|
+
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
|
|
20
|
+
if (!pathext) return true;
|
|
21
|
+
pathext = pathext.split(";");
|
|
22
|
+
if (pathext.indexOf("") !== -1) return true;
|
|
23
|
+
for (var i = 0; i < pathext.length; i++) {
|
|
24
|
+
var p = pathext[i].toLowerCase();
|
|
25
|
+
if (p && path.substr(-p.length).toLowerCase() === p) return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function checkStat(stat, path, options) {
|
|
30
|
+
if (!stat.isSymbolicLink() && !stat.isFile()) return false;
|
|
31
|
+
return checkPathExt(path, options);
|
|
32
|
+
}
|
|
33
|
+
function isexe(path, options, cb) {
|
|
34
|
+
fs$3.stat(path, function(er, stat) {
|
|
35
|
+
cb(er, er ? false : checkStat(stat, path, options));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function sync(path, options) {
|
|
39
|
+
return checkStat(fs$3.statSync(path), path, options);
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js
|
|
44
|
+
var require_mode = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
45
|
+
module.exports = isexe;
|
|
46
|
+
isexe.sync = sync;
|
|
47
|
+
var fs$2 = __require("fs");
|
|
48
|
+
function isexe(path, options, cb) {
|
|
49
|
+
fs$2.stat(path, function(er, stat) {
|
|
50
|
+
cb(er, er ? false : checkStat(stat, options));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function sync(path, options) {
|
|
54
|
+
return checkStat(fs$2.statSync(path), options);
|
|
55
|
+
}
|
|
56
|
+
function checkStat(stat, options) {
|
|
57
|
+
return stat.isFile() && checkMode(stat, options);
|
|
58
|
+
}
|
|
59
|
+
function checkMode(stat, options) {
|
|
60
|
+
var mod = stat.mode;
|
|
61
|
+
var uid = stat.uid;
|
|
62
|
+
var gid = stat.gid;
|
|
63
|
+
var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
|
|
64
|
+
var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
|
|
65
|
+
var u = parseInt("100", 8);
|
|
66
|
+
var g = parseInt("010", 8);
|
|
67
|
+
var o = parseInt("001", 8);
|
|
68
|
+
var ug = u | g;
|
|
69
|
+
return mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
|
|
74
|
+
var require_isexe = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
75
|
+
__require("fs");
|
|
76
|
+
var core;
|
|
77
|
+
if (process.platform === "win32" || global.TESTING_WINDOWS) core = require_windows();
|
|
78
|
+
else core = require_mode();
|
|
79
|
+
module.exports = isexe;
|
|
80
|
+
isexe.sync = sync;
|
|
81
|
+
function isexe(path, options, cb) {
|
|
82
|
+
if (typeof options === "function") {
|
|
83
|
+
cb = options;
|
|
84
|
+
options = {};
|
|
85
|
+
}
|
|
86
|
+
if (!cb) {
|
|
87
|
+
if (typeof Promise !== "function") throw new TypeError("callback not provided");
|
|
88
|
+
return new Promise(function(resolve, reject) {
|
|
89
|
+
isexe(path, options || {}, function(er, is) {
|
|
90
|
+
if (er) reject(er);
|
|
91
|
+
else resolve(is);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
core(path, options || {}, function(er, is) {
|
|
96
|
+
if (er) {
|
|
97
|
+
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
98
|
+
er = null;
|
|
99
|
+
is = false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
cb(er, is);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function sync(path, options) {
|
|
106
|
+
try {
|
|
107
|
+
return core.sync(path, options || {});
|
|
108
|
+
} catch (er) {
|
|
109
|
+
if (options && options.ignoreErrors || er.code === "EACCES") return false;
|
|
110
|
+
else throw er;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
|
|
116
|
+
var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
117
|
+
const isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
118
|
+
const path$3 = __require("path");
|
|
119
|
+
const COLON = isWindows ? ";" : ":";
|
|
120
|
+
const isexe = require_isexe();
|
|
121
|
+
const getNotFoundError = (cmd) => Object.assign(/* @__PURE__ */ new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
122
|
+
const getPathInfo = (cmd, opt) => {
|
|
123
|
+
const colon = opt.colon || COLON;
|
|
124
|
+
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [...isWindows ? [process.cwd()] : [], ...(opt.path || process.env.PATH || "").split(colon)];
|
|
125
|
+
const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
|
|
126
|
+
const pathExt = isWindows ? pathExtExe.split(colon) : [""];
|
|
127
|
+
if (isWindows) {
|
|
128
|
+
if (cmd.indexOf(".") !== -1 && pathExt[0] !== "") pathExt.unshift("");
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
pathEnv,
|
|
132
|
+
pathExt,
|
|
133
|
+
pathExtExe
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
const which = (cmd, opt, cb) => {
|
|
137
|
+
if (typeof opt === "function") {
|
|
138
|
+
cb = opt;
|
|
139
|
+
opt = {};
|
|
140
|
+
}
|
|
141
|
+
if (!opt) opt = {};
|
|
142
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
143
|
+
const found = [];
|
|
144
|
+
const step = (i) => new Promise((resolve, reject) => {
|
|
145
|
+
if (i === pathEnv.length) return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
|
|
146
|
+
const ppRaw = pathEnv[i];
|
|
147
|
+
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
148
|
+
const pCmd = path$3.join(pathPart, cmd);
|
|
149
|
+
resolve(subStep(!pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd, i, 0));
|
|
150
|
+
});
|
|
151
|
+
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
152
|
+
if (ii === pathExt.length) return resolve(step(i + 1));
|
|
153
|
+
const ext = pathExt[ii];
|
|
154
|
+
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
155
|
+
if (!er && is) if (opt.all) found.push(p + ext);
|
|
156
|
+
else return resolve(p + ext);
|
|
157
|
+
return resolve(subStep(p, i, ii + 1));
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
161
|
+
};
|
|
162
|
+
const whichSync = (cmd, opt) => {
|
|
163
|
+
opt = opt || {};
|
|
164
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
165
|
+
const found = [];
|
|
166
|
+
for (let i = 0; i < pathEnv.length; i++) {
|
|
167
|
+
const ppRaw = pathEnv[i];
|
|
168
|
+
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
169
|
+
const pCmd = path$3.join(pathPart, cmd);
|
|
170
|
+
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
171
|
+
for (let j = 0; j < pathExt.length; j++) {
|
|
172
|
+
const cur = p + pathExt[j];
|
|
173
|
+
try {
|
|
174
|
+
if (isexe.sync(cur, { pathExt: pathExtExe })) if (opt.all) found.push(cur);
|
|
175
|
+
else return cur;
|
|
176
|
+
} catch (ex) {}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (opt.all && found.length) return found;
|
|
180
|
+
if (opt.nothrow) return null;
|
|
181
|
+
throw getNotFoundError(cmd);
|
|
182
|
+
};
|
|
183
|
+
module.exports = which;
|
|
184
|
+
which.sync = whichSync;
|
|
185
|
+
}));
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region ../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js
|
|
188
|
+
var require_path_key = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
189
|
+
const pathKey = (options = {}) => {
|
|
190
|
+
const environment = options.env || process.env;
|
|
191
|
+
if ((options.platform || process.platform) !== "win32") return "PATH";
|
|
192
|
+
return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
|
|
193
|
+
};
|
|
194
|
+
module.exports = pathKey;
|
|
195
|
+
module.exports.default = pathKey;
|
|
196
|
+
}));
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
|
|
199
|
+
var require_resolveCommand = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
200
|
+
const path$2 = __require("path");
|
|
201
|
+
const which = require_which();
|
|
202
|
+
const getPathKey = require_path_key();
|
|
203
|
+
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
204
|
+
const env = parsed.options.env || process.env;
|
|
205
|
+
const cwd = process.cwd();
|
|
206
|
+
const hasCustomCwd = parsed.options.cwd != null;
|
|
207
|
+
const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
|
|
208
|
+
if (shouldSwitchCwd) try {
|
|
209
|
+
process.chdir(parsed.options.cwd);
|
|
210
|
+
} catch (err) {}
|
|
211
|
+
let resolved;
|
|
212
|
+
try {
|
|
213
|
+
resolved = which.sync(parsed.command, {
|
|
214
|
+
path: env[getPathKey({ env })],
|
|
215
|
+
pathExt: withoutPathExt ? path$2.delimiter : void 0
|
|
216
|
+
});
|
|
217
|
+
} catch (e) {} finally {
|
|
218
|
+
if (shouldSwitchCwd) process.chdir(cwd);
|
|
219
|
+
}
|
|
220
|
+
if (resolved) resolved = path$2.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
221
|
+
return resolved;
|
|
222
|
+
}
|
|
223
|
+
function resolveCommand(parsed) {
|
|
224
|
+
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
|
|
225
|
+
}
|
|
226
|
+
module.exports = resolveCommand;
|
|
227
|
+
}));
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
|
|
230
|
+
var require_escape = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
231
|
+
const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
|
232
|
+
function escapeCommand(arg) {
|
|
233
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
234
|
+
return arg;
|
|
235
|
+
}
|
|
236
|
+
function escapeArgument(arg, doubleEscapeMetaChars) {
|
|
237
|
+
arg = `${arg}`;
|
|
238
|
+
arg = arg.replace(/(?=(\\+?)?)\1"/g, "$1$1\\\"");
|
|
239
|
+
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
240
|
+
arg = `"${arg}"`;
|
|
241
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
242
|
+
if (doubleEscapeMetaChars) arg = arg.replace(metaCharsRegExp, "^$1");
|
|
243
|
+
return arg;
|
|
244
|
+
}
|
|
245
|
+
module.exports.command = escapeCommand;
|
|
246
|
+
module.exports.argument = escapeArgument;
|
|
247
|
+
}));
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region ../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js
|
|
250
|
+
var require_shebang_regex = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
251
|
+
module.exports = /^#!(.*)/;
|
|
252
|
+
}));
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region ../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js
|
|
255
|
+
var require_shebang_command = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
256
|
+
const shebangRegex = require_shebang_regex();
|
|
257
|
+
module.exports = (string = "") => {
|
|
258
|
+
const match = string.match(shebangRegex);
|
|
259
|
+
if (!match) return null;
|
|
260
|
+
const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
261
|
+
const binary = path.split("/").pop();
|
|
262
|
+
if (binary === "env") return argument;
|
|
263
|
+
return argument ? `${binary} ${argument}` : binary;
|
|
264
|
+
};
|
|
265
|
+
}));
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
|
|
268
|
+
var require_readShebang = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
269
|
+
const fs$1 = __require("fs");
|
|
270
|
+
const shebangCommand = require_shebang_command();
|
|
271
|
+
function readShebang(command) {
|
|
272
|
+
const size = 150;
|
|
273
|
+
const buffer = Buffer.alloc(size);
|
|
274
|
+
let fd;
|
|
275
|
+
try {
|
|
276
|
+
fd = fs$1.openSync(command, "r");
|
|
277
|
+
fs$1.readSync(fd, buffer, 0, size, 0);
|
|
278
|
+
fs$1.closeSync(fd);
|
|
279
|
+
} catch (e) {}
|
|
280
|
+
return shebangCommand(buffer.toString());
|
|
281
|
+
}
|
|
282
|
+
module.exports = readShebang;
|
|
283
|
+
}));
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
|
|
286
|
+
var require_parse$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
287
|
+
const path$1 = __require("path");
|
|
288
|
+
const resolveCommand = require_resolveCommand();
|
|
289
|
+
const escape = require_escape();
|
|
290
|
+
const readShebang = require_readShebang();
|
|
291
|
+
const isWin = process.platform === "win32";
|
|
292
|
+
const isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
293
|
+
const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
294
|
+
function detectShebang(parsed) {
|
|
295
|
+
parsed.file = resolveCommand(parsed);
|
|
296
|
+
const shebang = parsed.file && readShebang(parsed.file);
|
|
297
|
+
if (shebang) {
|
|
298
|
+
parsed.args.unshift(parsed.file);
|
|
299
|
+
parsed.command = shebang;
|
|
300
|
+
return resolveCommand(parsed);
|
|
301
|
+
}
|
|
302
|
+
return parsed.file;
|
|
303
|
+
}
|
|
304
|
+
function parseNonShell(parsed) {
|
|
305
|
+
if (!isWin) return parsed;
|
|
306
|
+
const commandFile = detectShebang(parsed);
|
|
307
|
+
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
308
|
+
if (parsed.options.forceShell || needsShell) {
|
|
309
|
+
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
310
|
+
parsed.command = path$1.normalize(parsed.command);
|
|
311
|
+
parsed.command = escape.command(parsed.command);
|
|
312
|
+
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
313
|
+
parsed.args = [
|
|
314
|
+
"/d",
|
|
315
|
+
"/s",
|
|
316
|
+
"/c",
|
|
317
|
+
`"${[parsed.command].concat(parsed.args).join(" ")}"`
|
|
318
|
+
];
|
|
319
|
+
parsed.command = process.env.comspec || "cmd.exe";
|
|
320
|
+
parsed.options.windowsVerbatimArguments = true;
|
|
321
|
+
}
|
|
322
|
+
return parsed;
|
|
323
|
+
}
|
|
324
|
+
function parse(command, args, options) {
|
|
325
|
+
if (args && !Array.isArray(args)) {
|
|
326
|
+
options = args;
|
|
327
|
+
args = null;
|
|
328
|
+
}
|
|
329
|
+
args = args ? args.slice(0) : [];
|
|
330
|
+
options = Object.assign({}, options);
|
|
331
|
+
const parsed = {
|
|
332
|
+
command,
|
|
333
|
+
args,
|
|
334
|
+
options,
|
|
335
|
+
file: void 0,
|
|
336
|
+
original: {
|
|
337
|
+
command,
|
|
338
|
+
args
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return options.shell ? parsed : parseNonShell(parsed);
|
|
342
|
+
}
|
|
343
|
+
module.exports = parse;
|
|
344
|
+
}));
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
|
|
347
|
+
var require_enoent = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
348
|
+
const isWin = process.platform === "win32";
|
|
349
|
+
function notFoundError(original, syscall) {
|
|
350
|
+
return Object.assign(/* @__PURE__ */ new Error(`${syscall} ${original.command} ENOENT`), {
|
|
351
|
+
code: "ENOENT",
|
|
352
|
+
errno: "ENOENT",
|
|
353
|
+
syscall: `${syscall} ${original.command}`,
|
|
354
|
+
path: original.command,
|
|
355
|
+
spawnargs: original.args
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function hookChildProcess(cp, parsed) {
|
|
359
|
+
if (!isWin) return;
|
|
360
|
+
const originalEmit = cp.emit;
|
|
361
|
+
cp.emit = function(name, arg1) {
|
|
362
|
+
if (name === "exit") {
|
|
363
|
+
const err = verifyENOENT(arg1, parsed);
|
|
364
|
+
if (err) return originalEmit.call(cp, "error", err);
|
|
365
|
+
}
|
|
366
|
+
return originalEmit.apply(cp, arguments);
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function verifyENOENT(status, parsed) {
|
|
370
|
+
if (isWin && status === 1 && !parsed.file) return notFoundError(parsed.original, "spawn");
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
function verifyENOENTSync(status, parsed) {
|
|
374
|
+
if (isWin && status === 1 && !parsed.file) return notFoundError(parsed.original, "spawnSync");
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
module.exports = {
|
|
378
|
+
hookChildProcess,
|
|
379
|
+
verifyENOENT,
|
|
380
|
+
verifyENOENTSync,
|
|
381
|
+
notFoundError
|
|
382
|
+
};
|
|
383
|
+
}));
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js
|
|
386
|
+
var require_cross_spawn = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
387
|
+
const cp = __require("child_process");
|
|
388
|
+
const parse = require_parse$1();
|
|
389
|
+
const enoent = require_enoent();
|
|
390
|
+
function spawn(command, args, options) {
|
|
391
|
+
const parsed = parse(command, args, options);
|
|
392
|
+
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
393
|
+
enoent.hookChildProcess(spawned, parsed);
|
|
394
|
+
return spawned;
|
|
395
|
+
}
|
|
396
|
+
function spawnSync(command, args, options) {
|
|
397
|
+
const parsed = parse(command, args, options);
|
|
398
|
+
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
399
|
+
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
400
|
+
return result;
|
|
401
|
+
}
|
|
402
|
+
module.exports = spawn;
|
|
403
|
+
module.exports.spawn = spawn;
|
|
404
|
+
module.exports.sync = spawnSync;
|
|
405
|
+
module.exports._parse = parse;
|
|
406
|
+
module.exports._enoent = enoent;
|
|
407
|
+
}));
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/utils/command.ts
|
|
410
|
+
var import_cross_spawn = /* @__PURE__ */ __toESM(require_cross_spawn(), 1);
|
|
411
|
+
async function runCommandSilently(options) {
|
|
412
|
+
const child = (0, import_cross_spawn.default)(options.command, options.args, {
|
|
413
|
+
stdio: [
|
|
414
|
+
"ignore",
|
|
415
|
+
"pipe",
|
|
416
|
+
"pipe"
|
|
417
|
+
],
|
|
418
|
+
cwd: options.cwd,
|
|
419
|
+
env: options.envs
|
|
420
|
+
});
|
|
421
|
+
return await new Promise((resolve, reject) => {
|
|
422
|
+
const stdout = [];
|
|
423
|
+
const stderr = [];
|
|
424
|
+
child.stdout?.on("data", (data) => {
|
|
425
|
+
stdout.push(data);
|
|
426
|
+
});
|
|
427
|
+
child.stderr?.on("data", (data) => {
|
|
428
|
+
stderr.push(data);
|
|
429
|
+
});
|
|
430
|
+
child.on("close", (code) => {
|
|
431
|
+
resolve({
|
|
432
|
+
exitCode: code ?? 0,
|
|
433
|
+
stdout: Buffer.concat(stdout),
|
|
434
|
+
stderr: Buffer.concat(stderr)
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
child.on("error", (err) => {
|
|
438
|
+
reject(err);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
async function runCommand$1(options) {
|
|
443
|
+
const child = (0, import_cross_spawn.default)(options.command, options.args, {
|
|
444
|
+
stdio: "inherit",
|
|
445
|
+
cwd: options.cwd,
|
|
446
|
+
env: options.envs
|
|
447
|
+
});
|
|
448
|
+
return new Promise((resolve, reject) => {
|
|
449
|
+
child.on("close", (code) => {
|
|
450
|
+
resolve({ exitCode: code ?? 0 });
|
|
451
|
+
});
|
|
452
|
+
child.on("error", (err) => {
|
|
453
|
+
reject(err);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
18
458
|
//#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
|
|
19
459
|
const getCodePointsLength = (() => {
|
|
20
460
|
const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
@@ -297,7 +737,7 @@ function wrapAnsi$1(string, columns, options) {
|
|
|
297
737
|
return String(string).normalize().split(CRLF_OR_LF$1).map((line) => exec$1(line, columns, options)).join("\n");
|
|
298
738
|
}
|
|
299
739
|
//#endregion
|
|
300
|
-
//#region ../../node_modules/.pnpm/@clack+core@1.
|
|
740
|
+
//#region ../../node_modules/.pnpm/@clack+core@1.4.0/node_modules/@clack/core/dist/index.mjs
|
|
301
741
|
var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
302
742
|
const ESC = "\x1B";
|
|
303
743
|
const CSI = `${ESC}[`;
|
|
@@ -350,10 +790,10 @@ var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
350
790
|
beep
|
|
351
791
|
};
|
|
352
792
|
})))();
|
|
353
|
-
function
|
|
793
|
+
function f(r, t, s) {
|
|
354
794
|
if (!s.some((o) => !o.disabled)) return r;
|
|
355
795
|
const e = r + t, i = Math.max(s.length - 1, 0), n = e < 0 ? i : e > i ? 0 : e;
|
|
356
|
-
return s[n].disabled ?
|
|
796
|
+
return s[n].disabled ? f(n, t < 0 ? -1 : 1, s) : n;
|
|
357
797
|
}
|
|
358
798
|
const h = {
|
|
359
799
|
actions: new Set([
|
|
@@ -407,7 +847,7 @@ function C(r, t) {
|
|
|
407
847
|
for (const s of r) if (s !== void 0 && C(s, t)) return !0;
|
|
408
848
|
return !1;
|
|
409
849
|
}
|
|
410
|
-
function
|
|
850
|
+
function Y(r, t) {
|
|
411
851
|
if (r === t) return;
|
|
412
852
|
const s = r.split(`
|
|
413
853
|
`), e = t.split(`
|
|
@@ -420,15 +860,15 @@ function z(r, t) {
|
|
|
420
860
|
numLines: i
|
|
421
861
|
};
|
|
422
862
|
}
|
|
423
|
-
const
|
|
424
|
-
function
|
|
863
|
+
const q = globalThis.process.platform.startsWith("win"), k = Symbol("clack:cancel");
|
|
864
|
+
function R(r) {
|
|
425
865
|
return r === k;
|
|
426
866
|
}
|
|
427
867
|
function w(r, t) {
|
|
428
868
|
const s = r;
|
|
429
869
|
s.isTTY && s.setRawMode(t);
|
|
430
870
|
}
|
|
431
|
-
function
|
|
871
|
+
function W({ input: r = stdin, output: t = stdout, overwrite: s = !0, hideCursor: e = !0 } = {}) {
|
|
432
872
|
const i = b.createInterface({
|
|
433
873
|
input: r,
|
|
434
874
|
output: t,
|
|
@@ -446,30 +886,38 @@ function R({ input: r = stdin, output: t = stdout, overwrite: s = !0, hideCursor
|
|
|
446
886
|
return;
|
|
447
887
|
}
|
|
448
888
|
if (!s) return;
|
|
449
|
-
const
|
|
450
|
-
b.moveCursor(t,
|
|
889
|
+
const c = u === "return" ? 0 : -1, y = u === "return" ? -1 : 0;
|
|
890
|
+
b.moveCursor(t, c, y, () => {
|
|
451
891
|
b.clearLine(t, 1, () => {
|
|
452
892
|
r.once("keypress", n);
|
|
453
893
|
});
|
|
454
894
|
});
|
|
455
895
|
};
|
|
456
896
|
return e && t.write(import_src.cursor.hide), r.once("keypress", n), () => {
|
|
457
|
-
r.off("keypress", n), e && t.write(import_src.cursor.show), r instanceof ReadStream && r.isTTY && !
|
|
897
|
+
r.off("keypress", n), e && t.write(import_src.cursor.show), r instanceof ReadStream && r.isTTY && !q && r.setRawMode(!1), i.terminal = !1, i.close();
|
|
458
898
|
};
|
|
459
899
|
}
|
|
460
900
|
const A = (r) => "columns" in r && typeof r.columns == "number" ? r.columns : 80, L = (r) => "rows" in r && typeof r.rows == "number" ? r.rows : 20;
|
|
461
|
-
function
|
|
901
|
+
function B(r, t, s, e = s, i = s, n) {
|
|
462
902
|
return wrapAnsi$1(t, A(r ?? stdout) - s.length, {
|
|
463
903
|
hard: !0,
|
|
464
904
|
trim: !1
|
|
465
905
|
}).split(`
|
|
466
|
-
`).map((
|
|
467
|
-
const
|
|
468
|
-
return
|
|
906
|
+
`).map((u, a, l) => {
|
|
907
|
+
const c = n ? n(u, a) : u;
|
|
908
|
+
return a === 0 ? `${e}${c}` : a === l.length - 1 ? `${i}${c}` : `${s}${c}`;
|
|
469
909
|
}).join(`
|
|
470
910
|
`);
|
|
471
911
|
}
|
|
472
|
-
|
|
912
|
+
function P(r, t) {
|
|
913
|
+
if ("~standard" in r) {
|
|
914
|
+
const s = r["~standard"].validate(t);
|
|
915
|
+
if (s instanceof Promise) throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");
|
|
916
|
+
return s.issues?.at(0)?.message;
|
|
917
|
+
}
|
|
918
|
+
return r(t);
|
|
919
|
+
}
|
|
920
|
+
var m = class {
|
|
473
921
|
input;
|
|
474
922
|
output;
|
|
475
923
|
_abortSignal;
|
|
@@ -517,7 +965,7 @@ let p = class {
|
|
|
517
965
|
this.state = "cancel", this.close();
|
|
518
966
|
}, { once: !0 });
|
|
519
967
|
}
|
|
520
|
-
this.rl =
|
|
968
|
+
this.rl = G.createInterface({
|
|
521
969
|
input: this.input,
|
|
522
970
|
tabSize: 2,
|
|
523
971
|
prompt: "",
|
|
@@ -552,9 +1000,9 @@ let p = class {
|
|
|
552
1000
|
if (this._track && s.name !== "return" && (s.name && this._isActionKey(t, s) && this.rl?.write(null, {
|
|
553
1001
|
ctrl: !0,
|
|
554
1002
|
name: "h"
|
|
555
|
-
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && h.aliases.has(s.name) && this.emit("cursor", h.aliases.get(s.name)), h.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t
|
|
1003
|
+
}), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && h.aliases.has(s.name) && this.emit("cursor", h.aliases.get(s.name)), h.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t, s), s?.name === "return" && this._shouldSubmit(t, s)) {
|
|
556
1004
|
if (this.opts.validate) {
|
|
557
|
-
const e = this.opts.validate
|
|
1005
|
+
const e = P(this.opts.validate, this.value);
|
|
558
1006
|
e && (this.error = e instanceof Error ? e.message : e, this.state = "error", this.rl?.write(this.userInput));
|
|
559
1007
|
}
|
|
560
1008
|
this.state !== "error" && (this.state = "submit");
|
|
@@ -585,7 +1033,7 @@ let p = class {
|
|
|
585
1033
|
if (t !== this._prevFrame) {
|
|
586
1034
|
if (this.state === "initial") this.output.write(import_src.cursor.hide);
|
|
587
1035
|
else {
|
|
588
|
-
const s =
|
|
1036
|
+
const s = Y(this._prevFrame, t), e = L(this.output);
|
|
589
1037
|
if (this.restoreCursor(), s) {
|
|
590
1038
|
const i = Math.max(0, s.numLinesAfter - e), n = Math.max(0, s.numLinesBefore - e);
|
|
591
1039
|
let o = s.lines.find((u) => u >= i);
|
|
@@ -619,7 +1067,7 @@ let p = class {
|
|
|
619
1067
|
}
|
|
620
1068
|
}
|
|
621
1069
|
};
|
|
622
|
-
var
|
|
1070
|
+
var Z = class extends m {
|
|
623
1071
|
get cursor() {
|
|
624
1072
|
return this.value ? 0 : 1;
|
|
625
1073
|
}
|
|
@@ -636,7 +1084,7 @@ var X = class extends p {
|
|
|
636
1084
|
});
|
|
637
1085
|
}
|
|
638
1086
|
};
|
|
639
|
-
let
|
|
1087
|
+
let ut = class extends m {
|
|
640
1088
|
options;
|
|
641
1089
|
cursor = 0;
|
|
642
1090
|
get _value() {
|
|
@@ -663,17 +1111,17 @@ let nt = class extends p {
|
|
|
663
1111
|
constructor(t) {
|
|
664
1112
|
super(t, !1), this.options = t.options, this.value = [...t.initialValues ?? []];
|
|
665
1113
|
const s = Math.max(this.options.findIndex(({ value: e }) => e === t.cursorAt), 0);
|
|
666
|
-
this.cursor = this.options[s].disabled ?
|
|
667
|
-
|
|
1114
|
+
this.cursor = this.options[s].disabled ? f(s, 1, this.options) : s, this.on("key", (e, i) => {
|
|
1115
|
+
i.name === "a" && this.toggleAll(), i.name === "i" && this.toggleInvert();
|
|
668
1116
|
}), this.on("cursor", (e) => {
|
|
669
1117
|
switch (e) {
|
|
670
1118
|
case "left":
|
|
671
1119
|
case "up":
|
|
672
|
-
this.cursor =
|
|
1120
|
+
this.cursor = f(this.cursor, -1, this.options);
|
|
673
1121
|
break;
|
|
674
1122
|
case "down":
|
|
675
1123
|
case "right":
|
|
676
|
-
this.cursor =
|
|
1124
|
+
this.cursor = f(this.cursor, 1, this.options);
|
|
677
1125
|
break;
|
|
678
1126
|
case "space":
|
|
679
1127
|
this.toggleValue();
|
|
@@ -682,7 +1130,7 @@ let nt = class extends p {
|
|
|
682
1130
|
});
|
|
683
1131
|
}
|
|
684
1132
|
};
|
|
685
|
-
var
|
|
1133
|
+
var ht = class extends m {
|
|
686
1134
|
options;
|
|
687
1135
|
cursor = 0;
|
|
688
1136
|
get _selectedValue() {
|
|
@@ -694,22 +1142,22 @@ var ut = class extends p {
|
|
|
694
1142
|
constructor(t) {
|
|
695
1143
|
super(t, !1), this.options = t.options;
|
|
696
1144
|
const s = this.options.findIndex(({ value: i }) => i === t.initialValue), e = s === -1 ? 0 : s;
|
|
697
|
-
this.cursor = this.options[e].disabled ?
|
|
1145
|
+
this.cursor = this.options[e].disabled ? f(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (i) => {
|
|
698
1146
|
switch (i) {
|
|
699
1147
|
case "left":
|
|
700
1148
|
case "up":
|
|
701
|
-
this.cursor =
|
|
1149
|
+
this.cursor = f(this.cursor, -1, this.options);
|
|
702
1150
|
break;
|
|
703
1151
|
case "down":
|
|
704
1152
|
case "right":
|
|
705
|
-
this.cursor =
|
|
1153
|
+
this.cursor = f(this.cursor, 1, this.options);
|
|
706
1154
|
break;
|
|
707
1155
|
}
|
|
708
1156
|
this.changeValue();
|
|
709
1157
|
});
|
|
710
1158
|
}
|
|
711
1159
|
};
|
|
712
|
-
var
|
|
1160
|
+
var ct = class extends m {
|
|
713
1161
|
get userInputWithCursor() {
|
|
714
1162
|
if (this.state === "submit") return this.userInput;
|
|
715
1163
|
const t = this.userInput;
|
|
@@ -1232,7 +1680,7 @@ const limitOptions = (params) => {
|
|
|
1232
1680
|
const confirm = (opts) => {
|
|
1233
1681
|
const active = opts.active ?? "Yes";
|
|
1234
1682
|
const inactive = opts.inactive ?? "No";
|
|
1235
|
-
return new
|
|
1683
|
+
return new Z({
|
|
1236
1684
|
active,
|
|
1237
1685
|
inactive,
|
|
1238
1686
|
signal: opts.signal,
|
|
@@ -1342,7 +1790,7 @@ const multiselect = (opts) => {
|
|
|
1342
1790
|
};
|
|
1343
1791
|
const required = opts.required ?? true;
|
|
1344
1792
|
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`));
|
|
1345
|
-
return new
|
|
1793
|
+
return new ut({
|
|
1346
1794
|
options: opts.options,
|
|
1347
1795
|
signal: opts.signal,
|
|
1348
1796
|
input: opts.input,
|
|
@@ -1359,7 +1807,7 @@ const multiselect = (opts) => {
|
|
|
1359
1807
|
const formatMessageLines = (message) => {
|
|
1360
1808
|
return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
|
|
1361
1809
|
};
|
|
1362
|
-
const wrappedMessage = hasGuide ?
|
|
1810
|
+
const wrappedMessage = hasGuide ? B(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
|
|
1363
1811
|
const title = `${hasGuide ? `${import_picocolors.default.gray(S_BAR)}\n` : ""}${wrappedMessage}\n`;
|
|
1364
1812
|
const value = this.value ?? [];
|
|
1365
1813
|
const styleOption = (option, active) => {
|
|
@@ -1373,13 +1821,13 @@ const multiselect = (opts) => {
|
|
|
1373
1821
|
case "submit": {
|
|
1374
1822
|
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");
|
|
1375
1823
|
const submitPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
1376
|
-
return `${title}${
|
|
1824
|
+
return `${title}${B(opts.output, submitText, submitPrefix)}\n`;
|
|
1377
1825
|
}
|
|
1378
1826
|
case "cancel": {
|
|
1379
1827
|
const label = this.options.filter(({ value: optionValue }) => value.includes(optionValue)).map((option) => opt(option, "cancelled")).join(import_picocolors.default.dim(", "));
|
|
1380
1828
|
if (label.trim() === "") return hasGuide ? `${title}${import_picocolors.default.gray(S_BAR)}\n` : `${title.trimEnd()}\n`;
|
|
1381
1829
|
const cancelPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
1382
|
-
const wrappedLabel =
|
|
1830
|
+
const wrappedLabel = B(opts.output, label, cancelPrefix);
|
|
1383
1831
|
return hasGuide ? `${title}${wrappedLabel}\n${import_picocolors.default.gray(S_BAR)}\n` : `${title}${wrappedLabel}\n`;
|
|
1384
1832
|
}
|
|
1385
1833
|
case "error": {
|
|
@@ -1491,7 +1939,7 @@ const spinner = ({ indicator = "dots", onCancel, output = process.stdout, cancel
|
|
|
1491
1939
|
const hasGuide = opts.withGuide ?? false;
|
|
1492
1940
|
const startLoop = () => {
|
|
1493
1941
|
isSpinnerActive = true;
|
|
1494
|
-
unblock =
|
|
1942
|
+
unblock = W({ output });
|
|
1495
1943
|
_origin = performance.now();
|
|
1496
1944
|
_prevMessage = void 0;
|
|
1497
1945
|
if (hasGuide) output.write(`${import_picocolors.default.gray(S_BAR)}\n`);
|
|
@@ -1592,7 +2040,7 @@ const select = (opts) => {
|
|
|
1592
2040
|
default: return withMarker(import_picocolors.default.dim(" "), label, (text) => text, hint);
|
|
1593
2041
|
}
|
|
1594
2042
|
};
|
|
1595
|
-
return new
|
|
2043
|
+
return new ht({
|
|
1596
2044
|
options: opts.options,
|
|
1597
2045
|
signal: opts.signal,
|
|
1598
2046
|
input: opts.input,
|
|
@@ -1605,16 +2053,16 @@ const select = (opts) => {
|
|
|
1605
2053
|
return message.split("\n").map((line, index) => `${index === 0 ? `${symbol(this.state)} ` : nestedPrefix}${line}`).join("\n");
|
|
1606
2054
|
};
|
|
1607
2055
|
const hasMessage = opts.message.trim().length > 0;
|
|
1608
|
-
const messageLines = !hasMessage ? "" : hasGuide ?
|
|
2056
|
+
const messageLines = !hasMessage ? "" : hasGuide ? B(opts.output, opts.message, `${symbolBar(this.state)} `, `${symbol(this.state)} `) : formatMessageLines(opts.message);
|
|
1609
2057
|
const title = hasMessage ? `${hasGuide ? `${import_picocolors.default.gray(S_BAR)}\n` : ""}${messageLines}\n` : "";
|
|
1610
2058
|
switch (this.state) {
|
|
1611
2059
|
case "submit": {
|
|
1612
2060
|
const submitPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
1613
|
-
return `${title}${
|
|
2061
|
+
return `${title}${B(opts.output, opt(this.options[this.cursor], "selected"), submitPrefix)}\n`;
|
|
1614
2062
|
}
|
|
1615
2063
|
case "cancel": {
|
|
1616
2064
|
const cancelPrefix = hasGuide ? `${import_picocolors.default.gray(S_BAR)} ` : nestedPrefix;
|
|
1617
|
-
return `${title}${
|
|
2065
|
+
return `${title}${B(opts.output, opt(this.options[this.cursor], "cancelled"), cancelPrefix)}${hasGuide ? `\n${import_picocolors.default.gray(S_BAR)}` : ""}\n`;
|
|
1618
2066
|
}
|
|
1619
2067
|
default: {
|
|
1620
2068
|
const prefix = hasGuide ? `${import_picocolors.default.blue(S_BAR)} ` : nestedPrefix;
|
|
@@ -1636,7 +2084,7 @@ const select = (opts) => {
|
|
|
1636
2084
|
}).prompt();
|
|
1637
2085
|
};
|
|
1638
2086
|
const text = (opts) => {
|
|
1639
|
-
return new
|
|
2087
|
+
return new ct({
|
|
1640
2088
|
validate: opts.validate,
|
|
1641
2089
|
placeholder: opts.placeholder,
|
|
1642
2090
|
defaultValue: opts.defaultValue,
|
|
@@ -1673,7 +2121,7 @@ const text = (opts) => {
|
|
|
1673
2121
|
}).prompt();
|
|
1674
2122
|
};
|
|
1675
2123
|
//#endregion
|
|
1676
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2124
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/internal/constants.js
|
|
1677
2125
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1678
2126
|
const SEMVER_SPEC_VERSION = "2.0.0";
|
|
1679
2127
|
const MAX_LENGTH = 256;
|
|
@@ -1698,12 +2146,12 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1698
2146
|
};
|
|
1699
2147
|
}));
|
|
1700
2148
|
//#endregion
|
|
1701
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2149
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/internal/debug.js
|
|
1702
2150
|
var require_debug = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1703
2151
|
module.exports = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
|
|
1704
2152
|
}));
|
|
1705
2153
|
//#endregion
|
|
1706
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2154
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/internal/re.js
|
|
1707
2155
|
var require_re = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1708
2156
|
const { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH, MAX_LENGTH } = require_constants();
|
|
1709
2157
|
const debug = require_debug();
|
|
@@ -1782,7 +2230,7 @@ var require_re = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1782
2230
|
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
|
|
1783
2231
|
}));
|
|
1784
2232
|
//#endregion
|
|
1785
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2233
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/internal/parse-options.js
|
|
1786
2234
|
var require_parse_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1787
2235
|
const looseOption = Object.freeze({ loose: true });
|
|
1788
2236
|
const emptyOpts = Object.freeze({});
|
|
@@ -1794,7 +2242,7 @@ var require_parse_options = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1794
2242
|
module.exports = parseOptions;
|
|
1795
2243
|
}));
|
|
1796
2244
|
//#endregion
|
|
1797
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2245
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/internal/identifiers.js
|
|
1798
2246
|
var require_identifiers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1799
2247
|
const numeric = /^[0-9]+$/;
|
|
1800
2248
|
const compareIdentifiers = (a, b) => {
|
|
@@ -1814,7 +2262,7 @@ var require_identifiers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1814
2262
|
};
|
|
1815
2263
|
}));
|
|
1816
2264
|
//#endregion
|
|
1817
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2265
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/classes/semver.js
|
|
1818
2266
|
var require_semver$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1819
2267
|
const debug = require_debug();
|
|
1820
2268
|
const { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
|
|
@@ -1992,7 +2440,7 @@ var require_semver$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1992
2440
|
};
|
|
1993
2441
|
}));
|
|
1994
2442
|
//#endregion
|
|
1995
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2443
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/parse.js
|
|
1996
2444
|
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1997
2445
|
const SemVer = require_semver$1();
|
|
1998
2446
|
const parse = (version, options, throwErrors = false) => {
|
|
@@ -2007,7 +2455,7 @@ var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2007
2455
|
module.exports = parse;
|
|
2008
2456
|
}));
|
|
2009
2457
|
//#endregion
|
|
2010
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2458
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/valid.js
|
|
2011
2459
|
var require_valid$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2012
2460
|
const parse = require_parse();
|
|
2013
2461
|
const valid = (version, options) => {
|
|
@@ -2017,7 +2465,7 @@ var require_valid$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2017
2465
|
module.exports = valid;
|
|
2018
2466
|
}));
|
|
2019
2467
|
//#endregion
|
|
2020
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2468
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/clean.js
|
|
2021
2469
|
var require_clean = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2022
2470
|
const parse = require_parse();
|
|
2023
2471
|
const clean = (version, options) => {
|
|
@@ -2027,7 +2475,7 @@ var require_clean = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2027
2475
|
module.exports = clean;
|
|
2028
2476
|
}));
|
|
2029
2477
|
//#endregion
|
|
2030
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2478
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/inc.js
|
|
2031
2479
|
var require_inc = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2032
2480
|
const SemVer = require_semver$1();
|
|
2033
2481
|
const inc = (version, release, options, identifier, identifierBase) => {
|
|
@@ -2045,7 +2493,7 @@ var require_inc = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2045
2493
|
module.exports = inc;
|
|
2046
2494
|
}));
|
|
2047
2495
|
//#endregion
|
|
2048
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2496
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/diff.js
|
|
2049
2497
|
var require_diff = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2050
2498
|
const parse = require_parse();
|
|
2051
2499
|
const diff = (version1, version2) => {
|
|
@@ -2073,28 +2521,28 @@ var require_diff = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2073
2521
|
module.exports = diff;
|
|
2074
2522
|
}));
|
|
2075
2523
|
//#endregion
|
|
2076
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2524
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/major.js
|
|
2077
2525
|
var require_major = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2078
2526
|
const SemVer = require_semver$1();
|
|
2079
2527
|
const major = (a, loose) => new SemVer(a, loose).major;
|
|
2080
2528
|
module.exports = major;
|
|
2081
2529
|
}));
|
|
2082
2530
|
//#endregion
|
|
2083
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2531
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/minor.js
|
|
2084
2532
|
var require_minor = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2085
2533
|
const SemVer = require_semver$1();
|
|
2086
2534
|
const minor = (a, loose) => new SemVer(a, loose).minor;
|
|
2087
2535
|
module.exports = minor;
|
|
2088
2536
|
}));
|
|
2089
2537
|
//#endregion
|
|
2090
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2538
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/patch.js
|
|
2091
2539
|
var require_patch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2092
2540
|
const SemVer = require_semver$1();
|
|
2093
2541
|
const patch = (a, loose) => new SemVer(a, loose).patch;
|
|
2094
2542
|
module.exports = patch;
|
|
2095
2543
|
}));
|
|
2096
2544
|
//#endregion
|
|
2097
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2545
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/prerelease.js
|
|
2098
2546
|
var require_prerelease = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2099
2547
|
const parse = require_parse();
|
|
2100
2548
|
const prerelease = (version, options) => {
|
|
@@ -2104,28 +2552,28 @@ var require_prerelease = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2104
2552
|
module.exports = prerelease;
|
|
2105
2553
|
}));
|
|
2106
2554
|
//#endregion
|
|
2107
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2555
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/compare.js
|
|
2108
2556
|
var require_compare = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2109
2557
|
const SemVer = require_semver$1();
|
|
2110
2558
|
const compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
2111
2559
|
module.exports = compare;
|
|
2112
2560
|
}));
|
|
2113
2561
|
//#endregion
|
|
2114
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2562
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/rcompare.js
|
|
2115
2563
|
var require_rcompare = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2116
2564
|
const compare = require_compare();
|
|
2117
2565
|
const rcompare = (a, b, loose) => compare(b, a, loose);
|
|
2118
2566
|
module.exports = rcompare;
|
|
2119
2567
|
}));
|
|
2120
2568
|
//#endregion
|
|
2121
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2569
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/compare-loose.js
|
|
2122
2570
|
var require_compare_loose = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2123
2571
|
const compare = require_compare();
|
|
2124
2572
|
const compareLoose = (a, b) => compare(a, b, true);
|
|
2125
2573
|
module.exports = compareLoose;
|
|
2126
2574
|
}));
|
|
2127
2575
|
//#endregion
|
|
2128
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2576
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/compare-build.js
|
|
2129
2577
|
var require_compare_build = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2130
2578
|
const SemVer = require_semver$1();
|
|
2131
2579
|
const compareBuild = (a, b, loose) => {
|
|
@@ -2136,63 +2584,63 @@ var require_compare_build = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
2136
2584
|
module.exports = compareBuild;
|
|
2137
2585
|
}));
|
|
2138
2586
|
//#endregion
|
|
2139
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2587
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/sort.js
|
|
2140
2588
|
var require_sort = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2141
2589
|
const compareBuild = require_compare_build();
|
|
2142
2590
|
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
|
|
2143
2591
|
module.exports = sort;
|
|
2144
2592
|
}));
|
|
2145
2593
|
//#endregion
|
|
2146
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2594
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/rsort.js
|
|
2147
2595
|
var require_rsort = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2148
2596
|
const compareBuild = require_compare_build();
|
|
2149
2597
|
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
|
|
2150
2598
|
module.exports = rsort;
|
|
2151
2599
|
}));
|
|
2152
2600
|
//#endregion
|
|
2153
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2601
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/gt.js
|
|
2154
2602
|
var require_gt = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2155
2603
|
const compare = require_compare();
|
|
2156
2604
|
const gt = (a, b, loose) => compare(a, b, loose) > 0;
|
|
2157
2605
|
module.exports = gt;
|
|
2158
2606
|
}));
|
|
2159
2607
|
//#endregion
|
|
2160
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2608
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/lt.js
|
|
2161
2609
|
var require_lt = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2162
2610
|
const compare = require_compare();
|
|
2163
2611
|
const lt = (a, b, loose) => compare(a, b, loose) < 0;
|
|
2164
2612
|
module.exports = lt;
|
|
2165
2613
|
}));
|
|
2166
2614
|
//#endregion
|
|
2167
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2615
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/eq.js
|
|
2168
2616
|
var require_eq = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2169
2617
|
const compare = require_compare();
|
|
2170
2618
|
const eq = (a, b, loose) => compare(a, b, loose) === 0;
|
|
2171
2619
|
module.exports = eq;
|
|
2172
2620
|
}));
|
|
2173
2621
|
//#endregion
|
|
2174
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2622
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/neq.js
|
|
2175
2623
|
var require_neq = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2176
2624
|
const compare = require_compare();
|
|
2177
2625
|
const neq = (a, b, loose) => compare(a, b, loose) !== 0;
|
|
2178
2626
|
module.exports = neq;
|
|
2179
2627
|
}));
|
|
2180
2628
|
//#endregion
|
|
2181
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2629
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/gte.js
|
|
2182
2630
|
var require_gte = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2183
2631
|
const compare = require_compare();
|
|
2184
2632
|
const gte = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
2185
2633
|
module.exports = gte;
|
|
2186
2634
|
}));
|
|
2187
2635
|
//#endregion
|
|
2188
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2636
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/lte.js
|
|
2189
2637
|
var require_lte = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2190
2638
|
const compare = require_compare();
|
|
2191
2639
|
const lte = (a, b, loose) => compare(a, b, loose) <= 0;
|
|
2192
2640
|
module.exports = lte;
|
|
2193
2641
|
}));
|
|
2194
2642
|
//#endregion
|
|
2195
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2643
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/cmp.js
|
|
2196
2644
|
var require_cmp = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2197
2645
|
const eq = require_eq();
|
|
2198
2646
|
const neq = require_neq();
|
|
@@ -2224,7 +2672,7 @@ var require_cmp = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2224
2672
|
module.exports = cmp;
|
|
2225
2673
|
}));
|
|
2226
2674
|
//#endregion
|
|
2227
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2675
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/coerce.js
|
|
2228
2676
|
var require_coerce = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2229
2677
|
const SemVer = require_semver$1();
|
|
2230
2678
|
const parse = require_parse();
|
|
@@ -2252,7 +2700,40 @@ var require_coerce = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2252
2700
|
module.exports = coerce;
|
|
2253
2701
|
}));
|
|
2254
2702
|
//#endregion
|
|
2255
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2703
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/truncate.js
|
|
2704
|
+
var require_truncate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2705
|
+
const parse = require_parse();
|
|
2706
|
+
const constants = require_constants();
|
|
2707
|
+
const SemVer = require_semver$1();
|
|
2708
|
+
const truncate = (version, truncation, options) => {
|
|
2709
|
+
if (!constants.RELEASE_TYPES.includes(truncation)) return null;
|
|
2710
|
+
const clonedVersion = cloneInputVersion(version, options);
|
|
2711
|
+
return clonedVersion && doTruncation(clonedVersion, truncation);
|
|
2712
|
+
};
|
|
2713
|
+
const cloneInputVersion = (version, options) => {
|
|
2714
|
+
return parse(version instanceof SemVer ? version.version : version, options);
|
|
2715
|
+
};
|
|
2716
|
+
const doTruncation = (version, truncation) => {
|
|
2717
|
+
if (isPrerelease(truncation)) return version.version;
|
|
2718
|
+
version.prerelease = [];
|
|
2719
|
+
switch (truncation) {
|
|
2720
|
+
case "major":
|
|
2721
|
+
version.minor = 0;
|
|
2722
|
+
version.patch = 0;
|
|
2723
|
+
break;
|
|
2724
|
+
case "minor":
|
|
2725
|
+
version.patch = 0;
|
|
2726
|
+
break;
|
|
2727
|
+
}
|
|
2728
|
+
return version.format();
|
|
2729
|
+
};
|
|
2730
|
+
const isPrerelease = (type) => {
|
|
2731
|
+
return type.startsWith("pre");
|
|
2732
|
+
};
|
|
2733
|
+
module.exports = truncate;
|
|
2734
|
+
}));
|
|
2735
|
+
//#endregion
|
|
2736
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/internal/lrucache.js
|
|
2256
2737
|
var require_lrucache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2257
2738
|
var LRUCache = class {
|
|
2258
2739
|
constructor() {
|
|
@@ -2285,7 +2766,7 @@ var require_lrucache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2285
2766
|
module.exports = LRUCache;
|
|
2286
2767
|
}));
|
|
2287
2768
|
//#endregion
|
|
2288
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
2769
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/classes/range.js
|
|
2289
2770
|
var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2290
2771
|
const SPACE_CHARACTERS = /\s+/g;
|
|
2291
2772
|
module.exports = class Range {
|
|
@@ -2557,7 +3038,7 @@ var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2557
3038
|
};
|
|
2558
3039
|
}));
|
|
2559
3040
|
//#endregion
|
|
2560
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3041
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/classes/comparator.js
|
|
2561
3042
|
var require_comparator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2562
3043
|
const ANY = Symbol("SemVer ANY");
|
|
2563
3044
|
module.exports = class Comparator {
|
|
@@ -2627,7 +3108,7 @@ var require_comparator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2627
3108
|
const Range = require_range();
|
|
2628
3109
|
}));
|
|
2629
3110
|
//#endregion
|
|
2630
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3111
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/satisfies.js
|
|
2631
3112
|
var require_satisfies = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2632
3113
|
const Range = require_range();
|
|
2633
3114
|
const satisfies = (version, range, options) => {
|
|
@@ -2641,14 +3122,14 @@ var require_satisfies = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2641
3122
|
module.exports = satisfies;
|
|
2642
3123
|
}));
|
|
2643
3124
|
//#endregion
|
|
2644
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3125
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/to-comparators.js
|
|
2645
3126
|
var require_to_comparators = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2646
3127
|
const Range = require_range();
|
|
2647
3128
|
const toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
|
|
2648
3129
|
module.exports = toComparators;
|
|
2649
3130
|
}));
|
|
2650
3131
|
//#endregion
|
|
2651
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3132
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/max-satisfying.js
|
|
2652
3133
|
var require_max_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2653
3134
|
const SemVer = require_semver$1();
|
|
2654
3135
|
const Range = require_range();
|
|
@@ -2674,7 +3155,7 @@ var require_max_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
2674
3155
|
module.exports = maxSatisfying;
|
|
2675
3156
|
}));
|
|
2676
3157
|
//#endregion
|
|
2677
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3158
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/min-satisfying.js
|
|
2678
3159
|
var require_min_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2679
3160
|
const SemVer = require_semver$1();
|
|
2680
3161
|
const Range = require_range();
|
|
@@ -2700,7 +3181,7 @@ var require_min_satisfying = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
2700
3181
|
module.exports = minSatisfying;
|
|
2701
3182
|
}));
|
|
2702
3183
|
//#endregion
|
|
2703
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3184
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/min-version.js
|
|
2704
3185
|
var require_min_version = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2705
3186
|
const SemVer = require_semver$1();
|
|
2706
3187
|
const Range = require_range();
|
|
@@ -2740,7 +3221,7 @@ var require_min_version = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2740
3221
|
module.exports = minVersion;
|
|
2741
3222
|
}));
|
|
2742
3223
|
//#endregion
|
|
2743
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3224
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/valid.js
|
|
2744
3225
|
var require_valid = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2745
3226
|
const Range = require_range();
|
|
2746
3227
|
const validRange = (range, options) => {
|
|
@@ -2753,7 +3234,7 @@ var require_valid = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2753
3234
|
module.exports = validRange;
|
|
2754
3235
|
}));
|
|
2755
3236
|
//#endregion
|
|
2756
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3237
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/outside.js
|
|
2757
3238
|
var require_outside = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2758
3239
|
const SemVer = require_semver$1();
|
|
2759
3240
|
const Comparator = require_comparator();
|
|
@@ -2806,21 +3287,21 @@ var require_outside = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2806
3287
|
module.exports = outside;
|
|
2807
3288
|
}));
|
|
2808
3289
|
//#endregion
|
|
2809
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3290
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/gtr.js
|
|
2810
3291
|
var require_gtr = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2811
3292
|
const outside = require_outside();
|
|
2812
3293
|
const gtr = (version, range, options) => outside(version, range, ">", options);
|
|
2813
3294
|
module.exports = gtr;
|
|
2814
3295
|
}));
|
|
2815
3296
|
//#endregion
|
|
2816
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3297
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/ltr.js
|
|
2817
3298
|
var require_ltr = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2818
3299
|
const outside = require_outside();
|
|
2819
3300
|
const ltr = (version, range, options) => outside(version, range, "<", options);
|
|
2820
3301
|
module.exports = ltr;
|
|
2821
3302
|
}));
|
|
2822
3303
|
//#endregion
|
|
2823
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3304
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/intersects.js
|
|
2824
3305
|
var require_intersects = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2825
3306
|
const Range = require_range();
|
|
2826
3307
|
const intersects = (r1, r2, options) => {
|
|
@@ -2831,7 +3312,7 @@ var require_intersects = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2831
3312
|
module.exports = intersects;
|
|
2832
3313
|
}));
|
|
2833
3314
|
//#endregion
|
|
2834
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3315
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/simplify.js
|
|
2835
3316
|
var require_simplify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2836
3317
|
const satisfies = require_satisfies();
|
|
2837
3318
|
const compare = require_compare();
|
|
@@ -2861,7 +3342,7 @@ var require_simplify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2861
3342
|
};
|
|
2862
3343
|
}));
|
|
2863
3344
|
//#endregion
|
|
2864
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3345
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/ranges/subset.js
|
|
2865
3346
|
var require_subset = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2866
3347
|
const Range = require_range();
|
|
2867
3348
|
const Comparator = require_comparator();
|
|
@@ -2956,7 +3437,7 @@ var require_subset = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2956
3437
|
module.exports = subset;
|
|
2957
3438
|
}));
|
|
2958
3439
|
//#endregion
|
|
2959
|
-
//#region ../../node_modules/.pnpm/semver@7.
|
|
3440
|
+
//#region ../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/index.js
|
|
2960
3441
|
var require_semver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2961
3442
|
const internalRe = require_re();
|
|
2962
3443
|
const constants = require_constants();
|
|
@@ -2986,6 +3467,7 @@ var require_semver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2986
3467
|
lte: require_lte(),
|
|
2987
3468
|
cmp: require_cmp(),
|
|
2988
3469
|
coerce: require_coerce(),
|
|
3470
|
+
truncate: require_truncate(),
|
|
2989
3471
|
Comparator: require_comparator(),
|
|
2990
3472
|
Range: require_range(),
|
|
2991
3473
|
satisfies: require_satisfies(),
|
|
@@ -3025,26 +3507,8 @@ const DependencyType = {
|
|
|
3025
3507
|
optionalDependencies: "optionalDependencies"
|
|
3026
3508
|
};
|
|
3027
3509
|
//#endregion
|
|
3028
|
-
//#region src/utils/path.ts
|
|
3029
|
-
var import_cross_spawn = /* @__PURE__ */ __toESM(require_cross_spawn(), 1);
|
|
3030
|
-
var import_semver = /* @__PURE__ */ __toESM(require_semver(), 1);
|
|
3031
|
-
var import_dist = require_dist();
|
|
3032
|
-
function findPkgRoot() {
|
|
3033
|
-
let dir = import.meta.dirname;
|
|
3034
|
-
while (dir !== path.dirname(dir)) {
|
|
3035
|
-
if (fs.existsSync(path.join(dir, "package.json"))) return dir;
|
|
3036
|
-
dir = path.dirname(dir);
|
|
3037
|
-
}
|
|
3038
|
-
return dir;
|
|
3039
|
-
}
|
|
3040
|
-
const pkgRoot = findPkgRoot();
|
|
3041
|
-
const templatesDir = path.join(pkgRoot, "templates");
|
|
3042
|
-
const rulesDir = path.join(pkgRoot, "rules");
|
|
3043
|
-
function displayRelative(to, from = process.cwd()) {
|
|
3044
|
-
return path.relative(from, to).replaceAll("\\", "/");
|
|
3045
|
-
}
|
|
3046
|
-
//#endregion
|
|
3047
3510
|
//#region src/utils/prompts.ts
|
|
3511
|
+
var import_semver = /* @__PURE__ */ __toESM(require_semver(), 1);
|
|
3048
3512
|
/**
|
|
3049
3513
|
* pnpm v11 promoted `ERR_PNPM_IGNORED_BUILDS` from a warning to a hard
|
|
3050
3514
|
* exit-1. Auto-installs run by `vp migrate` / `vp create` happen before the
|
|
@@ -3078,7 +3542,7 @@ async function selectPackageManager(interactive, silent = false) {
|
|
|
3078
3542
|
],
|
|
3079
3543
|
initialValue: PackageManager.pnpm
|
|
3080
3544
|
});
|
|
3081
|
-
if (
|
|
3545
|
+
if (R(selected)) cancelAndExit();
|
|
3082
3546
|
return selected;
|
|
3083
3547
|
} else {
|
|
3084
3548
|
if (!silent) log.info(`Using default package manager: ${accent(PackageManager.pnpm)}`);
|
|
@@ -3192,7 +3656,7 @@ async function promptGitHooks(options) {
|
|
|
3192
3656
|
message: "Set up pre-commit hooks to run formatting, linting, and type checking with auto-fixes?",
|
|
3193
3657
|
initialValue: true
|
|
3194
3658
|
});
|
|
3195
|
-
if (
|
|
3659
|
+
if (R(selected)) {
|
|
3196
3660
|
cancelAndExit();
|
|
3197
3661
|
return false;
|
|
3198
3662
|
}
|
|
@@ -3206,9 +3670,9 @@ async function promptGitInit(options) {
|
|
|
3206
3670
|
if (options.interactive) {
|
|
3207
3671
|
const selected = await confirm({
|
|
3208
3672
|
message: "Initialize a git repository with an initial commit?",
|
|
3209
|
-
initialValue:
|
|
3673
|
+
initialValue: true
|
|
3210
3674
|
});
|
|
3211
|
-
if (
|
|
3675
|
+
if (R(selected)) {
|
|
3212
3676
|
cancelAndExit();
|
|
3213
3677
|
return false;
|
|
3214
3678
|
}
|
|
@@ -3241,2027 +3705,130 @@ function getSilentSpinner() {
|
|
|
3241
3705
|
};
|
|
3242
3706
|
}
|
|
3243
3707
|
//#endregion
|
|
3244
|
-
//#region src/utils/
|
|
3245
|
-
function readYamlFile(file) {
|
|
3246
|
-
return (0, import_dist.parse)(fs.readFileSync(file, "utf-8"));
|
|
3247
|
-
}
|
|
3248
|
-
function editYamlFile(file, callback) {
|
|
3249
|
-
const doc = (0, import_dist.parseDocument)(fs.readFileSync(file, "utf-8"));
|
|
3250
|
-
callback(doc);
|
|
3251
|
-
fs.writeFileSync(file, doc.toString({ singleQuote: true }), "utf-8");
|
|
3252
|
-
}
|
|
3253
|
-
function scalarString(value) {
|
|
3254
|
-
return new import_dist.Scalar(value);
|
|
3255
|
-
}
|
|
3256
|
-
//#endregion
|
|
3257
|
-
//#region src/migration/detector.ts
|
|
3258
|
-
const PRETTIER_PACKAGE_JSON_CONFIG = "package.json#prettier";
|
|
3259
|
-
const PRETTIER_CONFIG_FILES = [
|
|
3260
|
-
".prettierrc",
|
|
3261
|
-
".prettierrc.json",
|
|
3262
|
-
".prettierrc.jsonc",
|
|
3263
|
-
".prettierrc.yaml",
|
|
3264
|
-
".prettierrc.yml",
|
|
3265
|
-
".prettierrc.toml",
|
|
3266
|
-
".prettierrc.js",
|
|
3267
|
-
".prettierrc.cjs",
|
|
3268
|
-
".prettierrc.mjs",
|
|
3269
|
-
".prettierrc.ts",
|
|
3270
|
-
".prettierrc.cts",
|
|
3271
|
-
".prettierrc.mts",
|
|
3272
|
-
"prettier.config.js",
|
|
3273
|
-
"prettier.config.cjs",
|
|
3274
|
-
"prettier.config.mjs",
|
|
3275
|
-
"prettier.config.ts",
|
|
3276
|
-
"prettier.config.cts",
|
|
3277
|
-
"prettier.config.mts"
|
|
3278
|
-
];
|
|
3279
|
-
function detectConfigs(projectPath) {
|
|
3280
|
-
const configs = {};
|
|
3281
|
-
for (const config of [
|
|
3282
|
-
"vite.config.ts",
|
|
3283
|
-
"vite.config.mts",
|
|
3284
|
-
"vite.config.cts",
|
|
3285
|
-
"vite.config.js",
|
|
3286
|
-
"vite.config.mjs",
|
|
3287
|
-
"vite.config.cjs"
|
|
3288
|
-
]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3289
|
-
configs.viteConfig = config;
|
|
3290
|
-
break;
|
|
3291
|
-
}
|
|
3292
|
-
for (const config of [
|
|
3293
|
-
"vitest.config.ts",
|
|
3294
|
-
"vitest.config.mts",
|
|
3295
|
-
"vitest.config.cts",
|
|
3296
|
-
"vitest.config.js",
|
|
3297
|
-
"vitest.config.mjs",
|
|
3298
|
-
"vitest.config.cjs"
|
|
3299
|
-
]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3300
|
-
configs.vitestConfig = config;
|
|
3301
|
-
break;
|
|
3302
|
-
}
|
|
3303
|
-
for (const config of [
|
|
3304
|
-
"tsdown.config.ts",
|
|
3305
|
-
"tsdown.config.mts",
|
|
3306
|
-
"tsdown.config.cts",
|
|
3307
|
-
"tsdown.config.js",
|
|
3308
|
-
"tsdown.config.mjs",
|
|
3309
|
-
"tsdown.config.cjs",
|
|
3310
|
-
"tsdown.config.json",
|
|
3311
|
-
"tsdown.config"
|
|
3312
|
-
]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3313
|
-
configs.tsdownConfig = config;
|
|
3314
|
-
break;
|
|
3315
|
-
}
|
|
3316
|
-
for (const config of [".oxlintrc.json", ".oxlintrc.jsonc"]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3317
|
-
configs.oxlintConfig = config;
|
|
3318
|
-
break;
|
|
3319
|
-
}
|
|
3320
|
-
for (const config of [".oxfmtrc.json", ".oxfmtrc.jsonc"]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3321
|
-
configs.oxfmtConfig = config;
|
|
3322
|
-
break;
|
|
3323
|
-
}
|
|
3324
|
-
for (const config of [
|
|
3325
|
-
"eslint.config.js",
|
|
3326
|
-
"eslint.config.mjs",
|
|
3327
|
-
"eslint.config.cjs",
|
|
3328
|
-
"eslint.config.ts",
|
|
3329
|
-
"eslint.config.mts",
|
|
3330
|
-
"eslint.config.cts"
|
|
3331
|
-
]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3332
|
-
configs.eslintConfig = config;
|
|
3333
|
-
break;
|
|
3334
|
-
}
|
|
3335
|
-
for (const config of [
|
|
3336
|
-
".eslintrc",
|
|
3337
|
-
".eslintrc.json",
|
|
3338
|
-
".eslintrc.js",
|
|
3339
|
-
".eslintrc.cjs",
|
|
3340
|
-
".eslintrc.yaml",
|
|
3341
|
-
".eslintrc.yml"
|
|
3342
|
-
]) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3343
|
-
configs.eslintLegacyConfig = config;
|
|
3344
|
-
break;
|
|
3345
|
-
}
|
|
3346
|
-
for (const config of PRETTIER_CONFIG_FILES) if (fs.existsSync(path.join(projectPath, config))) {
|
|
3347
|
-
configs.prettierConfig = config;
|
|
3348
|
-
break;
|
|
3349
|
-
}
|
|
3350
|
-
if (fs.existsSync(path.join(projectPath, ".prettierignore"))) configs.prettierIgnore = true;
|
|
3351
|
-
if (fs.existsSync(path.join(projectPath, ".nvmrc"))) configs.nvmrcFile = true;
|
|
3352
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
3353
|
-
if (fs.existsSync(packageJsonPath)) try {
|
|
3354
|
-
const content = fs.readFileSync(packageJsonPath, "utf8");
|
|
3355
|
-
const pkg = JSON.parse(content);
|
|
3356
|
-
if (!configs.prettierConfig && pkg.prettier) configs.prettierConfig = PRETTIER_PACKAGE_JSON_CONFIG;
|
|
3357
|
-
const voltaNode = pkg.volta?.node;
|
|
3358
|
-
if (typeof voltaNode === "string") configs.voltaNode = voltaNode;
|
|
3359
|
-
} catch {}
|
|
3360
|
-
return configs;
|
|
3361
|
-
}
|
|
3362
|
-
//#endregion
|
|
3363
|
-
//#region src/migration/migrator.ts
|
|
3364
|
-
const LINT_STAGED_JSON_CONFIG_FILES = [".lintstagedrc.json", ".lintstagedrc"];
|
|
3365
|
-
const LINT_STAGED_OTHER_CONFIG_FILES = [
|
|
3366
|
-
".lintstagedrc.yaml",
|
|
3367
|
-
".lintstagedrc.yml",
|
|
3368
|
-
".lintstagedrc.mjs",
|
|
3369
|
-
"lint-staged.config.mjs",
|
|
3370
|
-
".lintstagedrc.cjs",
|
|
3371
|
-
"lint-staged.config.cjs",
|
|
3372
|
-
".lintstagedrc.js",
|
|
3373
|
-
"lint-staged.config.js",
|
|
3374
|
-
".lintstagedrc.ts",
|
|
3375
|
-
"lint-staged.config.ts",
|
|
3376
|
-
".lintstagedrc.mts",
|
|
3377
|
-
"lint-staged.config.mts",
|
|
3378
|
-
".lintstagedrc.cts",
|
|
3379
|
-
"lint-staged.config.cts"
|
|
3380
|
-
];
|
|
3381
|
-
const LINT_STAGED_ALL_CONFIG_FILES = [...LINT_STAGED_JSON_CONFIG_FILES, ...LINT_STAGED_OTHER_CONFIG_FILES];
|
|
3382
|
-
const REMOVE_PACKAGES = [
|
|
3383
|
-
"oxlint",
|
|
3384
|
-
"oxlint-tsgolint",
|
|
3385
|
-
"oxfmt",
|
|
3386
|
-
"tsdown",
|
|
3387
|
-
"@vitest/browser",
|
|
3388
|
-
"@vitest/browser-preview",
|
|
3389
|
-
"@vitest/browser-playwright",
|
|
3390
|
-
"@vitest/browser-webdriverio"
|
|
3391
|
-
];
|
|
3392
|
-
const BROWSER_PROVIDER_PEER_DEPS = {
|
|
3393
|
-
"@vitest/browser-playwright": "playwright",
|
|
3394
|
-
"@vitest/browser-webdriverio": "webdriverio"
|
|
3395
|
-
};
|
|
3396
|
-
const PUBLIC_PEER_DEPENDENCY_FALLBACKS = {
|
|
3397
|
-
vite: "*",
|
|
3398
|
-
vitest: "*"
|
|
3399
|
-
};
|
|
3400
|
-
function warnMigration(message, report) {
|
|
3401
|
-
addMigrationWarning(report, message);
|
|
3402
|
-
if (!report) log.warn(message);
|
|
3403
|
-
}
|
|
3404
|
-
function infoMigration(message, report) {
|
|
3405
|
-
addManualStep(report, message);
|
|
3406
|
-
if (!report) log.info(message);
|
|
3407
|
-
}
|
|
3408
|
-
function checkViteVersion(projectPath) {
|
|
3409
|
-
return checkPackageVersion(projectPath, "vite", "7.0.0");
|
|
3410
|
-
}
|
|
3411
|
-
function checkVitestVersion(projectPath) {
|
|
3412
|
-
return checkPackageVersion(projectPath, "vitest", "4.0.0");
|
|
3413
|
-
}
|
|
3414
|
-
/**
|
|
3415
|
-
* Check the package version is supported by auto migration
|
|
3416
|
-
* @param projectPath - The path to the project
|
|
3417
|
-
* @param name - The name of the package
|
|
3418
|
-
* @param minVersion - The minimum version of the package
|
|
3419
|
-
* @returns true if the package version is supported by auto migration
|
|
3420
|
-
*/
|
|
3421
|
-
function checkPackageVersion(projectPath, name, minVersion) {
|
|
3422
|
-
const metadata = detectPackageMetadata(projectPath, name);
|
|
3423
|
-
if (!metadata || metadata.name !== name) return true;
|
|
3424
|
-
if (import_semver.default.satisfies(metadata.version, `<${minVersion}`)) {
|
|
3425
|
-
const packageJsonFilePath = path.join(projectPath, "package.json");
|
|
3426
|
-
log.error(`✘ ${name}@${metadata.version} in ${displayRelative(packageJsonFilePath)} is not supported by auto migration`);
|
|
3427
|
-
log.info(`Please upgrade ${name} to version >=${minVersion} first`);
|
|
3428
|
-
return false;
|
|
3429
|
-
}
|
|
3430
|
-
return true;
|
|
3431
|
-
}
|
|
3432
|
-
function detectEslintProject(projectPath, packages) {
|
|
3433
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
3434
|
-
if (!fs.existsSync(packageJsonPath)) return { hasDependency: false };
|
|
3435
|
-
const pkg = readJsonFile(packageJsonPath);
|
|
3436
|
-
let hasDependency = !!(pkg.devDependencies?.eslint || pkg.dependencies?.eslint);
|
|
3437
|
-
const configs = detectConfigs(projectPath);
|
|
3438
|
-
let configFile = configs.eslintConfig;
|
|
3439
|
-
const legacyConfigFile = configs.eslintLegacyConfig;
|
|
3440
|
-
if (!hasDependency && packages) for (const wp of packages) {
|
|
3441
|
-
const pkgJsonPath = path.join(projectPath, wp.path, "package.json");
|
|
3442
|
-
if (!fs.existsSync(pkgJsonPath)) continue;
|
|
3443
|
-
const wpPkg = readJsonFile(pkgJsonPath);
|
|
3444
|
-
if (wpPkg.devDependencies?.eslint || wpPkg.dependencies?.eslint) {
|
|
3445
|
-
hasDependency = true;
|
|
3446
|
-
break;
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
return {
|
|
3450
|
-
hasDependency,
|
|
3451
|
-
configFile,
|
|
3452
|
-
legacyConfigFile
|
|
3453
|
-
};
|
|
3454
|
-
}
|
|
3708
|
+
//#region src/utils/tsconfig.ts
|
|
3455
3709
|
/**
|
|
3456
|
-
*
|
|
3457
|
-
*
|
|
3710
|
+
* Check if tsconfig.json has compilerOptions.baseUrl set.
|
|
3711
|
+
* oxlint's TypeScript checker (tsgolint) does not support baseUrl,
|
|
3712
|
+
* so typeAware/typeCheck must be disabled when it is present.
|
|
3458
3713
|
*/
|
|
3459
|
-
|
|
3714
|
+
function hasBaseUrlInTsconfigFile(filePath) {
|
|
3460
3715
|
try {
|
|
3461
|
-
|
|
3462
|
-
command: vpBin,
|
|
3463
|
-
args: [
|
|
3464
|
-
"dlx",
|
|
3465
|
-
migratePackage,
|
|
3466
|
-
...args
|
|
3467
|
-
],
|
|
3468
|
-
cwd,
|
|
3469
|
-
envs: process.env
|
|
3470
|
-
});
|
|
3471
|
-
if (result.exitCode !== 0) {
|
|
3472
|
-
spinner.stop(failMessage);
|
|
3473
|
-
const stderr = result.stderr.toString().trim();
|
|
3474
|
-
if (stderr) log.warn(`⚠ ${stderr}`);
|
|
3475
|
-
log.info(manualHint);
|
|
3476
|
-
return false;
|
|
3477
|
-
}
|
|
3478
|
-
return true;
|
|
3716
|
+
return parse(fs.readFileSync(filePath, "utf-8"))?.compilerOptions?.baseUrl != null;
|
|
3479
3717
|
} catch {
|
|
3480
|
-
spinner.stop(failMessage);
|
|
3481
|
-
log.info(manualHint);
|
|
3482
3718
|
return false;
|
|
3483
3719
|
}
|
|
3484
3720
|
}
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
const spinner = options?.silent ? {
|
|
3488
|
-
start: () => {},
|
|
3489
|
-
stop: () => {},
|
|
3490
|
-
pause: () => {},
|
|
3491
|
-
resume: () => {},
|
|
3492
|
-
cancel: () => {},
|
|
3493
|
-
error: () => {},
|
|
3494
|
-
clear: () => {},
|
|
3495
|
-
message: () => {},
|
|
3496
|
-
isCancelled: false
|
|
3497
|
-
} : getSpinner(interactive);
|
|
3498
|
-
if (eslintConfigFile) {
|
|
3499
|
-
const { versions } = await import("./versions.js");
|
|
3500
|
-
const migratePackage = `@oxlint/migrate@${versions.oxlint}`;
|
|
3501
|
-
spinner.start("Migrating ESLint config to Oxlint...");
|
|
3502
|
-
if (!await runOxlintMigrateStep(vpBin, projectPath, migratePackage, [
|
|
3503
|
-
"--merge",
|
|
3504
|
-
"--type-aware",
|
|
3505
|
-
"--with-nursery",
|
|
3506
|
-
"--details"
|
|
3507
|
-
], spinner, "ESLint migration failed", `You can run \`vp dlx ${migratePackage} --merge --type-aware --with-nursery --details\` manually later`)) return false;
|
|
3508
|
-
spinner.stop("ESLint config migrated to .oxlintrc.json");
|
|
3509
|
-
spinner.start("Replacing ESLint comments with Oxlint equivalents...");
|
|
3510
|
-
if (await runOxlintMigrateStep(vpBin, projectPath, migratePackage, ["--replace-eslint-comments"], spinner, "ESLint comment replacement failed", `You can run \`vp dlx ${migratePackage} --replace-eslint-comments\` manually later`)) spinner.stop("ESLint comments replaced");
|
|
3511
|
-
}
|
|
3512
|
-
if (options?.report) options.report.eslintMigrated = true;
|
|
3513
|
-
deleteEslintConfigFiles(projectPath, options?.report, options?.silent);
|
|
3514
|
-
rewriteEslintPackageJson(path.join(projectPath, "package.json"));
|
|
3515
|
-
if (packages) for (const pkg of packages) rewriteEslintPackageJson(path.join(projectPath, pkg.path, "package.json"));
|
|
3516
|
-
rewriteEslintLintStagedConfigFiles(projectPath, options?.report);
|
|
3517
|
-
return true;
|
|
3518
|
-
}
|
|
3519
|
-
function deleteEslintConfigFiles(basePath, report, silent = false) {
|
|
3520
|
-
const configs = detectConfigs(basePath);
|
|
3521
|
-
for (const file of [configs.eslintConfig, configs.eslintLegacyConfig]) if (file) {
|
|
3522
|
-
const configPath = path.join(basePath, file);
|
|
3523
|
-
if (fs.existsSync(configPath)) {
|
|
3524
|
-
fs.unlinkSync(configPath);
|
|
3525
|
-
if (report) report.removedConfigCount++;
|
|
3526
|
-
if (!silent) log.success(`✔ Removed ${displayRelative(configPath)}`);
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3529
|
-
}
|
|
3530
|
-
function rewriteEslintPackageJson(packageJsonPath) {
|
|
3531
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
3532
|
-
let changed = false;
|
|
3533
|
-
if (pkg.devDependencies?.eslint) {
|
|
3534
|
-
delete pkg.devDependencies.eslint;
|
|
3535
|
-
changed = true;
|
|
3536
|
-
}
|
|
3537
|
-
if (pkg.dependencies?.eslint) {
|
|
3538
|
-
delete pkg.dependencies.eslint;
|
|
3539
|
-
changed = true;
|
|
3540
|
-
}
|
|
3541
|
-
if (pkg.scripts) {
|
|
3542
|
-
const updated = rewriteEslint(JSON.stringify(pkg.scripts));
|
|
3543
|
-
if (updated) {
|
|
3544
|
-
pkg.scripts = JSON.parse(updated);
|
|
3545
|
-
changed = true;
|
|
3546
|
-
}
|
|
3547
|
-
}
|
|
3548
|
-
if (pkg["lint-staged"]) {
|
|
3549
|
-
const updated = rewriteEslint(JSON.stringify(pkg["lint-staged"]));
|
|
3550
|
-
if (updated) {
|
|
3551
|
-
pkg["lint-staged"] = JSON.parse(updated);
|
|
3552
|
-
changed = true;
|
|
3553
|
-
}
|
|
3554
|
-
}
|
|
3555
|
-
return changed ? pkg : void 0;
|
|
3556
|
-
});
|
|
3557
|
-
}
|
|
3558
|
-
/**
|
|
3559
|
-
* Rewrite tool references in lint-staged config files (JSON ones are rewritten,
|
|
3560
|
-
* non-JSON ones get a warning).
|
|
3561
|
-
*/
|
|
3562
|
-
function rewriteToolLintStagedConfigFiles(projectPath, rewriteFn, toolName, report) {
|
|
3563
|
-
for (const filename of LINT_STAGED_JSON_CONFIG_FILES) {
|
|
3564
|
-
const configPath = path.join(projectPath, filename);
|
|
3565
|
-
if (!fs.existsSync(configPath)) continue;
|
|
3566
|
-
if (filename === ".lintstagedrc" && !isJsonFile(configPath)) {
|
|
3567
|
-
warnMigration(`${displayRelative(configPath)} is not JSON — please update ${toolName} references manually`, report);
|
|
3568
|
-
continue;
|
|
3569
|
-
}
|
|
3570
|
-
editJsonFile(configPath, (config) => {
|
|
3571
|
-
const updated = rewriteFn(JSON.stringify(config));
|
|
3572
|
-
if (updated) return JSON.parse(updated);
|
|
3573
|
-
});
|
|
3574
|
-
}
|
|
3575
|
-
for (const filename of LINT_STAGED_OTHER_CONFIG_FILES) {
|
|
3576
|
-
const configPath = path.join(projectPath, filename);
|
|
3577
|
-
if (!fs.existsSync(configPath)) continue;
|
|
3578
|
-
warnMigration(`${displayRelative(configPath)} — please update ${toolName} references manually`, report);
|
|
3579
|
-
}
|
|
3580
|
-
}
|
|
3581
|
-
function rewriteEslintLintStagedConfigFiles(projectPath, report) {
|
|
3582
|
-
rewriteToolLintStagedConfigFiles(projectPath, rewriteEslint, "eslint", report);
|
|
3583
|
-
}
|
|
3584
|
-
function detectPrettierProject(projectPath, packages) {
|
|
3585
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
3586
|
-
if (!fs.existsSync(packageJsonPath)) return { hasDependency: false };
|
|
3587
|
-
const pkg = readJsonFile(packageJsonPath);
|
|
3588
|
-
let hasDependency = !!(pkg.devDependencies?.prettier || pkg.dependencies?.prettier);
|
|
3589
|
-
const configFile = detectConfigs(projectPath).prettierConfig;
|
|
3590
|
-
if (!hasDependency && packages) for (const wp of packages) {
|
|
3591
|
-
const pkgJsonPath = path.join(projectPath, wp.path, "package.json");
|
|
3592
|
-
if (!fs.existsSync(pkgJsonPath)) continue;
|
|
3593
|
-
const wpPkg = readJsonFile(pkgJsonPath);
|
|
3594
|
-
if (wpPkg.devDependencies?.prettier || wpPkg.dependencies?.prettier) {
|
|
3595
|
-
hasDependency = true;
|
|
3596
|
-
break;
|
|
3597
|
-
}
|
|
3598
|
-
}
|
|
3599
|
-
return {
|
|
3600
|
-
hasDependency,
|
|
3601
|
-
configFile
|
|
3602
|
-
};
|
|
3603
|
-
}
|
|
3604
|
-
/**
|
|
3605
|
-
* Run `vp fmt --migrate=prettier` step with graceful error handling.
|
|
3606
|
-
* Returns true on success, false on failure.
|
|
3607
|
-
*/
|
|
3608
|
-
async function runPrettierMigrateStep(vpBin, cwd, spinner, failMessage, manualHint) {
|
|
3721
|
+
const TSCONFIG_FILE_RE = /^tsconfig(\.[\w-]+)?\.json$/i;
|
|
3722
|
+
function findTsconfigFiles(projectPath) {
|
|
3609
3723
|
try {
|
|
3610
|
-
|
|
3611
|
-
command: vpBin,
|
|
3612
|
-
args: ["fmt", "--migrate=prettier"],
|
|
3613
|
-
cwd,
|
|
3614
|
-
envs: process.env
|
|
3615
|
-
});
|
|
3616
|
-
if (result.exitCode !== 0) {
|
|
3617
|
-
spinner.stop(failMessage);
|
|
3618
|
-
const stderr = result.stderr.toString().trim();
|
|
3619
|
-
if (stderr) log.warn(`⚠ ${stderr}`);
|
|
3620
|
-
log.info(manualHint);
|
|
3621
|
-
return false;
|
|
3622
|
-
}
|
|
3623
|
-
return true;
|
|
3724
|
+
return fs.readdirSync(projectPath).filter((name) => TSCONFIG_FILE_RE.test(name)).map((name) => path.join(projectPath, name));
|
|
3624
3725
|
} catch {
|
|
3625
|
-
|
|
3626
|
-
log.info(manualHint);
|
|
3627
|
-
return false;
|
|
3726
|
+
return [];
|
|
3628
3727
|
}
|
|
3629
3728
|
}
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
const spinner = options?.silent ? {
|
|
3633
|
-
start: () => {},
|
|
3634
|
-
stop: () => {},
|
|
3635
|
-
pause: () => {},
|
|
3636
|
-
resume: () => {},
|
|
3637
|
-
cancel: () => {},
|
|
3638
|
-
error: () => {},
|
|
3639
|
-
clear: () => {},
|
|
3640
|
-
message: () => {},
|
|
3641
|
-
isCancelled: false
|
|
3642
|
-
} : getSpinner(interactive);
|
|
3643
|
-
if (prettierConfigFile) {
|
|
3644
|
-
let tempPrettierConfig;
|
|
3645
|
-
if (prettierConfigFile === "package.json#prettier") {
|
|
3646
|
-
const pkg = readJsonFile(path.join(projectPath, "package.json"));
|
|
3647
|
-
if (pkg.prettier) {
|
|
3648
|
-
tempPrettierConfig = path.join(projectPath, ".prettierrc.json");
|
|
3649
|
-
fs.writeFileSync(tempPrettierConfig, JSON.stringify(pkg.prettier, null, 2));
|
|
3650
|
-
} else return true;
|
|
3651
|
-
}
|
|
3652
|
-
try {
|
|
3653
|
-
spinner.start("Migrating Prettier config to Oxfmt...");
|
|
3654
|
-
if (!await runPrettierMigrateStep(vpBin, projectPath, spinner, "Prettier migration failed", "You can run `vp fmt --migrate=prettier` manually later")) return false;
|
|
3655
|
-
spinner.stop("Prettier config migrated to .oxfmtrc.json");
|
|
3656
|
-
} finally {
|
|
3657
|
-
if (tempPrettierConfig) try {
|
|
3658
|
-
fs.unlinkSync(tempPrettierConfig);
|
|
3659
|
-
} catch {}
|
|
3660
|
-
}
|
|
3661
|
-
}
|
|
3662
|
-
if (options?.report) options.report.prettierMigrated = true;
|
|
3663
|
-
deletePrettierConfigFiles(projectPath, options?.report, options?.silent);
|
|
3664
|
-
rewritePrettierPackageJson(path.join(projectPath, "package.json"));
|
|
3665
|
-
if (packages) for (const pkg of packages) rewritePrettierPackageJson(path.join(projectPath, pkg.path, "package.json"));
|
|
3666
|
-
rewritePrettierLintStagedConfigFiles(projectPath, options?.report);
|
|
3667
|
-
const prettierIgnorePath = path.join(projectPath, ".prettierignore");
|
|
3668
|
-
if (fs.existsSync(prettierIgnorePath)) warnMigration(`${displayRelative(prettierIgnorePath)} found — Oxfmt supports .prettierignore, but using the \`ignorePatterns\` option is recommended.`, options?.report);
|
|
3669
|
-
return true;
|
|
3729
|
+
function hasBaseUrlInTsconfig(projectPath) {
|
|
3730
|
+
return findTsconfigFiles(projectPath).some((filePath) => hasBaseUrlInTsconfigFile(filePath));
|
|
3670
3731
|
}
|
|
3671
|
-
function
|
|
3672
|
-
|
|
3673
|
-
if (configs.prettierConfig && configs.prettierConfig !== "package.json#prettier") {
|
|
3674
|
-
const configPath = path.join(basePath, configs.prettierConfig);
|
|
3675
|
-
if (fs.existsSync(configPath)) {
|
|
3676
|
-
fs.unlinkSync(configPath);
|
|
3677
|
-
if (report) report.removedConfigCount++;
|
|
3678
|
-
if (!silent) log.success(`✔ Removed ${displayRelative(configPath)}`);
|
|
3679
|
-
}
|
|
3680
|
-
}
|
|
3681
|
-
for (const file of PRETTIER_CONFIG_FILES) {
|
|
3682
|
-
if (file === configs.prettierConfig) continue;
|
|
3683
|
-
const configPath = path.join(basePath, file);
|
|
3684
|
-
if (fs.existsSync(configPath)) {
|
|
3685
|
-
fs.unlinkSync(configPath);
|
|
3686
|
-
if (report) report.removedConfigCount++;
|
|
3687
|
-
if (!silent) log.success(`✔ Removed ${displayRelative(configPath)}`);
|
|
3688
|
-
}
|
|
3689
|
-
}
|
|
3690
|
-
editJsonFile(path.join(basePath, "package.json"), (pkg) => {
|
|
3691
|
-
if (pkg.prettier) {
|
|
3692
|
-
delete pkg.prettier;
|
|
3693
|
-
return pkg;
|
|
3694
|
-
}
|
|
3695
|
-
});
|
|
3732
|
+
function findTsconfigFilesWithBaseUrl(projectPath) {
|
|
3733
|
+
return findTsconfigFiles(projectPath).filter((filePath) => hasBaseUrlInTsconfigFile(filePath));
|
|
3696
3734
|
}
|
|
3697
|
-
function
|
|
3698
|
-
if (!
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
delete pkg.devDependencies[dep];
|
|
3704
|
-
changed = true;
|
|
3705
|
-
}
|
|
3706
|
-
}
|
|
3707
|
-
if (pkg.dependencies) {
|
|
3708
|
-
for (const dep of Object.keys(pkg.dependencies)) if (dep === "prettier" || dep.startsWith("prettier-plugin-")) {
|
|
3709
|
-
delete pkg.dependencies[dep];
|
|
3710
|
-
changed = true;
|
|
3711
|
-
}
|
|
3712
|
-
}
|
|
3713
|
-
if (pkg.scripts) {
|
|
3714
|
-
const updated = rewritePrettier(JSON.stringify(pkg.scripts));
|
|
3715
|
-
if (updated) {
|
|
3716
|
-
pkg.scripts = JSON.parse(updated);
|
|
3717
|
-
changed = true;
|
|
3718
|
-
}
|
|
3719
|
-
}
|
|
3720
|
-
if (pkg["lint-staged"]) {
|
|
3721
|
-
const updated = rewritePrettier(JSON.stringify(pkg["lint-staged"]));
|
|
3722
|
-
if (updated) {
|
|
3723
|
-
pkg["lint-staged"] = JSON.parse(updated);
|
|
3724
|
-
changed = true;
|
|
3725
|
-
}
|
|
3726
|
-
}
|
|
3727
|
-
return changed ? pkg : void 0;
|
|
3735
|
+
async function confirmBaseUrlFix(interactive) {
|
|
3736
|
+
if (!interactive) return true;
|
|
3737
|
+
const command = [BASEURL_TSCONFIG_FIX_PACKAGE, ...createBaseUrlTsconfigFixArgs("<tsconfig path>")].join(" ");
|
|
3738
|
+
const confirmed = await confirm({
|
|
3739
|
+
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}\``),
|
|
3740
|
+
initialValue: true
|
|
3728
3741
|
});
|
|
3742
|
+
if (R(confirmed)) cancelAndExit();
|
|
3743
|
+
return confirmed;
|
|
3729
3744
|
}
|
|
3730
|
-
function
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
for (const filePath of files) for (const name of deprecatedOptions) if (removeDeprecatedTsconfigFalseOption(filePath, name)) {
|
|
3737
|
-
if (report) report.removedConfigCount++;
|
|
3738
|
-
if (!silent) log.success(`✔ Removed ${name}: false from ${displayRelative(filePath)}`);
|
|
3739
|
-
warnMigration(`Removed \`"${name}": false\` from ${displayRelative(filePath)} — this option has been deprecated. See https://github.com/oxc-project/tsgolint/issues/351, https://github.com/microsoft/TypeScript/issues/62529`, report);
|
|
3740
|
-
}
|
|
3741
|
-
}
|
|
3742
|
-
function rewriteTsconfigTypes(projectPath, silent = false, report) {
|
|
3743
|
-
const files = findTsconfigFiles(projectPath);
|
|
3744
|
-
for (const filePath of files) if (rewriteTypesInTsconfig(filePath)) {
|
|
3745
|
-
if (report) report.removedConfigCount++;
|
|
3746
|
-
if (!silent) log.success(`✔ Rewrote types in ${displayRelative(filePath)}`);
|
|
3747
|
-
}
|
|
3748
|
-
}
|
|
3749
|
-
const FRAMEWORK_SHIMS = {
|
|
3750
|
-
vue: [
|
|
3751
|
-
"declare module '*.vue' {",
|
|
3752
|
-
" import type { DefineComponent } from 'vue';",
|
|
3753
|
-
" const component: DefineComponent<{}, {}, unknown>;",
|
|
3754
|
-
" export default component;",
|
|
3755
|
-
"}"
|
|
3756
|
-
].join("\n"),
|
|
3757
|
-
astro: "/// <reference types=\"astro/client\" />"
|
|
3758
|
-
};
|
|
3759
|
-
function detectFramework(projectPath) {
|
|
3760
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
3761
|
-
if (!fs.existsSync(packageJsonPath)) return [];
|
|
3762
|
-
const pkg = readJsonFile(packageJsonPath);
|
|
3763
|
-
const allDeps = {
|
|
3764
|
-
...pkg.dependencies,
|
|
3765
|
-
...pkg.devDependencies
|
|
3766
|
-
};
|
|
3767
|
-
return ["vue", "astro"].filter((framework) => !!allDeps[framework]);
|
|
3768
|
-
}
|
|
3769
|
-
function getEnvDtsPath(projectPath) {
|
|
3770
|
-
const srcEnvDts = path.join(projectPath, "src", "env.d.ts");
|
|
3771
|
-
const rootEnvDts = path.join(projectPath, "env.d.ts");
|
|
3772
|
-
for (const candidate of [srcEnvDts, rootEnvDts]) if (fs.existsSync(candidate)) return candidate;
|
|
3773
|
-
return fs.existsSync(path.join(projectPath, "src")) ? srcEnvDts : rootEnvDts;
|
|
3774
|
-
}
|
|
3775
|
-
function hasFrameworkShim(projectPath, framework) {
|
|
3776
|
-
const dirsToScan = [projectPath, path.join(projectPath, "src")];
|
|
3777
|
-
for (const dir of dirsToScan) {
|
|
3778
|
-
if (!fs.existsSync(dir)) continue;
|
|
3779
|
-
let entries;
|
|
3780
|
-
try {
|
|
3781
|
-
entries = fs.readdirSync(dir);
|
|
3782
|
-
} catch {
|
|
3783
|
-
continue;
|
|
3784
|
-
}
|
|
3785
|
-
for (const entry of entries) {
|
|
3786
|
-
if (!entry.endsWith(".d.ts")) continue;
|
|
3787
|
-
const content = fs.readFileSync(path.join(dir, entry), "utf-8");
|
|
3788
|
-
if (framework === "astro") {
|
|
3789
|
-
if (content.includes("astro/client")) return true;
|
|
3790
|
-
} else if (content.includes(`'*.${framework}'`) || content.includes(`"*.${framework}"`)) return true;
|
|
3791
|
-
}
|
|
3792
|
-
}
|
|
3793
|
-
return false;
|
|
3794
|
-
}
|
|
3795
|
-
function addFrameworkShim(projectPath, framework, report) {
|
|
3796
|
-
const envDtsPath = getEnvDtsPath(projectPath);
|
|
3797
|
-
const shim = FRAMEWORK_SHIMS[framework];
|
|
3798
|
-
if (fs.existsSync(envDtsPath)) {
|
|
3799
|
-
const existing = fs.readFileSync(envDtsPath, "utf-8");
|
|
3800
|
-
fs.writeFileSync(envDtsPath, `${existing.trimEnd()}\n\n${shim}\n`, "utf-8");
|
|
3801
|
-
} else {
|
|
3802
|
-
fs.mkdirSync(path.dirname(envDtsPath), { recursive: true });
|
|
3803
|
-
fs.writeFileSync(envDtsPath, `${shim}\n`, "utf-8");
|
|
3745
|
+
async function fixBaseUrlInTsconfig(projectPath, options) {
|
|
3746
|
+
const files = findTsconfigFilesWithBaseUrl(projectPath);
|
|
3747
|
+
if (files.length === 0) return "not-needed";
|
|
3748
|
+
if (!(options?.confirmed ?? await confirmBaseUrlFix(options?.interactive ?? false))) {
|
|
3749
|
+
options?.onStatus?.("declined", projectPath);
|
|
3750
|
+
return "declined";
|
|
3804
3751
|
}
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
...pkg.resolutions,
|
|
3824
|
-
...VITE_PLUS_OVERRIDE_PACKAGES
|
|
3825
|
-
};
|
|
3826
|
-
else if (packageManager === PackageManager.npm || packageManager === PackageManager.bun) pkg.overrides = {
|
|
3827
|
-
...pkg.overrides,
|
|
3828
|
-
...VITE_PLUS_OVERRIDE_PACKAGES
|
|
3829
|
-
};
|
|
3830
|
-
else if (packageManager === PackageManager.pnpm) {
|
|
3831
|
-
usePnpmWorkspaceYaml = !pkg.pnpm;
|
|
3832
|
-
if (usePnpmWorkspaceYaml) {
|
|
3833
|
-
shouldRewritePnpmWorkspaceYaml = true;
|
|
3834
|
-
shouldAddPnpmWorkspaceVitePlusOverride = isForceOverrideMode();
|
|
3835
|
-
}
|
|
3836
|
-
const overrideKeys = Object.keys(VITE_PLUS_OVERRIDE_PACKAGES);
|
|
3837
|
-
if (!usePnpmWorkspaceYaml) pkg.pnpm = {
|
|
3838
|
-
...pkg.pnpm,
|
|
3839
|
-
overrides: {
|
|
3840
|
-
...pkg.pnpm?.overrides,
|
|
3841
|
-
...VITE_PLUS_OVERRIDE_PACKAGES,
|
|
3842
|
-
...isForceOverrideMode() ? { [VITE_PLUS_NAME]: VITE_PLUS_VERSION } : {}
|
|
3843
|
-
},
|
|
3844
|
-
peerDependencyRules: {
|
|
3845
|
-
...pkg.pnpm?.peerDependencyRules,
|
|
3846
|
-
allowAny: [...new Set([...pkg.pnpm?.peerDependencyRules?.allowAny ?? [], ...overrideKeys])],
|
|
3847
|
-
allowedVersions: {
|
|
3848
|
-
...pkg.pnpm?.peerDependencyRules?.allowedVersions,
|
|
3849
|
-
...Object.fromEntries(overrideKeys.map((key) => [key, "*"]))
|
|
3850
|
-
}
|
|
3752
|
+
try {
|
|
3753
|
+
for (const filePath of files) {
|
|
3754
|
+
const fixArgs = createBaseUrlTsconfigFixArgs(path.relative(projectPath, filePath) || filePath);
|
|
3755
|
+
if (!options?.silent) log.info(`Running vp dlx ${BASEURL_TSCONFIG_FIX_PACKAGE} ${fixArgs.join(" ")}`);
|
|
3756
|
+
const result = await runCommandSilently({
|
|
3757
|
+
command: process.env.VP_CLI_BIN ?? "vp",
|
|
3758
|
+
args: [
|
|
3759
|
+
"dlx",
|
|
3760
|
+
BASEURL_TSCONFIG_FIX_PACKAGE,
|
|
3761
|
+
...fixArgs
|
|
3762
|
+
],
|
|
3763
|
+
cwd: projectPath,
|
|
3764
|
+
envs: process.env
|
|
3765
|
+
});
|
|
3766
|
+
if (result.exitCode !== 0) {
|
|
3767
|
+
if (!options?.silent) {
|
|
3768
|
+
const output = `${result.stdout.toString()}${result.stderr.toString()}`.trim();
|
|
3769
|
+
if (output) log.warn(output);
|
|
3851
3770
|
}
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
for (const key in pkg.pnpm?.overrides) if (key.includes(">")) {
|
|
3855
|
-
const splits = key.split(">");
|
|
3856
|
-
if (splits[splits.length - 1].trim() === "vite") delete pkg.pnpm.overrides[key];
|
|
3771
|
+
options?.onStatus?.("failed", projectPath);
|
|
3772
|
+
return "failed";
|
|
3857
3773
|
}
|
|
3858
|
-
for (const key of [...overrideKeys, ...REMOVE_PACKAGES]) if (pkg.resolutions?.[key]) delete pkg.resolutions[key];
|
|
3859
3774
|
}
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
...pkg.devDependencies,
|
|
3865
|
-
[VITE_PLUS_NAME]: version
|
|
3866
|
-
};
|
|
3775
|
+
if (hasBaseUrlInTsconfig(projectPath)) {
|
|
3776
|
+
if (!options?.silent) log.warn("tsconfig still contains baseUrl after running the fixer.");
|
|
3777
|
+
options?.onStatus?.("failed", projectPath);
|
|
3778
|
+
return "failed";
|
|
3867
3779
|
}
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
if (shouldAddPnpmWorkspaceVitePlusOverride) migratePnpmOverridesToWorkspaceYaml(projectPath, { [VITE_PLUS_NAME]: VITE_PLUS_VERSION });
|
|
3873
|
-
if (packageManager === PackageManager.yarn) rewriteYarnrcYml(projectPath);
|
|
3874
|
-
if (extractedStagedConfig) {
|
|
3875
|
-
if (mergeStagedConfigToViteConfig(projectPath, extractedStagedConfig, silent, report)) removeLintStagedFromPackageJson(packageJsonPath);
|
|
3780
|
+
} catch (error) {
|
|
3781
|
+
if (!options?.silent && error instanceof Error) log.warn(error.message);
|
|
3782
|
+
options?.onStatus?.("failed", projectPath);
|
|
3783
|
+
return "failed";
|
|
3876
3784
|
}
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
rewriteTsconfigTypes(projectPath, silent, report);
|
|
3880
|
-
mergeViteConfigFiles(projectPath, silent, report);
|
|
3881
|
-
injectLintTypeCheckDefaults(projectPath, silent, report);
|
|
3882
|
-
injectFmtDefaults(projectPath, silent, report);
|
|
3883
|
-
mergeTsdownConfigFile(projectPath, silent, report);
|
|
3884
|
-
rewriteAllImports(projectPath, silent, report);
|
|
3885
|
-
setPackageManager(projectPath, workspaceInfo.downloadPackageManager);
|
|
3886
|
-
}
|
|
3887
|
-
/**
|
|
3888
|
-
* Rewrite monorepo to add vite-plus dependencies
|
|
3889
|
-
* @param workspaceInfo - The workspace info
|
|
3890
|
-
*/
|
|
3891
|
-
function rewriteMonorepo(workspaceInfo, skipStagedMigration, silent = false, report) {
|
|
3892
|
-
const catalogDependencyResolver = createCatalogDependencyResolver(workspaceInfo.rootDir, workspaceInfo.packageManager);
|
|
3893
|
-
if (workspaceInfo.packageManager === PackageManager.pnpm) rewritePnpmWorkspaceYaml(workspaceInfo.rootDir);
|
|
3894
|
-
else if (workspaceInfo.packageManager === PackageManager.yarn) rewriteYarnrcYml(workspaceInfo.rootDir);
|
|
3895
|
-
else if (workspaceInfo.packageManager === PackageManager.bun) rewriteBunCatalog(workspaceInfo.rootDir);
|
|
3896
|
-
rewriteRootWorkspacePackageJson(workspaceInfo.rootDir, workspaceInfo.packageManager, skipStagedMigration, catalogDependencyResolver);
|
|
3897
|
-
for (const pkg of workspaceInfo.packages) rewriteMonorepoProject(path.join(workspaceInfo.rootDir, pkg.path), workspaceInfo.packageManager, skipStagedMigration, silent, report, catalogDependencyResolver);
|
|
3898
|
-
if (!skipStagedMigration) rewriteLintStagedConfigFile(workspaceInfo.rootDir, report);
|
|
3899
|
-
cleanupDeprecatedTsconfigOptions(workspaceInfo.rootDir, silent, report);
|
|
3900
|
-
rewriteTsconfigTypes(workspaceInfo.rootDir, silent, report);
|
|
3901
|
-
mergeViteConfigFiles(workspaceInfo.rootDir, silent, report);
|
|
3902
|
-
injectLintTypeCheckDefaults(workspaceInfo.rootDir, silent, report);
|
|
3903
|
-
injectFmtDefaults(workspaceInfo.rootDir, silent, report);
|
|
3904
|
-
mergeTsdownConfigFile(workspaceInfo.rootDir, silent, report);
|
|
3905
|
-
rewriteAllImports(workspaceInfo.rootDir, silent, report);
|
|
3906
|
-
setPackageManager(workspaceInfo.rootDir, workspaceInfo.downloadPackageManager);
|
|
3785
|
+
options?.onStatus?.("fixed", projectPath);
|
|
3786
|
+
return "fixed";
|
|
3907
3787
|
}
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
rewriteTsconfigTypes(projectPath, silent, report);
|
|
3915
|
-
mergeViteConfigFiles(projectPath, silent, report);
|
|
3916
|
-
mergeTsdownConfigFile(projectPath, silent, report);
|
|
3917
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
3918
|
-
if (!fs.existsSync(packageJsonPath)) return;
|
|
3919
|
-
let extractedStagedConfig = null;
|
|
3920
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
3921
|
-
extractedStagedConfig = rewritePackageJson(pkg, packageManager, true, skipStagedMigration, catalogDependencyResolver);
|
|
3922
|
-
return pkg;
|
|
3923
|
-
});
|
|
3924
|
-
if (extractedStagedConfig) {
|
|
3925
|
-
if (mergeStagedConfigToViteConfig(projectPath, extractedStagedConfig, silent, report)) removeLintStagedFromPackageJson(packageJsonPath);
|
|
3788
|
+
function removeDeprecatedTsconfigFalseOption(filePath, optionName) {
|
|
3789
|
+
let text;
|
|
3790
|
+
try {
|
|
3791
|
+
text = fs.readFileSync(filePath, "utf-8");
|
|
3792
|
+
} catch {
|
|
3793
|
+
return false;
|
|
3926
3794
|
}
|
|
3795
|
+
if (parse(text)?.compilerOptions?.[optionName] !== false) return false;
|
|
3796
|
+
const edits = modify(text, ["compilerOptions", optionName], void 0, {});
|
|
3797
|
+
if (edits.length === 0) return false;
|
|
3798
|
+
const newText = applyEdits(text, edits);
|
|
3799
|
+
fs.writeFileSync(filePath, newText);
|
|
3800
|
+
return true;
|
|
3927
3801
|
}
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
* @param projectPath - The path to the project
|
|
3931
|
-
*/
|
|
3932
|
-
function rewritePnpmWorkspaceYaml(projectPath) {
|
|
3933
|
-
const pnpmWorkspaceYamlPath = path.join(projectPath, "pnpm-workspace.yaml");
|
|
3934
|
-
if (!fs.existsSync(pnpmWorkspaceYamlPath)) fs.writeFileSync(pnpmWorkspaceYamlPath, "");
|
|
3935
|
-
editYamlFile(pnpmWorkspaceYamlPath, (doc) => {
|
|
3936
|
-
rewriteCatalog(doc);
|
|
3937
|
-
const overrides = doc.getIn(["overrides"]);
|
|
3938
|
-
for (const key of Object.keys(VITE_PLUS_OVERRIDE_PACKAGES)) {
|
|
3939
|
-
const version = getCatalogDependencySpec(getYamlMapScalarStringValue(overrides, key), VITE_PLUS_OVERRIDE_PACKAGES[key], true);
|
|
3940
|
-
doc.setIn(["overrides", scalarString(key)], scalarString(version));
|
|
3941
|
-
}
|
|
3942
|
-
const updatedOverrides = doc.getIn(["overrides"]);
|
|
3943
|
-
for (const item of updatedOverrides.items) if (item.key.value.includes(">")) {
|
|
3944
|
-
const splits = item.key.value.split(">");
|
|
3945
|
-
if (splits[splits.length - 1].trim() === "vite") updatedOverrides.delete(item.key);
|
|
3946
|
-
}
|
|
3947
|
-
let allowAny = doc.getIn(["peerDependencyRules", "allowAny"]);
|
|
3948
|
-
if (!allowAny) allowAny = new import_dist.YAMLSeq();
|
|
3949
|
-
const existing = new Set(allowAny.items.map((n) => n.value));
|
|
3950
|
-
for (const key of Object.keys(VITE_PLUS_OVERRIDE_PACKAGES)) if (!existing.has(key)) allowAny.add(scalarString(key));
|
|
3951
|
-
doc.setIn(["peerDependencyRules", "allowAny"], allowAny);
|
|
3952
|
-
let allowedVersions = doc.getIn(["peerDependencyRules", "allowedVersions"]);
|
|
3953
|
-
if (!allowedVersions) allowedVersions = new import_dist.YAMLMap();
|
|
3954
|
-
for (const key of Object.keys(VITE_PLUS_OVERRIDE_PACKAGES)) allowedVersions.set(scalarString(key), scalarString("*"));
|
|
3955
|
-
doc.setIn(["peerDependencyRules", "allowedVersions"], allowedVersions);
|
|
3956
|
-
if (doc.has("minimumReleaseAge")) {
|
|
3957
|
-
const excludes = [
|
|
3958
|
-
"vite-plus",
|
|
3959
|
-
"@voidzero-dev/*",
|
|
3960
|
-
"oxlint",
|
|
3961
|
-
"@oxlint/*",
|
|
3962
|
-
"oxlint-tsgolint",
|
|
3963
|
-
"@oxlint-tsgolint/*",
|
|
3964
|
-
"oxfmt",
|
|
3965
|
-
"@oxfmt/*"
|
|
3966
|
-
];
|
|
3967
|
-
let minimumReleaseAgeExclude = doc.getIn(["minimumReleaseAgeExclude"]);
|
|
3968
|
-
if (!minimumReleaseAgeExclude) minimumReleaseAgeExclude = new import_dist.YAMLSeq();
|
|
3969
|
-
const existing = new Set(minimumReleaseAgeExclude.items.map((n) => n.value));
|
|
3970
|
-
for (const exclude of excludes) if (!existing.has(exclude)) minimumReleaseAgeExclude.add(scalarString(exclude));
|
|
3971
|
-
doc.setIn(["minimumReleaseAgeExclude"], minimumReleaseAgeExclude);
|
|
3972
|
-
}
|
|
3973
|
-
});
|
|
3974
|
-
}
|
|
3975
|
-
/**
|
|
3976
|
-
* Clean up pnpm.overrides and peerDependencyRules from package.json when migrating
|
|
3977
|
-
* to pnpm-workspace.yaml. Returns any remaining non-Vite overrides that need to be
|
|
3978
|
-
* moved to pnpm-workspace.yaml.
|
|
3979
|
-
*/
|
|
3980
|
-
function cleanupPnpmOverridesForWorkspaceYaml(pkg, overrideKeys) {
|
|
3981
|
-
const catalogOverrides = {};
|
|
3982
|
-
const overrides = pkg.pnpm?.overrides;
|
|
3983
|
-
for (const key of [...overrideKeys, ...REMOVE_PACKAGES]) {
|
|
3984
|
-
const value = overrides?.[key];
|
|
3985
|
-
if (value) {
|
|
3986
|
-
if (overrideKeys.includes(key) && value.startsWith("catalog:")) catalogOverrides[key] = value;
|
|
3987
|
-
delete overrides[key];
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
for (const key in pkg.pnpm?.overrides) if (key.includes(">")) {
|
|
3991
|
-
const splits = key.split(">");
|
|
3992
|
-
if (splits[splits.length - 1].trim() === "vite") delete pkg.pnpm.overrides[key];
|
|
3993
|
-
}
|
|
3994
|
-
let remaining;
|
|
3995
|
-
if (Object.keys(catalogOverrides).length > 0) remaining = { ...catalogOverrides };
|
|
3996
|
-
if (pkg.pnpm?.overrides && Object.keys(pkg.pnpm.overrides).length > 0) remaining = {
|
|
3997
|
-
...remaining,
|
|
3998
|
-
...pkg.pnpm.overrides
|
|
3999
|
-
};
|
|
4000
|
-
delete pkg.pnpm?.overrides;
|
|
4001
|
-
cleanupPeerDependencyRules(pkg.pnpm?.peerDependencyRules, overrideKeys);
|
|
4002
|
-
if (pkg.pnpm?.peerDependencyRules && Object.keys(pkg.pnpm.peerDependencyRules).length === 0) delete pkg.pnpm.peerDependencyRules;
|
|
4003
|
-
if (pkg.pnpm && Object.keys(pkg.pnpm).length === 0) delete pkg.pnpm;
|
|
4004
|
-
return remaining;
|
|
4005
|
-
}
|
|
4006
|
-
/**
|
|
4007
|
-
* Move remaining non-Vite pnpm.overrides from package.json to pnpm-workspace.yaml.
|
|
4008
|
-
* pnpm ignores workspace-level overrides when pnpm.overrides exists in package.json,
|
|
4009
|
-
* so all overrides must live in pnpm-workspace.yaml.
|
|
4010
|
-
*/
|
|
4011
|
-
function migratePnpmOverridesToWorkspaceYaml(projectPath, overrides) {
|
|
4012
|
-
editYamlFile(path.join(projectPath, "pnpm-workspace.yaml"), (doc) => {
|
|
4013
|
-
for (const [key, value] of Object.entries(overrides)) doc.setIn(["overrides", scalarString(key)], scalarString(value));
|
|
4014
|
-
});
|
|
4015
|
-
}
|
|
4016
|
-
/**
|
|
4017
|
-
* Remove only Vite-managed entries from peerDependencyRules, preserving custom ones.
|
|
4018
|
-
*/
|
|
4019
|
-
function cleanupPeerDependencyRules(peerDependencyRules, overrideKeys) {
|
|
4020
|
-
if (!peerDependencyRules) return;
|
|
4021
|
-
if (Array.isArray(peerDependencyRules.allowAny)) {
|
|
4022
|
-
peerDependencyRules.allowAny = peerDependencyRules.allowAny.filter((key) => !overrideKeys.includes(key));
|
|
4023
|
-
if (peerDependencyRules.allowAny.length === 0) delete peerDependencyRules.allowAny;
|
|
4024
|
-
}
|
|
4025
|
-
if (peerDependencyRules.allowedVersions) {
|
|
4026
|
-
for (const key of overrideKeys) delete peerDependencyRules.allowedVersions[key];
|
|
4027
|
-
if (Object.keys(peerDependencyRules.allowedVersions).length === 0) delete peerDependencyRules.allowedVersions;
|
|
4028
|
-
}
|
|
4029
|
-
}
|
|
4030
|
-
/**
|
|
4031
|
-
* Rewrite .yarnrc.yml to add vite-plus dependencies
|
|
4032
|
-
* @param projectPath - The path to the project
|
|
4033
|
-
*/
|
|
4034
|
-
function rewriteYarnrcYml(projectPath) {
|
|
4035
|
-
const yarnrcYmlPath = path.join(projectPath, ".yarnrc.yml");
|
|
4036
|
-
if (!fs.existsSync(yarnrcYmlPath)) fs.writeFileSync(yarnrcYmlPath, "");
|
|
4037
|
-
editYamlFile(yarnrcYmlPath, (doc) => {
|
|
4038
|
-
if (!doc.has("nodeLinker")) doc.set("nodeLinker", "node-modules");
|
|
4039
|
-
rewriteCatalog(doc);
|
|
4040
|
-
});
|
|
4041
|
-
}
|
|
4042
|
-
/**
|
|
4043
|
-
* Rewrite catalog in pnpm-workspace.yaml or .yarnrc.yml
|
|
4044
|
-
* @param doc - The document to rewrite
|
|
4045
|
-
*/
|
|
4046
|
-
function getCatalogDependencySpec(currentValue, version, supportCatalog, options) {
|
|
4047
|
-
if (options?.dependencyField === "peerDependencies") {
|
|
4048
|
-
if (currentValue?.startsWith("catalog:") && options.dependencyName) {
|
|
4049
|
-
const resolved = options.catalogDependencyResolver?.(currentValue, options.dependencyName);
|
|
4050
|
-
if (resolved && !isVitePlusOverrideSpec(resolved)) return resolved;
|
|
4051
|
-
return PUBLIC_PEER_DEPENDENCY_FALLBACKS[options.dependencyName] ?? currentValue;
|
|
4052
|
-
}
|
|
4053
|
-
return currentValue ?? version;
|
|
4054
|
-
}
|
|
4055
|
-
if (options?.dependencyField === "optionalDependencies" && options?.packageManager === PackageManager.yarn) return version;
|
|
4056
|
-
if (!supportCatalog || version.startsWith("file:")) return version;
|
|
4057
|
-
return currentValue?.startsWith("catalog:") ? currentValue : "catalog:";
|
|
4058
|
-
}
|
|
4059
|
-
function isVitePlusOverrideSpec(value) {
|
|
4060
|
-
return Object.values(VITE_PLUS_OVERRIDE_PACKAGES).includes(value) || value.startsWith("npm:@voidzero-dev/vite-plus-");
|
|
4061
|
-
}
|
|
4062
|
-
function createCatalogDependencyResolver(projectPath, packageManager) {
|
|
4063
|
-
if (packageManager === PackageManager.pnpm) {
|
|
4064
|
-
const pnpmWorkspaceYamlPath = path.join(projectPath, "pnpm-workspace.yaml");
|
|
4065
|
-
if (!fs.existsSync(pnpmWorkspaceYamlPath)) return;
|
|
4066
|
-
const doc = readYamlFile(pnpmWorkspaceYamlPath);
|
|
4067
|
-
return createCatalogDependencyResolverFromCatalogs(doc?.catalog, doc?.catalogs);
|
|
4068
|
-
}
|
|
4069
|
-
if (packageManager === PackageManager.yarn) {
|
|
4070
|
-
const yarnrcYmlPath = path.join(projectPath, ".yarnrc.yml");
|
|
4071
|
-
if (!fs.existsSync(yarnrcYmlPath)) return;
|
|
4072
|
-
const doc = readYamlFile(yarnrcYmlPath);
|
|
4073
|
-
return createCatalogDependencyResolverFromCatalogs(doc?.catalog, doc?.catalogs);
|
|
4074
|
-
}
|
|
4075
|
-
if (packageManager === PackageManager.bun) {
|
|
4076
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
4077
|
-
if (!fs.existsSync(packageJsonPath)) return;
|
|
4078
|
-
const pkg = readJsonFile(packageJsonPath);
|
|
4079
|
-
const workspacesObj = pkg.workspaces && !Array.isArray(pkg.workspaces) ? pkg.workspaces : void 0;
|
|
4080
|
-
return (catalogSpec, dependencyName) => {
|
|
4081
|
-
const catalogName = catalogSpec.slice(8);
|
|
4082
|
-
if (catalogName) return workspacesObj?.catalogs?.[catalogName]?.[dependencyName] ?? pkg.catalogs?.[catalogName]?.[dependencyName];
|
|
4083
|
-
return workspacesObj?.catalog?.[dependencyName] ?? pkg.catalog?.[dependencyName];
|
|
4084
|
-
};
|
|
4085
|
-
}
|
|
4086
|
-
}
|
|
4087
|
-
function createCatalogDependencyResolverFromCatalogs(catalog, catalogs) {
|
|
4088
|
-
return (catalogSpec, dependencyName) => {
|
|
4089
|
-
const catalogName = catalogSpec.slice(8);
|
|
4090
|
-
if (catalogName) return catalogs?.[catalogName]?.[dependencyName];
|
|
4091
|
-
return catalog?.[dependencyName];
|
|
4092
|
-
};
|
|
4093
|
-
}
|
|
4094
|
-
function getYamlMapScalarStringValue(map, key) {
|
|
4095
|
-
if (!(map instanceof import_dist.YAMLMap)) return;
|
|
4096
|
-
for (const item of map.items) if (item.key instanceof import_dist.Scalar && item.key.value === key && item.value instanceof import_dist.Scalar && typeof item.value.value === "string") return item.value.value;
|
|
4097
|
-
}
|
|
4098
|
-
function rewriteCatalog(doc) {
|
|
4099
|
-
for (const [key, value] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) {
|
|
4100
|
-
if (value.startsWith("file:")) continue;
|
|
4101
|
-
doc.setIn(["catalog", key], scalarString(value));
|
|
4102
|
-
}
|
|
4103
|
-
if (!VITE_PLUS_VERSION.startsWith("file:")) doc.setIn(["catalog", VITE_PLUS_NAME], scalarString(VITE_PLUS_VERSION));
|
|
4104
|
-
for (const name of REMOVE_PACKAGES) {
|
|
4105
|
-
const path = ["catalog", name];
|
|
4106
|
-
if (doc.hasIn(path)) doc.deleteIn(path);
|
|
4107
|
-
}
|
|
4108
|
-
const catalogs = doc.getIn(["catalogs"]);
|
|
4109
|
-
if (!(catalogs instanceof import_dist.YAMLMap)) return;
|
|
4110
|
-
for (const item of catalogs.items) {
|
|
4111
|
-
const catalogName = item.key instanceof import_dist.Scalar ? item.key.value : void 0;
|
|
4112
|
-
if (typeof catalogName !== "string" || !(item.value instanceof import_dist.YAMLMap)) continue;
|
|
4113
|
-
for (const [key, value] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) {
|
|
4114
|
-
const catalogPath = [
|
|
4115
|
-
"catalogs",
|
|
4116
|
-
catalogName,
|
|
4117
|
-
key
|
|
4118
|
-
];
|
|
4119
|
-
if (!value.startsWith("file:") && doc.hasIn(catalogPath)) doc.setIn(catalogPath, scalarString(value));
|
|
4120
|
-
}
|
|
4121
|
-
const vitePlusPath = [
|
|
4122
|
-
"catalogs",
|
|
4123
|
-
catalogName,
|
|
4124
|
-
VITE_PLUS_NAME
|
|
4125
|
-
];
|
|
4126
|
-
if (!VITE_PLUS_VERSION.startsWith("file:") && doc.hasIn(vitePlusPath)) doc.setIn(vitePlusPath, scalarString(VITE_PLUS_VERSION));
|
|
4127
|
-
for (const name of REMOVE_PACKAGES) {
|
|
4128
|
-
const catalogPath = [
|
|
4129
|
-
"catalogs",
|
|
4130
|
-
catalogName,
|
|
4131
|
-
name
|
|
4132
|
-
];
|
|
4133
|
-
if (doc.hasIn(catalogPath)) doc.deleteIn(catalogPath);
|
|
4134
|
-
}
|
|
4135
|
-
}
|
|
4136
|
-
}
|
|
4137
|
-
function rewriteCatalogObject(catalog, addMissing) {
|
|
4138
|
-
for (const [key, value] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) {
|
|
4139
|
-
if (value.startsWith("file:") || !addMissing && !(key in catalog)) continue;
|
|
4140
|
-
catalog[key] = value;
|
|
4141
|
-
}
|
|
4142
|
-
if (!VITE_PLUS_VERSION.startsWith("file:") && (addMissing || "vite-plus" in catalog)) catalog[VITE_PLUS_NAME] = VITE_PLUS_VERSION;
|
|
4143
|
-
for (const name of REMOVE_PACKAGES) delete catalog[name];
|
|
4144
|
-
}
|
|
4145
|
-
function rewriteCatalogsObject(catalogs) {
|
|
4146
|
-
for (const catalog of Object.values(catalogs)) rewriteCatalogObject(catalog, false);
|
|
4147
|
-
}
|
|
4148
|
-
/**
|
|
4149
|
-
* Write catalog entries to root package.json for bun.
|
|
4150
|
-
* Bun stores catalogs in package.json under the `catalog` key,
|
|
4151
|
-
* unlike pnpm which uses pnpm-workspace.yaml.
|
|
4152
|
-
* @see https://bun.sh/docs/pm/catalogs
|
|
4153
|
-
*/
|
|
4154
|
-
function rewriteBunCatalog(projectPath) {
|
|
4155
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
4156
|
-
if (!fs.existsSync(packageJsonPath)) return;
|
|
4157
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
4158
|
-
const workspacesObj = pkg.workspaces && !Array.isArray(pkg.workspaces) ? pkg.workspaces : void 0;
|
|
4159
|
-
const useWorkspacesCatalog = workspacesObj?.catalog != null || pkg.catalog == null && workspacesObj?.catalogs != null;
|
|
4160
|
-
const catalog = { ...useWorkspacesCatalog ? workspacesObj?.catalog : pkg.catalog };
|
|
4161
|
-
rewriteCatalogObject(catalog, true);
|
|
4162
|
-
if (useWorkspacesCatalog) {
|
|
4163
|
-
workspacesObj.catalog = catalog;
|
|
4164
|
-
if (pkg.catalog) rewriteCatalogObject(pkg.catalog, false);
|
|
4165
|
-
} else {
|
|
4166
|
-
pkg.catalog = catalog;
|
|
4167
|
-
if (workspacesObj?.catalog) rewriteCatalogObject(workspacesObj.catalog, false);
|
|
4168
|
-
}
|
|
4169
|
-
if (workspacesObj?.catalogs) rewriteCatalogsObject(workspacesObj.catalogs);
|
|
4170
|
-
if (pkg.catalogs) rewriteCatalogsObject(pkg.catalogs);
|
|
4171
|
-
const overrides = { ...pkg.overrides };
|
|
4172
|
-
for (const [key, value] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) overrides[key] = getCatalogDependencySpec(overrides[key], value, true);
|
|
4173
|
-
pkg.overrides = overrides;
|
|
4174
|
-
return pkg;
|
|
4175
|
-
});
|
|
4176
|
-
}
|
|
4177
|
-
/**
|
|
4178
|
-
* Rewrite root workspace package.json to add vite-plus dependencies
|
|
4179
|
-
* @param projectPath - The path to the project
|
|
4180
|
-
*/
|
|
4181
|
-
function rewriteRootWorkspacePackageJson(projectPath, packageManager, skipStagedMigration, catalogDependencyResolver) {
|
|
4182
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
4183
|
-
if (!fs.existsSync(packageJsonPath)) return;
|
|
4184
|
-
let remainingPnpmOverrides;
|
|
4185
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
4186
|
-
if (packageManager === PackageManager.yarn) pkg.resolutions = {
|
|
4187
|
-
...pkg.resolutions,
|
|
4188
|
-
...VITE_PLUS_OVERRIDE_PACKAGES
|
|
4189
|
-
};
|
|
4190
|
-
else if (packageManager === PackageManager.npm) pkg.overrides = {
|
|
4191
|
-
...pkg.overrides,
|
|
4192
|
-
...VITE_PLUS_OVERRIDE_PACKAGES
|
|
4193
|
-
};
|
|
4194
|
-
else if (packageManager === PackageManager.bun) {} else if (packageManager === PackageManager.pnpm) {
|
|
4195
|
-
const overrideKeys = Object.keys(VITE_PLUS_OVERRIDE_PACKAGES);
|
|
4196
|
-
if (isForceOverrideMode()) pkg.pnpm = {
|
|
4197
|
-
...pkg.pnpm,
|
|
4198
|
-
overrides: {
|
|
4199
|
-
...pkg.pnpm?.overrides,
|
|
4200
|
-
...VITE_PLUS_OVERRIDE_PACKAGES,
|
|
4201
|
-
[VITE_PLUS_NAME]: VITE_PLUS_VERSION
|
|
4202
|
-
}
|
|
4203
|
-
};
|
|
4204
|
-
else {
|
|
4205
|
-
for (const key of [...overrideKeys, ...REMOVE_PACKAGES]) if (pkg.resolutions?.[key]) delete pkg.resolutions[key];
|
|
4206
|
-
remainingPnpmOverrides = cleanupPnpmOverridesForWorkspaceYaml(pkg, overrideKeys);
|
|
4207
|
-
}
|
|
4208
|
-
for (const key in pkg.pnpm?.overrides) if (key.includes(">")) {
|
|
4209
|
-
const splits = key.split(">");
|
|
4210
|
-
if (splits[splits.length - 1].trim() === "vite") delete pkg.pnpm.overrides[key];
|
|
4211
|
-
}
|
|
4212
|
-
}
|
|
4213
|
-
if (!pkg.devDependencies?.["vite-plus"]) pkg.devDependencies = {
|
|
4214
|
-
...pkg.devDependencies,
|
|
4215
|
-
[VITE_PLUS_NAME]: packageManager === PackageManager.npm || VITE_PLUS_VERSION.startsWith("file:") ? VITE_PLUS_VERSION : "catalog:"
|
|
4216
|
-
};
|
|
4217
|
-
return pkg;
|
|
4218
|
-
});
|
|
4219
|
-
if (remainingPnpmOverrides) migratePnpmOverridesToWorkspaceYaml(projectPath, remainingPnpmOverrides);
|
|
4220
|
-
rewriteMonorepoProject(projectPath, packageManager, skipStagedMigration, void 0, void 0, catalogDependencyResolver);
|
|
4221
|
-
}
|
|
4222
|
-
const RULES_YAML_PATH = path.join(rulesDir, "vite-tools.yml");
|
|
4223
|
-
const PREPARE_RULES_YAML_PATH = path.join(rulesDir, "vite-prepare.yml");
|
|
4224
|
-
let cachedRulesYaml;
|
|
4225
|
-
let cachedRulesYamlNoLintStaged;
|
|
4226
|
-
let cachedPrepareRulesYaml;
|
|
4227
|
-
function readRulesYaml() {
|
|
4228
|
-
cachedRulesYaml ??= fs.readFileSync(RULES_YAML_PATH, "utf8");
|
|
4229
|
-
return cachedRulesYaml;
|
|
4230
|
-
}
|
|
4231
|
-
function getScriptRulesYaml(skipStagedMigration) {
|
|
4232
|
-
const yaml = readRulesYaml();
|
|
4233
|
-
if (!skipStagedMigration) return yaml;
|
|
4234
|
-
cachedRulesYamlNoLintStaged ??= yaml.split("\n\n\n").filter((block) => !block.includes("id: replace-lint-staged")).join("\n\n\n");
|
|
4235
|
-
return cachedRulesYamlNoLintStaged;
|
|
4236
|
-
}
|
|
4237
|
-
function readPrepareRulesYaml() {
|
|
4238
|
-
cachedPrepareRulesYaml ??= fs.readFileSync(PREPARE_RULES_YAML_PATH, "utf8");
|
|
4239
|
-
return cachedPrepareRulesYaml;
|
|
4240
|
-
}
|
|
4241
|
-
function rewritePackageJson(pkg, packageManager, isMonorepo, skipStagedMigration, catalogDependencyResolver) {
|
|
4242
|
-
if (pkg.scripts) {
|
|
4243
|
-
const updated = rewriteScripts(JSON.stringify(pkg.scripts), getScriptRulesYaml(skipStagedMigration));
|
|
4244
|
-
if (updated) pkg.scripts = JSON.parse(updated);
|
|
4245
|
-
}
|
|
4246
|
-
let extractedStagedConfig = null;
|
|
4247
|
-
if (!skipStagedMigration && pkg["lint-staged"]) {
|
|
4248
|
-
const config = pkg["lint-staged"];
|
|
4249
|
-
const updated = rewriteScripts(JSON.stringify(config), readRulesYaml());
|
|
4250
|
-
extractedStagedConfig = updated ? JSON.parse(updated) : config;
|
|
4251
|
-
}
|
|
4252
|
-
const supportCatalog = !!isMonorepo && packageManager !== PackageManager.npm;
|
|
4253
|
-
let needVitePlus = false;
|
|
4254
|
-
const dependencyGroups = [
|
|
4255
|
-
{
|
|
4256
|
-
dependencyField: "devDependencies",
|
|
4257
|
-
dependencies: pkg.devDependencies
|
|
4258
|
-
},
|
|
4259
|
-
{
|
|
4260
|
-
dependencyField: "dependencies",
|
|
4261
|
-
dependencies: pkg.dependencies
|
|
4262
|
-
},
|
|
4263
|
-
{
|
|
4264
|
-
dependencyField: "peerDependencies",
|
|
4265
|
-
dependencies: pkg.peerDependencies
|
|
4266
|
-
},
|
|
4267
|
-
{
|
|
4268
|
-
dependencyField: "optionalDependencies",
|
|
4269
|
-
dependencies: pkg.optionalDependencies
|
|
4270
|
-
}
|
|
4271
|
-
];
|
|
4272
|
-
for (const [key, version] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) for (const { dependencyField, dependencies } of dependencyGroups) if (dependencies?.[key]) {
|
|
4273
|
-
dependencies[key] = getCatalogDependencySpec(dependencies[key], version, supportCatalog, {
|
|
4274
|
-
dependencyField,
|
|
4275
|
-
dependencyName: key,
|
|
4276
|
-
packageManager,
|
|
4277
|
-
catalogDependencyResolver
|
|
4278
|
-
});
|
|
4279
|
-
needVitePlus = true;
|
|
4280
|
-
}
|
|
4281
|
-
for (const name of REMOVE_PACKAGES) {
|
|
4282
|
-
let wasRemoved = false;
|
|
4283
|
-
for (const { dependencies } of dependencyGroups) if (dependencies?.[name]) {
|
|
4284
|
-
delete dependencies[name];
|
|
4285
|
-
wasRemoved = true;
|
|
4286
|
-
}
|
|
4287
|
-
if (wasRemoved) needVitePlus = true;
|
|
4288
|
-
const peerDep = BROWSER_PROVIDER_PEER_DEPS[name];
|
|
4289
|
-
if (wasRemoved && peerDep && !pkg.devDependencies?.[peerDep] && !pkg.dependencies?.[peerDep] && !pkg.peerDependencies?.[peerDep] && !pkg.optionalDependencies?.[peerDep]) {
|
|
4290
|
-
pkg.devDependencies ??= {};
|
|
4291
|
-
pkg.devDependencies[peerDep] = "*";
|
|
4292
|
-
}
|
|
4293
|
-
}
|
|
4294
|
-
if (needVitePlus) {
|
|
4295
|
-
const version = supportCatalog && !VITE_PLUS_VERSION.startsWith("file:") ? "catalog:" : VITE_PLUS_VERSION;
|
|
4296
|
-
pkg.devDependencies = {
|
|
4297
|
-
...pkg.devDependencies,
|
|
4298
|
-
[VITE_PLUS_NAME]: version
|
|
4299
|
-
};
|
|
4300
|
-
const installableDeps = {
|
|
4301
|
-
...pkg.dependencies,
|
|
4302
|
-
...pkg.devDependencies,
|
|
4303
|
-
...pkg.optionalDependencies
|
|
4304
|
-
};
|
|
4305
|
-
if (!installableDeps.vitest && Object.keys(installableDeps).some((name) => name.includes("vitest"))) {
|
|
4306
|
-
const ver = VITE_PLUS_OVERRIDE_PACKAGES.vitest;
|
|
4307
|
-
pkg.devDependencies.vitest = getCatalogDependencySpec(void 0, ver, supportCatalog);
|
|
4308
|
-
}
|
|
4309
|
-
}
|
|
4310
|
-
return extractedStagedConfig;
|
|
4311
|
-
}
|
|
4312
|
-
function removeLintStagedFromPackageJson(packageJsonPath) {
|
|
4313
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
4314
|
-
if (pkg["lint-staged"]) {
|
|
4315
|
-
delete pkg["lint-staged"];
|
|
4316
|
-
return pkg;
|
|
4317
|
-
}
|
|
4318
|
-
});
|
|
4319
|
-
}
|
|
4320
|
-
function rewriteLintStagedConfigFile(projectPath, report) {
|
|
4321
|
-
let hasUnsupported = false;
|
|
4322
|
-
for (const filename of LINT_STAGED_JSON_CONFIG_FILES) {
|
|
4323
|
-
const configPath = path.join(projectPath, filename);
|
|
4324
|
-
if (!fs.existsSync(configPath)) continue;
|
|
4325
|
-
if (filename === ".lintstagedrc" && !isJsonFile(configPath)) {
|
|
4326
|
-
warnMigration(`${displayRelative(configPath)} is not JSON format — please migrate to "staged" in vite.config.ts manually`, report);
|
|
4327
|
-
hasUnsupported = true;
|
|
4328
|
-
continue;
|
|
4329
|
-
}
|
|
4330
|
-
if (!hasStagedConfigInViteConfig(projectPath)) {
|
|
4331
|
-
const config = readJsonFile(configPath);
|
|
4332
|
-
const updated = rewriteScripts(JSON.stringify(config), readRulesYaml());
|
|
4333
|
-
if (!mergeStagedConfigToViteConfig(projectPath, updated ? JSON.parse(updated) : config, true, report)) continue;
|
|
4334
|
-
fs.unlinkSync(configPath);
|
|
4335
|
-
if (report) report.inlinedLintStagedConfigCount++;
|
|
4336
|
-
} else warnMigration(`${displayRelative(configPath)} found but "staged" already exists in vite.config.ts — please merge manually`, report);
|
|
4337
|
-
}
|
|
4338
|
-
for (const filename of LINT_STAGED_OTHER_CONFIG_FILES) {
|
|
4339
|
-
const configPath = path.join(projectPath, filename);
|
|
4340
|
-
if (!fs.existsSync(configPath)) continue;
|
|
4341
|
-
warnMigration(`${displayRelative(configPath)} — please migrate to "staged" in vite.config.ts manually`, report);
|
|
4342
|
-
hasUnsupported = true;
|
|
4343
|
-
}
|
|
4344
|
-
if (hasUnsupported) infoMigration("Only \"staged\" in vite.config.ts is supported. See https://viteplus.dev/guide/migrate#lint-staged", report);
|
|
4345
|
-
}
|
|
4346
|
-
/**
|
|
4347
|
-
* Ensure vite.config.ts exists, create it if not
|
|
4348
|
-
* @returns The vite config filename
|
|
4349
|
-
*/
|
|
4350
|
-
function ensureViteConfig(projectPath, configs, silent = false, report) {
|
|
4351
|
-
if (!configs.viteConfig) {
|
|
4352
|
-
configs.viteConfig = "vite.config.ts";
|
|
4353
|
-
const viteConfigPath = path.join(projectPath, "vite.config.ts");
|
|
4354
|
-
fs.writeFileSync(viteConfigPath, `import { defineConfig } from '${VITE_PLUS_NAME}';
|
|
4355
|
-
|
|
4356
|
-
export default defineConfig({});
|
|
4357
|
-
`);
|
|
4358
|
-
if (report) report.createdViteConfigCount++;
|
|
4359
|
-
if (!silent) log.success(`✔ Created vite.config.ts in ${displayRelative(viteConfigPath)}`);
|
|
4360
|
-
}
|
|
4361
|
-
return configs.viteConfig;
|
|
4362
|
-
}
|
|
4363
|
-
/**
|
|
4364
|
-
* Merge tsdown.config.* into vite.config.ts
|
|
4365
|
-
* - For JSON files: merge content directly into `pack` field and delete the JSON file
|
|
4366
|
-
* - For TS/JS files: import the config file
|
|
4367
|
-
*/
|
|
4368
|
-
function mergeTsdownConfigFile(projectPath, silent = false, report) {
|
|
4369
|
-
const configs = detectConfigs(projectPath);
|
|
4370
|
-
if (!configs.tsdownConfig) return;
|
|
4371
|
-
const viteConfig = ensureViteConfig(projectPath, configs, silent, report);
|
|
4372
|
-
const fullViteConfigPath = path.join(projectPath, viteConfig);
|
|
4373
|
-
const fullTsdownConfigPath = path.join(projectPath, configs.tsdownConfig);
|
|
4374
|
-
if (configs.tsdownConfig.endsWith(".json")) {
|
|
4375
|
-
mergeAndRemoveJsonConfig(projectPath, viteConfig, configs.tsdownConfig, "pack", silent, report);
|
|
4376
|
-
return;
|
|
4377
|
-
}
|
|
4378
|
-
const result = mergeTsdownConfig(fullViteConfigPath, `./${configs.tsdownConfig}`);
|
|
4379
|
-
if (result.updated) {
|
|
4380
|
-
fs.writeFileSync(fullViteConfigPath, result.content);
|
|
4381
|
-
if (report) report.tsdownImportCount++;
|
|
4382
|
-
if (!silent) log.success(`✔ Added import for ${displayRelative(fullTsdownConfigPath)} in ${displayRelative(fullViteConfigPath)}`);
|
|
4383
|
-
}
|
|
4384
|
-
infoMigration(`Please manually merge ${displayRelative(fullTsdownConfigPath)} into ${displayRelative(fullViteConfigPath)}, see https://viteplus.dev/guide/migrate#tsdown`, report);
|
|
4385
|
-
}
|
|
4386
|
-
/**
|
|
4387
|
-
* Merge oxlint and oxfmt config into vite.config.ts
|
|
4388
|
-
*/
|
|
4389
|
-
function mergeViteConfigFiles(projectPath, silent = false, report) {
|
|
4390
|
-
const configs = detectConfigs(projectPath);
|
|
4391
|
-
if (!configs.oxfmtConfig && !configs.oxlintConfig) return;
|
|
4392
|
-
const viteConfig = ensureViteConfig(projectPath, configs, silent, report);
|
|
4393
|
-
if (configs.oxlintConfig) {
|
|
4394
|
-
const fullOxlintPath = path.join(projectPath, configs.oxlintConfig);
|
|
4395
|
-
const oxlintJson = readJsonFile(fullOxlintPath, true);
|
|
4396
|
-
if (!oxlintJson.options) oxlintJson.options = {};
|
|
4397
|
-
if (!hasBaseUrlInTsconfig(projectPath)) {
|
|
4398
|
-
if (oxlintJson.options.typeAware === void 0) oxlintJson.options.typeAware = true;
|
|
4399
|
-
if (oxlintJson.options.typeCheck === void 0) oxlintJson.options.typeCheck = true;
|
|
4400
|
-
} else warnMigration(BASEURL_TSCONFIG_WARNING, report);
|
|
4401
|
-
const normalizedOxlintConfig = ensureVitePlusImportRuleDefaults(oxlintJson);
|
|
4402
|
-
fs.writeFileSync(fullOxlintPath, JSON.stringify(normalizedOxlintConfig, null, 2));
|
|
4403
|
-
mergeAndRemoveJsonConfig(projectPath, viteConfig, configs.oxlintConfig, "lint", silent, report);
|
|
4404
|
-
}
|
|
4405
|
-
if (configs.oxfmtConfig) mergeAndRemoveJsonConfig(projectPath, viteConfig, configs.oxfmtConfig, "fmt", silent, report);
|
|
4406
|
-
}
|
|
4407
|
-
/**
|
|
4408
|
-
* Inject typeAware and typeCheck defaults into vite.config.ts lint config.
|
|
4409
|
-
* Called after mergeViteConfigFiles() to handle the case where no .oxlintrc.json exists
|
|
4410
|
-
* (e.g., newly created projects from create-vite templates).
|
|
4411
|
-
*/
|
|
4412
|
-
function injectLintTypeCheckDefaults(projectPath, silent = false, report) {
|
|
4413
|
-
if (hasBaseUrlInTsconfig(projectPath)) return;
|
|
4414
|
-
injectConfigDefaults(projectPath, "lint", ".vite-plus-lint-init.oxlintrc.json", JSON.stringify(createDefaultVitePlusLintConfig({ includeTypeAwareDefaults: true })), silent, report);
|
|
4415
|
-
}
|
|
4416
|
-
function injectFmtDefaults(projectPath, silent = false, report) {
|
|
4417
|
-
injectConfigDefaults(projectPath, "fmt", ".vite-plus-fmt-init.oxfmtrc.json", JSON.stringify({}), silent, report);
|
|
4418
|
-
}
|
|
4419
|
-
/**
|
|
4420
|
-
* Wire `create.defaultTemplate: '<scope>'` into the new monorepo's
|
|
4421
|
-
* `vite.config.ts`. The caller is `bin.ts`, only when scaffolding a
|
|
4422
|
-
* monorepo from a bundled `@org` manifest entry — that's the case where
|
|
4423
|
-
* the user just picked a template from a specific org and naturally
|
|
4424
|
-
* wants subsequent `vp create` invocations from the workspace to default
|
|
4425
|
-
* to that same org's picker.
|
|
4426
|
-
*/
|
|
4427
|
-
function injectCreateDefaultTemplate(projectPath, scope, silent = false, report) {
|
|
4428
|
-
if (!scope) return;
|
|
4429
|
-
injectConfigDefaults(projectPath, "create", ".vite-plus-create-init.json", JSON.stringify({ defaultTemplate: scope }), silent, report);
|
|
4430
|
-
}
|
|
4431
|
-
function injectConfigDefaults(projectPath, configKey, tempFileName, tempFileContent, silent, report) {
|
|
4432
|
-
const configs = detectConfigs(projectPath);
|
|
4433
|
-
if (configs.viteConfig && hasConfigKey(path.join(projectPath, configs.viteConfig), configKey)) return;
|
|
4434
|
-
const viteConfig = ensureViteConfig(projectPath, configs, silent, report);
|
|
4435
|
-
const tempConfigPath = path.join(projectPath, tempFileName);
|
|
4436
|
-
fs.writeFileSync(tempConfigPath, tempFileContent);
|
|
4437
|
-
const fullViteConfigPath = path.join(projectPath, viteConfig);
|
|
4438
|
-
let result;
|
|
3802
|
+
function rewriteTypesInTsconfig(filePath) {
|
|
3803
|
+
let text;
|
|
4439
3804
|
try {
|
|
4440
|
-
|
|
4441
|
-
}
|
|
4442
|
-
fs.rmSync(tempConfigPath, { force: true });
|
|
4443
|
-
}
|
|
4444
|
-
if (result.updated) fs.writeFileSync(fullViteConfigPath, result.content);
|
|
4445
|
-
}
|
|
4446
|
-
function mergeAndRemoveJsonConfig(projectPath, viteConfigPath, jsonConfigPath, configKey, silent = false, report) {
|
|
4447
|
-
const fullViteConfigPath = path.join(projectPath, viteConfigPath);
|
|
4448
|
-
const fullJsonConfigPath = path.join(projectPath, jsonConfigPath);
|
|
4449
|
-
if (hasConfigKey(fullViteConfigPath, configKey)) {
|
|
4450
|
-
fs.unlinkSync(fullJsonConfigPath);
|
|
4451
|
-
if (!silent) log.info(`${configKey} config already present in ${displayRelative(fullViteConfigPath)} — removed redundant ${displayRelative(fullJsonConfigPath)}`);
|
|
4452
|
-
return;
|
|
4453
|
-
}
|
|
4454
|
-
const result = mergeJsonConfig(fullViteConfigPath, fullJsonConfigPath, configKey);
|
|
4455
|
-
if (result.updated) {
|
|
4456
|
-
fs.writeFileSync(fullViteConfigPath, result.content);
|
|
4457
|
-
fs.unlinkSync(fullJsonConfigPath);
|
|
4458
|
-
if (report) report.mergedConfigCount++;
|
|
4459
|
-
if (!silent) log.success(`✔ Merged ${displayRelative(fullJsonConfigPath)} into ${displayRelative(fullViteConfigPath)}`);
|
|
4460
|
-
} else {
|
|
4461
|
-
warnMigration(`Failed to merge ${displayRelative(fullJsonConfigPath)} into ${displayRelative(fullViteConfigPath)}`, report);
|
|
4462
|
-
infoMigration("Please complete the merge manually and follow the instructions in the documentation: https://viteplus.dev/config/", report);
|
|
4463
|
-
}
|
|
4464
|
-
}
|
|
4465
|
-
/**
|
|
4466
|
-
* Merge a staged config object into vite.config.ts as `staged: { ... }`.
|
|
4467
|
-
* Writes the config to a temp JSON file, calls mergeJsonConfig NAPI, then cleans up.
|
|
4468
|
-
*/
|
|
4469
|
-
function mergeStagedConfigToViteConfig(projectPath, stagedConfig, silent = false, report) {
|
|
4470
|
-
const viteConfig = ensureViteConfig(projectPath, detectConfigs(projectPath), silent, report);
|
|
4471
|
-
const fullViteConfigPath = path.join(projectPath, viteConfig);
|
|
4472
|
-
const tempJsonPath = path.join(projectPath, ".staged-config-temp.json");
|
|
4473
|
-
fs.writeFileSync(tempJsonPath, JSON.stringify(stagedConfig, null, 2));
|
|
4474
|
-
let result;
|
|
4475
|
-
try {
|
|
4476
|
-
result = mergeJsonConfig(fullViteConfigPath, tempJsonPath, "staged");
|
|
4477
|
-
} finally {
|
|
4478
|
-
fs.unlinkSync(tempJsonPath);
|
|
4479
|
-
}
|
|
4480
|
-
if (result.updated) {
|
|
4481
|
-
fs.writeFileSync(fullViteConfigPath, result.content);
|
|
4482
|
-
if (report) report.mergedStagedConfigCount++;
|
|
4483
|
-
if (!silent) log.success(`✔ Merged staged config into ${displayRelative(fullViteConfigPath)}`);
|
|
4484
|
-
return true;
|
|
4485
|
-
} else {
|
|
4486
|
-
warnMigration(`Failed to merge staged config into ${displayRelative(fullViteConfigPath)}`, report);
|
|
4487
|
-
infoMigration(`Please add staged config to ${displayRelative(fullViteConfigPath)} manually, see https://viteplus.dev/guide/migrate#lint-staged`, report);
|
|
4488
|
-
return false;
|
|
4489
|
-
}
|
|
4490
|
-
}
|
|
4491
|
-
/**
|
|
4492
|
-
* Check if vite.config.ts already has a `staged` config key.
|
|
4493
|
-
*/
|
|
4494
|
-
function hasStagedConfigInViteConfig(projectPath) {
|
|
4495
|
-
const configs = detectConfigs(projectPath);
|
|
4496
|
-
if (!configs.viteConfig) return false;
|
|
4497
|
-
const viteConfigPath = path.join(projectPath, configs.viteConfig);
|
|
4498
|
-
const content = fs.readFileSync(viteConfigPath, "utf8");
|
|
4499
|
-
return /\bstaged\s*:/.test(content);
|
|
4500
|
-
}
|
|
4501
|
-
/**
|
|
4502
|
-
* Rewrite imports in all TypeScript/JavaScript files under a directory
|
|
4503
|
-
* This rewrites vite/vitest imports to @voidzero-dev/vite-plus
|
|
4504
|
-
* @param projectPath - The root directory to search for files
|
|
4505
|
-
*/
|
|
4506
|
-
function rewriteAllImports(projectPath, silent = false, report) {
|
|
4507
|
-
const result = rewriteImportsInDirectory(projectPath);
|
|
4508
|
-
const modified = result.modifiedFiles.length;
|
|
4509
|
-
const errors = result.errors.length;
|
|
4510
|
-
if (report) {
|
|
4511
|
-
report.rewrittenImportFileCount += modified;
|
|
4512
|
-
report.rewrittenImportErrors.push(...result.errors.map((error) => ({
|
|
4513
|
-
path: displayRelative(error.path),
|
|
4514
|
-
message: error.message
|
|
4515
|
-
})));
|
|
4516
|
-
}
|
|
4517
|
-
if (!silent && modified > 0) {
|
|
4518
|
-
log.success(`Rewrote imports in ${modified === 1 ? "one file" : `${modified} files`}`);
|
|
4519
|
-
log.info(result.modifiedFiles.map((file) => ` ${displayRelative(file)}`).join("\n"));
|
|
4520
|
-
}
|
|
4521
|
-
if (errors > 0) if (report) warnMigration(`${errors === 1 ? "one file had an error" : `${errors} files had errors`} while rewriting imports`, report);
|
|
4522
|
-
else {
|
|
4523
|
-
log.warn(`⚠ ${errors === 1 ? "one file had an error" : `${errors} files had errors`}:`);
|
|
4524
|
-
for (const error of result.errors) log.error(` ${displayRelative(error.path)}: ${error.message}`);
|
|
4525
|
-
}
|
|
4526
|
-
}
|
|
4527
|
-
/**
|
|
4528
|
-
* Check if the project has an unsupported husky version (<9.0.0).
|
|
4529
|
-
* Uses `semver.coerce` to handle ranges like `^8.0.0` → `8.0.0`.
|
|
4530
|
-
* When the specifier is not coercible (e.g. `"latest"`), falls back to
|
|
4531
|
-
* the installed version in node_modules via `detectPackageMetadata`.
|
|
4532
|
-
* Returns a reason string if hooks migration should be skipped, or null
|
|
4533
|
-
* if husky is absent or compatible.
|
|
4534
|
-
*/
|
|
4535
|
-
function checkUnsupportedHuskyVersion(projectPath, deps, prodDeps) {
|
|
4536
|
-
const huskyVersion = deps?.husky ?? prodDeps?.husky;
|
|
4537
|
-
if (!huskyVersion) return null;
|
|
4538
|
-
let coerced = import_semver.default.coerce(huskyVersion);
|
|
4539
|
-
if (coerced == null) {
|
|
4540
|
-
const installed = detectPackageMetadata(projectPath, "husky");
|
|
4541
|
-
if (installed) coerced = import_semver.default.coerce(installed.version);
|
|
4542
|
-
if (coerced == null) return `Could not determine husky version from "${huskyVersion}" — please specify a semver-compatible version (e.g., "^9.0.0") and re-run migration.`;
|
|
4543
|
-
}
|
|
4544
|
-
if (import_semver.default.satisfies(coerced, "<9.0.0")) return "Detected husky <9.0.0 — please upgrade to husky v9+ first, then re-run migration.";
|
|
4545
|
-
return null;
|
|
4546
|
-
}
|
|
4547
|
-
const OTHER_HOOK_TOOLS = [
|
|
4548
|
-
"simple-git-hooks",
|
|
4549
|
-
"lefthook",
|
|
4550
|
-
"yorkie"
|
|
4551
|
-
];
|
|
4552
|
-
const REPLACED_HOOK_PACKAGES = ["husky", "lint-staged"];
|
|
4553
|
-
function removeReplacedHookPackages(packageJsonPath) {
|
|
4554
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
4555
|
-
for (const name of REPLACED_HOOK_PACKAGES) {
|
|
4556
|
-
if (pkg.devDependencies?.[name]) delete pkg.devDependencies[name];
|
|
4557
|
-
if (pkg.dependencies?.[name]) delete pkg.dependencies[name];
|
|
4558
|
-
}
|
|
4559
|
-
return pkg;
|
|
4560
|
-
});
|
|
4561
|
-
}
|
|
4562
|
-
/**
|
|
4563
|
-
* Walk up from `startPath` looking for `.git` (directory or file — submodules
|
|
4564
|
-
* use a `.git` file). Returns the directory that contains `.git`, or `null`.
|
|
4565
|
-
*/
|
|
4566
|
-
function findGitRoot(startPath) {
|
|
4567
|
-
let dir = startPath;
|
|
4568
|
-
while (true) {
|
|
4569
|
-
if (fs.existsSync(path.join(dir, ".git"))) return dir;
|
|
4570
|
-
const parent = path.dirname(dir);
|
|
4571
|
-
if (parent === dir) return null;
|
|
4572
|
-
dir = parent;
|
|
4573
|
-
}
|
|
4574
|
-
}
|
|
4575
|
-
/**
|
|
4576
|
-
* Normalize "husky install [dir]" → "husky [dir]" so downstream regex
|
|
4577
|
-
* and ast-grep rules can match a single pattern.
|
|
4578
|
-
*/
|
|
4579
|
-
function collapseHuskyInstall(script) {
|
|
4580
|
-
return script.replace("husky install ", "husky ").replace("husky install", "husky");
|
|
4581
|
-
}
|
|
4582
|
-
/**
|
|
4583
|
-
* High-level helper: detect old hooks dir, set up git hooks, and rewrite
|
|
4584
|
-
* the prepare script. Returns true if hooks were successfully installed.
|
|
4585
|
-
*/
|
|
4586
|
-
function installGitHooks(projectPath, silent = false, report) {
|
|
4587
|
-
if (setupGitHooks(projectPath, getOldHooksDir(projectPath), silent, report)) {
|
|
4588
|
-
rewritePrepareScript(projectPath);
|
|
4589
|
-
return true;
|
|
4590
|
-
}
|
|
4591
|
-
return false;
|
|
4592
|
-
}
|
|
4593
|
-
/**
|
|
4594
|
-
* Read-only probe: extract the old husky hooks directory from `scripts.prepare`
|
|
4595
|
-
* without modifying package.json. Returns undefined when no husky reference is found.
|
|
4596
|
-
*/
|
|
4597
|
-
function getOldHooksDir(rootDir) {
|
|
4598
|
-
const packageJsonPath = path.join(rootDir, "package.json");
|
|
4599
|
-
if (!fs.existsSync(packageJsonPath)) return;
|
|
4600
|
-
const pkg = readJsonFile(packageJsonPath);
|
|
4601
|
-
if (!pkg.scripts?.prepare) return;
|
|
4602
|
-
const match = collapseHuskyInstall(pkg.scripts.prepare).match(/\bhusky(?:\s+([\w./-]+))?/);
|
|
4603
|
-
if (!match) return;
|
|
4604
|
-
return match[1] ?? ".husky";
|
|
4605
|
-
}
|
|
4606
|
-
/**
|
|
4607
|
-
* Pre-flight check: verify that git hooks can be set up for this project.
|
|
4608
|
-
* Returns `null` if hooks setup can proceed, or a warning reason string
|
|
4609
|
-
* explaining why hooks setup should be skipped.
|
|
4610
|
-
*
|
|
4611
|
-
* These checks are deterministic and read-only — they do not modify
|
|
4612
|
-
* the project in any way, making them safe to call before migration.
|
|
4613
|
-
*/
|
|
4614
|
-
function preflightGitHooksSetup(projectPath) {
|
|
4615
|
-
const gitRoot = findGitRoot(projectPath);
|
|
4616
|
-
if (gitRoot && path.resolve(projectPath) !== path.resolve(gitRoot)) return "Subdirectory project detected — skipping git hooks setup. Configure hooks at the repository root.";
|
|
4617
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
4618
|
-
if (!fs.existsSync(packageJsonPath)) return null;
|
|
4619
|
-
const pkgContent = readJsonFile(packageJsonPath);
|
|
4620
|
-
const deps = pkgContent.devDependencies;
|
|
4621
|
-
const prodDeps = pkgContent.dependencies;
|
|
4622
|
-
for (const tool of OTHER_HOOK_TOOLS) if (deps?.[tool] || prodDeps?.[tool] || pkgContent[tool]) return `Detected ${tool} — skipping git hooks setup. Please configure git hooks manually.`;
|
|
4623
|
-
const huskyReason = checkUnsupportedHuskyVersion(projectPath, deps, prodDeps);
|
|
4624
|
-
if (huskyReason) return huskyReason;
|
|
4625
|
-
if (hasUnsupportedLintStagedConfig(projectPath)) return "Unsupported lint-staged config format — skipping git hooks setup. Please configure git hooks manually.";
|
|
4626
|
-
return null;
|
|
4627
|
-
}
|
|
4628
|
-
/**
|
|
4629
|
-
* Set up git hooks with husky + lint-staged via vp commands.
|
|
4630
|
-
* Skips if another hook tool is detected (warns user).
|
|
4631
|
-
* Returns true if hooks were successfully set up, false if skipped.
|
|
4632
|
-
*/
|
|
4633
|
-
function setupGitHooks(projectPath, oldHooksDir, silent = false, report) {
|
|
4634
|
-
const reason = preflightGitHooksSetup(projectPath);
|
|
4635
|
-
if (reason) {
|
|
4636
|
-
warnMigration(reason, report);
|
|
4637
|
-
return false;
|
|
4638
|
-
}
|
|
4639
|
-
const packageJsonPath = path.join(projectPath, "package.json");
|
|
4640
|
-
if (!fs.existsSync(packageJsonPath)) return false;
|
|
4641
|
-
const gitRoot = findGitRoot(projectPath);
|
|
4642
|
-
const isCustomDir = oldHooksDir != null && oldHooksDir !== ".husky";
|
|
4643
|
-
const hooksDir = isCustomDir ? oldHooksDir : ".vite-hooks";
|
|
4644
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
4645
|
-
if (!pkg.scripts) pkg.scripts = {};
|
|
4646
|
-
if (!pkg.scripts.prepare) pkg.scripts.prepare = "vp config";
|
|
4647
|
-
else if (!pkg.scripts.prepare.includes("vp config") && !/\bhusky\b/.test(pkg.scripts.prepare)) pkg.scripts.prepare = `vp config && ${pkg.scripts.prepare}`;
|
|
4648
|
-
return pkg;
|
|
4649
|
-
});
|
|
4650
|
-
let stagedMerged = hasStagedConfigInViteConfig(projectPath);
|
|
4651
|
-
const hasStandaloneConfig = hasStandaloneLintStagedConfig(projectPath);
|
|
4652
|
-
if (!stagedMerged && !hasStandaloneConfig) {
|
|
4653
|
-
const stagedConfig = readJsonFile(packageJsonPath)?.["lint-staged"] ?? DEFAULT_STAGED_CONFIG;
|
|
4654
|
-
const updated = rewriteScripts(JSON.stringify(stagedConfig), readRulesYaml());
|
|
4655
|
-
stagedMerged = mergeStagedConfigToViteConfig(projectPath, updated ? JSON.parse(updated) : stagedConfig, silent, report);
|
|
4656
|
-
}
|
|
4657
|
-
if (stagedMerged) removeLintStagedFromPackageJson(packageJsonPath);
|
|
4658
|
-
if (oldHooksDir && !isCustomDir) {
|
|
4659
|
-
const oldDir = path.join(projectPath, oldHooksDir);
|
|
4660
|
-
if (fs.existsSync(oldDir)) {
|
|
4661
|
-
const targetDir = path.join(projectPath, hooksDir);
|
|
4662
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
4663
|
-
for (const entry of fs.readdirSync(oldDir, { withFileTypes: true })) {
|
|
4664
|
-
if (entry.isDirectory() || entry.name.startsWith(".")) continue;
|
|
4665
|
-
const src = path.join(oldDir, entry.name);
|
|
4666
|
-
const dest = path.join(targetDir, entry.name);
|
|
4667
|
-
fs.copyFileSync(src, dest);
|
|
4668
|
-
fs.chmodSync(dest, 493);
|
|
4669
|
-
}
|
|
4670
|
-
fs.rmSync(oldDir, {
|
|
4671
|
-
recursive: true,
|
|
4672
|
-
force: true
|
|
4673
|
-
});
|
|
4674
|
-
}
|
|
4675
|
-
}
|
|
4676
|
-
if (stagedMerged) createPreCommitHook(projectPath, hooksDir);
|
|
4677
|
-
if (!gitRoot) {
|
|
4678
|
-
removeReplacedHookPackages(packageJsonPath);
|
|
4679
|
-
return true;
|
|
4680
|
-
}
|
|
4681
|
-
if (oldHooksDir) {
|
|
4682
|
-
const checkResult = import_cross_spawn.default.sync("git", [
|
|
4683
|
-
"config",
|
|
4684
|
-
"--local",
|
|
4685
|
-
"core.hooksPath"
|
|
4686
|
-
], {
|
|
4687
|
-
cwd: projectPath,
|
|
4688
|
-
stdio: "pipe"
|
|
4689
|
-
});
|
|
4690
|
-
const existingPath = checkResult.status === 0 ? checkResult.stdout?.toString().trim() : "";
|
|
4691
|
-
if (existingPath === `${oldHooksDir}/_` || existingPath === oldHooksDir) import_cross_spawn.default.sync("git", [
|
|
4692
|
-
"config",
|
|
4693
|
-
"--local",
|
|
4694
|
-
"--unset",
|
|
4695
|
-
"core.hooksPath"
|
|
4696
|
-
], {
|
|
4697
|
-
cwd: projectPath,
|
|
4698
|
-
stdio: "pipe"
|
|
4699
|
-
});
|
|
4700
|
-
}
|
|
4701
|
-
const vpBin = process.env.VP_CLI_BIN ?? "vp";
|
|
4702
|
-
const configArgs = isCustomDir ? [
|
|
4703
|
-
"config",
|
|
4704
|
-
"--hooks-only",
|
|
4705
|
-
"--hooks-dir",
|
|
4706
|
-
hooksDir
|
|
4707
|
-
] : ["config", "--hooks-only"];
|
|
4708
|
-
const configResult = import_cross_spawn.default.sync(vpBin, configArgs, {
|
|
4709
|
-
cwd: projectPath,
|
|
4710
|
-
stdio: "pipe"
|
|
4711
|
-
});
|
|
4712
|
-
if (configResult.status === 0) {
|
|
4713
|
-
const stdout = configResult.stdout?.toString().trim() ?? "";
|
|
4714
|
-
if (stdout) {
|
|
4715
|
-
warnMigration(`Git hooks not configured — ${stdout}`, report);
|
|
4716
|
-
return false;
|
|
4717
|
-
}
|
|
4718
|
-
removeReplacedHookPackages(packageJsonPath);
|
|
4719
|
-
if (report) report.gitHooksConfigured = true;
|
|
4720
|
-
if (!silent) log.success("✔ Git hooks configured");
|
|
4721
|
-
return true;
|
|
4722
|
-
}
|
|
4723
|
-
warnMigration("Failed to install git hooks", report);
|
|
4724
|
-
return false;
|
|
4725
|
-
}
|
|
4726
|
-
/**
|
|
4727
|
-
* Check if a standalone lint-staged config file exists
|
|
4728
|
-
*/
|
|
4729
|
-
function hasStandaloneLintStagedConfig(projectPath) {
|
|
4730
|
-
return LINT_STAGED_ALL_CONFIG_FILES.some((file) => fs.existsSync(path.join(projectPath, file)));
|
|
4731
|
-
}
|
|
4732
|
-
/**
|
|
4733
|
-
* Check if a standalone lint-staged config exists in a format that can't be
|
|
4734
|
-
* auto-migrated to "staged" in vite.config.ts (non-JSON files like .yaml,
|
|
4735
|
-
* .mjs, .cjs, .js, or a non-JSON .lintstagedrc).
|
|
4736
|
-
*/
|
|
4737
|
-
function hasUnsupportedLintStagedConfig(projectPath) {
|
|
4738
|
-
for (const filename of LINT_STAGED_OTHER_CONFIG_FILES) if (fs.existsSync(path.join(projectPath, filename))) return true;
|
|
4739
|
-
const lintstagedrcPath = path.join(projectPath, ".lintstagedrc");
|
|
4740
|
-
if (fs.existsSync(lintstagedrcPath) && !isJsonFile(lintstagedrcPath)) return true;
|
|
4741
|
-
return false;
|
|
4742
|
-
}
|
|
4743
|
-
/**
|
|
4744
|
-
* Create pre-commit hook file in the hooks directory.
|
|
4745
|
-
*/
|
|
4746
|
-
const STALE_LINT_STAGED_PATTERNS = [/^((?:[A-Z_][A-Z0-9_]*(?:=\S*)?\s+)*)(pnpm|pnpm exec|npx|yarn|yarn run|npm exec|npm run|bunx|bun run|bun x)\s+lint-staged\b/, /^((?:[A-Z_][A-Z0-9_]*(?:=\S*)?\s+)*)lint-staged\b/];
|
|
4747
|
-
const DEFAULT_STAGED_CONFIG = { "*": "vp check --fix" };
|
|
4748
|
-
/**
|
|
4749
|
-
* Ensure the pre-commit hook exists with `vp staged`, and that
|
|
4750
|
-
* vite.config.ts contains a `staged` block (using the default config
|
|
4751
|
-
* if none is present). Called by `vp config` after hook installation.
|
|
4752
|
-
*/
|
|
4753
|
-
function ensurePreCommitHook(projectPath, dir = ".vite-hooks") {
|
|
4754
|
-
if (!hasStagedConfigInViteConfig(projectPath)) mergeStagedConfigToViteConfig(projectPath, DEFAULT_STAGED_CONFIG, true);
|
|
4755
|
-
createPreCommitHook(projectPath, dir);
|
|
4756
|
-
}
|
|
4757
|
-
function createPreCommitHook(projectPath, dir = ".vite-hooks") {
|
|
4758
|
-
const huskyDir = path.join(projectPath, dir);
|
|
4759
|
-
fs.mkdirSync(huskyDir, { recursive: true });
|
|
4760
|
-
const hookPath = path.join(huskyDir, "pre-commit");
|
|
4761
|
-
if (fs.existsSync(hookPath)) {
|
|
4762
|
-
const existing = fs.readFileSync(hookPath, "utf8");
|
|
4763
|
-
if (existing.includes("vp staged")) return;
|
|
4764
|
-
const lines = existing.split("\n");
|
|
4765
|
-
let replaced = false;
|
|
4766
|
-
const result = [];
|
|
4767
|
-
for (const line of lines) {
|
|
4768
|
-
const trimmed = line.trim();
|
|
4769
|
-
if (!replaced) {
|
|
4770
|
-
let matched = false;
|
|
4771
|
-
for (const pattern of STALE_LINT_STAGED_PATTERNS) {
|
|
4772
|
-
const match = pattern.exec(trimmed);
|
|
4773
|
-
if (match) {
|
|
4774
|
-
const parts = [
|
|
4775
|
-
match[1]?.trim() ?? "",
|
|
4776
|
-
"vp staged",
|
|
4777
|
-
trimmed.slice(match[0].length).trim()
|
|
4778
|
-
].filter(Boolean);
|
|
4779
|
-
result.push(parts.join(" "));
|
|
4780
|
-
replaced = true;
|
|
4781
|
-
matched = true;
|
|
4782
|
-
break;
|
|
4783
|
-
}
|
|
4784
|
-
}
|
|
4785
|
-
if (matched) continue;
|
|
4786
|
-
}
|
|
4787
|
-
result.push(line);
|
|
4788
|
-
}
|
|
4789
|
-
if (!replaced) fs.writeFileSync(hookPath, `${result.join("\n").trimEnd()}\nvp staged\n`);
|
|
4790
|
-
else fs.writeFileSync(hookPath, result.join("\n"));
|
|
4791
|
-
} else {
|
|
4792
|
-
fs.writeFileSync(hookPath, "vp staged\n");
|
|
4793
|
-
fs.chmodSync(hookPath, 493);
|
|
4794
|
-
}
|
|
4795
|
-
}
|
|
4796
|
-
/**
|
|
4797
|
-
* Rewrite only `scripts.prepare` in the root package.json using vite-prepare.yml rules.
|
|
4798
|
-
* Collapses "husky install" → "husky" before applying ast-grep so that the
|
|
4799
|
-
* replace-husky rule produces "vp config" with any directory argument preserved.
|
|
4800
|
-
* Returns the old husky hooks dir (if any) for migration to .vite-hooks.
|
|
4801
|
-
* Called only when hooks are being set up (not with --no-hooks).
|
|
4802
|
-
*/
|
|
4803
|
-
function rewritePrepareScript(rootDir) {
|
|
4804
|
-
const packageJsonPath = path.join(rootDir, "package.json");
|
|
4805
|
-
if (!fs.existsSync(packageJsonPath)) return;
|
|
4806
|
-
let oldDir;
|
|
4807
|
-
editJsonFile(packageJsonPath, (pkg) => {
|
|
4808
|
-
if (!pkg.scripts?.prepare) return pkg;
|
|
4809
|
-
const prepare = collapseHuskyInstall(pkg.scripts.prepare);
|
|
4810
|
-
const updated = rewriteScripts(JSON.stringify({ prepare }), readPrepareRulesYaml());
|
|
4811
|
-
if (updated) {
|
|
4812
|
-
let newPrepare = JSON.parse(updated).prepare;
|
|
4813
|
-
newPrepare = newPrepare.replace(/\bvp config(?:\s+(?!-)([\w./-]+))?/, (_match, dir) => {
|
|
4814
|
-
oldDir = dir ?? ".husky";
|
|
4815
|
-
return dir ? `vp config --hooks-dir ${dir}` : "vp config";
|
|
4816
|
-
});
|
|
4817
|
-
pkg.scripts.prepare = newPrepare;
|
|
4818
|
-
} else if (prepare !== pkg.scripts.prepare) pkg.scripts.prepare = prepare;
|
|
4819
|
-
return pkg;
|
|
4820
|
-
});
|
|
4821
|
-
return oldDir;
|
|
4822
|
-
}
|
|
4823
|
-
function setPackageManager(projectDir, downloadPackageManager) {
|
|
4824
|
-
editJsonFile(path.join(projectDir, "package.json"), (pkg) => {
|
|
4825
|
-
if (!pkg.packageManager) pkg.packageManager = `${downloadPackageManager.name}@${downloadPackageManager.version}`;
|
|
4826
|
-
return pkg;
|
|
4827
|
-
});
|
|
4828
|
-
}
|
|
4829
|
-
/**
|
|
4830
|
-
* Detect a .nvmrc file in the project directory.
|
|
4831
|
-
* If not found, check for a Volta node version in package.json.
|
|
4832
|
-
* If either is found, return the relevant info for migration.
|
|
4833
|
-
* Returns undefined if not found or .node-version already exists.
|
|
4834
|
-
*/
|
|
4835
|
-
function detectNodeVersionManagerFile(projectPath) {
|
|
4836
|
-
if (fs.existsSync(path.join(projectPath, ".node-version"))) return;
|
|
4837
|
-
const configs = detectConfigs(projectPath);
|
|
4838
|
-
if (configs.nvmrcFile) return configs.voltaNode ? {
|
|
4839
|
-
file: ".nvmrc",
|
|
4840
|
-
voltaPresent: true
|
|
4841
|
-
} : { file: ".nvmrc" };
|
|
4842
|
-
if (configs.voltaNode) return {
|
|
4843
|
-
file: "package.json",
|
|
4844
|
-
voltaNodeVersion: configs.voltaNode
|
|
4845
|
-
};
|
|
4846
|
-
}
|
|
4847
|
-
/**
|
|
4848
|
-
* Parse a version alias from a .nvmrc file into a .node-version compatible string.
|
|
4849
|
-
* Accepts the first line of .nvmrc (pre-trimmed).
|
|
4850
|
-
* Returns null for unsupported aliases like "system", "default", "iojs".
|
|
4851
|
-
*/
|
|
4852
|
-
function parseNvmrcVersion(alias) {
|
|
4853
|
-
const version = alias.trim();
|
|
4854
|
-
if (!version) return null;
|
|
4855
|
-
if (version === "node" || version === "stable") return "lts/*";
|
|
4856
|
-
if (version === "iojs" || version === "system" || version === "default") return null;
|
|
4857
|
-
if (version.startsWith("lts/")) return version;
|
|
4858
|
-
const normalized = version.startsWith("v") ? version.slice(1) : version;
|
|
4859
|
-
if (!normalized || !import_semver.default.validRange(normalized)) return null;
|
|
4860
|
-
return normalized;
|
|
4861
|
-
}
|
|
4862
|
-
/**
|
|
4863
|
-
* Migrate .nvmrc or Volta node version from package.json to .node-version.
|
|
4864
|
-
* - For .nvmrc: the source file is removed after migration.
|
|
4865
|
-
* - For package.json (Volta): the volta field is left as-is; removal is left to the user's discretion.
|
|
4866
|
-
* Returns true on success, false if migration was skipped or failed.
|
|
4867
|
-
*/
|
|
4868
|
-
function migrateNodeVersionManagerFile(projectPath, detection, report) {
|
|
4869
|
-
const nodeVersionPath = path.join(projectPath, ".node-version");
|
|
4870
|
-
if (detection.file === "package.json") {
|
|
4871
|
-
const { voltaNodeVersion } = detection;
|
|
4872
|
-
const resolvedVersion = voltaNodeVersion === "lts" ? "lts/*" : voltaNodeVersion;
|
|
4873
|
-
if (!import_semver.default.valid(resolvedVersion) && resolvedVersion !== "lts/*") {
|
|
4874
|
-
warnMigration(`package.json volta.node "${voltaNodeVersion}" is not an exact version. Pin an exact version (e.g. ${voltaNodeVersion}.0 or run \`volta pin node@${voltaNodeVersion}\`) then re-run migration.`, report);
|
|
4875
|
-
return false;
|
|
4876
|
-
}
|
|
4877
|
-
fs.writeFileSync(nodeVersionPath, `${resolvedVersion}\n`);
|
|
4878
|
-
if (report) {
|
|
4879
|
-
report.manualSteps.push("Remove the \"volta\" field from package.json");
|
|
4880
|
-
report.nodeVersionFileMigrated = true;
|
|
4881
|
-
} else log.info("You can now remove the \"volta\" field from package.json manually.");
|
|
4882
|
-
return true;
|
|
4883
|
-
}
|
|
4884
|
-
const sourcePath = path.join(projectPath, ".nvmrc");
|
|
4885
|
-
const originalAlias = fs.readFileSync(sourcePath, "utf8").split("\n")[0]?.trim() ?? "";
|
|
4886
|
-
const version = parseNvmrcVersion(originalAlias);
|
|
4887
|
-
if (!version) {
|
|
4888
|
-
warnMigration(".nvmrc contains an unsupported version alias. Create .node-version manually with your desired Node.js version.", report);
|
|
4889
|
-
return false;
|
|
4890
|
-
}
|
|
4891
|
-
if (version === "lts/*" && (originalAlias === "node" || originalAlias === "stable")) log.info(`"${originalAlias}" in .nvmrc is not a specific version; automatically mapping to "lts/*"`);
|
|
4892
|
-
fs.writeFileSync(nodeVersionPath, `${version}\n`);
|
|
4893
|
-
fs.unlinkSync(sourcePath);
|
|
4894
|
-
if (report) {
|
|
4895
|
-
report.nodeVersionFileMigrated = true;
|
|
4896
|
-
if (detection.voltaPresent) report.manualSteps.push("Remove the \"volta\" field from package.json");
|
|
4897
|
-
} else if (detection.voltaPresent) log.info("You can now remove the \"volta\" field from package.json manually.");
|
|
4898
|
-
return true;
|
|
4899
|
-
}
|
|
4900
|
-
function warnPackageLevelEslint() {
|
|
4901
|
-
log.warn("ESLint detected in workspace packages but no root config found. Package-level ESLint must be migrated manually.");
|
|
4902
|
-
}
|
|
4903
|
-
function warnLegacyEslintConfig(legacyConfigFile) {
|
|
4904
|
-
log.warn(`Legacy ESLint configuration detected (${legacyConfigFile}). Automatic migration to Oxlint requires ESLint v9+ with flat config format (eslint.config.*). Please upgrade to ESLint v9 first: https://eslint.org/docs/latest/use/migrate-to-9.0.0`);
|
|
4905
|
-
}
|
|
4906
|
-
async function confirmEslintMigration(interactive) {
|
|
4907
|
-
if (interactive) {
|
|
4908
|
-
const confirmed = await confirm({
|
|
4909
|
-
message: "Migrate ESLint rules to Oxlint using @oxlint/migrate?\n " + styleText("gray", "Oxlint is Vite+'s built-in linter — significantly faster than ESLint with compatible rule support. @oxlint/migrate converts your existing rules automatically."),
|
|
4910
|
-
initialValue: true
|
|
4911
|
-
});
|
|
4912
|
-
if (q(confirmed)) cancelAndExit();
|
|
4913
|
-
return confirmed;
|
|
4914
|
-
}
|
|
4915
|
-
return true;
|
|
4916
|
-
}
|
|
4917
|
-
async function promptEslintMigration(projectPath, interactive, packages) {
|
|
4918
|
-
const eslintProject = detectEslintProject(projectPath, packages);
|
|
4919
|
-
if (eslintProject.hasDependency && !eslintProject.configFile && eslintProject.legacyConfigFile) {
|
|
4920
|
-
warnLegacyEslintConfig(eslintProject.legacyConfigFile);
|
|
4921
|
-
return false;
|
|
4922
|
-
}
|
|
4923
|
-
if (!eslintProject.hasDependency) return false;
|
|
4924
|
-
if (!eslintProject.configFile) {
|
|
4925
|
-
warnPackageLevelEslint();
|
|
4926
|
-
return false;
|
|
4927
|
-
}
|
|
4928
|
-
if (!await confirmEslintMigration(interactive)) return false;
|
|
4929
|
-
if (!await migrateEslintToOxlint(projectPath, interactive, eslintProject.configFile, packages)) cancelAndExit("ESLint migration failed.", 1);
|
|
4930
|
-
return true;
|
|
4931
|
-
}
|
|
4932
|
-
function warnPackageLevelPrettier() {
|
|
4933
|
-
log.warn("Prettier detected in workspace packages but no root config found. Package-level Prettier must be migrated manually.");
|
|
4934
|
-
}
|
|
4935
|
-
async function confirmPrettierMigration(interactive) {
|
|
4936
|
-
if (interactive) {
|
|
4937
|
-
const confirmed = await confirm({
|
|
4938
|
-
message: "Migrate Prettier to Oxfmt?\n " + styleText("gray", "Oxfmt is Vite+'s built-in formatter that replaces Prettier with faster performance. Your configuration will be converted automatically."),
|
|
4939
|
-
initialValue: true
|
|
4940
|
-
});
|
|
4941
|
-
if (q(confirmed)) cancelAndExit();
|
|
4942
|
-
return confirmed;
|
|
4943
|
-
}
|
|
4944
|
-
log.info("Prettier configuration detected. Auto-migrating to Oxfmt...");
|
|
4945
|
-
return true;
|
|
4946
|
-
}
|
|
4947
|
-
async function promptPrettierMigration(projectPath, interactive, packages) {
|
|
4948
|
-
const prettierProject = detectPrettierProject(projectPath, packages);
|
|
4949
|
-
if (!prettierProject.hasDependency) return false;
|
|
4950
|
-
if (!prettierProject.configFile) {
|
|
4951
|
-
warnPackageLevelPrettier();
|
|
3805
|
+
text = fs.readFileSync(filePath, "utf-8");
|
|
3806
|
+
} catch {
|
|
4952
3807
|
return false;
|
|
4953
3808
|
}
|
|
4954
|
-
|
|
4955
|
-
if (!
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
const
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
"
|
|
4970
|
-
"
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
"opencode",
|
|
4977
|
-
"other"
|
|
4978
|
-
]
|
|
4979
|
-
},
|
|
4980
|
-
{
|
|
4981
|
-
id: "claude",
|
|
4982
|
-
label: "CLAUDE.md",
|
|
4983
|
-
targetPath: "CLAUDE.md",
|
|
4984
|
-
hint: "Claude Code",
|
|
4985
|
-
aliases: ["claude.md", "claude-code"]
|
|
4986
|
-
},
|
|
4987
|
-
{
|
|
4988
|
-
id: "gemini",
|
|
4989
|
-
label: "GEMINI.md",
|
|
4990
|
-
targetPath: "GEMINI.md",
|
|
4991
|
-
hint: "Gemini CLI",
|
|
4992
|
-
aliases: ["gemini.md", "gemini-cli"]
|
|
4993
|
-
},
|
|
4994
|
-
{
|
|
4995
|
-
id: "copilot",
|
|
4996
|
-
label: ".github/copilot-instructions.md",
|
|
4997
|
-
targetPath: ".github/copilot-instructions.md",
|
|
4998
|
-
hint: "GitHub Copilot",
|
|
4999
|
-
aliases: ["github-copilot", "copilot-instructions.md"]
|
|
5000
|
-
},
|
|
5001
|
-
{
|
|
5002
|
-
id: "cursor",
|
|
5003
|
-
label: ".cursor/rules/viteplus.mdc",
|
|
5004
|
-
targetPath: ".cursor/rules/viteplus.mdc",
|
|
5005
|
-
hint: "Cursor",
|
|
5006
|
-
aliases: ["viteplus.mdc"]
|
|
5007
|
-
},
|
|
5008
|
-
{
|
|
5009
|
-
id: "jetbrains",
|
|
5010
|
-
label: ".aiassistant/rules/viteplus.md",
|
|
5011
|
-
targetPath: ".aiassistant/rules/viteplus.md",
|
|
5012
|
-
hint: "JetBrains AI Assistant",
|
|
5013
|
-
aliases: [
|
|
5014
|
-
"jetbrains",
|
|
5015
|
-
"jetbrains-ai-assistant",
|
|
5016
|
-
"aiassistant",
|
|
5017
|
-
"viteplus.md"
|
|
5018
|
-
]
|
|
5019
|
-
}
|
|
5020
|
-
];
|
|
5021
|
-
const AGENT_DEFAULT_ID = "agents";
|
|
5022
|
-
const AGENT_STANDARD_PATH = "AGENTS.md";
|
|
5023
|
-
const AGENT_INSTRUCTIONS_START_MARKER = "<!--VITE PLUS START-->";
|
|
5024
|
-
const AGENT_INSTRUCTIONS_END_MARKER = "<!--VITE PLUS END-->";
|
|
5025
|
-
const AGENT_ALIASES = Object.fromEntries(AGENTS.flatMap((option) => (option.aliases ?? []).map((alias) => [normalizeAgentName(alias), option.id])));
|
|
5026
|
-
async function selectAgentTargetPaths({ interactive, agent, onCancel }) {
|
|
5027
|
-
if (agent === false) return;
|
|
5028
|
-
if (interactive && !agent) {
|
|
5029
|
-
const selectedAgents = await multiselect({
|
|
5030
|
-
message: "Which coding agent instruction files should Vite+ create?",
|
|
5031
|
-
options: AGENTS.map((option) => ({
|
|
5032
|
-
label: option.label,
|
|
5033
|
-
value: option.id,
|
|
5034
|
-
hint: option.hint
|
|
5035
|
-
})),
|
|
5036
|
-
initialValues: [AGENT_DEFAULT_ID],
|
|
5037
|
-
required: false
|
|
5038
|
-
});
|
|
5039
|
-
if (q(selectedAgents)) {
|
|
5040
|
-
onCancel();
|
|
5041
|
-
return;
|
|
5042
|
-
}
|
|
5043
|
-
if (selectedAgents.length === 0) return;
|
|
5044
|
-
return resolveAgentTargetPaths(selectedAgents);
|
|
5045
|
-
}
|
|
5046
|
-
return resolveAgentTargetPaths(agent ?? AGENT_DEFAULT_ID);
|
|
5047
|
-
}
|
|
5048
|
-
function detectExistingAgentTargetPaths(projectRoot) {
|
|
5049
|
-
const detectedPaths = [];
|
|
5050
|
-
const seenTargetPaths = /* @__PURE__ */ new Set();
|
|
5051
|
-
for (const option of AGENTS) {
|
|
5052
|
-
if (seenTargetPaths.has(option.targetPath)) continue;
|
|
5053
|
-
seenTargetPaths.add(option.targetPath);
|
|
5054
|
-
const targetPath = path.join(projectRoot, option.targetPath);
|
|
5055
|
-
if (fs.existsSync(targetPath) && !fs.lstatSync(targetPath).isSymbolicLink()) detectedPaths.push(option.targetPath);
|
|
5056
|
-
}
|
|
5057
|
-
return detectedPaths.length > 0 ? detectedPaths : void 0;
|
|
5058
|
-
}
|
|
5059
|
-
/**
|
|
5060
|
-
* Silently update agent instruction files that contain Vite+ markers.
|
|
5061
|
-
* - No agent files → no writes
|
|
5062
|
-
* - No Vite+ markers → no writes
|
|
5063
|
-
* - Markers present, content up to date → no writes
|
|
5064
|
-
* - Markers present, content outdated → update marked section
|
|
5065
|
-
*/
|
|
5066
|
-
function updateExistingAgentInstructions(projectRoot) {
|
|
5067
|
-
const targetPaths = detectExistingAgentTargetPaths(projectRoot);
|
|
5068
|
-
if (!targetPaths) return;
|
|
5069
|
-
const templatePath = path.join(pkgRoot, "AGENTS.md");
|
|
5070
|
-
if (!fs.existsSync(templatePath)) return;
|
|
5071
|
-
const templateContent = fs.readFileSync(templatePath, "utf-8");
|
|
5072
|
-
for (const targetPath of targetPaths) try {
|
|
5073
|
-
const fullPath = path.join(projectRoot, targetPath);
|
|
5074
|
-
const existing = fs.readFileSync(fullPath, "utf-8");
|
|
5075
|
-
const updated = replaceMarkedAgentInstructionsSection(existing, templateContent);
|
|
5076
|
-
if (updated !== void 0 && updated !== existing) fs.writeFileSync(fullPath, updated);
|
|
5077
|
-
} catch {}
|
|
5078
|
-
}
|
|
5079
|
-
function resolveAgentTargetPaths(agent) {
|
|
5080
|
-
const agentNames = parseAgentNames(agent);
|
|
5081
|
-
const resolvedAgentNames = agentNames.length > 0 ? agentNames : ["other"];
|
|
5082
|
-
const dedupedTargetPaths = [];
|
|
5083
|
-
const seenTargetPaths = /* @__PURE__ */ new Set();
|
|
5084
|
-
for (const name of resolvedAgentNames) {
|
|
5085
|
-
const targetPath = resolveSingleAgentTargetPath(name);
|
|
5086
|
-
if (seenTargetPaths.has(targetPath)) continue;
|
|
5087
|
-
seenTargetPaths.add(targetPath);
|
|
5088
|
-
dedupedTargetPaths.push(targetPath);
|
|
5089
|
-
}
|
|
5090
|
-
return dedupedTargetPaths;
|
|
5091
|
-
}
|
|
5092
|
-
function parseAgentNames(agent) {
|
|
5093
|
-
if (!agent) return [];
|
|
5094
|
-
return (Array.isArray(agent) ? agent : [agent]).filter((value) => typeof value === "string").flatMap((value) => value.split(",")).map((value) => value.trim()).filter((value) => value.length > 0);
|
|
5095
|
-
}
|
|
5096
|
-
function resolveSingleAgentTargetPath(agent) {
|
|
5097
|
-
const normalized = normalizeAgentName(agent);
|
|
5098
|
-
const alias = AGENT_ALIASES[normalized];
|
|
5099
|
-
const resolved = alias ? normalizeAgentName(alias) : normalized;
|
|
5100
|
-
return AGENTS.find((option) => normalizeAgentName(option.id) === resolved || normalizeAgentName(option.label) === resolved || normalizeAgentName(option.targetPath) === resolved || option.aliases?.some((candidate) => normalizeAgentName(candidate) === resolved))?.targetPath ?? AGENT_STANDARD_PATH;
|
|
5101
|
-
}
|
|
5102
|
-
/**
|
|
5103
|
-
* Detect agent instruction files that would conflict (exist without markers).
|
|
5104
|
-
* Returns only files that need a user decision (append or skip).
|
|
5105
|
-
* Read-only — does not write or modify any files.
|
|
5106
|
-
*/
|
|
5107
|
-
async function detectAgentConflicts({ projectRoot, targetPaths }) {
|
|
5108
|
-
if (!targetPaths || targetPaths.length === 0) return [];
|
|
5109
|
-
const sourcePath = path.join(pkgRoot, "AGENTS.md");
|
|
5110
|
-
if (!fs.existsSync(sourcePath)) return [];
|
|
5111
|
-
const incomingContent = await fsPromises.readFile(sourcePath, "utf-8");
|
|
5112
|
-
const shouldLinkToAgents = targetPaths.includes(AGENT_STANDARD_PATH);
|
|
5113
|
-
const orderedPaths = shouldLinkToAgents ? [AGENT_STANDARD_PATH, ...targetPaths.filter((p) => p !== AGENT_STANDARD_PATH)] : targetPaths;
|
|
5114
|
-
const conflicts = [];
|
|
5115
|
-
const seenDestinationPaths = /* @__PURE__ */ new Set();
|
|
5116
|
-
const seenRealPaths = /* @__PURE__ */ new Set();
|
|
5117
|
-
for (const targetPathToCheck of orderedPaths) {
|
|
5118
|
-
const destinationPath = path.join(projectRoot, targetPathToCheck);
|
|
5119
|
-
const destinationKey = path.resolve(destinationPath);
|
|
5120
|
-
if (seenDestinationPaths.has(destinationKey)) continue;
|
|
5121
|
-
seenDestinationPaths.add(destinationKey);
|
|
5122
|
-
if (shouldLinkToAgents && targetPathToCheck !== AGENT_STANDARD_PATH) {
|
|
5123
|
-
if (await getExistingPathKind(destinationPath) !== "file") continue;
|
|
5124
|
-
}
|
|
5125
|
-
if (fs.existsSync(destinationPath)) {
|
|
5126
|
-
if (fs.lstatSync(destinationPath).isSymbolicLink()) continue;
|
|
5127
|
-
const destinationRealPath = await fsPromises.realpath(destinationPath);
|
|
5128
|
-
if (seenRealPaths.has(destinationRealPath)) continue;
|
|
5129
|
-
if (replaceMarkedAgentInstructionsSection(await fsPromises.readFile(destinationPath, "utf-8"), incomingContent) !== void 0) {
|
|
5130
|
-
seenRealPaths.add(destinationRealPath);
|
|
5131
|
-
continue;
|
|
5132
|
-
}
|
|
5133
|
-
conflicts.push({ targetPath: targetPathToCheck });
|
|
5134
|
-
seenRealPaths.add(destinationRealPath);
|
|
5135
|
-
}
|
|
5136
|
-
}
|
|
5137
|
-
return conflicts;
|
|
5138
|
-
}
|
|
5139
|
-
async function writeAgentInstructions({ projectRoot, targetPath, targetPaths, interactive, conflictDecisions, silent = false }) {
|
|
5140
|
-
const paths = [...targetPaths ?? [], ...targetPath ? [targetPath] : []];
|
|
5141
|
-
if (paths.length === 0) return;
|
|
5142
|
-
const sourcePath = path.join(pkgRoot, "AGENTS.md");
|
|
5143
|
-
if (!fs.existsSync(sourcePath)) {
|
|
5144
|
-
if (!silent) log.warn("Agent instructions template not found; skipping.");
|
|
5145
|
-
return;
|
|
5146
|
-
}
|
|
5147
|
-
const seenDestinationPaths = /* @__PURE__ */ new Set();
|
|
5148
|
-
const seenRealPaths = /* @__PURE__ */ new Set();
|
|
5149
|
-
const incomingContent = await fsPromises.readFile(sourcePath, "utf-8");
|
|
5150
|
-
const shouldLinkToAgents = paths.includes(AGENT_STANDARD_PATH);
|
|
5151
|
-
const orderedPaths = shouldLinkToAgents ? [AGENT_STANDARD_PATH, ...paths.filter((p) => p !== AGENT_STANDARD_PATH)] : paths;
|
|
5152
|
-
for (const targetPathToWrite of orderedPaths) {
|
|
5153
|
-
const destinationPath = path.join(projectRoot, targetPathToWrite);
|
|
5154
|
-
const destinationKey = path.resolve(destinationPath);
|
|
5155
|
-
if (seenDestinationPaths.has(destinationKey)) continue;
|
|
5156
|
-
seenDestinationPaths.add(destinationKey);
|
|
5157
|
-
await fsPromises.mkdir(path.dirname(destinationPath), { recursive: true });
|
|
5158
|
-
if (shouldLinkToAgents && targetPathToWrite !== AGENT_STANDARD_PATH) {
|
|
5159
|
-
if (await tryLinkTargetToAgents(projectRoot, targetPathToWrite, silent)) continue;
|
|
5160
|
-
}
|
|
5161
|
-
if (fs.existsSync(destinationPath)) {
|
|
5162
|
-
if (fs.lstatSync(destinationPath).isSymbolicLink()) {
|
|
5163
|
-
if (!silent) log.info(`Skipped writing ${targetPathToWrite} (symlink)`);
|
|
5164
|
-
continue;
|
|
5165
|
-
}
|
|
5166
|
-
const destinationRealPath = await fsPromises.realpath(destinationPath);
|
|
5167
|
-
if (seenRealPaths.has(destinationRealPath)) {
|
|
5168
|
-
if (!silent) log.info(`Skipped writing ${targetPathToWrite} (duplicate target)`);
|
|
5169
|
-
continue;
|
|
5170
|
-
}
|
|
5171
|
-
const existingContent = await fsPromises.readFile(destinationPath, "utf-8");
|
|
5172
|
-
const updatedContent = replaceMarkedAgentInstructionsSection(existingContent, incomingContent);
|
|
5173
|
-
if (updatedContent !== void 0) {
|
|
5174
|
-
if (updatedContent !== existingContent) await fsPromises.writeFile(destinationPath, updatedContent);
|
|
5175
|
-
seenRealPaths.add(destinationRealPath);
|
|
5176
|
-
continue;
|
|
5177
|
-
}
|
|
5178
|
-
let conflictAction;
|
|
5179
|
-
const preResolved = conflictDecisions?.get(targetPathToWrite);
|
|
5180
|
-
if (preResolved) conflictAction = preResolved;
|
|
5181
|
-
else if (interactive) {
|
|
5182
|
-
const action = await select({
|
|
5183
|
-
message: `Agent instructions already exist at ${targetPathToWrite}.\n ` + styleText("gray", "The Vite+ template includes guidance on `vp` commands, the build pipeline, and project conventions."),
|
|
5184
|
-
options: [{
|
|
5185
|
-
label: "Append",
|
|
5186
|
-
value: "append",
|
|
5187
|
-
hint: "Add template content to the end"
|
|
5188
|
-
}, {
|
|
5189
|
-
label: "Skip",
|
|
5190
|
-
value: "skip",
|
|
5191
|
-
hint: "Leave existing file unchanged"
|
|
5192
|
-
}],
|
|
5193
|
-
initialValue: "skip"
|
|
5194
|
-
});
|
|
5195
|
-
conflictAction = q(action) || action === "skip" ? "skip" : "append";
|
|
5196
|
-
} else conflictAction = "skip";
|
|
5197
|
-
if (conflictAction === "append") await appendAgentContent(destinationPath, targetPathToWrite, existingContent, incomingContent, silent);
|
|
5198
|
-
else {
|
|
5199
|
-
const suffix = !preResolved && !interactive ? " (already exists)" : "";
|
|
5200
|
-
if (!silent) log.info(`Skipped writing ${targetPathToWrite}${suffix}`);
|
|
5201
|
-
}
|
|
5202
|
-
seenRealPaths.add(destinationRealPath);
|
|
5203
|
-
continue;
|
|
5204
|
-
}
|
|
5205
|
-
await fsPromises.writeFile(destinationPath, incomingContent);
|
|
5206
|
-
if (!silent) log.success(`Wrote agent instructions to ${targetPathToWrite}`);
|
|
5207
|
-
seenRealPaths.add(await fsPromises.realpath(destinationPath));
|
|
5208
|
-
}
|
|
5209
|
-
}
|
|
5210
|
-
async function appendAgentContent(destinationPath, targetPath, existingContent, incomingContent, silent = false) {
|
|
5211
|
-
const separator = existingContent.endsWith("\n") ? "" : "\n";
|
|
5212
|
-
await fsPromises.appendFile(destinationPath, `${separator}\n${incomingContent}`);
|
|
5213
|
-
if (!silent) log.success(`Appended agent instructions to ${targetPath}`);
|
|
5214
|
-
}
|
|
5215
|
-
function normalizeAgentName(value) {
|
|
5216
|
-
return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
5217
|
-
}
|
|
5218
|
-
function replaceMarkedAgentInstructionsSection(existing, incoming) {
|
|
5219
|
-
const existingRange = getMarkedRange(existing, AGENT_INSTRUCTIONS_START_MARKER, AGENT_INSTRUCTIONS_END_MARKER);
|
|
5220
|
-
if (!existingRange) return;
|
|
5221
|
-
const incomingRange = getMarkedRange(incoming, AGENT_INSTRUCTIONS_START_MARKER, AGENT_INSTRUCTIONS_END_MARKER);
|
|
5222
|
-
if (!incomingRange) return;
|
|
5223
|
-
return `${existing.slice(0, existingRange.start)}${incoming.slice(incomingRange.start, incomingRange.end)}${existing.slice(existingRange.end)}`;
|
|
5224
|
-
}
|
|
5225
|
-
async function tryLinkTargetToAgents(projectRoot, targetPath, silent = false) {
|
|
5226
|
-
const destinationPath = path.join(projectRoot, targetPath);
|
|
5227
|
-
const agentsPath = path.join(projectRoot, AGENT_STANDARD_PATH);
|
|
5228
|
-
const symlinkTarget = path.relative(path.dirname(destinationPath), agentsPath);
|
|
5229
|
-
const existing = await getExistingPathKind(destinationPath);
|
|
5230
|
-
if (existing === "file") return false;
|
|
5231
|
-
if (existing === "symlink") {
|
|
5232
|
-
const currentLink = await fsPromises.readlink(destinationPath);
|
|
5233
|
-
if (path.resolve(path.dirname(destinationPath), currentLink) === agentsPath) {
|
|
5234
|
-
if (!silent) log.info(`Skipped linking ${targetPath} (already linked to ${AGENT_STANDARD_PATH})`);
|
|
5235
|
-
return true;
|
|
5236
|
-
}
|
|
5237
|
-
await fsPromises.unlink(destinationPath);
|
|
5238
|
-
}
|
|
5239
|
-
try {
|
|
5240
|
-
await fsPromises.symlink(symlinkTarget, destinationPath);
|
|
5241
|
-
} catch (err) {
|
|
5242
|
-
if (err.code === "EPERM") {
|
|
5243
|
-
await fsPromises.copyFile(agentsPath, destinationPath);
|
|
5244
|
-
if (!silent) log.success(`Copied ${AGENT_STANDARD_PATH} to ${targetPath}`);
|
|
5245
|
-
return true;
|
|
5246
|
-
}
|
|
5247
|
-
throw err;
|
|
5248
|
-
}
|
|
5249
|
-
if (!silent) log.success(`Linked ${targetPath} to ${AGENT_STANDARD_PATH}`);
|
|
3809
|
+
const types = parse(text)?.compilerOptions?.types;
|
|
3810
|
+
if (!Array.isArray(types)) return false;
|
|
3811
|
+
const REPLACEMENTS = {
|
|
3812
|
+
"tsdown/client": "vite-plus/pack/client",
|
|
3813
|
+
"vite/client": "vite-plus/client"
|
|
3814
|
+
};
|
|
3815
|
+
const toReplace = types.map((t, i) => typeof t === "string" && t in REPLACEMENTS ? {
|
|
3816
|
+
i,
|
|
3817
|
+
newVal: REPLACEMENTS[t]
|
|
3818
|
+
} : null).filter((x) => x !== null);
|
|
3819
|
+
if (toReplace.length === 0) return false;
|
|
3820
|
+
let currentText = text;
|
|
3821
|
+
for (let j = toReplace.length - 1; j >= 0; j--) {
|
|
3822
|
+
const { i, newVal } = toReplace[j];
|
|
3823
|
+
const edits = modify(currentText, [
|
|
3824
|
+
"compilerOptions",
|
|
3825
|
+
"types",
|
|
3826
|
+
i
|
|
3827
|
+
], newVal, {});
|
|
3828
|
+
if (edits.length > 0) currentText = applyEdits(currentText, edits);
|
|
3829
|
+
}
|
|
3830
|
+
fs.writeFileSync(filePath, currentText);
|
|
5250
3831
|
return true;
|
|
5251
3832
|
}
|
|
5252
|
-
async function getExistingPathKind(filePath) {
|
|
5253
|
-
if (!fs.existsSync(filePath)) return "missing";
|
|
5254
|
-
return (await fsPromises.lstat(filePath)).isSymbolicLink() ? "symlink" : "file";
|
|
5255
|
-
}
|
|
5256
|
-
function getMarkedRange(content, startMarker, endMarker) {
|
|
5257
|
-
const start = content.indexOf(startMarker);
|
|
5258
|
-
if (start === -1) return;
|
|
5259
|
-
const endMarkerIndex = content.indexOf(endMarker, start + startMarker.length);
|
|
5260
|
-
if (endMarkerIndex === -1) return;
|
|
5261
|
-
return {
|
|
5262
|
-
start,
|
|
5263
|
-
end: endMarkerIndex + endMarker.length
|
|
5264
|
-
};
|
|
5265
|
-
}
|
|
5266
3833
|
//#endregion
|
|
5267
|
-
export {
|
|
3834
|
+
export { R as A, log as C, spinner as D, select as E, runCommandSilently as M, require_cross_spawn as N, text as O, intro as S, outro as T, DependencyType as _, removeDeprecatedTsconfigFalseOption as a, cancel as b, defaultInteractive as c, promptGitHooks as d, promptGitInit as f, upgradeYarn as g, selectPackageManager as h, hasBaseUrlInTsconfig as i, runCommand$1 as j, require_picocolors as k, downloadPackageManager$1 as l, runViteInstall as m, findTsconfigFiles as n, rewriteTypesInTsconfig as o, runViteFmt as p, fixBaseUrlInTsconfig as r, cancelAndExit as s, confirmBaseUrlFix as t, getSpinner as u, PackageManager as v, multiselect as w, confirm as x, require_semver as y };
|