@astrojs/cloudflare 12.0.0-beta.0 → 12.0.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.
|
@@ -26,7 +26,9 @@ const service = {
|
|
|
26
26
|
// If it's not an imported image, nor is it allowed using the current domains or remote patterns, we'll just return the original URL
|
|
27
27
|
return options.src;
|
|
28
28
|
}
|
|
29
|
-
const imageEndpoint = joinPaths(
|
|
29
|
+
const imageEndpoint = joinPaths(
|
|
30
|
+
// @ts-expect-error Can't recognise import.meta.env
|
|
31
|
+
import.meta.env.BASE_URL, '/cdn-cgi/image', resizingParams.join(','), imageSource);
|
|
30
32
|
return imageEndpoint;
|
|
31
33
|
},
|
|
32
34
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import { type GetPlatformProxyOptions } from 'wrangler';
|
|
2
3
|
export type { Runtime } from './entrypoints/server.js';
|
|
3
4
|
export type Options = {
|
|
4
5
|
/** Options for handling images. */
|
|
@@ -30,17 +31,9 @@ export type Options = {
|
|
|
30
31
|
/**
|
|
31
32
|
* Proxy configuration for the platform.
|
|
32
33
|
*/
|
|
33
|
-
platformProxy?: {
|
|
34
|
+
platformProxy?: GetPlatformProxyOptions & {
|
|
34
35
|
/** Toggle the proxy. Default `undefined`, which equals to `true`. */
|
|
35
36
|
enabled?: boolean;
|
|
36
|
-
/** Path to the configuration file. Default `wrangler.toml`. */
|
|
37
|
-
configPath?: string;
|
|
38
|
-
/** Enable experimental support for JSON configuration. Default `false`. */
|
|
39
|
-
experimentalJsonConfig?: boolean;
|
|
40
|
-
/** Configuration persistence settings. Default '.wrangler/state/v3' */
|
|
41
|
-
persist?: boolean | {
|
|
42
|
-
path: string;
|
|
43
|
-
};
|
|
44
37
|
};
|
|
45
38
|
/**
|
|
46
39
|
* Allow bundling cloudflare worker specific file types as importable modules. Defaults to true.
|
package/dist/index.js
CHANGED
|
@@ -24,13 +24,6 @@ function setProcessEnv(config, env) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function createPlatformProxy(platformProxy) {
|
|
28
|
-
return getPlatformProxy({
|
|
29
|
-
configPath: platformProxy?.configPath,
|
|
30
|
-
experimentalJsonConfig: platformProxy?.experimentalJsonConfig ?? false,
|
|
31
|
-
persist: platformProxy?.persist ?? true,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
27
|
export default function createIntegration(args) {
|
|
35
28
|
let _config;
|
|
36
29
|
const cloudflareModulePlugin = cloudflareModuleLoader(args?.cloudflareModules ?? true);
|
|
@@ -50,6 +43,16 @@ export default function createIntegration(args) {
|
|
|
50
43
|
// https://developers.cloudflare.com/pages/functions/module-support/
|
|
51
44
|
// Allows imports of '.wasm', '.bin', and '.txt' file types
|
|
52
45
|
cloudflareModulePlugin,
|
|
46
|
+
{
|
|
47
|
+
name: 'vite:cf-imports',
|
|
48
|
+
enforce: 'pre',
|
|
49
|
+
resolveId(source) {
|
|
50
|
+
if (source.startsWith('cloudflare:')) {
|
|
51
|
+
return { id: source, external: true };
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
53
56
|
],
|
|
54
57
|
},
|
|
55
58
|
integrations: [astroWhen()],
|
|
@@ -87,7 +90,7 @@ export default function createIntegration(args) {
|
|
|
87
90
|
},
|
|
88
91
|
'astro:server:setup': async ({ server }) => {
|
|
89
92
|
if ((args?.platformProxy?.enabled ?? true) === true) {
|
|
90
|
-
const platformProxy = await
|
|
93
|
+
const platformProxy = await getPlatformProxy(args?.platformProxy);
|
|
91
94
|
setProcessEnv(_config, platformProxy.env);
|
|
92
95
|
const clientLocalsSymbol = Symbol.for('astro.locals');
|
|
93
96
|
server.middlewares.use(async function middleware(req, res, next) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { prependForwardSlash, removeLeadingForwardSlash, removeTrailingForwardSlash, } from '@astrojs/internal-helpers/path';
|
|
6
6
|
import glob from 'tiny-glob';
|
|
@@ -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);
|
|
@@ -129,7 +151,7 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
129
151
|
continue;
|
|
130
152
|
const staticPath = staticFile;
|
|
131
153
|
const segments = removeLeadingForwardSlash(staticPath)
|
|
132
|
-
.split(
|
|
154
|
+
.split(path.sep)
|
|
133
155
|
.filter(Boolean)
|
|
134
156
|
.map((s) => {
|
|
135
157
|
return getParts(s);
|
|
@@ -142,6 +164,7 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
142
164
|
const convertedPath = segmentsToCfSyntax(route.segments, _config);
|
|
143
165
|
if (route.pathname === '/404' && route.prerender === true)
|
|
144
166
|
hasPrerendered404 = true;
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
145
168
|
switch (route.type) {
|
|
146
169
|
case 'page':
|
|
147
170
|
if (route.prerender === false)
|
|
@@ -170,7 +193,7 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
170
193
|
if (page.pathname === '404')
|
|
171
194
|
hasPrerendered404 = true;
|
|
172
195
|
const pageSegments = removeLeadingForwardSlash(page.pathname)
|
|
173
|
-
.split(posix.sep)
|
|
196
|
+
.split(path.posix.sep)
|
|
174
197
|
.filter(Boolean)
|
|
175
198
|
.map((s) => {
|
|
176
199
|
return getParts(s);
|
|
@@ -181,7 +204,6 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
181
204
|
for (const includePath of includePaths) {
|
|
182
205
|
includeTrie.insert(includePath);
|
|
183
206
|
}
|
|
184
|
-
const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie.getAllPaths();
|
|
185
207
|
const excludeTrie = new PathTrie();
|
|
186
208
|
for (const excludePath of excludePaths) {
|
|
187
209
|
/**
|
|
@@ -193,7 +215,12 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
193
215
|
continue;
|
|
194
216
|
excludeTrie.insert(excludePath);
|
|
195
217
|
}
|
|
196
|
-
const [
|
|
218
|
+
const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie
|
|
219
|
+
.reduceAllPaths(excludeTrie)
|
|
220
|
+
.getAllPaths();
|
|
221
|
+
const [deduplicatedExcludePaths, _excludedPathsHaveWildcard] = excludeTrie
|
|
222
|
+
.reduceAllPaths(includeTrie)
|
|
223
|
+
.getAllPaths();
|
|
197
224
|
/**
|
|
198
225
|
* Cloudflare allows no more than 100 include/exclude rules combined
|
|
199
226
|
* https://developers.cloudflare.com/pages/functions/routing/#limits
|
|
@@ -211,9 +238,8 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
211
238
|
const AUTOMATIC_EXCLUDE_RULES_COUNT = deduplicatedExcludePaths.length;
|
|
212
239
|
const EXTENDED_EXCLUDE_RULES_COUNT = excludeExtends?.length ?? 0;
|
|
213
240
|
const EXCLUDE_RULES_COUNT = AUTOMATIC_EXCLUDE_RULES_COUNT + EXTENDED_EXCLUDE_RULES_COUNT;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
EXCLUDE_RULES_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
|
|
241
|
+
const OPTION2_TOTAL_COUNT = INCLUDE_RULES_COUNT + (includedPathsHaveWildcard ? EXCLUDE_RULES_COUNT : 0);
|
|
242
|
+
if (!hasPrerendered404 || OPTION2_TOTAL_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
|
|
217
243
|
await writeRoutesFileToOutDir(_config, logger, ['/*'].concat(includeExtends?.map((entry) => entry.pattern) ?? []), deduplicatedExcludePaths
|
|
218
244
|
.map((path) => `${prependForwardSlash(path.join('/'))}`)
|
|
219
245
|
.slice(0, CLOUDFLARE_COMBINED_LIMIT -
|
|
@@ -12,6 +12,10 @@ export declare function setImageConfig(service: string, config: AstroConfig['ima
|
|
|
12
12
|
hostname?: string | undefined;
|
|
13
13
|
pathname?: string | undefined;
|
|
14
14
|
}[];
|
|
15
|
+
experimentalLayout?: "fixed" | "none" | "responsive" | "full-width" | undefined;
|
|
16
|
+
experimentalObjectFit?: string | undefined;
|
|
17
|
+
experimentalObjectPosition?: string | undefined;
|
|
18
|
+
experimentalBreakpoints?: number[] | undefined;
|
|
15
19
|
} | {
|
|
16
20
|
service: import("astro").ImageServiceConfig<Record<string, any>>;
|
|
17
21
|
endpoint: {
|
|
@@ -24,4 +28,8 @@ export declare function setImageConfig(service: string, config: AstroConfig['ima
|
|
|
24
28
|
hostname?: string | undefined;
|
|
25
29
|
pathname?: string | undefined;
|
|
26
30
|
}[];
|
|
31
|
+
experimentalLayout?: "fixed" | "none" | "responsive" | "full-width" | undefined;
|
|
32
|
+
experimentalObjectFit?: string | undefined;
|
|
33
|
+
experimentalObjectPosition?: string | undefined;
|
|
34
|
+
experimentalBreakpoints?: number[] | undefined;
|
|
27
35
|
};
|
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": "12.0.0
|
|
4
|
+
"version": "12.0.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.4.0-alpha.0",
|
|
34
|
-
"@cloudflare/workers-types": "^4.
|
|
35
|
-
"
|
|
34
|
+
"@cloudflare/workers-types": "^4.20241112.0",
|
|
35
|
+
"@inox-tools/astro-when": "^0.2.4",
|
|
36
|
+
"esbuild": "^0.24.0",
|
|
36
37
|
"estree-walker": "^3.0.3",
|
|
37
|
-
"magic-string": "^0.30.
|
|
38
|
-
"miniflare": "^3.
|
|
38
|
+
"magic-string": "^0.30.14",
|
|
39
|
+
"miniflare": "^3.20241106.1",
|
|
39
40
|
"tiny-glob": "^0.2.9",
|
|
40
|
-
"wrangler": "^3.
|
|
41
|
-
"@inox-tools/astro-when": "^0.2.2"
|
|
41
|
+
"wrangler": "^3.91.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"astro": "^5.0.0
|
|
44
|
+
"astro": "^5.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"astro": "^5.0.0-alpha.
|
|
47
|
+
"astro": "^5.0.0-alpha.15",
|
|
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.27.4",
|
|
52
52
|
"strip-ansi": "^7.1.0",
|
|
53
|
-
"vite": "
|
|
53
|
+
"vite": "6.0.1",
|
|
54
54
|
"@astrojs/test-utils": "0.0.1",
|
|
55
55
|
"astro-scripts": "0.0.14"
|
|
56
56
|
},
|