Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 15, 2024
1 parent 083d9bc commit f3fec05
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
## Features

- Fast .d.ts generation via isolatedDeclaration
- Configurability
- Cross-platform binary
- Configurability
- Bun-powered

## Install
Expand Down Expand Up @@ -59,6 +59,7 @@ export default {
root: './src',
outdir: './dist',
keepComments: true,
clean: true,
}
```

Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const config: DtsGenerationConfig = (await loadConfig({
outdir: './dist',
keepComments: true,
clean: true,
tsconfigPath: './tsconfig.json',
},
})).config
18 changes: 18 additions & 0 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ function formatDeclarations(declarations: string, isConfigFile: boolean): string
}

export async function generateDeclarationsFromFiles(options: DtsGenerationConfig = config): Promise<void> {
// Check for isolatedModules setting
const isIsolatedDeclarations = await checkIsolatedDeclarations(options)
if (!isIsolatedDeclarations) {
console.error('Error: isolatedModules must be set to true in your tsconfig.json. Ensure `tsc --noEmit` does not output any errors.')
return
}

if (options.clean) {
console.log('Cleaning output directory...')
await rm(options.outdir, { recursive: true, force: true })
Expand Down Expand Up @@ -192,3 +199,14 @@ async function getAllTypeScriptFiles(directory?: string): Promise<string[]> {
async function writeToFile(filePath: string, content: string): Promise<void> {
await Bun.write(filePath, content)
}

async function checkIsolatedDeclarations(options: DtsGenerationConfig): Promise<boolean> {
try {
const tsconfigPath = options.tsconfigPath || join(options.root, 'tsconfig.json')
const tsconfigContent = await readFile(tsconfigPath, 'utf-8')
const tsconfig = JSON.parse(tsconfigContent)
return tsconfig.compilerOptions?.isolatedModules === true
} catch (error) {
return false
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface DtsGenerationConfig {
outdir: string
keepComments: boolean
clean: boolean
tsconfigPath?: string
}

export type DtsGenerationOption = Partial<DtsGenerationConfig>
Expand Down

0 comments on commit f3fec05

Please sign in to comment.