@foldkit/vite-plugin 0.24.0-canary.63949f4e9660 → 0.24.0-canary.95fed7fdafa3
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/README.md +46 -0
- package/dist/build.d.ts +48 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +62 -57
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -65,6 +65,52 @@ With this set, the dev server converts HTML page requests to Web `Request` value
|
|
|
65
65
|
|
|
66
66
|
Vite retains ownership of configured proxy routes before Foldkit handles application requests. Vite's `server.cors` option applies to Vite-owned source modules, assets, and HMR. It does not add headers to application responses or answer their preflights. Preflight ownership follows `Access-Control-Request-Method`, so a preflight for an application `POST` reaches `renderPage` even when its path looks like an asset. An `OPTIONS` request without both `Origin` and `Access-Control-Request-Method` is not a preflight and also reaches `renderPage`. Define application CORS in `renderPage`, where development and the deployed host share one policy. Vite's `allowedHosts` check runs before proxy and application handling, including `OPTIONS` and methods the Web `Request` API cannot represent.
|
|
67
67
|
|
|
68
|
+
## Completed build metadata
|
|
69
|
+
|
|
70
|
+
Deployment tools that run Vite in process can read `foldkit:build` through Vite's standard plugin `api` field. Await the full application build before reading:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import type { FoldkitBuildApi } from '@foldkit/vite-plugin'
|
|
74
|
+
import { createBuilder } from 'vite'
|
|
75
|
+
|
|
76
|
+
const builder = await createBuilder()
|
|
77
|
+
await builder.buildApp()
|
|
78
|
+
|
|
79
|
+
const plugin = builder.config.plugins.find(
|
|
80
|
+
plugin => plugin.name === 'foldkit:build',
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if (plugin !== undefined) {
|
|
84
|
+
const api: FoldkitBuildApi | undefined = plugin.api
|
|
85
|
+
|
|
86
|
+
if (typeof api?.getBuildMetadata !== 'function') {
|
|
87
|
+
throw new Error('This Foldkit version does not expose build metadata')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const metadata = api.getBuildMetadata()
|
|
91
|
+
console.log(metadata.serverEntry)
|
|
92
|
+
console.log(metadata.manifest.prerendered)
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`FoldkitBuildApi` preserves `serverEntry` (the configured source entry) and `fetchModuleId` (the virtual fetch module). Its `getBuildMetadata()` method returns `FoldkitBuildMetadata`, exported as a Schema and inferred type:
|
|
97
|
+
|
|
98
|
+
| Field | Meaning |
|
|
99
|
+
| ----------------- | ------------------------------------------------------- |
|
|
100
|
+
| `root` | Absolute resolved application root |
|
|
101
|
+
| `clientDirectory` | Absolute resolved client output directory |
|
|
102
|
+
| `serverDirectory` | Absolute resolved server output directory |
|
|
103
|
+
| `serverEntry` | Absolute path to the emitted fetch handler |
|
|
104
|
+
| `manifest` | The version-1 data also written to `foldkit.build.json` |
|
|
105
|
+
|
|
106
|
+
The snapshot, manifest, and prerendered route array are frozen. The data can be serialized to another process. The manifest keeps its portable relative POSIX paths; the outer path fields describe the local build machine. Output paths reflect the resolved Vite environments, including overrides made by a host plugin.
|
|
107
|
+
|
|
108
|
+
A client-only build has no `foldkit:build` plugin. A present plugin without the accessor needs a Foldkit upgrade. The accessor throws before Foldkit finalizes, while another client or server build is running, or after its build fails. Always await `builder.buildApp()` successfully: another plugin can fail after Foldkit has finalized. An environment's `writeBundle` and another plugin's post-order `buildApp` hook do not establish this completion boundary.
|
|
109
|
+
|
|
110
|
+
Create a fresh Foldkit plugin set for each independent builder. The build plugin uses Vite's `sharedDuringBuild` to share captures across its environments. Concurrent builders must not reuse the same plugin object. This API does not add watch-mode support.
|
|
111
|
+
|
|
112
|
+
Prerendered pages and `foldkit.build.json` are finalized after the environment bundles. A separate deployment process that consumes an existing build can continue reading the disk manifest. An integration that runs the build in a child process can read the API there and transfer the serialized metadata in its child result.
|
|
113
|
+
|
|
68
114
|
## Build id
|
|
69
115
|
|
|
70
116
|
The build id does not make hydration correct. It makes hydration refuse when it would otherwise be incorrect.
|
package/dist/build.d.ts
CHANGED
|
@@ -76,6 +76,53 @@ export declare const FoldkitBuildManifest: Schema.Struct<{
|
|
|
76
76
|
* unknown versions rather than letting the host read missing fields.
|
|
77
77
|
*/
|
|
78
78
|
export type FoldkitBuildManifest = typeof FoldkitBuildManifest.Type;
|
|
79
|
+
/** Completed application build data for an in-process deployment integration. */
|
|
80
|
+
export declare const FoldkitBuildMetadata: Schema.Struct<{
|
|
81
|
+
/** Absolute resolved Vite application root. */
|
|
82
|
+
readonly root: Schema.String;
|
|
83
|
+
/** Absolute resolved browser output directory. */
|
|
84
|
+
readonly clientDirectory: Schema.String;
|
|
85
|
+
/** Absolute resolved server output directory. */
|
|
86
|
+
readonly serverDirectory: Schema.String;
|
|
87
|
+
/** Absolute path to the emitted fetch handler. */
|
|
88
|
+
readonly serverEntry: Schema.String;
|
|
89
|
+
/** Portable data also written to `foldkit.build.json`. */
|
|
90
|
+
readonly manifest: Schema.Struct<{
|
|
91
|
+
/**
|
|
92
|
+
* The shape of this document. A consumer decodes before reading and refuses
|
|
93
|
+
* a version it does not know, so a manifest written by a newer Foldkit is a
|
|
94
|
+
* clear refusal rather than a field silently read as undefined.
|
|
95
|
+
*/
|
|
96
|
+
readonly schemaVersion: Schema.Literals<readonly [1]>;
|
|
97
|
+
/**
|
|
98
|
+
* Where the browser build was written, as a POSIX path relative to the Vite
|
|
99
|
+
* root. Relative and normalized so a manifest survives being moved with the
|
|
100
|
+
* build it describes.
|
|
101
|
+
*/
|
|
102
|
+
readonly client: Schema.String;
|
|
103
|
+
/** Where the server build was written, on the same terms as {@link client}. */
|
|
104
|
+
readonly server: Schema.String;
|
|
105
|
+
/** The server build's entry file, relative to `server`. */
|
|
106
|
+
readonly serverEntry: Schema.String;
|
|
107
|
+
/** Every path this build generated a page for, in the order it generated. */
|
|
108
|
+
readonly prerendered: Schema.$Array<Schema.String>;
|
|
109
|
+
}>;
|
|
110
|
+
}>;
|
|
111
|
+
/** The serializable, frozen snapshot of a completed Foldkit build. */
|
|
112
|
+
export type FoldkitBuildMetadata = typeof FoldkitBuildMetadata.Type;
|
|
113
|
+
/** The `foldkit:build` plugin's public integration API. */
|
|
114
|
+
export type FoldkitBuildApi = Readonly<{
|
|
115
|
+
/** Configured application source entry. */
|
|
116
|
+
serverEntry: string;
|
|
117
|
+
/** Virtual module used to bundle the fetch handler. */
|
|
118
|
+
fetchModuleId: typeof FOLDKIT_FETCH_MODULE_ID;
|
|
119
|
+
/**
|
|
120
|
+
* Read after a successful `await builder.buildApp()`. Throws before Foldkit
|
|
121
|
+
* finalizes or after another client or server build starts. Later plugin failures
|
|
122
|
+
* still require callers to await the full build successfully.
|
|
123
|
+
*/
|
|
124
|
+
getBuildMetadata: () => FoldkitBuildMetadata;
|
|
125
|
+
}>;
|
|
79
126
|
export declare const manifestPath: (root: string, directory: string, pathApi?: typeof nodePath) => string;
|
|
80
127
|
export declare const renderTargetFor: (clientDirectory: string, path: string, origin: string, pathApi?: typeof nodePath) => Readonly<{
|
|
81
128
|
url: URL;
|
|
@@ -90,5 +137,5 @@ export declare const renderTargetFor: (clientDirectory: string, path: string, or
|
|
|
90
137
|
* use the HTML emitted by the browser build, but the unrendered template is not
|
|
91
138
|
* published with the assets. The server bundle's default export is `{ fetch }`.
|
|
92
139
|
*/
|
|
93
|
-
export declare const foldkitBuild: (serverEntry: string, options?: FoldkitBuildOptions) => Plugin
|
|
140
|
+
export declare const foldkitBuild: (serverEntry: string, options?: FoldkitBuildOptions) => Plugin<FoldkitBuildApi>;
|
|
94
141
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,OAAO,QAA8B,MAAM,WAAW,C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A;AAcF,eAAO,MAAM,YAAY,SACjB,MAAM,aACD,MAAM,YACR,OAAO,QAAQ,KACvB,MAQF,CAAA;AAyFD,eAAO,MAAM,eAAe,oBACT,MAAM,QACjB,MAAM,UACJ,MAAM,YACL,OAAO,QAAQ,KACvB,QAAQ,CAAC;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA0CrC,CAAA;AAsFD;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,gBACV,MAAM,YACV,mBAAmB,KAC3B,MAAM,CAAC,eAAe,CAmPxB,CAAA"}
|
package/dist/build.js
CHANGED
|
@@ -31,6 +31,19 @@ export const FoldkitBuildManifest = Schema.Struct({
|
|
|
31
31
|
/** Every path this build generated a page for, in the order it generated. */
|
|
32
32
|
prerendered: Schema.Array(Schema.String),
|
|
33
33
|
});
|
|
34
|
+
/** Completed application build data for an in-process deployment integration. */
|
|
35
|
+
export const FoldkitBuildMetadata = Schema.Struct({
|
|
36
|
+
/** Absolute resolved Vite application root. */
|
|
37
|
+
root: Schema.String,
|
|
38
|
+
/** Absolute resolved browser output directory. */
|
|
39
|
+
clientDirectory: Schema.String,
|
|
40
|
+
/** Absolute resolved server output directory. */
|
|
41
|
+
serverDirectory: Schema.String,
|
|
42
|
+
/** Absolute path to the emitted fetch handler. */
|
|
43
|
+
serverEntry: Schema.String,
|
|
44
|
+
/** Portable data also written to `foldkit.build.json`. */
|
|
45
|
+
manifest: FoldkitBuildManifest,
|
|
46
|
+
});
|
|
34
47
|
const MANIFEST_SCHEMA_VERSION = 1;
|
|
35
48
|
// Relative and POSIX so the manifest describes a layout rather than this
|
|
36
49
|
// machine: an absolute `clientOutDir` would otherwise be published verbatim and
|
|
@@ -154,26 +167,6 @@ const prerenderOptionsFrom = (prerender) => {
|
|
|
154
167
|
}
|
|
155
168
|
return prerender === true ? {} : prerender;
|
|
156
169
|
};
|
|
157
|
-
// Keyed by Vite root plus the output layout, so concurrent builds of different
|
|
158
|
-
// projects in one process never read each other's output.
|
|
159
|
-
//
|
|
160
|
-
// NOTE: the registry hangs off a global symbol rather than module scope. Vite
|
|
161
|
-
// re-bundles a config file for each environment it resolves, and every bundle
|
|
162
|
-
// is a fresh copy of this module with its own module scope, so what the client
|
|
163
|
-
// build recorded would be invisible to the instance that finalizes. The symbol
|
|
164
|
-
// is one registry for the process no matter how many copies of this module it
|
|
165
|
-
// loads.
|
|
166
|
-
const CAPTURES = Symbol.for('foldkit/vite-plugin:build-captures');
|
|
167
|
-
const captures = (() => {
|
|
168
|
-
const registry = globalThis;
|
|
169
|
-
const existing = registry[CAPTURES];
|
|
170
|
-
if (existing instanceof Map) {
|
|
171
|
-
return existing;
|
|
172
|
-
}
|
|
173
|
-
const fresh = new Map();
|
|
174
|
-
registry[CAPTURES] = fresh;
|
|
175
|
-
return fresh;
|
|
176
|
-
})();
|
|
177
170
|
const fetchModuleSource = (serverEntry, template, containerId) => {
|
|
178
171
|
const containerLiteral = containerId === undefined ? 'undefined' : JSON.stringify(containerId);
|
|
179
172
|
// NOTE: `export *` re-exports whatever the application entry actually names,
|
|
@@ -218,6 +211,8 @@ const templateForFetchModule = (capturedTemplate) => {
|
|
|
218
211
|
* published with the assets. The server bundle's default export is `{ fetch }`.
|
|
219
212
|
*/
|
|
220
213
|
export const foldkitBuild = (serverEntry, options = {}) => {
|
|
214
|
+
const state = {};
|
|
215
|
+
let metadata;
|
|
221
216
|
const clientOutDir = options.clientOutDir ?? DEFAULT_CLIENT_OUT_DIR;
|
|
222
217
|
const serverOutDir = options.serverOutDir ?? DEFAULT_SERVER_OUT_DIR;
|
|
223
218
|
const prerender = prerenderOptionsFrom(options.prerender ?? false);
|
|
@@ -226,12 +221,11 @@ export const foldkitBuild = (serverEntry, options = {}) => {
|
|
|
226
221
|
// with the build's own privileges. That module is the application's own code
|
|
227
222
|
// and its dependencies, built from the configured entry, and is trusted on
|
|
228
223
|
// exactly those terms. Nothing here is imported when prerendering is off.
|
|
229
|
-
const generatePages = async (builder, template, serverDirectory, entryFileName) => {
|
|
224
|
+
const generatePages = async (builder, template, clientDirectory, serverDirectory, entryFileName) => {
|
|
230
225
|
if (prerender === undefined) {
|
|
231
226
|
return [];
|
|
232
227
|
}
|
|
233
228
|
const origin = prerender.origin ?? DEFAULT_PRERENDER_ORIGIN;
|
|
234
|
-
const clientDirectory = resolve(builder.config.root, clientOutDir);
|
|
235
229
|
const entryFile = resolve(serverDirectory, entryFileName);
|
|
236
230
|
const contained = resolve(serverDirectory);
|
|
237
231
|
if (!entryFile.startsWith(`${contained}${nodePath.sep}`)) {
|
|
@@ -258,38 +252,12 @@ export const foldkitBuild = (serverEntry, options = {}) => {
|
|
|
258
252
|
}
|
|
259
253
|
return paths;
|
|
260
254
|
};
|
|
261
|
-
const writeManifest = async (builder, serverDirectory, entryFileName, prerendered) => {
|
|
262
|
-
const manifest = Schema.encodeSync(FoldkitBuildManifest)({
|
|
263
|
-
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
264
|
-
client: manifestPath(builder.config.root, clientOutDir),
|
|
265
|
-
server: manifestPath(builder.config.root, serverOutDir),
|
|
266
|
-
serverEntry: entryFileName,
|
|
267
|
-
prerendered,
|
|
268
|
-
});
|
|
269
|
-
await writeFile(resolve(serverDirectory, MANIFEST_FILE_NAME), `${JSON.stringify(manifest, undefined, 2)}\n`);
|
|
270
|
-
builder.config.logger.info(` wrote ${MANIFEST_FILE_NAME}`);
|
|
271
|
-
};
|
|
272
|
-
// What each environment emitted, recorded as it is emitted.
|
|
273
|
-
//
|
|
274
|
-
// Vite resolves the config once per environment unless `sharedConfigBuild` is
|
|
275
|
-
// on, so the plugin that finalizes is not necessarily the instance that saw a
|
|
276
|
-
// given environment build. Keying the record by the output layout it
|
|
277
|
-
// describes is what lets the finalizing instance read what the others
|
|
278
|
-
// emitted, and what lets finalization work whether this plugin orchestrates
|
|
279
|
-
// the environments or a host does.
|
|
280
|
-
const key = [clientOutDir, serverOutDir, serverEntry].join('\u0000');
|
|
281
|
-
const captured = (root) => {
|
|
282
|
-
const existing = captures.get(`${root}\u0000${key}`);
|
|
283
|
-
if (existing !== undefined) {
|
|
284
|
-
return existing;
|
|
285
|
-
}
|
|
286
|
-
const fresh = {};
|
|
287
|
-
captures.set(`${root}\u0000${key}`, fresh);
|
|
288
|
-
return fresh;
|
|
289
|
-
};
|
|
290
255
|
const finalize = async (builder) => {
|
|
291
|
-
|
|
292
|
-
const
|
|
256
|
+
metadata = undefined;
|
|
257
|
+
const client = environmentNamed(builder, 'client');
|
|
258
|
+
const server = environmentNamed(builder, 'ssr');
|
|
259
|
+
const clientDirectory = resolve(client.config.root, client.config.build.outDir);
|
|
260
|
+
const serverDirectory = resolve(server.config.root, server.config.build.outDir);
|
|
293
261
|
if (state.serverEntryFile === undefined) {
|
|
294
262
|
throw new Error('[foldkit] the server environment produced no entry chunk, so there is nothing to deploy or generate from.');
|
|
295
263
|
}
|
|
@@ -301,15 +269,54 @@ export const foldkitBuild = (serverEntry, options = {}) => {
|
|
|
301
269
|
}
|
|
302
270
|
return state.template;
|
|
303
271
|
};
|
|
304
|
-
const prerendered = await generatePages(builder, template, serverDirectory, state.serverEntryFile);
|
|
305
|
-
|
|
272
|
+
const prerendered = await generatePages(builder, template, clientDirectory, serverDirectory, state.serverEntryFile);
|
|
273
|
+
const manifest = FoldkitBuildManifest.make({
|
|
274
|
+
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
275
|
+
client: manifestPath(builder.config.root, clientDirectory),
|
|
276
|
+
server: manifestPath(builder.config.root, serverDirectory),
|
|
277
|
+
serverEntry: state.serverEntryFile,
|
|
278
|
+
prerendered: [...prerendered],
|
|
279
|
+
});
|
|
280
|
+
await writeFile(resolve(serverDirectory, MANIFEST_FILE_NAME), `${JSON.stringify(Schema.encodeSync(FoldkitBuildManifest)(manifest), undefined, 2)}\n`);
|
|
281
|
+
builder.config.logger.info(` wrote ${MANIFEST_FILE_NAME}`);
|
|
282
|
+
const completedMetadata = FoldkitBuildMetadata.make({
|
|
283
|
+
root: builder.config.root,
|
|
284
|
+
clientDirectory,
|
|
285
|
+
serverDirectory,
|
|
286
|
+
serverEntry: resolve(serverDirectory, state.serverEntryFile),
|
|
287
|
+
manifest,
|
|
288
|
+
});
|
|
289
|
+
Object.freeze(completedMetadata.manifest.prerendered);
|
|
290
|
+
Object.freeze(completedMetadata.manifest);
|
|
291
|
+
metadata = Object.freeze(completedMetadata);
|
|
306
292
|
};
|
|
307
293
|
return {
|
|
308
294
|
name: 'foldkit:build',
|
|
309
295
|
apply: 'build',
|
|
296
|
+
sharedDuringBuild: true,
|
|
310
297
|
api: {
|
|
311
298
|
serverEntry,
|
|
312
299
|
fetchModuleId: FOLDKIT_FETCH_MODULE_ID,
|
|
300
|
+
getBuildMetadata: () => {
|
|
301
|
+
if (metadata === undefined) {
|
|
302
|
+
throw new Error('[foldkit] build metadata is not available. Read it after a successful builder.buildApp().');
|
|
303
|
+
}
|
|
304
|
+
return metadata;
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
buildStart: {
|
|
308
|
+
order: 'pre',
|
|
309
|
+
handler() {
|
|
310
|
+
if (this.environment.name === 'client') {
|
|
311
|
+
delete state.template;
|
|
312
|
+
delete state.serverEntryFile;
|
|
313
|
+
metadata = undefined;
|
|
314
|
+
}
|
|
315
|
+
else if (this.environment.name === 'ssr') {
|
|
316
|
+
delete state.serverEntryFile;
|
|
317
|
+
metadata = undefined;
|
|
318
|
+
}
|
|
319
|
+
},
|
|
313
320
|
},
|
|
314
321
|
resolveId(id) {
|
|
315
322
|
if (id === FOLDKIT_FETCH_MODULE_ID) {
|
|
@@ -321,7 +328,6 @@ export const foldkitBuild = (serverEntry, options = {}) => {
|
|
|
321
328
|
if (id !== RESOLVED_FETCH_MODULE_ID) {
|
|
322
329
|
return;
|
|
323
330
|
}
|
|
324
|
-
const state = captured(this.environment.config.root);
|
|
325
331
|
const template = templateForFetchModule(state.template);
|
|
326
332
|
return fetchModuleSource(serverEntry, template, containerId);
|
|
327
333
|
},
|
|
@@ -330,7 +336,6 @@ export const foldkitBuild = (serverEntry, options = {}) => {
|
|
|
330
336
|
generateBundle: {
|
|
331
337
|
order: 'post',
|
|
332
338
|
handler(_options, bundle) {
|
|
333
|
-
const state = captured(this.environment.config.root);
|
|
334
339
|
if (this.environment.name === 'ssr') {
|
|
335
340
|
state.serverEntryFile = serverEntryFile(Object.values(bundle), FETCH_CHUNK_NAME);
|
|
336
341
|
return;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
import { type FoldkitBuildOptions } from './build.js';
|
|
3
3
|
import { type FoldkitSsrOptions } from './ssr.js';
|
|
4
4
|
export { type BrandDistResult, brandDistDirectory } from './brandDist.js';
|
|
5
|
-
export { FOLDKIT_FETCH_MODULE_ID, FoldkitBuildManifest, type FoldkitBuildOptions, type FoldkitPrerenderOptions, foldkitBuild, } from './build.js';
|
|
5
|
+
export { FOLDKIT_FETCH_MODULE_ID, FoldkitBuildManifest, FoldkitBuildMetadata, type FoldkitBuildApi, type FoldkitBuildOptions, type FoldkitPrerenderOptions, foldkitBuild, } from './build.js';
|
|
6
6
|
export { type FoldkitSsrOptions, foldkitSsr } from './ssr.js';
|
|
7
7
|
export { type ViewIdentityTransformResult, foldkitViewIdentity, transformViewIdentity, } from './viewIdentity.js';
|
|
8
8
|
/** Options for the `foldkit` Vite plugin. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+CA,OAAO,KAAK,EAEV,MAAM,EAIP,MAAM,MAAM,CAAA;AAOb,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,YAAY,CAAA;AAInE,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,UAAU,CAAA;AAG7D,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAg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AAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EACL,KAAK,2BAA2B,EAChC,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,mBAAmB,CAAA;AAE1B,6CAA6C;AAC7C,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAChC;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,gBAAgB,CAAC,GACzD,QAAQ,CAAC;QACP;;;;;;;;WAQG;QACH,KAAK,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAA;KACtC,CAAC,CAAA;IACJ;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC,CAAA;AAw8BF,eAAO,MAAM,OAAO,aAAa,oBAAoB,KAAQ,KAAK,CAAC,MAAM,CA+FxE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { publishRelayRecord, retireRelayRecord } from './relayRegistry.js';
|
|
|
16
16
|
import { foldkitSsr } from './ssr.js';
|
|
17
17
|
import { foldkitViewIdentity } from './viewIdentity.js';
|
|
18
18
|
export { brandDistDirectory } from './brandDist.js';
|
|
19
|
-
export { FOLDKIT_FETCH_MODULE_ID, FoldkitBuildManifest, foldkitBuild, } from './build.js';
|
|
19
|
+
export { FOLDKIT_FETCH_MODULE_ID, FoldkitBuildManifest, FoldkitBuildMetadata, foldkitBuild, } from './build.js';
|
|
20
20
|
export { foldkitSsr } from './ssr.js';
|
|
21
21
|
export { foldkitViewIdentity, transformViewIdentity, } from './viewIdentity.js';
|
|
22
22
|
// NOTE: Vite's dep optimizer scans the consumer's source for `effect`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/vite-plugin",
|
|
3
|
-
"version": "0.24.0-canary.
|
|
3
|
+
"version": "0.24.0-canary.95fed7fdafa3",
|
|
4
4
|
"description": "Vite plugin for Foldkit with state-preserving live reload",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"effect": "4.0.0-rc.116",
|
|
20
|
-
"foldkit": "0.163.0-canary.
|
|
20
|
+
"foldkit": "0.163.0-canary.95fed7fdafa3",
|
|
21
21
|
"vite": "^8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"vite": "^8.2.2",
|
|
37
37
|
"vite-host": "npm:vite@8.2.1",
|
|
38
38
|
"vitest": "^4.1.11",
|
|
39
|
-
"foldkit": "0.163.0-canary.
|
|
39
|
+
"foldkit": "0.163.0-canary.95fed7fdafa3"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
42
42
|
"vite",
|