Skip to content

Commit 1346f5b

Browse files
committed
Merge branch 'dev'
2 parents 80990a4 + 9541ece commit 1346f5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+58012
-4256
lines changed

.cursor/mcp.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"mcpServers": {
3+
"context7": {
4+
"command": "bunx",
5+
"args": [
6+
"-y",
7+
"@upstash/context7-mcp"
8+
]
9+
}
10+
}
11+
}

.github/art/cover.jpg

12.4 KB
Loading

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ docs/.vitepress/cache
1414
storage
1515
fixtures/generated
1616
bin/dtsx*
17+
/test/temp-output
18+
test/debug
19+
/test/fixtures/generated

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
bun install -d @stacksjs/dtsx
2424
```
2525

26-
<[email protected]>, please allow us to use the `dtsx` package name 🙏_
26+
_@npmjs.com, please allow us to use the `dtsx` package name 🙏_
2727

2828
<!-- _Alternatively, you can install:_
2929

benchmark.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* eslint-disable no-console */
2+
import { readFile } from 'node:fs/promises'
3+
import { performance } from 'node:perf_hooks'
4+
import { extractDeclarations } from './src/extractor'
5+
6+
async function benchmark() {
7+
console.log('🚀 DTS Extractor Performance Benchmark\n')
8+
9+
// Test files of different complexities
10+
const testFiles = [
11+
'test/fixtures/input/example/0001.ts', // Simple
12+
'test/fixtures/input/example/0002.ts', // Medium
13+
'test/fixtures/input/example/0003.ts', // Complex
14+
'test/fixtures/input/example/0005.ts', // Very complex
15+
]
16+
17+
for (const filePath of testFiles) {
18+
try {
19+
const sourceCode = await readFile(filePath, 'utf-8')
20+
const fileSize = sourceCode.length
21+
const lineCount = sourceCode.split('\n').length
22+
23+
console.log(`📁 ${filePath}`)
24+
console.log(` Size: ${fileSize} chars, ${lineCount} lines`)
25+
26+
// Warm up
27+
for (let i = 0; i < 3; i++) {
28+
extractDeclarations(sourceCode, filePath)
29+
}
30+
31+
// Benchmark
32+
const iterations = 100
33+
const start = performance.now()
34+
35+
for (let i = 0; i < iterations; i++) {
36+
extractDeclarations(sourceCode, filePath)
37+
}
38+
39+
const end = performance.now()
40+
const avgTime = (end - start) / iterations
41+
const throughput = fileSize / avgTime * 1000 // chars per second
42+
43+
console.log(` ⚡ Avg time: ${avgTime.toFixed(2)}ms`)
44+
console.log(` 📊 Throughput: ${(throughput / 1000).toFixed(1)}k chars/sec`)
45+
console.log()
46+
}
47+
catch (error) {
48+
console.error(`❌ Error processing ${filePath}:`, error instanceof Error ? error.message : String(error))
49+
}
50+
}
51+
52+
// Test with a large synthetic file
53+
console.log('🧪 Synthetic Large File Test')
54+
const largeFile = generateLargeTypeScriptFile(10000) // 10k lines
55+
56+
const start = performance.now()
57+
const declarations = extractDeclarations(largeFile, 'synthetic.ts')
58+
const end = performance.now()
59+
60+
console.log(` 📏 Generated ${largeFile.split('\n').length} lines`)
61+
console.log(` 🔍 Found ${declarations.length} declarations`)
62+
console.log(` ⚡ Time: ${(end - start).toFixed(2)}ms`)
63+
console.log(` 📊 Throughput: ${(largeFile.length / (end - start) * 1000 / 1000).toFixed(1)}k chars/sec`)
64+
}
65+
66+
function generateLargeTypeScriptFile(lines: number): string {
67+
const content: string[] = []
68+
69+
// Add imports
70+
content.push('import { SomeType } from \'some-module\'')
71+
content.push('import type { AnotherType } from \'another-module\'')
72+
content.push('')
73+
74+
// Add interfaces
75+
for (let i = 0; i < lines * 0.1; i++) {
76+
content.push(`export interface Interface${i} {`)
77+
content.push(` prop${i}: string`)
78+
content.push(` method${i}(): void`)
79+
content.push(`}`)
80+
content.push('')
81+
}
82+
83+
// Add types
84+
for (let i = 0; i < lines * 0.1; i++) {
85+
content.push(`export type Type${i} = string | number | Interface${i}`)
86+
}
87+
88+
// Add functions
89+
for (let i = 0; i < lines * 0.2; i++) {
90+
content.push(`export function func${i}(param: Type${i % 100}): Interface${i % 100} {`)
91+
content.push(` return {} as Interface${i % 100}`)
92+
content.push(`}`)
93+
content.push('')
94+
}
95+
96+
// Add variables
97+
for (let i = 0; i < lines * 0.1; i++) {
98+
content.push(`export const var${i}: Type${i % 100} = 'value${i}'`)
99+
}
100+
101+
// Add classes
102+
for (let i = 0; i < lines * 0.1; i++) {
103+
content.push(`export class Class${i} implements Interface${i % 100} {`)
104+
content.push(` prop${i} = 'value'`)
105+
content.push(` method${i}() {}`)
106+
content.push(`}`)
107+
content.push('')
108+
}
109+
110+
return content.join('\n')
111+
}
112+
113+
// Run benchmark
114+
benchmark().catch(console.error)

bin/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { DtsGenerationConfig, DtsGenerationOption } from '../src/types'
22
import { resolve } from 'node:path'
33
import process from 'node:process'
4-
import { CAC } from '@stacksjs/cli'
4+
import { CAC } from 'cac'
55
import { version } from '../package.json'
6-
import { generate } from '../src/generate'
6+
import { generate } from '../src/generator'
77

88
const cli = new CAC('dtsx')
99

build.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import fs from 'node:fs/promises'
2-
import { log } from '@stacksjs/cli'
32
import { dts } from 'bun-plugin-dtsx'
43

5-
log.info('Building...')
4+
console.log('Building...')
65

76
await fs.rm('./dist', { recursive: true, force: true })
87

@@ -23,4 +22,4 @@ await fs.rename('./dist/src/index.js', './dist/index.js')
2322
await fs.rm('./dist/src', { recursive: true, force: true })
2423
await fs.rm('./dist/bin', { recursive: true, force: true })
2524

26-
log.success('Built')
25+
console.log('Built!')

0 commit comments

Comments
 (0)