-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
94 lines (90 loc) · 3.69 KB
/
Copy pathtsdown.config.ts
File metadata and controls
94 lines (90 loc) · 3.69 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
/**
* Build faces for dsh-budget. The node half (src/index.ts + the hand-written
* Typert host manifest src/typert.host.ts) is the host Loader entry; the
* browser half (src/client/index.ts) is the client bundle the client-modules
* node half serves under /plugins/dsh-budget/client.js.
*
* The browser half follows the shell's client-bundle handshake exactly: a
* CJS bundle wrapped in `window.__ModuleLoader__.load({ id, factory })`,
* with the shell's platform modules left external (the factory's `require`
* answers them from the frozen module table) and every other dependency
* inlined. @deepseek-ai/dsh-typert-protocol values (RemoteResult helpers are
* types only; the contributed descriptor carries a zod schema) and zod are
* inlined into both halves; zod stays a declared dependency for the node
* face, where tsdown externalizes declared deps/peers by default.
*/
import { defineConfig } from 'tsdown'
/** Plugin id: the cordis.yml bare row id, the graph row id, and the stamped bundle id must all match. */
const PLUGIN_ID = 'dsh-budget'
/**
* Module specifiers the shell shares into the frozen browser module table
* (packages/client/web/src/platform.ts). Any value import outside this
* list must be inlined.
*/
const PLATFORM_EXTERNALS: readonly string[] = [
'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',
]
export default defineConfig([
{
name: PLUGIN_ID,
entry: { index: 'src/index.ts', 'typert.host': 'src/typert.host.ts' },
outDir: 'lib',
format: ['esm'],
platform: 'node',
target: 'es2024',
dts: false,
// `scripts/prepare.mjs` wipes lib/ up front; tsdown clean stays off so the
// tsc declarations emitted first survive the bundle step.
clean: false,
// ESM output under a "type": "module" package must land on .js, not .mjs.
fixedExtension: false,
deps: {
// Only zod may come in from node_modules; everything else stays external
// (zod is the only non-peer dependency: bundling it keeps the host half
// self-contained when a profile resolves the package outside pnpm's tree,
// since the shared profiles/node_modules fallback carries no dep set).
onlyBundle: ['zod'],
alwaysBundle: ['zod'],
neverBundle: [/^node:/],
},
},
{
name: `${PLUGIN_ID}/client`,
entry: { client: 'src/client/index.ts' },
outDir: 'lib',
format: ['cjs'],
platform: 'browser',
dts: false,
sourcemap: true,
clean: false,
deps: {
// Platform modules stay external (the factory's `require` answers them
// from the shell's frozen module table); every other import is inlined.
// `onlyBundle: false` suppresses the bundled-dependency warning — the
// inlining here is deliberate, not accidental.
onlyBundle: false,
alwaysBundle: (id: string) => (PLATFORM_EXTERNALS.includes(id) ? undefined : true),
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(PLUGIN_ID)}, factory: (require) => {`,
footer: 'return module.exports; } });',
intro: 'var module = { exports: {} }; var exports = module.exports;',
},
},
])