// @bun
import{hc as z}from"./chunk-94h87sgb.js";import{ad as R}from"./chunk-ns3hznyf.js";var V=R(z(),1);import{readFile as I}from"fs/promises";import{dirname as T,relative as $,resolve as k}from"path";async function M(j,B={}){let A=new Map,K=B.rootDir||process.cwd();for(let H of j){if(B.ignore?.some((L)=>q(H,L)))continue;if(!B.includeNodeModules&&H.includes("node_modules"))continue;let Q=await b(H,K);if(Q)A.set(H,Q)}for(let[H,Q]of A)for(let L of Q.dependencies){let U=A.get(L);if(U)U.dependents.add(H)}return A}async function b(j,B){try{let A=await I(j,"utf-8"),K=V.default.createSourceFile(j,A,V.default.ScriptTarget.Latest,!0,V.default.ScriptKind.TS),H={path:j,exports:new Set,imports:new Map,dependencies:new Set,dependents:new Set};return V.default.forEachChild(K,(Q)=>{F(Q,H,j,B)}),H}catch{return null}}function F(j,B,A,K){if(V.default.isImportDeclaration(j)){let H=j.moduleSpecifier;if(V.default.isStringLiteral(H)){let Q=w(H.text,A,K);if(Q){B.dependencies.add(Q);let L=j.importClause;if(L){if(L.name)B.imports.set(L.name.text,Q);if(L.namedBindings){if(V.default.isNamedImports(L.namedBindings))for(let U of L.namedBindings.elements)B.imports.set(U.name.text,Q);else if(V.default.isNamespaceImport(L.namedBindings))B.imports.set(L.namedBindings.name.text,Q)}}}}}if(V.default.isExportDeclaration(j)){if(j.moduleSpecifier&&V.default.isStringLiteral(j.moduleSpecifier)){let H=w(j.moduleSpecifier.text,A,K);if(H)B.dependencies.add(H)}if(j.exportClause&&V.default.isNamedExports(j.exportClause))for(let H of j.exportClause.elements)B.exports.add(H.name.text)}if(V.default.isFunctionDeclaration(j)&&j.name&&X(j))B.exports.add(j.name.text);if(V.default.isClassDeclaration(j)&&j.name&&X(j))B.exports.add(j.name.text);if(V.default.isInterfaceDeclaration(j)&&X(j))B.exports.add(j.name.text);if(V.default.isTypeAliasDeclaration(j)&&X(j))B.exports.add(j.name.text);if(V.default.isEnumDeclaration(j)&&X(j))B.exports.add(j.name.text);if(V.default.isVariableStatement(j)&&X(j)){for(let H of j.declarationList.declarations)if(V.default.isIdentifier(H.name))B.exports.add(H.name.text)}}function X(j){return(V.default.canHaveModifiers(j)?V.default.getModifiers(j):void 0)?.some((A)=>A.kind===V.default.SyntaxKind.ExportKeyword)??!1}function w(j,B,A){if(!j.startsWith(".")&&!j.startsWith("/"))return null;let K=T(B),H=k(K,j),Q=[".ts",".tsx",".d.ts","/index.ts","/index.tsx","/index.d.ts"];for(let L of Q){let U=H.endsWith(".ts")||H.endsWith(".tsx")?H:H+L;if(!U.includes("node_modules"))return U.replace(/\.tsx?$/,".ts")}return`${H}.ts`}function q(j,B){let A=B.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(A).test(j)}function E(j,B={}){let A=[],K=new Set,H=new Set,Q=B.maxDepth||100;function L(U,W,G){if(G>Q)return;if(H.has(U)){let Y=W.indexOf(U),Z=[...W.slice(Y),U],O=S(Z,j),_=v(Z,j);if(!B.typesOnly||_)A.push({chain:Z,symbols:O,severity:_?"error":"warning",reason:_?"Type-level circular dependency can cause compilation issues":"Value-level circular dependency may cause runtime issues"});return}if(K.has(U))return;let J=j.get(U);if(!J)return;K.add(U),H.add(U),W.push(U);for(let Y of J.dependencies)L(Y,[...W],G+1);H.delete(U)}for(let U of j.keys())K.clear(),H.clear(),L(U,[],0);return C(A)}function S(j,B){let A=[];for(let K=0;K<j.length-1;K++){let H=B.get(j[K]),Q=j[K+1];if(H){for(let[L,U]of H.imports)if(U===Q)A.push(L)}}return[...new Set(A)]}function v(j,B){return j.some((A)=>A.endsWith(".d.ts")||B.get(A)?.exports.has("type")||[...B.get(A)?.imports.keys()||[]].some((K)=>K.startsWith("type ")||K==="type"))}function C(j){let B=new Set,A=[];for(let K of j){let H=x(K.chain),Q=H.join(" -> ");if(!B.has(Q))B.add(Q),A.push({...K,chain:H})}return A}function x(j){if(j.length<=1)return j;let B=j.slice(0,-1),A=B;for(let K=1;K<B.length;K++){let H=[...B.slice(K),...B.slice(0,K)];if(H.join("")<A.join(""))A=H}return[...A,A[0]]}async function g(j,B={}){let A=Date.now(),K=await M(j,B),H=E(K,B);return{hasCircular:H.length>0,cycles:H,graph:K,filesAnalyzed:j,durationMs:Date.now()-A}}function y(j,B){let A=[];if(!j.hasCircular)return A.push(`\u2713 No circular dependencies found (${j.filesAnalyzed.length} files analyzed in ${j.durationMs}ms)`),A.join(`
`);A.push(`\u2717 Found ${j.cycles.length} circular dependency chain(s)`),A.push("");for(let K of j.cycles){let H=K.severity==="error"?"\uD83D\uDD34":"\uD83D\uDFE1";A.push(`${H} ${K.severity.toUpperCase()}: Circular dependency`);let Q=K.chain.map((L)=>B?$(B,L):L);if(A.push(`   ${Q.join(" \u2192 ")}`),K.symbols.length>0)A.push(`   Symbols: ${K.symbols.join(", ")}`);A.push(`   ${K.reason}`),A.push("")}return A.push(`Analyzed ${j.filesAnalyzed.length} files in ${j.durationMs}ms`),A.join(`
`)}function m(j){let B=0,A={file:"",count:0},K={file:"",count:0},H=[];for(let[Q,L]of j){let U=L.dependencies.size;if(B+=U,U>A.count)A={file:Q,count:U};if(U===0&&L.dependents.size===0)H.push(Q);if(L.dependents.size>K.count)K={file:Q,count:L.dependents.size}}return{totalFiles:j.size,totalDependencies:B,avgDependencies:j.size>0?B/j.size:0,maxDependencies:A,isolatedFiles:H,mostDepended:K}}function P(j,B){let A=new Set,K=[j];while(K.length>0){let H=K.shift(),Q=B.get(H);if(Q){for(let L of Q.dependents)if(!A.has(L))A.add(L),K.push(L)}}return A}function u(j,B){let A=new Set,K=[j];while(K.length>0){let H=K.shift(),Q=B.get(H);if(Q){for(let L of Q.dependencies)if(!A.has(L))A.add(L),K.push(L)}}return A}function f(j,B){let A=["digraph dependencies {","  rankdir=LR;","  node [shape=box];",""];for(let[K,H]of j){let Q=B?$(B,K):K,L=K.replace(/[^a-z0-9]/gi,"_");A.push(`  ${L} [label="${Q}"];`);for(let U of H.dependencies){let W=U.replace(/[^a-z0-9]/gi,"_");A.push(`  ${L} -> ${W};`)}}return A.push("}"),A.join(`
`)}function c(j,B){let A=[];for(let[K,H]of j){let Q=B?$(B,K):K;A.push({id:K,path:Q,exports:[...H.exports],imports:Object.fromEntries(H.imports),dependencies:[...H.dependencies],dependents:[...H.dependents]})}return JSON.stringify({nodes:A},null,2)}
export{M as Q,E as R,g as S,y as T,m as U,P as V,u as W,f as X,c as Y};
