giget 2.0.0 → 3.0.0

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 CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
  ## Features
10
10
 
11
+ ✨ Zero dependency
12
+
11
13
  ✨ Support popular git providers (GitHub, GitLab, Bitbucket, Sourcehut) out of the box.
12
14
 
13
15
  ✨ Built-in and custom [template registry](#template-registry).
@@ -24,8 +26,6 @@
24
26
 
25
27
  ✨ Optionally install dependencies after clone using [unjs/nypm](https://github.com/unjs/nypm)
26
28
 
27
- ✨ HTTP proxy support and native fetch via [unjs/node-fetch-native](https://github.com/unjs/node-fetch-native)
28
-
29
29
  ## Usage (CLI)
30
30
 
31
31
  ```bash
@@ -216,14 +216,14 @@ If your project depends on a private GitHub repository, you need to add the acce
216
216
  GIGET_AUTH: ${{ secrets.GIGET_AUTH }}
217
217
  ```
218
218
 
219
-
220
219
  ## Related projects
221
220
 
222
221
  Giget wouldn't be possible without inspiration from former projects. In comparison, giget does not depend on any local command which increases stability and performance and supports custom template providers, auth, and many more features out of the box.
223
222
 
224
- - https://github.com/samsonjs/gitter
225
- - https://github.com/tiged/tiged
226
- - https://github.com/Rich-Harris/degit
223
+ - [tiged/tiged](https://github.com/tiged/tiged) (maintained fork of degit)
224
+ - [nrjdalal/gitpick](https://github.com/nrjdalal/gitpick) (alternative approach)
225
+ - [Rich-Harris/degit](https://github.com/Rich-Harris/degit) (last updated - 2021)
226
+ - [samsonjs/gitter](https://github.com/samsonjs/gitter) (archived/updated - 2012)
227
227
 
228
228
  ## 💻 Development
229
229
 
@@ -0,0 +1,271 @@
1
+ import { t as extract } from "./libs/tar.mjs";
2
+ import { a as resolve, i as relative, n as basename, r as dirname, t as installDependencies } from "./libs/nypm.mjs";
3
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { createWriteStream, existsSync, readdirSync, renameSync } from "node:fs";
5
+ import { pipeline } from "node:stream";
6
+ import { spawnSync } from "node:child_process";
7
+ import { homedir, tmpdir } from "node:os";
8
+ import { promisify } from "node:util";
9
+
10
+ //#region src/_utils.ts
11
+ async function download(url, filePath, options = {}) {
12
+ const infoPath = filePath + ".json";
13
+ const info = JSON.parse(await readFile(infoPath, "utf8").catch(() => "{}"));
14
+ const etag = (await sendFetch(url, {
15
+ method: "HEAD",
16
+ headers: options.headers
17
+ }).catch(() => void 0))?.headers.get("etag");
18
+ if (info.etag === etag && existsSync(filePath)) return;
19
+ if (typeof etag === "string") info.etag = etag;
20
+ const response = await sendFetch(url, { headers: options.headers });
21
+ if (response.status >= 400) throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
22
+ const stream = createWriteStream(filePath);
23
+ await promisify(pipeline)(response.body, stream);
24
+ await writeFile(infoPath, JSON.stringify(info), "utf8");
25
+ }
26
+ const inputRegex = /^(?<repo>[\w.-]+\/[\w.-]+)(?<subdir>[^#]+)?(?<ref>#[\w./@-]+)?/;
27
+ function parseGitURI(input) {
28
+ const m = input.match(inputRegex)?.groups || {};
29
+ return {
30
+ repo: m.repo || "",
31
+ subdir: m.subdir || "/",
32
+ ref: m.ref ? m.ref.slice(1) : "main"
33
+ };
34
+ }
35
+ function debug(...args) {
36
+ if (process.env.DEBUG) console.debug("[giget]", ...args);
37
+ }
38
+ async function sendFetch(url, options = {}) {
39
+ if (options.headers?.["sec-fetch-mode"]) options.mode = options.headers["sec-fetch-mode"];
40
+ const res = await fetch(url, {
41
+ ...options,
42
+ headers: normalizeHeaders(options.headers)
43
+ }).catch((error) => {
44
+ throw new Error(`Failed to download ${url}: ${error}`, { cause: error });
45
+ });
46
+ if (options.validateStatus && res.status >= 400) throw new Error(`Failed to fetch ${url}: ${res.status} ${res.statusText}`);
47
+ return res;
48
+ }
49
+ function cacheDirectory() {
50
+ const cacheDir = process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "giget") : resolve(homedir(), ".cache/giget");
51
+ if (process.platform === "win32") {
52
+ const windowsCacheDir = resolve(tmpdir(), "giget");
53
+ if (!existsSync(windowsCacheDir) && existsSync(cacheDir)) try {
54
+ renameSync(cacheDir, windowsCacheDir);
55
+ } catch {}
56
+ return windowsCacheDir;
57
+ }
58
+ return cacheDir;
59
+ }
60
+ function normalizeHeaders(headers = {}) {
61
+ const normalized = {};
62
+ for (const [key, value] of Object.entries(headers)) {
63
+ if (!value) continue;
64
+ normalized[key.toLowerCase()] = value;
65
+ }
66
+ return normalized;
67
+ }
68
+ function currentShell() {
69
+ if (process.env.SHELL) return process.env.SHELL;
70
+ if (process.platform === "win32") return "cmd.exe";
71
+ return "/bin/bash";
72
+ }
73
+ function startShell(cwd) {
74
+ cwd = resolve(cwd);
75
+ const shell = currentShell();
76
+ console.info(`(experimental) Opening shell in ${relative(process.cwd(), cwd)}...`);
77
+ spawnSync(shell, [], {
78
+ cwd,
79
+ shell: true,
80
+ stdio: "inherit"
81
+ });
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/providers.ts
86
+ const http = async (input, options) => {
87
+ if (input.endsWith(".json")) return await _httpJSON(input, options);
88
+ const url = new URL(input);
89
+ let name = basename(url.pathname);
90
+ try {
91
+ const head = await sendFetch(url.href, {
92
+ method: "HEAD",
93
+ validateStatus: true,
94
+ headers: { authorization: options.auth ? `Bearer ${options.auth}` : void 0 }
95
+ });
96
+ if ((head.headers.get("content-type") || "").includes("application/json")) return await _httpJSON(input, options);
97
+ const filename = head.headers.get("content-disposition")?.match(/filename="?(.+)"?/)?.[1];
98
+ if (filename) name = filename.split(".")[0];
99
+ } catch (error) {
100
+ debug(`Failed to fetch HEAD for ${url.href}:`, error);
101
+ }
102
+ return {
103
+ name: `${name}-${url.href.slice(0, 8)}`,
104
+ version: "",
105
+ subdir: "",
106
+ tar: url.href,
107
+ defaultDir: name,
108
+ headers: { Authorization: options.auth ? `Bearer ${options.auth}` : void 0 }
109
+ };
110
+ };
111
+ const _httpJSON = async (input, options) => {
112
+ const info = await (await sendFetch(input, {
113
+ validateStatus: true,
114
+ headers: { authorization: options.auth ? `Bearer ${options.auth}` : void 0 }
115
+ })).json();
116
+ if (!info.tar || !info.name) throw new Error(`Invalid template info from ${input}. name or tar fields are missing!`);
117
+ return info;
118
+ };
119
+ const github = (input, options) => {
120
+ const parsed = parseGitURI(input);
121
+ const githubAPIURL = process.env.GIGET_GITHUB_URL || "https://api.github.com";
122
+ return {
123
+ name: parsed.repo.replace("/", "-"),
124
+ version: parsed.ref,
125
+ subdir: parsed.subdir,
126
+ headers: {
127
+ Authorization: options.auth ? `Bearer ${options.auth}` : void 0,
128
+ Accept: "application/vnd.github+json",
129
+ "X-GitHub-Api-Version": "2022-11-28"
130
+ },
131
+ url: `${githubAPIURL.replace("api.github.com", "github.com")}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`,
132
+ tar: `${githubAPIURL}/repos/${parsed.repo}/tarball/${parsed.ref}`
133
+ };
134
+ };
135
+ const gitlab = (input, options) => {
136
+ const parsed = parseGitURI(input);
137
+ const gitlab = process.env.GIGET_GITLAB_URL || "https://gitlab.com";
138
+ return {
139
+ name: parsed.repo.replace("/", "-"),
140
+ version: parsed.ref,
141
+ subdir: parsed.subdir,
142
+ headers: {
143
+ authorization: options.auth ? `Bearer ${options.auth}` : void 0,
144
+ "sec-fetch-mode": "same-origin"
145
+ },
146
+ url: `${gitlab}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`,
147
+ tar: `${gitlab}/${parsed.repo}/-/archive/${parsed.ref}.tar.gz`
148
+ };
149
+ };
150
+ const bitbucket = (input, options) => {
151
+ const parsed = parseGitURI(input);
152
+ return {
153
+ name: parsed.repo.replace("/", "-"),
154
+ version: parsed.ref,
155
+ subdir: parsed.subdir,
156
+ headers: { authorization: options.auth ? `Bearer ${options.auth}` : void 0 },
157
+ url: `https://bitbucket.com/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`,
158
+ tar: `https://bitbucket.org/${parsed.repo}/get/${parsed.ref}.tar.gz`
159
+ };
160
+ };
161
+ const sourcehut = (input, options) => {
162
+ const parsed = parseGitURI(input);
163
+ return {
164
+ name: parsed.repo.replace("/", "-"),
165
+ version: parsed.ref,
166
+ subdir: parsed.subdir,
167
+ headers: { authorization: options.auth ? `Bearer ${options.auth}` : void 0 },
168
+ url: `https://git.sr.ht/~${parsed.repo}/tree/${parsed.ref}/item${parsed.subdir}`,
169
+ tar: `https://git.sr.ht/~${parsed.repo}/archive/${parsed.ref}.tar.gz`
170
+ };
171
+ };
172
+ const providers = {
173
+ http,
174
+ https: http,
175
+ github,
176
+ gh: github,
177
+ gitlab,
178
+ bitbucket,
179
+ sourcehut
180
+ };
181
+
182
+ //#endregion
183
+ //#region src/registry.ts
184
+ const DEFAULT_REGISTRY = "https://raw.githubusercontent.com/unjs/giget/main/templates";
185
+ const registryProvider = (registryEndpoint = DEFAULT_REGISTRY, options = {}) => {
186
+ return (async (input) => {
187
+ const start = Date.now();
188
+ const registryURL = `${registryEndpoint}/${input}.json`;
189
+ const result = await sendFetch(registryURL, { headers: { authorization: options.auth ? `Bearer ${options.auth}` : void 0 } });
190
+ if (result.status >= 400) throw new Error(`Failed to download ${input} template info from ${registryURL}: ${result.status} ${result.statusText}`);
191
+ const info = await result.json();
192
+ if (!info.tar || !info.name) throw new Error(`Invalid template info from ${registryURL}. name or tar fields are missing!`);
193
+ debug(`Fetched ${input} template info from ${registryURL} in ${Date.now() - start}ms`);
194
+ return info;
195
+ });
196
+ };
197
+
198
+ //#endregion
199
+ //#region src/giget.ts
200
+ const sourceProtoRe = /^([\w-.]+):/;
201
+ async function downloadTemplate(input, options = {}) {
202
+ options.registry = process.env.GIGET_REGISTRY ?? options.registry;
203
+ options.auth = process.env.GIGET_AUTH ?? options.auth;
204
+ const registry = options.registry === false ? void 0 : registryProvider(options.registry, { auth: options.auth });
205
+ let providerName = options.provider || (registry ? "registry" : "github");
206
+ let source = input;
207
+ const sourceProviderMatch = input.match(sourceProtoRe);
208
+ if (sourceProviderMatch) {
209
+ providerName = sourceProviderMatch[1];
210
+ source = input.slice(sourceProviderMatch[0].length);
211
+ if (providerName === "http" || providerName === "https") source = input;
212
+ }
213
+ const provider = options.providers?.[providerName] || providers[providerName] || registry;
214
+ if (!provider) throw new Error(`Unsupported provider: ${providerName}`);
215
+ const template = await Promise.resolve().then(() => provider(source, { auth: options.auth })).catch((error) => {
216
+ throw new Error(`Failed to download template from ${providerName}: ${error.message}`);
217
+ });
218
+ if (!template) throw new Error(`Failed to resolve template from ${providerName}`);
219
+ template.name = (template.name || "template").replace(/[^\da-z-]/gi, "-");
220
+ template.defaultDir = (template.defaultDir || template.name).replace(/[^\da-z-]/gi, "-");
221
+ const tarPath = resolve(resolve(cacheDirectory(), providerName, template.name), (template.version || template.name) + ".tar.gz");
222
+ if (options.preferOffline && existsSync(tarPath)) options.offline = true;
223
+ if (!options.offline) {
224
+ await mkdir(dirname(tarPath), { recursive: true });
225
+ const s$1 = Date.now();
226
+ await download(template.tar, tarPath, { headers: {
227
+ Authorization: options.auth ? `Bearer ${options.auth}` : void 0,
228
+ ...normalizeHeaders(template.headers)
229
+ } }).catch((error) => {
230
+ if (!existsSync(tarPath)) throw error;
231
+ debug("Download error. Using cached version:", error);
232
+ options.offline = true;
233
+ });
234
+ debug(`Downloaded ${template.tar} to ${tarPath} in ${Date.now() - s$1}ms`);
235
+ }
236
+ if (!existsSync(tarPath)) throw new Error(`Tarball not found: ${tarPath} (offline: ${options.offline})`);
237
+ const extractPath = resolve(resolve(options.cwd || "."), options.dir || template.defaultDir);
238
+ if (options.forceClean) await rm(extractPath, {
239
+ recursive: true,
240
+ force: true
241
+ });
242
+ if (!options.force && existsSync(extractPath) && readdirSync(extractPath).length > 0) throw new Error(`Destination ${extractPath} already exists.`);
243
+ await mkdir(extractPath, { recursive: true });
244
+ const s = Date.now();
245
+ const subdir = template.subdir?.replace(/^\//, "") || "";
246
+ await extract({
247
+ file: tarPath,
248
+ cwd: extractPath,
249
+ onReadEntry(entry) {
250
+ entry.path = entry.path.split("/").splice(1).join("/");
251
+ if (subdir) if (entry.path.startsWith(subdir + "/")) entry.path = entry.path.slice(subdir.length);
252
+ else entry.path = "";
253
+ }
254
+ });
255
+ debug(`Extracted to ${extractPath} in ${Date.now() - s}ms`);
256
+ if (options.install) {
257
+ debug("Installing dependencies...");
258
+ await installDependencies({
259
+ cwd: extractPath,
260
+ silent: options.silent
261
+ });
262
+ }
263
+ return {
264
+ ...template,
265
+ source,
266
+ dir: extractPath
267
+ };
268
+ }
269
+
270
+ //#endregion
271
+ export { registryProvider as n, startShell as r, downloadTemplate as t };
@@ -0,0 +1 @@
1
+ import EE from"events";import fs from"fs";import{EventEmitter as EventEmitter$1}from"node:events";import Stream from"node:stream";import{StringDecoder}from"node:string_decoder";const proc=typeof process==`object`&&process?process:{stdout:null,stderr:null},isStream=_=>!!_&&typeof _==`object`&&(_ instanceof Minipass||_ instanceof Stream||isReadable(_)||isWritable(_)),isReadable=_=>!!_&&typeof _==`object`&&_ instanceof EventEmitter$1&&typeof _.pipe==`function`&&_.pipe!==Stream.Writable.prototype.pipe,isWritable=_=>!!_&&typeof _==`object`&&_ instanceof EventEmitter$1&&typeof _.write==`function`&&typeof _.end==`function`,EOF=Symbol(`EOF`),MAYBE_EMIT_END=Symbol(`maybeEmitEnd`),EMITTED_END=Symbol(`emittedEnd`),EMITTING_END=Symbol(`emittingEnd`),EMITTED_ERROR=Symbol(`emittedError`),CLOSED=Symbol(`closed`),READ=Symbol(`read`),FLUSH=Symbol(`flush`),FLUSHCHUNK=Symbol(`flushChunk`),ENCODING=Symbol(`encoding`),DECODER=Symbol(`decoder`),FLOWING=Symbol(`flowing`),PAUSED=Symbol(`paused`),RESUME=Symbol(`resume`),BUFFER=Symbol(`buffer`),PIPES=Symbol(`pipes`),BUFFERLENGTH=Symbol(`bufferLength`),BUFFERPUSH=Symbol(`bufferPush`),BUFFERSHIFT=Symbol(`bufferShift`),OBJECTMODE=Symbol(`objectMode`),DESTROYED=Symbol(`destroyed`),ERROR=Symbol(`error`),EMITDATA=Symbol(`emitData`),EMITEND=Symbol(`emitEnd`),EMITEND2=Symbol(`emitEnd2`),ASYNC=Symbol(`async`),ABORT=Symbol(`abort`),ABORTED=Symbol(`aborted`),SIGNAL=Symbol(`signal`),DATALISTENERS=Symbol(`dataListeners`),DISCARDED=Symbol(`discarded`),defer=_=>Promise.resolve().then(_),nodefer=_=>_(),isEndish=_=>_===`end`||_===`finish`||_===`prefinish`,isArrayBufferLike=_=>_ instanceof ArrayBuffer||!!_&&typeof _==`object`&&_.constructor&&_.constructor.name===`ArrayBuffer`&&_.byteLength>=0,isArrayBufferView=_=>!Buffer.isBuffer(_)&&ArrayBuffer.isView(_);var Pipe=class{src;dest;opts;ondrain;constructor(_,K,q){this.src=_,this.dest=K,this.opts=q,this.ondrain=()=>_[RESUME](),this.dest.on(`drain`,this.ondrain)}unpipe(){this.dest.removeListener(`drain`,this.ondrain)}proxyErrors(_){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},PipeProxyErrors=class extends Pipe{unpipe(){this.src.removeListener(`error`,this.proxyErrors),super.unpipe()}constructor(_,K,q){super(_,K,q),this.proxyErrors=_=>K.emit(`error`,_),_.on(`error`,this.proxyErrors)}};const isObjectModeOptions=_=>!!_.objectMode,isEncodingOptions=_=>!_.objectMode&&!!_.encoding&&_.encoding!==`buffer`;var Minipass=class extends EventEmitter$1{[FLOWING]=!1;[PAUSED]=!1;[PIPES]=[];[BUFFER]=[];[OBJECTMODE];[ENCODING];[ASYNC];[DECODER];[EOF]=!1;[EMITTED_END]=!1;[EMITTING_END]=!1;[CLOSED]=!1;[EMITTED_ERROR]=null;[BUFFERLENGTH]=0;[DESTROYED]=!1;[SIGNAL];[ABORTED]=!1;[DATALISTENERS]=0;[DISCARDED]=!1;writable=!0;readable=!0;constructor(..._){let K=_[0]||{};if(super(),K.objectMode&&typeof K.encoding==`string`)throw TypeError(`Encoding and objectMode may not be used together`);isObjectModeOptions(K)?(this[OBJECTMODE]=!0,this[ENCODING]=null):isEncodingOptions(K)?(this[ENCODING]=K.encoding,this[OBJECTMODE]=!1):(this[OBJECTMODE]=!1,this[ENCODING]=null),this[ASYNC]=!!K.async,this[DECODER]=this[ENCODING]?new StringDecoder(this[ENCODING]):null,K&&K.debugExposeBuffer===!0&&Object.defineProperty(this,`buffer`,{get:()=>this[BUFFER]}),K&&K.debugExposePipes===!0&&Object.defineProperty(this,`pipes`,{get:()=>this[PIPES]});let{signal:q}=K;q&&(this[SIGNAL]=q,q.aborted?this[ABORT]():q.addEventListener(`abort`,()=>this[ABORT]()))}get bufferLength(){return this[BUFFERLENGTH]}get encoding(){return this[ENCODING]}set encoding(_){throw Error(`Encoding must be set at instantiation time`)}setEncoding(_){throw Error(`Encoding must be set at instantiation time`)}get objectMode(){return this[OBJECTMODE]}set objectMode(_){throw Error(`objectMode must be set at instantiation time`)}get async(){return this[ASYNC]}set async(_){this[ASYNC]=this[ASYNC]||!!_}[ABORT](){this[ABORTED]=!0,this.emit(`abort`,this[SIGNAL]?.reason),this.destroy(this[SIGNAL]?.reason)}get aborted(){return this[ABORTED]}set aborted(_){}write(_,K,q){if(this[ABORTED])return!1;if(this[EOF])throw Error(`write after end`);if(this[DESTROYED])return this.emit(`error`,Object.assign(Error(`Cannot call write after a stream was destroyed`),{code:`ERR_STREAM_DESTROYED`})),!0;typeof K==`function`&&(q=K,K=`utf8`),K||=`utf8`;let J=this[ASYNC]?defer:nodefer;if(!this[OBJECTMODE]&&!Buffer.isBuffer(_)){if(isArrayBufferView(_))_=Buffer.from(_.buffer,_.byteOffset,_.byteLength);else if(isArrayBufferLike(_))_=Buffer.from(_);else if(typeof _!=`string`)throw Error(`Non-contiguous data written to non-objectMode stream`)}return this[OBJECTMODE]?(this[FLOWING]&&this[BUFFERLENGTH]!==0&&this[FLUSH](!0),this[FLOWING]?this.emit(`data`,_):this[BUFFERPUSH](_),this[BUFFERLENGTH]!==0&&this.emit(`readable`),q&&J(q),this[FLOWING]):_.length?(typeof _==`string`&&!(K===this[ENCODING]&&!this[DECODER]?.lastNeed)&&(_=Buffer.from(_,K)),Buffer.isBuffer(_)&&this[ENCODING]&&(_=this[DECODER].write(_)),this[FLOWING]&&this[BUFFERLENGTH]!==0&&this[FLUSH](!0),this[FLOWING]?this.emit(`data`,_):this[BUFFERPUSH](_),this[BUFFERLENGTH]!==0&&this.emit(`readable`),q&&J(q),this[FLOWING]):(this[BUFFERLENGTH]!==0&&this.emit(`readable`),q&&J(q),this[FLOWING])}read(_){if(this[DESTROYED])return null;if(this[DISCARDED]=!1,this[BUFFERLENGTH]===0||_===0||_&&_>this[BUFFERLENGTH])return this[MAYBE_EMIT_END](),null;this[OBJECTMODE]&&(_=null),this[BUFFER].length>1&&!this[OBJECTMODE]&&(this[BUFFER]=[this[ENCODING]?this[BUFFER].join(``):Buffer.concat(this[BUFFER],this[BUFFERLENGTH])]);let K=this[READ](_||null,this[BUFFER][0]);return this[MAYBE_EMIT_END](),K}[READ](_,K){if(this[OBJECTMODE])this[BUFFERSHIFT]();else{let q=K;_===q.length||_===null?this[BUFFERSHIFT]():typeof q==`string`?(this[BUFFER][0]=q.slice(_),K=q.slice(0,_),this[BUFFERLENGTH]-=_):(this[BUFFER][0]=q.subarray(_),K=q.subarray(0,_),this[BUFFERLENGTH]-=_)}return this.emit(`data`,K),!this[BUFFER].length&&!this[EOF]&&this.emit(`drain`),K}end(_,K,q){return typeof _==`function`&&(q=_,_=void 0),typeof K==`function`&&(q=K,K=`utf8`),_!==void 0&&this.write(_,K),q&&this.once(`end`,q),this[EOF]=!0,this.writable=!1,(this[FLOWING]||!this[PAUSED])&&this[MAYBE_EMIT_END](),this}[RESUME](){this[DESTROYED]||(!this[DATALISTENERS]&&!this[PIPES].length&&(this[DISCARDED]=!0),this[PAUSED]=!1,this[FLOWING]=!0,this.emit(`resume`),this[BUFFER].length?this[FLUSH]():this[EOF]?this[MAYBE_EMIT_END]():this.emit(`drain`))}resume(){return this[RESUME]()}pause(){this[FLOWING]=!1,this[PAUSED]=!0,this[DISCARDED]=!1}get destroyed(){return this[DESTROYED]}get flowing(){return this[FLOWING]}get paused(){return this[PAUSED]}[BUFFERPUSH](_){this[OBJECTMODE]?this[BUFFERLENGTH]+=1:this[BUFFERLENGTH]+=_.length,this[BUFFER].push(_)}[BUFFERSHIFT](){return this[OBJECTMODE]?--this[BUFFERLENGTH]:this[BUFFERLENGTH]-=this[BUFFER][0].length,this[BUFFER].shift()}[FLUSH](_=!1){do;while(this[FLUSHCHUNK](this[BUFFERSHIFT]())&&this[BUFFER].length);!_&&!this[BUFFER].length&&!this[EOF]&&this.emit(`drain`)}[FLUSHCHUNK](_){return this.emit(`data`,_),this[FLOWING]}pipe(_,K){if(this[DESTROYED])return _;this[DISCARDED]=!1;let q=this[EMITTED_END];return K||={},_===proc.stdout||_===proc.stderr?K.end=!1:K.end=K.end!==!1,K.proxyErrors=!!K.proxyErrors,q?K.end&&_.end():(this[PIPES].push(K.proxyErrors?new PipeProxyErrors(this,_,K):new Pipe(this,_,K)),this[ASYNC]?defer(()=>this[RESUME]()):this[RESUME]()),_}unpipe(_){let K=this[PIPES].find(K=>K.dest===_);K&&(this[PIPES].length===1?(this[FLOWING]&&this[DATALISTENERS]===0&&(this[FLOWING]=!1),this[PIPES]=[]):this[PIPES].splice(this[PIPES].indexOf(K),1),K.unpipe())}addListener(_,K){return this.on(_,K)}on(_,K){let q=super.on(_,K);if(_===`data`)this[DISCARDED]=!1,this[DATALISTENERS]++,!this[PIPES].length&&!this[FLOWING]&&this[RESUME]();else if(_===`readable`&&this[BUFFERLENGTH]!==0)super.emit(`readable`);else if(isEndish(_)&&this[EMITTED_END])super.emit(_),this.removeAllListeners(_);else if(_===`error`&&this[EMITTED_ERROR]){let _=K;this[ASYNC]?defer(()=>_.call(this,this[EMITTED_ERROR])):_.call(this,this[EMITTED_ERROR])}return q}removeListener(_,K){return this.off(_,K)}off(_,K){let q=super.off(_,K);return _===`data`&&(this[DATALISTENERS]=this.listeners(`data`).length,this[DATALISTENERS]===0&&!this[DISCARDED]&&!this[PIPES].length&&(this[FLOWING]=!1)),q}removeAllListeners(_){let K=super.removeAllListeners(_);return(_===`data`||_===void 0)&&(this[DATALISTENERS]=0,!this[DISCARDED]&&!this[PIPES].length&&(this[FLOWING]=!1)),K}get emittedEnd(){return this[EMITTED_END]}[MAYBE_EMIT_END](){!this[EMITTING_END]&&!this[EMITTED_END]&&!this[DESTROYED]&&this[BUFFER].length===0&&this[EOF]&&(this[EMITTING_END]=!0,this.emit(`end`),this.emit(`prefinish`),this.emit(`finish`),this[CLOSED]&&this.emit(`close`),this[EMITTING_END]=!1)}emit(_,...K){let q=K[0];if(_!==`error`&&_!==`close`&&_!==DESTROYED&&this[DESTROYED])return!1;if(_===`data`)return!this[OBJECTMODE]&&!q?!1:this[ASYNC]?(defer(()=>this[EMITDATA](q)),!0):this[EMITDATA](q);if(_===`end`)return this[EMITEND]();if(_===`close`){if(this[CLOSED]=!0,!this[EMITTED_END]&&!this[DESTROYED])return!1;let _=super.emit(`close`);return this.removeAllListeners(`close`),_}else if(_===`error`){this[EMITTED_ERROR]=q,super.emit(ERROR,q);let _=!this[SIGNAL]||this.listeners(`error`).length?super.emit(`error`,q):!1;return this[MAYBE_EMIT_END](),_}else if(_===`resume`){let _=super.emit(`resume`);return this[MAYBE_EMIT_END](),_}else if(_===`finish`||_===`prefinish`){let K=super.emit(_);return this.removeAllListeners(_),K}let J=super.emit(_,...K);return this[MAYBE_EMIT_END](),J}[EMITDATA](_){for(let K of this[PIPES])K.dest.write(_)===!1&&this.pause();let K=this[DISCARDED]?!1:super.emit(`data`,_);return this[MAYBE_EMIT_END](),K}[EMITEND](){return this[EMITTED_END]?!1:(this[EMITTED_END]=!0,this.readable=!1,this[ASYNC]?(defer(()=>this[EMITEND2]()),!0):this[EMITEND2]())}[EMITEND2](){if(this[DECODER]){let _=this[DECODER].end();if(_){for(let K of this[PIPES])K.dest.write(_);this[DISCARDED]||super.emit(`data`,_)}}for(let _ of this[PIPES])_.end();let _=super.emit(`end`);return this.removeAllListeners(`end`),_}async collect(){let _=Object.assign([],{dataLength:0});this[OBJECTMODE]||(_.dataLength=0);let K=this.promise();return this.on(`data`,K=>{_.push(K),this[OBJECTMODE]||(_.dataLength+=K.length)}),await K,_}async concat(){if(this[OBJECTMODE])throw Error(`cannot concat in objectMode`);let _=await this.collect();return this[ENCODING]?_.join(``):Buffer.concat(_,_.dataLength)}async promise(){return new Promise((_,K)=>{this.on(DESTROYED,()=>K(Error(`stream destroyed`))),this.on(`error`,_=>K(_)),this.on(`end`,()=>_())})}[Symbol.asyncIterator](){this[DISCARDED]=!1;let _=!1,K=async()=>(this.pause(),_=!0,{value:void 0,done:!0});return{next:()=>{if(_)return K();let q=this.read();if(q!==null)return Promise.resolve({done:!1,value:q});if(this[EOF])return K();let J,Y,X=_=>{this.off(`data`,Z),this.off(`end`,Q),this.off(DESTROYED,$),K(),Y(_)},Z=_=>{this.off(`error`,X),this.off(`end`,Q),this.off(DESTROYED,$),this.pause(),J({value:_,done:!!this[EOF]})},Q=()=>{this.off(`error`,X),this.off(`data`,Z),this.off(DESTROYED,$),K(),J({done:!0,value:void 0})},$=()=>X(Error(`stream destroyed`));return new Promise((_,K)=>{Y=K,J=_,this.once(DESTROYED,$),this.once(`error`,X),this.once(`end`,Q),this.once(`data`,Z)})},throw:K,return:K,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[DISCARDED]=!1;let _=!1,K=()=>(this.pause(),this.off(ERROR,K),this.off(DESTROYED,K),this.off(`end`,K),_=!0,{done:!0,value:void 0});return this.once(`end`,K),this.once(ERROR,K),this.once(DESTROYED,K),{next:()=>{if(_)return K();let q=this.read();return q===null?K():{done:!1,value:q}},throw:K,return:K,[Symbol.iterator](){return this}}}destroy(_){if(this[DESTROYED])return _?this.emit(`error`,_):this.emit(DESTROYED),this;this[DESTROYED]=!0,this[DISCARDED]=!0,this[BUFFER].length=0,this[BUFFERLENGTH]=0;let K=this;return typeof K.close==`function`&&!this[CLOSED]&&K.close(),_?this.emit(`error`,_):this.emit(DESTROYED),this}static get isStream(){return isStream}};const writev=fs.writev,_autoClose=Symbol(`_autoClose`),_close=Symbol(`_close`),_ended=Symbol(`_ended`),_fd=Symbol(`_fd`),_finished=Symbol(`_finished`),_flags=Symbol(`_flags`),_flush=Symbol(`_flush`),_handleChunk=Symbol(`_handleChunk`),_makeBuf=Symbol(`_makeBuf`),_mode=Symbol(`_mode`),_needDrain=Symbol(`_needDrain`),_onerror=Symbol(`_onerror`),_onopen=Symbol(`_onopen`),_onread=Symbol(`_onread`),_onwrite=Symbol(`_onwrite`),_open=Symbol(`_open`),_path=Symbol(`_path`),_pos=Symbol(`_pos`),_queue=Symbol(`_queue`),_read=Symbol(`_read`),_readSize=Symbol(`_readSize`),_reading=Symbol(`_reading`),_remain=Symbol(`_remain`),_size=Symbol(`_size`),_write=Symbol(`_write`),_writing=Symbol(`_writing`),_defaultFlag=Symbol(`_defaultFlag`),_errored=Symbol(`_errored`);var ReadStream=class extends Minipass{[_errored]=!1;[_fd];[_path];[_readSize];[_reading]=!1;[_size];[_remain];[_autoClose];constructor(_,K){if(K||={},super(K),this.readable=!0,this.writable=!1,typeof _!=`string`)throw TypeError(`path must be a string`);this[_errored]=!1,this[_fd]=typeof K.fd==`number`?K.fd:void 0,this[_path]=_,this[_readSize]=K.readSize||16*1024*1024,this[_reading]=!1,this[_size]=typeof K.size==`number`?K.size:1/0,this[_remain]=this[_size],this[_autoClose]=typeof K.autoClose==`boolean`?K.autoClose:!0,typeof this[_fd]==`number`?this[_read]():this[_open]()}get fd(){return this[_fd]}get path(){return this[_path]}write(){throw TypeError(`this is a readable stream`)}end(){throw TypeError(`this is a readable stream`)}[_open](){fs.open(this[_path],`r`,(_,K)=>this[_onopen](_,K))}[_onopen](_,K){_?this[_onerror](_):(this[_fd]=K,this.emit(`open`,K),this[_read]())}[_makeBuf](){return Buffer.allocUnsafe(Math.min(this[_readSize],this[_remain]))}[_read](){if(!this[_reading]){this[_reading]=!0;let _=this[_makeBuf]();if(_.length===0)return process.nextTick(()=>this[_onread](null,0,_));fs.read(this[_fd],_,0,_.length,null,(_,K,q)=>this[_onread](_,K,q))}}[_onread](_,K,q){this[_reading]=!1,_?this[_onerror](_):this[_handleChunk](K,q)&&this[_read]()}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.close(_,_=>_?this.emit(`error`,_):this.emit(`close`))}}[_onerror](_){this[_reading]=!0,this[_close](),this.emit(`error`,_)}[_handleChunk](_,K){let q=!1;return this[_remain]-=_,_>0&&(q=super.write(_<K.length?K.subarray(0,_):K)),(_===0||this[_remain]<=0)&&(q=!1,this[_close](),super.end()),q}emit(_,...K){switch(_){case`prefinish`:case`finish`:return!1;case`drain`:return typeof this[_fd]==`number`&&this[_read](),!1;case`error`:return this[_errored]?!1:(this[_errored]=!0,super.emit(_,...K));default:return super.emit(_,...K)}}},ReadStreamSync=class extends ReadStream{[_open](){let _=!0;try{this[_onopen](null,fs.openSync(this[_path],`r`)),_=!1}finally{_&&this[_close]()}}[_read](){let _=!0;try{if(!this[_reading]){this[_reading]=!0;do{let _=this[_makeBuf](),q=_.length===0?0:fs.readSync(this[_fd],_,0,_.length,null);if(!this[_handleChunk](q,_))break}while(!0);this[_reading]=!1}_=!1}finally{_&&this[_close]()}}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.closeSync(_),this.emit(`close`)}}},WriteStream=class extends EE{readable=!1;writable=!0;[_errored]=!1;[_writing]=!1;[_ended]=!1;[_queue]=[];[_needDrain]=!1;[_path];[_mode];[_autoClose];[_fd];[_defaultFlag];[_flags];[_finished]=!1;[_pos];constructor(_,K){K||={},super(K),this[_path]=_,this[_fd]=typeof K.fd==`number`?K.fd:void 0,this[_mode]=K.mode===void 0?438:K.mode,this[_pos]=typeof K.start==`number`?K.start:void 0,this[_autoClose]=typeof K.autoClose==`boolean`?K.autoClose:!0;let q=this[_pos]===void 0?`w`:`r+`;this[_defaultFlag]=K.flags===void 0,this[_flags]=K.flags===void 0?q:K.flags,this[_fd]===void 0&&this[_open]()}emit(_,...K){if(_===`error`){if(this[_errored])return!1;this[_errored]=!0}return super.emit(_,...K)}get fd(){return this[_fd]}get path(){return this[_path]}[_onerror](_){this[_close](),this[_writing]=!0,this.emit(`error`,_)}[_open](){fs.open(this[_path],this[_flags],this[_mode],(_,K)=>this[_onopen](_,K))}[_onopen](_,K){this[_defaultFlag]&&this[_flags]===`r+`&&_&&_.code===`ENOENT`?(this[_flags]=`w`,this[_open]()):_?this[_onerror](_):(this[_fd]=K,this.emit(`open`,K),this[_writing]||this[_flush]())}end(_,K){return _&&this.write(_,K),this[_ended]=!0,!this[_writing]&&!this[_queue].length&&typeof this[_fd]==`number`&&this[_onwrite](null,0),this}write(_,K){return typeof _==`string`&&(_=Buffer.from(_,K)),this[_ended]?(this.emit(`error`,Error(`write() after end()`)),!1):this[_fd]===void 0||this[_writing]||this[_queue].length?(this[_queue].push(_),this[_needDrain]=!0,!1):(this[_writing]=!0,this[_write](_),!0)}[_write](_){fs.write(this[_fd],_,0,_.length,this[_pos],(_,K)=>this[_onwrite](_,K))}[_onwrite](_,K){_?this[_onerror](_):(this[_pos]!==void 0&&typeof K==`number`&&(this[_pos]+=K),this[_queue].length?this[_flush]():(this[_writing]=!1,this[_ended]&&!this[_finished]?(this[_finished]=!0,this[_close](),this.emit(`finish`)):this[_needDrain]&&(this[_needDrain]=!1,this.emit(`drain`))))}[_flush](){if(this[_queue].length===0)this[_ended]&&this[_onwrite](null,0);else if(this[_queue].length===1)this[_write](this[_queue].pop());else{let _=this[_queue];this[_queue]=[],writev(this[_fd],_,this[_pos],(_,K)=>this[_onwrite](_,K))}}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.close(_,_=>_?this.emit(`error`,_):this.emit(`close`))}}},WriteStreamSync=class extends WriteStream{[_open](){let _;if(this[_defaultFlag]&&this[_flags]===`r+`)try{_=fs.openSync(this[_path],this[_flags],this[_mode])}catch(_){if(_?.code===`ENOENT`)return this[_flags]=`w`,this[_open]();throw _}else _=fs.openSync(this[_path],this[_flags],this[_mode]);this[_onopen](null,_)}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.closeSync(_),this.emit(`close`)}}[_write](_){let q=!0;try{this[_onwrite](null,fs.writeSync(this[_fd],_,0,_.length,this[_pos])),q=!1}finally{if(q)try{this[_close]()}catch{}}}};export{Minipass as a,WriteStreamSync as i,ReadStreamSync as n,WriteStream as r,ReadStream as t};
@@ -0,0 +1 @@
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};
@@ -0,0 +1,5 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1,2 @@
1
+ import"node:module";import{readFile}from"node:fs/promises";import{existsSync}from"node:fs";import{PassThrough}from"node:stream";import{delimiter,dirname,join,normalize,resolve}from"node:path";import{createRequire}from"module";import{spawn}from"node:child_process";import{cwd}from"node:process";import c from"node:readline";const _DRIVE_LETTER_START_RE=/^[A-Za-z]:\//;function normalizeWindowsPath(e=``){return e&&e.replace(/\\/g,`/`).replace(_DRIVE_LETTER_START_RE,e=>e.toUpperCase())}const _UNC_REGEX=/^[/\\]{2}/,_IS_ABSOLUTE_RE=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,_DRIVE_LETTER_RE=/^[A-Za-z]:$/,_ROOT_FOLDER_RE=/^\/([A-Za-z]:)?$/,normalize$1=function(e){if(e.length===0)return`.`;e=normalizeWindowsPath(e);let r=e.match(_UNC_REGEX),i=isAbsolute(e),a=e[e.length-1]===`/`;return e=normalizeString(e,!i),e.length===0?i?`/`:a?`./`:`.`:(a&&(e+=`/`),_DRIVE_LETTER_RE.test(e)&&(e+=`/`),r?i?`//${e}`:`//./${e}`:i&&!isAbsolute(e)?`/${e}`:e)},join$1=function(...e){let r=``;for(let i of e)if(i)if(r.length>0){let e=r[r.length-1]===`/`,a=i[0]===`/`;e&&a?r+=i.slice(1):r+=e||a?i:`/${i}`}else r+=i;return normalize$1(r)};function cwd$1(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}const resolve$1=function(...e){e=e.map(e=>normalizeWindowsPath(e));let r=``,i=!1;for(let a=e.length-1;a>=-1&&!i;a--){let o=a>=0?e[a]:cwd$1();!o||o.length===0||(r=`${o}/${r}`,i=isAbsolute(o))}return r=normalizeString(r,!i),i&&!isAbsolute(r)?`/${r}`:r.length>0?r:`.`};function normalizeString(e,r){let i=``,a=0,o=-1,s=0,L=null;for(let J=0;J<=e.length;++J){if(J<e.length)L=e[J];else if(L===`/`)break;else L=`/`;if(L===`/`){if(!(o===J-1||s===1))if(s===2){if(i.length<2||a!==2||i[i.length-1]!==`.`||i[i.length-2]!==`.`){if(i.length>2){let e=i.lastIndexOf(`/`);e===-1?(i=``,a=0):(i=i.slice(0,e),a=i.length-1-i.lastIndexOf(`/`)),o=J,s=0;continue}else if(i.length>0){i=``,a=0,o=J,s=0;continue}}r&&(i+=i.length>0?`/..`:`..`,a=2)}else i.length>0?i+=`/${e.slice(o+1,J)}`:i=e.slice(o+1,J),a=J-o-1;o=J,s=0}else L===`.`&&s!==-1?++s:s=-1}return i}const isAbsolute=function(e){return _IS_ABSOLUTE_RE.test(e)},relative=function(e,r){let i=resolve$1(e).replace(_ROOT_FOLDER_RE,`$1`).split(`/`),a=resolve$1(r).replace(_ROOT_FOLDER_RE,`$1`).split(`/`);if(a[0][1]===`:`&&i[0][1]===`:`&&i[0]!==a[0])return a.join(`/`);let o=[...i];for(let e of o){if(a[0]!==e)break;i.shift(),a.shift()}return[...i.map(()=>`..`),...a].join(`/`)},dirname$1=function(e){let r=normalizeWindowsPath(e).replace(/\/$/,``).split(`/`).slice(0,-1);return r.length===1&&_DRIVE_LETTER_RE.test(r[0])&&(r[0]+=`/`),r.join(`/`)||(isAbsolute(e)?`/`:`.`)},basename$1=function(e,r){let i=normalizeWindowsPath(e).split(`/`),a=``;for(let e=i.length-1;e>=0;e--){let r=i[e];if(r){a=r;break}}return r&&a.endsWith(r)?a.slice(0,-r.length):a};var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),g=(e,r,i,a)=>{if(r&&typeof r==`object`||typeof r==`function`)for(var o=f(r),s=0,L=o.length,J;s<L;s++)J=o[s],!m.call(e,J)&&J!==i&&u(e,J,{get:(e=>r[e]).bind(null,J),enumerable:!(a=d(r,J))||a.enumerable});return e},_=(e,r,i)=>(i=e==null?{}:l(p(e)),g(r||!e||!e.__esModule?u(i,`default`,{value:e,enumerable:!0}):i,e)),v=createRequire(import.meta.url);const y=/^path$/i,b={key:`PATH`,value:``};function x(e){for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r)||!y.test(r))continue;let i=e[r];return i?{key:r,value:i}:b}return b}function S(e,r){let i=r.value.split(delimiter),s=e,L;do i.push(resolve(s,`node_modules`,`.bin`)),L=s,s=dirname(s);while(s!==L);return{key:r.key,value:i.join(delimiter)}}function C(e,r){let i={...process.env,...r},a=S(e,x(i));return i[a.key]=a.value,i}const w=e=>{let r=e.length,a=new PassThrough,o=()=>{--r===0&&a.emit(`end`)};for(let r of e)r.pipe(a,{end:!1}),r.on(`end`,o);return a};var T=h((e,r)=>{r.exports=s,s.sync=L;var i=v(`fs`);function a(e,r){var i=r.pathExt===void 0?process.env.PATHEXT:r.pathExt;if(!i||(i=i.split(`;`),i.indexOf(``)!==-1))return!0;for(var a=0;a<i.length;a++){var o=i[a].toLowerCase();if(o&&e.substr(-o.length).toLowerCase()===o)return!0}return!1}function o(e,r,i){return!e.isSymbolicLink()&&!e.isFile()?!1:a(r,i)}function s(e,r,a){i.stat(e,function(i,s){a(i,i?!1:o(s,e,r))})}function L(e,r){return o(i.statSync(e),e,r)}}),E=h((e,r)=>{r.exports=a,a.sync=o;var i=v(`fs`);function a(e,r,a){i.stat(e,function(e,i){a(e,e?!1:s(i,r))})}function o(e,r){return s(i.statSync(e),r)}function s(e,r){return e.isFile()&&L(e,r)}function L(e,r){var i=e.mode,a=e.uid,o=e.gid,s=r.uid===void 0?process.getuid&&process.getuid():r.uid,L=r.gid===void 0?process.getgid&&process.getgid():r.gid,J=64,Y=8,X=1,Z=J|Y;return i&X||i&Y&&o===L||i&J&&a===s||i&Z&&s===0}}),D=h((e,r)=>{v(`fs`);var i=process.platform===`win32`||global.TESTING_WINDOWS?T():E();r.exports=a,a.sync=o;function a(e,r,o){if(typeof r==`function`&&(o=r,r={}),!o){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(i,o){a(e,r||{},function(e,r){e?o(e):i(r)})})}i(e,r||{},function(e,i){e&&(e.code===`EACCES`||r&&r.ignoreErrors)&&(e=null,i=!1),o(e,i)})}function o(e,r){try{return i.sync(e,r||{})}catch(e){if(r&&r.ignoreErrors||e.code===`EACCES`)return!1;throw e}}}),O=h((e,r)=>{let i=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,a=v(`path`),o=i?`;`:`:`,s=D(),L=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),J=(e,r)=>{let a=r.colon||o,s=e.match(/\//)||i&&e.match(/\\/)?[``]:[...i?[process.cwd()]:[],...(r.path||process.env.PATH||``).split(a)],L=i?r.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,J=i?L.split(a):[``];return i&&e.indexOf(`.`)!==-1&&J[0]!==``&&J.unshift(``),{pathEnv:s,pathExt:J,pathExtExe:L}},Y=(e,r,i)=>{typeof r==`function`&&(i=r,r={}),r||={};let{pathEnv:o,pathExt:Y,pathExtExe:X}=J(e,r),Z=[],Q=i=>new Promise((s,J)=>{if(i===o.length)return r.all&&Z.length?s(Z):J(L(e));let Y=o[i],X=/^".*"$/.test(Y)?Y.slice(1,-1):Y,Q=a.join(X,e);s($(!X&&/^\.[\\\/]/.test(e)?e.slice(0,2)+Q:Q,i,0))}),$=(e,i,a)=>new Promise((o,L)=>{if(a===Y.length)return o(Q(i+1));let J=Y[a];s(e+J,{pathExt:X},(s,L)=>{if(!s&&L)if(r.all)Z.push(e+J);else return o(e+J);return o($(e,i,a+1))})});return i?Q(0).then(e=>i(null,e),i):Q(0)};r.exports=Y,Y.sync=(e,r)=>{r||={};let{pathEnv:i,pathExt:o,pathExtExe:Y}=J(e,r),X=[];for(let L=0;L<i.length;L++){let J=i[L],Z=/^".*"$/.test(J)?J.slice(1,-1):J,Q=a.join(Z,e),$=!Z&&/^\.[\\\/]/.test(e)?e.slice(0,2)+Q:Q;for(let e=0;e<o.length;e++){let i=$+o[e];try{if(s.sync(i,{pathExt:Y}))if(r.all)X.push(i);else return i}catch{}}}if(r.all&&X.length)return X;if(r.nothrow)return null;throw L(e)}}),k=h((e,r)=>{let i=(e={})=>{let r=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(r).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};r.exports=i,r.exports.default=i}),A=h((e,r)=>{let i=v(`path`),a=O(),o=k();function s(e,r){let s=e.options.env||process.env,L=process.cwd(),J=e.options.cwd!=null,Y=J&&process.chdir!==void 0&&!process.chdir.disabled;if(Y)try{process.chdir(e.options.cwd)}catch{}let X;try{X=a.sync(e.command,{path:s[o({env:s})],pathExt:r?i.delimiter:void 0})}catch{}finally{Y&&process.chdir(L)}return X&&=i.resolve(J?e.options.cwd:``,X),X}function L(e){return s(e)||s(e,!0)}r.exports=L}),j=h((e,r)=>{let i=/([()\][%!^"`<>&|;, *?])/g;function a(e){return e=e.replace(i,`^$1`),e}function o(e,r){return e=`${e}`,e=e.replace(/(\\*)"/g,`$1$1\\"`),e=e.replace(/(\\*)$/,`$1$1`),e=`"${e}"`,e=e.replace(i,`^$1`),r&&(e=e.replace(i,`^$1`)),e}r.exports.command=a,r.exports.argument=o}),M=h((e,r)=>{r.exports=/^#!(.*)/}),N=h((e,r)=>{let i=M();r.exports=(e=``)=>{let r=e.match(i);if(!r)return null;let[a,o]=r[0].replace(/#! ?/,``).split(` `),s=a.split(`/`).pop();return s===`env`?o:o?`${s} ${o}`:s}}),P=h((e,r)=>{let i=v(`fs`),a=N();function o(e){let r=Buffer.alloc(150),o;try{o=i.openSync(e,`r`),i.readSync(o,r,0,150,0),i.closeSync(o)}catch{}return a(r.toString())}r.exports=o}),F=h((e,r)=>{let i=v(`path`),a=A(),o=j(),s=P(),L=process.platform===`win32`,J=/\.(?:com|exe)$/i,Y=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function X(e){e.file=a(e);let r=e.file&&s(e.file);return r?(e.args.unshift(e.file),e.command=r,a(e)):e.file}function Z(e){if(!L)return e;let r=X(e),a=!J.test(r);if(e.options.forceShell||a){let a=Y.test(r);e.command=i.normalize(e.command),e.command=o.command(e.command),e.args=e.args.map(e=>o.argument(e,a)),e.args=[`/d`,`/s`,`/c`,`"${[e.command].concat(e.args).join(` `)}"`],e.command=process.env.comspec||`cmd.exe`,e.options.windowsVerbatimArguments=!0}return e}function Q(e,r,i){r&&!Array.isArray(r)&&(i=r,r=null),r=r?r.slice(0):[],i=Object.assign({},i);let a={command:e,args:r,options:i,file:void 0,original:{command:e,args:r}};return i.shell?a:Z(a)}r.exports=Q}),I=h((e,r)=>{let i=process.platform===`win32`;function a(e,r){return Object.assign(Error(`${r} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${r} ${e.command}`,path:e.command,spawnargs:e.args})}function o(e,r){if(!i)return;let a=e.emit;e.emit=function(i,o){if(i===`exit`){let i=s(o,r,`spawn`);if(i)return a.call(e,`error`,i)}return a.apply(e,arguments)}}function s(e,r){return i&&e===1&&!r.file?a(r.original,`spawn`):null}function L(e,r){return i&&e===1&&!r.file?a(r.original,`spawnSync`):null}r.exports={hookChildProcess:o,verifyENOENT:s,verifyENOENTSync:L,notFoundError:a}}),R=_(h((e,r)=>{let i=v(`child_process`),a=F(),o=I();function s(e,r,s){let L=a(e,r,s),J=i.spawn(L.command,L.args,L.options);return o.hookChildProcess(J,L),J}function L(e,r,s){let L=a(e,r,s),J=i.spawnSync(L.command,L.args,L.options);return J.error=J.error||o.verifyENOENTSync(J.status,L),J}r.exports=s,r.exports.spawn=s,r.exports.sync=L,r.exports._parse=a,r.exports._enoent=o})(),1),z=class extends Error{result;output;get exitCode(){if(this.result.exitCode!==null)return this.result.exitCode}constructor(e,r){super(`Process exited with non-zero status (${e.exitCode})`),this.result=e,this.output=r}};const B={timeout:void 0,persist:!1},V={windowsHide:!0};function H(e,r){return{command:normalize(e),args:r??[]}}function U(e){let r=new AbortController;for(let i of e){if(i.aborted)return r.abort(),i;i.addEventListener(`abort`,()=>{r.abort(i.reason)},{signal:r.signal})}return r.signal}async function W(e){let r=``;for await(let i of e)r+=i.toString();return r}var G=class{_process;_aborted=!1;_options;_command;_args;_resolveClose;_processClosed;_thrownError;get process(){return this._process}get pid(){return this._process?.pid}get exitCode(){if(this._process&&this._process.exitCode!==null)return this._process.exitCode}constructor(e,r,i){this._options={...B,...i},this._command=e,this._args=r??[],this._processClosed=new Promise(e=>{this._resolveClose=e})}kill(e){return this._process?.kill(e)===!0}get aborted(){return this._aborted}get killed(){return this._process?.killed===!0}pipe(e,r,i){return q(e,r,{...i,stdin:this})}async*[Symbol.asyncIterator](){let e=this._process;if(!e)return;let r=[];this._streamErr&&r.push(this._streamErr),this._streamOut&&r.push(this._streamOut);let i=w(r),a=c.createInterface({input:i});for await(let e of a)yield e.toString();if(await this._processClosed,e.removeAllListeners(),this._thrownError)throw this._thrownError;if(this._options?.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new z(this)}async _waitForOutput(){let e=this._process;if(!e)throw Error(`No process was started`);let[r,i]=await Promise.all([this._streamOut?W(this._streamOut):``,this._streamErr?W(this._streamErr):``]);if(await this._processClosed,this._options?.stdin&&await this._options.stdin,e.removeAllListeners(),this._thrownError)throw this._thrownError;let a={stderr:i,stdout:r,exitCode:this.exitCode};if(this._options.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new z(this,a);return a}then(e,r){return this._waitForOutput().then(e,r)}_streamOut;_streamErr;spawn(){let e=cwd(),r=this._options,i={...V,...r.nodeOptions},a=[];this._resetState(),r.timeout!==void 0&&a.push(AbortSignal.timeout(r.timeout)),r.signal!==void 0&&a.push(r.signal),r.persist===!0&&(i.detached=!0),a.length>0&&(i.signal=U(a)),i.env=C(e,i.env);let{command:o,args:s}=H(this._command,this._args),L=(0,R._parse)(o,s,i),J=spawn(L.command,L.args,L.options);if(J.stderr&&(this._streamErr=J.stderr),J.stdout&&(this._streamOut=J.stdout),this._process=J,J.once(`error`,this._onError),J.once(`close`,this._onClose),r.stdin!==void 0&&J.stdin&&r.stdin.process){let{stdout:e}=r.stdin.process;e&&e.pipe(J.stdin)}}_resetState(){this._aborted=!1,this._processClosed=new Promise(e=>{this._resolveClose=e}),this._thrownError=void 0}_onError=e=>{if(e.name===`AbortError`&&(!(e.cause instanceof Error)||e.cause.name!==`TimeoutError`)){this._aborted=!0;return}this._thrownError=e};_onClose=()=>{this._resolveClose&&this._resolveClose()}};const K=(e,r,i)=>{let a=new G(e,r,i);return a.spawn(),a},q=K;async function findup(e,r,i={}){let a=normalize$1(e).split(`/`);for(;a.length>0;){let e=await r(a.join(`/`)||`/`);if(e||!i.includeParentDirs)return e;a.pop()}}function cached(e){let r;return()=>(r===void 0&&(r=e().then(e=>(r=e,r))),r)}const hasCorepack=cached(async()=>{if(globalThis.process?.versions?.webcontainer)return!1;try{let{exitCode:e}=await K(`corepack`,[`--version`]);return e===0}catch{return!1}});async function executeCommand(e,r,i={}){let a=e!==`npm`&&e!==`bun`&&e!==`deno`&&i.corepack!==!1&&await hasCorepack()?[`corepack`,[e,...r]]:[e,r],{exitCode:o,stdout:s,stderr:L}=await K(a[0],a[1],{nodeOptions:{cwd:resolve$1(i.cwd||process.cwd()),env:i.env,stdio:i.silent?`pipe`:`inherit`}});if(o!==0)throw Error(`\`${a.flat().join(` `)}\` failed.${i.silent?[``,s,L].join(`
2
+ `):``}`)}async function resolveOperationOptions(e={}){let r=e.cwd||process.cwd(),i={...process.env,...e.env},a=(typeof e.packageManager==`string`?packageManagers.find(r=>r.name===e.packageManager):e.packageManager)||await detectPackageManager(e.cwd||process.cwd());if(!a)throw Error(`No package manager auto-detected.`);return{cwd:r,env:i,silent:e.silent??!1,packageManager:a,dev:e.dev??!1,workspace:e.workspace,global:e.global??!1,dry:e.dry??!1,corepack:e.corepack??!0}}function parsePackageManagerField(e){let[r,i]=(e||``).split(`@`),[a,o]=i?.split(`+`)||[];if(r&&r!==`-`&&/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(r))return{name:r,version:a,buildMeta:o};let s=(r||``).replace(/\W+/g,``);return{name:s,version:a,buildMeta:o,warnings:[`Abnormal characters found in \`packageManager\` field, sanitizing from \`${r}\` to \`${s}\``]}}const packageManagers=[{name:`npm`,command:`npm`,lockFile:`package-lock.json`},{name:`pnpm`,command:`pnpm`,lockFile:`pnpm-lock.yaml`,files:[`pnpm-workspace.yaml`]},{name:`bun`,command:`bun`,lockFile:[`bun.lockb`,`bun.lock`]},{name:`yarn`,command:`yarn`,lockFile:`yarn.lock`,files:[`.yarnrc.yml`]},{name:`deno`,command:`deno`,lockFile:`deno.lock`,files:[`deno.json`]}];async function detectPackageManager(i,a={}){let o=await findup(resolve$1(i||`.`),async i=>{if(!a.ignorePackageJSON){let a=join$1(i,`package.json`);if(existsSync(a)){let r=JSON.parse(await readFile(a,`utf8`));if(r?.packageManager){let{name:e,version:i=`0.0.0`,buildMeta:a,warnings:o}=parsePackageManagerField(r.packageManager);if(e){let r=i.split(`.`)[0],s=packageManagers.find(i=>i.name===e&&i.majorVersion===r)||packageManagers.find(r=>r.name===e);return{name:e,command:e,version:i,majorVersion:r,buildMeta:a,warnings:o,files:s?.files,lockFile:s?.lockFile}}}}if(existsSync(join$1(i,`deno.json`)))return packageManagers.find(e=>e.name===`deno`)}if(!a.ignoreLockFile){for(let e of packageManagers)if([e.lockFile,e.files].flat().filter(Boolean).some(e=>existsSync(resolve$1(i,e))))return{...e}}},{includeParentDirs:a.includeParentDirs??!0});if(!o&&!a.ignoreArgv){let e=process.argv[1];if(e){for(let r of packageManagers)if(RegExp(`[/\\\\]\\.?${r.command}`).test(e))return r}}return o}async function installDependencies(e={}){let r=await resolveOperationOptions(e),i=e.frozenLockFile?{npm:[`ci`],yarn:[`install`,`--immutable`],bun:[`install`,`--frozen-lockfile`],pnpm:[`install`,`--frozen-lockfile`],deno:[`install`,`--frozen`]}[r.packageManager.name]:[`install`];return e.ignoreWorkspace&&r.packageManager.name===`pnpm`&&i.push(`--ignore-workspace`),r.dry||await executeCommand(r.packageManager.command,i,{cwd:r.cwd,silent:r.silent,corepack:r.corepack}),{exec:{command:r.packageManager.command,args:i}}}export{resolve$1 as a,relative as i,basename$1 as n,dirname$1 as r,installDependencies as t};
@@ -0,0 +1,3 @@
1
+ import{a as Minipass,i as WriteStreamSync,n as ReadStreamSync,r as WriteStream,t as ReadStream}from"./@isaacs/fs-minipass.mjs";import{a as ZstdCompress,i as Unzip,n as BrotliDecompress,o as ZstdDecompress,r as Gzip,t as BrotliCompress}from"./minizlib.mjs";import{n as chownrSync,t as chownr}from"./chownr.mjs";import fsp from"node:fs/promises";import fs from"node:fs";import{EventEmitter}from"events";import fs$1 from"fs";import path,{basename,join,posix,win32}from"node:path";import path$1,{dirname as dirname$1,parse}from"path";import assert from"node:assert";import{randomBytes}from"node:crypto";const argmap=new Map([[`C`,`cwd`],[`f`,`file`],[`z`,`gzip`],[`P`,`preservePaths`],[`U`,`unlink`],[`strip-components`,`strip`],[`stripComponents`,`strip`],[`keep-newer`,`newer`],[`keepNewer`,`newer`],[`keep-newer-files`,`newer`],[`keepNewerFiles`,`newer`],[`k`,`keep`],[`keep-existing`,`keep`],[`keepExisting`,`keep`],[`m`,`noMtime`],[`no-mtime`,`noMtime`],[`p`,`preserveOwner`],[`L`,`follow`],[`h`,`follow`],[`onentry`,`onReadEntry`]]),isSyncFile=d=>!!d.sync&&!!d.file,isAsyncFile=d=>!d.sync&&!!d.file,isSyncNoFile=d=>!!d.sync&&!d.file,isAsyncNoFile=d=>!d.sync&&!d.file,isFile=d=>!!d.file,dealiasKey=d=>argmap.get(d)||d,dealias=(d={})=>{if(!d)return{};let B={};for(let[V,H]of Object.entries(d)){let d=dealiasKey(V);B[d]=H}return B.chmod===void 0&&B.noChmod===!1&&(B.chmod=!0),delete B.noChmod,B},makeCommand=(d,B,V,H,U)=>Object.assign((W=[],G,K)=>{Array.isArray(W)&&(G=W,W={}),typeof G==`function`&&(K=G,G=void 0),G=G?Array.from(G):[];let q=dealias(W);if(U?.(q,G),isSyncFile(q)){if(typeof K==`function`)throw TypeError(`callback not supported for sync tar functions`);return d(q,G)}else if(isAsyncFile(q)){let d=B(q,G),V=K||void 0;return V?d.then(()=>V(),V):d}else if(isSyncNoFile(q)){if(typeof K==`function`)throw TypeError(`callback not supported for sync tar functions`);return V(q,G)}else if(isAsyncNoFile(q)){if(typeof K==`function`)throw TypeError(`callback only supported with file option`);return H(q,G)}else throw Error(`impossible options??`)},{syncFile:d,asyncFile:B,syncNoFile:V,asyncNoFile:H,validate:U}),encode$1=(d,B)=>{if(Number.isSafeInteger(d))d<0?encodeNegative(d,B):encodePositive(d,B);else throw Error(`cannot encode number outside of javascript safe integer range`);return B},encodePositive=(d,B)=>{B[0]=128;for(var V=B.length;V>1;V--)B[V-1]=d&255,d=Math.floor(d/256)},encodeNegative=(d,B)=>{B[0]=255;var V=!1;d*=-1;for(var H=B.length;H>1;H--){var U=d&255;d=Math.floor(d/256),V?B[H-1]=onesComp(U):U===0?B[H-1]=0:(V=!0,B[H-1]=twosComp(U))}},parse$2=d=>{let B=d[0],V=B===128?pos(d.subarray(1,d.length)):B===255?twos(d):null;if(V===null)throw Error(`invalid base256 encoding`);if(!Number.isSafeInteger(V))throw Error(`parsed number outside of javascript safe integer range`);return V},twos=d=>{for(var B=d.length,V=0,H=!1,U=B-1;U>-1;U--){var W=Number(d[U]),G;H?G=onesComp(W):W===0?G=W:(H=!0,G=twosComp(W)),G!==0&&(V-=G*256**(B-U-1))}return V},pos=d=>{for(var B=d.length,V=0,H=B-1;H>-1;H--){var U=Number(d[H]);U!==0&&(V+=U*256**(B-H-1))}return V},onesComp=d=>(255^d)&255,twosComp=d=>(255^d)+1&255,isCode=d=>name.has(d),name=new Map([[`0`,`File`],[``,`OldFile`],[`1`,`Link`],[`2`,`SymbolicLink`],[`3`,`CharacterDevice`],[`4`,`BlockDevice`],[`5`,`Directory`],[`6`,`FIFO`],[`7`,`ContiguousFile`],[`g`,`GlobalExtendedHeader`],[`x`,`ExtendedHeader`],[`A`,`SolarisACL`],[`D`,`GNUDumpDir`],[`I`,`Inode`],[`K`,`NextFileHasLongLinkpath`],[`L`,`NextFileHasLongPath`],[`M`,`ContinuationFile`],[`N`,`OldGnuLongPath`],[`S`,`SparseFile`],[`V`,`TapeVolumeHeader`],[`X`,`OldExtendedHeader`]]),code=new Map(Array.from(name).map(d=>[d[1],d[0]]));var Header=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#type=`Unsupported`;linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(d,B=0,V,H){Buffer.isBuffer(d)?this.decode(d,B||0,V,H):d&&this.#slurp(d)}decode(d,B,V,H){if(B||=0,!d||!(d.length>=B+512))throw Error(`need 512 bytes for header`);this.path=V?.path??decString(d,B,100),this.mode=V?.mode??H?.mode??decNumber(d,B+100,8),this.uid=V?.uid??H?.uid??decNumber(d,B+108,8),this.gid=V?.gid??H?.gid??decNumber(d,B+116,8),this.size=V?.size??H?.size??decNumber(d,B+124,12),this.mtime=V?.mtime??H?.mtime??decDate(d,B+136,12),this.cksum=decNumber(d,B+148,12),H&&this.#slurp(H,!0),V&&this.#slurp(V);let U=decString(d,B+156,1);if(isCode(U)&&(this.#type=U||`0`),this.#type===`0`&&this.path.slice(-1)===`/`&&(this.#type=`5`),this.#type===`5`&&(this.size=0),this.linkpath=decString(d,B+157,100),d.subarray(B+257,B+265).toString()===`ustar\x0000`)if(this.uname=V?.uname??H?.uname??decString(d,B+265,32),this.gname=V?.gname??H?.gname??decString(d,B+297,32),this.devmaj=V?.devmaj??H?.devmaj??decNumber(d,B+329,8)??0,this.devmin=V?.devmin??H?.devmin??decNumber(d,B+337,8)??0,d[B+475]!==0)this.path=decString(d,B+345,155)+`/`+this.path;else{let U=decString(d,B+345,130);U&&(this.path=U+`/`+this.path),this.atime=V?.atime??H?.atime??decDate(d,B+476,12),this.ctime=V?.ctime??H?.ctime??decDate(d,B+488,12)}let W=256;for(let V=B;V<B+148;V++)W+=d[V];for(let V=B+156;V<B+512;V++)W+=d[V];this.cksumValid=W===this.cksum,this.cksum===void 0&&W===256&&(this.nullBlock=!0)}#slurp(d,B=!1){Object.assign(this,Object.fromEntries(Object.entries(d).filter(([d,V])=>!(V==null||d===`path`&&B||d===`linkpath`&&B||d===`global`))))}encode(d,B=0){if(d||=this.block=Buffer.alloc(512),this.#type===`Unsupported`&&(this.#type=`0`),!(d.length>=B+512))throw Error(`need 512 bytes for header`);let V=this.ctime||this.atime?130:155,H=splitPrefix(this.path||``,V),U=H[0],W=H[1];this.needPax=!!H[2],this.needPax=encString(d,B,100,U)||this.needPax,this.needPax=encNumber(d,B+100,8,this.mode)||this.needPax,this.needPax=encNumber(d,B+108,8,this.uid)||this.needPax,this.needPax=encNumber(d,B+116,8,this.gid)||this.needPax,this.needPax=encNumber(d,B+124,12,this.size)||this.needPax,this.needPax=encDate(d,B+136,12,this.mtime)||this.needPax,d[B+156]=this.#type.charCodeAt(0),this.needPax=encString(d,B+157,100,this.linkpath)||this.needPax,d.write(`ustar\x0000`,B+257,8),this.needPax=encString(d,B+265,32,this.uname)||this.needPax,this.needPax=encString(d,B+297,32,this.gname)||this.needPax,this.needPax=encNumber(d,B+329,8,this.devmaj)||this.needPax,this.needPax=encNumber(d,B+337,8,this.devmin)||this.needPax,this.needPax=encString(d,B+345,V,W)||this.needPax,d[B+475]===0?(this.needPax=encString(d,B+345,130,W)||this.needPax,this.needPax=encDate(d,B+476,12,this.atime)||this.needPax,this.needPax=encDate(d,B+488,12,this.ctime)||this.needPax):this.needPax=encString(d,B+345,155,W)||this.needPax;let G=256;for(let V=B;V<B+148;V++)G+=d[V];for(let V=B+156;V<B+512;V++)G+=d[V];return this.cksum=G,encNumber(d,B+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#type===`Unsupported`?this.#type:name.get(this.#type)}get typeKey(){return this.#type}set type(d){let B=String(code.get(d));if(isCode(B)||B===`Unsupported`)this.#type=B;else if(isCode(d))this.#type=d;else throw TypeError(`invalid entry type: `+d)}};const splitPrefix=(d,B)=>{let V=d,H=``,U,W=posix.parse(d).root||`.`;if(Buffer.byteLength(V)<100)U=[V,H,!1];else{H=posix.dirname(V),V=posix.basename(V);do Buffer.byteLength(V)<=100&&Buffer.byteLength(H)<=B?U=[V,H,!1]:Buffer.byteLength(V)>100&&Buffer.byteLength(H)<=B?U=[V.slice(0,99),H,!0]:(V=posix.join(posix.basename(H),V),H=posix.dirname(H));while(H!==W&&U===void 0);U||=[d.slice(0,99),``,!0]}return U},decString=(d,B,V)=>d.subarray(B,B+V).toString(`utf8`).replace(/\0.*/,``),decDate=(d,B,V)=>numToDate(decNumber(d,B,V)),numToDate=d=>d===void 0?void 0:new Date(d*1e3),decNumber=(d,B,V)=>Number(d[B])&128?parse$2(d.subarray(B,B+V)):decSmallNumber(d,B,V),nanUndef=d=>isNaN(d)?void 0:d,decSmallNumber=(d,B,V)=>nanUndef(parseInt(d.subarray(B,B+V).toString(`utf8`).replace(/\0.*$/,``).trim(),8)),MAXNUM={12:8589934591,8:2097151},encNumber=(d,B,V,H)=>H===void 0?!1:H>MAXNUM[V]||H<0?(encode$1(H,d.subarray(B,B+V)),!0):(encSmallNumber(d,B,V,H),!1),encSmallNumber=(d,B,V,H)=>d.write(octalString(H,V),B,V,`ascii`),octalString=(d,B)=>padOctal(Math.floor(d).toString(8),B),padOctal=(d,B)=>(d.length===B-1?d:Array(B-d.length-1).join(`0`)+d+` `)+`\0`,encDate=(d,B,V,H)=>H===void 0?!1:encNumber(d,B,V,H.getTime()/1e3),NULLS=Array(156).join(`\0`),encString=(d,B,V,H)=>H===void 0?!1:(d.write(H+NULLS,B,V,`utf8`),H.length!==Buffer.byteLength(H)||H.length>V);var Pax=class d{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(d,B=!1){this.atime=d.atime,this.charset=d.charset,this.comment=d.comment,this.ctime=d.ctime,this.dev=d.dev,this.gid=d.gid,this.global=B,this.gname=d.gname,this.ino=d.ino,this.linkpath=d.linkpath,this.mtime=d.mtime,this.nlink=d.nlink,this.path=d.path,this.size=d.size,this.uid=d.uid,this.uname=d.uname}encode(){let d=this.encodeBody();if(d===``)return Buffer.allocUnsafe(0);let B=Buffer.byteLength(d),V=512*Math.ceil(1+B/512),H=Buffer.allocUnsafe(V);for(let d=0;d<512;d++)H[d]=0;new Header({path:(`PaxHeader/`+basename(this.path??``)).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:B,mtime:this.mtime,type:this.global?`GlobalExtendedHeader`:`ExtendedHeader`,linkpath:``,uname:this.uname||``,gname:this.gname||``,devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(H),H.write(d,512,B,`utf8`);for(let d=B+512;d<H.length;d++)H[d]=0;return H}encodeBody(){return this.encodeField(`path`)+this.encodeField(`ctime`)+this.encodeField(`atime`)+this.encodeField(`dev`)+this.encodeField(`ino`)+this.encodeField(`nlink`)+this.encodeField(`charset`)+this.encodeField(`comment`)+this.encodeField(`gid`)+this.encodeField(`gname`)+this.encodeField(`linkpath`)+this.encodeField(`mtime`)+this.encodeField(`size`)+this.encodeField(`uid`)+this.encodeField(`uname`)}encodeField(d){if(this[d]===void 0)return``;let B=this[d],V=B instanceof Date?B.getTime()/1e3:B,H=` `+(d===`dev`||d===`ino`||d===`nlink`?`SCHILY.`:``)+d+`=`+V+`
2
+ `,U=Buffer.byteLength(H),W=Math.floor(Math.log(U)/Math.log(10))+1;return U+W>=10**W&&(W+=1),W+U+H}static parse(B,V,H=!1){return new d(merge(parseKV(B),V),H)}};const merge=(d,B)=>B?Object.assign({},B,d):d,parseKV=d=>d.replace(/\n$/,``).split(`
3
+ `).reduce(parseKVLine,Object.create(null)),parseKVLine=(d,B)=>{let V=parseInt(B,10);if(V!==Buffer.byteLength(B)+1)return d;B=B.slice((V+` `).length);let H=B.split(`=`),U=H.shift();if(!U)return d;let W=U.replace(/^SCHILY\.(dev|ino|nlink)/,`$1`),G=H.join(`=`);return d[W]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(W)?new Date(Number(G)*1e3):/^[0-9]+$/.test(G)?+G:G,d},normalizeWindowsPath=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`?d=>d&&d.replace(/\\/g,`/`):d=>d;var ReadEntry=class extends Minipass{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(d,B,V){switch(super({}),this.pause(),this.extended=B,this.globalExtended=V,this.header=d,this.remain=d.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=d.type,this.type){case`File`:case`OldFile`:case`Link`:case`SymbolicLink`:case`CharacterDevice`:case`BlockDevice`:case`Directory`:case`FIFO`:case`ContiguousFile`:case`GNUDumpDir`:break;case`NextFileHasLongLinkpath`:case`NextFileHasLongPath`:case`OldGnuLongPath`:case`GlobalExtendedHeader`:case`ExtendedHeader`:case`OldExtendedHeader`:this.meta=!0;break;default:this.ignore=!0}if(!d.path)throw Error(`no path provided for tar.ReadEntry`);this.path=normalizeWindowsPath(d.path),this.mode=d.mode,this.mode&&(this.mode&=4095),this.uid=d.uid,this.gid=d.gid,this.uname=d.uname,this.gname=d.gname,this.size=this.remain,this.mtime=d.mtime,this.atime=d.atime,this.ctime=d.ctime,this.linkpath=d.linkpath?normalizeWindowsPath(d.linkpath):void 0,this.uname=d.uname,this.gname=d.gname,B&&this.#slurp(B),V&&this.#slurp(V,!0)}write(d){let B=d.length;if(B>this.blockRemain)throw Error(`writing more to entry than is appropriate`);let V=this.remain,H=this.blockRemain;return this.remain=Math.max(0,V-B),this.blockRemain=Math.max(0,H-B),this.ignore?!0:V>=B?super.write(d):super.write(d.subarray(0,V))}#slurp(d,B=!1){d.path&&=normalizeWindowsPath(d.path),d.linkpath&&=normalizeWindowsPath(d.linkpath),Object.assign(this,Object.fromEntries(Object.entries(d).filter(([d,V])=>!(V==null||d===`path`&&B))))}};const warnMethod=(d,B,V,H={})=>{d.file&&(H.file=d.file),d.cwd&&(H.cwd=d.cwd),H.code=V instanceof Error&&V.code||B,H.tarCode=B,!d.strict&&H.recoverable!==!1?(V instanceof Error&&(H=Object.assign(V,H),V=V.message),d.emit(`warn`,B,V,H)):V instanceof Error?d.emit(`error`,Object.assign(V,H)):d.emit(`error`,Object.assign(Error(`${B}: ${V}`),H))},gzipHeader=Buffer.from([31,139]),zstdHeader=Buffer.from([40,181,47,253]),ZIP_HEADER_LEN=Math.max(gzipHeader.length,zstdHeader.length),STATE=Symbol(`state`),WRITEENTRY=Symbol(`writeEntry`),READENTRY=Symbol(`readEntry`),NEXTENTRY=Symbol(`nextEntry`),PROCESSENTRY=Symbol(`processEntry`),EX=Symbol(`extendedHeader`),GEX=Symbol(`globalExtendedHeader`),META=Symbol(`meta`),EMITMETA=Symbol(`emitMeta`),BUFFER=Symbol(`buffer`),QUEUE$1=Symbol(`queue`),ENDED$2=Symbol(`ended`),EMITTEDEND=Symbol(`emittedEnd`),EMIT=Symbol(`emit`),UNZIP=Symbol(`unzip`),CONSUMECHUNK=Symbol(`consumeChunk`),CONSUMECHUNKSUB=Symbol(`consumeChunkSub`),CONSUMEBODY=Symbol(`consumeBody`),CONSUMEMETA=Symbol(`consumeMeta`),CONSUMEHEADER=Symbol(`consumeHeader`),CONSUMING=Symbol(`consuming`),BUFFERCONCAT=Symbol(`bufferConcat`),MAYBEEND=Symbol(`maybeEnd`),WRITING=Symbol(`writing`),ABORTED=Symbol(`aborted`),DONE=Symbol(`onDone`),SAW_VALID_ENTRY=Symbol(`sawValidEntry`),SAW_NULL_BLOCK=Symbol(`sawNullBlock`),SAW_EOF=Symbol(`sawEOF`),CLOSESTREAM=Symbol(`closeStream`),noop=()=>!0;var Parser=class extends EventEmitter{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[QUEUE$1]=[];[BUFFER];[READENTRY];[WRITEENTRY];[STATE]=`begin`;[META]=``;[EX];[GEX];[ENDED$2]=!1;[UNZIP];[ABORTED]=!1;[SAW_VALID_ENTRY];[SAW_NULL_BLOCK]=!1;[SAW_EOF]=!1;[WRITING]=!1;[CONSUMING]=!1;[EMITTEDEND]=!1;constructor(d={}){super(),this.file=d.file||``,this.on(DONE,()=>{(this[STATE]===`begin`||this[SAW_VALID_ENTRY]===!1)&&this.warn(`TAR_BAD_ARCHIVE`,`Unrecognized archive format`)}),d.ondone?this.on(DONE,d.ondone):this.on(DONE,()=>{this.emit(`prefinish`),this.emit(`finish`),this.emit(`end`)}),this.strict=!!d.strict,this.maxMetaEntrySize=d.maxMetaEntrySize||1048576,this.filter=typeof d.filter==`function`?d.filter:noop;let B=d.file&&(d.file.endsWith(`.tar.br`)||d.file.endsWith(`.tbr`));this.brotli=!(d.gzip||d.zstd)&&d.brotli!==void 0?d.brotli:B?void 0:!1;let V=d.file&&(d.file.endsWith(`.tar.zst`)||d.file.endsWith(`.tzst`));this.zstd=!(d.gzip||d.brotli)&&d.zstd!==void 0?d.zstd:V?!0:void 0,this.on(`end`,()=>this[CLOSESTREAM]()),typeof d.onwarn==`function`&&this.on(`warn`,d.onwarn),typeof d.onReadEntry==`function`&&this.on(`entry`,d.onReadEntry)}warn(d,B,V={}){warnMethod(this,d,B,V)}[CONSUMEHEADER](d,B){this[SAW_VALID_ENTRY]===void 0&&(this[SAW_VALID_ENTRY]=!1);let V;try{V=new Header(d,B,this[EX],this[GEX])}catch(d){return this.warn(`TAR_ENTRY_INVALID`,d)}if(V.nullBlock)this[SAW_NULL_BLOCK]?(this[SAW_EOF]=!0,this[STATE]===`begin`&&(this[STATE]=`header`),this[EMIT](`eof`)):(this[SAW_NULL_BLOCK]=!0,this[EMIT](`nullBlock`));else if(this[SAW_NULL_BLOCK]=!1,!V.cksumValid)this.warn(`TAR_ENTRY_INVALID`,`checksum failure`,{header:V});else if(!V.path)this.warn(`TAR_ENTRY_INVALID`,`path is required`,{header:V});else{let d=V.type;if(/^(Symbolic)?Link$/.test(d)&&!V.linkpath)this.warn(`TAR_ENTRY_INVALID`,`linkpath required`,{header:V});else if(!/^(Symbolic)?Link$/.test(d)&&!/^(Global)?ExtendedHeader$/.test(d)&&V.linkpath)this.warn(`TAR_ENTRY_INVALID`,`linkpath forbidden`,{header:V});else{let d=this[WRITEENTRY]=new ReadEntry(V,this[EX],this[GEX]);this[SAW_VALID_ENTRY]||(d.remain?d.on(`end`,()=>{d.invalid||(this[SAW_VALID_ENTRY]=!0)}):this[SAW_VALID_ENTRY]=!0),d.meta?d.size>this.maxMetaEntrySize?(d.ignore=!0,this[EMIT](`ignoredEntry`,d),this[STATE]=`ignore`,d.resume()):d.size>0&&(this[META]=``,d.on(`data`,d=>this[META]+=d),this[STATE]=`meta`):(this[EX]=void 0,d.ignore=d.ignore||!this.filter(d.path,d),d.ignore?(this[EMIT](`ignoredEntry`,d),this[STATE]=d.remain?`ignore`:`header`,d.resume()):(d.remain?this[STATE]=`body`:(this[STATE]=`header`,d.end()),this[READENTRY]?this[QUEUE$1].push(d):(this[QUEUE$1].push(d),this[NEXTENTRY]())))}}}[CLOSESTREAM](){queueMicrotask(()=>this.emit(`close`))}[PROCESSENTRY](d){let B=!0;if(!d)this[READENTRY]=void 0,B=!1;else if(Array.isArray(d)){let[B,...V]=d;this.emit(B,...V)}else this[READENTRY]=d,this.emit(`entry`,d),d.emittedEnd||(d.on(`end`,()=>this[NEXTENTRY]()),B=!1);return B}[NEXTENTRY](){do;while(this[PROCESSENTRY](this[QUEUE$1].shift()));if(!this[QUEUE$1].length){let d=this[READENTRY];!d||d.flowing||d.size===d.remain?this[WRITING]||this.emit(`drain`):d.once(`drain`,()=>this.emit(`drain`))}}[CONSUMEBODY](d,B){let V=this[WRITEENTRY];if(!V)throw Error(`attempt to consume body without entry??`);let H=V.blockRemain??0,U=H>=d.length&&B===0?d:d.subarray(B,B+H);return V.write(U),V.blockRemain||(this[STATE]=`header`,this[WRITEENTRY]=void 0,V.end()),U.length}[CONSUMEMETA](d,B){let V=this[WRITEENTRY],H=this[CONSUMEBODY](d,B);return!this[WRITEENTRY]&&V&&this[EMITMETA](V),H}[EMIT](d,B,V){!this[QUEUE$1].length&&!this[READENTRY]?this.emit(d,B,V):this[QUEUE$1].push([d,B,V])}[EMITMETA](d){switch(this[EMIT](`meta`,this[META]),d.type){case`ExtendedHeader`:case`OldExtendedHeader`:this[EX]=Pax.parse(this[META],this[EX],!1);break;case`GlobalExtendedHeader`:this[GEX]=Pax.parse(this[META],this[GEX],!0);break;case`NextFileHasLongPath`:case`OldGnuLongPath`:{let d=this[EX]??Object.create(null);this[EX]=d,d.path=this[META].replace(/\0.*/,``);break}case`NextFileHasLongLinkpath`:{let d=this[EX]||Object.create(null);this[EX]=d,d.linkpath=this[META].replace(/\0.*/,``);break}default:throw Error(`unknown meta: `+d.type)}}abort(d){this[ABORTED]=!0,this.emit(`abort`,d),this.warn(`TAR_ABORT`,d,{recoverable:!1})}write(d,B,V){if(typeof B==`function`&&(V=B,B=void 0),typeof d==`string`&&(d=Buffer.from(d,typeof B==`string`?B:`utf8`)),this[ABORTED])return V?.(),!1;if((this[UNZIP]===void 0||this.brotli===void 0&&this[UNZIP]===!1)&&d){if(this[BUFFER]&&(d=Buffer.concat([this[BUFFER],d]),this[BUFFER]=void 0),d.length<ZIP_HEADER_LEN)return this[BUFFER]=d,V?.(),!0;for(let B=0;this[UNZIP]===void 0&&B<gzipHeader.length;B++)d[B]!==gzipHeader[B]&&(this[UNZIP]=!1);let B=!1;if(this[UNZIP]===!1&&this.zstd!==!1){B=!0;for(let V=0;V<zstdHeader.length;V++)if(d[V]!==zstdHeader[V]){B=!1;break}}let H=this.brotli===void 0&&!B;if(this[UNZIP]===!1&&H)if(d.length<512)if(this[ENDED$2])this.brotli=!0;else return this[BUFFER]=d,V?.(),!0;else try{new Header(d.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[UNZIP]===void 0||this[UNZIP]===!1&&(this.brotli||B)){let H=this[ENDED$2];this[ENDED$2]=!1,this[UNZIP]=this[UNZIP]===void 0?new Unzip({}):B?new ZstdDecompress({}):new BrotliDecompress({}),this[UNZIP].on(`data`,d=>this[CONSUMECHUNK](d)),this[UNZIP].on(`error`,d=>this.abort(d)),this[UNZIP].on(`end`,()=>{this[ENDED$2]=!0,this[CONSUMECHUNK]()}),this[WRITING]=!0;let U=!!this[UNZIP][H?`end`:`write`](d);return this[WRITING]=!1,V?.(),U}}this[WRITING]=!0,this[UNZIP]?this[UNZIP].write(d):this[CONSUMECHUNK](d),this[WRITING]=!1;let H=this[QUEUE$1].length?!1:this[READENTRY]?this[READENTRY].flowing:!0;return!H&&!this[QUEUE$1].length&&this[READENTRY]?.once(`drain`,()=>this.emit(`drain`)),V?.(),H}[BUFFERCONCAT](d){d&&!this[ABORTED]&&(this[BUFFER]=this[BUFFER]?Buffer.concat([this[BUFFER],d]):d)}[MAYBEEND](){if(this[ENDED$2]&&!this[EMITTEDEND]&&!this[ABORTED]&&!this[CONSUMING]){this[EMITTEDEND]=!0;let d=this[WRITEENTRY];if(d&&d.blockRemain){let B=this[BUFFER]?this[BUFFER].length:0;this.warn(`TAR_BAD_ARCHIVE`,`Truncated input (needed ${d.blockRemain} more bytes, only ${B} available)`,{entry:d}),this[BUFFER]&&d.write(this[BUFFER]),d.end()}this[EMIT](DONE)}}[CONSUMECHUNK](d){if(this[CONSUMING]&&d)this[BUFFERCONCAT](d);else if(!d&&!this[BUFFER])this[MAYBEEND]();else if(d){if(this[CONSUMING]=!0,this[BUFFER]){this[BUFFERCONCAT](d);let B=this[BUFFER];this[BUFFER]=void 0,this[CONSUMECHUNKSUB](B)}else this[CONSUMECHUNKSUB](d);for(;this[BUFFER]&&this[BUFFER]?.length>=512&&!this[ABORTED]&&!this[SAW_EOF];){let d=this[BUFFER];this[BUFFER]=void 0,this[CONSUMECHUNKSUB](d)}this[CONSUMING]=!1}(!this[BUFFER]||this[ENDED$2])&&this[MAYBEEND]()}[CONSUMECHUNKSUB](d){let B=0,V=d.length;for(;B+512<=V&&!this[ABORTED]&&!this[SAW_EOF];)switch(this[STATE]){case`begin`:case`header`:this[CONSUMEHEADER](d,B),B+=512;break;case`ignore`:case`body`:B+=this[CONSUMEBODY](d,B);break;case`meta`:B+=this[CONSUMEMETA](d,B);break;default:throw Error(`invalid state: `+this[STATE])}B<V&&(this[BUFFER]?this[BUFFER]=Buffer.concat([d.subarray(B),this[BUFFER]]):this[BUFFER]=d.subarray(B))}end(d,B,V){return typeof d==`function`&&(V=d,B=void 0,d=void 0),typeof B==`function`&&(V=B,B=void 0),typeof d==`string`&&(d=Buffer.from(d,B)),V&&this.once(`finish`,V),this[ABORTED]||(this[UNZIP]?(d&&this[UNZIP].write(d),this[UNZIP].end()):(this[ENDED$2]=!0,(this.brotli===void 0||this.zstd===void 0)&&(d||=Buffer.alloc(0)),d&&this.write(d),this[MAYBEEND]())),this}};const stripTrailingSlashes=d=>{let B=d.length-1,V=-1;for(;B>-1&&d.charAt(B)===`/`;)V=B,B--;return V===-1?d:d.slice(0,V)},onReadEntryFunction=d=>{let B=d.onReadEntry;d.onReadEntry=B?d=>{B(d),d.resume()}:d=>d.resume()},filesFilter=(d,B)=>{let V=new Map(B.map(d=>[stripTrailingSlashes(d),!0])),H=d.filter,U=(d,B=``)=>{let H=B||parse(d).root||`.`,W;if(d===H)W=!1;else{let B=V.get(d);W=B===void 0?U(dirname$1(d),H):B}return V.set(d,W),W};d.filter=H?(d,B)=>H(d,B)&&U(stripTrailingSlashes(d)):d=>U(stripTrailingSlashes(d))},list=makeCommand(d=>{let B=new Parser(d),V=d.file,H;try{H=fs.openSync(V,`r`);let U=fs.fstatSync(H),W=d.maxReadSize||16*1024*1024;if(U.size<W){let d=Buffer.allocUnsafe(U.size),V=fs.readSync(H,d,0,U.size,0);B.end(V===d.byteLength?d:d.subarray(0,V))}else{let d=0,V=Buffer.allocUnsafe(W);for(;d<U.size;){let U=fs.readSync(H,V,0,W,d);if(U===0)break;d+=U,B.write(V.subarray(0,U))}B.end()}}finally{if(typeof H==`number`)try{fs.closeSync(H)}catch{}}},(d,B)=>{let V=new Parser(d),H=d.maxReadSize||16*1024*1024,W=d.file;return new Promise((d,B)=>{V.on(`error`,B),V.on(`end`,d),fs.stat(W,(d,G)=>{if(d)B(d);else{let d=new ReadStream(W,{readSize:H,size:G.size});d.on(`error`,B),d.pipe(V)}})})},d=>new Parser(d),d=>new Parser(d),(d,B)=>{B?.length&&filesFilter(d,B),d.noResume||onReadEntryFunction(d)}),modeFix=(d,B,V)=>(d&=4095,V&&(d=(d|384)&-19),B&&(d&256&&(d|=64),d&32&&(d|=8),d&4&&(d|=1)),d),{isAbsolute,parse:parse$1}=win32,stripAbsolutePath=d=>{let B=``,V=parse$1(d);for(;isAbsolute(d)||V.root;){let H=d.charAt(0)===`/`&&d.slice(0,4)!==`//?/`?`/`:V.root;d=d.slice(H.length),B+=H,V=parse$1(d)}return[B,d]},raw=[`|`,`<`,`>`,`?`,`:`],win=raw.map(d=>String.fromCharCode(61440+d.charCodeAt(0))),toWin=new Map(raw.map((d,B)=>[d,win[B]])),toRaw=new Map(win.map((d,B)=>[d,raw[B]])),encode=d=>raw.reduce((d,B)=>d.split(B).join(toWin.get(B)),d),decode=d=>win.reduce((d,B)=>d.split(B).join(toRaw.get(B)),d),prefixPath=(d,B)=>B?(d=normalizeWindowsPath(d).replace(/^\.(\/|$)/,``),stripTrailingSlashes(B)+`/`+d):normalizeWindowsPath(d),PROCESS$1=Symbol(`process`),FILE$1=Symbol(`file`),DIRECTORY$1=Symbol(`directory`),SYMLINK$1=Symbol(`symlink`),HARDLINK$1=Symbol(`hardlink`),HEADER=Symbol(`header`),READ=Symbol(`read`),LSTAT=Symbol(`lstat`),ONLSTAT=Symbol(`onlstat`),ONREAD=Symbol(`onread`),ONREADLINK=Symbol(`onreadlink`),OPENFILE=Symbol(`openfile`),ONOPENFILE=Symbol(`onopenfile`),CLOSE=Symbol(`close`),MODE=Symbol(`mode`),AWAITDRAIN=Symbol(`awaitDrain`),ONDRAIN$1=Symbol(`ondrain`),PREFIX=Symbol(`prefix`);var WriteEntry=class extends Minipass{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||``;maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#hadError=!1;constructor(d,B={}){let V=dealias(B);super(),this.path=normalizeWindowsPath(d),this.portable=!!V.portable,this.maxReadSize=V.maxReadSize||16777216,this.linkCache=V.linkCache||new Map,this.statCache=V.statCache||new Map,this.preservePaths=!!V.preservePaths,this.cwd=normalizeWindowsPath(V.cwd||process.cwd()),this.strict=!!V.strict,this.noPax=!!V.noPax,this.noMtime=!!V.noMtime,this.mtime=V.mtime,this.prefix=V.prefix?normalizeWindowsPath(V.prefix):void 0,this.onWriteEntry=V.onWriteEntry,typeof V.onwarn==`function`&&this.on(`warn`,V.onwarn);let H=!1;if(!this.preservePaths){let[d,B]=stripAbsolutePath(this.path);d&&typeof B==`string`&&(this.path=B,H=d)}this.win32=!!V.win32||process.platform===`win32`,this.win32&&(this.path=decode(this.path.replace(/\\/g,`/`)),d=d.replace(/\\/g,`/`)),this.absolute=normalizeWindowsPath(V.absolute||path$1.resolve(this.cwd,d)),this.path===``&&(this.path=`./`),H&&this.warn(`TAR_ENTRY_INFO`,`stripping ${H} from absolute path`,{entry:this,path:H+this.path});let U=this.statCache.get(this.absolute);U?this[ONLSTAT](U):this[LSTAT]()}warn(d,B,V={}){return warnMethod(this,d,B,V)}emit(d,...B){return d===`error`&&(this.#hadError=!0),super.emit(d,...B)}[LSTAT](){fs$1.lstat(this.absolute,(d,B)=>{if(d)return this.emit(`error`,d);this[ONLSTAT](B)})}[ONLSTAT](d){this.statCache.set(this.absolute,d),this.stat=d,d.isFile()||(d.size=0),this.type=getType(d),this.emit(`stat`,d),this[PROCESS$1]()}[PROCESS$1](){switch(this.type){case`File`:return this[FILE$1]();case`Directory`:return this[DIRECTORY$1]();case`SymbolicLink`:return this[SYMLINK$1]();default:return this.end()}}[MODE](d){return modeFix(d,this.type===`Directory`,this.portable)}[PREFIX](d){return prefixPath(d,this.prefix)}[HEADER](){if(!this.stat)throw Error(`cannot write header before stat`);this.type===`Directory`&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Header({path:this[PREFIX](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[PREFIX](this.linkpath):this.linkpath,mode:this[MODE](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type===`Unsupported`?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:``,atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Pax({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[PREFIX](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[PREFIX](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let d=this.header?.block;if(!d)throw Error(`failed to encode header`);super.write(d)}[DIRECTORY$1](){if(!this.stat)throw Error(`cannot create directory entry without stat`);this.path.slice(-1)!==`/`&&(this.path+=`/`),this.stat.size=0,this[HEADER](),this.end()}[SYMLINK$1](){fs$1.readlink(this.absolute,(d,B)=>{if(d)return this.emit(`error`,d);this[ONREADLINK](B)})}[ONREADLINK](d){this.linkpath=normalizeWindowsPath(d),this[HEADER](),this.end()}[HARDLINK$1](d){if(!this.stat)throw Error(`cannot create link entry without stat`);this.type=`Link`,this.linkpath=normalizeWindowsPath(path$1.relative(this.cwd,d)),this.stat.size=0,this[HEADER](),this.end()}[FILE$1](){if(!this.stat)throw Error(`cannot create file entry without stat`);if(this.stat.nlink>1){let d=`${this.stat.dev}:${this.stat.ino}`,B=this.linkCache.get(d);if(B?.indexOf(this.cwd)===0)return this[HARDLINK$1](B);this.linkCache.set(d,this.absolute)}if(this[HEADER](),this.stat.size===0)return this.end();this[OPENFILE]()}[OPENFILE](){fs$1.open(this.absolute,`r`,(d,B)=>{if(d)return this.emit(`error`,d);this[ONOPENFILE](B)})}[ONOPENFILE](d){if(this.fd=d,this.#hadError)return this[CLOSE]();if(!this.stat)throw Error(`should stat before calling onopenfile`);this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let B=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(B),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[READ]()}[READ](){let{fd:d,buf:B,offset:V,length:H,pos:U}=this;if(d===void 0||B===void 0)throw Error(`cannot read file without first opening`);fs$1.read(d,B,V,H,U,(d,B)=>{if(d)return this[CLOSE](()=>this.emit(`error`,d));this[ONREAD](B)})}[CLOSE](d=()=>{}){this.fd!==void 0&&fs$1.close(this.fd,d)}[ONREAD](d){if(d<=0&&this.remain>0){let d=Object.assign(Error(`encountered unexpected EOF`),{path:this.absolute,syscall:`read`,code:`EOF`});return this[CLOSE](()=>this.emit(`error`,d))}if(d>this.remain){let d=Object.assign(Error(`did not encounter expected EOF`),{path:this.absolute,syscall:`read`,code:`EOF`});return this[CLOSE](()=>this.emit(`error`,d))}if(!this.buf)throw Error(`should have created buffer prior to reading`);if(d===this.remain)for(let B=d;B<this.length&&d<this.blockRemain;B++)this.buf[B+this.offset]=0,d++,this.remain++;let B=this.offset===0&&d===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+d);this.write(B)?this[ONDRAIN$1]():this[AWAITDRAIN](()=>this[ONDRAIN$1]())}[AWAITDRAIN](d){this.once(`drain`,d)}write(d,B,V){if(typeof B==`function`&&(V=B,B=void 0),typeof d==`string`&&(d=Buffer.from(d,typeof B==`string`?B:`utf8`)),this.blockRemain<d.length){let d=Object.assign(Error(`writing more data than expected`),{path:this.absolute});return this.emit(`error`,d)}return this.remain-=d.length,this.blockRemain-=d.length,this.pos+=d.length,this.offset+=d.length,super.write(d,null,V)}[ONDRAIN$1](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[CLOSE](d=>d?this.emit(`error`,d):this.end());if(!this.buf)throw Error(`buffer lost somehow in ONDRAIN`);this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[READ]()}},WriteEntrySync=class extends WriteEntry{sync=!0;[LSTAT](){this[ONLSTAT](fs$1.lstatSync(this.absolute))}[SYMLINK$1](){this[ONREADLINK](fs$1.readlinkSync(this.absolute))}[OPENFILE](){this[ONOPENFILE](fs$1.openSync(this.absolute,`r`))}[READ](){let d=!0;try{let{fd:B,buf:V,offset:H,length:U,pos:W}=this;if(B===void 0||V===void 0)throw Error(`fd and buf must be set in READ method`);let G=fs$1.readSync(B,V,H,U,W);this[ONREAD](G),d=!1}finally{if(d)try{this[CLOSE](()=>{})}catch{}}}[AWAITDRAIN](d){d()}[CLOSE](d=()=>{}){this.fd!==void 0&&fs$1.closeSync(this.fd),d()}},WriteEntryTar=class extends Minipass{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(d,B,V={}){return warnMethod(this,d,B,V)}constructor(d,B={}){let V=dealias(B);super(),this.preservePaths=!!V.preservePaths,this.portable=!!V.portable,this.strict=!!V.strict,this.noPax=!!V.noPax,this.noMtime=!!V.noMtime,this.onWriteEntry=V.onWriteEntry,this.readEntry=d;let{type:H}=d;if(H===`Unsupported`)throw Error(`writing entry that should be ignored`);this.type=H,this.type===`Directory`&&this.portable&&(this.noMtime=!0),this.prefix=V.prefix,this.path=normalizeWindowsPath(d.path),this.mode=d.mode===void 0?void 0:this[MODE](d.mode),this.uid=this.portable?void 0:d.uid,this.gid=this.portable?void 0:d.gid,this.uname=this.portable?void 0:d.uname,this.gname=this.portable?void 0:d.gname,this.size=d.size,this.mtime=this.noMtime?void 0:V.mtime||d.mtime,this.atime=this.portable?void 0:d.atime,this.ctime=this.portable?void 0:d.ctime,this.linkpath=d.linkpath===void 0?void 0:normalizeWindowsPath(d.linkpath),typeof V.onwarn==`function`&&this.on(`warn`,V.onwarn);let U=!1;if(!this.preservePaths){let[d,B]=stripAbsolutePath(this.path);d&&typeof B==`string`&&(this.path=B,U=d)}this.remain=d.size,this.blockRemain=d.startBlockSize,this.onWriteEntry?.(this),this.header=new Header({path:this[PREFIX](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[PREFIX](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),U&&this.warn(`TAR_ENTRY_INFO`,`stripping ${U} from absolute path`,{entry:this,path:U+this.path}),this.header.encode()&&!this.noPax&&super.write(new Pax({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[PREFIX](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[PREFIX](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let W=this.header?.block;if(!W)throw Error(`failed to encode header`);super.write(W),d.pipe(this)}[PREFIX](d){return prefixPath(d,this.prefix)}[MODE](d){return modeFix(d,this.type===`Directory`,this.portable)}write(d,B,V){typeof B==`function`&&(V=B,B=void 0),typeof d==`string`&&(d=Buffer.from(d,typeof B==`string`?B:`utf8`));let H=d.length;if(H>this.blockRemain)throw Error(`writing more to entry than is appropriate`);return this.blockRemain-=H,super.write(d,V)}end(d,B,V){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof d==`function`&&(V=d,B=void 0,d=void 0),typeof B==`function`&&(V=B,B=void 0),typeof d==`string`&&(d=Buffer.from(d,B??`utf8`)),V&&this.once(`finish`,V),d?super.end(d,V):super.end(V),this}};const getType=d=>d.isFile()?`File`:d.isDirectory()?`Directory`:d.isSymbolicLink()?`SymbolicLink`:`Unsupported`;var Yallist=class d{tail;head;length=0;static create(B=[]){return new d(B)}constructor(d=[]){for(let B of d)this.push(B)}*[Symbol.iterator](){for(let d=this.head;d;d=d.next)yield d.value}removeNode(d){if(d.list!==this)throw Error(`removing node which does not belong to this list`);let B=d.next,V=d.prev;return B&&(B.prev=V),V&&(V.next=B),d===this.head&&(this.head=B),d===this.tail&&(this.tail=V),this.length--,d.next=void 0,d.prev=void 0,d.list=void 0,B}unshiftNode(d){if(d===this.head)return;d.list&&d.list.removeNode(d);let B=this.head;d.list=this,d.next=B,B&&(B.prev=d),this.head=d,this.tail||=d,this.length++}pushNode(d){if(d===this.tail)return;d.list&&d.list.removeNode(d);let B=this.tail;d.list=this,d.prev=B,B&&(B.next=d),this.tail=d,this.head||=d,this.length++}push(...d){for(let B=0,V=d.length;B<V;B++)push(this,d[B]);return this.length}unshift(...d){for(var B=0,V=d.length;B<V;B++)unshift(this,d[B]);return this.length}pop(){if(!this.tail)return;let d=this.tail.value,B=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,B.list=void 0,this.length--,d}shift(){if(!this.head)return;let d=this.head.value,B=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,B.list=void 0,this.length--,d}forEach(d,B){B||=this;for(let V=this.head,H=0;V;H++)d.call(B,V.value,H,this),V=V.next}forEachReverse(d,B){B||=this;for(let V=this.tail,H=this.length-1;V;H--)d.call(B,V.value,H,this),V=V.prev}get(d){let B=0,V=this.head;for(;V&&B<d;B++)V=V.next;if(B===d&&V)return V.value}getReverse(d){let B=0,V=this.tail;for(;V&&B<d;B++)V=V.prev;if(B===d&&V)return V.value}map(B,V){V||=this;let H=new d;for(let d=this.head;d;)H.push(B.call(V,d.value,this)),d=d.next;return H}mapReverse(B,V){V||=this;var H=new d;for(let d=this.tail;d;)H.push(B.call(V,d.value,this)),d=d.prev;return H}reduce(d,B){let V,H=this.head;if(arguments.length>1)V=B;else if(this.head)H=this.head.next,V=this.head.value;else throw TypeError(`Reduce of empty list with no initial value`);for(var U=0;H;U++)V=d(V,H.value,U),H=H.next;return V}reduceReverse(d,B){let V,H=this.tail;if(arguments.length>1)V=B;else if(this.tail)H=this.tail.prev,V=this.tail.value;else throw TypeError(`Reduce of empty list with no initial value`);for(let B=this.length-1;H;B--)V=d(V,H.value,B),H=H.prev;return V}toArray(){let d=Array(this.length);for(let B=0,V=this.head;V;B++)d[B]=V.value,V=V.next;return d}toArrayReverse(){let d=Array(this.length);for(let B=0,V=this.tail;V;B++)d[B]=V.value,V=V.prev;return d}slice(B=0,V=this.length){V<0&&(V+=this.length),B<0&&(B+=this.length);let H=new d;if(V<B||V<0)return H;B<0&&(B=0),V>this.length&&(V=this.length);let U=this.head,W=0;for(W=0;U&&W<B;W++)U=U.next;for(;U&&W<V;W++,U=U.next)H.push(U.value);return H}sliceReverse(B=0,V=this.length){V<0&&(V+=this.length),B<0&&(B+=this.length);let H=new d;if(V<B||V<0)return H;B<0&&(B=0),V>this.length&&(V=this.length);let U=this.length,W=this.tail;for(;W&&U>V;U--)W=W.prev;for(;W&&U>B;U--,W=W.prev)H.push(W.value);return H}splice(d,B=0,...V){d>this.length&&(d=this.length-1),d<0&&(d=this.length+d);let H=this.head;for(let B=0;H&&B<d;B++)H=H.next;let U=[];for(let d=0;H&&d<B;d++)U.push(H.value),H=this.removeNode(H);H?H!==this.tail&&(H=H.prev):H=this.tail;for(let d of V)H=insertAfter(this,H,d);return U}reverse(){let d=this.head,B=this.tail;for(let B=d;B;B=B.prev){let d=B.prev;B.prev=B.next,B.next=d}return this.head=B,this.tail=d,this}};function insertAfter(d,B,V){let H=new Node(V,B,B?B.next:d.head,d);return H.next===void 0&&(d.tail=H),H.prev===void 0&&(d.head=H),d.length++,H}function push(d,B){d.tail=new Node(B,d.tail,void 0,d),d.head||=d.tail,d.length++}function unshift(d,B){d.head=new Node(B,void 0,d.head,d),d.tail||=d.head,d.length++}var Node=class{list;next;prev;value;constructor(d,B,V,H){this.list=H,this.value=d,B?(B.next=this,this.prev=B):this.prev=void 0,V?(V.prev=this,this.next=V):this.next=void 0}},PackJob=class{path;absolute;entry;stat;readdir;pending=!1;ignore=!1;piped=!1;constructor(d,B){this.path=d||`./`,this.absolute=B}};const EOF=Buffer.alloc(1024),ONSTAT=Symbol(`onStat`),ENDED$1=Symbol(`ended`),QUEUE=Symbol(`queue`),CURRENT=Symbol(`current`),PROCESS=Symbol(`process`),PROCESSING=Symbol(`processing`),PROCESSJOB=Symbol(`processJob`),JOBS=Symbol(`jobs`),JOBDONE=Symbol(`jobDone`),ADDFSENTRY=Symbol(`addFSEntry`),ADDTARENTRY=Symbol(`addTarEntry`),STAT=Symbol(`stat`),READDIR=Symbol(`readdir`),ONREADDIR=Symbol(`onreaddir`),PIPE=Symbol(`pipe`),ENTRY=Symbol(`entry`),ENTRYOPT=Symbol(`entryOpt`),WRITEENTRYCLASS=Symbol(`writeEntryClass`),WRITE=Symbol(`write`),ONDRAIN=Symbol(`ondrain`);var Pack=class extends Minipass{opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[WRITEENTRYCLASS];onWriteEntry;[QUEUE];[JOBS]=0;[PROCESSING]=!1;[ENDED$1]=!1;constructor(d={}){if(super(),this.opt=d,this.file=d.file||``,this.cwd=d.cwd||process.cwd(),this.maxReadSize=d.maxReadSize,this.preservePaths=!!d.preservePaths,this.strict=!!d.strict,this.noPax=!!d.noPax,this.prefix=normalizeWindowsPath(d.prefix||``),this.linkCache=d.linkCache||new Map,this.statCache=d.statCache||new Map,this.readdirCache=d.readdirCache||new Map,this.onWriteEntry=d.onWriteEntry,this[WRITEENTRYCLASS]=WriteEntry,typeof d.onwarn==`function`&&this.on(`warn`,d.onwarn),this.portable=!!d.portable,d.gzip||d.brotli||d.zstd){if((d.gzip?1:0)+(d.brotli?1:0)+(d.zstd?1:0)>1)throw TypeError(`gzip, brotli, zstd are mutually exclusive`);if(d.gzip&&(typeof d.gzip!=`object`&&(d.gzip={}),this.portable&&(d.gzip.portable=!0),this.zip=new Gzip(d.gzip)),d.brotli&&(typeof d.brotli!=`object`&&(d.brotli={}),this.zip=new BrotliCompress(d.brotli)),d.zstd&&(typeof d.zstd!=`object`&&(d.zstd={}),this.zip=new ZstdCompress(d.zstd)),!this.zip)throw Error(`impossible`);let B=this.zip;B.on(`data`,d=>super.write(d)),B.on(`end`,()=>super.end()),B.on(`drain`,()=>this[ONDRAIN]()),this.on(`resume`,()=>B.resume())}else this.on(`drain`,this[ONDRAIN]);this.noDirRecurse=!!d.noDirRecurse,this.follow=!!d.follow,this.noMtime=!!d.noMtime,d.mtime&&(this.mtime=d.mtime),this.filter=typeof d.filter==`function`?d.filter:()=>!0,this[QUEUE]=new Yallist,this[JOBS]=0,this.jobs=Number(d.jobs)||4,this[PROCESSING]=!1,this[ENDED$1]=!1}[WRITE](d){return super.write(d)}add(d){return this.write(d),this}end(d,B,V){return typeof d==`function`&&(V=d,d=void 0),typeof B==`function`&&(V=B,B=void 0),d&&this.add(d),this[ENDED$1]=!0,this[PROCESS](),V&&V(),this}write(d){if(this[ENDED$1])throw Error(`write after end`);return d instanceof ReadEntry?this[ADDTARENTRY](d):this[ADDFSENTRY](d),this.flowing}[ADDTARENTRY](d){let B=normalizeWindowsPath(path$1.resolve(this.cwd,d.path));if(!this.filter(d.path,d))d.resume();else{let V=new PackJob(d.path,B);V.entry=new WriteEntryTar(d,this[ENTRYOPT](V)),V.entry.on(`end`,()=>this[JOBDONE](V)),this[JOBS]+=1,this[QUEUE].push(V)}this[PROCESS]()}[ADDFSENTRY](d){let B=normalizeWindowsPath(path$1.resolve(this.cwd,d));this[QUEUE].push(new PackJob(d,B)),this[PROCESS]()}[STAT](d){d.pending=!0,this[JOBS]+=1,fs$1[this.follow?`stat`:`lstat`](d.absolute,(B,V)=>{d.pending=!1,--this[JOBS],B?this.emit(`error`,B):this[ONSTAT](d,V)})}[ONSTAT](d,B){this.statCache.set(d.absolute,B),d.stat=B,this.filter(d.path,B)||(d.ignore=!0),this[PROCESS]()}[READDIR](d){d.pending=!0,this[JOBS]+=1,fs$1.readdir(d.absolute,(B,V)=>{if(d.pending=!1,--this[JOBS],B)return this.emit(`error`,B);this[ONREADDIR](d,V)})}[ONREADDIR](d,B){this.readdirCache.set(d.absolute,B),d.readdir=B,this[PROCESS]()}[PROCESS](){if(!this[PROCESSING]){this[PROCESSING]=!0;for(let d=this[QUEUE].head;d&&this[JOBS]<this.jobs;d=d.next)if(this[PROCESSJOB](d.value),d.value.ignore){let B=d.next;this[QUEUE].removeNode(d),d.next=B}this[PROCESSING]=!1,this[ENDED$1]&&!this[QUEUE].length&&this[JOBS]===0&&(this.zip?this.zip.end(EOF):(super.write(EOF),super.end()))}}get[CURRENT](){return this[QUEUE]&&this[QUEUE].head&&this[QUEUE].head.value}[JOBDONE](d){this[QUEUE].shift(),--this[JOBS],this[PROCESS]()}[PROCESSJOB](d){if(!d.pending){if(d.entry){d===this[CURRENT]&&!d.piped&&this[PIPE](d);return}if(!d.stat){let B=this.statCache.get(d.absolute);B?this[ONSTAT](d,B):this[STAT](d)}if(d.stat&&!d.ignore){if(!this.noDirRecurse&&d.stat.isDirectory()&&!d.readdir){let B=this.readdirCache.get(d.absolute);if(B?this[ONREADDIR](d,B):this[READDIR](d),!d.readdir)return}if(d.entry=this[ENTRY](d),!d.entry){d.ignore=!0;return}d===this[CURRENT]&&!d.piped&&this[PIPE](d)}}}[ENTRYOPT](d){return{onwarn:(d,B,V)=>this.warn(d,B,V),noPax:this.noPax,cwd:this.cwd,absolute:d.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[ENTRY](d){this[JOBS]+=1;try{return new this[WRITEENTRYCLASS](d.path,this[ENTRYOPT](d)).on(`end`,()=>this[JOBDONE](d)).on(`error`,d=>this.emit(`error`,d))}catch(d){this.emit(`error`,d)}}[ONDRAIN](){this[CURRENT]&&this[CURRENT].entry&&this[CURRENT].entry.resume()}[PIPE](d){d.piped=!0,d.readdir&&d.readdir.forEach(B=>{let V=d.path,H=V===`./`?``:V.replace(/\/*$/,`/`);this[ADDFSENTRY](H+B)});let B=d.entry,V=this.zip;if(!B)throw Error(`cannot pipe without source`);V?B.on(`data`,d=>{V.write(d)||B.pause()}):B.on(`data`,d=>{super.write(d)||B.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(d,B,V={}){warnMethod(this,d,B,V)}},PackSync=class extends Pack{sync=!0;constructor(d){super(d),this[WRITEENTRYCLASS]=WriteEntrySync}pause(){}resume(){}[STAT](d){let B=this.follow?`statSync`:`lstatSync`;this[ONSTAT](d,fs$1[B](d.absolute))}[READDIR](d){this[ONREADDIR](d,fs$1.readdirSync(d.absolute))}[PIPE](d){let B=d.entry,V=this.zip;if(d.readdir&&d.readdir.forEach(B=>{let V=d.path,H=V===`./`?``:V.replace(/\/*$/,`/`);this[ADDFSENTRY](H+B)}),!B)throw Error(`Cannot pipe without source`);V?B.on(`data`,d=>{V.write(d)}):B.on(`data`,d=>{super[WRITE](d)})}};const createFileSync=(d,V)=>{let H=new PackSync(d),U=new WriteStreamSync(d.file,{mode:d.mode||438});H.pipe(U),addFilesSync$1(H,V)},createFile=(d,B)=>{let V=new Pack(d),U=new WriteStream(d.file,{mode:d.mode||438});V.pipe(U);let W=new Promise((d,B)=>{U.on(`error`,B),U.on(`close`,d),V.on(`error`,B)});return addFilesAsync$1(V,B),W},addFilesSync$1=(d,B)=>{B.forEach(B=>{B.charAt(0)===`@`?list({file:path.resolve(d.cwd,B.slice(1)),sync:!0,noResume:!0,onReadEntry:B=>d.add(B)}):d.add(B)}),d.end()},addFilesAsync$1=async(d,B)=>{for(let V=0;V<B.length;V++){let H=String(B[V]);H.charAt(0)===`@`?await list({file:path.resolve(String(d.cwd),H.slice(1)),noResume:!0,onReadEntry:B=>{d.add(B)}}):d.add(H)}d.end()};makeCommand(createFileSync,createFile,(d,B)=>{let V=new PackSync(d);return addFilesSync$1(V,B),V},(d,B)=>{let V=new Pack(d);return addFilesAsync$1(V,B),V},(d,B)=>{if(!B?.length)throw TypeError(`no paths specified to add to archive`)});const isWindows$2=(process.env.__FAKE_PLATFORM__||process.platform)===`win32`,{O_CREAT,O_TRUNC,O_WRONLY}=fs$1.constants,UV_FS_O_FILEMAP=Number(process.env.__FAKE_FS_O_FILENAME__)||fs$1.constants.UV_FS_O_FILEMAP||0,fMapEnabled=isWindows$2&&!!UV_FS_O_FILEMAP,fMapFlag=UV_FS_O_FILEMAP|O_TRUNC|O_CREAT|O_WRONLY,getWriteFlag=fMapEnabled?d=>d<524288?fMapFlag:`w`:()=>`w`;var CwdError=class extends Error{path;code;syscall=`chdir`;constructor(d,B){super(`${B}: Cannot cd into '${d}'`),this.path=d,this.code=B}get name(){return`CwdError`}},SymlinkError=class extends Error{path;symlink;syscall=`symlink`;code=`TAR_SYMLINK_ERROR`;constructor(d,B){super(`TAR_SYMLINK_ERROR: Cannot extract through symbolic link`),this.symlink=d,this.path=B}get name(){return`SymlinkError`}};const checkCwd=(d,B)=>{fs.stat(d,(V,H)=>{(V||!H.isDirectory())&&(V=new CwdError(d,V?.code||`ENOTDIR`)),B(V)})},mkdir$1=(d,B,V)=>{d=normalizeWindowsPath(d);let H=B.umask??18,U=B.mode|448,W=(U&H)!==0,G=B.uid,K=B.gid,q=typeof G==`number`&&typeof K==`number`&&(G!==B.processUid||K!==B.processGid),J=B.preserve,Y=B.unlink,X=normalizeWindowsPath(B.cwd),$=(B,H)=>{B?V(B):H&&q?chownr(H,G,K,d=>$(d)):W?fs.chmod(d,U,V):V()};if(d===X)return checkCwd(d,$);if(J)return fsp.mkdir(d,{mode:U,recursive:!0}).then(d=>$(null,d??void 0),$);mkdir_(X,normalizeWindowsPath(path.relative(X,d)).split(`/`),U,Y,X,void 0,$)},mkdir_=(d,B,V,H,U,W,G)=>{if(!B.length)return G(null,W);let K=B.shift(),q=normalizeWindowsPath(path.resolve(d+`/`+K));fs.mkdir(q,V,onmkdir(q,B,V,H,U,W,G))},onmkdir=(d,B,V,H,U,W,G)=>K=>{K?fs.lstat(d,(q,J)=>{if(q)q.path=q.path&&normalizeWindowsPath(q.path),G(q);else if(J.isDirectory())mkdir_(d,B,V,H,U,W,G);else if(H)fs.unlink(d,K=>{if(K)return G(K);fs.mkdir(d,V,onmkdir(d,B,V,H,U,W,G))});else if(J.isSymbolicLink())return G(new SymlinkError(d,d+`/`+B.join(`/`)));else G(K)}):(W||=d,mkdir_(d,B,V,H,U,W,G))},checkCwdSync=d=>{let B=!1,V;try{B=fs.statSync(d).isDirectory()}catch(d){V=d?.code}finally{if(!B)throw new CwdError(d,V??`ENOTDIR`)}},mkdirSync=(d,B)=>{d=normalizeWindowsPath(d);let V=B.umask??18,H=B.mode|448,U=(H&V)!==0,W=B.uid,G=B.gid,K=typeof W==`number`&&typeof G==`number`&&(W!==B.processUid||G!==B.processGid),q=B.preserve,J=B.unlink,Y=normalizeWindowsPath(B.cwd),Z=B=>{B&&K&&chownrSync(B,W,G),U&&fs.chmodSync(d,H)};if(d===Y)return checkCwdSync(Y),Z();if(q)return Z(fs.mkdirSync(d,{mode:H,recursive:!0})??void 0);let Q=normalizeWindowsPath(path.relative(Y,d)).split(`/`),$;for(let d=Q.shift(),B=Y;d&&(B+=`/`+d);d=Q.shift()){B=normalizeWindowsPath(path.resolve(B));try{fs.mkdirSync(B,H),$||=B}catch{let d=fs.lstatSync(B);if(d.isDirectory())continue;if(J){fs.unlinkSync(B),fs.mkdirSync(B,H),$||=B;continue}else if(d.isSymbolicLink())return new SymlinkError(B,B+`/`+Q.join(`/`))}}return Z($)},normalizeCache=Object.create(null),MAX=1e4,cache=new Set,normalizeUnicode=d=>{cache.has(d)?cache.delete(d):normalizeCache[d]=d.normalize(`NFD`).toLocaleLowerCase(`en`).toLocaleUpperCase(`en`),cache.add(d);let B=normalizeCache[d],V=cache.size-MAX;if(V>MAX/10){for(let d of cache)if(cache.delete(d),delete normalizeCache[d],--V<=0)break}return B},isWindows$1=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`,getDirs=d=>d.split(`/`).slice(0,-1).reduce((d,B)=>{let V=d[d.length-1];return V!==void 0&&(B=join(V,B)),d.push(B||`/`),d},[]);var PathReservations=class{#queues=new Map;#reservations=new Map;#running=new Set;reserve(d,B){d=isWindows$1?[`win32 parallelization disabled`]:d.map(d=>stripTrailingSlashes(join(normalizeUnicode(d))));let V=new Set(d.map(d=>getDirs(d)).reduce((d,B)=>d.concat(B)));this.#reservations.set(B,{dirs:V,paths:d});for(let V of d){let d=this.#queues.get(V);d?d.push(B):this.#queues.set(V,[B])}for(let d of V){let V=this.#queues.get(d);if(!V)this.#queues.set(d,[new Set([B])]);else{let d=V[V.length-1];d instanceof Set?d.add(B):V.push(new Set([B]))}}return this.#run(B)}#getQueues(d){let B=this.#reservations.get(d);if(!B)throw Error(`function does not have any path reservations`);return{paths:B.paths.map(d=>this.#queues.get(d)),dirs:[...B.dirs].map(d=>this.#queues.get(d))}}check(d){let{paths:B,dirs:V}=this.#getQueues(d);return B.every(B=>B&&B[0]===d)&&V.every(B=>B&&B[0]instanceof Set&&B[0].has(d))}#run(d){return this.#running.has(d)||!this.check(d)?!1:(this.#running.add(d),d(()=>this.#clear(d)),!0)}#clear(d){if(!this.#running.has(d))return!1;let B=this.#reservations.get(d);if(!B)throw Error(`invalid reservation`);let{paths:V,dirs:H}=B,U=new Set;for(let B of V){let V=this.#queues.get(B);if(!V||V?.[0]!==d)continue;let H=V[1];if(!H){this.#queues.delete(B);continue}if(V.shift(),typeof H==`function`)U.add(H);else for(let d of H)U.add(d)}for(let B of H){let V=this.#queues.get(B),H=V?.[0];if(!(!V||!(H instanceof Set)))if(H.size===1&&V.length===1){this.#queues.delete(B);continue}else if(H.size===1){V.shift();let d=V[0];typeof d==`function`&&U.add(d)}else H.delete(d)}return this.#running.delete(d),U.forEach(d=>this.#run(d)),!0}};const ONENTRY=Symbol(`onEntry`),CHECKFS=Symbol(`checkFs`),CHECKFS2=Symbol(`checkFs2`),ISREUSABLE=Symbol(`isReusable`),MAKEFS=Symbol(`makeFs`),FILE=Symbol(`file`),DIRECTORY=Symbol(`directory`),LINK=Symbol(`link`),SYMLINK=Symbol(`symlink`),HARDLINK=Symbol(`hardlink`),UNSUPPORTED=Symbol(`unsupported`),CHECKPATH=Symbol(`checkPath`),STRIPABSOLUTEPATH=Symbol(`stripAbsolutePath`),MKDIR=Symbol(`mkdir`),ONERROR=Symbol(`onError`),PENDING=Symbol(`pending`),PEND=Symbol(`pend`),UNPEND=Symbol(`unpend`),ENDED=Symbol(`ended`),MAYBECLOSE=Symbol(`maybeClose`),SKIP=Symbol(`skip`),DOCHOWN=Symbol(`doChown`),UID=Symbol(`uid`),GID=Symbol(`gid`),CHECKED_CWD=Symbol(`checkedCwd`),isWindows=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`,unlinkFile=(d,B)=>{if(!isWindows)return fs.unlink(d,B);let V=d+`.DELETE.`+randomBytes(16).toString(`hex`);fs.rename(d,V,d=>{if(d)return B(d);fs.unlink(V,B)})},unlinkFileSync=d=>{if(!isWindows)return fs.unlinkSync(d);let B=d+`.DELETE.`+randomBytes(16).toString(`hex`);fs.renameSync(d,B),fs.unlinkSync(B)},uint32=(d,B,V)=>d!==void 0&&d===d>>>0?d:B!==void 0&&B===B>>>0?B:V;var Unpack=class extends Parser{[ENDED]=!1;[CHECKED_CWD]=!1;[PENDING]=0;reservations=new PathReservations;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(d={}){if(d.ondone=()=>{this[ENDED]=!0,this[MAYBECLOSE]()},super(d),this.transform=d.transform,this.chmod=!!d.chmod,typeof d.uid==`number`||typeof d.gid==`number`){if(typeof d.uid!=`number`||typeof d.gid!=`number`)throw TypeError(`cannot set owner without number uid and gid`);if(d.preserveOwner)throw TypeError(`cannot preserve owner in archive and also set owner explicitly`);this.uid=d.uid,this.gid=d.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;d.preserveOwner===void 0&&typeof d.uid!=`number`?this.preserveOwner=!!(process.getuid&&process.getuid()===0):this.preserveOwner=!!d.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof d.maxDepth==`number`?d.maxDepth:1024,this.forceChown=d.forceChown===!0,this.win32=!!d.win32||isWindows,this.newer=!!d.newer,this.keep=!!d.keep,this.noMtime=!!d.noMtime,this.preservePaths=!!d.preservePaths,this.unlink=!!d.unlink,this.cwd=normalizeWindowsPath(path.resolve(d.cwd||process.cwd())),this.strip=Number(d.strip)||0,this.processUmask=this.chmod?typeof d.processUmask==`number`?d.processUmask:process.umask():0,this.umask=typeof d.umask==`number`?d.umask:this.processUmask,this.dmode=d.dmode||511&~this.umask,this.fmode=d.fmode||438&~this.umask,this.on(`entry`,d=>this[ONENTRY](d))}warn(d,B,V={}){return(d===`TAR_BAD_ARCHIVE`||d===`TAR_ABORT`)&&(V.recoverable=!1),super.warn(d,B,V)}[MAYBECLOSE](){this[ENDED]&&this[PENDING]===0&&(this.emit(`prefinish`),this.emit(`finish`),this.emit(`end`))}[STRIPABSOLUTEPATH](d,B){let V=d[B];if(!V||this.preservePaths)return!0;let H=V.split(`/`);if(H.includes(`..`)||isWindows&&/^[a-z]:\.\.$/i.test(H[0]??``))return this.warn(`TAR_ENTRY_ERROR`,`${B} contains '..'`,{entry:d,[B]:V}),!1;let[U,W]=stripAbsolutePath(V);return U&&(d[B]=String(W),this.warn(`TAR_ENTRY_INFO`,`stripping ${U} from absolute ${B}`,{entry:d,[B]:V})),!0}[CHECKPATH](d){let B=normalizeWindowsPath(d.path),V=B.split(`/`);if(this.strip){if(V.length<this.strip)return!1;if(d.type===`Link`){let B=normalizeWindowsPath(String(d.linkpath)).split(`/`);if(B.length>=this.strip)d.linkpath=B.slice(this.strip).join(`/`);else return!1}V.splice(0,this.strip),d.path=V.join(`/`)}if(isFinite(this.maxDepth)&&V.length>this.maxDepth)return this.warn(`TAR_ENTRY_ERROR`,`path excessively deep`,{entry:d,path:B,depth:V.length,maxDepth:this.maxDepth}),!1;if(!this[STRIPABSOLUTEPATH](d,`path`)||!this[STRIPABSOLUTEPATH](d,`linkpath`))return!1;if(path.isAbsolute(d.path)?d.absolute=normalizeWindowsPath(path.resolve(d.path)):d.absolute=normalizeWindowsPath(path.resolve(this.cwd,d.path)),!this.preservePaths&&typeof d.absolute==`string`&&d.absolute.indexOf(this.cwd+`/`)!==0&&d.absolute!==this.cwd)return this.warn(`TAR_ENTRY_ERROR`,`path escaped extraction target`,{entry:d,path:normalizeWindowsPath(d.path),resolvedPath:d.absolute,cwd:this.cwd}),!1;if(d.absolute===this.cwd&&d.type!==`Directory`&&d.type!==`GNUDumpDir`)return!1;if(this.win32){let{root:B}=path.win32.parse(String(d.absolute));d.absolute=B+encode(String(d.absolute).slice(B.length));let{root:V}=path.win32.parse(d.path);d.path=V+encode(d.path.slice(V.length))}return!0}[ONENTRY](d){if(!this[CHECKPATH](d))return d.resume();switch(assert.equal(typeof d.absolute,`string`),d.type){case`Directory`:case`GNUDumpDir`:d.mode&&(d.mode|=448);case`File`:case`OldFile`:case`ContiguousFile`:case`Link`:case`SymbolicLink`:return this[CHECKFS](d);case`CharacterDevice`:case`BlockDevice`:case`FIFO`:default:return this[UNSUPPORTED](d)}}[ONERROR](d,B){d.name===`CwdError`?this.emit(`error`,d):(this.warn(`TAR_ENTRY_ERROR`,d,{entry:B}),this[UNPEND](),B.resume())}[MKDIR](d,B,V){mkdir$1(normalizeWindowsPath(d),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:B},V)}[DOCHOWN](d){return this.forceChown||this.preserveOwner&&(typeof d.uid==`number`&&d.uid!==this.processUid||typeof d.gid==`number`&&d.gid!==this.processGid)||typeof this.uid==`number`&&this.uid!==this.processUid||typeof this.gid==`number`&&this.gid!==this.processGid}[UID](d){return uint32(this.uid,d.uid,this.processUid)}[GID](d){return uint32(this.gid,d.gid,this.processGid)}[FILE](d,B){let V=typeof d.mode==`number`?d.mode&4095:this.fmode,U=new WriteStream(String(d.absolute),{flags:getWriteFlag(d.size),mode:V,autoClose:!1});U.on(`error`,V=>{U.fd&&fs.close(U.fd,()=>{}),U.write=()=>!0,this[ONERROR](V,d),B()});let W=1,G=V=>{if(V){U.fd&&fs.close(U.fd,()=>{}),this[ONERROR](V,d),B();return}--W===0&&U.fd!==void 0&&fs.close(U.fd,V=>{V?this[ONERROR](V,d):this[UNPEND](),B()})};U.on(`finish`,()=>{let B=String(d.absolute),V=U.fd;if(typeof V==`number`&&d.mtime&&!this.noMtime){W++;let H=d.atime||new Date,U=d.mtime;fs.futimes(V,H,U,d=>d?fs.utimes(B,H,U,B=>G(B&&d)):G())}if(typeof V==`number`&&this[DOCHOWN](d)){W++;let H=this[UID](d),U=this[GID](d);typeof H==`number`&&typeof U==`number`&&fs.fchown(V,H,U,d=>d?fs.chown(B,H,U,B=>G(B&&d)):G())}G()});let K=this.transform&&this.transform(d)||d;K!==d&&(K.on(`error`,V=>{this[ONERROR](V,d),B()}),d.pipe(K)),K.pipe(U)}[DIRECTORY](d,B){let V=typeof d.mode==`number`?d.mode&4095:this.dmode;this[MKDIR](String(d.absolute),V,V=>{if(V){this[ONERROR](V,d),B();return}let H=1,U=()=>{--H===0&&(B(),this[UNPEND](),d.resume())};d.mtime&&!this.noMtime&&(H++,fs.utimes(String(d.absolute),d.atime||new Date,d.mtime,U)),this[DOCHOWN](d)&&(H++,fs.chown(String(d.absolute),Number(this[UID](d)),Number(this[GID](d)),U)),U()})}[UNSUPPORTED](d){d.unsupported=!0,this.warn(`TAR_ENTRY_UNSUPPORTED`,`unsupported entry type: ${d.type}`,{entry:d}),d.resume()}[SYMLINK](d,B){this[LINK](d,String(d.linkpath),`symlink`,B)}[HARDLINK](d,B){let V=normalizeWindowsPath(path.resolve(this.cwd,String(d.linkpath)));this[LINK](d,V,`link`,B)}[PEND](){this[PENDING]++}[UNPEND](){this[PENDING]--,this[MAYBECLOSE]()}[SKIP](d){this[UNPEND](),d.resume()}[ISREUSABLE](d,B){return d.type===`File`&&!this.unlink&&B.isFile()&&B.nlink<=1&&!isWindows}[CHECKFS](d){this[PEND]();let B=[d.path];d.linkpath&&B.push(d.linkpath),this.reservations.reserve(B,B=>this[CHECKFS2](d,B))}[CHECKFS2](d,B){let V=d=>{B(d)},H=()=>{this[MKDIR](this.cwd,this.dmode,B=>{if(B){this[ONERROR](B,d),V();return}this[CHECKED_CWD]=!0,U()})},U=()=>{if(d.absolute!==this.cwd){let B=normalizeWindowsPath(path.dirname(String(d.absolute)));if(B!==this.cwd)return this[MKDIR](B,this.dmode,B=>{if(B){this[ONERROR](B,d),V();return}W()})}W()},W=()=>{fs.lstat(String(d.absolute),(B,H)=>{if(H&&(this.keep||this.newer&&H.mtime>(d.mtime??H.mtime))){this[SKIP](d),V();return}if(B||this[ISREUSABLE](d,H))return this[MAKEFS](null,d,V);if(H.isDirectory()){if(d.type===`Directory`){let B=this.chmod&&d.mode&&(H.mode&4095)!==d.mode,U=B=>this[MAKEFS](B??null,d,V);return B?fs.chmod(String(d.absolute),Number(d.mode),U):U()}if(d.absolute!==this.cwd)return fs.rmdir(String(d.absolute),B=>this[MAKEFS](B??null,d,V))}if(d.absolute===this.cwd)return this[MAKEFS](null,d,V);unlinkFile(String(d.absolute),B=>this[MAKEFS](B??null,d,V))})};this[CHECKED_CWD]?U():H()}[MAKEFS](d,B,V){if(d){this[ONERROR](d,B),V();return}switch(B.type){case`File`:case`OldFile`:case`ContiguousFile`:return this[FILE](B,V);case`Link`:return this[HARDLINK](B,V);case`SymbolicLink`:return this[SYMLINK](B,V);case`Directory`:case`GNUDumpDir`:return this[DIRECTORY](B,V)}}[LINK](d,B,V,H){fs[V](B,String(d.absolute),B=>{B?this[ONERROR](B,d):(this[UNPEND](),d.resume()),H()})}};const callSync=d=>{try{return[null,d()]}catch(d){return[d,null]}};var UnpackSync=class extends Unpack{sync=!0;[MAKEFS](d,B){return super[MAKEFS](d,B,()=>{})}[CHECKFS](d){if(!this[CHECKED_CWD]){let B=this[MKDIR](this.cwd,this.dmode);if(B)return this[ONERROR](B,d);this[CHECKED_CWD]=!0}if(d.absolute!==this.cwd){let B=normalizeWindowsPath(path.dirname(String(d.absolute)));if(B!==this.cwd){let V=this[MKDIR](B,this.dmode);if(V)return this[ONERROR](V,d)}}let[B,V]=callSync(()=>fs.lstatSync(String(d.absolute)));if(V&&(this.keep||this.newer&&V.mtime>(d.mtime??V.mtime)))return this[SKIP](d);if(B||this[ISREUSABLE](d,V))return this[MAKEFS](null,d);if(V.isDirectory()){if(d.type===`Directory`){let[B]=this.chmod&&d.mode&&(V.mode&4095)!==d.mode?callSync(()=>{fs.chmodSync(String(d.absolute),Number(d.mode))}):[];return this[MAKEFS](B,d)}let[B]=callSync(()=>fs.rmdirSync(String(d.absolute)));this[MAKEFS](B,d)}let[H]=d.absolute===this.cwd?[]:callSync(()=>unlinkFileSync(String(d.absolute)));this[MAKEFS](H,d)}[FILE](d,B){let V=typeof d.mode==`number`?d.mode&4095:this.fmode,H=V=>{let H;try{fs.closeSync(U)}catch(d){H=d}(V||H)&&this[ONERROR](V||H,d),B()},U;try{U=fs.openSync(String(d.absolute),getWriteFlag(d.size),V)}catch(d){return H(d)}let W=this.transform&&this.transform(d)||d;W!==d&&(W.on(`error`,B=>this[ONERROR](B,d)),d.pipe(W)),W.on(`data`,d=>{try{fs.writeSync(U,d,0,d.length)}catch(d){H(d)}}),W.on(`end`,()=>{let B=null;if(d.mtime&&!this.noMtime){let V=d.atime||new Date,H=d.mtime;try{fs.futimesSync(U,V,H)}catch(U){try{fs.utimesSync(String(d.absolute),V,H)}catch{B=U}}}if(this[DOCHOWN](d)){let V=this[UID](d),H=this[GID](d);try{fs.fchownSync(U,Number(V),Number(H))}catch(U){try{fs.chownSync(String(d.absolute),Number(V),Number(H))}catch{B||=U}}}H(B)})}[DIRECTORY](d,B){let V=typeof d.mode==`number`?d.mode&4095:this.dmode,H=this[MKDIR](String(d.absolute),V);if(H){this[ONERROR](H,d),B();return}if(d.mtime&&!this.noMtime)try{fs.utimesSync(String(d.absolute),d.atime||new Date,d.mtime)}catch{}if(this[DOCHOWN](d))try{fs.chownSync(String(d.absolute),Number(this[UID](d)),Number(this[GID](d)))}catch{}B(),d.resume()}[MKDIR](d,B){try{return mkdirSync(normalizeWindowsPath(d),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:B})}catch(d){return d}}[LINK](d,B,V,H){let U=`${V}Sync`;try{fs[U](B,String(d.absolute)),H(),d.resume()}catch(B){return this[ONERROR](B,d)}}};const extract=makeCommand(d=>{let B=new UnpackSync(d),H=d.file,U=fs.statSync(H);new ReadStreamSync(H,{readSize:d.maxReadSize||16*1024*1024,size:U.size}).pipe(B)},(d,B)=>{let V=new Unpack(d),H=d.maxReadSize||16*1024*1024,W=d.file;return new Promise((d,B)=>{V.on(`error`,B),V.on(`close`,d),fs.stat(W,(d,G)=>{if(d)B(d);else{let d=new ReadStream(W,{readSize:H,size:G.size});d.on(`error`,B),d.pipe(V)}})})},d=>new UnpackSync(d),d=>new Unpack(d),(d,B)=>{B?.length&&filesFilter(d,B)}),replaceSync=(d,B)=>{let V=new PackSync(d),H=!0,U,W;try{try{U=fs.openSync(d.file,`r+`)}catch(B){if(B?.code===`ENOENT`)U=fs.openSync(d.file,`w+`);else throw B}let G=fs.fstatSync(U),K=Buffer.alloc(512);POSITION:for(W=0;W<G.size;W+=512){for(let d=0,B=0;d<512;d+=B){if(B=fs.readSync(U,K,d,K.length-d,W+d),W===0&&K[0]===31&&K[1]===139)throw Error(`cannot append to compressed archives`);if(!B)break POSITION}let B=new Header(K);if(!B.cksumValid)break;let V=512*Math.ceil((B.size||0)/512);if(W+V+512>G.size)break;W+=V,d.mtimeCache&&B.mtime&&d.mtimeCache.set(String(B.path),B.mtime)}H=!1,streamSync(d,V,W,U,B)}finally{if(H)try{fs.closeSync(U)}catch{}}},streamSync=(d,V,H,U,W)=>{let G=new WriteStreamSync(d.file,{fd:U,start:H});V.pipe(G),addFilesSync(V,W)},replaceAsync=(d,B)=>{B=Array.from(B);let V=new Pack(d),U=(B,V,H)=>{let U=(d,V)=>{d?fs.close(B,B=>H(d)):H(null,V)},W=0;if(V===0)return U(null,0);let G=0,K=Buffer.alloc(512),q=(H,J)=>{if(H||J===void 0)return U(H);if(G+=J,G<512&&J)return fs.read(B,K,G,K.length-G,W+G,q);if(W===0&&K[0]===31&&K[1]===139)return U(Error(`cannot append to compressed archives`));if(G<512)return U(null,W);let Y=new Header(K);if(!Y.cksumValid)return U(null,W);let X=512*Math.ceil((Y.size??0)/512);if(W+X+512>V||(W+=X+512,W>=V))return U(null,W);d.mtimeCache&&Y.mtime&&d.mtimeCache.set(String(Y.path),Y.mtime),G=0,fs.read(B,K,0,512,W,q)};fs.read(B,K,0,512,W,q)};return new Promise((W,G)=>{V.on(`error`,G);let K=`r+`,q=(J,Y)=>{if(J&&J.code===`ENOENT`&&K===`r+`)return K=`w+`,fs.open(d.file,K,q);if(J||!Y)return G(J);fs.fstat(Y,(K,q)=>{if(K)return fs.close(Y,()=>G(K));U(Y,q.size,(U,K)=>{if(U)return G(U);let q=new WriteStream(d.file,{fd:Y,start:K});V.pipe(q),q.on(`error`,G),q.on(`close`,W),addFilesAsync(V,B)})})};fs.open(d.file,K,q)})},addFilesSync=(d,B)=>{B.forEach(B=>{B.charAt(0)===`@`?list({file:path.resolve(d.cwd,B.slice(1)),sync:!0,noResume:!0,onReadEntry:B=>d.add(B)}):d.add(B)}),d.end()},addFilesAsync=async(d,B)=>{for(let V=0;V<B.length;V++){let H=String(B[V]);H.charAt(0)===`@`?await list({file:path.resolve(String(d.cwd),H.slice(1)),noResume:!0,onReadEntry:B=>d.add(B)}):d.add(H)}d.end()},replace=makeCommand(replaceSync,replaceAsync,()=>{throw TypeError(`file is required`)},()=>{throw TypeError(`file is required`)},(d,B)=>{if(!isFile(d))throw TypeError(`file is required`);if(d.gzip||d.brotli||d.zstd||d.file.endsWith(`.br`)||d.file.endsWith(`.tbr`))throw TypeError(`cannot append to compressed archives`);if(!B?.length)throw TypeError(`no paths specified to add/replace`)});makeCommand(replace.syncFile,replace.asyncFile,replace.syncNoFile,replace.asyncNoFile,(d,B=[])=>{replace.validate?.(d,B),mtimeFilter(d)});const mtimeFilter=d=>{let B=d.filter;d.mtimeCache||=new Map,d.filter=B?(V,H)=>B(V,H)&&!((d.mtimeCache?.get(V)??H.mtime??0)>(H.mtime??0)):(B,V)=>!((d.mtimeCache?.get(B)??V.mtime??0)>(V.mtime??0))};export{extract as t};
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };