fix: add deno compile entry (#3189)

Fixes https://github.com/denoland/fresh/issues/3123
This commit is contained in:
Marvin Hagemeister
2025-08-05 14:53:08 +02:00
committed by GitHub
parent 2f76a0a2aa
commit 71b7d922ea
6 changed files with 129 additions and 16 deletions
+86 -7
View File
@@ -5,7 +5,10 @@ import { App } from "../app.ts";
import { DEV_ERROR_OVERLAY_URL } from "../constants.ts";
import { BUILD_ID } from "../runtime/build_id.ts";
import { withTmpDir, writeFiles } from "../test_utils.ts";
import { withChildProcessServer } from "../../tests/test_utils.tsx";
import {
getStdOutput,
withChildProcessServer,
} from "../../tests/test_utils.tsx";
Deno.test({
name: "Builder - chain onTransformStaticFile",
@@ -299,8 +302,7 @@ export const app = new App().fsRoutes()`,
let text = "fail";
await withChildProcessServer(
tmp,
["serve", "-A", "dist/server.js"],
{ cwd: tmp, args: ["serve", "-A", "dist/server.js"] },
async (address) => {
const res = await fetch(`${address}/foo`);
text = await res.text();
@@ -340,8 +342,7 @@ export const app = new App().fsRoutes()`,
let text = "fail";
await withChildProcessServer(
tmp,
["serve", "-A", "dist/server.js"],
{ cwd: tmp, args: ["serve", "-A", "dist/server.js"] },
async (address) => {
const res = await fetch(address);
text = await res.text();
@@ -456,8 +457,7 @@ export const app = new App().fsRoutes()`,
let text = "fail";
await withChildProcessServer(
tmp,
["serve", "-A", "dist/server.js"],
{ cwd: tmp, args: ["serve", "-A", "dist/server.js"] },
async (address) => {
const res = await fetch(address);
text = await res.text();
@@ -527,6 +527,85 @@ export const app = new App().fsRoutes()`,
sanitizeResources: false,
});
Deno.test({
name: "Builder - compile entry",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
await using _outDir = await withTmpDir();
const tmp = _tmp.dir;
await writeFiles(tmp, {
"deno.json": JSON.stringify({
links: [path.relative(tmp, root)],
workspace: [],
compilerOptions: {
jsx: "react-jsx",
jsxImportSource: "preact",
},
imports: {
"fresh": "jsr:@fresh/core@*",
"preact": "npm:preact@*",
"@preact/signals": "npm:@preact/signals@*",
},
}),
"islands/Foo.tsx": `export const Foo = () => <h1>hello</h1>`,
"routes/index.ts": `export const handler = () => new Response("ok")`,
"static/foo.txt": "ok",
"main.ts": `import { App, staticFiles } from "fresh";
export const app = new App()
.use(staticFiles())
.fsRoutes();`,
});
const builder = new Builder({
root: tmp,
});
await builder.build();
const outBin = path.join(_outDir.dir, "fresh-compiled");
const bin = Deno.build.os === "windows" ? "deno.exe" : "deno";
const cp = await new Deno.Command(bin, {
args: [
"compile",
"-A",
"--include",
"static/",
"--include",
"_fresh",
"--output",
outBin,
path.join("_fresh", "compiled-entry.js"),
],
cwd: tmp,
}).output();
const { stderr, stdout } = getStdOutput(cp);
// deno-lint-ignore no-console
console.log(stdout);
// deno-lint-ignore no-console
console.log(stderr);
await withChildProcessServer({
bin: outBin,
cwd: _outDir.dir,
args: [],
env: {
PORT: "0",
HOSTNAME: "127.0.0.1",
},
}, async (address) => {
let res = await fetch(address);
expect(await res.text()).toEqual("ok");
res = await fetch(`${address}/foo.txt`);
expect(await res.text()).toEqual("ok");
});
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test("specToName", () => {
// HTTP
expect(specToName("http://example.com")).toEqual("example");