Skip to content

Commit 311cf95

Browse files
antfubotopencode
andcommitted
example(hubs): add public/ asset fixtures and wire the Assets dock into both hubs
The Assets tab now works end-to-end in both hub examples: - vite-devframe-hub: already mounts the default assets devframe (manages <cwd>/public, served by Vite at /). Added a public/ fixture set so the tab has real content and previews resolve to Vite own URLs. - next-devframe-hub: mount the assets devframe with its dir pointed at the Next app public/ (src/client/public — what Next serves at /) so previews resolve to real host URLs. Loaded via the same bundler-ignored dynamic import as the other built-in plugins; the dir is derived with string path ops on import.meta.url (not new URL(), which Turbopack tries to resolve as an asset). Added the matching public/ fixtures + dep + turbo build edge, and a dock-registration assertion in its test. To keep the Next hub own booting test (and any short-lived host) from leaving a background file watcher running, add a watch boolean option to createAssetsDevframe (default true) and mount it with watch:false in the Next hub. Vite hub keeps live-refresh on. Co-authored-by: opencode <noreply@opencode.ai>
1 parent d4a09d9 commit 311cf95

27 files changed

Lines changed: 144 additions & 3 deletions

File tree

‎examples/next-devframe-hub/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@devframes/json-render": "workspace:*",
1717
"@devframes/next": "workspace:*",
1818
"@devframes/plugin-a11y": "workspace:*",
19+
"@devframes/plugin-assets": "workspace:*",
1920
"@devframes/plugin-code-server": "workspace:*",
2021
"@devframes/plugin-git": "workspace:*",
2122
"@devframes/plugin-inspect": "workspace:*",

‎examples/next-devframe-hub/src/client/devframe/next-devframe-hub.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { StartedServer } from 'devframe/node'
44
import type { ConnectionMeta, DevframeDefinition } from 'devframe/types'
55
import { homedir } from 'node:os'
66
import process from 'node:process'
7+
import { fileURLToPath } from 'node:url'
78
import { defineHubRpcFunction } from '@devframes/hub'
89
import { createHubContext, mountDevframe } from '@devframes/hub/node'
910
import { toJsonRenderDockEntry } from '@devframes/json-render/hub'
@@ -45,6 +46,24 @@ async function loadBuiltinPlugins(): Promise<DevframeDefinition[]> {
4546
return mods.map(mod => mod.default as DevframeDefinition)
4647
}
4748

49+
/**
50+
* Load the assets plugin and point its managed directory at this Next app's
51+
* `public/` (`src/client/public`) — the exact directory Next serves at `/`,
52+
* so the tab's previews resolve to real host URLs. Loaded through the same
53+
* bundler-ignored dynamic `import()` as the other plugins (its node code and
54+
* `import.meta.url`-based SPA-dist lookup don't survive static bundling), and
55+
* mounted with `watch: false` so no background file watcher lingers when the
56+
* hub is booted in a short-lived context (e.g. the example's own test).
57+
*/
58+
async function loadAssetsDevframe(): Promise<DevframeDefinition> {
59+
const mod = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ '@devframes/plugin-assets')
60+
// String path ops on the module path (not `new URL('../public', …)`, which
61+
// Turbopack eagerly resolves as an asset import and fails on a directory) —
62+
// `src/client/devframe/` → `src/client/public`, the dir Next serves at `/`.
63+
const dir = join(dirname(fileURLToPath(import.meta.url)), '../public')
64+
return (mod.createAssetsDevframe as (options: { dir: string, watch: boolean }) => DevframeDefinition)({ dir, watch: false })
65+
}
66+
4867
/** URL base the a11y agent module is served under (same-origin, catch-all route). */
4968
const A11Y_AGENT_MOUNT_BASE = '/__df-a11y-agent/'
5069

@@ -190,7 +209,7 @@ export async function nextDevframeHub(
190209

191210
// Demo devframes alongside the dogfooded built-in plugin packages.
192211
const devframes = options.devframes
193-
?? [demoDevframe, demoDevframeB, ...await loadBuiltinPlugins()]
212+
?? [demoDevframe, demoDevframeB, ...await loadBuiltinPlugins(), await loadAssetsDevframe()]
194213

195214
await context.messages.add({
196215
level: 'success',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Next hub assets
2+
3+
These files live in the Next app's `public/` directory (`src/client/public`),
4+
served by Next at the site root (`/`). The **Assets** dock is mounted with its
5+
`dir` pointed here, so previews load from Next's real URLs (`/logo.svg`,
6+
`/images/…`) and write actions round-trip to disk.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Devframe Assets",
3+
"description": "Sample fixtures for the assets plugin dev server.",
4+
"theme": {
5+
"primary": "#3a6a45",
6+
"surface": "#ffffff"
7+
},
8+
"nav": [
9+
{ "label": "Home", "href": "/" },
10+
{ "label": "Docs", "href": "/docs" }
11+
]
12+
}
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading
222 Bytes
Loading
293 Bytes
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Allow: /

0 commit comments

Comments
 (0)