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