@astrojs/cloudflare 6.8.0 → 7.0.0-beta.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.
package/README.md CHANGED
@@ -73,10 +73,12 @@ It's then possible to update the preview script in your `package.json` to `"prev
73
73
 
74
74
  ## Access to the Cloudflare runtime
75
75
 
76
- You can access all the Cloudflare bindings and environment variables from Astro components and API routes through `Astro.locals`.
76
+ You can access all the Cloudflare bindings and environment variables from Astro components and API routes through the adapter API.
77
77
 
78
78
  ```js
79
- const env = Astro.locals.runtime.env;
79
+ import { getRuntime } from '@astrojs/cloudflare/runtime';
80
+
81
+ getRuntime(Astro.request);
80
82
  ```
81
83
 
82
84
  Depending on your adapter mode (advanced = worker, directory = pages), the runtime object will look a little different due to differences in the Cloudflare API.
package/dist/index.js CHANGED
@@ -9,11 +9,31 @@ function getAdapter(isModeDirectory) {
9
9
  return isModeDirectory ? {
10
10
  name: "@astrojs/cloudflare",
11
11
  serverEntrypoint: "@astrojs/cloudflare/server.directory.js",
12
- exports: ["onRequest", "manifest"]
12
+ exports: ["onRequest", "manifest"],
13
+ supportedAstroFeatures: {
14
+ hybridOutput: "stable",
15
+ staticOutput: "unsupported",
16
+ serverOutput: "stable",
17
+ assets: {
18
+ supportKind: "unsupported",
19
+ isSharpCompatible: false,
20
+ isSquooshCompatible: false
21
+ }
22
+ }
13
23
  } : {
14
24
  name: "@astrojs/cloudflare",
15
25
  serverEntrypoint: "@astrojs/cloudflare/server.advanced.js",
16
- exports: ["default"]
26
+ exports: ["default"],
27
+ supportedAstroFeatures: {
28
+ hybridOutput: "stable",
29
+ staticOutput: "unsupported",
30
+ serverOutput: "stable",
31
+ assets: {
32
+ supportKind: "stable",
33
+ isSharpCompatible: false,
34
+ isSquooshCompatible: false
35
+ }
36
+ }
17
37
  };
18
38
  }
19
39
  const SHIM = `globalThis.process = {
@@ -25,7 +45,7 @@ const potentialFunctionRouteTypes = ["endpoint", "page"];
25
45
  function createIntegration(args) {
26
46
  let _config;
27
47
  let _buildConfig;
28
- const isModeDirectory = (args == null ? void 0 : args.mode) === "directory";
48
+ const isModeDirectory = args?.mode === "directory";
29
49
  let _entryPoints = /* @__PURE__ */ new Map();
30
50
  return {
31
51
  name: "@astrojs/cloudflare",
@@ -79,7 +99,6 @@ function createIntegration(args) {
79
99
  _entryPoints = entryPoints;
80
100
  },
81
101
  "astro:build:done": async ({ pages, routes, dir }) => {
82
- var _a, _b, _c, _d;
83
102
  const functionsUrl = new URL("functions/", _config.root);
84
103
  if (isModeDirectory) {
85
104
  await fs.promises.mkdir(functionsUrl, { recursive: true });
@@ -98,7 +117,7 @@ function createIntegration(args) {
98
117
  allowOverwrite: true,
99
118
  format: "esm",
100
119
  bundle: true,
101
- minify: ((_b = (_a = _config.vite) == null ? void 0 : _a.build) == null ? void 0 : _b.minify) !== false,
120
+ minify: _config.vite?.build?.minify !== false,
102
121
  banner: {
103
122
  js: SHIM
104
123
  },
@@ -144,7 +163,7 @@ function createIntegration(args) {
144
163
  allowOverwrite: true,
145
164
  format: "esm",
146
165
  bundle: true,
147
- minify: ((_d = (_c = _config.vite) == null ? void 0 : _c.build) == null ? void 0 : _d.minify) !== false,
166
+ minify: _config.vite?.build?.minify !== false,
148
167
  banner: {
149
168
  js: SHIM
150
169
  },
package/dist/runtime.d.ts CHANGED
@@ -22,14 +22,4 @@ export type PagesRuntime<T = unknown, U = unknown> = {
22
22
  };
23
23
  cf?: IncomingRequestCfProperties;
24
24
  };
25
- /**
26
- * @deprecated since version 6.8.0
27
- * The `getRuntime` utility has been deprecated and should be updated to the new [`Astro.locals`](https://docs.astro.build/en/guides/middleware/#locals) API.
28
- * ```diff
29
- * - import { getRuntime } from '@astrojs/cloudflare/runtime';
30
- * - getRuntime(Astro.request);
31
- *
32
- * + const runtime = Astro.locals.runtime;
33
- * ```
34
- */
35
25
  export declare function getRuntime<T = unknown, U = unknown>(request: Request): WorkerRuntime<T> | PagesRuntime<T, U>;
@@ -28,17 +28,7 @@ function createExports(manifest) {
28
28
  context.waitUntil(promise);
29
29
  }
30
30
  });
31
- const locals = {
32
- runtime: {
33
- waitUntil: (promise) => {
34
- context.waitUntil(promise);
35
- },
36
- env,
37
- cf: request.cf,
38
- caches
39
- }
40
- };
41
- let response = await app.render(request, routeData, locals);
31
+ let response = await app.render(request, routeData);
42
32
  if (app.setCookieHeaders) {
43
33
  for (const setCookieHeader of app.setCookieHeaders(response)) {
44
34
  response.headers.append("Set-Cookie", setCookieHeader);
@@ -1,6 +1,10 @@
1
- import type { EventContext } from '@cloudflare/workers-types';
1
+ import type { Request as CFRequest, EventContext } from '@cloudflare/workers-types';
2
2
  import type { SSRManifest } from 'astro';
3
3
  export declare function createExports(manifest: SSRManifest): {
4
- onRequest: (context: EventContext<unknown, string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
4
+ onRequest: ({ request, next, ...runtimeEnv }: {
5
+ request: Request & CFRequest;
6
+ next: (request: Request) => void;
7
+ waitUntil: EventContext<unknown, any, unknown>['waitUntil'];
8
+ } & Record<string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
5
9
  manifest: SSRManifest;
6
10
  };
@@ -5,13 +5,17 @@ if (!isNode) {
5
5
  }
6
6
  function createExports(manifest) {
7
7
  const app = new App(manifest);
8
- const onRequest = async (context) => {
9
- const request = context.request;
10
- const { next, env } = context;
11
- process.env = env;
8
+ const onRequest = async ({
9
+ request,
10
+ next,
11
+ ...runtimeEnv
12
+ }) => {
13
+ process.env = runtimeEnv.env;
12
14
  const { pathname } = new URL(request.url);
13
15
  if (manifest.assets.has(pathname)) {
14
- return env.ASSETS.fetch(request);
16
+ return runtimeEnv.env.ASSETS.fetch(
17
+ request
18
+ );
15
19
  }
16
20
  let routeData = app.match(request, { matchNotFound: true });
17
21
  if (routeData) {
@@ -21,26 +25,16 @@ function createExports(manifest) {
21
25
  request.headers.get("cf-connecting-ip")
22
26
  );
23
27
  Reflect.set(request, Symbol.for("runtime"), {
24
- ...context,
28
+ ...runtimeEnv,
25
29
  waitUntil: (promise) => {
26
- context.waitUntil(promise);
30
+ runtimeEnv.waitUntil(promise);
27
31
  },
28
32
  name: "cloudflare",
29
33
  next,
30
34
  caches,
31
35
  cf: request.cf
32
36
  });
33
- const locals = {
34
- runtime: {
35
- waitUntil: (promise) => {
36
- context.waitUntil(promise);
37
- },
38
- env: context.env,
39
- cf: request.cf,
40
- caches
41
- }
42
- };
43
- let response = await app.render(request, routeData, locals);
37
+ let response = await app.render(request, routeData);
44
38
  if (app.setCookieHeaders) {
45
39
  for (const setCookieHeader of app.setCookieHeaders(response)) {
46
40
  response.headers.append("Set-Cookie", setCookieHeader);
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": "6.8.0",
4
+ "version": "7.0.0-beta.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -32,20 +32,20 @@
32
32
  "runtime.d.ts"
33
33
  ],
34
34
  "dependencies": {
35
- "@astrojs/underscore-redirects": "^0.2.0",
36
35
  "@cloudflare/workers-types": "^4.20230518.0",
37
- "esbuild": "^0.17.19",
38
- "tiny-glob": "^0.2.9"
36
+ "esbuild": "^0.18.16",
37
+ "tiny-glob": "^0.2.9",
38
+ "@astrojs/underscore-redirects": "0.3.0-beta.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "astro": "^2.10.6"
41
+ "astro": "^3.0.0-beta.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "chai": "^4.3.7",
45
45
  "cheerio": "1.0.0-rc.12",
46
46
  "mocha": "^9.2.2",
47
47
  "wrangler": "^2.0.23",
48
- "astro": "2.10.6",
48
+ "astro": "3.0.0-beta.1",
49
49
  "astro-scripts": "0.0.14"
50
50
  },
51
51
  "scripts": {