astro 2.9.1 → 2.9.2

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.
package/astro-jsx.d.ts CHANGED
@@ -901,6 +901,7 @@ declare namespace astroHTML.JSX {
901
901
  crossorigin?: string | undefined | null;
902
902
  defer?: boolean | string | undefined | null;
903
903
  fetchpriority?: 'auto' | 'high' | 'low' | undefined | null;
904
+ referrerpolicy?: HTMLAttributeReferrerPolicy | undefined | null;
904
905
  integrity?: string | undefined | null;
905
906
  nomodule?: boolean | string | undefined | null;
906
907
  nonce?: string | undefined | null;
@@ -1,5 +1,5 @@
1
1
  import type { APIRoute } from '../@types/astro.js';
2
2
  /**
3
- * Endpoint used in SSR to serve optimized images
3
+ * Endpoint used in dev and SSR to serve optimized images by the base image services
4
4
  */
5
5
  export declare const get: APIRoute;
@@ -29,8 +29,8 @@ async function getImage(options, serviceConfig) {
29
29
  });
30
30
  }
31
31
  const service = await getConfiguredImageService();
32
- const validatedOptions = service.validateOptions ? service.validateOptions(options, serviceConfig) : options;
33
- let imageURL = service.getURL(validatedOptions, serviceConfig);
32
+ const validatedOptions = service.validateOptions ? await service.validateOptions(options, serviceConfig) : options;
33
+ let imageURL = await service.getURL(validatedOptions, serviceConfig);
34
34
  if (isLocalService(service) && globalThis.astroAsset.addStaticImage) {
35
35
  imageURL = globalThis.astroAsset.addStaticImage(validatedOptions);
36
36
  }
@@ -12,14 +12,14 @@ interface SharedServiceProps {
12
12
  * For external services, this should point to the URL your images are coming from, for instance, `/_vercel/image`
13
13
  *
14
14
  */
15
- getURL: (options: ImageTransform, serviceConfig: Record<string, any>) => string;
15
+ getURL: (options: ImageTransform, serviceConfig: Record<string, any>) => string | Promise<string>;
16
16
  /**
17
17
  * Return any additional HTML attributes separate from `src` that your service requires to show the image properly.
18
18
  *
19
19
  * For example, you might want to return the `width` and `height` to avoid CLS, or a particular `class` or `style`.
20
20
  * In most cases, you'll want to return directly what your user supplied you, minus the attributes that were used to generate the image.
21
21
  */
22
- getHTMLAttributes?: (options: ImageTransform, serviceConfig: Record<string, any>) => Record<string, any>;
22
+ getHTMLAttributes?: (options: ImageTransform, serviceConfig: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>;
23
23
  /**
24
24
  * Validate and return the options passed by the user.
25
25
  *
@@ -28,7 +28,7 @@ interface SharedServiceProps {
28
28
  *
29
29
  * This method should returns options, and can be used to set defaults (ex: a default output format to be used if the user didn't specify one.)
30
30
  */
31
- validateOptions?: (options: ImageTransform, serviceConfig: Record<string, any>) => ImageTransform;
31
+ validateOptions?: (options: ImageTransform, serviceConfig: Record<string, any>) => ImageTransform | Promise<ImageTransform>;
32
32
  }
33
33
  export type ExternalImageService = SharedServiceProps;
34
34
  export type LocalImageTransform = {
@@ -37,11 +37,11 @@ export type LocalImageTransform = {
37
37
  };
38
38
  export interface LocalImageService extends SharedServiceProps {
39
39
  /**
40
- * Parse the requested parameters passed in the URL from `getURL` back into an object to be used later by `transform`
40
+ * Parse the requested parameters passed in the URL from `getURL` back into an object to be used later by `transform`.
41
41
  *
42
42
  * In most cases, this will get query parameters using, for example, `params.get('width')` and return those.
43
43
  */
44
- parseURL: (url: URL, serviceConfig: Record<string, any>) => LocalImageTransform | undefined;
44
+ parseURL: (url: URL, serviceConfig: Record<string, any>) => LocalImageTransform | undefined | Promise<LocalImageTransform> | Promise<undefined>;
45
45
  /**
46
46
  * Performs the image transformations on the input image and returns both the binary data and
47
47
  * final image format of the optimized image.
@@ -1 +1,4 @@
1
1
  export { emitESMImage } from './emitAsset.js';
2
+ export { imageMetadata } from './metadata.js';
3
+ export { getOrigQueryParams } from './queryParams.js';
4
+ export { hashTransform, propsToFilename } from './transformToPath.js';
@@ -1,4 +1,11 @@
1
1
  import { emitESMImage } from "./emitAsset.js";
2
+ import { imageMetadata } from "./metadata.js";
3
+ import { getOrigQueryParams } from "./queryParams.js";
4
+ import { hashTransform, propsToFilename } from "./transformToPath.js";
2
5
  export {
3
- emitESMImage
6
+ emitESMImage,
7
+ getOrigQueryParams,
8
+ hashTransform,
9
+ imageMetadata,
10
+ propsToFilename
4
11
  };
@@ -1,8 +1,5 @@
1
1
  import { bold } from "kleur/colors";
2
2
  import MagicString from "magic-string";
3
- import mime from "mime/lite.js";
4
- import fs from "node:fs/promises";
5
- import { Readable } from "node:stream";
6
3
  import { fileURLToPath } from "node:url";
7
4
  import { normalizePath } from "vite";
8
5
  import { error } from "../core/logger/core.js";
@@ -14,10 +11,7 @@ import {
14
11
  } from "../core/path.js";
15
12
  import { VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
16
13
  import { isESMImportedImage } from "./internal.js";
17
- import { isLocalService } from "./services/service.js";
18
14
  import { emitESMImage } from "./utils/emitAsset.js";
19
- import { imageMetadata } from "./utils/metadata.js";
20
- import { getOrigQueryParams } from "./utils/queryParams.js";
21
15
  import { hashTransform, propsToFilename } from "./utils/transformToPath.js";
22
16
  const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
23
17
  const rawRE = /(?:\?|&)raw(?:&|$)/;
@@ -84,54 +78,6 @@ function assets({
84
78
  `;
85
79
  }
86
80
  },
87
- // Handle serving images during development
88
- configureServer(server) {
89
- server.middlewares.use(async (req, res, next) => {
90
- var _a2, _b;
91
- if ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/_image")) {
92
- if (!isLocalService(globalThis.astroAsset.imageService)) {
93
- return next();
94
- }
95
- const url = new URL(req.url, "file:");
96
- if (!url.searchParams.has("href")) {
97
- return next();
98
- }
99
- const filePath = (_b = url.searchParams.get("href")) == null ? void 0 : _b.slice("/@fs".length);
100
- const filePathURL = new URL("." + filePath, "file:");
101
- const file = await fs.readFile(filePathURL);
102
- let meta = getOrigQueryParams(filePathURL.searchParams);
103
- if (!meta) {
104
- meta = await imageMetadata(filePathURL, file);
105
- if (!meta) {
106
- return next();
107
- }
108
- }
109
- const transform = await globalThis.astroAsset.imageService.parseURL(
110
- url,
111
- settings.config.image.service.config
112
- );
113
- if (transform === void 0) {
114
- error(logging, "image", `Failed to parse transform for ${url}`);
115
- }
116
- let data = file;
117
- let format = meta.format;
118
- if (transform) {
119
- const result = await globalThis.astroAsset.imageService.transform(
120
- file,
121
- transform,
122
- settings.config.image.service.config
123
- );
124
- data = result.data;
125
- format = result.format;
126
- }
127
- res.setHeader("Content-Type", mime.getType(format) ?? `image/${format}`);
128
- res.setHeader("Cache-Control", "max-age=360000");
129
- const stream = Readable.from(data);
130
- return stream.pipe(res);
131
- }
132
- return next();
133
- });
134
- },
135
81
  buildStart() {
136
82
  if (mode != "build") {
137
83
  return;
@@ -17,10 +17,11 @@ async function loadSettings({ cmd, flags, logging }) {
17
17
  await handleConfigError(e, { cmd, cwd: root, flags, logging });
18
18
  return {};
19
19
  });
20
+ const mode = cmd === "build" ? "build" : "dev";
20
21
  if (!initialAstroConfig)
21
22
  return;
22
23
  telemetry.record(event.eventCliSession(cmd, initialUserConfig, flags));
23
- return createSettings(initialAstroConfig, root);
24
+ return createSettings(initialAstroConfig, mode, root);
24
25
  }
25
26
  async function handleConfigError(e, { cmd, cwd, flags, logging }) {
26
27
  const path = await resolveConfigPath({ cwd, flags, fs });
@@ -26,7 +26,7 @@ function getViteConfig(inlineConfig) {
26
26
  level: "info"
27
27
  };
28
28
  const { astroConfig: config } = await openConfig({ cmd });
29
- const settings = createSettings(config, inlineConfig.root);
29
+ const settings = createSettings(config, cmd, inlineConfig.root);
30
30
  await runHookConfigSetup({ settings, command: cmd, logging });
31
31
  const viteConfig = await createVite(
32
32
  {
@@ -1,4 +1,4 @@
1
1
  import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro';
2
- export declare function createBaseSettings(config: AstroConfig): AstroSettings;
3
- export declare function createSettings(config: AstroConfig, cwd?: string): AstroSettings;
2
+ export declare function createBaseSettings(config: AstroConfig, mode: 'build' | 'dev'): AstroSettings;
3
+ export declare function createSettings(config: AstroConfig, mode: 'build' | 'dev', cwd?: string): AstroSettings;
4
4
  export declare function createDefaultDevSettings(userConfig?: AstroUserConfig, root?: string | URL): Promise<AstroSettings>;
@@ -12,14 +12,14 @@ import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
12
12
  import { createDefaultDevConfig } from "./config.js";
13
13
  import { AstroTimer } from "./timer.js";
14
14
  import { loadTSConfig } from "./tsconfig.js";
15
- function createBaseSettings(config) {
15
+ function createBaseSettings(config, mode) {
16
16
  const { contentDir } = getContentPaths(config);
17
17
  return {
18
18
  config,
19
19
  tsConfig: void 0,
20
20
  tsConfigPath: void 0,
21
21
  adapter: void 0,
22
- injectedRoutes: config.experimental.assets && isServerLikeOutput(config) ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint", prerender: false }] : [],
22
+ injectedRoutes: config.experimental.assets && (isServerLikeOutput(config) || mode === "dev") ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint", prerender: false }] : [],
23
23
  pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
24
24
  contentEntryTypes: [markdownContentEntryType],
25
25
  dataEntryTypes: [
@@ -92,9 +92,9 @@ function createBaseSettings(config) {
92
92
  timer: new AstroTimer()
93
93
  };
94
94
  }
95
- function createSettings(config, cwd) {
95
+ function createSettings(config, mode, cwd) {
96
96
  const tsconfig = loadTSConfig(cwd);
97
- const settings = createBaseSettings(config);
97
+ const settings = createBaseSettings(config, mode);
98
98
  const watchFiles = (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : [];
99
99
  if (cwd) {
100
100
  watchFiles.push(fileURLToPath(new URL("./package.json", pathToFileURL(cwd))));
@@ -109,7 +109,7 @@ async function createDefaultDevSettings(userConfig = {}, root) {
109
109
  root = fileURLToPath(root);
110
110
  }
111
111
  const config = await createDefaultDevConfig(userConfig, root);
112
- return createBaseSettings(config);
112
+ return createBaseSettings(config, "dev");
113
113
  }
114
114
  export {
115
115
  createBaseSettings,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.9.1";
1
+ const ASTRO_VERSION = "2.9.2";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -54,7 +54,7 @@ async function dev(settings, options) {
54
54
  isRestart: options.isRestart
55
55
  })
56
56
  );
57
- const currentVersion = "2.9.1";
57
+ const currentVersion = "2.9.2";
58
58
  if (currentVersion.includes("-")) {
59
59
  warn(options.logging, null, msg.prerelease({ currentVersion }));
60
60
  }
@@ -62,7 +62,7 @@ async function restartContainer({
62
62
  });
63
63
  info(logging, "astro", logMsg + "\n");
64
64
  let astroConfig = newConfig.astroConfig;
65
- const settings = createSettings(astroConfig, resolvedRoot);
65
+ const settings = createSettings(astroConfig, "dev", resolvedRoot);
66
66
  await close();
67
67
  return {
68
68
  container: await createRestartedContainer(container, settings, needsStart),
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.9.1";
50
+ const version = "2.9.2";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
53
53
  const emptyPrefix = " ".repeat(11);
@@ -233,7 +233,7 @@ function printHelp({
233
233
  message.push(
234
234
  linebreak(),
235
235
  ` ${bgGreen(black(` ${commandName} `))} ${green(
236
- `v${"2.9.1"}`
236
+ `v${"2.9.2"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -89,7 +89,8 @@ function chunkToByteArray(result, chunk) {
89
89
  if (ArrayBuffer.isView(chunk)) {
90
90
  return chunk;
91
91
  } else {
92
- return encoder.encode(stringifyChunk(result, chunk));
92
+ const stringified = stringifyChunk(result, chunk);
93
+ return encoder.encode(stringified.toString());
93
94
  }
94
95
  }
95
96
  export {
@@ -17,7 +17,6 @@ async function cachedFullCompilation({
17
17
  tsconfigRaw: {
18
18
  compilerOptions: {
19
19
  // Ensure client:only imports are treeshaken
20
- // @ts-expect-error anticipate esbuild 0.18 feature
21
20
  verbatimModuleSyntax: false,
22
21
  importsNotUsedAsValues: "remove"
23
22
  }
@@ -121,7 +121,6 @@ function jsx({ settings, logging }) {
121
121
  tsconfigRaw: {
122
122
  compilerOptions: {
123
123
  // Ensure client:only imports are treeshaken
124
- // @ts-expect-error anticipate esbuild 0.18 feature
125
124
  verbatimModuleSyntax: false,
126
125
  importsNotUsedAsValues: "remove"
127
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
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",
@@ -155,7 +155,7 @@
155
155
  "typescript": "*",
156
156
  "unist-util-visit": "^4.1.2",
157
157
  "vfile": "^5.3.7",
158
- "vite": "^4.3.9",
158
+ "vite": "^4.4.6",
159
159
  "vitefu": "^0.2.4",
160
160
  "which-pm": "^2.0.0",
161
161
  "yargs-parser": "^21.1.1",