Skip to content

Commit 98f08ef

Browse files
committed
chore: wip
chore: wip
1 parent 08f015a commit 98f08ef

File tree

3 files changed

+3
-53
lines changed

3 files changed

+3
-53
lines changed

src/extract.ts

-50
Original file line numberDiff line numberDiff line change
@@ -89,53 +89,3 @@ export async function extractTypeFromSource(filePath: string): Promise<string> {
8989
// Apply final formatting
9090
return formatDeclarations(declarations, false)
9191
}
92-
93-
export async function extractConfigTypeFromSource(filePath: string): Promise<string> {
94-
const fileContent = await readFile(filePath, 'utf-8')
95-
let declarations = ''
96-
97-
try {
98-
// Handle type imports
99-
const importRegex = /import\s+type\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g
100-
let importMatch
101-
while ((importMatch = importRegex.exec(fileContent)) !== null) {
102-
const [, types, from] = importMatch
103-
const typeList = types.split(',').map(t => t.trim())
104-
declarations += `import type { ${typeList.join(', ')} } from '${from}'\n`
105-
}
106-
107-
if (declarations) {
108-
declarations += '\n'
109-
}
110-
111-
// Handle exports
112-
const exportRegex = /export\s+const\s+(\w+)\s*:\s*([^=]+)\s*=/g
113-
let exportMatch
114-
while ((exportMatch = exportRegex.exec(fileContent)) !== null) {
115-
const [, name, type] = exportMatch
116-
declarations += `export declare const ${name}: ${type.trim()}\n`
117-
}
118-
119-
// console.log(`Extracted config declarations for ${filePath}:`, declarations)
120-
return declarations.trim() + '\n'
121-
} catch (error) {
122-
console.error(`Error extracting config declarations from ${filePath}:`, error)
123-
return ''
124-
}
125-
}
126-
127-
export async function extractIndexTypeFromSource(filePath: string): Promise<string> {
128-
const fileContent = await readFile(filePath, 'utf-8')
129-
let declarations = ''
130-
131-
// Handle re-exports
132-
const reExportRegex = /export\s*(?:\*|\{[^}]*\})\s*from\s*['"]([^'"]+)['"]/g
133-
let match
134-
while ((match = reExportRegex.exec(fileContent)) !== null) {
135-
declarations += `${match[0]}\n`
136-
}
137-
138-
// console.log(`Extracted index declarations for ${filePath}:`, declarations)
139-
140-
return declarations.trim() + '\n'
141-
}

src/generate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { DtsGenerationConfig, DtsGenerationOption } from './types'
22
import { rm, mkdir } from 'node:fs/promises'
33
import { join, relative, dirname } from 'node:path'
44
import { config } from './config'
5-
import { writeToFile, getAllTypeScriptFiles, checkIsolatedDeclarations, formatDeclarations } from './utils'
6-
import { extractTypeFromSource, extractConfigTypeFromSource, extractIndexTypeFromSource } from './extract'
5+
import { writeToFile, getAllTypeScriptFiles, checkIsolatedDeclarations } from './utils'
6+
import { extractTypeFromSource } from './extract'
77

88
export async function generateDeclarationsFromFiles(options: DtsGenerationConfig = config): Promise<void> {
99
try {

src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function formatDeclarations(declarations: string, isConfigFile: boolean):
4343
.replace(/export (interface|type) ([^\{]+)\s*\{\s*\n/g, 'export $1 $2 {\n')
4444
.replace(/\n\s*\}/g, '\n}')
4545
.replace(/\/\*\*\n([^*]*)(\n \*\/)/g, (match, content) => {
46-
const formattedContent = content.split('\n').map(line => ` *${line.trim() ? ' ' + line.trim() : ''}`).join('\n')
46+
const formattedContent = content.split('\n').map((line: string) => ` *${line.trim() ? ' ' + line.trim() : ''}`).join('\n')
4747
return `/**\n${formattedContent}\n */`
4848
})
4949
.trim() + '\n'

0 commit comments

Comments
 (0)