Skip to content

Commit 1e65061

Browse files
committed
chore: add example-6
chore: wip
1 parent f7a9abd commit 1e65061

5 files changed

Lines changed: 87 additions & 1 deletion

File tree

fixtures/input/example-6.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { DtsGenerationOption } from '@stacksjs/dtsx'
2+
import type { BunPlugin } from 'bun'
3+
import process from 'node:process'
4+
import { generate } from '@stacksjs/dtsx'
5+
6+
export function dts(options?: DtsGenerationOption): BunPlugin {
7+
return {
8+
name: 'bun-plugin-dtsx',
9+
10+
async setup(build) {
11+
const cwd = options?.cwd ?? process.cwd()
12+
const root = options?.root ?? build.config.root
13+
const entrypoints = options?.entrypoints ?? build.config.entrypoints
14+
const outdir = options?.outdir ?? build.config.outdir
15+
const keepComments = options?.keepComments ?? true
16+
const clean = options?.clean ?? false
17+
const tsconfigPath = options?.tsconfigPath ?? './tsconfig.json'
18+
19+
await generate({
20+
...options,
21+
cwd,
22+
root,
23+
entrypoints,
24+
outdir,
25+
keepComments,
26+
clean,
27+
tsconfigPath,
28+
})
29+
},
30+
}
31+
}
32+
33+
export { generate }
34+
35+
export type { DtsGenerationOption }
36+
37+
export default dts

fixtures/output/example-6.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { DtsGenerationOption } from '@stacksjs/dtsx'
2+
import type { BunPlugin } from 'bun'
3+
import { generate } from '@stacksjs/dtsx'
4+
5+
export declare function dts(options?: DtsGenerationOption): BunPlugin
6+
7+
export { generate }
8+
9+
export type { DtsGenerationOption }
10+
11+
export default dts

scripts/compare.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import path from 'node:path'
2+
import { generate } from '../src'
3+
4+
console.log('Generating output for reviewal...', path.join(__dirname, '..'))
5+
6+
generate({
7+
cwd: path.join(__dirname, '..'),
8+
root: path.join(__dirname, '..', 'fixtures/input'),
9+
outdir: path.join(__dirname, '..', 'fixtures/generated'),
10+
clean: true,
11+
tsconfigPath: path.join(__dirname, '..', 'tsconfig.json'),
12+
})
13+
14+
console.log('Generated')

test/dts.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ describe('dts-generation', () => {
115115
expect(generatedContent).toBe(expectedContent)
116116
})
117117

118+
it('should properly generate types for example-6', async () => {
119+
const example = 'example-6'
120+
121+
const config: DtsGenerationOption = {
122+
entrypoints: [join(inputDir, `${example}.ts`)],
123+
outdir: generatedDir,
124+
clean: false,
125+
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
126+
}
127+
128+
await generate(config)
129+
130+
const outputPath = join(outputDir, `${example}.d.ts`)
131+
const generatedPath = join(generatedDir, `${example}.d.ts`)
132+
133+
const expectedContent = await Bun.file(outputPath).text()
134+
const generatedContent = await Bun.file(generatedPath).text()
135+
136+
expect(generatedContent).toBe(expectedContent)
137+
})
138+
118139
afterEach(async () => {
119140
// Clean up generated files
120141
try {

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"isolatedDeclarations": true,
2121
"verbatimModuleSyntax": true,
2222
"skipDefaultLibCheck": true,
23-
"skipLibCheck": true
23+
"skipLibCheck": true,
24+
"paths": {
25+
"@stacksjs/dtsx": ["./src/index.ts"]
26+
}
2427
}
2528
}

0 commit comments

Comments
 (0)