astro 5.16.5 → 5.16.6

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,16 +1,17 @@
1
1
  import { root } from "astro:config/server";
2
2
  import { readFile } from "node:fs/promises";
3
- import os from "node:os";
4
3
  import { fileURLToPath } from "node:url";
5
4
  import { isParentDirectory } from "@astrojs/internal-helpers/path";
6
5
  import { handleImageRequest, loadRemoteImage } from "./shared.js";
7
- function replaceFileSystemReferences(src) {
8
- return os.platform().includes("win32") ? src.replace(/^\/@fs\//, "") : src.replace(/^\/@fs/, "");
9
- }
10
6
  async function loadLocalImage(src, url) {
11
7
  if (src.startsWith("/@fs/")) {
12
- src = replaceFileSystemReferences(src);
13
- if (!isParentDirectory(fileURLToPath(root), src)) {
8
+ try {
9
+ const res = await fetch(new URL(src, url));
10
+ if (!res.ok) {
11
+ return void 0;
12
+ }
13
+ return Buffer.from(await res.arrayBuffer());
14
+ } catch {
14
15
  return void 0;
15
16
  }
16
17
  }
@@ -1,11 +1,16 @@
1
- import { baseService } from "./service.js";
1
+ import { isESMImportedImage } from "../utils/imageKind.js";
2
+ import { baseService, verifyOptions } from "./service.js";
2
3
  const noopService = {
3
4
  ...baseService,
4
5
  propertiesToHash: ["src"],
5
- async validateOptions(options, imageConfig) {
6
- const newOptions = await (baseService.validateOptions?.(options, imageConfig) ?? options);
7
- delete newOptions.format;
8
- return newOptions;
6
+ async validateOptions(options) {
7
+ if (isESMImportedImage(options.src) && options.src.format === "svg") {
8
+ options.format = "svg";
9
+ } else {
10
+ delete options.format;
11
+ }
12
+ verifyOptions(options);
13
+ return options;
9
14
  },
10
15
  async transform(inputBuffer, transformOptions) {
11
16
  return {
@@ -80,6 +80,7 @@ export type BaseServiceTransform = {
80
80
  fit?: ImageFit;
81
81
  position?: string;
82
82
  };
83
+ export declare function verifyOptions(options: ImageTransform): void;
83
84
  /**
84
85
  * Basic local service using the included `_image` endpoint.
85
86
  * This service intentionally does not implement `transform`.
@@ -95,7 +96,6 @@ export type BaseServiceTransform = {
95
96
  * ```
96
97
  *
97
98
  * This service adhere to the included services limitations:
98
- * - Remote images are passed as is.
99
99
  * - Only a limited amount of formats are supported.
100
100
  * - For remote images, `width` and `height` are always required.
101
101
  *
@@ -17,61 +17,64 @@ function parseQuality(quality) {
17
17
  return result;
18
18
  }
19
19
  const sortNumeric = (a, b) => a - b;
20
- const baseService = {
21
- propertiesToHash: DEFAULT_HASH_PROPS,
22
- validateOptions(options) {
23
- if (!options.src || !isRemoteImage(options.src) && !isESMImportedImage(options.src)) {
20
+ function verifyOptions(options) {
21
+ if (!options.src || !isRemoteImage(options.src) && !isESMImportedImage(options.src)) {
22
+ throw new AstroError({
23
+ ...AstroErrorData.ExpectedImage,
24
+ message: AstroErrorData.ExpectedImage.message(
25
+ JSON.stringify(options.src),
26
+ typeof options.src,
27
+ JSON.stringify(options, (_, v) => v === void 0 ? null : v)
28
+ )
29
+ });
30
+ }
31
+ if (!isESMImportedImage(options.src)) {
32
+ if (options.src.startsWith("/@fs/") || !isRemotePath(options.src) && !options.src.startsWith("/")) {
33
+ throw new AstroError({
34
+ ...AstroErrorData.LocalImageUsedWrongly,
35
+ message: AstroErrorData.LocalImageUsedWrongly.message(options.src)
36
+ });
37
+ }
38
+ let missingDimension;
39
+ if (!options.width && !options.height) {
40
+ missingDimension = "both";
41
+ } else if (!options.width && options.height) {
42
+ missingDimension = "width";
43
+ } else if (options.width && !options.height) {
44
+ missingDimension = "height";
45
+ }
46
+ if (missingDimension) {
24
47
  throw new AstroError({
25
- ...AstroErrorData.ExpectedImage,
26
- message: AstroErrorData.ExpectedImage.message(
27
- JSON.stringify(options.src),
28
- typeof options.src,
29
- JSON.stringify(options, (_, v) => v === void 0 ? null : v)
48
+ ...AstroErrorData.MissingImageDimension,
49
+ message: AstroErrorData.MissingImageDimension.message(missingDimension, options.src)
50
+ });
51
+ }
52
+ } else {
53
+ if (!VALID_SUPPORTED_FORMATS.includes(options.src.format)) {
54
+ throw new AstroError({
55
+ ...AstroErrorData.UnsupportedImageFormat,
56
+ message: AstroErrorData.UnsupportedImageFormat.message(
57
+ options.src.format,
58
+ options.src.src,
59
+ VALID_SUPPORTED_FORMATS
30
60
  )
31
61
  });
32
62
  }
33
- if (!isESMImportedImage(options.src)) {
34
- if (options.src.startsWith("/@fs/") || !isRemotePath(options.src) && !options.src.startsWith("/")) {
35
- throw new AstroError({
36
- ...AstroErrorData.LocalImageUsedWrongly,
37
- message: AstroErrorData.LocalImageUsedWrongly.message(options.src)
38
- });
39
- }
40
- let missingDimension;
41
- if (!options.width && !options.height) {
42
- missingDimension = "both";
43
- } else if (!options.width && options.height) {
44
- missingDimension = "width";
45
- } else if (options.width && !options.height) {
46
- missingDimension = "height";
47
- }
48
- if (missingDimension) {
49
- throw new AstroError({
50
- ...AstroErrorData.MissingImageDimension,
51
- message: AstroErrorData.MissingImageDimension.message(missingDimension, options.src)
52
- });
53
- }
54
- } else {
55
- if (!VALID_SUPPORTED_FORMATS.includes(options.src.format)) {
56
- throw new AstroError({
57
- ...AstroErrorData.UnsupportedImageFormat,
58
- message: AstroErrorData.UnsupportedImageFormat.message(
59
- options.src.format,
60
- options.src.src,
61
- VALID_SUPPORTED_FORMATS
62
- )
63
- });
64
- }
65
- if (options.widths && options.densities) {
66
- throw new AstroError(AstroErrorData.IncompatibleDescriptorOptions);
67
- }
68
- if (options.src.format === "svg") {
69
- options.format = "svg";
70
- }
71
- if (options.src.format === "svg" && options.format !== "svg" || options.src.format !== "svg" && options.format === "svg") {
72
- throw new AstroError(AstroErrorData.UnsupportedImageConversion);
73
- }
63
+ if (options.widths && options.densities) {
64
+ throw new AstroError(AstroErrorData.IncompatibleDescriptorOptions);
65
+ }
66
+ if (options.src.format === "svg" && options.format !== "svg" || options.src.format !== "svg" && options.format === "svg") {
67
+ throw new AstroError(AstroErrorData.UnsupportedImageConversion);
68
+ }
69
+ }
70
+ }
71
+ const baseService = {
72
+ propertiesToHash: DEFAULT_HASH_PROPS,
73
+ validateOptions(options) {
74
+ if (isESMImportedImage(options.src) && options.src.format === "svg") {
75
+ options.format = "svg";
74
76
  }
77
+ verifyOptions(options);
75
78
  if (!options.format) {
76
79
  options.format = DEFAULT_OUTPUT_FORMAT;
77
80
  }
@@ -234,5 +237,6 @@ function getTargetDimensions(options) {
234
237
  export {
235
238
  baseService,
236
239
  isLocalService,
237
- parseQuality
240
+ parseQuality,
241
+ verifyOptions
238
242
  };
@@ -72,7 +72,7 @@ export type ImageTransform = {
72
72
  fit?: ImageFit | undefined;
73
73
  position?: string | undefined;
74
74
  [key: string]: any;
75
- };
75
+ } & Astro.CustomImageProps;
76
76
  export interface GetImageResult {
77
77
  rawOptions: ImageTransform;
78
78
  options: ImageTransform;
@@ -201,7 +201,7 @@ type ImageSharedProps<T> = T & {
201
201
  layout?: never;
202
202
  fit?: never;
203
203
  position?: never;
204
- });
204
+ }) & Astro.CustomImageProps;
205
205
  export type LocalImageProps<T> = ImageSharedProps<T> & {
206
206
  /**
207
207
  * A reference to a local image imported through an ESM import.
@@ -1,6 +1,6 @@
1
1
  class BuildTimeAstroVersionProvider {
2
2
  // Injected during the build through esbuild define
3
- version = "5.16.5";
3
+ version = "5.16.6";
4
4
  }
5
5
  export {
6
6
  BuildTimeAstroVersionProvider
@@ -164,7 +164,7 @@ ${contentConfig.error.message}`);
164
164
  logger.info("Content config changed");
165
165
  shouldClear = true;
166
166
  }
167
- if (previousAstroVersion && previousAstroVersion !== "5.16.5") {
167
+ if (previousAstroVersion && previousAstroVersion !== "5.16.6") {
168
168
  logger.info("Astro version changed");
169
169
  shouldClear = true;
170
170
  }
@@ -172,8 +172,8 @@ ${contentConfig.error.message}`);
172
172
  logger.info("Clearing content store");
173
173
  this.#store.clearAll();
174
174
  }
175
- if ("5.16.5") {
176
- await this.#store.metaStore().set("astro-version", "5.16.5");
175
+ if ("5.16.6") {
176
+ await this.#store.metaStore().set("astro-version", "5.16.6");
177
177
  }
178
178
  if (currentConfigDigest) {
179
179
  await this.#store.metaStore().set("content-config-digest", currentConfigDigest);
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "5.16.5";
1
+ const ASTRO_VERSION = "5.16.6";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
22
22
  await telemetry.record([]);
23
23
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
24
24
  const logger = restart.container.logger;
25
- const currentVersion = "5.16.5";
25
+ const currentVersion = "5.16.6";
26
26
  const isPrerelease = currentVersion.includes("-");
27
27
  if (!isPrerelease) {
28
28
  try {
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "5.16.5";
41
+ const version = "5.16.6";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -275,7 +275,7 @@ function printHelp({
275
275
  message.push(
276
276
  linebreak(),
277
277
  ` ${bgGreen(black(` ${commandName} `))} ${green(
278
- `v${"5.16.5"}`
278
+ `v${"5.16.6"}`
279
279
  )} ${headline}`
280
280
  );
281
281
  }
@@ -18,6 +18,8 @@ declare global {
18
18
  }
19
19
  interface ClientDirectives extends AstroClientDirectives {
20
20
  }
21
+ interface CustomImageProps {
22
+ }
21
23
  }
22
24
  }
23
25
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "5.16.5",
3
+ "version": "5.16.6",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",