three Client packages as `immediately` dynamic plugins
three Client packages as `immediately` dynamic plugins
`@deepseek-ai/dsh-client-ui-slots`, `@deepseek-ai/dsh-client-ui-primitives`, and `@deepseek-ai/dsh-client-ui-dockkit` supply synchronous values, such as slot registry types, shared controls, and the dock layout engine, to most Client bundles. The Web shell linked them statically, so the shell bundle carried them together with KaTeX, Shiki, and the Markdown parser, and the shell seeded their module-table identities. A
English
Problem
@deepseek-ai/dsh-client-ui-slots, @deepseek-ai/dsh-client-ui-primitives, and @deepseek-ai/dsh-client-ui-dockkit supply synchronous values, such as slot registry types, shared controls, and the dock layout engine, to most Client bundles. The Web shell linked them statically, so the shell bundle carried them together with KaTeX, Shiki, and the Markdown parser, and the shell seeded their module-table identities.
A dynamic plugin package is a Loader row, and the Host Loader imports every row's package root in Node, where these packages' stylesheet imports cannot load. Published package exports can send the types and the runtime of the root to different files. In the repository, one tsconfig paths entry per name serves tsc, Vitest, and the tsx source launch alike, and it cannot.
Decision
immediately dynamic plugin packages
Each of the three packages declares dsh.client with platform: 'web' and immediately: true, as ui-renderer, client-connection, and the other immediately packages do, and packages/bundle/web-app/cordis.patch.yml lists their rows by plain package name. src/client/index.ts builds lib/client.js, the ./client export, whose apply registers nothing. The immediately tier registers these factories before other plugins materialize, so any bundle can require their exports, and every dynamic bundle leaves the three names to the module table without declaring them (shared module table).
They differ from the other immediately packages in two ways. Their package root carries the compatibility adjustments below. Their /client entries still export values, such as components, classes, and functions, that other bundles require; this is a historical exception that will be reduced over time and no precedent for new value exports (export discipline).
client-store is a statically linked library
@deepseek-ai/dsh-client-store is a staticLinked library that the Web shell bundles with Zustand and Immer and seeds into the module table; repository code imports it by package root, and it imports no DSH package. ui-slots and ui-primitives import it by package root, and their dynamic bundles leave it to the module table like every other baseline module. A store service, if one is needed, is a new package, not a conversion of this one.
The package root: a Host entry with the ./client types
The root's runtime is the hand-written src/index.js, which exports only the empty apply and builds the Host entry lib/index.js; the packages have no src/index.ts. tsconfig.base.json maps each package root to the src directory, as for every Client package, so tsx resolves it to src/index.js and the Host Loader never evaluates src/client/index.ts. The packages have no Host API, so the published root types reuse lib/types/client/index.d.ts, the ./client declarations, and check-workspace-constraints accepts root types that equal the package's own ./client types. Gates that need the Host source resolve ./src/index.js to its source module.
X and X/client name one module
The module table resolves a <specifier>/client it does not hold exactly to the <specifier> row (stripClientSuffix), so require('<package>') and require('<package>/client') return one exports object. The dynamic build preset applies the same rule through coversRequest in tsdown.client.ts: when <specifier> is a baseline, preloaded, or dsh.client.external request, a bundle that imports <specifier>/client emits a module-table require instead of inlining a private copy.
The repository names the packages through /client
Repository code imports values and types from, and augments, <package>/client; verify-client-packages rejects every package-root reference to a workspace package whose root types equal its own ./client types, a set it reads from the manifests. In the repository the package root resolves to the Host entry: Vite and Rolldown find src/index.js, so a root value import reads undefined, and the compiler finds no declarations there. Root declarations in the repository would need a separate file, and TypeScript merges a root augmentation and a /client augmentation of one interface only when it processes the /client one first. With /client everywhere, every augmentation lands on the module that declares the interface. The /client paths resolve to src/client/index.ts in every tool, so the Vitest lanes need no alias, and the benchmark workers bundle the /client subpaths of workspace packages that declare dsh.client from source (benchmarks/tsdown.config.ts).
/client is also the recommended specifier for every consumer.
Compatibility commitments
Published packages give the root and ./client one declaration file, so code outside the repository may use either spelling or mix them. DSH tests two commitments for code written against the package root:
| Commitment | Enforced by |
|---|---|
A TypeScript consumer may import types from the package root, augment declare module '<package>', and mix both spellings in one file or across files in either order; every importer reads one merged interface, under NodeNext and Bundler resolution | verify-client-package-consumer-types in pnpm run hygiene, compiling the external consumer fixtures against the built lib/types; its negative control requires the mixed programs to fail against a forwarding package root |
A built plugin's require('<package>') returns the same exports as require('<package>/client') | loader.client.spec.ts and the browser test client-package-specifiers.e2e.ts with a hand-written prebuilt fixture plugin |
A dynamic bundle that imports either specifier emits a module-table require and inlines none of the three packages (client-bundle-purity.spec.ts). Values from the package root in Node, the __$dsh_client_module_manifest export, and stability of the packages' exported APIs are not supported.
Alternatives considered
Change apps/cli/src/bin.ts or add a source-launch resolve hook. The source launch would resolve these three names differently from tsc and Vitest, a rule that every launcher and tool would have to repeat.
Change the Loader or the client-modules resolution. The module table already answers package rows and their /client subpaths; a branch for three packages would make them a special kind of row.
Name the rows by anything other than the plain package name. Every other row uses its package name; renaming these rows would move the special case into every composition.
Duplicate the tsconfig paths, mapping the root to /client for some tools and to the Host entry for others. One paths table serves tsc, Vitest, and tsx, so a second mapping per name would need a separate configuration for each tool.
Custom export conditions. tsc, Vite, Rolldown, tsx, and Node would each have to opt in to the condition, and a consumer that does not would read the wrong file.
File-existence checks for .ts versus .js in gates and tools. Gates would pass or fail depending on which file a checkout contains; they name ./src/index.js directly instead.
A separate "platform library" category or variable. The three packages are immediately dynamic plugin packages like the others; another category would add a third package kind to documentation and gates.
Keep root value imports and alias the package root to /client in Vitest and the benchmarks. About five hundred files would keep a form that works only where an alias exists, and every new test lane or tool would need the alias.
A hand-written src/index.d.ts that re-exports ./client/index.ts. The root would be a separate declaration file: mixed augmentations would merge in one processing order only, an augmenting program would fail with TS2664 unless it also loads the root, and gates that resolve configured rows would need to accept a declaration file under src/.
Augment the package root in the repository and reject /client augmentations. It needs the forwarding declaration file above and fixes the repository on the specifier that is not recommended.
Convert client-store as well. client-store is a leaf library that imports no DSH package; it stays statically linked, and a store service, if one is needed, becomes a new package with its own lifecycle rather than a conversion of this one.
Consequences
- The Web shell no longer bundles the three packages, KaTeX, Shiki, or the Markdown parser, and still bundles
client-store, Zustand, and Immer; a composition that replaces the Web client must list the three rows (upgrade guide). - Repository code and external code share one recommended specifier, and code written against the package root keeps compiling and loading.
- In Node the package root yields only the Host entry, so tests and tools that run these packages' browser code import
/client. - Gates that resolve configured row names, such as
verify-cordis-config, reach the Host entrysrc/index.jsundersrc/. - The TypeScript commitment holds because the published root and
./clientshare one declaration file; the consumer check's negative control shows that a separate root types file that forwards to./clientwould split mixed augmentations. - New shared runtime code goes through Cordis services, slots, or browser-safe utility packages, never into the value exports of these three packages.
中文
Problem
@deepseek-ai/dsh-client-ui-slots、@deepseek-ai/dsh-client-ui-primitives 和 @deepseek-ai/dsh-client-ui-dockkit 向大多数 Client bundle 提供同步的值,例如 slot 注册表类型、共享控件和 dock 布局引擎。Web 外壳曾静态链接它们,于是外壳 bundle 连同 KaTeX、Shiki 和 Markdown 解析器一起携带它们,并由外壳在模块表中预置它们的模块身份。
动态插件包是一个 Loader row,Host Loader 会在 Node 中 import 每个 row 的包根,而这几个包的样式表 import 在 Node 中无法加载。已发布包的 exports 可以把包根的类型和运行时指向不同的文件。在仓库里,每个名字只有一条 tsconfig paths,它同时服务 tsc、Vitest 和 tsx 源码启动,做不到这一点。
Decision
immediately 动态插件包
三个包都声明带 platform: 'web' 与 immediately: true 的 dsh.client,与 ui-renderer、client-connection 等其他 immediately 包相同,packages/bundle/web-app/cordis.patch.yml 按纯包名列出它们的 row。src/client/index.ts 构建出 ./client 导出 lib/client.js,其 apply 不登记任何东西。immediately 层在其他插件实例化之前登记这些 factory,因此任何 bundle 都可以 require 它们的导出,每个动态 bundle 也不必声明就会把这三个名字留给模块表(共享模块表)。
它们与其他 immediately 包只有两点不同。它们的包根带有下文的兼容调整。它们的 /client 入口仍导出供其他 bundle require 的实体值,例如组件、类和函数;这是会逐步缩减的历史例外,不是新增实体导出的先例(导出规则)。
client-store 是静态链接的库
@deepseek-ai/dsh-client-store 是 staticLinked 库,由 Web 外壳连同 Zustand 和 Immer 一起打包,并预置进模块表;仓库代码按包根 import 它,它也不 import 任何 DSH 包。ui-slots 和 ui-primitives 按包根 import 它,它们的动态 bundle 像对待其他基座模块一样把它留给模块表。如果需要 store service,那将是一个新包,而不是对这个包的转换。
包根:带 ./client 类型的 Host 入口
包根的运行时是手写的 src/index.js,只导出空 apply,构建出 Host 入口 lib/index.js;这几个包没有 src/index.ts。和所有 Client 包一样,tsconfig.base.json 把每个包根映射到 src 目录,所以 tsx 把它解析到 src/index.js,Host Loader 从不求值 src/client/index.ts。这几个包没有 Host API,因此发布后的根 types 复用 ./client 的声明 lib/types/client/index.d.ts,check-workspace-constraints 接受与本包 ./client types 相同的根 types。需要 Host 源码的门禁把 ./src/index.js 解析到对应的源码模块。
X 与 X/client 指向同一个模块
模块表在没有精确登记 <specifier>/client 时,会把它解析到 <specifier> 那一行(stripClientSuffix),所以 require('<包名>') 与 require('<包名>/client') 返回同一个导出对象。动态构建预设通过 tsdown.client.ts 中的 coversRequest 采用同一规则:当 <specifier> 是基线、预加载或 dsh.client.external 请求时,import <specifier>/client 的 bundle 会生成模块表 require,而不是内联一份私有副本。
仓库通过 /client 引用这些包
仓库代码从 <包名>/client import 值和类型,也扩展 <包名>/client;verify-client-packages 拒绝对这样一类工作区包的任何包根引用:包的根 types 等于它自己的 ./client types,这个集合从 manifest 中读出。仓库里的包根解析到 Host 入口:Vite 和 Rolldown 会找到 src/index.js,所以从包根 import 值会读到 undefined;编译器在那里也找不到声明。要让仓库里的包根带上声明,就得另写一个文件,而 TypeScript 只有在先处理 /client 扩展时,才会把同一接口的包根扩展与 /client 扩展合并。全部改用 /client 后,每个扩展都直接落在声明接口的那个模块上。/client 路径在所有工具中都解析到 src/client/index.ts,所以 Vitest 各 lane 不需要别名,benchmark worker 也从源码打包声明了 dsh.client 的工作区包的 /client 子路径(benchmarks/tsdown.config.ts)。
/client 也是对所有使用方推荐的写法。
兼容承诺
已发布包的根与 ./client 是同一个声明文件,所以仓库外的代码可以使用任一写法,也可以混用。对按包根编写的代码,DSH 用测试守住两条承诺:
| 承诺 | 由谁保证 |
|---|---|
TypeScript 使用方可以从包根导入类型、写 declare module '<包名>',并在同一文件或不同文件中按任意顺序混用两种写法;在 NodeNext 与 Bundler 解析下,每个使用方读到的都是同一个合并后的接口 | pnpm run hygiene 中的 verify-client-package-consumer-types,它针对构建出的 lib/types 编译外部消费者 fixture;其负对照要求混用程序在转发型包根上编译失败 |
已构建插件的 require('<包名>') 与 require('<包名>/client') 返回相同的导出 | loader.client.spec.ts,以及使用手写预构建 fixture 插件的浏览器测试 client-package-specifiers.e2e.ts |
无论 import 哪种写法,动态 bundle 都生成模块表 require,且不内联这三个包中的任何模块(client-bundle-purity.spec.ts)。不支持在 Node 中从包根取得值,不支持 __$dsh_client_module_manifest 导出,也不保证这些包导出的 API 稳定。
Alternatives considered
修改 apps/cli/src/bin.ts 或增加源码启动的 resolve hook。 这样源码启动对这三个名字的解析会与 tsc 和 Vitest 不同,每个启动器和工具都得重复这条规则。
修改 Loader 或 client-modules 的解析逻辑。 模块表已经能应答包 row 及其 /client 子路径;为三个包加分支,会让它们成为一种特殊的 row。
row 不用纯包名命名。 其他 row 都用包名;给这几个 row 改名只会把特例挪进每个组合。
重复 tsconfig paths,让一些工具把包根映射到 /client、另一些映射到 Host 入口。 同一张 paths 表服务 tsc、Vitest 和 tsx,每个名字再加一套映射,就得给每个工具单独配置。
自定义 export condition。 tsc、Vite、Rolldown、tsx 和 Node 都得各自启用这个 condition,没启用的使用方会读到错误的文件。
在门禁和工具里检查 .ts 与 .js 文件是否存在。 门禁的结果会取决于某个检出恰好有哪个文件;门禁改为直接写 ./src/index.js。
单独的「platform library」类别或变量。 这三个包与其他包一样是 immediately 动态插件包;再加一个类别,会让文档和门禁多出第三种包。
保留从包根 import 值,并在 Vitest 和 benchmark 中把包根别名到 /client。 大约五百个文件会保留一种只有在有别名时才能工作的写法,每个新的测试 lane 或工具都需要这个别名。
手写一个 re-export ./client/index.ts 的 src/index.d.ts。 包根会成为另一个声明文件:混用写法的扩展只在一种处理顺序下合并;做扩展的程序若不同时加载包根,会报 TS2664;解析已配置 row 的门禁也得接受 src/ 下的声明文件。
仓库内扩展包根,并拒绝 /client 扩展。 它需要上面那个转发声明文件,而且把仓库固定在不推荐的写法上。
把 client-store 也一并转换。 client-store 是不 import 任何 DSH 包的叶子库;它继续静态链接,如果需要 store service,将是一个有自己生命周期的新包,而不是对这个包的转换。
Consequences
- Web 外壳不再打包这三个包、KaTeX、Shiki 或 Markdown 解析器,仍打包
client-store、Zustand 和 Immer;替换 Web 客户端的组合必须列出这三个 row(升级指南)。 - 仓库代码与外部代码共用一种推荐写法,按包根编写的代码仍能编译和加载。
- 在 Node 中包根只给出 Host 入口,所以运行这些包的浏览器侧代码的测试和工具要 import
/client。 - 解析已配置 row 名的门禁,例如
verify-cordis-config,会落到src/下的 Host 入口src/index.js。 - TypeScript 承诺之所以成立,是因为已发布包的根与
./client共用一个声明文件;消费者检查的负对照表明,如果根 types 换成一个转发到./client的独立文件,混用写法的扩展就会分裂。 - 新的共享运行时代码经 Cordis service、slot 或浏览器安全的工具包提供,不放进这三个包的实体导出。