Skip to content

Commit 36e997b

Browse files
committed
chore: wip
chore: wip
1 parent 0294627 commit 36e997b

File tree

5 files changed

+6
-58
lines changed

5 files changed

+6
-58
lines changed

bun.lockb

358 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@stacksjs/development": "^0.67.0",
6767
"@stacksjs/eslint-config": "^3.8.1-beta.2",
6868
"@types/bun": "^1.1.13",
69+
"bun-config": "^0.1.0",
6970
"tinyglobby": "^0.2.10",
7071
"vitepress": "^1.4.5"
7172
},

src/config.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
11
import type { DtsGenerationConfig } from './types'
2-
import { existsSync } from 'node:fs'
3-
import { resolve } from 'node:path'
42
import process from 'node:process'
5-
import { deepMerge } from './utils'
6-
7-
interface Options<T> {
8-
name: string
9-
cwd?: string
10-
defaultConfig: T
11-
}
12-
13-
export async function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: Options<T>): Promise<T> {
14-
const c = cwd ?? process.cwd()
15-
const configPath = resolve(c, `${name}.config`)
16-
17-
if (existsSync(configPath)) {
18-
try {
19-
const importedConfig = await import(configPath)
20-
const loadedConfig = importedConfig.default || importedConfig
21-
return deepMerge(defaultConfig, loadedConfig)
22-
}
23-
catch (error) {
24-
console.error(`Error loading config from ${configPath}:`, error)
25-
}
26-
}
27-
28-
return defaultConfig
29-
}
3+
import { loadConfig } from 'bun-config'
304

315
// Get loaded config
326
// eslint-disable-next-line antfu/no-top-level-await

src/extract.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,13 +1103,13 @@ function inferTypeFromDefaultValue(defaultValue: string): string {
11031103
/**
11041104
* Check if a line is a JSDoc comment
11051105
*/
1106-
export function isJSDocComment(line: string): boolean {
1106+
function isJSDocComment(line: string): boolean {
11071107
const trimmed = line.trim()
11081108
const isJsDoc = trimmed.startsWith('/**') || trimmed.startsWith('*') || trimmed.startsWith('*/')
11091109
return isJsDoc
11101110
}
11111111

1112-
export function isDefaultExport(line: string): boolean {
1112+
function isDefaultExport(line: string): boolean {
11131113
// Handle both inline and multi-line default exports
11141114
return line.trim().startsWith('export default')
11151115
}
@@ -1532,7 +1532,7 @@ function processTypeBlock(cleanDeclaration: string, declarationText: string, sta
15321532
}
15331533

15341534
function processDefaultExportBlock(cleanDeclaration: string, state: ProcessingState): boolean {
1535-
if (!cleanDeclaration.startsWith('export default'))
1535+
if (!isDefaultExport(cleanDeclaration))
15361536
return false
15371537

15381538
const exportedValue = cleanDeclaration.replace(/^export\s+default\s+/, '').replace(/;$/, '')
@@ -1654,7 +1654,7 @@ function processModuleBlock(cleanDeclaration: string, declarationText: string, s
16541654
export function processSpecificDeclaration(declarationWithoutComments: string, fullDeclaration: string, state: ProcessingState): void {
16551655
// debugLog('processing', `Processing declaration: ${declarationWithoutComments.substring(0, 100)}...`)
16561656

1657-
if (declarationWithoutComments.startsWith('export default')) {
1657+
if (isDefaultExport(declarationWithoutComments)) {
16581658
// debugLog('default-export', `Found default export: ${declarationWithoutComments}`)
16591659

16601660
// Store the complete default export statement

src/utils.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,3 @@ export async function checkIsolatedDeclarations(options?: DtsGenerationConfig):
3333
return false
3434
}
3535
}
36-
37-
export function deepMerge<T extends object>(target: T, ...sources: Array<Partial<T>>): T {
38-
if (!sources.length)
39-
return target
40-
41-
const source = sources.shift()
42-
43-
if (isObject(target) && isObject(source)) {
44-
for (const key in source) {
45-
if (Object.prototype.hasOwnProperty.call(source, key)) {
46-
const sourceValue = source[key]
47-
if (isObject(sourceValue) && isObject(target[key])) {
48-
target[key] = deepMerge(target[key] as any, sourceValue as any)
49-
}
50-
else {
51-
(target as any)[key] = sourceValue
52-
}
53-
}
54-
}
55-
}
56-
57-
return deepMerge(target, ...sources)
58-
}
59-
60-
function isObject(item: unknown): item is Record<string, unknown> {
61-
return (item && typeof item === 'object' && !Array.isArray(item)) as boolean
62-
}

0 commit comments

Comments
 (0)