@stacksjs/dtsx 0.9.20 → 0.9.21
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/bin/cli.js +2 -2
- package/dist/{chunk-1b1j60g0.js → chunk-380wx22t.js} +1 -1
- package/dist/{chunk-fqym6cgw.js → chunk-4zdjnqrz.js} +1 -1
- package/dist/{chunk-r1yqh3qg.js → chunk-9asxz2at.js} +1 -1
- package/dist/{chunk-5zt12z1t.js → chunk-aaba58v4.js} +1 -1
- package/dist/chunk-af12rv0y.js +80 -0
- package/dist/{chunk-dnbr0hke.js → chunk-sp1xrnfe.js} +1 -1
- package/dist/{chunk-c60qpa3j.js → chunk-wr3swrge.js} +1 -1
- package/dist/{chunk-wtqapt0n.js → chunk-ww6wqbda.js} +1 -1
- package/dist/{chunk-h0dndwyc.js → chunk-wzbwr7a3.js} +1 -1
- package/dist/{chunk-9e542zj7.js → chunk-yzhdn85p.js} +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/plugins/bun.js +1 -1
- package/dist/src/plugins/esbuild.js +1 -1
- package/dist/src/plugins/index.js +1 -1
- package/dist/src/plugins/tsup.js +1 -1
- package/dist/src/plugins/vite.js +1 -1
- package/dist/src/plugins/webpack.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-y4g1csn2.js +0 -80
package/dist/bin/cli.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import{dd as Y}from"../chunk-mcdb3q06.js";import V from"process";var f=V.argv[2];if(f==="stdin"||f==="emit"||f==="--project"){if(f==="stdin"){let{processSource:q}=await import("../chunk-eqfegkc1.js"),Q=[];for await(let N of V.stdin)Q.push(N);let K=Buffer.concat(Q).toString("utf-8");if(K.trim())V.stdout.write(q(K,"stdin.ts")),V.stdout.write(`
|
|
3
3
|
`)}else if(f==="--project"){let{readdirSync:q,readFileSync:Q,writeFileSync:K,mkdirSync:N}=await import("fs"),A=typeof globalThis.Bun<"u",J=A?globalThis.Bun:null,$=V.argv.slice(3),z="",B="",G=!1;for(let X=0;X<$.length;X++)if($[X]==="--outdir"&&$[X+1])B=$[X+1],X++;else if($[X]==="--isolated-declarations")G=!0;else if(!z)z=$[X];N(B,{recursive:!0});let j=q(z).filter((X)=>X.endsWith(".ts")&&!X.endsWith(".d.ts")),Z=j.length,E=Array(Z),M=Array(Z);for(let X=0;X<Z;X++)E[X]=`${z}/${j[X]}`,M[X]=`${B}/${j[X].slice(0,-3)}.d.ts`;let T=["bun"],R=A&&Z>=64,I=!1,_=null;if(R){let X=null;try{let{createWorkerPool:F,calculateOptimalBatchSize:D}=await import("../chunk-3xqchdwd.js"),{cpus:C}=await import("os"),w=Math.max(1,C().length-1),U=Math.min(64,Math.max(8,D(Z,w)*2)),L=Z>=256,a=!0,l=Z>=256;if(!L&&Z>=256){_=Array(Z);for(let x=0;x<Z;x++)_[x]=J.file(E[x]).text()}let O=Math.ceil(Z/U),u=Math.min(O,Math.max(2,w*2));X=F({maxWorkers:w,initialWorkers:w,recycleAfter:Math.max(100,O+1)}),await X.init();let d=X,i=0,r=Date.now(),t=async()=>{for(;;){let x=i++;if(x>=O)return;let S=x*U;if(S>=Z)return;let g=Math.min(Z,S+U)-S,m;if(l){let P=Array(g),y=Array(g),b;if(L)for(let W=0;W<g;W++){let v=S+W;P[W]=E[v],y[W]=M[v]}else{let W=Array(g);for(let v=0;v<g;v++){let c=S+v;P[v]=E[c],y[v]=M[c],W[v]=_?_[c]:J.file(E[c]).text()}b=await Promise.all(W)}m=await d.submit({id:`batch-${r}-${x}`,type:"process-batch",filePath:P[0]||"",filePaths:P,sources:b,outPaths:y,writeOutput:!0,config:{keepComments:!0,importOrder:T,isolatedDeclarations:G}})}else{let P=Array(g);if(L)for(let y=0;y<g;y++){let b=S+y;P[y]={filePath:E[b],outPath:M[b]}}else{let y=Array(g);for(let W=0;W<g;W++){let v=S+W;y[W]=_?_[v]:J.file(E[v]).text()}let b=await Promise.all(y);for(let W=0;W<g;W++){let v=S+W;P[W]={filePath:E[v],sourceCode:b[W],outPath:M[v]}}}m=await d.submit({id:`batch-${r}-${x}`,type:"process-batch",filePath:E[S]||"",files:P,writeOutput:!0,config:{keepComments:!0,importOrder:T,isolatedDeclarations:G}})}if(!m.success)throw Error(m.error||`Worker batch failed for ${E[S]}`);if(m.batchResults?.length){let P=m.batchResults[0];throw Error(P?.error||m.error||`Worker failed for ${E[S]}`)}}},n=[];for(let x=0;x<u;x++)n.push(t());await Promise.all(n),I=!0}catch{I=!1}finally{if(X)await X.shutdown()}}if(!I){let{scanDeclarations:X}=await import("../chunk-nmmv0nrk.js"),{processDeclarations:F}=await import("../chunk-dymmh9x0.js"),D=Array(Z);if(A){let U=_?await Promise.all(_):await Promise.all(E.map((L)=>J.file(L).text()));for(let L=0;L<Z;L++)D[L]=U[L]}else for(let U=0;U<Z;U++)D[U]=Q(E[U],"utf-8");let C=Array(Z),w={filePath:"",sourceCode:"",declarations:[]};for(let U=0;U<Z;U++){let L=X(D[U],j[U],!0,G);w.filePath=j[U],w.sourceCode=D[U],w.declarations=L,C[U]=F(L,w,!0,T)}if(A){let U=Array(Z);for(let L=0;L<Z;L++)U[L]=J.write(M[L],C[L]);await Promise.all(U)}else for(let U=0;U<Z;U++)K(M[U],C[U])}}else{let{processSource:q}=await import("../chunk-eqfegkc1.js"),{readFileSync:Q,writeFileSync:K,mkdirSync:N}=await import("fs"),A=typeof globalThis.Bun<"u",J=A?globalThis.Bun:null,$=V.argv[3],z=A?await J.file($).text():Q($,"utf-8"),B=V.argv[4];if(B){let{dirname:G}=await import("path");N(G(B),{recursive:!0});let j=`${q(z,$)}
|
|
4
4
|
`;if(A)await J.write(B,j);else K(B,j)}else V.stdout.write(q(z,$)),V.stdout.write(`
|
|
5
|
-
`)}V.exit(0)}var{resolve:h}=await import("path"),{CLI:s}=await import("../chunk-cdv5r51q.js"),{version:e}=await import("../chunk-
|
|
6
|
-
Total: ${R}B -> ${R-T}B (-${I}%)`)}catch(Q){console.error("Error optimizing files:",Q),V.exit(1)}});k.command("docs","Generate API documentation from source files").option("--root <path>","Root directory to scan for source files",{default:"./src"}).option("--outdir <path>","Output directory for documentation",{default:"./docs"}).option("--format <format>","Output format: markdown or html",{default:"markdown"}).option("--title <title>","Documentation title",{default:"API Documentation"}).option("--include-private","Include private members (prefixed with _)",{default:!1}).option("--include-internal","Include internal members (@internal)",{default:!1}).option("--group-by-category","Group entries by @category tag",{default:!1}).option("--source-url <url>","Base URL for source links").example("dtsx docs").example("dtsx docs --format html --outdir ./api-docs").example('dtsx docs --group-by-category --title "My API"').action(async(q)=>{try{let{generateDocs:Q}=await import("../chunk-a0gah6hn.js"),{Glob:K}=awaitPromise.resolve(globalThis.Bun),{resolve:N}=await import("path"),A=N(q.root||"./src"),J=new K("**/*.ts"),$=[];for await(let z of J.scan({cwd:A,absolute:!0,onlyFiles:!0}))if(!z.endsWith(".d.ts")&&!z.includes("node_modules"))$.push(z);if($.length===0)console.error("No TypeScript files found"),V.exit(1);console.log(`Found ${$.length} source files`),await Q($,{format:q.format||"markdown",outdir:N(q.outdir||"./docs"),title:q.title||"API Documentation",includePrivate:q.includePrivate??!1,includeInternal:q.includeInternal??!1,groupByCategory:q.groupByCategory??!1,includeSourceLinks:!!q.sourceUrl,sourceBaseUrl:q.sourceUrl})}catch(Q){console.error("Error generating documentation:",Q),V.exit(1)}});k.command("workspace","Generate declarations for all projects in a monorepo/workspace").option("--cwd <path>","Workspace root directory",{default:V.cwd()}).option("--parallel","Process projects in parallel",{default:!1}).option("--continue-on-error","Continue if a project fails",{default:!0}).option("--log-level <level>","Log level (debug, info, warn, error, silent)",{default:"info"}).example("dtsx workspace").example("dtsx workspace --cwd /path/to/monorepo").action(async(q)=>{try{let{generateMonorepo:Q,generateFromPackageWorkspaces:K}=await import("../chunk-
|
|
5
|
+
`)}V.exit(0)}var{resolve:h}=await import("path"),{CLI:s}=await import("../chunk-cdv5r51q.js"),{version:e}=await import("../chunk-380wx22t.js"),{getConfig:o}=await import("../chunk-0d5r9n78.js"),{generate:qq,processSource:Hq,watch:Kq}=await import("../chunk-sp1xrnfe.js"),k=new s("dtsx"),H={cwd:V.cwd(),root:"./src",entrypoints:["**/*.ts"],outdir:"./dist",keepComments:!0,clean:!1,tsconfigPath:"tsconfig.json",verbose:!1,importOrder:["bun"],dryRun:!1,stats:!1,continueOnError:!1,logLevel:"info",exclude:[],outputFormat:"text",progress:!1,diff:!1,validate:!1,parallel:!1,concurrency:4};k.command("generate","Generate TypeScript declaration files").option("--cwd <path>","Current working directory",{default:H.cwd}).option("--root <path>","Root directory of the project",{default:H.root}).option("--entrypoints <files>","Entry point files (comma-separated)",{default:H.entrypoints?.join(","),type:[String]}).option("--outdir <path>","Output directory for generated .d.ts files",{default:H.outdir}).option("--keep-comments","Keep comments in generated .d.ts files",{default:H.keepComments}).option("--clean","Clean output directory before generation",{default:H.clean}).option("--tsconfig <path>","Path to tsconfig.json",{default:H.tsconfigPath}).option("--verbose","Enable verbose logging",{default:H.verbose}).option("--import-order <patterns>","Import order priority patterns (comma-separated)",{default:H.importOrder?.join(","),type:[String]}).option("--dry-run","Show what would be generated without writing files",{default:H.dryRun}).option("--stats","Show statistics after generation",{default:H.stats}).option("--continue-on-error","Continue processing other files if one fails",{default:H.continueOnError}).option("--log-level <level>","Log level (debug, info, warn, error, silent)",{default:H.logLevel}).option("--exclude <patterns>","Glob patterns to exclude (comma-separated)",{default:H.exclude?.join(","),type:[String]}).option("--output-format <format>","Output format: text or json",{default:H.outputFormat}).option("--progress","Show progress during generation",{default:H.progress}).option("--diff","Show diff of changes compared to existing files",{default:H.diff}).option("--validate","Validate generated .d.ts files against TypeScript",{default:H.validate}).option("--parallel","Process files in parallel",{default:H.parallel}).option("--concurrency <number>","Number of concurrent workers (with --parallel)",{default:H.concurrency}).option("--declaration-map","Generate declaration map files (.d.ts.map)",{default:!1}).option("--bundle","Bundle all declarations into a single output file",{default:!1}).option("--bundle-output <file>","Output filename when bundling (relative to outdir)",{default:"index.d.ts"}).option("--config <path>","Path to config file (dtsx.config.ts)",{default:""}).option("--incremental","Enable incremental builds (only regenerate changed files)",{default:!1}).option("--clear-cache","Clear the incremental build cache before generating",{default:!1}).option("--indent-style <style>","Indentation style: spaces or tabs",{default:"spaces"}).option("--indent-size <size>","Number of spaces for indentation",{default:2}).option("--prettier","Use Prettier for output formatting if available",{default:!1}).example("dtsx generate").example("dtsx generate --entrypoints src/index.ts,src/utils.ts --outdir dist/types").example('dtsx generate --import-order "node:,bun,@myorg/"').example("dtsx generate --dry-run --stats").example('dtsx generate --exclude "**/*.test.ts,**/__tests__/**"').example("dtsx generate --stats --output-format json").example("dtsx generate --bundle --bundle-output types.d.ts").action(async(q)=>{try{let Q=h(q.cwd||H.cwd),K=await o(Q),N={entrypoints:q.entrypoints?q.entrypoints:K.entrypoints||H.entrypoints,cwd:Q,root:h(q.root||K.root||H.root),outdir:h(q.outdir||K.outdir||H.outdir),tsconfigPath:h(q.tsconfigPath||K.tsconfigPath||H.tsconfigPath),keepComments:q.keepComments??K.keepComments??H.keepComments,clean:q.clean??K.clean??H.clean,verbose:q.verbose??K.verbose??H.verbose,importOrder:q.importOrder||K.importOrder||H.importOrder,dryRun:q.dryRun??K.dryRun??H.dryRun,stats:q.stats??K.stats??H.stats,continueOnError:q.continueOnError??K.continueOnError??H.continueOnError,logLevel:q.logLevel??K.logLevel??H.logLevel,exclude:q.exclude?q.exclude.flatMap((J)=>J.split(",").map(($)=>$.trim()).filter(Boolean)):K.exclude||H.exclude,outputFormat:q.outputFormat??K.outputFormat??H.outputFormat,progress:q.progress??K.progress??H.progress,diff:q.diff??K.diff??H.diff,validate:q.validate??K.validate??H.validate,parallel:q.parallel??K.parallel??H.parallel,concurrency:Number(q.concurrency)||K.concurrency||H.concurrency,declarationMap:q.declarationMap??K.declarationMap??!1,bundle:q.bundle??K.bundle??!1,bundleOutput:q.bundleOutput??K.bundleOutput??"index.d.ts",incremental:q.incremental??K.incremental??!1,clearCache:q.clearCache??!1,indentStyle:q.indentStyle??K.indentStyle??"spaces",indentSize:Number(q.indentSize)||K.indentSize||2,prettier:q.prettier??K.prettier??!1,plugins:K.plugins},A=await qq(N);if(A.filesFailed>0&&A.filesGenerated===0)V.exit(1);else if(A.filesFailed>0)V.exit(2)}catch(Q){console.error("Error generating .d.ts files:",Q),V.exit(1)}});k.command("watch","Watch for changes and regenerate .d.ts files").option("--cwd <path>","Current working directory",{default:H.cwd}).option("--root <path>","Root directory of the project",{default:H.root}).option("--entrypoints <files>","Entry point files (comma-separated)",{default:H.entrypoints?.join(","),type:[String]}).option("--outdir <path>","Output directory for generated .d.ts files",{default:H.outdir}).option("--keep-comments","Keep comments in generated .d.ts files",{default:H.keepComments}).option("--exclude <patterns>","Glob patterns to exclude (comma-separated)",{default:H.exclude?.join(","),type:[String]}).option("--log-level <level>","Log level (debug, info, warn, error, silent)",{default:H.logLevel}).example("dtsx watch").example("dtsx watch --root src --outdir dist/types").action(async(q)=>{try{let Q={entrypoints:q.entrypoints?q.entrypoints:H.entrypoints,cwd:h(q.cwd||H.cwd),root:h(q.root||H.root),outdir:h(q.outdir||H.outdir),keepComments:q.keepComments??H.keepComments,exclude:q.exclude?q.exclude.flatMap((K)=>K.split(",").map((N)=>N.trim()).filter(Boolean)):H.exclude,logLevel:q.logLevel??H.logLevel};await Kq(Q)}catch(Q){console.error("Error in watch mode:",Q),V.exit(1)}});k.command("stdin","Process TypeScript from stdin and output .d.ts to stdout").option("--keep-comments","Keep comments in generated .d.ts files",{default:!0}).option("--import-order <patterns>","Import order priority patterns (comma-separated)",{default:"bun",type:[String]}).example(`echo "export const foo: string = 'bar'" | dtsx stdin`).example("cat src/index.ts | dtsx stdin").action(async(q)=>{try{let Q=[];for await(let J of V.stdin)Q.push(J);let K=Buffer.concat(Q).toString("utf-8");if(!K.trim())console.error("Error: No input received from stdin"),V.exit(1);let N=["bun"];if(q.importOrder){if(Array.isArray(q.importOrder))N=q.importOrder.flatMap((J)=>J.split(",").map(($)=>$.trim()).filter(Boolean));else if(typeof q.importOrder==="string")N=q.importOrder.split(",").map((J)=>J.trim()).filter(Boolean)}let A=Hq(K,"stdin.ts",q.keepComments??!0,N);console.log(A)}catch(Q){console.error("Error processing stdin:",Q),V.exit(1)}});k.command("optimize","Optimize declaration files").option("--files <patterns>","Glob patterns for .d.ts files to optimize",{default:"**/*.d.ts",type:[String]}).option("--outdir <path>","Output directory (defaults to in-place)",{default:""}).option("--remove-unused-imports","Remove unused type imports",{default:!0}).option("--deduplicate","Remove duplicate declarations",{default:!0}).option("--merge-interfaces","Merge interface declarations with same name",{default:!0}).option("--inline-types","Inline simple type aliases",{default:!1}).option("--remove-empty","Remove empty interfaces",{default:!0}).option("--sort","Sort declarations alphabetically",{default:!1}).option("--sort-imports","Sort imports",{default:!0}).option("--minify","Minify output (remove whitespace)",{default:!1}).option("--remove-comments","Remove comments",{default:!1}).example('dtsx optimize --files "dist/**/*.d.ts"').example("dtsx optimize --minify --remove-comments").action(async(q)=>{try{let{optimizeFile:Q}=await import("../chunk-m94gn6yx.js"),{Glob:K}=awaitPromise.resolve(globalThis.Bun),{resolve:N,join:A,relative:J,dirname:$,basename:z}=await import("path"),{mkdirSync:B,copyFileSync:G,existsSync:j}=await import("fs"),Z=V.cwd(),E=q.files||["**/*.d.ts"],M=[];for(let _ of E){let X=new K(_);for await(let F of X.scan({cwd:Z,absolute:!0,onlyFiles:!0}))if(F.endsWith(".d.ts")&&!F.includes("node_modules"))M.push(F)}if(M.length===0)console.error("No .d.ts files found"),V.exit(1);console.log(`Optimizing ${M.length} declaration files...`);let T=0,R=0;for(let _ of M){let X=_;if(q.outdir){let C=J(Z,_);X=A(N(q.outdir),C);let w=$(X);if(!j(w))B(w,{recursive:!0});G(_,X)}let F=await Q(X,{removeUnusedImports:q.removeUnusedImports??!0,deduplicateDeclarations:q.deduplicate??!0,mergeInterfaces:q.mergeInterfaces??!0,inlineSimpleTypes:q.inlineTypes??!1,removeEmptyInterfaces:q.removeEmpty??!0,sortDeclarations:q.sort??!1,sortImports:q.sortImports??!0,minify:q.minify??!1,removeComments:q.removeComments??!1});R+=F.originalSize,T+=F.savings;let D=J(Z,X);console.log(` ${D}: ${F.originalSize}B -> ${F.optimizedSize}B (-${F.savingsPercent}%)`)}let I=R>0?Math.round(T/R*100):0;console.log(`
|
|
6
|
+
Total: ${R}B -> ${R-T}B (-${I}%)`)}catch(Q){console.error("Error optimizing files:",Q),V.exit(1)}});k.command("docs","Generate API documentation from source files").option("--root <path>","Root directory to scan for source files",{default:"./src"}).option("--outdir <path>","Output directory for documentation",{default:"./docs"}).option("--format <format>","Output format: markdown or html",{default:"markdown"}).option("--title <title>","Documentation title",{default:"API Documentation"}).option("--include-private","Include private members (prefixed with _)",{default:!1}).option("--include-internal","Include internal members (@internal)",{default:!1}).option("--group-by-category","Group entries by @category tag",{default:!1}).option("--source-url <url>","Base URL for source links").example("dtsx docs").example("dtsx docs --format html --outdir ./api-docs").example('dtsx docs --group-by-category --title "My API"').action(async(q)=>{try{let{generateDocs:Q}=await import("../chunk-a0gah6hn.js"),{Glob:K}=awaitPromise.resolve(globalThis.Bun),{resolve:N}=await import("path"),A=N(q.root||"./src"),J=new K("**/*.ts"),$=[];for await(let z of J.scan({cwd:A,absolute:!0,onlyFiles:!0}))if(!z.endsWith(".d.ts")&&!z.includes("node_modules"))$.push(z);if($.length===0)console.error("No TypeScript files found"),V.exit(1);console.log(`Found ${$.length} source files`),await Q($,{format:q.format||"markdown",outdir:N(q.outdir||"./docs"),title:q.title||"API Documentation",includePrivate:q.includePrivate??!1,includeInternal:q.includeInternal??!1,groupByCategory:q.groupByCategory??!1,includeSourceLinks:!!q.sourceUrl,sourceBaseUrl:q.sourceUrl})}catch(Q){console.error("Error generating documentation:",Q),V.exit(1)}});k.command("workspace","Generate declarations for all projects in a monorepo/workspace").option("--cwd <path>","Workspace root directory",{default:V.cwd()}).option("--parallel","Process projects in parallel",{default:!1}).option("--continue-on-error","Continue if a project fails",{default:!0}).option("--log-level <level>","Log level (debug, info, warn, error, silent)",{default:"info"}).example("dtsx workspace").example("dtsx workspace --cwd /path/to/monorepo").action(async(q)=>{try{let{generateMonorepo:Q,generateFromPackageWorkspaces:K}=await import("../chunk-wr3swrge.js"),{existsSync:N}=await import("fs"),{join:A,resolve:J}=await import("path"),$=J(q.cwd||V.cwd()),z=A($,"tsconfig.json"),B;if(N(z))B=await Q($,{logLevel:q.logLevel||"info",continueOnError:q.continueOnError??!0});else B=await K($,{logLevel:q.logLevel||"info",continueOnError:q.continueOnError??!0});if(!B.success)V.exit(1)}catch(Q){console.error("Error generating workspace declarations:",Q),V.exit(1)}});k.command("lsp","Start the Language Server Protocol server for IDE integration").example("dtsx lsp").action(async()=>{let{startLSPServer:q}=await import("../chunk-nqwz71ak.js");q()});k.command("check","Type check TypeScript files or validate generated declarations").option("--files <patterns>","Glob patterns for files to check",{default:"**/*.ts",type:[String]}).option("--declarations-only","Only check .d.ts files",{default:!1}).option("--tsconfig <path>","Path to tsconfig.json",{default:"tsconfig.json"}).option("--strict","Enable strict type checking",{default:!1}).option("--skip-lib-check","Skip checking library definitions",{default:!0}).option("--warnings-as-errors","Treat warnings as errors",{default:!1}).option("--max-errors <number>","Maximum errors before stopping",{default:0}).option("--isolated-declarations","Check if code follows isolated declarations best practices (recommended)",{default:!1}).option("--format <format>","Output format: text or json",{default:"text"}).example("dtsx check").example('dtsx check --files "src/**/*.ts" --strict').example('dtsx check --declarations-only --files "dist/**/*.d.ts"').example("dtsx check --isolated-declarations").action(async(q)=>{try{let{typeCheck:Q,checkIsolatedDeclarations:K,formatTypeCheckResults:N}=await import("../chunk-sw3m29sw.js"),{Glob:A}=awaitPromise.resolve(globalThis.Bun),{resolve:J,relative:$}=await import("path"),z=V.cwd(),B=q.files||["**/*.ts"],G=[];for(let Z of B){let E=new A(Z);for await(let M of E.scan({cwd:z,absolute:!0,onlyFiles:!0}))if(!M.includes("node_modules"))if(q.declarationsOnly){if(M.endsWith(".d.ts"))G.push(M)}else G.push(M)}if(G.length===0)console.error("No files found to check"),V.exit(1);if(q.isolatedDeclarations){console.log(`Checking ${G.length} files for isolated declarations best practices...`);let Z=await K(G,q.tsconfig?J(q.tsconfig):void 0),E=0,M=[];for(let[T,R]of Z){let I=$(z,T);if(!R.compatible)if(E+=R.issues.length,q.format==="json")M.push({file:I,compatible:!1,issues:R.issues});else{console.log(`
|
|
7
7
|
\u2717 ${I}`);for(let _ of R.issues)if(console.log(` ${_.line}:${_.column} - ${_.message}`),_.missingAnnotation)console.log(` Missing: ${_.missingAnnotation} type annotation`)}else if(q.format==="json")M.push({file:I,compatible:!0,issues:[]})}if(q.format==="json")console.log(JSON.stringify(M,null,2));else if(E>0)console.log(`
|
|
8
8
|
${G.length} files checked, ${E} recommendations found`),console.log("Tip: Adding explicit type annotations improves .d.ts accuracy");else console.log(`
|
|
9
9
|
${G.length} files checked, all follow isolated declarations best practices`);V.exit(E>0?1:0)}console.log(`Type checking ${G.length} files...`);let j=await Q(G,{tsconfigPath:q.tsconfig?J(q.tsconfig):void 0,strict:q.strict??!1,declarationsOnly:q.declarationsOnly??!1,skipLibCheck:q.skipLibCheck??!0,warningsAsErrors:q.warningsAsErrors??!1,maxErrors:q.maxErrors||void 0});if(q.format==="json")console.log(JSON.stringify(j,null,2));else console.log(N(j));V.exit(j.success?0:1)}catch(Q){console.error("Error during type checking:",Q),V.exit(1)}});k.command("convert","Convert TypeScript types to different schema formats").option("--files <patterns>","Glob patterns for TypeScript files",{default:"**/*.ts",type:[String]}).option("--format <format>","Output format: json-schema, zod, valibot, io-ts, yup, arktype",{default:"json-schema"}).option("--outdir <path>","Output directory for converted files",{default:"./schemas"}).option("--include-descriptions","Include JSDoc descriptions in output",{default:!0}).option("--all-optional","Make all properties optional",{default:!1}).option("--use-infer","Include inferred types (for Zod, Valibot, etc.)",{default:!0}).option("--json-schema-draft <version>","JSON Schema draft version: 2020-12, 2019-09, draft-07",{default:"2020-12"}).example("dtsx convert --format zod").example('dtsx convert --format json-schema --files "src/types/**/*.ts"').example("dtsx convert --format valibot --outdir ./validation").action(async(q)=>{try{let Q=await import("../chunk-xtee8g1a.js"),{extractDeclarations:K}=await import("../chunk-rd7n0yj1.js"),{Glob:N}=awaitPromise.resolve(globalThis.Bun),{resolve:A,relative:J,join:$,dirname:z,basename:B}=await import("path"),{mkdirSync:G,existsSync:j,readFileSync:Z,writeFileSync:E}=await import("fs"),M=V.cwd(),T=q.files||["**/*.ts"],R=q.format||"json-schema",I=A(q.outdir||"./schemas"),_=[];for(let D of T){let C=new N(D);for await(let w of C.scan({cwd:M,absolute:!0,onlyFiles:!0}))if(!w.endsWith(".d.ts")&&!w.includes("node_modules"))_.push(w)}if(_.length===0)console.error("No TypeScript files found"),V.exit(1);if(console.log(`Converting ${_.length} files to ${R} format...`),!j(I))G(I,{recursive:!0});let X=0,F=0;for(let D of _){let C=Z(D,"utf-8"),U=K(C,D).filter((d)=>d.kind==="interface"||d.kind==="type");if(U.length===0)continue;let L=Q.convertToFormat(U,{format:R,includeDescriptions:q.includeDescriptions??!0,allOptional:q.allOptional??!1,useInfer:q.useInfer??!0,jsonSchemaDraft:q.jsonSchemaDraft||"2020-12"}),a=J(M,D),l=B(D,".ts"),p=Q.getFormatExtension(R),O=$(I,z(a),`${l}${p}`),u=z(O);if(!j(u))G(u,{recursive:!0});E(O,L),X+=U.length,F++,console.log(` ${J(M,O)} (${U.length} types)`)}console.log(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-mcdb3q06.js";var e="@stacksjs/dtsx",i="module",n="0.9.
|
|
2
|
+
import"./chunk-mcdb3q06.js";var e="@stacksjs/dtsx",i="module",n="0.9.21",r=!0,u="A modern, fast .d.ts generation tool, powered by Bun.",c="Chris Breuer <chris@stacksjs.org>",o="MIT",p="https://github.com/stacksjs/dtsx#readme",a={type:"git",url:"git+https://github.com/stacksjs/dtsx.git"},b={url:"https://github.com/stacksjs/dtsx/issues"},d=["dts","generation","isolated declarations","development","bun","stacks","typescript","javascript"],m={".":{import:"./dist/index.js"},"./*":{import:"./dist/*"}},g="./dist/index.js",l="./dist/index.d.ts",x={dtsx:"./dist/cli.js"},k=["dist"],h={benchmark:"bun benchmark/index.ts",build:"bun --filter './packages/dtsx' build",test:"bun test",lint:"bun x --bun pickier .","lint:fix":"bun x --bun pickier . --fix",format:"bun x --bun pickier . --format","format:fix":"bun x --bun pickier . --format --write",changelog:"bun x logsmith --verbose","changelog:generate":"bun x logsmith --output CHANGELOG.md",release:"bun --bun run changelog:generate && bun x --bun bumpx prompt --recursive","release:patch":"bun --bun run changelog:generate && bun x --bun bumpx patch --recursive --yes",typecheck:"bun x tsc --noEmit","dev:docs":"bun --bun vitepress dev docs","build:docs":"bun --bun vitepress build docs","preview:docs":"bun --bun vitepress preview docs"},v={"@stacksjs/bumpx":"^0.2.4","@stacksjs/bunpress":"^0.1.4","@stacksjs/clapp":"^0.2.0",pickier:"^0.1.20","@stacksjs/gitlint":"^0.1.5","@stacksjs/logsmith":"^0.2.1","@types/bun":"^1.3.11","@typescript/native-preview":"^7.0.0-dev.20260311.1","buddy-bot":"^0.9.18","bun-git-hooks":"^0.3.1","bun-plugin-dtsx":"workspace:*",mitata:"^1.0.34","oxc-transform":"^0.121.0",typescript:"^5.9.3"},j=["packages/*"],y={name:e,type:i,version:n,private:r,description:u,author:c,license:o,homepage:p,repository:a,bugs:b,keywords:d,exports:m,module:g,types:l,bin:x,files:k,scripts:h,devDependencies:v,workspaces:j,"git-hooks":{"pre-commit":{"staged-lint":{"*.{js,ts,json,yaml,yml,md}":"bun x --bun pickier lint --fix"}},"commit-msg":"bun x gitlint --edit .git/COMMIT_EDITMSG"}};export{j as workspaces,n as version,l as types,i as type,h as scripts,a as repository,r as private,e as name,g as module,o as license,d as keywords,p as homepage,k as files,m as exports,v as devDependencies,u as description,y as default,b as bugs,x as bin,c as author};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as K}from"./chunk-
|
|
2
|
+
import{tb as K}from"./chunk-af12rv0y.js";function L(N={}){let{buildStart:P=!0,buildEnd:Q=!1,writeBundle:T=!1,modes:y,onGenerated:U,onError:H,...W}=N,I="production",z=async()=>{try{let q=await K(W);U?.(q)}catch(q){let J=q instanceof Error?q:Error(String(q));if(H?.(J),!H)console.error("[dtsx] Generation failed:",J.message)}},F=()=>{if(!y||y.length===0)return!0;return y.includes(I)};return{name:"dtsx",apply(q){return I=q.mode,!0},async buildStart(){if(P&&F())await z()},async buildEnd(){if(Q&&F())await z()},async writeBundle(){if(T&&F())await z()}}}var Y=L,_=L;
|
|
3
3
|
export{L as ca,Y as da,_ as ea};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as z}from"./chunk-
|
|
2
|
+
import{tb as z}from"./chunk-af12rv0y.js";function C(F={}){let{preBuild:H=!1,postBuild:I=!0,onGenerated:J,onError:w,...q}=F,y=async()=>{try{let j=await z(q);J?.(j)}catch(j){let k=j instanceof Error?j:Error(String(j));if(w?.(k),!w)console.error("[dtsx] Generation failed:",k.message)}};return{name:"dtsx",async setup(j){let k=j.config;if(!q.entrypoints&&k.entrypoints)q.entrypoints=k.entrypoints;if(!q.outdir&&k.outdir)q.outdir=k.outdir;if(!q.root&&k.root)q.root=k.root;if(H)j.onStart(async()=>{await y()});if(I){let v=!1;j.onLoad({filter:/.*/},async(K)=>{if(!v)queueMicrotask(async()=>{if(!v)v=!0,await y()});return})}}}}var M=C,P=C;
|
|
3
3
|
export{C as fa,M as ga,P as ha};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as I}from"./chunk-
|
|
2
|
+
import{tb as I}from"./chunk-af12rv0y.js";function z(J={}){let{onBuildStart:K=!1,onBuildEnd:L=!0,onGenerated:M,onError:C,...N}=J,w,q,F=async()=>{let j={...N};if(!j.outdir&&w)j.outdir=w;if(!j.entrypoints&&q)j.entrypoints=q;try{let k=await I(j);M?.(k)}catch(k){let H=k instanceof Error?k:Error(String(k));if(C?.(H),!C)console.error("[dtsx] Generation failed:",H.message)}};return{name:"dtsx",esbuildOptions(j){if(j.outdir&&typeof j.outdir==="string")w=j.outdir;if(j.entryPoints){if(Array.isArray(j.entryPoints))q=j.entryPoints;else if(typeof j.entryPoints==="object")q=Object.values(j.entryPoints)}},async buildStart(){if(K)await F()},async buildEnd(j){if(L)await F()}}}var R=z,T=z,V=z;
|
|
3
3
|
export{z as ma,R as na,T as oa,V as pa};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{ec as a}from"./chunk-ft0nf9jb.js";import{hc as CY}from"./chunk-2n1bbm2c.js";import{lc as UJ}from"./chunk-y2pe3jq3.js";import{Cc as iJ}from"./chunk-vx4a5crm.js";import{Uc as f}from"./chunk-7hy98p24.js";import{Wc as _,Yc as e}from"./chunk-gssantc8.js";import{bd as xY,dd as TY}from"./chunk-mcdb3q06.js";var{Glob:oJ}=globalThis.Bun;import{mkdir as t}from"fs/promises";import{availableParallelism as fY}from"os";import{dirname as m,relative as D,resolve as x}from"path";import{existsSync as GJ,mkdirSync as JY,readFileSync as YY,writeFileSync as ZY}from"fs";import{dirname as $Y,relative as XY,resolve as GY}from"path";async function OJ(J,Y,Z){let $=new Map,X=[],G=new Set,Q=0,H=0,U=0,W=[];for(let z of J){let B=Y.get(z);if(!B)continue;W.push({file:z,decls:a(B,z,Z.keepComments)})}for(let{file:z,decls:B}of W){Q+=B.length;for(let k of B)if(k.kind==="import"){H++;let R=k.source||"";if(R.startsWith("."))continue;if(!$.has(R))$.set(R,{source:R,specifiers:new Map,isTypeOnly:k.isTypeOnly||!1,isSideEffect:k.isSideEffect||!1});let L=$.get(R);if(k.specifiers)for(let F of k.specifiers){let S=F.alias||F.name;if(!L.specifiers.has(S))L.specifiers.set(S,{name:F.name,alias:F.alias,isType:F.isType||!1})}if(!k.isTypeOnly)L.isTypeOnly=!1}else if(k.isExported||k.kind==="export"){if(U++,k.kind==="export"&&k.source&&(k.source.startsWith(".")||k.source.startsWith("/")))continue;if(k.name&&G.has(k.name))continue;if(k.name)G.add(k.name);X.push({declaration:k,file:z})}}let V=[];V.push("/**"),V.push(" * Bundled TypeScript declarations"),V.push(` * Generated from ${J.length} source files`),V.push(" */"),V.push("");let T=Z.importOrder||["bun"],N=Array.from($.values()),q=Array(N.length);for(let z=0;z<N.length;z++){let B=N[z].source,k=T.length;for(let R=0;R<T.length;R++)if(B.startsWith(T[R])){k=R;break}q[z]=k}let O=N.map((z,B)=>B);O.sort((z,B)=>{let k=q[z],R=q[B];if(k!==R)return k-R;return N[z].source.localeCompare(N[B].source)});let j=O.map((z)=>N[z]);for(let z of j)if(z.isSideEffect)V.push(`import '${z.source}';`);else if(z.specifiers.size>0){let k=Array.from(z.specifiers.values()).map((L)=>{let F=L.isType?"type ":"";return L.alias?`${F}${L.name} as ${L.alias}`:`${F}${L.name}`}),R=z.isTypeOnly?"type ":"";V.push(`import ${R}{ ${k.join(", ")} } from '${z.source}';`)}if(j.length>0)V.push("");let K=new Map;for(let{declaration:z,file:B}of X){if(!K.has(B))K.set(B,[]);K.get(B).push(z)}for(let[z,B]of K){let k=XY(Z.cwd,z);V.push(`// From: ${k}`);for(let R of B){if(Z.keepComments&&R.leadingComments)for(let L of R.leadingComments)V.push(L);V.push(RJ(R))}V.push("")}let A=V.join(`
|
|
3
|
+
`);return{content:A,files:J,declarationCount:Q,importCount:H,exportCount:U,size:Buffer.byteLength(A,"utf8"),warnings:[]}}function RJ(J){if(J.text){let Z=J.text.trim();if(J.isExported&&!Z.startsWith("export"))Z=`export ${Z}`;if(!Z.endsWith(";")&&!Z.endsWith("}"))Z+=";";return Z}let Y=[];if(J.isExported)Y.push("export");if(J.isDefault)Y.push("default");switch(J.kind){case"function":if(Y.push("declare function"),Y.push(J.name),J.generics)Y.push(J.generics);if(Y.push(`(${QY(J.parameters)})`),J.returnType)Y.push(`: ${J.returnType}`);break;case"variable":if(Y.push("declare const"),Y.push(J.name),J.typeAnnotation)Y.push(`: ${J.typeAnnotation}`);break;case"interface":if(Y.push("interface"),Y.push(J.name),J.generics)Y.push(J.generics);if(J.extends)Y.push(`extends ${J.extends}`);if(Y.push("{"),J.members)for(let Z of J.members)Y.push(` ${Z.name}${Z.typeAnnotation?`: ${Z.typeAnnotation}`:""};`);Y.push("}");break;case"type":if(Y.push("type"),Y.push(J.name),J.generics)Y.push(J.generics);Y.push("="),Y.push(J.typeAnnotation||"unknown");break;case"class":if(Y.push("declare class"),Y.push(J.name),J.generics)Y.push(J.generics);if(J.extends)Y.push(`extends ${J.extends}`);if(J.implements&&J.implements.length>0)Y.push(`implements ${J.implements.join(", ")}`);if(Y.push("{"),J.members)for(let Z of J.members)Y.push(` ${RJ(Z)}`);Y.push("}");break;case"enum":if(Y.push("declare enum"),Y.push(J.name),Y.push("{"),J.members){let Z=J.members.map(($)=>$.value!==void 0?`${$.name} = ${$.value}`:$.name);Y.push(` ${Z.join(`,
|
|
4
|
+
`)}`)}Y.push("}");break;default:return J.text||""}return Y.join(" ")}function QY(J){if(!J||J.length===0)return"";return J.map((Y)=>{let Z="";if(Y.rest)Z+="...";if(Z+=Y.name,Y.optional)Z+="?";if(Y.type)Z+=`: ${Y.type}`;if(Y.defaultValue)Z+=` = ${Y.defaultValue}`;return Z}).join(", ")}async function LJ(J,Y={}){let Z=[],$=new Map,X=[],G=[],Q=new Set,H=0,U=0,W=0;for(let q of J){if(!GJ(q)){Z.push(`File not found: ${q}`);continue}let O=YY(q,"utf-8");G.push(q);let j=O.split(`
|
|
5
|
+
`),K=[],A=0,z=!1;for(let B of j){let k=B.trim();if(!k&&!z)continue;if(k.startsWith("import ")){U++;let L=k.match(/import\s+(type\s+)?(?:\{([^}]+)\}|(\w+)|\*\s+as\s+(\w+))\s+from\s+['"]([^'"]+)['"]/);if(L){let[,F,S,M,w,v]=L;if(Y.externals?.some((C)=>v.startsWith(C))){X.push(k);continue}if(v.startsWith("."))continue;if(!$.has(v))$.set(v,{source:v,specifiers:new Map,isTypeOnly:!!F,isSideEffect:!1});let c=$.get(v);if(S){let C=S.split(",").map((YJ)=>YJ.trim());for(let YJ of C){let[ZJ,$J]=YJ.split(/\s+as\s+/).map((eJ)=>eJ.trim()),NJ=ZJ.startsWith("type "),XJ=NJ?ZJ.replace("type ",""):ZJ;c.specifiers.set($J||XJ,{name:XJ,alias:$J!==XJ?$J:void 0,isType:NJ})}}if(!F)c.isTypeOnly=!1}continue}if(/^(export\s+)?(declare\s+)?(interface|type|class|function|const|let|var|enum|namespace|module)\s/.test(k)){if(z=!0,K=[B],A=(B.match(/\{/g)||[]).length-(B.match(/\}/g)||[]).length,A===0&&(k.endsWith(";")||!k.includes("{"))){let L=l(k);if(!Q.has(L)||!Y.mergeDuplicates){if(Q.add(L),X.push(B),H++,k.startsWith("export"))W++}z=!1,K=[]}}else if(z){if(K.push(B),A+=(B.match(/\{/g)||[]).length-(B.match(/\}/g)||[]).length,A<=0){let L=K.join(`
|
|
6
|
+
`),F=l(K[0]);if(!Q.has(F)||!Y.mergeDuplicates){if(Q.add(F),X.push(L),H++,K[0].trim().startsWith("export"))W++}z=!1,K=[]}}else if(k.startsWith("export ")&&!k.includes("declare"))X.push(B),W++}}let V=[];if(Y.banner)V.push(Y.banner),V.push("");if(Y.includeReferences&&Y.references){for(let q of Y.references)V.push(`/// <reference types="${q}" />`);V.push("")}let T=Array.from($.values()).sort((q,O)=>q.source.localeCompare(O.source));for(let q of T)if(q.specifiers.size>0){let j=Array.from(q.specifiers.values()).map((A)=>{let z=A.isType?"type ":"";return A.alias?`${z}${A.name} as ${A.alias}`:`${z}${A.name}`}),K=q.isTypeOnly?"type ":"";V.push(`import ${K}{ ${j.join(", ")} } from '${q.source}';`)}if(T.length>0)V.push("");if(Y.ambient&&Y.moduleName){V.push(`declare module '${Y.moduleName}' {`);for(let q of X){let O=q.split(`
|
|
7
|
+
`).map((j)=>` ${j.replace(/^(\s*)(export\s+)?declare\s+/,"$1$2")}`).join(`
|
|
8
|
+
`);V.push(O)}V.push("}")}else{if(Y.sortDeclarations)X.sort((q,O)=>{let j=l(q),K=l(O);return j.localeCompare(K)});for(let q of X)V.push(q)}if(Y.footer)V.push(""),V.push(Y.footer);let N=V.join(`
|
|
9
|
+
`);return{content:N,files:G,declarationCount:H,importCount:U,exportCount:W,size:Buffer.byteLength(N,"utf-8"),warnings:Z}}function l(J){let Y=J.match(/(interface|type|class|function|const|let|var|enum|namespace|module)\s+(\w+)/);return Y?`${Y[1]}:${Y[2]}`:J.trim()}async function UY(J,Y,Z={}){let $=await LJ(J,Z),X=$Y(Y);if(!GJ(X))JY(X,{recursive:!0});return ZY(Y,$.content),$}function rY(J={}){return{bundle:(Y)=>LJ(Y,J),bundleAndWrite:(Y,Z)=>UY(Y,Z,{...J,output:Z})}}async function tY(J,Y=process.cwd()){let Z=Array.isArray(J)?J:[J],$=[];for(let X of Z){if(X.includes("*"))continue;let G=GY(Y,X);if(GJ(G))$.push(G)}return $}import{existsSync as n,mkdirSync as zY,readFileSync as zJ,rmSync as VY,statSync as MJ,writeFileSync as FJ}from"fs";import{join as SJ,relative as s,resolve as jY}from"path";var QJ=1,VJ=".dtsx-cache",WY="manifest.json";class jJ{cacheDir;manifestPath;manifest=null;configHash;constructor(J){this.cacheDir=jY(J.cwd,VJ),this.manifestPath=SJ(this.cacheDir,WY),this.configHash=this.hashConfig(J)}hashConfig(J){let Y={keepComments:J.keepComments,importOrder:J.importOrder,outputStructure:J.outputStructure};return String(UJ(JSON.stringify(Y)))}hashString(J){return String(UJ(J))}load(){try{if(!n(this.manifestPath))return!1;let J=zJ(this.manifestPath,"utf-8"),Y=JSON.parse(J);if(Y.version!==QJ)return!1;if(Y.configHash!==this.configHash)return!1;return this.manifest=Y,!0}catch{return!1}}save(){if(!this.manifest)this.manifest={version:QJ,configHash:this.configHash,entries:{},createdAt:Date.now(),updatedAt:Date.now()};if(this.manifest.updatedAt=Date.now(),!n(this.cacheDir))zY(this.cacheDir,{recursive:!0});FJ(this.manifestPath,JSON.stringify(this.manifest,null,2))}needsRegeneration(J,Y){return this.getCachedIfValid(J,Y)===null}getCached(J,Y){return this.getCachedIfValid(J,Y)}getCachedIfValid(J,Y){if(!this.manifest)return null;let Z=s(Y,J),$=this.manifest.entries[Z];if(!$)return null;try{let G=MJ(J).mtimeMs;if(G>$.sourceMtime){let Q=zJ(J,"utf-8");if(this.hashString(Q)!==$.sourceHash)return null;$.sourceMtime=G}return $.dtsContent}catch{return null}}update(J,Y,Z,$){if(!this.manifest)this.manifest={version:QJ,configHash:this.configHash,entries:{},createdAt:Date.now(),updatedAt:Date.now()};let X=s($,J),G;try{G=MJ(J).mtimeMs}catch{G=Date.now()}this.manifest.entries[X]={sourcePath:X,sourceHash:this.hashString(Y),sourceMtime:G,dtsContent:Z,dtsHash:this.hashString(Z),generatedAt:Date.now(),configHash:this.configHash}}remove(J,Y){if(!this.manifest)return;let Z=s(Y,J);delete this.manifest.entries[Z]}clear(){this.manifest=null;try{if(n(this.manifestPath))VY(this.cacheDir,{recursive:!0,force:!0})}catch{}}getStats(){if(!this.manifest)return{entries:0,size:0};let J=Object.keys(this.manifest.entries).length,Y=0;for(let Z of Object.values(this.manifest.entries))Y+=Z.dtsContent.length;return{entries:J,size:Y}}prune(J,Y){if(!this.manifest)return 0;let Z=0,$=new Set(Array.from(J).map((X)=>s(Y,X)));for(let X of Object.keys(this.manifest.entries))if(!$.has(X))delete this.manifest.entries[X],Z++;return Z}}function wJ(J){let Y=SJ(J,".gitignore");try{let Z="";if(n(Y))Z=zJ(Y,"utf-8");if(!Z.includes(VJ)){let $=`${Z.trimEnd()}
|
|
10
|
+
|
|
11
|
+
# dtsx cache
|
|
12
|
+
${VJ}/
|
|
13
|
+
`;FJ(Y,$)}}catch{}}import{spawn as HY}from"child_process";import{readFile as WJ,stat as DJ,writeFile as KY}from"fs/promises";var I=typeof globalThis.Bun<"u",QZ=!I&&typeof process<"u"&&!!process.versions?.node,UZ=I?"bun":"node";class vJ{name;_size=-1;constructor(J){this.name=J}async exists(){try{return await DJ(this.name),!0}catch{return!1}}async text(){return WJ(this.name,"utf-8")}async arrayBuffer(){let J=await WJ(this.name);return J.buffer.slice(J.byteOffset,J.byteOffset+J.byteLength)}get size(){if(this._size===-1)return-1;return this._size}}class IJ{pid;stdout;stderr;stdin;exited;process;constructor(J){this.process=J,this.pid=J.pid??0,this.stdout=J.stdout,this.stderr=J.stderr,this.stdin=J.stdin,this.exited=new Promise((Y)=>{J.on("exit",(Z)=>{Y(Z??0)}),J.on("error",()=>{Y(1)})})}kill(J){this.process.kill(J)}ref(){this.process.ref()}unref(){this.process.unref()}}function EJ(J){if(I)return globalThis.Bun.file(J);return new vJ(J)}async function HJ(J,Y){if(I)return globalThis.Bun.write(J,Y);let Z=typeof Y==="string"?Y:Y instanceof ArrayBuffer?Buffer.from(Y):Y;return await KY(J,Z),typeof Y==="string"?Buffer.byteLength(Y):Y.byteLength}function yJ(J,Y={}){if(I)return globalThis.Bun.spawn(J,Y);let Z=Array.isArray(J)?J:[J],[$,...X]=Z,G={cwd:Y.cwd,env:Y.env,stdio:[Y.stdin??"pipe",Y.stdout??"pipe",Y.stderr??"pipe"]},Q=HY($,X,G);return new IJ(Q)}async function y(J){if(I)return globalThis.Bun.file(J).text();return WJ(J,"utf-8")}async function zZ(J){if(I)return globalThis.Bun.file(J).exists();try{return await DJ(J),!0}catch{return!1}}async function VZ(J,Y){await HJ(J,Y)}function jZ(){if(I)return{name:"bun",version:globalThis.Bun.version,isBun:!0,isNode:!1};return{name:"node",version:process.versions.node,isBun:!1,isNode:!0}}var g={PARSE_ERROR:"PARSE_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",FILE_NOT_FOUND:"FILE_NOT_FOUND",FILE_READ_ERROR:"FILE_READ_ERROR",FILE_WRITE_ERROR:"FILE_WRITE_ERROR",TYPE_INFERENCE_ERROR:"TYPE_INFERENCE_ERROR",UNRESOLVED_TYPE:"UNRESOLVED_TYPE",EXTRACTION_ERROR:"EXTRACTION_ERROR",PROCESSING_ERROR:"PROCESSING_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",INVALID_DECLARATION:"INVALID_DECLARATION",CONFIG_ERROR:"CONFIG_ERROR",INVALID_ENTRYPOINT:"INVALID_ENTRYPOINT",CIRCULAR_DEPENDENCY:"CIRCULAR_DEPENDENCY",TIMEOUT_ERROR:"TIMEOUT_ERROR",NOT_SUPPORTED:"NOT_SUPPORTED",UNKNOWN_ERROR:"UNKNOWN_ERROR"};class E extends Error{code;context;constructor(J,Y="UNKNOWN_ERROR",Z){super(J);if(this.name="DtsxError",this.code=Y,this.context=Z,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toString(){let J=`${this.name} [${this.code}]: ${this.message}`;if(this.context)J+=`
|
|
14
|
+
Context: ${JSON.stringify(this.context,null,2)}`;return J}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}}class bJ extends E{filePath;line;column;constructor(J,Y,Z){super(J,"PARSE_ERROR",{filePath:Y,line:Z?.line,column:Z?.column});if(this.name="ParseError",this.filePath=Y,this.line=Z?.line,this.column=Z?.column,Z?.cause)this.cause=Z.cause}get locationString(){if(this.line!==void 0&&this.column!==void 0)return`${this.filePath}:${this.line}:${this.column}`;return this.line!==void 0?`${this.filePath}:${this.line}`:this.filePath}}class _Y extends E{filePath;declarationKind;constructor(J,Y,Z,$){super(J,"EXTRACTION_ERROR",{filePath:Y,declarationKind:Z});if(this.name="ExtractionError",this.filePath=Y,this.declarationKind=Z,$)this.cause=$}}class qY extends E{declarationName;constructor(J,Y,Z){super(J,"PROCESSING_ERROR",{declarationName:Y});if(this.name="ProcessingError",this.declarationName=Y,Z)this.cause=Z}}class xJ extends E{filePath;operation;constructor(J,Y,Z,$){super(J,Z==="read"?"FILE_READ_ERROR":"FILE_WRITE_ERROR",{filePath:Y,operation:Z});if(this.name="FileError",this.filePath=Y,this.operation=Z,$)this.cause=$}}class CJ extends E{configPath;invalidKey;constructor(J,Y){super(J,"CONFIG_ERROR",{configPath:Y?.configPath,invalidKey:Y?.invalidKey});if(this.name="ConfigError",this.configPath=Y?.configPath,this.invalidKey=Y?.invalidKey,Y?.cause)this.cause=Y.cause}}class BY extends E{cycle;constructor(J){super(`Circular dependency detected: ${J.join(" -> ")}`,"CIRCULAR_DEPENDENCY",{cycle:J});this.name="CircularDependencyError",this.cycle=J}}function HZ(J){return J instanceof E}function KZ(J){return J instanceof bJ}function _Z(J){return J instanceof xJ}function qZ(J){return J instanceof CJ}function BZ(J,Y="UNKNOWN_ERROR",Z){if(J instanceof E)return J;let $=Z||(J instanceof Error?J.message:String(J)),X=new E($,Y);if(J instanceof Error)X.cause=J;return X}function TZ(J,Y){let Z=1,$=1,X=0;for(let G of J){if(X>=Y)break;if(G===`
|
|
15
|
+
`)Z++,$=1;else $++;X++}return{line:Z,column:$,offset:Y}}function AZ(J,Y,Z,$){let X=J.split(`
|
|
16
|
+
`),G=Y.line-1,Q=[];if($)Q.push(`${$}:${Y.line}:${Y.column}`);else Q.push(`Line ${Y.line}, Column ${Y.column}`);Q.push(`Error: ${Z}`),Q.push("");let H=Math.max(0,G-1),U=Math.min(X.length-1,G+1);for(let W=H;W<=U;W++){let V=(W+1).toString().padStart(4," "),T=W===G?">":" ";if(Q.push(`${T} ${V} | ${X[W]}`),W===G){let N=" ".repeat(8+Y.column-1);Q.push(`${N}^`)}}return Q.join(`
|
|
17
|
+
`)}function KJ(J,Y,Z){let $={file:Y,message:"Unknown error",code:g.UNKNOWN_ERROR};if(J instanceof Error){$.message=J.message,$.stack=J.stack;let X=J.message.match(/\((\d+),(\d+)\)/);if(X)$.location={line:Number.parseInt(X[1],10),column:Number.parseInt(X[2],10)};if(J.message.includes("Cannot find")||J.message.includes("not found"))$.code=g.FILE_NOT_FOUND,$.suggestion="Check that the file path is correct and the file exists.";else if(J.message.includes("syntax")||J.message.includes("Unexpected token"))$.code=g.SYNTAX_ERROR,$.suggestion="Check for syntax errors in your TypeScript code.";else if(J.message.includes("type")&&J.message.includes("cannot"))$.code=g.TYPE_INFERENCE_ERROR,$.suggestion="Add explicit type annotations to help with type inference.";else if(J.message.includes("parse")||J.message.includes("Parse"))$.code=g.PARSE_ERROR,$.suggestion="The file contains invalid TypeScript syntax."}else if(typeof J==="string")$.message=J;return $}function PJ(J,Y){let Z=[],$=J.file;if(J.location)$+=`:${J.location.line}:${J.location.column}`;if(J.code)$+=` [${J.code}]`;if(Z.push($),Z.push(` Error: ${J.message}`),Y&&J.location){Z.push("");let X=Y.split(`
|
|
18
|
+
`),G=J.location.line-1;if(G>=0&&G<X.length){let Q=Math.max(0,G-1),H=Math.min(X.length-1,G+1);for(let U=Q;U<=H;U++){let W=(U+1).toString().padStart(4," "),V=U===G?">":" ";if(Z.push(` ${V} ${W} | ${X[U]}`),U===G&&J.location.column>0){let T=" ".repeat(10+J.location.column-1);Z.push(` ${T}^`)}}}}if(J.suggestion)Z.push(""),Z.push(` Suggestion: ${J.suggestion}`);return Z.join(`
|
|
19
|
+
`)}function kZ(J){if(J.length===0)return"No errors";let Y=new Map;for(let $ of J){let X=$.code||"UNKNOWN";Y.set(X,(Y.get(X)||0)+1)}let Z=[`${J.length} error(s) found:`];for(let[$,X]of Y.entries())Z.push(` - ${$}: ${X}`);return Z.join(`
|
|
20
|
+
`)}var i=null,b=null;async function AY(){if(i!==null)return i;try{return b=await import("prettier"),i=!0,!0}catch{return i=!1,!1}}async function kY(J,Y){if(!b)return null;try{if(Y&&b.resolveConfig){let Z=await b.resolveConfig(Y);if(Z)return Z}if(J&&b.resolveConfig){let Z=await b.resolveConfig(J);if(Z)return Z}return null}catch{return null}}async function NY(J,Y){if(!b)throw Error("Prettier is not available");let Z={...Y,parser:Y.parser||"typescript"};return b.format(J,Z)}function OY(J,Y={}){let{indentSize:Z=2,useTabs:$=!1,maxLineWidth:X=100,trailingNewline:G=!0,normalizeWhitespace:Q=!0,sortImports:H=!0,groupImports:U=!0}=Y,W=J,V=$?"\t":" ".repeat(Z);if(W.indexOf(`\r
|
|
21
|
+
`)!==-1)W=W.replace(/\r\n/g,`
|
|
22
|
+
`);if(Q){if(/[ \t]\n/.test(W)||/[ \t]$/.test(W))W=W.replace(/[ \t]+$/gm,"");if(W.indexOf(`
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
`)!==-1)W=W.replace(/\n{3,}/g,`
|
|
26
|
+
|
|
27
|
+
`);W=RY(W,V)}if(H||U)W=LY(W,{sort:H,group:U});if(X>0)W=FY(W,X,V);if(G&&!W.endsWith(`
|
|
28
|
+
`))W+=`
|
|
29
|
+
`;return W}function RY(J,Y){let Z=J.split(`
|
|
30
|
+
`),$=[];for(let X of Z){let G=X.match(/^(\s*)(.*)$/);if(!G){$.push(X);continue}let[,Q,H]=G;if(!H){$.push("");continue}let U=Q.replace(/\t/g," ").length,W=Math.floor(U/2);$.push(Y.repeat(W)+H)}return $.join(`
|
|
31
|
+
`)}function LY(J,Y){let Z=J.split(`
|
|
32
|
+
`),$=[],X=[],G=!1,Q=0;for(let U=0;U<Z.length;U++){let W=Z[U],V=W.match(/^(import\s+(?:type\s+)?.*from\s+['"])([^'"]+)(['"].*)$/);if(V){G=!0,Q=U;let T=V[1];$.push({line:W,source:V[2],isType:T.startsWith("import type ")||T.startsWith("import type\t")})}else if(G&&W.trim()==="")continue;else{if(G)G=!1;X.push(W)}}if($.length===0)return J;if(Y.sort)$.sort((U,W)=>{if(U.isType!==W.isType)return U.isType?1:-1;return MY(U.source,W.source)});let H;if(Y.group){let U=[],W=[],V=[],T=[],N=[];for(let q=0;q<$.length;q++){let O=$[q],j=O.source;if(j.charCodeAt(0)===46)N.push(O);else if(j.startsWith("node:"))U.push(O);else if(j.charCodeAt(0)===64)T.push(O);else if(j.includes("/"))V.push(O);else W.push(O)}H=[...U.map((q)=>q.line),...U.length>0&&W.length>0?[""]:[],...W.map((q)=>q.line),...(U.length>0||W.length>0)&&V.length>0?[""]:[],...V.map((q)=>q.line),...T.length>0&&(U.length>0||W.length>0||V.length>0)?[""]:[],...T.map((q)=>q.line),...N.length>0?[""]:[],...N.map((q)=>q.line)]}else H=$.map((U)=>U.line);return[...H,"",...X].join(`
|
|
33
|
+
`)}function MY(J,Y){let Z=J.startsWith("node:"),$=Y.startsWith("node:");if(Z!==$)return Z?-1:1;let X=J.startsWith("."),G=Y.startsWith(".");if(X!==G)return X?1:-1;return J.localeCompare(Y)}function FY(J,Y,Z){let $=J.split(`
|
|
34
|
+
`),X=[];for(let G of $){if(G.length<=Y){X.push(G);continue}if(G.trimStart().startsWith("import ")){X.push(G);continue}let Q=G.match(/^(\s*)/)?.[1]||"",H=Q+Z;if(G.includes("{")&&G.includes("}")){let U=SY(G,Y,Q,H);X.push(...U);continue}if(G.includes(" | ")){let U=wY(G,Y,Q,H);X.push(...U);continue}X.push(G)}return X.join(`
|
|
35
|
+
`)}function SY(J,Y,Z,$){let X=J.match(/^(\s*)(.*?)(\{)(.+)(\}.*)$/);if(!X)return[J];let[,,G,Q,H,U]=X,W=H.split(/;\s*|,\s*/).filter((T)=>T.trim());if(W.length<=1)return[J];return[`${Z}${G}${Q}`,...W.map((T)=>`${$}${T.trim()};`),`${Z}${U.trim()}`]}function wY(J,Y,Z,$){let X=J.match(/^(\s*)(.*?=\s*)(.+)$/);if(!X)return[J];let[,,G,Q]=X,H=Q.split(/\s*\|\s*/).filter((W)=>W.trim());if(H.length<=2)return[J];return[`${Z}${G}`,...H.map((W,V)=>`${$}${V>0?"| ":" "}${W.trim()}`)]}async function d(J,Y={},Z){let $=[];if(Y.usePrettier!==!1){if(await AY())try{let H={...await kY(Y.prettierConfigPath,Z),...Y.prettierOptions,parser:"typescript"};return{content:await NY(J,H),usedPrettier:!0}}catch(Q){$.push(`Prettier formatting failed: ${Q}. Using built-in formatter.`)}else if(Y.usePrettier===!0)$.push("Prettier requested but not available. Using built-in formatter.")}return{content:OY(J,Y.builtIn),usedPrettier:!1,warnings:$.length>0?$:void 0}}async function DY(J,Y={}){let Z=new Map;for(let[$,X]of J){let G=await d(X,Y,$);Z.set($,G)}return Z}function OZ(J={}){return{format:(Y,Z)=>d(Y,J,Z),formatMany:(Y)=>DY(Y,J)}}async function RZ(J){return(await d(J,{usePrettier:!0,builtIn:{indentSize:2,normalizeWhitespace:!0,sortImports:!0,trailingNewline:!0}})).content}import{existsSync as vY,statSync as IY}from"fs";import{dirname as EY,isAbsolute as qJ,resolve as yY}from"path";var hJ=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".d.ts"];function _J(J){try{return IY(J).isFile()}catch{return!1}}function o(J,Y){if(!(J.startsWith("./")||J.startsWith("../")||J==="."||J==="..")&&!qJ(J))return{resolved:null,isRelative:!1};let $=EY(Y),X=qJ(J)?J:yY($,J);if(_J(X))return{resolved:X,isRelative:!0};for(let G of hJ){let Q=X+G;if(_J(Q))return{resolved:Q,isRelative:!0}}if(vY(X))for(let G of hJ){let Q=`${X}/index${G}`;if(_J(Q))return{resolved:Q,isRelative:!0}}return{resolved:null,isRelative:!0}}function bY(J){let Y=J.length,Z="",$=0;while($<Y){let X=J.charCodeAt($);if(X===34||X===39||X===96){let G=X;Z+=J[$++];while($<Y){let Q=J.charCodeAt($);if(Z+=J[$++],Q===92&&$<Y){Z+=J[$++];continue}if(Q===G)break}continue}if(X===47&&$+1<Y){let G=J.charCodeAt($+1);if(G===47){$+=2;while($<Y&&J.charCodeAt($)!==10)$++;continue}if(G===42){$+=2;while($+1<Y&&!(J.charCodeAt($)===42&&J.charCodeAt($+1)===47))$++;$+=2;continue}}Z+=J[$++]}return Z}var mJ=/(?:^|[\n;{}])\s*export\s+(type\s+)?(?:\*(?:\s+as\s+\w+)?|\{[^}]*\})\s+from\s+(['"])([^'"]+)\2/g,gJ=/(?:^|[\n;{}])\s*import\s+(type\s+)?(?:[^'";\n]+\s+from\s+)?(['"])([^'"]+)\2/g;function BJ(J,Y={}){let Z=[],$=bY(J);mJ.lastIndex=0;let X;while((X=mJ.exec($))!==null){let G=!!X[1],Q=X[3],H=X[0],U;if(H.includes("* as "))U="export-star-as";else if(H.includes("*"))U="export-star";else U="export-named";Z.push({specifier:Q,kind:U,isTypeOnly:G})}if(Y.includeImports){gJ.lastIndex=0;while((X=gJ.exec($))!==null)Z.push({specifier:X[3],kind:"import",isTypeOnly:!!X[1]})}return Z}async function TJ(J,Y={}){let Z=new Set,$=new Map,X=[],G=[];for(let Q of J)if(!Z.has(Q))Z.add(Q),G.push(Q);while(G.length>0){let Q=G.shift(),H;try{H=await y(Q)}catch{continue}let U=BJ(H,Y);$.set(Q,U);for(let W of U){if(!(W.specifier.startsWith(".")||qJ(W.specifier)))continue;let V=o(W.specifier,Q);if(V.resolved){if(!Z.has(V.resolved))Z.add(V.resolved),G.push(V.resolved)}else X.push({from:Q,specifier:W.specifier,isTypeOnly:W.isTypeOnly})}}return{reachable:Z,reExports:$,unresolved:X}}class r{plugins=[];config=null;register(J){if(this.plugins.some((Y)=>Y.name===J.name))throw Error(`Plugin "${J.name}" is already registered`);this.plugins.push(J)}unregister(J){let Y=this.plugins.findIndex((Z)=>Z.name===J);if(Y>=0)return this.plugins.splice(Y,1),!0;return!1}getPlugins(){return this.plugins}createLogger(J){return{debug:(Y)=>console.debug(`[${J}] ${Y}`),info:(Y)=>console.info(`[${J}] ${Y}`),warn:(Y)=>console.warn(`[${J}] ${Y}`),error:(Y)=>console.error(`[${J}] ${Y}`)}}async runOnStart(J){let Y=J;for(let Z of this.plugins)if(Z.onStart){let $=await Z.onStart(Y);if($)Y=$}return this.config=Y,Y}async runOnBeforeFile(J,Y){let Z=Y;for(let $ of this.plugins)if($.onBeforeFile){let X={filePath:J,sourceCode:Y,content:Z,config:this.config,log:this.createLogger($.name)},G=await $.onBeforeFile(X);if(typeof G==="string")Z=G}return Z}async runOnDeclarations(J,Y,Z){let $=Z;for(let X of this.plugins)if(X.onDeclarations){let G={filePath:J,sourceCode:Y,declarations:$,config:this.config,log:this.createLogger(X.name)},Q=await X.onDeclarations(G);if(Q)$=Q}return $}async runOnAfterFile(J,Y,Z){let $=Z;for(let X of this.plugins)if(X.onAfterFile){let G={filePath:J,sourceCode:Y,content:$,config:this.config,log:this.createLogger(X.name)},Q=await X.onAfterFile(G);if(typeof Q==="string")$=Q}return $}async runOnEnd(J){for(let Y of this.plugins)if(Y.onEnd)await Y.onEnd(J)}async runOnError(J,Y,Z){for(let $ of this.plugins)if($.onError){let X={filePath:Y,sourceCode:Z,config:this.config,log:this.createLogger($.name)};await $.onError(J,X)}}}var DZ=new r;function AJ(J){return J}var vZ=AJ({name:"strip-internal",version:"1.0.0",description:"Removes declarations marked with @internal",onDeclarations:(J)=>{return J.declarations.filter((Y)=>{if(Y.leadingComments){if(Y.leadingComments.some(($)=>$.includes("@internal")))return J.log.debug(`Stripping internal declaration: ${Y.name}`),!1}return!0})}});function IZ(J){return AJ({name:"banner",version:"1.0.0",description:"Adds a banner comment to generated files",onAfterFile:(Y)=>{return`/**
|
|
36
|
+
* ${J.split(`
|
|
37
|
+
`).join(`
|
|
38
|
+
* `)}
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
`+Y.content}})}function EZ(J){return AJ({name:"filter",version:"1.0.0",description:"Filters declarations by name",onDeclarations:(Y)=>{return Y.declarations.filter((Z)=>{if(Z.kind==="import")return!0;return J(Z.name)})}})}var P=xY(CY(),1);import{readdir as PY}from"fs/promises";import{dirname as hY,extname as mY,isAbsolute as gY,join as uJ,resolve as dJ}from"path";import pJ from"process";import{pathToFileURL as kJ}from"url";function gZ(J,Y){throw Error(Y||`Unexpected value: ${J}`)}async function h(J,Y){let Z=Y.replace(/\r\n/g,`
|
|
42
|
+
`);if(!Z.endsWith(`
|
|
43
|
+
`))Z+=`
|
|
44
|
+
`;await HJ(J,Z)}async function dY(J){let Y=J??f.root,Z=await PY(Y,{withFileTypes:!0});return(await Promise.all(Z.map((X)=>{let G=uJ(Y,X.name);return X.isDirectory()?dY(G):G}))).flat(1/0).filter((X)=>typeof X==="string"&&mY(X)===".ts")}async function cJ(J){try{let Y=J?.cwd||pJ.cwd(),Z=J?.tsconfigPath||uJ(Y,"tsconfig.json"),X=await import(kJ(Z).href);if(X.compilerOptions?.isolatedDeclarations===!0)return!0;if(X.extends){let G=fJ(Z,X.extends),Q=G.endsWith(".json")?G:`${G}.json`,U=await import(kJ(Q).href);if(U.compilerOptions?.isolatedDeclarations===!0)return!0;if(U.extends){let W=fJ(Q,U.extends),V=W.endsWith(".json")?W:`${W}.json`;if((await import(kJ(V).href)).compilerOptions?.isolatedDeclarations===!0)return!0}}return!1}catch{return!1}}function lJ(J,Y){let Z={isValid:!0,errors:[]},$=P.default.createSourceFile(Y,J,P.default.ScriptTarget.Latest,!0,P.default.ScriptKind.TS),X={getSourceFile:(H)=>{if(H===Y)return $;return},getDefaultLibFileName:()=>"lib.d.ts",writeFile:()=>{},getCurrentDirectory:()=>"",getCanonicalFileName:(H)=>H,useCaseSensitiveFileNames:()=>!0,getNewLine:()=>`
|
|
45
|
+
`,fileExists:(H)=>H===Y,readFile:()=>{return}},Q=[...P.default.createProgram({rootNames:[Y],options:{noEmit:!0,declaration:!0,skipLibCheck:!0,noLib:!0},host:X}).getSyntacticDiagnostics($)];for(let H of Q){let U=P.default.flattenDiagnosticMessageText(H.messageText,`
|
|
46
|
+
`),W=`TS${H.code}`,V;switch(H.code){case 1005:V="Add a semicolon at the end of the statement.";break;case 1109:V="Check for missing or malformed expressions.";break;case 1128:V="Ensure proper declaration syntax is used.";break;case 2304:V="Import or declare the missing type/value.";break;case 2307:V="Check that the module exists and is installed.";break;case 2322:V="Check type compatibility between the values.";break;case 2339:V="Add the missing property to the type definition.";break;case 2345:V="Check the argument types match the expected parameters.";break}if(H.file&&H.start!==void 0){let{line:T,character:N}=H.file.getLineAndCharacterOfPosition(H.start);Z.errors.push({line:T+1,column:N+1,message:U,code:W,suggestion:V})}else Z.errors.push({line:0,column:0,message:U,code:W,suggestion:V})}return Z.isValid=Z.errors.length===0,Z}function aJ(J,Y,Z){if(J===Y)return"";let $=J.split(`
|
|
47
|
+
`),X=Y.split(`
|
|
48
|
+
`),G=new Map,Q=new Map;for(let V=0;V<$.length;V++)G.set($[V],(G.get($[V])??0)+1);for(let V=0;V<X.length;V++)Q.set(X[V],(Q.get(X[V])??0)+1);let H=[],U=[];for(let[V,T]of G){let N=T-(Q.get(V)??0);for(let q=0;q<N;q++)H.push(V)}for(let[V,T]of Q){let N=T-(G.get(V)??0);for(let q=0;q<N;q++)U.push(V)}if(H.length===0&&U.length===0)return"";let W=[`--- ${Z}`,`+++ ${Z}`];for(let V=0;V<H.length;V++)W.push(`- ${H[V]}`);for(let V=0;V<U.length;V++)W.push(`+ ${U[V]}`);return W.join(`
|
|
49
|
+
`)}function fJ(J,Y){if(gY(Y))return Y;if(Y.startsWith("."))return dJ(hY(J),Y);return dJ(pJ.cwd(),"node_modules",Y)}function sJ(J,Y,Z,$){let X=J.split(`
|
|
50
|
+
`),G=[];function Q(T){let q="",O=T<0?-T<<1|1:T<<1;do{let j=O&31;if(O>>>=5,O>0)j|=32;q+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[j]}while(O>0);return q}let H=0,U=0,W=0,V=$.split(`
|
|
51
|
+
`).length;for(let T=0;T<X.length;T++){if(X[T].trim()===""){G.push("");continue}H=0;let q=Math.min(T,V-1),O=[],j=0-H,K=0,A=q-U,z=0-W;O.push(Q(j)+Q(K)+Q(A)+Q(z)),H=0,U=q,W=0,G.push(O.join(","))}return{version:3,file:Y,sourceRoot:"",sources:[Z],sourcesContent:[$],mappings:G.join(";")}}function nJ(J,Y){return`${J}
|
|
52
|
+
//# sourceMappingURL=${Y}
|
|
53
|
+
`}async function uY(J){let Y=Date.now(),Z={...f,...J};if(Z.logLevel)e(Z.logLevel);else if(Z.verbose)e("debug");let $=new r;if(Z.plugins&&Z.plugins.length>0){for(let j of Z.plugins)$.register(j),_.debug(`Registered plugin: ${j.name}`);Z=await $.runOnStart(Z)}if(Z.isolatedDeclarations===void 0)Z.isolatedDeclarations=await cJ(Z);let X=null;if(Z.incremental){if(X=new jJ(Z),Z.clearCache)_.debug("Clearing build cache..."),X.clear();else if(X.load()){let K=X.getStats();_.debug(`Loaded build cache with ${K.entries} entries`)}else _.debug("No existing build cache found, starting fresh");wJ(Z.cwd)}let G={filesProcessed:0,filesGenerated:0,filesFailed:0,filesValidated:0,validationErrors:0,declarationsFound:0,importsProcessed:0,exportsProcessed:0,durationMs:0,errors:[]},Q=0;_.debug("Starting DTS generation..."),_.debug("Config:",Z);let H=await lY(Z),U=H.slice(),W=null;if(Z.autoIncludeReExports!==!1&&U.length>0){W=await TJ(U,{includeImports:!0});let j=x(Z.cwd,Z.root),K=Z.exclude||[],A=[];for(let z of W.reachable){if(U.includes(z))continue;if(z.endsWith(".d.ts"))continue;if(z.includes("node_modules"))continue;if(JJ(z,K,j))continue;A.push(z)}if(A.length>0)U=[...U,...A],_.debug(`Auto-included ${A.length} file(s) reached via relative re-exports`)}if(X){let j=X.prune(new Set(U),Z.cwd);if(j>0)_.debug(`Pruned ${j} deleted files from cache`)}if(_.debug(`Found ${U.length} TypeScript files`),Z.progress&&U.length>0){let j=Z.parallel?"parallel":"sequential";_.info(`Processing ${U.length} files (${j})...`)}let V=async(j,K)=>{let A;try{let z=p(j,Z);if(X){let S=X.getCachedIfValid(j,Z.cwd);if(S)return await t(m(z),{recursive:!0}),await h(z,S),_.debug(`[cached] ${D(Z.cwd,z)}`),{success:!0,file:j,declarationCount:0,importCount:0,exportCount:0,cached:!0,validationErrorCount:0}}A=K??await y(j);let{content:B,declarationCount:k,importCount:R,exportCount:L}=await tJ(j,A,Z,$),F=0;if(Z.dryRun)_.info(`[dry-run] Would generate: ${z}`),_.debug("--- Content preview ---"),_.debug(B.slice(0,500)+(B.length>500?`
|
|
54
|
+
...`:"")),_.debug("--- End preview ---");else{if(Z.diff)try{let M=await y(z),w=aJ(M,B,D(Z.cwd,z));if(w)_.info(`
|
|
55
|
+
${w}`);else _.debug(`[no changes] ${z}`)}catch{_.info(`[new file] ${D(Z.cwd,z)}`)}await t(m(z),{recursive:!0});let S=B;if(Z.declarationMap&&A){let M=z.split("/").pop()||"output.d.ts",w=D(m(z),j),v=`${M}.map`,c=sJ(B,M,w,A),C=`${z}.map`;await h(C,JSON.stringify(c)),S=nJ(B,v),_.debug(` Generated source map: ${D(Z.cwd,C)}`)}if(Z.prettier||Z.indentStyle||Z.indentSize){let M=await d(S,{usePrettier:Z.prettier,builtIn:{indentSize:Z.indentSize||2,useTabs:Z.indentStyle==="tabs",normalizeWhitespace:!0,sortImports:!0,trailingNewline:!0}},z);if(S=M.content,M.warnings?.length)for(let w of M.warnings)_.warn(`[format] ${w}`)}if(await h(z,S),X&&A)X.update(j,A,S,Z.cwd);if(Z.validate){let M=lJ(B,z);if(!M.isValid){F=M.errors.length,_.warn(`[validation] ${D(Z.cwd,z)} has ${M.errors.length} error(s):`);for(let w of M.errors){let v=` Line ${w.line}:${w.column}`;if(w.code)v+=` [${w.code}]`;if(v+=` - ${w.message}`,_.warn(v),w.suggestion)_.warn(` Suggestion: ${w.suggestion}`)}}else _.debug(`[validation] ${z} - OK`)}_.debug(`Generated: ${z}`)}return{success:!0,file:j,declarationCount:k,importCount:R,exportCount:L,validationErrorCount:F}}catch(z){let B=KJ(z,j,A);if(Z.plugins&&Z.plugins.length>0)await $.runOnError(z instanceof Error?z:Error(String(z)),j,A||"");return{success:!1,file:j,declarationCount:0,importCount:0,exportCount:0,dtsError:B,validationErrorCount:0}}},T=Z.parallel||Z.parallel!==!1&&U.length>=10,N=Z.concurrency||(fY?.()??8),q=new Map;if(T&&U.length>1){let j=U.map(async(K)=>{try{let A=await y(K);return{file:K,source:A}}catch{return{file:K,source:null}}});for(let K of await Promise.all(j))if(K.source!==null)q.set(K.file,K.source)}let O=(j)=>{if(G.filesProcessed++,j.success){if(j.cached)Q++;else G.filesGenerated++,G.declarationsFound+=j.declarationCount,G.importsProcessed+=j.importCount,G.exportsProcessed+=j.exportCount;if(Z.validate){if(G.filesValidated++,j.validationErrorCount)G.validationErrors+=j.validationErrorCount}}else if(G.filesFailed++,j.dtsError){G.errors.push(j.dtsError);let K=PJ(j.dtsError);if(Z.continueOnError)_.warn(K);else throw _.error(K),Error(j.dtsError.message)}};if(T)for(let j=0;j<U.length;j+=N){let K=U.slice(j,j+N),A=await Promise.all(K.map((z)=>V(z,q.get(z))));for(let z of A)O(z);if(Z.progress){let z=Math.round(G.filesProcessed/U.length*100);_.info(`[${G.filesProcessed}/${U.length}] ${z}%`)}}else for(let j of U){let K=await V(j);if(O(K),Z.progress){let A=Math.round(G.filesProcessed/U.length*100),z=K.cached?"[cached]":"";_.info(`[${G.filesProcessed}/${U.length}] ${A}% - ${D(Z.cwd,j)} ${z}`)}}if(X)X.save(),_.debug("Saved build cache");if(!Z.bundle){let j=[];if(W)for(let K of W.unresolved)j.push({from:K.from,specifier:K.specifier,reason:"missing"});if(Z.autoIncludeReExports===!1&&U.length>0){let K=new Set(U);for(let A of U){let z;try{z=await y(A)}catch{continue}for(let B of BJ(z)){if(!B.specifier.startsWith("."))continue;let k=o(B.specifier,A);if(!k.resolved)j.push({from:A,specifier:B.specifier,reason:"missing"});else if(!K.has(k.resolved))j.push({from:A,specifier:B.specifier,reason:"not-emitted"})}}}if(j.length>0){let K=[];K.push(`Found ${j.length} re-export(s) pointing at siblings that won't be in the output:`);for(let z of j){let B=D(Z.cwd,z.from);if(z.reason==="missing")K.push(` ${B} \u2192 '${z.specifier}' (path not found on disk)`);else K.push(` ${B} \u2192 '${z.specifier}' (resolved but not in entrypoints; set autoIncludeReExports: true or add to entrypoints)`)}let A=K.join(`
|
|
56
|
+
`);if(Z.failOnUnresolvedReExport)throw Error(A);_.warn(A),_.warn('Generated .d.ts files reference modules that were not emitted \u2014 consumers will see "has no exported member" errors.')}}if(Z.bundle&&(G.filesGenerated>0||Q>0)&&H.length>0)try{_.debug("Bundling declarations...");let j=new Map,K=async(z)=>{let B=j.get(z);if(B!==void 0)return B;return B=await y(z),j.set(z,B),B};for(let z of U)await K(z);let A=H.length===1&&!!Z.bundleOutput;for(let z of H){let B=await TJ([z],{includeImports:!0}),k=new Set;for(let M of B.reachable){if(M.endsWith(".d.ts"))continue;if(M.includes("node_modules"))continue;k.add(M)}let R=U.filter((M)=>k.has(M));if(!R.includes(z))R.push(z);let L=new Map;for(let M of R){let w=j.get(M)??await K(M);L.set(M,w)}let F=await OJ(R,L,Z),S=A?x(Z.cwd,Z.outdir,Z.bundleOutput):p(z,Z);if(await t(m(S),{recursive:!0}),await h(S,F.content),_.info(`Bundled ${F.files.length} files to: ${D(Z.cwd,S)}`),A)break}}catch(j){let K=j instanceof Error?j.message:String(j);_.error(`Bundle failed: ${K}`)}if(G.durationMs=Date.now()-Y,Z.stats)if(Z.outputFormat==="json")console.log(JSON.stringify(G,null,2));else{if(_.info(`
|
|
57
|
+
--- Generation Statistics ---`),_.info(`Files processed: ${G.filesProcessed}`),_.info(`Files generated: ${G.filesGenerated}`),Q>0)_.info(`Files cached: ${Q}`);if(G.filesFailed>0)_.info(`Files failed: ${G.filesFailed}`);if(_.info(`Declarations found: ${G.declarationsFound}`),_.info(`Imports processed: ${G.importsProcessed}`),_.info(`Exports processed: ${G.exportsProcessed}`),G.filesValidated>0){if(_.info(`Files validated: ${G.filesValidated}`),G.validationErrors>0)_.info(`Validation errors: ${G.validationErrors}`)}if(_.info(`Duration: ${G.durationMs}ms`),G.errors.length>0){_.info(`
|
|
58
|
+
Errors:`);for(let j of G.errors){let K=` - ${j.file}`;if(j.location)K+=`:${j.location.line}:${j.location.column}`;if(j.code)K+=` [${j.code}]`;if(K+=`: ${j.message}`,_.info(K),j.suggestion)_.info(` Suggestion: ${j.suggestion}`)}}_.info(`-----------------------------
|
|
59
|
+
`)}if(Z.plugins&&Z.plugins.length>0)await $.runOnEnd(G);return _.debug("DTS generation complete!"),G}var pY=50,u=new Map;function cY(J){let Y=u.get(J);if(!Y){if(Y=new oJ(J),u.set(J,Y),u.size>pY){let Z=u.keys().next().value;if(Z!==void 0)u.delete(Z)}}return Y}function JJ(J,Y,Z){if(!Y||Y.length===0)return!1;let $=D(Z,J);for(let X of Y){let G=cY(X);if(G.match($)||G.match(J))return!0}return!1}async function lY(J){let Y=[],Z=x(J.cwd,J.root),$=J.exclude||[];for(let X of J.entrypoints)if(X.startsWith("/")&&X.endsWith(".ts")){if(!X.endsWith(".d.ts")&&!X.includes("node_modules")){if(!JJ(X,$,Z))Y.push(X)}}else{let G=new oJ(X);for await(let Q of G.scan({cwd:Z,absolute:!0,onlyFiles:!0}))if(!Q.endsWith(".d.ts")&&!Q.includes("node_modules")){if(!JJ(Q,$,Z))Y.push(Q)}}return[...new Set(Y)]}function p(J,Y){let Z=x(Y.cwd,Y.root),X=D(Z,J).replace(/\.(m?tsx?|cts)$/,(G)=>{if(G===".mts")return".d.mts";if(G===".cts")return".d.cts";return".d.ts"});if(Y.outputStructure==="mirror")return x(Y.cwd,Y.outdir,X);else{let G=X.split("/").pop();return x(Y.cwd,Y.outdir,G)}}function aY(J,Y){let Z=D(m(J),Y).replace(/\\/g,"/");if(Z=Z.replace(/\.d\.mts$/,"").replace(/\.d\.cts$/,"").replace(/\.d\.ts$/,""),!Z.startsWith("."))Z=`./${Z}`;return Z}function sY(J,Y,Z){let $=p(Y,Z),X=(G)=>{let Q=o(G,Y);if(!Q.isRelative||!Q.resolved)return G;return aY($,p(Q.resolved,Z))};return J.replace(/\b(from\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(G,Q,H,U)=>{return`${Q}${H}${X(U)}${H}`}).replace(/\b(import\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(G,Q,H,U)=>{return`${Q}${H}${X(U)}${H}`}).replace(/\b(import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g,(G,Q,H,U)=>{return`${Q}${H}${X(U)}${H}`})}async function G0(J,Y){return(await rJ(J,Y)).content}async function rJ(J,Y,Z){let $=await y(J);return tJ(J,$,Y,Z)}async function tJ(J,Y,Z,$){let X=Y;if($)X=await $.runOnBeforeFile(J,Y);let G=a(X,J,Z.keepComments,Z.isolatedDeclarations??!1);if($)G=await $.runOnDeclarations(J,X,G);let Q=0,H=0;for(let V=0;V<G.length;V++){let T=G[V];if(T.kind==="import")Q++;if(T.kind==="export"||T.isExported)H++}let W=iJ(G,{filePath:J,sourceCode:X,declarations:G},Z.keepComments,Z.importOrder);if(W=sY(W,J,Z),$)W=await $.runOnAfterFile(J,X,W);return{content:W,declarationCount:G.length,importCount:Q,exportCount:H}}async function Q0(J){let Y={...f,...J};if(Y.logLevel)e(Y.logLevel);let Z=x(Y.cwd,Y.root),$=150,X=5,G=1e4,Q={pendingChanges:new Set,debounceTimer:null,isProcessing:!1,errorCount:0,lastErrorTime:0};_.info(`Watching for changes in ${Z}...`),_.info(`Press Ctrl+C to stop
|
|
60
|
+
`);try{await uY(Y),_.info(`[watch] Initial generation complete
|
|
61
|
+
`)}catch(T){let N=T instanceof Error?T.message:String(T);_.error(`[watch] Initial generation failed: ${N}`),_.info(`[watch] Continuing to watch for changes...
|
|
62
|
+
`)}async function H(){if(Q.isProcessing||Q.pendingChanges.size===0)return;let T=Date.now();if(Q.errorCount>=X){if(T-Q.lastErrorTime<G){_.warn(`[watch] Too many errors, pausing for ${Math.ceil((G-(T-Q.lastErrorTime))/1000)}s...`);return}Q.errorCount=0}Q.isProcessing=!0;let N=Array.from(Q.pendingChanges);Q.pendingChanges.clear();let q=new Date().toLocaleTimeString();if(N.length===1)_.info(`
|
|
63
|
+
[${q}] File changed: ${N[0]}`);else _.info(`
|
|
64
|
+
[${q}] ${N.length} files changed`);let O=0,j=0;for(let K of N){let A=x(Z,K);try{let z=Y.exclude||[];if(JJ(A,z,Z)){_.debug(` Skipping excluded file: ${K}`);continue}if(!await EJ(A).exists()){_.debug(` Skipping deleted file: ${K}`);continue}let k=p(A,Y),{content:R}=await rJ(A,Y);await t(m(k),{recursive:!0}),await h(k,R),_.info(` \u2713 ${D(Y.cwd,k)}`),O++}catch(z){j++,Q.errorCount++,Q.lastErrorTime=Date.now();let B=KJ(z,A);if(_.error(` \u2717 ${K}: ${B.message}`),B.suggestion)_.error(` Suggestion: ${B.suggestion}`)}}if(N.length>1)_.info(` Done: ${O} generated, ${j} failed`);if(j===0)Q.errorCount=0;if(Q.isProcessing=!1,Q.pendingChanges.size>0)Q.debounceTimer=setTimeout(H,$)}function U(T){if(Q.pendingChanges.add(T),Q.debounceTimer)clearTimeout(Q.debounceTimer);Q.debounceTimer=setTimeout(H,$)}let V=yJ([I?"bun":"node","-e",`
|
|
65
|
+
const fs = require('fs');
|
|
66
|
+
|
|
67
|
+
const rootPath = '${Z}';
|
|
68
|
+
|
|
69
|
+
fs.watch(rootPath, { recursive: true }, (eventType, filename) => {
|
|
70
|
+
if (filename && filename.endsWith('.ts') && !filename.endsWith('.d.ts')) {
|
|
71
|
+
console.log(\`CHANGED:\${filename}\`);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Keep process alive
|
|
76
|
+
setInterval(() => {}, 1000);
|
|
77
|
+
`],{stdout:"pipe",stderr:"inherit"});if(I){let T=V.stdout.getReader(),N=new TextDecoder,q="";while(!0){let{done:O,value:j}=await T.read();if(O)break;q+=N.decode(j,{stream:!0});let K=q.split(`
|
|
78
|
+
`);q=K.pop()||"";for(let A of K)if(A.startsWith("CHANGED:")){let z=A.slice(8);U(z)}}}else{let T=V.stdout,N="";T.on("data",(q)=>{N+=q.toString();let O=N.split(`
|
|
79
|
+
`);N=O.pop()||"";for(let j of O)if(j.startsWith("CHANGED:")){let K=j.slice(8);U(K)}}),await V.exited}}
|
|
80
|
+
export{OJ as ua,LJ as va,UY as wa,rY as xa,tY as ya,jJ as za,wJ as Aa,I as Ba,QZ as Ca,UZ as Da,EJ as Ea,HJ as Fa,yJ as Ga,y as Ha,zZ as Ia,VZ as Ja,jZ as Ka,g as La,E as Ma,bJ as Na,_Y as Oa,qY as Pa,xJ as Qa,CJ as Ra,BY as Sa,HZ as Ta,KZ as Ua,_Z as Va,qZ as Wa,BZ as Xa,TZ as Ya,AZ as Za,KJ as _a,PJ as $a,kZ as ab,d as bb,DY as cb,OZ as db,RZ as eb,r as fb,DZ as gb,AJ as hb,vZ as ib,IZ as jb,EZ as kb,gZ as lb,h as mb,dY as nb,cJ as ob,lJ as pb,aJ as qb,sJ as rb,nJ as sb,uY as tb,G0 as ub,Q0 as vb};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as c,ub as d,vb as e}from"./chunk-
|
|
2
|
+
import{tb as c,ub as d,vb as e}from"./chunk-af12rv0y.js";import"./chunk-ft0nf9jb.js";import"./chunk-2n1bbm2c.js";import{ic as a,jc as b}from"./chunk-bymtns9a.js";import"./chunk-y2pe3jq3.js";import"./chunk-4mtbtmee.js";import"./chunk-vx4a5crm.js";import"./chunk-xw9wfq8f.js";import"./chunk-7hy98p24.js";import"./chunk-gssantc8.js";import"./chunk-mcdb3q06.js";export{e as watch,a as processSource,d as processFile,c as generate,b as clearResultCache};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{l as a,m as b,n as c,o as d,p as e,q as f,r as g}from"./chunk-
|
|
2
|
+
import{l as a,m as b,n as c,o as d,p as e,q as f,r as g}from"./chunk-ww6wqbda.js";import"./chunk-af12rv0y.js";import"./chunk-ft0nf9jb.js";import"./chunk-2n1bbm2c.js";import"./chunk-bymtns9a.js";import"./chunk-y2pe3jq3.js";import"./chunk-4mtbtmee.js";import"./chunk-vx4a5crm.js";import"./chunk-xw9wfq8f.js";import"./chunk-7hy98p24.js";import"./chunk-gssantc8.js";import"./chunk-mcdb3q06.js";export{b as sortProjectsByDependencies,f as resolveWorkspacePatterns,c as generateWorkspace,d as generateMonorepo,g as generateFromPackageWorkspaces,a as discoverWorkspaceProjects,e as discoverWorkspaceFromPackageJson};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as y}from"./chunk-
|
|
2
|
+
import{tb as y}from"./chunk-af12rv0y.js";import{Wc as H,Yc as F}from"./chunk-gssantc8.js";import{dd as R}from"./chunk-mcdb3q06.js";import{existsSync as V,readFileSync as G}from"fs";import{dirname as M,join as X,resolve as x}from"path";async function S(E){let A=[],z=new Set;async function q(I,O){let w=x(I);if(z.has(w))return;if(z.add(w),!V(w)){H.warn(`tsconfig not found: ${w}`);return}try{let K=G(w,"utf-8"),Q=K.indexOf("//")!==-1||K.indexOf("/*")!==-1?K.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,""):K,L=JSON.parse(Q),U=M(w),Y=B(U,O),W=[];if(L.references)for(let D of L.references){let $=x(U,D.path),J=V(X($,"tsconfig.json"))?X($,"tsconfig.json"):$;await q(J,Y);let b=B(M(J),Y);W.push(b)}let Z="./src";if(L.compilerOptions?.rootDir)Z=L.compilerOptions.rootDir;else if(L.include&&L.include.length>0){if(L.include[0].startsWith("src/"))Z="./src"}let _="./dist";if(L.compilerOptions?.outDir)_=L.compilerOptions.outDir;else if(L.compilerOptions?.declarationDir)_=L.compilerOptions.declarationDir;A.push({name:Y,root:U,tsconfigPath:w,references:W,config:{root:Z,outdir:_}})}catch(K){let Q=K instanceof Error?K.message:String(K);H.warn(`Failed to parse ${w}: ${Q}`)}}return await q(E),A}function B(E,A){let z=X(E,"package.json");if(V(z))try{let I=G(z,"utf-8"),O=JSON.parse(I);if(O.name)return O.name}catch{}let q=E.split("/").pop()||"unknown";return A?`${A}/${q}`:q}function N(E){let A=new Map(E.map((w)=>[w.name,w])),z=[],q=new Set,I=new Set;function O(w){if(q.has(w))return;if(I.has(w)){H.warn(`Circular dependency detected involving: ${w}`);return}I.add(w);let K=A.get(w);if(K){for(let Q of K.references)O(Q);z.push(K)}I.delete(w),q.add(w)}for(let w of E)O(w.name);return z}async function T(E){let A=Date.now(),z=N(E.projects);H.info(`Generating declarations for ${z.length} projects...`);let q=[],I=!0;for(let Q of z){H.info(`
|
|
3
3
|
[${Q.name}] Generating...`);try{let L={...E.sharedConfig,...Q.config,cwd:Q.root,tsconfigPath:Q.tsconfigPath},U=await y(L),Y=U.filesFailed===0;if(!Y)I=!1;q.push({name:Q.name,stats:U,success:Y}),H.info(`[${Q.name}] Generated ${U.filesGenerated} files`)}catch(L){I=!1;let U=L instanceof Error?L.message:String(L);q.push({name:Q.name,stats:{filesProcessed:0,filesGenerated:0,filesFailed:0,filesValidated:0,validationErrors:0,declarationsFound:0,importsProcessed:0,exportsProcessed:0,durationMs:0,errors:[]},success:!1,error:U}),H.error(`[${Q.name}] Failed: ${U}`)}}let O=Date.now()-A,w=q.filter((Q)=>Q.success).length,K=q.length-w;if(H.info(`
|
|
4
4
|
--- Workspace Generation Summary ---`),H.info(`Projects processed: ${q.length}`),H.info(`Successful: ${w}`),K>0)H.info(`Failed: ${K}`);return H.info(`Total duration: ${O}ms`),H.info(`------------------------------------
|
|
5
5
|
`),{success:I,projects:q,durationMs:O}}async function f(E,A){if(A?.logLevel)F(A.logLevel);let z=X(E,"tsconfig.json");if(!V(z))throw Error(`Root tsconfig.json not found at: ${z}`);H.info("Discovering workspace projects...");let q=await S(z);if(q.length===0)return H.warn("No projects found in workspace"),{success:!0,projects:[],durationMs:0};return H.info(`Found ${q.length} projects`),T({root:E,projects:q,sharedConfig:A})}async function v(E){let A=X(E,"package.json");if(!V(A))return[];try{let z=G(A,"utf-8"),q=JSON.parse(z),I=[];if(Array.isArray(q.workspaces))I=q.workspaces;else if(q.workspaces?.packages)I=q.workspaces.packages;return I}catch{return[]}}async function C(E,A){let{Glob:z}=awaitPromise.resolve(globalThis.Bun),q=[];for(let I of A){let O=new z(I);for await(let w of O.scan({cwd:E,absolute:!0,onlyFiles:!1})){let K=X(w,"package.json");if(V(K))q.push(w)}}return q}async function l(E,A){if(A?.logLevel)F(A.logLevel);let z=await v(E);if(z.length===0)return H.warn("No workspace patterns found in package.json"),{success:!0,projects:[],durationMs:0};H.info(`Found workspace patterns: ${z.join(", ")}`);let q=await C(E,z);if(q.length===0)return H.warn("No projects found matching workspace patterns"),{success:!0,projects:[],durationMs:0};H.info(`Found ${q.length} workspace packages`);let I=q.map((O)=>{let w=X(O,"tsconfig.json");return{name:B(O),root:O,tsconfigPath:V(w)?w:"",references:[]}});return T({root:E,projects:I,sharedConfig:A})}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as C}from"./chunk-
|
|
2
|
+
import{tb as C}from"./chunk-af12rv0y.js";function y(F={}){let{onStart:H=!1,onEnd:I=!0,onGenerated:J,onError:z,...q}=F,B=async()=>{try{let k=await C(q);J?.(k)}catch(k){let j=k instanceof Error?k:Error(String(k));if(z?.(j),!z)console.error("[dtsx] Generation failed:",j.message)}};return{name:"dtsx",setup(k){let j=k.initialOptions;if(!q.entrypoints&&j.entryPoints)if(Array.isArray(j.entryPoints))q.entrypoints=j.entryPoints;else q.entrypoints=Object.values(j.entryPoints);if(!q.outdir){if(j.outdir)q.outdir=j.outdir;else if(j.outfile){let w=j.outfile.lastIndexOf("/");if(w!==-1)q.outdir=j.outfile.substring(0,w)}}if(H)k.onStart(async()=>{await B()});if(I)k.onEnd(async(w)=>{if(w.errors.length===0)await B()})}}}var L=y,M=y,P=y;
|
|
3
3
|
export{y as ia,L as ja,M as ka,P as la};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{tb as I}from"./chunk-
|
|
2
|
+
import{tb as I}from"./chunk-af12rv0y.js";class H{options;generateOptions;constructor(j={}){let{onCompile:F=!1,afterEmit:w=!0,onWatchRun:q=!1,onGenerated:z,onError:B,...J}=j;this.options={onCompile:F,afterEmit:w,onWatchRun:q,onGenerated:z,onError:B},this.generateOptions=J}apply(j){if(!this.generateOptions.outdir&&j.options.output?.path)this.generateOptions.outdir=j.options.output.path;if(!this.generateOptions.cwd&&j.options.context)this.generateOptions.cwd=j.options.context;if(!this.generateOptions.entrypoints&&j.options.entry){let w=j.options.entry;if(typeof w==="string")this.generateOptions.entrypoints=[w];else if(Array.isArray(w))this.generateOptions.entrypoints=w;else if(typeof w==="object"&&w!==null){let q=[];for(let z of Object.values(w))if(typeof z==="string")q.push(z);else if(Array.isArray(z))q.push(...z.filter((B)=>typeof B==="string"));else if(typeof z==="object"&&z!==null&&"import"in z){let B=z.import;if(typeof B==="string")q.push(B);else if(Array.isArray(B))q.push(...B)}if(q.length>0)this.generateOptions.entrypoints=q}}if(this.options.onCompile)j.hooks.compile.tap("DtsxWebpackPlugin",()=>{this.runGenerate()});if(this.options.afterEmit)j.hooks.afterEmit.tapAsync("DtsxWebpackPlugin",async(w,q)=>{await this.runGenerate(),q()});if(this.options.onWatchRun)j.hooks.watchRun.tapAsync("DtsxWebpackPlugin",async(w,q)=>{await this.runGenerate(),q()})}async runGenerate(){try{let j=await I(this.generateOptions);this.options.onGenerated?.(j)}catch(j){let F=j instanceof Error?j:Error(String(j));if(this.options.onError?.(F),!this.options.onError)console.error("[dtsx] Generation failed:",F.message)}}}function K(j={}){return new H(j)}var M=K,Q=H;
|
|
3
3
|
export{H as qa,K as ra,M as sa,Q as ta};
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{a as i$,b as n$,c as r$}from"../chunk-0cfb4831.js";import{d as S9,e as T9,f as k9,g as v9,h as C9,i as b9,j as P9,k as x9}from"../chunk-1hy2eypj.js";import{l as Q2,m as X2,n as q2,o as V2,p as Y2,q as W2,r as K2}from"../chunk-
|
|
2
|
+
import{a as i$,b as n$,c as r$}from"../chunk-0cfb4831.js";import{d as S9,e as T9,f as k9,g as v9,h as C9,i as b9,j as P9,k as x9}from"../chunk-1hy2eypj.js";import{l as Q2,m as X2,n as q2,o as V2,p as Y2,q as W2,r as K2}from"../chunk-ww6wqbda.js";import{s as p$,t as d$,u as c$,v as l$,w as o$,x as s$,y as a$}from"../chunk-fvgc14nk.js";import{A as p8,B as d8,C as c8,D as l8,E as o8,F as s8,G as a8,H as i8,z as m8}from"../chunk-mxam9312.js";import{I as Z$,J as $$,K as J$,L as Q$,M as X$,N as q$,O as V$,P as Y$}from"../chunk-d0p3jzwb.js";import{Q as n8,R as r8,S as t8,T as e8,U as Z9,V as $9,W as J9,X as Q9,Y as X9}from"../chunk-nf54b52t.js";import{$ as Z2,Z as t$,_ as e$,aa as $2,ba as J2}from"../chunk-zf17s33e.js";import{$a as t9,Aa as u8,Ba as q9,Ca as V9,Da as Y9,Ea as QZ,Fa as W9,Ga as K9,Ha as H9,Ia as U9,Ja as O9,Ka as G9,La as y9,Ma as h9,Na as g9,Oa as f9,Pa as u9,Qa as m9,Ra as p9,Sa as d9,Ta as c9,Ua as l9,Va as o9,Wa as s9,Xa as a9,Ya as i9,Za as n9,_a as r9,ab as e9,bb as W$,cb as K$,db as H$,eb as U$,fb as O$,gb as G$,hb as uZ,ib as _$,jb as z$,kb as A$,lb as T$,mb as k$,nb as v$,ob as C$,pb as b$,qb as P$,rb as x$,sb as y$,tb as f$,ua as P8,ub as u$,va as x8,vb as m$,wa as y8,xa as h8,ya as g8,za as f8}from"../chunk-af12rv0y.js";import{$b as I8,Ab as s6,Bb as s0,Cb as a0,Db as Q8,Eb as X8,Fb as q8,Gb as V8,Hb as Y8,Ib as W8,Jb as K8,Kb as H8,Lb as U8,Mb as O8,Nb as G8,Ob as _8,Pb as z8,Qb as A8,Rb as B8,Sb as j8,Tb as N8,Ub as R8,Vb as F8,Wb as D8,Xb as E8,Yb as L8,Zb as w8,_b as M8,ac as S8,bc as T8,cc as k8,dc as v8,ec as FZ,fc as C8,gc as b8,wb as d6,xb as c6,yb as l6,zb as o6}from"../chunk-ft0nf9jb.js";import{hc as g0}from"../chunk-2n1bbm2c.js";import{ic as h$,jc as g$}from"../chunk-bymtns9a.js";import{lc as KZ}from"../chunk-y2pe3jq3.js";import"../chunk-4mtbtmee.js";import{Ac as I$,Bc as S$,Cc as DZ,pc as i0,qc as B$,rc as j$,sc as N$,tc as R$,uc as F$,vc as D$,wc as E$,xc as L$,yc as w$,zc as M$}from"../chunk-vx4a5crm.js";import{Fc as a6,Gc as i6,Hc as n6,Ic as r6,Jc as t6,Kc as o0,Lc as e6,Mc as Z8,Nc as $8,Oc as J8}from"../chunk-xw9wfq8f.js";import{Pc as D9,Qc as E9,Rc as L9,Sc as w9,Tc as M9,Uc as I9}from"../chunk-7hy98p24.js";import{$c as R9,Vc as _9,Wc as z9,Xc as A9,Yc as B9,Zc as j9,_c as N9,ad as F9}from"../chunk-gssantc8.js";import{bd as h0,dd as n0}from"../chunk-mcdb3q06.js";import{basename as rZ,dirname as tZ,isAbsolute as eZ,join as Z0,relative as $0,resolve as J0}from"path";function l1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid file path: must be a non-empty string");return Z}function o1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid directory path: must be a non-empty string");return Z}function s1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid glob pattern: must be a non-empty string");return Z}function a1(Z){if(typeof Z!=="string")throw TypeError("Invalid source code: must be a string");return Z}function i1(Z){if(typeof Z!=="string")throw TypeError("Invalid DTS content: must be a string");return Z}function n1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid module specifier: must be a non-empty string");return Z}function r1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid type name: must be a non-empty string");if(!["string","number","boolean","symbol","bigint","undefined","null","void","never","any","unknown","object"].includes(Z)&&!/^[A-Z_$]/.test(Z));return Z}function t1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid declaration name: must be a non-empty string");return Z}function e1(Z){if(!Z||typeof Z!=="string")throw Error("Invalid absolute path: must be a non-empty string");if(!Z.startsWith("/")&&!/^[A-Z]:/i.test(Z))throw Error("Invalid absolute path: must start with / or drive letter");return Z}function Z3(Z){if(!Z||typeof Z!=="string")throw Error("Invalid relative path: must be a non-empty string");if(Z.startsWith("/")||/^[A-Z]:/i.test(Z))throw Error("Invalid relative path: must not be absolute");return Z}function $3(Z){if(typeof Z!=="string")throw TypeError("Invalid JSON string: must be a string");try{JSON.parse(Z)}catch{throw Error("Invalid JSON string: must be valid JSON")}return Z}function J3(Z,$){return typeof Z==="string"||typeof Z==="number"}function Q3(Z){return Z}var X3={join(Z,...$){return Z0(Z,...$)},dirname(Z){return tZ(Z)},basename(Z){return rZ(Z)},resolve(...Z){return J0(...Z)},isAbsolute(Z){return eZ(Z)},relative(Z,$){return $0(Z,$)}};function Q0(Z,$){let J=Z.length,Q=$.length,X=Array.from({length:J+1},()=>Array(Q+1).fill(0));for(let q=1;q<=J;q++)for(let V=1;V<=Q;V++)if(Z[q-1]===$[V-1])X[q][V]=X[q-1][V-1]+1;else X[q][V]=Math.max(X[q-1][V],X[q][V-1]);return X}function X0(Z,$,J,Q,X){let q=[];while(Q>0||X>0)if(Q>0&&X>0&&$[Q-1]===J[X-1])q.unshift({op:"equal",oldIdx:Q-1,newIdx:X-1,line:$[Q-1]}),Q--,X--;else if(X>0&&(Q===0||Z[Q][X-1]>=Z[Q-1][X]))q.unshift({op:"add",newIdx:X-1,line:J[X-1]}),X--;else if(Q>0)q.unshift({op:"remove",oldIdx:Q-1,line:$[Q-1]}),Q--;return q}function JZ(Z,$){let J=Z;if($.ignoreWhitespace)J=J.replace(/\s+/g," ").trim();return J}function p(Z,$,J,Q={}){let{context:X=3,ignoreWhitespace:q=!1,ignoreBlankLines:V=!1}=Q,Y=Z.split(`
|
|
3
3
|
`),W=$.split(`
|
|
4
4
|
`);if(Y[Y.length-1]==="")Y.pop();if(W[W.length-1]==="")W.pop();let K=Y.map((F)=>JZ(F,{ignoreWhitespace:q})),H=W.map((F)=>JZ(F,{ignoreWhitespace:q})),A=K,_=H,O=Y.map((F,M)=>M),G=W.map((F,M)=>M);if(V)A=[],_=[],O=[],G=[],K.forEach((F,M)=>{if(F.trim())A.push(F),O.push(M)}),H.forEach((F,M)=>{if(F.trim())_.push(F),G.push(M)});let U=Q0(A,_),z=X0(U,A,_,A.length,_.length),B=z.every((F)=>F.op==="equal"),j=0,N=0,R=0;for(let F of z)if(F.op==="add")j++;else if(F.op==="remove")N++;else R++;let k=q0(z,Y,W,O,G,X);return{filePath:J,identical:B,hunks:k,stats:{additions:j,deletions:N,unchanged:R},oldContent:Z,newContent:$}}function q0(Z,$,J,Q,X,q){let V=[],Y=[];if(Z.forEach((H,A)=>{if(H.op!=="equal")Y.push(A)}),Y.length===0)return V;let W=[],K=[Y[0]];for(let H=1;H<Y.length;H++)if(Y[H]-Y[H-1]<=q*2+1)K.push(Y[H]);else W.push(K),K=[Y[H]];W.push(K);for(let H of W){let A=Math.max(0,H[0]-q),_=Math.min(Z.length-1,H[H.length-1]+q),O=Z.slice(A,_+1),G=[],U=1,z=1,B=0,j=0;for(let N=0;N<A;N++){let R=Z[N];if(R.op==="equal"||R.op==="remove")U++;if(R.op==="equal"||R.op==="add")z++}for(let N of O)if(N.op==="equal")G.push(` ${N.line}`),B++,j++;else if(N.op==="remove")G.push(`-${N.line}`),B++;else if(N.op==="add")G.push(`+${N.line}`),j++;V.push({operation:"equal",lines:G,oldStart:U,oldCount:B,newStart:z,newCount:j})}return V}function Y3(Z){if(Z.identical)return"";let $=[];$.push(`--- a/${Z.filePath}`),$.push(`+++ b/${Z.filePath}`);for(let J of Z.hunks)$.push(`@@ -${J.oldStart},${J.oldCount} +${J.newStart},${J.newCount} @@`),$.push(...J.lines);return $.join(`
|
|
5
5
|
`)}function V0(Z){if(Z.identical)return`\x1B[32m\u2713 ${Z.filePath} (unchanged)\x1B[0m`;let $=[],J=`+${Z.stats.additions} -${Z.stats.deletions}`;$.push(`\x1B[1m${Z.filePath}\x1B[0m \x1B[90m(${J})\x1B[0m`),$.push("");for(let Q of Z.hunks){$.push(`\x1B[36m@@ -${Q.oldStart},${Q.oldCount} +${Q.newStart},${Q.newCount} @@\x1B[0m`);for(let X of Q.lines)if(X.startsWith("+"))$.push(`\x1B[32m${X}\x1B[0m`);else if(X.startsWith("-"))$.push(`\x1B[31m${X}\x1B[0m`);else $.push(`\x1B[90m${X}\x1B[0m`);$.push("")}return $.join(`
|
package/dist/src/plugins/bun.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{fa as a,ga as b,ha as c}from"../../chunk-
|
|
2
|
+
import{fa as a,ga as b,ha as c}from"../../chunk-9asxz2at.js";import"../../chunk-af12rv0y.js";import"../../chunk-ft0nf9jb.js";import"../../chunk-2n1bbm2c.js";import"../../chunk-bymtns9a.js";import"../../chunk-y2pe3jq3.js";import"../../chunk-4mtbtmee.js";import"../../chunk-vx4a5crm.js";import"../../chunk-xw9wfq8f.js";import"../../chunk-7hy98p24.js";import"../../chunk-gssantc8.js";import"../../chunk-mcdb3q06.js";export{a as dts,c as default,b as bunDts};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ia as a,ja as b,ka as c,la as d}from"../../chunk-
|
|
2
|
+
import{ia as a,ja as b,ka as c,la as d}from"../../chunk-wzbwr7a3.js";import"../../chunk-af12rv0y.js";import"../../chunk-ft0nf9jb.js";import"../../chunk-2n1bbm2c.js";import"../../chunk-bymtns9a.js";import"../../chunk-y2pe3jq3.js";import"../../chunk-4mtbtmee.js";import"../../chunk-vx4a5crm.js";import"../../chunk-xw9wfq8f.js";import"../../chunk-7hy98p24.js";import"../../chunk-gssantc8.js";import"../../chunk-mcdb3q06.js";export{b as esbuildDts,a as dtsx,c as dts,d as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ca as s}from"../../chunk-
|
|
2
|
+
import{ca as s}from"../../chunk-4zdjnqrz.js";import{fa as t}from"../../chunk-9asxz2at.js";import{ia as i,ka as p}from"../../chunk-wzbwr7a3.js";import{ma as e,oa as u}from"../../chunk-aaba58v4.js";import{qa as l,ra as a,sa as n}from"../../chunk-yzhdn85p.js";import"../../chunk-af12rv0y.js";import"../../chunk-ft0nf9jb.js";import"../../chunk-2n1bbm2c.js";import"../../chunk-bymtns9a.js";import"../../chunk-y2pe3jq3.js";import"../../chunk-4mtbtmee.js";import"../../chunk-vx4a5crm.js";import"../../chunk-xw9wfq8f.js";import"../../chunk-7hy98p24.js";import"../../chunk-gssantc8.js";import"../../chunk-mcdb3q06.js";export{n as webpackPlugin,a as webpackDts,s as viteDts,s as vite,u as tsupPlugin,e as tsupDts,e as tsup,p as esbuildPlugin,i as esbuildDts,i as esbuild,t as bunDts,t as bun,l as DtsxWebpackPlugin};
|
package/dist/src/plugins/tsup.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ma as a,na as b,oa as c,pa as d}from"../../chunk-
|
|
2
|
+
import{ma as a,na as b,oa as c,pa as d}from"../../chunk-aaba58v4.js";import"../../chunk-af12rv0y.js";import"../../chunk-ft0nf9jb.js";import"../../chunk-2n1bbm2c.js";import"../../chunk-bymtns9a.js";import"../../chunk-y2pe3jq3.js";import"../../chunk-4mtbtmee.js";import"../../chunk-vx4a5crm.js";import"../../chunk-xw9wfq8f.js";import"../../chunk-7hy98p24.js";import"../../chunk-gssantc8.js";import"../../chunk-mcdb3q06.js";export{b as tsupDts,a as dtsxPlugin,c as dts,d as default};
|
package/dist/src/plugins/vite.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ca as a,da as b,ea as c}from"../../chunk-
|
|
2
|
+
import{ca as a,da as b,ea as c}from"../../chunk-4zdjnqrz.js";import"../../chunk-af12rv0y.js";import"../../chunk-ft0nf9jb.js";import"../../chunk-2n1bbm2c.js";import"../../chunk-bymtns9a.js";import"../../chunk-y2pe3jq3.js";import"../../chunk-4mtbtmee.js";import"../../chunk-vx4a5crm.js";import"../../chunk-xw9wfq8f.js";import"../../chunk-7hy98p24.js";import"../../chunk-gssantc8.js";import"../../chunk-mcdb3q06.js";export{b as viteDts,a as dts,c as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{qa as a,ra as b,sa as c,ta as d}from"../../chunk-
|
|
2
|
+
import{qa as a,ra as b,sa as c,ta as d}from"../../chunk-yzhdn85p.js";import"../../chunk-af12rv0y.js";import"../../chunk-ft0nf9jb.js";import"../../chunk-2n1bbm2c.js";import"../../chunk-bymtns9a.js";import"../../chunk-y2pe3jq3.js";import"../../chunk-4mtbtmee.js";import"../../chunk-vx4a5crm.js";import"../../chunk-xw9wfq8f.js";import"../../chunk-7hy98p24.js";import"../../chunk-gssantc8.js";import"../../chunk-mcdb3q06.js";export{b as dtsxWebpack,c as dts,d as default,a as DtsxWebpackPlugin};
|
package/package.json
CHANGED
package/dist/chunk-y4g1csn2.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{ec as l}from"./chunk-ft0nf9jb.js";import{hc as CY}from"./chunk-2n1bbm2c.js";import{lc as UJ}from"./chunk-y2pe3jq3.js";import{Cc as iJ}from"./chunk-vx4a5crm.js";import{Uc as f}from"./chunk-7hy98p24.js";import{Wc as K,Yc as r}from"./chunk-gssantc8.js";import{bd as xY,dd as AY}from"./chunk-mcdb3q06.js";var{Glob:oJ}=globalThis.Bun;import{mkdir as o}from"fs/promises";import{availableParallelism as dY}from"os";import{dirname as u,relative as v,resolve as x}from"path";import{existsSync as ZJ,mkdirSync as JY,readFileSync as YY,writeFileSync as $Y}from"fs";import{dirname as ZY,relative as QY,resolve as UY}from"path";async function TJ(J,Y,$){let Z=new Map,Q=[],U=new Set,X=0,H=0,j=0,G=[];for(let q of J){let B=Y.get(q);if(!B)continue;G.push({file:q,decls:l(B,q,$.keepComments)})}for(let{file:q,decls:B}of G){X+=B.length;for(let k of B)if(k.kind==="import"){H++;let R=k.source||"";if(R.startsWith("."))continue;if(!Z.has(R))Z.set(R,{source:R,specifiers:new Map,isTypeOnly:k.isTypeOnly||!1,isSideEffect:k.isSideEffect||!1});let L=Z.get(R);if(k.specifiers)for(let w of k.specifiers){let S=w.alias||w.name;if(!L.specifiers.has(S))L.specifiers.set(S,{name:w.name,alias:w.alias,isType:w.isType||!1})}if(!k.isTypeOnly)L.isTypeOnly=!1}else if(k.isExported||k.kind==="export"){if(j++,k.kind==="export"&&k.source&&(k.source.startsWith(".")||k.source.startsWith("/")))continue;if(k.name&&U.has(k.name))continue;if(k.name)U.add(k.name);Q.push({declaration:k,file:q})}}let z=[];z.push("/**"),z.push(" * Bundled TypeScript declarations"),z.push(` * Generated from ${J.length} source files`),z.push(" */"),z.push("");let A=$.importOrder||["bun"],N=Array.from(Z.values()),_=Array(N.length);for(let q=0;q<N.length;q++){let B=N[q].source,k=A.length;for(let R=0;R<A.length;R++)if(B.startsWith(A[R])){k=R;break}_[q]=k}let T=N.map((q,B)=>B);T.sort((q,B)=>{let k=_[q],R=_[B];if(k!==R)return k-R;return N[q].source.localeCompare(N[B].source)});let V=T.map((q)=>N[q]);for(let q of V)if(q.isSideEffect)z.push(`import '${q.source}';`);else if(q.specifiers.size>0){let k=Array.from(q.specifiers.values()).map((L)=>{let w=L.isType?"type ":"";return L.alias?`${w}${L.name} as ${L.alias}`:`${w}${L.name}`}),R=q.isTypeOnly?"type ":"";z.push(`import ${R}{ ${k.join(", ")} } from '${q.source}';`)}if(V.length>0)z.push("");let W=new Map;for(let{declaration:q,file:B}of Q){if(!W.has(B))W.set(B,[]);W.get(B).push(q)}for(let[q,B]of W){let k=QY($.cwd,q);z.push(`// From: ${k}`);for(let R of B){if($.keepComments&&R.leadingComments)for(let L of R.leadingComments)z.push(L);z.push(RJ(R))}z.push("")}let O=z.join(`
|
|
3
|
-
`);return{content:O,files:J,declarationCount:X,importCount:H,exportCount:j,size:Buffer.byteLength(O,"utf8"),warnings:[]}}function RJ(J){if(J.text){let $=J.text.trim();if(J.isExported&&!$.startsWith("export"))$=`export ${$}`;if(!$.endsWith(";")&&!$.endsWith("}"))$+=";";return $}let Y=[];if(J.isExported)Y.push("export");if(J.isDefault)Y.push("default");switch(J.kind){case"function":if(Y.push("declare function"),Y.push(J.name),J.generics)Y.push(J.generics);if(Y.push(`(${XY(J.parameters)})`),J.returnType)Y.push(`: ${J.returnType}`);break;case"variable":if(Y.push("declare const"),Y.push(J.name),J.typeAnnotation)Y.push(`: ${J.typeAnnotation}`);break;case"interface":if(Y.push("interface"),Y.push(J.name),J.generics)Y.push(J.generics);if(J.extends)Y.push(`extends ${J.extends}`);if(Y.push("{"),J.members)for(let $ of J.members)Y.push(` ${$.name}${$.typeAnnotation?`: ${$.typeAnnotation}`:""};`);Y.push("}");break;case"type":if(Y.push("type"),Y.push(J.name),J.generics)Y.push(J.generics);Y.push("="),Y.push(J.typeAnnotation||"unknown");break;case"class":if(Y.push("declare class"),Y.push(J.name),J.generics)Y.push(J.generics);if(J.extends)Y.push(`extends ${J.extends}`);if(J.implements&&J.implements.length>0)Y.push(`implements ${J.implements.join(", ")}`);if(Y.push("{"),J.members)for(let $ of J.members)Y.push(` ${RJ($)}`);Y.push("}");break;case"enum":if(Y.push("declare enum"),Y.push(J.name),Y.push("{"),J.members){let $=J.members.map((Z)=>Z.value!==void 0?`${Z.name} = ${Z.value}`:Z.name);Y.push(` ${$.join(`,
|
|
4
|
-
`)}`)}Y.push("}");break;default:return J.text||""}return Y.join(" ")}function XY(J){if(!J||J.length===0)return"";return J.map((Y)=>{let $="";if(Y.rest)$+="...";if($+=Y.name,Y.optional)$+="?";if(Y.type)$+=`: ${Y.type}`;if(Y.defaultValue)$+=` = ${Y.defaultValue}`;return $}).join(", ")}async function LJ(J,Y={}){let $=[],Z=new Map,Q=[],U=[],X=new Set,H=0,j=0,G=0;for(let _ of J){if(!ZJ(_)){$.push(`File not found: ${_}`);continue}let T=YY(_,"utf-8");U.push(_);let V=T.split(`
|
|
5
|
-
`),W=[],O=0,q=!1;for(let B of V){let k=B.trim();if(!k&&!q)continue;if(k.startsWith("import ")){j++;let L=k.match(/import\s+(type\s+)?(?:\{([^}]+)\}|(\w+)|\*\s+as\s+(\w+))\s+from\s+['"]([^'"]+)['"]/);if(L){let[,w,S,M,F,D]=L;if(Y.externals?.some((C)=>D.startsWith(C))){Q.push(k);continue}if(D.startsWith("."))continue;if(!Z.has(D))Z.set(D,{source:D,specifiers:new Map,isTypeOnly:!!w,isSideEffect:!1});let p=Z.get(D);if(S){let C=S.split(",").map((e)=>e.trim());for(let e of C){let[JJ,YJ]=e.split(/\s+as\s+/).map((eJ)=>eJ.trim()),NJ=JJ.startsWith("type "),$J=NJ?JJ.replace("type ",""):JJ;p.specifiers.set(YJ||$J,{name:$J,alias:YJ!==$J?YJ:void 0,isType:NJ})}}if(!w)p.isTypeOnly=!1}continue}if(/^(export\s+)?(declare\s+)?(interface|type|class|function|const|let|var|enum|namespace|module)\s/.test(k)){if(q=!0,W=[B],O=(B.match(/\{/g)||[]).length-(B.match(/\}/g)||[]).length,O===0&&(k.endsWith(";")||!k.includes("{"))){let L=c(k);if(!X.has(L)||!Y.mergeDuplicates){if(X.add(L),Q.push(B),H++,k.startsWith("export"))G++}q=!1,W=[]}}else if(q){if(W.push(B),O+=(B.match(/\{/g)||[]).length-(B.match(/\}/g)||[]).length,O<=0){let L=W.join(`
|
|
6
|
-
`),w=c(W[0]);if(!X.has(w)||!Y.mergeDuplicates){if(X.add(w),Q.push(L),H++,W[0].trim().startsWith("export"))G++}q=!1,W=[]}}else if(k.startsWith("export ")&&!k.includes("declare"))Q.push(B),G++}}let z=[];if(Y.banner)z.push(Y.banner),z.push("");if(Y.includeReferences&&Y.references){for(let _ of Y.references)z.push(`/// <reference types="${_}" />`);z.push("")}let A=Array.from(Z.values()).sort((_,T)=>_.source.localeCompare(T.source));for(let _ of A)if(_.specifiers.size>0){let V=Array.from(_.specifiers.values()).map((O)=>{let q=O.isType?"type ":"";return O.alias?`${q}${O.name} as ${O.alias}`:`${q}${O.name}`}),W=_.isTypeOnly?"type ":"";z.push(`import ${W}{ ${V.join(", ")} } from '${_.source}';`)}if(A.length>0)z.push("");if(Y.ambient&&Y.moduleName){z.push(`declare module '${Y.moduleName}' {`);for(let _ of Q){let T=_.split(`
|
|
7
|
-
`).map((V)=>` ${V.replace(/^(\s*)(export\s+)?declare\s+/,"$1$2")}`).join(`
|
|
8
|
-
`);z.push(T)}z.push("}")}else{if(Y.sortDeclarations)Q.sort((_,T)=>{let V=c(_),W=c(T);return V.localeCompare(W)});for(let _ of Q)z.push(_)}if(Y.footer)z.push(""),z.push(Y.footer);let N=z.join(`
|
|
9
|
-
`);return{content:N,files:U,declarationCount:H,importCount:j,exportCount:G,size:Buffer.byteLength(N,"utf-8"),warnings:$}}function c(J){let Y=J.match(/(interface|type|class|function|const|let|var|enum|namespace|module)\s+(\w+)/);return Y?`${Y[1]}:${Y[2]}`:J.trim()}async function qY(J,Y,$={}){let Z=await LJ(J,$),Q=ZY(Y);if(!ZJ(Q))JY(Q,{recursive:!0});return $Y(Y,Z.content),Z}function iY(J={}){return{bundle:(Y)=>LJ(Y,J),bundleAndWrite:(Y,$)=>qY(Y,$,{...J,output:$})}}async function oY(J,Y=process.cwd()){let $=Array.isArray(J)?J:[J],Z=[];for(let Q of $){if(Q.includes("*"))continue;let U=UY(Y,Q);if(ZJ(U))Z.push(U)}return Z}import{existsSync as s,mkdirSync as zY,readFileSync as XJ,rmSync as VY,statSync as MJ,writeFileSync as wJ}from"fs";import{join as SJ,relative as a,resolve as jY}from"path";var QJ=1,qJ=".dtsx-cache",GY="manifest.json";class zJ{cacheDir;manifestPath;manifest=null;configHash;constructor(J){this.cacheDir=jY(J.cwd,qJ),this.manifestPath=SJ(this.cacheDir,GY),this.configHash=this.hashConfig(J)}hashConfig(J){let Y={keepComments:J.keepComments,importOrder:J.importOrder,outputStructure:J.outputStructure};return String(UJ(JSON.stringify(Y)))}hashString(J){return String(UJ(J))}load(){try{if(!s(this.manifestPath))return!1;let J=XJ(this.manifestPath,"utf-8"),Y=JSON.parse(J);if(Y.version!==QJ)return!1;if(Y.configHash!==this.configHash)return!1;return this.manifest=Y,!0}catch{return!1}}save(){if(!this.manifest)this.manifest={version:QJ,configHash:this.configHash,entries:{},createdAt:Date.now(),updatedAt:Date.now()};if(this.manifest.updatedAt=Date.now(),!s(this.cacheDir))zY(this.cacheDir,{recursive:!0});wJ(this.manifestPath,JSON.stringify(this.manifest,null,2))}needsRegeneration(J,Y){return this.getCachedIfValid(J,Y)===null}getCached(J,Y){return this.getCachedIfValid(J,Y)}getCachedIfValid(J,Y){if(!this.manifest)return null;let $=a(Y,J),Z=this.manifest.entries[$];if(!Z)return null;try{let U=MJ(J).mtimeMs;if(U>Z.sourceMtime){let X=XJ(J,"utf-8");if(this.hashString(X)!==Z.sourceHash)return null;Z.sourceMtime=U}return Z.dtsContent}catch{return null}}update(J,Y,$,Z){if(!this.manifest)this.manifest={version:QJ,configHash:this.configHash,entries:{},createdAt:Date.now(),updatedAt:Date.now()};let Q=a(Z,J),U;try{U=MJ(J).mtimeMs}catch{U=Date.now()}this.manifest.entries[Q]={sourcePath:Q,sourceHash:this.hashString(Y),sourceMtime:U,dtsContent:$,dtsHash:this.hashString($),generatedAt:Date.now(),configHash:this.configHash}}remove(J,Y){if(!this.manifest)return;let $=a(Y,J);delete this.manifest.entries[$]}clear(){this.manifest=null;try{if(s(this.manifestPath))VY(this.cacheDir,{recursive:!0,force:!0})}catch{}}getStats(){if(!this.manifest)return{entries:0,size:0};let J=Object.keys(this.manifest.entries).length,Y=0;for(let $ of Object.values(this.manifest.entries))Y+=$.dtsContent.length;return{entries:J,size:Y}}prune(J,Y){if(!this.manifest)return 0;let $=0,Z=new Set(Array.from(J).map((Q)=>a(Y,Q)));for(let Q of Object.keys(this.manifest.entries))if(!Z.has(Q))delete this.manifest.entries[Q],$++;return $}}function FJ(J){let Y=SJ(J,".gitignore");try{let $="";if(s(Y))$=XJ(Y,"utf-8");if(!$.includes(qJ)){let Z=`${$.trimEnd()}
|
|
10
|
-
|
|
11
|
-
# dtsx cache
|
|
12
|
-
${qJ}/
|
|
13
|
-
`;wJ(Y,Z)}}catch{}}import{spawn as HY}from"child_process";import{readFile as VJ,stat as DJ,writeFile as WY}from"fs/promises";var I=typeof globalThis.Bun<"u",Q0=!I&&typeof process<"u"&&!!process.versions?.node,U0=I?"bun":"node";class vJ{name;_size=-1;constructor(J){this.name=J}async exists(){try{return await DJ(this.name),!0}catch{return!1}}async text(){return VJ(this.name,"utf-8")}async arrayBuffer(){let J=await VJ(this.name);return J.buffer.slice(J.byteOffset,J.byteOffset+J.byteLength)}get size(){if(this._size===-1)return-1;return this._size}}class IJ{pid;stdout;stderr;stdin;exited;process;constructor(J){this.process=J,this.pid=J.pid??0,this.stdout=J.stdout,this.stderr=J.stderr,this.stdin=J.stdin,this.exited=new Promise((Y)=>{J.on("exit",($)=>{Y($??0)}),J.on("error",()=>{Y(1)})})}kill(J){this.process.kill(J)}ref(){this.process.ref()}unref(){this.process.unref()}}function EJ(J){if(I)return globalThis.Bun.file(J);return new vJ(J)}async function jJ(J,Y){if(I)return globalThis.Bun.write(J,Y);let $=typeof Y==="string"?Y:Y instanceof ArrayBuffer?Buffer.from(Y):Y;return await WY(J,$),typeof Y==="string"?Buffer.byteLength(Y):Y.byteLength}function yJ(J,Y={}){if(I)return globalThis.Bun.spawn(J,Y);let $=Array.isArray(J)?J:[J],[Z,...Q]=$,U={cwd:Y.cwd,env:Y.env,stdio:[Y.stdin??"pipe",Y.stdout??"pipe",Y.stderr??"pipe"]},X=HY(Z,Q,U);return new IJ(X)}async function y(J){if(I)return globalThis.Bun.file(J).text();return VJ(J,"utf-8")}async function X0(J){if(I)return globalThis.Bun.file(J).exists();try{return await DJ(J),!0}catch{return!1}}async function q0(J,Y){await jJ(J,Y)}function z0(){if(I)return{name:"bun",version:globalThis.Bun.version,isBun:!0,isNode:!1};return{name:"node",version:process.versions.node,isBun:!1,isNode:!0}}var m={PARSE_ERROR:"PARSE_ERROR",SYNTAX_ERROR:"SYNTAX_ERROR",FILE_NOT_FOUND:"FILE_NOT_FOUND",FILE_READ_ERROR:"FILE_READ_ERROR",FILE_WRITE_ERROR:"FILE_WRITE_ERROR",TYPE_INFERENCE_ERROR:"TYPE_INFERENCE_ERROR",UNRESOLVED_TYPE:"UNRESOLVED_TYPE",EXTRACTION_ERROR:"EXTRACTION_ERROR",PROCESSING_ERROR:"PROCESSING_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",INVALID_DECLARATION:"INVALID_DECLARATION",CONFIG_ERROR:"CONFIG_ERROR",INVALID_ENTRYPOINT:"INVALID_ENTRYPOINT",CIRCULAR_DEPENDENCY:"CIRCULAR_DEPENDENCY",TIMEOUT_ERROR:"TIMEOUT_ERROR",NOT_SUPPORTED:"NOT_SUPPORTED",UNKNOWN_ERROR:"UNKNOWN_ERROR"};class E extends Error{code;context;constructor(J,Y="UNKNOWN_ERROR",$){super(J);if(this.name="DtsxError",this.code=Y,this.context=$,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toString(){let J=`${this.name} [${this.code}]: ${this.message}`;if(this.context)J+=`
|
|
14
|
-
Context: ${JSON.stringify(this.context,null,2)}`;return J}toJSON(){return{name:this.name,code:this.code,message:this.message,context:this.context,stack:this.stack}}}class bJ extends E{filePath;line;column;constructor(J,Y,$){super(J,"PARSE_ERROR",{filePath:Y,line:$?.line,column:$?.column});if(this.name="ParseError",this.filePath=Y,this.line=$?.line,this.column=$?.column,$?.cause)this.cause=$.cause}get locationString(){if(this.line!==void 0&&this.column!==void 0)return`${this.filePath}:${this.line}:${this.column}`;return this.line!==void 0?`${this.filePath}:${this.line}`:this.filePath}}class KY extends E{filePath;declarationKind;constructor(J,Y,$,Z){super(J,"EXTRACTION_ERROR",{filePath:Y,declarationKind:$});if(this.name="ExtractionError",this.filePath=Y,this.declarationKind=$,Z)this.cause=Z}}class _Y extends E{declarationName;constructor(J,Y,$){super(J,"PROCESSING_ERROR",{declarationName:Y});if(this.name="ProcessingError",this.declarationName=Y,$)this.cause=$}}class xJ extends E{filePath;operation;constructor(J,Y,$,Z){super(J,$==="read"?"FILE_READ_ERROR":"FILE_WRITE_ERROR",{filePath:Y,operation:$});if(this.name="FileError",this.filePath=Y,this.operation=$,Z)this.cause=Z}}class CJ extends E{configPath;invalidKey;constructor(J,Y){super(J,"CONFIG_ERROR",{configPath:Y?.configPath,invalidKey:Y?.invalidKey});if(this.name="ConfigError",this.configPath=Y?.configPath,this.invalidKey=Y?.invalidKey,Y?.cause)this.cause=Y.cause}}class BY extends E{cycle;constructor(J){super(`Circular dependency detected: ${J.join(" -> ")}`,"CIRCULAR_DEPENDENCY",{cycle:J});this.name="CircularDependencyError",this.cycle=J}}function j0(J){return J instanceof E}function G0(J){return J instanceof bJ}function H0(J){return J instanceof xJ}function W0(J){return J instanceof CJ}function K0(J,Y="UNKNOWN_ERROR",$){if(J instanceof E)return J;let Z=$||(J instanceof Error?J.message:String(J)),Q=new E(Z,Y);if(J instanceof Error)Q.cause=J;return Q}function _0(J,Y){let $=1,Z=1,Q=0;for(let U of J){if(Q>=Y)break;if(U===`
|
|
15
|
-
`)$++,Z=1;else Z++;Q++}return{line:$,column:Z,offset:Y}}function B0(J,Y,$,Z){let Q=J.split(`
|
|
16
|
-
`),U=Y.line-1,X=[];if(Z)X.push(`${Z}:${Y.line}:${Y.column}`);else X.push(`Line ${Y.line}, Column ${Y.column}`);X.push(`Error: ${$}`),X.push("");let H=Math.max(0,U-1),j=Math.min(Q.length-1,U+1);for(let G=H;G<=j;G++){let z=(G+1).toString().padStart(4," "),A=G===U?">":" ";if(X.push(`${A} ${z} | ${Q[G]}`),G===U){let N=" ".repeat(8+Y.column-1);X.push(`${N}^`)}}return X.join(`
|
|
17
|
-
`)}function GJ(J,Y,$){let Z={file:Y,message:"Unknown error",code:m.UNKNOWN_ERROR};if(J instanceof Error){Z.message=J.message,Z.stack=J.stack;let Q=J.message.match(/\((\d+),(\d+)\)/);if(Q)Z.location={line:Number.parseInt(Q[1],10),column:Number.parseInt(Q[2],10)};if(J.message.includes("Cannot find")||J.message.includes("not found"))Z.code=m.FILE_NOT_FOUND,Z.suggestion="Check that the file path is correct and the file exists.";else if(J.message.includes("syntax")||J.message.includes("Unexpected token"))Z.code=m.SYNTAX_ERROR,Z.suggestion="Check for syntax errors in your TypeScript code.";else if(J.message.includes("type")&&J.message.includes("cannot"))Z.code=m.TYPE_INFERENCE_ERROR,Z.suggestion="Add explicit type annotations to help with type inference.";else if(J.message.includes("parse")||J.message.includes("Parse"))Z.code=m.PARSE_ERROR,Z.suggestion="The file contains invalid TypeScript syntax."}else if(typeof J==="string")Z.message=J;return Z}function PJ(J,Y){let $=[],Z=J.file;if(J.location)Z+=`:${J.location.line}:${J.location.column}`;if(J.code)Z+=` [${J.code}]`;if($.push(Z),$.push(` Error: ${J.message}`),Y&&J.location){$.push("");let Q=Y.split(`
|
|
18
|
-
`),U=J.location.line-1;if(U>=0&&U<Q.length){let X=Math.max(0,U-1),H=Math.min(Q.length-1,U+1);for(let j=X;j<=H;j++){let G=(j+1).toString().padStart(4," "),z=j===U?">":" ";if($.push(` ${z} ${G} | ${Q[j]}`),j===U&&J.location.column>0){let A=" ".repeat(10+J.location.column-1);$.push(` ${A}^`)}}}}if(J.suggestion)$.push(""),$.push(` Suggestion: ${J.suggestion}`);return $.join(`
|
|
19
|
-
`)}function A0(J){if(J.length===0)return"No errors";let Y=new Map;for(let Z of J){let Q=Z.code||"UNKNOWN";Y.set(Q,(Y.get(Q)||0)+1)}let $=[`${J.length} error(s) found:`];for(let[Z,Q]of Y.entries())$.push(` - ${Z}: ${Q}`);return $.join(`
|
|
20
|
-
`)}var n=null,b=null;async function OY(){if(n!==null)return n;try{return b=await import("prettier"),n=!0,!0}catch{return n=!1,!1}}async function kY(J,Y){if(!b)return null;try{if(Y&&b.resolveConfig){let $=await b.resolveConfig(Y);if($)return $}if(J&&b.resolveConfig){let $=await b.resolveConfig(J);if($)return $}return null}catch{return null}}async function NY(J,Y){if(!b)throw Error("Prettier is not available");let $={...Y,parser:Y.parser||"typescript"};return b.format(J,$)}function TY(J,Y={}){let{indentSize:$=2,useTabs:Z=!1,maxLineWidth:Q=100,trailingNewline:U=!0,normalizeWhitespace:X=!0,sortImports:H=!0,groupImports:j=!0}=Y,G=J,z=Z?"\t":" ".repeat($);if(G.indexOf(`\r
|
|
21
|
-
`)!==-1)G=G.replace(/\r\n/g,`
|
|
22
|
-
`);if(X){if(/[ \t]\n/.test(G)||/[ \t]$/.test(G))G=G.replace(/[ \t]+$/gm,"");if(G.indexOf(`
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`)!==-1)G=G.replace(/\n{3,}/g,`
|
|
26
|
-
|
|
27
|
-
`);G=RY(G,z)}if(H||j)G=LY(G,{sort:H,group:j});if(Q>0)G=wY(G,Q,z);if(U&&!G.endsWith(`
|
|
28
|
-
`))G+=`
|
|
29
|
-
`;return G}function RY(J,Y){let $=J.split(`
|
|
30
|
-
`),Z=[];for(let Q of $){let U=Q.match(/^(\s*)(.*)$/);if(!U){Z.push(Q);continue}let[,X,H]=U;if(!H){Z.push("");continue}let j=X.replace(/\t/g," ").length,G=Math.floor(j/2);Z.push(Y.repeat(G)+H)}return Z.join(`
|
|
31
|
-
`)}function LY(J,Y){let $=J.split(`
|
|
32
|
-
`),Z=[],Q=[],U=!1,X=0;for(let j=0;j<$.length;j++){let G=$[j],z=G.match(/^(import\s+(?:type\s+)?.*from\s+['"])([^'"]+)(['"].*)$/);if(z){U=!0,X=j;let A=z[1];Z.push({line:G,source:z[2],isType:A.startsWith("import type ")||A.startsWith("import type\t")})}else if(U&&G.trim()==="")continue;else{if(U)U=!1;Q.push(G)}}if(Z.length===0)return J;if(Y.sort)Z.sort((j,G)=>{if(j.isType!==G.isType)return j.isType?1:-1;return MY(j.source,G.source)});let H;if(Y.group){let j=[],G=[],z=[],A=[],N=[];for(let _=0;_<Z.length;_++){let T=Z[_],V=T.source;if(V.charCodeAt(0)===46)N.push(T);else if(V.startsWith("node:"))j.push(T);else if(V.charCodeAt(0)===64)A.push(T);else if(V.includes("/"))z.push(T);else G.push(T)}H=[...j.map((_)=>_.line),...j.length>0&&G.length>0?[""]:[],...G.map((_)=>_.line),...(j.length>0||G.length>0)&&z.length>0?[""]:[],...z.map((_)=>_.line),...A.length>0&&(j.length>0||G.length>0||z.length>0)?[""]:[],...A.map((_)=>_.line),...N.length>0?[""]:[],...N.map((_)=>_.line)]}else H=Z.map((j)=>j.line);return[...H,"",...Q].join(`
|
|
33
|
-
`)}function MY(J,Y){let $=J.startsWith("node:"),Z=Y.startsWith("node:");if($!==Z)return $?-1:1;let Q=J.startsWith("."),U=Y.startsWith(".");if(Q!==U)return Q?1:-1;return J.localeCompare(Y)}function wY(J,Y,$){let Z=J.split(`
|
|
34
|
-
`),Q=[];for(let U of Z){if(U.length<=Y){Q.push(U);continue}if(U.trimStart().startsWith("import ")){Q.push(U);continue}let X=U.match(/^(\s*)/)?.[1]||"",H=X+$;if(U.includes("{")&&U.includes("}")){let j=SY(U,Y,X,H);Q.push(...j);continue}if(U.includes(" | ")){let j=FY(U,Y,X,H);Q.push(...j);continue}Q.push(U)}return Q.join(`
|
|
35
|
-
`)}function SY(J,Y,$,Z){let Q=J.match(/^(\s*)(.*?)(\{)(.+)(\}.*)$/);if(!Q)return[J];let[,,U,X,H,j]=Q,G=H.split(/;\s*|,\s*/).filter((A)=>A.trim());if(G.length<=1)return[J];return[`${$}${U}${X}`,...G.map((A)=>`${Z}${A.trim()};`),`${$}${j.trim()}`]}function FY(J,Y,$,Z){let Q=J.match(/^(\s*)(.*?=\s*)(.+)$/);if(!Q)return[J];let[,,U,X]=Q,H=X.split(/\s*\|\s*/).filter((G)=>G.trim());if(H.length<=2)return[J];return[`${$}${U}`,...H.map((G,z)=>`${Z}${z>0?"| ":" "}${G.trim()}`)]}async function g(J,Y={},$){let Z=[];if(Y.usePrettier!==!1){if(await OY())try{let H={...await kY(Y.prettierConfigPath,$),...Y.prettierOptions,parser:"typescript"};return{content:await NY(J,H),usedPrettier:!0}}catch(X){Z.push(`Prettier formatting failed: ${X}. Using built-in formatter.`)}else if(Y.usePrettier===!0)Z.push("Prettier requested but not available. Using built-in formatter.")}return{content:TY(J,Y.builtIn),usedPrettier:!1,warnings:Z.length>0?Z:void 0}}async function DY(J,Y={}){let $=new Map;for(let[Z,Q]of J){let U=await g(Q,Y,Z);$.set(Z,U)}return $}function k0(J={}){return{format:(Y,$)=>g(Y,J,$),formatMany:(Y)=>DY(Y,J)}}async function N0(J){return(await g(J,{usePrettier:!0,builtIn:{indentSize:2,normalizeWhitespace:!0,sortImports:!0,trailingNewline:!0}})).content}import{existsSync as vY,statSync as IY}from"fs";import{dirname as EY,isAbsolute as WJ,resolve as yY}from"path";var hJ=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".d.ts"];function HJ(J){try{return IY(J).isFile()}catch{return!1}}function KJ(J,Y){if(!(J.startsWith("./")||J.startsWith("../")||J==="."||J==="..")&&!WJ(J))return{resolved:null,isRelative:!1};let Z=EY(Y),Q=WJ(J)?J:yY(Z,J);if(HJ(Q))return{resolved:Q,isRelative:!0};for(let U of hJ){let X=Q+U;if(HJ(X))return{resolved:X,isRelative:!0}}if(vY(Q))for(let U of hJ){let X=`${Q}/index${U}`;if(HJ(X))return{resolved:X,isRelative:!0}}return{resolved:null,isRelative:!0}}function bY(J){let Y=J.length,$="",Z=0;while(Z<Y){let Q=J.charCodeAt(Z);if(Q===34||Q===39||Q===96){let U=Q;$+=J[Z++];while(Z<Y){let X=J.charCodeAt(Z);if($+=J[Z++],X===92&&Z<Y){$+=J[Z++];continue}if(X===U)break}continue}if(Q===47&&Z+1<Y){let U=J.charCodeAt(Z+1);if(U===47){Z+=2;while(Z<Y&&J.charCodeAt(Z)!==10)Z++;continue}if(U===42){Z+=2;while(Z+1<Y&&!(J.charCodeAt(Z)===42&&J.charCodeAt(Z+1)===47))Z++;Z+=2;continue}}$+=J[Z++]}return $}var mJ=/(?:^|[\n;{}])\s*export\s+(type\s+)?(?:\*(?:\s+as\s+\w+)?|\{[^}]*\})\s+from\s+(['"])([^'"]+)\2/g,gJ=/(?:^|[\n;{}])\s*import\s+(type\s+)?(?:[^'";\n]+\s+from\s+)?(['"])([^'"]+)\2/g;function _J(J,Y={}){let $=[],Z=bY(J);mJ.lastIndex=0;let Q;while((Q=mJ.exec(Z))!==null){let U=!!Q[1],X=Q[3],H=Q[0],j;if(H.includes("* as "))j="export-star-as";else if(H.includes("*"))j="export-star";else j="export-named";$.push({specifier:X,kind:j,isTypeOnly:U})}if(Y.includeImports){gJ.lastIndex=0;while((Q=gJ.exec(Z))!==null)$.push({specifier:Q[3],kind:"import",isTypeOnly:!!Q[1]})}return $}async function BJ(J,Y={}){let $=new Set,Z=new Map,Q=[],U=[];for(let X of J)if(!$.has(X))$.add(X),U.push(X);while(U.length>0){let X=U.shift(),H;try{H=await y(X)}catch{continue}let j=_J(H,Y);Z.set(X,j);for(let G of j){if(!(G.specifier.startsWith(".")||WJ(G.specifier)))continue;let z=KJ(G.specifier,X);if(z.resolved){if(!$.has(z.resolved))$.add(z.resolved),U.push(z.resolved)}else Q.push({from:X,specifier:G.specifier,isTypeOnly:G.isTypeOnly})}}return{reachable:$,reExports:Z,unresolved:Q}}class i{plugins=[];config=null;register(J){if(this.plugins.some((Y)=>Y.name===J.name))throw Error(`Plugin "${J.name}" is already registered`);this.plugins.push(J)}unregister(J){let Y=this.plugins.findIndex(($)=>$.name===J);if(Y>=0)return this.plugins.splice(Y,1),!0;return!1}getPlugins(){return this.plugins}createLogger(J){return{debug:(Y)=>console.debug(`[${J}] ${Y}`),info:(Y)=>console.info(`[${J}] ${Y}`),warn:(Y)=>console.warn(`[${J}] ${Y}`),error:(Y)=>console.error(`[${J}] ${Y}`)}}async runOnStart(J){let Y=J;for(let $ of this.plugins)if($.onStart){let Z=await $.onStart(Y);if(Z)Y=Z}return this.config=Y,Y}async runOnBeforeFile(J,Y){let $=Y;for(let Z of this.plugins)if(Z.onBeforeFile){let Q={filePath:J,sourceCode:Y,content:$,config:this.config,log:this.createLogger(Z.name)},U=await Z.onBeforeFile(Q);if(typeof U==="string")$=U}return $}async runOnDeclarations(J,Y,$){let Z=$;for(let Q of this.plugins)if(Q.onDeclarations){let U={filePath:J,sourceCode:Y,declarations:Z,config:this.config,log:this.createLogger(Q.name)},X=await Q.onDeclarations(U);if(X)Z=X}return Z}async runOnAfterFile(J,Y,$){let Z=$;for(let Q of this.plugins)if(Q.onAfterFile){let U={filePath:J,sourceCode:Y,content:Z,config:this.config,log:this.createLogger(Q.name)},X=await Q.onAfterFile(U);if(typeof X==="string")Z=X}return Z}async runOnEnd(J){for(let Y of this.plugins)if(Y.onEnd)await Y.onEnd(J)}async runOnError(J,Y,$){for(let Z of this.plugins)if(Z.onError){let Q={filePath:Y,sourceCode:$,config:this.config,log:this.createLogger(Z.name)};await Z.onError(J,Q)}}}var S0=new i;function AJ(J){return J}var F0=AJ({name:"strip-internal",version:"1.0.0",description:"Removes declarations marked with @internal",onDeclarations:(J)=>{return J.declarations.filter((Y)=>{if(Y.leadingComments){if(Y.leadingComments.some((Z)=>Z.includes("@internal")))return J.log.debug(`Stripping internal declaration: ${Y.name}`),!1}return!0})}});function D0(J){return AJ({name:"banner",version:"1.0.0",description:"Adds a banner comment to generated files",onAfterFile:(Y)=>{return`/**
|
|
36
|
-
* ${J.split(`
|
|
37
|
-
`).join(`
|
|
38
|
-
* `)}
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
`+Y.content}})}function v0(J){return AJ({name:"filter",version:"1.0.0",description:"Filters declarations by name",onDeclarations:(Y)=>{return Y.declarations.filter(($)=>{if($.kind==="import")return!0;return J($.name)})}})}var P=xY(CY(),1);import{readdir as PY}from"fs/promises";import{dirname as hY,extname as mY,isAbsolute as gY,join as uJ,resolve as fJ}from"path";import pJ from"process";import{pathToFileURL as OJ}from"url";function h0(J,Y){throw Error(Y||`Unexpected value: ${J}`)}async function h(J,Y){let $=Y.replace(/\r\n/g,`
|
|
42
|
-
`);if(!$.endsWith(`
|
|
43
|
-
`))$+=`
|
|
44
|
-
`;await jJ(J,$)}async function fY(J){let Y=J??f.root,$=await PY(Y,{withFileTypes:!0});return(await Promise.all($.map((Q)=>{let U=uJ(Y,Q.name);return Q.isDirectory()?fY(U):U}))).flat(1/0).filter((Q)=>typeof Q==="string"&&mY(Q)===".ts")}async function cJ(J){try{let Y=J?.cwd||pJ.cwd(),$=J?.tsconfigPath||uJ(Y,"tsconfig.json"),Q=await import(OJ($).href);if(Q.compilerOptions?.isolatedDeclarations===!0)return!0;if(Q.extends){let U=dJ($,Q.extends),X=U.endsWith(".json")?U:`${U}.json`,j=await import(OJ(X).href);if(j.compilerOptions?.isolatedDeclarations===!0)return!0;if(j.extends){let G=dJ(X,j.extends),z=G.endsWith(".json")?G:`${G}.json`;if((await import(OJ(z).href)).compilerOptions?.isolatedDeclarations===!0)return!0}}return!1}catch{return!1}}function lJ(J,Y){let $={isValid:!0,errors:[]},Z=P.default.createSourceFile(Y,J,P.default.ScriptTarget.Latest,!0,P.default.ScriptKind.TS),Q={getSourceFile:(H)=>{if(H===Y)return Z;return},getDefaultLibFileName:()=>"lib.d.ts",writeFile:()=>{},getCurrentDirectory:()=>"",getCanonicalFileName:(H)=>H,useCaseSensitiveFileNames:()=>!0,getNewLine:()=>`
|
|
45
|
-
`,fileExists:(H)=>H===Y,readFile:()=>{return}},X=[...P.default.createProgram({rootNames:[Y],options:{noEmit:!0,declaration:!0,skipLibCheck:!0,noLib:!0},host:Q}).getSyntacticDiagnostics(Z)];for(let H of X){let j=P.default.flattenDiagnosticMessageText(H.messageText,`
|
|
46
|
-
`),G=`TS${H.code}`,z;switch(H.code){case 1005:z="Add a semicolon at the end of the statement.";break;case 1109:z="Check for missing or malformed expressions.";break;case 1128:z="Ensure proper declaration syntax is used.";break;case 2304:z="Import or declare the missing type/value.";break;case 2307:z="Check that the module exists and is installed.";break;case 2322:z="Check type compatibility between the values.";break;case 2339:z="Add the missing property to the type definition.";break;case 2345:z="Check the argument types match the expected parameters.";break}if(H.file&&H.start!==void 0){let{line:A,character:N}=H.file.getLineAndCharacterOfPosition(H.start);$.errors.push({line:A+1,column:N+1,message:j,code:G,suggestion:z})}else $.errors.push({line:0,column:0,message:j,code:G,suggestion:z})}return $.isValid=$.errors.length===0,$}function aJ(J,Y,$){if(J===Y)return"";let Z=J.split(`
|
|
47
|
-
`),Q=Y.split(`
|
|
48
|
-
`),U=new Map,X=new Map;for(let z=0;z<Z.length;z++)U.set(Z[z],(U.get(Z[z])??0)+1);for(let z=0;z<Q.length;z++)X.set(Q[z],(X.get(Q[z])??0)+1);let H=[],j=[];for(let[z,A]of U){let N=A-(X.get(z)??0);for(let _=0;_<N;_++)H.push(z)}for(let[z,A]of X){let N=A-(U.get(z)??0);for(let _=0;_<N;_++)j.push(z)}if(H.length===0&&j.length===0)return"";let G=[`--- ${$}`,`+++ ${$}`];for(let z=0;z<H.length;z++)G.push(`- ${H[z]}`);for(let z=0;z<j.length;z++)G.push(`+ ${j[z]}`);return G.join(`
|
|
49
|
-
`)}function dJ(J,Y){if(gY(Y))return Y;if(Y.startsWith("."))return fJ(hY(J),Y);return fJ(pJ.cwd(),"node_modules",Y)}function sJ(J,Y,$,Z){let Q=J.split(`
|
|
50
|
-
`),U=[];function X(A){let _="",T=A<0?-A<<1|1:A<<1;do{let V=T&31;if(T>>>=5,T>0)V|=32;_+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[V]}while(T>0);return _}let H=0,j=0,G=0,z=Z.split(`
|
|
51
|
-
`).length;for(let A=0;A<Q.length;A++){if(Q[A].trim()===""){U.push("");continue}H=0;let _=Math.min(A,z-1),T=[],V=0-H,W=0,O=_-j,q=0-G;T.push(X(V)+X(W)+X(O)+X(q)),H=0,j=_,G=0,U.push(T.join(","))}return{version:3,file:Y,sourceRoot:"",sources:[$],sourcesContent:[Z],mappings:U.join(";")}}function nJ(J,Y){return`${J}
|
|
52
|
-
//# sourceMappingURL=${Y}
|
|
53
|
-
`}async function uY(J){let Y=Date.now(),$={...f,...J};if($.logLevel)r($.logLevel);else if($.verbose)r("debug");let Z=new i;if($.plugins&&$.plugins.length>0){for(let V of $.plugins)Z.register(V),K.debug(`Registered plugin: ${V.name}`);$=await Z.runOnStart($)}if($.isolatedDeclarations===void 0)$.isolatedDeclarations=await cJ($);let Q=null;if($.incremental){if(Q=new zJ($),$.clearCache)K.debug("Clearing build cache..."),Q.clear();else if(Q.load()){let W=Q.getStats();K.debug(`Loaded build cache with ${W.entries} entries`)}else K.debug("No existing build cache found, starting fresh");FJ($.cwd)}let U={filesProcessed:0,filesGenerated:0,filesFailed:0,filesValidated:0,validationErrors:0,declarationsFound:0,importsProcessed:0,exportsProcessed:0,durationMs:0,errors:[]},X=0;K.debug("Starting DTS generation..."),K.debug("Config:",$);let H=await lY($),j=H.slice(),G=null;if($.autoIncludeReExports!==!1&&j.length>0){G=await BJ(j,{includeImports:!0});let V=x($.cwd,$.root),W=$.exclude||[],O=[];for(let q of G.reachable){if(j.includes(q))continue;if(q.endsWith(".d.ts"))continue;if(q.includes("node_modules"))continue;if(t(q,W,V))continue;O.push(q)}if(O.length>0)j=[...j,...O],K.debug(`Auto-included ${O.length} file(s) reached via relative re-exports`)}if(Q){let V=Q.prune(new Set(j),$.cwd);if(V>0)K.debug(`Pruned ${V} deleted files from cache`)}if(K.debug(`Found ${j.length} TypeScript files`),$.progress&&j.length>0){let V=$.parallel?"parallel":"sequential";K.info(`Processing ${j.length} files (${V})...`)}let z=async(V,W)=>{let O;try{let q=kJ(V,$);if(Q){let S=Q.getCachedIfValid(V,$.cwd);if(S)return await o(u(q),{recursive:!0}),await h(q,S),K.debug(`[cached] ${v($.cwd,q)}`),{success:!0,file:V,declarationCount:0,importCount:0,exportCount:0,cached:!0,validationErrorCount:0}}O=W??await y(V);let{content:B,declarationCount:k,importCount:R,exportCount:L}=await tJ(V,O,$,Z),w=0;if($.dryRun)K.info(`[dry-run] Would generate: ${q}`),K.debug("--- Content preview ---"),K.debug(B.slice(0,500)+(B.length>500?`
|
|
54
|
-
...`:"")),K.debug("--- End preview ---");else{if($.diff)try{let M=await y(q),F=aJ(M,B,v($.cwd,q));if(F)K.info(`
|
|
55
|
-
${F}`);else K.debug(`[no changes] ${q}`)}catch{K.info(`[new file] ${v($.cwd,q)}`)}await o(u(q),{recursive:!0});let S=B;if($.declarationMap&&O){let M=q.split("/").pop()||"output.d.ts",F=v(u(q),V),D=`${M}.map`,p=sJ(B,M,F,O),C=`${q}.map`;await h(C,JSON.stringify(p)),S=nJ(B,D),K.debug(` Generated source map: ${v($.cwd,C)}`)}if($.prettier||$.indentStyle||$.indentSize){let M=await g(S,{usePrettier:$.prettier,builtIn:{indentSize:$.indentSize||2,useTabs:$.indentStyle==="tabs",normalizeWhitespace:!0,sortImports:!0,trailingNewline:!0}},q);if(S=M.content,M.warnings?.length)for(let F of M.warnings)K.warn(`[format] ${F}`)}if(await h(q,S),Q&&O)Q.update(V,O,S,$.cwd);if($.validate){let M=lJ(B,q);if(!M.isValid){w=M.errors.length,K.warn(`[validation] ${v($.cwd,q)} has ${M.errors.length} error(s):`);for(let F of M.errors){let D=` Line ${F.line}:${F.column}`;if(F.code)D+=` [${F.code}]`;if(D+=` - ${F.message}`,K.warn(D),F.suggestion)K.warn(` Suggestion: ${F.suggestion}`)}}else K.debug(`[validation] ${q} - OK`)}K.debug(`Generated: ${q}`)}return{success:!0,file:V,declarationCount:k,importCount:R,exportCount:L,validationErrorCount:w}}catch(q){let B=GJ(q,V,O);if($.plugins&&$.plugins.length>0)await Z.runOnError(q instanceof Error?q:Error(String(q)),V,O||"");return{success:!1,file:V,declarationCount:0,importCount:0,exportCount:0,dtsError:B,validationErrorCount:0}}},A=$.parallel||$.parallel!==!1&&j.length>=10,N=$.concurrency||(dY?.()??8),_=new Map;if(A&&j.length>1){let V=j.map(async(W)=>{try{let O=await y(W);return{file:W,source:O}}catch{return{file:W,source:null}}});for(let W of await Promise.all(V))if(W.source!==null)_.set(W.file,W.source)}let T=(V)=>{if(U.filesProcessed++,V.success){if(V.cached)X++;else U.filesGenerated++,U.declarationsFound+=V.declarationCount,U.importsProcessed+=V.importCount,U.exportsProcessed+=V.exportCount;if($.validate){if(U.filesValidated++,V.validationErrorCount)U.validationErrors+=V.validationErrorCount}}else if(U.filesFailed++,V.dtsError){U.errors.push(V.dtsError);let W=PJ(V.dtsError);if($.continueOnError)K.warn(W);else throw K.error(W),Error(V.dtsError.message)}};if(A)for(let V=0;V<j.length;V+=N){let W=j.slice(V,V+N),O=await Promise.all(W.map((q)=>z(q,_.get(q))));for(let q of O)T(q);if($.progress){let q=Math.round(U.filesProcessed/j.length*100);K.info(`[${U.filesProcessed}/${j.length}] ${q}%`)}}else for(let V of j){let W=await z(V);if(T(W),$.progress){let O=Math.round(U.filesProcessed/j.length*100),q=W.cached?"[cached]":"";K.info(`[${U.filesProcessed}/${j.length}] ${O}% - ${v($.cwd,V)} ${q}`)}}if(Q)Q.save(),K.debug("Saved build cache");if(!$.bundle){let V=[];if(G)for(let W of G.unresolved)V.push({from:W.from,specifier:W.specifier,reason:"missing"});if($.autoIncludeReExports===!1&&j.length>0){let W=new Set(j);for(let O of j){let q;try{q=await y(O)}catch{continue}for(let B of _J(q)){if(!B.specifier.startsWith("."))continue;let k=KJ(B.specifier,O);if(!k.resolved)V.push({from:O,specifier:B.specifier,reason:"missing"});else if(!W.has(k.resolved))V.push({from:O,specifier:B.specifier,reason:"not-emitted"})}}}if(V.length>0){let W=[];W.push(`Found ${V.length} re-export(s) pointing at siblings that won't be in the output:`);for(let q of V){let B=v($.cwd,q.from);if(q.reason==="missing")W.push(` ${B} \u2192 '${q.specifier}' (path not found on disk)`);else W.push(` ${B} \u2192 '${q.specifier}' (resolved but not in entrypoints; set autoIncludeReExports: true or add to entrypoints)`)}let O=W.join(`
|
|
56
|
-
`);if($.failOnUnresolvedReExport)throw Error(O);K.warn(O),K.warn('Generated .d.ts files reference modules that were not emitted \u2014 consumers will see "has no exported member" errors.')}}if($.bundle&&(U.filesGenerated>0||X>0)&&H.length>0)try{K.debug("Bundling declarations...");let V=new Map,W=async(q)=>{let B=V.get(q);if(B!==void 0)return B;return B=await y(q),V.set(q,B),B};for(let q of j)await W(q);let O=H.length===1&&!!$.bundleOutput;for(let q of H){let B=await BJ([q],{includeImports:!0}),k=new Set;for(let M of B.reachable){if(M.endsWith(".d.ts"))continue;if(M.includes("node_modules"))continue;k.add(M)}let R=j.filter((M)=>k.has(M));if(!R.includes(q))R.push(q);let L=new Map;for(let M of R){let F=V.get(M)??await W(M);L.set(M,F)}let w=await TJ(R,L,$),S=O?x($.cwd,$.outdir,$.bundleOutput):kJ(q,$);if(await o(u(S),{recursive:!0}),await h(S,w.content),K.info(`Bundled ${w.files.length} files to: ${v($.cwd,S)}`),O)break}}catch(V){let W=V instanceof Error?V.message:String(V);K.error(`Bundle failed: ${W}`)}if(U.durationMs=Date.now()-Y,$.stats)if($.outputFormat==="json")console.log(JSON.stringify(U,null,2));else{if(K.info(`
|
|
57
|
-
--- Generation Statistics ---`),K.info(`Files processed: ${U.filesProcessed}`),K.info(`Files generated: ${U.filesGenerated}`),X>0)K.info(`Files cached: ${X}`);if(U.filesFailed>0)K.info(`Files failed: ${U.filesFailed}`);if(K.info(`Declarations found: ${U.declarationsFound}`),K.info(`Imports processed: ${U.importsProcessed}`),K.info(`Exports processed: ${U.exportsProcessed}`),U.filesValidated>0){if(K.info(`Files validated: ${U.filesValidated}`),U.validationErrors>0)K.info(`Validation errors: ${U.validationErrors}`)}if(K.info(`Duration: ${U.durationMs}ms`),U.errors.length>0){K.info(`
|
|
58
|
-
Errors:`);for(let V of U.errors){let W=` - ${V.file}`;if(V.location)W+=`:${V.location.line}:${V.location.column}`;if(V.code)W+=` [${V.code}]`;if(W+=`: ${V.message}`,K.info(W),V.suggestion)K.info(` Suggestion: ${V.suggestion}`)}}K.info(`-----------------------------
|
|
59
|
-
`)}if($.plugins&&$.plugins.length>0)await Z.runOnEnd(U);return K.debug("DTS generation complete!"),U}var pY=50,d=new Map;function cY(J){let Y=d.get(J);if(!Y){if(Y=new oJ(J),d.set(J,Y),d.size>pY){let $=d.keys().next().value;if($!==void 0)d.delete($)}}return Y}function t(J,Y,$){if(!Y||Y.length===0)return!1;let Z=v($,J);for(let Q of Y){let U=cY(Q);if(U.match(Z)||U.match(J))return!0}return!1}async function lY(J){let Y=[],$=x(J.cwd,J.root),Z=J.exclude||[];for(let Q of J.entrypoints)if(Q.startsWith("/")&&Q.endsWith(".ts")){if(!Q.endsWith(".d.ts")&&!Q.includes("node_modules")){if(!t(Q,Z,$))Y.push(Q)}}else{let U=new oJ(Q);for await(let X of U.scan({cwd:$,absolute:!0,onlyFiles:!0}))if(!X.endsWith(".d.ts")&&!X.includes("node_modules")){if(!t(X,Z,$))Y.push(X)}}return[...new Set(Y)]}function kJ(J,Y){let $=x(Y.cwd,Y.root),Q=v($,J).replace(/\.(m?tsx?|cts)$/,(U)=>{if(U===".mts")return".d.mts";if(U===".cts")return".d.cts";return".d.ts"});if(Y.outputStructure==="mirror")return x(Y.cwd,Y.outdir,Q);else{let U=Q.split("/").pop();return x(Y.cwd,Y.outdir,U)}}async function Z1(J,Y){return(await rJ(J,Y)).content}async function rJ(J,Y,$){let Z=await y(J);return tJ(J,Z,Y,$)}async function tJ(J,Y,$,Z){let Q=Y;if(Z)Q=await Z.runOnBeforeFile(J,Y);let U=l(Q,J,$.keepComments,$.isolatedDeclarations??!1);if(Z)U=await Z.runOnDeclarations(J,Q,U);let X=0,H=0;for(let z=0;z<U.length;z++){let A=U[z];if(A.kind==="import")X++;if(A.kind==="export"||A.isExported)H++}let G=iJ(U,{filePath:J,sourceCode:Q,declarations:U},$.keepComments,$.importOrder);if(Z)G=await Z.runOnAfterFile(J,Q,G);return{content:G,declarationCount:U.length,importCount:X,exportCount:H}}async function Q1(J){let Y={...f,...J};if(Y.logLevel)r(Y.logLevel);let $=x(Y.cwd,Y.root),Z=150,Q=5,U=1e4,X={pendingChanges:new Set,debounceTimer:null,isProcessing:!1,errorCount:0,lastErrorTime:0};K.info(`Watching for changes in ${$}...`),K.info(`Press Ctrl+C to stop
|
|
60
|
-
`);try{await uY(Y),K.info(`[watch] Initial generation complete
|
|
61
|
-
`)}catch(A){let N=A instanceof Error?A.message:String(A);K.error(`[watch] Initial generation failed: ${N}`),K.info(`[watch] Continuing to watch for changes...
|
|
62
|
-
`)}async function H(){if(X.isProcessing||X.pendingChanges.size===0)return;let A=Date.now();if(X.errorCount>=Q){if(A-X.lastErrorTime<U){K.warn(`[watch] Too many errors, pausing for ${Math.ceil((U-(A-X.lastErrorTime))/1000)}s...`);return}X.errorCount=0}X.isProcessing=!0;let N=Array.from(X.pendingChanges);X.pendingChanges.clear();let _=new Date().toLocaleTimeString();if(N.length===1)K.info(`
|
|
63
|
-
[${_}] File changed: ${N[0]}`);else K.info(`
|
|
64
|
-
[${_}] ${N.length} files changed`);let T=0,V=0;for(let W of N){let O=x($,W);try{let q=Y.exclude||[];if(t(O,q,$)){K.debug(` Skipping excluded file: ${W}`);continue}if(!await EJ(O).exists()){K.debug(` Skipping deleted file: ${W}`);continue}let k=kJ(O,Y),{content:R}=await rJ(O,Y);await o(u(k),{recursive:!0}),await h(k,R),K.info(` \u2713 ${v(Y.cwd,k)}`),T++}catch(q){V++,X.errorCount++,X.lastErrorTime=Date.now();let B=GJ(q,O);if(K.error(` \u2717 ${W}: ${B.message}`),B.suggestion)K.error(` Suggestion: ${B.suggestion}`)}}if(N.length>1)K.info(` Done: ${T} generated, ${V} failed`);if(V===0)X.errorCount=0;if(X.isProcessing=!1,X.pendingChanges.size>0)X.debounceTimer=setTimeout(H,Z)}function j(A){if(X.pendingChanges.add(A),X.debounceTimer)clearTimeout(X.debounceTimer);X.debounceTimer=setTimeout(H,Z)}let z=yJ([I?"bun":"node","-e",`
|
|
65
|
-
const fs = require('fs');
|
|
66
|
-
|
|
67
|
-
const rootPath = '${$}';
|
|
68
|
-
|
|
69
|
-
fs.watch(rootPath, { recursive: true }, (eventType, filename) => {
|
|
70
|
-
if (filename && filename.endsWith('.ts') && !filename.endsWith('.d.ts')) {
|
|
71
|
-
console.log(\`CHANGED:\${filename}\`);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Keep process alive
|
|
76
|
-
setInterval(() => {}, 1000);
|
|
77
|
-
`],{stdout:"pipe",stderr:"inherit"});if(I){let A=z.stdout.getReader(),N=new TextDecoder,_="";while(!0){let{done:T,value:V}=await A.read();if(T)break;_+=N.decode(V,{stream:!0});let W=_.split(`
|
|
78
|
-
`);_=W.pop()||"";for(let O of W)if(O.startsWith("CHANGED:")){let q=O.slice(8);j(q)}}}else{let A=z.stdout,N="";A.on("data",(_)=>{N+=_.toString();let T=N.split(`
|
|
79
|
-
`);N=T.pop()||"";for(let V of T)if(V.startsWith("CHANGED:")){let W=V.slice(8);j(W)}}),await z.exited}}
|
|
80
|
-
export{TJ as ua,LJ as va,qY as wa,iY as xa,oY as ya,zJ as za,FJ as Aa,I as Ba,Q0 as Ca,U0 as Da,EJ as Ea,jJ as Fa,yJ as Ga,y as Ha,X0 as Ia,q0 as Ja,z0 as Ka,m as La,E as Ma,bJ as Na,KY as Oa,_Y as Pa,xJ as Qa,CJ as Ra,BY as Sa,j0 as Ta,G0 as Ua,H0 as Va,W0 as Wa,K0 as Xa,_0 as Ya,B0 as Za,GJ as _a,PJ as $a,A0 as ab,g as bb,DY as cb,k0 as db,N0 as eb,i as fb,S0 as gb,AJ as hb,F0 as ib,D0 as jb,v0 as kb,h0 as lb,h as mb,fY as nb,cJ as ob,lJ as pb,aJ as qb,sJ as rb,nJ as sb,uY as tb,Z1 as ub,Q1 as vb};
|