From d3b6fadd5909757d94d29d48081ab29ababcb179 Mon Sep 17 00:00:00 2001 From: Sandros94 Date: Tue, 5 Nov 2024 18:41:30 +0100 Subject: [PATCH 1/3] fix: environment specific event handlers --- src/core/scan.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/scan.ts b/src/core/scan.ts index 63a0517d3a..45f3b316e0 100644 --- a/src/core/scan.ts +++ b/src/core/scan.ts @@ -7,7 +7,7 @@ export const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}"; type FileInfo = { path: string; fullPath: string }; const suffixRegex = - /\.(connect|delete|get|head|options|patch|post|put|trace)(\.(dev|prod|prerender))?$/; + /\.(?connect|delete|get|head|options|patch|post|put|trace)?(?:\.(?dev|prod|prerender))?$/; // prettier-ignore type MatchedMethodSuffix = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace"; @@ -106,8 +106,9 @@ export async function scanServerRoutes( let env: MatchedEnvSuffix | undefined; if (suffixMatch?.index) { route = route.slice(0, Math.max(0, suffixMatch.index)); - method = suffixMatch[1] as MatchedMethodSuffix; - env = suffixMatch[3] as MatchedEnvSuffix; + const { groups } = suffixMatch; + method = groups?.method as MatchedMethodSuffix | undefined; + env = groups?.env as MatchedEnvSuffix | undefined; } route = route.replace(/\/index$/, "") || "/"; From 87735b27e0d1b3123af3a80a39bbddf47313aaf5 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 5 Nov 2024 19:27:08 +0100 Subject: [PATCH 2/3] update fixture (failing test) --- test/fixture/routes/env/{index.get.dev.ts => index.dev.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/fixture/routes/env/{index.get.dev.ts => index.dev.ts} (100%) diff --git a/test/fixture/routes/env/index.get.dev.ts b/test/fixture/routes/env/index.dev.ts similarity index 100% rename from test/fixture/routes/env/index.get.dev.ts rename to test/fixture/routes/env/index.dev.ts From c7db6db09f724128c34e7e4c55d1b88b1d265fa6 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 5 Nov 2024 19:34:36 +0100 Subject: [PATCH 3/3] update regex and logic --- src/core/scan.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/scan.ts b/src/core/scan.ts index 45f3b316e0..e04a70704e 100644 --- a/src/core/scan.ts +++ b/src/core/scan.ts @@ -7,7 +7,7 @@ export const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}"; type FileInfo = { path: string; fullPath: string }; const suffixRegex = - /\.(?connect|delete|get|head|options|patch|post|put|trace)?(?:\.(?dev|prod|prerender))?$/; + /(\.(?connect|delete|get|head|options|patch|post|put|trace))?(\.(?dev|prod|prerender))?$/; // prettier-ignore type MatchedMethodSuffix = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace"; @@ -104,11 +104,10 @@ export async function scanServerRoutes( const suffixMatch = route.match(suffixRegex); let method: MatchedMethodSuffix | undefined; let env: MatchedEnvSuffix | undefined; - if (suffixMatch?.index) { - route = route.slice(0, Math.max(0, suffixMatch.index)); - const { groups } = suffixMatch; - method = groups?.method as MatchedMethodSuffix | undefined; - env = groups?.env as MatchedEnvSuffix | undefined; + if (suffixMatch?.index && suffixMatch?.index >= 0) { + route = route.slice(0, suffixMatch.index); + method = suffixMatch.groups?.method as MatchedMethodSuffix | undefined; + env = suffixMatch.groups?.env as MatchedEnvSuffix | undefined; } route = route.replace(/\/index$/, "") || "/";