Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip
  • Loading branch information
chrisbbreuer committed Nov 6, 2024
1 parent 0294627 commit 36e997b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 58 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@stacksjs/development": "^0.67.0",
"@stacksjs/eslint-config": "^3.8.1-beta.2",
"@types/bun": "^1.1.13",
"bun-config": "^0.1.0",
"tinyglobby": "^0.2.10",
"vitepress": "^1.4.5"
},
Expand Down
28 changes: 1 addition & 27 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
import type { DtsGenerationConfig } from './types'
import { existsSync } from 'node:fs'
import { resolve } from 'node:path'
import process from 'node:process'
import { deepMerge } from './utils'

interface Options<T> {
name: string
cwd?: string
defaultConfig: T
}

export async function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: Options<T>): Promise<T> {
const c = cwd ?? process.cwd()
const configPath = resolve(c, `${name}.config`)

if (existsSync(configPath)) {
try {
const importedConfig = await import(configPath)
const loadedConfig = importedConfig.default || importedConfig
return deepMerge(defaultConfig, loadedConfig)
}
catch (error) {
console.error(`Error loading config from ${configPath}:`, error)
}
}

return defaultConfig
}
import { loadConfig } from 'bun-config'

// Get loaded config
// eslint-disable-next-line antfu/no-top-level-await
Expand Down
8 changes: 4 additions & 4 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,13 +1103,13 @@ function inferTypeFromDefaultValue(defaultValue: string): string {
/**
* Check if a line is a JSDoc comment
*/
export function isJSDocComment(line: string): boolean {
function isJSDocComment(line: string): boolean {
const trimmed = line.trim()
const isJsDoc = trimmed.startsWith('/**') || trimmed.startsWith('*') || trimmed.startsWith('*/')
return isJsDoc
}

export function isDefaultExport(line: string): boolean {
function isDefaultExport(line: string): boolean {
// Handle both inline and multi-line default exports
return line.trim().startsWith('export default')
}
Expand Down Expand Up @@ -1532,7 +1532,7 @@ function processTypeBlock(cleanDeclaration: string, declarationText: string, sta
}

function processDefaultExportBlock(cleanDeclaration: string, state: ProcessingState): boolean {
if (!cleanDeclaration.startsWith('export default'))
if (!isDefaultExport(cleanDeclaration))
return false

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

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

// Store the complete default export statement
Expand Down
27 changes: 0 additions & 27 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,3 @@ export async function checkIsolatedDeclarations(options?: DtsGenerationConfig):
return false
}
}

export function deepMerge<T extends object>(target: T, ...sources: Array<Partial<T>>): T {
if (!sources.length)
return target

const source = sources.shift()

if (isObject(target) && isObject(source)) {
for (const key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
const sourceValue = source[key]
if (isObject(sourceValue) && isObject(target[key])) {
target[key] = deepMerge(target[key] as any, sourceValue as any)
}
else {
(target as any)[key] = sourceValue
}
}
}
}

return deepMerge(target, ...sources)
}

function isObject(item: unknown): item is Record<string, unknown> {
return (item && typeof item === 'object' && !Array.isArray(item)) as boolean
}

0 comments on commit 36e997b

Please sign in to comment.