just-bash 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +47 -0
- package/dist/ast/types.d.ts +4 -1
- package/dist/bin/chunks/{chunk-QF7PPON7.js → chunk-5SR55TXB.js} +10 -10
- package/dist/bin/{shell/chunks/chunk-TL4JI2SL.js → chunks/chunk-6UK23ZFT.js} +17 -18
- package/dist/bin/chunks/{chunk-XBB73LFB.js → chunk-CMTQFWZK.js} +2 -2
- package/dist/bin/chunks/{chunk-YMELOXDK.js → chunk-D5G3L4PR.js} +8 -8
- package/dist/bin/chunks/{chunk-PRKSLEHG.js → chunk-DKIOFM35.js} +1 -1
- package/dist/bin/chunks/chunk-IJIJAQBT.js +12 -0
- package/dist/bin/{shell/chunks/chunk-NQQ3X7MZ.js → chunks/chunk-KXWWWQZK.js} +1 -1
- package/dist/bin/chunks/{chunk-3HUI54BW.js → chunk-TROO33BG.js} +1 -1
- package/dist/bin/chunks/chunk-USMDLXMM.js +21 -0
- package/dist/bin/{shell/chunks/chunk-JQER3HUP.js → chunks/chunk-XAVWLYZR.js} +1 -1
- package/dist/bin/chunks/{echo-4OUEL7QB.js → echo-NYDCCFWB.js} +1 -1
- package/dist/bin/chunks/{flag-coverage-WGSE667D.js → flag-coverage-EB3DK32J.js} +1 -1
- package/dist/bin/chunks/{grep-CMT2H2S7.js → grep-73YHJEX4.js} +1 -1
- package/dist/bin/{shell/chunks/jq-ACCMBTSD.js → chunks/jq-AO5GTPN4.js} +1 -1
- package/dist/bin/chunks/js-exec-worker.js +56 -20
- package/dist/bin/{shell/chunks/printf-F2KOCULO.js → chunks/printf-CNXNRQ3I.js} +1 -1
- package/dist/bin/chunks/python3-N252MJV6.js +14 -0
- package/dist/bin/{shell/chunks/rg-JRKJ6I4X.js → chunks/rg-OGGL3RIE.js} +1 -1
- package/dist/bin/chunks/{sqlite3-ZXF6BGDW.js → sqlite3-FEUFATVW.js} +1 -1
- package/dist/bin/chunks/worker.js +17 -1
- package/dist/bin/chunks/{xan-D6US4ZGL.js → xan-Q52EBQYW.js} +1 -1
- package/dist/bin/chunks/{yq-EYV7HLKK.js → yq-UA5NX5RT.js} +1 -1
- package/dist/bin/just-bash.js +391 -389
- package/dist/bin/shell/chunks/{chunk-QF7PPON7.js → chunk-5SR55TXB.js} +10 -10
- package/dist/bin/{chunks/chunk-TL4JI2SL.js → shell/chunks/chunk-6UK23ZFT.js} +17 -18
- package/dist/bin/shell/chunks/{chunk-XBB73LFB.js → chunk-CMTQFWZK.js} +2 -2
- package/dist/bin/shell/chunks/{chunk-YMELOXDK.js → chunk-D5G3L4PR.js} +8 -8
- package/dist/bin/shell/chunks/{chunk-PRKSLEHG.js → chunk-DKIOFM35.js} +1 -1
- package/dist/bin/shell/chunks/chunk-IJIJAQBT.js +12 -0
- package/dist/bin/{chunks/chunk-NQQ3X7MZ.js → shell/chunks/chunk-KXWWWQZK.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-3HUI54BW.js → chunk-TROO33BG.js} +1 -1
- package/dist/bin/shell/chunks/chunk-USMDLXMM.js +21 -0
- package/dist/bin/{chunks/chunk-JQER3HUP.js → shell/chunks/chunk-XAVWLYZR.js} +1 -1
- package/dist/bin/shell/chunks/{echo-4OUEL7QB.js → echo-NYDCCFWB.js} +1 -1
- package/dist/bin/shell/chunks/{flag-coverage-WGSE667D.js → flag-coverage-EB3DK32J.js} +1 -1
- package/dist/bin/shell/chunks/{grep-CMT2H2S7.js → grep-73YHJEX4.js} +1 -1
- package/dist/bin/{chunks/jq-ACCMBTSD.js → shell/chunks/jq-AO5GTPN4.js} +1 -1
- package/dist/bin/{chunks/printf-F2KOCULO.js → shell/chunks/printf-CNXNRQ3I.js} +1 -1
- package/dist/bin/shell/chunks/python3-N252MJV6.js +14 -0
- package/dist/bin/{chunks/rg-JRKJ6I4X.js → shell/chunks/rg-OGGL3RIE.js} +1 -1
- package/dist/bin/shell/chunks/{sqlite3-ZXF6BGDW.js → sqlite3-FEUFATVW.js} +1 -1
- package/dist/bin/shell/chunks/{xan-D6US4ZGL.js → xan-Q52EBQYW.js} +1 -1
- package/dist/bin/shell/chunks/{yq-EYV7HLKK.js → yq-UA5NX5RT.js} +1 -1
- package/dist/bin/shell/shell.js +396 -394
- package/dist/bundle/browser.js +836 -823
- package/dist/bundle/chunks/{chunk-RAHPENCM.js → chunk-3ZBJCAAR.js} +1 -1
- package/dist/bundle/chunks/{chunk-AMLHAS2N.js → chunk-4AKAIZPW.js} +9 -9
- package/dist/bundle/chunks/{chunk-6SHYIICL.js → chunk-AGH5UJJI.js} +2 -2
- package/dist/bundle/chunks/{chunk-NOPXHH6G.js → chunk-EZDB7TGH.js} +1 -1
- package/dist/bundle/chunks/chunk-FC5NW7U4.js +11 -0
- package/dist/bundle/chunks/{chunk-5KGKXQF6.js → chunk-FHFPWM4W.js} +1 -1
- package/dist/bundle/chunks/chunk-H3PXMIY3.js +20 -0
- package/dist/bundle/chunks/{chunk-EWWPEE2G.js → chunk-IHGFM3FN.js} +17 -18
- package/dist/bundle/chunks/{chunk-65Z4QURM.js → chunk-J5G3ZBEK.js} +8 -8
- package/dist/bundle/chunks/{chunk-WENIVVEE.js → chunk-LTCWFMCI.js} +1 -1
- package/dist/bundle/chunks/{echo-HZOVZAPR.js → echo-PLLZYM2L.js} +1 -1
- package/dist/bundle/chunks/{flag-coverage-THYQHOT3.js → flag-coverage-UV7GI2DF.js} +1 -1
- package/dist/bundle/chunks/{grep-S6SNTIHZ.js → grep-UDCQDUQK.js} +1 -1
- package/dist/bundle/chunks/{jq-D6N4QCAJ.js → jq-B5324QOX.js} +1 -1
- package/dist/bundle/chunks/js-exec-worker.js +56 -20
- package/dist/bundle/chunks/{printf-QHD2JRWQ.js → printf-V42QCPHL.js} +1 -1
- package/dist/bundle/chunks/python3-ETPBGJP3.js +13 -0
- package/dist/bundle/chunks/{rg-OUJZ5DH6.js → rg-XCX2J2RF.js} +1 -1
- package/dist/bundle/chunks/{sqlite3-WWZJZW37.js → sqlite3-ZTQJIC3G.js} +1 -1
- package/dist/bundle/chunks/worker.js +17 -1
- package/dist/bundle/chunks/{xan-KKPV2TJ3.js → xan-EGU5VRRP.js} +1 -1
- package/dist/bundle/chunks/{yq-ZGB3W46S.js → yq-FMWLA3S2.js} +1 -1
- package/dist/bundle/index.cjs +1026 -1014
- package/dist/bundle/index.js +391 -389
- package/dist/commands/python3/worker.d.ts +1 -0
- package/dist/commands/query-engine/evaluator.d.ts +8 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +42 -1
- package/dist/interpreter/builtin-dispatch.d.ts +9 -2
- package/dist/interpreter/builtins/eval.d.ts +7 -1
- package/dist/interpreter/control-flow.d.ts +1 -1
- package/dist/interpreter/fd-table.d.ts +130 -0
- package/dist/interpreter/functions.d.ts +3 -1
- package/dist/interpreter/helpers/word-matching.d.ts +0 -10
- package/dist/interpreter/interpreter.d.ts +7 -0
- package/dist/interpreter/numeric-fd-redirects.d.ts +8 -0
- package/dist/interpreter/process-substitution.d.ts +62 -0
- package/dist/interpreter/redirections.d.ts +33 -37
- package/dist/interpreter/subshell-group.d.ts +10 -2
- package/dist/interpreter/types.d.ts +38 -1
- package/dist/network/dns-pin.d.ts +11 -0
- package/dist/parser/expansion-parser.d.ts +3 -1
- package/dist/parser/lexer.d.ts +7 -9
- package/dist/parser/parser-substitution.d.ts +13 -4
- package/dist/parser/parser.d.ts +18 -4
- package/dist/parser/types.d.ts +6 -0
- package/dist/parser/word-parser.d.ts +2 -0
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
- package/dist/bin/chunks/chunk-P6NPCASY.js +0 -11
- package/dist/bin/chunks/chunk-WYTPLN2M.js +0 -11
- package/dist/bin/chunks/python3-AYUQQRCR.js +0 -14
- package/dist/bin/shell/chunks/chunk-P6NPCASY.js +0 -11
- package/dist/bin/shell/chunks/chunk-WYTPLN2M.js +0 -11
- package/dist/bin/shell/chunks/python3-AYUQQRCR.js +0 -14
- package/dist/bundle/chunks/chunk-VECGTAPW.js +0 -10
- package/dist/bundle/chunks/chunk-YOUUMJLJ.js +0 -10
- package/dist/bundle/chunks/python3-QDNG2UXX.js +0 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a as $,b as F,c as b,d as j,e as Ze,f as et,g as C,h as tt,i as nt,j as k,k as ie,l as ae}from"./chunk-VTAIIBJT.js";import{b as V,d as Qe}from"./chunk-
|
|
3
|
+
import{a as $,b as F,c as b,d as j,e as Ze,f as et,g as C,h as tt,i as nt,j as k,k as ie,l as ae}from"./chunk-VTAIIBJT.js";import{b as V,d as Qe}from"./chunk-D5G3L4PR.js";import{d as Ge,f as Xe,g as oe}from"./chunk-WDV2ECOC.js";import{a as Z}from"./chunk-CB4SODHK.js";import{b as Ye}from"./chunk-O74FSWB4.js";import{a as q}from"./chunk-BNYIXXC2.js";import{a as W,c as se,d as re}from"./chunk-CPTQXTBJ.js";import{l as E}from"./chunk-LCP3IKI7.js";import{a as K,b as Y}from"./chunk-CPKBPQ2C.js";import{a as J,b as ne}from"./chunk-MUFNRCMY.js";var G=class{input;pos=0;tokens=[];maxSourceLength;maxTokens;constructor(t,n={}){this.input=t,this.maxSourceLength=n.maxSourceLength??1024*1024,this.maxTokens=n.maxTokens??1e5}tokenize(){if(this.input.length>this.maxSourceLength)throw new E(`xan: expression length limit exceeded (${this.maxSourceLength})`,"string_length");for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let t=this.nextToken();t&&(this.assertTokenCapacity(),this.tokens.push(t))}return this.assertTokenCapacity(),this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}assertTokenCapacity(){if(this.tokens.length>=this.maxTokens)throw new E(`xan: expression token limit exceeded (${this.maxTokens})`,"array_elements")}skipWhitespace(){for(;this.pos<this.input.length;){let t=this.input[this.pos];if(t===" "||t===" "||t===`
|
|
4
4
|
`||t==="\r")this.pos++;else if(t==="#")for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
5
5
|
`;)this.pos++;else break}}nextToken(){let t=this.pos,n=this.input[this.pos];if(n>="0"&&n<="9")return this.readNumber();if(n==='"'||n==="'"||n==="`")return this.readString(n);if(n==="b"&&this.pos+1<this.input.length){let o=this.input[this.pos+1];if(o==='"'||o==="'"||o==="`")return this.pos++,this.readString(o)}if(n==="/"){let o=this.tokens[this.tokens.length-1];return o&&(o.type==="int"||o.type==="float"||o.type==="string"||o.type==="ident"||o.type===")"||o.type==="]")?this.input[this.pos+1]==="/"?(this.pos+=2,{type:"//",value:"//",pos:t}):(this.pos++,{type:"/",value:"/",pos:t}):this.readRegex()}if(this.match("not in"))return{type:"not in",value:"not in",pos:t};if(this.match("=>"))return{type:"=>",value:"=>",pos:t};if(this.match("**"))return{type:"**",value:"**",pos:t};if(this.match("++"))return{type:"++",value:"++",pos:t};if(this.match("//"))return{type:"//",value:"//",pos:t};if(this.match("=="))return{type:"==",value:"==",pos:t};if(this.match("!="))return{type:"!=",value:"!=",pos:t};if(this.match("<="))return{type:"<=",value:"<=",pos:t};if(this.match(">="))return{type:">=",value:">=",pos:t};if(this.match("&&"))return{type:"&&",value:"&&",pos:t};if(this.match("||"))return{type:"||",value:"||",pos:t};let r=new Map([["(","("],[")",")"],["[","["],["]","]"],["{","{"],["}","}"],[",",","],[":",":"],[";",";"],["+","+"],["-","-"],["*","*"],["%","%"],["<","<"],[">",">"],["!","!"],[".","."],["|","|"],["=","="]]).get(n);if(r!==void 0)return this.pos++,{type:r,value:n,pos:t};if(this.isIdentStart(n))return this.readIdentifier();throw new Error(`Unexpected character '${n}' at position ${this.pos}`)}match(t){if(this.input.slice(this.pos,this.pos+t.length)===t){if(/^[a-zA-Z]/.test(t)){let n=this.input[this.pos+t.length];if(n&&this.isIdentChar(n))return!1}return this.pos+=t.length,!0}return!1}isIdentStart(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"}isIdentChar(t){return this.isIdentStart(t)||t>="0"&&t<="9"}readNumber(){let t=this.pos,n=!1,s=!1;for(;this.pos<this.input.length;){let o=this.input[this.pos];if(o>="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!n&&!s)n=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,n=!0,this.pos++,this.pos<this.input.length&&(this.input[this.pos]==="+"||this.input[this.pos]==="-")&&this.pos++;else break}let r=this.input.slice(t,this.pos).replace(/_/g,"");return{type:n?"float":"int",value:r,pos:t}}readString(t){let n=this.pos;this.pos++;let s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r===t)return this.pos++,{type:"string",value:s,pos:n};if(r==="\\"){if(this.pos++,this.pos<this.input.length){let o=this.input[this.pos];switch(o){case"n":s+=`
|
|
6
6
|
`;break;case"r":s+="\r";break;case"t":s+=" ";break;case"\\":s+="\\";break;case'"':s+='"';break;case"'":s+="'";break;case"`":s+="`";break;case"0":s+="\0";break;default:s+=o}this.pos++}}else s+=r,this.pos++}throw new Error(`Unterminated string starting at position ${n}`)}readRegex(){let t=this.pos;this.pos++;let n="",s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r==="/"){for(this.pos++;this.pos<this.input.length&&this.input[this.pos]==="i";)s+=this.input[this.pos],this.pos++;return{type:"regex",value:n+(s?`/${s}`:""),pos:t}}r==="\\"?(n+=r,this.pos++,this.pos<this.input.length&&(n+=this.input[this.pos],this.pos++)):(n+=r,this.pos++)}throw new Error(`Unterminated regex starting at position ${t}`)}readIdentifier(){let t=this.pos;for(;this.pos<this.input.length&&this.isIdentChar(this.input[this.pos]);)this.pos++;let n=!1;this.pos<this.input.length&&this.input[this.pos]==="?"&&(n=!0,this.pos++);let s=this.input.slice(t,n?this.pos-1:this.pos);n&&(s+="?");let r=new Map([["true","true"],["false","false"],["null","null"],["and","and"],["or","or"],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["in","in"],["as","as"],["_","_"]]),o=s.replace(/\?$/,""),i=r.get(o);return i!==void 0&&!n?{type:i,value:o,pos:t}:{type:"ident",value:s,pos:t}}};function z(e){return{maxSourceLength:e.limits.maxStringLength,maxTokens:e.limits.maxQueryTokens,maxAstNodes:e.limits.maxQueryElements,maxOperations:e.limits.maxJqIterations,maxDepth:e.limits.maxQueryDepth}}var D={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},ee=class{pos=0;tokens;depth=0;operations=0;astNodes=0;limits;constructor(t,n={}){this.tokens=t,this.limits={maxSourceLength:n.maxSourceLength??1024*1024,maxTokens:n.maxTokens??1e5,maxDepth:n.maxDepth??100,maxOperations:n.maxOperations??1e5,maxAstNodes:n.maxAstNodes??1e5};let s=0;for(let r of t)this.useOperation(),r.type==="("||r.type==="["||r.type==="{"?(s++,s>this.limits.maxDepth&&this.throwDepthLimit()):(r.type===")"||r.type==="]"||r.type==="}")&&(s=Math.max(0,s-1))}parse(){let t=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return t}parseExpr(t){return this.withDepth(()=>this.parseExprInner(t))}parseExprInner(t){let n=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r<t)break;n=this.parseInfix(n,r)}return n}useOperation(t=1){if(t>this.limits.maxOperations-this.operations)throw new E(`xan: expression parser operation limit exceeded (${this.limits.maxOperations})`,"iterations");this.operations+=t}withDepth(t){this.depth>=this.limits.maxDepth&&this.throwDepthLimit(),this.depth++;try{return t()}finally{this.depth--}}throwDepthLimit(){throw new E(`xan: expression parser depth limit exceeded (${this.limits.maxDepth})`,"recursion")}addAstNode(){if(this.astNodes>=this.limits.maxAstNodes)throw new E(`xan: expression AST node limit exceeded (${this.limits.maxAstNodes})`,"array_elements");this.astNodes++}parsePrefix(){let t=this.peek();switch(t.type){case"int":return this.advance(),{type:"int",value:Number.parseInt(t.value,10)};case"float":return this.advance(),{type:"float",value:Number.parseFloat(t.value)};case"string":return this.advance(),{type:"string",value:t.value};case"regex":{this.advance();let n=t.value.split("/"),s=n.length>1?n[n.length-1]:"";return{type:"regex",pattern:n.slice(0,-1).join("/")||t.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let n=t.value,s=n.endsWith("?"),r=s?n.slice(0,-1):n;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let n=this.pos;if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=[this.peek().value];this.advance();let o=!0;for(;this.peek().type===",";)if(this.advance(),this.peek().type==="ident")r.push(this.peek().value),this.advance();else{o=!1;break}if(o&&this.peek().type===")"&&this.peekAt(1).type==="=>"){this.advance(),this.advance();let i=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:r,body:i},r)}this.pos=n}let s=this.parseExpr(0);return this.expect(")"),s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let n=this.parseExpr(D.UNARY);return n.type==="int"?{type:"int",value:-n.value}:n.type==="float"?{type:"float",value:-n.value}:{type:"func",name:"neg",args:[{expr:n}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(D.UNARY)}]};default:throw new Error(`Unexpected token: ${t.type} (${t.value})`)}}parseFunctionCall(t){this.expect("(");let n=[];if(this.peek().type!==")")do{n.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,i=this.pos+1;i<this.tokens.length&&this.tokens[i].type==="="&&(s=o,this.advance(),this.advance())}let r=this.parseExpr(0);n.push({name:s,expr:r})}while(this.peek().type===",");return this.expect(")"),{type:"func",name:t.toLowerCase(),args:n}}parseList(){this.expect("[");let t=[];if(this.peek().type!=="]")do t.length>0&&this.peek().type===","&&this.advance(),t.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:t}}parseMap(){this.expect("{");let t=[];if(this.peek().type!=="}")do{t.length>0&&this.peek().type===","&&this.advance();let n;if(this.peek().type==="ident")n=this.peek().value,this.advance();else if(this.peek().type==="string")n=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);t.push({key:n,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:t}}parseInfix(t,n){let s=this.peek(),o=new Map([["+","add"],["-","sub"],["*","mul"],["/","div"],["//","idiv"],["%","mod"],["**","pow"],["++","concat"],["==","=="],["!=","!="],["<","<"],["<=","<="],[">",">"],[">=",">="],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["&&","and"],["and","and"],["||","or"],["or","or"]]).get(s.type);if(o!==void 0){this.advance();let i=this.parseExpr(n+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:o,args:[{expr:t},{expr:i}]}}if(s.type==="|"){this.advance();let i=this.parseExpr(n);return this.handlePipe(t,i)}if(s.type===".")return this.advance(),this.handleDot(t);if(s.type==="[")return this.advance(),this.handleIndexing(t);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(n+1)},{expr:t}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(n+1)},{expr:t}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(t,n){if(n.type==="identifier")return{type:"func",name:n.name,args:[{expr:t}]};if(n.type==="func"){let s=this.countUnderscores(n);return s===0?n:s===1?this.fillUnderscore(n,t):{type:"pipeline",exprs:[t,n]}}return this.countUnderscores(n)===1?this.fillUnderscore(n,t):n}handleDot(t){let n=this.peek();if(n.type==="ident"){let s=n.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:t}),r}return{type:"func",name:"get",args:[{expr:t},{expr:{type:"string",value:s}}]}}if(n.type==="int"){let s=Number.parseInt(n.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:t},{expr:{type:"int",value:s}}]}}if(n.type==="string"){let s=n.value;return this.advance(),{type:"func",name:"get",args:[{expr:t},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${n.type}`)}handleIndexing(t){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:t},{expr:{type:"int",value:0}},{expr:s}]}}let n=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:t},{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:t},{expr:n},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:t},{expr:n}]}}countUnderscores(t){let n=[t],s=0;for(;n.length>0;){this.useOperation();let r=n.pop();if(!r)break;if(r.type==="underscore")s++;else if(r.type==="func")for(let o of r.args)n.push(o.expr);else if(r.type==="list")n.push(...r.elements);else if(r.type==="map")for(let o of r.entries)n.push(o.value);if(n.length>this.limits.maxAstNodes)throw new E(`xan: expression AST node limit exceeded (${this.limits.maxAstNodes})`,"array_elements")}return s}fillUnderscore(t,n){return this.withDepth(()=>this.fillUnderscoreInner(t,n))}fillUnderscoreInner(t,n){return this.useOperation(),t.type==="underscore"?n:t.type==="func"?{...t,args:t.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,n)}))}:t.type==="list"?{...t,elements:t.elements.map(s=>this.fillUnderscore(s,n))}:t.type==="map"?{...t,entries:t.entries.map(s=>({...s,value:this.fillUnderscore(s.value,n)}))}:t}bindLambdaArgs(t,n){return{...t,body:this.bindLambdaArgsInExpr(t.body,n)}}bindLambdaArgsInExpr(t,n){return this.withDepth(()=>this.bindLambdaArgsInExprInner(t,n))}bindLambdaArgsInExprInner(t,n){return this.useOperation(),t.type==="identifier"&&n.includes(t.name)?{type:"lambdaBinding",name:t.name}:t.type==="func"?{...t,args:t.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,n)}))}:t.type==="list"?{...t,elements:t.elements.map(s=>this.bindLambdaArgsInExpr(s,n))}:t.type==="map"?{...t,entries:t.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,n)}))}:t}getInfixPrec(t){switch(t){case"|":return D.PIPE;case"||":case"or":return D.OR;case"&&":case"and":return D.AND;case"==":case"!=":case"eq":case"ne":return D.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return D.COMPARISON;case"+":case"-":case"++":return D.ADDITIVE;case"*":case"/":case"//":case"%":return D.MULTIPLICATIVE;case"**":return D.POWER;case".":case"[":return D.POSTFIX;default:return-1}}isRightAssoc(t){return t==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}peekAt(t){return this.tokens[this.pos+t]||{type:"eof",value:"",pos:0}}advance(){return this.useOperation(),this.addAstNode(),this.tokens[this.pos++]}expect(t){let n=this.peek();if(n.type!==t)throw new Error(`Expected ${t}, got ${n.type}`);return this.advance()}};function X(e,t={}){let n=[],r=new G(e,{maxSourceLength:t.maxSourceLength,maxTokens:t.maxTokens}).tokenize(),o=0,i=()=>r[o]||{type:"eof",value:"",pos:0},p=()=>r[o++];for(;i().type!=="eof";){if(i().type===","&&n.length>0){p();continue}let h=[],m=0,c=o;for(;i().type!=="eof";){let l=i();if((l.type===","||l.type==="as")&&m===0)break;(l.type==="("||l.type==="["||l.type==="{")&&m++,(l.type===")"||l.type==="]"||l.type==="}")&&m--,h.push(p())}h.push({type:"eof",value:"",pos:0});let d=new ee(h,t).parse(),u;if(i().type==="as")if(p(),i().type==="("){p();let l=[];for(;i().type!==")"&&i().type!=="eof";)if((i().type==="ident"||i().type==="string")&&(l.push(i().value),p()),i().type===",")p();else if(i().type!==")"&&i().type!=="eof")throw new Error(`Expected tuple alias, got ${i().type}`);if(i().type!==")")throw new Error("Expected ')' after tuple alias");p(),u=l}else if(i().type==="ident"||i().type==="string")u=i().value,p();else throw new Error(`Expected name after 'as', got ${i().type}`);else u=e.slice(r[c].pos,r[o-1]?.pos||e.length).trim(),d.type==="identifier"&&(u=d.name);n.push({expr:d,name:u})}return n}function B(e,t={}){let s=new G(e,{maxSourceLength:t.maxSourceLength,maxTokens:t.maxTokens}).tokenize();return new ee(s,t).parse()}function R(e,t){return t.length===0?O(e,[]):t.length===1?{type:"Pipe",left:t[0],right:O(e,[])}:{type:"Pipe",left:t[0],right:O(e,t.slice(1))}}var le={add:e=>L("+",e[0],e[1]),sub:e=>L("-",e[0],e[1]),mul:e=>L("*",e[0],e[1]),div:e=>L("/",e[0],e[1]),mod:e=>L("%",e[0],e[1]),idiv:e=>O("floor",[L("/",e[0],e[1])]),pow:e=>R("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>L("==",e[0],e[1]),"!=":e=>L("!=",e[0],e[1]),"<":e=>L("<",e[0],e[1]),"<=":e=>L("<=",e[0],e[1]),">":e=>L(">",e[0],e[1]),">=":e=>L(">=",e[0],e[1]),eq:e=>L("==",M(e[0]),M(e[1])),ne:e=>L("!=",M(e[0]),M(e[1])),lt:e=>L("<",M(e[0]),M(e[1])),le:e=>L("<=",M(e[0]),M(e[1])),gt:e=>L(">",M(e[0]),M(e[1])),ge:e=>L(">=",M(e[0]),M(e[1])),and:e=>L("and",e[0],e[1]),or:e=>L("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>R("length",e),length:e=>R("length",e),upper:e=>R("ascii_upcase",e),lower:e=>R("ascii_downcase",e),trim:e=>R("trim",e),ltrim:e=>e.length===0?O("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:O("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?O("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:O("rtrimstr",[{type:"Literal",value:" "}])},split:e=>R("split",e),join:e=>e.length===1?O("join",[{type:"Literal",value:""}]):R("join",e),concat:e=>L("+",e[0],e[1]),startswith:e=>R("startswith",e),endswith:e=>R("endswith",e),contains:e=>R("contains",e),replace:e=>R("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:L("+",e[1],e[2])},abs:e=>R("fabs",e),floor:e=>R("floor",e),ceil:e=>R("ceil",e),round:e=>R("round",e),sqrt:e=>R("sqrt",e),log:e=>R("log",e),log10:e=>R("log10",e),log2:e=>R("log2",e),exp:e=>R("exp",e),sin:e=>R("sin",e),cos:e=>R("cos",e),tan:e=>R("tan",e),asin:e=>R("asin",e),acos:e=>R("acos",e),atan:e=>R("atan",e),min:e=>R("min",e),max:e=>R("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>O("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>O("select",e),empty:()=>O("empty",[]),count:()=>O("length",[]),sum:e=>e.length===0?O("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:O("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:L("/",O("add",[]),O("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:L("/",O("add",[]),O("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:L("/",O("add",[]),O("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:L("/",O("add",[]),O("length",[]))},type:"type",isnull:e=>e.length===0?L("==",{type:"Identity"},{type:"Literal",value:null}):L("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?L("==",{type:"Identity"},{type:"Literal",value:""}):L("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?O("tonumber",[]):O("tonumber",e),tostring:e=>e.length===0?O("tostring",[]):O("tostring",e),if:e=>st(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let t=e[e.length-1];for(let n=e.length-2;n>=0;n--){let s=e[n],r=L("and",L("!=",s,{type:"Literal",value:null}),L("!=",s,{type:"Literal",value:""}));t=st(r,s,t)}return t},index:()=>({type:"Field",name:"_row_index"}),now:()=>O("now",[]),fmt:e=>O("tostring",e),format:e=>O("tostring",e)};Object.setPrototypeOf(le,null);function L(e,t,n){return{type:"BinaryOp",op:e,left:t,right:n}}function O(e,t){return{type:"Call",name:e,args:t}}var mt="then";function st(e,t,n){let s=Xe({type:"Cond",cond:e,elifs:[],else:n||{type:"Literal",value:null}});return s[mt]=t,s}function M(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function U(e,t=!0,n={}){let s={nodes:0,operations:0,maxNodes:n.maxAstNodes??1e5,maxOperations:n.maxOperations??1e5,maxDepth:n.maxDepth??100};return rt(e,t,s,0)}function rt(e,t,n,s){if(s>=n.maxDepth)throw new E(`xan: expression conversion depth limit exceeded (${n.maxDepth})`,"recursion");if(++n.nodes>n.maxNodes)throw new E(`xan: expression conversion AST limit exceeded (${n.maxNodes})`,"array_elements");if(++n.operations>n.maxOperations)throw new E(`xan: expression conversion operation limit exceeded (${n.maxOperations})`,"iterations");let r=o=>rt(o,t,n,s+1);switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return t?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{if(e.args.length>n.maxNodes-n.nodes)throw new E(`xan: expression conversion AST limit exceeded (${n.maxNodes})`,"array_elements");let o=e.args.map(p=>r(p.expr));if(e.name==="coalesce"){let p=Math.max(0,o.length-1)*7;if(p>n.maxNodes-n.nodes)throw new E(`xan: expression conversion AST limit exceeded (${n.maxNodes})`,"array_elements");if(n.nodes+=p,n.operations+=o.length,n.operations>n.maxOperations)throw new E(`xan: expression conversion operation limit exceeded (${n.maxOperations})`,"iterations")}let i=Object.hasOwn(le,e.name)?le[e.name]:void 0;return typeof i=="function"?i(o):O(typeof i=="string"?i:e.name,o)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((o,i,p)=>{let h=r(i);return p===0?h:{type:"Comma",left:o,right:h}},null)};case"map":return{type:"Object",entries:e.entries.map(o=>({key:o.key,value:r(o.value)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?r(e.start):void 0,end:e.end?r(e.end):void 0};case"lambda":return r(e.body);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function Q(e){return e<2?0:Math.ceil(e*Math.log2(e))}function ue(e,t={}){let n=t.maxArrayElements??1e5,s=t.maxStringLength??10*1024*1024,r=t.maxIterations??1e5,o=t.maxDepth??100;if(K(e)>s)throw new E(`xan: aggregation expression length limit exceeded (${s} bytes)`,"string_length");let i=[],p=0,h=0,m=()=>{if(t.consumeWork?.(),++h>r)throw new E(`xan: aggregation parser operation limit exceeded (${r})`,"iterations")};for(;p<e.length;){for(m();p<e.length&&(e[p]===" "||e[p]===",");)p++;if(p>=e.length)break;let c=p;for(;p<e.length&&/\w/.test(e[p]);)p++;let a=e.slice(c,p);for(;p<e.length&&e[p]===" ";)p++;if(e[p]!=="(")break;p++;let d=1,u=p;for(;p<e.length&&d>0;){if(m(),e[p]==="("?d++:e[p]===")"&&d--,d>o)throw new E(`xan: aggregation parser depth limit exceeded (${o})`,"recursion");d>0&&p++}let l=e.slice(u,p).trim();for(p++;p<e.length&&e[p]===" ";)p++;let f="";if(e.slice(p,p+3).toLowerCase()==="as "){for(p+=3;p<e.length&&e[p]===" ";)p++;let x=p;for(;p<e.length&&/\w/.test(e[p]);)p++;f=e.slice(x,p)}if(f||(f=l?`${a}(${l})`:`${a}()`),i.length>=n)throw new E(`xan: aggregation specification limit exceeded (${n})`,"array_elements");i.push({func:a,expr:l,alias:f})}return i}function ft(e){return/^\w+$/.test(e)}function ht(e,t,n){let s=V(e,t,n);return s.length>0?s[0]:null}function ce(e,t,n={},s={}){let{func:r,expr:o}=t,i=s.maxArrayElements??1e5,p=s.maxStringLength??10*1024*1024,h=s.maxIterations??1e5,m={maxSourceLength:p,maxTokens:i,maxAstNodes:i,maxOperations:h,maxDepth:s.maxDepth??100};if(e.length>i)throw new E(`xan: aggregation input limit exceeded (${i})`,"array_elements");if(r==="count"&&!o)return e.length;let c=ft(o),a=c?null:U(B(o,m),!0,m),d;if(c)d=f=>f[o];else{if(a===null)throw new Error("xan: missing compiled aggregation expression");d=f=>ht(f,a,n)}if(r==="all"||r==="any"){let f=0;for(let x of e){if(s.consumeWork?.(),++f>h)throw new E(`xan: aggregation iteration limit exceeded (${h})`,"iterations");let g=!!d(x);if(r==="all"&&!g)return!1;if(r==="any"&&g)return!0}return r==="all"}let u=[],l=0;for(let f of e){if(s.consumeWork?.(),++l>h)throw new E(`xan: aggregation iteration limit exceeded (${h})`,"iterations");let x=d(f);if(x!=null){if(u.length>=i)throw new E(`xan: aggregation value limit exceeded (${i})`,"array_elements");u.push(x)}}switch(r){case"count":{if(c)return u.length;let f=0;for(let x of u)s.consumeWork?.(),x&&f++;return f}case"sum":{let f=0;for(let x of u)s.consumeWork?.(),f+=typeof x=="number"?x:Number.parseFloat(String(x));return f}case"mean":case"avg":{let f=0;for(let x of u)s.consumeWork?.(),f+=typeof x=="number"?x:Number.parseFloat(String(x));return u.length>0?f/u.length:0}case"min":{let f=null;for(let x of u){s.consumeWork?.();let g=typeof x=="number"?x:Number.parseFloat(String(x));f=f===null?g:Math.min(f,g)}return f}case"max":{let f=null;for(let x of u){s.consumeWork?.();let g=typeof x=="number"?x:Number.parseFloat(String(x));f=f===null?g:Math.max(f,g)}return f}case"first":return u.length>0?u[0]:null;case"last":return u.length>0?u[u.length-1]:null;case"median":{let f=[];for(let g of u){s.consumeWork?.();let y=typeof g=="number"?g:Number.parseFloat(String(g));Number.isNaN(y)||f.push(y)}if(s.consumeWork?.(Q(f.length)),f.sort((g,y)=>g-y),f.length===0)return null;let x=Math.floor(f.length/2);return f.length%2===0?(f[x-1]+f[x])/2:f[x]}case"mode":{let f=new Map;for(let y of u){s.consumeWork?.();let w=String(y);f.set(w,(f.get(w)||0)+1)}let x=0,g=null;for(let[y,w]of f)s.consumeWork?.(),w>x&&(x=w,g=y);return g}case"cardinality":{let f=new Set;for(let x of u)s.consumeWork?.(),f.add(String(x));return f.size}case"values":return ot(u,!1,p,s);case"distinct_values":return ot(u,!0,p,s);default:return null}}function it(e,t,n={},s={}){let r=F();for(let o of t)b(r,o.alias,ce(e,o,n,s));return r}function ot(e,t,n,s){let r=[],o=t?new Set:null,i=0;for(let p of e){s.consumeWork?.();let h=String(p);if(o?.has(h))continue;o?.add(h);let m=K(h)+(r.length>0?1:0);if(m>n-i)throw new E(`xan: aggregation string limit exceeded (${n} bytes)`,"string_length");r.push(h),i+=m}return t&&(s.consumeWork?.(Q(r.length)),r.sort()),r.join("|")}function lt(e,t){return{maxArrayElements:e.limits.maxArrayElements,maxStringLength:e.limits.maxStringLength,maxIterations:e.limits.maxJqIterations,maxDepth:e.limits.maxQueryDepth,consumeWork:(n=1)=>t.consumeWork(n)}}function at(e,t,n){let s=e.size-(t&&e.has("")?1:0);return n>0?Math.min(s,n):s}async function pe(e,t){let n="",s=[];for(let d of e)d.startsWith("-")||(n?s.push(d):n=d);if(!n)return{stdout:"",stderr:`xan agg: no aggregation expression
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
+
import{a as C}from"./chunk-X5VUGFUL.js";import{a as se,b as re}from"./chunk-XAVWLYZR.js";import{a as O}from"./chunk-BNYIXXC2.js";import{l as A}from"./chunk-LCP3IKI7.js";import{b as j}from"./chunk-CPKBPQ2C.js";import{a as me,c as ne}from"./chunk-MUFNRCMY.js";var xe="(standard input)";function he(t){let e=t.limits.maxLoopIterations,i=t.limits.maxArrayElements;return Math.max(e,Math.min(i,e*10))}function w(t){if(++t.operations>t.maxOperations)throw new A(`grep: glob operation limit exceeded (${t.maxOperations})`,"glob_operations")}function _(t){if(t.results>=t.maxResults)throw new A(`grep: array element limit exceeded (${t.maxResults})`,"array_elements");t.results++}var we="[^\\s\\S]";function Fe(t){return t.split(`
|
|
4
|
+
`)}function ve(t){if(t==="")return[];let e=t.split(`
|
|
5
|
+
`);return e[e.length-1]===""&&e.pop(),e}function Ce(t,e){return t.length===1?{pattern:t[0],mode:e}:e==="fixed"?{pattern:t.map(i=>`(?:${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`).join("|"),mode:"extended"}:e==="basic"?{pattern:t.join("\\|"),mode:e}:{pattern:t.map(i=>`(?:${i})`).join("|"),mode:e}}var Ee={name:"grep",summary:"print lines that match patterns",usage:"grep [OPTION]... PATTERN [FILE]...",description:["Search for PATTERN in each FILE.","With no FILE, or when FILE is -, read standard input."],options:["-E, --extended-regexp PATTERN is an extended regular expression","-P, --perl-regexp PATTERN is a Perl regular expression","-F, --fixed-strings PATTERN is a set of newline-separated strings","-i, --ignore-case ignore case distinctions","-v, --invert-match select non-matching lines","-w, --word-regexp match only whole words","-x, --line-regexp match only whole lines","-c, --count print only a count of matching lines","-l, --files-with-matches print only names of files with matches","-L, --files-without-match print names of files with no matches","-m NUM, --max-count=NUM stop after NUM matches","-n, --line-number print line number with output lines","-h, --no-filename suppress the file name prefix on output","-o, --only-matching show only nonempty parts of lines that match","-q, --quiet, --silent suppress all normal output","-r, -R, --recursive search directories recursively","-A NUM print NUM lines of trailing context","-B NUM print NUM lines of leading context","-C NUM print NUM lines of context","-e PATTERN use PATTERN for matching","-f FILE, --file=FILE obtain patterns from FILE, one per line"," --include=GLOB search only files matching GLOB"," --exclude=GLOB skip files matching GLOB"," --exclude-dir=DIR skip directories matching DIR"," --help display this help and exit"]},de={name:"grep",async execute(t,e){let i=!1,g=!1,f=!1,h=!1,c=!1,u=!1,a=!1,l=!1,m=!1,F=!1,$=!1,y=!1,x=!1,M=!1,G=!1,S=0,N=0,W=0,B=[],b=[],X=[],L=null,H=[],Z=[],Q=!0;for(let s=0;s<t.length;s++){let r=t[s];if(Q&&r==="--"){Q=!1;continue}if(Q&&r==="--help")return me(Ee);if(Q&&r.startsWith("-")&&r!=="-"){if(r==="-e"&&s+1<t.length){L=t[++s];continue}if(r.startsWith("--file=")){H.push(r.slice(7));continue}if(r.startsWith("--include=")){B.push(r.slice(10));continue}if(r.startsWith("--exclude=")){b.push(r.slice(10));continue}if(r.startsWith("--exclude-dir=")){X.push(r.slice(14));continue}if(r.startsWith("--max-count=")){S=parseInt(r.slice(12),10);continue}let v=r.match(/^-m(\d+)$/);if(v){S=parseInt(v[1],10);continue}if(r==="-m"&&s+1<t.length){S=parseInt(t[++s],10);continue}let o=r.match(/^-([ABC])(\d+)$/);if(o){let p=parseInt(o[2],10);o[1]==="A"?W=p:o[1]==="B"?N=p:o[1]==="C"&&(N=p,W=p);continue}if((r==="-A"||r==="-B"||r==="-C")&&s+1<t.length){let p=parseInt(t[++s],10);r==="-A"?W=p:r==="-B"?N=p:(N=p,W=p);continue}let d=r.startsWith("--")?[r]:r.slice(1).split("");for(let p=0;p<d.length;p++){let n=d[p];if(n==="f"||n==="--file"){let z=n==="f"?d.slice(p+1).join(""):"";if(z.length>0)H.push(z);else if(s+1<t.length)H.push(t[++s]);else return{stdout:"",stderr:n==="f"?`grep: option requires an argument -- 'f'
|
|
6
|
+
`:`grep: option '--file' requires an argument
|
|
7
|
+
`,exitCode:2};break}if(n==="i"||n==="--ignore-case")i=!0;else if(n==="n"||n==="--line-number")g=!0;else if(n==="v"||n==="--invert-match")f=!0;else if(n==="c"||n==="--count")h=!0;else if(n==="l"||n==="--files-with-matches")c=!0;else if(n==="L"||n==="--files-without-match")u=!0;else if(n==="r"||n==="R"||n==="--recursive")a=!0;else if(n==="w"||n==="--word-regexp")l=!0;else if(n==="x"||n==="--line-regexp")m=!0;else if(n==="E"||n==="--extended-regexp")F=!0;else if(n==="P"||n==="--perl-regexp")$=!0;else if(n==="F"||n==="--fixed-strings")y=!0;else if(n==="o"||n==="--only-matching")x=!0;else if(n==="h"||n==="--no-filename")M=!0;else if(n==="q"||n==="--quiet"||n==="--silent")G=!0;else{if(n.startsWith("--"))return ne("grep",n);if(n.length===1)return ne("grep",`-${n}`)}}}else Z.push(r)}if(L===null&&H.length===0&&(L=Z.shift()??null,L===null))return{stdout:"",stderr:`grep: missing pattern
|
|
8
|
+
`,exitCode:2};let J=Z,E=L===null?[]:Fe(L),K=!1;for(let s of H){let r;if(s==="")return{stdout:"",stderr:`grep: : No such file or directory
|
|
9
|
+
`,exitCode:2};if(s==="-")r=K?"":j(e.stdin),K=!0;else try{let o=e.fs.resolvePath(e.cwd,s);if((await e.fs.stat(o)).isDirectory)return{stdout:"",stderr:`grep: ${s}: Is a directory
|
|
10
|
+
`,exitCode:2};r=await e.fs.readFile(o)}catch(o){return O(o),{stdout:"",stderr:`grep: ${s}: No such file or directory
|
|
11
|
+
`,exitCode:2}}let v=ve(r);if(E.length+v.length>e.limits.maxArrayElements)throw new A(`grep: array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");E.push(...v)}if(E.length===0&&!f&&!u)return{stdout:"",stderr:"",exitCode:1};let k=y?"fixed":F?"extended":$?"perl":"basic";if(k==="perl"&&new Set(E).size>1)return{stdout:"",stderr:`grep: the -P option only supports a single pattern
|
|
12
|
+
`,exitCode:2};if(E.length>1&&k!=="fixed")for(let s of E)try{re(s,{mode:k})}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${s}
|
|
13
|
+
`,exitCode:2}}let ie=E.length===0?{pattern:we,mode:"extended"}:Ce(E,k),Y,ee,I;try{let s=re(ie.pattern,{mode:ie.mode,ignoreCase:i,wholeWord:l,lineRegexp:m});Y=s.regex,ee=s.kResetGroup,I=s.preFilter}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${E.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`,exitCode:2}}if(J.length===0&&e.stdin!==void 0){let s=K?"":j(e.stdin),r=se(s,Y,{invertMatch:f,showLineNumbers:g,countOnly:h,filename:"",onlyMatching:x,beforeContext:N,afterContext:W,maxCount:S,kResetGroup:ee,preFilter:I,maxWork:he(e),maxMatches:e.limits.maxArrayElements,signal:e.signal});return G?{stdout:"",stderr:"",exitCode:r.matched?0:1}:{stdout:r.output,stderr:"",exitCode:r.matched?0:1}}if(J.length===0)return{stdout:"",stderr:`grep: no input files
|
|
16
|
+
`,exitCode:2};let U="",oe="",le=!1,ae=!1,P=[],R={operations:0,results:0,maxOperations:e.limits.maxGlobOperations,maxResults:e.limits.maxArrayElements},te=s=>{if(s.length>R.maxResults-P.length)throw new A(`grep: array element limit exceeded (${R.maxResults})`,"array_elements");P.push(...s)},fe=!1,ue=!1;for(let s of J){if(s==="-"){if(P.length>=R.maxResults)throw new A(`grep: array element limit exceeded (${R.maxResults})`,"array_elements");P.push({path:xe,isFile:!0,isStdin:!0,stdinAtEof:fe}),fe=!0;continue}if(ue=!0,s.includes("*")||s.includes("?")||s.includes("[")){let r=await Pe(s,e,R);if(a)for(let v of r){let o=await V(v.path,e,B,b,X,v.isFile,R);te(o)}else te(r)}else if(a){let r=await V(s,e,B,b,X,void 0,R);te(r)}else{if(P.length>=R.maxResults)throw new A(`grep: array element limit exceeded (${R.maxResults})`,"array_elements");P.push({path:s})}}let pe=(P.length>1||a&&ue)&&!M,ce=50;for(let s=0;s<P.length;s+=ce){let r=P.slice(s,s+ce),v=await Promise.all(r.map(async o=>{let d=o.path,p=d.split("/").pop()||d;if(b.length>0&&!a&&!o.isStdin&&b.some(n=>C(p,n,{stripQuotes:!0}))||B.length>0&&!a&&!o.isStdin&&!B.some(n=>C(p,n,{stripQuotes:!0})))return null;try{let n;if(o.isStdin)n=o.stdinAtEof||e.stdin===void 0?"":j(e.stdin);else{let D=e.fs.resolvePath(e.cwd,d),T=!1;if(o.isFile===void 0?T=(await e.fs.stat(D)).isDirectory:T=!o.isFile,T)return a?null:{error:`grep: ${d}: Is a directory
|
|
17
|
+
`};n=await e.fs.readFile(D)}if(I&&!f){let D=I.ignoreCase?n.toLowerCase():n;if(!I.needles.some(T=>D.includes(T))){if(h){let T=pe?`${d}:0`:"0";return{file:d,result:{output:`${T}
|
|
18
|
+
`,matched:!1,matchCount:0}}}return{file:d,result:{output:"",matched:!1,matchCount:0}}}}let z=se(n,Y,{invertMatch:f,showLineNumbers:g,countOnly:h,filename:pe?d:"",onlyMatching:x,beforeContext:N,afterContext:W,maxCount:S,kResetGroup:ee,preFilter:I,maxWork:he(e),maxMatches:e.limits.maxArrayElements,signal:e.signal});return{file:d,result:z}}catch(n){return O(n),{error:`grep: ${d}: No such file or directory
|
|
19
|
+
`}}}));for(let o of v){if(o===null)continue;if("error"in o&&o.error){oe+=o.error,o.error.includes("Is a directory")||(ae=!0);continue}if(!("file"in o)||!o.result)continue;let{file:d,result:p}=o;if(p.matched){if(le=!0,G)return{stdout:"",stderr:"",exitCode:0};c?U+=`${d}
|
|
20
|
+
`:u||(U+=p.output)}else u?U+=`${d}
|
|
21
|
+
`:h&&!c&&(U+=p.output)}}let q;return ae?q=2:q=le?0:1,G?{stdout:"",stderr:"",exitCode:q}:{stdout:U,stderr:oe,exitCode:q}}},ge=256;async function ye(t,e,i,g,f,h=0){if(h>=ge)return;let c=i.fs.resolvePath(i.cwd,t);try{if(w(f),!(await i.fs.stat(c)).isDirectory){let l=t.split("/").pop()||"";if(e){let m=e.replace(/^\//,"");C(l,m,{stripQuotes:!0})&&(_(f),g.push(t))}return}w(f);let a=await i.fs.readdir(c);for(let l of a){let m=t==="."?l:`${t}/${l}`,F=i.fs.resolvePath(i.cwd,m);if(w(f),(await i.fs.stat(F)).isDirectory)await ye(m,e,i,g,f,h+1);else if(e){let y=e.replace(/^\//,"");C(l,y,{stripQuotes:!0})&&(_(f),g.push(m))}}}catch(u){O(u)}}async function Pe(t,e,i){let g=[],f=t.lastIndexOf("/"),h,c;if(f===-1?(h=e.cwd,c=t):(h=t.slice(0,f)||"/",c=t.slice(f+1)),t.includes("**")){let a=[],l=t.split("**"),m=l[0].replace(/\/$/,"")||".",F=l[1]||"";return await ye(m,F,e,a,i),a.map($=>({path:$}))}let u=e.fs.resolvePath(e.cwd,h);try{if(e.fs.readdirWithFileTypes){w(i);let a=await e.fs.readdirWithFileTypes(u);for(let l of a)if(w(i),C(l.name,c,{stripQuotes:!0})){let m=f===-1?l.name:`${h}/${l.name}`;_(i),g.push({path:m,isFile:l.isFile})}}else{w(i);let a=await e.fs.readdir(u);for(let l of a)if(w(i),C(l,c,{stripQuotes:!0})){let m=f===-1?l:`${h}/${l}`;_(i),g.push({path:m})}}}catch(a){O(a)}return g.sort((a,l)=>a.path.localeCompare(l.path))}async function V(t,e,i=[],g=[],f=[],h,c={operations:0,results:0,maxOperations:e.limits.maxGlobOperations,maxResults:e.limits.maxArrayElements},u=[],a=0){if(a>=ge)return u;let l=e.fs.resolvePath(e.cwd,t);try{let m,F;if(h!==void 0)m=h,F=!h;else{w(c);let y=await e.fs.stat(l);m=y.isFile,F=y.isDirectory}if(m){let y=t.split("/").pop()||t;return g.length>0&&g.some(x=>C(y,x,{stripQuotes:!0}))||i.length>0&&!i.some(x=>C(y,x,{stripQuotes:!0}))||(_(c),u.push({path:t,isFile:!0})),u}if(!F)return u;let $=t.split("/").pop()||t;if(f.length>0&&f.some(y=>C($,y,{stripQuotes:!0})))return u;if(e.fs.readdirWithFileTypes){w(c);let y=await e.fs.readdirWithFileTypes(l);for(let x of y){if(w(c),x.name.startsWith("."))continue;let M=t==="."?x.name:`${t}/${x.name}`;await V(M,e,i,g,f,x.isFile,c,u,a+1)}}else{w(c);let y=await e.fs.readdir(l);for(let x of y){if(w(c),x.startsWith("."))continue;let M=t==="."?x:`${t}/${x}`;await V(M,e,i,g,f,void 0,c,u,a+1)}}}catch(m){O(m)}return u}var Le={name:"fgrep",async execute(t,e){return de.execute(["-F",...t],e)}},Ie={name:"egrep",async execute(t,e){return de.execute(["-E",...t],e)}},Oe={name:"grep",flags:[{flag:"-E",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-P",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-L",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-o",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-m",type:"value",valueHint:"number"},{flag:"-A",type:"value",valueHint:"number"},{flag:"-B",type:"value",valueHint:"number"},{flag:"-C",type:"value",valueHint:"number"},{flag:"-e",type:"value",valueHint:"pattern"},{flag:"-f",type:"value",valueHint:"path"}],stdinType:"text",needsArgs:!0},Se={name:"fgrep",flags:[],stdinType:"text",needsArgs:!0},Be={name:"egrep",flags:[],stdinType:"text",needsArgs:!0};export{de as a,Le as b,Ie as c,Oe as d,Se as e,Be as f};
|
|
@@ -16,5 +16,5 @@ import{a as Y}from"./chunk-CB4SODHK.js";import{l as G,m as V}from"./chunk-LCP3IK
|
|
|
16
16
|
`)}
|
|
17
17
|
`:"",matched:m.length>0,matchCount:m.length}}if(y.length===0)return{output:"",matched:!1,matchCount:0};let k=new Set,M=-1,v=[];for(let f of y){g();let m=Math.max(0,f.startLine-F),$=Math.min(b-1,f.endLine+O);M>=0&&m>M+1&&v.push(q);for(let l=m;l<f.startLine;l++)if(g(),!k.has(l)){k.add(l),M=l;let a=_[l];s&&(a=`${l+1}-${a}`),h&&(a=`${h}-${a}`),v.push(a)}if(L){let l=W!==null?W:f.matchText,a=h?`${h}:`:"";H&&(a+=`${f.byteOffset}:`),s&&(a+=`${f.startLine+1}:`),Z&&(a+=`${f.column}:`),v.push(a+l);for(let d=f.startLine;d<=f.endLine;d++)g(),k.add(d),M=d}else for(let l=f.startLine;l<=f.endLine&&l<b;l++)if(g(),!k.has(l)){k.add(l),M=l;let a=_[l];W!==null&&l===f.startLine&&(n.lastIndex=0,a=n.replace(a,W));let d=h?`${h}:`:"";H&&l===f.startLine&&(d+=`${f.byteOffset}:`),s&&(d+=`${l+1}:`),Z&&l===f.startLine&&(d+=`${f.column}:`),v.push(d+a)}for(let l=f.endLine+1;l<=$;l++)if(g(),!k.has(l)){k.add(l),M=l;let a=_[l];s&&(a=`${l+1}-${a}`),h&&(a=`${h}-${a}`),v.push(a)}}return{output:v.length>0?`${v.join(`
|
|
18
18
|
`)}
|
|
19
|
-
`:"",matched:!0,matchCount:y.length}}var le=new Map([["alpha","a-zA-Z"],["digit","0-9"],["alnum","a-zA-Z0-9"],["lower","a-z"],["upper","A-Z"],["xdigit","0-9A-Fa-f"],["space"," \\t\\n\\r\\f\\v"],["blank"," \\t"],["punct","!-/:-@\\[-`{-~"],["graph","!-~"],["print"," -~"],["cntrl","\\x00-\\x1F\\x7F"],["ascii","\\x00-\\x7F"],["word","a-zA-Z0-9_"]]);function te(t){let n="",e=0;for(;e<t.length;){if(t.slice(e,e+7)==="[[:<:]]"){n+="\\b",e+=7;continue}if(t.slice(e,e+7)==="[[:>:]]"){n+="\\b",e+=7;continue}if(t[e]==="["){let i="[";for(e++,e<t.length&&(t[e]==="^"||t[e]==="!")&&(i+="^",e++),e<t.length&&t[e]==="]"&&(i+="\\]",e++);e<t.length&&t[e]!=="]";){if(t[e]==="["&&e+1<t.length&&t[e+1]===":"){let s=t.indexOf(":]",e+2);if(s!==-1){let o=t.slice(e+2,s),c=le.get(o);if(c){i+=c,e=s+2;continue}}}if(t[e]==="\\"&&e+1<t.length){i+=t[e]+t[e+1],e+=2;continue}i+=t[e],e++}e<t.length&&t[e]==="]"&&(i+="]",e++),n+=i;continue}if(t[e]==="\\"&&e+1<t.length){n+=t[e]+t[e+1],e+=2;continue}n+=t[e],e++}return n}function se(t,n){let e,i;switch(n.mode){case"fixed":e=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":{if(e=te(t),e=e.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),n.mode==="perl"){e=ue(e),e=he(e),e=ae(e);let h=$e(e);e=h.pattern,i=h.kResetGroup}break}default:e=te(t),e=Ce(e);break}n.wholeWord&&(e=`\\b(?:${e})\\b`),n.lineRegexp&&(e
|
|
19
|
+
`:"",matched:!0,matchCount:y.length}}var le=new Map([["alpha","a-zA-Z"],["digit","0-9"],["alnum","a-zA-Z0-9"],["lower","a-z"],["upper","A-Z"],["xdigit","0-9A-Fa-f"],["space"," \\t\\n\\r\\f\\v"],["blank"," \\t"],["punct","!-/:-@\\[-`{-~"],["graph","!-~"],["print"," -~"],["cntrl","\\x00-\\x1F\\x7F"],["ascii","\\x00-\\x7F"],["word","a-zA-Z0-9_"]]);function te(t){let n="",e=0;for(;e<t.length;){if(t.slice(e,e+7)==="[[:<:]]"){n+="\\b",e+=7;continue}if(t.slice(e,e+7)==="[[:>:]]"){n+="\\b",e+=7;continue}if(t[e]==="["){let i="[";for(e++,e<t.length&&(t[e]==="^"||t[e]==="!")&&(i+="^",e++),e<t.length&&t[e]==="]"&&(i+="\\]",e++);e<t.length&&t[e]!=="]";){if(t[e]==="["&&e+1<t.length&&t[e+1]===":"){let s=t.indexOf(":]",e+2);if(s!==-1){let o=t.slice(e+2,s),c=le.get(o);if(c){i+=c,e=s+2;continue}}}if(t[e]==="\\"&&e+1<t.length){i+=t[e]+t[e+1],e+=2;continue}i+=t[e],e++}e<t.length&&t[e]==="]"&&(i+="]",e++),n+=i;continue}if(t[e]==="\\"&&e+1<t.length){n+=t[e]+t[e+1],e+=2;continue}n+=t[e],e++}return n}function se(t,n){let e,i;switch(n.mode){case"fixed":e=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":{if(e=te(t),e=e.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),n.mode==="perl"){e=ue(e),e=he(e),e=ae(e);let h=$e(e);e=h.pattern,i=h.kResetGroup}break}default:e=te(t),e=Ce(e);break}n.wholeWord&&(e=`\\b(?:${e})\\b`),n.lineRegexp&&(e=`^(?:${e})$`);let s=/\\u\{[0-9A-Fa-f]+\}/.test(e),o="g"+(n.ignoreCase?"i":"")+(n.multiline?"m":"")+(n.multilineDotall?"s":"")+(s?"u":""),c=oe(e,n.ignoreCase??!1);return{regex:Y(e,o),kResetGroup:i,preFilter:c??void 0}}function oe(t,n){let e=t;if(e.startsWith("\\b(?:")&&e.endsWith(")\\b")?e=e.slice(5,e.length-3):e.startsWith("\\b")&&e.endsWith("\\b")&&e.length>=4&&(e=e.slice(2,e.length-2)),e.length===0)return null;let i=fe(e);if(i===null)return null;let s=[];for(let o of i){let c=ce(o);if(c===null||c.length===0)return null;s.push(c)}return s.length===0?null:{needles:n?s.map(o=>o.toLowerCase()):s,ignoreCase:n}}function fe(t){let n=[],e=0,i=!1,s=0;for(let o=0;o<t.length;o++){let c=t[o];if(c==="\\"){o++;continue}if(i){c==="]"&&(i=!1);continue}if(c==="[")i=!0;else if(c==="(")e++;else if(c===")"){if(e--,e<0)return null}else c==="|"&&e===0&&(n.push(t.slice(s,o)),s=o+1)}return e!==0||i?null:(n.push(t.slice(s)),n)}function ce(t){let n=t;if(n.startsWith("^")&&(n=n.slice(1)),n.endsWith("$")){let i=0;for(let s=n.length-2;s>=0&&n[s]==="\\";s--)i++;i%2===0&&(n=n.slice(0,-1))}if(n.length===0)return null;let e="";for(let i=0;i<n.length;i++){let s=n[i];if(s==="\\"){let o=n[i+1];if(o===void 0||/[dDwWsSbBAZzGQE0-9ckpPNXRxuU]/.test(o))return null;o==="n"?e+=`
|
|
20
20
|
`:o==="t"?e+=" ":o==="r"?e+="\r":o==="f"?e+="\f":o==="v"?e+="\v":e+=o,i++;continue}if(/[.*+?^${}()|[\]]/.test(s))return null;e+=s}return e}function ue(t){let n="",e=0;for(;e<t.length;)if(t[e]==="\\"&&e+1<t.length&&t[e+1]==="Q"){e+=2;let i="";for(;e<t.length;){if(t[e]==="\\"&&e+1<t.length&&t[e+1]==="E"){e+=2;break}i+=t[e],e++}n+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}else n+=t[e],e++;return n}function he(t){return t.replace(/\\x\{([0-9A-Fa-f]+)\}/g,"\\u{$1}")}function ae(t){let n="",e=0;for(;e<t.length;){if(t[e]==="("&&e+1<t.length&&t[e+1]==="?"){let i=t.slice(e).match(/^\(\?([imsx]*)(-[imsx]*)?(:|$|\))/);if(i){let s=i[1]||"",o=i[2]||"",c=i[3];if(c===":"){let h=e+i[0].length-1,L=re(t,e);if(L!==-1){let F=t.slice(h+1,L),O=de(F,s,o);n+=`(?:${O})`,e=L+1;continue}}else if(c===")"||c===""){e+=i[0].length;continue}}}n+=t[e],e++}return n}function re(t,n){let e=0,i=n;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==="["){for(i++;i<t.length&&t[i]!=="]";)t[i]==="\\"&&i++,i++;i++;continue}if(t[i]==="(")e++;else if(t[i]===")"&&(e--,e===0))return i;i++}return-1}function de(t,n,e){let i=t;return n.includes("i")&&(i=me(i)),i}function me(t){let n="",e=0;for(;e<t.length;){let i=t[e];if(i==="\\"){e+1<t.length?(n+=i+t[e+1],e+=2):(n+=i,e++);continue}if(i==="["){n+=i,e++,e<t.length&&t[e]==="^"&&(n+=t[e],e++);let s=[];for(;e<t.length&&t[e]!=="]";)if(t[e]==="\\")s.push(t[e]),e++,e<t.length&&(s.push(t[e]),e++);else if(t[e]==="-"&&s.length>0&&e+1<t.length&&t[e+1]!=="]"){let o=s[s.length-1],c=t[e+1];s.push("-"),s.push(c),/[a-z]/.test(o)&&/[a-z]/.test(c)?(s.push(o.toUpperCase()),s.push("-"),s.push(c.toUpperCase())):/[A-Z]/.test(o)&&/[A-Z]/.test(c)&&(s.push(o.toLowerCase()),s.push("-"),s.push(c.toLowerCase())),e+=2}else{let o=t[e];if(s.push(o),/[a-zA-Z]/.test(o)){let c=o===o.toLowerCase()?o.toUpperCase():o.toLowerCase();s.includes(c)||s.push(c)}e++}n+=s.join(""),e<t.length&&(n+=t[e],e++);continue}if(/[a-zA-Z]/.test(i)){let s=i.toLowerCase(),o=i.toUpperCase();n+=`[${o}${s}]`}else n+=i;e++}return n}function $e(t){let n=ge(t);if(n===-1)return{pattern:t};let e=t.slice(0,n),i=t.slice(n+2),s=xe(e);return{pattern:`(?:${e})(${i})`,kResetGroup:s+1}}function ge(t){let n=0;for(;n<t.length-1;)if(t[n]==="\\"){if(t[n+1]==="K"){let e=0,i=n-1;for(;i>=0&&t[i]==="\\";)e++,i--;if(e%2===0)return n}n+=2}else n++;return-1}function xe(t){let n=0,e=0;for(;e<t.length;){if(t[e]==="\\"){e+=2;continue}if(t[e]==="["){for(e++;e<t.length&&t[e]!=="]";)t[e]==="\\"&&e++,e++;e++;continue}if(t[e]==="(")if(e+1<t.length&&t[e+1]==="?"){if(e+2<t.length){let i=t[e+2];if(i===":"||i==="="||i==="!"){e++;continue}if(i==="<"&&e+3<t.length){let s=t[e+3];if(s==="="||s==="!"){e++;continue}n++,e++;continue}}}else n++;e++}return n}function we(t){let n=t.replace(/\$\{0\}|\$0(?![0-9])/g,"$$&");return n=n.replace(/\$\{([^0-9}][^}]*)\}/g,"$$<$1>"),n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)(?![>0-9])/g,"$$<$1>"),n}function Ce(t){let n="",e=0,i=!0,s=0;for(;e<t.length;){let o=t[e];if(o==="["){for(n+=o,e++,e<t.length&&(t[e]==="^"||t[e]==="!")&&(n+=t[e],e++),e<t.length&&t[e]==="]"&&(n+=t[e],e++);e<t.length&&t[e]!=="]";)t[e]==="\\"&&e+1<t.length?(n+=t[e]+t[e+1],e+=2):(n+=t[e],e++);e<t.length&&t[e]==="]"&&(n+=t[e],e++),i=!1;continue}if(o==="\\"&&e+1<t.length){let c=t[e+1];if(c==="|"){n+="|",e+=2,i=!0;continue}if(c==="("){n+="(",e+=2,s++,i=!0;continue}if(c===")"){n+=")",e+=2,s=Math.max(0,s-1),i=!1;continue}if(c==="{"){let L=t.slice(e).match(/^\\{(\d+)(,(\d*)?)?\\}/);if(L){let F=L[1],O=L[2]!==void 0,A=L[3]||"";O?n+=`{${F},${A}}`:n+=`{${F}}`,e+=L[0].length,i=!1;continue}n+="\\{",e+=2,i=!1;continue}if(c==="}"){n+="\\}",e+=2,i=!1;continue}n+=o+c,e+=2,i=!1;continue}if(o==="*"&&i){n+="\\*",e++;continue}if(o==="^"){if(i){n+="^",e++;continue}n+="\\^",e++;continue}if(o==="$"){let c=e===t.length-1,h=e+2<t.length&&t[e+1]==="\\"&&t[e+2]===")";c||h?n+="$":n+="\\$",e++,i=!1;continue}o==="+"||o==="?"||o==="|"||o==="("||o===")"||o==="{"||o==="}"?n+=`\\${o}`:n+=o,e++,i=!1}return n}export{ne as a,se as b,we as c};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-CMTQFWZK.js";import"./chunk-DN2YCFOR.js";export{a as echoCommand,b as flagsForFuzzing};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{b as yr}from"./chunk-D3MUBZ4P.js";import{b as Ar}from"./chunk-
|
|
3
|
+
import{b as yr}from"./chunk-D3MUBZ4P.js";import{b as Ar}from"./chunk-DKIOFM35.js";import{b as $r}from"./chunk-TROO33BG.js";import"./chunk-VTAIIBJT.js";import"./chunk-LGERQ5TD.js";import{c as Sr}from"./chunk-6UK23ZFT.js";import"./chunk-7I6MNC5I.js";import{b as wr}from"./chunk-OKU677H3.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-XAAXPEOP.js";import{d as Ir,e as Mr,f as jr}from"./chunk-PQPFDJFF.js";import"./chunk-QES5OSUC.js";import{b as tr}from"./chunk-QK6BXSHU.js";import{b as lr}from"./chunk-CC2AQ6B7.js";import{b as ur}from"./chunk-BPWZ7ADB.js";import{b as pr}from"./chunk-NJ67YJRE.js";import{b as er}from"./chunk-LXFMIXGA.js";import{b as dr}from"./chunk-WFVCEB5T.js";import{b as cr}from"./chunk-KG2KXL4Y.js";import"./chunk-2YLY6FJA.js";import{b as hr}from"./chunk-X63MJBLH.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-MYTNZ7MA.js";import{b as mr}from"./chunk-IJIJAQBT.js";import"./chunk-D5G3L4PR.js";import{b as Fr}from"./chunk-MZM7RVYU.js";import{b as zr}from"./chunk-23OI2XDJ.js";import{b as fr}from"./chunk-XEQ7KSRM.js";import{b as nr}from"./chunk-IAAPXDHN.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-QAYU7HPM.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-ETWDDV6I.js";import{b as G}from"./chunk-TZ3S7MY6.js";import{b as H}from"./chunk-5SKEZPTU.js";import{b as J}from"./chunk-6SAZRW7E.js";import{b as K}from"./chunk-B7RRNV3A.js";import{b as L}from"./chunk-E5VZGTZ6.js";import{b as O}from"./chunk-BCJ42NCM.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-VY2K25J4.js";import{b as y}from"./chunk-YYZSYLJO.js";import{b as A}from"./chunk-7FGDUBSN.js";import{b as $}from"./chunk-2OQ5HPZE.js";import{b as S}from"./chunk-BWRQ5HYX.js";import{b as T}from"./chunk-ZXIW4JPL.js";import{b as B}from"./chunk-YIANER7Y.js";import{b as D}from"./chunk-3VSWQCPN.js";import{b as E}from"./chunk-Q3LE3Y66.js";import{b as w}from"./chunk-WWOUFMMY.js";import{b as x}from"./chunk-VTHA5UK5.js";import{b as v}from"./chunk-GEUCQ4AB.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-USMDLXMM.js";import"./chunk-X5VUGFUL.js";import{b}from"./chunk-KXWWWQZK.js";import"./chunk-WDV2ECOC.js";import"./chunk-3MRB66F4.js";import"./chunk-XAVWLYZR.js";import{b as I}from"./chunk-3OYRDLJJ.js";import{b as M}from"./chunk-PKWK3LQM.js";import{b as j}from"./chunk-ISW2U76N.js";import{b as t}from"./chunk-YOIFOOGX.js";import{b as l}from"./chunk-VGR3NA3H.js";import{b as u}from"./chunk-RYQB6GQ7.js";import{b as p}from"./chunk-YTL6DXBO.js";import{b as e}from"./chunk-NGD6G5ZG.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-LUHU7UUN.js";import{b as h}from"./chunk-TPU3OX2A.js";import"./chunk-DSZQ22OX.js";import"./chunk-3PCPQIUD.js";import"./chunk-TW2IJRUF.js";import"./chunk-SSK3N7FN.js";import"./chunk-6D75E4LV.js";import"./chunk-MROECM42.js";import"./chunk-4SQKKW2M.js";import"./chunk-CB4SODHK.js";import{b as i}from"./chunk-CMTQFWZK.js";import{b as g}from"./chunk-W4U4QOZF.js";import"./chunk-O74FSWB4.js";import"./chunk-BNYIXXC2.js";import"./chunk-46CDVHZ3.js";import{b as m}from"./chunk-5SR55TXB.js";import"./chunk-K5KT6DMM.js";import"./chunk-VLWZ6L7C.js";import{b as F}from"./chunk-LNFTLSWJ.js";import"./chunk-CPTQXTBJ.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import{b as f}from"./chunk-PUZGSIMN.js";import"./chunk-H4BRFPKY.js";import"./chunk-43E7AR6A.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b,c,d,e,f}from"./chunk-
|
|
3
|
+
import{a,b,c,d,e,f}from"./chunk-USMDLXMM.js";import"./chunk-X5VUGFUL.js";import"./chunk-XAVWLYZR.js";import"./chunk-CB4SODHK.js";import"./chunk-BNYIXXC2.js";import"./chunk-46CDVHZ3.js";import"./chunk-CPTQXTBJ.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{c as egrepCommand,f as egrepFlagsForFuzzing,b as fgrepCommand,e as fgrepFlagsForFuzzing,d as flagsForFuzzing,a as grepCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-IJIJAQBT.js";import"./chunk-D5G3L4PR.js";import"./chunk-WDV2ECOC.js";import"./chunk-MROECM42.js";import"./chunk-4SQKKW2M.js";import"./chunk-CB4SODHK.js";import"./chunk-O74FSWB4.js";import"./chunk-46CDVHZ3.js";import"./chunk-VLWZ6L7C.js";import"./chunk-CPTQXTBJ.js";import"./chunk-7JZKVC3F.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{b as flagsForFuzzing,a as jqCommand};
|
|
@@ -7,6 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
|
|
8
8
|
// src/commands/js-exec/js-exec-worker.ts
|
|
9
9
|
import { stripTypeScriptTypes } from "node:module";
|
|
10
|
+
import { setTimeout } from "node:timers/promises";
|
|
10
11
|
import { parentPort } from "node:worker_threads";
|
|
11
12
|
import {
|
|
12
13
|
getQuickJS
|
|
@@ -3495,6 +3496,7 @@ async function getQuickJSModule() {
|
|
|
3495
3496
|
}
|
|
3496
3497
|
var MEMORY_LIMIT = 64 * 1024 * 1024;
|
|
3497
3498
|
var INTERRUPT_CYCLES = 1e5;
|
|
3499
|
+
var PROCESS_EXIT_MARKER = "__just_bash_process_exit_marker__";
|
|
3498
3500
|
function formatError(errorVal) {
|
|
3499
3501
|
if (typeof errorVal === "object" && errorVal !== null && "message" in errorVal) {
|
|
3500
3502
|
const err = errorVal;
|
|
@@ -3516,6 +3518,12 @@ function formatError(errorVal) {
|
|
|
3516
3518
|
function throwError(context, message) {
|
|
3517
3519
|
return { error: context.newError(message) };
|
|
3518
3520
|
}
|
|
3521
|
+
function isProcessExit(context, error, processExitMarker) {
|
|
3522
|
+
const marker = context.getProp(error, PROCESS_EXIT_MARKER);
|
|
3523
|
+
const isExit = context.sameValue(marker, processExitMarker);
|
|
3524
|
+
marker.dispose();
|
|
3525
|
+
return isExit;
|
|
3526
|
+
}
|
|
3519
3527
|
function jsToHandle(context, value) {
|
|
3520
3528
|
if (value === null || value === void 0) {
|
|
3521
3529
|
return context.undefined;
|
|
@@ -3741,7 +3749,7 @@ var VIRTUAL_MODULES = Object.assign(
|
|
|
3741
3749
|
for (const [name, hint] of Object.entries(UNSUPPORTED_MODULES)) {
|
|
3742
3750
|
VIRTUAL_MODULES[name] = `throw new Error("Module '${name}' is not available in the js-exec sandbox. ${hint} Run 'js-exec --help' for available modules.");`;
|
|
3743
3751
|
}
|
|
3744
|
-
function setupContext(context, backend, input) {
|
|
3752
|
+
function setupContext(context, backend, input, processExitMarker) {
|
|
3745
3753
|
const consoleObj = context.newObject();
|
|
3746
3754
|
const logFn = context.newFunction("log", (...args) => {
|
|
3747
3755
|
const parts = args.map((a) => {
|
|
@@ -4145,7 +4153,9 @@ function setupContext(context, backend, input) {
|
|
|
4145
4153
|
code = typeof val === "number" ? val : 0;
|
|
4146
4154
|
}
|
|
4147
4155
|
backend.exit(code);
|
|
4148
|
-
|
|
4156
|
+
const exitError = context.newError("process.exit()");
|
|
4157
|
+
context.setProp(exitError, PROCESS_EXIT_MARKER, processExitMarker);
|
|
4158
|
+
return { error: exitError };
|
|
4149
4159
|
});
|
|
4150
4160
|
context.setProp(processObj, "exit", exitFn);
|
|
4151
4161
|
exitFn.dispose();
|
|
@@ -4367,7 +4377,7 @@ async function initializeWithDefense() {
|
|
|
4367
4377
|
stripTypeScriptTypes("const x = 1;");
|
|
4368
4378
|
} catch {
|
|
4369
4379
|
}
|
|
4370
|
-
await
|
|
4380
|
+
await setTimeout(0);
|
|
4371
4381
|
defense = new WorkerDefenseInDepth({
|
|
4372
4382
|
excludeViolationTypes: [
|
|
4373
4383
|
// SharedArrayBuffer/Atomics: Used by sync-backend for synchronous
|
|
@@ -4405,6 +4415,7 @@ async function executeCode(input) {
|
|
|
4405
4415
|
const backend = new SyncBackend(input.sharedBuffer, input.timeoutMs);
|
|
4406
4416
|
let runtime;
|
|
4407
4417
|
let context;
|
|
4418
|
+
let processExitMarker;
|
|
4408
4419
|
try {
|
|
4409
4420
|
runtime = qjs.newRuntime();
|
|
4410
4421
|
runtime.setMemoryLimit(MEMORY_LIMIT);
|
|
@@ -4414,7 +4425,8 @@ async function executeCode(input) {
|
|
|
4414
4425
|
return interruptCount > INTERRUPT_CYCLES;
|
|
4415
4426
|
});
|
|
4416
4427
|
context = runtime.newContext();
|
|
4417
|
-
|
|
4428
|
+
processExitMarker = context.newObject();
|
|
4429
|
+
setupContext(context, backend, input, processExitMarker);
|
|
4418
4430
|
{
|
|
4419
4431
|
const initResult = context.evalCode(
|
|
4420
4432
|
`{
|
|
@@ -4625,12 +4637,12 @@ async function executeCode(input) {
|
|
|
4625
4637
|
}
|
|
4626
4638
|
const result = input.isModule ? context.evalCode(jsCode, filename, { type: "module" }) : context.evalCode(jsCode, filename);
|
|
4627
4639
|
if (result.error) {
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
const rawMsg = typeof errorVal === "object" && errorVal !== null && "message" in errorVal ? errorVal.message : String(errorVal);
|
|
4631
|
-
if (rawMsg === "__EXIT__") {
|
|
4640
|
+
if (isProcessExit(context, result.error, processExitMarker)) {
|
|
4641
|
+
result.error.dispose();
|
|
4632
4642
|
return { success: true };
|
|
4633
4643
|
}
|
|
4644
|
+
const errorVal = context.dump(result.error);
|
|
4645
|
+
result.error.dispose();
|
|
4634
4646
|
const errorMsg = formatError(errorVal);
|
|
4635
4647
|
try {
|
|
4636
4648
|
backend.writeStderr(`${errorMsg}
|
|
@@ -4640,24 +4652,47 @@ async function executeCode(input) {
|
|
|
4640
4652
|
backend.exit(1);
|
|
4641
4653
|
return { success: true };
|
|
4642
4654
|
}
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4655
|
+
const moduleCompletion = input.isModule ? context.resolvePromise(result.value) : void 0;
|
|
4656
|
+
const pendingResult = runtime.executePendingJobs();
|
|
4657
|
+
if ("error" in pendingResult && pendingResult.error) {
|
|
4658
|
+
if (isProcessExit(context, pendingResult.error, processExitMarker)) {
|
|
4647
4659
|
pendingResult.error.dispose();
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4660
|
+
result.value.dispose();
|
|
4661
|
+
return { success: true };
|
|
4662
|
+
}
|
|
4663
|
+
const errorVal = context.dump(pendingResult.error);
|
|
4664
|
+
pendingResult.error.dispose();
|
|
4665
|
+
result.value.dispose();
|
|
4666
|
+
const errorMsg = formatError(errorVal);
|
|
4667
|
+
try {
|
|
4668
|
+
backend.writeStderr(`${errorMsg}
|
|
4653
4669
|
`);
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4670
|
+
} catch {
|
|
4671
|
+
}
|
|
4672
|
+
backend.exit(1);
|
|
4673
|
+
return { success: true };
|
|
4674
|
+
}
|
|
4675
|
+
if (moduleCompletion) {
|
|
4676
|
+
const moduleResult = await moduleCompletion;
|
|
4677
|
+
if (moduleResult.error) {
|
|
4678
|
+
if (isProcessExit(context, moduleResult.error, processExitMarker)) {
|
|
4679
|
+
moduleResult.error.dispose();
|
|
4680
|
+
result.value.dispose();
|
|
4657
4681
|
return { success: true };
|
|
4658
4682
|
}
|
|
4683
|
+
const errorVal = context.dump(moduleResult.error);
|
|
4684
|
+
moduleResult.error.dispose();
|
|
4685
|
+
result.value.dispose();
|
|
4686
|
+
const errorMsg = formatError(errorVal);
|
|
4687
|
+
try {
|
|
4688
|
+
backend.writeStderr(`${errorMsg}
|
|
4689
|
+
`);
|
|
4690
|
+
} catch {
|
|
4691
|
+
}
|
|
4692
|
+
backend.exit(1);
|
|
4659
4693
|
return { success: true };
|
|
4660
4694
|
}
|
|
4695
|
+
moduleResult.value.dispose();
|
|
4661
4696
|
}
|
|
4662
4697
|
result.value.dispose();
|
|
4663
4698
|
backend.exit(0);
|
|
@@ -4679,6 +4714,7 @@ async function executeCode(input) {
|
|
|
4679
4714
|
}
|
|
4680
4715
|
return { success: true };
|
|
4681
4716
|
} finally {
|
|
4717
|
+
processExitMarker?.dispose();
|
|
4682
4718
|
context?.dispose();
|
|
4683
4719
|
runtime?.dispose();
|
|
4684
4720
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-5SR55TXB.js";import"./chunk-K5KT6DMM.js";import"./chunk-VLWZ6L7C.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{b as flagsForFuzzing,a as printfCommand};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
+
import{a as Q,b as W}from"./chunk-WSLBBXPJ.js";import{a as I}from"./chunk-7I6MNC5I.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import"./chunk-SSK3N7FN.js";import{a as F}from"./chunk-MROECM42.js";import{c as w}from"./chunk-4SQKKW2M.js";import{b as M}from"./chunk-46CDVHZ3.js";import{b as C}from"./chunk-CPKBPQ2C.js";import{a as A,b as d}from"./chunk-PBOVSFTJ.js";import{a as E}from"./chunk-I4IRHQDW.js";import{a as P,b as D}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{fileURLToPath as B}from"node:url";import{Worker as L}from"node:worker_threads";var z={name:"python3",summary:"Execute Python code via CPython Emscripten",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using CPython compiled to WebAssembly via Emscripten.","","This command runs Python in an isolated environment with access to","the virtual filesystem. Standard library modules are available."],options:["-c CODE Execute CODE as Python script","-m MODULE Run library module as a script","--version Show Python version","--help Show this help"],examples:['python3 -c "print(1 + 2)"','python3 -c "import sys; print(sys.version)"',"python3 script.py","python3 script.py arg1 arg2",`echo 'print("hello")' | python3`],notes:["CPython runs in WebAssembly, so execution may be slower than native Python.","Standard library modules are available (no pip install).","Maximum execution time is 30 seconds by default."]};function _(t){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(t.length===0)return e;let r=t.findIndex(n=>!n.startsWith("-")||n==="-"||n==="--");for(let n=0;n<(r===-1?t.length:r);n++){let i=t[n];if(i==="-c")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
|
|
4
|
+
`,exitCode:2}:(e.code=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="-m")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
|
|
5
|
+
`,exitCode:2}:(e.module=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="--version"||i==="-V")return e.showVersion=!0,e;if(i.startsWith("-")&&i!=="-")return{stdout:"",stderr:`python3: unrecognized option '${i}'
|
|
6
|
+
`,exitCode:2}}if(r!==-1){let n=t[r];n==="--"?r+1<t.length&&(e.scriptFile=t[r+1],e.scriptArgs=t.slice(r+2)):(e.scriptFile=n,e.scriptArgs=t.slice(r+1))}return e}var b=new WeakMap;function R(t){let e=b.get(t);return e||(e={executionQueue:[],activeExecution:null,poisonedError:null},b.set(t,e)),e}function ne(){b=new WeakMap}var H=B(new URL("./worker.js",import.meta.url));function U(t,e){if(!t||typeof t!="object")return{success:!1,error:"Malformed worker response"};let r=t;return typeof r.protocolToken!="string"||r.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}: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?{success:!0}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}function k(t){if(t.poisonedError!==null){for(let o of t.executionQueue.splice(0))o.state==="queued"&&(o.state="settled",o.stopBridge(),o.settle({success:!1,error:t.poisonedError}));return}if(t.activeExecution!==null||t.executionQueue.length===0)return;for(;t.executionQueue.length>0&&t.executionQueue[0]?.state!=="queued";)t.executionQueue.shift();if(t.executionQueue.length===0)return;let e=t.executionQueue.shift();if(!e)return;e.state="running",t.activeExecution=e;let r;try{r=M.runTrusted(()=>new L(H,{workerData:e.input}))}catch(o){let s=o instanceof Error?o.message:String(o);e.state="settled",e.settle({success:!1,error:d(s)}),t.activeExecution===e&&(t.activeExecution=null,k(t));return}e.worker=r;let n=!0,i=()=>{n&&(n=!1,r.removeListener("message",u),r.removeListener("error",g),r.removeListener("exit",v))},c=async(o,s)=>{if(!(t.activeExecution?.executionId!==e.executionId||e.state!=="running")){if(e.state="terminating",i(),e.settle(o),s&&!await e.controller.terminate(r)){let f="Worker termination was not acknowledged";e.worker=null,e.state="settled",t.poisonedError=f,t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null),k(t);return}e.worker=null,e.state="settled",t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null,k(t))}};e.cancel=o=>{c(o,!0)};let p=w(e.requireDefenseContext,"python3","worker message callback",o=>{try{e.controller.assertMessageSize(o,"response")}catch(s){c({success:!1,error:d(E(s))},!0);return}c(U(o,e.input.protocolToken),!0)}),h=w(e.requireDefenseContext,"python3","worker error callback",o=>{let s=d(E(o));c({success:!1,error:s},!0)}),a=w(e.requireDefenseContext,"python3","worker exit callback",()=>{c({success:!1,error:"Worker exited unexpectedly"},!1)}),u=o=>{try{p(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},g=o=>{try{h(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},v=()=>{try{a()}catch(o){let s=o instanceof Error?o.message:String(o);c({success:!1,error:d(s)},!0)}};r.on("message",u),r.on("error",g),r.on("exit",v)}async function N(t,e,r,n,i=[]){let c=Q(),p=new W(c,r.fs,r.cwd,"python3",r.fetch,r.limits.maxOutputSize),h=r.limits.maxPythonTimeoutMs,a=R(r.fs);if(a.poisonedError!==null)return{stdout:"",stderr:`python3: ${a.poisonedError}
|
|
7
|
+
`,exitCode:1};let u=new I({commandName:"python3",timeoutMs:h,signal:r.signal,maxMessageBytes:r.limits.maxWorkerMessageBytes}),g={protocolToken:u.protocolToken,sharedBuffer:c,pythonCode:t,stdin:e,cwd:r.cwd,env:F(r.env),args:i,scriptPath:n,timeoutMs:h,maxFileSize:r.limits.maxStringLength};u.assertMessageSize({...g,sharedBuffer:void 0},"request");let v=new Promise(l=>{let f=!1,m={executionId:Symbol("python3 execution"),input:g,settle:y=>{f||(f=!0,u.close(),l(y))},requireDefenseContext:r.requireDefenseContext,state:"queued",worker:null,controller:u,stopBridge:()=>p.stop?.(),cancel:()=>{}};m.cancel=y=>{if(m.state!=="queued")return;m.state="settled";let x=a.executionQueue.indexOf(m);x!==-1&&a.executionQueue.splice(x,1),m.settle(y),k(a)};let O=w(r.requireDefenseContext,"python3","worker cancellation callback",y=>{p.stop?.(),m.cancel({success:!1,error:y==="abort"?u.abortMessage():u.timeoutMessage()})}),T=y=>{try{O(y)}catch(x){let $=x instanceof Error?x.message:String(x);m.cancel({success:!1,error:d($)})}};u.arm(T),u.isCanceled||(a.executionQueue.push(m),k(a))}),[o,s]=await Promise.all([p.run(h).catch(l=>({stdout:"",stderr:`python3: bridge error: ${d(E(l))}
|
|
8
|
+
`,exitCode:1})),v.catch(l=>({success:!1,error:d(E(l))}))]);if(!s.success&&s.error){let l=d(s.error),f=s.error===u.timeoutMessage()||s.error===u.abortMessage();return{stdout:o.stdout,stderr:`${o.stderr}python3: ${l}
|
|
9
|
+
`,exitCode:o.exitCode||(f?124:1)}}return{...o}}var V={name:"python3",async execute(t,e){if(D(t))return P(z);let r=_(t);if("exitCode"in r)return r;if(r.showVersion)return{stdout:`Python 3.13.2 (Emscripten)
|
|
10
|
+
`,stderr:"",exitCode:0};let n,i,c=e.stdin;if(r.code!==null)n=r.code,i="-c";else if(r.module!==null){if(!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(r.module))return{stdout:"",stderr:`python3: No module named '${r.module.slice(0,200)}'
|
|
11
|
+
`,exitCode:1};n=`import runpy; runpy.run_module('${r.module}', run_name='__main__')`,i=r.module}else if(r.scriptFile==="-")n=C(e.stdin),c="",i="-";else if(r.scriptFile!==null){let p=e.fs.resolvePath(e.cwd,r.scriptFile);if(!await e.fs.exists(p))return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': [Errno 2] No such file or directory
|
|
12
|
+
`,exitCode:2};try{n=await e.fs.readFile(p),i=r.scriptFile}catch(h){let a=A(h.message);return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': ${a}
|
|
13
|
+
`,exitCode:2}}}else if(C(e.stdin).trim())n=C(e.stdin),c="",i="<stdin>";else return{stdout:"",stderr:`python3: no input provided (use -c CODE, -m MODULE, or provide a script file)
|
|
14
|
+
`,exitCode:2};return N(n,c,e,i,r.scriptArgs)}},se={name:"python",async execute(t,e){return V.execute(t,e)}};export{ne as _resetExecutionQueue,V as python3Command,se as pythonCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-KXWWWQZK.js";import"./chunk-WDV2ECOC.js";import"./chunk-3MRB66F4.js";import"./chunk-XAVWLYZR.js";import"./chunk-CB4SODHK.js";import"./chunk-BNYIXXC2.js";import"./chunk-46CDVHZ3.js";import"./chunk-CPTQXTBJ.js";import"./chunk-H4BRFPKY.js";import"./chunk-43E7AR6A.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{b as flagsForFuzzing,a as rgCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b,c}from"./chunk-
|
|
3
|
+
import{a,b,c}from"./chunk-6UK23ZFT.js";import"./chunk-7I6MNC5I.js";import"./chunk-SSK3N7FN.js";import"./chunk-4SQKKW2M.js";import"./chunk-46CDVHZ3.js";import"./chunk-H4BRFPKY.js";import"./chunk-43E7AR6A.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{a as _internals,c as flagsForFuzzing,b as sqlite3Command};
|
|
@@ -2661,10 +2661,19 @@ def _redir_scandir(path='.'):
|
|
|
2661
2661
|
return _orig_scandir(path)
|
|
2662
2662
|
os.scandir = _redir_scandir
|
|
2663
2663
|
|
|
2664
|
-
# io.open
|
|
2664
|
+
# io.open and io.open_code
|
|
2665
2665
|
import io as _io_module
|
|
2666
2666
|
_io_module.open = builtins.open
|
|
2667
2667
|
|
|
2668
|
+
# runpy uses io.open_code rather than builtins.open/io.open. Redirect it
|
|
2669
|
+
# separately so code loading keeps the logical path in __file__ and argv.
|
|
2670
|
+
_orig_open_code = _io_module.open_code
|
|
2671
|
+
def _redir_open_code(path):
|
|
2672
|
+
if _should_redirect(path):
|
|
2673
|
+
path = '/host' + path
|
|
2674
|
+
return _orig_open_code(path)
|
|
2675
|
+
_io_module.open_code = _redir_open_code
|
|
2676
|
+
|
|
2668
2677
|
# shutil
|
|
2669
2678
|
import shutil as _shutil_module
|
|
2670
2679
|
|
|
@@ -3068,10 +3077,17 @@ async function runPython(input) {
|
|
|
3068
3077
|
const pendingStderr = [];
|
|
3069
3078
|
let Module;
|
|
3070
3079
|
try {
|
|
3080
|
+
let stdinOffset = 0;
|
|
3081
|
+
const readStdin = wrapWasmCallback(
|
|
3082
|
+
"python3-worker",
|
|
3083
|
+
"stdin",
|
|
3084
|
+
() => stdinOffset < input.stdin.length ? input.stdin.charCodeAt(stdinOffset++) : null
|
|
3085
|
+
);
|
|
3071
3086
|
const onPreRun = wrapWasmCallback(
|
|
3072
3087
|
"python3-worker",
|
|
3073
3088
|
"preRun",
|
|
3074
3089
|
(mod) => {
|
|
3090
|
+
mod.FS.init(readStdin);
|
|
3075
3091
|
mod.FS.mkdirTree("/lib");
|
|
3076
3092
|
mod.FS.writeFile("/lib/python313.zip", cachedStdlibZip);
|
|
3077
3093
|
mod.ENV.PYTHONHOME = "/";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-TROO33BG.js";import"./chunk-VTAIIBJT.js";import"./chunk-LGERQ5TD.js";import"./chunk-D5G3L4PR.js";import"./chunk-WDV2ECOC.js";import"./chunk-MROECM42.js";import"./chunk-4SQKKW2M.js";import"./chunk-CB4SODHK.js";import"./chunk-O74FSWB4.js";import"./chunk-BNYIXXC2.js";import"./chunk-46CDVHZ3.js";import"./chunk-VLWZ6L7C.js";import"./chunk-CPTQXTBJ.js";import"./chunk-7JZKVC3F.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{b as flagsForFuzzing,a as xanCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a,b}from"./chunk-
|
|
3
|
+
import{a,b}from"./chunk-DKIOFM35.js";import"./chunk-LGERQ5TD.js";import"./chunk-D5G3L4PR.js";import"./chunk-WDV2ECOC.js";import"./chunk-MROECM42.js";import"./chunk-4SQKKW2M.js";import"./chunk-CB4SODHK.js";import"./chunk-46CDVHZ3.js";import"./chunk-VLWZ6L7C.js";import"./chunk-CPTQXTBJ.js";import"./chunk-LCP3IKI7.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";export{b as flagsForFuzzing,a as yqCommand};
|