Skip to content

Commit f3fec05

Browse files
committedOct 15, 2024
chore: wip
1 parent 083d9bc commit f3fec05

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed
 

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
## Features
1010

1111
- Fast .d.ts generation via isolatedDeclaration
12-
- Configurability
1312
- Cross-platform binary
13+
- Configurability
1414
- Bun-powered
1515

1616
## Install
@@ -59,6 +59,7 @@ export default {
5959
root: './src',
6060
outdir: './dist',
6161
keepComments: true,
62+
clean: true,
6263
}
6364
```
6465

‎bun.lockb

7.54 KB
Binary file not shown.

‎src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export const config: DtsGenerationConfig = (await loadConfig({
1212
outdir: './dist',
1313
keepComments: true,
1414
clean: true,
15+
tsconfigPath: './tsconfig.json',
1516
},
1617
})).config

‎src/generate.ts

+18
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ function formatDeclarations(declarations: string, isConfigFile: boolean): string
130130
}
131131

132132
export async function generateDeclarationsFromFiles(options: DtsGenerationConfig = config): Promise<void> {
133+
// Check for isolatedModules setting
134+
const isIsolatedDeclarations = await checkIsolatedDeclarations(options)
135+
if (!isIsolatedDeclarations) {
136+
console.error('Error: isolatedModules must be set to true in your tsconfig.json. Ensure `tsc --noEmit` does not output any errors.')
137+
return
138+
}
139+
133140
if (options.clean) {
134141
console.log('Cleaning output directory...')
135142
await rm(options.outdir, { recursive: true, force: true })
@@ -192,3 +199,14 @@ async function getAllTypeScriptFiles(directory?: string): Promise<string[]> {
192199
async function writeToFile(filePath: string, content: string): Promise<void> {
193200
await Bun.write(filePath, content)
194201
}
202+
203+
async function checkIsolatedDeclarations(options: DtsGenerationConfig): Promise<boolean> {
204+
try {
205+
const tsconfigPath = options.tsconfigPath || join(options.root, 'tsconfig.json')
206+
const tsconfigContent = await readFile(tsconfigPath, 'utf-8')
207+
const tsconfig = JSON.parse(tsconfigContent)
208+
return tsconfig.compilerOptions?.isolatedModules === true
209+
} catch (error) {
210+
return false
211+
}
212+
}

‎src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface DtsGenerationConfig {
44
outdir: string
55
keepComments: boolean
66
clean: boolean
7+
tsconfigPath?: string
78
}
89

910
export type DtsGenerationOption = Partial<DtsGenerationConfig>

0 commit comments

Comments
 (0)