@astrojs/cloudflare 13.0.0-alpha.3 → 13.0.0-beta.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/entrypoints/preview.js +6 -6
- package/dist/index.d.ts +10 -32
- package/dist/index.js +18 -11
- package/dist/utils/handler.js +36 -1
- package/dist/wrangler.d.ts +11 -7
- package/dist/wrangler.js +29 -25
- package/package.json +8 -8
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { cloudflare as cfVitePlugin } from "@cloudflare/vite-plugin";
|
|
6
6
|
import colors from "piccolore";
|
|
7
7
|
import { performance } from "node:perf_hooks";
|
|
8
|
-
import {
|
|
8
|
+
import { cloudflareConfigCustomizer } from "../wrangler.js";
|
|
9
9
|
const createPreviewServer = async ({
|
|
10
10
|
logger,
|
|
11
11
|
base,
|
|
@@ -17,10 +17,10 @@ const createPreviewServer = async ({
|
|
|
17
17
|
}) => {
|
|
18
18
|
const startServerTime = performance.now();
|
|
19
19
|
let previewServer;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
20
|
+
const cfPluginConfig = {
|
|
21
|
+
viteEnvironment: { name: "ssr" },
|
|
22
|
+
config: cloudflareConfigCustomizer()
|
|
23
|
+
};
|
|
24
24
|
try {
|
|
25
25
|
previewServer = await preview({
|
|
26
26
|
configFile: false,
|
|
@@ -83,7 +83,7 @@ function serverStart({
|
|
|
83
83
|
host,
|
|
84
84
|
base
|
|
85
85
|
}) {
|
|
86
|
-
const version = "13.0.0-
|
|
86
|
+
const version = "13.0.0-beta.0";
|
|
87
87
|
const localPrefix = `${colors.dim("\u2503")} Local `;
|
|
88
88
|
const networkPrefix = `${colors.dim("\u2503")} Network `;
|
|
89
89
|
const emptyPrefix = " ".repeat(11);
|
package/dist/index.d.ts
CHANGED
|
@@ -37,45 +37,23 @@ export type Options = {
|
|
|
37
37
|
*/
|
|
38
38
|
cloudflareModules?: boolean;
|
|
39
39
|
/**
|
|
40
|
-
* By default, Astro will be configured to use Cloudflare KV to store session data.
|
|
41
|
-
*
|
|
40
|
+
* By default, Astro will be configured to use Cloudflare KV to store session data. The KV namespace
|
|
41
|
+
* will be automatically provisioned when you deploy.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* This will log the id of the created namespace. You can then add it to your `wrangler.json` file like this:
|
|
48
|
-
*
|
|
49
|
-
* ```json
|
|
50
|
-
* {
|
|
51
|
-
* "kv_namespaces": [
|
|
52
|
-
* {
|
|
53
|
-
* "binding": "SESSION",
|
|
54
|
-
* "id": "<your kv namespace id here>"
|
|
55
|
-
* }
|
|
56
|
-
* ]
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
* By default, the driver looks for the binding named `SESSION`, but you can override this by providing a different name here.
|
|
60
|
-
*
|
|
61
|
-
* See https://developers.cloudflare.com/kv/concepts/kv-namespaces/ for more details on using KV namespaces.
|
|
43
|
+
* By default, the binding is named `SESSION`, but you can override this by providing a different name here.
|
|
44
|
+
* If you define the binding manually in your wrangler config, Astro will use your configuration instead.
|
|
62
45
|
*
|
|
46
|
+
* See https://developers.cloudflare.com/workers/wrangler/configuration/#automatic-provisioning for more details.
|
|
63
47
|
*/
|
|
64
48
|
sessionKVBindingName?: string;
|
|
65
49
|
/**
|
|
66
|
-
* When
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* By default, this will use the "IMAGES" binding name, but this can be customised in your `wrangler.json`:
|
|
50
|
+
* When `imageService` is set to `cloudflare-binding`, the Cloudflare Images binding will be used
|
|
51
|
+
* to transform images. The binding will be automatically configured for you.
|
|
70
52
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* "images": {
|
|
74
|
-
* "binding": "IMAGES" // <-- this should match `imagesBindingName`
|
|
75
|
-
* }
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
53
|
+
* By default, the binding is named `IMAGES`, but you can override this by providing a different name here.
|
|
54
|
+
* If you define the binding manually in your wrangler config, Astro will use your configuration instead.
|
|
78
55
|
*
|
|
56
|
+
* See https://developers.cloudflare.com/images/transform-images/bindings/ for more details.
|
|
79
57
|
*/
|
|
80
58
|
imagesBindingName?: string;
|
|
81
59
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,11 @@ import { cloudflareModuleLoader } from "./utils/cloudflare-module-loader.js";
|
|
|
10
10
|
import { createRoutesFile, getParts } from "./utils/generate-routes-json.js";
|
|
11
11
|
import { setImageConfig } from "./utils/image-config.js";
|
|
12
12
|
import { createConfigPlugin } from "./vite-plugin-config.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
cloudflareConfigCustomizer,
|
|
15
|
+
DEFAULT_SESSION_KV_BINDING_NAME,
|
|
16
|
+
DEFAULT_IMAGES_BINDING_NAME
|
|
17
|
+
} from "./wrangler.js";
|
|
14
18
|
import { parse } from "dotenv";
|
|
15
19
|
import { sessionDrivers } from "astro/config";
|
|
16
20
|
function createIntegration(args) {
|
|
@@ -20,34 +24,37 @@ function createIntegration(args) {
|
|
|
20
24
|
args?.cloudflareModules ?? true
|
|
21
25
|
);
|
|
22
26
|
let _routes;
|
|
23
|
-
const
|
|
27
|
+
const sessionKVBindingName = args?.sessionKVBindingName ?? DEFAULT_SESSION_KV_BINDING_NAME;
|
|
28
|
+
const imagesBindingName = args?.imagesBindingName ?? DEFAULT_IMAGES_BINDING_NAME;
|
|
24
29
|
return {
|
|
25
30
|
name: "@astrojs/cloudflare",
|
|
26
31
|
hooks: {
|
|
27
32
|
"astro:config:setup": ({ command, config, updateConfig, logger, addWatchFile }) => {
|
|
28
33
|
let session = config.session;
|
|
29
34
|
if (args?.imageService === "cloudflare-binding") {
|
|
30
|
-
const bindingName = args?.imagesBindingName ?? "IMAGES";
|
|
31
35
|
logger.info(
|
|
32
|
-
`Enabling image processing with Cloudflare Images for production with the "${
|
|
36
|
+
`Enabling image processing with Cloudflare Images for production with the "${imagesBindingName}" Images binding.`
|
|
33
37
|
);
|
|
34
38
|
}
|
|
35
39
|
if (!session?.driver) {
|
|
36
40
|
logger.info(
|
|
37
|
-
`Enabling sessions with Cloudflare KV with the "${
|
|
41
|
+
`Enabling sessions with Cloudflare KV with the "${sessionKVBindingName}" KV binding.`
|
|
38
42
|
);
|
|
39
43
|
session = {
|
|
40
44
|
driver: sessionDrivers.cloudflareKVBinding({
|
|
41
|
-
binding:
|
|
45
|
+
binding: sessionKVBindingName
|
|
42
46
|
}),
|
|
43
47
|
cookie: session?.cookie,
|
|
44
48
|
ttl: session?.ttl
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
|
-
const cfPluginConfig = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const cfPluginConfig = {
|
|
52
|
+
viteEnvironment: { name: "ssr" },
|
|
53
|
+
config: cloudflareConfigCustomizer({
|
|
54
|
+
sessionKVBindingName: args?.sessionKVBindingName,
|
|
55
|
+
imagesBindingName: args?.imageService === "cloudflare-binding" ? args?.imagesBindingName : false
|
|
56
|
+
})
|
|
57
|
+
};
|
|
51
58
|
updateConfig({
|
|
52
59
|
build: {
|
|
53
60
|
client: new URL(`./client/`, config.outDir),
|
|
@@ -129,7 +136,7 @@ function createIntegration(args) {
|
|
|
129
136
|
}
|
|
130
137
|
},
|
|
131
138
|
createConfigPlugin({
|
|
132
|
-
sessionKVBindingName
|
|
139
|
+
sessionKVBindingName
|
|
133
140
|
})
|
|
134
141
|
]
|
|
135
142
|
},
|
package/dist/utils/handler.js
CHANGED
|
@@ -16,7 +16,17 @@ async function handle(request, env, context) {
|
|
|
16
16
|
if (app.manifest.assets.has(pathname)) {
|
|
17
17
|
return env.ASSETS.fetch(request.url.replace(/\.html$/, ""));
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
let routeData = void 0;
|
|
20
|
+
if (app.isDev()) {
|
|
21
|
+
const result = await app.devMatch(
|
|
22
|
+
app.getPathnameFromRequest(request)
|
|
23
|
+
);
|
|
24
|
+
if (result) {
|
|
25
|
+
routeData = result.routeData;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
routeData = app.match(request);
|
|
29
|
+
}
|
|
20
30
|
if (!routeData) {
|
|
21
31
|
const asset = await env.ASSETS.fetch(
|
|
22
32
|
request.url.replace(/index.html$/, "").replace(/\.html$/, "")
|
|
@@ -28,6 +38,31 @@ async function handle(request, env, context) {
|
|
|
28
38
|
const locals = {
|
|
29
39
|
cfContext: context
|
|
30
40
|
};
|
|
41
|
+
Object.defineProperty(locals, "runtime", {
|
|
42
|
+
enumerable: false,
|
|
43
|
+
value: {
|
|
44
|
+
get env() {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Astro.locals.runtime.env has been removed in Astro v6. Use 'import { env } from "cloudflare:workers"' instead.`
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
get cf() {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Astro.locals.runtime.cf has been removed in Astro v6. Use 'Astro.request.cf' instead.`
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
get caches() {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Astro.locals.runtime.caches has been removed in Astro v6. Use the global 'caches' object instead.`
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
get ctx() {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Astro.locals.runtime.ctx has been removed in Astro v6. Use 'Astro.locals.cfContext' instead.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
31
66
|
const response = await app.render(
|
|
32
67
|
request,
|
|
33
68
|
{
|
package/dist/wrangler.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { PluginConfig } from '@cloudflare/vite-plugin';
|
|
2
|
+
export declare const DEFAULT_SESSION_KV_BINDING_NAME = "SESSION";
|
|
3
|
+
export declare const DEFAULT_IMAGES_BINDING_NAME = "IMAGES";
|
|
4
|
+
export declare const DEFAULT_ASSETS_BINDING_NAME = "ASSETS";
|
|
5
|
+
interface CloudflareConfigOptions {
|
|
6
|
+
sessionKVBindingName?: string;
|
|
7
|
+
imagesBindingName?: string | false;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
10
|
+
* Returns a config customizer that sets up the Astro Cloudflare defaults.
|
|
11
|
+
* Sets the main entrypoint and adds bindings for auto-provisioning.
|
|
5
12
|
*/
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
* Returns the default wrangler configuration used by Astro Cloudflare configuration.
|
|
9
|
-
*/
|
|
10
|
-
export declare function defaultCloudflareConfig(): PluginConfig['config'];
|
|
13
|
+
export declare function cloudflareConfigCustomizer(options?: CloudflareConfigOptions): PluginConfig['config'];
|
|
14
|
+
export {};
|
package/dist/wrangler.js
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
assets
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{
|
|
21
|
-
binding:
|
|
22
|
-
|
|
1
|
+
const DEFAULT_SESSION_KV_BINDING_NAME = "SESSION";
|
|
2
|
+
const DEFAULT_IMAGES_BINDING_NAME = "IMAGES";
|
|
3
|
+
const DEFAULT_ASSETS_BINDING_NAME = "ASSETS";
|
|
4
|
+
function cloudflareConfigCustomizer(options) {
|
|
5
|
+
const sessionKVBindingName = options?.sessionKVBindingName ?? DEFAULT_SESSION_KV_BINDING_NAME;
|
|
6
|
+
const imagesBindingName = options?.imagesBindingName === false ? void 0 : options?.imagesBindingName ?? DEFAULT_IMAGES_BINDING_NAME;
|
|
7
|
+
return (config) => {
|
|
8
|
+
const hasSessionBinding = config.kv_namespaces?.some(
|
|
9
|
+
(kv) => kv.binding === sessionKVBindingName
|
|
10
|
+
);
|
|
11
|
+
const hasImagesBinding = config.images?.binding !== void 0;
|
|
12
|
+
const hasAssetsBinding = config.assets?.binding !== void 0;
|
|
13
|
+
return {
|
|
14
|
+
main: config.main ?? "@astrojs/cloudflare/entrypoints/server",
|
|
15
|
+
kv_namespaces: hasSessionBinding ? void 0 : [
|
|
16
|
+
{
|
|
17
|
+
binding: sessionKVBindingName
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
images: hasImagesBinding || !imagesBindingName ? void 0 : {
|
|
21
|
+
binding: imagesBindingName
|
|
22
|
+
},
|
|
23
|
+
assets: hasAssetsBinding ? void 0 : {
|
|
24
|
+
binding: DEFAULT_ASSETS_BINDING_NAME
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
};
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
29
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
DEFAULT_ASSETS_BINDING_NAME,
|
|
31
|
+
DEFAULT_IMAGES_BINDING_NAME,
|
|
32
|
+
DEFAULT_SESSION_KV_BINDING_NAME,
|
|
33
|
+
cloudflareConfigCustomizer
|
|
30
34
|
};
|
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": "13.0.0-
|
|
4
|
+
"version": "13.0.0-beta.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"piccolore": "^0.1.3",
|
|
41
41
|
"tinyglobby": "^0.2.15",
|
|
42
42
|
"vite": "^7.1.12",
|
|
43
|
-
"
|
|
44
|
-
"@astrojs/internal-helpers": "0.7.5"
|
|
45
|
-
"@astrojs/underscore-redirects": "1.0.0"
|
|
43
|
+
"@astrojs/underscore-redirects": "1.0.0",
|
|
44
|
+
"@astrojs/internal-helpers": "0.7.5"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
|
-
"astro": "^6.0.0-alpha.0"
|
|
47
|
+
"astro": "^6.0.0-alpha.0",
|
|
48
|
+
"wrangler": "^4.53.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"cheerio": "1.1.2",
|
|
52
|
-
"devalue": "^5.
|
|
53
|
-
"rollup": "^4.
|
|
54
|
-
"astro": "6.0.0-
|
|
52
|
+
"devalue": "^5.6.1",
|
|
53
|
+
"rollup": "^4.54.0",
|
|
54
|
+
"astro": "6.0.0-beta.0",
|
|
55
55
|
"astro-scripts": "0.0.14"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|