Skip to content

Commit 03d4575

Browse files
committed
chore: wip
1 parent 1600c87 commit 03d4575

13 files changed

+429
-304
lines changed

.cursor/mcp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
]
99
}
1010
}
11-
}
11+
}

README-dtsx-implementation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ export default {
125125
4. AST-based parsing for more accurate extraction
126126
5. Better handling of module augmentations
127127

128-
The implementation provides a solid foundation for generating narrow, optimized TypeScript declaration files with good performance characteristics.
128+
The implementation provides a solid foundation for generating narrow, optimized TypeScript declaration files with good performance characteristics.

benchmark.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { performance } from 'node:perf_hooks'
21
import { readFile } from 'node:fs/promises'
3-
import { join } from 'node:path'
2+
import { performance } from 'node:perf_hooks'
43
import { extractDeclarations } from './src/extractor'
54

65
async function benchmark() {
@@ -43,8 +42,8 @@ async function benchmark() {
4342
console.log(` ⚡ Avg time: ${avgTime.toFixed(2)}ms`)
4443
console.log(` 📊 Throughput: ${(throughput / 1000).toFixed(1)}k chars/sec`)
4544
console.log()
46-
47-
} catch (error) {
45+
}
46+
catch (error) {
4847
console.error(`❌ Error processing ${filePath}:`, error instanceof Error ? error.message : String(error))
4948
}
5049
}
@@ -67,17 +66,17 @@ function generateLargeTypeScriptFile(lines: number): string {
6766
const content: string[] = []
6867

6968
// Add imports
70-
content.push("import { SomeType } from 'some-module'")
71-
content.push("import type { AnotherType } from 'another-module'")
72-
content.push("")
69+
content.push('import { SomeType } from \'some-module\'')
70+
content.push('import type { AnotherType } from \'another-module\'')
71+
content.push('')
7372

7473
// Add interfaces
7574
for (let i = 0; i < lines * 0.1; i++) {
7675
content.push(`export interface Interface${i} {`)
7776
content.push(` prop${i}: string`)
7877
content.push(` method${i}(): void`)
7978
content.push(`}`)
80-
content.push("")
79+
content.push('')
8180
}
8281

8382
// Add types
@@ -90,7 +89,7 @@ function generateLargeTypeScriptFile(lines: number): string {
9089
content.push(`export function func${i}(param: Type${i % 100}): Interface${i % 100} {`)
9190
content.push(` return {} as Interface${i % 100}`)
9291
content.push(`}`)
93-
content.push("")
92+
content.push('')
9493
}
9594

9695
// Add variables
@@ -104,11 +103,11 @@ function generateLargeTypeScriptFile(lines: number): string {
104103
content.push(` prop${i} = 'value'`)
105104
content.push(` method${i}() {}`)
106105
content.push(`}`)
107-
content.push("")
106+
content.push('')
108107
}
109108

110109
return content.join('\n')
111110
}
112111

113112
// Run benchmark
114-
benchmark().catch(console.error)
113+
benchmark().catch(console.error)

eslint.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const config: ESLintConfig = stacks({
1111
jsonc: true,
1212
yaml: true,
1313
ignores: [
14-
'fixtures/**',
15-
'docs/**',
14+
'**/node_modules',
15+
'**/fixtures',
16+
'**/docs',
1617
],
1718
})
1819

src/cli.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
#!/usr/bin/env bun
22

3-
import { parseArgs } from 'util'
4-
import { generate } from './generator'
53
import type { DtsGenerationOption } from './types'
6-
import { config as defaultConfig } from './config'
74
import { resolve } from 'node:path'
5+
import { parseArgs } from 'node:util'
6+
import { config as defaultConfig } from './config'
7+
import { generate } from './generator'
88

99
// Parse command line arguments
1010
const { values, positionals } = parseArgs({
1111
args: Bun.argv,
1212
options: {
13-
help: {
13+
'help': {
1414
type: 'boolean',
1515
short: 'h',
1616
},
17-
version: {
17+
'version': {
1818
type: 'boolean',
1919
short: 'v',
2020
},
21-
root: {
21+
'root': {
2222
type: 'string',
2323
short: 'r',
2424
},
25-
outdir: {
25+
'outdir': {
2626
type: 'string',
2727
short: 'o',
2828
},
29-
clean: {
29+
'clean': {
3030
type: 'boolean',
3131
short: 'c',
3232
},
3333
'keep-comments': {
3434
type: 'boolean',
3535
},
36-
tsconfig: {
36+
'tsconfig': {
3737
type: 'string',
3838
},
39-
verbose: {
39+
'verbose': {
4040
type: 'boolean',
4141
},
4242
'output-structure': {
@@ -94,22 +94,24 @@ const options: DtsGenerationOption = {
9494
// Handle entrypoints
9595
if (positionals.length > 2) { // First two are bun and script path
9696
const entrypoints = positionals.slice(2)
97-
options.entrypoints = entrypoints.map(e => {
97+
options.entrypoints = entrypoints.map((e) => {
9898
// If it's a file path, convert to glob pattern relative to root
9999
if (e.endsWith('.ts')) {
100100
const relativePath = resolve(process.cwd(), e)
101101
return relativePath
102102
}
103103
return e
104104
})
105-
} else {
105+
}
106+
else {
106107
options.entrypoints = defaultConfig.entrypoints
107108
}
108109

109110
// Run generation
110111
try {
111112
await generate(options)
112-
} catch (error) {
113+
}
114+
catch (error) {
113115
console.error('Error generating .d.ts files:', error)
114116
process.exit(1)
115-
}
117+
}

0 commit comments

Comments
 (0)