@stacksjs/dtsx 0.9.13 → 0.9.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -8
- package/dist/bin/cli.js +6 -6
- package/dist/branded-types.d.ts +10 -18
- package/dist/chunk-14gh6ezz.js +80 -0
- package/dist/chunk-285mqzvx.js +16 -0
- package/dist/chunk-2n1bbm2c.js +448 -0
- package/dist/chunk-2r21f44d.js +25 -0
- package/dist/chunk-3xqchdwd.js +2 -0
- package/dist/{chunk-e0gx49tv.js → chunk-3zjt21t1.js} +1 -1
- package/dist/chunk-4s9jv983.js +3 -0
- package/dist/chunk-5hzvjjt0.js +2 -0
- package/dist/chunk-83e9a4fq.js +4 -0
- package/dist/chunk-8cv1t8qg.js +2 -0
- package/dist/{chunk-pdt5pc9f.js → chunk-8g7jyxbr.js} +1 -1
- package/dist/chunk-8z31rkfp.js +3 -0
- package/dist/chunk-a3txc27m.js +33 -0
- package/dist/chunk-bh9ey0vw.js +2 -0
- package/dist/chunk-bsxtpwx6.js +2 -0
- package/dist/{chunk-0f9tt1yd.js → chunk-c09v68yx.js} +1 -1
- package/dist/{chunk-emwe4zbk.js → chunk-f4c389mj.js} +1 -1
- package/dist/{chunk-hbd2nj9p.js → chunk-fef6249b.js} +1 -1
- package/dist/{chunk-57agx6g8.js → chunk-gssantc8.js} +1 -1
- package/dist/chunk-j2yw0d45.js +6 -0
- package/dist/{chunk-ns3hznyf.js → chunk-mcdb3q06.js} +1 -1
- package/dist/{chunk-tzrvp0n2.js → chunk-mn46jafe.js} +1 -1
- package/dist/{chunk-mrk48ejm.js → chunk-mxam9312.js} +8 -8
- package/dist/chunk-nf54b52t.js +6 -0
- package/dist/{chunk-f0mvmcmj.js → chunk-npj0c002.js} +1 -1
- package/dist/chunk-pep9jyxn.js +2 -0
- package/dist/chunk-qrht3d5g.js +2 -0
- package/dist/chunk-rh2bqn7v.js +2 -0
- package/dist/{chunk-ck86m3vf.js → chunk-sw3m29sw.js} +1 -1
- package/dist/{chunk-a592hfkt.js → chunk-tne5n3h1.js} +1 -1
- package/dist/{chunk-1t76q5wk.js → chunk-trm0gptj.js} +1 -1
- package/dist/chunk-vpjw38x7.js +34 -0
- package/dist/chunk-w71syh0b.js +2 -0
- package/dist/chunk-w8d9jjsa.js +2 -0
- package/dist/{chunk-188ep5ns.js → chunk-xhs0tsnn.js} +1 -1
- package/dist/{chunk-e38jw5aa.js → chunk-xmje6xfw.js} +1 -1
- package/dist/{chunk-vf7ywnxz.js → chunk-xtee8g1a.js} +1 -1
- package/dist/chunk-y581wnfe.js +19 -0
- package/dist/{chunk-6qv7p9sg.js → chunk-zf17s33e.js} +18 -11
- package/dist/compat.d.ts +5 -2
- package/dist/extractor/cache.d.ts +6 -2
- package/dist/extractor/directives.d.ts +0 -4
- package/dist/generator.d.ts +1 -1
- package/dist/logger.d.ts +4 -0
- package/dist/optimizer.d.ts +4 -0
- package/dist/process-source.d.ts +1 -0
- package/dist/processor/cache.d.ts +4 -2
- package/dist/processor/imports.d.ts +1 -0
- package/dist/src/index.js +52 -51
- 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/dist/transformers.d.ts +4 -1
- package/dist/type-mappings.d.ts +16 -16
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
- package/dist/chunk-2vw7w2j4.js +0 -23
- package/dist/chunk-365avtde.js +0 -32
- package/dist/chunk-446n992h.js +0 -2
- package/dist/chunk-49b3ran6.js +0 -4
- package/dist/chunk-50hbgzrj.js +0 -3
- package/dist/chunk-6jpqpjkc.js +0 -3
- package/dist/chunk-94h87sgb.js +0 -449
- package/dist/chunk-at36dtgx.js +0 -2
- package/dist/chunk-b0bkjk0p.js +0 -19
- package/dist/chunk-chbk4344.js +0 -2
- package/dist/chunk-ez568rby.js +0 -2
- package/dist/chunk-hwm87z68.js +0 -2
- package/dist/chunk-jfk0hw36.js +0 -75
- package/dist/chunk-myvmq7hz.js +0 -2
- package/dist/chunk-nd0xbpbz.js +0 -2
- package/dist/chunk-nfeqwqca.js +0 -6
- package/dist/chunk-nr1gxnen.js +0 -2
- package/dist/chunk-pdvve1gm.js +0 -33
- package/dist/chunk-sv136qag.js +0 -17
- package/dist/chunk-te9r0j9z.js +0 -6
- package/dist/chunk-trftkghj.js +0 -2
- package/dist/chunk-xqymptjk.js +0 -2
- package/dist/extractor/extract.d.ts +0 -10
- package/dist/extractor/scanner.d.ts +0 -6
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center"><img src="https://github.com/stacksjs/dtsx/blob/main/.github/art/cover.jpg?raw=true" alt="Social Card of this repo"></p>
|
|
2
2
|
|
|
3
|
-
[![npm version]
|
|
4
|
-
[![GitHub Actions]
|
|
3
|
+
[](https://npmjs.com/package/@stacksjs/dtsx)
|
|
4
|
+
[](https://github.com/stacksjs/dtsx/actions?query=workflow%3Aci)
|
|
5
5
|
[](http://commitizen.github.io/cz-cli/)
|
|
6
6
|
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
7
|
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
bun install -d @stacksjs/dtsx
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
_@npmjs.com, please allow us to use the `dtsx` package name 🙏_
|
|
31
|
+
> _@npmjs.com, please allow us to use the `dtsx` package name 🙏_
|
|
32
32
|
|
|
33
33
|
<!-- _Alternatively, you can install:_
|
|
34
34
|
|
|
@@ -116,7 +116,7 @@ _You may also run:_
|
|
|
116
116
|
```bash
|
|
117
117
|
./dtsx generate
|
|
118
118
|
|
|
119
|
-
# if the package is installed, you can also run
|
|
119
|
+
# if the package is installed, you can also run
|
|
120
120
|
# bunx dtsx generate
|
|
121
121
|
```
|
|
122
122
|
|
|
@@ -411,10 +411,6 @@ The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/dtsx/tre
|
|
|
411
411
|
Made with 💙
|
|
412
412
|
|
|
413
413
|
<!-- Badges -->
|
|
414
|
-
[npm-version-src]: https://img.shields.io/npm/v/@stacksjs/dtsx?style=flat-square
|
|
415
|
-
[npm-version-href]: https://npmjs.com/package/@stacksjs/dtsx
|
|
416
|
-
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/dtsx/ci.yml?style=flat-square&branch=main
|
|
417
|
-
[github-actions-href]: https://github.com/stacksjs/dtsx/actions?query=workflow%3Aci
|
|
418
414
|
|
|
419
415
|
<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/dtsx/main?style=flat-square
|
|
420
416
|
[codecov-href]: https://codecov.io/gh/stacksjs/dtsx -->
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
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-
|
|
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-8cv1t8qg.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
|
+
`)}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-bh9ey0vw.js"),{processDeclarations:F}=await import("../chunk-xmje6xfw.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-8cv1t8qg.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-
|
|
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-
|
|
5
|
+
`)}V.exit(0)}var{resolve:h}=await import("path"),{CLI:s}=await import("../chunk-trm0gptj.js"),{version:e}=await import("../chunk-5hzvjjt0.js"),{getConfig:o}=await import("../chunk-w71syh0b.js"),{generate:qq,processSource:Hq,watch:Kq}=await import("../chunk-rh2bqn7v.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-w8d9jjsa.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-bsxtpwx6.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-qrht3d5g.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-pep9jyxn.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
|
-
${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-
|
|
10
|
-
Converted ${X} declarations from ${F} files`)}catch(Q){console.error("Error converting files:",Q),V.exit(1)}});k.command("circular","Detect circular dependencies in TypeScript files").option("--files <patterns>","Glob patterns for files to check",{default:"**/*.ts",type:[String]}).option("--root <path>","Root directory for resolution",{default:"."}).option("--ignore <patterns>","Glob patterns to ignore (comma-separated)",{default:"",type:[String]}).option("--types-only","Only report type-level cycles",{default:!1}).option("--max-depth <number>","Maximum depth for cycle detection",{default:100}).option("--include-node-modules","Include node_modules in analysis",{default:!1}).option("--format <format>","Output format: text, json, dot",{default:"text"}).option("--summary","Show graph summary statistics",{default:!1}).example("dtsx circular").example('dtsx circular --files "src/**/*.ts"').example('dtsx circular --ignore "**/*.test.ts,**/__tests__/**"').example("dtsx circular --format dot > deps.dot").example("dtsx circular --summary").action(async(q)=>{try{let{analyzeCircularDependencies:Q,formatCircularAnalysis:K,getGraphSummary:N,exportGraphAsDot:A,exportGraphAsJson:J}=await import("../chunk-
|
|
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-3zjt21t1.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(`
|
|
10
|
+
Converted ${X} declarations from ${F} files`)}catch(Q){console.error("Error converting files:",Q),V.exit(1)}});k.command("circular","Detect circular dependencies in TypeScript files").option("--files <patterns>","Glob patterns for files to check",{default:"**/*.ts",type:[String]}).option("--root <path>","Root directory for resolution",{default:"."}).option("--ignore <patterns>","Glob patterns to ignore (comma-separated)",{default:"",type:[String]}).option("--types-only","Only report type-level cycles",{default:!1}).option("--max-depth <number>","Maximum depth for cycle detection",{default:100}).option("--include-node-modules","Include node_modules in analysis",{default:!1}).option("--format <format>","Output format: text, json, dot",{default:"text"}).option("--summary","Show graph summary statistics",{default:!1}).example("dtsx circular").example('dtsx circular --files "src/**/*.ts"').example('dtsx circular --ignore "**/*.test.ts,**/__tests__/**"').example("dtsx circular --format dot > deps.dot").example("dtsx circular --summary").action(async(q)=>{try{let{analyzeCircularDependencies:Q,formatCircularAnalysis:K,getGraphSummary:N,exportGraphAsDot:A,exportGraphAsJson:J}=await import("../chunk-tne5n3h1.js"),{Glob:$}=awaitPromise.resolve(globalThis.Bun),{resolve:z,relative:B}=await import("path"),G=V.cwd(),j=z(q.root||"."),Z=q.files||["**/*.ts"],E=[];for(let T of Z){let R=new $(T);for await(let I of R.scan({cwd:j,absolute:!0,onlyFiles:!0}))if(!I.endsWith(".d.ts")){if(!q.includeNodeModules&&I.includes("node_modules"))continue;E.push(I)}}if(E.length===0)console.error("No TypeScript files found"),V.exit(1);console.log(`Analyzing ${E.length} files for circular dependencies...`);let M=await Q(E,{rootDir:j,ignore:q.ignore?.filter(Boolean),typesOnly:q.typesOnly??!1,maxDepth:q.maxDepth??100,includeNodeModules:q.includeNodeModules??!1});if(q.format==="json")console.log(J(M.graph,j));else if(q.format==="dot")console.log(A(M.graph,j));else if(console.log(K(M,j)),q.summary){let T=N(M.graph);if(console.log(`
|
|
11
11
|
--- Dependency Graph Summary ---`),console.log(`Total files: ${T.totalFiles}`),console.log(`Total dependencies: ${T.totalDependencies}`),console.log(`Average dependencies per file: ${T.avgDependencies.toFixed(2)}`),T.maxDependencies.count>0)console.log(`Most dependencies: ${B(j,T.maxDependencies.file)} (${T.maxDependencies.count})`);if(T.mostDepended.count>0)console.log(`Most depended on: ${B(j,T.mostDepended.file)} (${T.mostDepended.count} dependents)`);if(T.isolatedFiles.length>0)console.log(`Isolated files (no dependencies): ${T.isolatedFiles.length}`)}V.exit(M.hasCircular?1:0)}catch(Q){console.error("Error analyzing dependencies:",Q),V.exit(1)}});k.command("version","Show the version of dtsx").action(()=>{console.log(e)});k.version(e);k.help();k.parse();
|
package/dist/branded-types.d.ts
CHANGED
|
@@ -52,44 +52,36 @@ export declare function isBranded<T, B extends string>(value: unknown, _brand: B
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function unwrap<T>(branded: Brand<T, string>): T;
|
|
54
54
|
/**
|
|
55
|
-
* Safe path operations that preserve branding
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* join: (base: DirectoryPath, ...segments: string[]) => unknown,
|
|
60
|
-
* dirname: (path: FilePath) => unknown,
|
|
61
|
-
* basename: (path: FilePath) => unknown,
|
|
62
|
-
* resolve: (...segments: string[]) => unknown,
|
|
63
|
-
* isAbsolute: (path: string) => unknown,
|
|
64
|
-
* relative: (from: DirectoryPath, to: FilePath) => unknown
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
55
|
+
* Safe path operations that preserve branding.
|
|
56
|
+
* Uses ESM imports hoisted to module scope so each call avoids the per-call
|
|
57
|
+
* `require('node:path')` overhead that the previous CommonJS-style implementation
|
|
58
|
+
* incurred.
|
|
67
59
|
*/
|
|
68
60
|
export declare const BrandedPath: {
|
|
69
61
|
/**
|
|
70
62
|
* Join path segments, returning appropriate branded type
|
|
71
63
|
*/
|
|
72
|
-
join: (base: DirectoryPath, ...segments: string[]) =>
|
|
64
|
+
join: (base: DirectoryPath, ...segments: string[]) => FilePath;
|
|
73
65
|
/**
|
|
74
66
|
* Get directory name from a file path
|
|
75
67
|
*/
|
|
76
|
-
dirname: (path: FilePath) =>
|
|
68
|
+
dirname: (path: FilePath) => DirectoryPath;
|
|
77
69
|
/**
|
|
78
70
|
* Get base name from a file path
|
|
79
71
|
*/
|
|
80
|
-
basename: (path: FilePath) =>
|
|
72
|
+
basename: (path: FilePath) => string;
|
|
81
73
|
/**
|
|
82
74
|
* Resolve path to absolute
|
|
83
75
|
*/
|
|
84
|
-
resolve: (...segments: string[]) =>
|
|
76
|
+
resolve: (...segments: string[]) => AbsolutePath;
|
|
85
77
|
/**
|
|
86
78
|
* Check if path is absolute
|
|
87
79
|
*/
|
|
88
|
-
isAbsolute: (path: string) =>
|
|
80
|
+
isAbsolute: (path: string) => path is AbsolutePath;
|
|
89
81
|
/**
|
|
90
82
|
* Get relative path from one path to another
|
|
91
83
|
*/
|
|
92
|
-
relative: (from: DirectoryPath, to: FilePath) =>
|
|
84
|
+
relative: (from: DirectoryPath, to: FilePath) => RelativePath
|
|
93
85
|
};
|
|
94
86
|
/**
|
|
95
87
|
* Generic branded type creator
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{ec as l}from"./chunk-y581wnfe.js";import{hc as CY}from"./chunk-2n1bbm2c.js";import{lc as UJ}from"./chunk-8z31rkfp.js";import{Cc as iJ}from"./chunk-vpjw38x7.js";import{Uc as f}from"./chunk-a3txc27m.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);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};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var E=!1,M=null;function h(J){if(J.indexOf("/*")===-1)return J.trim();let X=[],$=0,z=0,B=J.length;while(z<B)if(J.charCodeAt(z)===47&&z+1<B&&J.charCodeAt(z+1)===42){if(z>$)X.push(J.substring($,z));z+=2;while(z<B-1){if(J.charCodeAt(z)===42&&J.charCodeAt(z+1)===47){z+=2;break}z++}$=z}else z++;if($<B)X.push(J.substring($));return X.join("").trim()}function $z(){E=!0,M=null}function Qz(){E=!1;let J=M;return M=null,J}function S(J){let Y=J.length;if(Y===0)return!1;let X=0;if(J.charCodeAt(X)===45)X++;if(X>=Y)return!1;let $=X;while(X<Y&&J.charCodeAt(X)>=48&&J.charCodeAt(X)<=57)X++;if(X===$)return!1;if(X<Y&&J.charCodeAt(X)===46){X++;let z=X;while(X<Y&&J.charCodeAt(X)>=48&&J.charCodeAt(X)<=57)X++;if(X===z)return!1}return X===Y}function o(J){for(let Y=0,X=J.length-1;Y<X;Y++){let $=J.charCodeAt(Y);if($<48||$>57)return!1}return!0}function D(J,Y){let X=0,$=0;while(($=J.indexOf(Y,$))!==-1)X++,$+=Y.length;return X}function _(J){let Y=J.length,X=!1;for(let Z=1;Z<Y;Z++)if(J.charCodeAt(Z)<=32&&J.charCodeAt(Z-1)<=32){X=!0;break}if(!X)for(let Z=0;Z<Y;Z++){let H=J.charCodeAt(Z);if(H===10||H===13||H===9){X=!0;break}}if(!X)return J;let $=[],z=-1,B=!1;for(let Z=0;Z<Y;Z++)if(J.charCodeAt(Z)<=32){if(!B){if(z>=0)$.push(J.substring(z,Z));$.push(" "),B=!0,z=-1}}else{if(B||z<0)z=Z;B=!1}if(z>=0)$.push(J.substring(z));return $.join("")}function V(J,Y=!1,X=!1,$=0){if(!J||typeof J!=="string")return"unknown";if($>=20)return"unknown";let z=J.trim();if(z.startsWith("BigInt("))return"bigint";if(z.startsWith("Symbol.for("))return"symbol";if(z.includes(".raw`")||z.includes("String.raw`"))return"string";if(z.startsWith('"')&&z.endsWith('"')||z.startsWith("'")&&z.endsWith("'")||z.startsWith("`")&&z.endsWith("`")){if(!z.includes("${")){if(!Y)return"string";return z}if(Y)return z;return"string"}if(S(z)){if(!Y)return"number";return z}if(z==="true"||z==="false"){if(!Y)return"boolean";return z}if(z==="null")return"null";if(z==="undefined")return"undefined";if(z.startsWith("[")&&z.endsWith("]"))return I(z,Y,$+1);if(z.startsWith("{")&&z.endsWith("}"))return s(z,Y,$+1);if(z.startsWith("class ")||z.startsWith("class{"))return c(z);if(z.startsWith("new "))return d(z);if(z.includes("=>")||z.startsWith("function")||z.startsWith("async"))return y(z,X,$,Y);if(z.endsWith("as const")){let B=z.slice(0,-8).trim();if(B.startsWith("[")&&B.endsWith("]")){let Z=B.slice(1,-1).trim();if(!Z)return"readonly []";let H=w(Z),Q=[];for(let L=0;L<H.length;L++)Q.push(V(H[L].trim(),!0,!1,$+1));return`readonly [${Q.join(", ")}]`}return V(B,!0,X,$+1)}if(z.startsWith("`")&&z.endsWith("`"))return p(z,Y);if(z.startsWith("Promise."))return f(z,Y,$);if(z.startsWith("await "))return"unknown";if(z.charCodeAt(z.length-1)===110&&z.length>1&&o(z)){if(Y)return z;return"bigint"}if(z.startsWith("Symbol(")||z==="Symbol.for")return"symbol";return"unknown"}function l(J,Y=!1,X=0){return V(J,Y,!0,X)}function p(J,Y){if(J.includes(".raw`")||J.includes("String.raw`"))return"string";if(!Y)return"string";if(!J.includes("${"))return J;return"string"}function d(J){let Y=4;while(Y<J.length&&J.charCodeAt(Y)<=32)Y++;let X=Y,$=J.charCodeAt(Y);if($<65||$>90)return"unknown";while(Y<J.length&&(P(J.charCodeAt(Y))||J.charCodeAt(Y)===46))Y++;if(Y===X)return"unknown";let z=J.slice(X,Y);{let B=J.slice(Y),Z=B;if(B.startsWith("<")){let Q=0,L=-1;for(let O=0;O<B.length;O++)if(B[O]==="<")Q++;else if(B[O]===">"){if(Q--,Q===0){L=O;break}}if(L!==-1){let O=B.slice(0,L+1);Z=B.slice(L+1);let G=Z.indexOf("(");if(G!==-1){let W=0,K=-1;for(let F=G;F<Z.length;F++)if(Z[F]==="(")W++;else if(Z[F]===")"){if(W--,W===0){K=F;break}}if(K!==-1){if(Z.slice(K+1).trimStart().startsWith("."))return"unknown"}}return`${z}${O}`}}let H=Z.indexOf("(");if(H!==-1){let Q=0,L=-1;for(let O=H;O<Z.length;O++)if(Z[O]==="(")Q++;else if(Z[O]===")"){if(Q--,Q===0){L=O;break}}if(L!==-1){if(Z.slice(L+1).trimStart().startsWith("."))return"unknown"}}switch(z){case"Date":return"Date";case"Map":return"Map<any, any>";case"Set":return"Set<any>";case"WeakMap":return"WeakMap<any, any>";case"WeakSet":return"WeakSet<any>";case"RegExp":return"RegExp";case"Error":return"Error";case"Array":return"any[]";case"Object":return"object";case"Function":return"Function";case"Promise":return"Promise<any>";default:return z}}return"unknown"}function c(J){let Y=J.trimStart(),X=5;while(X<Y.length&&Y.charCodeAt(X)<=32)X++;let $=X;if(X<Y.length&&P(Y.charCodeAt(X))){while(X<Y.length&&P(Y.charCodeAt(X)))X++;return`typeof ${Y.slice($,X)}`}return"{ new (...args: any[]): any }"}function f(J,Y,X=0){if(J.startsWith("Promise.resolve(")){let z=J.indexOf(")",16);if(z!==-1){let B=J.slice(16,z).trim();if(B)return`Promise<${V(B,Y,!1,X+1)}>`}return"Promise<unknown>"}if(J.startsWith("Promise.reject("))return"Promise<never>";if(J.startsWith("Promise.all(")){let $=J.indexOf("[",12),z=J.lastIndexOf("]");if($!==-1&&z>$){let B=J.slice($+1,z).trim(),Z=w(B),H=[];for(let Q=0;Q<Z.length;Q++){let L=Z[Q].trim();if(L.startsWith("Promise.resolve(")){let O=f(L,Y,X+1),G=O.indexOf("<"),W=O.lastIndexOf(">");H.push(G!==-1&&W>G?O.slice(G+1,W):"unknown")}else H.push(V(L,Y,!1,X+1))}return`Promise<[${H.join(", ")}]>`}return"Promise<unknown[]>"}return"Promise<unknown>"}function I(J,Y,X=0){let $=J.slice(1,-1).trim();if(!$)return"never[]";if(X>=20)return"unknown[]";let z=w($),B=!1;for(let W=0;W<z.length;W++){let K=z[W],F=K.length;while(F>0&&K.charCodeAt(F-1)<=32)F--;if(F>=8&&K.slice(F-8,F)==="as const"){B=!0;break}}if(B){let W=[];for(let K=0;K<z.length;K++){let F=z[K].trim();if(F.endsWith("as const")){let q=F.slice(0,-8).trim();if(q.startsWith("[")&&q.endsWith("]")){let N=q.slice(1,-1).trim(),U=w(N),R=[];for(let b=0;b<U.length;b++)R.push(V(U[b].trim(),!0,!1,X+1));W.push(`readonly [${R.join(", ")}]`)}else W.push(V(q,!0,!1,X+1))}else if(F.startsWith("[")&&F.endsWith("]"))W.push(I(F,!0,X+1));else W.push(V(F,!0,!1,X+1))}return`readonly [
|
|
3
|
+
${W.join(` |
|
|
4
|
+
`)}
|
|
5
|
+
]`}let Z=E&&!Y,H=[],Q=[];for(let W of z){let K=W.trim(),F=M;if(M=null,K.startsWith("[")&&K.endsWith("]"))H.push(I(K,Y,X+1));else H.push(l(K,Y,X+1));if(Z)Q.push(M);M=F}if(Z)if(g(J))M=_(J);else{let W=[];for(let K=0;K<z.length;K++){let F=z[K].trim();if(F.endsWith("as const"))continue;if(x(F)||F==="null"||F==="undefined")W.push(F);else if(F.startsWith("[")&&g(F))W.push(_(F));else if(F.startsWith("{")){if(Q[K])W.push(Q[K])}else{let q=V(F,!1,!1,0);if(q!=="unknown")W.push(q)}}if(W.length>0)M=`[${W.join(", ")}]`}if(Y)return`readonly [${H.join(", ")}]`;let L=new Set,O=[],G=!0;for(let W of H){if(!L.has(W))L.add(W),O.push(W);if(G){if(!(S(W)||W==="true"||W==="false"||W.charCodeAt(0)===34&&W.charCodeAt(W.length-1)===34||W.charCodeAt(0)===39&&W.charCodeAt(W.length-1)===39))G=!1}}if(G&&H.length<=10)return`readonly [${H.join(", ")}]`;if(O.length===1)return`${O[0]}[]`;return`(${O.join(" | ")})[]`}function w(J){let Y=[],X=0,$=0,z=!1,B=0;for(let H=0;H<J.length;H++){let Q=J.charCodeAt(H);if(!z&&(Q===34||Q===39||Q===96))z=!0,B=Q;else if(z&&Q===B&&(H===0||J.charCodeAt(H-1)!==92))z=!1;if(!z){if(Q===91||Q===123||Q===40)$++;else if(Q===93||Q===125||Q===41)$--;else if(Q===44&&$===0){let L=J.substring(X,H).trim();if(L)Y.push(L);X=H+1;continue}}}let Z=J.substring(X).trim();if(Z)Y.push(Z);return Y}function x(J){if(S(J))return!0;if(J==="true"||J==="false")return!0;if(J.startsWith('"')&&J.endsWith('"')||J.startsWith("'")&&J.endsWith("'"))return!0;return!1}function m(J){return J==="number"||J==="string"||J==="boolean"}function g(J){let Y=!1,X=0,$=J.length;for(let z=0;z<$;z++){let B=J.charCodeAt(z);if(Y){if(B===92){z++;continue}if(B===X)Y=!1;continue}if(B===34||B===39||B===96){Y=!0,X=B;continue}if(B===61&&z+1<$&&J.charCodeAt(z+1)===62)return!1;if(B>=97&&B<=122){let Z=z;while(z<$&&(J.charCodeAt(z)>=97&&J.charCodeAt(z)<=122||J.charCodeAt(z)>=65&&J.charCodeAt(z)<=90||J.charCodeAt(z)>=48&&J.charCodeAt(z)<=57||J.charCodeAt(z)===95||J.charCodeAt(z)===36))z++;let H=J.slice(Z,z);if(H==="new"||H==="async"||H==="await"||H==="function"||H==="yield"||H==="console"||H==="process")return!1;let Q=z;while(Q<$&&J.charCodeAt(Q)<=32)Q++;if(Q<$&&J.charCodeAt(Q)===40)return!1;z--}}return!0}function s(J,Y,X=0){let $=J.slice(1,-1).trim();if(!$)return"{}";if(X>=20)return"Record<string, unknown>";let z=a($),B=[],Z=E&&!Y,H=[];for(let[Q,L]of z){let O=M;M=null;let G,W=L.trim();if(e(W))G=zz(Q,W);else if(G=V(L,Y,!1,X+1),G.includes("=>")||G.includes("function")||G.includes("async"))G=i(G);let K=M;M=O;let F=L.trim(),q=r(Q);if(q){let N=t(q.kind,q.name,G);if(N){B.push(N);continue}}if(!Y&&m(G)&&x(F))B.push(`/** @defaultValue ${F} */
|
|
6
|
+
${Q}: ${G}`);else B.push(`${Q}: ${G}`);if(Z){let N=h(Q);if(F.endsWith("as const"));else if(x(F))H.push(`${N}: ${F}`);else if(F.startsWith("[")&&g(F))H.push(`${N}: ${_(F)}`);else if(F.startsWith("{")){if(K)H.push(`${N}: ${K}`)}else if(!F.startsWith("[")&&(F.includes("=>")||F.startsWith("function")||F.startsWith("async"))){let U=y(F,!1,0,!0);H.push(`${N}: ${U}`)}}}if(Z&&H.length>0){let Q=X>0?(X-1)/2:0,L=`{ ${H.join(", ")} }`;if(L.length<=80)M=L;else{let O=" ".repeat((Q+1)*2),G=" ".repeat(Q*2);M=`{
|
|
7
|
+
${O}${H.join(`,
|
|
8
|
+
${O}`)}
|
|
9
|
+
${G}}`}}return`{
|
|
10
|
+
${B.join(`;
|
|
11
|
+
`)}
|
|
12
|
+
}`}function i(J){let X=J.split(`
|
|
13
|
+
`).map((O)=>C(O)).join(`
|
|
14
|
+
`),$=X.indexOf("async");if($!==-1){let O=$>0?X.charCodeAt($-1):32,G=$+5<X.length?X.charCodeAt($+5):32;if(!P(O)&&!P(G))X=(X.slice(0,$)+X.slice($+5)).trim()}let z=X.indexOf("(");if(z!==-1){let O=j(X,z,"(",")");if(O!==-1){let G=X.slice(z,O+1),W=k(G);X=X.slice(0,z)+W+X.slice(O+1)}}let B=X.length,Z="",H=[],Q=!1,L=!1;for(let O=0;O<B;O++){let G=X.charCodeAt(O);if(G===123||G===40)H.push(G);else if(G===125||G===41)H.pop();if(G<=32){if(Q=!0,G===10||G===13)L=!0;continue}if(Q&&Z.length>0){let K=(H.length>0?H[H.length-1]:0)===123;if(L&&K){let F=Z.charCodeAt(Z.length-1),q=F===59||F===44||F===123||G===125,N=Z.length>=2&&Z.charCodeAt(Z.length-1)===47&&Z.charCodeAt(Z.length-2)===42;if(!q&&!N)Z+="; ";else Z+=" "}else Z+=" "}Q=!1,L=!1,Z+=X[O]}return Z.trim()}function P(J){return J>=97&&J<=122||J>=65&&J<=90||J>=48&&J<=57||J===95||J===36}function k(J){let Y=J.trim(),X,$=!1;if(Y.startsWith("(")&&Y.endsWith(")"))X=Y.slice(1,-1),$=!0;else X=Y;let z=X.trim();if(!z)return $?"()":"";let B=!1;{let F=0;for(let q=0;q<z.length;q++){let N=z.charCodeAt(q);if(N===40||N===60||N===91||N===123)F++;else if(N===41||N===62||N===93||N===125)F--;else if(F===0&&N===61){let U=q>0?z.charCodeAt(q-1):0,R=q+1<z.length?z.charCodeAt(q+1):0;if(U!==61&&U!==33&&U!==60&&U!==62&&R!==61&&R!==62){B=!0;break}}}}if(!B)return Y;let Z=[],H=[],Q=0,L=0,O=!1,G=0;for(let F=0;F<=z.length;F++){if(F===z.length){Z.push(z.slice(Q));break}let q=z.charCodeAt(F);if(O){if(q===92){F++;continue}if(q===G)O=!1;continue}if(q===39||q===34||q===96){O=!0,G=q;continue}if(q===40||q===60||q===91||q===123)L++;else if(q===41||q===62||q===93||q===125)L--;else if(q===44&&L===0){Z.push(z.slice(Q,F));let N=",",U=F+1;while(U<z.length&&z.charCodeAt(U)<=32)N+=z[U],U++;H.push(N),Q=U}}let W=[];for(let F of Z){let q=F.trim();if(!q){W.push(F);continue}if(q.startsWith("//"))continue;let N=C(q),U=F.slice(0,F.length-F.trimStart().length);W.push(U+n(N))}let K=W[0]||"";for(let F=1;F<W.length;F++)K+=(H[F-1]||", ")+W[F];return $?`(${K})`:K}function C(J){let Y=!1,X=0;for(let $=0;$<J.length-1;$++){let z=J.charCodeAt($);if(Y){if(z===92){$++;continue}if(z===X)Y=!1;continue}if(z===39||z===34||z===96){Y=!0,X=z;continue}if(z===47&&J.charCodeAt($+1)===47)return J.slice(0,$).trimEnd()}return J}function n(J){if(J.startsWith("..."))return J;let Y=-1,X=-1,$=0,z=!1,B=0;for(let H=0;H<J.length;H++){let Q=J.charCodeAt(H);if(z){if(Q===92){H++;continue}if(Q===B)z=!1;continue}if(Q===39||Q===34||Q===96){z=!0,B=Q;continue}if(Q===40||Q===60||Q===91||Q===123)$++;else if(Q===41||Q===62||Q===93||Q===125)$--;else if($===0){if(Q===58&&Y===-1)Y=H;else if(Q===61&&X===-1&&(H===0||J.charCodeAt(H-1)!==61)&&(H+1>=J.length||J.charCodeAt(H+1)!==61&&J.charCodeAt(H+1)!==62))X=H}}let Z=X!==-1;if(Y!==-1&&(X===-1||Y<X)){let H=J.slice(0,Y).trim(),Q=X!==-1?J.slice(Y+1,X).trim():J.slice(Y+1).trim(),L=Z&&!H.endsWith("?")?"?":"";return`${H}${L}: ${Q}`}else if(X!==-1){let H=J.slice(0,X).trim(),Q=!H.endsWith("?")?"?":"",L=J.slice(X+1).trim(),O="unknown";if(L==="true"||L==="false")O="boolean";else if(/^-?\d+(\.\d+)?$/.test(L))O="number";else if(L.startsWith("'")&&L.endsWith("'")||L.startsWith('"')&&L.endsWith('"'))O="string";else if(L.startsWith("["))O="unknown[]";else if(L.startsWith("{"))O="Record<string, unknown>";return`${H}${Q}: ${O}`}return J}function a(J){let Y=[],X="",$="",z=0,B=!1,Z="",H=!0,Q=!1,L=0;for(let O=0;O<J.length;O++){let G=J.charCodeAt(O),W=O>0?J.charCodeAt(O-1):0,K=O<J.length-1?J.charCodeAt(O+1):0;if(!B&&!Q&&G===47&&K===47){O+=2;while(O<J.length&&J.charCodeAt(O)!==10)O++;continue}if(!B&&!Q&&G===47&&K===42){Q=!0,L=1,X+="/*",O++;continue}else if(Q&&G===42&&K===47){if(L--,X+="*/",O++,L===0)Q=!1;continue}else if(Q&&G===47&&K===42){L++,X+="/*",O++;continue}let F=J[O];if(!B&&(G===34||G===39||G===96))B=!0,Z=F,X+=F;else if(B&&F===Z&&W!==92)B=!1,X+=F;else if(!B&&!Q)if(G===40&&z===0&&H){$=X.trim();let q="";if($.startsWith("async "))$=$.slice(6).trim(),q="async ";if($.startsWith("*"))$=$.slice(1).trim(),q+="*";X=q+F,H=!1,z=1}else if(G===123||G===91||G===40)z++,X+=F;else if(G===125||G===93||G===41)z--,X+=F;else if(G===58&&z===0&&H)$=X.trim(),X="",H=!1;else if(G===44&&z===0){if($&&X.trim()){let q=X.trim();Y.push([$,q])}X="",$="",H=!0}else X+=F;else X+=F}if($&&X.trim()){let O=X.trim();Y.push([$,O])}return Y}function r(J){let Y=J.trim();if(Y.startsWith("get ")&&Y.length>4){let X=Y.slice(4).trim();if(X)return{kind:"get",name:X}}if(Y.startsWith("set ")&&Y.length>4){let X=Y.slice(4).trim();if(X)return{kind:"set",name:X}}return null}function t(J,Y,X){let $=X.trim();if($.charCodeAt(0)!==40)return null;let z=j($,0,"(",")");if(z===-1)return null;let B=$.slice(1,z).trim(),Z=$.slice(z+1).trimStart();if(!Z.startsWith("=>"))return null;let H=Z.slice(2).trim();if(J==="get")return`get ${Y}(): ${H||"unknown"}`;return`set ${Y}(${B})`}function e(J){let Y=J;if(Y.startsWith("async ")||Y.startsWith("async\t"))Y=Y.slice(5).trimStart();if(Y.startsWith("*"))Y=Y.slice(1).trimStart();if(!Y.startsWith("("))return!1;let X=0;for(let $=0;$<Y.length;$++){let z=Y.charCodeAt($);if(z===40)X++;else if(z===41){if(X--,X===0){let B=Y.slice($+1).trimStart();if(B.startsWith("{"))return!0;if(B.startsWith(":")){let Z=0;for(let H=0;H<B.length;H++){let Q=B.charCodeAt(H);if(Q===40||Q===91)Z++;else if(Q===41||Q===93)Z--;else if(Q===60)Z++;else if(Q===62){if(Z>0)Z--}else if(Z===0&&Q===61&&H+1<B.length&&B.charCodeAt(H+1)===62)return!1;else if(Z===0&&Q===123)return!0}}return!1}}}return!1}function zz(J,Y){let X=Y.trimStart(),$=!1,z=!1;if(X.startsWith("async ")||X.startsWith("async\t"))$=!0,X=X.slice(5).trimStart();if(X.startsWith("*"))z=!0,X=X.slice(1).trimStart();let B="";if(X.charCodeAt(0)===60){let W=0,K=-1;for(let F=0;F<X.length;F++)if(X.charCodeAt(F)===60)W++;else if(X.charCodeAt(F)===62){if(W--,W===0){K=F;break}}if(K!==-1)B=X.slice(0,K+1),X=X.slice(K+1).trimStart()}let Z=X.indexOf("("),H=j(X,Z,"(",")");if(Z===-1||H===-1)return"() => unknown";let Q=X.slice(Z,H+1),L="unknown",O=X.slice(H+1).trimStart();if(O.charCodeAt(0)===58){let W=O.slice(1),K=0,F=-1,q=!1;for(let N=0;N<W.length;N++){let U=W.charCodeAt(N);if(U===40||U===91)K++;else if(U===41||U===93)K--;else if(U===123&&K===0){F=N;break}else if(U===61&&N+1<W.length&&W.charCodeAt(N+1)===62&&K===0){F=N,q=!0;break}}if(F!==-1)L=W.slice(0,F).trim();else L=W.trim()}if(L==="unknown"){if($&&z)L="AsyncGenerator<unknown, void, unknown>";else if(z)L="Generator<unknown, void, unknown>";else if($)L="Promise<void>"}else if($&&!L.startsWith("Promise<")&&!L.startsWith("AsyncGenerator<"))L=`Promise<${L}>`;let G=k(Q);return`${B}${G} => ${L}`}function j(J,Y,X,$){let z=0;for(let B=Y;B<J.length;B++)if(J[B]===X)z++;else if(J[B]===$){if(z--,z===0)return B}return-1}function Jz(J){let Y=0,X=0,$=!1,z="";for(let B=0;B<J.length-1;B++){let Z=J[B],H=J[B+1],Q=B>0?J[B-1]:"";if(!$&&(Z==='"'||Z==="'"||Z==="`"))$=!0,z=Z;else if($&&Z===z&&Q!=="\\")$=!1;if(!$){if(Z==="(")Y++;else if(Z===")")Y--;else if(Z==="[")X++;else if(Z==="]")X--;if(Z==="="&&H===">"&&Y===0&&X===0)return B}}return-1}function y(J,Y=!1,X=0,$=!0){let z=J.trim();if(z.length>200&&D(z,"=>")>2&&D(z,"<")>5&&!z.startsWith("function"))return Y?"((...args: any[]) => any)":"(...args: any[]) => any";if(z.startsWith("async ")&&z.includes("=>")){let Z=z.slice(5).trim(),H=Z.indexOf("=>"),Q=Z.substring(0,H).trim(),L=Z.substring(H+2).trim();if(Q=k(Q),Q==="()"||Q==="")Q="()";else if(!Q.startsWith("("))Q=`(${Q})`;let O="unknown";if(L.startsWith("{"))O="unknown";else O=V(L,$,!1,X+1);let G=`${Q} => Promise<${O}>`;return Y?`(${G})`:G}if(z.includes("=>")){let Z="",H=z;if(z.startsWith("<")){let q=j(z,0,"<",">");if(q!==-1)Z=z.substring(0,q+1),H=z.substring(q+1).trim()}let Q=Jz(H);if(Q===-1)return Y?"(() => unknown)":"() => unknown";let L=H.substring(0,Q).trim(),O=H.substring(Q+2).trim(),G="",W=L.lastIndexOf("):");if(W!==-1){let q=L.substring(W+2).trim();if(q&&!q.includes("=>")&&!q.includes("="))G=q,L=L.substring(0,W+1)}if(L=k(L),L==="()"||L==="")L="()";else if(!L.startsWith("("))L=`(${L})`;let K="unknown";if(G)K=G;else if(O.startsWith("{"))K="unknown";else if(O.includes("=>")){let q=O.trimStart(),N=q.indexOf("("),U=N!==-1?j(q,N,"(",")"):-1,R=U!==-1?q.indexOf("=>",U):-1;if(N===0&&U!==-1&&R!==-1){let b=q.substring(N+1,U).trim(),A=k(b);if(Z.includes("T")&&A.includes("T"))K=`(${A}) => T`;else K=`(${A}) => any`}else K="any"}else if(Y)K="unknown";else K=V(O,$,!1,X+1);let F=`${Z}${L} => ${K}`;return Y?`(${F})`:F}if(z.startsWith("function")){let Z=8,H=z.length;while(Z<H&&z.charCodeAt(Z)<=32)Z++;let Q=!1;if(Z<H&&z.charCodeAt(Z)===42){Q=!0,Z++;while(Z<H&&z.charCodeAt(Z)<=32)Z++}let L="";if(Z<H&&z.charCodeAt(Z)===60){let W=Z,K=1;Z++;while(Z<H&&K>0){let F=z.charCodeAt(Z);if(F===60)K++;else if(F===62)K--;Z++}L=z.substring(W,Z);while(Z<H&&z.charCodeAt(Z)<=32)Z++}let O=z.indexOf("(",Z);if(O!==-1){let W=1,K=O+1;while(K<H&&W>0){let U=z.charCodeAt(K);if(U===40)W++;else if(U===41)W--;K++}let F=z.substring(O+1,K-1).trim(),q=F?`(${F})`:"()";if(Q){let U=z.substring(K).trim(),R=U.indexOf("Generator<");if(R!==-1){let A=R+10,T=U.indexOf(">",A);if(T!==-1){let u=U.substring(A,T),v=`${L}${q} => Generator<${u}>`;return Y?`(${v})`:v}}let b=`${L}${q} => Generator<any, any, any>`;return Y?`(${b})`:b}let N=`${L}${q} => unknown`;return Y?`(${N})`:N}let G="(...args: any[]) => unknown";return Y?`(${G})`:G}if(z.includes("=>")&&z.includes("(")&&z.includes(")")){if(z.length>100||D(z,"=>")>2){let Z="";if(z.charCodeAt(0)===60){let G=j(z,0,"<",">");if(G!==-1)Z=z.substring(0,G+1)}let H=z.indexOf("("),Q=H!==-1?j(z,H,"(",")"):-1,L=H!==-1&&Q!==-1?z.substring(H,Q+1):"(...args: any[])";L=k(L);let O=`${Z}${L} => any`;return Y?`(${O})`:O}return Y?`(${z})`:z}let B="() => unknown";return Y?`(${B})`:B}function Hz(J){let Y=J.trim();if(Y==="any"||Y==="object"||Y==="unknown")return!0;if(Y.startsWith("Record<")&&Y.endsWith(">"))return!0;if(Y.startsWith("Array<")&&Y.endsWith(">"))return!0;if(/^\{\s*\[[^\]]*\]:\s*(any|string|number|unknown)\s*\}$/.test(Y))return!0;return!1}function Fz(J){let Y=J.lastIndexOf(" satisfies ");if(Y===-1)return null;let X=J.slice(Y+11).trim();if(X.endsWith(";"))X=X.slice(0,-1).trim();return X||null}var Xz=/^\/\/\/\s*<reference\s+(?:path|types|lib|no-default-lib)\s*=\s*["'][^"']+["']\s*\/>/,Yz=/^\/\/\/\s*<amd-module\s+name\s*=\s*["'][^"']+["']\s*\/>/,Zz=/^\/\/\/\s*<amd-dependency\s+path\s*=\s*["'][^"']+["']/;function Lz(J){let Y=[],X=0;for(let $=0;$<=J.length;$++)if($===J.length||J[$]===`
|
|
15
|
+
`){let z=X,B=$;while(z<B&&(J[z]===" "||J[z]==="\t"||J[z]==="\r"))z++;while(B>z&&(J[B-1]===" "||J[B-1]==="\t"||J[B-1]==="\r"))B--;let Z=J.slice(z,B);if(X=$+1,Z.startsWith("///")){if(Z.indexOf("<")===-1)continue;if(Xz.test(Z)||Yz.test(Z)||Zz.test(Z))Y.push(Z)}else if(Z===""||Z.startsWith("//"))continue;else break}return Y}
|
|
16
|
+
export{$z as Dc,Qz as Ec,V as Fc,l as Gc,I as Hc,w as Ic,s as Jc,j as Kc,y as Lc,Hz as Mc,Fz as Nc,Lz as Oc};
|