giget 3.1.0 → 3.1.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.
@@ -1 +1,48 @@
1
- import fs from"node:fs";import path from"node:path";const lchownSync=(t,n,r)=>{try{return fs.lchownSync(t,n,r)}catch(e){if(e?.code!==`ENOENT`)throw e}},chown=(t,n,r,i)=>{fs.lchown(t,n,r,e=>{i(e&&e?.code!==`ENOENT`?e:null)})},chownrKid=(e,n,i,o,s)=>{n.isDirectory()?chownr(path.resolve(e,n.name),i,o,a=>{if(a)return s(a);chown(path.resolve(e,n.name),i,o,s)}):chown(path.resolve(e,n.name),i,o,s)},chownr=(t,n,a,o)=>{fs.readdir(t,{withFileTypes:!0},(e,s)=>{if(e){if(e.code===`ENOENT`)return o();if(e.code!==`ENOTDIR`&&e.code!==`ENOTSUP`)return o(e)}if(e||!s.length)return chown(t,n,a,o);let c=s.length,l=null,u=e=>{if(!l){if(e)return o(l=e);if(--c===0)return chown(t,n,a,o)}};for(let e of s)chownrKid(t,e,n,a,u)})},chownrKidSync=(e,r,i,a)=>{r.isDirectory()&&chownrSync(path.resolve(e,r.name),i,a),lchownSync(path.resolve(e,r.name),i,a)},chownrSync=(t,r,i)=>{let a;try{a=fs.readdirSync(t,{withFileTypes:!0})}catch(e){let a=e;if(a?.code===`ENOENT`)return;if(a?.code===`ENOTDIR`||a?.code===`ENOTSUP`)return lchownSync(t,r,i);throw a}for(let e of a)chownrKidSync(t,e,r,i);return lchownSync(t,r,i)};export{chownrSync as n,chownr as t};
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ const lchownSync = (t, n, r) => {
4
+ try {
5
+ return fs.lchownSync(t, n, r);
6
+ } catch (e) {
7
+ if (e?.code !== `ENOENT`) throw e;
8
+ }
9
+ }, chown = (t, n, r, i) => {
10
+ fs.lchown(t, n, r, (e) => {
11
+ i(e && e?.code !== `ENOENT` ? e : null);
12
+ });
13
+ }, chownrKid = (e, n, i, o, s) => {
14
+ n.isDirectory() ? chownr(path.resolve(e, n.name), i, o, (a) => {
15
+ if (a) return s(a);
16
+ chown(path.resolve(e, n.name), i, o, s);
17
+ }) : chown(path.resolve(e, n.name), i, o, s);
18
+ }, chownr = (t, n, a, o) => {
19
+ fs.readdir(t, { withFileTypes: !0 }, (e, s) => {
20
+ if (e) {
21
+ if (e.code === `ENOENT`) return o();
22
+ if (e.code !== `ENOTDIR` && e.code !== `ENOTSUP`) return o(e);
23
+ }
24
+ if (e || !s.length) return chown(t, n, a, o);
25
+ let c = s.length, l = null, u = (e) => {
26
+ if (!l) {
27
+ if (e) return o(l = e);
28
+ if (--c === 0) return chown(t, n, a, o);
29
+ }
30
+ };
31
+ for (let e of s) chownrKid(t, e, n, a, u);
32
+ });
33
+ }, chownrKidSync = (e, r, i, a) => {
34
+ r.isDirectory() && chownrSync(path.resolve(e, r.name), i, a), lchownSync(path.resolve(e, r.name), i, a);
35
+ }, chownrSync = (t, r, i) => {
36
+ let a;
37
+ try {
38
+ a = fs.readdirSync(t, { withFileTypes: !0 });
39
+ } catch (e) {
40
+ let a = e;
41
+ if (a?.code === `ENOENT`) return;
42
+ if (a?.code === `ENOTDIR` || a?.code === `ENOTSUP`) return lchownSync(t, r, i);
43
+ throw a;
44
+ }
45
+ for (let e of a) chownrKidSync(t, e, r, i);
46
+ return lchownSync(t, r, i);
47
+ };
48
+ export { chownrSync as n, chownr as t };
@@ -1,5 +1,263 @@
1
- import{parseArgs}from"node:util";const NUMBER_CHAR_RE=/\d/,STR_SPLITTERS=[`-`,`_`,`/`,`.`];function isUppercase(e=``){if(!NUMBER_CHAR_RE.test(e))return e!==e.toLowerCase()}function splitByCase(e,h){let v=h??STR_SPLITTERS,y=[];if(!e||typeof e!=`string`)return y;let b=``,x,S;for(let h of e){let e=v.includes(h);if(e===!0){y.push(b),b=``,x=void 0;continue}let g=isUppercase(h);if(S===!1){if(x===!1&&g===!0){y.push(b),b=h,x=g;continue}if(x===!0&&g===!1&&b.length>1){let e=b.at(-1);y.push(b.slice(0,Math.max(0,b.length-1))),b=e+h,x=g;continue}}b+=h,x=g,S=e}return y.push(b),y}function upperFirst(e){return e?e[0].toUpperCase()+e.slice(1):``}function lowerFirst(e){return e?e[0].toLowerCase()+e.slice(1):``}function pascalCase(e,h){return e?(Array.isArray(e)?e:splitByCase(e)).map(e=>upperFirst(h?.normalize?e.toLowerCase():e)).join(``):``}function camelCase(e,h){return lowerFirst(pascalCase(e||``,h))}function kebabCase(e,h){return e?(Array.isArray(e)?e:splitByCase(e)).map(e=>e.toLowerCase()).join(h??`-`):``}function toArray(e){return Array.isArray(e)?e:e===void 0?[]:[e]}function formatLineColumns(e,h=``){let g=[];for(let h of e)for(let[e,_]of h.entries())g[e]=Math.max(g[e]||0,_.length);return e.map(e=>e.map((e,_)=>h+e[_===0?`padStart`:`padEnd`](g[_])).join(` `)).join(`
2
- `)}function resolveValue(e){return typeof e==`function`?e():e}var CLIError=class extends Error{code;constructor(e,h){super(e),this.name=`CLIError`,this.code=h}};function parseRawArgs(h=[],g={}){let _=new Set(g.boolean||[]),v=new Set(g.string||[]),y=g.alias||{},b=g.default||{},x=new Map,S=new Map;for(let[e,h]of Object.entries(y)){let g=h;for(let h of g)x.set(e,h),S.has(h)||S.set(h,[]),S.get(h).push(e),x.set(h,e),S.has(e)||S.set(e,[]),S.get(e).push(h)}let C={};function w(e){if(_.has(e))return`boolean`;let h=S.get(e)||[];for(let e of h)if(_.has(e))return`boolean`;return`string`}let T=new Set([..._,...v,...Object.keys(y),...Object.values(y).flat(),...Object.keys(b)]);for(let e of T)C[e]||(C[e]={type:w(e),default:b[e]});for(let[e,h]of x.entries())e.length===1&&C[h]&&!C[h].short&&(C[h].short=e);let E=[],D={};for(let e=0;e<h.length;e++){let g=h[e];if(g===`--`){E.push(...h.slice(e));break}if(g.startsWith(`--no-`)){let e=g.slice(5);D[e]=!0;continue}E.push(g)}let O;try{O=parseArgs({args:E,options:Object.keys(C).length>0?C:void 0,allowPositionals:!0,strict:!1})}catch{O={values:{},positionals:E}}let k={_:[]};k._=O.positionals;for(let[e,h]of Object.entries(O.values))k[e]=h;for(let[e]of Object.entries(D))k[e]=!1;for(let[e,h]of x.entries())k[e]!==void 0&&k[h]===void 0&&(k[h]=k[e]),k[h]!==void 0&&k[e]===void 0&&(k[e]=k[h]);return k}const noColor=(()=>{let e=globalThis.process?.env??{};return e.NO_COLOR===`1`||e.TERM===`dumb`||e.TEST||e.CI})(),_c=(e,h=39)=>g=>noColor?g:`\u001B[${e}m${g}\u001B[${h}m`,bold=_c(1,22),cyan=_c(36),gray=_c(90),underline=_c(4,24);function parseArgs$1(e,h){let g={boolean:[],string:[],alias:{},default:{}},_=resolveArgs(h);for(let e of _){if(e.type===`positional`)continue;e.type===`string`||e.type===`enum`?g.string.push(e.name):e.type===`boolean`&&g.boolean.push(e.name),e.default!==void 0&&(g.default[e.name]=e.default),e.alias&&(g.alias[e.name]=e.alias);let h=camelCase(e.name),_=kebabCase(e.name);if(h!==e.name||_!==e.name){let v=toArray(g.alias[e.name]||[]);h!==e.name&&!v.includes(h)&&v.push(h),_!==e.name&&!v.includes(_)&&v.push(_),v.length>0&&(g.alias[e.name]=v)}}let v=parseRawArgs(e,g),[...y]=v._,b=new Proxy(v,{get(e,h){return e[h]??e[camelCase(h)]??e[kebabCase(h)]}});for(let[,e]of _.entries())if(e.type===`positional`){let h=y.shift();if(h!==void 0)b[e.name]=h;else if(e.default===void 0&&e.required!==!1)throw new CLIError(`Missing required positional argument: ${e.name.toUpperCase()}`,`EARG`);else b[e.name]=e.default}else if(e.type===`enum`){let h=b[e.name],g=e.options||[];if(h!==void 0&&g.length>0&&!g.includes(h))throw new CLIError(`Invalid value for argument: ${cyan(`--${e.name}`)} (${cyan(h)}). Expected one of: ${g.map(e=>cyan(e)).join(`, `)}.`,`EARG`)}else if(e.required&&b[e.name]===void 0)throw new CLIError(`Missing required argument: --${e.name}`,`EARG`);return b}function resolveArgs(e){let h=[];for(let[g,_]of Object.entries(e||{}))h.push({..._,name:g,alias:toArray(_.alias)});return h}function defineCommand(e){return e}async function runCommand(e,h){let g=await resolveValue(e.args||{}),_=parseArgs$1(h.rawArgs,g),v={rawArgs:h.rawArgs,args:_,data:h.data,cmd:e};typeof e.setup==`function`&&await e.setup(v);let y;try{let g=await resolveValue(e.subCommands);if(g&&Object.keys(g).length>0){let _=h.rawArgs.findIndex(e=>!e.startsWith(`-`)),v=h.rawArgs[_];if(v){if(!g[v])throw new CLIError(`Unknown command ${cyan(v)}`,`E_UNKNOWN_COMMAND`);let e=await resolveValue(g[v]);e&&await runCommand(e,{rawArgs:h.rawArgs.slice(_+1)})}else if(!e.run)throw new CLIError(`No command specified.`,`E_NO_COMMAND`)}typeof e.run==`function`&&(y=await e.run(v))}finally{typeof e.cleanup==`function`&&await e.cleanup(v)}return{result:y}}async function resolveSubCommand(e,h,g){let _=await resolveValue(e.subCommands);if(_&&Object.keys(_).length>0){let g=h.findIndex(e=>!e.startsWith(`-`)),v=h[g],y=await resolveValue(_[v]);if(y)return resolveSubCommand(y,h.slice(g+1),e)}return[e,g]}async function showUsage(e,h){try{console.log(await renderUsage(e,h)+`
3
- `)}catch(e){console.error(e)}}const negativePrefixRe=/^no[-A-Z]/;async function renderUsage(e,h){let g=await resolveValue(e.meta||{}),_=resolveArgs(await resolveValue(e.args||{})),v=await resolveValue(h?.meta||{}),y=`${v.name?`${v.name} `:``}`+(g.name||process.argv[1]),b=[],x=[],S=[],C=[];for(let e of _)if(e.type===`positional`){let h=e.name.toUpperCase(),g=e.required!==!1&&e.default===void 0,_=e.default?`="${e.default}"`:``;x.push([cyan(h+_),e.description||``,e.valueHint?`<${e.valueHint}>`:``]),C.push(g?`<${h}>`:`[${h}]`)}else{let h=e.required===!0&&e.default===void 0,g=[...(e.alias||[]).map(e=>`-${e}`),`--${e.name}`].join(`, `)+(e.type===`string`&&(e.valueHint||e.default)?`=${e.valueHint?`<${e.valueHint}>`:`"${e.default||``}"`}`:``)+(e.type===`enum`&&e.options?`=<${e.options.join(`|`)}>`:``);if(b.push([cyan(g+(h?` (required)`:``)),e.description||``]),e.type===`boolean`&&(e.default===!0||e.negativeDescription)&&!negativePrefixRe.test(e.name)){let g=[...(e.alias||[]).map(e=>`--no-${e}`),`--no-${e.name}`].join(`, `);b.push([cyan(g+(h?` (required)`:``)),e.negativeDescription||``])}h&&C.push(g)}if(e.subCommands){let h=[],g=await resolveValue(e.subCommands);for(let[e,_]of Object.entries(g)){let g=await resolveValue((await resolveValue(_))?.meta);g?.hidden||(S.push([cyan(e),g?.description||``]),h.push(e))}C.push(h.join(`|`))}let w=[],D=g.version||v.version;w.push(gray(`${g.description} (${y+(D?` v${D}`:``)})`),``);let O=b.length>0||x.length>0;return w.push(`${underline(bold(`USAGE`))} ${cyan(`${y}${O?` [OPTIONS]`:``} ${C.join(` `)}`)}`,``),x.length>0&&(w.push(underline(bold(`ARGUMENTS`)),``),w.push(formatLineColumns(x,` `)),w.push(``)),b.length>0&&(w.push(underline(bold(`OPTIONS`)),``),w.push(formatLineColumns(b,` `)),w.push(``)),S.length>0&&(w.push(underline(bold(`COMMANDS`)),``),w.push(formatLineColumns(S,` `)),w.push(``,`Use ${cyan(`${y} <command> --help`)} for more information about a command.`)),w.filter(e=>typeof e==`string`).join(`
4
- `)}async function runMain(e,h={}){let g=h.rawArgs||process.argv.slice(2),_=h.showUsage||showUsage;try{if(g.includes(`--help`)||g.includes(`-h`))await _(...await resolveSubCommand(e,g)),process.exit(0);else if(g.length===1&&g[0]===`--version`){let h=typeof e.meta==`function`?await e.meta():await e.meta;if(!h?.version)throw new CLIError(`No version specified`,`E_NO_VERSION`);console.log(h.version)}else await runCommand(e,{rawArgs:g})}catch(h){h instanceof CLIError?(await _(...await resolveSubCommand(e,g)),console.error(h.message)):console.error(h,`
5
- `),process.exit(1)}}export{runMain as n,defineCommand as t};
1
+ import { parseArgs } from "node:util";
2
+ const NUMBER_CHAR_RE = /\d/, STR_SPLITTERS = [
3
+ `-`,
4
+ `_`,
5
+ `/`,
6
+ `.`
7
+ ];
8
+ function isUppercase(e = ``) {
9
+ if (!NUMBER_CHAR_RE.test(e)) return e !== e.toLowerCase();
10
+ }
11
+ function splitByCase(e, t) {
12
+ let i = t ?? STR_SPLITTERS, a = [];
13
+ if (!e || typeof e != `string`) return a;
14
+ let o = ``, s, c;
15
+ for (let t of e) {
16
+ let e = i.includes(t);
17
+ if (e === !0) {
18
+ a.push(o), o = ``, s = void 0;
19
+ continue;
20
+ }
21
+ let n = isUppercase(t);
22
+ if (c === !1) {
23
+ if (s === !1 && n === !0) {
24
+ a.push(o), o = t, s = n;
25
+ continue;
26
+ }
27
+ if (s === !0 && n === !1 && o.length > 1) {
28
+ let e = o.at(-1);
29
+ a.push(o.slice(0, Math.max(0, o.length - 1))), o = e + t, s = n;
30
+ continue;
31
+ }
32
+ }
33
+ o += t, s = n, c = e;
34
+ }
35
+ return a.push(o), a;
36
+ }
37
+ function upperFirst(e) {
38
+ return e ? e[0].toUpperCase() + e.slice(1) : ``;
39
+ }
40
+ function lowerFirst(e) {
41
+ return e ? e[0].toLowerCase() + e.slice(1) : ``;
42
+ }
43
+ function pascalCase(e, t) {
44
+ return e ? (Array.isArray(e) ? e : splitByCase(e)).map((e) => upperFirst(t?.normalize ? e.toLowerCase() : e)).join(``) : ``;
45
+ }
46
+ function camelCase(e, t) {
47
+ return lowerFirst(pascalCase(e || ``, t));
48
+ }
49
+ function kebabCase(e, t) {
50
+ return e ? (Array.isArray(e) ? e : splitByCase(e)).map((e) => e.toLowerCase()).join(t ?? `-`) : ``;
51
+ }
52
+ function toArray(e) {
53
+ return Array.isArray(e) ? e : e === void 0 ? [] : [e];
54
+ }
55
+ function formatLineColumns(e, t = ``) {
56
+ let n = [];
57
+ for (let t of e) for (let [e, r] of t.entries()) n[e] = Math.max(n[e] || 0, r.length);
58
+ return e.map((e) => e.map((e, r) => t + e[r === 0 ? `padStart` : `padEnd`](n[r])).join(` `)).join(`
59
+ `);
60
+ }
61
+ function resolveValue(e) {
62
+ return typeof e == `function` ? e() : e;
63
+ }
64
+ var CLIError = class extends Error {
65
+ code;
66
+ constructor(e, t) {
67
+ super(e), this.name = `CLIError`, this.code = t;
68
+ }
69
+ };
70
+ function parseRawArgs(t = [], n = {}) {
71
+ let r = new Set(n.boolean || []), i = new Set(n.string || []), a = n.alias || {}, o = n.default || {}, s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
72
+ for (let [e, t] of Object.entries(a)) {
73
+ let n = t;
74
+ for (let t of n) s.set(e, t), c.has(t) || c.set(t, []), c.get(t).push(e), s.set(t, e), c.has(e) || c.set(e, []), c.get(e).push(t);
75
+ }
76
+ let l = {};
77
+ function u(e) {
78
+ if (r.has(e)) return `boolean`;
79
+ let t = c.get(e) || [];
80
+ for (let e of t) if (r.has(e)) return `boolean`;
81
+ return `string`;
82
+ }
83
+ let d = new Set([
84
+ ...r,
85
+ ...i,
86
+ ...Object.keys(a),
87
+ ...Object.values(a).flat(),
88
+ ...Object.keys(o)
89
+ ]);
90
+ for (let e of d) l[e] || (l[e] = {
91
+ type: u(e),
92
+ default: o[e]
93
+ });
94
+ for (let [e, t] of s.entries()) e.length === 1 && l[t] && !l[t].short && (l[t].short = e);
95
+ let f = [], p = {};
96
+ for (let e = 0; e < t.length; e++) {
97
+ let n = t[e];
98
+ if (n === `--`) {
99
+ f.push(...t.slice(e));
100
+ break;
101
+ }
102
+ if (n.startsWith(`--no-`)) {
103
+ let e = n.slice(5);
104
+ p[e] = !0;
105
+ continue;
106
+ }
107
+ f.push(n);
108
+ }
109
+ let m;
110
+ try {
111
+ m = parseArgs({
112
+ args: f,
113
+ options: Object.keys(l).length > 0 ? l : void 0,
114
+ allowPositionals: !0,
115
+ strict: !1
116
+ });
117
+ } catch {
118
+ m = {
119
+ values: {},
120
+ positionals: f
121
+ };
122
+ }
123
+ let h = { _: [] };
124
+ h._ = m.positionals;
125
+ for (let [e, t] of Object.entries(m.values)) h[e] = t;
126
+ for (let [e] of Object.entries(p)) h[e] = !1;
127
+ for (let [e, t] of s.entries()) h[e] !== void 0 && h[t] === void 0 && (h[t] = h[e]), h[t] !== void 0 && h[e] === void 0 && (h[e] = h[t]);
128
+ return h;
129
+ }
130
+ const noColor = (() => {
131
+ let e = globalThis.process?.env ?? {};
132
+ return e.NO_COLOR === `1` || e.TERM === `dumb` || e.TEST || e.CI;
133
+ })(), _c = (e, t = 39) => (n) => noColor ? n : `\u001B[${e}m${n}\u001B[${t}m`, bold = _c(1, 22), cyan = _c(36), gray = _c(90), underline = _c(4, 24);
134
+ function parseArgs$1(e, t) {
135
+ let n = {
136
+ boolean: [],
137
+ string: [],
138
+ alias: {},
139
+ default: {}
140
+ }, r = resolveArgs(t);
141
+ for (let e of r) {
142
+ if (e.type === `positional`) continue;
143
+ e.type === `string` || e.type === `enum` ? n.string.push(e.name) : e.type === `boolean` && n.boolean.push(e.name), e.default !== void 0 && (n.default[e.name] = e.default), e.alias && (n.alias[e.name] = e.alias);
144
+ let t = camelCase(e.name), r = kebabCase(e.name);
145
+ if (t !== e.name || r !== e.name) {
146
+ let i = toArray(n.alias[e.name] || []);
147
+ t !== e.name && !i.includes(t) && i.push(t), r !== e.name && !i.includes(r) && i.push(r), i.length > 0 && (n.alias[e.name] = i);
148
+ }
149
+ }
150
+ let i = parseRawArgs(e, n), [ ...a] = i._, o = new Proxy(i, { get(e, t) {
151
+ return e[t] ?? e[camelCase(t)] ?? e[kebabCase(t)];
152
+ } });
153
+ for (let [, e] of r.entries()) if (e.type === `positional`) {
154
+ let t = a.shift();
155
+ if (t !== void 0) o[e.name] = t;
156
+ else if (e.default === void 0 && e.required !== !1) throw new CLIError(`Missing required positional argument: ${e.name.toUpperCase()}`, `EARG`);
157
+ else o[e.name] = e.default;
158
+ } else if (e.type === `enum`) {
159
+ let t = o[e.name], n = e.options || [];
160
+ if (t !== void 0 && n.length > 0 && !n.includes(t)) throw new CLIError(`Invalid value for argument: ${cyan(`--${e.name}`)} (${cyan(t)}). Expected one of: ${n.map((e) => cyan(e)).join(`, `)}.`, `EARG`);
161
+ } else if (e.required && o[e.name] === void 0) throw new CLIError(`Missing required argument: --${e.name}`, `EARG`);
162
+ return o;
163
+ }
164
+ function resolveArgs(e) {
165
+ let t = [];
166
+ for (let [n, r] of Object.entries(e || {})) t.push({
167
+ ...r,
168
+ name: n,
169
+ alias: toArray(r.alias)
170
+ });
171
+ return t;
172
+ }
173
+ function defineCommand(e) {
174
+ return e;
175
+ }
176
+ async function runCommand(e, t) {
177
+ let n = await resolveValue(e.args || {}), r = parseArgs$1(t.rawArgs, n), i = {
178
+ rawArgs: t.rawArgs,
179
+ args: r,
180
+ data: t.data,
181
+ cmd: e
182
+ };
183
+ typeof e.setup == `function` && await e.setup(i);
184
+ let a;
185
+ try {
186
+ let n = await resolveValue(e.subCommands);
187
+ if (n && Object.keys(n).length > 0) {
188
+ let r = t.rawArgs.findIndex((e) => !e.startsWith(`-`)), i = t.rawArgs[r];
189
+ if (i) {
190
+ if (!n[i]) throw new CLIError(`Unknown command ${cyan(i)}`, `E_UNKNOWN_COMMAND`);
191
+ let e = await resolveValue(n[i]);
192
+ e && await runCommand(e, { rawArgs: t.rawArgs.slice(r + 1) });
193
+ } else if (!e.run) throw new CLIError(`No command specified.`, `E_NO_COMMAND`);
194
+ }
195
+ typeof e.run == `function` && (a = await e.run(i));
196
+ } finally {
197
+ typeof e.cleanup == `function` && await e.cleanup(i);
198
+ }
199
+ return { result: a };
200
+ }
201
+ async function resolveSubCommand(e, t, n) {
202
+ let r = await resolveValue(e.subCommands);
203
+ if (r && Object.keys(r).length > 0) {
204
+ let n = t.findIndex((e) => !e.startsWith(`-`)), i = t[n], a = await resolveValue(r[i]);
205
+ if (a) return resolveSubCommand(a, t.slice(n + 1), e);
206
+ }
207
+ return [e, n];
208
+ }
209
+ async function showUsage(e, t) {
210
+ try {
211
+ console.log(await renderUsage(e, t) + `
212
+ `);
213
+ } catch (e) {
214
+ console.error(e);
215
+ }
216
+ }
217
+ const negativePrefixRe = /^no[-A-Z]/;
218
+ async function renderUsage(e, t) {
219
+ let n = await resolveValue(e.meta || {}), r = resolveArgs(await resolveValue(e.args || {})), i = await resolveValue(t?.meta || {}), a = `${i.name ? `${i.name} ` : ``}` + (n.name || process.argv[1]), o = [], s = [], c = [], l = [];
220
+ for (let e of r) if (e.type === `positional`) {
221
+ let t = e.name.toUpperCase(), n = e.required !== !1 && e.default === void 0, r = e.default ? `="${e.default}"` : ``;
222
+ s.push([
223
+ cyan(t + r),
224
+ e.description || ``,
225
+ e.valueHint ? `<${e.valueHint}>` : ``
226
+ ]), l.push(n ? `<${t}>` : `[${t}]`);
227
+ } else {
228
+ let t = e.required === !0 && e.default === void 0, n = [...(e.alias || []).map((e) => `-${e}`), `--${e.name}`].join(`, `) + (e.type === `string` && (e.valueHint || e.default) ? `=${e.valueHint ? `<${e.valueHint}>` : `"${e.default || ``}"`}` : ``) + (e.type === `enum` && e.options ? `=<${e.options.join(`|`)}>` : ``);
229
+ if (o.push([cyan(n + (t ? ` (required)` : ``)), e.description || ``]), e.type === `boolean` && (e.default === !0 || e.negativeDescription) && !negativePrefixRe.test(e.name)) {
230
+ let n = [...(e.alias || []).map((e) => `--no-${e}`), `--no-${e.name}`].join(`, `);
231
+ o.push([cyan(n + (t ? ` (required)` : ``)), e.negativeDescription || ``]);
232
+ }
233
+ t && l.push(n);
234
+ }
235
+ if (e.subCommands) {
236
+ let t = [], n = await resolveValue(e.subCommands);
237
+ for (let [e, r] of Object.entries(n)) {
238
+ let n = await resolveValue((await resolveValue(r))?.meta);
239
+ n?.hidden || (c.push([cyan(e), n?.description || ``]), t.push(e));
240
+ }
241
+ l.push(t.join(`|`));
242
+ }
243
+ let u = [], p = n.version || i.version;
244
+ u.push(gray(`${n.description} (${a + (p ? ` v${p}` : ``)})`), ``);
245
+ let m = o.length > 0 || s.length > 0;
246
+ return u.push(`${underline(bold(`USAGE`))} ${cyan(`${a}${m ? ` [OPTIONS]` : ``} ${l.join(` `)}`)}`, ``), s.length > 0 && (u.push(underline(bold(`ARGUMENTS`)), ``), u.push(formatLineColumns(s, ` `)), u.push(``)), o.length > 0 && (u.push(underline(bold(`OPTIONS`)), ``), u.push(formatLineColumns(o, ` `)), u.push(``)), c.length > 0 && (u.push(underline(bold(`COMMANDS`)), ``), u.push(formatLineColumns(c, ` `)), u.push(``, `Use ${cyan(`${a} <command> --help`)} for more information about a command.`)), u.filter((e) => typeof e == `string`).join(`
247
+ `);
248
+ }
249
+ async function runMain(e, t = {}) {
250
+ let n = t.rawArgs || process.argv.slice(2), r = t.showUsage || showUsage;
251
+ try {
252
+ if (n.includes(`--help`) || n.includes(`-h`)) await r(...await resolveSubCommand(e, n)), process.exit(0);
253
+ else if (n.length === 1 && n[0] === `--version`) {
254
+ let t = typeof e.meta == `function` ? await e.meta() : await e.meta;
255
+ if (!t?.version) throw new CLIError(`No version specified`, `E_NO_VERSION`);
256
+ console.log(t.version);
257
+ } else await runCommand(e, { rawArgs: n });
258
+ } catch (t) {
259
+ t instanceof CLIError ? (await r(...await resolveSubCommand(e, n)), console.error(t.message)) : console.error(t, `
260
+ `), process.exit(1);
261
+ }
262
+ }
263
+ export { runMain as n, defineCommand as t };
@@ -1 +1,261 @@
1
- import{a as Minipass}from"./@isaacs/fs-minipass.mjs";import assert from"assert";import{Buffer}from"buffer";import*as realZlib$1 from"zlib";import realZlib from"zlib";const realZlibConstants=realZlib.constants||{ZLIB_VERNUM:4736},constants=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},realZlibConstants)),OriginalBufferConcat=Buffer.concat,desc=Object.getOwnPropertyDescriptor(Buffer,`concat`),noop=e=>e,passthroughBufferConcat=desc?.writable===!0||desc?.set!==void 0?e=>{Buffer.concat=e?noop:OriginalBufferConcat}:e=>{},_superWrite=Symbol(`_superWrite`);var ZlibError=class extends Error{code;errno;constructor(e,h){super(`zlib: `+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||=`ZLIB_ERROR`,this.message=`zlib: `+e.message,Error.captureStackTrace(this,h??this.constructor)}get name(){return`ZlibError`}};const _flushFlag=Symbol(`flushFlag`);var ZlibBase=class extends Minipass{#sawError=!1;#ended=!1;#flushFlag;#finishFlushFlag;#fullFlushFlag;#handle;#onError;get sawError(){return this.#sawError}get handle(){return this.#handle}get flushFlag(){return this.#flushFlag}constructor(e,h){if(!e||typeof e!=`object`)throw TypeError(`invalid options for ZlibBase constructor`);if(super(e),this.#flushFlag=e.flush??0,this.#finishFlushFlag=e.finishFlush??0,this.#fullFlushFlag=e.fullFlushFlag??0,typeof realZlib$1[h]!=`function`)throw TypeError(`Compression method not supported: `+h);try{this.#handle=new realZlib$1[h](e)}catch(e){throw new ZlibError(e,this.constructor)}this.#onError=e=>{this.#sawError||(this.#sawError=!0,this.close(),this.emit(`error`,e))},this.#handle?.on(`error`,e=>this.#onError(new ZlibError(e))),this.once(`end`,()=>this.close)}close(){this.#handle&&(this.#handle.close(),this.#handle=void 0,this.emit(`close`))}reset(){if(!this.#sawError)return assert(this.#handle,`zlib binding closed`),this.#handle.reset?.()}flush(e){this.ended||(typeof e!=`number`&&(e=this.#fullFlushFlag),this.write(Object.assign(Buffer.alloc(0),{[_flushFlag]:e})))}end(e,h,g){return typeof e==`function`&&(g=e,h=void 0,e=void 0),typeof h==`function`&&(g=h,h=void 0),e&&(h?this.write(e,h):this.write(e)),this.flush(this.#finishFlushFlag),this.#ended=!0,super.end(g)}get ended(){return this.#ended}[_superWrite](e){return super.write(e)}write(e,_,v){if(typeof _==`function`&&(v=_,_=`utf8`),typeof e==`string`&&(e=Buffer.from(e,_)),this.#sawError)return;assert(this.#handle,`zlib binding closed`);let y=this.#handle._handle,b=y.close;y.close=()=>{};let x=this.#handle.close;this.#handle.close=()=>{},passthroughBufferConcat(!0);let S;try{let h=typeof e[_flushFlag]==`number`?e[_flushFlag]:this.#flushFlag;S=this.#handle._processChunk(e,h),passthroughBufferConcat(!1)}catch(e){passthroughBufferConcat(!1),this.#onError(new ZlibError(e,this.write))}finally{this.#handle&&(this.#handle._handle=y,y.close=b,this.#handle.close=x,this.#handle.removeAllListeners(`error`))}this.#handle&&this.#handle.on(`error`,e=>this.#onError(new ZlibError(e,this.write)));let C;if(S)if(Array.isArray(S)&&S.length>0){let e=S[0];C=this[_superWrite](Buffer.from(e));for(let e=1;e<S.length;e++)C=this[_superWrite](S[e])}else C=this[_superWrite](Buffer.from(S));return v&&v(),C}},Zlib=class extends ZlibBase{#level;#strategy;constructor(e,h){e||={},e.flush=e.flush||constants.Z_NO_FLUSH,e.finishFlush=e.finishFlush||constants.Z_FINISH,e.fullFlushFlag=constants.Z_FULL_FLUSH,super(e,h),this.#level=e.level,this.#strategy=e.strategy}params(e,g){if(!this.sawError){if(!this.handle)throw Error(`cannot switch params when binding is closed`);if(!this.handle.params)throw Error(`not supported in this implementation`);if(this.#level!==e||this.#strategy!==g){this.flush(constants.Z_SYNC_FLUSH),assert(this.handle,`zlib binding closed`);let _=this.handle.flush;this.handle.flush=(e,h)=>{typeof e==`function`&&(h=e,e=this.flushFlag),this.flush(e),h?.()};try{this.handle.params(e,g)}finally{this.handle.flush=_}this.handle&&(this.#level=e,this.#strategy=g)}}}},Gzip=class extends Zlib{#portable;constructor(e){super(e,`Gzip`),this.#portable=e&&!!e.portable}[_superWrite](e){return this.#portable?(this.#portable=!1,e[9]=255,super[_superWrite](e)):super[_superWrite](e)}},Unzip=class extends Zlib{constructor(e){super(e,`Unzip`)}},Brotli=class extends ZlibBase{constructor(e,h){e||={},e.flush=e.flush||constants.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||constants.BROTLI_OPERATION_FINISH,e.fullFlushFlag=constants.BROTLI_OPERATION_FLUSH,super(e,h)}},BrotliCompress=class extends Brotli{constructor(e){super(e,`BrotliCompress`)}},BrotliDecompress=class extends Brotli{constructor(e){super(e,`BrotliDecompress`)}},Zstd=class extends ZlibBase{constructor(e,h){e||={},e.flush=e.flush||constants.ZSTD_e_continue,e.finishFlush=e.finishFlush||constants.ZSTD_e_end,e.fullFlushFlag=constants.ZSTD_e_flush,super(e,h)}},ZstdCompress=class extends Zstd{constructor(e){super(e,`ZstdCompress`)}},ZstdDecompress=class extends Zstd{constructor(e){super(e,`ZstdDecompress`)}};export{ZstdCompress as a,Unzip as i,BrotliDecompress as n,ZstdDecompress as o,Gzip as r,BrotliCompress as t};
1
+ import { a as Minipass } from "./@isaacs/fs-minipass.mjs";
2
+ import assert from "assert";
3
+ import { Buffer } from "buffer";
4
+ import * as realZlib$1 from "zlib";
5
+ import realZlib from "zlib";
6
+ const realZlibConstants = realZlib.constants || { ZLIB_VERNUM: 4736 }, constants = Object.freeze(Object.assign(Object.create(null), {
7
+ Z_NO_FLUSH: 0,
8
+ Z_PARTIAL_FLUSH: 1,
9
+ Z_SYNC_FLUSH: 2,
10
+ Z_FULL_FLUSH: 3,
11
+ Z_FINISH: 4,
12
+ Z_BLOCK: 5,
13
+ Z_OK: 0,
14
+ Z_STREAM_END: 1,
15
+ Z_NEED_DICT: 2,
16
+ Z_ERRNO: -1,
17
+ Z_STREAM_ERROR: -2,
18
+ Z_DATA_ERROR: -3,
19
+ Z_MEM_ERROR: -4,
20
+ Z_BUF_ERROR: -5,
21
+ Z_VERSION_ERROR: -6,
22
+ Z_NO_COMPRESSION: 0,
23
+ Z_BEST_SPEED: 1,
24
+ Z_BEST_COMPRESSION: 9,
25
+ Z_DEFAULT_COMPRESSION: -1,
26
+ Z_FILTERED: 1,
27
+ Z_HUFFMAN_ONLY: 2,
28
+ Z_RLE: 3,
29
+ Z_FIXED: 4,
30
+ Z_DEFAULT_STRATEGY: 0,
31
+ DEFLATE: 1,
32
+ INFLATE: 2,
33
+ GZIP: 3,
34
+ GUNZIP: 4,
35
+ DEFLATERAW: 5,
36
+ INFLATERAW: 6,
37
+ UNZIP: 7,
38
+ BROTLI_DECODE: 8,
39
+ BROTLI_ENCODE: 9,
40
+ Z_MIN_WINDOWBITS: 8,
41
+ Z_MAX_WINDOWBITS: 15,
42
+ Z_DEFAULT_WINDOWBITS: 15,
43
+ Z_MIN_CHUNK: 64,
44
+ Z_MAX_CHUNK: Infinity,
45
+ Z_DEFAULT_CHUNK: 16384,
46
+ Z_MIN_MEMLEVEL: 1,
47
+ Z_MAX_MEMLEVEL: 9,
48
+ Z_DEFAULT_MEMLEVEL: 8,
49
+ Z_MIN_LEVEL: -1,
50
+ Z_MAX_LEVEL: 9,
51
+ Z_DEFAULT_LEVEL: -1,
52
+ BROTLI_OPERATION_PROCESS: 0,
53
+ BROTLI_OPERATION_FLUSH: 1,
54
+ BROTLI_OPERATION_FINISH: 2,
55
+ BROTLI_OPERATION_EMIT_METADATA: 3,
56
+ BROTLI_MODE_GENERIC: 0,
57
+ BROTLI_MODE_TEXT: 1,
58
+ BROTLI_MODE_FONT: 2,
59
+ BROTLI_DEFAULT_MODE: 0,
60
+ BROTLI_MIN_QUALITY: 0,
61
+ BROTLI_MAX_QUALITY: 11,
62
+ BROTLI_DEFAULT_QUALITY: 11,
63
+ BROTLI_MIN_WINDOW_BITS: 10,
64
+ BROTLI_MAX_WINDOW_BITS: 24,
65
+ BROTLI_LARGE_MAX_WINDOW_BITS: 30,
66
+ BROTLI_DEFAULT_WINDOW: 22,
67
+ BROTLI_MIN_INPUT_BLOCK_BITS: 16,
68
+ BROTLI_MAX_INPUT_BLOCK_BITS: 24,
69
+ BROTLI_PARAM_MODE: 0,
70
+ BROTLI_PARAM_QUALITY: 1,
71
+ BROTLI_PARAM_LGWIN: 2,
72
+ BROTLI_PARAM_LGBLOCK: 3,
73
+ BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4,
74
+ BROTLI_PARAM_SIZE_HINT: 5,
75
+ BROTLI_PARAM_LARGE_WINDOW: 6,
76
+ BROTLI_PARAM_NPOSTFIX: 7,
77
+ BROTLI_PARAM_NDIRECT: 8,
78
+ BROTLI_DECODER_RESULT_ERROR: 0,
79
+ BROTLI_DECODER_RESULT_SUCCESS: 1,
80
+ BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2,
81
+ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3,
82
+ BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0,
83
+ BROTLI_DECODER_PARAM_LARGE_WINDOW: 1,
84
+ BROTLI_DECODER_NO_ERROR: 0,
85
+ BROTLI_DECODER_SUCCESS: 1,
86
+ BROTLI_DECODER_NEEDS_MORE_INPUT: 2,
87
+ BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3,
88
+ BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1,
89
+ BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2,
90
+ BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3,
91
+ BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4,
92
+ BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5,
93
+ BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6,
94
+ BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7,
95
+ BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8,
96
+ BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9,
97
+ BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10,
98
+ BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11,
99
+ BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12,
100
+ BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13,
101
+ BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14,
102
+ BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15,
103
+ BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16,
104
+ BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19,
105
+ BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20,
106
+ BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21,
107
+ BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22,
108
+ BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25,
109
+ BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26,
110
+ BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27,
111
+ BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30,
112
+ BROTLI_DECODER_ERROR_UNREACHABLE: -31
113
+ }, realZlibConstants)), OriginalBufferConcat = Buffer.concat, desc = Object.getOwnPropertyDescriptor(Buffer, `concat`), noop = (e) => e, passthroughBufferConcat = desc?.writable === !0 || desc?.set !== void 0 ? (e) => {
114
+ Buffer.concat = e ? noop : OriginalBufferConcat;
115
+ } : (e) => {}, _superWrite = Symbol(`_superWrite`);
116
+ var ZlibError = class extends Error {
117
+ code;
118
+ errno;
119
+ constructor(e, t) {
120
+ super(`zlib: ` + e.message, { cause: e }), this.code = e.code, this.errno = e.errno, this.code ||= `ZLIB_ERROR`, this.message = `zlib: ` + e.message, Error.captureStackTrace(this, t ?? this.constructor);
121
+ }
122
+ get name() {
123
+ return `ZlibError`;
124
+ }
125
+ };
126
+ const _flushFlag = Symbol(`flushFlag`);
127
+ var ZlibBase = class extends Minipass {
128
+ #sawError = !1;
129
+ #ended = !1;
130
+ #flushFlag;
131
+ #finishFlushFlag;
132
+ #fullFlushFlag;
133
+ #handle;
134
+ #onError;
135
+ get sawError() {
136
+ return this.#sawError;
137
+ }
138
+ get handle() {
139
+ return this.#handle;
140
+ }
141
+ get flushFlag() {
142
+ return this.#flushFlag;
143
+ }
144
+ constructor(e, t) {
145
+ if (!e || typeof e != `object`) throw TypeError(`invalid options for ZlibBase constructor`);
146
+ if (super(e), this.#flushFlag = e.flush ?? 0, this.#finishFlushFlag = e.finishFlush ?? 0, this.#fullFlushFlag = e.fullFlushFlag ?? 0, typeof realZlib$1[t] != `function`) throw TypeError(`Compression method not supported: ` + t);
147
+ try {
148
+ this.#handle = new realZlib$1[t](e);
149
+ } catch (e) {
150
+ throw new ZlibError(e, this.constructor);
151
+ }
152
+ this.#onError = (e) => {
153
+ this.#sawError || (this.#sawError = !0, this.close(), this.emit(`error`, e));
154
+ }, this.#handle?.on(`error`, (e) => this.#onError(new ZlibError(e))), this.once(`end`, () => this.close);
155
+ }
156
+ close() {
157
+ this.#handle && (this.#handle.close(), this.#handle = void 0, this.emit(`close`));
158
+ }
159
+ reset() {
160
+ if (!this.#sawError) return assert(this.#handle, `zlib binding closed`), this.#handle.reset?.();
161
+ }
162
+ flush(e) {
163
+ this.ended || (typeof e != `number` && (e = this.#fullFlushFlag), this.write(Object.assign(Buffer.alloc(0), { [_flushFlag]: e })));
164
+ }
165
+ end(e, t, n) {
166
+ return typeof e == `function` && (n = e, t = void 0, e = void 0), typeof t == `function` && (n = t, t = void 0), e && (t ? this.write(e, t) : this.write(e)), this.flush(this.#finishFlushFlag), this.#ended = !0, super.end(n);
167
+ }
168
+ get ended() {
169
+ return this.#ended;
170
+ }
171
+ [_superWrite](e) {
172
+ return super.write(e);
173
+ }
174
+ write(e, r, i) {
175
+ if (typeof r == `function` && (i = r, r = `utf8`), typeof e == `string` && (e = Buffer.from(e, r)), this.#sawError) return;
176
+ assert(this.#handle, `zlib binding closed`);
177
+ let a = this.#handle._handle, o = a.close;
178
+ a.close = () => {};
179
+ let s = this.#handle.close;
180
+ this.#handle.close = () => {}, passthroughBufferConcat(!0);
181
+ let c;
182
+ try {
183
+ let t = typeof e[_flushFlag] == `number` ? e[_flushFlag] : this.#flushFlag;
184
+ c = this.#handle._processChunk(e, t), passthroughBufferConcat(!1);
185
+ } catch (e) {
186
+ passthroughBufferConcat(!1), this.#onError(new ZlibError(e, this.write));
187
+ } finally {
188
+ this.#handle && (this.#handle._handle = a, a.close = o, this.#handle.close = s, this.#handle.removeAllListeners(`error`));
189
+ }
190
+ this.#handle && this.#handle.on(`error`, (e) => this.#onError(new ZlibError(e, this.write)));
191
+ let l;
192
+ if (c) if (Array.isArray(c) && c.length > 0) {
193
+ let e = c[0];
194
+ l = this[_superWrite](Buffer.from(e));
195
+ for (let e = 1; e < c.length; e++) l = this[_superWrite](c[e]);
196
+ } else l = this[_superWrite](Buffer.from(c));
197
+ return i && i(), l;
198
+ }
199
+ }, Zlib = class extends ZlibBase {
200
+ #level;
201
+ #strategy;
202
+ constructor(e, t) {
203
+ e ||= {}, e.flush = e.flush || constants.Z_NO_FLUSH, e.finishFlush = e.finishFlush || constants.Z_FINISH, e.fullFlushFlag = constants.Z_FULL_FLUSH, super(e, t), this.#level = e.level, this.#strategy = e.strategy;
204
+ }
205
+ params(e, n) {
206
+ if (!this.sawError) {
207
+ if (!this.handle) throw Error(`cannot switch params when binding is closed`);
208
+ if (!this.handle.params) throw Error(`not supported in this implementation`);
209
+ if (this.#level !== e || this.#strategy !== n) {
210
+ this.flush(constants.Z_SYNC_FLUSH), assert(this.handle, `zlib binding closed`);
211
+ let r = this.handle.flush;
212
+ this.handle.flush = (e, t) => {
213
+ typeof e == `function` && (t = e, e = this.flushFlag), this.flush(e), t?.();
214
+ };
215
+ try {
216
+ this.handle.params(e, n);
217
+ } finally {
218
+ this.handle.flush = r;
219
+ }
220
+ this.handle && (this.#level = e, this.#strategy = n);
221
+ }
222
+ }
223
+ }
224
+ }, Gzip = class extends Zlib {
225
+ #portable;
226
+ constructor(e) {
227
+ super(e, `Gzip`), this.#portable = e && !!e.portable;
228
+ }
229
+ [_superWrite](e) {
230
+ return this.#portable ? (this.#portable = !1, e[9] = 255, super[_superWrite](e)) : super[_superWrite](e);
231
+ }
232
+ }, Unzip = class extends Zlib {
233
+ constructor(e) {
234
+ super(e, `Unzip`);
235
+ }
236
+ }, Brotli = class extends ZlibBase {
237
+ constructor(e, t) {
238
+ e ||= {}, e.flush = e.flush || constants.BROTLI_OPERATION_PROCESS, e.finishFlush = e.finishFlush || constants.BROTLI_OPERATION_FINISH, e.fullFlushFlag = constants.BROTLI_OPERATION_FLUSH, super(e, t);
239
+ }
240
+ }, BrotliCompress = class extends Brotli {
241
+ constructor(e) {
242
+ super(e, `BrotliCompress`);
243
+ }
244
+ }, BrotliDecompress = class extends Brotli {
245
+ constructor(e) {
246
+ super(e, `BrotliDecompress`);
247
+ }
248
+ }, Zstd = class extends ZlibBase {
249
+ constructor(e, t) {
250
+ e ||= {}, e.flush = e.flush || constants.ZSTD_e_continue, e.finishFlush = e.finishFlush || constants.ZSTD_e_end, e.fullFlushFlag = constants.ZSTD_e_flush, super(e, t);
251
+ }
252
+ }, ZstdCompress = class extends Zstd {
253
+ constructor(e) {
254
+ super(e, `ZstdCompress`);
255
+ }
256
+ }, ZstdDecompress = class extends Zstd {
257
+ constructor(e) {
258
+ super(e, `ZstdDecompress`);
259
+ }
260
+ };
261
+ export { ZstdCompress as a, Unzip as i, BrotliDecompress as n, ZstdDecompress as o, Gzip as r, BrotliCompress as t };