@taco-ai/cli 0.2.3 → 0.2.4
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/dist/taco.mjs +17 -17
- package/lib/installSchtasks.ts +21 -20
- package/package.json +3 -3
package/dist/taco.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as Jn}from"node:child_process";import{existsSync as Ke,readFileSync as Wr}from"node:fs";import{createRequire as Xn}from"node:module";import{dirname as Qn,join as kt}from"node:path";import{spawn as Zn}from"node:child_process";import{existsSync as Ze,readFileSync as Kn}from"node:fs";import{createRequire as Vn}from"node:module";import{dirname as Ri,join as ge}from"node:path";import{fileURLToPath as Yn}from"node:url";var fe=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"],Wn={"darwin-arm64":"aarch64-apple-darwin","darwin-x64":"x86_64-apple-darwin","linux-x64":"x86_64-unknown-linux-gnu","linux-arm64":"aarch64-unknown-linux-gnu","win32-x64":"x86_64-pc-windows-msvc","win32-arm64":"aarch64-pc-windows-msvc"},Gn="@taco-ai/sidecar-";function Fr(){let e=$r();return{key:e,pkg:`${Gn}${e}`}}function Br(){return Wn[$r()]}function $r(){let e=process.platform,t=process.arch,i=`${e}-${t}`;if(fe.includes(i))return i;throw new Error(`unsupported platform ${e}/${t} (known: ${fe.join(", ")})`)}function De(){let e=Ri(Yn(import.meta.url));for(let t=0;t<8;t++){if(Ze(ge(e,"pnpm-workspace.yaml")))return e;let i=Ri(e);if(i===e)break;e=i}return null}function _t(e=De()){return e!==null&&process.env.TACO_SIDECAR_DEV!=="0"}function qn(e){let t=ge(e,"node_modules",".bin",process.platform==="win32"?"tsx.cmd":"tsx");return{program:Ze(t)?t:"tsx",args:[ge(e,"packages","sidecar","src","index.ts")],cwd:e}}function Ur(){let e=Vn(import.meta.url);for(let t of fe)try{let i=e.resolve(`@taco-ai/sidecar-${t}/package.json`),r=Ri(i),s=ge(r,"manifest.json");if(!Ze(s))continue;let n=JSON.parse(Kn(s,"utf8")),o=ge(r,"bin",n.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Ze(o))continue;let a=ge(r,"lib","index.mjs");if(!Ze(a))continue;return{nodeBin:o,bundle:a,resources:r,sidecarVersion:typeof n.sidecarVersion=="string"?n.sidecarVersion:null}}catch{}return null}function zr(){return Ur()?.sidecarVersion??null}function
|
|
1
|
+
import{spawn as Jn}from"node:child_process";import{existsSync as Ke,readFileSync as Wr}from"node:fs";import{createRequire as Xn}from"node:module";import{dirname as Qn,join as kt}from"node:path";import{spawn as Zn}from"node:child_process";import{existsSync as Ze,readFileSync as Kn}from"node:fs";import{createRequire as Vn}from"node:module";import{dirname as Ri,join as ge}from"node:path";import{fileURLToPath as Yn}from"node:url";var fe=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"],Wn={"darwin-arm64":"aarch64-apple-darwin","darwin-x64":"x86_64-apple-darwin","linux-x64":"x86_64-unknown-linux-gnu","linux-arm64":"aarch64-unknown-linux-gnu","win32-x64":"x86_64-pc-windows-msvc","win32-arm64":"aarch64-pc-windows-msvc"},Gn="@taco-ai/sidecar-";function Fr(){let e=$r();return{key:e,pkg:`${Gn}${e}`}}function Br(){return Wn[$r()]}function $r(){let e=process.platform,t=process.arch,i=`${e}-${t}`;if(fe.includes(i))return i;throw new Error(`unsupported platform ${e}/${t} (known: ${fe.join(", ")})`)}function De(){let e=Ri(Yn(import.meta.url));for(let t=0;t<8;t++){if(Ze(ge(e,"pnpm-workspace.yaml")))return e;let i=Ri(e);if(i===e)break;e=i}return null}function _t(e=De()){return e!==null&&process.env.TACO_SIDECAR_DEV!=="0"}function qn(e){let t=ge(e,"node_modules",".bin",process.platform==="win32"?"tsx.cmd":"tsx");return{program:Ze(t)?t:"tsx",args:[ge(e,"packages","sidecar","src","index.ts")],cwd:e}}function Ur(){let e=Vn(import.meta.url);for(let t of fe)try{let i=e.resolve(`@taco-ai/sidecar-${t}/package.json`),r=Ri(i),s=ge(r,"manifest.json");if(!Ze(s))continue;let n=JSON.parse(Kn(s,"utf8")),o=ge(r,"bin",n.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Ze(o))continue;let a=ge(r,"lib","index.mjs");if(!Ze(a))continue;return{nodeBin:o,bundle:a,resources:r,sidecarVersion:typeof n.sidecarVersion=="string"?n.sidecarVersion:null}}catch{}return null}function zr(){return Ur()?.sidecarVersion??null}function jr(e){let t=De(),i=e.forceDev===!0||_t(t),r,s;if(i&&t)r=qn(t),s=ge(t,"packages","sidecar","src");else{let a=Ur();if(!a)throw new Error(`no @taco-ai/sidecar-<platform> bundle installed. Run \`pnpm install\` on a supported platform (${fe.join(", ")}) or set TACO_SIDECAR_DEV=1.`);r={program:a.nodeBin,args:[a.bundle]},s=a.resources}let n={...process.env,...e.extraEnv??{},TACO_DAEMON_MODE:"1",TACO_SOCKET:e.socketPath,TACO_CONTROL_SOCKET:e.controlSocketPath,TACO_HOME:e.tacoHome,TACO_RUNTIME_DIR:e.runtimeDir,TACO_SIDECAR_RESOURCES:s};return{child:Zn(r.program,r.args,{cwd:r.cwd,env:n,detached:!0,stdio:["ignore","ignore","inherit"],...process.platform==="win32"?{windowsHide:!0}:{}}),dev:i}}function Ot(){let e=[process.env.TACO_SIDECAR_NODE,process.env.TACO_SIDECAR_BUNDLE,process.env.TACO_SIDECAR_RESOURCES];if(e.every(r=>r!==void 0)){let[r,s,n]=e;if(Ke(r)&&Ke(s))return{pkgDir:n,nodeBin:r,bundle:s,resources:n,daemonMode:Gr(s)}}let t=Xn(import.meta.url);for(let r of fe){let s;try{s=Qn(t.resolve(`@taco-ai/sidecar-${r}/package.json`))}catch{continue}let n=Hr(s);if(n)return n}let i=De();if(i!==null){let r=kt(i,"packages","sidecar","dist","runtime",Br()),s=Hr(r);if(s)return s}return null}function Hr(e){let t=kt(e,"manifest.json");if(!Ke(t))return null;let i;try{i=JSON.parse(Wr(t,"utf8"))}catch{return null}let r=kt(e,"bin",i.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Ke(r))return null;let s=kt(e,"lib","index.mjs");if(!Ke(s))return null;let n=i.daemonMode===!0?!0:Gr(s);return{pkgDir:e,nodeBin:r,bundle:s,resources:e,daemonMode:n}}function Gr(e){try{return Wr(e,"utf8").includes("TACO_DAEMON_MODE")}catch{return!1}}function H(e,t,i={}){return new Promise((r,s)=>{let n=Jn(e,t,{stdio:["ignore","pipe","pipe"]}),o=[],a=[];n.stdout.on("data",h=>o.push(h)),n.stderr.on("data",h=>a.push(h)),n.once("error",h=>s(h)),n.once("close",h=>{let l=Buffer.concat(o).toString("utf8"),c=Buffer.concat(a).toString("utf8"),d={code:h??-1,stdout:l,stderr:c};h===0||i.allowFailure===!0?r(d):s(new Error(`${e} ${t.join(" ")} exited ${h}: ${c.trim()}`))})})}import{writeFileSync as Zr}from"node:fs";import{connect as eo}from"node:net";import{homedir as to}from"node:os";import{join as Kr}from"node:path";var Vr="com.taco-ai.sidecar";function _i(){return Kr(to(),"Library","LaunchAgents",`${Vr}.plist`)}function io(e){return Kr(e,"bin","taco-sidecar-daemon")}function Tt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ve(e){return`'${e.replace(/'/g,"'\\''")}'`}function ro(e){return`#!/bin/sh
|
|
2
2
|
# Generated by 'taco install' \u2014 do not edit.
|
|
3
3
|
set -e
|
|
4
4
|
|
|
@@ -40,7 +40,7 @@ exec "$NODE_BIN" "$BUNDLE"
|
|
|
40
40
|
</dict>
|
|
41
41
|
</dict>
|
|
42
42
|
</plist>
|
|
43
|
-
`}function no(e,t){let i=Date.now()+t;return new Promise((r,s)=>{let n=()=>{let o=eo(e),a=h=>{o.removeAllListeners(),o.destroy(),h?s(h):r()};o.once("connect",()=>a()),o.once("error",h=>{Date.now()>=i?a(new Error(`socket ${e} not ready in ${t}ms (${h.message})`)):setTimeout(n,100)})};n()})}async function Yr(e){let t=io(e.tacoHome),i=_i(),r=ro({socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});Zr(t,r,{mode:493});let s=so({wrapperPath:t,tacoHome:e.tacoHome,logDir:e.logDir});Zr(i,s,{mode:420});try{await
|
|
43
|
+
`}function no(e,t){let i=Date.now()+t;return new Promise((r,s)=>{let n=()=>{let o=eo(e),a=h=>{o.removeAllListeners(),o.destroy(),h?s(h):r()};o.once("connect",()=>a()),o.once("error",h=>{Date.now()>=i?a(new Error(`socket ${e} not ready in ${t}ms (${h.message})`)):setTimeout(n,100)})};n()})}async function Yr(e){let t=io(e.tacoHome),i=_i(),r=ro({socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});Zr(t,r,{mode:493});let s=so({wrapperPath:t,tacoHome:e.tacoHome,logDir:e.logDir});Zr(i,s,{mode:420});try{await H("launchctl",["bootout",i],{allowFailure:!0})}catch{}await H("launchctl",["load","-w",i]);try{await no(e.socket,1e4)}catch(n){throw new Error(`launchctl load succeeded but daemon socket ${e.socket} did not appear: ${n}`)}return{serviceManager:"launchd",wrapperPath:t,plistPath:i}}import{writeFileSync as oo}from"node:fs";import{join as ao}from"node:path";var Ye="TacoSidecar";function ho(e){return ao(e,"bin","taco-sidecar-daemon.cmd")}function Ae(e){return e.replace(/[&|<>^"%!]/g,"^$&")}function lo(e){let t=Ae(e.tacoHome),i=Ae(e.socketPath),r=Ae(e.controlSocketPath),s=Ae(e.nodeBin),n=Ae(e.bundle),o=Ae(e.resourcesRoot);return`@echo off
|
|
44
44
|
rem Generated by 'taco install' \u2014 do not edit.
|
|
45
45
|
rem Invokes the bundled sidecar in daemon mode under schtasks.
|
|
46
46
|
setlocal EnableExtensions EnableDelayedExpansion
|
|
@@ -63,28 +63,28 @@ set "BUNDLE=${n}"
|
|
|
63
63
|
|
|
64
64
|
"!NODE_BIN!" "!BUNDLE!"
|
|
65
65
|
endlocal
|
|
66
|
-
`}async function qr(e){let t=ho(e.tacoHome),i=lo({tacoHome:e.tacoHome,socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});return oo(t,i,{mode:493}),await
|
|
67
|
-
`)}function Ie(e){return{info(t){Pi("info",e,t)},warn(t){Pi("warn",e,t)},error(t){Pi("error",e,t)}}}import{mkdir as
|
|
66
|
+
`}function co(e){return["/Create","/SC","ONLOGON","/TN",Ye,"/TR",`"${e}"`,"/F"]}async function qr(e){let t=ho(e.tacoHome),i=lo({tacoHome:e.tacoHome,socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});return oo(t,i,{mode:493}),await H("schtasks",co(t)),await H("schtasks",["/Run","/TN",Ye],{allowFailure:!0}),{serviceManager:"schtasks",wrapperPath:t,taskName:Ye}}import{mkdir as qe}from"node:fs/promises";import{homedir as uo}from"node:os";import{join as D}from"node:path";function mo(){let e=process.env.TACO_HOME?.trim();return e&&e.length>0?e:D(uo(),".taco")}var T=mo();function ki(e=T){return D(e,"run")}function xt(e=T,t=process.env.TACO_RUNTIME_DIR){let i=t?.trim();return i&&i.length>0?i:ki(e)}var Jr=xt(),Hl=D(T,"bin");function Pt(e=Jr){return process.platform==="win32"?"\\\\.\\pipe\\taco-sidecar":D(e,"sidecar.sock")}function re(e=Jr){return process.platform==="win32"?"\\\\.\\pipe\\taco-sidecar-ctl":D(e,"sidecar-ctl.sock")}var Oi=D(T,"upgrade-marker.json"),Wl=D(T,"logs"),Gl=D(T,"staging"),Zl=D(T,"jobs");async function Lt(e=T,t=xt(e)){await qe(t,{recursive:!0,mode:493}),await qe(D(e,"bin"),{recursive:!0,mode:493}),await qe(D(e,"logs"),{recursive:!0,mode:493}),await qe(D(e,"staging"),{recursive:!0,mode:493}),await qe(D(e,"jobs"),{recursive:!0,mode:493})}async function Xr(e={}){let t=e.tacoHome??T,i=ki(t);await Lt(t,i);let r=Ot();if(!r)throw new Error("no @taco-ai/sidecar-<platform> bundle installed. Run `pnpm install` on a supported platform to install the optional dep, then retry `taco install`.");if(!r.daemonMode)throw new Error(`stale sidecar bundle at ${r.bundle}: missing daemon-mode support. Rebuild the runtime (\`pnpm --filter @taco-ai/sidecar package:runtime\`) and re-run \`taco install\`.`);let s={tacoHome:t,pkg:r,socket:Pt(i),control:re(i)};if(process.platform==="darwin")return Yr({...s,logDir:`${t}/logs`});if(process.platform==="win32")return qr({...s});throw new Error(`unsupported platform: ${process.platform}`)}import{readFileSync as ms,unlinkSync as Do}from"node:fs";import{createRequire as Ao}from"node:module";import{connect as ps}from"node:net";import*as fs from"node:path";import{join as Ct}from"node:path";import{createHash as po}from"node:crypto";function Qr(e,t){let i=po("sha256");return i.update(e),i.update("\0"),i.update(t),i.digest("hex").slice(0,16)}function Ti(e){let t=e.trim();if(t.length===0)return null;if(t.startsWith("{"))try{let r=JSON.parse(t);if(r.version!==1)return null;let s=typeof r.pid=="number"?r.pid:Number.NaN,n=typeof r.install_id=="string"?r.install_id:null,o=typeof r.started_at=="string"?r.started_at:null,a=typeof r.sidecar_version=="string"?r.sidecar_version:null;return!Number.isFinite(s)||s<=0?null:{pid:s,installId:n,startedAt:o,version:1,sidecarVersion:a}}catch{return null}let i=Number.parseInt(t,10);return!Number.isFinite(i)||i<=0?null:{pid:i,installId:null,startedAt:null,version:null,sidecarVersion:null}}function es(e,t,i){return e===null||e.installId!==null&&e.installId!==t?!1:e.sidecarVersion!==i}import{mkdir as fo,readFile as go,unlink as ts,writeFile as is}from"node:fs/promises";import{join as yo}from"node:path";var wo=15e3;async function xi(e){try{let t=await go(e,"utf8"),i=JSON.parse(t);return typeof i=="object"&&i!==null&&typeof i.pid=="number"&&typeof i.acquiredAt=="number"?i:null}catch{return null}}async function rs(e,t=Date.now){let i=yo(e,"start.lock");await fo(e,{recursive:!0});let r={pid:process.pid,acquiredAt:t()},s=JSON.stringify(r),n=!1;try{await is(i,s,{flag:"wx",encoding:"utf8"}),n=!0}catch(o){if(o.code==="EEXIST"){let a=await xi(i);if(a===null||t()-a.acquiredAt>wo){try{await ts(i)}catch{}try{await is(i,s,{flag:"wx",encoding:"utf8"}),n=!0}catch(l){if(l.code==="EEXIST")return null;throw l}}else return null}else throw o}return n?{path:i,async release(){try{await ts(i)}catch(o){if(o.code!=="ENOENT")throw o}}}:null}import{copyFile as Oo,mkdir as To,rename as xo,rm as At,stat as hs}from"node:fs/promises";import{join as It}from"node:path";function Pi(e,t,i){let r=new Date().toISOString();process.stderr.write(`${r} [${e}] [${t}] ${i}
|
|
67
|
+
`)}function Ie(e){return{info(t){Pi("info",e,t)},warn(t){Pi("warn",e,t)},error(t){Pi("error",e,t)}}}import{mkdir as bo,readFile as Eo,rename as So,unlink as vo,writeFile as Ro}from"node:fs/promises";import{dirname as _o,resolve as ss}from"node:path";var ns=Ie("taco.cli.upgrade.marker"),ko=2;function os(e,t){if(!t)return!1;let i=ss(e.live_dir),r=ss(t);return process.platform==="win32"?i.toLowerCase()===r.toLowerCase():i===r}async function Dt(e){let t;try{t=await Eo(e,"utf8")}catch(i){return i.code==="ENOENT"||ns.warn(`failed to read marker ${e}: ${String(i)}`),null}try{return JSON.parse(t)}catch(i){return ns.warn(`malformed marker ${e}: ${String(i)}`),null}}async function as(e,t){await bo(_o(e),{recursive:!0});let i=`${e}.tmp`;await Ro(i,JSON.stringify(t,null,ko),"utf8"),await So(i,e)}async function Li(e){await vo(e).catch(t=>{if(t.code!=="ENOENT")throw t})}var ye=Ie("taco.cli.upgrade.apply");async function Nt(e={}){let t=e.tacoHome??T,i=Oi.startsWith(t)?Oi:It(t,"upgrade-marker.json"),r=await Dt(i);if(!r)throw new Error("no upgrade pending; marker absent at "+i);if(ye.info(`applying upgrade \u2192 version=${r.version}, live=${r.live_dir}`),!await Po(r.staging_dir))throw ye.warn(`staging dir missing (${r.staging_dir}); clearing unusable marker`),await Li(i),new Error(`staging dir missing: ${r.staging_dir}`);await Lo(r.staging_dir);let s=`${r.live_dir}.prev`;await At(s,{recursive:!0,force:!0});let n=e.rename??xo;try{await n(r.live_dir,s)}catch(o){throw new Error(`failed to move live_dir \u2192 prev: ${String(o)}`)}try{try{await n(r.staging_dir,r.live_dir)}catch(o){if(o.code!=="EXDEV")throw o;ye.warn("cross-device rename; falling back to copyFile + unlink"),await ls(r.staging_dir,r.live_dir),await At(r.staging_dir,{recursive:!0,force:!0})}}catch(o){ye.error(`swap failed, rolling back: ${String(o)}`);try{await At(r.live_dir,{recursive:!0,force:!0}),await n(s,r.live_dir)}catch(a){ye.error(`rollback also failed: ${String(a)}`)}throw o}if(await Li(i),e.stop)try{await e.stop()}catch(o){ye.warn(`best-effort stop failed (ignored): ${String(o)}`)}return await At(s,{recursive:!0,force:!0}).catch(()=>{}),ye.info(`upgrade applied \u2192 version=${r.version}`),{version:r.version}}async function Po(e){try{return(await hs(e)).isDirectory()}catch{return!1}}async function Lo(e){try{await hs(It(e,"manifest.json"))}catch{throw new Error(`staging dir missing manifest.json: ${e}`)}}async function ls(e,t){await To(t,{recursive:!0});for await(let i of await import("node:fs/promises").then(r=>r.readdir(e,{withFileTypes:!0}))){let r=It(e,i.name),s=It(t,i.name);i.isDirectory()?await ls(r,s):i.isFile()&&await Oo(r,s)}}var Io=15e3,No=50,Co=2e4,Mo=3e3,Fo={major:2,minor:0};function cs(e,t=5e3){return new Promise(i=>{let r=ps(e),s="",n=!1,o=setTimeout(()=>a("wedged"),t);function a(h){n||(n=!0,clearTimeout(o),r.destroy(),i(h))}r.on("connect",()=>{let h={id:"probe",commandId:"probe",method:"initialize",params:{protocolVersion:Fo,clientCapabilities:{}}};r.write(`${JSON.stringify(h)}
|
|
68
68
|
`)}),r.on("data",h=>{s+=h.toString("utf8");let l=s.indexOf(`
|
|
69
69
|
`);for(;l!==-1;){let c=s.slice(0,l);s=s.slice(l+1);let d;try{d=JSON.parse(c)}catch{continue}if(!(typeof d.id!="string"||typeof d.ok!="boolean")){a("ready");return}}l=s.indexOf(`
|
|
70
|
-
`)}),r.once("error",()=>a("absent"))})}function ds(e){try{return process.kill(e,0),!0}catch(t){return t?.code==="EPERM"}}async function Di(e,t,i,r){let s=Ct(e,"sidecar.pid"),n=null;try{n=Ti(ms(s,"utf8"))}catch{n=null}let o=n!==null&&(n.installId===null||n.installId===r);if(n!==null&&o){let a=n.pid;try{process.kill(a,"SIGTERM")}catch{}let h=Date.now()+
|
|
70
|
+
`)}),r.once("error",()=>a("absent"))})}function ds(e){try{return process.kill(e,0),!0}catch(t){return t?.code==="EPERM"}}async function Di(e,t,i,r){let s=Ct(e,"sidecar.pid"),n=null;try{n=Ti(ms(s,"utf8"))}catch{n=null}let o=n!==null&&(n.installId===null||n.installId===r);if(n!==null&&o){let a=n.pid;try{process.kill(a,"SIGTERM")}catch{}let h=Date.now()+Mo;for(;Date.now()<h&&ds(a);)await new Promise(l=>setTimeout(l,100));if(ds(a))try{process.kill(a,"SIGKILL")}catch{}}for(let a of[t,i,s])try{Do(a)}catch{}}async function us(e,t){let i=Date.now()+t,r;for(;Date.now()<i;)try{await new Promise((s,n)=>{let o=ps(e);o.once("connect",()=>{o.destroy(),s()}),o.once("error",n)});return}catch(s){r=s,await new Promise(n=>setTimeout(n,No))}throw new Error(`socket ${e} did not become ready in ${t}ms (${String(r)})`)}function Bo(){let e=De();if(_t(e)&&e)return Ct(e,"packages","sidecar","src");try{let t=Ao(import.meta.url);for(let i of["@taco-ai/sidecar-darwin-arm64","@taco-ai/sidecar-darwin-x64","@taco-ai/sidecar-linux-arm64","@taco-ai/sidecar-linux-x64","@taco-ai/sidecar-win32-arm64","@taco-ai/sidecar-win32-x64"])try{let r=t.resolve(`${i}/package.json`);return fs.dirname(r)}catch{}}catch{}}function $o(e,t,i){let r=null;try{r=Ti(ms(Ct(e,"sidecar.pid"),"utf8"))}catch{r=null}return es(r,t,i)?`pid ${r?.pid??"?"} runs sidecar ${r?.sidecarVersion??"unknown"}, expected ${i}`:null}async function Uo(e){let t=await Dt(Ct(e,"upgrade-marker.json"));if(t&&os(t,Ot()?.resources))try{let{version:i}=await Nt({tacoHome:e});process.stderr.write(`[taco] applied pending upgrade \u2192 ${i}
|
|
71
71
|
`)}catch(i){process.stderr.write(`[taco] pending upgrade could not be applied (${String(i)}); starting existing version
|
|
72
|
-
`)}}async function gs(e={}){let t=e.tacoHome??T,i=xt(t,e.runtimeDir);await Lt(t,i);let r=Pt(i),s=re(i),n=await cs(r);n==="wedged"&&(await new Promise(l=>setTimeout(l,500)),n=await cs(r));let o=
|
|
72
|
+
`)}}async function gs(e={}){let t=e.tacoHome??T,i=xt(t,e.runtimeDir);await Lt(t,i);let r=Pt(i),s=re(i),n=await cs(r);n==="wedged"&&(await new Promise(l=>setTimeout(l,500)),n=await cs(r));let o=Bo(),a=Qr(o??"",t);if(n==="ready"){let l=_t(),c=l?null:zr(),d;if(l?d="dev checkout always respawns":c!==null?d=$o(i,a,c):(d=null,process.stderr.write(`[taco] freshness gate disabled: no bundle manifest version; reused daemon may be stale
|
|
73
73
|
`)),d===null){process.stdout.write(`${r}
|
|
74
74
|
`),process.stderr.write(`[taco] sidecar daemon already running (socket=${r})
|
|
75
75
|
`);return}process.stderr.write(`[taco] sidecar daemon stale (${d}); restarting
|
|
76
76
|
`),await Di(i,r,s,a),n="absent"}n==="wedged"&&(process.stderr.write(`[taco] sidecar daemon accepts connections but does not serve; killing it
|
|
77
|
-
`),await Di(i,r,s,a)),await Di(i,r,s,a);let h=await rs(i);if(!h){let l=await xi(`${i}/start.lock`);try{await us(r,
|
|
77
|
+
`),await Di(i,r,s,a)),await Di(i,r,s,a);let h=await rs(i);if(!h){let l=await xi(`${i}/start.lock`);try{await us(r,Co)}catch(c){throw new Error(`another process (pid=${l?.pid??"unknown"}) holds the start lock but its daemon did not become ready: ${String(c)}`)}process.stdout.write(`${r}
|
|
78
78
|
`),process.stderr.write(`[taco] sidecar daemon started by pid=${l?.pid??"unknown"}
|
|
79
|
-
`);return}try{await
|
|
79
|
+
`);return}try{await Uo(t);let{child:l,dev:c}=jr({socketPath:r,controlSocketPath:s,tacoHome:t,runtimeDir:i}),d=new Promise((p,w)=>{l.once("exit",(g,E)=>{w(new Error(`sidecar exited before binding socket (code=${g} sig=${E})`))})});try{await Promise.race([us(r,Io),d])}catch(p){throw l.killed||l.kill(),p}l.unref(),process.stdout.write(`${r}
|
|
80
80
|
`),process.stderr.write(`[taco] sidecar daemon started (dev=${c}, socket=${r}, control=${s}, tacoHome=${t})
|
|
81
|
-
`)}finally{await h.release()}}import{connect as
|
|
81
|
+
`)}finally{await h.release()}}import{connect as zo}from"node:net";var jo=3e3,Ho=1;function Mt(e,t,i={}){let r=i.timeoutMs??jo,s=i.id??Ho,n={method:t,id:s};return i.params!==void 0&&(n.params=i.params),new Promise((o,a)=>{let h=zo(e),l="",c=!1,d=w=>{c||(c=!0,clearTimeout(p),h.destroy(),w())},p=setTimeout(()=>{d(()=>a(new Error(`${t} timed out after ${r}ms`)))},r);h.once("error",w=>{d(()=>a(new Error(`${t}: ${w.message}`)))}),h.once("connect",()=>{h.write(`${JSON.stringify(n)}
|
|
82
82
|
`)}),h.on("data",w=>{l+=w.toString("utf8");let g=l.indexOf(`
|
|
83
|
-
`);if(g<0)return;let E=l.slice(0,g);try{let F=JSON.parse(E);"error"in F?d(()=>a(new Error(`${t}: ${F.error.code}: ${F.error.message}`))):d(()=>o(F.result))}catch(F){d(()=>a(new Error(`${t}: malformed reply: ${String(F)}`)))}}),h.on("end",()=>{c||d(()=>a(new Error(`${t}: socket closed before reply`)))}),h.on("close",()=>{c||d(()=>a(new Error(`${t}: socket closed before reply`)))})})}var
|
|
84
|
-
`)}import{existsSync as
|
|
85
|
-
`)}import{existsSync as Ko,unlinkSync as Vo}from"node:fs";async function Es(){let e=_i();if(Ko(e)){await j("launchctl",["unload",e],{allowFailure:!0});try{Vo(e)}catch{}}return{serviceManager:"launchd"}}async function Ss(){return await j("schtasks",["/Delete","/TN",Ye,"/F"],{allowFailure:!0}),{serviceManager:"schtasks"}}async function vs(){return process.platform==="darwin"?Es():process.platform==="win32"?Ss():{serviceManager:"none"}}import{createHash as tl}from"node:crypto";import{createReadStream as il}from"node:fs";import{mkdir as Mr,open as rl,rm as sl,stat as nl}from"node:fs/promises";import{dirname as Un,join as vi}from"node:path";import Jo from"events";import L from"fs";import{EventEmitter as Or}from"node:events";import nn from"node:stream";import{StringDecoder as Xo}from"node:string_decoder";import hn from"node:path";import He from"node:fs";import{dirname as da,parse as ua}from"path";import{EventEmitter as Ea}from"events";import ar from"assert";import{Buffer as Te}from"buffer";import*as Ts from"zlib";import Sa from"zlib";import{posix as Ce}from"node:path";import{basename as Ya}from"node:path";import ci from"fs";import V from"fs";import Cs from"path";import{win32 as hh}from"node:path";import Hs from"path";import Rn from"node:fs";import kh from"node:assert";import{randomBytes as _n}from"node:crypto";import m from"node:fs";import v from"node:path";import kn from"fs";import Ei from"node:fs";import ft from"node:path";import N from"node:fs";import Ah from"node:fs/promises";import mi from"node:path";import{join as Mn}from"node:path";import I from"node:fs";import $n from"node:path";var Yo=Object.defineProperty,qo=(e,t)=>{for(var i in t)Yo(e,i,{get:t[i],enumerable:!0})},Rs=typeof process=="object"&&process?process:{stdout:null,stderr:null},Qo=e=>!!e&&typeof e=="object"&&(e instanceof Le||e instanceof nn||ea(e)||ta(e)),ea=e=>!!e&&typeof e=="object"&&e instanceof Or&&typeof e.pipe=="function"&&e.pipe!==nn.Writable.prototype.pipe,ta=e=>!!e&&typeof e=="object"&&e instanceof Or&&typeof e.write=="function"&&typeof e.end=="function",J=Symbol("EOF"),X=Symbol("maybeEmitEnd"),se=Symbol("emittedEnd"),Ft=Symbol("emittingEnd"),Je=Symbol("emittedError"),Bt=Symbol("closed"),_s=Symbol("read"),$t=Symbol("flush"),ks=Symbol("flushChunk"),B=Symbol("encoding"),Ne=Symbol("decoder"),R=Symbol("flowing"),Xe=Symbol("paused"),$e=Symbol("resume"),_=Symbol("buffer"),P=Symbol("pipes"),k=Symbol("bufferLength"),Ai=Symbol("bufferPush"),Ut=Symbol("bufferShift"),x=Symbol("objectMode"),S=Symbol("destroyed"),Ii=Symbol("error"),Ni=Symbol("emitData"),Os=Symbol("emitEnd"),Ci=Symbol("emitEnd2"),W=Symbol("async"),Mi=Symbol("abort"),zt=Symbol("aborted"),Qe=Symbol("signal"),we=Symbol("dataListeners"),A=Symbol("discarded"),et=e=>Promise.resolve().then(e),ia=e=>e(),ra=e=>e==="end"||e==="finish"||e==="prefinish",sa=e=>e instanceof ArrayBuffer||!!e&&typeof e=="object"&&e.constructor&&e.constructor.name==="ArrayBuffer"&&e.byteLength>=0,na=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),on=class{src;dest;opts;ondrain;constructor(e,t,i){this.src=e,this.dest=t,this.opts=i,this.ondrain=()=>e[$e](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},oa=class extends on{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,i){super(e,t,i),this.proxyErrors=r=>this.dest.emit("error",r),e.on("error",this.proxyErrors)}},aa=e=>!!e.objectMode,ha=e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",Le=class extends Or{[R]=!1;[Xe]=!1;[P]=[];[_]=[];[x];[B];[W];[Ne];[J]=!1;[se]=!1;[Ft]=!1;[Bt]=!1;[Je]=null;[k]=0;[S]=!1;[Qe];[zt]=!1;[we]=0;[A]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");aa(t)?(this[x]=!0,this[B]=null):ha(t)?(this[B]=t.encoding,this[x]=!1):(this[x]=!1,this[B]=null),this[W]=!!t.async,this[Ne]=this[B]?new Xo(this[B]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[_]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[P]});let{signal:i}=t;i&&(this[Qe]=i,i.aborted?this[Mi]():i.addEventListener("abort",()=>this[Mi]()))}get bufferLength(){return this[k]}get encoding(){return this[B]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[x]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[W]}set async(e){this[W]=this[W]||!!e}[Mi](){this[zt]=!0,this.emit("abort",this[Qe]?.reason),this.destroy(this[Qe]?.reason)}get aborted(){return this[zt]}set aborted(e){}write(e,t,i){if(this[zt])return!1;if(this[J])throw new Error("write after end");if(this[S])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof t=="function"&&(i=t,t="utf8"),t||(t="utf8");let r=this[W]?et:ia;if(!this[x]&&!Buffer.isBuffer(e)){if(na(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(sa(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[x]?(this[R]&&this[k]!==0&&this[$t](!0),this[R]?this.emit("data",e):this[Ai](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[R]):e.length?(typeof e=="string"&&!(t===this[B]&&!this[Ne]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[B]&&(e=this[Ne].write(e)),this[R]&&this[k]!==0&&this[$t](!0),this[R]?this.emit("data",e):this[Ai](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[R]):(this[k]!==0&&this.emit("readable"),i&&r(i),this[R])}read(e){if(this[S])return null;if(this[A]=!1,this[k]===0||e===0||e&&e>this[k])return this[X](),null;this[x]&&(e=null),this[_].length>1&&!this[x]&&(this[_]=[this[B]?this[_].join(""):Buffer.concat(this[_],this[k])]);let t=this[_s](e||null,this[_][0]);return this[X](),t}[_s](e,t){if(this[x])this[Ut]();else{let i=t;e===i.length||e===null?this[Ut]():typeof i=="string"?(this[_][0]=i.slice(e),t=i.slice(0,e),this[k]-=e):(this[_][0]=i.subarray(e),t=i.subarray(0,e),this[k]-=e)}return this.emit("data",t),!this[_].length&&!this[J]&&this.emit("drain"),t}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t="utf8"),e!==void 0&&this.write(e,t),i&&this.once("end",i),this[J]=!0,this.writable=!1,(this[R]||!this[Xe])&&this[X](),this}[$e](){this[S]||(!this[we]&&!this[P].length&&(this[A]=!0),this[Xe]=!1,this[R]=!0,this.emit("resume"),this[_].length?this[$t]():this[J]?this[X]():this.emit("drain"))}resume(){return this[$e]()}pause(){this[R]=!1,this[Xe]=!0,this[A]=!1}get destroyed(){return this[S]}get flowing(){return this[R]}get paused(){return this[Xe]}[Ai](e){this[x]?this[k]+=1:this[k]+=e.length,this[_].push(e)}[Ut](){return this[x]?this[k]-=1:this[k]-=this[_][0].length,this[_].shift()}[$t](e=!1){do;while(this[ks](this[Ut]())&&this[_].length);!e&&!this[_].length&&!this[J]&&this.emit("drain")}[ks](e){return this.emit("data",e),this[R]}pipe(e,t){if(this[S])return e;this[A]=!1;let i=this[se];return t=t||{},e===Rs.stdout||e===Rs.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,i?t.end&&e.end():(this[P].push(t.proxyErrors?new oa(this,e,t):new on(this,e,t)),this[W]?et(()=>this[$e]()):this[$e]()),e}unpipe(e){let t=this[P].find(i=>i.dest===e);t&&(this[P].length===1?(this[R]&&this[we]===0&&(this[R]=!1),this[P]=[]):this[P].splice(this[P].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let i=super.on(e,t);if(e==="data")this[A]=!1,this[we]++,!this[P].length&&!this[R]&&this[$e]();else if(e==="readable"&&this[k]!==0)super.emit("readable");else if(ra(e)&&this[se])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[Je]){let r=t;this[W]?et(()=>r.call(this,this[Je])):r.call(this,this[Je])}return i}removeListener(e,t){return this.off(e,t)}off(e,t){let i=super.off(e,t);return e==="data"&&(this[we]=this.listeners("data").length,this[we]===0&&!this[A]&&!this[P].length&&(this[R]=!1)),i}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[we]=0,!this[A]&&!this[P].length&&(this[R]=!1)),t}get emittedEnd(){return this[se]}[X](){!this[Ft]&&!this[se]&&!this[S]&&this[_].length===0&&this[J]&&(this[Ft]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Bt]&&this.emit("close"),this[Ft]=!1)}emit(e,...t){let i=t[0];if(e!=="error"&&e!=="close"&&e!==S&&this[S])return!1;if(e==="data")return!this[x]&&!i?!1:this[W]?(et(()=>this[Ni](i)),!0):this[Ni](i);if(e==="end")return this[Os]();if(e==="close"){if(this[Bt]=!0,!this[se]&&!this[S])return!1;let s=super.emit("close");return this.removeAllListeners("close"),s}else if(e==="error"){this[Je]=i,super.emit(Ii,i);let s=!this[Qe]||this.listeners("error").length?super.emit("error",i):!1;return this[X](),s}else if(e==="resume"){let s=super.emit("resume");return this[X](),s}else if(e==="finish"||e==="prefinish"){let s=super.emit(e);return this.removeAllListeners(e),s}let r=super.emit(e,...t);return this[X](),r}[Ni](e){for(let i of this[P])i.dest.write(e)===!1&&this.pause();let t=this[A]?!1:super.emit("data",e);return this[X](),t}[Os](){return this[se]?!1:(this[se]=!0,this.readable=!1,this[W]?(et(()=>this[Ci]()),!0):this[Ci]())}[Ci](){if(this[Ne]){let t=this[Ne].end();if(t){for(let i of this[P])i.dest.write(t);this[A]||super.emit("data",t)}}for(let t of this[P])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[x]||(e.dataLength=0);let t=this.promise();return this.on("data",i=>{e.push(i),this[x]||(e.dataLength+=i.length)}),await t,e}async concat(){if(this[x])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[B]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(S,()=>t(new Error("stream destroyed"))),this.on("error",i=>t(i)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[A]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let i=this.read();if(i!==null)return Promise.resolve({done:!1,value:i});if(this[J])return t();let r,s,n=l=>{this.off("data",o),this.off("end",a),this.off(S,h),t(),s(l)},o=l=>{this.off("error",n),this.off("end",a),this.off(S,h),this.pause(),r({value:l,done:!!this[J]})},a=()=>{this.off("error",n),this.off("data",o),this.off(S,h),t(),r({done:!0,value:void 0})},h=()=>n(new Error("stream destroyed"));return new Promise((l,c)=>{s=c,r=l,this.once(S,h),this.once("error",n),this.once("end",a),this.once("data",o)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[A]=!1;let e=!1,t=()=>(this.pause(),this.off(Ii,t),this.off(S,t),this.off("end",t),e=!0,{done:!0,value:void 0}),i=()=>{if(e)return t();let r=this.read();return r===null?t():{done:!1,value:r}};return this.once("end",t),this.once(Ii,t),this.once(S,t),{next:i,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[S])return e?this.emit("error",e):this.emit(S),this;this[S]=!0,this[A]=!0,this[_].length=0,this[k]=0;let t=this;return typeof t.close=="function"&&!this[Bt]&&t.close(),e?this.emit("error",e):this.emit(S),this}static get isStream(){return Qo}},la=L.writev,me=Symbol("_autoClose"),H=Symbol("_close"),tt=Symbol("_ended"),f=Symbol("_fd"),Fi=Symbol("_finished"),ie=Symbol("_flags"),Bi=Symbol("_flush"),nr=Symbol("_handleChunk"),or=Symbol("_makeBuf"),mt=Symbol("_mode"),Ht=Symbol("_needDrain"),We=Symbol("_onerror"),Ge=Symbol("_onopen"),$i=Symbol("_onread"),Ue=Symbol("_onwrite"),pe=Symbol("_open"),z=Symbol("_path"),he=Symbol("_pos"),G=Symbol("_queue"),ze=Symbol("_read"),Ui=Symbol("_readSize"),te=Symbol("_reading"),it=Symbol("_remain"),zi=Symbol("_size"),Xt=Symbol("_write"),be=Symbol("_writing"),Qt=Symbol("_defaultFlag"),Oe=Symbol("_errored"),Tr=class extends Le{[Oe]=!1;[f];[z];[Ui];[te]=!1;[zi];[it];[me];constructor(e,t){if(t=t||{},super(t),this.readable=!0,this.writable=!1,typeof e!="string")throw new TypeError("path must be a string");this[Oe]=!1,this[f]=typeof t.fd=="number"?t.fd:void 0,this[z]=e,this[Ui]=t.readSize||16*1024*1024,this[te]=!1,this[zi]=typeof t.size=="number"?t.size:1/0,this[it]=this[zi],this[me]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[f]=="number"?this[ze]():this[pe]()}get fd(){return this[f]}get path(){return this[z]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[pe](){L.open(this[z],"r",(e,t)=>this[Ge](e,t))}[Ge](e,t){e?this[We](e):(this[f]=t,this.emit("open",t),this[ze]())}[or](){return Buffer.allocUnsafe(Math.min(this[Ui],this[it]))}[ze](){if(!this[te]){this[te]=!0;let e=this[or]();if(e.length===0)return process.nextTick(()=>this[$i](null,0,e));L.read(this[f],e,0,e.length,null,(t,i,r)=>this[$i](t,i,r))}}[$i](e,t,i){this[te]=!1,e?this[We](e):this[nr](t,i)&&this[ze]()}[H](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}[We](e){this[te]=!0,this[H](),this.emit("error",e)}[nr](e,t){let i=!1;return this[it]-=e,e>0&&(i=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[it]<=0)&&(i=!1,this[H](),super.end()),i}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[f]=="number"&&this[ze](),!1;case"error":return this[Oe]?!1:(this[Oe]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},ca=class extends Tr{[pe](){let e=!0;try{this[Ge](null,L.openSync(this[z],"r")),e=!1}finally{e&&this[H]()}}[ze](){let e=!0;try{if(!this[te]){this[te]=!0;do{let t=this[or](),i=t.length===0?0:L.readSync(this[f],t,0,t.length,null);if(!this[nr](i,t))break}while(!0);this[te]=!1}e=!1}finally{e&&this[H]()}}[H](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}},pi=class extends Jo{readable=!1;writable=!0;[Oe]=!1;[be]=!1;[tt]=!1;[G]=[];[Ht]=!1;[z];[mt];[me];[f];[Qt];[ie];[Fi]=!1;[he];constructor(e,t){t=t||{},super(t),this[z]=e,this[f]=typeof t.fd=="number"?t.fd:void 0,this[mt]=t.mode===void 0?438:t.mode,this[he]=typeof t.start=="number"?t.start:void 0,this[me]=typeof t.autoClose=="boolean"?t.autoClose:!0;let i=this[he]!==void 0?"r+":"w";this[Qt]=t.flags===void 0,this[ie]=t.flags===void 0?i:t.flags,this[f]===void 0&&this[pe]()}emit(e,...t){if(e==="error"){if(this[Oe])return!1;this[Oe]=!0}return super.emit(e,...t)}get fd(){return this[f]}get path(){return this[z]}[We](e){this[H](),this[be]=!0,this.emit("error",e)}[pe](){L.open(this[z],this[ie],this[mt],(e,t)=>this[Ge](e,t))}[Ge](e,t){this[Qt]&&this[ie]==="r+"&&e&&e.code==="ENOENT"?(this[ie]="w",this[pe]()):e?this[We](e):(this[f]=t,this.emit("open",t),this[be]||this[Bi]())}end(e,t){return e&&this.write(e,t),this[tt]=!0,!this[be]&&!this[G].length&&typeof this[f]=="number"&&this[Ue](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[tt]?(this.emit("error",new Error("write() after end()")),!1):this[f]===void 0||this[be]||this[G].length?(this[G].push(e),this[Ht]=!0,!1):(this[be]=!0,this[Xt](e),!0)}[Xt](e){L.write(this[f],e,0,e.length,this[he],(t,i)=>this[Ue](t,i))}[Ue](e,t){e?this[We](e):(this[he]!==void 0&&typeof t=="number"&&(this[he]+=t),this[G].length?this[Bi]():(this[be]=!1,this[tt]&&!this[Fi]?(this[Fi]=!0,this[H](),this.emit("finish")):this[Ht]&&(this[Ht]=!1,this.emit("drain"))))}[Bi](){if(this[G].length===0)this[tt]&&this[Ue](null,0);else if(this[G].length===1)this[Xt](this[G].pop());else{let e=this[G];this[G]=[],la(this[f],e,this[he],(t,i)=>this[Ue](t,i))}}[H](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}},an=class extends pi{[pe](){let e;if(this[Qt]&&this[ie]==="r+")try{e=L.openSync(this[z],this[ie],this[mt])}catch(t){if(t?.code==="ENOENT")return this[ie]="w",this[pe]();throw t}else e=L.openSync(this[z],this[ie],this[mt]);this[Ge](null,e)}[H](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}[Xt](e){let t=!0;try{this[Ue](null,L.writeSync(this[f],e,0,e.length,this[he])),t=!1}finally{if(t)try{this[H]()}catch{}}}},ma=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"]]),pa=e=>!!e.sync&&!!e.file,fa=e=>!e.sync&&!!e.file,ga=e=>!!e.sync&&!e.file,ya=e=>!e.sync&&!e.file,wa=e=>!!e.file,ba=e=>ma.get(e)||e,xr=(e={})=>{if(!e)return{};let t={};for(let[i,r]of Object.entries(e)){let s=ba(i);t[s]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},vt=(e,t,i,r,s)=>Object.assign((n=[],o,a)=>{Array.isArray(n)&&(o=n,n={}),typeof o=="function"&&(a=o,o=void 0),o=o?Array.from(o):[];let h=xr(n);if(s?.(h,o),pa(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return e(h,o)}else if(fa(h)){let l=t(h,o);return a?l.then(()=>a(),a):l}else if(ga(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return i(h,o)}else if(ya(h)){if(typeof a=="function")throw new TypeError("callback only supported with file option");return r(h,o)}throw new Error("impossible options??")},{syncFile:e,asyncFile:t,syncNoFile:i,asyncNoFile:r,validate:s}),va=Sa.constants||{ZLIB_VERNUM:4736},q=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},va)),Ra=Te.concat,xs=Object.getOwnPropertyDescriptor(Te,"concat"),_a=e=>e,Hi=xs?.writable===!0||xs?.set!==void 0?e=>{Te.concat=e?_a:Ra}:e=>{},xe=Symbol("_superWrite"),jt=class extends Error{code;errno;constructor(e,t){super("zlib: "+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+e.message,Error.captureStackTrace(this,t??this.constructor)}get name(){return"ZlibError"}},ji=Symbol("flushFlag"),Pr=class extends Le{#e=!1;#i=!1;#r;#n;#s;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(e,t){if(!e||typeof e!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(e),this.#r=e.flush??0,this.#n=e.finishFlush??0,this.#s=e.fullFlushFlag??0,typeof Ts[t]!="function")throw new TypeError("Compression method not supported: "+t);try{this.#t=new Ts[t](e)}catch(i){throw new jt(i,this.constructor)}this.#o=i=>{this.#e||(this.#e=!0,this.close(),this.emit("error",i))},this.#t?.on("error",i=>this.#o(new jt(i))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ar(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#s),this.write(Object.assign(Te.alloc(0),{[ji]:e})))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#n),this.#i=!0,super.end(i)}get ended(){return this.#i}[xe](e){return super.write(e)}write(e,t,i){if(typeof t=="function"&&(i=t,t="utf8"),typeof e=="string"&&(e=Te.from(e,t)),this.#e)return;ar(this.#t,"zlib binding closed");let r=this.#t._handle,s=r.close;r.close=()=>{};let n=this.#t.close;this.#t.close=()=>{},Hi(!0);let o;try{let h=typeof e[ji]=="number"?e[ji]:this.#r;o=this.#t._processChunk(e,h),Hi(!1)}catch(h){Hi(!1),this.#o(new jt(h,this.write))}finally{this.#t&&(this.#t._handle=r,r.close=s,this.#t.close=n,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new jt(h,this.write)));let a;if(o)if(Array.isArray(o)&&o.length>0){let h=o[0];a=this[xe](Te.from(h));for(let l=1;l<o.length;l++)a=this[xe](o[l])}else a=this[xe](Te.from(o));return i&&i(),a}},ln=class extends Pr{#e;#i;constructor(e,t){e=e||{},e.flush=e.flush||q.Z_NO_FLUSH,e.finishFlush=e.finishFlush||q.Z_FINISH,e.fullFlushFlag=q.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#i=e.strategy}params(e,t){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==e||this.#i!==t){this.flush(q.Z_SYNC_FLUSH),ar(this.handle,"zlib binding closed");let i=this.handle.flush;this.handle.flush=(r,s)=>{typeof r=="function"&&(s=r,r=this.flushFlag),this.flush(r),s?.()};try{this.handle.params(e,t)}finally{this.handle.flush=i}this.handle&&(this.#e=e,this.#i=t)}}}},ka=class extends ln{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[xe](e){return this.#e?(this.#e=!1,e[9]=255,super[xe](e)):super[xe](e)}},Oa=class extends ln{constructor(e){super(e,"Unzip")}},cn=class extends Pr{constructor(e,t){e=e||{},e.flush=e.flush||q.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||q.BROTLI_OPERATION_FINISH,e.fullFlushFlag=q.BROTLI_OPERATION_FLUSH,super(e,t)}},Ta=class extends cn{constructor(e){super(e,"BrotliCompress")}},xa=class extends cn{constructor(e){super(e,"BrotliDecompress")}},dn=class extends Pr{constructor(e,t){e=e||{},e.flush=e.flush||q.ZSTD_e_continue,e.finishFlush=e.finishFlush||q.ZSTD_e_end,e.fullFlushFlag=q.ZSTD_e_flush,super(e,t)}},Pa=class extends dn{constructor(e){super(e,"ZstdCompress")}},La=class extends dn{constructor(e){super(e,"ZstdDecompress")}},Da=(e,t)=>{if(Number.isSafeInteger(e))e<0?Ia(e,t):Aa(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},Aa=(e,t)=>{t[0]=128;for(var i=t.length;i>1;i--)t[i-1]=e&255,e=Math.floor(e/256)},Ia=(e,t)=>{t[0]=255;var i=!1;e=e*-1;for(var r=t.length;r>1;r--){var s=e&255;e=Math.floor(e/256),i?t[r-1]=un(s):s===0?t[r-1]=0:(i=!0,t[r-1]=mn(s))}},Na=e=>{let t=e[0],i=t===128?Ma(e.subarray(1,e.length)):t===255?Ca(e):null;if(i===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i},Ca=e=>{for(var t=e.length,i=0,r=!1,s=t-1;s>-1;s--){var n=Number(e[s]),o;r?o=un(n):n===0?o=n:(r=!0,o=mn(n)),o!==0&&(i-=o*Math.pow(256,t-s-1))}return i},Ma=e=>{for(var t=e.length,i=0,r=t-1;r>-1;r--){var s=Number(e[r]);s!==0&&(i+=s*Math.pow(256,t-r-1))}return i},un=e=>(255^e)&255,mn=e=>(255^e)+1&255,Fa={};qo(Fa,{code:()=>Lr,isCode:()=>ei,isName:()=>Ba,name:()=>fi,normalFsTypes:()=>pn});var ei=e=>fi.has(e),Ba=e=>Lr.has(e),pn=new Set(["0","","1","2","3","4","5","6","7","D"]),fi=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"]]),Lr=new Map(Array.from(fi).map(e=>[e[1],e[0]])),$a=e=>e===void 0||e<0?void 0:e,Pe=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,i,r){Buffer.isBuffer(e)?this.decode(e,t||0,i,r):e&&this.#i(e)}decode(e,t,i,r){if(t||(t=0),!e||!(e.length>=t+512))throw new Error("need 512 bytes for header");let s=Ee(e,t+156,1),n=pn.has(s),o=n?i:void 0,a=n?r:void 0;if(this.path=o?.path??Ee(e,t,100),this.mode=o?.mode??a?.mode??le(e,t+100,8),this.uid=o?.uid??a?.uid??le(e,t+108,8),this.gid=o?.gid??a?.gid??le(e,t+116,8),this.size=$a(o?.size??a?.size??le(e,t+124,12)),this.mtime=o?.mtime??a?.mtime??Wi(e,t+136,12),this.cksum=le(e,t+148,12),a&&this.#i(a,!0),o&&this.#i(o),ei(s)&&(this.#e=s||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Ee(e,t+157,100),e.subarray(t+257,t+265).toString()==="ustar\x0000")if(this.uname=o?.uname??a?.uname??Ee(e,t+265,32),this.gname=o?.gname??a?.gname??Ee(e,t+297,32),this.devmaj=o?.devmaj??a?.devmaj??le(e,t+329,8)??0,this.devmin=o?.devmin??a?.devmin??le(e,t+337,8)??0,e[t+475]!==0){let l=Ee(e,t+345,155);this.path=l+"/"+this.path}else{let l=Ee(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=i?.atime??r?.atime??Wi(e,t+476,12),this.ctime=i?.ctime??r?.ctime??Wi(e,t+488,12)}let h=256;for(let l=t;l<t+148;l++)h+=e[l];for(let l=t+156;l<t+512;l++)h+=e[l];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#i(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="size"&&Number(r)<0||i==="path"&&t||i==="linkpath"&&t||i==="global"))))}encode(e,t=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw new Error("need 512 bytes for header");let i=this.ctime||this.atime?130:155,r=Ua(this.path||"",i),s=r[0],n=r[1];this.needPax=!!r[2],this.needPax=Se(e,t,100,s)||this.needPax,this.needPax=ce(e,t+100,8,this.mode)||this.needPax,this.needPax=ce(e,t+108,8,this.uid)||this.needPax,this.needPax=ce(e,t+116,8,this.gid)||this.needPax,this.needPax=ce(e,t+124,12,this.size)||this.needPax,this.needPax=Gi(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=Se(e,t+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",t+257,8),this.needPax=Se(e,t+265,32,this.uname)||this.needPax,this.needPax=Se(e,t+297,32,this.gname)||this.needPax,this.needPax=ce(e,t+329,8,this.devmaj)||this.needPax,this.needPax=ce(e,t+337,8,this.devmin)||this.needPax,this.needPax=Se(e,t+345,i,n)||this.needPax,e[t+475]!==0?this.needPax=Se(e,t+345,155,n)||this.needPax:(this.needPax=Se(e,t+345,130,n)||this.needPax,this.needPax=Gi(e,t+476,12,this.atime)||this.needPax,this.needPax=Gi(e,t+488,12,this.ctime)||this.needPax);let o=256;for(let a=t;a<t+148;a++)o+=e[a];for(let a=t+156;a<t+512;a++)o+=e[a];return this.cksum=o,ce(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:fi.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Lr.get(e));if(ei(t)||t==="Unsupported")this.#e=t;else if(ei(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},Ua=(e,t)=>{let i=e,r="",s,n=Ce.parse(e).root||".";if(Buffer.byteLength(i)<100)s=[i,r,!1];else{r=Ce.dirname(i),i=Ce.basename(i);do Buffer.byteLength(i)<=100&&Buffer.byteLength(r)<=t?s=[i,r,!1]:Buffer.byteLength(i)>100&&Buffer.byteLength(r)<=t?s=[i.slice(0,99),r,!0]:(i=Ce.join(Ce.basename(r),i),r=Ce.dirname(r));while(r!==n&&s===void 0);s||(s=[e.slice(0,99),"",!0])}return s},Ee=(e,t,i)=>e.subarray(t,t+i).toString("utf8").replace(/\0.*/,""),Wi=(e,t,i)=>za(le(e,t,i)),za=e=>e===void 0?void 0:new Date(e*1e3),le=(e,t,i)=>Number(e[t])&128?Na(e.subarray(t,t+i)):ja(e,t,i),Ha=e=>isNaN(e)?void 0:e,ja=(e,t,i)=>Ha(parseInt(e.subarray(t,t+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),Wa={12:8589934591,8:2097151},ce=(e,t,i,r)=>r===void 0?!1:r>Wa[i]||r<0?(Da(r,e.subarray(t,t+i)),!0):(Ga(e,t,i,r),!1),Ga=(e,t,i,r)=>e.write(Za(r,i),t,i,"ascii"),Za=(e,t)=>Ka(Math.floor(e).toString(8),t),Ka=(e,t)=>(e.length===t-1?e:new Array(t-e.length-1).join("0")+e+" ")+"\0",Gi=(e,t,i,r)=>r===void 0?!1:ce(e,t,i,r.getTime()/1e3),Va=new Array(156).join("\0"),Se=(e,t,i,r)=>r===void 0?!1:(e.write(r+Va,t,i,"utf8"),r.length!==Buffer.byteLength(r)||r.length>i),li=class fn{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,i=!1){this.atime=t.atime,this.charset=t.charset,this.comment=t.comment,this.ctime=t.ctime,this.dev=t.dev,this.gid=t.gid,this.global=i,this.gname=t.gname,this.ino=t.ino,this.linkpath=t.linkpath,this.mtime=t.mtime,this.nlink=t.nlink,this.path=t.path,this.size=t.size,this.uid=t.uid,this.uname=t.uname}encode(){let t=this.encodeBody();if(t==="")return Buffer.allocUnsafe(0);let i=Buffer.byteLength(t),r=512*Math.ceil(1+i/512),s=Buffer.allocUnsafe(r);for(let n=0;n<512;n++)s[n]=0;new Pe({path:("PaxHeader/"+Ya(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:i,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(s),s.write(t,512,i,"utf8");for(let n=i+512;n<s.length;n++)s[n]=0;return s}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(t){if(this[t]===void 0)return"";let i=this[t],r=i instanceof Date?i.getTime()/1e3:i,s=" "+(t==="dev"||t==="ino"||t==="nlink"?"SCHILY.":"")+t+"="+r+`
|
|
86
|
-
`,n=Buffer.byteLength(s),o=Math.floor(Math.log(n)/Math.log(10))+1;return n+o>=Math.pow(10,o)&&(o+=1),o+n+s}static parse(t,i,r=!1){return new fn(
|
|
87
|
-
`).reduce(Xa,Object.create(null)),Xa=(e,t)=>{let i=parseInt(t,10);if(i!==Buffer.byteLength(t)+1)return e;t=t.slice((i+" ").length);let r=t.split("="),s=r.shift();if(!s)return e;let n=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),o=r.join("=").replace(/\0.*/,"");switch(n){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":e[n]=o;break;case"ctime":case"atime":case"mtime":e[n]=new Date(Number(o)*1e3);break;case"size":let a=+o;a>=0&&(e[n]=a);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":e[n]=+o;break}return e},Qa=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,u=Qa!=="win32"?e=>String(e):e=>String(e).replaceAll(/\\/g,"/"),eh=class extends Le{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,i){switch(super({}),this.pause(),this.extended=t,this.globalExtended=i,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 new Error("no path provided for tar.ReadEntry");this.path=u(e.path),this.mode=e.mode,this.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?u(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),i&&this.#e(i,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw new Error("writing more to entry than is appropriate");let i=this.remain,r=this.blockRemain;return this.remain=Math.max(0,i-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:i>=t?super.write(e):super.write(e.subarray(0,i))}#e(e,t=!1){e.path&&(e.path=u(e.path)),e.linkpath&&(e.linkpath=u(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="path"&&t))))}},gi=(e,t,i,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=i instanceof Error&&i.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(i instanceof Error&&(r=Object.assign(i,r),i=i.message),e.emit("warn",t,i,r)):i instanceof Error?e.emit("error",Object.assign(i,r)):e.emit("error",Object.assign(new Error(`${t}: ${i}`),r))},th=1024*1024,hr=Buffer.from([31,139]),lr=Buffer.from([40,181,47,253]),ih=Math.max(hr.length,lr.length),C=Symbol("state"),ve=Symbol("writeEntry"),Q=Symbol("readEntry"),Zi=Symbol("nextEntry"),Ps=Symbol("processEntry"),Z=Symbol("extendedHeader"),rt=Symbol("globalExtendedHeader"),ne=Symbol("meta"),Ls=Symbol("emitMeta"),y=Symbol("buffer"),ee=Symbol("queue"),oe=Symbol("ended"),Ki=Symbol("emittedEnd"),Re=Symbol("emit"),b=Symbol("unzip"),Wt=Symbol("consumeChunk"),Gt=Symbol("consumeChunkSub"),Vi=Symbol("consumeBody"),Ds=Symbol("consumeMeta"),As=Symbol("consumeHeader"),st=Symbol("consuming"),Yi=Symbol("bufferConcat"),Zt=Symbol("maybeEnd"),Me=Symbol("writing"),K=Symbol("aborted"),Kt=Symbol("onDone"),_e=Symbol("sawValidEntry"),Vt=Symbol("sawNullBlock"),Yt=Symbol("sawEOF"),Is=Symbol("closeStream"),rh=1e3,nt=Symbol("compressedBytesRead"),qi=Symbol("decompressedBytesRead"),Ns=Symbol("checkDecompressionRatio"),sh=()=>!0,St=class extends Ea{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[ee]=[];[y];[Q];[ve];[C]="begin";[ne]="";[Z];[rt];[oe]=!1;[b];[K]=!1;[_e];[Vt]=!1;[Yt]=!1;[Me]=!1;[st]=!1;[Ki]=!1;[nt]=0;[qi]=0;constructor(e={}){super(),this.file=e.file||"",this.on(Kt,()=>{(this[C]==="begin"||this[_e]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(Kt,e.ondone):this.on(Kt,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:rh,this.maxMetaEntrySize=e.maxMetaEntrySize||th,this.filter=typeof e.filter=="function"?e.filter:sh;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 i=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:i?!0:void 0,this.on("end",()=>this[Is]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,i={}){gi(this,e,t,i)}[As](e,t){this[_e]===void 0&&(this[_e]=!1);let i;try{i=new Pe(e,t,this[Z],this[rt])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(i.nullBlock)this[Vt]?(this[Yt]=!0,this[C]==="begin"&&(this[C]="header"),this[Re]("eof")):(this[Vt]=!0,this[Re]("nullBlock"));else if(this[Vt]=!1,!i.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:i});else if(!i.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:i});else{let r=i.type;if(/^(Symbolic)?Link$/.test(r)&&!i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:i});else if(!/^(Symbolic)?Link$/.test(r)&&!/^(Global)?ExtendedHeader$/.test(r)&&i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:i});else{let s=this[ve]=new eh(i,this[Z],this[rt]);if(!this[_e])if(s.remain){let n=()=>{s.invalid||(this[_e]=!0)};s.on("end",n)}else this[_e]=!0;s.meta?s.size>this.maxMetaEntrySize?(s.ignore=!0,this[Re]("ignoredEntry",s),this[C]="ignore",s.resume()):s.size>0&&(this[ne]="",s.on("data",n=>this[ne]+=n),this[C]="meta"):(this[Z]=void 0,s.ignore=s.ignore||!this.filter(s.path,s),s.ignore?(this[Re]("ignoredEntry",s),this[C]=s.remain?"ignore":"header",s.resume()):(s.remain?this[C]="body":(this[C]="header",s.end()),this[Q]?this[ee].push(s):(this[ee].push(s),this[Zi]())))}}}[Is](){queueMicrotask(()=>this.emit("close"))}[Ps](e){let t=!0;if(!e)this[Q]=void 0,t=!1;else if(Array.isArray(e)){let[i,...r]=e;this.emit(i,...r)}else this[Q]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[Zi]()),t=!1);return t}[Zi](){do;while(this[Ps](this[ee].shift()));if(this[ee].length===0){let e=this[Q];!e||e.flowing||e.size===e.remain?this[Me]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[Vi](e,t){let i=this[ve];if(!i)throw new Error("attempt to consume body without entry??");let r=i.blockRemain??0,s=r>=e.length&&t===0?e:e.subarray(t,t+r);return i.write(s),i.blockRemain||(this[C]="header",this[ve]=void 0,i.end()),s.length}[Ds](e,t){let i=this[ve],r=this[Vi](e,t);return!this[ve]&&i&&this[Ls](i),r}[Re](e,t,i){this[ee].length===0&&!this[Q]?this.emit(e,t,i):this[ee].push([e,t,i])}[Ls](e){switch(this[Re]("meta",this[ne]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[Z]=li.parse(this[ne],this[Z],!1);break;case"GlobalExtendedHeader":this[rt]=li.parse(this[ne],this[rt],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[Z]??Object.create(null);this[Z]=t,t.path=this[ne].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[Z]||Object.create(null);this[Z]=t,t.linkpath=this[ne].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){if(!this[K]){if(this[b]){let t=this[b];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[K]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}}[Ns](e){this[qi]+=e.length;let t=this[qi]/this[nt];return t>this.maxDecompressionRatio?(this.abort(new Error(`max decompression ratio exceeded: ${t.toFixed(2)} > ${this.maxDecompressionRatio}`)),!1):!0}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this[K])return i?.(),!1;if((this[b]===void 0||this.brotli===void 0&&this[b]===!1)&&e){if(this[y]&&(e=Buffer.concat([this[y],e]),this[y]=void 0),e.length<ih)return this[y]=e,i?.(),!0;for(let o=0;this[b]===void 0&&o<hr.length;o++)e[o]!==hr[o]&&(this[b]=!1);let s=!1;if(this[b]===!1&&this.zstd!==!1){s=!0;for(let o=0;o<lr.length;o++)if(e[o]!==lr[o]){s=!1;break}}let n=this.brotli===void 0&&!s;if(this[b]===!1&&n)if(e.length<512)if(this[oe])this.brotli=!0;else return this[y]=e,i?.(),!0;else try{new Pe(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[b]===void 0||this[b]===!1&&(this.brotli||s)){let o=this[oe];this[oe]=!1,this[b]=this[b]===void 0?new Oa({}):s?new La({}):new xa({}),this[b].on("data",h=>{this[Ns](h)&&this[Wt](h)}),this[b].on("error",h=>{this[K]||this.abort(h)}),this[b].on("end",()=>{this[oe]=!0,this[Wt]()}),this[Me]=!0,this[nt]+=e.length;let a=!!this[b][o?"end":"write"](e);return this[Me]=!1,i?.(),a}}this[Me]=!0,this[b]?(this[nt]+=e.length,this[b].write(e)):this[Wt](e),this[Me]=!1;let r=this[ee].length>0?!1:this[Q]?this[Q].flowing:!0;return!r&&this[ee].length===0&&this[Q]?.once("drain",()=>this.emit("drain")),i?.(),r}[Yi](e){e&&!this[K]&&(this[y]=this[y]?Buffer.concat([this[y],e]):e)}[Zt](){if(this[oe]&&!this[Ki]&&!this[K]&&!this[st]){this[Ki]=!0;let e=this[ve];if(e?.blockRemain){let t=this[y]?this[y].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[y]&&e.write(this[y]),e.end()}this[Re](Kt)}}[Wt](e){if(this[st]&&e)this[Yi](e);else if(!e&&!this[y])this[Zt]();else if(e){if(this[st]=!0,this[y]){this[Yi](e);let t=this[y];this[y]=void 0,this[Gt](t)}else this[Gt](e);for(;this[y]&&this[y]?.length>=512&&!this[K]&&!this[Yt];){let t=this[y];this[y]=void 0,this[Gt](t)}this[st]=!1}(!this[y]||this[oe])&&this[Zt]()}[Gt](e){let t=0,i=e.length;for(;t+512<=i&&!this[K]&&!this[Yt];)switch(this[C]){case"begin":case"header":this[As](e,t),t+=512;break;case"ignore":case"body":t+=this[Vi](e,t);break;case"meta":t+=this[Ds](e,t);break;default:throw new Error("invalid state: "+this[C])}t<i&&(this[y]=this[y]?Buffer.concat([e.subarray(t),this[y]]):e.subarray(t))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t)),i&&this.once("finish",i),this[K]||(this[b]?(e&&(this[nt]+=e.length,this[b].write(e)),this[b].end()):(this[oe]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[Zt]())),this}},pt=e=>{let t=e.length-1,i=-1;for(;t>-1&&e.charAt(t)==="/";)i=t,t--;return i===-1?e:e.slice(0,i)},nh=e=>{let t=e.onReadEntry;e.onReadEntry=t?i=>{t(i),i.resume()}:i=>i.resume()},gn=(e,t)=>{let i=new Map(t.map(o=>[pt(o),!0])),r=e.filter,s=100,n=(o,a="",h=0)=>{if(h>=s)return i.set(o,!1),!1;let l=a||ua(o).root||".",c;if(o===l)c=!1;else{let d=i.get(o);c=d!==void 0?d:n(da(o),l,h+1)}return i.set(o,c),c};e.filter=r?(o,a)=>r(o,a)&&n(pt(o)):o=>n(pt(o))},oh=e=>{let t=new St(e),i=e.file,r;try{r=He.openSync(i,"r");let s=He.fstatSync(r),n=e.maxReadSize||16*1024*1024;if(s.size<n){let o=Buffer.allocUnsafe(s.size),a=He.readSync(r,o,0,s.size,0);t.end(a===o.byteLength?o:o.subarray(0,a))}else{let o=0,a=Buffer.allocUnsafe(n);for(;o<s.size;){let h=He.readSync(r,a,0,n,o);if(h===0)break;o+=h,t.write(a.subarray(0,h))}t.end()}}finally{if(typeof r=="number")try{He.closeSync(r)}catch{}}},ah=(e,t)=>{let i=new St(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("end",n),He.stat(s,(a,h)=>{if(a)o(a);else{let l=new Tr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},yi=vt(oh,ah,e=>new St(e),e=>new St(e),(e,t)=>{t?.length&&gn(e,t),e.noResume||nh(e)}),yn=(e,t,i)=>(e&=4095,i&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),{isAbsolute:lh,parse:Ms}=hh,Dr=e=>{let t="",i=Ms(e);for(;lh(e)||i.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":i.root;e=e.slice(r.length),t+=r,i=Ms(e)}return[t,e]},wi=["|","<",">","?",":"],Ar=wi.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),ch=new Map(wi.map((e,t)=>[e,Ar[t]])),dh=new Map(Ar.map((e,t)=>[e,wi[t]])),Fs=e=>wi.reduce((t,i)=>t.split(i).join(ch.get(i)),e),uh=e=>Ar.reduce((t,i)=>t.split(i).join(dh.get(i)),e),wn=(e,t)=>t?(e=u(e).replace(/^\.(\/|$)/,""),pt(t)+"/"+e):u(e),mh=16*1024*1024,Bs=Symbol("process"),$s=Symbol("file"),Us=Symbol("directory"),cr=Symbol("symlink"),zs=Symbol("hardlink"),ot=Symbol("header"),ti=Symbol("read"),dr=Symbol("lstat"),ii=Symbol("onlstat"),ur=Symbol("onread"),mr=Symbol("onreadlink"),pr=Symbol("openfile"),fr=Symbol("onopenfile"),de=Symbol("close"),di=Symbol("mode"),gr=Symbol("awaitDrain"),Ji=Symbol("ondrain"),Y=Symbol("prefix"),bn=class extends Le{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 i=xr(t);super(),this.path=u(e),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||mh,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=u(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?u(i.prefix):void 0,this.onWriteEntry=i.onWriteEntry,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let r=!1;if(!this.preservePaths){let[n,o]=Dr(this.path);n&&typeof o=="string"&&(this.path=o,r=n)}this.win32=!!i.win32||process.platform==="win32",this.win32&&(this.path=uh(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=u(i.absolute||Cs.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 s=this.statCache.get(this.absolute);s?this[ii](s):this[dr]()}warn(e,t,i={}){return gi(this,e,t,i)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[dr](){V.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[ii](t)})}[ii](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=gh(e),this.emit("stat",e),this[Bs]()}[Bs](){switch(this.type){case"File":return this[$s]();case"Directory":return this[Us]();case"SymbolicLink":return this[cr]();default:return this.end()}}[di](e){return yn(e,this.type==="Directory",this.portable)}[Y](e){return wn(e,this.prefix)}[ot](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Pe({path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this[di](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 li({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 new Error("failed to encode header");super.write(e)}[Us](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ot](),this.end()}[cr](){V.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[mr](t)})}[mr](e){this.linkpath=u(e),this[ot](),this.end()}[zs](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=u(Cs.relative(this.cwd,e)),this.stat.size=0,this[ot](),this.end()}[$s](){if(!this.stat)throw new 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[zs](t);this.linkCache.set(e,this.absolute)}if(this[ot](),this.stat.size===0)return this.end();this[pr]()}[pr](){V.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[fr](t)})}[fr](e){if(this.fd=e,this.#e)return this[de]();if(!this.stat)throw new 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[ti]()}[ti](){let{fd:e,buf:t,offset:i,length:r,pos:s}=this;if(e===void 0||t===void 0)throw new Error("cannot read file without first opening");V.read(e,t,i,r,s,(n,o)=>{if(n)return this[de](()=>this.emit("error",n));this[ur](o)})}[de](e=()=>{}){this.fd!==void 0&&V.close(this.fd,e)}[ur](e){if(e<=0&&this.remain>0){let i=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[de](()=>this.emit("error",i))}if(e>this.remain){let i=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[de](()=>this.emit("error",i))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(e===this.remain)for(let i=e;i<this.length&&e<this.blockRemain;i++)this.buf[i+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[Ji]():this[gr](()=>this[Ji]())}[gr](e){this.once("drain",e)}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this.blockRemain<e.length){let r=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",r)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,i)}[Ji](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[de](e=>e?this.emit("error",e):this.end());if(!this.buf)throw new 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[ti]()}},ph=class extends bn{sync=!0;[dr](){this[ii](V.lstatSync(this.absolute))}[cr](){this[mr](V.readlinkSync(this.absolute))}[pr](){this[fr](V.openSync(this.absolute,"r"))}[ti](){let e=!0;try{let{fd:t,buf:i,offset:r,length:s,pos:n}=this;if(t===void 0||i===void 0)throw new Error("fd and buf must be set in READ method");let o=V.readSync(t,i,r,s,n);this[ur](o),e=!1}finally{if(e)try{this[de](()=>{})}catch{}}}[gr](e){e()}[de](e=()=>{}){this.fd!==void 0&&V.closeSync(this.fd),e()}},fh=class extends Le{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,i={}){return gi(this,e,t,i)}constructor(e,t={}){let i=xr(t);super(),this.preservePaths=!!i.preservePaths,this.portable=!!i.portable,this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.onWriteEntry=i.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r==="Unsupported")throw new Error("writing entry that should be ignored");this.type=r,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=i.prefix,this.path=u(e.path),this.mode=e.mode!==void 0?this[di](e.mode):void 0,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:i.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?u(e.linkpath):void 0,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){let[o,a]=Dr(this.path);o&&typeof a=="string"&&(this.path=a,s=o)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new Pe({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}),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path}),this.header.encode()&&!this.noPax&&super.write(new li({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 n=this.header?.block;if(!n)throw new Error("failed to encode header");super.write(n),e.pipe(this)}[Y](e){return wn(e,this.prefix)}[di](e){return yn(e,this.type==="Directory",this.portable)}write(e,t,i){typeof t=="function"&&(i=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 new Error("writing more to entry than is appropriate");return this.blockRemain-=r,super.write(e,i)}end(e,t,i){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t??"utf8")),i&&this.once("finish",i),e?super.end(e,i):super.end(i),this}},gh=e=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",yh=class je{tail;head;length=0;static create(t=[]){return new je(t)}constructor(t=[]){for(let i of t)this.push(i)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");let i=t.next,r=t.prev;return i&&(i.prev=r),r&&(r.next=i),t===this.head&&(this.head=i),t===this.tail&&(this.tail=r),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,i}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);let i=this.head;t.list=this,t.next=i,i&&(i.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}pushNode(t){if(t===this.tail)return;t.list&&t.list.removeNode(t);let i=this.tail;t.list=this,t.prev=i,i&&(i.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let i=0,r=t.length;i<r;i++)bh(this,t[i]);return this.length}unshift(...t){for(var i=0,r=t.length;i<r;i++)Eh(this,t[i]);return this.length}pop(){if(!this.tail)return;let t=this.tail.value,i=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,i.list=void 0,this.length--,t}shift(){if(!this.head)return;let t=this.head.value,i=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,i.list=void 0,this.length--,t}forEach(t,i){i=i||this;for(let r=this.head,s=0;r;s++)t.call(i,r.value,s,this),r=r.next}forEachReverse(t,i){i=i||this;for(let r=this.tail,s=this.length-1;r;s--)t.call(i,r.value,s,this),r=r.prev}get(t){let i=0,r=this.head;for(;r&&i<t;i++)r=r.next;if(i===t&&r)return r.value}getReverse(t){let i=0,r=this.tail;for(;r&&i<t;i++)r=r.prev;if(i===t&&r)return r.value}map(t,i){i=i||this;let r=new je;for(let s=this.head;s;)r.push(t.call(i,s.value,this)),s=s.next;return r}mapReverse(t,i){i=i||this;var r=new je;for(let s=this.tail;s;)r.push(t.call(i,s.value,this)),s=s.prev;return r}reduce(t,i){let r,s=this.head;if(arguments.length>1)r=i;else if(this.head)s=this.head.next,r=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var n=0;s;n++)r=t(r,s.value,n),s=s.next;return r}reduceReverse(t,i){let r,s=this.tail;if(arguments.length>1)r=i;else if(this.tail)s=this.tail.prev,r=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let n=this.length-1;s;n--)r=t(r,s.value,n),s=s.prev;return r}toArray(){let t=new Array(this.length);for(let i=0,r=this.head;r;i++)t[i]=r.value,r=r.next;return t}toArrayReverse(){let t=new Array(this.length);for(let i=0,r=this.tail;r;i++)t[i]=r.value,r=r.prev;return t}slice(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new je;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.head,n=0;for(n=0;s&&n<t;n++)s=s.next;for(;s&&n<i;n++,s=s.next)r.push(s.value);return r}sliceReverse(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new je;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.length,n=this.tail;for(;n&&s>i;s--)n=n.prev;for(;n&&s>t;s--,n=n.prev)r.push(n.value);return r}splice(t,i=0,...r){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let s=this.head;for(let o=0;s&&o<t;o++)s=s.next;let n=[];for(let o=0;s&&o<i;o++)n.push(s.value),s=this.removeNode(s);s?s!==this.tail&&(s=s.prev):s=this.tail;for(let o of r)s=wh(this,s,o);return n}reverse(){let t=this.head,i=this.tail;for(let r=t;r;r=r.prev){let s=r.prev;r.prev=r.next,r.next=s}return this.head=i,this.tail=t,this}};function wh(e,t,i){let r=t,s=t?t.next:e.head,n=new Ir(i,r,s,e);return n.next===void 0&&(e.tail=n),n.prev===void 0&&(e.head=n),e.length++,n}function bh(e,t){e.tail=new Ir(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function Eh(e,t){e.head=new Ir(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Ir=class{list;next;prev;value;constructor(e,t,i,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,i?(i.prev=this,this.next=i):this.next=void 0}},js=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||"./",this.absolute=t}},Ws=Buffer.alloc(1024),ri=Symbol("onStat"),at=Symbol("ended"),$=Symbol("queue"),ht=Symbol("pendingLinks"),ae=Symbol("current"),ke=Symbol("process"),lt=Symbol("processing"),qt=Symbol("processJob"),U=Symbol("jobs"),Xi=Symbol("jobDone"),si=Symbol("addFSEntry"),Gs=Symbol("addTarEntry"),yr=Symbol("stat"),wr=Symbol("readdir"),ni=Symbol("onreaddir"),oi=Symbol("pipe"),Zs=Symbol("entry"),Qi=Symbol("entryOpt"),ai=Symbol("writeEntryClass"),En=Symbol("write"),er=Symbol("ondrain"),bi=class extends Le{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[ai];onWriteEntry;[$];[ht]=new Map;[U]=0;[lt]=!1;[at]=!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=u(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[ai]=bn,typeof e.onwarn=="function"&&this.on("warn",e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if((e.gzip?1:0)+(e.brotli?1:0)+(e.zstd?1:0)>1)throw new 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 ka(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new Ta(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new Pa(e.zstd)),!this.zip)throw new Error("impossible");let t=this.zip;t.on("data",i=>super.write(i)),t.on("end",()=>super.end()),t.on("drain",()=>this[er]()),this.on("resume",()=>t.resume())}else this.on("drain",this[er]);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[$]=new yh,this[U]=0,this.jobs=Number(e.jobs)||4,this[lt]=!1,this[at]=!1}[En](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&this.add(e),this[at]=!0,this[ke](),i&&i(),this}write(e){if(this[at])throw new Error("write after end");return typeof e=="string"?this[si](e):this[Gs](e),this.flowing}[Gs](e){let t=u(Hs.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let i=new js(e.path,t);i.entry=new fh(e,this[Qi](i)),i.entry.on("end",()=>this[Xi](i)),this[U]+=1,this[$].push(i)}this[ke]()}[si](e){let t=u(Hs.resolve(this.cwd,e));this[$].push(new js(e,t)),this[ke]()}[yr](e){e.pending=!0,this[U]+=1;let t=this.follow?"stat":"lstat";ci[t](e.absolute,(i,r)=>{e.pending=!1,this[U]-=1,i?this.emit("error",i):this[ri](e,r)})}[ri](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[ae])this[qt](e);else{let i=`${t.dev}:${t.ino}`,r=this[ht].get(i);r?r.push(e):this[ht].set(i,[e]),e.pendingLink=!0,e.pending=!0}this[ke]()}[wr](e){e.pending=!0,this[U]+=1,ci.readdir(e.absolute,(t,i)=>{if(e.pending=!1,this[U]-=1,t)return this.emit("error",t);this[ni](e,i)})}[ni](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[ke]()}[ke](){if(!this[lt]){this[lt]=!0;for(let e=this[$].head;e&&this[U]<this.jobs;e=e.next)if(this[qt](e.value),e.value.ignore){let t=e.next;this[$].removeNode(e),e.next=t}this[lt]=!1,this[at]&&this[$].length===0&&this[U]===0&&(this.zip?this.zip.end(Ws):(super.write(Ws),super.end()))}}get[ae](){return this[$]&&this[$].head&&this[$].head.value}[Xi](e){this[$].shift(),this[U]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let i=`${t.dev}:${t.ino}`,r=this[ht].get(i);if(r){this[ht].delete(i);for(let s of r)s.pending=!1,this[qt](s)}}this[ke]()}[qt](e){if(e.pending&&e.pendingLink&&e===this[ae]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[ae]&&!e.piped&&this[oi](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[ri](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[ni](e,t):this[wr](e),!e.readdir)return}if(e.entry=this[Zs](e),!e.entry){e.ignore=!0;return}e===this[ae]&&!e.piped&&this[oi](e)}}}[Qi](e){return{onwarn:(t,i,r)=>this.warn(t,i,r),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}}[Zs](e){this[U]+=1;try{return new this[ai](e.path,this[Qi](e)).on("end",()=>this[Xi](e)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[er](){this[ae]&&this[ae].entry&&this[ae].entry.resume()}[oi](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[si](n+r)});let t=e.entry,i=this.zip;if(!t)throw new Error("cannot pipe without source");i?t.on("data",r=>{i.write(r)||t.pause()}):t.on("data",r=>{super.write(r)||t.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,t,i={}){gi(this,e,t,i)}},Nr=class extends bi{sync=!0;constructor(e){super(e),this[ai]=ph}pause(){}resume(){}[yr](e){let t=this.follow?"statSync":"lstatSync";this[ri](e,ci[t](e.absolute))}[wr](e){this[ni](e,ci.readdirSync(e.absolute))}[oi](e){let t=e.entry,i=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[si](n+r)}),!t)throw new Error("Cannot pipe without source");i?t.on("data",r=>{i.write(r)}):t.on("data",r=>{super[En](r)})}},Sh=(e,t)=>{let i=new Nr(e),r=new an(e.file,{mode:e.mode||438});i.pipe(r),Sn(i,t)},vh=(e,t)=>{let i=new bi(e),r=new pi(e.file,{mode:e.mode||438});i.pipe(r);let s=new Promise((n,o)=>{r.on("error",o),r.on("close",n),i.on("error",o)});return vn(i,t).catch(n=>i.emit("error",n)),s},Sn=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?yi({file:hn.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},vn=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await yi({file:hn.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>{e.add(r)}}):e.add(i);e.end()},Rh=(e,t)=>{let i=new Nr(e);return Sn(i,t),i},_h=(e,t)=>{let i=new bi(e);return vn(i,t).catch(r=>i.emit("error",r)),i},cd=vt(Sh,vh,Rh,_h,(e,t)=>{if(!t?.length)throw new TypeError("no paths specified to add to archive")}),Oh=process.env.__FAKE_PLATFORM__||process.platform,On=Oh==="win32",{O_CREAT:Tn,O_NOFOLLOW:Ks,O_TRUNC:xn,O_WRONLY:Pn}=kn.constants,Ln=Number(process.env.__FAKE_FS_O_FILENAME__)||kn.constants.UV_FS_O_FILEMAP||0,Th=On&&!!Ln,xh=512*1024,Ph=Ln|xn|Tn|Pn,Vs=!On&&typeof Ks=="number"?Ks|xn|Tn|Pn:null,Dn=Vs!==null?()=>Vs:Th?e=>e<xh?Ph:"w":()=>"w",br=(e,t,i)=>{try{return Ei.lchownSync(e,t,i)}catch(r){if(r?.code!=="ENOENT")throw r}},ui=(e,t,i,r)=>{Ei.lchown(e,t,i,s=>{r(s&&s?.code!=="ENOENT"?s:null)})},Lh=(e,t,i,r,s)=>{if(t.isDirectory())An(ft.resolve(e,t.name),i,r,n=>{if(n)return s(n);let o=ft.resolve(e,t.name);ui(o,i,r,s)});else{let n=ft.resolve(e,t.name);ui(n,i,r,s)}},An=(e,t,i,r)=>{Ei.readdir(e,{withFileTypes:!0},(s,n)=>{if(s){if(s.code==="ENOENT")return r();if(s.code!=="ENOTDIR"&&s.code!=="ENOTSUP")return r(s)}if(s||!n.length)return ui(e,t,i,r);let o=n.length,a=null,h=l=>{if(!a){if(l)return r(a=l);if(--o===0)return ui(e,t,i,r)}};for(let l of n)Lh(e,l,t,i,h)})},Dh=(e,t,i,r)=>{t.isDirectory()&&In(ft.resolve(e,t.name),i,r),br(ft.resolve(e,t.name),i,r)},In=(e,t,i)=>{let r;try{r=Ei.readdirSync(e,{withFileTypes:!0})}catch(s){let n=s;if(n?.code==="ENOENT")return;if(n?.code==="ENOTDIR"||n?.code==="ENOTSUP")return br(e,t,i);throw n}for(let s of r)Dh(e,s,t,i);return br(e,t,i)},Nn=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"}},Si=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"}},Ih=(e,t)=>{N.stat(e,(i,r)=>{(i||!r.isDirectory())&&(i=new Nn(e,i?.code||"ENOTDIR")),t(i)})},Nh=(e,t,i)=>{e=u(e);let r=t.umask??18,s=t.mode|448,n=(s&r)!==0,o=t.uid,a=t.gid,h=typeof o=="number"&&typeof a=="number"&&(o!==t.processUid||a!==t.processGid),l=t.preserve,c=t.unlink,d=u(t.cwd),p=(g,E)=>{g?i(g):E&&h?An(E,o,a,F=>p(F)):n?N.chmod(e,s,i):i()};if(e===d)return Ih(e,p);if(l)return Ah.mkdir(e,{mode:s,recursive:!0}).then(g=>p(null,g??void 0),p);let w=u(mi.relative(d,e)).split("/");Er(d,w,s,c,d,void 0,p)},Er=(e,t,i,r,s,n,o)=>{if(t.length===0)return o(null,n);let a=t.shift(),h=u(mi.resolve(e+"/"+a));N.mkdir(h,i,Cn(h,t,i,r,s,n,o))},Cn=(e,t,i,r,s,n,o)=>a=>{a?N.lstat(e,(h,l)=>{if(h)h.path=h.path&&u(h.path),o(h);else if(l.isDirectory())Er(e,t,i,r,s,n,o);else if(r)N.unlink(e,c=>{if(c)return o(c);N.mkdir(e,i,Cn(e,t,i,r,s,n,o))});else{if(l.isSymbolicLink())return o(new Si(e,e+"/"+t.join("/")));o(a)}}):(n=n||e,Er(e,t,i,r,s,n,o))},Ch=e=>{let t=!1,i;try{t=N.statSync(e).isDirectory()}catch(r){i=r?.code}finally{if(!t)throw new Nn(e,i??"ENOTDIR")}},Mh=(e,t)=>{e=u(e);let i=t.umask??18,r=t.mode|448,s=(r&i)!==0,n=t.uid,o=t.gid,a=typeof n=="number"&&typeof o=="number"&&(n!==t.processUid||o!==t.processGid),h=t.preserve,l=t.unlink,c=u(t.cwd),d=g=>{g&&a&&In(g,n,o),s&&N.chmodSync(e,r)};if(e===c)return Ch(c),d();if(h)return d(N.mkdirSync(e,{mode:r,recursive:!0})??void 0);let p=u(mi.relative(c,e)).split("/"),w;for(let g=p.shift(),E=c;g&&(E+="/"+g);g=p.shift()){E=u(mi.resolve(E));try{N.mkdirSync(E,r),w=w||E}catch{let F=N.lstatSync(E);if(F.isDirectory())continue;if(l){N.unlinkSync(E),N.mkdirSync(E,r),w=w||E;continue}else if(F.isSymbolicLink())return new Si(E,E+"/"+p.join("/"))}}return d(w)},tr=Object.create(null),Ys=1e4,Fe=new Set,Fh=e=>{Fe.has(e)?Fe.delete(e):tr[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Fe.add(e);let t=tr[e],i=Fe.size-Ys;if(i>Ys/10){for(let r of Fe)if(Fe.delete(r),delete tr[r],--i<=0)break}return t},Bh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,$h=Bh==="win32",Uh=e=>e.split("/").slice(0,-1).reduce((t,i)=>{let r=t.at(-1);return r!==void 0&&(i=Mn(r,i)),t.push(i||"/"),t},[]),zh=class{#e=new Map;#i=new Map;#r=new Set;reserve(e,t){e=$h?["win32 parallelization disabled"]:e.map(r=>pt(Mn(Fh(r))));let i=new Set(e.map(r=>Uh(r)).reduce((r,s)=>r.concat(s)));this.#i.set(t,{dirs:i,paths:e});for(let r of e){let s=this.#e.get(r);s?s.push(t):this.#e.set(r,[t])}for(let r of i){let s=this.#e.get(r);if(!s)this.#e.set(r,[new Set([t])]);else{let n=s.at(-1);n instanceof Set?n.add(t):s.push(new Set([t]))}}return this.#s(t)}#n(e){let t=this.#i.get(e);if(!t)throw new Error("function does not have any path reservations");return{paths:t.paths.map(i=>this.#e.get(i)),dirs:[...t.dirs].map(i=>this.#e.get(i))}}check(e){let{paths:t,dirs:i}=this.#n(e);return t.every(r=>r&&r[0]===e)&&i.every(r=>r&&r[0]instanceof Set&&r[0].has(e))}#s(e){return this.#r.has(e)||!this.check(e)?!1:(this.#r.add(e),e(()=>this.#t(e)),!0)}#t(e){if(!this.#r.has(e))return!1;let t=this.#i.get(e);if(!t)throw new Error("invalid reservation");let{paths:i,dirs:r}=t,s=new Set;for(let n of i){let o=this.#e.get(n);if(!o||o?.[0]!==e)continue;let a=o[1];if(!a){this.#e.delete(n);continue}if(o.shift(),typeof a=="function")s.add(a);else for(let h of a)s.add(h)}for(let n of r){let o=this.#e.get(n),a=o?.[0];if(!(!o||!(a instanceof Set)))if(a.size===1&&o.length===1){this.#e.delete(n);continue}else if(a.size===1){o.shift();let h=o[0];typeof h=="function"&&s.add(h)}else a.delete(e)}return this.#r.delete(e),s.forEach(n=>this.#s(n)),!0}},Hh=()=>process.umask(),qs=Symbol("onEntry"),Sr=Symbol("checkFs"),Js=Symbol("checkFs2"),vr=Symbol("isReusable"),M=Symbol("makeFs"),Rr=Symbol("file"),_r=Symbol("directory"),hi=Symbol("link"),Xs=Symbol("symlink"),Qs=Symbol("hardlink"),ut=Symbol("ensureNoSymlink"),en=Symbol("unsupported"),tn=Symbol("checkPath"),ir=Symbol("stripAbsolutePath"),ue=Symbol("mkdir"),O=Symbol("onError"),Jt=Symbol("pending"),rn=Symbol("pend"),Be=Symbol("unpend"),rr=Symbol("ended"),sr=Symbol("maybeClose"),kr=Symbol("skip"),gt=Symbol("doChown"),yt=Symbol("uid"),wt=Symbol("gid"),bt=Symbol("checkedCwd"),jh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Et=jh==="win32",Wh=1024,Gh=(e,t)=>{if(!Et)return m.unlink(e,t);let i=e+".DELETE."+_n(16).toString("hex");m.rename(e,i,r=>{if(r)return t(r);m.unlink(i,t)})},Zh=e=>{if(!Et)return m.unlinkSync(e);let t=e+".DELETE."+_n(16).toString("hex");m.renameSync(e,t),m.unlinkSync(t)},sn=(e,t,i)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:i,Cr=class extends St{[rr]=!1;[bt]=!1;[Jt]=0;reservations=new zh;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[rr]=!0,this[sr]()},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 new TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw new 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?.()===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:Wh,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||Et,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=u(v.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:Hh():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",t=>this[qs](t))}warn(e,t,i={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(i.recoverable=!1),super.warn(e,t,i)}[sr](){this[rr]&&this[Jt]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[ir](e,t){let i=e[t],{type:r}=e;if(!i||this.preservePaths)return!0;let[s,n]=Dr(i),o=n.replaceAll(/\\/g,"/").split("/");if(o.includes("..")||Et&&/^[a-z]:\.\.$/i.test(o[0]??"")){if(t==="path"||r==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:i}),!1;let a=v.posix.dirname(e.path),h=v.posix.normalize(v.posix.join(a,o.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:i}),!1}return s&&(e[t]=String(n),this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute ${t}`,{entry:e,[t]:i})),!0}[tn](e){let t=u(e.path),i=t.split("/");if(this.strip){if(i.length<this.strip)return!1;if(e.type==="Link"){let r=u(String(e.linkpath)).split("/");if(r.length>=this.strip)e.linkpath=r.slice(this.strip).join("/");else return!1}i.splice(0,this.strip),e.path=i.join("/")}if(isFinite(this.maxDepth)&&i.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:i.length,maxDepth:this.maxDepth}),!1;if(!this[ir](e,"path")||!this[ir](e,"linkpath"))return!1;if(e.absolute=v.isAbsolute(e.path)?u(v.resolve(e.path)):u(v.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:u(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:r}=v.win32.parse(String(e.absolute));e.absolute=r+Fs(String(e.absolute).slice(r.length));let{root:s}=v.win32.parse(e.path);e.path=s+Fs(e.path.slice(s.length))}return!0}[qs](e){if(!this[tn](e))return e.resume();switch(kh.equal(typeof e.absolute,"string"),e.type){case"Directory":case"GNUDumpDir":e.mode&&(e.mode=e.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Sr](e);default:return this[en](e)}}[O](e,t){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:t}),this[Be](),t.resume())}[ue](e,t,i){Nh(u(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},i)}[gt](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}[yt](e){return sn(this.uid,e.uid,this.processUid)}[wt](e){return sn(this.gid,e.gid,this.processGid)}[Rr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new pi(String(e.absolute),{flags:Dn(e.size),mode:i,autoClose:!1});r.on("error",a=>{r.fd&&m.close(r.fd,()=>{}),r.write=()=>!0,this[O](a,e),t()});let s=1,n=a=>{if(a){r.fd&&m.close(r.fd,()=>{}),this[O](a,e),t();return}--s===0&&r.fd!==void 0&&m.close(r.fd,h=>{h?this[O](h,e):this[Be](),t()})};r.on("finish",()=>{let a=String(e.absolute),h=r.fd;if(typeof h=="number"&&e.mtime&&!this.noMtime){s++;let l=e.atime||new Date,c=e.mtime;m.futimes(h,l,c,d=>d?m.utimes(a,l,c,p=>n(p&&d)):n())}if(typeof h=="number"&&this[gt](e)){s++;let l=this[yt](e),c=this[wt](e);typeof l=="number"&&typeof c=="number"&&m.fchown(h,l,c,d=>d?m.chown(a,l,c,p=>n(p&&d)):n())}n()});let o=this.transform&&this.transform(e)||e;o!==e&&(o.on("error",a=>{this[O](a,e),t()}),e.pipe(o)),o.pipe(r)}[_r](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode;this[ue](String(e.absolute),i,r=>{if(r){this[O](r,e),t();return}let s=1,n=()=>{--s===0&&(t(),this[Be](),e.resume())};e.mtime&&!this.noMtime&&(s++,m.utimes(String(e.absolute),e.atime||new Date,e.mtime,n)),this[gt](e)&&(s++,m.chown(String(e.absolute),Number(this[yt](e)),Number(this[wt](e)),n)),n()})}[en](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[Xs](e,t){let i=u(v.relative(this.cwd,v.resolve(v.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[ut](e,this.cwd,i,()=>this[hi](e,String(e.linkpath),"symlink",t),r=>{this[O](r,e),t()})}[Qs](e,t){let i=u(v.resolve(this.cwd,String(e.linkpath))),r=u(String(e.linkpath)).split("/");this[ut](e,this.cwd,r,()=>this[hi](e,i,"link",t),s=>{this[O](s,e),t()})}[ut](e,t,i,r,s){let n=i.shift();if(this.preservePaths||n===void 0)return r();let o=v.resolve(t,n);m.lstat(o,(a,h)=>{if(a)return r();if(h?.isSymbolicLink())return s(new Si(o,v.resolve(o,i.join("/"))));this[ut](e,o,i,r,s)})}[rn](){this[Jt]++}[Be](){this[Jt]--,this[sr]()}[kr](e){this[Be](),e.resume()}[vr](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!Et}[Sr](e){this[rn]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,i=>this[Js](e,i))}[Js](e,t){let i=o=>{t(o)},r=()=>{this[ue](this.cwd,this.dmode,o=>{if(o){this[O](o,e),i();return}this[bt]=!0,s()})},s=()=>{if(e.absolute!==this.cwd){let o=u(v.dirname(String(e.absolute)));if(o!==this.cwd)return this[ue](o,this.dmode,a=>{if(a){this[O](a,e),i();return}n()})}n()},n=()=>{m.lstat(String(e.absolute),(o,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[kr](e),i();return}if(o||this[vr](e,a))return this[M](null,e,i);if(a.isDirectory()){if(e.type==="Directory"){let h=this.chmod&&e.mode&&(a.mode&4095)!==e.mode,l=c=>this[M](c??null,e,i);return h?m.chmod(String(e.absolute),Number(e.mode),l):l()}if(e.absolute!==this.cwd)return m.rmdir(String(e.absolute),h=>this[M](h??null,e,i))}if(e.absolute===this.cwd)return this[M](null,e,i);Gh(String(e.absolute),h=>this[M](h??null,e,i))})};this[bt]?s():r()}[M](e,t,i){if(e){this[O](e,t),i();return}switch(t.type){case"File":case"OldFile":case"ContiguousFile":return this[Rr](t,i);case"Link":return this[Qs](t,i);case"SymbolicLink":return this[Xs](t,i);case"Directory":case"GNUDumpDir":return this[_r](t,i)}}[hi](e,t,i,r){m[i](t,String(e.absolute),s=>{s?this[O](s,e):(this[Be](),e.resume()),r()})}},ct=e=>{try{return[null,e()]}catch(t){return[t,null]}},Fn=class extends Cr{sync=!0;[M](e,t){return super[M](e,t,()=>{})}[Sr](e){if(!this[bt]){let s=this[ue](this.cwd,this.dmode);if(s)return this[O](s,e);this[bt]=!0}if(e.absolute!==this.cwd){let s=u(v.dirname(String(e.absolute)));if(s!==this.cwd){let n=this[ue](s,this.dmode);if(n)return this[O](n,e)}}let[t,i]=ct(()=>m.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[kr](e);if(t||this[vr](e,i))return this[M](null,e);if(i.isDirectory()){if(e.type==="Directory"){let n=this.chmod&&e.mode&&(i.mode&4095)!==e.mode,[o]=n?ct(()=>{m.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[M](o,e)}let[s]=ct(()=>m.rmdirSync(String(e.absolute)));this[M](s,e)}let[r]=e.absolute===this.cwd?[]:ct(()=>Zh(String(e.absolute)));this[M](r,e)}[Rr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=o=>{let a;try{m.closeSync(s)}catch(h){a=h}(o||a)&&this[O](o||a,e),t()},s;try{s=m.openSync(String(e.absolute),Dn(e.size),i)}catch(o){return r(o)}let n=this.transform&&this.transform(e)||e;n!==e&&(n.on("error",o=>this[O](o,e)),e.pipe(n)),n.on("data",o=>{try{m.writeSync(s,o,0,o.length)}catch(a){r(a)}}),n.on("end",()=>{let o=null;if(e.mtime&&!this.noMtime){let a=e.atime||new Date,h=e.mtime;try{m.futimesSync(s,a,h)}catch(l){try{m.utimesSync(String(e.absolute),a,h)}catch{o=l}}}if(this[gt](e)){let a=this[yt](e),h=this[wt](e);try{m.fchownSync(s,Number(a),Number(h))}catch(l){try{m.chownSync(String(e.absolute),Number(a),Number(h))}catch{o=o||l}}}r(o)})}[_r](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[ue](String(e.absolute),i);if(r){this[O](r,e),t();return}if(e.mtime&&!this.noMtime)try{m.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[gt](e))try{m.chownSync(String(e.absolute),Number(this[yt](e)),Number(this[wt](e)))}catch{}t(),e.resume()}[ue](e,t){try{return Mh(u(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(i){return i}}[ut](e,t,i,r,s){if(this.preservePaths||i.length===0)return r();let n=t;for(let o of i){n=v.resolve(n,o);let[a,h]=ct(()=>m.lstatSync(n));if(a)return r();if(h.isSymbolicLink())return s(new Si(n,v.resolve(t,i.join("/"))))}r()}[hi](e,t,i,r){let s=`${i}Sync`;try{m[s](t,String(e.absolute)),r(),e.resume()}catch(n){return this[O](n,e)}}},Kh=e=>{let t=new Fn(e),i=e.file,r=Rn.statSync(i),s=e.maxReadSize||16*1024*1024;new ca(i,{readSize:s,size:r.size}).pipe(t)},Vh=(e,t)=>{let i=new Cr(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("close",n),Rn.stat(s,(a,h)=>{if(a)o(a);else{let l=new Tr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},Bn=vt(Kh,Vh,e=>new Fn(e),e=>new Cr(e),(e,t)=>{t?.length&&gn(e,t)}),Yh=(e,t)=>{let i=new Nr(e),r=!0,s,n;try{try{s=I.openSync(e.file,"r+")}catch(h){if(h?.code==="ENOENT")s=I.openSync(e.file,"w+");else throw h}let o=I.fstatSync(s),a=Buffer.alloc(512);e:for(n=0;n<o.size;n+=512){for(let c=0,d=0;c<512;c+=d){if(d=I.readSync(s,a,c,a.length-c,n+c),n===0&&a[0]===31&&a[1]===139)throw new Error("cannot append to compressed archives");if(!d)break e}let h=new Pe(a);if(!h.cksumValid)break;let l=512*Math.ceil((h.size||0)/512);if(n+l+512>o.size)break;n+=l,e.mtimeCache&&h.mtime&&e.mtimeCache.set(String(h.path),h.mtime)}r=!1,qh(e,i,n,s,t)}finally{if(r)try{I.closeSync(s)}catch{}}},qh=(e,t,i,r,s)=>{let n=new an(e.file,{fd:r,start:i});t.pipe(n),Xh(t,s)},Jh=(e,t)=>{t=Array.from(t);let i=new bi(e),r=(s,n,o)=>{let a=(p,w)=>{p?I.close(s,g=>o(p)):o(null,w)},h=0;if(n===0)return a(null,0);let l=0,c=Buffer.alloc(512),d=(p,w)=>{if(p||w===void 0)return a(p);if(l+=w,l<512&&w)return I.read(s,c,l,c.length-l,h+l,d);if(h===0&&c[0]===31&&c[1]===139)return a(new Error("cannot append to compressed archives"));if(l<512)return a(null,h);let g=new Pe(c);if(!g.cksumValid)return a(null,h);let E=512*Math.ceil((g.size??0)/512);if(h+E+512>n||(h+=E+512,h>=n))return a(null,h);e.mtimeCache&&g.mtime&&e.mtimeCache.set(String(g.path),g.mtime),l=0,I.read(s,c,0,512,h,d)};I.read(s,c,0,512,h,d)};return new Promise((s,n)=>{i.on("error",n);let o="r+",a=(h,l)=>{if(h&&h.code==="ENOENT"&&o==="r+")return o="w+",I.open(e.file,o,a);if(h||!l)return n(h);I.fstat(l,(c,d)=>{if(c)return I.close(l,()=>n(c));r(l,d.size,(p,w)=>{if(p)return n(p);let g=new pi(e.file,{fd:l,start:w});i.pipe(g),g.on("error",n),g.on("close",s),Qh(i,t)})})};I.open(e.file,o,a)})},Xh=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?yi({file:$n.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},Qh=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await yi({file:$n.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i);e.end()},dt=vt(Yh,Jh,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(e,t)=>{if(!wa(e))throw new TypeError("file is required");if(e.gzip||e.brotli||e.zstd||e.file.endsWith(".br")||e.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!t?.length)throw new TypeError("no paths specified to add/replace")}),kd=vt(dt.syncFile,dt.asyncFile,dt.syncNoFile,dt.asyncNoFile,(e,t=[])=>{dt.validate?.(e,t),el(e)}),el=e=>{let t=e.filter;e.mtimeCache||(e.mtimeCache=new Map),e.filter=t?(i,r)=>t(i,r)&&!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0)):(i,r)=>!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0))};var Rt=Ie("taco.cli.upgrade"),ol="https://registry.npmjs.org",zn=3e4;async function al(e,t,i,r){let s=i==="latest"?`${e}/${t}/latest`:`${e}/${t}/${i}`,n=new AbortController,o=setTimeout(()=>n.abort(),zn);try{let a=await r(s,{signal:n.signal});if(!a.ok)throw new Error(`registry returned ${a.status} ${a.statusText} for ${t}@${i}`);return await a.json()}finally{clearTimeout(o)}}async function hl(e,t,i){let r=new AbortController,s=setTimeout(()=>r.abort(),zn);try{let n=await i(e,{signal:r.signal});if(!n.ok)throw new Error(`tarball download ${n.status} ${n.statusText} for ${e}`);if(!n.body)throw new Error(`tarball response had no body for ${e}`);await Mr(Un(t),{recursive:!0});let o=await rl(t,"w");try{let a=0,h=n.body.getReader();for(;;){let{done:l,value:c}=await h.read();if(l)break;await o.write(c),a+=c.byteLength}return a}finally{await o.close()}}finally{clearTimeout(s)}}async function ll(e,t){let[i,r]=t.split("-");if(i!=="sha512")throw new Error(`unsupported integrity algorithm: ${i}`);let s=tl("sha512");await new Promise((o,a)=>{let h=il(e);h.on("data",l=>s.update(l)),h.on("end",()=>o()),h.on("error",a)});let n=s.digest("base64");if(n!==r)throw new Error(`integrity mismatch: expected ${r}, got ${n}`)}async function Hn(e={}){let t=e.fetcher??globalThis.fetch;if(typeof t!="function")throw new Error("global fetch is not available; pass opts.fetcher explicitly");let i=e.tacoHome??T,r=e.registry??ol,s=e.platformKey?{key:e.platformKey,pkg:`@taco-ai/sidecar-${e.platformKey}`}:Fr(),n=e.version??"latest";Rt.info(`fetching metadata for ${s.pkg}@${n}`);let o=await al(r,s.pkg,n,t);if(!o.dist?.tarball||!o.dist?.integrity)throw new Error(`registry response missing dist.tarball/integrity for ${s.pkg}@${n}`);let a=o.version,h=vi(i,"staging",`sidecar-${s.key}-${a}`),l=vi(i,"cache","sidecar",`sidecar-${s.key}-${a}.tgz`);Rt.info(`downloading tarball \u2192 ${l}`),await Mr(Un(l),{recursive:!0}),await hl(o.dist.tarball,l,t),Rt.info("verifying integrity"),await ll(l,o.dist.integrity),await sl(h,{recursive:!0,force:!0}),await Mr(h,{recursive:!0}),Rt.info(`extracting \u2192 ${h}`),await Bn({file:l,cwd:h,strip:1}),await cl(h);let c=e.liveDirOverride??await dl(s.key);if(!c)throw new Error(`no current @taco-ai/sidecar-${s.key} install found; run 'taco install' first`);let d={version:a,staging_dir:h,live_dir:c,written_at:new Date().toISOString()},p=vi(i,"upgrade-marker.json");return await as(p,d),Rt.info(`upgrade staged \u2192 version=${a}, marker=${p}`),{version:a,stagingDir:h,liveDir:c}}async function cl(e){for(let t of["manifest.json","bin","lib"]){let i=vi(e,t);try{await nl(i)}catch{throw new Error(`staged bundle missing ${t} at ${i}`)}}}async function dl(e){let{createRequire:t}=await import("node:module"),i=t(import.meta.url);try{let r=i.resolve(`@taco-ai/sidecar-${e}/package.json`),s=r.lastIndexOf("/package.json");return s<0?r:r.slice(0,s)}catch{return null}}var jn=`taco \u2014 launcher + supervisor for the sidecar daemon
|
|
83
|
+
`);if(g<0)return;let E=l.slice(0,g);try{let F=JSON.parse(E);"error"in F?d(()=>a(new Error(`${t}: ${F.error.code}: ${F.error.message}`))):d(()=>o(F.result))}catch(F){d(()=>a(new Error(`${t}: malformed reply: ${String(F)}`)))}}),h.on("end",()=>{c||d(()=>a(new Error(`${t}: socket closed before reply`)))}),h.on("close",()=>{c||d(()=>a(new Error(`${t}: socket closed before reply`)))})})}var Wo=2e3;async function ys(){let e=re(),t=await Mt(e,"control.ping",{timeoutMs:Wo});process.stdout.write(`${JSON.stringify(t)}
|
|
84
|
+
`)}import{existsSync as Go}from"node:fs";var Zo=3e3,ws=3e3;async function Ko(e){let t=Date.now();for(;Date.now()-t<ws;){if(process.platform==="win32")return;let i=!0;try{i=Go(e)}catch{i=!1}if(!i)return;await new Promise(r=>setTimeout(r,100))}throw new Error(`socket ${e} still present after ${ws}ms`)}async function bs(){let e=re(),t=await Mt(e,"control.shutdown",{timeoutMs:Zo});await Ko(e),process.stdout.write(`${JSON.stringify(t??{ok:!0})}
|
|
85
|
+
`)}import{existsSync as Vo,unlinkSync as Yo}from"node:fs";async function Es(){let e=_i();if(Vo(e)){await H("launchctl",["unload",e],{allowFailure:!0});try{Yo(e)}catch{}}return{serviceManager:"launchd"}}async function Ss(){return await H("schtasks",["/Delete","/TN",Ye,"/F"],{allowFailure:!0}),{serviceManager:"schtasks"}}async function vs(){return process.platform==="darwin"?Es():process.platform==="win32"?Ss():{serviceManager:"none"}}import{createHash as il}from"node:crypto";import{createReadStream as rl}from"node:fs";import{mkdir as Mr,open as sl,rm as nl,stat as ol}from"node:fs/promises";import{dirname as Un,join as vi}from"node:path";import Xo from"events";import L from"fs";import{EventEmitter as Or}from"node:events";import nn from"node:stream";import{StringDecoder as Qo}from"node:string_decoder";import hn from"node:path";import je from"node:fs";import{dirname as ua,parse as ma}from"path";import{EventEmitter as Sa}from"events";import ar from"assert";import{Buffer as Te}from"buffer";import*as Ts from"zlib";import va from"zlib";import{posix as Ce}from"node:path";import{basename as qa}from"node:path";import ci from"fs";import V from"fs";import Cs from"path";import{win32 as lh}from"node:path";import js from"path";import Rn from"node:fs";import Oh from"node:assert";import{randomBytes as _n}from"node:crypto";import m from"node:fs";import v from"node:path";import kn from"fs";import Ei from"node:fs";import ft from"node:path";import N from"node:fs";import Ih from"node:fs/promises";import mi from"node:path";import{join as Mn}from"node:path";import I from"node:fs";import $n from"node:path";var qo=Object.defineProperty,Jo=(e,t)=>{for(var i in t)qo(e,i,{get:t[i],enumerable:!0})},Rs=typeof process=="object"&&process?process:{stdout:null,stderr:null},ea=e=>!!e&&typeof e=="object"&&(e instanceof Le||e instanceof nn||ta(e)||ia(e)),ta=e=>!!e&&typeof e=="object"&&e instanceof Or&&typeof e.pipe=="function"&&e.pipe!==nn.Writable.prototype.pipe,ia=e=>!!e&&typeof e=="object"&&e instanceof Or&&typeof e.write=="function"&&typeof e.end=="function",J=Symbol("EOF"),X=Symbol("maybeEmitEnd"),se=Symbol("emittedEnd"),Ft=Symbol("emittingEnd"),Je=Symbol("emittedError"),Bt=Symbol("closed"),_s=Symbol("read"),$t=Symbol("flush"),ks=Symbol("flushChunk"),B=Symbol("encoding"),Ne=Symbol("decoder"),R=Symbol("flowing"),Xe=Symbol("paused"),$e=Symbol("resume"),_=Symbol("buffer"),P=Symbol("pipes"),k=Symbol("bufferLength"),Ai=Symbol("bufferPush"),Ut=Symbol("bufferShift"),x=Symbol("objectMode"),S=Symbol("destroyed"),Ii=Symbol("error"),Ni=Symbol("emitData"),Os=Symbol("emitEnd"),Ci=Symbol("emitEnd2"),W=Symbol("async"),Mi=Symbol("abort"),zt=Symbol("aborted"),Qe=Symbol("signal"),we=Symbol("dataListeners"),A=Symbol("discarded"),et=e=>Promise.resolve().then(e),ra=e=>e(),sa=e=>e==="end"||e==="finish"||e==="prefinish",na=e=>e instanceof ArrayBuffer||!!e&&typeof e=="object"&&e.constructor&&e.constructor.name==="ArrayBuffer"&&e.byteLength>=0,oa=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),on=class{src;dest;opts;ondrain;constructor(e,t,i){this.src=e,this.dest=t,this.opts=i,this.ondrain=()=>e[$e](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},aa=class extends on{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,i){super(e,t,i),this.proxyErrors=r=>this.dest.emit("error",r),e.on("error",this.proxyErrors)}},ha=e=>!!e.objectMode,la=e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",Le=class extends Or{[R]=!1;[Xe]=!1;[P]=[];[_]=[];[x];[B];[W];[Ne];[J]=!1;[se]=!1;[Ft]=!1;[Bt]=!1;[Je]=null;[k]=0;[S]=!1;[Qe];[zt]=!1;[we]=0;[A]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");ha(t)?(this[x]=!0,this[B]=null):la(t)?(this[B]=t.encoding,this[x]=!1):(this[x]=!1,this[B]=null),this[W]=!!t.async,this[Ne]=this[B]?new Qo(this[B]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[_]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[P]});let{signal:i}=t;i&&(this[Qe]=i,i.aborted?this[Mi]():i.addEventListener("abort",()=>this[Mi]()))}get bufferLength(){return this[k]}get encoding(){return this[B]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[x]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[W]}set async(e){this[W]=this[W]||!!e}[Mi](){this[zt]=!0,this.emit("abort",this[Qe]?.reason),this.destroy(this[Qe]?.reason)}get aborted(){return this[zt]}set aborted(e){}write(e,t,i){if(this[zt])return!1;if(this[J])throw new Error("write after end");if(this[S])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof t=="function"&&(i=t,t="utf8"),t||(t="utf8");let r=this[W]?et:ra;if(!this[x]&&!Buffer.isBuffer(e)){if(oa(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(na(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[x]?(this[R]&&this[k]!==0&&this[$t](!0),this[R]?this.emit("data",e):this[Ai](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[R]):e.length?(typeof e=="string"&&!(t===this[B]&&!this[Ne]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[B]&&(e=this[Ne].write(e)),this[R]&&this[k]!==0&&this[$t](!0),this[R]?this.emit("data",e):this[Ai](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[R]):(this[k]!==0&&this.emit("readable"),i&&r(i),this[R])}read(e){if(this[S])return null;if(this[A]=!1,this[k]===0||e===0||e&&e>this[k])return this[X](),null;this[x]&&(e=null),this[_].length>1&&!this[x]&&(this[_]=[this[B]?this[_].join(""):Buffer.concat(this[_],this[k])]);let t=this[_s](e||null,this[_][0]);return this[X](),t}[_s](e,t){if(this[x])this[Ut]();else{let i=t;e===i.length||e===null?this[Ut]():typeof i=="string"?(this[_][0]=i.slice(e),t=i.slice(0,e),this[k]-=e):(this[_][0]=i.subarray(e),t=i.subarray(0,e),this[k]-=e)}return this.emit("data",t),!this[_].length&&!this[J]&&this.emit("drain"),t}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t="utf8"),e!==void 0&&this.write(e,t),i&&this.once("end",i),this[J]=!0,this.writable=!1,(this[R]||!this[Xe])&&this[X](),this}[$e](){this[S]||(!this[we]&&!this[P].length&&(this[A]=!0),this[Xe]=!1,this[R]=!0,this.emit("resume"),this[_].length?this[$t]():this[J]?this[X]():this.emit("drain"))}resume(){return this[$e]()}pause(){this[R]=!1,this[Xe]=!0,this[A]=!1}get destroyed(){return this[S]}get flowing(){return this[R]}get paused(){return this[Xe]}[Ai](e){this[x]?this[k]+=1:this[k]+=e.length,this[_].push(e)}[Ut](){return this[x]?this[k]-=1:this[k]-=this[_][0].length,this[_].shift()}[$t](e=!1){do;while(this[ks](this[Ut]())&&this[_].length);!e&&!this[_].length&&!this[J]&&this.emit("drain")}[ks](e){return this.emit("data",e),this[R]}pipe(e,t){if(this[S])return e;this[A]=!1;let i=this[se];return t=t||{},e===Rs.stdout||e===Rs.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,i?t.end&&e.end():(this[P].push(t.proxyErrors?new aa(this,e,t):new on(this,e,t)),this[W]?et(()=>this[$e]()):this[$e]()),e}unpipe(e){let t=this[P].find(i=>i.dest===e);t&&(this[P].length===1?(this[R]&&this[we]===0&&(this[R]=!1),this[P]=[]):this[P].splice(this[P].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let i=super.on(e,t);if(e==="data")this[A]=!1,this[we]++,!this[P].length&&!this[R]&&this[$e]();else if(e==="readable"&&this[k]!==0)super.emit("readable");else if(sa(e)&&this[se])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[Je]){let r=t;this[W]?et(()=>r.call(this,this[Je])):r.call(this,this[Je])}return i}removeListener(e,t){return this.off(e,t)}off(e,t){let i=super.off(e,t);return e==="data"&&(this[we]=this.listeners("data").length,this[we]===0&&!this[A]&&!this[P].length&&(this[R]=!1)),i}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[we]=0,!this[A]&&!this[P].length&&(this[R]=!1)),t}get emittedEnd(){return this[se]}[X](){!this[Ft]&&!this[se]&&!this[S]&&this[_].length===0&&this[J]&&(this[Ft]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Bt]&&this.emit("close"),this[Ft]=!1)}emit(e,...t){let i=t[0];if(e!=="error"&&e!=="close"&&e!==S&&this[S])return!1;if(e==="data")return!this[x]&&!i?!1:this[W]?(et(()=>this[Ni](i)),!0):this[Ni](i);if(e==="end")return this[Os]();if(e==="close"){if(this[Bt]=!0,!this[se]&&!this[S])return!1;let s=super.emit("close");return this.removeAllListeners("close"),s}else if(e==="error"){this[Je]=i,super.emit(Ii,i);let s=!this[Qe]||this.listeners("error").length?super.emit("error",i):!1;return this[X](),s}else if(e==="resume"){let s=super.emit("resume");return this[X](),s}else if(e==="finish"||e==="prefinish"){let s=super.emit(e);return this.removeAllListeners(e),s}let r=super.emit(e,...t);return this[X](),r}[Ni](e){for(let i of this[P])i.dest.write(e)===!1&&this.pause();let t=this[A]?!1:super.emit("data",e);return this[X](),t}[Os](){return this[se]?!1:(this[se]=!0,this.readable=!1,this[W]?(et(()=>this[Ci]()),!0):this[Ci]())}[Ci](){if(this[Ne]){let t=this[Ne].end();if(t){for(let i of this[P])i.dest.write(t);this[A]||super.emit("data",t)}}for(let t of this[P])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[x]||(e.dataLength=0);let t=this.promise();return this.on("data",i=>{e.push(i),this[x]||(e.dataLength+=i.length)}),await t,e}async concat(){if(this[x])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[B]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(S,()=>t(new Error("stream destroyed"))),this.on("error",i=>t(i)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[A]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let i=this.read();if(i!==null)return Promise.resolve({done:!1,value:i});if(this[J])return t();let r,s,n=l=>{this.off("data",o),this.off("end",a),this.off(S,h),t(),s(l)},o=l=>{this.off("error",n),this.off("end",a),this.off(S,h),this.pause(),r({value:l,done:!!this[J]})},a=()=>{this.off("error",n),this.off("data",o),this.off(S,h),t(),r({done:!0,value:void 0})},h=()=>n(new Error("stream destroyed"));return new Promise((l,c)=>{s=c,r=l,this.once(S,h),this.once("error",n),this.once("end",a),this.once("data",o)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[A]=!1;let e=!1,t=()=>(this.pause(),this.off(Ii,t),this.off(S,t),this.off("end",t),e=!0,{done:!0,value:void 0}),i=()=>{if(e)return t();let r=this.read();return r===null?t():{done:!1,value:r}};return this.once("end",t),this.once(Ii,t),this.once(S,t),{next:i,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[S])return e?this.emit("error",e):this.emit(S),this;this[S]=!0,this[A]=!0,this[_].length=0,this[k]=0;let t=this;return typeof t.close=="function"&&!this[Bt]&&t.close(),e?this.emit("error",e):this.emit(S),this}static get isStream(){return ea}},ca=L.writev,me=Symbol("_autoClose"),j=Symbol("_close"),tt=Symbol("_ended"),f=Symbol("_fd"),Fi=Symbol("_finished"),ie=Symbol("_flags"),Bi=Symbol("_flush"),nr=Symbol("_handleChunk"),or=Symbol("_makeBuf"),mt=Symbol("_mode"),jt=Symbol("_needDrain"),We=Symbol("_onerror"),Ge=Symbol("_onopen"),$i=Symbol("_onread"),Ue=Symbol("_onwrite"),pe=Symbol("_open"),z=Symbol("_path"),he=Symbol("_pos"),G=Symbol("_queue"),ze=Symbol("_read"),Ui=Symbol("_readSize"),te=Symbol("_reading"),it=Symbol("_remain"),zi=Symbol("_size"),Xt=Symbol("_write"),be=Symbol("_writing"),Qt=Symbol("_defaultFlag"),Oe=Symbol("_errored"),Tr=class extends Le{[Oe]=!1;[f];[z];[Ui];[te]=!1;[zi];[it];[me];constructor(e,t){if(t=t||{},super(t),this.readable=!0,this.writable=!1,typeof e!="string")throw new TypeError("path must be a string");this[Oe]=!1,this[f]=typeof t.fd=="number"?t.fd:void 0,this[z]=e,this[Ui]=t.readSize||16*1024*1024,this[te]=!1,this[zi]=typeof t.size=="number"?t.size:1/0,this[it]=this[zi],this[me]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[f]=="number"?this[ze]():this[pe]()}get fd(){return this[f]}get path(){return this[z]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[pe](){L.open(this[z],"r",(e,t)=>this[Ge](e,t))}[Ge](e,t){e?this[We](e):(this[f]=t,this.emit("open",t),this[ze]())}[or](){return Buffer.allocUnsafe(Math.min(this[Ui],this[it]))}[ze](){if(!this[te]){this[te]=!0;let e=this[or]();if(e.length===0)return process.nextTick(()=>this[$i](null,0,e));L.read(this[f],e,0,e.length,null,(t,i,r)=>this[$i](t,i,r))}}[$i](e,t,i){this[te]=!1,e?this[We](e):this[nr](t,i)&&this[ze]()}[j](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}[We](e){this[te]=!0,this[j](),this.emit("error",e)}[nr](e,t){let i=!1;return this[it]-=e,e>0&&(i=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[it]<=0)&&(i=!1,this[j](),super.end()),i}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[f]=="number"&&this[ze](),!1;case"error":return this[Oe]?!1:(this[Oe]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},da=class extends Tr{[pe](){let e=!0;try{this[Ge](null,L.openSync(this[z],"r")),e=!1}finally{e&&this[j]()}}[ze](){let e=!0;try{if(!this[te]){this[te]=!0;do{let t=this[or](),i=t.length===0?0:L.readSync(this[f],t,0,t.length,null);if(!this[nr](i,t))break}while(!0);this[te]=!1}e=!1}finally{e&&this[j]()}}[j](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}},pi=class extends Xo{readable=!1;writable=!0;[Oe]=!1;[be]=!1;[tt]=!1;[G]=[];[jt]=!1;[z];[mt];[me];[f];[Qt];[ie];[Fi]=!1;[he];constructor(e,t){t=t||{},super(t),this[z]=e,this[f]=typeof t.fd=="number"?t.fd:void 0,this[mt]=t.mode===void 0?438:t.mode,this[he]=typeof t.start=="number"?t.start:void 0,this[me]=typeof t.autoClose=="boolean"?t.autoClose:!0;let i=this[he]!==void 0?"r+":"w";this[Qt]=t.flags===void 0,this[ie]=t.flags===void 0?i:t.flags,this[f]===void 0&&this[pe]()}emit(e,...t){if(e==="error"){if(this[Oe])return!1;this[Oe]=!0}return super.emit(e,...t)}get fd(){return this[f]}get path(){return this[z]}[We](e){this[j](),this[be]=!0,this.emit("error",e)}[pe](){L.open(this[z],this[ie],this[mt],(e,t)=>this[Ge](e,t))}[Ge](e,t){this[Qt]&&this[ie]==="r+"&&e&&e.code==="ENOENT"?(this[ie]="w",this[pe]()):e?this[We](e):(this[f]=t,this.emit("open",t),this[be]||this[Bi]())}end(e,t){return e&&this.write(e,t),this[tt]=!0,!this[be]&&!this[G].length&&typeof this[f]=="number"&&this[Ue](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[tt]?(this.emit("error",new Error("write() after end()")),!1):this[f]===void 0||this[be]||this[G].length?(this[G].push(e),this[jt]=!0,!1):(this[be]=!0,this[Xt](e),!0)}[Xt](e){L.write(this[f],e,0,e.length,this[he],(t,i)=>this[Ue](t,i))}[Ue](e,t){e?this[We](e):(this[he]!==void 0&&typeof t=="number"&&(this[he]+=t),this[G].length?this[Bi]():(this[be]=!1,this[tt]&&!this[Fi]?(this[Fi]=!0,this[j](),this.emit("finish")):this[jt]&&(this[jt]=!1,this.emit("drain"))))}[Bi](){if(this[G].length===0)this[tt]&&this[Ue](null,0);else if(this[G].length===1)this[Xt](this[G].pop());else{let e=this[G];this[G]=[],ca(this[f],e,this[he],(t,i)=>this[Ue](t,i))}}[j](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}},an=class extends pi{[pe](){let e;if(this[Qt]&&this[ie]==="r+")try{e=L.openSync(this[z],this[ie],this[mt])}catch(t){if(t?.code==="ENOENT")return this[ie]="w",this[pe]();throw t}else e=L.openSync(this[z],this[ie],this[mt]);this[Ge](null,e)}[j](){if(this[me]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}[Xt](e){let t=!0;try{this[Ue](null,L.writeSync(this[f],e,0,e.length,this[he])),t=!1}finally{if(t)try{this[j]()}catch{}}}},pa=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"]]),fa=e=>!!e.sync&&!!e.file,ga=e=>!e.sync&&!!e.file,ya=e=>!!e.sync&&!e.file,wa=e=>!e.sync&&!e.file,ba=e=>!!e.file,Ea=e=>pa.get(e)||e,xr=(e={})=>{if(!e)return{};let t={};for(let[i,r]of Object.entries(e)){let s=Ea(i);t[s]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},vt=(e,t,i,r,s)=>Object.assign((n=[],o,a)=>{Array.isArray(n)&&(o=n,n={}),typeof o=="function"&&(a=o,o=void 0),o=o?Array.from(o):[];let h=xr(n);if(s?.(h,o),fa(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return e(h,o)}else if(ga(h)){let l=t(h,o);return a?l.then(()=>a(),a):l}else if(ya(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return i(h,o)}else if(wa(h)){if(typeof a=="function")throw new TypeError("callback only supported with file option");return r(h,o)}throw new Error("impossible options??")},{syncFile:e,asyncFile:t,syncNoFile:i,asyncNoFile:r,validate:s}),Ra=va.constants||{ZLIB_VERNUM:4736},q=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},Ra)),_a=Te.concat,xs=Object.getOwnPropertyDescriptor(Te,"concat"),ka=e=>e,ji=xs?.writable===!0||xs?.set!==void 0?e=>{Te.concat=e?ka:_a}:e=>{},xe=Symbol("_superWrite"),Ht=class extends Error{code;errno;constructor(e,t){super("zlib: "+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+e.message,Error.captureStackTrace(this,t??this.constructor)}get name(){return"ZlibError"}},Hi=Symbol("flushFlag"),Pr=class extends Le{#e=!1;#i=!1;#r;#n;#s;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(e,t){if(!e||typeof e!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(e),this.#r=e.flush??0,this.#n=e.finishFlush??0,this.#s=e.fullFlushFlag??0,typeof Ts[t]!="function")throw new TypeError("Compression method not supported: "+t);try{this.#t=new Ts[t](e)}catch(i){throw new Ht(i,this.constructor)}this.#o=i=>{this.#e||(this.#e=!0,this.close(),this.emit("error",i))},this.#t?.on("error",i=>this.#o(new Ht(i))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ar(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#s),this.write(Object.assign(Te.alloc(0),{[Hi]:e})))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#n),this.#i=!0,super.end(i)}get ended(){return this.#i}[xe](e){return super.write(e)}write(e,t,i){if(typeof t=="function"&&(i=t,t="utf8"),typeof e=="string"&&(e=Te.from(e,t)),this.#e)return;ar(this.#t,"zlib binding closed");let r=this.#t._handle,s=r.close;r.close=()=>{};let n=this.#t.close;this.#t.close=()=>{},ji(!0);let o;try{let h=typeof e[Hi]=="number"?e[Hi]:this.#r;o=this.#t._processChunk(e,h),ji(!1)}catch(h){ji(!1),this.#o(new Ht(h,this.write))}finally{this.#t&&(this.#t._handle=r,r.close=s,this.#t.close=n,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new Ht(h,this.write)));let a;if(o)if(Array.isArray(o)&&o.length>0){let h=o[0];a=this[xe](Te.from(h));for(let l=1;l<o.length;l++)a=this[xe](o[l])}else a=this[xe](Te.from(o));return i&&i(),a}},ln=class extends Pr{#e;#i;constructor(e,t){e=e||{},e.flush=e.flush||q.Z_NO_FLUSH,e.finishFlush=e.finishFlush||q.Z_FINISH,e.fullFlushFlag=q.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#i=e.strategy}params(e,t){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==e||this.#i!==t){this.flush(q.Z_SYNC_FLUSH),ar(this.handle,"zlib binding closed");let i=this.handle.flush;this.handle.flush=(r,s)=>{typeof r=="function"&&(s=r,r=this.flushFlag),this.flush(r),s?.()};try{this.handle.params(e,t)}finally{this.handle.flush=i}this.handle&&(this.#e=e,this.#i=t)}}}},Oa=class extends ln{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[xe](e){return this.#e?(this.#e=!1,e[9]=255,super[xe](e)):super[xe](e)}},Ta=class extends ln{constructor(e){super(e,"Unzip")}},cn=class extends Pr{constructor(e,t){e=e||{},e.flush=e.flush||q.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||q.BROTLI_OPERATION_FINISH,e.fullFlushFlag=q.BROTLI_OPERATION_FLUSH,super(e,t)}},xa=class extends cn{constructor(e){super(e,"BrotliCompress")}},Pa=class extends cn{constructor(e){super(e,"BrotliDecompress")}},dn=class extends Pr{constructor(e,t){e=e||{},e.flush=e.flush||q.ZSTD_e_continue,e.finishFlush=e.finishFlush||q.ZSTD_e_end,e.fullFlushFlag=q.ZSTD_e_flush,super(e,t)}},La=class extends dn{constructor(e){super(e,"ZstdCompress")}},Da=class extends dn{constructor(e){super(e,"ZstdDecompress")}},Aa=(e,t)=>{if(Number.isSafeInteger(e))e<0?Na(e,t):Ia(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},Ia=(e,t)=>{t[0]=128;for(var i=t.length;i>1;i--)t[i-1]=e&255,e=Math.floor(e/256)},Na=(e,t)=>{t[0]=255;var i=!1;e=e*-1;for(var r=t.length;r>1;r--){var s=e&255;e=Math.floor(e/256),i?t[r-1]=un(s):s===0?t[r-1]=0:(i=!0,t[r-1]=mn(s))}},Ca=e=>{let t=e[0],i=t===128?Fa(e.subarray(1,e.length)):t===255?Ma(e):null;if(i===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i},Ma=e=>{for(var t=e.length,i=0,r=!1,s=t-1;s>-1;s--){var n=Number(e[s]),o;r?o=un(n):n===0?o=n:(r=!0,o=mn(n)),o!==0&&(i-=o*Math.pow(256,t-s-1))}return i},Fa=e=>{for(var t=e.length,i=0,r=t-1;r>-1;r--){var s=Number(e[r]);s!==0&&(i+=s*Math.pow(256,t-r-1))}return i},un=e=>(255^e)&255,mn=e=>(255^e)+1&255,Ba={};Jo(Ba,{code:()=>Lr,isCode:()=>ei,isName:()=>$a,name:()=>fi,normalFsTypes:()=>pn});var ei=e=>fi.has(e),$a=e=>Lr.has(e),pn=new Set(["0","","1","2","3","4","5","6","7","D"]),fi=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"]]),Lr=new Map(Array.from(fi).map(e=>[e[1],e[0]])),Ua=e=>e===void 0||e<0?void 0:e,Pe=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,i,r){Buffer.isBuffer(e)?this.decode(e,t||0,i,r):e&&this.#i(e)}decode(e,t,i,r){if(t||(t=0),!e||!(e.length>=t+512))throw new Error("need 512 bytes for header");let s=Ee(e,t+156,1),n=pn.has(s),o=n?i:void 0,a=n?r:void 0;if(this.path=o?.path??Ee(e,t,100),this.mode=o?.mode??a?.mode??le(e,t+100,8),this.uid=o?.uid??a?.uid??le(e,t+108,8),this.gid=o?.gid??a?.gid??le(e,t+116,8),this.size=Ua(o?.size??a?.size??le(e,t+124,12)),this.mtime=o?.mtime??a?.mtime??Wi(e,t+136,12),this.cksum=le(e,t+148,12),a&&this.#i(a,!0),o&&this.#i(o),ei(s)&&(this.#e=s||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Ee(e,t+157,100),e.subarray(t+257,t+265).toString()==="ustar\x0000")if(this.uname=o?.uname??a?.uname??Ee(e,t+265,32),this.gname=o?.gname??a?.gname??Ee(e,t+297,32),this.devmaj=o?.devmaj??a?.devmaj??le(e,t+329,8)??0,this.devmin=o?.devmin??a?.devmin??le(e,t+337,8)??0,e[t+475]!==0){let l=Ee(e,t+345,155);this.path=l+"/"+this.path}else{let l=Ee(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=i?.atime??r?.atime??Wi(e,t+476,12),this.ctime=i?.ctime??r?.ctime??Wi(e,t+488,12)}let h=256;for(let l=t;l<t+148;l++)h+=e[l];for(let l=t+156;l<t+512;l++)h+=e[l];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#i(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="size"&&Number(r)<0||i==="path"&&t||i==="linkpath"&&t||i==="global"))))}encode(e,t=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw new Error("need 512 bytes for header");let i=this.ctime||this.atime?130:155,r=za(this.path||"",i),s=r[0],n=r[1];this.needPax=!!r[2],this.needPax=Se(e,t,100,s)||this.needPax,this.needPax=ce(e,t+100,8,this.mode)||this.needPax,this.needPax=ce(e,t+108,8,this.uid)||this.needPax,this.needPax=ce(e,t+116,8,this.gid)||this.needPax,this.needPax=ce(e,t+124,12,this.size)||this.needPax,this.needPax=Gi(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=Se(e,t+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",t+257,8),this.needPax=Se(e,t+265,32,this.uname)||this.needPax,this.needPax=Se(e,t+297,32,this.gname)||this.needPax,this.needPax=ce(e,t+329,8,this.devmaj)||this.needPax,this.needPax=ce(e,t+337,8,this.devmin)||this.needPax,this.needPax=Se(e,t+345,i,n)||this.needPax,e[t+475]!==0?this.needPax=Se(e,t+345,155,n)||this.needPax:(this.needPax=Se(e,t+345,130,n)||this.needPax,this.needPax=Gi(e,t+476,12,this.atime)||this.needPax,this.needPax=Gi(e,t+488,12,this.ctime)||this.needPax);let o=256;for(let a=t;a<t+148;a++)o+=e[a];for(let a=t+156;a<t+512;a++)o+=e[a];return this.cksum=o,ce(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:fi.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Lr.get(e));if(ei(t)||t==="Unsupported")this.#e=t;else if(ei(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},za=(e,t)=>{let i=e,r="",s,n=Ce.parse(e).root||".";if(Buffer.byteLength(i)<100)s=[i,r,!1];else{r=Ce.dirname(i),i=Ce.basename(i);do Buffer.byteLength(i)<=100&&Buffer.byteLength(r)<=t?s=[i,r,!1]:Buffer.byteLength(i)>100&&Buffer.byteLength(r)<=t?s=[i.slice(0,99),r,!0]:(i=Ce.join(Ce.basename(r),i),r=Ce.dirname(r));while(r!==n&&s===void 0);s||(s=[e.slice(0,99),"",!0])}return s},Ee=(e,t,i)=>e.subarray(t,t+i).toString("utf8").replace(/\0.*/,""),Wi=(e,t,i)=>ja(le(e,t,i)),ja=e=>e===void 0?void 0:new Date(e*1e3),le=(e,t,i)=>Number(e[t])&128?Ca(e.subarray(t,t+i)):Wa(e,t,i),Ha=e=>isNaN(e)?void 0:e,Wa=(e,t,i)=>Ha(parseInt(e.subarray(t,t+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),Ga={12:8589934591,8:2097151},ce=(e,t,i,r)=>r===void 0?!1:r>Ga[i]||r<0?(Aa(r,e.subarray(t,t+i)),!0):(Za(e,t,i,r),!1),Za=(e,t,i,r)=>e.write(Ka(r,i),t,i,"ascii"),Ka=(e,t)=>Va(Math.floor(e).toString(8),t),Va=(e,t)=>(e.length===t-1?e:new Array(t-e.length-1).join("0")+e+" ")+"\0",Gi=(e,t,i,r)=>r===void 0?!1:ce(e,t,i,r.getTime()/1e3),Ya=new Array(156).join("\0"),Se=(e,t,i,r)=>r===void 0?!1:(e.write(r+Ya,t,i,"utf8"),r.length!==Buffer.byteLength(r)||r.length>i),li=class fn{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,i=!1){this.atime=t.atime,this.charset=t.charset,this.comment=t.comment,this.ctime=t.ctime,this.dev=t.dev,this.gid=t.gid,this.global=i,this.gname=t.gname,this.ino=t.ino,this.linkpath=t.linkpath,this.mtime=t.mtime,this.nlink=t.nlink,this.path=t.path,this.size=t.size,this.uid=t.uid,this.uname=t.uname}encode(){let t=this.encodeBody();if(t==="")return Buffer.allocUnsafe(0);let i=Buffer.byteLength(t),r=512*Math.ceil(1+i/512),s=Buffer.allocUnsafe(r);for(let n=0;n<512;n++)s[n]=0;new Pe({path:("PaxHeader/"+qa(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:i,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(s),s.write(t,512,i,"utf8");for(let n=i+512;n<s.length;n++)s[n]=0;return s}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(t){if(this[t]===void 0)return"";let i=this[t],r=i instanceof Date?i.getTime()/1e3:i,s=" "+(t==="dev"||t==="ino"||t==="nlink"?"SCHILY.":"")+t+"="+r+`
|
|
86
|
+
`,n=Buffer.byteLength(s),o=Math.floor(Math.log(n)/Math.log(10))+1;return n+o>=Math.pow(10,o)&&(o+=1),o+n+s}static parse(t,i,r=!1){return new fn(Ja(Xa(t),i),r)}},Ja=(e,t)=>t?Object.assign({},t,e):e,Xa=e=>e.replace(/\n$/,"").split(`
|
|
87
|
+
`).reduce(Qa,Object.create(null)),Qa=(e,t)=>{let i=parseInt(t,10);if(i!==Buffer.byteLength(t)+1)return e;t=t.slice((i+" ").length);let r=t.split("="),s=r.shift();if(!s)return e;let n=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),o=r.join("=").replace(/\0.*/,"");switch(n){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":e[n]=o;break;case"ctime":case"atime":case"mtime":e[n]=new Date(Number(o)*1e3);break;case"size":let a=+o;a>=0&&(e[n]=a);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":e[n]=+o;break}return e},eh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,u=eh!=="win32"?e=>String(e):e=>String(e).replaceAll(/\\/g,"/"),th=class extends Le{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,i){switch(super({}),this.pause(),this.extended=t,this.globalExtended=i,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 new Error("no path provided for tar.ReadEntry");this.path=u(e.path),this.mode=e.mode,this.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?u(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),i&&this.#e(i,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw new Error("writing more to entry than is appropriate");let i=this.remain,r=this.blockRemain;return this.remain=Math.max(0,i-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:i>=t?super.write(e):super.write(e.subarray(0,i))}#e(e,t=!1){e.path&&(e.path=u(e.path)),e.linkpath&&(e.linkpath=u(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="path"&&t))))}},gi=(e,t,i,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=i instanceof Error&&i.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(i instanceof Error&&(r=Object.assign(i,r),i=i.message),e.emit("warn",t,i,r)):i instanceof Error?e.emit("error",Object.assign(i,r)):e.emit("error",Object.assign(new Error(`${t}: ${i}`),r))},ih=1024*1024,hr=Buffer.from([31,139]),lr=Buffer.from([40,181,47,253]),rh=Math.max(hr.length,lr.length),C=Symbol("state"),ve=Symbol("writeEntry"),Q=Symbol("readEntry"),Zi=Symbol("nextEntry"),Ps=Symbol("processEntry"),Z=Symbol("extendedHeader"),rt=Symbol("globalExtendedHeader"),ne=Symbol("meta"),Ls=Symbol("emitMeta"),y=Symbol("buffer"),ee=Symbol("queue"),oe=Symbol("ended"),Ki=Symbol("emittedEnd"),Re=Symbol("emit"),b=Symbol("unzip"),Wt=Symbol("consumeChunk"),Gt=Symbol("consumeChunkSub"),Vi=Symbol("consumeBody"),Ds=Symbol("consumeMeta"),As=Symbol("consumeHeader"),st=Symbol("consuming"),Yi=Symbol("bufferConcat"),Zt=Symbol("maybeEnd"),Me=Symbol("writing"),K=Symbol("aborted"),Kt=Symbol("onDone"),_e=Symbol("sawValidEntry"),Vt=Symbol("sawNullBlock"),Yt=Symbol("sawEOF"),Is=Symbol("closeStream"),sh=1e3,nt=Symbol("compressedBytesRead"),qi=Symbol("decompressedBytesRead"),Ns=Symbol("checkDecompressionRatio"),nh=()=>!0,St=class extends Sa{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[ee]=[];[y];[Q];[ve];[C]="begin";[ne]="";[Z];[rt];[oe]=!1;[b];[K]=!1;[_e];[Vt]=!1;[Yt]=!1;[Me]=!1;[st]=!1;[Ki]=!1;[nt]=0;[qi]=0;constructor(e={}){super(),this.file=e.file||"",this.on(Kt,()=>{(this[C]==="begin"||this[_e]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(Kt,e.ondone):this.on(Kt,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:sh,this.maxMetaEntrySize=e.maxMetaEntrySize||ih,this.filter=typeof e.filter=="function"?e.filter:nh;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 i=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:i?!0:void 0,this.on("end",()=>this[Is]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,i={}){gi(this,e,t,i)}[As](e,t){this[_e]===void 0&&(this[_e]=!1);let i;try{i=new Pe(e,t,this[Z],this[rt])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(i.nullBlock)this[Vt]?(this[Yt]=!0,this[C]==="begin"&&(this[C]="header"),this[Re]("eof")):(this[Vt]=!0,this[Re]("nullBlock"));else if(this[Vt]=!1,!i.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:i});else if(!i.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:i});else{let r=i.type;if(/^(Symbolic)?Link$/.test(r)&&!i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:i});else if(!/^(Symbolic)?Link$/.test(r)&&!/^(Global)?ExtendedHeader$/.test(r)&&i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:i});else{let s=this[ve]=new th(i,this[Z],this[rt]);if(!this[_e])if(s.remain){let n=()=>{s.invalid||(this[_e]=!0)};s.on("end",n)}else this[_e]=!0;s.meta?s.size>this.maxMetaEntrySize?(s.ignore=!0,this[Re]("ignoredEntry",s),this[C]="ignore",s.resume()):s.size>0&&(this[ne]="",s.on("data",n=>this[ne]+=n),this[C]="meta"):(this[Z]=void 0,s.ignore=s.ignore||!this.filter(s.path,s),s.ignore?(this[Re]("ignoredEntry",s),this[C]=s.remain?"ignore":"header",s.resume()):(s.remain?this[C]="body":(this[C]="header",s.end()),this[Q]?this[ee].push(s):(this[ee].push(s),this[Zi]())))}}}[Is](){queueMicrotask(()=>this.emit("close"))}[Ps](e){let t=!0;if(!e)this[Q]=void 0,t=!1;else if(Array.isArray(e)){let[i,...r]=e;this.emit(i,...r)}else this[Q]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[Zi]()),t=!1);return t}[Zi](){do;while(this[Ps](this[ee].shift()));if(this[ee].length===0){let e=this[Q];!e||e.flowing||e.size===e.remain?this[Me]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[Vi](e,t){let i=this[ve];if(!i)throw new Error("attempt to consume body without entry??");let r=i.blockRemain??0,s=r>=e.length&&t===0?e:e.subarray(t,t+r);return i.write(s),i.blockRemain||(this[C]="header",this[ve]=void 0,i.end()),s.length}[Ds](e,t){let i=this[ve],r=this[Vi](e,t);return!this[ve]&&i&&this[Ls](i),r}[Re](e,t,i){this[ee].length===0&&!this[Q]?this.emit(e,t,i):this[ee].push([e,t,i])}[Ls](e){switch(this[Re]("meta",this[ne]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[Z]=li.parse(this[ne],this[Z],!1);break;case"GlobalExtendedHeader":this[rt]=li.parse(this[ne],this[rt],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[Z]??Object.create(null);this[Z]=t,t.path=this[ne].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[Z]||Object.create(null);this[Z]=t,t.linkpath=this[ne].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){if(!this[K]){if(this[b]){let t=this[b];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[K]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}}[Ns](e){this[qi]+=e.length;let t=this[qi]/this[nt];return t>this.maxDecompressionRatio?(this.abort(new Error(`max decompression ratio exceeded: ${t.toFixed(2)} > ${this.maxDecompressionRatio}`)),!1):!0}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this[K])return i?.(),!1;if((this[b]===void 0||this.brotli===void 0&&this[b]===!1)&&e){if(this[y]&&(e=Buffer.concat([this[y],e]),this[y]=void 0),e.length<rh)return this[y]=e,i?.(),!0;for(let o=0;this[b]===void 0&&o<hr.length;o++)e[o]!==hr[o]&&(this[b]=!1);let s=!1;if(this[b]===!1&&this.zstd!==!1){s=!0;for(let o=0;o<lr.length;o++)if(e[o]!==lr[o]){s=!1;break}}let n=this.brotli===void 0&&!s;if(this[b]===!1&&n)if(e.length<512)if(this[oe])this.brotli=!0;else return this[y]=e,i?.(),!0;else try{new Pe(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[b]===void 0||this[b]===!1&&(this.brotli||s)){let o=this[oe];this[oe]=!1,this[b]=this[b]===void 0?new Ta({}):s?new Da({}):new Pa({}),this[b].on("data",h=>{this[Ns](h)&&this[Wt](h)}),this[b].on("error",h=>{this[K]||this.abort(h)}),this[b].on("end",()=>{this[oe]=!0,this[Wt]()}),this[Me]=!0,this[nt]+=e.length;let a=!!this[b][o?"end":"write"](e);return this[Me]=!1,i?.(),a}}this[Me]=!0,this[b]?(this[nt]+=e.length,this[b].write(e)):this[Wt](e),this[Me]=!1;let r=this[ee].length>0?!1:this[Q]?this[Q].flowing:!0;return!r&&this[ee].length===0&&this[Q]?.once("drain",()=>this.emit("drain")),i?.(),r}[Yi](e){e&&!this[K]&&(this[y]=this[y]?Buffer.concat([this[y],e]):e)}[Zt](){if(this[oe]&&!this[Ki]&&!this[K]&&!this[st]){this[Ki]=!0;let e=this[ve];if(e?.blockRemain){let t=this[y]?this[y].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[y]&&e.write(this[y]),e.end()}this[Re](Kt)}}[Wt](e){if(this[st]&&e)this[Yi](e);else if(!e&&!this[y])this[Zt]();else if(e){if(this[st]=!0,this[y]){this[Yi](e);let t=this[y];this[y]=void 0,this[Gt](t)}else this[Gt](e);for(;this[y]&&this[y]?.length>=512&&!this[K]&&!this[Yt];){let t=this[y];this[y]=void 0,this[Gt](t)}this[st]=!1}(!this[y]||this[oe])&&this[Zt]()}[Gt](e){let t=0,i=e.length;for(;t+512<=i&&!this[K]&&!this[Yt];)switch(this[C]){case"begin":case"header":this[As](e,t),t+=512;break;case"ignore":case"body":t+=this[Vi](e,t);break;case"meta":t+=this[Ds](e,t);break;default:throw new Error("invalid state: "+this[C])}t<i&&(this[y]=this[y]?Buffer.concat([e.subarray(t),this[y]]):e.subarray(t))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t)),i&&this.once("finish",i),this[K]||(this[b]?(e&&(this[nt]+=e.length,this[b].write(e)),this[b].end()):(this[oe]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[Zt]())),this}},pt=e=>{let t=e.length-1,i=-1;for(;t>-1&&e.charAt(t)==="/";)i=t,t--;return i===-1?e:e.slice(0,i)},oh=e=>{let t=e.onReadEntry;e.onReadEntry=t?i=>{t(i),i.resume()}:i=>i.resume()},gn=(e,t)=>{let i=new Map(t.map(o=>[pt(o),!0])),r=e.filter,s=100,n=(o,a="",h=0)=>{if(h>=s)return i.set(o,!1),!1;let l=a||ma(o).root||".",c;if(o===l)c=!1;else{let d=i.get(o);c=d!==void 0?d:n(ua(o),l,h+1)}return i.set(o,c),c};e.filter=r?(o,a)=>r(o,a)&&n(pt(o)):o=>n(pt(o))},ah=e=>{let t=new St(e),i=e.file,r;try{r=je.openSync(i,"r");let s=je.fstatSync(r),n=e.maxReadSize||16*1024*1024;if(s.size<n){let o=Buffer.allocUnsafe(s.size),a=je.readSync(r,o,0,s.size,0);t.end(a===o.byteLength?o:o.subarray(0,a))}else{let o=0,a=Buffer.allocUnsafe(n);for(;o<s.size;){let h=je.readSync(r,a,0,n,o);if(h===0)break;o+=h,t.write(a.subarray(0,h))}t.end()}}finally{if(typeof r=="number")try{je.closeSync(r)}catch{}}},hh=(e,t)=>{let i=new St(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("end",n),je.stat(s,(a,h)=>{if(a)o(a);else{let l=new Tr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},yi=vt(ah,hh,e=>new St(e),e=>new St(e),(e,t)=>{t?.length&&gn(e,t),e.noResume||oh(e)}),yn=(e,t,i)=>(e&=4095,i&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),{isAbsolute:ch,parse:Ms}=lh,Dr=e=>{let t="",i=Ms(e);for(;ch(e)||i.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":i.root;e=e.slice(r.length),t+=r,i=Ms(e)}return[t,e]},wi=["|","<",">","?",":"],Ar=wi.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),dh=new Map(wi.map((e,t)=>[e,Ar[t]])),uh=new Map(Ar.map((e,t)=>[e,wi[t]])),Fs=e=>wi.reduce((t,i)=>t.split(i).join(dh.get(i)),e),mh=e=>Ar.reduce((t,i)=>t.split(i).join(uh.get(i)),e),wn=(e,t)=>t?(e=u(e).replace(/^\.(\/|$)/,""),pt(t)+"/"+e):u(e),ph=16*1024*1024,Bs=Symbol("process"),$s=Symbol("file"),Us=Symbol("directory"),cr=Symbol("symlink"),zs=Symbol("hardlink"),ot=Symbol("header"),ti=Symbol("read"),dr=Symbol("lstat"),ii=Symbol("onlstat"),ur=Symbol("onread"),mr=Symbol("onreadlink"),pr=Symbol("openfile"),fr=Symbol("onopenfile"),de=Symbol("close"),di=Symbol("mode"),gr=Symbol("awaitDrain"),Ji=Symbol("ondrain"),Y=Symbol("prefix"),bn=class extends Le{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 i=xr(t);super(),this.path=u(e),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||ph,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=u(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?u(i.prefix):void 0,this.onWriteEntry=i.onWriteEntry,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let r=!1;if(!this.preservePaths){let[n,o]=Dr(this.path);n&&typeof o=="string"&&(this.path=o,r=n)}this.win32=!!i.win32||process.platform==="win32",this.win32&&(this.path=mh(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=u(i.absolute||Cs.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 s=this.statCache.get(this.absolute);s?this[ii](s):this[dr]()}warn(e,t,i={}){return gi(this,e,t,i)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[dr](){V.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[ii](t)})}[ii](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=yh(e),this.emit("stat",e),this[Bs]()}[Bs](){switch(this.type){case"File":return this[$s]();case"Directory":return this[Us]();case"SymbolicLink":return this[cr]();default:return this.end()}}[di](e){return yn(e,this.type==="Directory",this.portable)}[Y](e){return wn(e,this.prefix)}[ot](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Pe({path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this[di](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 li({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 new Error("failed to encode header");super.write(e)}[Us](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ot](),this.end()}[cr](){V.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[mr](t)})}[mr](e){this.linkpath=u(e),this[ot](),this.end()}[zs](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=u(Cs.relative(this.cwd,e)),this.stat.size=0,this[ot](),this.end()}[$s](){if(!this.stat)throw new 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[zs](t);this.linkCache.set(e,this.absolute)}if(this[ot](),this.stat.size===0)return this.end();this[pr]()}[pr](){V.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[fr](t)})}[fr](e){if(this.fd=e,this.#e)return this[de]();if(!this.stat)throw new 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[ti]()}[ti](){let{fd:e,buf:t,offset:i,length:r,pos:s}=this;if(e===void 0||t===void 0)throw new Error("cannot read file without first opening");V.read(e,t,i,r,s,(n,o)=>{if(n)return this[de](()=>this.emit("error",n));this[ur](o)})}[de](e=()=>{}){this.fd!==void 0&&V.close(this.fd,e)}[ur](e){if(e<=0&&this.remain>0){let i=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[de](()=>this.emit("error",i))}if(e>this.remain){let i=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[de](()=>this.emit("error",i))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(e===this.remain)for(let i=e;i<this.length&&e<this.blockRemain;i++)this.buf[i+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[Ji]():this[gr](()=>this[Ji]())}[gr](e){this.once("drain",e)}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this.blockRemain<e.length){let r=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",r)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,i)}[Ji](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[de](e=>e?this.emit("error",e):this.end());if(!this.buf)throw new 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[ti]()}},fh=class extends bn{sync=!0;[dr](){this[ii](V.lstatSync(this.absolute))}[cr](){this[mr](V.readlinkSync(this.absolute))}[pr](){this[fr](V.openSync(this.absolute,"r"))}[ti](){let e=!0;try{let{fd:t,buf:i,offset:r,length:s,pos:n}=this;if(t===void 0||i===void 0)throw new Error("fd and buf must be set in READ method");let o=V.readSync(t,i,r,s,n);this[ur](o),e=!1}finally{if(e)try{this[de](()=>{})}catch{}}}[gr](e){e()}[de](e=()=>{}){this.fd!==void 0&&V.closeSync(this.fd),e()}},gh=class extends Le{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,i={}){return gi(this,e,t,i)}constructor(e,t={}){let i=xr(t);super(),this.preservePaths=!!i.preservePaths,this.portable=!!i.portable,this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.onWriteEntry=i.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r==="Unsupported")throw new Error("writing entry that should be ignored");this.type=r,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=i.prefix,this.path=u(e.path),this.mode=e.mode!==void 0?this[di](e.mode):void 0,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:i.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?u(e.linkpath):void 0,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){let[o,a]=Dr(this.path);o&&typeof a=="string"&&(this.path=a,s=o)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new Pe({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}),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path}),this.header.encode()&&!this.noPax&&super.write(new li({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 n=this.header?.block;if(!n)throw new Error("failed to encode header");super.write(n),e.pipe(this)}[Y](e){return wn(e,this.prefix)}[di](e){return yn(e,this.type==="Directory",this.portable)}write(e,t,i){typeof t=="function"&&(i=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 new Error("writing more to entry than is appropriate");return this.blockRemain-=r,super.write(e,i)}end(e,t,i){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t??"utf8")),i&&this.once("finish",i),e?super.end(e,i):super.end(i),this}},yh=e=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",wh=class He{tail;head;length=0;static create(t=[]){return new He(t)}constructor(t=[]){for(let i of t)this.push(i)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");let i=t.next,r=t.prev;return i&&(i.prev=r),r&&(r.next=i),t===this.head&&(this.head=i),t===this.tail&&(this.tail=r),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,i}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);let i=this.head;t.list=this,t.next=i,i&&(i.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}pushNode(t){if(t===this.tail)return;t.list&&t.list.removeNode(t);let i=this.tail;t.list=this,t.prev=i,i&&(i.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let i=0,r=t.length;i<r;i++)Eh(this,t[i]);return this.length}unshift(...t){for(var i=0,r=t.length;i<r;i++)Sh(this,t[i]);return this.length}pop(){if(!this.tail)return;let t=this.tail.value,i=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,i.list=void 0,this.length--,t}shift(){if(!this.head)return;let t=this.head.value,i=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,i.list=void 0,this.length--,t}forEach(t,i){i=i||this;for(let r=this.head,s=0;r;s++)t.call(i,r.value,s,this),r=r.next}forEachReverse(t,i){i=i||this;for(let r=this.tail,s=this.length-1;r;s--)t.call(i,r.value,s,this),r=r.prev}get(t){let i=0,r=this.head;for(;r&&i<t;i++)r=r.next;if(i===t&&r)return r.value}getReverse(t){let i=0,r=this.tail;for(;r&&i<t;i++)r=r.prev;if(i===t&&r)return r.value}map(t,i){i=i||this;let r=new He;for(let s=this.head;s;)r.push(t.call(i,s.value,this)),s=s.next;return r}mapReverse(t,i){i=i||this;var r=new He;for(let s=this.tail;s;)r.push(t.call(i,s.value,this)),s=s.prev;return r}reduce(t,i){let r,s=this.head;if(arguments.length>1)r=i;else if(this.head)s=this.head.next,r=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var n=0;s;n++)r=t(r,s.value,n),s=s.next;return r}reduceReverse(t,i){let r,s=this.tail;if(arguments.length>1)r=i;else if(this.tail)s=this.tail.prev,r=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let n=this.length-1;s;n--)r=t(r,s.value,n),s=s.prev;return r}toArray(){let t=new Array(this.length);for(let i=0,r=this.head;r;i++)t[i]=r.value,r=r.next;return t}toArrayReverse(){let t=new Array(this.length);for(let i=0,r=this.tail;r;i++)t[i]=r.value,r=r.prev;return t}slice(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new He;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.head,n=0;for(n=0;s&&n<t;n++)s=s.next;for(;s&&n<i;n++,s=s.next)r.push(s.value);return r}sliceReverse(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new He;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.length,n=this.tail;for(;n&&s>i;s--)n=n.prev;for(;n&&s>t;s--,n=n.prev)r.push(n.value);return r}splice(t,i=0,...r){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let s=this.head;for(let o=0;s&&o<t;o++)s=s.next;let n=[];for(let o=0;s&&o<i;o++)n.push(s.value),s=this.removeNode(s);s?s!==this.tail&&(s=s.prev):s=this.tail;for(let o of r)s=bh(this,s,o);return n}reverse(){let t=this.head,i=this.tail;for(let r=t;r;r=r.prev){let s=r.prev;r.prev=r.next,r.next=s}return this.head=i,this.tail=t,this}};function bh(e,t,i){let r=t,s=t?t.next:e.head,n=new Ir(i,r,s,e);return n.next===void 0&&(e.tail=n),n.prev===void 0&&(e.head=n),e.length++,n}function Eh(e,t){e.tail=new Ir(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function Sh(e,t){e.head=new Ir(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Ir=class{list;next;prev;value;constructor(e,t,i,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,i?(i.prev=this,this.next=i):this.next=void 0}},Hs=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||"./",this.absolute=t}},Ws=Buffer.alloc(1024),ri=Symbol("onStat"),at=Symbol("ended"),$=Symbol("queue"),ht=Symbol("pendingLinks"),ae=Symbol("current"),ke=Symbol("process"),lt=Symbol("processing"),qt=Symbol("processJob"),U=Symbol("jobs"),Xi=Symbol("jobDone"),si=Symbol("addFSEntry"),Gs=Symbol("addTarEntry"),yr=Symbol("stat"),wr=Symbol("readdir"),ni=Symbol("onreaddir"),oi=Symbol("pipe"),Zs=Symbol("entry"),Qi=Symbol("entryOpt"),ai=Symbol("writeEntryClass"),En=Symbol("write"),er=Symbol("ondrain"),bi=class extends Le{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[ai];onWriteEntry;[$];[ht]=new Map;[U]=0;[lt]=!1;[at]=!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=u(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[ai]=bn,typeof e.onwarn=="function"&&this.on("warn",e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if((e.gzip?1:0)+(e.brotli?1:0)+(e.zstd?1:0)>1)throw new 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 Oa(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new xa(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new La(e.zstd)),!this.zip)throw new Error("impossible");let t=this.zip;t.on("data",i=>super.write(i)),t.on("end",()=>super.end()),t.on("drain",()=>this[er]()),this.on("resume",()=>t.resume())}else this.on("drain",this[er]);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[$]=new wh,this[U]=0,this.jobs=Number(e.jobs)||4,this[lt]=!1,this[at]=!1}[En](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&this.add(e),this[at]=!0,this[ke](),i&&i(),this}write(e){if(this[at])throw new Error("write after end");return typeof e=="string"?this[si](e):this[Gs](e),this.flowing}[Gs](e){let t=u(js.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let i=new Hs(e.path,t);i.entry=new gh(e,this[Qi](i)),i.entry.on("end",()=>this[Xi](i)),this[U]+=1,this[$].push(i)}this[ke]()}[si](e){let t=u(js.resolve(this.cwd,e));this[$].push(new Hs(e,t)),this[ke]()}[yr](e){e.pending=!0,this[U]+=1;let t=this.follow?"stat":"lstat";ci[t](e.absolute,(i,r)=>{e.pending=!1,this[U]-=1,i?this.emit("error",i):this[ri](e,r)})}[ri](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[ae])this[qt](e);else{let i=`${t.dev}:${t.ino}`,r=this[ht].get(i);r?r.push(e):this[ht].set(i,[e]),e.pendingLink=!0,e.pending=!0}this[ke]()}[wr](e){e.pending=!0,this[U]+=1,ci.readdir(e.absolute,(t,i)=>{if(e.pending=!1,this[U]-=1,t)return this.emit("error",t);this[ni](e,i)})}[ni](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[ke]()}[ke](){if(!this[lt]){this[lt]=!0;for(let e=this[$].head;e&&this[U]<this.jobs;e=e.next)if(this[qt](e.value),e.value.ignore){let t=e.next;this[$].removeNode(e),e.next=t}this[lt]=!1,this[at]&&this[$].length===0&&this[U]===0&&(this.zip?this.zip.end(Ws):(super.write(Ws),super.end()))}}get[ae](){return this[$]&&this[$].head&&this[$].head.value}[Xi](e){this[$].shift(),this[U]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let i=`${t.dev}:${t.ino}`,r=this[ht].get(i);if(r){this[ht].delete(i);for(let s of r)s.pending=!1,this[qt](s)}}this[ke]()}[qt](e){if(e.pending&&e.pendingLink&&e===this[ae]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[ae]&&!e.piped&&this[oi](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[ri](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[ni](e,t):this[wr](e),!e.readdir)return}if(e.entry=this[Zs](e),!e.entry){e.ignore=!0;return}e===this[ae]&&!e.piped&&this[oi](e)}}}[Qi](e){return{onwarn:(t,i,r)=>this.warn(t,i,r),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}}[Zs](e){this[U]+=1;try{return new this[ai](e.path,this[Qi](e)).on("end",()=>this[Xi](e)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[er](){this[ae]&&this[ae].entry&&this[ae].entry.resume()}[oi](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[si](n+r)});let t=e.entry,i=this.zip;if(!t)throw new Error("cannot pipe without source");i?t.on("data",r=>{i.write(r)||t.pause()}):t.on("data",r=>{super.write(r)||t.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,t,i={}){gi(this,e,t,i)}},Nr=class extends bi{sync=!0;constructor(e){super(e),this[ai]=fh}pause(){}resume(){}[yr](e){let t=this.follow?"statSync":"lstatSync";this[ri](e,ci[t](e.absolute))}[wr](e){this[ni](e,ci.readdirSync(e.absolute))}[oi](e){let t=e.entry,i=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[si](n+r)}),!t)throw new Error("Cannot pipe without source");i?t.on("data",r=>{i.write(r)}):t.on("data",r=>{super[En](r)})}},vh=(e,t)=>{let i=new Nr(e),r=new an(e.file,{mode:e.mode||438});i.pipe(r),Sn(i,t)},Rh=(e,t)=>{let i=new bi(e),r=new pi(e.file,{mode:e.mode||438});i.pipe(r);let s=new Promise((n,o)=>{r.on("error",o),r.on("close",n),i.on("error",o)});return vn(i,t).catch(n=>i.emit("error",n)),s},Sn=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?yi({file:hn.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},vn=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await yi({file:hn.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>{e.add(r)}}):e.add(i);e.end()},_h=(e,t)=>{let i=new Nr(e);return Sn(i,t),i},kh=(e,t)=>{let i=new bi(e);return vn(i,t).catch(r=>i.emit("error",r)),i},dd=vt(vh,Rh,_h,kh,(e,t)=>{if(!t?.length)throw new TypeError("no paths specified to add to archive")}),Th=process.env.__FAKE_PLATFORM__||process.platform,On=Th==="win32",{O_CREAT:Tn,O_NOFOLLOW:Ks,O_TRUNC:xn,O_WRONLY:Pn}=kn.constants,Ln=Number(process.env.__FAKE_FS_O_FILENAME__)||kn.constants.UV_FS_O_FILEMAP||0,xh=On&&!!Ln,Ph=512*1024,Lh=Ln|xn|Tn|Pn,Vs=!On&&typeof Ks=="number"?Ks|xn|Tn|Pn:null,Dn=Vs!==null?()=>Vs:xh?e=>e<Ph?Lh:"w":()=>"w",br=(e,t,i)=>{try{return Ei.lchownSync(e,t,i)}catch(r){if(r?.code!=="ENOENT")throw r}},ui=(e,t,i,r)=>{Ei.lchown(e,t,i,s=>{r(s&&s?.code!=="ENOENT"?s:null)})},Dh=(e,t,i,r,s)=>{if(t.isDirectory())An(ft.resolve(e,t.name),i,r,n=>{if(n)return s(n);let o=ft.resolve(e,t.name);ui(o,i,r,s)});else{let n=ft.resolve(e,t.name);ui(n,i,r,s)}},An=(e,t,i,r)=>{Ei.readdir(e,{withFileTypes:!0},(s,n)=>{if(s){if(s.code==="ENOENT")return r();if(s.code!=="ENOTDIR"&&s.code!=="ENOTSUP")return r(s)}if(s||!n.length)return ui(e,t,i,r);let o=n.length,a=null,h=l=>{if(!a){if(l)return r(a=l);if(--o===0)return ui(e,t,i,r)}};for(let l of n)Dh(e,l,t,i,h)})},Ah=(e,t,i,r)=>{t.isDirectory()&&In(ft.resolve(e,t.name),i,r),br(ft.resolve(e,t.name),i,r)},In=(e,t,i)=>{let r;try{r=Ei.readdirSync(e,{withFileTypes:!0})}catch(s){let n=s;if(n?.code==="ENOENT")return;if(n?.code==="ENOTDIR"||n?.code==="ENOTSUP")return br(e,t,i);throw n}for(let s of r)Ah(e,s,t,i);return br(e,t,i)},Nn=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"}},Si=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"}},Nh=(e,t)=>{N.stat(e,(i,r)=>{(i||!r.isDirectory())&&(i=new Nn(e,i?.code||"ENOTDIR")),t(i)})},Ch=(e,t,i)=>{e=u(e);let r=t.umask??18,s=t.mode|448,n=(s&r)!==0,o=t.uid,a=t.gid,h=typeof o=="number"&&typeof a=="number"&&(o!==t.processUid||a!==t.processGid),l=t.preserve,c=t.unlink,d=u(t.cwd),p=(g,E)=>{g?i(g):E&&h?An(E,o,a,F=>p(F)):n?N.chmod(e,s,i):i()};if(e===d)return Nh(e,p);if(l)return Ih.mkdir(e,{mode:s,recursive:!0}).then(g=>p(null,g??void 0),p);let w=u(mi.relative(d,e)).split("/");Er(d,w,s,c,d,void 0,p)},Er=(e,t,i,r,s,n,o)=>{if(t.length===0)return o(null,n);let a=t.shift(),h=u(mi.resolve(e+"/"+a));N.mkdir(h,i,Cn(h,t,i,r,s,n,o))},Cn=(e,t,i,r,s,n,o)=>a=>{a?N.lstat(e,(h,l)=>{if(h)h.path=h.path&&u(h.path),o(h);else if(l.isDirectory())Er(e,t,i,r,s,n,o);else if(r)N.unlink(e,c=>{if(c)return o(c);N.mkdir(e,i,Cn(e,t,i,r,s,n,o))});else{if(l.isSymbolicLink())return o(new Si(e,e+"/"+t.join("/")));o(a)}}):(n=n||e,Er(e,t,i,r,s,n,o))},Mh=e=>{let t=!1,i;try{t=N.statSync(e).isDirectory()}catch(r){i=r?.code}finally{if(!t)throw new Nn(e,i??"ENOTDIR")}},Fh=(e,t)=>{e=u(e);let i=t.umask??18,r=t.mode|448,s=(r&i)!==0,n=t.uid,o=t.gid,a=typeof n=="number"&&typeof o=="number"&&(n!==t.processUid||o!==t.processGid),h=t.preserve,l=t.unlink,c=u(t.cwd),d=g=>{g&&a&&In(g,n,o),s&&N.chmodSync(e,r)};if(e===c)return Mh(c),d();if(h)return d(N.mkdirSync(e,{mode:r,recursive:!0})??void 0);let p=u(mi.relative(c,e)).split("/"),w;for(let g=p.shift(),E=c;g&&(E+="/"+g);g=p.shift()){E=u(mi.resolve(E));try{N.mkdirSync(E,r),w=w||E}catch{let F=N.lstatSync(E);if(F.isDirectory())continue;if(l){N.unlinkSync(E),N.mkdirSync(E,r),w=w||E;continue}else if(F.isSymbolicLink())return new Si(E,E+"/"+p.join("/"))}}return d(w)},tr=Object.create(null),Ys=1e4,Fe=new Set,Bh=e=>{Fe.has(e)?Fe.delete(e):tr[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Fe.add(e);let t=tr[e],i=Fe.size-Ys;if(i>Ys/10){for(let r of Fe)if(Fe.delete(r),delete tr[r],--i<=0)break}return t},$h=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Uh=$h==="win32",zh=e=>e.split("/").slice(0,-1).reduce((t,i)=>{let r=t.at(-1);return r!==void 0&&(i=Mn(r,i)),t.push(i||"/"),t},[]),jh=class{#e=new Map;#i=new Map;#r=new Set;reserve(e,t){e=Uh?["win32 parallelization disabled"]:e.map(r=>pt(Mn(Bh(r))));let i=new Set(e.map(r=>zh(r)).reduce((r,s)=>r.concat(s)));this.#i.set(t,{dirs:i,paths:e});for(let r of e){let s=this.#e.get(r);s?s.push(t):this.#e.set(r,[t])}for(let r of i){let s=this.#e.get(r);if(!s)this.#e.set(r,[new Set([t])]);else{let n=s.at(-1);n instanceof Set?n.add(t):s.push(new Set([t]))}}return this.#s(t)}#n(e){let t=this.#i.get(e);if(!t)throw new Error("function does not have any path reservations");return{paths:t.paths.map(i=>this.#e.get(i)),dirs:[...t.dirs].map(i=>this.#e.get(i))}}check(e){let{paths:t,dirs:i}=this.#n(e);return t.every(r=>r&&r[0]===e)&&i.every(r=>r&&r[0]instanceof Set&&r[0].has(e))}#s(e){return this.#r.has(e)||!this.check(e)?!1:(this.#r.add(e),e(()=>this.#t(e)),!0)}#t(e){if(!this.#r.has(e))return!1;let t=this.#i.get(e);if(!t)throw new Error("invalid reservation");let{paths:i,dirs:r}=t,s=new Set;for(let n of i){let o=this.#e.get(n);if(!o||o?.[0]!==e)continue;let a=o[1];if(!a){this.#e.delete(n);continue}if(o.shift(),typeof a=="function")s.add(a);else for(let h of a)s.add(h)}for(let n of r){let o=this.#e.get(n),a=o?.[0];if(!(!o||!(a instanceof Set)))if(a.size===1&&o.length===1){this.#e.delete(n);continue}else if(a.size===1){o.shift();let h=o[0];typeof h=="function"&&s.add(h)}else a.delete(e)}return this.#r.delete(e),s.forEach(n=>this.#s(n)),!0}},Hh=()=>process.umask(),qs=Symbol("onEntry"),Sr=Symbol("checkFs"),Js=Symbol("checkFs2"),vr=Symbol("isReusable"),M=Symbol("makeFs"),Rr=Symbol("file"),_r=Symbol("directory"),hi=Symbol("link"),Xs=Symbol("symlink"),Qs=Symbol("hardlink"),ut=Symbol("ensureNoSymlink"),en=Symbol("unsupported"),tn=Symbol("checkPath"),ir=Symbol("stripAbsolutePath"),ue=Symbol("mkdir"),O=Symbol("onError"),Jt=Symbol("pending"),rn=Symbol("pend"),Be=Symbol("unpend"),rr=Symbol("ended"),sr=Symbol("maybeClose"),kr=Symbol("skip"),gt=Symbol("doChown"),yt=Symbol("uid"),wt=Symbol("gid"),bt=Symbol("checkedCwd"),Wh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Et=Wh==="win32",Gh=1024,Zh=(e,t)=>{if(!Et)return m.unlink(e,t);let i=e+".DELETE."+_n(16).toString("hex");m.rename(e,i,r=>{if(r)return t(r);m.unlink(i,t)})},Kh=e=>{if(!Et)return m.unlinkSync(e);let t=e+".DELETE."+_n(16).toString("hex");m.renameSync(e,t),m.unlinkSync(t)},sn=(e,t,i)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:i,Cr=class extends St{[rr]=!1;[bt]=!1;[Jt]=0;reservations=new jh;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[rr]=!0,this[sr]()},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 new TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw new 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?.()===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:Gh,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||Et,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=u(v.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:Hh():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",t=>this[qs](t))}warn(e,t,i={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(i.recoverable=!1),super.warn(e,t,i)}[sr](){this[rr]&&this[Jt]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[ir](e,t){let i=e[t],{type:r}=e;if(!i||this.preservePaths)return!0;let[s,n]=Dr(i),o=n.replaceAll(/\\/g,"/").split("/");if(o.includes("..")||Et&&/^[a-z]:\.\.$/i.test(o[0]??"")){if(t==="path"||r==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:i}),!1;let a=v.posix.dirname(e.path),h=v.posix.normalize(v.posix.join(a,o.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:i}),!1}return s&&(e[t]=String(n),this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute ${t}`,{entry:e,[t]:i})),!0}[tn](e){let t=u(e.path),i=t.split("/");if(this.strip){if(i.length<this.strip)return!1;if(e.type==="Link"){let r=u(String(e.linkpath)).split("/");if(r.length>=this.strip)e.linkpath=r.slice(this.strip).join("/");else return!1}i.splice(0,this.strip),e.path=i.join("/")}if(isFinite(this.maxDepth)&&i.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:i.length,maxDepth:this.maxDepth}),!1;if(!this[ir](e,"path")||!this[ir](e,"linkpath"))return!1;if(e.absolute=v.isAbsolute(e.path)?u(v.resolve(e.path)):u(v.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:u(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:r}=v.win32.parse(String(e.absolute));e.absolute=r+Fs(String(e.absolute).slice(r.length));let{root:s}=v.win32.parse(e.path);e.path=s+Fs(e.path.slice(s.length))}return!0}[qs](e){if(!this[tn](e))return e.resume();switch(Oh.equal(typeof e.absolute,"string"),e.type){case"Directory":case"GNUDumpDir":e.mode&&(e.mode=e.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Sr](e);default:return this[en](e)}}[O](e,t){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:t}),this[Be](),t.resume())}[ue](e,t,i){Ch(u(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},i)}[gt](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}[yt](e){return sn(this.uid,e.uid,this.processUid)}[wt](e){return sn(this.gid,e.gid,this.processGid)}[Rr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new pi(String(e.absolute),{flags:Dn(e.size),mode:i,autoClose:!1});r.on("error",a=>{r.fd&&m.close(r.fd,()=>{}),r.write=()=>!0,this[O](a,e),t()});let s=1,n=a=>{if(a){r.fd&&m.close(r.fd,()=>{}),this[O](a,e),t();return}--s===0&&r.fd!==void 0&&m.close(r.fd,h=>{h?this[O](h,e):this[Be](),t()})};r.on("finish",()=>{let a=String(e.absolute),h=r.fd;if(typeof h=="number"&&e.mtime&&!this.noMtime){s++;let l=e.atime||new Date,c=e.mtime;m.futimes(h,l,c,d=>d?m.utimes(a,l,c,p=>n(p&&d)):n())}if(typeof h=="number"&&this[gt](e)){s++;let l=this[yt](e),c=this[wt](e);typeof l=="number"&&typeof c=="number"&&m.fchown(h,l,c,d=>d?m.chown(a,l,c,p=>n(p&&d)):n())}n()});let o=this.transform&&this.transform(e)||e;o!==e&&(o.on("error",a=>{this[O](a,e),t()}),e.pipe(o)),o.pipe(r)}[_r](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode;this[ue](String(e.absolute),i,r=>{if(r){this[O](r,e),t();return}let s=1,n=()=>{--s===0&&(t(),this[Be](),e.resume())};e.mtime&&!this.noMtime&&(s++,m.utimes(String(e.absolute),e.atime||new Date,e.mtime,n)),this[gt](e)&&(s++,m.chown(String(e.absolute),Number(this[yt](e)),Number(this[wt](e)),n)),n()})}[en](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[Xs](e,t){let i=u(v.relative(this.cwd,v.resolve(v.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[ut](e,this.cwd,i,()=>this[hi](e,String(e.linkpath),"symlink",t),r=>{this[O](r,e),t()})}[Qs](e,t){let i=u(v.resolve(this.cwd,String(e.linkpath))),r=u(String(e.linkpath)).split("/");this[ut](e,this.cwd,r,()=>this[hi](e,i,"link",t),s=>{this[O](s,e),t()})}[ut](e,t,i,r,s){let n=i.shift();if(this.preservePaths||n===void 0)return r();let o=v.resolve(t,n);m.lstat(o,(a,h)=>{if(a)return r();if(h?.isSymbolicLink())return s(new Si(o,v.resolve(o,i.join("/"))));this[ut](e,o,i,r,s)})}[rn](){this[Jt]++}[Be](){this[Jt]--,this[sr]()}[kr](e){this[Be](),e.resume()}[vr](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!Et}[Sr](e){this[rn]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,i=>this[Js](e,i))}[Js](e,t){let i=o=>{t(o)},r=()=>{this[ue](this.cwd,this.dmode,o=>{if(o){this[O](o,e),i();return}this[bt]=!0,s()})},s=()=>{if(e.absolute!==this.cwd){let o=u(v.dirname(String(e.absolute)));if(o!==this.cwd)return this[ue](o,this.dmode,a=>{if(a){this[O](a,e),i();return}n()})}n()},n=()=>{m.lstat(String(e.absolute),(o,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[kr](e),i();return}if(o||this[vr](e,a))return this[M](null,e,i);if(a.isDirectory()){if(e.type==="Directory"){let h=this.chmod&&e.mode&&(a.mode&4095)!==e.mode,l=c=>this[M](c??null,e,i);return h?m.chmod(String(e.absolute),Number(e.mode),l):l()}if(e.absolute!==this.cwd)return m.rmdir(String(e.absolute),h=>this[M](h??null,e,i))}if(e.absolute===this.cwd)return this[M](null,e,i);Zh(String(e.absolute),h=>this[M](h??null,e,i))})};this[bt]?s():r()}[M](e,t,i){if(e){this[O](e,t),i();return}switch(t.type){case"File":case"OldFile":case"ContiguousFile":return this[Rr](t,i);case"Link":return this[Qs](t,i);case"SymbolicLink":return this[Xs](t,i);case"Directory":case"GNUDumpDir":return this[_r](t,i)}}[hi](e,t,i,r){m[i](t,String(e.absolute),s=>{s?this[O](s,e):(this[Be](),e.resume()),r()})}},ct=e=>{try{return[null,e()]}catch(t){return[t,null]}},Fn=class extends Cr{sync=!0;[M](e,t){return super[M](e,t,()=>{})}[Sr](e){if(!this[bt]){let s=this[ue](this.cwd,this.dmode);if(s)return this[O](s,e);this[bt]=!0}if(e.absolute!==this.cwd){let s=u(v.dirname(String(e.absolute)));if(s!==this.cwd){let n=this[ue](s,this.dmode);if(n)return this[O](n,e)}}let[t,i]=ct(()=>m.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[kr](e);if(t||this[vr](e,i))return this[M](null,e);if(i.isDirectory()){if(e.type==="Directory"){let n=this.chmod&&e.mode&&(i.mode&4095)!==e.mode,[o]=n?ct(()=>{m.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[M](o,e)}let[s]=ct(()=>m.rmdirSync(String(e.absolute)));this[M](s,e)}let[r]=e.absolute===this.cwd?[]:ct(()=>Kh(String(e.absolute)));this[M](r,e)}[Rr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=o=>{let a;try{m.closeSync(s)}catch(h){a=h}(o||a)&&this[O](o||a,e),t()},s;try{s=m.openSync(String(e.absolute),Dn(e.size),i)}catch(o){return r(o)}let n=this.transform&&this.transform(e)||e;n!==e&&(n.on("error",o=>this[O](o,e)),e.pipe(n)),n.on("data",o=>{try{m.writeSync(s,o,0,o.length)}catch(a){r(a)}}),n.on("end",()=>{let o=null;if(e.mtime&&!this.noMtime){let a=e.atime||new Date,h=e.mtime;try{m.futimesSync(s,a,h)}catch(l){try{m.utimesSync(String(e.absolute),a,h)}catch{o=l}}}if(this[gt](e)){let a=this[yt](e),h=this[wt](e);try{m.fchownSync(s,Number(a),Number(h))}catch(l){try{m.chownSync(String(e.absolute),Number(a),Number(h))}catch{o=o||l}}}r(o)})}[_r](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[ue](String(e.absolute),i);if(r){this[O](r,e),t();return}if(e.mtime&&!this.noMtime)try{m.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[gt](e))try{m.chownSync(String(e.absolute),Number(this[yt](e)),Number(this[wt](e)))}catch{}t(),e.resume()}[ue](e,t){try{return Fh(u(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(i){return i}}[ut](e,t,i,r,s){if(this.preservePaths||i.length===0)return r();let n=t;for(let o of i){n=v.resolve(n,o);let[a,h]=ct(()=>m.lstatSync(n));if(a)return r();if(h.isSymbolicLink())return s(new Si(n,v.resolve(t,i.join("/"))))}r()}[hi](e,t,i,r){let s=`${i}Sync`;try{m[s](t,String(e.absolute)),r(),e.resume()}catch(n){return this[O](n,e)}}},Vh=e=>{let t=new Fn(e),i=e.file,r=Rn.statSync(i),s=e.maxReadSize||16*1024*1024;new da(i,{readSize:s,size:r.size}).pipe(t)},Yh=(e,t)=>{let i=new Cr(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("close",n),Rn.stat(s,(a,h)=>{if(a)o(a);else{let l=new Tr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},Bn=vt(Vh,Yh,e=>new Fn(e),e=>new Cr(e),(e,t)=>{t?.length&&gn(e,t)}),qh=(e,t)=>{let i=new Nr(e),r=!0,s,n;try{try{s=I.openSync(e.file,"r+")}catch(h){if(h?.code==="ENOENT")s=I.openSync(e.file,"w+");else throw h}let o=I.fstatSync(s),a=Buffer.alloc(512);e:for(n=0;n<o.size;n+=512){for(let c=0,d=0;c<512;c+=d){if(d=I.readSync(s,a,c,a.length-c,n+c),n===0&&a[0]===31&&a[1]===139)throw new Error("cannot append to compressed archives");if(!d)break e}let h=new Pe(a);if(!h.cksumValid)break;let l=512*Math.ceil((h.size||0)/512);if(n+l+512>o.size)break;n+=l,e.mtimeCache&&h.mtime&&e.mtimeCache.set(String(h.path),h.mtime)}r=!1,Jh(e,i,n,s,t)}finally{if(r)try{I.closeSync(s)}catch{}}},Jh=(e,t,i,r,s)=>{let n=new an(e.file,{fd:r,start:i});t.pipe(n),Qh(t,s)},Xh=(e,t)=>{t=Array.from(t);let i=new bi(e),r=(s,n,o)=>{let a=(p,w)=>{p?I.close(s,g=>o(p)):o(null,w)},h=0;if(n===0)return a(null,0);let l=0,c=Buffer.alloc(512),d=(p,w)=>{if(p||w===void 0)return a(p);if(l+=w,l<512&&w)return I.read(s,c,l,c.length-l,h+l,d);if(h===0&&c[0]===31&&c[1]===139)return a(new Error("cannot append to compressed archives"));if(l<512)return a(null,h);let g=new Pe(c);if(!g.cksumValid)return a(null,h);let E=512*Math.ceil((g.size??0)/512);if(h+E+512>n||(h+=E+512,h>=n))return a(null,h);e.mtimeCache&&g.mtime&&e.mtimeCache.set(String(g.path),g.mtime),l=0,I.read(s,c,0,512,h,d)};I.read(s,c,0,512,h,d)};return new Promise((s,n)=>{i.on("error",n);let o="r+",a=(h,l)=>{if(h&&h.code==="ENOENT"&&o==="r+")return o="w+",I.open(e.file,o,a);if(h||!l)return n(h);I.fstat(l,(c,d)=>{if(c)return I.close(l,()=>n(c));r(l,d.size,(p,w)=>{if(p)return n(p);let g=new pi(e.file,{fd:l,start:w});i.pipe(g),g.on("error",n),g.on("close",s),el(i,t)})})};I.open(e.file,o,a)})},Qh=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?yi({file:$n.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},el=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await yi({file:$n.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i);e.end()},dt=vt(qh,Xh,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(e,t)=>{if(!ba(e))throw new TypeError("file is required");if(e.gzip||e.brotli||e.zstd||e.file.endsWith(".br")||e.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!t?.length)throw new TypeError("no paths specified to add/replace")}),Od=vt(dt.syncFile,dt.asyncFile,dt.syncNoFile,dt.asyncNoFile,(e,t=[])=>{dt.validate?.(e,t),tl(e)}),tl=e=>{let t=e.filter;e.mtimeCache||(e.mtimeCache=new Map),e.filter=t?(i,r)=>t(i,r)&&!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0)):(i,r)=>!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0))};var Rt=Ie("taco.cli.upgrade"),al="https://registry.npmjs.org",zn=3e4;async function hl(e,t,i,r){let s=i==="latest"?`${e}/${t}/latest`:`${e}/${t}/${i}`,n=new AbortController,o=setTimeout(()=>n.abort(),zn);try{let a=await r(s,{signal:n.signal});if(!a.ok)throw new Error(`registry returned ${a.status} ${a.statusText} for ${t}@${i}`);return await a.json()}finally{clearTimeout(o)}}async function ll(e,t,i){let r=new AbortController,s=setTimeout(()=>r.abort(),zn);try{let n=await i(e,{signal:r.signal});if(!n.ok)throw new Error(`tarball download ${n.status} ${n.statusText} for ${e}`);if(!n.body)throw new Error(`tarball response had no body for ${e}`);await Mr(Un(t),{recursive:!0});let o=await sl(t,"w");try{let a=0,h=n.body.getReader();for(;;){let{done:l,value:c}=await h.read();if(l)break;await o.write(c),a+=c.byteLength}return a}finally{await o.close()}}finally{clearTimeout(s)}}async function cl(e,t){let[i,r]=t.split("-");if(i!=="sha512")throw new Error(`unsupported integrity algorithm: ${i}`);let s=il("sha512");await new Promise((o,a)=>{let h=rl(e);h.on("data",l=>s.update(l)),h.on("end",()=>o()),h.on("error",a)});let n=s.digest("base64");if(n!==r)throw new Error(`integrity mismatch: expected ${r}, got ${n}`)}async function jn(e={}){let t=e.fetcher??globalThis.fetch;if(typeof t!="function")throw new Error("global fetch is not available; pass opts.fetcher explicitly");let i=e.tacoHome??T,r=e.registry??al,s=e.platformKey?{key:e.platformKey,pkg:`@taco-ai/sidecar-${e.platformKey}`}:Fr(),n=e.version??"latest";Rt.info(`fetching metadata for ${s.pkg}@${n}`);let o=await hl(r,s.pkg,n,t);if(!o.dist?.tarball||!o.dist?.integrity)throw new Error(`registry response missing dist.tarball/integrity for ${s.pkg}@${n}`);let a=o.version,h=vi(i,"staging",`sidecar-${s.key}-${a}`),l=vi(i,"cache","sidecar",`sidecar-${s.key}-${a}.tgz`);Rt.info(`downloading tarball \u2192 ${l}`),await Mr(Un(l),{recursive:!0}),await ll(o.dist.tarball,l,t),Rt.info("verifying integrity"),await cl(l,o.dist.integrity),await nl(h,{recursive:!0,force:!0}),await Mr(h,{recursive:!0}),Rt.info(`extracting \u2192 ${h}`),await Bn({file:l,cwd:h,strip:1}),await dl(h);let c=e.liveDirOverride??await ul(s.key);if(!c)throw new Error(`no current @taco-ai/sidecar-${s.key} install found; run 'taco install' first`);let d={version:a,staging_dir:h,live_dir:c,written_at:new Date().toISOString()},p=vi(i,"upgrade-marker.json");return await as(p,d),Rt.info(`upgrade staged \u2192 version=${a}, marker=${p}`),{version:a,stagingDir:h,liveDir:c}}async function dl(e){for(let t of["manifest.json","bin","lib"]){let i=vi(e,t);try{await ol(i)}catch{throw new Error(`staged bundle missing ${t} at ${i}`)}}}async function ul(e){let{createRequire:t}=await import("node:module"),i=t(import.meta.url);try{let r=i.resolve(`@taco-ai/sidecar-${e}/package.json`),s=r.lastIndexOf("/package.json");return s<0?r:r.slice(0,s)}catch{return null}}var Hn=`taco \u2014 launcher + supervisor for the sidecar daemon
|
|
88
88
|
|
|
89
89
|
Usage:
|
|
90
90
|
taco start Spawn the daemon; prints its NDJSON socket path.
|
|
@@ -100,7 +100,7 @@ Environment:
|
|
|
100
100
|
TACO_HOME Root directory for daemon state (default ~/.taco).
|
|
101
101
|
TACO_SIDECAR_DEV=1 Force dev launcher (tsx + repo source) even when a
|
|
102
102
|
@taco-ai/sidecar-<platform> bundle is installed.
|
|
103
|
-
`;async function
|
|
103
|
+
`;async function ml(e){let t=e[2];switch(t){case"start":return await gs(),0;case"status":return await ys(),0;case"stop":return await bs(),0;case"install":return await Xr(),0;case"uninstall":return await vs(),0;case"upgrade":return e.includes("--apply")?await Nt():await jn(),0;case"help":case"--help":case"-h":case void 0:return process.stdout.write(Hn),0;default:return process.stderr.write(`unknown subcommand: ${t}
|
|
104
104
|
|
|
105
|
-
${
|
|
106
|
-
`),process.exit(1)});export{
|
|
105
|
+
${Hn}`),1}}var pl=(()=>{try{let e=process.argv[1];if(!e)return!1;let t=new URL(`file://${e}`).href;return import.meta.url===t}catch{return!1}})();pl&&ml(process.argv).then(e=>process.exit(e??0),e=>{process.stderr.write(`[taco] error: ${e?.stack??e}
|
|
106
|
+
`),process.exit(1)});export{ml as run};
|
package/lib/installSchtasks.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/** Windows service registration through Task Scheduler.
|
|
2
|
-
*
|
|
3
|
-
*
|
|
1
|
+
/** Windows service registration through Task Scheduler. The daemon is
|
|
2
|
+
* per-user ($TACO_HOME lives under %USERPROFILE%), so the task runs as the
|
|
3
|
+
* creating user at logon — ONLOGON without /RU — never elevated, so the
|
|
4
|
+
* installer can terminate the process when upgrading over a live daemon.
|
|
5
|
+
* The wrapper bakes in the per-user home and runtime paths because schtasks
|
|
6
|
+
* cannot define environment variables. */
|
|
4
7
|
|
|
5
8
|
import { writeFileSync } from "node:fs";
|
|
6
9
|
import { join } from "node:path";
|
|
@@ -77,6 +80,20 @@ export interface InstallSchtasksInput {
|
|
|
77
80
|
control: string;
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
/** Args for the `schtasks /Create` call. Pure so tests can pin the contract
|
|
84
|
+
* that keeps the daemon killable by the installer:
|
|
85
|
+
* - ONLOGON without /RU runs the task as the creating user at sign-in.
|
|
86
|
+
* (ONSTART without /RU would run as SYSTEM, whose processes a per-user
|
|
87
|
+
* installer cannot kill — the source of "Error opening file for writing"
|
|
88
|
+
* on upgrade.)
|
|
89
|
+
* - No /RL HIGHEST: the daemon is pure user-mode; elevation only breaks
|
|
90
|
+
* the installer's ability to terminate it.
|
|
91
|
+
* - /F overwrites any prior registration; re-running `taco install` is the
|
|
92
|
+
* supported update path. */
|
|
93
|
+
export function schtasksCreateArgs(wrapperPath: string): string[] {
|
|
94
|
+
return ["/Create", "/SC", "ONLOGON", "/TN", SCHTASKS_NAME, "/TR", `"${wrapperPath}"`, "/F"];
|
|
95
|
+
}
|
|
96
|
+
|
|
80
97
|
/** Run the Windows install: write the .cmd wrapper + create the scheduled
|
|
81
98
|
* task via schtasks. We don't wait for the daemon socket (Windows named
|
|
82
99
|
* pipes don't have a stable readiness signal without a probe round-trip
|
|
@@ -95,23 +112,7 @@ export async function installSchtasks(input: InstallSchtasksInput): Promise<Inst
|
|
|
95
112
|
});
|
|
96
113
|
writeFileSync(wrapperPath, wrapperContent, { mode: 0o755 });
|
|
97
114
|
|
|
98
|
-
|
|
99
|
-
// under %USERPROFILE%\.taco is a per-user path. `/RL HIGHEST` runs the
|
|
100
|
-
// task with the highest privileges available (still the user). `/F`
|
|
101
|
-
// overwrites any prior registration; re-running `taco install` is the
|
|
102
|
-
// supported update path.
|
|
103
|
-
await execFile("schtasks", [
|
|
104
|
-
"/Create",
|
|
105
|
-
"/SC",
|
|
106
|
-
"ONSTART",
|
|
107
|
-
"/TN",
|
|
108
|
-
SCHTASKS_NAME,
|
|
109
|
-
"/TR",
|
|
110
|
-
`"${wrapperPath}"`,
|
|
111
|
-
"/RL",
|
|
112
|
-
"HIGHEST",
|
|
113
|
-
"/F",
|
|
114
|
-
]);
|
|
115
|
+
await execFile("schtasks", schtasksCreateArgs(wrapperPath));
|
|
115
116
|
|
|
116
117
|
// Kick the task immediately so the user doesn't have to sign out + in
|
|
117
118
|
// to see the install take effect. `/Run` returns once the task is
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taco-ai/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Taco CLI — launcher + daemon supervisor for the sidecar. Wraps @taco-ai/sidecar with user-facing subcommands (start, status, install, upgrade).",
|
|
6
6
|
"type": "module",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"tar": "^7.5.22",
|
|
25
|
-
"@taco-ai/shared": "0.2.
|
|
26
|
-
"@taco-ai/sidecar": "0.2.
|
|
25
|
+
"@taco-ai/shared": "0.2.4",
|
|
26
|
+
"@taco-ai/sidecar": "0.2.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.7.0",
|