Skip to content

Commit

Permalink
feat: add outDir option
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Feb 23, 2024
1 parent eb84883 commit 824d4d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ console.log('Build complete ✅')
```

> [!NOTE]
> Please note, this plugin honors your `tsconfig.json` settings (e.g. `compilerOptions.outDir`).
> Please note, this plugin honors your `tsconfig.json` `compilerOptions.outDir` setting. If you want to override this, you can do so by setting the `outdir` option in the build option object.
## 🧪 Testing

Expand Down
13 changes: 5 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ interface DtsOptions {
compiler?: ts.CompilerOptions
tsconfigPath?: string
withSourceMap?: boolean
outDir?: string
}

export async function generate(entryPoints: string | string[], options?: DtsOptions) {
const path = p.resolve(options?.tsconfigPath ?? 'tsconfig.json')
const configJson = ts.readConfigFile(path, ts.sys.readFile).config

let opts: TsOptions = {
const opts: TsOptions = {
declaration: true,
emitDeclarationOnly: true,
noEmit: false,
}

if (options?.withSourceMap) {
opts = {
...opts,
declarationMap: true,
}
outDir: options?.outDir ?? 'dist/types',
declarationMap: options?.withSourceMap ?? false,
}

const parsedConfig = ts.parseJsonConfigFileContent(
Expand All @@ -56,6 +52,7 @@ export async function generate(entryPoints: string | string[], options?: DtsOpti
export function dts(options?: DtsOptions): BunPlugin {
return {
name: 'bun-plugin-dts-auto',

async setup(build) {
const entrypoints = [...build.config.entrypoints].sort()
await generate(entrypoints, options)
Expand Down

0 comments on commit 824d4d9

Please sign in to comment.