Skip to content
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/astro
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: astro@4.0.5
Choose a base ref
...
head repository: withastro/astro
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: astro@4.0.6
Choose a head ref
  • 14 commits
  • 82 files changed
  • 14 contributors

Commits on Dec 14, 2023

  1. Prevent Partytown from hijacking history API (#9419)

    * Partytown overrides these methods to... do things, but it breaks ViewTransitions in Firefox.
    
    * Only redefine pushstate/replacestate in the browser
    matthewp authored Dec 14, 2023
    Copy the full SHA
    151bd42 View commit details
  2. [ci] format

    matthewp authored and astrobot-houston committed Dec 14, 2023
    Copy the full SHA
    745294d View commit details
  3. fix: merge headers from the original response in error pages (#9433)

    * fix: merge headers from the original response in error pages
    
    * revert local change
    
    * change test ordering
    
    * apply feedback
    ematipico authored Dec 14, 2023
    Copy the full SHA
    fcc2fd5 View commit details

Commits on Dec 15, 2023

  1. fix: improve error message when a middleware doesn't return a `Respon…

    …se` (#9434)
    
    * fix: improve error message when a middleware doesn't return a `Response`
    
    * Apply suggestions from code review
    
    Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
    
    * fix typo
    
    ---------
    
    Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
    ematipico and sarah11918 authored Dec 15, 2023
    Copy the full SHA
    c01580a View commit details
  2. fix(error pages): account for trailingSlash (#9126)

    * account for trailingSlash
    
    * add changeset
    
    * add tests
    
    * update lock file
    lilnasy authored Dec 15, 2023
    Copy the full SHA
    6d2d0e2 View commit details
  3. [ci] format

    ematipico authored and astrobot-houston committed Dec 15, 2023
    Copy the full SHA
    667539b View commit details
  4. Simplify vue appEntrypoint handling (#9362)

    * Simplify vue appEntrypoint handling
    
    * Try fix windows
    
    ---------
    
    Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
    bluwy and natemoo-re authored Dec 15, 2023
    Copy the full SHA
    a5db8d2 View commit details
  5. [ci] format

    ematipico authored and astrobot-houston committed Dec 15, 2023
    Copy the full SHA
    41b05b5 View commit details
  6. feat: make Houston festive for the holiday season (#9358)

    * feat: make Houston festive for the holiday season
    
    * fix: change changeset to minor
    xiBread authored Dec 15, 2023
    Copy the full SHA
    35e4c17 View commit details
  7. Fixes warning for external URL redirects (#9426)

    * Update warning for external URL redirects to use destination address
    
    * Update .changeset/gentle-chefs-glow.md
    
    Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
    
    ---------
    
    Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
    alexnguyennz and florian-lefebvre authored Dec 15, 2023
    Copy the full SHA
    c01cc4e View commit details
  8. [ci] format

    ematipico authored and astrobot-houston committed Dec 15, 2023
    Copy the full SHA
    3cf7fe4 View commit details
  9. Copy the full SHA
    017f981 View commit details
  10. Upgrade compiler (#9445)

    natemoo-re authored Dec 15, 2023
    Copy the full SHA
    f963d07 View commit details
  11. [ci] release (#9432)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    astrobot-houston and github-actions[bot] authored Dec 15, 2023
    Copy the full SHA
    8a0def2 View commit details
Showing with 368 additions and 390 deletions.
  1. +1 −1 examples/basics/package.json
  2. +1 −1 examples/blog/package.json
  3. +1 −1 examples/component/package.json
  4. +1 −1 examples/framework-alpine/package.json
  5. +1 −1 examples/framework-lit/package.json
  6. +2 −2 examples/framework-multiple/package.json
  7. +1 −1 examples/framework-preact/package.json
  8. +1 −1 examples/framework-react/package.json
  9. +1 −1 examples/framework-solid/package.json
  10. +1 −1 examples/framework-svelte/package.json
  11. +2 −2 examples/framework-vue/package.json
  12. +1 −1 examples/hackernews/package.json
  13. +1 −1 examples/integration/package.json
  14. +1 −1 examples/middleware/package.json
  15. +1 −1 examples/minimal/package.json
  16. +1 −1 examples/non-html-pages/package.json
  17. +1 −1 examples/portfolio/package.json
  18. +1 −1 examples/ssr/package.json
  19. +1 −1 examples/view-transitions/package.json
  20. +1 −1 examples/with-markdoc/package.json
  21. +1 −1 examples/with-markdown-plugins/package.json
  22. +1 −1 examples/with-markdown-shiki/package.json
  23. +1 −1 examples/with-mdx/package.json
  24. +1 −1 examples/with-nanostores/package.json
  25. +1 −1 examples/with-tailwindcss/package.json
  26. +1 −1 examples/with-vitest/package.json
  27. +16 −0 packages/astro/CHANGELOG.md
  28. +1 −1 packages/astro/components/Picture.astro
  29. +2 −2 packages/astro/package.json
  30. +2 −1 packages/astro/src/assets/build/generate.ts
  31. +15 −0 packages/astro/src/assets/endpoint/config.ts
  32. +2 −1 packages/astro/src/assets/endpoint/generic.ts
  33. +2 −1 packages/astro/src/assets/endpoint/node.ts
  34. +2 −42 packages/astro/src/assets/internal.ts
  35. +2 −1 packages/astro/src/assets/services/service.ts
  36. +9 −0 packages/astro/src/assets/utils/imageKind.ts
  37. +10 −0 packages/astro/src/assets/utils/index.ts
  38. +19 −0 packages/astro/src/assets/utils/remotePattern.ts
  39. +1 −1 packages/astro/src/assets/utils/transformToPath.ts
  40. +1 −1 packages/astro/src/assets/vite-plugin-assets.ts
  41. +24 −9 packages/astro/src/core/app/index.ts
  42. +1 −1 packages/astro/src/core/build/index.ts
  43. +1 −1 packages/astro/src/core/dev/container.ts
  44. +3 −2 packages/astro/src/core/errors/errors-data.ts
  45. +1 −1 packages/astro/src/core/routing/manifest/create.ts
  46. +11 −5 packages/astro/src/transitions/router.ts
  47. +0 −4 packages/astro/src/vite-plugin-astro-server/request.ts
  48. +0 −45 packages/astro/test/custom-404-server.test.js
  49. +12 −1 packages/astro/test/{custom-404.test.js → custom-404-static.test.js}
  50. +0 −8 packages/astro/test/fixtures/custom-404-server/astro.config.mjs
  51. +0 −8 packages/astro/test/fixtures/custom-404-server/package.json
  52. +0 −6 packages/astro/test/fixtures/custom-404-server/src/pages/[slug].astro
  53. 0 packages/astro/test/fixtures/{custom-404 → custom-404-static}/astro.config.mjs
  54. 0 packages/astro/test/fixtures/{custom-404 → custom-404-static}/package.json
  55. 0 packages/astro/test/fixtures/{custom-404-server → custom-404-static}/src/pages/404.astro
  56. 0 packages/astro/test/fixtures/{custom-404-server → custom-404-static}/src/pages/index.astro
  57. +0 −13 packages/astro/test/fixtures/custom-404/src/pages/404.astro
  58. +0 −11 packages/astro/test/fixtures/custom-404/src/pages/index.astro
  59. +13 −7 packages/astro/test/fixtures/middleware space/src/middleware.js
  60. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/package.json
  61. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/content/pages/index.md
  62. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/pages/404.astro
  63. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/pages/500.astro
  64. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/pages/api/route.js
  65. 0 ...stro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/pages/blog/[...ssrPath].astro
  66. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/pages/causes-404.astro
  67. 0 ...ges/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/pages/causes-error.astro
  68. 0 packages/astro/test/fixtures/{ssr-api-route-custom-404 → ssr-error-pages}/src/styles/main.css
  69. +0 −8 packages/astro/test/fixtures/status-code/package.json
  70. +0 −8 packages/astro/test/fixtures/status-code/src/pages/404.astro
  71. +0 −8 packages/astro/test/fixtures/status-code/src/pages/index.astro
  72. +10 −0 packages/astro/test/middleware.test.js
  73. +61 −11 packages/astro/test/{ssr-404-500-pages.test.js → ssr-error-pages.test.js}
  74. +0 −19 packages/astro/test/status-page.test.js
  75. +6 −0 packages/create-astro/CHANGELOG.md
  76. +1 −1 packages/create-astro/package.json
  77. +1 −1 packages/create-astro/src/actions/context.ts
  78. +24 −18 packages/create-astro/src/messages.ts
  79. +6 −0 packages/integrations/vue/CHANGELOG.md
  80. +1 −1 packages/integrations/vue/package.json
  81. +40 −62 packages/integrations/vue/src/index.ts
  82. +40 −52 pnpm-lock.yaml
2 changes: 1 addition & 1 deletion examples/basics/package.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/blog/package.json
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@
"@astrojs/mdx": "^2.0.1",
"@astrojs/rss": "^4.0.1",
"@astrojs/sitemap": "^3.0.3",
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/component/package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
},
"peerDependencies": {
"astro": "^3.0.0"
2 changes: 1 addition & 1 deletion examples/framework-alpine/package.json
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@
"@astrojs/alpinejs": "^0.3.1",
"@types/alpinejs": "^3.13.5",
"alpinejs": "^3.13.3",
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/framework-lit/package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/lit": "^4.0.0",
"@webcomponents/template-shadowroot": "^0.2.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"lit": "^2.8.0"
}
}
4 changes: 2 additions & 2 deletions examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@
"@astrojs/react": "^3.0.7",
"@astrojs/solid-js": "^3.0.2",
"@astrojs/svelte": "^5.0.1",
"@astrojs/vue": "^4.0.3",
"astro": "^4.0.5",
"@astrojs/vue": "^4.0.4",
"astro": "^4.0.6",
"preact": "^10.19.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
2 changes: 1 addition & 1 deletion examples/framework-preact/package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^3.0.1",
"@preact/signals": "^1.2.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"preact": "^10.19.2"
}
}
2 changes: 1 addition & 1 deletion examples/framework-react/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"@astrojs/react": "^3.0.7",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"astro": "^4.0.5",
"astro": "^4.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
2 changes: 1 addition & 1 deletion examples/framework-solid/package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/solid-js": "^3.0.2",
"astro": "^4.0.5",
"astro": "^4.0.6",
"solid-js": "^1.8.5"
}
}
2 changes: 1 addition & 1 deletion examples/framework-svelte/package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/svelte": "^5.0.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"svelte": "^4.2.5"
}
}
4 changes: 2 additions & 2 deletions examples/framework-vue/package.json
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/vue": "^4.0.3",
"astro": "^4.0.5",
"@astrojs/vue": "^4.0.4",
"astro": "^4.0.6",
"vue": "^3.3.8"
}
}
2 changes: 1 addition & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/node": "^7.0.1",
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/integration/package.json
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
},
"peerDependencies": {
"astro": "^3.0.0"
2 changes: 1 addition & 1 deletion examples/middleware/package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
},
"dependencies": {
"@astrojs/node": "^7.0.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"html-minifier": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion examples/minimal/package.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/non-html-pages/package.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/portfolio/package.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/ssr/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"dependencies": {
"@astrojs/node": "^7.0.1",
"@astrojs/svelte": "^5.0.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"svelte": "^4.2.5"
}
}
2 changes: 1 addition & 1 deletion examples/view-transitions/package.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@
"devDependencies": {
"@astrojs/tailwind": "^5.0.3",
"@astrojs/node": "^7.0.1",
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/with-markdoc/package.json
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/markdoc": "^0.8.0",
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/with-markdown-plugins/package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/markdown-remark": "^4.0.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"hast-util-select": "^6.0.2",
"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",
2 changes: 1 addition & 1 deletion examples/with-markdown-shiki/package.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.0.5"
"astro": "^4.0.6"
}
}
2 changes: 1 addition & 1 deletion examples/with-mdx/package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/mdx": "^2.0.1",
"@astrojs/preact": "^3.0.1",
"astro": "^4.0.5",
"astro": "^4.0.6",
"preact": "^10.19.2"
}
}
2 changes: 1 addition & 1 deletion examples/with-nanostores/package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^3.0.1",
"@nanostores/preact": "^0.5.0",
"astro": "^4.0.5",
"astro": "^4.0.6",
"nanostores": "^0.9.5",
"preact": "^10.19.2"
}
2 changes: 1 addition & 1 deletion examples/with-tailwindcss/package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"@astrojs/mdx": "^2.0.1",
"@astrojs/tailwind": "^5.0.3",
"@types/canvas-confetti": "^1.6.3",
"astro": "^4.0.5",
"astro": "^4.0.6",
"autoprefixer": "^10.4.15",
"canvas-confetti": "^1.9.1",
"postcss": "^8.4.28",
2 changes: 1 addition & 1 deletion examples/with-vitest/package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
"test": "vitest"
},
"dependencies": {
"astro": "^4.0.5",
"astro": "^4.0.6",
"vitest": "^0.34.2"
}
}
16 changes: 16 additions & 0 deletions packages/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# astro

## 4.0.6

### Patch Changes

- [#9419](https://github.com/withastro/astro/pull/9419) [`151bd429b`](https://github.com/withastro/astro/commit/151bd429b11a73d236ca8f43e8f5072e7c29641e) Thanks [@matthewp](https://github.com/matthewp)! - Prevent Partytown from hijacking history APIs

- [#9426](https://github.com/withastro/astro/pull/9426) [`c01cc4e34`](https://github.com/withastro/astro/commit/c01cc4e3409ae3cf81db7384bf8e53424f21bb5c) Thanks [@alexnguyennz](https://github.com/alexnguyennz)! - Fixes warning for external URL redirects

- [#9445](https://github.com/withastro/astro/pull/9445) [`f963d07f2`](https://github.com/withastro/astro/commit/f963d07f22f972938e1c9e8c95f9278efdff586b) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Upgrades Astro's compiler to a crash when sourcemaps try to map multibyte characters

- [#9126](https://github.com/withastro/astro/pull/9126) [`6d2d0e279`](https://github.com/withastro/astro/commit/6d2d0e279dd51e04099c86c4d900e2dd1d5fa837) Thanks [@lilnasy](https://github.com/lilnasy)! - Fixes an issue where error pages were not shown when trailingSlash was set to "always".

- [#9434](https://github.com/withastro/astro/pull/9434) [`c01580a2c`](https://github.com/withastro/astro/commit/c01580a2cd847ac82192d6717e9e823fba6ecb49) Thanks [@ematipico](https://github.com/ematipico)! - Improves the error message when a middleware doesn't return a `Response`

- [#9433](https://github.com/withastro/astro/pull/9433) [`fcc2fd5b0`](https://github.com/withastro/astro/commit/fcc2fd5b0f218ecfc7bbe3f48063221e5dd62757) Thanks [@ematipico](https://github.com/ematipico)! - Correctly merge headers from the original response when an error page is rendered

## 4.0.5

### Patch Changes
2 changes: 1 addition & 1 deletion packages/astro/components/Picture.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import { getImage, type LocalImageProps, type RemoteImageProps } from 'astro:assets';
import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro';
import { isESMImportedImage } from '../dist/assets/internal';
import { isESMImportedImage } from '../dist/assets/utils/imageKind';
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
import type { HTMLAttributes } from '../types';
4 changes: 2 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro",
"version": "4.0.5",
"version": "4.0.6",
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
"type": "module",
"author": "withastro",
@@ -112,7 +112,7 @@
"test:e2e:match": "playwright test -g"
},
"dependencies": {
"@astrojs/compiler": "^2.3.2",
"@astrojs/compiler": "^2.3.4",
"@astrojs/internal-helpers": "workspace:*",
"@astrojs/markdown-remark": "workspace:*",
"@astrojs/telemetry": "workspace:*",
3 changes: 2 additions & 1 deletion packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
@@ -10,9 +10,10 @@ import type { Logger } from '../../core/logger/core.js';
import { isRemotePath, prependForwardSlash } from '../../core/path.js';
import { isServerLikeOutput } from '../../prerender/utils.js';
import type { MapValue } from '../../type-utils.js';
import { getConfiguredImageService, isESMImportedImage } from '../internal.js';
import { getConfiguredImageService } from '../internal.js';
import type { LocalImageService } from '../services/service.js';
import type { AssetsGlobalStaticImagesList, ImageMetadata, ImageTransform } from '../types.js';
import { isESMImportedImage } from '../utils/imageKind.js';
import { loadRemoteImage, type RemoteCacheEntry } from './remote.js';

interface GenerationDataUncached {
15 changes: 15 additions & 0 deletions packages/astro/src/assets/endpoint/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { AstroSettings } from '../../@types/astro.js';

export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build') {
const endpointEntrypoint =
settings.config.image.endpoint ??
(mode === 'dev' ? 'astro/assets/endpoint/node' : 'astro/assets/endpoint/generic');

settings.injectedRoutes.push({
pattern: '/_image',
entrypoint: endpointEntrypoint,
prerender: false,
});

return settings;
}
3 changes: 2 additions & 1 deletion packages/astro/src/assets/endpoint/generic.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import mime from 'mime/lite.js';
import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService, isRemoteAllowed } from '../internal.js';
import { getConfiguredImageService } from '../internal.js';
import { etag } from '../utils/etag.js';
// @ts-expect-error
import { imageConfig } from 'astro:assets';
import { isRemoteAllowed } from '../utils/remotePattern.js';

async function loadRemoteImage(src: URL) {
try {
3 changes: 2 additions & 1 deletion packages/astro/src/assets/endpoint/node.ts
Original file line number Diff line number Diff line change
@@ -3,10 +3,11 @@ import { readFile } from 'fs/promises';
import mime from 'mime/lite.js';
import os from 'os';
import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService, isRemoteAllowed } from '../internal.js';
import { getConfiguredImageService } from '../internal.js';
import { etag } from '../utils/etag.js';
// @ts-expect-error
import { assetsDir, imageConfig } from 'astro:assets';
import { isRemoteAllowed } from '../utils/remotePattern.js';

function replaceFileSystemReferences(src: string) {
return os.platform().includes('win32') ? src.replace(/^\/@fs\//, '') : src.replace(/^\/@fs/, '');
44 changes: 2 additions & 42 deletions packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
import type { AstroConfig } from '../@types/astro.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { DEFAULT_HASH_PROPS } from './consts.js';
import { isLocalService, type ImageService } from './services/service.js';
import type {
GetImageResult,
ImageMetadata,
ImageTransform,
SrcSetValue,
UnresolvedImageTransform,
} from './types.js';
import { matchHostname, matchPattern } from './utils/remotePattern.js';

export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build') {
const endpointEntrypoint =
settings.config.image.endpoint ??
(mode === 'dev' ? 'astro/assets/endpoint/node' : 'astro/assets/endpoint/generic');

settings.injectedRoutes.push({
pattern: '/_image',
entrypoint: endpointEntrypoint,
prerender: false,
});

return settings;
}

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
return typeof src === 'object';
}

export function isRemoteImage(src: ImageMetadata | string): src is string {
return typeof src === 'string';
}

export function isRemoteAllowed(
src: string,
{
domains = [],
remotePatterns = [],
}: Partial<Pick<AstroConfig['image'], 'domains' | 'remotePatterns'>>
): boolean {
if (!isRemotePath(src)) return false;

const url = new URL(src);
return (
domains.some((domain) => matchHostname(url, domain)) ||
remotePatterns.some((remotePattern) => matchPattern(url, remotePattern))
);
}
import { isESMImportedImage, isRemoteImage } from './utils/imageKind.js';

export async function getConfiguredImageService(): Promise<ImageService> {
if (!globalThis?.astroAsset?.imageService) {
3 changes: 2 additions & 1 deletion packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@ import type { AstroConfig } from '../../@types/astro.js';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import { isRemotePath, joinPaths } from '../../core/path.js';
import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from '../consts.js';
import { isESMImportedImage, isRemoteAllowed } from '../internal.js';
import type { ImageOutputFormat, ImageTransform, UnresolvedSrcSetValue } from '../types.js';
import { isESMImportedImage } from '../utils/imageKind.js';
import { isRemoteAllowed } from '../utils/remotePattern.js';

export type ImageService = LocalImageService | ExternalImageService;

Loading