just-bash 2.4.1 → 2.4.3

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.
@@ -1,10 +0,0 @@
1
- import{a as H}from"./chunk-UJMN5NLH.js";import{a as J,b as U,c as q}from"./chunk-NWEGHOXL.js";import"./chunk-NUFRM6SI.js";import{a as _,b as V}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";function F(e,s){switch(e.type){case"name":return{matches:H(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:H(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let r=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=r>e.days:e.comparison==="less"?t=r<e.days:t=Math.floor(r)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let r;return e.comparison==="more"?r=s.size>n:e.comparison==="less"?r=s.size<n:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,r=e.mode&511,t;return e.matchType==="exact"?t=n===r:e.matchType==="all"?t=(n&r)===r:t=(n&r)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=F(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=F(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=F(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=F(e.left,s);if(n.matches)return n;let r=F(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function z(e){if(!e)return!1;switch(e.type){case"name":case"path":case"regex":case"type":case"prune":case"print":return!1;case"empty":case"mtime":case"newer":case"size":case"perm":return!0;case"not":return z(e.expr);case"and":case"or":return z(e.left)||z(e.right)}}function K(e){let s=[],n=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right)))};return n(e),s}function Q(e,s){let n=[],r=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let i=e[++t];if(i==="f"||i==="d")n.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${i}
2
- `,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let i=e[++t],c="exact",p=i;i.startsWith("+")?(c="more",p=i.slice(1)):i.startsWith("-")&&(c="less",p=i.slice(1));let u=parseInt(p,10);Number.isNaN(u)||n.push({type:"expr",expr:{type:"mtime",days:u,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let i=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(a==="-size"&&t+1<e.length){let i=e[++t],c="exact",p=i;i.startsWith("+")?(c="more",p=i.slice(1)):i.startsWith("-")&&(c="less",p=i.slice(1));let u=p.match(/^(\d+)([ckMGb])?$/);if(u){let W=parseInt(u[1],10),E=u[2]||"b";n.push({type:"expr",expr:{type:"size",value:W,unit:E,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let i=e[++t],c="exact",p=i;i.startsWith("-")?(c="all",p=i.slice(1)):i.startsWith("/")&&(c="any",p=i.slice(1));let u=parseInt(p,8);Number.isNaN(u)||n.push({type:"expr",expr:{type:"perm",mode:u,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let i=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)i.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";r.push({type:"exec",command:i,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(a==="-print0")r.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let i=e[++t];r.push({type:"printf",format:i})}else if(a==="-delete")r.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
3
- `,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:r};let D=te(n);return D.error?{expr:null,pathIndex:t,error:D.error,actions:r}:{expr:D.expr,pathIndex:t,actions:r}}function te(e){let s=0;function n(){let i=r();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let p=r();if(!p)return i;i={type:"or",left:i,right:p}}else break}return i}function r(){let i=t();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let p=t();if(!p)return i;i={type:"and",left:i,right:p}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let p=t();if(!p)return i;i={type:"and",left:i,right:p}}else break}return i}function t(){if(s<e.length&&e[s].type==="not"){s++;let i=t();return i?{type:"not",expr:i}:null}return D()}function D(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:n()}}var ne={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},se=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),ge={name:"find",async execute(e,s){if(V(e))return _(ne);let n=[],r=null,t=null,D=!1,a=!1;for(let o=0;o<e.length;o++){let l=e[o];if(l==="-maxdepth"&&o+1<e.length)a=!0,r=parseInt(e[++o],10);else if(l==="-mindepth"&&o+1<e.length)a=!0,t=parseInt(e[++o],10);else if(l==="-depth")a=!0,D=!0;else if(l==="-exec")for(a=!0,o++;o<e.length&&e[o]!==";"&&e[o]!=="+";)o++;else!l.startsWith("-")&&l!==";"&&l!=="+"&&l!=="("&&l!==")"&&l!=="\\("&&l!=="\\)"&&l!=="!"?a||n.push(l):se.has(l)?(a=!0,o++):(l.startsWith("-")||l==="("||l==="\\("||l==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:i,error:c,actions:p}=Q(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let u=p.some(o=>o.type==="print"),W=p.length===0,E=[],j=p.some(o=>o.type==="printf"),Y=[],A="",C=0,Z=K(i),L=new Map;for(let o of Z){let l=s.fs.resolvePath(s.cwd,o);try{let I=await s.fs.stat(l);L.set(o,I.mtime?.getTime()??Date.now())}catch{}}let X=z(i)||j,ee=typeof s.fs.readdirWithFileTypes=="function";for(let o of n){let b=function(h){let d=t===null||h.depth>=t,T=!1;if(d&&i!==null){let m={name:h.name,relativePath:h.relativePath,isFile:h.isFile,isDirectory:h.isDirectory,isEmpty:h.isEmpty,mtime:h.stat?.mtime?.getTime()??Date.now(),size:h.stat?.size??0,mode:h.stat?.mode??420,newerRefTimes:L},f=F(i,m);d=f.matches,T=u?f.printed:d}else d&&(T=!0);return T?{print:!0,printfData:j?{path:h.relativePath,name:h.name,size:h.stat?.size??0,mtime:h.stat?.mtime?.getTime()??Date.now(),mode:h.stat?.mode??420,isDirectory:h.isDirectory,depth:h.depth,startingPoint:o}:null}:{print:!1,printfData:null}};var le=b;o.length>1&&o.endsWith("/")&&(o=o.slice(0,-1));let l=s.fs.resolvePath(s.cwd,o);try{await s.fs.stat(l)}catch{A+=`find: ${o}: No such file or directory
4
- `,C=1;continue}async function I(h){let{path:P,depth:d,typeInfo:T}=h;if(r!==null&&d>r)return null;let v,m,f;if(T&&!X)v=T.isFile,m=T.isDirectory;else{try{f=await s.fs.stat(P)}catch{return null}if(!f)return null;v=f.isFile,m=f.isDirectory}let y;P===l?y=o.split("/").pop()||o:y=P.split("/").pop()||"";let g=P===l?o:o==="."?`./${P.slice(l==="/"?l.length:l.length+1)}`:o+P.slice(l.length),S=[],M=null,$=null;m&&(ee&&s.fs.readdirWithFileTypes?(M=await s.fs.readdirWithFileTypes(P),S=M.map((R,O)=>({path:P==="/"?`/${R.name}`:`${P}/${R.name}`,depth:d+1,typeInfo:{isFile:R.isFile,isDirectory:R.isDirectory},resultIndex:O})),$=M.map(R=>R.name)):($=await s.fs.readdir(P),S=$.map((R,O)=>({path:P==="/"?`/${R}`:`${P}/${R}`,depth:d+1,resultIndex:O}))));let w=v?(f?.size??0)===0:$!==null&&$.length===0,B=!1;if(!D&&i!==null){let R={name:y,relativePath:g,isFile:v,isDirectory:m,isEmpty:w,mtime:f?.mtime?.getTime()??Date.now(),size:f?.size??0,mode:f?.mode??420,newerRefTimes:L};B=F(i,R).pruned}return{relativePath:g,name:y,isFile:v,isDirectory:m,isEmpty:w,stat:f,depth:d,children:B?[]:S,pruned:B}}async function x(){let h={paths:[],printfData:[]};if(D){let m=function(f){let y={paths:[],printfData:[]},g=d[f];if(!g)return y;for(let $ of g.childIndices){let w=m($);y.paths.push(...w.paths),y.printfData.push(...w.printfData)}let{print:S,printfData:M}=b(g.node);return S&&(y.paths.push(g.node.relativePath),M&&y.printfData.push(M)),y};var P=m;let d=[],T=[{item:{path:l,depth:0,resultIndex:0},parentIndex:-1,childOrderInParent:0}],v=new Map;for(;T.length>0;){let f=T.splice(0,100),y=await Promise.all(f.map(g=>I(g.item)));for(let g=0;g<f.length;g++){let S=y[g],M=f[g];if(!S)continue;let $=d.length;if(M.parentIndex>=0){let w=v.get(M.parentIndex)||[];w.push($),v.set(M.parentIndex,w)}d.push({node:S,parentIndex:M.parentIndex,childIndices:[]});for(let w=0;w<S.children.length;w++)T.push({item:S.children[w],parentIndex:$,childOrderInParent:w})}}for(let[f,y]of v)f>=0&&f<d.length&&(d[f].childIndices=y);if(d.length>0){let f=m(0);h.paths.push(...f.paths),h.printfData.push(...f.printfData)}}else{async function d(v){let m={paths:[],printfData:[]},f=await I(v);if(!f)return m;let{print:y,printfData:g}=b(f);y&&(m.paths.push(f.relativePath),g&&m.printfData.push(g));for(let S=0;S<f.children.length;S+=100){let M=f.children.slice(S,S+100),$=await Promise.all(M.map(d));for(let w of $)m.paths.push(...w.paths),m.printfData.push(...w.printfData)}return m}let T=await d({path:l,depth:0,resultIndex:0});h.paths.push(...T.paths),h.printfData.push(...T.printfData)}return h}let k=await x();E.push(...k.paths),Y.push(...k.printfData)}let N="";if(p.length>0)for(let o of p)switch(o.type){case"print":N+=E.length>0?`${E.join(`
5
- `)}
6
- `:"";break;case"print0":N+=E.length>0?`${E.join("\0")}\0`:"";break;case"delete":{let l=[...E].sort((I,b)=>b.length-I.length);for(let I of l){let b=s.fs.resolvePath(s.cwd,I);try{await s.fs.rm(b,{recursive:!1})}catch(x){let k=x instanceof Error?x.message:String(x);A+=`find: cannot delete '${I}': ${k}
7
- `,C=1}}break}case"printf":for(let l of Y)N+=re(o.format,l);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
8
- `,exitCode:1};if(o.batchMode){let l=[];for(let x of o.command)x==="{}"?l.push(...E):l.push(x);let I=l.map(x=>`"${x}"`).join(" "),b=await s.exec(I,{cwd:s.cwd});N+=b.stdout,A+=b.stderr,b.exitCode!==0&&(C=b.exitCode)}else for(let l of E){let b=o.command.map(k=>k==="{}"?l:k).map(k=>`"${k}"`).join(" "),x=await s.exec(b,{cwd:s.cwd});N+=x.stdout,A+=x.stderr,x.exitCode!==0&&(C=x.exitCode)}break}else W&&(N=E.length>0?`${E.join(`
9
- `)}
10
- `:"");return{stdout:N,stderr:A,exitCode:C}}};function re(e,s){let n=q(e),r="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){r+="%",t++;continue}let[D,a,i]=U(n,t);if(t+=i,t>=n.length){r+="%";break}let c=n[t],p;switch(c){case"f":p=s.name,t++;break;case"h":{let u=s.path.lastIndexOf("/");p=u>0?s.path.slice(0,u):".",t++;break}case"p":p=s.path,t++;break;case"P":{let u=s.startingPoint;s.path===u?p="":s.path.startsWith(`${u}/`)?p=s.path.slice(u.length+1):u==="."&&s.path.startsWith("./")?p=s.path.slice(2):p=s.path,t++;break}case"s":p=String(s.size),t++;break;case"d":p=String(s.depth),t++;break;case"m":p=(s.mode&511).toString(8),t++;break;case"M":p=ie(s.mode,s.isDirectory),t++;break;case"t":{let u=new Date(s.mtime);p=ae(u),t++;break}case"T":{if(t+1<n.length){let u=n[t+1],W=new Date(s.mtime);p=pe(W,u),t+=2}else p="%T",t++;break}default:r+=`%${D!==0||a!==-1?`${D}.${a}`:""}${c}`,t++;continue}r+=J(p,D,a)}else r+=n[t],t++;return r}function ie(e,s){let n=e&511,r=s?"d":"-";return r+=n&256?"r":"-",r+=n&128?"w":"-",r+=n&64?"x":"-",r+=n&32?"r":"-",r+=n&16?"w":"-",r+=n&8?"x":"-",r+=n&4?"r":"-",r+=n&2?"w":"-",r+=n&1?"x":"-",r}function ae(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],r=s[e.getDay()],t=n[e.getMonth()],D=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),i=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),p=e.getFullYear();return`${r} ${t} ${D} ${a}:${i}:${c} ${p}`}function pe(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{ge as findCommand};