bun-plugin-stx 0.2.218 → 0.2.220

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/serve.js +20 -3
  2. package/package.json +1 -1
package/dist/serve.js CHANGED
@@ -8718,7 +8718,7 @@ var defaultConfigDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "config");
8718
8718
  var defaultGeneratedDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "src/generated");
8719
8719
 
8720
8720
  // src/serve.ts
8721
- import { BUILD_ID_HEADER, extractPageResponseStatus, findContainerRegion, getBuildId, mergeCrosswindConfig, stateDir, stateDirName } from "@stacksjs/stx";
8721
+ import { BUILD_ID_HEADER, extractPageResponseStatus, findContainerRegion, FRAGMENT_CACHE_CONTROL, getBuildId, mergeCrosswindConfig, readResponseHeaders, readResponseStatus, SPA_NAV_HEADER, spaNavVaryHeaders, stateDir, stateDirName } from "@stacksjs/stx";
8722
8722
  import { buildCodeFrame, locateFailureLine } from "@stacksjs/stx/build-message";
8723
8723
  import { clearBundleFailures, getBundleFailures } from "@stacksjs/stx/client-script-bundler";
8724
8724
  import { actionRedirectResponse, compressResponse, runPageAction as sharedRunPageAction } from "@stacksjs/stx";
@@ -9451,6 +9451,9 @@ function __stxOverlay(errs){
9451
9451
  if (Number.isInteger(status) && status >= 100 && status <= 599)
9452
9452
  full.responseStatus = status;
9453
9453
  };
9454
+ context.notFound = (status = 404) => {
9455
+ full.responseStatus = Number.isInteger(status) && status >= 400 && status <= 599 ? status : 404;
9456
+ };
9454
9457
  context.setResponseHeader = (name, value) => {
9455
9458
  const header = String(name ?? "").trim();
9456
9459
  if (!header)
@@ -9776,6 +9779,16 @@ function __stxOverlay(errs){
9776
9779
  if (result.cookies && result.cookies.length > 0)
9777
9780
  reqCtx.actionCookies = result.cookies;
9778
9781
  }
9782
+ function applyRecordedResponse(context, reqCtx) {
9783
+ if (!reqCtx)
9784
+ return;
9785
+ const status = readResponseStatus(context);
9786
+ if (status !== undefined)
9787
+ reqCtx.responseStatus = status;
9788
+ const headers = readResponseHeaders(context);
9789
+ if (headers)
9790
+ reqCtx.responseHeaders = { ...reqCtx.responseHeaders, ...headers };
9791
+ }
9779
9792
  async function processTemplate(filePath, reqCtx) {
9780
9793
  const content = await Bun.file(filePath).text();
9781
9794
  if (reqCtx)
@@ -9841,6 +9854,7 @@ function __stxOverlay(errs){
9841
9854
  let output = templateContent;
9842
9855
  const dependencies = new Set;
9843
9856
  output = await processDirectives(output, context, filePath, config5, dependencies);
9857
+ applyRecordedResponse(context, reqCtx);
9844
9858
  output = await injectRouterScript(output, getRouterInjectOptions());
9845
9859
  const directiveTemplateRe = REACTIVE_TEMPLATE_DIRECTIVE_RE;
9846
9860
  const hasDirectiveTemplates = new RegExp(`<template\\s[^>]*(?:${REACTIVE_TEMPLATE_DIRECTIVE_RE.source})`).test(output);
@@ -10021,6 +10035,7 @@ function __stxOverlay(errs){
10021
10035
  let output = templateContent;
10022
10036
  const dependencies = new Set;
10023
10037
  output = await processDirectives(output, context, filePath, config5, dependencies);
10038
+ applyRecordedResponse(context, reqCtx);
10024
10039
  if (paramNames.length > 0) {
10025
10040
  const serializedParams = JSON.stringify(paramsObj).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
10026
10041
  const paramsScript = `<script data-stx-route-params>(function(){var p=${serializedParams};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;
@@ -10493,7 +10508,7 @@ ${html}`;
10493
10508
  }
10494
10509
  if (content) {
10495
10510
  const responseStatus = reqCtx.responseStatus ?? 200;
10496
- const isSpaNav = req.headers.get("X-STX-Router") === "true";
10511
+ const isSpaNav = req.headers.get(SPA_NAV_HEADER) === "true";
10497
10512
  if (isSpaNav) {
10498
10513
  const layoutMatch = content.match(/<!-- stx-layout: ([^ ]+) -->/);
10499
10514
  const pageLayout = layoutMatch ? layoutMatch[1] : "default";
@@ -10609,7 +10624,8 @@ ${trailingPageScripts.join(`
10609
10624
  ...pageTitle && { "X-STX-Title": encodeURIComponent(pageTitle) },
10610
10625
  [BUILD_ID_HEADER]: getBuildId(),
10611
10626
  ...containerAttrs && { "X-STX-Container-Attrs": encodeURIComponent(containerAttrs) },
10612
- "Cache-Control": "no-store",
10627
+ ...spaNavVaryHeaders(),
10628
+ "Cache-Control": FRAGMENT_CACHE_CONTROL,
10613
10629
  ...corsHeaders
10614
10630
  }
10615
10631
  });
@@ -10642,6 +10658,7 @@ ${trailingPageScripts.join(`
10642
10658
  }
10643
10659
  const pageHeaders = new Headers({
10644
10660
  "Content-Type": "text/html; charset=utf-8",
10661
+ ...spaNavVaryHeaders(),
10645
10662
  "Cache-Control": "no-store",
10646
10663
  ...corsHeaders
10647
10664
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.218",
4
+ "version": "0.2.220",
5
5
  "description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",