vite 6.3.5 → 7.1.5

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