@stacksjs/dtsx 0.2.0

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.
@@ -0,0 +1,3 @@
1
+ import type { DtsGenerationConfig } from './types'
2
+
3
+ export declare const config: DtsGenerationConfig
@@ -0,0 +1,59 @@
1
+ export declare function extractTypeFromSource(filePath: string): Promise<string>
2
+
3
+ exportStatement = exportLines[i]
4
+ i++
5
+ while (i < exportLines.length && !exportLines[i].trim().startsWith('export') && !exportLines[i].trim().startsWith('/**')) {
6
+
7
+ exportStatement += `\n${exportLines[i]}`
8
+ i++
9
+ }
10
+ }
11
+
12
+ if (exportStatement) {
13
+ const formattedComment = comment ? formatComment(comment.trim()) : ''
14
+ let formattedExport = exportStatement.trim()
15
+
16
+ if (formattedExport.startsWith('export function') || formattedExport.startsWith('export async function')) {
17
+ formattedExport = formattedExport.replace(/^export\s+(async\s+)?function/, 'export declare function')
18
+ const functionSignature = formattedExport.match(/^.*?\)/)
19
+ if (functionSignature) {
20
+ let params = functionSignature[0].slice(functionSignature[0].indexOf('(') + 1, -1)
21
+ params = params.replace(/\s*=[^,)]+/g, '') // Remove default values
22
+ const returnType = formattedExport.match(/\):\s*([^{]+)/)
23
+ formattedExport = `export declare function ${formattedExport.split('function')[1].split('(')[0].trim()}(${params})${returnType ? `: ${returnType[1].trim()}` : ''};`
24
+ }
25
+ }
26
+ else if (formattedExport.startsWith('export const') || formattedExport.startsWith('export let') || formattedExport.startsWith('export var')) {
27
+ formattedExport = formattedExport.replace(/^export\s+(const|let|var)/, 'export declare $1')
28
+ formattedExport = `${formattedExport.split('=')[0].trim()};`
29
+ }
30
+
31
+ declarations += `${formattedComment}\n${formattedExport}\n\n`
32
+
33
+ // Add types used in the export to usedTypes
34
+ const typeRegex = /\b([A-Z]\w+)(?:<[^>]*>)?/g
35
+ const types = Array.from(formattedExport.matchAll(typeRegex))
36
+ types.forEach(([, type]) => usedTypes.add(type))
37
+ }
38
+
39
+ if (!exportStatement && !comment) {
40
+ i++
41
+ }
42
+ }
43
+
44
+ // Generate import statements for used types
45
+ let importDeclarations = ''
46
+ importMap.forEach((types, path) => {
47
+ const usedTypesFromPath = [...types].filter(type => usedTypes.has(type))
48
+ if (usedTypesFromPath.length > 0) {
49
+ importDeclarations += `import type { ${usedTypesFromPath.join(', ')} } from '${path}'\n`
50
+ }
51
+ })
52
+
53
+ if (importDeclarations) {
54
+ declarations = `${importDeclarations}\n${declarations}`
55
+ }
56
+
57
+ // Apply final formatting
58
+ return formatDeclarations(declarations)
59
+ }
@@ -0,0 +1,5 @@
1
+ import type { DtsGenerationConfig, DtsGenerationOption } from './types'
2
+
3
+ export declare function generateDeclarationsFromFiles(options?: DtsGenerationConfig): Promise<void>
4
+
5
+ export declare function generate(options?: DtsGenerationOption): Promise<void>
@@ -0,0 +1,15 @@
1
+ export { config } from './config'
2
+ export * from './extract'
3
+ export * from './generate'
4
+ export * from './types'
5
+ export * from './utils'
6
+
7
+ export { config } from './config'
8
+
9
+ export * from './extract'
10
+
11
+ export * from './generate'
12
+
13
+ export * from './types'
14
+
15
+ export * from './utils'