@astrojs/cloudflare 11.0.5 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -0
- package/dist/utils/generate-routes-json.js +30 -5
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -50,6 +50,16 @@ export default function createIntegration(args) {
|
|
|
50
50
|
// https://developers.cloudflare.com/pages/functions/module-support/
|
|
51
51
|
// Allows imports of '.wasm', '.bin', and '.txt' file types
|
|
52
52
|
cloudflareModulePlugin,
|
|
53
|
+
{
|
|
54
|
+
name: 'vite:cf-imports',
|
|
55
|
+
enforce: 'pre',
|
|
56
|
+
resolveId(source) {
|
|
57
|
+
if (source.startsWith('cloudflare:')) {
|
|
58
|
+
return { id: source, external: true };
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
53
63
|
],
|
|
54
64
|
},
|
|
55
65
|
integrations: [astroWhen()],
|
|
@@ -96,6 +96,28 @@ class PathTrie {
|
|
|
96
96
|
this.dfs(childNode, [...path, segment], allPaths);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The reduce function is used to remove unnecessary paths from the trie.
|
|
101
|
+
* It receives a trie node to compare with the current node.
|
|
102
|
+
*/
|
|
103
|
+
reduce(compNode, node) {
|
|
104
|
+
if (node.hasWildcardChild || compNode.hasWildcardChild)
|
|
105
|
+
return;
|
|
106
|
+
for (const [segment, childNode] of node.children) {
|
|
107
|
+
if (childNode.children.size === 0)
|
|
108
|
+
continue;
|
|
109
|
+
const compChildNode = compNode.children.get(segment);
|
|
110
|
+
if (compChildNode === undefined) {
|
|
111
|
+
childNode.hasWildcardChild = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
this.reduce(compChildNode, childNode);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
reduceAllPaths(compTrie) {
|
|
118
|
+
this.reduce(compTrie.root, this.root);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
99
121
|
getAllPaths() {
|
|
100
122
|
const allPaths = [];
|
|
101
123
|
this.dfs(this.root, [], allPaths);
|
|
@@ -181,7 +203,6 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
181
203
|
for (const includePath of includePaths) {
|
|
182
204
|
includeTrie.insert(includePath);
|
|
183
205
|
}
|
|
184
|
-
const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie.getAllPaths();
|
|
185
206
|
const excludeTrie = new PathTrie();
|
|
186
207
|
for (const excludePath of excludePaths) {
|
|
187
208
|
/**
|
|
@@ -193,7 +214,12 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
193
214
|
continue;
|
|
194
215
|
excludeTrie.insert(excludePath);
|
|
195
216
|
}
|
|
196
|
-
const [
|
|
217
|
+
const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie
|
|
218
|
+
.reduceAllPaths(excludeTrie)
|
|
219
|
+
.getAllPaths();
|
|
220
|
+
const [deduplicatedExcludePaths, _excludedPathsHaveWildcard] = excludeTrie
|
|
221
|
+
.reduceAllPaths(includeTrie)
|
|
222
|
+
.getAllPaths();
|
|
197
223
|
/**
|
|
198
224
|
* Cloudflare allows no more than 100 include/exclude rules combined
|
|
199
225
|
* https://developers.cloudflare.com/pages/functions/routing/#limits
|
|
@@ -211,9 +237,8 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
211
237
|
const AUTOMATIC_EXCLUDE_RULES_COUNT = deduplicatedExcludePaths.length;
|
|
212
238
|
const EXTENDED_EXCLUDE_RULES_COUNT = excludeExtends?.length ?? 0;
|
|
213
239
|
const EXCLUDE_RULES_COUNT = AUTOMATIC_EXCLUDE_RULES_COUNT + EXTENDED_EXCLUDE_RULES_COUNT;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
EXCLUDE_RULES_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
|
|
240
|
+
const OPTION2_TOTAL_COUNT = INCLUDE_RULES_COUNT + (includedPathsHaveWildcard ? EXCLUDE_RULES_COUNT : 0);
|
|
241
|
+
if (!hasPrerendered404 || OPTION2_TOTAL_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
|
|
217
242
|
await writeRoutesFileToOutDir(_config, logger, ['/*'].concat(includeExtends?.map((entry) => entry.pattern) ?? []), deduplicatedExcludePaths
|
|
218
243
|
.map((path) => `${prependForwardSlash(path.join('/'))}`)
|
|
219
244
|
.slice(0, CLOUDFLARE_COMBINED_LIMIT -
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/cloudflare",
|
|
3
3
|
"description": "Deploy your site to Cloudflare Workers/Pages",
|
|
4
|
-
"version": "11.0
|
|
4
|
+
"version": "11.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -31,26 +31,26 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@astrojs/internal-helpers": "0.4.1",
|
|
33
33
|
"@astrojs/underscore-redirects": "^0.3.4",
|
|
34
|
-
"@cloudflare/workers-types": "^4.
|
|
34
|
+
"@cloudflare/workers-types": "^4.20241022.0",
|
|
35
35
|
"esbuild": "^0.21.5",
|
|
36
36
|
"estree-walker": "^3.0.3",
|
|
37
|
-
"magic-string": "^0.30.
|
|
38
|
-
"miniflare": "^3.
|
|
37
|
+
"magic-string": "^0.30.12",
|
|
38
|
+
"miniflare": "^3.20241018.0",
|
|
39
39
|
"tiny-glob": "^0.2.9",
|
|
40
|
-
"wrangler": "^3.
|
|
41
|
-
"@inox-tools/astro-when": "^0.2.
|
|
40
|
+
"wrangler": "^3.82.0",
|
|
41
|
+
"@inox-tools/astro-when": "^0.2.4"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"astro": "^4.10.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"astro": "^4.
|
|
47
|
+
"astro": "^4.16.7",
|
|
48
48
|
"cheerio": "1.0.0",
|
|
49
49
|
"execa": "^8.0.1",
|
|
50
50
|
"fast-glob": "^3.3.2",
|
|
51
|
-
"rollup": "^4.
|
|
51
|
+
"rollup": "^4.24.0",
|
|
52
52
|
"strip-ansi": "^7.1.0",
|
|
53
|
-
"vite": "^5.4.
|
|
53
|
+
"vite": "^5.4.10",
|
|
54
54
|
"@astrojs/test-utils": "0.0.1",
|
|
55
55
|
"astro-scripts": "0.0.14"
|
|
56
56
|
},
|