fix: incorrect snapshot path with non-standard src directory (#1768)
This commit is contained in:
@@ -167,7 +167,10 @@ export class ServerContext {
|
|||||||
// Load from snapshot if not explicitly requested not to
|
// Load from snapshot if not explicitly requested not to
|
||||||
const loadFromSnapshot = !opts.skipSnapshot;
|
const loadFromSnapshot = !opts.skipSnapshot;
|
||||||
if (loadFromSnapshot) {
|
if (loadFromSnapshot) {
|
||||||
const snapshotDirPath = join(dirname(configPath), "_fresh");
|
const snapshotDirPath = join(
|
||||||
|
dirname(fromFileUrl(manifest.baseUrl)),
|
||||||
|
"_fresh",
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
if ((await Deno.stat(snapshotDirPath)).isDirectory) {
|
if ((await Deno.stat(snapshotDirPath)).isDirectory) {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
+23
-7
@@ -6,9 +6,12 @@ import { BuildSnapshotJson } from "$fresh/src/build/mod.ts";
|
|||||||
import { assertStringIncludes } from "$std/testing/asserts.ts";
|
import { assertStringIncludes } from "$std/testing/asserts.ts";
|
||||||
import { assertNotMatch } from "$std/testing/asserts.ts";
|
import { assertNotMatch } from "$std/testing/asserts.ts";
|
||||||
|
|
||||||
Deno.test("build snapshot and restore from it", async (t) => {
|
async function testBuild(
|
||||||
const fixture = path.join(Deno.cwd(), "tests", "fixture_build");
|
t: Deno.TestContext,
|
||||||
const outDir = path.join(fixture, "_fresh");
|
fixture: string,
|
||||||
|
subDirPath = "",
|
||||||
|
) {
|
||||||
|
const outDir = path.join(fixture, subDirPath, "_fresh");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await t.step("build snapshot", async () => {
|
await t.step("build snapshot", async () => {
|
||||||
@@ -16,7 +19,7 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
|||||||
args: [
|
args: [
|
||||||
"run",
|
"run",
|
||||||
"-A",
|
"-A",
|
||||||
path.join(fixture, "dev.ts"),
|
path.join(fixture, subDirPath, "dev.ts"),
|
||||||
"build",
|
"build",
|
||||||
],
|
],
|
||||||
env: {
|
env: {
|
||||||
@@ -70,7 +73,7 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
|||||||
args: [
|
args: [
|
||||||
"run",
|
"run",
|
||||||
"-A",
|
"-A",
|
||||||
path.join(fixture, "./main.ts"),
|
path.join(fixture, subDirPath, "main.ts"),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -123,7 +126,7 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
|||||||
args: [
|
args: [
|
||||||
"run",
|
"run",
|
||||||
"-A",
|
"-A",
|
||||||
path.join(fixture, "./dev.ts"),
|
path.join(fixture, subDirPath, "dev.ts"),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -140,6 +143,19 @@ Deno.test("build snapshot and restore from it", async (t) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await Deno.remove(path.join(fixture, "_fresh"), { recursive: true });
|
await Deno.remove(path.join(fixture, subDirPath, "_fresh"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Deno.test("build snapshot and restore from it", async (t) => {
|
||||||
|
// Note: If you change the fixture_build directory, you must also update fixture_build_sub_dir
|
||||||
|
const fixture = path.join(Deno.cwd(), "tests", "fixture_build");
|
||||||
|
await testBuild(t, fixture);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test("build snapshot and restore from it when has sub dirs", async (t) => {
|
||||||
|
const fixture = path.join(Deno.cwd(), "tests", "fixture_build_sub_dir");
|
||||||
|
await testBuild(t, fixture, "src");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"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.0",
|
||||||
|
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||||
|
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||||
|
},
|
||||||
|
"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,18 @@
|
|||||||
|
// 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";
|
||||||
|
import * as $$0 from "./islands/Counter.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/index.tsx": $0,
|
||||||
|
},
|
||||||
|
islands: {
|
||||||
|
"./islands/Counter.tsx": $$0,
|
||||||
|
},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import type { Signal } from "@preact/signals";
|
||||||
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
interface CounterProps {
|
||||||
|
count: Signal<number>;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Counter(props: CounterProps) {
|
||||||
|
return (
|
||||||
|
<div id={props.id}>
|
||||||
|
<p>{props.count}</p>
|
||||||
|
<button
|
||||||
|
id={`b-${props.id}`}
|
||||||
|
onClick={() => props.count.value += 1}
|
||||||
|
disabled={!IS_BROWSER}
|
||||||
|
>
|
||||||
|
+1
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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 routes from "./fresh.gen.ts";
|
||||||
|
|
||||||
|
await start(routes);
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { useSignal } from "@preact/signals";
|
||||||
|
import Counter from "../islands/Counter.tsx";
|
||||||
|
import { asset, Head } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
const signal = useSignal(0);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Head>
|
||||||
|
<link rel="stylesheet" href={asset("/style.css")} />
|
||||||
|
</Head>
|
||||||
|
<Counter id="counter" count={signal} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
body {
|
||||||
|
background: peachpuff;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user