feat(hub): buildHub accpets already-mounted context - #349
Conversation
Extract buildHub's post-mount baker into a public bakeHubStatic(ctx, opts) so a host that assembles and mounts its own hub context (Vite DevTools' kit-augmented context, devframes mounted from Vite plugins) reuses the exact baker instead of reimplementing it and drifting out of sync. - bakeHubStatic bakes an already-mounted DevframeHubContext; buildHub is now createHubContext + mountDevframes + bakeHubStatic. - Enumerate mounted frames via ctx.frames (HubMountedFrame), populated in prepareDevframe, so an externally-mounted context can emit __index.json and per-frame __connection.json. - Materialize statics from ctx.views.buildStaticDirs (each entry now carries its resolveFrom); route page scripts through views.hostStatic so they land there too. - Add a clean opt-out so the baker can write beside an app's own build output.
◈ PR Lens
Architecture 3 components touched across 5 lanes. Inside the changed components — 2 viewsComponent view — Hub static builder Static build pipeline in buildHub that consumes pre-mounted contexts, copies registered static asset directories, and emits static discovery artifacts. Component view — Hub context & frame registration Hub context creation and frame mounting lifecycle that tracks installed devframes in ctx.frames and records static asset directories on the view host. Data flow
Drill down
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
… concept Rather than introduce a new "bake" verb/function, mirror initHub's existing `context` option: buildHub now accepts an already-mounted DevframeHubContext and bakes it (reading ctx.frames + ctx.views.buildStaticDirs), throwing DF8002 if both `context` and `devframes` are passed. The baking helpers fold back into build.ts as module-private functions; the public surface stays just buildHub.
buildHub copies statics from ctx.views.buildStaticDirs, which for a plugin's RemoteAssets client bundle (e.g. @devframes/plugin-a11y--assets) must re-resolve with the plugin's importMetaUrl as resolveFrom to hit the locally-installed copy; without it resolution fell back to a stale CDN back-proxy cache, baking an outdated SPA (surfaced by the a11y summary sticky e2e). Record resolveFrom on each buildStaticDirs entry and pass it through when baking.
Closes #347.
Lets
buildHubreuse its baking pipeline for a context a host assembled and mounted itself (Vite DevTools' kit-augmented context, devframes mounted from Vite plugins), so downstreams stop shadowing the baker and inherit format/behaviour fixes for free.Rather than introduce a new
bakeHubStaticverb/concept, this mirrorsinitHub's existingcontextoption.What
buildHub({ context })— pass an already-mountedDevframeHubContextinstead ofdevframes;buildHubbakes it, readingctx.framesandctx.views.buildStaticDirsfor what to emit. Mutually exclusive withdevframes(throwsDF8002, same asinitHub).configure/ui.setupstill run against it.ctx.frames(HubMountedFrame[], exported from@devframes/hub/node) is populated inprepareDevframe, soctx.install,initHub, andbuildHuball record frames uniformly and the baker can emit__index.json+ per-frame metas for a context it did not mount itself.ctx.views.buildStaticDirs(local dircp, remote sourcematerialize), so a caller-mounted context whose host copied nothing live still gets its assets in. Page scripts route throughviews.hostStaticso they land there too.clean?: boolean(defaulttrue) — setfalseto bake beside an app's own build output.The public surface stays just
buildHub; the baking helpers are module-private inbuild.ts.Notes
The downstream deletion of
vitejs/devtools' hand-rolledpackages/core/src/node/build-static.tslives in that separate repo; this is the upstream half that unblocks it. The change is confined to@devframes/hub(+ docs). ExistingbuildHub/initHubbehaviour is unchanged; added tests cover baking acontext, theclean: falseflag, andctx.frames.This PR was created with the help of an agent.