@omfalos/mokosh 0.3.2 → 0.3.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.
package/dist/index.mjs CHANGED
@@ -1,32 +1,34 @@
1
- var Be=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import In from"path";import{fileURLToPath as Mn}from"url";var Dn=()=>Mn(import.meta.url),Rn=()=>In.dirname(Dn()),m=Rn();import Je from"fs";import Wt from"path";var An=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Lt=[];function he(t){Lt.push(t)}function Ot(t){return[...An,...Lt].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Ln=[".test.",".spec.","-test.","-spec."],Gt=[];function ye(t){Gt.push(t)}function Y(){return[...Ln,...Gt]}var On=["jest","vitest","playwright","cypress","@testing-library/"],_t=[];function xe(t){_t.push(t)}function Ue(){return[...On,..._t]}var jt=.8;function Ke(t){jt=t}function Ve(){return jt}var Gn=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function He(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=Wt.resolve(t);return Je.existsSync(n)?n.endsWith(".json")?$t(n):e?zt(n):{}:{}}for(let n of Gn){let s=Wt.resolve(t,n);if(Je.existsSync(s)){if(n.endsWith(".json"))return $t(s);if(e)return zt(s)}}return{}}function $t(t){return JSON.parse(Je.readFileSync(t,"utf-8"))}function zt(t){let e=Be(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function _n(t){for(let e of t.configMatchers??[])he(e);for(let e of t.testPatterns??[])ye(e);for(let e of t.testLibraries??[])xe(e);t.barrelThreshold!==void 0&&Ke(t.barrelThreshold)}function jn(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases}}var X=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],Qe=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];import Wn from"fs";import Bt from"path";function $n(t,e){let r=Bt.resolve(t,e);try{let n=Wn.readFileSync(r,"utf-8"),s=JSON.parse(n),i=new Map;for(let[o,a]of Object.entries(s)){if(o==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let l=Bt.relative(t,o);i.set(l,c)}return i}catch{return new Map}}var Ye={serialize(t){let e=["graph TD"],r=new Set;for(let n of t.nodes.values()){let s=`"${n.path}"`;for(let i of n.imports){if(!i.toPath)continue;let o=`"${i.toPath}"`,a=`${n.path} -> ${i.toPath}`;if(!r.has(a)){let c=i.isStyle?"-- styles -->":"-->";e.push(` ${s} ${c} ${o}`),r.add(a)}}}return e.join(`
2
- `)}};function Ut(t){return Ye.serialize(t)}import Kt from"fs";import zn from"path";function Xe(t,e){let r=t.replace(/^\.\//,"");if(e.nodes.has(r))return r;let n=r.replace(/^dist\//,"src/").replace(/\.(js|mjs|cjs)$/,".ts");return e.nodes.has(n)?n:null}function Vt(t,e){if(typeof t=="string")return Xe(t,e);if(t&&typeof t=="object"){let r=t;for(let n of["import","require","default"]){let s=Vt(r[n],e);if(s)return s}}return null}function Bn(t){if(!t)return"unknown";let e=t.trimStart();return e.startsWith("interface ")?"interface":e.startsWith("class ")?"class":e.startsWith("enum ")?"enum":e.startsWith("type ")?"type":e.startsWith("namespace ")?"namespace":e.startsWith("const ")||e.startsWith("let ")||e.startsWith("var ")||e.startsWith("readonly ")?"const":e.startsWith("(")||e.startsWith("async ")||e.startsWith("function ")||e.includes("=>")?"function":"unknown"}function Un(t,e){let r=new Set,n=new Set,s=[...e];for(;s.length;){let i=s.shift();if(n.has(i))continue;n.add(i);let o=t.nodes.get(i);if(o){for(let a of o.exports)r.add(a.name);for(let a of o.imports){if(a.type!=="re-export"||a.isExternal||!a.toPath)continue;if(!a.symbols?.length||a.symbols.includes("*")){let l=t.nodes.get(a.toPath);if(l)for(let p of l.exports)r.add(p.name);s.push(a.toPath)}else for(let l of a.symbols)r.add(l)}}}return r}function Kn(t,e){return Jt(t,e)[0]??null}function Jt(t,e){let r=[],n=zn.join(e,"package.json");if(Kt.existsSync(n))try{let s=JSON.parse(Kt.readFileSync(n,"utf8"));if(s.exports&&typeof s.exports=="object"&&!Array.isArray(s.exports))for(let i of Object.values(s.exports)){let o=Vt(i,t);o&&!r.includes(o)&&r.push(o)}else if(typeof s.exports=="string"){let i=Xe(s.exports,t);i&&r.push(i)}if(r.length===0)for(let i of[s.main,s.module].filter(Boolean)){let o=Xe(i,t);o&&!r.includes(o)&&r.push(o)}}catch{}if(r.length===0){for(let s of["src/index.ts","src/index.js","index.ts","index.js"])if(t.nodes.has(s)){r.push(s);break}}return r}function Vn(t,e){let r=new Set(e);for(let n of e)t.traverse(n,s=>(r.add(s.path),!0),{direction:"outgoing"});return r}function Jn(t,e,r){let n=new Map;for(let s of e){if(r.includes(s))continue;let i=t.nodes.get(s);if(!i)continue;let o=i.category==="barrel";for(let a of i.exports){let c=n.get(a.name),l=!!(a.signature||a.doc);(!c||l&&!o)&&n.set(a.name,{file:s,symbol:a})}}return n}function Hn(t,e,r,n){let s=[];for(let i of t){let o=e.get(i),a=n.flatMap(g=>r.nodes.get(g)?.exports??[]).find(g=>g.name===i),c=o?.symbol??a,l=o?.file??n.find(g=>r.nodes.get(g)?.exports.some(d=>d.name===i))??n[0],p={name:i,definedIn:l,kind:Bn(c?.signature)};c?.doc&&(p.doc=c.doc),c?.signature&&(p.signature=c.signature),s.push(p)}return s.sort((i,o)=>i.name.localeCompare(o.name)),s}function Qn(t,e,r){let n=c=>t.nodes.get(c)?.category==="test",s=[...e].filter(c=>!r.includes(c)&&!n(c)),i=[...t.nodes.keys()].filter(c=>!e.has(c)),o=i.filter(c=>!n(c)),a=i.filter(c=>n(c));return{internalFiles:s,unreachableFromEntry:o,testFiles:a}}function Yn(t,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let l of e)if(!t.nodes.has(l))throw new Error(`Entry point not found in graph: ${l}`);let r=Vn(t,e),n=Jn(t,r,e),s=Un(t,e),i=Hn(s,n,t,e),{internalFiles:o,unreachableFromEntry:a,testFiles:c}=Qn(t,r,e);return{entryPoints:e,publicExports:i,internalFiles:o,unreachableFromEntry:a,testFiles:c}}function Xn(t,e){let r=null,n=[];for(let i of t.nodes.values()){i.exports.some(o=>o.name===e)&&(r=i.path);for(let o of i.callEdges??[])o.to===e&&n.push({file:i.path,callerFunction:o.from})}let s=[];if(r){let i=t.nodes.get(r);for(let o of i?.callEdges??[])o.from===e&&s.push({file:o.toFile,calleeFunction:o.to})}return{functionName:e,definedIn:r,callers:n,callees:s}}import Z from"fs";import Zn from"path";function Ze(t){let e=[...t.nodes.entries()].sort(([n],[s])=>n.localeCompare(s)).map(([n,s])=>`${n}:${s.mtime}:${s.size}`).join("|"),r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=Math.imul(r,16777619)>>>0;return r.toString(16).padStart(8,"0")}function qn(t){let e=new Map;for(let r of t.nodes.keys()){let n=[];t.traverse(r,s=>(s.path!==r&&n.push(s.path),!0),{direction:"incoming"}),e.set(r,n)}return{impact:e,graphHash:Ze(t)}}function es(t,e){return t.impact.get(e)??[]}function ts(t,e){return t.graphHash===Ze(e)}function rs(t,e){let r=Zn.dirname(e);Z.existsSync(r)||Z.mkdirSync(r,{recursive:!0});let n={graphHash:t.graphHash,impact:[...t.impact.entries()]};Z.writeFileSync(e,JSON.stringify(n))}function ns(t){if(!Z.existsSync(t))return null;try{let e=Z.readFileSync(t,"utf-8"),r=JSON.parse(e);return{graphHash:r.graphHash,impact:new Map(r.impact)}}catch{return null}}import{readFile as Ws}from"fs/promises";import rt from"path";import Se from"fs";import ss from"path";import{load as Ht}from"js-yaml";var qe=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function Qt(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function is(t){return t.replace(/:$/,"").split(",").map(e=>{let r=e.trim();return r.startsWith('"')&&(r=r.slice(1)),r.endsWith('"')&&(r=r.slice(0,-1)),Qt(r)}).filter(Boolean)}function os(t,e){let r=t.startsWith("/")?t.slice(1):t,n=r.lastIndexOf("@");return n>0?{name:r.substring(0,n),version:e||r.substring(n+1)}:{name:r,version:e}}function as(t){try{let e=Ht(t),r={dependencies:{}};for(let[n,s]of Object.entries(e))if(!(n==="__metadata"||!s?.version))for(let i of n.split(", ")){let o=Qt(i);o&&(r.dependencies[o]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function cs(t){let e={dependencies:{}};for(let r of t.split(/\n\n+/)){let n=r.split(`
3
- `).filter(c=>c.trim().length>0&&!c.trim().startsWith("#"));if(n.length<2)continue;let s=n[0];if(!s||s.startsWith(" "))continue;let i=is(s);if(i.length===0)continue;let a=n.find(c=>c.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let c of i)e.dependencies[c]={version:a}}return e}function ls(t){let e=Se.readFileSync(t,"utf-8"),r=JSON.parse(e),n={dependencies:{}};if(r.packages)for(let[s,i]of Object.entries(r.packages)){if(!s.startsWith("node_modules/"))continue;let o=s.replace("node_modules/","");o.includes("node_modules/")||(n.dependencies[o]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}else if(r.dependencies)for(let[s,i]of Object.entries(r.dependencies))n.dependencies[s]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}};return n}function ps(t){let e=Se.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=as(e);if(r!==null)return r}return cs(e)}function fs(t){let e=Se.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=Ht(e);if(n.packages)for(let[s,i]of Object.entries(n.packages)){let{name:o,version:a}=os(s,i.version);o&&(r.dependencies[o]={version:a,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}if(n.dependencies)for(let[s,i]of Object.entries(n.dependencies)){if(r.dependencies[s])continue;let o=typeof i=="string"?i:i.version;r.dependencies[s]={version:o||""}}}catch{}return r}function Yt(t){let e={"package-lock.json":ls,"yarn.lock":ps,"pnpm-lock.yaml":fs},r=qe.map(n=>[n,e[n]]);for(let[n,s]of r){let i=ss.join(t,n);if(Se.existsSync(i))return s(i)}return null}var ms=new Set(["css","scss","less","stylus"]);function Xt(t){return ms.has(t)?"style":"code"}function us(t){let e=5381;for(let r=0;r<t.length;r++)e=e*33+t.charCodeAt(r)>>>0;return e.toString(36)}function gs(t,e){let r=[];for(let n=0;n<=t.length-e;n++)r.push(us(t.slice(n,n+e).map(s=>s.text).join(" ")));return r}function ds(t,e,r){let n=t.get(e.file),s=t.get(r.file);if(!n||!s)return 0;let i=0;for(;e.windowIndex+i+1<n.length&&r.windowIndex+i+1<s.length&&n[e.windowIndex+i+1]===s[r.windowIndex+i+1];)i++;return i}function hs(t,e,r){if(e.windowIndex===0||r.windowIndex===0)return!0;let n=t.get(e.file),s=t.get(r.file);return!n||!s?!0:n[e.windowIndex-1]!==s[r.windowIndex-1]}var et=class{parent=new Map;find(e){this.parent.has(e)||this.parent.set(e,e);let r=e;for(;this.parent.get(r)!==r;)r=this.parent.get(r);let n=e;for(;n!==r;){let s=this.parent.get(n);this.parent.set(n,r),n=s}return r}union(e,r){let n=this.find(e),s=this.find(r);n!==s&&this.parent.set(n,s)}root(e){return this.find(e)}};function be(t){return`${t.file}#${t.startLine}#${t.endLine}`}var ys=new Set(["{","}",":",",","[","]"]);function xs(t,e,r){let n=0;for(let s=e;s<e+r;s++)ys.has(t[s].text)&&n++;return n/r}function Zt(t,e,r,n=.5){let s=new Map,i=new Map,o=new Map;for(let{file:d,tokens:h}of t){if(h.length<e)continue;i.set(d,h);let x=gs(h,e);s.set(d,x);for(let y=0;y<x.length;y++){let S={file:d,windowIndex:y},E=o.get(x[y]);E?E.push(S):o.set(x[y],[S])}}let a=[];for(let d of o.values())if(!(d.length<2))for(let h=0;h<d.length;h++)for(let x=h+1;x<d.length;x++){let y=d[h],S=d[x];if(y.file===S.file&&y.windowIndex===S.windowIndex||!hs(s,y,S))continue;let E=ds(s,y,S),P=e+E,I=i.get(y.file);if(xs(I,y.windowIndex,P)>n)continue;if(y.file===S.file){let[Nn,Pn]=y.windowIndex<S.windowIndex?[y,S]:[S,y];if(Nn.windowIndex+P>Pn.windowIndex)continue}let O=i.get(S.file),$e={file:y.file,startLine:I[y.windowIndex].line,endLine:I[y.windowIndex+P-1].line},ze={file:S.file,startLine:O[S.windowIndex].line,endLine:O[S.windowIndex+P-1].line},At=Math.min($e.endLine-$e.startLine+1,ze.endLine-ze.startLine+1);At<r||a.push({occA:$e,occB:ze,lines:At,tokens:P})}let c=new et,l=new Map;for(let{occA:d,occB:h}of a){let x=be(d),y=be(h);l.set(x,d),l.set(y,h),c.union(x,y)}let p=new Map;for(let d of l.keys()){let h=c.root(d),x=p.get(h);x?x.add(d):p.set(h,new Set([d]))}let g=[];for(let d of p.values()){if(d.size<2)continue;let h=[...d].map(S=>l.get(S)),x=0,y=e;for(let S of a)!d.has(be(S.occA))||!d.has(be(S.occB))||S.lines>x&&(x=S.lines,y=S.tokens);g.push({occurrences:h,lines:x,tokens:y})}return g.sort((d,h)=>h.lines-d.lines)}import er from"postcss";import*as Ss from"postcss-less";var bs=Ss,tr=new Set(["reference","inline"]);function qt(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function vs(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function ks(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let i=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=tr.has(i)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...qt(o)?{isExternal:!0}:{}}}let n=t.match(/^url\(['"]?([^'")]+)['"]?\)/),s=n?n[1]?.trim()??"":t.match(/^['"]([^'"]+)['"]/)?.[1]??"";return s?{fromPath:e,toPath:"",rawSpecifier:s,isStyle:!0,type:"static",...qt(s)?{isExternal:!0}:{}}:null}function Cs(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let i=s[1]?.trim()??"";vs(i)&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function rr(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=ks(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...Cs(n.value,e))}),r}function Es(t){return t.replace(/(?<!:)\/\/.*/g,"")}function ws(t,e){let r=[],n=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let i=s[1]?.trim()??"",o=s[2]??"";if(o){let a=tr.has(i)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}s=n.exec(t)}return r}function ve(t,e){let r=er.parse(Es(t));return{imports:rr(r,e),root:r}}function Fs(t){let e=[],r=[];for(let n of t.nodes??[]){if(n.type!=="atrule")continue;let{value:s}=n;if(s===void 0)continue;let i=n.name;i&&(e.push({name:i}),r.push({name:i,kind:"variable"}))}return{exports:e,tags:r}}function ke(t,e){try{let r=bs.parse(t),{exports:n,tags:s}=Fs(r);return{imports:rr(r,e),root:r,exports:n,tags:s}}catch{return{imports:ws(t,e),root:er.parse(""),exports:[],tags:[]}}}import{parse as Ts}from"postcss-scss";function nr(t){return t.startsWith("_")||t.startsWith("-")}function Ns(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function Ps(t){let e=t.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let r=e[1],s=t.match(/\bas\s+(\S+)/)?.[1];return s!==void 0?{specifier:r,alias:s}:{specifier:r}}function Is(t){let e=[],r=[];for(let n of t.nodes??[]){if(n.type==="decl"&&n.prop.startsWith("$")){let s=n.prop.slice(1);if(!s||nr(s))continue;e.push({name:s}),r.push({name:s,kind:"variable"});continue}if(n.type==="atrule"&&(n.name==="mixin"||n.name==="function")){let i=n.params.match(/^([\w-]+)/)?.[1];if(!i||nr(i))continue;let o=n.params.trim();e.push(o.includes("(")?{name:i,signature:o}:{name:i}),r.push({name:i,kind:"function"})}}return{exports:e,tags:r}}function Ce(t,e){let r=Ts(t),n=[];r.walk(o=>{if(o.type!=="atrule")return;let{name:a,params:c}=o;if(a!=="import"&&a!=="use"&&a!=="forward")return;let{specifier:l,alias:p}=Ps(c);if(!l)return;let g={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...Ns(l)?{isExternal:!0}:{}};p&&(g.symbols=[p]),n.push(g)});let{exports:s,tags:i}=Is(r);return{imports:n,root:r,exports:s,tags:i}}function Ms(t){return t.trim().replace(/\s+/g," ")}function Ds(t){try{return t.fileType==="scss"?Ce(t.source,t.file).root:t.fileType==="less"?ke(t.source,t.file).root:t.fileType==="css"?ve(t.source,t.file).root:void 0}catch{return}}function Rs(t){let e=Ds(t);if(!e)return[];let r=[];return e.walkRules(n=>{let s=n.nodes?.filter(p=>p.type==="decl")??[];if(s.length===0)return;let i=s[0],o=s[s.length-1],a=n.source?.start?.line??i?.source?.start?.line,c=o?.source?.end?.line??o?.source?.start?.line??a;if(a===void 0||c===void 0)return;let l=s.map(p=>`${p.prop.trim().toLowerCase()}:${Ms(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function sr(t,e,r=2){let n=new Map;for(let i of t)for(let o of Rs(i)){if(o.declCount<r||o.lines<e)continue;let a=n.get(o.signature);a?a.push(o):n.set(o.signature,[o])}let s=[];for(let i of n.values())for(let o=0;o<i.length;o++)for(let a=o+1;a<i.length;a++){let c=i[o],l=i[a];if(c.file===l.file&&c.startLine===l.startLine&&c.endLine===l.endLine)continue;let p={file:c.file,startLine:c.startLine,endLine:c.endLine},g={file:l.file,startLine:l.startLine,endLine:l.endLine};s.push({occurrences:[p,g],lines:Math.min(c.lines,l.lines),tokens:c.declCount,family:"style"})}return s.sort((i,o)=>o.lines-i.lines)}var As={typescript:{line:["//"],block:[["/*","*/"]]},javascript:{line:["//"],block:[["/*","*/"]]},go:{line:["//"],block:[["/*","*/"]]},css:{block:[["/*","*/"]]},scss:{line:["//"],block:[["/*","*/"]]},less:{line:["//"],block:[["/*","*/"]]},stylus:{line:["//"],block:[["/*","*/"]]},python:{line:["#"]},gherkin:{line:["#"]},coffeescript:{line:["#"],block:[["###","###"]]},livescript:{line:["#"],block:[["###","###"]]},lua:{line:["--"],block:[["--[[","]]"]]},markdown:{block:[["<!--","-->"]]}};function ir(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function Ls(t,e){if(!e)return t;let r=t;for(let[n,s]of e.block??[]){let i=0;for(;;){let o=r.indexOf(n,i);if(o===-1)break;let a=r.indexOf(s,o+n.length),c=a===-1?r.length:a+s.length;r=ir(r,o,c),i=c}}for(let n of e.line??[]){let s=0;for(;;){let i=r.indexOf(n,s);if(i===-1)break;let o=r.indexOf(`
4
- `,i),a=o===-1?r.length:o;r=ir(r,i,a),s=a}}return r}var Os=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],tt=new RegExp(`${Os.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),Gs=/^[A-Za-z_$][A-Za-z0-9_$]*$/,or=/^\d+(?:\.\d+)?$/,_s=/^(".*"|'.*'|`.*`)$/s,js=new Set(["if","else","elif","for","while","do","switch","case","default","break","continue","return","function","def","class","struct","interface","const","let","var","local","import","export","from","package","try","catch","except","finally","throw","raise","new","this","self","end","then","yield","async","await","nil","null","None","true","false","True","False","and","or","not","in","of","is"]);function ar(t,e,r=!0){let n=Ls(t,As[e]),s=[],i=1,o=0;tt.lastIndex=0;let a=tt.exec(n);for(;a!==null;){for(let p=o;p<a.index;p++)n[p]===`
5
- `&&i++;o=a.index;let c=a[0],l=c;Gs.test(c)&&!js.has(c)?l="ID":r&&(or.test(c)||_s.test(c))&&(l=or.test(c)?"NUM":"STR"),s.push({text:l,line:i});for(let p=o;p<a.index+c.length;p++)n[p]===`
6
- `&&i++;o=a.index+c.length,a=tt.exec(n)}return s}var $s=new Set(["css","scss","less"]);function zs(t){return qe.includes(rt.basename(t))}function Bs(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(rt.sep).some(n=>r.has(n))}async function Us(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:i=!0,maxPunctuationRatio:o=.5,limit:a=50,ignoreDirs:c=X}=r,l=[...t.nodes.values()].filter(h=>!zs(h.path)&&!Bs(h.path,c)),p=[],g=new Map;await Promise.all(l.map(async h=>{let x;try{x=await Ws(rt.join(e,h.path),"utf8")}catch{return}if($s.has(h.type)){p.push({file:h.path,source:x,fileType:h.type});return}let y=Xt(h.type),S={file:h.path,tokens:ar(x,h.type,i)},E=g.get(y);E?E.push(S):g.set(y,[S])}));let d=sr(p,n);for(let[h,x]of g)for(let y of Zt(x,s,n,o))d.push({...y,family:h});return d.sort((h,x)=>x.lines-h.lines).slice(0,a)}import Ee from"path";function Ks(t){let e=new Map;for(let[r,n]of t){let s=n.imports.filter(i=>i.toPath&&!i.isExternal).length;s>0&&e.set(r,s)}return e}function Vs(t,e,r){let n=new Map;for(let[s,i]of e){if(i<r)continue;let o=t.get(s);if(!o||o.category==="test"||o.category==="barrel")continue;let a=Ee.extname(s),c=Ee.basename(s,a),l=c==="index"?Ee.basename(Ee.dirname(s)):c;n.set(s,{path:s,outDegree:i,tag:`feature:${l}`})}return n}function q(t,e){let r=e?.minOutDegree??5;return Vs(t,Ks(t),r)}var Js=(t,e)=>t.outDegree-e.outDegree;function Hs(t,e){let r=new Map;for(let n of e.values()){let s=new Set;t.traverse(n.path,i=>(i.path!==n.path&&s.add(i.path),!0),{direction:"outgoing"}),r.set(n.path,s)}return r}function Qs(t,e,r,n){let s=new Map;for(let[i]of t){if(e.has(i))continue;let o=null;for(let a of e.values())r.get(a.path)?.has(i)&&(!o||n(a,o)<0)&&(o=a);o&&s.set(i,o.path)}return s}function Ys(t,e){let r=new Map;for(let n of t.values()){let s=n.tag.replace("feature:",""),i=[];for(let[o,a]of e)a===n.path&&i.push(o);r.set(s,{hub:n.path,outDegree:n.outDegree,files:i})}return r}function Xs(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function nt(t,e){let r=e?.detectFn??q,n=e?.hubComparator??Js,s=r(t.nodes,e),i=Hs(t,s),o=Qs(t.nodes,s,i,n);return{features:Ys(s,o),unassigned:Xs(t.nodes,s,o)}}var cr=new Set(["typescript","javascript","python","go","scss","less","lua","coffeescript"]),lr=new Set(["typescript","javascript","python"]),we=new Set(["typescript","javascript","go","python"]);function Zs(t){let e=new Map;for(let r of t.nodes.values())e.set(r.type,(e.get(r.type)??0)+1);return[...e.entries()].map(([r,n])=>({type:r,fileCount:n,exportsTracked:cr.has(r),importSymbolsTracked:lr.has(r),callEdgesTracked:we.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}var ee=class{constructor(e){this.nodes=e}nodes;findUnusedFiles(e){let r=new Set(this.nodes.keys());return e.filter(n=>!r.has(n))}findHighExportUsage(e){let r=[];for(let n of this.nodes.values()){if(n.maxExportUsage===void 0||n.maxExportUsage<e)continue;let s=n.imports.reduce((i,o)=>(o.exportUsageRatio??0)>(i?.exportUsageRatio??0)?o:i,null);r.push({path:n.path,maxExportUsage:n.maxExportUsage,tightestDep:s?.toPath??""})}return r.sort((n,s)=>s.maxExportUsage-n.maxExportUsage)}findCycles(){let e=[],r=new Set,n=new Set,s=[],i=o=>{r.add(o),n.add(o),s.push(o);let a=this.nodes.get(o);if(a){for(let c of a.imports)if(!(!c.toPath||c.isExternal))if(n.has(c.toPath)){let l=s.indexOf(c.toPath);e.push([...s.slice(l),c.toPath])}else r.has(c.toPath)||i(c.toPath)}n.delete(o),s.pop()};for(let o of this.nodes.keys())r.has(o)||i(o);return e}};var G=class t{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let r=new Map;for(let n of e.nodes)r.set(n.path,n);return new t(r)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.imports)if(n.toPath){let s=e.get(n.toPath)||[];s.push(r.path),e.set(n.toPath,s)}return this._incomingEdgesCache=e,e}dfs(e,r,n,s){let i=new Set,o=n.maxDepth??1/0,a=(c,l,p)=>{if(l>o||i.has(c))return;let g=this.nodes.get(c);if(g&&(i.add(c),r(g,l,p)!==!1))for(let d of s(c))a(d,l+1,c)};a(e,0,null)}traverse(e,r,n={}){let s=n.direction??"outgoing",i=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,r,n,o=>s==="outgoing"?this.nodes.get(o)?.imports.map(a=>a.toPath).filter(Boolean)??[]:i?.get(o)??[])}getCallIncomingCache(){if(this._callIncomingCache)return this._callIncomingCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.callEdges??[]){let s=e.get(n.toFile)??[];s.push(r.path),e.set(n.toFile,s)}return this._callIncomingCache=e,e}traverseCalls(e,r,n={}){let s=n.direction??"outgoing",i=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,r,n,o=>s==="outgoing"?this.nodes.get(o)?.callEdges?.map(a=>a.toFile)??[]:i?.get(o)??[])}getCallers(e){let r=[];return this.traverseCalls(e,n=>(n.path!==e&&r.push(n.path),!0),{direction:"incoming",maxDepth:1}),r}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let r=this.nodes.get(e);return r?r.imports.map(n=>this.nodes.get(n.toPath)).filter(n=>n!==void 0):[]}findUnusedFiles(e){return new ee(this.nodes).findUnusedFiles(e)}findCycles(){return new ee(this.nodes).findCycles()}};var _=class{affectedSymbols=new Map;constructor(e,r){this.affectedSymbols.set(e,new Set(["default",...r]))}updateAffectedSymbols(e,r){let n=this.affectedSymbols.get(r)||new Set,s=e.imports.find(c=>c.toPath===r);if(!s)return!1;let i=s.symbols||["*"],o=new Set;for(let c of i)(c==="*"||n.has("*")||n.has(c))&&o.add("*");if(o.size===0)return!1;let a=this.affectedSymbols.get(e.path)||new Set;for(let c of o)a.add(c);return this.affectedSymbols.set(e.path,a),!0}};function qs(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function ei(t,e,r=1){let n=[];return t.traverse(e,(s,i,o)=>{if(s.path===e)return!0;let a=o?t.nodes.get(o)?.imports.find(c=>c.toPath===s.path):void 0;return n.push({path:s.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:r}),n}function st(t,e){let r=[];return t.traverse(e,n=>{if(n.path===e)return!0;let s=n.imports.find(i=>i.toPath===e);return r.push({path:n.path,...s?.symbols?{symbols:s.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),r}function ti(t,e,r={}){let{testsOnly:n=!1,changedSymbols:s}=r,i=s?new _(e,s):null,o=[];return t.traverse(e,(a,c,l)=>{if(a.path===e)return!0;if(i&&l&&!i.updateAffectedSymbols(a,l))return!1;let p=a.category==="test"||a.tags.some(g=>g.name==="test");return(!n||p)&&o.push(a.path),!0},{direction:"incoming"}),o}function ri(t,e,r={}){let{depth:n=1,withEdgeDetail:s=!1}=r,i=[];return t.traverseCalls(e,o=>{if(o.path===e)return!0;let a={file:o.path};return s&&(a.edges=(o.callEdges??[]).filter(c=>c.toFile===e).map(c=>({from:c.from,to:c.to}))),i.push(a),!0},{direction:"incoming",maxDepth:n}),i}function ni(t,e={}){let{metric:r="cognitiveComplexity",threshold:n=10,limit:s=20}=e;return[...t.nodes.values()].flatMap(i=>(i.functions??[]).filter(o=>o[r]>=n).map(o=>({file:i.path,name:o.name,line:o.line,complexity:o.complexity,cognitiveComplexity:o.cognitiveComplexity}))).sort((i,o)=>o[r]-i[r]).slice(0,s)}function si(t){return{nodes:t.nodes.map(r=>({path:r.path,type:r.type,category:r.category,exports:r.exports.map(n=>n.name),tags:r.tags.filter(n=>n.kind==="comment-marker"||n.kind==="import").map(n=>n.name),importsFiles:r.imports.filter(n=>!n.isExternal&&n.toPath).map(n=>n.toPath),...r.description!==void 0&&{description:r.description},...r.testedBy!==void 0&&{testedBy:r.testedBy},...r.coveragePct!==void 0&&{coveragePct:r.coveragePct},...r.avgExportUsage!==void 0&&{avgExportUsage:r.avgExportUsage},...r.maxExportUsage!==void 0&&{maxExportUsage:r.maxExportUsage}})),cycles:t.cycles}}function ii(t){let e=t.getPackageDependencies(),r=Array.from(t.packages.values()).map(({graph:n,pkg:s})=>({name:s.name,relativeRoot:s.relativeRoot,nodeCount:n.nodes.size,dependsOn:e.get(s.name)??[]}));return{monorepoType:t.type,packageCount:r.length,packages:r}}function oi(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function pr(t){if(t.category==="test")return"test";if(t.category==="config")return"config";if(t.category==="type-only")return"types";let e=t.path;return v(e,"component")||v(e,"components")?"component":v(e,"controller")||v(e,"controllers")?"controller":v(e,"middleware")?"middleware":v(e,"router")||v(e,"routes")||v(e,"route")?"router":v(e,"store")||v(e,"stores")?"store":v(e,"service")||v(e,"services")?"service":v(e,"handler")||v(e,"handlers")?"handler":v(e,"adapter")||v(e,"adapters")?"adapter":v(e,"plugin")||v(e,"plugins")?"plugin":v(e,"api")?"api":v(e,"cli")||v(e,"commands")||te(e)==="cli"?"cli":v(e,"util")||v(e,"utils")||v(e,"helper")||v(e,"helpers")?"util":v(e,"model")||v(e,"models")||te(e)==="model"?"model":v(e,"parser")||v(e,"parsers")||te(e)==="parser"?"parser":te(e)==="builder"?"builder":te(e)==="resolver"?"resolver":"other"}function v(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function te(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function ai(t,e){let r=nt(t,e),n=new Map;for(let[i,o]of r.features){for(let a of o.files)n.set(a,i);n.set(o.hub,i)}let s=new Map;for(let i of t.nodes.values()){let o=n.get(i.path);s.set(i.path,{path:i.path,role:pr(i),...i.description?{description:i.description}:{},exports:i.exports.map(a=>a.name),...o?{featureHub:o}:{}})}return s}function ci(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if(we.has(n.type)){let s=[];for(let i of t.nodes.values())for(let o of i.callEdges??[])o.to===e&&s.push({file:i.path,callerFunction:o.from});r.push({path:n.path,category:n.category,precision:"call",callers:s})}else{let s=st(t,n.path).map(i=>({file:i.path,...i.symbols?{symbols:i.symbols}:{}}));r.push({path:n.path,category:n.category,precision:"file-level",importers:s})}return r}function li(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function pi(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function fi(t){let e=new Map;for(let n of t.nodes.values())if(!(n.type!=="typescript"&&n.type!=="javascript"))for(let s of n.exports){if(!pi(s,n.category))continue;let i=`${n.path}::${s.name}`;e.set(i,{name:s.name,file:n.path,kind:li(s.signature),...s.doc?{doc:s.doc}:{}})}let r=[];for(let n of t.nodes.values())if(!(n.type!=="typescript"&&n.type!=="javascript")){for(let s of n.imports)if(!(!s.toPath||s.isExternal||!s.symbols?.length))for(let i of s.symbols)e.has(`${s.toPath}::${i}`)&&r.push({fromFile:n.path,toType:i,toFile:s.toPath})}return{types:e,edges:r}}function mi(t,e){let r=null;for(let i of t.types.values())if(i.name===e){r=i;break}if(!r)return{type:null,usedByFiles:[],uses:[]};let n=new Set,s=new Map;for(let i of t.edges)if(i.toType===e&&i.toFile===r.file&&n.add(i.fromFile),i.fromFile===r.file){let o=t.types.get(`${i.toFile}::${i.toType}`);o&&s.set(`${o.file}::${o.name}`,o)}return{type:r,usedByFiles:Array.from(n),uses:Array.from(s.values())}}import Ei from"path";import ot from"fs";import gr from"path";import re from"fs";import T from"path";import fr from"fs";import ep from"path";function mr(t){try{return fr.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Fe(t){try{return fr.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function it(t,e){let r=T.join(e,"package.json");if(!re.existsSync(r))return null;let n={};try{n=JSON.parse(re.readFileSync(r,"utf-8"))}catch{return null}let s=n.name;return s?{name:s,root:e,relativeRoot:T.relative(t,e),entryPoints:ui(e,n)}:null}function ui(t,e){let r=[];if(e.exports){let s=e.exports;if(typeof s=="string")r.push(T.join(t,s));else if(typeof s=="object"&&s!==null){let i=s["."];if(typeof i=="string")r.push(T.join(t,i));else if(typeof i=="object"&&i!==null){let o=i.import??i.require??i.default;typeof o=="string"&&r.push(T.join(t,o))}}}e.main&&r.push(T.join(t,e.main));for(let s of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(T.join(t,s));let n=r.filter(Fe);return n.length>0?n.slice(0,1):r.slice(0,1)}function U(t,e){let r=[],n=new Set;for(let s of e){let i=s.replace(/\/$/,"").replace(/^\.\//,"");gi(t,i,n,r)}return r}function gi(t,e,r,n){if(!e.includes("*")){di(t,e,r,n);return}let s=e.split("/");s.includes("**")?hi(t,s,r,n):yi(t,s,r,n)}function di(t,e,r,n){let s=T.join(t,e);if(r.has(s)||!mr(s))return;r.add(s);let i=it(t,s);i&&n.push(i)}function hi(t,e,r,n){let s=T.join(t,e[0]==="**"?"":e[0]??"");ur(t,s,r,n)}function yi(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),i=T.join(t,...e.slice(0,s)),o;try{o=re.readdirSync(i,{withFileTypes:!0})}catch{return}for(let a of o){if(!a.isDirectory())continue;let c=T.join(i,a.name);if(r.has(c))continue;r.add(c);let l=it(t,c);l&&n.push(l)}}function ur(t,e,r,n){let s;try{s=re.readdirSync(e,{withFileTypes:!0})}catch{return}for(let i of s){if(!i.isDirectory()||i.name==="node_modules"||i.name.startsWith("."))continue;let o=T.join(e,i.name);if(re.existsSync(T.join(o,"package.json"))&&!r.has(o)){r.add(o);let a=it(t,o);a&&n.push(a)}else ur(t,o,r,n)}}var dr={type:"npm",detect(t){let e=gr.join(t,"package.json");if(!ot.existsSync(e))return null;let r;try{r=JSON.parse(ot.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||ot.existsSync(gr.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:U(t,n)}};import K from"fs";import w from"path";var hr={type:"nx",detect(t){return K.existsSync(w.join(t,"nx.json"))?yr(t,t,new Set,0).map(r=>xi(t,r,w.join(r,"project.json"))).filter(r=>r!==null):null}};function yr(t,e,r,n){if(n>4)return[];let s;try{s=K.readdirSync(e,{withFileTypes:!0})}catch{return[]}let i=[];for(let o of s){if(!o.isDirectory())continue;let a=o.name;if(a.startsWith(".")||a==="node_modules"||a==="dist"||a===".nx")continue;let c=w.join(e,a);K.existsSync(w.join(c,"project.json"))&&!r.has(c)?(r.add(c),i.push(c)):i.push(...yr(t,c,r,n+1))}return i}function xi(t,e,r){let n={};try{n=JSON.parse(K.readFileSync(r,"utf-8"))}catch{return null}let s=n.name,i,o,a=w.join(e,"package.json");if(K.existsSync(a))try{let c=JSON.parse(K.readFileSync(a,"utf-8"));s=c.name??s,i=c.main,o=c.exports}catch{}return s?{name:s,root:e,relativeRoot:w.relative(t,e),entryPoints:Si(e,n,i,o)}:null}function Si(t,e,r,n){let s=[],i=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(i){let a=w.resolve(t,"../..");s.push(w.resolve(a,i)),s.push(w.resolve(t,i))}if(n){let a=n;if(typeof a=="string")s.push(w.join(t,a));else if(typeof a=="object"&&a!==null){let c=a["."];typeof c=="string"&&s.push(w.join(t,c))}}if(r&&s.push(w.join(t,r)),e.sourceRoot){let a=w.resolve(t,"../.."),c=w.resolve(a,e.sourceRoot);s.push(w.join(c,"index.ts"),w.join(c,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])s.push(w.join(t,a));let o=s.filter(Fe);return o.length>0?o.slice(0,1):s.slice(0,1)}import xr from"fs";import bi from"path";import{load as vi}from"js-yaml";var Sr={type:"pnpm",detect(t){let e=bi.join(t,"pnpm-workspace.yaml");if(!xr.existsSync(e))return null;let r=[];try{r=vi(xr.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return U(t,r)}};import ki from"fs";import Ci from"path";var br={type:"turborepo",detect(t){return ki.existsSync(Ci.join(t,"turbo.json"))?[]:null}};import at from"fs";import vr from"path";var kr={type:"yarn",detect(t){if(!at.existsSync(vr.join(t,"yarn.lock")))return null;let e=vr.join(t,"package.json");if(!at.existsSync(e))return null;let r;try{r=JSON.parse(at.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r)return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:U(t,n)}};var Cr=[];function D(t){Cr.push(t)}function Er(){return Cr}D(br);D(hr);D(Sr);D(kr);D(dr);function ct(t,e=Er()){let r=Ei.resolve(t),n=new Map,s=[];for(let o of e){let a=o.detect(r);if(a!==null){s.push(o.type);for(let c of a)n.has(c.name)||n.set(c.name,c)}}if(s.length===0)return{root:r,type:"none",types:[],packages:[],packageMap:new Map};let i=Array.from(n.values());return{root:r,type:s[0],types:s,packages:i,packageMap:new Map(i.map(o=>[o.name,o]))}}var ne=class t{constructor(e,r){this.monorepoRoot=e;this.type=r}monorepoRoot;type;packages=new Map;addPackage(e,r){this.packages.set(e.name,{graph:r,pkg:e})}getPackageForFile(e){for(let{pkg:r}of this.packages.values())if(e===r.relativeRoot||e.startsWith(`${r.relativeRoot}/`))return r}getPackageDependencies(){let e=new Map;for(let{graph:r,pkg:n}of this.packages.values()){let s=new Set;for(let i of r.nodes.values())for(let o of i.imports)o.isWorkspace&&o.workspacePackage&&s.add(o.workspacePackage);e.set(n.name,[...s])}return e}getAffectedAcrossPackages(e){let r=this.getPackageForFile(e);if(!r)return[];let n=this.packages.get(r.name);if(!n)return[];let s=[];n.graph.traverse(e,i=>(i.path!==e&&s.push({file:i.path,package:r.name}),!0),{direction:"incoming"});for(let{graph:i,pkg:o}of this.packages.values())if(o.name!==r.name)for(let a of i.nodes.values())a.imports.some(l=>l.isWorkspace&&l.workspacePackage===r.name)&&s.push({file:a.path,package:o.name});return s}serialize(){return{monorepoRoot:this.monorepoRoot,type:this.type,packages:Array.from(this.packages.values()).map(({graph:e,pkg:r})=>({pkg:{name:r.name,relativeRoot:r.relativeRoot,entryPoints:r.entryPoints},nodes:Array.from(e.nodes.values())}))}}static deserialize(e){let r=new t(e.monorepoRoot,e.type);for(let{pkg:n,nodes:s}of e.packages){let i=new Map(s.map(a=>[a.path,a])),o=new G(i);r.packages.set(n.name,{graph:o,pkg:{...n,root:""}})}return r}};var wr=new Map;function V(t,e){wr.set(t,e)}function Fr(t){return wr.get(t)}function Tr(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function wi(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var Fi=(t,e)=>!e.category||Tr(t.category,e.category),Ti=(t,e)=>!e.type||Tr(t.type,e.type),Ni=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,Pi=(t,e)=>!e.path||wi(t.path,e.path),Ii=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,Mi=(t,e)=>{if(!e.tags||e.tags.length===0)return!0;let r=e.tags.filter(s=>!s.startsWith("!")),n=e.tags.filter(s=>s.startsWith("!")).map(s=>s.slice(1));return!(r.length>0&&!r.some(s=>t.tags.some(i=>i.name===s))||n.some(s=>t.tags.some(i=>i.name===s)))},Di=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),Ri=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),Ai=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),Li=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,Oi=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,Gi=(t,e)=>e.minSize===void 0||t.size>=e.minSize,_i=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,ji=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,Wi=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,$i=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,zi=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,Bi=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,Ui=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,Ki=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,Vi=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,Ji=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,Hi=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,Qi=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,Yi=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,Xi=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,Zi=(t,e,r)=>!e.any?.length||e.any.some(n=>se(t,n,r)),qi=[Fi,Ti,Ni,Pi,Ii,Mi,Di,Ri,Ai,Li,Oi,Gi,_i,ji,Wi,$i,zi,Bi,Ui,Ki,Vi,Ji,Hi,Qi,Yi,Xi,Zi];function se(t,e,r){return qi.every(n=>n(t,e,r))}function Nr(t,e){let r=new Map;if(e.importedBy!==void 0){for(let o of t.nodes)for(let a of o.imports)if(a.toPath){let c=r.get(a.toPath)??[];c.push(o.path),r.set(a.toPath,c)}}let n=t.nodes.filter(o=>se(o,e,r)),s=new Set(n.map(o=>o.path)),i=n.map(o=>({...o,imports:o.imports.filter(a=>!a.toPath||s.has(a.toPath))}));if(e.sort){let o=e.sortDir==="asc"?-1:1;i.sort((a,c)=>{let l=0;return e.sort==="size"?l=c.size-a.size:e.sort==="imports"?l=c.imports.length-a.imports.length:e.sort==="commitCount90d"?l=(c.commitCount90d??0)-(a.commitCount90d??0):e.sort==="exportUsage"?l=(c.avgExportUsage??0)-(a.avgExportUsage??0):e.sort==="complexity"?l=(c.complexity??0)-(a.complexity??0):e.sort==="cognitiveComplexity"&&(l=(c.cognitiveComplexity??0)-(a.cognitiveComplexity??0)),l*o})}return e.limit!==void 0&&i.splice(e.limit),{nodes:i,cycles:t.cycles?.filter(o=>o.every(a=>s.has(a)))??void 0}}function Pr(t,e){let r=e.indexOf(":");if(r===-1)return;let n=e.slice(0,r).trim().toLowerCase(),s=e.slice(r+1).trim();if(!(!n||!s))switch(n){case"category":t.category=s;break;case"type":t.type=s;break;case"tag":case"tags":s.includes("+")?t.allTags=[...t.allTags??[],...s.split("+")]:t.tags=[...t.tags??[],s];break;case"path":t.path=s;break;case"external":t.isExternal=s.toLowerCase()==="true";break;case"importsfile":t.importsFile=s;break;case"importedby":t.importedBy=s;break;case"minimports":t.minImports=parseInt(s,10);break;case"maximports":t.maxImports=parseInt(s,10);break;case"minsize":t.minSize=parseInt(s,10);break;case"maxsize":t.maxSize=parseInt(s,10);break;case"sort":t.sort=s;break;case"sortdir":t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";break;case"limit":t.limit=parseInt(s,10);break;case"hasdocstring":t.hasDocstring=s.toLowerCase()!=="false";break;case"mincoverage":t.minCoverage=parseInt(s,10);break;case"maxcoverage":t.maxCoverage=parseInt(s,10);break;case"minexportusage":t.minExportUsage=parseFloat(s);break;case"maxexportusage":t.maxExportUsage=parseFloat(s);break;case"mincomplexity":t.minComplexity=parseInt(s,10);break;case"maxcomplexity":t.maxComplexity=parseInt(s,10);break;case"mincognitivecomplexity":t.minCognitiveComplexity=parseInt(s,10);break;case"maxcognitivecomplexity":t.maxCognitiveComplexity=parseInt(s,10);break;case"mincommits":t.minCommits=parseInt(s,10);break;case"maxcommits":t.maxCommits=parseInt(s,10);break;case"isdocumented":t.isDocumented=s.toLowerCase()!=="false";break;case"isstale":t.isStale=s.toLowerCase()!=="false";break;case"lastauthor":t.lastAuthor=s;break}}function eo(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};Pr(s,n),Object.keys(s).length>0&&e.push(s)}return e}function Ir(t){let e={},r=t.split(",");for(let n of r){let s=n.trim();if(s.toLowerCase().startsWith("any(")&&s.endsWith(")")){let i=s.slice(4,-1),o=eo(i);o.length>0&&(e.any=[...e.any??[],...o]);continue}Pr(e,n)}return e}import _r from"fs/promises";import wo from"path";import bt from"path";import Le from"typescript";import no from"path";import to from"path";import C from"typescript";var Mr=new Set(["describe","test","it"]);function j(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function lt(t){let e=[];for(let r of t.statements){if(!C.isExpressionStatement(r))continue;let n=r.expression;if(!C.isCallExpression(n))continue;let s=n.expression;C.isIdentifier(s)&&Mr.has(s.text)&&e.push(n),C.isPropertyAccessExpression(s)&&C.isIdentifier(s.expression)&&Mr.has(s.expression.text)&&e.push(n)}return e}function pt(t,e,r){for(let n of t.arguments){if(!C.isObjectLiteralExpression(n))continue;let s=n.properties.find(i=>C.isPropertyAssignment(i)&&C.isIdentifier(i.name)&&i.name.text===e);if(!(!s||!C.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(C.isStringLiteral).map(i=>i.text)}return null}function ft(t,e,r,n){if(t.arguments.length===0)return null;for(let i=1;i<t.arguments.length;i++){let o=j(t.arguments,i);if(!C.isObjectLiteralExpression(o))continue;let a=o.properties.find(l=>C.isPropertyAssignment(l)&&C.isIdentifier(l.name)&&l.name.text===e);if(a)return{start:a.initializer.getStart(n),end:a.initializer.getEnd(),text:r};let c=o.getEnd()-1;return{start:c,end:c,text:`${o.properties.length>0?", ":""}${e}: ${r}`}}let s=j(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function mt(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let i=j(n,s);if(!C.isObjectLiteralExpression(i))continue;let o=i.properties.findIndex(c=>C.isPropertyAssignment(c)&&C.isIdentifier(c.name)&&c.name.text===e);if(o<0)continue;if(i.properties.length===1)return{start:j(n,s-1).getEnd(),end:i.getEnd(),text:""};let a=j(i.properties,o);return o===i.properties.length-1?{start:j(i.properties,o-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:j(i.properties,o+1).getStart(r),text:""}}return null}function ut(t,e){let r=[...e].sort((s,i)=>i.start-s.start),n=t;for(let s of r)n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function gt(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var M=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function ro(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function Te(t,e,r,n){let s=C.createSourceFile(to.basename(t),e,C.ScriptTarget.Latest,!0),i=lt(s),[o]=i;if(!o)return e;let a=pt(o,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(ro(a).sort())===JSON.stringify(c))return e;let l=gt(c.map(g=>`@${g}`)),p=i.flatMap(g=>{let d=r.length===0?mt(g,n,s):ft(g,n,l,s);return d?[d]:[]});return p.length>0?ut(e,p):e}var Ne=class{name="cypress";canHandle(e){return M.has(no.extname(e).toLowerCase())}apply(e,r,n){return Te(e,r,n,"tags")}};import so from"path";var dt=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,ht=/^@([a-zA-Z0-9_-]+)/gm;function io(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
1
+ var Ve=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import Dn from"path";import{fileURLToPath as Rn}from"url";var An=()=>Rn(import.meta.url),Ln=()=>Dn.dirname(An()),u=Ln();import Ye from"fs";import $t from"path";var On=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Gt=[];function xe(t){Gt.push(t)}function _t(t){return[...On,...Gt].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Gn=[".test.",".spec.","-test.","-spec."],jt=[];function Se(t){jt.push(t)}function Z(){return[...Gn,...jt]}var _n=["jest","vitest","playwright","cypress","@testing-library/"],Wt=[];function be(t){Wt.push(t)}function Je(){return[..._n,...Wt]}var zt=.8;function He(t){zt=t}function Qe(){return zt}var jn=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function Xe(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=$t.resolve(t);return Ye.existsSync(n)?n.endsWith(".json")?Bt(n):e?Ut(n):{}:{}}for(let n of jn){let s=$t.resolve(t,n);if(Ye.existsSync(s)){if(n.endsWith(".json"))return Bt(s);if(e)return Ut(s)}}return{}}function Bt(t){return JSON.parse(Ye.readFileSync(t,"utf-8"))}function Ut(t){let e=Ve(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function Wn(t){for(let e of t.configMatchers??[])xe(e);for(let e of t.testPatterns??[])Se(e);for(let e of t.testLibraries??[])be(e);t.barrelThreshold!==void 0&&He(t.barrelThreshold)}function zn(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases}}var q=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],Ze=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];import $n from"fs";import Kt from"path";function Bn(t,e){let r=Kt.resolve(t,e);try{let n=$n.readFileSync(r,"utf-8"),s=JSON.parse(n),i=new Map;for(let[o,a]of Object.entries(s)){if(o==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let l=Kt.relative(t,o);i.set(l,c)}return i}catch{return new Map}}var qe={serialize(t){let e=["graph TD"],r=new Set;for(let n of t.nodes.values()){let s=`"${n.path}"`;for(let i of n.imports){if(!i.toPath)continue;let o=`"${i.toPath}"`,a=`${n.path} -> ${i.toPath}`;if(!r.has(a)){let c=i.isStyle?"-- styles -->":"-->";e.push(` ${s} ${c} ${o}`),r.add(a)}}}return e.join(`
2
+ `)}};function Vt(t){return qe.serialize(t)}import Jt from"fs";import Un from"path";function et(t,e){let r=t.replace(/^\.\//,"");if(e.nodes.has(r))return r;let n=r.replace(/^dist\//,"src/").replace(/\.(js|mjs|cjs)$/,".ts");return e.nodes.has(n)?n:null}function Ht(t,e){if(typeof t=="string")return et(t,e);if(t&&typeof t=="object"){let r=t;for(let n of["import","require","default"]){let s=Ht(r[n],e);if(s)return s}}return null}function Kn(t){if(!t)return"unknown";let e=t.trimStart();return e.startsWith("interface ")?"interface":e.startsWith("class ")?"class":e.startsWith("enum ")?"enum":e.startsWith("type ")?"type":e.startsWith("namespace ")?"namespace":e.startsWith("const ")||e.startsWith("let ")||e.startsWith("var ")||e.startsWith("readonly ")?"const":e.startsWith("(")||e.startsWith("async ")||e.startsWith("function ")||e.includes("=>")?"function":"unknown"}function Vn(t,e){let r=new Set,n=new Set,s=[...e];for(;s.length;){let i=s.shift();if(n.has(i))continue;n.add(i);let o=t.nodes.get(i);if(o){for(let a of o.exports)r.add(a.name);for(let a of o.imports){if(a.type!=="re-export"||a.isExternal||!a.toPath)continue;if(!a.symbols?.length||a.symbols.includes("*")){let l=t.nodes.get(a.toPath);if(l)for(let p of l.exports)r.add(p.name);s.push(a.toPath)}else for(let l of a.symbols)r.add(l)}}}return r}function Jn(t,e){return Qt(t,e)[0]??null}function Qt(t,e){let r=[],n=Un.join(e,"package.json");if(Jt.existsSync(n))try{let s=JSON.parse(Jt.readFileSync(n,"utf8"));if(s.exports&&typeof s.exports=="object"&&!Array.isArray(s.exports))for(let i of Object.values(s.exports)){let o=Ht(i,t);o&&!r.includes(o)&&r.push(o)}else if(typeof s.exports=="string"){let i=et(s.exports,t);i&&r.push(i)}if(r.length===0)for(let i of[s.main,s.module].filter(Boolean)){let o=et(i,t);o&&!r.includes(o)&&r.push(o)}}catch{}if(r.length===0){for(let s of["src/index.ts","src/index.js","index.ts","index.js"])if(t.nodes.has(s)){r.push(s);break}}return r}function Hn(t,e){let r=new Set(e);for(let n of e)t.traverse(n,s=>(r.add(s.path),!0),{direction:"outgoing"});return r}function Qn(t,e,r){let n=new Map;for(let s of e){if(r.includes(s))continue;let i=t.nodes.get(s);if(!i)continue;let o=i.category==="barrel";for(let a of i.exports){let c=n.get(a.name),l=!!(a.signature||a.doc);(!c||l&&!o)&&n.set(a.name,{file:s,symbol:a})}}return n}function Yn(t,e,r,n){let s=[];for(let i of t){let o=e.get(i),a=n.flatMap(g=>r.nodes.get(g)?.exports??[]).find(g=>g.name===i),c=o?.symbol??a,l=o?.file??n.find(g=>r.nodes.get(g)?.exports.some(d=>d.name===i))??n[0],p={name:i,definedIn:l,kind:Kn(c?.signature)};c?.doc&&(p.doc=c.doc),c?.signature&&(p.signature=c.signature),s.push(p)}return s.sort((i,o)=>i.name.localeCompare(o.name)),s}function Xn(t,e,r){let n=c=>t.nodes.get(c)?.category==="test",s=[...e].filter(c=>!r.includes(c)&&!n(c)),i=[...t.nodes.keys()].filter(c=>!e.has(c)),o=i.filter(c=>!n(c)),a=i.filter(c=>n(c));return{internalFiles:s,unreachableFromEntry:o,testFiles:a}}function Zn(t,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let l of e)if(!t.nodes.has(l))throw new Error(`Entry point not found in graph: ${l}`);let r=Hn(t,e),n=Qn(t,r,e),s=Vn(t,e),i=Yn(s,n,t,e),{internalFiles:o,unreachableFromEntry:a,testFiles:c}=Xn(t,r,e);return{entryPoints:e,publicExports:i,internalFiles:o,unreachableFromEntry:a,testFiles:c}}function qn(t,e){let r=null,n=[];for(let i of t.nodes.values()){i.exports.some(o=>o.name===e)&&(r=i.path);for(let o of i.callEdges??[])o.to===e&&n.push({file:i.path,callerFunction:o.from})}let s=[];if(r){let i=t.nodes.get(r);for(let o of i?.callEdges??[])o.from===e&&s.push({file:o.toFile,calleeFunction:o.to})}return{functionName:e,definedIn:r,callers:n,callees:s}}import ee from"fs";import es from"path";function tt(t){let e=[...t.nodes.entries()].sort(([n],[s])=>n.localeCompare(s)).map(([n,s])=>`${n}:${s.mtime}:${s.size}`).join("|"),r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=Math.imul(r,16777619)>>>0;return r.toString(16).padStart(8,"0")}function ts(t){let e=new Map;for(let r of t.nodes.keys()){let n=[];t.traverse(r,s=>(s.path!==r&&n.push(s.path),!0),{direction:"incoming"}),e.set(r,n)}return{impact:e,graphHash:tt(t)}}function rs(t,e){return t.impact.get(e)??[]}function ns(t,e){return t.graphHash===tt(e)}function ss(t,e){let r=es.dirname(e);ee.existsSync(r)||ee.mkdirSync(r,{recursive:!0});let n={graphHash:t.graphHash,impact:[...t.impact.entries()]};ee.writeFileSync(e,JSON.stringify(n))}function is(t){if(!ee.existsSync(t))return null;try{let e=ee.readFileSync(t,"utf-8"),r=JSON.parse(e);return{graphHash:r.graphHash,impact:new Map(r.impact)}}catch{return null}}import{readFile as Bs}from"fs/promises";import Fe from"path";import Us from"piscina";import ke from"fs";import os from"path";import{load as Yt}from"js-yaml";var rt=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function Xt(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function as(t){return t.replace(/:$/,"").split(",").map(e=>{let r=e.trim();return r.startsWith('"')&&(r=r.slice(1)),r.endsWith('"')&&(r=r.slice(0,-1)),Xt(r)}).filter(Boolean)}function cs(t,e){let r=t.startsWith("/")?t.slice(1):t,n=r.lastIndexOf("@");return n>0?{name:r.substring(0,n),version:e||r.substring(n+1)}:{name:r,version:e}}function ls(t){try{let e=Yt(t),r={dependencies:{}};for(let[n,s]of Object.entries(e))if(!(n==="__metadata"||!s?.version))for(let i of n.split(", ")){let o=Xt(i);o&&(r.dependencies[o]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function ps(t){let e={dependencies:{}};for(let r of t.split(/\n\n+/)){let n=r.split(`
3
+ `).filter(c=>c.trim().length>0&&!c.trim().startsWith("#"));if(n.length<2)continue;let s=n[0];if(!s||s.startsWith(" "))continue;let i=as(s);if(i.length===0)continue;let a=n.find(c=>c.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let c of i)e.dependencies[c]={version:a}}return e}function fs(t){let e=ke.readFileSync(t,"utf-8"),r=JSON.parse(e),n={dependencies:{}};if(r.packages)for(let[s,i]of Object.entries(r.packages)){if(!s.startsWith("node_modules/"))continue;let o=s.replace("node_modules/","");o.includes("node_modules/")||(n.dependencies[o]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}else if(r.dependencies)for(let[s,i]of Object.entries(r.dependencies))n.dependencies[s]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}};return n}function us(t){let e=ke.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=ls(e);if(r!==null)return r}return ps(e)}function ms(t){let e=ke.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=Yt(e);if(n.packages)for(let[s,i]of Object.entries(n.packages)){let{name:o,version:a}=cs(s,i.version);o&&(r.dependencies[o]={version:a,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}if(n.dependencies)for(let[s,i]of Object.entries(n.dependencies)){if(r.dependencies[s])continue;let o=typeof i=="string"?i:i.version;r.dependencies[s]={version:o||""}}}catch{}return r}function Zt(t){let e={"package-lock.json":fs,"yarn.lock":us,"pnpm-lock.yaml":ms},r=rt.map(n=>[n,e[n]]);for(let[n,s]of r){let i=os.join(t,n);if(ke.existsSync(i))return s(i)}return null}var gs=new Set(["css","scss","less","stylus"]);function qt(t){return gs.has(t)?"style":"code"}function ds(t){let e=5381;for(let r=0;r<t.length;r++)e=e*33+t.charCodeAt(r)>>>0;return e.toString(36)}function hs(t,e){let r=[];for(let n=0;n<=t.length-e;n++)r.push(ds(t.slice(n,n+e).map(s=>s.text).join(" ")));return r}function ys(t,e,r){let n=t.get(e.file),s=t.get(r.file);if(!n||!s)return 0;let i=0;for(;e.windowIndex+i+1<n.length&&r.windowIndex+i+1<s.length&&n[e.windowIndex+i+1]===s[r.windowIndex+i+1];)i++;return i}function xs(t,e,r){if(e.windowIndex===0||r.windowIndex===0)return!0;let n=t.get(e.file),s=t.get(r.file);return!n||!s?!0:n[e.windowIndex-1]!==s[r.windowIndex-1]}var nt=class{parent=new Map;find(e){this.parent.has(e)||this.parent.set(e,e);let r=e;for(;this.parent.get(r)!==r;)r=this.parent.get(r);let n=e;for(;n!==r;){let s=this.parent.get(n);this.parent.set(n,r),n=s}return r}union(e,r){let n=this.find(e),s=this.find(r);n!==s&&this.parent.set(n,s)}root(e){return this.find(e)}};function ve(t){return`${t.file}#${t.startLine}#${t.endLine}`}var Ss=new Set(["{","}",":",",","[","]"]);function bs(t,e,r){let n=0;for(let s=e;s<e+r;s++)Ss.has(t[s].text)&&n++;return n/r}var ks=400;function er(t,e,r,n=.5,s=ks){let i=new Map,o=new Map,a=new Map;for(let{file:S,tokens:x}of t){if(x.length<e)continue;o.set(S,x);let k=hs(x,e);i.set(S,k);for(let y=0;y<k.length;y++){let b={file:S,windowIndex:y},F=a.get(k[y]);F?F.push(b):a.set(k[y],[b])}}let c=[],l=0;for(let S of a.values())if(!(S.length<2)){if(S.length>s){l++;continue}for(let x=0;x<S.length;x++)for(let k=x+1;k<S.length;k++){let y=S[x],b=S[k];if(y.file===b.file&&y.windowIndex===b.windowIndex||!xs(i,y,b))continue;let F=ys(i,y,b),P=e+F,U=o.get(y.file);if(bs(U,y.windowIndex,P)>n)continue;if(y.file===b.file){let[In,Mn]=y.windowIndex<b.windowIndex?[y,b]:[b,y];if(In.windowIndex+P>Mn.windowIndex)continue}let X=o.get(b.file),Ue={file:y.file,startLine:U[y.windowIndex].line,endLine:U[y.windowIndex+P-1].line},Ke={file:b.file,startLine:X[b.windowIndex].line,endLine:X[b.windowIndex+P-1].line},Ot=Math.min(Ue.endLine-Ue.startLine+1,Ke.endLine-Ke.startLine+1);Ot<r||c.push({occA:Ue,occB:Ke,lines:Ot,tokens:P})}}let p=new nt,g=new Map;for(let{occA:S,occB:x}of c){let k=ve(S),y=ve(x);g.set(k,S),g.set(y,x),p.union(k,y)}let d=new Map;for(let S of g.keys()){let x=p.root(S),k=d.get(x);k?k.add(S):d.set(x,new Set([S]))}let h=[];for(let S of d.values()){if(S.size<2)continue;let x=[...S].map(b=>g.get(b)),k=0,y=e;for(let b of c)!S.has(ve(b.occA))||!S.has(ve(b.occB))||b.lines>k&&(k=b.lines,y=b.tokens);h.push({occurrences:x,lines:k,tokens:y})}return{groups:h.sort((S,x)=>x.lines-S.lines),skippedBuckets:l}}import rr from"postcss";import*as vs from"postcss-less";var Cs=vs,nr=new Set(["reference","inline"]);function tr(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function Es(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function ws(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let i=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=nr.has(i)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...tr(o)?{isExternal:!0}:{}}}let n=t.match(/^url\(['"]?([^'")]+)['"]?\)/),s=n?n[1]?.trim()??"":t.match(/^['"]([^'"]+)['"]/)?.[1]??"";return s?{fromPath:e,toPath:"",rawSpecifier:s,isStyle:!0,type:"static",...tr(s)?{isExternal:!0}:{}}:null}function Fs(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let i=s[1]?.trim()??"";Es(i)&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function sr(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=ws(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...Fs(n.value,e))}),r}function Ts(t){return t.replace(/(?<!:)\/\/.*/g,"")}function Ns(t,e){let r=[],n=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let i=s[1]?.trim()??"",o=s[2]??"";if(o){let a=nr.has(i)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}s=n.exec(t)}return r}function Ce(t,e){let r=rr.parse(Ts(t));return{imports:sr(r,e),root:r}}function Ps(t){let e=[],r=[];for(let n of t.nodes??[]){if(n.type!=="atrule")continue;let{value:s}=n;if(s===void 0)continue;let i=n.name;i&&(e.push({name:i}),r.push({name:i,kind:"variable"}))}return{exports:e,tags:r}}function Ee(t,e){try{let r=Cs.parse(t),{exports:n,tags:s}=Ps(r);return{imports:sr(r,e),root:r,exports:n,tags:s}}catch{return{imports:Ns(t,e),root:rr.parse(""),exports:[],tags:[]}}}import{parse as Is}from"postcss-scss";function ir(t){return t.startsWith("_")||t.startsWith("-")}function Ms(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function Ds(t){let e=t.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let r=e[1],s=t.match(/\bas\s+(\S+)/)?.[1];return s!==void 0?{specifier:r,alias:s}:{specifier:r}}function Rs(t){let e=[],r=[];for(let n of t.nodes??[]){if(n.type==="decl"&&n.prop.startsWith("$")){let s=n.prop.slice(1);if(!s||ir(s))continue;e.push({name:s}),r.push({name:s,kind:"variable"});continue}if(n.type==="atrule"&&(n.name==="mixin"||n.name==="function")){let i=n.params.match(/^([\w-]+)/)?.[1];if(!i||ir(i))continue;let o=n.params.trim();e.push(o.includes("(")?{name:i,signature:o}:{name:i}),r.push({name:i,kind:"function"})}}return{exports:e,tags:r}}function we(t,e){let r=Is(t),n=[];r.walk(o=>{if(o.type!=="atrule")return;let{name:a,params:c}=o;if(a!=="import"&&a!=="use"&&a!=="forward")return;let{specifier:l,alias:p}=Ds(c);if(!l)return;let g={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...Ms(l)?{isExternal:!0}:{}};p&&(g.symbols=[p]),n.push(g)});let{exports:s,tags:i}=Rs(r);return{imports:n,root:r,exports:s,tags:i}}function As(t){return t.trim().replace(/\s+/g," ")}function Ls(t){try{return t.fileType==="scss"?we(t.source,t.file).root:t.fileType==="less"?Ee(t.source,t.file).root:t.fileType==="css"?Ce(t.source,t.file).root:void 0}catch{return}}function Os(t){let e=Ls(t);if(!e)return[];let r=[];return e.walkRules(n=>{let s=n.nodes?.filter(p=>p.type==="decl")??[];if(s.length===0)return;let i=s[0],o=s[s.length-1],a=n.source?.start?.line??i?.source?.start?.line,c=o?.source?.end?.line??o?.source?.start?.line??a;if(a===void 0||c===void 0)return;let l=s.map(p=>`${p.prop.trim().toLowerCase()}:${As(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function or(t,e,r=2){let n=new Map;for(let i of t)for(let o of Os(i)){if(o.declCount<r||o.lines<e)continue;let a=n.get(o.signature);a?a.push(o):n.set(o.signature,[o])}let s=[];for(let i of n.values())for(let o=0;o<i.length;o++)for(let a=o+1;a<i.length;a++){let c=i[o],l=i[a];if(c.file===l.file&&c.startLine===l.startLine&&c.endLine===l.endLine)continue;let p={file:c.file,startLine:c.startLine,endLine:c.endLine},g={file:l.file,startLine:l.startLine,endLine:l.endLine};s.push({occurrences:[p,g],lines:Math.min(c.lines,l.lines),tokens:c.declCount,family:"style"})}return s.sort((i,o)=>o.lines-i.lines)}var Gs={typescript:{line:["//"],block:[["/*","*/"]]},javascript:{line:["//"],block:[["/*","*/"]]},go:{line:["//"],block:[["/*","*/"]]},css:{block:[["/*","*/"]]},scss:{line:["//"],block:[["/*","*/"]]},less:{line:["//"],block:[["/*","*/"]]},stylus:{line:["//"],block:[["/*","*/"]]},python:{line:["#"]},gherkin:{line:["#"]},coffeescript:{line:["#"],block:[["###","###"]]},livescript:{line:["#"],block:[["###","###"]]},lua:{line:["--"],block:[["--[[","]]"]]},markdown:{block:[["<!--","-->"]]}};function ar(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function _s(t,e){if(!e)return t;let r=t;for(let[n,s]of e.block??[]){let i=0;for(;;){let o=r.indexOf(n,i);if(o===-1)break;let a=r.indexOf(s,o+n.length),c=a===-1?r.length:a+s.length;r=ar(r,o,c),i=c}}for(let n of e.line??[]){let s=0;for(;;){let i=r.indexOf(n,s);if(i===-1)break;let o=r.indexOf(`
4
+ `,i),a=o===-1?r.length:o;r=ar(r,i,a),s=a}}return r}var js=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],st=new RegExp(`${js.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),Ws=/^[A-Za-z_$][A-Za-z0-9_$]*$/,cr=/^\d+(?:\.\d+)?$/,zs=/^(".*"|'.*'|`.*`)$/s,$s=new Set(["if","else","elif","for","while","do","switch","case","default","break","continue","return","function","def","class","struct","interface","const","let","var","local","import","export","from","package","try","catch","except","finally","throw","raise","new","this","self","end","then","yield","async","await","nil","null","None","true","false","True","False","and","or","not","in","of","is"]);function lr(t,e,r=!0){let n=_s(t,Gs[e]),s=[],i=1,o=0;st.lastIndex=0;let a=st.exec(n);for(;a!==null;){for(let p=o;p<a.index;p++)n[p]===`
5
+ `&&i++;o=a.index;let c=a[0],l=c;Ws.test(c)&&!$s.has(c)?l="ID":r&&(cr.test(c)||zs.test(c))&&(l=cr.test(c)?"NUM":"STR"),s.push({text:l,line:i});for(let p=o;p<a.index+c.length;p++)n[p]===`
6
+ `&&i++;o=a.index+c.length,a=st.exec(n)}return s}var Ks=20,Vs=new Set(["css","scss","less"]);function Js(t){return rt.includes(Fe.basename(t))}function Hs(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(Fe.sep).some(n=>r.has(n))}async function Qs(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:i=!0,maxPunctuationRatio:o=.5,maxBucketSize:a,limit:c=50,ignoreDirs:l=q,parallelTokenizing:p=!0}=r,g=[...t.nodes.values()].filter(h=>!Js(h.path)&&!Hs(h.path,l)),d=Ys(p,g.length);try{let h=[],S=new Map;await Promise.all(g.map(async y=>{let b;try{b=await Bs(Fe.join(e,y.path),"utf8")}catch{return}if(Vs.has(y.type)){h.push({file:y.path,source:b,fileType:y.type});return}let F=qt(y.type),P=d?await d.run({source:b,fileType:y.type,ignoreLiterals:i}):lr(b,y.type,i),U={file:y.path,tokens:P},X=S.get(F);X?X.push(U):S.set(F,[U])}));let x=or(h,n),k=0;for(let[y,b]of S){let F=er(b,s,n,o,a);k+=F.skippedBuckets;for(let P of F.groups)x.push({...P,family:y})}return{groups:x.sort((y,b)=>b.lines-y.lines).slice(0,c),skippedBuckets:k}}finally{d&&await d.destroy()}}function Ys(t,e){if(t===!1)return null;let r=typeof t=="object"?t:{},n=r.minFiles??Ks;if(e<n)return null;try{return new Us({filename:Fe.join(u,"duplication-worker.js"),...r.maxThreads!==void 0?{maxThreads:r.maxThreads}:{}})}catch(s){return process.stderr.write(`
7
+ Warning: failed to start duplicate-detection worker pool, falling back to synchronous tokenizing: ${s}
8
+ `),null}}import Te from"path";function Xs(t){let e=new Map;for(let[r,n]of t){let s=n.imports.filter(i=>i.toPath&&!i.isExternal).length;s>0&&e.set(r,s)}return e}function Zs(t,e,r){let n=new Map;for(let[s,i]of e){if(i<r)continue;let o=t.get(s);if(!o||o.category==="test"||o.category==="barrel")continue;let a=Te.extname(s),c=Te.basename(s,a),l=c==="index"?Te.basename(Te.dirname(s)):c;n.set(s,{path:s,outDegree:i,tag:`feature:${l}`})}return n}function te(t,e){let r=e?.minOutDegree??5;return Zs(t,Xs(t),r)}var qs=(t,e)=>t.outDegree-e.outDegree;function ei(t,e){let r=new Map;for(let n of e.values()){let s=new Set;t.traverse(n.path,i=>(i.path!==n.path&&s.add(i.path),!0),{direction:"outgoing"}),r.set(n.path,s)}return r}function ti(t,e,r,n){let s=new Map;for(let[i]of t){if(e.has(i))continue;let o=null;for(let a of e.values())r.get(a.path)?.has(i)&&(!o||n(a,o)<0)&&(o=a);o&&s.set(i,o.path)}return s}function ri(t,e){let r=new Map;for(let n of t.values()){let s=n.tag.replace("feature:",""),i=[];for(let[o,a]of e)a===n.path&&i.push(o);r.set(s,{hub:n.path,outDegree:n.outDegree,files:i})}return r}function ni(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function it(t,e){let r=e?.detectFn??te,n=e?.hubComparator??qs,s=r(t.nodes,e),i=ei(t,s),o=ti(t.nodes,s,i,n);return{features:ri(s,o),unassigned:ni(t.nodes,s,o)}}var pr=new Set(["typescript","javascript","python","go","scss","less","lua","coffeescript"]),fr=new Set(["typescript","javascript","python"]),Ne=new Set(["typescript","javascript","go","python"]);function si(t){let e=new Map;for(let r of t.nodes.values())e.set(r.type,(e.get(r.type)??0)+1);return[...e.entries()].map(([r,n])=>({type:r,fileCount:n,exportsTracked:pr.has(r),importSymbolsTracked:fr.has(r),callEdgesTracked:Ne.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}var re=class{constructor(e){this.nodes=e}nodes;findUnusedFiles(e){let r=new Set(this.nodes.keys());return e.filter(n=>!r.has(n))}findHighExportUsage(e){let r=[];for(let n of this.nodes.values()){if(n.maxExportUsage===void 0||n.maxExportUsage<e)continue;let s=n.imports.reduce((i,o)=>(o.exportUsageRatio??0)>(i?.exportUsageRatio??0)?o:i,null);r.push({path:n.path,maxExportUsage:n.maxExportUsage,tightestDep:s?.toPath??""})}return r.sort((n,s)=>s.maxExportUsage-n.maxExportUsage)}findCycles(){let e=[],r=new Set,n=new Set,s=[],i=o=>{r.add(o),n.add(o),s.push(o);let a=this.nodes.get(o);if(a){for(let c of a.imports)if(!(!c.toPath||c.isExternal))if(n.has(c.toPath)){let l=s.indexOf(c.toPath);e.push([...s.slice(l),c.toPath])}else r.has(c.toPath)||i(c.toPath)}n.delete(o),s.pop()};for(let o of this.nodes.keys())r.has(o)||i(o);return e}};var G=class t{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let r=new Map;for(let n of e.nodes)r.set(n.path,n);return new t(r)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.imports)if(n.toPath){let s=e.get(n.toPath)||[];s.push(r.path),e.set(n.toPath,s)}return this._incomingEdgesCache=e,e}dfs(e,r,n,s){let i=new Set,o=n.maxDepth??1/0,a=(c,l,p)=>{if(l>o||i.has(c))return;let g=this.nodes.get(c);if(g&&(i.add(c),r(g,l,p)!==!1))for(let d of s(c))a(d,l+1,c)};a(e,0,null)}traverse(e,r,n={}){let s=n.direction??"outgoing",i=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,r,n,o=>s==="outgoing"?this.nodes.get(o)?.imports.map(a=>a.toPath).filter(Boolean)??[]:i?.get(o)??[])}getCallIncomingCache(){if(this._callIncomingCache)return this._callIncomingCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.callEdges??[]){let s=e.get(n.toFile)??[];s.push(r.path),e.set(n.toFile,s)}return this._callIncomingCache=e,e}traverseCalls(e,r,n={}){let s=n.direction??"outgoing",i=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,r,n,o=>s==="outgoing"?this.nodes.get(o)?.callEdges?.map(a=>a.toFile)??[]:i?.get(o)??[])}getCallers(e){let r=[];return this.traverseCalls(e,n=>(n.path!==e&&r.push(n.path),!0),{direction:"incoming",maxDepth:1}),r}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let r=this.nodes.get(e);return r?r.imports.map(n=>this.nodes.get(n.toPath)).filter(n=>n!==void 0):[]}findUnusedFiles(e){return new re(this.nodes).findUnusedFiles(e)}findCycles(){return new re(this.nodes).findCycles()}};var _=class{affectedSymbols=new Map;constructor(e,r){this.affectedSymbols.set(e,new Set(["default",...r]))}updateAffectedSymbols(e,r){let n=this.affectedSymbols.get(r)||new Set,s=e.imports.find(c=>c.toPath===r);if(!s)return!1;let i=s.symbols||["*"],o=new Set;for(let c of i)(c==="*"||n.has("*")||n.has(c))&&o.add("*");if(o.size===0)return!1;let a=this.affectedSymbols.get(e.path)||new Set;for(let c of o)a.add(c);return this.affectedSymbols.set(e.path,a),!0}};function ii(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function oi(t,e,r=1){let n=[];return t.traverse(e,(s,i,o)=>{if(s.path===e)return!0;let a=o?t.nodes.get(o)?.imports.find(c=>c.toPath===s.path):void 0;return n.push({path:s.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:r}),n}function ot(t,e){let r=[];return t.traverse(e,n=>{if(n.path===e)return!0;let s=n.imports.find(i=>i.toPath===e);return r.push({path:n.path,...s?.symbols?{symbols:s.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),r}function ai(t,e,r={}){let{testsOnly:n=!1,changedSymbols:s}=r,i=s?new _(e,s):null,o=[];return t.traverse(e,(a,c,l)=>{if(a.path===e)return!0;if(i&&l&&!i.updateAffectedSymbols(a,l))return!1;let p=a.category==="test"||a.tags.some(g=>g.name==="test");return(!n||p)&&o.push(a.path),!0},{direction:"incoming"}),o}function ci(t,e,r={}){let{depth:n=1,withEdgeDetail:s=!1}=r,i=[];return t.traverseCalls(e,o=>{if(o.path===e)return!0;let a={file:o.path};return s&&(a.edges=(o.callEdges??[]).filter(c=>c.toFile===e).map(c=>({from:c.from,to:c.to}))),i.push(a),!0},{direction:"incoming",maxDepth:n}),i}function li(t,e={}){let{metric:r="cognitiveComplexity",threshold:n=10,limit:s=20}=e;return[...t.nodes.values()].flatMap(i=>(i.functions??[]).filter(o=>o[r]>=n).map(o=>({file:i.path,name:o.name,line:o.line,complexity:o.complexity,cognitiveComplexity:o.cognitiveComplexity}))).sort((i,o)=>o[r]-i[r]).slice(0,s)}function pi(t){return{nodes:t.nodes.map(r=>({path:r.path,type:r.type,category:r.category,exports:r.exports.map(n=>n.name),tags:r.tags.filter(n=>n.kind==="comment-marker"||n.kind==="import").map(n=>n.name),importsFiles:r.imports.filter(n=>!n.isExternal&&n.toPath).map(n=>n.toPath),...r.description!==void 0&&{description:r.description},...r.testedBy!==void 0&&{testedBy:r.testedBy},...r.coveragePct!==void 0&&{coveragePct:r.coveragePct},...r.avgExportUsage!==void 0&&{avgExportUsage:r.avgExportUsage},...r.maxExportUsage!==void 0&&{maxExportUsage:r.maxExportUsage}})),cycles:t.cycles}}function fi(t){let e=t.getPackageDependencies(),r=Array.from(t.packages.values()).map(({graph:n,pkg:s})=>({name:s.name,relativeRoot:s.relativeRoot,nodeCount:n.nodes.size,dependsOn:e.get(s.name)??[]}));return{monorepoType:t.type,packageCount:r.length,packages:r}}function ui(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function ur(t){if(t.category==="test")return"test";if(t.category==="config")return"config";if(t.category==="type-only")return"types";let e=t.path;return C(e,"component")||C(e,"components")?"component":C(e,"controller")||C(e,"controllers")?"controller":C(e,"middleware")?"middleware":C(e,"router")||C(e,"routes")||C(e,"route")?"router":C(e,"store")||C(e,"stores")?"store":C(e,"service")||C(e,"services")?"service":C(e,"handler")||C(e,"handlers")?"handler":C(e,"adapter")||C(e,"adapters")?"adapter":C(e,"plugin")||C(e,"plugins")?"plugin":C(e,"api")?"api":C(e,"cli")||C(e,"commands")||ne(e)==="cli"?"cli":C(e,"util")||C(e,"utils")||C(e,"helper")||C(e,"helpers")?"util":C(e,"model")||C(e,"models")||ne(e)==="model"?"model":C(e,"parser")||C(e,"parsers")||ne(e)==="parser"?"parser":ne(e)==="builder"?"builder":ne(e)==="resolver"?"resolver":"other"}function C(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function ne(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function mi(t,e){let r=it(t,e),n=new Map;for(let[i,o]of r.features){for(let a of o.files)n.set(a,i);n.set(o.hub,i)}let s=new Map;for(let i of t.nodes.values()){let o=n.get(i.path);s.set(i.path,{path:i.path,role:ur(i),...i.description?{description:i.description}:{},exports:i.exports.map(a=>a.name),...o?{featureHub:o}:{}})}return s}function gi(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if(Ne.has(n.type)){let s=[];for(let i of t.nodes.values())for(let o of i.callEdges??[])o.to===e&&s.push({file:i.path,callerFunction:o.from});r.push({path:n.path,category:n.category,precision:"call",callers:s})}else{let s=ot(t,n.path).map(i=>({file:i.path,...i.symbols?{symbols:i.symbols}:{}}));r.push({path:n.path,category:n.category,precision:"file-level",importers:s})}return r}function di(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function hi(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function yi(t){let e=new Map;for(let n of t.nodes.values())if(!(n.type!=="typescript"&&n.type!=="javascript"))for(let s of n.exports){if(!hi(s,n.category))continue;let i=`${n.path}::${s.name}`;e.set(i,{name:s.name,file:n.path,kind:di(s.signature),...s.doc?{doc:s.doc}:{}})}let r=[];for(let n of t.nodes.values())if(!(n.type!=="typescript"&&n.type!=="javascript")){for(let s of n.imports)if(!(!s.toPath||s.isExternal||!s.symbols?.length))for(let i of s.symbols)e.has(`${s.toPath}::${i}`)&&r.push({fromFile:n.path,toType:i,toFile:s.toPath})}return{types:e,edges:r}}function xi(t,e){let r=null;for(let i of t.types.values())if(i.name===e){r=i;break}if(!r)return{type:null,usedByFiles:[],uses:[]};let n=new Set,s=new Map;for(let i of t.edges)if(i.toType===e&&i.toFile===r.file&&n.add(i.fromFile),i.fromFile===r.file){let o=t.types.get(`${i.toFile}::${i.toType}`);o&&s.set(`${o.file}::${o.name}`,o)}return{type:r,usedByFiles:Array.from(n),uses:Array.from(s.values())}}import Ii from"path";import ct from"fs";import hr from"path";import se from"fs";import I from"path";import mr from"fs";import ap from"path";function gr(t){try{return mr.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Pe(t){try{return mr.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function at(t,e){let r=I.join(e,"package.json");if(!se.existsSync(r))return null;let n={};try{n=JSON.parse(se.readFileSync(r,"utf-8"))}catch{return null}let s=n.name;return s?{name:s,root:e,relativeRoot:I.relative(t,e),entryPoints:Si(e,n)}:null}function Si(t,e){let r=[];if(e.exports){let s=e.exports;if(typeof s=="string")r.push(I.join(t,s));else if(typeof s=="object"&&s!==null){let i=s["."];if(typeof i=="string")r.push(I.join(t,i));else if(typeof i=="object"&&i!==null){let o=i.import??i.require??i.default;typeof o=="string"&&r.push(I.join(t,o))}}}e.main&&r.push(I.join(t,e.main));for(let s of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(I.join(t,s));let n=r.filter(Pe);return n.length>0?n.slice(0,1):r.slice(0,1)}function K(t,e){let r=[],n=new Set;for(let s of e){let i=s.replace(/\/$/,"").replace(/^\.\//,"");bi(t,i,n,r)}return r}function bi(t,e,r,n){if(!e.includes("*")){ki(t,e,r,n);return}let s=e.split("/");s.includes("**")?vi(t,s,r,n):Ci(t,s,r,n)}function ki(t,e,r,n){let s=I.join(t,e);if(r.has(s)||!gr(s))return;r.add(s);let i=at(t,s);i&&n.push(i)}function vi(t,e,r,n){let s=I.join(t,e[0]==="**"?"":e[0]??"");dr(t,s,r,n)}function Ci(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),i=I.join(t,...e.slice(0,s)),o;try{o=se.readdirSync(i,{withFileTypes:!0})}catch{return}for(let a of o){if(!a.isDirectory())continue;let c=I.join(i,a.name);if(r.has(c))continue;r.add(c);let l=at(t,c);l&&n.push(l)}}function dr(t,e,r,n){let s;try{s=se.readdirSync(e,{withFileTypes:!0})}catch{return}for(let i of s){if(!i.isDirectory()||i.name==="node_modules"||i.name.startsWith("."))continue;let o=I.join(e,i.name);if(se.existsSync(I.join(o,"package.json"))&&!r.has(o)){r.add(o);let a=at(t,o);a&&n.push(a)}else dr(t,o,r,n)}}var yr={type:"npm",detect(t){let e=hr.join(t,"package.json");if(!ct.existsSync(e))return null;let r;try{r=JSON.parse(ct.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||ct.existsSync(hr.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:K(t,n)}};import V from"fs";import T from"path";var xr={type:"nx",detect(t){return V.existsSync(T.join(t,"nx.json"))?Sr(t,t,new Set,0).map(r=>Ei(t,r,T.join(r,"project.json"))).filter(r=>r!==null):null}};function Sr(t,e,r,n){if(n>4)return[];let s;try{s=V.readdirSync(e,{withFileTypes:!0})}catch{return[]}let i=[];for(let o of s){if(!o.isDirectory())continue;let a=o.name;if(a.startsWith(".")||a==="node_modules"||a==="dist"||a===".nx")continue;let c=T.join(e,a);V.existsSync(T.join(c,"project.json"))&&!r.has(c)?(r.add(c),i.push(c)):i.push(...Sr(t,c,r,n+1))}return i}function Ei(t,e,r){let n={};try{n=JSON.parse(V.readFileSync(r,"utf-8"))}catch{return null}let s=n.name,i,o,a=T.join(e,"package.json");if(V.existsSync(a))try{let c=JSON.parse(V.readFileSync(a,"utf-8"));s=c.name??s,i=c.main,o=c.exports}catch{}return s?{name:s,root:e,relativeRoot:T.relative(t,e),entryPoints:wi(e,n,i,o)}:null}function wi(t,e,r,n){let s=[],i=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(i){let a=T.resolve(t,"../..");s.push(T.resolve(a,i)),s.push(T.resolve(t,i))}if(n){let a=n;if(typeof a=="string")s.push(T.join(t,a));else if(typeof a=="object"&&a!==null){let c=a["."];typeof c=="string"&&s.push(T.join(t,c))}}if(r&&s.push(T.join(t,r)),e.sourceRoot){let a=T.resolve(t,"../.."),c=T.resolve(a,e.sourceRoot);s.push(T.join(c,"index.ts"),T.join(c,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])s.push(T.join(t,a));let o=s.filter(Pe);return o.length>0?o.slice(0,1):s.slice(0,1)}import br from"fs";import Fi from"path";import{load as Ti}from"js-yaml";var kr={type:"pnpm",detect(t){let e=Fi.join(t,"pnpm-workspace.yaml");if(!br.existsSync(e))return null;let r=[];try{r=Ti(br.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return K(t,r)}};import Ni from"fs";import Pi from"path";var vr={type:"turborepo",detect(t){return Ni.existsSync(Pi.join(t,"turbo.json"))?[]:null}};import lt from"fs";import Cr from"path";var Er={type:"yarn",detect(t){if(!lt.existsSync(Cr.join(t,"yarn.lock")))return null;let e=Cr.join(t,"package.json");if(!lt.existsSync(e))return null;let r;try{r=JSON.parse(lt.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r)return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:K(t,n)}};var wr=[];function R(t){wr.push(t)}function Fr(){return wr}R(vr);R(xr);R(kr);R(Er);R(yr);function pt(t,e=Fr()){let r=Ii.resolve(t),n=new Map,s=[];for(let o of e){let a=o.detect(r);if(a!==null){s.push(o.type);for(let c of a)n.has(c.name)||n.set(c.name,c)}}if(s.length===0)return{root:r,type:"none",types:[],packages:[],packageMap:new Map};let i=Array.from(n.values());return{root:r,type:s[0],types:s,packages:i,packageMap:new Map(i.map(o=>[o.name,o]))}}var ie=class t{constructor(e,r){this.monorepoRoot=e;this.type=r}monorepoRoot;type;packages=new Map;addPackage(e,r){this.packages.set(e.name,{graph:r,pkg:e})}getPackageForFile(e){for(let{pkg:r}of this.packages.values())if(e===r.relativeRoot||e.startsWith(`${r.relativeRoot}/`))return r}getPackageDependencies(){let e=new Map;for(let{graph:r,pkg:n}of this.packages.values()){let s=new Set;for(let i of r.nodes.values())for(let o of i.imports)o.isWorkspace&&o.workspacePackage&&s.add(o.workspacePackage);e.set(n.name,[...s])}return e}getAffectedAcrossPackages(e){let r=this.getPackageForFile(e);if(!r)return[];let n=this.packages.get(r.name);if(!n)return[];let s=[];n.graph.traverse(e,i=>(i.path!==e&&s.push({file:i.path,package:r.name}),!0),{direction:"incoming"});for(let{graph:i,pkg:o}of this.packages.values())if(o.name!==r.name)for(let a of i.nodes.values())a.imports.some(l=>l.isWorkspace&&l.workspacePackage===r.name)&&s.push({file:a.path,package:o.name});return s}serialize(){return{monorepoRoot:this.monorepoRoot,type:this.type,packages:Array.from(this.packages.values()).map(({graph:e,pkg:r})=>({pkg:{name:r.name,relativeRoot:r.relativeRoot,entryPoints:r.entryPoints},nodes:Array.from(e.nodes.values())}))}}static deserialize(e){let r=new t(e.monorepoRoot,e.type);for(let{pkg:n,nodes:s}of e.packages){let i=new Map(s.map(a=>[a.path,a])),o=new G(i);r.packages.set(n.name,{graph:o,pkg:{...n,root:""}})}return r}};var Tr=new Map;function J(t,e){Tr.set(t,e)}function Nr(t){return Tr.get(t)}function Pr(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function Mi(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var Di=(t,e)=>!e.category||Pr(t.category,e.category),Ri=(t,e)=>!e.type||Pr(t.type,e.type),Ai=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,Li=(t,e)=>!e.path||Mi(t.path,e.path),Oi=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,Gi=(t,e)=>{if(!e.tags||e.tags.length===0)return!0;let r=e.tags.filter(s=>!s.startsWith("!")),n=e.tags.filter(s=>s.startsWith("!")).map(s=>s.slice(1));return!(r.length>0&&!r.some(s=>t.tags.some(i=>i.name===s))||n.some(s=>t.tags.some(i=>i.name===s)))},_i=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),ji=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),Wi=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),zi=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,$i=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,Bi=(t,e)=>e.minSize===void 0||t.size>=e.minSize,Ui=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,Ki=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,Vi=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,Ji=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,Hi=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,Qi=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,Yi=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,Xi=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,Zi=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,qi=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,eo=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,to=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,ro=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,no=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,so=(t,e,r)=>!e.any?.length||e.any.some(n=>oe(t,n,r)),io=[Di,Ri,Ai,Li,Oi,Gi,_i,ji,Wi,zi,$i,Bi,Ui,Ki,Vi,Ji,Hi,Qi,Yi,Xi,Zi,qi,eo,to,ro,no,so];function oe(t,e,r){return io.every(n=>n(t,e,r))}function Ir(t,e){let r=new Map;if(e.importedBy!==void 0){for(let o of t.nodes)for(let a of o.imports)if(a.toPath){let c=r.get(a.toPath)??[];c.push(o.path),r.set(a.toPath,c)}}let n=t.nodes.filter(o=>oe(o,e,r)),s=new Set(n.map(o=>o.path)),i=n.map(o=>({...o,imports:o.imports.filter(a=>!a.toPath||s.has(a.toPath))}));if(e.sort){let o=e.sortDir==="asc"?-1:1;i.sort((a,c)=>{let l=0;return e.sort==="size"?l=c.size-a.size:e.sort==="imports"?l=c.imports.length-a.imports.length:e.sort==="commitCount90d"?l=(c.commitCount90d??0)-(a.commitCount90d??0):e.sort==="exportUsage"?l=(c.avgExportUsage??0)-(a.avgExportUsage??0):e.sort==="complexity"?l=(c.complexity??0)-(a.complexity??0):e.sort==="cognitiveComplexity"&&(l=(c.cognitiveComplexity??0)-(a.cognitiveComplexity??0)),l*o})}return e.limit!==void 0&&i.splice(e.limit),{nodes:i,cycles:t.cycles?.filter(o=>o.every(a=>s.has(a)))??void 0}}function Mr(t,e){let r=e.indexOf(":");if(r===-1)return;let n=e.slice(0,r).trim().toLowerCase(),s=e.slice(r+1).trim();if(!(!n||!s))switch(n){case"category":t.category=s;break;case"type":t.type=s;break;case"tag":case"tags":s.includes("+")?t.allTags=[...t.allTags??[],...s.split("+")]:t.tags=[...t.tags??[],s];break;case"path":t.path=s;break;case"external":t.isExternal=s.toLowerCase()==="true";break;case"importsfile":t.importsFile=s;break;case"importedby":t.importedBy=s;break;case"minimports":t.minImports=parseInt(s,10);break;case"maximports":t.maxImports=parseInt(s,10);break;case"minsize":t.minSize=parseInt(s,10);break;case"maxsize":t.maxSize=parseInt(s,10);break;case"sort":t.sort=s;break;case"sortdir":t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";break;case"limit":t.limit=parseInt(s,10);break;case"hasdocstring":t.hasDocstring=s.toLowerCase()!=="false";break;case"mincoverage":t.minCoverage=parseInt(s,10);break;case"maxcoverage":t.maxCoverage=parseInt(s,10);break;case"minexportusage":t.minExportUsage=parseFloat(s);break;case"maxexportusage":t.maxExportUsage=parseFloat(s);break;case"mincomplexity":t.minComplexity=parseInt(s,10);break;case"maxcomplexity":t.maxComplexity=parseInt(s,10);break;case"mincognitivecomplexity":t.minCognitiveComplexity=parseInt(s,10);break;case"maxcognitivecomplexity":t.maxCognitiveComplexity=parseInt(s,10);break;case"mincommits":t.minCommits=parseInt(s,10);break;case"maxcommits":t.maxCommits=parseInt(s,10);break;case"isdocumented":t.isDocumented=s.toLowerCase()!=="false";break;case"isstale":t.isStale=s.toLowerCase()!=="false";break;case"lastauthor":t.lastAuthor=s;break}}function oo(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};Mr(s,n),Object.keys(s).length>0&&e.push(s)}return e}function Dr(t){let e={},r=t.split(",");for(let n of r){let s=n.trim();if(s.toLowerCase().startsWith("any(")&&s.endsWith(")")){let i=s.slice(4,-1),o=oo(i);o.length>0&&(e.any=[...e.any??[],...o]);continue}Mr(e,n)}return e}import Wr from"fs/promises";import Mo from"path";import vt from"path";import _e from"typescript";import lo from"path";import ao from"path";import w from"typescript";var Rr=new Set(["describe","test","it"]);function j(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function ft(t){let e=[];for(let r of t.statements){if(!w.isExpressionStatement(r))continue;let n=r.expression;if(!w.isCallExpression(n))continue;let s=n.expression;w.isIdentifier(s)&&Rr.has(s.text)&&e.push(n),w.isPropertyAccessExpression(s)&&w.isIdentifier(s.expression)&&Rr.has(s.expression.text)&&e.push(n)}return e}function ut(t,e,r){for(let n of t.arguments){if(!w.isObjectLiteralExpression(n))continue;let s=n.properties.find(i=>w.isPropertyAssignment(i)&&w.isIdentifier(i.name)&&i.name.text===e);if(!(!s||!w.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(w.isStringLiteral).map(i=>i.text)}return null}function mt(t,e,r,n){if(t.arguments.length===0)return null;for(let i=1;i<t.arguments.length;i++){let o=j(t.arguments,i);if(!w.isObjectLiteralExpression(o))continue;let a=o.properties.find(l=>w.isPropertyAssignment(l)&&w.isIdentifier(l.name)&&l.name.text===e);if(a)return{start:a.initializer.getStart(n),end:a.initializer.getEnd(),text:r};let c=o.getEnd()-1;return{start:c,end:c,text:`${o.properties.length>0?", ":""}${e}: ${r}`}}let s=j(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function gt(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let i=j(n,s);if(!w.isObjectLiteralExpression(i))continue;let o=i.properties.findIndex(c=>w.isPropertyAssignment(c)&&w.isIdentifier(c.name)&&c.name.text===e);if(o<0)continue;if(i.properties.length===1)return{start:j(n,s-1).getEnd(),end:i.getEnd(),text:""};let a=j(i.properties,o);return o===i.properties.length-1?{start:j(i.properties,o-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:j(i.properties,o+1).getStart(r),text:""}}return null}function dt(t,e){let r=[...e].sort((s,i)=>i.start-s.start),n=t;for(let s of r)n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function ht(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var D=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function co(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function Ie(t,e,r,n){let s=w.createSourceFile(ao.basename(t),e,w.ScriptTarget.Latest,!0),i=ft(s),[o]=i;if(!o)return e;let a=ut(o,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(co(a).sort())===JSON.stringify(c))return e;let l=ht(c.map(g=>`@${g}`)),p=i.flatMap(g=>{let d=r.length===0?gt(g,n,s):mt(g,n,l,s);return d?[d]:[]});return p.length>0?dt(e,p):e}var Me=class{name="cypress";canHandle(e){return D.has(lo.extname(e).toLowerCase())}apply(e,r,n){return Ie(e,r,n,"tags")}};import po from"path";var yt=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,xt=/^@([a-zA-Z0-9_-]+)/gm;function fo(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
7
9
  `)}
8
10
 
9
- `}function oo(t){let e=new Set;ht.lastIndex=0;let r=ht.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=ht.exec(t);return e}var Pe=class{name="gherkin";canHandle(e){return so.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(dt,""),i=oo(s),o=n.filter(c=>!i.has(c)),a=o.length>0?io(o):"";return dt.test(r)?r.replace(dt,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Dr(t,e){let r=t.replace(/\\/g,"/"),n=e.replace(/\\/g,"/"),s="";for(let i=0;i<r.length;i++){let o=r[i];o==="*"?r[i+1]==="*"?(s+=".*",i++):s+="[^/]*":o==="?"?s+="[^/]":o!==void 0&&(s+=o.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${s}$`).test(n)}import ao from"path";var yt=/^\/\/go:build mokosh_[^\n]+\n/m,co=/^package\s+\S+/m;function lo(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
10
- `}function po(t){let e=yt.exec(t);if(!e)return null;let r=e[0]??"",n=/mokosh_([a-zA-Z0-9_-]+)/g,s=[],i=n.exec(r);for(;i!==null;)i[1]&&s.push(i[1]),i=n.exec(r);return s}var Ie=class{name="go";canHandle(e){return ao.basename(e).endsWith("_test.go")}apply(e,r,n){let s=po(r),i=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return r;if(n.length===0)return r.replace(yt,"");let o=lo(i);if(s!==null)return r.replace(yt,o);let a=co.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+o}
11
- ${r.slice(c)}`}};import fo from"path";var mo=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,xt=/^ \* @group (.+)$/gm;function uo(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
11
+ `}function uo(t){let e=new Set;xt.lastIndex=0;let r=xt.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=xt.exec(t);return e}var De=class{name="gherkin";canHandle(e){return po.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(yt,""),i=uo(s),o=n.filter(c=>!i.has(c)),a=o.length>0?fo(o):"";return yt.test(r)?r.replace(yt,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Ar(t,e){let r=t.replace(/\\/g,"/"),n=e.replace(/\\/g,"/"),s="";for(let i=0;i<r.length;i++){let o=r[i];o==="*"?r[i+1]==="*"?(s+=".*",i++):s+="[^/]*":o==="?"?s+="[^/]":o!==void 0&&(s+=o.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${s}$`).test(n)}import mo from"path";var St=/^\/\/go:build mokosh_[^\n]+\n/m,go=/^package\s+\S+/m;function ho(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
12
+ `}function yo(t){let e=St.exec(t);if(!e)return null;let r=e[0]??"",n=/mokosh_([a-zA-Z0-9_-]+)/g,s=[],i=n.exec(r);for(;i!==null;)i[1]&&s.push(i[1]),i=n.exec(r);return s}var Re=class{name="go";canHandle(e){return mo.basename(e).endsWith("_test.go")}apply(e,r,n){let s=yo(r),i=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return r;if(n.length===0)return r.replace(St,"");let o=ho(i);if(s!==null)return r.replace(St,o);let a=go.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+o}
13
+ ${r.slice(c)}`}};import xo from"path";var So=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,bt=/^ \* @group (.+)$/gm;function bo(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
12
14
  `)}
13
15
 
14
- `}function go(t){let e=[];xt.lastIndex=0;let r=xt.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=xt.exec(t);return e}var Me=class{name="jest";canHandle(e){return M.has(fo.extname(e).toLowerCase())}apply(e,r,n){let s=mo.exec(r),i=s?go(s[0]):null,o=[...n].sort();if(i!==null&&JSON.stringify([...i].sort())===JSON.stringify(o))return r;let a=s?r.slice(s[0].length):r;return n.length===0?a:uo(o)+a}};import ho from"path";var De=class{name="playwright";canHandle(e){return M.has(ho.extname(e).toLowerCase())}apply(e,r,n){return Te(e,r,n,"tag")}};import yo from"path";var St=/^pytestmark\s*=\s*.+$/m,xo=/^import pytest\s*$/m;function So(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function bo(t){let e=St.exec(t);if(!e)return null;let r=e[0],n=[],s=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,i=s.exec(r);for(;i!==null;)i[1]&&n.push(i[1]),i=s.exec(r);return n}var Re=class{name="pytest";canHandle(e){return yo.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=bo(r),i=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return r;if(n.length===0)return r.replace(St,"").replace(/\n{3,}/g,`
16
+ `}function ko(t){let e=[];bt.lastIndex=0;let r=bt.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=bt.exec(t);return e}var Ae=class{name="jest";canHandle(e){return D.has(xo.extname(e).toLowerCase())}apply(e,r,n){let s=So.exec(r),i=s?ko(s[0]):null,o=[...n].sort();if(i!==null&&JSON.stringify([...i].sort())===JSON.stringify(o))return r;let a=s?r.slice(s[0].length):r;return n.length===0?a:bo(o)+a}};import vo from"path";var Le=class{name="playwright";canHandle(e){return D.has(vo.extname(e).toLowerCase())}apply(e,r,n){return Ie(e,r,n,"tag")}};import Co from"path";var kt=/^pytestmark\s*=\s*.+$/m,Eo=/^import pytest\s*$/m;function wo(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function Fo(t){let e=kt.exec(t);if(!e)return null;let r=e[0],n=[],s=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,i=s.exec(r);for(;i!==null;)i[1]&&n.push(i[1]),i=s.exec(r);return n}var Oe=class{name="pytest";canHandle(e){return Co.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=Fo(r),i=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return r;if(n.length===0)return r.replace(kt,"").replace(/\n{3,}/g,`
15
17
 
16
- `);let o=So(i);if(s!==null)return r.replace(St,o);let a=xo.test(r),c=vo(r),l=r.slice(0,c),p=r.slice(c),g=a?"":`import pytest
18
+ `);let o=wo(i);if(s!==null)return r.replace(kt,o);let a=Eo.test(r),c=To(r),l=r.slice(0,c),p=r.slice(c),g=a?"":`import pytest
17
19
  `,d=l.endsWith(`
18
20
 
19
21
  `)?"":`
20
22
  `;return`${l+d+g+o}
21
- ${p}`}};function vo(t){let e=t.split(`
22
- `),r=-1;return e.forEach((s,i)=>{(s.trimStart().startsWith("import ")||s.trimStart().startsWith("from "))&&(r=i)}),r<0?0:e.slice(0,r+1).reduce((s,i)=>s+i.length+1,0)}import Rr from"path";import Ar from"typescript";var ko=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,Ae=class{name="vitest";canHandle(e){return M.has(Rr.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(ko,""),i=Ar.createSourceFile(Rr.basename(e),s,Ar.ScriptTarget.Latest,!0),o=lt(i),[a]=o;if(!a)return s;let c=pt(a,"tags",i),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=o.flatMap(g=>{let d=n.length===0?mt(g,"tags",i):ft(g,"tags",gt(l),i);return d?[d]:[]});return p.length>0?ut(s,p):s}};var Lr={vitest:()=>new Ae,playwright:()=>new De,cypress:()=>new Ne,jest:()=>new Me},Co={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function Eo(t){let e=Le.createSourceFile("detect.ts",t,Le.ScriptTarget.Latest,!0);for(let r of e.statements){if(!Le.isImportDeclaration(r)||!Le.isStringLiteral(r.moduleSpecifier))continue;let n=Co[r.moduleSpecifier.text];if(n)return n}return null}var vt=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return M.has(bt.extname(e).toLowerCase())}apply(e,r,n){let s=Eo(r)??this.matchOverride(e)??this.defaultFramework;return(Lr[s]??Lr.vitest)().apply(e,r,n)}matchOverride(e){let r=bt.relative(this.rootDir,e).split(bt.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(Dr(n,r))return s;return null}};function Or(t="vitest",e={},r=process.cwd()){return[new Pe,new Re,new Ie,new vt(r,t,Object.entries(e))]}function Gr(t,e){return e.find(r=>r.canHandle(t))??null}var Fo=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,To=new Set(["import"]),No=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function Po(t,e,r,n){let s;try{s=await _r.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let i=Gr(t,n);if(!i)return{path:t,status:"unchanged"};let o=i.apply(t,s,e);return o===s?{path:t,status:"unchanged"}:(r||await _r.writeFile(t,o,"utf8"),{path:t,status:"updated"})}async function Io(t,e,r){let n=He(e),s=n.tagApplier?.framework??"vitest",i=n.tagApplier?.frameworkOverrides??{},o=Or(s,i,e),a={updated:0,unchanged:0,errors:0,files:[]};for(let c of t.nodes.values()){if(c.category!=="test")continue;let l=new Set,p=[];for(let h of c.tags)To.has(h.kind)&&Fo.test(h.name)&&(No.has(h.name.toLowerCase())||l.has(h.name)||(l.add(h.name),p.push(h.name)));p.sort();let g=wo.resolve(e,c.path),d=await Po(g,p,r.dryRun,o);d.path=c.path,a.files.push(d),d.status==="updated"?a.updated++:d.status==="unchanged"?a.unchanged++:a.errors++}return a}var Oe=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};import ue from"fs";import F from"path";import ic from"piscina";import{execFileSync as jr}from"child_process";var Wr="%x00%H%x09%ae%x09%at",$r=256*1024*1024;function zr(t,e){let r="",n=0;for(let s of t.split(`
23
- `)){if(s.startsWith("\0")){let[,c,l]=s.slice(1).split(" ");r=c??"",n=l?Number(l)*1e3:0;continue}if(s==="")continue;let i=s.split(" "),o=i[0];if(!o)continue;let a=o.startsWith("R")||o.startsWith("C")?i[2]:i[1];a&&e(a,r,n)}}function Br(t){let e=new Map;try{let r=jr("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${Wr}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:$r});zr(r,(n,s,i)=>{let o=e.get(n);if(o){o.commitCount90d+=1;return}e.set(n,{commitCount90d:1,lastAuthor:s||void 0,lastCommitAt:i||void 0})})}catch{return e}try{let r=jr("git",["-C",t,"log","--name-status","-M",`--format=${Wr}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:$r});zr(r,(n,s,i)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:i||void 0})})}catch{}return e}import Ur from"path";function R(t){switch(Ur.extname(t).toLowerCase()){case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".ts":case".tsx":return"typescript";case".css":return"css";case".scss":case".sass":return"scss";case".less":return"less";case".styl":return"stylus";case".coffee":return"coffeescript";case".ls":return"livescript";case".lua":return"lua";case".py":return"python";case".go":return"go";case".java":case".cpp":case".cc":case".cxx":case".c":return"unknown";case".feature":return"gherkin";case".md":case".mdx":return"markdown";default:return"unknown"}}function N(t){let e=Ur.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import Mo from"coffeescript";function A(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function J(t){let e=new Set,r=/@tag\s+([a-zA-Z0-9_-]+)/g,n=r.exec(t);for(;n!==null;)n[1]&&e.add(n[1]),n=r.exec(t);return e}function H(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||e.has("test")?"test":"logic"}function Vr(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return A(t.value)}}function W(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function Do(t,e){let r=Vr(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:N(r),type:"static"}:null}function Ro(t,e){let r=e.variable?.base?.value==="require",n=Vr(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:N(n),type:"require"}}function Kr(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=W(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>W(s.variable)??W(s)).filter(s=>!!s).map(s=>({name:s}));let n=W(r);return n?[{name:n}]:[]}function Ao(t){if(Array.isArray(t.specifiers))return t.specifiers.map(r=>r.identifier??r.original?.value).filter(r=>!!r).map(r=>({name:r}));let e=W(t.variable)??W(t.variable?.base);return e?[{name:e}]:[]}function Lo(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let i=Do(t,e);i&&r.push(i)}else if(s==="Call"){let i=Ro(t,e);i&&r.push(i)}else if(s==="Assign"){let i=W(e.variable?.base),o=e.variable?.properties?.[0]?.name?.value;i==="module"&&o==="exports"?n.push(...Kr(e,void 0)):i==="exports"&&typeof o=="string"&&n.push(...Kr(e,o))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...Ao(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function kt(t,e,r,n){if(!(!e||typeof e!="object")){Lo(t,e,r,n);for(let s in e){if(s==="locationData")continue;let i=e[s];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let o of i)kt(t,o,r,n);else kt(t,i,r,n)}}}function Jr(t,e){let r=J(e),n=H(t,r),s=[],i=[];try{kt(t,Mo.nodes(e),s,i)}catch{}let o=new Set,a=i.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}import{AstBuilder as Oo,GherkinClassicTokenMatcher as Go,Parser as _o}from"@cucumber/gherkin";import{IdGenerator as jo}from"@cucumber/messages";var Wo=jo.uuid();function Ct(t,e){let r=new Set;try{let n=new Oo(Wo),s=new Go,o=new _o(n,s).parse(e);o.feature&&(o.feature.tags.forEach(a=>{r.add(a.name.startsWith("@")?a.name.slice(1):a.name)}),o.feature.children.forEach(a=>{a.scenario&&(a.scenario.tags.forEach(c=>{r.add(c.name.startsWith("@")?c.name.slice(1):c.name)}),a.scenario.examples.forEach(c=>{c.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})),a.rule&&a.rule.children.forEach(c=>{c.scenario&&c.scenario.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})}))}catch(n){console.warn(`[GherkinParser] Failed to parse ${t}:`,n)}return{imports:[],exports:[],tags:Array.from(r).map(n=>({name:n,kind:"comment-marker"})),category:"test"}}V("gherkin",Ct);import Bo from"path";import{parser as Uo}from"@lezer/go";function $(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function ie(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
24
- `&&r++;return r}function $o(t,e){let r=1;function n(s){switch(s.type.name){case"IfStatement":case"ForStatement":r++;break;case"Case":{s.firstChild?.type.name==="case"&&r++;break}case"LogicOp":{let o=e.slice(s.from,s.to);(o==="&&"||o==="||")&&r++;break}}let i=s.firstChild;for(;i;)n(i),i=i.nextSibling}return n(t),r}function zo(t,e){let r=0;function n(s,i,o){let a=s.type.name;if(a==="IfStatement"){r+=o?1:1+i;let p=$(s),g=o?i:i+1,d=p[1];d&&d.type.name!=="Block"&&n(d,g,!1);let h=p.find(y=>y.type.name==="Block");h&&n(h,g,!1);let x=p.findIndex(y=>y.type.name==="else");if(x>=0){let y=p[x+1];y?.type.name==="IfStatement"?n(y,i,!0):y&&(r+=1,n(y,i+1,!1))}return}if(a==="ForStatement"||a==="SwitchStatement"||a==="SelectStatement"){r+=1+i;let p=s.firstChild;for(;p;)n(p,i+1,!1),p=p.nextSibling;return}if(a==="LogicOp"){let p=e.slice(s.from,s.to);(p==="&&"||p==="||")&&(r+=1)}if(i>0&&a==="FunctionLiteral"){r+=1+i;let p=s.firstChild;for(;p;)n(p,i+1,!1),p=p.nextSibling;return}let l=s.firstChild;for(;l;)n(l,i,!1),l=l.nextSibling}return n(t,0,!1),r}function Ge(t,e){return{complexity:$o(t,e),cognitiveComplexity:zo(t,e)}}function Et(t,e){let n=t.getChild("Parameters")?.getChild("Parameter"),s=n?.getChild("TypeName")??n?.getChild("PointerType")?.getChild("TypeName");return s?e.slice(s.from,s.to):void 0}function Hr(t,e){let r=[],n=t.cursor();do if(n.name==="FunctionDecl"){let s=n.node.getChild("DefName");if(s){let i=e.slice(s.from,s.to),{complexity:o,cognitiveComplexity:a}=Ge(n.node,e);r.push({name:i,line:ie(e,n.from),complexity:o,cognitiveComplexity:a})}}else if(n.name==="MethodDecl"){let s=n.node.getChild("FieldName");if(s){let i=e.slice(s.from,s.to),o=Et(n.node,e),a=o?`${o}.${i}`:i,{complexity:c,cognitiveComplexity:l}=Ge(n.node,e);r.push({name:a,line:ie(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var Ko=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,Vo=/^\/\/go:build\s+(.+)$/,Jo=/^\/\/\s*\+build\s+(.+)$/;function Yr(t,e){let r=[],n=new Map,s=new Set,i=new Set,o=new Map,a=Uo.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let S=e.slice(c.from,c.to),E=S.match(Ko);E?.[1]&&s.add(E[1]);let P=S.match(Vo);P&&Qr(P[1],i);let I=S.match(Jo);I&&Qr(I[1],i);break}case"ImportSpec":{let S=c.node.getChild("String");if(S){let P=e.slice(S.from,S.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:P,isExternal:!0,isStyle:!1,type:"static"});let I=c.node.getChild("DefName"),O=I?e.slice(I.from,I.to):P.split("/").pop();O&&O!=="_"&&O!=="."&&o.set(O,P)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let S=c.node.getChild("DefName")??c.node.getChild("FieldName")??c.node.getChild("TypeSpec")?.getChild("DefName")??c.node.getChild("VarSpec")?.getChild("DefName")??c.node.getChild("ConstSpec")?.getChild("DefName");if(S){let E=e.slice(S.from,S.to);E!=="_"&&/^[A-Z]/.test(E)&&!n.has(E)&&n.set(E,{name:E})}break}}while(c.next());let l=r.some(S=>S.rawSpecifier==="testing"),p=Bo.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",g=new Set([...s,...i]),{complexity:d,cognitiveComplexity:h}=Ge(a.topNode,e),x=Hr(a,e),y=p==="test"?[]:Ho(a,e,o);return{imports:r,exports:Array.from(n.values()),tags:Array.from(g).map(S=>({name:S,kind:"comment-marker"})),category:p,rawCallEdges:y,complexity:d,cognitiveComplexity:h,...x.length>0?{functions:x}:{}}}function Ho(t,e,r){let n=[];function s(o,a){if(o.type.name==="CallExpr"){let l=o.firstChild;if(l?.type.name==="SelectorExpr"){let p=l.firstChild,g=l.getChild("FieldName");if(p?.type.name==="VariableName"&&g){let d=e.slice(p.from,p.to),h=r.get(d);if(h){let x=e.slice(g.from,g.to);n.push({from:a,to:x,toSpecifier:h})}}}}let c=o.firstChild;for(;c;)s(c,a),c=c.nextSibling}let i=t.cursor();do if(i.name==="FunctionDecl"){let o=i.node.getChild("DefName"),a=i.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to);/^[A-Z]/.test(c)&&s(a,c)}}else if(i.name==="MethodDecl"){let o=i.node.getChild("FieldName"),a=i.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to),l=Et(i.node,e);s(a,l?`${l}.${c}`:c)}}while(i.next());return n}function Qr(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}import Qo from"livescript";function z(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function Yo(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=z(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>z(r.key)??z(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=z(t);return e?[{name:e}]:[]}function Xo(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,n=z(r.head),i=r.tails?.[0]?.key?.name;if(n==="module"&&i==="exports")return Yo(t.right);if(n==="exports"&&typeof i=="string")return[{name:i}];if(r.head?.verb==="out"&&typeof i=="string")return[{name:i}]}if(e==="Import"&&t.left?.verb==="out"){let r=t.right;if(r?.constructor?.name==="Obj"&&Array.isArray(r.items))return r.items.map(n=>z(n.val)??z(n.key)).filter(n=>!!n).map(n=>({name:n}))}return[]}var Zo=new Set(["first_line","first_column","last_line","last_column","line","column"]);function qo(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let n=t.right?.value;if(typeof n=="string"){let s=A(n);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:N(s),type:"static"}}}if(r==="Chain"&&t.head?.value==="require"){let n=t.tails?.[0];if(n?.constructor?.name==="Call"||n?.type==="Call"){let s=n.args?.[0]?.value;if(typeof s=="string"){let i=A(s);return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:N(i),type:"require"}}}}return null}function wt(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=qo(t,e);s&&n.push(s),r.push(...Xo(t));for(let i in t){if(Zo.has(i))continue;let o=t[i];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let a of o)n.push(...wt(a,e,r));else n.push(...wt(o,e,r))}return n}function Xr(t,e){let r=J(e),n=H(t,r),s=[],i=[];try{s=wt(Qo.ast(e),t,i)}catch{}let o=new Set,a=i.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}import ea from"luaparse";function ta(t,e){let r=[];function n(s){if(!(!s||typeof s!="object")){if((s.type==="CallExpression"||s.type==="StringCallExpression")&&s.base?.type==="Identifier"&&s.base?.name==="require"){let i;if(s.type==="CallExpression"){let o=s.arguments?.[0];o?.type==="StringLiteral"&&(i=A(o.raw))}else if(s.type==="StringCallExpression"){let o=s.argument;o?.type==="StringLiteral"&&(i=A(o.raw))}i&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:N(i),type:"require"})}for(let i in s){if(i==="loc")continue;let o=s[i];if(o&&typeof o=="object")if(Array.isArray(o))for(let a of o)n(a);else n(o)}}}return n(t),r}function ra(t){let e=new Set;for(let r of t)r.type==="LocalStatement"&&r.variables.forEach((n,s)=>{r.init[s]?.type==="TableConstructorExpression"&&e.add(n.name)});return e}function na(t){let e=t[t.length-1];if(e?.type!=="ReturnStatement")return[];let r=e.arguments[0];if(r?.type!=="TableConstructorExpression")return[];let n=[];for(let s of r.fields)s.type==="TableKeyString"&&n.push({name:s.key.name});return n}function sa(t){let e=t.body,r=ra(e),n=na(e);for(let i of e)if(i.type==="FunctionDeclaration")i.identifier?.type==="MemberExpression"?i.identifier.base.type==="Identifier"&&r.has(i.identifier.base.name)&&n.push({name:i.identifier.identifier.name}):i.identifier?.type==="Identifier"&&!i.isLocal&&n.push({name:i.identifier.name});else if(i.type==="AssignmentStatement")for(let o of i.variables)o.type==="MemberExpression"&&o.base.type==="Identifier"&&r.has(o.base.name)&&n.push({name:o.identifier.name});let s=new Set;return n.filter(i=>s.has(i.name)?!1:(s.add(i.name),!0))}function Zr(t,e){let r=J(e),n=H(t,r),s=[],i=[];try{let o=ea.parse(e);s=ta(o,t),i=sa(o)}catch{}return{imports:s,exports:i,tags:Array.from(r).map(o=>({name:o,kind:"comment-marker"})),category:n}}var ia=["http://","https://","mailto:","//"],oa="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",aa=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${oa})\\b`,"g"),qr;async function ca(){return qr??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),qr}function la(t){let e=t.trim();return e.length===0||e.startsWith("#")||ia.some(r=>e.startsWith(r))}function pa(t,e){let r=t.match(aa);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static"})):[]}function en(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!la(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static"}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...pa(t.value,e)),Array.isArray(t.children))for(let n of t.children)en(n,e,r)}async function tn(t,e){let n=(await ca()).parse(e),s=[];en(n,t,s);let i=new Set;return{imports:s.filter(a=>i.has(a.rawSpecifier)?!1:(i.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import ua from"path";import{parser as ga}from"@lezer/python";function fa(t){let e=1;function r(n){switch(n.type.name){case"IfStatement":{e+=$(n).filter(i=>i.type.name==="if"||i.type.name==="elif").length;break}case"TryStatement":{e+=$(n).filter(i=>i.type.name==="except").length;break}case"ForStatement":case"WhileStatement":case"ConditionalExpression":e++;break;case"and":case"or":e++;break}let s=n.firstChild;for(;s;)r(s),s=s.nextSibling}return r(t),e}function ma(t){let e=0;function r(n,s){let i=n.type.name;if(i==="IfStatement"){let c=$(n),l=0,p=0;for(;p<c.length;){let g=c[p];if(g?.type.name==="if"||g?.type.name==="elif"){let d=l>0;e+=d?1:1+s;let h=d?s:s+1,x=c[p+1],y=c[p+2];x&&r(x,h),y&&r(y,h),l++,p+=3}else if(g?.type.name==="else"){e+=1;let d=c[p+1];d&&r(d,s+1),p+=2}else p++}return}if(i==="TryStatement"){let c=$(n),l=0;for(;l<c.length;){let p=c[l];if(p?.type.name==="except"){for(e+=1+s,l++;l<c.length&&c[l]?.type.name!=="Body";)r(c[l],s),l++;l<c.length&&(r(c[l],s),l++)}else p?.type.name==="Body"&&r(p,s),l++}return}if(i==="ForStatement"||i==="WhileStatement"){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}if((i==="ConditionalExpression"||i==="and"||i==="or")&&(e+=1),s>0&&(i==="FunctionDefinition"||i==="LambdaExpression")){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}let a=n.firstChild;for(;a;)r(a,s),a=a.nextSibling}return r(t,0),e}function Ft(t){return{complexity:fa(t),cognitiveComplexity:ma(t)}}function rn(t,e){let r=[];function n(o,a){let{complexity:c,cognitiveComplexity:l}=Ft(o);r.push({name:a,line:ie(e,o.from),complexity:c,cognitiveComplexity:l})}function s(o){let a=o.firstChild;for(;a;)i(a),a=a.nextSibling}function i(o){if(o.type.name==="ClassDefinition"){let a=o.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=o.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let g=p.getChild("VariableName"),d=g?e.slice(g.from,g.to):void 0;d&&n(p,c?`${c}.${d}`:d),s(p)}else i(p);p=p.nextSibling}}return}if(o.type.name==="FunctionDefinition"){let a=o.getChild("VariableName");a&&n(o,e.slice(a.from,a.to)),s(o);return}s(o)}return i(t.topNode),r}var da=new Set(["pytest","unittest","nose","hypothesis"]);function nn(t,e){let r=[],n=[],s=new Set,i=ua.basename(t).toLowerCase(),o=ga.parse(e),a=o.cursor();do switch(a.name){case"Comment":{let h=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);h?.[1]&&s.add(h[1]);break}case"ImportStatement":{for(let h of ha(a.node,e,t))r.push(h);break}case"FunctionDefinition":case"ClassDefinition":{let h=a.node.parent;if(h?.name==="Script"||h?.name==="DecoratedStatement"&&h.parent?.name==="Script"){let y=a.node.getChild("VariableName");y&&n.push({name:e.slice(y.from,y.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let h=a.node.firstChild;h?.name==="VariableName"&&n.push({name:e.slice(h.from,h.to)})}break}}while(a.next());let c=ka(i,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=Ft(o.topNode),g=rn(o,e),d=c==="test"?[]:va(o,e);return{imports:r,exports:n,tags:Array.from(s).map(h=>({name:h,kind:"comment-marker"})),category:c,rawCallEdges:d,complexity:l,cognitiveComplexity:p,...g.length>0?{functions:g}:{}}}function ha(t,e,r){let n=t.firstChild;return n?n.name==="from"?ya(t,e,r):xa(t,e,r):[]}function ya(t,e,r){let n=t.firstChild;if(!n)return[];let s=n.nextSibling;for(;s&&s.name!=="import";)s=s.nextSibling;if(!s)return[];let i=e.slice(n.to,s.from).trim(),o=Sa(s.nextSibling,e);if(!o.length)return[];let a=0;for(;a<i.length&&i[a]===".";)a++;let c=i.slice(a);if(a===0)return[oe(r,i,o,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[oe(r,l+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[oe(r,l.slice(0,-1),["*"],!1)]:o.map(p=>oe(r,l+p,[p],!1))}function xa(t,e,r){let n=[],s=t.firstChild?.nextSibling??null;for(;s;){if(s.name==="VariableName"){let i=e.slice(s.from,s.to);for(;s.nextSibling?.name==="."&&s.nextSibling.nextSibling?.name==="VariableName";)s=s.nextSibling.nextSibling,i+=`.${e.slice(s.from,s.to)}`;s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling),n.push(oe(r,i,["*"],!0))}s=s.nextSibling}return n}function Sa(t,e){let r=[],n=t;for(;n;)n.name==="*"?r.push("*"):n.name==="VariableName"&&(r.push(e.slice(n.from,n.to)),n.nextSibling?.name==="as"&&(n=n.nextSibling.nextSibling??n.nextSibling)),n=n.nextSibling;return r}function ba(t,e){let r=new Map,n=t.cursor();do{if(n.name!=="ImportStatement")continue;let i=n.node.firstChild;if(i?.type.name!=="from")continue;let o=i.nextSibling;for(;o&&o.type.name!=="import";)o=o.nextSibling;if(!o)continue;let a=e.slice(i.to,o.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),g=o.nextSibling;for(;g;){if(g.type.name==="VariableName"){let d=e.slice(g.from,g.to),h=d;if(g.nextSibling?.type.name==="as"){let y=g.nextSibling.nextSibling;y?.type.name==="VariableName"&&(h=e.slice(y.from,y.to),g=y)}let x=c===0?a:l?p+l.replace(/\./g,"/"):p+d;r.set(h,x)}g=g.nextSibling}}while(n.next());return r}function va(t,e){let r=ba(t,e),n=[];function s(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,g=e.slice(p.from,p.to),d=r.get(g);d&&n.push({from:c,to:g,toSpecifier:d})}let l=a.firstChild;for(;l;)s(l,c),l=l.nextSibling}function i(a){let c=a.firstChild;for(;c;)o(c),c=c.nextSibling}function o(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let g=p.firstChild;for(;g;){if(g.type.name==="FunctionDefinition"){let d=g.getChild("VariableName"),h=d?e.slice(d.from,d.to):void 0;h&&s(g,l?`${l}.${h}`:h)}else o(g);g=g.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&s(a,e.slice(c.from,c.to));return}i(a)}return o(t.topNode),n}function oe(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function ka(t,e,r){return t.startsWith("test_")||t.endsWith("_test.py")?"test":t==="conftest.py"||t==="setup.py"?"config":r.has("test")||e.some(n=>da.has(n.rawSpecifier))?"test":"logic"}import on from"path";import f from"typescript";import b from"typescript";function Ca(t){let e=1;function r(n){switch(n.kind){case b.SyntaxKind.IfStatement:case b.SyntaxKind.ConditionalExpression:case b.SyntaxKind.ForStatement:case b.SyntaxKind.ForInStatement:case b.SyntaxKind.ForOfStatement:case b.SyntaxKind.WhileStatement:case b.SyntaxKind.DoStatement:case b.SyntaxKind.CatchClause:case b.SyntaxKind.CaseClause:e++;break;case b.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===b.SyntaxKind.AmpersandAmpersandToken||s===b.SyntaxKind.BarBarToken||s===b.SyntaxKind.QuestionQuestionToken)&&e++;break}}b.forEachChild(n,r)}return r(t),e}function Ea(t){let e=0;function r(n,s,i){if(b.isIfStatement(n)){e+=i?1:1+s;let a=i?s:s+1;r(n.expression,a,!1),r(n.thenStatement,a,!1),n.elseStatement&&(b.isIfStatement(n.elseStatement)?r(n.elseStatement,s,!0):(e+=1,r(n.elseStatement,s+1,!1)));return}if(b.isForStatement(n)||b.isForInStatement(n)||b.isForOfStatement(n)||b.isWhileStatement(n)||b.isDoStatement(n)||b.isSwitchStatement(n)){e+=1+s,b.forEachChild(n,a=>r(a,s+1,!1));return}if(b.isCatchClause(n)){e+=1+s,b.forEachChild(n,a=>r(a,s,!1));return}if(b.isConditionalExpression(n)&&(e+=1),b.isBinaryExpression(n)){let a=n.operatorToken.kind;(a===b.SyntaxKind.AmpersandAmpersandToken||a===b.SyntaxKind.BarBarToken||a===b.SyntaxKind.QuestionQuestionToken)&&(e+=1)}if(s>0&&(b.isFunctionDeclaration(n)||b.isFunctionExpression(n)||b.isArrowFunction(n))){e+=1+s,b.forEachChild(n,a=>r(a,s+1,!1));return}b.forEachChild(n,a=>r(a,s,!1))}return r(t,0,!1),e}function Tt(t){return{complexity:Ca(t),cognitiveComplexity:Ea(t)}}import k from"typescript";var Nt=new Set(["test","describe","it"]);function sn(t,e){wa(t,e),Ta(t,e),Na(t,e),Pa(t,e)}function wa(t,e){if((k.isFunctionDeclaration(t)||k.isVariableDeclaration(t))&&t.name&&k.isIdentifier(t.name)&&Fa(t)){let r;if(k.isFunctionDeclaration(t))r="function";else{let n=t.initializer;r=n&&(k.isArrowFunction(n)||k.isFunctionExpression(n))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Fa(t){if(k.isFunctionDeclaration(t))return k.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&k.isSourceFile(e.parent)}function Ta(t,e){if(!k.isStringLiteral(t))return;let r=t.text.match(/@[\w-]+/g);if(r)for(let n of r)e.tags.add({name:n.substring(1),kind:"comment-marker"})}function Na(t,e){if(!k.isSourceFile(t))return;let r=/@tag\s+([a-zA-Z0-9_-]+)/g,n=t.getFullText(),s=r.exec(n);for(;s!==null;)s[1]&&e.tags.add({name:s[1],kind:"comment-marker"}),s=r.exec(n)}function Pa(t,e){if(k.isCallExpression(t)&&Ia(t.expression))for(let r of t.arguments)k.isObjectLiteralExpression(r)&&Ma(r,e)}function Ia(t){return k.isIdentifier(t)?Nt.has(t.text):!!(k.isPropertyAccessExpression(t)&&(Nt.has(t.name.text)||k.isIdentifier(t.expression)&&Nt.has(t.expression.text)))}function Ma(t,e){for(let r of t.properties){if(!k.isPropertyAssignment(r)||!k.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:n}=r,s=k.isArrayLiteralExpression(n)?n.elements.filter(k.isStringLiteral):r.name.text==="tag"&&k.isStringLiteral(n)?[n]:[];for(let i of s)e.tags.add({name:i.text.replace(/^@/,""),kind:"comment-marker"})}}function Pt(t,e,r){let n=[],s=new Map,i=new Set,o=f.createSourceFile(t,e,f.ScriptTarget.Latest,!0,r==="typescript"?f.ScriptKind.TSX:f.ScriptKind.JSX),a={filePath:t,imports:n,exports:s,tags:i,rawCallEdges:[],sourceFile:o,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=y=>{La(y,a),f.forEachChild(y,c)};c(o);let l=Va(t,a);(l==="test"||l==="barrel")&&i.add({name:l,kind:"comment-marker"}),l!=="test"&&Ja(a,o);let p=o.statements[0],g=p?cn(p):void 0,{complexity:d,cognitiveComplexity:h}=Tt(o),x=Da(o);return{imports:n,exports:Array.from(s.values()),tags:Array.from(i),category:l,rawCallEdges:a.rawCallEdges??[],complexity:d,cognitiveComplexity:h,...x.length>0?{functions:x}:{},...g!==void 0?{description:g}:{}}}function Da(t){let e=[],r=(s,i)=>{let{complexity:o,cognitiveComplexity:a}=Tt(i),c=t.getLineAndCharacterOfPosition(i.getStart(t)).line+1;e.push({name:s,line:c,complexity:o,cognitiveComplexity:a})},n=(s,i)=>{if(f.isFunctionDeclaration(s)&&s.name&&s.body?r(s.name.text,s):f.isVariableDeclaration(s)&&f.isIdentifier(s.name)&&s.initializer&&(f.isArrowFunction(s.initializer)||f.isFunctionExpression(s.initializer))?r(s.name.text,s.initializer):i&&f.isMethodDeclaration(s)&&f.isIdentifier(s.name)&&s.body?r(`${i}.${s.name.text}`,s):i&&f.isConstructorDeclaration(s)&&s.body?r(`${i}.constructor`,s):i&&f.isGetAccessorDeclaration(s)&&f.isIdentifier(s.name)&&s.body?r(`${i}.get ${s.name.text}`,s):i&&f.isSetAccessorDeclaration(s)&&f.isIdentifier(s.name)&&s.body&&r(`${i}.set ${s.name.text}`,s),f.isClassDeclaration(s)&&s.name){let o=s.name.text;f.forEachChild(s,a=>n(a,o));return}f.forEachChild(s,o=>n(o,i))};return n(t,void 0),e}function an(t,e,r,n){let s={name:t},i=cn(r);i!==void 0&&(s.doc=i);let o=Ra(e);o!==void 0&&(s.flags=o);let a=Aa(e,n);return a!==void 0&&(s.signature=a),s}function cn(t){let e=f.getJSDocCommentsAndTags(t);for(let r of e)if(f.isJSDoc(r)&&r.comment)return f.getTextOfJSDocComment(r.comment)||void 0}function Ra(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=f.getJSDocTags(t).map(n=>n.tagName.text).filter(n=>e.has(n));return r.length>0?r:void 0}function Aa(t,e){let r=f.createPrinter({removeComments:!0}),n=s=>r.printNode(f.EmitHint.Unspecified,s,e);if(f.isFunctionDeclaration(t)||f.isMethodDeclaration(t)){let s=t.parameters.map(n).join(", "),i=t.type?n(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${s}) => ${i}`}if(f.isVariableDeclaration(t)){if(t.type)return n(t.type);if(t.initializer&&(f.isArrowFunction(t.initializer)||f.isFunctionExpression(t.initializer))){let s=t.initializer,i=s.parameters.map(n).join(", "),o=s.type?n(s.type):"unknown";return`(${i}) => ${o}`}return}if(f.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(f.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(f.isTypeAliasDeclaration(t))return n(t.type);if(f.isEnumDeclaration(t))return`enum ${t.name.text}`}function La(t,e){Oa(t,e),Ga(t,e),ja(t,e),Wa(t,e),Ka(t,e),sn(t,e)}function Oa(t,e){if(!f.isSourceFile(t))return;let r=t.statements.filter(n=>!f.isEmptyStatement(n));e.totalStatements=r.length,e.exportStatements=r.filter(n=>f.isExportDeclaration(n)||f.isExportAssignment(n)||It(n)).length}function Ga(t,e){if(f.isJsxElement(t)||f.isJsxSelfClosingElement(t)||f.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(f.isFunctionDeclaration(t)||f.isMethodDeclaration(t)||f.isArrowFunction(t)||f.isClassDeclaration(t)||f.isVariableStatement(t)||f.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}f.isExportDeclaration(t)&&!_a(t)&&(e.hasTypesOnly=!1)}function _a(t){return t.isTypeOnly?!0:!t.exportClause||!f.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function ja(t,e){if(!f.isImportDeclaration(t)||!t.moduleSpecifier||!f.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(f.isNamedImports(t.importClause.namedBindings))for(let s of t.importClause.namedBindings.elements)r.push(s.name.text);else f.isNamespaceImport(t.importClause.namedBindings)&&r.push("*");let n=r.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.moduleSpecifier.text,isStyle:N(t.moduleSpecifier.text),type:n,symbols:r.length>0?r:void 0})}function Wa(t,e){f.isExportDeclaration(t)?$a(t,e):f.isExportAssignment(t)?e.exports.set("default",{name:"default"}):It(t)&&Ua(t,e)}function $a(t,e){if(t.moduleSpecifier&&f.isStringLiteral(t.moduleSpecifier))za(t,t.moduleSpecifier.text,e);else if(t.exportClause&&f.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let n=r.name.text;e.exports.set(n,{name:n})}}function za(t,e,r){let n=Ba(t),s={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:N(e),type:"re-export"};n.length>0&&(s.symbols=n),r.imports.push(s)}function Ba(t){return t.exportClause?f.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function Ua(t,e){if((f.isFunctionDeclaration(t)||f.isClassDeclaration(t)||f.isInterfaceDeclaration(t)||f.isTypeAliasDeclaration(t)||f.isEnumDeclaration(t))&&t.name){let n=t.name.text;e.exports.set(n,an(n,t,t,e.sourceFile));return}if(f.isVariableStatement(t)){for(let n of t.declarationList.declarations)if(f.isIdentifier(n.name)){let s=n.name.text;e.exports.set(s,an(s,n,t,e.sourceFile))}}}function Ka(t,e){if(!f.isCallExpression(t))return;let r=t.arguments[0];!r||!f.isStringLiteral(r)||(t.expression.kind===f.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"dynamic"}):f.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"require"}))}function Va(t,e){let r=on.basename(t).toLowerCase(),n=on.extname(t).toLowerCase();return Y().some(i=>r.includes(i))?"test":Ot(r)?"config":e.imports.some(i=>Ue().some(o=>i.rawSpecifier.includes(o)))?"test":n===".tsx"||n===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>Ve()?"barrel":"logic"}function It(t){return f.canHaveModifiers(t)&&f.getModifiers(t)?.some(e=>e.kind===f.SyntaxKind.ExportKeyword)===!0}function Ja(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let n=new Map;for(let s of e.statements){if(!f.isImportDeclaration(s)||!f.isStringLiteral(s.moduleSpecifier))continue;let i=s.moduleSpecifier.text,o=s.importClause;if(o&&(o.name&&n.set(o.name.text,i),o.namedBindings&&f.isNamedImports(o.namedBindings)))for(let a of o.namedBindings.elements)n.set(a.name.text,i)}if(n.size!==0)for(let s of e.statements){let i=Qa(s);if(i){let o=Ya(s);o&&_e(o,i,n,r);continue}f.isClassDeclaration(s)&&s.name&&Ha(s,s.name.text,n,r)}}function Ha(t,e,r,n){for(let s of t.members)f.isMethodDeclaration(s)&&s.body&&f.isIdentifier(s.name)?_e(s.body,`${e}.${s.name.text}`,r,n):f.isConstructorDeclaration(s)&&s.body&&_e(s.body,`${e}.constructor`,r,n)}function Qa(t){if(It(t)){if(f.isFunctionDeclaration(t)&&t.name)return t.name.text;if(f.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(f.isIdentifier(e.name)&&e.initializer&&(f.isArrowFunction(e.initializer)||f.isFunctionExpression(e.initializer)))return e.name.text}}}function Ya(t){if(f.isFunctionDeclaration(t))return t.body;if(f.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(f.isArrowFunction(e.initializer)||f.isFunctionExpression(e.initializer)))return e.initializer}}function _e(t,e,r,n){if(f.isCallExpression(t)&&f.isIdentifier(t.expression)){let s=t.expression.text,i=r.get(s);i&&!n.some(o=>o.from===e&&o.to===s&&o.toSpecifier===i)&&n.push({from:e,to:s,toSpecifier:i})}f.forEachChild(t,s=>_e(s,e,r,n))}function je(t,e){if(e.length===0)return"ui";let r=!1;return t.walk(n=>{if(n.type==="rule")return r=!0,!1}),r?"ui":"barrel"}function ln(t,e){let r=[],n=/@require\s+['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let o=s[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"require"}),s=n.exec(t)}let i=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(s=i.exec(t);s!==null;){let o=s[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=i.exec(t)}return r}function pn(t,e){if(e.length===0)return"ui";try{let r=Be("stylus");return new r.Parser(t).parse().nodes.some(i=>i.constructor.name!=="Import")?"ui":"barrel"}catch{return t.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function ae(t,e){let r=R(t);if(r==="stylus"){let i=ln(e,t);return{imports:i,exports:[],tags:[],category:pn(e,i)}}if(r==="scss"){let{imports:i,root:o,exports:a,tags:c}=Ce(e,t);return{imports:i,exports:a,tags:c,category:je(o,i)}}if(r==="less"){let{imports:i,root:o,exports:a,tags:c}=ke(e,t);return{imports:i,exports:a,tags:c,category:je(o,i)}}let{imports:n,root:s}=ve(e,t);return{imports:n,exports:[],tags:[],category:je(s,n)}}for(let[t,e]of[["javascript",(r,n)=>Pt(r,n,"javascript")],["typescript",(r,n)=>Pt(r,n,"typescript")],["css",ae],["scss",ae],["less",ae],["stylus",ae],["coffeescript",Jr],["livescript",Xr],["lua",Zr],["python",nn],["go",Yr],["gherkin",Ct],["markdown",tn]])V(t,e);async function fn(t,e){let r=R(t),n=Fr(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}import mn from"path";function gn(t,e){for(let r of t.values()){let n=e.get(r.path);n!==void 0&&(r.coveragePct=n)}}function dn(t,e){for(let r of t)if(r.isExternal){let n=r.rawSpecifier.startsWith("@")?r.rawSpecifier.split("/").slice(0,2).join("/"):r.rawSpecifier.split("/")[0];n&&!e.some(s=>s.name===n)&&e.push({name:n,kind:"library"})}}function hn(t){for(let e of t.values())if(e.category==="test")for(let r of e.imports){if(r.isExternal||!r.toPath)continue;let n=t.get(r.toPath);n&&(n.category!=="logic"&&n.category!=="barrel"||(n.testedBy??=[],n.testedBy.includes(e.path)||n.testedBy.push(e.path)))}}function yn(t){for(let e of t.values())if(e.type==="markdown")for(let r of e.imports){if(r.isExternal||!r.toPath)continue;let n=t.get(r.toPath);!n||n===e||(n.documentedBy??=[],n.documentedBy.includes(e.path)||n.documentedBy.push(e.path),n.category==="logic"&&(n.lastCommitAt??0)>(e.lastCommitAt??0)&&(e.staleFor??=[],e.staleFor.includes(n.path)||e.staleFor.push(n.path)))}}function un(t){return Math.round(t*1e4)/1e4}function xn(t){for(let e of t.values()){let r=[];for(let n of e.imports){if(n.isExternal||!n.toPath)continue;let s=t.get(n.toPath);if(!s||s.exports.length===0)continue;let i;if(n.symbols===void 0){if(n.type==="side-effect")continue;i=1}else n.symbols.includes("*")?i=1:i=n.symbols.length/s.exports.length;n.exportUsageRatio=un(Math.min(1,i)),r.push(n.exportUsageRatio)}r.length>0&&(e.avgExportUsage=un(r.reduce((n,s)=>n+s,0)/r.length),e.maxExportUsage=Math.max(...r))}}function Mt(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function Xa(t,e){let r=e.toPath,n=mn.basename(r,mn.extname(r)).replace(/\.(test|spec)$/,"");Mt(t.tags,n,"import")}function Za(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)Mt(t.tags,r,"import")}function qa(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&Mt(t.tags,s.name,"comment-marker")}function Sn(t){for(let e of t.values())if(e.category==="test")for(let r of e.imports)!r.toPath||r.isExternal||(Xa(e,r),Za(e,r),qa(e,r,t))}import We from"fs";import L from"path";import kn from"fs";import Q from"path";var ce=class{extensions=[".go"];goModCache=new Map;resolve(e,r,n,s){let{mod:i,replaces:o}=this.readGoMod(n);if(!i)return null;let a=this.applyReplace(r,o,n);if(a!==void 0)return vn(a);if(r!==i&&!r.startsWith(`${i}/`))return null;let c=r.slice(i.length).replace(/^\//,"");return c?vn(Q.join(n,c)):null}readGoMod(e){let r=this.goModCache.get(e);if(r!==void 0)return r;let n={mod:null,replaces:new Map};try{let s=kn.readFileSync(Q.join(e,"go.mod"),"utf-8"),i=ec(s,e);return this.goModCache.set(e,i),i}catch{return this.goModCache.set(e,n),n}}applyReplace(e,r,n){for(let[s,i]of r){if(e===s)return i;if(e.startsWith(`${s}/`)){let o=e.slice(s.length+1);return Q.join(i,o)}}}};function ec(t,e){let r=t.split(`
25
- `),n=null,s=new Map,i=!1;for(let o of r){let a=o.trim();if(a.startsWith("module ")){n=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){i=!0;continue}if(i&&a===")"){i=!1;continue}if(i&&a.includes("=>")){bn(a,e,s);continue}!i&&/^replace\s+/.test(a)&&a.includes("=>")&&bn(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function bn(t,e,r){let[n,s]=t.split("=>").map(a=>a.trim());if(!n||!s)return;let i=n.split(/\s+/)[0];if(!s.startsWith(".")&&!s.startsWith("/"))return;let o=Q.isAbsolute(s)?s:Q.resolve(e,s);r.set(i,o)}function vn(t){let e;try{e=kn.readdirSync(t,{withFileTypes:!0})}catch{return null}let r=e.filter(n=>n.isFile()&&n.name.endsWith(".go")&&!n.name.endsWith("_test.go")).map(n=>({path:Q.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}import tc from"fs";import Dt from"path";var le=class{extensions=[".lua"];resolve(e,r,n,s){let i=r.replace(/\./g,Dt.sep),o=[n,Dt.join(n,"lib")];for(let a of o){if(!tc.existsSync(a))continue;let c=s(Dt.join(a,"_dummy.lua"),i);if(c)return[c]}return null}};import rc from"path";var pe=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let i=s(rc.join(n,"_dummy"),`./${r}`);return i?[i]:null}};import nc from"fs";import Rt from"path";var fe=class{extensions=[".py"];resolve(e,r,n,s){let i=r.replace(/\./g,Rt.sep),o=Rt.join(n,`${i}.py`);if(Cn(o))return[{path:o,isExternal:!1}];let a=Rt.join(n,i,"__init__.py");return Cn(a)?[{path:a,isExternal:!1}]:null}};function Cn(t){try{return nc.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import En from"path";var sc=["~","http://","https://","//","data:","sass:"],me=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,r,n,s){if(sc.some(p=>r.startsWith(p)))return null;let i=s(e,r);if(i)return[i];let o=En.dirname(r),a=En.basename(r),c=o==="."?`_${a}`:`${o}/_${a}`,l=s(e,c);return l?[l]:null}};var B=class{constructor(e,r={}){this.rootDir=e;this.workspaceMap=r.workspaceMap??new Map,this.tsconfigSearchPaths=r.tsconfigSearchPaths??[e],this.pathAliases=r.pathAliases,this.langResolvers=r.langResolvers??[new fe,new le,new ce,new me,new pe]}rootDir;workspaceMap;tsconfigSearchPaths;pathAliases;langResolvers;resolveAll(e,r){let n=this.resolvePathAlias(r);if(n)return[n];if(r.startsWith(".")||r.startsWith("/")){let o=this.resolveLocalPath(e,r);return o?[o]:[]}let s=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>e.endsWith(a))){let a=o.resolve(e,r,this.rootDir,s);if(a)return a}let i=this.resolveWorkspaceImport(r);return i?[i]:[{path:r,isExternal:!0}]}resolve(e,r){let n=this.resolvePathAlias(r);if(n)return n;if(r.startsWith(".")||r.startsWith("/"))return this.resolveLocalPath(e,r);let s=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>e.endsWith(a))){let a=o.resolve(e,r,this.rootDir,s);if(a)return a[0]??null}let i=this.resolveWorkspaceImport(r);return i||{path:r,isExternal:!0}}resolveLocalPath(e,r){let n=L.dirname(e),s=r.startsWith("/")?r:L.resolve(n,r),i=!s.startsWith(this.rootDir),o=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature",".md",".mdx"],a=s.match(/\.(js|mjs|cjs)$/);if(a){let c=s.slice(0,-a[0].length);for(let l of[".ts",".tsx"]){let p=this.tryExtensions(c,l,i);if(p)return p}}for(let c of o){let l=this.tryExtensions(s,c,i);if(l)return l}return i?{path:s,isExternal:!0}:null}tryExtensions(e,r,n){let s=e+r;if(this.isFile(s))return{path:s,isExternal:n};let i=L.join(e,`index${r}`);if(this.isFile(i))return{path:i,isExternal:n};if(r===".py"){let o=L.join(e,"__init__.py");if(this.isFile(o))return{path:o,isExternal:n}}return null}isFile(e){try{return We.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(e){if(this.pathAliases)for(let r in this.pathAliases){let n=this.matchAliasPattern(r,e),s=this.pathAliases[r];if(n&&s){let i=this.tryAliasSubstitutions(s,n[1]||"");if(i)return i}}for(let r of this.tsconfigSearchPaths){let n=L.join(r,"tsconfig.json");if(We.existsSync(n))try{let i=JSON.parse(We.readFileSync(n,"utf-8")).compilerOptions?.paths;if(!i)continue;for(let o in i){let a=this.matchAliasPattern(o,e);if(a){let c=this.tryAliasSubstitutions(i[o],a[1]||"",r);if(c)return c}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(e,r){let n=this.aliasRegexCache.get(e);if(!n){let s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");n=new RegExp(`^${s}$`),this.aliasRegexCache.set(e,n)}return r.match(n)}tryAliasSubstitutions(e,r,n=this.rootDir){let s=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let i of e){let o=i.replace("*",r),a=L.resolve(n,o);for(let c of s){let l=this.tryExtensions(a,c,!1);if(l)return l}}return null}resolveWorkspaceImport(e){if(this.workspaceMap.size===0)return null;for(let[r,n]of this.workspaceMap){if(e!==r&&!e.startsWith(`${r}/`))continue;let s=e.slice(r.length),i={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:r};if(!s){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let c=L.join(n,a);try{if(We.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...i,path:c}}catch{}}return{...i,path:n}}let o=this.resolveLocalPath(L.join(n,"_dummy"),s.slice(1));return o?{...i,path:o.path}:null}return null}};var oc=["tests","test","__tests__","specs","spec"],wn=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),ac=20;function cc(t,e){if(t.length===0)return e;let r=t.map(o=>F.dirname(o).split(F.sep)),n=r[0]??[];for(let o of r.slice(1)){let a=0;for(;a<n.length&&a<o.length&&n[a]===o[a];)a++;n=n.slice(0,a)}let s=n.join(F.sep)||F.sep,i=F.relative(e,s);return i.startsWith("..")||F.isAbsolute(i)?e:s}var ge=class{constructor(e,r=null,n,s,i=!1,o=new Map,a=!0){this.rootDir=e;this.enableGitStats=i;this.coverageMap=o;this.parallelParsing=a;this.previousGraph=r,this.resolver=n||new B(e),this.lockFile=Yt(e),s&&(this.progressCallback=s)}rootDir;enableGitStats;coverageMap;parallelParsing;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;async build(e){let r=e.map(n=>F.isAbsolute(n)?n:F.resolve(this.rootDir,n));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=Br(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(cc(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
23
+ ${p}`}};function To(t){let e=t.split(`
24
+ `),r=-1;return e.forEach((s,i)=>{(s.trimStart().startsWith("import ")||s.trimStart().startsWith("from "))&&(r=i)}),r<0?0:e.slice(0,r+1).reduce((s,i)=>s+i.length+1,0)}import Lr from"path";import Or from"typescript";var No=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,Ge=class{name="vitest";canHandle(e){return D.has(Lr.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(No,""),i=Or.createSourceFile(Lr.basename(e),s,Or.ScriptTarget.Latest,!0),o=ft(i),[a]=o;if(!a)return s;let c=ut(a,"tags",i),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=o.flatMap(g=>{let d=n.length===0?gt(g,"tags",i):mt(g,"tags",ht(l),i);return d?[d]:[]});return p.length>0?dt(s,p):s}};var Gr={vitest:()=>new Ge,playwright:()=>new Le,cypress:()=>new Me,jest:()=>new Ae},Po={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function Io(t){let e=_e.createSourceFile("detect.ts",t,_e.ScriptTarget.Latest,!0);for(let r of e.statements){if(!_e.isImportDeclaration(r)||!_e.isStringLiteral(r.moduleSpecifier))continue;let n=Po[r.moduleSpecifier.text];if(n)return n}return null}var Ct=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return D.has(vt.extname(e).toLowerCase())}apply(e,r,n){let s=Io(r)??this.matchOverride(e)??this.defaultFramework;return(Gr[s]??Gr.vitest)().apply(e,r,n)}matchOverride(e){let r=vt.relative(this.rootDir,e).split(vt.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(Ar(n,r))return s;return null}};function _r(t="vitest",e={},r=process.cwd()){return[new De,new Oe,new Re,new Ct(r,t,Object.entries(e))]}function jr(t,e){return e.find(r=>r.canHandle(t))??null}var Do=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,Ro=new Set(["import"]),Ao=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function Lo(t,e,r,n){let s;try{s=await Wr.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let i=jr(t,n);if(!i)return{path:t,status:"unchanged"};let o=i.apply(t,s,e);return o===s?{path:t,status:"unchanged"}:(r||await Wr.writeFile(t,o,"utf8"),{path:t,status:"updated"})}async function Oo(t,e,r){let n=Xe(e),s=n.tagApplier?.framework??"vitest",i=n.tagApplier?.frameworkOverrides??{},o=_r(s,i,e),a={updated:0,unchanged:0,errors:0,files:[]};for(let c of t.nodes.values()){if(c.category!=="test")continue;let l=new Set,p=[];for(let h of c.tags)Ro.has(h.kind)&&Do.test(h.name)&&(Ao.has(h.name.toLowerCase())||l.has(h.name)||(l.add(h.name),p.push(h.name)));p.sort();let g=Mo.resolve(e,c.path),d=await Lo(g,p,r.dryRun,o);d.path=c.path,a.files.push(d),d.status==="updated"?a.updated++:d.status==="unchanged"?a.unchanged++:a.errors++}return a}var je=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};import de from"fs";import N from"path";import fc from"piscina";import{execFileSync as zr}from"child_process";var $r="%x00%H%x09%ae%x09%at",Br=256*1024*1024;function Ur(t,e){let r="",n=0;for(let s of t.split(`
25
+ `)){if(s.startsWith("\0")){let[,c,l]=s.slice(1).split(" ");r=c??"",n=l?Number(l)*1e3:0;continue}if(s==="")continue;let i=s.split(" "),o=i[0];if(!o)continue;let a=o.startsWith("R")||o.startsWith("C")?i[2]:i[1];a&&e(a,r,n)}}function Kr(t){let e=new Map;try{let r=zr("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${$r}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:Br});Ur(r,(n,s,i)=>{let o=e.get(n);if(o){o.commitCount90d+=1;return}e.set(n,{commitCount90d:1,lastAuthor:s||void 0,lastCommitAt:i||void 0})})}catch{return e}try{let r=zr("git",["-C",t,"log","--name-status","-M",`--format=${$r}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:Br});Ur(r,(n,s,i)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:i||void 0})})}catch{}return e}import Vr from"path";function A(t){switch(Vr.extname(t).toLowerCase()){case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".ts":case".tsx":return"typescript";case".css":return"css";case".scss":case".sass":return"scss";case".less":return"less";case".styl":return"stylus";case".coffee":return"coffeescript";case".ls":return"livescript";case".lua":return"lua";case".py":return"python";case".go":return"go";case".java":case".cpp":case".cc":case".cxx":case".c":return"unknown";case".feature":return"gherkin";case".md":case".mdx":return"markdown";default:return"unknown"}}function M(t){let e=Vr.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import Go from"coffeescript";function L(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function H(t){let e=new Set,r=/@tag\s+([a-zA-Z0-9_-]+)/g,n=r.exec(t);for(;n!==null;)n[1]&&e.add(n[1]),n=r.exec(t);return e}function Q(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||e.has("test")?"test":"logic"}function Hr(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return L(t.value)}}function W(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function _o(t,e){let r=Hr(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:M(r),type:"static"}:null}function jo(t,e){let r=e.variable?.base?.value==="require",n=Hr(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:M(n),type:"require"}}function Jr(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=W(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>W(s.variable)??W(s)).filter(s=>!!s).map(s=>({name:s}));let n=W(r);return n?[{name:n}]:[]}function Wo(t){if(Array.isArray(t.specifiers))return t.specifiers.map(r=>r.identifier??r.original?.value).filter(r=>!!r).map(r=>({name:r}));let e=W(t.variable)??W(t.variable?.base);return e?[{name:e}]:[]}function zo(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let i=_o(t,e);i&&r.push(i)}else if(s==="Call"){let i=jo(t,e);i&&r.push(i)}else if(s==="Assign"){let i=W(e.variable?.base),o=e.variable?.properties?.[0]?.name?.value;i==="module"&&o==="exports"?n.push(...Jr(e,void 0)):i==="exports"&&typeof o=="string"&&n.push(...Jr(e,o))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...Wo(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function Et(t,e,r,n){if(!(!e||typeof e!="object")){zo(t,e,r,n);for(let s in e){if(s==="locationData")continue;let i=e[s];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let o of i)Et(t,o,r,n);else Et(t,i,r,n)}}}function Qr(t,e){let r=H(e),n=Q(t,r),s=[],i=[];try{Et(t,Go.nodes(e),s,i)}catch{}let o=new Set,a=i.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}import{AstBuilder as $o,GherkinClassicTokenMatcher as Bo,Parser as Uo}from"@cucumber/gherkin";import{IdGenerator as Ko}from"@cucumber/messages";var Vo=Ko.uuid();function wt(t,e){let r=new Set;try{let n=new $o(Vo),s=new Bo,o=new Uo(n,s).parse(e);o.feature&&(o.feature.tags.forEach(a=>{r.add(a.name.startsWith("@")?a.name.slice(1):a.name)}),o.feature.children.forEach(a=>{a.scenario&&(a.scenario.tags.forEach(c=>{r.add(c.name.startsWith("@")?c.name.slice(1):c.name)}),a.scenario.examples.forEach(c=>{c.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})),a.rule&&a.rule.children.forEach(c=>{c.scenario&&c.scenario.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})}))}catch(n){console.warn(`[GherkinParser] Failed to parse ${t}:`,n)}return{imports:[],exports:[],tags:Array.from(r).map(n=>({name:n,kind:"comment-marker"})),category:"test"}}J("gherkin",wt);import Qo from"path";import{parser as Yo}from"@lezer/go";function z(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function ae(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
26
+ `&&r++;return r}function Jo(t,e){let r=1;function n(s){switch(s.type.name){case"IfStatement":case"ForStatement":r++;break;case"Case":{s.firstChild?.type.name==="case"&&r++;break}case"LogicOp":{let o=e.slice(s.from,s.to);(o==="&&"||o==="||")&&r++;break}}let i=s.firstChild;for(;i;)n(i),i=i.nextSibling}return n(t),r}function Ho(t,e){let r=0;function n(s,i,o){let a=s.type.name;if(a==="IfStatement"){r+=o?1:1+i;let p=z(s),g=o?i:i+1,d=p[1];d&&d.type.name!=="Block"&&n(d,g,!1);let h=p.find(x=>x.type.name==="Block");h&&n(h,g,!1);let S=p.findIndex(x=>x.type.name==="else");if(S>=0){let x=p[S+1];x?.type.name==="IfStatement"?n(x,i,!0):x&&(r+=1,n(x,i+1,!1))}return}if(a==="ForStatement"||a==="SwitchStatement"||a==="SelectStatement"){r+=1+i;let p=s.firstChild;for(;p;)n(p,i+1,!1),p=p.nextSibling;return}if(a==="LogicOp"){let p=e.slice(s.from,s.to);(p==="&&"||p==="||")&&(r+=1)}if(i>0&&a==="FunctionLiteral"){r+=1+i;let p=s.firstChild;for(;p;)n(p,i+1,!1),p=p.nextSibling;return}let l=s.firstChild;for(;l;)n(l,i,!1),l=l.nextSibling}return n(t,0,!1),r}function We(t,e){return{complexity:Jo(t,e),cognitiveComplexity:Ho(t,e)}}function Ft(t,e){let n=t.getChild("Parameters")?.getChild("Parameter"),s=n?.getChild("TypeName")??n?.getChild("PointerType")?.getChild("TypeName");return s?e.slice(s.from,s.to):void 0}function Yr(t,e){let r=[],n=t.cursor();do if(n.name==="FunctionDecl"){let s=n.node.getChild("DefName");if(s){let i=e.slice(s.from,s.to),{complexity:o,cognitiveComplexity:a}=We(n.node,e);r.push({name:i,line:ae(e,n.from),complexity:o,cognitiveComplexity:a})}}else if(n.name==="MethodDecl"){let s=n.node.getChild("FieldName");if(s){let i=e.slice(s.from,s.to),o=Ft(n.node,e),a=o?`${o}.${i}`:i,{complexity:c,cognitiveComplexity:l}=We(n.node,e);r.push({name:a,line:ae(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var Xo=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,Zo=/^\/\/go:build\s+(.+)$/,qo=/^\/\/\s*\+build\s+(.+)$/;function Zr(t,e){let r=[],n=new Map,s=new Set,i=new Set,o=new Map,a=Yo.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let k=e.slice(c.from,c.to),y=k.match(Xo);y?.[1]&&s.add(y[1]);let b=k.match(Zo);b&&Xr(b[1],i);let F=k.match(qo);F&&Xr(F[1],i);break}case"ImportSpec":{let k=c.node.getChild("String");if(k){let b=e.slice(k.from,k.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:b,isExternal:!0,isStyle:!1,type:"static"});let F=c.node.getChild("DefName"),P=F?e.slice(F.from,F.to):b.split("/").pop();P&&P!=="_"&&P!=="."&&o.set(P,b)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let k=c.node.getChild("DefName")??c.node.getChild("FieldName")??c.node.getChild("TypeSpec")?.getChild("DefName")??c.node.getChild("VarSpec")?.getChild("DefName")??c.node.getChild("ConstSpec")?.getChild("DefName");if(k){let y=e.slice(k.from,k.to);y!=="_"&&/^[A-Z]/.test(y)&&!n.has(y)&&n.set(y,{name:y})}break}}while(c.next());let l=r.some(k=>k.rawSpecifier==="testing"),p=Qo.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",g=new Set([...s,...i]),{complexity:d,cognitiveComplexity:h}=We(a.topNode,e),S=Yr(a,e),x=p==="test"?[]:ea(a,e,o);return{imports:r,exports:Array.from(n.values()),tags:Array.from(g).map(k=>({name:k,kind:"comment-marker"})),category:p,rawCallEdges:x,complexity:d,cognitiveComplexity:h,...S.length>0?{functions:S}:{}}}function ea(t,e,r){let n=[];function s(o,a){if(o.type.name==="CallExpr"){let l=o.firstChild;if(l?.type.name==="SelectorExpr"){let p=l.firstChild,g=l.getChild("FieldName");if(p?.type.name==="VariableName"&&g){let d=e.slice(p.from,p.to),h=r.get(d);if(h){let S=e.slice(g.from,g.to);n.push({from:a,to:S,toSpecifier:h})}}}}let c=o.firstChild;for(;c;)s(c,a),c=c.nextSibling}let i=t.cursor();do if(i.name==="FunctionDecl"){let o=i.node.getChild("DefName"),a=i.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to);/^[A-Z]/.test(c)&&s(a,c)}}else if(i.name==="MethodDecl"){let o=i.node.getChild("FieldName"),a=i.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to),l=Ft(i.node,e);s(a,l?`${l}.${c}`:c)}}while(i.next());return n}function Xr(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}import ta from"livescript";function $(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function ra(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=$(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>$(r.key)??$(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=$(t);return e?[{name:e}]:[]}function na(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,n=$(r.head),i=r.tails?.[0]?.key?.name;if(n==="module"&&i==="exports")return ra(t.right);if(n==="exports"&&typeof i=="string")return[{name:i}];if(r.head?.verb==="out"&&typeof i=="string")return[{name:i}]}if(e==="Import"&&t.left?.verb==="out"){let r=t.right;if(r?.constructor?.name==="Obj"&&Array.isArray(r.items))return r.items.map(n=>$(n.val)??$(n.key)).filter(n=>!!n).map(n=>({name:n}))}return[]}var sa=new Set(["first_line","first_column","last_line","last_column","line","column"]);function ia(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let n=t.right?.value;if(typeof n=="string"){let s=L(n);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:M(s),type:"static"}}}if(r==="Chain"&&t.head?.value==="require"){let n=t.tails?.[0];if(n?.constructor?.name==="Call"||n?.type==="Call"){let s=n.args?.[0]?.value;if(typeof s=="string"){let i=L(s);return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:M(i),type:"require"}}}}return null}function Tt(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=ia(t,e);s&&n.push(s),r.push(...na(t));for(let i in t){if(sa.has(i))continue;let o=t[i];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let a of o)n.push(...Tt(a,e,r));else n.push(...Tt(o,e,r))}return n}function qr(t,e){let r=H(e),n=Q(t,r),s=[],i=[];try{s=Tt(ta.ast(e),t,i)}catch{}let o=new Set,a=i.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}import oa from"luaparse";function aa(t,e){let r=[];function n(s){if(!(!s||typeof s!="object")){if((s.type==="CallExpression"||s.type==="StringCallExpression")&&s.base?.type==="Identifier"&&s.base?.name==="require"){let i;if(s.type==="CallExpression"){let o=s.arguments?.[0];o?.type==="StringLiteral"&&(i=L(o.raw))}else if(s.type==="StringCallExpression"){let o=s.argument;o?.type==="StringLiteral"&&(i=L(o.raw))}i&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:M(i),type:"require"})}for(let i in s){if(i==="loc")continue;let o=s[i];if(o&&typeof o=="object")if(Array.isArray(o))for(let a of o)n(a);else n(o)}}}return n(t),r}function ca(t){let e=new Set;for(let r of t)r.type==="LocalStatement"&&r.variables.forEach((n,s)=>{r.init[s]?.type==="TableConstructorExpression"&&e.add(n.name)});return e}function la(t){let e=t[t.length-1];if(e?.type!=="ReturnStatement")return[];let r=e.arguments[0];if(r?.type!=="TableConstructorExpression")return[];let n=[];for(let s of r.fields)s.type==="TableKeyString"&&n.push({name:s.key.name});return n}function pa(t){let e=t.body,r=ca(e),n=la(e);for(let i of e)if(i.type==="FunctionDeclaration")i.identifier?.type==="MemberExpression"?i.identifier.base.type==="Identifier"&&r.has(i.identifier.base.name)&&n.push({name:i.identifier.identifier.name}):i.identifier?.type==="Identifier"&&!i.isLocal&&n.push({name:i.identifier.name});else if(i.type==="AssignmentStatement")for(let o of i.variables)o.type==="MemberExpression"&&o.base.type==="Identifier"&&r.has(o.base.name)&&n.push({name:o.identifier.name});let s=new Set;return n.filter(i=>s.has(i.name)?!1:(s.add(i.name),!0))}function en(t,e){let r=H(e),n=Q(t,r),s=[],i=[];try{let o=oa.parse(e);s=aa(o,t),i=pa(o)}catch{}return{imports:s,exports:i,tags:Array.from(r).map(o=>({name:o,kind:"comment-marker"})),category:n}}var fa=["http://","https://","mailto:","//"],ua="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",ma=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${ua})\\b`,"g"),tn;async function ga(){return tn??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),tn}function da(t){let e=t.trim();return e.length===0||e.startsWith("#")||fa.some(r=>e.startsWith(r))}function ha(t,e){let r=t.match(ma);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static"})):[]}function rn(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!da(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static"}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...ha(t.value,e)),Array.isArray(t.children))for(let n of t.children)rn(n,e,r)}async function nn(t,e){let n=(await ga()).parse(e),s=[];rn(n,t,s);let i=new Set;return{imports:s.filter(a=>i.has(a.rawSpecifier)?!1:(i.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import Sa from"path";import{parser as ba}from"@lezer/python";function ya(t){let e=1;function r(n){switch(n.type.name){case"IfStatement":{e+=z(n).filter(i=>i.type.name==="if"||i.type.name==="elif").length;break}case"TryStatement":{e+=z(n).filter(i=>i.type.name==="except").length;break}case"ForStatement":case"WhileStatement":case"ConditionalExpression":e++;break;case"and":case"or":e++;break}let s=n.firstChild;for(;s;)r(s),s=s.nextSibling}return r(t),e}function xa(t){let e=0;function r(n,s){let i=n.type.name;if(i==="IfStatement"){let c=z(n),l=0,p=0;for(;p<c.length;){let g=c[p];if(g?.type.name==="if"||g?.type.name==="elif"){let d=l>0;e+=d?1:1+s;let h=d?s:s+1,S=c[p+1],x=c[p+2];S&&r(S,h),x&&r(x,h),l++,p+=3}else if(g?.type.name==="else"){e+=1;let d=c[p+1];d&&r(d,s+1),p+=2}else p++}return}if(i==="TryStatement"){let c=z(n),l=0;for(;l<c.length;){let p=c[l];if(p?.type.name==="except"){for(e+=1+s,l++;l<c.length&&c[l]?.type.name!=="Body";)r(c[l],s),l++;l<c.length&&(r(c[l],s),l++)}else p?.type.name==="Body"&&r(p,s),l++}return}if(i==="ForStatement"||i==="WhileStatement"){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}if((i==="ConditionalExpression"||i==="and"||i==="or")&&(e+=1),s>0&&(i==="FunctionDefinition"||i==="LambdaExpression")){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}let a=n.firstChild;for(;a;)r(a,s),a=a.nextSibling}return r(t,0),e}function Nt(t){return{complexity:ya(t),cognitiveComplexity:xa(t)}}function sn(t,e){let r=[];function n(o,a){let{complexity:c,cognitiveComplexity:l}=Nt(o);r.push({name:a,line:ae(e,o.from),complexity:c,cognitiveComplexity:l})}function s(o){let a=o.firstChild;for(;a;)i(a),a=a.nextSibling}function i(o){if(o.type.name==="ClassDefinition"){let a=o.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=o.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let g=p.getChild("VariableName"),d=g?e.slice(g.from,g.to):void 0;d&&n(p,c?`${c}.${d}`:d),s(p)}else i(p);p=p.nextSibling}}return}if(o.type.name==="FunctionDefinition"){let a=o.getChild("VariableName");a&&n(o,e.slice(a.from,a.to)),s(o);return}s(o)}return i(t.topNode),r}var ka=new Set(["pytest","unittest","nose","hypothesis"]);function on(t,e){let r=[],n=[],s=new Set,i=Sa.basename(t).toLowerCase(),o=ba.parse(e),a=o.cursor();do switch(a.name){case"Comment":{let h=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);h?.[1]&&s.add(h[1]);break}case"ImportStatement":{for(let h of va(a.node,e,t))r.push(h);break}case"FunctionDefinition":case"ClassDefinition":{let h=a.node.parent;if(h?.name==="Script"||h?.name==="DecoratedStatement"&&h.parent?.name==="Script"){let x=a.node.getChild("VariableName");x&&n.push({name:e.slice(x.from,x.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let h=a.node.firstChild;h?.name==="VariableName"&&n.push({name:e.slice(h.from,h.to)})}break}}while(a.next());let c=Na(i,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=Nt(o.topNode),g=sn(o,e),d=c==="test"?[]:Ta(o,e);return{imports:r,exports:n,tags:Array.from(s).map(h=>({name:h,kind:"comment-marker"})),category:c,rawCallEdges:d,complexity:l,cognitiveComplexity:p,...g.length>0?{functions:g}:{}}}function va(t,e,r){let n=t.firstChild;return n?n.name==="from"?Ca(t,e,r):Ea(t,e,r):[]}function Ca(t,e,r){let n=t.firstChild;if(!n)return[];let s=n.nextSibling;for(;s&&s.name!=="import";)s=s.nextSibling;if(!s)return[];let i=e.slice(n.to,s.from).trim(),o=wa(s.nextSibling,e);if(!o.length)return[];let a=0;for(;a<i.length&&i[a]===".";)a++;let c=i.slice(a);if(a===0)return[ce(r,i,o,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[ce(r,l+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[ce(r,l.slice(0,-1),["*"],!1)]:o.map(p=>ce(r,l+p,[p],!1))}function Ea(t,e,r){let n=[],s=t.firstChild?.nextSibling??null;for(;s;){if(s.name==="VariableName"){let i=e.slice(s.from,s.to);for(;s.nextSibling?.name==="."&&s.nextSibling.nextSibling?.name==="VariableName";)s=s.nextSibling.nextSibling,i+=`.${e.slice(s.from,s.to)}`;s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling),n.push(ce(r,i,["*"],!0))}s=s.nextSibling}return n}function wa(t,e){let r=[],n=t;for(;n;)n.name==="*"?r.push("*"):n.name==="VariableName"&&(r.push(e.slice(n.from,n.to)),n.nextSibling?.name==="as"&&(n=n.nextSibling.nextSibling??n.nextSibling)),n=n.nextSibling;return r}function Fa(t,e){let r=new Map,n=t.cursor();do{if(n.name!=="ImportStatement")continue;let i=n.node.firstChild;if(i?.type.name!=="from")continue;let o=i.nextSibling;for(;o&&o.type.name!=="import";)o=o.nextSibling;if(!o)continue;let a=e.slice(i.to,o.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),g=o.nextSibling;for(;g;){if(g.type.name==="VariableName"){let d=e.slice(g.from,g.to),h=d;if(g.nextSibling?.type.name==="as"){let x=g.nextSibling.nextSibling;x?.type.name==="VariableName"&&(h=e.slice(x.from,x.to),g=x)}let S=c===0?a:l?p+l.replace(/\./g,"/"):p+d;r.set(h,S)}g=g.nextSibling}}while(n.next());return r}function Ta(t,e){let r=Fa(t,e),n=[];function s(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,g=e.slice(p.from,p.to),d=r.get(g);d&&n.push({from:c,to:g,toSpecifier:d})}let l=a.firstChild;for(;l;)s(l,c),l=l.nextSibling}function i(a){let c=a.firstChild;for(;c;)o(c),c=c.nextSibling}function o(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let g=p.firstChild;for(;g;){if(g.type.name==="FunctionDefinition"){let d=g.getChild("VariableName"),h=d?e.slice(d.from,d.to):void 0;h&&s(g,l?`${l}.${h}`:h)}else o(g);g=g.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&s(a,e.slice(c.from,c.to));return}i(a)}return o(t.topNode),n}function ce(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function Na(t,e,r){return t.startsWith("test_")||t.endsWith("_test.py")?"test":t==="conftest.py"||t==="setup.py"?"config":r.has("test")||e.some(n=>ka.has(n.rawSpecifier))?"test":"logic"}import cn from"path";import f from"typescript";import v from"typescript";function Pa(t){let e=1;function r(n){switch(n.kind){case v.SyntaxKind.IfStatement:case v.SyntaxKind.ConditionalExpression:case v.SyntaxKind.ForStatement:case v.SyntaxKind.ForInStatement:case v.SyntaxKind.ForOfStatement:case v.SyntaxKind.WhileStatement:case v.SyntaxKind.DoStatement:case v.SyntaxKind.CatchClause:case v.SyntaxKind.CaseClause:e++;break;case v.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===v.SyntaxKind.AmpersandAmpersandToken||s===v.SyntaxKind.BarBarToken||s===v.SyntaxKind.QuestionQuestionToken)&&e++;break}}v.forEachChild(n,r)}return r(t),e}function Ia(t){let e=0;function r(n,s,i){if(v.isIfStatement(n)){e+=i?1:1+s;let a=i?s:s+1;r(n.expression,a,!1),r(n.thenStatement,a,!1),n.elseStatement&&(v.isIfStatement(n.elseStatement)?r(n.elseStatement,s,!0):(e+=1,r(n.elseStatement,s+1,!1)));return}if(v.isForStatement(n)||v.isForInStatement(n)||v.isForOfStatement(n)||v.isWhileStatement(n)||v.isDoStatement(n)||v.isSwitchStatement(n)){e+=1+s,v.forEachChild(n,a=>r(a,s+1,!1));return}if(v.isCatchClause(n)){e+=1+s,v.forEachChild(n,a=>r(a,s,!1));return}if(v.isConditionalExpression(n)&&(e+=1),v.isBinaryExpression(n)){let a=n.operatorToken.kind;(a===v.SyntaxKind.AmpersandAmpersandToken||a===v.SyntaxKind.BarBarToken||a===v.SyntaxKind.QuestionQuestionToken)&&(e+=1)}if(s>0&&(v.isFunctionDeclaration(n)||v.isFunctionExpression(n)||v.isArrowFunction(n))){e+=1+s,v.forEachChild(n,a=>r(a,s+1,!1));return}v.forEachChild(n,a=>r(a,s,!1))}return r(t,0,!1),e}function Pt(t){return{complexity:Pa(t),cognitiveComplexity:Ia(t)}}import E from"typescript";var It=new Set(["test","describe","it"]);function an(t,e){Ma(t,e),Ra(t,e),Aa(t,e),La(t,e)}function Ma(t,e){if((E.isFunctionDeclaration(t)||E.isVariableDeclaration(t))&&t.name&&E.isIdentifier(t.name)&&Da(t)){let r;if(E.isFunctionDeclaration(t))r="function";else{let n=t.initializer;r=n&&(E.isArrowFunction(n)||E.isFunctionExpression(n))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Da(t){if(E.isFunctionDeclaration(t))return E.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&E.isSourceFile(e.parent)}function Ra(t,e){if(!E.isStringLiteral(t))return;let r=t.text.match(/@[\w-]+/g);if(r)for(let n of r)e.tags.add({name:n.substring(1),kind:"comment-marker"})}function Aa(t,e){if(!E.isSourceFile(t))return;let r=/@tag\s+([a-zA-Z0-9_-]+)/g,n=t.getFullText(),s=r.exec(n);for(;s!==null;)s[1]&&e.tags.add({name:s[1],kind:"comment-marker"}),s=r.exec(n)}function La(t,e){if(E.isCallExpression(t)&&Oa(t.expression))for(let r of t.arguments)E.isObjectLiteralExpression(r)&&Ga(r,e)}function Oa(t){return E.isIdentifier(t)?It.has(t.text):!!(E.isPropertyAccessExpression(t)&&(It.has(t.name.text)||E.isIdentifier(t.expression)&&It.has(t.expression.text)))}function Ga(t,e){for(let r of t.properties){if(!E.isPropertyAssignment(r)||!E.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:n}=r,s=E.isArrayLiteralExpression(n)?n.elements.filter(E.isStringLiteral):r.name.text==="tag"&&E.isStringLiteral(n)?[n]:[];for(let i of s)e.tags.add({name:i.text.replace(/^@/,""),kind:"comment-marker"})}}function Mt(t,e,r){let n=[],s=new Map,i=new Set,o=f.createSourceFile(t,e,f.ScriptTarget.Latest,!0,r==="typescript"?f.ScriptKind.TSX:f.ScriptKind.JSX),a={filePath:t,imports:n,exports:s,tags:i,rawCallEdges:[],sourceFile:o,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=x=>{za(x,a),f.forEachChild(x,c)};c(o);let l=Za(t,a);(l==="test"||l==="barrel")&&i.add({name:l,kind:"comment-marker"}),l!=="test"&&qa(a,o);let p=o.statements[0],g=p?pn(p):void 0,{complexity:d,cognitiveComplexity:h}=Pt(o),S=_a(o);return{imports:n,exports:Array.from(s.values()),tags:Array.from(i),category:l,rawCallEdges:a.rawCallEdges??[],complexity:d,cognitiveComplexity:h,...S.length>0?{functions:S}:{},...g!==void 0?{description:g}:{}}}function _a(t){let e=[],r=(s,i)=>{let{complexity:o,cognitiveComplexity:a}=Pt(i),c=t.getLineAndCharacterOfPosition(i.getStart(t)).line+1;e.push({name:s,line:c,complexity:o,cognitiveComplexity:a})},n=(s,i)=>{if(f.isFunctionDeclaration(s)&&s.name&&s.body?r(s.name.text,s):f.isVariableDeclaration(s)&&f.isIdentifier(s.name)&&s.initializer&&(f.isArrowFunction(s.initializer)||f.isFunctionExpression(s.initializer))?r(s.name.text,s.initializer):i&&f.isMethodDeclaration(s)&&f.isIdentifier(s.name)&&s.body?r(`${i}.${s.name.text}`,s):i&&f.isConstructorDeclaration(s)&&s.body?r(`${i}.constructor`,s):i&&f.isGetAccessorDeclaration(s)&&f.isIdentifier(s.name)&&s.body?r(`${i}.get ${s.name.text}`,s):i&&f.isSetAccessorDeclaration(s)&&f.isIdentifier(s.name)&&s.body&&r(`${i}.set ${s.name.text}`,s),f.isClassDeclaration(s)&&s.name){let o=s.name.text;f.forEachChild(s,a=>n(a,o));return}f.forEachChild(s,o=>n(o,i))};return n(t,void 0),e}function ln(t,e,r,n){let s={name:t},i=pn(r);i!==void 0&&(s.doc=i);let o=ja(e);o!==void 0&&(s.flags=o);let a=Wa(e,n);return a!==void 0&&(s.signature=a),s}function pn(t){let e=f.getJSDocCommentsAndTags(t);for(let r of e)if(f.isJSDoc(r)&&r.comment)return f.getTextOfJSDocComment(r.comment)||void 0}function ja(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=f.getJSDocTags(t).map(n=>n.tagName.text).filter(n=>e.has(n));return r.length>0?r:void 0}function Wa(t,e){let r=f.createPrinter({removeComments:!0}),n=s=>r.printNode(f.EmitHint.Unspecified,s,e);if(f.isFunctionDeclaration(t)||f.isMethodDeclaration(t)){let s=t.parameters.map(n).join(", "),i=t.type?n(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${s}) => ${i}`}if(f.isVariableDeclaration(t)){if(t.type)return n(t.type);if(t.initializer&&(f.isArrowFunction(t.initializer)||f.isFunctionExpression(t.initializer))){let s=t.initializer,i=s.parameters.map(n).join(", "),o=s.type?n(s.type):"unknown";return`(${i}) => ${o}`}return}if(f.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(f.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(f.isTypeAliasDeclaration(t))return n(t.type);if(f.isEnumDeclaration(t))return`enum ${t.name.text}`}function za(t,e){$a(t,e),Ba(t,e),Ka(t,e),Va(t,e),Xa(t,e),an(t,e)}function $a(t,e){if(!f.isSourceFile(t))return;let r=t.statements.filter(n=>!f.isEmptyStatement(n));e.totalStatements=r.length,e.exportStatements=r.filter(n=>f.isExportDeclaration(n)||f.isExportAssignment(n)||Dt(n)).length}function Ba(t,e){if(f.isJsxElement(t)||f.isJsxSelfClosingElement(t)||f.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(f.isFunctionDeclaration(t)||f.isMethodDeclaration(t)||f.isArrowFunction(t)||f.isClassDeclaration(t)||f.isVariableStatement(t)||f.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}f.isExportDeclaration(t)&&!Ua(t)&&(e.hasTypesOnly=!1)}function Ua(t){return t.isTypeOnly?!0:!t.exportClause||!f.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function Ka(t,e){if(!f.isImportDeclaration(t)||!t.moduleSpecifier||!f.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(f.isNamedImports(t.importClause.namedBindings))for(let s of t.importClause.namedBindings.elements)r.push(s.name.text);else f.isNamespaceImport(t.importClause.namedBindings)&&r.push("*");let n=r.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.moduleSpecifier.text,isStyle:M(t.moduleSpecifier.text),type:n,symbols:r.length>0?r:void 0})}function Va(t,e){f.isExportDeclaration(t)?Ja(t,e):f.isExportAssignment(t)?e.exports.set("default",{name:"default"}):Dt(t)&&Ya(t,e)}function Ja(t,e){if(t.moduleSpecifier&&f.isStringLiteral(t.moduleSpecifier))Ha(t,t.moduleSpecifier.text,e);else if(t.exportClause&&f.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let n=r.name.text;e.exports.set(n,{name:n})}}function Ha(t,e,r){let n=Qa(t),s={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:M(e),type:"re-export"};n.length>0&&(s.symbols=n),r.imports.push(s)}function Qa(t){return t.exportClause?f.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function Ya(t,e){if((f.isFunctionDeclaration(t)||f.isClassDeclaration(t)||f.isInterfaceDeclaration(t)||f.isTypeAliasDeclaration(t)||f.isEnumDeclaration(t))&&t.name){let n=t.name.text;e.exports.set(n,ln(n,t,t,e.sourceFile));return}if(f.isVariableStatement(t)){for(let n of t.declarationList.declarations)if(f.isIdentifier(n.name)){let s=n.name.text;e.exports.set(s,ln(s,n,t,e.sourceFile))}}}function Xa(t,e){if(!f.isCallExpression(t))return;let r=t.arguments[0];!r||!f.isStringLiteral(r)||(t.expression.kind===f.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:M(r.text),type:"dynamic"}):f.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:M(r.text),type:"require"}))}function Za(t,e){let r=cn.basename(t).toLowerCase(),n=cn.extname(t).toLowerCase();return Z().some(i=>r.includes(i))?"test":_t(r)?"config":e.imports.some(i=>Je().some(o=>i.rawSpecifier.includes(o)))?"test":n===".tsx"||n===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>Qe()?"barrel":"logic"}function Dt(t){return f.canHaveModifiers(t)&&f.getModifiers(t)?.some(e=>e.kind===f.SyntaxKind.ExportKeyword)===!0}function qa(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let n=new Map;for(let s of e.statements){if(!f.isImportDeclaration(s)||!f.isStringLiteral(s.moduleSpecifier))continue;let i=s.moduleSpecifier.text,o=s.importClause;if(o&&(o.name&&n.set(o.name.text,i),o.namedBindings&&f.isNamedImports(o.namedBindings)))for(let a of o.namedBindings.elements)n.set(a.name.text,i)}if(n.size!==0)for(let s of e.statements){let i=tc(s);if(i){let o=rc(s);o&&ze(o,i,n,r);continue}f.isClassDeclaration(s)&&s.name&&ec(s,s.name.text,n,r)}}function ec(t,e,r,n){for(let s of t.members)f.isMethodDeclaration(s)&&s.body&&f.isIdentifier(s.name)?ze(s.body,`${e}.${s.name.text}`,r,n):f.isConstructorDeclaration(s)&&s.body&&ze(s.body,`${e}.constructor`,r,n)}function tc(t){if(Dt(t)){if(f.isFunctionDeclaration(t)&&t.name)return t.name.text;if(f.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(f.isIdentifier(e.name)&&e.initializer&&(f.isArrowFunction(e.initializer)||f.isFunctionExpression(e.initializer)))return e.name.text}}}function rc(t){if(f.isFunctionDeclaration(t))return t.body;if(f.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(f.isArrowFunction(e.initializer)||f.isFunctionExpression(e.initializer)))return e.initializer}}function ze(t,e,r,n){if(f.isCallExpression(t)&&f.isIdentifier(t.expression)){let s=t.expression.text,i=r.get(s);i&&!n.some(o=>o.from===e&&o.to===s&&o.toSpecifier===i)&&n.push({from:e,to:s,toSpecifier:i})}f.forEachChild(t,s=>ze(s,e,r,n))}function $e(t,e){if(e.length===0)return"ui";let r=!1;return t.walk(n=>{if(n.type==="rule")return r=!0,!1}),r?"ui":"barrel"}function fn(t,e){let r=[],n=/@require\s+['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let o=s[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"require"}),s=n.exec(t)}let i=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(s=i.exec(t);s!==null;){let o=s[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=i.exec(t)}return r}function un(t,e){if(e.length===0)return"ui";try{let r=Ve("stylus");return new r.Parser(t).parse().nodes.some(i=>i.constructor.name!=="Import")?"ui":"barrel"}catch{return t.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function le(t,e){let r=A(t);if(r==="stylus"){let i=fn(e,t);return{imports:i,exports:[],tags:[],category:un(e,i)}}if(r==="scss"){let{imports:i,root:o,exports:a,tags:c}=we(e,t);return{imports:i,exports:a,tags:c,category:$e(o,i)}}if(r==="less"){let{imports:i,root:o,exports:a,tags:c}=Ee(e,t);return{imports:i,exports:a,tags:c,category:$e(o,i)}}let{imports:n,root:s}=Ce(e,t);return{imports:n,exports:[],tags:[],category:$e(s,n)}}for(let[t,e]of[["javascript",(r,n)=>Mt(r,n,"javascript")],["typescript",(r,n)=>Mt(r,n,"typescript")],["css",le],["scss",le],["less",le],["stylus",le],["coffeescript",Qr],["livescript",qr],["lua",en],["python",on],["go",Zr],["gherkin",wt],["markdown",nn]])J(t,e);async function mn(t,e){let r=A(t),n=Nr(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}import gn from"path";function hn(t,e){for(let r of t.values()){let n=e.get(r.path);n!==void 0&&(r.coveragePct=n)}}function yn(t,e){for(let r of t)if(r.isExternal){let n=r.rawSpecifier.startsWith("@")?r.rawSpecifier.split("/").slice(0,2).join("/"):r.rawSpecifier.split("/")[0];n&&!e.some(s=>s.name===n)&&e.push({name:n,kind:"library"})}}function xn(t){for(let e of t.values())if(e.category==="test")for(let r of e.imports){if(r.isExternal||!r.toPath)continue;let n=t.get(r.toPath);n&&(n.category!=="logic"&&n.category!=="barrel"||(n.testedBy??=[],n.testedBy.includes(e.path)||n.testedBy.push(e.path)))}}function Sn(t){for(let e of t.values())if(e.type==="markdown")for(let r of e.imports){if(r.isExternal||!r.toPath)continue;let n=t.get(r.toPath);!n||n===e||(n.documentedBy??=[],n.documentedBy.includes(e.path)||n.documentedBy.push(e.path),n.category==="logic"&&(n.lastCommitAt??0)>(e.lastCommitAt??0)&&(e.staleFor??=[],e.staleFor.includes(n.path)||e.staleFor.push(n.path)))}}function dn(t){return Math.round(t*1e4)/1e4}function bn(t){for(let e of t.values()){let r=[];for(let n of e.imports){if(n.isExternal||!n.toPath)continue;let s=t.get(n.toPath);if(!s||s.exports.length===0)continue;let i;if(n.symbols===void 0){if(n.type==="side-effect")continue;i=1}else n.symbols.includes("*")?i=1:i=n.symbols.length/s.exports.length;n.exportUsageRatio=dn(Math.min(1,i)),r.push(n.exportUsageRatio)}r.length>0&&(e.avgExportUsage=dn(r.reduce((n,s)=>n+s,0)/r.length),e.maxExportUsage=Math.max(...r))}}function Rt(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function nc(t,e){let r=e.toPath,n=gn.basename(r,gn.extname(r)).replace(/\.(test|spec)$/,"");Rt(t.tags,n,"import")}function sc(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)Rt(t.tags,r,"import")}function ic(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&Rt(t.tags,s.name,"comment-marker")}function kn(t){for(let e of t.values())if(e.category==="test")for(let r of e.imports)!r.toPath||r.isExternal||(nc(e,r),sc(e,r),ic(e,r,t))}import Be from"fs";import O from"path";import En from"fs";import Y from"path";var pe=class{extensions=[".go"];goModCache=new Map;resolve(e,r,n,s){let{mod:i,replaces:o}=this.readGoMod(n);if(!i)return null;let a=this.applyReplace(r,o,n);if(a!==void 0)return Cn(a);if(r!==i&&!r.startsWith(`${i}/`))return null;let c=r.slice(i.length).replace(/^\//,"");return c?Cn(Y.join(n,c)):null}readGoMod(e){let r=this.goModCache.get(e);if(r!==void 0)return r;let n={mod:null,replaces:new Map};try{let s=En.readFileSync(Y.join(e,"go.mod"),"utf-8"),i=oc(s,e);return this.goModCache.set(e,i),i}catch{return this.goModCache.set(e,n),n}}applyReplace(e,r,n){for(let[s,i]of r){if(e===s)return i;if(e.startsWith(`${s}/`)){let o=e.slice(s.length+1);return Y.join(i,o)}}}};function oc(t,e){let r=t.split(`
27
+ `),n=null,s=new Map,i=!1;for(let o of r){let a=o.trim();if(a.startsWith("module ")){n=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){i=!0;continue}if(i&&a===")"){i=!1;continue}if(i&&a.includes("=>")){vn(a,e,s);continue}!i&&/^replace\s+/.test(a)&&a.includes("=>")&&vn(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function vn(t,e,r){let[n,s]=t.split("=>").map(a=>a.trim());if(!n||!s)return;let i=n.split(/\s+/)[0];if(!s.startsWith(".")&&!s.startsWith("/"))return;let o=Y.isAbsolute(s)?s:Y.resolve(e,s);r.set(i,o)}function Cn(t){let e;try{e=En.readdirSync(t,{withFileTypes:!0})}catch{return null}let r=e.filter(n=>n.isFile()&&n.name.endsWith(".go")&&!n.name.endsWith("_test.go")).map(n=>({path:Y.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}import ac from"fs";import At from"path";var fe=class{extensions=[".lua"];resolve(e,r,n,s){let i=r.replace(/\./g,At.sep),o=[n,At.join(n,"lib")];for(let a of o){if(!ac.existsSync(a))continue;let c=s(At.join(a,"_dummy.lua"),i);if(c)return[c]}return null}};import cc from"path";var ue=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let i=s(cc.join(n,"_dummy"),`./${r}`);return i?[i]:null}};import lc from"fs";import Lt from"path";var me=class{extensions=[".py"];resolve(e,r,n,s){let i=r.replace(/\./g,Lt.sep),o=Lt.join(n,`${i}.py`);if(wn(o))return[{path:o,isExternal:!1}];let a=Lt.join(n,i,"__init__.py");return wn(a)?[{path:a,isExternal:!1}]:null}};function wn(t){try{return lc.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import Fn from"path";var pc=["~","http://","https://","//","data:","sass:"],ge=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,r,n,s){if(pc.some(p=>r.startsWith(p)))return null;let i=s(e,r);if(i)return[i];let o=Fn.dirname(r),a=Fn.basename(r),c=o==="."?`_${a}`:`${o}/_${a}`,l=s(e,c);return l?[l]:null}};var B=class{constructor(e,r={}){this.rootDir=e;this.workspaceMap=r.workspaceMap??new Map,this.tsconfigSearchPaths=r.tsconfigSearchPaths??[e],this.pathAliases=r.pathAliases,this.langResolvers=r.langResolvers??[new me,new fe,new pe,new ge,new ue]}rootDir;workspaceMap;tsconfigSearchPaths;pathAliases;langResolvers;resolveAll(e,r){let n=this.resolvePathAlias(r);if(n)return[n];if(r.startsWith(".")||r.startsWith("/")){let o=this.resolveLocalPath(e,r);return o?[o]:[]}let s=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>e.endsWith(a))){let a=o.resolve(e,r,this.rootDir,s);if(a)return a}let i=this.resolveWorkspaceImport(r);return i?[i]:[{path:r,isExternal:!0}]}resolve(e,r){let n=this.resolvePathAlias(r);if(n)return n;if(r.startsWith(".")||r.startsWith("/"))return this.resolveLocalPath(e,r);let s=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>e.endsWith(a))){let a=o.resolve(e,r,this.rootDir,s);if(a)return a[0]??null}let i=this.resolveWorkspaceImport(r);return i||{path:r,isExternal:!0}}resolveLocalPath(e,r){let n=O.dirname(e),s=r.startsWith("/")?r:O.resolve(n,r),i=!s.startsWith(this.rootDir),o=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature",".md",".mdx"],a=s.match(/\.(js|mjs|cjs)$/);if(a){let c=s.slice(0,-a[0].length);for(let l of[".ts",".tsx"]){let p=this.tryExtensions(c,l,i);if(p)return p}}for(let c of o){let l=this.tryExtensions(s,c,i);if(l)return l}return i?{path:s,isExternal:!0}:null}tryExtensions(e,r,n){let s=e+r;if(this.isFile(s))return{path:s,isExternal:n};let i=O.join(e,`index${r}`);if(this.isFile(i))return{path:i,isExternal:n};if(r===".py"){let o=O.join(e,"__init__.py");if(this.isFile(o))return{path:o,isExternal:n}}return null}isFile(e){try{return Be.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(e){if(this.pathAliases)for(let r in this.pathAliases){let n=this.matchAliasPattern(r,e),s=this.pathAliases[r];if(n&&s){let i=this.tryAliasSubstitutions(s,n[1]||"");if(i)return i}}for(let r of this.tsconfigSearchPaths){let n=O.join(r,"tsconfig.json");if(Be.existsSync(n))try{let i=JSON.parse(Be.readFileSync(n,"utf-8")).compilerOptions?.paths;if(!i)continue;for(let o in i){let a=this.matchAliasPattern(o,e);if(a){let c=this.tryAliasSubstitutions(i[o],a[1]||"",r);if(c)return c}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(e,r){let n=this.aliasRegexCache.get(e);if(!n){let s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");n=new RegExp(`^${s}$`),this.aliasRegexCache.set(e,n)}return r.match(n)}tryAliasSubstitutions(e,r,n=this.rootDir){let s=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let i of e){let o=i.replace("*",r),a=O.resolve(n,o);for(let c of s){let l=this.tryExtensions(a,c,!1);if(l)return l}}return null}resolveWorkspaceImport(e){if(this.workspaceMap.size===0)return null;for(let[r,n]of this.workspaceMap){if(e!==r&&!e.startsWith(`${r}/`))continue;let s=e.slice(r.length),i={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:r};if(!s){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let c=O.join(n,a);try{if(Be.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...i,path:c}}catch{}}return{...i,path:n}}let o=this.resolveLocalPath(O.join(n,"_dummy"),s.slice(1));return o?{...i,path:o.path}:null}return null}};var uc=["tests","test","__tests__","specs","spec"],Tn=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),mc=20;function gc(t,e){if(t.length===0)return e;let r=t.map(o=>N.dirname(o).split(N.sep)),n=r[0]??[];for(let o of r.slice(1)){let a=0;for(;a<n.length&&a<o.length&&n[a]===o[a];)a++;n=n.slice(0,a)}let s=n.join(N.sep)||N.sep,i=N.relative(e,s);return i.startsWith("..")||N.isAbsolute(i)?e:s}var he=class{constructor(e,r=null,n,s,i=!1,o=new Map,a=!0){this.rootDir=e;this.enableGitStats=i;this.coverageMap=o;this.parallelParsing=a;this.previousGraph=r,this.resolver=n||new B(e),this.lockFile=Zt(e),s&&(this.progressCallback=s)}rootDir;enableGitStats;coverageMap;parallelParsing;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;async build(e){let r=e.map(n=>N.isAbsolute(n)?n:N.resolve(this.rootDir,n));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=Kr(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(gc(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
26
28
  Done. Total processed: ${this.visited.size} nodes.
27
- `),Sn(this.graph.nodes),hn(this.graph.nodes),xn(this.graph.nodes),yn(this.graph.nodes),this.coverageMap.size>0&&gn(this.graph.nodes,this.coverageMap),new G(this.graph.nodes)}finally{this.pool&&(await this.pool.destroy(),this.pool=null)}}async initPool(){if(this.parallelParsing===!1)return;let e=typeof this.parallelParsing=="object"?this.parallelParsing:{},r=e.minFiles??ac;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r)))try{let n=F.join(m,"parse-worker.js");this.pool=new ic({filename:n,...e.maxThreads!==void 0?{maxThreads:e.maxThreads}:{}})}catch(n){process.stderr.write(`
29
+ `),kn(this.graph.nodes),xn(this.graph.nodes),bn(this.graph.nodes),Sn(this.graph.nodes),this.coverageMap.size>0&&hn(this.graph.nodes,this.coverageMap),new G(this.graph.nodes)}finally{this.pool&&(await this.pool.destroy(),this.pool=null)}}async initPool(){if(this.parallelParsing===!1)return;let e=typeof this.parallelParsing=="object"?this.parallelParsing:{},r=e.minFiles??mc;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r)))try{let n=N.join(u,"parse-worker.js");this.pool=new fc({filename:n,...e.maxThreads!==void 0?{maxThreads:e.maxThreads}:{}})}catch(n){process.stderr.write(`
28
30
  Warning: failed to start parse worker pool, falling back to synchronous parsing: ${n}
29
- `),this.pool=null}}hasAtLeastFiles(e,r){let n=0,s=[e];for(;s.length>0;){let i=s.pop();if(i===void 0)continue;let o;try{o=ue.readdirSync(i,{withFileTypes:!0})}catch{continue}for(let a of o)if(a.isDirectory())wn.has(a.name)||s.push(F.join(i,a.name));else if(a.isFile()&&(n++,n>=r))return!0}return n>=r}async processTestFiles(e){let r=Y(),n=i=>r.some(o=>i.name.includes(o));this.walkProject(e,n);let s=e;for(;s!==this.rootDir;){let i=F.dirname(s);if(i===s)break;for(let o of oc){let a=F.join(i,o);try{ue.statSync(a).isDirectory()&&this.walkProject(a,n)}catch{}}s=i}await this.drain()}async processDocFiles(){this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,r){let n;try{n=ue.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let i=F.join(e,s.name);s.isDirectory()?wn.has(s.name)||this.walkProject(i,r):s.isFile()&&r(s)&&this.enqueue(i)}}enqueue(e){this.visited.has(e)||(this.visited.add(e),this.showProgress(),this.queue.push(e))}async drain(){for(;this.queue.length>0;){let e=this.queue;this.queue=[],await Promise.all(e.map(r=>this.finishFile(r)))}}async finishFile(e){let r=ue.statSync(e,{throwIfNoEntry:!1});if(!r?.isFile())return;let n=F.relative(this.rootDir,e),s=await this.getNode(e,n,r);s.imports=await this.resolveImports(e,s.imports),dn(s.imports,s.tags),this.graph.nodes.set(s.path,s)}async getNode(e,r,n){let s=this.previousGraph?.nodes.get(r);if(s&&s.mtime===n.mtimeMs&&s.size===n.size)return{...s};let i=await this.tryParse(e,r);if(!i)return this.makeStubNode(e,r,n);let o=this.resolveCallEdges(e,i.rawCallEdges),a=this.buildNode(e,r,n,i,o);return this.attachGitStats(a,r),a}async tryParse(e,r){let n=ue.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
31
+ `),this.pool=null}}hasAtLeastFiles(e,r){let n=0,s=[e];for(;s.length>0;){let i=s.pop();if(i===void 0)continue;let o;try{o=de.readdirSync(i,{withFileTypes:!0})}catch{continue}for(let a of o)if(a.isDirectory())Tn.has(a.name)||s.push(N.join(i,a.name));else if(a.isFile()&&(n++,n>=r))return!0}return n>=r}async processTestFiles(e){let r=Z(),n=i=>r.some(o=>i.name.includes(o));this.walkProject(e,n);let s=e;for(;s!==this.rootDir;){let i=N.dirname(s);if(i===s)break;for(let o of uc){let a=N.join(i,o);try{de.statSync(a).isDirectory()&&this.walkProject(a,n)}catch{}}s=i}await this.drain()}async processDocFiles(){this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,r){let n;try{n=de.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let i=N.join(e,s.name);s.isDirectory()?Tn.has(s.name)||this.walkProject(i,r):s.isFile()&&r(s)&&this.enqueue(i)}}enqueue(e){this.visited.has(e)||(this.visited.add(e),this.showProgress(),this.queue.push(e))}async drain(){for(;this.queue.length>0;){let e=this.queue;this.queue=[],await Promise.all(e.map(r=>this.finishFile(r)))}}async finishFile(e){let r=de.statSync(e,{throwIfNoEntry:!1});if(!r?.isFile())return;let n=N.relative(this.rootDir,e),s=await this.getNode(e,n,r);s.imports=await this.resolveImports(e,s.imports),yn(s.imports,s.tags),this.graph.nodes.set(s.path,s)}async getNode(e,r,n){let s=this.previousGraph?.nodes.get(r);if(s&&s.mtime===n.mtimeMs&&s.size===n.size)return{...s};let i=await this.tryParse(e,r);if(!i)return this.makeStubNode(e,r,n);let o=this.resolveCallEdges(e,i.rawCallEdges),a=this.buildNode(e,r,n,i,o);return this.attachGitStats(a,r),a}async tryParse(e,r){let n=de.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
30
32
  Warning: failed to parse ${r}: ${s}
31
- `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):fn(e,r)}makeStubNode(e,r,n){return{path:r,type:R(e),category:"other",imports:[],exports:[],tags:[],mtime:n.mtimeMs,size:n.size}}resolveCallEdges(e,r){let n=[];for(let s of r??[])try{let i=this.resolver.resolve(e,s.toSpecifier);i&&!i.isExternal&&n.push({from:s.from,to:s.to,toFile:F.relative(this.rootDir,i.path)})}catch{}return n}buildNode(e,r,n,s,i){let{imports:o,exports:a,tags:c,category:l,description:p,complexity:g,cognitiveComplexity:d,functions:h}=s;return{path:r,type:R(e),category:l,imports:o,exports:a,tags:c,mtime:n.mtimeMs,size:n.size,...p!==void 0?{description:p}:{},...i.length>0?{callEdges:i}:{},...g!==void 0?{complexity:g}:{},...d!==void 0?{cognitiveComplexity:d}:{},...h!==void 0?{functions:h}:{}}}attachGitStats(e,r){let n=this.gitStatsMap?.get(r);n&&(e.commitCount90d=n.commitCount90d,n.lastAuthor!==void 0&&(e.lastAuthor=n.lastAuthor),n.lastCommitAt!==void 0&&(e.lastCommitAt=n.lastCommitAt))}async resolveImports(e,r){let n=[];for(let s of r){let i=this.resolver.resolveAll(e,s.rawSpecifier);if(i.length!==0)for(let o of i){let a={...s,toPath:o.isExternal?o.path:F.relative(this.rootDir,o.path),isExternal:o.isExternal};o.isWorkspace&&(a.isWorkspace=!0,a.workspacePackage=o.workspacePackage),o.isExternal?this.attachLockfileVersion(a):this.enqueue(o.path),n.push(a)}}return n}attachLockfileVersion(e){if(!this.lockFile)return;let r=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],n=r?this.lockFile.dependencies[r]:void 0;n&&(e.version=n.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function Fn(t,e){return{identifier:e?.identifier??new Oe,featureMap:e?.featureDetection===!1?new Map:q(t.nodes,e?.featureDetection??void 0)}}function Tn(t,e,r,n,s){for(let i of e){let o=t.nodes.get(i);if(!o)continue;let a=new _(i,["*",...o.exports.map(c=>c.name)]);t.traverse(i,(c,l,p)=>{if(!p)return!0;if(!a.updateAffectedSymbols(c,p))return!1;if(l>0){let g=r.get(c.path);if(g)return n(g),!1}return s(c),!0},{direction:"incoming"})}}function lc(t,e,r){let{identifier:n,featureMap:s}=Fn(t,r),i=new Set;for(let o of e){let a=s.get(o);a&&i.add(a.tag)}return Tn(t,e,s,o=>i.add(o.tag),o=>{if(n.isTestNode(o))for(let a of o.tags)i.add(a.name)}),Array.from(i)}function pc(t,e,r){let{identifier:n,featureMap:s}=Fn(t,r),i=new Set;return Tn(t,e,s,()=>{},o=>{n.isTestNode(o)&&i.add(o.path)}),Array.from(i)}import fc from"fs";import de from"path";async function gd(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},i=de.resolve(t);return await new ge(i,r,n.pathAliases?new B(i,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0).build(e)}async function dd(t,e={}){let r=de.resolve(t),n=ct(r),s=e.packages?n.packages.filter(a=>e.packages?.includes(a.name)||e.packages?.includes(a.relativeRoot)):n.packages,i=new Map(n.packages.map(a=>[a.name,a.root])),o=new ne(r,n.type);for(let a of s){let c=e.silent?void 0:g=>{process.stderr.write(`[${a.name}] Processed ${g} files...\r`)},p=await new ge(r,null,new B(r,{workspaceMap:i,tsconfigSearchPaths:[a.root,r],pathAliases:e.pathAliases}),c,e.gitStats??!1,new Map,e.parallelParsing??!0).build(a.entryPoints);o.addPackage(a,p)}return o}function hd(t,e={}){let r=[],n=new Set([...e.ignoreDirs??X,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??Qe,...e.additionalExtensions??[]]);function i(o){try{let a=fc.readdirSync(o,{withFileTypes:!0});for(let c of a){let l=de.join(o,c.name);c.isDirectory()?n.has(c.name)||i(l):c.isFile()&&s.has(de.extname(c.name).toLowerCase())&&r.push(de.relative(t,l))}}catch{}}return i(t),r}export{we as CALL_EDGE_TYPES,Qe as DEFAULT_EXTENSIONS,X as DEFAULT_IGNORE_DIRS,cr as EXPORT_TRACKING_TYPES,G as Graph,lr as IMPORT_SYMBOL_TYPES,Ye as MermaidExporter,_ as SymbolTraversalContext,ne as WorkspaceGraph,_n as applyConfig,Io as applyTags,Yn as buildApiSurface,qn as buildChangeImpactCache,nt as buildFeatureGraph,ai as buildResponsibilityGraph,fi as buildTypeGraph,Ze as computeGraphHash,jn as configToGraphOptions,gd as createImportMap,dd as createWorkspaceGraph,Jt as detectAllEntryPoints,Kn as detectEntryPoint,q as detectFeatures,ct as detectMonorepo,Nr as filterGraph,ni as findComplexFunctions,Us as findDuplicates,ci as findSymbol,ti as getAffected,hd as getAllProjectFiles,ri as getCallers,ei as getDependencies,st as getDependents,Zs as getLanguageCoverage,qs as getNodeMeta,oi as hasCoverageData,ts as isChangeImpactCacheValid,ns as loadChangeImpactCache,$n as loadCoverageMap,He as loadMokoshConfig,Ir as parseQuery,pc as proposeAffectedTests,lc as proposeTags,Xn as queryCallGraph,es as queryChangeImpact,mi as queryTypeGraph,he as registerConfigMatcher,D as registerMonorepoDetector,V as registerParser,xe as registerTestLibrary,ye as registerTestPattern,rs as saveChangeImpactCache,si as slimSerialize,ii as summarizeWorkspacePackages,Ut as toMermaid};
33
+ `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):mn(e,r)}makeStubNode(e,r,n){return{path:r,type:A(e),category:"other",imports:[],exports:[],tags:[],mtime:n.mtimeMs,size:n.size}}resolveCallEdges(e,r){let n=[];for(let s of r??[])try{let i=this.resolver.resolve(e,s.toSpecifier);i&&!i.isExternal&&n.push({from:s.from,to:s.to,toFile:N.relative(this.rootDir,i.path)})}catch{}return n}buildNode(e,r,n,s,i){let{imports:o,exports:a,tags:c,category:l,description:p,complexity:g,cognitiveComplexity:d,functions:h}=s;return{path:r,type:A(e),category:l,imports:o,exports:a,tags:c,mtime:n.mtimeMs,size:n.size,...p!==void 0?{description:p}:{},...i.length>0?{callEdges:i}:{},...g!==void 0?{complexity:g}:{},...d!==void 0?{cognitiveComplexity:d}:{},...h!==void 0?{functions:h}:{}}}attachGitStats(e,r){let n=this.gitStatsMap?.get(r);n&&(e.commitCount90d=n.commitCount90d,n.lastAuthor!==void 0&&(e.lastAuthor=n.lastAuthor),n.lastCommitAt!==void 0&&(e.lastCommitAt=n.lastCommitAt))}async resolveImports(e,r){let n=[];for(let s of r){let i=this.resolver.resolveAll(e,s.rawSpecifier);if(i.length!==0)for(let o of i){let a={...s,toPath:o.isExternal?o.path:N.relative(this.rootDir,o.path),isExternal:o.isExternal};o.isWorkspace&&(a.isWorkspace=!0,a.workspacePackage=o.workspacePackage),o.isExternal?this.attachLockfileVersion(a):this.enqueue(o.path),n.push(a)}}return n}attachLockfileVersion(e){if(!this.lockFile)return;let r=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],n=r?this.lockFile.dependencies[r]:void 0;n&&(e.version=n.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function Nn(t,e){return{identifier:e?.identifier??new je,featureMap:e?.featureDetection===!1?new Map:te(t.nodes,e?.featureDetection??void 0)}}function Pn(t,e,r,n,s){for(let i of e){let o=t.nodes.get(i);if(!o)continue;let a=new _(i,["*",...o.exports.map(c=>c.name)]);t.traverse(i,(c,l,p)=>{if(!p)return!0;if(!a.updateAffectedSymbols(c,p))return!1;if(l>0){let g=r.get(c.path);if(g)return n(g),!1}return s(c),!0},{direction:"incoming"})}}function dc(t,e,r){let{identifier:n,featureMap:s}=Nn(t,r),i=new Set;for(let o of e){let a=s.get(o);a&&i.add(a.tag)}return Pn(t,e,s,o=>i.add(o.tag),o=>{if(n.isTestNode(o))for(let a of o.tags)i.add(a.name)}),Array.from(i)}function hc(t,e,r){let{identifier:n,featureMap:s}=Nn(t,r),i=new Set;return Pn(t,e,s,()=>{},o=>{n.isTestNode(o)&&i.add(o.path)}),Array.from(i)}import yc from"fs";import ye from"path";async function kd(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},i=ye.resolve(t);return await new he(i,r,n.pathAliases?new B(i,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0).build(e)}async function vd(t,e={}){let r=ye.resolve(t),n=pt(r),s=e.packages?n.packages.filter(a=>e.packages?.includes(a.name)||e.packages?.includes(a.relativeRoot)):n.packages,i=new Map(n.packages.map(a=>[a.name,a.root])),o=new ie(r,n.type);for(let a of s){let c=e.silent?void 0:g=>{process.stderr.write(`[${a.name}] Processed ${g} files...\r`)},p=await new he(r,null,new B(r,{workspaceMap:i,tsconfigSearchPaths:[a.root,r],pathAliases:e.pathAliases}),c,e.gitStats??!1,new Map,e.parallelParsing??!0).build(a.entryPoints);o.addPackage(a,p)}return o}function Cd(t,e={}){let r=[],n=new Set([...e.ignoreDirs??q,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??Ze,...e.additionalExtensions??[]]);function i(o){try{let a=yc.readdirSync(o,{withFileTypes:!0});for(let c of a){let l=ye.join(o,c.name);c.isDirectory()?n.has(c.name)||i(l):c.isFile()&&s.has(ye.extname(c.name).toLowerCase())&&r.push(ye.relative(t,l))}}catch{}}return i(t),r}export{Ne as CALL_EDGE_TYPES,Ze as DEFAULT_EXTENSIONS,q as DEFAULT_IGNORE_DIRS,pr as EXPORT_TRACKING_TYPES,G as Graph,fr as IMPORT_SYMBOL_TYPES,qe as MermaidExporter,_ as SymbolTraversalContext,ie as WorkspaceGraph,Wn as applyConfig,Oo as applyTags,Zn as buildApiSurface,ts as buildChangeImpactCache,it as buildFeatureGraph,mi as buildResponsibilityGraph,yi as buildTypeGraph,tt as computeGraphHash,zn as configToGraphOptions,kd as createImportMap,vd as createWorkspaceGraph,Qt as detectAllEntryPoints,Jn as detectEntryPoint,te as detectFeatures,pt as detectMonorepo,Ir as filterGraph,li as findComplexFunctions,Qs as findDuplicates,gi as findSymbol,ai as getAffected,Cd as getAllProjectFiles,ci as getCallers,oi as getDependencies,ot as getDependents,si as getLanguageCoverage,ii as getNodeMeta,ui as hasCoverageData,ns as isChangeImpactCacheValid,is as loadChangeImpactCache,Bn as loadCoverageMap,Xe as loadMokoshConfig,Dr as parseQuery,hc as proposeAffectedTests,dc as proposeTags,qn as queryCallGraph,rs as queryChangeImpact,xi as queryTypeGraph,xe as registerConfigMatcher,R as registerMonorepoDetector,J as registerParser,be as registerTestLibrary,Se as registerTestPattern,ss as saveChangeImpactCache,pi as slimSerialize,fi as summarizeWorkspacePackages,Vt as toMermaid};
32
34
  //# sourceMappingURL=index.mjs.map