nitro 3.0.260311-beta → 3.0.260415-beta

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 (206) hide show
  1. package/dist/_build/common.mjs +630 -1602
  2. package/dist/_build/rolldown.mjs +0 -11
  3. package/dist/_build/rollup.mjs +0 -13
  4. package/dist/_build/vite.build.mjs +0 -2
  5. package/dist/_chunks/nitro.mjs +23 -216
  6. package/dist/_chunks/nitro2.mjs +0 -2
  7. package/dist/_chunks/nitro3.mjs +128 -121
  8. package/dist/_chunks/nitro4.mjs +127 -0
  9. package/dist/_chunks/utils.mjs +0 -7
  10. package/dist/_common.mjs +0 -2
  11. package/dist/_dev.d.mts +0 -3
  12. package/dist/_dev.mjs +0 -10
  13. package/dist/_libs/_.mjs +0 -1
  14. package/dist/_libs/_3.mjs +0 -1
  15. package/dist/_libs/_5.mjs +0 -1
  16. package/dist/_libs/_6.mjs +0 -2
  17. package/dist/_libs/_7.mjs +0 -3
  18. package/dist/_libs/c12+rc9.mjs +24 -22
  19. package/dist/_libs/c12+readdirp+chokidar.d.mts +0 -7
  20. package/dist/_libs/citty.mjs +134 -31
  21. package/dist/_libs/commondir+is-reference.mjs +2 -9
  22. package/dist/_libs/compatx.d.mts +0 -2
  23. package/dist/_libs/compatx.mjs +0 -2
  24. package/dist/_libs/esbuild.d.mts +0 -1
  25. package/dist/_libs/escape-string-regexp.mjs +0 -2
  26. package/dist/_libs/estree+pluginutils.d.mts +0 -5
  27. package/dist/_libs/estree-walker.mjs +3 -88
  28. package/dist/_libs/hasown+resolve+deepmerge.mjs +22 -85
  29. package/dist/_libs/httpxy.d.mts +9 -5
  30. package/dist/_libs/httpxy.mjs +284 -116
  31. package/dist/_libs/klona.mjs +0 -2
  32. package/dist/_libs/magic-string.d.mts +0 -2
  33. package/dist/_libs/mlly.d.mts +0 -2
  34. package/dist/_libs/nypm+tinyexec.mjs +111 -134
  35. package/dist/_libs/perfect-debounce.mjs +0 -20
  36. package/dist/_libs/pkg-types.d.mts +0 -3
  37. package/dist/_libs/plugin-alias.mjs +0 -2
  38. package/dist/_libs/plugin-inject.mjs +0 -2
  39. package/dist/_libs/plugin-json.mjs +0 -2
  40. package/dist/_libs/pluginutils.mjs +0 -26
  41. package/dist/_libs/readdirp+chokidar.mjs +0 -173
  42. package/dist/_libs/remapping.mjs +0 -2
  43. package/dist/_libs/resolve-uri+gen-mapping.mjs +0 -32
  44. package/dist/_libs/rou3.d.mts +0 -4
  45. package/dist/_libs/rou3.mjs +0 -29
  46. package/dist/_libs/std-env.d.mts +1 -3
  47. package/dist/_libs/tsconfck.mjs +0 -294
  48. package/dist/_libs/ultrahtml.mjs +0 -2
  49. package/dist/_libs/unimport+unplugin.mjs +1 -44
  50. package/dist/_libs/unplugin+unimport.d.mts +0 -7
  51. package/dist/_libs/unwasm.d.mts +0 -3
  52. package/dist/_presets.mjs +211 -80
  53. package/dist/builder.d.mts +1 -22
  54. package/dist/builder.mjs +0 -11
  55. package/dist/cli/_chunks/build.mjs +0 -2
  56. package/dist/cli/_chunks/common.mjs +0 -2
  57. package/dist/cli/_chunks/deploy.mjs +0 -3
  58. package/dist/cli/_chunks/dev.mjs +0 -5
  59. package/dist/cli/_chunks/docs.mjs +1 -3
  60. package/dist/cli/_chunks/list.mjs +0 -2
  61. package/dist/cli/_chunks/prepare.mjs +0 -2
  62. package/dist/cli/_chunks/preview.mjs +1 -4
  63. package/dist/cli/_chunks/run.mjs +0 -2
  64. package/dist/cli/_chunks/task.mjs +0 -2
  65. package/dist/cli/index.mjs +0 -2
  66. package/{skills/nitro/docs/docs/quick-start.md → dist/docs/0.docs/1.quick-start.md} +4 -4
  67. package/{skills/nitro/docs/docs/lifecycle.md → dist/docs/0.docs/10.lifecycle.md} +4 -4
  68. package/dist/docs/0.docs/11.openapi.md +291 -0
  69. package/{skills/nitro/docs/docs/plugins.md → dist/docs/0.docs/12.plugins.md} +2 -2
  70. package/{skills/nitro/docs/docs/tasks.md → dist/docs/0.docs/13.tasks.md} +6 -6
  71. package/dist/docs/0.docs/14.websocket.md +386 -0
  72. package/{skills/nitro/docs/docs/migration.md → dist/docs/0.docs/15.migration.md} +2 -4
  73. package/{skills/nitro/docs/docs/renderer.md → dist/docs/0.docs/2.renderer.md} +8 -8
  74. package/{skills/nitro/docs/docs/routing.md → dist/docs/0.docs/3.routing.md} +34 -34
  75. package/{skills/nitro/docs/docs/server-entry.md → dist/docs/0.docs/4.server-entry.md} +6 -6
  76. package/{skills/nitro/docs/docs/cache.md → dist/docs/0.docs/5.cache.md} +12 -12
  77. package/{skills/nitro/docs/docs/storage.md → dist/docs/0.docs/6.storage.md} +6 -6
  78. package/{skills/nitro/docs/docs/assets.md → dist/docs/0.docs/7.assets.md} +8 -8
  79. package/{skills/nitro/docs/docs/configuration.md → dist/docs/0.docs/8.configuration.md} +16 -16
  80. package/{skills/nitro/docs/docs/database.md → dist/docs/0.docs/9.database.md} +6 -6
  81. package/{skills/nitro/docs/deploy → dist/docs/1.deploy/0.index}/index.md +3 -3
  82. package/{skills/nitro/docs/deploy/providers/aws.md → dist/docs/1.deploy/2.providers/1.aws.md} +4 -4
  83. package/{skills/nitro/docs/deploy/providers/iis.md → dist/docs/1.deploy/2.providers/15.iis.md} +2 -2
  84. package/{skills/nitro/docs/deploy/providers/aws-amplify.md → dist/docs/1.deploy/2.providers/2.aws-amplify.md} +2 -2
  85. package/{skills/nitro/docs/deploy/providers/vercel.md → dist/docs/1.deploy/2.providers/21.vercel.md} +98 -7
  86. package/{skills/nitro/docs/deploy/providers/zephyr.md → dist/docs/1.deploy/2.providers/23.zephyr.md} +2 -2
  87. package/{skills/nitro/docs/deploy/providers/cloudflare.md → dist/docs/1.deploy/2.providers/5.cloudflare.md} +9 -15
  88. package/dist/docs/1.deploy/2.providers/8.edgeone.md +20 -0
  89. package/{skills/nitro/docs/config → dist/docs/2.config/0.index}/index.md +165 -91
  90. package/{skills/nitro/docs/examples/hono.md → dist/docs/3.examples/10.hono.md} +1 -1
  91. package/{skills/nitro/docs/examples/import-alias.md → dist/docs/3.examples/11.import-alias.md} +1 -4
  92. package/{skills/nitro/docs/examples/mono-jsx.md → dist/docs/3.examples/13.mono-jsx.md} +2 -2
  93. package/{skills/nitro/docs/examples/plugins.md → dist/docs/3.examples/15.plugins.md} +4 -4
  94. package/{skills/nitro/docs/examples/shiki.md → dist/docs/3.examples/19.shiki.md} +1 -1
  95. package/{skills/nitro/docs/examples/auto-imports.md → dist/docs/3.examples/2.auto-imports.md} +0 -1
  96. package/{skills/nitro/docs/examples/vite-nitro-plugin.md → dist/docs/3.examples/21.vite-nitro-plugin.md} +1 -1
  97. package/{skills/nitro/docs/examples/vite-rsc.md → dist/docs/3.examples/22.vite-rsc.md} +4 -4
  98. package/{skills/nitro/docs/examples/vite-ssr-html.md → dist/docs/3.examples/23.vite-ssr-html.md} +3 -3
  99. package/{skills/nitro/docs/examples/vite-ssr-preact.md → dist/docs/3.examples/24.vite-ssr-preact.md} +6 -6
  100. package/{skills/nitro/docs/examples/vite-ssr-react.md → dist/docs/3.examples/25.vite-ssr-react.md} +3 -3
  101. package/{skills/nitro/docs/examples/vite-ssr-solid.md → dist/docs/3.examples/26.vite-ssr-solid.md} +3 -3
  102. package/{skills/nitro/docs/examples/vite-ssr-tsr-react.md → dist/docs/3.examples/27.vite-ssr-tsr-react.md} +6 -6
  103. package/{skills/nitro/docs/examples/vite-ssr-tss-react.md → dist/docs/3.examples/28.vite-ssr-tss-react.md} +11 -11
  104. package/{skills/nitro/docs/examples/vite-ssr-vue-router.md → dist/docs/3.examples/29.vite-ssr-vue-router.md} +6 -5
  105. package/{skills/nitro/docs/examples/vite-trpc.md → dist/docs/3.examples/30.vite-trpc.md} +3 -3
  106. package/{skills/nitro/docs/examples/elysia.md → dist/docs/3.examples/6.elysia.md} +1 -1
  107. package/{skills/nitro/docs/examples/fastify.md → dist/docs/3.examples/8.fastify.md} +1 -1
  108. package/dist/docs/README.md +86 -0
  109. package/dist/node_modules/@speed-highlight/core/dist/index.js +4 -4
  110. package/dist/node_modules/@speed-highlight/core/dist/terminal.js +2 -2
  111. package/dist/node_modules/@speed-highlight/core/package.json +1 -1
  112. package/dist/node_modules/cookie-es/dist/index.mjs +299 -250
  113. package/dist/node_modules/cookie-es/package.json +26 -23
  114. package/dist/node_modules/defu/dist/defu.mjs +2 -2
  115. package/dist/node_modules/defu/package.json +33 -28
  116. package/dist/node_modules/rendu/dist/_chunks/libs/cookie-es.mjs +151 -0
  117. package/dist/node_modules/rendu/dist/index.mjs +5 -112
  118. package/dist/node_modules/rendu/package.json +25 -24
  119. package/dist/node_modules/youch/package.json +2 -2
  120. package/dist/presets/_nitro/runtime/nitro-dev.mjs +3 -1
  121. package/dist/presets/_nitro/runtime/service-worker.mjs +1 -1
  122. package/dist/presets/aws-lambda/runtime/_utils.mjs +6 -6
  123. package/dist/presets/azure/runtime/_utils.mjs +5 -5
  124. package/dist/presets/azure/runtime/azure-swa.mjs +5 -5
  125. package/dist/presets/bun/runtime/bun.mjs +5 -3
  126. package/dist/presets/cloudflare/runtime/_module-handler.mjs +1 -1
  127. package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +4 -4
  128. package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +3 -3
  129. package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +2 -2
  130. package/dist/presets/cloudflare/runtime/plugin.dev.mjs +10 -21
  131. package/dist/presets/deno/runtime/deno-deploy.mjs +4 -4
  132. package/dist/presets/deno/runtime/deno-server.mjs +5 -3
  133. package/dist/presets/edgeone/runtime/edgeone.mjs +10 -0
  134. package/dist/presets/netlify/runtime/netlify-edge.mjs +2 -2
  135. package/dist/presets/node/runtime/node-cluster.mjs +2 -2
  136. package/dist/presets/node/runtime/node-middleware.mjs +1 -1
  137. package/dist/presets/node/runtime/node-server.mjs +5 -3
  138. package/dist/presets/stormkit/runtime/stormkit.mjs +1 -1
  139. package/dist/presets/vercel/runtime/cron-handler.mjs +1 -1
  140. package/dist/presets/vercel/runtime/queue-handler.mjs +21 -0
  141. package/dist/presets/vercel/runtime/vercel.node.mjs +3 -3
  142. package/dist/presets/vercel/runtime/vercel.web.mjs +1 -1
  143. package/dist/presets/winterjs/runtime/winterjs.mjs +10 -10
  144. package/dist/runtime/internal/app.mjs +12 -11
  145. package/dist/runtime/internal/context.mjs +1 -9
  146. package/dist/runtime/internal/error/dev.mjs +10 -10
  147. package/dist/runtime/internal/route-rules.d.mts +3 -1
  148. package/dist/runtime/internal/route-rules.mjs +9 -7
  149. package/dist/runtime/internal/routes/dev-tasks.mjs +13 -12
  150. package/dist/runtime/internal/routes/openapi.mjs +2 -2
  151. package/dist/runtime/internal/routes/scalar.mjs +3 -3
  152. package/dist/runtime/internal/routes/swagger.mjs +7 -4
  153. package/dist/runtime/internal/runtime-config.mjs +2 -2
  154. package/dist/runtime/internal/task.mjs +5 -5
  155. package/dist/runtime/meta.d.mts +1 -0
  156. package/dist/runtime/meta.mjs +1 -0
  157. package/dist/runtime/nitro.mjs +3 -3
  158. package/dist/runtime/virtual/renderer-template.mjs +1 -1
  159. package/dist/runtime/virtual/tracing.d.mts +5 -0
  160. package/dist/runtime/virtual/tracing.mjs +1 -0
  161. package/dist/types/index.d.mts +155 -86
  162. package/dist/vite.d.mts +0 -5
  163. package/dist/vite.mjs +57 -28
  164. package/lib/tsconfig.json +3 -5
  165. package/package.json +56 -54
  166. package/skills/nitro/SKILL.md +0 -10
  167. package/skills/nitro/docs/TOC.md +0 -83
  168. package/skills/nitro/docs/_navigation.json +0 -679
  169. /package/{skills/nitro/docs/docs → dist/docs/0.docs/0.index}/index.md +0 -0
  170. /package/{skills/nitro/docs/docs/nightly.md → dist/docs/0.docs/16.nightly.md} +0 -0
  171. /package/{skills/nitro/docs/deploy/runtimes/node.md → dist/docs/1.deploy/1.runtimes/0.node.md} +0 -0
  172. /package/{skills/nitro/docs/deploy/runtimes/bun.md → dist/docs/1.deploy/1.runtimes/1.bun.md} +0 -0
  173. /package/{skills/nitro/docs/deploy/runtimes/deno.md → dist/docs/1.deploy/1.runtimes/2.deno.md} +0 -0
  174. /package/{skills/nitro/docs/deploy/providers/alwaysdata.md → dist/docs/1.deploy/2.providers/0.alwaysdata.md} +0 -0
  175. /package/{skills/nitro/docs/deploy/providers/flightcontrol.md → dist/docs/1.deploy/2.providers/10.flightcontrol.md} +0 -0
  176. /package/{skills/nitro/docs/deploy/providers/genezio.md → dist/docs/1.deploy/2.providers/11.genezio.md} +0 -0
  177. /package/{skills/nitro/docs/deploy/providers/github-pages.md → dist/docs/1.deploy/2.providers/12.github-pages.md} +0 -0
  178. /package/{skills/nitro/docs/deploy/providers/gitlab-pages.md → dist/docs/1.deploy/2.providers/13.gitlab-pages.md} +0 -0
  179. /package/{skills/nitro/docs/deploy/providers/heroku.md → dist/docs/1.deploy/2.providers/14.heroku.md} +0 -0
  180. /package/{skills/nitro/docs/deploy/providers/koyeb.md → dist/docs/1.deploy/2.providers/16.koyeb.md} +0 -0
  181. /package/{skills/nitro/docs/deploy/providers/netlify.md → dist/docs/1.deploy/2.providers/17.netlify.md} +0 -0
  182. /package/{skills/nitro/docs/deploy/providers/platform-sh.md → dist/docs/1.deploy/2.providers/18.platform-sh.md} +0 -0
  183. /package/{skills/nitro/docs/deploy/providers/render.md → dist/docs/1.deploy/2.providers/19.render.md} +0 -0
  184. /package/{skills/nitro/docs/deploy/providers/stormkit.md → dist/docs/1.deploy/2.providers/20.stormkit.md} +0 -0
  185. /package/{skills/nitro/docs/deploy/providers/zeabur.md → dist/docs/1.deploy/2.providers/22.zeabur.md} +0 -0
  186. /package/{skills/nitro/docs/deploy/providers/zerops.md → dist/docs/1.deploy/2.providers/24.zerops.md} +0 -0
  187. /package/{skills/nitro/docs/deploy/providers/azure.md → dist/docs/1.deploy/2.providers/3.azure.md} +0 -0
  188. /package/{skills/nitro/docs/deploy/providers/cleavr.md → dist/docs/1.deploy/2.providers/4.cleavr.md} +0 -0
  189. /package/{skills/nitro/docs/deploy/providers/deno-deploy.md → dist/docs/1.deploy/2.providers/6.deno-deploy.md} +0 -0
  190. /package/{skills/nitro/docs/deploy/providers/digitalocean.md → dist/docs/1.deploy/2.providers/7.digitalocean.md} +0 -0
  191. /package/{skills/nitro/docs/deploy/providers/firebase.md → dist/docs/1.deploy/2.providers/9.firebase.md} +0 -0
  192. /package/{skills/nitro/docs/examples → dist/docs/3.examples/0.index}/index.md +0 -0
  193. /package/{skills/nitro/docs/examples/api-routes.md → dist/docs/3.examples/1.api-routes.md} +0 -0
  194. /package/{skills/nitro/docs/examples/middleware.md → dist/docs/3.examples/12.middleware.md} +0 -0
  195. /package/{skills/nitro/docs/examples/nano-jsx.md → dist/docs/3.examples/14.nano-jsx.md} +0 -0
  196. /package/{skills/nitro/docs/examples/renderer.md → dist/docs/3.examples/16.renderer.md} +0 -0
  197. /package/{skills/nitro/docs/examples/runtime-config.md → dist/docs/3.examples/17.runtime-config.md} +0 -0
  198. /package/{skills/nitro/docs/examples/server-fetch.md → dist/docs/3.examples/18.server-fetch.md} +0 -0
  199. /package/{skills/nitro/docs/examples/virtual-routes.md → dist/docs/3.examples/20.virtual-routes.md} +0 -0
  200. /package/{skills/nitro/docs/examples/cached-handler.md → dist/docs/3.examples/3.cached-handler.md} +0 -0
  201. /package/{skills/nitro/docs/examples/websocket.md → dist/docs/3.examples/31.websocket.md} +0 -0
  202. /package/{skills/nitro/docs/examples/custom-error-handler.md → dist/docs/3.examples/4.custom-error-handler.md} +0 -0
  203. /package/{skills/nitro/docs/examples/database.md → dist/docs/3.examples/5.database.md} +0 -0
  204. /package/{skills/nitro/docs/examples/express.md → dist/docs/3.examples/7.express.md} +0 -0
  205. /package/{skills/nitro/docs/examples/hello-world.md → dist/docs/3.examples/9.hello-world.md} +0 -0
  206. /package/{skills/nitro → dist}/docs/index.md +0 -0
@@ -1,5 +1,4 @@
1
1
  import { parseArgs } from "node:util";
2
- //#region node_modules/.pnpm/citty@0.2.1/node_modules/citty/dist/_chunks/libs/scule.mjs
3
2
  const NUMBER_CHAR_RE = /\d/;
4
3
  const STR_SPLITTERS = [
5
4
  "-",
@@ -64,8 +63,9 @@ function camelCase(str, opts) {
64
63
  function kebabCase(str, joiner) {
65
64
  return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
66
65
  }
67
- //#endregion
68
- //#region node_modules/.pnpm/citty@0.2.1/node_modules/citty/dist/index.mjs
66
+ function snakeCase(str) {
67
+ return kebabCase(str || "", "_");
68
+ }
69
69
  function toArray(val) {
70
70
  if (Array.isArray(val)) return val;
71
71
  return val === void 0 ? [] : [val];
@@ -111,6 +111,12 @@ function parseRawArgs(args = [], opts = {}) {
111
111
  for (const alias of aliases) if (booleans.has(alias)) return "boolean";
112
112
  return "string";
113
113
  }
114
+ function isStringType(name) {
115
+ if (strings.has(name)) return true;
116
+ const aliases = mainToAliases.get(name) || [];
117
+ for (const alias of aliases) if (strings.has(alias)) return true;
118
+ return false;
119
+ }
114
120
  const allOptions = new Set([
115
121
  ...booleans,
116
122
  ...strings,
@@ -154,7 +160,12 @@ function parseRawArgs(args = [], opts = {}) {
154
160
  }
155
161
  const out = { _: [] };
156
162
  out._ = parsed.positionals;
157
- for (const [key, value] of Object.entries(parsed.values)) out[key] = value;
163
+ for (const [key, value] of Object.entries(parsed.values)) {
164
+ let coerced = value;
165
+ if (getType(key) === "boolean" && typeof value === "string") coerced = value !== "false";
166
+ else if (isStringType(key) && typeof value === "boolean") coerced = "";
167
+ out[key] = coerced;
168
+ }
158
169
  for (const [name] of Object.entries(negatedFlags)) {
159
170
  out[name] = false;
160
171
  const mainName = aliasToMain.get(name);
@@ -165,6 +176,7 @@ function parseRawArgs(args = [], opts = {}) {
165
176
  for (const [alias, main] of aliasToMain.entries()) {
166
177
  if (out[alias] !== void 0 && out[main] === void 0) out[main] = out[alias];
167
178
  if (out[main] !== void 0 && out[alias] === void 0) out[alias] = out[main];
179
+ if (out[alias] !== out[main] && defaults[main] === out[main]) out[main] = out[alias];
168
180
  }
169
181
  return out;
170
182
  }
@@ -226,6 +238,9 @@ function resolveArgs(argsDef) {
226
238
  });
227
239
  return args;
228
240
  }
241
+ async function resolvePlugins(plugins) {
242
+ return Promise.all(plugins.map((p) => resolveValue(p)));
243
+ }
229
244
  function defineCommand(def) {
230
245
  return def;
231
246
  }
@@ -238,35 +253,92 @@ async function runCommand(cmd, opts) {
238
253
  data: opts.data,
239
254
  cmd
240
255
  };
241
- if (typeof cmd.setup === "function") await cmd.setup(context);
256
+ const plugins = await resolvePlugins(cmd.plugins ?? []);
242
257
  let result;
258
+ let runError;
243
259
  try {
260
+ for (const plugin of plugins) await plugin.setup?.(context);
261
+ if (typeof cmd.setup === "function") await cmd.setup(context);
244
262
  const subCommands = await resolveValue(cmd.subCommands);
245
263
  if (subCommands && Object.keys(subCommands).length > 0) {
246
- const subCommandArgIndex = opts.rawArgs.findIndex((arg) => !arg.startsWith("-"));
247
- const subCommandName = opts.rawArgs[subCommandArgIndex];
248
- if (subCommandName) {
249
- if (!subCommands[subCommandName]) throw new CLIError(`Unknown command ${cyan(subCommandName)}`, "E_UNKNOWN_COMMAND");
250
- const subCommand = await resolveValue(subCommands[subCommandName]);
251
- if (subCommand) await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
252
- } else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
264
+ const subCommandArgIndex = findSubCommandIndex(opts.rawArgs, cmdArgs);
265
+ const explicitName = opts.rawArgs[subCommandArgIndex];
266
+ if (explicitName) {
267
+ const subCommand = await _findSubCommand(subCommands, explicitName);
268
+ if (!subCommand) throw new CLIError(`Unknown command ${cyan(explicitName)}`, "E_UNKNOWN_COMMAND");
269
+ await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
270
+ } else {
271
+ const defaultSubCommand = await resolveValue(cmd.default);
272
+ if (defaultSubCommand) {
273
+ if (cmd.run) throw new CLIError(`Cannot specify both 'run' and 'default' on the same command.`, "E_DEFAULT_CONFLICT");
274
+ const subCommand = await _findSubCommand(subCommands, defaultSubCommand);
275
+ if (!subCommand) throw new CLIError(`Default sub command ${cyan(defaultSubCommand)} not found in subCommands.`, "E_UNKNOWN_COMMAND");
276
+ await runCommand(subCommand, { rawArgs: opts.rawArgs });
277
+ } else if (!cmd.run) throw new CLIError(`No command specified.`, "E_NO_COMMAND");
278
+ }
253
279
  }
254
280
  if (typeof cmd.run === "function") result = await cmd.run(context);
255
- } finally {
256
- if (typeof cmd.cleanup === "function") await cmd.cleanup(context);
281
+ } catch (error) {
282
+ runError = error;
257
283
  }
284
+ const cleanupErrors = [];
285
+ if (typeof cmd.cleanup === "function") try {
286
+ await cmd.cleanup(context);
287
+ } catch (error) {
288
+ cleanupErrors.push(error);
289
+ }
290
+ for (const plugin of [...plugins].reverse()) try {
291
+ await plugin.cleanup?.(context);
292
+ } catch (error) {
293
+ cleanupErrors.push(error);
294
+ }
295
+ if (runError) throw runError;
296
+ if (cleanupErrors.length === 1) throw cleanupErrors[0];
297
+ if (cleanupErrors.length > 1) throw new Error("Multiple cleanup errors", { cause: cleanupErrors });
258
298
  return { result };
259
299
  }
260
300
  async function resolveSubCommand(cmd, rawArgs, parent) {
261
301
  const subCommands = await resolveValue(cmd.subCommands);
262
302
  if (subCommands && Object.keys(subCommands).length > 0) {
263
- const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
303
+ const subCommandArgIndex = findSubCommandIndex(rawArgs, await resolveValue(cmd.args || {}));
264
304
  const subCommandName = rawArgs[subCommandArgIndex];
265
- const subCommand = await resolveValue(subCommands[subCommandName]);
305
+ const subCommand = await _findSubCommand(subCommands, subCommandName);
266
306
  if (subCommand) return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
267
307
  }
268
308
  return [cmd, parent];
269
309
  }
310
+ async function _findSubCommand(subCommands, name) {
311
+ if (name in subCommands) return resolveValue(subCommands[name]);
312
+ for (const sub of Object.values(subCommands)) {
313
+ const resolved = await resolveValue(sub);
314
+ const meta = await resolveValue(resolved?.meta);
315
+ if (meta?.alias) {
316
+ if (toArray(meta.alias).includes(name)) return resolved;
317
+ }
318
+ }
319
+ }
320
+ function findSubCommandIndex(rawArgs, argsDef) {
321
+ for (let i = 0; i < rawArgs.length; i++) {
322
+ const arg = rawArgs[i];
323
+ if (arg === "--") return -1;
324
+ if (arg.startsWith("-")) {
325
+ if (!arg.includes("=") && _isValueFlag(arg, argsDef)) i++;
326
+ continue;
327
+ }
328
+ return i;
329
+ }
330
+ return -1;
331
+ }
332
+ function _isValueFlag(flag, argsDef) {
333
+ const name = flag.replace(/^-{1,2}/, "");
334
+ const normalized = camelCase(name);
335
+ for (const [key, def] of Object.entries(argsDef)) {
336
+ if (def.type !== "string" && def.type !== "enum") continue;
337
+ if (normalized === camelCase(key)) return true;
338
+ if ((Array.isArray(def.alias) ? def.alias : def.alias ? [def.alias] : []).includes(name)) return true;
339
+ }
340
+ return false;
341
+ }
270
342
  async function showUsage(cmd, parent) {
271
343
  try {
272
344
  console.log(await renderUsage(cmd, parent) + "\n");
@@ -287,22 +359,17 @@ async function renderUsage(cmd, parent) {
287
359
  for (const arg of cmdArgs) if (arg.type === "positional") {
288
360
  const name = arg.name.toUpperCase();
289
361
  const isRequired = arg.required !== false && arg.default === void 0;
290
- const defaultHint = arg.default ? `="${arg.default}"` : "";
291
- posLines.push([
292
- cyan(name + defaultHint),
293
- arg.description || "",
294
- arg.valueHint ? `<${arg.valueHint}>` : ""
295
- ]);
362
+ posLines.push([cyan(name + renderValueHint(arg)), renderDescription(arg, isRequired)]);
296
363
  usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
297
364
  } else {
298
365
  const isRequired = arg.required === true && arg.default === void 0;
299
- 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("|")}>` : "");
300
- argLines.push([cyan(argStr + (isRequired ? " (required)" : "")), arg.description || ""]);
366
+ const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + renderValueHint(arg);
367
+ argLines.push([cyan(argStr), renderDescription(arg, isRequired)]);
301
368
  if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
302
369
  const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
303
- argLines.push([cyan(negativeArgStr + (isRequired ? " (required)" : "")), arg.negativeDescription || ""]);
370
+ argLines.push([cyan(negativeArgStr), [arg.negativeDescription, isRequired ? gray("(Required)") : ""].filter(Boolean).join(" ")]);
304
371
  }
305
- if (isRequired) usageLine.push(argStr);
372
+ if (isRequired) usageLine.push(`--${arg.name}` + renderValueHint(arg));
306
373
  }
307
374
  if (cmd.subCommands) {
308
375
  const commandNames = [];
@@ -310,8 +377,10 @@ async function renderUsage(cmd, parent) {
310
377
  for (const [name, sub] of Object.entries(subCommands)) {
311
378
  const meta = await resolveValue((await resolveValue(sub))?.meta);
312
379
  if (meta?.hidden) continue;
313
- commandsLines.push([cyan(name), meta?.description || ""]);
314
- commandNames.push(name);
380
+ const aliases = toArray(meta?.alias);
381
+ const label = [name, ...aliases].join(", ");
382
+ commandsLines.push([cyan(label), meta?.description || ""]);
383
+ commandNames.push(name, ...aliases);
315
384
  }
316
385
  usageLine.push(commandNames.join("|"));
317
386
  }
@@ -337,14 +406,31 @@ async function renderUsage(cmd, parent) {
337
406
  }
338
407
  return usageLines.filter((l) => typeof l === "string").join("\n");
339
408
  }
409
+ function renderValueHint(arg) {
410
+ const valueHint = arg.valueHint ? `=<${arg.valueHint}>` : "";
411
+ const fallbackValueHint = valueHint || `=<${snakeCase(arg.name)}>`;
412
+ if (!arg.type || arg.type === "positional" || arg.type === "boolean") return valueHint;
413
+ if (arg.type === "enum" && arg.options?.length) return `=<${arg.options.join("|")}>`;
414
+ return fallbackValueHint;
415
+ }
416
+ function renderDescription(arg, required) {
417
+ const requiredHint = required ? gray("(Required)") : "";
418
+ const defaultHint = arg.default === void 0 ? "" : gray(`(Default: ${arg.default})`);
419
+ return [
420
+ arg.description,
421
+ requiredHint,
422
+ defaultHint
423
+ ].filter(Boolean).join(" ");
424
+ }
340
425
  async function runMain(cmd, opts = {}) {
341
426
  const rawArgs = opts.rawArgs || process.argv.slice(2);
342
427
  const showUsage$1 = opts.showUsage || showUsage;
343
428
  try {
344
- if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
429
+ const builtinFlags = await _resolveBuiltinFlags(cmd);
430
+ if (builtinFlags.help.length > 0 && rawArgs.some((arg) => builtinFlags.help.includes(arg))) {
345
431
  await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
346
432
  process.exit(0);
347
- } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
433
+ } else if (rawArgs.length === 1 && builtinFlags.version.includes(rawArgs[0])) {
348
434
  const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
349
435
  if (!meta?.version) throw new CLIError("No version specified", "E_NO_VERSION");
350
436
  console.log(meta.version);
@@ -357,5 +443,22 @@ async function runMain(cmd, opts = {}) {
357
443
  process.exit(1);
358
444
  }
359
445
  }
360
- //#endregion
446
+ async function _resolveBuiltinFlags(cmd) {
447
+ const argsDef = await resolveValue(cmd.args || {});
448
+ const userNames = /* @__PURE__ */ new Set();
449
+ const userAliases = /* @__PURE__ */ new Set();
450
+ for (const [name, def] of Object.entries(argsDef)) {
451
+ userNames.add(name);
452
+ for (const alias of toArray(def.alias)) userAliases.add(alias);
453
+ }
454
+ return {
455
+ help: _getBuiltinFlags("help", "h", userNames, userAliases),
456
+ version: _getBuiltinFlags("version", "v", userNames, userAliases)
457
+ };
458
+ }
459
+ function _getBuiltinFlags(long, short, userNames, userAliases) {
460
+ if (userNames.has(long) || userAliases.has(long)) return [];
461
+ if (userNames.has(short) || userAliases.has(short)) return [`--${long}`];
462
+ return [`--${long}`, `-${short}`];
463
+ }
361
464
  export { runMain as n, defineCommand as t };
@@ -2,8 +2,7 @@ import { i as __toESM, r as __require, t as __commonJSMin } from "../_common.mjs
2
2
  import { P as Builder, S as MagicString, c as walk, i as createFilter, o as extractAssignedNames, r as attachScopes, s as makeLegalIdentifier } from "../_build/common.mjs";
3
3
  import { existsSync, readFileSync, statSync } from "fs";
4
4
  import { basename, dirname, extname, join, relative, resolve, sep } from "path";
5
- //#region node_modules/.pnpm/commondir@1.0.1/node_modules/commondir/index.js
6
- var require_commondir = /* @__PURE__ */ __commonJSMin(((exports, module) => {
5
+ var import_commondir = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
7
6
  var path$1 = __require("path");
8
7
  module.exports = function(basedir, relfiles) {
9
8
  if (relfiles) var files = relfiles.map(function(r) {
@@ -18,9 +17,7 @@ var require_commondir = /* @__PURE__ */ __commonJSMin(((exports, module) => {
18
17
  }, files[0].split(/\/+|\\+/));
19
18
  return res.length > 1 ? res.join("/") : "/";
20
19
  };
21
- }));
22
- //#endregion
23
- //#region node_modules/.pnpm/is-reference@1.2.1/node_modules/is-reference/dist/is-reference.es.js
20
+ })))(), 1);
24
21
  function isReference(node, parent) {
25
22
  if (node.type === "MemberExpression") return !node.computed && isReference(node.object, node);
26
23
  if (node.type === "Identifier") {
@@ -40,9 +37,6 @@ function isReference(node, parent) {
40
37
  }
41
38
  return false;
42
39
  }
43
- //#endregion
44
- //#region node_modules/.pnpm/@rollup+plugin-commonjs@29.0.2_rollup@4.59.0/node_modules/@rollup/plugin-commonjs/dist/es/index.js
45
- var import_commondir = /* @__PURE__ */ __toESM(require_commondir(), 1);
46
40
  var version = "29.0.1";
47
41
  var peerDependencies = { rollup: "^2.68.0||^3.0.0||^4.0.0" };
48
42
  function tryParse(parse, code, id) {
@@ -1307,5 +1301,4 @@ function commonjs(options = {}) {
1307
1301
  }
1308
1302
  };
1309
1303
  }
1310
- //#endregion
1311
1304
  export { commonjs as t };
@@ -1,4 +1,3 @@
1
- //#region node_modules/.pnpm/compatx@0.2.0/node_modules/compatx/dist/index.d.mts
2
1
  /**
3
2
  * Known platform names
4
3
  */
@@ -43,5 +42,4 @@ type CompatibilityDateSpec = DateString | Partial<CompatibilityDates>;
43
42
  /**
44
43
  * Get compatibility updates applicable for the user given platform and date range.
45
44
  */
46
- //#endregion
47
45
  export { CompatibilityDates as n, DateString as r, CompatibilityDateSpec as t };
@@ -1,4 +1,3 @@
1
- //#region node_modules/.pnpm/compatx@0.2.0/node_modules/compatx/dist/index.mjs
2
1
  const platforms = [
3
2
  "aws",
4
3
  "azure",
@@ -41,5 +40,4 @@ function normalizeDate(date) {
41
40
  if (date === "latest") return /* @__PURE__ */ new Date();
42
41
  return new Date(date);
43
42
  }
44
- //#endregion
45
43
  export { resolveCompatibilityDates as n, resolveCompatibilityDatesFromEnv as r, formatCompatibilityDate as t };
@@ -1,4 +1,3 @@
1
- //#region node_modules/.pnpm/esbuild@0.27.3/node_modules/esbuild/lib/main.d.ts
2
1
  // Note: These declarations exist to avoid type errors when you omit "dom" from
3
2
  // "lib" in your "tsconfig.json" file. TypeScript confusingly declares the
4
3
  // global "WebAssembly" type in "lib.dom.d.ts" even though it has nothing to do
@@ -1,7 +1,5 @@
1
- //#region node_modules/.pnpm/escape-string-regexp@5.0.0/node_modules/escape-string-regexp/index.js
2
1
  function escapeStringRegexp(string) {
3
2
  if (typeof string !== "string") throw new TypeError("Expected a string");
4
3
  return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
5
4
  }
6
- //#endregion
7
5
  export { escapeStringRegexp as t };
@@ -1,12 +1,8 @@
1
1
  import { Plugin } from "rollup";
2
-
3
- //#region node_modules/.pnpm/@rollup+pluginutils@5.3.0_rollup@4.59.0/node_modules/@rollup/pluginutils/types/index.d.ts
4
2
  /**
5
3
  * A valid `picomatch` glob pattern, or array of patterns.
6
4
  */
7
5
  type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
8
- //#endregion
9
- //#region node_modules/.pnpm/@rollup+plugin-commonjs@29.0.2_rollup@4.59.0/node_modules/@rollup/plugin-commonjs/types/index.d.ts
10
6
  type RequireReturnsDefaultOption = boolean | 'auto' | 'preferred' | 'namespace';
11
7
  type DefaultIsModuleExportsOption = boolean | 'auto';
12
8
  interface RollupCommonJSOptions {
@@ -237,5 +233,4 @@ interface RollupCommonJSOptions {
237
233
  * Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
238
234
  */
239
235
  declare function commonjs(options?: RollupCommonJSOptions): Plugin;
240
- //#endregion
241
236
  export { commonjs as t };
@@ -1,98 +1,37 @@
1
- //#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
2
- /**
3
- * @typedef { import('estree').Node} Node
4
- * @typedef {{
5
- * skip: () => void;
6
- * remove: () => void;
7
- * replace: (node: Node) => void;
8
- * }} WalkerContext
9
- */
10
1
  var WalkerBase = class {
11
2
  constructor() {
12
- /** @type {boolean} */
13
3
  this.should_skip = false;
14
- /** @type {boolean} */
15
4
  this.should_remove = false;
16
- /** @type {Node | null} */
17
5
  this.replacement = null;
18
- /** @type {WalkerContext} */
19
6
  this.context = {
20
7
  skip: () => this.should_skip = true,
21
8
  remove: () => this.should_remove = true,
22
9
  replace: (node) => this.replacement = node
23
10
  };
24
11
  }
25
- /**
26
- * @template {Node} Parent
27
- * @param {Parent | null | undefined} parent
28
- * @param {keyof Parent | null | undefined} prop
29
- * @param {number | null | undefined} index
30
- * @param {Node} node
31
- */
32
12
  replace(parent, prop, index, node) {
33
- if (parent && prop) if (index != null)
34
- /** @type {Array<Node>} */ parent[prop][index] = node;
35
- else
36
- /** @type {Node} */ parent[prop] = node;
13
+ if (parent && prop) if (index != null) parent[prop][index] = node;
14
+ else parent[prop] = node;
37
15
  }
38
- /**
39
- * @template {Node} Parent
40
- * @param {Parent | null | undefined} parent
41
- * @param {keyof Parent | null | undefined} prop
42
- * @param {number | null | undefined} index
43
- */
44
16
  remove(parent, prop, index) {
45
- if (parent && prop) if (index !== null && index !== void 0)
46
- /** @type {Array<Node>} */ parent[prop].splice(index, 1);
17
+ if (parent && prop) if (index !== null && index !== void 0) parent[prop].splice(index, 1);
47
18
  else delete parent[prop];
48
19
  }
49
20
  };
50
- //#endregion
51
- //#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
52
- /**
53
- * @typedef { import('estree').Node} Node
54
- * @typedef { import('./walker.js').WalkerContext} WalkerContext
55
- * @typedef {(
56
- * this: WalkerContext,
57
- * node: Node,
58
- * parent: Node | null,
59
- * key: string | number | symbol | null | undefined,
60
- * index: number | null | undefined
61
- * ) => void} SyncHandler
62
- */
63
21
  var SyncWalker = class extends WalkerBase {
64
- /**
65
- *
66
- * @param {SyncHandler} [enter]
67
- * @param {SyncHandler} [leave]
68
- */
69
22
  constructor(enter, leave) {
70
23
  super();
71
- /** @type {boolean} */
72
24
  this.should_skip = false;
73
- /** @type {boolean} */
74
25
  this.should_remove = false;
75
- /** @type {Node | null} */
76
26
  this.replacement = null;
77
- /** @type {WalkerContext} */
78
27
  this.context = {
79
28
  skip: () => this.should_skip = true,
80
29
  remove: () => this.should_remove = true,
81
30
  replace: (node) => this.replacement = node
82
31
  };
83
- /** @type {SyncHandler | undefined} */
84
32
  this.enter = enter;
85
- /** @type {SyncHandler | undefined} */
86
33
  this.leave = leave;
87
34
  }
88
- /**
89
- * @template {Node} Parent
90
- * @param {Node} node
91
- * @param {Parent | null} parent
92
- * @param {keyof Parent} [prop]
93
- * @param {number | null} [index]
94
- * @returns {Node | null}
95
- */
96
35
  visit(node, parent, prop, index) {
97
36
  if (node) {
98
37
  if (this.enter) {
@@ -116,10 +55,8 @@ var SyncWalker = class extends WalkerBase {
116
55
  if (skipped) return node;
117
56
  if (removed) return null;
118
57
  }
119
- /** @type {keyof Node} */
120
58
  let key;
121
59
  for (key in node) {
122
- /** @type {unknown} */
123
60
  const value = node[key];
124
61
  if (value && typeof value === "object") {
125
62
  if (Array.isArray(value)) {
@@ -153,32 +90,10 @@ var SyncWalker = class extends WalkerBase {
153
90
  return node;
154
91
  }
155
92
  };
156
- /**
157
- * Ducktype a node.
158
- *
159
- * @param {unknown} value
160
- * @returns {value is Node}
161
- */
162
93
  function isNode(value) {
163
94
  return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
164
95
  }
165
- //#endregion
166
- //#region node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
167
- /**
168
- * @typedef {import('estree').Node} Node
169
- * @typedef {import('./sync.js').SyncHandler} SyncHandler
170
- * @typedef {import('./async.js').AsyncHandler} AsyncHandler
171
- */
172
- /**
173
- * @param {Node} ast
174
- * @param {{
175
- * enter?: SyncHandler
176
- * leave?: SyncHandler
177
- * }} walker
178
- * @returns {Node | null}
179
- */
180
96
  function walk(ast, { enter, leave }) {
181
97
  return new SyncWalker(enter, leave).visit(ast, null);
182
98
  }
183
- //#endregion
184
99
  export { walk as t };