@foldkit/vite-plugin 0.29.0-canary.54f8bcd443b4 → 0.29.0-canary.7dfe32f9d0cd
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/brandDist.d.ts.map +1 -1
- package/dist/build.d.ts +0 -4
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +4 -31
- package/dist/buildToken.d.ts +1 -8
- package/dist/buildToken.d.ts.map +1 -1
- package/dist/buildToken.js +3 -31
- package/dist/devToolsOverlay.d.ts +0 -6
- package/dist/devToolsOverlay.d.ts.map +1 -1
- package/dist/devToolsOverlay.js +3 -6
- package/dist/foldkitPackages.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -23
- package/dist/relayRegistry.d.ts.map +1 -1
- package/dist/relayRegistry.js +12 -9
- package/dist/relayRegistryTrust.d.ts.map +1 -1
- package/dist/ssr.d.ts +6 -12
- package/dist/ssr.d.ts.map +1 -1
- package/dist/ssr.js +19 -178
- package/dist/viewIdentity.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/preview.d.ts +0 -4
- package/dist/preview.d.ts.map +0 -1
- package/dist/preview.js +0 -67
- package/dist/relayLiveness.d.ts +0 -6
- package/dist/relayLiveness.d.ts.map +0 -1
- package/dist/relayLiveness.js +0 -80
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ Pass `ssr` with the path to your server entry to render page requests through it
|
|
|
61
61
|
plugins: [foldkit({ ssr: { serverEntry: '/src/entry.server.ts' } })]
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
With this set, the dev server converts HTML page requests to Web `Request` values, passes them to the entry's `renderPage`, and serves the returned `Response`. The request URL retains Vite's configured `base` prefix and the browser's query string. Vite continues to serve the client entry, HMR, and assets, and the server entry runs through
|
|
64
|
+
With this set, the dev server converts HTML page requests to Web `Request` values, passes them to the entry's `renderPage`, and serves the returned `Response`. The request URL retains Vite's configured `base` prefix and the browser's query string. Vite continues to serve the client entry, HMR, and assets, and the server entry runs through Vite's module graph, so edits to it apply without a restart. The client side of the handoff needs no plugin configuration: a server-rendered application's client entry calls `Runtime.hydrate` instead of `Runtime.run`. Hydration adopts matching DOM, rebuilds mismatched subtrees, and refuses an invalid or cross-deployment handoff. The option shapes only the dev server; production hosts import the built server entry themselves. See the [Server Rendering documentation](https://foldkit.dev/core/server-rendering) for the full contract.
|
|
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
|
|
|
@@ -171,10 +171,10 @@ When one Vite app build produces the client and server artifacts, the plugin gen
|
|
|
171
171
|
|
|
172
172
|
```typescript
|
|
173
173
|
// src/entry.server.ts
|
|
174
|
-
Server.renderToString(
|
|
174
|
+
Server.renderToString(config, { flags })
|
|
175
175
|
|
|
176
176
|
// src/entry.ts
|
|
177
|
-
Runtime.hydrate(
|
|
177
|
+
Runtime.hydrate(application)
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
Use the `buildId` option or `FOLDKIT_BUILD_ID` as an explicit override when client and server build in separate jobs, or when the id should name a deployment in another system:
|
package/dist/brandDist.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brandDist.d.ts","sources":["../src/brandDist.ts"],"names":[],"mappings":"AAQA,sEAAsE;AACtE,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,gBAChB,MAAM,eACN,MAAM,KAClB,eAyBF,CAAA"}
|
|
1
|
+
{"version":3,"file":"brandDist.d.ts","sourceRoot":"","sources":["../src/brandDist.ts"],"names":[],"mappings":"AAQA,sEAAsE;AACtE,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,gBAChB,MAAM,eACN,MAAM,KAClB,eAyBF,CAAA"}
|
package/dist/build.d.ts
CHANGED
|
@@ -127,10 +127,6 @@ export declare const renderTargetFor: (clientDirectory: string, path: string, or
|
|
|
127
127
|
* use the server entry's `renderDocument` export with the emitted browser assets.
|
|
128
128
|
* The browser build has a script input and emits no HTML until prerendering.
|
|
129
129
|
* The server bundle's default export is `{ fetch }`.
|
|
130
|
-
*
|
|
131
|
-
* With prerendering enabled, `vite preview` resolves generated directory-index
|
|
132
|
-
* pages at their declared paths. Vite serves the existing files without running
|
|
133
|
-
* the server entry. Custom application hosts retain their own routing.
|
|
134
130
|
*/
|
|
135
131
|
export declare const foldkitBuild: (serverEntry: string, options: FoldkitBuildOptions) => Plugin<FoldkitBuildApi>;
|
|
136
132
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAA;AAS1C,OAAO,QAA8B,MAAM,WAAW,CAAA;AAEtD,OAAO,KAAK,EAGV,MAAM,EAGP,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAA;AAS1C,OAAO,QAA8B,MAAM,WAAW,CAAA;AAEtD,OAAO,KAAK,EAGV,MAAM,EAGP,MAAM,MAAM,CAAA;AAEb,mEAAmE;AACnE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAC,CAAA;AAEF,4EAA4E;AAC5E,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,2HAA2H;IAC3H,WAAW,EAAE,MAAM,CAAA;IACnB,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,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,0BAA0B,CAAA;AAE9D;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;;;OAIG;;IAEH;;;;OAIG;;IAEH,+EAA+E;;IAE/E,2DAA2D;;IAE3D,6EAA6E;;EAE7E,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAA;AAEnE,iFAAiF;AACjF,eAAO,MAAM,oBAAoB;IAC/B,+CAA+C;;IAE/C,kDAAkD;;IAElD,iDAAiD;;IAEjD,kDAAkD;;IAElD,0DAA0D;;QAtC1D;;;;WAIG;;QAEH;;;;WAIG;;QAEH,+EAA+E;;QAE/E,2DAA2D;;QAE3D,6EAA6E;;;EAwB7E,CAAA;AAEF,sEAAsE;AACtE,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAA;AAEnE,2DAA2D;AAC3D,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAA;IACnB,uDAAuD;IACvD,aAAa,EAAE,OAAO,uBAAuB,CAAA;IAC7C;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;CAC7C,CAAC,CAAA;AAcF,eAAO,MAAM,YAAY,SACjB,MAAM,aACD,MAAM,YACR,OAAO,QAAQ,KACvB,MAQF,CAAA;AA6FD,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;AAqLD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,gBACV,MAAM,WACV,mBAAmB,KAC3B,MAAM,CAAC,eAAe,CAwSxB,CAAA"}
|
package/dist/build.js
CHANGED
|
@@ -4,8 +4,6 @@ import { existsSync } from 'node:fs';
|
|
|
4
4
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
5
|
import nodePath, { dirname, resolve } from 'node:path';
|
|
6
6
|
import { pathToFileURL } from 'node:url';
|
|
7
|
-
import { DEV_TOOLS_OVERLAY_MODULE_ID, DEV_TOOLS_OVERLAY_MODULE_SOURCE, RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID, shouldInjectDevToolsOverlay, } from './devToolsOverlay.js';
|
|
8
|
-
import { installPrerenderPreview } from './preview.js';
|
|
9
7
|
/** Vite module id of the fetch handler Foldkit emits as the server entry. */
|
|
10
8
|
export const FOLDKIT_FETCH_MODULE_ID = 'virtual:foldkit/fetch';
|
|
11
9
|
/**
|
|
@@ -282,10 +280,6 @@ const assetsForFetchModule = (assets) => {
|
|
|
282
280
|
* use the server entry's `renderDocument` export with the emitted browser assets.
|
|
283
281
|
* The browser build has a script input and emits no HTML until prerendering.
|
|
284
282
|
* The server bundle's default export is `{ fetch }`.
|
|
285
|
-
*
|
|
286
|
-
* With prerendering enabled, `vite preview` resolves generated directory-index
|
|
287
|
-
* pages at their declared paths. Vite serves the existing files without running
|
|
288
|
-
* the server entry. Custom application hosts retain their own routing.
|
|
289
283
|
*/
|
|
290
284
|
export const foldkitBuild = (serverEntry, options) => {
|
|
291
285
|
const state = {};
|
|
@@ -375,10 +369,7 @@ export const foldkitBuild = (serverEntry, options) => {
|
|
|
375
369
|
};
|
|
376
370
|
return {
|
|
377
371
|
name: 'foldkit:build',
|
|
378
|
-
apply:
|
|
379
|
-
...(prerender === undefined
|
|
380
|
-
? {}
|
|
381
|
-
: { configurePreviewServer: installPrerenderPreview }),
|
|
372
|
+
apply: 'build',
|
|
382
373
|
sharedDuringBuild: true,
|
|
383
374
|
api: {
|
|
384
375
|
serverEntry,
|
|
@@ -413,9 +404,6 @@ export const foldkitBuild = (serverEntry, options) => {
|
|
|
413
404
|
},
|
|
414
405
|
},
|
|
415
406
|
resolveId(id) {
|
|
416
|
-
if (id === DEV_TOOLS_OVERLAY_MODULE_ID) {
|
|
417
|
-
return RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID;
|
|
418
|
-
}
|
|
419
407
|
if (id === CLIENT_MODULE_ID) {
|
|
420
408
|
return RESOLVED_CLIENT_MODULE_ID;
|
|
421
409
|
}
|
|
@@ -425,18 +413,12 @@ export const foldkitBuild = (serverEntry, options) => {
|
|
|
425
413
|
return undefined;
|
|
426
414
|
},
|
|
427
415
|
load(id) {
|
|
428
|
-
if (id === RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID) {
|
|
429
|
-
return DEV_TOOLS_OVERLAY_MODULE_SOURCE;
|
|
430
|
-
}
|
|
431
416
|
if (id === RESOLVED_CLIENT_MODULE_ID) {
|
|
432
417
|
const { modulePreload } = this.environment.config.build;
|
|
433
418
|
const polyfill = modulePreload !== false && modulePreload.polyfill
|
|
434
419
|
? "import 'vite/modulepreload-polyfill'\n"
|
|
435
420
|
: '';
|
|
436
|
-
|
|
437
|
-
? `import ${JSON.stringify(DEV_TOOLS_OVERLAY_MODULE_ID)}\n`
|
|
438
|
-
: '';
|
|
439
|
-
return `${polyfill}${overlay}import ${JSON.stringify(options.clientEntry)}\n`;
|
|
421
|
+
return `${polyfill}import ${JSON.stringify(options.clientEntry)}\n`;
|
|
440
422
|
}
|
|
441
423
|
if (id !== RESOLVED_FETCH_MODULE_ID) {
|
|
442
424
|
return;
|
|
@@ -456,14 +438,10 @@ export const foldkitBuild = (serverEntry, options) => {
|
|
|
456
438
|
state.assets = collectDocumentAssets(Object.values(bundle), this.environment.config);
|
|
457
439
|
},
|
|
458
440
|
},
|
|
459
|
-
config:
|
|
441
|
+
config: userConfig => {
|
|
460
442
|
const client = {
|
|
461
443
|
build: {
|
|
462
|
-
outDir:
|
|
463
|
-
? (userConfig.environments?.['client']?.build?.outDir ??
|
|
464
|
-
userConfig.build?.outDir ??
|
|
465
|
-
clientOutDir)
|
|
466
|
-
: clientOutDir,
|
|
444
|
+
outDir: clientOutDir,
|
|
467
445
|
rolldownOptions: { input: { [CLIENT_CHUNK_NAME]: CLIENT_MODULE_ID } },
|
|
468
446
|
},
|
|
469
447
|
};
|
|
@@ -497,11 +475,6 @@ export const foldkitBuild = (serverEntry, options) => {
|
|
|
497
475
|
: { environments: { client, ssr } };
|
|
498
476
|
},
|
|
499
477
|
configResolved(config) {
|
|
500
|
-
if (config.command === 'build' &&
|
|
501
|
-
(config.environments['client']?.build.watch ||
|
|
502
|
-
config.environments['ssr']?.build.watch)) {
|
|
503
|
-
throw new Error('[foldkit] ssr.build does not support build.watch or vite build --watch. Use the Vite dev server for SSR development, or rerun a full vite build when sources change.');
|
|
504
|
-
}
|
|
505
478
|
if (config.base === '' || config.base === './') {
|
|
506
479
|
throw new Error('[foldkit] ssr.build requires an absolute URL or root-relative base, such as "/" or "/app/". A relative base cannot locate browser assets consistently across server-rendered routes.');
|
|
507
480
|
}
|
package/dist/buildToken.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
/** The development-only module supplying the running server's build identity.
|
|
3
|
-
* @internal */
|
|
4
|
-
export declare const DEVELOPMENT_BUILD_ID_MODULE_ID = "virtual:foldkit/development-build-id";
|
|
5
|
-
/** Vite's resolved id for the development build-identity module.
|
|
6
|
-
* @internal */
|
|
7
|
-
export declare const RESOLVED_DEVELOPMENT_BUILD_ID_MODULE_ID = "\0virtual:foldkit/development-build-id";
|
|
8
2
|
/** The build id explicitly supplied through plugin configuration or the
|
|
9
3
|
* environment, or `undefined` when neither supplied a nonempty value.
|
|
10
4
|
*
|
|
@@ -16,8 +10,7 @@ export declare const resolveBuildId: (configured?: string) => string | undefined
|
|
|
16
10
|
* @internal Exported for tests.
|
|
17
11
|
*/
|
|
18
12
|
export declare const buildIdForCommand: (command: 'build' | 'serve', configured?: string) => string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* inlined production literals.
|
|
13
|
+
/** Compiles one build identity into application entries and Foldkit itself.
|
|
21
14
|
*
|
|
22
15
|
* @internal
|
|
23
16
|
*/
|
package/dist/buildToken.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildToken.d.ts","sources":["../src/buildToken.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAA+B,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"buildToken.d.ts","sourceRoot":"","sources":["../src/buildToken.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAA+B,MAAM,MAAM,CAAA;AAoC/D;;;;GAIG;AACH,eAAO,MAAM,cAAc,gBAAiB,MAAM,KAAG,MAAM,GAAG,SAQ7D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,YACnB,OAAO,GAAG,OAAO,eACb,MAAM,KAClB,MAAM,GAAG,SAMX,CAAA;AA0ID;;;GAGG;AACH,eAAO,MAAM,iBAAiB,aAClB,MAAM,wCAEf,KAAK,CAAC,MAAM,CA+Dd,CAAA"}
|
package/dist/buildToken.js
CHANGED
|
@@ -19,13 +19,6 @@ import { isFoldkitSingletonPackageSpecifier } from './foldkitPackages.js';
|
|
|
19
19
|
// still imports Foldkit externally.
|
|
20
20
|
const BUILD_ID_ENVIRONMENT_VARIABLE = 'FOLDKIT_BUILD_ID';
|
|
21
21
|
const FRAMEWORK_BUILD_ID_PLACEHOLDER = 'foldkitBuildIdPlaceholder()';
|
|
22
|
-
const DEVELOPMENT_BUILD_ID_BINDING = '__foldkitDevelopmentBuildId';
|
|
23
|
-
/** The development-only module supplying the running server's build identity.
|
|
24
|
-
* @internal */
|
|
25
|
-
export const DEVELOPMENT_BUILD_ID_MODULE_ID = 'virtual:foldkit/development-build-id';
|
|
26
|
-
/** Vite's resolved id for the development build-identity module.
|
|
27
|
-
* @internal */
|
|
28
|
-
export const RESOLVED_DEVELOPMENT_BUILD_ID_MODULE_ID = `\0${DEVELOPMENT_BUILD_ID_MODULE_ID}`;
|
|
29
22
|
const buildIdentitySessions = new WeakMap();
|
|
30
23
|
const developmentBuildIds = new WeakMap();
|
|
31
24
|
/** The build id explicitly supplied through plugin configuration or the
|
|
@@ -81,7 +74,6 @@ const buildIdForConfig = (config, configuredBuildId) => {
|
|
|
81
74
|
developmentBuildIds.set(config, fresh);
|
|
82
75
|
return fresh;
|
|
83
76
|
};
|
|
84
|
-
const buildIdLiteral = (buildId) => buildId === undefined ? 'undefined' : JSON.stringify(buildId);
|
|
85
77
|
const replaceAll = (source, code, search, replacement) => {
|
|
86
78
|
let didReplace = false;
|
|
87
79
|
let fromIndex = 0;
|
|
@@ -107,20 +99,13 @@ const transformBuildIdentity = (code, id, config, configuredBuildId) => {
|
|
|
107
99
|
!code.includes(FRAMEWORK_BUILD_ID_PLACEHOLDER)) {
|
|
108
100
|
return undefined;
|
|
109
101
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
: buildIdLiteral(buildIdForConfig(config, configuredBuildId));
|
|
102
|
+
const buildId = buildIdForConfig(config, configuredBuildId);
|
|
103
|
+
const replacement = buildId === undefined ? 'undefined' : JSON.stringify(buildId);
|
|
113
104
|
const transformed = new MagicString(code);
|
|
114
105
|
const transformedFramework = replaceAll(transformed, code, FRAMEWORK_BUILD_ID_PLACEHOLDER, replacement);
|
|
115
106
|
if (!transformedFramework) {
|
|
116
107
|
return undefined;
|
|
117
108
|
}
|
|
118
|
-
if (config.command === 'serve') {
|
|
119
|
-
// NOTE: Vite serves installed dependency modules with immutable caching.
|
|
120
|
-
// Keep their code stable and revalidate the current server's identity
|
|
121
|
-
// through a virtual module, which Vite serves with no-cache and an ETag.
|
|
122
|
-
transformed.prepend(`import { buildId as ${DEVELOPMENT_BUILD_ID_BINDING} } from ${JSON.stringify(DEVELOPMENT_BUILD_ID_MODULE_ID)};\n`);
|
|
123
|
-
}
|
|
124
109
|
return {
|
|
125
110
|
code: transformed.toString(),
|
|
126
111
|
map: transformed.generateMap({ hires: 'boundary', source: id }),
|
|
@@ -142,8 +127,7 @@ const verifyBuildIdentity = (builder) => {
|
|
|
142
127
|
'Remove Foldkit packages from explicit SSR or Rolldown externalization ' +
|
|
143
128
|
'settings and let @foldkit/vite-plugin bundle them.');
|
|
144
129
|
};
|
|
145
|
-
/**
|
|
146
|
-
* inlined production literals.
|
|
130
|
+
/** Compiles one build identity into application entries and Foldkit itself.
|
|
147
131
|
*
|
|
148
132
|
* @internal
|
|
149
133
|
*/
|
|
@@ -170,18 +154,6 @@ export const foldkitBuildToken = (buildId, verifyFrameworkIdentity = true) => {
|
|
|
170
154
|
beginBuildIdentity(builder, configuredBuildId, verifyFrameworkIdentity);
|
|
171
155
|
},
|
|
172
156
|
},
|
|
173
|
-
resolveId(id) {
|
|
174
|
-
return id === DEVELOPMENT_BUILD_ID_MODULE_ID
|
|
175
|
-
? RESOLVED_DEVELOPMENT_BUILD_ID_MODULE_ID
|
|
176
|
-
: undefined;
|
|
177
|
-
},
|
|
178
|
-
load(id) {
|
|
179
|
-
if (id !== RESOLVED_DEVELOPMENT_BUILD_ID_MODULE_ID) {
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
|
-
const buildId = buildIdForConfig(this.environment.getTopLevelConfig(), configuredBuildId);
|
|
183
|
-
return `export const buildId = ${buildIdLiteral(buildId)}\n`;
|
|
184
|
-
},
|
|
185
157
|
transform(code, id) {
|
|
186
158
|
const config = this.environment.getTopLevelConfig();
|
|
187
159
|
return transformBuildIdentity(code, id, config, configuredBuildId);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
/** @internal Virtual module that registers the installed browser overlay. */
|
|
3
|
-
export declare const DEV_TOOLS_OVERLAY_MODULE_ID = "virtual:foldkit-devtools-overlay";
|
|
4
|
-
/** @internal Resolved identity shared by HTML and generated client entries. */
|
|
5
|
-
export declare const RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID = "\0virtual:foldkit-devtools-overlay";
|
|
6
|
-
/** @internal Browser registration used by both client entry paths. */
|
|
7
|
-
export declare const DEV_TOOLS_OVERLAY_MODULE_SOURCE: string;
|
|
8
2
|
/**
|
|
9
3
|
* Determines whether the Vite integration should include the DevTools overlay.
|
|
10
4
|
* Development serves it whenever the package is installed. Production builds
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devToolsOverlay.d.ts","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;AAoIlC;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,YAC7B,OAAO,GAAG,OAAO,QACpB,MAAM,KACX,OAQF,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB,QAAO,MAmExC,CAAA"}
|
package/dist/devToolsOverlay.js
CHANGED
|
@@ -3,14 +3,11 @@ import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
|
3
3
|
import { dirname, join, resolve, sep } from 'node:path';
|
|
4
4
|
const DEV_TOOLS_PACKAGE_NAME = '@foldkit/devtools';
|
|
5
5
|
const DEV_TOOLS_VITE_EXPORT = './vite';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** @internal Resolved identity shared by HTML and generated client entries. */
|
|
9
|
-
export const RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID = `\0${DEV_TOOLS_OVERLAY_MODULE_ID}`;
|
|
6
|
+
const DEV_TOOLS_OVERLAY_MODULE_ID = 'virtual:foldkit-devtools-overlay';
|
|
7
|
+
const RESOLVED_DEV_TOOLS_OVERLAY_MODULE_ID = `\0${DEV_TOOLS_OVERLAY_MODULE_ID}`;
|
|
10
8
|
const DEV_TOOLS_VITE_IMPORT_SPECIFIER = `${DEV_TOOLS_PACKAGE_NAME}${DEV_TOOLS_VITE_EXPORT.slice(1)}`;
|
|
11
9
|
const DEV_TOOLS_HOST_IMPORT_SPECIFIER = 'foldkit/devtools-host';
|
|
12
|
-
|
|
13
|
-
export const DEV_TOOLS_OVERLAY_MODULE_SOURCE = `
|
|
10
|
+
const DEV_TOOLS_OVERLAY_MODULE_SOURCE = `
|
|
14
11
|
import { overlay } from '${DEV_TOOLS_VITE_IMPORT_SPECIFIER}'
|
|
15
12
|
import { __setDevToolsOverlay } from '${DEV_TOOLS_HOST_IMPORT_SPECIFIER}'
|
|
16
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foldkitPackages.d.ts","sources":["../src/foldkitPackages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAA0B,MAAM,MAAM,CAAA;AAS9D;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,cAClC,MAAM,KAChB,OAKA,CAAA;AA8CH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SACzB,MAAM,WACH,OAAO,kBACA,UAAU,KACzB,OAAO,CAAC,QAAQ,CAAC;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAoCxE,CAAA"}
|
|
1
|
+
{"version":3,"file":"foldkitPackages.d.ts","sourceRoot":"","sources":["../src/foldkitPackages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAA0B,MAAM,MAAM,CAAA;AAS9D;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,cAClC,MAAM,KAChB,OAKA,CAAA;AA8CH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SACzB,MAAM,WACH,OAAO,kBACA,UAAU,KACzB,OAAO,CAAC,QAAQ,CAAC;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAoCxE,CAAA"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAEV,MAAM,EAIP,MAAM,MAAM,CAAA;AAQb,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAEV,MAAM,EAIP,MAAM,MAAM,CAAA;AAQb,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,YAAY,CAAA;AAMnE,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,UAAU,CAAA;AAG7D,OAAO,EAAE,KAAK,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,eAAe,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;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAChC;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,IAAI,CACR,iBAAiB,EACjB,SAAS,GAAG,gBAAgB,GAAG,aAAa,GAAG,aAAa,CAC7D,GACC,CACI,QAAQ,CAAC;QACP,kFAAkF;QAClF,WAAW,EAAE,MAAM,CAAA;QACnB,WAAW,CAAC,EAAE,KAAK,CAAA;QACnB;;;;;;;;WAQG;QACH,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAA;KAC3D,CAAC,GACF,QAAQ,CAAC;QACP,kEAAkE;QAClE,WAAW,CAAC,EAAE,KAAK,CAAA;QACnB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,KAAK,CAAC,EAAE,KAAK,CAAA;KACd,CAAC,CACL,CAAA;IACH;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC,CAAA;AAigCF,eAAO,MAAM,OAAO,aAAa,oBAAoB,KAAQ,KAAK,CAAC,MAAM,CA+IxE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,6 @@ import { foldkitBuild } from './build.js';
|
|
|
13
13
|
import { foldkitBuildToken } from './buildToken.js';
|
|
14
14
|
import { devToolsOverlayPlugin } from './devToolsOverlay.js';
|
|
15
15
|
import { crawlFoldkitPackages } from './foldkitPackages.js';
|
|
16
|
-
import { readProcessNamespaces } from './relayLiveness.js';
|
|
17
16
|
import { publishRelayRecord, retireRelayRecord } from './relayRegistry.js';
|
|
18
17
|
import { relayRegistryTrust } from './relayRegistryTrust.js';
|
|
19
18
|
import { foldkitSsr } from './ssr.js';
|
|
@@ -34,7 +33,6 @@ const FORCE_INCLUDED_EFFECT_ENTRIES = [
|
|
|
34
33
|
'effect/Array',
|
|
35
34
|
'effect/Boolean',
|
|
36
35
|
'effect/Cause',
|
|
37
|
-
'effect/Chunk',
|
|
38
36
|
'effect/Clock',
|
|
39
37
|
'effect/Context',
|
|
40
38
|
'effect/Data',
|
|
@@ -52,6 +50,7 @@ const FORCE_INCLUDED_EFFECT_ENTRIES = [
|
|
|
52
50
|
'effect/Layer',
|
|
53
51
|
'effect/Logger',
|
|
54
52
|
'effect/Match',
|
|
53
|
+
'effect/MutableRef',
|
|
55
54
|
'effect/Number',
|
|
56
55
|
'effect/Option',
|
|
57
56
|
'effect/Order',
|
|
@@ -73,7 +72,6 @@ const FORCE_INCLUDED_EFFECT_ENTRIES = [
|
|
|
73
72
|
'effect/String',
|
|
74
73
|
'effect/Struct',
|
|
75
74
|
'effect/SubscriptionRef',
|
|
76
|
-
'effect/Tuple',
|
|
77
75
|
'effect/Types',
|
|
78
76
|
];
|
|
79
77
|
// NOTE: Adding includes to an environment whose optimizer is otherwise disabled
|
|
@@ -108,9 +106,6 @@ const byConnectionOrder = Order.mapInput(Order.Number, ({ sequence }) => sequenc
|
|
|
108
106
|
const handlePreserveModelReceived = (state, payload) => Exit.match(Schema.decodeUnknownExit(PreserveModelMessage)(payload), {
|
|
109
107
|
onFailure: error => Console.warn('[foldkit:preserve] failed to decode preserve-model payload', error),
|
|
110
108
|
onSuccess: ({ id, model, isReloadFlush }) => Ref.update(state.preservedModels, current => {
|
|
111
|
-
if (model === undefined) {
|
|
112
|
-
return HashMap.remove(current, id);
|
|
113
|
-
}
|
|
114
109
|
const existingFlag = Option.exists(HashMap.get(current, id), ({ isReloadFlush }) => isReloadFlush);
|
|
115
110
|
const entry = {
|
|
116
111
|
model,
|
|
@@ -469,7 +464,6 @@ const reportRelayBindFailed = (maybePort, cause) => {
|
|
|
469
464
|
const unpublishedRelayMessage = (reason) => `[foldkit:devTools] Cannot publish the MCP relay address: ${reason}. Set matching devToolsMcpPort and FOLDKIT_DEVTOOLS_MCP_PORT values for MCP access on a trusted network, or set FOLDKIT_DEVTOOLS_RELAY_DIRECTORY to a directory private to your user.`;
|
|
470
465
|
const publishRelay = (root, relay) => Effect.gen(function* () {
|
|
471
466
|
const startedAt = yield* Clock.currentTimeMillis;
|
|
472
|
-
const maybeNamespaces = yield* readProcessNamespaces;
|
|
473
467
|
const directory = yield* publishRelayRecord({
|
|
474
468
|
version: RELAY_RECORD_VERSION,
|
|
475
469
|
id: relay.id,
|
|
@@ -477,10 +471,6 @@ const publishRelay = (root, relay) => Effect.gen(function* () {
|
|
|
477
471
|
url: relay.url,
|
|
478
472
|
pid: process.pid,
|
|
479
473
|
startedAt,
|
|
480
|
-
...Option.match(maybeNamespaces, {
|
|
481
|
-
onNone: () => ({}),
|
|
482
|
-
onSome: namespaces => ({ namespaces }),
|
|
483
|
-
}),
|
|
484
474
|
}, relayRegistryTrust);
|
|
485
475
|
return Option.some(directory);
|
|
486
476
|
}).pipe(Effect.catchTag('RelayRegistryDirectoryRefused', ({ directory, reason }) => Effect.as(Console.error(unpublishedRelayMessage(`the registry directory ${directory} ${reason}`)), Option.none())), Effect.catch(error => Effect.as(Console.error(unpublishedRelayMessage('the registry could not be written'), error), Option.none())));
|
|
@@ -584,18 +574,9 @@ export const foldkit = (options = {}) => {
|
|
|
584
574
|
closeBundle() {
|
|
585
575
|
return Effect.runPromise(stopMain(this.environment.getTopLevelConfig()));
|
|
586
576
|
},
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
// run the server entry's `import.meta.hot.dispose` callback.
|
|
591
|
-
hotUpdate({ type, file, modules, server }) {
|
|
592
|
-
if (type !== 'update' || this.environment.name !== 'client') {
|
|
593
|
-
return undefined;
|
|
594
|
-
}
|
|
595
|
-
const serverModules = server.environments.ssr?.moduleGraph.getModulesByFile(file);
|
|
596
|
-
if (Array.isArrayEmpty(modules) &&
|
|
597
|
-
(serverModules === undefined || serverModules.size === 0)) {
|
|
598
|
-
return undefined;
|
|
577
|
+
handleHotUpdate: ({ server, modules, }) => {
|
|
578
|
+
if (modules.length === 0) {
|
|
579
|
+
return;
|
|
599
580
|
}
|
|
600
581
|
server.ws.send({ type: 'full-reload' });
|
|
601
582
|
const run = mainRuns.get(server.config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayRegistry.d.ts","sources":["../src/relayRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EAEV,IAAI,EACJ,KAAK,aAAa,EAGnB,MAAM,QAAQ,CAAA;AACf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAGL,WAAW,EACZ,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"relayRegistry.d.ts","sourceRoot":"","sources":["../src/relayRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EAEV,IAAI,EACJ,KAAK,aAAa,EAGnB,MAAM,QAAQ,CAAA;AACf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAGL,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAGlC,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,yBAAyB,CAAA;AAUhC,KAAK,qBAAqB,GAAG,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAA;AAE9D,MAAM,MAAM,sBAAsB,GAC9B,qBAAqB,GACrB,mBAAmB,CAAC,mBAAmB,CAAA;;;;AAE3C,qBAAa,6BAA8B,SAAQ,mCAEjD;IACA,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB,CAAC;CAAG;AAkIL,eAAO,MAAM,kBAAkB,WACrB,WAAW,SACZ,kBAAkB,KACxB,MAAM,CAAC,MAAM,CACd,MAAM,EACN,aAAa,CAAC,aAAa,GAAG,6BAA6B,EAC3D,sBAAsB,CA+CpB,CAAA;AAEJ,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAC1C,aAAa,CAAC,WAAW,CAAC,EAC1B,KAAK,EACL,qBAAqB,CAOrB,CAAA;AAEF,eAAO,MAAM,iBAAiB,OACxB,MAAM,aACC,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,aAAa,EAAE,qBAAqB,CAKrE,CAAA"}
|
package/dist/relayRegistry.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Array, Config, Data, Effect, FileSystem, Option, Path, Schema, String, } from 'effect';
|
|
2
2
|
import { RELAY_REGISTRY_DIRECTORY_NAME, RELAY_REGISTRY_DIRECTORY_VARIABLE, RelayRecord, } from 'foldkit/devtools-protocol';
|
|
3
3
|
import { homedir, tmpdir } from 'node:os';
|
|
4
|
-
import { checkRelay, readProcessNamespaces } from './relayLiveness.js';
|
|
5
4
|
import { windowsTempRootRefusal, } from './relayRegistryTrust.js';
|
|
6
5
|
const RUNTIME_DIRECTORY_VARIABLE = 'XDG_RUNTIME_DIR';
|
|
7
6
|
const RECORD_FILE_EXTENSION = '.json';
|
|
@@ -26,6 +25,15 @@ const relayRecordPath = (directory, id) => Effect.gen(function* () {
|
|
|
26
25
|
const path = yield* Path.Path;
|
|
27
26
|
return path.join(directory, `${encodeURIComponent(id)}${RECORD_FILE_EXTENSION}`);
|
|
28
27
|
});
|
|
28
|
+
const isProcessAlive = (pid) => {
|
|
29
|
+
try {
|
|
30
|
+
process.kill(pid, 0);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return error instanceof Error && 'code' in error && error.code === 'EPERM';
|
|
35
|
+
}
|
|
36
|
+
};
|
|
29
37
|
const readRecordFile = (filePath) => Effect.gen(function* () {
|
|
30
38
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
31
39
|
const raw = yield* fileSystem.readFileString(filePath);
|
|
@@ -60,16 +68,11 @@ const retireStaleRecord = (filePath, record) => Effect.gen(function* () {
|
|
|
60
68
|
});
|
|
61
69
|
const removeDeadRecords = (directory) => Effect.gen(function* () {
|
|
62
70
|
const filePaths = yield* recordFilePaths(directory);
|
|
63
|
-
const maybeOwnNamespaces = yield* readProcessNamespaces;
|
|
64
71
|
yield* Effect.forEach(filePaths, filePath => Effect.gen(function* () {
|
|
65
72
|
const maybeRecord = yield* readRecordFile(filePath);
|
|
66
|
-
if (Option.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const record = maybeRecord.value;
|
|
70
|
-
const status = yield* checkRelay(record, maybeOwnNamespaces);
|
|
71
|
-
if (status === 'Gone') {
|
|
72
|
-
yield* retireStaleRecord(filePath, record);
|
|
73
|
+
if (Option.isSome(maybeRecord) &&
|
|
74
|
+
!isProcessAlive(maybeRecord.value.pid)) {
|
|
75
|
+
yield* retireStaleRecord(filePath, maybeRecord.value);
|
|
73
76
|
}
|
|
74
77
|
}), { discard: true });
|
|
75
78
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayRegistryTrust.d.ts","sources":["../src/relayRegistryTrust.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EACV,MAAM,EAIP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAyElE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,OAAO,EAAE,CACP,SAAS,EAAE,MAAM,KACd,MAAM,CAAC,MAAM,CAChB,uBAAuB,EACvB,KAAK,EACL,mBAAmB,CAAC,mBAAmB,CACxC,CAAA;CACF,CAAC,CAAA;AAEF,KAAK,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,CAAA;AAE/D,eAAO,MAAM,6BAA6B,SAClC,aAAa,mBACF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KACrC,MAAM,CAAC,MAAM,CAAC,MAAM,CAkBnB,CAAA;AA2OJ,eAAO,MAAM,uBAAuB,SAC5B,MAAM,kBACI,MAAM,KACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAwCtB,CAAA;AAuFD,eAAO,MAAM,4BAA4B,gBAC1B,aAAa,CAAC,MAAM,CAAC,kBAClB,MAAM,KACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAwEtB,CAAA;AAED,eAAO,MAAM,cAAc,eAAgB,MAAM,KAAG,MAOjD,CAAA;AAEH,eAAO,MAAM,sBAAsB,cACtB,MAAM,YACP,MAAM,KACf,MAAM,CAAC,MAAM,CAAC,MAAM,CAGgB,CAAA;AAuHvC,eAAO,MAAM,qBAAqB,oBACf,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,aAC3B,MAAM,KAChB,MAAM,CAAC,MAAM,CACd,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EACrB,KAAK,EACL,mBAAmB,CAAC,mBAAmB,CAQrC,CAAA;AA+BJ,eAAO,MAAM,kBAAkB,EAAE,kBAgFhC,CAAA"}
|
|
1
|
+
{"version":3,"file":"relayRegistryTrust.d.ts","sourceRoot":"","sources":["../src/relayRegistryTrust.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EACV,MAAM,EAIP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAyElE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,OAAO,EAAE,CACP,SAAS,EAAE,MAAM,KACd,MAAM,CAAC,MAAM,CAChB,uBAAuB,EACvB,KAAK,EACL,mBAAmB,CAAC,mBAAmB,CACxC,CAAA;CACF,CAAC,CAAA;AAEF,KAAK,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,CAAA;AAE/D,eAAO,MAAM,6BAA6B,SAClC,aAAa,mBACF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KACrC,MAAM,CAAC,MAAM,CAAC,MAAM,CAkBnB,CAAA;AA2OJ,eAAO,MAAM,uBAAuB,SAC5B,MAAM,kBACI,MAAM,KACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAwCtB,CAAA;AAuFD,eAAO,MAAM,4BAA4B,gBAC1B,aAAa,CAAC,MAAM,CAAC,kBAClB,MAAM,KACrB,MAAM,CAAC,MAAM,CAAC,MAAM,CAwEtB,CAAA;AAED,eAAO,MAAM,cAAc,eAAgB,MAAM,KAAG,MAOjD,CAAA;AAEH,eAAO,MAAM,sBAAsB,cACtB,MAAM,YACP,MAAM,KACf,MAAM,CAAC,MAAM,CAAC,MAAM,CAGgB,CAAA;AAuHvC,eAAO,MAAM,qBAAqB,oBACf,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,aAC3B,MAAM,KAChB,MAAM,CAAC,MAAM,CACd,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EACrB,KAAK,EACL,mBAAmB,CAAC,mBAAmB,CAQrC,CAAA;AA+BJ,eAAO,MAAM,kBAAkB,EAAE,kBAgFhC,CAAA"}
|
package/dist/ssr.d.ts
CHANGED
|
@@ -53,19 +53,13 @@ export type FoldkitSsrOptions = Readonly<{
|
|
|
53
53
|
* Serves server-rendered pages from the Vite dev server.
|
|
54
54
|
*
|
|
55
55
|
* Vite retains ownership of configured proxies, source modules, HMR, and
|
|
56
|
-
* assets. Requests that fall through load the server entry through
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
56
|
+
* assets. Requests that fall through load the server entry through Vite's SSR
|
|
57
|
+
* module loader, call its `renderPage` with a Web `Request`, and send the
|
|
58
|
+
* resulting Web `Response`. Vite's host validation applies before either
|
|
59
|
+
* owner. Foldkit then validates and normalizes the request target before Vite
|
|
60
|
+
* or the server entry can resolve it. Vite's CORS option applies only to
|
|
61
61
|
* Vite-owned responses, while the server entry owns CORS for application
|
|
62
|
-
* responses. Server entry edits take effect without a restart.
|
|
63
|
-
* entry accepts its own updates, and the server graph is reevaluated so Block
|
|
64
|
-
* Definitions and their declarations are created together. Unless
|
|
65
|
-
* `server.hmr` is `false`, an `import.meta.hot.dispose` callback in the entry
|
|
66
|
-
* runs before a hot update replaces it. With HMR disabled, stop and restart
|
|
67
|
-
* the dev-server process after editing server modules that own long-lived
|
|
68
|
-
* resources; an in-process restart cannot invoke the missing callback.
|
|
62
|
+
* responses. Server entry edits take effect without a restart.
|
|
69
63
|
*/
|
|
70
64
|
export declare const foldkitSsr: (options: FoldkitSsrOptions) => Plugin;
|
|
71
65
|
//# sourceMappingURL=ssr.d.ts.map
|
package/dist/ssr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.d.ts","sources":["../src/ssr.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../src/ssr.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,MAAM,EAGP,MAAM,MAAM,CAAA;AAIb,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC,CAAA;AA6tBF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,YAAa,iBAAiB,KAAG,MAyGvD,CAAA"}
|
package/dist/ssr.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Array, Effect,
|
|
1
|
+
import { Array, Effect, Predicate } from 'effect';
|
|
2
2
|
import * as Server from 'foldkit/experimental/server';
|
|
3
|
-
import MagicString from 'magic-string';
|
|
4
3
|
import { readFile } from 'node:fs/promises';
|
|
5
4
|
import { resolve } from 'node:path';
|
|
6
5
|
import { Readable } from 'node:stream';
|
|
@@ -11,87 +10,6 @@ import { buildIdForCommand } from './buildToken.js';
|
|
|
11
10
|
// getter is the shape every copy shares, and `in` reads its descriptor without
|
|
12
11
|
// invoking it.
|
|
13
12
|
const isRunnable = (environment) => 'runner' in environment;
|
|
14
|
-
const isHotServerEnvironment = (environment) => environment.name === 'ssr' &&
|
|
15
|
-
environment.config.server.hmr !== false &&
|
|
16
|
-
isRunnable(environment);
|
|
17
|
-
// NOTE: Vite reruns an edited declaration module and its importers, but keeps
|
|
18
|
-
// imported Block Definitions. Invalidate the full server graph so the next
|
|
19
|
-
// entry evaluation creates each Definition before registering its declarations.
|
|
20
|
-
const invalidateServerModulesForReevaluation = (environment) => {
|
|
21
|
-
const { moduleGraph } = environment;
|
|
22
|
-
const invalidatedModules = new Set();
|
|
23
|
-
for (const module of moduleGraph.idToModuleMap.values()) {
|
|
24
|
-
moduleGraph.invalidateModule(module, invalidatedModules, undefined, false, true);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const reevaluatedServerEntries = new WeakMap();
|
|
28
|
-
// NOTE: Vite invalidates the edited file after async watchChange hooks settle.
|
|
29
|
-
// Non-HMR requests can arrive during those hooks, so refresh the graph only
|
|
30
|
-
// after Vite changes the entry's stamp. Record our resulting stamp before
|
|
31
|
-
// importing so concurrent requests reuse that same evaluation.
|
|
32
|
-
const importServerEntry = async (environment, serverEntry) => {
|
|
33
|
-
if (environment.config.server.hmr === false) {
|
|
34
|
-
const entry = await environment.moduleGraph.ensureEntryFromUrl(serverEntry);
|
|
35
|
-
const previousTimestamp = reevaluatedServerEntries.get(entry);
|
|
36
|
-
if (previousTimestamp !== undefined &&
|
|
37
|
-
previousTimestamp !== entry.lastInvalidationTimestamp) {
|
|
38
|
-
invalidateServerModulesForReevaluation(environment);
|
|
39
|
-
}
|
|
40
|
-
reevaluatedServerEntries.set(entry, entry.lastInvalidationTimestamp);
|
|
41
|
-
}
|
|
42
|
-
return environment.runner.import(serverEntry);
|
|
43
|
-
};
|
|
44
|
-
const SERVER_UPDATE_SETTLED_EVENT = 'foldkit:server-update-settled';
|
|
45
|
-
const SERVER_UPDATE_SETTLE_TIMEOUT_MS = 1_000;
|
|
46
|
-
// NOTE: The entry accepts updates so Vite runs its `import.meta.hot.dispose`
|
|
47
|
-
// callback before evaluating the replacement. The server graph is invalidated
|
|
48
|
-
// separately so every Block Definition is recreated with its declarations.
|
|
49
|
-
// The entry also reports each update payload the runner finishes handling, so
|
|
50
|
-
// the dev server can hold requests until then.
|
|
51
|
-
const SERVER_ENTRY_HOT_SOURCE = `if (import.meta.hot) {
|
|
52
|
-
import.meta.hot.accept()
|
|
53
|
-
const reportSettledUpdate = () => {
|
|
54
|
-
import.meta.hot.send(${JSON.stringify(SERVER_UPDATE_SETTLED_EVENT)})
|
|
55
|
-
}
|
|
56
|
-
import.meta.hot.on('vite:afterUpdate', reportSettledUpdate)
|
|
57
|
-
import.meta.hot.on('vite:beforeFullReload', reportSettledUpdate)
|
|
58
|
-
import.meta.hot.on('vite:error', reportSettledUpdate)
|
|
59
|
-
}
|
|
60
|
-
`;
|
|
61
|
-
// NOTE: Vite invalidates the edited modules before it sends the update to the
|
|
62
|
-
// module runner. A request that imports the server entry in between evaluates
|
|
63
|
-
// a new copy, whose `dispose` callback replaces the old copy's, so the old copy
|
|
64
|
-
// is never released. The gate counts the edits to modules in the `ssr` module
|
|
65
|
-
// graph and holds requests until the entry reports each one settled. The
|
|
66
|
-
// timeout releases them when an edit never reaches the runner.
|
|
67
|
-
const makeServerUpdateGate = () => {
|
|
68
|
-
const settled = Latch.makeUnsafe(true);
|
|
69
|
-
let pendingUpdateCount = 0;
|
|
70
|
-
let settleTimeout;
|
|
71
|
-
const release = () => {
|
|
72
|
-
pendingUpdateCount = 0;
|
|
73
|
-
clearTimeout(settleTimeout);
|
|
74
|
-
settled.openUnsafe();
|
|
75
|
-
};
|
|
76
|
-
const beginUpdate = () => {
|
|
77
|
-
pendingUpdateCount += 1;
|
|
78
|
-
settled.closeUnsafe();
|
|
79
|
-
clearTimeout(settleTimeout);
|
|
80
|
-
settleTimeout = setTimeout(release, SERVER_UPDATE_SETTLE_TIMEOUT_MS).unref();
|
|
81
|
-
};
|
|
82
|
-
const settleUpdate = () => {
|
|
83
|
-
pendingUpdateCount = Math.max(0, pendingUpdateCount - 1);
|
|
84
|
-
if (pendingUpdateCount === 0) {
|
|
85
|
-
release();
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
beginUpdate,
|
|
90
|
-
settleUpdate,
|
|
91
|
-
awaitSettledUpdates: settled.await,
|
|
92
|
-
close: release,
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
13
|
const isEntryModule = (loadedModule) => Predicate.isObject(loadedModule) &&
|
|
96
14
|
Predicate.hasProperty(loadedModule, 'renderPage') &&
|
|
97
15
|
Predicate.isFunction(loadedModule.renderPage);
|
|
@@ -211,11 +129,10 @@ const renderDecision = (nodeRequest, requestUrl) => {
|
|
|
211
129
|
}
|
|
212
130
|
return 'Render';
|
|
213
131
|
};
|
|
214
|
-
const renderRequest = (server,
|
|
132
|
+
const renderRequest = (server, options, nodeRequest, requestUrl) => Effect.gen(function* () {
|
|
215
133
|
const { pathname, search } = new URL(requestUrl);
|
|
216
134
|
const route = `${pathname}${search}`;
|
|
217
|
-
yield*
|
|
218
|
-
const loadedModule = yield* Effect.promise(() => importServerEntry(ssrEnvironment, options.serverEntry));
|
|
135
|
+
const loadedModule = yield* Effect.promise(() => server.ssrLoadModule(options.serverEntry));
|
|
219
136
|
if (!isEntryModule(loadedModule)) {
|
|
220
137
|
return yield* Effect.die(new Error(`[foldkit] '${options.serverEntry}' does not export a renderPage function, so the dev server cannot render pages.`));
|
|
221
138
|
}
|
|
@@ -491,7 +408,7 @@ const sendWebResponse = async (webResponse, nodeRequest, nodeResponse, isNegotia
|
|
|
491
408
|
// The handler that turns an application-owned request into a response. OPTIONS
|
|
492
409
|
// reaches it at the host boundary. Other methods reach it after Vite's modules
|
|
493
410
|
// and assets have had an opportunity to answer.
|
|
494
|
-
const renderMiddleware = (server,
|
|
411
|
+
const renderMiddleware = (server, options, requestUrls, stateByRequest) => (nodeRequest, nodeResponse, next) => {
|
|
495
412
|
const corsState = stateByRequest.get(nodeRequest);
|
|
496
413
|
stateByRequest.delete(nodeRequest);
|
|
497
414
|
corsState?.tracking.stop();
|
|
@@ -535,35 +452,29 @@ const renderMiddleware = (server, ssrEnvironment, serverUpdates, options, reques
|
|
|
535
452
|
return;
|
|
536
453
|
}
|
|
537
454
|
const isNegotiated = decision === 'RenderNegotiated';
|
|
538
|
-
void Effect.runPromise(renderRequest(server,
|
|
455
|
+
void Effect.runPromise(renderRequest(server, options, nodeRequest, requestUrl))
|
|
539
456
|
.then(response => sendWebResponse(response, nodeRequest, nodeResponse, isNegotiated))
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
457
|
+
.catch((error) => {
|
|
458
|
+
if (error instanceof Error) {
|
|
459
|
+
server.ssrFixStacktrace(error);
|
|
460
|
+
}
|
|
461
|
+
next(error);
|
|
462
|
+
});
|
|
544
463
|
};
|
|
545
464
|
/**
|
|
546
465
|
* Serves server-rendered pages from the Vite dev server.
|
|
547
466
|
*
|
|
548
467
|
* Vite retains ownership of configured proxies, source modules, HMR, and
|
|
549
|
-
* assets. Requests that fall through load the server entry through
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
468
|
+
* assets. Requests that fall through load the server entry through Vite's SSR
|
|
469
|
+
* module loader, call its `renderPage` with a Web `Request`, and send the
|
|
470
|
+
* resulting Web `Response`. Vite's host validation applies before either
|
|
471
|
+
* owner. Foldkit then validates and normalizes the request target before Vite
|
|
472
|
+
* or the server entry can resolve it. Vite's CORS option applies only to
|
|
554
473
|
* Vite-owned responses, while the server entry owns CORS for application
|
|
555
|
-
* responses. Server entry edits take effect without a restart.
|
|
556
|
-
* entry accepts its own updates, and the server graph is reevaluated so Block
|
|
557
|
-
* Definitions and their declarations are created together. Unless
|
|
558
|
-
* `server.hmr` is `false`, an `import.meta.hot.dispose` callback in the entry
|
|
559
|
-
* runs before a hot update replaces it. With HMR disabled, stop and restart
|
|
560
|
-
* the dev-server process after editing server modules that own long-lived
|
|
561
|
-
* resources; an in-process restart cannot invoke the missing callback.
|
|
474
|
+
* responses. Server entry edits take effect without a restart.
|
|
562
475
|
*/
|
|
563
476
|
export const foldkitSsr = (options) => {
|
|
564
477
|
let isDevelopmentHost = false;
|
|
565
|
-
const entryIds = new WeakMap();
|
|
566
|
-
const serverUpdates = makeServerUpdateGate();
|
|
567
478
|
return {
|
|
568
479
|
name: 'foldkit-ssr',
|
|
569
480
|
configResolved(config) {
|
|
@@ -607,65 +518,6 @@ export const foldkitSsr = (options) => {
|
|
|
607
518
|
}),
|
|
608
519
|
};
|
|
609
520
|
},
|
|
610
|
-
perEnvironmentWatchChangeDuringDev: true,
|
|
611
|
-
watchChange(id, change) {
|
|
612
|
-
if (!isDevelopmentHost ||
|
|
613
|
-
change.event !== 'update' ||
|
|
614
|
-
this.environment.name !== 'ssr' ||
|
|
615
|
-
!isRunnable(this.environment)) {
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
const serverModules = this.environment.moduleGraph.getModulesByFile(id);
|
|
619
|
-
if (serverModules !== undefined && serverModules.size > 0) {
|
|
620
|
-
if (isHotServerEnvironment(this.environment)) {
|
|
621
|
-
serverUpdates.beginUpdate();
|
|
622
|
-
invalidateServerModulesForReevaluation(this.environment);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
// NOTE: Vite invalidates the server entry when a module it imports
|
|
627
|
-
// dynamically changes, even when the runner has not loaded that module,
|
|
628
|
-
// but sends the runner no update for it. The next request would then
|
|
629
|
-
// evaluate a new copy without disposing the old one, so the update goes to
|
|
630
|
-
// the entry instead.
|
|
631
|
-
hotUpdate({ type, file, modules }) {
|
|
632
|
-
if (!isDevelopmentHost ||
|
|
633
|
-
type !== 'update' ||
|
|
634
|
-
!isHotServerEnvironment(this.environment) ||
|
|
635
|
-
Array.isArrayEmpty(modules)) {
|
|
636
|
-
return undefined;
|
|
637
|
-
}
|
|
638
|
-
const entryId = entryIds.get(this.environment);
|
|
639
|
-
const evaluatedModules = this.environment.runner.evaluatedModules.getModulesByFile(file);
|
|
640
|
-
if (entryId === undefined ||
|
|
641
|
-
(evaluatedModules !== undefined && evaluatedModules.size > 0)) {
|
|
642
|
-
return undefined;
|
|
643
|
-
}
|
|
644
|
-
const entryModule = this.environment.moduleGraph.getModuleById(entryId);
|
|
645
|
-
return entryModule === undefined ? undefined : [entryModule];
|
|
646
|
-
},
|
|
647
|
-
async transform(code, id) {
|
|
648
|
-
if (!isDevelopmentHost ||
|
|
649
|
-
this.environment.name !== 'ssr' ||
|
|
650
|
-
!isRunnable(this.environment)) {
|
|
651
|
-
return undefined;
|
|
652
|
-
}
|
|
653
|
-
const entryId = entryIds.get(this.environment) ??
|
|
654
|
-
(await this.resolve(options.serverEntry).catch(() => undefined))?.id;
|
|
655
|
-
if (entryId === undefined) {
|
|
656
|
-
return undefined;
|
|
657
|
-
}
|
|
658
|
-
entryIds.set(this.environment, entryId);
|
|
659
|
-
if (entryId !== id) {
|
|
660
|
-
return undefined;
|
|
661
|
-
}
|
|
662
|
-
const transformed = new MagicString(code);
|
|
663
|
-
transformed.prepend(SERVER_ENTRY_HOT_SOURCE);
|
|
664
|
-
return {
|
|
665
|
-
code: transformed.toString(),
|
|
666
|
-
map: transformed.generateMap({ hires: 'boundary', source: id }),
|
|
667
|
-
};
|
|
668
|
-
},
|
|
669
521
|
configureServer: server => {
|
|
670
522
|
// Rendering here loads the server entry through the `ssr` environment's
|
|
671
523
|
// module runner, which only a runnable environment has. A host plugin
|
|
@@ -676,8 +528,7 @@ export const foldkitSsr = (options) => {
|
|
|
676
528
|
// them here instead would run the application in Node, without the
|
|
677
529
|
// bindings the deployed entry holds, while the deployment it is standing
|
|
678
530
|
// in for renders in workerd.
|
|
679
|
-
|
|
680
|
-
if (!isRunnable(ssrEnvironment)) {
|
|
531
|
+
if (!isRunnable(server.environments.ssr)) {
|
|
681
532
|
if (options.quietStandDown !== true) {
|
|
682
533
|
server.config.logger.warn('[foldkit] the "ssr" environment is not runnable, so another plugin owns' +
|
|
683
534
|
" server-side execution. Dev-time rendering through Foldkit's Vite" +
|
|
@@ -687,22 +538,12 @@ export const foldkitSsr = (options) => {
|
|
|
687
538
|
}
|
|
688
539
|
const requestUrls = new WeakMap();
|
|
689
540
|
const stateByRequest = new WeakMap();
|
|
690
|
-
|
|
691
|
-
const render = renderMiddleware(server, ssrEnvironment, serverUpdates, options, requestUrls, stateByRequest);
|
|
541
|
+
const render = renderMiddleware(server, options, requestUrls, stateByRequest);
|
|
692
542
|
server.middlewares.use(requestTargetMiddleware(server, options, requestUrls, render));
|
|
693
543
|
wrapViteCors(server, options, requestUrls, stateByRequest);
|
|
694
544
|
return () => {
|
|
695
545
|
server.middlewares.use(render);
|
|
696
546
|
};
|
|
697
547
|
},
|
|
698
|
-
closeBundle() {
|
|
699
|
-
if (!isDevelopmentHost ||
|
|
700
|
-
this.environment.name !== 'ssr' ||
|
|
701
|
-
!isRunnable(this.environment)) {
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
this.environment.hot.off(SERVER_UPDATE_SETTLED_EVENT, serverUpdates.settleUpdate);
|
|
705
|
-
serverUpdates.close();
|
|
706
|
-
},
|
|
707
548
|
};
|
|
708
549
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewIdentity.d.ts","sources":["../src/viewIdentity.ts"],"names":[],"mappings":"AAAA,OAAoB,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAI1D,OAAO,EAAE,KAAK,MAAM,EAAY,MAAM,MAAM,CAAA;AA6a5C,iFAAiF;AACjF,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,SAAS,CAAA;CACf,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,qBAAqB,SAC1B,MAAM,MACR,MAAM,QACJ,MAAM,YACF,QAAQ,CAAC;IACjB,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAC,KACD,2BAA2B,GAAG,IAyChC,CAAA;AA8DD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QAAO,MA0CtC,CAAA"}
|
|
1
|
+
{"version":3,"file":"viewIdentity.d.ts","sourceRoot":"","sources":["../src/viewIdentity.ts"],"names":[],"mappings":"AAAA,OAAoB,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAI1D,OAAO,EAAE,KAAK,MAAM,EAAY,MAAM,MAAM,CAAA;AA6a5C,iFAAiF;AACjF,MAAM,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IACjD,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,SAAS,CAAA;CACf,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,qBAAqB,SAC1B,MAAM,MACR,MAAM,QACJ,MAAM,YACF,QAAQ,CAAC;IACjB,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAC,KACD,2BAA2B,GAAG,IAyChC,CAAA;AA8DD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QAAO,MA0CtC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/vite-plugin",
|
|
3
|
-
"version": "0.29.0-canary.
|
|
3
|
+
"version": "0.29.0-canary.7dfe32f9d0cd",
|
|
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.1.0",
|
|
20
|
-
"foldkit": "0.170.0-canary.
|
|
20
|
+
"foldkit": "0.170.0-canary.7dfe32f9d0cd",
|
|
21
21
|
"vite": "^8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@types/ws": "^8.18.1",
|
|
33
33
|
"@vitejs/plugin-basic-ssl": "^2.3.0",
|
|
34
34
|
"effect": "4.1.0",
|
|
35
|
-
"foldkit": "0.170.0-canary.
|
|
36
|
-
"happy-dom": "^
|
|
35
|
+
"foldkit": "0.170.0-canary.7dfe32f9d0cd",
|
|
36
|
+
"happy-dom": "^20.14.5",
|
|
37
37
|
"rimraf": "^6.1.3",
|
|
38
|
-
"typescript": "7.
|
|
39
|
-
"vite": "^8.3.
|
|
40
|
-
"vite-host": "npm:vite@8.2.
|
|
41
|
-
"vitest": "^4.1.
|
|
38
|
+
"typescript": "^7.0.2",
|
|
39
|
+
"vite": "^8.3.1",
|
|
40
|
+
"vite-host": "npm:vite@8.2.1",
|
|
41
|
+
"vitest": "^4.1.11"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"vite",
|
package/dist/preview.d.ts
DELETED
package/dist/preview.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sources":["../src/preview.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,aAAa,EAAE,MAAM,MAAM,CAAA;AAgElD,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,WAAY,aAAa,KAAG,IA6B/D,CAAA"}
|
package/dist/preview.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
-
import { resolve, sep } from 'node:path';
|
|
3
|
-
const isContained = (root, file) => file.startsWith(root.endsWith(sep) ? root : `${root}${sep}`);
|
|
4
|
-
const rewriteDirectoryIndex = (request, root, base, isProxied) => {
|
|
5
|
-
const { method, headers, url } = request;
|
|
6
|
-
if ((method !== 'GET' && method !== 'HEAD') ||
|
|
7
|
-
url === undefined ||
|
|
8
|
-
isProxied(url) ||
|
|
9
|
-
isProxied(url.replace(/(\?|$)/, '/index.html$1')) ||
|
|
10
|
-
(headers.accept &&
|
|
11
|
-
!headers.accept.includes('text/html') &&
|
|
12
|
-
!headers.accept.includes('*/*'))) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const [pathname = ''] = url.split('?');
|
|
16
|
-
if (!pathname.startsWith('/') ||
|
|
17
|
-
pathname.startsWith('//') ||
|
|
18
|
-
pathname.includes('#') ||
|
|
19
|
-
!pathname.startsWith(base)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const route = pathname.slice(base.length);
|
|
23
|
-
if (route === '' || route.endsWith('/')) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const segments = route.split('/').map(segment => decodeURIComponent(segment));
|
|
27
|
-
if (segments.join('/') !== decodeURI(route) ||
|
|
28
|
-
segments.some(segment => /^\.{1,2}$|[/\\\u0000:]/.test(segment))) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const file = resolve(root, ...segments);
|
|
32
|
-
if (!isContained(root, file) ||
|
|
33
|
-
file.endsWith('.html') ||
|
|
34
|
-
statSync(file, { throwIfNoEntry: false })?.isFile() ||
|
|
35
|
-
statSync(resolve(file, 'index'), { throwIfNoEntry: false })?.isFile() ||
|
|
36
|
-
existsSync(`${file}.html`)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const index = realpathSync(resolve(file, 'index.html'));
|
|
40
|
-
if (isContained(realpathSync(root), index) && statSync(index).isFile()) {
|
|
41
|
-
request.url = `${pathname}/index.html${url.slice(pathname.length)}`;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
/** @internal Resolve generated directory indexes through Vite's preview pipeline. */
|
|
45
|
-
export const installPrerenderPreview = (server) => {
|
|
46
|
-
if (server.config.appType === 'custom') {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const client = server.config.environments['client'];
|
|
50
|
-
if (client === undefined) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const root = resolve(server.config.root, client.build.outDir);
|
|
54
|
-
const isProxied = (url) => Object.entries(server.config.preview.proxy ?? {}).some(([context, options]) => Boolean(options) &&
|
|
55
|
-
(context.startsWith('^')
|
|
56
|
-
? new RegExp(context).test(url)
|
|
57
|
-
: url.startsWith(context)));
|
|
58
|
-
server.middlewares.use((request, _response, next) => {
|
|
59
|
-
try {
|
|
60
|
-
rewriteDirectoryIndex(request, root, server.config.base, isProxied);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
return next();
|
|
64
|
-
}
|
|
65
|
-
next();
|
|
66
|
-
});
|
|
67
|
-
};
|
package/dist/relayLiveness.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Effect, FileSystem, Option } from 'effect';
|
|
2
|
-
import type { RelayNamespaces, RelayRecord } from 'foldkit/devtools-protocol';
|
|
3
|
-
export type RelayStatus = 'Running' | 'Gone' | 'Unreachable';
|
|
4
|
-
export declare const readProcessNamespaces: Effect.Effect<Option.Option<RelayNamespaces>, never, FileSystem.FileSystem>;
|
|
5
|
-
export declare const checkRelay: (record: RelayRecord, maybeOwnNamespaces: Option.Option<RelayNamespaces>) => Effect.Effect<RelayStatus>;
|
|
6
|
-
//# sourceMappingURL=relayLiveness.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relayLiveness.d.ts","sources":["../src/relayLiveness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,UAAU,EAAU,MAAM,EAAU,MAAM,QAAQ,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAW7E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,aAAa,CAAA;AAE5D,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAC/C,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,EAC9B,KAAK,EACL,UAAU,CAAC,UAAU,CAO4C,CAAA;AA2DnE,eAAO,MAAM,UAAU,WACb,WAAW,sBACC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,KACjD,MAAM,CAAC,MAAM,CAAC,WAAW,CAqC3B,CAAA"}
|
package/dist/relayLiveness.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Duration, Effect, FileSystem, Number, Option, String } from 'effect';
|
|
2
|
-
import { connect } from 'node:net';
|
|
3
|
-
const NAMESPACE_DIRECTORY = '/proc/self/ns';
|
|
4
|
-
const PROBE_TIMEOUT = Duration.seconds(1);
|
|
5
|
-
const WEBSOCKET_PORT = 80;
|
|
6
|
-
const SECURE_WEBSOCKET_PORT = 443;
|
|
7
|
-
const IPV6_BRACKETS = /^\[|\]$/g;
|
|
8
|
-
export const readProcessNamespaces = Effect.gen(function* () {
|
|
9
|
-
const fileSystem = yield* FileSystem.FileSystem;
|
|
10
|
-
const pid = yield* fileSystem.readLink(`${NAMESPACE_DIRECTORY}/pid`);
|
|
11
|
-
const network = yield* fileSystem.readLink(`${NAMESPACE_DIRECTORY}/net`);
|
|
12
|
-
return Option.some({ pid, network });
|
|
13
|
-
}).pipe(Effect.orElseSucceed(() => Option.none()));
|
|
14
|
-
const isProcessAlive = (pid) => {
|
|
15
|
-
try {
|
|
16
|
-
process.kill(pid, 0);
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
return error instanceof Error && 'code' in error && error.code === 'EPERM';
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const relayAddress = (url) => Option.flatMap(Option.fromNullishOr(URL.parse(url)), parsed => {
|
|
24
|
-
const host = parsed.hostname.replace(IPV6_BRACKETS, '');
|
|
25
|
-
if (String.isNonEmpty(parsed.port)) {
|
|
26
|
-
return Option.map(Number.parse(parsed.port), port => ({ host, port }));
|
|
27
|
-
}
|
|
28
|
-
else if (parsed.protocol === 'wss:') {
|
|
29
|
-
return Option.some({ host, port: SECURE_WEBSOCKET_PORT });
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return Option.some({ host, port: WEBSOCKET_PORT });
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const refusesConnections = ({ host, port, }) => Effect.callback(resume => {
|
|
36
|
-
const socket = connect({ host, port });
|
|
37
|
-
const settle = (isRefused) => {
|
|
38
|
-
socket.destroy();
|
|
39
|
-
resume(Effect.succeed(isRefused));
|
|
40
|
-
};
|
|
41
|
-
socket.once('connect', () => settle(false));
|
|
42
|
-
socket.once('error', error => settle('code' in error && error.code === 'ECONNREFUSED'));
|
|
43
|
-
return Effect.sync(() => socket.destroy());
|
|
44
|
-
}).pipe(Effect.timeoutOption(PROBE_TIMEOUT), Effect.map(Option.getOrElse(() => false)));
|
|
45
|
-
const statusFromPort = (url) => Option.match(relayAddress(url), {
|
|
46
|
-
onNone: () => Effect.succeed('Running'),
|
|
47
|
-
onSome: address => Effect.map(refusesConnections(address), (isRefused) => isRefused ? 'Gone' : 'Running'),
|
|
48
|
-
});
|
|
49
|
-
// NOTE: kill(pid, 0) answers for this process's PID namespace only. A relay
|
|
50
|
-
// published from another PID namespace looks dead even while it runs, so its
|
|
51
|
-
// record counts as gone only when its port refuses connections. A relay in
|
|
52
|
-
// another network namespace listens on a loopback this process cannot reach.
|
|
53
|
-
export const checkRelay = (record, maybeOwnNamespaces) => {
|
|
54
|
-
const maybeRecordNamespaces = Option.fromNullishOr(record.namespaces);
|
|
55
|
-
const maybeBothNamespaces = Option.all([
|
|
56
|
-
maybeOwnNamespaces,
|
|
57
|
-
maybeRecordNamespaces,
|
|
58
|
-
]);
|
|
59
|
-
const hasNoNamespaces = Option.isNone(maybeOwnNamespaces) && Option.isNone(maybeRecordNamespaces);
|
|
60
|
-
const isSamePidNamespace = Option.exists(maybeBothNamespaces, ([own, recorded]) => own.pid === recorded.pid);
|
|
61
|
-
const isOtherNetworkNamespace = Option.exists(maybeBothNamespaces, ([own, recorded]) => own.network !== recorded.network);
|
|
62
|
-
if (Option.isSome(maybeRecordNamespaces) &&
|
|
63
|
-
Option.isNone(maybeOwnNamespaces)) {
|
|
64
|
-
return Effect.succeed('Unreachable');
|
|
65
|
-
}
|
|
66
|
-
else if (isOtherNetworkNamespace) {
|
|
67
|
-
return Effect.succeed('Unreachable');
|
|
68
|
-
}
|
|
69
|
-
else if (isSamePidNamespace ||
|
|
70
|
-
(hasNoNamespaces && process.platform !== 'linux')) {
|
|
71
|
-
return Effect.succeed(isProcessAlive(record.pid) ? 'Running' : 'Gone');
|
|
72
|
-
}
|
|
73
|
-
else if (Option.isNone(maybeRecordNamespaces) &&
|
|
74
|
-
isProcessAlive(record.pid)) {
|
|
75
|
-
return Effect.succeed('Running');
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return statusFromPort(record.url);
|
|
79
|
-
}
|
|
80
|
-
};
|