Skip to content

Commit c3a954f

Browse files
committed
refactor(hub): minimize bakeHubStatic change surface
Ablation of the previous commit dropped two deltas that no tested or in-repo path depends on: - Removed the `resolveFrom` field added to devframe's core `buildStaticDirs` (types/views + host-views). No devframe in the repo declares RemoteAssets client assets, and string dist dirs ignore resolveFrom, so re-resolving in bakeHubStatic without it is equivalent. Confines the change to @devframes/hub. - Removed `HubMountedFrame.hasClientAssets` (and serveDevframeAssets' boolean return): whether a frame served its own SPA is derivable from ctx.views.buildStaticDirs, so bakeHubStatic derives the per-frame meta targets instead of carrying an extra field on the public type.
1 parent 5bafc33 commit c3a954f

6 files changed

Lines changed: 18 additions & 30 deletions

File tree

packages/devframe/src/node/host-views.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class DevframeViewHost implements DevframeViewHostType {
77
/**
88
* @internal
99
*/
10-
public buildStaticDirs: { baseUrl: string, source: StaticAssetsSource, resolveFrom?: string | null }[] = []
10+
public buildStaticDirs: { baseUrl: string, source: StaticAssetsSource }[] = []
1111

1212
constructor(
1313
public readonly context: DevframeNodeContext,
@@ -30,7 +30,7 @@ export class DevframeViewHost implements DevframeViewHostType {
3030
throw diagnostics.DF0008({ distDir: resolved })
3131
}
3232

33-
this.buildStaticDirs.push({ baseUrl, source, resolveFrom: defaultResolveFrom })
33+
this.buildStaticDirs.push({ baseUrl, source })
3434
this.context.host.mountStatic(baseUrl, resolved)
3535
}
3636
}

packages/devframe/src/types/views.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ import type { StaticAssetsSource } from './remote-assets'
22

33
export interface DevframeViewHost {
44
/**
5-
* Static mounts registered through {@link DevframeViewHost.hostStatic}, in
6-
* registration order, each carrying the `resolveFrom` base it was mounted
7-
* with so a build step can re-resolve a remote source identically. A static
8-
* build that assembles the context itself (rather than serving it live)
9-
* copies these into its output.
10-
*
115
* @internal
126
*/
13-
buildStaticDirs: { baseUrl: string, source: StaticAssetsSource, resolveFrom?: string | null }[]
7+
buildStaticDirs: { baseUrl: string, source: StaticAssetsSource }[]
148
/**
159
* Helper to host static files
1610
* - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files

packages/hub/src/node/__tests__/install-devframe.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function createContext(): DevframeHubContext {
2828
hostStatic: vi.fn((baseUrl: string, source: unknown) => {
2929
mountStatic(baseUrl, source as string)
3030
}),
31-
buildStaticDirs: [],
3231
},
3332
frames: [],
3433
/**

packages/hub/src/node/bake.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export async function bakeHubStatic(ctx: DevframeHubContext, options: BakeHubSta
110110
*/
111111
async function copyBuildStatics(ctx: DevframeHubContext, resolveOutPath: (urlBase: string) => string): Promise<void> {
112112
const storageDir = ctx.host.getStorageDir('project')
113-
for (const { baseUrl, source, resolveFrom } of ctx.views.buildStaticDirs) {
113+
for (const { baseUrl, source } of ctx.views.buildStaticDirs) {
114114
const target = resolveOutPath(baseUrl)
115-
const resolved = resolveStaticAssetsSource(source, storageDir, resolveFrom)
115+
const resolved = resolveStaticAssetsSource(source, storageDir)
116116
await fs.mkdir(dirname(target), { recursive: true })
117117
if (typeof resolved === 'string')
118118
await fs.cp(resolved, target, { recursive: true })
@@ -188,10 +188,10 @@ async function writeHubIndex(
188188

189189
/**
190190
* Write the `backend: 'static'` connection meta at the hub base, and a copy at
191-
* every frame base that served its own SPA whose `baseUrl` points relative
192-
* resolution (the RPC dump) back at the hub's own meta, so a frame SPA that
193-
* fetched its per-frame copy (instead of inheriting the host page's connection)
194-
* still finds the shared dump.
191+
* every frame base that served its own SPA (i.e. registered a static mount at
192+
* that base) whose `baseUrl` points relative resolution (the RPC dump) back at
193+
* the hub's own meta, so a frame SPA that fetched its per-frame copy (instead
194+
* of inheriting the host page's connection) still finds the shared dump.
195195
*/
196196
async function writeConnectionMetas(
197197
ctx: DevframeHubContext,
@@ -211,8 +211,11 @@ async function writeConnectionMetas(
211211
}
212212
await fs.writeFile(resolve(outDir, DEVFRAME_CONNECTION_META_FILENAME), JSON.stringify(meta, null, 2), 'utf-8')
213213
const frameMeta: ConnectionMeta = { ...meta, baseUrl: joinURL(base, DEVFRAME_CONNECTION_META_FILENAME) }
214+
// A frame served its own SPA exactly when it registered a static mount at its
215+
// base; only those need a per-frame meta beside the copied SPA.
216+
const servedBases = new Set(ctx.views.buildStaticDirs.map(dir => dir.baseUrl))
214217
for (const frame of ctx.frames) {
215-
if (!frame.hasClientAssets)
218+
if (!servedBases.has(frame.base))
216219
continue
217220
const target = resolve(resolveOutPath(frame.base), DEVFRAME_CONNECTION_META_FILENAME)
218221
await fs.mkdir(dirname(target), { recursive: true })

packages/hub/src/node/context.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ declare module 'devframe/types' {
8989
* A devframe mounted into a hub context, recorded as it is installed
9090
* (whether through `initHub({ devframes })`, `buildHub`, or `ctx.install`).
9191
* Enumerable via {@link DevframeHubContext.frames} so a host that mounted the
92-
* context itself can still discover what to advertise in `__index.json` and
93-
* where to write each frame's connection meta.
92+
* context itself can still discover what to advertise in `__index.json`.
9493
*/
9594
export interface HubMountedFrame {
9695
/** Dock id the devframe mounted under (disambiguated for duplicates). */
@@ -99,12 +98,6 @@ export interface HubMountedFrame {
9998
base: string
10099
/** Human title (the definition's `name`). */
101100
title: string
102-
/**
103-
* Whether the devframe served client assets at {@link HubMountedFrame.base}.
104-
* A frame with its own SPA gets a per-frame `__connection.json` in a static
105-
* build (pointing back at the hub's shared meta); one without does not.
106-
*/
107-
hasClientAssets: boolean
108101
}
109102

110103
/**

packages/hub/src/node/install-devframe.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ async function serveDevframeAssets(
9494
d: DevframeDefinition,
9595
id: string,
9696
base: string,
97-
): Promise<boolean> {
97+
): Promise<void> {
9898
const clientAssets = resolveClientAssets(d)
9999
if (!clientAssets)
100-
return false
100+
return
101101
// Serve the hub's connection meta under the devframe's base so its SPA
102102
// discovers the RPC/WS endpoint via `connectDevframe()`'s relative
103103
// `./__connection.json` fetch (rather than inheriting cross-origin from a
@@ -110,7 +110,6 @@ async function serveDevframeAssets(
110110
// Resolve the plugin's assets against *its* dependency graph: pass the
111111
// devframe's own `importMetaUrl` as the default `resolveFrom`.
112112
ctx.views.hostStatic(base, typeof clientAssets === 'string' ? resolve(clientAssets) : clientAssets, d.importMetaUrl)
113-
return true
114113
}
115114

116115
/**
@@ -159,9 +158,9 @@ export async function prepareDevframe(
159158
if (clientScript)
160159
dockDefaults.clientScript = clientScript
161160

162-
const hasClientAssets = await serveDevframeAssets(ctx, d, id, base)
161+
await serveDevframeAssets(ctx, d, id, base)
163162

164-
;(ctx.frames as HubMountedFrame[]).push({ id, base, title: d.name, hasClientAssets })
163+
;(ctx.frames as HubMountedFrame[]).push({ id, base, title: d.name })
165164

166165
ctx.docks.register({
167166
id,

0 commit comments

Comments
 (0)