-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
89 lines (85 loc) · 4.01 KB
/
Copy pathtsdown.config.ts
File metadata and controls
89 lines (85 loc) · 4.01 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
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import { basename, dirname, join, normalize, relative, resolve as resolvePath, sep } from 'node:path'
import { transform } from 'lightningcss'
import type { UserConfig } from 'tsdown'
const PLUGIN_ID = 'dsh-side-chat'
const CSS_VIRTUAL_PREFIX = '\0dsh-side-chat-css:'
const CSS_VIRTUAL_SUFFIX = '.mjs'
const REPOSITORY_ROOT = dirname(fileURLToPath(import.meta.url))
const CLIENT_EXTERNALS = [
'react', 'react/jsx-runtime', 'react-dom', 'react-dom/client',
'@deepseek-ai/cordis',
'@deepseek-ai/dsh-client-runtime/client',
'@deepseek-ai/dsh-api-remotes/client',
'@deepseek-ai/dsh-client-ui-slots',
'@deepseek-ai/dsh-client-ui-conversation/client',
'@deepseek-ai/dsh-client-ui-layout/client',
'@deepseek-ai/dsh-client-ui-primitives',
'@deepseek-ai/dsh-client-locale/client',
] as const
const inlineCssPlugin = {
name: 'dsh-side-chat-css-inline',
resolveId(source: string, importer: string | undefined) {
if (!source.endsWith('.css')) return null
if (source.startsWith('\0')) return `${CSS_VIRTUAL_PREFIX}${source}${CSS_VIRTUAL_SUFFIX}`
if (!source.startsWith('.')) throw new Error(`bare stylesheet imports are not supported: ${source}`)
const importerDirectory = importer === undefined ? '' : relative(REPOSITORY_ROOT, dirname(importer))
const fileId = normalize(join(importerDirectory, source)).split(sep).join('/')
return `${CSS_VIRTUAL_PREFIX}${fileId}${CSS_VIRTUAL_SUFFIX}`
},
async load(virtualId: string) {
if (!virtualId.startsWith(CSS_VIRTUAL_PREFIX)) return null
const fileId = virtualId.slice(CSS_VIRTUAL_PREFIX.length, -CSS_VIRTUAL_SUFFIX.length)
const source = await readFile(resolvePath(REPOSITORY_ROOT, fileId))
const isModule = fileId.endsWith('.module.css')
const { code, exports: cssExports } = transform({
filename: fileId,
code: source,
...(isModule ? { cssModules: { pattern: '[hash]_[local]' } } : {}),
minify: true,
})
const classMap = Object.fromEntries(
Object.entries(cssExports ?? {})
.sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
.map(([local, exported]) => [local, exported.name]),
)
const tagId = `${PLUGIN_ID}/${basename(fileId)}`
return [
`const css = ${JSON.stringify(code.toString())};`,
`const tagId = ${JSON.stringify(tagId)};`,
`if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css=' + JSON.stringify(tagId) + ']') === null) {`,
" const tag = document.createElement('style');",
` tag.dataset.plugin = ${JSON.stringify(PLUGIN_ID)};`,
' tag.dataset.pluginCss = tagId;',
' tag.textContent = css;',
' document.head.appendChild(tag);',
'}',
`export default ${JSON.stringify(classMap)};`,
].join('\n')
},
}
export default [
{
entry: { index: 'src/index.ts', 'typert.host': 'src/typert.host.ts', 'typert.remote-client': 'src/client/remote.ts' },
outDir: 'lib', format: ['esm'], platform: 'node', target: 'es2024', fixedExtension: false, dts: true, clean: true,
deps: { neverBundle: [
'@deepseek-ai/cordis', '@deepseek-ai/dsh-agent', '@deepseek-ai/dsh-llm',
'@deepseek-ai/dsh-session', '@deepseek-ai/dsh-subagent', '@deepseek-ai/dsh-tools',
'@deepseek-ai/dsh-typert-protocol', '@deepseek-ai/dsh-workspace', 'zod',
] },
},
{
entry: { client: 'src/client/index.ts' }, outDir: 'lib', format: 'cjs', platform: 'browser', target: 'es2024',
dts: false, clean: false,
deps: { alwaysBundle: ['zod'], neverBundle: [...CLIENT_EXTERNALS] },
define: { 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production') },
plugins: [inlineCssPlugin],
outputOptions: {
entryFileNames: 'client.js',
banner: `window.__ModuleLoader__.load({ id: ${JSON.stringify(PLUGIN_ID)}, factory: (require) => {`,
footer: 'return module.exports; } });',
intro: 'var module = { exports: {} }; var exports = module.exports;',
},
},
] satisfies UserConfig[]