-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
47 lines (42 loc) · 1.08 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { build } = require('esbuild');
const { copyFile } = require('fs/promises');
const { resolve } = require('path');
async function buildPackage() {
try {
// Build ESM version
await build({
entryPoints: ['./src/index.ts'],
outfile: './dist/index.mjs',
format: 'esm',
platform: 'node',
target: 'es2018',
bundle: true,
external: ['zod'],
});
// Build CommonJS version
await build({
entryPoints: ['./src/index.ts'],
outfile: './dist/index.js',
format: 'cjs',
platform: 'node',
target: 'es2018',
bundle: true,
external: ['zod'],
});
// Copy the TypeScript declarations
await copyFile(
resolve('./dist/index.d.ts'),
resolve('./dist/index.d.mts')
).catch(err => {
// Ignore if the file doesn't exist, as TypeScript doesn't generate .d.mts files
if (err.code !== 'ENOENT') {
throw err;
}
});
console.log('✅ Build completed');
} catch (err) {
console.error('❌ Build failed:', err);
process.exit(1);
}
}
buildPackage();