@foldkit/vite-plugin 0.8.1 → 0.8.3
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/index.d.ts.map +1 -1
- package/dist/index.js +37 -1
- package/package.json +3 -3
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,MAAM,EAAkC,MAAM,MAAM,CAAA;AAGlE,6CAA6C;AAC7C,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAC,CAAA;AA+hBF,eAAO,MAAM,OAAO,GAAI,UAAS,oBAAyB,KAAG,MAqC5D,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Array, Console, Data, Effect, Exit, Fiber, HashMap, HashSet, Match as M, Option, Queue, Ref, Schema as S, Stream, pipe, } from 'effect';
|
|
2
2
|
import { EventFrame, RequestFrame, ResponseFrame, ResponseRuntimes, } from 'foldkit/devtools-protocol';
|
|
3
3
|
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from 'foldkit/hmr-protocol';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { resolve } from 'node:path';
|
|
4
6
|
import { WebSocketServer } from 'ws';
|
|
5
7
|
// NOTE: Vite's dep optimizer scans the consumer's source for `effect`
|
|
6
8
|
// imports and pre-bundles only those exports into a single `effect.js`
|
|
@@ -50,6 +52,37 @@ const FORCE_INCLUDED_EFFECT_NAMESPACES = [
|
|
|
50
52
|
'effect/SubscriptionRef',
|
|
51
53
|
'effect/Types',
|
|
52
54
|
];
|
|
55
|
+
// NOTE: a duplicate `foldkit` instance is its own hazard. If a bundler
|
|
56
|
+
// resolves `foldkit` (or a foldkit-consuming package like `@foldkit/ui`) to
|
|
57
|
+
// more than one copy, the copies get distinct Schema and tagged-message
|
|
58
|
+
// identities (decode and tag matching fail across the boundary) and separate
|
|
59
|
+
// module-level singleton state. `resolve.dedupe` (below) collapses every
|
|
60
|
+
// installed Foldkit package to one resolved copy.
|
|
61
|
+
const FOLDKIT_SINGLETON_PACKAGES = [
|
|
62
|
+
'foldkit',
|
|
63
|
+
'@foldkit/ui',
|
|
64
|
+
'@foldkit/devtools',
|
|
65
|
+
];
|
|
66
|
+
// NOTE: `@foldkit/ui` and `@foldkit/devtools` are optional, so dedupe only
|
|
67
|
+
// the ones the consumer installed. An installed ESM package resolves to
|
|
68
|
+
// ERR_PACKAGE_PATH_NOT_EXPORTED rather than succeeding, so a missing package
|
|
69
|
+
// is signalled only by MODULE_NOT_FOUND.
|
|
70
|
+
const resolveInstalledFoldkitPackages = (root) => {
|
|
71
|
+
// NOTE: `root` (Vite's `config.root`) can be relative at config-hook time,
|
|
72
|
+
// and createRequire requires an absolute path; `resolve` normalizes it.
|
|
73
|
+
const requireFromRoot = createRequire(resolve(root, 'noop.js'));
|
|
74
|
+
return Array.filter(FOLDKIT_SINGLETON_PACKAGES, packageName => {
|
|
75
|
+
try {
|
|
76
|
+
requireFromRoot.resolve(packageName);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return !(error instanceof Error &&
|
|
81
|
+
'code' in error &&
|
|
82
|
+
error.code === 'MODULE_NOT_FOUND');
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
53
86
|
const Event = Data.taggedEnum();
|
|
54
87
|
const makeState = Effect.gen(function* () {
|
|
55
88
|
const preservedModels = yield* Ref.make(HashMap.empty());
|
|
@@ -250,10 +283,13 @@ export const foldkit = (options = {}) => {
|
|
|
250
283
|
return {
|
|
251
284
|
name: 'foldkit-hmr',
|
|
252
285
|
apply: 'serve',
|
|
253
|
-
config:
|
|
286
|
+
config: userConfig => ({
|
|
254
287
|
optimizeDeps: {
|
|
255
288
|
include: [...FORCE_INCLUDED_EFFECT_NAMESPACES],
|
|
256
289
|
},
|
|
290
|
+
resolve: {
|
|
291
|
+
dedupe: resolveInstalledFoldkitPackages(userConfig.root ?? process.cwd()),
|
|
292
|
+
},
|
|
257
293
|
}),
|
|
258
294
|
configureServer: server => {
|
|
259
295
|
const fiber = Effect.runFork(Effect.scoped(main(server, events, options)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/vite-plugin",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Vite plugin for Foldkit hot module reloading with state preservation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"effect": "4.0.0-beta.78",
|
|
20
20
|
"foldkit": "^0",
|
|
21
|
-
"vite": "^8.0.0"
|
|
21
|
+
"vite": "^7.0.0 || ^8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"ws": "^8.20.0"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"rimraf": "^6.1.3",
|
|
30
30
|
"typescript": "^6.0.3",
|
|
31
31
|
"vite": "^8.0.10",
|
|
32
|
-
"foldkit": "0.112.
|
|
32
|
+
"foldkit": "0.112.4"
|
|
33
33
|
},
|
|
34
34
|
"keywords": [
|
|
35
35
|
"vite",
|