@vesk/vesk-cli 0.2.8 → 0.2.10

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 +1952 -630
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -1605,8 +1605,11 @@ function buildRequestInit(options2) {
1605
1605
  }
1606
1606
  function resolveFetchUrl(url) {
1607
1607
  if (/^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("//")) return url;
1608
- const reqUrl = g().__vesk_request?.url;
1609
- const base = typeof reqUrl === "string" && /^https?:\/\//i.test(reqUrl) ? reqUrl : g().__vesk_ssr_base_url || "";
1608
+ const ctx2 = g().__vesk_request;
1609
+ const resolver = ctx2 && typeof ctx2.resolveUrl === "function" ? ctx2.resolveUrl : null;
1610
+ if (resolver) return resolver(url);
1611
+ const reqUrl = ctx2?.url;
1612
+ const base = typeof reqUrl === "string" && /^https?:\/\//i.test(reqUrl) ? reqUrl : globalThis.__vesk_ssr_base_url || "";
1610
1613
  if (base) return new URL(url, base).href;
1611
1614
  return url;
1612
1615
  }
@@ -1666,7 +1669,34 @@ async function runFetcher(handle2, timeout) {
1666
1669
  }
1667
1670
  }
1668
1671
  function sleep(ms) {
1669
- return new Promise((resolve26) => setTimeout(resolve26, ms));
1672
+ return new Promise((resolve27) => setTimeout(resolve27, ms));
1673
+ }
1674
+ function streamText(res, into, onChunk) {
1675
+ const decoder = new TextDecoder();
1676
+ let total = "";
1677
+ const emit = (text) => {
1678
+ if (!text) return;
1679
+ total += text;
1680
+ if (into) setInto(into, total);
1681
+ if (onChunk) onChunk(text, total);
1682
+ };
1683
+ const body = res.body;
1684
+ if (body && typeof body.getReader === "function") {
1685
+ const reader = body.getReader();
1686
+ return (async () => {
1687
+ for (; ; ) {
1688
+ const { done, value } = await reader.read();
1689
+ if (done) break;
1690
+ emit(decoder.decode(value, { stream: true }));
1691
+ }
1692
+ emit(decoder.decode());
1693
+ return total;
1694
+ })();
1695
+ }
1696
+ return res.text().then((text) => {
1697
+ emit(text);
1698
+ return total;
1699
+ });
1670
1700
  }
1671
1701
  function settle(handle2, data2) {
1672
1702
  if (handle2.block !== null && is_destroyed(handle2.block)) return;
@@ -1959,6 +1989,22 @@ var init_resource = __esm({
1959
1989
  ...options2,
1960
1990
  key: options2?.key ?? url
1961
1991
  });
1992
+ useFetch.stream = (urlOrFn, options2) => {
1993
+ const streamInto = options2?.into;
1994
+ const streamOnChunk = options2?.onChunk;
1995
+ const fetcher = (signal) => {
1996
+ const url = typeof urlOrFn === "function" ? urlOrFn() : urlOrFn;
1997
+ const init = buildRequestInit(options2 ?? {});
1998
+ return doFetch(resolveFetchUrl(url), signal ? { ...init, signal } : init).then(async (res) => {
1999
+ if (!res.ok) throw new HttpError(res.status, res.statusText);
2000
+ return streamText(res, streamInto, streamOnChunk);
2001
+ });
2002
+ };
2003
+ const key = options2?.key ?? (typeof urlOrFn === "string" ? urlOrFn : void 0);
2004
+ const resource = useFetch(fetcher, { ...options2, key });
2005
+ resource.into = streamInto;
2006
+ return resource;
2007
+ };
1962
2008
  }
1963
2009
  });
1964
2010
 
@@ -2032,10 +2078,10 @@ function createHydrateWalker(container, markerList) {
2032
2078
  }
2033
2079
  function hydrateViewport(container, componentFn, props, rootMargin = 500) {
2034
2080
  if (document.readyState !== "complete") {
2035
- return new Promise((resolve26) => {
2081
+ return new Promise((resolve27) => {
2036
2082
  const onLoad = () => {
2037
2083
  window.removeEventListener("load", onLoad);
2038
- resolve26(hydrateViewport(container, componentFn, props, rootMargin));
2084
+ resolve27(hydrateViewport(container, componentFn, props, rootMargin));
2039
2085
  };
2040
2086
  window.addEventListener("load", onLoad);
2041
2087
  });
@@ -2062,7 +2108,7 @@ function hydrateViewport(container, componentFn, props, rootMargin = 500) {
2062
2108
  const viewportWalker = createHydrateWalker(container, viewportMarkers);
2063
2109
  componentFn(props || {}, /* @__PURE__ */ new Map(), viewportWalker);
2064
2110
  if (deferredMarkers.length > 0) {
2065
- return new Promise((resolve26) => {
2111
+ return new Promise((resolve27) => {
2066
2112
  const observer = new IntersectionObserver((entries) => {
2067
2113
  const toHydrate = [];
2068
2114
  for (const entry of entries) {
@@ -2085,7 +2131,7 @@ function hydrateViewport(container, componentFn, props, rootMargin = 500) {
2085
2131
  }
2086
2132
  if (observer._observed === 0) {
2087
2133
  observer.disconnect();
2088
- resolve26();
2134
+ resolve27();
2089
2135
  }
2090
2136
  }, { rootMargin: `${rootMargin}px` });
2091
2137
  observer._observed = deferredMarkers.length;
@@ -2308,9 +2354,9 @@ function startProgress() {
2308
2354
  const step = () => {
2309
2355
  rafId = null;
2310
2356
  if (!animating || isServer2()) return;
2311
- const ts8 = now();
2312
- if (startTimeStamp === null) startTimeStamp = ts8;
2313
- const pct = globalOpts.estimatedProgress(globalOpts.duration, ts8 - startTimeStamp);
2357
+ const ts9 = now();
2358
+ if (startTimeStamp === null) startTimeStamp = ts9;
2359
+ const pct = globalOpts.estimatedProgress(globalOpts.duration, ts9 - startTimeStamp);
2314
2360
  set(progressCell, Math.max(0, Math.min(100, pct)));
2315
2361
  rafId = setTimeout(step, 16);
2316
2362
  };
@@ -2948,12 +2994,12 @@ function ensureChunk(chunkUrl) {
2948
2994
  if (typeof document === "undefined" || typeof document.createElement !== "function") {
2949
2995
  return Promise.resolve();
2950
2996
  }
2951
- return new Promise((resolve26, reject) => {
2997
+ return new Promise((resolve27, reject) => {
2952
2998
  const s = document.createElement("script");
2953
2999
  s.src = chunkUrl;
2954
3000
  s.onload = () => {
2955
3001
  failedChunks.delete(chunkUrl);
2956
- resolve26();
3002
+ resolve27();
2957
3003
  };
2958
3004
  s.onerror = () => {
2959
3005
  loadedChunks.delete(chunkUrl);
@@ -15289,6 +15335,15 @@ function isIdentStartCode(code) {
15289
15335
  function isIdentCharCode(code) {
15290
15336
  return isIdentStartCode(code) || code >= 48 && code <= 57;
15291
15337
  }
15338
+ function getQualifiedJSXName2(object) {
15339
+ if (!object) return object;
15340
+ if (object.type === "JSXIdentifier") return object.name;
15341
+ if (object.type === "JSXNamespacedName") return object.namespace.name + ":" + object.name.name;
15342
+ if (object.type === "JSXMemberExpression") {
15343
+ return getQualifiedJSXName2(object.object) + "." + getQualifiedJSXName2(object.property);
15344
+ }
15345
+ return null;
15346
+ }
15292
15347
  function looksLikeGenericArrowAt(input, pos) {
15293
15348
  let i = pos + 1;
15294
15349
  while (i < input.length && isWsChar(input.charCodeAt(i))) i++;
@@ -15372,6 +15427,9 @@ function VeskParserPlugin(config = {}) {
15372
15427
  #closeTagName = null;
15373
15428
  #jsxStartsStatement = false;
15374
15429
  #inTSTypeDecl = false;
15430
+ #pendingChildStatement = false;
15431
+ /** per-statement context-stack depths (LIFO — child statements may nest) */
15432
+ #jsxChildDepthStack = [];
15375
15433
  constructor(options2, input) {
15376
15434
  super(options2, input);
15377
15435
  }
@@ -15379,7 +15437,231 @@ function VeskParserPlugin(config = {}) {
15379
15437
  const ctx2 = this.curContext();
15380
15438
  return ctx2 && (ctx2.token === "{" || ctx2.token === "function");
15381
15439
  }
15440
+ #isJsxChildrenContext() {
15441
+ const ctx2 = this.curContext();
15442
+ return !!ctx2 && ctx2.token === "<tag>...</tag>";
15443
+ }
15444
+ /**
15445
+ * Determines whether the text starting at `this.pos` opens a
15446
+ * statement-mode control-flow header (`if (`, `for (`, `while (`,
15447
+ * `switch (`, `try {`, `do {`) among JSX children. Scans chars only —
15448
+ * the paren body must balance and be followed by a `{` block.
15449
+ */
15450
+ #scansChildStatement() {
15451
+ const input = this.input;
15452
+ let i = this.pos;
15453
+ while (i < input.length && isWsChar(input.charCodeAt(i))) i++;
15454
+ if (i >= input.length || !isIdentStartCode(input.charCodeAt(i))) return false;
15455
+ const wordStart = i;
15456
+ while (i < input.length && isIdentCharCode(input.charCodeAt(i))) i++;
15457
+ const word = input.slice(wordStart, i);
15458
+ if (word === "const" || word === "let" || word === "var") {
15459
+ let depth2 = 0;
15460
+ let seenAssign = false;
15461
+ let q2 = i;
15462
+ while (q2 < input.length) {
15463
+ const c = input.charCodeAt(q2);
15464
+ if (c === 34 || c === 39 || c === 96) {
15465
+ const quote = c;
15466
+ let tplDepth = 0;
15467
+ q2++;
15468
+ while (q2 < input.length) {
15469
+ const ch = input.charCodeAt(q2);
15470
+ if (ch === 92) {
15471
+ q2 += 2;
15472
+ continue;
15473
+ }
15474
+ if (quote === 96 && ch === 36 && input.charCodeAt(q2 + 1) === 123) {
15475
+ tplDepth++;
15476
+ q2 += 2;
15477
+ continue;
15478
+ }
15479
+ if (quote === 96 && ch === 125 && tplDepth > 0) {
15480
+ tplDepth--;
15481
+ q2++;
15482
+ continue;
15483
+ }
15484
+ if (ch === quote && tplDepth === 0) {
15485
+ q2++;
15486
+ break;
15487
+ }
15488
+ q2++;
15489
+ }
15490
+ continue;
15491
+ }
15492
+ if (c === 60 && input.charCodeAt(q2 + 1) === 47) return false;
15493
+ if (c === 40 || c === 91 || c === 123) depth2++;
15494
+ else if (c === 41 || c === 93 || c === 125) depth2--;
15495
+ else if (c === 61 && depth2 === 0) {
15496
+ const n2 = input.charCodeAt(q2 + 1);
15497
+ const n1 = q2 > 0 ? input.charCodeAt(q2 - 1) : 0;
15498
+ if (n2 !== 61 && n2 !== 62 && n1 !== 33 && n1 !== 60 && n1 !== 61) seenAssign = true;
15499
+ } else if (c === 59 && depth2 === 0) return true;
15500
+ else if ((c === 10 || c === 13) && depth2 === 0 && seenAssign) return true;
15501
+ q2++;
15502
+ }
15503
+ return false;
15504
+ }
15505
+ if (isIdentStartCode(input.charCodeAt(wordStart))) {
15506
+ let q2 = i;
15507
+ while (q2 < input.length) {
15508
+ const c = input.charCodeAt(q2);
15509
+ if (c === 46) {
15510
+ q2++;
15511
+ } else if (c === 63 && input.charCodeAt(q2 + 1) === 46) {
15512
+ q2 += 2;
15513
+ } else break;
15514
+ if (q2 >= input.length || !isIdentStartCode(input.charCodeAt(q2))) return false;
15515
+ q2++;
15516
+ while (q2 < input.length && isIdentCharCode(input.charCodeAt(q2))) q2++;
15517
+ }
15518
+ if (input.charCodeAt(q2) === 40) {
15519
+ let depth2 = 0;
15520
+ let callClosed = false;
15521
+ let s = q2;
15522
+ while (s < input.length) {
15523
+ const c = input.charCodeAt(s);
15524
+ if (c === 34 || c === 39 || c === 96) {
15525
+ const quote = c;
15526
+ let tplDepth = 0;
15527
+ s++;
15528
+ while (s < input.length) {
15529
+ const ch = input.charCodeAt(s);
15530
+ if (ch === 92) {
15531
+ s += 2;
15532
+ continue;
15533
+ }
15534
+ if (quote === 96 && ch === 36 && input.charCodeAt(s + 1) === 123) {
15535
+ tplDepth++;
15536
+ s += 2;
15537
+ continue;
15538
+ }
15539
+ if (quote === 96 && ch === 125 && tplDepth > 0) {
15540
+ tplDepth--;
15541
+ s++;
15542
+ continue;
15543
+ }
15544
+ if (ch === quote && tplDepth === 0) {
15545
+ s++;
15546
+ break;
15547
+ }
15548
+ s++;
15549
+ }
15550
+ continue;
15551
+ }
15552
+ if (c === 60 && input.charCodeAt(s + 1) === 47) return false;
15553
+ if (c === 40 || c === 91 || c === 123) depth2++;
15554
+ else if (c === 41 || c === 93 || c === 125) {
15555
+ depth2--;
15556
+ if (c === 41 && depth2 === 0) {
15557
+ callClosed = true;
15558
+ s++;
15559
+ break;
15560
+ }
15561
+ }
15562
+ s++;
15563
+ }
15564
+ if (!callClosed) return false;
15565
+ let d = 0;
15566
+ for (; ; ) {
15567
+ if (s >= input.length) return false;
15568
+ const c = input.charCodeAt(s);
15569
+ if (c === 60 && input.charCodeAt(s + 1) === 47) return false;
15570
+ if (c === 34 || c === 39 || c === 96) {
15571
+ const quote = c;
15572
+ let tplDepth = 0;
15573
+ s++;
15574
+ while (s < input.length) {
15575
+ const ch = input.charCodeAt(s);
15576
+ if (ch === 92) {
15577
+ s += 2;
15578
+ continue;
15579
+ }
15580
+ if (quote === 96 && ch === 36 && input.charCodeAt(s + 1) === 123) {
15581
+ tplDepth++;
15582
+ s += 2;
15583
+ continue;
15584
+ }
15585
+ if (quote === 96 && ch === 125 && tplDepth > 0) {
15586
+ tplDepth--;
15587
+ s++;
15588
+ continue;
15589
+ }
15590
+ if (ch === quote && tplDepth === 0) {
15591
+ s++;
15592
+ break;
15593
+ }
15594
+ s++;
15595
+ }
15596
+ continue;
15597
+ }
15598
+ if (c === 40 || c === 91 || c === 123) d++;
15599
+ else if (c === 41 || c === 93 || c === 125) d--;
15600
+ else if (c === 59 && d === 0) return true;
15601
+ else if ((c === 10 || c === 13) && d === 0) return true;
15602
+ else if (c === 46) {
15603
+ s++;
15604
+ while (s < input.length && isIdentCharCode(input.charCodeAt(s))) s++;
15605
+ continue;
15606
+ } else if (isIdentCharCode(c) || isIdentStartCode(c)) return false;
15607
+ s++;
15608
+ }
15609
+ }
15610
+ }
15611
+ if (word !== "if" && word !== "for" && word !== "while" && word !== "switch" && word !== "try" && word !== "do") return false;
15612
+ let p = i;
15613
+ while (p < input.length && isWsChar(input.charCodeAt(p))) p++;
15614
+ if (word === "try" || word === "do") {
15615
+ return input.charCodeAt(p) === 123;
15616
+ }
15617
+ if (input.charCodeAt(p) !== 40) return false;
15618
+ let depth = 1;
15619
+ let q = p + 1;
15620
+ while (q < input.length) {
15621
+ const c = input.charCodeAt(q);
15622
+ if (c === 34 || c === 39 || c === 96) {
15623
+ const quote = c;
15624
+ q++;
15625
+ while (q < input.length) {
15626
+ const ch = input.charCodeAt(q);
15627
+ if (ch === 92) {
15628
+ q += 2;
15629
+ continue;
15630
+ }
15631
+ if (ch === quote) {
15632
+ q++;
15633
+ break;
15634
+ }
15635
+ q++;
15636
+ }
15637
+ continue;
15638
+ }
15639
+ if (c === 40 || c === 91 || c === 123) depth++;
15640
+ else if (c === 41 || c === 93 || c === 125) {
15641
+ depth--;
15642
+ if (c === 41 && depth === 0) break;
15643
+ }
15644
+ q++;
15645
+ }
15646
+ if (q >= input.length) return false;
15647
+ let r = q + 1;
15648
+ while (r < input.length && isWsChar(input.charCodeAt(r))) r++;
15649
+ return input.charCodeAt(r) === 123;
15650
+ }
15382
15651
  readToken(code) {
15652
+ if (this.#componentDepth > 0 && this.#isJsxChildrenContext() && this.#scansChildStatement()) {
15653
+ this.#pendingChildStatement = true;
15654
+ this.#jsxChildDepthStack.push(this.context.length);
15655
+ this.context.push(types.b_stat);
15656
+ if (isWsChar(code)) {
15657
+ this.skipSpace();
15658
+ this.start = this.pos;
15659
+ if (this.options.locations && typeof this.curPosition === "function") {
15660
+ this.startLoc = this.curPosition();
15661
+ }
15662
+ }
15663
+ return super.readToken(this.input.codePointAt(this.pos));
15664
+ }
15383
15665
  if (this.#componentDepth > 0 && code === 60 && this.#isBlockContext()) {
15384
15666
  const next = this.input.charCodeAt(this.pos + 1);
15385
15667
  if (next === 47 || next >= 65 && next <= 90 || next >= 97 && next <= 122) {
@@ -15692,7 +15974,68 @@ function VeskParserPlugin(config = {}) {
15692
15974
  if (prefix.startsWith("<style") && isStyleBoundary(prefix.charCodeAt(6))) {
15693
15975
  return this.parseStyleElement(startPos, startLoc);
15694
15976
  }
15695
- return super.jsx_parseElementAt(startPos, startLoc);
15977
+ return this.#parseElementWithStatements(startPos, startLoc);
15978
+ }
15979
+ /**
15980
+ * Parses an entire JSX element (or fragment) starting after `<`,
15981
+ * mirroring the vendored acorn-jsx `jsx_parseElementAt` with an added
15982
+ * statement-mode branch: when `#pendingChildStatement` is set (a
15983
+ * control-flow header like `if (…) {` appeared where JSX children
15984
+ * expect text), a real statement is parsed into the children array.
15985
+ */
15986
+ #parseElementWithStatements(startPos, startLoc) {
15987
+ const node = this.startNodeAt(startPos, startLoc);
15988
+ const children = [];
15989
+ const openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
15990
+ let closingElement = null;
15991
+ if (!openingElement.selfClosing) {
15992
+ contents: for (; ; ) {
15993
+ if (this.#pendingChildStatement) {
15994
+ this.#pendingChildStatement = false;
15995
+ const stmt = this.parseStatement(null);
15996
+ children.push(stmt);
15997
+ this.context.length = this.#jsxChildDepthStack.pop() ?? this.context.length;
15998
+ this.exprAllowed = true;
15999
+ this.pos = this.start;
16000
+ this.next();
16001
+ continue;
16002
+ }
16003
+ switch (this.type) {
16004
+ case tstt?.jsxTagStart:
16005
+ startPos = this.start;
16006
+ startLoc = this.startLoc;
16007
+ this.next();
16008
+ if (this.eat(tt.slash)) {
16009
+ closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
16010
+ break contents;
16011
+ }
16012
+ children.push(this.jsx_parseElementAt(startPos, startLoc));
16013
+ break;
16014
+ case tstt?.jsxText:
16015
+ children.push(this.parseExprAtom());
16016
+ break;
16017
+ case tt.braceL:
16018
+ children.push(this.jsx_parseExpressionContainer());
16019
+ break;
16020
+ default:
16021
+ this.unexpected();
16022
+ }
16023
+ }
16024
+ if (getQualifiedJSXName2(closingElement.name) !== getQualifiedJSXName2(openingElement.name)) {
16025
+ this.raise(
16026
+ closingElement.start,
16027
+ "Expected corresponding JSX closing tag for <" + getQualifiedJSXName2(openingElement.name) + ">"
16028
+ );
16029
+ }
16030
+ }
16031
+ const fragmentOrElement = openingElement.name ? "Element" : "Fragment";
16032
+ node["opening" + fragmentOrElement] = openingElement;
16033
+ node["closing" + fragmentOrElement] = closingElement;
16034
+ node.children = children;
16035
+ if (this.type === tt.relational && this.value === "<") {
16036
+ this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
16037
+ }
16038
+ return this.finishNode(node, "JSX" + fragmentOrElement);
15696
16039
  }
15697
16040
  jsx_parseOpeningElementAt(startPos, startLoc) {
15698
16041
  const node = this.startNodeAt(startPos, startLoc);
@@ -16505,7 +16848,15 @@ function collectCalledIdentifiers(code) {
16505
16848
  const t = tokens[i];
16506
16849
  if (t.label !== "name") continue;
16507
16850
  const prev = i > 0 ? tokens[i - 1] : null;
16508
- if (prev && (prev.label === "." || prev.label === "?.")) continue;
16851
+ if (prev && (prev.label === "." || prev.label === "?.")) {
16852
+ const obj = i >= 2 ? tokens[i - 2] : null;
16853
+ const next2 = tokens[i + 1];
16854
+ if (obj && obj.label === "name" && next2) {
16855
+ const nextCh2 = code[next2.start];
16856
+ if (nextCh2 === "(" || nextCh2 === "<") result2.add(obj.value);
16857
+ }
16858
+ continue;
16859
+ }
16509
16860
  const next = tokens[i + 1];
16510
16861
  if (!next) continue;
16511
16862
  const nextCh = code[next.start];
@@ -16593,6 +16944,7 @@ function importModuleTarget(importText) {
16593
16944
  function manualCollectCalledIdentifiers(code) {
16594
16945
  const result2 = /* @__PURE__ */ new Set();
16595
16946
  let i = 0;
16947
+ let prevIdent = null;
16596
16948
  while (i < code.length) {
16597
16949
  const c = code[i];
16598
16950
  if (c === '"' || c === "'" || c === "`") {
@@ -16611,7 +16963,15 @@ function manualCollectCalledIdentifiers(code) {
16611
16963
  let k = skipWhitespace(code, j);
16612
16964
  if (code[k] === "<") k = skipTrackGeneric(code, k);
16613
16965
  if (code[k] === "(") result2.add(code.slice(i, j));
16966
+ } else if (before === "." && prevIdent) {
16967
+ let p = i - 1;
16968
+ while (p > prevIdent[1] && (code[p] === "." || code[p] === "?" || code[p] === "\n" || code[p] === " " || code[p] === " ")) p--;
16969
+ if (p === prevIdent[1]) {
16970
+ let k = skipWhitespace(code, j);
16971
+ if (code[k] === "(") result2.add(code.slice(prevIdent[0], prevIdent[1]));
16972
+ }
16614
16973
  }
16974
+ prevIdent = [i, j];
16615
16975
  i = j;
16616
16976
  continue;
16617
16977
  }
@@ -16829,7 +17189,7 @@ function stripTypeImport(importSrc) {
16829
17189
  if (isTypeOnlyImport(stmt)) return null;
16830
17190
  const specs = stmt.specifiers || [];
16831
17191
  const kept = specs.filter((s) => s.importKind !== "type");
16832
- if (kept.length === 0) return null;
17192
+ if (specs.length > 0 && kept.length === 0) return null;
16833
17193
  if (kept.length === specs.length) return importSrc;
16834
17194
  try {
16835
17195
  const rewritten = { ...stmt, specifiers: kept };
@@ -16846,6 +17206,505 @@ var init_vsk_imports = __esm({
16846
17206
  }
16847
17207
  });
16848
17208
 
17209
+ // ../compiler/src/module-imports.ts
17210
+ import { readFileSync, realpathSync, statSync } from "node:fs";
17211
+ import { createRequire } from "node:module";
17212
+ import { dirname as dirname2, extname, isAbsolute, join, resolve as resolve2 } from "node:path";
17213
+ import { print as print3 } from "esrap";
17214
+ import ts3 from "esrap/languages/ts";
17215
+ function cacheModule(p, val) {
17216
+ MODULE_CACHE.delete(p);
17217
+ MODULE_CACHE.set(p, val);
17218
+ if (MODULE_CACHE.size > MAX_CACHE_ENTRIES) {
17219
+ MODULE_CACHE.delete(MODULE_CACHE.keys().next().value);
17220
+ }
17221
+ }
17222
+ function isCompilerOwnedTarget(target) {
17223
+ if (target === "@vesk/runtime" || target === "@vesk/reactivity") return true;
17224
+ for (const prefix of RUNTIME_PREFIXES) {
17225
+ if (target.startsWith(prefix)) return true;
17226
+ }
17227
+ return false;
17228
+ }
17229
+ function isValueLessTarget(target) {
17230
+ return target.endsWith(".vsk") || target.endsWith(".css") || target.endsWith(".md") || target.endsWith(".markdown");
17231
+ }
17232
+ function importBindingPairs(imp) {
17233
+ const pairs = [];
17234
+ let ast = null;
17235
+ try {
17236
+ ast = parse4(imp, { filename: "import.mjs" });
17237
+ } catch {
17238
+ ast = null;
17239
+ }
17240
+ if (!ast) return pairs;
17241
+ const stmt = (ast.body || []).find((n) => n.type === "ImportDeclaration");
17242
+ if (!stmt) return pairs;
17243
+ const specifiers = stmt.specifiers || [];
17244
+ for (const spec of specifiers) {
17245
+ if (spec.importKind === "type") continue;
17246
+ const local = spec.local?.name;
17247
+ if (!local) continue;
17248
+ if (spec.type === "ImportDefaultSpecifier") {
17249
+ pairs.push({ local, imported: "default" });
17250
+ } else if (spec.type === "ImportNamespaceSpecifier") {
17251
+ pairs.push({ local, imported: "*" });
17252
+ } else {
17253
+ const importedSpec = spec.imported || spec.local;
17254
+ const imported = importedSpec.name ?? importedSpec.value;
17255
+ if (imported) pairs.push({ local, imported });
17256
+ }
17257
+ }
17258
+ return pairs;
17259
+ }
17260
+ function localValueImportNames(importStrs) {
17261
+ const names = [];
17262
+ for (const imp of importStrs) {
17263
+ const target = importModuleTarget(imp);
17264
+ if (!target || isCompilerOwnedTarget(target) || isValueLessTarget(target)) continue;
17265
+ for (const pair of importBindingPairs(imp)) names.push(pair.local);
17266
+ }
17267
+ return names;
17268
+ }
17269
+ function applyLocalModuleImports(__vesk, importStrs, sourcePath2) {
17270
+ if (!sourcePath2) return;
17271
+ const fromDir = dirname2(sourcePath2);
17272
+ for (const imp of importStrs) {
17273
+ const target = importModuleTarget(imp);
17274
+ if (!target || isCompilerOwnedTarget(target) || isValueLessTarget(target)) continue;
17275
+ const resolved = resolveSsrModule(target, fromDir);
17276
+ if (!resolved) {
17277
+ console.warn(`[vesk] SSR: cannot resolve "${target}" imported by ${sourcePath2} \u2014 the imported name will be undefined during server render.`);
17278
+ continue;
17279
+ }
17280
+ const mod = loadSsrModule(resolved);
17281
+ if (!mod || typeof mod !== "object") continue;
17282
+ for (const pair of importBindingPairs(imp)) {
17283
+ if (pair.imported === "*") {
17284
+ __vesk[pair.local] = mod;
17285
+ } else if (pair.imported in mod) {
17286
+ __vesk[pair.local] = mod[pair.imported];
17287
+ }
17288
+ }
17289
+ }
17290
+ }
17291
+ function nativeRequireFallback(absPath) {
17292
+ try {
17293
+ const req = createRequire(absPath);
17294
+ const loaded = req(absPath);
17295
+ if (loaded && typeof loaded === "object") return loaded;
17296
+ if (loaded !== null && loaded !== void 0) return { default: loaded };
17297
+ return null;
17298
+ } catch {
17299
+ return null;
17300
+ }
17301
+ }
17302
+ function loadSsrModule(absPath) {
17303
+ if (isBuiltinPath(absPath)) {
17304
+ return loadBuiltin(absPath.slice(BUILTIN_PREFIX.length));
17305
+ }
17306
+ let mtimeMs = 0;
17307
+ try {
17308
+ mtimeMs = statSync(absPath).mtimeMs;
17309
+ } catch {
17310
+ return null;
17311
+ }
17312
+ const inFlight = EVALUATING.get(absPath);
17313
+ if (inFlight !== void 0) return inFlight;
17314
+ const cachedVal = MODULE_CACHE.get(absPath);
17315
+ if (cachedVal && cachedVal.mtimeMs === mtimeMs && depsFresh(cachedVal)) return cachedVal.exports;
17316
+ const frame = /* @__PURE__ */ new Set();
17317
+ depStack.push(frame);
17318
+ try {
17319
+ let exportsObj = null;
17320
+ if (absPath.endsWith(".json")) {
17321
+ try {
17322
+ exportsObj = JSON.parse(readFileSync(absPath, "utf-8"));
17323
+ if (exportsObj && typeof exportsObj === "object" && !("default" in exportsObj)) {
17324
+ exportsObj.default = exportsObj;
17325
+ }
17326
+ } catch {
17327
+ exportsObj = null;
17328
+ }
17329
+ } else {
17330
+ exportsObj = {};
17331
+ EVALUATING.set(absPath, exportsObj);
17332
+ const ran = evaluateModuleFile(absPath, exportsObj);
17333
+ if (!ran) exportsObj = null;
17334
+ }
17335
+ if (exportsObj === null) {
17336
+ exportsObj = nativeRequireFallback(absPath);
17337
+ }
17338
+ if (exportsObj === null) return null;
17339
+ cacheModule(absPath, { mtimeMs, deps: captureClosure(frame), exports: exportsObj });
17340
+ return exportsObj;
17341
+ } finally {
17342
+ depStack.pop();
17343
+ EVALUATING.delete(absPath);
17344
+ }
17345
+ }
17346
+ function captureClosure(frame) {
17347
+ const deps = [];
17348
+ for (const dep of frame) {
17349
+ try {
17350
+ deps.push({ path: dep, mtimeMs: statSync(dep).mtimeMs });
17351
+ } catch {
17352
+ deps.push({ path: dep, mtimeMs: -1 });
17353
+ }
17354
+ }
17355
+ return deps;
17356
+ }
17357
+ function depsFresh(cachedVal) {
17358
+ for (const dep of cachedVal.deps) {
17359
+ try {
17360
+ if (statSync(dep.path).mtimeMs !== dep.mtimeMs) return false;
17361
+ } catch {
17362
+ return false;
17363
+ }
17364
+ }
17365
+ return true;
17366
+ }
17367
+ function evaluateModuleFile(absPath, exportsObj) {
17368
+ let raw2;
17369
+ try {
17370
+ raw2 = readFileSync(absPath, "utf-8");
17371
+ } catch (err) {
17372
+ console.warn(`[vesk] SSR: failed to read ${absPath}: ${err?.message ?? String(err)}`);
17373
+ return false;
17374
+ }
17375
+ let ast = null;
17376
+ try {
17377
+ ast = parse4(raw2, { filename: absPath });
17378
+ } catch {
17379
+ ast = null;
17380
+ }
17381
+ if (!ast) {
17382
+ try {
17383
+ const fn = new Function("require", "module", "exports", "__dirname", "__filename", raw2);
17384
+ fn(createModuleRequire(dirname2(absPath)), { exports: exportsObj }, exportsObj, dirname2(absPath), absPath);
17385
+ } catch (err) {
17386
+ console.warn(`[vesk] SSR: failed to load ${absPath}: ${err?.message ?? String(err)}`);
17387
+ return false;
17388
+ }
17389
+ return true;
17390
+ }
17391
+ const unsupported = findUnsupportedEsm(ast.body);
17392
+ if (unsupported) {
17393
+ throw new Error(
17394
+ `${absPath} uses ${unsupported} \u2014 not representable in the SSR module loader. Split it out of the module or avoid ${unsupported} in .vsk-imported code.`
17395
+ );
17396
+ }
17397
+ let stripped = ast;
17398
+ if (hasTsSyntax(ast)) stripped = stripTsTypes(ast);
17399
+ stripped.body = (stripped.body || []).filter((n) => {
17400
+ if (!n) return false;
17401
+ return !isTypeOnlyStatement(n);
17402
+ });
17403
+ const body = esmToCjs(stripped.body);
17404
+ try {
17405
+ const fn = new Function("require", "module", "exports", "__dirname", "__filename", "'use strict';\n" + body);
17406
+ fn(createModuleRequire(dirname2(absPath)), { exports: exportsObj }, exportsObj, dirname2(absPath), absPath);
17407
+ } catch (err) {
17408
+ console.warn(`[vesk] SSR: failed to load ${absPath}: ${err?.message ?? String(err)}`);
17409
+ return false;
17410
+ }
17411
+ return true;
17412
+ }
17413
+ function findUnsupportedEsm(body) {
17414
+ for (const stmt of body) {
17415
+ const hit = scanUnsupportedNode(stmt);
17416
+ if (hit) return hit;
17417
+ }
17418
+ return null;
17419
+ }
17420
+ function scanUnsupportedNode(node, inFunction = false) {
17421
+ if (!node || typeof node !== "object") return null;
17422
+ const n = node;
17423
+ const t = n.type;
17424
+ if (t === "MetaProperty" || t === "MetaProperty" && n.meta?.name === "import") {
17425
+ return "import.meta";
17426
+ }
17427
+ if (!inFunction && t === "AwaitExpression") return "top-level await";
17428
+ if (t === "FunctionDeclaration" || t === "FunctionExpression" || t === "ArrowFunctionExpression" || t === "ClassDeclaration" || t === "ClassExpression") {
17429
+ return null;
17430
+ }
17431
+ for (const key of Object.keys(n)) {
17432
+ const val = n[key];
17433
+ if (Array.isArray(val)) {
17434
+ for (const item of val) {
17435
+ if (item && typeof item === "object") {
17436
+ const sub = scanUnsupportedNode(item, inFunction);
17437
+ if (sub) return sub;
17438
+ }
17439
+ }
17440
+ } else if (val && typeof val === "object") {
17441
+ const sub = scanUnsupportedNode(val, inFunction);
17442
+ if (sub) return sub;
17443
+ }
17444
+ }
17445
+ return null;
17446
+ }
17447
+ function createModuleRequire(fromDir) {
17448
+ return (specifier) => {
17449
+ const resolved = resolveSsrModule(specifier, fromDir);
17450
+ if (!resolved) throw new Error(`Cannot find module '${specifier}'`);
17451
+ for (const frame of depStack) frame.add(resolved);
17452
+ const loaded = loadSsrModule(resolved);
17453
+ if (loaded === null) throw new Error(`Cannot load module '${specifier}'`);
17454
+ return loaded;
17455
+ };
17456
+ }
17457
+ function resolveSsrModule(specifier, fromDir) {
17458
+ let resolved = null;
17459
+ if (specifier === "." || specifier === ".." || isAbsolute(specifier)) {
17460
+ resolved = probeFile(resolve2(specifier));
17461
+ } else if (specifier.startsWith("./") || specifier.startsWith("../")) {
17462
+ resolved = probeFile(resolve2(fromDir, specifier));
17463
+ } else {
17464
+ const native = nativeResolve(specifier, fromDir);
17465
+ if (native) return native;
17466
+ let dir = fromDir;
17467
+ for (let depth = 0; depth < 64; depth++) {
17468
+ const base = join(dir, "node_modules", specifier);
17469
+ const found = probeFile(base);
17470
+ if (found) {
17471
+ resolved = found;
17472
+ break;
17473
+ }
17474
+ const parent = dirname2(dir);
17475
+ if (parent === dir) break;
17476
+ dir = parent;
17477
+ }
17478
+ }
17479
+ return resolved ? toRealPath(resolved) : null;
17480
+ }
17481
+ function toRealPath(p) {
17482
+ try {
17483
+ return realpathSync(p);
17484
+ } catch {
17485
+ return p;
17486
+ }
17487
+ }
17488
+ function nativeResolve(specifier, fromDir) {
17489
+ try {
17490
+ const req = createRequire(join(fromDir, "__vesk_resolve__.js"));
17491
+ const resolved = req.resolve(specifier);
17492
+ if (isAbsolute(resolved)) return toRealPath(resolved);
17493
+ return builtinMarker(resolved);
17494
+ } catch {
17495
+ return null;
17496
+ }
17497
+ }
17498
+ function builtinMarker(name) {
17499
+ return BUILTIN_PREFIX + name;
17500
+ }
17501
+ function isBuiltinPath(p) {
17502
+ return p.startsWith(BUILTIN_PREFIX);
17503
+ }
17504
+ function loadBuiltin(name) {
17505
+ const id = name.startsWith("node:") ? name : `node:${name}`;
17506
+ const cachedVal = BUILTIN_CACHE.get(id);
17507
+ if (cachedVal) return cachedVal;
17508
+ try {
17509
+ const req = createRequire(join("/", "__vesk_builtin__.js"));
17510
+ const loaded = req(id);
17511
+ let mod = null;
17512
+ if (loaded && typeof loaded === "object") mod = loaded;
17513
+ else if (loaded !== null && loaded !== void 0) mod = { default: loaded };
17514
+ if (mod) BUILTIN_CACHE.set(id, mod);
17515
+ return mod;
17516
+ } catch {
17517
+ return null;
17518
+ }
17519
+ }
17520
+ function statOrNull(p) {
17521
+ try {
17522
+ return statSync(p);
17523
+ } catch {
17524
+ return null;
17525
+ }
17526
+ }
17527
+ function probeFile(base) {
17528
+ const st = statOrNull(base);
17529
+ if (st && st.isFile()) return base;
17530
+ if (st && st.isDirectory()) {
17531
+ const pkgPath = join(base, "package.json");
17532
+ const pkgSt = statOrNull(pkgPath);
17533
+ if (pkgSt && pkgSt.isFile()) {
17534
+ try {
17535
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
17536
+ if (typeof pkg.main === "string" && pkg.main.length > 0) {
17537
+ const viaMain = probeFile(resolve2(base, pkg.main));
17538
+ if (viaMain) return viaMain;
17539
+ }
17540
+ } catch {
17541
+ }
17542
+ }
17543
+ return probeFile(join(base, "index"));
17544
+ }
17545
+ const ext = extname(base);
17546
+ if (ext.length === 0 || "/\\".includes(base[base.length - 1])) {
17547
+ for (const suffix of EXTENSIONS) {
17548
+ const candidate = base + suffix;
17549
+ const cst = statOrNull(candidate);
17550
+ if (cst && cst.isFile()) return candidate;
17551
+ }
17552
+ }
17553
+ return null;
17554
+ }
17555
+ function astName(node) {
17556
+ if (!node) return "undefined";
17557
+ if (node.type === "Identifier" && typeof node.name === "string") return node.name;
17558
+ return printNode(node);
17559
+ }
17560
+ function printNode(node) {
17561
+ try {
17562
+ return print3(node, ts3()).code.trim();
17563
+ } catch {
17564
+ return "";
17565
+ }
17566
+ }
17567
+ function memberAccess(obj, prop) {
17568
+ if (prop.type === "Identifier" && typeof prop.name === "string") return `${obj}.${prop.name}`;
17569
+ if ((prop.type === "Literal" || prop.type === "StringLiteral") && typeof prop.value === "string") {
17570
+ return `${obj}[${JSON.stringify(prop.value)}]`;
17571
+ }
17572
+ return `${obj}[${astName(prop)}]`;
17573
+ }
17574
+ function exportKeyName(node) {
17575
+ if (!node) return "";
17576
+ if (node.type === "Identifier" && typeof node.name === "string") return node.name;
17577
+ if ((node.type === "Literal" || node.type === "StringLiteral") && typeof node.value === "string") return node.value;
17578
+ const printed = printNode(node);
17579
+ return stripOuterQuotes(printed);
17580
+ }
17581
+ function stripOuterQuotes(s) {
17582
+ if (s.length >= 2) {
17583
+ const first = s[0];
17584
+ const last = s[s.length - 1];
17585
+ if ((first === '"' || first === "'" || first === "`") && first === last) return s.slice(1, -1);
17586
+ }
17587
+ return s;
17588
+ }
17589
+ function exportGetter(lines, key, valueExpr) {
17590
+ lines.push(`Object.defineProperty(exports, ${JSON.stringify(key)}, { get: () => ${valueExpr}, enumerable: true });`);
17591
+ }
17592
+ function esmToCjs(body) {
17593
+ const lines = [];
17594
+ for (const stmt of body) {
17595
+ switch (stmt.type) {
17596
+ case "ImportDeclaration": {
17597
+ const source = printNode(stmt.source);
17598
+ const specifiers = stmt.specifiers || [];
17599
+ if (specifiers.length === 0) {
17600
+ lines.push(`require(${source});`);
17601
+ continue;
17602
+ }
17603
+ for (const spec of specifiers) {
17604
+ if (spec.type === "ImportNamespaceSpecifier") {
17605
+ lines.push(`const ${astName(spec.local)} = require(${source});`);
17606
+ } else if (spec.type === "ImportDefaultSpecifier") {
17607
+ lines.push(`const ${astName(spec.local)} = require(${source}).default;`);
17608
+ } else {
17609
+ const local = astName(spec.local);
17610
+ const imported = spec.imported;
17611
+ if (imported && spec.importKind === "type") continue;
17612
+ lines.push(`const ${local} = ${memberAccess(`require(${source})`, imported || spec.local)};`);
17613
+ }
17614
+ }
17615
+ break;
17616
+ }
17617
+ case "ExportNamedDeclaration": {
17618
+ if (stmt.exportKind === "type") continue;
17619
+ const declaration = stmt.declaration;
17620
+ const source = stmt.source ? printNode(stmt.source) : null;
17621
+ if (declaration) {
17622
+ const printed = printNode(declaration);
17623
+ if (printed) {
17624
+ lines.push(printed);
17625
+ if (declaration.type === "VariableDeclaration") {
17626
+ const declarators = declaration.declarations || [];
17627
+ for (const d of declarators) {
17628
+ if (d.id && d.id.type === "Identifier") exportGetter(lines, exportKeyName(d.id), d.id.name ?? "");
17629
+ }
17630
+ } else if (declaration.id) {
17631
+ const name = declaration.id;
17632
+ exportGetter(lines, exportKeyName(name), name.name ?? "");
17633
+ }
17634
+ }
17635
+ } else if (source) {
17636
+ const modVar = `__veskExport${exportCounter++}`;
17637
+ lines.push(`const ${modVar} = require(${source});`);
17638
+ const specifiers = stmt.specifiers || [];
17639
+ for (const spec of specifiers) {
17640
+ if (spec.exportKind === "type") continue;
17641
+ const local = spec.local;
17642
+ const exported = spec.exported;
17643
+ exportGetter(lines, exportKeyName(exported), memberAccess(modVar, local));
17644
+ }
17645
+ } else {
17646
+ const specifiers = stmt.specifiers || [];
17647
+ for (const spec of specifiers) {
17648
+ if (spec.exportKind === "type") continue;
17649
+ const local = spec.local;
17650
+ const exported = spec.exported;
17651
+ exportGetter(lines, exportKeyName(exported), astName(local));
17652
+ }
17653
+ }
17654
+ break;
17655
+ }
17656
+ case "ExportDefaultDeclaration": {
17657
+ const declaration = stmt.declaration;
17658
+ if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") {
17659
+ if (declaration.id) {
17660
+ const name = declaration.id.name;
17661
+ lines.push(printNode(declaration));
17662
+ lines.push(`exports.default = ${name};`);
17663
+ } else {
17664
+ const expr = { ...declaration, type: declaration.type === "FunctionDeclaration" ? "FunctionExpression" : "ClassExpression" };
17665
+ lines.push(`exports.default = ${printNode(expr)};`);
17666
+ }
17667
+ } else {
17668
+ lines.push(`exports.default = ${printNode(declaration)};`);
17669
+ }
17670
+ break;
17671
+ }
17672
+ case "ExportAllDeclaration": {
17673
+ const source = printNode(stmt.source);
17674
+ const modVar = `__veskExport${exportCounter++}`;
17675
+ lines.push(`const ${modVar} = require(${source});`);
17676
+ if (stmt.exported) {
17677
+ lines.push(`exports[${JSON.stringify(exportKeyName(stmt.exported))}] = ${modVar};`);
17678
+ } else {
17679
+ lines.push(`for (const __veskKey in ${modVar}) { if (__veskKey !== 'default' && __veskKey !== '__esModule' && !(__veskKey in exports)) exports[__veskKey] = ${modVar}[__veskKey]; }`);
17680
+ }
17681
+ break;
17682
+ }
17683
+ default:
17684
+ lines.push(printNode(stmt));
17685
+ }
17686
+ }
17687
+ return lines.join("\n");
17688
+ }
17689
+ var RUNTIME_PREFIXES, EXTENSIONS, BUILTIN_PREFIX, BUILTIN_CACHE, MODULE_CACHE, MAX_CACHE_ENTRIES, depStack, EVALUATING, exportCounter;
17690
+ var init_module_imports = __esm({
17691
+ "../compiler/src/module-imports.ts"() {
17692
+ "use strict";
17693
+ init_parser();
17694
+ init_strip_ts();
17695
+ init_tokens();
17696
+ RUNTIME_PREFIXES = ["@vesk/runtime/", "@vesk/reactivity/", "@vesk/types", "@vesk/"];
17697
+ EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".jsx", ".json"];
17698
+ BUILTIN_PREFIX = "\0builtin:";
17699
+ BUILTIN_CACHE = /* @__PURE__ */ new Map();
17700
+ MODULE_CACHE = /* @__PURE__ */ new Map();
17701
+ MAX_CACHE_ENTRIES = 256;
17702
+ depStack = [];
17703
+ EVALUATING = /* @__PURE__ */ new Map();
17704
+ exportCounter = 0;
17705
+ }
17706
+ });
17707
+
16849
17708
  // ../compiler/src/ir-generator.ts
16850
17709
  function parseExprNode(text) {
16851
17710
  try {
@@ -16918,9 +17777,9 @@ function componentUsesFetch(nodes) {
16918
17777
  if (node instanceof ServerBlock || node instanceof ClientBlock) {
16919
17778
  if (componentUsesFetch(node.children)) return true;
16920
17779
  } else if (node instanceof RuntimeStatement) {
16921
- if (node.raw.includes("useFetch(")) return true;
17780
+ if (node.raw.includes("useFetch(") || node.raw.includes("useFetch.")) return true;
16922
17781
  } else if (node instanceof DynamicBinding) {
16923
- if (node.expression.raw.includes("useFetch(")) return true;
17782
+ if (node.expression.raw.includes("useFetch(") || node.expression.raw.includes("useFetch.")) return true;
16924
17783
  } else if (node instanceof MapRegion) {
16925
17784
  if (componentUsesFetch(node.bodyTemplate)) return true;
16926
17785
  if (componentUsesFetch(node.alternateNodes)) return true;
@@ -17212,6 +18071,21 @@ function processJSXChildren(source, children) {
17212
18071
  } else if (child.type === "JSXFragment") {
17213
18072
  for (const c of child.children) result2.push(...processJSXChildren(source, [c]));
17214
18073
  i++;
18074
+ } else if (child.type === "ForOfStatement") {
18075
+ let alternate = [];
18076
+ let consumed = 1;
18077
+ const emptyText = children[i + 1];
18078
+ const emptyContainer = children[i + 2];
18079
+ if (emptyText && emptyText.type === "JSXText" && ["#empty", "empty"].includes(emptyText.value.trim()) && emptyContainer && emptyContainer.type === "JSXExpressionContainer" && emptyContainer.expression.type !== "JSXEmptyExpression") {
18080
+ alternate = exprToIR(source, emptyContainer.expression);
18081
+ consumed = 3;
18082
+ }
18083
+ result2.push(...processForStatement(source, child, alternate));
18084
+ i += consumed;
18085
+ continue;
18086
+ } else if (child.type === "IfStatement" || child.type === "ForStatement" || child.type === "ForInStatement" || child.type === "WhileStatement" || child.type === "DoWhileStatement" || child.type === "SwitchStatement" || child.type === "TryStatement" || child.type === "VariableDeclaration" || child.type === "ExpressionStatement" || child.type === "ReturnStatement" || child.type === "WithStatement" || child.type === "LabeledStatement") {
18087
+ result2.push(...processStatementModeBody(source, [child]));
18088
+ i++;
17215
18089
  } else {
17216
18090
  i++;
17217
18091
  }
@@ -17248,6 +18122,19 @@ function exprToIR(source, expr) {
17248
18122
  }
17249
18123
  return [new DynamicBinding(toExpression(source, expr))];
17250
18124
  }
18125
+ function isRenderableExpression(expr) {
18126
+ const t = expr.type;
18127
+ if (t === "CallExpression" || t === "NewExpression" || t === "AssignmentExpression" || t === "UpdateExpression" || t === "AwaitExpression" || t === "YieldExpression" || t === "TaggedTemplateExpression" || t === "ImportExpression" || t === "MetaProperty") {
18128
+ return false;
18129
+ }
18130
+ if (t === "UnaryExpression") {
18131
+ return expr.operator !== "delete" && expr.operator !== "void";
18132
+ }
18133
+ if (t === "SequenceExpression") {
18134
+ return isRenderableExpression(expr.expressions[expr.expressions.length - 1]);
18135
+ }
18136
+ return true;
18137
+ }
17251
18138
  function processJSXCallbackBody(source, body) {
17252
18139
  if (body.type === "JSXElement") return processJSXElement(source, body);
17253
18140
  if (body.type === "JSXFragment") {
@@ -17332,11 +18219,14 @@ function buildGuardChain(source, guardClauses, mainReturn) {
17332
18219
  const guard = guardClauses[i];
17333
18220
  const condExpr = toExpression(source, guard.test);
17334
18221
  const consequent = [];
17335
- if (guard.consequent.type === "ReturnStatement" && guard.consequent.argument) {
17336
- if (guard.consequent.argument.type === "JSXElement") {
17337
- consequent.push(...processJSXElement(source, guard.consequent.argument));
18222
+ const guardReturn = getReturnArgument(guard.consequent);
18223
+ if (guardReturn) {
18224
+ if (guardReturn.type === "JSXElement") {
18225
+ consequent.push(...processJSXElement(source, guardReturn));
18226
+ } else if (guardReturn.type === "JSXFragment") {
18227
+ for (const c of guardReturn.children) consequent.push(...processJSXChildren(source, [c]));
17338
18228
  } else {
17339
- consequent.push(new DynamicBinding(toExpression(source, guard.consequent.argument)));
18229
+ consequent.push(new DynamicBinding(toExpression(source, guardReturn)));
17340
18230
  }
17341
18231
  }
17342
18232
  currentAlternate = [new OpaqueDynamicRegion(condExpr, consequent, currentAlternate)];
@@ -17367,7 +18257,14 @@ function hasJSXInSubtree(node) {
17367
18257
  return false;
17368
18258
  }
17369
18259
  function isGuardClause(node) {
17370
- return node.type === "IfStatement" && node.consequent.type === "ReturnStatement" && hasJSXInSubtree(node.consequent);
18260
+ return node.type === "IfStatement" && !node.alternate && getReturnArgument(node.consequent) !== null && hasJSXInSubtree(node.consequent);
18261
+ }
18262
+ function getReturnArgument(node) {
18263
+ if (node.type === "ReturnStatement") return node.argument ?? null;
18264
+ if (node.type === "BlockStatement" && node.body.length === 1 && node.body[0].type === "ReturnStatement") {
18265
+ return node.body[0].argument ?? null;
18266
+ }
18267
+ return null;
17371
18268
  }
17372
18269
  function isStatementMode(bodyStmts) {
17373
18270
  if (bodyStmts.some((s) => s.type === "JSXElement" || s.type === "JSXExpressionContainer" || s.type === "JSXFragment")) return true;
@@ -17518,6 +18415,13 @@ function processStatementModeBody(source, bodyStmts) {
17518
18415
  nodes.push(...processForStatement(source, stmt));
17519
18416
  } else if (stmt.type === "ForStatement") {
17520
18417
  nodes.push(...processForStatement(source, stmt));
18418
+ } else if (stmt.type === "ExpressionStatement") {
18419
+ if (isRenderableExpression(stmt.expression)) {
18420
+ nodes.push(...exprToIR(source, stmt.expression));
18421
+ } else {
18422
+ const raw2 = getSource(source, stmt);
18423
+ if (raw2) nodes.push(new RuntimeStatement(raw2, stmt, source));
18424
+ }
17521
18425
  } else if (stmt.type === "ClassDeclaration") {
17522
18426
  throw VeskError.classDecl();
17523
18427
  } else {
@@ -17823,7 +18727,11 @@ function generateIR(ast, source) {
17823
18727
  if (importModuleTarget(imp) !== "@vesk/runtime") continue;
17824
18728
  for (const n of extractImportNames(imp)) existing.add(n);
17825
18729
  }
17826
- const missing = [...usedFunctions].filter((f) => !existing.has(f));
18730
+ const boundLocally = /* @__PURE__ */ new Set();
18731
+ for (const imp of imports) {
18732
+ for (const pair of importBindingPairs(imp)) boundLocally.add(pair.local);
18733
+ }
18734
+ const missing = [...usedFunctions].filter((f) => !existing.has(f) && !boundLocally.has(f));
17827
18735
  if (missing.length > 0) {
17828
18736
  imports.push(`import { ${missing.join(", ")} } from '@vesk/runtime';`);
17829
18737
  }
@@ -17840,6 +18748,7 @@ var init_ir_generator = __esm({
17840
18748
  init_scan();
17841
18749
  init_strip_ts();
17842
18750
  init_vsk_imports();
18751
+ init_module_imports();
17843
18752
  init_tokens();
17844
18753
  __vskAnnotations = [];
17845
18754
  }
@@ -19342,7 +20251,7 @@ var init_request = __esm({
19342
20251
  });
19343
20252
  }
19344
20253
  };
19345
- VeskRequest = class extends ServerRequest {
20254
+ VeskRequest = class _VeskRequest extends ServerRequest {
19346
20255
  _query;
19347
20256
  _ip;
19348
20257
  _protocol;
@@ -19360,6 +20269,21 @@ var init_request = __esm({
19360
20269
  this._body = null;
19361
20270
  this._bodyPromise = null;
19362
20271
  this._parsedUrl = null;
20272
+ const cookieHeader = this.headers?.get("cookie") || "";
20273
+ if (cookieHeader) {
20274
+ for (const part of cookieHeader.split(";")) {
20275
+ const eq = part.indexOf("=");
20276
+ if (eq > 0) {
20277
+ const name = part.slice(0, eq).trim();
20278
+ const val = part.slice(eq + 1).trim();
20279
+ try {
20280
+ this._cookies[name] = decodeURIComponent(val);
20281
+ } catch {
20282
+ this._cookies[name] = val;
20283
+ }
20284
+ }
20285
+ }
20286
+ }
19363
20287
  Object.defineProperty(this, "body", {
19364
20288
  get: () => {
19365
20289
  if (!this._bodyPromise) {
@@ -19371,6 +20295,52 @@ var init_request = __esm({
19371
20295
  enumerable: true
19372
20296
  });
19373
20297
  }
20298
+ /**
20299
+ * The request's host header (honoring `x-forwarded-host` when
20300
+ * setTrustProxy() is enabled). Falls back to the parsed URL host.
20301
+ */
20302
+ get host() {
20303
+ const trust = this._security.trustProxy === true;
20304
+ const fwd = trust ? this.headers?.get("x-forwarded-host") : void 0;
20305
+ const header = typeof fwd === "string" && fwd ? fwd : this.headers?.get("host") || "";
20306
+ if (header) return header;
20307
+ return this.parsedUrl.host || "localhost";
20308
+ }
20309
+ /** Absolute origin (`protocol://host`) — the base for resolving relative URLs. */
20310
+ get origin() {
20311
+ return `${this.protocol}://${this.host}`;
20312
+ }
20313
+ /**
20314
+ * Resolves a possibly-relative URL against this request's own origin.
20315
+ * Absolute URLs (scheme or protocol-relative `//`) pass through untouched.
20316
+ * Used by the runtime SSR fetcher (`resolveFetchUrl`) to make in-app
20317
+ * fetches (e.g. `/api/...`) work during server rendering.
20318
+ */
20319
+ resolveUrl(url) {
20320
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("//")) return url;
20321
+ return new URL(url, this.origin).href;
20322
+ }
20323
+ /** locals map accessors so <VeskRequest> can double as the middleware ctx. */
20324
+ set(key, value) {
20325
+ this._locals[key] = value;
20326
+ }
20327
+ get(key) {
20328
+ return this._locals[key];
20329
+ }
20330
+ /**
20331
+ * Wraps an inbound platform `Request` (from dev/prod/platform handlers)
20332
+ * into a VeskRequest carrying the same method, headers and cookie store.
20333
+ * Params/locals can be seeded so useParams()/useRequest() work in renders.
20334
+ */
20335
+ static from(request, init) {
20336
+ const vreq = new _VeskRequest(request instanceof Request ? request.url : String(request), {
20337
+ method: request.method,
20338
+ headers: request.headers
20339
+ });
20340
+ if (init?.params) vreq._params = { ...init.params };
20341
+ if (init?.locals) vreq._locals = { ...init.locals };
20342
+ return vreq;
20343
+ }
19374
20344
  get parsedUrl() {
19375
20345
  if (!this._parsedUrl) {
19376
20346
  this._parsedUrl = new URL(this.url);
@@ -19574,6 +20544,10 @@ var init_request = __esm({
19574
20544
  headers: { "Content-Type": "text/html; charset=utf-8", ...init?.headers }
19575
20545
  });
19576
20546
  }
20547
+ /** Chunked streaming response over a `ReadableStream` body (SSE, file streams, …). */
20548
+ static stream(readable, init) {
20549
+ return new __VeskResponse(readable, init);
20550
+ }
19577
20551
  };
19578
20552
  VeskResponse = new Proxy(_VeskResponse, {
19579
20553
  apply(target, _thisArg, args2) {
@@ -21940,6 +22914,84 @@ function wireCopyHandlers(root3) {
21940
22914
  function mdIsSSR() {
21941
22915
  return typeof document === "undefined";
21942
22916
  }
22917
+ function stringEndsWith(s, suffix) {
22918
+ if (suffix.length > s.length) return false;
22919
+ for (let i = 0; i < suffix.length; i++) {
22920
+ if (s[s.length - suffix.length + i] !== suffix[i]) return false;
22921
+ }
22922
+ return true;
22923
+ }
22924
+ function isPublicMarkdownPath(v) {
22925
+ if (typeof v !== "string") return false;
22926
+ const s = v;
22927
+ if (s.length < 2 || s.charCodeAt(0) !== 47) return false;
22928
+ if (s.charCodeAt(1) === 47) return false;
22929
+ for (let i = 0; i < s.length; i++) {
22930
+ const c = s.charCodeAt(i);
22931
+ if (c === 63 || c === 35 || c === 92) return false;
22932
+ }
22933
+ const lower = s.toLowerCase();
22934
+ return stringEndsWith(lower, ".md") || stringEndsWith(lower, ".markdown");
22935
+ }
22936
+ function getMdPathCell(path) {
22937
+ let cell = mdPathCells.get(path);
22938
+ if (!cell) {
22939
+ cell = tracked(void 0);
22940
+ mdPathCells.set(path, cell);
22941
+ }
22942
+ return cell;
22943
+ }
22944
+ function ensureMdPathLoaded(path) {
22945
+ if (mdPathCache.has(path) || mdPathInflight.has(path)) return;
22946
+ const ssr = getSsrData("md:" + path);
22947
+ if (typeof ssr === "string") {
22948
+ mdPathCache.set(path, ssr);
22949
+ return;
22950
+ }
22951
+ mdPathInflight.add(path);
22952
+ fetch(path).then((r) => r.ok ? r.text() : Promise.reject(r)).then((text) => {
22953
+ mdPathCache.set(path, text);
22954
+ set(getMdPathCell(path), text);
22955
+ }).catch(() => {
22956
+ mdPathCache.set(path, null);
22957
+ set(getMdPathCell(path), null);
22958
+ }).finally(() => {
22959
+ mdPathInflight.delete(path);
22960
+ });
22961
+ }
22962
+ function readServerMdPath(path) {
22963
+ const hook = globalThis.__vsk_md_read_file;
22964
+ if (typeof hook !== "function") return null;
22965
+ try {
22966
+ const out = hook(path);
22967
+ if (typeof out === "string") return out;
22968
+ } catch {
22969
+ }
22970
+ return null;
22971
+ }
22972
+ function resolveMdSource(value) {
22973
+ const s = String(value ?? "");
22974
+ if (!isPublicMarkdownPath(s)) return s;
22975
+ if (mdIsSSR()) {
22976
+ const content = readServerMdPath(s);
22977
+ if (content !== null) {
22978
+ setSsrData("md:" + s, content);
22979
+ return content;
22980
+ }
22981
+ return s;
22982
+ }
22983
+ ensureMdPathLoaded(s);
22984
+ const cached = mdPathCache.get(s);
22985
+ return cached === void 0 || cached === null ? s : cached;
22986
+ }
22987
+ function streamCellFrom(rawContent) {
22988
+ if (rawContent === null || typeof rawContent !== "object") return null;
22989
+ const into = rawContent.into;
22990
+ if (into !== null && typeof into === "object" && typeof into.get === "function") {
22991
+ return into;
22992
+ }
22993
+ return null;
22994
+ }
21943
22995
  function buildHtml(content, props) {
21944
22996
  const global = getMdPolicy();
21945
22997
  const mode = props.html || global.html;
@@ -21976,8 +23028,10 @@ function buildHtml(content, props) {
21976
23028
  }
21977
23029
  function Md(props, _registry, hydrate) {
21978
23030
  const rawContent = props.content;
21979
- const content = String(unwrapMaybeCell(rawContent) ?? "");
21980
- const html = buildHtml(content, props);
23031
+ const streamTarget = streamCellFrom(rawContent);
23032
+ const contentCell = streamTarget ?? rawContent;
23033
+ const content = String(unwrapMaybeCell(contentCell) ?? "");
23034
+ const html = buildHtml(resolveMdSource(content), props);
21981
23035
  const classNameRaw = props.className != null ? String(props.className) : props.class != null ? String(props.class) : "";
21982
23036
  const themeClass = props.theme === "dark" ? " vesk-md-dark" : "";
21983
23037
  const className = `vesk-md${themeClass}${classNameRaw ? " " + classNameRaw : ""}`;
@@ -21988,7 +23042,8 @@ function Md(props, _registry, hydrate) {
21988
23042
  const propFg = safeColorValue(String(props.codeFg ?? ""));
21989
23043
  if (propFg && propFg !== "none") wrapperParts.push(`--md-code-fg:${propFg}`);
21990
23044
  const wrapperStyle = wrapperParts.length > 0 ? escapeHtml3(wrapperParts.join(";")) : "";
21991
- const reactive = isCell(rawContent);
23045
+ const reactive = isCell(contentCell);
23046
+ const pathMode = isPublicMarkdownPath(content);
21992
23047
  if (mdIsSSR()) {
21993
23048
  const attrs = className ? ` class="${escapeHtml3(className)}"` : "";
21994
23049
  const styleAttr = style || wrapperStyle ? ` style="${[wrapperStyle, style.split('"').join("&quot;")].filter(Boolean).join(";")}"` : "";
@@ -22000,11 +23055,19 @@ function Md(props, _registry, hydrate) {
22000
23055
  const existing = hydrate.root.querySelector("div");
22001
23056
  if (existing) el = existing;
22002
23057
  }
22003
- el.innerHTML = html;
23058
+ const claimed = !!el.parentNode;
23059
+ if (pathMode && claimed) {
23060
+ el.setAttribute("data-vsk-md-ssr", "1");
23061
+ if (mdPathCache.has(content)) el.innerHTML = html;
23062
+ } else {
23063
+ el.innerHTML = html;
23064
+ }
22004
23065
  el.className = className;
22005
23066
  el.style.cssText = [wrapperStyle, style].filter(Boolean).join(";");
22006
23067
  wireCopyHandlers(el);
22007
- if (reactive) subscribeContent(el, rawContent, props);
23068
+ if (reactive || pathMode) {
23069
+ subscribeContent(el, contentCell, props, pathMode && claimed ? { trustInitialSsr: true, initialValue: content } : void 0);
23070
+ }
22008
23071
  if (el.parentNode) return document.createDocumentFragment();
22009
23072
  return el;
22010
23073
  }
@@ -22013,21 +23076,41 @@ function Md(props, _registry, hydrate) {
22013
23076
  div.className = className;
22014
23077
  div.style.cssText = [wrapperStyle, style].filter(Boolean).join(";");
22015
23078
  wireCopyHandlers(div);
22016
- if (reactive) subscribeContent(div, rawContent, props);
23079
+ if (reactive || pathMode) subscribeContent(div, contentCell, props);
22017
23080
  return div;
22018
23081
  }
22019
- function subscribeContent(el, rawContent, props) {
23082
+ function subscribeContent(el, rawContent, props, opts) {
23083
+ const trust = opts?.trustInitialSsr === true;
23084
+ const initial = opts?.initialValue;
23085
+ let ran = false;
22020
23086
  effect(() => {
22021
23087
  const value = String(unwrapMaybeCell(rawContent) ?? "");
22022
- el.innerHTML = buildHtml(value, props);
23088
+ if (isPublicMarkdownPath(value)) {
23089
+ const known = getSsrData("md:" + value) !== void 0 || mdPathCache.has(value);
23090
+ ensureMdPathLoaded(value);
23091
+ const cell = getMdPathCell(value);
23092
+ get(cell);
23093
+ if (trust && !ran && value === initial && !known) {
23094
+ ran = true;
23095
+ return;
23096
+ }
23097
+ ran = true;
23098
+ el.innerHTML = buildHtml(resolveMdSource(value), props);
23099
+ wireCopyHandlers(el);
23100
+ return;
23101
+ }
23102
+ ran = true;
23103
+ el.innerHTML = buildHtml(resolveMdSource(value), props);
22023
23104
  wireCopyHandlers(el);
22024
23105
  });
22025
23106
  }
22026
- var COLOR_FUNCS, SAFE_SCHEMES, KW_JS, KW_VSK, LIT_JS, KW_PY, LIT_PY, KW_GO, LIT_GO, KW_RUST, LIT_RUST, KW_SQL, KW_BASH, NAMED_ENTITIES, URL_ATTRS, MD_DEFAULT_ALLOW_TAGS, MD_BASE_CSS, __globalMode, __globalAllowTags, __sessionWarnings, __warnedKeys, __suppressMdConsoleWarnings;
23107
+ var COLOR_FUNCS, SAFE_SCHEMES, KW_JS, KW_VSK, LIT_JS, KW_PY, LIT_PY, KW_GO, LIT_GO, KW_RUST, LIT_RUST, KW_SQL, KW_BASH, NAMED_ENTITIES, URL_ATTRS, MD_DEFAULT_ALLOW_TAGS, MD_BASE_CSS, __globalMode, __globalAllowTags, __sessionWarnings, __warnedKeys, __suppressMdConsoleWarnings, mdPathCache, mdPathCells, mdPathInflight;
22027
23108
  var init_md = __esm({
22028
23109
  "../runtime/src/md.ts"() {
22029
23110
  "use strict";
22030
23111
  init_ripple_blocks();
23112
+ init_ripple_runtime();
23113
+ init_resource();
22031
23114
  COLOR_FUNCS = /* @__PURE__ */ new Set(["rgb", "rgba", "hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "color", "color-mix"]);
22032
23115
  SAFE_SCHEMES = ["http:", "https:", "mailto:", "tel:"];
22033
23116
  KW_JS = /* @__PURE__ */ new Set([
@@ -22429,6 +23512,9 @@ var init_md = __esm({
22429
23512
  __sessionWarnings = [];
22430
23513
  __warnedKeys = /* @__PURE__ */ new Set();
22431
23514
  __suppressMdConsoleWarnings = false;
23515
+ mdPathCache = /* @__PURE__ */ new Map();
23516
+ mdPathCells = /* @__PURE__ */ new Map();
23517
+ mdPathInflight = /* @__PURE__ */ new Set();
22432
23518
  }
22433
23519
  });
22434
23520
 
@@ -23609,7 +24695,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23609
24695
  let latestResultPromise;
23610
24696
  let provideLatestResult;
23611
24697
  if (isContext)
23612
- requestCallbacks["on-end"] = (id, request2) => new Promise((resolve26) => {
24698
+ requestCallbacks["on-end"] = (id, request2) => new Promise((resolve27) => {
23613
24699
  buildResponseToResult(request2, (err, result2, onEndErrors, onEndWarnings) => {
23614
24700
  const response = {
23615
24701
  errors: onEndErrors,
@@ -23619,7 +24705,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23619
24705
  latestResultPromise = void 0;
23620
24706
  provideLatestResult = void 0;
23621
24707
  sendResponse(id, response);
23622
- resolve26();
24708
+ resolve27();
23623
24709
  });
23624
24710
  });
23625
24711
  sendRequest(refs, request, (error, response) => {
@@ -23636,10 +24722,10 @@ is not a problem with esbuild. You need to fix your environment instead.
23636
24722
  let didDispose = false;
23637
24723
  const result2 = {
23638
24724
  rebuild: () => {
23639
- if (!latestResultPromise) latestResultPromise = new Promise((resolve26, reject) => {
24725
+ if (!latestResultPromise) latestResultPromise = new Promise((resolve27, reject) => {
23640
24726
  let settlePromise;
23641
24727
  provideLatestResult = (err, result22) => {
23642
- if (!settlePromise) settlePromise = () => err ? reject(err) : resolve26(result22);
24728
+ if (!settlePromise) settlePromise = () => err ? reject(err) : resolve27(result22);
23643
24729
  };
23644
24730
  const triggerAnotherBuild = () => {
23645
24731
  const request2 = {
@@ -23660,7 +24746,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23660
24746
  });
23661
24747
  return latestResultPromise;
23662
24748
  },
23663
- watch: (options22 = {}) => new Promise((resolve26, reject) => {
24749
+ watch: (options22 = {}) => new Promise((resolve27, reject) => {
23664
24750
  if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
23665
24751
  const keys = {};
23666
24752
  const delay = getFlag(options22, keys, "delay", mustBeInteger);
@@ -23672,10 +24758,10 @@ is not a problem with esbuild. You need to fix your environment instead.
23672
24758
  if (delay) request2.delay = delay;
23673
24759
  sendRequest(refs, request2, (error2) => {
23674
24760
  if (error2) reject(new Error(error2));
23675
- else resolve26(void 0);
24761
+ else resolve27(void 0);
23676
24762
  });
23677
24763
  }),
23678
- serve: (options22 = {}) => new Promise((resolve26, reject) => {
24764
+ serve: (options22 = {}) => new Promise((resolve27, reject) => {
23679
24765
  if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
23680
24766
  const keys = {};
23681
24767
  const port2 = getFlag(options22, keys, "port", mustBeValidPortNumber);
@@ -23713,28 +24799,28 @@ is not a problem with esbuild. You need to fix your environment instead.
23713
24799
  sendResponse(id, {});
23714
24800
  };
23715
24801
  }
23716
- resolve26(response2);
24802
+ resolve27(response2);
23717
24803
  });
23718
24804
  }),
23719
- cancel: () => new Promise((resolve26) => {
23720
- if (didDispose) return resolve26();
24805
+ cancel: () => new Promise((resolve27) => {
24806
+ if (didDispose) return resolve27();
23721
24807
  const request2 = {
23722
24808
  command: "cancel",
23723
24809
  key: buildKey
23724
24810
  };
23725
24811
  sendRequest(refs, request2, () => {
23726
- resolve26();
24812
+ resolve27();
23727
24813
  });
23728
24814
  }),
23729
- dispose: () => new Promise((resolve26) => {
23730
- if (didDispose) return resolve26();
24815
+ dispose: () => new Promise((resolve27) => {
24816
+ if (didDispose) return resolve27();
23731
24817
  didDispose = true;
23732
24818
  const request2 = {
23733
24819
  command: "dispose",
23734
24820
  key: buildKey
23735
24821
  };
23736
24822
  sendRequest(refs, request2, () => {
23737
- resolve26();
24823
+ resolve27();
23738
24824
  scheduleOnDisposeCallbacks();
23739
24825
  refs.unref();
23740
24826
  });
@@ -23773,7 +24859,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23773
24859
  onLoad: []
23774
24860
  };
23775
24861
  i++;
23776
- let resolve26 = (path3, options2 = {}) => {
24862
+ let resolve27 = (path3, options2 = {}) => {
23777
24863
  if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
23778
24864
  if (typeof path3 !== "string") throw new Error(`The path to resolve must be a string`);
23779
24865
  let keys2 = /* @__PURE__ */ Object.create(null);
@@ -23785,7 +24871,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23785
24871
  let pluginData = getFlag(options2, keys2, "pluginData", canBeAnything);
23786
24872
  let importAttributes = getFlag(options2, keys2, "with", mustBeObject);
23787
24873
  checkForInvalidFlags(options2, keys2, "in resolve() call");
23788
- return new Promise((resolve27, reject) => {
24874
+ return new Promise((resolve28, reject) => {
23789
24875
  const request = {
23790
24876
  command: "resolve",
23791
24877
  path: path3,
@@ -23802,7 +24888,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23802
24888
  if (importAttributes != null) request.with = sanitizeStringMap(importAttributes, "with");
23803
24889
  sendRequest(refs, request, (error, response) => {
23804
24890
  if (error !== null) reject(new Error(error));
23805
- else resolve27({
24891
+ else resolve28({
23806
24892
  errors: replaceDetailsInMessages(response.errors, details),
23807
24893
  warnings: replaceDetailsInMessages(response.warnings, details),
23808
24894
  path: response.path,
@@ -23817,7 +24903,7 @@ is not a problem with esbuild. You need to fix your environment instead.
23817
24903
  };
23818
24904
  let promise = setup({
23819
24905
  initialOptions,
23820
- resolve: resolve26,
24906
+ resolve: resolve27,
23821
24907
  onStart(callback) {
23822
24908
  let registeredText = `This error came from the "onStart" callback registered here:`;
23823
24909
  let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
@@ -24510,46 +25596,46 @@ More information: The file containing the code for esbuild's JavaScript API (${_
24510
25596
  }
24511
25597
  };
24512
25598
  longLivedService = {
24513
- build: (options2) => new Promise((resolve26, reject) => {
25599
+ build: (options2) => new Promise((resolve27, reject) => {
24514
25600
  service.buildOrContext({
24515
25601
  callName: "build",
24516
25602
  refs,
24517
25603
  options: options2,
24518
25604
  isTTY: isTTY(),
24519
25605
  defaultWD,
24520
- callback: (err, res) => err ? reject(err) : resolve26(res)
25606
+ callback: (err, res) => err ? reject(err) : resolve27(res)
24521
25607
  });
24522
25608
  }),
24523
- context: (options2) => new Promise((resolve26, reject) => service.buildOrContext({
25609
+ context: (options2) => new Promise((resolve27, reject) => service.buildOrContext({
24524
25610
  callName: "context",
24525
25611
  refs,
24526
25612
  options: options2,
24527
25613
  isTTY: isTTY(),
24528
25614
  defaultWD,
24529
- callback: (err, res) => err ? reject(err) : resolve26(res)
25615
+ callback: (err, res) => err ? reject(err) : resolve27(res)
24530
25616
  })),
24531
- transform: (input, options2) => new Promise((resolve26, reject) => service.transform({
25617
+ transform: (input, options2) => new Promise((resolve27, reject) => service.transform({
24532
25618
  callName: "transform",
24533
25619
  refs,
24534
25620
  input,
24535
25621
  options: options2 || {},
24536
25622
  isTTY: isTTY(),
24537
25623
  fs: fsAsync,
24538
- callback: (err, res) => err ? reject(err) : resolve26(res)
25624
+ callback: (err, res) => err ? reject(err) : resolve27(res)
24539
25625
  })),
24540
- formatMessages: (messages, options2) => new Promise((resolve26, reject) => service.formatMessages({
25626
+ formatMessages: (messages, options2) => new Promise((resolve27, reject) => service.formatMessages({
24541
25627
  callName: "formatMessages",
24542
25628
  refs,
24543
25629
  messages,
24544
25630
  options: options2,
24545
- callback: (err, res) => err ? reject(err) : resolve26(res)
25631
+ callback: (err, res) => err ? reject(err) : resolve27(res)
24546
25632
  })),
24547
- analyzeMetafile: (metafile, options2) => new Promise((resolve26, reject) => service.analyzeMetafile({
25633
+ analyzeMetafile: (metafile, options2) => new Promise((resolve27, reject) => service.analyzeMetafile({
24548
25634
  callName: "analyzeMetafile",
24549
25635
  refs,
24550
25636
  metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
24551
25637
  options: options2,
24552
- callback: (err, res) => err ? reject(err) : resolve26(res)
25638
+ callback: (err, res) => err ? reject(err) : resolve27(res)
24553
25639
  }))
24554
25640
  };
24555
25641
  return longLivedService;
@@ -24627,13 +25713,13 @@ error: ${text}`);
24627
25713
  worker.postMessage(msg);
24628
25714
  let status = Atomics.wait(sharedBufferView, 0, 0);
24629
25715
  if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
24630
- let { message: { id: id2, resolve: resolve26, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
25716
+ let { message: { id: id2, resolve: resolve27, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
24631
25717
  if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
24632
25718
  if (reject) {
24633
25719
  applyProperties(reject, properties);
24634
25720
  throw reject;
24635
25721
  }
24636
- return resolve26;
25722
+ return resolve27;
24637
25723
  };
24638
25724
  worker.unref();
24639
25725
  return {
@@ -25025,8 +26111,8 @@ var init_server_head = __esm({
25025
26111
 
25026
26112
  // ../compiler/src/actions.ts
25027
26113
  import { walk as walk2 } from "zimmerframe";
25028
- import { print as print3 } from "esrap";
25029
- import ts3 from "esrap/languages/ts";
26114
+ import { print as print4 } from "esrap";
26115
+ import ts4 from "esrap/languages/ts";
25030
26116
  function hashString2(str) {
25031
26117
  let h1 = 2166136261;
25032
26118
  let h2 = 16777619;
@@ -25090,7 +26176,7 @@ function printWithTypesStripped(ast, code, hadTs = hasTsSyntax(ast)) {
25090
26176
  stripped.body = stripped.body.filter((n) => !isTypeOnlyStatement(n));
25091
26177
  }
25092
26178
  try {
25093
- return print3(stripped, ts3()).code;
26179
+ return print4(stripped, ts4()).code;
25094
26180
  } catch {
25095
26181
  return code;
25096
26182
  }
@@ -25163,8 +26249,8 @@ var init_actions = __esm({
25163
26249
  });
25164
26250
 
25165
26251
  // ../compiler/src/md-inline.ts
25166
- import { readFileSync, existsSync as existsSync3 } from "node:fs";
25167
- import { dirname as dirname3, join as join2, resolve as resolve3 } from "node:path";
26252
+ import { readFileSync as readFileSync2, existsSync as existsSync3 } from "node:fs";
26253
+ import { dirname as dirname4, join as join3, resolve as resolve4 } from "node:path";
25168
26254
  function looksLikeMarkdownPath(value) {
25169
26255
  const v = value.trim();
25170
26256
  if (v.length === 0 || v.length > 4096) return false;
@@ -25201,7 +26287,7 @@ function inlineMdContentAttrs(source, importerDir, mdRoots = []) {
25201
26287
  if (abs !== null) {
25202
26288
  let contents;
25203
26289
  try {
25204
- contents = readFileSync(abs, "utf-8");
26290
+ contents = readFileSync2(abs, "utf-8");
25205
26291
  } catch {
25206
26292
  out += source[i];
25207
26293
  i++;
@@ -25228,14 +26314,14 @@ function resolveMdPath(specifier, importerDir, roots) {
25228
26314
  const spec = specifier.trim();
25229
26315
  if (isRelativeSpecifier(spec)) {
25230
26316
  if (!importerDir) return null;
25231
- const abs = resolve3(importerDir, spec);
26317
+ const abs = resolve4(importerDir, spec);
25232
26318
  return existsSync3(abs) ? abs : null;
25233
26319
  }
25234
26320
  if (spec.startsWith("/")) {
25235
26321
  for (const root3 of roots) {
25236
- const pub = join2(root3, "public", spec);
26322
+ const pub = join3(root3, "public", spec);
25237
26323
  if (existsSync3(pub)) return pub;
25238
- const direct = join2(root3, spec);
26324
+ const direct = join3(root3, spec);
25239
26325
  if (existsSync3(direct)) return direct;
25240
26326
  }
25241
26327
  }
@@ -25247,15 +26333,15 @@ function guessProjectRoots(dir) {
25247
26333
  let cur = dir;
25248
26334
  for (let i = 0; i < 6; i++) {
25249
26335
  roots.push(cur);
25250
- if (existsSync3(join2(cur, "package.json"))) break;
25251
- const parent = dirname3(cur);
26336
+ if (existsSync3(join3(cur, "package.json"))) break;
26337
+ const parent = dirname4(cur);
25252
26338
  if (parent === cur) break;
25253
26339
  cur = parent;
25254
26340
  }
25255
26341
  return roots;
25256
26342
  }
25257
26343
  function inlineMdImportsFrom(source, importerFile, mdRoots = []) {
25258
- const dir = importerFile ? dirname3(importerFile) : null;
26344
+ const dir = importerFile ? dirname4(importerFile) : null;
25259
26345
  return inlineMdContentAttrs(source, dir, mdRoots.length > 0 ? mdRoots : [dir || process.cwd()]);
25260
26346
  }
25261
26347
  var MD_EXT_MARKER;
@@ -25268,8 +26354,8 @@ var init_md_inline = __esm({
25268
26354
 
25269
26355
  // ../compiler/src/client-codegen.ts
25270
26356
  import { walk as walk3 } from "zimmerframe";
25271
- import { print as print4 } from "esrap";
25272
- import ts4 from "esrap/languages/ts";
26357
+ import { print as print5 } from "esrap";
26358
+ import ts5 from "esrap/languages/ts";
25273
26359
  import tsx from "esrap/languages/tsx";
25274
26360
  function callExpr(callee, args2 = []) {
25275
26361
  return { type: "CallExpression", callee, arguments: args2, optional: false };
@@ -25306,7 +26392,7 @@ function containsJsx(node, depth = 0) {
25306
26392
  return false;
25307
26393
  }
25308
26394
  function printAst(ast) {
25309
- return print4(ast, containsJsx(ast) ? tsx() : ts4()).code;
26395
+ return print5(ast, containsJsx(ast) ? tsx() : ts5()).code;
25310
26396
  }
25311
26397
  function transformTracked(irNode, tracked2) {
25312
26398
  const ast = irNode.ast;
@@ -25390,7 +26476,7 @@ function transformTracked(irNode, tracked2) {
25390
26476
  return context.next();
25391
26477
  }
25392
26478
  });
25393
- return print4(transformed, containsJsx(transformed) ? tsx() : ts4()).code;
26479
+ return print5(transformed, containsJsx(transformed) ? tsx() : ts5()).code;
25394
26480
  }
25395
26481
  function collectTrackedNames(body) {
25396
26482
  const names = /* @__PURE__ */ new Map();
@@ -26471,7 +27557,12 @@ function emitClientFromIR(ir, options2) {
26471
27557
  runtimeNames.push(name);
26472
27558
  }
26473
27559
  }
26474
- const runtimeImport = `import { ${runtimeNames.join(", ")} } from '@vesk/runtime';`;
27560
+ const boundLocally = /* @__PURE__ */ new Set();
27561
+ for (const imp of ir.imports) {
27562
+ for (const pair of importBindingPairs(imp)) boundLocally.add(pair.local);
27563
+ }
27564
+ const shadowedRuntimeNames = runtimeNames.filter((n) => !boundLocally.has(n));
27565
+ const runtimeImport = `import { ${shadowedRuntimeNames.length > 0 ? shadowedRuntimeNames.join(", ") : "destroy_block"} } from '@vesk/runtime';`;
26475
27566
  const moduleCode = `
26476
27567
  ${runtimeImport}
26477
27568
  ${importLines}
@@ -26517,6 +27608,7 @@ var init_client_codegen = __esm({
26517
27608
  init_ir_generator();
26518
27609
  init_actions();
26519
27610
  init_server_utils();
27611
+ init_module_imports();
26520
27612
  init_scan();
26521
27613
  init_md_inline();
26522
27614
  init_strip_ts();
@@ -26973,18 +28065,21 @@ function generateFunctionBody(comp, importedNames) {
26973
28065
  function buildComponentMap2(irRoot, useSharedScope) {
26974
28066
  const map = /* @__PURE__ */ new Map();
26975
28067
  const runtimeNames = extractRuntimeNames(irRoot.imports);
26976
- const importedNames = new Set(runtimeNames);
28068
+ const localValueNames = localValueImportNames(irRoot.imports);
28069
+ const importedNames = /* @__PURE__ */ new Set([...runtimeNames, ...localValueNames]);
26977
28070
  const topNames = extractTopLevelNames(irRoot.topLevelCode);
26978
28071
  const hasTracked = irRoot.components.some((c) => c.body.some((n) => n instanceof TrackDecl));
26979
28072
  const extraNames = hasTracked ? ["get", "set", "track"] : [];
26980
- const allNames = [.../* @__PURE__ */ new Set([...runtimeNames, ...topNames, ...extraNames])];
28073
+ const allNames = [.../* @__PURE__ */ new Set([...runtimeNames, ...topNames, ...extraNames, ...localValueNames])];
26981
28074
  const scopeDecl = allNames.length > 0 ? `const { ${allNames.join(", ")} } = __vesk;
26982
28075
  ` : "";
26983
28076
  setVskImportedNames(importedNames);
26984
28077
  for (const comp of irRoot.components) {
26985
28078
  const bodyCode = generateFunctionBody(comp, importedNames);
26986
28079
  const paramInit = buildParamInit(comp.paramNames);
26987
- const code = `${scopeDecl}${paramInit}
28080
+ const diag = process.env.VESK_SSR_LOG ? `console.error('[SSR-CALL]', ${JSON.stringify(comp.name)}, props ? JSON.stringify(props) : String(props));
28081
+ ` : "";
28082
+ const code = `${scopeDecl}${paramInit}${diag}
26988
28083
  ${bodyCode}`;
26989
28084
  let fn;
26990
28085
  if (comp.isAsync || comp.ssrAwait) {
@@ -27007,6 +28102,7 @@ var init_server_jsgen = __esm({
27007
28102
  init_client_codegen();
27008
28103
  init_scan();
27009
28104
  init_server_utils();
28105
+ init_module_imports();
27010
28106
  __currentCompName = "";
27011
28107
  }
27012
28108
  });
@@ -27056,34 +28152,39 @@ __export(server_render_exports, {
27056
28152
  renderPageStream: () => renderPageStream,
27057
28153
  ssg: () => ssg
27058
28154
  });
27059
- import { readFileSync as readFileSync2 } from "node:fs";
27060
- import { dirname as dirname4 } from "node:path";
28155
+ import { readFileSync as readFileSync3 } from "node:fs";
28156
+ import { dirname as dirname5 } from "node:path";
27061
28157
  function compileFile(source, options2) {
27062
28158
  return compileFileInternal(source, options2?.sourcePath, /* @__PURE__ */ new Set());
27063
28159
  }
27064
28160
  function compileFileInternal(source, sourcePath2, seenImportFiles) {
27065
28161
  if (sourcePath2) {
27066
- const dir = dirname4(sourcePath2);
28162
+ const dir = dirname5(sourcePath2);
27067
28163
  source = inlineMdImportsFrom(source, sourcePath2, guessProjectRoots(dir));
27068
28164
  }
27069
28165
  const ast = parse4(source);
27070
28166
  const ir = generateIR(ast, source);
27071
28167
  const componentMap = buildComponentMap2(ir, true);
28168
+ const __vesk = loadRuntimeImports(ir.imports);
28169
+ applyLocalModuleImports(__vesk, ir.imports, sourcePath2);
27072
28170
  if (sourcePath2) {
27073
28171
  for (const importPath of collectVskImportPaths(ir.imports, sourcePath2)) {
27074
28172
  if (seenImportFiles.has(importPath)) continue;
27075
28173
  seenImportFiles.add(importPath);
27076
28174
  try {
27077
- const importedSrc = readFileSync2(importPath, "utf-8");
28175
+ const importedSrc = readFileSync3(importPath, "utf-8");
27078
28176
  const sub = compileFileInternal(importedSrc, importPath, seenImportFiles);
27079
28177
  for (const [name, fn] of sub.componentMap) {
27080
28178
  if (!componentMap.has(name)) componentMap.set(name, fn);
27081
28179
  }
28180
+ for (const key of Object.keys(sub.__vesk)) {
28181
+ if (key in __vesk) continue;
28182
+ __vesk[key] = sub.__vesk[key];
28183
+ }
27082
28184
  } catch {
27083
28185
  }
27084
28186
  }
27085
28187
  }
27086
- const __vesk = loadRuntimeImports(ir.imports);
27087
28188
  evalTopLevelCode(transformTopLevelForActions(ir.topLevelCode, "server"), __vesk);
27088
28189
  return { ir, componentMap, __vesk };
27089
28190
  }
@@ -27341,7 +28442,11 @@ function renderPageStream(source, componentName, props = {}, registry = /* @__PU
27341
28442
  const ir = cached ? cached.ir : generateIR(parse4(source), source);
27342
28443
  let ssrProps = { ...props };
27343
28444
  let serializedProps = null;
27344
- let __vesk = options2.__vesk || cached?.__vesk || loadRuntimeImports(ir.imports);
28445
+ let __vesk = options2.__vesk || cached?.__vesk || null;
28446
+ if (!__vesk) {
28447
+ __vesk = loadRuntimeImports(ir.imports);
28448
+ applyLocalModuleImports(__vesk, ir.imports, options2.sourcePath || void 0);
28449
+ }
27345
28450
  if (ir.loadFn) {
27346
28451
  const loadResult = await callLoadFunction(ir.loadFn, props, __vesk);
27347
28452
  if (loadResult && typeof loadResult === "object") {
@@ -27428,18 +28533,38 @@ var init_server_render = __esm({
27428
28533
  init_vsk_imports();
27429
28534
  init_md_inline();
27430
28535
  init_ssr_store();
28536
+ init_module_imports();
27431
28537
  }
27432
28538
  });
27433
28539
 
27434
28540
  // ../adapter/src/paths.ts
27435
- import { resolve as resolve8, sep as sep2 } from "node:path";
28541
+ import { resolve as resolve9, sep as sep2 } from "node:path";
28542
+ import { existsSync as existsSync8, statSync as statSync4, readFileSync as readFileSync9 } from "node:fs";
27436
28543
  function resolveWithin(baseDir, relPath) {
27437
- const base = resolve8(baseDir);
27438
- const target = resolve8(baseDir, relPath);
28544
+ const base = resolve9(baseDir);
28545
+ const target = resolve9(baseDir, relPath);
27439
28546
  const prefix = base + sep2;
27440
28547
  if (!target.startsWith(prefix)) return null;
27441
28548
  return target;
27442
28549
  }
28550
+ function installMdReadHook(publicDirs) {
28551
+ const dirs = publicDirs.map((d) => resolve9(d));
28552
+ globalThis.__vsk_md_read_file = (p) => {
28553
+ for (const dir of dirs) {
28554
+ try {
28555
+ let rel = String(p);
28556
+ while (rel.length > 0 && rel.charCodeAt(0) === 47) rel = rel.slice(1);
28557
+ const abs = resolveWithin(dir, rel);
28558
+ if (!abs) continue;
28559
+ const lower = abs.toLowerCase();
28560
+ if (!lower.endsWith(".md") && !lower.endsWith(".markdown")) continue;
28561
+ if (existsSync8(abs) && statSync4(abs).isFile()) return readFileSync9(abs, "utf8");
28562
+ } catch {
28563
+ }
28564
+ }
28565
+ return null;
28566
+ };
28567
+ }
27443
28568
  var init_paths = __esm({
27444
28569
  "../adapter/src/paths.ts"() {
27445
28570
  "use strict";
@@ -27454,20 +28579,20 @@ __export(static_exports, {
27454
28579
  generateSitemap: () => generateSitemap,
27455
28580
  generateSsgRoutes: () => generateSsgRoutes
27456
28581
  });
27457
- import { mkdirSync as mkdirSync2, copyFileSync as copyFileSync2, readdirSync as readdirSync3, statSync as statSync5, existsSync as existsSync10, writeFileSync as writeFileSync4, readFileSync as readFileSync10 } from "node:fs";
27458
- import { resolve as resolve11, join as join6 } from "node:path";
28582
+ import { mkdirSync as mkdirSync2, copyFileSync as copyFileSync2, readdirSync as readdirSync3, statSync as statSync7, existsSync as existsSync11, writeFileSync as writeFileSync4, readFileSync as readFileSync12 } from "node:fs";
28583
+ import { resolve as resolve12, join as join7 } from "node:path";
27459
28584
  function copyStaticAssets2(publicDir, outDir2) {
27460
- const targetDir = resolve11(outDir2, "static", "public");
28585
+ const targetDir = resolve12(outDir2, "static", "public");
27461
28586
  mkdirSync2(targetDir, { recursive: true });
27462
- if (!existsSync10(publicDir))
28587
+ if (!existsSync11(publicDir))
27463
28588
  return;
27464
28589
  function copyDir(src2, dest) {
27465
28590
  mkdirSync2(dest, { recursive: true });
27466
28591
  const entries = readdirSync3(src2);
27467
28592
  for (const entry of entries) {
27468
- const srcPath = join6(src2, entry);
27469
- const destPath = join6(dest, entry);
27470
- const st = statSync5(srcPath);
28593
+ const srcPath = join7(src2, entry);
28594
+ const destPath = join7(dest, entry);
28595
+ const st = statSync7(srcPath);
27471
28596
  if (st.isDirectory()) {
27472
28597
  copyDir(srcPath, destPath);
27473
28598
  } else {
@@ -27479,7 +28604,7 @@ function copyStaticAssets2(publicDir, outDir2) {
27479
28604
  }
27480
28605
  async function generateSsgRoutes(routeTree, appDir, outDir2) {
27481
28606
  const { ssg: ssg2 } = await Promise.resolve().then(() => (init_server_render(), server_render_exports));
27482
- const prerenderDir = resolve11(outDir2, "prerendered");
28607
+ const prerenderDir = resolve12(outDir2, "prerendered");
27483
28608
  mkdirSync2(prerenderDir, { recursive: true });
27484
28609
  const results = [];
27485
28610
  async function evaluateExport(src2, exportName) {
@@ -27498,8 +28623,8 @@ async function generateSsgRoutes(routeTree, appDir, outDir2) {
27498
28623
  async function walk6(nodes) {
27499
28624
  for (const node of nodes) {
27500
28625
  if (node.page) {
27501
- const pagePath = resolve11(appDir, node.sourceDir, "page.vsk");
27502
- const src2 = readFileSync10(pagePath, "utf-8");
28626
+ const pagePath = resolve12(appDir, node.sourceDir, "page.vsk");
28627
+ const src2 = readFileSync12(pagePath, "utf-8");
27503
28628
  const hasStaticProps = src2.includes("getStaticProps");
27504
28629
  const hasStaticPaths = src2.includes("getStaticPaths");
27505
28630
  if (hasStaticPaths) {
@@ -27516,7 +28641,7 @@ async function generateSsgRoutes(routeTree, appDir, outDir2) {
27516
28641
  console.error(`vesk: SSG path escaped output dir \u2014 skipping ${pagePath} (path: ${urlPath})`);
27517
28642
  continue;
27518
28643
  }
27519
- mkdirSync2(resolve11(htmlPath, ".."), { recursive: true });
28644
+ mkdirSync2(resolve12(htmlPath, ".."), { recursive: true });
27520
28645
  writeFileSync4(htmlPath, result2.html);
27521
28646
  results.push({ path: urlPath, html: htmlPath, static: result2.static, params });
27522
28647
  } catch (e) {
@@ -27528,8 +28653,8 @@ async function generateSsgRoutes(routeTree, appDir, outDir2) {
27528
28653
  } else if (hasStaticProps) {
27529
28654
  try {
27530
28655
  const result2 = await ssg2(src2, null, void 0, {});
27531
- const htmlPath = resolve11(prerenderDir, node.fullPath === "/" ? "index.html" : `${node.fullPath.slice(1)}.html`);
27532
- mkdirSync2(resolve11(htmlPath, ".."), { recursive: true });
28656
+ const htmlPath = resolve12(prerenderDir, node.fullPath === "/" ? "index.html" : `${node.fullPath.slice(1)}.html`);
28657
+ mkdirSync2(resolve12(htmlPath, ".."), { recursive: true });
27533
28658
  writeFileSync4(htmlPath, result2.html);
27534
28659
  results.push({ path: node.fullPath, html: htmlPath, static: result2.static });
27535
28660
  } catch (e) {
@@ -27599,15 +28724,15 @@ var image_pipeline_exports = {};
27599
28724
  __export(image_pipeline_exports, {
27600
28725
  optimizeImages: () => optimizeImages
27601
28726
  });
27602
- import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync5, readFileSync as readFileSync11, existsSync as existsSync11, readdirSync as readdirSync4, statSync as statSync6 } from "node:fs";
27603
- import { resolve as resolve12, extname as extname3, dirname as dirname7 } from "node:path";
28727
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync5, readFileSync as readFileSync13, existsSync as existsSync12, readdirSync as readdirSync4, statSync as statSync8 } from "node:fs";
28728
+ import { resolve as resolve13, extname as extname4, dirname as dirname8 } from "node:path";
27604
28729
  async function processImage(srcPath, outDir2, baseName) {
27605
28730
  const image = sharpFn ? sharpFn(srcPath) : null;
27606
28731
  if (!image) {
27607
- const original = readFileSync11(srcPath);
28732
+ const original = readFileSync13(srcPath);
27608
28733
  for (const w of OUTPUT_WIDTHS) {
27609
- const outputPath = resolve12(outDir2, `${baseName}-${w}w`);
27610
- mkdirSync3(dirname7(outputPath), { recursive: true });
28734
+ const outputPath = resolve13(outDir2, `${baseName}-${w}w`);
28735
+ mkdirSync3(dirname8(outputPath), { recursive: true });
27611
28736
  writeFileSync5(outputPath, original);
27612
28737
  }
27613
28738
  return [];
@@ -27620,12 +28745,12 @@ async function processImage(srcPath, outDir2, baseName) {
27620
28745
  continue;
27621
28746
  const resized = image.clone().resize({ width: w, withoutEnlargement: true });
27622
28747
  const base = `${baseName}-${w}w`;
27623
- const jpgPath = resolve12(outDir2, `${base}${extname3(srcPath)}`);
27624
- mkdirSync3(dirname7(jpgPath), { recursive: true });
28748
+ const jpgPath = resolve13(outDir2, `${base}${extname4(srcPath)}`);
28749
+ mkdirSync3(dirname8(jpgPath), { recursive: true });
27625
28750
  await resized.toFile(jpgPath);
27626
28751
  generated.push(jpgPath);
27627
28752
  for (const fmt of FORMATS) {
27628
- const fmtPath = resolve12(outDir2, `${base}.${fmt}`);
28753
+ const fmtPath = resolve13(outDir2, `${base}.${fmt}`);
27629
28754
  await resized.toFormat(fmt, { quality: 80 }).toFile(fmtPath);
27630
28755
  generated.push(fmtPath);
27631
28756
  }
@@ -27642,14 +28767,14 @@ function collectImageRefs(appDir) {
27642
28767
  return;
27643
28768
  }
27644
28769
  for (const entry of entries) {
27645
- const full = resolve12(dir, entry);
27646
- const st = statSync6(full);
28770
+ const full = resolve13(dir, entry);
28771
+ const st = statSync8(full);
27647
28772
  if (st.isDirectory()) {
27648
28773
  if (entry.startsWith("."))
27649
28774
  continue;
27650
28775
  walk6(full);
27651
28776
  } else if (entry === "page.vsk") {
27652
- const src2 = readFileSync11(full, "utf-8");
28777
+ const src2 = readFileSync13(full, "utf-8");
27653
28778
  const imgRegex = /<Image\s+src=["']([^"']+)["']/g;
27654
28779
  let m;
27655
28780
  while ((m = imgRegex.exec(src2)) !== null) {
@@ -27662,7 +28787,7 @@ function collectImageRefs(appDir) {
27662
28787
  return refs;
27663
28788
  }
27664
28789
  async function optimizeImages(appDir, outDir2) {
27665
- const imageOutDir = resolve12(outDir2, "static", "images");
28790
+ const imageOutDir = resolve13(outDir2, "static", "images");
27666
28791
  mkdirSync3(imageOutDir, { recursive: true });
27667
28792
  const refs = collectImageRefs(appDir);
27668
28793
  if (refs.length === 0) {
@@ -27672,14 +28797,14 @@ async function optimizeImages(appDir, outDir2) {
27672
28797
  const results = [];
27673
28798
  for (const ref2 of refs) {
27674
28799
  const possiblePaths = [
27675
- resolve12(appDir, ref2.src),
27676
- resolve12(appDir, "..", "public", ref2.src.replace(/^\//, "")),
27677
- resolve12(appDir, "..", "src", ref2.src.replace(/^\//, "")),
27678
- resolve12(outDir2, "static", "public", ref2.src.replace(/^\//, ""))
28800
+ resolve13(appDir, ref2.src),
28801
+ resolve13(appDir, "..", "public", ref2.src.replace(/^\//, "")),
28802
+ resolve13(appDir, "..", "src", ref2.src.replace(/^\//, "")),
28803
+ resolve13(outDir2, "static", "public", ref2.src.replace(/^\//, ""))
27679
28804
  ];
27680
28805
  let srcPath = null;
27681
28806
  for (const p of possiblePaths) {
27682
- if (existsSync11(p)) {
28807
+ if (existsSync12(p)) {
27683
28808
  srcPath = p;
27684
28809
  break;
27685
28810
  }
@@ -27688,12 +28813,12 @@ async function optimizeImages(appDir, outDir2) {
27688
28813
  console.error(`vesk images: not found \u2014 ${ref2.src} (referenced by ${ref2.source})`);
27689
28814
  continue;
27690
28815
  }
27691
- const ext = extname3(srcPath).toLowerCase();
28816
+ const ext = extname4(srcPath).toLowerCase();
27692
28817
  if (!SUPPORTED.has(ext)) {
27693
28818
  console.error(`vesk images: unsupported format \u2014 ${ref2.src} (${ext})`);
27694
28819
  continue;
27695
28820
  }
27696
- const baseName = ref2.src.replace(/^\//, "").replace(extname3(ref2.src), "");
28821
+ const baseName = ref2.src.replace(/^\//, "").replace(extname4(ref2.src), "");
27697
28822
  const files = await processImage(srcPath, imageOutDir, baseName);
27698
28823
  results.push({ src: ref2.src, baseName, files, widths: OUTPUT_WIDTHS });
27699
28824
  console.error(`vesk images: ${ref2.src} \u2192 ${files.length} variants`);
@@ -27726,8 +28851,8 @@ var seo_audit_exports = {};
27726
28851
  __export(seo_audit_exports, {
27727
28852
  runSeoAudit: () => runSeoAudit
27728
28853
  });
27729
- import { readFileSync as readFileSync12, existsSync as existsSync12, readdirSync as readdirSync5, statSync as statSync7 } from "node:fs";
27730
- import { resolve as resolve13 } from "node:path";
28854
+ import { readFileSync as readFileSync14, existsSync as existsSync13, readdirSync as readdirSync5, statSync as statSync9 } from "node:fs";
28855
+ import { resolve as resolve14 } from "node:path";
27731
28856
  function walkFiles(dir) {
27732
28857
  const results = [];
27733
28858
  let entries;
@@ -27737,8 +28862,8 @@ function walkFiles(dir) {
27737
28862
  return results;
27738
28863
  }
27739
28864
  for (const entry of entries) {
27740
- const full = resolve13(dir, entry);
27741
- const st = statSync7(full);
28865
+ const full = resolve14(dir, entry);
28866
+ const st = statSync9(full);
27742
28867
  if (st.isDirectory()) {
27743
28868
  if (!entry.startsWith("."))
27744
28869
  results.push(...walkFiles(full));
@@ -27752,10 +28877,10 @@ function collectCombinedSource(appDir) {
27752
28877
  const pages = files.filter((f) => f.endsWith("/page.vsk") || f.endsWith("\\page.vsk"));
27753
28878
  const combined = [];
27754
28879
  for (const pagePath of pages) {
27755
- const dir = resolve13(pagePath, "..");
27756
- const layoutPath = resolve13(dir, "layout.vsk");
27757
- const pageSrc = readFileSync12(pagePath, "utf-8");
27758
- const layoutSrc = existsSync12(layoutPath) ? readFileSync12(layoutPath, "utf-8") : "";
28880
+ const dir = resolve14(pagePath, "..");
28881
+ const layoutPath = resolve14(dir, "layout.vsk");
28882
+ const pageSrc = readFileSync14(pagePath, "utf-8");
28883
+ const layoutSrc = existsSync13(layoutPath) ? readFileSync14(layoutPath, "utf-8") : "";
27759
28884
  const combinedSrc = layoutSrc ? layoutSrc + "\n" + pageSrc : pageSrc;
27760
28885
  combined.push({
27761
28886
  path: pagePath,
@@ -27930,8 +29055,8 @@ var init_platform = __esm({
27930
29055
  });
27931
29056
 
27932
29057
  // ../adapter/src/platform-handler.ts
27933
- import { existsSync as existsSync13 } from "node:fs";
27934
- import { resolve as resolve14, dirname as dirname8 } from "node:path";
29058
+ import { existsSync as existsSync14 } from "node:fs";
29059
+ import { resolve as resolve15, dirname as dirname9 } from "node:path";
27935
29060
  import { fileURLToPath as fileURLToPath4 } from "node:url";
27936
29061
  function routeName2(segments) {
27937
29062
  const parts = segments.filter(Boolean).map((s) => {
@@ -27948,8 +29073,8 @@ function toId(s) {
27948
29073
  return s.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^_/, "");
27949
29074
  }
27950
29075
  function findCompilerSrc2() {
27951
- const monorepo = resolve14(__dirname5, "..", "..", "..", "packages", "compiler", "dist");
27952
- if (existsSync13(monorepo)) return monorepo;
29076
+ const monorepo = resolve15(__dirname5, "..", "..", "..", "packages", "compiler", "dist");
29077
+ if (existsSync14(monorepo)) return monorepo;
27953
29078
  throw new Error('@vesk/compiler/dist not found \u2014 run "npm run build" first');
27954
29079
  }
27955
29080
  function generatePlatformHandlerSource(input) {
@@ -27980,7 +29105,7 @@ function generatePlatformHandlerSource(input) {
27980
29105
  ` : "const __prerendered = new Set();\n";
27981
29106
  const isrCache = "const __isrCache = new Map();";
27982
29107
  const compilerSrc = findCompilerSrc2();
27983
- const parseCookiesImport = hasMiddleware ? `import { parseCookies } from ${JSON.stringify(resolve14(compilerSrc, "server-cookies.js"))};` : "";
29108
+ const parseCookiesImport = hasMiddleware ? `import { parseCookies } from ${JSON.stringify(resolve15(compilerSrc, "server-cookies.js"))};` : "";
27984
29109
  return `
27985
29110
  ${imports}
27986
29111
  ${parseCookiesImport}
@@ -28018,7 +29143,7 @@ export async function handleRequest(request) {
28018
29143
  return new Response(null, { status: 308, headers: { Location: '/_vesk/static/public' + (pathname.endsWith('/') ? pathname + 'index.html' : pathname + '.html') } });
28019
29144
  }
28020
29145
 
28021
- let mwCtx = { params: {}, url, locals: {}, cookies: {}, request, set() {}, get() { return undefined; } };
29146
+ let mwCtx = { params: {}, url, locals: {}, cookies: {}, request, resolveUrl(u) { return new URL(u, request.url).href; }, set() {}, get() { return undefined; } };
28022
29147
  if (${hasMwLiteral}) {
28023
29148
  mwCtx = {
28024
29149
  request,
@@ -28026,6 +29151,7 @@ export async function handleRequest(request) {
28026
29151
  url,
28027
29152
  locals: {},
28028
29153
  cookies: typeof parseCookies !== 'undefined' ? parseCookies(request.headers.get('cookie') || '') : {},
29154
+ resolveUrl(u) { return new URL(u, request.url).href; },
28029
29155
  set(key, value) { this.locals[key] = value; },
28030
29156
  get(key) { return this.locals[key]; },
28031
29157
  };
@@ -28080,7 +29206,7 @@ async function bundlePlatformHandler(options2) {
28080
29206
  plugins.push({
28081
29207
  name: "empty-node-builtins",
28082
29208
  setup(build5) {
28083
- const builtins = /^(node:)?(fs|path|child_process|os|crypto|net|stream|buffer|events|util|url|querystring|http|https|zlib|tty|async_hooks)$/;
29209
+ const builtins = /^(node:)?(fs|module|path|child_process|os|crypto|net|stream|buffer|events|util|url|querystring|http|https|zlib|tty|async_hooks)$/;
28084
29210
  build5.onResolve({ filter: builtins }, (args2) => {
28085
29211
  return { path: args2.path, namespace: "empty-node" };
28086
29212
  });
@@ -28108,14 +29234,19 @@ export const readFileSync = () => {};
28108
29234
  export const writeFileSync = () => {};
28109
29235
  export const existsSync = () => {};
28110
29236
  export const statSync = () => {};
29237
+ export const realpathSync = () => '';
28111
29238
  export const readdirSync = () => {};
28112
29239
  export const mkdirSync = () => {};
28113
29240
  export const unlinkSync = () => {};
28114
29241
  export const rmSync = () => {};
28115
29242
  export const copyFileSync = () => {};
28116
29243
  export const accessSync = () => {};
29244
+ // node:module \u2014 createRequire is server-only dead code in the browser bundle;
29245
+ // the stub keeps esbuild from failing on the named import.
29246
+ export const createRequire = () => () => undefined;
28117
29247
  export const join = (...a) => a.join('/');
28118
29248
  export const resolve = (...a) => a.join('/');
29249
+ export const isAbsolute = () => false;
28119
29250
  export const dirname = () => '';
28120
29251
  export const basename = () => '';
28121
29252
  export const extname = () => '';
@@ -28155,7 +29286,7 @@ var __dirname5;
28155
29286
  var init_platform_handler = __esm({
28156
29287
  "../adapter/src/platform-handler.ts"() {
28157
29288
  "use strict";
28158
- __dirname5 = dirname8(fileURLToPath4(import.meta.url));
29289
+ __dirname5 = dirname9(fileURLToPath4(import.meta.url));
28159
29290
  }
28160
29291
  });
28161
29292
 
@@ -28164,74 +29295,74 @@ import {
28164
29295
  mkdirSync as mkdirSync4,
28165
29296
  copyFileSync as copyFileSync3,
28166
29297
  readdirSync as readdirSync6,
28167
- statSync as statSync8,
28168
- existsSync as existsSync14,
29298
+ statSync as statSync10,
29299
+ existsSync as existsSync15,
28169
29300
  writeFileSync as writeFileSync6,
28170
29301
  rmSync,
28171
- readFileSync as readFileSync13
29302
+ readFileSync as readFileSync15
28172
29303
  } from "node:fs";
28173
- import { resolve as resolve15, join as join7, extname as extname4, dirname as dirname9 } from "node:path";
29304
+ import { resolve as resolve16, join as join8, extname as extname5, dirname as dirname10 } from "node:path";
28174
29305
  function ensureCleanDir(dir) {
28175
29306
  rmSync(dir, { recursive: true, force: true });
28176
29307
  mkdirSync4(dir, { recursive: true });
28177
29308
  }
28178
29309
  function copyDirContents(srcDir, destDir) {
28179
- if (!existsSync14(srcDir)) return;
29310
+ if (!existsSync15(srcDir)) return;
28180
29311
  mkdirSync4(destDir, { recursive: true });
28181
29312
  for (const entry of readdirSync6(srcDir)) {
28182
- const srcPath = join7(srcDir, entry);
28183
- const destPath = join7(destDir, entry);
28184
- if (statSync8(srcPath).isDirectory()) {
29313
+ const srcPath = join8(srcDir, entry);
29314
+ const destPath = join8(destDir, entry);
29315
+ if (statSync10(srcPath).isDirectory()) {
28185
29316
  copyDirContents(srcPath, destPath);
28186
29317
  } else {
28187
- mkdirSync4(dirname9(destPath), { recursive: true });
29318
+ mkdirSync4(dirname10(destPath), { recursive: true });
28188
29319
  copyFileSync3(srcPath, destPath);
28189
29320
  }
28190
29321
  }
28191
29322
  }
28192
29323
  function writeFile(path, content) {
28193
- mkdirSync4(dirname9(path), { recursive: true });
29324
+ mkdirSync4(dirname10(path), { recursive: true });
28194
29325
  writeFileSync6(path, content, "utf-8");
28195
29326
  }
28196
29327
  function writePlatformStatic(buildStaticDir, platformStaticDir) {
28197
29328
  mkdirSync4(platformStaticDir, { recursive: true });
28198
- const publicDir = resolve15(buildStaticDir, "public");
28199
- if (existsSync14(publicDir)) {
29329
+ const publicDir = resolve16(buildStaticDir, "public");
29330
+ if (existsSync15(publicDir)) {
28200
29331
  copyDirContents(publicDir, platformStaticDir);
28201
29332
  }
28202
- const assetsDir = resolve15(platformStaticDir, "_vesk", "static");
29333
+ const assetsDir = resolve16(platformStaticDir, "_vesk", "static");
28203
29334
  copyDirContents(buildStaticDir, assetsDir);
28204
- const runtimeAlias = resolve15(platformStaticDir, "_vesk", "runtime.js");
28205
- const clientPath = resolve15(buildStaticDir, "client.js");
28206
- if (existsSync14(clientPath)) {
28207
- mkdirSync4(dirname9(runtimeAlias), { recursive: true });
29335
+ const runtimeAlias = resolve16(platformStaticDir, "_vesk", "runtime.js");
29336
+ const clientPath = resolve16(buildStaticDir, "client.js");
29337
+ if (existsSync15(clientPath)) {
29338
+ mkdirSync4(dirname10(runtimeAlias), { recursive: true });
28208
29339
  copyFileSync3(clientPath, runtimeAlias);
28209
29340
  }
28210
29341
  }
28211
29342
  function writePrerenderedStatic(prerenderedRoutes, platformStaticDir) {
28212
29343
  for (const route of prerenderedRoutes) {
28213
- if (!existsSync14(route.html)) continue;
28214
- const content = readFileSync13(route.html);
29344
+ if (!existsSync15(route.html)) continue;
29345
+ const content = readFileSync15(route.html);
28215
29346
  const htmlRel = route.path === "/" ? "index.html" : `${route.path.replace(/^\//, "")}.html`;
28216
- const target = resolve15(platformStaticDir, "_vesk", "static", "public", htmlRel);
29347
+ const target = resolve16(platformStaticDir, "_vesk", "static", "public", htmlRel);
28217
29348
  writeFile(target, content);
28218
29349
  if (route.path !== "/" && route.path.endsWith("/")) {
28219
- const dirIndex = resolve15(platformStaticDir, "_vesk", "static", "public", `${route.path.replace(/^\//, "")}index.html`);
29350
+ const dirIndex = resolve16(platformStaticDir, "_vesk", "static", "public", `${route.path.replace(/^\//, "")}index.html`);
28220
29351
  writeFile(dirIndex, content);
28221
29352
  }
28222
29353
  }
28223
29354
  }
28224
29355
  function listStaticDir(dir) {
28225
29356
  const out = [];
28226
- if (!existsSync14(dir)) return out;
29357
+ if (!existsSync15(dir)) return out;
28227
29358
  function walk6(d, prefix) {
28228
29359
  for (const entry of readdirSync6(d)) {
28229
- const full = join7(d, entry);
29360
+ const full = join8(d, entry);
28230
29361
  const rel = prefix ? `${prefix}/${entry}` : entry;
28231
- if (statSync8(full).isDirectory()) {
29362
+ if (statSync10(full).isDirectory()) {
28232
29363
  walk6(full, rel);
28233
29364
  } else {
28234
- out.push({ rel, buffer: readFileSync13(full) });
29365
+ out.push({ rel, buffer: readFileSync15(full) });
28235
29366
  }
28236
29367
  }
28237
29368
  }
@@ -28239,7 +29370,7 @@ function listStaticDir(dir) {
28239
29370
  return out;
28240
29371
  }
28241
29372
  function mimeFor(path) {
28242
- return MIME2[extname4(path).toLowerCase()] || "application/octet-stream";
29373
+ return MIME2[extname5(path).toLowerCase()] || "application/octet-stream";
28243
29374
  }
28244
29375
  var MIME2;
28245
29376
  var init_platform_output = __esm({
@@ -28279,7 +29410,7 @@ __export(platform_deploy_exports, {
28279
29410
  emitPlatformOutput: () => emitPlatformOutput
28280
29411
  });
28281
29412
  import { writeFileSync as writeFileSync7, mkdirSync as mkdirSync5, rmSync as rmSync2, symlinkSync } from "node:fs";
28282
- import { resolve as resolve16, dirname as dirname10, relative as relative3 } from "node:path";
29413
+ import { resolve as resolve17, dirname as dirname11, relative as relative3 } from "node:path";
28283
29414
  async function emitPlatformOutput(platform, ctx2) {
28284
29415
  if (platform === "node") return null;
28285
29416
  const prerenderedPaths = ctx2.prerenderedRoutes.map((r) => r.path);
@@ -28290,13 +29421,13 @@ async function emitPlatformOutput(platform, ctx2) {
28290
29421
  hasMiddleware: ctx2.hasMiddleware
28291
29422
  });
28292
29423
  const shell = shellFor(platform);
28293
- const projectRoot = resolve16(ctx2.outDir, "..");
28294
- const outRoot = resolve16(projectRoot, shell.root);
29424
+ const projectRoot = resolve17(ctx2.outDir, "..");
29425
+ const outRoot = resolve17(projectRoot, shell.root);
28295
29426
  ensureCleanDir(outRoot);
28296
- const staticDir2 = shell.staticSubdir === "" ? outRoot : resolve16(outRoot, shell.staticSubdir || "static");
28297
- writePlatformStatic(resolve16(ctx2.outDir, "static"), staticDir2);
29427
+ const staticDir2 = shell.staticSubdir === "" ? outRoot : resolve17(outRoot, shell.staticSubdir || "static");
29428
+ writePlatformStatic(resolve17(ctx2.outDir, "static"), staticDir2);
28298
29429
  writePrerenderedStatic(ctx2.prerenderedRoutes, staticDir2);
28299
- const entry = resolve16(ctx2.outDir, ".platform-entry.mjs");
29430
+ const entry = resolve17(ctx2.outDir, ".platform-entry.mjs");
28300
29431
  let source = handler;
28301
29432
  if (shell.imports) source = `${shell.imports}
28302
29433
  ${source}`;
@@ -28314,24 +29445,24 @@ ${shell.bootstrap}
28314
29445
  writeFileSync7(entry, source, "utf-8");
28315
29446
  let handlerRel;
28316
29447
  if (shell.functionFile) {
28317
- const funcDir = resolve16(outRoot, shell.functionFile.dir);
29448
+ const funcDir = resolve17(outRoot, shell.functionFile.dir);
28318
29449
  mkdirSync5(funcDir, { recursive: true });
28319
29450
  if (shell.functionConfig) {
28320
- writeFileSync7(resolve16(funcDir, ".vc-config.json"), JSON.stringify(shell.functionConfig, null, 2), "utf-8");
29451
+ writeFileSync7(resolve17(funcDir, ".vc-config.json"), JSON.stringify(shell.functionConfig, null, 2), "utf-8");
28321
29452
  }
28322
29453
  handlerRel = `${shell.functionFile.dir}/${shell.functionFile.file}`;
28323
- await bundlePlatformHandler({ entry, outfile: resolve16(funcDir, shell.functionFile.file), nodeBuiltins: shell.nodeBuiltins });
29454
+ await bundlePlatformHandler({ entry, outfile: resolve17(funcDir, shell.functionFile.file), nodeBuiltins: shell.nodeBuiltins });
28324
29455
  } else {
28325
29456
  handlerRel = shell.outfile || "index.js";
28326
- await bundlePlatformHandler({ entry, outfile: resolve16(outRoot, handlerRel), nodeBuiltins: shell.nodeBuiltins });
29457
+ await bundlePlatformHandler({ entry, outfile: resolve17(outRoot, handlerRel), nodeBuiltins: shell.nodeBuiltins });
28327
29458
  }
28328
29459
  for (const file of shell.extraFiles || []) {
28329
- writeFileSync7(resolve16(outRoot, file.path), file.content, "utf-8");
29460
+ writeFileSync7(resolve17(outRoot, file.path), file.content, "utf-8");
28330
29461
  }
28331
29462
  if (platform === "vercel") {
28332
- writeFileSync7(resolve16(outRoot, "config.json"), vercelConfigJson(prerenderedPaths), "utf-8");
29463
+ writeFileSync7(resolve17(outRoot, "config.json"), vercelConfigJson(prerenderedPaths), "utf-8");
28333
29464
  }
28334
- writeFileSync7(resolve16(outRoot, "manifest.json"), JSON.stringify({
29465
+ writeFileSync7(resolve17(outRoot, "manifest.json"), JSON.stringify({
28335
29466
  platform,
28336
29467
  runtime: shell.nodeBuiltins ? "node" : "edge",
28337
29468
  static: shell.staticMode,
@@ -28341,11 +29472,11 @@ ${shell.bootstrap}
28341
29472
  prerendered: prerenderedPaths
28342
29473
  }, null, 2), "utf-8");
28343
29474
  if (platform === "vercel") {
28344
- const vercelDir = resolve16(projectRoot, ".vercel");
29475
+ const vercelDir = resolve17(projectRoot, ".vercel");
28345
29476
  mkdirSync5(vercelDir, { recursive: true });
28346
- const linkPath = resolve16(vercelDir, "output");
29477
+ const linkPath = resolve17(vercelDir, "output");
28347
29478
  rmSync2(linkPath, { recursive: true, force: true });
28348
- symlinkSync(relative3(dirname10(linkPath), outRoot), linkPath, "dir");
29479
+ symlinkSync(relative3(dirname11(linkPath), outRoot), linkPath, "dir");
28349
29480
  }
28350
29481
  rmSync2(entry, { force: true });
28351
29482
  return outRoot;
@@ -30518,6 +31649,95 @@ function wireCopyHandlers2(root3) {
30518
31649
  function mdIsSSR2() {
30519
31650
  return typeof document === "undefined";
30520
31651
  }
31652
+ function stringEndsWith2(s, suffix) {
31653
+ if (suffix.length > s.length)
31654
+ return false;
31655
+ for (let i = 0; i < suffix.length; i++) {
31656
+ if (s[s.length - suffix.length + i] !== suffix[i])
31657
+ return false;
31658
+ }
31659
+ return true;
31660
+ }
31661
+ function isPublicMarkdownPath2(v) {
31662
+ if (typeof v !== "string")
31663
+ return false;
31664
+ const s = v;
31665
+ if (s.length < 2 || s.charCodeAt(0) !== 47)
31666
+ return false;
31667
+ if (s.charCodeAt(1) === 47)
31668
+ return false;
31669
+ for (let i = 0; i < s.length; i++) {
31670
+ const c = s.charCodeAt(i);
31671
+ if (c === 63 || c === 35 || c === 92)
31672
+ return false;
31673
+ }
31674
+ const lower = s.toLowerCase();
31675
+ return stringEndsWith2(lower, ".md") || stringEndsWith2(lower, ".markdown");
31676
+ }
31677
+ function getMdPathCell2(path) {
31678
+ let cell = mdPathCells2.get(path);
31679
+ if (!cell) {
31680
+ cell = tracked(void 0);
31681
+ mdPathCells2.set(path, cell);
31682
+ }
31683
+ return cell;
31684
+ }
31685
+ function ensureMdPathLoaded2(path) {
31686
+ if (mdPathCache2.has(path) || mdPathInflight2.has(path))
31687
+ return;
31688
+ const ssr = getSsrData("md:" + path);
31689
+ if (typeof ssr === "string") {
31690
+ mdPathCache2.set(path, ssr);
31691
+ return;
31692
+ }
31693
+ mdPathInflight2.add(path);
31694
+ fetch(path).then((r) => r.ok ? r.text() : Promise.reject(r)).then((text) => {
31695
+ mdPathCache2.set(path, text);
31696
+ set(getMdPathCell2(path), text);
31697
+ }).catch(() => {
31698
+ mdPathCache2.set(path, null);
31699
+ set(getMdPathCell2(path), null);
31700
+ }).finally(() => {
31701
+ mdPathInflight2.delete(path);
31702
+ });
31703
+ }
31704
+ function readServerMdPath2(path) {
31705
+ const hook = globalThis.__vsk_md_read_file;
31706
+ if (typeof hook !== "function")
31707
+ return null;
31708
+ try {
31709
+ const out = hook(path);
31710
+ if (typeof out === "string")
31711
+ return out;
31712
+ } catch {
31713
+ }
31714
+ return null;
31715
+ }
31716
+ function resolveMdSource2(value) {
31717
+ const s = String(value ?? "");
31718
+ if (!isPublicMarkdownPath2(s))
31719
+ return s;
31720
+ if (mdIsSSR2()) {
31721
+ const content = readServerMdPath2(s);
31722
+ if (content !== null) {
31723
+ setSsrData("md:" + s, content);
31724
+ return content;
31725
+ }
31726
+ return s;
31727
+ }
31728
+ ensureMdPathLoaded2(s);
31729
+ const cached = mdPathCache2.get(s);
31730
+ return cached === void 0 || cached === null ? s : cached;
31731
+ }
31732
+ function streamCellFrom2(rawContent) {
31733
+ if (rawContent === null || typeof rawContent !== "object")
31734
+ return null;
31735
+ const into = rawContent.into;
31736
+ if (into !== null && typeof into === "object" && typeof into.get === "function") {
31737
+ return into;
31738
+ }
31739
+ return null;
31740
+ }
30521
31741
  function buildHtml2(content, props) {
30522
31742
  const global = getMdPolicy2();
30523
31743
  const mode = props.html || global.html;
@@ -30553,8 +31773,10 @@ function buildHtml2(content, props) {
30553
31773
  }
30554
31774
  function Md2(props, _registry, hydrate) {
30555
31775
  const rawContent = props.content;
30556
- const content = String(unwrapMaybeCell2(rawContent) ?? "");
30557
- const html = buildHtml2(content, props);
31776
+ const streamTarget = streamCellFrom2(rawContent);
31777
+ const contentCell = streamTarget ?? rawContent;
31778
+ const content = String(unwrapMaybeCell2(contentCell) ?? "");
31779
+ const html = buildHtml2(resolveMdSource2(content), props);
30558
31780
  const classNameRaw = props.className != null ? String(props.className) : props.class != null ? String(props.class) : "";
30559
31781
  const themeClass = props.theme === "dark" ? " vesk-md-dark" : "";
30560
31782
  const className = `vesk-md${themeClass}${classNameRaw ? " " + classNameRaw : ""}`;
@@ -30567,7 +31789,8 @@ function Md2(props, _registry, hydrate) {
30567
31789
  if (propFg && propFg !== "none")
30568
31790
  wrapperParts.push(`--md-code-fg:${propFg}`);
30569
31791
  const wrapperStyle = wrapperParts.length > 0 ? escapeHtml6(wrapperParts.join(";")) : "";
30570
- const reactive = isCell2(rawContent);
31792
+ const reactive = isCell2(contentCell);
31793
+ const pathMode = isPublicMarkdownPath2(content);
30571
31794
  if (mdIsSSR2()) {
30572
31795
  const attrs = className ? ` class="${escapeHtml6(className)}"` : "";
30573
31796
  const styleAttr = style || wrapperStyle ? ` style="${[wrapperStyle, style.split('"').join("&quot;")].filter(Boolean).join(";")}"` : "";
@@ -30580,12 +31803,20 @@ function Md2(props, _registry, hydrate) {
30580
31803
  if (existing)
30581
31804
  el = existing;
30582
31805
  }
30583
- el.innerHTML = html;
31806
+ const claimed = !!el.parentNode;
31807
+ if (pathMode && claimed) {
31808
+ el.setAttribute("data-vsk-md-ssr", "1");
31809
+ if (mdPathCache2.has(content))
31810
+ el.innerHTML = html;
31811
+ } else {
31812
+ el.innerHTML = html;
31813
+ }
30584
31814
  el.className = className;
30585
31815
  el.style.cssText = [wrapperStyle, style].filter(Boolean).join(";");
30586
31816
  wireCopyHandlers2(el);
30587
- if (reactive)
30588
- subscribeContent2(el, rawContent, props);
31817
+ if (reactive || pathMode) {
31818
+ subscribeContent2(el, contentCell, props, pathMode && claimed ? { trustInitialSsr: true, initialValue: content } : void 0);
31819
+ }
30589
31820
  if (el.parentNode)
30590
31821
  return document.createDocumentFragment();
30591
31822
  return el;
@@ -30595,22 +31826,42 @@ function Md2(props, _registry, hydrate) {
30595
31826
  div.className = className;
30596
31827
  div.style.cssText = [wrapperStyle, style].filter(Boolean).join(";");
30597
31828
  wireCopyHandlers2(div);
30598
- if (reactive)
30599
- subscribeContent2(div, rawContent, props);
31829
+ if (reactive || pathMode)
31830
+ subscribeContent2(div, contentCell, props);
30600
31831
  return div;
30601
31832
  }
30602
- function subscribeContent2(el, rawContent, props) {
31833
+ function subscribeContent2(el, rawContent, props, opts) {
31834
+ const trust = opts?.trustInitialSsr === true;
31835
+ const initial = opts?.initialValue;
31836
+ let ran = false;
30603
31837
  effect(() => {
30604
31838
  const value = String(unwrapMaybeCell2(rawContent) ?? "");
30605
- el.innerHTML = buildHtml2(value, props);
31839
+ if (isPublicMarkdownPath2(value)) {
31840
+ const known = getSsrData("md:" + value) !== void 0 || mdPathCache2.has(value);
31841
+ ensureMdPathLoaded2(value);
31842
+ const cell = getMdPathCell2(value);
31843
+ get(cell);
31844
+ if (trust && !ran && value === initial && !known) {
31845
+ ran = true;
31846
+ return;
31847
+ }
31848
+ ran = true;
31849
+ el.innerHTML = buildHtml2(resolveMdSource2(value), props);
31850
+ wireCopyHandlers2(el);
31851
+ return;
31852
+ }
31853
+ ran = true;
31854
+ el.innerHTML = buildHtml2(resolveMdSource2(value), props);
30606
31855
  wireCopyHandlers2(el);
30607
31856
  });
30608
31857
  }
30609
- var COLOR_FUNCS2, SAFE_SCHEMES2, KW_JS2, KW_VSK2, LIT_JS2, KW_PY2, LIT_PY2, KW_GO2, LIT_GO2, KW_RUST2, LIT_RUST2, KW_SQL2, KW_BASH2, NAMED_ENTITIES2, URL_ATTRS2, MD_DEFAULT_ALLOW_TAGS2, MD_BASE_CSS2, __globalMode2, __globalAllowTags2, __sessionWarnings2, __warnedKeys2, __suppressMdConsoleWarnings2;
31858
+ var COLOR_FUNCS2, SAFE_SCHEMES2, KW_JS2, KW_VSK2, LIT_JS2, KW_PY2, LIT_PY2, KW_GO2, LIT_GO2, KW_RUST2, LIT_RUST2, KW_SQL2, KW_BASH2, NAMED_ENTITIES2, URL_ATTRS2, MD_DEFAULT_ALLOW_TAGS2, MD_BASE_CSS2, __globalMode2, __globalAllowTags2, __sessionWarnings2, __warnedKeys2, __suppressMdConsoleWarnings2, mdPathCache2, mdPathCells2, mdPathInflight2;
30610
31859
  var init_md2 = __esm({
30611
31860
  "../runtime/dist/md.js"() {
30612
31861
  "use strict";
30613
31862
  init_ripple_blocks();
31863
+ init_ripple_runtime();
31864
+ init_resource();
30614
31865
  COLOR_FUNCS2 = /* @__PURE__ */ new Set(["rgb", "rgba", "hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "color", "color-mix"]);
30615
31866
  SAFE_SCHEMES2 = ["http:", "https:", "mailto:", "tel:"];
30616
31867
  KW_JS2 = /* @__PURE__ */ new Set([
@@ -31012,6 +32263,9 @@ var init_md2 = __esm({
31012
32263
  __sessionWarnings2 = [];
31013
32264
  __warnedKeys2 = /* @__PURE__ */ new Set();
31014
32265
  __suppressMdConsoleWarnings2 = false;
32266
+ mdPathCache2 = /* @__PURE__ */ new Map();
32267
+ mdPathCells2 = /* @__PURE__ */ new Map();
32268
+ mdPathInflight2 = /* @__PURE__ */ new Set();
31015
32269
  }
31016
32270
  });
31017
32271
 
@@ -31466,6 +32720,11 @@ function emitJSXChildren(g2, source, children, opts) {
31466
32720
  } else if (child.type === "JSXFragment") {
31467
32721
  emitJSXFragment(g2, source, child, opts);
31468
32722
  i++;
32723
+ } else if (child.type === "IfStatement" || child.type === "ForOfStatement" || child.type === "ForStatement" || child.type === "ForInStatement" || child.type === "WhileStatement" || child.type === "DoWhileStatement" || child.type === "SwitchStatement" || child.type === "TryStatement" || child.type === "VariableDeclaration" || child.type === "ExpressionStatement") {
32724
+ g2.addRaw("{(() => { ");
32725
+ emitBody(g2, source, [child], "", opts);
32726
+ g2.addRaw(" })()}");
32727
+ i++;
31469
32728
  } else {
31470
32729
  i++;
31471
32730
  }
@@ -31978,9 +33237,9 @@ __export(typecheck_exports, {
31978
33237
  formatTypecheckWarnings: () => formatTypecheckWarnings,
31979
33238
  typecheckProject: () => typecheckProject
31980
33239
  });
31981
- import { readFileSync as readFileSync20, readdirSync as readdirSync12, statSync as statSync14 } from "node:fs";
31982
- import { join as join13, dirname as dirname14, normalize, relative as relative7, resolve as resolve24, sep as sep5 } from "node:path";
31983
- import * as ts7 from "typescript";
33240
+ import { readFileSync as readFileSync23, readdirSync as readdirSync12, statSync as statSync17 } from "node:fs";
33241
+ import { join as join14, dirname as dirname15, normalize, relative as relative7, resolve as resolve25, sep as sep5 } from "node:path";
33242
+ import * as ts8 from "typescript";
31984
33243
  function walkProjectFiles(projectRoot) {
31985
33244
  const code = [];
31986
33245
  const js = [];
@@ -31992,10 +33251,10 @@ function walkProjectFiles(projectRoot) {
31992
33251
  return;
31993
33252
  }
31994
33253
  for (const e of entries) {
31995
- const p = join13(dir, e);
33254
+ const p = join14(dir, e);
31996
33255
  let st;
31997
33256
  try {
31998
- st = statSync14(p);
33257
+ st = statSync17(p);
31999
33258
  } catch {
32000
33259
  continue;
32001
33260
  }
@@ -32020,8 +33279,8 @@ function walkProjectFiles(projectRoot) {
32020
33279
  return { code, js };
32021
33280
  }
32022
33281
  function isUnder(dir, file) {
32023
- const base = resolve24(dir);
32024
- const abs = resolve24(file);
33282
+ const base = resolve25(dir);
33283
+ const abs = resolve25(file);
32025
33284
  return abs === base || abs.startsWith(base + sep5);
32026
33285
  }
32027
33286
  function structureWarning(rel, message) {
@@ -32047,10 +33306,10 @@ function checkStructureFile(appDir, file) {
32047
33306
  return null;
32048
33307
  }
32049
33308
  function createTypecheckHost(projectRoot, appDir, vskFiles) {
32050
- const ambientPath = join13(appDir, "__vesk_ambient.d.ts");
32051
- const overridePath = join13(appDir, "__vesk_runtime_override.d.ts");
33309
+ const ambientPath = join14(appDir, "__vesk_ambient.d.ts");
33310
+ const overridePath = join14(appDir, "__vesk_runtime_override.d.ts");
32052
33311
  const cached = /* @__PURE__ */ new Map();
32053
- const scriptKindFor = (file) => file.endsWith(".vsk") ? ts7.ScriptKind.TSX : ts7.ScriptKind.TS;
33312
+ const scriptKindFor = (file) => file.endsWith(".vsk") ? ts8.ScriptKind.TSX : ts8.ScriptKind.TS;
32054
33313
  const host2 = {
32055
33314
  getSourceFile(file, langVersion, onError, shouldCreateNewSourceFile) {
32056
33315
  if (!shouldCreateNewSourceFile && cached.has(file))
@@ -32062,21 +33321,21 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
32062
33321
  content = RUNTIME_OVERRIDE;
32063
33322
  } else if (file.endsWith(".vsk.d.ts")) {
32064
33323
  const vskPath = file.slice(0, -".d.ts".length);
32065
- const src2 = vskFiles.get(vskPath) ?? (ts7.sys.fileExists(vskPath) ? ts7.sys.readFile(vskPath) : void 0);
33324
+ const src2 = vskFiles.get(vskPath) ?? (ts8.sys.fileExists(vskPath) ? ts8.sys.readFile(vskPath) : void 0);
32066
33325
  content = src2 !== void 0 ? generateVskDts(src2) : void 0;
32067
33326
  } else if (file.endsWith(".css.d.ts")) {
32068
33327
  content = "";
32069
33328
  } else if (vskFiles.has(file)) {
32070
33329
  content = vskToTsx(vskFiles.get(file));
32071
- } else if (ts7.sys.fileExists(file)) {
32072
- content = ts7.sys.readFile(file);
33330
+ } else if (ts8.sys.fileExists(file)) {
33331
+ content = ts8.sys.readFile(file);
32073
33332
  }
32074
33333
  if (content === void 0) {
32075
33334
  if (onError)
32076
33335
  onError(`File not found: ${file}`);
32077
33336
  return void 0;
32078
33337
  }
32079
- const sf = ts7.createSourceFile(file, content, langVersion, true, scriptKindFor(file));
33338
+ const sf = ts8.createSourceFile(file, content, langVersion, true, scriptKindFor(file));
32080
33339
  cached.set(file, sf);
32081
33340
  return sf;
32082
33341
  },
@@ -32087,13 +33346,13 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
32087
33346
  return true;
32088
33347
  if (file.endsWith(".vsk.d.ts")) {
32089
33348
  const vskPath = file.slice(0, -".d.ts".length);
32090
- return vskFiles.has(vskPath) || ts7.sys.fileExists(vskPath);
33349
+ return vskFiles.has(vskPath) || ts8.sys.fileExists(vskPath);
32091
33350
  }
32092
33351
  if (file.endsWith(".css.d.ts"))
32093
33352
  return true;
32094
33353
  if (vskFiles.has(file))
32095
33354
  return true;
32096
- return ts7.sys.fileExists(file);
33355
+ return ts8.sys.fileExists(file);
32097
33356
  },
32098
33357
  readFile(file) {
32099
33358
  if (file === ambientPath)
@@ -32102,55 +33361,55 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
32102
33361
  return RUNTIME_OVERRIDE;
32103
33362
  if (file.endsWith(".vsk.d.ts")) {
32104
33363
  const vskPath = file.slice(0, -".d.ts".length);
32105
- const src2 = vskFiles.get(vskPath) ?? (ts7.sys.fileExists(vskPath) ? ts7.sys.readFile(vskPath) : void 0);
33364
+ const src2 = vskFiles.get(vskPath) ?? (ts8.sys.fileExists(vskPath) ? ts8.sys.readFile(vskPath) : void 0);
32106
33365
  return src2 !== void 0 ? generateVskDts(src2) : void 0;
32107
33366
  }
32108
33367
  if (file.endsWith(".css.d.ts"))
32109
33368
  return "";
32110
33369
  if (vskFiles.has(file))
32111
33370
  return vskToTsx(vskFiles.get(file));
32112
- return ts7.sys.readFile(file);
33371
+ return ts8.sys.readFile(file);
32113
33372
  },
32114
33373
  writeFile: () => {
32115
33374
  },
32116
33375
  getCurrentDirectory: () => projectRoot,
32117
- getDefaultLibFileName: (o) => ts7.getDefaultLibFilePath(o),
32118
- directoryExists: (dir) => ts7.sys.directoryExists(dir),
33376
+ getDefaultLibFileName: (o) => ts8.getDefaultLibFilePath(o),
33377
+ directoryExists: (dir) => ts8.sys.directoryExists(dir),
32119
33378
  getDirectories: (dir) => {
32120
33379
  try {
32121
- return readdirSync12(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join13(dir, d.name));
33380
+ return readdirSync12(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => join14(dir, d.name));
32122
33381
  } catch {
32123
33382
  return [];
32124
33383
  }
32125
33384
  },
32126
33385
  getCanonicalFileName: (f) => normalize(f),
32127
- useCaseSensitiveFileNames: () => ts7.sys.useCaseSensitiveFileNames,
33386
+ useCaseSensitiveFileNames: () => ts8.sys.useCaseSensitiveFileNames,
32128
33387
  getNewLine: () => "\n",
32129
33388
  resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options2) {
32130
33389
  return moduleLiterals.map(({ text }) => {
32131
33390
  if (text.endsWith(".vsk")) {
32132
- const abs = normalize(join13(dirname14(containingFile), text));
33391
+ const abs = normalize(join14(dirname15(containingFile), text));
32133
33392
  return {
32134
33393
  resolvedModule: {
32135
33394
  resolvedFileName: abs + ".d.ts",
32136
- extension: ts7.Extension.Dts,
33395
+ extension: ts8.Extension.Dts,
32137
33396
  isExternalLibraryImport: false
32138
33397
  },
32139
33398
  failedLookupLocations: []
32140
33399
  };
32141
33400
  }
32142
33401
  if (text.endsWith(".css")) {
32143
- const abs = normalize(join13(dirname14(containingFile), text));
33402
+ const abs = normalize(join14(dirname15(containingFile), text));
32144
33403
  return {
32145
33404
  resolvedModule: {
32146
33405
  resolvedFileName: abs + ".d.ts",
32147
- extension: ts7.Extension.Dts,
33406
+ extension: ts8.Extension.Dts,
32148
33407
  isExternalLibraryImport: false
32149
33408
  },
32150
33409
  failedLookupLocations: []
32151
33410
  };
32152
33411
  }
32153
- const res = ts7.resolveModuleName(text, containingFile, options2, host2);
33412
+ const res = ts8.resolveModuleName(text, containingFile, options2, host2);
32154
33413
  return { resolvedModule: res.resolvedModule, failedLookupLocations: [] };
32155
33414
  });
32156
33415
  }
@@ -32158,7 +33417,7 @@ function createTypecheckHost(projectRoot, appDir, vskFiles) {
32158
33417
  return host2;
32159
33418
  }
32160
33419
  function typecheckProject(projectRoot, opts = {}) {
32161
- const appDir = opts.appDir ?? join13(projectRoot, "app");
33420
+ const appDir = opts.appDir ?? join14(projectRoot, "app");
32162
33421
  const vskFiles = /* @__PURE__ */ new Map();
32163
33422
  const parseErrors = [];
32164
33423
  const warnings = [];
@@ -32180,7 +33439,7 @@ function typecheckProject(projectRoot, opts = {}) {
32180
33439
  }
32181
33440
  }
32182
33441
  if (f.endsWith(".vsk")) {
32183
- const src2 = readFileSync20(f, "utf-8");
33442
+ const src2 = readFileSync23(f, "utf-8");
32184
33443
  try {
32185
33444
  parse4(src2);
32186
33445
  } catch (e) {
@@ -32197,16 +33456,16 @@ function typecheckProject(projectRoot, opts = {}) {
32197
33456
  }
32198
33457
  rootNames.push(f);
32199
33458
  }
32200
- const ambientPath = join13(appDir, "__vesk_ambient.d.ts");
32201
- const overridePath = join13(appDir, "__vesk_runtime_override.d.ts");
33459
+ const ambientPath = join14(appDir, "__vesk_ambient.d.ts");
33460
+ const overridePath = join14(appDir, "__vesk_runtime_override.d.ts");
32202
33461
  rootNames.push(ambientPath);
32203
33462
  rootNames.push(overridePath);
32204
33463
  const options2 = {
32205
- target: ts7.ScriptTarget.ES2022,
32206
- module: ts7.ModuleKind.ESNext,
32207
- moduleResolution: ts7.ModuleResolutionKind.Bundler,
33464
+ target: ts8.ScriptTarget.ES2022,
33465
+ module: ts8.ModuleKind.ESNext,
33466
+ moduleResolution: ts8.ModuleResolutionKind.Bundler,
32208
33467
  strict: opts.strict !== false,
32209
- jsx: ts7.JsxEmit.Preserve,
33468
+ jsx: ts8.JsxEmit.Preserve,
32210
33469
  noEmit: true,
32211
33470
  skipLibCheck: true,
32212
33471
  esModuleInterop: true,
@@ -32219,13 +33478,13 @@ function typecheckProject(projectRoot, opts = {}) {
32219
33478
  allowJs: false
32220
33479
  };
32221
33480
  const host2 = createTypecheckHost(projectRoot, appDir, vskFiles);
32222
- const program = ts7.createProgram({ rootNames, options: options2, host: host2 });
33481
+ const program = ts8.createProgram({ rootNames, options: options2, host: host2 });
32223
33482
  const rootSet = new Set(rootNames.map(normalize));
32224
33483
  const vskSet = /* @__PURE__ */ new Set();
32225
33484
  for (const p of vskFiles.keys())
32226
33485
  vskSet.add(normalize(p));
32227
33486
  const errors = [...parseErrors];
32228
- for (const diag of ts7.getPreEmitDiagnostics(program)) {
33487
+ for (const diag of ts8.getPreEmitDiagnostics(program)) {
32229
33488
  const file = diag.file;
32230
33489
  if (!file)
32231
33490
  continue;
@@ -32242,7 +33501,7 @@ function typecheckProject(projectRoot, opts = {}) {
32242
33501
  line: pos.line + 1,
32243
33502
  column: pos.character + 1,
32244
33503
  code,
32245
- message: ts7.flattenDiagnosticMessageText(diag.messageText, "\n")
33504
+ message: ts8.flattenDiagnosticMessageText(diag.messageText, "\n")
32246
33505
  });
32247
33506
  }
32248
33507
  return { errors, warnings };
@@ -32675,6 +33934,11 @@ declare function useFetch<T = unknown>(
32675
33934
  urlOrFn: string | (() => Promise<T>),
32676
33935
  options?: VeskUseFetchOptions<T>,
32677
33936
  ): VeskResource<T>;
33937
+ declare namespace useFetch {
33938
+ function text<T = string>(url: string, options?: Omit<VeskUseFetchOptions<T>, 'body'>): VeskResource<T>;
33939
+ function json<T = unknown>(url: string, options?: Omit<VeskUseFetchOptions<T>, 'body'>): VeskResource<T>;
33940
+ function arrayBuffer<T = ArrayBuffer>(url: string, options?: Omit<VeskUseFetchOptions<T>, 'body'>): VeskResource<T>;
33941
+ }
32678
33942
  declare function useRouter(): unknown;
32679
33943
  declare function useParams(): Record<string, string>;
32680
33944
  declare function usePathname(): string;
@@ -32757,8 +34021,8 @@ declare module '@vesk/runtime' {
32757
34021
  });
32758
34022
 
32759
34023
  // src/index.ts
32760
- import { readFileSync as readFileSync21, writeFileSync as writeFileSync11, mkdirSync as mkdirSync9, existsSync as existsSync23 } from "fs";
32761
- import { resolve as resolve25, join as join14, dirname as dirname15 } from "path";
34024
+ import { readFileSync as readFileSync24, writeFileSync as writeFileSync11, mkdirSync as mkdirSync9, existsSync as existsSync25 } from "fs";
34025
+ import { resolve as resolve26, join as join15, dirname as dirname16 } from "path";
32762
34026
  import { fileURLToPath as fileURLToPath8 } from "url";
32763
34027
 
32764
34028
  // ../compiler/dist/config.js
@@ -33257,41 +34521,41 @@ function setRuntimeModule2(mod) {
33257
34521
 
33258
34522
  // ../adapter/dist/index.js
33259
34523
  init_scan();
33260
- import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync8, existsSync as existsSync15, readFileSync as readFileSync14 } from "node:fs";
33261
- import { resolve as resolve17, dirname as dirname11, relative as relative4 } from "node:path";
34524
+ import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync8, existsSync as existsSync16, readFileSync as readFileSync16 } from "node:fs";
34525
+ import { resolve as resolve18, dirname as dirname12, relative as relative4 } from "node:path";
33262
34526
  import { fileURLToPath as fileURLToPath5 } from "node:url";
33263
34527
 
33264
34528
  // ../adapter/src/runtime-bundle.ts
33265
34529
  init_esbuild_fallback();
33266
34530
  import { writeFileSync, existsSync as existsSync2, unlinkSync } from "node:fs";
33267
- import { resolve as resolve2, dirname as dirname2, join } from "node:path";
34531
+ import { resolve as resolve3, dirname as dirname3, join as join2 } from "node:path";
33268
34532
  import { fileURLToPath } from "node:url";
33269
34533
  var buildId = 0;
33270
- var __dirname2 = dirname2(fileURLToPath(import.meta.url));
34534
+ var __dirname2 = dirname3(fileURLToPath(import.meta.url));
33271
34535
  function findCompilerSrc(appDir) {
33272
- const monorepoRoot = resolve2(__dirname2, "..", "..", "..");
34536
+ const monorepoRoot = resolve3(__dirname2, "..", "..", "..");
33273
34537
  const candidates = [
33274
- resolve2(monorepoRoot, "packages", "compiler", "dist"),
33275
- resolve2(appDir, "..", "node_modules", "@vesk/compiler"),
33276
- resolve2(appDir, "node_modules", "@vesk/compiler")
34538
+ resolve3(monorepoRoot, "packages", "compiler", "dist"),
34539
+ resolve3(appDir, "..", "node_modules", "@vesk/compiler"),
34540
+ resolve3(appDir, "node_modules", "@vesk/compiler")
33277
34541
  ];
33278
34542
  for (const base of candidates) {
33279
- for (const dir of [base, join(base, "dist")]) {
33280
- if (existsSync2(join(dir, "server-codegen.js"))) return dir;
34543
+ for (const dir of [base, join2(base, "dist")]) {
34544
+ if (existsSync2(join2(dir, "server-codegen.js"))) return dir;
33281
34545
  }
33282
34546
  }
33283
34547
  throw new Error('@vesk/compiler/dist not found \u2014 run "npm run build" first');
33284
34548
  }
33285
34549
  function findRuntimeSrc(appDir) {
33286
- const monorepoRoot = resolve2(__dirname2, "..", "..", "..");
34550
+ const monorepoRoot = resolve3(__dirname2, "..", "..", "..");
33287
34551
  const candidates = [
33288
- resolve2(monorepoRoot, "packages", "runtime", "dist"),
33289
- resolve2(appDir, "..", "node_modules", "@vesk/runtime"),
33290
- resolve2(appDir, "node_modules", "@vesk/runtime")
34552
+ resolve3(monorepoRoot, "packages", "runtime", "dist"),
34553
+ resolve3(appDir, "..", "node_modules", "@vesk/runtime"),
34554
+ resolve3(appDir, "node_modules", "@vesk/runtime")
33291
34555
  ];
33292
34556
  for (const base of candidates) {
33293
- for (const dir of [base, join(base, "dist")]) {
33294
- if (existsSync2(join(dir, "index-server.js"))) return dir;
34557
+ for (const dir of [base, join2(base, "dist")]) {
34558
+ if (existsSync2(join2(dir, "index-server.js"))) return dir;
33295
34559
  }
33296
34560
  }
33297
34561
  throw new Error('@vesk/runtime/dist not found \u2014 run "npm run build" first');
@@ -33299,11 +34563,11 @@ function findRuntimeSrc(appDir) {
33299
34563
  async function bundleRuntime(appDir, outDir2) {
33300
34564
  const compilerRoot = findCompilerSrc(appDir);
33301
34565
  const runtimeRoot = findRuntimeSrc(appDir);
33302
- const entryFile = resolve2(outDir2, "server", `.runtime-entry-${buildId++}.mjs`);
34566
+ const entryFile = resolve3(outDir2, "server", `.runtime-entry-${buildId++}.mjs`);
33303
34567
  const entryContent = [
33304
- `import { renderPage, renderFullPage, renderPageStream, compileFile, setRuntimeModule, setVskHydrate, assertSameOrigin } from ${JSON.stringify(resolve2(compilerRoot, "server-codegen.js"))};`,
33305
- `import { parseCookies } from ${JSON.stringify(resolve2(compilerRoot, "server-cookies.js"))};`,
33306
- `import * as __veskRuntime from ${JSON.stringify(resolve2(runtimeRoot, "index-server.js"))};`,
34568
+ `import { renderPage, renderFullPage, renderPageStream, compileFile, setRuntimeModule, setVskHydrate, assertSameOrigin } from ${JSON.stringify(resolve3(compilerRoot, "server-codegen.js"))};`,
34569
+ `import { parseCookies } from ${JSON.stringify(resolve3(compilerRoot, "server-cookies.js"))};`,
34570
+ `import * as __veskRuntime from ${JSON.stringify(resolve3(runtimeRoot, "index-server.js"))};`,
33307
34571
  "",
33308
34572
  "// Inject runtime module so server-codegen can find components like NavLink, Link, etc.",
33309
34573
  "setRuntimeModule(__veskRuntime);",
@@ -33384,8 +34648,8 @@ async function bundleRuntime(appDir, outDir2) {
33384
34648
  platform: "neutral",
33385
34649
  format: "esm",
33386
34650
  minify: true,
33387
- outfile: resolve2(outDir2, "server", "runtime.js"),
33388
- external: ["fs", "node:fs", "path", "node:path", "node:async_hooks"],
34651
+ outfile: resolve3(outDir2, "server", "runtime.js"),
34652
+ external: ["fs", "node:fs", "path", "node:path", "module", "node:module", "node:async_hooks"],
33389
34653
  target: ["es2022"],
33390
34654
  treeShaking: true
33391
34655
  });
@@ -33395,7 +34659,7 @@ async function bundleRuntime(appDir, outDir2) {
33395
34659
  if (result2.warnings.length > 0) {
33396
34660
  for (const w of result2.warnings) console.error("vesk build warning:", w.text);
33397
34661
  }
33398
- return resolve2(outDir2, "server", "runtime.js");
34662
+ return resolve3(outDir2, "server", "runtime.js");
33399
34663
  } finally {
33400
34664
  try {
33401
34665
  unlinkSync(entryFile);
@@ -33405,8 +34669,8 @@ async function bundleRuntime(appDir, outDir2) {
33405
34669
  }
33406
34670
 
33407
34671
  // ../adapter/src/ssr-function.ts
33408
- import { readFileSync as readFileSync3, existsSync as existsSync5 } from "node:fs";
33409
- import { resolve as resolve5, relative, join as join3 } from "node:path";
34672
+ import { readFileSync as readFileSync4, existsSync as existsSync5 } from "node:fs";
34673
+ import { resolve as resolve6, relative, join as join4 } from "node:path";
33410
34674
 
33411
34675
  // ../compiler/src/server-codegen.ts
33412
34676
  init_server_utils();
@@ -33421,8 +34685,8 @@ function escapeSource(src2) {
33421
34685
  function resolveErrorFile(sourceDir, appDir) {
33422
34686
  const rel = relative(appDir, sourceDir).split("/").filter(Boolean);
33423
34687
  for (let depth = rel.length; depth >= 0; depth--) {
33424
- const dir = depth === 0 ? appDir : join3(appDir, ...rel.slice(0, depth));
33425
- const p = join3(dir, "error.vsk");
34688
+ const dir = depth === 0 ? appDir : join4(appDir, ...rel.slice(0, depth));
34689
+ const p = join4(dir, "error.vsk");
33426
34690
  if (existsSync5(p)) return p;
33427
34691
  }
33428
34692
  return null;
@@ -33474,27 +34738,27 @@ function buildParamExtraction(node, urlParts) {
33474
34738
  function generateSsrFunction(routeNode, appDir, outDir2, componentMap, options2) {
33475
34739
  const ancestorLayouts = options2?.ancestorLayouts || [];
33476
34740
  const middlewareCode = options2?.middlewareCode || null;
33477
- const pagePath = resolve5(appDir, routeNode.sourceDir, "page.vsk");
33478
- const layoutPath = resolve5(appDir, routeNode.sourceDir, "layout.vsk");
34741
+ const pagePath = resolve6(appDir, routeNode.sourceDir, "page.vsk");
34742
+ const layoutPath = resolve6(appDir, routeNode.sourceDir, "layout.vsk");
33479
34743
  const parts = routeNode.fullPath.split("/").filter(Boolean);
33480
34744
  const name = routeName(parts);
33481
- const funcDir = resolve5(outDir2, "server", "functions");
33482
- const funcPath = resolve5(funcDir, `${name}.js`);
33483
- const tailwindPath = resolve5(outDir2, "static", "_tailwind.css");
33484
- const globalCssPath = resolve5(appDir, "..", "src", "global.css");
33485
- const altCssPath = resolve5(appDir, "..", "src", "app.css");
34745
+ const funcDir = resolve6(outDir2, "server", "functions");
34746
+ const funcPath = resolve6(funcDir, `${name}.js`);
34747
+ const tailwindPath = resolve6(outDir2, "static", "_tailwind.css");
34748
+ const globalCssPath = resolve6(appDir, "..", "src", "global.css");
34749
+ const altCssPath = resolve6(appDir, "..", "src", "app.css");
33486
34750
  const hasGlobalCss = existsSync5(globalCssPath) || existsSync5(altCssPath);
33487
- const hasTailwind = existsSync5(tailwindPath) && readFileSync3(tailwindPath, "utf-8").trim().length > 0;
34751
+ const hasTailwind = existsSync5(tailwindPath) && readFileSync4(tailwindPath, "utf-8").trim().length > 0;
33488
34752
  const cssUrls = [];
33489
34753
  if (hasTailwind) cssUrls.push("/_vesk/static/_tailwind.css");
33490
34754
  if (hasGlobalCss) cssUrls.push("/_vesk/static/global.css");
33491
34755
  const cssOption = cssUrls.length > 0 ? `, cssUrls: ${JSON.stringify(cssUrls)}` : "";
33492
34756
  const hasLayout = !!routeNode.layout;
33493
34757
  const hasAncestorLayout = ancestorLayouts.length > 0;
33494
- const pageSrc = readFileSync3(pagePath, "utf-8");
34758
+ const pageSrc = readFileSync4(pagePath, "utf-8");
33495
34759
  const pageComp = extractCompName(pageSrc) || "Page";
33496
34760
  const errorPath = resolveErrorFile(routeNode.sourceDir, appDir);
33497
- const errorSrc = errorPath ? readFileSync3(errorPath, "utf-8") : null;
34761
+ const errorSrc = errorPath ? readFileSync4(errorPath, "utf-8") : null;
33498
34762
  const errorComp = errorPath ? extractCompName(errorSrc) || "Error" : null;
33499
34763
  const errorVars = errorPath ? `const _errorSrc = \`${escapeSource(errorSrc)}\`;
33500
34764
  const _errorComp = ${JSON.stringify(errorComp)};
@@ -33503,7 +34767,7 @@ const _errorCompiled = (() => { try { setVskHydrate(true); return compileFile(_e
33503
34767
  ` : "const _errorSrc = null;\nconst _errorComp = null;\nconst _errorPath = null;\nconst _errorCompiled = null;\n";
33504
34768
  let src2 = "";
33505
34769
  if (hasLayout) {
33506
- const layoutSrc = readFileSync3(layoutPath, "utf-8");
34770
+ const layoutSrc = readFileSync4(layoutPath, "utf-8");
33507
34771
  const layoutComp = extractCompName(layoutSrc) || "Layout";
33508
34772
  src2 = `const _layoutSrc = \`${escapeSource(layoutSrc)}\`;
33509
34773
  const _pageSrc = \`${escapeSource(pageSrc)}\`;
@@ -33521,8 +34785,8 @@ const _pagePath = ${JSON.stringify(pagePath)};
33521
34785
  src2 += errorVars;
33522
34786
  } else if (hasAncestorLayout) {
33523
34787
  const outerLayout = ancestorLayouts[0];
33524
- const outerLayoutPath = resolve5(appDir, outerLayout.sourceDir, "layout.vsk");
33525
- const outerLayoutSrc = readFileSync3(outerLayoutPath, "utf-8");
34788
+ const outerLayoutPath = resolve6(appDir, outerLayout.sourceDir, "layout.vsk");
34789
+ const outerLayoutSrc = readFileSync4(outerLayoutPath, "utf-8");
33526
34790
  const outerLayoutComp = extractCompName(outerLayoutSrc) || "Layout";
33527
34791
  src2 = `const _pageSrc = \`${escapeSource(pageSrc)}\`;
33528
34792
  `;
@@ -33563,7 +34827,7 @@ const _comp = ${JSON.stringify(pageComp)};
33563
34827
  const compRegEntries = [];
33564
34828
  const compMap = componentMap || /* @__PURE__ */ new Map();
33565
34829
  for (const [compName, compPath] of compMap) {
33566
- const compSrc = readFileSync3(compPath, "utf-8");
34830
+ const compSrc = readFileSync4(compPath, "utf-8");
33567
34831
  const escapedSrc = escapeSource(compSrc);
33568
34832
  compRegEntries.push(` registry.set(${JSON.stringify(compName)}, async (props, __registry, __vesk) => {
33569
34833
  const _src = \`${escapedSrc}\`;
@@ -33709,6 +34973,7 @@ ${compRegEntries.join("\n")}
33709
34973
  " url,",
33710
34974
  " locals: Object.assign({}, __rootLocals),",
33711
34975
  " cookies: parseCookies(request.headers.get('cookie') || ''),",
34976
+ " resolveUrl(u) { return new URL(u, request.url).href; },",
33712
34977
  " set(key, value) { this.locals[key] = value; },",
33713
34978
  " get(key) { return this.locals[key]; },",
33714
34979
  " };",
@@ -33724,7 +34989,17 @@ ${compRegEntries.join("\n")}
33724
34989
  " }"
33725
34990
  ].join("\n");
33726
34991
  } else {
33727
- bodyCode = dataCode;
34992
+ const indentedRender = dataCode.split("\n").map((l) => l ? ` ${l}` : "").join("\n");
34993
+ bodyCode = [
34994
+ " // Request context for SSR helpers (useParams/useRequest, relative useFetch resolution).",
34995
+ " const prevReq = globalThis.__vesk_request;",
34996
+ " globalThis.__vesk_request = VeskRequest.from(request, { params });",
34997
+ " try {",
34998
+ indentedRender,
34999
+ " } finally {",
35000
+ " globalThis.__vesk_request = prevReq;",
35001
+ " }"
35002
+ ].join("\n");
33728
35003
  }
33729
35004
  let registerActionsCode;
33730
35005
  if (hasLayout || hasAncestorLayout) {
@@ -33797,6 +35072,7 @@ ${compRegEntries.join("\n")}
33797
35072
  " url: pageUrl,",
33798
35073
  " locals: {},",
33799
35074
  " cookies: parseCookies(request.headers.get('cookie') || ''),",
35075
+ " resolveUrl(u) { return new URL(u, pageUrl.href).href; },",
33800
35076
  " };",
33801
35077
  " try {",
33802
35078
  " const result = await action.execute(input, {",
@@ -33827,7 +35103,7 @@ ${compRegEntries.join("\n")}
33827
35103
  ""
33828
35104
  ].join("\n");
33829
35105
  const funcCode = [
33830
- "import { renderFullPage, renderPageStream, renderPage, compileFile, setVskHydrate, parseCookies, getAction, validateActionInput, issuesToFieldMap, storeDataScriptGlobal, withSsrStore, assertSameOrigin } from '../runtime.js';",
35106
+ "import { renderFullPage, renderPageStream, renderPage, compileFile, setVskHydrate, parseCookies, getAction, validateActionInput, issuesToFieldMap, storeDataScriptGlobal, withSsrStore, assertSameOrigin, VeskRequest } from '../runtime.js';",
33831
35107
  "",
33832
35108
  middlewareCode || "",
33833
35109
  registryCode,
@@ -33859,8 +35135,8 @@ init_actions();
33859
35135
 
33860
35136
  // ../adapter/src/api-function.ts
33861
35137
  init_strip_ts();
33862
- import { readFileSync as readFileSync4 } from "node:fs";
33863
- import { resolve as resolve6 } from "node:path";
35138
+ import { readFileSync as readFileSync5 } from "node:fs";
35139
+ import { resolve as resolve7 } from "node:path";
33864
35140
  function apiRouteName(fullPath) {
33865
35141
  const parts = fullPath.split("/").filter(Boolean);
33866
35142
  return parts.map((s) => s.startsWith(":") ? s.slice(1) || "param" : s).join("_") || "index";
@@ -33868,10 +35144,10 @@ function apiRouteName(fullPath) {
33868
35144
  function generateApiFunction(apiNode, _apiDir, outDir2, options2) {
33869
35145
  const middlewareCode = options2?.middlewareCode || null;
33870
35146
  const name = apiRouteName(apiNode.fullPath);
33871
- const funcPath = resolve6(outDir2, "server", "api", `${name}.js`);
35147
+ const funcPath = resolve7(outDir2, "server", "api", `${name}.js`);
33872
35148
  const routeFilePath = apiNode.filePath;
33873
35149
  if (!routeFilePath) throw new Error(`api route ${apiNode.fullPath} has no filePath`);
33874
- let routeSrc = readFileSync4(routeFilePath, "utf-8");
35150
+ let routeSrc = readFileSync5(routeFilePath, "utf-8");
33875
35151
  routeSrc = routeSrc.replace(/from\s+['"]@vesk\/runtime['"]\s*;?/g, "from '../runtime.js';").replace(/from\s+['"]@vesk\/runtime\/(\w+)['"]\s*;?/g, () => {
33876
35152
  return "from '../runtime.js';";
33877
35153
  });
@@ -34039,10 +35315,10 @@ function generateApiFunction(apiNode, _apiDir, outDir2, options2) {
34039
35315
  }
34040
35316
 
34041
35317
  // ../adapter/src/middleware.ts
34042
- import { readFileSync as readFileSync6 } from "node:fs";
35318
+ import { readFileSync as readFileSync7 } from "node:fs";
34043
35319
 
34044
35320
  // ../compiler/src/router.ts
34045
- import { readdirSync, statSync, existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
35321
+ import { readdirSync, statSync as statSync2, existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
34046
35322
  init_parser();
34047
35323
  init_tokens();
34048
35324
  init_scan();
@@ -34125,7 +35401,7 @@ function fallbackExtractMiddleware(src2) {
34125
35401
  function extractMiddleware(sourcePath2) {
34126
35402
  try {
34127
35403
  if (!existsSync6(sourcePath2)) return null;
34128
- const src2 = readFileSync5(sourcePath2, "utf-8");
35404
+ const src2 = readFileSync6(sourcePath2, "utf-8");
34129
35405
  const parts = extractMiddlewareParts(src2);
34130
35406
  if (!parts) return null;
34131
35407
  return `async function middleware(${parts.params}) {
@@ -34147,7 +35423,7 @@ function compileMiddleware(mwChain, _appDir) {
34147
35423
  const parts = [];
34148
35424
  for (let i = 0; i < mwChain.length; i++) {
34149
35425
  const { sourcePath: sourcePath2 } = mwChain[i];
34150
- const src2 = readFileSync6(sourcePath2, "utf-8");
35426
+ const src2 = readFileSync7(sourcePath2, "utf-8");
34151
35427
  const extracted = extractMiddlewareBody(src2);
34152
35428
  if (!extracted) continue;
34153
35429
  parts.push(`async function mw_${i}(${extracted.params}) {
@@ -34239,15 +35515,15 @@ ${extracted.body}
34239
35515
  init_esbuild_fallback();
34240
35516
  init_strip_ts();
34241
35517
  init_client_codegen();
34242
- import { readFileSync as readFileSync7, existsSync as existsSync7, writeFileSync as writeFileSync2, unlinkSync as unlinkSync2, statSync as statSync2 } from "node:fs";
34243
- import { resolve as resolve7, join as join4, dirname as dirname5, relative as relative2, sep } from "node:path";
35518
+ import { readFileSync as readFileSync8, existsSync as existsSync7, writeFileSync as writeFileSync2, unlinkSync as unlinkSync2, statSync as statSync3 } from "node:fs";
35519
+ import { resolve as resolve8, join as join5, dirname as dirname6, relative as relative2, sep } from "node:path";
34244
35520
  import { fileURLToPath as fileURLToPath2 } from "node:url";
34245
35521
  init_vsk_imports();
34246
35522
  init_md_inline();
34247
- var __dirname3 = dirname5(fileURLToPath2(import.meta.url));
35523
+ var __dirname3 = dirname6(fileURLToPath2(import.meta.url));
34248
35524
  function fileUnchanged(filePath, cached) {
34249
35525
  try {
34250
- const st = statSync2(filePath);
35526
+ const st = statSync3(filePath);
34251
35527
  return st.mtimeMs === cached.mtimeMs && st.size === cached.size;
34252
35528
  } catch {
34253
35529
  return false;
@@ -34261,15 +35537,15 @@ function buildRouterOpts(options2) {
34261
35537
  return "";
34262
35538
  }
34263
35539
  function findRuntimeSrc2(appDir) {
34264
- const monorepoRoot = resolve7(__dirname3, "..", "..", "..");
35540
+ const monorepoRoot = resolve8(__dirname3, "..", "..", "..");
34265
35541
  const candidates = [
34266
- resolve7(monorepoRoot, "packages", "runtime", "dist"),
34267
- resolve7(appDir, "..", "node_modules", "@vesk/runtime"),
34268
- resolve7(appDir, "node_modules", "@vesk/runtime")
35542
+ resolve8(monorepoRoot, "packages", "runtime", "dist"),
35543
+ resolve8(appDir, "..", "node_modules", "@vesk/runtime"),
35544
+ resolve8(appDir, "node_modules", "@vesk/runtime")
34269
35545
  ];
34270
35546
  for (const base of candidates) {
34271
- for (const dir of [base, join4(base, "dist")]) {
34272
- if (existsSync7(join4(dir, "index-client.js"))) return dir;
35547
+ for (const dir of [base, join5(base, "dist")]) {
35548
+ if (existsSync7(join5(dir, "index-client.js"))) return dir;
34273
35549
  }
34274
35550
  }
34275
35551
  throw new Error('@vesk/runtime/dist not found \u2014 run "npm run build" first');
@@ -34307,11 +35583,11 @@ async function generateClientBundle(routeTree, appDir, componentMap, options2) {
34307
35583
  return code.replace(/^import\s*\{[^}]*\}\s*from\s*['"][^'"]*\.vsk['"];?\s*\n?/gm, "");
34308
35584
  }
34309
35585
  function resolveVskImports(filePath, compile) {
34310
- const src2 = readFileSync7(filePath, "utf-8");
35586
+ const src2 = readFileSync8(filePath, "utf-8");
34311
35587
  const resolved = [];
34312
35588
  for (const importPath of collectVskImportPaths(vskImportLines(src2), filePath)) {
34313
35589
  try {
34314
- readFileSync7(importPath);
35590
+ readFileSync8(importPath);
34315
35591
  } catch {
34316
35592
  continue;
34317
35593
  }
@@ -34351,9 +35627,9 @@ async function generateClientBundle(routeTree, appDir, componentMap, options2) {
34351
35627
  return;
34352
35628
  }
34353
35629
  compiledFiles++;
34354
- let src2 = readFileSync7(filePath, "utf-8");
35630
+ let src2 = readFileSync8(filePath, "utf-8");
34355
35631
  if (/content=["'][^"']*\.md["']/i.test(src2)) {
34356
- src2 = inlineMdContentAttrs(src2, dirname5(filePath), guessProjectRoots(appDir));
35632
+ src2 = inlineMdContentAttrs(src2, dirname6(filePath), guessProjectRoots(appDir));
34357
35633
  }
34358
35634
  const namesBefore = cache2 ? new Set(runtimeImportNames) : null;
34359
35635
  const importedPaths = resolveVskImports(filePath, (p, n) => compileFile2(p, n || "", output));
@@ -34374,7 +35650,7 @@ async function generateClientBundle(routeTree, appDir, componentMap, options2) {
34374
35650
  output.push(`Object.defineProperty(__hydrators, ${JSON.stringify(resolvedName)}, { get: () => __hydrators[${JSON.stringify(actualName)}], configurable: true });`);
34375
35651
  }
34376
35652
  if (cache2 && namesBefore) {
34377
- const st = statSync2(filePath);
35653
+ const st = statSync3(filePath);
34378
35654
  cache2.files.set(filePath, {
34379
35655
  mtimeMs: st.mtimeMs,
34380
35656
  size: st.size,
@@ -34397,31 +35673,31 @@ async function generateClientBundle(routeTree, appDir, componentMap, options2) {
34397
35673
  let walkSplit2 = function(nodes, _chain) {
34398
35674
  for (const node of nodes) {
34399
35675
  const chunkCode = [];
34400
- const pagePath = resolve7(appDir, node.sourceDir, "page.vsk");
35676
+ const pagePath = resolve8(appDir, node.sourceDir, "page.vsk");
34401
35677
  if (node.page && existsSync7(pagePath)) {
34402
35678
  compileFile2(pagePath, node.page, chunkCode);
34403
35679
  }
34404
- const layoutPath = resolve7(appDir, node.sourceDir, "layout.vsk");
35680
+ const layoutPath = resolve8(appDir, node.sourceDir, "layout.vsk");
34405
35681
  if (node.layout && existsSync7(layoutPath)) {
34406
35682
  compileFile2(layoutPath, node.layout, chunkCode);
34407
35683
  }
34408
- const errorPath = resolve7(appDir, node.sourceDir, "error.vsk");
35684
+ const errorPath = resolve8(appDir, node.sourceDir, "error.vsk");
34409
35685
  if (node.error && existsSync7(errorPath)) {
34410
35686
  compileFile2(errorPath, node.error, chunkCode);
34411
35687
  }
34412
- const notFoundPath = resolve7(appDir, node.sourceDir, "not-found.vsk");
35688
+ const notFoundPath = resolve8(appDir, node.sourceDir, "not-found.vsk");
34413
35689
  if (node.notFound && existsSync7(notFoundPath)) {
34414
35690
  compileFile2(notFoundPath, node.notFound, chunkCode);
34415
35691
  }
34416
- const offlinePath = resolve7(appDir, node.sourceDir, "offline.vsk");
35692
+ const offlinePath = resolve8(appDir, node.sourceDir, "offline.vsk");
34417
35693
  if (node.offline && existsSync7(offlinePath)) {
34418
35694
  compileFile2(offlinePath, node.offline, chunkCode);
34419
35695
  }
34420
- const networkPath = resolve7(appDir, node.sourceDir, "network.vsk");
35696
+ const networkPath = resolve8(appDir, node.sourceDir, "network.vsk");
34421
35697
  if (node.network && existsSync7(networkPath)) {
34422
35698
  compileFile2(networkPath, node.network, chunkCode);
34423
35699
  }
34424
- const loadingPath = resolve7(appDir, node.sourceDir, "loading.vsk");
35700
+ const loadingPath = resolve8(appDir, node.sourceDir, "loading.vsk");
34425
35701
  if (node.loading && existsSync7(loadingPath)) {
34426
35702
  compileFile2(loadingPath, node.loading, chunkCode);
34427
35703
  }
@@ -34478,7 +35754,7 @@ ${entry.code}
34478
35754
  let compileFileMono2 = function(filePath, resolvedName) {
34479
35755
  if (seen.has(filePath)) return;
34480
35756
  seen.add(filePath);
34481
- const src2 = readFileSync7(filePath, "utf-8");
35757
+ const src2 = readFileSync8(filePath, "utf-8");
34482
35758
  resolveVskImports(filePath, (p, n) => compileFileMono2(p, n || ""));
34483
35759
  const compCode = compileClient(src2, null, { forceClient: true });
34484
35760
  if (compCode) {
@@ -34499,19 +35775,19 @@ ${entry.code}
34499
35775
  }
34500
35776
  }, walkMono2 = function(nodes) {
34501
35777
  for (const node of nodes) {
34502
- const pagePath = resolve7(appDir, node.sourceDir, "page.vsk");
35778
+ const pagePath = resolve8(appDir, node.sourceDir, "page.vsk");
34503
35779
  if (node.page && existsSync7(pagePath)) compileFileMono2(pagePath, node.page);
34504
- const layoutPath = resolve7(appDir, node.sourceDir, "layout.vsk");
35780
+ const layoutPath = resolve8(appDir, node.sourceDir, "layout.vsk");
34505
35781
  if (node.layout && existsSync7(layoutPath)) compileFileMono2(layoutPath, node.layout);
34506
- const errorPath = resolve7(appDir, node.sourceDir, "error.vsk");
35782
+ const errorPath = resolve8(appDir, node.sourceDir, "error.vsk");
34507
35783
  if (node.error && existsSync7(errorPath)) compileFileMono2(errorPath, node.error);
34508
- const notFoundPath = resolve7(appDir, node.sourceDir, "not-found.vsk");
35784
+ const notFoundPath = resolve8(appDir, node.sourceDir, "not-found.vsk");
34509
35785
  if (node.notFound && existsSync7(notFoundPath)) compileFileMono2(notFoundPath, node.notFound);
34510
- const offlinePath = resolve7(appDir, node.sourceDir, "offline.vsk");
35786
+ const offlinePath = resolve8(appDir, node.sourceDir, "offline.vsk");
34511
35787
  if (node.offline && existsSync7(offlinePath)) compileFileMono2(offlinePath, node.offline);
34512
- const networkPath = resolve7(appDir, node.sourceDir, "network.vsk");
35788
+ const networkPath = resolve8(appDir, node.sourceDir, "network.vsk");
34513
35789
  if (node.network && existsSync7(networkPath)) compileFileMono2(networkPath, node.network);
34514
- const loadingPath = resolve7(appDir, node.sourceDir, "loading.vsk");
35790
+ const loadingPath = resolve8(appDir, node.sourceDir, "loading.vsk");
34515
35791
  if (node.loading && existsSync7(loadingPath)) compileFileMono2(loadingPath, node.loading);
34516
35792
  walkMono2(node.children || []);
34517
35793
  }
@@ -34561,9 +35837,9 @@ function buildRuntimeCode(runtimeDir) {
34561
35837
  ];
34562
35838
  let code = "";
34563
35839
  for (const f of runtimeFiles) {
34564
- const p = join4(runtimeDir, f);
35840
+ const p = join5(runtimeDir, f);
34565
35841
  if (existsSync7(p)) {
34566
- let src2 = readFileSync7(p, "utf-8");
35842
+ let src2 = readFileSync8(p, "utf-8");
34567
35843
  src2 = stripTypes(src2);
34568
35844
  src2 = src2.replace(/^import\s+[\s\S]*?from\s+['"](?:\.\/.*?|@vesk\/runtime\/src\/.*?)['"];?\n?/gm, "");
34569
35845
  src2 = src2.replace(/^import\s+['"](?:\.\/.*?|@vesk\/runtime\/src\/.*?)['"];?\n?/gm, "");
@@ -34575,7 +35851,7 @@ ${src2}
34575
35851
  `;
34576
35852
  }
34577
35853
  }
34578
- const indexSrc = readFileSync7(join4(runtimeDir, "index-client.js"), "utf-8");
35854
+ const indexSrc = readFileSync8(join5(runtimeDir, "index-client.js"), "utf-8");
34579
35855
  const exportNames = stripTypes(indexSrc).match(/export\s*\{\s*([^}]+)\s*\}\s*from/g)?.flatMap((m) => m.replace(/export\s*\{\s*|\s*\}\s*from/g, "").split(",").map((s) => s.trim())) || [];
34580
35856
  code += "// --- exports ---\n";
34581
35857
  for (const name of [...new Set(exportNames)]) {
@@ -34585,7 +35861,7 @@ ${src2}
34585
35861
  return code;
34586
35862
  }
34587
35863
  function runtimeExportNames(runtimeDir) {
34588
- const indexSrc = readFileSync7(join4(runtimeDir, "index-client.js"), "utf-8");
35864
+ const indexSrc = readFileSync8(join5(runtimeDir, "index-client.js"), "utf-8");
34589
35865
  const names = /* @__PURE__ */ new Set();
34590
35866
  for (const m of indexSrc.matchAll(/export\s*\{([^}]+)\}\s*from/g)) {
34591
35867
  for (const raw2 of m[1].split(",")) {
@@ -34604,7 +35880,7 @@ async function buildTreeShakenRuntime(runtimeDir, usedNames) {
34604
35880
  console.error(`vesk: runtime names not exported \u2014 ${missing.join(", ")}; falling back to full runtime`);
34605
35881
  return buildRuntimeCode(runtimeDir);
34606
35882
  }
34607
- const entry = join4(runtimeDir, `.runtime-tree-entry-${runtimeEntryId++}.mjs`);
35883
+ const entry = join5(runtimeDir, `.runtime-tree-entry-${runtimeEntryId++}.mjs`);
34608
35884
  try {
34609
35885
  writeFileSync2(entry, `export { ${unique.join(", ")} } from './index-client.js';
34610
35886
  `);
@@ -34776,19 +36052,19 @@ function generateManifest(routes, ssrRoutes, apiRoutes, staticRoutes, middleware
34776
36052
 
34777
36053
  // ../adapter/src/static.ts
34778
36054
  init_paths();
34779
- import { mkdirSync, copyFileSync, readdirSync as readdirSync2, statSync as statSync3, existsSync as existsSync8, writeFileSync as writeFileSync3, readFileSync as readFileSync8 } from "node:fs";
34780
- import { resolve as resolve9, join as join5 } from "node:path";
36055
+ import { mkdirSync, copyFileSync, readdirSync as readdirSync2, statSync as statSync5, existsSync as existsSync9, writeFileSync as writeFileSync3, readFileSync as readFileSync10 } from "node:fs";
36056
+ import { resolve as resolve10, join as join6 } from "node:path";
34781
36057
  function copyStaticAssets(publicDir, outDir2) {
34782
- const targetDir = resolve9(outDir2, "static", "public");
36058
+ const targetDir = resolve10(outDir2, "static", "public");
34783
36059
  mkdirSync(targetDir, { recursive: true });
34784
- if (!existsSync8(publicDir)) return;
36060
+ if (!existsSync9(publicDir)) return;
34785
36061
  function copyDir(src2, dest) {
34786
36062
  mkdirSync(dest, { recursive: true });
34787
36063
  const entries = readdirSync2(src2);
34788
36064
  for (const entry of entries) {
34789
- const srcPath = join5(src2, entry);
34790
- const destPath = join5(dest, entry);
34791
- const st = statSync3(srcPath);
36065
+ const srcPath = join6(src2, entry);
36066
+ const destPath = join6(dest, entry);
36067
+ const st = statSync5(srcPath);
34792
36068
  if (st.isDirectory()) {
34793
36069
  copyDir(srcPath, destPath);
34794
36070
  } else {
@@ -34800,15 +36076,15 @@ function copyStaticAssets(publicDir, outDir2) {
34800
36076
  }
34801
36077
 
34802
36078
  // ../adapter/src/prod-server.ts
34803
- import { readFileSync as readFileSync9, existsSync as existsSync9, statSync as statSync4 } from "node:fs";
34804
- import { resolve as resolve10, extname as extname2, dirname as dirname6 } from "node:path";
36079
+ import { readFileSync as readFileSync11, existsSync as existsSync10, statSync as statSync6 } from "node:fs";
36080
+ import { resolve as resolve11, extname as extname3, dirname as dirname7 } from "node:path";
34805
36081
  import { createServer } from "node:http";
34806
- import { createRequire } from "node:module";
36082
+ import { createRequire as createRequire2 } from "node:module";
34807
36083
  import { fileURLToPath as fileURLToPath3 } from "node:url";
34808
36084
  init_server_utils();
34809
36085
  init_paths();
34810
- var _require = createRequire(import.meta.url);
34811
- var __dirname4 = dirname6(fileURLToPath3(import.meta.url));
36086
+ var _require = createRequire2(import.meta.url);
36087
+ var __dirname4 = dirname7(fileURLToPath3(import.meta.url));
34812
36088
  async function readBody(req, maxBytes = DEFAULT_MAX_BODY_BYTES) {
34813
36089
  const chunks = [];
34814
36090
  let total = 0;
@@ -34819,6 +36095,24 @@ async function readBody(req, maxBytes = DEFAULT_MAX_BODY_BYTES) {
34819
36095
  }
34820
36096
  return Buffer.concat(chunks);
34821
36097
  }
36098
+ async function deliverResponse(res, response) {
36099
+ res.writeHead(response.status, Object.fromEntries(response.headers));
36100
+ const body = response.body;
36101
+ if (body && typeof body.getReader === "function") {
36102
+ const reader = body.getReader();
36103
+ try {
36104
+ for (; ; ) {
36105
+ const { done, value } = await reader.read();
36106
+ if (done) break;
36107
+ res.write(Buffer.from(value));
36108
+ }
36109
+ } catch {
36110
+ }
36111
+ res.end();
36112
+ return;
36113
+ }
36114
+ res.end(await response.text());
36115
+ }
34822
36116
  function bodyTooLarge(maxBytes) {
34823
36117
  const err = new Error(`Request body exceeds limit (${maxBytes} bytes)`);
34824
36118
  err.status = 413;
@@ -34897,27 +36191,28 @@ async function startProdServer(outDir, options) {
34897
36191
  const host = options?.host || "127.0.0.1";
34898
36192
  const maxBodyBytes = options?.maxBodyBytes || DEFAULT_MAX_BODY_BYTES;
34899
36193
  if (!process.env.NODE_ENV) process.env.NODE_ENV = "production";
34900
- const staticDir = resolve10(outDir, "static");
34901
- const configPath = resolve10(outDir, "config.json");
34902
- if (!existsSync9(configPath)) {
36194
+ const staticDir = resolve11(outDir, "static");
36195
+ const configPath = resolve11(outDir, "config.json");
36196
+ installMdReadHook([resolve11(staticDir, "public")]);
36197
+ if (!existsSync10(configPath)) {
34903
36198
  console.error(`vesk start: no build found at ${outDir}`);
34904
36199
  console.error('Run "vesk build" first');
34905
36200
  process.exit(1);
34906
36201
  }
34907
- const buildConfig = JSON.parse(readFileSync9(configPath, "utf-8"));
36202
+ const buildConfig = JSON.parse(readFileSync11(configPath, "utf-8"));
34908
36203
  console.error(`vesk start: serving from ${outDir}`);
34909
- const projectDir = resolve10(outDir, "..");
36204
+ const projectDir = resolve11(outDir, "..");
34910
36205
  let securityConfig = {};
34911
36206
  let mdConfig;
34912
36207
  try {
34913
- const veskConfigPath = resolve10(projectDir, "vesk.config.js");
34914
- const veskConfigTsPath = resolve10(projectDir, "vesk.config.ts");
36208
+ const veskConfigPath = resolve11(projectDir, "vesk.config.js");
36209
+ const veskConfigTsPath = resolve11(projectDir, "vesk.config.ts");
34915
36210
  let rawConfig = {};
34916
- if (existsSync9(veskConfigPath)) {
36211
+ if (existsSync10(veskConfigPath)) {
34917
36212
  rawConfig = _require(veskConfigPath);
34918
- } else if (existsSync9(veskConfigTsPath)) {
36213
+ } else if (existsSync10(veskConfigTsPath)) {
34919
36214
  const { transpile } = _require("typescript");
34920
- const src = readFileSync9(veskConfigTsPath, "utf-8");
36215
+ const src = readFileSync11(veskConfigTsPath, "utf-8");
34921
36216
  const result = transpile(src, { module: 99, target: 99 });
34922
36217
  rawConfig = eval(`(${result})`);
34923
36218
  }
@@ -34946,8 +36241,8 @@ async function startProdServer(outDir, options) {
34946
36241
  } catch {
34947
36242
  }
34948
36243
  let middlewareMod = null;
34949
- const mwPath = resolve10(outDir, "server", "middleware.js");
34950
- if (existsSync9(mwPath)) {
36244
+ const mwPath = resolve11(outDir, "server", "middleware.js");
36245
+ if (existsSync10(mwPath)) {
34951
36246
  try {
34952
36247
  middlewareMod = await import(`${mwPath}?t=${Date.now()}`);
34953
36248
  } catch {
@@ -34956,8 +36251,8 @@ async function startProdServer(outDir, options) {
34956
36251
  const functionCache = /* @__PURE__ */ new Map();
34957
36252
  async function loadFunction(funcPath) {
34958
36253
  if (functionCache.has(funcPath)) return functionCache.get(funcPath);
34959
- const fullPath = resolve10(outDir, funcPath);
34960
- if (!existsSync9(fullPath)) return null;
36254
+ const fullPath = resolve11(outDir, funcPath);
36255
+ if (!existsSync10(fullPath)) return null;
34961
36256
  try {
34962
36257
  const mod = await import(`${fullPath}?t=${Date.now()}`);
34963
36258
  functionCache.set(funcPath, mod);
@@ -35017,12 +36312,12 @@ async function startProdServer(outDir, options) {
35017
36312
  }
35018
36313
  return origWriteHead(statusCode, headers2);
35019
36314
  });
35020
- const publicDir = resolve10(staticDir, "public");
36315
+ const publicDir = resolve11(staticDir, "public");
35021
36316
  const rootFile = url.pathname.length > 1 ? resolveWithin(publicDir, url.pathname.slice(1)) : null;
35022
- if (rootFile && existsSync9(rootFile) && statSync4(rootFile).isFile()) {
35023
- const ext = extname2(rootFile);
36317
+ if (rootFile && existsSync10(rootFile) && statSync6(rootFile).isFile()) {
36318
+ const ext = extname3(rootFile);
35024
36319
  res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
35025
- res.end(readFileSync9(rootFile));
36320
+ res.end(readFileSync11(rootFile));
35026
36321
  return;
35027
36322
  }
35028
36323
  if (url.pathname === "/ssr-data.js") {
@@ -35038,10 +36333,10 @@ async function startProdServer(outDir, options) {
35038
36333
  return;
35039
36334
  }
35040
36335
  if (url.pathname === "/_vesk/runtime.js") {
35041
- const clientPath = resolve10(staticDir, "client.js");
35042
- if (existsSync9(clientPath)) {
36336
+ const clientPath = resolve11(staticDir, "client.js");
36337
+ if (existsSync10(clientPath)) {
35043
36338
  res.writeHead(200, { "Content-Type": "application/javascript" });
35044
- res.end(readFileSync9(clientPath));
36339
+ res.end(readFileSync11(clientPath));
35045
36340
  return;
35046
36341
  }
35047
36342
  }
@@ -35053,20 +36348,20 @@ async function startProdServer(outDir, options) {
35053
36348
  res.end("Forbidden");
35054
36349
  return;
35055
36350
  }
35056
- if (existsSync9(staticPath) && statSync4(staticPath).isFile()) {
35057
- const ext = extname2(staticPath);
36351
+ if (existsSync10(staticPath) && statSync6(staticPath).isFile()) {
36352
+ const ext = extname3(staticPath);
35058
36353
  res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
35059
- res.end(readFileSync9(staticPath));
36354
+ res.end(readFileSync11(staticPath));
35060
36355
  return;
35061
36356
  }
35062
36357
  }
35063
36358
  if (buildConfig.prerendered) {
35064
36359
  const prerendered = buildConfig.prerendered.find((r) => r.path === url.pathname);
35065
36360
  if (prerendered) {
35066
- const htmlPath = resolve10(outDir, prerendered.file);
35067
- if (existsSync9(htmlPath)) {
36361
+ const htmlPath = resolve11(outDir, prerendered.file);
36362
+ if (existsSync10(htmlPath)) {
35068
36363
  res.writeHead(200, { "Content-Type": "text/html" });
35069
- res.end(readFileSync9(htmlPath));
36364
+ res.end(readFileSync11(htmlPath));
35070
36365
  return;
35071
36366
  }
35072
36367
  }
@@ -35128,9 +36423,7 @@ async function startProdServer(outDir, options) {
35128
36423
  try {
35129
36424
  const webRequest = makeWebRequest(req, url.href, maxBodyBytes);
35130
36425
  const response = await mod.handleAction(webRequest, actionId);
35131
- const body = await response.text();
35132
- res.writeHead(response.status, Object.fromEntries(response.headers));
35133
- res.end(body);
36426
+ await deliverResponse(res, response);
35134
36427
  } catch (e) {
35135
36428
  const status = errorStatus(e, 500);
35136
36429
  const message = status === 500 && process.env.NODE_ENV === "production" ? "Internal Server Error" : e instanceof Error ? e.message : String(e);
@@ -35149,9 +36442,7 @@ async function startProdServer(outDir, options) {
35149
36442
  try {
35150
36443
  const webRequest = makeWebRequest(req, url.href, maxBodyBytes);
35151
36444
  const response = await mod.handle(webRequest);
35152
- const body = await response.text();
35153
- res.writeHead(response.status, Object.fromEntries(response.headers));
35154
- res.end(body);
36445
+ await deliverResponse(res, response);
35155
36446
  return;
35156
36447
  } catch (e) {
35157
36448
  const status = errorStatus(e, 500);
@@ -35164,14 +36455,14 @@ async function startProdServer(outDir, options) {
35164
36455
  }
35165
36456
  }
35166
36457
  }
35167
- const appDir = resolve10(projectDir, "app");
35168
- const nfPath = resolve10(appDir, "not-found.vsk");
36458
+ const appDir = resolve11(projectDir, "app");
36459
+ const nfPath = resolve11(appDir, "not-found.vsk");
35169
36460
  let notFoundHtml = null;
35170
- if (existsSync9(nfPath)) {
36461
+ if (existsSync10(nfPath)) {
35171
36462
  try {
35172
- const runtimePath = resolve10(outDir, "server", "runtime.js");
36463
+ const runtimePath = resolve11(outDir, "server", "runtime.js");
35173
36464
  const { renderFullPage: renderFullPage2, storeDataScriptGlobal } = await import(runtimePath);
35174
- const src2 = readFileSync9(nfPath, "utf-8");
36465
+ const src2 = readFileSync11(nfPath, "utf-8");
35175
36466
  const compName = resolveComponentName(src2) || "NotFound";
35176
36467
  notFoundHtml = await renderFullPage2(src2, compName, { params: {}, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security: securityConfig?.security || {}, externalDataScript: storeDataScriptGlobal, sourcePath: nfPath });
35177
36468
  } catch {
@@ -35229,13 +36520,13 @@ async function startProdServer(outDir, options) {
35229
36520
  return;
35230
36521
  }
35231
36522
  console.error("vesk ssr error:", err.message);
35232
- const errPath = resolve10(appDir, "error.vsk");
36523
+ const errPath = resolve11(appDir, "error.vsk");
35233
36524
  let errorHtml = null;
35234
- if (existsSync9(errPath)) {
36525
+ if (existsSync10(errPath)) {
35235
36526
  try {
35236
- const runtimePath = resolve10(outDir, "server", "runtime.js");
36527
+ const runtimePath = resolve11(outDir, "server", "runtime.js");
35237
36528
  const { renderFullPage: renderFullPage2, storeDataScriptGlobal } = await import(runtimePath);
35238
- const src2 = readFileSync9(errPath, "utf-8");
36529
+ const src2 = readFileSync11(errPath, "utf-8");
35239
36530
  const compName = resolveComponentName(src2) || "Error";
35240
36531
  const expose = process.env.NODE_ENV !== "production";
35241
36532
  errorHtml = await renderFullPage2(src2, compName, { error: expose ? err.message : "Internal Server Error", stack: expose ? err.stack : "", statusCode: 500, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], clientScriptUrl: "/_vesk/static/client.js", security: securityConfig?.security || {}, externalDataScript: storeDataScriptGlobal, sourcePath: errPath });
@@ -35260,22 +36551,22 @@ async function startProdServer(outDir, options) {
35260
36551
  }
35261
36552
 
35262
36553
  // ../adapter/dist/index.js
35263
- var __dirname6 = dirname11(fileURLToPath5(import.meta.url));
36554
+ var __dirname6 = dirname12(fileURLToPath5(import.meta.url));
35264
36555
  async function resolveCompilerApi(name) {
35265
- const monorepoSrc = resolve17(__dirname6, "..", "..", "compiler", "src");
35266
- if (existsSync15(monorepoSrc)) {
35267
- const tsFile = resolve17(monorepoSrc, name.replace(/\.js$/, ".ts"));
35268
- if (existsSync15(tsFile)) {
36556
+ const monorepoSrc = resolve18(__dirname6, "..", "..", "compiler", "src");
36557
+ if (existsSync16(monorepoSrc)) {
36558
+ const tsFile = resolve18(monorepoSrc, name.replace(/\.js$/, ".ts"));
36559
+ if (existsSync16(tsFile)) {
35269
36560
  return import(tsFile);
35270
36561
  }
35271
- return import(resolve17(monorepoSrc, name));
36562
+ return import(resolve18(monorepoSrc, name));
35272
36563
  }
35273
36564
  return import(`@vesk/compiler/src/${name.replace(/\.js$/, "")}`);
35274
36565
  }
35275
36566
  async function build2(appDir, options2) {
35276
- appDir = resolve17(appDir);
35277
- const outDir2 = resolve17(options2?.outDir || resolve17(appDir, "..", ".vesk"));
35278
- const publicDir = options2?.publicDir || resolve17(appDir, "..", "public");
36567
+ appDir = resolve18(appDir);
36568
+ const outDir2 = resolve18(options2?.outDir || resolve18(appDir, "..", ".vesk"));
36569
+ const publicDir = options2?.publicDir || resolve18(appDir, "..", "public");
35279
36570
  const plugins = options2?.plugins || [];
35280
36571
  if (options2?.md) {
35281
36572
  const { configureMd: configureMd3 } = await Promise.resolve().then(() => (init_md(), md_exports));
@@ -35288,10 +36579,10 @@ async function build2(appDir, options2) {
35288
36579
  }
35289
36580
  console.error(`vesk build: output \u2192 ${outDir2}`);
35290
36581
  const dirs = [
35291
- resolve17(outDir2, "server", "functions"),
35292
- resolve17(outDir2, "server", "api"),
35293
- resolve17(outDir2, "static", "public"),
35294
- resolve17(outDir2, "prerendered")
36582
+ resolve18(outDir2, "server", "functions"),
36583
+ resolve18(outDir2, "server", "api"),
36584
+ resolve18(outDir2, "static", "public"),
36585
+ resolve18(outDir2, "prerendered")
35295
36586
  ];
35296
36587
  for (const d of dirs)
35297
36588
  mkdirSync6(d, { recursive: true });
@@ -35303,14 +36594,14 @@ async function build2(appDir, options2) {
35303
36594
  console.error("vesk build: no routes found in", appDir);
35304
36595
  return;
35305
36596
  }
35306
- const projectRoot = resolve17(appDir, "..");
35307
- const componentsDir = resolve17(projectRoot, "components");
36597
+ const projectRoot = resolve18(appDir, "..");
36598
+ const componentsDir = resolve18(projectRoot, "components");
35308
36599
  const componentMap = scanComponents(componentsDir);
35309
36600
  if (componentMap.size > 0) {
35310
36601
  console.error(`vesk build: ${componentMap.size} external components found in ${componentsDir}`);
35311
36602
  }
35312
- const apiDir = resolve17(appDir, "api");
35313
- const apiTree = existsSync15(apiDir) ? scanApiRoutes2(apiDir) : [];
36603
+ const apiDir = resolve18(appDir, "api");
36604
+ const apiTree = existsSync16(apiDir) ? scanApiRoutes2(apiDir) : [];
35314
36605
  console.error(`vesk build: ${routeTree.length} root routes, ${apiTree.length} API routes`);
35315
36606
  console.error("vesk build: bundling server runtime...");
35316
36607
  await bundleRuntime(appDir, outDir2);
@@ -35323,21 +36614,21 @@ async function build2(appDir, options2) {
35323
36614
  const mwChain2 = collectMiddlewareChain2(routeTree, node.fullPath, appDir);
35324
36615
  let mwCode = null;
35325
36616
  if (mwChain2.length > 0) {
35326
- const mwSources = mwChain2.map((m) => readFileSync14(m.sourcePath, "utf-8"));
36617
+ const mwSources = mwChain2.map((m) => readFileSync16(m.sourcePath, "utf-8"));
35327
36618
  mwCode = compileMiddlewareCode(mwSources);
35328
36619
  }
35329
36620
  const { funcPath, funcCode, name } = generateSsrFunction(node, appDir, outDir2, componentMap, { ancestorLayouts, middlewareCode: mwCode });
35330
36621
  writeFileSync8(funcPath, funcCode, "utf-8");
35331
- const pagePath = resolve17(appDir, node.sourceDir, "page.vsk");
35332
- if (existsSync15(pagePath)) {
35333
- const src2 = readFileSync14(pagePath, "utf-8");
36622
+ const pagePath = resolve18(appDir, node.sourceDir, "page.vsk");
36623
+ if (existsSync16(pagePath)) {
36624
+ const src2 = readFileSync16(pagePath, "utf-8");
35334
36625
  const actionIds = collectActionIds(src2);
35335
36626
  if (node.layout) {
35336
- const layoutSrc = readFileSync14(resolve17(appDir, node.sourceDir, "layout.vsk"), "utf-8");
36627
+ const layoutSrc = readFileSync16(resolve18(appDir, node.sourceDir, "layout.vsk"), "utf-8");
35337
36628
  actionIds.push(...collectActionIds(layoutSrc));
35338
36629
  }
35339
36630
  for (const a of ancestorLayouts) {
35340
- const ancestorSrc = readFileSync14(resolve17(appDir, a.sourceDir, "layout.vsk"), "utf-8");
36631
+ const ancestorSrc = readFileSync16(resolve18(appDir, a.sourceDir, "layout.vsk"), "utf-8");
35341
36632
  actionIds.push(...collectActionIds(ancestorSrc));
35342
36633
  }
35343
36634
  for (const id of actionIds) {
@@ -35377,7 +36668,7 @@ async function build2(appDir, options2) {
35377
36668
  if (mwChain.length > 0) {
35378
36669
  const mwCode = compileMiddleware(mwChain, appDir);
35379
36670
  if (mwCode) {
35380
- writeFileSync8(resolve17(outDir2, "server", "middleware.js"), mwCode, "utf-8");
36671
+ writeFileSync8(resolve18(outDir2, "server", "middleware.js"), mwCode, "utf-8");
35381
36672
  middlewareEnabled = true;
35382
36673
  console.error(`vesk build: mw \u2192 server/middleware.js (${mwChain.length} middlewares)`);
35383
36674
  }
@@ -35391,28 +36682,28 @@ async function build2(appDir, options2) {
35391
36682
  if (options2?.routeDataCache !== void 0)
35392
36683
  bundleOpts.routeDataCache = options2.routeDataCache;
35393
36684
  const { main, chunks } = await generateClientBundle(routeTree, appDir, componentMap, bundleOpts);
35394
- writeFileSync8(resolve17(outDir2, "static", "client.js"), main, "utf-8");
36685
+ writeFileSync8(resolve18(outDir2, "static", "client.js"), main, "utf-8");
35395
36686
  const mode = chunks.length > 0 ? "code-split" : "monolithic";
35396
36687
  console.error(`vesk build: client \u2192 static/client.js (${main.length} bytes, ${mode})`);
35397
36688
  if (chunks.length > 0) {
35398
- const staticDir2 = resolve17(outDir2, "static");
36689
+ const staticDir2 = resolve18(outDir2, "static");
35399
36690
  for (const chunk of chunks) {
35400
- writeFileSync8(resolve17(staticDir2, chunk.name), chunk.code, "utf-8");
36691
+ writeFileSync8(resolve18(staticDir2, chunk.name), chunk.code, "utf-8");
35401
36692
  console.error(`vesk build: chunk \u2192 static/${chunk.name} (${chunk.code.length} bytes)`);
35402
36693
  }
35403
36694
  }
35404
36695
  copyStaticAssets(publicDir, outDir2);
35405
36696
  console.error("vesk build: static \u2192 static/public/");
35406
- const srcDir = resolve17(appDir, "..", "src");
35407
- const cssSrc = resolve17(srcDir, "global.css");
35408
- const altCssSrc = resolve17(srcDir, "app.css");
36697
+ const srcDir = resolve18(appDir, "..", "src");
36698
+ const cssSrc = resolve18(srcDir, "global.css");
36699
+ const altCssSrc = resolve18(srcDir, "app.css");
35409
36700
  let cssContent = null;
35410
36701
  let cssSourcePath = null;
35411
- if (existsSync15(cssSrc)) {
35412
- cssContent = readFileSync14(cssSrc, "utf-8");
36702
+ if (existsSync16(cssSrc)) {
36703
+ cssContent = readFileSync16(cssSrc, "utf-8");
35413
36704
  cssSourcePath = cssSrc;
35414
- } else if (existsSync15(altCssSrc)) {
35415
- cssContent = readFileSync14(altCssSrc, "utf-8");
36705
+ } else if (existsSync16(altCssSrc)) {
36706
+ cssContent = readFileSync16(altCssSrc, "utf-8");
35416
36707
  cssSourcePath = altCssSrc;
35417
36708
  }
35418
36709
  function stripTailwindDirectives2(css) {
@@ -35436,7 +36727,7 @@ async function build2(appDir, options2) {
35436
36727
  }
35437
36728
  if (cssContent !== null) {
35438
36729
  const userCss = stripTailwindDirectives2(cssContent);
35439
- const userCssTarget = resolve17(outDir2, "static", "global.css");
36730
+ const userCssTarget = resolve18(outDir2, "static", "global.css");
35440
36731
  writeFileSync8(userCssTarget, userCss, "utf-8");
35441
36732
  console.error(`vesk build: css \u2192 static/global.css (${userCss.length} bytes)`);
35442
36733
  let twCss = cssContent;
@@ -35448,7 +36739,7 @@ async function build2(appDir, options2) {
35448
36739
  }
35449
36740
  }
35450
36741
  }
35451
- const twCssTarget = resolve17(outDir2, "static", "_tailwind.css");
36742
+ const twCssTarget = resolve18(outDir2, "static", "_tailwind.css");
35452
36743
  const hasUnresolvedTailwindImport = /@import\s+['"]tailwindcss['"]/.test(twCss);
35453
36744
  if (hasUnresolvedTailwindImport) {
35454
36745
  const lines = twCss.split("\n").filter((l) => !/^\s*@import\s+['"]tailwindcss['"]/.test(l));
@@ -35488,23 +36779,23 @@ async function build2(appDir, options2) {
35488
36779
  }
35489
36780
  {
35490
36781
  const { generateSitemap: generateSitemap2, generateRobotsTxt: generateRobotsTxt2 } = await Promise.resolve().then(() => (init_static(), static_exports));
35491
- const publicDirResolved = resolve17(outDir2, "static", "public");
36782
+ const publicDirResolved = resolve18(outDir2, "static", "public");
35492
36783
  const siteUrl = options2?.siteUrl || "http://localhost:3000";
35493
- const sitemapOverride = resolve17(publicDirResolved, "sitemap.xml");
35494
- if (!existsSync15(sitemapOverride)) {
36784
+ const sitemapOverride = resolve18(publicDirResolved, "sitemap.xml");
36785
+ if (!existsSync16(sitemapOverride)) {
35495
36786
  const sitemap = generateSitemap2(routeTree, ssrRoutes, prerenderedRoutes, { siteUrl });
35496
36787
  writeFileSync8(sitemapOverride, sitemap, "utf-8");
35497
36788
  console.error(`vesk build: seo \u2192 static/public/sitemap.xml (${sitemap.length} bytes)`);
35498
36789
  }
35499
- const robotsOverride = resolve17(publicDirResolved, "robots.txt");
35500
- if (!existsSync15(robotsOverride)) {
36790
+ const robotsOverride = resolve18(publicDirResolved, "robots.txt");
36791
+ if (!existsSync16(robotsOverride)) {
35501
36792
  const robots = generateRobotsTxt2(siteUrl);
35502
36793
  writeFileSync8(robotsOverride, robots, "utf-8");
35503
36794
  console.error(`vesk build: seo \u2192 static/public/robots.txt (${robots.length} bytes)`);
35504
36795
  }
35505
36796
  }
35506
36797
  const manifest = generateManifest(routeTree, ssrRoutes, apiRoutes, prerenderedRoutes, middlewareEnabled, actionMap);
35507
- writeFileSync8(resolve17(outDir2, "config.json"), JSON.stringify(manifest, null, 2) + "\n", "utf-8");
36798
+ writeFileSync8(resolve18(outDir2, "config.json"), JSON.stringify(manifest, null, 2) + "\n", "utf-8");
35508
36799
  console.error("vesk build: config \u2192 config.json");
35509
36800
  {
35510
36801
  const { detectPlatform: detectPlatform2 } = await Promise.resolve().then(() => (init_platform(), platform_exports));
@@ -35543,16 +36834,16 @@ vesk build: done (${outDir2})`);
35543
36834
  init_seo_audit();
35544
36835
 
35545
36836
  // src/dev-server.ts
35546
- import { readFileSync as readFileSync19, watch, statSync as statSync13, existsSync as existsSync22, readdirSync as readdirSync11 } from "node:fs";
35547
- import { resolve as resolve23, extname as extname5, join as join12 } from "node:path";
36837
+ import { readFileSync as readFileSync22, watch, statSync as statSync16, existsSync as existsSync24, readdirSync as readdirSync11 } from "node:fs";
36838
+ import { resolve as resolve24, extname as extname6, join as join13 } from "node:path";
35548
36839
  import { createServer as createServer2 } from "node:http";
35549
36840
  import { WebSocketServer } from "ws";
35550
36841
 
35551
36842
  // ../compiler/dist/strip-ts.js
35552
36843
  init_parser();
35553
36844
  import { walk as walk4 } from "zimmerframe";
35554
- import { print as print5 } from "esrap";
35555
- import ts5 from "esrap/languages/ts";
36845
+ import { print as print6 } from "esrap";
36846
+ import ts6 from "esrap/languages/ts";
35556
36847
  var TS_NODE_TYPES2 = /* @__PURE__ */ new Set([
35557
36848
  "TSAsExpression",
35558
36849
  "TSSatisfiesExpression",
@@ -35693,7 +36984,7 @@ function stripCodeTypes2(code) {
35693
36984
  stripped.body = stripped.body.filter((n) => !isTypeOnlyStatement2(n));
35694
36985
  }
35695
36986
  try {
35696
- return print5(stripped, ts5()).code;
36987
+ return print6(stripped, ts6()).code;
35697
36988
  } catch {
35698
36989
  return code;
35699
36990
  }
@@ -35742,12 +37033,13 @@ init_parser();
35742
37033
  init_ir_generator();
35743
37034
  init_actions();
35744
37035
  init_server_utils();
37036
+ init_module_imports();
35745
37037
  init_scan();
35746
37038
  init_md_inline();
35747
37039
  init_strip_ts();
35748
37040
  import { walk as walk5 } from "zimmerframe";
35749
- import { print as print6 } from "esrap";
35750
- import ts6 from "esrap/languages/ts";
37041
+ import { print as print7 } from "esrap";
37042
+ import ts7 from "esrap/languages/ts";
35751
37043
  import tsx2 from "esrap/languages/tsx";
35752
37044
  function callExpr2(callee, args2 = []) {
35753
37045
  return { type: "CallExpression", callee, arguments: args2, optional: false };
@@ -35792,7 +37084,7 @@ function containsJsx2(node, depth = 0) {
35792
37084
  return false;
35793
37085
  }
35794
37086
  function printAst2(ast) {
35795
- return print6(ast, containsJsx2(ast) ? tsx2() : ts6()).code;
37087
+ return print7(ast, containsJsx2(ast) ? tsx2() : ts7()).code;
35796
37088
  }
35797
37089
  function transformTracked2(irNode, tracked2) {
35798
37090
  const ast = irNode.ast;
@@ -35878,7 +37170,7 @@ function transformTracked2(irNode, tracked2) {
35878
37170
  return context.next();
35879
37171
  }
35880
37172
  });
35881
- return print6(transformed, containsJsx2(transformed) ? tsx2() : ts6()).code;
37173
+ return print7(transformed, containsJsx2(transformed) ? tsx2() : ts7()).code;
35882
37174
  }
35883
37175
  function collectTrackedNames2(body) {
35884
37176
  const names = /* @__PURE__ */ new Map();
@@ -37201,7 +38493,13 @@ function emitClientFromIR2(ir, options2) {
37201
38493
  runtimeNames.push(name);
37202
38494
  }
37203
38495
  }
37204
- const runtimeImport = `import { ${runtimeNames.join(", ")} } from '@vesk/runtime';`;
38496
+ const boundLocally = /* @__PURE__ */ new Set();
38497
+ for (const imp of ir.imports) {
38498
+ for (const pair of importBindingPairs(imp))
38499
+ boundLocally.add(pair.local);
38500
+ }
38501
+ const shadowedRuntimeNames = runtimeNames.filter((n) => !boundLocally.has(n));
38502
+ const runtimeImport = `import { ${shadowedRuntimeNames.length > 0 ? shadowedRuntimeNames.join(", ") : "destroy_block"} } from '@vesk/runtime';`;
37205
38503
  const moduleCode = `
37206
38504
  ${runtimeImport}
37207
38505
  ${importLines}
@@ -37225,8 +38523,8 @@ init_parser();
37225
38523
  init_tokens();
37226
38524
  init_scan();
37227
38525
  init_strip_ts();
37228
- import { readdirSync as readdirSync7, statSync as statSync9, existsSync as existsSync16, readFileSync as readFileSync15 } from "fs";
37229
- import { join as join8, relative as relative5, basename } from "path";
38526
+ import { readdirSync as readdirSync7, statSync as statSync11, existsSync as existsSync17, readFileSync as readFileSync17 } from "fs";
38527
+ import { join as join9, relative as relative5, basename } from "path";
37230
38528
  function collapseSlashes2(p) {
37231
38529
  let out = "";
37232
38530
  let prevSlash = false;
@@ -37243,7 +38541,7 @@ function collapseSlashes2(p) {
37243
38541
  return out;
37244
38542
  }
37245
38543
  function scanRoutes(appDir, options2 = {}) {
37246
- if (!existsSync16(appDir)) {
38544
+ if (!existsSync17(appDir)) {
37247
38545
  return [];
37248
38546
  }
37249
38547
  return scanDirectory(appDir, appDir, "/", options2);
@@ -37346,10 +38644,10 @@ function scanDirectory(rootDir, dir, parentPath, options2) {
37346
38644
  segmentCount: isGroup || dir === rootDir ? 0 : 1
37347
38645
  };
37348
38646
  for (const entry of entries) {
37349
- const entryPath = join8(dir, entry);
38647
+ const entryPath = join9(dir, entry);
37350
38648
  let entryStat;
37351
38649
  try {
37352
- entryStat = statSync9(entryPath);
38650
+ entryStat = statSync11(entryPath);
37353
38651
  } catch {
37354
38652
  continue;
37355
38653
  }
@@ -37398,19 +38696,19 @@ function collectSources(tree) {
37398
38696
  function walk6(nodes) {
37399
38697
  for (const node of nodes) {
37400
38698
  if (node.page)
37401
- map.set(node.page, join8(node.sourceDir, "page.vsk"));
38699
+ map.set(node.page, join9(node.sourceDir, "page.vsk"));
37402
38700
  if (node.layout)
37403
- map.set(node.layout, join8(node.sourceDir, "layout.vsk"));
38701
+ map.set(node.layout, join9(node.sourceDir, "layout.vsk"));
37404
38702
  if (node.loading)
37405
- map.set(node.loading, join8(node.sourceDir, "loading.vsk"));
38703
+ map.set(node.loading, join9(node.sourceDir, "loading.vsk"));
37406
38704
  if (node.error)
37407
- map.set(node.error, join8(node.sourceDir, "error.vsk"));
38705
+ map.set(node.error, join9(node.sourceDir, "error.vsk"));
37408
38706
  if (node.notFound)
37409
- map.set(node.notFound, join8(node.sourceDir, "not-found.vsk"));
38707
+ map.set(node.notFound, join9(node.sourceDir, "not-found.vsk"));
37410
38708
  if (node.offline)
37411
- map.set(node.offline, join8(node.sourceDir, "offline.vsk"));
38709
+ map.set(node.offline, join9(node.sourceDir, "offline.vsk"));
37412
38710
  if (node.network)
37413
- map.set(node.network, join8(node.sourceDir, "network.vsk"));
38711
+ map.set(node.network, join9(node.sourceDir, "network.vsk"));
37414
38712
  walk6(node.children);
37415
38713
  }
37416
38714
  }
@@ -37496,15 +38794,15 @@ function matchUrl(tree, pathname) {
37496
38794
  }
37497
38795
 
37498
38796
  // ../compiler/dist/api-routes.js
37499
- import { readdirSync as readdirSync8, statSync as statSync10, existsSync as existsSync17 } from "fs";
37500
- import { join as join9 } from "path";
38797
+ import { readdirSync as readdirSync8, statSync as statSync12, existsSync as existsSync18 } from "fs";
38798
+ import { join as join10 } from "path";
37501
38799
  init_server_utils();
37502
38800
  function basename2(p) {
37503
38801
  const idx = p.lastIndexOf("/");
37504
38802
  return idx === -1 ? p : p.slice(idx + 1);
37505
38803
  }
37506
38804
  function scanApiRoutes(apiDir) {
37507
- if (!existsSync17(apiDir))
38805
+ if (!existsSync18(apiDir))
37508
38806
  return [];
37509
38807
  return scanApiDir(apiDir, apiDir, "/");
37510
38808
  }
@@ -37534,10 +38832,10 @@ function scanApiDir(rootDir, dir, parentPath) {
37534
38832
  return nodes;
37535
38833
  if (isRouteGroup) {
37536
38834
  for (const entry of entries) {
37537
- const entryPath = join9(dir, entry);
38835
+ const entryPath = join10(dir, entry);
37538
38836
  let entryStat;
37539
38837
  try {
37540
- entryStat = statSync10(entryPath);
38838
+ entryStat = statSync12(entryPath);
37541
38839
  } catch {
37542
38840
  continue;
37543
38841
  }
@@ -37564,14 +38862,14 @@ function scanApiDir(rootDir, dir, parentPath) {
37564
38862
  fullPath: collapseSlashes(fullPath) || "/",
37565
38863
  isDynamic,
37566
38864
  isCatchAll,
37567
- filePath: hasRoute && routeFileName ? join9(dir, routeFileName) : null,
38865
+ filePath: hasRoute && routeFileName ? join10(dir, routeFileName) : null,
37568
38866
  children: []
37569
38867
  };
37570
38868
  for (const entry of entries) {
37571
- const entryPath = join9(dir, entry);
38869
+ const entryPath = join10(dir, entry);
37572
38870
  let entryStat;
37573
38871
  try {
37574
- entryStat = statSync10(entryPath);
38872
+ entryStat = statSync12(entryPath);
37575
38873
  } catch {
37576
38874
  continue;
37577
38875
  }
@@ -37869,8 +39167,8 @@ async function executeRewrite(url, originalRequest) {
37869
39167
  }
37870
39168
 
37871
39169
  // ../compiler/dist/middleware.js
37872
- import { existsSync as existsSync18 } from "fs";
37873
- import { resolve as resolve18 } from "path";
39170
+ import { existsSync as existsSync19 } from "fs";
39171
+ import { resolve as resolve19 } from "path";
37874
39172
 
37875
39173
  // ../compiler/src/api-routes.ts
37876
39174
  init_server_utils();
@@ -37929,8 +39227,8 @@ function collectMiddlewareChain(routeTree, url, appDir) {
37929
39227
  }
37930
39228
  function collectForNode(node) {
37931
39229
  if (node.hasMiddleware) {
37932
- const mwPath2 = resolve18(appDir, node.sourceDir, "middleware.ts");
37933
- if (existsSync18(mwPath2)) {
39230
+ const mwPath2 = resolve19(appDir, node.sourceDir, "middleware.ts");
39231
+ if (existsSync19(mwPath2)) {
37934
39232
  chain.push({ sourcePath: mwPath2, node });
37935
39233
  }
37936
39234
  }
@@ -38093,8 +39391,8 @@ async function executeMiddlewareChain(chain, request, params, options2 = {}) {
38093
39391
  }
38094
39392
 
38095
39393
  // ../adapter/dist/client-bundle.js
38096
- import { readFileSync as readFileSync16, existsSync as existsSync19, writeFileSync as writeFileSync9, unlinkSync as unlinkSync3, statSync as statSync11 } from "node:fs";
38097
- import { resolve as resolve19, join as join10, dirname as dirname12, relative as relative6, sep as sep3 } from "node:path";
39394
+ import { readFileSync as readFileSync18, existsSync as existsSync20, writeFileSync as writeFileSync9, unlinkSync as unlinkSync3, statSync as statSync13 } from "node:fs";
39395
+ import { resolve as resolve20, join as join11, dirname as dirname13, relative as relative6, sep as sep3 } from "node:path";
38098
39396
  import { fileURLToPath as fileURLToPath6 } from "node:url";
38099
39397
 
38100
39398
  // ../adapter/dist/esbuild-fallback.js
@@ -38149,10 +39447,10 @@ init_strip_ts();
38149
39447
  init_client_codegen();
38150
39448
  init_vsk_imports();
38151
39449
  init_md_inline();
38152
- var __dirname7 = dirname12(fileURLToPath6(import.meta.url));
39450
+ var __dirname7 = dirname13(fileURLToPath6(import.meta.url));
38153
39451
  function fileUnchanged2(filePath, cached) {
38154
39452
  try {
38155
- const st = statSync11(filePath);
39453
+ const st = statSync13(filePath);
38156
39454
  return st.mtimeMs === cached.mtimeMs && st.size === cached.size;
38157
39455
  } catch {
38158
39456
  return false;
@@ -38166,15 +39464,15 @@ function buildRouterOpts2(options2) {
38166
39464
  return "";
38167
39465
  }
38168
39466
  function findRuntimeSrc3(appDir) {
38169
- const monorepoRoot = resolve19(__dirname7, "..", "..", "..");
39467
+ const monorepoRoot = resolve20(__dirname7, "..", "..", "..");
38170
39468
  const candidates = [
38171
- resolve19(monorepoRoot, "packages", "runtime", "dist"),
38172
- resolve19(appDir, "..", "node_modules", "@vesk/runtime"),
38173
- resolve19(appDir, "node_modules", "@vesk/runtime")
39469
+ resolve20(monorepoRoot, "packages", "runtime", "dist"),
39470
+ resolve20(appDir, "..", "node_modules", "@vesk/runtime"),
39471
+ resolve20(appDir, "node_modules", "@vesk/runtime")
38174
39472
  ];
38175
39473
  for (const base of candidates) {
38176
- for (const dir of [base, join10(base, "dist")]) {
38177
- if (existsSync19(join10(dir, "index-client.js")))
39474
+ for (const dir of [base, join11(base, "dist")]) {
39475
+ if (existsSync20(join11(dir, "index-client.js")))
38178
39476
  return dir;
38179
39477
  }
38180
39478
  }
@@ -38214,11 +39512,11 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options2)
38214
39512
  return code.replace(/^import\s*\{[^}]*\}\s*from\s*['"][^'"]*\.vsk['"];?\s*\n?/gm, "");
38215
39513
  }
38216
39514
  function resolveVskImports(filePath, compile) {
38217
- const src2 = readFileSync16(filePath, "utf-8");
39515
+ const src2 = readFileSync18(filePath, "utf-8");
38218
39516
  const resolved = [];
38219
39517
  for (const importPath of collectVskImportPaths(vskImportLines(src2), filePath)) {
38220
39518
  try {
38221
- readFileSync16(importPath);
39519
+ readFileSync18(importPath);
38222
39520
  } catch {
38223
39521
  continue;
38224
39522
  }
@@ -38263,9 +39561,9 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options2)
38263
39561
  return;
38264
39562
  }
38265
39563
  compiledFiles++;
38266
- let src2 = readFileSync16(filePath, "utf-8");
39564
+ let src2 = readFileSync18(filePath, "utf-8");
38267
39565
  if (/content=["'][^"']*\.md["']/i.test(src2)) {
38268
- src2 = inlineMdContentAttrs(src2, dirname12(filePath), guessProjectRoots(appDir));
39566
+ src2 = inlineMdContentAttrs(src2, dirname13(filePath), guessProjectRoots(appDir));
38269
39567
  }
38270
39568
  const namesBefore = cache2 ? new Set(runtimeImportNames) : null;
38271
39569
  const importedPaths = resolveVskImports(filePath, (p, n) => compileFile2(p, n || "", output));
@@ -38290,7 +39588,7 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options2)
38290
39588
  output.push(`Object.defineProperty(__hydrators, ${JSON.stringify(resolvedName)}, { get: () => __hydrators[${JSON.stringify(actualName)}], configurable: true });`);
38291
39589
  }
38292
39590
  if (cache2 && namesBefore) {
38293
- const st = statSync11(filePath);
39591
+ const st = statSync13(filePath);
38294
39592
  cache2.files.set(filePath, {
38295
39593
  mtimeMs: st.mtimeMs,
38296
39594
  size: st.size,
@@ -38313,32 +39611,32 @@ async function generateClientBundle2(routeTree, appDir, componentMap, options2)
38313
39611
  let walkSplit2 = function(nodes, _chain) {
38314
39612
  for (const node of nodes) {
38315
39613
  const chunkCode = [];
38316
- const pagePath = resolve19(appDir, node.sourceDir, "page.vsk");
38317
- if (node.page && existsSync19(pagePath)) {
39614
+ const pagePath = resolve20(appDir, node.sourceDir, "page.vsk");
39615
+ if (node.page && existsSync20(pagePath)) {
38318
39616
  compileFile2(pagePath, node.page, chunkCode);
38319
39617
  }
38320
- const layoutPath = resolve19(appDir, node.sourceDir, "layout.vsk");
38321
- if (node.layout && existsSync19(layoutPath)) {
39618
+ const layoutPath = resolve20(appDir, node.sourceDir, "layout.vsk");
39619
+ if (node.layout && existsSync20(layoutPath)) {
38322
39620
  compileFile2(layoutPath, node.layout, chunkCode);
38323
39621
  }
38324
- const errorPath = resolve19(appDir, node.sourceDir, "error.vsk");
38325
- if (node.error && existsSync19(errorPath)) {
39622
+ const errorPath = resolve20(appDir, node.sourceDir, "error.vsk");
39623
+ if (node.error && existsSync20(errorPath)) {
38326
39624
  compileFile2(errorPath, node.error, chunkCode);
38327
39625
  }
38328
- const notFoundPath = resolve19(appDir, node.sourceDir, "not-found.vsk");
38329
- if (node.notFound && existsSync19(notFoundPath)) {
39626
+ const notFoundPath = resolve20(appDir, node.sourceDir, "not-found.vsk");
39627
+ if (node.notFound && existsSync20(notFoundPath)) {
38330
39628
  compileFile2(notFoundPath, node.notFound, chunkCode);
38331
39629
  }
38332
- const offlinePath = resolve19(appDir, node.sourceDir, "offline.vsk");
38333
- if (node.offline && existsSync19(offlinePath)) {
39630
+ const offlinePath = resolve20(appDir, node.sourceDir, "offline.vsk");
39631
+ if (node.offline && existsSync20(offlinePath)) {
38334
39632
  compileFile2(offlinePath, node.offline, chunkCode);
38335
39633
  }
38336
- const networkPath = resolve19(appDir, node.sourceDir, "network.vsk");
38337
- if (node.network && existsSync19(networkPath)) {
39634
+ const networkPath = resolve20(appDir, node.sourceDir, "network.vsk");
39635
+ if (node.network && existsSync20(networkPath)) {
38338
39636
  compileFile2(networkPath, node.network, chunkCode);
38339
39637
  }
38340
- const loadingPath = resolve19(appDir, node.sourceDir, "loading.vsk");
38341
- if (node.loading && existsSync19(loadingPath)) {
39638
+ const loadingPath = resolve20(appDir, node.sourceDir, "loading.vsk");
39639
+ if (node.loading && existsSync20(loadingPath)) {
38342
39640
  compileFile2(loadingPath, node.loading, chunkCode);
38343
39641
  }
38344
39642
  if (chunkCode.length > 0) {
@@ -38397,7 +39695,7 @@ ${entry.code}
38397
39695
  if (seen.has(filePath))
38398
39696
  return;
38399
39697
  seen.add(filePath);
38400
- const src2 = readFileSync16(filePath, "utf-8");
39698
+ const src2 = readFileSync18(filePath, "utf-8");
38401
39699
  resolveVskImports(filePath, (p, n) => compileFileMono2(p, n || ""));
38402
39700
  const compCode = compileClient(src2, null, { forceClient: true });
38403
39701
  if (compCode) {
@@ -38418,26 +39716,26 @@ ${entry.code}
38418
39716
  }
38419
39717
  }, walkMono2 = function(nodes) {
38420
39718
  for (const node of nodes) {
38421
- const pagePath = resolve19(appDir, node.sourceDir, "page.vsk");
38422
- if (node.page && existsSync19(pagePath))
39719
+ const pagePath = resolve20(appDir, node.sourceDir, "page.vsk");
39720
+ if (node.page && existsSync20(pagePath))
38423
39721
  compileFileMono2(pagePath, node.page);
38424
- const layoutPath = resolve19(appDir, node.sourceDir, "layout.vsk");
38425
- if (node.layout && existsSync19(layoutPath))
39722
+ const layoutPath = resolve20(appDir, node.sourceDir, "layout.vsk");
39723
+ if (node.layout && existsSync20(layoutPath))
38426
39724
  compileFileMono2(layoutPath, node.layout);
38427
- const errorPath = resolve19(appDir, node.sourceDir, "error.vsk");
38428
- if (node.error && existsSync19(errorPath))
39725
+ const errorPath = resolve20(appDir, node.sourceDir, "error.vsk");
39726
+ if (node.error && existsSync20(errorPath))
38429
39727
  compileFileMono2(errorPath, node.error);
38430
- const notFoundPath = resolve19(appDir, node.sourceDir, "not-found.vsk");
38431
- if (node.notFound && existsSync19(notFoundPath))
39728
+ const notFoundPath = resolve20(appDir, node.sourceDir, "not-found.vsk");
39729
+ if (node.notFound && existsSync20(notFoundPath))
38432
39730
  compileFileMono2(notFoundPath, node.notFound);
38433
- const offlinePath = resolve19(appDir, node.sourceDir, "offline.vsk");
38434
- if (node.offline && existsSync19(offlinePath))
39731
+ const offlinePath = resolve20(appDir, node.sourceDir, "offline.vsk");
39732
+ if (node.offline && existsSync20(offlinePath))
38435
39733
  compileFileMono2(offlinePath, node.offline);
38436
- const networkPath = resolve19(appDir, node.sourceDir, "network.vsk");
38437
- if (node.network && existsSync19(networkPath))
39734
+ const networkPath = resolve20(appDir, node.sourceDir, "network.vsk");
39735
+ if (node.network && existsSync20(networkPath))
38438
39736
  compileFileMono2(networkPath, node.network);
38439
- const loadingPath = resolve19(appDir, node.sourceDir, "loading.vsk");
38440
- if (node.loading && existsSync19(loadingPath))
39737
+ const loadingPath = resolve20(appDir, node.sourceDir, "loading.vsk");
39738
+ if (node.loading && existsSync20(loadingPath))
38441
39739
  compileFileMono2(loadingPath, node.loading);
38442
39740
  walkMono2(node.children || []);
38443
39741
  }
@@ -38487,9 +39785,9 @@ function buildRuntimeCode2(runtimeDir) {
38487
39785
  ];
38488
39786
  let code = "";
38489
39787
  for (const f of runtimeFiles) {
38490
- const p = join10(runtimeDir, f);
38491
- if (existsSync19(p)) {
38492
- let src2 = readFileSync16(p, "utf-8");
39788
+ const p = join11(runtimeDir, f);
39789
+ if (existsSync20(p)) {
39790
+ let src2 = readFileSync18(p, "utf-8");
38493
39791
  src2 = stripTypes2(src2);
38494
39792
  src2 = src2.replace(/^import\s+[\s\S]*?from\s+['"](?:\.\/.*?|@vesk\/runtime\/src\/.*?)['"];?\n?/gm, "");
38495
39793
  src2 = src2.replace(/^import\s+['"](?:\.\/.*?|@vesk\/runtime\/src\/.*?)['"];?\n?/gm, "");
@@ -38501,7 +39799,7 @@ ${src2}
38501
39799
  `;
38502
39800
  }
38503
39801
  }
38504
- const indexSrc = readFileSync16(join10(runtimeDir, "index-client.js"), "utf-8");
39802
+ const indexSrc = readFileSync18(join11(runtimeDir, "index-client.js"), "utf-8");
38505
39803
  const exportNames = stripTypes2(indexSrc).match(/export\s*\{\s*([^}]+)\s*\}\s*from/g)?.flatMap((m) => m.replace(/export\s*\{\s*|\s*\}\s*from/g, "").split(",").map((s) => s.trim())) || [];
38506
39804
  code += "// --- exports ---\n";
38507
39805
  for (const name of [...new Set(exportNames)]) {
@@ -38512,7 +39810,7 @@ ${src2}
38512
39810
  return code;
38513
39811
  }
38514
39812
  function runtimeExportNames2(runtimeDir) {
38515
- const indexSrc = readFileSync16(join10(runtimeDir, "index-client.js"), "utf-8");
39813
+ const indexSrc = readFileSync18(join11(runtimeDir, "index-client.js"), "utf-8");
38516
39814
  const names = /* @__PURE__ */ new Set();
38517
39815
  for (const m of indexSrc.matchAll(/export\s*\{([^}]+)\}\s*from/g)) {
38518
39816
  for (const raw2 of m[1].split(",")) {
@@ -38532,7 +39830,7 @@ async function buildTreeShakenRuntime2(runtimeDir, usedNames) {
38532
39830
  console.error(`vesk: runtime names not exported \u2014 ${missing.join(", ")}; falling back to full runtime`);
38533
39831
  return buildRuntimeCode2(runtimeDir);
38534
39832
  }
38535
- const entry = join10(runtimeDir, `.runtime-tree-entry-${runtimeEntryId2++}.mjs`);
39833
+ const entry = join11(runtimeDir, `.runtime-tree-entry-${runtimeEntryId2++}.mjs`);
38536
39834
  try {
38537
39835
  writeFileSync9(entry, `export { ${unique.join(", ")} } from './index-client.js';
38538
39836
  `);
@@ -38658,15 +39956,38 @@ if (typeof document !== 'undefined') __router.start();
38658
39956
  }
38659
39957
 
38660
39958
  // ../adapter/dist/paths.js
38661
- import { resolve as resolve20, sep as sep4 } from "node:path";
39959
+ import { resolve as resolve21, sep as sep4 } from "node:path";
39960
+ import { existsSync as existsSync21, statSync as statSync14, readFileSync as readFileSync19 } from "node:fs";
38662
39961
  function resolveWithin2(baseDir, relPath) {
38663
- const base = resolve20(baseDir);
38664
- const target = resolve20(baseDir, relPath);
39962
+ const base = resolve21(baseDir);
39963
+ const target = resolve21(baseDir, relPath);
38665
39964
  const prefix = base + sep4;
38666
39965
  if (!target.startsWith(prefix))
38667
39966
  return null;
38668
39967
  return target;
38669
39968
  }
39969
+ function installMdReadHook2(publicDirs) {
39970
+ const dirs = publicDirs.map((d) => resolve21(d));
39971
+ globalThis.__vsk_md_read_file = (p) => {
39972
+ for (const dir of dirs) {
39973
+ try {
39974
+ let rel = String(p);
39975
+ while (rel.length > 0 && rel.charCodeAt(0) === 47)
39976
+ rel = rel.slice(1);
39977
+ const abs = resolveWithin2(dir, rel);
39978
+ if (!abs)
39979
+ continue;
39980
+ const lower = abs.toLowerCase();
39981
+ if (!lower.endsWith(".md") && !lower.endsWith(".markdown"))
39982
+ continue;
39983
+ if (existsSync21(abs) && statSync14(abs).isFile())
39984
+ return readFileSync19(abs, "utf8");
39985
+ } catch {
39986
+ }
39987
+ }
39988
+ return null;
39989
+ };
39990
+ }
38670
39991
  function isAllowedWsUpgrade(headers2) {
38671
39992
  const origin = typeof headers2["origin"] === "string" ? headers2["origin"] : "";
38672
39993
  if (!origin)
@@ -38728,13 +40049,13 @@ function urlAuthority3(url) {
38728
40049
 
38729
40050
  // src/build-packages.ts
38730
40051
  import { spawnSync } from "node:child_process";
38731
- import { cpSync, existsSync as existsSync20, mkdirSync as mkdirSync7, readFileSync as readFileSync17, readdirSync as readdirSync9, statSync as statSync12, writeFileSync as writeFileSync10 } from "node:fs";
38732
- import { createRequire as createRequire2 } from "node:module";
38733
- import { dirname as dirname13, join as join11, resolve as resolve21 } from "node:path";
40052
+ import { cpSync, existsSync as existsSync22, mkdirSync as mkdirSync7, readFileSync as readFileSync20, readdirSync as readdirSync9, statSync as statSync15, writeFileSync as writeFileSync10 } from "node:fs";
40053
+ import { createRequire as createRequire3 } from "node:module";
40054
+ import { dirname as dirname14, join as join12, resolve as resolve22 } from "node:path";
38734
40055
  import { fileURLToPath as fileURLToPath7 } from "node:url";
38735
- var require2 = createRequire2(import.meta.url);
38736
- var __dirname8 = dirname13(fileURLToPath7(import.meta.url));
38737
- var root2 = resolve21(__dirname8, "..", "..", "..");
40056
+ var require2 = createRequire3(import.meta.url);
40057
+ var __dirname8 = dirname14(fileURLToPath7(import.meta.url));
40058
+ var root2 = resolve22(__dirname8, "..", "..", "..");
38738
40059
  var PACKAGES = {
38739
40060
  // types first — it is a dependency-free leaf that compiler and adapter
38740
40061
  // import for their shared type definitions.
@@ -38750,8 +40071,8 @@ var PACKAGES = {
38750
40071
  function newestSourceMtime(srcDir) {
38751
40072
  let newest = 0;
38752
40073
  for (const name of readdirSync9(srcDir)) {
38753
- const p = join11(srcDir, name);
38754
- const st = statSync12(p);
40074
+ const p = join12(srcDir, name);
40075
+ const st = statSync15(p);
38755
40076
  if (st.isDirectory()) {
38756
40077
  newest = Math.max(newest, newestSourceMtime(p));
38757
40078
  } else if (st.isFile() && /\.ts$/.test(name) && !name.endsWith(".test.ts")) {
@@ -38761,11 +40082,11 @@ function newestSourceMtime(srcDir) {
38761
40082
  return newest;
38762
40083
  }
38763
40084
  function distStale(pkgDir, entry) {
38764
- const distIndex = join11(pkgDir, "dist", `${entry}.js`);
38765
- if (!existsSync20(distIndex)) return true;
38766
- const distPkg = join11(pkgDir, "dist", "package.json");
38767
- const distStamp = Math.max(statSync12(distIndex).mtimeMs, existsSync20(distPkg) ? statSync12(distPkg).mtimeMs : 0);
38768
- return newestSourceMtime(join11(pkgDir, "src")) > distStamp;
40085
+ const distIndex = join12(pkgDir, "dist", `${entry}.js`);
40086
+ if (!existsSync22(distIndex)) return true;
40087
+ const distPkg = join12(pkgDir, "dist", "package.json");
40088
+ const distStamp = Math.max(statSync15(distIndex).mtimeMs, existsSync22(distPkg) ? statSync15(distPkg).mtimeMs : 0);
40089
+ return newestSourceMtime(join12(pkgDir, "src")) > distStamp;
38769
40090
  }
38770
40091
  function distPackageJson(pkgName, entry, serverEntry, version2) {
38771
40092
  const exports = {
@@ -38788,38 +40109,38 @@ function distPackageJson(pkgName, entry, serverEntry, version2) {
38788
40109
  }
38789
40110
  function buildPackages(force = false) {
38790
40111
  for (const [pkg, cfg] of Object.entries(PACKAGES)) {
38791
- const pkgDir = resolve21(root2, "packages", pkg);
38792
- if (!existsSync20(join11(pkgDir, "src"))) continue;
40112
+ const pkgDir = resolve22(root2, "packages", pkg);
40113
+ if (!existsSync22(join12(pkgDir, "src"))) continue;
38793
40114
  if (!force && !distStale(pkgDir, cfg.entry)) continue;
38794
40115
  console.log(`[build] ${cfg.name} -> tsc`);
38795
40116
  const tscBin = require2.resolve("typescript/bin/tsc");
38796
- const result2 = spawnSync(process.execPath, [tscBin, "-p", join11(pkgDir, "tsconfig.build.json")], {
40117
+ const result2 = spawnSync(process.execPath, [tscBin, "-p", join12(pkgDir, "tsconfig.build.json")], {
38797
40118
  stdio: "inherit"
38798
40119
  });
38799
40120
  if (result2.status !== 0) {
38800
40121
  throw new Error(`tsc failed for ${cfg.name}`);
38801
40122
  }
38802
- const distDir = join11(pkgDir, "dist");
40123
+ const distDir = join12(pkgDir, "dist");
38803
40124
  for (const c of cfg.copy || []) {
38804
- const to = join11(distDir, c.to);
38805
- mkdirSync7(dirname13(to), { recursive: true });
38806
- cpSync(join11(pkgDir, c.from), to, { recursive: true });
40125
+ const to = join12(distDir, c.to);
40126
+ mkdirSync7(dirname14(to), { recursive: true });
40127
+ cpSync(join12(pkgDir, c.from), to, { recursive: true });
38807
40128
  }
38808
- const srcPkg = JSON.parse(readFileSync17(join11(pkgDir, "package.json"), "utf-8"));
38809
- writeFileSync10(join11(distDir, "package.json"), distPackageJson(cfg.name, cfg.entry, cfg.serverEntry, srcPkg.version || "1.0.0"));
40129
+ const srcPkg = JSON.parse(readFileSync20(join12(pkgDir, "package.json"), "utf-8"));
40130
+ writeFileSync10(join12(distDir, "package.json"), distPackageJson(cfg.name, cfg.entry, cfg.serverEntry, srcPkg.version || "1.0.0"));
38810
40131
  console.log(`[build] ${cfg.name} -> dist`);
38811
40132
  }
38812
40133
  }
38813
40134
  function ensurePackagesBuilt() {
38814
40135
  buildPackages(false);
38815
40136
  }
38816
- if (process.argv[1] && resolve21(process.argv[1]) === fileURLToPath7(import.meta.url)) {
40137
+ if (process.argv[1] && resolve22(process.argv[1]) === fileURLToPath7(import.meta.url)) {
38817
40138
  buildPackages(process.argv.includes("--force"));
38818
40139
  }
38819
40140
 
38820
40141
  // src/action-handler.ts
38821
- import { existsSync as existsSync21, readFileSync as readFileSync18, readdirSync as readdirSync10 } from "node:fs";
38822
- import { resolve as resolve22 } from "node:path";
40142
+ import { existsSync as existsSync23, readFileSync as readFileSync21, readdirSync as readdirSync10 } from "node:fs";
40143
+ import { resolve as resolve23 } from "node:path";
38823
40144
 
38824
40145
  // ../compiler/dist/server-cookies.js
38825
40146
  function parseCookies3(str) {
@@ -38896,8 +40217,8 @@ function pageSourcesFor(appDirPath, routeTree) {
38896
40217
  const out = [];
38897
40218
  function walk6(nodes) {
38898
40219
  for (const node of nodes) {
38899
- if (node.page) out.push(resolve22(appDirPath, node.sourceDir, "page.vsk"));
38900
- if (node.layout) out.push(resolve22(appDirPath, node.sourceDir, "layout.vsk"));
40220
+ if (node.page) out.push(resolve23(appDirPath, node.sourceDir, "page.vsk"));
40221
+ if (node.layout) out.push(resolve23(appDirPath, node.sourceDir, "layout.vsk"));
38901
40222
  walk6(node.children);
38902
40223
  }
38903
40224
  }
@@ -38905,7 +40226,7 @@ function pageSourcesFor(appDirPath, routeTree) {
38905
40226
  return out;
38906
40227
  }
38907
40228
  function walkVskFiles(dir, out, seen) {
38908
- if (!existsSync21(dir)) return;
40229
+ if (!existsSync23(dir)) return;
38909
40230
  let entries;
38910
40231
  try {
38911
40232
  entries = readdirSync10(dir, { withFileTypes: true });
@@ -38913,7 +40234,7 @@ function walkVskFiles(dir, out, seen) {
38913
40234
  return;
38914
40235
  }
38915
40236
  for (const entry of entries) {
38916
- const full = resolve22(dir, entry.name);
40237
+ const full = resolve23(dir, entry.name);
38917
40238
  if (seen.has(full)) continue;
38918
40239
  seen.add(full);
38919
40240
  if (entry.isDirectory()) {
@@ -38933,16 +40254,16 @@ function candidateSources(appDirPath, routeTree) {
38933
40254
  seen.add(src2);
38934
40255
  out.push(src2);
38935
40256
  }
38936
- const projectRoot = resolve22(appDirPath, "..");
38937
- for (const dir of [resolve22(projectRoot, "components"), appDirPath, projectRoot]) {
40257
+ const projectRoot = resolve23(appDirPath, "..");
40258
+ for (const dir of [resolve23(projectRoot, "components"), appDirPath, projectRoot]) {
38938
40259
  walkVskFiles(dir, out, seen);
38939
40260
  }
38940
40261
  return out;
38941
40262
  }
38942
40263
  function registerSource(sourcePath2) {
38943
- if (!existsSync21(sourcePath2)) return;
40264
+ if (!existsSync23(sourcePath2)) return;
38944
40265
  try {
38945
- compileFile(readFileSync18(sourcePath2, "utf-8"), { sourcePath: sourcePath2 });
40266
+ compileFile(readFileSync21(sourcePath2, "utf-8"), { sourcePath: sourcePath2 });
38946
40267
  } catch {
38947
40268
  }
38948
40269
  }
@@ -38951,8 +40272,8 @@ function ensureActionRegistered(actionId, pagePathname, appDirPath, routeTree) {
38951
40272
  const match = matchUrl(routeTree, pagePathname);
38952
40273
  if (match) {
38953
40274
  for (let i = match.nodes.length - 1; i >= 0; i--) {
38954
- registerSource(resolve22(appDirPath, match.nodes[i].sourceDir, "page.vsk"));
38955
- registerSource(resolve22(appDirPath, match.nodes[i].sourceDir, "layout.vsk"));
40275
+ registerSource(resolve23(appDirPath, match.nodes[i].sourceDir, "page.vsk"));
40276
+ registerSource(resolve23(appDirPath, match.nodes[i].sourceDir, "layout.vsk"));
38956
40277
  }
38957
40278
  }
38958
40279
  if (getAction2(actionId)) return;
@@ -38978,24 +40299,24 @@ async function renderPageHtml(pagePathname, params, ctx2) {
38978
40299
  let head = "";
38979
40300
  for (let i = chain.length - 1; i >= 0; i--) {
38980
40301
  const node = chain[i];
38981
- const pageFilePath = resolve22(ctx2.appDirPath, node.sourceDir, "page.vsk");
38982
- const layoutFilePath = resolve22(ctx2.appDirPath, node.sourceDir, "layout.vsk");
38983
- if (i === chain.length - 1 && node.page && existsSync21(pageFilePath)) {
38984
- const src3 = readFileSync18(pageFilePath, "utf-8");
40302
+ const pageFilePath = resolve23(ctx2.appDirPath, node.sourceDir, "page.vsk");
40303
+ const layoutFilePath = resolve23(ctx2.appDirPath, node.sourceDir, "layout.vsk");
40304
+ if (i === chain.length - 1 && node.page && existsSync23(pageFilePath)) {
40305
+ const src3 = readFileSync21(pageFilePath, "utf-8");
38985
40306
  const compName2 = resolveComponentName(src3) || node.page;
38986
40307
  const result2 = await renderPage(src3, compName2, { params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath });
38987
40308
  body = result2.body;
38988
40309
  head = result2.head || "";
38989
40310
  }
38990
- if (node.layout && existsSync21(layoutFilePath)) {
38991
- const src3 = readFileSync18(layoutFilePath, "utf-8");
40311
+ if (node.layout && existsSync23(layoutFilePath)) {
40312
+ const src3 = readFileSync21(layoutFilePath, "utf-8");
38992
40313
  const compName2 = resolveComponentName(src3) || node.layout;
38993
40314
  const result2 = await renderPage(src3, compName2, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath });
38994
40315
  body = result2.body;
38995
40316
  head = (result2.head || "") + head;
38996
40317
  }
38997
40318
  }
38998
- const hasLayout = chain.some((n) => n.layout && existsSync21(resolve22(ctx2.appDirPath, n.sourceDir, "layout.vsk")));
40319
+ const hasLayout = chain.some((n) => n.layout && existsSync23(resolve23(ctx2.appDirPath, n.sourceDir, "layout.vsk")));
38999
40320
  if (hasLayout) {
39000
40321
  const secMeta = securityMeta(ctx2.security);
39001
40322
  return `<!DOCTYPE html>
@@ -39017,9 +40338,9 @@ ${prettifyHtml(body)}
39017
40338
  }
39018
40339
  const leaf = chain.find((n) => n.page);
39019
40340
  if (!leaf) return null;
39020
- const src2 = readFileSync18(resolve22(ctx2.appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
40341
+ const src2 = readFileSync21(resolve23(ctx2.appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
39021
40342
  const compName = resolveComponentName(src2) || leaf.page;
39022
- const html = await renderFullPage(src2, compName, { params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security: ctx2.security, sourcePath: resolve22(ctx2.appDirPath, leaf.sourceDir, "page.vsk") });
40343
+ const html = await renderFullPage(src2, compName, { params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security: ctx2.security, sourcePath: resolve23(ctx2.appDirPath, leaf.sourceDir, "page.vsk") });
39023
40344
  return html.replace("</body>", ' <script type="module" src="/_vesk/hmr.js"></script>\n</body>');
39024
40345
  }
39025
40346
  async function handleActionRequest(req, res, ctx2) {
@@ -39163,14 +40484,14 @@ async function handleActionRequest(req, res, ctx2) {
39163
40484
  function resolveRuntimeDir(projectDir2) {
39164
40485
  const candidates = [
39165
40486
  // installed app layout
39166
- resolve23(projectDir2, "node_modules", "@vesk", "runtime"),
40487
+ resolve24(projectDir2, "node_modules", "@vesk", "runtime"),
39167
40488
  // monorepo checkout (tests/probes run from the repo root)
39168
- resolve23(import.meta.dirname ?? ".", "..", "..", "runtime", "dist")
40489
+ resolve24(import.meta.dirname ?? ".", "..", "..", "runtime", "dist")
39169
40490
  ];
39170
40491
  for (const dir of candidates) {
39171
- if (existsSync22(join12(dir, "ripple-runtime.js"))) return dir;
39172
- const distDir = join12(dir, "dist");
39173
- if (existsSync22(join12(distDir, "ripple-runtime.js"))) return distDir;
40492
+ if (existsSync24(join13(dir, "ripple-runtime.js"))) return dir;
40493
+ const distDir = join13(dir, "dist");
40494
+ if (existsSync24(join13(distDir, "ripple-runtime.js"))) return distDir;
39174
40495
  }
39175
40496
  return null;
39176
40497
  }
@@ -39240,10 +40561,10 @@ function collectRoutePaths(nodes, out = []) {
39240
40561
  return out;
39241
40562
  }
39242
40563
  function countFilesNamed(dir, name) {
39243
- if (!existsSync22(dir)) return 0;
40564
+ if (!existsSync24(dir)) return 0;
39244
40565
  let n = 0;
39245
40566
  for (const entry of readdirSync11(dir, { withFileTypes: true })) {
39246
- const p = join12(dir, entry.name);
40567
+ const p = join13(dir, entry.name);
39247
40568
  if (entry.isDirectory()) n += countFilesNamed(p, name);
39248
40569
  else if (entry.name === name) n++;
39249
40570
  }
@@ -39254,8 +40575,9 @@ async function startDevServer(port2, projectDir2, config, host2) {
39254
40575
  if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";
39255
40576
  const secCfg = config.security || {};
39256
40577
  const maxBodyBytes2 = (typeof secCfg.maxBodyBytes === "number" ? secCfg.maxBodyBytes : void 0) || DEFAULT_MAX_BODY_BYTES;
39257
- const appDirPath = join12(projectDir2, "app");
39258
- const publicDir = join12(projectDir2, "public");
40578
+ const appDirPath = join13(projectDir2, "app");
40579
+ const publicDir = join13(projectDir2, "public");
40580
+ installMdReadHook2([publicDir]);
39259
40581
  try {
39260
40582
  ensurePackagesBuilt();
39261
40583
  } catch (e) {
@@ -39272,14 +40594,14 @@ async function startDevServer(port2, projectDir2, config, host2) {
39272
40594
  let devTailwindCssContent = "";
39273
40595
  let lastServedCssGlobal = "";
39274
40596
  let lastServedCssTailwind = "";
39275
- const srcDir = join12(projectDir2, "src");
39276
- const cssPath = join12(srcDir, "global.css");
39277
- const altCssPath = join12(srcDir, "app.css");
40597
+ const srcDir = join13(projectDir2, "src");
40598
+ const cssPath = join13(srcDir, "global.css");
40599
+ const altCssPath = join13(srcDir, "app.css");
39278
40600
  let rawCss = "";
39279
- if (existsSync22(cssPath)) {
39280
- rawCss = readFileSync19(cssPath, "utf-8");
39281
- } else if (existsSync22(altCssPath)) {
39282
- rawCss = readFileSync19(altCssPath, "utf-8");
40601
+ if (existsSync24(cssPath)) {
40602
+ rawCss = readFileSync22(cssPath, "utf-8");
40603
+ } else if (existsSync24(altCssPath)) {
40604
+ rawCss = readFileSync22(altCssPath, "utf-8");
39283
40605
  }
39284
40606
  if (rawCss) {
39285
40607
  for (const plugin of devPlugins) {
@@ -39405,7 +40727,7 @@ async function startDevServer(port2, projectDir2, config, host2) {
39405
40727
  let debounceTimer = null;
39406
40728
  let cssDebounceTimer = null;
39407
40729
  const watchDirs = [appDirPath];
39408
- if (existsSync22(srcDir)) watchDirs.push(srcDir);
40730
+ if (existsSync24(srcDir)) watchDirs.push(srcDir);
39409
40731
  for (const watchDir of watchDirs) {
39410
40732
  watch(watchDir, { recursive: true }, (eventType, filename) => {
39411
40733
  if (!filename) return;
@@ -39413,8 +40735,8 @@ async function startDevServer(port2, projectDir2, config, host2) {
39413
40735
  const isCss = filename.endsWith(".css");
39414
40736
  const isApiRoute = filename.endsWith(".ts") || filename.endsWith(".js") || filename.endsWith(".tsx");
39415
40737
  if (!isVsk && !isCss && !isApiRoute) return;
39416
- const fullPath = filename.startsWith("/") ? filename : join12(watchDir, filename);
39417
- const fileExists = existsSync22(fullPath);
40738
+ const fullPath = filename.startsWith("/") ? filename : join13(watchDir, filename);
40739
+ const fileExists = existsSync24(fullPath);
39418
40740
  if (isVsk) {
39419
40741
  if (debounceTimer) clearTimeout(debounceTimer);
39420
40742
  debounceTimer = setTimeout(async () => {
@@ -39463,7 +40785,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39463
40785
  if (compCode.trim()) fnSources = { _raw: compCode };
39464
40786
  } else if (fileExists && !bundleError) {
39465
40787
  try {
39466
- const src2 = readFileSync19(fullPath, "utf-8");
40788
+ const src2 = readFileSync22(fullPath, "utf-8");
39467
40789
  let compCode = compileClient2(src2, null, { forceClient: true, sourcePath: fullPath, mdRoots: [projectDir2] });
39468
40790
  compCode = compCode.replace(/^import\s*[\s\S]*?from\s*['"][^'"]+['"];?\s*\n?/gm, "");
39469
40791
  compCode = compCode.replace(/^const __components = \{\};\s*\n?/m, "");
@@ -39519,7 +40841,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39519
40841
  let code = "";
39520
40842
  if (line > 0 && fileExists) {
39521
40843
  try {
39522
- const src2 = readFileSync19(fullPath, "utf-8");
40844
+ const src2 = readFileSync22(fullPath, "utf-8");
39523
40845
  const lines = src2.split("\n");
39524
40846
  const start = Math.max(0, line - 3);
39525
40847
  const end = Math.min(lines.length, line + 2);
@@ -39570,7 +40892,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39570
40892
  cssDebounceTimer = setTimeout(async () => {
39571
40893
  try {
39572
40894
  if (fileExists) {
39573
- rawCss = readFileSync19(fullPath, "utf-8");
40895
+ rawCss = readFileSync22(fullPath, "utf-8");
39574
40896
  }
39575
40897
  const cssChanged = await rebuildTailwindCss();
39576
40898
  if (cssChanged && typeof globalThis.__vesk_broadcastHmr === "function") {
@@ -39602,9 +40924,9 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39602
40924
  ".html": "text/html",
39603
40925
  ".json": "application/json"
39604
40926
  };
39605
- const hmrJsPath = join12(runtimeDir, "hmr-client.js");
39606
- const hmrTsPath = join12(runtimeDir, "hmr-client.ts");
39607
- const hmrClientPath = existsSync22(hmrJsPath) ? hmrJsPath : existsSync22(hmrTsPath) ? hmrTsPath : null;
40927
+ const hmrJsPath = join13(runtimeDir, "hmr-client.js");
40928
+ const hmrTsPath = join13(runtimeDir, "hmr-client.ts");
40929
+ const hmrClientPath = existsSync24(hmrJsPath) ? hmrJsPath : existsSync24(hmrTsPath) ? hmrTsPath : null;
39608
40930
  function extractCompName2(src2) {
39609
40931
  return resolveComponentName(src2);
39610
40932
  }
@@ -39705,7 +41027,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39705
41027
  }
39706
41028
  if (url.pathname === "/_vesk/hmr" || url.pathname === "/_vesk/hmr.js") {
39707
41029
  if (hmrClientPath) {
39708
- let hmrContent = readFileSync19(hmrClientPath, "utf-8");
41030
+ let hmrContent = readFileSync22(hmrClientPath, "utf-8");
39709
41031
  if (hmrClientPath.endsWith(".ts")) {
39710
41032
  hmrContent = stripCodeTypes2(hmrContent);
39711
41033
  }
@@ -39719,16 +41041,16 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39719
41041
  }
39720
41042
  if (url.pathname !== "/") {
39721
41043
  const staticPath = url.pathname.length > 1 ? resolveWithin2(publicDir, url.pathname.slice(1)) : null;
39722
- if (staticPath && existsSync22(staticPath) && statSync13(staticPath).isFile()) {
39723
- const ext = extname5(staticPath);
41044
+ if (staticPath && existsSync24(staticPath) && statSync16(staticPath).isFile()) {
41045
+ const ext = extname6(staticPath);
39724
41046
  res.writeHead(200, { "Content-Type": MIME3[ext] || "application/octet-stream" });
39725
- res.end(readFileSync19(staticPath));
41047
+ res.end(readFileSync22(staticPath));
39726
41048
  return;
39727
41049
  }
39728
41050
  }
39729
41051
  const mwChain = collectMiddlewareChain(routeTree, url.pathname, appDirPath);
39730
- const apiDirPath = join12(appDirPath, "api");
39731
- if (url.pathname.startsWith("/api") && existsSync22(apiDirPath)) {
41052
+ const apiDirPath = join13(appDirPath, "api");
41053
+ if (url.pathname.startsWith("/api") && existsSync24(apiDirPath)) {
39732
41054
  const apiRoutes = await scanApiRoutes(apiDirPath);
39733
41055
  const apiMatch = matchApiUrl(apiRoutes, req.url || url.pathname);
39734
41056
  if (apiMatch) {
@@ -39803,10 +41125,10 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39803
41125
  const rootNode = routeTree.find((n) => n.fullPath === "/");
39804
41126
  let notFoundHtml = null;
39805
41127
  if (rootNode && rootNode.notFound) {
39806
- const nfPath = resolve23(appDirPath, rootNode.sourceDir, "not-found.vsk");
39807
- if (existsSync22(nfPath)) {
41128
+ const nfPath = resolve24(appDirPath, rootNode.sourceDir, "not-found.vsk");
41129
+ if (existsSync24(nfPath)) {
39808
41130
  try {
39809
- const nfSrc = readFileSync19(nfPath, "utf-8");
41131
+ const nfSrc = readFileSync22(nfPath, "utf-8");
39810
41132
  const nfCompName = extractCompName2(nfSrc) || rootNode.notFound;
39811
41133
  notFoundHtml = await renderFullPage(nfSrc, nfCompName, { params: {}, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: nfPath });
39812
41134
  } catch {
@@ -39843,18 +41165,18 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39843
41165
  let props;
39844
41166
  for (let i = chain.length - 1; i >= 0; i--) {
39845
41167
  const node = chain[i];
39846
- const pageFilePath = resolve23(appDirPath, node.sourceDir, "page.vsk");
39847
- const layoutFilePath = resolve23(appDirPath, node.sourceDir, "layout.vsk");
39848
- if (i === chain.length - 1 && node.page && existsSync22(pageFilePath)) {
39849
- const src2 = readFileSync19(pageFilePath, "utf-8");
41168
+ const pageFilePath = resolve24(appDirPath, node.sourceDir, "page.vsk");
41169
+ const layoutFilePath = resolve24(appDirPath, node.sourceDir, "layout.vsk");
41170
+ if (i === chain.length - 1 && node.page && existsSync24(pageFilePath)) {
41171
+ const src2 = readFileSync22(pageFilePath, "utf-8");
39850
41172
  const compName = extractCompName2(src2) || node.page;
39851
41173
  const result2 = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath });
39852
41174
  body = result2.body;
39853
41175
  head = result2.head || "";
39854
41176
  props = result2.props;
39855
41177
  }
39856
- if (node.layout && existsSync22(layoutFilePath)) {
39857
- const src2 = readFileSync19(layoutFilePath, "utf-8");
41178
+ if (node.layout && existsSync24(layoutFilePath)) {
41179
+ const src2 = readFileSync22(layoutFilePath, "utf-8");
39858
41180
  const compName = extractCompName2(src2) || node.layout;
39859
41181
  const result2 = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath });
39860
41182
  body = result2.body;
@@ -39864,7 +41186,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
39864
41186
  if (forData) {
39865
41187
  return { html: "", props: props || { params: matched.params }, head };
39866
41188
  }
39867
- const hasLayout = chain.some((n) => n.layout && existsSync22(resolve23(appDirPath, n.sourceDir, "layout.vsk")));
41189
+ const hasLayout = chain.some((n) => n.layout && existsSync24(resolve24(appDirPath, n.sourceDir, "layout.vsk")));
39868
41190
  let html;
39869
41191
  if (hasLayout) {
39870
41192
  const ssrData = ssrSink3.snapshot();
@@ -39896,9 +41218,9 @@ ${prettifyHtml(body)}
39896
41218
  } else {
39897
41219
  const leaf = chain.find((n) => n.page);
39898
41220
  if (leaf) {
39899
- const src2 = readFileSync19(resolve23(appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
41221
+ const src2 = readFileSync22(resolve24(appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
39900
41222
  const compName = extractCompName2(src2) || leaf.page;
39901
- html = await renderFullPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: resolve23(appDirPath, leaf.sourceDir, "page.vsk") });
41223
+ html = await renderFullPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: resolve24(appDirPath, leaf.sourceDir, "page.vsk") });
39902
41224
  html = html.replace("</body>", ' <script type="module" src="/_vesk/hmr.js"></script>\n</body>');
39903
41225
  } else {
39904
41226
  throw new Error("No page or layout matched");
@@ -39910,13 +41232,13 @@ ${prettifyHtml(body)}
39910
41232
  function renderSSRStream() {
39911
41233
  async function* raw2() {
39912
41234
  const chain = cleanChain;
39913
- const hasLayout = chain.some((n) => n.layout && existsSync22(resolve23(appDirPath, n.sourceDir, "layout.vsk")));
41235
+ const hasLayout = chain.some((n) => n.layout && existsSync24(resolve24(appDirPath, n.sourceDir, "layout.vsk")));
39914
41236
  if (!hasLayout) {
39915
41237
  const leaf = chain.find((n) => n.page);
39916
41238
  if (leaf) {
39917
- const src2 = readFileSync19(resolve23(appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
41239
+ const src2 = readFileSync22(resolve24(appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
39918
41240
  const compName = extractCompName2(src2) || leaf.page;
39919
- yield* renderPageStream(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: resolve23(appDirPath, leaf.sourceDir, "page.vsk") });
41241
+ yield* renderPageStream(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: resolve24(appDirPath, leaf.sourceDir, "page.vsk") });
39920
41242
  } else {
39921
41243
  throw new Error("No page or layout matched");
39922
41244
  }
@@ -39927,18 +41249,18 @@ ${prettifyHtml(body)}
39927
41249
  let props;
39928
41250
  for (let i = chain.length - 1; i >= 0; i--) {
39929
41251
  const node = chain[i];
39930
- const pageFilePath = resolve23(appDirPath, node.sourceDir, "page.vsk");
39931
- const layoutFilePath = resolve23(appDirPath, node.sourceDir, "layout.vsk");
39932
- if (i === chain.length - 1 && node.page && existsSync22(pageFilePath)) {
39933
- const src2 = readFileSync19(pageFilePath, "utf-8");
41252
+ const pageFilePath = resolve24(appDirPath, node.sourceDir, "page.vsk");
41253
+ const layoutFilePath = resolve24(appDirPath, node.sourceDir, "layout.vsk");
41254
+ if (i === chain.length - 1 && node.page && existsSync24(pageFilePath)) {
41255
+ const src2 = readFileSync22(pageFilePath, "utf-8");
39934
41256
  const compName = extractCompName2(src2) || node.page;
39935
41257
  const result2 = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath });
39936
41258
  body = result2.body;
39937
41259
  head = result2.head || "";
39938
41260
  props = result2.props;
39939
41261
  }
39940
- if (node.layout && existsSync22(layoutFilePath)) {
39941
- const src2 = readFileSync19(layoutFilePath, "utf-8");
41262
+ if (node.layout && existsSync24(layoutFilePath)) {
41263
+ const src2 = readFileSync22(layoutFilePath, "utf-8");
39942
41264
  const compName = extractCompName2(src2) || node.layout;
39943
41265
  const result2 = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath });
39944
41266
  body = result2.body;
@@ -40065,10 +41387,10 @@ ${prettifyHtml(body)}
40065
41387
  for (let i = match.nodes.length - 1; i >= 0; i--) {
40066
41388
  const node = match.nodes[i];
40067
41389
  if (node.notFound) {
40068
- const nfPath = resolve23(appDirPath, node.sourceDir, "not-found.vsk");
40069
- if (existsSync22(nfPath)) {
41390
+ const nfPath = resolve24(appDirPath, node.sourceDir, "not-found.vsk");
41391
+ if (existsSync24(nfPath)) {
40070
41392
  try {
40071
- const nfSrc = readFileSync19(nfPath, "utf-8");
41393
+ const nfSrc = readFileSync22(nfPath, "utf-8");
40072
41394
  const nfCompName = extractCompName2(nfSrc) || node.notFound;
40073
41395
  const html = await renderFullPage(nfSrc, nfCompName, { params: match.params, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: nfPath });
40074
41396
  notFoundHtml = html.replace(
@@ -40093,10 +41415,10 @@ ${prettifyHtml(body)}
40093
41415
  for (let i = match.nodes.length - 1; i >= 0; i--) {
40094
41416
  const node = match.nodes[i];
40095
41417
  if (node.error) {
40096
- const errPath = resolve23(appDirPath, node.sourceDir, "error.vsk");
40097
- if (existsSync22(errPath)) {
41418
+ const errPath = resolve24(appDirPath, node.sourceDir, "error.vsk");
41419
+ if (existsSync24(errPath)) {
40098
41420
  try {
40099
- const errSrc = readFileSync19(errPath, "utf-8");
41421
+ const errSrc = readFileSync22(errPath, "utf-8");
40100
41422
  const errCompName = extractCompName2(errSrc) || node.error;
40101
41423
  const errProps = { error: err.message, stack: err.stack, statusCode: errorStatusCode(err), url: url.pathname };
40102
41424
  const html = await renderFullPage(errSrc, errCompName, errProps, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"], security, externalDataScript: storeDataScript, sourcePath: errPath });
@@ -40130,7 +41452,7 @@ ${err.stack}</pre></body></html>`);
40130
41452
  LOG.ok(`dev server at http://localhost:${port2} (listening on ${bindHost})`);
40131
41453
  const routes = collectRoutePaths(routeTree);
40132
41454
  const pageCount = countPages(routeTree);
40133
- const apiCount = countFilesNamed(join12(appDirPath, "api"), "route.ts");
41455
+ const apiCount = countFilesNamed(join13(appDirPath, "api"), "route.ts");
40134
41456
  LOG.info(`${projectDir2}`);
40135
41457
  LOG.info(`${pageCount} page${pageCount === 1 ? "" : "s"}: ${routes.join(", ") || "(none)"}`);
40136
41458
  if (apiCount > 0) LOG.info(`${apiCount} api route${apiCount === 1 ? "" : "s"} (app/api)`);
@@ -40359,7 +41681,7 @@ init_action();
40359
41681
 
40360
41682
  // src/index.ts
40361
41683
  var __filename2 = fileURLToPath8(import.meta.url);
40362
- var __dirname9 = resolve25(__filename2, "..");
41684
+ var __dirname9 = resolve26(__filename2, "..");
40363
41685
  var args = process.argv.slice(2);
40364
41686
  var cmd = args[0];
40365
41687
  function usage(code = 0) {
@@ -40402,12 +41724,12 @@ if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
40402
41724
  }
40403
41725
  function loadEnvFiles(projectDir2) {
40404
41726
  const files = [
40405
- join14(projectDir2, ".env"),
40406
- join14(projectDir2, ".env.local")
41727
+ join15(projectDir2, ".env"),
41728
+ join15(projectDir2, ".env.local")
40407
41729
  ];
40408
41730
  for (const filePath of files) {
40409
- if (!existsSync23(filePath)) continue;
40410
- const content = readFileSync21(filePath, "utf-8");
41731
+ if (!existsSync25(filePath)) continue;
41732
+ const content = readFileSync24(filePath, "utf-8");
40411
41733
  for (const line of content.split("\n")) {
40412
41734
  const trimmed = line.trim();
40413
41735
  if (!trimmed || trimmed.startsWith("#")) continue;
@@ -40426,22 +41748,22 @@ function loadEnvFiles(projectDir2) {
40426
41748
  }
40427
41749
  async function loadConfig(projectDir2) {
40428
41750
  loadEnvFiles(projectDir2);
40429
- const jsPath = join14(projectDir2, "vesk.config.js");
40430
- const tsPath = join14(projectDir2, "vesk.config.ts");
41751
+ const jsPath = join15(projectDir2, "vesk.config.js");
41752
+ const tsPath = join15(projectDir2, "vesk.config.ts");
40431
41753
  let configPath2 = null;
40432
- if (existsSync23(jsPath)) configPath2 = jsPath;
40433
- else if (existsSync23(tsPath)) configPath2 = tsPath;
41754
+ if (existsSync25(jsPath)) configPath2 = jsPath;
41755
+ else if (existsSync25(tsPath)) configPath2 = tsPath;
40434
41756
  if (!configPath2) return {};
40435
41757
  let raw2;
40436
41758
  if (configPath2.endsWith(".ts")) {
40437
41759
  const { transpile: transpile2 } = await import("typescript");
40438
- const src2 = readFileSync21(configPath2, "utf-8");
41760
+ const src2 = readFileSync24(configPath2, "utf-8");
40439
41761
  let js = transpile2(src2, { module: 99, target: 99 });
40440
41762
  js = js.replace(/import\s+\{[^}]*\}\s*from\s+['"]@vesk\/compiler['"]\s*;?\s*/g, "");
40441
41763
  js = `const { defineConfig, definePlugin, preset } = globalThis.__vesk_inject;
40442
41764
  ` + js;
40443
- const tmpFile = join14(projectDir2, ".vesk", "config.tmp.js");
40444
- mkdirSync9(dirname15(tmpFile), { recursive: true });
41765
+ const tmpFile = join15(projectDir2, ".vesk", "config.tmp.js");
41766
+ mkdirSync9(dirname16(tmpFile), { recursive: true });
40445
41767
  writeFileSync11(tmpFile, js, "utf-8");
40446
41768
  globalThis.__vesk_inject = { defineConfig, definePlugin, preset };
40447
41769
  raw2 = (await import(tmpFile)).default;
@@ -40462,9 +41784,9 @@ async function loadConfig(projectDir2) {
40462
41784
  }
40463
41785
  if (cmd === "build") {
40464
41786
  const projectDir2 = process.cwd();
40465
- const appDirPath = join14(projectDir2, "app");
40466
- const publicDir = join14(projectDir2, "public");
40467
- if (!existsSync23(appDirPath)) {
41787
+ const appDirPath = join15(projectDir2, "app");
41788
+ const publicDir = join15(projectDir2, "public");
41789
+ if (!existsSync25(appDirPath)) {
40468
41790
  console.error(`vesk build: no app/ directory found in ${projectDir2}`);
40469
41791
  process.exit(1);
40470
41792
  }
@@ -40502,8 +41824,8 @@ if (cmd === "build") {
40502
41824
  }
40503
41825
  if (cmd === "seo") {
40504
41826
  const projectDir2 = process.cwd();
40505
- const appDirPath = join14(projectDir2, "app");
40506
- if (!existsSync23(appDirPath)) {
41827
+ const appDirPath = join15(projectDir2, "app");
41828
+ if (!existsSync25(appDirPath)) {
40507
41829
  console.error(`vesk seo: no app/ directory found in ${projectDir2}`);
40508
41830
  process.exit(1);
40509
41831
  }
@@ -40517,8 +41839,8 @@ if (cmd === "seo") {
40517
41839
  }
40518
41840
  if (cmd === "typecheck") {
40519
41841
  const projectDir2 = process.cwd();
40520
- const appDirPath = join14(projectDir2, "app");
40521
- if (!existsSync23(appDirPath)) {
41842
+ const appDirPath = join15(projectDir2, "app");
41843
+ if (!existsSync25(appDirPath)) {
40522
41844
  console.error(`vesk typecheck: no app/ directory found in ${projectDir2}`);
40523
41845
  process.exit(1);
40524
41846
  }
@@ -40542,7 +41864,7 @@ if (cmd === "typecheck") {
40542
41864
  }
40543
41865
  if (cmd === "start") {
40544
41866
  const projectDir2 = process.cwd();
40545
- const outDir2 = join14(projectDir2, ".vesk");
41867
+ const outDir2 = join15(projectDir2, ".vesk");
40546
41868
  const port2 = parsePortArg(args);
40547
41869
  const host2 = parseHostArg(args);
40548
41870
  startProdServer(outDir2, { port: port2, host: host2 });
@@ -40551,9 +41873,9 @@ if (cmd === "start") {
40551
41873
  }
40552
41874
  if (cmd === "init") {
40553
41875
  const projectDir2 = process.cwd();
40554
- const srcDir = join14(projectDir2, "src");
40555
- const target = join14(srcDir, "global.css");
40556
- if (existsSync23(target)) {
41876
+ const srcDir = join15(projectDir2, "src");
41877
+ const target = join15(srcDir, "global.css");
41878
+ if (existsSync25(target)) {
40557
41879
  console.error(`vesk init: ${target} already exists \u2014 skipping`);
40558
41880
  process.exit(0);
40559
41881
  }
@@ -40571,10 +41893,10 @@ if (cmd === "init") {
40571
41893
  }
40572
41894
  if (cmd === "dev") {
40573
41895
  const projectDir2 = process.cwd();
40574
- const appDirPath = join14(projectDir2, "app");
41896
+ const appDirPath = join15(projectDir2, "app");
40575
41897
  const port2 = parsePortArg(args);
40576
41898
  const host2 = parseHostArg(args);
40577
- if (!existsSync23(appDirPath)) {
41899
+ if (!existsSync25(appDirPath)) {
40578
41900
  console.error(`vesk: no app/ directory found in ${projectDir2}`);
40579
41901
  console.error('Run "npx create-vesk@latest <project-name>" first');
40580
41902
  process.exit(1);