feat: allow plugins to modify HTML body (#2022)
Based on https://github.com/denoland/fresh/pull/1769 . Mostly added a test. --------- Co-authored-by: Adam Gregory <adam@aguilaengineering.com>
This commit is contained in:
co-authored by
Adam Gregory
parent
14cecc0a6f
commit
7ff2781fcd
+21
-1
@@ -286,6 +286,7 @@ export async function fakeServe(
|
||||
export async function withFakeServe(
|
||||
name: string,
|
||||
cb: (server: FakeServer) => Promise<void> | void,
|
||||
options: { loadConfig?: boolean } = {},
|
||||
) {
|
||||
const fixture = join(Deno.cwd(), name);
|
||||
const dev = basename(name) === "dev.ts";
|
||||
@@ -293,7 +294,26 @@ export async function withFakeServe(
|
||||
const manifestPath = toFileUrl(join(dirname(fixture), "fresh.gen.ts")).href;
|
||||
const manifestMod = await import(manifestPath);
|
||||
|
||||
const server = await fakeServe(manifestMod.default, { dev });
|
||||
const configPath = join(dirname(fixture), "fresh.config.ts");
|
||||
|
||||
let config = { dev };
|
||||
|
||||
// For now we load config on a case by case basis, because something in
|
||||
// twind (unsure) doesn't work well if multiple instances are running
|
||||
if (options.loadConfig) {
|
||||
try {
|
||||
const stats = await Deno.stat(configPath);
|
||||
if (stats.isFile) {
|
||||
const m = await import(toFileUrl(configPath).href);
|
||||
config = m.default;
|
||||
config.dev = dev;
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const server = await fakeServe(manifestMod.default, config);
|
||||
await cb(server);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user