diff --git a/.changeset/sharp-cameras-rescue.md b/.changeset/sharp-cameras-rescue.md new file mode 100644 index 00000000..bda9afe6 --- /dev/null +++ b/.changeset/sharp-cameras-rescue.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Fixes an error with automatic deduplication of `_routes.json` for more complex project structures diff --git a/packages/cloudflare/src/utils/deduplicatePatterns.ts b/packages/cloudflare/src/utils/deduplicatePatterns.ts index 362ac167..b408083b 100644 --- a/packages/cloudflare/src/utils/deduplicatePatterns.ts +++ b/packages/cloudflare/src/utils/deduplicatePatterns.ts @@ -13,7 +13,7 @@ export function deduplicatePatterns(patterns: string[]) { const uniquePatterns = [...new Set(patterns)]; for (const pattern of uniquePatterns) { if (pattern.endsWith('*')) { - openPatterns.push(new RegExp(`^${pattern.replace(/(\*\/)*\*$/g, '[^*\n]*$')}`)); + openPatterns.push(new RegExp(`^${pattern.replace(/(\*\/)*\*$/g, '(?=.{2,}).+[^*\n]$')}`)); } } diff --git a/packages/cloudflare/test/routes-json.test.js b/packages/cloudflare/test/routes-json.test.js index 8997ac4e..e9889967 100644 --- a/packages/cloudflare/test/routes-json.test.js +++ b/packages/cloudflare/test/routes-json.test.js @@ -202,7 +202,7 @@ describe('_routes.json generation', () => { assert.deepEqual(routes, { version: 1, include: ['/a/*', '/_image'], - exclude: ['/a/*', '/another'], + exclude: ['/a/', '/a/*', '/another'], }); }); });