* Detects if the project is a Cloudflare Pages project by checking for * `pages_build_output_dir` in the wrangler configuration file. * * Cloudflare Pages projects use `pages_build_output_dir` while Workers projects * use `assets.directory` or `main` fields instead.
()
| 267 | * use `assets.directory` or `main` fields instead. |
| 268 | */ |
| 269 | function isCloudflarePages(): boolean { |
| 270 | const cwd = process.cwd(); |
| 271 | const configFiles = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml']; |
| 272 | |
| 273 | for (const configFile of configFiles) { |
| 274 | const configPath = path.join(cwd, configFile); |
| 275 | |
| 276 | if (!fs.existsSync(configPath)) { |
| 277 | continue; |
| 278 | } |
| 279 | |
| 280 | const content = fs.readFileSync(configPath, 'utf-8'); |
| 281 | |
| 282 | if (configFile.endsWith('.toml')) { |
| 283 | // https://regex101.com/r/Uxe4p0/1 |
| 284 | // Match pages_build_output_dir as a TOML key (at start of line, ignoring whitespace) |
| 285 | // This avoids false positives from comments (lines starting with #) |
| 286 | return /^\s*pages_build_output_dir\s*=/m.test(content); |
| 287 | } |
| 288 | |
| 289 | // Match "pages_build_output_dir" as a JSON key (followed by :) |
| 290 | // This works for both .json and .jsonc without needing to strip comments |
| 291 | return /"pages_build_output_dir"\s*:/.test(content); |
| 292 | } |
| 293 | |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | function getSourcemapsAssetsGlob(config: AstroConfig): string { |
| 298 | // The vercel adapter puts the output into its .vercel directory |