nitro-nightly 3.0.1-20260120-020848-6786d069 → 3.0.1-20260120-133849-ca1a9dee

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 (93) hide show
  1. package/dist/_build/common.mjs +24931 -0
  2. package/dist/_build/rolldown.mjs +6 -11
  3. package/dist/_build/rollup.mjs +201 -0
  4. package/dist/_build/vite.build.mjs +1 -1
  5. package/dist/_chunks/dev.mjs +4 -6
  6. package/dist/_chunks/nitro.mjs +1183 -24
  7. package/dist/_chunks/nitro2.mjs +91 -248
  8. package/dist/_chunks/utils.mjs +254 -0
  9. package/dist/_common.mjs +45 -0
  10. package/dist/_libs/c12+giget+readdirp+chokidar.d.mts +214 -0
  11. package/dist/_libs/citty.mjs +140 -110
  12. package/dist/_libs/commondir+is-reference.mjs +1300 -0
  13. package/dist/_libs/compatx.d.mts +47 -0
  14. package/dist/_libs/confbox.mjs +2488 -70
  15. package/dist/_libs/esbuild.d.mts +20 -0
  16. package/dist/_libs/escape-string-regexp.mjs +8 -0
  17. package/dist/_libs/estree-walker.mjs +187 -0
  18. package/dist/_libs/hasown+resolve+deepmerge.mjs +1972 -0
  19. package/dist/_libs/httpxy.d.mts +79 -0
  20. package/dist/_libs/httpxy.mjs +6 -1
  21. package/dist/_libs/klona.mjs +38 -0
  22. package/dist/_libs/magic-string.d.mts +220 -0
  23. package/dist/_libs/mlly.d.mts +57 -0
  24. package/dist/_libs/nypm+giget+tinyexec.mjs +3603 -0
  25. package/dist/_libs/pkg-types.d.mts +23 -0
  26. package/dist/_libs/plugin-alias.mjs +64 -0
  27. package/dist/_libs/{plugin-alias+plugin-inject.mjs → plugin-inject.mjs} +2 -65
  28. package/dist/_libs/plugin-json.mjs +36 -0
  29. package/dist/_libs/pluginutils+plugin-commonjs.d.mts +241 -0
  30. package/dist/_libs/pluginutils.mjs +652 -0
  31. package/dist/_libs/{c12+dotenv+rc9.mjs → rc9+c12+dotenv.mjs} +105 -12
  32. package/dist/_libs/{chokidar+readdirp.mjs → readdirp+chokidar.mjs} +8 -1
  33. package/dist/_libs/remapping.mjs +117 -0
  34. package/dist/_libs/resolve-uri+gen-mapping.mjs +448 -0
  35. package/dist/_libs/rou3.d.mts +43 -0
  36. package/dist/_libs/rou3.mjs +322 -0
  37. package/dist/_libs/std-env.d.mts +4 -0
  38. package/dist/_libs/tsconfck.mjs +832 -0
  39. package/dist/_libs/ultrahtml.mjs +138 -0
  40. package/dist/_libs/{gen-mapping+remapping+resolve-uri+trace-mapping+unimport+unplugin+unplugin-utils+webpack-virtual-modules.mjs → unimport+unplugin.mjs} +228 -593
  41. package/dist/_libs/unplugin+unimport.d.mts +426 -0
  42. package/dist/_libs/unwasm.d.mts +29 -0
  43. package/dist/_presets.mjs +3 -8
  44. package/dist/builder.mjs +6 -8
  45. package/dist/cli/_chunks/build.mjs +1 -1
  46. package/dist/cli/_chunks/dev.mjs +2 -3
  47. package/dist/cli/_chunks/list.mjs +1 -1
  48. package/dist/cli/_chunks/prepare.mjs +1 -1
  49. package/dist/cli/_chunks/run.mjs +1 -1
  50. package/dist/cli/_chunks/task.mjs +16 -0
  51. package/dist/cli/index.mjs +1 -1
  52. package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -5
  53. package/dist/presets/netlify/runtime/netlify-edge.d.mts +0 -1
  54. package/dist/presets/winterjs/runtime/winterjs.d.mts +0 -1
  55. package/dist/runtime/internal/error/dev.d.mts +0 -1
  56. package/dist/runtime/internal/route-rules.d.mts +0 -4
  57. package/dist/runtime/internal/routes/openapi.d.mts +0 -1
  58. package/dist/runtime/internal/routes/scalar.d.mts +0 -1
  59. package/dist/runtime/internal/routes/swagger.d.mts +0 -1
  60. package/dist/runtime/internal/runtime-config.d.mts +0 -1
  61. package/dist/runtime/nitro.d.mts +0 -3
  62. package/dist/runtime/virtual/renderer-template.d.mts +0 -1
  63. package/dist/types/index.d.mts +25 -1394
  64. package/dist/vite.mjs +18 -641
  65. package/package.json +5 -5
  66. package/dist/_chunks/nitro3.mjs +0 -2696
  67. package/dist/_chunks/nitro4.mjs +0 -176
  68. package/dist/_chunks/nitro5.mjs +0 -733
  69. package/dist/_chunks/nitro6.mjs +0 -1458
  70. package/dist/_chunks/nitro7.mjs +0 -7561
  71. package/dist/_chunks/nitro8.mjs +0 -3524
  72. package/dist/_chunks/nitro9.mjs +0 -1729
  73. package/dist/_libs/_.mjs +0 -3
  74. package/dist/_libs/_2.mjs +0 -3
  75. package/dist/_libs/_3.mjs +0 -4
  76. package/dist/_libs/_4.mjs +0 -6
  77. package/dist/_libs/_5.mjs +0 -3
  78. package/dist/_libs/_6.mjs +0 -3
  79. package/dist/_libs/acorn+confbox+js-tokens+magic-string+mlly+pkg-types+sourcemap-codec+strip-literal+unimport.mjs +0 -8900
  80. package/dist/_libs/confbox+exsolve+pkg-types.mjs +0 -1249
  81. package/dist/_libs/confbox2.mjs +0 -786
  82. package/dist/_libs/confbox3.mjs +0 -404
  83. package/dist/_libs/confbox4.mjs +0 -3
  84. package/dist/_libs/estree-walker+unimport.mjs +0 -378
  85. package/dist/_libs/fdir+picomatch+tinyglobby.mjs +0 -2471
  86. package/dist/_libs/giget+node-fetch-native.mjs +0 -2692
  87. package/dist/_libs/local-pkg+quansync+unimport.mjs +0 -1526
  88. package/dist/_libs/nypm+tinyexec.mjs +0 -858
  89. package/dist/_libs/pathe.mjs +0 -164
  90. package/dist/_libs/perfect-debounce.mjs +0 -89
  91. package/dist/_libs/std-env.mjs +0 -158
  92. package/dist/_libs/unimport.mjs +0 -9
  93. package/dist/_libs/vite-plugin-fullstack.mjs +0 -26
@@ -0,0 +1,214 @@
1
+ import { Stats } from "node:fs";
2
+ import { Jiti, JitiOptions } from "jiti";
3
+ import { EventEmitter } from "node:events";
4
+ import { Readable } from "node:stream";
5
+ import { diff } from "ohash/utils";
6
+
7
+ //#region node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.d.ts
8
+ type AWF = {
9
+ stabilityThreshold: number;
10
+ pollInterval: number;
11
+ };
12
+ type BasicOpts = {
13
+ persistent: boolean;
14
+ ignoreInitial: boolean;
15
+ followSymlinks: boolean;
16
+ cwd?: string;
17
+ usePolling: boolean;
18
+ interval: number;
19
+ binaryInterval: number;
20
+ alwaysStat?: boolean;
21
+ depth?: number;
22
+ ignorePermissionErrors: boolean;
23
+ atomic: boolean | number;
24
+ };
25
+ type ChokidarOptions = Partial<BasicOpts & {
26
+ ignored: Matcher | Matcher[];
27
+ awaitWriteFinish: boolean | Partial<AWF>;
28
+ }>;
29
+ type MatchFunction = (val: string, stats?: Stats) => boolean;
30
+ interface MatcherObject {
31
+ path: string;
32
+ recursive?: boolean;
33
+ }
34
+ type Matcher = string | RegExp | MatchFunction | MatcherObject;
35
+ //#endregion
36
+ //#region node_modules/.pnpm/giget@2.0.0/node_modules/giget/dist/index.d.mts
37
+ interface TemplateInfo {
38
+ name: string;
39
+ tar: string;
40
+ version?: string;
41
+ subdir?: string;
42
+ url?: string;
43
+ defaultDir?: string;
44
+ headers?: Record<string, string | undefined>;
45
+ source?: never;
46
+ dir?: never;
47
+ [key: string]: any;
48
+ }
49
+ type TemplateProvider = (input: string, options: {
50
+ auth?: string;
51
+ }) => TemplateInfo | Promise<TemplateInfo> | null;
52
+ interface DownloadTemplateOptions {
53
+ provider?: string;
54
+ force?: boolean;
55
+ forceClean?: boolean;
56
+ offline?: boolean;
57
+ preferOffline?: boolean;
58
+ providers?: Record<string, TemplateProvider>;
59
+ dir?: string;
60
+ registry?: false | string;
61
+ cwd?: string;
62
+ auth?: string;
63
+ install?: boolean;
64
+ silent?: boolean;
65
+ }
66
+ //#endregion
67
+ //#region node_modules/.pnpm/c12@3.3.3_magicast@0.5.1/node_modules/c12/dist/index.d.mts
68
+ //#region src/dotenv.d.ts
69
+ interface DotenvOptions {
70
+ /**
71
+ * The project root directory (either absolute or relative to the current working directory).
72
+ *
73
+ * Defaults to `options.cwd` in `loadConfig` context, or `process.cwd()` when used as standalone.
74
+ */
75
+ cwd?: string;
76
+ /**
77
+ * What file or files to look in for environment variables (either absolute or relative
78
+ * to the current working directory). For example, `.env`.
79
+ * With the array type, the order enforce the env loading priority (last one overrides).
80
+ */
81
+ fileName?: string | string[];
82
+ /**
83
+ * Whether to interpolate variables within .env.
84
+ *
85
+ * @example
86
+ * ```env
87
+ * BASE_DIR="/test"
88
+ * # resolves to "/test/further"
89
+ * ANOTHER_DIR="${BASE_DIR}/further"
90
+ * ```
91
+ */
92
+ interpolate?: boolean;
93
+ /**
94
+ * An object describing environment variables (key, value pairs).
95
+ */
96
+ env?: NodeJS.ProcessEnv;
97
+ }
98
+ declare global {
99
+ var __c12_dotenv_vars__: Map<Record<string, any>, Set<string>>;
100
+ } //#endregion
101
+ //#region src/types.d.ts
102
+ interface ConfigLayerMeta {
103
+ name?: string;
104
+ [key: string]: any;
105
+ }
106
+ type UserInputConfig = Record<string, any>;
107
+ interface C12InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
108
+ $test?: T;
109
+ $development?: T;
110
+ $production?: T;
111
+ $env?: Record<string, T>;
112
+ $meta?: MT;
113
+ }
114
+ interface SourceOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
115
+ /** Custom meta for layer */
116
+ meta?: MT;
117
+ /** Layer config overrides */
118
+ overrides?: T;
119
+ [key: string]: any;
120
+ /**
121
+ * Options for cloning remote sources
122
+ *
123
+ * @see https://giget.unjs.io
124
+ */
125
+ giget?: DownloadTemplateOptions;
126
+ /**
127
+ * Install dependencies after cloning
128
+ *
129
+ * @see https://nypm.unjs.io
130
+ */
131
+ install?: boolean;
132
+ /**
133
+ * Token for cloning private sources
134
+ *
135
+ * @see https://giget.unjs.io#providing-token-for-private-repositories
136
+ */
137
+ auth?: string;
138
+ }
139
+ interface ConfigLayer<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
140
+ config: T | null;
141
+ source?: string;
142
+ sourceOptions?: SourceOptions<T, MT>;
143
+ meta?: MT;
144
+ cwd?: string;
145
+ configFile?: string;
146
+ }
147
+ interface ResolvedConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends ConfigLayer<T, MT> {
148
+ config: T;
149
+ layers?: ConfigLayer<T, MT>[];
150
+ cwd?: string;
151
+ _configFile?: string;
152
+ }
153
+ type ConfigSource = "overrides" | "main" | "rc" | "packageJson" | "defaultConfig";
154
+ interface ConfigFunctionContext {
155
+ [key: string]: any;
156
+ }
157
+ interface ResolvableConfigContext<T extends UserInputConfig = UserInputConfig> {
158
+ configs: Record<ConfigSource, T | null | undefined>;
159
+ rawConfigs: Record<ConfigSource, ResolvableConfig<T> | null | undefined>;
160
+ }
161
+ type MaybePromise<T> = T | Promise<T>;
162
+ type ResolvableConfig<T extends UserInputConfig = UserInputConfig> = MaybePromise<T | null | undefined> | ((ctx: ResolvableConfigContext<T>) => MaybePromise<T | null | undefined>);
163
+ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
164
+ name?: string;
165
+ cwd?: string;
166
+ configFile?: string;
167
+ rcFile?: false | string;
168
+ globalRc?: boolean;
169
+ dotenv?: boolean | DotenvOptions;
170
+ envName?: string | false;
171
+ packageJson?: boolean | string | string[];
172
+ defaults?: T;
173
+ defaultConfig?: ResolvableConfig<T>;
174
+ overrides?: ResolvableConfig<T>;
175
+ omit$Keys?: boolean;
176
+ /** Context passed to config functions */
177
+ context?: ConfigFunctionContext;
178
+ resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
179
+ jiti?: Jiti;
180
+ jitiOptions?: JitiOptions;
181
+ giget?: false | DownloadTemplateOptions;
182
+ merger?: (...sources: Array<T | null | undefined>) => T;
183
+ extend?: false | {
184
+ extendKey?: string | string[];
185
+ };
186
+ configFileRequired?: boolean;
187
+ }
188
+ //#endregion
189
+ //#region src/watch.d.ts
190
+ type DiffEntries = ReturnType<typeof diff>;
191
+ type ConfigWatcher<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = ResolvedConfig<T, MT> & {
192
+ watchingFiles: string[];
193
+ unwatch: () => Promise<void>;
194
+ };
195
+ interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends LoadConfigOptions<T, MT> {
196
+ chokidarOptions?: ChokidarOptions;
197
+ debounce?: false | number;
198
+ onWatch?: (event: {
199
+ type: "created" | "updated" | "removed";
200
+ path: string;
201
+ }) => void | Promise<void>;
202
+ acceptHMR?: (context: {
203
+ getDiff: () => DiffEntries;
204
+ newConfig: ResolvedConfig<T, MT>;
205
+ oldConfig: ResolvedConfig<T, MT>;
206
+ }) => void | boolean | Promise<void | boolean>;
207
+ onUpdate?: (context: {
208
+ getDiff: () => ReturnType<typeof diff>;
209
+ newConfig: ResolvedConfig<T, MT>;
210
+ oldConfig: ResolvedConfig<T, MT>;
211
+ }) => void | Promise<void>;
212
+ }
213
+ //#endregion
214
+ export { WatchConfigOptions as a, ResolvedConfig as i, ConfigWatcher as n, ChokidarOptions as o, DotenvOptions as r, C12InputConfig as t };
@@ -1,26 +1,6 @@
1
- import consola$1 from "consola";
2
- import { colors } from "consola/utils";
1
+ import { parseArgs } from "node:util";
3
2
 
4
- //#region node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs
5
- function toArray(val) {
6
- if (Array.isArray(val)) return val;
7
- return val === void 0 ? [] : [val];
8
- }
9
- function formatLineColumns(lines, linePrefix = "") {
10
- const maxLengh = [];
11
- for (const line of lines) for (const [i, element] of line.entries()) maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
12
- return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLengh[i])).join(" ")).join("\n");
13
- }
14
- function resolveValue(input) {
15
- return typeof input === "function" ? input() : input;
16
- }
17
- var CLIError = class extends Error {
18
- constructor(message, code) {
19
- super(message);
20
- this.code = code;
21
- this.name = "CLIError";
22
- }
23
- };
3
+ //#region node_modules/.pnpm/citty@0.2.0/node_modules/citty/dist/_chunks/libs/scule.mjs
24
4
  const NUMBER_CHAR_RE = /\d/;
25
5
  const STR_SPLITTERS = [
26
6
  "-",
@@ -85,101 +65,136 @@ function camelCase(str, opts) {
85
65
  function kebabCase(str, joiner) {
86
66
  return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
87
67
  }
88
- function toArr(any) {
89
- return any == void 0 ? [] : Array.isArray(any) ? any : [any];
68
+
69
+ //#endregion
70
+ //#region node_modules/.pnpm/citty@0.2.0/node_modules/citty/dist/index.mjs
71
+ function toArray(val) {
72
+ if (Array.isArray(val)) return val;
73
+ return val === void 0 ? [] : [val];
90
74
  }
91
- function toVal(out, key, val, opts) {
92
- let x;
93
- const old = out[key];
94
- const nxt = ~opts.string.indexOf(key) ? val == void 0 || 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;
95
- out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
75
+ function formatLineColumns(lines, linePrefix = "") {
76
+ const maxLength = [];
77
+ for (const line of lines) for (const [i, element] of line.entries()) maxLength[i] = Math.max(maxLength[i] || 0, element.length);
78
+ return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join("\n");
96
79
  }
97
- function parseRawArgs(args = [], opts = {}) {
98
- let k;
99
- let arr;
100
- let arg;
101
- let name;
102
- let val;
103
- const out = { _: [] };
104
- let i = 0;
105
- let j = 0;
106
- let idx = 0;
107
- const len = args.length;
108
- const alibi = opts.alias !== void 0;
109
- const strict = opts.unknown !== void 0;
110
- const defaults = opts.default !== void 0;
111
- opts.alias = opts.alias || {};
112
- opts.string = toArr(opts.string);
113
- opts.boolean = toArr(opts.boolean);
114
- if (alibi) for (k in opts.alias) {
115
- arr = opts.alias[k] = toArr(opts.alias[k]);
116
- for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
117
- }
118
- for (i = opts.boolean.length; i-- > 0;) {
119
- arr = opts.alias[opts.boolean[i]] || [];
120
- for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
121
- }
122
- for (i = opts.string.length; i-- > 0;) {
123
- arr = opts.alias[opts.string[i]] || [];
124
- for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
80
+ function resolveValue(input) {
81
+ return typeof input === "function" ? input() : input;
82
+ }
83
+ var CLIError = class extends Error {
84
+ code;
85
+ constructor(message, code) {
86
+ super(message);
87
+ this.name = "CLIError";
88
+ this.code = code;
125
89
  }
126
- if (defaults) for (k in opts.default) {
127
- name = typeof opts.default[k];
128
- arr = opts.alias[k] = opts.alias[k] || [];
129
- if (opts[name] !== void 0) {
130
- opts[name].push(k);
131
- for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
90
+ };
91
+ function parseRawArgs(args = [], opts = {}) {
92
+ const booleans = new Set(opts.boolean || []);
93
+ const strings = new Set(opts.string || []);
94
+ const aliasMap = opts.alias || {};
95
+ const defaults = opts.default || {};
96
+ const aliasToMain = /* @__PURE__ */ new Map();
97
+ const mainToAliases = /* @__PURE__ */ new Map();
98
+ for (const [key, value] of Object.entries(aliasMap)) {
99
+ const targets = value;
100
+ for (const target of targets) {
101
+ aliasToMain.set(key, target);
102
+ if (!mainToAliases.has(target)) mainToAliases.set(target, []);
103
+ mainToAliases.get(target).push(key);
104
+ aliasToMain.set(target, key);
105
+ if (!mainToAliases.has(key)) mainToAliases.set(key, []);
106
+ mainToAliases.get(key).push(target);
132
107
  }
133
108
  }
134
- const keys = strict ? Object.keys(opts.alias) : [];
135
- for (i = 0; i < len; i++) {
136
- arg = args[i];
109
+ const options = {};
110
+ function getType(name) {
111
+ if (booleans.has(name)) return "boolean";
112
+ const aliases = mainToAliases.get(name) || [];
113
+ for (const alias of aliases) if (booleans.has(alias)) return "boolean";
114
+ return "string";
115
+ }
116
+ const allOptions = new Set([
117
+ ...booleans,
118
+ ...strings,
119
+ ...Object.keys(aliasMap),
120
+ ...Object.values(aliasMap).flat(),
121
+ ...Object.keys(defaults)
122
+ ]);
123
+ for (const name of allOptions) if (!options[name]) options[name] = {
124
+ type: getType(name),
125
+ default: defaults[name]
126
+ };
127
+ for (const [alias, main] of aliasToMain.entries()) if (alias.length === 1 && options[main] && !options[main].short) options[main].short = alias;
128
+ const processedArgs = [];
129
+ const negatedFlags = {};
130
+ for (let i = 0; i < args.length; i++) {
131
+ const arg = args[i];
137
132
  if (arg === "--") {
138
- out._ = out._.concat(args.slice(++i));
133
+ processedArgs.push(...args.slice(i));
139
134
  break;
140
135
  }
141
- for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
142
- if (j === 0) out._.push(arg);
143
- else if (arg.substring(j, j + 3) === "no-") {
144
- name = arg.slice(Math.max(0, j + 3));
145
- if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
146
- out[name] = false;
147
- } else {
148
- for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
149
- name = arg.substring(j, idx);
150
- val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
151
- arr = j === 2 ? [name] : name;
152
- for (idx = 0; idx < arr.length; idx++) {
153
- name = arr[idx];
154
- if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
155
- toVal(out, name, idx + 1 < arr.length || val, opts);
156
- }
136
+ if (arg.startsWith("--no-")) {
137
+ const flagName = arg.slice(5);
138
+ negatedFlags[flagName] = true;
139
+ continue;
157
140
  }
141
+ processedArgs.push(arg);
158
142
  }
159
- if (defaults) {
160
- for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
143
+ let parsed;
144
+ try {
145
+ parsed = parseArgs({
146
+ args: processedArgs,
147
+ options: Object.keys(options).length > 0 ? options : void 0,
148
+ allowPositionals: true,
149
+ strict: false
150
+ });
151
+ } catch {
152
+ parsed = {
153
+ values: {},
154
+ positionals: processedArgs
155
+ };
161
156
  }
162
- if (alibi) for (k in out) {
163
- arr = opts.alias[k] || [];
164
- while (arr.length > 0) out[arr.shift()] = out[k];
157
+ const out = { _: [] };
158
+ out._ = parsed.positionals;
159
+ for (const [key, value] of Object.entries(parsed.values)) out[key] = value;
160
+ for (const [name] of Object.entries(negatedFlags)) out[name] = false;
161
+ for (const [alias, main] of aliasToMain.entries()) {
162
+ if (out[alias] !== void 0 && out[main] === void 0) out[main] = out[alias];
163
+ if (out[main] !== void 0 && out[alias] === void 0) out[alias] = out[main];
165
164
  }
166
165
  return out;
167
166
  }
168
- function parseArgs(rawArgs, argsDef) {
167
+ const noColor = /* @__PURE__ */ (() => {
168
+ const env = globalThis.process?.env ?? {};
169
+ return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
170
+ })();
171
+ const _c = (c, r = 39) => (t) => noColor ? t : `\u001B[${c}m${t}\u001B[${r}m`;
172
+ const bold = /* @__PURE__ */ _c(1, 22);
173
+ const cyan = /* @__PURE__ */ _c(36);
174
+ const gray = /* @__PURE__ */ _c(90);
175
+ const underline = /* @__PURE__ */ _c(4, 24);
176
+ function parseArgs$1(rawArgs, argsDef) {
169
177
  const parseOptions = {
170
178
  boolean: [],
171
179
  string: [],
172
- mixed: [],
173
180
  alias: {},
174
181
  default: {}
175
182
  };
176
183
  const args = resolveArgs(argsDef);
177
184
  for (const arg of args) {
178
185
  if (arg.type === "positional") continue;
179
- if (arg.type === "string") parseOptions.string.push(arg.name);
186
+ if (arg.type === "string" || arg.type === "enum") parseOptions.string.push(arg.name);
180
187
  else if (arg.type === "boolean") parseOptions.boolean.push(arg.name);
181
188
  if (arg.default !== void 0) parseOptions.default[arg.name] = arg.default;
182
189
  if (arg.alias) parseOptions.alias[arg.name] = arg.alias;
190
+ const camelName = camelCase(arg.name);
191
+ const kebabName = kebabCase(arg.name);
192
+ if (camelName !== arg.name || kebabName !== arg.name) {
193
+ const existingAliases = toArray(parseOptions.alias[arg.name] || []);
194
+ if (camelName !== arg.name && !existingAliases.includes(camelName)) existingAliases.push(camelName);
195
+ if (kebabName !== arg.name && !existingAliases.includes(kebabName)) existingAliases.push(kebabName);
196
+ if (existingAliases.length > 0) parseOptions.alias[arg.name] = existingAliases;
197
+ }
183
198
  }
184
199
  const parsed = parseRawArgs(rawArgs, parseOptions);
185
200
  const [ ...positionalArguments] = parsed._;
@@ -191,6 +206,10 @@ function parseArgs(rawArgs, argsDef) {
191
206
  if (nextPositionalArgument !== void 0) parsedArgsProxy[arg.name] = nextPositionalArgument;
192
207
  else if (arg.default === void 0 && arg.required !== false) throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
193
208
  else parsedArgsProxy[arg.name] = arg.default;
209
+ } else if (arg.type === "enum") {
210
+ const argument = parsedArgsProxy[arg.name];
211
+ const options = arg.options || [];
212
+ if (argument !== void 0 && options.length > 0 && !options.includes(argument)) throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
194
213
  } else if (arg.required && parsedArgsProxy[arg.name] === void 0) throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
195
214
  return parsedArgsProxy;
196
215
  }
@@ -208,7 +227,7 @@ function defineCommand(def) {
208
227
  }
209
228
  async function runCommand(cmd, opts) {
210
229
  const cmdArgs = await resolveValue(cmd.args || {});
211
- const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
230
+ const parsedArgs = parseArgs$1(opts.rawArgs, cmdArgs);
212
231
  const context = {
213
232
  rawArgs: opts.rawArgs,
214
233
  args: parsedArgs,
@@ -223,7 +242,7 @@ async function runCommand(cmd, opts) {
223
242
  const subCommandArgIndex = opts.rawArgs.findIndex((arg) => !arg.startsWith("-"));
224
243
  const subCommandName = opts.rawArgs[subCommandArgIndex];
225
244
  if (subCommandName) {
226
- if (!subCommands[subCommandName]) throw new CLIError(`Unknown command \`${subCommandName}\``, "E_UNKNOWN_COMMAND");
245
+ if (!subCommands[subCommandName]) throw new CLIError(`Unknown command ${cyan(subCommandName)}`, "E_UNKNOWN_COMMAND");
227
246
  const subCommand = await resolveValue(subCommands[subCommandName]);
228
247
  if (subCommand) await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
229
248
  } else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
@@ -246,11 +265,12 @@ async function resolveSubCommand(cmd, rawArgs, parent) {
246
265
  }
247
266
  async function showUsage(cmd, parent) {
248
267
  try {
249
- consola$1.log(await renderUsage(cmd, parent) + "\n");
268
+ console.log(await renderUsage(cmd, parent) + "\n");
250
269
  } catch (error) {
251
- consola$1.error(error);
270
+ console.error(error);
252
271
  }
253
272
  }
273
+ const negativePrefixRe = /^no[-A-Z]/;
254
274
  async function renderUsage(cmd, parent) {
255
275
  const cmdMeta = await resolveValue(cmd.meta || {});
256
276
  const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
@@ -265,15 +285,24 @@ async function renderUsage(cmd, parent) {
265
285
  const isRequired = arg.required !== false && arg.default === void 0;
266
286
  const defaultHint = arg.default ? `="${arg.default}"` : "";
267
287
  posLines.push([
268
- "`" + name + defaultHint + "`",
288
+ cyan(name + defaultHint),
269
289
  arg.description || "",
270
290
  arg.valueHint ? `<${arg.valueHint}>` : ""
271
291
  ]);
272
292
  usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
273
293
  } else {
274
294
  const isRequired = arg.required === true && arg.default === void 0;
275
- const argStr = (arg.type === "boolean" && arg.default === true ? [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ") : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ")) + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "");
276
- argLines.push(["`" + argStr + (isRequired ? " (required)" : "") + "`", arg.description || ""]);
295
+ const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "") + (arg.type === "enum" && arg.options ? `=<${arg.options.join("|")}>` : "");
296
+ argLines.push([cyan(argStr + (isRequired ? " (required)" : "")), arg.description || ""]);
297
+ /**
298
+ * print negative boolean arg variant usage when
299
+ * - enabled by default or has `negativeDescription`
300
+ * - not prefixed with `no-` or `no[A-Z]`
301
+ */
302
+ if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
303
+ const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
304
+ argLines.push([cyan(negativeArgStr + (isRequired ? " (required)" : "")), arg.negativeDescription || ""]);
305
+ }
277
306
  if (isRequired) usageLine.push(argStr);
278
307
  }
279
308
  if (cmd.subCommands) {
@@ -281,30 +310,31 @@ async function renderUsage(cmd, parent) {
281
310
  const subCommands = await resolveValue(cmd.subCommands);
282
311
  for (const [name, sub] of Object.entries(subCommands)) {
283
312
  const meta = await resolveValue((await resolveValue(sub))?.meta);
284
- commandsLines.push([`\`${name}\``, meta?.description || ""]);
313
+ if (meta?.hidden) continue;
314
+ commandsLines.push([cyan(name), meta?.description || ""]);
285
315
  commandNames.push(name);
286
316
  }
287
317
  usageLine.push(commandNames.join("|"));
288
318
  }
289
319
  const usageLines = [];
290
320
  const version = cmdMeta.version || parentMeta.version;
291
- usageLines.push(colors.gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
321
+ usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
292
322
  const hasOptions = argLines.length > 0 || posLines.length > 0;
293
- usageLines.push(`${colors.underline(colors.bold("USAGE"))} \`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}\``, "");
323
+ usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
294
324
  if (posLines.length > 0) {
295
- usageLines.push(colors.underline(colors.bold("ARGUMENTS")), "");
325
+ usageLines.push(underline(bold("ARGUMENTS")), "");
296
326
  usageLines.push(formatLineColumns(posLines, " "));
297
327
  usageLines.push("");
298
328
  }
299
329
  if (argLines.length > 0) {
300
- usageLines.push(colors.underline(colors.bold("OPTIONS")), "");
330
+ usageLines.push(underline(bold("OPTIONS")), "");
301
331
  usageLines.push(formatLineColumns(argLines, " "));
302
332
  usageLines.push("");
303
333
  }
304
334
  if (commandsLines.length > 0) {
305
- usageLines.push(colors.underline(colors.bold("COMMANDS")), "");
335
+ usageLines.push(underline(bold("COMMANDS")), "");
306
336
  usageLines.push(formatLineColumns(commandsLines, " "));
307
- usageLines.push("", `Use \`${commandName} <command> --help\` for more information about a command.`);
337
+ usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
308
338
  }
309
339
  return usageLines.filter((l) => typeof l === "string").join("\n");
310
340
  }
@@ -318,13 +348,13 @@ async function runMain(cmd, opts = {}) {
318
348
  } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
319
349
  const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
320
350
  if (!meta?.version) throw new CLIError("No version specified", "E_NO_VERSION");
321
- consola$1.log(meta.version);
351
+ console.log(meta.version);
322
352
  } else await runCommand(cmd, { rawArgs });
323
353
  } catch (error) {
324
- const isCLIError = error instanceof CLIError;
325
- if (!isCLIError) consola$1.error(error, "\n");
326
- if (isCLIError) await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
327
- consola$1.error(error.message);
354
+ if (error instanceof CLIError) {
355
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
356
+ console.error(error.message);
357
+ } else console.error(error, "\n");
328
358
  process.exit(1);
329
359
  }
330
360
  }