fix: serve internal JS from path containing build ID (#2753)
Previously imported chunks were not cached at all. They are now cached properly with immutable cache headers.
This commit is contained in:
+4
-2
@@ -182,9 +182,11 @@ export class Builder implements FreshBuilder {
|
||||
denoJsonPath: denoJson.filePath,
|
||||
});
|
||||
|
||||
const prefix = `/_fresh/js/${BUILD_ID}/`;
|
||||
|
||||
for (let i = 0; i < output.files.length; i++) {
|
||||
const file = output.files[i];
|
||||
const pathname = `/${file.path}`;
|
||||
const pathname = `${prefix}${file.path}`;
|
||||
await buildCache.addProcessedFile(pathname, file.contents, file.hash);
|
||||
}
|
||||
|
||||
@@ -196,7 +198,7 @@ export class Builder implements FreshBuilder {
|
||||
`Missing chunk for ${island.file}#${island.exportName}`,
|
||||
);
|
||||
}
|
||||
buildCache.islands.set(island.name, `/${chunk}`);
|
||||
buildCache.islands.set(island.name, `${prefix}${chunk}`);
|
||||
}
|
||||
|
||||
await buildCache.flush();
|
||||
|
||||
+10
-1
@@ -3,6 +3,7 @@ import * as path from "@std/path";
|
||||
import { Builder } from "./builder.ts";
|
||||
import { App } from "../app.ts";
|
||||
import { RemoteIsland } from "@marvinh-test/fresh-island";
|
||||
import { BUILD_ID } from "../runtime/build_id.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "Builder - chain onTransformStaticFile",
|
||||
@@ -114,7 +115,15 @@ Deno.test({
|
||||
await builder.build(app);
|
||||
|
||||
const code = await Deno.readTextFile(
|
||||
path.join(tmp, "dist", "static", "RemoteIsland.js"),
|
||||
path.join(
|
||||
tmp,
|
||||
"dist",
|
||||
"static",
|
||||
"_fresh",
|
||||
"js",
|
||||
BUILD_ID,
|
||||
"RemoteIsland.js",
|
||||
),
|
||||
);
|
||||
expect(code).toContain('"remote-island"');
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user