create-mugnavo 0.5.0 → 0.6.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 +1 -1
- package/dist/index.mjs +65 -70
- package/dist/tar-BOAfigV2.mjs +4 -0
- package/package.json +10 -10
- package/dist/rolldown-runtime-Dh0vTgs_.mjs +0 -2
- package/dist/tar-Bd_UMghg.mjs +0 -4
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ pnpm create mugnavo
|
|
|
9
9
|
## Templates
|
|
10
10
|
|
|
11
11
|
- [`default`](https://github.com/mugnavo/tanstarter) - Minimal TanStarter template
|
|
12
|
-
- [`monorepo`](https://github.com/mugnavo/tanstarter-
|
|
12
|
+
- [`monorepo`](https://github.com/mugnavo/tanstarter-monorepo) - TanStarter Monorepo via pnpm workspaces
|
|
13
13
|
|
|
14
14
|
## License
|
|
15
15
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,92 +1,87 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
3
|
-
`),u=!1;for(let e=0;e<l.length;e++){let t=l[e];if(r+=t,u)u=!1;else if(u=t>=`\ud800`&&t<=`\udbff`,u)continue;if(t===`\x1B`||t===``){
|
|
4
|
-
`){a&&(r+=
|
|
5
|
-
`&&(i&&
|
|
6
|
-
`)}var
|
|
2
|
+
import{parseArgs as e,promisify as t,styleText as n}from"node:util";import r,{cwd as i,stdin as a,stdout as o}from"node:process";import*as s from"node:readline";import c from"node:readline";import{ReadStream as l}from"node:tty";import{closeSync as u,constants as d,createWriteStream as f,existsSync as p,openSync as m,readSync as h,readdirSync as g,renameSync as _,statSync as v}from"node:fs";import{basename as y,delimiter as b,dirname as x,join as S,normalize as ee,resolve as C}from"node:path";import{copyFile as w,mkdir as T,mkdtemp as te,readFile as E,readdir as ne,rm as D,writeFile as O}from"node:fs/promises";import{PassThrough as re,Readable as ie,pipeline as ae}from"node:stream";import{pipeline as oe}from"node:stream/promises";import{spawn as se}from"node:child_process";import{homedir as ce,tmpdir as le}from"node:os";var ue=Object.defineProperty,de=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),fe=(e,t)=>{let n={};for(var r in e)ue(n,r,{get:e[r],enumerable:!0});return t||ue(n,Symbol.toStringTag,{value:`Module`}),n};const pe=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),me=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,he=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,ge=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,_e=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,ve=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,ye=/\t{1,1000}/y,be=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy,xe=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Se=/\p{M}+/gu,Ce={limit:1/0,ellipsis:``},we=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?we(i,Ce,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[xe,l],[ge,0],[_e,o],[ye,s],[be,c],[ve,u]],f=0,p=0,m=e.length,h=0,g=!1,_=m,v=Math.max(0,r-a),y=0,b=0,x=0,S=0;outer:for(;;){if(b>y||p>=m&&p>f){let t=e.slice(y,b)||e.slice(f,p);h=0;for(let e of t.replaceAll(Se,``)){let t=e.codePointAt(0)||0;if(S=me(t)?2:he(t)?u:l,x+S>v&&(_=Math.min(_,Math.max(y,f)+h)),x+S>r){g=!0;break outer}h+=e.length,x+=S}y=b=0}if(p>=m)break outer;for(let t=0,n=d.length;t<n;t++){let[n,i]=d[t];if(n.lastIndex=p,n.test(e)){if(h=n===ve?pe(e.slice(p,n.lastIndex)):n===be?1:n.lastIndex-p,S=h*i,x+S>v&&(_=Math.min(_,p+Math.floor((v-x)/i))),x+S>r){g=!0;break outer}x+=S,y=f,b=p,p=f=n.lastIndex;continue outer}}p+=1}return{width:g?v:x,index:g?_:m,truncated:g,ellipsed:g&&r>=a}},Te={limit:1/0,ellipsis:``,ellipsisWidth:0},k=(e,t={})=>we(e,Te,t).width,Ee=`]8;;`,De=RegExp(`(?:\\[(?<code>\\d+)m|\\${Ee}(?<uri>.*))`,`y`),Oe=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},ke=e=>`[${e}m`,Ae=e=>`${Ee}${e}`,je=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:k(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=k(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===``)&&(i=!0,a=t.startsWith(Ee,u+1)),i?a?o===`\x07`&&(i=!1,a=!1):o===`m`&&(i=!1):(s+=d,s===n&&!l.done&&(e.push(``),s=0)),c=l,l=r.next(),u+=o.length}o=e.at(-1),!s&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},Me=e=>{let t=e.split(` `),n=t.length;for(;n&&!k(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},Ne=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=e.split(` `),s=[``],c=0;for(let e=0;e<o.length;e++){let r=o[e];if(n.trim!==!1){let e=s.at(-1)??``,t=e.trimStart();e.length!==t.length&&(s[s.length-1]=t,c=k(t))}e!==0&&(c>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),c=0),(c||n.trim===!1)&&(s[s.length-1]+=` `,c++));let i=k(r);if(n.hard&&i>t){let e=t-c,n=1+Math.floor((i-e-1)/t);Math.floor((i-1)/t)<n&&s.push(``),je(s,r,t),c=k(s.at(-1)??``);continue}if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){je(s,r,t),c=k(s.at(-1)??``);continue}s.push(``),c=0}if(c+i>t&&n.wordWrap===!1){je(s,r,t),c=k(s.at(-1)??``);continue}s[s.length-1]+=r,c+=i}n.trim!==!1&&(s=s.map(e=>Me(e)));let l=s.join(`
|
|
3
|
+
`),u=!1;for(let e=0;e<l.length;e++){let t=l[e];if(r+=t,u)u=!1;else if(u=t>=`\ud800`&&t<=`\udbff`,u)continue;if(t===`\x1B`||t===``){De.lastIndex=e+1;let t=De.exec(l)?.groups;if(t?.code!==void 0){let e=Number.parseFloat(t.code);i=e===39?void 0:e}else t?.uri!==void 0&&(a=t.uri.length===0?void 0:t.uri)}if(l[e+1]===`
|
|
4
|
+
`){a&&(r+=Ae(``));let e=i?Oe(i):void 0;i&&e&&(r+=ke(e))}else t===`
|
|
5
|
+
`&&(i&&Oe(i)&&(r+=ke(i)),a&&(r+=Ae(a)))}return r},Pe=/\r?\n/;function A(e,t,n){return String(e).normalize().split(Pe).map(e=>Ne(e,t,n)).join(`
|
|
6
|
+
`)}var j=de(((e,t)=>{let n={to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e,t){let n=``;return e<0?n+=`[${-e}D`:e>0&&(n+=`[${e}C`),t<0?n+=`[${-t}A`:t>0&&(n+=`[${t}B`),n},up:(e=1)=>`[${e}A`,down:(e=1)=>`[${e}B`,forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),left:`\x1B[G`,hide:`\x1B[?25l`,show:`\x1B[?25h`,save:`\x1B7`,restore:`\x1B8`};t.exports={cursor:n,scroll:{up:(e=1)=>`\x1B[S`.repeat(e),down:(e=1)=>`\x1B[T`.repeat(e)},erase:{screen:`\x1B[2J`,up:(e=1)=>`\x1B[1J`.repeat(e),down:(e=1)=>`\x1B[J`.repeat(e),line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,lines(e){let t=``;for(let r=0;r<e;r++)t+=this.line+(r<e-1?n.up():``);return e&&(t+=n.left),t}},beep:`\x07`}}))();function Fe(e,t,n){if(!n.some(e=>!e.disabled))return e;let r=e+t,i=Math.max(n.length-1,0),a=r<0?i:r>i?0:r;return n[a].disabled?Fe(a,t<0?-1:1,n):a}const M={actions:new Set([`up`,`down`,`left`,`right`,`space`,`enter`,`cancel`]),aliases:new Map([[`k`,`up`],[`j`,`down`],[`h`,`left`],[`l`,`right`],[``,`cancel`],[`escape`,`cancel`]]),messages:{cancel:`Canceled`,error:`Something went wrong`},withGuide:!0,date:{monthNames:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],messages:{required:`Please enter a valid date`,invalidMonth:`There are only 12 months in a year`,invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function Ie(e,t){if(typeof e==`string`)return M.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Ie(n,t))return!0;return!1}function Le(e,t){if(e===t)return;let n=e.split(`
|
|
7
7
|
`),r=t.split(`
|
|
8
|
-
`),i=Math.max(n.length,r.length),a=[];for(let e=0;e<i;e++)n[e]!==r[e]&&a.push(e);return{lines:a,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}const
|
|
8
|
+
`),i=Math.max(n.length,r.length),a=[];for(let e=0;e<i;e++)n[e]!==r[e]&&a.push(e);return{lines:a,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}const Re=globalThis.process.platform.startsWith(`win`),ze=Symbol(`clack:cancel`);function Be(e){return e===ze}function N(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Ve({input:e=a,output:t=o,overwrite:n=!0,hideCursor:r=!0}={}){let i=s.createInterface({input:e,output:t,prompt:``,tabSize:1});s.emitKeypressEvents(e,i),e instanceof l&&e.isTTY&&e.setRawMode(!0);let c=(i,{name:a,sequence:o})=>{if(Ie([String(i),a,o],`cancel`)){r&&t.write(j.cursor.show),process.exit(0);return}if(!n)return;let l=a===`return`?0:-1,u=a===`return`?-1:0;s.moveCursor(t,l,u,()=>{s.clearLine(t,1,()=>{e.once(`keypress`,c)})})};return r&&t.write(j.cursor.hide),e.once(`keypress`,c),()=>{e.off(`keypress`,c),r&&t.write(j.cursor.show),e instanceof l&&e.isTTY&&!Re&&e.setRawMode(!1),i.terminal=!1,i.close()}}const P=e=>`columns`in e&&typeof e.columns==`number`?e.columns:80,He=e=>`rows`in e&&typeof e.rows==`number`?e.rows:20;function F(e,t,n,r=n,i=n,a){return A(t,P(e??o)-n.length,{hard:!0,trim:!1}).split(`
|
|
9
9
|
`).map((e,t,o)=>{let s=a?a(e,t):e;return t===0?`${r}${s}`:t===o.length-1?`${i}${s}`:`${n}${s}`}).join(`
|
|
10
|
-
`)}let
|
|
11
|
-
`),
|
|
12
|
-
`).length-1;this.output.write(
|
|
13
|
-
`);this.output.write(t[a]),this._prevFrame=e,this.output.write(
|
|
10
|
+
`)}function Ue(e,t){if(`~standard`in e){let n=e[`~standard`].validate(t);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return e(t)}var We=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame=``;_subscribers=new Map;_cursor=0;state=`initial`;error=``;value;userInput=``;constructor(e,t=!0){let{input:n=a,output:r=o,render:i,signal:s,...c}=e;this.opts=c,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=t,this._abortSignal=s,this.input=n,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],r=[];for(let e of n)e.cb(...t),e.once&&r.push(()=>n.splice(n.indexOf(e),1));for(let e of r)e()}prompt(){return new Promise(e=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state=`cancel`,this.close(),e(ze);this._abortSignal.addEventListener(`abort`,()=>{this.state=`cancel`,this.close()},{once:!0})}this.rl=c.createInterface({input:this.input,tabSize:2,prompt:``,escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on(`keypress`,this.onKeypress),N(this.input,!0),this.output.on(`resize`,this.render),this.render(),this.once(`submit`,()=>{this.output.write(j.cursor.show),this.output.off(`resize`,this.render),N(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(j.cursor.show),this.output.off(`resize`,this.render),N(this.input,!1),e(ze)})})}_isActionKey(e,t){return e===` `}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit(`value`,this.value)}_setUserInput(e,t){this.userInput=e??``,this.emit(`userInput`,this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:`u`}),this._setUserInput(``)}onKeypress(e,t){if(this._track&&t.name!==`return`&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:`h`}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state===`error`&&(this.state=`active`),t?.name&&(!this._track&&M.aliases.has(t.name)&&this.emit(`cursor`,M.aliases.get(t.name)),M.actions.has(t.name)&&this.emit(`cursor`,t.name)),e&&(e.toLowerCase()===`y`||e.toLowerCase()===`n`)&&this.emit(`confirm`,e.toLowerCase()===`y`),this.emit(`key`,e,t),t?.name===`return`&&this._shouldSubmit(e,t)){if(this.opts.validate){let e=Ue(this.opts.validate,this.value);e&&(this.error=e instanceof Error?e.message:e,this.state=`error`,this.rl?.write(this.userInput))}this.state!==`error`&&(this.state=`submit`)}Ie([e,t?.name,t?.sequence],`cancel`)&&(this.state=`cancel`),(this.state===`submit`||this.state===`cancel`)&&this.emit(`finalize`),this.render(),(this.state===`submit`||this.state===`cancel`)&&this.close()}close(){this.input.unpipe(),this.input.removeListener(`keypress`,this.onKeypress),this.output.write(`
|
|
11
|
+
`),N(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=A(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
12
|
+
`).length-1;this.output.write(j.cursor.move(-999,e*-1))}render(){let e=A(this._render(this)??``,process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state===`initial`)this.output.write(j.cursor.hide);else{let t=Le(this._prevFrame,e),n=He(this.output);if(this.restoreCursor(),t){let r=Math.max(0,t.numLinesAfter-n),i=Math.max(0,t.numLinesBefore-n),a=t.lines.find(e=>e>=r);if(a===void 0){this._prevFrame=e;return}if(t.lines.length===1){this.output.write(j.cursor.move(0,a-i)),this.output.write(j.erase.lines(1));let t=e.split(`
|
|
13
|
+
`);this.output.write(t[a]),this._prevFrame=e,this.output.write(j.cursor.move(0,t.length-a-1));return}else if(t.lines.length>1){if(r<i)a=r;else{let e=a-i;e>0&&this.output.write(j.cursor.move(0,e))}this.output.write(j.erase.down());let t=e.split(`
|
|
14
14
|
`).slice(a);this.output.write(t.join(`
|
|
15
|
-
`)),this._prevFrame=e;return}}this.output.write(
|
|
16
|
-
`);_.push(i),v+=i.length}if(v>d){let t=0,n=0,r=v,i=e-y,a=d,o=()=>
|
|
15
|
+
`)),this._prevFrame=e;return}}this.output.write(j.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},Ge=class extends We{get cursor(){return+!this.value}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on(`userInput`,()=>{this.value=this._value}),this.on(`confirm`,e=>{this.output.write(j.cursor.move(0,-1)),this.value=e,this.state=`submit`,this.close()}),this.on(`cursor`,()=>{this.value=!this.value})}},Ke=class extends We{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){this.value=this._selectedValue.value}constructor(e){super(e,!1),this.options=e.options;let t=this.options.findIndex(({value:t})=>t===e.initialValue),n=t===-1?0:t;this.cursor=this.options[n].disabled?Fe(n,1,this.options):n,this.changeValue(),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=Fe(this.cursor,-1,this.options);break;case`down`:case`right`:this.cursor=Fe(this.cursor,1,this.options);break}this.changeValue()})}},qe=class extends We{get userInputWithCursor(){if(this.state===`submit`)return this.userInput;let e=this.userInput;if(this.cursor>=e.length)return`${this.userInput}\u2588`;let t=e.slice(0,this.cursor),[r,...i]=e.slice(this.cursor);return`${t}${n(`inverse`,r)}${i.join(``)}`}get cursor(){return this._cursor}constructor(e){super({...e,initialUserInput:e.initialUserInput??e.initialValue}),this.on(`userInput`,e=>{this._setValue(e)}),this.on(`finalize`,()=>{this.value||=e.defaultValue,this.value===void 0&&(this.value=``)})}};function Je(){return r.platform===`win32`?!!r.env.CI||!!r.env.WT_SESSION||!!r.env.TERMINUS_SUBLIME||r.env.ConEmuTask===`{cmd::Cmder}`||r.env.TERM_PROGRAM===`Terminus-Sublime`||r.env.TERM_PROGRAM===`vscode`||r.env.TERM===`xterm-256color`||r.env.TERM===`alacritty`||r.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:r.env.TERM!==`linux`}const Ye=Je(),Xe=()=>process.env.CI===`true`,Ze=e=>e.isTTY===!0,I=(e,t)=>Ye?e:t,Qe=I(`◆`,`*`),$e=I(`■`,`x`),et=I(`▲`,`x`),L=I(`◇`,`o`),R=I(`│`,`|`),z=I(`└`,`—`),tt=I(`●`,`>`),B=I(`○`,` `),nt=I(`─`,`-`),rt=I(`╮`,`+`),it=I(`├`,`+`),at=I(`╯`,`+`),ot=I(`╰`,`+`),st=I(`●`,`•`),ct=I(`◆`,`*`),lt=I(`▲`,`!`),ut=I(`■`,`x`),dt=e=>{switch(e){case`initial`:case`active`:return n(`cyan`,Qe);case`cancel`:return n(`red`,$e);case`error`:return n(`yellow`,et);case`submit`:return n(`green`,L)}},ft=e=>{switch(e){case`initial`:case`active`:return n(`cyan`,R);case`cancel`:return n(`red`,R);case`error`:return n(`yellow`,R);case`submit`:return n(`green`,R)}};function pt(e,t){let r=[`${t?`${n(`cyan`,R)} `:``}${e.join(` • `)}`];return t&&r.push(n(`cyan`,z)),r}const mt=(e,t,n,r,i,a=!1)=>{let o=t,s=0;if(a)for(let t=r-1;t>=n&&(o-=e[t].length,s++,!(o<=i));t--);else for(let t=n;t<r&&(o-=e[t].length,s++,!(o<=i));t++);return{lineCount:o,removals:s}},ht=({cursor:e,options:t,style:r,output:i=process.stdout,maxItems:a=1/0,columnPadding:o=0,rowPadding:s=4})=>{let c=P(i)-o,l=He(i),u=n(`dim`,`...`),d=Math.max(l-s,0),f=Math.max(Math.min(a,d),5),p=0;e>=f-3&&(p=Math.max(Math.min(e-f+3,t.length-f),0));let m=f<t.length&&p>0,h=f<t.length&&p+f<t.length,g=Math.min(p+f,t.length),_=[],v=0;m&&v++,h&&v++;let y=p+ +!!m,b=g-+!!h;for(let n=y;n<b;n++){let i=A(r(t[n],n===e),c,{hard:!0,trim:!1}).split(`
|
|
16
|
+
`);_.push(i),v+=i.length}if(v>d){let t=0,n=0,r=v,i=e-y,a=d,o=()=>mt(_,r,0,i,a),s=()=>mt(_,r,i+1,_.length,a,!0);m?({lineCount:r,removals:t}=o(),r>a&&(h||--a,{lineCount:r,removals:n}=s())):(h||--a,{lineCount:r,removals:n}=s(),r>a&&(--a,{lineCount:r,removals:t}=o())),t>0&&(m=!0,_.splice(0,t)),n>0&&(h=!0,_.splice(_.length-n,n))}let x=[];m&&x.push(u);for(let e of _)for(let t of e)x.push(t);return h&&x.push(u),x},gt=e=>{let t=e.active??`Yes`,r=e.inactive??`No`;return new Ge({active:t,inactive:r,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let i=e.withGuide??M.withGuide,a=`${dt(this.state)} `,o=i?`${n(`gray`,R)} `:``,s=F(e.output,e.message,o,a),c=`${i?`${n(`gray`,R)}
|
|
17
17
|
`:``}${s}
|
|
18
|
-
`,l=this.value?t:
|
|
19
|
-
${
|
|
20
|
-
${
|
|
21
|
-
`:` ${
|
|
18
|
+
`,l=this.value?t:r;switch(this.state){case`submit`:return`${c}${i?`${n(`gray`,R)} `:``}${n(`dim`,l)}`;case`cancel`:return`${c}${i?`${n(`gray`,R)} `:``}${n([`strikethrough`,`dim`],l)}${i?`
|
|
19
|
+
${n(`gray`,R)}`:``}`;default:{let a=i?`${n(`cyan`,R)} `:``,o=i?n(`cyan`,z):``;return`${c}${a}${this.value?`${n(`green`,tt)} ${t}`:`${n(`dim`,B)} ${n(`dim`,t)}`}${e.vertical?i?`
|
|
20
|
+
${n(`cyan`,R)} `:`
|
|
21
|
+
`:` ${n(`dim`,`/`)} `}${this.value?`${n(`dim`,B)} ${n(`dim`,r)}`:`${n(`green`,tt)} ${r}`}
|
|
22
22
|
${o}
|
|
23
|
-
`}}}}).prompt()}
|
|
24
|
-
`);if(f.length>0){let[e,...
|
|
23
|
+
`}}}}).prompt()};`${n(`dim`,`↑/↓`)}`,`${n(`dim`,`Space:`)}`,`${n(`dim`,`Enter:`)}`;const V={message:(e=[],{symbol:t=n(`gray`,R),secondarySymbol:r=n(`gray`,R),output:i=process.stdout,spacing:a=1,withGuide:o}={})=>{let s=[],c=o??M.withGuide,l=c?r:``,u=c?`${t} `:``,d=c?`${r} `:``;for(let e=0;e<a;e++)s.push(l);let f=Array.isArray(e)?e:e.split(`
|
|
24
|
+
`);if(f.length>0){let[e,...n]=f;e.length>0?s.push(`${u}${e}`):s.push(c?t:``);for(let e of n)e.length>0?s.push(`${d}${e}`):s.push(c?r:``)}i.write(`${s.join(`
|
|
25
25
|
`)}
|
|
26
|
-
`)},info:(e,t)=>{
|
|
26
|
+
`)},info:(e,t)=>{V.message(e,{...t,symbol:n(`blue`,st)})},success:(e,t)=>{V.message(e,{...t,symbol:n(`green`,ct)})},step:(e,t)=>{V.message(e,{...t,symbol:n(`green`,L)})},warn:(e,t)=>{V.message(e,{...t,symbol:n(`yellow`,lt)})},warning:(e,t)=>{V.warn(e,t)},error:(e,t)=>{V.message(e,{...t,symbol:n(`red`,ut)})}},H=(e=``,t)=>{let r=t?.output??process.stdout,i=t?.withGuide??M.withGuide?`${n(`gray`,z)} `:``;r.write(`${i}${n(`red`,e)}
|
|
27
27
|
|
|
28
|
-
`)},
|
|
29
|
-
${
|
|
28
|
+
`)},_t=(e=``,t)=>{let r=t?.output??process.stdout,i=t?.withGuide??M.withGuide?`${n(`gray`,R)}
|
|
29
|
+
${n(`gray`,z)} `:``;r.write(`${i}${e}
|
|
30
30
|
|
|
31
|
-
`)},
|
|
32
|
-
`),a=i.reduce((e,t)=>Math.max(
|
|
33
|
-
`).map(s),``],l=
|
|
34
|
-
`),f=
|
|
35
|
-
`:``,p=
|
|
31
|
+
`)},vt=e=>e,yt=(e,t,n)=>{let r={hard:!0,trim:!1},i=A(e,t,r).split(`
|
|
32
|
+
`),a=i.reduce((e,t)=>Math.max(k(t),e),0);return A(e,t-(i.map(n).reduce((e,t)=>Math.max(k(t),e),0)-a),r)},bt=(e=``,t=``,i)=>{let a=i?.output??r.stdout,o=i?.withGuide??M.withGuide,s=i?.format??vt,c=[``,...yt(e,P(a)-6,s).split(`
|
|
33
|
+
`).map(s),``],l=k(t),u=Math.max(c.reduce((e,t)=>{let n=k(t);return n>e?n:e},0),l)+2,d=c.map(e=>`${n(`gray`,R)} ${e}${` `.repeat(u-k(e))}${n(`gray`,R)}`).join(`
|
|
34
|
+
`),f=o?`${n(`gray`,R)}
|
|
35
|
+
`:``,p=o?it:ot;a.write(`${f}${n(`green`,L)} ${n(`reset`,t)} ${n(`gray`,nt.repeat(Math.max(u-l-1,1))+rt)}
|
|
36
36
|
${d}
|
|
37
|
-
${
|
|
38
|
-
`)},
|
|
39
|
-
`);let e=
|
|
40
|
-
`);e.length>1&&
|
|
41
|
-
`);let
|
|
42
|
-
`):
|
|
43
|
-
`)),
|
|
37
|
+
${n(`gray`,p+nt.repeat(u+2)+at)}
|
|
38
|
+
`)},xt=e=>n(`magenta`,e),St=({indicator:e=`dots`,onCancel:t,output:r=process.stdout,cancelMessage:i,errorMessage:a,frames:o=Ye?[`◒`,`◐`,`◓`,`◑`]:[`•`,`o`,`O`,`0`],delay:s=Ye?80:120,signal:c,...l}={})=>{let u=Xe(),d,f,p=!1,m=!1,h=``,g,_=performance.now(),v=P(r),y=l?.styleFrame??xt,b=e=>{let n=e>1?a??M.messages.error:i??M.messages.cancel;m=e===1,p&&(D(n,e),m&&typeof t==`function`&&t())},x=()=>b(2),S=()=>b(1),ee=()=>{process.on(`uncaughtExceptionMonitor`,x),process.on(`unhandledRejection`,x),process.on(`SIGINT`,S),process.on(`SIGTERM`,S),process.on(`exit`,b),c&&c.addEventListener(`abort`,S)},C=()=>{process.removeListener(`uncaughtExceptionMonitor`,x),process.removeListener(`unhandledRejection`,x),process.removeListener(`SIGINT`,S),process.removeListener(`SIGTERM`,S),process.removeListener(`exit`,b),c&&c.removeEventListener(`abort`,S)},w=()=>{if(g===void 0)return;u&&r.write(`
|
|
39
|
+
`);let e=A(g,v,{hard:!0,trim:!1}).split(`
|
|
40
|
+
`);e.length>1&&r.write(j.cursor.up(e.length-1)),r.write(j.cursor.to(0)),r.write(j.erase.down())},T=e=>e.replace(/\.+$/,``),te=e=>{let t=(performance.now()-e)/1e3,n=Math.floor(t/60),r=Math.floor(t%60);return n>0?`[${n}m ${r}s]`:`[${r}s]`},E=l.withGuide??M.withGuide,ne=(t=``)=>{p=!0,d=Ve({output:r}),h=T(t),_=performance.now(),E&&r.write(`${n(`gray`,R)}
|
|
41
|
+
`);let i=0,a=0;ee(),f=setInterval(()=>{if(u&&h===g)return;w(),g=h;let t=y(o[i]),n;if(u)n=`${t} ${h}...`;else if(e===`timer`)n=`${t} ${h} ${te(_)}`;else{let e=`.`.repeat(Math.floor(a)).slice(0,3);n=`${t} ${h}${e}`}let s=A(n,v,{hard:!0,trim:!1});r.write(s),i=i+1<o.length?i+1:0,a=a<4?a+.125:0},s)},D=(t=``,i=0,a=!1)=>{if(!p)return;p=!1,clearInterval(f),w();let o=i===0?n(`green`,L):i===1?n(`red`,$e):n(`red`,et);h=t??h,a||(e===`timer`?r.write(`${o} ${h} ${te(_)}
|
|
42
|
+
`):r.write(`${o} ${h}
|
|
43
|
+
`)),C(),d()};return{start:ne,stop:(e=``)=>D(e,0),message:(e=``)=>{h=T(e??h)},cancel:(e=``)=>D(e,1),error:(e=``)=>D(e,2),clear:()=>D(``,0,!0),get isCancelled(){return m}}},Ct=[`${n(`dim`,`↑/↓`)} to navigate`,`${n(`dim`,`Enter:`)} confirm`],U=(e,t)=>e.includes(`
|
|
44
44
|
`)?e.split(`
|
|
45
45
|
`).map(e=>t(e)).join(`
|
|
46
|
-
`):t(e),
|
|
46
|
+
`):t(e),wt=e=>{let t=(e,t)=>{let r=e.label??String(e.value);switch(t){case`disabled`:return`${n(`gray`,B)} ${U(r,e=>n(`gray`,e))}${e.hint?` ${n(`dim`,`(${e.hint??`disabled`})`)}`:``}`;case`selected`:return`${U(r,e=>n(`dim`,e))}`;case`active`:return`${n(`green`,tt)} ${r}${e.hint?` ${n(`dim`,`(${e.hint})`)}`:``}`;case`cancelled`:return`${U(r,e=>n([`strikethrough`,`dim`],e))}`;default:return`${n(`dim`,B)} ${U(r,e=>n(`dim`,e))}`}};return new Ke({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let r=e.withGuide??M.withGuide,i=`${dt(this.state)} `,a=`${ft(this.state)} `,o=F(e.output,e.message,a,i),s=`${r?`${n(`gray`,R)}
|
|
47
47
|
`:``}${o}
|
|
48
|
-
`;switch(this.state){case`submit`:{let r
|
|
49
|
-
${
|
|
50
|
-
`).length,
|
|
51
|
-
${
|
|
52
|
-
${i}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`)
|
|
57
|
-
`)
|
|
58
|
-
${Dt}${t.trimStart()}`),n=3+i(t.trimStart()).length)}process.stdout.write(`
|
|
59
|
-
`)},info:e=>R.message(e,{symbol:a(`blue`,ut)}),success:e=>R.message(e,{symbol:a(`green`,dt)}),step:e=>R.message(e,{symbol:a(`green`,N)}),warn:e=>R.message(e,{symbol:a(`yellow`,ft)}),warning:e=>R.warn(e),error:e=>R.message(e,{symbol:a(`red`,pt)})},Ot=e=>e.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,``),kt=e=>{let t=e.output??process.stdout,n=j(t),r=a(`gray`,P),i=e.spacing??1,o=e.retainLog===!0,s=!Qe()&&$e(t);t.write(`${r}
|
|
60
|
-
`),t.write(`${a(`green`,N)} ${e.title}
|
|
61
|
-
`);for(let e=0;e<i;e++)t.write(`${r}
|
|
62
|
-
`);let c=[{value:``,full:``}],l=!1,u=e=>{if(c.length===0)return;let r=0;e&&(r+=i+2);for(let e of c){let{value:t,result:i}=e,a=i?.message??t;if(a.length===0)continue;i===void 0&&e.header!==void 0&&e.header!==``&&(a+=`
|
|
48
|
+
`;switch(this.state){case`submit`:{let i=r?`${n(`gray`,R)} `:``;return`${s}${F(e.output,t(this.options[this.cursor],`selected`),i)}`}case`cancel`:{let i=r?`${n(`gray`,R)} `:``;return`${s}${F(e.output,t(this.options[this.cursor],`cancelled`),i)}${r?`
|
|
49
|
+
${n(`gray`,R)}`:``}`}default:{let i=r?`${n(`cyan`,R)} `:``,a=s.split(`
|
|
50
|
+
`).length,o=pt(Ct,r),c=o.join(`
|
|
51
|
+
`),l=o.length+1;return`${s}${i}${ht({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:i.length,rowPadding:a+l,style:(e,n)=>t(e,e.disabled?`disabled`:n?`active`:`inactive`)}).join(`
|
|
52
|
+
${i}`)}
|
|
53
|
+
${c}
|
|
54
|
+
`}}}}).prompt()};`${n(`gray`,R)}`;const Tt=e=>e.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,``),Et=e=>{let t=e.output??process.stdout,r=P(t),i=n(`gray`,R),a=e.spacing??1,o=e.retainLog===!0,s=!Xe()&&Ze(t);t.write(`${i}
|
|
55
|
+
`),t.write(`${n(`green`,L)} ${e.title}
|
|
56
|
+
`);for(let e=0;e<a;e++)t.write(`${i}
|
|
57
|
+
`);let c=[{value:``,full:``}],l=!1,u=e=>{if(c.length===0)return;let n=0;e&&(n+=a+2);for(let e of c){let{value:t,result:i}=e,a=i?.message??t;if(a.length===0)continue;i===void 0&&e.header!==void 0&&e.header!==``&&(a+=`
|
|
63
58
|
${e.header}`);let o=a.split(`
|
|
64
|
-
`).reduce((e,t)=>t===``?e+1:e+Math.ceil((t.length+3)/
|
|
65
|
-
${e.value}`:e.value;e.header!==void 0&&e.header!==``&&
|
|
66
|
-
`).map(e=>
|
|
67
|
-
`).map(e=>
|
|
68
|
-
`),t.value+=
|
|
59
|
+
`).reduce((e,t)=>t===``?e+1:e+Math.ceil((t.length+3)/r),0);n+=o}n>0&&(n+=1,t.write(j.erase.lines(n)))},d=(e,r,o)=>{let s=o?`${e.full}
|
|
60
|
+
${e.value}`:e.value;e.header!==void 0&&e.header!==``&&V.message(e.header.split(`
|
|
61
|
+
`).map(e=>n(`bold`,e)),{output:t,secondarySymbol:i,symbol:i,spacing:0}),V.message(s.split(`
|
|
62
|
+
`).map(e=>n(`dim`,e)),{output:t,secondarySymbol:i,symbol:i,spacing:r??a})},f=()=>{for(let e of c){let{header:t,value:n,full:r}=e;(t===void 0||t.length===0)&&n.length===0||d(e,void 0,o===!0&&r.length>0)}},p=(t,n,r)=>{if(u(!1),(r?.raw!==!0||!l)&&t.value!==``&&(t.value+=`
|
|
63
|
+
`),t.value+=Tt(n),l=r?.raw===!0,e.limit!==void 0){let n=t.value.split(`
|
|
69
64
|
`),r=n.length-e.limit;if(r>0){let e=n.splice(0,r);o&&(t.full+=(t.full===``?``:`
|
|
70
65
|
`)+e.join(`
|
|
71
66
|
`))}t.value=n.join(`
|
|
72
|
-
`)}s&&m()},m=()=>{for(let e of c)e.result?e.result.status===`error`?
|
|
73
|
-
`:``}${
|
|
74
|
-
`,
|
|
75
|
-
${
|
|
67
|
+
`)}s&&m()},m=()=>{for(let e of c)e.result?e.result.status===`error`?V.error(e.result.message,{output:t,secondarySymbol:i,spacing:0}):V.success(e.result.message,{output:t,secondarySymbol:i,spacing:0}):e.value!==``&&d(e,0)},h=(e,t)=>{u(!1),e.result=t,s&&m()};return{message(e,t){p(c[0],e,t)},group(e){let t={header:e,value:``,full:``};return c.push(t),{message(e,n){p(t,e,n)},error(e){h(t,{status:`error`,message:e})},success(e){h(t,{status:`success`,message:e})}}},error(e,n){u(!0),V.error(e,{output:t,secondarySymbol:i,spacing:1}),n?.showLog!==!1&&f(),c.splice(1,c.length-1),c[0].value=``,c[0].full=``},success(e,n){u(!0),V.success(e,{output:t,secondarySymbol:i,spacing:1}),n?.showLog===!0&&f(),c.splice(1,c.length-1),c[0].value=``,c[0].full=``}}},Dt=e=>new qe({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??M.withGuide,r=`${`${t?`${n(`gray`,R)}
|
|
68
|
+
`:``}${dt(this.state)} `}${e.message}
|
|
69
|
+
`,i=e.placeholder?n(`inverse`,e.placeholder[0])+n(`dim`,e.placeholder.slice(1)):n([`inverse`,`hidden`],`_`),a=this.userInput?this.userInputWithCursor:i,o=this.value??``;switch(this.state){case`error`:{let e=this.error?` ${n(`yellow`,this.error)}`:``,i=t?`${n(`yellow`,R)} `:``,o=t?n(`yellow`,z):``;return`${r.trim()}
|
|
70
|
+
${i}${a}
|
|
76
71
|
${o}${e}
|
|
77
|
-
`}case`submit`:{let e=o?` ${
|
|
78
|
-
${
|
|
79
|
-
${t?
|
|
80
|
-
`}}}).prompt(),
|
|
81
|
-
`)}function
|
|
82
|
-
`)}catch(e){console.error(e)}}const
|
|
83
|
-
`)}function
|
|
84
|
-
`),process.exit(1)}}async function un(e){let t=await B(e.args||{}),n=new Set,r=new Set;for(let[e,i]of Object.entries(t)){n.add(e);for(let e of z(i.alias))r.add(e)}return{help:dn(`help`,`h`,n,r),version:dn(`version`,`v`,n,r)}}function dn(e,t,n,r){return n.has(e)||r.has(e)?[]:n.has(t)||r.has(t)?[`--${e}`]:[`--${e}`,`-${t}`]}var fn=pe({a:()=>W,n:()=>Sn,r:()=>xn,t:()=>Zn});const pn=/^[A-Za-z]:\//;function U(e=``){return e&&e.replace(/\\/g,`/`).replace(pn,e=>e.toUpperCase())}const mn=/^[/\\]{2}/,hn=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,gn=/^[A-Za-z]:$/,_n=function(e){if(e.length===0)return`.`;e=U(e);let t=e.match(mn),n=G(e),r=e[e.length-1]===`/`;return e=bn(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),gn.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!G(e)?`/${e}`:e)},vn=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return _n(t)};function yn(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}const W=function(...e){e=e.map(e=>U(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:yn();!i||i.length===0||(t=`${i}/${t}`,n=G(i))}return t=bn(t,!n),n&&!G(t)?`/${t}`:t.length>0?t:`.`};function bn(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}const G=function(e){return hn.test(e)},xn=function(e){let t=U(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&gn.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(G(e)?`/`:`.`)},Sn=function(e,t){let n=U(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r};globalThis.process?.platform;var K=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),q=t(import.meta.url);const Cn=/^path$/i,wn={key:`PATH`,value:``};function Tn(e){for(let t in e){if(!Object.prototype.hasOwnProperty.call(e,t)||!Cn.test(t))continue;let n=e[t];return n?{key:t,value:n}:wn}return wn}function En(e,t){let n=t.value.split(y),r=[],i=e,a;do r.push(ee(i,`node_modules`,`.bin`)),a=i,i=b(i);while(i!==a);let o=r.concat(n).join(y);return{key:t.key,value:o}}function Dn(e,t){let n={...process.env,...t},r=En(e,Tn(n));return n[r.key]=r.value,n}const On=e=>{let t=e.length,n=new ie,r=()=>{--t===0&&n.emit(`end`)};for(let t of e)t.pipe(n,{end:!1}),t.on(`end`,r);return n};var kn=K(((e,t)=>{t.exports=a,a.sync=o;var n=q(`fs`);function r(e,t){var n=t.pathExt===void 0?process.env.PATHEXT:t.pathExt;if(!n||(n=n.split(`;`),n.indexOf(``)!==-1))return!0;for(var r=0;r<n.length;r++){var i=n[r].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,n){return!e.isSymbolicLink()&&!e.isFile()?!1:r(t,n)}function a(e,t,r){n.stat(e,function(n,a){r(n,n?!1:i(a,e,t))})}function o(e,t){return i(n.statSync(e),e,t)}})),An=K(((e,t)=>{t.exports=r,r.sync=i;var n=q(`fs`);function r(e,t,r){n.stat(e,function(e,n){r(e,e?!1:a(n,t))})}function i(e,t){return a(n.statSync(e),t)}function a(e,t){return e.isFile()&&o(e,t)}function o(e,t){var n=e.mode,r=e.uid,i=e.gid,a=t.uid===void 0?process.getuid&&process.getuid():t.uid,o=t.gid===void 0?process.getgid&&process.getgid():t.gid,s=64,c=8,l=1,u=s|c;return n&l||n&c&&i===o||n&s&&r===a||n&u&&a===0}})),jn=K(((e,t)=>{q(`fs`);var n=process.platform===`win32`||global.TESTING_WINDOWS?kn():An();t.exports=r,r.sync=i;function r(e,t,i){if(typeof t==`function`&&(i=t,t={}),!i){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(n,i){r(e,t||{},function(e,t){e?i(e):n(t)})})}n(e,t||{},function(e,n){e&&(e.code===`EACCES`||t&&t.ignoreErrors)&&(e=null,n=!1),i(e,n)})}function i(e,t){try{return n.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code===`EACCES`)return!1;throw e}}})),Mn=K(((e,t)=>{let n=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,r=q(`path`),i=n?`;`:`:`,a=jn(),o=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),s=(e,t)=>{let r=t.colon||i,a=e.match(/\//)||n&&e.match(/\\/)?[``]:[...n?[process.cwd()]:[],...(t.path||process.env.PATH||``).split(r)],o=n?t.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,s=n?o.split(r):[``];return n&&e.indexOf(`.`)!==-1&&s[0]!==``&&s.unshift(``),{pathEnv:a,pathExt:s,pathExtExe:o}},c=(e,t,n)=>{typeof t==`function`&&(n=t,t={}),t||={};let{pathEnv:i,pathExt:c,pathExtExe:l}=s(e,t),u=[],d=n=>new Promise((a,s)=>{if(n===i.length)return t.all&&u.length?a(u):s(o(e));let c=i[n],l=/^".*"$/.test(c)?c.slice(1,-1):c,d=r.join(l,e);a(f(!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d,n,0))}),f=(e,n,r)=>new Promise((i,o)=>{if(r===c.length)return i(d(n+1));let s=c[r];a(e+s,{pathExt:l},(a,o)=>{if(!a&&o)if(t.all)u.push(e+s);else return i(e+s);return i(f(e,n,r+1))})});return n?d(0).then(e=>n(null,e),n):d(0)};t.exports=c,c.sync=(e,t)=>{t||={};let{pathEnv:n,pathExt:i,pathExtExe:c}=s(e,t),l=[];for(let o=0;o<n.length;o++){let s=n[o],u=/^".*"$/.test(s)?s.slice(1,-1):s,d=r.join(u,e),f=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;for(let e=0;e<i.length;e++){let n=f+i[e];try{if(a.sync(n,{pathExt:c}))if(t.all)l.push(n);else return n}catch{}}}if(t.all&&l.length)return l;if(t.nothrow)return null;throw o(e)}})),Nn=K(((e,t)=>{let n=(e={})=>{let t=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};t.exports=n,t.exports.default=n})),Pn=K(((e,t)=>{let n=q(`path`),r=Mn(),i=Nn();function a(e,t){let a=e.options.env||process.env,o=process.cwd(),s=e.options.cwd!=null,c=s&&process.chdir!==void 0&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch{}let l;try{l=r.sync(e.command,{path:a[i({env:a})],pathExt:t?n.delimiter:void 0})}catch{}finally{c&&process.chdir(o)}return l&&=n.resolve(s?e.options.cwd:``,l),l}function o(e){return a(e)||a(e,!0)}t.exports=o})),Fn=K(((e,t)=>{let n=/([()\][%!^"`<>&|;, *?])/g;function r(e){return e=e.replace(n,`^$1`),e}function i(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(n,`^$1`),t&&(e=e.replace(n,`^$1`)),e}t.exports.command=r,t.exports.argument=i})),In=K(((e,t)=>{t.exports=/^#!(.*)/})),Ln=K(((e,t)=>{let n=In();t.exports=(e=``)=>{let t=e.match(n);if(!t)return null;let[r,i]=t[0].replace(/#! ?/,``).split(` `),a=r.split(`/`).pop();return a===`env`?i:i?`${a} ${i}`:a}})),Rn=K(((e,t)=>{let n=q(`fs`),r=Ln();function i(e){let t=Buffer.alloc(150),i;try{i=n.openSync(e,`r`),n.readSync(i,t,0,150,0),n.closeSync(i)}catch{}return r(t.toString())}t.exports=i})),zn=K(((e,t)=>{let n=q(`path`),r=Pn(),i=Fn(),a=Rn(),o=process.platform===`win32`,s=/\.(?:com|exe)$/i,c=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function l(e){e.file=r(e);let t=e.file&&a(e.file);return t?(e.args.unshift(e.file),e.command=t,r(e)):e.file}function u(e){if(!o)return e;let t=l(e),r=!s.test(t);if(e.options.forceShell||r){let r=c.test(t);e.command=n.normalize(e.command),e.command=i.command(e.command),e.args=e.args.map(e=>i.argument(e,r)),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 d(e,t,n){t&&!Array.isArray(t)&&(n=t,t=null),t=t?t.slice(0):[],n=Object.assign({},n);let r={command:e,args:t,options:n,file:void 0,original:{command:e,args:t}};return n.shell?r:u(r)}t.exports=d})),Bn=K(((e,t)=>{let n=process.platform===`win32`;function r(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function i(e,t){if(!n)return;let r=e.emit;e.emit=function(n,i){if(n===`exit`){let n=a(i,t);if(n)return r.call(e,`error`,n)}return r.apply(e,arguments)}}function a(e,t){return n&&e===1&&!t.file?r(t.original,`spawn`):null}function o(e,t){return n&&e===1&&!t.file?r(t.original,`spawnSync`):null}t.exports={hookChildProcess:i,verifyENOENT:a,verifyENOENTSync:o,notFoundError:r}})),Vn=K(((e,t)=>{let n=q(`child_process`),r=zn(),i=Bn();function a(e,t,a){let o=r(e,t,a),s=n.spawn(o.command,o.args,o.options);return i.hookChildProcess(s,o),s}function o(e,t,a){let o=r(e,t,a),s=n.spawnSync(o.command,o.args,o.options);return s.error=s.error||i.verifyENOENTSync(s.status,o),s}t.exports=a,t.exports.spawn=a,t.exports.sync=o,t.exports._parse=r,t.exports._enoent=i}))(),Hn=class extends Error{result;output;get exitCode(){if(this.result.exitCode!==null)return this.result.exitCode}constructor(e,t){super(`Process exited with non-zero status (${e.exitCode})`),this.result=e,this.output=t}};const Un={timeout:void 0,persist:!1},Wn={windowsHide:!0};function Gn(e,t){return{command:S(e),args:t??[]}}function Kn(e){let t=new AbortController;for(let n of e){if(n.aborted)return t.abort(),n;n.addEventListener(`abort`,()=>{t.abort(n.reason)},{signal:t.signal})}return t.signal}async function qn(e){let t=``;for await(let n of e)t+=n.toString();return t}var Jn=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,t,n){this._options={...Un,...n},this._command=e,this._args=t??[],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,t,n){return Xn(e,t,{...n,stdin:this})}async*[Symbol.asyncIterator](){let e=this._process;if(!e)return;let t=[];this._streamErr&&t.push(this._streamErr),this._streamOut&&t.push(this._streamOut);let n=On(t),r=d.createInterface({input:n});for await(let e of r)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 Hn(this)}async _waitForOutput(){let e=this._process;if(!e)throw Error(`No process was started`);let[t,n]=await Promise.all([this._streamOut?qn(this._streamOut):``,this._streamErr?qn(this._streamErr):``]);if(await this._processClosed,this._options?.stdin&&await this._options.stdin,e.removeAllListeners(),this._thrownError)throw this._thrownError;let r={stderr:n,stdout:t,exitCode:this.exitCode};if(this._options.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new Hn(this,r);return r}then(e,t){return this._waitForOutput().then(e,t)}_streamOut;_streamErr;spawn(){let e=s(),t=this._options,n={...Wn,...t.nodeOptions},r=[];this._resetState(),t.timeout!==void 0&&r.push(AbortSignal.timeout(t.timeout)),t.signal!==void 0&&r.push(t.signal),t.persist===!0&&(n.detached=!0),r.length>0&&(n.signal=Kn(r)),n.env=Dn(e,n.env);let{command:i,args:a}=Gn(this._command,this._args),o=(0,Vn._parse)(i,a,n),c=se(o.command,o.args,o.options);if(c.stderr&&(this._streamErr=c.stderr),c.stdout&&(this._streamOut=c.stdout),this._process=c,c.once(`error`,this._onError),c.once(`close`,this._onClose),t.stdin!==void 0&&c.stdin&&t.stdin.process){let{stdout:e}=t.stdin.process;e&&e.pipe(c.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 Yn=(e,t,n)=>{let r=new Jn(e,t,n);return r.spawn(),r},Xn=Yn;var Zn=e({detectPackageManager:()=>ir,installDependencies:()=>ar,packageManagers:()=>J});async function Qn(e,t,n={}){let r=_n(e).split(`/`);for(;r.length>0;){let e=await t(r.join(`/`)||`/`);if(e||!n.includeParentDirs)return e;r.pop()}}function $n(e){let t;return()=>(t===void 0&&(t=e().then(e=>(t=e,t))),t)}const er=$n(async()=>{if(globalThis.process?.versions?.webcontainer)return!1;try{let{exitCode:e}=await Yn(`corepack`,[`--version`]);return e===0}catch{return!1}});async function tr(e,t,n={}){let r=e!==`npm`&&e!==`bun`&&e!==`deno`&&n.corepack!==!1&&await er()?[`corepack`,[e,...t]]:[e,t],{exitCode:i,stdout:a,stderr:o}=await Yn(r[0],r[1],{nodeOptions:{cwd:W(n.cwd||process.cwd()),env:n.env,stdio:n.silent?`pipe`:`inherit`}});if(i!==0)throw Error(`\`${r.flat().join(` `)}\` failed.${n.silent?[``,a,o].join(`
|
|
85
|
-
`):``}`)}async function nr(e={}){let t=e.cwd||process.cwd(),n={...process.env,...e.env},r=(typeof e.packageManager==`string`?J.find(t=>t.name===e.packageManager):e.packageManager)||await ir(e.cwd||process.cwd());if(!r)throw Error(`No package manager auto-detected.`);return{cwd:t,env:n,silent:e.silent??!1,packageManager:r,dev:e.dev??!1,workspace:e.workspace,global:e.global??!1,dry:e.dry??!1,corepack:e.corepack??!0}}function rr(e){let[t,n]=(e||``).split(`@`),[r,i]=n?.split(`+`)||[];if(t&&t!==`-`&&/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(t))return{name:t,version:r,buildMeta:i};let a=(t||``).replace(/\W+/g,``);return{name:a,version:r,buildMeta:i,warnings:[`Abnormal characters found in \`packageManager\` field, sanitizing from \`${t}\` to \`${a}\``]}}const J=[{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 ir(e,t={}){let n=await Qn(W(e||`.`),async e=>{if(!t.ignorePackageJSON){let t=vn(e,`package.json`);if(h(t)){let e=JSON.parse(await w(t,`utf8`));if(e?.packageManager){let{name:t,version:n=`0.0.0`,buildMeta:r,warnings:i}=rr(e.packageManager);if(t){let e=n.split(`.`)[0],a=J.find(n=>n.name===t&&n.majorVersion===e)||J.find(e=>e.name===t);return{name:t,command:t,version:n,majorVersion:e,buildMeta:r,warnings:i,files:a?.files,lockFile:a?.lockFile}}}}if(h(vn(e,`deno.json`)))return J.find(e=>e.name===`deno`)}if(!t.ignoreLockFile){for(let t of J)if([t.lockFile,t.files].flat().filter(Boolean).some(t=>h(W(e,t))))return{...t}}},{includeParentDirs:t.includeParentDirs??!0});if(!n&&!t.ignoreArgv){let e=process.argv[1];if(e){for(let t of J)if(RegExp(`[/\\\\]\\.?${t.command}`).test(e))return t}}return n}async function ar(e={}){let t=await nr(e),n=e.frozenLockFile?{npm:[`ci`],yarn:[`install`,`--immutable`],bun:[`install`,`--frozen-lockfile`],pnpm:[`install`,`--frozen-lockfile`],deno:[`install`,`--frozen`]}[t.packageManager.name]:[`install`];return e.ignoreWorkspace&&t.packageManager.name===`pnpm`&&n.push(`--ignore-workspace`),t.dry||await tr(t.packageManager.command,n,{cwd:t.cwd,silent:t.silent,corepack:t.corepack}),{exec:{command:t.packageManager.command,args:n}}}async function or(e,t,n={}){let i=t+`.json`,a=JSON.parse(await w(i,`utf8`).catch(()=>`{}`)),o=(await X(e,{method:`HEAD`,headers:n.headers}).catch(()=>void 0))?.headers.get(`etag`);if(a.etag===o&&h(t))return;typeof o==`string`&&(a.etag=o);let s=await X(e,{headers:n.headers});if(s.status>=400)throw Error(`Failed to download ${e}: ${s.status} ${s.statusText}`);let c=m(t);await r(oe)(s.body,c),await E(i,JSON.stringify(a),`utf8`)}const sr=/^(?<repo>[-\w.]+\/[-\w.]+)(?<subdir>[^#]+)?(?<ref>#[-\w./@]+)?/,cr=/^(?<repo>[-\w.]+(?:\/[-\w.]+)+?)(?:::(?<subdir>[^#]*))?(?<ref>#[-\w./@]+)?$/;function lr(e,t){let n=t?.expandRepo||e.includes(`::`),r=e.match(n?cr:sr)?.groups||{},i=n?r.subdir?`/`+r.subdir:`/`:r.subdir||`/`;return{repo:r.repo||``,subdir:i,ref:r.ref?r.ref.slice(1):`main`}}function Y(...e){process.env.DEBUG&&console.debug(`[giget]`,...e)}async function X(e,t={}){t.headers?.[`sec-fetch-mode`]&&(t.mode=t.headers[`sec-fetch-mode`]);let n=await fetch(e,{...t,headers:dr(t.headers)}).catch(t=>{throw Error(`Failed to download ${e}: ${t}`,{cause:t})});if(t.validateStatus&&n.status>=400)throw Error(`Failed to fetch ${e}: ${n.status} ${n.statusText}`);return n}function ur(){let e=process.env.XDG_CACHE_HOME?W(process.env.XDG_CACHE_HOME,`giget`):W(le(),`.cache/giget`);if(process.platform===`win32`){let t=W(ue(),`giget`);if(!h(t)&&h(e))try{_(e,t)}catch{}return t}return e}function dr(e={}){let t={};for(let[n,r]of Object.entries(e))r&&(t[n.toLowerCase()]=r);return t}const fr=(e,t)=>{let n=pr(e);return{name:n.name,version:n.subdir?`${n.version||`default`}-${n.subdir.replaceAll(`/`,`-`)}`:n.version,tar:({auth:e}={})=>mr(n,e??t.auth)}};function pr(e,t={}){let n=t.cwd??process.cwd(),r=e.replace(/#.*$/,``),i;if(/^[./]/.test(e))r=W(n,r);else if(/^https?:\/\//.test(r)){let e=/^(https?:\/\/[^/]+)\/([\w.-]+\/[\w.-]+?)(?:\.git)?(?:\/(.+))?$/.exec(r);if(e){let[,t,n,a]=e;r=`${t}/${n}`,a&&(i=a)}}else if(r.includes(`@`)){let e=/^(.*?:[\w.-]+\/[\w.-]+?)(?:\.git)?(?:\/(.+))?$/.exec(r);if(e){let[,t,n]=e;r=t,n&&(i=n)}}else{let e={"github:":`https://github.com/`,"gh:":`https://github.com/`,"gitlab:":`https://gitlab.com/`,"bitbucket:":`https://bitbucket.org/`,"sourcehut:":`https://git.sr.ht/~`},t=/^(.+?:)/.exec(r)?.at(1);t&&e[t]?r=r.replace(t,e[t]):t||(r=`${(process.env.GIGET_GIT_HOST||`https://github.com/`).replace(/\/$/,``)}/${r}`);let n=/^(https?:\/\/[^/]+\/~?[\w.-]+\/[\w.-]+?)(?:\.git)?(?:\/(.+))?$/.exec(r);if(n){let[,e,t]=n;r=e,t&&(i=t)}}let a=r.replace(/^https?:\/\//,``).replace(/^.+@/,``).replace(/(\.git)?(#.*)?$/,``).replace(/^\W+/,``).replaceAll(/[:/]/g,`-`),[o,s]=/#(.+)$/.exec(e)?.at(1)?.split(`:`)??[],c=o||void 0,l=s||i;return{uri:r,name:a,...c&&{version:c},...l&&{subdir:l}}}async function mr(e,t){let n=await ne(x(ue(),`giget-git-`));if(t&&/[\r\n]/.test(t))throw Error(`Auth token must not contain newline characters`);let r={...process.env,GIT_TERMINAL_PROMPT:`0`};t&&(r.GIT_CONFIG_COUNT=`1`,r.GIT_CONFIG_KEY_0=`http.extraHeader`,r.GIT_CONFIG_VALUE_0=`Authorization: Bearer ${t}`);let i={env:r,timeout:6e4},a=_r(),o=e=>gr(e,i,a),s=e=>gr(e,{...i,cwd:n},a);try{let t=[`clone`,`--progress`,`--depth`,`1`];e.subdir&&t.push(`--filter=blob:none`,`--sparse`,`--no-checkout`),e.version&&t.push(`--branch`,e.version),t.push(`--`,e.uri,n);try{a.update(`Cloning...`),await o(t),a.update(`Cloned.`)}catch(t){if(!e.version)throw t;Y(`Shallow clone failed, falling back to full clone:`,t),a.update(`Shallow clone failed, cloning...`),await T(n,{recursive:!0,force:!0}),await C(n,{recursive:!0}),await s([`init`]),await s([`remote`,`add`,`origin`,e.uri]),await s([`fetch`,`origin`]),await s([`checkout`,e.version]),a.update(`Fetched.`)}e.subdir&&(a.update(`Sparse checkout ${e.subdir}...`),await s([`sparse-checkout`,`set`,e.subdir]),await s([`checkout`])),a.update(`Packing...`);let r=e.subdir?x(n,e.subdir):n,{create:i}=await import(`./tar-Bd_UMghg.mjs`).then(e=>e.t);a.done();let c=i({gzip:!0,cwd:r,filter:e=>!e.startsWith(`.git/`)&&e!==`.git`&&!e.startsWith(`./.git/`)&&e!==`./.git`},[`.`]).pipe(new ie),l=!1,u=()=>{l||(l=!0,T(n,{recursive:!0,force:!0}))};return c.on(`end`,u),c.on(`error`,u),c.on(`close`,u),c}catch(e){throw a.done(),await T(n,{recursive:!0,force:!0}),e}}const hr=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];function gr(e,t,n){return new Promise((r,i)=>{let a=se(`git`,e,{...t,stdio:[`ignore`,`pipe`,`pipe`]});a.stdout.resume();let o=``;a.stderr?.on(`data`,e=>{let t=e.toString();for(let e of t.split(/[\r\n]/)){let t=e.trim();t&&(o=t)}n&&n.update(o)}),a.on(`close`,t=>{t===0?r(o):i(Error(`git ${e[0]} exited with code ${t}. Is git installed?`))}),a.on(`error`,e=>{e.code===`ENOENT`?i(Error(`git is not installed or not found in PATH`)):i(e)})})}function _r(){if(!process.stderr.isTTY)return{update(e){},done(){}};let e=``,t=0,n=()=>{let n=hr[t%hr.length];t++,process.stderr.write(`\x1B[2K\r\x1B[2m${n} ${e}\x1B[0m`)},r=setInterval(n,80);return{update(t){e=t,n()},done(){clearInterval(r),process.stderr.write(`\x1B[2K\r`)}}}const vr=async(e,t)=>{if(e.endsWith(`.json`))return await yr(e,t);let n=new URL(e),r=Sn(n.pathname);try{let i=await X(n.href,{method:`HEAD`,validateStatus:!0,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0}});if((i.headers.get(`content-type`)||``).includes(`application/json`))return await yr(e,t);let a=i.headers.get(`content-disposition`)?.match(/filename="?(.+)"?/)?.[1];a&&(r=a.split(`.`)[0])}catch(e){Y(`Failed to fetch HEAD for ${n.href}:`,e)}return{name:`${r}-${n.href.slice(0,8)}`,version:``,subdir:``,tar:n.href,defaultDir:r,headers:{Authorization:t.auth?`Bearer ${t.auth}`:void 0}}},yr=async(e,t)=>{let n=await(await X(e,{validateStatus:!0,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0}})).json();if(!n.tar||!n.name)throw Error(`Invalid template info from ${e}. name or tar fields are missing!`);return n},br=(e,t)=>{let n=lr(e),r=process.env.GIGET_GITHUB_URL||`https://api.github.com`;return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{Authorization:t.auth?`Bearer ${t.auth}`:void 0,Accept:`application/vnd.github+json`,"X-GitHub-Api-Version":`2022-11-28`},url:`${r.replace(`api.github.com`,`github.com`)}/${n.repo}/tree/${n.ref}${n.subdir}`,tar:`${r}/repos/${n.repo}/tarball/${n.ref}`}},xr={http:vr,https:vr,git:fr,github:br,gh:br,gitlab:(e,t)=>{let n=lr(e,{expandRepo:!0}),r=process.env.GIGET_GITLAB_URL||`https://gitlab.com`;return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0,"sec-fetch-mode":`same-origin`},url:`${r}/${n.repo}/tree/${n.ref}${n.subdir}`,tar:`${r}/${n.repo}/-/archive/${n.ref}.tar.gz`}},bitbucket:(e,t)=>{let n=lr(e);return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0},url:`https://bitbucket.com/${n.repo}/src/${n.ref}${n.subdir}`,tar:`https://bitbucket.org/${n.repo}/get/${n.ref}.tar.gz`}},sourcehut:(e,t)=>{let n=lr(e);return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0},url:`https://git.sr.ht/~${n.repo}/tree/${n.ref}/item${n.subdir}`,tar:`https://git.sr.ht/~${n.repo}/archive/${n.ref}.tar.gz`}}},Sr=(e=`https://raw.githubusercontent.com/unjs/giget/main/templates`,t={})=>(async n=>{let r=Date.now(),i=`${e}/${n}.json`,a=await X(i,{headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0}});if(a.status>=400)throw Error(`Failed to download ${n} template info from ${i}: ${a.status} ${a.statusText}`);let o=await a.json();if(!o.tar||!o.name)throw Error(`Invalid template info from ${i}. name or tar fields are missing!`);return Y(`Fetched ${n} template info from ${i} in ${Date.now()-r}ms`),o}),Cr=/^([\w+-.]+):/;async function wr(e,t={}){t.registry=process.env.GIGET_REGISTRY??t.registry,t.auth=process.env.GIGET_AUTH??t.auth;let n=t.registry===!1?void 0:Sr(t.registry,{auth:t.auth}),r=t.provider||(n?`registry`:`github`),i=e,a=e.match(Cr);a&&(r=a[1],i=e.slice(a[0].length),(r===`http`||r===`https`)&&(i=e)),r.endsWith(`+git`)&&(i=`${r.slice(0,-4)}:${i}`,r=`git`);let o=t.providers?.[r]||xr[r]||n;if(!o)throw Error(`Unsupported provider: ${r}`);let s=await Promise.resolve().then(()=>o(i,{auth:t.auth})).catch(e=>{throw Error(`Failed to download template from ${r}: ${e.message}`)});if(!s)throw Error(`Failed to resolve template from ${r}`);s.name=(s.name||`template`).replace(/[^\da-z-]/gi,`-`),s.defaultDir=(s.defaultDir||s.name).replace(/[^\da-z-]/gi,`-`);let c=W(W(ur(),r,s.name),(s.version||s.name)+`.tar.gz`);if(t.preferOffline&&h(c)&&(t.offline=!0),!t.offline){await C(xn(c),{recursive:!0});let e=Date.now();if(typeof s.tar==`function`){let e=s.tar;await(async()=>{let n=await e({auth:t.auth});await ce(n instanceof ae?n:ae.fromWeb(n),m(c))})().catch(e=>{if(!h(c))throw e;Y(`Download error. Using cached version:`,e),t.offline=!0})}else await or(s.tar,c,{headers:{Authorization:t.auth?`Bearer ${t.auth}`:void 0,...dr(s.headers)}}).catch(e=>{if(!h(c))throw e;Y(`Download error. Using cached version:`,e),t.offline=!0});Y(`Downloaded to ${c} in ${Date.now()-e}ms`)}if(!h(c))throw Error(`Tarball not found: ${c} (offline: ${t.offline})`);let l=W(W(t.cwd||`.`),t.dir||s.defaultDir);if(t.forceClean&&await T(l,{recursive:!0,force:!0}),!t.force&&h(l)&&g(l).length>0)throw Error(`Destination ${l} already exists.`);await C(l,{recursive:!0});let u=Date.now(),d=s.subdir?.replace(/^\//,``)||``,{extract:f}=await import(`./tar-Bd_UMghg.mjs`).then(e=>e.t);if(await f({file:c,cwd:l,onReadEntry(e){e.path=e.path.split(`/`).splice(1).join(`/`),d&&(e.path.startsWith(d+`/`)?e.path=e.path.slice(d.length):e.path=``)}}),Y(`Extracted to ${l} in ${Date.now()-u}ms`),t.install){Y(`Installing dependencies...`);let{installDependencies:e}=await Promise.resolve().then(()=>fn).then(e=>e.t);await e({cwd:l,silent:t.silent,...typeof t.install==`object`?t.install:{}})}return{...s,source:i,dir:l}}function Tr(e){return e}const Er=Tr([`default`,`monorepo`]),Dr={name:{type:`positional`,description:`Project name`,required:!1},template:{type:`enum`,description:`Template to use`,options:Er,required:!1,alias:[`t`]},install:{type:`boolean`,description:`Install dependencies`,required:!1,alias:[`i`]}};var Z=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),Q=t(import.meta.url);const Or=/^path$/i,kr={key:`PATH`,value:``};function Ar(e){for(let t in e){if(!Object.prototype.hasOwnProperty.call(e,t)||!Or.test(t))continue;let n=e[t];return n?{key:t,value:n}:kr}return kr}function jr(e,t){let n=t.value.split(y),r=[],i=e,a;do r.push(ee(i,`node_modules`,`.bin`)),a=i,i=b(i);while(i!==a);r.push(b(process.execPath));let o=r.concat(n).join(y);return{key:t.key,value:o}}function Mr(e,t){let n={...process.env,...t},r=jr(e,Ar(n));return n[r.key]=r.value,n}const Nr=e=>{let t=e.length,n=new ie,r=()=>{--t===0&&n.end()};for(let t of e)ce(t,n,{end:!1}).then(r).catch(r);return n};var Pr=Z(((e,t)=>{t.exports=a,a.sync=o;var n=Q(`fs`);function r(e,t){var n=t.pathExt===void 0?process.env.PATHEXT:t.pathExt;if(!n||(n=n.split(`;`),n.indexOf(``)!==-1))return!0;for(var r=0;r<n.length;r++){var i=n[r].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,n){return!e.isSymbolicLink()&&!e.isFile()?!1:r(t,n)}function a(e,t,r){n.stat(e,function(n,a){r(n,n?!1:i(a,e,t))})}function o(e,t){return i(n.statSync(e),e,t)}})),Fr=Z(((e,t)=>{t.exports=r,r.sync=i;var n=Q(`fs`);function r(e,t,r){n.stat(e,function(e,n){r(e,e?!1:a(n,t))})}function i(e,t){return a(n.statSync(e),t)}function a(e,t){return e.isFile()&&o(e,t)}function o(e,t){var n=e.mode,r=e.uid,i=e.gid,a=t.uid===void 0?process.getuid&&process.getuid():t.uid,o=t.gid===void 0?process.getgid&&process.getgid():t.gid,s=64,c=8,l=1,u=s|c;return n&l||n&c&&i===o||n&s&&r===a||n&u&&a===0}})),Ir=Z(((e,t)=>{Q(`fs`);var n=process.platform===`win32`||global.TESTING_WINDOWS?Pr():Fr();t.exports=r,r.sync=i;function r(e,t,i){if(typeof t==`function`&&(i=t,t={}),!i){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(n,i){r(e,t||{},function(e,t){e?i(e):n(t)})})}n(e,t||{},function(e,n){e&&(e.code===`EACCES`||t&&t.ignoreErrors)&&(e=null,n=!1),i(e,n)})}function i(e,t){try{return n.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code===`EACCES`)return!1;throw e}}})),Lr=Z(((e,t)=>{let n=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,r=Q(`path`),i=n?`;`:`:`,a=Ir(),o=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),s=(e,t)=>{let r=t.colon||i,a=e.match(/\//)||n&&e.match(/\\/)?[``]:[...n?[process.cwd()]:[],...(t.path||process.env.PATH||``).split(r)],o=n?t.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,s=n?o.split(r):[``];return n&&e.indexOf(`.`)!==-1&&s[0]!==``&&s.unshift(``),{pathEnv:a,pathExt:s,pathExtExe:o}},c=(e,t,n)=>{typeof t==`function`&&(n=t,t={}),t||={};let{pathEnv:i,pathExt:c,pathExtExe:l}=s(e,t),u=[],d=n=>new Promise((a,s)=>{if(n===i.length)return t.all&&u.length?a(u):s(o(e));let c=i[n],l=/^".*"$/.test(c)?c.slice(1,-1):c,d=r.join(l,e);a(f(!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d,n,0))}),f=(e,n,r)=>new Promise((i,o)=>{if(r===c.length)return i(d(n+1));let s=c[r];a(e+s,{pathExt:l},(a,o)=>{if(!a&&o)if(t.all)u.push(e+s);else return i(e+s);return i(f(e,n,r+1))})});return n?d(0).then(e=>n(null,e),n):d(0)};t.exports=c,c.sync=(e,t)=>{t||={};let{pathEnv:n,pathExt:i,pathExtExe:c}=s(e,t),l=[];for(let o=0;o<n.length;o++){let s=n[o],u=/^".*"$/.test(s)?s.slice(1,-1):s,d=r.join(u,e),f=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;for(let e=0;e<i.length;e++){let n=f+i[e];try{if(a.sync(n,{pathExt:c}))if(t.all)l.push(n);else return n}catch{}}}if(t.all&&l.length)return l;if(t.nothrow)return null;throw o(e)}})),Rr=Z(((e,t)=>{let n=(e={})=>{let t=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};t.exports=n,t.exports.default=n})),zr=Z(((e,t)=>{let n=Q(`path`),r=Lr(),i=Rr();function a(e,t){let a=e.options.env||process.env,o=process.cwd(),s=e.options.cwd!=null,c=s&&process.chdir!==void 0&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch{}let l;try{l=r.sync(e.command,{path:a[i({env:a})],pathExt:t?n.delimiter:void 0})}catch{}finally{c&&process.chdir(o)}return l&&=n.resolve(s?e.options.cwd:``,l),l}function o(e){return a(e)||a(e,!0)}t.exports=o})),Br=Z(((e,t)=>{let n=/([()\][%!^"`<>&|;, *?])/g;function r(e){return e=e.replace(n,`^$1`),e}function i(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(n,`^$1`),t&&(e=e.replace(n,`^$1`)),e}t.exports.command=r,t.exports.argument=i})),Vr=Z(((e,t)=>{t.exports=/^#!(.*)/})),Hr=Z(((e,t)=>{let n=Vr();t.exports=(e=``)=>{let t=e.match(n);if(!t)return null;let[r,i]=t[0].replace(/#! ?/,``).split(` `),a=r.split(`/`).pop();return a===`env`?i:i?`${a} ${i}`:a}})),Ur=Z(((e,t)=>{let n=Q(`fs`),r=Hr();function i(e){let t=Buffer.alloc(150),i;try{i=n.openSync(e,`r`),n.readSync(i,t,0,150,0),n.closeSync(i)}catch{}return r(t.toString())}t.exports=i})),Wr=Z(((e,t)=>{let n=Q(`path`),r=zr(),i=Br(),a=Ur(),o=process.platform===`win32`,s=/\.(?:com|exe)$/i,c=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function l(e){e.file=r(e);let t=e.file&&a(e.file);return t?(e.args.unshift(e.file),e.command=t,r(e)):e.file}function u(e){if(!o)return e;let t=l(e),r=!s.test(t);if(e.options.forceShell||r){let r=c.test(t);e.command=n.normalize(e.command),e.command=i.command(e.command),e.args=e.args.map(e=>i.argument(e,r)),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 d(e,t,n){t&&!Array.isArray(t)&&(n=t,t=null),t=t?t.slice(0):[],n=Object.assign({},n);let r={command:e,args:t,options:n,file:void 0,original:{command:e,args:t}};return n.shell?r:u(r)}t.exports=d})),Gr=Z(((e,t)=>{let n=process.platform===`win32`;function r(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function i(e,t){if(!n)return;let r=e.emit;e.emit=function(n,i){if(n===`exit`){let n=a(i,t);if(n)return r.call(e,`error`,n)}return r.apply(e,arguments)}}function a(e,t){return n&&e===1&&!t.file?r(t.original,`spawn`):null}function o(e,t){return n&&e===1&&!t.file?r(t.original,`spawnSync`):null}t.exports={hookChildProcess:i,verifyENOENT:a,verifyENOENTSync:o,notFoundError:r}})),Kr=Z(((e,t)=>{let n=Q(`child_process`),r=Wr(),i=Gr();function a(e,t,a){let o=r(e,t,a),s=n.spawn(o.command,o.args,o.options);return i.hookChildProcess(s,o),s}function o(e,t,a){let o=r(e,t,a),s=n.spawnSync(o.command,o.args,o.options);return s.error=s.error||i.verifyENOENTSync(s.status,o),s}t.exports=a,t.exports.spawn=a,t.exports.sync=o,t.exports._parse=r,t.exports._enoent=i}))(),qr=class extends Error{get exitCode(){if(this.result.exitCode!==null)return this.result.exitCode}constructor(e,t){super(`Process exited with non-zero status (${e.exitCode})`),this.result=e,this.output=t}};const Jr={timeout:void 0,persist:!1},Yr={windowsHide:!0};function Xr(e){let t=new AbortController;for(let n of e){if(n.aborted)return t.abort(),n;n.addEventListener(`abort`,()=>{t.abort(n.reason)},{signal:t.signal})}return t.signal}async function Zr(e){let t=``;try{for await(let n of e)t+=n.toString()}catch{}return t}var Qr=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,t,n){this._options={...Jr,...n},this._command=e,this._args=t??[],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,t,n){return $r(e,t,{...n,stdin:this})}async*[Symbol.asyncIterator](){let e=this._process;if(!e)return;let t=[];this._streamErr&&t.push(this._streamErr),this._streamOut&&t.push(this._streamOut);let n=Nr(t),r=d.createInterface({input:n});for await(let e of r)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 qr(this)}async _waitForOutput(){let e=this._process;if(!e)throw Error(`No process was started`);let[t,n]=await Promise.all([this._streamOut?Zr(this._streamOut):``,this._streamErr?Zr(this._streamErr):``]);await this._processClosed;let{stdin:r}=this._options;if(r&&typeof r!=`string`&&await r,e.removeAllListeners(),this._thrownError)throw this._thrownError;let i={stderr:n,stdout:t,exitCode:this.exitCode};if(this._options.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new qr(this,i);return i}then(e,t){return this._waitForOutput().then(e,t)}_streamOut;_streamErr;spawn(){let e=s(),t=this._options,n={...Yr,...t.nodeOptions},r=[];this._resetState(),t.timeout!==void 0&&r.push(AbortSignal.timeout(t.timeout)),t.signal!==void 0&&r.push(t.signal),t.persist===!0&&(n.detached=!0),r.length>0&&(n.signal=Xr(r)),n.env=Mr(e,n.env);let i=(0,Kr._parse)(this._command,this._args,n),a=se(i.command,i.args,i.options);if(a.stderr&&(this._streamErr=a.stderr),a.stdout&&(this._streamOut=a.stdout),this._process=a,a.once(`error`,this._onError),a.once(`close`,this._onClose),a.stdin){let{stdin:e}=t;typeof e==`string`?a.stdin.end(e):e?.process?.stdout?.pipe(a.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 $=(e,t,n)=>{let r=new Qr(e,t,n);return r.spawn(),r},$r=$;function ei(){let e=process.env.npm_config_user_agent??``;return e.startsWith(`pnpm/`)?`pnpm`:e.startsWith(`yarn/`)?`yarn`:e.startsWith(`bun/`)?`bun`:e.startsWith(`deno/`)?`deno`:`npm`}async function ti(){try{return await $(`pnpm`,[`--version`],{throwOnError:!0}),!0}catch{return!1}}async function ni(e){await $(`git`,[`init`],{throwOnError:!1,nodeOptions:{cwd:e,stdio:`inherit`}})}async function ri(e,t){let n=kt({title:`Installing dependencies with ${t}...`,limit:5,retainLog:!1}),r=wt();r.start();let i=[`install`];t===`npm`&&i.push(`--legacy-peer-deps`);let a=$(t,i,{throwOnError:!1,nodeOptions:{cwd:e}});for await(let e of a){let t=e.trim();t&&n.message(t)}let o=await a;return r.stop(),o.exitCode===0?(n.success(`Dependencies installed`),!0):(n.error(`Dependency installation failed. You can run \`${t} install\` manually.`),!1)}function ii(e){return e===`npm`?`npm run dev`:e===`deno`?`deno task dev`:`${e} dev`}const ai=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;function oi(e){for(let t of e){let e=t.codePointAt(0);if(e!==void 0&&(e<=31||`<>:"|?*`.includes(t)))return!0}return!1}function si(e){let t=e.trim();if(t.length===0)return`Project name is required`;if(t!==`.`){if(t.includes(`/`)||t.includes(`\\`))return`Project name cannot contain path separators`;if(oi(t))return`Project name contains invalid characters`;if(t===`..`)return`Project name cannot be ..`;if(t.startsWith(`.`))return`Project name cannot start with a period`;if(t.endsWith(`.`)||t.endsWith(`-`))return`Project name cannot end with a period or hyphen`;if(t.length>214)return`Project name must be 214 characters or fewer`;if(!ai.test(t))return`Use letters, numbers, periods, underscores, or hyphens`}}function ci(e,t){return typeof t==`string`&&e.includes(t)}async function li(e){let t;try{t=await re(e)}catch(e){if(e&&typeof e==`object`&&`code`in e&&e.code===`ENOENT`)return;throw e}if(t.length>0)return`Directory must be empty.`}async function ui(){let e=await At({message:`Project name:`,placeholder:`my-project`,defaultValue:`my-project`,validate(e){if(typeof e==`string`)return si(e)}});if(Ve(e)){L(`Operation cancelled.`);return}return e}async function di(){let e=await Et({message:`Select a template:`,options:[{value:`default`,label:`Default`,hint:`minimal TanStarter template`},{value:`monorepo`,label:`Monorepo (beta)`,hint:`TanStarter via Vite+ with pnpm`}]});if(Ve(e)){L(`Operation cancelled.`);return}return e}async function fi(){let e=await vt({message:`Install dependencies after scaffolding?`,initialValue:!0});if(Ve(e)){L(`Operation cancelled.`);return}return e}async function pi(e){let t=e.name,n=e.template,r=e.install,i=await ti()?`pnpm`:ei();if(!t&&(t=await ui(),!t))return;t=String(t).trim();let a=await li(t===`.`?process.cwd():x(process.cwd(),t));if(a){L(a);return}let o=si(t);if(o){L(o);return}if(!(!n&&(n=await di(),!n))&&!(r===void 0&&i===`pnpm`&&(r=await fi(),r===void 0))&&!(!ci(Er,n)||typeof r!=`boolean`))return{projectName:t,template:n,install:r,selectedPackageManager:void 0,preferredPackageManager:i}}const mi={default:{source:`github:mugnavo/tanstarter`,homeUrl:`https://github.com/mugnavo/tanstarter`},monorepo:{source:`github:mugnavo/tanstarter-plus`,homeUrl:`https://github.com/mugnavo/tanstarter-plus`}};function hi(e){return mi[e]}function gi(e,t){if(!t)return"This project was scaffolded with [`create-mugnavo`](https://github.com/mugnavo/create-mugnavo).";let n=hi(e);return`This project was scaffolded with \`create-mugnavo\` from commit [\`${t.slice(0,7)}\`](${`${n.homeUrl}/tree/${t}`}). See the [template changelog](${`${n.homeUrl}/compare/${t}...main`}) for newer changes.`}function _i(e,t,n){if(!n)return!1;let r=e.findIndex(e=>e.trim()===`## Issue watchlist`);if(r===-1)return!1;let i=e.findIndex((e,t)=>t>r&&e.startsWith(`## `)),a=i===-1?e.length:i,o=`${hi(t).homeUrl}/compare/${n}...main`;if(e.slice(r+1,a).some(e=>e.includes(o)))return!1;let s=r+1;for(;s<a&&e[s]?.trim()===``;)s+=1;return e.splice(s,0,`- [Template changelog](${o}) - Track template updates since this project was created.`),!0}function vi(e,t){return t===`.`?v(ee(e))||`app`:t}async function yi(e){await T(x(e,`LICENSE`),{force:!0})}async function bi(e,t){if(t===`default`){await te(x(e,`.env.example`),x(e,`.env`),p.COPYFILE_EXCL);return}if(t===`monorepo`){await te(x(e,`apps`,`web`,`.env.example`),x(e,`apps`,`web`,`.env`),p.COPYFILE_EXCL);return}}async function xi(e,t){let n=x(e,`package.json`),r=JSON.parse(await w(n,`utf8`));r.name=vi(e,t),await E(n,`${JSON.stringify(r,null,2)}\n`)}async function Si(e,t,n,r){let i=x(e,`README.md`),a=vi(e,n),o=await w(i,`utf8`),s=o.includes(`\r
|
|
72
|
+
`}case`submit`:{let e=o?` ${n(`dim`,o)}`:``;return`${r}${t?n(`gray`,R):``}${e}`}case`cancel`:{let e=o?` ${n([`strikethrough`,`dim`],o)}`:``,i=t?n(`gray`,R):``;return`${r}${i}${e}${o.trim()?`
|
|
73
|
+
${i}`:``}`}default:return`${r}${t?`${n(`cyan`,R)} `:``}${a}
|
|
74
|
+
${t?n(`cyan`,z):``}
|
|
75
|
+
`}}}).prompt(),Ot=/\d/,kt=[`-`,`_`,`/`,`.`];function At(e=``){if(!Ot.test(e))return e!==e.toLowerCase()}function jt(e,t){let n=t??kt,r=[];if(!e||typeof e!=`string`)return r;let i=``,a,o;for(let t of e){let e=n.includes(t);if(e===!0){r.push(i),i=``,a=void 0;continue}let s=At(t);if(o===!1){if(a===!1&&s===!0){r.push(i),i=t,a=s;continue}if(a===!0&&s===!1&&i.length>1){let e=i.at(-1);r.push(i.slice(0,Math.max(0,i.length-1))),i=e+t,a=s;continue}}i+=t,a=s,o=e}return r.push(i),r}function Mt(e){return e?e[0].toUpperCase()+e.slice(1):``}function Nt(e){return e?e[0].toLowerCase()+e.slice(1):``}function Pt(e,t){return e?(Array.isArray(e)?e:jt(e)).map(e=>Mt(t?.normalize?e.toLowerCase():e)).join(``):``}function W(e,t){return Nt(Pt(e||``,t))}function Ft(e,t){return e?(Array.isArray(e)?e:jt(e)).map(e=>e.toLowerCase()).join(t??`-`):``}function It(e){return Ft(e||``,`_`)}function G(e){return Array.isArray(e)?e:e===void 0?[]:[e]}function Lt(e,t=``){let n=[];for(let t of e)for(let[e,r]of t.entries())n[e]=Math.max(n[e]||0,r.length);return e.map(e=>e.map((e,r)=>t+e[r===0?`padStart`:`padEnd`](n[r])).join(` `)).join(`
|
|
76
|
+
`)}function K(e){return typeof e==`function`?e():e}var q=class extends Error{code;constructor(e,t){super(e),this.name=`CLIError`,this.code=t}};function Rt(t=[],n={}){let r=new Set(n.boolean||[]),i=new Set(n.string||[]),a=n.alias||{},o=n.default||{},s=new Map,c=new Map;for(let[e,t]of Object.entries(a)){let n=t;for(let t of n)s.set(e,t),c.has(t)||c.set(t,[]),c.get(t).push(e),s.set(t,e),c.has(e)||c.set(e,[]),c.get(e).push(t)}let l={};function u(e){if(r.has(e))return`boolean`;let t=c.get(e)||[];for(let e of t)if(r.has(e))return`boolean`;return`string`}function d(e){if(i.has(e))return!0;let t=c.get(e)||[];for(let e of t)if(i.has(e))return!0;return!1}let f=new Set([...r,...i,...Object.keys(a),...Object.values(a).flat(),...Object.keys(o)]);for(let e of f)l[e]||(l[e]={type:u(e),default:o[e]});for(let[e,t]of s.entries())e.length===1&&l[t]&&!l[t].short&&(l[t].short=e);let p=[],m={};for(let e=0;e<t.length;e++){let n=t[e];if(n===`--`){p.push(...t.slice(e));break}if(n.startsWith(`--no-`)){let e=n.slice(5);m[e]=!0;continue}p.push(n)}let h;try{h=e({args:p,options:Object.keys(l).length>0?l:void 0,allowPositionals:!0,strict:!1})}catch{h={values:{},positionals:p}}let g={_:[]};g._=h.positionals;for(let[e,t]of Object.entries(h.values)){let n=t;u(e)===`boolean`&&typeof t==`string`?n=t!==`false`:d(e)&&typeof t==`boolean`&&(n=``),g[e]=n}for(let[e]of Object.entries(m)){g[e]=!1;let t=s.get(e);t&&(g[t]=!1);let n=c.get(e);if(n)for(let e of n)g[e]=!1}for(let[e,t]of s.entries())g[e]!==void 0&&g[t]===void 0&&(g[t]=g[e]),g[t]!==void 0&&g[e]===void 0&&(g[e]=g[t]),g[e]!==g[t]&&o[t]===g[t]&&(g[t]=g[e]);return g}const zt=(()=>{let e=globalThis.process?.env??{};return e.NO_COLOR===`1`||e.TERM===`dumb`||e.TEST||e.CI})(),Bt=(e,t=39)=>n=>zt?n:`\u001B[${e}m${n}\u001B[${t}m`,Vt=Bt(1,22),J=Bt(36),Ht=Bt(90),Ut=Bt(4,24);function Wt(e,t){let n={boolean:[],string:[],alias:{},default:{}},r=Gt(t);for(let e of r){if(e.type===`positional`)continue;e.type===`string`||e.type===`enum`?n.string.push(e.name):e.type===`boolean`&&n.boolean.push(e.name),e.default!==void 0&&(n.default[e.name]=e.default),e.alias&&(n.alias[e.name]=e.alias);let t=W(e.name),r=Ft(e.name);if(t!==e.name||r!==e.name){let i=G(n.alias[e.name]||[]);t!==e.name&&!i.includes(t)&&i.push(t),r!==e.name&&!i.includes(r)&&i.push(r),i.length>0&&(n.alias[e.name]=i)}}let i=Rt(e,n),[...a]=i._,o=new Proxy(i,{get(e,t){return e[t]??e[W(t)]??e[Ft(t)]}});for(let[,e]of r.entries())if(e.type===`positional`){let t=a.shift();if(t!==void 0)o[e.name]=t;else if(e.default===void 0&&e.required!==!1)throw new q(`Missing required positional argument: ${e.name.toUpperCase()}`,`EARG`);else o[e.name]=e.default}else if(e.type===`enum`){let t=o[e.name],n=e.options||[];if(t!==void 0&&n.length>0&&!n.includes(t))throw new q(`Invalid value for argument: ${J(`--${e.name}`)} (${J(t)}). Expected one of: ${n.map(e=>J(e)).join(`, `)}.`,`EARG`)}else if(e.required&&o[e.name]===void 0)throw new q(`Missing required argument: --${e.name}`,`EARG`);return o}function Gt(e){let t=[];for(let[n,r]of Object.entries(e||{}))t.push({...r,name:n,alias:G(r.alias)});return t}async function Kt(e){return Promise.all(e.map(e=>K(e)))}function qt(e){return e}async function Jt(e,t){let n=await K(e.args||{}),r=Wt(t.rawArgs,n),i={rawArgs:t.rawArgs,args:r,data:t.data,cmd:e},a=await Kt(e.plugins??[]),o,s;try{for(let e of a)await e.setup?.(i);typeof e.setup==`function`&&await e.setup(i);let r=await K(e.subCommands);if(r&&Object.keys(r).length>0){let i=Zt(t.rawArgs,n),a=t.rawArgs[i];if(a){let e=await Xt(r,a);if(!e)throw new q(`Unknown command ${J(a)}`,`E_UNKNOWN_COMMAND`);await Jt(e,{rawArgs:t.rawArgs.slice(i+1)})}else{let n=await K(e.default);if(n){if(e.run)throw new q(`Cannot specify both 'run' and 'default' on the same command.`,`E_DEFAULT_CONFLICT`);let i=await Xt(r,n);if(!i)throw new q(`Default sub command ${J(n)} not found in subCommands.`,`E_UNKNOWN_COMMAND`);await Jt(i,{rawArgs:t.rawArgs})}else if(!e.run)throw new q(`No command specified.`,`E_NO_COMMAND`)}}typeof e.run==`function`&&(o=await e.run(i))}catch(e){s=e}let c=[];if(typeof e.cleanup==`function`)try{await e.cleanup(i)}catch(e){c.push(e)}for(let e of[...a].reverse())try{await e.cleanup?.(i)}catch(e){c.push(e)}if(s)throw s;if(c.length===1)throw c[0];if(c.length>1)throw Error(`Multiple cleanup errors`,{cause:c});return{result:o}}async function Yt(e,t,n){let r=await K(e.subCommands);if(r&&Object.keys(r).length>0){let n=Zt(t,await K(e.args||{})),i=t[n],a=await Xt(r,i);if(a)return Yt(a,t.slice(n+1),e)}return[e,n]}async function Xt(e,t){if(t in e)return K(e[t]);for(let n of Object.values(e)){let e=await K(n),r=await K(e?.meta);if(r?.alias&&G(r.alias).includes(t))return e}}function Zt(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r===`--`)return-1;if(r.startsWith(`-`)){!r.includes(`=`)&&Qt(r,t)&&n++;continue}return n}return-1}function Qt(e,t){let n=e.replace(/^-{1,2}/,``),r=W(n);for(let[e,i]of Object.entries(t))if(!(i.type!==`string`&&i.type!==`enum`)&&(r===W(e)||(Array.isArray(i.alias)?i.alias:i.alias?[i.alias]:[]).includes(n)))return!0;return!1}async function $t(e,t){try{console.log(await tn(e,t)+`
|
|
77
|
+
`)}catch(e){console.error(e)}}const en=/^no[-A-Z]/;async function tn(e,t){let n=await K(e.meta||{}),r=Gt(await K(e.args||{})),i=await K(t?.meta||{}),a=`${i.name?`${i.name} `:``}`+(n.name||process.argv[1]),o=[],s=[],c=[],l=[];for(let e of r)if(e.type===`positional`){let t=e.name.toUpperCase(),n=e.required!==!1&&e.default===void 0;s.push([J(t+nn(e)),rn(e,n)]),l.push(n?`<${t}>`:`[${t}]`)}else{let t=e.required===!0&&e.default===void 0,n=[...(e.alias||[]).map(e=>`-${e}`),`--${e.name}`].join(`, `)+nn(e);if(o.push([J(n),rn(e,t)]),e.type===`boolean`&&(e.default===!0||e.negativeDescription)&&!en.test(e.name)){let n=[...(e.alias||[]).map(e=>`--no-${e}`),`--no-${e.name}`].join(`, `);o.push([J(n),[e.negativeDescription,t?Ht(`(Required)`):``].filter(Boolean).join(` `)])}t&&l.push(`--${e.name}`+nn(e))}if(e.subCommands){let t=[],n=await K(e.subCommands);for(let[e,r]of Object.entries(n)){let n=await K((await K(r))?.meta);if(n?.hidden)continue;let i=G(n?.alias),a=[e,...i].join(`, `);c.push([J(a),n?.description||``]),t.push(e,...i)}l.push(t.join(`|`))}let u=[],d=n.version||i.version;u.push(Ht(`${n.description} (${a+(d?` v${d}`:``)})`),``);let f=o.length>0||s.length>0;return u.push(`${Ut(Vt(`USAGE`))} ${J(`${a}${f?` [OPTIONS]`:``} ${l.join(` `)}`)}`,``),s.length>0&&(u.push(Ut(Vt(`ARGUMENTS`)),``),u.push(Lt(s,` `)),u.push(``)),o.length>0&&(u.push(Ut(Vt(`OPTIONS`)),``),u.push(Lt(o,` `)),u.push(``)),c.length>0&&(u.push(Ut(Vt(`COMMANDS`)),``),u.push(Lt(c,` `)),u.push(``,`Use ${J(`${a} <command> --help`)} for more information about a command.`)),u.filter(e=>typeof e==`string`).join(`
|
|
78
|
+
`)}function nn(e){let t=e.valueHint?`=<${e.valueHint}>`:``,n=t||`=<${It(e.name)}>`;return!e.type||e.type===`positional`||e.type===`boolean`?t:e.type===`enum`&&e.options?.length?`=<${e.options.join(`|`)}>`:n}function rn(e,t){let n=t?Ht(`(Required)`):``,r=e.default===void 0?``:Ht(`(Default: ${e.default})`);return[e.description,n,r].filter(Boolean).join(` `)}async function an(e,t={}){let n=t.rawArgs||process.argv.slice(2),r=t.showUsage||$t;try{let t=await on(e);if(t.help.length>0&&n.some(e=>t.help.includes(e)))await r(...await Yt(e,n)),process.exit(0);else if(n.length===1&&t.version.includes(n[0])){let t=typeof e.meta==`function`?await e.meta():await e.meta;if(!t?.version)throw new q(`No version specified`,`E_NO_VERSION`);console.log(t.version)}else await Jt(e,{rawArgs:n})}catch(t){t instanceof q?(await r(...await Yt(e,n)),console.error(t.message)):console.error(t,`
|
|
79
|
+
`),process.exit(1)}}async function on(e){let t=await K(e.args||{}),n=new Set,r=new Set;for(let[e,i]of Object.entries(t)){n.add(e);for(let e of G(i.alias))r.add(e)}return{help:sn(`help`,`h`,n,r),version:sn(`version`,`v`,n,r)}}function sn(e,t,n,r){return n.has(e)||r.has(e)?[]:n.has(t)||r.has(t)?[`--${e}`]:[`--${e}`,`-${t}`]}var cn=Object.defineProperty,ln=(e,t)=>{let n={};for(var r in e)cn(n,r,{get:e[r],enumerable:!0});return t||cn(n,Symbol.toStringTag,{value:`Module`}),n},un=fe({basename:()=>xn,dirname:()=>bn,dist_exports:()=>Wn,resolve:()=>Y});const dn=/^[A-Za-z]:\//;function fn(e=``){return e&&e.replace(/\\/g,`/`).replace(dn,e=>e.toUpperCase())}const pn=/^[/\\]{2}/,mn=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,hn=/^[A-Za-z]:$/,gn=function(e){if(e.length===0)return`.`;e=fn(e);let t=e.match(pn),n=X(e),r=e[e.length-1]===`/`;return e=yn(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),hn.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!X(e)?`/${e}`:e)},_n=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return gn(t)};function vn(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}const Y=function(...e){e=e.map(e=>fn(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:vn();!i||i.length===0||(t=`${i}/${t}`,n=X(i))}return t=yn(t,!n),n&&!X(t)?`/${t}`:t.length>0?t:`.`};function yn(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}const X=function(e){return mn.test(e)},bn=function(e){let t=fn(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&hn.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(X(e)?`/`:`.`)},xn=function(e,t){let n=fn(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},Sn=/^path$/i,Cn={key:`PATH`,value:``};function wn(e){for(let t in e){if(!Object.prototype.hasOwnProperty.call(e,t)||!Sn.test(t))continue;let n=e[t];return n?{key:t,value:n}:Cn}return Cn}function Tn(e,t){let n=t.value.split(b),r=[],i=e,a;do r.push(C(i,`node_modules`,`.bin`)),a=i,i=x(i);while(i!==a);r.push(x(process.execPath));let o=r.concat(n).join(b);return{key:t.key,value:o}}function En(e,t,n=!0){let r={...process.env,...t};if(!n)return r;let i=Tn(e,wn(r));return r[i.key]=i.value,r}const Dn=e=>{let t=e.length,n=new re,r=()=>{--t===0&&n.end()};for(let t of e)oe(t,n,{end:!1}).then(r).catch(r);return n},On=/([()\][%!^"`<>&|;, *?])/g,kn=/^#!\s*(.+)/,An=/\.(?:com|exe)$/i,jn=/node_modules[\\/]\.bin[\\/][^\\/]+\.cmd$/i,Mn=process.platform===`win32`,Nn=[`.EXE`,`.CMD`,`.BAT`,`.COM`];function Pn(e,t=[],n={}){if(n.shell===!0||!Mn)return{command:e,args:t,options:n};let r=Fn(e,n),i=null;if(r!==null){let e=Buffer.alloc(150),t=null;try{t=m(r,`r`),h(t,e,0,150,0)}catch{}finally{t!==null&&u(t)}let n=e.toString().match(kn);if(n!==null){let e=n[1].trim(),t=e.indexOf(` `),r=t===-1?e:e.slice(0,t),a=t===-1?``:e.slice(t+1),o=y(r);i=o===`env`?a||null:o}}if(i!==null&&r!==null&&(t=[r,...t],e=i,r=Fn(e,n)),r===null||!An.test(r)){let i=r!==null&&jn.test(r);e=ee(e),e=e.replace(On,`^$1`),t=t.map(e=>(e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(On,`^$1`),i&&(e=e.replace(On,`^$1`)),e)),t=[`/d`,`/s`,`/c`,`"${[e,...t].join(` `)}"`],e=n.env?.comspec??`cmd.exe`,n={...n,windowsVerbatimArguments:!0}}return{command:e,args:t,options:n}}function Fn(e,t){let n=(t.cwd??i()).toString(),r=t.env??process.env,a=wn(r).value,o=e.includes(`/`)||e.includes(`\\`)?[``]:[n,...a.split(b)],s=r.PATHEXT?r.PATHEXT.split(b):Nn;e.includes(`.`)&&s[0]!==``&&s.unshift(``);for(let t of o){let r=C(n,t.startsWith(`"`)&&t.endsWith(`"`)&&t.length>1?t.slice(1,-1):t,e);for(let e of s){let t=r+e;try{if(v(t).isFile())return t}catch{}}}return null}var In=class extends Error{result;output;get exitCode(){if(this.result.exitCode!==null)return this.result.exitCode}constructor(e,t){super(`Process exited with non-zero status (${e.exitCode})`),this.result=e,this.output=t}};const Ln={timeout:void 0,persist:!1},Rn={windowsHide:!0};function zn(e){let t=new AbortController;for(let n of e){if(n.aborted)return t.abort(),n;n.addEventListener(`abort`,()=>{t.abort(n.reason)},{signal:t.signal})}return t.signal}async function Bn(e){let t=``;try{for await(let n of e)t+=n.toString()}catch{}return t}var Vn=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,t,n){this._options={...Ln,...n},this._command=e,this._args=t??[],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,t,n){return Un(e,t,{...n,stdin:this})}async*[Symbol.asyncIterator](){let e=this._process;if(!e)return;let t=[];this._streamErr&&t.push(this._streamErr),this._streamOut&&t.push(this._streamOut);let n=Dn(t),r=c.createInterface({input:n});for await(let e of r)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 In(this)}async _waitForOutput(){let e=this._process;if(!e)throw Error(`No process was started`);let[t,n]=await Promise.all([this._streamOut?Bn(this._streamOut):``,this._streamErr?Bn(this._streamErr):``]);await this._processClosed;let{stdin:r}=this._options;if(r&&typeof r!=`string`&&await r,e.removeAllListeners(),this._thrownError)throw this._thrownError;let i={stderr:n,stdout:t,exitCode:this.exitCode};if(this._options.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new In(this,i);return i}then(e,t){return this._waitForOutput().then(e,t)}_streamOut;_streamErr;spawn(){let e=i(),t=this._options,n={...Rn,...t.nodeOptions},r=[];this._resetState(),t.timeout!==void 0&&r.push(AbortSignal.timeout(t.timeout)),t.signal!==void 0&&r.push(t.signal),t.persist===!0&&(n.detached=!0),r.length>0&&(n.signal=zn(r)),n.env=En(e,n.env,t.nodePath);let a=Pn(this._command,this._args,n),o=se(a.command,a.args,a.options);if(o.stderr&&(this._streamErr=o.stderr),o.stdout&&(this._streamOut=o.stdout),this._process=o,o.once(`error`,this._onError),o.once(`close`,this._onClose),o.stdin){let{stdin:e}=t;typeof e==`string`?o.stdin.end(e):e?.process?.stdout?.pipe(o.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 Hn=(e,t,n)=>{let r=new Vn(e,t,n);return r.spawn(),r},Un=Hn;var Wn=ln({detectPackageManager:()=>Zn,installDependencies:()=>Qn,packageManagers:()=>Z});async function Gn(e,t,n={}){let r=gn(e).split(`/`);for(;r.length>0;){let e=await t(r.join(`/`)||`/`);if(e||!n.includeParentDirs)return e;r.pop()}}function Kn(e){let t;return()=>(t===void 0&&(t=e().then(e=>(t=e,t))),t)}const qn=Kn(async()=>{if(globalThis.process?.versions?.webcontainer)return!1;try{let{exitCode:e}=await Hn(`corepack`,[`--version`]);return e===0}catch{return!1}});async function Jn(e,t,n={}){let r=e!==`npm`&&e!==`bun`&&e!==`deno`&&n.corepack!==!1&&await qn()?[`corepack`,[e,...t]]:[e,t],{exitCode:i,stdout:a,stderr:o}=await Hn(r[0],r[1],{nodeOptions:{cwd:Y(n.cwd||process.cwd()),env:n.env,stdio:n.silent?`pipe`:`inherit`}});if(i!==0)throw Error(`\`${r.flat().join(` `)}\` failed.${n.silent?[``,a,o].join(`
|
|
80
|
+
`):``}`)}async function Yn(e={}){let t=e.cwd||process.cwd(),n={...process.env,...e.env},r=(typeof e.packageManager==`string`?Z.find(t=>t.name===e.packageManager):e.packageManager)||await Zn(e.cwd||process.cwd());if(!r)throw Error(`No package manager auto-detected.`);return{cwd:t,env:n,silent:e.silent??!1,packageManager:r,dev:e.dev??!1,workspace:e.workspace,global:e.global??!1,dry:e.dry??!1,corepack:e.corepack??!0}}function Xn(e){let[t,n]=(e||``).split(`@`),[r,i]=n?.split(`+`)||[];if(t&&t!==`-`&&/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(t))return{name:t,version:r,buildMeta:i};let a=(t||``).replace(/\W+/g,``);return{name:a,version:r,buildMeta:i,warnings:[`Abnormal characters found in \`packageManager\` field, sanitizing from \`${t}\` to \`${a}\``]}}const Z=[{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 Zn(e,t={}){let n=await Gn(Y(e||`.`),async e=>{if(!t.ignorePackageJSON){let t=_n(e,`package.json`);if(p(t)){let e=JSON.parse(await E(t,`utf8`));if(e?.packageManager){let{name:t,version:n=`0.0.0`,buildMeta:r,warnings:i}=Xn(e.packageManager);if(t){let e=n.split(`.`)[0],a=Z.find(n=>n.name===t&&n.majorVersion===e)||Z.find(e=>e.name===t);return{name:t,command:t,version:n,majorVersion:e,buildMeta:r,warnings:i,files:a?.files,lockFile:a?.lockFile}}}}if(p(_n(e,`deno.json`)))return Z.find(e=>e.name===`deno`)}if(!t.ignoreLockFile){for(let t of Z)if([t.lockFile,t.files].flat().filter(Boolean).some(t=>p(Y(e,t))))return{...t}}},{includeParentDirs:t.includeParentDirs??!0});if(!n&&!t.ignoreArgv){let e=process.argv[1];if(e){for(let t of Z)if(RegExp(`[/\\\\]\\.?${t.command}`).test(e))return t}}return n}async function Qn(e={}){let t=await Yn(e),n=e.frozenLockFile?{npm:[`ci`],yarn:[`install`,`--immutable`],bun:[`install`,`--frozen-lockfile`],pnpm:[`install`,`--frozen-lockfile`],deno:[`install`,`--frozen`]}[t.packageManager.name]:[`install`];return e.ignoreWorkspace&&t.packageManager.name===`pnpm`&&n.push(`--ignore-workspace`),t.dry||await Jn(t.packageManager.command,n,{cwd:t.cwd,silent:t.silent,corepack:t.corepack}),{exec:{command:t.packageManager.command,args:n}}}async function $n(e,n,r={}){let i=n+`.json`,a=JSON.parse(await E(i,`utf8`).catch(()=>`{}`)),o=(await $(e,{method:`HEAD`,headers:r.headers}).catch(()=>void 0))?.headers.get(`etag`);if(a.etag===o&&p(n))return;typeof o==`string`&&(a.etag=o);let s=await $(e,{headers:r.headers});if(s.status>=400)throw Error(`Failed to download ${e}: ${s.status} ${s.statusText}`);let c=f(n);await t(ae)(s.body,c),await O(i,JSON.stringify(a),`utf8`)}const er=/^(?<repo>[-\w.]+\/[-\w.]+)(?<subdir>[^#]+)?(?<ref>#[-\w./@]+)?/,tr=/^(?<repo>[-\w.]+(?:\/[-\w.]+)+?)(?:::(?<subdir>[^#]*))?(?<ref>#[-\w./@]+)?$/;function nr(e,t){let n=t?.expandRepo||e.includes(`::`),r=e.match(n?tr:er)?.groups||{},i=n?r.subdir?`/`+r.subdir:`/`:r.subdir||`/`;return{repo:r.repo||``,subdir:i,ref:r.ref?r.ref.slice(1):`main`}}function Q(...e){process.env.DEBUG&&console.debug(`[giget]`,...e)}async function $(e,t={}){t.headers?.[`sec-fetch-mode`]&&(t.mode=t.headers[`sec-fetch-mode`]);let n=await fetch(e,{...t,headers:ir(t.headers)}).catch(t=>{throw Error(`Failed to download ${e}: ${t}`,{cause:t})});if(t.validateStatus&&n.status>=400)throw Error(`Failed to fetch ${e}: ${n.status} ${n.statusText}`);return n}function rr(){let e=process.env.XDG_CACHE_HOME?Y(process.env.XDG_CACHE_HOME,`giget`):Y(ce(),`.cache/giget`);if(process.platform===`win32`){let t=Y(le(),`giget`);if(!p(t)&&p(e))try{_(e,t)}catch{}return t}return e}function ir(e={}){let t={};for(let[n,r]of Object.entries(e))r&&(t[n.toLowerCase()]=r);return t}const ar=(e,t)=>{let n=or(e);return{name:n.name,version:n.subdir?`${n.version||`default`}-${n.subdir.replaceAll(`/`,`-`)}`:n.version,tar:({auth:e}={})=>sr(n,e??t.auth)}};function or(e,t={}){let n=t.cwd??process.cwd(),r=e.replace(/#.*$/,``),i;if(/^[./]/.test(e))r=Y(n,r);else if(/^https?:\/\//.test(r)){let e=/^(https?:\/\/[^/]+)\/([\w.-]+\/[\w.-]+?)(?:\.git)?(?:\/(.+))?$/.exec(r);if(e){let[,t,n,a]=e;r=`${t}/${n}`,a&&(i=a)}}else if(r.includes(`@`)){let e=/^(.*?:[\w.-]+\/[\w.-]+?)(?:\.git)?(?:\/(.+))?$/.exec(r);if(e){let[,t,n]=e;r=t,n&&(i=n)}}else{let e={"github:":`https://github.com/`,"gh:":`https://github.com/`,"gitlab:":`https://gitlab.com/`,"bitbucket:":`https://bitbucket.org/`,"sourcehut:":`https://git.sr.ht/~`},t=/^(.+?:)/.exec(r)?.at(1);t&&e[t]?r=r.replace(t,e[t]):t||(r=`${(process.env.GIGET_GIT_HOST||`https://github.com/`).replace(/\/$/,``)}/${r}`);let n=/^(https?:\/\/[^/]+\/~?[\w.-]+\/[\w.-]+?)(?:\.git)?(?:\/(.+))?$/.exec(r);if(n){let[,e,t]=n;r=e,t&&(i=t)}}let a=r.replace(/^https?:\/\//,``).replace(/^.+@/,``).replace(/(\.git)?(#.*)?$/,``).replace(/^\W+/,``).replaceAll(/[:/]/g,`-`),[o,s]=/#(.+)$/.exec(e)?.at(1)?.split(`:`)??[],c=o||void 0,l=s||i;return{uri:r,name:a,...c&&{version:c},...l&&{subdir:l}}}async function sr(e,t){let n=await te(S(le(),`giget-git-`));if(t&&/[\r\n]/.test(t))throw Error(`Auth token must not contain newline characters`);let r={...process.env,GIT_TERMINAL_PROMPT:`0`};t&&(r.GIT_CONFIG_COUNT=`1`,r.GIT_CONFIG_KEY_0=`http.extraHeader`,r.GIT_CONFIG_VALUE_0=`Authorization: Bearer ${t}`);let i={env:r,timeout:6e4},a=ur(),o=e=>lr(e,i,a),s=e=>lr(e,{...i,cwd:n},a);try{let t=[`clone`,`--progress`,`--depth`,`1`];e.subdir&&t.push(`--filter=blob:none`,`--sparse`,`--no-checkout`),e.version&&t.push(`--branch`,e.version),t.push(`--`,e.uri,n);try{a.update(`Cloning...`),await o(t),a.update(`Cloned.`)}catch(t){if(!e.version)throw t;Q(`Shallow clone failed, falling back to full clone:`,t),a.update(`Shallow clone failed, cloning...`),await D(n,{recursive:!0,force:!0}),await T(n,{recursive:!0}),await s([`init`]),await s([`remote`,`add`,`origin`,e.uri]),await s([`fetch`,`origin`]),await s([`checkout`,e.version]),a.update(`Fetched.`)}e.subdir&&(a.update(`Sparse checkout ${e.subdir}...`),await s([`sparse-checkout`,`set`,e.subdir]),await s([`checkout`])),a.update(`Packing...`);let r=e.subdir?S(n,e.subdir):n,{create:i}=await import(`./tar-BOAfigV2.mjs`).then(e=>e.index_min_exports);a.done();let c=i({gzip:!0,cwd:r,filter:e=>!e.startsWith(`.git/`)&&e!==`.git`&&!e.startsWith(`./.git/`)&&e!==`./.git`},[`.`]).pipe(new re),l=!1,u=()=>{l||(l=!0,D(n,{recursive:!0,force:!0}))};return c.on(`end`,u),c.on(`error`,u),c.on(`close`,u),c}catch(e){throw a.done(),await D(n,{recursive:!0,force:!0}),e}}const cr=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];function lr(e,t,n){return new Promise((r,i)=>{let a=se(`git`,e,{...t,stdio:[`ignore`,`pipe`,`pipe`]});a.stdout.resume();let o=``;a.stderr?.on(`data`,e=>{let t=e.toString();for(let e of t.split(/[\r\n]/)){let t=e.trim();t&&(o=t)}n&&n.update(o)}),a.on(`close`,t=>{t===0?r(o):i(Error(`git ${e[0]} exited with code ${t}. Is git installed?`))}),a.on(`error`,e=>{e.code===`ENOENT`?i(Error(`git is not installed or not found in PATH`)):i(e)})})}function ur(){if(!process.stderr.isTTY)return{update(e){},done(){}};let e=``,t=0,n=()=>{let n=cr[t%cr.length];t++,process.stderr.write(`\x1B[2K\r\x1B[2m${n} ${e}\x1B[0m`)},r=setInterval(n,80);return{update(t){e=t,n()},done(){clearInterval(r),process.stderr.write(`\x1B[2K\r`)}}}const dr=async(e,t)=>{if(e.endsWith(`.json`))return await fr(e,t);let n=new URL(e),r=xn(n.pathname);try{let i=await $(n.href,{method:`HEAD`,validateStatus:!0,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0}});if((i.headers.get(`content-type`)||``).includes(`application/json`))return await fr(e,t);let a=i.headers.get(`content-disposition`)?.match(/filename="?(.+)"?/)?.[1];a&&(r=a.split(`.`)[0])}catch(e){Q(`Failed to fetch HEAD for ${n.href}:`,e)}return{name:`${r}-${n.href.slice(0,8)}`,version:``,subdir:``,tar:n.href,defaultDir:r,headers:{Authorization:t.auth?`Bearer ${t.auth}`:void 0}}},fr=async(e,t)=>{let n=await(await $(e,{validateStatus:!0,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0}})).json();if(!n.tar||!n.name)throw Error(`Invalid template info from ${e}. name or tar fields are missing!`);return n},pr=(e,t)=>{let n=nr(e),r=process.env.GIGET_GITHUB_URL||`https://api.github.com`;return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{Authorization:t.auth?`Bearer ${t.auth}`:void 0,Accept:`application/vnd.github+json`,"X-GitHub-Api-Version":`2022-11-28`},url:`${r.replace(`api.github.com`,`github.com`)}/${n.repo}/tree/${n.ref}${n.subdir}`,tar:`${r}/repos/${n.repo}/tarball/${n.ref}`}},mr={http:dr,https:dr,git:ar,github:pr,gh:pr,gitlab:(e,t)=>{let n=nr(e,{expandRepo:!0}),r=process.env.GIGET_GITLAB_URL||`https://gitlab.com`;return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0,"sec-fetch-mode":`same-origin`},url:`${r}/${n.repo}/tree/${n.ref}${n.subdir}`,tar:`${r}/${n.repo}/-/archive/${n.ref}.tar.gz`}},bitbucket:(e,t)=>{let n=nr(e);return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0},url:`https://bitbucket.com/${n.repo}/src/${n.ref}${n.subdir}`,tar:`https://bitbucket.org/${n.repo}/get/${n.ref}.tar.gz`}},sourcehut:(e,t)=>{let n=nr(e);return{name:n.repo.replace(`/`,`-`),version:n.ref,subdir:n.subdir,headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0},url:`https://git.sr.ht/~${n.repo}/tree/${n.ref}/item${n.subdir}`,tar:`https://git.sr.ht/~${n.repo}/archive/${n.ref}.tar.gz`}}},hr=(e=`https://raw.githubusercontent.com/unjs/giget/main/templates`,t={})=>(async n=>{let r=Date.now(),i=`${e}/${n}.json`,a=await $(i,{headers:{authorization:t.auth?`Bearer ${t.auth}`:void 0}});if(a.status>=400)throw Error(`Failed to download ${n} template info from ${i}: ${a.status} ${a.statusText}`);let o=await a.json();if(!o.tar||!o.name)throw Error(`Invalid template info from ${i}. name or tar fields are missing!`);return Q(`Fetched ${n} template info from ${i} in ${Date.now()-r}ms`),o}),gr=/^([\w+-.]+):/;function _r(e){if(!e)return;if(typeof e==`function`)return e;let t=globalThis.process.getBuiltinModule?.(`node:path`)?.matchesGlob;if(typeof t!=`function`)throw TypeError("Ignore patterns require `path.matchesGlob` which is supported in Node.js v22.5.0, v20.17.0 or later.");return n=>e.some(e=>t(n,e))}async function vr(e,t={}){let n=_r(t.ignore);t.registry=process.env.GIGET_REGISTRY??t.registry,t.auth=process.env.GIGET_AUTH??t.auth;let r=t.registry===!1?void 0:hr(t.registry,{auth:t.auth}),i=t.provider||(r?`registry`:`github`),a=e,o=e.match(gr);o&&(i=o[1],a=e.slice(o[0].length),(i===`http`||i===`https`)&&(a=e)),i.endsWith(`+git`)&&(a=`${i.slice(0,-4)}:${a}`,i=`git`);let s=t.providers?.[i]||mr[i]||r;if(!s)throw Error(`Unsupported provider: ${i}`);let c=await Promise.resolve().then(()=>s(a,{auth:t.auth})).catch(e=>{throw Error(`Failed to download template from ${i}: ${e.message}`)});if(!c)throw Error(`Failed to resolve template from ${i}`);c.name=(c.name||`template`).replace(/[^\da-z-]/gi,`-`),c.defaultDir=(c.defaultDir||c.name).replace(/[^\da-z-]/gi,`-`);let l=Y(Y(rr(),i,c.name),(c.version||c.name)+`.tar.gz`);if(t.preferOffline&&p(l)&&(t.offline=!0),!t.offline){await T(bn(l),{recursive:!0});let e=Date.now();if(typeof c.tar==`function`){let e=c.tar;await(async()=>{let n=await e({auth:t.auth});await oe(n instanceof ie?n:ie.fromWeb(n),f(l))})().catch(e=>{if(!p(l))throw e;Q(`Download error. Using cached version:`,e),t.offline=!0})}else await $n(c.tar,l,{headers:{Authorization:t.auth?`Bearer ${t.auth}`:void 0,...ir(c.headers)}}).catch(e=>{if(!p(l))throw e;Q(`Download error. Using cached version:`,e),t.offline=!0});Q(`Downloaded to ${l} in ${Date.now()-e}ms`)}if(!p(l))throw Error(`Tarball not found: ${l} (offline: ${t.offline})`);let u=Y(Y(t.cwd||`.`),t.dir||c.defaultDir);if(t.forceClean&&await D(u,{recursive:!0,force:!0}),!t.force&&p(u)&&g(u).length>0)throw Error(`Destination ${u} already exists.`);await T(u,{recursive:!0});let d=Date.now(),m=c.subdir?.replace(/^\//,``)||``,{extract:h}=await import(`./tar-BOAfigV2.mjs`).then(e=>e.index_min_exports);if(await h({file:l,cwd:u,onReadEntry(e){e.path=e.path.split(`/`).splice(1).join(`/`),m&&(e.path.startsWith(m+`/`)?e.path=e.path.slice(m.length):e.path=``),n&&e.path&&n(e.path.replace(/^\//,``))&&(e.path=``)}}),Q(`Extracted to ${u} in ${Date.now()-d}ms`),t.install){Q(`Installing dependencies...`);let{installDependencies:e}=await Promise.resolve().then(()=>un).then(e=>e.dist_exports);await e({cwd:u,silent:t.silent,...typeof t.install==`object`?t.install:{}})}return{...c,source:a,dir:u}}function yr(e){return e}const br=yr([`default`,`monorepo`]),xr={name:{type:`positional`,description:`Project name`,required:!1},template:{type:`enum`,description:`Template to use`,options:br,required:!1,alias:[`t`]},install:{type:`boolean`,description:`Install dependencies with pnpm`,required:!1,alias:[`i`]}},Sr=/^path$/i,Cr={key:`PATH`,value:``};function wr(e){for(let t in e){if(!Object.prototype.hasOwnProperty.call(e,t)||!Sr.test(t))continue;let n=e[t];return n?{key:t,value:n}:Cr}return Cr}function Tr(e,t){let n=t.value.split(b),r=[],i=e,a;do r.push(C(i,`node_modules`,`.bin`)),a=i,i=x(i);while(i!==a);r.push(x(process.execPath));let o=r.concat(n).join(b);return{key:t.key,value:o}}function Er(e,t,n=!0){let r={...process.env,...t};if(!n)return r;let i=Tr(e,wr(r));return r[i.key]=i.value,r}const Dr=e=>{let t=e.length,n=new re,r=()=>{--t===0&&n.end()};for(let t of e)oe(t,n,{end:!1}).then(r).catch(r);return n},Or=/([()\][%!^"`<>&|;, *?])/g,kr=/^#!\s*(.+)/,Ar=/\.(?:com|exe)$/i,jr=/node_modules[\\/]\.bin[\\/][^\\/]+\.cmd$/i,Mr=process.platform===`win32`,Nr=[`.EXE`,`.CMD`,`.BAT`,`.COM`];function Pr(e,t=[],n={}){if(n.shell===!0||!Mr)return{command:e,args:t,options:n};let r=Fr(e,n),i=null;if(r!==null){let e=Buffer.alloc(150),t=null;try{t=m(r,`r`),h(t,e,0,150,0)}catch{}finally{t!==null&&u(t)}let n=e.toString().match(kr);if(n!==null){let e=n[1].trim(),t=e.indexOf(` `),r=t===-1?e:e.slice(0,t),a=t===-1?``:e.slice(t+1),o=y(r);i=o===`env`?a||null:o}}if(i!==null&&r!==null&&(t=[r,...t],e=i,r=Fr(e,n)),r===null||!Ar.test(r)){let i=r!==null&&jr.test(r);e=ee(e),e=e.replace(Or,`^$1`),t=t.map(e=>(e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(Or,`^$1`),i&&(e=e.replace(Or,`^$1`)),e)),t=[`/d`,`/s`,`/c`,`"${[e,...t].join(` `)}"`],e=n.env?.comspec??`cmd.exe`,n={...n,windowsVerbatimArguments:!0}}return{command:e,args:t,options:n}}function Fr(e,t){let n=(t.cwd??i()).toString(),r=t.env??process.env,a=wr(r).value,o=e.includes(`/`)||e.includes(`\\`)?[``]:[n,...a.split(b)],s=r.PATHEXT?r.PATHEXT.split(b):Nr;e.includes(`.`)&&s[0]!==``&&s.unshift(``);for(let t of o){let r=C(n,t.startsWith(`"`)&&t.endsWith(`"`)&&t.length>1?t.slice(1,-1):t,e);for(let e of s){let t=r+e;try{if(v(t).isFile())return t}catch{}}}return null}var Ir=class extends Error{result;output;get exitCode(){if(this.result.exitCode!==null)return this.result.exitCode}constructor(e,t){super(`Process exited with non-zero status (${e.exitCode})`),this.result=e,this.output=t}};const Lr={timeout:void 0,persist:!1},Rr={windowsHide:!0};function zr(e){let t=new AbortController;for(let n of e){if(n.aborted)return t.abort(),n;n.addEventListener(`abort`,()=>{t.abort(n.reason)},{signal:t.signal})}return t.signal}async function Br(e){let t=``;try{for await(let n of e)t+=n.toString()}catch{}return t}var Vr=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,t,n){this._options={...Lr,...n},this._command=e,this._args=t??[],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,t,n){return Ur(e,t,{...n,stdin:this})}async*[Symbol.asyncIterator](){let e=this._process;if(!e)return;let t=[];this._streamErr&&t.push(this._streamErr),this._streamOut&&t.push(this._streamOut);let n=Dr(t),r=c.createInterface({input:n});for await(let e of r)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 Ir(this)}async _waitForOutput(){let e=this._process;if(!e)throw Error(`No process was started`);let[t,n]=await Promise.all([this._streamOut?Br(this._streamOut):``,this._streamErr?Br(this._streamErr):``]);await this._processClosed;let{stdin:r}=this._options;if(r&&typeof r!=`string`&&await r,e.removeAllListeners(),this._thrownError)throw this._thrownError;let i={stderr:n,stdout:t,exitCode:this.exitCode};if(this._options.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new Ir(this,i);return i}then(e,t){return this._waitForOutput().then(e,t)}_streamOut;_streamErr;spawn(){let e=i(),t=this._options,n={...Rr,...t.nodeOptions},r=[];this._resetState(),t.timeout!==void 0&&r.push(AbortSignal.timeout(t.timeout)),t.signal!==void 0&&r.push(t.signal),t.persist===!0&&(n.detached=!0),r.length>0&&(n.signal=zr(r)),n.env=Er(e,n.env,t.nodePath);let a=Pr(this._command,this._args,n),o=se(a.command,a.args,a.options);if(o.stderr&&(this._streamErr=o.stderr),o.stdout&&(this._streamOut=o.stdout),this._process=o,o.once(`error`,this._onError),o.once(`close`,this._onClose),o.stdin){let{stdin:e}=t;typeof e==`string`?o.stdin.end(e):e?.process?.stdout?.pipe(o.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 Hr=(e,t,n)=>{let r=new Vr(e,t,n);return r.spawn(),r},Ur=Hr;function Wr(){let e=process.env.npm_config_user_agent??``;return e.startsWith(`pnpm/`)?`pnpm`:e.startsWith(`yarn/`)?`yarn`:e.startsWith(`bun/`)?`bun`:e.startsWith(`deno/`)?`deno`:`npm`}async function Gr(){try{return await Hr(`pnpm`,[`--version`],{throwOnError:!0}),!0}catch{return!1}}async function Kr(e){await Hr(`git`,[`init`],{throwOnError:!1,nodeOptions:{cwd:e,stdio:`inherit`}})}async function qr(e,t){let n=Et({title:`Installing dependencies with ${t}...`,limit:5,retainLog:!1}),r=St();r.start();let i=[`install`];t===`npm`&&i.push(`--legacy-peer-deps`);let a=Hr(t,i,{throwOnError:!1,nodeOptions:{cwd:e}});for await(let e of a){let t=e.trim();t&&n.message(t)}let o=await a;return r.stop(),o.exitCode===0?(n.success(`Dependencies installed`),!0):(n.error(`Dependency installation failed. You can run \`${t} install\` manually.`),!1)}function Jr(e){return e===`npm`?`npm run dev`:e===`deno`?`deno task dev`:`${e} dev`}const Yr=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;function Xr(e){for(let t of e){let e=t.codePointAt(0);if(e!==void 0&&(e<=31||`<>:"|?*`.includes(t)))return!0}return!1}function Zr(e){let t=e.trim();if(t.length===0)return`Project name is required`;if(t!==`.`){if(t.includes(`/`)||t.includes(`\\`))return`Project name cannot contain path separators`;if(Xr(t))return`Project name contains invalid characters`;if(t===`..`)return`Project name cannot be ..`;if(t.startsWith(`.`))return`Project name cannot start with a period`;if(t.endsWith(`.`)||t.endsWith(`-`))return`Project name cannot end with a period or hyphen`;if(t.length>214)return`Project name must be 214 characters or fewer`;if(!Yr.test(t))return`Use letters, numbers, periods, underscores, or hyphens`}}function Qr(e,t){return typeof t==`string`&&e.includes(t)}async function $r(e){let t;try{t=await ne(e)}catch(e){if(e&&typeof e==`object`&&`code`in e&&e.code===`ENOENT`)return;throw e}if(t.length>0)return`Directory must be empty.`}async function ei(){let e=await Dt({message:`Project name:`,placeholder:`my-project`,defaultValue:`my-project`,validate(e){if(typeof e==`string`)return Zr(e)}});if(Be(e)){H(`Operation cancelled.`);return}return e}async function ti(){let e=await wt({message:`Select a template:`,options:[{value:`default`,label:`Default`,hint:`minimal TanStarter template`},{value:`monorepo`,label:`Monorepo`,hint:`TanStarter via pnpm workspaces`}]});if(Be(e)){H(`Operation cancelled.`);return}return e}async function ni(){let e=await gt({message:`Install dependencies after scaffolding?`,initialValue:!0});if(Be(e)){H(`Operation cancelled.`);return}return e}async function ri(e){let t=e.name,n=e.template,r=e.install,i=await Gr()?`pnpm`:Wr();if(!t&&(t=await ei(),!t))return;t=String(t).trim();let a=await $r(t===`.`?process.cwd():S(process.cwd(),t));if(a){H(a);return}let o=Zr(t);if(o){H(o);return}if(!(!n&&(n=await ti(),!n))&&!(r===void 0&&i===`pnpm`&&(r=await ni(),r===void 0))&&!(!Qr(br,n)||typeof r!=`boolean`))return{projectName:t,template:n,install:r,selectedPackageManager:void 0,preferredPackageManager:i}}const ii={default:{source:`github:mugnavo/tanstarter`,homeUrl:`https://github.com/mugnavo/tanstarter`},monorepo:{source:`github:mugnavo/tanstarter-monorepo`,homeUrl:`https://github.com/mugnavo/tanstarter-monorepo`}};function ai(e){return ii[e]}function oi(e,t){if(!t)return"This project was scaffolded with [`create-mugnavo`](https://github.com/mugnavo/create-mugnavo).";let n=ai(e);return`This project was scaffolded with \`create-mugnavo\` from commit [\`${t.slice(0,7)}\`](${`${n.homeUrl}/tree/${t}`}). See the [template changelog](${`${n.homeUrl}/compare/${t}...main`}) for newer changes.`}function si(e,t,n){if(!n)return!1;let r=e.findIndex(e=>e.trim()===`## Issue watchlist`);if(r===-1)return!1;let i=e.findIndex((e,t)=>t>r&&e.startsWith(`## `)),a=i===-1?e.length:i,o=`${ai(t).homeUrl}/compare/${n}...main`;if(e.slice(r+1,a).some(e=>e.includes(o)))return!1;let s=r+1;for(;s<a&&e[s]?.trim()===``;)s+=1;return e.splice(s,0,`- [Template changelog](${o}) - Track template updates since this project was created.`),!0}function ci(e,t){return t===`.`?y(C(e))||`app`:t}async function li(e){await D(S(e,`LICENSE`),{force:!0})}async function ui(e,t){if(t==="default"){await w(S(e,`.env.example`),S(e,`.env`),d.COPYFILE_EXCL);return}if(t===`monorepo`){await w(S(e,`apps`,`web`,`.env.example`),S(e,`apps`,`web`,`.env`),d.COPYFILE_EXCL);return}}async function di(e,t){let n=S(e,`package.json`),r=JSON.parse(await E(n,`utf8`));r.name=ci(e,t),await O(n,`${JSON.stringify(r,null,2)}\n`)}async function fi(e,t,n,r){let i=S(e,`README.md`),a=ci(e,n),o=await E(i,`utf8`),s=o.includes(`\r
|
|
86
81
|
`)?`\r
|
|
87
82
|
`:`
|
|
88
|
-
`,c=o.split(/\r?\n/),l=c.findIndex(e=>e.startsWith(`# `));l===-1?c.length>0&&(c[0]=`# ${a}`):c[l]=`# ${a}`,
|
|
83
|
+
`,c=o.split(/\r?\n/),l=c.findIndex(e=>e.startsWith(`# `));l===-1?c.length>0&&(c[0]=`# ${a}`):c[l]=`# ${a}`,pi(c,[{marker:`<!-- scaffold:description -->`,replacementContent:oi(t,r),skipEmptyLinesAfterMarker:!0}]),si(c,t,r);let u=c.join(s);u!==o&&await O(i,u)}function pi(e,t){let n=!1;for(let{marker:r,replacementContent:i,skipEmptyLinesAfterMarker:a}of t){let t=e.findIndex(e=>e.trim()===r);if(t===-1)continue;let o=t+1;if(a)for(;e[o]!==void 0&&e[o]?.trim()===``;)o+=1;let s=e[o];if(s===void 0){e.splice(t,1),n=!0;continue}let c=`${s.match(/^\s*/)?.[0]??``}${i}`;e.splice(t,o-t+1,c),n=!0}return n}async function mi(e,t){let n=await E(e,`utf8`),r=n.includes(`\r
|
|
89
84
|
`)?`\r
|
|
90
85
|
`:`
|
|
91
|
-
`,i=n.split(/\r?\n/);
|
|
92
|
-
`)}
|
|
86
|
+
`,i=n.split(/\r?\n/);pi(i,t)&&await O(e,i.join(r))}async function hi(e,t,n){let r=ci(e,n);await mi(t==="default"?S(e,`src`,`routes`,`__root.tsx`):S(e,`apps`,`web`,`src`,`routes`,`__root.tsx`),[{marker:`// scaffold:title`,replacementContent:`title: ${JSON.stringify(r)},`},{marker:`// scaffold:description`,replacementContent:`content: "A TanStack Start project scaffolded with create-mugnavo.",`}])}async function gi(e,t,n,r){await Promise.allSettled([li(e),ui(e,t),di(e,n),fi(e,t,n,r),hi(e,t,n)])}function _i(e){return new URL(e).pathname.replace(/^\/|\/$/g,``)}async function vi(e){try{let t=_i(e.homeUrl),n=await fetch(`https://api.github.com/repos/${t}/commits/main`,{headers:{accept:`application/vnd.github+json`,"user-agent":`create-mugnavo`},signal:AbortSignal.timeout(5e3)});if(!n.ok)throw Error(`GitHub API request failed with status ${n.status}`);let r=await n.json();if(!r.sha)throw Error(`GitHub API response did not include commit metadata`);return r.sha}catch{return}}function yi(e,t,n,r){let i=[];return e!==`.`&&i.push(`cd ${e}`),t||i.push(`${n} install${n===`npm`?` --legacy-peer-deps`:``}`),i.push(r,``,`See README.md for next steps`),i.join(`
|
|
87
|
+
`)}an(qt({meta:{name:`create-mugnavo`,version:`0.6.0`,description:`Create a project using Mugnavo templates.`},args:xr,async run({args:e}){let t=await ri(e);if(!t)return;let{projectName:n,template:r,install:i,selectedPackageManager:a,preferredPackageManager:o}=t,s=St();try{let e=ai(r),t=vi(e);s.start(`Cloning project...`);let{dir:c,source:l}=await vr(e.source,{dir:n,force:!0,forceClean:!0});await gi(c,r,n,await t);let u=a||o;s.stop(`Project cloned from ${l}`),await Kr(c),i&&(await qr(c,u)||(i=!1));let d=yi(n,i,u,Jr(u));bt(`${d}\n${e.homeUrl}`,`Next steps`),_t(`All set. Happy coding! 🚀`)}catch(e){s.stop(),_t(`Failed to download template. Please try again later.`),console.error(e);return}}}));export{ln as t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{t as e}from"./index.mjs";import t from"node:fs";import n,{basename as r,join as i,posix as a,win32 as o}from"node:path";import s from"node:fs/promises";import c from"node:stream";import l,{EventEmitter as u}from"events";import d from"fs";import{EventEmitter as f}from"node:events";import{StringDecoder as ee}from"node:string_decoder";import p,{dirname as m,parse as te}from"path";import ne from"assert";import{Buffer as re}from"buffer";import*as ie from"zlib";import ae from"zlib";import oe from"node:assert";import{randomBytes as se}from"node:crypto";var ce=e({Header:()=>I,Pack:()=>ii,PackJob:()=>Lr,PackSync:()=>ai,Parser:()=>Jn,Pax:()=>gn,ReadEntry:()=>bn,Unpack:()=>ya,UnpackSync:()=>xa,WriteEntry:()=>Or,WriteEntrySync:()=>kr,WriteEntryTar:()=>Ar,c:()=>ui,create:()=>ui,extract:()=>Sa,filesFilter:()=>Zn,list:()=>Qn,r:()=>Oa,replace:()=>Oa,t:()=>Qn,types:()=>Xt,x:()=>Sa}),le=Object.defineProperty,ue=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},de=typeof process==`object`&&process?process:{stdout:null,stderr:null},fe=e=>!!e&&typeof e==`object`&&(e instanceof Ue||e instanceof c||pe(e)||me(e)),pe=e=>!!e&&typeof e==`object`&&e instanceof f&&typeof e.pipe==`function`&&e.pipe!==c.Writable.prototype.pipe,me=e=>!!e&&typeof e==`object`&&e instanceof f&&typeof e.write==`function`&&typeof e.end==`function`,h=Symbol(`EOF`),g=Symbol(`maybeEmitEnd`),_=Symbol(`emittedEnd`),he=Symbol(`emittingEnd`),ge=Symbol(`emittedError`),_e=Symbol(`closed`),ve=Symbol(`read`),ye=Symbol(`flush`),be=Symbol(`flushChunk`),v=Symbol(`encoding`),xe=Symbol(`decoder`),y=Symbol(`flowing`),Se=Symbol(`paused`),Ce=Symbol(`resume`),b=Symbol(`buffer`),x=Symbol(`pipes`),S=Symbol(`bufferLength`),we=Symbol(`bufferPush`),Te=Symbol(`bufferShift`),C=Symbol(`objectMode`),w=Symbol(`destroyed`),Ee=Symbol(`error`),De=Symbol(`emitData`),Oe=Symbol(`emitEnd`),ke=Symbol(`emitEnd2`),T=Symbol(`async`),Ae=Symbol(`abort`),je=Symbol(`aborted`),Me=Symbol(`signal`),Ne=Symbol(`dataListeners`),E=Symbol(`discarded`),Pe=e=>Promise.resolve().then(e),Fe=e=>e(),Ie=e=>e===`end`||e===`finish`||e===`prefinish`,Le=e=>e instanceof ArrayBuffer||!!e&&typeof e==`object`&&e.constructor&&e.constructor.name===`ArrayBuffer`&&e.byteLength>=0,Re=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),ze=class{src;dest;opts;ondrain;constructor(e,t,n){this.src=e,this.dest=t,this.opts=n,this.ondrain=()=>e[Ce](),this.dest.on(`drain`,this.ondrain)}unpipe(){this.dest.removeListener(`drain`,this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Be=class extends ze{unpipe(){this.src.removeListener(`error`,this.proxyErrors),super.unpipe()}constructor(e,t,n){super(e,t,n),this.proxyErrors=e=>this.dest.emit(`error`,e),e.on(`error`,this.proxyErrors)}},Ve=e=>!!e.objectMode,He=e=>!e.objectMode&&!!e.encoding&&e.encoding!==`buffer`,Ue=class extends f{[y]=!1;[Se]=!1;[x]=[];[b]=[];[C];[v];[T];[xe];[h]=!1;[_]=!1;[he]=!1;[_e]=!1;[ge]=null;[S]=0;[w]=!1;[Me];[je]=!1;[Ne]=0;[E]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding==`string`)throw TypeError(`Encoding and objectMode may not be used together`);Ve(t)?(this[C]=!0,this[v]=null):He(t)?(this[v]=t.encoding,this[C]=!1):(this[C]=!1,this[v]=null),this[T]=!!t.async,this[xe]=this[v]?new ee(this[v]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[b]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[x]});let{signal:n}=t;n&&(this[Me]=n,n.aborted?this[Ae]():n.addEventListener(`abort`,()=>this[Ae]()))}get bufferLength(){return this[S]}get encoding(){return this[v]}set encoding(e){throw Error(`Encoding must be set at instantiation time`)}setEncoding(e){throw Error(`Encoding must be set at instantiation time`)}get objectMode(){return this[C]}set objectMode(e){throw Error(`objectMode must be set at instantiation time`)}get async(){return this[T]}set async(e){this[T]=this[T]||!!e}[Ae](){this[je]=!0,this.emit(`abort`,this[Me]?.reason),this.destroy(this[Me]?.reason)}get aborted(){return this[je]}set aborted(e){}write(e,t,n){if(this[je])return!1;if(this[h])throw Error(`write after end`);if(this[w])return this.emit(`error`,Object.assign(Error(`Cannot call write after a stream was destroyed`),{code:`ERR_STREAM_DESTROYED`})),!0;typeof t==`function`&&(n=t,t=`utf8`),t||=`utf8`;let r=this[T]?Pe:Fe;if(!this[C]&&!Buffer.isBuffer(e)){if(Re(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Le(e))e=Buffer.from(e);else if(typeof e!=`string`)throw Error(`Non-contiguous data written to non-objectMode stream`)}return this[C]?(this[y]&&this[S]!==0&&this[ye](!0),this[y]?this.emit(`data`,e):this[we](e),this[S]!==0&&this.emit(`readable`),n&&r(n),this[y]):e.length?(typeof e==`string`&&!(t===this[v]&&!this[xe]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[v]&&(e=this[xe].write(e)),this[y]&&this[S]!==0&&this[ye](!0),this[y]?this.emit(`data`,e):this[we](e),this[S]!==0&&this.emit(`readable`),n&&r(n),this[y]):(this[S]!==0&&this.emit(`readable`),n&&r(n),this[y])}read(e){if(this[w])return null;if(this[E]=!1,this[S]===0||e===0||e&&e>this[S])return this[g](),null;this[C]&&(e=null),this[b].length>1&&!this[C]&&(this[b]=[this[v]?this[b].join(``):Buffer.concat(this[b],this[S])]);let t=this[ve](e||null,this[b][0]);return this[g](),t}[ve](e,t){if(this[C])this[Te]();else{let n=t;e===n.length||e===null?this[Te]():typeof n==`string`?(this[b][0]=n.slice(e),t=n.slice(0,e),this[S]-=e):(this[b][0]=n.subarray(e),t=n.subarray(0,e),this[S]-=e)}return this.emit(`data`,t),!this[b].length&&!this[h]&&this.emit(`drain`),t}end(e,t,n){return typeof e==`function`&&(n=e,e=void 0),typeof t==`function`&&(n=t,t=`utf8`),e!==void 0&&this.write(e,t),n&&this.once(`end`,n),this[h]=!0,this.writable=!1,(this[y]||!this[Se])&&this[g](),this}[Ce](){this[w]||(!this[Ne]&&!this[x].length&&(this[E]=!0),this[Se]=!1,this[y]=!0,this.emit(`resume`),this[b].length?this[ye]():this[h]?this[g]():this.emit(`drain`))}resume(){return this[Ce]()}pause(){this[y]=!1,this[Se]=!0,this[E]=!1}get destroyed(){return this[w]}get flowing(){return this[y]}get paused(){return this[Se]}[we](e){this[C]?this[S]+=1:this[S]+=e.length,this[b].push(e)}[Te](){return this[C]?--this[S]:this[S]-=this[b][0].length,this[b].shift()}[ye](e=!1){do;while(this[be](this[Te]())&&this[b].length);!e&&!this[b].length&&!this[h]&&this.emit(`drain`)}[be](e){return this.emit(`data`,e),this[y]}pipe(e,t){if(this[w])return e;this[E]=!1;let n=this[_];return t||={},e===de.stdout||e===de.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,n?t.end&&e.end():(this[x].push(t.proxyErrors?new Be(this,e,t):new ze(this,e,t)),this[T]?Pe(()=>this[Ce]()):this[Ce]()),e}unpipe(e){let t=this[x].find(t=>t.dest===e);t&&(this[x].length===1?(this[y]&&this[Ne]===0&&(this[y]=!1),this[x]=[]):this[x].splice(this[x].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let n=super.on(e,t);if(e===`data`)this[E]=!1,this[Ne]++,!this[x].length&&!this[y]&&this[Ce]();else if(e===`readable`&&this[S]!==0)super.emit(`readable`);else if(Ie(e)&&this[_])super.emit(e),this.removeAllListeners(e);else if(e===`error`&&this[ge]){let e=t;this[T]?Pe(()=>e.call(this,this[ge])):e.call(this,this[ge])}return n}removeListener(e,t){return this.off(e,t)}off(e,t){let n=super.off(e,t);return e===`data`&&(this[Ne]=this.listeners(`data`).length,this[Ne]===0&&!this[E]&&!this[x].length&&(this[y]=!1)),n}removeAllListeners(e){let t=super.removeAllListeners(e);return(e===`data`||e===void 0)&&(this[Ne]=0,!this[E]&&!this[x].length&&(this[y]=!1)),t}get emittedEnd(){return this[_]}[g](){!this[he]&&!this[_]&&!this[w]&&this[b].length===0&&this[h]&&(this[he]=!0,this.emit(`end`),this.emit(`prefinish`),this.emit(`finish`),this[_e]&&this.emit(`close`),this[he]=!1)}emit(e,...t){let n=t[0];if(e!==`error`&&e!==`close`&&e!==w&&this[w])return!1;if(e===`data`)return!this[C]&&!n?!1:this[T]?(Pe(()=>this[De](n)),!0):this[De](n);if(e===`end`)return this[Oe]();if(e===`close`){if(this[_e]=!0,!this[_]&&!this[w])return!1;let e=super.emit(`close`);return this.removeAllListeners(`close`),e}else if(e===`error`){this[ge]=n,super.emit(Ee,n);let e=!this[Me]||this.listeners(`error`).length?super.emit(`error`,n):!1;return this[g](),e}else if(e===`resume`){let e=super.emit(`resume`);return this[g](),e}else if(e===`finish`||e===`prefinish`){let t=super.emit(e);return this.removeAllListeners(e),t}let r=super.emit(e,...t);return this[g](),r}[De](e){for(let t of this[x])t.dest.write(e)===!1&&this.pause();let t=this[E]?!1:super.emit(`data`,e);return this[g](),t}[Oe](){return this[_]?!1:(this[_]=!0,this.readable=!1,this[T]?(Pe(()=>this[ke]()),!0):this[ke]())}[ke](){if(this[xe]){let e=this[xe].end();if(e){for(let t of this[x])t.dest.write(e);this[E]||super.emit(`data`,e)}}for(let e of this[x])e.end();let e=super.emit(`end`);return this.removeAllListeners(`end`),e}async collect(){let e=Object.assign([],{dataLength:0});this[C]||(e.dataLength=0);let t=this.promise();return this.on(`data`,t=>{e.push(t),this[C]||(e.dataLength+=t.length)}),await t,e}async concat(){if(this[C])throw Error(`cannot concat in objectMode`);let e=await this.collect();return this[v]?e.join(``):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(w,()=>t(Error(`stream destroyed`))),this.on(`error`,e=>t(e)),this.on(`end`,()=>e())})}[Symbol.asyncIterator](){this[E]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[h])return t();let r,i,a=e=>{this.off(`data`,o),this.off(`end`,s),this.off(w,c),t(),i(e)},o=e=>{this.off(`error`,a),this.off(`end`,s),this.off(w,c),this.pause(),r({value:e,done:!!this[h]})},s=()=>{this.off(`error`,a),this.off(`data`,o),this.off(w,c),t(),r({done:!0,value:void 0})},c=()=>a(Error(`stream destroyed`));return new Promise((e,t)=>{i=t,r=e,this.once(w,c),this.once(`error`,a),this.once(`end`,s),this.once(`data`,o)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[E]=!1;let e=!1,t=()=>(this.pause(),this.off(Ee,t),this.off(w,t),this.off(`end`,t),e=!0,{done:!0,value:void 0});return this.once(`end`,t),this.once(Ee,t),this.once(w,t),{next:()=>{if(e)return t();let n=this.read();return n===null?t():{done:!1,value:n}},throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[w])return e?this.emit(`error`,e):this.emit(w),this;this[w]=!0,this[E]=!0,this[b].length=0,this[S]=0;let t=this;return typeof t.close==`function`&&!this[_e]&&t.close(),e?this.emit(`error`,e):this.emit(w),this}static get isStream(){return fe}},We=d.writev,D=Symbol(`_autoClose`),O=Symbol(`_close`),Ge=Symbol(`_ended`),k=Symbol(`_fd`),Ke=Symbol(`_finished`),A=Symbol(`_flags`),qe=Symbol(`_flush`),Je=Symbol(`_handleChunk`),Ye=Symbol(`_makeBuf`),Xe=Symbol(`_mode`),Ze=Symbol(`_needDrain`),Qe=Symbol(`_onerror`),$e=Symbol(`_onopen`),et=Symbol(`_onread`),tt=Symbol(`_onwrite`),j=Symbol(`_open`),M=Symbol(`_path`),nt=Symbol(`_pos`),N=Symbol(`_queue`),rt=Symbol(`_read`),it=Symbol(`_readSize`),P=Symbol(`_reading`),at=Symbol(`_remain`),ot=Symbol(`_size`),st=Symbol(`_write`),ct=Symbol(`_writing`),lt=Symbol(`_defaultFlag`),ut=Symbol(`_errored`),dt=class extends Ue{[ut]=!1;[k];[M];[it];[P]=!1;[ot];[at];[D];constructor(e,t){if(t||={},super(t),this.readable=!0,this.writable=!1,typeof e!=`string`)throw TypeError(`path must be a string`);this[ut]=!1,this[k]=typeof t.fd==`number`?t.fd:void 0,this[M]=e,this[it]=t.readSize||16*1024*1024,this[P]=!1,this[ot]=typeof t.size==`number`?t.size:1/0,this[at]=this[ot],this[D]=typeof t.autoClose==`boolean`?t.autoClose:!0,typeof this[k]==`number`?this[rt]():this[j]()}get fd(){return this[k]}get path(){return this[M]}write(){throw TypeError(`this is a readable stream`)}end(){throw TypeError(`this is a readable stream`)}[j](){d.open(this[M],`r`,(e,t)=>this[$e](e,t))}[$e](e,t){e?this[Qe](e):(this[k]=t,this.emit(`open`,t),this[rt]())}[Ye](){return Buffer.allocUnsafe(Math.min(this[it],this[at]))}[rt](){if(!this[P]){this[P]=!0;let e=this[Ye]();if(e.length===0)return process.nextTick(()=>this[et](null,0,e));d.read(this[k],e,0,e.length,null,(e,t,n)=>this[et](e,t,n))}}[et](e,t,n){this[P]=!1,e?this[Qe](e):this[Je](t,n)&&this[rt]()}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.close(e,e=>e?this.emit(`error`,e):this.emit(`close`))}}[Qe](e){this[P]=!0,this[O](),this.emit(`error`,e)}[Je](e,t){let n=!1;return this[at]-=e,e>0&&(n=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[at]<=0)&&(n=!1,this[O](),super.end()),n}emit(e,...t){switch(e){case`prefinish`:case`finish`:return!1;case`drain`:return typeof this[k]==`number`&&this[rt](),!1;case`error`:return this[ut]?!1:(this[ut]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},ft=class extends dt{[j](){let e=!0;try{this[$e](null,d.openSync(this[M],`r`)),e=!1}finally{e&&this[O]()}}[rt](){let e=!0;try{if(!this[P]){this[P]=!0;do{let e=this[Ye](),t=e.length===0?0:d.readSync(this[k],e,0,e.length,null);if(!this[Je](t,e))break}while(!0);this[P]=!1}e=!1}finally{e&&this[O]()}}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.closeSync(e),this.emit(`close`)}}},pt=class extends l{readable=!1;writable=!0;[ut]=!1;[ct]=!1;[Ge]=!1;[N]=[];[Ze]=!1;[M];[Xe];[D];[k];[lt];[A];[Ke]=!1;[nt];constructor(e,t){t||={},super(t),this[M]=e,this[k]=typeof t.fd==`number`?t.fd:void 0,this[Xe]=t.mode===void 0?438:t.mode,this[nt]=typeof t.start==`number`?t.start:void 0,this[D]=typeof t.autoClose==`boolean`?t.autoClose:!0;let n=this[nt]===void 0?`w`:`r+`;this[lt]=t.flags===void 0,this[A]=t.flags===void 0?n:t.flags,this[k]===void 0&&this[j]()}emit(e,...t){if(e===`error`){if(this[ut])return!1;this[ut]=!0}return super.emit(e,...t)}get fd(){return this[k]}get path(){return this[M]}[Qe](e){this[O](),this[ct]=!0,this.emit(`error`,e)}[j](){d.open(this[M],this[A],this[Xe],(e,t)=>this[$e](e,t))}[$e](e,t){this[lt]&&this[A]===`r+`&&e&&e.code===`ENOENT`?(this[A]=`w`,this[j]()):e?this[Qe](e):(this[k]=t,this.emit(`open`,t),this[ct]||this[qe]())}end(e,t){return e&&this.write(e,t),this[Ge]=!0,!this[ct]&&!this[N].length&&typeof this[k]==`number`&&this[tt](null,0),this}write(e,t){return typeof e==`string`&&(e=Buffer.from(e,t)),this[Ge]?(this.emit(`error`,Error(`write() after end()`)),!1):this[k]===void 0||this[ct]||this[N].length?(this[N].push(e),this[Ze]=!0,!1):(this[ct]=!0,this[st](e),!0)}[st](e){d.write(this[k],e,0,e.length,this[nt],(e,t)=>this[tt](e,t))}[tt](e,t){e?this[Qe](e):(this[nt]!==void 0&&typeof t==`number`&&(this[nt]+=t),this[N].length?this[qe]():(this[ct]=!1,this[Ge]&&!this[Ke]?(this[Ke]=!0,this[O](),this.emit(`finish`)):this[Ze]&&(this[Ze]=!1,this.emit(`drain`))))}[qe](){if(this[N].length===0)this[Ge]&&this[tt](null,0);else if(this[N].length===1)this[st](this[N].pop());else{let e=this[N];this[N]=[],We(this[k],e,this[nt],(e,t)=>this[tt](e,t))}}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.close(e,e=>e?this.emit(`error`,e):this.emit(`close`))}}},mt=class extends pt{[j](){let e;if(this[lt]&&this[A]===`r+`)try{e=d.openSync(this[M],this[A],this[Xe])}catch(e){if(e?.code===`ENOENT`)return this[A]=`w`,this[j]();throw e}else e=d.openSync(this[M],this[A],this[Xe]);this[$e](null,e)}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.closeSync(e),this.emit(`close`)}}[st](e){let t=!0;try{this[tt](null,d.writeSync(this[k],e,0,e.length,this[nt])),t=!1}finally{if(t)try{this[O]()}catch{}}}},ht=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`]]),gt=e=>!!e.sync&&!!e.file,_t=e=>!e.sync&&!!e.file,vt=e=>!!e.sync&&!e.file,yt=e=>!e.sync&&!e.file,bt=e=>!!e.file,xt=e=>ht.get(e)||e,St=(e={})=>{if(!e)return{};let t={};for(let[n,r]of Object.entries(e)){let e=xt(n);t[e]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},Ct=(e,t,n,r,i)=>Object.assign((a=[],o,s)=>{Array.isArray(a)&&(o=a,a={}),typeof o==`function`&&(s=o,o=void 0),o=o?Array.from(o):[];let c=St(a);if(i?.(c,o),gt(c)){if(typeof s==`function`)throw TypeError(`callback not supported for sync tar functions`);return e(c,o)}else if(_t(c)){let e=t(c,o);return s?e.then(()=>s(),s):e}else if(vt(c)){if(typeof s==`function`)throw TypeError(`callback not supported for sync tar functions`);return n(c,o)}else if(yt(c)){if(typeof s==`function`)throw TypeError(`callback only supported with file option`);return r(c,o)}throw Error(`impossible options??`)},{syncFile:e,asyncFile:t,syncNoFile:n,asyncNoFile:r,validate:i}),wt=ae.constants||{ZLIB_VERNUM:4736},F=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},wt)),Tt=re.concat,Et=Object.getOwnPropertyDescriptor(re,`concat`),Dt=e=>e,Ot=Et?.writable===!0||Et?.set!==void 0?e=>{re.concat=e?Dt:Tt}:e=>{},kt=Symbol(`_superWrite`),At=class extends Error{code;errno;constructor(e,t){super(`zlib: `+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||=`ZLIB_ERROR`,this.message=`zlib: `+e.message,Error.captureStackTrace(this,t??this.constructor)}get name(){return`ZlibError`}},jt=Symbol(`flushFlag`),Mt=class extends Ue{#e=!1;#t=!1;#n;#r;#i;#a;#o;get sawError(){return this.#e}get handle(){return this.#a}get flushFlag(){return this.#n}constructor(e,t){if(!e||typeof e!=`object`)throw TypeError(`invalid options for ZlibBase constructor`);if(super(e),this.#n=e.flush??0,this.#r=e.finishFlush??0,this.#i=e.fullFlushFlag??0,typeof ie[t]!=`function`)throw TypeError(`Compression method not supported: `+t);try{this.#a=new ie[t](e)}catch(e){throw new At(e,this.constructor)}this.#o=e=>{this.#e||(this.#e=!0,this.close(),this.emit(`error`,e))},this.#a?.on(`error`,e=>this.#o(new At(e))),this.once(`end`,()=>this.close)}close(){this.#a&&(this.#a.close(),this.#a=void 0,this.emit(`close`))}reset(){if(!this.#e)return ne(this.#a,`zlib binding closed`),this.#a.reset?.()}flush(e){this.ended||(typeof e!=`number`&&(e=this.#i),this.write(Object.assign(re.alloc(0),{[jt]:e})))}end(e,t,n){return typeof e==`function`&&(n=e,t=void 0,e=void 0),typeof t==`function`&&(n=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#r),this.#t=!0,super.end(n)}get ended(){return this.#t}[kt](e){return super.write(e)}write(e,t,n){if(typeof t==`function`&&(n=t,t=`utf8`),typeof e==`string`&&(e=re.from(e,t)),this.#e)return;ne(this.#a,`zlib binding closed`);let r=this.#a._handle,i=r.close;r.close=()=>{};let a=this.#a.close;this.#a.close=()=>{},Ot(!0);let o;try{let t=typeof e[jt]==`number`?e[jt]:this.#n;o=this.#a._processChunk(e,t),Ot(!1)}catch(e){Ot(!1),this.#o(new At(e,this.write))}finally{this.#a&&(this.#a._handle=r,r.close=i,this.#a.close=a,this.#a.removeAllListeners(`error`))}this.#a&&this.#a.on(`error`,e=>this.#o(new At(e,this.write)));let s;if(o)if(Array.isArray(o)&&o.length>0){let e=o[0];s=this[kt](re.from(e));for(let e=1;e<o.length;e++)s=this[kt](o[e])}else s=this[kt](re.from(o));return n&&n(),s}},Nt=class extends Mt{#e;#t;constructor(e,t){e||={},e.flush=e.flush||F.Z_NO_FLUSH,e.finishFlush=e.finishFlush||F.Z_FINISH,e.fullFlushFlag=F.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#t=e.strategy}params(e,t){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.#e!==e||this.#t!==t){this.flush(F.Z_SYNC_FLUSH),ne(this.handle,`zlib binding closed`);let n=this.handle.flush;this.handle.flush=(e,t)=>{typeof e==`function`&&(t=e,e=this.flushFlag),this.flush(e),t?.()};try{this.handle.params(e,t)}finally{this.handle.flush=n}this.handle&&(this.#e=e,this.#t=t)}}}},Pt=class extends Nt{#e;constructor(e){super(e,`Gzip`),this.#e=e&&!!e.portable}[kt](e){return this.#e?(this.#e=!1,e[9]=255,super[kt](e)):super[kt](e)}},Ft=class extends Nt{constructor(e){super(e,`Unzip`)}},It=class extends Mt{constructor(e,t){e||={},e.flush=e.flush||F.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||F.BROTLI_OPERATION_FINISH,e.fullFlushFlag=F.BROTLI_OPERATION_FLUSH,super(e,t)}},Lt=class extends It{constructor(e){super(e,`BrotliCompress`)}},Rt=class extends It{constructor(e){super(e,`BrotliDecompress`)}},zt=class extends Mt{constructor(e,t){e||={},e.flush=e.flush||F.ZSTD_e_continue,e.finishFlush=e.finishFlush||F.ZSTD_e_end,e.fullFlushFlag=F.ZSTD_e_flush,super(e,t)}},Bt=class extends zt{constructor(e){super(e,`ZstdCompress`)}},Vt=class extends zt{constructor(e){super(e,`ZstdDecompress`)}},Ht=(e,t)=>{if(Number.isSafeInteger(e))e<0?Wt(e,t):Ut(e,t);else throw Error(`cannot encode number outside of javascript safe integer range`);return t},Ut=(e,t)=>{t[0]=128;for(var n=t.length;n>1;n--)t[n-1]=e&255,e=Math.floor(e/256)},Wt=(e,t)=>{t[0]=255;var n=!1;e*=-1;for(var r=t.length;r>1;r--){var i=e&255;e=Math.floor(e/256),n?t[r-1]=Jt(i):i===0?t[r-1]=0:(n=!0,t[r-1]=Yt(i))}},Gt=e=>{let t=e[0],n=t===128?qt(e.subarray(1,e.length)):t===255?Kt(e):null;if(n===null)throw Error(`invalid base256 encoding`);if(!Number.isSafeInteger(n))throw Error(`parsed number outside of javascript safe integer range`);return n},Kt=e=>{for(var t=e.length,n=0,r=!1,i=t-1;i>-1;i--){var a=Number(e[i]),o;r?o=Jt(a):a===0?o=a:(r=!0,o=Yt(a)),o!==0&&(n-=o*256**(t-i-1))}return n},qt=e=>{for(var t=e.length,n=0,r=t-1;r>-1;r--){var i=Number(e[r]);i!==0&&(n+=i*256**(t-r-1))}return n},Jt=e=>(255^e)&255,Yt=e=>(255^e)+1&255,Xt={};ue(Xt,{code:()=>tn,isCode:()=>Zt,isName:()=>Qt,name:()=>en,normalFsTypes:()=>$t});var Zt=e=>en.has(e),Qt=e=>tn.has(e),$t=new Set([`0`,``,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`D`]),en=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`]]),tn=new Map(Array.from(en).map(e=>[e[1],e[0]])),I=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e=`Unsupported`;linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,t=0,n,r){Buffer.isBuffer(e)?this.decode(e,t||0,n,r):e&&this.#t(e)}decode(e,t,n,r){if(t||=0,!e||!(e.length>=t+512))throw Error(`need 512 bytes for header`);let i=rn(e,t+156,1),a=$t.has(i),o=a?n:void 0,s=a?r:void 0;if(this.path=o?.path??rn(e,t,100),this.mode=o?.mode??s?.mode??L(e,t+100,8),this.uid=o?.uid??s?.uid??L(e,t+108,8),this.gid=o?.gid??s?.gid??L(e,t+116,8),this.size=o?.size??s?.size??L(e,t+124,12),this.mtime=o?.mtime??s?.mtime??an(e,t+136,12),this.cksum=L(e,t+148,12),s&&this.#t(s,!0),o&&this.#t(o),Zt(i)&&(this.#e=i||`0`),this.#e===`0`&&this.path.slice(-1)===`/`&&(this.#e=`5`),this.#e===`5`&&(this.size=0),this.linkpath=rn(e,t+157,100),e.subarray(t+257,t+265).toString()===`ustar\x0000`)if(this.uname=o?.uname??s?.uname??rn(e,t+265,32),this.gname=o?.gname??s?.gname??rn(e,t+297,32),this.devmaj=o?.devmaj??s?.devmaj??L(e,t+329,8)??0,this.devmin=o?.devmin??s?.devmin??L(e,t+337,8)??0,e[t+475]!==0){let n=rn(e,t+345,155);this.path=n+`/`+this.path}else{let i=rn(e,t+345,130);i&&(this.path=i+`/`+this.path),this.atime=n?.atime??r?.atime??an(e,t+476,12),this.ctime=n?.ctime??r?.ctime??an(e,t+488,12)}let c=256;for(let n=t;n<t+148;n++)c+=e[n];for(let n=t+156;n<t+512;n++)c+=e[n];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#t(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([e,n])=>!(n==null||e===`path`&&t||e===`linkpath`&&t||e===`global`))))}encode(e,t=0){if(e||=this.block=Buffer.alloc(512),this.#e===`Unsupported`&&(this.#e=`0`),!(e.length>=t+512))throw Error(`need 512 bytes for header`);let n=this.ctime||this.atime?130:155,r=nn(this.path||``,n),i=r[0],a=r[1];this.needPax=!!r[2],this.needPax=hn(e,t,100,i)||this.needPax,this.needPax=R(e,t+100,8,this.mode)||this.needPax,this.needPax=R(e,t+108,8,this.uid)||this.needPax,this.needPax=R(e,t+116,8,this.gid)||this.needPax,this.needPax=R(e,t+124,12,this.size)||this.needPax,this.needPax=pn(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=hn(e,t+157,100,this.linkpath)||this.needPax,e.write(`ustar\x0000`,t+257,8),this.needPax=hn(e,t+265,32,this.uname)||this.needPax,this.needPax=hn(e,t+297,32,this.gname)||this.needPax,this.needPax=R(e,t+329,8,this.devmaj)||this.needPax,this.needPax=R(e,t+337,8,this.devmin)||this.needPax,this.needPax=hn(e,t+345,n,a)||this.needPax,e[t+475]===0?(this.needPax=hn(e,t+345,130,a)||this.needPax,this.needPax=pn(e,t+476,12,this.atime)||this.needPax,this.needPax=pn(e,t+488,12,this.ctime)||this.needPax):this.needPax=hn(e,t+345,155,a)||this.needPax;let o=256;for(let n=t;n<t+148;n++)o+=e[n];for(let n=t+156;n<t+512;n++)o+=e[n];return this.cksum=o,R(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e===`Unsupported`?this.#e:en.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(tn.get(e));if(Zt(t)||t===`Unsupported`)this.#e=t;else if(Zt(e))this.#e=e;else throw TypeError(`invalid entry type: `+e)}},nn=(e,t)=>{let n=e,r=``,i,o=a.parse(e).root||`.`;if(Buffer.byteLength(n)<100)i=[n,r,!1];else{r=a.dirname(n),n=a.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(r)<=t?i=[n,r,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(r)<=t?i=[n.slice(0,99),r,!0]:(n=a.join(a.basename(r),n),r=a.dirname(r));while(r!==o&&i===void 0);i||=[e.slice(0,99),``,!0]}return i},rn=(e,t,n)=>e.subarray(t,t+n).toString(`utf8`).replace(/\0.*/,``),an=(e,t,n)=>on(L(e,t,n)),on=e=>e===void 0?void 0:new Date(e*1e3),L=(e,t,n)=>Number(e[t])&128?Gt(e.subarray(t,t+n)):cn(e,t,n),sn=e=>isNaN(e)?void 0:e,cn=(e,t,n)=>sn(parseInt(e.subarray(t,t+n).toString(`utf8`).replace(/\0.*$/,``).trim(),8)),ln={12:8589934591,8:2097151},R=(e,t,n,r)=>r===void 0?!1:r>ln[n]||r<0?(Ht(r,e.subarray(t,t+n)),!0):(un(e,t,n,r),!1),un=(e,t,n,r)=>e.write(dn(r,n),t,n,`ascii`),dn=(e,t)=>fn(Math.floor(e).toString(8),t),fn=(e,t)=>(e.length===t-1?e:Array(t-e.length-1).join(`0`)+e+` `)+`\0`,pn=(e,t,n,r)=>r===void 0?!1:R(e,t,n,r.getTime()/1e3),mn=Array(156).join(`\0`),hn=(e,t,n,r)=>r===void 0?!1:(e.write(r+mn,t,n,`utf8`),r.length!==Buffer.byteLength(r)||r.length>n),gn=class e{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,t=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=t,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e===``)return Buffer.allocUnsafe(0);let t=Buffer.byteLength(e),n=512*Math.ceil(1+t/512),i=Buffer.allocUnsafe(n);for(let e=0;e<512;e++)i[e]=0;new I({path:(`PaxHeader/`+r(this.path??``)).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:t,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(i),i.write(e,512,t,`utf8`);for(let e=t+512;e<i.length;e++)i[e]=0;return i}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(e){if(this[e]===void 0)return``;let t=this[e],n=t instanceof Date?t.getTime()/1e3:t,r=` `+(e===`dev`||e===`ino`||e===`nlink`?`SCHILY.`:``)+e+`=`+n+`
|
|
3
|
+
`,i=Buffer.byteLength(r),a=Math.floor(Math.log(i)/Math.log(10))+1;return i+a>=10**a&&(a+=1),a+i+r}static parse(t,n,r=!1){return new e(_n(vn(t),n),r)}},_n=(e,t)=>t?Object.assign({},t,e):e,vn=e=>e.replace(/\n$/,``).split(`
|
|
4
|
+
`).reduce(yn,Object.create(null)),yn=(e,t)=>{let n=parseInt(t,10);if(n!==Buffer.byteLength(t)+1)return e;t=t.slice((n+` `).length);let r=t.split(`=`),i=r.shift();if(!i)return e;let a=i.replace(/^SCHILY\.(dev|ino|nlink)/,`$1`),o=r.join(`=`);return e[a]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(a)?new Date(Number(o)*1e3):/^[0-9]+$/.test(o)?+o:o,e},z=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`?e=>e&&e.replaceAll(/\\/g,`/`):e=>e,bn=class extends Ue{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(e,t,n){switch(super({}),this.pause(),this.extended=t,this.globalExtended=n,this.header=e,this.remain=e.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=e.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(!e.path)throw Error(`no path provided for tar.ReadEntry`);this.path=z(e.path),this.mode=e.mode,this.mode&&(this.mode&=4095),this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=this.remain,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?z(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),n&&this.#e(n,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw Error(`writing more to entry than is appropriate`);let n=this.remain,r=this.blockRemain;return this.remain=Math.max(0,n-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:n>=t?super.write(e):super.write(e.subarray(0,n))}#e(e,t=!1){e.path&&=z(e.path),e.linkpath&&=z(e.linkpath),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([e,n])=>!(n==null||e===`path`&&t))))}},xn=(e,t,n,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=n instanceof Error&&n.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(n instanceof Error&&(r=Object.assign(n,r),n=n.message),e.emit(`warn`,t,n,r)):n instanceof Error?e.emit(`error`,Object.assign(n,r)):e.emit(`error`,Object.assign(Error(`${t}: ${n}`),r))},Sn=1024*1024,Cn=Buffer.from([31,139]),wn=Buffer.from([40,181,47,253]),Tn=Math.max(Cn.length,wn.length),B=Symbol(`state`),En=Symbol(`writeEntry`),V=Symbol(`readEntry`),Dn=Symbol(`nextEntry`),On=Symbol(`processEntry`),H=Symbol(`extendedHeader`),kn=Symbol(`globalExtendedHeader`),U=Symbol(`meta`),An=Symbol(`emitMeta`),W=Symbol(`buffer`),G=Symbol(`queue`),K=Symbol(`ended`),jn=Symbol(`emittedEnd`),Mn=Symbol(`emit`),q=Symbol(`unzip`),Nn=Symbol(`consumeChunk`),Pn=Symbol(`consumeChunkSub`),Fn=Symbol(`consumeBody`),In=Symbol(`consumeMeta`),Ln=Symbol(`consumeHeader`),Rn=Symbol(`consuming`),zn=Symbol(`bufferConcat`),Bn=Symbol(`maybeEnd`),Vn=Symbol(`writing`),J=Symbol(`aborted`),Hn=Symbol(`onDone`),Un=Symbol(`sawValidEntry`),Wn=Symbol(`sawNullBlock`),Gn=Symbol(`sawEOF`),Kn=Symbol(`closeStream`),qn=()=>!0,Jn=class extends u{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[G]=[];[W];[V];[En];[B]=`begin`;[U]=``;[H];[kn];[K]=!1;[q];[J]=!1;[Un];[Wn]=!1;[Gn]=!1;[Vn]=!1;[Rn]=!1;[jn]=!1;constructor(e={}){super(),this.file=e.file||``,this.on(Hn,()=>{(this[B]===`begin`||this[Un]===!1)&&this.warn(`TAR_BAD_ARCHIVE`,`Unrecognized archive format`)}),e.ondone?this.on(Hn,e.ondone):this.on(Hn,()=>{this.emit(`prefinish`),this.emit(`finish`),this.emit(`end`)}),this.strict=!!e.strict,this.maxMetaEntrySize=e.maxMetaEntrySize||Sn,this.filter=typeof e.filter==`function`?e.filter:qn;let t=e.file&&(e.file.endsWith(`.tar.br`)||e.file.endsWith(`.tbr`));this.brotli=!(e.gzip||e.zstd)&&e.brotli!==void 0?e.brotli:t?void 0:!1;let n=e.file&&(e.file.endsWith(`.tar.zst`)||e.file.endsWith(`.tzst`));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:n?!0:void 0,this.on(`end`,()=>this[Kn]()),typeof e.onwarn==`function`&&this.on(`warn`,e.onwarn),typeof e.onReadEntry==`function`&&this.on(`entry`,e.onReadEntry)}warn(e,t,n={}){xn(this,e,t,n)}[Ln](e,t){this[Un]===void 0&&(this[Un]=!1);let n;try{n=new I(e,t,this[H],this[kn])}catch(e){return this.warn(`TAR_ENTRY_INVALID`,e)}if(n.nullBlock)this[Wn]?(this[Gn]=!0,this[B]===`begin`&&(this[B]=`header`),this[Mn](`eof`)):(this[Wn]=!0,this[Mn](`nullBlock`));else if(this[Wn]=!1,!n.cksumValid)this.warn(`TAR_ENTRY_INVALID`,`checksum failure`,{header:n});else if(!n.path)this.warn(`TAR_ENTRY_INVALID`,`path is required`,{header:n});else{let e=n.type;if(/^(Symbolic)?Link$/.test(e)&&!n.linkpath)this.warn(`TAR_ENTRY_INVALID`,`linkpath required`,{header:n});else if(!/^(Symbolic)?Link$/.test(e)&&!/^(Global)?ExtendedHeader$/.test(e)&&n.linkpath)this.warn(`TAR_ENTRY_INVALID`,`linkpath forbidden`,{header:n});else{let e=this[En]=new bn(n,this[H],this[kn]);this[Un]||(e.remain?e.on(`end`,()=>{e.invalid||(this[Un]=!0)}):this[Un]=!0),e.meta?e.size>this.maxMetaEntrySize?(e.ignore=!0,this[Mn](`ignoredEntry`,e),this[B]=`ignore`,e.resume()):e.size>0&&(this[U]=``,e.on(`data`,e=>this[U]+=e),this[B]=`meta`):(this[H]=void 0,e.ignore=e.ignore||!this.filter(e.path,e),e.ignore?(this[Mn](`ignoredEntry`,e),this[B]=e.remain?`ignore`:`header`,e.resume()):(e.remain?this[B]=`body`:(this[B]=`header`,e.end()),this[V]?this[G].push(e):(this[G].push(e),this[Dn]())))}}}[Kn](){queueMicrotask(()=>this.emit(`close`))}[On](e){let t=!0;if(!e)this[V]=void 0,t=!1;else if(Array.isArray(e)){let[t,...n]=e;this.emit(t,...n)}else this[V]=e,this.emit(`entry`,e),e.emittedEnd||(e.on(`end`,()=>this[Dn]()),t=!1);return t}[Dn](){do;while(this[On](this[G].shift()));if(this[G].length===0){let e=this[V];!e||e.flowing||e.size===e.remain?this[Vn]||this.emit(`drain`):e.once(`drain`,()=>this.emit(`drain`))}}[Fn](e,t){let n=this[En];if(!n)throw Error(`attempt to consume body without entry??`);let r=n.blockRemain??0,i=r>=e.length&&t===0?e:e.subarray(t,t+r);return n.write(i),n.blockRemain||(this[B]=`header`,this[En]=void 0,n.end()),i.length}[In](e,t){let n=this[En],r=this[Fn](e,t);return!this[En]&&n&&this[An](n),r}[Mn](e,t,n){this[G].length===0&&!this[V]?this.emit(e,t,n):this[G].push([e,t,n])}[An](e){switch(this[Mn](`meta`,this[U]),e.type){case`ExtendedHeader`:case`OldExtendedHeader`:this[H]=gn.parse(this[U],this[H],!1);break;case`GlobalExtendedHeader`:this[kn]=gn.parse(this[U],this[kn],!0);break;case`NextFileHasLongPath`:case`OldGnuLongPath`:{let e=this[H]??Object.create(null);this[H]=e,e.path=this[U].replace(/\0.*/,``);break}case`NextFileHasLongLinkpath`:{let e=this[H]||Object.create(null);this[H]=e,e.linkpath=this[U].replace(/\0.*/,``);break}default:throw Error(`unknown meta: `+e.type)}}abort(e){this[J]=!0,this.emit(`abort`,e),this.warn(`TAR_ABORT`,e,{recoverable:!1})}write(e,t,n){if(typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,typeof t==`string`?t:`utf8`)),this[J])return n?.(),!1;if((this[q]===void 0||this.brotli===void 0&&this[q]===!1)&&e){if(this[W]&&(e=Buffer.concat([this[W],e]),this[W]=void 0),e.length<Tn)return this[W]=e,n?.(),!0;for(let t=0;this[q]===void 0&&t<Cn.length;t++)e[t]!==Cn[t]&&(this[q]=!1);let t=!1;if(this[q]===!1&&this.zstd!==!1){t=!0;for(let n=0;n<wn.length;n++)if(e[n]!==wn[n]){t=!1;break}}let r=this.brotli===void 0&&!t;if(this[q]===!1&&r)if(e.length<512)if(this[K])this.brotli=!0;else return this[W]=e,n?.(),!0;else try{new I(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[q]===void 0||this[q]===!1&&(this.brotli||t)){let r=this[K];this[K]=!1,this[q]=this[q]===void 0?new Ft({}):t?new Vt({}):new Rt({}),this[q].on(`data`,e=>this[Nn](e)),this[q].on(`error`,e=>this.abort(e)),this[q].on(`end`,()=>{this[K]=!0,this[Nn]()}),this[Vn]=!0;let i=!!this[q][r?`end`:`write`](e);return this[Vn]=!1,n?.(),i}}this[Vn]=!0,this[q]?this[q].write(e):this[Nn](e),this[Vn]=!1;let r=this[G].length>0?!1:this[V]?this[V].flowing:!0;return!r&&this[G].length===0&&this[V]?.once(`drain`,()=>this.emit(`drain`)),n?.(),r}[zn](e){e&&!this[J]&&(this[W]=this[W]?Buffer.concat([this[W],e]):e)}[Bn](){if(this[K]&&!this[jn]&&!this[J]&&!this[Rn]){this[jn]=!0;let e=this[En];if(e&&e.blockRemain){let t=this[W]?this[W].length:0;this.warn(`TAR_BAD_ARCHIVE`,`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[W]&&e.write(this[W]),e.end()}this[Mn](Hn)}}[Nn](e){if(this[Rn]&&e)this[zn](e);else if(!e&&!this[W])this[Bn]();else if(e){if(this[Rn]=!0,this[W]){this[zn](e);let t=this[W];this[W]=void 0,this[Pn](t)}else this[Pn](e);for(;this[W]&&this[W]?.length>=512&&!this[J]&&!this[Gn];){let e=this[W];this[W]=void 0,this[Pn](e)}this[Rn]=!1}(!this[W]||this[K])&&this[Bn]()}[Pn](e){let t=0,n=e.length;for(;t+512<=n&&!this[J]&&!this[Gn];)switch(this[B]){case`begin`:case`header`:this[Ln](e,t),t+=512;break;case`ignore`:case`body`:t+=this[Fn](e,t);break;case`meta`:t+=this[In](e,t);break;default:throw Error(`invalid state: `+this[B])}t<n&&(this[W]=this[W]?Buffer.concat([e.subarray(t),this[W]]):e.subarray(t))}end(e,t,n){return typeof e==`function`&&(n=e,t=void 0,e=void 0),typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,t)),n&&this.once(`finish`,n),this[J]||(this[q]?(e&&this[q].write(e),this[q].end()):(this[K]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e||=Buffer.alloc(0)),e&&this.write(e),this[Bn]())),this}},Yn=e=>{let t=e.length-1,n=-1;for(;t>-1&&e.charAt(t)===`/`;)n=t,t--;return n===-1?e:e.slice(0,n)},Xn=e=>{let t=e.onReadEntry;e.onReadEntry=t?e=>{t(e),e.resume()}:e=>e.resume()},Zn=(e,t)=>{let n=new Map(t.map(e=>[Yn(e),!0])),r=e.filter,i=(e,t=``)=>{let r=t||te(e).root||`.`,a;if(e===r)a=!1;else{let t=n.get(e);a=t===void 0?i(m(e),r):t}return n.set(e,a),a};e.filter=r?(e,t)=>r(e,t)&&i(Yn(e)):e=>i(Yn(e))},Qn=Ct(e=>{let n=new Jn(e),r=e.file,i;try{i=t.openSync(r,`r`);let a=t.fstatSync(i),o=e.maxReadSize||16*1024*1024;if(a.size<o){let e=Buffer.allocUnsafe(a.size),r=t.readSync(i,e,0,a.size,0);n.end(r===e.byteLength?e:e.subarray(0,r))}else{let e=0,r=Buffer.allocUnsafe(o);for(;e<a.size;){let a=t.readSync(i,r,0,o,e);if(a===0)break;e+=a,n.write(r.subarray(0,a))}n.end()}}finally{if(typeof i==`number`)try{t.closeSync(i)}catch{}}},(e,n)=>{let r=new Jn(e),i=e.maxReadSize||16*1024*1024,a=e.file;return new Promise((e,n)=>{r.on(`error`,n),r.on(`end`,e),t.stat(a,(e,t)=>{if(e)n(e);else{let e=new dt(a,{readSize:i,size:t.size});e.on(`error`,n),e.pipe(r)}})})},e=>new Jn(e),e=>new Jn(e),(e,t)=>{t?.length&&Zn(e,t),e.noResume||Xn(e)}),$n=(e,t,n)=>(e&=4095,n&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),{isAbsolute:er,parse:tr}=o,nr=e=>{let t=``,n=tr(e);for(;er(e)||n.root;){let r=e.charAt(0)===`/`&&e.slice(0,4)!==`//?/`?`/`:n.root;e=e.slice(r.length),t+=r,n=tr(e)}return[t,e]},rr=[`|`,`<`,`>`,`?`,`:`],ir=rr.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),ar=new Map(rr.map((e,t)=>[e,ir[t]])),or=new Map(ir.map((e,t)=>[e,rr[t]])),sr=e=>rr.reduce((e,t)=>e.split(t).join(ar.get(t)),e),cr=e=>ir.reduce((e,t)=>e.split(t).join(or.get(t)),e),lr=(e,t)=>t?(e=z(e).replace(/^\.(\/|$)/,``),Yn(t)+`/`+e):z(e),ur=16*1024*1024,dr=Symbol(`process`),fr=Symbol(`file`),pr=Symbol(`directory`),mr=Symbol(`symlink`),hr=Symbol(`hardlink`),gr=Symbol(`header`),_r=Symbol(`read`),vr=Symbol(`lstat`),yr=Symbol(`onlstat`),br=Symbol(`onread`),xr=Symbol(`onreadlink`),Sr=Symbol(`openfile`),Cr=Symbol(`onopenfile`),wr=Symbol(`close`),Tr=Symbol(`mode`),Er=Symbol(`awaitDrain`),Dr=Symbol(`ondrain`),Y=Symbol(`prefix`),Or=class extends Ue{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;#e=!1;constructor(e,t={}){let n=St(t);super(),this.path=z(e),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||ur,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=z(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?z(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn==`function`&&this.on(`warn`,n.onwarn);let r=!1;if(!this.preservePaths){let[e,t]=nr(this.path);e&&typeof t==`string`&&(this.path=t,r=e)}this.win32=!!n.win32||process.platform===`win32`,this.win32&&(this.path=cr(this.path.replaceAll(/\\/g,`/`)),e=e.replaceAll(/\\/g,`/`)),this.absolute=z(n.absolute||p.resolve(this.cwd,e)),this.path===``&&(this.path=`./`),r&&this.warn(`TAR_ENTRY_INFO`,`stripping ${r} from absolute path`,{entry:this,path:r+this.path});let i=this.statCache.get(this.absolute);i?this[yr](i):this[vr]()}warn(e,t,n={}){return xn(this,e,t,n)}emit(e,...t){return e===`error`&&(this.#e=!0),super.emit(e,...t)}[vr](){d.lstat(this.absolute,(e,t)=>{if(e)return this.emit(`error`,e);this[yr](t)})}[yr](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=jr(e),this.emit(`stat`,e),this[dr]()}[dr](){switch(this.type){case`File`:return this[fr]();case`Directory`:return this[pr]();case`SymbolicLink`:return this[mr]();default:return this.end()}}[Tr](e){return $n(e,this.type===`Directory`,this.portable)}[Y](e){return lr(e,this.prefix)}[gr](){if(!this.stat)throw Error(`cannot write header before stat`);this.type===`Directory`&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new I({path:this[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this[Tr](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 gn({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[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](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 e=this.header?.block;if(!e)throw Error(`failed to encode header`);super.write(e)}[pr](){if(!this.stat)throw Error(`cannot create directory entry without stat`);this.path.slice(-1)!==`/`&&(this.path+=`/`),this.stat.size=0,this[gr](),this.end()}[mr](){d.readlink(this.absolute,(e,t)=>{if(e)return this.emit(`error`,e);this[xr](t)})}[xr](e){this.linkpath=z(e),this[gr](),this.end()}[hr](e){if(!this.stat)throw Error(`cannot create link entry without stat`);this.type=`Link`,this.linkpath=z(p.relative(this.cwd,e)),this.stat.size=0,this[gr](),this.end()}[fr](){if(!this.stat)throw Error(`cannot create file entry without stat`);if(this.stat.nlink>1){let e=`${this.stat.dev}:${this.stat.ino}`,t=this.linkCache.get(e);if(t?.indexOf(this.cwd)===0)return this[hr](t);this.linkCache.set(e,this.absolute)}if(this[gr](),this.stat.size===0)return this.end();this[Sr]()}[Sr](){d.open(this.absolute,`r`,(e,t)=>{if(e)return this.emit(`error`,e);this[Cr](t)})}[Cr](e){if(this.fd=e,this.#e)return this[wr]();if(!this.stat)throw Error(`should stat before calling onopenfile`);this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let t=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(t),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[_r]()}[_r](){let{fd:e,buf:t,offset:n,length:r,pos:i}=this;if(e===void 0||t===void 0)throw Error(`cannot read file without first opening`);d.read(e,t,n,r,i,(e,t)=>{if(e)return this[wr](()=>this.emit(`error`,e));this[br](t)})}[wr](e=()=>{}){this.fd!==void 0&&d.close(this.fd,e)}[br](e){if(e<=0&&this.remain>0){let e=Object.assign(Error(`encountered unexpected EOF`),{path:this.absolute,syscall:`read`,code:`EOF`});return this[wr](()=>this.emit(`error`,e))}if(e>this.remain){let e=Object.assign(Error(`did not encounter expected EOF`),{path:this.absolute,syscall:`read`,code:`EOF`});return this[wr](()=>this.emit(`error`,e))}if(!this.buf)throw Error(`should have created buffer prior to reading`);if(e===this.remain)for(let t=e;t<this.length&&e<this.blockRemain;t++)this.buf[t+this.offset]=0,e++,this.remain++;let t=this.offset===0&&e===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+e);this.write(t)?this[Dr]():this[Er](()=>this[Dr]())}[Er](e){this.once(`drain`,e)}write(e,t,n){if(typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,typeof t==`string`?t:`utf8`)),this.blockRemain<e.length){let e=Object.assign(Error(`writing more data than expected`),{path:this.absolute});return this.emit(`error`,e)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,n)}[Dr](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[wr](e=>e?this.emit(`error`,e):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[_r]()}},kr=class extends Or{sync=!0;[vr](){this[yr](d.lstatSync(this.absolute))}[mr](){this[xr](d.readlinkSync(this.absolute))}[Sr](){this[Cr](d.openSync(this.absolute,`r`))}[_r](){let e=!0;try{let{fd:t,buf:n,offset:r,length:i,pos:a}=this;if(t===void 0||n===void 0)throw Error(`fd and buf must be set in READ method`);let o=d.readSync(t,n,r,i,a);this[br](o),e=!1}finally{if(e)try{this[wr](()=>{})}catch{}}}[Er](e){e()}[wr](e=()=>{}){this.fd!==void 0&&d.closeSync(this.fd),e()}},Ar=class extends Ue{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(e,t,n={}){return xn(this,e,t,n)}constructor(e,t={}){let n=St(t);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r===`Unsupported`)throw Error(`writing entry that should be ignored`);this.type=r,this.type===`Directory`&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=z(e.path),this.mode=e.mode===void 0?void 0:this[Tr](e.mode),this.uid=this.portable?void 0:e.uid,this.gid=this.portable?void 0:e.gid,this.uname=this.portable?void 0:e.uname,this.gname=this.portable?void 0:e.gname,this.size=e.size,this.mtime=this.noMtime?void 0:n.mtime||e.mtime,this.atime=this.portable?void 0:e.atime,this.ctime=this.portable?void 0:e.ctime,this.linkpath=e.linkpath===void 0?void 0:z(e.linkpath),typeof n.onwarn==`function`&&this.on(`warn`,n.onwarn);let i=!1;if(!this.preservePaths){let[e,t]=nr(this.path);e&&typeof t==`string`&&(this.path=t,i=e)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new I({path:this[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](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}),i&&this.warn(`TAR_ENTRY_INFO`,`stripping ${i} from absolute path`,{entry:this,path:i+this.path}),this.header.encode()&&!this.noPax&&super.write(new gn({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[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](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 a=this.header?.block;if(!a)throw Error(`failed to encode header`);super.write(a),e.pipe(this)}[Y](e){return lr(e,this.prefix)}[Tr](e){return $n(e,this.type===`Directory`,this.portable)}write(e,t,n){typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,typeof t==`string`?t:`utf8`));let r=e.length;if(r>this.blockRemain)throw Error(`writing more to entry than is appropriate`);return this.blockRemain-=r,super.write(e,n)}end(e,t,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e==`function`&&(n=e,t=void 0,e=void 0),typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,t??`utf8`)),n&&this.once(`finish`,n),e?super.end(e,n):super.end(n),this}},jr=e=>e.isFile()?`File`:e.isDirectory()?`Directory`:e.isSymbolicLink()?`SymbolicLink`:`Unsupported`,Mr=class e{tail;head;length=0;static create(t=[]){return new e(t)}constructor(e=[]){for(let t of e)this.push(t)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw Error(`removing node which does not belong to this list`);let t=e.next,n=e.prev;return t&&(t.prev=n),n&&(n.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=n),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,t}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let t=this.head;e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||=e,this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||=e,this.length++}push(...e){for(let t=0,n=e.length;t<n;t++)Pr(this,e[t]);return this.length}unshift(...e){for(var t=0,n=e.length;t<n;t++)Fr(this,e[t]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,t=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,t.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,t=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,t.list=void 0,this.length--,e}forEach(e,t){t||=this;for(let n=this.head,r=0;n;r++)e.call(t,n.value,r,this),n=n.next}forEachReverse(e,t){t||=this;for(let n=this.tail,r=this.length-1;n;r--)e.call(t,n.value,r,this),n=n.prev}get(e){let t=0,n=this.head;for(;n&&t<e;t++)n=n.next;if(t===e&&n)return n.value}getReverse(e){let t=0,n=this.tail;for(;n&&t<e;t++)n=n.prev;if(t===e&&n)return n.value}map(t,n){n||=this;let r=new e;for(let e=this.head;e;)r.push(t.call(n,e.value,this)),e=e.next;return r}mapReverse(t,n){n||=this;var r=new e;for(let e=this.tail;e;)r.push(t.call(n,e.value,this)),e=e.prev;return r}reduce(e,t){let n,r=this.head;if(arguments.length>1)n=t;else if(this.head)r=this.head.next,n=this.head.value;else throw TypeError(`Reduce of empty list with no initial value`);for(var i=0;r;i++)n=e(n,r.value,i),r=r.next;return n}reduceReverse(e,t){let n,r=this.tail;if(arguments.length>1)n=t;else if(this.tail)r=this.tail.prev,n=this.tail.value;else throw TypeError(`Reduce of empty list with no initial value`);for(let t=this.length-1;r;t--)n=e(n,r.value,t),r=r.prev;return n}toArray(){let e=Array(this.length);for(let t=0,n=this.head;n;t++)e[t]=n.value,n=n.next;return e}toArrayReverse(){let e=Array(this.length);for(let t=0,n=this.tail;n;t++)e[t]=n.value,n=n.prev;return e}slice(t=0,n=this.length){n<0&&(n+=this.length),t<0&&(t+=this.length);let r=new e;if(n<t||n<0)return r;t<0&&(t=0),n>this.length&&(n=this.length);let i=this.head,a=0;for(a=0;i&&a<t;a++)i=i.next;for(;i&&a<n;a++,i=i.next)r.push(i.value);return r}sliceReverse(t=0,n=this.length){n<0&&(n+=this.length),t<0&&(t+=this.length);let r=new e;if(n<t||n<0)return r;t<0&&(t=0),n>this.length&&(n=this.length);let i=this.length,a=this.tail;for(;a&&i>n;i--)a=a.prev;for(;a&&i>t;i--,a=a.prev)r.push(a.value);return r}splice(e,t=0,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let r=this.head;for(let t=0;r&&t<e;t++)r=r.next;let i=[];for(let e=0;r&&e<t;e++)i.push(r.value),r=this.removeNode(r);r?r!==this.tail&&(r=r.prev):r=this.tail;for(let e of n)r=Nr(this,r,e);return i}reverse(){let e=this.head,t=this.tail;for(let t=e;t;t=t.prev){let e=t.prev;t.prev=t.next,t.next=e}return this.head=t,this.tail=e,this}};function Nr(e,t,n){let r=new Ir(n,t,t?t.next:e.head,e);return r.next===void 0&&(e.tail=r),r.prev===void 0&&(e.head=r),e.length++,r}function Pr(e,t){e.tail=new Ir(t,e.tail,void 0,e),e.head||=e.tail,e.length++}function Fr(e,t){e.head=new Ir(t,void 0,e.head,e),e.tail||=e.head,e.length++}var Ir=class{list;next;prev;value;constructor(e,t,n,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},Lr=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||`./`,this.absolute=t}},Rr=Buffer.alloc(1024),zr=Symbol(`onStat`),Br=Symbol(`ended`),X=Symbol(`queue`),Vr=Symbol(`pendingLinks`),Hr=Symbol(`current`),Ur=Symbol(`process`),Wr=Symbol(`processing`),Gr=Symbol(`processJob`),Z=Symbol(`jobs`),Kr=Symbol(`jobDone`),qr=Symbol(`addFSEntry`),Jr=Symbol(`addTarEntry`),Yr=Symbol(`stat`),Xr=Symbol(`readdir`),Zr=Symbol(`onreaddir`),Qr=Symbol(`pipe`),$r=Symbol(`entry`),ei=Symbol(`entryOpt`),ti=Symbol(`writeEntryClass`),ni=Symbol(`write`),ri=Symbol(`ondrain`),ii=class extends Ue{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[ti];onWriteEntry;[X];[Vr]=new Map;[Z]=0;[Wr]=!1;[Br]=!1;constructor(e={}){if(super(),this.opt=e,this.file=e.file||``,this.cwd=e.cwd||process.cwd(),this.maxReadSize=e.maxReadSize,this.preservePaths=!!e.preservePaths,this.strict=!!e.strict,this.noPax=!!e.noPax,this.prefix=z(e.prefix||``),this.linkCache=e.linkCache||new Map,this.statCache=e.statCache||new Map,this.readdirCache=e.readdirCache||new Map,this.onWriteEntry=e.onWriteEntry,this[ti]=Or,typeof e.onwarn==`function`&&this.on(`warn`,e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if(+!!e.gzip+ +!!e.brotli+ +!!e.zstd>1)throw TypeError(`gzip, brotli, zstd are mutually exclusive`);if(e.gzip&&(typeof e.gzip!=`object`&&(e.gzip={}),this.portable&&(e.gzip.portable=!0),this.zip=new Pt(e.gzip)),e.brotli&&(typeof e.brotli!=`object`&&(e.brotli={}),this.zip=new Lt(e.brotli)),e.zstd&&(typeof e.zstd!=`object`&&(e.zstd={}),this.zip=new Bt(e.zstd)),!this.zip)throw Error(`impossible`);let t=this.zip;t.on(`data`,e=>super.write(e)),t.on(`end`,()=>super.end()),t.on(`drain`,()=>this[ri]()),this.on(`resume`,()=>t.resume())}else this.on(`drain`,this[ri]);this.noDirRecurse=!!e.noDirRecurse,this.follow=!!e.follow,this.noMtime=!!e.noMtime,e.mtime&&(this.mtime=e.mtime),this.filter=typeof e.filter==`function`?e.filter:()=>!0,this[X]=new Mr,this[Z]=0,this.jobs=Number(e.jobs)||4,this[Wr]=!1,this[Br]=!1}[ni](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,n){return typeof e==`function`&&(n=e,e=void 0),typeof t==`function`&&(n=t,t=void 0),e&&this.add(e),this[Br]=!0,this[Ur](),n&&n(),this}write(e){if(this[Br])throw Error(`write after end`);return typeof e==`string`?this[qr](e):this[Jr](e),this.flowing}[Jr](e){let t=z(p.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let n=new Lr(e.path,t);n.entry=new Ar(e,this[ei](n)),n.entry.on(`end`,()=>this[Kr](n)),this[Z]+=1,this[X].push(n)}this[Ur]()}[qr](e){let t=z(p.resolve(this.cwd,e));this[X].push(new Lr(e,t)),this[Ur]()}[Yr](e){e.pending=!0,this[Z]+=1,d[this.follow?`stat`:`lstat`](e.absolute,(t,n)=>{e.pending=!1,--this[Z],t?this.emit(`error`,t):this[zr](e,n)})}[zr](e,t){if(this.statCache.set(e.absolute,t),e.stat=t,!this.filter(e.path,t))e.ignore=!0;else if(t.isFile()&&t.nlink>1&&!this.linkCache.get(`${t.dev}:${t.ino}`)&&!this.sync)if(e===this[Hr])this[Gr](e);else{let n=`${t.dev}:${t.ino}`,r=this[Vr].get(n);r?r.push(e):this[Vr].set(n,[e]),e.pendingLink=!0,e.pending=!0}this[Ur]()}[Xr](e){e.pending=!0,this[Z]+=1,d.readdir(e.absolute,(t,n)=>{if(e.pending=!1,--this[Z],t)return this.emit(`error`,t);this[Zr](e,n)})}[Zr](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[Ur]()}[Ur](){if(!this[Wr]){this[Wr]=!0;for(let e=this[X].head;e&&this[Z]<this.jobs;e=e.next)if(this[Gr](e.value),e.value.ignore){let t=e.next;this[X].removeNode(e),e.next=t}this[Wr]=!1,this[Br]&&this[X].length===0&&this[Z]===0&&(this.zip?this.zip.end(Rr):(super.write(Rr),super.end()))}}get[Hr](){return this[X]&&this[X].head&&this[X].head.value}[Kr](e){this[X].shift(),--this[Z];let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let e=`${t.dev}:${t.ino}`,n=this[Vr].get(e);if(n){this[Vr].delete(e);for(let e of n)e.pending=!1,this[Gr](e)}}this[Ur]()}[Gr](e){if(e.pending&&e.pendingLink&&e===this[Hr]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[Hr]&&!e.piped&&this[Qr](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[zr](e,t):this[Yr](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[Zr](e,t):this[Xr](e),!e.readdir)return}if(e.entry=this[$r](e),!e.entry){e.ignore=!0;return}e===this[Hr]&&!e.piped&&this[Qr](e)}}}[ei](e){return{onwarn:(e,t,n)=>this.warn(e,t,n),noPax:this.noPax,cwd:this.cwd,absolute:e.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}}[$r](e){this[Z]+=1;try{return new this[ti](e.path,this[ei](e)).on(`end`,()=>this[Kr](e)).on(`error`,e=>this.emit(`error`,e))}catch(e){this.emit(`error`,e)}}[ri](){this[Hr]&&this[Hr].entry&&this[Hr].entry.resume()}[Qr](e){e.piped=!0,e.readdir&&e.readdir.forEach(t=>{let n=e.path,r=n===`./`?``:n.replace(/\/*$/,`/`);this[qr](r+t)});let t=e.entry,n=this.zip;if(!t)throw Error(`cannot pipe without source`);n?t.on(`data`,e=>{n.write(e)||t.pause()}):t.on(`data`,e=>{super.write(e)||t.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,t,n={}){xn(this,e,t,n)}},ai=class extends ii{sync=!0;constructor(e){super(e),this[ti]=kr}pause(){}resume(){}[Yr](e){let t=this.follow?`statSync`:`lstatSync`;this[zr](e,d[t](e.absolute))}[Xr](e){this[Zr](e,d.readdirSync(e.absolute))}[Qr](e){let t=e.entry,n=this.zip;if(e.readdir&&e.readdir.forEach(t=>{let n=e.path,r=n===`./`?``:n.replace(/\/*$/,`/`);this[qr](r+t)}),!t)throw Error(`Cannot pipe without source`);n?t.on(`data`,e=>{n.write(e)}):t.on(`data`,e=>{super[ni](e)})}},oi=(e,t)=>{let n=new ai(e),r=new mt(e.file,{mode:e.mode||438});n.pipe(r),ci(n,t)},si=(e,t)=>{let n=new ii(e),r=new pt(e.file,{mode:e.mode||438});n.pipe(r);let i=new Promise((e,t)=>{r.on(`error`,t),r.on(`close`,e),n.on(`error`,t)});return li(n,t).catch(e=>n.emit(`error`,e)),i},ci=(e,t)=>{t.forEach(t=>{t.charAt(0)===`@`?Qn({file:n.resolve(e.cwd,t.slice(1)),sync:!0,noResume:!0,onReadEntry:t=>e.add(t)}):e.add(t)}),e.end()},li=async(e,t)=>{for(let r of t)r.charAt(0)===`@`?await Qn({file:n.resolve(String(e.cwd),r.slice(1)),noResume:!0,onReadEntry:t=>{e.add(t)}}):e.add(r);e.end()},ui=Ct(oi,si,(e,t)=>{let n=new ai(e);return ci(n,t),n},(e,t)=>{let n=new ii(e);return li(n,t).catch(e=>n.emit(`error`,e)),n},(e,t)=>{if(!t?.length)throw TypeError(`no paths specified to add to archive`)}),di=(process.env.__FAKE_PLATFORM__||process.platform)===`win32`,{O_CREAT:fi,O_NOFOLLOW:pi,O_TRUNC:mi,O_WRONLY:hi}=d.constants,gi=Number(process.env.__FAKE_FS_O_FILENAME__)||d.constants.UV_FS_O_FILEMAP||0,_i=di&&!!gi,vi=512*1024,yi=gi|mi|fi|hi,bi=!di&&typeof pi==`number`?pi|mi|fi|hi:null,xi=bi===null?_i?e=>e<vi?yi:`w`:()=>`w`:()=>bi,Si=(e,n,r)=>{try{return t.lchownSync(e,n,r)}catch(e){if(e?.code!==`ENOENT`)throw e}},Ci=(e,n,r,i)=>{t.lchown(e,n,r,e=>{i(e&&e?.code!==`ENOENT`?e:null)})},wi=(e,t,r,i,a)=>{t.isDirectory()?Ti(n.resolve(e,t.name),r,i,o=>{if(o)return a(o);Ci(n.resolve(e,t.name),r,i,a)}):Ci(n.resolve(e,t.name),r,i,a)},Ti=(e,n,r,i)=>{t.readdir(e,{withFileTypes:!0},(t,a)=>{if(t){if(t.code===`ENOENT`)return i();if(t.code!==`ENOTDIR`&&t.code!==`ENOTSUP`)return i(t)}if(t||!a.length)return Ci(e,n,r,i);let o=a.length,s=null,c=t=>{if(!s){if(t)return i(s=t);if(--o===0)return Ci(e,n,r,i)}};for(let t of a)wi(e,t,n,r,c)})},Ei=(e,t,r,i)=>{t.isDirectory()&&Di(n.resolve(e,t.name),r,i),Si(n.resolve(e,t.name),r,i)},Di=(e,n,r)=>{let i;try{i=t.readdirSync(e,{withFileTypes:!0})}catch(t){let i=t;if(i?.code===`ENOENT`)return;if(i?.code===`ENOTDIR`||i?.code===`ENOTSUP`)return Si(e,n,r);throw i}for(let t of i)Ei(e,t,n,r);return Si(e,n,r)},Oi=class extends Error{path;code;syscall=`chdir`;constructor(e,t){super(`${t}: Cannot cd into '${e}'`),this.path=e,this.code=t}get name(){return`CwdError`}},ki=class extends Error{path;symlink;syscall=`symlink`;code=`TAR_SYMLINK_ERROR`;constructor(e,t){super(`TAR_SYMLINK_ERROR: Cannot extract through symbolic link`),this.symlink=e,this.path=t}get name(){return`SymlinkError`}},Ai=(e,n)=>{t.stat(e,(t,r)=>{(t||!r.isDirectory())&&(t=new Oi(e,t?.code||`ENOTDIR`)),n(t)})},ji=(e,r,i)=>{e=z(e);let a=r.umask??18,o=r.mode|448,c=(o&a)!==0,l=r.uid,u=r.gid,d=typeof l==`number`&&typeof u==`number`&&(l!==r.processUid||u!==r.processGid),f=r.preserve,ee=r.unlink,p=z(r.cwd),m=(n,r)=>{n?i(n):r&&d?Ti(r,l,u,e=>m(e)):c?t.chmod(e,o,i):i()};if(e===p)return Ai(e,m);if(f)return s.mkdir(e,{mode:o,recursive:!0}).then(e=>m(null,e??void 0),m);Mi(p,z(n.relative(p,e)).split(`/`),o,ee,p,void 0,m)},Mi=(e,r,i,a,o,s,c)=>{if(r.length===0)return c(null,s);let l=r.shift(),u=z(n.resolve(e+`/`+l));t.mkdir(u,i,Ni(u,r,i,a,o,s,c))},Ni=(e,n,r,i,a,o,s)=>c=>{c?t.lstat(e,(l,u)=>{if(l)l.path=l.path&&z(l.path),s(l);else if(u.isDirectory())Mi(e,n,r,i,a,o,s);else if(i)t.unlink(e,c=>{if(c)return s(c);t.mkdir(e,r,Ni(e,n,r,i,a,o,s))});else{if(u.isSymbolicLink())return s(new ki(e,e+`/`+n.join(`/`)));s(c)}}):(o||=e,Mi(e,n,r,i,a,o,s))},Pi=e=>{let n=!1,r;try{n=t.statSync(e).isDirectory()}catch(e){r=e?.code}finally{if(!n)throw new Oi(e,r??`ENOTDIR`)}},Fi=(e,r)=>{e=z(e);let i=r.umask??18,a=r.mode|448,o=(a&i)!==0,s=r.uid,c=r.gid,l=typeof s==`number`&&typeof c==`number`&&(s!==r.processUid||c!==r.processGid),u=r.preserve,d=r.unlink,f=z(r.cwd),ee=n=>{n&&l&&Di(n,s,c),o&&t.chmodSync(e,a)};if(e===f)return Pi(f),ee();if(u)return ee(t.mkdirSync(e,{mode:a,recursive:!0})??void 0);let p=z(n.relative(f,e)).split(`/`),m;for(let e=p.shift(),r=f;e&&(r+=`/`+e);e=p.shift()){r=z(n.resolve(r));try{t.mkdirSync(r,a),m||=r}catch{let e=t.lstatSync(r);if(e.isDirectory())continue;if(d){t.unlinkSync(r),t.mkdirSync(r,a),m||=r;continue}else if(e.isSymbolicLink())return new ki(r,r+`/`+p.join(`/`))}}return ee(m)},Ii=Object.create(null),Li=1e4,Ri=new Set,zi=e=>{Ri.has(e)?Ri.delete(e):Ii[e]=e.normalize(`NFD`).toLocaleLowerCase(`en`).toLocaleUpperCase(`en`),Ri.add(e);let t=Ii[e],n=Ri.size-Li;if(n>Li/10){for(let e of Ri)if(Ri.delete(e),delete Ii[e],--n<=0)break}return t},Bi=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`,Vi=e=>e.split(`/`).slice(0,-1).reduce((e,t)=>{let n=e.at(-1);return n!==void 0&&(t=i(n,t)),e.push(t||`/`),e},[]),Hi=class{#e=new Map;#t=new Map;#n=new Set;reserve(e,t){e=Bi?[`win32 parallelization disabled`]:e.map(e=>Yn(i(zi(e))));let n=new Set(e.map(e=>Vi(e)).reduce((e,t)=>e.concat(t)));this.#t.set(t,{dirs:n,paths:e});for(let n of e){let e=this.#e.get(n);e?e.push(t):this.#e.set(n,[t])}for(let e of n){let n=this.#e.get(e);if(!n)this.#e.set(e,[new Set([t])]);else{let e=n.at(-1);e instanceof Set?e.add(t):n.push(new Set([t]))}}return this.#i(t)}#r(e){let t=this.#t.get(e);if(!t)throw Error(`function does not have any path reservations`);return{paths:t.paths.map(e=>this.#e.get(e)),dirs:[...t.dirs].map(e=>this.#e.get(e))}}check(e){let{paths:t,dirs:n}=this.#r(e);return t.every(t=>t&&t[0]===e)&&n.every(t=>t&&t[0]instanceof Set&&t[0].has(e))}#i(e){return this.#n.has(e)||!this.check(e)?!1:(this.#n.add(e),e(()=>this.#a(e)),!0)}#a(e){if(!this.#n.has(e))return!1;let t=this.#t.get(e);if(!t)throw Error(`invalid reservation`);let{paths:n,dirs:r}=t,i=new Set;for(let t of n){let n=this.#e.get(t);if(!n||n?.[0]!==e)continue;let r=n[1];if(!r){this.#e.delete(t);continue}if(n.shift(),typeof r==`function`)i.add(r);else for(let e of r)i.add(e)}for(let t of r){let n=this.#e.get(t),r=n?.[0];if(!(!n||!(r instanceof Set)))if(r.size===1&&n.length===1){this.#e.delete(t);continue}else if(r.size===1){n.shift();let e=n[0];typeof e==`function`&&i.add(e)}else r.delete(e)}return this.#n.delete(e),i.forEach(e=>this.#i(e)),!0}},Ui=()=>process.umask(),Wi=Symbol(`onEntry`),Gi=Symbol(`checkFs`),Ki=Symbol(`checkFs2`),qi=Symbol(`isReusable`),Q=Symbol(`makeFs`),Ji=Symbol(`file`),Yi=Symbol(`directory`),Xi=Symbol(`link`),Zi=Symbol(`symlink`),Qi=Symbol(`hardlink`),$i=Symbol(`ensureNoSymlink`),ea=Symbol(`unsupported`),ta=Symbol(`checkPath`),na=Symbol(`stripAbsolutePath`),ra=Symbol(`mkdir`),$=Symbol(`onError`),ia=Symbol(`pending`),aa=Symbol(`pend`),oa=Symbol(`unpend`),sa=Symbol(`ended`),ca=Symbol(`maybeClose`),la=Symbol(`skip`),ua=Symbol(`doChown`),da=Symbol(`uid`),fa=Symbol(`gid`),pa=Symbol(`checkedCwd`),ma=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`,ha=1024,ga=(e,n)=>{if(!ma)return t.unlink(e,n);let r=e+`.DELETE.`+se(16).toString(`hex`);t.rename(e,r,e=>{if(e)return n(e);t.unlink(r,n)})},_a=e=>{if(!ma)return t.unlinkSync(e);let n=e+`.DELETE.`+se(16).toString(`hex`);t.renameSync(e,n),t.unlinkSync(n)},va=(e,t,n)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:n,ya=class extends Jn{[sa]=!1;[pa]=!1;[ia]=0;reservations=new Hi;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(e={}){if(e.ondone=()=>{this[sa]=!0,this[ca]()},super(e),this.transform=e.transform,this.chmod=!!e.chmod,typeof e.uid==`number`||typeof e.gid==`number`){if(typeof e.uid!=`number`||typeof e.gid!=`number`)throw TypeError(`cannot set owner without number uid and gid`);if(e.preserveOwner)throw TypeError(`cannot preserve owner in archive and also set owner explicitly`);this.uid=e.uid,this.gid=e.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=e.preserveOwner===void 0&&typeof e.uid!=`number`?!!(process.getuid&&process.getuid()===0):!!e.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 e.maxDepth==`number`?e.maxDepth:ha,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||ma,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=z(n.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask==`number`?e.processUmask:Ui():0,this.umask=typeof e.umask==`number`?e.umask:this.processUmask,this.dmode=e.dmode||511&~this.umask,this.fmode=e.fmode||438&~this.umask,this.on(`entry`,e=>this[Wi](e))}warn(e,t,n={}){return(e===`TAR_BAD_ARCHIVE`||e===`TAR_ABORT`)&&(n.recoverable=!1),super.warn(e,t,n)}[ca](){this[sa]&&this[ia]===0&&(this.emit(`prefinish`),this.emit(`finish`),this.emit(`end`))}[na](e,t){let r=e[t],{type:i}=e;if(!r||this.preservePaths)return!0;let[a,o]=nr(r),s=o.replaceAll(/\\/g,`/`).split(`/`);if(s.includes(`..`)||ma&&/^[a-z]:\.\.$/i.test(s[0]??``)){if(t===`path`||i===`Link`)return this.warn(`TAR_ENTRY_ERROR`,`${t} contains '..'`,{entry:e,[t]:r}),!1;let a=n.posix.dirname(e.path),o=n.posix.normalize(n.posix.join(a,s.join(`/`)));if(o.startsWith(`../`)||o===`..`)return this.warn(`TAR_ENTRY_ERROR`,`${t} escapes extraction directory`,{entry:e,[t]:r}),!1}return a&&(e[t]=String(o),this.warn(`TAR_ENTRY_INFO`,`stripping ${a} from absolute ${t}`,{entry:e,[t]:r})),!0}[ta](e){let t=z(e.path),r=t.split(`/`);if(this.strip){if(r.length<this.strip)return!1;if(e.type===`Link`){let t=z(String(e.linkpath)).split(`/`);if(t.length>=this.strip)e.linkpath=t.slice(this.strip).join(`/`);else return!1}r.splice(0,this.strip),e.path=r.join(`/`)}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn(`TAR_ENTRY_ERROR`,`path excessively deep`,{entry:e,path:t,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[na](e,`path`)||!this[na](e,`linkpath`))return!1;if(e.absolute=n.isAbsolute(e.path)?z(n.resolve(e.path)):z(n.resolve(this.cwd,e.path)),!this.preservePaths&&typeof e.absolute==`string`&&e.absolute.indexOf(this.cwd+`/`)!==0&&e.absolute!==this.cwd)return this.warn(`TAR_ENTRY_ERROR`,`path escaped extraction target`,{entry:e,path:z(e.path),resolvedPath:e.absolute,cwd:this.cwd}),!1;if(e.absolute===this.cwd&&e.type!==`Directory`&&e.type!==`GNUDumpDir`)return!1;if(this.win32){let{root:t}=n.win32.parse(String(e.absolute));e.absolute=t+sr(String(e.absolute).slice(t.length));let{root:r}=n.win32.parse(e.path);e.path=r+sr(e.path.slice(r.length))}return!0}[Wi](e){if(!this[ta](e))return e.resume();switch(oe.equal(typeof e.absolute,`string`),e.type){case`Directory`:case`GNUDumpDir`:e.mode&&(e.mode|=448);case`File`:case`OldFile`:case`ContiguousFile`:case`Link`:case`SymbolicLink`:return this[Gi](e);default:return this[ea](e)}}[$](e,t){e.name===`CwdError`?this.emit(`error`,e):(this.warn(`TAR_ENTRY_ERROR`,e,{entry:t}),this[oa](),t.resume())}[ra](e,t,n){ji(z(e),{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:t},n)}[ua](e){return this.forceChown||this.preserveOwner&&(typeof e.uid==`number`&&e.uid!==this.processUid||typeof e.gid==`number`&&e.gid!==this.processGid)||typeof this.uid==`number`&&this.uid!==this.processUid||typeof this.gid==`number`&&this.gid!==this.processGid}[da](e){return va(this.uid,e.uid,this.processUid)}[fa](e){return va(this.gid,e.gid,this.processGid)}[Ji](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.fmode,i=new pt(String(e.absolute),{flags:xi(e.size),mode:r,autoClose:!1});i.on(`error`,r=>{i.fd&&t.close(i.fd,()=>{}),i.write=()=>!0,this[$](r,e),n()});let a=1,o=r=>{if(r){i.fd&&t.close(i.fd,()=>{}),this[$](r,e),n();return}--a===0&&i.fd!==void 0&&t.close(i.fd,t=>{t?this[$](t,e):this[oa](),n()})};i.on(`finish`,()=>{let n=String(e.absolute),r=i.fd;if(typeof r==`number`&&e.mtime&&!this.noMtime){a++;let i=e.atime||new Date,s=e.mtime;t.futimes(r,i,s,e=>e?t.utimes(n,i,s,t=>o(t&&e)):o())}if(typeof r==`number`&&this[ua](e)){a++;let i=this[da](e),s=this[fa](e);typeof i==`number`&&typeof s==`number`&&t.fchown(r,i,s,e=>e?t.chown(n,i,s,t=>o(t&&e)):o())}o()});let s=this.transform&&this.transform(e)||e;s!==e&&(s.on(`error`,t=>{this[$](t,e),n()}),e.pipe(s)),s.pipe(i)}[Yi](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.dmode;this[ra](String(e.absolute),r,r=>{if(r){this[$](r,e),n();return}let i=1,a=()=>{--i===0&&(n(),this[oa](),e.resume())};e.mtime&&!this.noMtime&&(i++,t.utimes(String(e.absolute),e.atime||new Date,e.mtime,a)),this[ua](e)&&(i++,t.chown(String(e.absolute),Number(this[da](e)),Number(this[fa](e)),a)),a()})}[ea](e){e.unsupported=!0,this.warn(`TAR_ENTRY_UNSUPPORTED`,`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[Zi](e,t){let r=z(n.relative(this.cwd,n.resolve(n.dirname(String(e.absolute)),String(e.linkpath)))).split(`/`);this[$i](e,this.cwd,r,()=>this[Xi](e,String(e.linkpath),`symlink`,t),n=>{this[$](n,e),t()})}[Qi](e,t){let r=z(n.resolve(this.cwd,String(e.linkpath))),i=z(String(e.linkpath)).split(`/`);this[$i](e,this.cwd,i,()=>this[Xi](e,r,`link`,t),n=>{this[$](n,e),t()})}[$i](e,r,i,a,o){let s=i.shift();if(this.preservePaths||s===void 0)return a();let c=n.resolve(r,s);t.lstat(c,(t,r)=>{if(t)return a();if(r?.isSymbolicLink())return o(new ki(c,n.resolve(c,i.join(`/`))));this[$i](e,c,i,a,o)})}[aa](){this[ia]++}[oa](){this[ia]--,this[ca]()}[la](e){this[oa](),e.resume()}[qi](e,t){return e.type===`File`&&!this.unlink&&t.isFile()&&t.nlink<=1&&!ma}[Gi](e){this[aa]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,t=>this[Ki](e,t))}[Ki](e,r){let i=e=>{r(e)},a=()=>{this[ra](this.cwd,this.dmode,t=>{if(t){this[$](t,e),i();return}this[pa]=!0,o()})},o=()=>{if(e.absolute!==this.cwd){let t=z(n.dirname(String(e.absolute)));if(t!==this.cwd)return this[ra](t,this.dmode,t=>{if(t){this[$](t,e),i();return}s()})}s()},s=()=>{t.lstat(String(e.absolute),(n,r)=>{if(r&&(this.keep||this.newer&&r.mtime>(e.mtime??r.mtime))){this[la](e),i();return}if(n||this[qi](e,r))return this[Q](null,e,i);if(r.isDirectory()){if(e.type===`Directory`){let n=this.chmod&&e.mode&&(r.mode&4095)!==e.mode,a=t=>this[Q](t??null,e,i);return n?t.chmod(String(e.absolute),Number(e.mode),a):a()}if(e.absolute!==this.cwd)return t.rmdir(String(e.absolute),t=>this[Q](t??null,e,i))}if(e.absolute===this.cwd)return this[Q](null,e,i);ga(String(e.absolute),t=>this[Q](t??null,e,i))})};this[pa]?o():a()}[Q](e,t,n){if(e){this[$](e,t),n();return}switch(t.type){case`File`:case`OldFile`:case`ContiguousFile`:return this[Ji](t,n);case`Link`:return this[Qi](t,n);case`SymbolicLink`:return this[Zi](t,n);case`Directory`:case`GNUDumpDir`:return this[Yi](t,n)}}[Xi](e,n,r,i){t[r](n,String(e.absolute),t=>{t?this[$](t,e):(this[oa](),e.resume()),i()})}},ba=e=>{try{return[null,e()]}catch(e){return[e,null]}},xa=class extends ya{sync=!0;[Q](e,t){return super[Q](e,t,()=>{})}[Gi](e){if(!this[pa]){let t=this[ra](this.cwd,this.dmode);if(t)return this[$](t,e);this[pa]=!0}if(e.absolute!==this.cwd){let t=z(n.dirname(String(e.absolute)));if(t!==this.cwd){let n=this[ra](t,this.dmode);if(n)return this[$](n,e)}}let[r,i]=ba(()=>t.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[la](e);if(r||this[qi](e,i))return this[Q](null,e);if(i.isDirectory()){if(e.type===`Directory`){let[n]=this.chmod&&e.mode&&(i.mode&4095)!==e.mode?ba(()=>{t.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[Q](n,e)}let[n]=ba(()=>t.rmdirSync(String(e.absolute)));this[Q](n,e)}let[a]=e.absolute===this.cwd?[]:ba(()=>_a(String(e.absolute)));this[Q](a,e)}[Ji](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.fmode,i=r=>{let i;try{t.closeSync(a)}catch(e){i=e}(r||i)&&this[$](r||i,e),n()},a;try{a=t.openSync(String(e.absolute),xi(e.size),r)}catch(e){return i(e)}let o=this.transform&&this.transform(e)||e;o!==e&&(o.on(`error`,t=>this[$](t,e)),e.pipe(o)),o.on(`data`,e=>{try{t.writeSync(a,e,0,e.length)}catch(e){i(e)}}),o.on(`end`,()=>{let n=null;if(e.mtime&&!this.noMtime){let r=e.atime||new Date,i=e.mtime;try{t.futimesSync(a,r,i)}catch(a){try{t.utimesSync(String(e.absolute),r,i)}catch{n=a}}}if(this[ua](e)){let r=this[da](e),i=this[fa](e);try{t.fchownSync(a,Number(r),Number(i))}catch(a){try{t.chownSync(String(e.absolute),Number(r),Number(i))}catch{n||=a}}}i(n)})}[Yi](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.dmode,i=this[ra](String(e.absolute),r);if(i){this[$](i,e),n();return}if(e.mtime&&!this.noMtime)try{t.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[ua](e))try{t.chownSync(String(e.absolute),Number(this[da](e)),Number(this[fa](e)))}catch{}n(),e.resume()}[ra](e,t){try{return Fi(z(e),{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:t})}catch(e){return e}}[$i](e,r,i,a,o){if(this.preservePaths||i.length===0)return a();let s=r;for(let e of i){s=n.resolve(s,e);let[c,l]=ba(()=>t.lstatSync(s));if(c)return a();if(l.isSymbolicLink())return o(new ki(s,n.resolve(r,i.join(`/`))))}a()}[Xi](e,n,r,i){let a=`${r}Sync`;try{t[a](n,String(e.absolute)),i(),e.resume()}catch(t){return this[$](t,e)}}},Sa=Ct(e=>{let n=new xa(e),r=e.file,i=t.statSync(r);new ft(r,{readSize:e.maxReadSize||16*1024*1024,size:i.size}).pipe(n)},(e,n)=>{let r=new ya(e),i=e.maxReadSize||16*1024*1024,a=e.file;return new Promise((e,n)=>{r.on(`error`,n),r.on(`close`,e),t.stat(a,(e,t)=>{if(e)n(e);else{let e=new dt(a,{readSize:i,size:t.size});e.on(`error`,n),e.pipe(r)}})})},e=>new xa(e),e=>new ya(e),(e,t)=>{t?.length&&Zn(e,t)}),Ca=(e,n)=>{let r=new ai(e),i=!0,a,o;try{try{a=t.openSync(e.file,`r+`)}catch(n){if(n?.code===`ENOENT`)a=t.openSync(e.file,`w+`);else throw n}let s=t.fstatSync(a),c=Buffer.alloc(512);t:for(o=0;o<s.size;o+=512){for(let e=0,n=0;e<512;e+=n){if(n=t.readSync(a,c,e,c.length-e,o+e),o===0&&c[0]===31&&c[1]===139)throw Error(`cannot append to compressed archives`);if(!n)break t}let n=new I(c);if(!n.cksumValid)break;let r=512*Math.ceil((n.size||0)/512);if(o+r+512>s.size)break;o+=r,e.mtimeCache&&n.mtime&&e.mtimeCache.set(String(n.path),n.mtime)}i=!1,wa(e,r,o,a,n)}finally{if(i)try{t.closeSync(a)}catch{}}},wa=(e,t,n,r,i)=>{let a=new mt(e.file,{fd:r,start:n});t.pipe(a),Ea(t,i)},Ta=(e,n)=>{n=Array.from(n);let r=new ii(e),i=(n,r,i)=>{let a=(e,r)=>{e?t.close(n,t=>i(e)):i(null,r)},o=0;if(r===0)return a(null,0);let s=0,c=Buffer.alloc(512),l=(i,u)=>{if(i||u===void 0)return a(i);if(s+=u,s<512&&u)return t.read(n,c,s,c.length-s,o+s,l);if(o===0&&c[0]===31&&c[1]===139)return a(Error(`cannot append to compressed archives`));if(s<512)return a(null,o);let d=new I(c);if(!d.cksumValid)return a(null,o);let f=512*Math.ceil((d.size??0)/512);if(o+f+512>r||(o+=f+512,o>=r))return a(null,o);e.mtimeCache&&d.mtime&&e.mtimeCache.set(String(d.path),d.mtime),s=0,t.read(n,c,0,512,o,l)};t.read(n,c,0,512,o,l)};return new Promise((a,o)=>{r.on(`error`,o);let s=`r+`,c=(l,u)=>{if(l&&l.code===`ENOENT`&&s===`r+`)return s=`w+`,t.open(e.file,s,c);if(l||!u)return o(l);t.fstat(u,(s,c)=>{if(s)return t.close(u,()=>o(s));i(u,c.size,(t,i)=>{if(t)return o(t);let s=new pt(e.file,{fd:u,start:i});r.pipe(s),s.on(`error`,o),s.on(`close`,a),Da(r,n)})})};t.open(e.file,s,c)})},Ea=(e,t)=>{t.forEach(t=>{t.charAt(0)===`@`?Qn({file:n.resolve(e.cwd,t.slice(1)),sync:!0,noResume:!0,onReadEntry:t=>e.add(t)}):e.add(t)}),e.end()},Da=async(e,t)=>{for(let r of t)r.charAt(0)===`@`?await Qn({file:n.resolve(String(e.cwd),r.slice(1)),noResume:!0,onReadEntry:t=>e.add(t)}):e.add(r);e.end()},Oa=Ct(Ca,Ta,()=>{throw TypeError(`file is required`)},()=>{throw TypeError(`file is required`)},(e,t)=>{if(!bt(e))throw TypeError(`file is required`);if(e.gzip||e.brotli||e.zstd||e.file.endsWith(`.br`)||e.file.endsWith(`.tbr`))throw TypeError(`cannot append to compressed archives`);if(!t?.length)throw TypeError(`no paths specified to add/replace`)});Ct(Oa.syncFile,Oa.asyncFile,Oa.syncNoFile,Oa.asyncNoFile,(e,t=[])=>{Oa.validate?.(e,t),ka(e)});var ka=e=>{let t=e.filter;e.mtimeCache||=new Map,e.filter=t?(n,r)=>t(n,r)&&!((e.mtimeCache?.get(n)??r.mtime??0)>(r.mtime??0)):(t,n)=>!((e.mtimeCache?.get(t)??n.mtime??0)>(n.mtime??0))};export{ce as index_min_exports};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-mugnavo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Create a project using Mugnavo templates.",
|
|
5
5
|
"homepage": "https://github.com/mugnavo/create-mugnavo#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
],
|
|
18
18
|
"type": "module",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@clack/prompts": "^1.
|
|
21
|
-
"@types/node": "^
|
|
20
|
+
"@clack/prompts": "^1.6.0",
|
|
21
|
+
"@types/node": "^26.1.0",
|
|
22
22
|
"bumpp": "^11.1.0",
|
|
23
23
|
"citty": "^0.2.2",
|
|
24
|
-
"giget": "^3.
|
|
25
|
-
"oxfmt": "^0.
|
|
26
|
-
"oxlint": "^1.
|
|
27
|
-
"oxlint-tsgolint": "^0.
|
|
28
|
-
"tinyexec": "^1.
|
|
29
|
-
"tsdown": "^0.22.
|
|
24
|
+
"giget": "^3.3.0",
|
|
25
|
+
"oxfmt": "^0.57.0",
|
|
26
|
+
"oxlint": "^1.72.0",
|
|
27
|
+
"oxlint-tsgolint": "^0.24.0",
|
|
28
|
+
"tinyexec": "^1.2.4",
|
|
29
|
+
"tsdown": "^0.22.3",
|
|
30
30
|
"typescript": "^6.0.3",
|
|
31
|
-
"vitest": "^4.1.
|
|
31
|
+
"vitest": "^4.1.9"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=24"
|
package/dist/tar-Bd_UMghg.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{t as e}from"./rolldown-runtime-Dh0vTgs_.mjs";import t from"node:fs";import n,{basename as r,join as i,posix as a,win32 as o}from"node:path";import s from"node:fs/promises";import c from"node:stream";import l,{EventEmitter as u}from"events";import d from"fs";import{EventEmitter as f}from"node:events";import{StringDecoder as ee}from"node:string_decoder";import p,{dirname as m,parse as te}from"path";import ne from"assert";import{Buffer as re}from"buffer";import*as ie from"zlib";import ae from"zlib";import oe from"node:assert";import{randomBytes as se}from"node:crypto";var ce=e({Header:()=>I,Pack:()=>ni,PackJob:()=>Ir,PackSync:()=>ri,Parser:()=>Jn,Pax:()=>hn,ReadEntry:()=>yn,Unpack:()=>_a,UnpackSync:()=>ya,WriteEntry:()=>Dr,WriteEntrySync:()=>Or,WriteEntryTar:()=>kr,c:()=>ci,create:()=>ci,extract:()=>ba,filesFilter:()=>Zn,list:()=>Qn,r:()=>Ea,replace:()=>Ea,t:()=>Qn,types:()=>Xt,x:()=>ba}),le=Object.defineProperty,ue=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},de=typeof process==`object`&&process?process:{stdout:null,stderr:null},fe=e=>!!e&&typeof e==`object`&&(e instanceof Ue||e instanceof c||pe(e)||me(e)),pe=e=>!!e&&typeof e==`object`&&e instanceof f&&typeof e.pipe==`function`&&e.pipe!==c.Writable.prototype.pipe,me=e=>!!e&&typeof e==`object`&&e instanceof f&&typeof e.write==`function`&&typeof e.end==`function`,h=Symbol(`EOF`),g=Symbol(`maybeEmitEnd`),_=Symbol(`emittedEnd`),he=Symbol(`emittingEnd`),ge=Symbol(`emittedError`),_e=Symbol(`closed`),ve=Symbol(`read`),ye=Symbol(`flush`),be=Symbol(`flushChunk`),v=Symbol(`encoding`),xe=Symbol(`decoder`),y=Symbol(`flowing`),Se=Symbol(`paused`),Ce=Symbol(`resume`),b=Symbol(`buffer`),x=Symbol(`pipes`),S=Symbol(`bufferLength`),we=Symbol(`bufferPush`),Te=Symbol(`bufferShift`),C=Symbol(`objectMode`),w=Symbol(`destroyed`),Ee=Symbol(`error`),De=Symbol(`emitData`),Oe=Symbol(`emitEnd`),ke=Symbol(`emitEnd2`),T=Symbol(`async`),Ae=Symbol(`abort`),je=Symbol(`aborted`),Me=Symbol(`signal`),Ne=Symbol(`dataListeners`),E=Symbol(`discarded`),Pe=e=>Promise.resolve().then(e),Fe=e=>e(),Ie=e=>e===`end`||e===`finish`||e===`prefinish`,Le=e=>e instanceof ArrayBuffer||!!e&&typeof e==`object`&&e.constructor&&e.constructor.name===`ArrayBuffer`&&e.byteLength>=0,Re=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),ze=class{src;dest;opts;ondrain;constructor(e,t,n){this.src=e,this.dest=t,this.opts=n,this.ondrain=()=>e[Ce](),this.dest.on(`drain`,this.ondrain)}unpipe(){this.dest.removeListener(`drain`,this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Be=class extends ze{unpipe(){this.src.removeListener(`error`,this.proxyErrors),super.unpipe()}constructor(e,t,n){super(e,t,n),this.proxyErrors=e=>this.dest.emit(`error`,e),e.on(`error`,this.proxyErrors)}},Ve=e=>!!e.objectMode,He=e=>!e.objectMode&&!!e.encoding&&e.encoding!==`buffer`,Ue=class extends f{[y]=!1;[Se]=!1;[x]=[];[b]=[];[C];[v];[T];[xe];[h]=!1;[_]=!1;[he]=!1;[_e]=!1;[ge]=null;[S]=0;[w]=!1;[Me];[je]=!1;[Ne]=0;[E]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding==`string`)throw TypeError(`Encoding and objectMode may not be used together`);Ve(t)?(this[C]=!0,this[v]=null):He(t)?(this[v]=t.encoding,this[C]=!1):(this[C]=!1,this[v]=null),this[T]=!!t.async,this[xe]=this[v]?new ee(this[v]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,`buffer`,{get:()=>this[b]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,`pipes`,{get:()=>this[x]});let{signal:n}=t;n&&(this[Me]=n,n.aborted?this[Ae]():n.addEventListener(`abort`,()=>this[Ae]()))}get bufferLength(){return this[S]}get encoding(){return this[v]}set encoding(e){throw Error(`Encoding must be set at instantiation time`)}setEncoding(e){throw Error(`Encoding must be set at instantiation time`)}get objectMode(){return this[C]}set objectMode(e){throw Error(`objectMode must be set at instantiation time`)}get async(){return this[T]}set async(e){this[T]=this[T]||!!e}[Ae](){this[je]=!0,this.emit(`abort`,this[Me]?.reason),this.destroy(this[Me]?.reason)}get aborted(){return this[je]}set aborted(e){}write(e,t,n){if(this[je])return!1;if(this[h])throw Error(`write after end`);if(this[w])return this.emit(`error`,Object.assign(Error(`Cannot call write after a stream was destroyed`),{code:`ERR_STREAM_DESTROYED`})),!0;typeof t==`function`&&(n=t,t=`utf8`),t||=`utf8`;let r=this[T]?Pe:Fe;if(!this[C]&&!Buffer.isBuffer(e)){if(Re(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Le(e))e=Buffer.from(e);else if(typeof e!=`string`)throw Error(`Non-contiguous data written to non-objectMode stream`)}return this[C]?(this[y]&&this[S]!==0&&this[ye](!0),this[y]?this.emit(`data`,e):this[we](e),this[S]!==0&&this.emit(`readable`),n&&r(n),this[y]):e.length?(typeof e==`string`&&!(t===this[v]&&!this[xe]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[v]&&(e=this[xe].write(e)),this[y]&&this[S]!==0&&this[ye](!0),this[y]?this.emit(`data`,e):this[we](e),this[S]!==0&&this.emit(`readable`),n&&r(n),this[y]):(this[S]!==0&&this.emit(`readable`),n&&r(n),this[y])}read(e){if(this[w])return null;if(this[E]=!1,this[S]===0||e===0||e&&e>this[S])return this[g](),null;this[C]&&(e=null),this[b].length>1&&!this[C]&&(this[b]=[this[v]?this[b].join(``):Buffer.concat(this[b],this[S])]);let t=this[ve](e||null,this[b][0]);return this[g](),t}[ve](e,t){if(this[C])this[Te]();else{let n=t;e===n.length||e===null?this[Te]():typeof n==`string`?(this[b][0]=n.slice(e),t=n.slice(0,e),this[S]-=e):(this[b][0]=n.subarray(e),t=n.subarray(0,e),this[S]-=e)}return this.emit(`data`,t),!this[b].length&&!this[h]&&this.emit(`drain`),t}end(e,t,n){return typeof e==`function`&&(n=e,e=void 0),typeof t==`function`&&(n=t,t=`utf8`),e!==void 0&&this.write(e,t),n&&this.once(`end`,n),this[h]=!0,this.writable=!1,(this[y]||!this[Se])&&this[g](),this}[Ce](){this[w]||(!this[Ne]&&!this[x].length&&(this[E]=!0),this[Se]=!1,this[y]=!0,this.emit(`resume`),this[b].length?this[ye]():this[h]?this[g]():this.emit(`drain`))}resume(){return this[Ce]()}pause(){this[y]=!1,this[Se]=!0,this[E]=!1}get destroyed(){return this[w]}get flowing(){return this[y]}get paused(){return this[Se]}[we](e){this[C]?this[S]+=1:this[S]+=e.length,this[b].push(e)}[Te](){return this[C]?--this[S]:this[S]-=this[b][0].length,this[b].shift()}[ye](e=!1){do;while(this[be](this[Te]())&&this[b].length);!e&&!this[b].length&&!this[h]&&this.emit(`drain`)}[be](e){return this.emit(`data`,e),this[y]}pipe(e,t){if(this[w])return e;this[E]=!1;let n=this[_];return t||={},e===de.stdout||e===de.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,n?t.end&&e.end():(this[x].push(t.proxyErrors?new Be(this,e,t):new ze(this,e,t)),this[T]?Pe(()=>this[Ce]()):this[Ce]()),e}unpipe(e){let t=this[x].find(t=>t.dest===e);t&&(this[x].length===1?(this[y]&&this[Ne]===0&&(this[y]=!1),this[x]=[]):this[x].splice(this[x].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let n=super.on(e,t);if(e===`data`)this[E]=!1,this[Ne]++,!this[x].length&&!this[y]&&this[Ce]();else if(e===`readable`&&this[S]!==0)super.emit(`readable`);else if(Ie(e)&&this[_])super.emit(e),this.removeAllListeners(e);else if(e===`error`&&this[ge]){let e=t;this[T]?Pe(()=>e.call(this,this[ge])):e.call(this,this[ge])}return n}removeListener(e,t){return this.off(e,t)}off(e,t){let n=super.off(e,t);return e===`data`&&(this[Ne]=this.listeners(`data`).length,this[Ne]===0&&!this[E]&&!this[x].length&&(this[y]=!1)),n}removeAllListeners(e){let t=super.removeAllListeners(e);return(e===`data`||e===void 0)&&(this[Ne]=0,!this[E]&&!this[x].length&&(this[y]=!1)),t}get emittedEnd(){return this[_]}[g](){!this[he]&&!this[_]&&!this[w]&&this[b].length===0&&this[h]&&(this[he]=!0,this.emit(`end`),this.emit(`prefinish`),this.emit(`finish`),this[_e]&&this.emit(`close`),this[he]=!1)}emit(e,...t){let n=t[0];if(e!==`error`&&e!==`close`&&e!==w&&this[w])return!1;if(e===`data`)return!this[C]&&!n?!1:this[T]?(Pe(()=>this[De](n)),!0):this[De](n);if(e===`end`)return this[Oe]();if(e===`close`){if(this[_e]=!0,!this[_]&&!this[w])return!1;let e=super.emit(`close`);return this.removeAllListeners(`close`),e}else if(e===`error`){this[ge]=n,super.emit(Ee,n);let e=!this[Me]||this.listeners(`error`).length?super.emit(`error`,n):!1;return this[g](),e}else if(e===`resume`){let e=super.emit(`resume`);return this[g](),e}else if(e===`finish`||e===`prefinish`){let t=super.emit(e);return this.removeAllListeners(e),t}let r=super.emit(e,...t);return this[g](),r}[De](e){for(let t of this[x])t.dest.write(e)===!1&&this.pause();let t=this[E]?!1:super.emit(`data`,e);return this[g](),t}[Oe](){return this[_]?!1:(this[_]=!0,this.readable=!1,this[T]?(Pe(()=>this[ke]()),!0):this[ke]())}[ke](){if(this[xe]){let e=this[xe].end();if(e){for(let t of this[x])t.dest.write(e);this[E]||super.emit(`data`,e)}}for(let e of this[x])e.end();let e=super.emit(`end`);return this.removeAllListeners(`end`),e}async collect(){let e=Object.assign([],{dataLength:0});this[C]||(e.dataLength=0);let t=this.promise();return this.on(`data`,t=>{e.push(t),this[C]||(e.dataLength+=t.length)}),await t,e}async concat(){if(this[C])throw Error(`cannot concat in objectMode`);let e=await this.collect();return this[v]?e.join(``):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(w,()=>t(Error(`stream destroyed`))),this.on(`error`,e=>t(e)),this.on(`end`,()=>e())})}[Symbol.asyncIterator](){this[E]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[h])return t();let r,i,a=e=>{this.off(`data`,o),this.off(`end`,s),this.off(w,c),t(),i(e)},o=e=>{this.off(`error`,a),this.off(`end`,s),this.off(w,c),this.pause(),r({value:e,done:!!this[h]})},s=()=>{this.off(`error`,a),this.off(`data`,o),this.off(w,c),t(),r({done:!0,value:void 0})},c=()=>a(Error(`stream destroyed`));return new Promise((e,t)=>{i=t,r=e,this.once(w,c),this.once(`error`,a),this.once(`end`,s),this.once(`data`,o)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[E]=!1;let e=!1,t=()=>(this.pause(),this.off(Ee,t),this.off(w,t),this.off(`end`,t),e=!0,{done:!0,value:void 0});return this.once(`end`,t),this.once(Ee,t),this.once(w,t),{next:()=>{if(e)return t();let n=this.read();return n===null?t():{done:!1,value:n}},throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[w])return e?this.emit(`error`,e):this.emit(w),this;this[w]=!0,this[E]=!0,this[b].length=0,this[S]=0;let t=this;return typeof t.close==`function`&&!this[_e]&&t.close(),e?this.emit(`error`,e):this.emit(w),this}static get isStream(){return fe}},We=d.writev,D=Symbol(`_autoClose`),O=Symbol(`_close`),Ge=Symbol(`_ended`),k=Symbol(`_fd`),Ke=Symbol(`_finished`),A=Symbol(`_flags`),qe=Symbol(`_flush`),Je=Symbol(`_handleChunk`),Ye=Symbol(`_makeBuf`),Xe=Symbol(`_mode`),Ze=Symbol(`_needDrain`),Qe=Symbol(`_onerror`),$e=Symbol(`_onopen`),et=Symbol(`_onread`),tt=Symbol(`_onwrite`),j=Symbol(`_open`),M=Symbol(`_path`),nt=Symbol(`_pos`),N=Symbol(`_queue`),rt=Symbol(`_read`),it=Symbol(`_readSize`),P=Symbol(`_reading`),at=Symbol(`_remain`),ot=Symbol(`_size`),st=Symbol(`_write`),ct=Symbol(`_writing`),lt=Symbol(`_defaultFlag`),ut=Symbol(`_errored`),dt=class extends Ue{[ut]=!1;[k];[M];[it];[P]=!1;[ot];[at];[D];constructor(e,t){if(t||={},super(t),this.readable=!0,this.writable=!1,typeof e!=`string`)throw TypeError(`path must be a string`);this[ut]=!1,this[k]=typeof t.fd==`number`?t.fd:void 0,this[M]=e,this[it]=t.readSize||16*1024*1024,this[P]=!1,this[ot]=typeof t.size==`number`?t.size:1/0,this[at]=this[ot],this[D]=typeof t.autoClose==`boolean`?t.autoClose:!0,typeof this[k]==`number`?this[rt]():this[j]()}get fd(){return this[k]}get path(){return this[M]}write(){throw TypeError(`this is a readable stream`)}end(){throw TypeError(`this is a readable stream`)}[j](){d.open(this[M],`r`,(e,t)=>this[$e](e,t))}[$e](e,t){e?this[Qe](e):(this[k]=t,this.emit(`open`,t),this[rt]())}[Ye](){return Buffer.allocUnsafe(Math.min(this[it],this[at]))}[rt](){if(!this[P]){this[P]=!0;let e=this[Ye]();if(e.length===0)return process.nextTick(()=>this[et](null,0,e));d.read(this[k],e,0,e.length,null,(e,t,n)=>this[et](e,t,n))}}[et](e,t,n){this[P]=!1,e?this[Qe](e):this[Je](t,n)&&this[rt]()}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.close(e,e=>e?this.emit(`error`,e):this.emit(`close`))}}[Qe](e){this[P]=!0,this[O](),this.emit(`error`,e)}[Je](e,t){let n=!1;return this[at]-=e,e>0&&(n=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[at]<=0)&&(n=!1,this[O](),super.end()),n}emit(e,...t){switch(e){case`prefinish`:case`finish`:return!1;case`drain`:return typeof this[k]==`number`&&this[rt](),!1;case`error`:return this[ut]?!1:(this[ut]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},ft=class extends dt{[j](){let e=!0;try{this[$e](null,d.openSync(this[M],`r`)),e=!1}finally{e&&this[O]()}}[rt](){let e=!0;try{if(!this[P]){this[P]=!0;do{let e=this[Ye](),t=e.length===0?0:d.readSync(this[k],e,0,e.length,null);if(!this[Je](t,e))break}while(!0);this[P]=!1}e=!1}finally{e&&this[O]()}}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.closeSync(e),this.emit(`close`)}}},pt=class extends l{readable=!1;writable=!0;[ut]=!1;[ct]=!1;[Ge]=!1;[N]=[];[Ze]=!1;[M];[Xe];[D];[k];[lt];[A];[Ke]=!1;[nt];constructor(e,t){t||={},super(t),this[M]=e,this[k]=typeof t.fd==`number`?t.fd:void 0,this[Xe]=t.mode===void 0?438:t.mode,this[nt]=typeof t.start==`number`?t.start:void 0,this[D]=typeof t.autoClose==`boolean`?t.autoClose:!0;let n=this[nt]===void 0?`w`:`r+`;this[lt]=t.flags===void 0,this[A]=t.flags===void 0?n:t.flags,this[k]===void 0&&this[j]()}emit(e,...t){if(e===`error`){if(this[ut])return!1;this[ut]=!0}return super.emit(e,...t)}get fd(){return this[k]}get path(){return this[M]}[Qe](e){this[O](),this[ct]=!0,this.emit(`error`,e)}[j](){d.open(this[M],this[A],this[Xe],(e,t)=>this[$e](e,t))}[$e](e,t){this[lt]&&this[A]===`r+`&&e&&e.code===`ENOENT`?(this[A]=`w`,this[j]()):e?this[Qe](e):(this[k]=t,this.emit(`open`,t),this[ct]||this[qe]())}end(e,t){return e&&this.write(e,t),this[Ge]=!0,!this[ct]&&!this[N].length&&typeof this[k]==`number`&&this[tt](null,0),this}write(e,t){return typeof e==`string`&&(e=Buffer.from(e,t)),this[Ge]?(this.emit(`error`,Error(`write() after end()`)),!1):this[k]===void 0||this[ct]||this[N].length?(this[N].push(e),this[Ze]=!0,!1):(this[ct]=!0,this[st](e),!0)}[st](e){d.write(this[k],e,0,e.length,this[nt],(e,t)=>this[tt](e,t))}[tt](e,t){e?this[Qe](e):(this[nt]!==void 0&&typeof t==`number`&&(this[nt]+=t),this[N].length?this[qe]():(this[ct]=!1,this[Ge]&&!this[Ke]?(this[Ke]=!0,this[O](),this.emit(`finish`)):this[Ze]&&(this[Ze]=!1,this.emit(`drain`))))}[qe](){if(this[N].length===0)this[Ge]&&this[tt](null,0);else if(this[N].length===1)this[st](this[N].pop());else{let e=this[N];this[N]=[],We(this[k],e,this[nt],(e,t)=>this[tt](e,t))}}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.close(e,e=>e?this.emit(`error`,e):this.emit(`close`))}}},mt=class extends pt{[j](){let e;if(this[lt]&&this[A]===`r+`)try{e=d.openSync(this[M],this[A],this[Xe])}catch(e){if(e?.code===`ENOENT`)return this[A]=`w`,this[j]();throw e}else e=d.openSync(this[M],this[A],this[Xe]);this[$e](null,e)}[O](){if(this[D]&&typeof this[k]==`number`){let e=this[k];this[k]=void 0,d.closeSync(e),this.emit(`close`)}}[st](e){let t=!0;try{this[tt](null,d.writeSync(this[k],e,0,e.length,this[nt])),t=!1}finally{if(t)try{this[O]()}catch{}}}},ht=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`]]),gt=e=>!!e.sync&&!!e.file,_t=e=>!e.sync&&!!e.file,vt=e=>!!e.sync&&!e.file,yt=e=>!e.sync&&!e.file,bt=e=>!!e.file,xt=e=>ht.get(e)||e,St=(e={})=>{if(!e)return{};let t={};for(let[n,r]of Object.entries(e)){let e=xt(n);t[e]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},Ct=(e,t,n,r,i)=>Object.assign((a=[],o,s)=>{Array.isArray(a)&&(o=a,a={}),typeof o==`function`&&(s=o,o=void 0),o=o?Array.from(o):[];let c=St(a);if(i?.(c,o),gt(c)){if(typeof s==`function`)throw TypeError(`callback not supported for sync tar functions`);return e(c,o)}else if(_t(c)){let e=t(c,o);return s?e.then(()=>s(),s):e}else if(vt(c)){if(typeof s==`function`)throw TypeError(`callback not supported for sync tar functions`);return n(c,o)}else if(yt(c)){if(typeof s==`function`)throw TypeError(`callback only supported with file option`);return r(c,o)}throw Error(`impossible options??`)},{syncFile:e,asyncFile:t,syncNoFile:n,asyncNoFile:r,validate:i}),wt=ae.constants||{ZLIB_VERNUM:4736},F=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},wt)),Tt=re.concat,Et=Object.getOwnPropertyDescriptor(re,`concat`),Dt=e=>e,Ot=Et?.writable===!0||Et?.set!==void 0?e=>{re.concat=e?Dt:Tt}:e=>{},kt=Symbol(`_superWrite`),At=class extends Error{code;errno;constructor(e,t){super(`zlib: `+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||=`ZLIB_ERROR`,this.message=`zlib: `+e.message,Error.captureStackTrace(this,t??this.constructor)}get name(){return`ZlibError`}},jt=Symbol(`flushFlag`),Mt=class extends Ue{#e=!1;#t=!1;#n;#r;#i;#a;#o;get sawError(){return this.#e}get handle(){return this.#a}get flushFlag(){return this.#n}constructor(e,t){if(!e||typeof e!=`object`)throw TypeError(`invalid options for ZlibBase constructor`);if(super(e),this.#n=e.flush??0,this.#r=e.finishFlush??0,this.#i=e.fullFlushFlag??0,typeof ie[t]!=`function`)throw TypeError(`Compression method not supported: `+t);try{this.#a=new ie[t](e)}catch(e){throw new At(e,this.constructor)}this.#o=e=>{this.#e||(this.#e=!0,this.close(),this.emit(`error`,e))},this.#a?.on(`error`,e=>this.#o(new At(e))),this.once(`end`,()=>this.close)}close(){this.#a&&(this.#a.close(),this.#a=void 0,this.emit(`close`))}reset(){if(!this.#e)return ne(this.#a,`zlib binding closed`),this.#a.reset?.()}flush(e){this.ended||(typeof e!=`number`&&(e=this.#i),this.write(Object.assign(re.alloc(0),{[jt]:e})))}end(e,t,n){return typeof e==`function`&&(n=e,t=void 0,e=void 0),typeof t==`function`&&(n=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#r),this.#t=!0,super.end(n)}get ended(){return this.#t}[kt](e){return super.write(e)}write(e,t,n){if(typeof t==`function`&&(n=t,t=`utf8`),typeof e==`string`&&(e=re.from(e,t)),this.#e)return;ne(this.#a,`zlib binding closed`);let r=this.#a._handle,i=r.close;r.close=()=>{};let a=this.#a.close;this.#a.close=()=>{},Ot(!0);let o;try{let t=typeof e[jt]==`number`?e[jt]:this.#n;o=this.#a._processChunk(e,t),Ot(!1)}catch(e){Ot(!1),this.#o(new At(e,this.write))}finally{this.#a&&(this.#a._handle=r,r.close=i,this.#a.close=a,this.#a.removeAllListeners(`error`))}this.#a&&this.#a.on(`error`,e=>this.#o(new At(e,this.write)));let s;if(o)if(Array.isArray(o)&&o.length>0){let e=o[0];s=this[kt](re.from(e));for(let e=1;e<o.length;e++)s=this[kt](o[e])}else s=this[kt](re.from(o));return n&&n(),s}},Nt=class extends Mt{#e;#t;constructor(e,t){e||={},e.flush=e.flush||F.Z_NO_FLUSH,e.finishFlush=e.finishFlush||F.Z_FINISH,e.fullFlushFlag=F.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#t=e.strategy}params(e,t){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.#e!==e||this.#t!==t){this.flush(F.Z_SYNC_FLUSH),ne(this.handle,`zlib binding closed`);let n=this.handle.flush;this.handle.flush=(e,t)=>{typeof e==`function`&&(t=e,e=this.flushFlag),this.flush(e),t?.()};try{this.handle.params(e,t)}finally{this.handle.flush=n}this.handle&&(this.#e=e,this.#t=t)}}}},Pt=class extends Nt{#e;constructor(e){super(e,`Gzip`),this.#e=e&&!!e.portable}[kt](e){return this.#e?(this.#e=!1,e[9]=255,super[kt](e)):super[kt](e)}},Ft=class extends Nt{constructor(e){super(e,`Unzip`)}},It=class extends Mt{constructor(e,t){e||={},e.flush=e.flush||F.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||F.BROTLI_OPERATION_FINISH,e.fullFlushFlag=F.BROTLI_OPERATION_FLUSH,super(e,t)}},Lt=class extends It{constructor(e){super(e,`BrotliCompress`)}},Rt=class extends It{constructor(e){super(e,`BrotliDecompress`)}},zt=class extends Mt{constructor(e,t){e||={},e.flush=e.flush||F.ZSTD_e_continue,e.finishFlush=e.finishFlush||F.ZSTD_e_end,e.fullFlushFlag=F.ZSTD_e_flush,super(e,t)}},Bt=class extends zt{constructor(e){super(e,`ZstdCompress`)}},Vt=class extends zt{constructor(e){super(e,`ZstdDecompress`)}},Ht=(e,t)=>{if(Number.isSafeInteger(e))e<0?Wt(e,t):Ut(e,t);else throw Error(`cannot encode number outside of javascript safe integer range`);return t},Ut=(e,t)=>{t[0]=128;for(var n=t.length;n>1;n--)t[n-1]=e&255,e=Math.floor(e/256)},Wt=(e,t)=>{t[0]=255;var n=!1;e*=-1;for(var r=t.length;r>1;r--){var i=e&255;e=Math.floor(e/256),n?t[r-1]=Jt(i):i===0?t[r-1]=0:(n=!0,t[r-1]=Yt(i))}},Gt=e=>{let t=e[0],n=t===128?qt(e.subarray(1,e.length)):t===255?Kt(e):null;if(n===null)throw Error(`invalid base256 encoding`);if(!Number.isSafeInteger(n))throw Error(`parsed number outside of javascript safe integer range`);return n},Kt=e=>{for(var t=e.length,n=0,r=!1,i=t-1;i>-1;i--){var a=Number(e[i]),o;r?o=Jt(a):a===0?o=a:(r=!0,o=Yt(a)),o!==0&&(n-=o*256**(t-i-1))}return n},qt=e=>{for(var t=e.length,n=0,r=t-1;r>-1;r--){var i=Number(e[r]);i!==0&&(n+=i*256**(t-r-1))}return n},Jt=e=>(255^e)&255,Yt=e=>(255^e)+1&255,Xt={};ue(Xt,{code:()=>en,isCode:()=>Zt,isName:()=>Qt,name:()=>$t});var Zt=e=>$t.has(e),Qt=e=>en.has(e),$t=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`]]),en=new Map(Array.from($t).map(e=>[e[1],e[0]])),I=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e=`Unsupported`;linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,t=0,n,r){Buffer.isBuffer(e)?this.decode(e,t||0,n,r):e&&this.#t(e)}decode(e,t,n,r){if(t||=0,!e||!(e.length>=t+512))throw Error(`need 512 bytes for header`);this.path=n?.path??nn(e,t,100),this.mode=n?.mode??r?.mode??L(e,t+100,8),this.uid=n?.uid??r?.uid??L(e,t+108,8),this.gid=n?.gid??r?.gid??L(e,t+116,8),this.size=n?.size??r?.size??L(e,t+124,12),this.mtime=n?.mtime??r?.mtime??rn(e,t+136,12),this.cksum=L(e,t+148,12),r&&this.#t(r,!0),n&&this.#t(n);let i=nn(e,t+156,1);if(Zt(i)&&(this.#e=i||`0`),this.#e===`0`&&this.path.slice(-1)===`/`&&(this.#e=`5`),this.#e===`5`&&(this.size=0),this.linkpath=nn(e,t+157,100),e.subarray(t+257,t+265).toString()===`ustar\x0000`)if(this.uname=n?.uname??r?.uname??nn(e,t+265,32),this.gname=n?.gname??r?.gname??nn(e,t+297,32),this.devmaj=n?.devmaj??r?.devmaj??L(e,t+329,8)??0,this.devmin=n?.devmin??r?.devmin??L(e,t+337,8)??0,e[t+475]!==0)this.path=nn(e,t+345,155)+`/`+this.path;else{let i=nn(e,t+345,130);i&&(this.path=i+`/`+this.path),this.atime=n?.atime??r?.atime??rn(e,t+476,12),this.ctime=n?.ctime??r?.ctime??rn(e,t+488,12)}let a=256;for(let n=t;n<t+148;n++)a+=e[n];for(let n=t+156;n<t+512;n++)a+=e[n];this.cksumValid=a===this.cksum,this.cksum===void 0&&a===256&&(this.nullBlock=!0)}#t(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([e,n])=>!(n==null||e===`path`&&t||e===`linkpath`&&t||e===`global`))))}encode(e,t=0){if(e||=this.block=Buffer.alloc(512),this.#e===`Unsupported`&&(this.#e=`0`),!(e.length>=t+512))throw Error(`need 512 bytes for header`);let n=this.ctime||this.atime?130:155,r=tn(this.path||``,n),i=r[0],a=r[1];this.needPax=!!r[2],this.needPax=mn(e,t,100,i)||this.needPax,this.needPax=R(e,t+100,8,this.mode)||this.needPax,this.needPax=R(e,t+108,8,this.uid)||this.needPax,this.needPax=R(e,t+116,8,this.gid)||this.needPax,this.needPax=R(e,t+124,12,this.size)||this.needPax,this.needPax=fn(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=mn(e,t+157,100,this.linkpath)||this.needPax,e.write(`ustar\x0000`,t+257,8),this.needPax=mn(e,t+265,32,this.uname)||this.needPax,this.needPax=mn(e,t+297,32,this.gname)||this.needPax,this.needPax=R(e,t+329,8,this.devmaj)||this.needPax,this.needPax=R(e,t+337,8,this.devmin)||this.needPax,this.needPax=mn(e,t+345,n,a)||this.needPax,e[t+475]===0?(this.needPax=mn(e,t+345,130,a)||this.needPax,this.needPax=fn(e,t+476,12,this.atime)||this.needPax,this.needPax=fn(e,t+488,12,this.ctime)||this.needPax):this.needPax=mn(e,t+345,155,a)||this.needPax;let o=256;for(let n=t;n<t+148;n++)o+=e[n];for(let n=t+156;n<t+512;n++)o+=e[n];return this.cksum=o,R(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e===`Unsupported`?this.#e:$t.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(en.get(e));if(Zt(t)||t===`Unsupported`)this.#e=t;else if(Zt(e))this.#e=e;else throw TypeError(`invalid entry type: `+e)}},tn=(e,t)=>{let n=e,r=``,i,o=a.parse(e).root||`.`;if(Buffer.byteLength(n)<100)i=[n,r,!1];else{r=a.dirname(n),n=a.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(r)<=t?i=[n,r,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(r)<=t?i=[n.slice(0,99),r,!0]:(n=a.join(a.basename(r),n),r=a.dirname(r));while(r!==o&&i===void 0);i||=[e.slice(0,99),``,!0]}return i},nn=(e,t,n)=>e.subarray(t,t+n).toString(`utf8`).replace(/\0.*/,``),rn=(e,t,n)=>an(L(e,t,n)),an=e=>e===void 0?void 0:new Date(e*1e3),L=(e,t,n)=>Number(e[t])&128?Gt(e.subarray(t,t+n)):sn(e,t,n),on=e=>isNaN(e)?void 0:e,sn=(e,t,n)=>on(parseInt(e.subarray(t,t+n).toString(`utf8`).replace(/\0.*$/,``).trim(),8)),cn={12:8589934591,8:2097151},R=(e,t,n,r)=>r===void 0?!1:r>cn[n]||r<0?(Ht(r,e.subarray(t,t+n)),!0):(ln(e,t,n,r),!1),ln=(e,t,n,r)=>e.write(un(r,n),t,n,`ascii`),un=(e,t)=>dn(Math.floor(e).toString(8),t),dn=(e,t)=>(e.length===t-1?e:Array(t-e.length-1).join(`0`)+e+` `)+`\0`,fn=(e,t,n,r)=>r===void 0?!1:R(e,t,n,r.getTime()/1e3),pn=Array(156).join(`\0`),mn=(e,t,n,r)=>r===void 0?!1:(e.write(r+pn,t,n,`utf8`),r.length!==Buffer.byteLength(r)||r.length>n),hn=class e{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,t=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=t,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e===``)return Buffer.allocUnsafe(0);let t=Buffer.byteLength(e),n=512*Math.ceil(1+t/512),i=Buffer.allocUnsafe(n);for(let e=0;e<512;e++)i[e]=0;new I({path:(`PaxHeader/`+r(this.path??``)).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:t,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(i),i.write(e,512,t,`utf8`);for(let e=t+512;e<i.length;e++)i[e]=0;return i}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(e){if(this[e]===void 0)return``;let t=this[e],n=t instanceof Date?t.getTime()/1e3:t,r=` `+(e===`dev`||e===`ino`||e===`nlink`?`SCHILY.`:``)+e+`=`+n+`
|
|
3
|
-
`,i=Buffer.byteLength(r),a=Math.floor(Math.log(i)/Math.log(10))+1;return i+a>=10**a&&(a+=1),a+i+r}static parse(t,n,r=!1){return new e(gn(_n(t),n),r)}},gn=(e,t)=>t?Object.assign({},t,e):e,_n=e=>e.replace(/\n$/,``).split(`
|
|
4
|
-
`).reduce(vn,Object.create(null)),vn=(e,t)=>{let n=parseInt(t,10);if(n!==Buffer.byteLength(t)+1)return e;t=t.slice((n+` `).length);let r=t.split(`=`),i=r.shift();if(!i)return e;let a=i.replace(/^SCHILY\.(dev|ino|nlink)/,`$1`),o=r.join(`=`);return e[a]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(a)?new Date(Number(o)*1e3):/^[0-9]+$/.test(o)?+o:o,e},z=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`?e=>e&&e.replaceAll(/\\/g,`/`):e=>e,yn=class extends Ue{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(e,t,n){switch(super({}),this.pause(),this.extended=t,this.globalExtended=n,this.header=e,this.remain=e.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=e.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(!e.path)throw Error(`no path provided for tar.ReadEntry`);this.path=z(e.path),this.mode=e.mode,this.mode&&(this.mode&=4095),this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=this.remain,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?z(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),n&&this.#e(n,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw Error(`writing more to entry than is appropriate`);let n=this.remain,r=this.blockRemain;return this.remain=Math.max(0,n-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:n>=t?super.write(e):super.write(e.subarray(0,n))}#e(e,t=!1){e.path&&=z(e.path),e.linkpath&&=z(e.linkpath),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([e,n])=>!(n==null||e===`path`&&t))))}},bn=(e,t,n,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=n instanceof Error&&n.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(n instanceof Error&&(r=Object.assign(n,r),n=n.message),e.emit(`warn`,t,n,r)):n instanceof Error?e.emit(`error`,Object.assign(n,r)):e.emit(`error`,Object.assign(Error(`${t}: ${n}`),r))},xn=1024*1024,Sn=Buffer.from([31,139]),Cn=Buffer.from([40,181,47,253]),wn=Math.max(Sn.length,Cn.length),B=Symbol(`state`),Tn=Symbol(`writeEntry`),V=Symbol(`readEntry`),En=Symbol(`nextEntry`),Dn=Symbol(`processEntry`),H=Symbol(`extendedHeader`),On=Symbol(`globalExtendedHeader`),kn=Symbol(`meta`),An=Symbol(`emitMeta`),U=Symbol(`buffer`),W=Symbol(`queue`),G=Symbol(`ended`),jn=Symbol(`emittedEnd`),Mn=Symbol(`emit`),K=Symbol(`unzip`),Nn=Symbol(`consumeChunk`),Pn=Symbol(`consumeChunkSub`),Fn=Symbol(`consumeBody`),In=Symbol(`consumeMeta`),Ln=Symbol(`consumeHeader`),Rn=Symbol(`consuming`),zn=Symbol(`bufferConcat`),Bn=Symbol(`maybeEnd`),Vn=Symbol(`writing`),q=Symbol(`aborted`),Hn=Symbol(`onDone`),Un=Symbol(`sawValidEntry`),Wn=Symbol(`sawNullBlock`),Gn=Symbol(`sawEOF`),Kn=Symbol(`closeStream`),qn=()=>!0,Jn=class extends u{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[W]=[];[U];[V];[Tn];[B]=`begin`;[kn]=``;[H];[On];[G]=!1;[K];[q]=!1;[Un];[Wn]=!1;[Gn]=!1;[Vn]=!1;[Rn]=!1;[jn]=!1;constructor(e={}){super(),this.file=e.file||``,this.on(Hn,()=>{(this[B]===`begin`||this[Un]===!1)&&this.warn(`TAR_BAD_ARCHIVE`,`Unrecognized archive format`)}),e.ondone?this.on(Hn,e.ondone):this.on(Hn,()=>{this.emit(`prefinish`),this.emit(`finish`),this.emit(`end`)}),this.strict=!!e.strict,this.maxMetaEntrySize=e.maxMetaEntrySize||xn,this.filter=typeof e.filter==`function`?e.filter:qn;let t=e.file&&(e.file.endsWith(`.tar.br`)||e.file.endsWith(`.tbr`));this.brotli=!(e.gzip||e.zstd)&&e.brotli!==void 0?e.brotli:t?void 0:!1;let n=e.file&&(e.file.endsWith(`.tar.zst`)||e.file.endsWith(`.tzst`));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:n?!0:void 0,this.on(`end`,()=>this[Kn]()),typeof e.onwarn==`function`&&this.on(`warn`,e.onwarn),typeof e.onReadEntry==`function`&&this.on(`entry`,e.onReadEntry)}warn(e,t,n={}){bn(this,e,t,n)}[Ln](e,t){this[Un]===void 0&&(this[Un]=!1);let n;try{n=new I(e,t,this[H],this[On])}catch(e){return this.warn(`TAR_ENTRY_INVALID`,e)}if(n.nullBlock)this[Wn]?(this[Gn]=!0,this[B]===`begin`&&(this[B]=`header`),this[Mn](`eof`)):(this[Wn]=!0,this[Mn](`nullBlock`));else if(this[Wn]=!1,!n.cksumValid)this.warn(`TAR_ENTRY_INVALID`,`checksum failure`,{header:n});else if(!n.path)this.warn(`TAR_ENTRY_INVALID`,`path is required`,{header:n});else{let e=n.type;if(/^(Symbolic)?Link$/.test(e)&&!n.linkpath)this.warn(`TAR_ENTRY_INVALID`,`linkpath required`,{header:n});else if(!/^(Symbolic)?Link$/.test(e)&&!/^(Global)?ExtendedHeader$/.test(e)&&n.linkpath)this.warn(`TAR_ENTRY_INVALID`,`linkpath forbidden`,{header:n});else{let e=this[Tn]=new yn(n,this[H],this[On]);this[Un]||(e.remain?e.on(`end`,()=>{e.invalid||(this[Un]=!0)}):this[Un]=!0),e.meta?e.size>this.maxMetaEntrySize?(e.ignore=!0,this[Mn](`ignoredEntry`,e),this[B]=`ignore`,e.resume()):e.size>0&&(this[kn]=``,e.on(`data`,e=>this[kn]+=e),this[B]=`meta`):(this[H]=void 0,e.ignore=e.ignore||!this.filter(e.path,e),e.ignore?(this[Mn](`ignoredEntry`,e),this[B]=e.remain?`ignore`:`header`,e.resume()):(e.remain?this[B]=`body`:(this[B]=`header`,e.end()),this[V]?this[W].push(e):(this[W].push(e),this[En]())))}}}[Kn](){queueMicrotask(()=>this.emit(`close`))}[Dn](e){let t=!0;if(!e)this[V]=void 0,t=!1;else if(Array.isArray(e)){let[t,...n]=e;this.emit(t,...n)}else this[V]=e,this.emit(`entry`,e),e.emittedEnd||(e.on(`end`,()=>this[En]()),t=!1);return t}[En](){do;while(this[Dn](this[W].shift()));if(this[W].length===0){let e=this[V];!e||e.flowing||e.size===e.remain?this[Vn]||this.emit(`drain`):e.once(`drain`,()=>this.emit(`drain`))}}[Fn](e,t){let n=this[Tn];if(!n)throw Error(`attempt to consume body without entry??`);let r=n.blockRemain??0,i=r>=e.length&&t===0?e:e.subarray(t,t+r);return n.write(i),n.blockRemain||(this[B]=`header`,this[Tn]=void 0,n.end()),i.length}[In](e,t){let n=this[Tn],r=this[Fn](e,t);return!this[Tn]&&n&&this[An](n),r}[Mn](e,t,n){this[W].length===0&&!this[V]?this.emit(e,t,n):this[W].push([e,t,n])}[An](e){switch(this[Mn](`meta`,this[kn]),e.type){case`ExtendedHeader`:case`OldExtendedHeader`:this[H]=hn.parse(this[kn],this[H],!1);break;case`GlobalExtendedHeader`:this[On]=hn.parse(this[kn],this[On],!0);break;case`NextFileHasLongPath`:case`OldGnuLongPath`:{let e=this[H]??Object.create(null);this[H]=e,e.path=this[kn].replace(/\0.*/,``);break}case`NextFileHasLongLinkpath`:{let e=this[H]||Object.create(null);this[H]=e,e.linkpath=this[kn].replace(/\0.*/,``);break}default:throw Error(`unknown meta: `+e.type)}}abort(e){this[q]=!0,this.emit(`abort`,e),this.warn(`TAR_ABORT`,e,{recoverable:!1})}write(e,t,n){if(typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,typeof t==`string`?t:`utf8`)),this[q])return n?.(),!1;if((this[K]===void 0||this.brotli===void 0&&this[K]===!1)&&e){if(this[U]&&(e=Buffer.concat([this[U],e]),this[U]=void 0),e.length<wn)return this[U]=e,n?.(),!0;for(let t=0;this[K]===void 0&&t<Sn.length;t++)e[t]!==Sn[t]&&(this[K]=!1);let t=!1;if(this[K]===!1&&this.zstd!==!1){t=!0;for(let n=0;n<Cn.length;n++)if(e[n]!==Cn[n]){t=!1;break}}let r=this.brotli===void 0&&!t;if(this[K]===!1&&r)if(e.length<512)if(this[G])this.brotli=!0;else return this[U]=e,n?.(),!0;else try{new I(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[K]===void 0||this[K]===!1&&(this.brotli||t)){let r=this[G];this[G]=!1,this[K]=this[K]===void 0?new Ft({}):t?new Vt({}):new Rt({}),this[K].on(`data`,e=>this[Nn](e)),this[K].on(`error`,e=>this.abort(e)),this[K].on(`end`,()=>{this[G]=!0,this[Nn]()}),this[Vn]=!0;let i=!!this[K][r?`end`:`write`](e);return this[Vn]=!1,n?.(),i}}this[Vn]=!0,this[K]?this[K].write(e):this[Nn](e),this[Vn]=!1;let r=this[W].length>0?!1:this[V]?this[V].flowing:!0;return!r&&this[W].length===0&&this[V]?.once(`drain`,()=>this.emit(`drain`)),n?.(),r}[zn](e){e&&!this[q]&&(this[U]=this[U]?Buffer.concat([this[U],e]):e)}[Bn](){if(this[G]&&!this[jn]&&!this[q]&&!this[Rn]){this[jn]=!0;let e=this[Tn];if(e&&e.blockRemain){let t=this[U]?this[U].length:0;this.warn(`TAR_BAD_ARCHIVE`,`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[U]&&e.write(this[U]),e.end()}this[Mn](Hn)}}[Nn](e){if(this[Rn]&&e)this[zn](e);else if(!e&&!this[U])this[Bn]();else if(e){if(this[Rn]=!0,this[U]){this[zn](e);let t=this[U];this[U]=void 0,this[Pn](t)}else this[Pn](e);for(;this[U]&&this[U]?.length>=512&&!this[q]&&!this[Gn];){let e=this[U];this[U]=void 0,this[Pn](e)}this[Rn]=!1}(!this[U]||this[G])&&this[Bn]()}[Pn](e){let t=0,n=e.length;for(;t+512<=n&&!this[q]&&!this[Gn];)switch(this[B]){case`begin`:case`header`:this[Ln](e,t),t+=512;break;case`ignore`:case`body`:t+=this[Fn](e,t);break;case`meta`:t+=this[In](e,t);break;default:throw Error(`invalid state: `+this[B])}t<n&&(this[U]=this[U]?Buffer.concat([e.subarray(t),this[U]]):e.subarray(t))}end(e,t,n){return typeof e==`function`&&(n=e,t=void 0,e=void 0),typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,t)),n&&this.once(`finish`,n),this[q]||(this[K]?(e&&this[K].write(e),this[K].end()):(this[G]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e||=Buffer.alloc(0)),e&&this.write(e),this[Bn]())),this}},Yn=e=>{let t=e.length-1,n=-1;for(;t>-1&&e.charAt(t)===`/`;)n=t,t--;return n===-1?e:e.slice(0,n)},Xn=e=>{let t=e.onReadEntry;e.onReadEntry=t?e=>{t(e),e.resume()}:e=>e.resume()},Zn=(e,t)=>{let n=new Map(t.map(e=>[Yn(e),!0])),r=e.filter,i=(e,t=``)=>{let r=t||te(e).root||`.`,a;if(e===r)a=!1;else{let t=n.get(e);a=t===void 0?i(m(e),r):t}return n.set(e,a),a};e.filter=r?(e,t)=>r(e,t)&&i(Yn(e)):e=>i(Yn(e))},Qn=Ct(e=>{let n=new Jn(e),r=e.file,i;try{i=t.openSync(r,`r`);let a=t.fstatSync(i),o=e.maxReadSize||16*1024*1024;if(a.size<o){let e=Buffer.allocUnsafe(a.size),r=t.readSync(i,e,0,a.size,0);n.end(r===e.byteLength?e:e.subarray(0,r))}else{let e=0,r=Buffer.allocUnsafe(o);for(;e<a.size;){let a=t.readSync(i,r,0,o,e);if(a===0)break;e+=a,n.write(r.subarray(0,a))}n.end()}}finally{if(typeof i==`number`)try{t.closeSync(i)}catch{}}},(e,n)=>{let r=new Jn(e),i=e.maxReadSize||16*1024*1024,a=e.file;return new Promise((e,n)=>{r.on(`error`,n),r.on(`end`,e),t.stat(a,(e,t)=>{if(e)n(e);else{let e=new dt(a,{readSize:i,size:t.size});e.on(`error`,n),e.pipe(r)}})})},e=>new Jn(e),e=>new Jn(e),(e,t)=>{t?.length&&Zn(e,t),e.noResume||Xn(e)}),$n=(e,t,n)=>(e&=4095,n&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),{isAbsolute:er,parse:tr}=o,nr=e=>{let t=``,n=tr(e);for(;er(e)||n.root;){let r=e.charAt(0)===`/`&&e.slice(0,4)!==`//?/`?`/`:n.root;e=e.slice(r.length),t+=r,n=tr(e)}return[t,e]},rr=[`|`,`<`,`>`,`?`,`:`],ir=rr.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),ar=new Map(rr.map((e,t)=>[e,ir[t]])),or=new Map(ir.map((e,t)=>[e,rr[t]])),sr=e=>rr.reduce((e,t)=>e.split(t).join(ar.get(t)),e),cr=e=>ir.reduce((e,t)=>e.split(t).join(or.get(t)),e),lr=(e,t)=>t?(e=z(e).replace(/^\.(\/|$)/,``),Yn(t)+`/`+e):z(e),ur=16*1024*1024,dr=Symbol(`process`),fr=Symbol(`file`),pr=Symbol(`directory`),mr=Symbol(`symlink`),hr=Symbol(`hardlink`),gr=Symbol(`header`),_r=Symbol(`read`),vr=Symbol(`lstat`),yr=Symbol(`onlstat`),br=Symbol(`onread`),xr=Symbol(`onreadlink`),Sr=Symbol(`openfile`),Cr=Symbol(`onopenfile`),J=Symbol(`close`),wr=Symbol(`mode`),Tr=Symbol(`awaitDrain`),Er=Symbol(`ondrain`),Y=Symbol(`prefix`),Dr=class extends Ue{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;#e=!1;constructor(e,t={}){let n=St(t);super(),this.path=z(e),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||ur,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=z(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?z(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn==`function`&&this.on(`warn`,n.onwarn);let r=!1;if(!this.preservePaths){let[e,t]=nr(this.path);e&&typeof t==`string`&&(this.path=t,r=e)}this.win32=!!n.win32||process.platform===`win32`,this.win32&&(this.path=cr(this.path.replaceAll(/\\/g,`/`)),e=e.replaceAll(/\\/g,`/`)),this.absolute=z(n.absolute||p.resolve(this.cwd,e)),this.path===``&&(this.path=`./`),r&&this.warn(`TAR_ENTRY_INFO`,`stripping ${r} from absolute path`,{entry:this,path:r+this.path});let i=this.statCache.get(this.absolute);i?this[yr](i):this[vr]()}warn(e,t,n={}){return bn(this,e,t,n)}emit(e,...t){return e===`error`&&(this.#e=!0),super.emit(e,...t)}[vr](){d.lstat(this.absolute,(e,t)=>{if(e)return this.emit(`error`,e);this[yr](t)})}[yr](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=Ar(e),this.emit(`stat`,e),this[dr]()}[dr](){switch(this.type){case`File`:return this[fr]();case`Directory`:return this[pr]();case`SymbolicLink`:return this[mr]();default:return this.end()}}[wr](e){return $n(e,this.type===`Directory`,this.portable)}[Y](e){return lr(e,this.prefix)}[gr](){if(!this.stat)throw Error(`cannot write header before stat`);this.type===`Directory`&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new I({path:this[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this[wr](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 hn({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[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](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 e=this.header?.block;if(!e)throw Error(`failed to encode header`);super.write(e)}[pr](){if(!this.stat)throw Error(`cannot create directory entry without stat`);this.path.slice(-1)!==`/`&&(this.path+=`/`),this.stat.size=0,this[gr](),this.end()}[mr](){d.readlink(this.absolute,(e,t)=>{if(e)return this.emit(`error`,e);this[xr](t)})}[xr](e){this.linkpath=z(e),this[gr](),this.end()}[hr](e){if(!this.stat)throw Error(`cannot create link entry without stat`);this.type=`Link`,this.linkpath=z(p.relative(this.cwd,e)),this.stat.size=0,this[gr](),this.end()}[fr](){if(!this.stat)throw Error(`cannot create file entry without stat`);if(this.stat.nlink>1){let e=`${this.stat.dev}:${this.stat.ino}`,t=this.linkCache.get(e);if(t?.indexOf(this.cwd)===0)return this[hr](t);this.linkCache.set(e,this.absolute)}if(this[gr](),this.stat.size===0)return this.end();this[Sr]()}[Sr](){d.open(this.absolute,`r`,(e,t)=>{if(e)return this.emit(`error`,e);this[Cr](t)})}[Cr](e){if(this.fd=e,this.#e)return this[J]();if(!this.stat)throw Error(`should stat before calling onopenfile`);this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let t=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(t),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[_r]()}[_r](){let{fd:e,buf:t,offset:n,length:r,pos:i}=this;if(e===void 0||t===void 0)throw Error(`cannot read file without first opening`);d.read(e,t,n,r,i,(e,t)=>{if(e)return this[J](()=>this.emit(`error`,e));this[br](t)})}[J](e=()=>{}){this.fd!==void 0&&d.close(this.fd,e)}[br](e){if(e<=0&&this.remain>0){let e=Object.assign(Error(`encountered unexpected EOF`),{path:this.absolute,syscall:`read`,code:`EOF`});return this[J](()=>this.emit(`error`,e))}if(e>this.remain){let e=Object.assign(Error(`did not encounter expected EOF`),{path:this.absolute,syscall:`read`,code:`EOF`});return this[J](()=>this.emit(`error`,e))}if(!this.buf)throw Error(`should have created buffer prior to reading`);if(e===this.remain)for(let t=e;t<this.length&&e<this.blockRemain;t++)this.buf[t+this.offset]=0,e++,this.remain++;let t=this.offset===0&&e===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+e);this.write(t)?this[Er]():this[Tr](()=>this[Er]())}[Tr](e){this.once(`drain`,e)}write(e,t,n){if(typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,typeof t==`string`?t:`utf8`)),this.blockRemain<e.length){let e=Object.assign(Error(`writing more data than expected`),{path:this.absolute});return this.emit(`error`,e)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,n)}[Er](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[J](e=>e?this.emit(`error`,e):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[_r]()}},Or=class extends Dr{sync=!0;[vr](){this[yr](d.lstatSync(this.absolute))}[mr](){this[xr](d.readlinkSync(this.absolute))}[Sr](){this[Cr](d.openSync(this.absolute,`r`))}[_r](){let e=!0;try{let{fd:t,buf:n,offset:r,length:i,pos:a}=this;if(t===void 0||n===void 0)throw Error(`fd and buf must be set in READ method`);let o=d.readSync(t,n,r,i,a);this[br](o),e=!1}finally{if(e)try{this[J](()=>{})}catch{}}}[Tr](e){e()}[J](e=()=>{}){this.fd!==void 0&&d.closeSync(this.fd),e()}},kr=class extends Ue{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(e,t,n={}){return bn(this,e,t,n)}constructor(e,t={}){let n=St(t);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r===`Unsupported`)throw Error(`writing entry that should be ignored`);this.type=r,this.type===`Directory`&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=z(e.path),this.mode=e.mode===void 0?void 0:this[wr](e.mode),this.uid=this.portable?void 0:e.uid,this.gid=this.portable?void 0:e.gid,this.uname=this.portable?void 0:e.uname,this.gname=this.portable?void 0:e.gname,this.size=e.size,this.mtime=this.noMtime?void 0:n.mtime||e.mtime,this.atime=this.portable?void 0:e.atime,this.ctime=this.portable?void 0:e.ctime,this.linkpath=e.linkpath===void 0?void 0:z(e.linkpath),typeof n.onwarn==`function`&&this.on(`warn`,n.onwarn);let i=!1;if(!this.preservePaths){let[e,t]=nr(this.path);e&&typeof t==`string`&&(this.path=t,i=e)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new I({path:this[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](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}),i&&this.warn(`TAR_ENTRY_INFO`,`stripping ${i} from absolute path`,{entry:this,path:i+this.path}),this.header.encode()&&!this.noPax&&super.write(new hn({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[Y](this.path),linkpath:this.type===`Link`&&this.linkpath!==void 0?this[Y](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 a=this.header?.block;if(!a)throw Error(`failed to encode header`);super.write(a),e.pipe(this)}[Y](e){return lr(e,this.prefix)}[wr](e){return $n(e,this.type===`Directory`,this.portable)}write(e,t,n){typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,typeof t==`string`?t:`utf8`));let r=e.length;if(r>this.blockRemain)throw Error(`writing more to entry than is appropriate`);return this.blockRemain-=r,super.write(e,n)}end(e,t,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e==`function`&&(n=e,t=void 0,e=void 0),typeof t==`function`&&(n=t,t=void 0),typeof e==`string`&&(e=Buffer.from(e,t??`utf8`)),n&&this.once(`finish`,n),e?super.end(e,n):super.end(n),this}},Ar=e=>e.isFile()?`File`:e.isDirectory()?`Directory`:e.isSymbolicLink()?`SymbolicLink`:`Unsupported`,jr=class e{tail;head;length=0;static create(t=[]){return new e(t)}constructor(e=[]){for(let t of e)this.push(t)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw Error(`removing node which does not belong to this list`);let t=e.next,n=e.prev;return t&&(t.prev=n),n&&(n.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=n),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,t}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let t=this.head;e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||=e,this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||=e,this.length++}push(...e){for(let t=0,n=e.length;t<n;t++)Nr(this,e[t]);return this.length}unshift(...e){for(var t=0,n=e.length;t<n;t++)Pr(this,e[t]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,t=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,t.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,t=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,t.list=void 0,this.length--,e}forEach(e,t){t||=this;for(let n=this.head,r=0;n;r++)e.call(t,n.value,r,this),n=n.next}forEachReverse(e,t){t||=this;for(let n=this.tail,r=this.length-1;n;r--)e.call(t,n.value,r,this),n=n.prev}get(e){let t=0,n=this.head;for(;n&&t<e;t++)n=n.next;if(t===e&&n)return n.value}getReverse(e){let t=0,n=this.tail;for(;n&&t<e;t++)n=n.prev;if(t===e&&n)return n.value}map(t,n){n||=this;let r=new e;for(let e=this.head;e;)r.push(t.call(n,e.value,this)),e=e.next;return r}mapReverse(t,n){n||=this;var r=new e;for(let e=this.tail;e;)r.push(t.call(n,e.value,this)),e=e.prev;return r}reduce(e,t){let n,r=this.head;if(arguments.length>1)n=t;else if(this.head)r=this.head.next,n=this.head.value;else throw TypeError(`Reduce of empty list with no initial value`);for(var i=0;r;i++)n=e(n,r.value,i),r=r.next;return n}reduceReverse(e,t){let n,r=this.tail;if(arguments.length>1)n=t;else if(this.tail)r=this.tail.prev,n=this.tail.value;else throw TypeError(`Reduce of empty list with no initial value`);for(let t=this.length-1;r;t--)n=e(n,r.value,t),r=r.prev;return n}toArray(){let e=Array(this.length);for(let t=0,n=this.head;n;t++)e[t]=n.value,n=n.next;return e}toArrayReverse(){let e=Array(this.length);for(let t=0,n=this.tail;n;t++)e[t]=n.value,n=n.prev;return e}slice(t=0,n=this.length){n<0&&(n+=this.length),t<0&&(t+=this.length);let r=new e;if(n<t||n<0)return r;t<0&&(t=0),n>this.length&&(n=this.length);let i=this.head,a=0;for(a=0;i&&a<t;a++)i=i.next;for(;i&&a<n;a++,i=i.next)r.push(i.value);return r}sliceReverse(t=0,n=this.length){n<0&&(n+=this.length),t<0&&(t+=this.length);let r=new e;if(n<t||n<0)return r;t<0&&(t=0),n>this.length&&(n=this.length);let i=this.length,a=this.tail;for(;a&&i>n;i--)a=a.prev;for(;a&&i>t;i--,a=a.prev)r.push(a.value);return r}splice(e,t=0,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let r=this.head;for(let t=0;r&&t<e;t++)r=r.next;let i=[];for(let e=0;r&&e<t;e++)i.push(r.value),r=this.removeNode(r);r?r!==this.tail&&(r=r.prev):r=this.tail;for(let e of n)r=Mr(this,r,e);return i}reverse(){let e=this.head,t=this.tail;for(let t=e;t;t=t.prev){let e=t.prev;t.prev=t.next,t.next=e}return this.head=t,this.tail=e,this}};function Mr(e,t,n){let r=new Fr(n,t,t?t.next:e.head,e);return r.next===void 0&&(e.tail=r),r.prev===void 0&&(e.head=r),e.length++,r}function Nr(e,t){e.tail=new Fr(t,e.tail,void 0,e),e.head||=e.tail,e.length++}function Pr(e,t){e.head=new Fr(t,void 0,e.head,e),e.tail||=e.head,e.length++}var Fr=class{list;next;prev;value;constructor(e,t,n,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},Ir=class{path;absolute;entry;stat;readdir;pending=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||`./`,this.absolute=t}},Lr=Buffer.alloc(1024),Rr=Symbol(`onStat`),zr=Symbol(`ended`),X=Symbol(`queue`),Br=Symbol(`current`),Vr=Symbol(`process`),Hr=Symbol(`processing`),Ur=Symbol(`processJob`),Z=Symbol(`jobs`),Wr=Symbol(`jobDone`),Gr=Symbol(`addFSEntry`),Kr=Symbol(`addTarEntry`),qr=Symbol(`stat`),Jr=Symbol(`readdir`),Yr=Symbol(`onreaddir`),Xr=Symbol(`pipe`),Zr=Symbol(`entry`),Qr=Symbol(`entryOpt`),$r=Symbol(`writeEntryClass`),ei=Symbol(`write`),ti=Symbol(`ondrain`),ni=class extends Ue{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[$r];onWriteEntry;[X];[Z]=0;[Hr]=!1;[zr]=!1;constructor(e={}){if(super(),this.opt=e,this.file=e.file||``,this.cwd=e.cwd||process.cwd(),this.maxReadSize=e.maxReadSize,this.preservePaths=!!e.preservePaths,this.strict=!!e.strict,this.noPax=!!e.noPax,this.prefix=z(e.prefix||``),this.linkCache=e.linkCache||new Map,this.statCache=e.statCache||new Map,this.readdirCache=e.readdirCache||new Map,this.onWriteEntry=e.onWriteEntry,this[$r]=Dr,typeof e.onwarn==`function`&&this.on(`warn`,e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if(+!!e.gzip+ +!!e.brotli+ +!!e.zstd>1)throw TypeError(`gzip, brotli, zstd are mutually exclusive`);if(e.gzip&&(typeof e.gzip!=`object`&&(e.gzip={}),this.portable&&(e.gzip.portable=!0),this.zip=new Pt(e.gzip)),e.brotli&&(typeof e.brotli!=`object`&&(e.brotli={}),this.zip=new Lt(e.brotli)),e.zstd&&(typeof e.zstd!=`object`&&(e.zstd={}),this.zip=new Bt(e.zstd)),!this.zip)throw Error(`impossible`);let t=this.zip;t.on(`data`,e=>super.write(e)),t.on(`end`,()=>super.end()),t.on(`drain`,()=>this[ti]()),this.on(`resume`,()=>t.resume())}else this.on(`drain`,this[ti]);this.noDirRecurse=!!e.noDirRecurse,this.follow=!!e.follow,this.noMtime=!!e.noMtime,e.mtime&&(this.mtime=e.mtime),this.filter=typeof e.filter==`function`?e.filter:()=>!0,this[X]=new jr,this[Z]=0,this.jobs=Number(e.jobs)||4,this[Hr]=!1,this[zr]=!1}[ei](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,n){return typeof e==`function`&&(n=e,e=void 0),typeof t==`function`&&(n=t,t=void 0),e&&this.add(e),this[zr]=!0,this[Vr](),n&&n(),this}write(e){if(this[zr])throw Error(`write after end`);return e instanceof yn?this[Kr](e):this[Gr](e),this.flowing}[Kr](e){let t=z(p.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let n=new Ir(e.path,t);n.entry=new kr(e,this[Qr](n)),n.entry.on(`end`,()=>this[Wr](n)),this[Z]+=1,this[X].push(n)}this[Vr]()}[Gr](e){let t=z(p.resolve(this.cwd,e));this[X].push(new Ir(e,t)),this[Vr]()}[qr](e){e.pending=!0,this[Z]+=1,d[this.follow?`stat`:`lstat`](e.absolute,(t,n)=>{e.pending=!1,--this[Z],t?this.emit(`error`,t):this[Rr](e,n)})}[Rr](e,t){this.statCache.set(e.absolute,t),e.stat=t,this.filter(e.path,t)?t.isFile()&&t.nlink>1&&e===this[Br]&&!this.linkCache.get(`${t.dev}:${t.ino}`)&&!this.sync&&this[Ur](e):e.ignore=!0,this[Vr]()}[Jr](e){e.pending=!0,this[Z]+=1,d.readdir(e.absolute,(t,n)=>{if(e.pending=!1,--this[Z],t)return this.emit(`error`,t);this[Yr](e,n)})}[Yr](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[Vr]()}[Vr](){if(!this[Hr]){this[Hr]=!0;for(let e=this[X].head;e&&this[Z]<this.jobs;e=e.next)if(this[Ur](e.value),e.value.ignore){let t=e.next;this[X].removeNode(e),e.next=t}this[Hr]=!1,this[zr]&&this[X].length===0&&this[Z]===0&&(this.zip?this.zip.end(Lr):(super.write(Lr),super.end()))}}get[Br](){return this[X]&&this[X].head&&this[X].head.value}[Wr](e){this[X].shift(),--this[Z],this[Vr]()}[Ur](e){if(!e.pending){if(e.entry){e===this[Br]&&!e.piped&&this[Xr](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[Rr](e,t):this[qr](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[Yr](e,t):this[Jr](e),!e.readdir)return}if(e.entry=this[Zr](e),!e.entry){e.ignore=!0;return}e===this[Br]&&!e.piped&&this[Xr](e)}}}[Qr](e){return{onwarn:(e,t,n)=>this.warn(e,t,n),noPax:this.noPax,cwd:this.cwd,absolute:e.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}}[Zr](e){this[Z]+=1;try{return new this[$r](e.path,this[Qr](e)).on(`end`,()=>this[Wr](e)).on(`error`,e=>this.emit(`error`,e))}catch(e){this.emit(`error`,e)}}[ti](){this[Br]&&this[Br].entry&&this[Br].entry.resume()}[Xr](e){e.piped=!0,e.readdir&&e.readdir.forEach(t=>{let n=e.path,r=n===`./`?``:n.replace(/\/*$/,`/`);this[Gr](r+t)});let t=e.entry,n=this.zip;if(!t)throw Error(`cannot pipe without source`);n?t.on(`data`,e=>{n.write(e)||t.pause()}):t.on(`data`,e=>{super.write(e)||t.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,t,n={}){bn(this,e,t,n)}},ri=class extends ni{sync=!0;constructor(e){super(e),this[$r]=Or}pause(){}resume(){}[qr](e){let t=this.follow?`statSync`:`lstatSync`;this[Rr](e,d[t](e.absolute))}[Jr](e){this[Yr](e,d.readdirSync(e.absolute))}[Xr](e){let t=e.entry,n=this.zip;if(e.readdir&&e.readdir.forEach(t=>{let n=e.path,r=n===`./`?``:n.replace(/\/*$/,`/`);this[Gr](r+t)}),!t)throw Error(`Cannot pipe without source`);n?t.on(`data`,e=>{n.write(e)}):t.on(`data`,e=>{super[ei](e)})}},ii=(e,t)=>{let n=new ri(e),r=new mt(e.file,{mode:e.mode||438});n.pipe(r),oi(n,t)},ai=(e,t)=>{let n=new ni(e),r=new pt(e.file,{mode:e.mode||438});n.pipe(r);let i=new Promise((e,t)=>{r.on(`error`,t),r.on(`close`,e),n.on(`error`,t)});return si(n,t).catch(e=>n.emit(`error`,e)),i},oi=(e,t)=>{t.forEach(t=>{t.charAt(0)===`@`?Qn({file:n.resolve(e.cwd,t.slice(1)),sync:!0,noResume:!0,onReadEntry:t=>e.add(t)}):e.add(t)}),e.end()},si=async(e,t)=>{for(let r of t)r.charAt(0)===`@`?await Qn({file:n.resolve(String(e.cwd),r.slice(1)),noResume:!0,onReadEntry:t=>{e.add(t)}}):e.add(r);e.end()},ci=Ct(ii,ai,(e,t)=>{let n=new ri(e);return oi(n,t),n},(e,t)=>{let n=new ni(e);return si(n,t).catch(e=>n.emit(`error`,e)),n},(e,t)=>{if(!t?.length)throw TypeError(`no paths specified to add to archive`)}),li=(process.env.__FAKE_PLATFORM__||process.platform)===`win32`,{O_CREAT:ui,O_NOFOLLOW:di,O_TRUNC:fi,O_WRONLY:pi}=d.constants,mi=Number(process.env.__FAKE_FS_O_FILENAME__)||d.constants.UV_FS_O_FILEMAP||0,hi=li&&!!mi,gi=512*1024,_i=mi|fi|ui|pi,vi=!li&&typeof di==`number`?di|fi|ui|pi:null,yi=vi===null?hi?e=>e<gi?_i:`w`:()=>`w`:()=>vi,bi=(e,n,r)=>{try{return t.lchownSync(e,n,r)}catch(e){if(e?.code!==`ENOENT`)throw e}},xi=(e,n,r,i)=>{t.lchown(e,n,r,e=>{i(e&&e?.code!==`ENOENT`?e:null)})},Si=(e,t,r,i,a)=>{t.isDirectory()?Ci(n.resolve(e,t.name),r,i,o=>{if(o)return a(o);xi(n.resolve(e,t.name),r,i,a)}):xi(n.resolve(e,t.name),r,i,a)},Ci=(e,n,r,i)=>{t.readdir(e,{withFileTypes:!0},(t,a)=>{if(t){if(t.code===`ENOENT`)return i();if(t.code!==`ENOTDIR`&&t.code!==`ENOTSUP`)return i(t)}if(t||!a.length)return xi(e,n,r,i);let o=a.length,s=null,c=t=>{if(!s){if(t)return i(s=t);if(--o===0)return xi(e,n,r,i)}};for(let t of a)Si(e,t,n,r,c)})},wi=(e,t,r,i)=>{t.isDirectory()&&Ti(n.resolve(e,t.name),r,i),bi(n.resolve(e,t.name),r,i)},Ti=(e,n,r)=>{let i;try{i=t.readdirSync(e,{withFileTypes:!0})}catch(t){let i=t;if(i?.code===`ENOENT`)return;if(i?.code===`ENOTDIR`||i?.code===`ENOTSUP`)return bi(e,n,r);throw i}for(let t of i)wi(e,t,n,r);return bi(e,n,r)},Ei=class extends Error{path;code;syscall=`chdir`;constructor(e,t){super(`${t}: Cannot cd into '${e}'`),this.path=e,this.code=t}get name(){return`CwdError`}},Di=class extends Error{path;symlink;syscall=`symlink`;code=`TAR_SYMLINK_ERROR`;constructor(e,t){super(`TAR_SYMLINK_ERROR: Cannot extract through symbolic link`),this.symlink=e,this.path=t}get name(){return`SymlinkError`}},Oi=(e,n)=>{t.stat(e,(t,r)=>{(t||!r.isDirectory())&&(t=new Ei(e,t?.code||`ENOTDIR`)),n(t)})},ki=(e,r,i)=>{e=z(e);let a=r.umask??18,o=r.mode|448,c=(o&a)!==0,l=r.uid,u=r.gid,d=typeof l==`number`&&typeof u==`number`&&(l!==r.processUid||u!==r.processGid),f=r.preserve,ee=r.unlink,p=z(r.cwd),m=(n,r)=>{n?i(n):r&&d?Ci(r,l,u,e=>m(e)):c?t.chmod(e,o,i):i()};if(e===p)return Oi(e,m);if(f)return s.mkdir(e,{mode:o,recursive:!0}).then(e=>m(null,e??void 0),m);Ai(p,z(n.relative(p,e)).split(`/`),o,ee,p,void 0,m)},Ai=(e,r,i,a,o,s,c)=>{if(r.length===0)return c(null,s);let l=r.shift(),u=z(n.resolve(e+`/`+l));t.mkdir(u,i,ji(u,r,i,a,o,s,c))},ji=(e,n,r,i,a,o,s)=>c=>{c?t.lstat(e,(l,u)=>{if(l)l.path=l.path&&z(l.path),s(l);else if(u.isDirectory())Ai(e,n,r,i,a,o,s);else if(i)t.unlink(e,c=>{if(c)return s(c);t.mkdir(e,r,ji(e,n,r,i,a,o,s))});else{if(u.isSymbolicLink())return s(new Di(e,e+`/`+n.join(`/`)));s(c)}}):(o||=e,Ai(e,n,r,i,a,o,s))},Mi=e=>{let n=!1,r;try{n=t.statSync(e).isDirectory()}catch(e){r=e?.code}finally{if(!n)throw new Ei(e,r??`ENOTDIR`)}},Ni=(e,r)=>{e=z(e);let i=r.umask??18,a=r.mode|448,o=(a&i)!==0,s=r.uid,c=r.gid,l=typeof s==`number`&&typeof c==`number`&&(s!==r.processUid||c!==r.processGid),u=r.preserve,d=r.unlink,f=z(r.cwd),ee=n=>{n&&l&&Ti(n,s,c),o&&t.chmodSync(e,a)};if(e===f)return Mi(f),ee();if(u)return ee(t.mkdirSync(e,{mode:a,recursive:!0})??void 0);let p=z(n.relative(f,e)).split(`/`),m;for(let e=p.shift(),r=f;e&&(r+=`/`+e);e=p.shift()){r=z(n.resolve(r));try{t.mkdirSync(r,a),m||=r}catch{let e=t.lstatSync(r);if(e.isDirectory())continue;if(d){t.unlinkSync(r),t.mkdirSync(r,a),m||=r;continue}else if(e.isSymbolicLink())return new Di(r,r+`/`+p.join(`/`))}}return ee(m)},Pi=Object.create(null),Fi=1e4,Ii=new Set,Li=e=>{Ii.has(e)?Ii.delete(e):Pi[e]=e.normalize(`NFD`).toLocaleLowerCase(`en`).toLocaleUpperCase(`en`),Ii.add(e);let t=Pi[e],n=Ii.size-Fi;if(n>Fi/10){for(let e of Ii)if(Ii.delete(e),delete Pi[e],--n<=0)break}return t},Ri=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`,zi=e=>e.split(`/`).slice(0,-1).reduce((e,t)=>{let n=e.at(-1);return n!==void 0&&(t=i(n,t)),e.push(t||`/`),e},[]),Bi=class{#e=new Map;#t=new Map;#n=new Set;reserve(e,t){e=Ri?[`win32 parallelization disabled`]:e.map(e=>Yn(i(Li(e))));let n=new Set(e.map(e=>zi(e)).reduce((e,t)=>e.concat(t)));this.#t.set(t,{dirs:n,paths:e});for(let n of e){let e=this.#e.get(n);e?e.push(t):this.#e.set(n,[t])}for(let e of n){let n=this.#e.get(e);if(!n)this.#e.set(e,[new Set([t])]);else{let e=n.at(-1);e instanceof Set?e.add(t):n.push(new Set([t]))}}return this.#i(t)}#r(e){let t=this.#t.get(e);if(!t)throw Error(`function does not have any path reservations`);return{paths:t.paths.map(e=>this.#e.get(e)),dirs:[...t.dirs].map(e=>this.#e.get(e))}}check(e){let{paths:t,dirs:n}=this.#r(e);return t.every(t=>t&&t[0]===e)&&n.every(t=>t&&t[0]instanceof Set&&t[0].has(e))}#i(e){return this.#n.has(e)||!this.check(e)?!1:(this.#n.add(e),e(()=>this.#a(e)),!0)}#a(e){if(!this.#n.has(e))return!1;let t=this.#t.get(e);if(!t)throw Error(`invalid reservation`);let{paths:n,dirs:r}=t,i=new Set;for(let t of n){let n=this.#e.get(t);if(!n||n?.[0]!==e)continue;let r=n[1];if(!r){this.#e.delete(t);continue}if(n.shift(),typeof r==`function`)i.add(r);else for(let e of r)i.add(e)}for(let t of r){let n=this.#e.get(t),r=n?.[0];if(!(!n||!(r instanceof Set)))if(r.size===1&&n.length===1){this.#e.delete(t);continue}else if(r.size===1){n.shift();let e=n[0];typeof e==`function`&&i.add(e)}else r.delete(e)}return this.#n.delete(e),i.forEach(e=>this.#i(e)),!0}},Vi=()=>process.umask(),Hi=Symbol(`onEntry`),Ui=Symbol(`checkFs`),Wi=Symbol(`checkFs2`),Gi=Symbol(`isReusable`),Q=Symbol(`makeFs`),Ki=Symbol(`file`),qi=Symbol(`directory`),Ji=Symbol(`link`),Yi=Symbol(`symlink`),Xi=Symbol(`hardlink`),Zi=Symbol(`ensureNoSymlink`),Qi=Symbol(`unsupported`),$i=Symbol(`checkPath`),ea=Symbol(`stripAbsolutePath`),ta=Symbol(`mkdir`),$=Symbol(`onError`),na=Symbol(`pending`),ra=Symbol(`pend`),ia=Symbol(`unpend`),aa=Symbol(`ended`),oa=Symbol(`maybeClose`),sa=Symbol(`skip`),ca=Symbol(`doChown`),la=Symbol(`uid`),ua=Symbol(`gid`),da=Symbol(`checkedCwd`),fa=(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)===`win32`,pa=1024,ma=(e,n)=>{if(!fa)return t.unlink(e,n);let r=e+`.DELETE.`+se(16).toString(`hex`);t.rename(e,r,e=>{if(e)return n(e);t.unlink(r,n)})},ha=e=>{if(!fa)return t.unlinkSync(e);let n=e+`.DELETE.`+se(16).toString(`hex`);t.renameSync(e,n),t.unlinkSync(n)},ga=(e,t,n)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:n,_a=class extends Jn{[aa]=!1;[da]=!1;[na]=0;reservations=new Bi;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(e={}){if(e.ondone=()=>{this[aa]=!0,this[oa]()},super(e),this.transform=e.transform,this.chmod=!!e.chmod,typeof e.uid==`number`||typeof e.gid==`number`){if(typeof e.uid!=`number`||typeof e.gid!=`number`)throw TypeError(`cannot set owner without number uid and gid`);if(e.preserveOwner)throw TypeError(`cannot preserve owner in archive and also set owner explicitly`);this.uid=e.uid,this.gid=e.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=e.preserveOwner===void 0&&typeof e.uid!=`number`?!!(process.getuid&&process.getuid()===0):!!e.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 e.maxDepth==`number`?e.maxDepth:pa,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||fa,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=z(n.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask==`number`?e.processUmask:Vi():0,this.umask=typeof e.umask==`number`?e.umask:this.processUmask,this.dmode=e.dmode||511&~this.umask,this.fmode=e.fmode||438&~this.umask,this.on(`entry`,e=>this[Hi](e))}warn(e,t,n={}){return(e===`TAR_BAD_ARCHIVE`||e===`TAR_ABORT`)&&(n.recoverable=!1),super.warn(e,t,n)}[oa](){this[aa]&&this[na]===0&&(this.emit(`prefinish`),this.emit(`finish`),this.emit(`end`))}[ea](e,t){let r=e[t],{type:i}=e;if(!r||this.preservePaths)return!0;let[a,o]=nr(r),s=o.replaceAll(/\\/g,`/`).split(`/`);if(s.includes(`..`)||fa&&/^[a-z]:\.\.$/i.test(s[0]??``)){if(t===`path`||i===`Link`)return this.warn(`TAR_ENTRY_ERROR`,`${t} contains '..'`,{entry:e,[t]:r}),!1;let a=n.posix.dirname(e.path),o=n.posix.normalize(n.posix.join(a,s.join(`/`)));if(o.startsWith(`../`)||o===`..`)return this.warn(`TAR_ENTRY_ERROR`,`${t} escapes extraction directory`,{entry:e,[t]:r}),!1}return a&&(e[t]=String(o),this.warn(`TAR_ENTRY_INFO`,`stripping ${a} from absolute ${t}`,{entry:e,[t]:r})),!0}[$i](e){let t=z(e.path),r=t.split(`/`);if(this.strip){if(r.length<this.strip)return!1;if(e.type===`Link`){let t=z(String(e.linkpath)).split(`/`);if(t.length>=this.strip)e.linkpath=t.slice(this.strip).join(`/`);else return!1}r.splice(0,this.strip),e.path=r.join(`/`)}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn(`TAR_ENTRY_ERROR`,`path excessively deep`,{entry:e,path:t,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[ea](e,`path`)||!this[ea](e,`linkpath`))return!1;if(e.absolute=n.isAbsolute(e.path)?z(n.resolve(e.path)):z(n.resolve(this.cwd,e.path)),!this.preservePaths&&typeof e.absolute==`string`&&e.absolute.indexOf(this.cwd+`/`)!==0&&e.absolute!==this.cwd)return this.warn(`TAR_ENTRY_ERROR`,`path escaped extraction target`,{entry:e,path:z(e.path),resolvedPath:e.absolute,cwd:this.cwd}),!1;if(e.absolute===this.cwd&&e.type!==`Directory`&&e.type!==`GNUDumpDir`)return!1;if(this.win32){let{root:t}=n.win32.parse(String(e.absolute));e.absolute=t+sr(String(e.absolute).slice(t.length));let{root:r}=n.win32.parse(e.path);e.path=r+sr(e.path.slice(r.length))}return!0}[Hi](e){if(!this[$i](e))return e.resume();switch(oe.equal(typeof e.absolute,`string`),e.type){case`Directory`:case`GNUDumpDir`:e.mode&&(e.mode|=448);case`File`:case`OldFile`:case`ContiguousFile`:case`Link`:case`SymbolicLink`:return this[Ui](e);default:return this[Qi](e)}}[$](e,t){e.name===`CwdError`?this.emit(`error`,e):(this.warn(`TAR_ENTRY_ERROR`,e,{entry:t}),this[ia](),t.resume())}[ta](e,t,n){ki(z(e),{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:t},n)}[ca](e){return this.forceChown||this.preserveOwner&&(typeof e.uid==`number`&&e.uid!==this.processUid||typeof e.gid==`number`&&e.gid!==this.processGid)||typeof this.uid==`number`&&this.uid!==this.processUid||typeof this.gid==`number`&&this.gid!==this.processGid}[la](e){return ga(this.uid,e.uid,this.processUid)}[ua](e){return ga(this.gid,e.gid,this.processGid)}[Ki](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.fmode,i=new pt(String(e.absolute),{flags:yi(e.size),mode:r,autoClose:!1});i.on(`error`,r=>{i.fd&&t.close(i.fd,()=>{}),i.write=()=>!0,this[$](r,e),n()});let a=1,o=r=>{if(r){i.fd&&t.close(i.fd,()=>{}),this[$](r,e),n();return}--a===0&&i.fd!==void 0&&t.close(i.fd,t=>{t?this[$](t,e):this[ia](),n()})};i.on(`finish`,()=>{let n=String(e.absolute),r=i.fd;if(typeof r==`number`&&e.mtime&&!this.noMtime){a++;let i=e.atime||new Date,s=e.mtime;t.futimes(r,i,s,e=>e?t.utimes(n,i,s,t=>o(t&&e)):o())}if(typeof r==`number`&&this[ca](e)){a++;let i=this[la](e),s=this[ua](e);typeof i==`number`&&typeof s==`number`&&t.fchown(r,i,s,e=>e?t.chown(n,i,s,t=>o(t&&e)):o())}o()});let s=this.transform&&this.transform(e)||e;s!==e&&(s.on(`error`,t=>{this[$](t,e),n()}),e.pipe(s)),s.pipe(i)}[qi](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.dmode;this[ta](String(e.absolute),r,r=>{if(r){this[$](r,e),n();return}let i=1,a=()=>{--i===0&&(n(),this[ia](),e.resume())};e.mtime&&!this.noMtime&&(i++,t.utimes(String(e.absolute),e.atime||new Date,e.mtime,a)),this[ca](e)&&(i++,t.chown(String(e.absolute),Number(this[la](e)),Number(this[ua](e)),a)),a()})}[Qi](e){e.unsupported=!0,this.warn(`TAR_ENTRY_UNSUPPORTED`,`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[Yi](e,t){let r=z(n.relative(this.cwd,n.resolve(n.dirname(String(e.absolute)),String(e.linkpath)))).split(`/`);this[Zi](e,this.cwd,r,()=>this[Ji](e,String(e.linkpath),`symlink`,t),n=>{this[$](n,e),t()})}[Xi](e,t){let r=z(n.resolve(this.cwd,String(e.linkpath))),i=z(String(e.linkpath)).split(`/`);this[Zi](e,this.cwd,i,()=>this[Ji](e,r,`link`,t),n=>{this[$](n,e),t()})}[Zi](e,r,i,a,o){let s=i.shift();if(this.preservePaths||s===void 0)return a();let c=n.resolve(r,s);t.lstat(c,(t,r)=>{if(t)return a();if(r?.isSymbolicLink())return o(new Di(c,n.resolve(c,i.join(`/`))));this[Zi](e,c,i,a,o)})}[ra](){this[na]++}[ia](){this[na]--,this[oa]()}[sa](e){this[ia](),e.resume()}[Gi](e,t){return e.type===`File`&&!this.unlink&&t.isFile()&&t.nlink<=1&&!fa}[Ui](e){this[ra]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,t=>this[Wi](e,t))}[Wi](e,r){let i=e=>{r(e)},a=()=>{this[ta](this.cwd,this.dmode,t=>{if(t){this[$](t,e),i();return}this[da]=!0,o()})},o=()=>{if(e.absolute!==this.cwd){let t=z(n.dirname(String(e.absolute)));if(t!==this.cwd)return this[ta](t,this.dmode,t=>{if(t){this[$](t,e),i();return}s()})}s()},s=()=>{t.lstat(String(e.absolute),(n,r)=>{if(r&&(this.keep||this.newer&&r.mtime>(e.mtime??r.mtime))){this[sa](e),i();return}if(n||this[Gi](e,r))return this[Q](null,e,i);if(r.isDirectory()){if(e.type===`Directory`){let n=this.chmod&&e.mode&&(r.mode&4095)!==e.mode,a=t=>this[Q](t??null,e,i);return n?t.chmod(String(e.absolute),Number(e.mode),a):a()}if(e.absolute!==this.cwd)return t.rmdir(String(e.absolute),t=>this[Q](t??null,e,i))}if(e.absolute===this.cwd)return this[Q](null,e,i);ma(String(e.absolute),t=>this[Q](t??null,e,i))})};this[da]?o():a()}[Q](e,t,n){if(e){this[$](e,t),n();return}switch(t.type){case`File`:case`OldFile`:case`ContiguousFile`:return this[Ki](t,n);case`Link`:return this[Xi](t,n);case`SymbolicLink`:return this[Yi](t,n);case`Directory`:case`GNUDumpDir`:return this[qi](t,n)}}[Ji](e,n,r,i){t[r](n,String(e.absolute),t=>{t?this[$](t,e):(this[ia](),e.resume()),i()})}},va=e=>{try{return[null,e()]}catch(e){return[e,null]}},ya=class extends _a{sync=!0;[Q](e,t){return super[Q](e,t,()=>{})}[Ui](e){if(!this[da]){let t=this[ta](this.cwd,this.dmode);if(t)return this[$](t,e);this[da]=!0}if(e.absolute!==this.cwd){let t=z(n.dirname(String(e.absolute)));if(t!==this.cwd){let n=this[ta](t,this.dmode);if(n)return this[$](n,e)}}let[r,i]=va(()=>t.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[sa](e);if(r||this[Gi](e,i))return this[Q](null,e);if(i.isDirectory()){if(e.type===`Directory`){let[n]=this.chmod&&e.mode&&(i.mode&4095)!==e.mode?va(()=>{t.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[Q](n,e)}let[n]=va(()=>t.rmdirSync(String(e.absolute)));this[Q](n,e)}let[a]=e.absolute===this.cwd?[]:va(()=>ha(String(e.absolute)));this[Q](a,e)}[Ki](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.fmode,i=r=>{let i;try{t.closeSync(a)}catch(e){i=e}(r||i)&&this[$](r||i,e),n()},a;try{a=t.openSync(String(e.absolute),yi(e.size),r)}catch(e){return i(e)}let o=this.transform&&this.transform(e)||e;o!==e&&(o.on(`error`,t=>this[$](t,e)),e.pipe(o)),o.on(`data`,e=>{try{t.writeSync(a,e,0,e.length)}catch(e){i(e)}}),o.on(`end`,()=>{let n=null;if(e.mtime&&!this.noMtime){let r=e.atime||new Date,i=e.mtime;try{t.futimesSync(a,r,i)}catch(a){try{t.utimesSync(String(e.absolute),r,i)}catch{n=a}}}if(this[ca](e)){let r=this[la](e),i=this[ua](e);try{t.fchownSync(a,Number(r),Number(i))}catch(a){try{t.chownSync(String(e.absolute),Number(r),Number(i))}catch{n||=a}}}i(n)})}[qi](e,n){let r=typeof e.mode==`number`?e.mode&4095:this.dmode,i=this[ta](String(e.absolute),r);if(i){this[$](i,e),n();return}if(e.mtime&&!this.noMtime)try{t.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[ca](e))try{t.chownSync(String(e.absolute),Number(this[la](e)),Number(this[ua](e)))}catch{}n(),e.resume()}[ta](e,t){try{return Ni(z(e),{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:t})}catch(e){return e}}[Zi](e,r,i,a,o){if(this.preservePaths||i.length===0)return a();let s=r;for(let e of i){s=n.resolve(s,e);let[c,l]=va(()=>t.lstatSync(s));if(c)return a();if(l.isSymbolicLink())return o(new Di(s,n.resolve(r,i.join(`/`))))}a()}[Ji](e,n,r,i){let a=`${r}Sync`;try{t[a](n,String(e.absolute)),i(),e.resume()}catch(t){return this[$](t,e)}}},ba=Ct(e=>{let n=new ya(e),r=e.file,i=t.statSync(r);new ft(r,{readSize:e.maxReadSize||16*1024*1024,size:i.size}).pipe(n)},(e,n)=>{let r=new _a(e),i=e.maxReadSize||16*1024*1024,a=e.file;return new Promise((e,n)=>{r.on(`error`,n),r.on(`close`,e),t.stat(a,(e,t)=>{if(e)n(e);else{let e=new dt(a,{readSize:i,size:t.size});e.on(`error`,n),e.pipe(r)}})})},e=>new ya(e),e=>new _a(e),(e,t)=>{t?.length&&Zn(e,t)}),xa=(e,n)=>{let r=new ri(e),i=!0,a,o;try{try{a=t.openSync(e.file,`r+`)}catch(n){if(n?.code===`ENOENT`)a=t.openSync(e.file,`w+`);else throw n}let s=t.fstatSync(a),c=Buffer.alloc(512);t:for(o=0;o<s.size;o+=512){for(let e=0,n=0;e<512;e+=n){if(n=t.readSync(a,c,e,c.length-e,o+e),o===0&&c[0]===31&&c[1]===139)throw Error(`cannot append to compressed archives`);if(!n)break t}let n=new I(c);if(!n.cksumValid)break;let r=512*Math.ceil((n.size||0)/512);if(o+r+512>s.size)break;o+=r,e.mtimeCache&&n.mtime&&e.mtimeCache.set(String(n.path),n.mtime)}i=!1,Sa(e,r,o,a,n)}finally{if(i)try{t.closeSync(a)}catch{}}},Sa=(e,t,n,r,i)=>{let a=new mt(e.file,{fd:r,start:n});t.pipe(a),wa(t,i)},Ca=(e,n)=>{n=Array.from(n);let r=new ni(e),i=(n,r,i)=>{let a=(e,r)=>{e?t.close(n,t=>i(e)):i(null,r)},o=0;if(r===0)return a(null,0);let s=0,c=Buffer.alloc(512),l=(i,u)=>{if(i||u===void 0)return a(i);if(s+=u,s<512&&u)return t.read(n,c,s,c.length-s,o+s,l);if(o===0&&c[0]===31&&c[1]===139)return a(Error(`cannot append to compressed archives`));if(s<512)return a(null,o);let d=new I(c);if(!d.cksumValid)return a(null,o);let f=512*Math.ceil((d.size??0)/512);if(o+f+512>r||(o+=f+512,o>=r))return a(null,o);e.mtimeCache&&d.mtime&&e.mtimeCache.set(String(d.path),d.mtime),s=0,t.read(n,c,0,512,o,l)};t.read(n,c,0,512,o,l)};return new Promise((a,o)=>{r.on(`error`,o);let s=`r+`,c=(l,u)=>{if(l&&l.code===`ENOENT`&&s===`r+`)return s=`w+`,t.open(e.file,s,c);if(l||!u)return o(l);t.fstat(u,(s,c)=>{if(s)return t.close(u,()=>o(s));i(u,c.size,(t,i)=>{if(t)return o(t);let s=new pt(e.file,{fd:u,start:i});r.pipe(s),s.on(`error`,o),s.on(`close`,a),Ta(r,n)})})};t.open(e.file,s,c)})},wa=(e,t)=>{t.forEach(t=>{t.charAt(0)===`@`?Qn({file:n.resolve(e.cwd,t.slice(1)),sync:!0,noResume:!0,onReadEntry:t=>e.add(t)}):e.add(t)}),e.end()},Ta=async(e,t)=>{for(let r of t)r.charAt(0)===`@`?await Qn({file:n.resolve(String(e.cwd),r.slice(1)),noResume:!0,onReadEntry:t=>e.add(t)}):e.add(r);e.end()},Ea=Ct(xa,Ca,()=>{throw TypeError(`file is required`)},()=>{throw TypeError(`file is required`)},(e,t)=>{if(!bt(e))throw TypeError(`file is required`);if(e.gzip||e.brotli||e.zstd||e.file.endsWith(`.br`)||e.file.endsWith(`.tbr`))throw TypeError(`cannot append to compressed archives`);if(!t?.length)throw TypeError(`no paths specified to add/replace`)});Ct(Ea.syncFile,Ea.asyncFile,Ea.syncNoFile,Ea.asyncNoFile,(e,t=[])=>{Ea.validate?.(e,t),Da(e)});var Da=e=>{let t=e.filter;e.mtimeCache||=new Map,e.filter=t?(n,r)=>t(n,r)&&!((e.mtimeCache?.get(n)??r.mtime??0)>(r.mtime??0)):(t,n)=>!((e.mtimeCache?.get(t)??n.mtime??0)>(n.mtime??0))};export{ce as t};
|