|
1 | 1 | import fsMod, { existsSync, promises as fs } from 'node:fs'; |
| 2 | +import { createRequire } from 'node:module'; |
2 | 3 | import path from 'node:path'; |
3 | 4 | import { fileURLToPath, pathToFileURL } from 'node:url'; |
4 | 5 | import boxen from 'boxen'; |
@@ -81,9 +82,9 @@ export default async function seed() { |
81 | 82 | // TODO |
82 | 83 | } |
83 | 84 | `, |
84 | | - CLOUDFLARE_WRANGLER_CONFIG: (name: string) => `\ |
| 85 | + CLOUDFLARE_WRANGLER_CONFIG: (name: string, compatibilityDate: string) => `\ |
85 | 86 | { |
86 | | - "compatibility_date": ${JSON.stringify(new Date().toISOString().slice(0, 10))}, |
| 87 | + "compatibility_date": ${JSON.stringify(compatibilityDate)}, |
87 | 88 | "compatibility_flags": ["global_fetch_strictly_public"], |
88 | 89 | "name": ${JSON.stringify(name)}, |
89 | 90 | "main": "@astrojs/cloudflare/entrypoints/server", |
@@ -217,10 +218,22 @@ export async function add(names: string[], { flags }: AddOptions) { |
217 | 218 |
|
218 | 219 | if (await askToContinue({ flags, logger })) { |
219 | 220 | const data = await getPackageJson(); |
| 221 | + let compatibilityDate: string; |
| 222 | + try { |
| 223 | + const require = createRequire(root); |
| 224 | + const { getLocalWorkerdCompatibilityDate } = await import( |
| 225 | + require.resolve('@astrojs/cloudflare/info') |
| 226 | + ); |
| 227 | + ({ date: compatibilityDate } = getLocalWorkerdCompatibilityDate({ |
| 228 | + projectPath: rootPath, |
| 229 | + })); |
| 230 | + } catch { |
| 231 | + compatibilityDate = new Date().toISOString().slice(0, 10); |
| 232 | + } |
220 | 233 |
|
221 | 234 | await fs.writeFile( |
222 | 235 | wranglerConfigURL, |
223 | | - STUBS.CLOUDFLARE_WRANGLER_CONFIG(data?.name ?? 'example'), |
| 236 | + STUBS.CLOUDFLARE_WRANGLER_CONFIG(data?.name ?? 'example', compatibilityDate), |
224 | 237 | 'utf-8', |
225 | 238 | ); |
226 | 239 | } |
|
0 commit comments