@stacksjs/stx 0.2.149 → 0.2.151

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.
@@ -8,6 +8,7 @@ import { partialsCache } from "../includes.js";
8
8
  import { stateDir } from "../state-dir.js";
9
9
  import { plugin as stxPlugin } from "../plugin.js";
10
10
  import { clearComponentCache } from "../utils.js";
11
+ import { bracketPathToRegex } from "stx-router";
11
12
  import {
12
13
  colors,
13
14
  findAvailablePort,
@@ -275,9 +276,9 @@ export async function serveMultipleStxFiles(filePaths, options = {}) {
275
276
  if (routePath.endsWith("/index"))
276
277
  routePath = routePath.slice(0, -6) || "/";
277
278
  if (routePath.includes("[")) {
278
- const paramNames = [...routePath.matchAll(/\[([^\]]+)\]/g)].map((m) => m[1]), regexStr = routePath.replace(/\[([^\]]+)\]/g, "([^/]+)");
279
+ const { regex, params: paramNames } = bracketPathToRegex(routePath);
279
280
  dynamicRoutes.push({
280
- pattern: new RegExp(`^${regexStr}$`),
281
+ pattern: regex,
281
282
  paramNames,
282
283
  filePath: absolutePath,
283
284
  routeTemplate: routePath,
@@ -4,6 +4,7 @@ import { serve } from "bun";
4
4
  import { loadManifest } from "./manifest.js";
5
5
  import { hydrateTemplateStream, hydrateFragment } from "./template-hydrator.js";
6
6
  import { extractLayoutMetadata } from "./app-shell.js";
7
+ import { patternToRegex } from "stx-router";
7
8
  const MIME_TYPES = {
8
9
  ".js": "application/javascript",
9
10
  ".mjs": "application/javascript",
@@ -55,11 +56,8 @@ export async function startProductionServer(options = {}) {
55
56
  const exactRoutes = new Map, paramRoutes = [];
56
57
  for (const route of manifest.routes)
57
58
  if (route.hasParams) {
58
- const paramNames = [], regexStr = route.pattern.replace(/:([^/]+)/g, (_, name) => {
59
- paramNames.push(name);
60
- return "([^/]+)";
61
- });
62
- paramRoutes.push({ regex: new RegExp(`^${regexStr}$`), route, paramNames });
59
+ const { regex, params: paramNames } = patternToRegex(route.pattern);
60
+ paramRoutes.push({ regex, route, paramNames });
63
61
  } else
64
62
  exactRoutes.set(route.pattern, route);
65
63
  const server = serve({
package/dist/ssr.js CHANGED
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { errorLogger } from "./error-handling.js";
4
4
  import { processDirectives } from "./process.js";
5
5
  import { extractVariables } from "./utils.js";
6
+ import { patternToRegex } from "stx-router";
6
7
 
7
8
  export class MemorySessionStore {
8
9
  store = new Map;
@@ -180,10 +181,7 @@ export function createApp(config = {}) {
180
181
  for (const route of routes) {
181
182
  if (route.method !== method && route.method !== "*")
182
183
  continue;
183
- const paramNames = [], regexPattern = route.pattern.replace(/\/:(\w+)/g, (_, name) => {
184
- paramNames.push(name);
185
- return "/([^/]+)";
186
- }).replace(/\//g, "\\/"), regex = new RegExp(`^${regexPattern}$`), match = pathname.match(regex);
184
+ const { regex, params: paramNames } = patternToRegex(route.pattern), match = pathname.match(regex);
187
185
  if (match) {
188
186
  const params = {};
189
187
  paramNames.forEach((name, i) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.149",
4
+ "version": "0.2.151",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -117,12 +117,12 @@
117
117
  "dependencies": {
118
118
  "@cwcss/crosswind": "^0.2.14",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/desktop": "0.2.149",
121
- "@stacksjs/sanitizer": "0.2.149",
120
+ "@stacksjs/desktop": "0.2.151",
121
+ "@stacksjs/sanitizer": "0.2.151",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.149",
123
+ "bun-plugin-stx": "0.2.151",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.149",
125
+ "stx-router": "0.2.151",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.1.9",
128
128
  "ts-syntax-highlighter": "^0.2.1"