-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtsup.config.ts
More file actions
91 lines (81 loc) · 2.25 KB
/
tsup.config.ts
File metadata and controls
91 lines (81 loc) · 2.25 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
import { defineConfig } from 'tsup';
import { readdirSync, readFileSync, statSync } from 'fs';
import { join, resolve } from 'path';
// Read version from package.json
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
// 自动扫描 src 目录下的所有 index.ts 文件作为入口点
function getEntryPoints(srcDir: string): string[] {
const entries: string[] = [];
const basePath = resolve(srcDir);
function scanDir(dir: string, relativePath = ''): void {
const items = readdirSync(dir);
for (const item of items) {
const fullPath = join(dir, item);
const stat = statSync(fullPath);
if (stat.isDirectory()) {
// 检查是否有 index.ts 文件
const indexPath = join(fullPath, 'index.ts');
try {
if (statSync(indexPath).isFile()) {
const entryPath = relativePath
? `${relativePath}/${item}/index.ts`
: `${item}/index.ts`;
entries.push(`src/${entryPath}`);
}
} catch {
// index.ts 不存在,继续递归扫描子目录
}
// 递归扫描子目录
const newRelativePath = relativePath ? `${relativePath}/${item}` : item;
scanDir(fullPath, newRelativePath);
}
}
}
// 总是包含根目录的 index.ts
entries.unshift('src/index.ts');
// 扫描 src 目录
scanDir(basePath);
return entries;
}
export default defineConfig({
entry: getEntryPoints('src'),
format: ['esm', 'cjs'],
dts: true,
splitting: false,
sourcemap: true,
clean: true,
target: 'node18',
outDir: 'dist',
external: [
'@ai-sdk/openai',
'@alicloud/agentrun20250910',
'@alicloud/devs20230714',
'@alicloud/openapi-client',
'@alicloud/tea-util',
'@modelcontextprotocol/sdk',
'ai',
'archiver',
'crc64-ecma182.js',
'dotenv',
'js-yaml',
'lodash',
'openai',
'uuid',
'zod',
'@mastra/core',
'chromium-bidi',
'playwright',
],
treeshake: true,
minify: false,
// ESM output uses .js extension, CJS uses .cjs
outExtension({ format }) {
return {
js: format === 'cjs' ? '.cjs' : '.js',
};
},
// Define constants to be replaced at build time
define: {
__VERSION__: JSON.stringify(pkg.version),
},
});