vite 6.3.5 → 7.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +29 -0
- package/dist/client/client.mjs +796 -924
- package/dist/client/env.mjs +14 -19
- package/dist/node/chunks/dep-3jlWaCfC.js +5 -0
- package/dist/node/chunks/dep-B4i1tHPo.js +30 -0
- package/dist/node/chunks/dep-CCzsqxOh.js +5597 -0
- package/dist/node/chunks/dep-Ccq9jQdz.js +5 -0
- package/dist/node/chunks/dep-Ctugieod.js +150 -0
- package/dist/node/chunks/dep-D5HXLrlI.js +378 -0
- package/dist/node/chunks/dep-D_UgUiRQ.js +5 -0
- package/dist/node/chunks/dep-FHYvcJhE.js +446 -0
- package/dist/node/chunks/dep-P8c3Tybu.js +5 -0
- package/dist/node/chunks/dep-RiwDEHuV.js +7345 -0
- package/dist/node/chunks/dep-bvBD1i2C.js +36517 -0
- package/dist/node/cli.js +617 -865
- package/dist/node/constants.js +3 -148
- package/dist/node/index.d.ts +2730 -3081
- package/dist/node/index.js +25 -188
- package/dist/node/module-runner.d.ts +241 -229
- package/dist/node/module-runner.js +1041 -1175
- package/dist/node/moduleRunnerTransport-CnL9s_k9.d.ts +88 -0
- package/package.json +36 -38
- package/types/internal/cssPreprocessorOptions.d.ts +0 -19
- 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/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,701 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
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 { createRequire as ___createRequire } from 'module'; const require = ___createRequire(import.meta.url);
|
2
|
+
import { __toESM } from "./chunks/dep-B4i1tHPo.js";
|
3
|
+
import { createLogger, require_picocolors, resolveConfig } from "./chunks/dep-bvBD1i2C.js";
|
4
|
+
import { VERSION } from "./chunks/dep-Ctugieod.js";
|
5
|
+
import fs from "node:fs";
|
6
|
+
import path from "node:path";
|
7
|
+
import { performance } from "node:perf_hooks";
|
8
|
+
import { EventEmitter } from "events";
|
50
9
|
|
10
|
+
//#region ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
51
11
|
function toArr(any) {
|
52
12
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
53
13
|
}
|
54
|
-
|
55
14
|
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]);
|
15
|
+
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;
|
16
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
63
17
|
}
|
64
|
-
|
65
|
-
function mri2 (args, opts) {
|
18
|
+
function mri2(args, opts) {
|
66
19
|
args = args || [];
|
67
20
|
opts = opts || {};
|
68
|
-
|
69
|
-
var
|
70
|
-
var i=0, j=0, idx=0, len=args.length;
|
71
|
-
|
21
|
+
var k, arr, arg, name, val, out = { _: [] };
|
22
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
72
23
|
const alibi = opts.alias !== void 0;
|
73
24
|
const strict = opts.unknown !== void 0;
|
74
25
|
const defaults = opts.default !== void 0;
|
75
|
-
|
76
26
|
opts.alias = opts.alias || {};
|
77
27
|
opts.string = toArr(opts.string);
|
78
28
|
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
|
-
}
|
29
|
+
if (alibi) for (k in opts.alias) {
|
30
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
31
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
87
32
|
}
|
88
|
-
|
89
|
-
for (i=opts.boolean.length; i-- > 0;) {
|
33
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
90
34
|
arr = opts.alias[opts.boolean[i]] || [];
|
91
|
-
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
35
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
92
36
|
}
|
93
|
-
|
94
|
-
for (i=opts.string.length; i-- > 0;) {
|
37
|
+
for (i = opts.string.length; i-- > 0;) {
|
95
38
|
arr = opts.alias[opts.string[i]] || [];
|
96
|
-
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
39
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
97
40
|
}
|
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
|
-
}
|
41
|
+
if (defaults) for (k in opts.default) {
|
42
|
+
name = typeof opts.default[k];
|
43
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
44
|
+
if (opts[name] !== void 0) {
|
45
|
+
opts[name].push(k);
|
46
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
109
47
|
}
|
110
48
|
}
|
111
|
-
|
112
49
|
const keys = strict ? Object.keys(opts.alias) : [];
|
113
|
-
|
114
|
-
for (i=0; i < len; i++) {
|
50
|
+
for (i = 0; i < len; i++) {
|
115
51
|
arg = args[i];
|
116
|
-
|
117
|
-
if (arg === '--') {
|
52
|
+
if (arg === "--") {
|
118
53
|
out._ = out._.concat(args.slice(++i));
|
119
54
|
break;
|
120
55
|
}
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
}
|
125
|
-
|
126
|
-
if (j === 0) {
|
127
|
-
out._.push(arg);
|
128
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
56
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
57
|
+
if (j === 0) out._.push(arg);
|
58
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
129
59
|
name = arg.substring(j + 3);
|
130
|
-
if (strict && !~keys.indexOf(name))
|
131
|
-
return opts.unknown(arg);
|
132
|
-
}
|
60
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
133
61
|
out[name] = false;
|
134
62
|
} else {
|
135
|
-
for (idx=j+1; idx < arg.length; idx++)
|
136
|
-
if (arg.charCodeAt(idx) === 61) break; // "="
|
137
|
-
}
|
138
|
-
|
63
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
139
64
|
name = arg.substring(j, idx);
|
140
|
-
val = arg.substring(++idx) ||
|
141
|
-
arr =
|
142
|
-
|
143
|
-
for (idx=0; idx < arr.length; idx++) {
|
65
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
66
|
+
arr = j === 2 ? [name] : name;
|
67
|
+
for (idx = 0; idx < arr.length; idx++) {
|
144
68
|
name = arr[idx];
|
145
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown(
|
146
|
-
toVal(out, name,
|
69
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
70
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
147
71
|
}
|
148
72
|
}
|
149
73
|
}
|
150
|
-
|
151
74
|
if (defaults) {
|
152
|
-
for (k in opts.default)
|
153
|
-
if (out[k] === void 0) {
|
154
|
-
out[k] = opts.default[k];
|
155
|
-
}
|
156
|
-
}
|
75
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
157
76
|
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
arr = opts.alias[k] || [];
|
162
|
-
while (arr.length > 0) {
|
163
|
-
out[arr.shift()] = out[k];
|
164
|
-
}
|
165
|
-
}
|
77
|
+
if (alibi) for (k in out) {
|
78
|
+
arr = opts.alias[k] || [];
|
79
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
166
80
|
}
|
167
|
-
|
168
81
|
return out;
|
169
82
|
}
|
170
|
-
|
171
83
|
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
172
84
|
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;
|
85
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
86
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
87
|
+
const res = [];
|
88
|
+
const parse = (match) => {
|
89
|
+
let variadic = false;
|
90
|
+
let value = match[1];
|
91
|
+
if (value.startsWith("...")) {
|
92
|
+
value = value.slice(3);
|
93
|
+
variadic = true;
|
94
|
+
}
|
95
|
+
return {
|
96
|
+
required: match[0].startsWith("<"),
|
97
|
+
value,
|
98
|
+
variadic
|
99
|
+
};
|
100
|
+
};
|
101
|
+
let angledMatch;
|
102
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
103
|
+
let squareMatch;
|
104
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
105
|
+
return res;
|
198
106
|
};
|
199
107
|
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;
|
108
|
+
const result = {
|
109
|
+
alias: {},
|
110
|
+
boolean: []
|
111
|
+
};
|
112
|
+
for (const [index, option] of options.entries()) {
|
113
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
114
|
+
if (option.isBoolean) if (option.negated) {
|
115
|
+
const hasStringTypeOption = options.some((o, i) => {
|
116
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
117
|
+
});
|
118
|
+
if (!hasStringTypeOption) result.boolean.push(option.names[0]);
|
119
|
+
} else result.boolean.push(option.names[0]);
|
120
|
+
}
|
121
|
+
return result;
|
219
122
|
};
|
220
123
|
const findLongest = (arr) => {
|
221
|
-
|
222
|
-
|
223
|
-
|
124
|
+
return arr.sort((a, b) => {
|
125
|
+
return a.length > b.length ? -1 : 1;
|
126
|
+
})[0];
|
224
127
|
};
|
225
128
|
const padRight = (str, length) => {
|
226
|
-
|
129
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
227
130
|
};
|
228
131
|
const camelcase = (input) => {
|
229
|
-
|
230
|
-
|
231
|
-
|
132
|
+
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
133
|
+
return p1 + p2.toUpperCase();
|
134
|
+
});
|
232
135
|
};
|
233
136
|
const setDotProp = (obj, keys, val) => {
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
137
|
+
let i = 0;
|
138
|
+
let length = keys.length;
|
139
|
+
let t = obj;
|
140
|
+
let x;
|
141
|
+
for (; i < length; ++i) {
|
142
|
+
x = t[keys[i]];
|
143
|
+
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
144
|
+
}
|
242
145
|
};
|
243
146
|
const setByType = (obj, transforms) => {
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
}
|
252
|
-
}
|
147
|
+
for (const key of Object.keys(transforms)) {
|
148
|
+
const transform = transforms[key];
|
149
|
+
if (transform.shouldTransform) {
|
150
|
+
obj[key] = Array.prototype.concat.call([], obj[key]);
|
151
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
152
|
+
}
|
153
|
+
}
|
253
154
|
};
|
254
155
|
const getFileName = (input) => {
|
255
|
-
|
256
|
-
|
156
|
+
const m = /([^\\\/]+)$/.exec(input);
|
157
|
+
return m ? m[1] : "";
|
257
158
|
};
|
258
159
|
const camelcaseOptionName = (name) => {
|
259
|
-
|
260
|
-
|
261
|
-
|
160
|
+
return name.split(".").map((v, i) => {
|
161
|
+
return i === 0 ? camelcase(v) : v;
|
162
|
+
}).join(".");
|
163
|
+
};
|
164
|
+
var CACError = class extends Error {
|
165
|
+
constructor(message) {
|
166
|
+
super(message);
|
167
|
+
this.name = this.constructor.name;
|
168
|
+
if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, this.constructor);
|
169
|
+
else this.stack = new Error(message).stack;
|
170
|
+
}
|
171
|
+
};
|
172
|
+
var Option = class {
|
173
|
+
constructor(rawName, description, config) {
|
174
|
+
this.rawName = rawName;
|
175
|
+
this.description = description;
|
176
|
+
this.config = Object.assign({}, config);
|
177
|
+
rawName = rawName.replace(/\.\*/g, "");
|
178
|
+
this.negated = false;
|
179
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
180
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
181
|
+
if (name.startsWith("no-")) {
|
182
|
+
this.negated = true;
|
183
|
+
name = name.replace(/^no-/, "");
|
184
|
+
}
|
185
|
+
return camelcaseOptionName(name);
|
186
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
187
|
+
this.name = this.names[this.names.length - 1];
|
188
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
189
|
+
if (rawName.includes("<")) this.required = true;
|
190
|
+
else if (rawName.includes("[")) this.required = false;
|
191
|
+
else this.isBoolean = true;
|
192
|
+
}
|
262
193
|
};
|
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
194
|
const processArgs = process.argv;
|
305
195
|
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}:
|
196
|
+
var Command = class {
|
197
|
+
constructor(rawName, description, config = {}, cli$1) {
|
198
|
+
this.rawName = rawName;
|
199
|
+
this.description = description;
|
200
|
+
this.config = config;
|
201
|
+
this.cli = cli$1;
|
202
|
+
this.options = [];
|
203
|
+
this.aliasNames = [];
|
204
|
+
this.name = removeBrackets(rawName);
|
205
|
+
this.args = findAllBrackets(rawName);
|
206
|
+
this.examples = [];
|
207
|
+
}
|
208
|
+
usage(text) {
|
209
|
+
this.usageText = text;
|
210
|
+
return this;
|
211
|
+
}
|
212
|
+
allowUnknownOptions() {
|
213
|
+
this.config.allowUnknownOptions = true;
|
214
|
+
return this;
|
215
|
+
}
|
216
|
+
ignoreOptionDefaultValue() {
|
217
|
+
this.config.ignoreOptionDefaultValue = true;
|
218
|
+
return this;
|
219
|
+
}
|
220
|
+
version(version, customFlags = "-v, --version") {
|
221
|
+
this.versionNumber = version;
|
222
|
+
this.option(customFlags, "Display version number");
|
223
|
+
return this;
|
224
|
+
}
|
225
|
+
example(example) {
|
226
|
+
this.examples.push(example);
|
227
|
+
return this;
|
228
|
+
}
|
229
|
+
option(rawName, description, config) {
|
230
|
+
const option = new Option(rawName, description, config);
|
231
|
+
this.options.push(option);
|
232
|
+
return this;
|
233
|
+
}
|
234
|
+
alias(name) {
|
235
|
+
this.aliasNames.push(name);
|
236
|
+
return this;
|
237
|
+
}
|
238
|
+
action(callback) {
|
239
|
+
this.commandAction = callback;
|
240
|
+
return this;
|
241
|
+
}
|
242
|
+
isMatched(name) {
|
243
|
+
return this.name === name || this.aliasNames.includes(name);
|
244
|
+
}
|
245
|
+
get isDefaultCommand() {
|
246
|
+
return this.name === "" || this.aliasNames.includes("!");
|
247
|
+
}
|
248
|
+
get isGlobalCommand() {
|
249
|
+
return this instanceof GlobalCommand;
|
250
|
+
}
|
251
|
+
hasOption(name) {
|
252
|
+
name = name.split(".")[0];
|
253
|
+
return this.options.find((option) => {
|
254
|
+
return option.names.includes(name);
|
255
|
+
});
|
256
|
+
}
|
257
|
+
outputHelp() {
|
258
|
+
const { name, commands } = this.cli;
|
259
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
260
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
261
|
+
sections.push({
|
262
|
+
title: "Usage",
|
263
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
264
|
+
});
|
265
|
+
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
266
|
+
if (showCommands) {
|
267
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
268
|
+
sections.push({
|
269
|
+
title: "Commands",
|
270
|
+
body: commands.map((command) => {
|
271
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
272
|
+
}).join("\n")
|
273
|
+
});
|
274
|
+
sections.push({
|
275
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
276
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
277
|
+
});
|
278
|
+
}
|
279
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
280
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
281
|
+
if (options.length > 0) {
|
282
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
283
|
+
sections.push({
|
284
|
+
title: "Options",
|
285
|
+
body: options.map((option) => {
|
286
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
287
|
+
}).join("\n")
|
288
|
+
});
|
289
|
+
}
|
290
|
+
if (this.examples.length > 0) sections.push({
|
291
|
+
title: "Examples",
|
292
|
+
body: this.examples.map((example) => {
|
293
|
+
if (typeof example === "function") return example(name);
|
294
|
+
return example;
|
295
|
+
}).join("\n")
|
296
|
+
});
|
297
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
298
|
+
console.log(sections.map((section) => {
|
299
|
+
return section.title ? `${section.title}:
|
427
300
|
${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
|
-
|
301
|
+
}).join("\n\n"));
|
302
|
+
}
|
303
|
+
outputVersion() {
|
304
|
+
const { name } = this.cli;
|
305
|
+
const { versionNumber } = this.cli.globalCommand;
|
306
|
+
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
307
|
+
}
|
308
|
+
checkRequiredArgs() {
|
309
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
310
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
311
|
+
}
|
312
|
+
checkUnknownOptions() {
|
313
|
+
const { options, globalCommand } = this.cli;
|
314
|
+
if (!this.config.allowUnknownOptions) {
|
315
|
+
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}`}\``);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
checkOptionValue() {
|
319
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
320
|
+
const options = [...globalCommand.options, ...this.options];
|
321
|
+
for (const option of options) {
|
322
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
323
|
+
if (option.required) {
|
324
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
325
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
326
|
+
}
|
327
|
+
}
|
328
|
+
}
|
329
|
+
};
|
330
|
+
var GlobalCommand = class extends Command {
|
331
|
+
constructor(cli$1) {
|
332
|
+
super("@@global@@", "", {}, cli$1);
|
333
|
+
}
|
334
|
+
};
|
473
335
|
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
|
-
|
336
|
+
var CAC = class extends EventEmitter {
|
337
|
+
constructor(name = "") {
|
338
|
+
super();
|
339
|
+
this.name = name;
|
340
|
+
this.commands = [];
|
341
|
+
this.rawArgs = [];
|
342
|
+
this.args = [];
|
343
|
+
this.options = {};
|
344
|
+
this.globalCommand = new GlobalCommand(this);
|
345
|
+
this.globalCommand.usage("<command> [options]");
|
346
|
+
}
|
347
|
+
usage(text) {
|
348
|
+
this.globalCommand.usage(text);
|
349
|
+
return this;
|
350
|
+
}
|
351
|
+
command(rawName, description, config) {
|
352
|
+
const command = new Command(rawName, description || "", config, this);
|
353
|
+
command.globalCommand = this.globalCommand;
|
354
|
+
this.commands.push(command);
|
355
|
+
return command;
|
356
|
+
}
|
357
|
+
option(rawName, description, config) {
|
358
|
+
this.globalCommand.option(rawName, description, config);
|
359
|
+
return this;
|
360
|
+
}
|
361
|
+
help(callback) {
|
362
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
363
|
+
this.globalCommand.helpCallback = callback;
|
364
|
+
this.showHelpOnExit = true;
|
365
|
+
return this;
|
366
|
+
}
|
367
|
+
version(version, customFlags = "-v, --version") {
|
368
|
+
this.globalCommand.version(version, customFlags);
|
369
|
+
this.showVersionOnExit = true;
|
370
|
+
return this;
|
371
|
+
}
|
372
|
+
example(example) {
|
373
|
+
this.globalCommand.example(example);
|
374
|
+
return this;
|
375
|
+
}
|
376
|
+
outputHelp() {
|
377
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
378
|
+
else this.globalCommand.outputHelp();
|
379
|
+
}
|
380
|
+
outputVersion() {
|
381
|
+
this.globalCommand.outputVersion();
|
382
|
+
}
|
383
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
384
|
+
this.args = args;
|
385
|
+
this.options = options;
|
386
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
387
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
388
|
+
return this;
|
389
|
+
}
|
390
|
+
unsetMatchedCommand() {
|
391
|
+
this.matchedCommand = void 0;
|
392
|
+
this.matchedCommandName = void 0;
|
393
|
+
}
|
394
|
+
parse(argv = processArgs, { run = true } = {}) {
|
395
|
+
this.rawArgs = argv;
|
396
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
397
|
+
let shouldParse = true;
|
398
|
+
for (const command of this.commands) {
|
399
|
+
const parsed = this.mri(argv.slice(2), command);
|
400
|
+
const commandName = parsed.args[0];
|
401
|
+
if (command.isMatched(commandName)) {
|
402
|
+
shouldParse = false;
|
403
|
+
const parsedInfo = __assign(__assign({}, parsed), { args: parsed.args.slice(1) });
|
404
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
405
|
+
this.emit(`command:${commandName}`, command);
|
406
|
+
}
|
407
|
+
}
|
408
|
+
if (shouldParse) {
|
409
|
+
for (const command of this.commands) if (command.name === "") {
|
410
|
+
shouldParse = false;
|
411
|
+
const parsed = this.mri(argv.slice(2), command);
|
412
|
+
this.setParsedInfo(parsed, command);
|
413
|
+
this.emit(`command:!`, command);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
if (shouldParse) {
|
417
|
+
const parsed = this.mri(argv.slice(2));
|
418
|
+
this.setParsedInfo(parsed);
|
419
|
+
}
|
420
|
+
if (this.options.help && this.showHelpOnExit) {
|
421
|
+
this.outputHelp();
|
422
|
+
run = false;
|
423
|
+
this.unsetMatchedCommand();
|
424
|
+
}
|
425
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
426
|
+
this.outputVersion();
|
427
|
+
run = false;
|
428
|
+
this.unsetMatchedCommand();
|
429
|
+
}
|
430
|
+
const parsedArgv = {
|
431
|
+
args: this.args,
|
432
|
+
options: this.options
|
433
|
+
};
|
434
|
+
if (run) this.runMatchedCommand();
|
435
|
+
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
436
|
+
return parsedArgv;
|
437
|
+
}
|
438
|
+
mri(argv, command) {
|
439
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
440
|
+
const mriOptions = getMriOptions(cliOptions);
|
441
|
+
let argsAfterDoubleDashes = [];
|
442
|
+
const doubleDashesIndex = argv.indexOf("--");
|
443
|
+
if (doubleDashesIndex > -1) {
|
444
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
445
|
+
argv = argv.slice(0, doubleDashesIndex);
|
446
|
+
}
|
447
|
+
let parsed = mri2(argv, mriOptions);
|
448
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
449
|
+
return __assign(__assign({}, res), { [camelcaseOptionName(name)]: parsed[name] });
|
450
|
+
}, { _: [] });
|
451
|
+
const args = parsed._;
|
452
|
+
const options = { "--": argsAfterDoubleDashes };
|
453
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
454
|
+
let transforms = Object.create(null);
|
455
|
+
for (const cliOption of cliOptions) {
|
456
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
457
|
+
if (Array.isArray(cliOption.config.type)) {
|
458
|
+
if (transforms[cliOption.name] === void 0) {
|
459
|
+
transforms[cliOption.name] = Object.create(null);
|
460
|
+
transforms[cliOption.name]["shouldTransform"] = true;
|
461
|
+
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
462
|
+
}
|
463
|
+
}
|
464
|
+
}
|
465
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
466
|
+
const keys = key.split(".");
|
467
|
+
setDotProp(options, keys, parsed[key]);
|
468
|
+
setByType(options, transforms);
|
469
|
+
}
|
470
|
+
return {
|
471
|
+
args,
|
472
|
+
options
|
473
|
+
};
|
474
|
+
}
|
475
|
+
runMatchedCommand() {
|
476
|
+
const { args, options, matchedCommand: command } = this;
|
477
|
+
if (!command || !command.commandAction) return;
|
478
|
+
command.checkUnknownOptions();
|
479
|
+
command.checkOptionValue();
|
480
|
+
command.checkRequiredArgs();
|
481
|
+
const actionArgs = [];
|
482
|
+
command.args.forEach((arg, index) => {
|
483
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
484
|
+
else actionArgs.push(args[index]);
|
485
|
+
});
|
486
|
+
actionArgs.push(options);
|
487
|
+
return command.commandAction.apply(this, actionArgs);
|
488
|
+
}
|
489
|
+
};
|
662
490
|
const cac = (name = "") => new CAC(name);
|
663
491
|
|
492
|
+
//#endregion
|
493
|
+
//#region src/node/cli.ts
|
494
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
664
495
|
const cli = cac("vite");
|
665
496
|
let profileSession = global.__vite_profile_session;
|
666
497
|
let profileCount = 0;
|
667
498
|
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
|
-
});
|
499
|
+
if (!profileSession) return;
|
500
|
+
return new Promise((res, rej) => {
|
501
|
+
profileSession.post("Profiler.stop", (err, { profile }) => {
|
502
|
+
if (!err) {
|
503
|
+
const outPath = path.resolve(`./vite-profile-${profileCount++}.cpuprofile`);
|
504
|
+
fs.writeFileSync(outPath, JSON.stringify(profile));
|
505
|
+
log(import_picocolors.default.yellow(`CPU profile written to ${import_picocolors.default.white(import_picocolors.default.dim(outPath))}`));
|
506
|
+
profileSession = void 0;
|
507
|
+
res();
|
508
|
+
} else rej(err);
|
509
|
+
});
|
510
|
+
});
|
688
511
|
};
|
689
512
|
const filterDuplicateOptions = (options) => {
|
690
|
-
|
691
|
-
if (Array.isArray(value)) {
|
692
|
-
options[key] = value[value.length - 1];
|
693
|
-
}
|
694
|
-
}
|
513
|
+
for (const [key, value] of Object.entries(options)) if (Array.isArray(value)) options[key] = value[value.length - 1];
|
695
514
|
};
|
515
|
+
/**
|
516
|
+
* removing global flags before passing as command specific sub-configs
|
517
|
+
*/
|
696
518
|
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
|
-
|
519
|
+
const ret = { ...options };
|
520
|
+
delete ret["--"];
|
521
|
+
delete ret.c;
|
522
|
+
delete ret.config;
|
523
|
+
delete ret.base;
|
524
|
+
delete ret.l;
|
525
|
+
delete ret.logLevel;
|
526
|
+
delete ret.clearScreen;
|
527
|
+
delete ret.configLoader;
|
528
|
+
delete ret.d;
|
529
|
+
delete ret.debug;
|
530
|
+
delete ret.f;
|
531
|
+
delete ret.filter;
|
532
|
+
delete ret.m;
|
533
|
+
delete ret.mode;
|
534
|
+
delete ret.force;
|
535
|
+
delete ret.w;
|
536
|
+
if ("sourcemap" in ret) {
|
537
|
+
const sourcemap = ret.sourcemap;
|
538
|
+
ret.sourcemap = sourcemap === "true" ? true : sourcemap === "false" ? false : ret.sourcemap;
|
539
|
+
}
|
540
|
+
if ("watch" in ret) {
|
541
|
+
const watch = ret.watch;
|
542
|
+
ret.watch = watch ? {} : void 0;
|
543
|
+
}
|
544
|
+
return ret;
|
722
545
|
}
|
546
|
+
/**
|
547
|
+
* removing builder flags before passing as command specific sub-configs
|
548
|
+
*/
|
723
549
|
function cleanBuilderCLIOptions(options) {
|
724
|
-
|
725
|
-
|
726
|
-
|
550
|
+
const ret = { ...options };
|
551
|
+
delete ret.app;
|
552
|
+
return ret;
|
727
553
|
}
|
554
|
+
/**
|
555
|
+
* host may be a number (like 0), should convert to string
|
556
|
+
*/
|
728
557
|
const convertHost = (v) => {
|
729
|
-
|
730
|
-
|
731
|
-
}
|
732
|
-
return v;
|
558
|
+
if (typeof v === "number") return String(v);
|
559
|
+
return v;
|
733
560
|
};
|
561
|
+
/**
|
562
|
+
* base may be a number (like 0), should convert to empty string
|
563
|
+
*/
|
734
564
|
const convertBase = (v) => {
|
735
|
-
|
736
|
-
|
737
|
-
}
|
738
|
-
return v;
|
565
|
+
if (v === 0) return "";
|
566
|
+
return v;
|
739
567
|
};
|
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
|
-
|
568
|
+
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`);
|
569
|
+
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) => {
|
570
|
+
filterDuplicateOptions(options);
|
571
|
+
const { createServer } = await import("./chunks/dep-D_UgUiRQ.js");
|
572
|
+
try {
|
573
|
+
const server = await createServer({
|
574
|
+
root,
|
575
|
+
base: options.base,
|
576
|
+
mode: options.mode,
|
577
|
+
configFile: options.config,
|
578
|
+
configLoader: options.configLoader,
|
579
|
+
logLevel: options.logLevel,
|
580
|
+
clearScreen: options.clearScreen,
|
581
|
+
server: cleanGlobalCLIOptions(options),
|
582
|
+
forceOptimizeDeps: options.force
|
583
|
+
});
|
584
|
+
if (!server.httpServer) throw new Error("HTTP server not available");
|
585
|
+
await server.listen();
|
586
|
+
const info = server.config.logger.info;
|
587
|
+
const modeString = options.mode && options.mode !== "development" ? ` ${import_picocolors.default.bgGreen(` ${import_picocolors.default.bold(options.mode)} `)}` : "";
|
588
|
+
const viteStartTime = global.__vite_start_time ?? false;
|
589
|
+
const startupDurationString = viteStartTime ? import_picocolors.default.dim(`ready in ${import_picocolors.default.reset(import_picocolors.default.bold(Math.ceil(performance.now() - viteStartTime)))} ms`) : "";
|
590
|
+
const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
|
591
|
+
info(`\n ${import_picocolors.default.green(`${import_picocolors.default.bold("VITE")} v${VERSION}`)}${modeString} ${startupDurationString}\n`, { clear: !hasExistingLogs });
|
592
|
+
server.printUrls();
|
593
|
+
const customShortcuts = [];
|
594
|
+
if (profileSession) customShortcuts.push({
|
595
|
+
key: "p",
|
596
|
+
description: "start/stop the profiler",
|
597
|
+
async action(server$1) {
|
598
|
+
if (profileSession) await stopProfiler(server$1.config.logger.info);
|
599
|
+
else {
|
600
|
+
const inspector = await import("node:inspector").then((r) => r.default);
|
601
|
+
await new Promise((res) => {
|
602
|
+
profileSession = new inspector.Session();
|
603
|
+
profileSession.connect();
|
604
|
+
profileSession.post("Profiler.enable", () => {
|
605
|
+
profileSession.post("Profiler.start", () => {
|
606
|
+
server$1.config.logger.info("Profiler started");
|
607
|
+
res();
|
608
|
+
});
|
609
|
+
});
|
610
|
+
});
|
611
|
+
}
|
612
|
+
}
|
613
|
+
});
|
614
|
+
server.bindCLIShortcuts({
|
615
|
+
print: true,
|
616
|
+
customShortcuts
|
617
|
+
});
|
618
|
+
} catch (e) {
|
619
|
+
const logger = createLogger(options.logLevel);
|
620
|
+
logger.error(import_picocolors.default.red(`error when starting dev server:\n${e.stack}`), { error: e });
|
621
|
+
stopProfiler(logger.info);
|
622
|
+
process.exit(1);
|
623
|
+
}
|
624
|
+
});
|
625
|
+
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) => {
|
626
|
+
filterDuplicateOptions(options);
|
627
|
+
const { createBuilder } = await import("./chunks/dep-Ccq9jQdz.js");
|
628
|
+
const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
|
629
|
+
try {
|
630
|
+
const inlineConfig = {
|
631
|
+
root,
|
632
|
+
base: options.base,
|
633
|
+
mode: options.mode,
|
634
|
+
configFile: options.config,
|
635
|
+
configLoader: options.configLoader,
|
636
|
+
logLevel: options.logLevel,
|
637
|
+
clearScreen: options.clearScreen,
|
638
|
+
build: buildOptions,
|
639
|
+
...options.app ? { builder: {} } : {}
|
640
|
+
};
|
641
|
+
const builder = await createBuilder(inlineConfig, null);
|
642
|
+
await builder.buildApp();
|
643
|
+
} catch (e) {
|
644
|
+
createLogger(options.logLevel).error(import_picocolors.default.red(`error during build:\n${e.stack}`), { error: e });
|
645
|
+
process.exit(1);
|
646
|
+
} finally {
|
647
|
+
stopProfiler((message) => createLogger(options.logLevel).info(message));
|
648
|
+
}
|
649
|
+
});
|
650
|
+
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) => {
|
651
|
+
filterDuplicateOptions(options);
|
652
|
+
const { optimizeDeps } = await import("./chunks/dep-P8c3Tybu.js");
|
653
|
+
try {
|
654
|
+
const config = await resolveConfig({
|
655
|
+
root,
|
656
|
+
base: options.base,
|
657
|
+
configFile: options.config,
|
658
|
+
configLoader: options.configLoader,
|
659
|
+
logLevel: options.logLevel,
|
660
|
+
mode: options.mode
|
661
|
+
}, "serve");
|
662
|
+
await optimizeDeps(config, options.force, true);
|
663
|
+
} catch (e) {
|
664
|
+
createLogger(options.logLevel).error(import_picocolors.default.red(`error when optimizing deps:\n${e.stack}`), { error: e });
|
665
|
+
process.exit(1);
|
666
|
+
}
|
667
|
+
});
|
668
|
+
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) => {
|
669
|
+
filterDuplicateOptions(options);
|
670
|
+
const { preview } = await import("./chunks/dep-3jlWaCfC.js");
|
671
|
+
try {
|
672
|
+
const server = await preview({
|
673
|
+
root,
|
674
|
+
base: options.base,
|
675
|
+
configFile: options.config,
|
676
|
+
configLoader: options.configLoader,
|
677
|
+
logLevel: options.logLevel,
|
678
|
+
mode: options.mode,
|
679
|
+
build: { outDir: options.outDir },
|
680
|
+
preview: {
|
681
|
+
port: options.port,
|
682
|
+
strictPort: options.strictPort,
|
683
|
+
host: options.host,
|
684
|
+
open: options.open
|
685
|
+
}
|
686
|
+
});
|
687
|
+
server.printUrls();
|
688
|
+
server.bindCLIShortcuts({ print: true });
|
689
|
+
} catch (e) {
|
690
|
+
createLogger(options.logLevel).error(import_picocolors.default.red(`error when starting preview server:\n${e.stack}`), { error: e });
|
691
|
+
process.exit(1);
|
692
|
+
} finally {
|
693
|
+
stopProfiler((message) => createLogger(options.logLevel).info(message));
|
694
|
+
}
|
824
695
|
});
|
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
696
|
cli.help();
|
946
697
|
cli.version(VERSION);
|
947
698
|
cli.parse();
|
948
699
|
|
949
|
-
|
700
|
+
//#endregion
|
701
|
+
export { stopProfiler };
|