@astrojs/cloudflare 13.0.0-alpha.2 → 13.0.0-alpha.3
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 +4 -12
- package/dist/index.js +16 -42
- package/dist/wrangler.js +3 -2
- package/package.json +2 -2
|
@@ -6,28 +6,20 @@ import { cloudflare as cfVitePlugin } from "@cloudflare/vite-plugin";
|
|
|
6
6
|
import colors from "piccolore";
|
|
7
7
|
import { performance } from "node:perf_hooks";
|
|
8
8
|
import { hasWranglerConfig, defaultCloudflareConfig } from "../wrangler.js";
|
|
9
|
-
import { copyFileSync, existsSync } from "node:fs";
|
|
10
9
|
const createPreviewServer = async ({
|
|
11
10
|
logger,
|
|
12
11
|
base,
|
|
13
|
-
|
|
12
|
+
server,
|
|
14
13
|
headers,
|
|
15
14
|
port,
|
|
16
15
|
host,
|
|
17
|
-
createCodegenDir,
|
|
18
16
|
root
|
|
19
17
|
}) => {
|
|
20
18
|
const startServerTime = performance.now();
|
|
21
19
|
let previewServer;
|
|
22
20
|
let cfPluginConfig = { viteEnvironment: { name: "ssr" } };
|
|
23
|
-
if (!hasWranglerConfig(
|
|
21
|
+
if (!hasWranglerConfig(server)) {
|
|
24
22
|
cfPluginConfig.config = defaultCloudflareConfig();
|
|
25
|
-
const codegenDir = createCodegenDir();
|
|
26
|
-
const devVarsPath = new URL(".dev.vars", outDir);
|
|
27
|
-
const devVarsCodegenPath = new URL(".dev.vars", codegenDir);
|
|
28
|
-
if (existsSync(devVarsPath)) {
|
|
29
|
-
copyFileSync(devVarsPath, devVarsCodegenPath);
|
|
30
|
-
}
|
|
31
23
|
}
|
|
32
24
|
try {
|
|
33
25
|
previewServer = await preview({
|
|
@@ -35,7 +27,7 @@ const createPreviewServer = async ({
|
|
|
35
27
|
base,
|
|
36
28
|
appType: "mpa",
|
|
37
29
|
build: {
|
|
38
|
-
outDir: fileURLToPath(
|
|
30
|
+
outDir: fileURLToPath(server)
|
|
39
31
|
},
|
|
40
32
|
root: fileURLToPath(root),
|
|
41
33
|
preview: {
|
|
@@ -91,7 +83,7 @@ function serverStart({
|
|
|
91
83
|
host,
|
|
92
84
|
base
|
|
93
85
|
}) {
|
|
94
|
-
const version = "13.0.0-alpha.
|
|
86
|
+
const version = "13.0.0-alpha.3";
|
|
95
87
|
const localPrefix = `${colors.dim("\u2503")} Local `;
|
|
96
88
|
const networkPrefix = `${colors.dim("\u2503")} Network `;
|
|
97
89
|
const emptyPrefix = " ".repeat(11);
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { createReadStream,
|
|
1
|
+
import { createReadStream, existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { appendFile, stat } from "node:fs/promises";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { createInterface } from "node:readline/promises";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
|
-
import {
|
|
7
|
-
appendForwardSlash,
|
|
8
|
-
prependForwardSlash,
|
|
9
|
-
removeLeadingForwardSlash
|
|
10
|
-
} from "@astrojs/internal-helpers/path";
|
|
6
|
+
import { removeLeadingForwardSlash } from "@astrojs/internal-helpers/path";
|
|
11
7
|
import { createRedirectsFromAstroRoutes, printAsRedirects } from "@astrojs/underscore-redirects";
|
|
12
8
|
import { cloudflare as cfVitePlugin } from "@cloudflare/vite-plugin";
|
|
13
9
|
import { cloudflareModuleLoader } from "./utils/cloudflare-module-loader.js";
|
|
@@ -16,9 +12,7 @@ import { setImageConfig } from "./utils/image-config.js";
|
|
|
16
12
|
import { createConfigPlugin } from "./vite-plugin-config.js";
|
|
17
13
|
import { hasWranglerConfig, defaultCloudflareConfig } from "./wrangler.js";
|
|
18
14
|
import { parse } from "dotenv";
|
|
19
|
-
|
|
20
|
-
return prependForwardSlash(appendForwardSlash(path));
|
|
21
|
-
}
|
|
15
|
+
import { sessionDrivers } from "astro/config";
|
|
22
16
|
function createIntegration(args) {
|
|
23
17
|
let _config;
|
|
24
18
|
let finalBuildOutput;
|
|
@@ -30,53 +24,33 @@ function createIntegration(args) {
|
|
|
30
24
|
return {
|
|
31
25
|
name: "@astrojs/cloudflare",
|
|
32
26
|
hooks: {
|
|
33
|
-
"astro:config:setup": ({
|
|
34
|
-
command,
|
|
35
|
-
config,
|
|
36
|
-
updateConfig,
|
|
37
|
-
logger,
|
|
38
|
-
addWatchFile,
|
|
39
|
-
createCodegenDir
|
|
40
|
-
}) => {
|
|
27
|
+
"astro:config:setup": ({ command, config, updateConfig, logger, addWatchFile }) => {
|
|
41
28
|
let session = config.session;
|
|
42
29
|
if (args?.imageService === "cloudflare-binding") {
|
|
43
30
|
const bindingName = args?.imagesBindingName ?? "IMAGES";
|
|
44
31
|
logger.info(
|
|
45
32
|
`Enabling image processing with Cloudflare Images for production with the "${bindingName}" Images binding.`
|
|
46
33
|
);
|
|
47
|
-
logger.info(
|
|
48
|
-
`If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`
|
|
49
|
-
);
|
|
50
34
|
}
|
|
51
35
|
if (!session?.driver) {
|
|
52
36
|
logger.info(
|
|
53
37
|
`Enabling sessions with Cloudflare KV with the "${SESSION_KV_BINDING_NAME}" KV binding.`
|
|
54
38
|
);
|
|
55
|
-
logger.info(
|
|
56
|
-
`If you see the error "Invalid binding \`${SESSION_KV_BINDING_NAME}\`" in your build output, you need to add the binding to your wrangler config file.`
|
|
57
|
-
);
|
|
58
39
|
session = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
40
|
+
driver: sessionDrivers.cloudflareKVBinding({
|
|
41
|
+
binding: SESSION_KV_BINDING_NAME
|
|
42
|
+
}),
|
|
43
|
+
cookie: session?.cookie,
|
|
44
|
+
ttl: session?.ttl
|
|
65
45
|
};
|
|
66
46
|
}
|
|
67
47
|
const cfPluginConfig = { viteEnvironment: { name: "ssr" } };
|
|
68
48
|
if (!hasWranglerConfig(config.root)) {
|
|
69
49
|
cfPluginConfig.config = defaultCloudflareConfig();
|
|
70
|
-
const codegenDir = createCodegenDir();
|
|
71
|
-
const devVarsPath = new URL(".dev.vars", config.root);
|
|
72
|
-
const devVarsCodegenPath = new URL(".dev.vars", codegenDir);
|
|
73
|
-
if (existsSync(devVarsPath)) {
|
|
74
|
-
copyFileSync(devVarsPath, devVarsCodegenPath);
|
|
75
|
-
}
|
|
76
50
|
}
|
|
77
51
|
updateConfig({
|
|
78
52
|
build: {
|
|
79
|
-
client: new URL(
|
|
53
|
+
client: new URL(`./client/`, config.outDir),
|
|
80
54
|
server: new URL("./_worker.js/", config.outDir),
|
|
81
55
|
serverEntry: "index.js",
|
|
82
56
|
redirects: false
|
|
@@ -122,6 +96,7 @@ function createIntegration(args) {
|
|
|
122
96
|
"astro > es-module-lexer",
|
|
123
97
|
"astro > unstorage",
|
|
124
98
|
"astro > neotraverse/modern",
|
|
99
|
+
"astro > piccolore",
|
|
125
100
|
"astro/app",
|
|
126
101
|
"astro/compiler-runtime"
|
|
127
102
|
],
|
|
@@ -136,8 +111,7 @@ function createIntegration(args) {
|
|
|
136
111
|
} else if (environmentName === "client") {
|
|
137
112
|
return {
|
|
138
113
|
optimizeDeps: {
|
|
139
|
-
include: ["astro/runtime/client/dev-toolbar/entrypoint.js"]
|
|
140
|
-
exclude: ["astro:*"]
|
|
114
|
+
include: ["astro/runtime/client/dev-toolbar/entrypoint.js"]
|
|
141
115
|
}
|
|
142
116
|
};
|
|
143
117
|
}
|
|
@@ -244,7 +218,7 @@ function createIntegration(args) {
|
|
|
244
218
|
"astro:build:done": async ({ pages, dir, logger, assets }) => {
|
|
245
219
|
let redirectsExists = false;
|
|
246
220
|
try {
|
|
247
|
-
const redirectsStat = await stat(new URL("./_redirects", _config.
|
|
221
|
+
const redirectsStat = await stat(new URL("./_redirects", _config.build.client));
|
|
248
222
|
if (redirectsStat.isFile()) {
|
|
249
223
|
redirectsExists = true;
|
|
250
224
|
}
|
|
@@ -254,7 +228,7 @@ function createIntegration(args) {
|
|
|
254
228
|
const redirects = [];
|
|
255
229
|
if (redirectsExists) {
|
|
256
230
|
const rl = createInterface({
|
|
257
|
-
input: createReadStream(new URL("./_redirects", _config.
|
|
231
|
+
input: createReadStream(new URL("./_redirects", _config.build.client)),
|
|
258
232
|
crlfDelay: Number.POSITIVE_INFINITY
|
|
259
233
|
});
|
|
260
234
|
for await (const line of rl) {
|
|
@@ -270,7 +244,7 @@ function createIntegration(args) {
|
|
|
270
244
|
}
|
|
271
245
|
let routesExists = false;
|
|
272
246
|
try {
|
|
273
|
-
const routesStat = await stat(new URL("./_routes.json", _config.
|
|
247
|
+
const routesStat = await stat(new URL("./_routes.json", _config.build.client));
|
|
274
248
|
if (routesStat.isFile()) {
|
|
275
249
|
routesExists = true;
|
|
276
250
|
}
|
|
@@ -302,7 +276,7 @@ function createIntegration(args) {
|
|
|
302
276
|
if (!trueRedirects.empty()) {
|
|
303
277
|
try {
|
|
304
278
|
await appendFile(
|
|
305
|
-
new URL("./_redirects", _config.
|
|
279
|
+
new URL("./_redirects", _config.build.client),
|
|
306
280
|
printAsRedirects(trueRedirects)
|
|
307
281
|
);
|
|
308
282
|
} catch (_error) {
|
package/dist/wrangler.js
CHANGED
|
@@ -7,6 +7,7 @@ function defaultCloudflareConfig() {
|
|
|
7
7
|
// TODO: better way to handle name, maybe package.json#name ?
|
|
8
8
|
name: "test-application",
|
|
9
9
|
compatibility_date: "2025-05-21",
|
|
10
|
+
compatibility_flags: ["global_fetch_strictly_public"],
|
|
10
11
|
main: "@astrojs/cloudflare/entrypoints/server",
|
|
11
12
|
assets: {
|
|
12
13
|
directory: "./dist",
|
|
@@ -17,8 +18,8 @@ function defaultCloudflareConfig() {
|
|
|
17
18
|
},
|
|
18
19
|
kv_namespaces: [
|
|
19
20
|
{
|
|
20
|
-
binding: "SESSION"
|
|
21
|
-
|
|
21
|
+
binding: "SESSION"
|
|
22
|
+
// KV with no binding gets automatically created
|
|
22
23
|
}
|
|
23
24
|
]
|
|
24
25
|
};
|
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-alpha.
|
|
4
|
+
"version": "13.0.0-alpha.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"cheerio": "1.1.2",
|
|
52
52
|
"devalue": "^5.5.0",
|
|
53
53
|
"rollup": "^4.53.3",
|
|
54
|
-
"astro": "6.0.0-alpha.
|
|
54
|
+
"astro": "6.0.0-alpha.3",
|
|
55
55
|
"astro-scripts": "0.0.14"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|