fix: plugins not loaded with legacy dev (#1764)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
42dc54500c
commit
ec2f785455
@@ -12,15 +12,13 @@ import { startFromContext } from "../server/boot.ts";
|
|||||||
export async function dev(
|
export async function dev(
|
||||||
base: string,
|
base: string,
|
||||||
entrypoint: string,
|
entrypoint: string,
|
||||||
options: FreshOptions = {},
|
options?: FreshOptions,
|
||||||
) {
|
) {
|
||||||
ensureMinDenoVersion();
|
ensureMinDenoVersion();
|
||||||
|
|
||||||
// Run update check in background
|
// Run update check in background
|
||||||
updateCheck(DAY).catch(() => {});
|
updateCheck(DAY).catch(() => {});
|
||||||
|
|
||||||
entrypoint = new URL(entrypoint, base).href;
|
|
||||||
|
|
||||||
const dir = dirname(fromFileUrl(base));
|
const dir = dirname(fromFileUrl(base));
|
||||||
|
|
||||||
let currentManifest: Manifest;
|
let currentManifest: Manifest;
|
||||||
@@ -54,13 +52,15 @@ export async function dev(
|
|||||||
if (isBuild) {
|
if (isBuild) {
|
||||||
// Ensure that build dir is empty
|
// Ensure that build dir is empty
|
||||||
await fs.emptyDir(outDir);
|
await fs.emptyDir(outDir);
|
||||||
await build(join(dir, "fresh.gen.ts"), options);
|
await build(join(dir, "fresh.gen.ts"), options ?? {});
|
||||||
} else if (options) {
|
} else if (options) {
|
||||||
await startFromContext(ctx, options);
|
await startFromContext(ctx, options);
|
||||||
} else {
|
} else {
|
||||||
// Legacy entry point: Back then `dev.ts` would call `main.ts` but
|
// Legacy entry point: Back then `dev.ts` would call `main.ts` but
|
||||||
// this causes duplicate plugin instantiation if both `dev.ts` and
|
// this causes duplicate plugin instantiation if both `dev.ts` and
|
||||||
// `main.ts` instantiate plugins.
|
// `main.ts` instantiate plugins.
|
||||||
|
Deno.env.set("__FRSH_LEGACY_DEV", "true");
|
||||||
|
entrypoint = new URL(entrypoint, base).href;
|
||||||
await import(entrypoint);
|
await import(entrypoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,7 +165,11 @@ export class ServerContext {
|
|||||||
// Restore snapshot if available
|
// Restore snapshot if available
|
||||||
let snapshot: BuildSnapshot | null = null;
|
let snapshot: BuildSnapshot | null = null;
|
||||||
// Load from snapshot if not explicitly requested not to
|
// Load from snapshot if not explicitly requested not to
|
||||||
const loadFromSnapshot = !opts.skipSnapshot;
|
let loadFromSnapshot = !opts.skipSnapshot;
|
||||||
|
// We still need to check for a legacy entry point :S
|
||||||
|
if (Deno.env.has("__FRSH_LEGACY_DEV")) {
|
||||||
|
loadFromSnapshot = false;
|
||||||
|
}
|
||||||
if (loadFromSnapshot) {
|
if (loadFromSnapshot) {
|
||||||
const snapshotDirPath = join(
|
const snapshotDirPath = join(
|
||||||
dirname(fromFileUrl(manifest.baseUrl)),
|
dirname(fromFileUrl(manifest.baseUrl)),
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { waitForStyle, withPageName } from "$fresh/tests/test_utils.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "dev_command config",
|
||||||
|
async fn() {
|
||||||
|
await withPageName(
|
||||||
|
"./tests/fixture_dev_config/main.ts",
|
||||||
|
async (page, address) => {
|
||||||
|
await page.goto(`${address}`);
|
||||||
|
await waitForStyle(page, "h1", "color", "rgb(220, 38, 38)");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "dev_command legacy",
|
||||||
|
async fn() {
|
||||||
|
await withPageName(
|
||||||
|
"./tests/fixture_dev_legacy/main.ts",
|
||||||
|
async (page, address) => {
|
||||||
|
await page.goto(`${address}`);
|
||||||
|
await waitForStyle(page, "h1", "color", "rgb(220, 38, 38)");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { dev } from "$fresh/src/dev/dev_command.ts";
|
||||||
|
import config from "./fresh.config.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts", config);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { defineConfig } from "$fresh/server.ts";
|
||||||
|
import twind from "$fresh/plugins/twind.ts";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [twind({
|
||||||
|
selfURL: import.meta.url,
|
||||||
|
})],
|
||||||
|
});
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// DO NOT EDIT. This file is generated by Fresh.
|
||||||
|
// This file SHOULD be checked into source version control.
|
||||||
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import * as $0 from "./routes/index.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/index.tsx": $0,
|
||||||
|
},
|
||||||
|
islands: {},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/// <reference no-default-lib="true" />
|
||||||
|
/// <reference lib="dom" />
|
||||||
|
/// <reference lib="dom.iterable" />
|
||||||
|
/// <reference lib="dom.asynciterable" />
|
||||||
|
/// <reference lib="deno.ns" />
|
||||||
|
|
||||||
|
import { start } from "$fresh/server.ts";
|
||||||
|
import manifest from "./fresh.gen.ts";
|
||||||
|
import config from "./fresh.config.ts";
|
||||||
|
|
||||||
|
await start(manifest, config);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Page() {
|
||||||
|
return <h1 class="text-red-600">check color</h1>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { dev } from "$fresh/src/dev/dev_command.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts");
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// DO NOT EDIT. This file is generated by Fresh.
|
||||||
|
// This file SHOULD be checked into source version control.
|
||||||
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import * as $0 from "./routes/index.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/index.tsx": $0,
|
||||||
|
},
|
||||||
|
islands: {},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/// <reference no-default-lib="true" />
|
||||||
|
/// <reference lib="dom" />
|
||||||
|
/// <reference lib="dom.iterable" />
|
||||||
|
/// <reference lib="dom.asynciterable" />
|
||||||
|
/// <reference lib="deno.ns" />
|
||||||
|
|
||||||
|
import { start } from "$fresh/server.ts";
|
||||||
|
import manifest from "./fresh.gen.ts";
|
||||||
|
import twind from "$fresh/plugins/twind.ts";
|
||||||
|
|
||||||
|
await start(manifest, { plugins: [twind({ selfURL: import.meta.url })] });
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Page() {
|
||||||
|
return <h1 class="text-red-600">check color</h1>;
|
||||||
|
}
|
||||||
+2
-2
@@ -59,7 +59,7 @@ Deno.test("/props/123 page prerender", async () => {
|
|||||||
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
|
||||||
const body = await resp.text();
|
const body = await resp.text();
|
||||||
const doc = parseHtml(body);
|
const doc = parseHtml(body);
|
||||||
const data = JSON.parse(doc.querySelector("body > div").textContent);
|
const data = JSON.parse(doc.querySelector("body > div")!.textContent!);
|
||||||
|
|
||||||
assertEquals(data, {
|
assertEquals(data, {
|
||||||
"params": { "id": "123" },
|
"params": { "id": "123" },
|
||||||
@@ -613,7 +613,7 @@ Deno.test({
|
|||||||
|
|
||||||
const body = await resp.text();
|
const body = await resp.text();
|
||||||
const doc = parseHtml(body);
|
const doc = parseHtml(body);
|
||||||
assertEquals(JSON.parse(doc.querySelector("pre").textContent), {
|
assertEquals(JSON.parse(doc.querySelector("pre")!.textContent!), {
|
||||||
handler1: "it works",
|
handler1: "it works",
|
||||||
handler2: "it works",
|
handler2: "it works",
|
||||||
handler3: "it works",
|
handler3: "it works",
|
||||||
|
|||||||
+38
-3
@@ -10,8 +10,9 @@ import {
|
|||||||
TextLineStream,
|
TextLineStream,
|
||||||
} from "./deps.ts";
|
} from "./deps.ts";
|
||||||
|
|
||||||
export function parseHtml(input: string) {
|
export function parseHtml(input: string): Document {
|
||||||
return new DOMParser().parseFromString(input, "text/html");
|
// deno-lint-ignore no-explicit-any
|
||||||
|
return new DOMParser().parseFromString(input, "text/html") as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startFreshServer(options: Deno.CommandOptions) {
|
export async function startFreshServer(options: Deno.CommandOptions) {
|
||||||
@@ -87,7 +88,6 @@ export const VOID_ELEMENTS =
|
|||||||
/^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
/^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
||||||
function prettyDom(doc: Document) {
|
function prettyDom(doc: Document) {
|
||||||
let out = colors.dim(`<!DOCTYPE ${doc.doctype?.name ?? ""}>\n`);
|
let out = colors.dim(`<!DOCTYPE ${doc.doctype?.name ?? ""}>\n`);
|
||||||
console.log(out);
|
|
||||||
|
|
||||||
const node = doc.documentElement;
|
const node = doc.documentElement;
|
||||||
out += _printDomNode(node, 0);
|
out += _printDomNode(node, 0);
|
||||||
@@ -269,6 +269,41 @@ export async function waitForText(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function waitForStyle(
|
||||||
|
page: Page,
|
||||||
|
selector: string,
|
||||||
|
name: keyof CSSStyleDeclaration,
|
||||||
|
value: string,
|
||||||
|
) {
|
||||||
|
await page.waitForSelector(selector);
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
|
let now = start;
|
||||||
|
let found = false;
|
||||||
|
while (now < start + 2000) {
|
||||||
|
found = await page.evaluate(
|
||||||
|
(s, n, v) => {
|
||||||
|
const el = document.querySelector(s);
|
||||||
|
if (!el) return false;
|
||||||
|
return window.getComputedStyle(el)[n] === v;
|
||||||
|
},
|
||||||
|
selector,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (found) break;
|
||||||
|
|
||||||
|
await delay(200);
|
||||||
|
now = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
console.log(prettyDom(parseHtml(await page.content())));
|
||||||
|
throw new Error(`Could not find style ${String(name)}: ${value}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function spawnServer(
|
async function spawnServer(
|
||||||
options: Deno.CommandOptions,
|
options: Deno.CommandOptions,
|
||||||
expectErrors = false,
|
expectErrors = false,
|
||||||
|
|||||||
Reference in New Issue
Block a user