@vesk/vesk-cli 0.2.78 → 0.2.81

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 +51 -31
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -22616,6 +22616,7 @@ __export(server_utils_exports, {
22616
22616
  extractTopLevelNames: () => extractTopLevelNames,
22617
22617
  getClientIp: () => getClientIp,
22618
22618
  getClientProtocol: () => getClientProtocol,
22619
+ getRuntimeModule: () => getRuntimeModule,
22619
22620
  indent: () => indent,
22620
22621
  isStatic: () => isStatic,
22621
22622
  loadRuntimeImports: () => loadRuntimeImports,
@@ -23471,6 +23472,9 @@ function resolveComponentName(source) {
23471
23472
  function setRuntimeModule(mod) {
23472
23473
  __cachedRuntimeModule = mod;
23473
23474
  }
23475
+ function getRuntimeModule() {
23476
+ return __cachedRuntimeModule || index_server_exports || null;
23477
+ }
23474
23478
  function loadRuntimeImports(importStrs) {
23475
23479
  const pairs = extractRuntimeBindingPairs(importStrs);
23476
23480
  const mod = __cachedRuntimeModule || index_server_exports;
@@ -50152,34 +50156,49 @@ function generateSsrFunction(routeNode, appDir, outDir, componentMap, options) {
50152
50156
  const errorPath = resolveErrorFile(routeNode.sourceDir, appDir);
50153
50157
  const errorSrc = errorPath ? readFileSync7(errorPath, "utf-8") : null;
50154
50158
  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";
50159
+ const errorCompDecl = errorPath ? `const _errorComp = ${JSON.stringify(errorComp)};
50160
+ ` : "const _errorComp = null;\n";
50161
+ const errorPlanExpr = errorPath ? hydrateInvoke(precompilePlan(errorPath)) : "null";
50158
50162
  const notFoundPath = resolveNotFoundFile(routeNode.sourceDir, appDir);
50159
50163
  const notFoundSrc = notFoundPath ? readFileSync7(notFoundPath, "utf-8") : null;
50160
50164
  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";
50165
+ const notFoundCompDecl = notFoundPath ? `const _notFoundComp = ${JSON.stringify(notFoundComp)};
50166
+ ` : "const _notFoundComp = null;\n";
50167
+ const notFoundPlanExpr = notFoundPath ? hydrateInvoke(precompilePlan(notFoundPath)) : "null";
50164
50168
  let src2 = "";
50165
50169
  if (layoutDecls.length > 0) {
50166
- src2 = `const _pageComp = ${JSON.stringify(pageComp)};
50170
+ src2 = errorCompDecl + notFoundCompDecl;
50171
+ src2 += `const _pageComp = ${JSON.stringify(pageComp)};
50167
50172
  `;
50168
- src2 += `const _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })();
50173
+ src2 += `let _pageCompiled = null;
50174
+ function __getPageCompiled() { if (!_pageCompiled) _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _pageCompiled; }
50169
50175
  `;
50170
50176
  src2 += `const _layoutCompList = [${layoutDecls.map((d) => d.comp).join(", ")}];
50171
50177
  `;
50172
- src2 += `const _layoutCompiledList = [
50178
+ src2 += `let _layoutCompiledList = null;
50179
+ function __getLayoutCompiledList() { if (!_layoutCompiledList) { _layoutCompiledList = [
50173
50180
  ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50174
- ];
50181
+ ]; } return _layoutCompiledList; }
50182
+ `;
50183
+ src2 += `let _errorCompiled = null;
50184
+ function __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }
50185
+ `;
50186
+ src2 += `let _notFoundCompiled = null;
50187
+ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = ${notFoundPlanExpr}; return _notFoundCompiled; }
50175
50188
  `;
50176
- src2 += errorVars + notFoundVars;
50177
50189
  } else {
50178
- src2 = `const _comp = ${JSON.stringify(pageComp)};
50190
+ src2 = errorCompDecl + notFoundCompDecl;
50191
+ src2 += `const _comp = ${JSON.stringify(pageComp)};
50179
50192
  `;
50180
- src2 += `const _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })();
50193
+ src2 += `let _compiled = null;
50194
+ function __getCompiled() { if (!_compiled) _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _compiled; }
50195
+ `;
50196
+ src2 += `let _errorCompiled = null;
50197
+ function __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }
50198
+ `;
50199
+ src2 += `let _notFoundCompiled = null;
50200
+ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = ${notFoundPlanExpr}; return _notFoundCompiled; }
50181
50201
  `;
50182
- src2 += errorVars + notFoundVars;
50183
50202
  }
50184
50203
  const urlParts = routeNode.fullPath.split("/").filter(Boolean);
50185
50204
  const paramExprs = buildParamExtraction(routeNode, urlParts);
@@ -50193,20 +50212,21 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50193
50212
  let registryCode = "";
50194
50213
  const compRegEntries = [];
50195
50214
  const compMap = componentMap || /* @__PURE__ */ new Map();
50215
+ const regPlans = [];
50196
50216
  for (const [compName, compPath] of compMap) {
50197
50217
  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) => {
50218
+ regPlans.push(` __regPlans.set(${JSON.stringify(compName)}, ${JSON.stringify(plan)});`);
50219
+ compRegEntries.push(` __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {
50220
+ let _compiled = __regCompiled.get(${JSON.stringify(compName)});
50221
+ if (!_compiled) { _compiled = hydratePrecompile(__regPlans.get(${JSON.stringify(compName)})); __regCompiled.set(${JSON.stringify(compName)}, _compiled); }
50201
50222
  const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });
50202
50223
  return result.body;
50203
- });
50204
- })();`);
50224
+ });`);
50205
50225
  }
50206
50226
  if (compRegEntries.length > 0) {
50207
- registryCode = "const __componentRegistry = new Map();\n{\n" + compRegEntries.join("\n") + "\n}\n";
50227
+ 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
50228
  } else {
50209
- registryCode = "const __componentRegistry = new Map();\n";
50229
+ registryCode = "const __componentRegistry = new Map();\nconst __regPlans = new Map();\nconst __regCompiled = new Map();\n";
50210
50230
  }
50211
50231
  let htmlFnCode;
50212
50232
  if (layoutDecls.length > 0) {
@@ -50214,7 +50234,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50214
50234
  "async function __renderErrorBody(props) {",
50215
50235
  ' if (!_errorComp) throw props.error || new Error("Internal Server Error");',
50216
50236
  " try {",
50217
- " const result = await renderPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: _errorCompiled });",
50237
+ " const result = await renderPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: __getErrorCompiled() });",
50218
50238
  " return result.body;",
50219
50239
  " } catch {",
50220
50240
  ` return ${JSON.stringify(renderDefaultErrorFragment())};`,
@@ -50227,7 +50247,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50227
50247
  "async function __renderNotFoundBody(props) {",
50228
50248
  " if (!_notFoundComp) return null;",
50229
50249
  " try {",
50230
- " const result = await renderPage('', _notFoundComp, props, __componentRegistry, { hydrate: true, cached: _notFoundCompiled });",
50250
+ " const result = await renderPage('', _notFoundComp, props, __componentRegistry, { hydrate: true, cached: __getNotFoundCompiled() });",
50231
50251
  " return result.body;",
50232
50252
  " } catch {",
50233
50253
  " return null;",
@@ -50241,11 +50261,11 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50241
50261
  " let _b = body;",
50242
50262
  ' let _h = head || "";',
50243
50263
  " 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] });",
50264
+ " const _inner = await renderPage('', _layoutCompList[_i], { params, children: _b }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[_i] });",
50245
50265
  " _b = _inner.body;",
50246
50266
  " if (_inner.head) _h = _inner.head + _h;",
50247
50267
  " }",
50248
- " return renderFullPage('', _layoutCompList[0], { params, children: _b }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[0]" + bakedOptions + clientScriptOption + dataScriptOption + ", pageHead: _h });",
50268
+ " return renderFullPage('', _layoutCompList[0], { params, children: _b }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[0]" + bakedOptions + clientScriptOption + dataScriptOption + ", pageHead: _h });",
50249
50269
  "}",
50250
50270
  "",
50251
50271
  "async function __renderHtml(params, requestUrl) {",
@@ -50256,7 +50276,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50256
50276
  " let notFound = false;",
50257
50277
  " const __expose = process.env.NODE_ENV !== 'production';",
50258
50278
  " try {",
50259
- " page = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
50279
+ " page = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: __getPageCompiled() });",
50260
50280
  " } catch (err) {",
50261
50281
  " if (err && err.name === 'Redirect') throw err;",
50262
50282
  " if (err && err.name === 'NotFoundError') {",
@@ -50293,7 +50313,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50293
50313
  " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
50294
50314
  " const stack = err && typeof err === 'object' && 'stack' in err ? String(err.stack) : '';",
50295
50315
  " 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 + " });",
50316
+ " return renderFullPage('', _errorComp, props, __componentRegistry, { hydrate: true, cached: __getErrorCompiled()" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50297
50317
  "}",
50298
50318
  "",
50299
50319
  "async function __renderHtml(params, requestUrl) {",
@@ -50308,7 +50328,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50308
50328
  // though it runs outside the ALS scope.
50309
50329
  " const __streamToken = globalThis.__vsk_ssr_token || '';",
50310
50330
  " try {",
50311
- " stream = renderPageStream('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50331
+ " stream = renderPageStream('', _comp, { params }, __componentRegistry, { hydrate: true, cached: __getCompiled()" + bakedOptions + clientScriptOption + dataScriptOption + " });",
50312
50332
  " } catch (err) {",
50313
50333
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
50314
50334
  " const html = await __renderErrorFullPage(params, requestUrl, err);",
@@ -50382,7 +50402,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50382
50402
  " try {",
50383
50403
  " let dataPage;",
50384
50404
  " try {",
50385
- " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: _pageCompiled });",
50405
+ " dataPage = await renderPage('', _pageComp, { params }, __componentRegistry, { hydrate: true, cached: __getPageCompiled() });",
50386
50406
  " } catch (err) {",
50387
50407
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
50388
50408
  " const message = err && typeof err === 'object' && 'message' in err ? String(err.message) : String(err);",
@@ -50390,7 +50410,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50390
50410
  " }",
50391
50411
  " let _dataHead = dataPage.head || '';",
50392
50412
  " for (let _i = _layoutCompList.length - 1; _i >= 0; _i--) {",
50393
- " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: _layoutCompiledList[_i] });",
50413
+ " const _dl = await renderPage('', _layoutCompList[_i], { params, children: '' }, __componentRegistry, { hydrate: true, cached: __getLayoutCompiledList()[_i] });",
50394
50414
  " _dataHead = (_dl.head || '') + _dataHead;",
50395
50415
  " }",
50396
50416
  " return new Response(JSON.stringify({ path: url.pathname, params, props: dataPage.props || { params }, head: _dataHead }), {",
@@ -50408,7 +50428,7 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50408
50428
  " try {",
50409
50429
  " let dataPage;",
50410
50430
  " try {",
50411
- " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: _compiled });",
50431
+ " dataPage = await renderPage('', _comp, { params }, __componentRegistry, { hydrate: true, cached: __getCompiled() });",
50412
50432
  " } catch (err) {",
50413
50433
  " if (err && (err.name === 'NotFoundError' || err.name === 'Redirect')) throw err;",
50414
50434
  " 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.81",
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.81",
12
+ "@vesk/compiler": "^0.2.81",
13
+ "@vesk/plugin-tailwind": "^0.2.81",
14
+ "@vesk/runtime": "^0.2.81",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",