diff --git a/build.ts b/build.ts index 1c6c41f..8d1ea64 100644 --- a/build.ts +++ b/build.ts @@ -1,5 +1,6 @@ import { Glob, Transpiler, fileURLToPath, pathToFileURL } from "bun"; -import { basename, join, relative } from "node:path"; +import { basename, join, parse, relative } from "node:path"; +import { hashremap } from "./hash"; function escapeRegExp(string: string) { return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string @@ -105,8 +106,12 @@ export async function build({ const path = relative(outdir, output.path); if (output.kind === "entry-point" && output.hash) { hashed[`/${path}`] = output.hash; + const imports = transpiler.scanImports(await output.text()); + dependencies[`/${hashremap(path, output.hash)}`] = imports + .filter((x) => x.kind === "import-statement") + .map((x) => "/" + join(path, "..", x.path)); } - if (output.kind === "entry-point" || output.kind === "chunk") { + if (output.kind === "chunk") { const imports = transpiler.scanImports(await output.text()); dependencies[`/${path}`] = imports .filter((x) => x.kind === "import-statement") diff --git a/bun.lockb b/bun.lockb index de5d793..09c4faa 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/example/pages/users/[id].tsx b/example/pages/users/[id].tsx index da919e8..ac2a0ed 100644 --- a/example/pages/users/[id].tsx +++ b/example/pages/users/[id].tsx @@ -1,8 +1,11 @@ +import { Clock } from "../../components/Clock"; + export default function User(props: any) { return (
user {JSON.stringify(props)}
history.back()}>back
+
); } @@ -10,6 +13,9 @@ export default function User(props: any) { export function getServerSideProps(props: any) { console.log("some secret"); return { - props, + props: { + ...props, + time: new Date(), + }, }; } diff --git a/index.tsx b/index.tsx index 6707a0f..97d57b2 100644 --- a/index.tsx +++ b/index.tsx @@ -144,12 +144,17 @@ export class StaticRouters { headers: { Location: result.redirect }, }); } + const hashedBootstrapModules = bootstrapModules?.map((name) => { + const hash = this.#hashed[name]; + if (hash) return hashremap(name, hash); + return name; + }); const stream = await renderToReadableStream( - {bootstrapModules?.map((name, idx) => ( + {hashedBootstrapModules?.map((name, idx) => ( ))} { - const hash = this.#hashed[name]; - if (hash) return hashremap(name, hash); - return name; - }), + bootstrapModules: hashedBootstrapModules, onError, } ); diff --git a/package.json b/package.json index 4e8acc1..5d315fd 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "license": "MIT", "type": "module", "devDependencies": { - "typescript": "^5.6.3", - "@types/bun": "^1.1.12", + "typescript": "^5.7.2", + "@types/bun": "^1.1.14", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", "bun-plugin-dts": "^0.2.4"