Skip to content

Commit ae096b1

Browse files
committed
fix(hub): resolve baked statics with their mount resolveFrom
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.
1 parent e140c7a commit ae096b1

4 files changed

Lines changed: 14 additions & 5 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 }[] = []
10+
public buildStaticDirs: { baseUrl: string, source: StaticAssetsSource, resolveFrom?: string | null }[] = []
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 })
33+
this.buildStaticDirs.push({ baseUrl, source, resolveFrom: defaultResolveFrom })
3434
this.context.host.mountStatic(baseUrl, resolved)
3535
}
3636
}

packages/devframe/src/types/views.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import type { StaticAssetsSource } from './remote-assets'
22

33
export interface DevframeViewHost {
44
/**
5+
* Static mounts registered through {@link DevframeViewHost.hostStatic}, each
6+
* carrying the `resolveFrom` base it was mounted with so a build step that
7+
* copies these itself (rather than serving them live) re-resolves a remote
8+
* source to the same locally-installed copy it would serve live.
9+
*
510
* @internal
611
*/
7-
buildStaticDirs: { baseUrl: string, source: StaticAssetsSource }[]
12+
buildStaticDirs: { baseUrl: string, source: StaticAssetsSource, resolveFrom?: string | null }[]
813
/**
914
* Helper to host static files
1015
* - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files

packages/hub/src/node/build.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,15 @@ async function createAndMountContext(options: BuildHubOptions, base: string, cwd
185185
* source by materializing every listed file. Reads the list rather than
186186
* relying on a live host `mountStatic`, so a context whose host copied no
187187
* statics at mount time (the build host, or a kit's) still gets its assets in.
188+
* Each source re-resolves with the `resolveFrom` it was mounted with, so a
189+
* remote source (e.g. a plugin's `--assets` package) resolves to the same
190+
* locally-installed copy it would serve live.
188191
*/
189192
async function copyBuildStatics(ctx: DevframeHubContext, resolveOutPath: (urlBase: string) => string): Promise<void> {
190193
const storageDir = ctx.host.getStorageDir('project')
191-
for (const { baseUrl, source } of ctx.views.buildStaticDirs) {
194+
for (const { baseUrl, source, resolveFrom } of ctx.views.buildStaticDirs) {
192195
const target = resolveOutPath(baseUrl)
193-
const resolved = resolveStaticAssetsSource(source, storageDir)
196+
const resolved = resolveStaticAssetsSource(source, storageDir, resolveFrom)
194197
await fs.mkdir(dirname(target), { recursive: true })
195198
if (typeof resolved === 'string')
196199
await fs.cp(resolved, target, { recursive: true })

tests/__snapshots__/tsnapi/devframe/index.snapshot.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export interface DevframeViewHost {
367367
buildStaticDirs: {
368368
baseUrl: string;
369369
source: StaticAssetsSource;
370+
resolveFrom?: string | null;
370371
}[];
371372
hostStatic: (_: string, _: StaticAssetsSource, _?: string | null) => void;
372373
}

0 commit comments

Comments
 (0)