Skip to content

Commit a8529d4

Browse files
chore: wip
1 parent ba26be4 commit a8529d4

File tree

1 file changed

+3
-50
lines changed

1 file changed

+3
-50
lines changed

build.ts

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,8 @@
1-
import { execSync } from 'node:child_process'
2-
import fs, { existsSync, rmSync } from 'node:fs'
3-
import path from 'node:path'
4-
import process from 'node:process'
1+
import { dts } from 'bun-plugin-dtsx'
52

6-
// Clean dist directory
7-
if (existsSync('./dist')) {
8-
rmSync('./dist', { recursive: true })
9-
}
10-
11-
console.log('Building JavaScript files...')
12-
13-
// Build JavaScript files using Bun's bundler
14-
const jsResult = await Bun.build({
3+
await Bun.build({
154
entrypoints: ['src/index.ts'],
165
outdir: './dist',
176
target: 'bun',
18-
format: 'esm',
19-
minify: false,
20-
sourcemap: 'external',
7+
plugins: [dts()],
218
})
22-
23-
if (!jsResult.success) {
24-
console.error('JavaScript build failed:', jsResult.logs)
25-
process.exit(1)
26-
}
27-
28-
console.log('Generating TypeScript declaration files...')
29-
30-
// Generate declaration files using TypeScript compiler
31-
try {
32-
execSync('bunx tsc --declaration --emitDeclarationOnly --outDir dist --project tsconfig.json', {
33-
stdio: 'inherit',
34-
cwd: process.cwd(),
35-
})
36-
37-
const srcIndexDts = path.join(process.cwd(), 'dist', 'src', 'index.d.ts')
38-
const distIndexDts = path.join(process.cwd(), 'dist', 'index.d.ts')
39-
40-
if (fs.existsSync(srcIndexDts)) {
41-
let content = fs.readFileSync(srcIndexDts, 'utf8')
42-
43-
// Fix relative paths to point to src/ subdirectory
44-
content = content.replace(/from '\.\//g, 'from \'./src/')
45-
46-
fs.writeFileSync(distIndexDts, content)
47-
console.log('✅ Copied and fixed main declaration file to dist root')
48-
}
49-
50-
console.log('✅ Build completed successfully!')
51-
}
52-
catch (error) {
53-
console.error('❌ Failed to generate declaration files:', error)
54-
process.exit(1)
55-
}

0 commit comments

Comments
 (0)