@vesk/adapter 0.2.15 → 0.2.17
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/client-bundle.d.ts.map +1 -1
- package/dist/client-bundle.js +243 -35
- package/dist/css.d.ts +6 -11
- package/dist/css.d.ts.map +1 -1
- package/dist/css.js +19 -38
- package/dist/dev-config.d.ts.map +1 -1
- package/dist/dev-config.js +139 -3
- package/dist/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js +90 -1
- package/dist/events.d.ts +9 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +109 -0
- package/dist/hmr.d.ts.map +1 -1
- package/dist/hmr.js +33 -43
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -34
- package/dist/manifest.d.ts +1 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +2 -1
- package/dist/platform-deploy.d.ts.map +1 -1
- package/dist/platform-deploy.js +1 -0
- package/dist/platform-handler.d.ts +2 -0
- package/dist/platform-handler.d.ts.map +1 -1
- package/dist/platform-handler.js +14 -2
- package/dist/prod-server.d.ts.map +1 -1
- package/dist/prod-server.js +62 -15
- package/dist/runtime-bundle.d.ts.map +1 -1
- package/dist/runtime-bundle.js +10 -0
- package/dist/ssr-function.d.ts.map +1 -1
- package/dist/ssr-function.js +43 -32
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -3,10 +3,11 @@ import { resolve, dirname, relative, basename } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { bundleRuntime } from '@vesk/adapter/src/runtime-bundle';
|
|
5
5
|
import { generateSsrFunction } from '@vesk/adapter/src/ssr-function';
|
|
6
|
-
import { resolveUserCssPath,
|
|
6
|
+
import { resolveUserCssPath, isTailwindPlugin, resolveCssUrls, hasBuiltGlobalCss } from '@vesk/adapter/src/css';
|
|
7
7
|
import { collectActionIds } from '@vesk/compiler/src/actions';
|
|
8
8
|
import { generateApiFunction } from '@vesk/adapter/src/api-function';
|
|
9
9
|
import { compileMiddleware, compileMiddlewareCode } from '@vesk/adapter/src/middleware';
|
|
10
|
+
import { compileEvents } from '@vesk/adapter/src/events';
|
|
10
11
|
import { generateClientBundle } from '@vesk/adapter/src/client-bundle';
|
|
11
12
|
import { generateManifest } from '@vesk/adapter/src/manifest';
|
|
12
13
|
import { copyStaticAssets } from '@vesk/adapter/src/static';
|
|
@@ -152,43 +153,25 @@ export async function build(appDir, options) {
|
|
|
152
153
|
const cssSourcePath = resolveUserCssPath(appDir);
|
|
153
154
|
if (cssSourcePath !== null) {
|
|
154
155
|
const cssContent = readFileSync(cssSourcePath, 'utf-8');
|
|
155
|
-
const
|
|
156
|
-
const userCssTarget = resolve(outDir, 'static', 'global.css');
|
|
157
|
-
writeFileSync(userCssTarget, userCss, 'utf-8');
|
|
158
|
-
console.error(`vesk build: css → static/global.css (${userCss.length} bytes)`);
|
|
159
|
-
const twCssTarget = resolve(outDir, 'static', '_tailwind.css');
|
|
156
|
+
const cssTarget = resolve(outDir, 'static', 'global.css');
|
|
160
157
|
const tailwindActive = isTailwindPlugin(pluginsPipelines);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
console.error('vesk build: css → static/_tailwind.css (empty, tailwind plugin inactive)');
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
let twCss = cssContent;
|
|
158
|
+
let finalCss = cssContent;
|
|
159
|
+
if (tailwindActive) {
|
|
167
160
|
for (const plugin of pluginsPipelines) {
|
|
168
161
|
if (typeof plugin.onCSS === 'function') {
|
|
169
|
-
const result = await plugin.onCSS(
|
|
162
|
+
const result = await plugin.onCSS(finalCss, cssSourcePath);
|
|
170
163
|
if (result !== null && typeof result === 'string') {
|
|
171
|
-
|
|
164
|
+
finalCss = result;
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
167
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
writeFileSync(twCssTarget, twCss, 'utf-8');
|
|
185
|
-
console.error(`vesk build: css → static/_tailwind.css (${twCss.length} bytes, tailwind partially unresolved)`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
writeFileSync(twCssTarget, twCss, 'utf-8');
|
|
190
|
-
console.error(`vesk build: css → static/_tailwind.css (${twCss.length} bytes)`);
|
|
191
|
-
}
|
|
168
|
+
}
|
|
169
|
+
writeFileSync(cssTarget, finalCss, 'utf-8');
|
|
170
|
+
if (tailwindActive) {
|
|
171
|
+
console.error(`vesk build: css → static/global.css (${finalCss.length} bytes)`);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.error(`vesk build: css → static/global.css (${finalCss.length} bytes, tailwind plugin inactive)`);
|
|
192
175
|
}
|
|
193
176
|
}
|
|
194
177
|
const { scanRoutes, scanComponents } = await resolveCompilerApi('router.js');
|
|
@@ -280,6 +263,9 @@ export async function build(appDir, options) {
|
|
|
280
263
|
console.error(`vesk build: mw → server/middleware.js (${mwChain.length} middlewares)`);
|
|
281
264
|
}
|
|
282
265
|
}
|
|
266
|
+
const hasEvents = await compileEvents(appDir, outDir);
|
|
267
|
+
if (hasEvents)
|
|
268
|
+
console.error('vesk build: evt → server/events.js (onStart/onRequest/onStop)');
|
|
283
269
|
console.error('vesk build: bundling client runtime...');
|
|
284
270
|
const bundleOpts = {};
|
|
285
271
|
if (options?.codeSplit)
|
|
@@ -307,8 +293,7 @@ export async function build(appDir, options) {
|
|
|
307
293
|
if (options?.ssg) {
|
|
308
294
|
const { generateSsgRoutes } = await import('./static.js');
|
|
309
295
|
const cssUrls = resolveCssUrls({
|
|
310
|
-
|
|
311
|
-
userCss: hasUserCss(appDir),
|
|
296
|
+
enabled: hasBuiltGlobalCss(outDir),
|
|
312
297
|
});
|
|
313
298
|
prerenderedRoutes = await generateSsgRoutes(routeTree, appDir, outDir, pluginsPipelines, pluginHeadExtra, cssUrls);
|
|
314
299
|
console.error(`vesk build: ssg → prerendered/ (${prerenderedRoutes.length} pages)`);
|
|
@@ -345,7 +330,7 @@ export async function build(appDir, options) {
|
|
|
345
330
|
console.error(`vesk build: seo → static/public/robots.txt (${robots.length} bytes)`);
|
|
346
331
|
}
|
|
347
332
|
}
|
|
348
|
-
const manifest = generateManifest(routeTree, ssrRoutes, apiRoutes, prerenderedRoutes, middlewareEnabled, actionMap, pluginHeadExtra);
|
|
333
|
+
const manifest = generateManifest(routeTree, ssrRoutes, apiRoutes, prerenderedRoutes, middlewareEnabled, actionMap, pluginHeadExtra, hasEvents);
|
|
349
334
|
writeFileSync(resolve(outDir, 'config.json'), JSON.stringify(manifest, null, 2) + '\n', 'utf-8');
|
|
350
335
|
console.error('vesk build: config → config.json');
|
|
351
336
|
{
|
|
@@ -362,6 +347,7 @@ export async function build(appDir, options) {
|
|
|
362
347
|
prerenderedPaths: prerenderedRoutes.map(r => r.path),
|
|
363
348
|
prerenderedRoutes,
|
|
364
349
|
hasMiddleware: middlewareEnabled,
|
|
350
|
+
hasEvents,
|
|
365
351
|
});
|
|
366
352
|
if (outRoot) {
|
|
367
353
|
console.error(`vesk build: ${platform} → ${relative(projectRoot, outRoot)}`);
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RouteNode, ApiRouteNode, Manifest, SsgRouteResult } from '@vesk/adapter/src/types';
|
|
2
|
-
export declare function generateManifest(routes: RouteNode[], ssrRoutes: RouteNode[], apiRoutes: ApiRouteNode[], staticRoutes: SsgRouteResult[], middlewareEnabled: boolean, actionMap?: Record<string, string>, headExtra?: string): Manifest;
|
|
2
|
+
export declare function generateManifest(routes: RouteNode[], ssrRoutes: RouteNode[], apiRoutes: ApiRouteNode[], staticRoutes: SsgRouteResult[], middlewareEnabled: boolean, actionMap?: Record<string, string>, headExtra?: string, eventsEnabled?: boolean): Manifest;
|
|
3
3
|
//# sourceMappingURL=manifest.d.ts.map
|
package/dist/manifest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAqE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEpK,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,EAAE,EACnB,SAAS,EAAE,SAAS,EAAE,EACtB,SAAS,EAAE,YAAY,EAAE,EACzB,YAAY,EAAE,cAAc,EAAE,EAC9B,iBAAiB,EAAE,OAAO,EAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,SAAS,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAqE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEpK,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,EAAE,EACnB,SAAS,EAAE,SAAS,EAAE,EACtB,SAAS,EAAE,YAAY,EAAE,EACzB,YAAY,EAAE,cAAc,EAAE,EAC9B,iBAAiB,EAAE,OAAO,EAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,UAAQ,GACpB,QAAQ,CAmDV"}
|
package/dist/manifest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function generateManifest(routes, ssrRoutes, apiRoutes, staticRoutes, middlewareEnabled, actionMap, headExtra) {
|
|
1
|
+
export function generateManifest(routes, ssrRoutes, apiRoutes, staticRoutes, middlewareEnabled, actionMap, headExtra, eventsEnabled = false) {
|
|
2
2
|
const routeEntries = [];
|
|
3
3
|
for (const r of ssrRoutes) {
|
|
4
4
|
const urlParts = r.fullPath.split('/').filter(Boolean);
|
|
@@ -44,5 +44,6 @@ export function generateManifest(routes, ssrRoutes, apiRoutes, staticRoutes, mid
|
|
|
44
44
|
},
|
|
45
45
|
...(actionEntries.length > 0 ? { actions: actionEntries } : {}),
|
|
46
46
|
...(headExtra ? { headExtra } : {}),
|
|
47
|
+
...(eventsEnabled ? { events: true } : {}),
|
|
47
48
|
};
|
|
48
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-deploy.d.ts","sourceRoot":"","sources":["../src/platform-deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwD,KAAK,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAErI,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,WAAW,aAAc,SAAQ,oBAAoB;IACzD,iBAAiB,EAAE,cAAc,EAAE,CAAC;CACrC;AA0BD;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"platform-deploy.d.ts","sourceRoot":"","sources":["../src/platform-deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwD,KAAK,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAErI,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,WAAW,aAAc,SAAQ,oBAAoB;IACzD,iBAAiB,EAAE,cAAc,EAAE,CAAC;CACrC;AA0BD;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0EvG"}
|
package/dist/platform-deploy.js
CHANGED
|
@@ -21,6 +21,7 @@ export async function emitPlatformOutput(platform, ctx) {
|
|
|
21
21
|
apiRoutes: ctx.apiRoutes,
|
|
22
22
|
prerenderedPaths,
|
|
23
23
|
hasMiddleware: ctx.hasMiddleware,
|
|
24
|
+
hasEvents: ctx.hasEvents,
|
|
24
25
|
});
|
|
25
26
|
const shell = shellFor(platform);
|
|
26
27
|
const projectRoot = resolve(ctx.outDir, '..');
|
|
@@ -4,6 +4,7 @@ export interface PlatformHandlerInput {
|
|
|
4
4
|
apiRoutes: ApiRouteNode[];
|
|
5
5
|
prerenderedPaths: string[];
|
|
6
6
|
hasMiddleware: boolean;
|
|
7
|
+
hasEvents?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare function routeName(segments: string[]): string;
|
|
9
10
|
export declare function apiRouteName(fullPath: string): string;
|
|
@@ -28,5 +29,6 @@ export interface PlatformBuildContext {
|
|
|
28
29
|
apiRoutes: ApiRouteNode[];
|
|
29
30
|
prerenderedPaths: string[];
|
|
30
31
|
hasMiddleware: boolean;
|
|
32
|
+
hasEvents?: boolean;
|
|
31
33
|
}
|
|
32
34
|
//# sourceMappingURL=platform-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-handler.d.ts","sourceRoot":"","sources":["../src/platform-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvE,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"platform-handler.d.ts","sourceRoot":"","sources":["../src/platform-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvE,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAQD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CA8IjF;AAED,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsFzF;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
|
package/dist/platform-handler.js
CHANGED
|
@@ -31,6 +31,7 @@ function findCompilerSrc() {
|
|
|
31
31
|
*/
|
|
32
32
|
export function generatePlatformHandlerSource(input) {
|
|
33
33
|
const { ssrRoutes, apiRoutes, prerenderedPaths, hasMiddleware } = input;
|
|
34
|
+
const hasEvents = !!input.hasEvents;
|
|
34
35
|
let imports = '';
|
|
35
36
|
const routeEntries = [];
|
|
36
37
|
for (const r of ssrRoutes) {
|
|
@@ -51,10 +52,15 @@ export function generatePlatformHandlerSource(input) {
|
|
|
51
52
|
}
|
|
52
53
|
const mwImport = hasMiddleware ? "import { execute as __executeMw } from './server/middleware.js';" : '';
|
|
53
54
|
const hasMwLiteral = hasMiddleware ? 'true' : 'false';
|
|
55
|
+
const eventsImport = hasEvents ? "import { executeStart as __eventsStart, executeRequest as __eventsRequest } from './server/events.js';" : '';
|
|
54
56
|
const prerenderedList = prerenderedPaths.length > 0
|
|
55
57
|
? `const __prerendered = new Set(${JSON.stringify(prerenderedPaths)});\n`
|
|
56
58
|
: 'const __prerendered = new Set();\n';
|
|
57
59
|
const isrCache = 'const __isrCache = new Map();';
|
|
60
|
+
const serverStoreLine = hasEvents ? 'const __serverStore = globalThis.__vesk_server_ctx || {};' : '';
|
|
61
|
+
const eventsStartLine = hasEvents ? ' await __eventsStart({ server: null });' : '';
|
|
62
|
+
const eventsRequestLine = hasEvents ? ' await __eventsRequest(mwCtx);' : '';
|
|
63
|
+
const localsSeed = hasEvents ? 'Object.assign({}, __serverStore)' : '{}';
|
|
58
64
|
const compilerSrc = findCompilerSrc();
|
|
59
65
|
const parseCookiesImport = hasMiddleware
|
|
60
66
|
? `import { parseCookies } from ${JSON.stringify(resolve(compilerSrc, 'server-cookies.js'))};`
|
|
@@ -63,6 +69,7 @@ export function generatePlatformHandlerSource(input) {
|
|
|
63
69
|
${imports}
|
|
64
70
|
${parseCookiesImport}
|
|
65
71
|
${mwImport}
|
|
72
|
+
${eventsImport}
|
|
66
73
|
${prerenderedList}
|
|
67
74
|
${isrCache}
|
|
68
75
|
const __routes = [${routeEntries.join(',\n')}];
|
|
@@ -91,23 +98,28 @@ export async function handleRequest(request) {
|
|
|
91
98
|
const url = new URL(request.url);
|
|
92
99
|
const pathname = url.pathname;
|
|
93
100
|
const isDataRequest = request.headers.get('x-vesk-data') === '1';
|
|
101
|
+
${serverStoreLine}
|
|
94
102
|
|
|
95
103
|
if (__prerendered.has(pathname) && !isDataRequest) {
|
|
96
104
|
return new Response(null, { status: 308, headers: { Location: '/_vesk/static/public' + (pathname.endsWith('/') ? pathname + 'index.html' : pathname + '.html') } });
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
|
|
107
|
+
${eventsStartLine}
|
|
108
|
+
let mwCtx = { params: {}, url, locals: ${localsSeed}, cookies: {}, request, resolveUrl(u) { return new URL(u, request.url).href; }, set() {}, get() { return undefined; } };
|
|
100
109
|
if (${hasMwLiteral}) {
|
|
101
110
|
mwCtx = {
|
|
102
111
|
request,
|
|
103
112
|
params: {},
|
|
104
113
|
url,
|
|
105
|
-
locals: {},
|
|
114
|
+
locals: ${localsSeed},
|
|
106
115
|
cookies: typeof parseCookies !== 'undefined' ? parseCookies(request.headers.get('cookie') || '') : {},
|
|
107
116
|
resolveUrl(u) { return new URL(u, request.url).href; },
|
|
108
117
|
set(key, value) { this.locals[key] = value; },
|
|
109
118
|
get(key) { return this.locals[key]; },
|
|
110
119
|
};
|
|
120
|
+
}
|
|
121
|
+
${eventsRequestLine}
|
|
122
|
+
if (${hasMwLiteral}) {
|
|
111
123
|
const mwResult = await __executeMw(mwCtx);
|
|
112
124
|
if (mwResult.response) return mwResult.response;
|
|
113
125
|
if (mwResult.rewriteUrl) url.pathname = mwResult.rewriteUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prod-server.d.ts","sourceRoot":"","sources":["../src/prod-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2D,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AA+CjG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAIzE;AA+FD,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"prod-server.d.ts","sourceRoot":"","sources":["../src/prod-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2D,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AA+CjG,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAIzE;AA+FD,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAkcxI"}
|
package/dist/prod-server.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
6
6
|
import { createRateLimiter, resolveComponentName, safeJsonForScript, getClientProtocol, DEFAULT_MAX_BODY_BYTES } from '@vesk/compiler/src/server-codegen';
|
|
7
7
|
import { securityHeaders } from '@vesk/compiler/src/server-utils';
|
|
8
8
|
import { resolveWithin, installMdReadHook } from '@vesk/adapter/src/paths';
|
|
9
|
-
import { resolveCssUrls,
|
|
9
|
+
import { resolveCssUrls, hasBuiltGlobalCss } from '@vesk/adapter/src/css';
|
|
10
10
|
const _require = createRequire(import.meta.url);
|
|
11
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
async function readBody(req, maxBytes = DEFAULT_MAX_BODY_BYTES) {
|
|
@@ -192,6 +192,16 @@ export async function startProdServer(outDir, options) {
|
|
|
192
192
|
// ignore
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
+
let eventsMod = null;
|
|
196
|
+
const eventsPath = resolve(outDir, 'server', 'events.js');
|
|
197
|
+
if (existsSync(eventsPath)) {
|
|
198
|
+
try {
|
|
199
|
+
eventsMod = await import(`${eventsPath}?t=${Date.now()}`);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// ignore
|
|
203
|
+
}
|
|
204
|
+
}
|
|
195
205
|
const functionCache = new Map();
|
|
196
206
|
async function loadFunction(funcPath) {
|
|
197
207
|
if (functionCache.has(funcPath))
|
|
@@ -325,38 +335,49 @@ export async function startProdServer(outDir, options) {
|
|
|
325
335
|
}
|
|
326
336
|
}
|
|
327
337
|
let mwCtx;
|
|
338
|
+
const serverStore = globalThis.__vesk_server_ctx;
|
|
328
339
|
if (middlewareMod) {
|
|
329
340
|
mwCtx = {
|
|
330
341
|
request: new Request(url.href, { headers: req.headers, method: req.method || 'GET' }),
|
|
331
342
|
params: {},
|
|
332
343
|
url,
|
|
333
|
-
locals: {},
|
|
344
|
+
locals: Object.assign({}, serverStore || {}),
|
|
334
345
|
cookies: {},
|
|
335
346
|
set(key, value) { this.locals[key] = value; },
|
|
336
347
|
get(key) { return this.locals[key]; },
|
|
337
348
|
};
|
|
338
|
-
const mwResult = await middlewareMod.execute(mwCtx);
|
|
339
|
-
if (mwResult.response) {
|
|
340
|
-
const body = await mwResult.response.text();
|
|
341
|
-
res.writeHead(mwResult.response.status, Object.fromEntries(mwResult.response.headers));
|
|
342
|
-
res.end(body);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (mwResult.rewriteUrl) {
|
|
346
|
-
url.pathname = mwResult.rewriteUrl;
|
|
347
|
-
}
|
|
348
349
|
}
|
|
349
350
|
else {
|
|
350
351
|
mwCtx = {
|
|
351
352
|
params: {},
|
|
352
353
|
url,
|
|
353
|
-
locals: {},
|
|
354
|
+
locals: Object.assign({}, serverStore || {}),
|
|
354
355
|
cookies: {},
|
|
355
356
|
request: null,
|
|
356
357
|
set() { },
|
|
357
358
|
get() { return undefined; },
|
|
358
359
|
};
|
|
359
360
|
}
|
|
361
|
+
if (eventsMod) {
|
|
362
|
+
try {
|
|
363
|
+
await eventsMod.executeRequest?.(mwCtx);
|
|
364
|
+
}
|
|
365
|
+
catch (e) {
|
|
366
|
+
console.error('vesk request: onRequest error:', e instanceof Error ? e.message : e);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (middlewareMod) {
|
|
370
|
+
const mwResult = await middlewareMod.execute(mwCtx);
|
|
371
|
+
if (mwResult.response) {
|
|
372
|
+
const body = await mwResult.response.text();
|
|
373
|
+
res.writeHead(mwResult.response.status, Object.fromEntries(mwResult.response.headers));
|
|
374
|
+
res.end(body);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (mwResult.rewriteUrl) {
|
|
378
|
+
url.pathname = mwResult.rewriteUrl;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
360
381
|
// Expose root middleware locals to API/SSR handlers (which seed their own
|
|
361
382
|
// ctx.locals from this before running route-level middleware).
|
|
362
383
|
globalThis.__vesk_request = mwCtx;
|
|
@@ -415,8 +436,7 @@ export async function startProdServer(outDir, options) {
|
|
|
415
436
|
}
|
|
416
437
|
const appDir = resolve(projectDir, 'app');
|
|
417
438
|
const pageCssUrls = resolveCssUrls({
|
|
418
|
-
|
|
419
|
-
userCss: hasUserCss(appDir),
|
|
439
|
+
enabled: hasBuiltGlobalCss(outDir),
|
|
420
440
|
});
|
|
421
441
|
const nfPath = resolve(appDir, 'not-found.vsk');
|
|
422
442
|
let notFoundHtml = null;
|
|
@@ -510,6 +530,33 @@ export async function startProdServer(outDir, options) {
|
|
|
510
530
|
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
511
531
|
res.end(notFoundHtml || '<!DOCTYPE html><html><body><h1>404</h1><p>Not Found</p></body></html>');
|
|
512
532
|
});
|
|
533
|
+
try {
|
|
534
|
+
await eventsMod?.executeStart?.({ server, port, host });
|
|
535
|
+
}
|
|
536
|
+
catch (e) {
|
|
537
|
+
console.error('vesk start: onStart error:', e instanceof Error ? e.message : e);
|
|
538
|
+
}
|
|
539
|
+
server.on('close', () => {
|
|
540
|
+
void (async () => {
|
|
541
|
+
try {
|
|
542
|
+
await eventsMod?.executeStop?.({ server, port, host });
|
|
543
|
+
}
|
|
544
|
+
catch (e) {
|
|
545
|
+
console.error('vesk stop: onStop error:', e instanceof Error ? e.message : e);
|
|
546
|
+
}
|
|
547
|
+
})();
|
|
548
|
+
});
|
|
549
|
+
let shuttingDown = false;
|
|
550
|
+
function shutdown(signal) {
|
|
551
|
+
if (shuttingDown)
|
|
552
|
+
return;
|
|
553
|
+
shuttingDown = true;
|
|
554
|
+
console.error(`vesk stop: received ${signal}, closing…`);
|
|
555
|
+
server.close(() => process.exit(0));
|
|
556
|
+
setTimeout(() => process.exit(0), 3000).unref();
|
|
557
|
+
}
|
|
558
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
559
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
513
560
|
server.listen(port, host, () => {
|
|
514
561
|
console.error(`vesk production server at http://localhost:${port} (listening on ${host})`);
|
|
515
562
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-bundle.d.ts","sourceRoot":"","sources":["../src/runtime-bundle.ts"],"names":[],"mappings":"AAuCA,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"runtime-bundle.d.ts","sourceRoot":"","sources":["../src/runtime-bundle.ts"],"names":[],"mappings":"AAuCA,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqHnF"}
|
package/dist/runtime-bundle.js
CHANGED
|
@@ -113,6 +113,16 @@ export async function bundleRuntime(appDir, outDir) {
|
|
|
113
113
|
'export const clearActions = __veskRuntime.clearActions;',
|
|
114
114
|
'export const validateActionInput = __veskRuntime.validateActionInput;',
|
|
115
115
|
'export const issuesToFieldMap = __veskRuntime.issuesToFieldMap;',
|
|
116
|
+
'',
|
|
117
|
+
'// Server-wide context store (server events)',
|
|
118
|
+
'export const serverLocals = __veskRuntime.serverLocals;',
|
|
119
|
+
'export const getServerContext = __veskRuntime.getServerContext;',
|
|
120
|
+
'export const setServerContext = __veskRuntime.setServerContext;',
|
|
121
|
+
'export const clearServerContext = __veskRuntime.clearServerContext;',
|
|
122
|
+
'export const server_locals = __veskRuntime.server_locals;',
|
|
123
|
+
'export const get_server_context = __veskRuntime.get_server_context;',
|
|
124
|
+
'export const set_server_context = __veskRuntime.set_server_context;',
|
|
125
|
+
'export const clear_server_context = __veskRuntime.clear_server_context;',
|
|
116
126
|
].join('\n');
|
|
117
127
|
writeFileSync(entryFile, entryContent, 'utf-8');
|
|
118
128
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-function.d.ts","sourceRoot":"","sources":["../src/ssr-function.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAW7F,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjF;AAiDD,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"ssr-function.d.ts","sourceRoot":"","sources":["../src/ssr-function.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAW7F,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjF;AAiDD,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAoYtD"}
|
package/dist/ssr-function.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from 'node:fs';
|
|
2
2
|
import { resolve, relative, join } from 'node:path';
|
|
3
3
|
import { resolveComponentName } from '@vesk/compiler/src/server-codegen';
|
|
4
|
-
import { resolveCssUrls,
|
|
4
|
+
import { resolveCssUrls, hasBuiltGlobalCss } from '@vesk/adapter/src/css';
|
|
5
5
|
function escapeSource(src) {
|
|
6
6
|
return src
|
|
7
7
|
.replace(/\\/g, '\\\\')
|
|
@@ -75,22 +75,35 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
75
75
|
const middlewareCode = options?.middlewareCode || null;
|
|
76
76
|
const headExtra = options?.headExtra || null;
|
|
77
77
|
const pagePath = resolve(appDir, routeNode.sourceDir, 'page.vsk');
|
|
78
|
-
const layoutPath = resolve(appDir, routeNode.sourceDir, 'layout.vsk');
|
|
79
78
|
const parts = routeNode.fullPath.split('/').filter(Boolean);
|
|
80
79
|
const name = routeName(parts);
|
|
81
80
|
const funcDir = resolve(outDir, 'server', 'functions');
|
|
82
81
|
const funcPath = resolve(funcDir, `${name}.js`);
|
|
83
82
|
const cssUrls = resolveCssUrls({
|
|
84
|
-
|
|
85
|
-
userCss: hasUserCss(appDir),
|
|
83
|
+
enabled: hasBuiltGlobalCss(outDir),
|
|
86
84
|
});
|
|
87
85
|
const cssOption = cssUrls.length > 0 ? `, cssUrls: ${JSON.stringify(cssUrls)}` : '';
|
|
88
86
|
// Static head snippet baked from the active onHead plugins — merged into
|
|
89
87
|
// every rendered head at request time (page tags win via mergeHeadHtml).
|
|
90
88
|
const headExtraOption = headExtra ? `, headExtra: ${JSON.stringify(headExtra)}` : '';
|
|
91
89
|
const bakedOptions = cssOption + headExtraOption;
|
|
92
|
-
const
|
|
93
|
-
|
|
90
|
+
const layoutStack = [
|
|
91
|
+
...ancestorLayouts.map((a) => ({ sourceDir: a.sourceDir, layoutCompName: a.layoutCompName })),
|
|
92
|
+
...(routeNode.layout ? [{ sourceDir: routeNode.sourceDir, layoutCompName: routeNode.layout }] : []),
|
|
93
|
+
];
|
|
94
|
+
const layoutDecls = [];
|
|
95
|
+
for (const entry of layoutStack) {
|
|
96
|
+
const entryPath = resolve(appDir, entry.sourceDir, 'layout.vsk');
|
|
97
|
+
const entrySrc = readFileSync(entryPath, 'utf-8');
|
|
98
|
+
const entryComp = extractCompName(entrySrc) || 'Layout';
|
|
99
|
+
const escaped = escapeSource(entrySrc);
|
|
100
|
+
layoutDecls.push({
|
|
101
|
+
src: `\`${escaped}\``,
|
|
102
|
+
comp: JSON.stringify(entryComp),
|
|
103
|
+
path: JSON.stringify(entryPath),
|
|
104
|
+
compiled: `(() => { try { setVskHydrate(true); return compileFile(\`${escaped}\`, { sourcePath: ${JSON.stringify(entryPath)} }); } catch { return null; } finally { setVskHydrate(false); } })()`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
94
107
|
const pageSrc = readFileSync(pagePath, 'utf-8');
|
|
95
108
|
const pageComp = extractCompName(pageSrc) || 'Page';
|
|
96
109
|
const errorPath = resolveErrorFile(routeNode.sourceDir, appDir);
|
|
@@ -100,28 +113,15 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
100
113
|
? `const _errorSrc = \`${escapeSource(errorSrc)}\`;\nconst _errorComp = ${JSON.stringify(errorComp)};\nconst _errorPath = ${JSON.stringify(errorPath)};\nconst _errorCompiled = (() => { try { setVskHydrate(true); return compileFile(_errorSrc, { sourcePath: _errorPath }); } catch { return null; } finally { setVskHydrate(false); } })();\n`
|
|
101
114
|
: 'const _errorSrc = null;\nconst _errorComp = null;\nconst _errorPath = null;\nconst _errorCompiled = null;\n';
|
|
102
115
|
let src = '';
|
|
103
|
-
if (
|
|
104
|
-
const layoutSrc = readFileSync(layoutPath, 'utf-8');
|
|
105
|
-
const layoutComp = extractCompName(layoutSrc) || 'Layout';
|
|
106
|
-
src = `const _layoutSrc = \`${escapeSource(layoutSrc)}\`;\nconst _pageSrc = \`${escapeSource(pageSrc)}\`;\n`;
|
|
107
|
-
src += `const _layoutComp = ${JSON.stringify(layoutComp)};\nconst _pageComp = ${JSON.stringify(pageComp)};\n`;
|
|
108
|
-
src += `const _layoutPath = ${JSON.stringify(layoutPath)};\nconst _pagePath = ${JSON.stringify(pagePath)};\n`;
|
|
109
|
-
src += `const _layoutCompiled = (() => { try { setVskHydrate(true); return compileFile(_layoutSrc, { sourcePath: _layoutPath }); } catch { return null; } finally { setVskHydrate(false); } })();\n`;
|
|
110
|
-
src += `const _pageCompiled = (() => { try { setVskHydrate(true); return compileFile(_pageSrc, { sourcePath: _pagePath }); } catch { return null; } finally { setVskHydrate(false); } })();\n`;
|
|
111
|
-
src += errorVars;
|
|
112
|
-
}
|
|
113
|
-
else if (hasAncestorLayout) {
|
|
114
|
-
const outerLayout = ancestorLayouts[0];
|
|
115
|
-
const outerLayoutPath = resolve(appDir, outerLayout.sourceDir, 'layout.vsk');
|
|
116
|
-
const outerLayoutSrc = readFileSync(outerLayoutPath, 'utf-8');
|
|
117
|
-
const outerLayoutComp = extractCompName(outerLayoutSrc) || 'Layout';
|
|
116
|
+
if (layoutDecls.length > 0) {
|
|
118
117
|
src = `const _pageSrc = \`${escapeSource(pageSrc)}\`;\n`;
|
|
119
118
|
src += `const _pageComp = ${JSON.stringify(pageComp)};\n`;
|
|
120
|
-
src += `const
|
|
121
|
-
src += `const _layoutComp = ${JSON.stringify(outerLayoutComp)};\n`;
|
|
122
|
-
src += `const _layoutPath = ${JSON.stringify(outerLayoutPath)};\nconst _pagePath = ${JSON.stringify(pagePath)};\n`;
|
|
123
|
-
src += `const _layoutCompiled = (() => { try { setVskHydrate(true); return compileFile(_layoutSrc, { sourcePath: _layoutPath }); } catch { return null; } finally { setVskHydrate(false); } })();\n`;
|
|
119
|
+
src += `const _pagePath = ${JSON.stringify(pagePath)};\n`;
|
|
124
120
|
src += `const _pageCompiled = (() => { try { setVskHydrate(true); return compileFile(_pageSrc, { sourcePath: _pagePath }); } catch { return null; } finally { setVskHydrate(false); } })();\n`;
|
|
121
|
+
src += `const _layoutSrcList = [\n${layoutDecls.map((d) => ' ' + d.src + ',').join('\n')}\n];\n`;
|
|
122
|
+
src += `const _layoutCompList = [${layoutDecls.map((d) => d.comp).join(', ')}];\n`;
|
|
123
|
+
src += `const _layoutPathList = [${layoutDecls.map((d) => d.path).join(', ')}];\n`;
|
|
124
|
+
src += `const _layoutCompiledList = [\n${layoutDecls.map((d) => ' ' + d.compiled + ',').join('\n')}\n];\n`;
|
|
125
125
|
src += errorVars;
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
@@ -150,7 +150,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
150
150
|
registryCode = 'const __componentRegistry = new Map();\n';
|
|
151
151
|
}
|
|
152
152
|
let htmlFnCode;
|
|
153
|
-
if (
|
|
153
|
+
if (layoutDecls.length > 0) {
|
|
154
154
|
htmlFnCode = [
|
|
155
155
|
'async function __renderErrorBody(props) {',
|
|
156
156
|
' if (!_errorSrc) throw props.error || new Error("Internal Server Error");',
|
|
@@ -176,7 +176,14 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
176
176
|
" const stack = err && typeof err === 'object' && 'stack' in err ? String(err.stack) : '';",
|
|
177
177
|
" page = { body: await __renderErrorBody({ params, statusCode: 500, error: __expose ? message : 'Internal Server Error', stack: __expose ? stack : '', url: requestUrl || '' }), head: '' };",
|
|
178
178
|
' }',
|
|
179
|
-
|
|
179
|
+
' let _body = (caughtError ? \'<!--vesk-ssr-error:\' + (caughtError && typeof caughtError === \'object\' && \'message\' in caughtError ? encodeURIComponent(__expose ? String(caughtError.message) : \'Internal Server Error\') : \'\') + \'-->\' : \'\') + page.body;',
|
|
180
|
+
' let _head = page.head || \'\';',
|
|
181
|
+
' for (let _i = _layoutSrcList.length - 1; _i > 0; _i--) {',
|
|
182
|
+
' const _inner = await renderPage(_layoutSrcList[_i], _layoutCompList[_i], { params, children: _body }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i], sourcePath: _layoutPathList[_i] });',
|
|
183
|
+
' _body = _inner.body;',
|
|
184
|
+
' if (_inner.head) _head = _inner.head + _head;',
|
|
185
|
+
' }',
|
|
186
|
+
' const html = await renderFullPage(_layoutSrcList[0], _layoutCompList[0], { params, children: _body }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[0]' + bakedOptions + clientScriptOption + dataScriptOption + ', pageHead: _head, sourcePath: _layoutPathList[0] });',
|
|
180
187
|
" return new Response(html, { headers: { 'Content-Type': 'text/html' }, status: caughtError ? 500 : 200 });",
|
|
181
188
|
' });',
|
|
182
189
|
'}',
|
|
@@ -228,7 +235,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
228
235
|
}
|
|
229
236
|
let dataCode;
|
|
230
237
|
const exposeErr = "process.env.NODE_ENV !== 'production'";
|
|
231
|
-
if (
|
|
238
|
+
if (layoutDecls.length > 0) {
|
|
232
239
|
dataCode = [
|
|
233
240
|
" if (request.headers.get('x-vesk-data') === '1') {",
|
|
234
241
|
' let dataPage;',
|
|
@@ -239,8 +246,12 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
239
246
|
' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
|
|
240
247
|
` return new Response(JSON.stringify({ error: ${exposeErr} ? message : 'Internal Server Error' }), { status: 500, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' } });`,
|
|
241
248
|
' }',
|
|
242
|
-
'
|
|
243
|
-
|
|
249
|
+
' let _dataHead = dataPage.head || \'\';',
|
|
250
|
+
' for (let _i = _layoutSrcList.length - 1; _i >= 0; _i--) {',
|
|
251
|
+
' const _dl = await renderPage(_layoutSrcList[_i], _layoutCompList[_i], { params, children: \'\' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i], sourcePath: _layoutPathList[_i] });',
|
|
252
|
+
' _dataHead = (_dl.head || \'\') + _dataHead;',
|
|
253
|
+
' }',
|
|
254
|
+
" return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
|
|
244
255
|
" headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', Vary: 'x-vesk-data' },",
|
|
245
256
|
' });',
|
|
246
257
|
' }',
|
|
@@ -308,12 +319,12 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
|
|
|
308
319
|
].join('\n');
|
|
309
320
|
}
|
|
310
321
|
let registerActionsCode;
|
|
311
|
-
if (
|
|
322
|
+
if (layoutDecls.length > 0) {
|
|
312
323
|
registerActionsCode = [
|
|
313
324
|
'async function __registerActions() {',
|
|
314
325
|
' if (__actionsRegistered) return;',
|
|
315
326
|
' __actionsRegistered = true;',
|
|
316
|
-
' compileFile(
|
|
327
|
+
' for (let _i = 0; _i < _layoutSrcList.length; _i++) compileFile(_layoutSrcList[_i], { sourcePath: _layoutPathList[_i] });',
|
|
317
328
|
' compileFile(_pageSrc, { sourcePath: _pagePath });',
|
|
318
329
|
'}',
|
|
319
330
|
'',
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { RouteNode, ApiRouteNode, VeskPlugin, VeskSecurity, VeskCors, VeskRateLimit, VeskSecurityPreset, SecurityConfig, MiddlewareChainItem, MiddlewareExtractResult, AncestorLayout, BuildOptions, DevServerOptions, ProdServerOptions, SsrFunctionOptions, ApiFunctionOptions, ClientBundleOptions, ClientBundleFileEntry, ClientBundleCache, ChunkEntry, ClientBundleResult, MonolithicBundleParts, Manifest, ManifestRouteEntry, ManifestActionEntry, ManifestPrerenderedEntry, SsgRouteResult, BuildResult, ImageRef, ImageResult, SeoCheckIssue, SeoAuditResult, CombinedPageInfo, Tracked, Resource, UseFetchOptions, UseFetchStreamOptions, VeskRequest, VeskResponse, SetCookieOptions, CookieStore, ServerRequest, SsrDataSink, MdProps, MdConfig, MdHtmlMode, MarkdownOptions, MdHtmlWarning, } from '@vesk/types';
|
|
1
|
+
export type { RouteNode, ApiRouteNode, VeskPlugin, ServerEventContext, VeskEventHandlers, VeskSecurity, VeskCors, VeskRateLimit, VeskSecurityPreset, SecurityConfig, MiddlewareChainItem, MiddlewareExtractResult, AncestorLayout, BuildOptions, DevServerOptions, ProdServerOptions, SsrFunctionOptions, ApiFunctionOptions, ClientBundleOptions, ClientBundleFileEntry, ClientBundleCache, ChunkEntry, ClientBundleResult, MonolithicBundleParts, Manifest, ManifestRouteEntry, ManifestActionEntry, ManifestPrerenderedEntry, SsgRouteResult, BuildResult, ImageRef, ImageResult, SeoCheckIssue, SeoAuditResult, CombinedPageInfo, Tracked, Resource, UseFetchOptions, UseFetchStreamOptions, VeskRequest, VeskResponse, SetCookieOptions, CookieStore, ServerRequest, SsrDataSink, MdProps, MdConfig, MdHtmlMode, MarkdownOptions, MdHtmlWarning, } from '@vesk/types';
|
|
2
2
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,OAAO,EACP,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,SAAS,EACT,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,WAAW,EACX,QAAQ,EACR,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACX,OAAO,EACP,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesk/adapter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vesk adapter — builds deployable .vesk/ output for Deno and Node serverless",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"sharp": "^0.35.3"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@vesk/compiler": "^0.2.
|
|
27
|
-
"@vesk/runtime": "^0.2.
|
|
28
|
-
"@vesk/types": "^0.2.
|
|
26
|
+
"@vesk/compiler": "^0.2.17",
|
|
27
|
+
"@vesk/runtime": "^0.2.17",
|
|
28
|
+
"@vesk/types": "^0.2.17"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/ws": "^8.18.1",
|