fix: code frame not showing up in dev mode (#1814)

This commit is contained in:
Marvin Hagemeister
2023-09-24 11:26:47 +02:00
committed by GitHub
parent 738a51ad52
commit 3604c224ce
8 changed files with 47 additions and 19 deletions
+1 -2
View File
@@ -1,4 +1,3 @@
import { DEV_MODE } from "./constants.ts";
import { dirname, fromFileUrl, isAbsolute, join, JSONC } from "./deps.ts";
import { FromManifestOptions, Manifest } from "./mod.ts";
import { DenoConfig, InternalFreshOptions } from "./types.ts";
@@ -55,7 +54,7 @@ export async function getFreshConfigWithDefaults(
loadSnapshot: typeof opts.skipSnapshot === "boolean"
? !opts.skipSnapshot
: false,
dev: opts.dev ?? DEV_MODE,
dev: opts.dev ?? false,
denoJsonPath,
denoJson,
manifest,
-5
View File
@@ -9,8 +9,3 @@ export const DEBUG = !Deno.env.get("DENO_DEPLOYMENT_ID");
export function bundleAssetUrl(path: string) {
return `${INTERNAL_PREFIX}${JS_PREFIX}/${BUILD_ID}${path}`;
}
export let DEV_MODE = false;
export function setDevMode(value: boolean) {
DEV_MODE = value;
}
+2 -8
View File
@@ -10,12 +10,7 @@ import {
import { ComponentType, h } from "preact";
import * as router from "./router.ts";
import { Manifest } from "./mod.ts";
import {
ALIVE_URL,
JS_PREFIX,
REFRESH_JS_URL,
setDevMode,
} from "./constants.ts";
import { ALIVE_URL, JS_PREFIX, REFRESH_JS_URL } from "./constants.ts";
import { BUILD_ID, setBuildId } from "./build_id.ts";
import DefaultErrorHandler from "./default_error_page.tsx";
import {
@@ -450,9 +445,8 @@ export class ServerContext {
opts: FromManifestOptions,
): Promise<ServerContext> {
const isLegacyDev = Deno.env.get("__FRSH_LEGACY_DEV") === "true";
const dev = isLegacyDev ||
opts.dev = isLegacyDev ||
Boolean(opts.dev);
setDevMode(dev);
if (isLegacyDev) {
opts.skipSnapshot = true;
+28
View File
@@ -25,6 +25,20 @@ Deno.test({
},
});
Deno.test({
name: "dev_command config: shows codeframe",
async fn() {
await withFakeServe(
"./tests/fixture_dev_config/dev.ts",
async (server) => {
const doc = await server.getHtml("/codeframe");
assertSelector(doc, ".frsh-error-page");
assertSelector(doc, ".code-frame");
},
);
},
});
Deno.test({
name: "dev_command legacy",
async fn() {
@@ -38,6 +52,20 @@ Deno.test({
},
});
Deno.test({
name: "dev_command legacy: shows codeframe",
async fn() {
await withFakeServe(
"./tests/fixture_dev_legacy/dev.ts",
async (server) => {
const doc = await server.getHtml("/codeframe");
assertSelector(doc, ".frsh-error-page");
assertSelector(doc, ".code-frame");
},
);
},
});
Deno.test("adds refresh script to html", async () => {
await withFakeServe("./tests/fixture/dev.ts", async (server) => {
const doc = await server.getHtml("/");
+4 -2
View File
@@ -2,11 +2,13 @@
// 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";
import * as $0 from "./routes/codeframe.tsx";
import * as $1 from "./routes/index.tsx";
const manifest = {
routes: {
"./routes/index.tsx": $0,
"./routes/codeframe.tsx": $0,
"./routes/index.tsx": $1,
},
islands: {},
baseUrl: import.meta.url,
@@ -0,0 +1,4 @@
// deno-lint-ignore no-explicit-any
export default function Page(): any {
throw new Error("fail");
}
+4 -2
View File
@@ -2,11 +2,13 @@
// 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";
import * as $0 from "./routes/codeframe.tsx";
import * as $1 from "./routes/index.tsx";
const manifest = {
routes: {
"./routes/index.tsx": $0,
"./routes/codeframe.tsx": $0,
"./routes/index.tsx": $1,
},
islands: {},
baseUrl: import.meta.url,
@@ -0,0 +1,4 @@
// deno-lint-ignore no-explicit-any
export default function Page(): any {
throw new Error("fail");
}