Skip to content

Commit dc33087

Browse files
committed
feat(client): 删除 rc.7 宿主的 __DSH_MODULES__ 回退路径
peer 基线已是 ^0.1.2-rc.1(全部 dsh-* peer),最后提供 window.__DSH_MODULES__ 页面全局的宿主是 0.1.0-rc.7,远低于下限, 装不上本插件——回退在受支持宿主上不可达。受支持宿主上 apply() 在 任何懒加载发生前调 setChunkModuleSystem(ctx.modules),moduleSystem() 前两跳(注入变量 + 插件全局 __dshSidebarModuleSystem__)必中。 回退的唯一活消费者是 vitest fixture:installModuleSystem() 原先经 rc.7 全局投递 fake 模块系统,现改为与生产同路径的 setChunkModuleSystem 注入;无任何专测回退分支的用例,全部断言保持不变。 - chunk-loader.ts: 删 moduleSystem() 第三跳,同步头注 / ChunkModuleSystem 接口注中的回退描述 - index.tsx: 删「falls back to the rc.7 global」注释 - README v0.14.0 changelog 与 docs/plans 设计文档中的提及属历史 存档(描述 PR #232 当时的迁移),保留不改 验证:lint / typecheck / build / vitest 119 文件 1243 用例全绿; 真机挂载 lane(钉版 @deepseek-ai/dsh@0.1.2-rc.1 CLI)mount.e2e 全内置 tab sweep(含终端 / editor 懒加载 chunk)通过;lib/*.js 产物中无 __DSH_MODULES__ 残留。
1 parent 8820efd commit dc33087

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

src/client/chunk-loader.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
* arbitrary file names, so the plugin's own host route serves the chunks),
2424
* 2. read the factory from the global registry,
2525
* 3. call it with a require that resolves the platform externals through
26-
* `__DSH_MODULES__.import(spec)` — the seed-word branch, the one part of
27-
* the module system that is stable across versions.
26+
* the injected module system's `import(spec)` (the `ctx.modules` service)
27+
* — the seed-word branch, the one part of the module system that is
28+
* stable across versions.
2829
*
2930
* Caching contract (three layers, each with a failure path):
3031
* - In-memory: one in-flight promise per chunk, memoized until
@@ -90,8 +91,7 @@ const CHUNK_REVALIDATE_TIMEOUT_MS = 5_000
9091
* The client module system surface this loader needs to resolve externals.
9192
* DSH 0.1.0-rc.8 provides it as the `ctx.modules` service (no page global
9293
* anymore); the plugin injects it at activation via
93-
* {@link setChunkModuleSystem}. The rc.7-era `window.__DSH_MODULES__` global
94-
* remains as a fallback so older hosts and the test harness keep working.
94+
* {@link setChunkModuleSystem}.
9595
*/
9696
export interface ChunkModuleSystem {
9797
import(specifier: string): Promise<unknown>
@@ -123,12 +123,11 @@ export function setChunkModuleSystem(system: ChunkModuleSystem | undefined): voi
123123
}
124124

125125
/** Resolve the shell-installed module system (injected, then the plugin
126-
* global shared with chunk-bundle copies, then the rc.7 page global). */
126+
* global shared with chunk-bundle copies). */
127127
function moduleSystem(): ChunkModuleSystem | undefined {
128128
const g = globalThis as Record<string, unknown>
129129
return injectedModuleSystem
130130
?? g[MODULE_SYSTEM_GLOBAL] as ChunkModuleSystem | undefined
131-
?? (g as { __DSH_MODULES__?: ChunkModuleSystem }).__DSH_MODULES__
132131
}
133132

134133
/** The plugin-owned chunk factory registry the chunk scripts populate. */

src/client/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ export function apply(ctx: Context): void {
188188
}
189189
}
190190
try {
191-
// rc.8+ exposes the client module system as the `ctx.modules` service
192-
// (no window.__DSH_MODULES__ page global anymore); the chunk loader needs
193-
// it to resolve its externals, so inject it before anything can load a
194-
// lazy chunk. The loader falls back to the rc.7 global when absent.
191+
// rc.8+ exposes the client module system as the `ctx.modules` service;
192+
// the chunk loader needs it to resolve its externals, so inject it
193+
// before anything can load a lazy chunk.
195194
setChunkModuleSystem(ctx.modules)
196195
// Fresh chunk state for this activation: drop per-test fixtures and
197196
// revalidate loaded chunk scripts against the bundle route's ETags —

tests/chunk-loader.spec.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* - externals resolve through the module system's seed branch (the stable,
99
* version-independent part), once per page,
1010
* - resetChunks drops the cache and the externals memo (HMR).
11-
* The production path runs against a fake `window.__DSH_MODULES__` and a
12-
* stub script loader that simulates the executed chunk script by assigning
13-
* the plugin-owned global factory registry.
11+
* The production path runs against a fake module system injected via
12+
* {@link setChunkModuleSystem} (mirroring the client half's `ctx.modules`
13+
* injection) and a stub script loader that simulates the executed chunk
14+
* script by assigning the plugin-owned global factory registry.
1415
*/
1516
import { beforeEach, describe, expect, it, vi } from 'vitest'
1617
import './browser-globals.ts'
@@ -33,14 +34,10 @@ function installModuleSystem(): FakeModuleSystem {
3334
const fake: FakeModuleSystem = {
3435
import: vi.fn(async (specifier: string) => ({ seed: specifier })),
3536
}
36-
;(globalThis as Record<string, unknown>).__DSH_MODULES__ = fake
37+
setChunkModuleSystem(fake)
3738
return fake
3839
}
3940

40-
function removeModuleSystem(): void {
41-
delete (globalThis as Record<string, unknown>).__DSH_MODULES__
42-
}
43-
4441
/** Simulate a chunk script executing: it assigns its factory to the registry. */
4542
function simulateScript(name: string, factory: (require: (spec: string) => unknown) => ChunkExports): void {
4643
const g = globalThis as { __dshChunks__?: Record<string, unknown> }
@@ -49,7 +46,6 @@ function simulateScript(name: string, factory: (require: (spec: string) => unkno
4946
}
5047

5148
beforeEach(() => {
52-
removeModuleSystem()
5349
setChunkModuleSystem(undefined)
5450
delete (globalThis as Record<string, unknown>).__dshChunks__
5551
resetChunks()
@@ -89,9 +85,6 @@ describe('test-registry path (vitest / jsdom-less environments)', () => {
8985
describe('production path (script injection + global registry + externals require)', () => {
9086
it('resolves externals through an injected ctx.modules system (rc.8 — no page global)', async () => {
9187
const modules = installModuleSystem()
92-
// rc.8 drops window.__DSH_MODULES__; the client half injects ctx.modules.
93-
removeModuleSystem()
94-
setChunkModuleSystem(modules)
9588
const loaded: string[] = []
9689
setChunkScriptLoaderForTests(async (src) => {
9790
loaded.push(src)

0 commit comments

Comments
 (0)