Skip to content

Commit

Permalink
fix(cloudflare): _routes.json deduplication (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
alexanderniebuhr and sarah11918 authored Feb 27, 2024
1 parent de62fa8 commit 0463483
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-cameras-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

Fixes an error with automatic deduplication of `_routes.json` for more complex project structures
2 changes: 1 addition & 1 deletion packages/cloudflare/src/utils/deduplicatePatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]$')}`));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/routes-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('_routes.json generation', () => {
assert.deepEqual(routes, {
version: 1,
include: ['/a/*', '/_image'],
exclude: ['/a/*', '/another'],
exclude: ['/a/', '/a/*', '/another'],
});
});
});
Expand Down

0 comments on commit 0463483

Please sign in to comment.