bun-plugin-stx 0.2.170 → 0.2.172

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.
@@ -14,7 +14,7 @@ import fs from "fs";
14
14
  import path from "path";
15
15
 
16
16
  // ../router/src/page-routes.ts
17
- var NON_PAGE_DIRS = ["components", "layouts", "partials"];
17
+ var NON_PAGE_DIRS = ["components", "layouts", "partials", "emails"];
18
18
  function isNonPageRoutePath(relativePath) {
19
19
  const segments = relativePath.split(/[\\/]/).filter(Boolean);
20
20
  return segments.slice(0, -1).some((segment) => NON_PAGE_DIRS.includes(segment));
package/dist/serve.js CHANGED
@@ -8721,7 +8721,7 @@ var defaultGeneratedDir4 = /* @__PURE__ */ resolve12(process20.cwd(), "src/gener
8721
8721
  import { BUILD_ID_HEADER, extractPageResponseStatus, findContainerRegion, getBuildId, mergeCrosswindConfig, 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
- import { compressResponse } from "@stacksjs/stx";
8724
+ import { compressResponse, runPageAction as sharedRunPageAction } from "@stacksjs/stx";
8725
8725
  var defaultStxModule = import("@stacksjs/stx");
8726
8726
  var REACTIVE_TEMPLATE_DIRECTIVE_RE = /@for|:for|@if|:if|@else|:else|x-for|x-if|x-else/;
8727
8727
  function extractServerScriptsFromTemplate(content) {
@@ -9380,6 +9380,7 @@ function __stxOverlay(errs){
9380
9380
  const full = reqCtx ?? {
9381
9381
  url: "",
9382
9382
  path: "",
9383
+ method: "GET",
9383
9384
  search,
9384
9385
  host,
9385
9386
  cookieHeader: activeServeCookieHeader,
@@ -9521,7 +9522,7 @@ function __stxOverlay(errs){
9521
9522
  pageMiddlewarePatterns.length = 0;
9522
9523
  await Promise.all(files.map((f) => detectPageMiddleware(f)));
9523
9524
  try {
9524
- const { Router } = await import("./chunk-z66h8w4a.js");
9525
+ const { Router } = await import("./chunk-ebg5468e.js");
9525
9526
  const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
9526
9527
  const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName() });
9527
9528
  if (!options.quiet)
@@ -9701,57 +9702,17 @@ function __stxOverlay(errs){
9701
9702
  return "";
9702
9703
  }
9703
9704
  }
9704
- async function parseFormBody(request) {
9705
- const type = request.headers.get("content-type") || "";
9706
- const form = {};
9707
- const put = (key, value) => {
9708
- const existing = form[key];
9709
- if (existing === undefined)
9710
- form[key] = value;
9711
- else if (Array.isArray(existing))
9712
- existing.push(value);
9713
- else
9714
- form[key] = [existing, value];
9715
- };
9716
- if (type.includes("multipart/form-data")) {
9717
- const data = await request.formData();
9718
- for (const [key, value] of data.entries()) {
9719
- if (typeof value === "string")
9720
- put(key, value);
9721
- }
9722
- return form;
9723
- }
9724
- if (type.includes("application/x-www-form-urlencoded")) {
9725
- for (const [key, value] of new URLSearchParams(await request.text()).entries())
9726
- put(key, value);
9727
- return form;
9728
- }
9729
- return form;
9730
- }
9731
9705
  async function runPageAction(context, reqCtx) {
9732
- if (!reqCtx || reqCtx.method === "GET" || reqCtx.method === "HEAD")
9733
- return;
9734
- if (typeof context.action !== "function" || !reqCtx.request)
9706
+ if (!reqCtx)
9735
9707
  return;
9736
- let form = {};
9737
- try {
9738
- form = await parseFormBody(reqCtx.request);
9739
- } catch {}
9740
- const result = await context.action({
9708
+ const result = await sharedRunPageAction(context, {
9741
9709
  request: reqCtx.request,
9742
- form,
9710
+ method: reqCtx.method,
9743
9711
  params: reqCtx.params ?? {},
9744
- query: context.query ?? {},
9745
9712
  cookies: reqCtx.cookies ?? {}
9746
9713
  });
9747
- if (result && typeof result === "object") {
9748
- const to = result.redirect;
9749
- if (typeof to === "string" && to) {
9750
- reqCtx.actionRedirect = to;
9751
- return;
9752
- }
9753
- Object.assign(context, result);
9754
- }
9714
+ if (result.redirect)
9715
+ reqCtx.actionRedirect = result.redirect;
9755
9716
  }
9756
9717
  async function processTemplate(filePath, reqCtx) {
9757
9718
  const content = await Bun.file(filePath).text();
@@ -10619,16 +10580,18 @@ ${trailingPageScripts.join(`
10619
10580
  }
10620
10581
  });
10621
10582
  }
10622
- const contentWithExt = await getRoute(`${path}.html`, reqCtx);
10623
- if (contentWithExt) {
10624
- return new Response(injectHmrClient(contentWithExt), {
10625
- status: reqCtx.responseStatus ?? 200,
10626
- headers: {
10627
- "Content-Type": "text/html; charset=utf-8",
10628
- "Cache-Control": "no-store",
10629
- ...corsHeaders
10630
- }
10631
- });
10583
+ if (!isStaticAssetPath(path)) {
10584
+ const contentWithExt = await getRoute(`${path}.html`, reqCtx);
10585
+ if (contentWithExt) {
10586
+ return new Response(injectHmrClient(contentWithExt), {
10587
+ status: reqCtx.responseStatus ?? 200,
10588
+ headers: {
10589
+ "Content-Type": "text/html; charset=utf-8",
10590
+ "Cache-Control": "no-store",
10591
+ ...corsHeaders
10592
+ }
10593
+ });
10594
+ }
10632
10595
  }
10633
10596
  if (path.startsWith("/chunk-") || path.endsWith(".js") || path.endsWith(".css")) {
10634
10597
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.170",
4
+ "version": "0.2.172",
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",