@astrojs/cloudflare 12.6.2 → 12.6.4

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.
Files changed (2) hide show
  1. package/dist/index.js +14 -26
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { createReadStream } 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
- import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { pathToFileURL } from "node:url";
6
6
  import {
7
7
  appendForwardSlash,
8
8
  prependForwardSlash,
@@ -39,6 +39,7 @@ function createIntegration(args) {
39
39
  args?.cloudflareModules ?? true
40
40
  );
41
41
  let _routes;
42
+ const SESSION_KV_BINDING_NAME = args?.sessionKVBindingName ?? "SESSION";
42
43
  return {
43
44
  name: "@astrojs/cloudflare",
44
45
  hooks: {
@@ -48,34 +49,21 @@ function createIntegration(args) {
48
49
  updateConfig,
49
50
  logger,
50
51
  addWatchFile,
51
- addMiddleware,
52
- createCodegenDir
52
+ addMiddleware
53
53
  }) => {
54
54
  let session = config.session;
55
- const isBuild = command === "build";
56
55
  if (!session?.driver) {
57
- const sessionDir = isBuild ? void 0 : createCodegenDir();
58
- const bindingName = args?.sessionKVBindingName ?? "SESSION";
59
- if (isBuild) {
60
- logger.info(
61
- `Enabling sessions with Cloudflare KV for production with the "${bindingName}" KV binding.`
62
- );
63
- logger.info(
64
- `If you see the error "Invalid binding \`${bindingName}\`" in your build output, you need to add the binding to your wrangler config file.`
65
- );
66
- }
67
- session = isBuild ? {
56
+ logger.info(
57
+ `Enabling sessions with Cloudflare KV with the "${SESSION_KV_BINDING_NAME}" KV binding.`
58
+ );
59
+ logger.info(
60
+ `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.`
61
+ );
62
+ session = {
68
63
  ...session,
69
64
  driver: "cloudflare-kv-binding",
70
65
  options: {
71
- binding: bindingName,
72
- ...session?.options
73
- }
74
- } : {
75
- ...session,
76
- driver: "fs-lite",
77
- options: {
78
- base: fileURLToPath(new URL("sessions", sessionDir)),
66
+ binding: SESSION_KV_BINDING_NAME,
79
67
  ...session?.options
80
68
  }
81
69
  };
@@ -170,6 +158,8 @@ function createIntegration(args) {
170
158
  await platformProxy.dispose();
171
159
  });
172
160
  setProcessEnv(_config, platformProxy.env);
161
+ globalThis.__env__ ??= {};
162
+ globalThis.__env__[SESSION_KV_BINDING_NAME] = platformProxy.env[SESSION_KV_BINDING_NAME];
173
163
  const clientLocalsSymbol = Symbol.for("astro.locals");
174
164
  server.middlewares.use(async function middleware(req, _res, next) {
175
165
  Reflect.set(req, clientLocalsSymbol, {
@@ -222,9 +212,7 @@ function createIntegration(args) {
222
212
  vite.define = {
223
213
  "process.env": "process.env",
224
214
  // Allows the request handler to know what the binding name is
225
- "globalThis.__ASTRO_SESSION_BINDING_NAME": JSON.stringify(
226
- args?.sessionKVBindingName ?? "SESSION"
227
- ),
215
+ "globalThis.__ASTRO_SESSION_BINDING_NAME": JSON.stringify(SESSION_KV_BINDING_NAME),
228
216
  ...vite.define
229
217
  };
230
218
  }
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.6.2",
4
+ "version": "12.6.4",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -34,7 +34,7 @@
34
34
  "tinyglobby": "^0.2.13",
35
35
  "vite": "^6.3.5",
36
36
  "wrangler": "^4.14.1",
37
- "@astrojs/internal-helpers": "0.7.1",
37
+ "@astrojs/internal-helpers": "0.7.2",
38
38
  "@astrojs/underscore-redirects": "1.0.0"
39
39
  },
40
40
  "peerDependencies": {
@@ -45,7 +45,7 @@
45
45
  "devalue": "^5.1.1",
46
46
  "execa": "^8.0.1",
47
47
  "rollup": "^4.40.2",
48
- "astro": "5.12.8",
48
+ "astro": "5.13.2",
49
49
  "astro-scripts": "0.0.14"
50
50
  },
51
51
  "publishConfig": {