@foldkit/vite-plugin 0.20.2-canary.c2bb6757f86f → 0.20.2-canary.e590389b2928
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 +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -15
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @foldkit/vite-plugin
|
|
2
2
|
|
|
3
|
-
Vite plugin for Foldkit: view identity branding for the differ, plus
|
|
3
|
+
Vite plugin for Foldkit: view identity branding for the differ, plus state-preserving live reload.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -34,7 +34,7 @@ This plugin supplies that identity. At build time, in dev and production alike,
|
|
|
34
34
|
|
|
35
35
|
Foldkit core modules are never instrumented, and functions that never return vnodes are wrapped inertly. Builds without this plugin fall back to positional matching plus keys, where branch points need hand-written keys.
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## State-preserving live reload
|
|
38
38
|
|
|
39
39
|
When you save a file during development, the plugin:
|
|
40
40
|
|
|
@@ -51,7 +51,7 @@ The plugin uses Vite's WebSocket connection to communicate between the dev serve
|
|
|
51
51
|
- **On file change**: The browser sends the current Model to the Vite server for preservation.
|
|
52
52
|
- **On reload**: The browser requests the preserved Model from the server and initializes the Foldkit Runtime with it.
|
|
53
53
|
|
|
54
|
-
The Model survives
|
|
54
|
+
The Model survives development reloads but clears on a manual browser refresh, so a refresh still resets the application.
|
|
55
55
|
|
|
56
56
|
## Server rendering dev host
|
|
57
57
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EACV,MAAM,EAIP,MAAM,MAAM,CAAA;AAGb,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,YAAY,CAAA;AAGnE,O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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;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;;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;AAonBF,eAAO,MAAM,OAAO,aAAa,oBAAoB,KAAQ,KAAK,CAAC,MAAM,CAuFxE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array, Console, Data, Duration, Effect, Exit, Fiber, HashMap, HashSet, Match, Option, Predicate, Queue, Ref, Schedule, Schema, Stream, pipe, } from 'effect';
|
|
2
2
|
import { Event as DevToolsEvent, EventFrame, RequestFrame, Response, ResponseFrame, } from 'foldkit/devtools-protocol';
|
|
3
|
-
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from 'foldkit/
|
|
3
|
+
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from 'foldkit/model-preservation';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
6
|
import { WebSocketServer } from 'ws';
|
|
@@ -41,6 +41,7 @@ const FORCE_INCLUDED_EFFECT_NAMESPACES = [
|
|
|
41
41
|
'effect/HashMap',
|
|
42
42
|
'effect/HashSet',
|
|
43
43
|
'effect/Layer',
|
|
44
|
+
'effect/Logger',
|
|
44
45
|
'effect/Match',
|
|
45
46
|
'effect/Number',
|
|
46
47
|
'effect/Option',
|
|
@@ -114,26 +115,26 @@ const makeState = Effect.gen(function* () {
|
|
|
114
115
|
const encodeResponseFrameJson = Schema.encodeUnknownSync(Schema.fromJsonString(ResponseFrame));
|
|
115
116
|
// HANDLERS
|
|
116
117
|
const handlePreserveModelReceived = (state, payload) => Exit.match(Schema.decodeUnknownExit(PreserveModelMessage)(payload), {
|
|
117
|
-
onFailure: error => Console.warn('[foldkit:
|
|
118
|
-
onSuccess: ({ id, model,
|
|
119
|
-
const existingFlag = Option.exists(HashMap.get(current, id), ({
|
|
118
|
+
onFailure: error => Console.warn('[foldkit:preserve] failed to decode preserve-model payload', error),
|
|
119
|
+
onSuccess: ({ id, model, isReloadFlush }) => Ref.update(state.preservedModels, current => {
|
|
120
|
+
const existingFlag = Option.exists(HashMap.get(current, id), ({ isReloadFlush }) => isReloadFlush);
|
|
120
121
|
const entry = {
|
|
121
122
|
model,
|
|
122
|
-
|
|
123
|
+
isReloadFlush: isReloadFlush === true || existingFlag,
|
|
123
124
|
};
|
|
124
125
|
return HashMap.set(current, id, entry);
|
|
125
126
|
}),
|
|
126
127
|
});
|
|
127
128
|
const handleRequestModelReceived = (server, state, payload) => Exit.match(Schema.decodeUnknownExit(RequestModelMessage)(payload), {
|
|
128
|
-
onFailure: error => Console.warn('[foldkit:
|
|
129
|
+
onFailure: error => Console.warn('[foldkit:preserve] failed to decode request-model payload', error),
|
|
129
130
|
onSuccess: ({ id }) => Effect.gen(function* () {
|
|
130
131
|
const current = yield* Ref.get(state.preservedModels);
|
|
131
132
|
const sendRestore = (model) => Effect.sync(() => server.ws.send('foldkit:restore-model', Schema.encodeUnknownSync(RestoreModelMessage)(RestoreModelMessage.make({ id, model }))));
|
|
132
133
|
yield* Option.match(HashMap.get(current, id), {
|
|
133
134
|
onNone: () => sendRestore(undefined),
|
|
134
135
|
onSome: entry => {
|
|
135
|
-
if (entry.
|
|
136
|
-
const served = { ...entry,
|
|
136
|
+
if (entry.isReloadFlush) {
|
|
137
|
+
const served = { ...entry, isReloadFlush: false };
|
|
137
138
|
return Ref.update(state.preservedModels, HashMap.set(id, served)).pipe(Effect.flatMap(() => sendRestore(entry.model)));
|
|
138
139
|
}
|
|
139
140
|
return Ref.update(state.preservedModels, HashMap.remove(id)).pipe(Effect.flatMap(() => sendRestore(undefined)));
|
|
@@ -141,7 +142,7 @@ const handleRequestModelReceived = (server, state, payload) => Exit.match(Schema
|
|
|
141
142
|
});
|
|
142
143
|
}),
|
|
143
144
|
});
|
|
144
|
-
const handleHotUpdateFired = (state) => Ref.update(state.preservedModels, current => HashMap.map(current, entry => ({ ...entry,
|
|
145
|
+
const handleHotUpdateFired = (state) => Ref.update(state.preservedModels, current => HashMap.map(current, entry => ({ ...entry, isReloadFlush: true })));
|
|
145
146
|
const handleBrowserEventFrameReceived = (state, data, client) => Exit.match(Schema.decodeUnknownExit(EventFrame)(data), {
|
|
146
147
|
onFailure: error => Console.warn('[foldkit:devTools] failed to decode browser event frame', error),
|
|
147
148
|
onSuccess: frame => DevToolsEvent.match(frame.event, {
|
|
@@ -315,7 +316,7 @@ const main = (server, events, options) => Effect.gen(function* () {
|
|
|
315
316
|
};
|
|
316
317
|
yield* registerViteWsHandlers(server, state, enqueue);
|
|
317
318
|
// NOTE: Forked rather than awaited because binding the relay can retry for
|
|
318
|
-
// seconds.
|
|
319
|
+
// seconds. Model preservation is independent of the relay, and the runtime
|
|
319
320
|
// gives up on its boot-time model request in well under a second, so
|
|
320
321
|
// sequencing the dispatch loop behind the bind would cost model
|
|
321
322
|
// preservation whenever the port is contended.
|
|
@@ -327,8 +328,8 @@ const main = (server, events, options) => Effect.gen(function* () {
|
|
|
327
328
|
// PLUGIN ENTRY
|
|
328
329
|
/**
|
|
329
330
|
* Foldkit's Vite plugin set: the view-identity branding transform and
|
|
330
|
-
* DevTools overlay injection (dev and build), plus
|
|
331
|
-
*
|
|
331
|
+
* DevTools overlay injection (dev and build), plus Model preservation across
|
|
332
|
+
* reloads and the optional DevTools MCP relay (dev only). Returned as
|
|
332
333
|
* an array; Vite flattens nested plugin arrays, so `plugins: [foldkit()]`
|
|
333
334
|
* keeps working.
|
|
334
335
|
*/
|
|
@@ -370,8 +371,8 @@ export const foldkit = (options = {}) => {
|
|
|
370
371
|
return Fiber.interrupt(fiber);
|
|
371
372
|
}
|
|
372
373
|
});
|
|
373
|
-
const
|
|
374
|
-
name: 'foldkit
|
|
374
|
+
const reloadPlugin = {
|
|
375
|
+
name: 'foldkit',
|
|
375
376
|
apply: 'serve',
|
|
376
377
|
config: userConfig => ({
|
|
377
378
|
optimizeDeps: {
|
|
@@ -405,7 +406,7 @@ export const foldkit = (options = {}) => {
|
|
|
405
406
|
foldkitBuildToken(options.buildId),
|
|
406
407
|
foldkitViewIdentity(),
|
|
407
408
|
devToolsOverlayPlugin(),
|
|
408
|
-
|
|
409
|
+
reloadPlugin,
|
|
409
410
|
];
|
|
410
411
|
if (options.ssr === undefined) {
|
|
411
412
|
return shared;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/vite-plugin",
|
|
3
|
-
"version": "0.20.2-canary.
|
|
4
|
-
"description": "Vite plugin for Foldkit
|
|
3
|
+
"version": "0.20.2-canary.e590389b2928",
|
|
4
|
+
"description": "Vite plugin for Foldkit with state-preserving live reload",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"effect": "4.0.0-rc.112",
|
|
20
|
-
"foldkit": "0.158.2-canary.
|
|
20
|
+
"foldkit": "0.158.2-canary.e590389b2928",
|
|
21
21
|
"vite": "^7.0.0 || ^8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"vite": "^8.2.2",
|
|
35
35
|
"vite7": "npm:vite@^7.3.6",
|
|
36
36
|
"vitest": "^4.1.11",
|
|
37
|
-
"foldkit": "0.158.2-canary.
|
|
37
|
+
"foldkit": "0.158.2-canary.e590389b2928"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"vite",
|
|
41
41
|
"vite-plugin",
|
|
42
42
|
"foldkit",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"live-reload",
|
|
44
|
+
"state-preservation"
|
|
45
45
|
],
|
|
46
46
|
"author": "Devin Jameson",
|
|
47
47
|
"license": "MIT",
|