@voidzero-dev/vite-plus-core 0.1.2 → 0.1.4

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 (92) hide show
  1. package/dist/rolldown/cli.mjs +619 -197
  2. package/dist/rolldown/config.d.mts +1 -1
  3. package/dist/rolldown/config.mjs +10 -11
  4. package/dist/rolldown/experimental-index.d.mts +20 -6
  5. package/dist/rolldown/experimental-index.mjs +24 -22
  6. package/dist/rolldown/filter-index.d.mts +1 -1
  7. package/dist/rolldown/filter-index.mjs +2 -8
  8. package/dist/rolldown/get-log-filter.mjs +1 -2
  9. package/dist/rolldown/index.d.mts +3 -3
  10. package/dist/rolldown/index.mjs +10 -13
  11. package/dist/rolldown/parallel-plugin-worker.mjs +7 -9
  12. package/dist/rolldown/parallel-plugin.d.mts +1 -1
  13. package/dist/rolldown/parallel-plugin.mjs +1 -2
  14. package/dist/rolldown/parse-ast-index.d.mts +1 -1
  15. package/dist/rolldown/parse-ast-index.mjs +4 -6
  16. package/dist/rolldown/plugins-index.d.mts +3 -3
  17. package/dist/rolldown/plugins-index.mjs +4 -6
  18. package/dist/rolldown/shared/{binding-Bd04_f8P.mjs → binding-BSVL02lq.mjs} +7 -16
  19. package/dist/rolldown/shared/{binding-C4ZlFAt6.d.mts → binding-BohGL_65.d.mts} +10 -5
  20. package/dist/rolldown/shared/{bindingify-input-options-ffqkmT9z.mjs → bindingify-input-options-DkwIzK4F.mjs} +36 -56
  21. package/dist/rolldown/shared/{constructors-cPsD1J5w.d.mts → constructors-Bnr_ApVf.d.mts} +2 -2
  22. package/dist/rolldown/shared/{constructors-C5a55nbY.mjs → constructors-D91FHkmz.mjs} +2 -4
  23. package/dist/rolldown/shared/{define-config-DX_4SBzo.d.mts → define-config-B1jccsL9.d.mts} +84 -30
  24. package/dist/rolldown/shared/{define-config-BMj_QknW.mjs → define-config-DJOr6Iwt.mjs} +1 -2
  25. package/dist/rolldown/shared/{error-BYPsvVEN.mjs → error-tpgdcGrK.mjs} +3 -8
  26. package/dist/rolldown/shared/{load-config-Oj1-3DPg.mjs → load-config-Dapgaecf.mjs} +2 -4
  27. package/dist/rolldown/shared/{logs-CCc_0vhs.mjs → logs-D80CXhvg.mjs} +5 -8
  28. package/dist/rolldown/shared/{misc-Xty885dB.mjs → misc-DJYbNKZX.mjs} +1 -2
  29. package/dist/rolldown/shared/{normalize-string-or-regex-DoNa0azR.mjs → normalize-string-or-regex-BCllTl21.mjs} +3 -6
  30. package/dist/rolldown/shared/{parse-Wj8OTS4w.mjs → parse-DFYpKkKl.mjs} +2 -5
  31. package/dist/rolldown/shared/{prompt-CmNr0AI-.mjs → prompt-DZIXsnf9.mjs} +1 -3
  32. package/dist/rolldown/shared/{rolldown-y9H0nYAD.mjs → rolldown-DK6iIJl8.mjs} +2 -4
  33. package/dist/rolldown/shared/{rolldown-build-DkOWV5Vu.mjs → rolldown-build-rw0HCMhn.mjs} +427 -473
  34. package/dist/rolldown/shared/{transform-D55YcCvB.mjs → transform-BSCulZAO.mjs} +3 -6
  35. package/dist/rolldown/shared/{transform-DoG7c5_r.d.mts → transform-BoJxrM-e.d.mts} +1 -1
  36. package/dist/rolldown/shared/{watch-CVufTfok.mjs → watch-D8uEZyLj.mjs} +71 -77
  37. package/dist/rolldown/utils-index.d.mts +2 -2
  38. package/dist/rolldown/utils-index.mjs +9 -18
  39. package/dist/tsdown/{build-TmLngPCw-I7MHSf0I.js → build-BG-XbM6V-hoyhQqI3.js} +87 -292
  40. package/dist/tsdown/build-DHPfiKA--CvTonTfC.js +5 -0
  41. package/dist/tsdown/{chunk-CdeBBKNj.js → chunk-CSNpwdVU.js} +13 -23
  42. package/dist/tsdown/{debug-tOJ_PtrM-DITcI9An.js → debug-C4FmgzkJ-B6m_gRpz.js} +4 -6
  43. package/dist/tsdown/{detect-DK-FDZQ9-CALXiuJa.js → detect-J1_Vd1yf-BWDiPZkP.js} +2 -4
  44. package/dist/tsdown/{dist-uzMTIu3J.js → dist-C9Oecl0H.js} +24 -56
  45. package/dist/tsdown/{dist-DVPyDO-_.js → dist-Dx-jtFHM.js} +5 -10
  46. package/dist/tsdown/{dist-kuoe97DJ.js → dist-_l70jCqI.js} +1 -2
  47. package/dist/tsdown/{filename-C2azOotK.js → filename-tIvGuRvQ.js} +1 -3
  48. package/dist/tsdown/{index-node-Djp92Gzb-fgHTblzo.js → index-node-Bpsmc0eX-jMz9gD3P.js} +2 -4
  49. package/dist/tsdown/index-types.d.ts +8561 -180
  50. package/dist/tsdown/index.js +7 -9
  51. package/dist/tsdown/{main-BWoReXjl.js → main-DN-_H9u2.js} +8 -23
  52. package/dist/tsdown/{node-Ba_UB_xO.js → node-B3Gdtau1.js} +1 -4
  53. package/dist/tsdown/npm_cjs_chunk_chunk.cjs +6 -8
  54. package/dist/tsdown/npm_cjs_chunk_lt.cjs +13 -16
  55. package/dist/tsdown/npm_cjs_chunk_range.cjs +16 -28
  56. package/dist/tsdown/npm_cjs_chunk_semver.cjs +40 -52
  57. package/dist/tsdown/npm_entry_picomatch.cjs +18 -30
  58. package/dist/tsdown/npm_entry_semver_functions_coerce.cjs +3 -7
  59. package/dist/tsdown/npm_entry_semver_functions_lt.cjs +3 -5
  60. package/dist/tsdown/npm_entry_semver_functions_satisfies.cjs +5 -8
  61. package/dist/tsdown/npm_entry_semver_ranges_min-version.cjs +5 -8
  62. package/dist/tsdown/npm_entry_tree-kill.cjs +2 -6
  63. package/dist/tsdown/{resolver-CdD-yT15-OWjlgV0D.js → resolver-CdD-yT15-3eaymYLw.js} +2 -4
  64. package/dist/tsdown/run.js +6 -12
  65. package/dist/tsdown/{tsc-D6YfZJBZ.js → tsc-OwK9UHsV.js} +4 -6
  66. package/dist/tsdown/{tsc-context-CGmk4Cps.js → tsc-context-DiIjfXAG.js} +2 -4
  67. package/dist/vite/client/client.mjs +116 -19
  68. package/dist/vite/client/env.mjs +1 -2
  69. package/dist/vite/node/chunks/build.js +2 -3
  70. package/dist/vite/node/chunks/build2.js +91 -243
  71. package/dist/vite/node/chunks/chunk.js +7 -13
  72. package/dist/vite/node/chunks/config.js +2 -3
  73. package/dist/vite/node/chunks/dist.js +27 -61
  74. package/dist/vite/node/chunks/dist2.js +11 -95
  75. package/dist/vite/node/chunks/lib.js +1 -7
  76. package/dist/vite/node/chunks/logger.js +4 -9
  77. package/dist/vite/node/chunks/node.js +956 -918
  78. package/dist/vite/node/chunks/optimizer.js +2 -3
  79. package/dist/vite/node/chunks/postcss-import.js +1 -13
  80. package/dist/vite/node/chunks/preview.js +2 -3
  81. package/dist/vite/node/chunks/server.js +2 -3
  82. package/dist/vite/node/cli.js +202 -67
  83. package/dist/vite/node/index.d.ts +17 -14
  84. package/dist/vite/node/index.js +2 -3
  85. package/dist/vite/node/internal.js +1 -2
  86. package/dist/vite/node/module-runner.d.ts +5 -1
  87. package/dist/vite/node/module-runner.js +44 -3
  88. package/dist/vite/types/customEvent.d.ts +27 -0
  89. package/package.json +10 -10
  90. package/dist/rolldown/cli-setup.d.mts +0 -1
  91. package/dist/rolldown/cli-setup.mjs +0 -17
  92. package/dist/tsdown/build-gOkJM1H9-BRI3DQle.js +0 -6
@@ -1,4 +1,3 @@
1
1
  import "./logger.js";
2
- import { $ as depsFromOptimizedDepInfo, J as addManuallyIncludedOptimizeDeps, Q as createIsOptimizedDepUrl, X as cleanupDepsCacheStaleDirs, Y as addOptimizedDepInfo, Z as createIsOptimizedDepFile, at as initDepsOptimizerMetadata, ct as optimizeDeps, dt as optimizedDepInfoFromId, et as depsLogString, ft as optimizedDepNeedsInterop, it as getOptimizedDepPath, lt as optimizeExplicitEnvironmentDeps, mt as toDiscoveredDependencies, nt as extractExportsData, ot as isDepOptimizationDisabled, pt as runOptimizeDeps, rt as getDepsCacheDir, st as loadCachedDepOptimizationMetadata, tt as discoverProjectDependencies, ut as optimizedDepInfoFromFile } from "./node.js";
3
-
4
- export { optimizeDeps };
2
+ import { ct as optimizeDeps } from "./node.js";
3
+ export { optimizeDeps };
@@ -1,6 +1,5 @@
1
1
  import { n as __require, t as __commonJSMin } from "./chunk.js";
2
2
  import { t as require_lib } from "./lib.js";
3
-
4
3
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/format-import-prelude.js
5
4
  var require_format_import_prelude = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
5
  module.exports = function formatImportPrelude(layer, media, supports) {
@@ -15,7 +14,6 @@ var require_format_import_prelude = /* @__PURE__ */ __commonJSMin(((exports, mod
15
14
  return parts.join(" ");
16
15
  };
17
16
  }));
18
-
19
17
  //#endregion
20
18
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/base64-encoded-import.js
21
19
  var require_base64_encoded_import = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -29,7 +27,6 @@ var require_base64_encoded_import = /* @__PURE__ */ __commonJSMin(((exports, mod
29
27
  return params;
30
28
  };
31
29
  }));
32
-
33
30
  //#endregion
34
31
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/apply-conditions.js
35
32
  var require_apply_conditions = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -105,7 +102,6 @@ var require_apply_conditions = /* @__PURE__ */ __commonJSMin(((exports, module)
105
102
  });
106
103
  };
107
104
  }));
108
-
109
105
  //#endregion
110
106
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/apply-raws.js
111
107
  var require_apply_raws = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -120,7 +116,6 @@ var require_apply_raws = /* @__PURE__ */ __commonJSMin(((exports, module) => {
120
116
  });
121
117
  };
122
118
  }));
123
-
124
119
  //#endregion
125
120
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/apply-styles.js
126
121
  var require_apply_styles = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -141,7 +136,6 @@ var require_apply_styles = /* @__PURE__ */ __commonJSMin(((exports, module) => {
141
136
  });
142
137
  };
143
138
  }));
144
-
145
139
  //#endregion
146
140
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/data-url.js
147
141
  var require_data_url = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -161,7 +155,6 @@ var require_data_url = /* @__PURE__ */ __commonJSMin(((exports, module) => {
161
155
  contents
162
156
  };
163
157
  }));
164
-
165
158
  //#endregion
166
159
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/parse-statements.js
167
160
  var require_parse_statements = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -287,7 +280,6 @@ var require_parse_statements = /* @__PURE__ */ __commonJSMin(((exports, module)
287
280
  };
288
281
  }
289
282
  }));
290
-
291
283
  //#endregion
292
284
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/process-content.js
293
285
  var require_process_content = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -322,7 +314,6 @@ var require_process_content = /* @__PURE__ */ __commonJSMin(((exports, module) =
322
314
  });
323
315
  }
324
316
  }));
325
-
326
317
  //#endregion
327
318
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/lib/parse-styles.js
328
319
  var require_parse_styles = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -426,7 +417,6 @@ var require_parse_styles = /* @__PURE__ */ __commonJSMin(((exports, module) => {
426
417
  }
427
418
  module.exports = parseStyles;
428
419
  }));
429
-
430
420
  //#endregion
431
421
  //#region ../../node_modules/.pnpm/postcss-import@16.1.1_postcss@8.5.6/node_modules/postcss-import/index.js
432
422
  var require_postcss_import = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -472,8 +462,6 @@ var require_postcss_import = /* @__PURE__ */ __commonJSMin(((exports, module) =>
472
462
  AtImport.postcss = true;
473
463
  module.exports = AtImport;
474
464
  }));
475
-
476
465
  //#endregion
477
466
  export default require_postcss_import();
478
-
479
- export { };
467
+ export {};
@@ -1,4 +1,3 @@
1
1
  import "./logger.js";
2
- import { C as resolvePreviewOptions, S as preview } from "./node.js";
3
-
4
- export { preview };
2
+ import { S as preview } from "./node.js";
3
+ export { preview };
@@ -1,4 +1,3 @@
1
1
  import "./logger.js";
2
- import { _t as createServer, bt as restartServerWithUrls, gt as _createServer, vt as createServerCloseFn, xt as serverConfigDefaults, yt as resolveServerOptions } from "./node.js";
3
-
4
- export { createServer };
2
+ import { _t as createServer } from "./node.js";
3
+ export { createServer };
@@ -4,9 +4,7 @@ import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import { inspect } from "node:util";
6
6
  import { performance } from "node:perf_hooks";
7
- import { EventEmitter } from "events";
8
-
9
- //#region ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
7
+ //#region ../../node_modules/.pnpm/cac@7.0.0/node_modules/cac/dist/index.js
10
8
  function toArr(any) {
11
9
  return any == null ? [] : Array.isArray(any) ? any : [any];
12
10
  }
@@ -14,7 +12,7 @@ function toVal(out, key, val, opts) {
14
12
  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;
15
13
  out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
16
14
  }
17
- function mri2(args, opts) {
15
+ function lib_default(args, opts) {
18
16
  args = args || [];
19
17
  opts = opts || {};
20
18
  var k, arr, arg, name, val, out = { _: [] };
@@ -79,8 +77,10 @@ function mri2(args, opts) {
79
77
  }
80
78
  return out;
81
79
  }
82
- const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
83
- const findAllBrackets = (v) => {
80
+ function removeBrackets(v) {
81
+ return v.replace(/[<[].+/, "").trim();
82
+ }
83
+ function findAllBrackets(v) {
84
84
  const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
85
85
  const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
86
86
  const res = [];
@@ -102,8 +102,8 @@ const findAllBrackets = (v) => {
102
102
  let squareMatch;
103
103
  while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
104
104
  return res;
105
- };
106
- const getMriOptions = (options) => {
105
+ }
106
+ function getMriOptions(options) {
107
107
  const result = {
108
108
  alias: {},
109
109
  boolean: []
@@ -117,62 +117,76 @@ const getMriOptions = (options) => {
117
117
  } else result.boolean.push(option.names[0]);
118
118
  }
119
119
  return result;
120
- };
121
- const findLongest = (arr) => {
120
+ }
121
+ function findLongest(arr) {
122
122
  return arr.sort((a, b) => {
123
123
  return a.length > b.length ? -1 : 1;
124
124
  })[0];
125
- };
126
- const padRight = (str, length) => {
125
+ }
126
+ function padRight(str, length) {
127
127
  return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
128
- };
129
- const camelcase = (input) => {
130
- return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
128
+ }
129
+ function camelcase(input) {
130
+ return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2) => {
131
131
  return p1 + p2.toUpperCase();
132
132
  });
133
- };
134
- const setDotProp = (obj, keys, val) => {
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) ? {} : [];
133
+ }
134
+ function setDotProp(obj, keys, val) {
135
+ let current = obj;
136
+ for (let i = 0; i < keys.length; i++) {
137
+ const key = keys[i];
138
+ if (i === keys.length - 1) {
139
+ current[key] = val;
140
+ return;
141
+ }
142
+ if (current[key] == null) {
143
+ const nextKeyIsArrayIndex = +keys[i + 1] > -1;
144
+ current[key] = nextKeyIsArrayIndex ? [] : {};
145
+ }
146
+ current = current[key];
142
147
  }
143
- };
144
- const setByType = (obj, transforms) => {
148
+ }
149
+ function setByType(obj, transforms) {
145
150
  for (const key of Object.keys(transforms)) {
146
151
  const transform = transforms[key];
147
152
  if (transform.shouldTransform) {
148
- obj[key] = Array.prototype.concat.call([], obj[key]);
153
+ obj[key] = [obj[key]].flat();
149
154
  if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
150
155
  }
151
156
  }
152
- };
153
- const getFileName = (input) => {
154
- const m = /([^\\\/]+)$/.exec(input);
157
+ }
158
+ function getFileName(input) {
159
+ const m = /([^\\/]+)$/.exec(input);
155
160
  return m ? m[1] : "";
156
- };
157
- const camelcaseOptionName = (name) => {
161
+ }
162
+ function camelcaseOptionName(name) {
158
163
  return name.split(".").map((v, i) => {
159
164
  return i === 0 ? camelcase(v) : v;
160
165
  }).join(".");
161
- };
166
+ }
162
167
  var CACError = class extends Error {
163
168
  constructor(message) {
164
169
  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;
170
+ this.name = "CACError";
171
+ if (typeof Error.captureStackTrace !== "function") this.stack = new Error(message).stack;
168
172
  }
169
173
  };
170
174
  var Option = class {
175
+ rawName;
176
+ description;
177
+ /** Option name */
178
+ name;
179
+ /** Option name and aliases */
180
+ names;
181
+ isBoolean;
182
+ required;
183
+ config;
184
+ negated;
171
185
  constructor(rawName, description, config) {
172
186
  this.rawName = rawName;
173
187
  this.description = description;
174
188
  this.config = Object.assign({}, config);
175
- rawName = rawName.replace(/\.\*/g, "");
189
+ rawName = rawName.replaceAll(".*", "");
176
190
  this.negated = false;
177
191
  this.names = removeBrackets(rawName).split(",").map((v) => {
178
192
  let name = v.trim().replace(/^-{1,2}/, "");
@@ -182,16 +196,39 @@ var Option = class {
182
196
  }
183
197
  return camelcaseOptionName(name);
184
198
  }).sort((a, b) => a.length > b.length ? 1 : -1);
185
- this.name = this.names[this.names.length - 1];
199
+ this.name = this.names.at(-1);
186
200
  if (this.negated && this.config.default == null) this.config.default = true;
187
201
  if (rawName.includes("<")) this.required = true;
188
202
  else if (rawName.includes("[")) this.required = false;
189
203
  else this.isBoolean = true;
190
204
  }
191
205
  };
192
- const processArgs = process.argv;
193
- const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
206
+ let runtimeProcessArgs;
207
+ let runtimeInfo;
208
+ if (typeof process !== "undefined") {
209
+ let runtimeName;
210
+ if (typeof Deno !== "undefined" && typeof Deno.version?.deno === "string") runtimeName = "deno";
211
+ else if (typeof Bun !== "undefined" && typeof Bun.version === "string") runtimeName = "bun";
212
+ else runtimeName = "node";
213
+ runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
214
+ runtimeProcessArgs = process.argv;
215
+ } else if (typeof navigator === "undefined") runtimeInfo = `unknown`;
216
+ else runtimeInfo = `${navigator.platform} ${navigator.userAgent}`;
194
217
  var Command = class {
218
+ rawName;
219
+ description;
220
+ config;
221
+ cli;
222
+ options;
223
+ aliasNames;
224
+ name;
225
+ args;
226
+ commandAction;
227
+ usageText;
228
+ versionNumber;
229
+ examples;
230
+ helpCallback;
231
+ globalCommand;
195
232
  constructor(rawName, description, config = {}, cli) {
196
233
  this.rawName = rawName;
197
234
  this.description = description;
@@ -224,6 +261,12 @@ var Command = class {
224
261
  this.examples.push(example);
225
262
  return this;
226
263
  }
264
+ /**
265
+ * Add a option for this command
266
+ * @param rawName Raw option name(s)
267
+ * @param description Option description
268
+ * @param config Option config
269
+ */
227
270
  option(rawName, description, config) {
228
271
  const option = new Option(rawName, description, config);
229
272
  this.options.push(option);
@@ -237,6 +280,10 @@ var Command = class {
237
280
  this.commandAction = callback;
238
281
  return this;
239
282
  }
283
+ /**
284
+ * Check if a command name is matched by this command
285
+ * @param name Command name
286
+ */
240
287
  isMatched(name) {
241
288
  return this.name === name || this.aliasNames.includes(name);
242
289
  }
@@ -246,6 +293,10 @@ var Command = class {
246
293
  get isGlobalCommand() {
247
294
  return this instanceof GlobalCommand;
248
295
  }
296
+ /**
297
+ * Check if an option is registered in this command
298
+ * @param name Option name
299
+ */
249
300
  hasOption(name) {
250
301
  name = name.split(".")[0];
251
302
  return this.options.find((option) => {
@@ -267,8 +318,7 @@ var Command = class {
267
318
  body: commands.map((command) => {
268
319
  return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
269
320
  }).join("\n")
270
- });
271
- sections.push({
321
+ }, {
272
322
  title: `For more info, run any command with the \`--help\` flag`,
273
323
  body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
274
324
  });
@@ -292,26 +342,33 @@ var Command = class {
292
342
  }).join("\n")
293
343
  });
294
344
  if (helpCallback) sections = helpCallback(sections) || sections;
295
- console.log(sections.map((section) => {
296
- return section.title ? `${section.title}:
297
- ${section.body}` : section.body;
345
+ console.info(sections.map((section) => {
346
+ return section.title ? `${section.title}:\n${section.body}` : section.body;
298
347
  }).join("\n\n"));
299
348
  }
300
349
  outputVersion() {
301
350
  const { name } = this.cli;
302
351
  const { versionNumber } = this.cli.globalCommand;
303
- if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
352
+ if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
304
353
  }
305
354
  checkRequiredArgs() {
306
355
  const minimalArgsCount = this.args.filter((arg) => arg.required).length;
307
356
  if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
308
357
  }
358
+ /**
359
+ * Check if the parsed options contain any unknown options
360
+ *
361
+ * Exit and output error when true
362
+ */
309
363
  checkUnknownOptions() {
310
364
  const { options, globalCommand } = this.cli;
311
365
  if (!this.config.allowUnknownOptions) {
312
366
  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}`}\``);
313
367
  }
314
368
  }
369
+ /**
370
+ * Check if the required string-type options exist
371
+ */
315
372
  checkOptionValue() {
316
373
  const { options: parsedOptions, globalCommand } = this.cli;
317
374
  const options = [...globalCommand.options, ...this.options];
@@ -323,14 +380,43 @@ ${section.body}` : section.body;
323
380
  }
324
381
  }
325
382
  }
383
+ /**
384
+ * Check if the number of args is more than expected
385
+ */
386
+ checkUnusedArgs() {
387
+ const maximumArgsCount = this.args.some((arg) => arg.variadic) ? Infinity : this.args.length;
388
+ if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg) => `\`${arg}\``).join(", ")}`);
389
+ }
326
390
  };
327
391
  var GlobalCommand = class extends Command {
328
392
  constructor(cli) {
329
393
  super("@@global@@", "", {}, cli);
330
394
  }
331
395
  };
332
- var __assign = Object.assign;
333
- var CAC = class extends EventEmitter {
396
+ var CAC = class extends EventTarget {
397
+ /** The program name to display in help and version message */
398
+ name;
399
+ commands;
400
+ globalCommand;
401
+ matchedCommand;
402
+ matchedCommandName;
403
+ /**
404
+ * Raw CLI arguments
405
+ */
406
+ rawArgs;
407
+ /**
408
+ * Parsed CLI arguments
409
+ */
410
+ args;
411
+ /**
412
+ * Parsed CLI options, camelCased
413
+ */
414
+ options;
415
+ showHelpOnExit;
416
+ showVersionOnExit;
417
+ /**
418
+ * @param name The program name to display in help and version message
419
+ */
334
420
  constructor(name = "") {
335
421
  super();
336
422
  this.name = name;
@@ -341,39 +427,75 @@ var CAC = class extends EventEmitter {
341
427
  this.globalCommand = new GlobalCommand(this);
342
428
  this.globalCommand.usage("<command> [options]");
343
429
  }
430
+ /**
431
+ * Add a global usage text.
432
+ *
433
+ * This is not used by sub-commands.
434
+ */
344
435
  usage(text) {
345
436
  this.globalCommand.usage(text);
346
437
  return this;
347
438
  }
439
+ /**
440
+ * Add a sub-command
441
+ */
348
442
  command(rawName, description, config) {
349
443
  const command = new Command(rawName, description || "", config, this);
350
444
  command.globalCommand = this.globalCommand;
351
445
  this.commands.push(command);
352
446
  return command;
353
447
  }
448
+ /**
449
+ * Add a global CLI option.
450
+ *
451
+ * Which is also applied to sub-commands.
452
+ */
354
453
  option(rawName, description, config) {
355
454
  this.globalCommand.option(rawName, description, config);
356
455
  return this;
357
456
  }
457
+ /**
458
+ * Show help message when `-h, --help` flags appear.
459
+ *
460
+ */
358
461
  help(callback) {
359
462
  this.globalCommand.option("-h, --help", "Display this message");
360
463
  this.globalCommand.helpCallback = callback;
361
464
  this.showHelpOnExit = true;
362
465
  return this;
363
466
  }
467
+ /**
468
+ * Show version number when `-v, --version` flags appear.
469
+ *
470
+ */
364
471
  version(version, customFlags = "-v, --version") {
365
472
  this.globalCommand.version(version, customFlags);
366
473
  this.showVersionOnExit = true;
367
474
  return this;
368
475
  }
476
+ /**
477
+ * Add a global example.
478
+ *
479
+ * This example added here will not be used by sub-commands.
480
+ */
369
481
  example(example) {
370
482
  this.globalCommand.example(example);
371
483
  return this;
372
484
  }
485
+ /**
486
+ * Output the corresponding help message
487
+ * When a sub-command is matched, output the help message for the command
488
+ * Otherwise output the global one.
489
+ *
490
+ */
373
491
  outputHelp() {
374
492
  if (this.matchedCommand) this.matchedCommand.outputHelp();
375
493
  else this.globalCommand.outputHelp();
376
494
  }
495
+ /**
496
+ * Output the version number.
497
+ *
498
+ */
377
499
  outputVersion() {
378
500
  this.globalCommand.outputVersion();
379
501
  }
@@ -388,7 +510,14 @@ var CAC = class extends EventEmitter {
388
510
  this.matchedCommand = void 0;
389
511
  this.matchedCommandName = void 0;
390
512
  }
391
- parse(argv = processArgs, { run = true } = {}) {
513
+ /**
514
+ * Parse argv
515
+ */
516
+ parse(argv, { run = true } = {}) {
517
+ if (!argv) {
518
+ if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
519
+ argv = runtimeProcessArgs;
520
+ }
392
521
  this.rawArgs = argv;
393
522
  if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
394
523
  let shouldParse = true;
@@ -397,17 +526,20 @@ var CAC = class extends EventEmitter {
397
526
  const commandName = parsed.args[0];
398
527
  if (command.isMatched(commandName)) {
399
528
  shouldParse = false;
400
- const parsedInfo = __assign(__assign({}, parsed), { args: parsed.args.slice(1) });
529
+ const parsedInfo = {
530
+ ...parsed,
531
+ args: parsed.args.slice(1)
532
+ };
401
533
  this.setParsedInfo(parsedInfo, command, commandName);
402
- this.emit(`command:${commandName}`, command);
534
+ this.dispatchEvent(new CustomEvent(`command:${commandName}`, { detail: command }));
403
535
  }
404
536
  }
405
537
  if (shouldParse) {
406
- for (const command of this.commands) if (command.name === "") {
538
+ for (const command of this.commands) if (command.isDefaultCommand) {
407
539
  shouldParse = false;
408
540
  const parsed = this.mri(argv.slice(2), command);
409
541
  this.setParsedInfo(parsed, command);
410
- this.emit(`command:!`, command);
542
+ this.dispatchEvent(new CustomEvent("command:!", { detail: command }));
411
543
  }
412
544
  }
413
545
  if (shouldParse) {
@@ -429,7 +561,7 @@ var CAC = class extends EventEmitter {
429
561
  options: this.options
430
562
  };
431
563
  if (run) this.runMatchedCommand();
432
- if (!this.matchedCommand && this.args[0]) this.emit("command:*");
564
+ if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", { detail: this.args[0] }));
433
565
  return parsedArgv;
434
566
  }
435
567
  mri(argv, command) {
@@ -437,26 +569,27 @@ var CAC = class extends EventEmitter {
437
569
  const mriOptions = getMriOptions(cliOptions);
438
570
  let argsAfterDoubleDashes = [];
439
571
  const doubleDashesIndex = argv.indexOf("--");
440
- if (doubleDashesIndex > -1) {
572
+ if (doubleDashesIndex !== -1) {
441
573
  argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
442
574
  argv = argv.slice(0, doubleDashesIndex);
443
575
  }
444
- let parsed = mri2(argv, mriOptions);
576
+ let parsed = lib_default(argv, mriOptions);
445
577
  parsed = Object.keys(parsed).reduce((res, name) => {
446
- return __assign(__assign({}, res), { [camelcaseOptionName(name)]: parsed[name] });
578
+ return {
579
+ ...res,
580
+ [camelcaseOptionName(name)]: parsed[name]
581
+ };
447
582
  }, { _: [] });
448
583
  const args = parsed._;
449
584
  const options = { "--": argsAfterDoubleDashes };
450
585
  const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
451
- let transforms = Object.create(null);
586
+ const transforms = Object.create(null);
452
587
  for (const cliOption of cliOptions) {
453
588
  if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
454
- if (Array.isArray(cliOption.config.type)) {
455
- if (transforms[cliOption.name] === void 0) {
456
- transforms[cliOption.name] = Object.create(null);
457
- transforms[cliOption.name]["shouldTransform"] = true;
458
- transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
459
- }
589
+ if (Array.isArray(cliOption.config.type) && transforms[cliOption.name] === void 0) {
590
+ transforms[cliOption.name] = Object.create(null);
591
+ transforms[cliOption.name].shouldTransform = true;
592
+ transforms[cliOption.name].transformFunction = cliOption.config.type[0];
460
593
  }
461
594
  }
462
595
  for (const key of Object.keys(parsed)) if (key !== "_") {
@@ -474,6 +607,7 @@ var CAC = class extends EventEmitter {
474
607
  command.checkUnknownOptions();
475
608
  command.checkOptionValue();
476
609
  command.checkRequiredArgs();
610
+ command.checkUnusedArgs();
477
611
  const actionArgs = [];
478
612
  command.args.forEach((arg, index) => {
479
613
  if (arg.variadic) actionArgs.push(args.slice(index));
@@ -483,8 +617,10 @@ var CAC = class extends EventEmitter {
483
617
  return command.commandAction.apply(this, actionArgs);
484
618
  }
485
619
  };
620
+ /**
621
+ * @param name The program name to display in help and version message
622
+ */
486
623
  const cac = (name = "") => new CAC(name);
487
-
488
624
  //#endregion
489
625
  //#region ../../rolldown-vite/packages/vite/src/node/cli.ts
490
626
  var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
@@ -697,6 +833,5 @@ cli.command("preview [root]", "locally preview production build").option("--host
697
833
  cli.help();
698
834
  cli.version(VITE_PLUS_VERSION);
699
835
  cli.parse();
700
-
701
836
  //#endregion
702
- export { stopProfiler };
837
+ export { stopProfiler };