@astrojs/cloudflare 7.1.0 → 7.2.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/README.md +37 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -0
- package/dist/server.advanced.d.ts +2 -3
- package/dist/server.directory.d.ts +2 -2
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -115,8 +115,12 @@ If you're using the `advanced` runtime, you can type the `runtime` object as fol
|
|
|
115
115
|
/// <reference types="astro/client" />
|
|
116
116
|
import type { AdvancedRuntime } from '@astrojs/cloudflare';
|
|
117
117
|
|
|
118
|
+
type ENV = {
|
|
119
|
+
SERVER_URL: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
118
122
|
declare namespace App {
|
|
119
|
-
interface Locals extends AdvancedRuntime {
|
|
123
|
+
interface Locals extends AdvancedRuntime<ENV> {
|
|
120
124
|
user: {
|
|
121
125
|
name: string;
|
|
122
126
|
surname: string;
|
|
@@ -132,8 +136,12 @@ If you're using the `directory` runtime, you can type the `runtime` object as fo
|
|
|
132
136
|
/// <reference types="astro/client" />
|
|
133
137
|
import type { DirectoryRuntime } from '@astrojs/cloudflare';
|
|
134
138
|
|
|
139
|
+
type ENV = {
|
|
140
|
+
SERVER_URL: string;
|
|
141
|
+
};
|
|
142
|
+
|
|
135
143
|
declare namespace App {
|
|
136
|
-
interface Locals extends DirectoryRuntime {
|
|
144
|
+
interface Locals extends DirectoryRuntime<ENV> {
|
|
137
145
|
user: {
|
|
138
146
|
name: string;
|
|
139
147
|
surname: string;
|
|
@@ -194,6 +202,33 @@ This will enable Cloudflare to serve files and process static redirects without
|
|
|
194
202
|
|
|
195
203
|
See [Cloudflare's documentation](https://developers.cloudflare.com/pages/platform/functions/routing/#create-a-_routesjson-file) for more details.
|
|
196
204
|
|
|
205
|
+
## Node.js compatibility
|
|
206
|
+
|
|
207
|
+
Astro's Cloudflare adapter allows you to use any Node.js runtime API supported by Cloudflare:
|
|
208
|
+
|
|
209
|
+
- assert
|
|
210
|
+
- AsyncLocalStorage
|
|
211
|
+
- Buffer
|
|
212
|
+
- Diagnostics Channel
|
|
213
|
+
- EventEmitter
|
|
214
|
+
- path
|
|
215
|
+
- process
|
|
216
|
+
- Streams
|
|
217
|
+
- StringDecoder
|
|
218
|
+
- util
|
|
219
|
+
|
|
220
|
+
To use these APIs, your page or endpoint must be server-side rendered (not pre-rendered) and must use the the `import {} from 'node:*'` import syntax.
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
// pages/api/endpoint.js
|
|
224
|
+
export const prerender = false;
|
|
225
|
+
import { Buffer } from 'node:buffer';
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Additionally, you'll need to enable the Compatibility Flag in Cloudflare. The configuration for this flag may vary based on where you deploy your Astro site.
|
|
229
|
+
|
|
230
|
+
For detailed guidance, please refer to the [Cloudflare documentation](https://developers.cloudflare.com/workers/runtime-apis/nodejs).
|
|
231
|
+
|
|
197
232
|
## Troubleshooting
|
|
198
233
|
|
|
199
234
|
For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help!
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AstroAdapter, AstroIntegration } from 'astro';
|
|
2
|
-
export type { AdvancedRuntime } from './server.advanced';
|
|
3
|
-
export type { DirectoryRuntime } from './server.directory';
|
|
2
|
+
export type { AdvancedRuntime } from './server.advanced.js';
|
|
3
|
+
export type { DirectoryRuntime } from './server.directory.js';
|
|
4
4
|
type Options = {
|
|
5
5
|
mode?: 'directory' | 'advanced';
|
|
6
6
|
functionPerRoute?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -241,6 +241,18 @@ function createIntegration(args) {
|
|
|
241
241
|
target: "es2020",
|
|
242
242
|
platform: "browser",
|
|
243
243
|
conditions: ["workerd", "worker", "browser"],
|
|
244
|
+
external: [
|
|
245
|
+
"node:assert",
|
|
246
|
+
"node:async_hooks",
|
|
247
|
+
"node:buffer",
|
|
248
|
+
"node:diagnostics_channel",
|
|
249
|
+
"node:events",
|
|
250
|
+
"node:path",
|
|
251
|
+
"node:process",
|
|
252
|
+
"node:stream",
|
|
253
|
+
"node:string_decoder",
|
|
254
|
+
"node:util"
|
|
255
|
+
],
|
|
244
256
|
entryPoints: entryPaths,
|
|
245
257
|
outdir: outputDir,
|
|
246
258
|
allowOverwrite: true,
|
|
@@ -287,6 +299,18 @@ function createIntegration(args) {
|
|
|
287
299
|
target: "es2020",
|
|
288
300
|
platform: "browser",
|
|
289
301
|
conditions: ["workerd", "worker", "browser"],
|
|
302
|
+
external: [
|
|
303
|
+
"node:assert",
|
|
304
|
+
"node:async_hooks",
|
|
305
|
+
"node:buffer",
|
|
306
|
+
"node:diagnostics_channel",
|
|
307
|
+
"node:events",
|
|
308
|
+
"node:path",
|
|
309
|
+
"node:process",
|
|
310
|
+
"node:stream",
|
|
311
|
+
"node:string_decoder",
|
|
312
|
+
"node:util"
|
|
313
|
+
],
|
|
290
314
|
entryPoints: [entryPath],
|
|
291
315
|
outfile: buildPath,
|
|
292
316
|
allowOverwrite: true,
|
|
@@ -4,12 +4,11 @@ type Env = {
|
|
|
4
4
|
ASSETS: {
|
|
5
5
|
fetch: (req: Request) => Promise<Response>;
|
|
6
6
|
};
|
|
7
|
-
name: string;
|
|
8
7
|
};
|
|
9
|
-
export interface AdvancedRuntime {
|
|
8
|
+
export interface AdvancedRuntime<T extends object = object> {
|
|
10
9
|
runtime: {
|
|
11
10
|
waitUntil: (promise: Promise<any>) => void;
|
|
12
|
-
env: Env;
|
|
11
|
+
env: Env & T;
|
|
13
12
|
cf: CFRequest['cf'];
|
|
14
13
|
caches: typeof caches;
|
|
15
14
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Request as CFRequest, EventContext } from '@cloudflare/workers-types';
|
|
2
2
|
import type { SSRManifest } from 'astro';
|
|
3
|
-
export interface DirectoryRuntime {
|
|
3
|
+
export interface DirectoryRuntime<T extends object = object> {
|
|
4
4
|
runtime: {
|
|
5
5
|
waitUntil: (promise: Promise<any>) => void;
|
|
6
|
-
env: EventContext<unknown, string, unknown>['env'];
|
|
6
|
+
env: EventContext<unknown, string, unknown>['env'] & T;
|
|
7
7
|
cf: CFRequest['cf'];
|
|
8
8
|
caches: typeof caches;
|
|
9
9
|
};
|
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": "7.
|
|
4
|
+
"version": "7.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -33,26 +33,27 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@cloudflare/workers-types": "^4.20230821.0",
|
|
36
|
-
"esbuild": "^0.19.2",
|
|
37
|
-
"tiny-glob": "^0.2.9",
|
|
38
|
-
"find-up": "^6.3.0",
|
|
39
36
|
"@iarna/toml": "^2.2.5",
|
|
40
|
-
"dotenv": "^16.3.1",
|
|
41
37
|
"@miniflare/cache": "^2.14.1",
|
|
42
38
|
"@miniflare/shared": "^2.14.1",
|
|
43
39
|
"@miniflare/storage-memory": "^2.14.1",
|
|
40
|
+
"dotenv": "^16.3.1",
|
|
41
|
+
"esbuild": "^0.19.2",
|
|
42
|
+
"find-up": "^6.3.0",
|
|
43
|
+
"tiny-glob": "^0.2.9",
|
|
44
44
|
"@astrojs/underscore-redirects": "0.3.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"astro": "^3.
|
|
47
|
+
"astro": "^3.1.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@types/iarna__toml": "^2.0.2",
|
|
50
51
|
"chai": "^4.3.7",
|
|
51
52
|
"cheerio": "1.0.0-rc.12",
|
|
52
53
|
"kill-port": "^2.0.1",
|
|
53
54
|
"mocha": "^10.2.0",
|
|
54
55
|
"wrangler": "^3.5.1",
|
|
55
|
-
"astro": "3.
|
|
56
|
+
"astro": "3.1.2",
|
|
56
57
|
"astro-scripts": "0.0.14"
|
|
57
58
|
},
|
|
58
59
|
"scripts": {
|