@vesk/adapter 0.2.78 → 0.2.80

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-function.d.ts","sourceRoot":"","sources":["../src/ssr-function.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7F;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQlG;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjF;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEpF;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQvG;AAgED;;;2EAG2E;AAC3E,wBAAgB,qBAAqB,IAAI,MAAM,CA4C9C;AAED,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,CAiftD"}
1
+ {"version":3,"file":"ssr-function.d.ts","sourceRoot":"","sources":["../src/ssr-function.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7F;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQlG;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjF;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEpF;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQvG;AAgED;;;2EAG2E;AAC3E,wBAAgB,qBAAqB,IAAI,MAAM,CA4C9C;AAED,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,CAqftD"}
@@ -196,9 +196,8 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
196
196
  const errorPath = resolveErrorFile(routeNode.sourceDir, appDir);
197
197
  const errorSrc = errorPath ? readFileSync(errorPath, 'utf-8') : null;
198
198
  const errorComp = errorPath ? (extractCompName(errorSrc) || 'Error') : null;
199
- const errorVars = errorPath
200
- ? `const _errorComp = ${JSON.stringify(errorComp)};\nconst _errorCompiled = ${hydrateInvoke(precompilePlan(errorPath))};\n`
201
- : 'const _errorComp = null;\nconst _errorCompiled = null;\n';
199
+ const errorCompDecl = errorPath ? `const _errorComp = ${JSON.stringify(errorComp)};\n` : 'const _errorComp = null;\n';
200
+ const errorPlanExpr = errorPath ? hydrateInvoke(precompilePlan(errorPath)) : 'null';
202
201
  // Not-found used to have no server-side resolution at all: a NotFoundError was
203
202
  // re-thrown out of the function and the prod server answered with the ROOT
204
203
  // not-found.vsk. A nested `app/admin/not-found.vsk` therefore did nothing on a
@@ -208,21 +207,24 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
208
207
  const notFoundPath = resolveNotFoundFile(routeNode.sourceDir, appDir);
209
208
  const notFoundSrc = notFoundPath ? readFileSync(notFoundPath, 'utf-8') : null;
210
209
  const notFoundComp = notFoundPath ? (extractCompName(notFoundSrc) || 'NotFound') : null;
211
- const notFoundVars = notFoundPath
212
- ? `const _notFoundComp = ${JSON.stringify(notFoundComp)};\nconst _notFoundCompiled = ${hydrateInvoke(precompilePlan(notFoundPath))};\n`
213
- : 'const _notFoundComp = null;\nconst _notFoundCompiled = null;\n';
210
+ const notFoundCompDecl = notFoundPath ? `const _notFoundComp = ${JSON.stringify(notFoundComp)};\n` : 'const _notFoundComp = null;\n';
211
+ const notFoundPlanExpr = notFoundPath ? hydrateInvoke(precompilePlan(notFoundPath)) : 'null';
214
212
  let src = '';
215
213
  if (layoutDecls.length > 0) {
216
- src = `const _pageComp = ${JSON.stringify(pageComp)};\n`;
217
- src += `const _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })();\n`;
214
+ src = errorCompDecl + notFoundCompDecl;
215
+ src += `const _pageComp = ${JSON.stringify(pageComp)};\n`;
216
+ src += `let _pageCompiled = null;\nfunction __getPageCompiled() { if (!_pageCompiled) _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _pageCompiled; }\n`;
218
217
  src += `const _layoutCompList = [${layoutDecls.map((d) => d.comp).join(', ')}];\n`;
219
- src += `const _layoutCompiledList = [\n${layoutDecls.map((d) => ' ' + d.compiled + ',').join('\n')}\n];\n`;
220
- src += errorVars + notFoundVars;
218
+ src += `let _layoutCompiledList = null;\nfunction __getLayoutCompiledList() { if (!_layoutCompiledList) { _layoutCompiledList = [\n${layoutDecls.map((d) => ' ' + d.compiled + ',').join('\n')}\n]; } return _layoutCompiledList; }\n`;
219
+ src += `let _errorCompiled = null;\nfunction __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }\n`;
220
+ src += `let _notFoundCompiled = null;\nfunction __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = ${notFoundPlanExpr}; return _notFoundCompiled; }\n`;
221
221
  }
222
222
  else {
223
- src = `const _comp = ${JSON.stringify(pageComp)};\n`;
224
- src += `const _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })();\n`;
225
- src += errorVars + notFoundVars;
223
+ src = errorCompDecl + notFoundCompDecl;
224
+ src += `const _comp = ${JSON.stringify(pageComp)};\n`;
225
+ src += `let _compiled = null;\nfunction __getCompiled() { if (!_compiled) _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _compiled; }\n`;
226
+ src += `let _errorCompiled = null;\nfunction __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }\n`;
227
+ src += `let _notFoundCompiled = null;\nfunction __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = ${notFoundPlanExpr}; return _notFoundCompiled; }\n`;
226
228
  }
227
229
  const urlParts = routeNode.fullPath.split('/').filter(Boolean);
228
230
  const paramExprs = buildParamExtraction(routeNode, urlParts);
@@ -235,15 +237,17 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
235
237
  let registryCode = '';
236
238
  const compRegEntries = [];
237
239
  const compMap = componentMap || new Map();
240
+ const regPlans = [];
238
241
  for (const [compName, compPath] of compMap) {
239
242
  const plan = precompilePlan(compPath);
240
- compRegEntries.push(` (() => {\n const _compiled = (() => { try { return hydratePrecompile(${plan}); } catch { return null; } })();\n __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {\n const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });\n return result.body;\n });\n })();`);
243
+ regPlans.push(` __regPlans.set(${JSON.stringify(compName)}, ${JSON.stringify(plan)});`);
244
+ compRegEntries.push(` __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {\n let _compiled = __regCompiled.get(${JSON.stringify(compName)});\n if (!_compiled) { _compiled = hydratePrecompile(__regPlans.get(${JSON.stringify(compName)})); __regCompiled.set(${JSON.stringify(compName)}, _compiled); }\n const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });\n return result.body;\n });`);
241
245
  }
242
246
  if (compRegEntries.length > 0) {
243
- registryCode = 'const __componentRegistry = new Map();\n{\n' + compRegEntries.join('\n') + '\n}\n';
247
+ registryCode = 'const __componentRegistry = new Map();\nconst __regPlans = new Map();\nconst __regCompiled = new Map();\n{\n' + regPlans.join('\n') + '\n' + compRegEntries.join('\n') + '\n}\n';
244
248
  }
245
249
  else {
246
- registryCode = 'const __componentRegistry = new Map();\n';
250
+ registryCode = 'const __componentRegistry = new Map();\nconst __regPlans = new Map();\nconst __regCompiled = new Map();\n';
247
251
  }
248
252
  let htmlFnCode;
249
253
  if (layoutDecls.length > 0) {
@@ -251,7 +255,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
251
255
  'async function __renderErrorBody(props) {',
252
256
  ' if (!_errorComp) throw props.error || new Error("Internal Server Error");',
253
257
  ' try {',
254
- ' const result = await renderPage(\'\', _errorComp, props, __componentRegistry, { hydrate: true, cached: _errorCompiled });',
258
+ ' const result = await renderPage(\'\', _errorComp, props, __componentRegistry, { hydrate: true, cached: __getErrorCompiled() });',
255
259
  ' return result.body;',
256
260
  ' } catch {',
257
261
  ` return ${JSON.stringify(renderDefaultErrorFragment())};`,
@@ -264,7 +268,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
264
268
  'async function __renderNotFoundBody(props) {',
265
269
  ' if (!_notFoundComp) return null;',
266
270
  ' try {',
267
- ' const result = await renderPage(\'\', _notFoundComp, props, __componentRegistry, { hydrate: true, cached: _notFoundCompiled });',
271
+ ' const result = await renderPage(\'\', _notFoundComp, props, __componentRegistry, { hydrate: true, cached: __getNotFoundCompiled() });',
268
272
  ' return result.body;',
269
273
  ' } catch {',
270
274
  ' return null;',
@@ -278,11 +282,11 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
278
282
  ' let _b = body;',
279
283
  ' let _h = head || "";',
280
284
  ' for (let _i = _layoutCompList.length - 1; _i > 0; _i--) {',
281
- " const _inner = await renderPage('', _layoutCompList[_i], { params, children: _b }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
285
+ " const _inner = await renderPage('', _layoutCompList[_i], { params, children: _b }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[_i] });",
282
286
  ' _b = _inner.body;',
283
287
  ' if (_inner.head) _h = _inner.head + _h;',
284
288
  ' }',
285
- " return renderFullPage('', _layoutCompList[0], { params, children: _b }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[0]" + bakedOptions + clientScriptOption + dataScriptOption + ", pageHead: _h });",
289
+ " return renderFullPage('', _layoutCompList[0], { params, children: _b }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[0]" + bakedOptions + clientScriptOption + dataScriptOption + ", pageHead: _h });",
286
290
  '}',
287
291
  '',
288
292
  'async function __renderHtml(params, requestUrl) {',
@@ -293,7 +297,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
293
297
  ' let notFound = false;',
294
298
  " const __expose = process.env.NODE_ENV !== 'production';",
295
299
  ' try {',
296
- ' page = await renderPage(\'\', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });',
300
+ ' page = await renderPage(\'\', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: __getPageCompiled() });',
297
301
  ' } catch (err) {',
298
302
  " if (err && err.name === 'Redirect') throw err;",
299
303
  " if (err && err.name === 'NotFoundError') {",
@@ -331,7 +335,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
331
335
  " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
332
336
  " const stack = err && typeof err === 'object' && 'stack' in err ? String(err.stack) : '';",
333
337
  " const props = { params, statusCode: 500, error: __expose ? message : 'Internal Server Error', stack: __expose ? stack : '', url: requestUrl || '' };",
334
- " return renderFullPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: _errorCompiled" + bakedOptions + clientScriptOption + dataScriptOption + " });",
338
+ " return renderFullPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: __getErrorCompiled()" + bakedOptions + clientScriptOption + dataScriptOption + " });",
335
339
  '}',
336
340
  '',
337
341
  'async function __renderHtml(params, requestUrl) {',
@@ -346,7 +350,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
346
350
  // though it runs outside the ALS scope.
347
351
  " const __streamToken = globalThis.__vsk_ssr_token || '';",
348
352
  ' try {',
349
- " stream = renderPageStream('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled" + bakedOptions + clientScriptOption + dataScriptOption + ' });',
353
+ " stream = renderPageStream('', _comp, { params }, __componentRegistry, { hydrate: true, cached: __getCompiled()" + bakedOptions + clientScriptOption + dataScriptOption + ' });',
350
354
  ' } catch (err) {',
351
355
  ' if (err && (err.name === \'NotFoundError\' || err.name === \'Redirect\')) throw err;',
352
356
  ' const html = await __renderErrorFullPage(params, requestUrl, err);',
@@ -433,7 +437,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
433
437
  ' try {',
434
438
  ' let dataPage;',
435
439
  ' try {',
436
- " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
440
+ " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: __getPageCompiled() });",
437
441
  ' } catch (err) {',
438
442
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
439
443
  ' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
@@ -441,7 +445,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
441
445
  ' }',
442
446
  ' let _dataHead = dataPage.head || \'\';',
443
447
  ' for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {',
444
- " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
448
+ " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[_i] });",
445
449
  ' _dataHead = (_dl.head || \'\') + _dataHead;',
446
450
  ' }',
447
451
  " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
@@ -460,7 +464,7 @@ export function generateSsrFunction(routeNode, appDir, outDir, componentMap, opt
460
464
  ' try {',
461
465
  ' let dataPage;',
462
466
  ' try {',
463
- " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
467
+ " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: __getCompiled() });",
464
468
  ' } catch (err) {',
465
469
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
466
470
  ' const message = err && typeof err === \'object\' && \'message\' in err ? String(err.message) : String(err);',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/adapter",
3
- "version": "0.2.78",
3
+ "version": "0.2.80",
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.78",
27
- "@vesk/runtime": "^0.2.78",
28
- "@vesk/types": "^0.2.78"
26
+ "@vesk/compiler": "^0.2.80",
27
+ "@vesk/runtime": "^0.2.80",
28
+ "@vesk/types": "^0.2.80"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/ws": "^8.18.1",