|
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' |
5 | 2 |
|
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({ |
15 | 4 | entrypoints: ['src/index.ts'], |
16 | 5 | outdir: './dist', |
| 6 | + splitting: true, |
17 | 7 | target: 'bun', |
18 | 8 | format: 'esm', |
19 | | - minify: false, |
20 | | - sourcemap: 'external', |
| 9 | + plugins: [dts()], |
21 | 10 | }) |
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