@vesk/vesk-cli 0.2.72 → 0.2.76

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 +752 -382
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -1081,8 +1081,8 @@ function run_teardown(block2) {
1081
1081
  }
1082
1082
  function on_destroy(fn) {
1083
1083
  const block2 = scope();
1084
- if (block2 === null) return;
1085
- if (block2.tc === null) block2.tc = [];
1084
+ if (block2 == null) return;
1085
+ if (block2.tc == null) block2.tc = [];
1086
1086
  block2.tc.push(fn);
1087
1087
  }
1088
1088
  function with_block(block2, fn) {
@@ -2094,7 +2094,7 @@ async function runFetcher(handle2, timeout) {
2094
2094
  }
2095
2095
  }
2096
2096
  function sleep(ms) {
2097
- return new Promise((resolve41) => setTimeout(resolve41, ms));
2097
+ return new Promise((resolve42) => setTimeout(resolve42, ms));
2098
2098
  }
2099
2099
  function streamText(res, into, onChunk) {
2100
2100
  const decoder = new TextDecoder();
@@ -2896,12 +2896,12 @@ function hydrateViewport(container, componentFn, props, rootMargin = 500, option
2896
2896
  let cancelled = false;
2897
2897
  let cancelFn = () => {
2898
2898
  };
2899
- const promise = new Promise((resolve41) => {
2899
+ const promise = new Promise((resolve42) => {
2900
2900
  const finish = () => {
2901
2901
  cancelled = true;
2902
2902
  cancelFn = () => {
2903
2903
  };
2904
- resolve41();
2904
+ resolve42();
2905
2905
  };
2906
2906
  cancelFn = finish;
2907
2907
  if (!batchAlive(container, epoch, isCurrent)) return finish();
@@ -4422,7 +4422,8 @@ function usePathname() {
4422
4422
  return get(_state.path);
4423
4423
  }
4424
4424
  function useSearchParams() {
4425
- const s = get(_state.search);
4425
+ const routed = get(_state.search);
4426
+ const s = routed || (typeof window !== "undefined" && window.location?.search ? window.location.search.replace(/^\?/, "") : "");
4426
4427
  const sp = new URLSearchParams(s || "");
4427
4428
  const setter = (next) => {
4428
4429
  const q = typeof next === "string" ? next : new URLSearchParams(next).toString();
@@ -4616,7 +4617,7 @@ function ensureChunk(chunkUrl) {
4616
4617
  if (typeof document === "undefined" || typeof document.createElement !== "function") {
4617
4618
  return Promise.resolve();
4618
4619
  }
4619
- const promise = new Promise((resolve41, reject) => {
4620
+ const promise = new Promise((resolve42, reject) => {
4620
4621
  const s = document.createElement("script");
4621
4622
  s.src = chunkUrl;
4622
4623
  let settled = false;
@@ -4635,7 +4636,7 @@ function ensureChunk(chunkUrl) {
4635
4636
  loadedChunks.add(chunkUrl);
4636
4637
  inFlightChunks.delete(chunkUrl);
4637
4638
  failedChunks.delete(chunkUrl);
4638
- resolve41();
4639
+ resolve42();
4639
4640
  };
4640
4641
  s.onerror = () => {
4641
4642
  fail(new Error(`Failed to load chunk: ${chunkUrl}`));
@@ -4839,6 +4840,7 @@ async function renderNotFound(router, match, container) {
4839
4840
  } else if (typeof nfDom === "string") {
4840
4841
  container.innerHTML = nfDom;
4841
4842
  }
4843
+ router._currentMatch = match;
4842
4844
  return;
4843
4845
  }
4844
4846
  if (container.replaceChildren) container.replaceChildren();
@@ -5323,12 +5325,14 @@ function clearOfflineFlag(router, container) {
5323
5325
  router._showingOffline = false;
5324
5326
  if (container) container.__veskNetworkUI = false;
5325
5327
  }
5326
- async function renderErrorPage(router, match, container, error) {
5328
+ async function renderErrorPage(router, match, container, error, navToken) {
5329
+ const stale = () => navToken !== void 0 && (router._navToken || 0) !== navToken;
5327
5330
  clearOfflineFlag(router, container);
5328
5331
  const chain = match.matchChain;
5329
5332
  const paramValues = match.params;
5330
5333
  const errorFn = findErrorComponent(chain);
5331
5334
  if (!errorFn) {
5335
+ if (stale()) return;
5332
5336
  if (container.replaceChildren) container.replaceChildren();
5333
5337
  else container.innerHTML = "";
5334
5338
  container.innerHTML = defaultErrorHtml(500, "Internal Server Error");
@@ -5371,6 +5375,7 @@ async function renderErrorPage(router, match, container, error) {
5371
5375
  return result;
5372
5376
  };
5373
5377
  const dom = await runInBlockWindow(() => renderErrorChain(0));
5378
+ if (stale()) return;
5374
5379
  if (dom && typeof dom === "object" && dom.nodeType) {
5375
5380
  if (container.replaceChildren) container.replaceChildren(dom);
5376
5381
  else {
@@ -5382,6 +5387,7 @@ async function renderErrorPage(router, match, container, error) {
5382
5387
  }
5383
5388
  }
5384
5389
  async function hydrateInitial(router, match, container, strategy) {
5390
+ const hydrationNavToken = router._navToken || 0;
5385
5391
  const chain = match.matchChain;
5386
5392
  const paramValues = match.params;
5387
5393
  let pageNode = findPageNodeOrFailed(match);
@@ -5422,7 +5428,7 @@ async function hydrateInitial(router, match, container, strategy) {
5422
5428
  } catch {
5423
5429
  }
5424
5430
  }
5425
- await renderErrorPage(router, match, container, makeSsrError(message));
5431
+ await renderErrorPage(router, match, container, makeSsrError(message), hydrationNavToken);
5426
5432
  return;
5427
5433
  }
5428
5434
  const layoutNodes = chain.filter((n) => n.layout);
@@ -5446,7 +5452,8 @@ async function hydrateInitial(router, match, container, strategy) {
5446
5452
  router,
5447
5453
  match,
5448
5454
  container,
5449
- chunkErr || new Error(`Component "${pageNode._pageName}" is unavailable`)
5455
+ chunkErr || new Error(`Component "${pageNode._pageName}" is unavailable`),
5456
+ hydrationNavToken
5450
5457
  );
5451
5458
  return;
5452
5459
  }
@@ -5541,7 +5548,7 @@ async function hydrateInitial(router, match, container, strategy) {
5541
5548
  try {
5542
5549
  await renderMatch(router, match, container);
5543
5550
  } catch (err2) {
5544
- await renderErrorPage(router, match, container, err2);
5551
+ await renderErrorPage(router, match, container, err2, hydrationNavToken);
5545
5552
  }
5546
5553
  }
5547
5554
  }
@@ -6153,7 +6160,7 @@ function createFileRouter(routeTree, options = {}) {
6153
6160
  looksOffline().then((offline) => {
6154
6161
  navDebug("handleNavFailure verdict", offline ? "offline" : "online");
6155
6162
  if (offline) return void renderOfflinePage(router, match, container);
6156
- return void renderErrorPage(router, match, container, err);
6163
+ return void renderErrorPage(router, match, container, err, navToken);
6157
6164
  }).catch(() => {
6158
6165
  });
6159
6166
  };
@@ -6370,7 +6377,7 @@ var init_router = __esm({
6370
6377
  loadedChunks = /* @__PURE__ */ new Set();
6371
6378
  failedChunks = /* @__PURE__ */ new Map();
6372
6379
  inFlightChunks = /* @__PURE__ */ new Map();
6373
- CHUNK_LOAD_TIMEOUT_MS = 1e4;
6380
+ CHUNK_LOAD_TIMEOUT_MS = typeof window !== "undefined" && Number(window.__vesk_chunk_timeout_ms) || 1e4;
6374
6381
  _dataPromises = /* @__PURE__ */ new Map();
6375
6382
  PAGE_START_MARKER = "vesk:page";
6376
6383
  PAGE_END_MARKER = "/vesk:page";
@@ -20594,7 +20601,9 @@ function resolveVskTarget(target, sourcePath2) {
20594
20601
  return existsSync3(full) ? full : null;
20595
20602
  }
20596
20603
  const aliased = resolveImportPath(target, dirname3(sourcePath2));
20597
- return aliased !== target && existsSync3(aliased) ? aliased : null;
20604
+ if (aliased !== target && existsSync3(aliased)) return aliased;
20605
+ const published = resolveSsrModule(target, dirname3(sourcePath2));
20606
+ return published !== null && published.endsWith(".vsk") && existsSync3(published) ? published : null;
20598
20607
  }
20599
20608
  function vskImportValueNames(imports) {
20600
20609
  const names = [];
@@ -20670,6 +20679,30 @@ var init_vsk_imports = __esm({
20670
20679
  });
20671
20680
 
20672
20681
  // ../compiler/src/ir-generator.ts
20682
+ function resolveNamedTypeText(text) {
20683
+ if (!text || !__typeTexts || __typeTexts.size === 0) return text;
20684
+ let t = text.trim();
20685
+ for (let i = 0; i < 8; i++) {
20686
+ if (!/^[A-Za-z_$][\w$]*$/.test(t)) return t;
20687
+ const next = __typeTexts.get(t);
20688
+ if (!next || next === t) return t;
20689
+ t = next.trim();
20690
+ }
20691
+ return t;
20692
+ }
20693
+ function collectTypeTexts(ast, source) {
20694
+ const out = /* @__PURE__ */ new Map();
20695
+ for (const node of ast?.body || []) {
20696
+ const decl = (node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration") && node.declaration ? node.declaration : node;
20697
+ if (decl?.type !== "TSInterfaceDeclaration" && decl?.type !== "TSTypeAliasDeclaration") continue;
20698
+ const name = decl.id?.name;
20699
+ if (!name) continue;
20700
+ const typeNode = decl.type === "TSInterfaceDeclaration" ? decl.body : decl.typeAnnotation;
20701
+ if (!typeNode || typeof typeNode.start !== "number" || typeof typeNode.end !== "number") continue;
20702
+ out.set(name, source.slice(typeNode.start, typeNode.end).trim());
20703
+ }
20704
+ return out;
20705
+ }
20673
20706
  function parseExprNode(text) {
20674
20707
  try {
20675
20708
  const ParserClass = createBaseParser();
@@ -21310,18 +21343,48 @@ function slotReadPropName(expr) {
21310
21343
  }
21311
21344
  return null;
21312
21345
  }
21346
+ function splitTypeMembers(text) {
21347
+ const parts = [];
21348
+ let depth = 0;
21349
+ let last = 0;
21350
+ let i = 0;
21351
+ while (i < text.length) {
21352
+ const c = text[i];
21353
+ if (c === '"' || c === "'" || c === "`") {
21354
+ i = skipString(text, i);
21355
+ continue;
21356
+ }
21357
+ if (c === "/" && (text[i + 1] === "/" || text[i + 1] === "*")) {
21358
+ i = skipComment(text, i);
21359
+ continue;
21360
+ }
21361
+ if (c === "(" || c === "[" || c === "{" || c === "<") depth++;
21362
+ else if (c === ")" || c === "]" || c === "}" || c === ">") {
21363
+ if (depth > 0) depth--;
21364
+ } else if (depth === 0 && (c === ";" || c === "\n")) {
21365
+ parts.push(text.slice(last, i));
21366
+ last = i + 1;
21367
+ i++;
21368
+ continue;
21369
+ }
21370
+ i++;
21371
+ }
21372
+ parts.push(text.slice(last));
21373
+ return parts;
21374
+ }
21313
21375
  function slotPropNamesFromType(propsType) {
21314
21376
  const out = /* @__PURE__ */ new Set();
21315
21377
  if (!propsType) return out;
21316
21378
  const trimmed = propsType.trim();
21317
21379
  if (trimmed.startsWith("{")) {
21318
21380
  const inner = findBalancedEnd(trimmed, 0) === trimmed.length - 1 ? trimmed.slice(1, -1) : trimmed;
21319
- for (const part of splitTopLevel(inner, ";")) {
21381
+ const members = splitTypeMembers(inner);
21382
+ for (const part of members) {
21320
21383
  const colon = findTopLevelColon(part);
21321
21384
  if (colon === -1) continue;
21322
- const namePart = part.slice(0, colon).trim().replace(/^\$/, "").replace(/\?$/, "").trim();
21385
+ const namePart = part.slice(0, colon).trim().replace(/^readonly\s+/, "").replace(/^\$/, "").replace(/\?$/, "").trim();
21323
21386
  const typePart = part.slice(colon + 1).trim();
21324
- if (namePart && typePart.includes("Component")) out.add(namePart);
21387
+ if (namePart && /^[A-Za-z_$][\w$]*$/.test(namePart) && typePart.includes("Component")) out.add(namePart);
21325
21388
  }
21326
21389
  }
21327
21390
  return out;
@@ -22199,6 +22262,7 @@ function collectIdentifiers(node, into) {
22199
22262
  function generateIR(ast, source, filename) {
22200
22263
  __vskAnnotations = ast.__vskAnnotations ?? [];
22201
22264
  __slotProps = null;
22265
+ __typeTexts = collectTypeTexts(ast, source);
22202
22266
  const file = filename || "";
22203
22267
  const components = [];
22204
22268
  const imports = [];
@@ -22341,7 +22405,7 @@ function generateIR(ast, source, filename) {
22341
22405
  const bodyStmts = inner.body.body;
22342
22406
  const isClientComp = !!inner.client;
22343
22407
  const prevSlotProps = __slotProps;
22344
- __slotProps = slotPropNamesFromType(propsType);
22408
+ __slotProps = slotPropNamesFromType(resolveNamedTypeText(propsType));
22345
22409
  __propsParam = propsAlias || null;
22346
22410
  if (isStatementMode(bodyStmts)) {
22347
22411
  const raw2 = processStatementModeBody(source, bodyStmts, file);
@@ -22496,7 +22560,7 @@ function generateIR(ast, source, filename) {
22496
22560
  currentComponentCallHelpers = null;
22497
22561
  }
22498
22562
  }
22499
- var __vskAnnotations, __slotProps, __propsParam, currentVskNamespaceLocals, currentSourceFile, currentComponentValues, currentFileComponentNames, currentFileValueBindings, currentImportedNames, currentComponentCallHelpers;
22563
+ var __vskAnnotations, __slotProps, __typeTexts, __propsParam, currentVskNamespaceLocals, currentSourceFile, currentComponentValues, currentFileComponentNames, currentFileValueBindings, currentImportedNames, currentComponentCallHelpers;
22500
22564
  var init_ir_generator = __esm({
22501
22565
  "../compiler/src/ir-generator.ts"() {
22502
22566
  "use strict";
@@ -22510,6 +22574,7 @@ var init_ir_generator = __esm({
22510
22574
  init_tokens();
22511
22575
  __vskAnnotations = [];
22512
22576
  __slotProps = null;
22577
+ __typeTexts = null;
22513
22578
  __propsParam = null;
22514
22579
  currentVskNamespaceLocals = null;
22515
22580
  currentComponentValues = null;
@@ -29947,7 +30012,7 @@ is not a problem with esbuild. You need to fix your environment instead.
29947
30012
  let latestResultPromise;
29948
30013
  let provideLatestResult;
29949
30014
  if (isContext)
29950
- requestCallbacks["on-end"] = (id, request2) => new Promise((resolve41) => {
30015
+ requestCallbacks["on-end"] = (id, request2) => new Promise((resolve42) => {
29951
30016
  buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
29952
30017
  const response = {
29953
30018
  errors: onEndErrors,
@@ -29957,7 +30022,7 @@ is not a problem with esbuild. You need to fix your environment instead.
29957
30022
  latestResultPromise = void 0;
29958
30023
  provideLatestResult = void 0;
29959
30024
  sendResponse(id, response);
29960
- resolve41();
30025
+ resolve42();
29961
30026
  });
29962
30027
  });
29963
30028
  sendRequest(refs, request, (error, response) => {
@@ -29974,10 +30039,10 @@ is not a problem with esbuild. You need to fix your environment instead.
29974
30039
  let didDispose = false;
29975
30040
  const result = {
29976
30041
  rebuild: () => {
29977
- if (!latestResultPromise) latestResultPromise = new Promise((resolve41, reject) => {
30042
+ if (!latestResultPromise) latestResultPromise = new Promise((resolve42, reject) => {
29978
30043
  let settlePromise;
29979
30044
  provideLatestResult = (err, result2) => {
29980
- if (!settlePromise) settlePromise = () => err ? reject(err) : resolve41(result2);
30045
+ if (!settlePromise) settlePromise = () => err ? reject(err) : resolve42(result2);
29981
30046
  };
29982
30047
  const triggerAnotherBuild = () => {
29983
30048
  const request2 = {
@@ -29998,7 +30063,7 @@ is not a problem with esbuild. You need to fix your environment instead.
29998
30063
  });
29999
30064
  return latestResultPromise;
30000
30065
  },
30001
- watch: (options2 = {}) => new Promise((resolve41, reject) => {
30066
+ watch: (options2 = {}) => new Promise((resolve42, reject) => {
30002
30067
  if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
30003
30068
  const keys = {};
30004
30069
  const delay = getFlag(options2, keys, "delay", mustBeInteger);
@@ -30010,10 +30075,10 @@ is not a problem with esbuild. You need to fix your environment instead.
30010
30075
  if (delay) request2.delay = delay;
30011
30076
  sendRequest(refs, request2, (error2) => {
30012
30077
  if (error2) reject(new Error(error2));
30013
- else resolve41(void 0);
30078
+ else resolve42(void 0);
30014
30079
  });
30015
30080
  }),
30016
- serve: (options2 = {}) => new Promise((resolve41, reject) => {
30081
+ serve: (options2 = {}) => new Promise((resolve42, reject) => {
30017
30082
  if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
30018
30083
  const keys = {};
30019
30084
  const port = getFlag(options2, keys, "port", mustBeValidPortNumber);
@@ -30051,28 +30116,28 @@ is not a problem with esbuild. You need to fix your environment instead.
30051
30116
  sendResponse(id, {});
30052
30117
  };
30053
30118
  }
30054
- resolve41(response2);
30119
+ resolve42(response2);
30055
30120
  });
30056
30121
  }),
30057
- cancel: () => new Promise((resolve41) => {
30058
- if (didDispose) return resolve41();
30122
+ cancel: () => new Promise((resolve42) => {
30123
+ if (didDispose) return resolve42();
30059
30124
  const request2 = {
30060
30125
  command: "cancel",
30061
30126
  key: buildKey
30062
30127
  };
30063
30128
  sendRequest(refs, request2, () => {
30064
- resolve41();
30129
+ resolve42();
30065
30130
  });
30066
30131
  }),
30067
- dispose: () => new Promise((resolve41) => {
30068
- if (didDispose) return resolve41();
30132
+ dispose: () => new Promise((resolve42) => {
30133
+ if (didDispose) return resolve42();
30069
30134
  didDispose = true;
30070
30135
  const request2 = {
30071
30136
  command: "dispose",
30072
30137
  key: buildKey
30073
30138
  };
30074
30139
  sendRequest(refs, request2, () => {
30075
- resolve41();
30140
+ resolve42();
30076
30141
  scheduleOnDisposeCallbacks();
30077
30142
  refs.unref();
30078
30143
  });
@@ -30111,7 +30176,7 @@ is not a problem with esbuild. You need to fix your environment instead.
30111
30176
  onLoad: []
30112
30177
  };
30113
30178
  i++;
30114
- let resolve41 = (path3, options = {}) => {
30179
+ let resolve42 = (path3, options = {}) => {
30115
30180
  if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
30116
30181
  if (typeof path3 !== "string") throw new Error(`The path to resolve must be a string`);
30117
30182
  let keys2 = /* @__PURE__ */ Object.create(null);
@@ -30155,7 +30220,7 @@ is not a problem with esbuild. You need to fix your environment instead.
30155
30220
  };
30156
30221
  let promise = setup({
30157
30222
  initialOptions,
30158
- resolve: resolve41,
30223
+ resolve: resolve42,
30159
30224
  onStart(callback) {
30160
30225
  let registeredText = `This error came from the "onStart" callback registered here:`;
30161
30226
  let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
@@ -30848,46 +30913,46 @@ More information: The file containing the code for esbuild's JavaScript API (${_
30848
30913
  }
30849
30914
  };
30850
30915
  longLivedService = {
30851
- build: (options) => new Promise((resolve41, reject) => {
30916
+ build: (options) => new Promise((resolve42, reject) => {
30852
30917
  service.buildOrContext({
30853
30918
  callName: "build",
30854
30919
  refs,
30855
30920
  options,
30856
30921
  isTTY: isTTY(),
30857
30922
  defaultWD,
30858
- callback: (err, res) => err ? reject(err) : resolve41(res)
30923
+ callback: (err, res) => err ? reject(err) : resolve42(res)
30859
30924
  });
30860
30925
  }),
30861
- context: (options) => new Promise((resolve41, reject) => service.buildOrContext({
30926
+ context: (options) => new Promise((resolve42, reject) => service.buildOrContext({
30862
30927
  callName: "context",
30863
30928
  refs,
30864
30929
  options,
30865
30930
  isTTY: isTTY(),
30866
30931
  defaultWD,
30867
- callback: (err, res) => err ? reject(err) : resolve41(res)
30932
+ callback: (err, res) => err ? reject(err) : resolve42(res)
30868
30933
  })),
30869
- transform: (input, options) => new Promise((resolve41, reject) => service.transform({
30934
+ transform: (input, options) => new Promise((resolve42, reject) => service.transform({
30870
30935
  callName: "transform",
30871
30936
  refs,
30872
30937
  input,
30873
30938
  options: options || {},
30874
30939
  isTTY: isTTY(),
30875
30940
  fs: fsAsync,
30876
- callback: (err, res) => err ? reject(err) : resolve41(res)
30941
+ callback: (err, res) => err ? reject(err) : resolve42(res)
30877
30942
  })),
30878
- formatMessages: (messages, options) => new Promise((resolve41, reject) => service.formatMessages({
30943
+ formatMessages: (messages, options) => new Promise((resolve42, reject) => service.formatMessages({
30879
30944
  callName: "formatMessages",
30880
30945
  refs,
30881
30946
  messages,
30882
30947
  options,
30883
- callback: (err, res) => err ? reject(err) : resolve41(res)
30948
+ callback: (err, res) => err ? reject(err) : resolve42(res)
30884
30949
  })),
30885
- analyzeMetafile: (metafile, options) => new Promise((resolve41, reject) => service.analyzeMetafile({
30950
+ analyzeMetafile: (metafile, options) => new Promise((resolve42, reject) => service.analyzeMetafile({
30886
30951
  callName: "analyzeMetafile",
30887
30952
  refs,
30888
30953
  metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
30889
30954
  options,
30890
- callback: (err, res) => err ? reject(err) : resolve41(res)
30955
+ callback: (err, res) => err ? reject(err) : resolve42(res)
30891
30956
  }))
30892
30957
  };
30893
30958
  return longLivedService;
@@ -30965,13 +31030,13 @@ error: ${text}`);
30965
31030
  worker.postMessage(msg);
30966
31031
  let status = Atomics.wait(sharedBufferView, 0, 0);
30967
31032
  if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
30968
- let { message: { id: id2, resolve: resolve41, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
31033
+ let { message: { id: id2, resolve: resolve42, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
30969
31034
  if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
30970
31035
  if (reject) {
30971
31036
  applyProperties(reject, properties);
30972
31037
  throw reject;
30973
31038
  }
30974
- return resolve41;
31039
+ return resolve42;
30975
31040
  };
30976
31041
  worker.unref();
30977
31042
  return {
@@ -31856,8 +31921,19 @@ function emitStatic(ctx2, node, tracked2, effectsVar, skipK = 0, regionBudget) {
31856
31921
  let childVar;
31857
31922
  const isPureStaticChild = ctx2.hydrate && child instanceof StaticNode && isStaticIR(child.children);
31858
31923
  if (isPureStaticChild) {
31859
- const ssrEl = `${el}.__vsk_ssrEls[${residueBefore}]`;
31860
- childVar = ssrEl;
31924
+ const savedHydrate = ctx2.hydrate;
31925
+ ctx2.hydrate = false;
31926
+ const buildStart = ctx2.lines.length;
31927
+ const freshChild = emitStatic(ctx2, child, tracked2, effectsVar);
31928
+ const buildLines = ctx2.lines.splice(buildStart, ctx2.lines.length - buildStart);
31929
+ ctx2.hydrate = savedHydrate;
31930
+ const childSlot = ctx2.n();
31931
+ ctx2.push(`const ${childSlot} = ${el}.__vsk_ssrEls ? ${el}.__vsk_ssrEls[${residueBefore}] : (() => {`);
31932
+ for (const line of buildLines) ctx2.push(` ${line}`);
31933
+ ctx2.push(` return ${freshChild ?? "document.createElement('div')"};`);
31934
+ ctx2.push(`})();`);
31935
+ childVar = childSlot;
31936
+ const ssrEl = childSlot;
31861
31937
  const dynAttrs2 = [];
31862
31938
  const staticChildren = [];
31863
31939
  for (const c of child.children) {
@@ -32080,12 +32156,12 @@ function emitDynamicBinding(ctx2, node, tracked2, effectsVar, ssrTextExpr = null
32080
32156
  const expr = transformTracked(node.expression, tracked2);
32081
32157
  const v = ctx2.n();
32082
32158
  if (!isReactiveExpression(node.expression, tracked2)) {
32083
- ctx2.push(`const ${v} = document.createTextNode(String(${expr}));`);
32159
+ ctx2.push(`const ${v} = document.createTextNode(String((${expr}) ?? ''));`);
32084
32160
  return v;
32085
32161
  }
32086
32162
  const init = ssrTextExpr ? `String(${ssrTextExpr} ?? '')` : `''`;
32087
32163
  ctx2.push(`const ${v} = document.createTextNode(${init});`);
32088
- const eff = `effect(() => { ${v}.data = String(${expr}); })`;
32164
+ const eff = `effect(() => { const __v = ${expr}; ${v}.data = __v == null ? '' : String(__v); })`;
32089
32165
  if (effectsVar) {
32090
32166
  ctx2.push(`${effectsVar}.push(${eff});`);
32091
32167
  } else {
@@ -33246,7 +33322,9 @@ function isStaticIR(body) {
33246
33322
  function claimsWalkerNode(ctx2, node) {
33247
33323
  if (node instanceof StaticNode) return ctx2.claimStatic || !isStaticIR(node.children);
33248
33324
  if (node instanceof ComponentCall) return true;
33249
- if (node instanceof OpaqueDynamicRegion) return true;
33325
+ if (node instanceof OpaqueDynamicRegion) {
33326
+ return branchClaimsWalker(ctx2, node.consequentNodes) || branchClaimsWalker(ctx2, node.alternateNodes);
33327
+ }
33250
33328
  if (node instanceof MapRegion) return true;
33251
33329
  if (node instanceof ForLoop) return true;
33252
33330
  if (node instanceof WhileLoop) return true;
@@ -33254,6 +33332,13 @@ function claimsWalkerNode(ctx2, node) {
33254
33332
  if (node instanceof TryCatch) return true;
33255
33333
  return false;
33256
33334
  }
33335
+ function branchClaimsWalker(ctx2, nodes) {
33336
+ const previous = ctx2.claimStatic;
33337
+ ctx2.claimStatic = true;
33338
+ const claims = nodes.some((node) => claimsWalkerNode(ctx2, node));
33339
+ ctx2.claimStatic = previous;
33340
+ return claims;
33341
+ }
33257
33342
  function isStaticComponent(comp) {
33258
33343
  if (comp.style) return false;
33259
33344
  return isStaticIR(comp.body);
@@ -35652,7 +35737,7 @@ import {
35652
35737
  rmSync as rmSync2,
35653
35738
  readFileSync as readFileSync17
35654
35739
  } from "node:fs";
35655
- import { resolve as resolve13, join as join11, extname as extname3, dirname as dirname10 } from "node:path";
35740
+ import { resolve as resolve13, join as join11, extname as extname3, dirname as dirname11 } from "node:path";
35656
35741
  function ensureCleanDir(dir) {
35657
35742
  rmSync2(dir, { recursive: true, force: true });
35658
35743
  mkdirSync6(dir, { recursive: true });
@@ -35666,13 +35751,13 @@ function copyDirContents(srcDir, destDir) {
35666
35751
  if (statSync7(srcPath).isDirectory()) {
35667
35752
  copyDirContents(srcPath, destPath);
35668
35753
  } else {
35669
- mkdirSync6(dirname10(destPath), { recursive: true });
35754
+ mkdirSync6(dirname11(destPath), { recursive: true });
35670
35755
  copyFileSync2(srcPath, destPath);
35671
35756
  }
35672
35757
  }
35673
35758
  }
35674
35759
  function writeFile(path, content) {
35675
- mkdirSync6(dirname10(path), { recursive: true });
35760
+ mkdirSync6(dirname11(path), { recursive: true });
35676
35761
  writeFileSync7(path, content, "utf-8");
35677
35762
  }
35678
35763
  function writePlatformStatic(buildStaticDir, platformStaticDir) {
@@ -35686,7 +35771,7 @@ function writePlatformStatic(buildStaticDir, platformStaticDir) {
35686
35771
  const runtimeAlias = resolve13(platformStaticDir, "_vesk", "runtime.js");
35687
35772
  const clientPath = resolve13(buildStaticDir, "client.js");
35688
35773
  if (existsSync15(clientPath)) {
35689
- mkdirSync6(dirname10(runtimeAlias), { recursive: true });
35774
+ mkdirSync6(dirname11(runtimeAlias), { recursive: true });
35690
35775
  copyFileSync2(clientPath, runtimeAlias);
35691
35776
  }
35692
35777
  }
@@ -35781,7 +35866,7 @@ import {
35781
35866
  mkdirSync as mkdirSync7,
35782
35867
  statSync as statSync9
35783
35868
  } from "node:fs";
35784
- import { resolve as resolve15, dirname as dirname12, join as join12, extname as extname4, basename as basename2 } from "node:path";
35869
+ import { resolve as resolve15, dirname as dirname13, join as join12, extname as extname4, basename as basename2 } from "node:path";
35785
35870
  import { createRequire as createRequire4 } from "node:module";
35786
35871
  import { spawn } from "node:child_process";
35787
35872
  function defaultState() {
@@ -35815,7 +35900,7 @@ function readPluginState(veskDir) {
35815
35900
  }
35816
35901
  function writePluginState(veskDir, state) {
35817
35902
  const file = stateFilePath(veskDir);
35818
- const dir = dirname12(file);
35903
+ const dir = dirname13(file);
35819
35904
  if (!existsSync17(dir)) mkdirSync7(dir, { recursive: true });
35820
35905
  writeFileSync8(file, JSON.stringify(state, null, 2) + "\n", "utf-8");
35821
35906
  }
@@ -35829,16 +35914,16 @@ function resolvePackage(appDir, pkg) {
35829
35914
  } catch {
35830
35915
  try {
35831
35916
  entryPath = require3.resolve(pkg);
35832
- let cur = dirname12(entryPath);
35917
+ let cur = dirname13(entryPath);
35833
35918
  const seen = /* @__PURE__ */ new Set();
35834
- while (cur && cur !== dirname12(cur) && !seen.has(cur)) {
35919
+ while (cur && cur !== dirname13(cur) && !seen.has(cur)) {
35835
35920
  seen.add(cur);
35836
35921
  const candidate = join12(cur, "package.json");
35837
35922
  if (existsSync17(candidate)) {
35838
35923
  pkgJsonPath = candidate;
35839
35924
  break;
35840
35925
  }
35841
- const parent = dirname12(cur);
35926
+ const parent = dirname13(cur);
35842
35927
  if (parent !== cur && basename2(cur) === "node_modules") break;
35843
35928
  cur = parent;
35844
35929
  }
@@ -35848,7 +35933,7 @@ function resolvePackage(appDir, pkg) {
35848
35933
  if (pkgJsonPath && existsSync17(pkgJsonPath)) {
35849
35934
  pkgJson = readJsonFile(pkgJsonPath);
35850
35935
  const main = pkgJson?.main || pkgJson?.module || "index.js";
35851
- entryPath = resolve15(dirname12(pkgJsonPath), main);
35936
+ entryPath = resolve15(dirname13(pkgJsonPath), main);
35852
35937
  }
35853
35938
  let localPath = localDir(appDir, pkg);
35854
35939
  if (!localPath) {
@@ -35869,7 +35954,7 @@ function resolvePackage(appDir, pkg) {
35869
35954
  return { installed: true, path: localPath, dir: localPath, packageJson: json ?? pkgJson };
35870
35955
  }
35871
35956
  const installed2 = !!pkgJsonPath && existsSync17(pkgJsonPath);
35872
- return { installed: installed2, path: entryPath, dir: installed2 ? dirname12(pkgJsonPath) : null, packageJson: pkgJson };
35957
+ return { installed: installed2, path: entryPath, dir: installed2 ? dirname13(pkgJsonPath) : null, packageJson: pkgJson };
35873
35958
  }
35874
35959
  function localDir(base, pkg) {
35875
35960
  if (pkg.startsWith("@")) {
@@ -36844,7 +36929,7 @@ __export(image_pipeline_exports, {
36844
36929
  });
36845
36930
  import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync10, readFileSync as readFileSync21, existsSync as existsSync19, readdirSync as readdirSync6, statSync as statSync11 } from "node:fs";
36846
36931
  import { spawnSync } from "node:child_process";
36847
- import { resolve as resolve17, extname as extname5, dirname as dirname13, join as join14 } from "node:path";
36932
+ import { resolve as resolve17, extname as extname5, dirname as dirname14, join as join14 } from "node:path";
36848
36933
  import { createRequire as createRequire5 } from "node:module";
36849
36934
  import { tmpdir as tmpdir2 } from "node:os";
36850
36935
  function probeMemoPath() {
@@ -36910,7 +36995,7 @@ async function processImage(srcPath, outDir, baseName) {
36910
36995
  const written = [];
36911
36996
  for (const w of OUTPUT_WIDTHS) {
36912
36997
  const outputPath = resolve17(outDir, `${baseName}-${w}w${ext}`);
36913
- mkdirSync9(dirname13(outputPath), { recursive: true });
36998
+ mkdirSync9(dirname14(outputPath), { recursive: true });
36914
36999
  writeFileSync10(outputPath, original);
36915
37000
  written.push(outputPath);
36916
37001
  }
@@ -36923,14 +37008,14 @@ async function processImage(srcPath, outDir, baseName) {
36923
37008
  const base = `${baseName}-${w}w`;
36924
37009
  if (w >= originalWidth) {
36925
37010
  const copyPath = resolve17(outDir, `${base}${extname5(srcPath)}`);
36926
- mkdirSync9(dirname13(copyPath), { recursive: true });
37011
+ mkdirSync9(dirname14(copyPath), { recursive: true });
36927
37012
  writeFileSync10(copyPath, readFileSync21(srcPath));
36928
37013
  generated.push(copyPath);
36929
37014
  continue;
36930
37015
  }
36931
37016
  const resized = image.clone().resize({ width: w, withoutEnlargement: true });
36932
37017
  const jpgPath = resolve17(outDir, `${base}${extname5(srcPath)}`);
36933
- mkdirSync9(dirname13(jpgPath), { recursive: true });
37018
+ mkdirSync9(dirname14(jpgPath), { recursive: true });
36934
37019
  await resized.toFile(jpgPath);
36935
37020
  generated.push(jpgPath);
36936
37021
  for (const fmt of FORMATS) {
@@ -37259,7 +37344,7 @@ var init_platform = __esm({
37259
37344
 
37260
37345
  // ../adapter/src/platform-handler.ts
37261
37346
  import { existsSync as existsSync21 } from "node:fs";
37262
- import { resolve as resolve19, dirname as dirname14, join as join15 } from "node:path";
37347
+ import { resolve as resolve19, dirname as dirname15, join as join15 } from "node:path";
37263
37348
  import { fileURLToPath as fileURLToPath4 } from "node:url";
37264
37349
  function routeName2(segments) {
37265
37350
  const parts = segments.filter(Boolean).map((s) => {
@@ -37573,7 +37658,7 @@ var init_platform_handler = __esm({
37573
37658
  "../adapter/src/platform-handler.ts"() {
37574
37659
  "use strict";
37575
37660
  init_default_pages();
37576
- __dirname5 = dirname14(fileURLToPath4(import.meta.url));
37661
+ __dirname5 = dirname15(fileURLToPath4(import.meta.url));
37577
37662
  }
37578
37663
  });
37579
37664
 
@@ -42307,8 +42392,8 @@ __export(typecheck_exports, {
42307
42392
  formatTypecheckWarnings: () => formatTypecheckWarnings,
42308
42393
  typecheckProject: () => typecheckProject
42309
42394
  });
42310
- import { readFileSync as readFileSync41, readdirSync as readdirSync15, statSync as statSync23 } from "node:fs";
42311
- import { join as join28, dirname as dirname27, normalize, relative as relative8, resolve as resolve39, sep as sep7 } from "node:path";
42395
+ import { readFileSync as readFileSync42, readdirSync as readdirSync15, statSync as statSync23 } from "node:fs";
42396
+ import { join as join29, dirname as dirname28, normalize, relative as relative10, resolve as resolve40, sep as sep7 } from "node:path";
42312
42397
  import * as ts8 from "typescript";
42313
42398
  function walkProjectFiles(projectRoot) {
42314
42399
  const code = [];
@@ -42321,7 +42406,7 @@ function walkProjectFiles(projectRoot) {
42321
42406
  return;
42322
42407
  }
42323
42408
  for (const e of entries) {
42324
- const p = join28(dir, e);
42409
+ const p = join29(dir, e);
42325
42410
  let st;
42326
42411
  try {
42327
42412
  st = statSync23(p);
@@ -42349,15 +42434,15 @@ function walkProjectFiles(projectRoot) {
42349
42434
  return { code, js };
42350
42435
  }
42351
42436
  function isUnder(dir, file) {
42352
- const base = resolve39(dir);
42353
- const abs = resolve39(file);
42437
+ const base = resolve40(dir);
42438
+ const abs = resolve40(file);
42354
42439
  return abs === base || abs.startsWith(base + sep7);
42355
42440
  }
42356
42441
  function structureWarning(rel, message) {
42357
42442
  return { file: rel, line: 1, column: 1, code: "vesk-structure", message };
42358
42443
  }
42359
42444
  function checkStructureFile(appDir, file) {
42360
- const rel = relative8(appDir, file);
42445
+ const rel = relative10(appDir, file);
42361
42446
  const parts = rel.split("\\").join("/").split("/");
42362
42447
  const name = parts[parts.length - 1] ?? "";
42363
42448
  const isApi = parts.includes("api");
@@ -42376,8 +42461,8 @@ function checkStructureFile(appDir, file) {
42376
42461
  return null;
42377
42462
  }
42378
42463
  function createTypecheckHost(projectRoot, appDir, vskFiles) {
42379
- const ambientPath = join28(appDir, "__vesk_ambient.d.ts");
42380
- const overridePath = join28(appDir, "__vesk_runtime_override.d.ts");
42464
+ const ambientPath = join29(appDir, "__vesk_ambient.d.ts");
42465
+ const overridePath = join29(appDir, "__vesk_runtime_override.d.ts");
42381
42466
  const cached = /* @__PURE__ */ new Map();
42382
42467
  const scriptKindFor = (file) => file.endsWith(".vsk") ? ts8.ScriptKind.TSX : ts8.ScriptKind.TS;
42383
42468
  const host = {
@@ -42447,7 +42532,7 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
42447
42532
  directoryExists: (dir) => ts8.sys.directoryExists(dir),
42448
42533
  getDirectories: (dir) => {
42449
42534
  try {
42450
- return readdirSync15(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join28(dir, d.name));
42535
+ return readdirSync15(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join29(dir, d.name));
42451
42536
  } catch {
42452
42537
  return [];
42453
42538
  }
@@ -42458,8 +42543,8 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
42458
42543
  resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options) {
42459
42544
  return moduleLiterals.map(({ text }) => {
42460
42545
  if (text.endsWith(".vsk")) {
42461
- const aliased = text.startsWith(".") ? null : resolveAliasModule(text, dirname27(containingFile));
42462
- const abs = normalize(aliased ?? join28(dirname27(containingFile), text));
42546
+ const aliased = text.startsWith(".") ? null : resolveAliasModule(text, dirname28(containingFile));
42547
+ const abs = normalize(aliased ?? join29(dirname28(containingFile), text));
42463
42548
  return {
42464
42549
  resolvedModule: {
42465
42550
  resolvedFileName: abs + ".d.ts",
@@ -42470,7 +42555,7 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
42470
42555
  };
42471
42556
  }
42472
42557
  if (text.endsWith(".css")) {
42473
- const abs = normalize(join28(dirname27(containingFile), text));
42558
+ const abs = normalize(join29(dirname28(containingFile), text));
42474
42559
  return {
42475
42560
  resolvedModule: {
42476
42561
  resolvedFileName: abs + ".d.ts",
@@ -42517,7 +42602,7 @@ function sourcePosition(source, offset2) {
42517
42602
  return { line, character: bounded - lineStart + 1 };
42518
42603
  }
42519
42604
  function typecheckProject(projectRoot, opts = {}) {
42520
- const appDir = opts.appDir ?? join28(projectRoot, "app");
42605
+ const appDir = opts.appDir ?? join29(projectRoot, "app");
42521
42606
  const vskFiles = /* @__PURE__ */ new Map();
42522
42607
  const parseErrors = [];
42523
42608
  const warnings = [];
@@ -42539,12 +42624,12 @@ function typecheckProject(projectRoot, opts = {}) {
42539
42624
  }
42540
42625
  }
42541
42626
  if (f.endsWith(".vsk")) {
42542
- const src2 = readFileSync41(f, "utf-8");
42627
+ const src2 = readFileSync42(f, "utf-8");
42543
42628
  try {
42544
42629
  parse4(src2);
42545
42630
  } catch (e) {
42546
42631
  parseErrors.push({
42547
- file: relative8(projectRoot, f),
42632
+ file: relative10(projectRoot, f),
42548
42633
  line: 1,
42549
42634
  column: 1,
42550
42635
  code: "vesk-parse",
@@ -42556,8 +42641,8 @@ function typecheckProject(projectRoot, opts = {}) {
42556
42641
  }
42557
42642
  rootNames.push(f);
42558
42643
  }
42559
- const ambientPath = join28(appDir, "__vesk_ambient.d.ts");
42560
- const overridePath = join28(appDir, "__vesk_runtime_override.d.ts");
42644
+ const ambientPath = join29(appDir, "__vesk_ambient.d.ts");
42645
+ const overridePath = join29(appDir, "__vesk_runtime_override.d.ts");
42561
42646
  rootNames.push(ambientPath);
42562
42647
  rootNames.push(overridePath);
42563
42648
  const options = {
@@ -42615,7 +42700,7 @@ function typecheckProject(projectRoot, opts = {}) {
42615
42700
  }
42616
42701
  const code = typeof diag.code === "number" ? `TS${diag.code}` : String(diag.code);
42617
42702
  errors.push({
42618
- file: relative8(projectRoot, filePath),
42703
+ file: relative10(projectRoot, filePath),
42619
42704
  line,
42620
42705
  column,
42621
42706
  code,
@@ -48678,8 +48763,8 @@ __export(codemods_exports, {
48678
48763
  applicableCodemods: () => applicableCodemods,
48679
48764
  compareCore: () => compareCore
48680
48765
  });
48681
- import { readFileSync as readFileSync42, existsSync as existsSync43 } from "node:fs";
48682
- import { join as join29 } from "node:path";
48766
+ import { readFileSync as readFileSync43, existsSync as existsSync44 } from "node:fs";
48767
+ import { join as join30 } from "node:path";
48683
48768
  import { walk as walk8 } from "zimmerframe";
48684
48769
  function safeParse(source, filePath) {
48685
48770
  try {
@@ -48699,12 +48784,12 @@ function isVskFile(filePath) {
48699
48784
  }
48700
48785
  function typesPackageExports(projectDir) {
48701
48786
  const candidates = [
48702
- projectDir ? join29(projectDir, "node_modules", "@vesk", "types", "dist", "index.d.ts") : null,
48787
+ projectDir ? join30(projectDir, "node_modules", "@vesk", "types", "dist", "index.d.ts") : null,
48703
48788
  new URL("../../types/dist/index.d.ts", import.meta.url).pathname
48704
- ].filter((p) => typeof p === "string" && existsSync43(p));
48789
+ ].filter((p) => typeof p === "string" && existsSync44(p));
48705
48790
  for (const path of candidates) {
48706
48791
  try {
48707
- const src2 = readFileSync42(path, "utf-8");
48792
+ const src2 = readFileSync43(path, "utf-8");
48708
48793
  const names = /* @__PURE__ */ new Set();
48709
48794
  for (const line of src2.split("\n")) {
48710
48795
  const m = /^export\s+(?:declare\s+)?(?:abstract\s+)?(?:interface|class|type|enum|const|function|let|var|namespace)\s+([A-Za-z_$][\w$]*)/.exec(line);
@@ -48828,14 +48913,14 @@ __export(migrate_exports, {
48828
48913
  detectInstalledVersion: () => detectInstalledVersion,
48829
48914
  runMigrate: () => runMigrate
48830
48915
  });
48831
- import { readFileSync as readFileSync43, writeFileSync as writeFileSync22, existsSync as existsSync44, statSync as statSync24, readdirSync as readdirSync16 } from "node:fs";
48832
- import { join as join30, relative as relative9, extname as extname8 } from "node:path";
48916
+ import { readFileSync as readFileSync44, writeFileSync as writeFileSync22, existsSync as existsSync45, statSync as statSync24, readdirSync as readdirSync16 } from "node:fs";
48917
+ import { join as join31, relative as relative11, extname as extname8 } from "node:path";
48833
48918
  function detectInstalledVersion(projectDir, cliVersion) {
48834
48919
  for (const pkg of ["@vesk/vesk-cli", "@vesk/adapter", "@vesk/compiler"]) {
48835
- const p = join30(projectDir, "node_modules", pkg, "package.json");
48836
- if (!existsSync44(p)) continue;
48920
+ const p = join31(projectDir, "node_modules", pkg, "package.json");
48921
+ if (!existsSync45(p)) continue;
48837
48922
  try {
48838
- const version2 = JSON.parse(readFileSync43(p, "utf-8")).version;
48923
+ const version2 = JSON.parse(readFileSync44(p, "utf-8")).version;
48839
48924
  if (typeof version2 === "string" && version2) return { version: version2, source: pkg };
48840
48925
  } catch {
48841
48926
  }
@@ -48852,7 +48937,7 @@ function collectTargets(dir, root3 = dir) {
48852
48937
  }
48853
48938
  for (const entry of entries.sort()) {
48854
48939
  if (SKIP_DIRS2.has(entry)) continue;
48855
- const full = join30(dir, entry);
48940
+ const full = join31(dir, entry);
48856
48941
  let st;
48857
48942
  try {
48858
48943
  st = statSync24(full);
@@ -48862,7 +48947,7 @@ function collectTargets(dir, root3 = dir) {
48862
48947
  if (st.isDirectory()) {
48863
48948
  out.push(...collectTargets(full, root3));
48864
48949
  } else if (SCAN_EXTENSIONS.has(extname8(entry))) {
48865
- out.push(relative9(root3, full));
48950
+ out.push(relative11(root3, full));
48866
48951
  }
48867
48952
  }
48868
48953
  return out;
@@ -48887,12 +48972,12 @@ function runMigrate(options) {
48887
48972
  return report;
48888
48973
  }
48889
48974
  for (const relPath of collectTargets(options.projectDir)) {
48890
- const abs = join30(options.projectDir, relPath);
48975
+ const abs = join31(options.projectDir, relPath);
48891
48976
  const ctx2 = { filePath: abs, displayPath: relPath, projectDir: options.projectDir };
48892
- if (!existsSync44(abs)) continue;
48977
+ if (!existsSync45(abs)) continue;
48893
48978
  let source;
48894
48979
  try {
48895
- source = readFileSync43(abs, "utf-8");
48980
+ source = readFileSync44(abs, "utf-8");
48896
48981
  } catch (e) {
48897
48982
  report.skipped.push(`${relPath}: unreadable (${e.message})`);
48898
48983
  continue;
@@ -48932,9 +49017,11 @@ var init_migrate = __esm({
48932
49017
  });
48933
49018
 
48934
49019
  // src/index.ts
48935
- import { readFileSync as readFileSync44, writeFileSync as writeFileSync23, mkdirSync as mkdirSync20, existsSync as existsSync45 } from "fs";
48936
- import { resolve as resolve40, join as join31 } from "path";
49020
+ import { readFileSync as readFileSync45, writeFileSync as writeFileSync23, mkdirSync as mkdirSync20, existsSync as existsSync46 } from "fs";
49021
+ import { resolve as resolve41, join as join32 } from "path";
48937
49022
  import { fileURLToPath as fileURLToPath9 } from "url";
49023
+ import { createRequire as createRequire8 } from "module";
49024
+ import { spawn as spawn3 } from "child_process";
48938
49025
 
48939
49026
  // ../adapter/dist/load-config.js
48940
49027
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
@@ -49512,7 +49599,7 @@ function setRuntimeModule2(mod) {
49512
49599
 
49513
49600
  // ../adapter/dist/index.js
49514
49601
  import { mkdirSync as mkdirSync11, writeFileSync as writeFileSync12, existsSync as existsSync22, readFileSync as readFileSync23 } from "node:fs";
49515
- import { resolve as resolve21, dirname as dirname16, relative as relative4, basename as basename3, join as join16 } from "node:path";
49602
+ import { resolve as resolve21, dirname as dirname17, relative as relative4, basename as basename3, join as join16 } from "node:path";
49516
49603
  import { fileURLToPath as fileURLToPath5 } from "node:url";
49517
49604
 
49518
49605
  // ../adapter/src/runtime-bundle.ts
@@ -50385,7 +50472,9 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50385
50472
  ""
50386
50473
  ].join("\n");
50387
50474
  const actionCode = [
50388
- "export async function handleAction(request, id) {",
50475
+ // Underscored internal name (see api-function.ts): page source is inlined
50476
+ // into this module and may declare/import `handleAction` itself.
50477
+ "async function __vesk_handleAction(request, id) {",
50389
50478
  " // CSRF defense: cross-site browser POSTs always carry an Origin header.",
50390
50479
  " try {",
50391
50480
  " assertSameOrigin(request);",
@@ -50462,6 +50551,8 @@ ${layoutDecls.map((d) => " " + d.compiled + ",").join("\n")}
50462
50551
  " globalThis.__vesk_request = prevReq;",
50463
50552
  " }",
50464
50553
  "}",
50554
+ "",
50555
+ "export { __vesk_handleAction as handleAction };",
50465
50556
  ""
50466
50557
  ].join("\n");
50467
50558
  const funcCode = [
@@ -50499,8 +50590,9 @@ init_actions();
50499
50590
 
50500
50591
  // ../adapter/src/api-function.ts
50501
50592
  init_strip_ts();
50593
+ init_module_imports();
50502
50594
  import { readFileSync as readFileSync8 } from "node:fs";
50503
- import { resolve as resolve8 } from "node:path";
50595
+ import { resolve as resolve8, dirname as dirname8 } from "node:path";
50504
50596
  function apiRouteName(fullPath) {
50505
50597
  const parts = fullPath.split("/").filter(Boolean);
50506
50598
  return parts.map((s) => s.startsWith(":") ? s.slice(1) || "param" : s).join("_") || "index";
@@ -50512,6 +50604,17 @@ function generateApiFunction(apiNode, _apiDir, outDir, options) {
50512
50604
  const routeFilePath = apiNode.filePath;
50513
50605
  if (!routeFilePath) throw new Error(`api route ${apiNode.fullPath} has no filePath`);
50514
50606
  let routeSrc = readFileSync8(routeFilePath, "utf-8");
50607
+ const routeDir = dirname8(routeFilePath);
50608
+ routeSrc = routeSrc.replace(
50609
+ /(from\s+['"]|import\s*\(\s*['"])(\.{1,2}\/[^'"]+)(['"])/g,
50610
+ (match, prefix, spec, suffix) => {
50611
+ try {
50612
+ return prefix + resolveImportPath(spec, routeDir) + suffix;
50613
+ } catch {
50614
+ return match;
50615
+ }
50616
+ }
50617
+ );
50515
50618
  routeSrc = routeSrc.replace(/from\s+['"]@vesk\/runtime['"]\s*;?/g, "from '../runtime.js';").replace(/from\s+['"]@vesk\/runtime\/(\w+)['"]\s*;?/g, () => {
50516
50619
  return "from '../runtime.js';";
50517
50620
  });
@@ -50524,9 +50627,12 @@ function generateApiFunction(apiNode, _apiDir, outDir, options) {
50524
50627
  const urlParts = apiNode.fullPath.split("/").filter(Boolean);
50525
50628
  const extracts = [];
50526
50629
  let partIdx = 0;
50527
- for (const p of urlParts) {
50528
- if (p.startsWith(":") && p.includes("...")) {
50630
+ for (let i = 0; i < urlParts.length; i++) {
50631
+ const p = urlParts[i];
50632
+ const isCatchAll = apiNode.isCatchAll && i === urlParts.length - 1;
50633
+ if (p.startsWith(":") && (isCatchAll || p.includes("..."))) {
50529
50634
  extracts.push(`${JSON.stringify(p.slice(1))}: urlParts.slice(${partIdx}).join('/')`);
50635
+ partIdx = urlParts.length;
50530
50636
  } else if (p.startsWith(":")) {
50531
50637
  extracts.push(`${JSON.stringify(p.slice(1))}: urlParts[${partIdx}]`);
50532
50638
  partIdx++;
@@ -50709,9 +50815,14 @@ function generateApiFunction(apiNode, _apiDir, outDir, options) {
50709
50815
  middlewareCode ? "import { parseCookies as __parseCookies } from '../runtime.js';" : "",
50710
50816
  "",
50711
50817
  middlewareCode || "",
50712
- "export async function handle(request) {",
50818
+ // Underscored internal name: route source is inlined above and commonly
50819
+ // imports a user helper called `handle`, which would otherwise clash with
50820
+ // (and crash) this wrapper. The public export name is preserved.
50821
+ "async function __vesk_api_handle(request) {",
50713
50822
  handleBody,
50714
50823
  "}",
50824
+ "",
50825
+ "export { __vesk_api_handle as handle };",
50715
50826
  ""
50716
50827
  ].filter(Boolean).join("\n");
50717
50828
  return { funcPath, funcCode, name };
@@ -51071,7 +51182,7 @@ async function compileEvents(appDir, outDir) {
51071
51182
  // ../adapter/src/client-bundle.ts
51072
51183
  init_esbuild_fallback();
51073
51184
  import { readFileSync as readFileSync13, existsSync as existsSync11, writeFileSync as writeFileSync4, unlinkSync as unlinkSync3, statSync as statSync4, rmSync, mkdtempSync, mkdirSync as mkdirSync3 } from "node:fs";
51074
- import { resolve as resolve10, join as join8, dirname as dirname8, relative as relative2, sep } from "node:path";
51185
+ import { resolve as resolve10, join as join8, dirname as dirname9, relative as relative2, sep } from "node:path";
51075
51186
  import { fileURLToPath as fileURLToPath2 } from "node:url";
51076
51187
  import { tmpdir } from "node:os";
51077
51188
  init_strip_ts();
@@ -51366,7 +51477,7 @@ async function mapWithConcurrency(items, limit, fn) {
51366
51477
  if (firstError !== null) throw firstError;
51367
51478
  return out;
51368
51479
  }
51369
- var __dirname3 = dirname8(fileURLToPath2(import.meta.url));
51480
+ var __dirname3 = dirname9(fileURLToPath2(import.meta.url));
51370
51481
  function fileUnchanged(filePath, cached) {
51371
51482
  try {
51372
51483
  const st = statSync4(filePath);
@@ -51535,7 +51646,9 @@ function demoteExports(code) {
51535
51646
  function chunkHasImports(headLen, mergeAborted) {
51536
51647
  return headLen > 0 || mergeAborted;
51537
51648
  }
51538
- function runtimeImportsOf(filePath) {
51649
+ function runtimeImportsOf(filePath, seen = /* @__PURE__ */ new Set()) {
51650
+ if (seen.has(filePath)) return [];
51651
+ seen.add(filePath);
51539
51652
  let text;
51540
51653
  try {
51541
51654
  text = readFileSync13(filePath, "utf8");
@@ -51553,6 +51666,29 @@ function runtimeImportsOf(filePath) {
51553
51666
  if (name) names.push(name);
51554
51667
  }
51555
51668
  }
51669
+ const relativeImport = /import\s+(?:type\s+)?(?:[^'"]*?\sfrom\s*)?['"](\.[^'"]+)['"]/g;
51670
+ for (const match of text.matchAll(relativeImport)) {
51671
+ const base = resolve10(dirname9(filePath), match[1]);
51672
+ const candidates = [
51673
+ base,
51674
+ `${base}.ts`,
51675
+ `${base}.tsx`,
51676
+ `${base}.js`,
51677
+ `${base}.jsx`,
51678
+ join8(base, "index.ts"),
51679
+ join8(base, "index.tsx"),
51680
+ join8(base, "index.js")
51681
+ ];
51682
+ for (const candidate of candidates) {
51683
+ try {
51684
+ if (!existsSync11(candidate) || !statSync4(candidate).isFile()) continue;
51685
+ } catch {
51686
+ continue;
51687
+ }
51688
+ names.push(...runtimeImportsOf(candidate, seen));
51689
+ break;
51690
+ }
51691
+ }
51556
51692
  return names;
51557
51693
  }
51558
51694
  function sharedRuntimeResolver(shimPath) {
@@ -51590,7 +51726,7 @@ var ChunkImports = class {
51590
51726
  if (node.type !== "ImportDeclaration" || typeof node.start !== "number" || typeof node.end !== "number") continue;
51591
51727
  const src2 = node.source?.value;
51592
51728
  if (typeof src2 !== "string") continue;
51593
- const resolved = resolveImportPath(src2, dirname8(filePath));
51729
+ const resolved = resolveImportPath(src2, dirname9(filePath));
51594
51730
  for (const spec of node.specifiers ?? []) {
51595
51731
  const s = spec;
51596
51732
  const local = s.local?.name;
@@ -51895,7 +52031,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
51895
52031
  __stats.distinct.add(filePath);
51896
52032
  let src2 = readFileSync13(filePath, "utf-8");
51897
52033
  if (/content=["'][^"']*\.md["']/i.test(src2)) {
51898
- src2 = inlineMdContentAttrs(src2, dirname8(filePath), guessProjectRoots(appDir));
52034
+ src2 = inlineMdContentAttrs(src2, dirname9(filePath), guessProjectRoots(appDir));
51899
52035
  }
51900
52036
  const namesBefore = cache2 ? new Set(runtimeImportNames) : null;
51901
52037
  const importedPaths = resolveVskImports(filePath, (p, n) => compileFile2(p, n, output, imports));
@@ -51994,6 +52130,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
51994
52130
  }
51995
52131
  if (chunkCode.length > 0) {
51996
52132
  const chunkName = `page-${buildChunkName(appDir, node)}.js`;
52133
+ allRouteImportTables.push(chunkImports);
51997
52134
  if (!onlyRoutes || onlyRoutes.has(node.fullPath)) {
51998
52135
  if (!chunkImports.ok) console.error("[vesk] chunk import merge aborted for", chunkName + ":", chunkImports.reason);
51999
52136
  const head = chunkImports.render();
@@ -52010,7 +52147,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
52010
52147
  if (emitted) {
52011
52148
  const fileName = options?.hmr ? chunkName : hashedName(chunkName, emitted.code);
52012
52149
  node.chunk = `/_vesk/static/${fileName}`;
52013
- } else if (options?.skipRouteChunks) {
52150
+ } else if (options?.skipRouteChunks && (node.page || node.layout)) {
52014
52151
  node.chunk = `/_vesk/static/${chunkName}`;
52015
52152
  }
52016
52153
  annotate2(node.children || []);
@@ -52018,6 +52155,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options) {
52018
52155
  };
52019
52156
  var walkSplit = walkSplit2, annotate = annotate2;
52020
52157
  const chunkEntries = [];
52158
+ const allRouteImportTables = [];
52021
52159
  walkSplit2(routeTree, []);
52022
52160
  const sharedCode = [];
52023
52161
  const sharedImports = new ChunkImports();
@@ -52039,16 +52177,37 @@ ${body}
52039
52177
  })();
52040
52178
  `;
52041
52179
  const sharedUsage = /* @__PURE__ */ new Map();
52042
- for (const entry of chunkEntries) {
52043
- for (const source of new Set(entry.importsTable.sources())) {
52180
+ const sharedUsageTables = [...allRouteImportTables];
52181
+ if (sharedCode.length > 0) sharedUsageTables.push(sharedImports);
52182
+ for (const table of sharedUsageTables) {
52183
+ for (const source of new Set(table.sources())) {
52044
52184
  sharedUsage.set(source, (sharedUsage.get(source) ?? 0) + 1);
52045
52185
  }
52046
52186
  }
52047
52187
  const isAppLocal = (source) => !source.includes("node_modules") && source.startsWith(resolve10(appDir, ".."));
52048
- const sharedSources = [...sharedUsage.entries()].filter(([source, uses]) => uses > 1 && isAppLocal(source)).map(([source]) => source);
52188
+ const sharedFilesFor = /* @__PURE__ */ new Map();
52189
+ for (const [source, uses] of sharedUsage) {
52190
+ let file = source;
52191
+ if (!source.startsWith("/")) {
52192
+ try {
52193
+ file = resolveSsrModule(source, appDir) ?? source;
52194
+ } catch {
52195
+ }
52196
+ }
52197
+ if (file.endsWith(".vsk") || !existsSync11(file)) continue;
52198
+ let needsRuntime = false;
52199
+ try {
52200
+ needsRuntime = runtimeImportsOf(file).length > 0;
52201
+ } catch {
52202
+ }
52203
+ if (needsRuntime || uses > 1 && isAppLocal(source)) {
52204
+ sharedFilesFor.set(source, file);
52205
+ }
52206
+ }
52207
+ const sharedSources = [...new Set(sharedFilesFor.values())];
52049
52208
  if (process.env.VESK_DEBUG_SHARED) {
52050
52209
  console.error("[shared] candidates:", [...sharedUsage.entries()].map(([s, n]) => `${n}x ${s}`).join("\n"));
52051
- console.error("[shared] selected:", sharedSources.join(", "));
52210
+ console.error("[shared] selected:", [...sharedFilesFor.entries()].map(([s, f]) => `${s} -> ${f}`).join("\n"));
52052
52211
  }
52053
52212
  const chunkAlias = {};
52054
52213
  let sharedBundleCode = "";
@@ -52098,7 +52257,7 @@ ${body}
52098
52257
  ...appTsconfig ? { tsconfig: appTsconfig } : {}
52099
52258
  });
52100
52259
  sharedBundleCode = result.outputFiles[0].text;
52101
- sharedSources.forEach((source, i) => {
52260
+ [...sharedFilesFor.entries()].forEach(([source, file], i) => {
52102
52261
  const named = /* @__PURE__ */ new Set();
52103
52262
  let hasDefault = false;
52104
52263
  for (const entry of chunkEntries) {
@@ -52107,7 +52266,7 @@ ${body}
52107
52266
  hasDefault = hasDefault || bindings.hasDefault;
52108
52267
  }
52109
52268
  const shim = join8(tmpBase, `shim-${i}.js`);
52110
- const shimLines = [`const m = globalThis.__veskShared[${JSON.stringify(source)}];`];
52269
+ const shimLines = [`const m = globalThis.__veskShared[${JSON.stringify(file)}];`];
52111
52270
  if (hasDefault) shimLines.push(`export default m;`);
52112
52271
  for (const name of [...named].sort()) {
52113
52272
  shimLines.push(`export const ${name} = m[${JSON.stringify(name)}];`);
@@ -52218,7 +52377,8 @@ A module-scope statement runs the moment the browser evaluates the chunk, so a s
52218
52377
  return { name: entry.name, code: finalCode };
52219
52378
  };
52220
52379
  const effectiveChunkEntries = options?.skipRouteChunks ? chunkEntries.filter((e) => e.name === SHARED_CHUNK_NAME) : chunkEntries;
52221
- const CHUNK_CONCURRENCY = Math.max(1, Math.min(6, (availableParallelism?.() ?? 4) - 1));
52380
+ const envConcurrency = process.env.VESK_CHUNK_CONCURRENCY ? Number(process.env.VESK_CHUNK_CONCURRENCY) : NaN;
52381
+ const CHUNK_CONCURRENCY = Number.isFinite(envConcurrency) && envConcurrency >= 1 ? Math.floor(envConcurrency) : Math.max(1, Math.min(6, (availableParallelism?.() ?? 4) - 1));
52222
52382
  const built = await mapWithConcurrency(effectiveChunkEntries, CHUNK_CONCURRENCY, buildChunkEntry);
52223
52383
  for (const c of built) {
52224
52384
  if (c !== null) chunks.push(c);
@@ -52394,7 +52554,7 @@ async function bundleRuntimeNames(runtimeDir, names, strict = false) {
52394
52554
  const unique = [...new Set(names)];
52395
52555
  try {
52396
52556
  try {
52397
- mkdirSync3(dirname8(entry), { recursive: true });
52557
+ mkdirSync3(dirname9(entry), { recursive: true });
52398
52558
  } catch {
52399
52559
  }
52400
52560
  try {
@@ -52630,7 +52790,7 @@ function copyStaticAssets(publicDir, outDir) {
52630
52790
 
52631
52791
  // ../adapter/src/prod-server.ts
52632
52792
  import { readFileSync as readFileSync18, existsSync as existsSync16, statSync as statSync8 } from "node:fs";
52633
- import { resolve as resolve14, dirname as dirname11, basename } from "node:path";
52793
+ import { resolve as resolve14, dirname as dirname12, basename } from "node:path";
52634
52794
  import { createServer } from "node:http";
52635
52795
  import { fileURLToPath as fileURLToPath3 } from "node:url";
52636
52796
  init_server_utils();
@@ -52670,7 +52830,7 @@ init_paths();
52670
52830
 
52671
52831
  // ../adapter/src/load-config.ts
52672
52832
  import { existsSync as existsSync14, readFileSync as readFileSync16, writeFileSync as writeFileSync6, mkdirSync as mkdirSync5 } from "node:fs";
52673
- import { join as join10, dirname as dirname9 } from "node:path";
52833
+ import { join as join10, dirname as dirname10 } from "node:path";
52674
52834
  import { pathToFileURL as pathToFileURL2 } from "node:url";
52675
52835
  import { createRequire as createRequire3 } from "node:module";
52676
52836
  async function loadVeskConfig2(projectDir) {
@@ -52714,7 +52874,7 @@ async function loadVeskConfig2(projectDir) {
52714
52874
  js = `const {${injectKeys.join(",")}} = globalThis.__vesk_inject;
52715
52875
  ` + js;
52716
52876
  const tmpFile = join10(projectDir, ".vesk", "config.loader.tmp.mjs");
52717
- mkdirSync5(dirname9(tmpFile), { recursive: true });
52877
+ mkdirSync5(dirname10(tmpFile), { recursive: true });
52718
52878
  writeFileSync6(tmpFile, js, "utf-8");
52719
52879
  globalThis.__vesk_inject = inject;
52720
52880
  try {
@@ -53027,7 +53187,7 @@ function makeWebRequest(nodeReq, url, maxBodyBytes = DEFAULT_MAX_BODY_BYTES) {
53027
53187
  const settleEnd = (body) => {
53028
53188
  if (body !== null) cachedBody = body;
53029
53189
  streamEnded = true;
53030
- for (const resolve41 of endWaiters.splice(0)) resolve41();
53190
+ for (const resolve42 of endWaiters.splice(0)) resolve42();
53031
53191
  };
53032
53192
  function createBodyStream() {
53033
53193
  streamTaken = true;
@@ -53148,11 +53308,17 @@ function makeWebRequest(nodeReq, url, maxBodyBytes = DEFAULT_MAX_BODY_BYTES) {
53148
53308
 
53149
53309
  // ../adapter/src/prod-server.ts
53150
53310
  init_platform_output();
53151
- var __dirname4 = dirname11(fileURLToPath3(import.meta.url));
53311
+ var __dirname4 = dirname12(fileURLToPath3(import.meta.url));
53152
53312
  var STREAMING_TYPES = /* @__PURE__ */ new Set(["text/event-stream", "application/x-ndjson"]);
53153
53313
  var DELIVER_BUFFER_LIMIT = 1024 * 1024;
53154
- async function deliverResponse(res, response) {
53314
+ function toNodeHeaders(response) {
53155
53315
  const headers2 = Object.fromEntries(response.headers);
53316
+ const cookies2 = response.headers.getSetCookie?.() ?? [];
53317
+ if (cookies2.length > 0) headers2["set-cookie"] = cookies2;
53318
+ return headers2;
53319
+ }
53320
+ async function deliverResponse(res, response) {
53321
+ const headers2 = toNodeHeaders(response);
53156
53322
  const body = response.body;
53157
53323
  if (!body || typeof body.getReader !== "function") {
53158
53324
  res.writeHead(response.status, headers2);
@@ -53207,6 +53373,22 @@ function errorStatus(e, fallback) {
53207
53373
  const s = e?.status ?? e?.statusCode;
53208
53374
  return typeof s === "number" && s >= 400 && s < 600 ? s : fallback;
53209
53375
  }
53376
+ function firstHeaderValue(value) {
53377
+ const raw2 = Array.isArray(value) ? value[0] : value;
53378
+ const trimmed = raw2?.split(",")[0]?.trim();
53379
+ return trimmed || void 0;
53380
+ }
53381
+ function resolveRequestUrl(req, port, trustProxy) {
53382
+ const proto = req.socket.encrypted ? "https" : getClientProtocol({ headers: req.headers }, trustProxy);
53383
+ const forwardedHost = trustProxy ? firstHeaderValue(req.headers["x-forwarded-host"]) : void 0;
53384
+ const host = forwardedHost || req.headers.host || `localhost:${port}`;
53385
+ const path = req.url || "/";
53386
+ try {
53387
+ return new URL(path, `${proto}://${host}`);
53388
+ } catch {
53389
+ return new URL(path, `http://localhost:${port}`);
53390
+ }
53391
+ }
53210
53392
  async function startProdServer(outDir, options) {
53211
53393
  const port = options?.port || 3e3;
53212
53394
  const host = options?.host || "127.0.0.1";
@@ -53333,10 +53515,8 @@ async function startProdServer(outDir, options) {
53333
53515
  return req.headers["x-real-ip"] || req.socket?.remoteAddress || "unknown";
53334
53516
  }
53335
53517
  const server = createServer(async (req, res) => {
53336
- const url = new URL(req.url || "/", `http://localhost:${port}`);
53337
- const reqHost = req.headers.host || `localhost:${port}`;
53338
- const proto = req.socket.encrypted ? "https" : getClientProtocol({ headers: req.headers }, !!securityConfig?.trustProxy);
53339
- globalThis.__vesk_ssr_base_url = `${proto}://${reqHost}`;
53518
+ const url = resolveRequestUrl(req, port, !!securityConfig?.trustProxy);
53519
+ globalThis.__vesk_ssr_base_url = url.origin;
53340
53520
  if (healthCheckEnabled && (url.pathname === "/healthz" || url.pathname === "/_vesk/healthz")) {
53341
53521
  const probe = JSON.stringify({ status: "ok", uptime: Math.floor(process.uptime()) });
53342
53522
  res.writeHead(200, {
@@ -53739,9 +53919,9 @@ init_paths();
53739
53919
 
53740
53920
  // ../adapter/dist/index.js
53741
53921
  function PACKAGES_DIR_SELF() {
53742
- return resolve21(dirname16(fileURLToPath5(import.meta.url)), "..");
53922
+ return resolve21(dirname17(fileURLToPath5(import.meta.url)), "..");
53743
53923
  }
53744
- var __dirname6 = dirname16(fileURLToPath5(import.meta.url));
53924
+ var __dirname6 = dirname17(fileURLToPath5(import.meta.url));
53745
53925
  async function resolveCompilerApi(name) {
53746
53926
  const monorepoSrc = resolve21(__dirname6, "..", "..", "compiler", "src");
53747
53927
  if (existsSync22(monorepoSrc)) {
@@ -53792,7 +53972,7 @@ function filterPluginsForBuild(plugins, state) {
53792
53972
  function veskDirFromOutDir(outDir) {
53793
53973
  const base = basename3(outDir);
53794
53974
  if (base === "dev" || base === "build")
53795
- return dirname16(outDir);
53975
+ return dirname17(outDir);
53796
53976
  return outDir;
53797
53977
  }
53798
53978
  async function collectPluginHeadExtra(pluginsPipelines) {
@@ -54139,9 +54319,9 @@ vesk build: done (${outDir})`);
54139
54319
  init_seo_audit();
54140
54320
 
54141
54321
  // src/dev-server.ts
54142
- import { readFileSync as readFileSync40, watch, statSync as statSync22, existsSync as existsSync42, mkdirSync as mkdirSync19, readdirSync as readdirSync14, writeFileSync as writeFileSync21, renameSync as renameSync2 } from "node:fs";
54322
+ import { readFileSync as readFileSync41, watch, statSync as statSync22, existsSync as existsSync43, mkdirSync as mkdirSync19, readdirSync as readdirSync14, writeFileSync as writeFileSync21, renameSync as renameSync2 } from "node:fs";
54143
54323
  import { createHash as createHash3 } from "node:crypto";
54144
- import { resolve as resolve38, extname as extname7, join as join27, dirname as dirname26 } from "node:path";
54324
+ import { resolve as resolve39, extname as extname7, join as join28, dirname as dirname27, relative as relative9 } from "node:path";
54145
54325
  import { createServer as createServer2 } from "node:http";
54146
54326
  import { WebSocketServer as WebSocketServer2 } from "ws";
54147
54327
 
@@ -55183,8 +55363,20 @@ function emitStatic2(ctx2, node, tracked2, effectsVar, skipK = 0, regionBudget)
55183
55363
  let childVar;
55184
55364
  const isPureStaticChild = ctx2.hydrate && child instanceof StaticNode && isStaticIR2(child.children);
55185
55365
  if (isPureStaticChild) {
55186
- const ssrEl = `${el}.__vsk_ssrEls[${residueBefore}]`;
55187
- childVar = ssrEl;
55366
+ const savedHydrate = ctx2.hydrate;
55367
+ ctx2.hydrate = false;
55368
+ const buildStart = ctx2.lines.length;
55369
+ const freshChild = emitStatic2(ctx2, child, tracked2, effectsVar);
55370
+ const buildLines = ctx2.lines.splice(buildStart, ctx2.lines.length - buildStart);
55371
+ ctx2.hydrate = savedHydrate;
55372
+ const childSlot = ctx2.n();
55373
+ ctx2.push(`const ${childSlot} = ${el}.__vsk_ssrEls ? ${el}.__vsk_ssrEls[${residueBefore}] : (() => {`);
55374
+ for (const line of buildLines)
55375
+ ctx2.push(` ${line}`);
55376
+ ctx2.push(` return ${freshChild ?? "document.createElement('div')"};`);
55377
+ ctx2.push(`})();`);
55378
+ childVar = childSlot;
55379
+ const ssrEl = childSlot;
55188
55380
  const dynAttrs2 = [];
55189
55381
  const staticChildren = [];
55190
55382
  for (const c of child.children) {
@@ -55428,12 +55620,12 @@ function emitDynamicBinding2(ctx2, node, tracked2, effectsVar, ssrTextExpr = nul
55428
55620
  const expr = transformTracked2(node.expression, tracked2);
55429
55621
  const v = ctx2.n();
55430
55622
  if (!isReactiveExpression2(node.expression, tracked2)) {
55431
- ctx2.push(`const ${v} = document.createTextNode(String(${expr}));`);
55623
+ ctx2.push(`const ${v} = document.createTextNode(String((${expr}) ?? ''));`);
55432
55624
  return v;
55433
55625
  }
55434
55626
  const init = ssrTextExpr ? `String(${ssrTextExpr} ?? '')` : `''`;
55435
55627
  ctx2.push(`const ${v} = document.createTextNode(${init});`);
55436
- const eff = `effect(() => { ${v}.data = String(${expr}); })`;
55628
+ const eff = `effect(() => { const __v = ${expr}; ${v}.data = __v == null ? '' : String(__v); })`;
55437
55629
  if (effectsVar) {
55438
55630
  ctx2.push(`${effectsVar}.push(${eff});`);
55439
55631
  } else {
@@ -56738,8 +56930,9 @@ function claimsWalkerNode2(ctx2, node) {
56738
56930
  return ctx2.claimStatic || !isStaticIR2(node.children);
56739
56931
  if (node instanceof ComponentCall)
56740
56932
  return true;
56741
- if (node instanceof OpaqueDynamicRegion)
56742
- return true;
56933
+ if (node instanceof OpaqueDynamicRegion) {
56934
+ return branchClaimsWalker2(ctx2, node.consequentNodes) || branchClaimsWalker2(ctx2, node.alternateNodes);
56935
+ }
56743
56936
  if (node instanceof MapRegion)
56744
56937
  return true;
56745
56938
  if (node instanceof ForLoop)
@@ -56752,6 +56945,13 @@ function claimsWalkerNode2(ctx2, node) {
56752
56945
  return true;
56753
56946
  return false;
56754
56947
  }
56948
+ function branchClaimsWalker2(ctx2, nodes) {
56949
+ const previous = ctx2.claimStatic;
56950
+ ctx2.claimStatic = true;
56951
+ const claims = nodes.some((node) => claimsWalkerNode2(ctx2, node));
56952
+ ctx2.claimStatic = previous;
56953
+ return claims;
56954
+ }
56755
56955
  function isStaticComponent2(comp) {
56756
56956
  if (comp.style)
56757
56957
  return false;
@@ -58105,7 +58305,7 @@ async function runEventHandlers(handlers, name, ctx2) {
58105
58305
 
58106
58306
  // ../compiler/dist/md-inline.js
58107
58307
  import { readFileSync as readFileSync25, existsSync as existsSync27 } from "node:fs";
58108
- import { dirname as dirname17, join as join20, resolve as resolve23 } from "node:path";
58308
+ import { dirname as dirname18, join as join20, resolve as resolve23 } from "node:path";
58109
58309
  var MD_EXT_MARKER2 = ".md";
58110
58310
  function looksLikeMarkdownPath2(value) {
58111
58311
  const v = value.trim();
@@ -58201,7 +58401,7 @@ function guessProjectRoots2(dir) {
58201
58401
  roots.push(cur);
58202
58402
  if (existsSync27(join20(cur, "package.json")))
58203
58403
  break;
58204
- const parent = dirname17(cur);
58404
+ const parent = dirname18(cur);
58205
58405
  if (parent === cur)
58206
58406
  break;
58207
58407
  cur = parent;
@@ -58211,7 +58411,7 @@ function guessProjectRoots2(dir) {
58211
58411
 
58212
58412
  // ../adapter/dist/client-bundle.js
58213
58413
  import { readFileSync as readFileSync26, existsSync as existsSync28, writeFileSync as writeFileSync13, unlinkSync as unlinkSync4, statSync as statSync15, rmSync as rmSync4, mkdtempSync as mkdtempSync2, mkdirSync as mkdirSync12 } from "node:fs";
58214
- import { resolve as resolve24, join as join21, dirname as dirname18, relative as relative6, sep as sep3 } from "node:path";
58414
+ import { resolve as resolve24, join as join21, dirname as dirname19, relative as relative6, sep as sep3 } from "node:path";
58215
58415
  import { fileURLToPath as fileURLToPath6 } from "node:url";
58216
58416
  import { tmpdir as tmpdir3 } from "node:os";
58217
58417
 
@@ -58299,7 +58499,7 @@ async function mapWithConcurrency2(items, limit, fn) {
58299
58499
  throw firstError;
58300
58500
  return out;
58301
58501
  }
58302
- var __dirname7 = dirname18(fileURLToPath6(import.meta.url));
58502
+ var __dirname7 = dirname19(fileURLToPath6(import.meta.url));
58303
58503
  function fileUnchanged2(filePath, cached) {
58304
58504
  try {
58305
58505
  const st = statSync15(filePath);
@@ -58481,7 +58681,10 @@ function demoteExports2(code) {
58481
58681
  function chunkHasImports2(headLen, mergeAborted) {
58482
58682
  return headLen > 0 || mergeAborted;
58483
58683
  }
58484
- function runtimeImportsOf2(filePath) {
58684
+ function runtimeImportsOf2(filePath, seen = /* @__PURE__ */ new Set()) {
58685
+ if (seen.has(filePath))
58686
+ return [];
58687
+ seen.add(filePath);
58485
58688
  let text;
58486
58689
  try {
58487
58690
  text = readFileSync26(filePath, "utf8");
@@ -58502,6 +58705,30 @@ function runtimeImportsOf2(filePath) {
58502
58705
  names.push(name);
58503
58706
  }
58504
58707
  }
58708
+ const relativeImport = /import\s+(?:type\s+)?(?:[^'"]*?\sfrom\s*)?['"](\.[^'"]+)['"]/g;
58709
+ for (const match of text.matchAll(relativeImport)) {
58710
+ const base = resolve24(dirname19(filePath), match[1]);
58711
+ const candidates = [
58712
+ base,
58713
+ `${base}.ts`,
58714
+ `${base}.tsx`,
58715
+ `${base}.js`,
58716
+ `${base}.jsx`,
58717
+ join21(base, "index.ts"),
58718
+ join21(base, "index.tsx"),
58719
+ join21(base, "index.js")
58720
+ ];
58721
+ for (const candidate of candidates) {
58722
+ try {
58723
+ if (!existsSync28(candidate) || !statSync15(candidate).isFile())
58724
+ continue;
58725
+ } catch {
58726
+ continue;
58727
+ }
58728
+ names.push(...runtimeImportsOf2(candidate, seen));
58729
+ break;
58730
+ }
58731
+ }
58505
58732
  return names;
58506
58733
  }
58507
58734
  function sharedRuntimeResolver2(shimPath) {
@@ -58542,7 +58769,7 @@ var ChunkImports2 = class {
58542
58769
  const src2 = node.source?.value;
58543
58770
  if (typeof src2 !== "string")
58544
58771
  continue;
58545
- const resolved = resolveImportPath(src2, dirname18(filePath));
58772
+ const resolved = resolveImportPath(src2, dirname19(filePath));
58546
58773
  for (const spec of node.specifiers ?? []) {
58547
58774
  const s = spec;
58548
58775
  const local = s.local?.name;
@@ -58879,7 +59106,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
58879
59106
  __stats.distinct.add(filePath);
58880
59107
  let src2 = readFileSync26(filePath, "utf-8");
58881
59108
  if (/content=["'][^"']*\.md["']/i.test(src2)) {
58882
- src2 = inlineMdContentAttrs(src2, dirname18(filePath), guessProjectRoots(appDir));
59109
+ src2 = inlineMdContentAttrs(src2, dirname19(filePath), guessProjectRoots(appDir));
58883
59110
  }
58884
59111
  const namesBefore = cache2 ? new Set(runtimeImportNames) : null;
58885
59112
  const importedPaths = resolveVskImports(filePath, (p, n) => compileFile2(p, n, output, imports));
@@ -58985,6 +59212,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
58985
59212
  }
58986
59213
  if (chunkCode.length > 0) {
58987
59214
  const chunkName = `page-${buildChunkName2(appDir, node)}.js`;
59215
+ allRouteImportTables.push(chunkImports);
58988
59216
  if (!onlyRoutes || onlyRoutes.has(node.fullPath)) {
58989
59217
  if (!chunkImports.ok)
58990
59218
  console.error("[vesk] chunk import merge aborted for", chunkName + ":", chunkImports.reason);
@@ -59002,7 +59230,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
59002
59230
  if (emitted) {
59003
59231
  const fileName = options?.hmr ? chunkName : hashedName(chunkName, emitted.code);
59004
59232
  node.chunk = `/_vesk/static/${fileName}`;
59005
- } else if (options?.skipRouteChunks) {
59233
+ } else if (options?.skipRouteChunks && (node.page || node.layout)) {
59006
59234
  node.chunk = `/_vesk/static/${chunkName}`;
59007
59235
  }
59008
59236
  annotate2(node.children || []);
@@ -59010,6 +59238,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options) {
59010
59238
  };
59011
59239
  var walkSplit = walkSplit2, annotate = annotate2;
59012
59240
  const chunkEntries = [];
59241
+ const allRouteImportTables = [];
59013
59242
  walkSplit2(routeTree, []);
59014
59243
  const sharedCode = [];
59015
59244
  const sharedImports = new ChunkImports2();
@@ -59032,16 +59261,39 @@ ${body}
59032
59261
  })();
59033
59262
  `;
59034
59263
  const sharedUsage = /* @__PURE__ */ new Map();
59035
- for (const entry of chunkEntries) {
59036
- for (const source of new Set(entry.importsTable.sources())) {
59264
+ const sharedUsageTables = [...allRouteImportTables];
59265
+ if (sharedCode.length > 0)
59266
+ sharedUsageTables.push(sharedImports);
59267
+ for (const table of sharedUsageTables) {
59268
+ for (const source of new Set(table.sources())) {
59037
59269
  sharedUsage.set(source, (sharedUsage.get(source) ?? 0) + 1);
59038
59270
  }
59039
59271
  }
59040
59272
  const isAppLocal = (source) => !source.includes("node_modules") && source.startsWith(resolve24(appDir, ".."));
59041
- const sharedSources = [...sharedUsage.entries()].filter(([source, uses]) => uses > 1 && isAppLocal(source)).map(([source]) => source);
59273
+ const sharedFilesFor = /* @__PURE__ */ new Map();
59274
+ for (const [source, uses] of sharedUsage) {
59275
+ let file = source;
59276
+ if (!source.startsWith("/")) {
59277
+ try {
59278
+ file = resolveSsrModule(source, appDir) ?? source;
59279
+ } catch {
59280
+ }
59281
+ }
59282
+ if (file.endsWith(".vsk") || !existsSync28(file))
59283
+ continue;
59284
+ let needsRuntime = false;
59285
+ try {
59286
+ needsRuntime = runtimeImportsOf2(file).length > 0;
59287
+ } catch {
59288
+ }
59289
+ if (needsRuntime || uses > 1 && isAppLocal(source)) {
59290
+ sharedFilesFor.set(source, file);
59291
+ }
59292
+ }
59293
+ const sharedSources = [...new Set(sharedFilesFor.values())];
59042
59294
  if (process.env.VESK_DEBUG_SHARED) {
59043
59295
  console.error("[shared] candidates:", [...sharedUsage.entries()].map(([s, n]) => `${n}x ${s}`).join("\n"));
59044
- console.error("[shared] selected:", sharedSources.join(", "));
59296
+ console.error("[shared] selected:", [...sharedFilesFor.entries()].map(([s, f]) => `${s} -> ${f}`).join("\n"));
59045
59297
  }
59046
59298
  const chunkAlias = {};
59047
59299
  let sharedBundleCode = "";
@@ -59092,7 +59344,7 @@ ${body}
59092
59344
  ...appTsconfig ? { tsconfig: appTsconfig } : {}
59093
59345
  });
59094
59346
  sharedBundleCode = result.outputFiles[0].text;
59095
- sharedSources.forEach((source, i) => {
59347
+ [...sharedFilesFor.entries()].forEach(([source, file], i) => {
59096
59348
  const named = /* @__PURE__ */ new Set();
59097
59349
  let hasDefault = false;
59098
59350
  for (const entry of chunkEntries) {
@@ -59101,7 +59353,7 @@ ${body}
59101
59353
  hasDefault = hasDefault || bindings.hasDefault;
59102
59354
  }
59103
59355
  const shim = join21(tmpBase, `shim-${i}.js`);
59104
- const shimLines = [`const m = globalThis.__veskShared[${JSON.stringify(source)}];`];
59356
+ const shimLines = [`const m = globalThis.__veskShared[${JSON.stringify(file)}];`];
59105
59357
  if (hasDefault)
59106
59358
  shimLines.push(`export default m;`);
59107
59359
  for (const name of [...named].sort()) {
@@ -59211,7 +59463,8 @@ A module-scope statement runs the moment the browser evaluates the chunk, so a s
59211
59463
  return { name: entry.name, code: finalCode };
59212
59464
  };
59213
59465
  const effectiveChunkEntries = options?.skipRouteChunks ? chunkEntries.filter((e) => e.name === SHARED_CHUNK_NAME2) : chunkEntries;
59214
- const CHUNK_CONCURRENCY = Math.max(1, Math.min(6, (availableParallelism2?.() ?? 4) - 1));
59466
+ const envConcurrency = process.env.VESK_CHUNK_CONCURRENCY ? Number(process.env.VESK_CHUNK_CONCURRENCY) : NaN;
59467
+ const CHUNK_CONCURRENCY = Number.isFinite(envConcurrency) && envConcurrency >= 1 ? Math.floor(envConcurrency) : Math.max(1, Math.min(6, (availableParallelism2?.() ?? 4) - 1));
59215
59468
  const built = await mapWithConcurrency2(effectiveChunkEntries, CHUNK_CONCURRENCY, buildChunkEntry);
59216
59469
  for (const c of built) {
59217
59470
  if (c !== null)
@@ -59407,7 +59660,7 @@ async function bundleRuntimeNames2(runtimeDir, names, strict = false) {
59407
59660
  const unique = [...new Set(names)];
59408
59661
  try {
59409
59662
  try {
59410
- mkdirSync12(dirname18(entry), { recursive: true });
59663
+ mkdirSync12(dirname19(entry), { recursive: true });
59411
59664
  } catch {
59412
59665
  }
59413
59666
  try {
@@ -59648,7 +59901,7 @@ import { resolve as resolve28 } from "node:path";
59648
59901
  // ../adapter/dist/plugins.js
59649
59902
  init_paths();
59650
59903
  import { readFileSync as readFileSync28, writeFileSync as writeFileSync14, existsSync as existsSync30, mkdirSync as mkdirSync13, statSync as statSync17 } from "node:fs";
59651
- import { resolve as resolve26, dirname as dirname19, join as join22, extname as extname6, basename as basename6 } from "node:path";
59904
+ import { resolve as resolve26, dirname as dirname20, join as join22, extname as extname6, basename as basename6 } from "node:path";
59652
59905
  import { createRequire as createRequire6 } from "node:module";
59653
59906
  import { spawn as spawn2 } from "node:child_process";
59654
59907
  var PLUGIN_STATE_FILENAME2 = "plugins.json";
@@ -59689,7 +59942,7 @@ function readPluginState2(veskDir) {
59689
59942
  }
59690
59943
  function writePluginState2(veskDir, state) {
59691
59944
  const file = stateFilePath2(veskDir);
59692
- const dir = dirname19(file);
59945
+ const dir = dirname20(file);
59693
59946
  if (!existsSync30(dir))
59694
59947
  mkdirSync13(dir, { recursive: true });
59695
59948
  writeFileSync14(file, JSON.stringify(state, null, 2) + "\n", "utf-8");
@@ -59704,16 +59957,16 @@ function resolvePackage2(appDir, pkg) {
59704
59957
  } catch {
59705
59958
  try {
59706
59959
  entryPath = require3.resolve(pkg);
59707
- let cur = dirname19(entryPath);
59960
+ let cur = dirname20(entryPath);
59708
59961
  const seen = /* @__PURE__ */ new Set();
59709
- while (cur && cur !== dirname19(cur) && !seen.has(cur)) {
59962
+ while (cur && cur !== dirname20(cur) && !seen.has(cur)) {
59710
59963
  seen.add(cur);
59711
59964
  const candidate = join22(cur, "package.json");
59712
59965
  if (existsSync30(candidate)) {
59713
59966
  pkgJsonPath = candidate;
59714
59967
  break;
59715
59968
  }
59716
- const parent = dirname19(cur);
59969
+ const parent = dirname20(cur);
59717
59970
  if (parent !== cur && basename6(cur) === "node_modules")
59718
59971
  break;
59719
59972
  cur = parent;
@@ -59724,7 +59977,7 @@ function resolvePackage2(appDir, pkg) {
59724
59977
  if (pkgJsonPath && existsSync30(pkgJsonPath)) {
59725
59978
  pkgJson = readJsonFile2(pkgJsonPath);
59726
59979
  const main = pkgJson?.main || pkgJson?.module || "index.js";
59727
- entryPath = resolve26(dirname19(pkgJsonPath), main);
59980
+ entryPath = resolve26(dirname20(pkgJsonPath), main);
59728
59981
  }
59729
59982
  let localPath = localDir2(appDir, pkg);
59730
59983
  if (!localPath) {
@@ -59745,7 +59998,7 @@ function resolvePackage2(appDir, pkg) {
59745
59998
  return { installed: true, path: localPath, dir: localPath, packageJson: json ?? pkgJson };
59746
59999
  }
59747
60000
  const installed2 = !!pkgJsonPath && existsSync30(pkgJsonPath);
59748
- return { installed: installed2, path: entryPath, dir: installed2 ? dirname19(pkgJsonPath) : null, packageJson: pkgJson };
60001
+ return { installed: installed2, path: entryPath, dir: installed2 ? dirname20(pkgJsonPath) : null, packageJson: pkgJson };
59749
60002
  }
59750
60003
  function localDir2(base, pkg) {
59751
60004
  if (pkg.startsWith("@")) {
@@ -60625,7 +60878,7 @@ var __internals2 = {
60625
60878
  // ../adapter/dist/dev-config.js
60626
60879
  import { existsSync as existsSync31, readFileSync as readFileSync29, writeFileSync as writeFileSync15, mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync3, rmSync as rmSync5 } from "node:fs";
60627
60880
  import { tmpdir as tmpdir4 } from "node:os";
60628
- import { resolve as resolve27, dirname as dirname20, join as join23 } from "node:path";
60881
+ import { resolve as resolve27, dirname as dirname21, join as join23 } from "node:path";
60629
60882
  init_parser();
60630
60883
  function findConfigFile2(projectDir) {
60631
60884
  const ts9 = resolve27(projectDir, "vesk.config.ts");
@@ -60690,7 +60943,7 @@ async function writeConfigSource2(projectDir, source) {
60690
60943
  const { path, isTs } = findConfigFile2(projectDir);
60691
60944
  const target = path || resolve27(projectDir, "vesk.config.ts");
60692
60945
  await parseConfigSource(source, isTs, projectDir);
60693
- mkdirSync14(dirname20(target), { recursive: true });
60946
+ mkdirSync14(dirname21(target), { recursive: true });
60694
60947
  writeFileSync15(target, source, "utf-8");
60695
60948
  const config = await parseConfigSource(source, isTs, projectDir);
60696
60949
  return { path: target, exists: true, source, config };
@@ -61965,7 +62218,7 @@ function produceDiagnostics(input) {
61965
62218
 
61966
62219
  // ../agentic/dist/checkpoints.js
61967
62220
  import { existsSync as existsSync33, mkdirSync as mkdirSync15, readFileSync as readFileSync31, writeFileSync as writeFileSync16, statSync as statSync19, unlinkSync as unlinkSync5, rmSync as rmSync6, renameSync } from "node:fs";
61968
- import { join as join24, resolve as resolve29, dirname as dirname21, sep as sep5 } from "node:path";
62221
+ import { join as join24, resolve as resolve29, dirname as dirname22, sep as sep5 } from "node:path";
61969
62222
  import { randomUUID as nodeRandomUUID } from "node:crypto";
61970
62223
  function generateId() {
61971
62224
  try {
@@ -62125,7 +62378,7 @@ function readJson(filePath, fallback) {
62125
62378
  }
62126
62379
  }
62127
62380
  function writeJsonAtomic(filePath, data2) {
62128
- ensureDir(dirname21(filePath));
62381
+ ensureDir(dirname22(filePath));
62129
62382
  const tmp = `${filePath}.tmp`;
62130
62383
  writeFileSync16(tmp, JSON.stringify(data2, null, 2), "utf-8");
62131
62384
  try {
@@ -62226,7 +62479,7 @@ function rollback(projectDir, id) {
62226
62479
  }
62227
62480
  } else {
62228
62481
  try {
62229
- ensureDir(dirname21(abs));
62482
+ ensureDir(dirname22(abs));
62230
62483
  writeFileSync16(abs, f.before, "utf-8");
62231
62484
  } catch {
62232
62485
  }
@@ -62237,7 +62490,7 @@ function rollback(projectDir, id) {
62237
62490
 
62238
62491
  // ../agentic/dist/config.js
62239
62492
  import { readFileSync as readFileSync32, writeFileSync as writeFileSync17, existsSync as existsSync34, mkdirSync as mkdirSync16, chmodSync } from "node:fs";
62240
- import { resolve as resolve30, dirname as dirname22 } from "node:path";
62493
+ import { resolve as resolve30, dirname as dirname23 } from "node:path";
62241
62494
  var DEFAULT_CONFIG = {
62242
62495
  provider: "openai",
62243
62496
  model: "",
@@ -62366,7 +62619,7 @@ function saveAgenticConfig(projectDir, patch) {
62366
62619
  if (next.baseUrl)
62367
62620
  toWrite.baseUrl = next.baseUrl;
62368
62621
  try {
62369
- mkdirSync16(dirname22(p), { recursive: true });
62622
+ mkdirSync16(dirname23(p), { recursive: true });
62370
62623
  writeFileSync17(p, JSON.stringify(toWrite, null, 2), "utf-8");
62371
62624
  } catch {
62372
62625
  }
@@ -63692,7 +63945,7 @@ var Agent = class {
63692
63945
 
63693
63946
  // ../agentic/dist/tools/vesk.js
63694
63947
  import { existsSync as existsSync36, readFileSync as readFileSync34, writeFileSync as writeFileSync18, mkdirSync as mkdirSync17, readdirSync as readdirSync11, statSync as statSync20 } from "node:fs";
63695
- import { resolve as resolve32, join as join25, dirname as dirname23, sep as sep6 } from "node:path";
63948
+ import { resolve as resolve32, join as join25, dirname as dirname24, sep as sep6 } from "node:path";
63696
63949
  function resolveWithin3(baseDir, relPath) {
63697
63950
  const base = resolve32(baseDir);
63698
63951
  const target = resolve32(baseDir, relPath);
@@ -63725,7 +63978,7 @@ function readPluginState3(veskDir) {
63725
63978
  }
63726
63979
  function writePluginState3(veskDir, state) {
63727
63980
  const file = stateFilePath3(veskDir);
63728
- mkdirSync17(dirname23(file), { recursive: true });
63981
+ mkdirSync17(dirname24(file), { recursive: true });
63729
63982
  writeFileSync18(file, JSON.stringify(state, null, 2) + "\n", "utf-8");
63730
63983
  }
63731
63984
  function eqIgnoreCase3(a, b) {
@@ -64085,7 +64338,7 @@ function createVeskTools(deps) {
64085
64338
  if (!contained)
64086
64339
  return jsonError("path escapes project root");
64087
64340
  }
64088
- mkdirSync17(dirname23(target), { recursive: true });
64341
+ mkdirSync17(dirname24(target), { recursive: true });
64089
64342
  writeFileSync18(target, source, "utf-8");
64090
64343
  return jsonOk({ ok: true, path: target, source });
64091
64344
  }
@@ -64506,19 +64759,34 @@ function renderDefaultNotFoundPage2(opts = {}) {
64506
64759
  });
64507
64760
  }
64508
64761
 
64509
- // ../adapter/dist/css.js
64762
+ // ../adapter/dist/ssr-function.js
64510
64763
  import { readFileSync as readFileSync35, existsSync as existsSync37 } from "node:fs";
64511
- import { resolve as resolve33 } from "node:path";
64764
+ import { resolve as resolve33, relative as relative7, join as join26 } from "node:path";
64765
+ init_default_pages();
64766
+ function resolveBoundaryFileForUrl2(pathname, appDir, file) {
64767
+ const segments = pathname.split("/").filter(Boolean);
64768
+ for (let depth = segments.length; depth >= 0; depth--) {
64769
+ const dir = join26(appDir, ...segments.slice(0, depth));
64770
+ const p = join26(dir, file);
64771
+ if (existsSync37(p))
64772
+ return p;
64773
+ }
64774
+ return null;
64775
+ }
64776
+
64777
+ // ../adapter/dist/css.js
64778
+ import { readFileSync as readFileSync36, existsSync as existsSync38 } from "node:fs";
64779
+ import { resolve as resolve34 } from "node:path";
64512
64780
  var GLOBAL_CSS_URL2 = "/_vesk/static/global.css";
64513
64781
  function resolveUserCssPath2(appDir) {
64514
- const appCssSrc = resolve33(appDir, "global.css");
64515
- if (existsSync37(appCssSrc))
64782
+ const appCssSrc = resolve34(appDir, "global.css");
64783
+ if (existsSync38(appCssSrc))
64516
64784
  return appCssSrc;
64517
- const cssSrc = resolve33(appDir, "..", "src", "global.css");
64518
- if (existsSync37(cssSrc))
64785
+ const cssSrc = resolve34(appDir, "..", "src", "global.css");
64786
+ if (existsSync38(cssSrc))
64519
64787
  return cssSrc;
64520
- const altCssSrc = resolve33(appDir, "..", "src", "app.css");
64521
- if (existsSync37(altCssSrc))
64788
+ const altCssSrc = resolve34(appDir, "..", "src", "app.css");
64789
+ if (existsSync38(altCssSrc))
64522
64790
  return altCssSrc;
64523
64791
  return null;
64524
64792
  }
@@ -64534,8 +64802,8 @@ function resolveCssUrls2(opts) {
64534
64802
  // ../adapter/dist/hmr.js
64535
64803
  init_client_codegen();
64536
64804
  import { WebSocketServer } from "ws";
64537
- import { readFileSync as readFileSync36, existsSync as existsSync38, writeFileSync as writeFileSync19 } from "node:fs";
64538
- import { resolve as resolve34, dirname as dirname24 } from "node:path";
64805
+ import { readFileSync as readFileSync37, existsSync as existsSync39, writeFileSync as writeFileSync19 } from "node:fs";
64806
+ import { resolve as resolve35, dirname as dirname25 } from "node:path";
64539
64807
  import { fileURLToPath as fileURLToPath7 } from "node:url";
64540
64808
  init_default_pages();
64541
64809
  init_paths();
@@ -64743,7 +65011,7 @@ function suggestFor(message) {
64743
65011
  }
64744
65012
 
64745
65013
  // ../adapter/dist/hmr.js
64746
- var __dirname8 = dirname24(fileURLToPath7(import.meta.url));
65014
+ var __dirname8 = dirname25(fileURLToPath7(import.meta.url));
64747
65015
  function buildErrorPayload(error, filename, opts = {}) {
64748
65016
  const file = typeof filename === "string" && filename ? filename : "unknown";
64749
65017
  const parsed = parseCompilerError(error, file);
@@ -64766,19 +65034,19 @@ function buildErrorPayload(error, filename, opts = {}) {
64766
65034
  if (file.startsWith("/")) {
64767
65035
  candidates.push(file);
64768
65036
  } else {
64769
- candidates.push(resolve34(opts.appDir, file));
65037
+ candidates.push(resolve35(opts.appDir, file));
64770
65038
  if (file.startsWith("app/")) {
64771
- candidates.push(resolve34(opts.appDir, file.slice(4)));
64772
- candidates.push(resolve34(opts.appDir, "..", file));
65039
+ candidates.push(resolve35(opts.appDir, file.slice(4)));
65040
+ candidates.push(resolve35(opts.appDir, "..", file));
64773
65041
  } else {
64774
- candidates.push(resolve34(opts.appDir, "..", file));
65042
+ candidates.push(resolve35(opts.appDir, "..", file));
64775
65043
  }
64776
- candidates.push(resolve34(file));
65044
+ candidates.push(resolve35(file));
64777
65045
  }
64778
65046
  for (const absPath of candidates) {
64779
65047
  try {
64780
- if (existsSync38(absPath)) {
64781
- src2 = readFileSync36(absPath, "utf-8");
65048
+ if (existsSync39(absPath)) {
65049
+ src2 = readFileSync37(absPath, "utf-8");
64782
65050
  resolvedAbsPath = absPath;
64783
65051
  break;
64784
65052
  }
@@ -64794,7 +65062,7 @@ function buildErrorPayload(error, filename, opts = {}) {
64794
65062
  }
64795
65063
  }
64796
65064
  const tipsData = suggestFor(message);
64797
- const filePath = resolvedAbsPath ?? (typeof opts.appDir === "string" ? resolve34(opts.appDir, file) : void 0);
65065
+ const filePath = resolvedAbsPath ?? (typeof opts.appDir === "string" ? resolve35(opts.appDir, file) : void 0);
64798
65066
  const errorCode = parsed && typeof parsed.code === "string" && parsed.code ? parsed.code : error?.code ? String(error.code) : void 0;
64799
65067
  const cleanMessage = filePath && message.endsWith(` in ${filePath}`) ? message.slice(0, -` in ${filePath}`.length).trim() : message.endsWith(` in ${file}`) ? message.slice(0, -` in ${file}`.length).trim() : message;
64800
65068
  const payload = {
@@ -64826,8 +65094,8 @@ function buildErrorPayload(error, filename, opts = {}) {
64826
65094
  }
64827
65095
 
64828
65096
  // ../adapter/dist/ssr-error.js
64829
- import { existsSync as existsSync39, readFileSync as readFileSync37 } from "node:fs";
64830
- import { relative as relative7, resolve as resolve35 } from "node:path";
65097
+ import { existsSync as existsSync40, readFileSync as readFileSync38 } from "node:fs";
65098
+ import { relative as relative8, resolve as resolve36 } from "node:path";
64831
65099
 
64832
65100
  // ../adapter/dist/error-codeframe.js
64833
65101
  function buildCodeframe2(src2, line, column, context = 5) {
@@ -65011,7 +65279,7 @@ function firstSourceFileFrame(stack, projectRoot) {
65011
65279
  if (!isInsideRoot(p, projectRoot))
65012
65280
  continue;
65013
65281
  try {
65014
- if (!existsSync39(p))
65282
+ if (!existsSync40(p))
65015
65283
  continue;
65016
65284
  } catch {
65017
65285
  continue;
@@ -65042,22 +65310,22 @@ function findIdentifierUsage(src2, name) {
65042
65310
  return null;
65043
65311
  }
65044
65312
  function projectOf(ctx2) {
65045
- return ctx2.projectDir || resolve35(ctx2.appDir, "..");
65313
+ return ctx2.projectDir || resolve36(ctx2.appDir, "..");
65046
65314
  }
65047
65315
  function displayPath(absPath, ctx2) {
65048
- const appRel = relative7(ctx2.appDir, absPath);
65316
+ const appRel = relative8(ctx2.appDir, absPath);
65049
65317
  if (appRel && !appRel.startsWith(".."))
65050
65318
  return appRel || absPath;
65051
- const projRel = relative7(projectOf(ctx2), absPath);
65319
+ const projRel = relative8(projectOf(ctx2), absPath);
65052
65320
  if (projRel && !projRel.startsWith(".."))
65053
65321
  return projRel;
65054
65322
  return absPath;
65055
65323
  }
65056
65324
  function readIfFile(absPath) {
65057
65325
  try {
65058
- if (!existsSync39(absPath))
65326
+ if (!existsSync40(absPath))
65059
65327
  return null;
65060
- return readFileSync37(absPath, "utf-8");
65328
+ return readFileSync38(absPath, "utf-8");
65061
65329
  } catch {
65062
65330
  return null;
65063
65331
  }
@@ -65065,13 +65333,13 @@ function readIfFile(absPath) {
65065
65333
  function resolveComponentFile(name, ctx2) {
65066
65334
  const fromRoutes = ctx2.routeSources?.get(name);
65067
65335
  if (fromRoutes) {
65068
- const abs = resolve35(ctx2.appDir, fromRoutes);
65336
+ const abs = resolve36(ctx2.appDir, fromRoutes);
65069
65337
  if (readIfFile(abs) !== null)
65070
65338
  return abs;
65071
65339
  }
65072
65340
  const fromShared = ctx2.componentMap?.get(name);
65073
65341
  if (fromShared) {
65074
- const abs = resolve35(projectOf(ctx2), fromShared);
65342
+ const abs = resolve36(projectOf(ctx2), fromShared);
65075
65343
  if (readIfFile(abs) !== null)
65076
65344
  return abs;
65077
65345
  if (readIfFile(fromShared) !== null)
@@ -65205,13 +65473,13 @@ function renderDevErrorPage(payload, opts) {
65205
65473
 
65206
65474
  // src/build-packages.ts
65207
65475
  import { spawnSync as spawnSync2 } from "node:child_process";
65208
- import { cpSync as cpSync2, existsSync as existsSync40, mkdirSync as mkdirSync18, readFileSync as readFileSync38, readdirSync as readdirSync12, statSync as statSync21, writeFileSync as writeFileSync20 } from "node:fs";
65476
+ import { cpSync as cpSync2, existsSync as existsSync41, mkdirSync as mkdirSync18, readFileSync as readFileSync39, readdirSync as readdirSync12, statSync as statSync21, writeFileSync as writeFileSync20 } from "node:fs";
65209
65477
  import { createRequire as createRequire7 } from "node:module";
65210
- import { dirname as dirname25, join as join26, resolve as resolve36 } from "node:path";
65478
+ import { dirname as dirname26, join as join27, resolve as resolve37 } from "node:path";
65211
65479
  import { fileURLToPath as fileURLToPath8 } from "node:url";
65212
65480
  var require2 = createRequire7(import.meta.url);
65213
- var __dirname9 = dirname25(fileURLToPath8(import.meta.url));
65214
- var root2 = resolve36(__dirname9, "..", "..", "..");
65481
+ var __dirname9 = dirname26(fileURLToPath8(import.meta.url));
65482
+ var root2 = resolve37(__dirname9, "..", "..", "..");
65215
65483
  var PACKAGES = {
65216
65484
  // types first — it is a dependency-free leaf that compiler and adapter
65217
65485
  // import for their shared type definitions.
@@ -65242,7 +65510,7 @@ var PACKAGES = {
65242
65510
  function newestSourceMtime(srcDir) {
65243
65511
  let newest = 0;
65244
65512
  for (const name of readdirSync12(srcDir)) {
65245
- const p = join26(srcDir, name);
65513
+ const p = join27(srcDir, name);
65246
65514
  const st = statSync21(p);
65247
65515
  if (st.isDirectory()) {
65248
65516
  newest = Math.max(newest, newestSourceMtime(p));
@@ -65253,11 +65521,11 @@ function newestSourceMtime(srcDir) {
65253
65521
  return newest;
65254
65522
  }
65255
65523
  function distStale(pkgDir, entry) {
65256
- const distIndex = join26(pkgDir, "dist", `${entry}.js`);
65257
- if (!existsSync40(distIndex)) return true;
65258
- const distPkg = join26(pkgDir, "dist", "package.json");
65259
- const distStamp = Math.max(statSync21(distIndex).mtimeMs, existsSync40(distPkg) ? statSync21(distPkg).mtimeMs : 0);
65260
- return newestSourceMtime(join26(pkgDir, "src")) > distStamp;
65524
+ const distIndex = join27(pkgDir, "dist", `${entry}.js`);
65525
+ if (!existsSync41(distIndex)) return true;
65526
+ const distPkg = join27(pkgDir, "dist", "package.json");
65527
+ const distStamp = Math.max(statSync21(distIndex).mtimeMs, existsSync41(distPkg) ? statSync21(distPkg).mtimeMs : 0);
65528
+ return newestSourceMtime(join27(pkgDir, "src")) > distStamp;
65261
65529
  }
65262
65530
  function distPackageJson(pkgName, entry, serverEntry, version2) {
65263
65531
  const exports = {
@@ -65280,24 +65548,24 @@ function distPackageJson(pkgName, entry, serverEntry, version2) {
65280
65548
  }
65281
65549
  function buildPackages(force = false) {
65282
65550
  for (const [pkg, cfg] of Object.entries(PACKAGES)) {
65283
- const pkgDir = resolve36(root2, "packages", pkg);
65284
- if (!existsSync40(join26(pkgDir, "src"))) continue;
65551
+ const pkgDir = resolve37(root2, "packages", pkg);
65552
+ if (!existsSync41(join27(pkgDir, "src"))) continue;
65285
65553
  if (!force && !distStale(pkgDir, cfg.entry)) continue;
65286
65554
  console.log(`[build] ${cfg.name} -> tsc`);
65287
65555
  const tscBin = require2.resolve("typescript/bin/tsc");
65288
- const result = spawnSync2(process.execPath, [tscBin, "-p", join26(pkgDir, "tsconfig.build.json")], {
65556
+ const result = spawnSync2(process.execPath, [tscBin, "-p", join27(pkgDir, "tsconfig.build.json")], {
65289
65557
  stdio: "inherit"
65290
65558
  });
65291
65559
  if (result.status !== 0) {
65292
65560
  throw new Error(`tsc failed for ${cfg.name}`);
65293
65561
  }
65294
- const distDir = join26(pkgDir, "dist");
65562
+ const distDir = join27(pkgDir, "dist");
65295
65563
  for (const c of cfg.copy || []) {
65296
- const to = join26(distDir, c.to);
65297
- mkdirSync18(dirname25(to), { recursive: true });
65298
- cpSync2(join26(pkgDir, c.from), to, { recursive: true });
65564
+ const to = join27(distDir, c.to);
65565
+ mkdirSync18(dirname26(to), { recursive: true });
65566
+ cpSync2(join27(pkgDir, c.from), to, { recursive: true });
65299
65567
  }
65300
- const srcPkg = JSON.parse(readFileSync38(join26(pkgDir, "package.json"), "utf-8"));
65568
+ const srcPkg = JSON.parse(readFileSync39(join27(pkgDir, "package.json"), "utf-8"));
65301
65569
  if (pkg === "lucide-vesk") {
65302
65570
  const lucideDistPkg = {
65303
65571
  name: srcPkg.name,
@@ -65311,9 +65579,9 @@ function buildPackages(force = false) {
65311
65579
  "./package.json": "./package.json"
65312
65580
  }
65313
65581
  };
65314
- writeFileSync20(join26(distDir, "package.json"), JSON.stringify(lucideDistPkg, null, 2) + "\n");
65582
+ writeFileSync20(join27(distDir, "package.json"), JSON.stringify(lucideDistPkg, null, 2) + "\n");
65315
65583
  } else {
65316
- writeFileSync20(join26(distDir, "package.json"), distPackageJson(cfg.name, cfg.entry, cfg.serverEntry, srcPkg.version || "1.0.0"));
65584
+ writeFileSync20(join27(distDir, "package.json"), distPackageJson(cfg.name, cfg.entry, cfg.serverEntry, srcPkg.version || "1.0.0"));
65317
65585
  }
65318
65586
  console.log(`[build] ${cfg.name} -> dist`);
65319
65587
  }
@@ -65321,13 +65589,13 @@ function buildPackages(force = false) {
65321
65589
  function ensurePackagesBuilt() {
65322
65590
  buildPackages(false);
65323
65591
  }
65324
- if (process.argv[1] && resolve36(process.argv[1]) === fileURLToPath8(import.meta.url)) {
65592
+ if (process.argv[1] && resolve37(process.argv[1]) === fileURLToPath8(import.meta.url)) {
65325
65593
  buildPackages(process.argv.includes("--force"));
65326
65594
  }
65327
65595
 
65328
65596
  // src/action-handler.ts
65329
- import { existsSync as existsSync41, readFileSync as readFileSync39, readdirSync as readdirSync13 } from "node:fs";
65330
- import { resolve as resolve37 } from "node:path";
65597
+ import { existsSync as existsSync42, readFileSync as readFileSync40, readdirSync as readdirSync13 } from "node:fs";
65598
+ import { resolve as resolve38 } from "node:path";
65331
65599
 
65332
65600
  // ../compiler/dist/server-cookies.js
65333
65601
  function parseCookies3(str3) {
@@ -65410,8 +65678,8 @@ function pageSourcesFor(appDirPath, routeTree) {
65410
65678
  const out = [];
65411
65679
  function walk9(nodes) {
65412
65680
  for (const node of nodes) {
65413
- if (node.page) out.push(resolve37(appDirPath, node.sourceDir, "page.vsk"));
65414
- if (node.layout) out.push(resolve37(appDirPath, node.sourceDir, "layout.vsk"));
65681
+ if (node.page) out.push(resolve38(appDirPath, node.sourceDir, "page.vsk"));
65682
+ if (node.layout) out.push(resolve38(appDirPath, node.sourceDir, "layout.vsk"));
65415
65683
  walk9(node.children);
65416
65684
  }
65417
65685
  }
@@ -65419,7 +65687,7 @@ function pageSourcesFor(appDirPath, routeTree) {
65419
65687
  return out;
65420
65688
  }
65421
65689
  function walkVskFiles(dir, out, seen) {
65422
- if (!existsSync41(dir)) return;
65690
+ if (!existsSync42(dir)) return;
65423
65691
  let entries;
65424
65692
  try {
65425
65693
  entries = readdirSync13(dir, { withFileTypes: true });
@@ -65427,7 +65695,7 @@ function walkVskFiles(dir, out, seen) {
65427
65695
  return;
65428
65696
  }
65429
65697
  for (const entry of entries) {
65430
- const full = resolve37(dir, entry.name);
65698
+ const full = resolve38(dir, entry.name);
65431
65699
  if (seen.has(full)) continue;
65432
65700
  seen.add(full);
65433
65701
  if (entry.isDirectory()) {
@@ -65447,16 +65715,16 @@ function candidateSources(appDirPath, routeTree) {
65447
65715
  seen.add(src2);
65448
65716
  out.push(src2);
65449
65717
  }
65450
- const projectRoot = resolve37(appDirPath, "..");
65451
- for (const dir of [resolve37(projectRoot, "components"), appDirPath, projectRoot]) {
65718
+ const projectRoot = resolve38(appDirPath, "..");
65719
+ for (const dir of [resolve38(projectRoot, "components"), appDirPath, projectRoot]) {
65452
65720
  walkVskFiles(dir, out, seen);
65453
65721
  }
65454
65722
  return out;
65455
65723
  }
65456
65724
  function registerSource(sourcePath2) {
65457
- if (!existsSync41(sourcePath2)) return;
65725
+ if (!existsSync42(sourcePath2)) return;
65458
65726
  try {
65459
- compileFile(readFileSync39(sourcePath2, "utf-8"), { sourcePath: sourcePath2 });
65727
+ compileFile(readFileSync40(sourcePath2, "utf-8"), { sourcePath: sourcePath2 });
65460
65728
  } catch {
65461
65729
  }
65462
65730
  }
@@ -65465,8 +65733,8 @@ function ensureActionRegistered(actionId, pagePathname, appDirPath, routeTree) {
65465
65733
  const match = matchUrl(routeTree, pagePathname);
65466
65734
  if (match) {
65467
65735
  for (let i = match.nodes.length - 1; i >= 0; i--) {
65468
- registerSource(resolve37(appDirPath, match.nodes[i].sourceDir, "page.vsk"));
65469
- registerSource(resolve37(appDirPath, match.nodes[i].sourceDir, "layout.vsk"));
65736
+ registerSource(resolve38(appDirPath, match.nodes[i].sourceDir, "page.vsk"));
65737
+ registerSource(resolve38(appDirPath, match.nodes[i].sourceDir, "layout.vsk"));
65470
65738
  }
65471
65739
  }
65472
65740
  if (getAction2(actionId)) return;
@@ -65492,24 +65760,24 @@ async function renderPageHtml(pagePathname, params, ctx2) {
65492
65760
  let head = "";
65493
65761
  for (let i = chain.length - 1; i >= 0; i--) {
65494
65762
  const node = chain[i];
65495
- const pageFilePath = resolve37(ctx2.appDirPath, node.sourceDir, "page.vsk");
65496
- const layoutFilePath = resolve37(ctx2.appDirPath, node.sourceDir, "layout.vsk");
65497
- if (i === chain.length - 1 && node.page && existsSync41(pageFilePath)) {
65498
- const src3 = readFileSync39(pageFilePath, "utf-8");
65763
+ const pageFilePath = resolve38(ctx2.appDirPath, node.sourceDir, "page.vsk");
65764
+ const layoutFilePath = resolve38(ctx2.appDirPath, node.sourceDir, "layout.vsk");
65765
+ if (i === chain.length - 1 && node.page && existsSync42(pageFilePath)) {
65766
+ const src3 = readFileSync40(pageFilePath, "utf-8");
65499
65767
  const compName2 = resolveComponentName(src3) || node.page;
65500
65768
  const result = await renderPage(src3, compName2, { params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath });
65501
65769
  body = result.body;
65502
65770
  head = result.head || "";
65503
65771
  }
65504
- if (node.layout && existsSync41(layoutFilePath)) {
65505
- const src3 = readFileSync39(layoutFilePath, "utf-8");
65772
+ if (node.layout && existsSync42(layoutFilePath)) {
65773
+ const src3 = readFileSync40(layoutFilePath, "utf-8");
65506
65774
  const compName2 = resolveComponentName(src3) || node.layout;
65507
65775
  const result = await renderPage(src3, compName2, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath });
65508
65776
  body = result.body;
65509
65777
  head = (result.head || "") + head;
65510
65778
  }
65511
65779
  }
65512
- const hasLayout = chain.some((n) => n.layout && existsSync41(resolve37(ctx2.appDirPath, n.sourceDir, "layout.vsk")));
65780
+ const hasLayout = chain.some((n) => n.layout && existsSync42(resolve38(ctx2.appDirPath, n.sourceDir, "layout.vsk")));
65513
65781
  if (hasLayout) {
65514
65782
  const secMeta = securityMeta(ctx2.security);
65515
65783
  const headBlock = await applyHeadInjects(
@@ -65533,9 +65801,9 @@ ${prettifyHtml(body)}
65533
65801
  }
65534
65802
  const leaf2 = chain.find((n) => n.page);
65535
65803
  if (!leaf2) return null;
65536
- const src2 = readFileSync39(resolve37(ctx2.appDirPath, leaf2.sourceDir, "page.vsk"), "utf-8");
65804
+ const src2 = readFileSync40(resolve38(ctx2.appDirPath, leaf2.sourceDir, "page.vsk"), "utf-8");
65537
65805
  const compName = resolveComponentName(src2) || leaf2.page;
65538
- const html = await renderFullPage(src2, compName, { params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: actionCssUrls(ctx2.appDirPath), security: ctx2.security, sourcePath: resolve37(ctx2.appDirPath, leaf2.sourceDir, "page.vsk"), plugins: ctx2.plugins });
65806
+ const html = await renderFullPage(src2, compName, { params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: actionCssUrls(ctx2.appDirPath), security: ctx2.security, sourcePath: resolve38(ctx2.appDirPath, leaf2.sourceDir, "page.vsk"), plugins: ctx2.plugins });
65539
65807
  return applyHtmlPlugins(html.replace("</body>", ' <script type="module" src="/_vesk/hmr.js"></script>\n</body>'), ctx2.plugins, { sourcePath: ctx2.url.pathname });
65540
65808
  }
65541
65809
  async function handleActionRequest(req, res, ctx2) {
@@ -65676,6 +65944,12 @@ async function handleActionRequest(req, res, ctx2) {
65676
65944
  }
65677
65945
 
65678
65946
  // src/dev-server.ts
65947
+ function toNodeHeaders2(response) {
65948
+ const headers2 = Object.fromEntries(response.headers);
65949
+ const cookies2 = response.headers.getSetCookie?.() ?? [];
65950
+ if (cookies2.length > 0) headers2["set-cookie"] = cookies2;
65951
+ return headers2;
65952
+ }
65679
65953
  var agenticCheckpointManager = new CheckpointManager();
65680
65954
  function buildDevErrorPayload(input) {
65681
65955
  const { err, errorMessage, filename, fullPath, appDir, fileExists } = input;
@@ -65700,7 +65974,7 @@ function buildDevErrorPayload(input) {
65700
65974
  payload.column = colMatch ? parseInt(colMatch[1], 10) : 1;
65701
65975
  if (fileExists && payload.line > 0) {
65702
65976
  try {
65703
- const src2 = readFileSync40(fullPath, "utf-8");
65977
+ const src2 = readFileSync41(fullPath, "utf-8");
65704
65978
  const cf = buildCodeframe2(src2, payload.line, payload.column);
65705
65979
  if (cf) {
65706
65980
  cf.file = payload.file || filename;
@@ -65718,14 +65992,14 @@ function resolveDevErrorReport(report, ctx2) {
65718
65992
  let componentMap;
65719
65993
  let routeSources;
65720
65994
  try {
65721
- componentMap = scanComponents(resolve38(ctx2.projectDir, "components"));
65995
+ componentMap = scanComponents(resolve39(ctx2.projectDir, "components"));
65722
65996
  } catch {
65723
65997
  componentMap = void 0;
65724
65998
  }
65725
65999
  try {
65726
66000
  routeSources = /* @__PURE__ */ new Map();
65727
66001
  for (const [name, rel] of collectSources(ctx2.routeTree || [])) {
65728
- routeSources.set(name, resolve38(ctx2.appDir, rel));
66002
+ routeSources.set(name, resolve39(ctx2.appDir, rel));
65729
66003
  }
65730
66004
  } catch {
65731
66005
  routeSources = void 0;
@@ -65756,9 +66030,9 @@ function devErrorContextForMatch(match, appDir, projectDir, routeTree) {
65756
66030
  for (const kind of ["page.vsk", "layout.vsk", "error.vsk"]) {
65757
66031
  for (const node of nodes) {
65758
66032
  if (!node || typeof node.sourceDir !== "string") continue;
65759
- const p = resolve38(appDir, node.sourceDir, kind);
66033
+ const p = resolve39(appDir, node.sourceDir, kind);
65760
66034
  try {
65761
- if (existsSync42(p) && !routeFiles.includes(p)) routeFiles.push(p);
66035
+ if (existsSync43(p) && !routeFiles.includes(p)) routeFiles.push(p);
65762
66036
  } catch {
65763
66037
  }
65764
66038
  }
@@ -65768,14 +66042,14 @@ function devErrorContextForMatch(match, appDir, projectDir, routeTree) {
65768
66042
  let componentMap;
65769
66043
  let routeSources;
65770
66044
  try {
65771
- componentMap = scanComponents(resolve38(projectDir, "components"));
66045
+ componentMap = scanComponents(resolve39(projectDir, "components"));
65772
66046
  } catch {
65773
66047
  componentMap = void 0;
65774
66048
  }
65775
66049
  try {
65776
66050
  routeSources = /* @__PURE__ */ new Map();
65777
66051
  for (const [name, rel] of collectSources(routeTree || [])) {
65778
- routeSources.set(name, resolve38(appDir, rel));
66052
+ routeSources.set(name, resolve39(appDir, rel));
65779
66053
  }
65780
66054
  } catch {
65781
66055
  routeSources = void 0;
@@ -65785,14 +66059,14 @@ function devErrorContextForMatch(match, appDir, projectDir, routeTree) {
65785
66059
  function resolveRuntimeDir(projectDir) {
65786
66060
  const candidates = [
65787
66061
  // installed app layout
65788
- resolve38(projectDir, "node_modules", "@vesk", "runtime"),
66062
+ resolve39(projectDir, "node_modules", "@vesk", "runtime"),
65789
66063
  // monorepo checkout (tests/probes run from the repo root)
65790
- resolve38(import.meta.dirname ?? ".", "..", "..", "runtime", "dist")
66064
+ resolve39(import.meta.dirname ?? ".", "..", "..", "runtime", "dist")
65791
66065
  ];
65792
66066
  for (const dir of candidates) {
65793
- if (existsSync42(join27(dir, "ripple-runtime.js"))) return dir;
65794
- const distDir = join27(dir, "dist");
65795
- if (existsSync42(join27(distDir, "ripple-runtime.js"))) return distDir;
66067
+ if (existsSync43(join28(dir, "ripple-runtime.js"))) return dir;
66068
+ const distDir = join28(dir, "dist");
66069
+ if (existsSync43(join28(distDir, "ripple-runtime.js"))) return distDir;
65796
66070
  }
65797
66071
  return null;
65798
66072
  }
@@ -65834,7 +66108,7 @@ var LOG = {
65834
66108
  console.log(` ${m} ${pathname} ${s}${t}`);
65835
66109
  }
65836
66110
  };
65837
- var DEV_SCRIPTS = ' <script type="module" src="/_vesk/client.js"></script>\n <script type="module" src="/_vesk/hmr.js"></script>';
66111
+ var DEV_SCRIPTS = ' <script src="/_vesk/dev-config.js"></script>\n <script type="module" src="/_vesk/client.js"></script>\n <script type="module" src="/_vesk/hmr.js"></script>';
65838
66112
  function injectDevScripts(html) {
65839
66113
  if (!html.includes("</body>")) return html;
65840
66114
  return html.replace("</body>", DEV_SCRIPTS + "\n</body>");
@@ -65950,6 +66224,7 @@ var HMR_SKIP_MARKERS = [
65950
66224
  "node_modules/",
65951
66225
  ".vesk/",
65952
66226
  "tmp-vesk-chunk-",
66227
+ "tmp-vesk-shared-",
65953
66228
  "/dist/",
65954
66229
  "/build/",
65955
66230
  "/coverage/",
@@ -66029,10 +66304,10 @@ function collectRoutePaths(nodes, out = []) {
66029
66304
  return out;
66030
66305
  }
66031
66306
  function countFilesNamed(dir, name) {
66032
- if (!existsSync42(dir)) return 0;
66307
+ if (!existsSync43(dir)) return 0;
66033
66308
  let n = 0;
66034
66309
  for (const entry of readdirSync14(dir, { withFileTypes: true })) {
66035
- const p = join27(dir, entry.name);
66310
+ const p = join28(dir, entry.name);
66036
66311
  if (entry.isDirectory()) n += countFilesNamed(p, name);
66037
66312
  else if (entry.name === name) n++;
66038
66313
  }
@@ -66061,8 +66336,8 @@ async function startDevServer(port, projectDir, config, host) {
66061
66336
  if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";
66062
66337
  const secCfg = config.security || {};
66063
66338
  const maxBodyBytes = (typeof secCfg.maxBodyBytes === "number" ? secCfg.maxBodyBytes : void 0) || DEFAULT_MAX_BODY_BYTES;
66064
- const appDirPath = resolve38(projectDir, typeof config.appDir === "string" ? config.appDir : "./app");
66065
- const publicDir = resolve38(projectDir, typeof config.publicDir === "string" ? config.publicDir : "./public");
66339
+ const appDirPath = resolve39(projectDir, typeof config.appDir === "string" ? config.appDir : "./app");
66340
+ const publicDir = resolve39(projectDir, typeof config.publicDir === "string" ? config.publicDir : "./public");
66066
66341
  installMdReadHook2([publicDir]);
66067
66342
  try {
66068
66343
  ensurePackagesBuilt();
@@ -66075,7 +66350,7 @@ async function startDevServer(port, projectDir, config, host) {
66075
66350
  process.exit(1);
66076
66351
  }
66077
66352
  const runtimeDir = runtimeDirUnchecked;
66078
- const veskStateDir = join27(projectDir, ".vesk");
66353
+ const veskStateDir = join28(projectDir, ".vesk");
66079
66354
  const configPluginsRaw = config.plugins || [];
66080
66355
  const configPluginNames = configPluginsRaw.map((p) => typeof p === "string" ? p : p?.name).filter((n) => !!n);
66081
66356
  const rawDevPlugins = config.plugins || [];
@@ -66174,21 +66449,21 @@ async function startDevServer(port, projectDir, config, host) {
66174
66449
  }
66175
66450
  let devGlobalCssContent = "";
66176
66451
  let lastServedCssGlobal = "";
66177
- const appCssPath = join27(appDirPath, "global.css");
66178
- const srcDir = join27(projectDir, "src");
66179
- const cssPath = join27(srcDir, "global.css");
66180
- const altCssPath = join27(srcDir, "app.css");
66452
+ const appCssPath = join28(appDirPath, "global.css");
66453
+ const srcDir = join28(projectDir, "src");
66454
+ const cssPath = join28(srcDir, "global.css");
66455
+ const altCssPath = join28(srcDir, "app.css");
66181
66456
  let rawCss = "";
66182
66457
  let devCssSource = "";
66183
- if (existsSync42(appCssPath)) {
66458
+ if (existsSync43(appCssPath)) {
66184
66459
  devCssSource = appCssPath;
66185
- rawCss = readFileSync40(appCssPath, "utf-8");
66186
- } else if (existsSync42(cssPath)) {
66460
+ rawCss = readFileSync41(appCssPath, "utf-8");
66461
+ } else if (existsSync43(cssPath)) {
66187
66462
  devCssSource = cssPath;
66188
- rawCss = readFileSync40(cssPath, "utf-8");
66189
- } else if (existsSync42(altCssPath)) {
66463
+ rawCss = readFileSync41(cssPath, "utf-8");
66464
+ } else if (existsSync43(altCssPath)) {
66190
66465
  devCssSource = altCssPath;
66191
- rawCss = readFileSync40(altCssPath, "utf-8");
66466
+ rawCss = readFileSync41(altCssPath, "utf-8");
66192
66467
  }
66193
66468
  if (rawCss) {
66194
66469
  const activeAtStart = getActiveDevPlugins();
@@ -66235,8 +66510,9 @@ async function startDevServer(port, projectDir, config, host) {
66235
66510
  clientChunks = next;
66236
66511
  }
66237
66512
  const routeChunksBuilt = /* @__PURE__ */ new Set();
66513
+ const routeChunkBuilds = /* @__PURE__ */ new Map();
66238
66514
  let clientGeneration = 0;
66239
- const devCacheDir = () => join27(projectDir, "node_modules", ".vesk", "dev-cache");
66515
+ const devCacheDir = () => join28(projectDir, "node_modules", ".vesk", "dev-cache");
66240
66516
  function devCacheKey() {
66241
66517
  const parts = [`flags:${!!config.routeDataCache}`];
66242
66518
  const walk9 = (dir) => {
@@ -66248,7 +66524,7 @@ async function startDevServer(port, projectDir, config, host) {
66248
66524
  }
66249
66525
  for (const name of entries.sort()) {
66250
66526
  if (name === "node_modules" || name.startsWith(".")) continue;
66251
- const p = join27(dir, name);
66527
+ const p = join28(dir, name);
66252
66528
  let st;
66253
66529
  try {
66254
66530
  st = statSync22(p);
@@ -66265,27 +66541,42 @@ async function startDevServer(port, projectDir, config, host) {
66265
66541
  };
66266
66542
  walk9(appDirPath);
66267
66543
  try {
66268
- parts.push(`compiler:${readFileSync40(join27(process.cwd(), "node_modules", "@vesk", "compiler", "package.json"), "utf8")}`);
66544
+ parts.push(`compiler:${readFileSync41(join28(process.cwd(), "node_modules", "@vesk", "compiler", "package.json"), "utf8")}`);
66269
66545
  } catch {
66270
66546
  }
66271
66547
  return createHash3("sha256").update(parts.join("\n")).digest("hex").slice(0, 32);
66272
66548
  }
66273
66549
  function readDevBundleCache() {
66274
66550
  try {
66275
- const file = join27(devCacheDir(), "client-bundle.json");
66276
- const parsed = JSON.parse(readFileSync40(file, "utf8"));
66551
+ const file = join28(devCacheDir(), "client-bundle.json");
66552
+ const parsed = JSON.parse(readFileSync41(file, "utf8"));
66277
66553
  if (parsed.key !== devCacheKey() || typeof parsed.main !== "string" || !Array.isArray(parsed.chunks)) return null;
66278
66554
  return { main: parsed.main, chunks: parsed.chunks };
66279
66555
  } catch {
66280
66556
  return null;
66281
66557
  }
66282
66558
  }
66559
+ let persistChunksTimer = null;
66560
+ function persistDevChunksSoon() {
66561
+ if (persistChunksTimer) return;
66562
+ persistChunksTimer = setTimeout(() => {
66563
+ persistChunksTimer = null;
66564
+ writeDevBundleCache(
66565
+ clientBundle,
66566
+ [...clientChunks].map(([url, code]) => ({
66567
+ name: url.slice(url.lastIndexOf("/") + 1),
66568
+ code
66569
+ }))
66570
+ );
66571
+ }, 2e3);
66572
+ persistChunksTimer.unref?.();
66573
+ }
66283
66574
  function writeDevBundleCache(main, chunks) {
66284
66575
  try {
66285
66576
  const dir = devCacheDir();
66286
66577
  mkdirSync19(dir, { recursive: true });
66287
- const file = join27(dir, "client-bundle.json");
66288
- const tmp = join27(dir, `client-bundle.${process.pid}.tmp`);
66578
+ const file = join28(dir, "client-bundle.json");
66579
+ const tmp = join28(dir, `client-bundle.${process.pid}.tmp`);
66289
66580
  writeFileSync21(tmp, JSON.stringify({ key: devCacheKey(), main, chunks }), "utf8");
66290
66581
  renameSync2(tmp, file);
66291
66582
  } catch {
@@ -66293,23 +66584,36 @@ async function startDevServer(port, projectDir, config, host) {
66293
66584
  }
66294
66585
  async function ensureRouteChunk(fullPath) {
66295
66586
  if (routeChunksBuilt.has(fullPath)) return;
66296
- routeChunksBuilt.add(fullPath);
66297
- const generation = clientGeneration;
66298
- const { chunks } = await generateClientBundle2(routeTree, appDirPath, /* @__PURE__ */ new Map(), {
66299
- importRuntime: true,
66300
- hmr: true,
66301
- codeSplit: true,
66302
- cache: bundleCache,
66303
- onlyRoutes: [fullPath],
66304
- ...config.routeDataCache !== void 0 ? { routeDataCache: config.routeDataCache } : {}
66305
- });
66306
- if (generation !== clientGeneration) {
66307
- routeChunksBuilt.delete(fullPath);
66587
+ const inFlight = routeChunkBuilds.get(fullPath);
66588
+ if (inFlight) {
66589
+ await inFlight;
66308
66590
  return;
66309
66591
  }
66310
- const next = new Map(clientChunks);
66311
- for (const c of chunks) next.set(`/_vesk/static/${c.name}`, c.code);
66312
- clientChunks = next;
66592
+ const build4 = (async () => {
66593
+ const generation = clientGeneration;
66594
+ const { chunks } = await generateClientBundle2(routeTree, appDirPath, /* @__PURE__ */ new Map(), {
66595
+ importRuntime: true,
66596
+ hmr: true,
66597
+ codeSplit: true,
66598
+ cache: bundleCache,
66599
+ onlyRoutes: [fullPath],
66600
+ ...config.routeDataCache !== void 0 ? { routeDataCache: config.routeDataCache } : {}
66601
+ });
66602
+ if (generation !== clientGeneration) return false;
66603
+ const next = new Map(clientChunks);
66604
+ for (const c of chunks) next.set(`/_vesk/static/${c.name}`, c.code);
66605
+ clientChunks = next;
66606
+ return true;
66607
+ })();
66608
+ routeChunkBuilds.set(fullPath, build4);
66609
+ try {
66610
+ if (await build4) {
66611
+ routeChunksBuilt.add(fullPath);
66612
+ persistDevChunksSoon();
66613
+ }
66614
+ } finally {
66615
+ routeChunkBuilds.delete(fullPath);
66616
+ }
66313
66617
  }
66314
66618
  function routeFullPathForChunk(chunkName) {
66315
66619
  let found = null;
@@ -66355,6 +66659,12 @@ async function startDevServer(port, projectDir, config, host) {
66355
66659
  clientBundle = main;
66356
66660
  devBundleBytes = Buffer.byteLength(main, "utf8");
66357
66661
  storeChunks(chunks);
66662
+ routeChunksBuilt.clear();
66663
+ for (const c of chunks) {
66664
+ const fullPath = c.name === SHARED_CHUNK_NAME2 ? null : routeFullPathForChunk(c.name);
66665
+ if (fullPath) routeChunksBuilt.add(fullPath);
66666
+ }
66667
+ clientGeneration++;
66358
66668
  writeDevBundleCache(main, chunks);
66359
66669
  } catch (e) {
66360
66670
  LOG.err(`client build error:`, e.message);
@@ -66574,12 +66884,54 @@ async function startDevServer(port, projectDir, config, host) {
66574
66884
  let debounceTimer = null;
66575
66885
  let cssDebounceTimer = null;
66576
66886
  const watchDir = projectDir;
66577
- watch(watchDir, { recursive: true }, (eventType, filename) => {
66578
- if (!filename) return;
66887
+ const dirWatchers = /* @__PURE__ */ new Map();
66888
+ const watchDirTree = (dir) => {
66889
+ if (dirWatchers.has(dir)) return;
66890
+ let entries;
66891
+ try {
66892
+ entries = readdirSync14(dir, { withFileTypes: true });
66893
+ } catch {
66894
+ return;
66895
+ }
66896
+ try {
66897
+ const watcher = watch(dir, (eventType, changed) => {
66898
+ if (!changed) return;
66899
+ const abs = join28(dir, String(changed));
66900
+ const rel = relative9(projectDir, abs);
66901
+ if (!rel || rel.startsWith("..")) return;
66902
+ if (eventType === "rename") {
66903
+ try {
66904
+ if (statSync22(abs).isDirectory()) {
66905
+ watchDirTree(abs);
66906
+ return;
66907
+ }
66908
+ } catch {
66909
+ }
66910
+ }
66911
+ onWatchEvent(eventType, normalizeWatchPath(rel));
66912
+ });
66913
+ watcher.on("error", () => {
66914
+ try {
66915
+ watcher.close();
66916
+ } catch {
66917
+ }
66918
+ dirWatchers.delete(dir);
66919
+ });
66920
+ dirWatchers.set(dir, watcher);
66921
+ } catch {
66922
+ return;
66923
+ }
66924
+ for (const entry of entries) {
66925
+ if (!entry.isDirectory()) continue;
66926
+ if (HMR_SKIP_DIRS.has(entry.name)) continue;
66927
+ watchDirTree(join28(dir, entry.name));
66928
+ }
66929
+ };
66930
+ const onWatchEvent = (eventType, filename) => {
66579
66931
  const kind = classifyHmrWatchPath(filename);
66580
66932
  if (kind === "ignored") return;
66581
- const fullPath = filename.startsWith("/") ? filename : join27(watchDir, filename);
66582
- const fileExists = existsSync42(fullPath);
66933
+ const fullPath = filename.startsWith("/") ? filename : join28(watchDir, filename);
66934
+ const fileExists = existsSync43(fullPath);
66583
66935
  const bcast = (msg) => {
66584
66936
  const f = globalThis.__vesk_broadcastHmr;
66585
66937
  if (typeof f === "function") f(msg);
@@ -66603,7 +66955,7 @@ async function startDevServer(port, projectDir, config, host) {
66603
66955
  debounceTimer = setTimeout(async () => {
66604
66956
  const t0 = Date.now();
66605
66957
  try {
66606
- const current3 = fileExists ? readFileSync40(fullPath, "utf-8") : null;
66958
+ const current3 = fileExists ? readFileSync41(fullPath, "utf-8") : null;
66607
66959
  if (eventType !== "rename" && current3 !== null && lastSeenContent.get(fullPath) === current3) {
66608
66960
  LOG.info(`skipped unchanged (${filename})`);
66609
66961
  return;
@@ -66635,7 +66987,7 @@ async function startDevServer(port, projectDir, config, host) {
66635
66987
  } else if (fileExists && current3 !== null) {
66636
66988
  let source = current3;
66637
66989
  if (/content=["'][^"']*\.md["']/i.test(source)) {
66638
- source = inlineMdContentAttrs2(source, dirname26(fullPath), guessProjectRoots2(appDirPath));
66990
+ source = inlineMdContentAttrs2(source, dirname27(fullPath), guessProjectRoots2(appDirPath));
66639
66991
  }
66640
66992
  const { comp, name } = compileClientBoth2(source, null, fullPath, { skipHyd: true });
66641
66993
  hotEditedSource = buildHmrEvalSnippet2(comp);
@@ -66662,7 +67014,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66662
67014
  if (compCode.trim()) fnSources = { _raw: compCode };
66663
67015
  } else if (fileExists && !bundleError) {
66664
67016
  try {
66665
- const src2 = readFileSync40(fullPath, "utf-8");
67017
+ const src2 = readFileSync41(fullPath, "utf-8");
66666
67018
  let compCode = buildHmrEvalSnippet2(
66667
67019
  compileClient2(src2, null, { forceClient: true, sourcePath: fullPath, mdRoots: [projectDir] })
66668
67020
  );
@@ -66746,7 +67098,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66746
67098
  cssDebounceTimer = setTimeout(async () => {
66747
67099
  try {
66748
67100
  if (fileExists) {
66749
- rawCss = readFileSync40(fullPath, "utf-8");
67101
+ rawCss = readFileSync41(fullPath, "utf-8");
66750
67102
  }
66751
67103
  const cssChanged = await rebuildTailwindCss();
66752
67104
  if (cssChanged && typeof globalThis.__vesk_broadcastHmr === "function") {
@@ -66776,7 +67128,8 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66776
67128
  }
66777
67129
  }, HMR_DEBOUNCE_MS);
66778
67130
  }
66779
- });
67131
+ };
67132
+ watchDirTree(watchDir);
66780
67133
  } catch (e) {
66781
67134
  LOG.warn("file watching unavailable, serving without auto-rebuild");
66782
67135
  }
@@ -66793,9 +67146,9 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66793
67146
  ".json": "application/json",
66794
67147
  ".webmanifest": "application/manifest+json"
66795
67148
  };
66796
- const hmrJsPath = join27(runtimeDir, "hmr-client.js");
66797
- const hmrTsPath = join27(runtimeDir, "hmr-client.ts");
66798
- const hmrClientPath = existsSync42(hmrJsPath) ? hmrJsPath : existsSync42(hmrTsPath) ? hmrTsPath : null;
67149
+ const hmrJsPath = join28(runtimeDir, "hmr-client.js");
67150
+ const hmrTsPath = join28(runtimeDir, "hmr-client.ts");
67151
+ const hmrClientPath = existsSync43(hmrJsPath) ? hmrJsPath : existsSync43(hmrTsPath) ? hmrTsPath : null;
66799
67152
  function extractCompName2(src2) {
66800
67153
  return resolveComponentName(src2);
66801
67154
  }
@@ -66860,6 +67213,11 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66860
67213
  res.end(runtimeBundle);
66861
67214
  return;
66862
67215
  }
67216
+ if (url.pathname === "/_vesk/dev-config.js") {
67217
+ res.writeHead(200, { "Content-Type": "application/javascript", "Cache-Control": "no-store" });
67218
+ res.end("globalThis.__vesk_chunk_timeout_ms = 120000;");
67219
+ return;
67220
+ }
66863
67221
  if (url.pathname === "/_vesk/client" || url.pathname === "/_vesk/client.js") {
66864
67222
  res.writeHead(200, { "Content-Type": "application/javascript" });
66865
67223
  res.end(clientBundle);
@@ -66903,7 +67261,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66903
67261
  }
66904
67262
  if (url.pathname === "/_vesk/hmr" || url.pathname === "/_vesk/hmr.js") {
66905
67263
  if (hmrClientPath) {
66906
- let hmrContent = readFileSync40(hmrClientPath, "utf-8");
67264
+ let hmrContent = readFileSync41(hmrClientPath, "utf-8");
66907
67265
  if (hmrClientPath.endsWith(".ts")) {
66908
67266
  hmrContent = stripCodeTypes2(hmrContent);
66909
67267
  }
@@ -66951,10 +67309,10 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66951
67309
  }
66952
67310
  if (url.pathname !== "/") {
66953
67311
  const staticPath = url.pathname.length > 1 ? resolveWithin2(publicDir, url.pathname.slice(1)) : null;
66954
- if (staticPath && existsSync42(staticPath) && statSync22(staticPath).isFile()) {
67312
+ if (staticPath && existsSync43(staticPath) && statSync22(staticPath).isFile()) {
66955
67313
  const ext = extname7(staticPath);
66956
67314
  res.writeHead(200, { "Content-Type": MIME2[ext] || "application/octet-stream" });
66957
- res.end(readFileSync40(staticPath));
67315
+ res.end(readFileSync41(staticPath));
66958
67316
  return;
66959
67317
  }
66960
67318
  }
@@ -66978,8 +67336,8 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
66978
67336
  return;
66979
67337
  }
66980
67338
  const mwChain = collectMiddlewareChain(routeTree, url.pathname, appDirPath);
66981
- const apiDirPath = join27(appDirPath, "api");
66982
- if (url.pathname.startsWith("/api") && existsSync42(apiDirPath)) {
67339
+ const apiDirPath = join28(appDirPath, "api");
67340
+ if (url.pathname.startsWith("/api") && existsSync43(apiDirPath)) {
66983
67341
  const apiRoutes = await scanApiRoutes(apiDirPath);
66984
67342
  const apiMatch = matchApiUrl(apiRoutes, req.url || url.pathname);
66985
67343
  if (apiMatch) {
@@ -67016,7 +67374,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67016
67374
  });
67017
67375
  if (mwResult.response) {
67018
67376
  logRequest(mwResult.response.status);
67019
- res.writeHead(mwResult.response.status, Object.fromEntries(mwResult.response.headers));
67377
+ res.writeHead(mwResult.response.status, toNodeHeaders2(mwResult.response));
67020
67378
  res.end(await mwResult.response.text());
67021
67379
  return;
67022
67380
  }
@@ -67043,7 +67401,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67043
67401
  }
67044
67402
  logRequest(response.status);
67045
67403
  const body = await response.text();
67046
- res.writeHead(response.status, Object.fromEntries(response.headers));
67404
+ res.writeHead(response.status, toNodeHeaders2(response));
67047
67405
  res.end(body);
67048
67406
  return;
67049
67407
  }
@@ -67051,22 +67409,19 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67051
67409
  const ctx2 = rawCtx;
67052
67410
  const match = matchUrl(routeTree, url.pathname);
67053
67411
  if (!match) {
67054
- const rootNode = routeTree.find((n) => n.fullPath === "/");
67055
67412
  let notFoundHtml = null;
67056
- if (rootNode && rootNode.notFound) {
67057
- const nfPath = resolve38(appDirPath, rootNode.sourceDir, "not-found.vsk");
67058
- if (existsSync42(nfPath)) {
67059
- try {
67060
- const nfSrc = readFileSync40(nfPath, "utf-8");
67061
- const nfCompName = extractCompName2(nfSrc) || rootNode.notFound;
67062
- notFoundHtml = await renderFullPage(nfSrc, nfCompName, { params: {}, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, cached: cachedSsrCompile(ssrCompileCache, nfSrc, nfPath), plugins: getActiveDevPlugins() });
67063
- } catch {
67064
- }
67413
+ const nfPath = resolveBoundaryFileForUrl2(url.pathname, appDirPath, "not-found.vsk");
67414
+ if (nfPath) {
67415
+ try {
67416
+ const nfSrc = readFileSync41(nfPath, "utf-8");
67417
+ const nfCompName = extractCompName2(nfSrc) || "NotFound";
67418
+ notFoundHtml = await renderFullPage(nfSrc, nfCompName, { params: {}, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, cached: cachedSsrCompile(ssrCompileCache, nfSrc, nfPath), plugins: getActiveDevPlugins() });
67419
+ } catch {
67065
67420
  }
67066
67421
  }
67067
67422
  logRequest(404);
67068
67423
  res.writeHead(404, { "Content-Type": "text/html" });
67069
- res.end(notFoundHtml || renderDefaultNotFoundPage2({ url: url.pathname }));
67424
+ res.end(notFoundHtml ? injectDevScripts(notFoundHtml) : renderDefaultNotFoundPage2({ url: url.pathname }));
67070
67425
  return;
67071
67426
  }
67072
67427
  const urlParts = url.pathname.split("/").filter(Boolean);
@@ -67086,16 +67441,6 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67086
67441
  }
67087
67442
  const matched = match;
67088
67443
  const forData = req.headers["x-vesk-data"] === "1";
67089
- if (!forData && matched && Array.isArray(matched.nodes)) {
67090
- const leaf2 = matched.nodes.find((n) => n.page);
67091
- if (leaf2 && typeof leaf2.fullPath === "string") {
67092
- try {
67093
- await ensureRouteChunk(leaf2.fullPath);
67094
- } catch (e) {
67095
- LOG.err(`client chunk build failed for ${leaf2.fullPath}:`, e.message);
67096
- }
67097
- }
67098
- }
67099
67444
  async function renderSSR() {
67100
67445
  const ssg2 = globalThis;
67101
67446
  ssg2.__vsk_ssr_data = {};
@@ -67109,18 +67454,18 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67109
67454
  let props;
67110
67455
  for (let i = chain.length - 1; i >= 0; i--) {
67111
67456
  const node = chain[i];
67112
- const pageFilePath = resolve38(appDirPath, node.sourceDir, "page.vsk");
67113
- const layoutFilePath = resolve38(appDirPath, node.sourceDir, "layout.vsk");
67114
- if (i === chain.length - 1 && node.page && existsSync42(pageFilePath)) {
67115
- const src2 = readFileSync40(pageFilePath, "utf-8");
67457
+ const pageFilePath = resolve39(appDirPath, node.sourceDir, "page.vsk");
67458
+ const layoutFilePath = resolve39(appDirPath, node.sourceDir, "layout.vsk");
67459
+ if (i === chain.length - 1 && node.page && existsSync43(pageFilePath)) {
67460
+ const src2 = readFileSync41(pageFilePath, "utf-8");
67116
67461
  const compName = extractCompName2(src2) || node.page;
67117
67462
  const result = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, pageFilePath) });
67118
67463
  body = result.body;
67119
67464
  head = result.head || "";
67120
67465
  props = result.props;
67121
67466
  }
67122
- if (node.layout && existsSync42(layoutFilePath)) {
67123
- const src2 = readFileSync40(layoutFilePath, "utf-8");
67467
+ if (node.layout && existsSync43(layoutFilePath)) {
67468
+ const src2 = readFileSync41(layoutFilePath, "utf-8");
67124
67469
  const compName = extractCompName2(src2) || node.layout;
67125
67470
  const result = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, layoutFilePath) });
67126
67471
  body = result.body;
@@ -67130,7 +67475,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67130
67475
  if (forData) {
67131
67476
  return { html: "", props: props || { params: matched.params }, head };
67132
67477
  }
67133
- const hasLayout = chain.some((n) => n.layout && existsSync42(resolve38(appDirPath, n.sourceDir, "layout.vsk")));
67478
+ const hasLayout = chain.some((n) => n.layout && existsSync43(resolve39(appDirPath, n.sourceDir, "layout.vsk")));
67134
67479
  let html;
67135
67480
  if (hasLayout) {
67136
67481
  const ssrData = currentSsrData();
@@ -67165,9 +67510,9 @@ ${prettifyHtml(body)}
67165
67510
  } else {
67166
67511
  const leaf2 = chain.find((n) => n.page);
67167
67512
  if (leaf2) {
67168
- const src2 = readFileSync40(resolve38(appDirPath, leaf2.sourceDir, "page.vsk"), "utf-8");
67513
+ const src2 = readFileSync41(resolve39(appDirPath, leaf2.sourceDir, "page.vsk"), "utf-8");
67169
67514
  const compName = extractCompName2(src2) || leaf2.page;
67170
- html = await renderFullPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve38(appDirPath, leaf2.sourceDir, "page.vsk"), cached: cachedSsrCompile(ssrCompileCache, src2, resolve38(appDirPath, leaf2.sourceDir, "page.vsk")), plugins: getActiveDevPlugins() });
67515
+ html = await renderFullPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve39(appDirPath, leaf2.sourceDir, "page.vsk"), cached: cachedSsrCompile(ssrCompileCache, src2, resolve39(appDirPath, leaf2.sourceDir, "page.vsk")), plugins: getActiveDevPlugins() });
67171
67516
  html = html.replace("</body>", ' <script type="module" src="/_vesk/hmr.js"></script>\n</body>');
67172
67517
  html = await applyHtmlPlugins(html, getActiveDevPlugins(), { sourcePath: url.pathname });
67173
67518
  } else {
@@ -67190,13 +67535,13 @@ ${prettifyHtml(body)}
67190
67535
  sst.__vsk_ssr_data = {};
67191
67536
  async function* raw2() {
67192
67537
  const chain = cleanChain;
67193
- const hasLayout = chain.some((n) => n.layout && existsSync42(resolve38(appDirPath, n.sourceDir, "layout.vsk")));
67538
+ const hasLayout = chain.some((n) => n.layout && existsSync43(resolve39(appDirPath, n.sourceDir, "layout.vsk")));
67194
67539
  if (!hasLayout) {
67195
67540
  const leaf2 = chain.find((n) => n.page);
67196
67541
  if (leaf2) {
67197
- const src2 = readFileSync40(resolve38(appDirPath, leaf2.sourceDir, "page.vsk"), "utf-8");
67542
+ const src2 = readFileSync41(resolve39(appDirPath, leaf2.sourceDir, "page.vsk"), "utf-8");
67198
67543
  const compName = extractCompName2(src2) || leaf2.page;
67199
- yield* renderPageStream(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve38(appDirPath, leaf2.sourceDir, "page.vsk"), cached: cachedSsrCompile(ssrCompileCache, src2, resolve38(appDirPath, leaf2.sourceDir, "page.vsk")), plugins: getActiveDevPlugins() });
67544
+ yield* renderPageStream(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve39(appDirPath, leaf2.sourceDir, "page.vsk"), cached: cachedSsrCompile(ssrCompileCache, src2, resolve39(appDirPath, leaf2.sourceDir, "page.vsk")), plugins: getActiveDevPlugins() });
67200
67545
  } else {
67201
67546
  throw new Error("No page or layout matched");
67202
67547
  }
@@ -67207,18 +67552,18 @@ ${prettifyHtml(body)}
67207
67552
  let props;
67208
67553
  for (let i = chain.length - 1; i >= 0; i--) {
67209
67554
  const node = chain[i];
67210
- const pageFilePath = resolve38(appDirPath, node.sourceDir, "page.vsk");
67211
- const layoutFilePath = resolve38(appDirPath, node.sourceDir, "layout.vsk");
67212
- if (i === chain.length - 1 && node.page && existsSync42(pageFilePath)) {
67213
- const src2 = readFileSync40(pageFilePath, "utf-8");
67555
+ const pageFilePath = resolve39(appDirPath, node.sourceDir, "page.vsk");
67556
+ const layoutFilePath = resolve39(appDirPath, node.sourceDir, "layout.vsk");
67557
+ if (i === chain.length - 1 && node.page && existsSync43(pageFilePath)) {
67558
+ const src2 = readFileSync41(pageFilePath, "utf-8");
67214
67559
  const compName = extractCompName2(src2) || node.page;
67215
67560
  const result = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, pageFilePath) });
67216
67561
  body = result.body;
67217
67562
  head = result.head || "";
67218
67563
  props = result.props;
67219
67564
  }
67220
- if (node.layout && existsSync42(layoutFilePath)) {
67221
- const src2 = readFileSync40(layoutFilePath, "utf-8");
67565
+ if (node.layout && existsSync43(layoutFilePath)) {
67566
+ const src2 = readFileSync41(layoutFilePath, "utf-8");
67222
67567
  const compName = extractCompName2(src2) || node.layout;
67223
67568
  const result = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, layoutFilePath) });
67224
67569
  body = result.body;
@@ -67312,7 +67657,7 @@ ${prettifyHtml(body)}
67312
67657
  const respRecord = mwResult.response;
67313
67658
  if (typeof respRecord.build === "function") respRecord.build();
67314
67659
  logRequest(mwResult.response.status);
67315
- res.writeHead(mwResult.response.status, Object.fromEntries(mwResult.response.headers));
67660
+ res.writeHead(mwResult.response.status, toNodeHeaders2(mwResult.response));
67316
67661
  res.end(await mwResult.response.text());
67317
67662
  return;
67318
67663
  }
@@ -67359,10 +67704,10 @@ ${prettifyHtml(body)}
67359
67704
  for (let i = match.nodes.length - 1; i >= 0; i--) {
67360
67705
  const node = match.nodes[i];
67361
67706
  if (node.notFound) {
67362
- const nfPath = resolve38(appDirPath, node.sourceDir, "not-found.vsk");
67363
- if (existsSync42(nfPath)) {
67707
+ const nfPath = resolve39(appDirPath, node.sourceDir, "not-found.vsk");
67708
+ if (existsSync43(nfPath)) {
67364
67709
  try {
67365
- const nfSrc = readFileSync40(nfPath, "utf-8");
67710
+ const nfSrc = readFileSync41(nfPath, "utf-8");
67366
67711
  const nfCompName = extractCompName2(nfSrc) || node.notFound;
67367
67712
  const html = await renderFullPage(nfSrc, nfCompName, { params: match.params, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, cached: cachedSsrCompile(ssrCompileCache, nfSrc, nfPath), plugins: getActiveDevPlugins() });
67368
67713
  notFoundHtml = injectDevScripts(html);
@@ -67405,10 +67750,10 @@ ${prettifyHtml(body)}
67405
67750
  for (let i = match.nodes.length - 1; i >= 0; i--) {
67406
67751
  const node = match.nodes[i];
67407
67752
  if (node.error) {
67408
- const errPath = resolve38(appDirPath, node.sourceDir, "error.vsk");
67409
- if (existsSync42(errPath)) {
67753
+ const errPath = resolve39(appDirPath, node.sourceDir, "error.vsk");
67754
+ if (existsSync43(errPath)) {
67410
67755
  try {
67411
- const errSrc = readFileSync40(errPath, "utf-8");
67756
+ const errSrc = readFileSync41(errPath, "utf-8");
67412
67757
  const errCompName = extractCompName2(errSrc) || node.error;
67413
67758
  const errProps = {
67414
67759
  error: err.message,
@@ -67480,7 +67825,7 @@ ${prettifyHtml(body)}
67480
67825
  LOG.ok(`dev server at http://localhost:${port} (listening on ${bindHost})`);
67481
67826
  const routes = collectRoutePaths(routeTree);
67482
67827
  const pageCount = countPages(routeTree);
67483
- const apiCount = countFilesNamed(join27(appDirPath, "api"), "route.ts");
67828
+ const apiCount = countFilesNamed(join28(appDirPath, "api"), "route.ts");
67484
67829
  LOG.info(`${projectDir}`);
67485
67830
  LOG.info(`${pageCount} page${pageCount === 1 ? "" : "s"}: ${routes.join(", ") || "(none)"}`);
67486
67831
  if (apiCount > 0) LOG.info(`${apiCount} api route${apiCount === 1 ? "" : "s"} (app/api)`);
@@ -67762,7 +68107,8 @@ init_path_store();
67762
68107
 
67763
68108
  // src/index.ts
67764
68109
  var __filename2 = fileURLToPath9(import.meta.url);
67765
- var __dirname10 = resolve40(__filename2, "..");
68110
+ var __dirname10 = resolve41(__filename2, "..");
68111
+ var requireFromCli = createRequire8(import.meta.url);
67766
68112
  var args = process.argv.slice(2);
67767
68113
  var cmd = args[0];
67768
68114
  function usage(code = 0) {
@@ -67807,12 +68153,12 @@ if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
67807
68153
  }
67808
68154
  function loadEnvFiles(projectDir) {
67809
68155
  const files = [
67810
- join31(projectDir, ".env"),
67811
- join31(projectDir, ".env.local")
68156
+ join32(projectDir, ".env"),
68157
+ join32(projectDir, ".env.local")
67812
68158
  ];
67813
68159
  for (const filePath of files) {
67814
- if (!existsSync45(filePath)) continue;
67815
- const content = readFileSync44(filePath, "utf-8");
68160
+ if (!existsSync46(filePath)) continue;
68161
+ const content = readFileSync45(filePath, "utf-8");
67816
68162
  for (const line of content.split("\n")) {
67817
68163
  const trimmed = line.trim();
67818
68164
  if (!trimmed || trimmed.startsWith("#")) continue;
@@ -67845,16 +68191,39 @@ async function loadConfig(projectDir) {
67845
68191
  function resolveProjectDirs(projectDir, config) {
67846
68192
  const cfg = config || {};
67847
68193
  return {
67848
- appDir: resolve40(projectDir, typeof cfg.appDir === "string" ? cfg.appDir : "./app"),
67849
- publicDir: resolve40(projectDir, typeof cfg.publicDir === "string" ? cfg.publicDir : "./public"),
67850
- outDir: resolve40(projectDir, typeof cfg.outDir === "string" ? cfg.outDir : ".vesk")
68194
+ appDir: resolve41(projectDir, typeof cfg.appDir === "string" ? cfg.appDir : "./app"),
68195
+ publicDir: resolve41(projectDir, typeof cfg.publicDir === "string" ? cfg.publicDir : "./public"),
68196
+ outDir: resolve41(projectDir, typeof cfg.outDir === "string" ? cfg.outDir : ".vesk")
67851
68197
  };
67852
68198
  }
68199
+ async function typecheckBeforeBuild(projectDir) {
68200
+ if (!existsSync46(join32(projectDir, "tsconfig.json"))) return;
68201
+ let tscPath;
68202
+ try {
68203
+ tscPath = requireFromCli.resolve("typescript/bin/tsc", { paths: [projectDir] });
68204
+ } catch {
68205
+ console.error("vesk build: typecheck skipped \u2014 TypeScript is not installed in this project.");
68206
+ return;
68207
+ }
68208
+ console.error("vesk build: typechecking...");
68209
+ const exitCode = await new Promise((resolveExit) => {
68210
+ const child = spawn3(process.execPath, [tscPath, "--noEmit", "-p", projectDir], {
68211
+ cwd: projectDir,
68212
+ stdio: "inherit"
68213
+ });
68214
+ child.on("error", () => resolveExit(1));
68215
+ child.on("close", (code) => resolveExit(code ?? 1));
68216
+ });
68217
+ if (exitCode !== 0) {
68218
+ console.error("vesk build: typecheck failed \u2014 fix the errors above and build again.");
68219
+ process.exit(1);
68220
+ }
68221
+ }
67853
68222
  if (cmd === "build") {
67854
68223
  const projectDir = process.cwd();
67855
68224
  const rawConfig = await loadConfig(projectDir) || {};
67856
68225
  const { appDir: appDirPath, publicDir, outDir } = resolveProjectDirs(projectDir, rawConfig);
67857
- if (!existsSync45(appDirPath)) {
68226
+ if (!existsSync46(appDirPath)) {
67858
68227
  console.error(`vesk build: no app directory found in ${projectDir} (config appDir: ${rawConfig.appDir ?? "./app"})`);
67859
68228
  process.exit(1);
67860
68229
  }
@@ -67874,6 +68243,7 @@ if (cmd === "build") {
67874
68243
  if (platform) opts.platform = platform;
67875
68244
  if (config.ssg !== void 0 && config.ssg !== false) opts.ssg = true;
67876
68245
  try {
68246
+ await typecheckBeforeBuild(projectDir);
67877
68247
  await build2(appDirPath, opts);
67878
68248
  const { drainMdHtmlWarnings: drainMdHtmlWarnings3 } = await Promise.resolve().then(() => (init_md2(), md_exports2));
67879
68249
  const drained = drainMdHtmlWarnings3();
@@ -67928,7 +68298,7 @@ ${frame}`;
67928
68298
  if (cmd === "seo") {
67929
68299
  const projectDir = process.cwd();
67930
68300
  const { appDir: appDirPath } = resolveProjectDirs(projectDir, await loadConfig(projectDir) || {});
67931
- if (!existsSync45(appDirPath)) {
68301
+ if (!existsSync46(appDirPath)) {
67932
68302
  console.error(`vesk seo: no app directory found in ${projectDir}`);
67933
68303
  process.exit(1);
67934
68304
  }
@@ -67943,7 +68313,7 @@ if (cmd === "seo") {
67943
68313
  if (cmd === "typecheck") {
67944
68314
  const projectDir = process.cwd();
67945
68315
  const { appDir: appDirPath } = resolveProjectDirs(projectDir, await loadConfig(projectDir) || {});
67946
- if (!existsSync45(appDirPath)) {
68316
+ if (!existsSync46(appDirPath)) {
67947
68317
  console.error(`vesk typecheck: no app directory found in ${projectDir}`);
67948
68318
  process.exit(1);
67949
68319
  }
@@ -67970,7 +68340,7 @@ if (cmd === "start") {
67970
68340
  const { outDir } = resolveProjectDirs(projectDir, await loadConfig(projectDir) || {});
67971
68341
  const port = parsePortArg(args);
67972
68342
  const host = parseHostArg(args);
67973
- if (!existsSync45(outDir)) {
68343
+ if (!existsSync46(outDir)) {
67974
68344
  console.error(`vesk start: no build found at ${outDir} \u2014 run "vesk build" first.`);
67975
68345
  process.exit(1);
67976
68346
  }
@@ -67981,8 +68351,8 @@ if (cmd === "start") {
67981
68351
  if (cmd === "init") {
67982
68352
  const projectDir = process.cwd();
67983
68353
  const { appDir: appDirPath } = resolveProjectDirs(projectDir, await loadConfig(projectDir) || {});
67984
- const target = join31(appDirPath, "global.css");
67985
- if (existsSync45(target)) {
68354
+ const target = join32(appDirPath, "global.css");
68355
+ if (existsSync46(target)) {
67986
68356
  console.error(`vesk init: ${target} already exists \u2014 skipping`);
67987
68357
  process.exit(0);
67988
68358
  }
@@ -68002,7 +68372,7 @@ if (cmd === "migrate") {
68002
68372
  const projectDir = process.cwd();
68003
68373
  const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
68004
68374
  const { CODEMODS: CODEMODS2 } = await Promise.resolve().then(() => (init_codemods(), codemods_exports));
68005
- const { version: cliVersion } = JSON.parse(readFileSync44(join31(__dirname10, "..", "package.json"), "utf-8"));
68375
+ const { version: cliVersion } = JSON.parse(readFileSync45(join32(__dirname10, "..", "package.json"), "utf-8"));
68006
68376
  if (args.includes("--list")) {
68007
68377
  console.error("vesk migrate: available codemods");
68008
68378
  for (const c of CODEMODS2) {
@@ -68044,7 +68414,7 @@ if (cmd === "dev") {
68044
68414
  const { appDir: appDirPath, publicDir } = resolveProjectDirs(projectDir, await loadConfig(projectDir) || {});
68045
68415
  const port = parsePortArg(args);
68046
68416
  const host = parseHostArg(args);
68047
- if (!existsSync45(appDirPath)) {
68417
+ if (!existsSync46(appDirPath)) {
68048
68418
  console.error(`vesk: no app/ directory found in ${projectDir}`);
68049
68419
  console.error('Run "npx create-vesk@latest <project-name>" first');
68050
68420
  process.exit(1);