nitro-nightly 3.0.1-alpha.1 → 3.0.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/_build/common.mjs +24924 -52
- package/dist/_build/rolldown.mjs +29 -63
- package/dist/_build/rollup.mjs +22 -110
- package/dist/_build/vite.build.mjs +3 -43
- package/dist/{_dev.mjs → _chunks/dev.mjs} +45 -43
- package/dist/_chunks/{B-D1JOIz.mjs → nitro.mjs} +144 -308
- package/dist/_chunks/nitro2.mjs +101 -0
- package/dist/_chunks/utils.mjs +254 -0
- package/dist/{_chunks/Bqks5huO.mjs → _common.mjs} +24 -10
- package/dist/_libs/c12+giget+readdirp+chokidar.d.mts +214 -0
- package/dist/_libs/citty.mjs +140 -110
- package/dist/_libs/{plugin-commonjs.mjs → commondir+is-reference.mjs} +59 -250
- package/dist/_libs/compatx.d.mts +47 -0
- package/dist/_libs/confbox.mjs +388 -799
- package/dist/_libs/esbuild.d.mts +20 -0
- package/dist/_libs/estree-walker.mjs +1 -144
- package/dist/_libs/{plugin-node-resolve.mjs → hasown+resolve+deepmerge.mjs} +497 -78
- package/dist/_libs/httpxy.d.mts +79 -0
- package/dist/_libs/httpxy.mjs +6 -1
- package/dist/_libs/magic-string.d.mts +220 -0
- package/dist/_libs/mlly.d.mts +57 -0
- package/dist/_libs/nypm+giget+tinyexec.mjs +3603 -0
- package/dist/_libs/pkg-types.d.mts +23 -0
- package/dist/_libs/plugin-alias.mjs +4 -2
- package/dist/_libs/plugin-inject.mjs +5 -5
- package/dist/_libs/plugin-json.mjs +2 -2
- package/dist/_libs/pluginutils+plugin-commonjs.d.mts +241 -0
- package/dist/_libs/{vite-plugin-fullstack.mjs → pluginutils.mjs} +244 -153
- package/dist/_libs/rc9+c12+dotenv.mjs +972 -0
- package/dist/_libs/{chokidar.mjs → readdirp+chokidar.mjs} +237 -187
- package/dist/_libs/remapping.mjs +1 -1
- package/dist/_libs/{gen-mapping.mjs → resolve-uri+gen-mapping.mjs} +2 -166
- package/dist/_libs/rou3.d.mts +43 -0
- package/dist/_libs/rou3.mjs +9 -6
- package/dist/_libs/std-env.d.mts +4 -0
- package/dist/_libs/tsconfck.mjs +3 -3
- package/dist/_libs/{unimport.mjs → unimport+unplugin.mjs} +226 -1961
- package/dist/_libs/unplugin+unimport.d.mts +426 -0
- package/dist/_libs/unwasm.d.mts +29 -0
- package/dist/_presets.mjs +130 -80
- package/dist/builder.d.mts +4 -4
- package/dist/builder.mjs +6 -30
- package/dist/cli/_chunks/build.mjs +1 -1
- package/dist/cli/_chunks/dev.mjs +5 -11
- package/dist/cli/_chunks/list.mjs +1 -1
- package/dist/cli/_chunks/prepare.mjs +1 -1
- package/dist/cli/_chunks/run.mjs +1 -1
- package/dist/node_modules/@poppinss/colors/build/index.js +130 -160
- package/dist/node_modules/@poppinss/colors/package.json +20 -18
- package/dist/node_modules/@poppinss/exception/build/index.js +36 -55
- package/dist/node_modules/@poppinss/exception/package.json +19 -16
- package/dist/node_modules/@sindresorhus/is/distribution/index.js +46 -5
- package/dist/node_modules/@sindresorhus/is/package.json +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/index.js +1 -1
- package/dist/node_modules/@speed-highlight/core/dist/terminal.js +1 -1
- package/dist/node_modules/@speed-highlight/core/package.json +2 -2
- package/dist/node_modules/hookable/dist/index.mjs +5 -6
- package/dist/node_modules/hookable/package.json +13 -13
- package/dist/node_modules/ufo/dist/index.mjs +16 -9
- package/dist/node_modules/ufo/package.json +15 -14
- package/dist/node_modules/unctx/package.json +16 -16
- package/dist/node_modules/youch/build/{chunk-4XB2BYKC.js → chunk-7QV3D5YX.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-PUHGL6HA.js → chunk-AUGPHE32.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-F4I6KX4R.js → chunk-CM7DWJNZ.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-YYEJ3AGB.js → chunk-EJH674NB.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-EUJBVOYB.js → chunk-OIJ3WD7L.js} +2 -4
- package/dist/node_modules/youch/build/{chunk-HFSXRSKS.js → chunk-P36L72PL.js} +5 -3
- package/dist/node_modules/youch/build/{chunk-4YEN7HVQ.js → chunk-PE3GG3TN.js} +5 -1
- package/dist/node_modules/youch/build/{chunk-PINJDICN.js → chunk-X53OIOJH.js} +2 -4
- package/dist/node_modules/youch/build/index.js +8 -9
- package/dist/node_modules/youch/build/public/error_info/style.css +1 -0
- package/dist/node_modules/youch/build/public/error_metadata/style.css +3 -0
- package/dist/node_modules/youch/build/public/error_stack/style.css +2 -3
- package/dist/node_modules/youch/package.json +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +5 -6
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +1 -1
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +1 -1
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -1
- package/dist/presets/_nitro/runtime/service-worker.mjs +2 -2
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -1
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +1 -1
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +0 -5
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +9 -11
- package/dist/presets/aws-lambda/runtime/aws-lambda.d.mts +1 -1
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +1 -1
- package/dist/presets/azure/runtime/azure-swa.d.mts +1 -1
- package/dist/presets/azure/runtime/azure-swa.mjs +1 -1
- package/dist/presets/bun/runtime/bun.d.mts +1 -1
- package/dist/presets/bun/runtime/bun.mjs +7 -8
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +3 -3
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +19 -17
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +17 -16
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +8 -9
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +1 -1
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +12 -18
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-deploy.mjs +4 -5
- package/dist/presets/deno/runtime/deno-server.d.mts +1 -1
- package/dist/presets/deno/runtime/deno-server.mjs +5 -6
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +1 -2
- package/dist/presets/netlify/runtime/netlify-edge.mjs +3 -2
- package/dist/presets/netlify/runtime/netlify.d.mts +3 -2
- package/dist/presets/netlify/runtime/netlify.mjs +3 -1
- package/dist/presets/node/runtime/node-cluster.d.mts +1 -1
- package/dist/presets/node/runtime/node-cluster.mjs +5 -6
- package/dist/presets/node/runtime/node-middleware.d.mts +1 -1
- package/dist/presets/node/runtime/node-middleware.mjs +4 -5
- package/dist/presets/node/runtime/node-server.d.mts +1 -1
- package/dist/presets/node/runtime/node-server.mjs +5 -6
- package/dist/presets/standard/runtime/server.d.mts +1 -1
- package/dist/presets/standard/runtime/server.mjs +1 -1
- package/dist/presets/stormkit/runtime/stormkit.d.mts +1 -1
- package/dist/presets/stormkit/runtime/stormkit.mjs +1 -1
- package/dist/presets/vercel/runtime/isr.d.mts +2 -0
- package/dist/presets/vercel/runtime/isr.mjs +19 -0
- package/dist/presets/vercel/runtime/vercel.node.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.node.mjs +16 -7
- package/dist/presets/vercel/runtime/vercel.web.d.mts +1 -1
- package/dist/presets/vercel/runtime/vercel.web.mjs +18 -13
- package/dist/presets/winterjs/runtime/winterjs.d.mts +1 -2
- package/dist/presets/winterjs/runtime/winterjs.mjs +1 -1
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/presets/zeabur/runtime/zeabur.mjs +1 -1
- package/dist/runtime/app.d.mts +1 -1
- package/dist/runtime/app.mjs +1 -1
- package/dist/runtime/internal/app.d.mts +7 -3
- package/dist/runtime/internal/app.mjs +29 -22
- package/dist/runtime/internal/database.mjs +1 -1
- package/dist/runtime/internal/error/dev.d.mts +0 -1
- package/dist/runtime/internal/error/dev.mjs +1 -1
- package/dist/runtime/internal/route-rules.d.mts +0 -4
- package/dist/runtime/internal/routes/dev-tasks.mjs +1 -1
- package/dist/runtime/internal/routes/openapi.d.mts +0 -1
- package/dist/runtime/internal/routes/openapi.mjs +3 -3
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +1 -1
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +0 -1
- package/dist/runtime/internal/routes/scalar.mjs +4 -4
- package/dist/runtime/internal/routes/swagger.d.mts +0 -1
- package/dist/runtime/internal/routes/swagger.mjs +3 -3
- package/dist/runtime/internal/runtime-config.mjs +8 -8
- package/dist/runtime/internal/static.mjs +1 -1
- package/dist/runtime/internal/storage.mjs +1 -1
- package/dist/runtime/internal/task.mjs +1 -1
- package/dist/runtime/internal/vite/dev-entry.mjs +3 -4
- package/dist/runtime/internal/vite/{dev-worker.mjs → node-runner.mjs} +51 -6
- package/dist/runtime/meta.d.mts +1 -1
- package/dist/runtime/meta.mjs +1 -1
- package/dist/runtime/nitro.d.mts +0 -3
- package/dist/runtime/nitro.mjs +1 -1
- package/dist/runtime/virtual/_runtime_warn.d.mts +1 -0
- package/dist/runtime/virtual/_runtime_warn.mjs +5 -0
- package/dist/runtime/virtual/database.d.mts +8 -0
- package/dist/runtime/virtual/database.mjs +2 -0
- package/dist/runtime/virtual/error-handler.d.mts +6 -0
- package/dist/runtime/virtual/error-handler.mjs +9 -0
- package/dist/runtime/virtual/feature-flags.d.mts +7 -0
- package/dist/runtime/virtual/feature-flags.mjs +7 -0
- package/dist/runtime/virtual/plugins.d.mts +3 -0
- package/dist/runtime/virtual/plugins.mjs +2 -0
- package/dist/runtime/virtual/polyfills.d.mts +3 -0
- package/dist/runtime/virtual/polyfills.mjs +2 -0
- package/dist/runtime/virtual/public-assets.d.mts +9 -0
- package/dist/runtime/virtual/public-assets.mjs +8 -0
- package/dist/runtime/virtual/renderer-template.d.mts +4 -0
- package/dist/runtime/virtual/renderer-template.mjs +7 -0
- package/dist/runtime/virtual/routing-meta.d.mts +7 -0
- package/dist/runtime/virtual/routing-meta.mjs +2 -0
- package/dist/runtime/virtual/routing.d.mts +8 -0
- package/dist/runtime/virtual/routing.mjs +11 -0
- package/dist/runtime/virtual/runtime-config.d.mts +3 -0
- package/dist/runtime/virtual/runtime-config.mjs +5 -0
- package/dist/runtime/virtual/server-assets.d.mts +6 -0
- package/dist/runtime/virtual/server-assets.mjs +12 -0
- package/dist/runtime/virtual/storage.d.mts +3 -0
- package/dist/runtime/virtual/storage.mjs +5 -0
- package/dist/runtime/virtual/tasks.d.mts +10 -0
- package/dist/runtime/virtual/tasks.mjs +3 -0
- package/dist/types/index.d.mts +292 -371
- package/dist/types/index.mjs +10 -0
- package/dist/vite.d.mts +7 -12
- package/dist/vite.mjs +734 -41
- package/lib/vite.types.d.mts +26 -0
- package/lib/vite.types.mjs +2 -0
- package/package.json +82 -53
- package/dist/_build/common2.mjs +0 -772
- package/dist/_build/vite.plugin.mjs +0 -768
- package/dist/_chunks/ANM1K1bE.mjs +0 -304
- package/dist/_chunks/BX9-zVkM.mjs +0 -59
- package/dist/_chunks/C7CbzoI1.mjs +0 -39
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/c12.mjs +0 -2858
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/giget.mjs +0 -19289
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -32
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -1686
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/node-fetch-native.mjs +0 -173
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -41
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/plugin-replace.mjs +0 -104
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5836
- package/dist/cli/_chunks/detect-acorn.mjs +0 -12
- package/dist/cli/_chunks/dist.mjs +0 -3
- package/dist/cli/_chunks/dist2.mjs +0 -3
- package/dist/cli/_chunks/dist3.mjs +0 -3
- package/dist/cli/_chunks/dist4.mjs +0 -4
- package/dist/cli/_chunks/dist5.mjs +0 -4
- package/dist/cli/_chunks/esm.mjs +0 -3
- package/dist/cli/_chunks/json5.mjs +0 -4
- package/dist/cli/_chunks/jsonc.mjs +0 -4
- package/dist/cli/_chunks/multipart-parser.mjs +0 -6
- package/dist/cli/_chunks/toml.mjs +0 -4
- package/dist/cli/_chunks/yaml.mjs +0 -4
- package/dist/node_modules/kleur/index.js +0 -110
- package/dist/node_modules/youch/build/chunk-OSUFJZHZ.js +0 -6
- package/lib/deps/ofetch.mjs +0 -1
- package/lib/deps/ofetch.mts +0 -1
- /package/dist/runtime/{vite-runtime.d.mts → vite.d.mts} +0 -0
- /package/dist/runtime/{vite-runtime.mjs → vite.mjs} +0 -0
- /package/lib/{deps/h3.d.mts → h3.d.mts} +0 -0
- /package/lib/{deps/h3.mjs → h3.mjs} +0 -0
package/dist/_libs/citty.mjs
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { colors } from "consola/utils";
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
3
2
|
|
|
4
|
-
//#region node_modules/.pnpm/citty@0.
|
|
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
|
-
|
|
89
|
-
|
|
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
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
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
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
133
|
+
processedArgs.push(...args.slice(i));
|
|
139
134
|
break;
|
|
140
135
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
268
|
+
console.log(await renderUsage(cmd, parent) + "\n");
|
|
250
269
|
} catch (error) {
|
|
251
|
-
|
|
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
|
-
|
|
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 =
|
|
276
|
-
argLines.push([
|
|
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
|
-
|
|
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(
|
|
321
|
+
usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
|
|
292
322
|
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
293
|
-
usageLines.push(`${
|
|
323
|
+
usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
|
|
294
324
|
if (posLines.length > 0) {
|
|
295
|
-
usageLines.push(
|
|
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(
|
|
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(
|
|
335
|
+
usageLines.push(underline(bold("COMMANDS")), "");
|
|
306
336
|
usageLines.push(formatLineColumns(commandsLines, " "));
|
|
307
|
-
usageLines.push("", `Use
|
|
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
|
-
|
|
351
|
+
console.log(meta.version);
|
|
322
352
|
} else await runCommand(cmd, { rawArgs });
|
|
323
353
|
} catch (error) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
}
|