Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: withastro/adapters
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @astrojs/[email protected]
Choose a base ref
...
head repository: withastro/adapters
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Dec 3, 2024

  1. test: use Astro v5 and update cloudflare assertions (#460)

    * test: use Astro v5 and update cloudflare assertions
    
    * disable check origin
    
    * disable check origin
    
    * update test
    
    * fix another test
    
    * remove logging
    
    * format
    ematipico authored Dec 3, 2024
    Copy the full SHA
    3d94421 View commit details
  2. test(node): add image tests (#459)

    * chore(node): add image tests
    
    * Format
    
    * Format
    ascorbic authored Dec 3, 2024
    Copy the full SHA
    26976ad View commit details

Commits on Dec 4, 2024

  1. refactor: readability (#463)

    ematipico authored Dec 4, 2024
    Copy the full SHA
    2c36ee5 View commit details

Commits on Dec 5, 2024

  1. Fix cloudflare ssr conditions setup (#465)

    bluwy authored Dec 5, 2024
    Copy the full SHA
    70e0054 View commit details
  2. [ci] release (#466)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Dec 5, 2024
    Copy the full SHA
    8dc4ff1 View commit details
  3. fix(deps): update dependency @inox-tools/astro-when to v1 (#468)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Dec 5, 2024
    Copy the full SHA
    46a0157 View commit details
  4. fix(deps): update dependency @astrojs/solid-js to v5 (#467)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Dec 5, 2024
    Copy the full SHA
    f08b855 View commit details

Commits on Dec 6, 2024

  1. Add support for wrangler.jsonc (#455)

    meyer authored Dec 6, 2024
    Copy the full SHA
    1d4e6fc View commit details
  2. fix(vercel): add support for Node 22 (v8) (#472)

    Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
    Co-authored-by: Nick Rutten <2504906+nickrttn@users.noreply.github.com>
    3 people authored Dec 6, 2024
    Copy the full SHA
    d9eed7e View commit details

Commits on Dec 13, 2024

  1. fix: cloudflare resolve conditions (#476)

    bluwy authored Dec 13, 2024
    Copy the full SHA
    a8a8ab1 View commit details
  2. [ci] release (#473)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Dec 13, 2024
    Copy the full SHA
    e53c18d View commit details
  3. fix(netlify): don't directly assign locals (#481)

    ascorbic authored Dec 13, 2024
    Copy the full SHA
    9d98b8a View commit details

Commits on Dec 16, 2024

  1. fix: correctly pass locals from Netlify edge middleware (#488)

    * fix: correctly pass locals from Netlify edge middleware
    
    * Format
    
    * Remove console
    ascorbic authored Dec 16, 2024
    Copy the full SHA
    f3739be View commit details
  2. [ci] release (#482)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Dec 16, 2024
    Copy the full SHA
    f487c91 View commit details

Commits on Jan 7, 2025

  1. Copy the full SHA
    4b5cd22 View commit details
  2. fix(deps): update all non-major dependencies (#457)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    Co-authored-by: bluwy <bjornlu.dev@gmail.com>
    renovate[bot] and bluwy authored Jan 7, 2025
    Copy the full SHA
    d7e7d5e View commit details
  3. chore: update adapters to better support astro v5 (#454)

    Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
    alexanderniebuhr and florian-lefebvre authored Jan 7, 2025
    Copy the full SHA
    83cedad View commit details

Commits on Jan 13, 2025

  1. feat: upgrade underscore-redirects (#501)

    florian-lefebvre authored Jan 13, 2025
    Copy the full SHA
    012b31d View commit details
  2. [ci] release (#497)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jan 13, 2025
    Copy the full SHA
    76dc7a0 View commit details

Commits on Jan 14, 2025

  1. fix(deps): update all non-major dependencies (#503)

    renovate[bot] authored Jan 14, 2025
    Copy the full SHA
    7b352ee View commit details

Commits on Jan 17, 2025

  1. Remove internal vue handling in cloudflare integration (#506)

    bluwy authored Jan 17, 2025
    Copy the full SHA
    ce66003 View commit details

Commits on Jan 20, 2025

  1. fix(vercel): copy static assets after all integrations (#508)

    * fix(vercel): copy static assets after all integrations
    
    * Format
    
    * Fix logic
    
    * Format
    ascorbic authored Jan 20, 2025
    Copy the full SHA
    af69a12 View commit details

Commits on Jan 22, 2025

  1. fix: correctly handle wildcard hosts in preview (#514)

    ascorbic authored Jan 22, 2025
    Copy the full SHA
    ea4297b View commit details
  2. [ci] release (#507)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jan 22, 2025
    Copy the full SHA
    c61df56 View commit details

Commits on Jan 23, 2025

  1. fix(vercel): handle integration static assets in non-static sites (#516)

    * fix: arrange assets for server output too
    
    * Changeset
    
    * Format
    ascorbic authored Jan 23, 2025
    Copy the full SHA
    3fe04eb View commit details
  2. [ci] release (#517)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jan 23, 2025
    Copy the full SHA
    e52877f View commit details
  3. chore(node): add tests for preview host (#518)

    * Add tests
    
    * Format
    ascorbic authored Jan 23, 2025
    Copy the full SHA
    e4d41ce View commit details
  4. fix(vercel): update middleware esbuild settings (#519)

    * fix(vercel): update middleware esbuild settings
    
    * Update target
    ascorbic authored Jan 23, 2025
    Copy the full SHA
    641d7d5 View commit details

Commits on Jan 30, 2025

  1. fix: use vercel routing utils (#525)

    * fix: use vercel routing utils
    
    * changeset
    
    * log error
    
    * Format
    
    * Update changeset
    
    * Update tests
    
    * Changes from review
    
    * Format
    ascorbic authored Jan 30, 2025
    Copy the full SHA
    6ef9a6f View commit details
  2. [ci] release (#520)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jan 30, 2025
    Copy the full SHA
    991eea7 View commit details

Commits on Feb 6, 2025

  1. fix: pin @vercel/routing-utils (#528)

    ascorbic authored Feb 6, 2025
    Copy the full SHA
    5c2ea1f View commit details
  2. [ci] release (#529)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Feb 6, 2025
    Copy the full SHA
    3288446 View commit details

Commits on Feb 10, 2025

  1. chore: reword readme (#531)

    ematipico authored Feb 10, 2025
    Copy the full SHA
    80b402e View commit details
Showing with 4,460 additions and 1,473 deletions.
  1. +1 −0 .gitignore
  2. +6 −15 package.json
  3. +34 −0 packages/cloudflare/CHANGELOG.md
  4. +12 −13 packages/cloudflare/package.json
  5. +8 −19 packages/cloudflare/src/entrypoints/middleware.ts
  6. +1 −0 packages/cloudflare/src/entrypoints/server.ts
  7. +45 −50 packages/cloudflare/src/index.ts
  8. +12 −7 packages/cloudflare/src/utils/generate-routes-json.ts
  9. +2 −2 packages/cloudflare/test/fixtures/astro-dev-platform/package.json
  10. +2 −2 packages/cloudflare/test/fixtures/astro-env/package.json
  11. +1 −1 packages/cloudflare/test/fixtures/compile-image-service/package.json
  12. +1 −1 packages/cloudflare/test/fixtures/external-image-service/package.json
  13. +1 −1 packages/cloudflare/test/fixtures/module-loader/package.json
  14. +1 −1 packages/cloudflare/test/fixtures/no-output/package.json
  15. +1 −1 packages/cloudflare/test/fixtures/routes-json/package.json
  16. +3 −3 packages/cloudflare/test/fixtures/with-solid-js/package.json
  17. +9 −0 packages/cloudflare/test/fixtures/with-svelte/astro.config.mjs
  18. +11 −0 packages/cloudflare/test/fixtures/with-svelte/package.json
  19. +1 −0 packages/cloudflare/test/fixtures/with-svelte/src/components/Component.svelte
  20. +13 −0 packages/cloudflare/test/fixtures/with-svelte/src/pages/index.astro
  21. +9 −0 packages/cloudflare/test/fixtures/with-vue/astro.config.mjs
  22. +11 −0 packages/cloudflare/test/fixtures/with-vue/package.json
  23. +3 −0 packages/cloudflare/test/fixtures/with-vue/src/components/Component.vue
  24. +13 −0 packages/cloudflare/test/fixtures/with-vue/src/pages/index.astro
  25. +1 −1 packages/cloudflare/test/fixtures/wrangler-preview-platform/package.json
  26. +107 −6 packages/cloudflare/test/routes-json.test.js
  27. +1 −1 packages/cloudflare/test/with-solid-js.test.js
  28. +37 −0 packages/cloudflare/test/with-svelte.test.js
  29. +37 −0 packages/cloudflare/test/with-vue.test.js
  30. +20 −0 packages/netlify/CHANGELOG.md
  31. +9 −9 packages/netlify/package.json
  32. +37 −21 packages/netlify/src/index.ts
  33. +1 −0 packages/netlify/test/functions/fixtures/cookies/.astro/types.d.ts
  34. +3 −0 packages/netlify/test/functions/fixtures/cookies/astro.config.mjs
  35. +1 −0 packages/netlify/test/functions/fixtures/middleware/.astro/types.d.ts
  36. +1 −0 packages/netlify/test/functions/fixtures/redirects/.astro/types.d.ts
  37. +3 −1 packages/netlify/test/hosted/hosted-astro-project/astro.config.mjs
  38. +1 −1 packages/netlify/test/hosted/hosted-astro-project/package.json
  39. +11 −0 packages/netlify/test/hosted/hosted-astro-project/src/middleware.ts
  40. +7 −0 packages/netlify/test/hosted/hosted-astro-project/src/pages/country.astro
  41. +9 −2 packages/netlify/test/hosted/hosted.test.js
  42. +1 −0 packages/netlify/test/static/fixtures/redirects/.astro/types.d.ts
  43. +12 −0 packages/node/CHANGELOG.md
  44. +5 −5 packages/node/package.json
  45. +6 −8 packages/node/src/log-listening-on.ts
  46. +0 −1 packages/node/src/middleware.ts
  47. +8 −3 packages/node/src/preview.ts
  48. +19 −19 packages/node/src/serve-static.ts
  49. +1 −1 packages/node/src/standalone.ts
  50. +7 −0 packages/node/test/fixtures/api-route/astro.config.mjs
  51. +2 −2 packages/node/test/fixtures/api-route/package.json
  52. +1 −1 packages/node/test/fixtures/api-route/src/pages/redirect.ts
  53. +1 −1 packages/node/test/fixtures/api-route/src/pages/response-redirect.ts
  54. +2 −2 packages/node/test/fixtures/bad-urls/package.json
  55. +2 −2 packages/node/test/fixtures/encoded/package.json
  56. +2 −2 packages/node/test/fixtures/errors/package.json
  57. +2 −2 packages/node/test/fixtures/headers/package.json
  58. +6 −3 packages/node/test/fixtures/image/package.json
  59. +8 −0 packages/node/test/fixtures/image/src/pages/[...catchall].astro
  60. +0 −6 packages/node/test/fixtures/image/src/pages/index.astro
  61. +7 −0 packages/node/test/fixtures/locals/astro.config.mjs
  62. +2 −2 packages/node/test/fixtures/locals/package.json
  63. +2 −2 packages/node/test/fixtures/node-middleware/package.json
  64. +2 −2 packages/node/test/fixtures/prerender-404-500/package.json
  65. +2 −2 packages/node/test/fixtures/prerender/package.json
  66. +2 −2 packages/node/test/fixtures/preview-headers/package.json
  67. +2 −2 packages/node/test/fixtures/trailing-slash/package.json
  68. +2 −2 packages/node/test/fixtures/url/package.json
  69. +2 −2 packages/node/test/fixtures/well-known-locations/package.json
  70. +25 −7 packages/node/test/image.test.js
  71. +3 −4 packages/node/test/node-middleware.test.js
  72. +63 −0 packages/node/test/preview-host.test.js
  73. +7 −0 packages/test-utils/CHANGELOG.md
  74. +3 −3 packages/test-utils/package.json
  75. +40 −0 packages/vercel/CHANGELOG.md
  76. +7 −6 packages/vercel/package.json
  77. +107 −36 packages/vercel/src/index.ts
  78. +40 −54 packages/vercel/src/lib/redirects.ts
  79. +6 −2 packages/vercel/src/serverless/middleware.ts
  80. +0 −2 packages/vercel/test/edge-middleware.test.js
  81. +1 −1 packages/vercel/test/fixtures/basic/astro.config.mjs
  82. +1 −1 packages/vercel/test/fixtures/basic/package.json
  83. +1 −1 packages/vercel/test/fixtures/image/astro.config.mjs
  84. +1 −1 packages/vercel/test/fixtures/image/package.json
  85. +10 −0 packages/vercel/test/fixtures/integration-assets/astro.config.mjs
  86. +10 −0 packages/vercel/test/fixtures/integration-assets/package.json
  87. +8 −0 packages/vercel/test/fixtures/integration-assets/src/pages/one.astro
  88. +8 −0 packages/vercel/test/fixtures/integration-assets/src/pages/two.astro
  89. +1 −1 packages/vercel/test/fixtures/isr/astro.config.mjs
  90. +1 −1 packages/vercel/test/fixtures/isr/package.json
  91. +1 −1 packages/vercel/test/fixtures/max-duration/astro.config.mjs
  92. +1 −1 packages/vercel/test/fixtures/max-duration/package.json
  93. +1 −1 packages/vercel/test/fixtures/middleware-with-edge-file/astro.config.mjs
  94. +1 −1 packages/vercel/test/fixtures/middleware-with-edge-file/package.json
  95. +5 −0 packages/vercel/test/fixtures/middleware-with-edge-file/src/middleware.js
  96. +1 −1 packages/vercel/test/fixtures/middleware-without-edge-file/astro.config.mjs
  97. +1 −1 packages/vercel/test/fixtures/middleware-without-edge-file/package.json
  98. +1 −1 packages/vercel/test/fixtures/no-output/astro.config.mjs
  99. +1 −1 packages/vercel/test/fixtures/no-output/package.json
  100. +1 −1 packages/vercel/test/fixtures/prerendered-error-pages/astro.config.mjs
  101. +1 −1 packages/vercel/test/fixtures/prerendered-error-pages/package.json
  102. +1 −1 packages/vercel/test/fixtures/redirects-serverless/astro.config.mjs
  103. +1 −1 packages/vercel/test/fixtures/redirects-serverless/package.json
  104. +1 −1 packages/vercel/test/fixtures/redirects/astro.config.mjs
  105. +1 −1 packages/vercel/test/fixtures/redirects/package.json
  106. +1 −1 packages/vercel/test/fixtures/server-islands/astro.config.mjs
  107. +1 −1 packages/vercel/test/fixtures/server-islands/package.json
  108. +1 −1 packages/vercel/test/fixtures/serverless-prerender/astro.config.mjs
  109. +1 −1 packages/vercel/test/fixtures/serverless-prerender/package.json
  110. +1 −1 packages/vercel/test/fixtures/serverless-with-dynamic-routes/astro.config.mjs
  111. +1 −1 packages/vercel/test/fixtures/serverless-with-dynamic-routes/package.json
  112. +1 −1 packages/vercel/test/fixtures/static-assets/package.json
  113. +1 −1 packages/vercel/test/fixtures/static/astro.config.mjs
  114. +1 −1 packages/vercel/test/fixtures/static/package.json
  115. +1 −1 packages/vercel/test/fixtures/streaming/astro.config.mjs
  116. +1 −1 packages/vercel/test/fixtures/streaming/package.json
  117. +1 −1 packages/vercel/test/fixtures/with-web-analytics-enabled/output-as-static/astro.config.mjs
  118. +1 −1 packages/vercel/test/fixtures/with-web-analytics-enabled/output-as-static/package.json
  119. +1 −1 packages/vercel/test/hosted/hosted-astro-project/astro.config.mjs
  120. +1 −1 packages/vercel/test/hosted/hosted-astro-project/package.json
  121. +24 −0 packages/vercel/test/integration-assets.test.js
  122. +12 −8 packages/vercel/test/isr.test.js
  123. +1 −1 packages/vercel/test/prerendered-error-pages.test.js
  124. +18 −21 packages/vercel/test/redirects.test.js
  125. +4 −4 packages/vercel/test/static-assets.test.js
  126. +1 −1 packages/vercel/test/static.test.js
  127. +3,423 −1,053 pnpm-lock.yaml
  128. +2 −1 readme.md
  129. +3 −3 scripts/notify/index.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ package-lock.json
.pnpm-store
.idea/
**/fixtures/**/.astro
**/hosted/**/.astro

# ignore top-level vscode settings
/.vscode/settings.json
21 changes: 6 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -29,35 +29,26 @@
"packageManager": "pnpm@9.7.1",
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
"rollup",
"@babel/core",
"@babel/plugin-transform-react-jsx",
"vite",
"react",
"react-dom",
"@types/react"
],
"allowAny": ["astro", "vite"]
}
},
"devDependencies": {
"@astrojs/check": "^0.9.4",
"@biomejs/biome": "1.9.4",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.10",
"@types/node": "^22.10.0",
"@changesets/cli": "^2.27.11",
"@types/node": "^22.10.6",
"esbuild": "^0.24.0",
"eslint": "^9.15.0",
"eslint": "^9.18.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-regexp": "^2.7.0",
"only-allow": "^1.2.1",
"prettier": "^3.4.1",
"prettier": "^3.4.2",
"prettier-plugin-astro": "^0.14.1",
"turbo": "^2.3.3",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0"
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
}
}
34 changes: 34 additions & 0 deletions packages/cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# @astrojs/cloudflare

## 12.2.1

### Patch Changes

- [#506](https://github.com/withastro/adapters/pull/506) [`ce66003`](https://github.com/withastro/adapters/commit/ce66003c093daa0e53a7ab1cf46ddd1d4ddcbee4) Thanks [@bluwy](https://github.com/bluwy)! - Removes internal `vue` handling

## 12.2.0

### Minor Changes

- [#496](https://github.com/withastro/adapters/pull/496) [`4b5cd22`](https://github.com/withastro/adapters/commit/4b5cd2268e8ed5e720772f50241b299762ea1eb8) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Stabilizes `astro:env` secrets support

### Patch Changes

- [#454](https://github.com/withastro/adapters/pull/454) [`83cedad`](https://github.com/withastro/adapters/commit/83cedad780bf7a23ae9f6ca0c44a7b7f1c1767e1) Thanks [@alexanderniebuhr](https://github.com/alexanderniebuhr)! - Improves Astro 5 support

- [#501](https://github.com/withastro/adapters/pull/501) [`012b31d`](https://github.com/withastro/adapters/commit/012b31d98ce87c1199eb38b7aba2a28b7c1cf8cc) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Refactor of the redirects logic

## 12.1.0

### Minor Changes

- [#455](https://github.com/withastro/adapters/pull/455) [`1d4e6fc`](https://github.com/withastro/adapters/commit/1d4e6fca41b67277a21dcf2a42910e12206a0299) Thanks [@meyer](https://github.com/meyer)! - Adds `wrangler.jsonc` to the default watched config files. If a config file is specified in `platformProxy.configPath`, that file location is watched instead of the defaults.

### Patch Changes

- [#476](https://github.com/withastro/adapters/pull/476) [`a8a8ab1`](https://github.com/withastro/adapters/commit/a8a8ab12d9cfb5157e6a350b93a505010367b8e4) Thanks [@bluwy](https://github.com/bluwy)! - Removes resolving with "node" conditionto fix Vue imports

## 12.0.1

### Patch Changes

- [#465](https://github.com/withastro/adapters/pull/465) [`70e0054`](https://github.com/withastro/adapters/commit/70e0054aade5368f1bd9b1595766826af7e9ec8d) Thanks [@bluwy](https://github.com/bluwy)! - Fixes setting custom `workerd` and `worker` conditions for the ssr environment only

## 12.0.0

### Major Changes
25 changes: 12 additions & 13 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@astrojs/cloudflare",
"description": "Deploy your site to Cloudflare Workers/Pages",
"version": "12.0.0",
"version": "12.2.1",
"type": "module",
"types": "./dist/index.d.ts",
"author": "withastro",
@@ -28,30 +28,29 @@
"test": "astro-scripts test \"test/**/*.test.js\""
},
"dependencies": {
"@astrojs/internal-helpers": "0.4.1",
"@astrojs/underscore-redirects": "^0.4.0-alpha.0",
"@cloudflare/workers-types": "^4.20241112.0",
"@inox-tools/astro-when": "^0.2.4",
"@astrojs/internal-helpers": "0.4.2",
"@astrojs/underscore-redirects": "^0.6.0",
"@cloudflare/workers-types": "^4.20250109.0",
"esbuild": "^0.24.0",
"estree-walker": "^3.0.3",
"magic-string": "^0.30.14",
"miniflare": "^3.20241106.1",
"magic-string": "^0.30.17",
"miniflare": "^3.20241230.1",
"tiny-glob": "^0.2.9",
"wrangler": "^3.91.0"
"vite": "^6.0.7",
"wrangler": "^3.101.0"
},
"peerDependencies": {
"astro": "^5.0.0"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"astro": "^5.0.0-alpha.15",
"astro": "^5.1.6",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"rollup": "^4.27.4",
"strip-ansi": "^7.1.0",
"vite": "6.0.1"
"fast-glob": "^3.3.3",
"rollup": "^4.30.1",
"strip-ansi": "^7.1.0"
},
"publishConfig": {
"provenance": true
27 changes: 8 additions & 19 deletions packages/cloudflare/src/entrypoints/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { When, whenAmI } from '@it-astro:when';
import type { MiddlewareHandler } from 'astro';

const middlewares: Record<When, MiddlewareHandler> = {
[When.Client]: () => {
throw new Error('Client should not run a middleware!');
},
[When.DevServer]: (_, next) => next(),
[When.Server]: (_, next) => next(),
[When.Prerender]: (ctx, next) => {
export const onRequest: MiddlewareHandler = (context, next) => {
if (context.isPrerendered) {
// @ts-expect-error
if (ctx.locals.runtime === undefined) {
// @ts-expect-error
ctx.locals.runtime = {
env: process.env,
};
}
return next();
},
[When.StaticBuild]: (_, next) => next(),
};
context.locals.runtime ??= {
env: process.env,
};
}

export const onRequest = middlewares[whenAmI];
return next();
};
1 change: 1 addition & 0 deletions packages/cloudflare/src/entrypoints/server.ts
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ export function createExports(manifest: SSRManifest) {
'`passThroughOnException` is currently not available in Cloudflare Pages. See https://developers.cloudflare.com/pages/platform/known-issues/#pages-functions.'
);
},
props: {},
},
},
};
95 changes: 45 additions & 50 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { AstroConfig, AstroIntegration, IntegrationRouteData } from 'astro';
import type {
AstroConfig,
AstroIntegration,
HookParameters,
IntegrationResolvedRoute,
} from 'astro';
import type { PluginOption } from 'vite';

import { createReadStream } from 'node:fs';
@@ -10,8 +15,8 @@ import {
removeLeadingForwardSlash,
} from '@astrojs/internal-helpers/path';
import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects';
import astroWhen from '@inox-tools/astro-when';
import { AstroError } from 'astro/errors';
import { defaultClientConditions } from 'vite';
import { type GetPlatformProxyOptions, getPlatformProxy } from 'wrangler';
import {
type CloudflareModulePluginExtra,
@@ -87,11 +92,14 @@ function setProcessEnv(config: AstroConfig, env: Record<string, unknown>) {

export default function createIntegration(args?: Options): AstroIntegration {
let _config: AstroConfig;
let finalBuildOutput: HookParameters<'astro:config:done'>['buildOutput'];

const cloudflareModulePlugin: PluginOption & CloudflareModulePluginExtra = cloudflareModuleLoader(
args?.cloudflareModules ?? true
);

let _routes: IntegrationResolvedRoute[];

return {
name: '@astrojs/cloudflare',
hooks: {
@@ -127,16 +135,23 @@ export default function createIntegration(args?: Options): AstroIntegration {
},
],
},
integrations: [astroWhen()],
image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger),
});
addWatchFile(new URL('./wrangler.toml', config.root));
addWatchFile(new URL('./wrangler.json', config.root));
if (args?.platformProxy?.configPath) {
addWatchFile(new URL(args.platformProxy.configPath, config.root));
} else {
addWatchFile(new URL('./wrangler.toml', config.root));
addWatchFile(new URL('./wrangler.json', config.root));
addWatchFile(new URL('./wrangler.jsonc', config.root));
}
addMiddleware({
entrypoint: '@astrojs/cloudflare/entrypoints/middleware.js',
order: 'pre',
});
},
'astro:routes:resolved': ({ routes }) => {
_routes = routes;
},
'astro:config:done': ({ setAdapter, config, buildOutput, logger }) => {
if (buildOutput === 'static') {
logger.warn(
@@ -145,6 +160,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
}

_config = config;
finalBuildOutput = buildOutput;

setAdapter({
name: '@astrojs/cloudflare',
@@ -159,8 +175,12 @@ export default function createIntegration(args?: Options): AstroIntegration {
hybridOutput: 'stable',
staticOutput: 'unsupported',
i18nDomains: 'experimental',
sharpImageService: 'limited',
envGetSecret: 'experimental',
sharpImageService: {
support: 'limited',
message:
'Cloudflare does not support sharp. You can use the `compile` image service to compile images at build time. It will not work for any on-demand rendered images.',
},
envGetSecret: 'stable',
},
});
},
@@ -213,60 +233,32 @@ export default function createIntegration(args?: Options): AstroIntegration {
}
}

vite.resolve.conditions ||= [];
// We need those conditions, previous these conditions where applied at the esbuild step which we removed
// https://github.com/withastro/astro/pull/7092
vite.resolve.conditions.push('workerd', 'worker');

// Support `workerd` and `worker` conditions for the ssr environment
// (previously supported in esbuild instead: https://github.com/withastro/astro/pull/7092)
vite.ssr ||= {};
vite.ssr.resolve ||= {};
vite.ssr.resolve.conditions ||= [...defaultClientConditions];
vite.ssr.resolve.conditions.push('workerd', 'worker');

vite.ssr.target = 'webworker';
vite.ssr.noExternal = true;

if (typeof _config.vite.ssr?.external === 'undefined') vite.ssr.external = [];
if (typeof _config.vite.ssr?.external === 'boolean')
vite.ssr.external = _config.vite.ssr?.external;
if (Array.isArray(_config.vite.ssr?.external))
// `@astrojs/vue` sets `@vue/server-renderer` to external
// https://github.com/withastro/astro/blob/e648c5575a8774af739231cfa9fc27a32086aa5f/packages/integrations/vue/src/index.ts#L119
// the cloudflare adapter needs to get all dependencies inlined, we use `noExternal` for that, but any `external` config overrides that
// therefore we need to remove `@vue/server-renderer` from the external config again
vite.ssr.external = _config.vite.ssr?.external.filter(
(entry) => entry !== '@vue/server-renderer'
);

vite.build ||= {};
vite.build.rollupOptions ||= {};
vite.build.rollupOptions.output ||= {};
// @ts-expect-error
vite.build.rollupOptions.output.banner ||=
'globalThis.process ??= {}; globalThis.process.env ??= {};';

vite.build.rollupOptions.external = _config.vite.build?.rollupOptions?.external ?? [];

// Cloudflare env is only available per request. This isn't feasible for code that access env vars
// in a global way, so we shim their access as `process.env.*`. This is not the recommended way for users to access environment variables. But we'll add this for compatibility for chosen variables. Mainly to support `@astrojs/db`
vite.define = {
'process.env': 'process.env',
...vite.define,
};
}
// we thought that vite config inside `if (target === 'server')` would not apply for client
// but it seems like the same `vite` reference is used for both
// so we need to reset the previous conflicting setting
// in the future we should look into a more robust solution
if (target === 'client') {
vite.resolve ||= {};
vite.resolve.conditions ||= [];
vite.resolve.conditions = vite.resolve.conditions.filter(
(c) => c !== 'workerd' && c !== 'worker'
);

vite.build ||= {};
vite.build.rollupOptions ||= {};
vite.build.rollupOptions.output ||= {};
}
},
'astro:build:done': async ({ pages, routes, dir, logger }) => {
'astro:build:done': async ({ pages, dir, logger, assets }) => {
await cloudflareModulePlugin.afterBuildCompleted(_config);
const PLATFORM_FILES = ['_headers', '_redirects', '_routes.json'];
if (_config.base !== '/') {
@@ -291,7 +283,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
redirectsExists = false;
}

const redirects: IntegrationRouteData['segments'][] = [];
const redirects: IntegrationResolvedRoute['segments'][] = [];
if (redirectsExists) {
const rl = createInterface({
input: createReadStream(new URL('./_redirects', _config.outDir)),
@@ -330,23 +322,26 @@ export default function createIntegration(args?: Options): AstroIntegration {
await createRoutesFile(
_config,
logger,
routes,
_routes,
pages,
redirects,
args?.routes?.extend?.include,
args?.routes?.extend?.exclude
);
}

const redirectRoutes: [IntegrationRouteData, string][] = [];
for (const route of routes) {
if (route.type === 'redirect') redirectRoutes.push([route, '']);
}

const trueRedirects = createRedirectsFromAstroRoutes({
config: _config,
routeToDynamicTargetMap: new Map(Array.from(redirectRoutes)),
routeToDynamicTargetMap: new Map(
Array.from(
_routes
.filter((route) => route.type === 'redirect')
.map((route) => [route, ''] as const)
)
),
dir,
buildOutput: finalBuildOutput,
assets,
});

if (!trueRedirects.empty()) {
Loading