@vesk/vesk-cli 0.2.83 → 0.2.85

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 +82 -34
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -20425,11 +20425,9 @@ function collectModuleSpecifiers(ast) {
20425
20425
  });
20426
20426
  return specs;
20427
20427
  }
20428
- function collectModuleBundled(absPath, collector) {
20429
- const existing2 = collector.keysByAbs.get(absPath);
20428
+ function collectModuleBundled(absPath, registry) {
20429
+ const existing2 = registry.getKey(absPath);
20430
20430
  if (existing2) return existing2;
20431
- const key = `__veskMod${collector.keysByAbs.size}`;
20432
- collector.keysByAbs.set(absPath, key);
20433
20431
  const dir = dirname2(absPath);
20434
20432
  if (absPath.endsWith(".json")) {
20435
20433
  let raw2 = "";
@@ -20438,8 +20436,7 @@ function collectModuleBundled(absPath, collector) {
20438
20436
  } catch (err) {
20439
20437
  raw2 = "{}";
20440
20438
  }
20441
- collector.modules.push({ key, code: `module.exports = ${raw2};`, dir, deps: {} });
20442
- return key;
20439
+ return registry.register(absPath, { code: `module.exports = ${raw2};`, dir, deps: {} });
20443
20440
  }
20444
20441
  let mtimeMs = -1;
20445
20442
  try {
@@ -20457,8 +20454,7 @@ function collectModuleBundled(absPath, collector) {
20457
20454
  if (!src2 || !src2.ast) {
20458
20455
  if (src2?.parseError) throw src2.parseError;
20459
20456
  const raw2 = src2 ? src2.raw : "// unreadable during build\nmodule.exports = {};";
20460
- collector.modules.push({ key, code: raw2, dir, deps: {} });
20461
- return key;
20457
+ return registry.register(absPath, { code: raw2, dir, deps: {} });
20462
20458
  }
20463
20459
  let stripped = src2.ast;
20464
20460
  if (hasTsSyntax(src2.ast)) stripped = stripTsTypes(src2.ast);
@@ -20473,14 +20469,14 @@ function collectModuleBundled(absPath, collector) {
20473
20469
  if (!isRelativeSpec(spec)) continue;
20474
20470
  const depPath = resolveSsrModule(spec, dir);
20475
20471
  if (!depPath) continue;
20476
- deps[spec] = collectModuleBundled(depPath, collector);
20472
+ deps[spec] = collectModuleBundled(depPath, registry);
20477
20473
  }
20478
- collector.modules.push({ key, code, dir, deps });
20479
- return key;
20474
+ return registry.register(absPath, { code, dir, deps });
20480
20475
  }
20481
- function collectModuleBundle(importStrs, fromDir, collector) {
20476
+ function collectModuleBundle(importStrs, fromDir, registry, collector) {
20482
20477
  const bindings = [];
20483
20478
  if (!fromDir) return bindings;
20479
+ const seenKeys = /* @__PURE__ */ new Set();
20484
20480
  for (const imp of importStrs) {
20485
20481
  const target = importModuleTarget(imp);
20486
20482
  if (!target || isCompilerOwnedTarget(target) || isValueLessTarget(target)) continue;
@@ -20488,14 +20484,19 @@ function collectModuleBundle(importStrs, fromDir, collector) {
20488
20484
  if (!resolved) {
20489
20485
  continue;
20490
20486
  }
20491
- const key = collectModuleBundled(resolved, collector);
20487
+ const key = collectModuleBundled(resolved, registry);
20488
+ const mod = registry.getModule(key);
20489
+ if (mod && !seenKeys.has(key)) {
20490
+ seenKeys.add(key);
20491
+ collector.modules.push({ key, dir: mod.dir, deps: mod.deps });
20492
+ }
20492
20493
  for (const pair of importBindingPairs(imp)) {
20493
20494
  bindings.push({ local: pair.local, key, kind: pair.imported });
20494
20495
  }
20495
20496
  }
20496
20497
  return bindings;
20497
20498
  }
20498
- var RUNTIME_PREFIXES, EXTENSIONS, BUILTIN_PREFIX, BUILTIN_CACHE, MODULE_CACHE, MAX_CACHE_ENTRIES, depStack, rawSourceCache, BUILD_CACHE_MAX, BUILD_CACHE_EVICT, EVALUATING, EMPTY_ALIASES, ALIAS_CACHE, exportCounter, bundledCodeCache;
20499
+ var RUNTIME_PREFIXES, EXTENSIONS, BUILTIN_PREFIX, BUILTIN_CACHE, MODULE_CACHE, MAX_CACHE_ENTRIES, depStack, rawSourceCache, BUILD_CACHE_MAX, BUILD_CACHE_EVICT, EVALUATING, EMPTY_ALIASES, ALIAS_CACHE, exportCounter, ModuleRegistry, bundledCodeCache;
20499
20500
  var init_module_imports = __esm({
20500
20501
  "../compiler/src/module-imports.ts"() {
20501
20502
  "use strict";
@@ -20517,6 +20518,45 @@ var init_module_imports = __esm({
20517
20518
  EMPTY_ALIASES = { exact: /* @__PURE__ */ new Map(), wildcard: [] };
20518
20519
  ALIAS_CACHE = /* @__PURE__ */ new Map();
20519
20520
  exportCounter = 0;
20521
+ ModuleRegistry = class {
20522
+ keysByAbs = /* @__PURE__ */ new Map();
20523
+ data = /* @__PURE__ */ new Map();
20524
+ has(absPath) {
20525
+ return this.keysByAbs.has(absPath);
20526
+ }
20527
+ getKey(absPath) {
20528
+ return this.keysByAbs.get(absPath);
20529
+ }
20530
+ get size() {
20531
+ return this.data.size;
20532
+ }
20533
+ /** Register a module's transpiled body, returning its globally-unique key. */
20534
+ register(absPath, entry) {
20535
+ const existing2 = this.keysByAbs.get(absPath);
20536
+ if (existing2) return existing2;
20537
+ const key = `__veskMod${this.data.size}`;
20538
+ this.keysByAbs.set(absPath, key);
20539
+ this.data.set(key, entry);
20540
+ return key;
20541
+ }
20542
+ getModule(key) {
20543
+ return this.data.get(key);
20544
+ }
20545
+ /** All registered modules as a plain object keyed by synthetic key, for
20546
+ * passing to `hydratePrecompile` at SSR load time. */
20547
+ modules() {
20548
+ return Object.fromEntries(this.data.entries());
20549
+ }
20550
+ /** Emit a self-contained module registry source file. */
20551
+ toModuleSource() {
20552
+ const parts = [];
20553
+ for (const [key, entry] of this.data) {
20554
+ parts.push(`${JSON.stringify(key)}: ${JSON.stringify({ code: entry.code, dir: entry.dir, deps: entry.deps })}`);
20555
+ }
20556
+ return `export const __veskModules = {${parts.join(",")}};
20557
+ `;
20558
+ }
20559
+ };
20520
20560
  bundledCodeCache = /* @__PURE__ */ new Map();
20521
20561
  }
20522
20562
  });
@@ -49923,17 +49963,18 @@ init_md_inline();
49923
49963
  init_module_imports();
49924
49964
  import { readFileSync as readFileSync4 } from "node:fs";
49925
49965
  import { dirname as dirname6 } from "node:path";
49926
- function precompileFile(source, sourcePath2) {
49927
- if (sourcePath2 === void 0) return precompileFileInternal(source, sourcePath2, /* @__PURE__ */ new Set());
49966
+ function precompileFile(source, sourcePath2, registry) {
49967
+ const reg = registry ?? new ModuleRegistry();
49968
+ if (sourcePath2 === void 0) return precompileFileInternal(source, sourcePath2, /* @__PURE__ */ new Set(), reg);
49928
49969
  const hit = precompileCache.get(sourcePath2);
49929
49970
  if (hit !== void 0 && hit.source === source) return hit.plan;
49930
- const plan = precompileFileInternal(source, sourcePath2, /* @__PURE__ */ new Set());
49971
+ const plan = precompileFileInternal(source, sourcePath2, /* @__PURE__ */ new Set(), reg);
49931
49972
  if (precompileCache.size >= 512) precompileCache.clear();
49932
49973
  precompileCache.set(sourcePath2, { source, plan });
49933
49974
  return plan;
49934
49975
  }
49935
49976
  var precompileCache = /* @__PURE__ */ new Map();
49936
- function precompileFileInternal(source, sourcePath2, seenImportFiles) {
49977
+ function precompileFileInternal(source, sourcePath2, seenImportFiles, registry) {
49937
49978
  if (sourcePath2) {
49938
49979
  const dir = dirname6(sourcePath2);
49939
49980
  source = inlineMdImportsFrom(source, sourcePath2, guessProjectRoots(dir));
@@ -49954,8 +49995,8 @@ function precompileFileInternal(source, sourcePath2, seenImportFiles) {
49954
49995
  const topLevelCode = transformTopLevelForActions(ir.topLevelCode, "server");
49955
49996
  const metadataSource = ir.metadataSource || null;
49956
49997
  const runtimeImports = ir.imports.slice();
49957
- const collector = { keysByAbs: /* @__PURE__ */ new Map(), modules: [] };
49958
- const bindings = sourcePath2 !== void 0 ? collectModuleBundle(ir.imports, dirname6(sourcePath2), collector) : [];
49998
+ const collector = { modules: [] };
49999
+ const bindings = sourcePath2 !== void 0 ? collectModuleBundle(ir.imports, dirname6(sourcePath2), registry, collector) : [];
49959
50000
  const subFiles = [];
49960
50001
  if (sourcePath2 !== void 0) {
49961
50002
  const vskPaths = [
@@ -49967,7 +50008,7 @@ function precompileFileInternal(source, sourcePath2, seenImportFiles) {
49967
50008
  seenImportFiles.add(importPath);
49968
50009
  try {
49969
50010
  const importedSrc = readFileSync4(importPath, "utf-8");
49970
- const subPlan = precompileFileInternal(importedSrc, importPath, seenImportFiles);
50011
+ const subPlan = precompileFileInternal(importedSrc, importPath, seenImportFiles, registry);
49971
50012
  subFiles.push({ importPath, plan: subPlan });
49972
50013
  } catch {
49973
50014
  }
@@ -50018,6 +50059,7 @@ function resolveCssUrls(opts) {
50018
50059
 
50019
50060
  // ../adapter/src/ssr-function.ts
50020
50061
  init_default_pages();
50062
+ init_module_imports();
50021
50063
  function resolveBoundaryFile(sourceDir, appDir, file) {
50022
50064
  const rel = relative(appDir, sourceDir).split("/").filter(Boolean);
50023
50065
  for (let depth = rel.length; depth >= 0; depth--) {
@@ -50052,12 +50094,12 @@ function routeName(segments) {
50052
50094
  function extractCompName(src2) {
50053
50095
  return resolveComponentName(src2);
50054
50096
  }
50055
- function precompilePlan(entryPath) {
50097
+ function precompilePlan(entryPath, registry) {
50056
50098
  const src2 = readFileSync7(entryPath, "utf-8");
50057
- return JSON.stringify(precompileFile(src2, entryPath));
50099
+ return JSON.stringify(precompileFile(src2, entryPath, registry));
50058
50100
  }
50059
50101
  function hydrateInvoke(planExpr) {
50060
- return `(() => { try { return hydratePrecompile(${planExpr}); } catch { return null; } })()`;
50102
+ return `(() => { try { return hydratePrecompile(${planExpr}, __veskModules); } catch { return null; } })()`;
50061
50103
  }
50062
50104
  function buildParamExtraction(node, urlParts) {
50063
50105
  const parts = [];
@@ -50138,7 +50180,8 @@ function persistedStoreSsrCode() {
50138
50180
  ""
50139
50181
  ].join("\n");
50140
50182
  }
50141
- function generateSsrFunction(routeNode, appDir, outDir, componentMap, options) {
50183
+ function generateSsrFunction(routeNode, appDir, outDir, componentMap, options, registry) {
50184
+ const reg = registry ?? new ModuleRegistry();
50142
50185
  const ancestorLayouts = options?.ancestorLayouts || [];
50143
50186
  const middlewareCode = options?.middlewareCode || null;
50144
50187
  const headExtra = options?.headExtra || null;
@@ -50162,34 +50205,34 @@ function generateSsrFunction(routeNode, appDir, outDir, componentMap, options) {
50162
50205
  const entryPath = resolve7(appDir, entry.sourceDir, "layout.vsk");
50163
50206
  const entrySrc = readFileSync7(entryPath, "utf-8");
50164
50207
  const entryComp = extractCompName(entrySrc) || "Layout";
50165
- const plan = precompilePlan(entryPath);
50208
+ const plan = precompilePlan(entryPath, reg);
50166
50209
  layoutDecls.push({
50167
50210
  comp: JSON.stringify(entryComp),
50168
50211
  plan,
50169
50212
  compiled: hydrateInvoke(plan)
50170
50213
  });
50171
50214
  }
50172
- const pagePlan = precompilePlan(pagePath);
50215
+ const pagePlan = precompilePlan(pagePath, reg);
50173
50216
  const pageComp = extractCompName(readFileSync7(pagePath, "utf-8")) || "Page";
50174
50217
  const errorPath = resolveErrorFile(routeNode.sourceDir, appDir);
50175
50218
  const errorSrc = errorPath ? readFileSync7(errorPath, "utf-8") : null;
50176
50219
  const errorComp = errorPath ? extractCompName(errorSrc) || "Error" : null;
50177
50220
  const errorCompDecl = errorPath ? `const _errorComp = ${JSON.stringify(errorComp)};
50178
50221
  ` : "const _errorComp = null;\n";
50179
- const errorPlanExpr = errorPath ? hydrateInvoke(precompilePlan(errorPath)) : "null";
50222
+ const errorPlanExpr = errorPath ? hydrateInvoke(precompilePlan(errorPath, reg)) : "null";
50180
50223
  const notFoundPath = resolveNotFoundFile(routeNode.sourceDir, appDir);
50181
50224
  const notFoundSrc = notFoundPath ? readFileSync7(notFoundPath, "utf-8") : null;
50182
50225
  const notFoundComp = notFoundPath ? extractCompName(notFoundSrc) || "NotFound" : null;
50183
50226
  const notFoundCompDecl = notFoundPath ? `const _notFoundComp = ${JSON.stringify(notFoundComp)};
50184
50227
  ` : "const _notFoundComp = null;\n";
50185
- const notFoundPlanExpr = notFoundPath ? hydrateInvoke(precompilePlan(notFoundPath)) : "null";
50228
+ const notFoundPlanExpr = notFoundPath ? hydrateInvoke(precompilePlan(notFoundPath, reg)) : "null";
50186
50229
  let src2 = "";
50187
50230
  if (layoutDecls.length > 0) {
50188
50231
  src2 = errorCompDecl + notFoundCompDecl;
50189
50232
  src2 += `const _pageComp = ${JSON.stringify(pageComp)};
50190
50233
  `;
50191
50234
  src2 += `let _pageCompiled = null;
50192
- function __getPageCompiled() { if (!_pageCompiled) _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _pageCompiled; }
50235
+ function __getPageCompiled() { if (!_pageCompiled) _pageCompiled = (() => { try { return hydratePrecompile(${pagePlan}, __veskModules); } catch { return null; } })(); return _pageCompiled; }
50193
50236
  `;
50194
50237
  src2 += `const _layoutCompList = [${layoutDecls.map((d) => d.comp).join(", ")}];
50195
50238
  `;
@@ -50209,7 +50252,7 @@ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = $
50209
50252
  src2 += `const _comp = ${JSON.stringify(pageComp)};
50210
50253
  `;
50211
50254
  src2 += `let _compiled = null;
50212
- function __getCompiled() { if (!_compiled) _compiled = (() => { try { return hydratePrecompile(${pagePlan}); } catch { return null; } })(); return _compiled; }
50255
+ function __getCompiled() { if (!_compiled) _compiled = (() => { try { return hydratePrecompile(${pagePlan}, __veskModules); } catch { return null; } })(); return _compiled; }
50213
50256
  `;
50214
50257
  src2 += `let _errorCompiled = null;
50215
50258
  function __getErrorCompiled() { if (!_errorCompiled) _errorCompiled = ${errorPlanExpr}; return _errorCompiled; }
@@ -50232,11 +50275,11 @@ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = $
50232
50275
  const compMap = componentMap || /* @__PURE__ */ new Map();
50233
50276
  const regPlans = [];
50234
50277
  for (const [compName, compPath] of compMap) {
50235
- const plan = precompilePlan(compPath);
50278
+ const plan = precompilePlan(compPath, reg);
50236
50279
  regPlans.push(` __regPlans.set(${JSON.stringify(compName)}, ${JSON.stringify(plan)});`);
50237
50280
  compRegEntries.push(` __componentRegistry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {
50238
50281
  let _compiled = __regCompiled.get(${JSON.stringify(compName)});
50239
- if (!_compiled) { _compiled = hydratePrecompile(__regPlans.get(${JSON.stringify(compName)})); __regCompiled.set(${JSON.stringify(compName)}, _compiled); }
50282
+ if (!_compiled) { _compiled = hydratePrecompile(__regPlans.get(${JSON.stringify(compName)}), __veskModules); __regCompiled.set(${JSON.stringify(compName)}, _compiled); }
50240
50283
  const result = await renderPage('', ${JSON.stringify(compName)}, props, __registry, { hydrate: true, cached: _compiled });
50241
50284
  return result.body;
50242
50285
  });`);
@@ -50594,6 +50637,7 @@ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = $
50594
50637
  ""
50595
50638
  ].join("\n");
50596
50639
  const funcCode = [
50640
+ "import { __veskModules } from '../__vesk-modules.mjs';",
50597
50641
  "import { renderFullPage, renderPageStream, renderPage, hydratePrecompile, parseCookies, getAction, validateActionInput, issuesToFieldMap, storeDataScriptGlobal, withSsrStore, assertSameOrigin, VeskRequest, installPersistedStoreServerHooks, persistedStoreCookieName, getPersistedStoreKeys, resetPersistedStoreKeys, buildStorePrePaintPayload, storeInitScriptGlobal, storeInitScriptTag } from '../runtime.js';",
50598
50642
  "",
50599
50643
  middlewareCode || "",
@@ -50625,6 +50669,7 @@ function __getNotFoundCompiled() { if (!_notFoundCompiled) _notFoundCompiled = $
50625
50669
 
50626
50670
  // ../adapter/dist/index.js
50627
50671
  init_actions();
50672
+ init_module_imports();
50628
50673
 
50629
50674
  // ../adapter/src/api-function.ts
50630
50675
  init_strip_ts();
@@ -54199,7 +54244,7 @@ async function build2(appDir, options) {
54199
54244
  mwCode = compileMiddlewareCode(mwSources);
54200
54245
  }
54201
54246
  const ssrAncestorLayouts = isStandalone ? [] : ancestorLayouts;
54202
- const { funcPath, funcCode, name } = generateSsrFunction(node, appDir, outDir, componentMap, { ancestorLayouts: ssrAncestorLayouts, middlewareCode: mwCode, headExtra: pluginHeadExtra, clientScriptUrl: clientUrl, clientScriptIntegrity: clientIntegrity });
54247
+ const { funcPath, funcCode, name } = generateSsrFunction(node, appDir, outDir, componentMap, { ancestorLayouts: ssrAncestorLayouts, middlewareCode: mwCode, headExtra: pluginHeadExtra, clientScriptUrl: clientUrl, clientScriptIntegrity: clientIntegrity }, registry);
54203
54248
  writeFileSync12(funcPath, funcCode, "utf-8");
54204
54249
  const pagePath = resolve21(appDir, node.sourceDir, "page.vsk");
54205
54250
  if (existsSync22(pagePath)) {
@@ -54231,7 +54276,9 @@ async function build2(appDir, options) {
54231
54276
  walk9(node.children || [], childAncestorLayouts);
54232
54277
  }
54233
54278
  }
54279
+ const registry = new ModuleRegistry();
54234
54280
  walk9(routeTree);
54281
+ writeFileSync12(resolve21(outDir, "server", "__vesk-modules.mjs"), registry.toModuleSource(), "utf-8");
54235
54282
  markPhase("server runtime + ssr functions");
54236
54283
  const apiRoutes = [];
54237
54284
  function walkApi(nodes) {
@@ -64801,6 +64848,7 @@ function renderDefaultNotFoundPage2(opts = {}) {
64801
64848
  import { readFileSync as readFileSync36, existsSync as existsSync37 } from "node:fs";
64802
64849
  import { resolve as resolve33, relative as relative7, join as join26 } from "node:path";
64803
64850
  init_default_pages();
64851
+ init_module_imports();
64804
64852
  function resolveBoundaryFileForUrl2(pathname, appDir, file) {
64805
64853
  const segments = pathname.split("/").filter(Boolean);
64806
64854
  for (let depth = segments.length; depth >= 0; depth--) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.83",
3
+ "version": "0.2.85",
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.83",
12
- "@vesk/compiler": "^0.2.83",
13
- "@vesk/plugin-tailwind": "^0.2.83",
14
- "@vesk/runtime": "^0.2.83",
11
+ "@vesk/adapter": "^0.2.85",
12
+ "@vesk/compiler": "^0.2.85",
13
+ "@vesk/plugin-tailwind": "^0.2.85",
14
+ "@vesk/runtime": "^0.2.85",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",