@astrojs/cloudflare 10.3.0 → 10.4.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.
@@ -1,6 +1,7 @@
1
1
  import type { CacheStorage as CLOUDFLARE_CACHESTORAGE, Request as CLOUDFLARE_REQUEST, ExecutionContext } from '@cloudflare/workers-types';
2
2
  import type { SSRManifest } from 'astro';
3
3
  type Env = {
4
+ [key: string]: unknown;
4
5
  ASSETS: {
5
6
  fetch: (req: Request | string) => Promise<Response>;
6
7
  };
@@ -1,4 +1,5 @@
1
1
  import { App } from 'astro/app';
2
+ import { createGetEnv } from '../utils/env.js';
2
3
  export function createExports(manifest) {
3
4
  const app = new App(manifest);
4
5
  const fetch = async (request, env, context) => {
@@ -32,6 +33,9 @@ export function createExports(manifest) {
32
33
  },
33
34
  },
34
35
  };
36
+ // Won't throw if the virtual module is not available because it's not supported in
37
+ // the users's astro version or if astro:env is not enabled in the project
38
+ await import('astro/env/setup').then((mod) => mod.setGetEnv(createGetEnv(env))).catch(() => { });
35
39
  const response = await app.render(request, { routeData, locals });
36
40
  if (app.setCookieHeaders) {
37
41
  for (const setCookieHeader of app.setCookieHeaders(response)) {
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { walk } from 'estree-walker';
8
8
  import MagicString from 'magic-string';
9
9
  import { getPlatformProxy } from 'wrangler';
10
10
  import { cloudflareModuleLoader, } from './utils/cloudflare-module-loader.js';
11
+ import { createGetEnv } from './utils/env.js';
11
12
  import { createRoutesFile, getParts } from './utils/generate-routes-json.js';
12
13
  import { setImageConfig } from './utils/image-config.js';
13
14
  import { mutateDynamicPageImportsInPlace, mutatePageMapInPlace } from './utils/index.js';
@@ -107,6 +108,7 @@ export default function createIntegration(args) {
107
108
  isSharpCompatible: false,
108
109
  isSquooshCompatible: false,
109
110
  },
111
+ envGetSecret: 'experimental',
110
112
  },
111
113
  });
112
114
  },
@@ -117,6 +119,15 @@ export default function createIntegration(args) {
117
119
  experimentalJsonConfig: args.platformProxy.experimentalJsonConfig ?? false,
118
120
  persist: args.platformProxy.persist ?? true,
119
121
  });
122
+ const getEnv = createGetEnv(platformProxy.env);
123
+ if (_config.experimental.env?.schema) {
124
+ for (const key of Object.keys(_config.experimental.env.schema)) {
125
+ const value = getEnv(key);
126
+ if (value !== undefined) {
127
+ process.env[key] = value;
128
+ }
129
+ }
130
+ }
120
131
  const clientLocalsSymbol = Symbol.for('astro.locals');
121
132
  server.middlewares.use(async function middleware(req, res, next) {
122
133
  Reflect.set(req, clientLocalsSymbol, {
@@ -0,0 +1,2 @@
1
+ import type { GetEnv } from 'astro/env/setup';
2
+ export declare const createGetEnv: (env: Record<string, unknown>) => GetEnv;
@@ -0,0 +1,11 @@
1
+ export const createGetEnv = (env) => (key) => {
2
+ const v = env[key];
3
+ if (typeof v === 'undefined' || typeof v === 'string') {
4
+ return v;
5
+ }
6
+ if (typeof v === 'boolean' || typeof v === 'number') {
7
+ // let astro:env handle the validation and transformation
8
+ return v.toString();
9
+ }
10
+ return undefined;
11
+ };
@@ -3,9 +3,9 @@ export declare function setImageConfig(service: string, config: AstroConfig['ima
3
3
  service: import("astro").ImageServiceConfig<Record<string, any>>;
4
4
  domains: string[];
5
5
  remotePatterns: {
6
+ port?: string | undefined;
6
7
  protocol?: string | undefined;
7
8
  hostname?: string | undefined;
8
- port?: string | undefined;
9
9
  pathname?: string | undefined;
10
10
  }[];
11
11
  endpoint?: string | undefined;
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
1
+ import type { PluginOption } from 'vite';
2
2
  /**
3
3
  * A Vite bundle analyzer that identifies chunks that are not used for server rendering.
4
4
  *
@@ -8,7 +8,7 @@ import type { Plugin } from 'vite';
8
8
  */
9
9
  export declare class NonServerChunkDetector {
10
10
  private nonServerChunks?;
11
- getPlugin(): Plugin;
11
+ getPlugin(): PluginOption;
12
12
  private processBundle;
13
13
  getNonServerChunks(): string[];
14
14
  }
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": "10.3.0",
4
+ "version": "10.4.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -42,13 +42,13 @@
42
42
  "astro": "^4.2.0"
43
43
  },
44
44
  "devDependencies": {
45
- "astro": "^4.5.8",
45
+ "astro": "^4.10.1",
46
46
  "cheerio": "1.0.0-rc.12",
47
47
  "execa": "^8.0.1",
48
48
  "fast-glob": "^3.3.2",
49
49
  "rollup": "^4.14.0",
50
50
  "strip-ansi": "^7.1.0",
51
- "vite": "^5.2.6",
51
+ "vite": "^5.2.12",
52
52
  "@astrojs/test-utils": "0.0.1",
53
53
  "astro-scripts": "0.0.14"
54
54
  },