fondu 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,7 +90,7 @@ export function prerenderRoutes(app, routes, version) {
90
90
  return app.fetch(new Request(url, { headers }), c.env, ctx);
91
91
  });
92
92
  app.get('/__fondu/prerender', async (c) => {
93
- // set for the build only: a Worker binding, or the environment of `node` / `bun dist/index.js`
93
+ // set for the build only: a Worker binding, or the environment of `node` / `bun dist/server/index.js`
94
94
  const env = c.env?.FONDU_PRERENDER ??
95
95
  globalThis.process?.env?.FONDU_PRERENDER;
96
96
  if (!env)
@@ -107,7 +107,8 @@ async function buildPlugin(options) {
107
107
  const plugin = build({
108
108
  entry: SERVER,
109
109
  external,
110
- outputDir: './dist',
110
+ outputDir: './dist/server', // next to dist/client, as the client build writes it
111
+ emptyOutDir: true, // dist/server is the server build's own
111
112
  // Node: @hono/node-server's serve() on `PORT` (else the option), saying where it listens, with a graceful
112
113
  // shutdown on SIGTERM / SIGINT (10 s). Bun serves the default export itself and reads `PORT`.
113
114
  ...(options.target === 'node' && {
@@ -134,7 +135,7 @@ async function buildPlugin(options) {
134
135
  return [
135
136
  `import { serveStatic } from '${options.target === 'bun' ? 'hono/bun' : '@hono/node-server/serve-static'}'`,
136
137
  `import { fileURLToPath } from 'node:url'`,
137
- `const clientRoot = fileURLToPath(new URL('./client', import.meta.url))`,
138
+ `const clientRoot = fileURLToPath(new URL('../client', import.meta.url))`,
138
139
  `${app}.use('/assets/*', async (c, next) => { await next(); if (c.res.ok) c.header('Cache-Control', 'public, max-age=31536000, immutable') })`,
139
140
  ...paths.map((p) => `${app}.use(${JSON.stringify(p)}, serveStatic({ root: clientRoot }))`),
140
141
  // prerender: how the app reads the prerendered pages (fondu's server/prerender.ts), in the client build
@@ -257,7 +258,7 @@ function core(options) {
257
258
  ssr: { noExternal: ['fondu'] },
258
259
  build: {
259
260
  copyPublicDir: false,
260
- rollupOptions: { output: { chunkFileNames: 'server/[name]-[hash].js' } },
261
+ rollupOptions: { output: { chunkFileNames: '[name]-[hash].js' } },
261
262
  },
262
263
  };
263
264
  },
@@ -24,7 +24,7 @@ interface Server {
24
24
  dispose(): Promise<void>;
25
25
  }
26
26
  /**
27
- * After the build: the built server (the Worker in wrangler, or `node` / `bun dist/index.js`), started with
27
+ * After the build: the built server (the Worker in wrangler, or `node` / `bun dist/server/index.js`), started with
28
28
  * `FONDU_PRERENDER` set, lists the pages to prerender (`/__fondu/prerender`); each is asked for as a document and as
29
29
  * a visit, and both are written to the client build. Cloudflare serves them before the Worker, with the security
30
30
  * headers written to `_headers`; Node and Bun before the routes, behind the app's own headers.
@@ -32,5 +32,5 @@ interface Server {
32
32
  export declare function prerender(start: () => Promise<Server>, clientDir: string, logger: Logger, headersFile: boolean): Promise<undefined>;
33
33
  /** Cloudflare: the built Worker, in the app's own wrangler (fondu does not depend on it) */
34
34
  export declare const worker: (root: string, workerConfig: string) => () => Promise<Server>;
35
- /** Node / Bun: `node dist/index.js` (or `bun`), on a free port, until it answers */
35
+ /** Node / Bun: `node dist/server/index.js` (or `bun`), on a free port, until it answers */
36
36
  export declare const nodeServer: (root: string, runtime: 'node' | 'bun') => () => Promise<Server>;
@@ -53,7 +53,7 @@ export function headerRules(headers) {
53
53
  return `\n/*\n${lines.join('\n')}\n${PAGE_DATA}/*\n X-Inertia: true\n`;
54
54
  }
55
55
  /**
56
- * After the build: the built server (the Worker in wrangler, or `node` / `bun dist/index.js`), started with
56
+ * After the build: the built server (the Worker in wrangler, or `node` / `bun dist/server/index.js`), started with
57
57
  * `FONDU_PRERENDER` set, lists the pages to prerender (`/__fondu/prerender`); each is asked for as a document and as
58
58
  * a visit, and both are written to the client build. Cloudflare serves them before the Worker, with the security
59
59
  * headers written to `_headers`; Node and Bun before the routes, behind the app's own headers.
@@ -143,10 +143,10 @@ export const worker = (root, workerConfig) => async () => {
143
143
  dispose: () => started.dispose(),
144
144
  };
145
145
  };
146
- /** Node / Bun: `node dist/index.js` (or `bun`), on a free port, until it answers */
146
+ /** Node / Bun: `node dist/server/index.js` (or `bun`), on a free port, until it answers */
147
147
  export const nodeServer = (root, runtime) => async () => {
148
148
  const port = await freePort();
149
- const child = spawn(runtime, ['dist/index.js'], {
149
+ const child = spawn(runtime, ['dist/server/index.js'], {
150
150
  cwd: root,
151
151
  env: { ...process.env, PORT: String(port), FONDU_PRERENDER: '1', NODE_ENV: 'production' },
152
152
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -169,7 +169,7 @@ export const nodeServer = (root, runtime) => async () => {
169
169
  };
170
170
  for (let tries = 0;; tries++) {
171
171
  if (child.exitCode !== null || tries === 200)
172
- throw new Error(`the server (${runtime} dist/index.js) did not start:\n${output.trim()}`);
172
+ throw new Error(`the server (${runtime} dist/server/index.js) did not start:\n${output.trim()}`);
173
173
  try {
174
174
  await fetch(base + '/__fondu/prerender');
175
175
  return server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fondu",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "A small meta-framework for full-stack React apps, built on Hono, Vite and Inertia. It runs on Bun, Cloudflare Workers and Node.",
5
5
  "keywords": [
6
6
  "bun",