just-bash 2.12.1 → 2.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-2FFXXW3F.js +14 -0
- package/dist/bin/chunks/chunk-435ZOZCY.js +63 -0
- package/dist/bin/chunks/chunk-4FNW6LFM.js +5 -0
- package/dist/bin/chunks/chunk-4PZYIYYG.js +36 -0
- package/dist/bin/chunks/{chunk-JWVOLGWZ.js → chunk-DREQRXNN.js} +1 -1
- package/dist/bin/chunks/chunk-IYZRLSTQ.js +2 -0
- package/dist/bin/chunks/chunk-JJHAWOIB.js +2 -0
- package/dist/bin/chunks/{chunk-F37UEO7A.js → chunk-JNPUO56K.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-DAGNL3F2.js → chunks/chunk-MZKPWGID.js} +24 -24
- package/dist/bin/chunks/{chunk-45MJQ2LX.js → chunk-OKL2SPHK.js} +32 -32
- package/dist/bin/chunks/{expansion-QVHAYGVZ.js → expansion-TCB3WZP5.js} +1 -1
- package/dist/bin/chunks/{flag-coverage-F4EAJUHL.js → flag-coverage-LQ37DA4R.js} +1 -1
- package/dist/bin/{shell/chunks/gzip-EENEW6WQ.js → chunks/gzip-RQ5RIFJV.js} +1 -1
- package/dist/bin/chunks/python3-74B25WCY.js +17 -0
- package/dist/bin/{shell/chunks/sleep-RA6DYTJX.js → chunks/sleep-GUJH2AMQ.js} +1 -1
- package/dist/bin/chunks/sqlite3-57UI7HYL.js +2 -0
- package/dist/bin/{shell/chunks/tar-GP2CCB47.js → chunks/tar-VIYVHMER.js} +1 -1
- package/dist/bin/chunks/time-FAWHHOMA.js +2 -0
- package/dist/bin/chunks/timeout-4O4YYRTS.js +2 -0
- package/dist/bin/chunks/worker.js +154 -4
- package/dist/bin/just-bash.js +255 -255
- package/dist/bin/shell/chunks/chunk-2FFXXW3F.js +14 -0
- package/dist/bin/shell/chunks/chunk-435ZOZCY.js +63 -0
- package/dist/bin/shell/chunks/chunk-4FNW6LFM.js +5 -0
- package/dist/bin/shell/chunks/chunk-4PZYIYYG.js +36 -0
- package/dist/bin/shell/chunks/{chunk-JWVOLGWZ.js → chunk-DREQRXNN.js} +1 -1
- package/dist/bin/shell/chunks/chunk-IYZRLSTQ.js +2 -0
- package/dist/bin/shell/chunks/chunk-JJHAWOIB.js +2 -0
- package/dist/bin/shell/chunks/{chunk-F37UEO7A.js → chunk-JNPUO56K.js} +1 -1
- package/dist/bin/{chunks/chunk-DAGNL3F2.js → shell/chunks/chunk-MZKPWGID.js} +24 -24
- package/dist/bin/shell/chunks/{chunk-45MJQ2LX.js → chunk-OKL2SPHK.js} +32 -32
- package/dist/bin/shell/chunks/{expansion-QVHAYGVZ.js → expansion-TCB3WZP5.js} +1 -1
- package/dist/bin/shell/chunks/{flag-coverage-F4EAJUHL.js → flag-coverage-LQ37DA4R.js} +1 -1
- package/dist/bin/{chunks/gzip-EENEW6WQ.js → shell/chunks/gzip-RQ5RIFJV.js} +1 -1
- package/dist/bin/shell/chunks/python3-74B25WCY.js +17 -0
- package/dist/bin/{chunks/sleep-RA6DYTJX.js → shell/chunks/sleep-GUJH2AMQ.js} +1 -1
- package/dist/bin/shell/chunks/sqlite3-57UI7HYL.js +2 -0
- package/dist/bin/{chunks/tar-GP2CCB47.js → shell/chunks/tar-VIYVHMER.js} +1 -1
- package/dist/bin/shell/chunks/time-FAWHHOMA.js +2 -0
- package/dist/bin/shell/chunks/timeout-4O4YYRTS.js +2 -0
- package/dist/bin/shell/shell.js +252 -252
- package/dist/bundle/browser.js +739 -738
- package/dist/bundle/chunks/{chunk-WCVBECE6.js → chunk-4VCAQZKQ.js} +32 -32
- package/dist/bundle/chunks/chunk-5CJQNRNJ.js +62 -0
- package/dist/bundle/chunks/{chunk-VFBZTF5G.js → chunk-7BQDVPII.js} +1 -1
- package/dist/bundle/chunks/chunk-7KHLIOOW.js +4 -0
- package/dist/bundle/chunks/chunk-BEFDX7IY.js +1 -0
- package/dist/bundle/chunks/{chunk-DZ33S2U7.js → chunk-FO655G4V.js} +24 -24
- package/dist/bundle/chunks/chunk-NBAARP4B.js +1 -0
- package/dist/bundle/chunks/{chunk-HBB2R24Y.js → chunk-OKEHYWBE.js} +1 -1
- package/dist/bundle/chunks/chunk-RHOPHAL6.js +35 -0
- package/dist/bundle/chunks/{chunk-DKOIE53N.js → chunk-UJIR5V54.js} +1 -1
- package/dist/bundle/chunks/chunk-YIY2RKBW.js +13 -0
- package/dist/bundle/chunks/{expansion-NCEBD7KB.js → expansion-HJ6B4DDG.js} +1 -1
- package/dist/bundle/chunks/{flag-coverage-U322DJFL.js → flag-coverage-MPLWXQQK.js} +1 -1
- package/dist/bundle/chunks/{gzip-UTSGNF5Z.js → gzip-Y4N2UKE7.js} +1 -1
- package/dist/bundle/chunks/python3-6BKA3FYA.js +16 -0
- package/dist/bundle/chunks/rg-RAICUFGG.js +1 -0
- package/dist/bundle/chunks/{sleep-RKLUWJ7F.js → sleep-LB7FI6AB.js} +1 -1
- package/dist/bundle/chunks/sqlite3-FVNA4KNF.js +1 -0
- package/dist/bundle/chunks/{tar-H6XTXOAP.js → tar-E2DVQEWO.js} +1 -1
- package/dist/bundle/chunks/time-AGNW2ZY6.js +1 -0
- package/dist/bundle/chunks/timeout-VN35D5O7.js +1 -0
- package/dist/bundle/chunks/worker.js +154 -4
- package/dist/bundle/index.cjs +775 -773
- package/dist/bundle/index.js +263 -263
- package/dist/commands/python3/fs-bridge-handler.d.ts +5 -1
- package/dist/commands/tar/tar-options.d.ts +1 -0
- package/dist/interpreter/helpers/result.d.ts +6 -0
- package/dist/limits.d.ts +2 -0
- package/dist/network/types.d.ts +1 -1
- package/dist/sandbox/Command.d.ts +8 -1
- package/dist/sandbox/Sandbox.d.ts +1 -0
- package/dist/timers.d.ts +1 -0
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
- package/dist/bin/chunks/chunk-4QM2TCNV.js +0 -2
- package/dist/bin/chunks/chunk-C7TH4MVZ.js +0 -14
- package/dist/bin/chunks/chunk-H7Y3TH22.js +0 -36
- package/dist/bin/chunks/chunk-KTFEQPO7.js +0 -4
- package/dist/bin/chunks/chunk-QC46PWBQ.js +0 -63
- package/dist/bin/chunks/chunk-WIWKAGK6.js +0 -2
- package/dist/bin/chunks/python3-XRP5IZRL.js +0 -16
- package/dist/bin/chunks/sqlite3-ZUGDKEIT.js +0 -2
- package/dist/bin/chunks/time-E5YULACD.js +0 -2
- package/dist/bin/chunks/timeout-TCIINQNA.js +0 -2
- package/dist/bin/shell/chunks/chunk-4QM2TCNV.js +0 -2
- package/dist/bin/shell/chunks/chunk-C7TH4MVZ.js +0 -14
- package/dist/bin/shell/chunks/chunk-H7Y3TH22.js +0 -36
- package/dist/bin/shell/chunks/chunk-KTFEQPO7.js +0 -4
- package/dist/bin/shell/chunks/chunk-QC46PWBQ.js +0 -63
- package/dist/bin/shell/chunks/chunk-WIWKAGK6.js +0 -2
- package/dist/bin/shell/chunks/python3-XRP5IZRL.js +0 -16
- package/dist/bin/shell/chunks/sqlite3-ZUGDKEIT.js +0 -2
- package/dist/bin/shell/chunks/time-E5YULACD.js +0 -2
- package/dist/bin/shell/chunks/timeout-TCIINQNA.js +0 -2
- package/dist/bundle/chunks/chunk-BNVESM72.js +0 -35
- package/dist/bundle/chunks/chunk-FPGA7RT4.js +0 -62
- package/dist/bundle/chunks/chunk-JOVMV4XV.js +0 -13
- package/dist/bundle/chunks/chunk-LEOLL6PF.js +0 -1
- package/dist/bundle/chunks/chunk-R7KYILVY.js +0 -3
- package/dist/bundle/chunks/chunk-YYAPW4OA.js +0 -1
- package/dist/bundle/chunks/python3-E7VF6UYO.js +0 -15
- package/dist/bundle/chunks/rg-DMOXE47H.js +0 -1
- package/dist/bundle/chunks/sqlite3-ZGX3YFJB.js +0 -1
- package/dist/bundle/chunks/time-ZEEYNXNZ.js +0 -1
- package/dist/bundle/chunks/timeout-LYYTWG45.js +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as p}from"./chunk-4OALHZXB.js";import{e as m}from"./chunk-JJHAWOIB.js";import{a as c}from"./chunk-4PRVMER6.js";var M={name:"time",async execute(r,i){let a="%e %M",o=null,f=!1,u=!1,t=0;for(;t<r.length;){let e=r[t];if(e==="-f"||e==="--format"){if(t++,t>=r.length)return{stdout:"",stderr:`time: missing argument to '-f'
|
|
3
|
+
`,exitCode:1};a=r[t],t++}else if(e==="-o"||e==="--output"){if(t++,t>=r.length)return{stdout:"",stderr:`time: missing argument to '-o'
|
|
4
|
+
`,exitCode:1};o=r[t],t++}else if(e==="-a"||e==="--append")f=!0,t++;else if(e==="-v"||e==="--verbose")a=`Command being timed: %C
|
|
5
|
+
Elapsed (wall clock) time: %e seconds
|
|
6
|
+
Maximum resident set size (kbytes): %M`,t++;else if(e==="-p"||e==="--portability")u=!0,t++;else if(e==="--"){t++;break}else if(e.startsWith("-"))t++;else break}let l=r.slice(t);if(l.length===0)return{stdout:"",stderr:"",exitCode:0};let g=m(),h=p(l),w=l.join(" "),s;try{if(!i.exec)return{stdout:"",stderr:`time: exec not available
|
|
7
|
+
`,exitCode:1};s=await i.exec(h,{env:c(i.env),cwd:i.cwd,stdin:i.stdin,signal:i.signal})}catch(e){s={stdout:"",stderr:`time: ${e.message}
|
|
8
|
+
`,exitCode:127}}let d=(m()-g)/1e3,n;if(u?n=`real ${d.toFixed(2)}
|
|
9
|
+
user 0.00
|
|
10
|
+
sys 0.00
|
|
11
|
+
`:(n=a.replace(/%e/g,d.toFixed(2)).replace(/%E/g,F(d)).replace(/%M/g,"0").replace(/%S/g,"0.00").replace(/%U/g,"0.00").replace(/%P/g,"0%").replace(/%C/g,w),n.endsWith(`
|
|
12
|
+
`)||(n+=`
|
|
13
|
+
`)),o)try{let e=i.fs.resolvePath(i.cwd,o);if(f&&await i.fs.exists(e)){let C=await i.fs.readFile(e);await i.fs.writeFile(e,C+n)}else await i.fs.writeFile(e,n)}catch(e){return{stdout:s.stdout,stderr:s.stderr+`time: cannot write to '${o}': ${e.message}
|
|
14
|
+
`,exitCode:s.exitCode}}else s={...s,stderr:s.stderr+n};return s}};function F(r){let i=Math.floor(r/3600),a=Math.floor(r%3600/60),o=r%60;return i>0?`${i}:${a.toString().padStart(2,"0")}:${o.toFixed(2).padStart(5,"0")}`:`${a}:${o.toFixed(2).padStart(5,"0")}`}var S={name:"time",flags:[{flag:"-p",type:"boolean"}],needsArgs:!0};export{M as a,S as b};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as G}from"./chunk-4FNW6LFM.js";import{a as I}from"./chunk-SE4C7FJY.js";import{a as se,b as ae,c as H}from"./chunk-GTNBSMZR.js";import ve from"compressjs";var j="file",le="link",ue="symlink",Z="directory",Ze={file:"0",link:"1",symlink:"2","character-device":"3","block-device":"4",directory:"5",fifo:"6","pax-header":"x","pax-global-header":"g","gnu-long-name":"L","gnu-long-link-name":"K"},Be={0:j,1:le,2:ue,3:"character-device",4:"block-device",5:Z,6:"fifo",x:"pax-header",g:"pax-global-header",L:"gnu-long-name",K:"gnu-long-link-name"},Ne=new Uint8Array(512),$=new Uint8Array(0),F=new TextEncoder,fe=new TextDecoder;function v(e,t,n,r){r&&F.encodeInto(r,e.subarray(t,t+n))}function z(e,t,n,r){if(r===void 0)return;let i=r.toString(8).padStart(n-1,"0");F.encodeInto(i,e.subarray(t,t+n-1))}function x(e,t,n){let r=e.indexOf(0,t),i=r===-1||r>t+n?t+n:r;return fe.decode(e.subarray(t,i))}function q(e,t,n){let r=0,i=t+n;for(let s=t;s<i;s++){let o=e[s];if(o===0)break;o!==32&&(r=r*8+(o-48))}return r}function b(e,t,n){if(e[t]&128){let r=0;r=e[t]&127;for(let i=1;i<n;i++)r=r*256+e[t+i];if(!Number.isSafeInteger(r))throw new Error("TAR number too large");return r}return q(e,t,n)}var R=e=>e.type===Z||e.type===ue||e.type===le;async function de(e){if(e==null)return $;if(e instanceof Uint8Array)return e;if(typeof e=="string")return F.encode(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await e.arrayBuffer());throw new TypeError("Unsupported content type for entry body.")}function me(e,t){let{strip:n,filter:r,map:i}=t;if(!n&&!r&&!i)return e;let s={...e};if(n&&n>0){let a=s.name.split("/").filter(Boolean);if(n>=a.length)return null;let c=a.slice(n).join("/");if(s.name=s.type===Z&&!c.endsWith("/")?`${c}/`:c,s.linkname?.startsWith("/")){let l=s.linkname.split("/").filter(Boolean);s.linkname=n>=l.length?"/":`/${l.slice(n).join("/")}`}}if(r?.(s)===!1)return null;let o=i?i(s):s;return o&&(!o.name||!o.name.trim()||o.name==="."||o.name==="/")?null:o}var X=32,De=48;function Le(e){let t=q(e,148,8),n=0;for(let r=0;r<e.length;r++)r>=148&&r<156?n+=X:n+=e[r];return t===n}function Pe(e){e.fill(X,148,156);let t=0;for(let n of e)t+=n;for(let n=153;n>=148;n--)e[n]=(t&7)+De,t>>=3;e[154]=0,e[155]=X}function Ke(e){let t={};e.name.length>100&&pe(e.name)===null&&(t.path=e.name),e.linkname&&e.linkname.length>100&&(t.linkpath=e.linkname),e.uname&&e.uname.length>32&&(t.uname=e.uname),e.gname&&e.gname.length>32&&(t.gname=e.gname),e.uid!=null&&e.uid>2097151&&(t.uid=String(e.uid)),e.gid!=null&&e.gid>2097151&&(t.gid=String(e.gid)),e.size!=null&&e.size>8589934591&&(t.size=String(e.size)),e.pax&&Object.assign(t,e.pax);let n=Object.entries(t);if(n.length===0)return null;let r=F.encode(n.map(([i,s])=>{let o=`${i}=${s}
|
|
3
|
+
`,a=F.encode(o).length+1,c=a+String(a).length;return c=a+String(c).length,`${c} ${o}`}).join(""));return{paxHeader:he({name:fe.decode(F.encode(`PaxHeader/${e.name}`).slice(0,100)),size:r.length,type:"pax-header",mode:420,mtime:e.mtime,uname:e.uname,gname:e.gname,uid:e.uid,gid:e.gid}),paxBody:r}}function pe(e){if(e.length<=100)return null;let t=e.length-100-1,n=e.lastIndexOf("/",155);return n>0&&n>=t?{prefix:e.slice(0,n),name:e.slice(n+1)}:null}function he(e){let t=new Uint8Array(512),n=R(e)?0:e.size??0,r=e.name,i="";if(!e.pax?.path){let s=pe(r);s&&(r=s.name,i=s.prefix)}return v(t,0,100,r),z(t,100,8,e.mode??(e.type===Z?493:420)),z(t,108,8,e.uid??0),z(t,116,8,e.gid??0),z(t,124,12,n),z(t,136,12,Math.floor((e.mtime?.getTime()??Date.now())/1e3)),v(t,156,1,Ze[e.type??j]),v(t,157,100,e.linkname),v(t,257,6,"ustar\0"),v(t,263,2,"00"),v(t,265,32,e.uname),v(t,297,32,e.gname),v(t,345,155,i),Pe(t),t}function Ge(e,t){if(t&&!Le(e))throw new Error("Invalid tar header checksum.");let n=x(e,156,1),r={name:x(e,0,100),mode:q(e,100,8),uid:b(e,108,8),gid:b(e,116,8),size:b(e,124,12),mtime:new Date(b(e,136,12)*1e3),type:Be[n]||j,linkname:x(e,157,100)},i=x(e,257,6);return i.trim()==="ustar"&&(r.uname=x(e,265,32),r.gname=x(e,297,32)),i==="ustar"&&(r.prefix=x(e,345,155)),r}var He={path:["name",e=>e],linkpath:["linkname",e=>e],size:["size",e=>parseInt(e,10)],mtime:["mtime",parseFloat],uid:["uid",e=>parseInt(e,10)],gid:["gid",e=>parseInt(e,10)],uname:["uname",e=>e],gname:["gname",e=>e]};function We(e){let t=new TextDecoder("utf-8"),n={},r={},i=0;for(;i<e.length;){let s=e.indexOf(32,i);if(s===-1)break;let o=parseInt(t.decode(e.subarray(i,s)),10);if(Number.isNaN(o)||o===0)break;let a=i+o,[c,l]=t.decode(e.subarray(s+1,a-1)).split("=",2);if(c&&l!==void 0){r[c]=l;let f=He[c];if(f){let[u,g]=f,p=g(l);(typeof p=="string"||!Number.isNaN(p))&&(n[u]=p)}}i=a}return Object.keys(r).length>0&&(n.pax=r),n}function oe(e,t){t.name!==void 0&&(e.name=t.name),t.linkname!==void 0&&(e.linkname=t.linkname),t.size!==void 0&&(e.size=t.size),t.mtime!==void 0&&(e.mtime=new Date(t.mtime*1e3)),t.uid!==void 0&&(e.uid=t.uid),t.gid!==void 0&&(e.gid=t.gid),t.uname!==void 0&&(e.uname=t.uname),t.gname!==void 0&&(e.gname=t.gname),t.pax&&(e.pax=Object.assign({},e.pax??{},t.pax))}function Xe(e){switch(e){case"pax-global-header":case"pax-header":return We;case"gnu-long-name":return t=>({name:x(t,0,t.length)});case"gnu-long-link-name":return t=>({linkname:x(t,0,t.length)});default:return}}function je(e){let t=he(e),n=Ke(e);if(!n)return[t];let r=-n.paxBody.length&511,i=r>0?[Ne.subarray(0,r)]:[];return[n.paxHeader,n.paxBody,...i,t]}var qe=new Uint8Array(512*2);function ge(e,t,n){let r=null,i=0,s=!1;return{add(o){if(s){let a=new Error("No new tar entries after finalize.");throw t(a),a}if(r!==null){let a=new Error("Previous entry must be completed before adding a new one");throw t(a),a}try{let a=R(o)?0:o.size??0,c=je({...o,size:a});for(let l of c)e(l);r={...o,size:a},i=0}catch(a){t(a)}},write(o){if(!r){let c=new Error("No active tar entry.");throw t(c),c}if(s){let c=new Error("Cannot write data after finalize.");throw t(c),c}let a=i+o.length;if(a>r.size){let c=new Error(`"${r.name}" exceeds given size of ${r.size} bytes.`);throw t(c),c}try{i=a,e(o)}catch(c){t(c)}},endEntry(){if(!r){let o=new Error("No active entry to end.");throw t(o),o}if(s){let o=new Error("Cannot end entry after finalize.");throw t(o),o}try{if(i!==r.size){let a=new Error(`Size mismatch for "${r.name}".`);throw t(a),a}let o=-r.size&511;o>0&&e(new Uint8Array(o)),r=null,i=0}catch(o){throw t(o),o}},finalize(){if(s){let o=new Error("Archive has already been finalized");throw t(o),o}if(r!==null){let o=new Error("Cannot finalize while an entry is still active");throw t(o),o}try{e(qe),s=!0,n&&n()}catch(o){t(o)}}}}var O=256;function Ye(){let e=new Array(O),t=e.length-1,n=0,r=0,i=0,s=a=>{let c=e[n];a===c.length?(e[n]=$,n=n+1&t):e[n]=c.subarray(a),i-=a,i===0&&e.length>O&&(e=new Array(O),t=O-1,n=0,r=0)};function o(a,c){if(c){let p=0,d=Math.min(a,i);for(;d>0;){let h=e[n],m=Math.min(d,h.length),E=m===h.length?h:h.subarray(0,m);if(s(m),d-=m,p+=m,!c(E))break}return p}if(i<a)return null;if(a===0)return $;let l=e[n];if(l.length>=a){let p=l.length===a?l:l.subarray(0,a);return s(a),p}let f=new Uint8Array(a),u=0,g=a;for(;g>0;){let p=e[n],d=Math.min(g,p.length);f.set(d===p.length?p:p.subarray(0,d),u),u+=d,g-=d,s(d)}return f}return{push:a=>{if(a.length===0)return;let c=r+1&t;if(c===n){let l=e.length,f=l*2,u=new Array(f),g=r-n+l&l-1;if(n<r)for(let p=0;p<g;p++)u[p]=e[n+p];else if(g>0){let p=l-n;for(let d=0;d<p;d++)u[d]=e[n+d];for(let d=0;d<r;d++)u[p+d]=e[d]}e=u,t=f-1,n=0,r=g,c=r+1&t}e[r]=a,r=c,i+=a.length},available:()=>i,peek:a=>{if(i<a)return null;if(a===0)return $;let c=e[n];if(c.length>=a)return c.length===a?c:c.subarray(0,a);let l=new Uint8Array(a),f=0,u=n;for(;f<a;){let g=e[u],p=Math.min(a-f,g.length);p===g.length?l.set(g,f):l.set(g.subarray(0,p),f),f+=p,u=u+1&t}return l},discard:a=>{if(a>i)throw new Error("Too many bytes consumed");if(a===0)return;let c=a;for(;c>0;){let l=e[n],f=Math.min(c,l.length);s(f),c-=f}},pull:o}}var W=0,k=1,M=new Error("Tar archive is truncated.");function Se(e={}){let t=e.strict??!1,{available:n,peek:r,push:i,discard:s,pull:o}=Ye(),a=W,c=!1,l=!1,f=!1,u=null,g={},p={},d={isEntryActive:()=>a===k,isBodyComplete:()=>!u||u.remaining===0,write(h){if(c)throw new Error("Archive already ended.");i(h)},end(){c=!0},readHeader(){if(a!==W)throw new Error("Cannot read header while an entry is active");if(!l)for(;!l;){if(n()<512){if(c){if(n()>0&&t)throw M;l=!0;return}return null}let h=r(512);if(ce(h)){if(n()<512*2){if(c){if(t)throw M;l=!0;return}return null}if(ce(r(512*2).subarray(512))){s(512*2),l=!0,f=!0;return}if(t)throw new Error("Invalid tar header.");s(512);continue}let m;try{m=Ge(h,t)}catch(A){if(t)throw A;s(512);continue}let E=Xe(m.type);if(E){let A=m.size+511&-512;if(n()<512+A){if(c&&t)throw M;return null}s(512);let w=E(o(A).subarray(0,m.size)),_=m.type==="pax-global-header"?g:p;for(let T in w)_[T]=w[T];continue}s(512);let S=m;return m.prefix&&(S.name=`${m.prefix}/${S.name}`),oe(S,g),oe(S,p),p={},u={header:S,remaining:S.size,padding:-S.size&511},a=k,S}},streamBody(h){if(a!==k||!u||u.remaining===0)return 0;let m=Math.min(u.remaining,n());if(m===0)return 0;let E=o(m,h);return u.remaining-=E,E},skipPadding(){if(a!==k||!u)return!0;if(u.remaining>0)throw new Error("Body not fully consumed");return n()<u.padding?!1:(s(u.padding),u=null,a=W,!0)},skipEntry(){if(a!==k||!u)return!0;let h=Math.min(u.remaining,n());return h>0&&(s(h),u.remaining-=h),u.remaining>0?!1:d.skipPadding()},validateEOF(){if(t){if(!f)throw M;if(n()>0&&o(n()).some(h=>h!==0))throw new Error("Invalid EOF.")}}};return d}function ce(e){if(e.byteOffset%8===0){let t=new BigUint64Array(e.buffer,e.byteOffset,e.length/8);for(let n=0;n<t.length;n++)if(t[n]!==0n)return!1;return!0}for(let t=0;t<e.length;t++)if(e[t]!==0)return!1;return!0}function ye(){return new CompressionStream("gzip")}function we(){return new DecompressionStream("gzip")}function Ve(){let e,t;return{readable:new ReadableStream({start(n){e=n,t=ge(n.enqueue.bind(n),n.error.bind(n),n.close.bind(n))}}),controller:{add(n){let r=R(n),i={...n};return r&&(i.size=0),t.add(i),r&&t.endEntry(),new WritableStream({write(s){t.write(s)},close(){r||t.endEntry()},abort(s){e.error(s)}})},finalize(){t.finalize()},error(n){e.error(n)}}}}async function Ae(e){let t=[],n=e.getReader(),r=0;try{for(;;){let{done:o,value:a}=await n.read();if(o)break;t.push(a),r+=a.length}let i=new Uint8Array(r),s=0;for(let o of t)i.set(o,s),s+=o.length;return i}finally{n.releaseLock()}}var Ee=e=>e.pipeTo(new WritableStream);function Je(e={}){let t=Se(e),n=null,r=!1,i=s=>{if(!r){r=!0;try{for(;;)if(t.isEntryActive()){if(n){if(t.streamBody(o=>(n.enqueue(o),!0))===0&&!t.isBodyComplete())break}else if(!t.skipEntry())break;if(t.isBodyComplete()){try{n?.close()}catch{}if(n=null,!t.skipPadding())break}}else{let o=t.readHeader();if(o==null)break;s.enqueue({header:o,body:new ReadableStream({start(a){o.size===0?a.close():n=a},pull:()=>i(s),cancel(){n=null,i(s)}})})}}catch(o){try{n?.error(o)}catch{}throw n=null,o}finally{r=!1}}};return new TransformStream({transform(s,o){try{t.write(s),i(o)}catch(a){try{n?.error(a)}catch{}throw a}},flush(s){try{if(t.end(),i(s),t.validateEOF(),t.isEntryActive()&&!t.isBodyComplete())try{n?.close()}catch{}}catch(o){try{n?.error(o)}catch{}throw o}}},void 0,{highWaterMark:1})}async function _e(e){let{readable:t,controller:n}=Ve();return await(async()=>{for(let r of e){let i=n.add(r.header),s="body"in r?r.body:r.data;if(!s){await i.close();continue}if(s instanceof ReadableStream)await s.pipeTo(i);else if(s instanceof Blob)await s.stream().pipeTo(i);else try{let o=await de(s);if(o.length>0){let a=i.getWriter();await a.write(o),await a.close()}else await i.close()}catch{throw new TypeError(`Unsupported content type for entry "${r.header.name}".`)}}})().then(()=>n.finalize()).catch(r=>n.error(r)),new Uint8Array(await Ae(t))}async function Te(e,t={}){let n=e instanceof ReadableStream?e:new ReadableStream({start(s){s.enqueue(e instanceof Uint8Array?e:new Uint8Array(e)),s.close()}}),r=[],i=n.pipeThrough(Je(t));for await(let s of i){let o;try{o=me(s.header,t)}catch(a){throw await s.body.cancel(),a}if(o===null){await Ee(s.body);continue}R(o)?(await Ee(s.body),r.push({header:o})):r.push({header:o,data:await Ae(s.body)})}return r}var B=null,N=null;async function Ue(){if(B)return B;if(N)throw N;try{return B=await G.runTrustedAsync(()=>import("node-liblzma")),B}catch{throw N=new Error("xz compression requires node-liblzma which failed to load. Install liblzma-dev (apt) or xz (brew) and reinstall dependencies."),N}}var D=null,L=null;async function Ie(){if(D)return D;if(L)throw L;try{return D=await G.runTrustedAsync(()=>import("@mongodb-js/zstd")),D}catch{throw L=new Error("zstd compression requires @mongodb-js/zstd which is not installed. Install it with: npm install @mongodb-js/zstd"),L}}var y=100*1024*1024,xe=512,Ce=1e4;function Qe(e){let t="file";e.isDirectory?t="directory":e.isSymlink&&(t="symlink");let n=e.name;e.isDirectory&&!n.endsWith("/")&&(n+="/");let r;e.content!==void 0&&(typeof e.content=="string"?r=new TextEncoder().encode(e.content):r=e.content);let i=e.isDirectory||e.isSymlink?0:r?.length??0;return{header:{name:n,mode:e.mode??(e.isDirectory?493:420),uid:e.uid??0,gid:e.gid??0,size:i,mtime:e.mtime??new Date,type:t,linkname:e.linkTarget??"",uname:"user",gname:"user"},body:r}}async function U(e){let t=e.map(Qe);return _e(t)}async function Fe(e){let t=await U(e),i=new ReadableStream({start(l){l.enqueue(t),l.close()}}).pipeThrough(ye()).getReader(),s=[];for(;;){let{done:l,value:f}=await i.read();if(l)break;s.push(f)}let o=s.reduce((l,f)=>l+f.length,0),a=new Uint8Array(o),c=0;for(let l of s)a.set(l,c),c+=l.length;return a}async function C(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};if(e.length<xe||e.length%xe!==0)return{entries:[],error:"Invalid tar archive format"};try{let t=await Te(e),n=[];for(let r of t){if(n.length>=Ce)return{entries:n,error:`Too many entries (max ${Ce})`};let i="file";switch(r.header.type){case"directory":i="directory";break;case"symlink":i="symlink";break;case"link":i="hardlink";break;case"file":i="file";break;default:i="other"}n.push({name:r.header.name,mode:r.header.mode??420,uid:r.header.uid??0,gid:r.header.gid??0,size:r.header.size,mtime:r.header.mtime??new Date,type:i,linkTarget:r.header.linkname||void 0,content:r.data??new Uint8Array(0)})}return{entries:n}}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:n}}}async function Y(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let r=new ReadableStream({start(c){c.enqueue(e),c.close()}}).pipeThrough(we()).getReader(),i=[],s=0;for(;;){let{done:c,value:l}=await r.read();if(c)break;if(s+=l.length,s>y)return await r.cancel(),{entries:[],error:`Decompressed archive too large (max ${y} bytes)`};i.push(l)}let o=new Uint8Array(s),a=0;for(let c of i)o.set(c,a),a+=c.length;return C(o)}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:`Decompression failed: ${n}`}}}function V(e){return e.length>=2&&e[0]===31&&e[1]===139}function J(e){return e.length>=3&&e[0]===66&&e[1]===90&&e[2]===104}function Q(e){return e.length>=6&&e[0]===253&&e[1]===55&&e[2]===122&&e[3]===88&&e[4]===90&&e[5]===0}async function et(e){let n=ve.Bzip2.decompressFile(Array.from(e));return new Uint8Array(n)}async function tt(e){let t=ve.Bzip2,n=[];return t.compressFile(Array.from(e),n,9),new Uint8Array(n)}async function rt(e){let n=(await Ue()).unxzSync(Buffer.from(e));return new Uint8Array(n)}async function nt(e){let n=(await Ue()).xzSync(Buffer.from(e));return new Uint8Array(n)}async function ze(e){let t=await U(e);return tt(t)}async function ke(e){let t=await U(e);return nt(t)}async function ee(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let t=await et(e);return t.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:C(t)}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:n}}}async function te(e,t){if(!t?.allowNativeCodecs)return{entries:[],error:"xz decompression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in, or decompress the archive externally before extraction."};if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let n=await rt(e);return n.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:C(n)}catch(n){let r=n instanceof Error?n.message:"Unknown error";return{entries:[],error:r}}}function re(e){return e.length>=4&&e[0]===40&&e[1]===181&&e[2]===47&&e[3]===253}async function it(e){let n=await(await Ie()).compress(Buffer.from(e),3);return new Uint8Array(n)}async function st(e){let n=await(await Ie()).decompress(Buffer.from(e));return new Uint8Array(n)}async function Re(e){let t=await U(e);return it(t)}async function ne(e,t){if(!t?.allowNativeCodecs)return{entries:[],error:"zstd decompression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in, or decompress the archive externally before extraction."};if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let n=await st(e);return n.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:C(n)}catch(n){let r=n instanceof Error?n.message:"Unknown error";return{entries:[],error:r}}}function be(e){let t={create:!1,append:!1,update:!1,extract:!1,list:!1,file:"",autoCompress:!1,gzip:!1,bzip2:!1,xz:!1,zstd:!1,verbose:!1,toStdout:!1,keepOldFiles:!1,touch:!1,directory:"",preserve:!1,absoluteNames:!1,strip:0,exclude:[],filesFrom:"",excludeFrom:"",wildcards:!1},n=[],r=0;for(;r<e.length;){let i=e[r];if(i.startsWith("-")&&!i.startsWith("--")&&i.length>2){if(/^-\d+$/.test(i)){n.push(i),r++;continue}for(let s=1;s<i.length;s++){let o=i[s];switch(o){case"c":t.create=!0;break;case"r":t.append=!0;break;case"u":t.update=!0;break;case"x":t.extract=!0;break;case"t":t.list=!0;break;case"a":t.autoCompress=!0;break;case"z":t.gzip=!0;break;case"j":t.bzip2=!0;break;case"J":t.xz=!0;break;case"v":t.verbose=!0;break;case"O":t.toStdout=!0;break;case"k":t.keepOldFiles=!0;break;case"m":t.touch=!0;break;case"p":t.preserve=!0;break;case"P":t.absoluteNames=!0;break;case"f":if(s<i.length-1)t.file=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'f'
|
|
4
|
+
`,exitCode:2}};t.file=e[r]}break;case"C":if(s<i.length-1)t.directory=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'C'
|
|
5
|
+
`,exitCode:2}};t.directory=e[r]}break;case"T":if(s<i.length-1)t.filesFrom=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'T'
|
|
6
|
+
`,exitCode:2}};t.filesFrom=e[r]}break;case"X":if(s<i.length-1)t.excludeFrom=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'X'
|
|
7
|
+
`,exitCode:2}};t.excludeFrom=e[r]}break;default:return{ok:!1,error:H("tar",`-${o}`)}}}r++;continue}if(i==="-c"||i==="--create")t.create=!0;else if(i==="-r"||i==="--append")t.append=!0;else if(i==="-u"||i==="--update")t.update=!0;else if(i==="-x"||i==="--extract"||i==="--get")t.extract=!0;else if(i==="-t"||i==="--list")t.list=!0;else if(i==="-a"||i==="--auto-compress")t.autoCompress=!0;else if(i==="-z"||i==="--gzip"||i==="--gunzip")t.gzip=!0;else if(i==="-j"||i==="--bzip2")t.bzip2=!0;else if(i==="-J"||i==="--xz")t.xz=!0;else if(i==="--zstd")t.zstd=!0;else if(i==="-v"||i==="--verbose")t.verbose=!0;else if(i==="-O"||i==="--to-stdout")t.toStdout=!0;else if(i==="-k"||i==="--keep-old-files")t.keepOldFiles=!0;else if(i==="-m"||i==="--touch")t.touch=!0;else if(i==="--wildcards")t.wildcards=!0;else if(i==="-p"||i==="--preserve"||i==="--preserve-permissions")t.preserve=!0;else if(i==="-P"||i==="--absolute-names")t.absoluteNames=!0;else if(i==="-f"||i==="--file"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'f'
|
|
8
|
+
`,exitCode:2}};t.file=e[r]}else if(i.startsWith("--file="))t.file=i.substring(7);else if(i==="-C"||i==="--directory"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'C'
|
|
9
|
+
`,exitCode:2}};t.directory=e[r]}else if(i.startsWith("--directory="))t.directory=i.substring(12);else if(i.startsWith("--strip-components=")||i.startsWith("--strip=")){let s=i.includes("--strip-components=")?i.substring(19):i.substring(8),o=parseInt(s,10);if(Number.isNaN(o)||o<0)return{ok:!1,error:{stdout:"",stderr:`tar: invalid number for --strip: '${s}'
|
|
10
|
+
`,exitCode:2}};t.strip=o}else if(i.startsWith("--exclude="))t.exclude.push(i.substring(10));else if(i==="--exclude"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option '--exclude' requires an argument
|
|
11
|
+
`,exitCode:2}};t.exclude.push(e[r])}else if(i==="-T"||i==="--files-from"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'T'
|
|
12
|
+
`,exitCode:2}};t.filesFrom=e[r]}else if(i.startsWith("--files-from="))t.filesFrom=i.substring(13);else if(i==="-X"||i==="--exclude-from"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'X'
|
|
13
|
+
`,exitCode:2}};t.excludeFrom=e[r]}else if(i.startsWith("--exclude-from="))t.excludeFrom=i.substring(15);else if(i==="--"){n.push(...e.slice(r+1));break}else{if(i.startsWith("-"))return{ok:!1,error:H("tar",i)};n.push(i)}r++}return{ok:!0,options:t,files:n}}var Oe=100,at={name:"tar",summary:"manipulate tape archives",usage:"tar [options] [file...]",description:["Create, extract, or list contents of tar archives.","","One of -c, -r, -u, -x, or -t is required to specify the operation."],options:["-c, --create create a new archive","-r, --append append files to the end of an archive","-u, --update only append files newer than copy in archive","-x, --extract extract files from an archive","-t, --list list contents of an archive","-f, --file=ARCHIVE use archive file ARCHIVE","-a, --auto-compress use archive suffix to determine compression","-z, --gzip filter archive through gzip","-j, --bzip2 filter archive through bzip2","-J, --xz filter archive through xz","--zstd filter archive through zstd","-v, --verbose verbosely list files processed","-O, --to-stdout extract files to standard output","-k, --keep-old-files don't replace existing files when extracting","-m, --touch don't extract file modified time","-C, --directory=DIR change to directory DIR before performing operations","-p, --preserve preserve permissions","-P, --absolute-names do not strip leading '/' or block '..' paths","-T, --files-from=FILE read files to extract/create from FILE","-X, --exclude-from=FILE read exclude patterns from FILE","--strip=N strip N leading path components on extraction","--exclude=PATTERN exclude files matching PATTERN","--wildcards use wildcards for pattern matching"," --help display this help and exit"],examples:["tar -cvf archive.tar file1 file2 Create archive from files","tar -czvf archive.tar.gz dir/ Create gzip-compressed archive","tar -cjvf archive.tar.bz2 dir/ Create bzip2-compressed archive","tar -rf archive.tar newfile.txt Append file to archive","tar -uf archive.tar dir/ Update archive with newer files","tar -xvf archive.tar Extract archive","tar -xvf archive.tar -C /tmp Extract to /tmp","tar -tvf archive.tar List archive contents","tar -xzf archive.tar.gz Extract gzip archive","tar -xf archive.tar file1.txt Extract specific file","tar -xOf archive.tar file.txt Extract file to stdout","tar -xf archive.tar --wildcards '*.txt' Extract matching files"]};function ie(e,t){let n=e.includes("/")?e.substring(e.lastIndexOf("/")+1):e;for(let r of t){let i=r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*").replace(/\?/g,".");if(I(`^${i}$`).test(e)||I(`^${i}/`).test(e)||!r.includes("/")&&I(`^${i}$`).test(n))return!0}return!1}function P(e,t){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*").replace(/\?/g,"."),r=e.includes("/")?e.substring(e.lastIndexOf("/")+1):e;return I(`^${n}$`).test(e)||I(`^${n}$`).test(r)}function Me(e,t){if(t<=0)return e;let n=e.split("/").filter(r=>r!=="");return n.length<=t?"":n.slice(t).join("/")}function $e(e){return e.split("/").some(t=>t==="..")}function ot(e,t){if(t)return{safePath:e};let n=e.replace(/^\/+/,"");return n.length===0?{safePath:""}:$e(n)?{error:"Path contains '..'"}:{safePath:n}}function ct(e,t){let n=t?"d":"-",r=[e&256?"r":"-",e&128?"w":"-",e&64?"x":"-",e&32?"r":"-",e&16?"w":"-",e&8?"x":"-",e&4?"r":"-",e&2?"w":"-",e&1?"x":"-"].join("");return n+r}function lt(e){let n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][e.getMonth()],r=e.getDate().toString().padStart(2," "),i=e.getHours().toString().padStart(2,"0"),s=e.getMinutes().toString().padStart(2,"0");return`${n} ${r} ${i}:${s}`}async function K(e,t,n,r){let i=[],s=[],o=e.fs.resolvePath(t,n);try{let a=await e.fs.stat(o);if(ie(n,r))return{entries:i,errors:s};if(a.isDirectory){i.push({name:n,isDirectory:!0,mode:a.mode,mtime:a.mtime});let c=await e.fs.readdir(o);for(let l=0;l<c.length;l+=Oe){let f=c.slice(l,l+Oe),u=await Promise.all(f.map(g=>K(e,t,n?`${n}/${g}`:g,r)));for(let g of u)i.push(...g.entries),s.push(...g.errors)}}else if(a.isFile){let c=await e.fs.readFileBuffer(o);i.push({name:n,content:c,mode:a.mode,mtime:a.mtime})}else if(a.isSymbolicLink){let c=await e.fs.readlink(o);i.push({name:n,isSymlink:!0,linkTarget:c,mode:a.mode,mtime:a.mtime})}}catch(a){let c=a instanceof Error?a.message:"unknown error";s.push(`tar: ${n}: ${c}`)}return{entries:i,errors:s}}async function ut(e,t,n){if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to create an empty archive
|
|
14
|
+
`,exitCode:2};let r=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,i=[],s=[],o="";for(let f of n){let{entries:u,errors:g}=await K(e,r,f,t.exclude);if(i.push(...u),s.push(...g),t.verbose)for(let p of u)o+=`${p.name}${p.isDirectory?"/":""}
|
|
15
|
+
`}if(i.length===0&&s.length>0)return{stdout:"",stderr:`${s.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`,exitCode:2};let a;try{t.gzip?a=await Fe(i):t.bzip2?a=await ze(i):t.xz?a=await ke(i):t.zstd?a=await Re(i):a=await U(i)}catch(f){return{stdout:"",stderr:`tar: error creating archive: ${f instanceof Error?f.message:"unknown error"}
|
|
18
|
+
`,exitCode:2}}let c="";if(t.file&&t.file!=="-"){let f=e.fs.resolvePath(e.cwd,t.file);try{await e.fs.writeFile(f,a)}catch(u){let g=u instanceof Error?u.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${g}
|
|
19
|
+
`,exitCode:2}}}else c=Buffer.from(a).toString("latin1");let l=o;return s.length>0&&(l+=`${s.join(`
|
|
20
|
+
`)}
|
|
21
|
+
`),{stdout:c,stderr:l,exitCode:s.length>0?2:0}}async function ft(e,t,n){if(!t.file||t.file==="-")return{stdout:"",stderr:`tar: Cannot append to stdin/stdout
|
|
22
|
+
`,exitCode:2};if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to append nothing to archive
|
|
23
|
+
`,exitCode:2};let r=e.fs.resolvePath(e.cwd,t.file),i;try{i=await e.fs.readFileBuffer(r)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
|
|
24
|
+
`,exitCode:2}}let s=await C(i);if(s.error)return{stdout:"",stderr:`tar: ${s.error}
|
|
25
|
+
`,exitCode:2};let o=s.entries.map(d=>({name:d.name,content:d.content,mode:d.mode,mtime:d.mtime,isDirectory:d.type==="directory",isSymlink:d.type==="symlink",linkTarget:d.linkTarget,uid:d.uid,gid:d.gid})),a=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,c=[],l=[],f="";for(let d of n){let{entries:h,errors:m}=await K(e,a,d,t.exclude);if(c.push(...h),l.push(...m),t.verbose)for(let E of h)f+=`${E.name}${E.isDirectory?"/":""}
|
|
26
|
+
`}let u=[...o,...c],g;try{g=await U(u)}catch(d){return{stdout:"",stderr:`tar: error creating archive: ${d instanceof Error?d.message:"unknown error"}
|
|
27
|
+
`,exitCode:2}}try{await e.fs.writeFile(r,g)}catch(d){let h=d instanceof Error?d.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${h}
|
|
28
|
+
`,exitCode:2}}let p=f;return l.length>0&&(p+=`${l.join(`
|
|
29
|
+
`)}
|
|
30
|
+
`),{stdout:"",stderr:p,exitCode:l.length>0?2:0}}async function dt(e,t,n){if(!t.file||t.file==="-")return{stdout:"",stderr:`tar: Cannot update stdin/stdout
|
|
31
|
+
`,exitCode:2};if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to update with nothing
|
|
32
|
+
`,exitCode:2};let r=e.fs.resolvePath(e.cwd,t.file),i;try{i=await e.fs.readFileBuffer(r)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
|
|
33
|
+
`,exitCode:2}}let s=await C(i);if(s.error)return{stdout:"",stderr:`tar: ${s.error}
|
|
34
|
+
`,exitCode:2};let o=new Map;for(let m of s.entries)o.set(m.name,m.mtime);let a=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,c=[],l=[],f="";for(let m of n){let{entries:E,errors:S}=await K(e,a,m,t.exclude);l.push(...S);for(let A of E){let w=o.get(A.name);(!w||A.mtime&&A.mtime.getTime()>w.getTime())&&(c.push(A),t.verbose&&(f+=`${A.name}${A.isDirectory?"/":""}
|
|
35
|
+
`))}}if(c.length===0){let m="";return l.length>0&&(m=`${l.join(`
|
|
36
|
+
`)}
|
|
37
|
+
`),{stdout:"",stderr:m,exitCode:l.length>0?2:0}}let u=new Set(c.map(m=>m.name)),p=[...s.entries.filter(m=>!u.has(m.name)).map(m=>({name:m.name,content:m.content,mode:m.mode,mtime:m.mtime,isDirectory:m.type==="directory",isSymlink:m.type==="symlink",linkTarget:m.linkTarget,uid:m.uid,gid:m.gid})),...c],d;try{d=await U(p)}catch(m){return{stdout:"",stderr:`tar: error creating archive: ${m instanceof Error?m.message:"unknown error"}
|
|
38
|
+
`,exitCode:2}}try{await e.fs.writeFile(r,d)}catch(m){let E=m instanceof Error?m.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${E}
|
|
39
|
+
`,exitCode:2}}let h=f;return l.length>0&&(h+=`${l.join(`
|
|
40
|
+
`)}
|
|
41
|
+
`),{stdout:"",stderr:h,exitCode:l.length>0?2:0}}async function mt(e,t,n){let r;if(t.file&&t.file!=="-"){let h=e.fs.resolvePath(e.cwd,t.file);try{r=await e.fs.readFileBuffer(h)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
|
|
42
|
+
`,exitCode:2}}}else r=Uint8Array.from(e.stdin,h=>h.charCodeAt(0));let i,s=t.gzip||V(r),o=t.bzip2||J(r),a=t.xz||Q(r),c=t.zstd||re(r);if(s?i=await Y(r):o?i=await ee(r):a?i=await te(r):c?i=await ne(r):i=await C(r),i.error)return{stdout:"",stderr:`tar: ${i.error}
|
|
43
|
+
`,exitCode:2};let l=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,f=t.absoluteNames?n:n.map(h=>h.replace(/^\/+/,"")).filter(h=>h.length>0),u="",g="",p=[];if(t.directory&&!t.toStdout)try{await e.fs.mkdir(l,{recursive:!0})}catch{}for(let h of i.entries){let m=Me(h.name,t.strip);if(!m)continue;let E=ot(m,t.absoluteNames);if(E.error){p.push(`tar: ${m}: ${E.error}`);continue}let S=E.safePath??"";if(!S)continue;let A=S.endsWith("/")?S.slice(0,-1):S;if(f.length>0){let _;if(t.wildcards?_=f.some(T=>P(S,T)||P(A,T)||S.startsWith(`${T}/`)):_=f.some(T=>S===T||S.startsWith(`${T}/`)||A===T),!_)continue}if(ie(S,t.exclude))continue;let w=e.fs.resolvePath(l,S);try{if(h.type==="directory"){if(t.toStdout)continue;await e.fs.mkdir(w,{recursive:!0}),t.verbose&&(u+=`${S}
|
|
44
|
+
`)}else if(h.type==="file"){if(t.toStdout){g+=new TextDecoder().decode(h.content),t.verbose&&(u+=`${S}
|
|
45
|
+
`);continue}if(t.keepOldFiles)try{await e.fs.stat(w),t.verbose&&(u+=`${S}: not overwritten, file exists
|
|
46
|
+
`);continue}catch{}let _=w.substring(0,w.lastIndexOf("/"));if(_)try{await e.fs.mkdir(_,{recursive:!0})}catch{}if(await e.fs.writeFile(w,h.content),t.preserve&&h.mode)try{await e.fs.chmod(w,h.mode)}catch{}t.verbose&&(u+=`${S}
|
|
47
|
+
`)}else if(h.type==="symlink"&&h.linkTarget){if(t.toStdout)continue;if(!t.absoluteNames&&(h.linkTarget.startsWith("/")||$e(h.linkTarget))){p.push(`tar: ${S}: unsafe symlink target`);continue}if(t.keepOldFiles)try{await e.fs.stat(w),t.verbose&&(u+=`${S}: not overwritten, file exists
|
|
48
|
+
`);continue}catch{}let _=w.substring(0,w.lastIndexOf("/"));if(_)try{await e.fs.mkdir(_,{recursive:!0})}catch{}try{await e.fs.symlink(h.linkTarget,w)}catch{}t.verbose&&(u+=`${S}
|
|
49
|
+
`)}}catch(_){let T=_ instanceof Error?_.message:"unknown error";p.push(`tar: ${S}: ${T}`)}}let d=u;return p.length>0&&(d+=`${p.join(`
|
|
50
|
+
`)}
|
|
51
|
+
`),{stdout:g,stderr:d,exitCode:p.length>0?2:0}}async function pt(e,t,n){let r;if(t.file&&t.file!=="-"){let f=e.fs.resolvePath(e.cwd,t.file);try{r=await e.fs.readFileBuffer(f)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
|
|
52
|
+
`,exitCode:2}}}else r=Uint8Array.from(e.stdin,f=>f.charCodeAt(0));let i,s=t.gzip||V(r),o=t.bzip2||J(r),a=t.xz||Q(r),c=t.zstd||re(r);if(s?i=await Y(r):o?i=await ee(r):a?i=await te(r):c?i=await ne(r):i=await C(r),i.error)return{stdout:"",stderr:`tar: ${i.error}
|
|
53
|
+
`,exitCode:2};let l="";for(let f of i.entries){let u=Me(f.name,t.strip);if(!u)continue;let g=u.endsWith("/")?u.slice(0,-1):u;if(n.length>0){let p;if(t.wildcards?p=n.some(d=>P(u,d)||P(g,d)||u.startsWith(`${d}/`)):p=n.some(d=>u===d||u.startsWith(`${d}/`)||g===d),!p)continue}if(!ie(u,t.exclude))if(t.verbose){let p=f.type==="directory",d=ct(f.mode,p),h=`${f.uid}/${f.gid}`,m=f.size.toString().padStart(8," "),E=lt(f.mtime),S=`${d} ${h.padEnd(10)} ${m} ${E} ${u}`;f.type==="symlink"&&f.linkTarget&&(S+=` -> ${f.linkTarget}`),l+=`${S}
|
|
54
|
+
`}else l+=`${u}
|
|
55
|
+
`}return{stdout:l,stderr:"",exitCode:0}}var It={name:"tar",async execute(e,t){if(ae(e))return se(at);let n=be(e);if(!n.ok)return n.error;let{options:r,files:i}=n,s=[r.create,r.append,r.update,r.extract,r.list].filter(Boolean).length;if(s===0)return{stdout:"",stderr:`tar: You must specify one of -c, -r, -u, -x, or -t
|
|
56
|
+
`,exitCode:2};if(s>1)return{stdout:"",stderr:`tar: You may not specify more than one of -c, -r, -u, -x, or -t
|
|
57
|
+
`,exitCode:2};if(r.autoCompress&&r.file&&r.create){let c=r.file.toLowerCase();c.endsWith(".tar.gz")||c.endsWith(".tgz")?r.gzip=!0:c.endsWith(".tar.bz2")||c.endsWith(".tbz2")?r.bzip2=!0:c.endsWith(".tar.xz")||c.endsWith(".txz")?r.xz=!0:(c.endsWith(".tar.zst")||c.endsWith(".tzst"))&&(r.zstd=!0)}let o=[r.gzip,r.bzip2,r.xz,r.zstd].filter(Boolean).length;if(o>1)return{stdout:"",stderr:`tar: You may not specify more than one compression option
|
|
58
|
+
`,exitCode:2};if((r.append||r.update)&&o>0)return{stdout:"",stderr:`tar: Cannot append/update compressed archives - decompress first
|
|
59
|
+
`,exitCode:2};let a=i;if(r.filesFrom){let c=t.fs.resolvePath(t.cwd,r.filesFrom);try{let f=(await t.fs.readFile(c)).split(`
|
|
60
|
+
`).map(u=>u.trim()).filter(u=>u.length>0&&!u.startsWith("#"));a=[...i,...f]}catch{return{stdout:"",stderr:`tar: ${r.filesFrom}: Cannot open: No such file or directory
|
|
61
|
+
`,exitCode:2}}}if(r.excludeFrom){let c=t.fs.resolvePath(t.cwd,r.excludeFrom);try{let f=(await t.fs.readFile(c)).split(`
|
|
62
|
+
`).map(u=>u.trim()).filter(u=>u.length>0&&!u.startsWith("#"));r.exclude.push(...f)}catch{return{stdout:"",stderr:`tar: ${r.excludeFrom}: Cannot open: No such file or directory
|
|
63
|
+
`,exitCode:2}}}return r.create?ut(t,r,a):r.append?ft(t,r,a):r.update?dt(t,r,a):r.extract?mt(t,r,a):pt(t,r,a)}},Ft={name:"tar",flags:[{flag:"-c",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-f",type:"value",valueHint:"path"},{flag:"-z",type:"boolean"},{flag:"-j",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-C",type:"value",valueHint:"path"},{flag:"--strip-components",type:"value",valueHint:"number"},{flag:"--exclude",type:"value",valueHint:"pattern"}],needsArgs:!0};export{It as a,Ft as b};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as g}from"./chunk-KGOUQS5A.js";function m(){let c=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables",allowedKeys:new Set(["NODE_V8_COVERAGE","NODE_DEBUG","NODE_DEBUG_NATIVE","NODE_COMPILE_CACHE","WATCH_REPORT_DEPENDENCIES","FORCE_COLOR","DEBUG","UNDICI_NO_FG","JEST_WORKER_ID","__MINIMATCH_TESTING_PLATFORM__","LOG_TOKENS","LOG_STREAM"])},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"getBuiltinModule",target:process,violationType:"process_get_builtin_module",strategy:"throw",reason:"process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"},{prop:"exit",target:process,violationType:"process_exit",strategy:"throw",reason:"process.exit could terminate the interpreter"},{prop:"abort",target:process,violationType:"process_exit",strategy:"throw",reason:"process.abort could crash the interpreter"},{prop:"kill",target:process,violationType:"process_kill",strategy:"throw",reason:"process.kill could signal other processes"},{prop:"setuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setuid could escalate privileges"},{prop:"setgid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgid could escalate privileges"},{prop:"umask",target:process,violationType:"process_umask",strategy:"throw",reason:"process.umask could modify file creation permissions"},{prop:"argv",target:process,violationType:"process_argv",strategy:"throw",reason:"process.argv may contain secrets in CLI arguments"},{prop:"chdir",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.chdir could confuse the interpreter's CWD tracking"},{prop:"send",target:process,violationType:"process_send",strategy:"throw",reason:"process.send could communicate with parent process in IPC contexts"},{prop:"channel",target:process,violationType:"process_channel",strategy:"throw",reason:"process.channel could access IPC channel to parent process"},{prop:"cpuUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.cpuUsage could enable timing side-channel attacks"},{prop:"memoryUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.memoryUsage could enable timing side-channel attacks"},{prop:"hrtime",target:process,violationType:"process_timing",strategy:"throw",reason:"process.hrtime could enable timing side-channel attacks"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"},{prop:"performance",target:globalThis,violationType:"performance_timing",strategy:"throw",reason:"performance.now() provides sub-millisecond timing for side-channel attacks"},{prop:"stdout",target:process,violationType:"process_stdout",strategy:"throw",reason:"process.stdout could bypass interpreter output to write to host stdout"},{prop:"stderr",target:process,violationType:"process_stderr",strategy:"throw",reason:"process.stderr could bypass interpreter output to write to host stderr"},{prop:"__defineGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineGetter__ allows prototype pollution via getter injection"},{prop:"__defineSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineSetter__ allows prototype pollution via setter injection"},{prop:"__lookupGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupGetter__ enables introspection for prototype pollution attacks"},{prop:"__lookupSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupSetter__ enables introspection for prototype pollution attacks"},{prop:"JSON",target:globalThis,violationType:"json_mutation",strategy:"freeze",reason:"Freeze JSON to prevent mutation of parsing/serialization"},{prop:"Math",target:globalThis,violationType:"math_mutation",strategy:"freeze",reason:"Freeze Math to prevent mutation of math utilities"}];try{let e=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&c.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let e=Object.getPrototypeOf(function*(){}).constructor;e&&e!==Function&&c.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let e=Object.getPrototypeOf(async function*(){}).constructor;e&&e!==Function&&e!==Object.getPrototypeOf(async()=>{}).constructor&&c.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return c.filter(e=>{try{return e.target[e.prop]!==void 0}catch{return!1}})}var h=typeof __BROWSER__<"u"&&__BROWSER__;function _(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,c=>{let e=Math.random()*16|0;return(c==="x"?e:e&3|8).toString(16)})}var b=null;if(!h)try{let{AsyncLocalStorage:c}=g("node:async_hooks");b=c}catch{}var w=`
|
|
3
|
+
|
|
4
|
+
This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,p=class extends Error{violation;constructor(e,t){super(e+w),this.violation=t,this.name="SecurityViolationError"}},l=!h&&b?new b:null,T=1e3,y={enabled:!0,auditMode:!1};function k(c){return c===void 0?{...y,enabled:!1}:typeof c=="boolean"?{...y,enabled:c}:{...y,...c}}var x=class c{static instance=null;static importHooksRegistered=!1;config;refCount=0;patchFailures=[];originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(e){this.config=e}static getInstance(e){let t=k(e);if(!c.instance)c.instance=new c(t);else{let r=c.instance.config;if(t.enabled!==r.enabled||t.auditMode!==r.auditMode)throw new Error(`DefenseInDepthBox config conflict: requested {enabled: ${t.enabled}, auditMode: ${t.auditMode}} but singleton already has {enabled: ${r.enabled}, auditMode: ${r.auditMode}}. All Bash instances must use the same defense-in-depth security settings, or call DefenseInDepthBox.resetInstance() between incompatible configurations.`)}return c.instance}static resetInstance(){c.instance&&(c.instance.forceDeactivate(),c.instance=null)}static isInSandboxedContext(){return l?l?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(l)return l?.getStore()?.executionId}isEnabled(){return this.config.enabled===!0&&l!==null&&!h}updateConfig(e){this.config={...this.config,...e}}activate(){if(h||!this.config.enabled||!l){let t=_();return{run:r=>r(),deactivate:()=>{},executionId:t}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let e=_();return{run:t=>l.run({sandboxActive:!0,executionId:e},t),deactivate:()=>{this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0)},executionId:e}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}getPatchFailures(){return[...this.patchFailures]}clearViolations(){this.violations=[]}getPathForTarget(e,t){return e===globalThis?`globalThis.${t}`:e===process?`process.${t}`:e===Error?`Error.${t}`:e===Function.prototype?`Function.prototype.${t}`:e===Object.prototype?`Object.prototype.${t}`:`<object>.${t}`}static runTrusted(e){if(!l)return e();let t=l.getStore();return t?l.run({...t,trusted:!0},e):e()}static async runTrustedAsync(e){if(!l)return e();let t=l.getStore();return t?l.run({...t,trusted:!0},e):e()}shouldBlock(){if(h||this.config.auditMode||!l)return!1;let e=l?.getStore();return!(e?.sandboxActive!==!0||e.trusted)}recordViolation(e,t,r){let s={timestamp:Date.now(),type:e,message:r,path:t,stack:new Error().stack,executionId:l?.getStore()?.executionId};if(this.violations.length<T&&this.violations.push(s),this.config.onViolation)try{this.config.onViolation(s)}catch(o){console.debug("[DefenseInDepthBox] onViolation callback threw:",o instanceof Error?o.message:o)}return s}createBlockingProxy(e,t,r){let s=this;return new Proxy(e,{apply(o,n,i){if(s.shouldBlock()){let a=`${t} is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} called (audit mode)`),Reflect.apply(o,n,i)},construct(o,n,i){if(s.shouldBlock()){let a=`${t} constructor is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} constructor called (audit mode)`),Reflect.construct(o,n,i)}})}createBlockingObjectProxy(e,t,r,s){let o=this;return new Proxy(e,{get(n,i,a){if(o.shouldBlock()){if(s&&typeof i=="string"&&s.has(i))return Reflect.get(n,i,a);let u=`${t}.${String(i)}`,d=`${u} is blocked during script execution`,f=o.recordViolation(r,u,d);throw new p(d,f)}if(o.config.auditMode&&l?.getStore()?.sandboxActive===!0){let u=`${t}.${String(i)}`;o.recordViolation(r,u,`${u} accessed (audit mode)`)}return Reflect.get(n,i,a)},set(n,i,a,u){if(o.shouldBlock()){let d=`${t}.${String(i)}`,f=`${d} modification is blocked during script execution`,v=o.recordViolation(r,d,f);throw new p(f,v)}return Reflect.set(n,i,a,u)},ownKeys(n){if(o.shouldBlock()){let i=`${t} enumeration is blocked during script execution`,a=o.recordViolation(r,t,i);throw new p(i,a)}return Reflect.ownKeys(n)},getOwnPropertyDescriptor(n,i){if(o.shouldBlock()){let a=`${t}.${String(i)}`,u=`${a} descriptor access is blocked during script execution`,d=o.recordViolation(r,a,u);throw new p(u,d)}return Reflect.getOwnPropertyDescriptor(n,i)},has(n,i){if(o.shouldBlock()){let a=`${t}.${String(i)}`,u=`${a} existence check is blocked during script execution`,d=o.recordViolation(r,a,u);throw new p(u,d)}return Reflect.has(n,i)}})}applyPatches(){this.patchFailures=[];let e=m(),t=new Set(["process_send","process_channel","process_stdout","process_stderr"]);for(let o of e)t.has(o.violationType)||this.applyPatch(o);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectDynamicImport(),this.protectModuleLoad(),this.protectModuleResolveFilename(),this.protectProcessMainModule(),this.protectProcessExecPath();let r=["Function.prototype.constructor","Module._load"],s=this.patchFailures.filter(o=>r.includes(o));if(s.length>0)throw this.restorePatches(),new Error(`DefenseInDepthBox: critical patches failed: ${s.join(", ")}`)}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let e=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&this.patchPrototypeConstructor(e.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(e){this.patchFailures.push("AsyncFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",e instanceof Error?e.message:e)}try{let e=Object.getPrototypeOf(function*(){}).constructor;e&&e!==Function&&this.patchPrototypeConstructor(e.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(e){this.patchFailures.push("GeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",e instanceof Error?e.message:e)}try{let e=Object.getPrototypeOf(async function*(){}).constructor,t=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&e!==t&&this.patchPrototypeConstructor(e.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(e){this.patchFailures.push("AsyncGeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",e instanceof Error?e.message:e)}}protectErrorPrepareStackTrace(){let e=this;try{let t=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:t});let r=t?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return r},set(s){if(e.shouldBlock()){let o="Error.prepareStackTrace modification is blocked during script execution",n=e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",o);throw new p(o,n)}e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),r=s},configurable:!0})}catch(t){this.patchFailures.push("Error.prepareStackTrace"),console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",t instanceof Error?t.message:t)}}patchPrototypeConstructor(e,t,r){let s=this;try{let o=Object.getOwnPropertyDescriptor(e,"constructor");this.originalDescriptors.push({target:e,prop:"constructor",descriptor:o});let n=o?.value;Object.defineProperty(e,"constructor",{get(){if(s.shouldBlock()){let i=`${t} access is blocked during script execution`,a=s.recordViolation(r,t,i);throw new p(i,a)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} accessed (audit mode)`),n},set(i){if(s.shouldBlock()){let a=`${t} modification is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}Object.defineProperty(this,"constructor",{value:i,writable:!0,configurable:!0})},configurable:!0})}catch(o){this.patchFailures.push(t),console.debug(`[DefenseInDepthBox] Could not patch ${t}:`,o instanceof Error?o.message:o)}}protectProcessMainModule(){if(typeof process>"u")return;let e=this;try{let t=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:t});let r=t?.value;r!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(e.shouldBlock()){let s="process.mainModule access is blocked during script execution",o=e.recordViolation("process_main_module","process.mainModule",s);throw new p(s,o)}return e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),r},set(s){if(e.shouldBlock()){let o="process.mainModule modification is blocked during script execution",n=e.recordViolation("process_main_module","process.mainModule",o);throw new p(o,n)}Object.defineProperty(process,"mainModule",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(t){this.patchFailures.push("process.mainModule"),console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",t instanceof Error?t.message:t)}}protectProcessExecPath(){if(typeof process>"u")return;let e=this;try{let t=Object.getOwnPropertyDescriptor(process,"execPath");this.originalDescriptors.push({target:process,prop:"execPath",descriptor:t});let r=t?.value??process.execPath;Object.defineProperty(process,"execPath",{get(){if(e.shouldBlock()){let s="process.execPath access is blocked during script execution",o=e.recordViolation("process_exec_path","process.execPath",s);throw new p(s,o)}return e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("process_exec_path","process.execPath","process.execPath accessed (audit mode)"),r},set(s){if(e.shouldBlock()){let o="process.execPath modification is blocked during script execution",n=e.recordViolation("process_exec_path","process.execPath",o);throw new p(o,n)}Object.defineProperty(process,"execPath",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(t){this.patchFailures.push("process.execPath"),console.debug("[DefenseInDepthBox] Could not protect process.execPath:",t instanceof Error?t.message:t)}}protectDynamicImport(){if(!(h||c.importHooksRegistered))try{let e=g("node:module");if(typeof e.registerHooks=="function"){e.registerHooks({resolve(t,r,s){if(t.startsWith("data:")||t.startsWith("blob:"))throw new Error(`dynamic import of ${t.startsWith("data:")?"data:":"blob:"} URLs is blocked by defense-in-depth`);return s(t,r)}}),c.importHooksRegistered=!0;return}if(typeof e.register=="function"){let t=["export async function resolve(specifier, context, nextResolve) {",' if (specifier.startsWith("data:") || specifier.startsWith("blob:")) {',' throw new Error("dynamic import of " + (specifier.startsWith("data:") ? "data:" : "blob:") + " URLs is blocked by defense-in-depth");'," }"," return nextResolve(specifier, context);","}"].join(`
|
|
5
|
+
`);e.register(`data:text/javascript,${encodeURIComponent(t)}`),c.importHooksRegistered=!0}}catch(e){console.debug("[DefenseInDepthBox] Could not register import() hooks:",e instanceof Error?e.message:e)}}protectModuleLoad(){if(!h)try{let e=null;if(typeof process<"u"){let n=process.mainModule;n&&typeof n=="object"&&(e=n.constructor)}if(!e&&typeof g<"u"&&typeof g.main<"u"&&(e=g.main.constructor),!e||typeof e._load!="function")return;let t=e._load,r=Object.getOwnPropertyDescriptor(e,"_load");this.originalDescriptors.push({target:e,prop:"_load",descriptor:r});let o=this.createBlockingProxy(t,"Module._load","module_load");Object.defineProperty(e,"_load",{value:o,writable:!0,configurable:!0})}catch(e){this.patchFailures.push("Module._load"),console.debug("[DefenseInDepthBox] Could not protect Module._load:",e instanceof Error?e.message:e)}}protectModuleResolveFilename(){if(!h)try{let e=null;if(typeof process<"u"){let n=process.mainModule;n&&typeof n=="object"&&(e=n.constructor)}if(!e&&typeof g<"u"&&typeof g.main<"u"&&(e=g.main.constructor),!e||typeof e._resolveFilename!="function")return;let t=e._resolveFilename,r=Object.getOwnPropertyDescriptor(e,"_resolveFilename");this.originalDescriptors.push({target:e,prop:"_resolveFilename",descriptor:r});let o=this.createBlockingProxy(t,"Module._resolveFilename","module_resolve_filename");Object.defineProperty(e,"_resolveFilename",{value:o,writable:!0,configurable:!0})}catch(e){this.patchFailures.push("Module._resolveFilename"),console.debug("[DefenseInDepthBox] Could not protect Module._resolveFilename:",e instanceof Error?e.message:e)}}applyPatch(e){let{target:t,prop:r,violationType:s,strategy:o}=e;try{let n=t[r];if(n===void 0)return;let i=Object.getOwnPropertyDescriptor(t,r);if(this.originalDescriptors.push({target:t,prop:r,descriptor:i}),o==="freeze")typeof n=="object"&&n!==null&&Object.freeze(n);else{let a=this.getPathForTarget(t,r),u=typeof n=="function"?this.createBlockingProxy(n,a,s):this.createBlockingObjectProxy(n,a,s,e.allowedKeys);Object.defineProperty(t,r,{value:u,writable:!0,configurable:!0})}}catch(n){let i=this.getPathForTarget(t,r);this.patchFailures.push(i),console.debug(`[DefenseInDepthBox] Could not patch ${i}:`,n instanceof Error?n.message:n)}}restorePatches(){for(let e=this.originalDescriptors.length-1;e>=0;e--){let{target:t,prop:r,descriptor:s}=this.originalDescriptors[e];try{s?Object.defineProperty(t,r,s):delete t[r]}catch(o){let n=this.getPathForTarget(t,r);console.debug(`[DefenseInDepthBox] Could not restore ${n}:`,o instanceof Error?o.message:o)}}this.originalDescriptors=[]}};export{p as a,x as b};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as p}from"./chunk-4FNW6LFM.js";import{a as j,b as h}from"./chunk-JJHAWOIB.js";import{a as S,b as y}from"./chunk-GTNBSMZR.js";import{existsSync as g}from"node:fs";import{dirname as W,join as w}from"node:path";import{fileURLToPath as H}from"node:url";import{Worker as J}from"node:worker_threads";import _ from"sql.js";function E(e,r,n){switch(n.mode){case"list":return M(e,r,n);case"csv":return V(e,r,n);case"json":return B(e,r);case"line":return O(e,r,n);case"column":return I(e,r,n);case"table":return N(e,r,n);case"markdown":return P(e,r,n);case"tabs":return R(e,r,n);case"box":return F(e,r,n);case"quote":return Q(e,r,n);case"html":return D(e,r,n);case"ascii":return U(e,r,n)}}function u(e,r){return e==null?r:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function M(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(n.separator));for(let a of r)t.push(a.map(i=>u(i,n.nullValue)).join(n.separator));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function V(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(x).join(","));for(let a of r)t.push(a.map(i=>x(u(i,n.nullValue))).join(","));return t.length>0?`${t.join(`
|
|
3
|
+
`)}
|
|
4
|
+
`:""}function x(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
5
|
+
`)?`"${e.replace(/"/g,'""')}"`:e}function T(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function A(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):T(e):JSON.stringify(e)}function B(e,r){return r.length===0?"":`[${r.map(t=>`{${e.map((i,s)=>`${JSON.stringify(i)}:${A(t[s])}`).join(",")}}`).join(`,
|
|
6
|
+
`)}]
|
|
7
|
+
`}function O(e,r,n){if(e.length===0||r.length===0)return"";let t=Math.max(5,...e.map(i=>i.length)),a=[];for(let i of r)for(let s=0;s<e.length;s++){let o=e[s].padStart(t);a.push(`${o} = ${u(i[s],n.nullValue)}`)}return`${a.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`}function I(e,r,n){if(e.length===0)return"";let t=e.map(i=>i.length);for(let i of r)for(let s=0;s<i.length;s++){let o=u(i[s],n.nullValue).length;o>t[s]&&(t[s]=o)}let a=[];n.header&&(a.push(e.map((i,s)=>i.padEnd(t[s])).join(" ")),a.push(t.map(i=>"-".repeat(i)).join(" ")));for(let i of r)a.push(i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" "));return a.length>0?`${a.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:""}function N(e,r,n){if(e.length===0)return"";let t=e.map(s=>s.length);for(let s of r)for(let o=0;o<s.length;o++){let f=u(s[o],n.nullValue).length;f>t[o]&&(t[o]=f)}let a=[],i=`+${t.map(s=>"-".repeat(s+2)).join("+")}+`;a.push(i),n.header&&(a.push(`| ${e.map((s,o)=>s.padEnd(t[o])).join(" | ")} |`),a.push(i));for(let s of r)a.push(`| ${s.map((o,f)=>u(o,n.nullValue).padEnd(t[f])).join(" | ")} |`);return a.push(i),`${a.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`}function P(e,r,n){if(e.length===0)return"";let t=[];n.header&&(t.push(`| ${e.join(" | ")} |`),t.push(`|${e.map(()=>"---").join("|")}|`));for(let a of r)t.push(`| ${a.map(i=>u(i,n.nullValue)).join(" | ")} |`);return t.length>0?`${t.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`:""}function R(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(" "));for(let a of r)t.push(a.map(i=>u(i,n.nullValue)).join(" "));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function F(e,r,n){if(e.length===0)return"";let t=e.map(i=>i.length);for(let i of r)for(let s=0;s<i.length;s++){let o=u(i[s],n.nullValue).length;o>t[s]&&(t[s]=o)}let a=[];a.push(`\u250C${t.map(i=>"\u2500".repeat(i+2)).join("\u252C")}\u2510`),a.push(`\u2502 ${e.map((i,s)=>i.padEnd(t[s])).join(" \u2502 ")} \u2502`),a.push(`\u251C${t.map(i=>"\u2500".repeat(i+2)).join("\u253C")}\u2524`);for(let i of r)a.push(`\u2502 ${i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" \u2502 ")} \u2502`);return a.push(`\u2514${t.map(i=>"\u2500".repeat(i+2)).join("\u2534")}\u2518`),`${a.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`}function Q(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(a=>`'${a}'`).join(","));for(let a of r)t.push(a.map(i=>i==null?"NULL":typeof i=="number"?Number.isInteger(i)?String(i):T(i):`'${String(i)}'`).join(","));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function D(e,r,n){let t=[];n.header&&e.length>0&&(t.push(`<TR>${e.map(a=>`<TH>${q(a)}</TH>`).join("")}`),t.push("</TR>"));for(let a of r)t.push(`<TR>${a.map(i=>`<TD>${q(u(i,n.nullValue))}</TD>`).join("")}`),t.push("</TR>");return t.length>0?`${t.join(`
|
|
18
|
+
`)}
|
|
19
|
+
`:""}function q(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function U(e,r,n){let i=[];n.header&&e.length>0&&i.push(e.join(""));for(let s of r)i.push(s.map(o=>u(o,n.nullValue)).join(""));return i.length>0?i.join("")+"":""}var z=5e3,X={name:"sqlite3",summary:"SQLite database CLI",usage:"sqlite3 [OPTIONS] DATABASE [SQL]",options:["-list output in list mode (default)","-csv output in CSV mode","-json output in JSON mode","-line output in line mode","-column output in column mode","-table output as ASCII table","-markdown output as markdown table","-tabs output in tab-separated mode","-box output in Unicode box mode","-quote output in SQL quote mode","-html output as HTML table","-ascii output in ASCII mode (control chars)","-header show column headers","-noheader hide column headers","-separator SEP field separator for list mode (default: |)","-newline SEP row separator (default: \\n)","-nullvalue TEXT text for NULL values (default: empty)","-readonly open database read-only (no writeback)","-bail stop on first error","-echo print SQL before execution","-cmd COMMAND run SQL command before main SQL","-version show SQLite version","-- end of options","--help show this help"],examples:['sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1); SELECT * FROM t"','sqlite3 -json data.db "SELECT * FROM users"','sqlite3 -csv -header data.db "SELECT id, name FROM products"','sqlite3 -box data.db "SELECT * FROM users"']};function Y(e){let r={mode:"list",header:!1,separator:"|",newline:`
|
|
20
|
+
`,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},n=null,t=null,a=!1,i=!1;for(let s=0;s<e.length;s++){let o=e[s];if(i){n===null?n=o:t===null&&(t=o);continue}if(o==="--")i=!0;else if(o==="-version")a=!0;else if(o==="-list")r.mode="list";else if(o==="-csv")r.mode="csv";else if(o==="-json")r.mode="json";else if(o==="-line")r.mode="line";else if(o==="-column")r.mode="column";else if(o==="-table")r.mode="table";else if(o==="-markdown")r.mode="markdown";else if(o==="-tabs")r.mode="tabs";else if(o==="-box")r.mode="box";else if(o==="-quote")r.mode="quote";else if(o==="-html")r.mode="html";else if(o==="-ascii")r.mode="ascii";else if(o==="-header")r.header=!0;else if(o==="-noheader")r.header=!1;else if(o==="-readonly")r.readonly=!0;else if(o==="-bail")r.bail=!0;else if(o==="-echo")r.echo=!0;else if(o==="-separator"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
|
|
21
|
+
`,exitCode:1};r.separator=e[++s]}else if(o==="-newline"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
|
|
22
|
+
`,exitCode:1};r.newline=e[++s]}else if(o==="-nullvalue"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
|
|
23
|
+
`,exitCode:1};r.nullValue=e[++s]}else if(o==="-cmd"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
|
|
24
|
+
`,exitCode:1};r.cmd=e[++s]}else{if(o.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${o.startsWith("--")?o.slice(1):o}
|
|
25
|
+
Use -help for a list of options.
|
|
26
|
+
`,exitCode:1};n===null?n=o:t===null&&(t=o)}}return{options:r,database:n,sql:t,showVersion:a}}async function v(){let e=await p.runTrustedAsync(()=>_()),r=new e.Database;try{let n=r.exec("SELECT sqlite_version()");return n.length>0&&n[0].values.length>0?String(n[0].values[0][0]):"unknown"}finally{r.close()}}function G(){let e=W(H(import.meta.url)),r=w(e,"../../commands/sqlite3/worker.js");if(g(r))return r;let n=w(e,"worker.js");if(g(n))return n;let t=w(e,"../../../dist/commands/sqlite3/worker.js");if(g(t))return t;throw new Error("sqlite3 worker not found. Run 'pnpm build' to compile the worker.")}var K={createWorker(e,r){return new J(e,{workerData:r})}};function Z(e){if(!e||typeof e!="object")return{success:!1,error:"Malformed worker response"};let r=e;return r.type==="security-violation"?{success:!1,error:`Security violation: ${typeof r.violation?.type=="string"?r.violation.type:"unknown"}`}:typeof r.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:r.success?Array.isArray(r.results)?typeof r.hasModifications!="boolean"?{success:!1,error:"Malformed worker response: missing hasModifications flag"}:r.dbBuffer!==null&&r.dbBuffer!==void 0&&!(r.dbBuffer instanceof Uint8Array)?{success:!1,error:"Malformed worker response: invalid dbBuffer"}:{success:!0,results:r.results,hasModifications:r.hasModifications,dbBuffer:r.dbBuffer===void 0?null:r.dbBuffer,defenseStats:r.defenseStats}:{success:!1,error:"Malformed worker response: missing results array"}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}async function ee(e,r){try{let n=G();return await new Promise((t,a)=>{let i=p.runTrusted(()=>K.createWorker(n,e)),s=j(()=>{i.terminate(),t({success:!1,error:`Query timeout: execution exceeded ${r}ms limit`})},r);i.on("message",o=>{h(s),t(Z(o))}),i.on("error",o=>{h(s),a(o)}),i.on("exit",o=>{h(s),o!==0&&t({success:!1,error:`Worker exited with code ${o}`})})})}catch(n){throw new Error(`sqlite3 worker failed to load: ${n.message}`)}}var de={name:"sqlite3",async execute(e,r){if(y(e)||e.includes("-help"))return S(X);let n=Y(e);if("exitCode"in n)return n;let{options:t,database:a,sql:i,showVersion:s}=n;if(s)return{stdout:`${await v()}
|
|
27
|
+
`,stderr:"",exitCode:0};if(!a)return{stdout:"",stderr:`sqlite3: missing database argument
|
|
28
|
+
`,exitCode:1};let o=i||r.stdin.trim();if(t.cmd&&(o=t.cmd+(o?`; ${o}`:"")),!o)return{stdout:"",stderr:`sqlite3: no SQL provided
|
|
29
|
+
`,exitCode:1};let f=a===":memory:",m="",b=null;try{f||(m=r.fs.resolvePath(r.cwd,a),await r.fs.exists(m)&&(b=await r.fs.readFileBuffer(m)))}catch(l){return{stdout:"",stderr:`sqlite3: unable to open database "${a}": ${l.message}
|
|
30
|
+
`,exitCode:1}}let C=r.limits?.maxSqliteTimeoutMs??z,k={dbBuffer:b,sql:o,options:{bail:t.bail,echo:t.echo}},d;try{d=await ee(k,C)}catch(l){return{stdout:"",stderr:`sqlite3: worker error: ${l.message}
|
|
31
|
+
`,exitCode:1}}if(!d.success)return{stdout:"",stderr:`sqlite3: ${d.error}
|
|
32
|
+
`,exitCode:1};let L={mode:t.mode,header:t.header,separator:t.separator,newline:t.newline,nullValue:t.nullValue},c="";t.echo&&(c+=`${o}
|
|
33
|
+
`);let $=!1;for(let l of d.results)if(l.type==="error"){if(t.bail)return{stdout:c,stderr:`Error: ${l.error}
|
|
34
|
+
`,exitCode:1};c+=`Error: ${l.error}
|
|
35
|
+
`,$=!0}else l.columns&&l.rows&&(l.rows.length>0||t.header)&&(c+=E(l.columns,l.rows,L));if(d.hasModifications&&!t.readonly&&!f&&m&&d.dbBuffer)try{await r.fs.writeFile(m,d.dbBuffer)}catch(l){return{stdout:c,stderr:`sqlite3: failed to write database: ${l.message}
|
|
36
|
+
`,exitCode:1}}return{stdout:c,stderr:"",exitCode:$&&t.bail?1:0}}},ce={name:"sqlite3",flags:[],needsArgs:!0};export{K as a,de as b,ce as c};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as h}from"./chunk-4OALHZXB.js";import{a as c}from"./chunk-
|
|
2
|
+
import{a as h}from"./chunk-4OALHZXB.js";import{a as c}from"./chunk-JJHAWOIB.js";import{a as g,b as p,c as a}from"./chunk-GTNBSMZR.js";var v={name:"timeout",summary:"run a command with a time limit",usage:"timeout [OPTION] DURATION COMMAND [ARG]...",description:`Start COMMAND, and kill it if still running after DURATION.
|
|
3
3
|
|
|
4
4
|
DURATION is a number with optional suffix:
|
|
5
5
|
s - seconds (default)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
function d(t){if(!t)return t;let e=t.replace(/\n\s+at\s.*/g,"");return e=e.replace(/(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,"<path>"),e=e.replace(/node:internal\/[^\s'",)}\]:]+/g,"<internal>"),e=e.replace(/[A-Z]:\\[^\s'",)}\]:]+/g,"<path>"),e}import*as o from"node:fs";import*as r from"node:path";function y(t){if(!t||t==="/")return"/";let e=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;e.startsWith("/")||(e=`/${e}`);let n=e.split("/").filter(i=>i&&i!=="."),s=[];for(let i of n)i===".."?s.pop():s.push(i);return`/${s.join("/")}`||"/"}function f(t,e){return t===e||t.startsWith(`${e}/`)}function a(t,e){try{let n=o.realpathSync(t);return f(n,e)?n:null}catch(n){if(n.code==="ENOENT"){let s=r.dirname(t);if(s===t)return null;let i=a(s,e);if(i===null)return null;try{if(o.lstatSync(t).isSymbolicLink()){let l=o.readlinkSync(t),u=r.isAbsolute(l)?l:r.resolve(r.dirname(t),l);if(a(u,e)===null)return null}}catch{}return r.join(i,r.basename(t))}return null}}function v(t,e,n){let s=a(t,n);if(s===null)return null;let i=r.resolve(t),c=i.slice(e.length),l=s.slice(n.length);if(c!==l)return null;try{if(o.lstatSync(i).isSymbolicLink())return null}catch{}return s}function m(t,e){if(!o.existsSync(t))throw new Error(`${e} root does not exist`);if(!o.statSync(t).isDirectory())throw new Error(`${e} root is not a directory`)}function S(t,e){if(t.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${e} '${t}'`)}function x(t,e){if(!r.isAbsolute(t))return{withinRoot:!0,relativePath:t};let n;try{n=o.realpathSync(t)}catch{n=r.resolve(t)}return f(n,e)?{withinRoot:!0,relativePath:n.slice(e.length)||"/"}:{withinRoot:!1,safeName:r.basename(t)}}export{d as a,y as b,f as c,a as d,v as e,m as f,S as g,x as h};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a,b as o}from"./chunk-
|
|
2
|
+
import{a,b as o}from"./chunk-JJHAWOIB.js";import{a as i,b as l}from"./chunk-GTNBSMZR.js";var d={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
3
3
|
s - seconds (default)
|
|
4
4
|
m - minutes
|
|
5
5
|
h - hours
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as $}from"./chunk-JBABAK44.js";import{a as
|
|
2
|
+
import{a as $}from"./chunk-JBABAK44.js";import{a as z,b as w}from"./chunk-GTNBSMZR.js";import{constants as x,gunzipSync as F,gzipSync as S}from"node:zlib";var O={name:"gzip",summary:"compress or expand files",usage:"gzip [OPTION]... [FILE]...",description:`Compress FILEs (by default, in-place).
|
|
3
3
|
|
|
4
4
|
When no FILE is given, or when FILE is -, read from standard input.
|
|
5
5
|
|
|
6
|
-
With -d, decompress instead.`,options:["-c, --stdout write to standard output, keep original files","-d, --decompress decompress","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not save or restore the original name and timestamp","-N, --name save or restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode","-1, --fast compress faster","-9, --best compress better"," --help display this help and exit"]},
|
|
6
|
+
With -d, decompress instead.`,options:["-c, --stdout write to standard output, keep original files","-d, --decompress decompress","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not save or restore the original name and timestamp","-N, --name save or restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode","-1, --fast compress faster","-9, --best compress better"," --help display this help and exit"]},U={name:"gunzip",summary:"decompress files",usage:"gunzip [OPTION]... [FILE]...",description:`Decompress FILEs (by default, in-place).
|
|
7
7
|
|
|
8
|
-
When no FILE is given, or when FILE is -, read from standard input.`,options:["-c, --stdout write to standard output, keep original files","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not restore the original name and timestamp","-N, --name restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},
|
|
8
|
+
When no FILE is given, or when FILE is -, read from standard input.`,options:["-c, --stdout write to standard output, keep original files","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not restore the original name and timestamp","-N, --name restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},D={name:"zcat",summary:"decompress files to stdout",usage:"zcat [OPTION]... [FILE]...",description:`Decompress FILEs to standard output.
|
|
9
9
|
|
|
10
|
-
When no FILE is given, or when FILE is -, read from standard input.`,options:["-f, --force force; read compressed data even from a terminal","-l, --list list compressed file contents","-q, --quiet suppress all warnings","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},
|
|
11
|
-
`,exitCode:1};try{let
|
|
12
|
-
`,exitCode:1}}}else{let
|
|
10
|
+
When no FILE is given, or when FILE is -, read from standard input.`,options:["-f, --force force; read compressed data even from a terminal","-l, --list list compressed file contents","-q, --quiet suppress all warnings","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},T={stdout:{short:"c",long:"stdout",type:"boolean"},toStdout:{long:"to-stdout",type:"boolean"},decompress:{short:"d",long:"decompress",type:"boolean"},uncompress:{long:"uncompress",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},keep:{short:"k",long:"keep",type:"boolean"},list:{short:"l",long:"list",type:"boolean"},noName:{short:"n",long:"no-name",type:"boolean"},name:{short:"N",long:"name",type:"boolean"},quiet:{short:"q",long:"quiet",type:"boolean"},recursive:{short:"r",long:"recursive",type:"boolean"},suffix:{short:"S",long:"suffix",type:"string",default:".gz"},test:{short:"t",long:"test",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"},fast:{short:"1",long:"fast",type:"boolean"},level2:{short:"2",type:"boolean"},level3:{short:"3",type:"boolean"},level4:{short:"4",type:"boolean"},level5:{short:"5",type:"boolean"},level6:{short:"6",type:"boolean"},level7:{short:"7",type:"boolean"},level8:{short:"8",type:"boolean"},best:{short:"9",long:"best",type:"boolean"}};function E(e){return e.best?x.Z_BEST_COMPRESSION:e.level8?8:e.level7?7:e.level6?6:e.level5?5:e.level4?4:e.level3?3:e.level2?2:e.fast?x.Z_BEST_SPEED:x.Z_DEFAULT_COMPRESSION}function k(e){if(e.length<10)return{originalName:null,mtime:null,headerSize:0};if(e[0]!==31||e[1]!==139)return{originalName:null,mtime:null,headerSize:0};let t=e[3],o=e[4]|e[5]<<8|e[6]<<16|e[7]<<24,r=10;if(t&4){if(r+2>e.length)return{originalName:null,mtime:null,headerSize:0};let n=e[r]|e[r+1]<<8;r+=2+n}let s=null;if(t&8){let n=r;for(;r<e.length&&e[r]!==0;)r++;r<e.length&&(s=new TextDecoder().decode(e.slice(n,r)),r++)}if(t&16){for(;r<e.length&&e[r]!==0;)r++;r++}return t&2&&(r+=2),{originalName:s,mtime:o>0?new Date(o*1e3):null,headerSize:r}}function q(e){if(e.length<4)return 0;let t=e.length;return e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24}function b(e){return e.length>=2&&e[0]===31&&e[1]===139}function m(e){return Buffer.from(e).toString("latin1")}function I(e){return e.limits?.maxOutputSize??0}function v(e,t){if(t>0){if(q(e)>t)throw new Error(`decompressed data exceeds limit (${t} bytes)`);return F(e,{maxOutputLength:t})}return F(e)}async function L(e,t,o,r,s,n){let d=o.suffix,f,p,a,c=I(e);if(t==="-"||t==="")if(a=Uint8Array.from(e.stdin,i=>i.charCodeAt(0)),s){if(!b(a))return o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: stdin: not in gzip format
|
|
11
|
+
`,exitCode:1};try{let i=v(a,c);return{stdout:m(i),stderr:"",exitCode:0}}catch(i){let l=i instanceof Error?i.message:"unknown error";return{stdout:"",stderr:`${r}: stdin: ${l}
|
|
12
|
+
`,exitCode:1}}}else{let i=E(o),l=S(a,{level:i});return{stdout:m(l),stderr:"",exitCode:0}}f=e.fs.resolvePath(e.cwd,t);try{if((await e.fs.stat(f)).isDirectory)return o.recursive?await P(e,f,o,r,s,n):o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${t}: is a directory -- ignored
|
|
13
13
|
`,exitCode:1}}catch{return{stdout:"",stderr:`${r}: ${t}: No such file or directory
|
|
14
14
|
`,exitCode:1}}try{a=await e.fs.readFileBuffer(f)}catch{return{stdout:"",stderr:`${r}: ${t}: No such file or directory
|
|
15
|
-
`,exitCode:1}}if(s){if(!t.endsWith(
|
|
16
|
-
`,exitCode:1};if(!
|
|
17
|
-
`,exitCode:1};let
|
|
18
|
-
`,exitCode:1}}if(n)return{stdout:
|
|
19
|
-
`,exitCode:1}}catch{}if(await e.fs.writeFile(p,
|
|
20
|
-
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}else{if(t.endsWith(
|
|
21
|
-
`,exitCode:1};let
|
|
22
|
-
`,exitCode:1}}if(n)return{stdout:
|
|
23
|
-
`,exitCode:1}}catch{}if(await e.fs.writeFile(p,
|
|
24
|
-
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}}async function
|
|
25
|
-
`,exitCode:1}}}if(!
|
|
26
|
-
`,exitCode:1};let n=s.length,
|
|
27
|
-
`,stderr:"",exitCode:0}}async function
|
|
28
|
-
`,exitCode:1}}}if(!
|
|
29
|
-
`,exitCode:1};try{return
|
|
30
|
-
`,exitCode:0}:{stdout:"",stderr:"",exitCode:0}}catch(n){let
|
|
31
|
-
`,exitCode:1}}}async function
|
|
32
|
-
`,
|
|
15
|
+
`,exitCode:1}}if(s){if(!t.endsWith(d))return o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${t}: unknown suffix -- ignored
|
|
16
|
+
`,exitCode:1};if(!b(a))return o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${t}: not in gzip format
|
|
17
|
+
`,exitCode:1};let i;try{i=v(a,c)}catch(l){let u=l instanceof Error?l.message:"unknown error";return{stdout:"",stderr:`${r}: ${t}: ${u}
|
|
18
|
+
`,exitCode:1}}if(n)return{stdout:m(i),stderr:"",exitCode:0};if(o.name){let l=k(a);l.originalName?p=e.fs.resolvePath(e.cwd,l.originalName):p=f.slice(0,-d.length)}else p=f.slice(0,-d.length);if(!o.force)try{return await e.fs.stat(p),{stdout:"",stderr:`${r}: ${p} already exists; not overwritten
|
|
19
|
+
`,exitCode:1}}catch{}if(await e.fs.writeFile(p,i),!o.keep&&!n&&await e.fs.rm(f),o.verbose){let l=a.length>0?((1-a.length/i.length)*100).toFixed(1):"0.0";return{stdout:"",stderr:`${t}: ${l}% -- replaced with ${p.split("/").pop()}
|
|
20
|
+
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}else{if(t.endsWith(d))return o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${t} already has ${d} suffix -- unchanged
|
|
21
|
+
`,exitCode:1};let i=E(o),l;try{l=S(a,{level:i})}catch(u){let g=u instanceof Error?u.message:"unknown error";return{stdout:"",stderr:`${r}: ${t}: ${g}
|
|
22
|
+
`,exitCode:1}}if(n)return{stdout:m(l),stderr:"",exitCode:0};if(p=f+d,!o.force)try{return await e.fs.stat(p),{stdout:"",stderr:`${r}: ${p} already exists; not overwritten
|
|
23
|
+
`,exitCode:1}}catch{}if(await e.fs.writeFile(p,l),!o.keep&&!n&&await e.fs.rm(f),o.verbose){let u=a.length>0?((1-l.length/a.length)*100).toFixed(1):"0.0";return{stdout:"",stderr:`${t}: ${u}% -- replaced with ${p.split("/").pop()}
|
|
24
|
+
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}}async function P(e,t,o,r,s,n){let d=await e.fs.readdir(t),f="",p="",a=0;for(let c of d){let i=e.fs.resolvePath(t,c),l=await e.fs.stat(i);if(l.isDirectory){let u=await P(e,i,o,r,s,n);f+=u.stdout,p+=u.stderr,u.exitCode!==0&&(a=u.exitCode)}else if(l.isFile){let u=o.suffix;if(s&&!c.endsWith(u)||!s&&c.endsWith(u))continue;let g=i.startsWith(`${e.cwd}/`)?i.slice(e.cwd.length+1):i,y=await L(e,g,o,r,s,n);f+=y.stdout,p+=y.stderr,y.exitCode!==0&&(a=y.exitCode)}}return{stdout:f,stderr:p,exitCode:a}}async function W(e,t,o,r){let s;if(t==="-"||t==="")s=Uint8Array.from(e.stdin,i=>i.charCodeAt(0));else{let i=e.fs.resolvePath(e.cwd,t);try{s=await e.fs.readFileBuffer(i)}catch{return{stdout:"",stderr:`${r}: ${t}: No such file or directory
|
|
25
|
+
`,exitCode:1}}}if(!b(s))return o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${t}: not in gzip format
|
|
26
|
+
`,exitCode:1};let n=s.length,d=q(s),f=d>0?((1-n/d)*100).toFixed(1):"0.0",a=k(s).originalName||(t==="-"?"":t.replace(/\.gz$/,""));return{stdout:`${n.toString().padStart(10)} ${d.toString().padStart(10)} ${f.padStart(5)}% ${a}
|
|
27
|
+
`,stderr:"",exitCode:0}}async function A(e,t,o,r){let s;if(t==="-"||t==="")s=Uint8Array.from(e.stdin,n=>n.charCodeAt(0));else{let n=e.fs.resolvePath(e.cwd,t);try{s=await e.fs.readFileBuffer(n)}catch{return{stdout:"",stderr:`${r}: ${t}: No such file or directory
|
|
28
|
+
`,exitCode:1}}}if(!b(s))return o.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${t}: not in gzip format
|
|
29
|
+
`,exitCode:1};try{return v(s,I(e)),o.verbose?{stdout:"",stderr:`${t}: OK
|
|
30
|
+
`,exitCode:0}:{stdout:"",stderr:"",exitCode:0}}catch(n){let d=n instanceof Error?n.message:"invalid";return{stdout:"",stderr:`${r}: ${t}: ${d}
|
|
31
|
+
`,exitCode:1}}}async function C(e,t,o){let r=o==="zcat"?D:o==="gunzip"?U:O;if(w(e))return z(r);let s=$(o,e,T);if(!s.ok)return s.error.stderr.includes("unrecognized option"),s.error;let n=s.result.flags,d=s.result.positional,f=o==="gunzip"||o==="zcat"||n.decompress||n.uncompress,p=o==="zcat"||n.stdout||n.toStdout;if(n.list){d.length===0&&(d=["-"]);let l=` compressed uncompressed ratio uncompressed_name
|
|
32
|
+
`,u="",g=0;for(let y of d){let h=await W(t,y,n,o);l+=h.stdout,u+=h.stderr,h.exitCode!==0&&(g=h.exitCode)}return{stdout:l,stderr:u,exitCode:g}}if(n.test){d.length===0&&(d=["-"]);let l="",u="",g=0;for(let y of d){let h=await A(t,y,n,o);l+=h.stdout,u+=h.stderr,h.exitCode!==0&&(g=h.exitCode)}return{stdout:l,stderr:u,exitCode:g}}d.length===0&&(d=["-"]);let a="",c="",i=0;for(let l of d){let u=await L(t,l,n,o,f,p);a+=u.stdout,c+=u.stderr,u.exitCode!==0&&(i=u.exitCode)}return{stdout:a,stderr:c,exitCode:i}}var G={name:"gzip",async execute(e,t){return C(e,t,"gzip")}},M={name:"gunzip",async execute(e,t){return C(e,t,"gunzip")}},Z={name:"zcat",async execute(e,t){return C(e,t,"zcat")}},R={name:"gzip",flags:[{flag:"-c",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-k",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-1",type:"boolean"},{flag:"-9",type:"boolean"}],stdinType:"binary",needsFiles:!0},K={name:"gunzip",flags:[{flag:"-c",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-k",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-v",type:"boolean"}],stdinType:"binary",needsFiles:!0},j={name:"zcat",flags:[{flag:"-f",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-v",type:"boolean"}],stdinType:"binary",needsFiles:!0};export{G as a,M as b,Z as c,R as d,K as e,j as f};
|