// @bun
import{hc as y}from"./chunk-94h87sgb.js";import{ad as k}from"./chunk-ns3hznyf.js";var H=k(y(),1);import{dirname as C,resolve as F}from"path";function v(q,j){let B=H.default.readConfigFile(q,H.default.sys.readFile);if(B.error)throw Error(`Error reading tsconfig.json: ${b(B.error)}`);let J=H.default.parseJsonConfigFileContent(B.config,H.default.sys,C(q));if(J.errors.length>0){let I=J.errors.map(b).join(`
`);throw Error(`Error parsing tsconfig.json:
${I}`)}return{...J.options,...j}}function b(q){if(q.file&&q.start!==void 0){let{line:j,character:B}=q.file.getLineAndCharacterOfPosition(q.start),J=H.default.flattenDiagnosticMessageText(q.messageText,`
`);return`${q.file.fileName}(${j+1},${B+1}): ${J}`}return H.default.flattenDiagnosticMessageText(q.messageText,`
`)}function x(q){switch(q){case H.default.DiagnosticCategory.Error:return"error";case H.default.DiagnosticCategory.Warning:return"warning";case H.default.DiagnosticCategory.Suggestion:return"hint";case H.default.DiagnosticCategory.Message:default:return"info"}}function S(q){switch(q){case H.default.DiagnosticCategory.Error:return"Error";case H.default.DiagnosticCategory.Warning:return"Warning";case H.default.DiagnosticCategory.Suggestion:return"Suggestion";case H.default.DiagnosticCategory.Message:return"Message";default:return"Unknown"}}function P(q){let j=H.default.flattenDiagnosticMessageText(q.messageText,`
`);if(q.file&&q.start!==void 0){let{line:B,character:J}=q.file.getLineAndCharacterOfPosition(q.start),I=q.file,R;if(q.length){let K=B,Q=q.start+q.length,{line:X}=I.getLineAndCharacterOfPosition(Q),$=I.text.split(`
`),V=Math.max(0,K-1),G=Math.min($.length,X+2);R=$.slice(V,G).join(`
`)}return{file:I.fileName,line:B+1,column:J+1,message:j,code:q.code,severity:x(q.category),source:R,category:S(q.category)}}return{file:"<unknown>",line:0,column:0,message:j,code:q.code,severity:x(q.category),category:S(q.category)}}function L(q,j){let B=H.default.createCompilerHost(j);return H.default.createProgram(q,j,B)}async function E(q,j={}){let B=Date.now(),J;if(j.tsconfigPath)J=v(j.tsconfigPath,j.compilerOptions);else J={target:H.default.ScriptTarget.ESNext,module:H.default.ModuleKind.ESNext,moduleResolution:H.default.ModuleResolutionKind.Bundler,strict:j.strict??!0,skipLibCheck:j.skipLibCheck??!0,noEmit:!0,declaration:!0,...j.compilerOptions};let I=q;if(j.declarationsOnly)I=q.filter((G)=>G.endsWith(".d.ts"));if(j.include?.length){let G=j.include.map((U)=>new RegExp(U.replace(/\*/g,".*")));I=I.filter((U)=>G.some((W)=>W.test(U)))}if(j.exclude?.length){let G=j.exclude.map((U)=>new RegExp(U.replace(/\*/g,".*")));I=I.filter((U)=>!G.some((W)=>W.test(U)))}let R=L(I,J),Q=[...R.getConfigFileParsingDiagnostics(),...R.getSyntacticDiagnostics(),...R.getSemanticDiagnostics(),...R.getDeclarationDiagnostics()].map(P);if(j.maxErrors&&Q.length>j.maxErrors)Q=Q.slice(0,j.maxErrors);let X=Q.filter((G)=>G.severity==="error").length,$=Q.filter((G)=>G.severity==="warning").length,V=Q.filter((G)=>G.severity==="info"||G.severity==="hint").length;if(j.warningsAsErrors)Q=Q.map((G)=>G.severity==="warning"?{...G,severity:"error"}:G),X+=$;return{success:X===0,diagnostics:Q,errorCount:X,warningCount:j.warningsAsErrors?0:$,infoCount:V,filesChecked:I,durationMs:Date.now()-B}}async function u(q,j={}){return E(q,{...j,declarationsOnly:!0,skipLibCheck:!0,compilerOptions:{...j.compilerOptions,noEmit:!0,declaration:!1}})}async function m(q,j){let B=new Map,I={...j?v(j):{target:H.default.ScriptTarget.ESNext,module:H.default.ModuleKind.ESNext,moduleResolution:H.default.ModuleResolutionKind.Bundler},isolatedDeclarations:!0,declaration:!0,noEmit:!0},R=L(q,I);for(let K of q){let Q=R.getSourceFile(K);if(!Q){B.set(K,{compatible:!0,issues:[]});continue}let X=[],V=[...R.getSyntacticDiagnostics(Q),...R.getSemanticDiagnostics(Q)].filter((G)=>G.code>=9006&&G.code<=9099);for(let G of V)if(G.start!==void 0){let{line:U,character:W}=Q.getLineAndCharacterOfPosition(G.start),Y=H.default.flattenDiagnosticMessageText(G.messageText,`
`),Z;if(Y.includes("return type"))Z="return";else if(Y.includes("parameter"))Z="parameter";else if(Y.includes("variable"))Z="variable";else if(Y.includes("property"))Z="property";X.push({line:U+1,column:W+1,message:Y,missingAnnotation:Z})}B.set(K,{compatible:X.length===0,issues:X})}return B}function f(q,j,B,J){try{let U=function(Z){if(V>=Z.getStart()&&V<Z.getEnd())return H.default.forEachChild(Z,U)||Z;return},I=J?v(J):{target:H.default.ScriptTarget.ESNext,module:H.default.ModuleKind.ESNext,moduleResolution:H.default.ModuleResolutionKind.Bundler},R=L([q],I),K=R.getSourceFile(q);if(!K)return null;let Q=K.getLineStarts().length;if(j<1||j>Q)return null;let X=K.getLineStarts()[j-1],$=j<Q?K.getLineStarts()[j]:K.text.length;if(B<1||B>$-X)return null;let V=K.getPositionOfLineAndCharacter(j-1,B-1),G=R.getTypeChecker(),W=U(K);if(!W)return null;let Y=G.getTypeAtLocation(W);return G.typeToString(Y)}catch{return null}}function d(q,j,B,J){try{let U=function(M){if(V>=M.getStart()&&V<M.getEnd())return H.default.forEachChild(M,U)||M;return},I=J?v(J):{target:H.default.ScriptTarget.ESNext,module:H.default.ModuleKind.ESNext,moduleResolution:H.default.ModuleResolutionKind.Bundler},R=L([q],I),K=R.getSourceFile(q);if(!K)return null;let Q=K.getLineStarts().length;if(j<1||j>Q)return null;let X=K.getLineStarts()[j-1],$=j<Q?K.getLineStarts()[j]:K.text.length;if(B<1||B>$-X)return null;let V=K.getPositionOfLineAndCharacter(j-1,B-1),G=R.getTypeChecker(),W=U(K);if(!W)return null;let Y=G.getSymbolAtLocation(W);if(!Y){let M=G.getTypeAtLocation(W);return{type:G.typeToString(M)}}let Z=G.typeToString(G.getTypeOfSymbolAtLocation(Y,W)),A=H.default.displayPartsToString(Y.getDocumentationComment(G));return{type:Z,documentation:A||void 0}}catch{return null}}function g(q){let j=[];if(q.success)j.push(`\u2713 Type check passed (${q.filesChecked.length} files checked in ${q.durationMs}ms)`);else{j.push("\u2717 Type check failed"),j.push(`  ${q.errorCount} error(s), ${q.warningCount} warning(s)`),j.push("");for(let B of q.diagnostics){let J=B.severity==="error"?"\u2717":B.severity==="warning"?"\u26A0":"\u2139";if(j.push(`${J} ${B.file}:${B.line}:${B.column}`),j.push(`  ${B.message}`),B.source){let I=B.source.split(`
`);for(let R of I)j.push(`  \u2502 ${R}`)}if(B.suggestion)j.push(`  \uD83D\uDCA1 ${B.suggestion}`);j.push("")}}return j.join(`
`)}async function l(q){let j=q.entrypoints.map((B)=>F(q.cwd,B));return E(j,{tsconfigPath:q.tsconfigPath,rootDir:q.root})}async function a(q,j,B){let J=q,I=j,R=B,K=[],Q=R?v(R):{target:H.default.ScriptTarget.ESNext,module:H.default.ModuleKind.ESNext,moduleResolution:H.default.ModuleResolutionKind.Bundler},X=L(J,Q),$=L(I,{...Q,declaration:!1}),V=X.getTypeChecker(),G=$.getTypeChecker();for(let U=0;U<J.length;U++){let W=X.getSourceFile(J[U]),Y=$.getSourceFile(I[U]);if(!W||!Y)continue;let Z=V.getSymbolAtLocation(W),A=G.getSymbolAtLocation(Y);if(!Z||!A)continue;let M=V.getExportsOfModule(Z),O=G.getExportsOfModule(A),T=new Map(O.map((w)=>[w.getName(),w]));for(let w of M){let N=w.getName(),D=T.get(N);if(!D){K.push({sourceName:N,sourceType:V.typeToString(V.getTypeOfSymbolAtLocation(w,W)),dtsType:"<missing>"});continue}let _=V.typeToString(V.getTypeOfSymbolAtLocation(w,W)),z=G.typeToString(G.getTypeOfSymbolAtLocation(D,Y));if(_!==z&&!h(_,z))K.push({sourceName:N,sourceType:_,dtsType:z})}}return{valid:K.length===0,mismatches:K}}function h(q,j){let B=(R)=>R.replace(/\s+/g," ").replace(/\s*([<>,{}()[\]:;])\s*/g,"$1").trim(),J=B(q),I=B(j);if(J===I)return!0;if(I==="any")return!0;if(J.startsWith("Promise<")&&I.startsWith("PromiseLike<"))return!0;return!1}
export{v as z,E as A,u as B,m as C,f as D,d as E,g as F,l as G,a as H};
