Skip to content

Commit 53da886

Browse files
committed
chore: wip
1 parent 9d33756 commit 53da886

File tree

8 files changed

+458
-352
lines changed

8 files changed

+458
-352
lines changed

debug-extract.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { extractDeclarations } from './src/extractor'
2+
import { readFile } from 'node:fs/promises'
3+
import { join } from 'node:path'
4+
5+
const filePath = join(__dirname, 'test/fixtures/input/example/0002.ts')
6+
const sourceCode = await readFile(filePath, 'utf-8')
7+
8+
console.log('Source code:')
9+
console.log(sourceCode)
10+
console.log('\n' + '='.repeat(50) + '\n')
11+
12+
const declarations = extractDeclarations(sourceCode, filePath)
13+
14+
console.log('Extracted declarations:')
15+
declarations.forEach((decl, index) => {
16+
console.log(`${index + 1}. Kind: ${decl.kind}`)
17+
console.log(` Name: ${decl.name}`)
18+
console.log(` Text: ${decl.text}`)
19+
console.log(` IsExported: ${decl.isExported}`)
20+
console.log(` IsTypeOnly: ${decl.isTypeOnly}`)
21+
console.log(' ---')
22+
})

src/generator.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,26 @@ async function findFiles(config: DtsGenerationConfig): Promise<string[]> {
6060
const rootPath = resolve(config.cwd, config.root)
6161

6262
for (const pattern of config.entrypoints) {
63-
const glob = new Glob(pattern)
64-
65-
// Scan for matching files
66-
for await (const file of glob.scan({
67-
cwd: rootPath,
68-
absolute: true,
69-
onlyFiles: true
70-
})) {
71-
// Skip .d.ts files and node_modules
72-
if (!file.endsWith('.d.ts') && !file.includes('node_modules')) {
73-
files.push(file)
63+
// Check if pattern is an absolute path to a specific file
64+
if (pattern.startsWith('/') && pattern.endsWith('.ts')) {
65+
// It's an absolute file path
66+
if (!pattern.endsWith('.d.ts') && !pattern.includes('node_modules')) {
67+
files.push(pattern)
68+
}
69+
} else {
70+
// It's a glob pattern
71+
const glob = new Glob(pattern)
72+
73+
// Scan for matching files
74+
for await (const file of glob.scan({
75+
cwd: rootPath,
76+
absolute: true,
77+
onlyFiles: true
78+
})) {
79+
// Skip .d.ts files and node_modules
80+
if (!file.endsWith('.d.ts') && !file.includes('node_modules')) {
81+
files.push(file)
82+
}
7483
}
7584
}
7685
}

0 commit comments

Comments
 (0)