vite 6.3.4 → 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/dist/node/cli.js CHANGED
@@ -1,949 +1,701 @@
1
- import path from 'node:path';
2
- import fs__default from 'node:fs';
3
- import { performance } from 'node:perf_hooks';
4
- import { EventEmitter } from 'events';
5
- import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-Bn81Esdm.js';
6
- import { VERSION } from './constants.js';
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 { 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
- !!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
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 k, arr, arg, name, val, out={ _:[] };
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
- if (alibi) {
81
- for (k in opts.alias) {
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
- if (defaults) {
100
- for (k in opts.default) {
101
- name = typeof opts.default[k];
102
- arr = opts.alias[k] = opts.alias[k] || [];
103
- if (opts[name] !== void 0) {
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
- for (j=0; j < arg.length; j++) {
123
- if (arg.charCodeAt(j) !== 45) break; // "-"
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) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
141
- arr = (j === 2 ? [name] : name);
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('-'.repeat(j) + name);
146
- toVal(out, name, (idx + 1 < arr.length) || val, opts);
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
- if (alibi) {
160
- for (k in out) {
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
- const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
174
- const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
175
- const res = [];
176
- const parse = (match) => {
177
- let variadic = false;
178
- let value = match[1];
179
- if (value.startsWith("...")) {
180
- value = value.slice(3);
181
- variadic = true;
182
- }
183
- return {
184
- required: match[0].startsWith("<"),
185
- value,
186
- variadic
187
- };
188
- };
189
- let angledMatch;
190
- while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
191
- res.push(parse(angledMatch));
192
- }
193
- let squareMatch;
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
- const result = {alias: {}, boolean: []};
201
- for (const [index, option] of options.entries()) {
202
- if (option.names.length > 1) {
203
- result.alias[option.names[0]] = option.names.slice(1);
204
- }
205
- if (option.isBoolean) {
206
- if (option.negated) {
207
- const hasStringTypeOption = options.some((o, i) => {
208
- return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
209
- });
210
- if (!hasStringTypeOption) {
211
- result.boolean.push(option.names[0]);
212
- }
213
- } else {
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
- return arr.sort((a, b) => {
222
- return a.length > b.length ? -1 : 1;
223
- })[0];
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
- return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
129
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
227
130
  };
228
131
  const camelcase = (input) => {
229
- return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
230
- return p1 + p2.toUpperCase();
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
- let i = 0;
235
- let length = keys.length;
236
- let t = obj;
237
- let x;
238
- for (; i < length; ++i) {
239
- x = t[keys[i]];
240
- t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
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
- for (const key of Object.keys(transforms)) {
245
- const transform = transforms[key];
246
- if (transform.shouldTransform) {
247
- obj[key] = Array.prototype.concat.call([], obj[key]);
248
- if (typeof transform.transformFunction === "function") {
249
- obj[key] = obj[key].map(transform.transformFunction);
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
- const m = /([^\\\/]+)$/.exec(input);
256
- return m ? m[1] : "";
156
+ const m = /([^\\\/]+)$/.exec(input);
157
+ return m ? m[1] : "";
257
158
  };
258
159
  const camelcaseOptionName = (name) => {
259
- return name.split(".").map((v, i) => {
260
- return i === 0 ? camelcase(v) : v;
261
- }).join(".");
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
- class Command {
308
- constructor(rawName, description, config = {}, cli) {
309
- this.rawName = rawName;
310
- this.description = description;
311
- this.config = config;
312
- this.cli = cli;
313
- this.options = [];
314
- this.aliasNames = [];
315
- this.name = removeBrackets(rawName);
316
- this.args = findAllBrackets(rawName);
317
- this.examples = [];
318
- }
319
- usage(text) {
320
- this.usageText = text;
321
- return this;
322
- }
323
- allowUnknownOptions() {
324
- this.config.allowUnknownOptions = true;
325
- return this;
326
- }
327
- ignoreOptionDefaultValue() {
328
- this.config.ignoreOptionDefaultValue = true;
329
- return this;
330
- }
331
- version(version, customFlags = "-v, --version") {
332
- this.versionNumber = version;
333
- this.option(customFlags, "Display version number");
334
- return this;
335
- }
336
- example(example) {
337
- this.examples.push(example);
338
- return this;
339
- }
340
- option(rawName, description, config) {
341
- const option = new Option(rawName, description, config);
342
- this.options.push(option);
343
- return this;
344
- }
345
- alias(name) {
346
- this.aliasNames.push(name);
347
- return this;
348
- }
349
- action(callback) {
350
- this.commandAction = callback;
351
- return this;
352
- }
353
- isMatched(name) {
354
- return this.name === name || this.aliasNames.includes(name);
355
- }
356
- get isDefaultCommand() {
357
- return this.name === "" || this.aliasNames.includes("!");
358
- }
359
- get isGlobalCommand() {
360
- return this instanceof GlobalCommand;
361
- }
362
- hasOption(name) {
363
- name = name.split(".")[0];
364
- return this.options.find((option) => {
365
- return option.names.includes(name);
366
- });
367
- }
368
- outputHelp() {
369
- const {name, commands} = this.cli;
370
- const {
371
- versionNumber,
372
- options: globalOptions,
373
- helpCallback
374
- } = this.cli.globalCommand;
375
- let sections = [
376
- {
377
- body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
378
- }
379
- ];
380
- sections.push({
381
- title: "Usage",
382
- body: ` $ ${name} ${this.usageText || this.rawName}`
383
- });
384
- const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
385
- if (showCommands) {
386
- const longestCommandName = findLongest(commands.map((command) => command.rawName));
387
- sections.push({
388
- title: "Commands",
389
- body: commands.map((command) => {
390
- return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
391
- }).join("\n")
392
- });
393
- sections.push({
394
- title: `For more info, run any command with the \`--help\` flag`,
395
- body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
396
- });
397
- }
398
- let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
399
- if (!this.isGlobalCommand && !this.isDefaultCommand) {
400
- options = options.filter((option) => option.name !== "version");
401
- }
402
- if (options.length > 0) {
403
- const longestOptionName = findLongest(options.map((option) => option.rawName));
404
- sections.push({
405
- title: "Options",
406
- body: options.map((option) => {
407
- return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
408
- }).join("\n")
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
- }).join("\n\n"));
429
- }
430
- outputVersion() {
431
- const {name} = this.cli;
432
- const {versionNumber} = this.cli.globalCommand;
433
- if (versionNumber) {
434
- console.log(`${name}/${versionNumber} ${platformInfo}`);
435
- }
436
- }
437
- checkRequiredArgs() {
438
- const minimalArgsCount = this.args.filter((arg) => arg.required).length;
439
- if (this.cli.args.length < minimalArgsCount) {
440
- throw new CACError(`missing required args for command \`${this.rawName}\``);
441
- }
442
- }
443
- checkUnknownOptions() {
444
- const {options, globalCommand} = this.cli;
445
- if (!this.config.allowUnknownOptions) {
446
- for (const name of Object.keys(options)) {
447
- if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
448
- throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
449
- }
450
- }
451
- }
452
- }
453
- checkOptionValue() {
454
- const {options: parsedOptions, globalCommand} = this.cli;
455
- const options = [...globalCommand.options, ...this.options];
456
- for (const option of options) {
457
- const value = parsedOptions[option.name.split(".")[0]];
458
- if (option.required) {
459
- const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
460
- if (value === true || value === false && !hasNegated) {
461
- throw new CACError(`option \`${option.rawName}\` value is missing`);
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
- class CAC extends EventEmitter {
475
- constructor(name = "") {
476
- super();
477
- this.name = name;
478
- this.commands = [];
479
- this.rawArgs = [];
480
- this.args = [];
481
- this.options = {};
482
- this.globalCommand = new GlobalCommand(this);
483
- this.globalCommand.usage("<command> [options]");
484
- }
485
- usage(text) {
486
- this.globalCommand.usage(text);
487
- return this;
488
- }
489
- command(rawName, description, config) {
490
- const command = new Command(rawName, description || "", config, this);
491
- command.globalCommand = this.globalCommand;
492
- this.commands.push(command);
493
- return command;
494
- }
495
- option(rawName, description, config) {
496
- this.globalCommand.option(rawName, description, config);
497
- return this;
498
- }
499
- help(callback) {
500
- this.globalCommand.option("-h, --help", "Display this message");
501
- this.globalCommand.helpCallback = callback;
502
- this.showHelpOnExit = true;
503
- return this;
504
- }
505
- version(version, customFlags = "-v, --version") {
506
- this.globalCommand.version(version, customFlags);
507
- this.showVersionOnExit = true;
508
- return this;
509
- }
510
- example(example) {
511
- this.globalCommand.example(example);
512
- return this;
513
- }
514
- outputHelp() {
515
- if (this.matchedCommand) {
516
- this.matchedCommand.outputHelp();
517
- } else {
518
- this.globalCommand.outputHelp();
519
- }
520
- }
521
- outputVersion() {
522
- this.globalCommand.outputVersion();
523
- }
524
- setParsedInfo({args, options}, matchedCommand, matchedCommandName) {
525
- this.args = args;
526
- this.options = options;
527
- if (matchedCommand) {
528
- this.matchedCommand = matchedCommand;
529
- }
530
- if (matchedCommandName) {
531
- this.matchedCommandName = matchedCommandName;
532
- }
533
- return this;
534
- }
535
- unsetMatchedCommand() {
536
- this.matchedCommand = void 0;
537
- this.matchedCommandName = void 0;
538
- }
539
- parse(argv = processArgs, {
540
- run = true
541
- } = {}) {
542
- this.rawArgs = argv;
543
- if (!this.name) {
544
- this.name = argv[1] ? getFileName(argv[1]) : "cli";
545
- }
546
- let shouldParse = true;
547
- for (const command of this.commands) {
548
- const parsed = this.mri(argv.slice(2), command);
549
- const commandName = parsed.args[0];
550
- if (command.isMatched(commandName)) {
551
- shouldParse = false;
552
- const parsedInfo = __assign(__assign({}, parsed), {
553
- args: parsed.args.slice(1)
554
- });
555
- this.setParsedInfo(parsedInfo, command, commandName);
556
- this.emit(`command:${commandName}`, command);
557
- }
558
- }
559
- if (shouldParse) {
560
- for (const command of this.commands) {
561
- if (command.name === "") {
562
- shouldParse = false;
563
- const parsed = this.mri(argv.slice(2), command);
564
- this.setParsedInfo(parsed, command);
565
- this.emit(`command:!`, command);
566
- }
567
- }
568
- }
569
- if (shouldParse) {
570
- const parsed = this.mri(argv.slice(2));
571
- this.setParsedInfo(parsed);
572
- }
573
- if (this.options.help && this.showHelpOnExit) {
574
- this.outputHelp();
575
- run = false;
576
- this.unsetMatchedCommand();
577
- }
578
- if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
579
- this.outputVersion();
580
- run = false;
581
- this.unsetMatchedCommand();
582
- }
583
- const parsedArgv = {args: this.args, options: this.options};
584
- if (run) {
585
- this.runMatchedCommand();
586
- }
587
- if (!this.matchedCommand && this.args[0]) {
588
- this.emit("command:*");
589
- }
590
- return parsedArgv;
591
- }
592
- mri(argv, command) {
593
- const cliOptions = [
594
- ...this.globalCommand.options,
595
- ...command ? command.options : []
596
- ];
597
- const mriOptions = getMriOptions(cliOptions);
598
- let argsAfterDoubleDashes = [];
599
- const doubleDashesIndex = argv.indexOf("--");
600
- if (doubleDashesIndex > -1) {
601
- argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
602
- argv = argv.slice(0, doubleDashesIndex);
603
- }
604
- let parsed = mri2(argv, mriOptions);
605
- parsed = Object.keys(parsed).reduce((res, name) => {
606
- return __assign(__assign({}, res), {
607
- [camelcaseOptionName(name)]: parsed[name]
608
- });
609
- }, {_: []});
610
- const args = parsed._;
611
- const options = {
612
- "--": argsAfterDoubleDashes
613
- };
614
- const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
615
- let transforms = Object.create(null);
616
- for (const cliOption of cliOptions) {
617
- if (!ignoreDefault && cliOption.config.default !== void 0) {
618
- for (const name of cliOption.names) {
619
- options[name] = cliOption.config.default;
620
- }
621
- }
622
- if (Array.isArray(cliOption.config.type)) {
623
- if (transforms[cliOption.name] === void 0) {
624
- transforms[cliOption.name] = Object.create(null);
625
- transforms[cliOption.name]["shouldTransform"] = true;
626
- transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
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
- if (!profileSession) return;
669
- return new Promise((res, rej) => {
670
- profileSession.post("Profiler.stop", (err, { profile }) => {
671
- if (!err) {
672
- const outPath = path.resolve(
673
- `./vite-profile-${profileCount++}.cpuprofile`
674
- );
675
- fs__default.writeFileSync(outPath, JSON.stringify(profile));
676
- log(
677
- colors.yellow(
678
- `CPU profile written to ${colors.white(colors.dim(outPath))}`
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
- for (const [key, value] of Object.entries(options)) {
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
- const ret = { ...options };
698
- delete ret["--"];
699
- delete ret.c;
700
- delete ret.config;
701
- delete ret.base;
702
- delete ret.l;
703
- delete ret.logLevel;
704
- delete ret.clearScreen;
705
- delete ret.configLoader;
706
- delete ret.d;
707
- delete ret.debug;
708
- delete ret.f;
709
- delete ret.filter;
710
- delete ret.m;
711
- delete ret.mode;
712
- delete ret.w;
713
- if ("sourcemap" in ret) {
714
- const sourcemap = ret.sourcemap;
715
- ret.sourcemap = sourcemap === "true" ? true : sourcemap === "false" ? false : ret.sourcemap;
716
- }
717
- if ("watch" in ret) {
718
- const watch = ret.watch;
719
- ret.watch = watch ? {} : void 0;
720
- }
721
- return ret;
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
- const ret = { ...options };
725
- delete ret.app;
726
- return ret;
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
- if (typeof v === "number") {
730
- return String(v);
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
- if (v === 0) {
736
- return "";
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
- type: [convertBase]
742
- }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option(
743
- "--configLoader <loader>",
744
- `[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)`
745
- ).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`);
746
- 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(
747
- "--force",
748
- `[boolean] force the optimizer to ignore the cache and re-bundle`
749
- ).action(async (root, options) => {
750
- filterDuplicateOptions(options);
751
- const { createServer } = await import('./chunks/dep-Bn81Esdm.js').then(function (n) { return n.S; });
752
- try {
753
- const server = await createServer({
754
- root,
755
- base: options.base,
756
- mode: options.mode,
757
- configFile: options.config,
758
- configLoader: options.configLoader,
759
- logLevel: options.logLevel,
760
- clearScreen: options.clearScreen,
761
- server: cleanGlobalCLIOptions(options),
762
- forceOptimizeDeps: options.force
763
- });
764
- if (!server.httpServer) {
765
- throw new Error("HTTP server not available");
766
- }
767
- await server.listen();
768
- const info = server.config.logger.info;
769
- const modeString = options.mode && options.mode !== "development" ? ` ${colors.bgGreen(` ${colors.bold(options.mode)} `)}` : "";
770
- const viteStartTime = global.__vite_start_time ?? false;
771
- const startupDurationString = viteStartTime ? colors.dim(
772
- `ready in ${colors.reset(
773
- colors.bold(Math.ceil(performance.now() - viteStartTime))
774
- )} ms`
775
- ) : "";
776
- const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
777
- info(
778
- `
779
- ${colors.green(
780
- `${colors.bold("VITE")} v${VERSION}`
781
- )}${modeString} ${startupDurationString}
782
- `,
783
- {
784
- clear: !hasExistingLogs
785
- }
786
- );
787
- server.printUrls();
788
- const customShortcuts = [];
789
- if (profileSession) {
790
- customShortcuts.push({
791
- key: "p",
792
- description: "start/stop the profiler",
793
- async action(server2) {
794
- if (profileSession) {
795
- await stopProfiler(server2.config.logger.info);
796
- } else {
797
- const inspector = await import('node:inspector').then(
798
- (r) => r.default
799
- );
800
- await new Promise((res) => {
801
- profileSession = new inspector.Session();
802
- profileSession.connect();
803
- profileSession.post("Profiler.enable", () => {
804
- profileSession.post("Profiler.start", () => {
805
- server2.config.logger.info("Profiler started");
806
- res();
807
- });
808
- });
809
- });
810
- }
811
- }
812
- });
813
- }
814
- server.bindCLIShortcuts({ print: true, customShortcuts });
815
- } catch (e) {
816
- const logger = createLogger(options.logLevel);
817
- logger.error(colors.red(`error when starting dev server:
818
- ${e.stack}`), {
819
- error: e
820
- });
821
- stopProfiler(logger.info);
822
- process.exit(1);
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-Bn81Esdm.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-Bn81Esdm.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-Bn81Esdm.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
- export { stopProfiler };
700
+ //#endregion
701
+ export { stopProfiler };