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