Skip to content

Commit

Permalink
wait go back go back
Browse files Browse the repository at this point in the history
  • Loading branch information
actualwitch committed Jan 21, 2025
1 parent e41d048 commit cae8355
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/build.bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $`rm -rf ./build`;
const revision = await store.get(revisionAtom);

for (const target of ["linux-x64", "linux-arm64", "windows-x64", "darwin-x64", "darwin-arm64"]) {
await $`bun build --compile --minify --target=bun-${target}-modern ./src/entry/server.tsx --outfile ./build/experiment-${revision}-${target}`;
await $`bun build --compile --minify --target=bun-${target}-modern ./src/entry/bin.tsx --outfile ./build/experiment-${revision}-${target}`;
}
2 changes: 0 additions & 2 deletions src/atoms/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { atom } from "jotai";
import { getRealm } from "../utils/realm";
import { Maybe } from "true-myth";
import { resolve, spawn } from "../utils";
import { clientFile, staticDir } from "../const";

export const clientScriptAtom = atom(async () => {
if (getRealm() !== "server") return Maybe.nothing();
const result = await spawn("bun", [
"build",
"./src/entry/client.tsx",
Expand Down
13 changes: 13 additions & 0 deletions src/entry/_macro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const getClientAsString = async (entry = "src/entry/client.tsx") => {
const {
outputs: [js, ...outputs],
} = await Bun.build({
entrypoints: [entry],
throw: true,
});
console.log(`Emitted 1+${outputs.length} files`);
if (outputs.length) {
console.log(outputs);
}
return js.text();
};
47 changes: 47 additions & 0 deletions src/entry/bin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { Serve } from "bun";
import { debugAtom } from "../atoms/common";
import { clientScriptAtom } from "../atoms/server";
import { clientFile, description, hostname, iconResolutions, name, port } from "../const";
import { getManifest } from "../feature/pwa/manifest";
import { store } from "../store";
import { createFetch } from "../utils/handler";
import { log } from "../utils/logger";
import { doPOST, doSSE, doStreamingSSR } from "./_handlers";
import { Maybe } from "true-myth";
import { getClientAsString } from "./_macro" with { type: "macro" };

export default {
development: store.get(debugAtom),
hostname,
port,
fetch: createFetch(
doSSE,
doPOST,
async (request: Request) => {
const url = new URL(request.url);
let response: Response | null = null;
if (url.pathname === "/favicon.ico") {
response = new Response("KO", { status: 404 });
}
if (url.pathname === "/manifest.json") {
response = new Response(JSON.stringify(getManifest(name, description, iconResolutions)), {
headers: {
"Content-Type": "application/json",
},
});
}
if (url.pathname === clientFile) {
const clientScript = Maybe.just(await getClientAsString());
response = clientScript.match({
Just: (script) => new Response(script, { headers: { "Content-Type": "application/javascript" } }),
Nothing: () => new Response("KO", { status: 500 }),
});
}
if (response) {
log("Static", request.url);
}
return response;
},
doStreamingSSR,
),
} satisfies Serve;

0 comments on commit cae8355

Please sign in to comment.