-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cloudflare): refactor structure, optimize patterns (#8654)
--------- Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: 100gle <[email protected]>
- Loading branch information
1 parent
b814003
commit 081f25b
Showing
12 changed files
with
308 additions
and
308 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rations/cloudflare/src/server.advanced.ts → ...dflare/src/entrypoints/server.advanced.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ations/cloudflare/src/server.directory.ts → ...flare/src/entrypoints/server.directory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { AstroAdapter, AstroFeatureMap } from 'astro'; | ||
|
||
export function getAdapter({ | ||
isModeDirectory, | ||
functionPerRoute, | ||
}: { | ||
isModeDirectory: boolean; | ||
functionPerRoute: boolean; | ||
}): AstroAdapter { | ||
const astroFeatures = { | ||
hybridOutput: 'stable', | ||
staticOutput: 'unsupported', | ||
serverOutput: 'stable', | ||
assets: { | ||
supportKind: 'stable', | ||
isSharpCompatible: false, | ||
isSquooshCompatible: false, | ||
}, | ||
} satisfies AstroFeatureMap; | ||
|
||
if (isModeDirectory) { | ||
return { | ||
name: '@astrojs/cloudflare', | ||
serverEntrypoint: '@astrojs/cloudflare/entrypoints/server.directory.js', | ||
exports: ['onRequest', 'manifest'], | ||
adapterFeatures: { | ||
functionPerRoute, | ||
edgeMiddleware: false, | ||
}, | ||
supportedAstroFeatures: astroFeatures, | ||
}; | ||
} | ||
|
||
return { | ||
name: '@astrojs/cloudflare', | ||
serverEntrypoint: '@astrojs/cloudflare/entrypoints/server.advanced.js', | ||
exports: ['default'], | ||
supportedAstroFeatures: astroFeatures, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/integrations/cloudflare/src/utils/deduplicatePatterns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Remove duplicates and redundant patterns from an `include` or `exclude` list. | ||
* Otherwise Cloudflare will throw an error on deployment. Plus, it saves more entries. | ||
* E.g. `['/foo/*', '/foo/*', '/foo/bar'] => ['/foo/*']` | ||
* @param patterns a list of `include` or `exclude` patterns | ||
* @returns a deduplicated list of patterns | ||
*/ | ||
export function deduplicatePatterns(patterns: string[]) { | ||
const openPatterns: RegExp[] = []; | ||
|
||
// A value in the set may only occur once; it is unique in the set's collection. | ||
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set | ||
return [...new Set(patterns)] | ||
.sort((a, b) => a.length - b.length) | ||
.filter((pattern) => { | ||
if (openPatterns.some((p) => p.test(pattern))) { | ||
return false; | ||
} | ||
|
||
if (pattern.endsWith('*')) { | ||
openPatterns.push(new RegExp(`^${pattern.replace(/(\*\/)*\*$/g, '.*')}`)); | ||
} | ||
|
||
return true; | ||
}); | ||
} |
Oops, something went wrong.