@foldkit/vite-plugin 0.23.0 → 0.24.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.
package/dist/build.d.ts CHANGED
@@ -9,9 +9,10 @@ export type FoldkitPrerenderOptions = Readonly<{
9
9
  */
10
10
  paths?: ReadonlyArray<string>;
11
11
  /**
12
- * The origin the entry sees as `Request.url` while generating, such as
13
- * `'https://app.example'`. It reaches canonical URLs and Open Graph URLs, so
14
- * a deployment that publishes those should set the origin it publishes.
12
+ * The origin used for `Request.url` while generating, such as
13
+ * `'https://app.example'`. This option does not set canonical or Open Graph
14
+ * metadata. It affects those fields only when the server entry derives them
15
+ * from `Request.url`, in which case it should match the published origin.
15
16
  */
16
17
  origin?: string;
17
18
  /**
@@ -42,15 +43,11 @@ export type FoldkitBuildOptions = Readonly<{
42
43
  /** Vite module id of the fetch handler Foldkit emits as the server entry. */
43
44
  export declare const FOLDKIT_FETCH_MODULE_ID = "virtual:foldkit/fetch";
44
45
  /**
45
- * What the build produced, written beside the server bundle for whatever
46
- * deploys it.
46
+ * What an `ssr.build` build produced, written beside the server bundle.
47
47
  *
48
- * A host has to decide what the asset layer does with a request that matches no
49
- * file, and that answer follows from the build rather than from taste: an
50
- * application with generated pages and no others wants a miss to stay a miss,
51
- * one with a server wants a miss to reach it, and one with neither wants the
52
- * template. Reading it here is how a deployment target gets that right without
53
- * asking its user to configure it twice.
48
+ * An SSR host serves generated paths as files and sends requests without a
49
+ * matching file to the server entry. A static-only SSG host serves the files
50
+ * and leaves other paths as misses.
54
51
  */
55
52
  export declare const FoldkitBuildManifest: Schema.Struct<{
56
53
  /**
@@ -71,26 +68,12 @@ export declare const FoldkitBuildManifest: Schema.Struct<{
71
68
  readonly serverEntry: Schema.String;
72
69
  /** Every path this build generated a page for, in the order it generated. */
73
70
  readonly prerendered: Schema.$Array<Schema.String>;
74
- /**
75
- * How a request-time host should run the server entry. Always `'fetch'`:
76
- * the entry is a Web `fetch` handler, not a Node process.
77
- */
78
- readonly host: Schema.optional<Schema.Literals<readonly ["fetch"]>>;
79
71
  }>;
80
72
  /**
81
- * What the build produced, written beside the server bundle for whatever
82
- * deploys it.
83
- *
84
- * A host has to decide what the asset layer does with a request that matches no
85
- * file, and that answer follows from the build rather than from taste: an
86
- * application with generated pages and no others wants a miss to stay a miss,
87
- * one with a server wants a miss to reach it, and one with neither wants the
88
- * template. Reading it here is how a deployment target gets that right without
89
- * asking its user to configure it twice.
73
+ * The decoded shape of `foldkit.build.json`.
90
74
  *
91
- * It is a file on disk that something else writes the next time it builds, so a
92
- * consumer decodes it with this Schema and fails closed rather than trusting
93
- * the shape it happens to find.
75
+ * A deployment host decodes the manifest before using it. The Schema rejects
76
+ * unknown versions rather than letting the host read missing fields.
94
77
  */
95
78
  export type FoldkitBuildManifest = typeof FoldkitBuildManifest.Type;
96
79
  export declare const manifestPath: (root: string, directory: string, pathApi?: typeof nodePath) => string;
@@ -102,11 +85,10 @@ export declare const renderTargetFor: (clientDirectory: string, path: string, or
102
85
  * Builds a Web `fetch` handler alongside the browser build, and generates
103
86
  * static HTML from the server entry, inside one `vite build`.
104
87
  *
105
- * Vite drives both environments and every host plugin composes with them, so a
106
- * deployment target that runs `vite build` gets the whole application rather
107
- * than the browser half. The generated pages take their template from the
108
- * browser build's own output, so generating twice over one build produces the
109
- * same pages. The server bundle's default export is `{ fetch }`.
88
+ * Vite builds both environments, so a deployment target that runs `vite build`
89
+ * gets the browser and server bundles. The `fetch` handler and generated pages
90
+ * use the HTML emitted by the browser build, but the unrendered template is not
91
+ * published with the assets. The server bundle's default export is `{ fetch }`.
110
92
  */
111
93
  export declare const foldkitBuild: (serverEntry: string, options?: FoldkitBuildOptions) => Plugin;
112
94
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAA;A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,MAAM,UACJ,MAAM,YACL,OAAO,QAAQ,KACvB,QAAQ,CAAC;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA0CrC,CAAA;AA4GD;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,gBACV,MAAM,YACV,mBAAmB,KAC3B,MAqOF,CAAA"}
package/dist/build.js CHANGED
@@ -1,19 +1,15 @@
1
- import { Array, Schema } from 'effect';
1
+ import { Schema } from 'effect';
2
2
  import { mkdir, writeFile } from 'node:fs/promises';
3
3
  import nodePath, { dirname, resolve } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  /** Vite module id of the fetch handler Foldkit emits as the server entry. */
6
6
  export const FOLDKIT_FETCH_MODULE_ID = 'virtual:foldkit/fetch';
7
7
  /**
8
- * What the build produced, written beside the server bundle for whatever
9
- * deploys it.
8
+ * What an `ssr.build` build produced, written beside the server bundle.
10
9
  *
11
- * A host has to decide what the asset layer does with a request that matches no
12
- * file, and that answer follows from the build rather than from taste: an
13
- * application with generated pages and no others wants a miss to stay a miss,
14
- * one with a server wants a miss to reach it, and one with neither wants the
15
- * template. Reading it here is how a deployment target gets that right without
16
- * asking its user to configure it twice.
10
+ * An SSR host serves generated paths as files and sends requests without a
11
+ * matching file to the server entry. A static-only SSG host serves the files
12
+ * and leaves other paths as misses.
17
13
  */
18
14
  export const FoldkitBuildManifest = Schema.Struct({
19
15
  /**
@@ -34,11 +30,6 @@ export const FoldkitBuildManifest = Schema.Struct({
34
30
  serverEntry: Schema.String,
35
31
  /** Every path this build generated a page for, in the order it generated. */
36
32
  prerendered: Schema.Array(Schema.String),
37
- /**
38
- * How a request-time host should run the server entry. Always `'fetch'`:
39
- * the entry is a Web `fetch` handler, not a Node process.
40
- */
41
- host: Schema.optional(Schema.Literals(['fetch'])),
42
33
  });
43
34
  const MANIFEST_SCHEMA_VERSION = 1;
44
35
  // Relative and POSIX so the manifest describes a layout rather than this
@@ -59,6 +50,7 @@ export const manifestPath = (root, directory, pathApi = nodePath) => {
59
50
  return related.split(pathApi.sep).join('/');
60
51
  };
61
52
  const MANIFEST_FILE_NAME = 'foldkit.build.json';
53
+ const TEMPLATE_FILE_NAME = 'index.html';
62
54
  const DEFAULT_CLIENT_OUT_DIR = 'dist/client';
63
55
  const DEFAULT_SERVER_OUT_DIR = 'dist/server';
64
56
  const DEFAULT_PRERENDER_ORIGIN = 'http://localhost';
@@ -212,7 +204,7 @@ const fetchModuleSource = (serverEntry, template, containerId) => {
212
204
  // page which cannot hydrate, from a build that reported success.
213
205
  const templateForFetchModule = (capturedTemplate) => {
214
206
  if (capturedTemplate === undefined) {
215
- throw new Error('[foldkit] the browser build has not emitted index.html, so the fetch handler has no template to render into. Build the "client" environment before "ssr", and give the client an HTML entry.');
207
+ throw new Error(`[foldkit] the browser build has not emitted ${TEMPLATE_FILE_NAME}, so the fetch handler has no template to render into. Build the "client" environment before "ssr", and give the client an HTML entry.`);
216
208
  }
217
209
  return capturedTemplate;
218
210
  };
@@ -220,11 +212,10 @@ const templateForFetchModule = (capturedTemplate) => {
220
212
  * Builds a Web `fetch` handler alongside the browser build, and generates
221
213
  * static HTML from the server entry, inside one `vite build`.
222
214
  *
223
- * Vite drives both environments and every host plugin composes with them, so a
224
- * deployment target that runs `vite build` gets the whole application rather
225
- * than the browser half. The generated pages take their template from the
226
- * browser build's own output, so generating twice over one build produces the
227
- * same pages. The server bundle's default export is `{ fetch }`.
215
+ * Vite builds both environments, so a deployment target that runs `vite build`
216
+ * gets the browser and server bundles. The `fetch` handler and generated pages
217
+ * use the HTML emitted by the browser build, but the unrendered template is not
218
+ * published with the assets. The server bundle's default export is `{ fetch }`.
228
219
  */
229
220
  export const foldkitBuild = (serverEntry, options = {}) => {
230
221
  const clientOutDir = options.clientOutDir ?? DEFAULT_CLIENT_OUT_DIR;
@@ -274,7 +265,6 @@ export const foldkitBuild = (serverEntry, options = {}) => {
274
265
  server: manifestPath(builder.config.root, serverOutDir),
275
266
  serverEntry: entryFileName,
276
267
  prerendered,
277
- host: 'fetch',
278
268
  });
279
269
  await writeFile(resolve(serverDirectory, MANIFEST_FILE_NAME), `${JSON.stringify(manifest, undefined, 2)}\n`);
280
270
  builder.config.logger.info(` wrote ${MANIFEST_FILE_NAME}`);
@@ -307,7 +297,7 @@ export const foldkitBuild = (serverEntry, options = {}) => {
307
297
  // nothing has no use for an HTML entry and must not require one.
308
298
  const template = () => {
309
299
  if (state.template === undefined) {
310
- throw new Error('[foldkit] the browser build emitted no index.html to generate pages from. Prerendering needs an HTML entry.');
300
+ throw new Error(`[foldkit] the browser build emitted no ${TEMPLATE_FILE_NAME} to generate pages from. Prerendering needs an HTML entry.`);
311
301
  }
312
302
  return state.template;
313
303
  };
@@ -318,7 +308,6 @@ export const foldkitBuild = (serverEntry, options = {}) => {
318
308
  name: 'foldkit:build',
319
309
  apply: 'build',
320
310
  api: {
321
- host: 'fetch',
322
311
  serverEntry,
323
312
  fetchModuleId: FOLDKIT_FETCH_MODULE_ID,
324
313
  },
@@ -336,23 +325,26 @@ export const foldkitBuild = (serverEntry, options = {}) => {
336
325
  const template = templateForFetchModule(state.template);
337
326
  return fetchModuleSource(serverEntry, template, containerId);
338
327
  },
339
- // NOTE: `writeBundle` rather than `generateBundle`: Vite's own HTML plugin
340
- // emits `index.html` from a `generateBundle` hook of its own, and hook
341
- // order between plugins decides whether that asset exists yet. By
342
- // `writeBundle` the bundle is whatever the environment actually produced.
343
- writeBundle(_options, bundle) {
344
- const state = captured(this.environment.config.root);
345
- const outputs = Object.values(bundle);
346
- if (this.environment.name === 'client') {
347
- const html = Array.findFirst(outputs, file => file.type === 'asset' && file.fileName === 'index.html');
348
- if (html._tag === 'Some' && html.value.type === 'asset') {
349
- state.template = String(html.value.source);
328
+ // NOTE: `order: 'post'` because Vite's own HTML plugin emits `index.html`
329
+ // from a `generateBundle` of its own; post is guaranteed to run after it.
330
+ generateBundle: {
331
+ order: 'post',
332
+ handler(_options, bundle) {
333
+ const state = captured(this.environment.config.root);
334
+ if (this.environment.name === 'ssr') {
335
+ state.serverEntryFile = serverEntryFile(Object.values(bundle), FETCH_CHUNK_NAME);
336
+ return;
350
337
  }
351
- return;
352
- }
353
- if (this.environment.name === 'ssr') {
354
- state.serverEntryFile = serverEntryFile(outputs, FETCH_CHUNK_NAME);
355
- }
338
+ if (this.environment.name !== 'client') {
339
+ return;
340
+ }
341
+ const html = bundle[TEMPLATE_FILE_NAME];
342
+ if (html === undefined || html.type !== 'asset') {
343
+ return;
344
+ }
345
+ state.template = String(html.source);
346
+ delete bundle[TEMPLATE_FILE_NAME];
347
+ },
356
348
  },
357
349
  config: userConfig => {
358
350
  const client = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldkit/vite-plugin",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Vite plugin for Foldkit with state-preserving live reload",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "dist"
17
17
  ],
18
18
  "peerDependencies": {
19
- "effect": "4.0.0-rc.115",
19
+ "effect": "4.0.0-rc.116",
20
20
  "foldkit": ">=0.159.0",
21
21
  "vite": "^8.0.0"
22
22
  },
@@ -27,14 +27,14 @@
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.4.0",
29
29
  "@types/ws": "^8.18.1",
30
- "effect": "4.0.0-rc.115",
30
+ "effect": "4.0.0-rc.116",
31
31
  "happy-dom": "^20.11.13",
32
32
  "rimraf": "^6.1.3",
33
33
  "typescript": "^7.0.2",
34
34
  "vite": "^8.2.2",
35
35
  "vite-host": "npm:vite@8.2.1",
36
36
  "vitest": "^4.1.11",
37
- "foldkit": "0.161.0"
37
+ "foldkit": "0.163.0"
38
38
  },
39
39
  "keywords": [
40
40
  "vite",