@foldkit/vite-plugin 0.20.0 → 0.20.1
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 +7 -7
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +8 -8
- package/dist/devToolsOverlay.d.ts.map +1 -1
- package/dist/devToolsOverlay.js +49 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/package.json +2 -2
package/dist/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
2
|
import nodePath from 'node:path';
|
|
3
3
|
import type { Plugin } from 'vite';
|
|
4
4
|
/** How a build materializes the URLs a server entry can render. */
|
|
@@ -54,25 +54,25 @@ export type FoldkitBuildOptions = Readonly<{
|
|
|
54
54
|
* template. Reading it here is how a deployment target gets that right without
|
|
55
55
|
* asking its user to configure it twice.
|
|
56
56
|
*/
|
|
57
|
-
export declare const FoldkitBuildManifest:
|
|
57
|
+
export declare const FoldkitBuildManifest: Schema.Struct<{
|
|
58
58
|
/**
|
|
59
59
|
* The shape of this document. A consumer decodes before reading and refuses
|
|
60
60
|
* a version it does not know, so a manifest written by a newer Foldkit is a
|
|
61
61
|
* clear refusal rather than a field silently read as undefined.
|
|
62
62
|
*/
|
|
63
|
-
readonly schemaVersion:
|
|
63
|
+
readonly schemaVersion: Schema.Literals<readonly [1]>;
|
|
64
64
|
/**
|
|
65
65
|
* Where the browser build was written, as a POSIX path relative to the Vite
|
|
66
66
|
* root. Relative and normalized so a manifest survives being moved with the
|
|
67
67
|
* build it describes.
|
|
68
68
|
*/
|
|
69
|
-
readonly client:
|
|
69
|
+
readonly client: Schema.String;
|
|
70
70
|
/** Where the server build was written, on the same terms as {@link client}. */
|
|
71
|
-
readonly server:
|
|
71
|
+
readonly server: Schema.String;
|
|
72
72
|
/** The server build's entry file, relative to `server`. */
|
|
73
|
-
readonly serverEntry:
|
|
73
|
+
readonly serverEntry: Schema.String;
|
|
74
74
|
/** Every path this build generated a page for, in the order it generated. */
|
|
75
|
-
readonly prerendered:
|
|
75
|
+
readonly prerendered: Schema.$Array<Schema.String>;
|
|
76
76
|
}>;
|
|
77
77
|
/**
|
|
78
78
|
* What the build produced, written beside the server bundle for whatever
|
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,EAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAA;AAGtC,OAAO,QAAiD,MAAM,WAAW,CAAA;AAEzE,OAAO,KAAK,EAGV,MAAM,EAEP,MAAM,MAAM,CAAA;AAEb,mEAAmE;AACnE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AAEF,4EAA4E;AAC5E,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,yCAAyC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,uBAAuB,CAAA;CAC9C,CAAC,CAAA;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;OAIG;;IAEH;;;;OAIG;;IAEH,+EAA+E;;IAE/E,2DAA2D;;IAE3D,6EAA6E;;EAE7E,CAAA;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAA;AAcnE,eAAO,MAAM,YAAY,SACjB,MAAM,aACD,MAAM,YACR,OAAO,QAAQ,KACvB,MAQF,CAAA;AA2FD,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;AA+DD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,gBACV,MAAM,YACV,mBAAmB,KAC3B,MA8MF,CAAA"}
|
package/dist/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array, Schema
|
|
1
|
+
import { Array, Schema } from 'effect';
|
|
2
2
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
3
|
import nodePath, { basename, dirname, extname, resolve } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
@@ -13,25 +13,25 @@ import { pathToFileURL } from 'node:url';
|
|
|
13
13
|
* template. Reading it here is how a deployment target gets that right without
|
|
14
14
|
* asking its user to configure it twice.
|
|
15
15
|
*/
|
|
16
|
-
export const FoldkitBuildManifest =
|
|
16
|
+
export const FoldkitBuildManifest = Schema.Struct({
|
|
17
17
|
/**
|
|
18
18
|
* The shape of this document. A consumer decodes before reading and refuses
|
|
19
19
|
* a version it does not know, so a manifest written by a newer Foldkit is a
|
|
20
20
|
* clear refusal rather than a field silently read as undefined.
|
|
21
21
|
*/
|
|
22
|
-
schemaVersion:
|
|
22
|
+
schemaVersion: Schema.Literals([1]),
|
|
23
23
|
/**
|
|
24
24
|
* Where the browser build was written, as a POSIX path relative to the Vite
|
|
25
25
|
* root. Relative and normalized so a manifest survives being moved with the
|
|
26
26
|
* build it describes.
|
|
27
27
|
*/
|
|
28
|
-
client:
|
|
28
|
+
client: Schema.String,
|
|
29
29
|
/** Where the server build was written, on the same terms as {@link client}. */
|
|
30
|
-
server:
|
|
30
|
+
server: Schema.String,
|
|
31
31
|
/** The server build's entry file, relative to `server`. */
|
|
32
|
-
serverEntry:
|
|
32
|
+
serverEntry: Schema.String,
|
|
33
33
|
/** Every path this build generated a page for, in the order it generated. */
|
|
34
|
-
prerendered:
|
|
34
|
+
prerendered: Schema.Array(Schema.String),
|
|
35
35
|
});
|
|
36
36
|
const MANIFEST_SCHEMA_VERSION = 1;
|
|
37
37
|
// Relative and POSIX so the manifest describes a layout rather than this
|
|
@@ -229,7 +229,7 @@ export const foldkitBuild = (serverEntry, options = {}) => {
|
|
|
229
229
|
return paths;
|
|
230
230
|
};
|
|
231
231
|
const writeManifest = async (builder, serverDirectory, entryFileName, prerendered) => {
|
|
232
|
-
const manifest =
|
|
232
|
+
const manifest = Schema.encodeSync(FoldkitBuildManifest)({
|
|
233
233
|
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
234
234
|
client: manifestPath(builder.config.root, clientOutDir),
|
|
235
235
|
server: manifestPath(builder.config.root, serverOutDir),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devToolsOverlay.d.ts","sourceRoot":"","sources":["../src/devToolsOverlay.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"devToolsOverlay.d.ts","sourceRoot":"","sources":["../src/devToolsOverlay.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAsJlC;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YAC7B,OAAO,GAAG,OAAO,QACpB,MAAM,KACX,OAQF,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB,QAAO,MA+DxC,CAAA"}
|
package/dist/devToolsOverlay.js
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
|
-
import { Option, Record, Schema
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { dirname, join, resolve } from 'node:path';
|
|
1
|
+
import { Array, Option, Record, Schema } from 'effect';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
4
4
|
const DEV_TOOLS_PACKAGE_NAME = '@foldkit/devtools';
|
|
5
|
+
const FOLDKIT_PACKAGE_NAME = 'foldkit';
|
|
5
6
|
const DEV_TOOLS_VITE_EXPORT = './vite';
|
|
6
7
|
const DEV_TOOLS_OVERLAY_MODULE_ID = 'virtual:foldkit-devtools-overlay';
|
|
7
8
|
const RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID = `\0${DEV_TOOLS_OVERLAY_MODULE_ID}`;
|
|
9
|
+
const DEV_TOOLS_VITE_IMPORT_SPECIFIER = `${DEV_TOOLS_PACKAGE_NAME}${DEV_TOOLS_VITE_EXPORT.slice(1)}`;
|
|
10
|
+
const DEV_TOOLS_HOST_IMPORT_SPECIFIER = 'foldkit/devtools-host';
|
|
11
|
+
// NOTE: Vite's dependency scan cannot discover this virtual module's imports.
|
|
12
|
+
// Declaring registry-installed imports before the first request avoids a
|
|
13
|
+
// mid-session reoptimization and page reload.
|
|
14
|
+
const DEV_TOOLS_OVERLAY_IMPORTS = [
|
|
15
|
+
{
|
|
16
|
+
specifier: DEV_TOOLS_VITE_IMPORT_SPECIFIER,
|
|
17
|
+
packageName: DEV_TOOLS_PACKAGE_NAME,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
specifier: DEV_TOOLS_HOST_IMPORT_SPECIFIER,
|
|
21
|
+
packageName: FOLDKIT_PACKAGE_NAME,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
8
24
|
const DEV_TOOLS_OVERLAY_MODULE_SOURCE = `
|
|
9
|
-
import { overlay } from '
|
|
10
|
-
import { __setDevToolsOverlay } from '
|
|
25
|
+
import { overlay } from '${DEV_TOOLS_VITE_IMPORT_SPECIFIER}'
|
|
26
|
+
import { __setDevToolsOverlay } from '${DEV_TOOLS_HOST_IMPORT_SPECIFIER}'
|
|
11
27
|
|
|
12
28
|
__setDevToolsOverlay(overlay)
|
|
13
29
|
`;
|
|
14
|
-
const ApplicationPackageJson =
|
|
15
|
-
dependencies:
|
|
30
|
+
const ApplicationPackageJson = Schema.Struct({
|
|
31
|
+
dependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
16
32
|
});
|
|
17
|
-
const DevToolsPackageJson =
|
|
18
|
-
exports:
|
|
33
|
+
const DevToolsPackageJson = Schema.Struct({
|
|
34
|
+
exports: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
19
35
|
});
|
|
20
|
-
const decodeApplicationPackageJson =
|
|
21
|
-
const decodeDevToolsPackageJson =
|
|
36
|
+
const decodeApplicationPackageJson = Schema.decodeUnknownSync(ApplicationPackageJson);
|
|
37
|
+
const decodeDevToolsPackageJson = Schema.decodeUnknownSync(DevToolsPackageJson);
|
|
22
38
|
const readPackageJson = (decode, packageJsonPath) => {
|
|
23
39
|
try {
|
|
24
40
|
return Option.some(decode(JSON.parse(readFileSync(packageJsonPath, 'utf8'))));
|
|
@@ -46,8 +62,9 @@ const findDirectoryUpward = (directory, isMatch) => {
|
|
|
46
62
|
// package is installed, and `resolve.paths` appends this module's own lookup
|
|
47
63
|
// chain, which under pnpm includes the hoisted virtual store. Both would make
|
|
48
64
|
// the answer depend on something other than what the application installed.
|
|
49
|
-
const
|
|
50
|
-
const
|
|
65
|
+
const installedPackageJsonPath = (directory, packageName) => join(directory, 'node_modules', packageName, 'package.json');
|
|
66
|
+
const findInstalledPackageJsonPath = (root, packageName) => findDirectoryUpward(resolve(root), directory => existsSync(installedPackageJsonPath(directory, packageName))).pipe(Option.map(directory => installedPackageJsonPath(directory, packageName)));
|
|
67
|
+
const findDevToolsPackageJsonPath = (root) => findInstalledPackageJsonPath(root, DEV_TOOLS_PACKAGE_NAME);
|
|
51
68
|
// NOTE: the virtual module imports `@foldkit/devtools/vite` statically, so an
|
|
52
69
|
// installed copy that predates that export point would fail the build rather
|
|
53
70
|
// than quietly skip the overlay. Injecting only when the export exists lets
|
|
@@ -58,6 +75,13 @@ const hasDevToolsViteExport = (root) => findDevToolsPackageJsonPath(root).pipe(O
|
|
|
58
75
|
// nearest manifest keeps dependency placement meaningful for those layouts.
|
|
59
76
|
const applicationPackageJsonPath = (directory) => join(directory, 'package.json');
|
|
60
77
|
const findApplicationPackageJsonPath = (root) => findDirectoryUpward(resolve(root), directory => existsSync(applicationPackageJsonPath(directory))).pipe(Option.map(applicationPackageJsonPath));
|
|
78
|
+
const resolvePackageDirectory = Option.liftThrowable((packageJsonPath) => realpathSync(dirname(packageJsonPath)));
|
|
79
|
+
// NOTE: Vite serves linked packages from source rather than pre-bundling them.
|
|
80
|
+
// A registry-installed package has a real path under `node_modules`, while a
|
|
81
|
+
// workspace link resolves to its source checkout; force-including a link would
|
|
82
|
+
// cache its current source and hide edits. Each owner is checked independently
|
|
83
|
+
// because one package may be linked while the other is installed.
|
|
84
|
+
const isPackageResolvedIntoNodeModules = (root, packageName) => findInstalledPackageJsonPath(root, packageName).pipe(Option.flatMap(resolvePackageDirectory), Option.exists(packageDirectory => packageDirectory.split(sep).includes('node_modules')));
|
|
61
85
|
const isDevToolsProductionDependency = (root) => findApplicationPackageJsonPath(root).pipe(Option.flatMap(packageJsonPath => readPackageJson(decodeApplicationPackageJson, packageJsonPath)), Option.flatMapNullishOr(packageJson => packageJson.dependencies), Option.exists(Record.has(DEV_TOOLS_PACKAGE_NAME)));
|
|
62
86
|
/**
|
|
63
87
|
* Determines whether the Vite integration should include the DevTools overlay.
|
|
@@ -81,6 +105,18 @@ export const devToolsOverlayPlugin = () => {
|
|
|
81
105
|
let isInjectionEnabled = false;
|
|
82
106
|
return {
|
|
83
107
|
name: 'foldkit:devtools-overlay',
|
|
108
|
+
config: (userConfig, environment) => {
|
|
109
|
+
const root = userConfig.root ?? process.cwd();
|
|
110
|
+
if (environment.command !== 'serve' ||
|
|
111
|
+
!shouldInjectDevToolsOverlay(environment.command, root)) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
const include = DEV_TOOLS_OVERLAY_IMPORTS.filter(({ packageName }) => isPackageResolvedIntoNodeModules(root, packageName)).map(({ specifier }) => specifier);
|
|
115
|
+
return Array.match(include, {
|
|
116
|
+
onEmpty: () => undefined,
|
|
117
|
+
onNonEmpty: () => ({ optimizeDeps: { include } }),
|
|
118
|
+
});
|
|
119
|
+
},
|
|
84
120
|
configResolved: config => {
|
|
85
121
|
isInjectionEnabled = shouldInjectDevToolsOverlay(config.command, config.root);
|
|
86
122
|
},
|
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,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,UAAU,CAAA;AAG7D,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,YAAY,GACb,MAAM,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;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GACtC,QAAQ,CAAC;QACP;;;;;;;WAOG;QACH,KAAK,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAA;KACtC,CAAC,CAAA;IACJ;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC,CAAA;
|
|
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,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,UAAU,CAAA;AAG7D,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,YAAY,GACb,MAAM,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;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GACtC,QAAQ,CAAC;QACP;;;;;;;WAOG;QACH,KAAK,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAAA;KACtC,CAAC,CAAA;IACJ;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC,CAAA;AA+mBF,eAAO,MAAM,OAAO,aAAa,oBAAoB,KAAQ,KAAK,CAAC,MAAM,CAsFxE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array, Console, Data, Duration, Effect, Exit, Fiber, HashMap, HashSet, Match
|
|
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
3
|
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from 'foldkit/hmr-protocol';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
@@ -111,9 +111,9 @@ const makeState = Effect.gen(function* () {
|
|
|
111
111
|
};
|
|
112
112
|
return state;
|
|
113
113
|
});
|
|
114
|
-
const encodeResponseFrameJson =
|
|
114
|
+
const encodeResponseFrameJson = Schema.encodeUnknownSync(Schema.fromJsonString(ResponseFrame));
|
|
115
115
|
// HANDLERS
|
|
116
|
-
const handlePreserveModelReceived = (state, payload) => Exit.match(
|
|
116
|
+
const handlePreserveModelReceived = (state, payload) => Exit.match(Schema.decodeUnknownExit(PreserveModelMessage)(payload), {
|
|
117
117
|
onFailure: error => Console.warn('[foldkit:hmr] failed to decode preserve-model payload', error),
|
|
118
118
|
onSuccess: ({ id, model, isHmrReload }) => Ref.update(state.preservedModels, current => {
|
|
119
119
|
const existingFlag = Option.exists(HashMap.get(current, id), ({ isHmrReload }) => isHmrReload);
|
|
@@ -124,11 +124,11 @@ const handlePreserveModelReceived = (state, payload) => Exit.match(S.decodeUnkno
|
|
|
124
124
|
return HashMap.set(current, id, entry);
|
|
125
125
|
}),
|
|
126
126
|
});
|
|
127
|
-
const handleRequestModelReceived = (server, state, payload) => Exit.match(
|
|
127
|
+
const handleRequestModelReceived = (server, state, payload) => Exit.match(Schema.decodeUnknownExit(RequestModelMessage)(payload), {
|
|
128
128
|
onFailure: error => Console.warn('[foldkit:hmr] failed to decode request-model payload', error),
|
|
129
129
|
onSuccess: ({ id }) => Effect.gen(function* () {
|
|
130
130
|
const current = yield* Ref.get(state.preservedModels);
|
|
131
|
-
const sendRestore = (model) => Effect.sync(() => server.ws.send('foldkit:restore-model',
|
|
131
|
+
const sendRestore = (model) => Effect.sync(() => server.ws.send('foldkit:restore-model', Schema.encodeUnknownSync(RestoreModelMessage)(RestoreModelMessage.make({ id, model }))));
|
|
132
132
|
yield* Option.match(HashMap.get(current, id), {
|
|
133
133
|
onNone: () => sendRestore(undefined),
|
|
134
134
|
onSome: entry => {
|
|
@@ -142,7 +142,7 @@ const handleRequestModelReceived = (server, state, payload) => Exit.match(S.deco
|
|
|
142
142
|
}),
|
|
143
143
|
});
|
|
144
144
|
const handleHotUpdateFired = (state) => Ref.update(state.preservedModels, current => HashMap.map(current, entry => ({ ...entry, isHmrReload: true })));
|
|
145
|
-
const handleBrowserEventFrameReceived = (state, data, client) => Exit.match(
|
|
145
|
+
const handleBrowserEventFrameReceived = (state, data, client) => Exit.match(Schema.decodeUnknownExit(EventFrame)(data), {
|
|
146
146
|
onFailure: error => Console.warn('[foldkit:devTools] failed to decode browser event frame', error),
|
|
147
147
|
onSuccess: frame => DevToolsEvent.match(frame.event, {
|
|
148
148
|
EventConnected: event => handleConnectedEvent(state, event, client),
|
|
@@ -175,7 +175,7 @@ const handleViteClientClosed = (state, client) => Effect.gen(function* () {
|
|
|
175
175
|
yield* Ref.update(state.clientConnections, HashMap.remove(client));
|
|
176
176
|
yield* Ref.update(state.trackedClients, HashSet.remove(client));
|
|
177
177
|
});
|
|
178
|
-
const handleBrowserResponseFrameReceived = (state, data) => Exit.match(
|
|
178
|
+
const handleBrowserResponseFrameReceived = (state, data) => Exit.match(Schema.decodeUnknownExit(ResponseFrame)(data), {
|
|
179
179
|
onFailure: error => Console.warn('[foldkit:devTools] failed to decode browser response frame', error),
|
|
180
180
|
onSuccess: frame => broadcastResponseToMcpClients(state, frame),
|
|
181
181
|
});
|
|
@@ -200,9 +200,9 @@ const handleMcpClientDisconnected = (state, client) => Effect.gen(function* () {
|
|
|
200
200
|
const remaining = HashSet.size(yield* Ref.get(state.mcpClients));
|
|
201
201
|
yield* Console.log(`[foldkit:devTools] MCP client disconnected (${remaining} remaining)`);
|
|
202
202
|
});
|
|
203
|
-
const handleMcpRequestReceived = (server, state, client, raw) => Exit.match(
|
|
203
|
+
const handleMcpRequestReceived = (server, state, client, raw) => Exit.match(Schema.decodeUnknownExit(Schema.fromJsonString(RequestFrame))(raw), {
|
|
204
204
|
onFailure: error => Console.warn('[foldkit:devTools] failed to decode MCP request frame', error),
|
|
205
|
-
onSuccess: frame =>
|
|
205
|
+
onSuccess: frame => Match.value(frame.request).pipe(Match.tag('RequestListRuntimes', () => replyListRuntimes(state, client, frame.id)), Match.orElse(() => forwardRequestToBrowsers(server, frame))),
|
|
206
206
|
});
|
|
207
207
|
const replyListRuntimes = (state, client, requestId) => Effect.gen(function* () {
|
|
208
208
|
const runtimes = pipe(yield* Ref.get(state.connectedRuntimes), HashMap.values, Array.fromIterable);
|
|
@@ -216,9 +216,9 @@ const replyListRuntimes = (state, client, requestId) => Effect.gen(function* ()
|
|
|
216
216
|
}
|
|
217
217
|
});
|
|
218
218
|
});
|
|
219
|
-
const forwardRequestToBrowsers = (server, frame) => Effect.sync(() => server.ws.send('foldkit:devTools:request',
|
|
219
|
+
const forwardRequestToBrowsers = (server, frame) => Effect.sync(() => server.ws.send('foldkit:devTools:request', Schema.encodeUnknownSync(RequestFrame)(frame)));
|
|
220
220
|
// EVENT DISPATCH
|
|
221
|
-
const dispatchEvent = (server, state, event) =>
|
|
221
|
+
const dispatchEvent = (server, state, event) => Match.value(event).pipe(Match.tagsExhaustive({
|
|
222
222
|
PreserveModelReceived: ({ payload }) => handlePreserveModelReceived(state, payload),
|
|
223
223
|
RequestModelReceived: ({ payload }) => handleRequestModelReceived(server, state, payload),
|
|
224
224
|
BrowserEventFrameReceived: ({ data, client }) => handleBrowserEventFrameReceived(state, data, client),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/vite-plugin",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Vite plugin for Foldkit hot module reloading with state preservation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"vite": "^8.2.2",
|
|
35
35
|
"vite7": "npm:vite@^7.3.6",
|
|
36
36
|
"vitest": "^4.1.11",
|
|
37
|
-
"foldkit": "0.
|
|
37
|
+
"foldkit": "0.157.0"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"vite",
|