vite 6.3.5 → 7.1.5
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/LICENSE.md +81 -314
- package/bin/openChrome.js +68 -0
- package/bin/vite.js +7 -7
- package/dist/client/client.mjs +886 -922
- package/dist/client/env.mjs +14 -19
- package/dist/node/chunks/dep-BuoK8Wda.js +377 -0
- package/dist/node/chunks/dep-BvyJBvVx.js +4 -0
- package/dist/node/chunks/dep-Cs9lwdKu.js +4 -0
- package/dist/node/chunks/dep-DCVhRpiz.js +5595 -0
- package/dist/node/chunks/dep-DDbTn5rw.js +482 -0
- package/dist/node/chunks/dep-D_YDhiNx.js +4 -0
- package/dist/node/chunks/dep-M_KD0XSK.js +36707 -0
- package/dist/node/chunks/dep-SmwnYDP9.js +320 -0
- package/dist/node/chunks/dep-cWFO4sv4.js +4 -0
- package/dist/node/chunks/dep-lCKrEJQm.js +31 -0
- package/dist/node/chunks/dep-sDKrrA4S.js +6814 -0
- package/dist/node/chunks/dep-yxQqhtZq.js +4 -0
- package/dist/node/cli.js +624 -865
- package/dist/node/index.d.ts +2723 -3277
- package/dist/node/index.js +24 -188
- package/dist/node/module-runner.d.ts +256 -234
- package/dist/node/module-runner.js +1000 -1178
- package/dist/node/moduleRunnerTransport-BWUZBVLX.d.ts +88 -0
- package/package.json +52 -55
- package/types/importGlob.d.ts +14 -0
- package/types/internal/cssPreprocessorOptions.d.ts +3 -22
- package/types/internal/terserOptions.d.ts +11 -0
- package/types/metadata.d.ts +0 -2
- package/bin/openChrome.applescript +0 -95
- package/dist/node/chunks/dep-3RmXg9uo.js +0 -553
- package/dist/node/chunks/dep-AiMcmC_f.js +0 -822
- package/dist/node/chunks/dep-CvfTChi5.js +0 -8218
- package/dist/node/chunks/dep-DBxKXgDP.js +0 -49496
- package/dist/node/chunks/dep-SgSik2vo.js +0 -7113
- package/dist/node/constants.js +0 -149
- package/dist/node/moduleRunnerTransport.d-DJ_mE5sf.d.ts +0 -87
- package/dist/node-cjs/publicUtils.cjs +0 -3986
- package/index.cjs +0 -96
- package/index.d.cts +0 -6
package/dist/node/cli.js
CHANGED
@@ -1,949 +1,708 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import 'node:fs/promises';
|
8
|
-
import 'node:url';
|
9
|
-
import 'node:util';
|
10
|
-
import 'node:module';
|
11
|
-
import 'node:crypto';
|
12
|
-
import 'picomatch';
|
13
|
-
import 'esbuild';
|
14
|
-
import 'path';
|
15
|
-
import 'fs';
|
16
|
-
import 'fdir';
|
17
|
-
import 'node:child_process';
|
18
|
-
import 'node:http';
|
19
|
-
import 'node:https';
|
20
|
-
import 'tty';
|
21
|
-
import 'util';
|
22
|
-
import 'net';
|
23
|
-
import 'url';
|
24
|
-
import 'http';
|
25
|
-
import 'stream';
|
26
|
-
import 'os';
|
27
|
-
import 'child_process';
|
28
|
-
import 'node:os';
|
29
|
-
import 'node:net';
|
30
|
-
import 'node:dns';
|
31
|
-
import 'vite/module-runner';
|
32
|
-
import 'rollup/parseAst';
|
33
|
-
import 'node:buffer';
|
34
|
-
import 'module';
|
35
|
-
import 'node:readline';
|
36
|
-
import 'node:process';
|
37
|
-
import 'node:events';
|
38
|
-
import 'tinyglobby';
|
39
|
-
import 'crypto';
|
40
|
-
import 'node:assert';
|
41
|
-
import 'node:v8';
|
42
|
-
import 'node:worker_threads';
|
43
|
-
import 'https';
|
44
|
-
import 'tls';
|
45
|
-
import 'zlib';
|
46
|
-
import 'buffer';
|
47
|
-
import 'assert';
|
48
|
-
import 'node:querystring';
|
49
|
-
import 'node:zlib';
|
1
|
+
import { __toESM } from "./chunks/dep-lCKrEJQm.js";
|
2
|
+
import { VERSION, createLogger, require_picocolors } from "./chunks/dep-SmwnYDP9.js";
|
3
|
+
import fs from "node:fs";
|
4
|
+
import path from "node:path";
|
5
|
+
import { performance } from "node:perf_hooks";
|
6
|
+
import { EventEmitter } from "events";
|
50
7
|
|
8
|
+
//#region ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
51
9
|
function toArr(any) {
|
52
10
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
53
11
|
}
|
54
|
-
|
55
12
|
function toVal(out, key, val, opts) {
|
56
|
-
var x, old=out[key], nxt=(
|
57
|
-
|
58
|
-
: typeof val === 'boolean' ? val
|
59
|
-
: !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
|
60
|
-
: (x = +val,x * 0 === 0) ? x : val
|
61
|
-
);
|
62
|
-
out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
|
13
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
14
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
63
15
|
}
|
64
|
-
|
65
|
-
function mri2 (args, opts) {
|
16
|
+
function mri2(args, opts) {
|
66
17
|
args = args || [];
|
67
18
|
opts = opts || {};
|
68
|
-
|
69
|
-
var
|
70
|
-
var i=0, j=0, idx=0, len=args.length;
|
71
|
-
|
19
|
+
var k, arr, arg, name, val, out = { _: [] };
|
20
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
72
21
|
const alibi = opts.alias !== void 0;
|
73
22
|
const strict = opts.unknown !== void 0;
|
74
23
|
const defaults = opts.default !== void 0;
|
75
|
-
|
76
24
|
opts.alias = opts.alias || {};
|
77
25
|
opts.string = toArr(opts.string);
|
78
26
|
opts.boolean = toArr(opts.boolean);
|
79
|
-
|
80
|
-
|
81
|
-
for (
|
82
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
83
|
-
for (i=0; i < arr.length; i++) {
|
84
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
85
|
-
}
|
86
|
-
}
|
27
|
+
if (alibi) for (k in opts.alias) {
|
28
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
29
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
87
30
|
}
|
88
|
-
|
89
|
-
for (i=opts.boolean.length; i-- > 0;) {
|
31
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
90
32
|
arr = opts.alias[opts.boolean[i]] || [];
|
91
|
-
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
33
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
92
34
|
}
|
93
|
-
|
94
|
-
for (i=opts.string.length; i-- > 0;) {
|
35
|
+
for (i = opts.string.length; i-- > 0;) {
|
95
36
|
arr = opts.alias[opts.string[i]] || [];
|
96
|
-
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
37
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
97
38
|
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
opts[name].push(k);
|
105
|
-
for (i=0; i < arr.length; i++) {
|
106
|
-
opts[name].push(arr[i]);
|
107
|
-
}
|
108
|
-
}
|
39
|
+
if (defaults) for (k in opts.default) {
|
40
|
+
name = typeof opts.default[k];
|
41
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
42
|
+
if (opts[name] !== void 0) {
|
43
|
+
opts[name].push(k);
|
44
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
109
45
|
}
|
110
46
|
}
|
111
|
-
|
112
47
|
const keys = strict ? Object.keys(opts.alias) : [];
|
113
|
-
|
114
|
-
for (i=0; i < len; i++) {
|
48
|
+
for (i = 0; i < len; i++) {
|
115
49
|
arg = args[i];
|
116
|
-
|
117
|
-
if (arg === '--') {
|
50
|
+
if (arg === "--") {
|
118
51
|
out._ = out._.concat(args.slice(++i));
|
119
52
|
break;
|
120
53
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}
|
125
|
-
|
126
|
-
if (j === 0) {
|
127
|
-
out._.push(arg);
|
128
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
54
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
55
|
+
if (j === 0) out._.push(arg);
|
56
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
129
57
|
name = arg.substring(j + 3);
|
130
|
-
if (strict && !~keys.indexOf(name))
|
131
|
-
return opts.unknown(arg);
|
132
|
-
}
|
58
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
133
59
|
out[name] = false;
|
134
60
|
} else {
|
135
|
-
for (idx=j+1; idx < arg.length; idx++)
|
136
|
-
if (arg.charCodeAt(idx) === 61) break; // "="
|
137
|
-
}
|
138
|
-
|
61
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
139
62
|
name = arg.substring(j, idx);
|
140
|
-
val = arg.substring(++idx) ||
|
141
|
-
arr =
|
142
|
-
|
143
|
-
for (idx=0; idx < arr.length; idx++) {
|
63
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
64
|
+
arr = j === 2 ? [name] : name;
|
65
|
+
for (idx = 0; idx < arr.length; idx++) {
|
144
66
|
name = arr[idx];
|
145
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown(
|
146
|
-
toVal(out, name,
|
67
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
68
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
147
69
|
}
|
148
70
|
}
|
149
71
|
}
|
150
|
-
|
151
72
|
if (defaults) {
|
152
|
-
for (k in opts.default)
|
153
|
-
if (out[k] === void 0) {
|
154
|
-
out[k] = opts.default[k];
|
155
|
-
}
|
156
|
-
}
|
73
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
157
74
|
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
arr = opts.alias[k] || [];
|
162
|
-
while (arr.length > 0) {
|
163
|
-
out[arr.shift()] = out[k];
|
164
|
-
}
|
165
|
-
}
|
75
|
+
if (alibi) for (k in out) {
|
76
|
+
arr = opts.alias[k] || [];
|
77
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
166
78
|
}
|
167
|
-
|
168
79
|
return out;
|
169
80
|
}
|
170
|
-
|
171
81
|
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
172
82
|
const findAllBrackets = (v) => {
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
195
|
-
res.push(parse(squareMatch));
|
196
|
-
}
|
197
|
-
return res;
|
83
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
84
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
85
|
+
const res = [];
|
86
|
+
const parse = (match) => {
|
87
|
+
let variadic = false;
|
88
|
+
let value = match[1];
|
89
|
+
if (value.startsWith("...")) {
|
90
|
+
value = value.slice(3);
|
91
|
+
variadic = true;
|
92
|
+
}
|
93
|
+
return {
|
94
|
+
required: match[0].startsWith("<"),
|
95
|
+
value,
|
96
|
+
variadic
|
97
|
+
};
|
98
|
+
};
|
99
|
+
let angledMatch;
|
100
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
101
|
+
let squareMatch;
|
102
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
103
|
+
return res;
|
198
104
|
};
|
199
105
|
const getMriOptions = (options) => {
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
result.boolean.push(option.names[0]);
|
215
|
-
}
|
216
|
-
}
|
217
|
-
}
|
218
|
-
return result;
|
106
|
+
const result = {
|
107
|
+
alias: {},
|
108
|
+
boolean: []
|
109
|
+
};
|
110
|
+
for (const [index, option] of options.entries()) {
|
111
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
112
|
+
if (option.isBoolean) if (option.negated) {
|
113
|
+
const hasStringTypeOption = options.some((o, i) => {
|
114
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
115
|
+
});
|
116
|
+
if (!hasStringTypeOption) result.boolean.push(option.names[0]);
|
117
|
+
} else result.boolean.push(option.names[0]);
|
118
|
+
}
|
119
|
+
return result;
|
219
120
|
};
|
220
121
|
const findLongest = (arr) => {
|
221
|
-
|
222
|
-
|
223
|
-
|
122
|
+
return arr.sort((a, b) => {
|
123
|
+
return a.length > b.length ? -1 : 1;
|
124
|
+
})[0];
|
224
125
|
};
|
225
126
|
const padRight = (str, length) => {
|
226
|
-
|
127
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
227
128
|
};
|
228
129
|
const camelcase = (input) => {
|
229
|
-
|
230
|
-
|
231
|
-
|
130
|
+
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
131
|
+
return p1 + p2.toUpperCase();
|
132
|
+
});
|
232
133
|
};
|
233
134
|
const setDotProp = (obj, keys, val) => {
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
135
|
+
let i = 0;
|
136
|
+
let length = keys.length;
|
137
|
+
let t = obj;
|
138
|
+
let x;
|
139
|
+
for (; i < length; ++i) {
|
140
|
+
x = t[keys[i]];
|
141
|
+
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
142
|
+
}
|
242
143
|
};
|
243
144
|
const setByType = (obj, transforms) => {
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
}
|
252
|
-
}
|
145
|
+
for (const key of Object.keys(transforms)) {
|
146
|
+
const transform = transforms[key];
|
147
|
+
if (transform.shouldTransform) {
|
148
|
+
obj[key] = Array.prototype.concat.call([], obj[key]);
|
149
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
150
|
+
}
|
151
|
+
}
|
253
152
|
};
|
254
153
|
const getFileName = (input) => {
|
255
|
-
|
256
|
-
|
154
|
+
const m = /([^\\\/]+)$/.exec(input);
|
155
|
+
return m ? m[1] : "";
|
257
156
|
};
|
258
157
|
const camelcaseOptionName = (name) => {
|
259
|
-
|
260
|
-
|
261
|
-
|
158
|
+
return name.split(".").map((v, i) => {
|
159
|
+
return i === 0 ? camelcase(v) : v;
|
160
|
+
}).join(".");
|
161
|
+
};
|
162
|
+
var CACError = class extends Error {
|
163
|
+
constructor(message) {
|
164
|
+
super(message);
|
165
|
+
this.name = this.constructor.name;
|
166
|
+
if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, this.constructor);
|
167
|
+
else this.stack = new Error(message).stack;
|
168
|
+
}
|
169
|
+
};
|
170
|
+
var Option = class {
|
171
|
+
constructor(rawName, description, config) {
|
172
|
+
this.rawName = rawName;
|
173
|
+
this.description = description;
|
174
|
+
this.config = Object.assign({}, config);
|
175
|
+
rawName = rawName.replace(/\.\*/g, "");
|
176
|
+
this.negated = false;
|
177
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
178
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
179
|
+
if (name.startsWith("no-")) {
|
180
|
+
this.negated = true;
|
181
|
+
name = name.replace(/^no-/, "");
|
182
|
+
}
|
183
|
+
return camelcaseOptionName(name);
|
184
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
185
|
+
this.name = this.names[this.names.length - 1];
|
186
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
187
|
+
if (rawName.includes("<")) this.required = true;
|
188
|
+
else if (rawName.includes("[")) this.required = false;
|
189
|
+
else this.isBoolean = true;
|
190
|
+
}
|
262
191
|
};
|
263
|
-
class CACError extends Error {
|
264
|
-
constructor(message) {
|
265
|
-
super(message);
|
266
|
-
this.name = this.constructor.name;
|
267
|
-
if (typeof Error.captureStackTrace === "function") {
|
268
|
-
Error.captureStackTrace(this, this.constructor);
|
269
|
-
} else {
|
270
|
-
this.stack = new Error(message).stack;
|
271
|
-
}
|
272
|
-
}
|
273
|
-
}
|
274
|
-
|
275
|
-
class Option {
|
276
|
-
constructor(rawName, description, config) {
|
277
|
-
this.rawName = rawName;
|
278
|
-
this.description = description;
|
279
|
-
this.config = Object.assign({}, config);
|
280
|
-
rawName = rawName.replace(/\.\*/g, "");
|
281
|
-
this.negated = false;
|
282
|
-
this.names = removeBrackets(rawName).split(",").map((v) => {
|
283
|
-
let name = v.trim().replace(/^-{1,2}/, "");
|
284
|
-
if (name.startsWith("no-")) {
|
285
|
-
this.negated = true;
|
286
|
-
name = name.replace(/^no-/, "");
|
287
|
-
}
|
288
|
-
return camelcaseOptionName(name);
|
289
|
-
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
290
|
-
this.name = this.names[this.names.length - 1];
|
291
|
-
if (this.negated && this.config.default == null) {
|
292
|
-
this.config.default = true;
|
293
|
-
}
|
294
|
-
if (rawName.includes("<")) {
|
295
|
-
this.required = true;
|
296
|
-
} else if (rawName.includes("[")) {
|
297
|
-
this.required = false;
|
298
|
-
} else {
|
299
|
-
this.isBoolean = true;
|
300
|
-
}
|
301
|
-
}
|
302
|
-
}
|
303
|
-
|
304
192
|
const processArgs = process.argv;
|
305
193
|
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
}
|
411
|
-
if (this.examples.length > 0) {
|
412
|
-
sections.push({
|
413
|
-
title: "Examples",
|
414
|
-
body: this.examples.map((example) => {
|
415
|
-
if (typeof example === "function") {
|
416
|
-
return example(name);
|
417
|
-
}
|
418
|
-
return example;
|
419
|
-
}).join("\n")
|
420
|
-
});
|
421
|
-
}
|
422
|
-
if (helpCallback) {
|
423
|
-
sections = helpCallback(sections) || sections;
|
424
|
-
}
|
425
|
-
console.log(sections.map((section) => {
|
426
|
-
return section.title ? `${section.title}:
|
194
|
+
var Command = class {
|
195
|
+
constructor(rawName, description, config = {}, cli$1) {
|
196
|
+
this.rawName = rawName;
|
197
|
+
this.description = description;
|
198
|
+
this.config = config;
|
199
|
+
this.cli = cli$1;
|
200
|
+
this.options = [];
|
201
|
+
this.aliasNames = [];
|
202
|
+
this.name = removeBrackets(rawName);
|
203
|
+
this.args = findAllBrackets(rawName);
|
204
|
+
this.examples = [];
|
205
|
+
}
|
206
|
+
usage(text) {
|
207
|
+
this.usageText = text;
|
208
|
+
return this;
|
209
|
+
}
|
210
|
+
allowUnknownOptions() {
|
211
|
+
this.config.allowUnknownOptions = true;
|
212
|
+
return this;
|
213
|
+
}
|
214
|
+
ignoreOptionDefaultValue() {
|
215
|
+
this.config.ignoreOptionDefaultValue = true;
|
216
|
+
return this;
|
217
|
+
}
|
218
|
+
version(version, customFlags = "-v, --version") {
|
219
|
+
this.versionNumber = version;
|
220
|
+
this.option(customFlags, "Display version number");
|
221
|
+
return this;
|
222
|
+
}
|
223
|
+
example(example) {
|
224
|
+
this.examples.push(example);
|
225
|
+
return this;
|
226
|
+
}
|
227
|
+
option(rawName, description, config) {
|
228
|
+
const option = new Option(rawName, description, config);
|
229
|
+
this.options.push(option);
|
230
|
+
return this;
|
231
|
+
}
|
232
|
+
alias(name) {
|
233
|
+
this.aliasNames.push(name);
|
234
|
+
return this;
|
235
|
+
}
|
236
|
+
action(callback) {
|
237
|
+
this.commandAction = callback;
|
238
|
+
return this;
|
239
|
+
}
|
240
|
+
isMatched(name) {
|
241
|
+
return this.name === name || this.aliasNames.includes(name);
|
242
|
+
}
|
243
|
+
get isDefaultCommand() {
|
244
|
+
return this.name === "" || this.aliasNames.includes("!");
|
245
|
+
}
|
246
|
+
get isGlobalCommand() {
|
247
|
+
return this instanceof GlobalCommand;
|
248
|
+
}
|
249
|
+
hasOption(name) {
|
250
|
+
name = name.split(".")[0];
|
251
|
+
return this.options.find((option) => {
|
252
|
+
return option.names.includes(name);
|
253
|
+
});
|
254
|
+
}
|
255
|
+
outputHelp() {
|
256
|
+
const { name, commands } = this.cli;
|
257
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
258
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
259
|
+
sections.push({
|
260
|
+
title: "Usage",
|
261
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
262
|
+
});
|
263
|
+
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
264
|
+
if (showCommands) {
|
265
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
266
|
+
sections.push({
|
267
|
+
title: "Commands",
|
268
|
+
body: commands.map((command) => {
|
269
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
270
|
+
}).join("\n")
|
271
|
+
});
|
272
|
+
sections.push({
|
273
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
274
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
275
|
+
});
|
276
|
+
}
|
277
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
278
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
279
|
+
if (options.length > 0) {
|
280
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
281
|
+
sections.push({
|
282
|
+
title: "Options",
|
283
|
+
body: options.map((option) => {
|
284
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
285
|
+
}).join("\n")
|
286
|
+
});
|
287
|
+
}
|
288
|
+
if (this.examples.length > 0) sections.push({
|
289
|
+
title: "Examples",
|
290
|
+
body: this.examples.map((example) => {
|
291
|
+
if (typeof example === "function") return example(name);
|
292
|
+
return example;
|
293
|
+
}).join("\n")
|
294
|
+
});
|
295
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
296
|
+
console.log(sections.map((section) => {
|
297
|
+
return section.title ? `${section.title}:
|
427
298
|
${section.body}` : section.body;
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
}
|
463
|
-
}
|
464
|
-
}
|
465
|
-
}
|
466
|
-
}
|
467
|
-
class GlobalCommand extends Command {
|
468
|
-
constructor(cli) {
|
469
|
-
super("@@global@@", "", {}, cli);
|
470
|
-
}
|
471
|
-
}
|
472
|
-
|
299
|
+
}).join("\n\n"));
|
300
|
+
}
|
301
|
+
outputVersion() {
|
302
|
+
const { name } = this.cli;
|
303
|
+
const { versionNumber } = this.cli.globalCommand;
|
304
|
+
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
305
|
+
}
|
306
|
+
checkRequiredArgs() {
|
307
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
308
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
309
|
+
}
|
310
|
+
checkUnknownOptions() {
|
311
|
+
const { options, globalCommand } = this.cli;
|
312
|
+
if (!this.config.allowUnknownOptions) {
|
313
|
+
for (const name of Object.keys(options)) if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
checkOptionValue() {
|
317
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
318
|
+
const options = [...globalCommand.options, ...this.options];
|
319
|
+
for (const option of options) {
|
320
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
321
|
+
if (option.required) {
|
322
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
323
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
};
|
328
|
+
var GlobalCommand = class extends Command {
|
329
|
+
constructor(cli$1) {
|
330
|
+
super("@@global@@", "", {}, cli$1);
|
331
|
+
}
|
332
|
+
};
|
473
333
|
var __assign = Object.assign;
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
}
|
629
|
-
}
|
630
|
-
for (const key of Object.keys(parsed)) {
|
631
|
-
if (key !== "_") {
|
632
|
-
const keys = key.split(".");
|
633
|
-
setDotProp(options, keys, parsed[key]);
|
634
|
-
setByType(options, transforms);
|
635
|
-
}
|
636
|
-
}
|
637
|
-
return {
|
638
|
-
args,
|
639
|
-
options
|
640
|
-
};
|
641
|
-
}
|
642
|
-
runMatchedCommand() {
|
643
|
-
const {args, options, matchedCommand: command} = this;
|
644
|
-
if (!command || !command.commandAction)
|
645
|
-
return;
|
646
|
-
command.checkUnknownOptions();
|
647
|
-
command.checkOptionValue();
|
648
|
-
command.checkRequiredArgs();
|
649
|
-
const actionArgs = [];
|
650
|
-
command.args.forEach((arg, index) => {
|
651
|
-
if (arg.variadic) {
|
652
|
-
actionArgs.push(args.slice(index));
|
653
|
-
} else {
|
654
|
-
actionArgs.push(args[index]);
|
655
|
-
}
|
656
|
-
});
|
657
|
-
actionArgs.push(options);
|
658
|
-
return command.commandAction.apply(this, actionArgs);
|
659
|
-
}
|
660
|
-
}
|
661
|
-
|
334
|
+
var CAC = class extends EventEmitter {
|
335
|
+
constructor(name = "") {
|
336
|
+
super();
|
337
|
+
this.name = name;
|
338
|
+
this.commands = [];
|
339
|
+
this.rawArgs = [];
|
340
|
+
this.args = [];
|
341
|
+
this.options = {};
|
342
|
+
this.globalCommand = new GlobalCommand(this);
|
343
|
+
this.globalCommand.usage("<command> [options]");
|
344
|
+
}
|
345
|
+
usage(text) {
|
346
|
+
this.globalCommand.usage(text);
|
347
|
+
return this;
|
348
|
+
}
|
349
|
+
command(rawName, description, config) {
|
350
|
+
const command = new Command(rawName, description || "", config, this);
|
351
|
+
command.globalCommand = this.globalCommand;
|
352
|
+
this.commands.push(command);
|
353
|
+
return command;
|
354
|
+
}
|
355
|
+
option(rawName, description, config) {
|
356
|
+
this.globalCommand.option(rawName, description, config);
|
357
|
+
return this;
|
358
|
+
}
|
359
|
+
help(callback) {
|
360
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
361
|
+
this.globalCommand.helpCallback = callback;
|
362
|
+
this.showHelpOnExit = true;
|
363
|
+
return this;
|
364
|
+
}
|
365
|
+
version(version, customFlags = "-v, --version") {
|
366
|
+
this.globalCommand.version(version, customFlags);
|
367
|
+
this.showVersionOnExit = true;
|
368
|
+
return this;
|
369
|
+
}
|
370
|
+
example(example) {
|
371
|
+
this.globalCommand.example(example);
|
372
|
+
return this;
|
373
|
+
}
|
374
|
+
outputHelp() {
|
375
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
376
|
+
else this.globalCommand.outputHelp();
|
377
|
+
}
|
378
|
+
outputVersion() {
|
379
|
+
this.globalCommand.outputVersion();
|
380
|
+
}
|
381
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
382
|
+
this.args = args;
|
383
|
+
this.options = options;
|
384
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
385
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
386
|
+
return this;
|
387
|
+
}
|
388
|
+
unsetMatchedCommand() {
|
389
|
+
this.matchedCommand = void 0;
|
390
|
+
this.matchedCommandName = void 0;
|
391
|
+
}
|
392
|
+
parse(argv = processArgs, { run = true } = {}) {
|
393
|
+
this.rawArgs = argv;
|
394
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
395
|
+
let shouldParse = true;
|
396
|
+
for (const command of this.commands) {
|
397
|
+
const parsed = this.mri(argv.slice(2), command);
|
398
|
+
const commandName = parsed.args[0];
|
399
|
+
if (command.isMatched(commandName)) {
|
400
|
+
shouldParse = false;
|
401
|
+
const parsedInfo = __assign(__assign({}, parsed), { args: parsed.args.slice(1) });
|
402
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
403
|
+
this.emit(`command:${commandName}`, command);
|
404
|
+
}
|
405
|
+
}
|
406
|
+
if (shouldParse) {
|
407
|
+
for (const command of this.commands) if (command.name === "") {
|
408
|
+
shouldParse = false;
|
409
|
+
const parsed = this.mri(argv.slice(2), command);
|
410
|
+
this.setParsedInfo(parsed, command);
|
411
|
+
this.emit(`command:!`, command);
|
412
|
+
}
|
413
|
+
}
|
414
|
+
if (shouldParse) {
|
415
|
+
const parsed = this.mri(argv.slice(2));
|
416
|
+
this.setParsedInfo(parsed);
|
417
|
+
}
|
418
|
+
if (this.options.help && this.showHelpOnExit) {
|
419
|
+
this.outputHelp();
|
420
|
+
run = false;
|
421
|
+
this.unsetMatchedCommand();
|
422
|
+
}
|
423
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
424
|
+
this.outputVersion();
|
425
|
+
run = false;
|
426
|
+
this.unsetMatchedCommand();
|
427
|
+
}
|
428
|
+
const parsedArgv = {
|
429
|
+
args: this.args,
|
430
|
+
options: this.options
|
431
|
+
};
|
432
|
+
if (run) this.runMatchedCommand();
|
433
|
+
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
434
|
+
return parsedArgv;
|
435
|
+
}
|
436
|
+
mri(argv, command) {
|
437
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
438
|
+
const mriOptions = getMriOptions(cliOptions);
|
439
|
+
let argsAfterDoubleDashes = [];
|
440
|
+
const doubleDashesIndex = argv.indexOf("--");
|
441
|
+
if (doubleDashesIndex > -1) {
|
442
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
443
|
+
argv = argv.slice(0, doubleDashesIndex);
|
444
|
+
}
|
445
|
+
let parsed = mri2(argv, mriOptions);
|
446
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
447
|
+
return __assign(__assign({}, res), { [camelcaseOptionName(name)]: parsed[name] });
|
448
|
+
}, { _: [] });
|
449
|
+
const args = parsed._;
|
450
|
+
const options = { "--": argsAfterDoubleDashes };
|
451
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
452
|
+
let transforms = Object.create(null);
|
453
|
+
for (const cliOption of cliOptions) {
|
454
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
455
|
+
if (Array.isArray(cliOption.config.type)) {
|
456
|
+
if (transforms[cliOption.name] === void 0) {
|
457
|
+
transforms[cliOption.name] = Object.create(null);
|
458
|
+
transforms[cliOption.name]["shouldTransform"] = true;
|
459
|
+
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
460
|
+
}
|
461
|
+
}
|
462
|
+
}
|
463
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
464
|
+
const keys = key.split(".");
|
465
|
+
setDotProp(options, keys, parsed[key]);
|
466
|
+
setByType(options, transforms);
|
467
|
+
}
|
468
|
+
return {
|
469
|
+
args,
|
470
|
+
options
|
471
|
+
};
|
472
|
+
}
|
473
|
+
runMatchedCommand() {
|
474
|
+
const { args, options, matchedCommand: command } = this;
|
475
|
+
if (!command || !command.commandAction) return;
|
476
|
+
command.checkUnknownOptions();
|
477
|
+
command.checkOptionValue();
|
478
|
+
command.checkRequiredArgs();
|
479
|
+
const actionArgs = [];
|
480
|
+
command.args.forEach((arg, index) => {
|
481
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
482
|
+
else actionArgs.push(args[index]);
|
483
|
+
});
|
484
|
+
actionArgs.push(options);
|
485
|
+
return command.commandAction.apply(this, actionArgs);
|
486
|
+
}
|
487
|
+
};
|
662
488
|
const cac = (name = "") => new CAC(name);
|
663
489
|
|
490
|
+
//#endregion
|
491
|
+
//#region src/node/cli.ts
|
492
|
+
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
493
|
+
function checkNodeVersion(nodeVersion) {
|
494
|
+
const currentVersion = nodeVersion.split(".");
|
495
|
+
const major = parseInt(currentVersion[0], 10);
|
496
|
+
const minor = parseInt(currentVersion[1], 10);
|
497
|
+
const isSupported = major === 20 && minor >= 19 || major === 22 && minor >= 12 || major > 22;
|
498
|
+
return isSupported;
|
499
|
+
}
|
500
|
+
if (!checkNodeVersion(process.versions.node)) console.warn(import_picocolors.default.yellow(`You are using Node.js ${process.versions.node}. Vite requires Node.js version 20.19+ or 22.12+. Please upgrade your Node.js version.`));
|
664
501
|
const cli = cac("vite");
|
665
502
|
let profileSession = global.__vite_profile_session;
|
666
503
|
let profileCount = 0;
|
667
504
|
const stopProfiler = (log) => {
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
);
|
681
|
-
profileSession = void 0;
|
682
|
-
res();
|
683
|
-
} else {
|
684
|
-
rej(err);
|
685
|
-
}
|
686
|
-
});
|
687
|
-
});
|
505
|
+
if (!profileSession) return;
|
506
|
+
return new Promise((res, rej) => {
|
507
|
+
profileSession.post("Profiler.stop", (err, { profile }) => {
|
508
|
+
if (!err) {
|
509
|
+
const outPath = path.resolve(`./vite-profile-${profileCount++}.cpuprofile`);
|
510
|
+
fs.writeFileSync(outPath, JSON.stringify(profile));
|
511
|
+
log(import_picocolors.default.yellow(`CPU profile written to ${import_picocolors.default.white(import_picocolors.default.dim(outPath))}`));
|
512
|
+
profileSession = void 0;
|
513
|
+
res();
|
514
|
+
} else rej(err);
|
515
|
+
});
|
516
|
+
});
|
688
517
|
};
|
689
518
|
const filterDuplicateOptions = (options) => {
|
690
|
-
|
691
|
-
if (Array.isArray(value)) {
|
692
|
-
options[key] = value[value.length - 1];
|
693
|
-
}
|
694
|
-
}
|
519
|
+
for (const [key, value] of Object.entries(options)) if (Array.isArray(value)) options[key] = value[value.length - 1];
|
695
520
|
};
|
521
|
+
/**
|
522
|
+
* removing global flags before passing as command specific sub-configs
|
523
|
+
*/
|
696
524
|
function cleanGlobalCLIOptions(options) {
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
525
|
+
const ret = { ...options };
|
526
|
+
delete ret["--"];
|
527
|
+
delete ret.c;
|
528
|
+
delete ret.config;
|
529
|
+
delete ret.base;
|
530
|
+
delete ret.l;
|
531
|
+
delete ret.logLevel;
|
532
|
+
delete ret.clearScreen;
|
533
|
+
delete ret.configLoader;
|
534
|
+
delete ret.d;
|
535
|
+
delete ret.debug;
|
536
|
+
delete ret.f;
|
537
|
+
delete ret.filter;
|
538
|
+
delete ret.m;
|
539
|
+
delete ret.mode;
|
540
|
+
delete ret.force;
|
541
|
+
delete ret.w;
|
542
|
+
if ("sourcemap" in ret) {
|
543
|
+
const sourcemap = ret.sourcemap;
|
544
|
+
ret.sourcemap = sourcemap === "true" ? true : sourcemap === "false" ? false : ret.sourcemap;
|
545
|
+
}
|
546
|
+
if ("watch" in ret) {
|
547
|
+
const watch = ret.watch;
|
548
|
+
ret.watch = watch ? {} : void 0;
|
549
|
+
}
|
550
|
+
return ret;
|
722
551
|
}
|
552
|
+
/**
|
553
|
+
* removing builder flags before passing as command specific sub-configs
|
554
|
+
*/
|
723
555
|
function cleanBuilderCLIOptions(options) {
|
724
|
-
|
725
|
-
|
726
|
-
|
556
|
+
const ret = { ...options };
|
557
|
+
delete ret.app;
|
558
|
+
return ret;
|
727
559
|
}
|
560
|
+
/**
|
561
|
+
* host may be a number (like 0), should convert to string
|
562
|
+
*/
|
728
563
|
const convertHost = (v) => {
|
729
|
-
|
730
|
-
|
731
|
-
}
|
732
|
-
return v;
|
564
|
+
if (typeof v === "number") return String(v);
|
565
|
+
return v;
|
733
566
|
};
|
567
|
+
/**
|
568
|
+
* base may be a number (like 0), should convert to empty string
|
569
|
+
*/
|
734
570
|
const convertBase = (v) => {
|
735
|
-
|
736
|
-
|
737
|
-
}
|
738
|
-
return v;
|
571
|
+
if (v === 0) return "";
|
572
|
+
return v;
|
739
573
|
};
|
740
|
-
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
574
|
+
cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, { type: [convertBase] }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("--configLoader <loader>", `[string] use 'bundle' to bundle the config with esbuild, or 'runner' (experimental) to process it on the fly, or 'native' (experimental) to load using the native runtime (default: bundle)`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
|
575
|
+
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--open [path]", `[boolean | string] open browser on startup`).option("--cors", `[boolean] enable CORS`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--force", `[boolean] force the optimizer to ignore the cache and re-bundle`).action(async (root, options) => {
|
576
|
+
filterDuplicateOptions(options);
|
577
|
+
const { createServer } = await import("./chunks/dep-D_YDhiNx.js");
|
578
|
+
try {
|
579
|
+
const server = await createServer({
|
580
|
+
root,
|
581
|
+
base: options.base,
|
582
|
+
mode: options.mode,
|
583
|
+
configFile: options.config,
|
584
|
+
configLoader: options.configLoader,
|
585
|
+
logLevel: options.logLevel,
|
586
|
+
clearScreen: options.clearScreen,
|
587
|
+
server: cleanGlobalCLIOptions(options),
|
588
|
+
forceOptimizeDeps: options.force
|
589
|
+
});
|
590
|
+
if (!server.httpServer) throw new Error("HTTP server not available");
|
591
|
+
await server.listen();
|
592
|
+
const info = server.config.logger.info;
|
593
|
+
const modeString = options.mode && options.mode !== "development" ? ` ${import_picocolors.default.bgGreen(` ${import_picocolors.default.bold(options.mode)} `)}` : "";
|
594
|
+
const viteStartTime = global.__vite_start_time ?? false;
|
595
|
+
const startupDurationString = viteStartTime ? import_picocolors.default.dim(`ready in ${import_picocolors.default.reset(import_picocolors.default.bold(Math.ceil(performance.now() - viteStartTime)))} ms`) : "";
|
596
|
+
const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
|
597
|
+
info(`\n ${import_picocolors.default.green(`${import_picocolors.default.bold("VITE")} v${VERSION}`)}${modeString} ${startupDurationString}\n`, { clear: !hasExistingLogs });
|
598
|
+
server.printUrls();
|
599
|
+
const customShortcuts = [];
|
600
|
+
if (profileSession) customShortcuts.push({
|
601
|
+
key: "p",
|
602
|
+
description: "start/stop the profiler",
|
603
|
+
async action(server$1) {
|
604
|
+
if (profileSession) await stopProfiler(server$1.config.logger.info);
|
605
|
+
else {
|
606
|
+
const inspector = await import("node:inspector").then((r) => r.default);
|
607
|
+
await new Promise((res) => {
|
608
|
+
profileSession = new inspector.Session();
|
609
|
+
profileSession.connect();
|
610
|
+
profileSession.post("Profiler.enable", () => {
|
611
|
+
profileSession.post("Profiler.start", () => {
|
612
|
+
server$1.config.logger.info("Profiler started");
|
613
|
+
res();
|
614
|
+
});
|
615
|
+
});
|
616
|
+
});
|
617
|
+
}
|
618
|
+
}
|
619
|
+
});
|
620
|
+
server.bindCLIShortcuts({
|
621
|
+
print: true,
|
622
|
+
customShortcuts
|
623
|
+
});
|
624
|
+
} catch (e) {
|
625
|
+
const logger = createLogger(options.logLevel);
|
626
|
+
logger.error(import_picocolors.default.red(`error when starting dev server:\n${e.stack}`), { error: e });
|
627
|
+
await stopProfiler(logger.info);
|
628
|
+
process.exit(1);
|
629
|
+
}
|
630
|
+
});
|
631
|
+
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'baseline-widely-available')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("--assetsDir <dir>", `[string] directory under outDir to place assets in (default: assets)`).option("--assetsInlineLimit <number>", `[number] static asset base64 inline threshold in bytes (default: 4096)`).option("--ssr [entry]", `[string] build specified entry for server-side rendering`).option("--sourcemap [output]", `[boolean | "inline" | "hidden"] output source maps for build (default: false)`).option("--minify [minifier]", "[boolean | \"terser\" | \"esbuild\"] enable/disable minification, or specify minifier to use (default: esbuild)").option("--manifest [name]", `[boolean | string] emit build manifest json`).option("--ssrManifest [name]", `[boolean | string] emit ssr manifest json`).option("--emptyOutDir", `[boolean] force empty outDir when it's outside of root`).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(async (root, options) => {
|
632
|
+
filterDuplicateOptions(options);
|
633
|
+
const { createBuilder } = await import("./chunks/dep-BvyJBvVx.js");
|
634
|
+
const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
|
635
|
+
try {
|
636
|
+
const inlineConfig = {
|
637
|
+
root,
|
638
|
+
base: options.base,
|
639
|
+
mode: options.mode,
|
640
|
+
configFile: options.config,
|
641
|
+
configLoader: options.configLoader,
|
642
|
+
logLevel: options.logLevel,
|
643
|
+
clearScreen: options.clearScreen,
|
644
|
+
build: buildOptions,
|
645
|
+
...options.app ? { builder: {} } : {}
|
646
|
+
};
|
647
|
+
const builder = await createBuilder(inlineConfig, null);
|
648
|
+
await builder.buildApp();
|
649
|
+
} catch (e) {
|
650
|
+
createLogger(options.logLevel).error(import_picocolors.default.red(`error during build:\n${e.stack}`), { error: e });
|
651
|
+
process.exit(1);
|
652
|
+
} finally {
|
653
|
+
await stopProfiler((message) => createLogger(options.logLevel).info(message));
|
654
|
+
}
|
655
|
+
});
|
656
|
+
cli.command("optimize [root]", "pre-bundle dependencies (deprecated, the pre-bundle process runs automatically and does not need to be called)").option("--force", `[boolean] force the optimizer to ignore the cache and re-bundle`).action(async (root, options) => {
|
657
|
+
filterDuplicateOptions(options);
|
658
|
+
const { resolveConfig } = await import("./chunks/dep-Cs9lwdKu.js");
|
659
|
+
const { optimizeDeps } = await import("./chunks/dep-cWFO4sv4.js");
|
660
|
+
try {
|
661
|
+
const config = await resolveConfig({
|
662
|
+
root,
|
663
|
+
base: options.base,
|
664
|
+
configFile: options.config,
|
665
|
+
configLoader: options.configLoader,
|
666
|
+
logLevel: options.logLevel,
|
667
|
+
mode: options.mode
|
668
|
+
}, "serve");
|
669
|
+
await optimizeDeps(config, options.force, true);
|
670
|
+
} catch (e) {
|
671
|
+
createLogger(options.logLevel).error(import_picocolors.default.red(`error when optimizing deps:\n${e.stack}`), { error: e });
|
672
|
+
process.exit(1);
|
673
|
+
}
|
674
|
+
});
|
675
|
+
cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(async (root, options) => {
|
676
|
+
filterDuplicateOptions(options);
|
677
|
+
const { preview } = await import("./chunks/dep-yxQqhtZq.js");
|
678
|
+
try {
|
679
|
+
const server = await preview({
|
680
|
+
root,
|
681
|
+
base: options.base,
|
682
|
+
configFile: options.config,
|
683
|
+
configLoader: options.configLoader,
|
684
|
+
logLevel: options.logLevel,
|
685
|
+
mode: options.mode,
|
686
|
+
build: { outDir: options.outDir },
|
687
|
+
preview: {
|
688
|
+
port: options.port,
|
689
|
+
strictPort: options.strictPort,
|
690
|
+
host: options.host,
|
691
|
+
open: options.open
|
692
|
+
}
|
693
|
+
});
|
694
|
+
server.printUrls();
|
695
|
+
server.bindCLIShortcuts({ print: true });
|
696
|
+
} catch (e) {
|
697
|
+
createLogger(options.logLevel).error(import_picocolors.default.red(`error when starting preview server:\n${e.stack}`), { error: e });
|
698
|
+
process.exit(1);
|
699
|
+
} finally {
|
700
|
+
await stopProfiler((message) => createLogger(options.logLevel).info(message));
|
701
|
+
}
|
824
702
|
});
|
825
|
-
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
|
826
|
-
"--assetsDir <dir>",
|
827
|
-
`[string] directory under outDir to place assets in (default: assets)`
|
828
|
-
).option(
|
829
|
-
"--assetsInlineLimit <number>",
|
830
|
-
`[number] static asset base64 inline threshold in bytes (default: 4096)`
|
831
|
-
).option(
|
832
|
-
"--ssr [entry]",
|
833
|
-
`[string] build specified entry for server-side rendering`
|
834
|
-
).option(
|
835
|
-
"--sourcemap [output]",
|
836
|
-
`[boolean | "inline" | "hidden"] output source maps for build (default: false)`
|
837
|
-
).option(
|
838
|
-
"--minify [minifier]",
|
839
|
-
`[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
|
840
|
-
).option("--manifest [name]", `[boolean | string] emit build manifest json`).option("--ssrManifest [name]", `[boolean | string] emit ssr manifest json`).option(
|
841
|
-
"--emptyOutDir",
|
842
|
-
`[boolean] force empty outDir when it's outside of root`
|
843
|
-
).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(
|
844
|
-
async (root, options) => {
|
845
|
-
filterDuplicateOptions(options);
|
846
|
-
const { createBuilder } = await import('./chunks/dep-DBxKXgDP.js').then(function (n) { return n.T; });
|
847
|
-
const buildOptions = cleanGlobalCLIOptions(
|
848
|
-
cleanBuilderCLIOptions(options)
|
849
|
-
);
|
850
|
-
try {
|
851
|
-
const inlineConfig = {
|
852
|
-
root,
|
853
|
-
base: options.base,
|
854
|
-
mode: options.mode,
|
855
|
-
configFile: options.config,
|
856
|
-
configLoader: options.configLoader,
|
857
|
-
logLevel: options.logLevel,
|
858
|
-
clearScreen: options.clearScreen,
|
859
|
-
build: buildOptions,
|
860
|
-
...options.app ? { builder: {} } : {}
|
861
|
-
};
|
862
|
-
const builder = await createBuilder(inlineConfig, null);
|
863
|
-
await builder.buildApp();
|
864
|
-
} catch (e) {
|
865
|
-
createLogger(options.logLevel).error(
|
866
|
-
colors.red(`error during build:
|
867
|
-
${e.stack}`),
|
868
|
-
{ error: e }
|
869
|
-
);
|
870
|
-
process.exit(1);
|
871
|
-
} finally {
|
872
|
-
stopProfiler((message) => createLogger(options.logLevel).info(message));
|
873
|
-
}
|
874
|
-
}
|
875
|
-
);
|
876
|
-
cli.command(
|
877
|
-
"optimize [root]",
|
878
|
-
"pre-bundle dependencies (deprecated, the pre-bundle process runs automatically and does not need to be called)"
|
879
|
-
).option(
|
880
|
-
"--force",
|
881
|
-
`[boolean] force the optimizer to ignore the cache and re-bundle`
|
882
|
-
).action(
|
883
|
-
async (root, options) => {
|
884
|
-
filterDuplicateOptions(options);
|
885
|
-
const { optimizeDeps } = await import('./chunks/dep-DBxKXgDP.js').then(function (n) { return n.R; });
|
886
|
-
try {
|
887
|
-
const config = await resolveConfig(
|
888
|
-
{
|
889
|
-
root,
|
890
|
-
base: options.base,
|
891
|
-
configFile: options.config,
|
892
|
-
configLoader: options.configLoader,
|
893
|
-
logLevel: options.logLevel,
|
894
|
-
mode: options.mode
|
895
|
-
},
|
896
|
-
"serve"
|
897
|
-
);
|
898
|
-
await optimizeDeps(config, options.force, true);
|
899
|
-
} catch (e) {
|
900
|
-
createLogger(options.logLevel).error(
|
901
|
-
colors.red(`error when optimizing deps:
|
902
|
-
${e.stack}`),
|
903
|
-
{ error: e }
|
904
|
-
);
|
905
|
-
process.exit(1);
|
906
|
-
}
|
907
|
-
}
|
908
|
-
);
|
909
|
-
cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(
|
910
|
-
async (root, options) => {
|
911
|
-
filterDuplicateOptions(options);
|
912
|
-
const { preview } = await import('./chunks/dep-DBxKXgDP.js').then(function (n) { return n.U; });
|
913
|
-
try {
|
914
|
-
const server = await preview({
|
915
|
-
root,
|
916
|
-
base: options.base,
|
917
|
-
configFile: options.config,
|
918
|
-
configLoader: options.configLoader,
|
919
|
-
logLevel: options.logLevel,
|
920
|
-
mode: options.mode,
|
921
|
-
build: {
|
922
|
-
outDir: options.outDir
|
923
|
-
},
|
924
|
-
preview: {
|
925
|
-
port: options.port,
|
926
|
-
strictPort: options.strictPort,
|
927
|
-
host: options.host,
|
928
|
-
open: options.open
|
929
|
-
}
|
930
|
-
});
|
931
|
-
server.printUrls();
|
932
|
-
server.bindCLIShortcuts({ print: true });
|
933
|
-
} catch (e) {
|
934
|
-
createLogger(options.logLevel).error(
|
935
|
-
colors.red(`error when starting preview server:
|
936
|
-
${e.stack}`),
|
937
|
-
{ error: e }
|
938
|
-
);
|
939
|
-
process.exit(1);
|
940
|
-
} finally {
|
941
|
-
stopProfiler((message) => createLogger(options.logLevel).info(message));
|
942
|
-
}
|
943
|
-
}
|
944
|
-
);
|
945
703
|
cli.help();
|
946
704
|
cli.version(VERSION);
|
947
705
|
cli.parse();
|
948
706
|
|
949
|
-
|
707
|
+
//#endregion
|
708
|
+
export { stopProfiler };
|