From e67e6355888284644c622c40bc030e727b374ac8 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 20 Oct 2024 12:57:57 +0200 Subject: [PATCH] chore: add `example-6` --- fixtures/input/example-6.ts | 37 ++++++++++++++++++++++++++++++++++ fixtures/output/example-6.d.ts | 10 +++++++++ test/dts.test.ts | 21 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 fixtures/input/example-6.ts create mode 100644 fixtures/output/example-6.d.ts diff --git a/fixtures/input/example-6.ts b/fixtures/input/example-6.ts new file mode 100644 index 0000000..40830a1 --- /dev/null +++ b/fixtures/input/example-6.ts @@ -0,0 +1,37 @@ +import type { DtsGenerationOption } from '../../src/types' +import type { BunPlugin } from 'bun' +import process from 'node:process' +import { generate } from '../../src/index' + +export function dts(options?: DtsGenerationOption): BunPlugin { + return { + name: 'bun-plugin-dtsx', + + async setup(build) { + const cwd = options?.cwd ?? process.cwd() + const root = options?.root ?? build.config.root + const entrypoints = options?.entrypoints ?? build.config.entrypoints + const outdir = options?.outdir ?? build.config.outdir + const keepComments = options?.keepComments ?? true + const clean = options?.clean ?? false + const tsconfigPath = options?.tsconfigPath ?? './tsconfig.json' + + await generate({ + ...options, + cwd, + root, + entrypoints, + outdir, + keepComments, + clean, + tsconfigPath, + }) + }, + } +} + +export { generate } + +export type { DtsGenerationOption } + +export default dts diff --git a/fixtures/output/example-6.d.ts b/fixtures/output/example-6.d.ts new file mode 100644 index 0000000..12be12d --- /dev/null +++ b/fixtures/output/example-6.d.ts @@ -0,0 +1,10 @@ +import type { DtsGenerationOption } from '../../src/types' +import type { BunPlugin } from 'bun' + +export function dts(options?: DtsGenerationOption): BunPlugin + +export function generate(options: DtsGenerationOption): Promise + +export { DtsGenerationOption } + +export default dts diff --git a/test/dts.test.ts b/test/dts.test.ts index e9f2966..96888c4 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -115,6 +115,27 @@ describe('dts-generation', () => { expect(generatedContent).toBe(expectedContent) }) + it('should properly generate types for example-6', async () => { + const example = 'example-6' + + const config: DtsGenerationOption = { + entrypoints: [join(inputDir, `${example}.ts`)], + outdir: generatedDir, + clean: false, + tsconfigPath: join(__dirname, '..', 'tsconfig.json'), + } + + await generate(config) + + const outputPath = join(outputDir, `${example}.d.ts`) + const generatedPath = join(generatedDir, `${example}.d.ts`) + + const expectedContent = await Bun.file(outputPath).text() + const generatedContent = await Bun.file(generatedPath).text() + + expect(generatedContent).toBe(expectedContent) + }) + afterEach(async () => { // Clean up generated files try {