-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtsup.config.ts
More file actions
104 lines (96 loc) · 3.14 KB
/
tsup.config.ts
File metadata and controls
104 lines (96 loc) · 3.14 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { defineConfig } from 'tsup';
export default defineConfig([
// Server build (with shebang for npx usage, excludes native deps)
{
entry: ['src/index.ts'],
outDir: 'dist/server',
format: ['esm'],
dts: true,
clean: true,
splitting: false,
sourcemap: true,
minify: false,
target: 'node18',
platform: 'node',
bundle: true,
external: ['@lancedb/lancedb', 'better-sqlite3'], // Mark native deps as external
publicDir: false,
treeshake: true,
skipNodeModulesBundle: true, // Don't bundle node_modules due to native deps
tsconfig: 'tsconfig.json',
shims: false,
cjsInterop: false,
banner: {
js: '#!/usr/bin/env node'
},
// Ensure server binary is executable and copy hooks
onSuccess: async () => {
const { execSync } = await import('child_process');
const fs = await import('fs');
const path = await import('path');
try {
execSync('chmod +x dist/server/index.js', { stdio: 'ignore' });
console.log('✅ Made server binary executable');
} catch (error) {
console.warn('⚠️ Failed to make server binary executable:', error);
}
// Copy hooks directory to dist with Unix line endings
try {
const srcHooksDir = path.resolve('src/hooks');
const distHooksDir = path.resolve('dist/hooks');
if (fs.existsSync(srcHooksDir)) {
// Create dist hooks directory
fs.mkdirSync(distHooksDir, { recursive: true });
// Copy each hook file and fix line endings
const hookFiles = fs.readdirSync(srcHooksDir);
for (const file of hookFiles) {
const srcFile = path.join(srcHooksDir, file);
const destFile = path.join(distHooksDir, file);
let content = fs.readFileSync(srcFile, 'utf8');
// Ensure Unix line endings
content = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
fs.writeFileSync(destFile, content);
fs.chmodSync(destFile, 0o755); // Make executable
}
console.log('✅ Copied hooks to dist with Unix line endings');
}
} catch (error) {
console.warn('⚠️ Failed to copy hooks:', error);
}
}
},
// CLI build (with shebang)
{
entry: ['src/cli/index.ts'],
outDir: 'dist/cli',
format: ['esm'],
dts: true,
clean: true,
splitting: false,
sourcemap: true,
minify: false,
target: 'node18',
platform: 'node',
bundle: true,
external: [],
publicDir: false,
treeshake: true,
skipNodeModulesBundle: true,
tsconfig: 'tsconfig.json',
shims: false,
cjsInterop: false,
banner: {
js: '#!/usr/bin/env node'
},
// Ensure CLI binary is executable
onSuccess: async () => {
const { execSync } = await import('child_process');
try {
execSync('chmod +x dist/cli/index.js', { stdio: 'ignore' });
console.log('✅ Made CLI binary executable');
} catch (error) {
console.warn('⚠️ Failed to make CLI binary executable:', error);
}
}
}
]);