@vesk/vesk-cli 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.
Files changed (2) hide show
  1. package/dist/cli.js +47 -31
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -50152,34 +50152,49 @@ function generateSsrFunction(routeNode, appDir, outDir, componentMap, options) {
50152
50152
  const errorPath = resolveErrorFile(routeNode.sourceDir, appDir);
50153
50153
  const errorSrc = errorPath ? readFileSync7(errorPath, "utf-8") : null;
50154
50154
  const errorComp = errorPath ? extractCompName(errorSrc) || "Error" : null;
50155
- const errorVars = errorPath ? `const _errorComp = ${JSON.stringify(errorComp)};
50156
- const _errorCompiled = ${hydrateInvoke(precompilePlan(errorPath))};
50157
- ` : "const _errorComp = null;\nconst _errorCompiled = null;\n";
50155
+ const errorCompDecl = errorPath ? `const _errorComp = ${JSON.stringify(errorComp)};
50156
+ ` : "const _errorComp = null;\n";
50157
+ const errorPlanExpr = errorPath ? hydrateInvoke(precompilePlan(errorPath)) : "null";
50158
50158
  const notFoundPath = resolveNotFoundFile(routeNode.sourceDir, appDir);
50159
50159
  const notFoundSrc = notFoundPath ? readFileSync7(notFoundPath, "utf-8") : null;
50160
50160
  const notFoundComp = notFoundPath ? extractCompName(notFoundSrc) || "NotFound" : null;
50161
- const notFoundVars = notFoundPath ? `const _notFoundComp = ${JSON.stringify(notFoundComp)};
50162
- const _notFoundCompiled = ${hydrateInvoke(precompilePlan(notFoundPath))};
50163
- ` : "const _notFoundComp = null;\nconst _notFoundCompiled = null;\n";
50161
+ const notFoundCompDecl = notFoundPath ? `const _notFoundComp = ${JSON.stringify(notFoundComp)};
50162
+ ` : "const _notFoundComp = null;\n";
50163
+ const notFoundPlanExpr = notFoundPath ? hydrateInvoke(precompilePlan(notFoundPath)) : "null";
50164
50164
  let src2 = "";
50165
50165
  if (layoutDecls.length > 0) {
50166
- src2 = `const _pageComp = ${JSON.stringify(pageComp)};
50166
+ src2 = errorCompDecl + notFoundCompDecl;
50167
+ src2 += `const _pageComp = ${JSON.stringify(pageComp)};
50167
50168
  `;
50168
- src2 += `const _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })();
50169
+ src2 += `let _pageCompiled = null;
50170
+ function __getPageCompiled() { if (!_pageCompiled) _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _pageCompiled; }
50169
50171
  `;
50170
50172
  src2 += `const _layoutCompList = [${layoutDecls.map((d) => d.comp).join(", ")}];
50171
50173
  `;
50172
- src2 += `const _layoutCompiledList = [
50174
+ src2 += `let _layoutCompiledList = null;
50175
+ function __getLayoutCompiledList() { if (!_layoutCompiledList) { _layoutCompiledList = [
50173
50176
  ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50174
- ];
50177
+ ]; } return _layoutCompiledList; }
50178
+ `;
50179
+ src2 += `let _errorCompiled = null;
50180
+ function __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }
50181
+ `;
50182
+ src2 += `let _notFoundCompiled = null;
50183
+ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = ${notFoundPlanExpr}; return _notFoundCompiled; }
50175
50184
  `;
50176
- src2 += errorVars + notFoundVars;
50177
50185
  } else {
50178
- src2 = `const _comp = ${JSON.stringify(pageComp)};
50186
+ src2 = errorCompDecl + notFoundCompDecl;
50187
+ src2 += `const _comp = ${JSON.stringify(pageComp)};
50179
50188
  `;
50180
- src2 += `const _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })();
50189
+ src2 += `let _compiled = null;
50190
+ function __getCompiled() { if (!_compiled) _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _compiled; }
50191
+ `;
50192
+ src2 += `let _errorCompiled = null;
50193
+ function __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }
50194
+ `;
50195
+ src2 += `let _notFoundCompiled = null;
50196
+ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = ${notFoundPlanExpr}; return _notFoundCompiled; }
50181
50197
  `;
50182
- src2 += errorVars + notFoundVars;
50183
50198
  }
50184
50199
  const urlParts = routeNode.fullPath.split("/").filter(Boolean);
50185
50200
  const paramExprs = buildParamExtraction(routeNode, urlParts);
@@ -50193,20 +50208,21 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50193
50208
  let registryCode = "";
50194
50209
  const compRegEntries = [];
50195
50210
  const compMap = componentMap || /* @__PURE__ */ new Map();
50211
+ const regPlans = [];
50196
50212
  for (const [compName, compPath] of compMap) {
50197
50213
  const plan = precompilePlan(compPath);
50198
- compRegEntries.push(` (() => {
50199
- const _compiled = (() => { try { return hydratePrecompile(${plan}); } catch { return null; } })();
50200
- __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {
50214
+ regPlans.push(` __regPlans.set(${JSON.stringify(compName)}, ${JSON.stringify(plan)});`);
50215
+ compRegEntries.push(` __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {
50216
+ let _compiled = __regCompiled.get(${JSON.stringify(compName)});
50217
+ if (!_compiled) { _compiled = hydratePrecompile(__regPlans.get(${JSON.stringify(compName)})); __regCompiled.set(${JSON.stringify(compName)}, _compiled); }
50201
50218
  const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });
50202
50219
  return result.body;
50203
- });
50204
- })();`);
50220
+ });`);
50205
50221
  }
50206
50222
  if (compRegEntries.length > 0) {
50207
- registryCode = "const __componentRegistry = new Map();\n{\n" + compRegEntries.join("\n") + "\n}\n";
50223
+ registryCode = "const __componentRegistry = new Map();\nconst __regPlans = new Map();\nconst __regCompiled = new Map();\n{\n" + regPlans.join("\n") + "\n" + compRegEntries.join("\n") + "\n}\n";
50208
50224
  } else {
50209
- registryCode = "const __componentRegistry = new Map();\n";
50225
+ registryCode = "const __componentRegistry = new Map();\nconst __regPlans = new Map();\nconst __regCompiled = new Map();\n";
50210
50226
  }
50211
50227
  let htmlFnCode;
50212
50228
  if (layoutDecls.length > 0) {
@@ -50214,7 +50230,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50214
50230
  "async function __renderErrorBody(props) {",
50215
50231
  ' if (!_errorComp) throw props.error || new Error("Internal Server Error");',
50216
50232
  " try {",
50217
- " const result = await renderPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: _errorCompiled });",
50233
+ " const result = await renderPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: __getErrorCompiled() });",
50218
50234
  " return result.body;",
50219
50235
  " } catch {",
50220
50236
  ` return ${JSON.stringify(renderDefaultErrorFragment())};`,
@@ -50227,7 +50243,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50227
50243
  "async function __renderNotFoundBody(props) {",
50228
50244
  " if (!_notFoundComp) return null;",
50229
50245
  " try {",
50230
- " const result = await renderPage('', _notFoundComp, props, __componentRegistry, { hydrate: true, cached: _notFoundCompiled });",
50246
+ " const result = await renderPage('', _notFoundComp, props, __componentRegistry, { hydrate: true, cached: __getNotFoundCompiled() });",
50231
50247
  " return result.body;",
50232
50248
  " } catch {",
50233
50249
  " return null;",
@@ -50241,11 +50257,11 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50241
50257
  " let _b = body;",
50242
50258
  ' let _h = head || "";',
50243
50259
  " for (let _i = _layoutCompList.length - 1; _i > 0; _i--) {",
50244
- " const _inner = await renderPage('', _layoutCompList[_i], { params, children: _b }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
50260
+ " const _inner = await renderPage('', _layoutCompList[_i], { params, children: _b }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[_i] });",
50245
50261
  " _b = _inner.body;",
50246
50262
  " if (_inner.head) _h = _inner.head + _h;",
50247
50263
  " }",
50248
- " return renderFullPage('', _layoutCompList[0], { params, children: _b }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[0]" + bakedOptions + clientScriptOption + dataScriptOption + ", pageHead: _h });",
50264
+ " return renderFullPage('', _layoutCompList[0], { params, children: _b }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[0]" + bakedOptions + clientScriptOption + dataScriptOption + ", pageHead: _h });",
50249
50265
  "}",
50250
50266
  "",
50251
50267
  "async function __renderHtml(params, requestUrl) {",
@@ -50256,7 +50272,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50256
50272
  " let notFound = false;",
50257
50273
  " const __expose = process.env.NODE_ENV !== 'production';",
50258
50274
  " try {",
50259
- " page = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
50275
+ " page = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: __getPageCompiled() });",
50260
50276
  " } catch (err) {",
50261
50277
  " if (err && err.name === 'Redirect') throw err;",
50262
50278
  " if (err && err.name === 'NotFoundError') {",
@@ -50293,7 +50309,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50293
50309
  " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
50294
50310
  " const stack = err && typeof err === 'object' && 'stack' in err ? String(err.stack) : '';",
50295
50311
  " const props = { params, statusCode: 500, error: __expose ? message : 'Internal Server Error', stack: __expose ? stack : '', url: requestUrl || '' };",
50296
- " return renderFullPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: _errorCompiled" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50312
+ " return renderFullPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: __getErrorCompiled()" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50297
50313
  "}",
50298
50314
  "",
50299
50315
  "async function __renderHtml(params, requestUrl) {",
@@ -50308,7 +50324,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50308
50324
  // though it runs outside the ALS scope.
50309
50325
  " const __streamToken = globalThis.__vsk_ssr_token || '';",
50310
50326
  " try {",
50311
- " stream = renderPageStream('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50327
+ " stream = renderPageStream('', _comp, { params }, __componentRegistry, { hydrate: true, cached: __getCompiled()" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50312
50328
  " } catch (err) {",
50313
50329
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
50314
50330
  " const html = await __renderErrorFullPage(params, requestUrl, err);",
@@ -50382,7 +50398,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50382
50398
  " try {",
50383
50399
  " let dataPage;",
50384
50400
  " try {",
50385
- " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
50401
+ " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: __getPageCompiled() });",
50386
50402
  " } catch (err) {",
50387
50403
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
50388
50404
  " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
@@ -50390,7 +50406,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50390
50406
  " }",
50391
50407
  " let _dataHead = dataPage.head || '';",
50392
50408
  " for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {",
50393
- " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
50409
+ " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[_i] });",
50394
50410
  " _dataHead = (_dl.head || '') + _dataHead;",
50395
50411
  " }",
50396
50412
  " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
@@ -50408,7 +50424,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50408
50424
  " try {",
50409
50425
  " let dataPage;",
50410
50426
  " try {",
50411
- " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
50427
+ " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: __getCompiled() });",
50412
50428
  " } catch (err) {",
50413
50429
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
50414
50430
  " 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/vesk-cli",
3
- "version": "0.2.78",
3
+ "version": "0.2.80",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "main": "./dist/cli.js",
10
10
  "dependencies": {
11
- "@vesk/adapter": "^0.2.78",
12
- "@vesk/compiler": "^0.2.78",
13
- "@vesk/plugin-tailwind": "^0.2.78",
14
- "@vesk/runtime": "^0.2.78",
11
+ "@vesk/adapter": "^0.2.80",
12
+ "@vesk/compiler": "^0.2.80",
13
+ "@vesk/plugin-tailwind": "^0.2.80",
14
+ "@vesk/runtime": "^0.2.80",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",