@omfalos/mokosh 0.2.0 → 0.3.0

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