@omfalos/mokosh 0.1.7 → 0.1.8
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 +1 -1
- package/dist/cli.js +23 -23
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +23 -23
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.js +16 -16
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +16 -16
- package/dist/mcp.mjs.map +1 -1
- package/package.json +9 -6
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var Ft=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import
|
|
2
|
-
`)}};function de(e){return At.serialize(e)}import he from"fs";import ts from"path";function Lt(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 ye(e,t){if(typeof e=="string")return Lt(e,t);if(e&&typeof e=="object"){let r=e;for(let s of["import","require","default"]){let n=ye(r[s],t);if(n)return n}}return null}function es(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 rs(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 ss(e,t){return xe(e,t)[0]??null}function xe(e,t){let r=[],s=ts.join(t,"package.json");if(he.existsSync(s))try{let n=JSON.parse(he.readFileSync(s,"utf8"));if(n.exports&&typeof n.exports=="object"&&!Array.isArray(n.exports))for(let i of Object.values(n.exports)){let o=ye(i,e);o&&!r.includes(o)&&r.push(o)}else if(typeof n.exports=="string"){let i=Lt(n.exports,e);i&&r.push(i)}if(r.length===0)for(let i of[n.main,n.module].filter(Boolean)){let o=Lt(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 ns(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 is(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 os(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:es(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 as(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 cs(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=ns(e,t),s=is(e,r,t),n=rs(e,t),i=os(n,s,e,t),{internalFiles:o,unreachableFromEntry:a,testFiles:c}=as(e,r,t);return{entryPoints:t,publicExports:i,internalFiles:o,unreachableFromEntry:a,testFiles:c}}function ps(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 K from"fs";import ls from"path";function Gt(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 fs(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:Gt(e)}}function ms(e,t){return e.impact.get(t)??[]}function us(e,t){return e.graphHash===Gt(t)}function gs(e,t){let r=ls.dirname(t);K.existsSync(r)||K.mkdirSync(r,{recursive:!0});let s={graphHash:e.graphHash,impact:[...e.impact.entries()]};K.writeFileSync(t,JSON.stringify(s))}function ds(e){if(!K.existsSync(e))return null;try{let t=K.readFileSync(e,"utf-8"),r=JSON.parse(t);return{graphHash:r.graphHash,impact:new Map(r.impact)}}catch{return null}}import ft from"path";function hs(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 ys(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=ft.extname(n),c=ft.basename(n,a),p=c==="index"?ft.basename(ft.dirname(n)):c;s.set(n,{path:n,outDegree:i,tag:`feature:${p}`})}return s}function J(e,t){let r=t?.minOutDegree??5;return ys(e,hs(e),r)}var xs=(e,t)=>e.outDegree-t.outDegree;function Ss(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 bs(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 vs(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 ks(e,t,r){let s=[];for(let n of e.keys())!t.has(n)&&!r.has(n)&&s.push(n);return s}function jt(e,t){let r=t?.detectFn??J,s=t?.hubComparator??xs,n=r(e.nodes,t),i=Ss(e,n),o=bs(e.nodes,n,i,s);return{features:vs(n,o),unassigned:ks(e.nodes,n,o)}}var H=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 H(this.nodes).findUnusedFiles(t)}findCycles(){return new H(this.nodes).findCycles()}};var N=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 Cs(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 Es(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 ws(e,t,r={}){let{testsOnly:s=!1,changedSymbols:n}=r,i=n?new N(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 Fs(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 Ps(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 Ts(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 Is(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 Ns(e){return[...e.nodes.values()].some(t=>t.coveragePct!==void 0)}function Se(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 Ms(e,t){let r=jt(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:Se(i),...i.description?{description:i.description}:{},exports:i.exports.map(a=>a.name),...o?{featureHub:o}:{}})}return n}function Ds(e){return e?e.startsWith("interface ")?"interface":e.startsWith("class ")?"class":e.startsWith("enum ")?"enum":"type":"type"}function Rs(e,t){if(t==="type-only")return!0;let r=e.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function As(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(!Rs(n,s.category))continue;let i=`${s.path}::${n.name}`;t.set(i,{name:n.name,file:s.path,kind:Ds(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 Ls(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 Hs from"path";import Wt from"fs";import Ce from"path";import V from"fs";import C from"path";import be from"fs";import Ya from"path";function ve(e){try{return be.statSync(e,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function mt(e){try{return be.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function Ot(e,t){let r=C.join(t,"package.json");if(!V.existsSync(r))return null;let s={};try{s=JSON.parse(V.readFileSync(r,"utf-8"))}catch{return null}let n=s.name;return n?{name:n,root:t,relativeRoot:C.relative(e,t),entryPoints:Gs(t,s)}:null}function Gs(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(mt);return s.length>0?s.slice(0,1):r.slice(0,1)}function M(e,t){let r=[],s=new Set;for(let n of t){let i=n.replace(/\/$/,"").replace(/^\.\//,"");js(e,i,s,r)}return r}function js(e,t,r,s){if(!t.includes("*")){Os(e,t,r,s);return}let n=t.split("/");n.includes("**")?Ws(e,n,r,s):_s(e,n,r,s)}function Os(e,t,r,s){let n=C.join(e,t);if(r.has(n)||!ve(n))return;r.add(n);let i=Ot(e,n);i&&s.push(i)}function Ws(e,t,r,s){let n=C.join(e,t[0]==="**"?"":t[0]??"");ke(e,n,r,s)}function _s(e,t,r,s){let n=t.findIndex(a=>a.includes("*")),i=C.join(e,...t.slice(0,n)),o;try{o=V.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=Ot(e,c);p&&s.push(p)}}function ke(e,t,r,s){let n;try{n=V.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(V.existsSync(C.join(o,"package.json"))&&!r.has(o)){r.add(o);let a=Ot(e,o);a&&s.push(a)}else ke(e,o,r,s)}}var Ee={type:"npm",detect(e){let t=Ce.join(e,"package.json");if(!Wt.existsSync(t))return null;let r;try{r=JSON.parse(Wt.readFileSync(t,"utf-8")).workspaces}catch{return null}if(!r||Wt.existsSync(Ce.join(e,"yarn.lock")))return null;let s=Array.isArray(r)?r:r.packages??[];return s.length===0?null:M(e,s)}};import D from"fs";import S from"path";var we={type:"nx",detect(e){return D.existsSync(S.join(e,"nx.json"))?Fe(e,e,new Set,0).map(r=>zs(e,r,S.join(r,"project.json"))).filter(r=>r!==null):null}};function Fe(e,t,r,s){if(s>4)return[];let n;try{n=D.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);D.existsSync(S.join(c,"project.json"))&&!r.has(c)?(r.add(c),i.push(c)):i.push(...Fe(e,c,r,s+1))}return i}function zs(e,t,r){let s={};try{s=JSON.parse(D.readFileSync(r,"utf-8"))}catch{return null}let n=s.name,i,o,a=S.join(t,"package.json");if(D.existsSync(a))try{let c=JSON.parse(D.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:$s(t,s,i,o)}:null}function $s(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(mt);return o.length>0?o.slice(0,1):n.slice(0,1)}import Pe from"fs";import Bs from"path";import Us from"js-yaml";var Te={type:"pnpm",detect(e){let t=Bs.join(e,"pnpm-workspace.yaml");if(!Pe.existsSync(t))return null;let r=[];try{r=Us.load(Pe.readFileSync(t,"utf-8"))?.packages??[]}catch{return null}return M(e,r)}};import Ks from"fs";import Js from"path";var Ie={type:"turborepo",detect(e){return Ks.existsSync(Js.join(e,"turbo.json"))?[]:null}};import _t from"fs";import Ne from"path";var Me={type:"yarn",detect(e){if(!_t.existsSync(Ne.join(e,"yarn.lock")))return null;let t=Ne.join(e,"package.json");if(!_t.existsSync(t))return null;let r;try{r=JSON.parse(_t.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:M(e,s)}};var De=[];function F(e){De.push(e)}function Re(){return De}F(Ie);F(we);F(Te);F(Me);F(Ee);function zt(e,t=Re()){let r=Hs.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 X=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 Ae=new Map;function R(e,t){Ae.set(e,t)}function Le(e){return Ae.get(e)}function Ge(e,t){return t.startsWith("!")?e!==t.slice(1):e===t}function Qs(e,t){return t.startsWith("!")?!e.includes(t.slice(1)):e.includes(t)}var Vs=(e,t)=>!t.category||Ge(e.category,t.category),Xs=(e,t)=>!t.type||Ge(e.type,t.type),Zs=(e,t)=>t.lastAuthor?t.lastAuthor.startsWith("!")?e.lastAuthor!==t.lastAuthor.slice(1):e.lastAuthor!==void 0&&e.lastAuthor===t.lastAuthor:!0,Ys=(e,t)=>!t.path||Qs(e.path,t.path),qs=(e,t)=>t.isExternal===void 0?!0:e.imports.some(s=>s.isExternal)===t.isExternal,tn=(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)))},en=(e,t)=>!t.allTags?.length||t.allTags.every(r=>e.tags.some(s=>s.name===r)),rn=(e,t)=>!t.importsFile||e.imports.some(r=>r.toPath?.includes(t.importsFile)),sn=(e,t,r)=>t.importedBy===void 0?!0:(r?.get(e.path)??[]).some(n=>n.includes(t.importedBy)),nn=(e,t)=>t.minImports===void 0||e.imports.length>=t.minImports,on=(e,t)=>t.maxImports===void 0||e.imports.length<=t.maxImports,an=(e,t)=>t.minSize===void 0||e.size>=t.minSize,cn=(e,t)=>t.maxSize===void 0||e.size<=t.maxSize,pn=(e,t)=>t.hasDocstring===void 0||!!e.description===t.hasDocstring,ln=(e,t)=>t.isDocumented===void 0||!!e.documentedBy?.length===t.isDocumented,fn=(e,t)=>t.isStale===void 0||!!e.staleFor?.length===t.isStale,mn=(e,t)=>t.minCoverage===void 0||(e.coveragePct??101)>=t.minCoverage,un=(e,t)=>t.maxCoverage===void 0||(e.coveragePct??0)<=t.maxCoverage,gn=(e,t)=>t.minExportUsage===void 0||(e.avgExportUsage??-1)>=t.minExportUsage,dn=(e,t)=>t.maxExportUsage===void 0||(e.avgExportUsage??0)<=t.maxExportUsage,hn=(e,t)=>t.minComplexity===void 0||(e.complexity??-1/0)>=t.minComplexity,yn=(e,t)=>t.maxComplexity===void 0||(e.complexity??0)<=t.maxComplexity,xn=(e,t)=>t.minCognitiveComplexity===void 0||(e.cognitiveComplexity??-1/0)>=t.minCognitiveComplexity,Sn=(e,t)=>t.maxCognitiveComplexity===void 0||(e.cognitiveComplexity??0)<=t.maxCognitiveComplexity,bn=(e,t)=>t.minCommits===void 0||(e.commitCount90d??-1/0)>=t.minCommits,vn=(e,t)=>t.maxCommits===void 0||(e.commitCount90d??0)<=t.maxCommits,kn=(e,t,r)=>!t.any?.length||t.any.some(s=>Z(e,s,r)),Cn=[Vs,Xs,Zs,Ys,qs,tn,en,rn,sn,nn,on,an,cn,pn,ln,fn,mn,un,gn,dn,hn,yn,xn,Sn,bn,vn,kn];function Z(e,t,r){return Cn.every(s=>s(e,t,r))}function je(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 Oe(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 En(e){let t=[];for(let r of e.split("|")){let s=r.trim();if(!s)continue;let n={};Oe(n,s),Object.keys(n).length>0&&t.push(n)}return t}function We(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=En(i);o.length>0&&(t.any=[...t.any??[],...o]);continue}Oe(t,s)}return t}import Ze from"fs/promises";import Qn from"path";import Ht from"path";import bt from"typescript";import ze from"path";import $e from"typescript";import v from"typescript";var _e=new Set(["describe","test","it"]);function A(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)&&_e.has(n.text)&&t.push(s),v.isPropertyAccessExpression(n)&&v.isIdentifier(n.expression)&&_e.has(n.expression.text)&&t.push(s)}return t}function L(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 G(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 j(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 O(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 W(e){return`[${e.map(t=>JSON.stringify(t)).join(", ")}]`}var w=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function wn(e){return W(e.map(t=>`@${t}`))}function Fn(e){return e.map(t=>t.startsWith("@")?t.slice(1):t)}var ut=class{name="cypress";canHandle(t){return w.has(ze.extname(t).toLowerCase())}apply(t,r,s){let n=$e.createSourceFile(ze.basename(t),r,$e.ScriptTarget.Latest,!0),i=A(n);if(i.length===0)return r;let o=L(i[0],"tags",n),a=[...s].sort();if(o!==null&&JSON.stringify(Fn(o).sort())===JSON.stringify(a))return r;let c=i.flatMap(p=>{let g=s.length===0?j(p,"tags",n):G(p,"tags",wn(a),n);return g?[g]:[]});return c.length>0?O(r,c):r}};import Pn from"path";var $t=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,Bt=/^@([a-zA-Z0-9_-]+)/gm;function Tn(e){return["# <mokosh-tags>",...e.map(t=>`@${t}`),"# </mokosh-tags>"].join(`
|
|
1
|
+
var Ft=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import Jr from"path";import{fileURLToPath as Hr}from"url";var Qr=()=>Hr(import.meta.url),Vr=()=>Jr.dirname(Qr()),f=Vr();import Mt from"fs";import fe from"path";var Xr=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],oe=[];function ct(e){oe.push(e)}function ae(e){return[...Xr,...oe].some(t=>typeof t=="string"?e.includes(t):t instanceof RegExp?t.test(e):t(e))}var Yr=[".test.",".spec.","-test.","-spec."],ce=[];function pt(e){ce.push(e)}function U(){return[...Yr,...ce]}var Zr=["jest","vitest","playwright","cypress","@testing-library/"],pe=[];function lt(e){pe.push(e)}function Pt(){return[...Zr,...pe]}var le=.8;function Tt(e){le=e}function It(){return le}var qr=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function Nt(e,{allowJs:t=!0,isExplicitPath:r=!1}={}){if(r){let s=fe.resolve(e);return Mt.existsSync(s)?s.endsWith(".json")?me(s):t?ue(s):{}:{}}for(let s of qr){let n=fe.resolve(e,s);if(Mt.existsSync(n)){if(s.endsWith(".json"))return me(n);if(t)return ue(n)}}return{}}function me(e){return JSON.parse(Mt.readFileSync(e,"utf-8"))}function ue(e){let t=Ft(e);return t&&typeof t=="object"&&"default"in t&&(t=t.default),typeof t=="function"?t({}):t}function ts(e){for(let t of e.configMatchers??[])ct(t);for(let t of e.testPatterns??[])pt(t);for(let t of e.testLibraries??[])lt(t);e.barrelThreshold!==void 0&&Tt(e.barrelThreshold)}var Rt=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],Dt=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];import es from"fs";import ge from"path";function rs(e,t){let r=ge.resolve(e,t);try{let s=es.readFileSync(r,"utf-8"),n=JSON.parse(s),i=new Map;for(let[o,a]of Object.entries(n)){if(o==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let p=ge.relative(e,o);i.set(p,c)}return i}catch{return new Map}}var At={serialize(e){let t=["graph TD"],r=new Set;for(let s of e.nodes.values()){let n=`"${s.path}"`;for(let i of s.imports){if(!i.toPath)continue;let o=`"${i.toPath}"`,a=`${s.path} -> ${i.toPath}`;if(!r.has(a)){let c=i.isStyle?"-- styles -->":"-->";t.push(` ${n} ${c} ${o}`),r.add(a)}}}return t.join(`
|
|
2
|
+
`)}};function de(e){return At.serialize(e)}import he from"fs";import ss from"path";function Lt(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 ye(e,t){if(typeof e=="string")return Lt(e,t);if(e&&typeof e=="object"){let r=e;for(let s of["import","require","default"]){let n=ye(r[s],t);if(n)return n}}return null}function ns(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 is(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 os(e,t){return xe(e,t)[0]??null}function xe(e,t){let r=[],s=ss.join(t,"package.json");if(he.existsSync(s))try{let n=JSON.parse(he.readFileSync(s,"utf8"));if(n.exports&&typeof n.exports=="object"&&!Array.isArray(n.exports))for(let i of Object.values(n.exports)){let o=ye(i,e);o&&!r.includes(o)&&r.push(o)}else if(typeof n.exports=="string"){let i=Lt(n.exports,e);i&&r.push(i)}if(r.length===0)for(let i of[n.main,n.module].filter(Boolean)){let o=Lt(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 as(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 cs(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 ps(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:ns(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 ls(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 fs(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=as(e,t),s=cs(e,r,t),n=is(e,t),i=ps(n,s,e,t),{internalFiles:o,unreachableFromEntry:a,testFiles:c}=ls(e,r,t);return{entryPoints:t,publicExports:i,internalFiles:o,unreachableFromEntry:a,testFiles:c}}function ms(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 K from"fs";import us from"path";function Gt(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 gs(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:Gt(e)}}function ds(e,t){return e.impact.get(t)??[]}function hs(e,t){return e.graphHash===Gt(t)}function ys(e,t){let r=us.dirname(t);K.existsSync(r)||K.mkdirSync(r,{recursive:!0});let s={graphHash:e.graphHash,impact:[...e.impact.entries()]};K.writeFileSync(t,JSON.stringify(s))}function xs(e){if(!K.existsSync(e))return null;try{let t=K.readFileSync(e,"utf-8"),r=JSON.parse(t);return{graphHash:r.graphHash,impact:new Map(r.impact)}}catch{return null}}import ft from"path";function Ss(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 bs(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=ft.extname(n),c=ft.basename(n,a),p=c==="index"?ft.basename(ft.dirname(n)):c;s.set(n,{path:n,outDegree:i,tag:`feature:${p}`})}return s}function J(e,t){let r=t?.minOutDegree??5;return bs(e,Ss(e),r)}var vs=(e,t)=>e.outDegree-t.outDegree;function ks(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 Es(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 Cs(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 ws(e,t,r){let s=[];for(let n of e.keys())!t.has(n)&&!r.has(n)&&s.push(n);return s}function jt(e,t){let r=t?.detectFn??J,s=t?.hubComparator??vs,n=r(e.nodes,t),i=ks(e,n),o=Es(e.nodes,n,i,s);return{features:Cs(n,o),unassigned:ws(e.nodes,n,o)}}var H=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 H(this.nodes).findUnusedFiles(t)}findCycles(){return new H(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 Fs(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 Ps(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 Ts(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 Is(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 Ms(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 Ns(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 Rs(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 Ds(e){return[...e.nodes.values()].some(t=>t.coveragePct!==void 0)}function Se(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 As(e,t){let r=jt(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:Se(i),...i.description?{description:i.description}:{},exports:i.exports.map(a=>a.name),...o?{featureHub:o}:{}})}return n}function Ls(e){return e?e.startsWith("interface ")?"interface":e.startsWith("class ")?"class":e.startsWith("enum ")?"enum":"type":"type"}function Gs(e,t){if(t==="type-only")return!0;let r=e.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function js(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(!Gs(n,s.category))continue;let i=`${s.path}::${n.name}`;t.set(i,{name:n.name,file:s.path,kind:Ls(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 Os(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 Xs from"path";import Wt from"fs";import Ee from"path";import V from"fs";import E from"path";import be from"fs";import ec from"path";function ve(e){try{return be.statSync(e,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function mt(e){try{return be.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function Ot(e,t){let r=E.join(t,"package.json");if(!V.existsSync(r))return null;let s={};try{s=JSON.parse(V.readFileSync(r,"utf-8"))}catch{return null}let n=s.name;return n?{name:n,root:t,relativeRoot:E.relative(e,t),entryPoints:Ws(t,s)}:null}function Ws(e,t){let r=[];if(t.exports){let n=t.exports;if(typeof n=="string")r.push(E.join(e,n));else if(typeof n=="object"&&n!==null){let i=n["."];if(typeof i=="string")r.push(E.join(e,i));else if(typeof i=="object"&&i!==null){let o=i.import??i.require??i.default;typeof o=="string"&&r.push(E.join(e,o))}}}t.main&&r.push(E.join(e,t.main));for(let n of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(E.join(e,n));let s=r.filter(mt);return s.length>0?s.slice(0,1):r.slice(0,1)}function N(e,t){let r=[],s=new Set;for(let n of t){let i=n.replace(/\/$/,"").replace(/^\.\//,"");_s(e,i,s,r)}return r}function _s(e,t,r,s){if(!t.includes("*")){$s(e,t,r,s);return}let n=t.split("/");n.includes("**")?zs(e,n,r,s):Bs(e,n,r,s)}function $s(e,t,r,s){let n=E.join(e,t);if(r.has(n)||!ve(n))return;r.add(n);let i=Ot(e,n);i&&s.push(i)}function zs(e,t,r,s){let n=E.join(e,t[0]==="**"?"":t[0]??"");ke(e,n,r,s)}function Bs(e,t,r,s){let n=t.findIndex(a=>a.includes("*")),i=E.join(e,...t.slice(0,n)),o;try{o=V.readdirSync(i,{withFileTypes:!0})}catch{return}for(let a of o){if(!a.isDirectory())continue;let c=E.join(i,a.name);if(r.has(c))continue;r.add(c);let p=Ot(e,c);p&&s.push(p)}}function ke(e,t,r,s){let n;try{n=V.readdirSync(t,{withFileTypes:!0})}catch{return}for(let i of n){if(!i.isDirectory()||i.name==="node_modules"||i.name.startsWith("."))continue;let o=E.join(t,i.name);if(V.existsSync(E.join(o,"package.json"))&&!r.has(o)){r.add(o);let a=Ot(e,o);a&&s.push(a)}else ke(e,o,r,s)}}var Ce={type:"npm",detect(e){let t=Ee.join(e,"package.json");if(!Wt.existsSync(t))return null;let r;try{r=JSON.parse(Wt.readFileSync(t,"utf-8")).workspaces}catch{return null}if(!r||Wt.existsSync(Ee.join(e,"yarn.lock")))return null;let s=Array.isArray(r)?r:r.packages??[];return s.length===0?null:N(e,s)}};import R from"fs";import S from"path";var we={type:"nx",detect(e){return R.existsSync(S.join(e,"nx.json"))?Fe(e,e,new Set,0).map(r=>Us(e,r,S.join(r,"project.json"))).filter(r=>r!==null):null}};function Fe(e,t,r,s){if(s>4)return[];let n;try{n=R.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);R.existsSync(S.join(c,"project.json"))&&!r.has(c)?(r.add(c),i.push(c)):i.push(...Fe(e,c,r,s+1))}return i}function Us(e,t,r){let s={};try{s=JSON.parse(R.readFileSync(r,"utf-8"))}catch{return null}let n=s.name,i,o,a=S.join(t,"package.json");if(R.existsSync(a))try{let c=JSON.parse(R.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:Ks(t,s,i,o)}:null}function Ks(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(mt);return o.length>0?o.slice(0,1):n.slice(0,1)}import Pe from"fs";import Js from"path";import{load as Hs}from"js-yaml";var Te={type:"pnpm",detect(e){let t=Js.join(e,"pnpm-workspace.yaml");if(!Pe.existsSync(t))return null;let r=[];try{r=Hs(Pe.readFileSync(t,"utf-8"))?.packages??[]}catch{return null}return N(e,r)}};import Qs from"fs";import Vs from"path";var Ie={type:"turborepo",detect(e){return Qs.existsSync(Vs.join(e,"turbo.json"))?[]:null}};import _t from"fs";import Me from"path";var Ne={type:"yarn",detect(e){if(!_t.existsSync(Me.join(e,"yarn.lock")))return null;let t=Me.join(e,"package.json");if(!_t.existsSync(t))return null;let r;try{r=JSON.parse(_t.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:N(e,s)}};var Re=[];function F(e){Re.push(e)}function De(){return Re}F(Ie);F(we);F(Te);F(Ne);F(Ce);function $t(e,t=De()){let r=Xs.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 X=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 Ae=new Map;function D(e,t){Ae.set(e,t)}function Le(e){return Ae.get(e)}function Ge(e,t){return t.startsWith("!")?e!==t.slice(1):e===t}function Ys(e,t){return t.startsWith("!")?!e.includes(t.slice(1)):e.includes(t)}var Zs=(e,t)=>!t.category||Ge(e.category,t.category),qs=(e,t)=>!t.type||Ge(e.type,t.type),tn=(e,t)=>t.lastAuthor?t.lastAuthor.startsWith("!")?e.lastAuthor!==t.lastAuthor.slice(1):e.lastAuthor!==void 0&&e.lastAuthor===t.lastAuthor:!0,en=(e,t)=>!t.path||Ys(e.path,t.path),rn=(e,t)=>t.isExternal===void 0?!0:e.imports.some(s=>s.isExternal)===t.isExternal,sn=(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)))},nn=(e,t)=>!t.allTags?.length||t.allTags.every(r=>e.tags.some(s=>s.name===r)),on=(e,t)=>!t.importsFile||e.imports.some(r=>r.toPath?.includes(t.importsFile)),an=(e,t,r)=>t.importedBy===void 0?!0:(r?.get(e.path)??[]).some(n=>n.includes(t.importedBy)),cn=(e,t)=>t.minImports===void 0||e.imports.length>=t.minImports,pn=(e,t)=>t.maxImports===void 0||e.imports.length<=t.maxImports,ln=(e,t)=>t.minSize===void 0||e.size>=t.minSize,fn=(e,t)=>t.maxSize===void 0||e.size<=t.maxSize,mn=(e,t)=>t.hasDocstring===void 0||!!e.description===t.hasDocstring,un=(e,t)=>t.isDocumented===void 0||!!e.documentedBy?.length===t.isDocumented,gn=(e,t)=>t.isStale===void 0||!!e.staleFor?.length===t.isStale,dn=(e,t)=>t.minCoverage===void 0||(e.coveragePct??101)>=t.minCoverage,hn=(e,t)=>t.maxCoverage===void 0||(e.coveragePct??0)<=t.maxCoverage,yn=(e,t)=>t.minExportUsage===void 0||(e.avgExportUsage??-1)>=t.minExportUsage,xn=(e,t)=>t.maxExportUsage===void 0||(e.avgExportUsage??0)<=t.maxExportUsage,Sn=(e,t)=>t.minComplexity===void 0||(e.complexity??-1/0)>=t.minComplexity,bn=(e,t)=>t.maxComplexity===void 0||(e.complexity??0)<=t.maxComplexity,vn=(e,t)=>t.minCognitiveComplexity===void 0||(e.cognitiveComplexity??-1/0)>=t.minCognitiveComplexity,kn=(e,t)=>t.maxCognitiveComplexity===void 0||(e.cognitiveComplexity??0)<=t.maxCognitiveComplexity,En=(e,t)=>t.minCommits===void 0||(e.commitCount90d??-1/0)>=t.minCommits,Cn=(e,t)=>t.maxCommits===void 0||(e.commitCount90d??0)<=t.maxCommits,wn=(e,t,r)=>!t.any?.length||t.any.some(s=>Y(e,s,r)),Fn=[Zs,qs,tn,en,rn,sn,nn,on,an,cn,pn,ln,fn,mn,un,gn,dn,hn,yn,xn,Sn,bn,vn,kn,En,Cn,wn];function Y(e,t,r){return Fn.every(s=>s(e,t,r))}function je(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=>Y(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 Oe(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 Pn(e){let t=[];for(let r of e.split("|")){let s=r.trim();if(!s)continue;let n={};Oe(n,s),Object.keys(n).length>0&&t.push(n)}return t}function We(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=Pn(i);o.length>0&&(t.any=[...t.any??[],...o]);continue}Oe(t,s)}return t}import Ye from"fs/promises";import Yn from"path";import Ht from"path";import bt from"typescript";import $e from"path";import ze from"typescript";import v from"typescript";var _e=new Set(["describe","test","it"]);function A(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)&&_e.has(n.text)&&t.push(s),v.isPropertyAccessExpression(n)&&v.isIdentifier(n.expression)&&_e.has(n.expression.text)&&t.push(s)}return t}function L(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 G(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 j(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 O(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 W(e){return`[${e.map(t=>JSON.stringify(t)).join(", ")}]`}var w=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function Tn(e){return W(e.map(t=>`@${t}`))}function In(e){return e.map(t=>t.startsWith("@")?t.slice(1):t)}var ut=class{name="cypress";canHandle(t){return w.has($e.extname(t).toLowerCase())}apply(t,r,s){let n=ze.createSourceFile($e.basename(t),r,ze.ScriptTarget.Latest,!0),i=A(n);if(i.length===0)return r;let o=L(i[0],"tags",n),a=[...s].sort();if(o!==null&&JSON.stringify(In(o).sort())===JSON.stringify(a))return r;let c=i.flatMap(p=>{let g=s.length===0?j(p,"tags",n):G(p,"tags",Tn(a),n);return g?[g]:[]});return c.length>0?O(r,c):r}};import Mn from"path";var zt=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,Bt=/^@([a-zA-Z0-9_-]+)/gm;function Nn(e){return["# <mokosh-tags>",...e.map(t=>`@${t}`),"# </mokosh-tags>"].join(`
|
|
3
3
|
`)+`
|
|
4
4
|
|
|
5
|
-
`}function
|
|
6
|
-
`}function
|
|
7
|
-
`+r.slice(c)}};import
|
|
5
|
+
`}function Rn(e){let t=new Set;Bt.lastIndex=0;let r=Bt.exec(e);for(;r!==null;)r[1]&&t.add(r[1]),r=Bt.exec(e);return t}var gt=class{name="gherkin";canHandle(t){return Mn.extname(t).toLowerCase()===".feature"}apply(t,r,s){let n=r.replace(zt,""),i=Rn(n),o=s.filter(c=>!i.has(c)),a=o.length>0?Nn(o):"";return zt.test(r)?r.replace(zt,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Be(e,t){let r=e.replace(/\\/g,"/"),s=t.replace(/\\/g,"/"),n="";for(let i=0;i<r.length;i++){let o=r[i];o==="*"?r[i+1]==="*"?(n+=".*",i++):n+="[^/]*":o==="?"?n+="[^/]":o!==void 0&&(n+=o.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${n}$`).test(s)}import Dn from"path";var Ut=/^\/\/go:build mokosh_[^\n]+\n/m,An=/^package\s+\S+/m;function Ln(e){return`//go:build ${e.map(r=>`mokosh_${r}`).join(" || ")}
|
|
6
|
+
`}function Gn(e){let t=Ut.exec(e);if(!t)return null;let r=t[0],s=/mokosh_([a-zA-Z0-9_-]+)/g,n=[],i=s.exec(r);for(;i!==null;)i[1]&&n.push(i[1]),i=s.exec(r);return n}var dt=class{name="go";canHandle(t){return Dn.basename(t).endsWith("_test.go")}apply(t,r,s){let n=Gn(r),i=[...s].sort();if(n!==null&&JSON.stringify([...n].sort())===JSON.stringify(i))return r;if(s.length===0)return r.replace(Ut,"");let o=Ln(i);if(n!==null)return r.replace(Ut,o);let a=An.exec(r);if(!a)return r;let c=a.index;return r.slice(0,c)+o+`
|
|
7
|
+
`+r.slice(c)}};import jn from"path";var On=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,Kt=/^ \* @group (.+)$/gm;function Wn(e){return["/**",...e.map(t=>` * @group ${t}`)," */"].join(`
|
|
8
8
|
`)+`
|
|
9
9
|
|
|
10
|
-
`}function
|
|
10
|
+
`}function _n(e){let t=[];Kt.lastIndex=0;let r=Kt.exec(e);for(;r!==null;)r[1]&&t.push(r[1]),r=Kt.exec(e);return t}var ht=class{name="jest";canHandle(t){return w.has(jn.extname(t).toLowerCase())}apply(t,r,s){let n=On.exec(r),i=n?_n(n[0]):null,o=[...s].sort();if(i!==null&&JSON.stringify([...i].sort())===JSON.stringify(o))return r;let a=n?r.slice(n[0].length):r;return s.length===0?a:Wn(o)+a}};import Ue from"path";import Ke from"typescript";function $n(e){return W(e.map(t=>`@${t}`))}function zn(e){return e.map(t=>t.startsWith("@")?t.slice(1):t)}var yt=class{name="playwright";canHandle(t){return w.has(Ue.extname(t).toLowerCase())}apply(t,r,s){let n=Ke.createSourceFile(Ue.basename(t),r,Ke.ScriptTarget.Latest,!0),i=A(n);if(i.length===0)return r;let o=L(i[0],"tag",n),a=[...s].sort();if(o!==null&&JSON.stringify(zn(o).sort())===JSON.stringify(a))return r;let c=i.flatMap(p=>{let g=s.length===0?j(p,"tag",n):G(p,"tag",$n(a),n);return g?[g]:[]});return c.length>0?O(r,c):r}};import Bn from"path";var Jt=/^pytestmark\s*=\s*.+$/m,Un=/^import pytest\s*$/m;function Kn(e){let t=e.map(r=>`pytest.mark.${r}`).join(", ");return e.length===1?`pytestmark = pytest.mark.${e[0]}`:`pytestmark = [${t}]`}function Jn(e){let t=Jt.exec(e);if(!t)return null;let r=t[0],s=[],n=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,i=n.exec(r);for(;i!==null;)i[1]&&s.push(i[1]),i=n.exec(r);return s}var xt=class{name="pytest";canHandle(t){return Bn.extname(t).toLowerCase()===".py"}apply(t,r,s){let n=Jn(r),i=[...s].sort();if(n!==null&&JSON.stringify([...n].sort())===JSON.stringify(i))return r;if(s.length===0)return r.replace(Jt,"").replace(/\n{3,}/g,`
|
|
11
11
|
|
|
12
|
-
`);let o
|
|
12
|
+
`);let o=Kn(i);if(n!==null)return r.replace(Jt,o);let a=Un.test(r),c=Hn(r),p=r.slice(0,c),g=r.slice(c),u=a?"":`import pytest
|
|
13
13
|
`,y=p.endsWith(`
|
|
14
14
|
|
|
15
15
|
`)?"":`
|
|
16
16
|
`;return p+y+u+o+`
|
|
17
|
-
`+g}};function
|
|
18
|
-
`),r=-1;for(let n=0;n<t.length;n++){let i=t[n].trimStart();(i.startsWith("import ")||i.startsWith("from "))&&(r=n)}if(r<0)return 0;let s=0;for(let n=0;n<=r;n++)s+=t[n].length+1;return s}import Je from"path";import He from"typescript";var
|
|
19
|
-
`).
|
|
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=ei(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 ii(e){let t=kt.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 oi(e){let t=kt.readFileSync(e,"utf-8");if(t.includes("__metadata:")){let r=si(t);if(r!==null)return r}return ni(t)}function ai(e){let t=kt.readFileSync(e,"utf-8"),r={dependencies:{}};try{let s=tr.load(t);if(s.packages)for(let[n,i]of Object.entries(s.packages)){let{name:o,version:a}=ri(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 rr(e){let t=[["package-lock.json",ii],["yarn.lock",oi],["pnpm-lock.yaml",ai]];for(let[r,s]of t){let n=ti.join(e,r);if(kt.existsSync(n))return s(n)}return null}import sr from"path";function P(e){switch(sr.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 E(e){let t=sr.extname(e).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(t)}import ci from"coffeescript";function pi(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 li(e,t){let r=e.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||t.has("test")?"test":"logic"}function fi(e,t){let r=t.source?.value;return r?{fromPath:e,toPath:"",rawSpecifier:r,isStyle:E(r),type:"static"}:null}function mi(e,t){let r=t.variable?.base?.value==="require",s=t.args?.[0]?.base?.value;return!r||!s?null:{fromPath:e,toPath:"",rawSpecifier:s,isStyle:E(s),type:"require"}}function ui(e,t,r){let s=t.constructor?.name;if(s==="ImportDeclaration"){let n=fi(e,t);n&&r.push(n)}else if(s==="Call"){let n=mi(e,t);n&&r.push(n)}}function Vt(e,t,r){if(!(!t||typeof t!="object")){ui(e,t,r);for(let s in t){if(s==="locationData")continue;let n=t[s];if(!(!n||typeof n!="object"))if(Array.isArray(n))for(let i of n)Vt(e,i,r);else Vt(e,n,r)}}}function nr(e,t){let r=pi(t),s=li(e,r),n=[];try{Vt(e,ci.nodes(t),n)}catch{}return{imports:n,exports:[],tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:s}}import{AstBuilder as gi,GherkinClassicTokenMatcher as di,Parser as hi}from"@cucumber/gherkin";import{IdGenerator as yi}from"@cucumber/messages";var xi=yi.uuid();function Xt(e,t){let r=new Set;try{let s=new gi(xi),n=new di,o=new hi(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"}}R("gherkin",Xt);import Si from"path";import{parser as bi}from"@lezer/go";var vi=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,ki=/^\/\/go:build\s+(.+)$/,Ci=/^\/\/\s*\+build\s+(.+)$/;function or(e,t){let r=[],s=new Map,n=new Set,i=new Set,a=bi.parse(t).cursor();do switch(a.name){case"LineComment":{let u=t.slice(a.from,a.to),y=u.match(vi);y?.[1]&&n.add(y[1]);let b=u.match(ki);b&&ir(b[1],i);let B=u.match(Ci);B&&ir(B[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=Si.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 ir(e,t){for(let r of e.split(/[\s,&|!()]+/)){let s=r.trim();s&&s!=="ignore"&&t.add(s)}}import Ei from"livescript";function _(e){return e.startsWith("'")||e.startsWith('"')?e.slice(1,-1):e}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 Fi(e,t){let r=e.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||t.has("test")?"test":"logic"}var Pi=new Set(["first_line","first_column","last_line","last_column","line","column"]);function Ti(e,t){let r=e.constructor?.name||e.type;if(r==="Import"){let s=e.right?.value;if(typeof s=="string"){let n=_(s);return{fromPath:t,toPath:"",rawSpecifier:n,isStyle:E(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=_(n);return{fromPath:t,toPath:"",rawSpecifier:i,isStyle:E(i),type:"require"}}}}return null}function Zt(e,t){if(!e||typeof e!="object")return[];let r=[],s=Ti(e,t);s&&r.push(s);for(let n in e){if(Pi.has(n))continue;let i=e[n];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let o of i)r.push(...Zt(o,t));else r.push(...Zt(i,t))}return r}function ar(e,t){let r=wi(t),s=Fi(e,r),n=[];try{n=Zt(Ei.ast(t),e)}catch{}return{imports:n,exports:[],tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:s}}import Ii from"luaparse";function Ni(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 Mi(e,t){let r=e.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||t.has("test")?"test":"logic"}function Di(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=_(o.raw))}else if(n.type==="StringCallExpression"){let o=n.argument;o?.type==="StringLiteral"&&(i=_(o.raw))}i&&r.push({fromPath:t,toPath:"",rawSpecifier:i,isStyle:E(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 cr(e,t){let r=Ni(t),s=Mi(e,r),n=[];try{let i=Ii.parse(t);n=Di(i,e)}catch{}return{imports:n,exports:[],tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:s}}var Ri=["http://","https://","mailto:","//"],Ai="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",Li=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${Ai})\\b`,"g"),pr;async function Gi(){return pr??=(async()=>{let{unified:e}=await import("unified"),t=(await import("remark-parse")).default;return e().use(t)})(),pr}function ji(e){let t=e.trim();return t.length===0||t.startsWith("#")||Ri.some(r=>t.startsWith(r))}function Oi(e,t){let r=e.match(Li);return r?r.map(s=>({fromPath:t,toPath:"",rawSpecifier:s,isStyle:!1,type:"static"})):[]}function lr(e,t,r){if(e.type==="link"&&typeof e.url=="string"&&!ji(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(...Oi(e.value,t)),Array.isArray(e.children))for(let s of e.children)lr(s,t,r)}async function fr(e,t){let s=(await Gi()).parse(t),n=[];lr(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 Wi from"path";import{parser as _i}from"@lezer/python";var zi=new Set(["pytest","unittest","nose","hypothesis"]);function mr(e,t){let r=[],s=[],n=new Set,i=Wi.basename(e).toLowerCase(),a=_i.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 $i(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=Ji(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 $i(e,t,r){let s=e.firstChild;return s?s.name==="from"?Bi(e,t,r):Ui(e,t,r):[]}function Bi(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=Ki(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[Y(r,i,o,!0)];let p=a===1?"./":"../".repeat(a-1);return c?[Y(r,p+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[Y(r,p.slice(0,-1),["*"],!1)]:o.map(g=>Y(r,p+g,[g],!1))}function Ui(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(Y(r,i,["*"],!0))}n=n.nextSibling}return s}function Ki(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 Y(e,t,r,s){return{fromPath:e,toPath:"",rawSpecifier:t,isStyle:!1,isExternal:s,type:"static",symbols:r.length>0?r:void 0}}function Ji(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=>zi.has(s.rawSpecifier))?"test":"logic"}import gr from"path";import l from"typescript";import d from"typescript";function Hi(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 Qi(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 Yt(e){return{complexity:Hi(e),cognitiveComplexity:Qi(e)}}import x from"typescript";var qt=new Set(["test","describe","it"]);function ur(e,t){Vi(e,t),Zi(e,t),Yi(e,t),qi(e,t)}function Vi(e,t){if((x.isFunctionDeclaration(e)||x.isVariableDeclaration(e))&&e.name&&x.isIdentifier(e.name)&&Xi(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 Xi(e){if(x.isFunctionDeclaration(e))return x.isSourceFile(e.parent);let t=e.parent?.parent;return!!t&&x.isSourceFile(t.parent)}function Zi(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 Yi(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 qi(e,t){if(x.isCallExpression(e)&&to(e.expression))for(let r of e.arguments)x.isObjectLiteralExpression(r)&&eo(r,t)}function to(e){return x.isIdentifier(e)?qt.has(e.text):!!(x.isPropertyAccessExpression(e)&&(qt.has(e.name.text)||x.isIdentifier(e.expression)&&qt.has(e.expression.text)))}function eo(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 te(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=ie=>{io(ie,a),l.forEachChild(ie,c)};c(o);let p=yo(e,a);(p==="test"||p==="barrel")&&i.add({name:p,kind:"comment-marker"}),p!=="test"&&xo(a,o);let g=o.statements[0],u=g?hr(g):void 0,{complexity:y,cognitiveComplexity:b}=Yt(o),B=ro(o);return{imports:s,exports:Array.from(n.values()),tags:Array.from(i),category:p,rawCallEdges:a.rawCallEdges??[],complexity:y,cognitiveComplexity:b,...B.length>0?{functions:B}:{},...u!==void 0?{description:u}:{}}}function ro(e){let t=[],r=(n,i)=>{let{complexity:o,cognitiveComplexity:a}=Yt(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 dr(e,t,r,s){let n={name:e},i=hr(r);i!==void 0&&(n.doc=i);let o=so(t);o!==void 0&&(n.flags=o);let a=no(t,s);return a!==void 0&&(n.signature=a),n}function hr(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 so(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 no(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 io(e,t){oo(e,t),ao(e,t),po(e,t),lo(e,t),ho(e,t),ur(e,t)}function oo(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)||ee(s)).length}function ao(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)&&!co(e)&&(t.hasTypesOnly=!1)}function co(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:E(e.moduleSpecifier.text),type:s,symbols:r.length>0?r:void 0})}function lo(e,t){l.isExportDeclaration(e)?fo(e,t):l.isExportAssignment(e)?t.exports.set("default",{name:"default"}):ee(e)&&go(e,t)}function fo(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=uo(e),n={fromPath:r.filePath,toPath:"",rawSpecifier:t,isStyle:E(t),type:"re-export"};s.length>0&&(n.symbols=s),r.imports.push(n)}function uo(e){return e.exportClause?l.isNamedExports(e.exportClause)?e.exportClause.elements.map(t=>t.name.text):[]:["*"]}function go(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,dr(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,dr(n,s,e,t.sourceFile))}}}function ho(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:E(r.text),type:"dynamic"}):l.isIdentifier(e.expression)&&e.expression.text==="require"&&t.imports.push({fromPath:t.filePath,toPath:"",rawSpecifier:r.text,isStyle:E(r.text),type:"require"}))}function yo(e,t){let r=gr.basename(e).toLowerCase(),s=gr.extname(e).toLowerCase();return U().some(i=>r.includes(i))?"test":ae(r)?"config":t.imports.some(i=>Pt().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>It()?"barrel":"logic"}function ee(e){return l.canHaveModifiers(e)&&l.getModifiers(e)?.some(t=>t.kind===l.SyntaxKind.ExportKeyword)===!0}function xo(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=bo(n);if(i){let o=vo(n);o&&Ct(o,i,s,r);continue}l.isClassDeclaration(n)&&n.name&&So(n,s,r)}}function So(e,t,r){let s=e.name.text;for(let n of e.members)l.isMethodDeclaration(n)&&n.body&&l.isIdentifier(n.name)?Ct(n.body,`${s}.${n.name.text}`,t,r):l.isConstructorDeclaration(n)&&n.body&&Ct(n.body,`${s}.constructor`,t,r)}function bo(e){if(ee(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 vo(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 Ct(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=>Ct(n,t,r,s))}function Et(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 xr from"postcss";import*as ko from"postcss-less";var Co=ko,Sr=new Set(["reference","inline"]);function yr(e){return e.startsWith("~")||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")||e.startsWith("data:")}function Eo(e){let t=e.trim();return t.length>0&&!t.startsWith("http://")&&!t.startsWith("https://")&&!t.startsWith("//")&&!t.startsWith("data:")&&!t.startsWith("#")}function wo(e,t){let r=e.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let i=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=Sr.has(i)?"side-effect":"static";return{fromPath:t,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...yr(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",...yr(n)?{isExternal:!0}:{}}:null}function Fo(e,t){let r=[],s=/url\(['"]?([^'")]+)['"]?\)/g,n=s.exec(e);for(;n!==null;){let i=n[1]?.trim()??"";Eo(i)&&r.push({fromPath:t,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),n=s.exec(e)}return r}function br(e,t){let r=[];return e.walk(s=>{if(s.type==="atrule"&&s.name==="import"){let n=wo(s.params,t);n&&r.push(n)}s.type==="decl"&&r.push(...Fo(s.value,t))}),r}function Po(e){return e.replace(/(?<!:)\/\/.*/g,"")}function To(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=Sr.has(i)?"side-effect":"static";r.push({fromPath:t,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}n=s.exec(e)}return r}function vr(e,t){let r=xr.parse(Po(e));return{imports:br(r,t),root:r}}function kr(e,t){try{let r=Co.parse(e);return{imports:br(r,t),root:r}}catch{return{imports:To(e,t),root:xr.parse("")}}}import{parse as Io}from"postcss-scss";function No(e){return!!(e.startsWith("sass:")||e.startsWith("~")||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")||!e.startsWith(".")&&!e.startsWith("/")&&!e.startsWith("_"))}function Mo(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 Cr(e,t){let r=Io(e),s=[];return r.walk(n=>{if(n.type!=="atrule")return;let{name:i,params:o}=n;if(i!=="import"&&i!=="use"&&i!=="forward")return;let{specifier:a,alias:c}=Mo(o);if(!a)return;let p={fromPath:t,toPath:"",rawSpecifier:a,isStyle:!0,type:i==="forward"?"re-export":"static",...No(a)?{isExternal:!0}:{}};c&&(p.symbols=[c]),s.push(p)}),{imports:s,root:r}}function Er(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 wr(e,t){if(t.length===0)return"ui";try{let r=Ft("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 q(e,t){let r=P(e);if(r==="stylus"){let i=Er(t,e);return{imports:i,exports:[],tags:[],category:wr(t,i)}}if(r==="scss"){let{imports:i,root:o}=Cr(t,e);return{imports:i,exports:[],tags:[],category:Et(o,i)}}if(r==="less"){let{imports:i,root:o}=kr(t,e);return{imports:i,exports:[],tags:[],category:Et(o,i)}}let{imports:s,root:n}=vr(t,e);return{imports:s,exports:[],tags:[],category:Et(n,s)}}for(let[e,t]of[["javascript",(r,s)=>te(r,s,"javascript")],["typescript",(r,s)=>te(r,s,"typescript")],["css",q],["scss",q],["less",q],["stylus",q],["coffeescript",nr],["livescript",ar],["lua",cr],["python",mr],["go",or],["gherkin",Xt],["markdown",fr]])R(e,t);async function Fr(e,t){let r=P(e),s=Le(r);return s?s(e,t):{imports:[],exports:[],tags:[],category:"other"}}import Pr from"path";function Ir(e,t){for(let r of e.values()){let s=t.get(r.path);s!==void 0&&(r.coveragePct=s)}}function Nr(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 Mr(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 Dr(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 Tr(e){return Math.round(e*1e4)/1e4}function Rr(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=Tr(Math.min(1,i)),r.push(s.exportUsageRatio)}r.length>0&&(t.avgExportUsage=Tr(r.reduce((s,n)=>s+n,0)/r.length),t.maxExportUsage=Math.max(...r))}}function re(e,t,r){t&&(e.some(s=>s.name===t&&s.kind===r)||e.push({name:t,kind:r}))}function Do(e,t){let r=t.toPath,s=Pr.basename(r,Pr.extname(r)).replace(/\.(test|spec)$/,"");re(e.tags,s,"import")}function Ro(e,t){if(!(!t.symbols||t.symbols.includes("*")))for(let r of t.symbols)re(e.tags,r,"import")}function Ao(e,t,r){let s=r.get(t.toPath);if(!(!s||s.category==="test"))for(let n of s.tags)n.kind==="comment-marker"&&re(e.tags,n.name,"comment-marker")}function Ar(e){for(let t of e.values())if(t.category==="test")for(let r of t.imports)!r.toPath||r.isExternal||(Do(t,r),Ro(t,r),Ao(t,r,e))}import wt from"fs";import T from"path";import jr from"fs";import z from"path";var tt=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 Gr(a);if(r!==i&&!r.startsWith(`${i}/`))return null;let c=r.slice(i.length).replace(/^\//,"");return c?Gr(z.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=jr.readFileSync(z.join(t,"go.mod"),"utf-8"),i=Lo(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 z.join(i,o)}}}};function Lo(e,t){let r=e.split(`
|
|
21
|
-
`),s=null,n=new Map,i=!1;for(let o of r){let a=o.trim();if(a.startsWith("module ")){s=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){i=!0;continue}if(i&&a===")"){i=!1;continue}if(i&&a.includes("=>")){
|
|
17
|
+
`+g}};function Hn(e){let t=e.split(`
|
|
18
|
+
`),r=-1;for(let n=0;n<t.length;n++){let i=t[n].trimStart();(i.startsWith("import ")||i.startsWith("from "))&&(r=n)}if(r<0)return 0;let s=0;for(let n=0;n<=r;n++)s+=t[n].length+1;return s}import Je from"path";import He from"typescript";var Qn=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,St=class{name="vitest";canHandle(t){return w.has(Je.extname(t).toLowerCase())}apply(t,r,s){let n=r.replace(Qn,""),i=He.createSourceFile(Je.basename(t),n,He.ScriptTarget.Latest,!0),o=A(i);if(o.length===0)return n;let a=L(o[0],"tags",i),c=[...s].sort();if(a!==null&&JSON.stringify([...a].sort())===JSON.stringify(c))return n;let p=o.flatMap(g=>{let u=s.length===0?j(g,"tags",i):G(g,"tags",W(c),i);return u?[u]:[]});return p.length>0?O(n,p):n}};var Qe={vitest:()=>new St,playwright:()=>new yt,cypress:()=>new ut,jest:()=>new ht},Vn={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function Xn(e){let t=bt.createSourceFile("detect.ts",e,bt.ScriptTarget.Latest,!0);for(let r of t.statements){if(!bt.isImportDeclaration(r)||!bt.isStringLiteral(r.moduleSpecifier))continue;let s=Vn[r.moduleSpecifier.text];if(s)return s}return null}var Qt=class{constructor(t,r,s){this.rootDir=t;this.defaultFramework=r;this.frameworkOverrides=s}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(t){return w.has(Ht.extname(t).toLowerCase())}apply(t,r,s){let n=Xn(r)??this.matchOverride(t)??this.defaultFramework;return(Qe[n]??Qe.vitest)().apply(t,r,s)}matchOverride(t){let r=Ht.relative(this.rootDir,t).split(Ht.sep).join("/");for(let[s,n]of this.frameworkOverrides)if(Be(s,r))return n;return null}};function Ve(e="vitest",t={},r=process.cwd()){return[new gt,new xt,new dt,new Qt(r,e,Object.entries(t))]}function Xe(e,t){return t.find(r=>r.canHandle(e))??null}var Zn=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,qn=new Set(["import"]),ti=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function ei(e,t,r,s){let n;try{n=await Ye.readFile(e,"utf8")}catch(a){return{path:e,status:"error",error:String(a)}}let i=Xe(e,s);if(!i)return{path:e,status:"unchanged"};let o=i.apply(e,n,t);return o===n?{path:e,status:"unchanged"}:(r||await Ye.writeFile(e,o,"utf8"),{path:e,status:"updated"})}async function ri(e,t,r){let s=Nt(t),n=s.tagApplier?.framework??"vitest",i=s.tagApplier?.frameworkOverrides??{},o=Ve(n,i,t),a={updated:0,unchanged:0,errors:0,files:[]};for(let c of e.nodes.values()){if(c.category!=="test")continue;let p=new Set,g=[];for(let b of c.tags)qn.has(b.kind)&&Zn.test(b.name)&&(ti.has(b.name.toLowerCase())||p.has(b.name)||(p.add(b.name),g.push(b.name)));g.sort();let u=Yn.resolve(t,c.path),y=await ei(u,g,r.dryRun,o);y.path=c.path,a.files.push(y),y.status==="updated"?a.updated++:y.status==="unchanged"?a.unchanged++:a.errors++}return a}var vt=class{isTestNode(t){return t.category==="test"||t.tags.some(r=>r.name==="test")}};import it from"fs";import k from"path";import Bo from"piscina";import{execFileSync as Ze}from"child_process";var qe="%x00%H%x09%ae%x09%at",tr=256*1024*1024;function er(e,t){let r="",s=0;for(let n of e.split(`
|
|
19
|
+
`)){if(n.startsWith("\0")){let[,c,p]=n.slice(1).split(" ");r=c??"",s=p?Number(p)*1e3:0;continue}if(n==="")continue;let i=n.split(" "),o=i[0];if(!o)continue;let a=o.startsWith("R")||o.startsWith("C")?i[2]:i[1];a&&t(a,r,s)}}function rr(e){let t=new Map;try{let r=Ze("git",["-C",e,"log","--since=90 days ago","--name-status","-M",`--format=${qe}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:tr});er(r,(s,n,i)=>{let o=t.get(s);if(o){o.commitCount90d+=1;return}t.set(s,{commitCount90d:1,lastAuthor:n||void 0,lastCommitAt:i||void 0})})}catch{return t}try{let r=Ze("git",["-C",e,"log","--name-status","-M",`--format=${qe}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:tr});er(r,(s,n,i)=>{t.has(s)||t.set(s,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:i||void 0})})}catch{}return t}import kt from"fs";import si from"path";import{load as sr}from"js-yaml";function nr(e){let t=e.lastIndexOf("@");return t>0?e.substring(0,t):e}function ni(e){return e.replace(/:$/,"").split(",").map(t=>{let r=t.trim();return r.startsWith('"')&&(r=r.slice(1)),r.endsWith('"')&&(r=r.slice(0,-1)),nr(r)}).filter(Boolean)}function ii(e,t){let r=e.startsWith("/")?e.slice(1):e,s=r.lastIndexOf("@");return s>0?{name:r.substring(0,s),version:t||r.substring(s+1)}:{name:r,version:t}}function oi(e){try{let t=sr(e),r={dependencies:{}};for(let[s,n]of Object.entries(t))if(!(s==="__metadata"||!n?.version))for(let i of s.split(", ")){let o=nr(i);o&&(r.dependencies[o]={version:n.version,...n.dependencies!==void 0&&{dependencies:n.dependencies}})}return r}catch{return null}}function ai(e){let t={dependencies:{}};for(let r of e.split(/\n\n+/)){let s=r.split(`
|
|
20
|
+
`).filter(c=>c.trim().length>0&&!c.trim().startsWith("#"));if(s.length<2)continue;let n=s[0];if(!n||n.startsWith(" "))continue;let i=ni(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 ci(e){let t=kt.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 pi(e){let t=kt.readFileSync(e,"utf-8");if(t.includes("__metadata:")){let r=oi(t);if(r!==null)return r}return ai(t)}function li(e){let t=kt.readFileSync(e,"utf-8"),r={dependencies:{}};try{let s=sr(t);if(s.packages)for(let[n,i]of Object.entries(s.packages)){let{name:o,version:a}=ii(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 ir(e){let t=[["package-lock.json",ci],["yarn.lock",pi],["pnpm-lock.yaml",li]];for(let[r,s]of t){let n=si.join(e,r);if(kt.existsSync(n))return s(n)}return null}import or from"path";function P(e){switch(or.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 C(e){let t=or.extname(e).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(t)}import fi from"coffeescript";function mi(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 ui(e,t){let r=e.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||t.has("test")?"test":"logic"}function gi(e,t){let r=t.source?.value;return r?{fromPath:e,toPath:"",rawSpecifier:r,isStyle:C(r),type:"static"}:null}function di(e,t){let r=t.variable?.base?.value==="require",s=t.args?.[0]?.base?.value;return!r||!s?null:{fromPath:e,toPath:"",rawSpecifier:s,isStyle:C(s),type:"require"}}function hi(e,t,r){let s=t.constructor?.name;if(s==="ImportDeclaration"){let n=gi(e,t);n&&r.push(n)}else if(s==="Call"){let n=di(e,t);n&&r.push(n)}}function Vt(e,t,r){if(!(!t||typeof t!="object")){hi(e,t,r);for(let s in t){if(s==="locationData")continue;let n=t[s];if(!(!n||typeof n!="object"))if(Array.isArray(n))for(let i of n)Vt(e,i,r);else Vt(e,n,r)}}}function ar(e,t){let r=mi(t),s=ui(e,r),n=[];try{Vt(e,fi.nodes(t),n)}catch{}return{imports:n,exports:[],tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:s}}import{AstBuilder as yi,GherkinClassicTokenMatcher as xi,Parser as Si}from"@cucumber/gherkin";import{IdGenerator as bi}from"@cucumber/messages";var vi=bi.uuid();function Xt(e,t){let r=new Set;try{let s=new yi(vi),n=new xi,o=new Si(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"}}D("gherkin",Xt);import ki from"path";import{parser as Ei}from"@lezer/go";var Ci=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,wi=/^\/\/go:build\s+(.+)$/,Fi=/^\/\/\s*\+build\s+(.+)$/;function pr(e,t){let r=[],s=new Map,n=new Set,i=new Set,a=Ei.parse(t).cursor();do switch(a.name){case"LineComment":{let u=t.slice(a.from,a.to),y=u.match(Ci);y?.[1]&&n.add(y[1]);let b=u.match(wi);b&&cr(b[1],i);let B=u.match(Fi);B&&cr(B[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=ki.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 cr(e,t){for(let r of e.split(/[\s,&|!()]+/)){let s=r.trim();s&&s!=="ignore"&&t.add(s)}}import Pi from"livescript";function _(e){return e.startsWith("'")||e.startsWith('"')?e.slice(1,-1):e}function Ti(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 Ii(e,t){let r=e.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||t.has("test")?"test":"logic"}var Mi=new Set(["first_line","first_column","last_line","last_column","line","column"]);function Ni(e,t){let r=e.constructor?.name||e.type;if(r==="Import"){let s=e.right?.value;if(typeof s=="string"){let n=_(s);return{fromPath:t,toPath:"",rawSpecifier:n,isStyle:C(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=_(n);return{fromPath:t,toPath:"",rawSpecifier:i,isStyle:C(i),type:"require"}}}}return null}function Yt(e,t){if(!e||typeof e!="object")return[];let r=[],s=Ni(e,t);s&&r.push(s);for(let n in e){if(Mi.has(n))continue;let i=e[n];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let o of i)r.push(...Yt(o,t));else r.push(...Yt(i,t))}return r}function lr(e,t){let r=Ti(t),s=Ii(e,r),n=[];try{n=Yt(Pi.ast(t),e)}catch{}return{imports:n,exports:[],tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:s}}import Ri from"luaparse";function Di(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 Ai(e,t){let r=e.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||t.has("test")?"test":"logic"}function Li(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=_(o.raw))}else if(n.type==="StringCallExpression"){let o=n.argument;o?.type==="StringLiteral"&&(i=_(o.raw))}i&&r.push({fromPath:t,toPath:"",rawSpecifier:i,isStyle:C(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 fr(e,t){let r=Di(t),s=Ai(e,r),n=[];try{let i=Ri.parse(t);n=Li(i,e)}catch{}return{imports:n,exports:[],tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:s}}var Gi=["http://","https://","mailto:","//"],ji="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",Oi=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${ji})\\b`,"g"),mr;async function Wi(){return mr??=(async()=>{let{unified:e}=await import("unified"),t=(await import("remark-parse")).default;return e().use(t)})(),mr}function _i(e){let t=e.trim();return t.length===0||t.startsWith("#")||Gi.some(r=>t.startsWith(r))}function $i(e,t){let r=e.match(Oi);return r?r.map(s=>({fromPath:t,toPath:"",rawSpecifier:s,isStyle:!1,type:"static"})):[]}function ur(e,t,r){if(e.type==="link"&&typeof e.url=="string"&&!_i(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(...$i(e.value,t)),Array.isArray(e.children))for(let s of e.children)ur(s,t,r)}async function gr(e,t){let s=(await Wi()).parse(t),n=[];ur(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 zi from"path";import{parser as Bi}from"@lezer/python";var Ui=new Set(["pytest","unittest","nose","hypothesis"]);function dr(e,t){let r=[],s=[],n=new Set,i=zi.basename(e).toLowerCase(),a=Bi.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 Ki(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=Vi(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 Ki(e,t,r){let s=e.firstChild;return s?s.name==="from"?Ji(e,t,r):Hi(e,t,r):[]}function Ji(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=Qi(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[Z(r,i,o,!0)];let p=a===1?"./":"../".repeat(a-1);return c?[Z(r,p+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[Z(r,p.slice(0,-1),["*"],!1)]:o.map(g=>Z(r,p+g,[g],!1))}function Hi(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(Z(r,i,["*"],!0))}n=n.nextSibling}return s}function Qi(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 Z(e,t,r,s){return{fromPath:e,toPath:"",rawSpecifier:t,isStyle:!1,isExternal:s,type:"static",symbols:r.length>0?r:void 0}}function Vi(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=>Ui.has(s.rawSpecifier))?"test":"logic"}import yr from"path";import l from"typescript";import d from"typescript";function Xi(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 Yi(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 Zt(e){return{complexity:Xi(e),cognitiveComplexity:Yi(e)}}import x from"typescript";var qt=new Set(["test","describe","it"]);function hr(e,t){Zi(e,t),to(e,t),eo(e,t),ro(e,t)}function Zi(e,t){if((x.isFunctionDeclaration(e)||x.isVariableDeclaration(e))&&e.name&&x.isIdentifier(e.name)&&qi(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 qi(e){if(x.isFunctionDeclaration(e))return x.isSourceFile(e.parent);let t=e.parent?.parent;return!!t&&x.isSourceFile(t.parent)}function to(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 eo(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 ro(e,t){if(x.isCallExpression(e)&&so(e.expression))for(let r of e.arguments)x.isObjectLiteralExpression(r)&&no(r,t)}function so(e){return x.isIdentifier(e)?qt.has(e.text):!!(x.isPropertyAccessExpression(e)&&(qt.has(e.name.text)||x.isIdentifier(e.expression)&&qt.has(e.expression.text)))}function no(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 te(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=ie=>{co(ie,a),l.forEachChild(ie,c)};c(o);let p=bo(e,a);(p==="test"||p==="barrel")&&i.add({name:p,kind:"comment-marker"}),p!=="test"&&vo(a,o);let g=o.statements[0],u=g?Sr(g):void 0,{complexity:y,cognitiveComplexity:b}=Zt(o),B=io(o);return{imports:s,exports:Array.from(n.values()),tags:Array.from(i),category:p,rawCallEdges:a.rawCallEdges??[],complexity:y,cognitiveComplexity:b,...B.length>0?{functions:B}:{},...u!==void 0?{description:u}:{}}}function io(e){let t=[],r=(n,i)=>{let{complexity:o,cognitiveComplexity:a}=Zt(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 xr(e,t,r,s){let n={name:e},i=Sr(r);i!==void 0&&(n.doc=i);let o=oo(t);o!==void 0&&(n.flags=o);let a=ao(t,s);return a!==void 0&&(n.signature=a),n}function Sr(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 oo(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 ao(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 co(e,t){po(e,t),lo(e,t),mo(e,t),uo(e,t),So(e,t),hr(e,t)}function po(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)||ee(s)).length}function lo(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)&&!fo(e)&&(t.hasTypesOnly=!1)}function fo(e){return e.isTypeOnly?!0:!e.exportClause||!l.isNamedExports(e.exportClause)?!1:e.exportClause.elements.every(t=>t.isTypeOnly)}function mo(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:C(e.moduleSpecifier.text),type:s,symbols:r.length>0?r:void 0})}function uo(e,t){l.isExportDeclaration(e)?go(e,t):l.isExportAssignment(e)?t.exports.set("default",{name:"default"}):ee(e)&&xo(e,t)}function go(e,t){if(e.moduleSpecifier&&l.isStringLiteral(e.moduleSpecifier))ho(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 ho(e,t,r){let s=yo(e),n={fromPath:r.filePath,toPath:"",rawSpecifier:t,isStyle:C(t),type:"re-export"};s.length>0&&(n.symbols=s),r.imports.push(n)}function yo(e){return e.exportClause?l.isNamedExports(e.exportClause)?e.exportClause.elements.map(t=>t.name.text):[]:["*"]}function xo(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,xr(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,xr(n,s,e,t.sourceFile))}}}function So(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:C(r.text),type:"dynamic"}):l.isIdentifier(e.expression)&&e.expression.text==="require"&&t.imports.push({fromPath:t.filePath,toPath:"",rawSpecifier:r.text,isStyle:C(r.text),type:"require"}))}function bo(e,t){let r=yr.basename(e).toLowerCase(),s=yr.extname(e).toLowerCase();return U().some(i=>r.includes(i))?"test":ae(r)?"config":t.imports.some(i=>Pt().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>It()?"barrel":"logic"}function ee(e){return l.canHaveModifiers(e)&&l.getModifiers(e)?.some(t=>t.kind===l.SyntaxKind.ExportKeyword)===!0}function vo(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=Eo(n);if(i){let o=Co(n);o&&Et(o,i,s,r);continue}l.isClassDeclaration(n)&&n.name&&ko(n,s,r)}}function ko(e,t,r){let s=e.name.text;for(let n of e.members)l.isMethodDeclaration(n)&&n.body&&l.isIdentifier(n.name)?Et(n.body,`${s}.${n.name.text}`,t,r):l.isConstructorDeclaration(n)&&n.body&&Et(n.body,`${s}.constructor`,t,r)}function Eo(e){if(ee(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 Co(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 Et(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=>Et(n,t,r,s))}function Ct(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 vr from"postcss";import*as wo from"postcss-less";var Fo=wo,kr=new Set(["reference","inline"]);function br(e){return e.startsWith("~")||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")||e.startsWith("data:")}function Po(e){let t=e.trim();return t.length>0&&!t.startsWith("http://")&&!t.startsWith("https://")&&!t.startsWith("//")&&!t.startsWith("data:")&&!t.startsWith("#")}function To(e,t){let r=e.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let i=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=kr.has(i)?"side-effect":"static";return{fromPath:t,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...br(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",...br(n)?{isExternal:!0}:{}}:null}function Io(e,t){let r=[],s=/url\(['"]?([^'")]+)['"]?\)/g,n=s.exec(e);for(;n!==null;){let i=n[1]?.trim()??"";Po(i)&&r.push({fromPath:t,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),n=s.exec(e)}return r}function Er(e,t){let r=[];return e.walk(s=>{if(s.type==="atrule"&&s.name==="import"){let n=To(s.params,t);n&&r.push(n)}s.type==="decl"&&r.push(...Io(s.value,t))}),r}function Mo(e){return e.replace(/(?<!:)\/\/.*/g,"")}function No(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=kr.has(i)?"side-effect":"static";r.push({fromPath:t,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}n=s.exec(e)}return r}function Cr(e,t){let r=vr.parse(Mo(e));return{imports:Er(r,t),root:r}}function wr(e,t){try{let r=Fo.parse(e);return{imports:Er(r,t),root:r}}catch{return{imports:No(e,t),root:vr.parse("")}}}import{parse as Ro}from"postcss-scss";function Do(e){return!!(e.startsWith("sass:")||e.startsWith("~")||e.startsWith("http://")||e.startsWith("https://")||e.startsWith("//")||!e.startsWith(".")&&!e.startsWith("/")&&!e.startsWith("_"))}function Ao(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 Fr(e,t){let r=Ro(e),s=[];return r.walk(n=>{if(n.type!=="atrule")return;let{name:i,params:o}=n;if(i!=="import"&&i!=="use"&&i!=="forward")return;let{specifier:a,alias:c}=Ao(o);if(!a)return;let p={fromPath:t,toPath:"",rawSpecifier:a,isStyle:!0,type:i==="forward"?"re-export":"static",...Do(a)?{isExternal:!0}:{}};c&&(p.symbols=[c]),s.push(p)}),{imports:s,root:r}}function Pr(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 Tr(e,t){if(t.length===0)return"ui";try{let r=Ft("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 q(e,t){let r=P(e);if(r==="stylus"){let i=Pr(t,e);return{imports:i,exports:[],tags:[],category:Tr(t,i)}}if(r==="scss"){let{imports:i,root:o}=Fr(t,e);return{imports:i,exports:[],tags:[],category:Ct(o,i)}}if(r==="less"){let{imports:i,root:o}=wr(t,e);return{imports:i,exports:[],tags:[],category:Ct(o,i)}}let{imports:s,root:n}=Cr(t,e);return{imports:s,exports:[],tags:[],category:Ct(n,s)}}for(let[e,t]of[["javascript",(r,s)=>te(r,s,"javascript")],["typescript",(r,s)=>te(r,s,"typescript")],["css",q],["scss",q],["less",q],["stylus",q],["coffeescript",ar],["livescript",lr],["lua",fr],["python",dr],["go",pr],["gherkin",Xt],["markdown",gr]])D(e,t);async function Ir(e,t){let r=P(e),s=Le(r);return s?s(e,t):{imports:[],exports:[],tags:[],category:"other"}}import Mr from"path";function Rr(e,t){for(let r of e.values()){let s=t.get(r.path);s!==void 0&&(r.coveragePct=s)}}function Dr(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 Ar(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 Lr(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 Nr(e){return Math.round(e*1e4)/1e4}function Gr(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=Nr(Math.min(1,i)),r.push(s.exportUsageRatio)}r.length>0&&(t.avgExportUsage=Nr(r.reduce((s,n)=>s+n,0)/r.length),t.maxExportUsage=Math.max(...r))}}function re(e,t,r){t&&(e.some(s=>s.name===t&&s.kind===r)||e.push({name:t,kind:r}))}function Lo(e,t){let r=t.toPath,s=Mr.basename(r,Mr.extname(r)).replace(/\.(test|spec)$/,"");re(e.tags,s,"import")}function Go(e,t){if(!(!t.symbols||t.symbols.includes("*")))for(let r of t.symbols)re(e.tags,r,"import")}function jo(e,t,r){let s=r.get(t.toPath);if(!(!s||s.category==="test"))for(let n of s.tags)n.kind==="comment-marker"&&re(e.tags,n.name,"comment-marker")}function jr(e){for(let t of e.values())if(t.category==="test")for(let r of t.imports)!r.toPath||r.isExternal||(Lo(t,r),Go(t,r),jo(t,r,e))}import wt from"fs";import T from"path";import _r from"fs";import $ from"path";var tt=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 Wr(a);if(r!==i&&!r.startsWith(`${i}/`))return null;let c=r.slice(i.length).replace(/^\//,"");return c?Wr($.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=_r.readFileSync($.join(t,"go.mod"),"utf-8"),i=Oo(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 $.join(i,o)}}}};function Oo(e,t){let r=e.split(`
|
|
21
|
+
`),s=null,n=new Map,i=!1;for(let o of r){let a=o.trim();if(a.startsWith("module ")){s=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){i=!0;continue}if(i&&a===")"){i=!1;continue}if(i&&a.includes("=>")){Or(a,t,n);continue}!i&&/^replace\s+/.test(a)&&a.includes("=>")&&Or(a.replace(/^replace\s+/,""),t,n)}return{mod:s,replaces:n}}function Or(e,t,r){let[s,n]=e.split("=>").map(a=>a.trim());if(!s||!n)return;let i=s.split(/\s+/)[0];if(!n.startsWith(".")&&!n.startsWith("/"))return;let o=$.isAbsolute(n)?n:$.resolve(t,n);r.set(i,o)}function Wr(e){let t;try{t=_r.readdirSync(e,{withFileTypes:!0})}catch{return null}let r=t.filter(s=>s.isFile()&&s.name.endsWith(".go")&&!s.name.endsWith("_test.go")).map(s=>({path:$.join(e,s.name),isExternal:!1})).sort((s,n)=>s.path.localeCompare(n.path));return r.length>0?r:null}import Wo from"fs";import se from"path";var et=class{extensions=[".lua"];resolve(t,r,s,n){let i=r.replace(/\./g,se.sep),o=[s,se.join(s,"lib")];for(let a of o){if(!Wo.existsSync(a))continue;let c=n(se.join(a,"_dummy.lua"),i);if(c)return[c]}return null}};import _o from"path";var rt=class{extensions=[".md",".mdx"];resolve(t,r,s,n){let i=n(_o.join(s,"_dummy"),`./${r}`);return i?[i]:null}};import $o from"fs";import ne from"path";var st=class{extensions=[".py"];resolve(t,r,s,n){let i=r.replace(/\./g,ne.sep),o=ne.join(s,`${i}.py`);if($r(o))return[{path:o,isExternal:!1}];let a=ne.join(s,i,"__init__.py");return $r(a)?[{path:a,isExternal:!1}]:null}};function $r(e){try{return $o.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import zr from"path";var zo=["~","http://","https://","//","data:","sass:"],nt=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(t,r,s,n){if(zo.some(g=>r.startsWith(g)))return null;let i=n(t,r);if(i)return[i];let o=zr.dirname(r),a=zr.basename(r),c=o==="."?`_${a}`:`${o}/_${a}`,p=n(t,c);return p?[p]:null}};var z=class{constructor(t,r={}){this.rootDir=t;this.workspaceMap=r.workspaceMap??new Map,this.tsconfigSearchPaths=r.tsconfigSearchPaths??[t],this.langResolvers=r.langResolvers??[new st,new et,new tt,new nt,new rt]}rootDir;workspaceMap;tsconfigSearchPaths;langResolvers;resolveAll(t,r){let s=this.resolvePathAlias(r);if(s)return[s];if(r.startsWith(".")||r.startsWith("/")){let o=this.resolveLocalPath(t,r);return o?[o]:[]}let n=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>t.endsWith(a))){let a=o.resolve(t,r,this.rootDir,n);if(a)return a}let i=this.resolveWorkspaceImport(r);return i?[i]:[{path:r,isExternal:!0}]}resolve(t,r){let s=this.resolvePathAlias(r);if(s)return s;if(r.startsWith(".")||r.startsWith("/"))return this.resolveLocalPath(t,r);let n=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>t.endsWith(a))){let a=o.resolve(t,r,this.rootDir,n);if(a)return a[0]??null}let i=this.resolveWorkspaceImport(r);return i||{path:r,isExternal:!0}}resolveLocalPath(t,r){let s=T.dirname(t),n=r.startsWith("/")?r:T.resolve(s,r),i=!n.startsWith(this.rootDir),o=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature",".md",".mdx"],a=n.match(/\.(js|mjs|cjs)$/);if(a){let c=n.slice(0,-a[0].length);for(let p of[".ts",".tsx"]){let g=this.tryExtensions(c,p,i);if(g)return g}}for(let c of o){let p=this.tryExtensions(n,c,i);if(p)return p}return i?{path:n,isExternal:!0}:null}tryExtensions(t,r,s){let n=t+r;if(this.isFile(n))return{path:n,isExternal:s};let i=T.join(t,`index${r}`);if(this.isFile(i))return{path:i,isExternal:s};if(r===".py"){let o=T.join(t,"__init__.py");if(this.isFile(o))return{path:o,isExternal:s}}return null}isFile(t){try{return wt.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(t){for(let r of this.tsconfigSearchPaths){let s=T.join(r,"tsconfig.json");if(wt.existsSync(s))try{let i=JSON.parse(wt.readFileSync(s,"utf-8")).compilerOptions?.paths;if(!i)continue;for(let o in i){let a=this.matchAliasPattern(o,t);if(a){let c=this.tryAliasSubstitutions(i[o],a[1]||"",r);if(c)return c}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(t,r){let s=this.aliasRegexCache.get(t);if(!s){let n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");s=new RegExp(`^${n}$`),this.aliasRegexCache.set(t,s)}return r.match(s)}tryAliasSubstitutions(t,r,s=this.rootDir){let n=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let i of t){let o=i.replace("*",r),a=T.resolve(s,o);for(let c of n){let p=this.tryExtensions(a,c,!1);if(p)return p}}return null}resolveWorkspaceImport(t){if(this.workspaceMap.size===0)return null;for(let[r,s]of this.workspaceMap){if(t!==r&&!t.startsWith(`${r}/`))continue;let n=t.slice(r.length),i={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:r};if(!n){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let c=T.join(s,a);try{if(wt.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...i,path:c}}catch{}}return{...i,path:s}}let o=this.resolveLocalPath(T.join(s,"_dummy"),n.slice(1));return o?{...i,path:o.path}:null}return null}};var Uo=["tests","test","__tests__","specs","spec"],Br=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),Ko=20;function Jo(e,t){if(e.length===0)return t;let r=e.map(o=>k.dirname(o).split(k.sep)),s=r[0];for(let o of r.slice(1)){let a=0;for(;a<s.length&&a<o.length&&s[a]===o[a];)a++;s=s.slice(0,a)}let n=s.join(k.sep)||k.sep,i=k.relative(t,n);return i.startsWith("..")||k.isAbsolute(i)?t:n}var ot=class{constructor(t,r=null,s,n,i=!1,o=new Map,a=!0){this.rootDir=t;this.enableGitStats=i;this.coverageMap=o;this.parallelParsing=a;this.previousGraph=r,this.resolver=s||new z(t),this.lockFile=ir(t),n&&(this.progressCallback=n)}rootDir;enableGitStats;coverageMap;parallelParsing;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;async build(t){let r=t.map(s=>k.isAbsolute(s)?s:k.resolve(this.rootDir,s));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=rr(this.rootDir));try{for(let s of r)this.enqueue(s);return await this.drain(),await this.processTestFiles(Jo(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
|
|
22
22
|
Done. Total processed: ${this.visited.size} nodes.
|
|
23
|
-
`),
|
|
23
|
+
`),jr(this.graph.nodes),Ar(this.graph.nodes),Gr(this.graph.nodes),Lr(this.graph.nodes),this.coverageMap.size>0&&Rr(this.graph.nodes,this.coverageMap),new I(this.graph.nodes)}finally{this.pool&&(await this.pool.destroy(),this.pool=null)}}async initPool(){if(this.parallelParsing===!1)return;let t=typeof this.parallelParsing=="object"?this.parallelParsing:{},r=t.minFiles??Ko;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r)))try{let s=k.join(f,"parse-worker.js");this.pool=new Bo({filename:s,...t.maxThreads!==void 0?{maxThreads:t.maxThreads}:{}})}catch(s){process.stderr.write(`
|
|
24
24
|
Warning: failed to start parse worker pool, falling back to synchronous parsing: ${s}
|
|
25
|
-
`),this.pool=null}}hasAtLeastFiles(t,r){let s=0,n=[t];for(;n.length>0;){let i=n.pop(),o;try{o=it.readdirSync(i,{withFileTypes:!0})}catch{continue}for(let a of o)if(a.isDirectory())
|
|
25
|
+
`),this.pool=null}}hasAtLeastFiles(t,r){let s=0,n=[t];for(;n.length>0;){let i=n.pop(),o;try{o=it.readdirSync(i,{withFileTypes:!0})}catch{continue}for(let a of o)if(a.isDirectory())Br.has(a.name)||n.push(k.join(i,a.name));else if(a.isFile()&&(s++,s>=r))return!0}return s>=r}async processTestFiles(t){let r=U(),s=i=>r.some(o=>i.name.includes(o));this.walkProject(t,s);let n=t;for(;n!==this.rootDir;){let i=k.dirname(n);if(i===n)break;for(let o of Uo){let a=k.join(i,o);try{it.statSync(a).isDirectory()&&this.walkProject(a,s)}catch{}}n=i}await this.drain()}async processDocFiles(){this.walkProject(this.rootDir,t=>t.name.endsWith(".md")||t.name.endsWith(".mdx")),await this.drain()}walkProject(t,r){let s;try{s=it.readdirSync(t,{withFileTypes:!0})}catch{return}for(let n of s){let i=k.join(t,n.name);n.isDirectory()?Br.has(n.name)||this.walkProject(i,r):n.isFile()&&r(n)&&this.enqueue(i)}}enqueue(t){this.visited.has(t)||(this.visited.add(t),this.showProgress(),this.queue.push(t))}async drain(){for(;this.queue.length>0;){let t=this.queue;this.queue=[],await Promise.all(t.map(r=>this.finishFile(r)))}}async finishFile(t){let r=it.statSync(t,{throwIfNoEntry:!1});if(!r?.isFile())return;let s=k.relative(this.rootDir,t),n=await this.getNode(t,s,r);n.imports=await this.resolveImports(t,n.imports),Dr(n.imports,n.tags),this.graph.nodes.set(n.path,n)}async getNode(t,r,s){let n=this.previousGraph?.nodes.get(r);if(n&&n.mtime===s.mtimeMs&&n.size===s.size)return{...n};let i=await this.tryParse(t,r);if(!i)return this.makeStubNode(t,r,s);let o=this.resolveCallEdges(t,i.rawCallEdges),a=this.buildNode(t,r,s,i,o);return this.attachGitStats(a,r),a}async tryParse(t,r){let s=it.readFileSync(t,"utf-8");try{return await this.parseContent(t,s)}catch(n){return process.stderr.write(`
|
|
26
26
|
Warning: failed to parse ${r}: ${n}
|
|
27
|
-
`),null}}parseContent(t,r){return this.pool?this.pool.run({filePath:t,content:r}):
|
|
27
|
+
`),null}}parseContent(t,r){return this.pool?this.pool.run({filePath:t,content:r}):Ir(t,r)}makeStubNode(t,r,s){return{path:r,type:P(t),category:"other",imports:[],exports:[],tags:[],mtime:s.mtimeMs,size:s.size}}resolveCallEdges(t,r){let s=[];for(let n of r??[])try{let i=this.resolver.resolve(t,n.toSpecifier);i&&!i.isExternal&&s.push({from:n.from,to:n.to,toFile:k.relative(this.rootDir,i.path)})}catch{}return s}buildNode(t,r,s,n,i){let{imports:o,exports:a,tags:c,category:p,description:g,complexity:u,cognitiveComplexity:y,functions:b}=n;return{path:r,type:P(t),category:p,imports:o,exports:a,tags:c,mtime:s.mtimeMs,size:s.size,...g!==void 0?{description:g}:{},...i.length>0?{callEdges:i}:{},...u!==void 0?{complexity:u}:{},...y!==void 0?{cognitiveComplexity:y}:{},...b!==void 0?{functions:b}:{}}}attachGitStats(t,r){let s=this.gitStatsMap?.get(r);s&&(t.commitCount90d=s.commitCount90d,s.lastAuthor!==void 0&&(t.lastAuthor=s.lastAuthor),s.lastCommitAt!==void 0&&(t.lastCommitAt=s.lastCommitAt))}async resolveImports(t,r){let s=[];for(let n of r){let i=this.resolver.resolveAll(t,n.rawSpecifier);if(i.length!==0)for(let o of i){let a={...n,toPath:o.isExternal?o.path:k.relative(this.rootDir,o.path),isExternal:o.isExternal};o.isWorkspace&&(a.isWorkspace=!0,a.workspacePackage=o.workspacePackage),o.isExternal?this.attachLockfileVersion(a):this.enqueue(o.path),s.push(a)}}return s}attachLockfileVersion(t){if(!this.lockFile)return;let r=t.rawSpecifier.startsWith("@")?t.rawSpecifier.split("/").slice(0,2).join("/"):t.rawSpecifier.split("/")[0],s=r?this.lockFile.dependencies[r]:void 0;s&&(t.version=s.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function Ur(e,t){return{identifier:t?.identifier??new vt,featureMap:t?.featureDetection===!1?new Map:J(e.nodes,t?.featureDetection??void 0)}}function Kr(e,t,r,s,n){for(let i of t){let o=e.nodes.get(i);if(!o)continue;let a=new M(i,["*",...o.exports.map(c=>c.name)]);e.traverse(i,(c,p,g)=>{if(!g)return!0;if(!a.updateAffectedSymbols(c,g))return!1;if(p>0){let u=r.get(c.path);if(u)return s(u),!1}return n(c),!0},{direction:"incoming"})}}function Ho(e,t,r){let{identifier:s,featureMap:n}=Ur(e,r),i=new Set;for(let o of t){let a=n.get(o);a&&i.add(a.tag)}return Kr(e,t,n,o=>i.add(o.tag),o=>{if(s.isTestNode(o))for(let a of o.tags)i.add(a.name)}),Array.from(i)}function Qo(e,t,r){let{identifier:s,featureMap:n}=Ur(e,r),i=new Set;return Kr(e,t,n,()=>{},o=>{s.isTestNode(o)&&i.add(o.path)}),Array.from(i)}import Vo from"fs";import at from"path";async function du(e,t,r=null,s={}){let n=s.silent?void 0:o=>{process.stderr.write(`Processed ${o} files...\r`)};return await new ot(at.resolve(e),r,void 0,n,s.gitStats??!1,s.coverageMap??new Map,s.parallelParsing??!0).build(t)}async function hu(e,t={}){let r=at.resolve(e),s=$t(r),n=t.packages?s.packages.filter(a=>t.packages?.includes(a.name)||t.packages?.includes(a.relativeRoot)):s.packages,i=new Map(s.packages.map(a=>[a.name,a.root])),o=new X(r,s.type);for(let a of n){let c=t.silent?void 0:u=>{process.stderr.write(`[${a.name}] Processed ${u} files...\r`)},g=await new ot(r,null,new z(r,{workspaceMap:i,tsconfigSearchPaths:[a.root,r]}),c,t.gitStats??!1,new Map,t.parallelParsing??!0).build(a.entryPoints);o.addPackage(a,g)}return o}function yu(e,t={}){let r=[],s=new Set([...t.ignoreDirs??Rt,...t.additionalIgnoreDirs??[]]),n=new Set([...t.extensions??Dt,...t.additionalExtensions??[]]);function i(o){try{let a=Vo.readdirSync(o,{withFileTypes:!0});for(let c of a){let p=at.join(o,c.name);c.isDirectory()?s.has(c.name)||i(p):c.isFile()&&n.has(at.extname(c.name).toLowerCase())&&r.push(at.relative(e,p))}}catch{}}return i(e),r}export{Dt as DEFAULT_EXTENSIONS,Rt as DEFAULT_IGNORE_DIRS,I as Graph,At as MermaidExporter,M as SymbolTraversalContext,X as WorkspaceGraph,ts as applyConfig,ri as applyTags,fs as buildApiSurface,gs as buildChangeImpactCache,jt as buildFeatureGraph,As as buildResponsibilityGraph,js as buildTypeGraph,Gt as computeGraphHash,du as createImportMap,hu as createWorkspaceGraph,xe as detectAllEntryPoints,os as detectEntryPoint,J as detectFeatures,$t as detectMonorepo,je as filterGraph,Ms as findComplexFunctions,Ts as getAffected,yu as getAllProjectFiles,Is as getCallers,Fs as getDependencies,Ps as getDependents,Ds as hasCoverageData,hs as isChangeImpactCacheValid,xs as loadChangeImpactCache,rs as loadCoverageMap,Nt as loadMokoshConfig,We as parseQuery,Qo as proposeAffectedTests,Ho as proposeTags,ms as queryCallGraph,ds as queryChangeImpact,Os as queryTypeGraph,ct as registerConfigMatcher,F as registerMonorepoDetector,D as registerParser,lt as registerTestLibrary,pt as registerTestPattern,ys as saveChangeImpactCache,Ns as slimSerialize,Rs as summarizeWorkspacePackages,de as toMermaid};
|
|
28
28
|
//# sourceMappingURL=index.mjs.map
|