@astrojs/cloudflare 12.1.0 → 12.2.1
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.
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
[When.Client]: () => {
|
|
4
|
-
throw new Error('Client should not run a middleware!');
|
|
5
|
-
},
|
|
6
|
-
[When.DevServer]: (_, next) => next(),
|
|
7
|
-
[When.Server]: (_, next) => next(),
|
|
8
|
-
[When.Prerender]: (ctx, next) => {
|
|
1
|
+
export const onRequest = (context, next) => {
|
|
2
|
+
if (context.isPrerendered) {
|
|
9
3
|
// @ts-expect-error
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return next();
|
|
17
|
-
},
|
|
18
|
-
[When.StaticBuild]: (_, next) => next(),
|
|
4
|
+
context.locals.runtime ??= {
|
|
5
|
+
env: process.env,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
return next();
|
|
19
9
|
};
|
|
20
|
-
export const onRequest = middlewares[whenAmI];
|
|
@@ -34,6 +34,7 @@ export function createExports(manifest) {
|
|
|
34
34
|
passThroughOnException: () => {
|
|
35
35
|
throw new Error('`passThroughOnException` is currently not available in Cloudflare Pages. See https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions.');
|
|
36
36
|
},
|
|
37
|
+
props: {},
|
|
37
38
|
},
|
|
38
39
|
},
|
|
39
40
|
};
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { appendFile, rename, stat } from 'node:fs/promises';
|
|
|
3
3
|
import { createInterface } from 'node:readline/promises';
|
|
4
4
|
import { appendForwardSlash, prependForwardSlash, removeLeadingForwardSlash, } from '@astrojs/internal-helpers/path';
|
|
5
5
|
import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects';
|
|
6
|
-
import astroWhen from '@inox-tools/astro-when';
|
|
7
6
|
import { AstroError } from 'astro/errors';
|
|
8
7
|
import { defaultClientConditions } from 'vite';
|
|
9
8
|
import { getPlatformProxy } from 'wrangler';
|
|
@@ -27,7 +26,9 @@ function setProcessEnv(config, env) {
|
|
|
27
26
|
}
|
|
28
27
|
export default function createIntegration(args) {
|
|
29
28
|
let _config;
|
|
29
|
+
let finalBuildOutput;
|
|
30
30
|
const cloudflareModulePlugin = cloudflareModuleLoader(args?.cloudflareModules ?? true);
|
|
31
|
+
let _routes;
|
|
31
32
|
return {
|
|
32
33
|
name: '@astrojs/cloudflare',
|
|
33
34
|
hooks: {
|
|
@@ -56,7 +57,6 @@ export default function createIntegration(args) {
|
|
|
56
57
|
},
|
|
57
58
|
],
|
|
58
59
|
},
|
|
59
|
-
integrations: [astroWhen()],
|
|
60
60
|
image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger),
|
|
61
61
|
});
|
|
62
62
|
if (args?.platformProxy?.configPath) {
|
|
@@ -72,11 +72,15 @@ export default function createIntegration(args) {
|
|
|
72
72
|
order: 'pre',
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
|
+
'astro:routes:resolved': ({ routes }) => {
|
|
76
|
+
_routes = routes;
|
|
77
|
+
},
|
|
75
78
|
'astro:config:done': ({ setAdapter, config, buildOutput, logger }) => {
|
|
76
79
|
if (buildOutput === 'static') {
|
|
77
80
|
logger.warn('[@astrojs/cloudflare] This adapter is intended to be used with server rendered pages, which this project does not contain any of. As such, this adapter is unnecessary.');
|
|
78
81
|
}
|
|
79
82
|
_config = config;
|
|
83
|
+
finalBuildOutput = buildOutput;
|
|
80
84
|
setAdapter({
|
|
81
85
|
name: '@astrojs/cloudflare',
|
|
82
86
|
serverEntrypoint: '@astrojs/cloudflare/entrypoints/server.js',
|
|
@@ -90,8 +94,11 @@ export default function createIntegration(args) {
|
|
|
90
94
|
hybridOutput: 'stable',
|
|
91
95
|
staticOutput: 'unsupported',
|
|
92
96
|
i18nDomains: 'experimental',
|
|
93
|
-
sharpImageService:
|
|
94
|
-
|
|
97
|
+
sharpImageService: {
|
|
98
|
+
support: 'limited',
|
|
99
|
+
message: 'Cloudflare does not support sharp. You can use the `compile` image service to compile images at build time. It will not work for any on-demand rendered images.',
|
|
100
|
+
},
|
|
101
|
+
envGetSecret: 'stable',
|
|
95
102
|
},
|
|
96
103
|
});
|
|
97
104
|
},
|
|
@@ -145,23 +152,12 @@ export default function createIntegration(args) {
|
|
|
145
152
|
vite.ssr.resolve.conditions.push('workerd', 'worker');
|
|
146
153
|
vite.ssr.target = 'webworker';
|
|
147
154
|
vite.ssr.noExternal = true;
|
|
148
|
-
if (typeof _config.vite.ssr?.external === 'undefined')
|
|
149
|
-
vite.ssr.external = [];
|
|
150
|
-
if (typeof _config.vite.ssr?.external === 'boolean')
|
|
151
|
-
vite.ssr.external = _config.vite.ssr?.external;
|
|
152
|
-
if (Array.isArray(_config.vite.ssr?.external))
|
|
153
|
-
// `@astrojs/vue` sets `@vue/server-renderer` to external
|
|
154
|
-
// https://github.com/withastro/astro/blob/e648c5575a8774af739231cfa9fc27a32086aa5f/packages/integrations/vue/src/index.ts#L119
|
|
155
|
-
// the cloudflare adapter needs to get all dependencies inlined, we use `noExternal` for that, but any `external` config overrides that
|
|
156
|
-
// therefore we need to remove `@vue/server-renderer` from the external config again
|
|
157
|
-
vite.ssr.external = _config.vite.ssr?.external.filter((entry) => entry !== '@vue/server-renderer');
|
|
158
155
|
vite.build ||= {};
|
|
159
156
|
vite.build.rollupOptions ||= {};
|
|
160
157
|
vite.build.rollupOptions.output ||= {};
|
|
161
158
|
// @ts-expect-error
|
|
162
159
|
vite.build.rollupOptions.output.banner ||=
|
|
163
160
|
'globalThis.process ??= {}; globalThis.process.env ??= {};';
|
|
164
|
-
vite.build.rollupOptions.external = _config.vite.build?.rollupOptions?.external ?? [];
|
|
165
161
|
// Cloudflare env is only available per request. This isn't feasible for code that access env vars
|
|
166
162
|
// in a global way, so we shim their access as `process.env.*`. This is not the recommended way for users to access environment variables. But we'll add this for compatibility for chosen variables. Mainly to support `@astrojs/db`
|
|
167
163
|
vite.define = {
|
|
@@ -170,7 +166,7 @@ export default function createIntegration(args) {
|
|
|
170
166
|
};
|
|
171
167
|
}
|
|
172
168
|
},
|
|
173
|
-
'astro:build:done': async ({ pages,
|
|
169
|
+
'astro:build:done': async ({ pages, dir, logger, assets }) => {
|
|
174
170
|
await cloudflareModulePlugin.afterBuildCompleted(_config);
|
|
175
171
|
const PLATFORM_FILES = ['_headers', '_redirects', '_routes.json'];
|
|
176
172
|
if (_config.base !== '/') {
|
|
@@ -227,17 +223,16 @@ export default function createIntegration(args) {
|
|
|
227
223
|
routesExists = false;
|
|
228
224
|
}
|
|
229
225
|
if (!routesExists) {
|
|
230
|
-
await createRoutesFile(_config, logger,
|
|
231
|
-
}
|
|
232
|
-
const redirectRoutes = [];
|
|
233
|
-
for (const route of routes) {
|
|
234
|
-
if (route.type === 'redirect')
|
|
235
|
-
redirectRoutes.push([route, '']);
|
|
226
|
+
await createRoutesFile(_config, logger, _routes, pages, redirects, args?.routes?.extend?.include, args?.routes?.extend?.exclude);
|
|
236
227
|
}
|
|
237
228
|
const trueRedirects = createRedirectsFromAstroRoutes({
|
|
238
229
|
config: _config,
|
|
239
|
-
routeToDynamicTargetMap: new Map(Array.from(
|
|
230
|
+
routeToDynamicTargetMap: new Map(Array.from(_routes
|
|
231
|
+
.filter((route) => route.type === 'redirect')
|
|
232
|
+
.map((route) => [route, '']))),
|
|
240
233
|
dir,
|
|
234
|
+
buildOutput: finalBuildOutput,
|
|
235
|
+
assets,
|
|
241
236
|
});
|
|
242
237
|
if (!trueRedirects.empty()) {
|
|
243
238
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AstroConfig, AstroIntegrationLogger,
|
|
1
|
+
import type { AstroConfig, AstroIntegrationLogger, IntegrationResolvedRoute, RoutePart } from 'astro';
|
|
2
2
|
export declare function getParts(part: string): RoutePart[];
|
|
3
|
-
export declare function createRoutesFile(_config: AstroConfig, logger: AstroIntegrationLogger, routes:
|
|
3
|
+
export declare function createRoutesFile(_config: AstroConfig, logger: AstroIntegrationLogger, routes: IntegrationResolvedRoute[], pages: {
|
|
4
4
|
pathname: string;
|
|
5
|
-
}[], redirects:
|
|
5
|
+
}[], redirects: IntegrationResolvedRoute['segments'][], includeExtends: {
|
|
6
6
|
pattern: string;
|
|
7
7
|
}[] | undefined, excludeExtends: {
|
|
8
8
|
pattern: string;
|
|
@@ -162,16 +162,16 @@ export async function createRoutesFile(_config, logger, routes, pages, redirects
|
|
|
162
162
|
let hasPrerendered404 = false;
|
|
163
163
|
for (const route of routes) {
|
|
164
164
|
const convertedPath = segmentsToCfSyntax(route.segments, _config);
|
|
165
|
-
if (route.pathname === '/404' && route.
|
|
165
|
+
if (route.pathname === '/404' && route.isPrerendered === true)
|
|
166
166
|
hasPrerendered404 = true;
|
|
167
167
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
168
168
|
switch (route.type) {
|
|
169
169
|
case 'page':
|
|
170
|
-
if (route.
|
|
170
|
+
if (route.isPrerendered === false)
|
|
171
171
|
includePaths.push(convertedPath);
|
|
172
172
|
break;
|
|
173
173
|
case 'endpoint':
|
|
174
|
-
if (route.
|
|
174
|
+
if (route.isPrerendered === false)
|
|
175
175
|
includePaths.push(convertedPath);
|
|
176
176
|
else
|
|
177
177
|
excludePaths.push(convertedPath);
|
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.1
|
|
4
|
+
"version": "12.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -29,29 +29,28 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@astrojs/internal-helpers": "0.4.
|
|
33
|
-
"@astrojs/underscore-redirects": "^0.
|
|
34
|
-
"@cloudflare/workers-types": "^4.
|
|
35
|
-
"@inox-tools/astro-when": "^1.0.1",
|
|
32
|
+
"@astrojs/internal-helpers": "0.4.2",
|
|
33
|
+
"@astrojs/underscore-redirects": "^0.6.0",
|
|
34
|
+
"@cloudflare/workers-types": "^4.20250109.0",
|
|
36
35
|
"esbuild": "^0.24.0",
|
|
37
36
|
"estree-walker": "^3.0.3",
|
|
38
|
-
"magic-string": "^0.30.
|
|
39
|
-
"miniflare": "^3.
|
|
37
|
+
"magic-string": "^0.30.17",
|
|
38
|
+
"miniflare": "^3.20241230.1",
|
|
40
39
|
"tiny-glob": "^0.2.9",
|
|
41
|
-
"vite": "^6.0.
|
|
42
|
-
"wrangler": "^3.
|
|
40
|
+
"vite": "^6.0.7",
|
|
41
|
+
"wrangler": "^3.101.0"
|
|
43
42
|
},
|
|
44
43
|
"peerDependencies": {
|
|
45
44
|
"astro": "^5.0.0"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"astro": "^5.
|
|
47
|
+
"astro": "^5.1.6",
|
|
49
48
|
"cheerio": "1.0.0",
|
|
50
49
|
"execa": "^8.0.1",
|
|
51
|
-
"fast-glob": "^3.3.
|
|
52
|
-
"rollup": "^4.
|
|
50
|
+
"fast-glob": "^3.3.3",
|
|
51
|
+
"rollup": "^4.30.1",
|
|
53
52
|
"strip-ansi": "^7.1.0",
|
|
54
|
-
"@astrojs/test-utils": "0.0.
|
|
53
|
+
"@astrojs/test-utils": "0.0.2",
|
|
55
54
|
"astro-scripts": "0.0.14"
|
|
56
55
|
},
|
|
57
56
|
"publishConfig": {
|