From b6c0c28272635ed2399c2c3d25261eac891dcdd4 Mon Sep 17 00:00:00 2001 From: Veit Bjarsch Date: Wed, 11 Sep 2024 09:40:10 +0200 Subject: [PATCH 1/6] Added windows support for static files --- packages/cloudflare/src/utils/generate-routes-json.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cloudflare/src/utils/generate-routes-json.ts b/packages/cloudflare/src/utils/generate-routes-json.ts index 5d1470db9..1bd9bd162 100644 --- a/packages/cloudflare/src/utils/generate-routes-json.ts +++ b/packages/cloudflare/src/utils/generate-routes-json.ts @@ -2,7 +2,7 @@ import type { AstroConfig, AstroIntegrationLogger, RouteData, RoutePart } from ' import { existsSync } from 'node:fs'; import { writeFile } from 'node:fs/promises'; -import { posix } from 'node:path'; +import { win32, posix } from 'node:path'; import { fileURLToPath } from 'node:url'; import { prependForwardSlash, @@ -232,7 +232,7 @@ export async function createRoutesFile( for (const page of pages) { if (page.pathname === '404') hasPrerendered404 = true; const pageSegments = removeLeadingForwardSlash(page.pathname) - .split(posix.sep) + .split(process.platform === `win32` ? win32.sep : posix.sep) .filter(Boolean) .map((s) => { return getParts(s); From a4329f02ec651b095655e01b9f38885a3b84e1ad Mon Sep 17 00:00:00 2001 From: Veit Bjarsch Date: Wed, 11 Sep 2024 09:58:42 +0200 Subject: [PATCH 2/6] fix: fixed formatting --- packages/cloudflare/src/utils/generate-routes-json.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cloudflare/src/utils/generate-routes-json.ts b/packages/cloudflare/src/utils/generate-routes-json.ts index 1bd9bd162..e87cdce73 100644 --- a/packages/cloudflare/src/utils/generate-routes-json.ts +++ b/packages/cloudflare/src/utils/generate-routes-json.ts @@ -2,7 +2,7 @@ import type { AstroConfig, AstroIntegrationLogger, RouteData, RoutePart } from ' import { existsSync } from 'node:fs'; import { writeFile } from 'node:fs/promises'; -import { win32, posix } from 'node:path'; +import { posix, win32 } from 'node:path'; import { fileURLToPath } from 'node:url'; import { prependForwardSlash, From 616b23ca5b015ce15bb139a8c9876793eb765580 Mon Sep 17 00:00:00 2001 From: Veit Bjarsch Date: Wed, 11 Sep 2024 10:01:03 +0200 Subject: [PATCH 3/6] fix: fixed linting issue --- packages/cloudflare/src/utils/generate-routes-json.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cloudflare/src/utils/generate-routes-json.ts b/packages/cloudflare/src/utils/generate-routes-json.ts index e87cdce73..a057b2a3f 100644 --- a/packages/cloudflare/src/utils/generate-routes-json.ts +++ b/packages/cloudflare/src/utils/generate-routes-json.ts @@ -232,7 +232,7 @@ export async function createRoutesFile( for (const page of pages) { if (page.pathname === '404') hasPrerendered404 = true; const pageSegments = removeLeadingForwardSlash(page.pathname) - .split(process.platform === `win32` ? win32.sep : posix.sep) + .split(process.platform === 'win32' ? win32.sep : posix.sep) .filter(Boolean) .map((s) => { return getParts(s); From d894e55dff81f113b68199a096e4f02189211137 Mon Sep 17 00:00:00 2001 From: Veit Bjarsch Date: Wed, 11 Sep 2024 14:56:13 +0200 Subject: [PATCH 4/6] adjusted code --- packages/cloudflare/src/utils/generate-routes-json.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cloudflare/src/utils/generate-routes-json.ts b/packages/cloudflare/src/utils/generate-routes-json.ts index a057b2a3f..98d7add04 100644 --- a/packages/cloudflare/src/utils/generate-routes-json.ts +++ b/packages/cloudflare/src/utils/generate-routes-json.ts @@ -186,7 +186,7 @@ export async function createRoutesFile( const staticPath = staticFile; const segments = removeLeadingForwardSlash(staticPath) - .split(posix.sep) + .split(process.platform === 'win32' ? win32.sep : posix.sep) .filter(Boolean) .map((s: string) => { return getParts(s); @@ -232,7 +232,7 @@ export async function createRoutesFile( for (const page of pages) { if (page.pathname === '404') hasPrerendered404 = true; const pageSegments = removeLeadingForwardSlash(page.pathname) - .split(process.platform === 'win32' ? win32.sep : posix.sep) + .split(posix.sep) .filter(Boolean) .map((s) => { return getParts(s); From dcc23c2f5863069aa8e0b27e69583d0795f9999b Mon Sep 17 00:00:00 2001 From: Veit Bjarsch Date: Mon, 16 Sep 2024 09:21:09 +0200 Subject: [PATCH 5/6] use path.sep instead --- packages/cloudflare/src/utils/generate-routes-json.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cloudflare/src/utils/generate-routes-json.ts b/packages/cloudflare/src/utils/generate-routes-json.ts index 98d7add04..60f598d13 100644 --- a/packages/cloudflare/src/utils/generate-routes-json.ts +++ b/packages/cloudflare/src/utils/generate-routes-json.ts @@ -2,7 +2,7 @@ import type { AstroConfig, AstroIntegrationLogger, RouteData, RoutePart } from ' import { existsSync } from 'node:fs'; import { writeFile } from 'node:fs/promises'; -import { posix, win32 } from 'node:path'; +import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { prependForwardSlash, @@ -186,7 +186,7 @@ export async function createRoutesFile( const staticPath = staticFile; const segments = removeLeadingForwardSlash(staticPath) - .split(process.platform === 'win32' ? win32.sep : posix.sep) + .split(path.sep) .filter(Boolean) .map((s: string) => { return getParts(s); @@ -232,7 +232,7 @@ export async function createRoutesFile( for (const page of pages) { if (page.pathname === '404') hasPrerendered404 = true; const pageSegments = removeLeadingForwardSlash(page.pathname) - .split(posix.sep) + .split(path.posix.sep) .filter(Boolean) .map((s) => { return getParts(s); From b6574c8403c1280c7b64a617bd33f5f81d1275ef Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Tue, 17 Sep 2024 10:22:48 +0200 Subject: [PATCH 6/6] add changeset --- .changeset/weak-steaks-hang.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/weak-steaks-hang.md diff --git a/.changeset/weak-steaks-hang.md b/.changeset/weak-steaks-hang.md new file mode 100644 index 000000000..7d9b2ddd1 --- /dev/null +++ b/.changeset/weak-steaks-hang.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Fixes a bug which was caused on windows when splitting static file paths