@vesk/vesk-cli 0.2.62 → 0.2.63

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 +180 -34
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -49922,6 +49922,30 @@ init_vsk_collision();
49922
49922
  init_vsk_imports();
49923
49923
  init_md_inline();
49924
49924
  init_module_imports();
49925
+ import { availableParallelism } from "node:os";
49926
+ async function mapWithConcurrency(items, limit, fn) {
49927
+ const out = new Array(items.length);
49928
+ let next = 0;
49929
+ let firstError = null;
49930
+ const worker = async () => {
49931
+ for (; ; ) {
49932
+ const i = next++;
49933
+ if (i >= items.length) return;
49934
+ if (firstError !== null) return;
49935
+ try {
49936
+ out[i] = await fn(items[i], i);
49937
+ } catch (e) {
49938
+ if (firstError === null) firstError = e;
49939
+ return;
49940
+ }
49941
+ }
49942
+ };
49943
+ const workers = [];
49944
+ for (let i = 0; i < Math.min(limit, items.length); i++) workers.push(worker());
49945
+ await Promise.all(workers);
49946
+ if (firstError !== null) throw firstError;
49947
+ return out;
49948
+ }
49925
49949
  var __dirname3 = dirname8(fileURLToPath2(import.meta.url));
49926
49950
  function fileUnchanged(filePath, cached) {
49927
49951
  try {
@@ -50340,6 +50364,13 @@ function removeCompiledNodes(code, isTarget) {
50340
50364
  }
50341
50365
  return code;
50342
50366
  }
50367
+ var SHARED_CHUNK_NAME = "shared.js";
50368
+ function buildChunkName(appDir, node) {
50369
+ const dir = relative2(appDir, node.sourceDir || "");
50370
+ const parts = dir.split(sep).filter(Boolean);
50371
+ const slug = parts.length > 0 ? parts.join("-") : "index";
50372
+ return slug.replace(/[\[\]]/g, "_");
50373
+ }
50343
50374
  async function generateClientBundle(routeTree, appDir, componentMap, options) {
50344
50375
  const runtimeDir = findRuntimeSrc2(appDir);
50345
50376
  let seen = /* @__PURE__ */ new Set();
@@ -50348,6 +50379,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
50348
50379
  const runtimeImportNames = /* @__PURE__ */ new Set();
50349
50380
  const cache2 = options?.cache;
50350
50381
  const only = options?.only && options.only.length > 0 ? new Set(options.only) : null;
50382
+ const onlyRoutes = options?.onlyRoutes && options.onlyRoutes.length > 0 ? new Set(options.onlyRoutes) : null;
50351
50383
  const returnEdited = !!options?.returnEditedSources && !!only;
50352
50384
  const editedSources = returnEdited ? /* @__PURE__ */ new Map() : void 0;
50353
50385
  const editedNames = returnEdited ? /* @__PURE__ */ new Map() : void 0;
@@ -50481,12 +50513,6 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
50481
50513
  });
50482
50514
  }
50483
50515
  }
50484
- function buildChunkName(node) {
50485
- const dir = relative2(appDir, node.sourceDir || "");
50486
- const parts = dir.split(sep).filter(Boolean);
50487
- const slug = parts.length > 0 ? parts.join("-") : "index";
50488
- return slug.replace(/[\[\]]/g, "_");
50489
- }
50490
50516
  const codeSplit = !!options?.codeSplit;
50491
50517
  const transformPlugins = options?.plugins || [];
50492
50518
  const componentOwners = new VskComponentOwners();
@@ -50536,21 +50562,25 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
50536
50562
  compileFile2(loadingPath, node.loading, chunkCode, chunkImports);
50537
50563
  }
50538
50564
  if (chunkCode.length > 0) {
50539
- const chunkName = `page-${buildChunkName(node)}.js`;
50540
- if (!chunkImports.ok) console.error("[vesk] chunk import merge aborted for", chunkName + ":", chunkImports.reason);
50541
- const head = chunkImports.render();
50542
- const code = (head ? head + "\n\n" : "") + chunkCode.join("\n\n");
50543
- chunkEntries.push({ name: chunkName, code, node, importsTable: chunkImports, imports: chunkHasImports(head.length, !chunkImports.ok) });
50565
+ const chunkName = `page-${buildChunkName(appDir, node)}.js`;
50566
+ if (!onlyRoutes || onlyRoutes.has(node.fullPath)) {
50567
+ if (!chunkImports.ok) console.error("[vesk] chunk import merge aborted for", chunkName + ":", chunkImports.reason);
50568
+ const head = chunkImports.render();
50569
+ const code = (head ? head + "\n\n" : "") + chunkCode.join("\n\n");
50570
+ chunkEntries.push({ name: chunkName, code, node, importsTable: chunkImports, imports: chunkHasImports(head.length, !chunkImports.ok) });
50571
+ }
50544
50572
  }
50545
50573
  walkSplit2(node.children || [], [..._chain, node]);
50546
50574
  }
50547
50575
  }, annotate2 = function(nodes) {
50548
50576
  for (const node of nodes) {
50549
- const chunkName = `page-${buildChunkName(node)}.js`;
50577
+ const chunkName = `page-${buildChunkName(appDir, node)}.js`;
50550
50578
  const emitted = chunks.find((c) => c.name === chunkName && c.code.trim());
50551
50579
  if (emitted) {
50552
50580
  const fileName = options?.hmr ? chunkName : hashedName(chunkName, emitted.code);
50553
50581
  node.chunk = `/_vesk/static/${fileName}`;
50582
+ } else if (options?.skipRouteChunks) {
50583
+ node.chunk = `/_vesk/static/${chunkName}`;
50554
50584
  }
50555
50585
  annotate2(node.children || []);
50556
50586
  }
@@ -50569,7 +50599,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
50569
50599
  if (!sharedImports.ok) console.error("[vesk] chunk import merge aborted for shared.js:", sharedImports.reason);
50570
50600
  const head = sharedImports.render();
50571
50601
  const code = (head ? head + "\n\n" : "") + sharedCode.join("\n\n");
50572
- chunkEntries.push({ name: "shared.js", code, node: null, importsTable: sharedImports, imports: chunkHasImports(head.length, !sharedImports.ok) });
50602
+ chunkEntries.push({ name: SHARED_CHUNK_NAME, code, node: null, importsTable: sharedImports, imports: chunkHasImports(head.length, !sharedImports.ok) });
50573
50603
  }
50574
50604
  const chunkIIFE = (body) => `(()=>{
50575
50605
  const __components = globalThis.__components || (globalThis.__components = {});
@@ -50669,8 +50699,8 @@ ${body}
50669
50699
  });
50670
50700
  }
50671
50701
  } : null;
50672
- for (const entry of chunkEntries) {
50673
- if (!entry.code.trim()) continue;
50702
+ const buildChunkEntry = async (entry) => {
50703
+ if (!entry.code.trim()) return null;
50674
50704
  let finalCode;
50675
50705
  if (entry.imports) {
50676
50706
  const tmpBase = mkdtempSync(join7(resolve10(appDir, ".."), "tmp-vesk-chunk-"));
@@ -50728,7 +50758,13 @@ ${entry.code}
50728
50758
  } else {
50729
50759
  finalCode = chunkIIFE(demoteExports(entry.code));
50730
50760
  }
50731
- chunks.push({ name: entry.name, code: finalCode });
50761
+ return { name: entry.name, code: finalCode };
50762
+ };
50763
+ const effectiveChunkEntries = options?.skipRouteChunks ? chunkEntries.filter((e) => e.name === SHARED_CHUNK_NAME) : chunkEntries;
50764
+ const CHUNK_CONCURRENCY = Math.max(1, Math.min(6, (availableParallelism?.() ?? 4) - 1));
50765
+ const built = await mapWithConcurrency(effectiveChunkEntries, CHUNK_CONCURRENCY, buildChunkEntry);
50766
+ for (const c of built) {
50767
+ if (c !== null) chunks.push(c);
50732
50768
  }
50733
50769
  annotate2(routeTree);
50734
50770
  sharedModuleBundle = sharedBundleCode;
@@ -56237,6 +56273,35 @@ init_vsk_collision();
56237
56273
  init_vsk_imports();
56238
56274
  init_md_inline();
56239
56275
  init_module_imports();
56276
+ import { availableParallelism as availableParallelism2 } from "node:os";
56277
+ async function mapWithConcurrency2(items, limit, fn) {
56278
+ const out = new Array(items.length);
56279
+ let next = 0;
56280
+ let firstError = null;
56281
+ const worker = async () => {
56282
+ for (; ; ) {
56283
+ const i = next++;
56284
+ if (i >= items.length)
56285
+ return;
56286
+ if (firstError !== null)
56287
+ return;
56288
+ try {
56289
+ out[i] = await fn(items[i], i);
56290
+ } catch (e) {
56291
+ if (firstError === null)
56292
+ firstError = e;
56293
+ return;
56294
+ }
56295
+ }
56296
+ };
56297
+ const workers = [];
56298
+ for (let i = 0; i < Math.min(limit, items.length); i++)
56299
+ workers.push(worker());
56300
+ await Promise.all(workers);
56301
+ if (firstError !== null)
56302
+ throw firstError;
56303
+ return out;
56304
+ }
56240
56305
  var __dirname7 = dirname18(fileURLToPath6(import.meta.url));
56241
56306
  function fileUnchanged2(filePath, cached) {
56242
56307
  try {
@@ -56705,6 +56770,13 @@ function removeCompiledNodes2(code, isTarget) {
56705
56770
  }
56706
56771
  return code;
56707
56772
  }
56773
+ var SHARED_CHUNK_NAME2 = "shared.js";
56774
+ function buildChunkName2(appDir, node) {
56775
+ const dir = relative6(appDir, node.sourceDir || "");
56776
+ const parts = dir.split(sep3).filter(Boolean);
56777
+ const slug = parts.length > 0 ? parts.join("-") : "index";
56778
+ return slug.replace(/[\[\]]/g, "_");
56779
+ }
56708
56780
  async function generateClientBundle2(routeTree, appDir, componentMap, options) {
56709
56781
  const runtimeDir = findRuntimeSrc3(appDir);
56710
56782
  let seen = /* @__PURE__ */ new Set();
@@ -56713,6 +56785,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
56713
56785
  const runtimeImportNames = /* @__PURE__ */ new Set();
56714
56786
  const cache2 = options?.cache;
56715
56787
  const only = options?.only && options.only.length > 0 ? new Set(options.only) : null;
56788
+ const onlyRoutes = options?.onlyRoutes && options.onlyRoutes.length > 0 ? new Set(options.onlyRoutes) : null;
56716
56789
  const returnEdited = !!options?.returnEditedSources && !!only;
56717
56790
  const editedSources = returnEdited ? /* @__PURE__ */ new Map() : void 0;
56718
56791
  const editedNames = returnEdited ? /* @__PURE__ */ new Map() : void 0;
@@ -56856,12 +56929,6 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
56856
56929
  });
56857
56930
  }
56858
56931
  }
56859
- function buildChunkName(node) {
56860
- const dir = relative6(appDir, node.sourceDir || "");
56861
- const parts = dir.split(sep3).filter(Boolean);
56862
- const slug = parts.length > 0 ? parts.join("-") : "index";
56863
- return slug.replace(/[\[\]]/g, "_");
56864
- }
56865
56932
  const codeSplit = !!options?.codeSplit;
56866
56933
  const transformPlugins = options?.plugins || [];
56867
56934
  const componentOwners = new VskComponentOwners();
@@ -56913,22 +56980,26 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
56913
56980
  compileFile2(loadingPath, node.loading, chunkCode, chunkImports);
56914
56981
  }
56915
56982
  if (chunkCode.length > 0) {
56916
- const chunkName = `page-${buildChunkName(node)}.js`;
56917
- if (!chunkImports.ok)
56918
- console.error("[vesk] chunk import merge aborted for", chunkName + ":", chunkImports.reason);
56919
- const head = chunkImports.render();
56920
- const code = (head ? head + "\n\n" : "") + chunkCode.join("\n\n");
56921
- chunkEntries.push({ name: chunkName, code, node, importsTable: chunkImports, imports: chunkHasImports2(head.length, !chunkImports.ok) });
56983
+ const chunkName = `page-${buildChunkName2(appDir, node)}.js`;
56984
+ if (!onlyRoutes || onlyRoutes.has(node.fullPath)) {
56985
+ if (!chunkImports.ok)
56986
+ console.error("[vesk] chunk import merge aborted for", chunkName + ":", chunkImports.reason);
56987
+ const head = chunkImports.render();
56988
+ const code = (head ? head + "\n\n" : "") + chunkCode.join("\n\n");
56989
+ chunkEntries.push({ name: chunkName, code, node, importsTable: chunkImports, imports: chunkHasImports2(head.length, !chunkImports.ok) });
56990
+ }
56922
56991
  }
56923
56992
  walkSplit2(node.children || [], [..._chain, node]);
56924
56993
  }
56925
56994
  }, annotate2 = function(nodes) {
56926
56995
  for (const node of nodes) {
56927
- const chunkName = `page-${buildChunkName(node)}.js`;
56996
+ const chunkName = `page-${buildChunkName2(appDir, node)}.js`;
56928
56997
  const emitted = chunks.find((c) => c.name === chunkName && c.code.trim());
56929
56998
  if (emitted) {
56930
56999
  const fileName = options?.hmr ? chunkName : hashedName(chunkName, emitted.code);
56931
57000
  node.chunk = `/_vesk/static/${fileName}`;
57001
+ } else if (options?.skipRouteChunks) {
57002
+ node.chunk = `/_vesk/static/${chunkName}`;
56932
57003
  }
56933
57004
  annotate2(node.children || []);
56934
57005
  }
@@ -56948,7 +57019,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
56948
57019
  console.error("[vesk] chunk import merge aborted for shared.js:", sharedImports.reason);
56949
57020
  const head = sharedImports.render();
56950
57021
  const code = (head ? head + "\n\n" : "") + sharedCode.join("\n\n");
56951
- chunkEntries.push({ name: "shared.js", code, node: null, importsTable: sharedImports, imports: chunkHasImports2(head.length, !sharedImports.ok) });
57022
+ chunkEntries.push({ name: SHARED_CHUNK_NAME2, code, node: null, importsTable: sharedImports, imports: chunkHasImports2(head.length, !sharedImports.ok) });
56952
57023
  }
56953
57024
  const chunkIIFE = (body) => `(()=>{
56954
57025
  const __components = globalThis.__components || (globalThis.__components = {});
@@ -57051,9 +57122,9 @@ ${body}
57051
57122
  });
57052
57123
  }
57053
57124
  } : null;
57054
- for (const entry of chunkEntries) {
57125
+ const buildChunkEntry = async (entry) => {
57055
57126
  if (!entry.code.trim())
57056
- continue;
57127
+ return null;
57057
57128
  let finalCode;
57058
57129
  if (entry.imports) {
57059
57130
  const tmpBase = mkdtempSync2(join20(resolve24(appDir, ".."), "tmp-vesk-chunk-"));
@@ -57111,7 +57182,14 @@ ${entry.code}
57111
57182
  } else {
57112
57183
  finalCode = chunkIIFE(demoteExports2(entry.code));
57113
57184
  }
57114
- chunks.push({ name: entry.name, code: finalCode });
57185
+ return { name: entry.name, code: finalCode };
57186
+ };
57187
+ const effectiveChunkEntries = options?.skipRouteChunks ? chunkEntries.filter((e) => e.name === SHARED_CHUNK_NAME2) : chunkEntries;
57188
+ const CHUNK_CONCURRENCY = Math.max(1, Math.min(6, (availableParallelism2?.() ?? 4) - 1));
57189
+ const built = await mapWithConcurrency2(effectiveChunkEntries, CHUNK_CONCURRENCY, buildChunkEntry);
57190
+ for (const c of built) {
57191
+ if (c !== null)
57192
+ chunks.push(c);
57115
57193
  }
57116
57194
  annotate2(routeTree);
57117
57195
  sharedModuleBundle = sharedBundleCode;
@@ -64116,6 +64194,43 @@ async function startDevServer(port, projectDir, config, host) {
64116
64194
  for (const c of chunks) next.set(`/_vesk/static/${c.name}`, c.code);
64117
64195
  clientChunks = next;
64118
64196
  }
64197
+ const routeChunksBuilt = /* @__PURE__ */ new Set();
64198
+ let clientGeneration = 0;
64199
+ async function ensureRouteChunk(fullPath) {
64200
+ if (routeChunksBuilt.has(fullPath)) return;
64201
+ routeChunksBuilt.add(fullPath);
64202
+ const generation = clientGeneration;
64203
+ const { chunks } = await generateClientBundle2(routeTree, appDirPath, /* @__PURE__ */ new Map(), {
64204
+ importRuntime: true,
64205
+ hmr: true,
64206
+ codeSplit: true,
64207
+ cache: bundleCache,
64208
+ onlyRoutes: [fullPath],
64209
+ ...config.routeDataCache !== void 0 ? { routeDataCache: config.routeDataCache } : {}
64210
+ });
64211
+ if (generation !== clientGeneration) {
64212
+ routeChunksBuilt.delete(fullPath);
64213
+ return;
64214
+ }
64215
+ const next = new Map(clientChunks);
64216
+ for (const c of chunks) next.set(`/_vesk/static/${c.name}`, c.code);
64217
+ clientChunks = next;
64218
+ }
64219
+ function routeFullPathForChunk(chunkName) {
64220
+ let found = null;
64221
+ const walk9 = (nodes) => {
64222
+ for (const node of nodes) {
64223
+ if (found) return;
64224
+ if (`page-${buildChunkName2(appDirPath, node)}.js` === chunkName) {
64225
+ found = node.fullPath;
64226
+ return;
64227
+ }
64228
+ walk9(node.children || []);
64229
+ }
64230
+ };
64231
+ walk9(routeTree);
64232
+ return found;
64233
+ }
64119
64234
  async function buildClientBundle() {
64120
64235
  try {
64121
64236
  const { main, chunks } = await generateClientBundle2(routeTree, appDirPath, /* @__PURE__ */ new Map(), {
@@ -64123,6 +64238,11 @@ async function startDevServer(port, projectDir, config, host) {
64123
64238
  hmr: true,
64124
64239
  codeSplit: true,
64125
64240
  cache: bundleCache,
64241
+ // Startup cost otherwise scales with app size: one self-contained
64242
+ // compile + esbuild pass per route. A dev session visits a handful of
64243
+ // routes, so each route's chunk is built on first request instead
64244
+ // (see ensureRouteChunk).
64245
+ skipRouteChunks: true,
64126
64246
  ...config.routeDataCache !== void 0 ? { routeDataCache: config.routeDataCache } : {}
64127
64247
  });
64128
64248
  clientBundle = main;
@@ -64144,6 +64264,10 @@ async function startDevServer(port, projectDir, config, host) {
64144
64264
  returnEditedSources: true,
64145
64265
  ...config.routeDataCache !== void 0 ? { routeDataCache: config.routeDataCache } : {}
64146
64266
  });
64267
+ const keepShared = (name) => name === SHARED_CHUNK_NAME2;
64268
+ clientChunks = new Map([...clientChunks].filter(([url]) => keepShared(url.slice(url.lastIndexOf("/") + 1))));
64269
+ routeChunksBuilt.clear();
64270
+ clientGeneration++;
64147
64271
  storeChunks(chunks);
64148
64272
  return { err: null, editedSource: editedSources?.get(fullPath) ?? null, actualName: editedNames?.get(fullPath) ?? null };
64149
64273
  } catch (e) {
@@ -64634,7 +64758,19 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
64634
64758
  return;
64635
64759
  }
64636
64760
  if (url.pathname.startsWith("/_vesk/static/") && url.pathname.endsWith(".js")) {
64637
- const code = clientChunks.get(url.pathname);
64761
+ let code = clientChunks.get(url.pathname);
64762
+ if (code === void 0) {
64763
+ const name = url.pathname.slice(url.pathname.lastIndexOf("/") + 1);
64764
+ const fullPath = routeFullPathForChunk(name);
64765
+ if (fullPath) {
64766
+ try {
64767
+ await ensureRouteChunk(fullPath);
64768
+ } catch (e) {
64769
+ LOG.err(`client chunk build failed for ${name}:`, e.message);
64770
+ }
64771
+ code = clientChunks.get(url.pathname);
64772
+ }
64773
+ }
64638
64774
  if (code !== void 0) {
64639
64775
  res.writeHead(200, { "Content-Type": "application/javascript", "Cache-Control": "no-store" });
64640
64776
  res.end(code);
@@ -64842,6 +64978,16 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
64842
64978
  }
64843
64979
  const matched = match;
64844
64980
  const forData = req.headers["x-vesk-data"] === "1";
64981
+ if (!forData && matched && Array.isArray(matched.nodes)) {
64982
+ const leaf2 = matched.nodes.find((n) => n.page);
64983
+ if (leaf2 && typeof leaf2.fullPath === "string") {
64984
+ try {
64985
+ await ensureRouteChunk(leaf2.fullPath);
64986
+ } catch (e) {
64987
+ LOG.err(`client chunk build failed for ${leaf2.fullPath}:`, e.message);
64988
+ }
64989
+ }
64990
+ }
64845
64991
  async function renderSSR() {
64846
64992
  const ssg2 = globalThis;
64847
64993
  ssg2.__vsk_ssr_data = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.62",
3
+ "version": "0.2.63",
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.62",
12
- "@vesk/compiler": "^0.2.62",
13
- "@vesk/plugin-tailwind": "^0.2.62",
14
- "@vesk/runtime": "^0.2.62",
11
+ "@vesk/adapter": "^0.2.63",
12
+ "@vesk/compiler": "^0.2.63",
13
+ "@vesk/plugin-tailwind": "^0.2.63",
14
+ "@vesk/runtime": "^0.2.63",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",