-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
91 lines (85 loc) · 3.11 KB
/
Copy pathtsdown.config.ts
File metadata and controls
91 lines (85 loc) · 3.11 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
/**
* dsh-plugin/command-opt — DSH 命令优化插件。
*
* 构建产出两个半区:
* - lib/index.js host 半区(Node ESM 占位:插件逻辑全部在 browser 半区)
* - lib/client.js browser 半区(Tab 补全命令名 + 空对话命令输出修复)
*
* 客户端打包约定(与 hotkeys/官方 packages/client/tsdown.client.ts 一致):
* 闭包工厂产物 —— bundle 调用 window.__ModuleLoader__.load({ id, factory }),
* 外部模块(react 平台模块表等)经注入的 require 在运行时解析,绝不内联。
*/
import type { UserConfig } from 'tsdown'
/** 本插件包名(同时是 client bundle 的 loader id)。 */
const ID = '@dsh-external/dsh-command-opt'
/**
* 浏览器侧外部模块:平台种子表(PLATFORM_MODULES)加 runtime/client 豁免。
* 与 host 的模块表逐字一致;运行时由 loader 的 require 提供。
*/
const PLATFORM_EXTERNALS = [
'react', 'react/jsx-runtime', 'react-dom', 'react-dom/client', '@deepseek-ai/cordis',
'@deepseek-ai/dsh-client-ui-slots',
'@deepseek-ai/dsh-client-web-react',
'@deepseek-ai/dsh-client-ui-primitives',
'@deepseek-ai/dsh-client-ui-attachment',
'@deepseek-ai/dsh-client-schema-form',
'@deepseek-ai/dsh-client-runtime/client',
]
/**
* host 半区运行时值依赖:由插件安装后自带的 node_modules 提供
* (link: 指向本机 deepseek-harness 检出的构建产物),不内联。
*/
const HOST_RUNTIME_DEPS = [
'@deepseek-ai/cordis',
]
/** host 半区:node 侧库构建。 */
const libConfig: UserConfig = {
name: ID,
entry: ['src/index.ts'],
outDir: 'lib',
format: ['esm'],
platform: 'node',
target: 'es2022',
// 保持入口文件名:src/index.ts → lib/index.js(package.json main 指向它)。
fixedExtension: false,
dts: true,
clean: false,
deps: {
neverBundle: HOST_RUNTIME_DEPS,
},
}
/** browser 半区:client bundle(lib/client.js)。 */
const clientConfig: UserConfig = {
name: `${ID}/client`,
entry: { client: 'src/client/index.ts' },
outDir: 'lib',
format: 'cjs',
platform: 'browser',
target: 'es2022',
dts: true,
sourcemap: true,
clean: false,
deps: {
neverBundle: PLATFORM_EXTERNALS,
},
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),
'import.meta.env.MODE': JSON.stringify(process.env.NODE_ENV ?? 'production'),
'import.meta.env': JSON.stringify({ MODE: process.env.NODE_ENV ?? 'production' }),
},
outputOptions: {
entryFileNames: 'client.js',
banner: `window.__ModuleLoader__.load({ id: ${JSON.stringify(ID)}, factory: (require) => {`,
footer: 'return module.exports; } });',
intro: 'var module = { exports: {} }; var exports = module.exports;',
},
}
export default ({ env }: { env?: { DSH_BUILD_FACE?: string } }) => {
const face = env?.DSH_BUILD_FACE
if (face !== undefined && face !== 'host' && face !== 'client') {
throw new Error(`tsdown: --env.DSH_BUILD_FACE must be host or client, received ${String(face)}`)
}
if (face === 'host') return [libConfig]
if (face === 'client') return [clientConfig]
return [libConfig, clientConfig]
}