fix: don't fallthrough static files in dev (#2156)
This commit is contained in:
@@ -296,8 +296,15 @@ export async function extractRoutes(
|
|||||||
|
|
||||||
const staticFiles: StaticFile[] = [];
|
const staticFiles: StaticFile[] = [];
|
||||||
try {
|
try {
|
||||||
const outDirStatic = join(config.build.outDir, "static");
|
const staticDirs = [config.staticDir];
|
||||||
for (const staticDir of [config.staticDir, outDirStatic]) {
|
|
||||||
|
// Only fall through to files in /_fresh/static when not in dev
|
||||||
|
if (state.loadSnapshot) {
|
||||||
|
const outDirStatic = join(config.build.outDir, "static");
|
||||||
|
staticDirs.push(outDirStatic);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const staticDir of staticDirs) {
|
||||||
const staticDirUrl = toFileUrl(staticDir);
|
const staticDirUrl = toFileUrl(staticDir);
|
||||||
const entries = walk(staticDir, {
|
const entries = walk(staticDir, {
|
||||||
includeFiles: true,
|
includeFiles: true,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"lock": false,
|
||||||
|
"imports": {
|
||||||
|
"$fresh/": "../../",
|
||||||
|
"preact": "https://esm.sh/preact@10.15.1",
|
||||||
|
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||||
|
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||||
|
|
||||||
|
import dev from "$fresh/dev.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts");
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// 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 $_app from "./routes/_app.tsx";
|
||||||
|
import * as $css from "./routes/css.tsx";
|
||||||
|
import * as $index from "./routes/index.tsx";
|
||||||
|
|
||||||
|
import { type Manifest } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/_app.tsx": $_app,
|
||||||
|
"./routes/css.tsx": $css,
|
||||||
|
"./routes/index.tsx": $index,
|
||||||
|
},
|
||||||
|
islands: {},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
} satisfies Manifest;
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/// <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";
|
||||||
|
|
||||||
|
await start(manifest);
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { PageProps } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export default function App({ Component }: PageProps) {
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>My Fresh app</title>
|
||||||
|
<link rel="stylesheet" href="/style.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<Component />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Page() {
|
||||||
|
return <h1>test</h1>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { basename, dirname, extname, fromFileUrl } from "../../deps.ts";
|
||||||
|
|
||||||
|
const __dirname = dirname(fromFileUrl(import.meta.url));
|
||||||
|
|
||||||
|
const links: string[] = [];
|
||||||
|
for (const file of Deno.readDirSync(__dirname)) {
|
||||||
|
if (file.name.startsWith("index")) continue;
|
||||||
|
const name = basename(file.name, extname(file.name));
|
||||||
|
links.push(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Tests</h1>
|
||||||
|
<ul>
|
||||||
|
{links.sort().map((link) => {
|
||||||
|
return (
|
||||||
|
<li key={link}>
|
||||||
|
<a href={`/${link}`}>{link}</a>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
h1 {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { assertEquals, dirname, fromFileUrl, join } from "./deps.ts";
|
||||||
|
import { withFakeServe } from "./test_utils.ts";
|
||||||
|
|
||||||
|
Deno.test("don't fallthrough to /_fresh/static in dev", async () => {
|
||||||
|
const fixtureDir = join(
|
||||||
|
dirname(fromFileUrl(import.meta.url)),
|
||||||
|
"fixture_static",
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Deno.mkdir(join(fixtureDir, "_fresh", "static"), { recursive: true });
|
||||||
|
} catch (_err) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
await Deno.writeTextFile(
|
||||||
|
join(fixtureDir, "_fresh", "static", "style.css"),
|
||||||
|
"h1 { color: blue; }",
|
||||||
|
);
|
||||||
|
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture_static/dev.ts",
|
||||||
|
async (server) => {
|
||||||
|
const res = await server.get(`/style.css`);
|
||||||
|
const css = await res.text();
|
||||||
|
assertEquals(css.replace(/\s+/g, ""), "h1{color:red;}");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
await Deno.remove(join(fixtureDir, "_fresh", "static", "style.css"));
|
||||||
|
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture_static/dev.ts",
|
||||||
|
async (server) => {
|
||||||
|
const res = await server.get(`/style.css`);
|
||||||
|
const css = await res.text();
|
||||||
|
assertEquals(css.replace(/\s+/g, ""), "h1{color:red;}");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test("fallthrough to /_fresh/static in normal mode", async () => {
|
||||||
|
const fixtureDir = join(
|
||||||
|
dirname(fromFileUrl(import.meta.url)),
|
||||||
|
"fixture_static",
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Deno.mkdir(join(fixtureDir, "_fresh", "static"), { recursive: true });
|
||||||
|
} catch (_err) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
await Deno.writeTextFile(
|
||||||
|
join(fixtureDir, "_fresh", "static", "style.css"),
|
||||||
|
"h1 { color: blue; }",
|
||||||
|
);
|
||||||
|
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture_static/main.ts",
|
||||||
|
async (server) => {
|
||||||
|
const res = await server.get(`/style.css`);
|
||||||
|
const css = await res.text();
|
||||||
|
assertEquals(css.replace(/\s+/g, ""), "h1{color:blue;}");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user