@vesk/vesk-cli 0.2.29 → 0.2.31

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 +63 -10
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -1619,6 +1619,17 @@ function getInflight() {
1619
1619
  g().__vsk_fetch_inflight = map;
1620
1620
  return map;
1621
1621
  }
1622
+ function getServerFailureCache() {
1623
+ const value = g().__vsk_ssr_failure_cache;
1624
+ if (value) return value;
1625
+ const map = /* @__PURE__ */ new Map();
1626
+ g().__vsk_ssr_failure_cache = map;
1627
+ return map;
1628
+ }
1629
+ function clearFailureCache(key) {
1630
+ if (!isServer()) return;
1631
+ g().__vsk_ssr_failure_cache?.delete(key);
1632
+ }
1622
1633
  function getRegistry() {
1623
1634
  const value = g().__vsk_fetch_registry;
1624
1635
  if (value) return value;
@@ -1887,6 +1898,20 @@ function startRequest(handle2, skipCache) {
1887
1898
  const key = handle2.key;
1888
1899
  const options = handle2.options;
1889
1900
  if (isServer()) {
1901
+ const failureTtl = options.failureTtl ?? DEFAULT_FAILURE_TTL;
1902
+ if (!skipCache && failureTtl > 0) {
1903
+ const failed = getServerFailureCache().get(key);
1904
+ if (failed && failed.ttl > 0 && Date.now() - failed.failedAt < failed.ttl) {
1905
+ getSsrFailures()?.set(key, failed.error);
1906
+ settleError(handle2, failed.error);
1907
+ const settled = handle2.settled.then(() => {
1908
+ throw failed.error;
1909
+ });
1910
+ settled.catch(() => {
1911
+ });
1912
+ return settled;
1913
+ }
1914
+ }
1890
1915
  const recorded = !skipCache ? getSsrFailures()?.get(key) : void 0;
1891
1916
  if (recorded !== void 0) {
1892
1917
  settleError(handle2, recorded);
@@ -1905,10 +1930,14 @@ function startRequest(handle2, skipCache) {
1905
1930
  prom2.then(
1906
1931
  (data2) => {
1907
1932
  setSsrData(key, data2, startToken);
1933
+ clearFailureCache(key);
1908
1934
  settle(handle2, data2);
1909
1935
  },
1910
1936
  (error) => {
1911
1937
  getSsrFailures()?.set(key, error);
1938
+ if (isServer() && !isAbortError(error) && failureTtl > 0) {
1939
+ getServerFailureCache().set(key, { error, failedAt: Date.now(), ttl: failureTtl });
1940
+ }
1912
1941
  settleError(handle2, error);
1913
1942
  }
1914
1943
  ).finally(() => {
@@ -2056,7 +2085,10 @@ function createResource(fn, key, into, options = {}) {
2056
2085
  }
2057
2086
  const ssrData = getSsrData(resourceKey);
2058
2087
  if (ssrData !== void 0) {
2059
- if (isServer()) setSsrData(resourceKey, ssrData);
2088
+ if (isServer()) {
2089
+ setSsrData(resourceKey, ssrData);
2090
+ clearFailureCache(resourceKey);
2091
+ }
2060
2092
  settle(handle2, ssrData);
2061
2093
  writeCache(resourceKey, ssrData);
2062
2094
  return accessor;
@@ -2081,7 +2113,7 @@ async function resolveSsrResources() {
2081
2113
  delete g().__vsk_ssr_failures;
2082
2114
  return data2;
2083
2115
  }
2084
- var HttpError, TimeoutError, g, isServer, ssrSink;
2116
+ var HttpError, TimeoutError, g, isServer, ssrSink, DEFAULT_FAILURE_TTL;
2085
2117
  var init_resource = __esm({
2086
2118
  "../runtime/src/resource.ts"() {
2087
2119
  "use strict";
@@ -2106,6 +2138,7 @@ var init_resource = __esm({
2106
2138
  g = () => globalThis;
2107
2139
  isServer = () => !!g().__vsk_ssr;
2108
2140
  ssrSink = null;
2141
+ DEFAULT_FAILURE_TTL = 1e4;
2109
2142
  useFetch.text = (url, options) => useFetch(() => doFetch(resolveFetchUrl(url), buildRequestInit(options ?? {})).then((r) => r.text()), {
2110
2143
  ...options,
2111
2144
  key: options?.key ?? url
@@ -52411,6 +52444,24 @@ function countFilesNamed(dir, name) {
52411
52444
  }
52412
52445
  return n;
52413
52446
  }
52447
+ function cachedSsrCompile(cache2, src2, filePath) {
52448
+ const compileHydrate = (source) => {
52449
+ resetVskState(true);
52450
+ return compileFile(source, { sourcePath: filePath });
52451
+ };
52452
+ const st = statSync21(filePath, { throwIfNoEntry: false });
52453
+ if (st) {
52454
+ const cur = cache2.get(filePath);
52455
+ if (cur && cur.mtimeMs === st.mtimeMs && cur.size === st.size) return cur.result;
52456
+ const result = compileHydrate(src2);
52457
+ cache2.set(filePath, { mtimeMs: st.mtimeMs, size: st.size, result });
52458
+ return result;
52459
+ }
52460
+ return compileHydrate(src2);
52461
+ }
52462
+ function invalidateSsrCompile(cache2, filePath) {
52463
+ cache2.delete(filePath);
52464
+ }
52414
52465
  async function startDevServer(port, projectDir, config, host) {
52415
52466
  const bindHost = host || "127.0.0.1";
52416
52467
  if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";
@@ -52562,6 +52613,7 @@ async function startDevServer(port, projectDir, config, host) {
52562
52613
  let runtimeBundle = "";
52563
52614
  let devBundleBytes = 0;
52564
52615
  const bundleCache = { files: /* @__PURE__ */ new Map() };
52616
+ const ssrCompileCache = /* @__PURE__ */ new Map();
52565
52617
  function runtimeImportNamesFrom(clientJs) {
52566
52618
  const m = clientJs.match(/^import\s*\{([^}]*)\}\s*from\s*['"]\/_vesk\/runtime\.js['"];?\s*$/m);
52567
52619
  if (!m) return null;
@@ -52770,6 +52822,7 @@ async function startDevServer(port, projectDir, config, host) {
52770
52822
  const lastSeenContent = /* @__PURE__ */ new Map();
52771
52823
  let chunkRefresh = Promise.resolve();
52772
52824
  const queueClientChunksRefresh = (fullPath, filename, fileExists) => {
52825
+ invalidateSsrCompile(ssrCompileCache, fullPath);
52773
52826
  chunkRefresh = chunkRefresh.then(async () => {
52774
52827
  try {
52775
52828
  const hot = await buildClientChunks(fullPath);
@@ -53277,7 +53330,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
53277
53330
  try {
53278
53331
  const nfSrc = readFileSync38(nfPath, "utf-8");
53279
53332
  const nfCompName = extractCompName2(nfSrc) || rootNode.notFound;
53280
- notFoundHtml = await renderFullPage(nfSrc, nfCompName, { params: {}, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, plugins: getActiveDevPlugins() });
53333
+ notFoundHtml = await renderFullPage(nfSrc, nfCompName, { params: {}, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, cached: cachedSsrCompile(ssrCompileCache, nfSrc, nfPath), plugins: getActiveDevPlugins() });
53281
53334
  } catch {
53282
53335
  }
53283
53336
  }
@@ -53322,7 +53375,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
53322
53375
  if (i === chain.length - 1 && node.page && existsSync42(pageFilePath)) {
53323
53376
  const src2 = readFileSync38(pageFilePath, "utf-8");
53324
53377
  const compName = extractCompName2(src2) || node.page;
53325
- const result = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath });
53378
+ const result = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, pageFilePath) });
53326
53379
  body = result.body;
53327
53380
  head = result.head || "";
53328
53381
  props = result.props;
@@ -53330,7 +53383,7 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
53330
53383
  if (node.layout && existsSync42(layoutFilePath)) {
53331
53384
  const src2 = readFileSync38(layoutFilePath, "utf-8");
53332
53385
  const compName = extractCompName2(src2) || node.layout;
53333
- const result = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath });
53386
+ const result = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, layoutFilePath) });
53334
53387
  body = result.body;
53335
53388
  head = (result.head || "") + head;
53336
53389
  }
@@ -53375,7 +53428,7 @@ ${prettifyHtml(body)}
53375
53428
  if (leaf) {
53376
53429
  const src2 = readFileSync38(resolve38(appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
53377
53430
  const compName = extractCompName2(src2) || leaf.page;
53378
- html = await renderFullPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve38(appDirPath, leaf.sourceDir, "page.vsk"), plugins: getActiveDevPlugins() });
53431
+ html = await renderFullPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve38(appDirPath, leaf.sourceDir, "page.vsk"), cached: cachedSsrCompile(ssrCompileCache, src2, resolve38(appDirPath, leaf.sourceDir, "page.vsk")), plugins: getActiveDevPlugins() });
53379
53432
  html = html.replace("</body>", ' <script type="module" src="/_vesk/hmr.js"></script>\n</body>');
53380
53433
  html = await applyHtmlPlugins(html, getActiveDevPlugins(), { sourcePath: url.pathname });
53381
53434
  } else {
@@ -53405,7 +53458,7 @@ ${prettifyHtml(body)}
53405
53458
  if (leaf) {
53406
53459
  const src2 = readFileSync38(resolve38(appDirPath, leaf.sourceDir, "page.vsk"), "utf-8");
53407
53460
  const compName = extractCompName2(src2) || leaf.page;
53408
- yield* renderPageStream(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve38(appDirPath, leaf.sourceDir, "page.vsk"), plugins: getActiveDevPlugins() });
53461
+ yield* renderPageStream(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, clientScriptUrl: "/_vesk/client.js", cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: resolve38(appDirPath, leaf.sourceDir, "page.vsk"), cached: cachedSsrCompile(ssrCompileCache, src2, resolve38(appDirPath, leaf.sourceDir, "page.vsk")), plugins: getActiveDevPlugins() });
53409
53462
  } else {
53410
53463
  throw new Error("No page or layout matched");
53411
53464
  }
@@ -53421,7 +53474,7 @@ ${prettifyHtml(body)}
53421
53474
  if (i === chain.length - 1 && node.page && existsSync42(pageFilePath)) {
53422
53475
  const src2 = readFileSync38(pageFilePath, "utf-8");
53423
53476
  const compName = extractCompName2(src2) || node.page;
53424
- const result = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath });
53477
+ const result = await renderPage(src2, compName, { params: matched.params }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: pageFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, pageFilePath) });
53425
53478
  body = result.body;
53426
53479
  head = result.head || "";
53427
53480
  props = result.props;
@@ -53429,7 +53482,7 @@ ${prettifyHtml(body)}
53429
53482
  if (node.layout && existsSync42(layoutFilePath)) {
53430
53483
  const src2 = readFileSync38(layoutFilePath, "utf-8");
53431
53484
  const compName = extractCompName2(src2) || node.layout;
53432
- const result = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath });
53485
+ const result = await renderPage(src2, compName, { children: body }, /* @__PURE__ */ new Map(), { hydrate: true, sourcePath: layoutFilePath, cached: cachedSsrCompile(ssrCompileCache, src2, layoutFilePath) });
53433
53486
  body = result.body;
53434
53487
  head = (result.head || "") + head;
53435
53488
  }
@@ -53569,7 +53622,7 @@ ${prettifyHtml(body)}
53569
53622
  try {
53570
53623
  const nfSrc = readFileSync38(nfPath, "utf-8");
53571
53624
  const nfCompName = extractCompName2(nfSrc) || node.notFound;
53572
- const html = await renderFullPage(nfSrc, nfCompName, { params: match.params, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, plugins: getActiveDevPlugins() });
53625
+ const html = await renderFullPage(nfSrc, nfCompName, { params: match.params, url: url.pathname }, /* @__PURE__ */ new Map(), { hydrate: true, cssUrls: activeCssUrls(), security, externalDataScript: storeDataScript, sourcePath: nfPath, cached: cachedSsrCompile(ssrCompileCache, nfSrc, nfPath), plugins: getActiveDevPlugins() });
53573
53626
  notFoundHtml = injectDevScripts(html);
53574
53627
  } catch {
53575
53628
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "main": "./dist/cli.js",
10
10
  "dependencies": {
11
- "@vesk/adapter": "^0.2.29",
12
- "@vesk/compiler": "^0.2.29",
13
- "@vesk/plugin-tailwind": "^0.2.29",
14
- "@vesk/runtime": "^0.2.29",
11
+ "@vesk/adapter": "^0.2.31",
12
+ "@vesk/compiler": "^0.2.31",
13
+ "@vesk/plugin-tailwind": "^0.2.31",
14
+ "@vesk/runtime": "^0.2.31",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",