@taco-ai/cli 0.4.7 → 0.4.8
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 +26 -26
- package/lib/installId.ts +4 -98
- package/lib/installSchtasks.ts +1 -19
- package/lib/paths.ts +22 -61
- package/lib/start.ts +4 -12
- package/lib/upgradeMarker.ts +13 -52
- package/lib/upgradeTypes.ts +3 -13
- package/package.json +3 -3
package/dist/taco.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as bo}from"node:child_process";import{existsSync as Ke,readFileSync as rs}from"node:fs";import{createRequire as Eo}from"node:module";import{dirname as So,join as Pt}from"node:path";import{spawn as lo}from"node:child_process";import{closeSync as co,existsSync as Le,mkdirSync as uo,openSync as mo,readFileSync as po}from"node:fs";import{createRequire as fo}from"node:module";import{dirname as Ze,join as j}from"node:path";import{fileURLToPath as Xr,pathToFileURL as go}from"node:url";var fe=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"],ao={"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"},ho="@taco-ai/sidecar-";function Yr(){let e=Jr();return{key:e,pkg:`${ho}${e}`}}function qr(){return ao[Jr()]}function Jr(){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 Ae(){let e=Ze(Xr(import.meta.url));for(let t=0;t<8;t++){if(Le(j(e,"pnpm-workspace.yaml")))return e;let i=Ze(e);if(i===e)break;e=i}return null}function xt(e=Ae()){return e!==null&&process.env.TACO_SIDECAR_DEV!=="0"}function yo(e){let t=j(e,"node_modules","tsx","dist","loader.mjs");if(Le(t))return t;let i=Ze(Xr(import.meta.url));for(let r=0;r<8;r++){let s=j(i,"node_modules","tsx","dist","loader.mjs");if(Le(s))return s;let n=Ze(i);if(n===i)break;i=n}throw new Error("tsx loader not found (node_modules/tsx/dist/loader.mjs). Run `pnpm install` in the taco checkout.")}function wo(e){let t=yo(e),i=go(t).href;return{program:process.execPath,args:["--import",i,j(e,"packages","sidecar","src","index.ts")],cwd:e}}function Qr(){let e=fo(import.meta.url);for(let t of fe)try{let i=e.resolve(`@taco-ai/sidecar-${t}/package.json`),r=Ze(i),s=j(r,"manifest.json");if(!Le(s))continue;let n=JSON.parse(po(s,"utf8")),o=j(r,"bin",n.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Le(o))continue;let a=j(r,"lib","index.mjs");if(!Le(a))continue;return{nodeBin:o,bundle:a,resources:r,sidecarVersion:typeof n.sidecarVersion=="string"?n.sidecarVersion:null}}catch{}return null}function es(){return Qr()?.sidecarVersion??null}function ts(e){let t=Ae(),i=e.forceDev===!0||xt(t),r,s;if(i&&t)r=wo(t),s=j(t,"packages","sidecar","src");else{let h=Qr();if(!h)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:h.nodeBin,args:[h.bundle]},s=h.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},o="inherit";if(process.platform==="win32"){delete n.TACO_STDERR_LOG,o="ignore";try{let h=j(e.tacoHome,"logs");uo(h,{recursive:!0}),o=mo(j(h,"daemon.err.log"),"a")}catch{o="ignore"}}let a=lo(r.program,r.args,{cwd:r.cwd,env:n,detached:!0,stdio:["ignore","ignore",o],...process.platform==="win32"?{windowsHide:!0}:{}});return typeof o=="number"&&co(o),{child:a,dev:i}}function Dt(){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:ss(s)}}let t=Eo(import.meta.url);for(let r of fe){let s;try{s=So(t.resolve(`@taco-ai/sidecar-${r}/package.json`))}catch{continue}let n=is(s);if(n)return n}let i=Ae();if(i!==null){let r=Pt(i,"packages","sidecar","dist","runtime",qr()),s=is(r);if(s)return s}return null}function is(e){let t=Pt(e,"manifest.json");if(!Ke(t))return null;let i;try{i=JSON.parse(rs(t,"utf8"))}catch{return null}let r=Pt(e,"bin",i.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Ke(r))return null;let s=Pt(e,"lib","index.mjs");if(!Ke(s))return null;let n=i.daemonMode===!0?!0:ss(s);return{pkgDir:e,nodeBin:r,bundle:s,resources:e,daemonMode:n}}function ss(e){try{return rs(e,"utf8").includes("TACO_DAEMON_MODE")}catch{return!1}}function H(e,t,i={}){return new Promise((r,s)=>{let n=bo(e,t,{stdio:["ignore","pipe","pipe"],windowsHide:!0}),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 ns}from"node:fs";import{connect as vo}from"node:net";import{homedir as Ro}from"node:os";import{join as os}from"node:path";var as="com.taco-ai.sidecar";function Ai(){return os(Ro(),"Library","LaunchAgents",`${as}.plist`)}function _o(e){return os(e,"bin","taco-sidecar-daemon")}function Lt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ve(e){return`'${e.replace(/'/g,"'\\''")}'`}function ko(e){return`#!/bin/sh
|
|
2
2
|
# Generated by 'taco install' \u2014 do not edit.
|
|
3
3
|
set -e
|
|
4
4
|
|
|
@@ -6,19 +6,19 @@ SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
|
6
6
|
TACO_HOME=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
|
|
7
7
|
export TACO_HOME
|
|
8
8
|
|
|
9
|
-
export TACO_SOCKET=${
|
|
10
|
-
export TACO_CONTROL_SOCKET=${
|
|
9
|
+
export TACO_SOCKET=${Ve(e.socketPath)}
|
|
10
|
+
export TACO_CONTROL_SOCKET=${Ve(e.controlSocketPath)}
|
|
11
11
|
export TACO_DAEMON_MODE=1
|
|
12
|
-
export TACO_SIDECAR_RESOURCES=${
|
|
12
|
+
export TACO_SIDECAR_RESOURCES=${Ve(e.resourcesRoot)}
|
|
13
13
|
|
|
14
|
-
NODE_BIN=${
|
|
15
|
-
BUNDLE=${
|
|
14
|
+
NODE_BIN=${Ve(e.nodeBin)}
|
|
15
|
+
BUNDLE=${Ve(e.bundle)}
|
|
16
16
|
exec "$NODE_BIN" "$BUNDLE"
|
|
17
|
-
`}function
|
|
17
|
+
`}function Oo(e){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
18
18
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
19
19
|
<plist version="1.0">
|
|
20
20
|
<dict>
|
|
21
|
-
<key>Label</key> <string>${
|
|
21
|
+
<key>Label</key> <string>${as}</string>
|
|
22
22
|
<key>ProgramArguments</key>
|
|
23
23
|
<array>
|
|
24
24
|
<string>${Lt(e.wrapperPath)}</string>
|
|
@@ -40,7 +40,7 @@ exec "$NODE_BIN" "$BUNDLE"
|
|
|
40
40
|
</dict>
|
|
41
41
|
</dict>
|
|
42
42
|
</plist>
|
|
43
|
-
`}function
|
|
43
|
+
`}function To(e,t){let i=Date.now()+t;return new Promise((r,s)=>{let n=()=>{let o=vo(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 hs(e){let t=_o(e.tacoHome),i=Ai(),r=ko({socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});ns(t,r,{mode:493});let s=Oo({wrapperPath:t,tacoHome:e.tacoHome,logDir:e.logDir});ns(i,s,{mode:420});try{await H("launchctl",["bootout",i],{allowFailure:!0})}catch{}await H("launchctl",["load","-w",i]);try{await To(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 xo}from"node:fs";import{join as Po}from"node:path";var Ye="TacoSidecar";function Do(e){return Po(e,"bin","taco-sidecar-daemon.vbs")}function ge(e){return e.replace(/"/g,'""')}function Lo(e){let t=ge(e.tacoHome),i=ge(e.socketPath),r=ge(e.controlSocketPath),s=ge(e.nodeBin),n=ge(e.bundle),o=ge(e.resourcesRoot),a=ge(`${e.tacoHome}\\logs\\daemon.err.log`);return`' Generated by 'taco install' \u2014 do not edit.
|
|
44
44
|
' Invokes the bundled sidecar in daemon mode under schtasks.
|
|
45
45
|
' Window style 0 (SW_HIDE) + wait so logon does not flash a console.
|
|
46
46
|
Option Explicit
|
|
@@ -65,28 +65,28 @@ env("TACO_SIDECAR_RESOURCES") = "${o}"
|
|
|
65
65
|
env("TACO_STDERR_LOG") = "${a}"
|
|
66
66
|
|
|
67
67
|
WScript.Quit sh.Run("""${s}"" ""${n}""", 0, True)
|
|
68
|
-
`}function
|
|
69
|
-
`)}function
|
|
68
|
+
`}function Ao(e){return["/Create","/SC","ONLOGON","/TN",Ye,"/TR",`wscript.exe //nologo "${e}"`,"/F"]}async function ls(e){let t=Do(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 xo(t,`\uFEFF${i}`,{encoding:"utf16le"}),await H("schtasks",Ao(t)),await H("schtasks",["/Run","/TN",Ye],{allowFailure:!0}),{serviceManager:"schtasks",wrapperPath:t,taskName:Ye}}import{mkdir as Je}from"node:fs/promises";import{join as Xe}from"node:path";import{createHash as cs,randomUUID as Io}from"node:crypto";import{mkdir as Co,readFile as No,rename as Mo,unlink as ds,writeFile as Fo}from"node:fs/promises";import{homedir as Bo}from"node:os";import{dirname as $o,join as Ii,resolve as At}from"node:path";function It(e=process.env){let t=e.TACO_HOME?.trim();return t?At(t):At(Bo(),".taco")}function Ci(e=It()){return Ii(e,"run")}function Ct(e=It(),t=process.env.TACO_RUNTIME_DIR){let i=t?.trim();return i&&i.length>0?i:Ci(e)}function Ni(e){let t=e.replace(/\//g,"\\");return t.startsWith("\\\\?\\")&&(t=t.slice(4)),t=t.replace(/\\+$/,"").replace(/[A-Z]/g,i=>i.toLowerCase()),cs("sha256").update(t,"utf8").digest("hex").slice(0,16)}function us(e=Ct()){return process.platform==="win32"?`\\\\.\\pipe\\taco-sidecar-${Ni(e)}`:Ii(e,"sidecar.sock")}function ms(e=Ct()){return process.platform==="win32"?`\\\\.\\pipe\\taco-sidecar-ctl-${Ni(e)}`:Ii(e,"sidecar-ctl.sock")}function Mi(e,t){let i=cs("sha256");return i.update(e),i.update("\0"),i.update(t),i.digest("hex").slice(0,16)}function qe(e){let t=e.trim();if(!t.startsWith("{"))return null;try{let i=JSON.parse(t);if(i.version!==1)return null;let r=typeof i.pid=="number"?i.pid:Number.NaN,s=typeof i.install_id=="string"?i.install_id:null,n=typeof i.started_at=="string"?i.started_at:null,o=typeof i.sidecar_version=="string"?i.sidecar_version:null;return!Number.isFinite(r)||r<=0?null:{pid:r,installId:s,startedAt:n,version:1,sidecarVersion:o}}catch{return null}}function Fi(e,t,i){return e===null||e.installId!==null&&e.installId!==t?!1:e.sidecarVersion!==i}function Nt(e){if(!Number.isSafeInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(t){return t?.code==="EPERM"}}var Uo=2;function ps(e,t){let i=At(e),r=At(t);return process.platform==="win32"?i.toLowerCase()===r.toLowerCase():i===r}async function fs(e,t){let i;try{i=await No(e,"utf8")}catch(r){return r.code==="ENOENT"||t?.(`failed to read marker ${e}: ${String(r)}`),null}try{return JSON.parse(i)}catch(r){return t?.(`malformed marker ${e}: ${String(r)}`),null}}async function Bi(e,t){await Co($o(e),{recursive:!0});let i=`${e}.${process.pid}.${Io()}.tmp`;try{await Fo(i,JSON.stringify(t,null,Uo),"utf8"),await Mo(i,e)}finally{await ds(i).catch(()=>{})}}async function Mt(e){await ds(e).catch(t=>{if(t.code!=="ENOENT")throw t})}var C=It();function gs(e=C){return Ci(e)}function Ft(e=C,t=process.env.TACO_RUNTIME_DIR){return Ct(e,t)}var ys=Ft();function Bt(e=ys){return us(e)}function re(e=ys){return ms(e)}var $i=Xe(C,"upgrade-marker.json");async function $t(e=C,t=Ft(e)){await Je(t,{recursive:!0,mode:493}),await Je(Xe(e,"bin"),{recursive:!0,mode:493}),await Je(Xe(e,"logs"),{recursive:!0,mode:493}),await Je(Xe(e,"staging"),{recursive:!0,mode:493}),await Je(Xe(e,"jobs"),{recursive:!0,mode:493})}async function ws(e={}){let t=e.tacoHome??C,i=gs(t);await $t(t,i);let r=Dt();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:Bt(i),control:re(i)};if(process.platform==="darwin")return hs({...s,logDir:`${t}/logs`});if(process.platform==="win32")return ls({...s});throw new Error(`unsupported platform: ${process.platform}`)}import{readFileSync as Hi,unlinkSync as Jo}from"node:fs";import{createRequire as Xo}from"node:module";import{connect as Ds}from"node:net";import*as Ls from"node:path";import{join as et}from"node:path";import{mkdir as zo,readFile as jo,unlink as bs,writeFile as Es}from"node:fs/promises";import{join as Ho}from"node:path";var Wo=15e3;async function Ui(e){try{let t=await jo(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 Ss(e,t=Date.now,i=Wo){let r=Ho(e,"start.lock");await zo(e,{recursive:!0});let s={pid:process.pid,acquiredAt:t()},n=JSON.stringify(s),o=!1;try{await Es(r,n,{flag:"wx",encoding:"utf8"}),o=!0}catch(a){if(a.code==="EEXIST"){let h=await Ui(r);if(h===null||t()-h.acquiredAt>i){try{await bs(r)}catch{}try{await Es(r,n,{flag:"wx",encoding:"utf8"}),o=!0}catch(c){if(c.code==="EEXIST")return null;throw c}}else return null}else throw a}return o?{path:r,async release(){try{await bs(r)}catch(a){if(a.code!=="ENOENT")throw a}}}:null}import{copyFile as Zo,mkdir as Ko,rename as Vo,rm as zt,stat as Rs}from"node:fs/promises";import{join as jt}from"node:path";function zi(e,t,i){let r=new Date().toISOString();process.stderr.write(`${r} [${e}] [${t}] ${i}
|
|
69
|
+
`)}function Ie(e){return{info(t){zi("info",e,t)},warn(t){zi("warn",e,t)},error(t){zi("error",e,t)}}}var Go=Ie("taco.cli.upgrade.marker");function vs(e,t){return t?ps(e.live_dir,t):!1}function Ut(e){return fs(e,t=>Go.warn(t))}var ye=Ie("taco.cli.upgrade.apply");async function Ht(e={}){let t=e.tacoHome??C,i=$i.startsWith(t)?$i:jt(t,"upgrade-marker.json"),r=await Ut(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 Yo(r.staging_dir))throw ye.warn(`staging dir missing (${r.staging_dir}); clearing unusable marker`),await Mt(i),new Error(`staging dir missing: ${r.staging_dir}`);await qo(r.staging_dir);let s=`${r.live_dir}.prev`;await zt(s,{recursive:!0,force:!0});let n=e.rename??Vo;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 _s(r.staging_dir,r.live_dir),await zt(r.staging_dir,{recursive:!0,force:!0})}}catch(o){ye.error(`swap failed, rolling back: ${String(o)}`);try{await zt(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 Mt(i),e.stop)try{await e.stop()}catch(o){ye.warn(`best-effort stop failed (ignored): ${String(o)}`)}return await zt(s,{recursive:!0,force:!0}).catch(()=>{}),ye.info(`upgrade applied \u2192 version=${r.version}`),{version:r.version}}async function Yo(e){try{return(await Rs(e)).isDirectory()}catch{return!1}}async function qo(e){try{await Rs(jt(e,"manifest.json"))}catch{throw new Error(`staging dir missing manifest.json: ${e}`)}}async function _s(e,t){await Ko(t,{recursive:!0});for await(let i of await import("node:fs/promises").then(r=>r.readdir(e,{withFileTypes:!0}))){let r=jt(e,i.name),s=jt(t,i.name);i.isDirectory()?await _s(r,s):i.isFile()&&await Zo(r,s)}}var ks=15e3,Os=3e4,Qo=50,ea=2e4,ta=35e3,ia=3e3,ra={major:2,minor:0};function Ts(e,t=5e3){return new Promise(i=>{let r=Ds(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:ra,clientCapabilities:{}}};r.write(`${JSON.stringify(h)}
|
|
70
70
|
`)}),r.on("data",h=>{s+=h.toString("utf8");let l=s.indexOf(`
|
|
71
71
|
`);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(`
|
|
72
|
-
`)}),r.once("error",()=>a("absent"))})}
|
|
72
|
+
`)}),r.once("error",()=>a("absent"))})}async function ji(e,t,i,r){let s=et(e,"sidecar.pid"),n=null;try{n=qe(Hi(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()+ia;for(;Date.now()<h&&Nt(a);)await new Promise(l=>setTimeout(l,100));if(Nt(a))try{process.kill(a,"SIGKILL")}catch{}}for(let a of[t,i,s])try{Jo(a)}catch{}}var Qe=class extends Error{constructor(t,i,r){super(`a sidecar daemon (pid ${t}, install ${i}) from another taco install owns this runtime directory, so this install (${r}) cannot replace it. It is usually a launchd/schtasks service registered by \`taco install\` from a different checkout or bundle: run \`taco uninstall\` for that install, or \`taco stop\`, then retry.`),this.name="ForeignDaemonError"}};function xs(e,t){let i=null;try{i=qe(Hi(et(e,"sidecar.pid"),"utf8"))}catch{return}if(!(i===null||i.installId===null||i.installId===t)&&Nt(i.pid))throw new Qe(i.pid,i.installId,t)}async function Ps(e,t){let i=Date.now()+t,r;for(;Date.now()<i;)try{await new Promise((s,n)=>{let o=Ds(e);o.once("connect",()=>{o.destroy(),s()}),o.once("error",n)});return}catch(s){r=s,await new Promise(n=>setTimeout(n,Qo))}throw new Error(`socket ${e} did not become ready in ${t}ms (${String(r)})`)}function sa(){let e=Ae();if(xt(e)&&e)return et(e,"packages","sidecar","src");try{let t=Xo(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 Ls.dirname(r)}catch{}}catch{}}function na(e,t,i){let r=null;try{r=qe(Hi(et(e,"sidecar.pid"),"utf8"))}catch{r=null}return Fi(r,t,i)?`pid ${r?.pid??"?"} runs sidecar ${r?.sidecarVersion??"unknown"}, expected ${i}`:null}async function oa(e){let t=await Ut(et(e,"upgrade-marker.json"));if(t&&vs(t,Dt()?.resources))try{let{version:i}=await Ht({tacoHome:e});process.stderr.write(`[taco] applied pending upgrade \u2192 ${i}
|
|
73
73
|
`)}catch(i){process.stderr.write(`[taco] pending upgrade could not be applied (${String(i)}); starting existing version
|
|
74
|
-
`)}}async function
|
|
74
|
+
`)}}async function As(e={}){let t=e.tacoHome??C,i=Ft(t,e.runtimeDir);await $t(t,i);let r=Bt(i),s=re(i),n=await Ts(r);n==="wedged"&&(await new Promise(u=>setTimeout(u,500)),n=await Ts(r));let o=sa(),a=Mi(o??"",t),h=xt(),l=h?Os:ks,c=h?ta:ea;if(n==="ready"){let u=h?null:es(),f;if(h?f="dev checkout always respawns":u!==null?f=na(i,a,u):(f=null,process.stderr.write(`[taco] freshness gate disabled: no bundle manifest version; reused daemon may be stale
|
|
75
75
|
`)),f===null){process.stdout.write(`${r}
|
|
76
76
|
`),process.stderr.write(`[taco] sidecar daemon already running (socket=${r})
|
|
77
|
-
`);return}
|
|
78
|
-
`),await
|
|
79
|
-
`),await
|
|
77
|
+
`);return}xs(i,a),process.stderr.write(`[taco] sidecar daemon stale (${f}); restarting
|
|
78
|
+
`),await ji(i,r,s,a),n="absent"}n==="wedged"&&(xs(i,a),process.stderr.write(`[taco] sidecar daemon accepts connections but does not serve; killing it
|
|
79
|
+
`),await ji(i,r,s,a)),await ji(i,r,s,a);let d=await Ss(i,Date.now,l);if(!d){let u=await Ui(`${i}/start.lock`);try{await Ps(r,c)}catch(f){throw new Error(`another process (pid=${u?.pid??"unknown"}) holds the start lock but its daemon did not become ready: ${String(f)}`)}process.stdout.write(`${r}
|
|
80
80
|
`),process.stderr.write(`[taco] sidecar daemon started by pid=${u?.pid??"unknown"}
|
|
81
|
-
`);return}try{await
|
|
81
|
+
`);return}try{await oa(t);let{child:u,dev:f}=ts({socketPath:r,controlSocketPath:s,tacoHome:t,runtimeDir:i}),y=new Promise((b,P)=>{u.once("error",Li=>P(Li)),u.once("exit",(Li,oo)=>{P(new Error(`sidecar exited before binding socket (code=${Li} sig=${oo})`))})});try{let b=f?Os:ks;await Promise.race([Ps(r,b),y])}catch(b){throw u.killed||u.kill(),b}u.unref(),process.stdout.write(`${r}
|
|
82
82
|
`),process.stderr.write(`[taco] sidecar daemon started (dev=${f}, socket=${r}, control=${s}, tacoHome=${t})
|
|
83
|
-
`)}finally{await d.release()}}import{connect as
|
|
83
|
+
`)}finally{await d.release()}}import{connect as aa}from"node:net";var ha=3e3,la=1;function Wt(e,t,i={}){let r=i.timeoutMs??ha,s=i.id??la,n={method:t,id:s};return i.params!==void 0&&(n.params=i.params),new Promise((o,a)=>{let h=aa(e),l="",c=!1,d=f=>{c||(c=!0,clearTimeout(u),h.destroy(),f())},u=setTimeout(()=>{d(()=>a(new Error(`${t} timed out after ${r}ms`)))},r);h.once("error",f=>{d(()=>a(new Error(`${t}: ${f.message}`)))}),h.once("connect",()=>{h.write(`${JSON.stringify(n)}
|
|
84
84
|
`)}),h.on("data",f=>{l+=f.toString("utf8");let y=l.indexOf(`
|
|
85
|
-
`);if(y<0)return;let b=l.slice(0,y);try{let P=JSON.parse(b);"error"in P?d(()=>a(new Error(`${t}: ${P.error.code}: ${P.error.message}`))):d(()=>o(P.result))}catch(P){d(()=>a(new Error(`${t}: malformed reply: ${String(P)}`)))}}),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
|
|
86
|
-
`)}import{existsSync as
|
|
87
|
-
`)}import{existsSync as ca,unlinkSync as da}from"node:fs";async function xs(){let e=Ti();if(ca(e)){await j("launchctl",["unload",e],{allowFailure:!0});try{da(e)}catch{}}return{serviceManager:"launchd"}}async function Ps(){return await j("schtasks",["/Delete","/TN",qe,"/F"],{allowFailure:!0}),{serviceManager:"schtasks"}}async function Ls(){return process.platform==="darwin"?xs():process.platform==="win32"?Ps():{serviceManager:"none"}}import{createHash as wl}from"node:crypto";import{createReadStream as bl}from"node:fs";import{mkdir as Ur,open as El,rm as Sl,stat as vl}from"node:fs/promises";import{dirname as Kn,join as ki}from"node:path";import pa from"events";import L from"fs";import{EventEmitter as Lr}from"node:events";import mn from"node:stream";import{StringDecoder as fa}from"node:string_decoder";import gn from"node:path";import je from"node:fs";import{dirname as xa,parse as Pa}from"path";import{EventEmitter as Fa}from"events";import dr from"assert";import{Buffer as xe}from"buffer";import*as Cs from"zlib";import Ba from"zlib";import{posix as Me}from"node:path";import{basename as uh}from"node:path";import mi from"fs";import K from"fs";import js from"path";import{win32 as kh}from"node:path";import qs from"path";import Dn from"node:fs";import Hh from"node:assert";import{randomBytes as An}from"node:crypto";import p from"node:fs";import v from"node:path";import In from"fs";import Ri from"node:fs";import wt from"node:path";import I from"node:fs";import Yh from"node:fs/promises";import gi from"node:path";import{join as Wn}from"node:path";import A from"node:fs";import Zn from"node:path";var ua=Object.defineProperty,ma=(e,t)=>{for(var i in t)ua(e,i,{get:t[i],enumerable:!0})},Ds=typeof process=="object"&&process?process:{stdout:null,stderr:null},ga=e=>!!e&&typeof e=="object"&&(e instanceof De||e instanceof mn||ya(e)||wa(e)),ya=e=>!!e&&typeof e=="object"&&e instanceof Lr&&typeof e.pipe=="function"&&e.pipe!==mn.Writable.prototype.pipe,wa=e=>!!e&&typeof e=="object"&&e instanceof Lr&&typeof e.write=="function"&&typeof e.end=="function",X=Symbol("EOF"),Q=Symbol("maybeEmitEnd"),ne=Symbol("emittedEnd"),Ut=Symbol("emittingEnd"),et=Symbol("emittedError"),zt=Symbol("closed"),As=Symbol("read"),Ht=Symbol("flush"),Is=Symbol("flushChunk"),F=Symbol("encoding"),Ce=Symbol("decoder"),R=Symbol("flowing"),tt=Symbol("paused"),Ue=Symbol("resume"),_=Symbol("buffer"),x=Symbol("pipes"),k=Symbol("bufferLength"),Mi=Symbol("bufferPush"),jt=Symbol("bufferShift"),T=Symbol("objectMode"),S=Symbol("destroyed"),Fi=Symbol("error"),Bi=Symbol("emitData"),Ns=Symbol("emitEnd"),$i=Symbol("emitEnd2"),W=Symbol("async"),Ui=Symbol("abort"),Wt=Symbol("aborted"),it=Symbol("signal"),be=Symbol("dataListeners"),D=Symbol("discarded"),rt=e=>Promise.resolve().then(e),ba=e=>e(),Ea=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,va=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),pn=class{src;dest;opts;ondrain;constructor(e,t,i){this.src=e,this.dest=t,this.opts=i,this.ondrain=()=>e[Ue](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Ra=class extends pn{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)}},_a=e=>!!e.objectMode,ka=e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",De=class extends Lr{[R]=!1;[tt]=!1;[x]=[];[_]=[];[T];[F];[W];[Ce];[X]=!1;[ne]=!1;[Ut]=!1;[zt]=!1;[et]=null;[k]=0;[S]=!1;[it];[Wt]=!1;[be]=0;[D]=!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");_a(t)?(this[T]=!0,this[F]=null):ka(t)?(this[F]=t.encoding,this[T]=!1):(this[T]=!1,this[F]=null),this[W]=!!t.async,this[Ce]=this[F]?new fa(this[F]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[_]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[x]});let{signal:i}=t;i&&(this[it]=i,i.aborted?this[Ui]():i.addEventListener("abort",()=>this[Ui]()))}get bufferLength(){return this[k]}get encoding(){return this[F]}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[T]}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}[Ui](){this[Wt]=!0,this.emit("abort",this[it]?.reason),this.destroy(this[it]?.reason)}get aborted(){return this[Wt]}set aborted(e){}write(e,t,i){if(this[Wt])return!1;if(this[X])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]?rt:ba;if(!this[T]&&!Buffer.isBuffer(e)){if(va(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[T]?(this[R]&&this[k]!==0&&this[Ht](!0),this[R]?this.emit("data",e):this[Mi](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[R]):e.length?(typeof e=="string"&&!(t===this[F]&&!this[Ce]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[F]&&(e=this[Ce].write(e)),this[R]&&this[k]!==0&&this[Ht](!0),this[R]?this.emit("data",e):this[Mi](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[D]=!1,this[k]===0||e===0||e&&e>this[k])return this[Q](),null;this[T]&&(e=null),this[_].length>1&&!this[T]&&(this[_]=[this[F]?this[_].join(""):Buffer.concat(this[_],this[k])]);let t=this[As](e||null,this[_][0]);return this[Q](),t}[As](e,t){if(this[T])this[jt]();else{let i=t;e===i.length||e===null?this[jt]():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[X]&&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[X]=!0,this.writable=!1,(this[R]||!this[tt])&&this[Q](),this}[Ue](){this[S]||(!this[be]&&!this[x].length&&(this[D]=!0),this[tt]=!1,this[R]=!0,this.emit("resume"),this[_].length?this[Ht]():this[X]?this[Q]():this.emit("drain"))}resume(){return this[Ue]()}pause(){this[R]=!1,this[tt]=!0,this[D]=!1}get destroyed(){return this[S]}get flowing(){return this[R]}get paused(){return this[tt]}[Mi](e){this[T]?this[k]+=1:this[k]+=e.length,this[_].push(e)}[jt](){return this[T]?this[k]-=1:this[k]-=this[_][0].length,this[_].shift()}[Ht](e=!1){do;while(this[Is](this[jt]())&&this[_].length);!e&&!this[_].length&&!this[X]&&this.emit("drain")}[Is](e){return this.emit("data",e),this[R]}pipe(e,t){if(this[S])return e;this[D]=!1;let i=this[ne];return t=t||{},e===Ds.stdout||e===Ds.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,i?t.end&&e.end():(this[x].push(t.proxyErrors?new Ra(this,e,t):new pn(this,e,t)),this[W]?rt(()=>this[Ue]()):this[Ue]()),e}unpipe(e){let t=this[x].find(i=>i.dest===e);t&&(this[x].length===1?(this[R]&&this[be]===0&&(this[R]=!1),this[x]=[]):this[x].splice(this[x].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let i=super.on(e,t);if(e==="data")this[D]=!1,this[be]++,!this[x].length&&!this[R]&&this[Ue]();else if(e==="readable"&&this[k]!==0)super.emit("readable");else if(Ea(e)&&this[ne])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[et]){let r=t;this[W]?rt(()=>r.call(this,this[et])):r.call(this,this[et])}return i}removeListener(e,t){return this.off(e,t)}off(e,t){let i=super.off(e,t);return e==="data"&&(this[be]=this.listeners("data").length,this[be]===0&&!this[D]&&!this[x].length&&(this[R]=!1)),i}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[be]=0,!this[D]&&!this[x].length&&(this[R]=!1)),t}get emittedEnd(){return this[ne]}[Q](){!this[Ut]&&!this[ne]&&!this[S]&&this[_].length===0&&this[X]&&(this[Ut]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[zt]&&this.emit("close"),this[Ut]=!1)}emit(e,...t){let i=t[0];if(e!=="error"&&e!=="close"&&e!==S&&this[S])return!1;if(e==="data")return!this[T]&&!i?!1:this[W]?(rt(()=>this[Bi](i)),!0):this[Bi](i);if(e==="end")return this[Ns]();if(e==="close"){if(this[zt]=!0,!this[ne]&&!this[S])return!1;let s=super.emit("close");return this.removeAllListeners("close"),s}else if(e==="error"){this[et]=i,super.emit(Fi,i);let s=!this[it]||this.listeners("error").length?super.emit("error",i):!1;return this[Q](),s}else if(e==="resume"){let s=super.emit("resume");return this[Q](),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[Q](),r}[Bi](e){for(let i of this[x])i.dest.write(e)===!1&&this.pause();let t=this[D]?!1:super.emit("data",e);return this[Q](),t}[Ns](){return this[ne]?!1:(this[ne]=!0,this.readable=!1,this[W]?(rt(()=>this[$i]()),!0):this[$i]())}[$i](){if(this[Ce]){let t=this[Ce].end();if(t){for(let i of this[x])i.dest.write(t);this[D]||super.emit("data",t)}}for(let t of this[x])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[T]||(e.dataLength=0);let t=this.promise();return this.on("data",i=>{e.push(i),this[T]||(e.dataLength+=i.length)}),await t,e}async concat(){if(this[T])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[F]?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[D]=!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[X])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[X]})},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[D]=!1;let e=!1,t=()=>(this.pause(),this.off(Fi,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(Fi,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[D]=!0,this[_].length=0,this[k]=0;let t=this;return typeof t.close=="function"&&!this[zt]&&t.close(),e?this.emit("error",e):this.emit(S),this}static get isStream(){return ga}},Oa=L.writev,pe=Symbol("_autoClose"),z=Symbol("_close"),st=Symbol("_ended"),g=Symbol("_fd"),zi=Symbol("_finished"),re=Symbol("_flags"),Hi=Symbol("_flush"),lr=Symbol("_handleChunk"),cr=Symbol("_makeBuf"),gt=Symbol("_mode"),Gt=Symbol("_needDrain"),Ge=Symbol("_onerror"),Ve=Symbol("_onopen"),ji=Symbol("_onread"),ze=Symbol("_onwrite"),fe=Symbol("_open"),U=Symbol("_path"),le=Symbol("_pos"),G=Symbol("_queue"),He=Symbol("_read"),Wi=Symbol("_readSize"),ie=Symbol("_reading"),nt=Symbol("_remain"),Gi=Symbol("_size"),ti=Symbol("_write"),Ee=Symbol("_writing"),ii=Symbol("_defaultFlag"),Te=Symbol("_errored"),Dr=class extends De{[Te]=!1;[g];[U];[Wi];[ie]=!1;[Gi];[nt];[pe];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[Te]=!1,this[g]=typeof t.fd=="number"?t.fd:void 0,this[U]=e,this[Wi]=t.readSize||16*1024*1024,this[ie]=!1,this[Gi]=typeof t.size=="number"?t.size:1/0,this[nt]=this[Gi],this[pe]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[g]=="number"?this[He]():this[fe]()}get fd(){return this[g]}get path(){return this[U]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[fe](){L.open(this[U],"r",(e,t)=>this[Ve](e,t))}[Ve](e,t){e?this[Ge](e):(this[g]=t,this.emit("open",t),this[He]())}[cr](){return Buffer.allocUnsafe(Math.min(this[Wi],this[nt]))}[He](){if(!this[ie]){this[ie]=!0;let e=this[cr]();if(e.length===0)return process.nextTick(()=>this[ji](null,0,e));L.read(this[g],e,0,e.length,null,(t,i,r)=>this[ji](t,i,r))}}[ji](e,t,i){this[ie]=!1,e?this[Ge](e):this[lr](t,i)&&this[He]()}[z](){if(this[pe]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}[Ge](e){this[ie]=!0,this[z](),this.emit("error",e)}[lr](e,t){let i=!1;return this[nt]-=e,e>0&&(i=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[nt]<=0)&&(i=!1,this[z](),super.end()),i}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[g]=="number"&&this[He](),!1;case"error":return this[Te]?!1:(this[Te]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},Ta=class extends Dr{[fe](){let e=!0;try{this[Ve](null,L.openSync(this[U],"r")),e=!1}finally{e&&this[z]()}}[He](){let e=!0;try{if(!this[ie]){this[ie]=!0;do{let t=this[cr](),i=t.length===0?0:L.readSync(this[g],t,0,t.length,null);if(!this[lr](i,t))break}while(!0);this[ie]=!1}e=!1}finally{e&&this[z]()}}[z](){if(this[pe]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,L.closeSync(e),this.emit("close")}}},yi=class extends pa{readable=!1;writable=!0;[Te]=!1;[Ee]=!1;[st]=!1;[G]=[];[Gt]=!1;[U];[gt];[pe];[g];[ii];[re];[zi]=!1;[le];constructor(e,t){t=t||{},super(t),this[U]=e,this[g]=typeof t.fd=="number"?t.fd:void 0,this[gt]=t.mode===void 0?438:t.mode,this[le]=typeof t.start=="number"?t.start:void 0,this[pe]=typeof t.autoClose=="boolean"?t.autoClose:!0;let i=this[le]!==void 0?"r+":"w";this[ii]=t.flags===void 0,this[re]=t.flags===void 0?i:t.flags,this[g]===void 0&&this[fe]()}emit(e,...t){if(e==="error"){if(this[Te])return!1;this[Te]=!0}return super.emit(e,...t)}get fd(){return this[g]}get path(){return this[U]}[Ge](e){this[z](),this[Ee]=!0,this.emit("error",e)}[fe](){L.open(this[U],this[re],this[gt],(e,t)=>this[Ve](e,t))}[Ve](e,t){this[ii]&&this[re]==="r+"&&e&&e.code==="ENOENT"?(this[re]="w",this[fe]()):e?this[Ge](e):(this[g]=t,this.emit("open",t),this[Ee]||this[Hi]())}end(e,t){return e&&this.write(e,t),this[st]=!0,!this[Ee]&&!this[G].length&&typeof this[g]=="number"&&this[ze](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[st]?(this.emit("error",new Error("write() after end()")),!1):this[g]===void 0||this[Ee]||this[G].length?(this[G].push(e),this[Gt]=!0,!1):(this[Ee]=!0,this[ti](e),!0)}[ti](e){L.write(this[g],e,0,e.length,this[le],(t,i)=>this[ze](t,i))}[ze](e,t){e?this[Ge](e):(this[le]!==void 0&&typeof t=="number"&&(this[le]+=t),this[G].length?this[Hi]():(this[Ee]=!1,this[st]&&!this[zi]?(this[zi]=!0,this[z](),this.emit("finish")):this[Gt]&&(this[Gt]=!1,this.emit("drain"))))}[Hi](){if(this[G].length===0)this[st]&&this[ze](null,0);else if(this[G].length===1)this[ti](this[G].pop());else{let e=this[G];this[G]=[],Oa(this[g],e,this[le],(t,i)=>this[ze](t,i))}}[z](){if(this[pe]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}},fn=class extends yi{[fe](){let e;if(this[ii]&&this[re]==="r+")try{e=L.openSync(this[U],this[re],this[gt])}catch(t){if(t?.code==="ENOENT")return this[re]="w",this[fe]();throw t}else e=L.openSync(this[U],this[re],this[gt]);this[Ve](null,e)}[z](){if(this[pe]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,L.closeSync(e),this.emit("close")}}[ti](e){let t=!0;try{this[ze](null,L.writeSync(this[g],e,0,e.length,this[le])),t=!1}finally{if(t)try{this[z]()}catch{}}}},La=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"]]),Da=e=>!!e.sync&&!!e.file,Aa=e=>!e.sync&&!!e.file,Ia=e=>!!e.sync&&!e.file,Na=e=>!e.sync&&!e.file,Ca=e=>!!e.file,Ma=e=>La.get(e)||e,Ar=(e={})=>{if(!e)return{};let t={};for(let[i,r]of Object.entries(e)){let s=Ma(i);t[s]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},kt=(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=Ar(n);if(s?.(h,o),Da(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return e(h,o)}else if(Aa(h)){let l=t(h,o);return a?l.then(()=>a(),a):l}else if(Ia(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return i(h,o)}else if(Na(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}),$a=Ba.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},$a)),Ua=xe.concat,Ms=Object.getOwnPropertyDescriptor(xe,"concat"),za=e=>e,Vi=Ms?.writable===!0||Ms?.set!==void 0?e=>{xe.concat=e?za:Ua}:e=>{},Pe=Symbol("_superWrite"),Vt=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"}},Zi=Symbol("flushFlag"),Ir=class extends De{#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 Cs[t]!="function")throw new TypeError("Compression method not supported: "+t);try{this.#t=new Cs[t](e)}catch(i){throw new Vt(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 Vt(i))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return dr(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#s),this.write(Object.assign(xe.alloc(0),{[Zi]: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}[Pe](e){return super.write(e)}write(e,t,i){if(typeof t=="function"&&(i=t,t="utf8"),typeof e=="string"&&(e=xe.from(e,t)),this.#e)return;dr(this.#t,"zlib binding closed");let r=this.#t._handle,s=r.close;r.close=()=>{};let n=this.#t.close;this.#t.close=()=>{},Vi(!0);let o;try{let h=typeof e[Zi]=="number"?e[Zi]:this.#r;o=this.#t._processChunk(e,h),Vi(!1)}catch(h){Vi(!1),this.#o(new Vt(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 Vt(h,this.write)));let a;if(o)if(Array.isArray(o)&&o.length>0){let h=o[0];a=this[Pe](xe.from(h));for(let l=1;l<o.length;l++)a=this[Pe](o[l])}else a=this[Pe](xe.from(o));return i&&i(),a}},yn=class extends Ir{#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),dr(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)}}}},Ha=class extends yn{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[Pe](e){return this.#e?(this.#e=!1,e[9]=255,super[Pe](e)):super[Pe](e)}},ja=class extends yn{constructor(e){super(e,"Unzip")}},wn=class extends Ir{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)}},Wa=class extends wn{constructor(e){super(e,"BrotliCompress")}},Ga=class extends wn{constructor(e){super(e,"BrotliDecompress")}},bn=class extends Ir{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)}},Va=class extends bn{constructor(e){super(e,"ZstdCompress")}},Za=class extends bn{constructor(e){super(e,"ZstdDecompress")}},Ka=(e,t)=>{if(Number.isSafeInteger(e))e<0?qa(e,t):Ya(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},Ya=(e,t)=>{t[0]=128;for(var i=t.length;i>1;i--)t[i-1]=e&255,e=Math.floor(e/256)},qa=(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]=En(s):s===0?t[r-1]=0:(i=!0,t[r-1]=Sn(s))}},Ja=e=>{let t=e[0],i=t===128?Qa(e.subarray(1,e.length)):t===255?Xa(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},Xa=e=>{for(var t=e.length,i=0,r=!1,s=t-1;s>-1;s--){var n=Number(e[s]),o;r?o=En(n):n===0?o=n:(r=!0,o=Sn(n)),o!==0&&(i-=o*Math.pow(256,t-s-1))}return i},Qa=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},En=e=>(255^e)&255,Sn=e=>(255^e)+1&255,eh={};ma(eh,{code:()=>Nr,isCode:()=>ri,isName:()=>th,name:()=>wi,normalFsTypes:()=>vn});var ri=e=>wi.has(e),th=e=>Nr.has(e),vn=new Set(["0","","1","2","3","4","5","6","7","D"]),wi=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"]]),Nr=new Map(Array.from(wi).map(e=>[e[1],e[0]])),ih=e=>e===void 0||e<0?void 0:e,Le=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=Se(e,t+156,1),n=vn.has(s),o=n?i:void 0,a=n?r:void 0;if(this.path=o?.path??Se(e,t,100),this.mode=o?.mode??a?.mode??ce(e,t+100,8),this.uid=o?.uid??a?.uid??ce(e,t+108,8),this.gid=o?.gid??a?.gid??ce(e,t+116,8),this.size=ih(o?.size??a?.size??ce(e,t+124,12)),this.mtime=o?.mtime??a?.mtime??Ki(e,t+136,12),this.cksum=ce(e,t+148,12),a&&this.#i(a,!0),o&&this.#i(o),ri(s)&&(this.#e=s||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Se(e,t+157,100),e.subarray(t+257,t+265).toString()==="ustar\x0000")if(this.uname=o?.uname??a?.uname??Se(e,t+265,32),this.gname=o?.gname??a?.gname??Se(e,t+297,32),this.devmaj=o?.devmaj??a?.devmaj??ce(e,t+329,8)??0,this.devmin=o?.devmin??a?.devmin??ce(e,t+337,8)??0,e[t+475]!==0){let l=Se(e,t+345,155);this.path=l+"/"+this.path}else{let l=Se(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=i?.atime??r?.atime??Ki(e,t+476,12),this.ctime=i?.ctime??r?.ctime??Ki(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=rh(this.path||"",i),s=r[0],n=r[1];this.needPax=!!r[2],this.needPax=ve(e,t,100,s)||this.needPax,this.needPax=de(e,t+100,8,this.mode)||this.needPax,this.needPax=de(e,t+108,8,this.uid)||this.needPax,this.needPax=de(e,t+116,8,this.gid)||this.needPax,this.needPax=de(e,t+124,12,this.size)||this.needPax,this.needPax=Yi(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=ve(e,t+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",t+257,8),this.needPax=ve(e,t+265,32,this.uname)||this.needPax,this.needPax=ve(e,t+297,32,this.gname)||this.needPax,this.needPax=de(e,t+329,8,this.devmaj)||this.needPax,this.needPax=de(e,t+337,8,this.devmin)||this.needPax,this.needPax=ve(e,t+345,i,n)||this.needPax,e[t+475]!==0?this.needPax=ve(e,t+345,155,n)||this.needPax:(this.needPax=ve(e,t+345,130,n)||this.needPax,this.needPax=Yi(e,t+476,12,this.atime)||this.needPax,this.needPax=Yi(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,de(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:wi.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Nr.get(e));if(ri(t)||t==="Unsupported")this.#e=t;else if(ri(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},rh=(e,t)=>{let i=e,r="",s,n=Me.parse(e).root||".";if(Buffer.byteLength(i)<100)s=[i,r,!1];else{r=Me.dirname(i),i=Me.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=Me.join(Me.basename(r),i),r=Me.dirname(r));while(r!==n&&s===void 0);s||(s=[e.slice(0,99),"",!0])}return s},Se=(e,t,i)=>e.subarray(t,t+i).toString("utf8").replace(/\0.*/,""),Ki=(e,t,i)=>sh(ce(e,t,i)),sh=e=>e===void 0?void 0:new Date(e*1e3),ce=(e,t,i)=>Number(e[t])&128?Ja(e.subarray(t,t+i)):oh(e,t,i),nh=e=>isNaN(e)?void 0:e,oh=(e,t,i)=>nh(parseInt(e.subarray(t,t+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),ah={12:8589934591,8:2097151},de=(e,t,i,r)=>r===void 0?!1:r>ah[i]||r<0?(Ka(r,e.subarray(t,t+i)),!0):(hh(e,t,i,r),!1),hh=(e,t,i,r)=>e.write(lh(r,i),t,i,"ascii"),lh=(e,t)=>ch(Math.floor(e).toString(8),t),ch=(e,t)=>(e.length===t-1?e:new Array(t-e.length-1).join("0")+e+" ")+"\0",Yi=(e,t,i,r)=>r===void 0?!1:de(e,t,i,r.getTime()/1e3),dh=new Array(156).join("\0"),ve=(e,t,i,r)=>r===void 0?!1:(e.write(r+dh,t,i,"utf8"),r.length!==Buffer.byteLength(r)||r.length>i),ui=class Rn{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 Le({path:("PaxHeader/"+uh(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+`
|
|
88
|
-
`,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
|
|
89
|
-
`).reduce(fh,Object.create(null)),fh=(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},gh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,m=gh!=="win32"?e=>String(e):e=>String(e).replaceAll(/\\/g,"/"),yh=class extends De{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=m(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?m(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=m(e.path)),e.linkpath&&(e.linkpath=m(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="path"&&t))))}},bi=(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))},wh=1024*1024,ur=Buffer.from([31,139]),mr=Buffer.from([40,181,47,253]),bh=Math.max(ur.length,mr.length),C=Symbol("state"),Re=Symbol("writeEntry"),ee=Symbol("readEntry"),qi=Symbol("nextEntry"),Fs=Symbol("processEntry"),V=Symbol("extendedHeader"),ot=Symbol("globalExtendedHeader"),oe=Symbol("meta"),Bs=Symbol("emitMeta"),w=Symbol("buffer"),te=Symbol("queue"),ae=Symbol("ended"),Ji=Symbol("emittedEnd"),_e=Symbol("emit"),E=Symbol("unzip"),Zt=Symbol("consumeChunk"),Kt=Symbol("consumeChunkSub"),Xi=Symbol("consumeBody"),$s=Symbol("consumeMeta"),Us=Symbol("consumeHeader"),at=Symbol("consuming"),Qi=Symbol("bufferConcat"),Yt=Symbol("maybeEnd"),Fe=Symbol("writing"),Z=Symbol("aborted"),qt=Symbol("onDone"),ke=Symbol("sawValidEntry"),Jt=Symbol("sawNullBlock"),Xt=Symbol("sawEOF"),zs=Symbol("closeStream"),Eh=1e3,ht=Symbol("compressedBytesRead"),er=Symbol("decompressedBytesRead"),Hs=Symbol("checkDecompressionRatio"),Sh=()=>!0,_t=class extends Fa{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[te]=[];[w];[ee];[Re];[C]="begin";[oe]="";[V];[ot];[ae]=!1;[E];[Z]=!1;[ke];[Jt]=!1;[Xt]=!1;[Fe]=!1;[at]=!1;[Ji]=!1;[ht]=0;[er]=0;constructor(e={}){super(),this.file=e.file||"",this.on(qt,()=>{(this[C]==="begin"||this[ke]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(qt,e.ondone):this.on(qt,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:Eh,this.maxMetaEntrySize=e.maxMetaEntrySize||wh,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[zs]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,i={}){bi(this,e,t,i)}[Us](e,t){this[ke]===void 0&&(this[ke]=!1);let i;try{i=new Le(e,t,this[V],this[ot])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(i.nullBlock)this[Jt]?(this[Xt]=!0,this[C]==="begin"&&(this[C]="header"),this[_e]("eof")):(this[Jt]=!0,this[_e]("nullBlock"));else if(this[Jt]=!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[Re]=new yh(i,this[V],this[ot]);if(!this[ke])if(s.remain){let n=()=>{s.invalid||(this[ke]=!0)};s.on("end",n)}else this[ke]=!0;s.meta?s.size>this.maxMetaEntrySize?(s.ignore=!0,this[_e]("ignoredEntry",s),this[C]="ignore",s.resume()):s.size>0&&(this[oe]="",s.on("data",n=>this[oe]+=n),this[C]="meta"):(this[V]=void 0,s.ignore=s.ignore||!this.filter(s.path,s),s.ignore?(this[_e]("ignoredEntry",s),this[C]=s.remain?"ignore":"header",s.resume()):(s.remain?this[C]="body":(this[C]="header",s.end()),this[ee]?this[te].push(s):(this[te].push(s),this[qi]())))}}}[zs](){queueMicrotask(()=>this.emit("close"))}[Fs](e){let t=!0;if(!e)this[ee]=void 0,t=!1;else if(Array.isArray(e)){let[i,...r]=e;this.emit(i,...r)}else this[ee]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[qi]()),t=!1);return t}[qi](){do;while(this[Fs](this[te].shift()));if(this[te].length===0){let e=this[ee];!e||e.flowing||e.size===e.remain?this[Fe]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[Xi](e,t){let i=this[Re];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[Re]=void 0,i.end()),s.length}[$s](e,t){let i=this[Re],r=this[Xi](e,t);return!this[Re]&&i&&this[Bs](i),r}[_e](e,t,i){this[te].length===0&&!this[ee]?this.emit(e,t,i):this[te].push([e,t,i])}[Bs](e){switch(this[_e]("meta",this[oe]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[V]=ui.parse(this[oe],this[V],!1);break;case"GlobalExtendedHeader":this[ot]=ui.parse(this[oe],this[ot],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[V]??Object.create(null);this[V]=t,t.path=this[oe].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[V]||Object.create(null);this[V]=t,t.linkpath=this[oe].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){if(!this[Z]){if(this[E]){let t=this[E];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[Z]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}}[Hs](e){this[er]+=e.length;let t=this[er]/this[ht];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[Z])return i?.(),!1;if((this[E]===void 0||this.brotli===void 0&&this[E]===!1)&&e){if(this[w]&&(e=Buffer.concat([this[w],e]),this[w]=void 0),e.length<bh)return this[w]=e,i?.(),!0;for(let o=0;this[E]===void 0&&o<ur.length;o++)e[o]!==ur[o]&&(this[E]=!1);let s=!1;if(this[E]===!1&&this.zstd!==!1){s=!0;for(let o=0;o<mr.length;o++)if(e[o]!==mr[o]){s=!1;break}}let n=this.brotli===void 0&&!s;if(this[E]===!1&&n)if(e.length<512)if(this[ae])this.brotli=!0;else return this[w]=e,i?.(),!0;else try{new Le(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[E]===void 0||this[E]===!1&&(this.brotli||s)){let o=this[ae];this[ae]=!1,this[E]=this[E]===void 0?new ja({}):s?new Za({}):new Ga({}),this[E].on("data",h=>{this[Hs](h)&&this[Zt](h)}),this[E].on("error",h=>{this[Z]||this.abort(h)}),this[E].on("end",()=>{this[ae]=!0,this[Zt]()}),this[Fe]=!0,this[ht]+=e.length;let a=!!this[E][o?"end":"write"](e);return this[Fe]=!1,i?.(),a}}this[Fe]=!0,this[E]?(this[ht]+=e.length,this[E].write(e)):this[Zt](e),this[Fe]=!1;let r=this[te].length>0?!1:this[ee]?this[ee].flowing:!0;return!r&&this[te].length===0&&this[ee]?.once("drain",()=>this.emit("drain")),i?.(),r}[Qi](e){e&&!this[Z]&&(this[w]=this[w]?Buffer.concat([this[w],e]):e)}[Yt](){if(this[ae]&&!this[Ji]&&!this[Z]&&!this[at]){this[Ji]=!0;let e=this[Re];if(e?.blockRemain){let t=this[w]?this[w].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[w]&&e.write(this[w]),e.end()}this[_e](qt)}}[Zt](e){if(this[at]&&e)this[Qi](e);else if(!e&&!this[w])this[Yt]();else if(e){if(this[at]=!0,this[w]){this[Qi](e);let t=this[w];this[w]=void 0,this[Kt](t)}else this[Kt](e);for(;this[w]&&this[w]?.length>=512&&!this[Z]&&!this[Xt];){let t=this[w];this[w]=void 0,this[Kt](t)}this[at]=!1}(!this[w]||this[ae])&&this[Yt]()}[Kt](e){let t=0,i=e.length;for(;t+512<=i&&!this[Z]&&!this[Xt];)switch(this[C]){case"begin":case"header":this[Us](e,t),t+=512;break;case"ignore":case"body":t+=this[Xi](e,t);break;case"meta":t+=this[$s](e,t);break;default:throw new Error("invalid state: "+this[C])}t<i&&(this[w]=this[w]?Buffer.concat([e.subarray(t),this[w]]):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[Z]||(this[E]?(e&&(this[ht]+=e.length,this[E].write(e)),this[E].end()):(this[ae]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[Yt]())),this}},yt=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)},vh=e=>{let t=e.onReadEntry;e.onReadEntry=t?i=>{t(i),i.resume()}:i=>i.resume()},_n=(e,t)=>{let i=new Map(t.map(o=>[yt(o),!0])),r=e.filter,s=100,n=(o,a="",h=0)=>{if(h>=s)return i.set(o,!1),!1;let l=a||Pa(o).root||".",c;if(o===l)c=!1;else{let d=i.get(o);c=d!==void 0?d:n(xa(o),l,h+1)}return i.set(o,c),c};e.filter=r?(o,a)=>r(o,a)&&n(yt(o)):o=>n(yt(o))},Rh=e=>{let t=new _t(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{}}},_h=(e,t)=>{let i=new _t(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 Dr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},Ei=kt(Rh,_h,e=>new _t(e),e=>new _t(e),(e,t)=>{t?.length&&_n(e,t),e.noResume||vh(e)}),kn=(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:Oh,parse:Ws}=kh,Cr=e=>{let t="",i=Ws(e);for(;Oh(e)||i.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":i.root;e=e.slice(r.length),t+=r,i=Ws(e)}return[t,e]},Si=["|","<",">","?",":"],Mr=Si.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),Th=new Map(Si.map((e,t)=>[e,Mr[t]])),xh=new Map(Mr.map((e,t)=>[e,Si[t]])),Gs=e=>Si.reduce((t,i)=>t.split(i).join(Th.get(i)),e),Ph=e=>Mr.reduce((t,i)=>t.split(i).join(xh.get(i)),e),On=(e,t)=>t?(e=m(e).replace(/^\.(\/|$)/,""),yt(t)+"/"+e):m(e),Lh=16*1024*1024,Vs=Symbol("process"),Zs=Symbol("file"),Ks=Symbol("directory"),pr=Symbol("symlink"),Ys=Symbol("hardlink"),lt=Symbol("header"),si=Symbol("read"),fr=Symbol("lstat"),ni=Symbol("onlstat"),gr=Symbol("onread"),yr=Symbol("onreadlink"),wr=Symbol("openfile"),br=Symbol("onopenfile"),ue=Symbol("close"),pi=Symbol("mode"),Er=Symbol("awaitDrain"),tr=Symbol("ondrain"),Y=Symbol("prefix"),Tn=class extends De{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=Ar(t);super(),this.path=m(e),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||Lh,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=m(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?m(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]=Cr(this.path);n&&typeof o=="string"&&(this.path=o,r=n)}this.win32=!!i.win32||process.platform==="win32",this.win32&&(this.path=Ph(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=m(i.absolute||js.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[ni](s):this[fr]()}warn(e,t,i={}){return bi(this,e,t,i)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[fr](){K.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[ni](t)})}[ni](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=Ih(e),this.emit("stat",e),this[Vs]()}[Vs](){switch(this.type){case"File":return this[Zs]();case"Directory":return this[Ks]();case"SymbolicLink":return this[pr]();default:return this.end()}}[pi](e){return kn(e,this.type==="Directory",this.portable)}[Y](e){return On(e,this.prefix)}[lt](){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 Le({path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this[pi](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 ui({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)}[Ks](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[lt](),this.end()}[pr](){K.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[yr](t)})}[yr](e){this.linkpath=m(e),this[lt](),this.end()}[Ys](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=m(js.relative(this.cwd,e)),this.stat.size=0,this[lt](),this.end()}[Zs](){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[Ys](t);this.linkCache.set(e,this.absolute)}if(this[lt](),this.stat.size===0)return this.end();this[wr]()}[wr](){K.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[br](t)})}[br](e){if(this.fd=e,this.#e)return this[ue]();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[si]()}[si](){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");K.read(e,t,i,r,s,(n,o)=>{if(n)return this[ue](()=>this.emit("error",n));this[gr](o)})}[ue](e=()=>{}){this.fd!==void 0&&K.close(this.fd,e)}[gr](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[ue](()=>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[ue](()=>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[tr]():this[Er](()=>this[tr]())}[Er](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)}[tr](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[ue](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[si]()}},Dh=class extends Tn{sync=!0;[fr](){this[ni](K.lstatSync(this.absolute))}[pr](){this[yr](K.readlinkSync(this.absolute))}[wr](){this[br](K.openSync(this.absolute,"r"))}[si](){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=K.readSync(t,i,r,s,n);this[gr](o),e=!1}finally{if(e)try{this[ue](()=>{})}catch{}}}[Er](e){e()}[ue](e=()=>{}){this.fd!==void 0&&K.closeSync(this.fd),e()}},Ah=class extends De{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 bi(this,e,t,i)}constructor(e,t={}){let i=Ar(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=m(e.path),this.mode=e.mode!==void 0?this[pi](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?m(e.linkpath):void 0,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){let[o,a]=Cr(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 Le({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 ui({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 On(e,this.prefix)}[pi](e){return kn(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}},Ih=e=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",Nh=class We{tail;head;length=0;static create(t=[]){return new We(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++)Mh(this,t[i]);return this.length}unshift(...t){for(var i=0,r=t.length;i<r;i++)Fh(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 We;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 We;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 We;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 We;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=Ch(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 Ch(e,t,i){let r=t,s=t?t.next:e.head,n=new Fr(i,r,s,e);return n.next===void 0&&(e.tail=n),n.prev===void 0&&(e.head=n),e.length++,n}function Mh(e,t){e.tail=new Fr(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function Fh(e,t){e.head=new Fr(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Fr=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}},Xs=Buffer.alloc(1024),oi=Symbol("onStat"),ct=Symbol("ended"),B=Symbol("queue"),dt=Symbol("pendingLinks"),he=Symbol("current"),Oe=Symbol("process"),ut=Symbol("processing"),Qt=Symbol("processJob"),$=Symbol("jobs"),ir=Symbol("jobDone"),ai=Symbol("addFSEntry"),Qs=Symbol("addTarEntry"),Sr=Symbol("stat"),vr=Symbol("readdir"),hi=Symbol("onreaddir"),li=Symbol("pipe"),en=Symbol("entry"),rr=Symbol("entryOpt"),ci=Symbol("writeEntryClass"),xn=Symbol("write"),sr=Symbol("ondrain"),vi=class extends De{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[ci];onWriteEntry;[B];[dt]=new Map;[$]=0;[ut]=!1;[ct]=!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=m(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[ci]=Tn,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 Ha(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new Wa(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new Va(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[sr]()),this.on("resume",()=>t.resume())}else this.on("drain",this[sr]);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[B]=new Nh,this[$]=0,this.jobs=Number(e.jobs)||4,this[ut]=!1,this[ct]=!1}[xn](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[ct]=!0,this[Oe](),i&&i(),this}write(e){if(this[ct])throw new Error("write after end");return typeof e=="string"?this[ai](e):this[Qs](e),this.flowing}[Qs](e){let t=m(qs.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let i=new Js(e.path,t);i.entry=new Ah(e,this[rr](i)),i.entry.on("end",()=>this[ir](i)),this[$]+=1,this[B].push(i)}this[Oe]()}[ai](e){let t=m(qs.resolve(this.cwd,e));this[B].push(new Js(e,t)),this[Oe]()}[Sr](e){e.pending=!0,this[$]+=1;let t=this.follow?"stat":"lstat";mi[t](e.absolute,(i,r)=>{e.pending=!1,this[$]-=1,i?this.emit("error",i):this[oi](e,r)})}[oi](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[he])this[Qt](e);else{let i=`${t.dev}:${t.ino}`,r=this[dt].get(i);r?r.push(e):this[dt].set(i,[e]),e.pendingLink=!0,e.pending=!0}this[Oe]()}[vr](e){e.pending=!0,this[$]+=1,mi.readdir(e.absolute,(t,i)=>{if(e.pending=!1,this[$]-=1,t)return this.emit("error",t);this[hi](e,i)})}[hi](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[Oe]()}[Oe](){if(!this[ut]){this[ut]=!0;for(let e=this[B].head;e&&this[$]<this.jobs;e=e.next)if(this[Qt](e.value),e.value.ignore){let t=e.next;this[B].removeNode(e),e.next=t}this[ut]=!1,this[ct]&&this[B].length===0&&this[$]===0&&(this.zip?this.zip.end(Xs):(super.write(Xs),super.end()))}}get[he](){return this[B]&&this[B].head&&this[B].head.value}[ir](e){this[B].shift(),this[$]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let i=`${t.dev}:${t.ino}`,r=this[dt].get(i);if(r){this[dt].delete(i);for(let s of r)s.pending=!1,this[Qt](s)}}this[Oe]()}[Qt](e){if(e.pending&&e.pendingLink&&e===this[he]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[he]&&!e.piped&&this[li](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[oi](e,t):this[Sr](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[hi](e,t):this[vr](e),!e.readdir)return}if(e.entry=this[en](e),!e.entry){e.ignore=!0;return}e===this[he]&&!e.piped&&this[li](e)}}}[rr](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}}[en](e){this[$]+=1;try{return new this[ci](e.path,this[rr](e)).on("end",()=>this[ir](e)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[sr](){this[he]&&this[he].entry&&this[he].entry.resume()}[li](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ai](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={}){bi(this,e,t,i)}},Br=class extends vi{sync=!0;constructor(e){super(e),this[ci]=Dh}pause(){}resume(){}[Sr](e){let t=this.follow?"statSync":"lstatSync";this[oi](e,mi[t](e.absolute))}[vr](e){this[hi](e,mi.readdirSync(e.absolute))}[li](e){let t=e.entry,i=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ai](n+r)}),!t)throw new Error("Cannot pipe without source");i?t.on("data",r=>{i.write(r)}):t.on("data",r=>{super[xn](r)})}},Bh=(e,t)=>{let i=new Br(e),r=new fn(e.file,{mode:e.mode||438});i.pipe(r),Pn(i,t)},$h=(e,t)=>{let i=new vi(e),r=new yi(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 Ln(i,t).catch(n=>i.emit("error",n)),s},Pn=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?Ei({file:gn.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},Ln=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await Ei({file:gn.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>{e.add(r)}}):e.add(i);e.end()},Uh=(e,t)=>{let i=new Br(e);return Pn(i,t),i},zh=(e,t)=>{let i=new vi(e);return Ln(i,t).catch(r=>i.emit("error",r)),i},_d=kt(Bh,$h,Uh,zh,(e,t)=>{if(!t?.length)throw new TypeError("no paths specified to add to archive")}),jh=process.env.__FAKE_PLATFORM__||process.platform,Nn=jh==="win32",{O_CREAT:Cn,O_NOFOLLOW:tn,O_TRUNC:Mn,O_WRONLY:Fn}=In.constants,Bn=Number(process.env.__FAKE_FS_O_FILENAME__)||In.constants.UV_FS_O_FILEMAP||0,Wh=Nn&&!!Bn,Gh=512*1024,Vh=Bn|Mn|Cn|Fn,rn=!Nn&&typeof tn=="number"?tn|Mn|Cn|Fn:null,$n=rn!==null?()=>rn:Wh?e=>e<Gh?Vh:"w":()=>"w",Rr=(e,t,i)=>{try{return Ri.lchownSync(e,t,i)}catch(r){if(r?.code!=="ENOENT")throw r}},fi=(e,t,i,r)=>{Ri.lchown(e,t,i,s=>{r(s&&s?.code!=="ENOENT"?s:null)})},Zh=(e,t,i,r,s)=>{if(t.isDirectory())Un(wt.resolve(e,t.name),i,r,n=>{if(n)return s(n);let o=wt.resolve(e,t.name);fi(o,i,r,s)});else{let n=wt.resolve(e,t.name);fi(n,i,r,s)}},Un=(e,t,i,r)=>{Ri.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 fi(e,t,i,r);let o=n.length,a=null,h=l=>{if(!a){if(l)return r(a=l);if(--o===0)return fi(e,t,i,r)}};for(let l of n)Zh(e,l,t,i,h)})},Kh=(e,t,i,r)=>{t.isDirectory()&&zn(wt.resolve(e,t.name),i,r),Rr(wt.resolve(e,t.name),i,r)},zn=(e,t,i)=>{let r;try{r=Ri.readdirSync(e,{withFileTypes:!0})}catch(s){let n=s;if(n?.code==="ENOENT")return;if(n?.code==="ENOTDIR"||n?.code==="ENOTSUP")return Rr(e,t,i);throw n}for(let s of r)Kh(e,s,t,i);return Rr(e,t,i)},Hn=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"}},_i=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"}},qh=(e,t)=>{I.stat(e,(i,r)=>{(i||!r.isDirectory())&&(i=new Hn(e,i?.code||"ENOTDIR")),t(i)})},Jh=(e,t,i)=>{e=m(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=m(t.cwd),u=(y,b)=>{y?i(y):b&&h?Un(b,o,a,P=>u(P)):n?I.chmod(e,s,i):i()};if(e===d)return qh(e,u);if(l)return Yh.mkdir(e,{mode:s,recursive:!0}).then(y=>u(null,y??void 0),u);let f=m(gi.relative(d,e)).split("/");_r(d,f,s,c,d,void 0,u)},_r=(e,t,i,r,s,n,o)=>{if(t.length===0)return o(null,n);let a=t.shift(),h=m(gi.resolve(e+"/"+a));I.mkdir(h,i,jn(h,t,i,r,s,n,o))},jn=(e,t,i,r,s,n,o)=>a=>{a?I.lstat(e,(h,l)=>{if(h)h.path=h.path&&m(h.path),o(h);else if(l.isDirectory())_r(e,t,i,r,s,n,o);else if(r)I.unlink(e,c=>{if(c)return o(c);I.mkdir(e,i,jn(e,t,i,r,s,n,o))});else{if(l.isSymbolicLink())return o(new _i(e,e+"/"+t.join("/")));o(a)}}):(n=n||e,_r(e,t,i,r,s,n,o))},Xh=e=>{let t=!1,i;try{t=I.statSync(e).isDirectory()}catch(r){i=r?.code}finally{if(!t)throw new Hn(e,i??"ENOTDIR")}},Qh=(e,t)=>{e=m(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=m(t.cwd),d=y=>{y&&a&&zn(y,n,o),s&&I.chmodSync(e,r)};if(e===c)return Xh(c),d();if(h)return d(I.mkdirSync(e,{mode:r,recursive:!0})??void 0);let u=m(gi.relative(c,e)).split("/"),f;for(let y=u.shift(),b=c;y&&(b+="/"+y);y=u.shift()){b=m(gi.resolve(b));try{I.mkdirSync(b,r),f=f||b}catch{let P=I.lstatSync(b);if(P.isDirectory())continue;if(l){I.unlinkSync(b),I.mkdirSync(b,r),f=f||b;continue}else if(P.isSymbolicLink())return new _i(b,b+"/"+u.join("/"))}}return d(f)},nr=Object.create(null),sn=1e4,Be=new Set,el=e=>{Be.has(e)?Be.delete(e):nr[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Be.add(e);let t=nr[e],i=Be.size-sn;if(i>sn/10){for(let r of Be)if(Be.delete(r),delete nr[r],--i<=0)break}return t},tl=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,il=tl==="win32",rl=e=>e.split("/").slice(0,-1).reduce((t,i)=>{let r=t.at(-1);return r!==void 0&&(i=Wn(r,i)),t.push(i||"/"),t},[]),sl=class{#e=new Map;#i=new Map;#r=new Set;reserve(e,t){e=il?["win32 parallelization disabled"]:e.map(r=>yt(Wn(el(r))));let i=new Set(e.map(r=>rl(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}},nl=()=>process.umask(),nn=Symbol("onEntry"),kr=Symbol("checkFs"),on=Symbol("checkFs2"),Or=Symbol("isReusable"),M=Symbol("makeFs"),Tr=Symbol("file"),xr=Symbol("directory"),di=Symbol("link"),an=Symbol("symlink"),hn=Symbol("hardlink"),ft=Symbol("ensureNoSymlink"),ln=Symbol("unsupported"),cn=Symbol("checkPath"),or=Symbol("stripAbsolutePath"),me=Symbol("mkdir"),O=Symbol("onError"),ei=Symbol("pending"),dn=Symbol("pend"),$e=Symbol("unpend"),ar=Symbol("ended"),hr=Symbol("maybeClose"),Pr=Symbol("skip"),bt=Symbol("doChown"),Et=Symbol("uid"),St=Symbol("gid"),vt=Symbol("checkedCwd"),ol=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Rt=ol==="win32",al=1024,hl=(e,t)=>{if(!Rt)return p.unlink(e,t);let i=e+".DELETE."+An(16).toString("hex");p.rename(e,i,r=>{if(r)return t(r);p.unlink(i,t)})},ll=e=>{if(!Rt)return p.unlinkSync(e);let t=e+".DELETE."+An(16).toString("hex");p.renameSync(e,t),p.unlinkSync(t)},un=(e,t,i)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:i,$r=class extends _t{[ar]=!1;[vt]=!1;[ei]=0;reservations=new sl;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[ar]=!0,this[hr]()},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:al,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||Rt,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=m(v.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:nl():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[nn](t))}warn(e,t,i={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(i.recoverable=!1),super.warn(e,t,i)}[hr](){this[ar]&&this[ei]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[or](e,t){let i=e[t],{type:r}=e;if(!i||this.preservePaths)return!0;let[s,n]=Cr(i),o=n.replaceAll(/\\/g,"/").split("/");if(o.includes("..")||Rt&&/^[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}[cn](e){let t=m(e.path),i=t.split("/");if(this.strip){if(i.length<this.strip)return!1;if(e.type==="Link"){let r=m(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[or](e,"path")||!this[or](e,"linkpath"))return!1;if(e.absolute=v.isAbsolute(e.path)?m(v.resolve(e.path)):m(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:m(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+Gs(String(e.absolute).slice(r.length));let{root:s}=v.win32.parse(e.path);e.path=s+Gs(e.path.slice(s.length))}return!0}[nn](e){if(!this[cn](e))return e.resume();switch(Hh.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[kr](e);default:return this[ln](e)}}[O](e,t){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:t}),this[$e](),t.resume())}[me](e,t,i){Jh(m(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)}[bt](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}[Et](e){return un(this.uid,e.uid,this.processUid)}[St](e){return un(this.gid,e.gid,this.processGid)}[Tr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new yi(String(e.absolute),{flags:$n(e.size),mode:i,autoClose:!1});r.on("error",a=>{r.fd&&p.close(r.fd,()=>{}),r.write=()=>!0,this[O](a,e),t()});let s=1,n=a=>{if(a){r.fd&&p.close(r.fd,()=>{}),this[O](a,e),t();return}--s===0&&r.fd!==void 0&&p.close(r.fd,h=>{h?this[O](h,e):this[$e](),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;p.futimes(h,l,c,d=>d?p.utimes(a,l,c,u=>n(u&&d)):n())}if(typeof h=="number"&&this[bt](e)){s++;let l=this[Et](e),c=this[St](e);typeof l=="number"&&typeof c=="number"&&p.fchown(h,l,c,d=>d?p.chown(a,l,c,u=>n(u&&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)}[xr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode;this[me](String(e.absolute),i,r=>{if(r){this[O](r,e),t();return}let s=1,n=()=>{--s===0&&(t(),this[$e](),e.resume())};e.mtime&&!this.noMtime&&(s++,p.utimes(String(e.absolute),e.atime||new Date,e.mtime,n)),this[bt](e)&&(s++,p.chown(String(e.absolute),Number(this[Et](e)),Number(this[St](e)),n)),n()})}[ln](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[an](e,t){let i=m(v.relative(this.cwd,v.resolve(v.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[ft](e,this.cwd,i,()=>this[di](e,String(e.linkpath),"symlink",t),r=>{this[O](r,e),t()})}[hn](e,t){let i=m(v.resolve(this.cwd,String(e.linkpath))),r=m(String(e.linkpath)).split("/");this[ft](e,this.cwd,r,()=>this[di](e,i,"link",t),s=>{this[O](s,e),t()})}[ft](e,t,i,r,s){let n=i.shift();if(this.preservePaths||n===void 0)return r();let o=v.resolve(t,n);p.lstat(o,(a,h)=>{if(a)return r();if(h?.isSymbolicLink())return s(new _i(o,v.resolve(o,i.join("/"))));this[ft](e,o,i,r,s)})}[dn](){this[ei]++}[$e](){this[ei]--,this[hr]()}[Pr](e){this[$e](),e.resume()}[Or](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!Rt}[kr](e){this[dn]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,i=>this[on](e,i))}[on](e,t){let i=o=>{t(o)},r=()=>{this[me](this.cwd,this.dmode,o=>{if(o){this[O](o,e),i();return}this[vt]=!0,s()})},s=()=>{if(e.absolute!==this.cwd){let o=m(v.dirname(String(e.absolute)));if(o!==this.cwd)return this[me](o,this.dmode,a=>{if(a){this[O](a,e),i();return}n()})}n()},n=()=>{p.lstat(String(e.absolute),(o,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[Pr](e),i();return}if(o||this[Or](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?p.chmod(String(e.absolute),Number(e.mode),l):l()}if(e.absolute!==this.cwd)return p.rmdir(String(e.absolute),h=>this[M](h??null,e,i))}if(e.absolute===this.cwd)return this[M](null,e,i);hl(String(e.absolute),h=>this[M](h??null,e,i))})};this[vt]?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[Tr](t,i);case"Link":return this[hn](t,i);case"SymbolicLink":return this[an](t,i);case"Directory":case"GNUDumpDir":return this[xr](t,i)}}[di](e,t,i,r){p[i](t,String(e.absolute),s=>{s?this[O](s,e):(this[$e](),e.resume()),r()})}},mt=e=>{try{return[null,e()]}catch(t){return[t,null]}},Gn=class extends $r{sync=!0;[M](e,t){return super[M](e,t,()=>{})}[kr](e){if(!this[vt]){let s=this[me](this.cwd,this.dmode);if(s)return this[O](s,e);this[vt]=!0}if(e.absolute!==this.cwd){let s=m(v.dirname(String(e.absolute)));if(s!==this.cwd){let n=this[me](s,this.dmode);if(n)return this[O](n,e)}}let[t,i]=mt(()=>p.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[Pr](e);if(t||this[Or](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?mt(()=>{p.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[M](o,e)}let[s]=mt(()=>p.rmdirSync(String(e.absolute)));this[M](s,e)}let[r]=e.absolute===this.cwd?[]:mt(()=>ll(String(e.absolute)));this[M](r,e)}[Tr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=o=>{let a;try{p.closeSync(s)}catch(h){a=h}(o||a)&&this[O](o||a,e),t()},s;try{s=p.openSync(String(e.absolute),$n(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{p.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{p.futimesSync(s,a,h)}catch(l){try{p.utimesSync(String(e.absolute),a,h)}catch{o=l}}}if(this[bt](e)){let a=this[Et](e),h=this[St](e);try{p.fchownSync(s,Number(a),Number(h))}catch(l){try{p.chownSync(String(e.absolute),Number(a),Number(h))}catch{o=o||l}}}r(o)})}[xr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[me](String(e.absolute),i);if(r){this[O](r,e),t();return}if(e.mtime&&!this.noMtime)try{p.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[bt](e))try{p.chownSync(String(e.absolute),Number(this[Et](e)),Number(this[St](e)))}catch{}t(),e.resume()}[me](e,t){try{return Qh(m(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}}[ft](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]=mt(()=>p.lstatSync(n));if(a)return r();if(h.isSymbolicLink())return s(new _i(n,v.resolve(t,i.join("/"))))}r()}[di](e,t,i,r){let s=`${i}Sync`;try{p[s](t,String(e.absolute)),r(),e.resume()}catch(n){return this[O](n,e)}}},cl=e=>{let t=new Gn(e),i=e.file,r=Dn.statSync(i),s=e.maxReadSize||16*1024*1024;new Ta(i,{readSize:s,size:r.size}).pipe(t)},dl=(e,t)=>{let i=new $r(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("close",n),Dn.stat(s,(a,h)=>{if(a)o(a);else{let l=new Dr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},Vn=kt(cl,dl,e=>new Gn(e),e=>new $r(e),(e,t)=>{t?.length&&_n(e,t)}),ul=(e,t)=>{let i=new Br(e),r=!0,s,n;try{try{s=A.openSync(e.file,"r+")}catch(h){if(h?.code==="ENOENT")s=A.openSync(e.file,"w+");else throw h}let o=A.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=A.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 Le(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,ml(e,i,n,s,t)}finally{if(r)try{A.closeSync(s)}catch{}}},ml=(e,t,i,r,s)=>{let n=new fn(e.file,{fd:r,start:i});t.pipe(n),fl(t,s)},pl=(e,t)=>{t=Array.from(t);let i=new vi(e),r=(s,n,o)=>{let a=(u,f)=>{u?A.close(s,y=>o(u)):o(null,f)},h=0;if(n===0)return a(null,0);let l=0,c=Buffer.alloc(512),d=(u,f)=>{if(u||f===void 0)return a(u);if(l+=f,l<512&&f)return A.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 y=new Le(c);if(!y.cksumValid)return a(null,h);let b=512*Math.ceil((y.size??0)/512);if(h+b+512>n||(h+=b+512,h>=n))return a(null,h);e.mtimeCache&&y.mtime&&e.mtimeCache.set(String(y.path),y.mtime),l=0,A.read(s,c,0,512,h,d)};A.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+",A.open(e.file,o,a);if(h||!l)return n(h);A.fstat(l,(c,d)=>{if(c)return A.close(l,()=>n(c));r(l,d.size,(u,f)=>{if(u)return n(u);let y=new yi(e.file,{fd:l,start:f});i.pipe(y),y.on("error",n),y.on("close",s),gl(i,t)})})};A.open(e.file,o,a)})},fl=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?Ei({file:Zn.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},gl=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await Ei({file:Zn.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i);e.end()},pt=kt(ul,pl,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(e,t)=>{if(!Ca(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")}),$d=kt(pt.syncFile,pt.asyncFile,pt.syncNoFile,pt.asyncNoFile,(e,t=[])=>{pt.validate?.(e,t),yl(e)}),yl=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 Ot=Ne("taco.cli.upgrade"),Rl="https://registry.npmjs.org",Yn=3e4;async function _l(e,t,i,r){let s=i==="latest"?`${e}/${t}/latest`:`${e}/${t}/${i}`,n=new AbortController,o=setTimeout(()=>n.abort(),Yn);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 kl(e,t,i){let r=new AbortController,s=setTimeout(()=>r.abort(),Yn);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 Ur(Kn(t),{recursive:!0});let o=await El(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 Ol(e,t){let[i,r]=t.split("-");if(i!=="sha512")throw new Error(`unsupported integrity algorithm: ${i}`);let s=wl("sha512");await new Promise((o,a)=>{let h=bl(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 qn(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??N,r=e.registry??Rl,s=e.platformKey?{key:e.platformKey,pkg:`@taco-ai/sidecar-${e.platformKey}`}:zr(),n=e.version??"latest";Ot.info(`fetching metadata for ${s.pkg}@${n}`);let o=await _l(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=ki(i,"staging",`sidecar-${s.key}-${a}`),l=ki(i,"cache","sidecar",`sidecar-${s.key}-${a}.tgz`);Ot.info(`downloading tarball \u2192 ${l}`),await Ur(Kn(l),{recursive:!0}),await kl(o.dist.tarball,l,t),Ot.info("verifying integrity"),await Ol(l,o.dist.integrity),await Sl(h,{recursive:!0,force:!0}),await Ur(h,{recursive:!0}),Ot.info(`extracting \u2192 ${h}`),await Vn({file:l,cwd:h,strip:1}),await Tl(h);let c=e.liveDirOverride??await xl(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()},u=ki(i,"upgrade-marker.json");return await ps(u,d),Ot.info(`upgrade staged \u2192 version=${a}, marker=${u}`),{version:a,stagingDir:h,liveDir:c}}async function Tl(e){for(let t of["manifest.json","bin","lib"]){let i=ki(e,t);try{await vl(i)}catch{throw new Error(`staged bundle missing ${t} at ${i}`)}}}async function xl(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
|
|
85
|
+
`);if(y<0)return;let b=l.slice(0,y);try{let P=JSON.parse(b);"error"in P?d(()=>a(new Error(`${t}: ${P.error.code}: ${P.error.message}`))):d(()=>o(P.result))}catch(P){d(()=>a(new Error(`${t}: malformed reply: ${String(P)}`)))}}),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 ca=2e3;async function Is(){let e=re(),t=await Wt(e,"control.ping",{timeoutMs:ca});process.stdout.write(`${JSON.stringify(t)}
|
|
86
|
+
`)}import{existsSync as da}from"node:fs";var ua=3e3,Cs=3e3;async function ma(e){let t=Date.now();for(;Date.now()-t<Cs;){if(process.platform==="win32")return;let i=!0;try{i=da(e)}catch{i=!1}if(!i)return;await new Promise(r=>setTimeout(r,100))}throw new Error(`socket ${e} still present after ${Cs}ms`)}async function Ns(){let e=re(),t=await Wt(e,"control.shutdown",{timeoutMs:ua});await ma(e),process.stdout.write(`${JSON.stringify(t??{ok:!0})}
|
|
87
|
+
`)}import{existsSync as pa,unlinkSync as fa}from"node:fs";async function Ms(){let e=Ai();if(pa(e)){await H("launchctl",["unload",e],{allowFailure:!0});try{fa(e)}catch{}}return{serviceManager:"launchd"}}async function Fs(){return await H("schtasks",["/Delete","/TN",Ye,"/F"],{allowFailure:!0}),{serviceManager:"schtasks"}}async function Bs(){return process.platform==="darwin"?Ms():process.platform==="win32"?Fs():{serviceManager:"none"}}import{createHash as vl}from"node:crypto";import{createReadStream as Rl}from"node:fs";import{mkdir as Vr,open as _l,rm as kl,stat as Ol}from"node:fs/promises";import{dirname as io,join as Di}from"node:path";import wa from"events";import D from"fs";import{EventEmitter as Br}from"node:events";import Sn from"node:stream";import{StringDecoder as ba}from"node:string_decoder";import _n from"node:path";import je from"node:fs";import{dirname as Aa,parse as Ia}from"path";import{EventEmitter as za}from"events";import br from"assert";import{Buffer as Te}from"buffer";import*as Hs from"zlib";import ja from"zlib";import{posix as Ne}from"node:path";import{basename as gh}from"node:path";import wi from"fs";import V from"fs";import Js from"path";import{win32 as Ph}from"node:path";import nn from"path";import $n from"node:fs";import Zh from"node:assert";import{randomBytes as Un}from"node:crypto";import p from"node:fs";import v from"node:path";import zn from"fs";import xi from"node:fs";import bt from"node:path";import I from"node:fs";import Qh from"node:fs/promises";import Si from"node:path";import{join as Xn}from"node:path";import A from"node:fs";import to from"node:path";var ga=Object.defineProperty,ya=(e,t)=>{for(var i in t)ga(e,i,{get:t[i],enumerable:!0})},$s=typeof process=="object"&&process?process:{stdout:null,stderr:null},Ea=e=>!!e&&typeof e=="object"&&(e instanceof De||e instanceof Sn||Sa(e)||va(e)),Sa=e=>!!e&&typeof e=="object"&&e instanceof Br&&typeof e.pipe=="function"&&e.pipe!==Sn.Writable.prototype.pipe,va=e=>!!e&&typeof e=="object"&&e instanceof Br&&typeof e.write=="function"&&typeof e.end=="function",J=Symbol("EOF"),X=Symbol("maybeEmitEnd"),se=Symbol("emittedEnd"),Gt=Symbol("emittingEnd"),tt=Symbol("emittedError"),Zt=Symbol("closed"),Us=Symbol("read"),Kt=Symbol("flush"),zs=Symbol("flushChunk"),F=Symbol("encoding"),Ce=Symbol("decoder"),R=Symbol("flowing"),it=Symbol("paused"),$e=Symbol("resume"),_=Symbol("buffer"),x=Symbol("pipes"),k=Symbol("bufferLength"),Wi=Symbol("bufferPush"),Vt=Symbol("bufferShift"),T=Symbol("objectMode"),S=Symbol("destroyed"),Gi=Symbol("error"),Zi=Symbol("emitData"),js=Symbol("emitEnd"),Ki=Symbol("emitEnd2"),W=Symbol("async"),Vi=Symbol("abort"),Yt=Symbol("aborted"),rt=Symbol("signal"),we=Symbol("dataListeners"),L=Symbol("discarded"),st=e=>Promise.resolve().then(e),Ra=e=>e(),_a=e=>e==="end"||e==="finish"||e==="prefinish",ka=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),vn=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()}},Ta=class extends vn{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)}},xa=e=>!!e.objectMode,Pa=e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",De=class extends Br{[R]=!1;[it]=!1;[x]=[];[_]=[];[T];[F];[W];[Ce];[J]=!1;[se]=!1;[Gt]=!1;[Zt]=!1;[tt]=null;[k]=0;[S]=!1;[rt];[Yt]=!1;[we]=0;[L]=!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");xa(t)?(this[T]=!0,this[F]=null):Pa(t)?(this[F]=t.encoding,this[T]=!1):(this[T]=!1,this[F]=null),this[W]=!!t.async,this[Ce]=this[F]?new ba(this[F]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[_]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[x]});let{signal:i}=t;i&&(this[rt]=i,i.aborted?this[Vi]():i.addEventListener("abort",()=>this[Vi]()))}get bufferLength(){return this[k]}get encoding(){return this[F]}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[T]}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}[Vi](){this[Yt]=!0,this.emit("abort",this[rt]?.reason),this.destroy(this[rt]?.reason)}get aborted(){return this[Yt]}set aborted(e){}write(e,t,i){if(this[Yt])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]?st:Ra;if(!this[T]&&!Buffer.isBuffer(e)){if(Oa(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(ka(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[T]?(this[R]&&this[k]!==0&&this[Kt](!0),this[R]?this.emit("data",e):this[Wi](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[R]):e.length?(typeof e=="string"&&!(t===this[F]&&!this[Ce]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[F]&&(e=this[Ce].write(e)),this[R]&&this[k]!==0&&this[Kt](!0),this[R]?this.emit("data",e):this[Wi](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[L]=!1,this[k]===0||e===0||e&&e>this[k])return this[X](),null;this[T]&&(e=null),this[_].length>1&&!this[T]&&(this[_]=[this[F]?this[_].join(""):Buffer.concat(this[_],this[k])]);let t=this[Us](e||null,this[_][0]);return this[X](),t}[Us](e,t){if(this[T])this[Vt]();else{let i=t;e===i.length||e===null?this[Vt]():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[it])&&this[X](),this}[$e](){this[S]||(!this[we]&&!this[x].length&&(this[L]=!0),this[it]=!1,this[R]=!0,this.emit("resume"),this[_].length?this[Kt]():this[J]?this[X]():this.emit("drain"))}resume(){return this[$e]()}pause(){this[R]=!1,this[it]=!0,this[L]=!1}get destroyed(){return this[S]}get flowing(){return this[R]}get paused(){return this[it]}[Wi](e){this[T]?this[k]+=1:this[k]+=e.length,this[_].push(e)}[Vt](){return this[T]?this[k]-=1:this[k]-=this[_][0].length,this[_].shift()}[Kt](e=!1){do;while(this[zs](this[Vt]())&&this[_].length);!e&&!this[_].length&&!this[J]&&this.emit("drain")}[zs](e){return this.emit("data",e),this[R]}pipe(e,t){if(this[S])return e;this[L]=!1;let i=this[se];return t=t||{},e===$s.stdout||e===$s.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,i?t.end&&e.end():(this[x].push(t.proxyErrors?new Ta(this,e,t):new vn(this,e,t)),this[W]?st(()=>this[$e]()):this[$e]()),e}unpipe(e){let t=this[x].find(i=>i.dest===e);t&&(this[x].length===1?(this[R]&&this[we]===0&&(this[R]=!1),this[x]=[]):this[x].splice(this[x].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let i=super.on(e,t);if(e==="data")this[L]=!1,this[we]++,!this[x].length&&!this[R]&&this[$e]();else if(e==="readable"&&this[k]!==0)super.emit("readable");else if(_a(e)&&this[se])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[tt]){let r=t;this[W]?st(()=>r.call(this,this[tt])):r.call(this,this[tt])}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[L]&&!this[x].length&&(this[R]=!1)),i}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[we]=0,!this[L]&&!this[x].length&&(this[R]=!1)),t}get emittedEnd(){return this[se]}[X](){!this[Gt]&&!this[se]&&!this[S]&&this[_].length===0&&this[J]&&(this[Gt]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Zt]&&this.emit("close"),this[Gt]=!1)}emit(e,...t){let i=t[0];if(e!=="error"&&e!=="close"&&e!==S&&this[S])return!1;if(e==="data")return!this[T]&&!i?!1:this[W]?(st(()=>this[Zi](i)),!0):this[Zi](i);if(e==="end")return this[js]();if(e==="close"){if(this[Zt]=!0,!this[se]&&!this[S])return!1;let s=super.emit("close");return this.removeAllListeners("close"),s}else if(e==="error"){this[tt]=i,super.emit(Gi,i);let s=!this[rt]||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}[Zi](e){for(let i of this[x])i.dest.write(e)===!1&&this.pause();let t=this[L]?!1:super.emit("data",e);return this[X](),t}[js](){return this[se]?!1:(this[se]=!0,this.readable=!1,this[W]?(st(()=>this[Ki]()),!0):this[Ki]())}[Ki](){if(this[Ce]){let t=this[Ce].end();if(t){for(let i of this[x])i.dest.write(t);this[L]||super.emit("data",t)}}for(let t of this[x])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[T]||(e.dataLength=0);let t=this.promise();return this.on("data",i=>{e.push(i),this[T]||(e.dataLength+=i.length)}),await t,e}async concat(){if(this[T])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[F]?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[L]=!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[L]=!1;let e=!1,t=()=>(this.pause(),this.off(Gi,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(Gi,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[L]=!0,this[_].length=0,this[k]=0;let t=this;return typeof t.close=="function"&&!this[Zt]&&t.close(),e?this.emit("error",e):this.emit(S),this}static get isStream(){return Ea}},Da=D.writev,me=Symbol("_autoClose"),z=Symbol("_close"),nt=Symbol("_ended"),g=Symbol("_fd"),Yi=Symbol("_finished"),ie=Symbol("_flags"),qi=Symbol("_flush"),yr=Symbol("_handleChunk"),wr=Symbol("_makeBuf"),yt=Symbol("_mode"),qt=Symbol("_needDrain"),We=Symbol("_onerror"),Ge=Symbol("_onopen"),Ji=Symbol("_onread"),Ue=Symbol("_onwrite"),pe=Symbol("_open"),U=Symbol("_path"),he=Symbol("_pos"),G=Symbol("_queue"),ze=Symbol("_read"),Xi=Symbol("_readSize"),te=Symbol("_reading"),ot=Symbol("_remain"),Qi=Symbol("_size"),oi=Symbol("_write"),be=Symbol("_writing"),ai=Symbol("_defaultFlag"),Oe=Symbol("_errored"),$r=class extends De{[Oe]=!1;[g];[U];[Xi];[te]=!1;[Qi];[ot];[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[g]=typeof t.fd=="number"?t.fd:void 0,this[U]=e,this[Xi]=t.readSize||16*1024*1024,this[te]=!1,this[Qi]=typeof t.size=="number"?t.size:1/0,this[ot]=this[Qi],this[me]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[g]=="number"?this[ze]():this[pe]()}get fd(){return this[g]}get path(){return this[U]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[pe](){D.open(this[U],"r",(e,t)=>this[Ge](e,t))}[Ge](e,t){e?this[We](e):(this[g]=t,this.emit("open",t),this[ze]())}[wr](){return Buffer.allocUnsafe(Math.min(this[Xi],this[ot]))}[ze](){if(!this[te]){this[te]=!0;let e=this[wr]();if(e.length===0)return process.nextTick(()=>this[Ji](null,0,e));D.read(this[g],e,0,e.length,null,(t,i,r)=>this[Ji](t,i,r))}}[Ji](e,t,i){this[te]=!1,e?this[We](e):this[yr](t,i)&&this[ze]()}[z](){if(this[me]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,D.close(e,t=>t?this.emit("error",t):this.emit("close"))}}[We](e){this[te]=!0,this[z](),this.emit("error",e)}[yr](e,t){let i=!1;return this[ot]-=e,e>0&&(i=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[ot]<=0)&&(i=!1,this[z](),super.end()),i}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[g]=="number"&&this[ze](),!1;case"error":return this[Oe]?!1:(this[Oe]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},La=class extends $r{[pe](){let e=!0;try{this[Ge](null,D.openSync(this[U],"r")),e=!1}finally{e&&this[z]()}}[ze](){let e=!0;try{if(!this[te]){this[te]=!0;do{let t=this[wr](),i=t.length===0?0:D.readSync(this[g],t,0,t.length,null);if(!this[yr](i,t))break}while(!0);this[te]=!1}e=!1}finally{e&&this[z]()}}[z](){if(this[me]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,D.closeSync(e),this.emit("close")}}},vi=class extends wa{readable=!1;writable=!0;[Oe]=!1;[be]=!1;[nt]=!1;[G]=[];[qt]=!1;[U];[yt];[me];[g];[ai];[ie];[Yi]=!1;[he];constructor(e,t){t=t||{},super(t),this[U]=e,this[g]=typeof t.fd=="number"?t.fd:void 0,this[yt]=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[ai]=t.flags===void 0,this[ie]=t.flags===void 0?i:t.flags,this[g]===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[g]}get path(){return this[U]}[We](e){this[z](),this[be]=!0,this.emit("error",e)}[pe](){D.open(this[U],this[ie],this[yt],(e,t)=>this[Ge](e,t))}[Ge](e,t){this[ai]&&this[ie]==="r+"&&e&&e.code==="ENOENT"?(this[ie]="w",this[pe]()):e?this[We](e):(this[g]=t,this.emit("open",t),this[be]||this[qi]())}end(e,t){return e&&this.write(e,t),this[nt]=!0,!this[be]&&!this[G].length&&typeof this[g]=="number"&&this[Ue](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[nt]?(this.emit("error",new Error("write() after end()")),!1):this[g]===void 0||this[be]||this[G].length?(this[G].push(e),this[qt]=!0,!1):(this[be]=!0,this[oi](e),!0)}[oi](e){D.write(this[g],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[qi]():(this[be]=!1,this[nt]&&!this[Yi]?(this[Yi]=!0,this[z](),this.emit("finish")):this[qt]&&(this[qt]=!1,this.emit("drain"))))}[qi](){if(this[G].length===0)this[nt]&&this[Ue](null,0);else if(this[G].length===1)this[oi](this[G].pop());else{let e=this[G];this[G]=[],Da(this[g],e,this[he],(t,i)=>this[Ue](t,i))}}[z](){if(this[me]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,D.close(e,t=>t?this.emit("error",t):this.emit("close"))}}},Rn=class extends vi{[pe](){let e;if(this[ai]&&this[ie]==="r+")try{e=D.openSync(this[U],this[ie],this[yt])}catch(t){if(t?.code==="ENOENT")return this[ie]="w",this[pe]();throw t}else e=D.openSync(this[U],this[ie],this[yt]);this[Ge](null,e)}[z](){if(this[me]&&typeof this[g]=="number"){let e=this[g];this[g]=void 0,D.closeSync(e),this.emit("close")}}[oi](e){let t=!0;try{this[Ue](null,D.writeSync(this[g],e,0,e.length,this[he])),t=!1}finally{if(t)try{this[z]()}catch{}}}},Ca=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"]]),Na=e=>!!e.sync&&!!e.file,Ma=e=>!e.sync&&!!e.file,Fa=e=>!!e.sync&&!e.file,Ba=e=>!e.sync&&!e.file,$a=e=>!!e.file,Ua=e=>Ca.get(e)||e,Ur=(e={})=>{if(!e)return{};let t={};for(let[i,r]of Object.entries(e)){let s=Ua(i);t[s]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},Ot=(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=Ur(n);if(s?.(h,o),Na(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return e(h,o)}else if(Ma(h)){let l=t(h,o);return a?l.then(()=>a(),a):l}else if(Fa(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return i(h,o)}else if(Ba(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}),Ha=ja.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},Ha)),Wa=Te.concat,Ws=Object.getOwnPropertyDescriptor(Te,"concat"),Ga=e=>e,er=Ws?.writable===!0||Ws?.set!==void 0?e=>{Te.concat=e?Ga:Wa}: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"}},tr=Symbol("flushFlag"),zr=class extends De{#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 Hs[t]!="function")throw new TypeError("Compression method not supported: "+t);try{this.#t=new Hs[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 br(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),{[tr]: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;br(this.#t,"zlib binding closed");let r=this.#t._handle,s=r.close;r.close=()=>{};let n=this.#t.close;this.#t.close=()=>{},er(!0);let o;try{let h=typeof e[tr]=="number"?e[tr]:this.#r;o=this.#t._processChunk(e,h),er(!1)}catch(h){er(!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}},kn=class extends zr{#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),br(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)}}}},Za=class extends kn{#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)}},Ka=class extends kn{constructor(e){super(e,"Unzip")}},On=class extends zr{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)}},Va=class extends On{constructor(e){super(e,"BrotliCompress")}},Ya=class extends On{constructor(e){super(e,"BrotliDecompress")}},Tn=class extends zr{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)}},qa=class extends Tn{constructor(e){super(e,"ZstdCompress")}},Ja=class extends Tn{constructor(e){super(e,"ZstdDecompress")}},Xa=(e,t)=>{if(Number.isSafeInteger(e))e<0?eh(e,t):Qa(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},Qa=(e,t)=>{t[0]=128;for(var i=t.length;i>1;i--)t[i-1]=e&255,e=Math.floor(e/256)},eh=(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]=xn(s):s===0?t[r-1]=0:(i=!0,t[r-1]=Pn(s))}},th=e=>{let t=e[0],i=t===128?rh(e.subarray(1,e.length)):t===255?ih(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},ih=e=>{for(var t=e.length,i=0,r=!1,s=t-1;s>-1;s--){var n=Number(e[s]),o;r?o=xn(n):n===0?o=n:(r=!0,o=Pn(n)),o!==0&&(i-=o*Math.pow(256,t-s-1))}return i},rh=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},xn=e=>(255^e)&255,Pn=e=>(255^e)+1&255,sh={};ya(sh,{code:()=>jr,isCode:()=>hi,isName:()=>nh,name:()=>Ri,normalFsTypes:()=>Dn});var hi=e=>Ri.has(e),nh=e=>jr.has(e),Dn=new Set(["0","","1","2","3","4","5","6","7","D"]),Ri=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"]]),jr=new Map(Array.from(Ri).map(e=>[e[1],e[0]])),oh=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=Dn.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=oh(o?.size??a?.size??le(e,t+124,12)),this.mtime=o?.mtime??a?.mtime??ir(e,t+136,12),this.cksum=le(e,t+148,12),a&&this.#i(a,!0),o&&this.#i(o),hi(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??ir(e,t+476,12),this.ctime=i?.ctime??r?.ctime??ir(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=ah(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=rr(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=rr(e,t+476,12,this.atime)||this.needPax,this.needPax=rr(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:Ri.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(jr.get(e));if(hi(t)||t==="Unsupported")this.#e=t;else if(hi(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},ah=(e,t)=>{let i=e,r="",s,n=Ne.parse(e).root||".";if(Buffer.byteLength(i)<100)s=[i,r,!1];else{r=Ne.dirname(i),i=Ne.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=Ne.join(Ne.basename(r),i),r=Ne.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.*/,""),ir=(e,t,i)=>hh(le(e,t,i)),hh=e=>e===void 0?void 0:new Date(e*1e3),le=(e,t,i)=>Number(e[t])&128?th(e.subarray(t,t+i)):ch(e,t,i),lh=e=>isNaN(e)?void 0:e,ch=(e,t,i)=>lh(parseInt(e.subarray(t,t+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),dh={12:8589934591,8:2097151},ce=(e,t,i,r)=>r===void 0?!1:r>dh[i]||r<0?(Xa(r,e.subarray(t,t+i)),!0):(uh(e,t,i,r),!1),uh=(e,t,i,r)=>e.write(mh(r,i),t,i,"ascii"),mh=(e,t)=>ph(Math.floor(e).toString(8),t),ph=(e,t)=>(e.length===t-1?e:new Array(t-e.length-1).join("0")+e+" ")+"\0",rr=(e,t,i,r)=>r===void 0?!1:ce(e,t,i,r.getTime()/1e3),fh=new Array(156).join("\0"),Se=(e,t,i,r)=>r===void 0?!1:(e.write(r+fh,t,i,"utf8"),r.length!==Buffer.byteLength(r)||r.length>i),yi=class Ln{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/"+gh(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+`
|
|
88
|
+
`,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 Ln(yh(wh(t),i),r)}},yh=(e,t)=>t?Object.assign({},t,e):e,wh=e=>e.replace(/\n$/,"").split(`
|
|
89
|
+
`).reduce(bh,Object.create(null)),bh=(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,m=Eh!=="win32"?e=>String(e):e=>String(e).replaceAll(/\\/g,"/"),Sh=class extends De{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=m(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?m(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=m(e.path)),e.linkpath&&(e.linkpath=m(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="path"&&t))))}},_i=(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))},vh=1024*1024,Er=Buffer.from([31,139]),Sr=Buffer.from([40,181,47,253]),Rh=Math.max(Er.length,Sr.length),N=Symbol("state"),ve=Symbol("writeEntry"),Q=Symbol("readEntry"),sr=Symbol("nextEntry"),Gs=Symbol("processEntry"),Z=Symbol("extendedHeader"),at=Symbol("globalExtendedHeader"),ne=Symbol("meta"),Zs=Symbol("emitMeta"),w=Symbol("buffer"),ee=Symbol("queue"),oe=Symbol("ended"),nr=Symbol("emittedEnd"),Re=Symbol("emit"),E=Symbol("unzip"),Xt=Symbol("consumeChunk"),Qt=Symbol("consumeChunkSub"),or=Symbol("consumeBody"),Ks=Symbol("consumeMeta"),Vs=Symbol("consumeHeader"),ht=Symbol("consuming"),ar=Symbol("bufferConcat"),ei=Symbol("maybeEnd"),Me=Symbol("writing"),K=Symbol("aborted"),ti=Symbol("onDone"),_e=Symbol("sawValidEntry"),ii=Symbol("sawNullBlock"),ri=Symbol("sawEOF"),Ys=Symbol("closeStream"),_h=1e3,lt=Symbol("compressedBytesRead"),hr=Symbol("decompressedBytesRead"),qs=Symbol("checkDecompressionRatio"),kh=()=>!0,kt=class extends za{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[ee]=[];[w];[Q];[ve];[N]="begin";[ne]="";[Z];[at];[oe]=!1;[E];[K]=!1;[_e];[ii]=!1;[ri]=!1;[Me]=!1;[ht]=!1;[nr]=!1;[lt]=0;[hr]=0;constructor(e={}){super(),this.file=e.file||"",this.on(ti,()=>{(this[N]==="begin"||this[_e]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(ti,e.ondone):this.on(ti,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:_h,this.maxMetaEntrySize=e.maxMetaEntrySize||vh,this.filter=typeof e.filter=="function"?e.filter:kh;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[Ys]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,i={}){_i(this,e,t,i)}[Vs](e,t){this[_e]===void 0&&(this[_e]=!1);let i;try{i=new Pe(e,t,this[Z],this[at])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(i.nullBlock)this[ii]?(this[ri]=!0,this[N]==="begin"&&(this[N]="header"),this[Re]("eof")):(this[ii]=!0,this[Re]("nullBlock"));else if(this[ii]=!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 Sh(i,this[Z],this[at]);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[N]="ignore",s.resume()):s.size>0&&(this[ne]="",s.on("data",n=>this[ne]+=n),this[N]="meta"):(this[Z]=void 0,s.ignore=s.ignore||!this.filter(s.path,s),s.ignore?(this[Re]("ignoredEntry",s),this[N]=s.remain?"ignore":"header",s.resume()):(s.remain?this[N]="body":(this[N]="header",s.end()),this[Q]?this[ee].push(s):(this[ee].push(s),this[sr]())))}}}[Ys](){queueMicrotask(()=>this.emit("close"))}[Gs](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[sr]()),t=!1);return t}[sr](){do;while(this[Gs](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"))}}[or](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[N]="header",this[ve]=void 0,i.end()),s.length}[Ks](e,t){let i=this[ve],r=this[or](e,t);return!this[ve]&&i&&this[Zs](i),r}[Re](e,t,i){this[ee].length===0&&!this[Q]?this.emit(e,t,i):this[ee].push([e,t,i])}[Zs](e){switch(this[Re]("meta",this[ne]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[Z]=yi.parse(this[ne],this[Z],!1);break;case"GlobalExtendedHeader":this[at]=yi.parse(this[ne],this[at],!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[E]){let t=this[E];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})}}[qs](e){this[hr]+=e.length;let t=this[hr]/this[lt];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[E]===void 0||this.brotli===void 0&&this[E]===!1)&&e){if(this[w]&&(e=Buffer.concat([this[w],e]),this[w]=void 0),e.length<Rh)return this[w]=e,i?.(),!0;for(let o=0;this[E]===void 0&&o<Er.length;o++)e[o]!==Er[o]&&(this[E]=!1);let s=!1;if(this[E]===!1&&this.zstd!==!1){s=!0;for(let o=0;o<Sr.length;o++)if(e[o]!==Sr[o]){s=!1;break}}let n=this.brotli===void 0&&!s;if(this[E]===!1&&n)if(e.length<512)if(this[oe])this.brotli=!0;else return this[w]=e,i?.(),!0;else try{new Pe(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[E]===void 0||this[E]===!1&&(this.brotli||s)){let o=this[oe];this[oe]=!1,this[E]=this[E]===void 0?new Ka({}):s?new Ja({}):new Ya({}),this[E].on("data",h=>{this[qs](h)&&this[Xt](h)}),this[E].on("error",h=>{this[K]||this.abort(h)}),this[E].on("end",()=>{this[oe]=!0,this[Xt]()}),this[Me]=!0,this[lt]+=e.length;let a=!!this[E][o?"end":"write"](e);return this[Me]=!1,i?.(),a}}this[Me]=!0,this[E]?(this[lt]+=e.length,this[E].write(e)):this[Xt](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}[ar](e){e&&!this[K]&&(this[w]=this[w]?Buffer.concat([this[w],e]):e)}[ei](){if(this[oe]&&!this[nr]&&!this[K]&&!this[ht]){this[nr]=!0;let e=this[ve];if(e?.blockRemain){let t=this[w]?this[w].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[w]&&e.write(this[w]),e.end()}this[Re](ti)}}[Xt](e){if(this[ht]&&e)this[ar](e);else if(!e&&!this[w])this[ei]();else if(e){if(this[ht]=!0,this[w]){this[ar](e);let t=this[w];this[w]=void 0,this[Qt](t)}else this[Qt](e);for(;this[w]&&this[w]?.length>=512&&!this[K]&&!this[ri];){let t=this[w];this[w]=void 0,this[Qt](t)}this[ht]=!1}(!this[w]||this[oe])&&this[ei]()}[Qt](e){let t=0,i=e.length;for(;t+512<=i&&!this[K]&&!this[ri];)switch(this[N]){case"begin":case"header":this[Vs](e,t),t+=512;break;case"ignore":case"body":t+=this[or](e,t);break;case"meta":t+=this[Ks](e,t);break;default:throw new Error("invalid state: "+this[N])}t<i&&(this[w]=this[w]?Buffer.concat([e.subarray(t),this[w]]):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[E]?(e&&(this[lt]+=e.length,this[E].write(e)),this[E].end()):(this[oe]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[ei]())),this}},wt=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()},An=(e,t)=>{let i=new Map(t.map(o=>[wt(o),!0])),r=e.filter,s=100,n=(o,a="",h=0)=>{if(h>=s)return i.set(o,!1),!1;let l=a||Ia(o).root||".",c;if(o===l)c=!1;else{let d=i.get(o);c=d!==void 0?d:n(Aa(o),l,h+1)}return i.set(o,c),c};e.filter=r?(o,a)=>r(o,a)&&n(wt(o)):o=>n(wt(o))},Th=e=>{let t=new kt(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{}}},xh=(e,t)=>{let i=new kt(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 $r(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},ki=Ot(Th,xh,e=>new kt(e),e=>new kt(e),(e,t)=>{t?.length&&An(e,t),e.noResume||Oh(e)}),In=(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:Dh,parse:Xs}=Ph,Hr=e=>{let t="",i=Xs(e);for(;Dh(e)||i.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":i.root;e=e.slice(r.length),t+=r,i=Xs(e)}return[t,e]},Oi=["|","<",">","?",":"],Wr=Oi.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),Lh=new Map(Oi.map((e,t)=>[e,Wr[t]])),Ah=new Map(Wr.map((e,t)=>[e,Oi[t]])),Qs=e=>Oi.reduce((t,i)=>t.split(i).join(Lh.get(i)),e),Ih=e=>Wr.reduce((t,i)=>t.split(i).join(Ah.get(i)),e),Cn=(e,t)=>t?(e=m(e).replace(/^\.(\/|$)/,""),wt(t)+"/"+e):m(e),Ch=16*1024*1024,en=Symbol("process"),tn=Symbol("file"),rn=Symbol("directory"),vr=Symbol("symlink"),sn=Symbol("hardlink"),ct=Symbol("header"),li=Symbol("read"),Rr=Symbol("lstat"),ci=Symbol("onlstat"),_r=Symbol("onread"),kr=Symbol("onreadlink"),Or=Symbol("openfile"),Tr=Symbol("onopenfile"),de=Symbol("close"),bi=Symbol("mode"),xr=Symbol("awaitDrain"),lr=Symbol("ondrain"),Y=Symbol("prefix"),Nn=class extends De{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=Ur(t);super(),this.path=m(e),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||Ch,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=m(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?m(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]=Hr(this.path);n&&typeof o=="string"&&(this.path=o,r=n)}this.win32=!!i.win32||process.platform==="win32",this.win32&&(this.path=Ih(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=m(i.absolute||Js.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[ci](s):this[Rr]()}warn(e,t,i={}){return _i(this,e,t,i)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[Rr](){V.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[ci](t)})}[ci](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=Fh(e),this.emit("stat",e),this[en]()}[en](){switch(this.type){case"File":return this[tn]();case"Directory":return this[rn]();case"SymbolicLink":return this[vr]();default:return this.end()}}[bi](e){return In(e,this.type==="Directory",this.portable)}[Y](e){return Cn(e,this.prefix)}[ct](){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[bi](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 yi({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)}[rn](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ct](),this.end()}[vr](){V.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[kr](t)})}[kr](e){this.linkpath=m(e),this[ct](),this.end()}[sn](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=m(Js.relative(this.cwd,e)),this.stat.size=0,this[ct](),this.end()}[tn](){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[sn](t);this.linkCache.set(e,this.absolute)}if(this[ct](),this.stat.size===0)return this.end();this[Or]()}[Or](){V.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[Tr](t)})}[Tr](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[li]()}[li](){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[_r](o)})}[de](e=()=>{}){this.fd!==void 0&&V.close(this.fd,e)}[_r](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[lr]():this[xr](()=>this[lr]())}[xr](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)}[lr](){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[li]()}},Nh=class extends Nn{sync=!0;[Rr](){this[ci](V.lstatSync(this.absolute))}[vr](){this[kr](V.readlinkSync(this.absolute))}[Or](){this[Tr](V.openSync(this.absolute,"r"))}[li](){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[_r](o),e=!1}finally{if(e)try{this[de](()=>{})}catch{}}}[xr](e){e()}[de](e=()=>{}){this.fd!==void 0&&V.closeSync(this.fd),e()}},Mh=class extends De{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 _i(this,e,t,i)}constructor(e,t={}){let i=Ur(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=m(e.path),this.mode=e.mode!==void 0?this[bi](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?m(e.linkpath):void 0,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){let[o,a]=Hr(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 yi({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 Cn(e,this.prefix)}[bi](e){return In(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}},Fh=e=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",Bh=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++)Uh(this,t[i]);return this.length}unshift(...t){for(var i=0,r=t.length;i<r;i++)zh(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=$h(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 $h(e,t,i){let r=t,s=t?t.next:e.head,n=new Gr(i,r,s,e);return n.next===void 0&&(e.tail=n),n.prev===void 0&&(e.head=n),e.length++,n}function Uh(e,t){e.tail=new Gr(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function zh(e,t){e.head=new Gr(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Gr=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}},on=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||"./",this.absolute=t}},an=Buffer.alloc(1024),di=Symbol("onStat"),dt=Symbol("ended"),B=Symbol("queue"),ut=Symbol("pendingLinks"),ae=Symbol("current"),ke=Symbol("process"),mt=Symbol("processing"),si=Symbol("processJob"),$=Symbol("jobs"),cr=Symbol("jobDone"),ui=Symbol("addFSEntry"),hn=Symbol("addTarEntry"),Pr=Symbol("stat"),Dr=Symbol("readdir"),mi=Symbol("onreaddir"),pi=Symbol("pipe"),ln=Symbol("entry"),dr=Symbol("entryOpt"),fi=Symbol("writeEntryClass"),Mn=Symbol("write"),ur=Symbol("ondrain"),Ti=class extends De{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[fi];onWriteEntry;[B];[ut]=new Map;[$]=0;[mt]=!1;[dt]=!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=m(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[fi]=Nn,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 Za(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new Va(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new qa(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[ur]()),this.on("resume",()=>t.resume())}else this.on("drain",this[ur]);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[B]=new Bh,this[$]=0,this.jobs=Number(e.jobs)||4,this[mt]=!1,this[dt]=!1}[Mn](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[dt]=!0,this[ke](),i&&i(),this}write(e){if(this[dt])throw new Error("write after end");return typeof e=="string"?this[ui](e):this[hn](e),this.flowing}[hn](e){let t=m(nn.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let i=new on(e.path,t);i.entry=new Mh(e,this[dr](i)),i.entry.on("end",()=>this[cr](i)),this[$]+=1,this[B].push(i)}this[ke]()}[ui](e){let t=m(nn.resolve(this.cwd,e));this[B].push(new on(e,t)),this[ke]()}[Pr](e){e.pending=!0,this[$]+=1;let t=this.follow?"stat":"lstat";wi[t](e.absolute,(i,r)=>{e.pending=!1,this[$]-=1,i?this.emit("error",i):this[di](e,r)})}[di](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[si](e);else{let i=`${t.dev}:${t.ino}`,r=this[ut].get(i);r?r.push(e):this[ut].set(i,[e]),e.pendingLink=!0,e.pending=!0}this[ke]()}[Dr](e){e.pending=!0,this[$]+=1,wi.readdir(e.absolute,(t,i)=>{if(e.pending=!1,this[$]-=1,t)return this.emit("error",t);this[mi](e,i)})}[mi](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[ke]()}[ke](){if(!this[mt]){this[mt]=!0;for(let e=this[B].head;e&&this[$]<this.jobs;e=e.next)if(this[si](e.value),e.value.ignore){let t=e.next;this[B].removeNode(e),e.next=t}this[mt]=!1,this[dt]&&this[B].length===0&&this[$]===0&&(this.zip?this.zip.end(an):(super.write(an),super.end()))}}get[ae](){return this[B]&&this[B].head&&this[B].head.value}[cr](e){this[B].shift(),this[$]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let i=`${t.dev}:${t.ino}`,r=this[ut].get(i);if(r){this[ut].delete(i);for(let s of r)s.pending=!1,this[si](s)}}this[ke]()}[si](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[pi](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[di](e,t):this[Pr](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[mi](e,t):this[Dr](e),!e.readdir)return}if(e.entry=this[ln](e),!e.entry){e.ignore=!0;return}e===this[ae]&&!e.piped&&this[pi](e)}}}[dr](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}}[ln](e){this[$]+=1;try{return new this[fi](e.path,this[dr](e)).on("end",()=>this[cr](e)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[ur](){this[ae]&&this[ae].entry&&this[ae].entry.resume()}[pi](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ui](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={}){_i(this,e,t,i)}},Zr=class extends Ti{sync=!0;constructor(e){super(e),this[fi]=Nh}pause(){}resume(){}[Pr](e){let t=this.follow?"statSync":"lstatSync";this[di](e,wi[t](e.absolute))}[Dr](e){this[mi](e,wi.readdirSync(e.absolute))}[pi](e){let t=e.entry,i=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ui](n+r)}),!t)throw new Error("Cannot pipe without source");i?t.on("data",r=>{i.write(r)}):t.on("data",r=>{super[Mn](r)})}},jh=(e,t)=>{let i=new Zr(e),r=new Rn(e.file,{mode:e.mode||438});i.pipe(r),Fn(i,t)},Hh=(e,t)=>{let i=new Ti(e),r=new vi(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 Bn(i,t).catch(n=>i.emit("error",n)),s},Fn=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?ki({file:_n.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},Bn=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await ki({file:_n.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>{e.add(r)}}):e.add(i);e.end()},Wh=(e,t)=>{let i=new Zr(e);return Fn(i,t),i},Gh=(e,t)=>{let i=new Ti(e);return Bn(i,t).catch(r=>i.emit("error",r)),i},Id=Ot(jh,Hh,Wh,Gh,(e,t)=>{if(!t?.length)throw new TypeError("no paths specified to add to archive")}),Kh=process.env.__FAKE_PLATFORM__||process.platform,jn=Kh==="win32",{O_CREAT:Hn,O_NOFOLLOW:cn,O_TRUNC:Wn,O_WRONLY:Gn}=zn.constants,Zn=Number(process.env.__FAKE_FS_O_FILENAME__)||zn.constants.UV_FS_O_FILEMAP||0,Vh=jn&&!!Zn,Yh=512*1024,qh=Zn|Wn|Hn|Gn,dn=!jn&&typeof cn=="number"?cn|Wn|Hn|Gn:null,Kn=dn!==null?()=>dn:Vh?e=>e<Yh?qh:"w":()=>"w",Lr=(e,t,i)=>{try{return xi.lchownSync(e,t,i)}catch(r){if(r?.code!=="ENOENT")throw r}},Ei=(e,t,i,r)=>{xi.lchown(e,t,i,s=>{r(s&&s?.code!=="ENOENT"?s:null)})},Jh=(e,t,i,r,s)=>{if(t.isDirectory())Vn(bt.resolve(e,t.name),i,r,n=>{if(n)return s(n);let o=bt.resolve(e,t.name);Ei(o,i,r,s)});else{let n=bt.resolve(e,t.name);Ei(n,i,r,s)}},Vn=(e,t,i,r)=>{xi.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 Ei(e,t,i,r);let o=n.length,a=null,h=l=>{if(!a){if(l)return r(a=l);if(--o===0)return Ei(e,t,i,r)}};for(let l of n)Jh(e,l,t,i,h)})},Xh=(e,t,i,r)=>{t.isDirectory()&&Yn(bt.resolve(e,t.name),i,r),Lr(bt.resolve(e,t.name),i,r)},Yn=(e,t,i)=>{let r;try{r=xi.readdirSync(e,{withFileTypes:!0})}catch(s){let n=s;if(n?.code==="ENOENT")return;if(n?.code==="ENOTDIR"||n?.code==="ENOTSUP")return Lr(e,t,i);throw n}for(let s of r)Xh(e,s,t,i);return Lr(e,t,i)},qn=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"}},Pi=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"}},el=(e,t)=>{I.stat(e,(i,r)=>{(i||!r.isDirectory())&&(i=new qn(e,i?.code||"ENOTDIR")),t(i)})},tl=(e,t,i)=>{e=m(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=m(t.cwd),u=(y,b)=>{y?i(y):b&&h?Vn(b,o,a,P=>u(P)):n?I.chmod(e,s,i):i()};if(e===d)return el(e,u);if(l)return Qh.mkdir(e,{mode:s,recursive:!0}).then(y=>u(null,y??void 0),u);let f=m(Si.relative(d,e)).split("/");Ar(d,f,s,c,d,void 0,u)},Ar=(e,t,i,r,s,n,o)=>{if(t.length===0)return o(null,n);let a=t.shift(),h=m(Si.resolve(e+"/"+a));I.mkdir(h,i,Jn(h,t,i,r,s,n,o))},Jn=(e,t,i,r,s,n,o)=>a=>{a?I.lstat(e,(h,l)=>{if(h)h.path=h.path&&m(h.path),o(h);else if(l.isDirectory())Ar(e,t,i,r,s,n,o);else if(r)I.unlink(e,c=>{if(c)return o(c);I.mkdir(e,i,Jn(e,t,i,r,s,n,o))});else{if(l.isSymbolicLink())return o(new Pi(e,e+"/"+t.join("/")));o(a)}}):(n=n||e,Ar(e,t,i,r,s,n,o))},il=e=>{let t=!1,i;try{t=I.statSync(e).isDirectory()}catch(r){i=r?.code}finally{if(!t)throw new qn(e,i??"ENOTDIR")}},rl=(e,t)=>{e=m(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=m(t.cwd),d=y=>{y&&a&&Yn(y,n,o),s&&I.chmodSync(e,r)};if(e===c)return il(c),d();if(h)return d(I.mkdirSync(e,{mode:r,recursive:!0})??void 0);let u=m(Si.relative(c,e)).split("/"),f;for(let y=u.shift(),b=c;y&&(b+="/"+y);y=u.shift()){b=m(Si.resolve(b));try{I.mkdirSync(b,r),f=f||b}catch{let P=I.lstatSync(b);if(P.isDirectory())continue;if(l){I.unlinkSync(b),I.mkdirSync(b,r),f=f||b;continue}else if(P.isSymbolicLink())return new Pi(b,b+"/"+u.join("/"))}}return d(f)},mr=Object.create(null),un=1e4,Fe=new Set,sl=e=>{Fe.has(e)?Fe.delete(e):mr[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Fe.add(e);let t=mr[e],i=Fe.size-un;if(i>un/10){for(let r of Fe)if(Fe.delete(r),delete mr[r],--i<=0)break}return t},nl=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,ol=nl==="win32",al=e=>e.split("/").slice(0,-1).reduce((t,i)=>{let r=t.at(-1);return r!==void 0&&(i=Xn(r,i)),t.push(i||"/"),t},[]),hl=class{#e=new Map;#i=new Map;#r=new Set;reserve(e,t){e=ol?["win32 parallelization disabled"]:e.map(r=>wt(Xn(sl(r))));let i=new Set(e.map(r=>al(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}},ll=()=>process.umask(),mn=Symbol("onEntry"),Ir=Symbol("checkFs"),pn=Symbol("checkFs2"),Cr=Symbol("isReusable"),M=Symbol("makeFs"),Nr=Symbol("file"),Mr=Symbol("directory"),gi=Symbol("link"),fn=Symbol("symlink"),gn=Symbol("hardlink"),gt=Symbol("ensureNoSymlink"),yn=Symbol("unsupported"),wn=Symbol("checkPath"),pr=Symbol("stripAbsolutePath"),ue=Symbol("mkdir"),O=Symbol("onError"),ni=Symbol("pending"),bn=Symbol("pend"),Be=Symbol("unpend"),fr=Symbol("ended"),gr=Symbol("maybeClose"),Fr=Symbol("skip"),Et=Symbol("doChown"),St=Symbol("uid"),vt=Symbol("gid"),Rt=Symbol("checkedCwd"),cl=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,_t=cl==="win32",dl=1024,ul=(e,t)=>{if(!_t)return p.unlink(e,t);let i=e+".DELETE."+Un(16).toString("hex");p.rename(e,i,r=>{if(r)return t(r);p.unlink(i,t)})},ml=e=>{if(!_t)return p.unlinkSync(e);let t=e+".DELETE."+Un(16).toString("hex");p.renameSync(e,t),p.unlinkSync(t)},En=(e,t,i)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:i,Kr=class extends kt{[fr]=!1;[Rt]=!1;[ni]=0;reservations=new hl;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[fr]=!0,this[gr]()},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:dl,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||_t,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=m(v.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:ll():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[mn](t))}warn(e,t,i={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(i.recoverable=!1),super.warn(e,t,i)}[gr](){this[fr]&&this[ni]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[pr](e,t){let i=e[t],{type:r}=e;if(!i||this.preservePaths)return!0;let[s,n]=Hr(i),o=n.replaceAll(/\\/g,"/").split("/");if(o.includes("..")||_t&&/^[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}[wn](e){let t=m(e.path),i=t.split("/");if(this.strip){if(i.length<this.strip)return!1;if(e.type==="Link"){let r=m(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[pr](e,"path")||!this[pr](e,"linkpath"))return!1;if(e.absolute=v.isAbsolute(e.path)?m(v.resolve(e.path)):m(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:m(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+Qs(String(e.absolute).slice(r.length));let{root:s}=v.win32.parse(e.path);e.path=s+Qs(e.path.slice(s.length))}return!0}[mn](e){if(!this[wn](e))return e.resume();switch(Zh.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[Ir](e);default:return this[yn](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){tl(m(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)}[Et](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}[St](e){return En(this.uid,e.uid,this.processUid)}[vt](e){return En(this.gid,e.gid,this.processGid)}[Nr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new vi(String(e.absolute),{flags:Kn(e.size),mode:i,autoClose:!1});r.on("error",a=>{r.fd&&p.close(r.fd,()=>{}),r.write=()=>!0,this[O](a,e),t()});let s=1,n=a=>{if(a){r.fd&&p.close(r.fd,()=>{}),this[O](a,e),t();return}--s===0&&r.fd!==void 0&&p.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;p.futimes(h,l,c,d=>d?p.utimes(a,l,c,u=>n(u&&d)):n())}if(typeof h=="number"&&this[Et](e)){s++;let l=this[St](e),c=this[vt](e);typeof l=="number"&&typeof c=="number"&&p.fchown(h,l,c,d=>d?p.chown(a,l,c,u=>n(u&&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)}[Mr](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++,p.utimes(String(e.absolute),e.atime||new Date,e.mtime,n)),this[Et](e)&&(s++,p.chown(String(e.absolute),Number(this[St](e)),Number(this[vt](e)),n)),n()})}[yn](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[fn](e,t){let i=m(v.relative(this.cwd,v.resolve(v.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[gt](e,this.cwd,i,()=>this[gi](e,String(e.linkpath),"symlink",t),r=>{this[O](r,e),t()})}[gn](e,t){let i=m(v.resolve(this.cwd,String(e.linkpath))),r=m(String(e.linkpath)).split("/");this[gt](e,this.cwd,r,()=>this[gi](e,i,"link",t),s=>{this[O](s,e),t()})}[gt](e,t,i,r,s){let n=i.shift();if(this.preservePaths||n===void 0)return r();let o=v.resolve(t,n);p.lstat(o,(a,h)=>{if(a)return r();if(h?.isSymbolicLink())return s(new Pi(o,v.resolve(o,i.join("/"))));this[gt](e,o,i,r,s)})}[bn](){this[ni]++}[Be](){this[ni]--,this[gr]()}[Fr](e){this[Be](),e.resume()}[Cr](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!_t}[Ir](e){this[bn]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,i=>this[pn](e,i))}[pn](e,t){let i=o=>{t(o)},r=()=>{this[ue](this.cwd,this.dmode,o=>{if(o){this[O](o,e),i();return}this[Rt]=!0,s()})},s=()=>{if(e.absolute!==this.cwd){let o=m(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=()=>{p.lstat(String(e.absolute),(o,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[Fr](e),i();return}if(o||this[Cr](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?p.chmod(String(e.absolute),Number(e.mode),l):l()}if(e.absolute!==this.cwd)return p.rmdir(String(e.absolute),h=>this[M](h??null,e,i))}if(e.absolute===this.cwd)return this[M](null,e,i);ul(String(e.absolute),h=>this[M](h??null,e,i))})};this[Rt]?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[Nr](t,i);case"Link":return this[gn](t,i);case"SymbolicLink":return this[fn](t,i);case"Directory":case"GNUDumpDir":return this[Mr](t,i)}}[gi](e,t,i,r){p[i](t,String(e.absolute),s=>{s?this[O](s,e):(this[Be](),e.resume()),r()})}},pt=e=>{try{return[null,e()]}catch(t){return[t,null]}},Qn=class extends Kr{sync=!0;[M](e,t){return super[M](e,t,()=>{})}[Ir](e){if(!this[Rt]){let s=this[ue](this.cwd,this.dmode);if(s)return this[O](s,e);this[Rt]=!0}if(e.absolute!==this.cwd){let s=m(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]=pt(()=>p.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[Fr](e);if(t||this[Cr](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?pt(()=>{p.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[M](o,e)}let[s]=pt(()=>p.rmdirSync(String(e.absolute)));this[M](s,e)}let[r]=e.absolute===this.cwd?[]:pt(()=>ml(String(e.absolute)));this[M](r,e)}[Nr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=o=>{let a;try{p.closeSync(s)}catch(h){a=h}(o||a)&&this[O](o||a,e),t()},s;try{s=p.openSync(String(e.absolute),Kn(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{p.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{p.futimesSync(s,a,h)}catch(l){try{p.utimesSync(String(e.absolute),a,h)}catch{o=l}}}if(this[Et](e)){let a=this[St](e),h=this[vt](e);try{p.fchownSync(s,Number(a),Number(h))}catch(l){try{p.chownSync(String(e.absolute),Number(a),Number(h))}catch{o=o||l}}}r(o)})}[Mr](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{p.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[Et](e))try{p.chownSync(String(e.absolute),Number(this[St](e)),Number(this[vt](e)))}catch{}t(),e.resume()}[ue](e,t){try{return rl(m(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}}[gt](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]=pt(()=>p.lstatSync(n));if(a)return r();if(h.isSymbolicLink())return s(new Pi(n,v.resolve(t,i.join("/"))))}r()}[gi](e,t,i,r){let s=`${i}Sync`;try{p[s](t,String(e.absolute)),r(),e.resume()}catch(n){return this[O](n,e)}}},pl=e=>{let t=new Qn(e),i=e.file,r=$n.statSync(i),s=e.maxReadSize||16*1024*1024;new La(i,{readSize:s,size:r.size}).pipe(t)},fl=(e,t)=>{let i=new Kr(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("close",n),$n.stat(s,(a,h)=>{if(a)o(a);else{let l=new $r(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},eo=Ot(pl,fl,e=>new Qn(e),e=>new Kr(e),(e,t)=>{t?.length&&An(e,t)}),gl=(e,t)=>{let i=new Zr(e),r=!0,s,n;try{try{s=A.openSync(e.file,"r+")}catch(h){if(h?.code==="ENOENT")s=A.openSync(e.file,"w+");else throw h}let o=A.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=A.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,yl(e,i,n,s,t)}finally{if(r)try{A.closeSync(s)}catch{}}},yl=(e,t,i,r,s)=>{let n=new Rn(e.file,{fd:r,start:i});t.pipe(n),bl(t,s)},wl=(e,t)=>{t=Array.from(t);let i=new Ti(e),r=(s,n,o)=>{let a=(u,f)=>{u?A.close(s,y=>o(u)):o(null,f)},h=0;if(n===0)return a(null,0);let l=0,c=Buffer.alloc(512),d=(u,f)=>{if(u||f===void 0)return a(u);if(l+=f,l<512&&f)return A.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 y=new Pe(c);if(!y.cksumValid)return a(null,h);let b=512*Math.ceil((y.size??0)/512);if(h+b+512>n||(h+=b+512,h>=n))return a(null,h);e.mtimeCache&&y.mtime&&e.mtimeCache.set(String(y.path),y.mtime),l=0,A.read(s,c,0,512,h,d)};A.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+",A.open(e.file,o,a);if(h||!l)return n(h);A.fstat(l,(c,d)=>{if(c)return A.close(l,()=>n(c));r(l,d.size,(u,f)=>{if(u)return n(u);let y=new vi(e.file,{fd:l,start:f});i.pipe(y),y.on("error",n),y.on("close",s),El(i,t)})})};A.open(e.file,o,a)})},bl=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?ki({file:to.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 ki({file:to.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i);e.end()},ft=Ot(gl,wl,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(e,t)=>{if(!$a(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")}),Vd=Ot(ft.syncFile,ft.asyncFile,ft.syncNoFile,ft.asyncNoFile,(e,t=[])=>{ft.validate?.(e,t),Sl(e)}),Sl=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 Tt=Ie("taco.cli.upgrade"),Tl="https://registry.npmjs.org",ro=3e4;async function xl(e,t,i,r){let s=i==="latest"?`${e}/${t}/latest`:`${e}/${t}/${i}`,n=new AbortController,o=setTimeout(()=>n.abort(),ro);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 Pl(e,t,i){let r=new AbortController,s=setTimeout(()=>r.abort(),ro);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 Vr(io(t),{recursive:!0});let o=await _l(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 Dl(e,t){let[i,r]=t.split("-");if(i!=="sha512")throw new Error(`unsupported integrity algorithm: ${i}`);let s=vl("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 so(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??C,r=e.registry??Tl,s=e.platformKey?{key:e.platformKey,pkg:`@taco-ai/sidecar-${e.platformKey}`}:Yr(),n=e.version??"latest";Tt.info(`fetching metadata for ${s.pkg}@${n}`);let o=await xl(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=Di(i,"staging",`sidecar-${s.key}-${a}`),l=Di(i,"cache","sidecar",`sidecar-${s.key}-${a}.tgz`);Tt.info(`downloading tarball \u2192 ${l}`),await Vr(io(l),{recursive:!0}),await Pl(o.dist.tarball,l,t),Tt.info("verifying integrity"),await Dl(l,o.dist.integrity),await kl(h,{recursive:!0,force:!0}),await Vr(h,{recursive:!0}),Tt.info(`extracting \u2192 ${h}`),await eo({file:l,cwd:h,strip:1}),await Ll(h);let c=e.liveDirOverride??await Al(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()},u=Di(i,"upgrade-marker.json");return await Bi(u,d),Tt.info(`upgrade staged \u2192 version=${a}, marker=${u}`),{version:a,stagingDir:h,liveDir:c}}async function Ll(e){for(let t of["manifest.json","bin","lib"]){let i=Di(e,t);try{await Ol(i)}catch{throw new Error(`staged bundle missing ${t} at ${i}`)}}}async function Al(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 no=`taco \u2014 launcher + supervisor for the sidecar daemon
|
|
90
90
|
|
|
91
91
|
Usage:
|
|
92
92
|
taco start Spawn the daemon; prints its NDJSON socket path.
|
|
@@ -102,7 +102,7 @@ Environment:
|
|
|
102
102
|
TACO_HOME Root directory for daemon state (default ~/.taco).
|
|
103
103
|
TACO_SIDECAR_DEV=1 Force dev launcher (tsx + repo source) even when a
|
|
104
104
|
@taco-ai/sidecar-<platform> bundle is installed.
|
|
105
|
-
`;async function
|
|
105
|
+
`;async function Il(e){let t=e[2];switch(t){case"start":return await As(),0;case"status":return await Is(),0;case"stop":return await Ns(),0;case"install":return await ws(),0;case"uninstall":return await Bs(),0;case"upgrade":return e.includes("--apply")?await Ht():await so(),0;case"help":case"--help":case"-h":case void 0:return process.stdout.write(no),0;default:return process.stderr.write(`unknown subcommand: ${t}
|
|
106
106
|
|
|
107
|
-
${
|
|
108
|
-
`),process.exit(1)});export{
|
|
107
|
+
${no}`),1}}var Cl=(()=>{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}})();Cl&&Il(process.argv).then(e=>process.exit(e??0),e=>{let t=e instanceof Qe?e.message:e?.stack??e;process.stderr.write(`[taco] error: ${t}
|
|
108
|
+
`),process.exit(1)});export{Il as run};
|
package/lib/installId.ts
CHANGED
|
@@ -1,100 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* pkg ships at runtime, not the TS source), so we duplicate the algorithm.
|
|
5
|
-
* Both sides MUST stay byte-for-byte identical — any drift means the
|
|
6
|
-
* desktop reap path will skip a daemon it owns (or kill one it doesn't).
|
|
7
|
-
* The unit test in `tests/installId.test.ts` enforces identical output
|
|
8
|
-
* against a fixed corpus of inputs.
|
|
1
|
+
/**
|
|
2
|
+
* Re-exported from `@taco-ai/shared/daemonPaths` so CLI and sidecar share a
|
|
3
|
+
* single byte-for-byte identical implementation.
|
|
9
4
|
*/
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
5
|
|
|
12
|
-
export
|
|
13
|
-
const h = createHash("sha256");
|
|
14
|
-
h.update(resourcesRoot);
|
|
15
|
-
h.update("\0");
|
|
16
|
-
h.update(tacoHome);
|
|
17
|
-
return h.digest("hex").slice(0, 16);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Parse the contents of $TACO_HOME/run/sidecar.pid.
|
|
21
|
-
*
|
|
22
|
-
* Two on-disk formats are accepted:
|
|
23
|
-
* - **JSON record** (current, written by the daemon post-PR-A): a JSON
|
|
24
|
-
* object with `{version, pid, install_id, started_at}`. The version
|
|
25
|
-
* field exists so future schema changes can fail loudly rather than
|
|
26
|
-
* silently misparse old files.
|
|
27
|
-
* - **Legacy bare-int** (pre-PR-A): a single decimal pid string. Kept
|
|
28
|
-
* readable so a desktop upgrade doesn't strand an already-running
|
|
29
|
-
* daemon's pid file — the next reap on the new code will overwrite
|
|
30
|
-
* it once a fresh daemon starts.
|
|
31
|
-
*
|
|
32
|
-
* Returns null when the file is absent, unparseable, or yields a
|
|
33
|
-
* non-finite pid. Callers must treat null as "no claim to ownership" and
|
|
34
|
-
* not signal/kill anything. */
|
|
35
|
-
export interface ParsedPidFile {
|
|
36
|
-
pid: number;
|
|
37
|
-
installId: string | null;
|
|
38
|
-
startedAt: string | null;
|
|
39
|
-
/** Schema version, when the on-disk format is JSON. null for legacy. */
|
|
40
|
-
version: number | null;
|
|
41
|
-
/** `sidecar_version` from the JSON record; null for legacy files and for
|
|
42
|
-
* records written by daemons that predate the field. */
|
|
43
|
-
sidecarVersion: string | null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function parsePidFile(contents: string): ParsedPidFile | null {
|
|
47
|
-
const trimmed = contents.trim();
|
|
48
|
-
if (trimmed.length === 0) return null;
|
|
49
|
-
|
|
50
|
-
// Try JSON first. The version field is the discriminator: a bare-int
|
|
51
|
-
// pid (e.g. "12345\n") is the legacy format; anything starting with
|
|
52
|
-
// "{" is the new JSON record. JSON.parse of a bare int would throw,
|
|
53
|
-
// so a try/catch is cheap insurance against ambiguous input.
|
|
54
|
-
if (trimmed.startsWith("{")) {
|
|
55
|
-
try {
|
|
56
|
-
const parsed = JSON.parse(trimmed) as Record<string, unknown>;
|
|
57
|
-
if (parsed.version !== 1) {
|
|
58
|
-
// Unknown schema — caller can choose to log + unlink rather
|
|
59
|
-
// than act on a record whose shape we don't recognise.
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
const pid = typeof parsed.pid === "number" ? parsed.pid : Number.NaN;
|
|
63
|
-
const installId = typeof parsed.install_id === "string" ? parsed.install_id : null;
|
|
64
|
-
const startedAt = typeof parsed.started_at === "string" ? parsed.started_at : null;
|
|
65
|
-
const sidecarVersion =
|
|
66
|
-
typeof parsed.sidecar_version === "string" ? parsed.sidecar_version : null;
|
|
67
|
-
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
68
|
-
return { pid, installId, startedAt, version: 1, sidecarVersion };
|
|
69
|
-
} catch {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Legacy fallback. Some pid files may have whitespace or a trailing
|
|
75
|
-
// newline — trim already handled that. parseInt is permissive so we
|
|
76
|
-
// sanity-check with isFinite + positive.
|
|
77
|
-
const pid = Number.parseInt(trimmed, 10);
|
|
78
|
-
if (!Number.isFinite(pid) || pid <= 0) return null;
|
|
79
|
-
return { pid, installId: null, startedAt: null, version: null, sidecarVersion: null };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Decide whether a serving daemon should be reaped for running stale code.
|
|
83
|
-
*
|
|
84
|
-
* Ownership comes first: a record whose install_id names a DIFFERENT
|
|
85
|
-
* install is never ours to kill (sibling installs share $TACO_HOME by
|
|
86
|
-
* design), and an absent/unparseable record gives no ownership claim at
|
|
87
|
-
* all — killing on that basis could hit a daemon we don't own. Only when
|
|
88
|
-
* the record is ours (install_id match, or legacy bare-int which only our
|
|
89
|
-
* predecessors could have written) does the version comparison apply, and
|
|
90
|
-
* a missing sidecar_version counts as stale: pre-field daemons are older
|
|
91
|
-
* than any launcher that knows to compare. */
|
|
92
|
-
export function pidRecordIsStale(
|
|
93
|
-
parsed: ParsedPidFile | null,
|
|
94
|
-
ownInstallId: string,
|
|
95
|
-
expectedVersion: string,
|
|
96
|
-
): boolean {
|
|
97
|
-
if (parsed === null) return false;
|
|
98
|
-
if (parsed.installId !== null && parsed.installId !== ownInstallId) return false;
|
|
99
|
-
return parsed.sidecarVersion !== expectedVersion;
|
|
100
|
-
}
|
|
6
|
+
export { computeInstallId, parsePidFile, pidRecordIsStale } from "@taco-ai/shared/daemonPaths";
|
package/lib/installSchtasks.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* still tears the tree down. macOS launchd is a separate file and is not
|
|
15
15
|
* involved here. */
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { writeFileSync } from "node:fs";
|
|
18
18
|
import { join } from "node:path";
|
|
19
19
|
import type { InstallResult } from "./install.ts";
|
|
20
20
|
import { execFile, type PlatformPkgPaths } from "./installHelpers.ts";
|
|
@@ -27,13 +27,6 @@ export function windowsWrapperPath(tacoHome: string): string {
|
|
|
27
27
|
return join(tacoHome, "bin", "taco-sidecar-daemon.vbs");
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/** Pre-vbs wrapper left behind by older installs. Inert once the task
|
|
31
|
-
* points at the .vbs; removed on re-install so operators don't keep two
|
|
32
|
-
* launchers around. */
|
|
33
|
-
export function legacyWindowsCmdPath(tacoHome: string): string {
|
|
34
|
-
return join(tacoHome, "bin", "taco-sidecar-daemon.cmd");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
30
|
/** Escape a string for embedding inside a VBScript `"..."` literal.
|
|
38
31
|
* The only metacharacter VBS strings have is `"` itself (doubled). `&`
|
|
39
32
|
* is concatenation only outside quotes, so paths like `C:\R&D` pass
|
|
@@ -150,17 +143,6 @@ export async function installSchtasks(input: InstallSchtasksInput): Promise<Inst
|
|
|
150
143
|
|
|
151
144
|
await execFile("schtasks", schtasksCreateArgs(wrapperPath));
|
|
152
145
|
|
|
153
|
-
// Drop the pre-vbs .cmd only after /Create succeeds. Doing it first
|
|
154
|
-
// would leave a failed install pointing at a missing launcher (the
|
|
155
|
-
// old ONLOGON task still targets taco-sidecar-daemon.cmd). Once the
|
|
156
|
-
// task is retargeted at the .vbs the leftover is inert.
|
|
157
|
-
const legacyCmd = legacyWindowsCmdPath(input.tacoHome);
|
|
158
|
-
try {
|
|
159
|
-
if (existsSync(legacyCmd)) unlinkSync(legacyCmd);
|
|
160
|
-
} catch {
|
|
161
|
-
// Best-effort: the .cmd is unused once the task points at the .vbs.
|
|
162
|
-
}
|
|
163
|
-
|
|
164
146
|
// Kick the task immediately so the user doesn't have to sign out + in
|
|
165
147
|
// to see the install take effect. `/Run` returns once the task is
|
|
166
148
|
// dispatched, not when the daemon is ready — the desktop handles
|
package/lib/paths.ts
CHANGED
|
@@ -1,41 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Path constants for taco CLI / daemon layout under $TACO_HOME.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* bin/ # launcher wrapper scripts (taco-sidecar-daemon[.vbs])
|
|
8
|
-
* logs/ # service stdout/stderr targets
|
|
9
|
-
* staging/ # upgrade staging area
|
|
10
|
-
* jobs/ # scheduler job definitions
|
|
11
|
-
* taco.json # user config
|
|
12
|
-
* desktop.json # desktop-only config (sidecar reads via $TACO_HOME)
|
|
13
|
-
*
|
|
14
|
-
* $TACO_HOME resolution matches the sidecar's `tacoHome()` helper so CLI and
|
|
15
|
-
* sidecar agree on the root:
|
|
16
|
-
* 1. $TACO_HOME env (absolute, non-empty)
|
|
17
|
-
* 2. $HOME/.taco
|
|
4
|
+
* Core path & Windows pipe slug algorithms live in `@taco-ai/shared/daemonPaths`
|
|
5
|
+
* so CLI and sidecar never drift. This module binds the process-start defaults
|
|
6
|
+
* (`TACO_HOME`, `UPGRADE_MARKER`) and exposes `ensureDirs` for `taco install`.
|
|
18
7
|
*/
|
|
19
8
|
|
|
20
|
-
import { createHash } from "node:crypto";
|
|
21
9
|
import { mkdir } from "node:fs/promises";
|
|
22
|
-
import { homedir } from "node:os";
|
|
23
10
|
import { join } from "node:path";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
11
|
+
import {
|
|
12
|
+
resolveTacoHome,
|
|
13
|
+
controlSocketPath as sharedControlSocketPath,
|
|
14
|
+
defaultRuntimeDir as sharedDefaultRuntimeDir,
|
|
15
|
+
ndjsonSocketPath as sharedNdjsonSocketPath,
|
|
16
|
+
resolveTacoRuntimeDir as sharedResolveTacoRuntimeDir,
|
|
17
|
+
runtimePidFile as sharedRuntimePidFile,
|
|
18
|
+
windowsPipeSlug,
|
|
19
|
+
} from "@taco-ai/shared/daemonPaths";
|
|
33
20
|
|
|
34
21
|
export const TACO_HOME = resolveTacoHome();
|
|
35
22
|
|
|
36
23
|
/** Default daemon runtime directory for a user-data home. */
|
|
37
24
|
export function defaultRuntimeDir(home: string = TACO_HOME): string {
|
|
38
|
-
return
|
|
25
|
+
return sharedDefaultRuntimeDir(home);
|
|
39
26
|
}
|
|
40
27
|
|
|
41
28
|
/** Resolve daemon runtime state independently from the shared user-data home. */
|
|
@@ -43,59 +30,33 @@ export function resolveTacoRuntimeDir(
|
|
|
43
30
|
home: string = TACO_HOME,
|
|
44
31
|
runtimeOverride: string | undefined = process.env.TACO_RUNTIME_DIR,
|
|
45
32
|
): string {
|
|
46
|
-
|
|
47
|
-
return raw && raw.length > 0 ? raw : defaultRuntimeDir(home);
|
|
33
|
+
return sharedResolveTacoRuntimeDir(home, runtimeOverride);
|
|
48
34
|
}
|
|
49
35
|
|
|
50
36
|
/** Current process daemon runtime directory. */
|
|
51
37
|
const RUNTIME_DIR = resolveTacoRuntimeDir();
|
|
52
38
|
|
|
53
|
-
|
|
54
|
-
* to the same pipe slug. Slash direction, a trailing separator, and the
|
|
55
|
-
* `\\?\` prefix must not produce a second daemon for the same directory.
|
|
56
|
-
* The step order and the ASCII-only case fold must match the Rust twin
|
|
57
|
-
* (`paths.rs::windows_pipe_slug`) byte for byte — the desktop connects to the
|
|
58
|
-
* pipe this slug names, so `toLowerCase()`'s Unicode folding would split
|
|
59
|
-
* `C:\Users\Ü…` into two different pipes. */
|
|
60
|
-
export function windowsPipeSlug(runtimeDir: string): string {
|
|
61
|
-
let normalized = runtimeDir.replace(/\//g, "\\");
|
|
62
|
-
if (normalized.startsWith("\\\\?\\")) normalized = normalized.slice(4);
|
|
63
|
-
normalized = normalized.replace(/\\+$/, "").replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
64
|
-
return createHash("sha256").update(normalized, "utf8").digest("hex").slice(0, 16);
|
|
65
|
-
}
|
|
39
|
+
export { windowsPipeSlug };
|
|
66
40
|
|
|
67
|
-
/** NDJSON socket path
|
|
68
|
-
* Windows: named pipe derived from the runtime directory so debug
|
|
69
|
-
* (`~/.taco-dev/run`) and release (`~/.taco/run`) do not collide on the
|
|
70
|
-
* previously-global `\\.\pipe\taco-sidecar`. */
|
|
41
|
+
/** NDJSON socket path (Unix domain socket or Windows named pipe). */
|
|
71
42
|
export function ndjsonSocketPath(runtimeDir: string = RUNTIME_DIR): string {
|
|
72
|
-
|
|
73
|
-
return `\\\\.\\pipe\\taco-sidecar-${windowsPipeSlug(runtimeDir)}`;
|
|
74
|
-
}
|
|
75
|
-
return join(runtimeDir, "sidecar.sock");
|
|
43
|
+
return sharedNdjsonSocketPath(runtimeDir);
|
|
76
44
|
}
|
|
77
45
|
|
|
78
|
-
/** Control socket path
|
|
46
|
+
/** Control socket path (Unix domain socket or Windows named pipe). */
|
|
79
47
|
export function controlSocketPath(runtimeDir: string = RUNTIME_DIR): string {
|
|
80
|
-
|
|
81
|
-
return `\\\\.\\pipe\\taco-sidecar-ctl-${windowsPipeSlug(runtimeDir)}`;
|
|
82
|
-
}
|
|
83
|
-
return join(runtimeDir, "sidecar-ctl.sock");
|
|
48
|
+
return sharedControlSocketPath(runtimeDir);
|
|
84
49
|
}
|
|
85
50
|
|
|
86
|
-
/** Daemon pid file
|
|
51
|
+
/** Daemon pid file path inside the runtime directory. */
|
|
87
52
|
export function runtimePidFile(runtimeDir: string = RUNTIME_DIR): string {
|
|
88
|
-
return
|
|
53
|
+
return sharedRuntimePidFile(runtimeDir);
|
|
89
54
|
}
|
|
90
55
|
|
|
91
56
|
/** Upgrade marker file. */
|
|
92
57
|
export const UPGRADE_MARKER = join(TACO_HOME, "upgrade-marker.json");
|
|
93
58
|
|
|
94
|
-
/** Create the directory tree under $TACO_HOME that `taco install` + later PRs rely on.
|
|
95
|
-
* Idempotent (recursive mkdir). Modes are 0o755 so launchd / schtasks can read
|
|
96
|
-
* the wrapper script but a multi-user system doesn't accidentally inherit
|
|
97
|
-
* world-writable state. The helper takes an explicit `home` so callers can
|
|
98
|
-
* override $TACO_HOME for tests / dry-run scenarios. */
|
|
59
|
+
/** Create the directory tree under $TACO_HOME that `taco install` + later PRs rely on. */
|
|
99
60
|
export async function ensureDirs(
|
|
100
61
|
home: string = TACO_HOME,
|
|
101
62
|
runtimeDir: string = resolveTacoRuntimeDir(home),
|
package/lib/start.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { createRequire } from "node:module";
|
|
|
19
19
|
import { connect, type Socket } from "node:net";
|
|
20
20
|
import * as path from "node:path";
|
|
21
21
|
import { join } from "node:path";
|
|
22
|
+
import { isPidAlive } from "@taco-ai/shared/daemonPaths";
|
|
22
23
|
import { findPlatformPkg } from "./installHelpers.ts";
|
|
23
24
|
import { computeInstallId, parsePidFile, pidRecordIsStale } from "./installId.ts";
|
|
24
25
|
import {
|
|
@@ -128,15 +129,6 @@ function probeDaemonInitialize(path: string, timeoutMs = 5_000): Promise<DaemonP
|
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
function pidAlive(pid: number): boolean {
|
|
132
|
-
try {
|
|
133
|
-
process.kill(pid, 0);
|
|
134
|
-
return true;
|
|
135
|
-
} catch (err) {
|
|
136
|
-
return (err as NodeJS.ErrnoException)?.code === "EPERM";
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
132
|
/** Reap a daemon that accepts connections but won't serve them.
|
|
141
133
|
*
|
|
142
134
|
* Order matters:
|
|
@@ -179,10 +171,10 @@ async function killWedgedDaemon(
|
|
|
179
171
|
/* already dead */
|
|
180
172
|
}
|
|
181
173
|
const deadline = Date.now() + KILL_GRACE_MS;
|
|
182
|
-
while (Date.now() < deadline &&
|
|
174
|
+
while (Date.now() < deadline && isPidAlive(pid)) {
|
|
183
175
|
await new Promise((r) => setTimeout(r, 100));
|
|
184
176
|
}
|
|
185
|
-
if (
|
|
177
|
+
if (isPidAlive(pid)) {
|
|
186
178
|
try {
|
|
187
179
|
process.kill(pid, "SIGKILL");
|
|
188
180
|
} catch {
|
|
@@ -225,7 +217,7 @@ function assertDaemonOwned(runtimeDir: string, ownInstallId: string): void {
|
|
|
225
217
|
if (parsed === null || parsed.installId === null || parsed.installId === ownInstallId) {
|
|
226
218
|
return;
|
|
227
219
|
}
|
|
228
|
-
if (!
|
|
220
|
+
if (!isPidAlive(parsed.pid)) return;
|
|
229
221
|
throw new ForeignDaemonError(parsed.pid, parsed.installId, ownInstallId);
|
|
230
222
|
}
|
|
231
223
|
|
package/lib/upgradeMarker.ts
CHANGED
|
@@ -1,69 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CLI-side upgrade-marker helpers
|
|
3
|
-
*
|
|
4
|
-
* Mirrors the on-disk shape that the sidecar's `upgrader/marker.ts` reads.
|
|
5
|
-
* We intentionally duplicate the tiny read/write/clear surface here rather
|
|
6
|
-
* than importing from `@taco-ai/sidecar` — the CLI doesn't depend on the
|
|
7
|
-
* sidecar's TS source (the bundled platform pkg is what ships at runtime),
|
|
8
|
-
* and the public exports of `@taco-ai/sidecar` are the runtime entry, not
|
|
9
|
-
* the marker module. The duplication is bounded: the type + 3 functions,
|
|
10
|
-
* covered by `upgradeMarker.test.ts` so on-disk drift surfaces immediately.
|
|
11
|
-
*
|
|
12
|
-
* Tolerant read: a missing file (the common case after `upgrade --apply`)
|
|
13
|
-
* returns null; a malformed file logs + returns null rather than throwing,
|
|
14
|
-
* so the operator-visible error stays with whoever wrote the bad marker.
|
|
2
|
+
* CLI-side upgrade-marker helpers backed by `@taco-ai/shared/daemonPaths`,
|
|
3
|
+
* attaching the CLI upgrade logger for tolerant-read warnings.
|
|
15
4
|
*/
|
|
16
5
|
|
|
17
|
-
import {
|
|
18
|
-
|
|
6
|
+
import {
|
|
7
|
+
clearUpgradeMarker,
|
|
8
|
+
readUpgradeMarker as readSharedUpgradeMarker,
|
|
9
|
+
sameInstallPath,
|
|
10
|
+
writeUpgradeMarker,
|
|
11
|
+
} from "@taco-ai/shared/daemonPaths";
|
|
19
12
|
import { createLogger } from "./upgradeLogger.ts";
|
|
20
13
|
import type { UpgradeMarker } from "./upgradeTypes.ts";
|
|
21
14
|
|
|
22
15
|
const log = createLogger("taco.cli.upgrade.marker");
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
export { clearUpgradeMarker, writeUpgradeMarker };
|
|
25
18
|
|
|
26
|
-
/** True when the marker's live_dir is this CLI's own install root.
|
|
27
|
-
* installations can share one $TACO_HOME (npm sidecar + desktop-bundled
|
|
28
|
-
* sidecar) but only one marker exists, so ownership must be checked before
|
|
29
|
-
* applying. resolve() normalizes separators/trailing slashes; Windows
|
|
30
|
-
* compares case-insensitively (NTFS). */
|
|
19
|
+
/** True when the marker's live_dir is this CLI's own install root. */
|
|
31
20
|
export function markerTargetsInstall(
|
|
32
21
|
marker: UpgradeMarker,
|
|
33
22
|
ownRoot: string | null | undefined,
|
|
34
23
|
): boolean {
|
|
35
24
|
if (!ownRoot) return false;
|
|
36
|
-
|
|
37
|
-
const nb = resolve(ownRoot);
|
|
38
|
-
return process.platform === "win32" ? na.toLowerCase() === nb.toLowerCase() : na === nb;
|
|
25
|
+
return sameInstallPath(marker.live_dir, ownRoot);
|
|
39
26
|
}
|
|
40
27
|
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
raw = await readFile(filePath, "utf8");
|
|
45
|
-
} catch (err) {
|
|
46
|
-
if ((err as NodeJS.ErrnoException).code === "ENOENT") return null;
|
|
47
|
-
log.warn(`failed to read marker ${filePath}: ${String(err)}`);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(raw) as UpgradeMarker;
|
|
52
|
-
} catch (err) {
|
|
53
|
-
log.warn(`malformed marker ${filePath}: ${String(err)}`);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function writeUpgradeMarker(filePath: string, marker: UpgradeMarker): Promise<void> {
|
|
59
|
-
await mkdir(dirname(filePath), { recursive: true });
|
|
60
|
-
const tmp = `${filePath}.tmp`;
|
|
61
|
-
await writeFile(tmp, JSON.stringify(marker, null, JSON_INDENT), "utf8");
|
|
62
|
-
await rename(tmp, filePath);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export async function clearUpgradeMarker(filePath: string): Promise<void> {
|
|
66
|
-
await unlink(filePath).catch((err: NodeJS.ErrnoException) => {
|
|
67
|
-
if (err.code !== "ENOENT") throw err;
|
|
68
|
-
});
|
|
28
|
+
export function readUpgradeMarker(filePath: string): Promise<UpgradeMarker | null> {
|
|
29
|
+
return readSharedUpgradeMarker(filePath, (msg) => log.warn(msg));
|
|
69
30
|
}
|
package/lib/upgradeTypes.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared types for the upgrade flow.
|
|
3
|
-
*
|
|
4
|
-
* the marker is the contract between the two packages.
|
|
2
|
+
* Shared types for the upgrade flow. `UpgradeMarker` is defined in
|
|
3
|
+
* `@taco-ai/shared/daemonPaths` so CLI and sidecar share the on-disk contract.
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
/** Target version (e.g. "0.2.0"). Surfaces in the UI's "daemon upgrading" notice. */
|
|
9
|
-
version: string;
|
|
10
|
-
/** Absolute path to the staging dir holding the new bundle contents. */
|
|
11
|
-
staging_dir: string;
|
|
12
|
-
/** Absolute path to the live dir the staging should replace. */
|
|
13
|
-
live_dir: string;
|
|
14
|
-
/** Wall-clock ISO when the marker was written; used for diagnostics only. */
|
|
15
|
-
written_at: string;
|
|
16
|
-
}
|
|
6
|
+
export type { UpgradeMarker } from "@taco-ai/shared/daemonPaths";
|
|
17
7
|
|
|
18
8
|
export interface PackageMetadata {
|
|
19
9
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taco-ai/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
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.23",
|
|
25
|
-
"@taco-ai/shared": "0.4.
|
|
26
|
-
"@taco-ai/sidecar": "0.4.
|
|
25
|
+
"@taco-ai/shared": "0.4.8",
|
|
26
|
+
"@taco-ai/sidecar": "0.4.8"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.7.0",
|