astro 2.0.17 → 2.1.0

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.
Files changed (142) hide show
  1. package/README.md +3 -3
  2. package/client-base.d.ts +27 -0
  3. package/client-image.d.ts +48 -0
  4. package/components/Image.astro +28 -0
  5. package/dist/@types/astro.d.ts +101 -1
  6. package/dist/assets/consts.d.ts +4 -0
  7. package/dist/assets/consts.js +20 -0
  8. package/dist/assets/image-endpoint.d.ts +5 -0
  9. package/dist/assets/image-endpoint.js +50 -0
  10. package/dist/assets/index.d.ts +4 -0
  11. package/dist/assets/index.js +10 -0
  12. package/dist/assets/internal.d.ts +36 -0
  13. package/dist/assets/internal.js +70 -0
  14. package/dist/assets/services/service.d.ts +71 -0
  15. package/dist/assets/services/service.js +88 -0
  16. package/dist/assets/services/sharp.d.ts +3 -0
  17. package/dist/assets/services/sharp.js +57 -0
  18. package/dist/assets/services/squoosh.d.ts +3 -0
  19. package/dist/assets/services/squoosh.js +56 -0
  20. package/dist/assets/services/vendor/squoosh/avif/avif_enc.d.js +11 -0
  21. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.d.ts +2 -0
  22. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +1628 -0
  23. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm +0 -0
  24. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.d.ts +2 -0
  25. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +1850 -0
  26. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm +0 -0
  27. package/dist/assets/services/vendor/squoosh/codecs.d.ts +158 -0
  28. package/dist/assets/services/vendor/squoosh/codecs.js +284 -0
  29. package/dist/assets/services/vendor/squoosh/copy-wasm.d.ts +1 -0
  30. package/dist/assets/services/vendor/squoosh/copy-wasm.js +24 -0
  31. package/dist/assets/services/vendor/squoosh/emscripten-types.d.js +0 -0
  32. package/dist/assets/services/vendor/squoosh/emscripten-utils.d.ts +9 -0
  33. package/dist/assets/services/vendor/squoosh/emscripten-utils.js +33 -0
  34. package/dist/assets/services/vendor/squoosh/image-pool.d.ts +4 -0
  35. package/dist/assets/services/vendor/squoosh/image-pool.js +94 -0
  36. package/dist/assets/services/vendor/squoosh/image.d.ts +14 -0
  37. package/dist/assets/services/vendor/squoosh/image.js +27 -0
  38. package/dist/assets/services/vendor/squoosh/image_data.d.ts +9 -0
  39. package/dist/assets/services/vendor/squoosh/image_data.js +22 -0
  40. package/dist/assets/services/vendor/squoosh/impl.d.ts +22 -0
  41. package/dist/assets/services/vendor/squoosh/impl.js +110 -0
  42. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_enc.d.js +11 -0
  43. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.d.ts +2 -0
  44. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +1631 -0
  45. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm +0 -0
  46. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.d.ts +2 -0
  47. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +1737 -0
  48. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm +0 -0
  49. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.d.ts +10 -0
  50. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.js +89 -0
  51. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm +0 -0
  52. package/dist/assets/services/vendor/squoosh/png/squoosh_png.d.ts +15 -0
  53. package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +138 -0
  54. package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm +0 -0
  55. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.d.ts +15 -0
  56. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.js +95 -0
  57. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm +0 -0
  58. package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm +0 -0
  59. package/dist/assets/services/vendor/squoosh/utils/execOnce.d.ts +1 -0
  60. package/dist/assets/services/vendor/squoosh/utils/execOnce.js +14 -0
  61. package/dist/assets/services/vendor/squoosh/utils/workerPool.d.ts +22 -0
  62. package/dist/assets/services/vendor/squoosh/utils/workerPool.js +95 -0
  63. package/dist/assets/services/vendor/squoosh/webp/webp_enc.d.js +4 -0
  64. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.d.ts +2 -0
  65. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +1473 -0
  66. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm +0 -0
  67. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.d.ts +2 -0
  68. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +1640 -0
  69. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm +0 -0
  70. package/dist/assets/types.d.ts +119 -0
  71. package/dist/assets/types.js +0 -0
  72. package/dist/assets/utils/etag.d.ts +12 -0
  73. package/dist/assets/utils/etag.js +28 -0
  74. package/dist/assets/utils/metadata.d.ts +6 -0
  75. package/dist/assets/utils/metadata.js +30 -0
  76. package/dist/assets/utils/queryParams.d.ts +2 -0
  77. package/dist/assets/utils/queryParams.js +16 -0
  78. package/dist/assets/utils/transformToPath.d.ts +2 -0
  79. package/dist/assets/utils/transformToPath.js +17 -0
  80. package/dist/assets/vite-plugin-assets.d.ts +5 -0
  81. package/dist/assets/vite-plugin-assets.js +187 -0
  82. package/dist/cli/check/index.d.ts +81 -2
  83. package/dist/cli/check/index.js +190 -44
  84. package/dist/cli/index.js +39 -16
  85. package/dist/cli/telemetry.js +1 -1
  86. package/dist/content/consts.d.ts +0 -1
  87. package/dist/content/consts.js +1 -3
  88. package/dist/content/internal.d.ts +7 -0
  89. package/dist/content/internal.js +27 -5
  90. package/dist/content/template/virtual-mod.d.mts +1 -0
  91. package/dist/content/types-generator.js +25 -10
  92. package/dist/content/utils.d.ts +16 -13
  93. package/dist/content/utils.js +29 -6
  94. package/dist/content/vite-plugin-content-assets.d.ts +3 -1
  95. package/dist/content/vite-plugin-content-assets.js +10 -6
  96. package/dist/content/vite-plugin-content-imports.js +54 -27
  97. package/dist/content/vite-plugin-content-virtual-mod.js +7 -4
  98. package/dist/core/add/index.js +2 -1
  99. package/dist/core/app/index.js +104 -134
  100. package/dist/core/build/generate.js +30 -5
  101. package/dist/core/build/index.d.ts +2 -0
  102. package/dist/core/build/index.js +16 -0
  103. package/dist/core/build/plugins/plugin-ssr.js +3 -5
  104. package/dist/core/config/config.js +2 -1
  105. package/dist/core/config/schema.d.ts +64 -8
  106. package/dist/core/config/schema.js +17 -3
  107. package/dist/core/config/settings.js +4 -2
  108. package/dist/core/constants.js +1 -1
  109. package/dist/core/cookies/cookies.js +36 -68
  110. package/dist/core/create-vite.js +5 -1
  111. package/dist/core/dev/dev.d.ts +2 -2
  112. package/dist/core/dev/dev.js +24 -4
  113. package/dist/core/errors/dev/vite.js +6 -1
  114. package/dist/core/errors/errors-data.d.ts +17 -1
  115. package/dist/core/errors/errors-data.js +16 -0
  116. package/dist/core/messages.js +2 -2
  117. package/dist/core/path.d.ts +1 -0
  118. package/dist/core/path.js +4 -0
  119. package/dist/core/preview/index.d.ts +3 -1
  120. package/dist/core/preview/index.js +16 -1
  121. package/dist/core/render/dev/css.js +2 -2
  122. package/dist/core/render/dev/environment.js +1 -5
  123. package/dist/core/render/environment.js +1 -2
  124. package/dist/core/render/result.js +13 -35
  125. package/dist/core/sync/index.d.ts +18 -5
  126. package/dist/core/sync/index.js +13 -1
  127. package/dist/integrations/index.js +12 -1
  128. package/dist/runtime/server/render/component.js +1 -1
  129. package/dist/runtime/server/response.js +11 -30
  130. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  131. package/dist/vite-plugin-astro-server/plugin.js +1 -1
  132. package/dist/vite-plugin-env/index.js +4 -4
  133. package/dist/vite-plugin-inject-env-ts/index.js +17 -2
  134. package/dist/vite-plugin-markdown/content-entry-type.d.ts +7 -0
  135. package/dist/vite-plugin-markdown/content-entry-type.js +39 -0
  136. package/dist/vite-plugin-markdown/index.js +70 -4
  137. package/dist/vite-plugin-ssr-manifest/index.d.ts +2 -0
  138. package/dist/vite-plugin-ssr-manifest/index.js +25 -0
  139. package/package.json +26 -9
  140. package/src/content/template/types.d.ts +18 -9
  141. package/src/content/template/virtual-mod.mjs +6 -0
  142. package/tsconfigs/base.json +6 -1
@@ -0,0 +1,119 @@
1
+ import { VALID_INPUT_FORMATS, VALID_OUTPUT_FORMATS } from './consts.js';
2
+ import { ImageService } from './services/service.js';
3
+ export type ImageQualityPreset = 'low' | 'mid' | 'high' | 'max' | (string & {});
4
+ export type ImageQuality = ImageQualityPreset | number;
5
+ export type InputFormat = (typeof VALID_INPUT_FORMATS)[number] | (string & {});
6
+ export type OutputFormat = (typeof VALID_OUTPUT_FORMATS)[number] | (string & {});
7
+ declare global {
8
+ var astroAsset: {
9
+ imageService?: ImageService;
10
+ addStaticImage?: ((options: ImageTransform) => string) | undefined;
11
+ staticImages?: Map<ImageTransform, string>;
12
+ };
13
+ }
14
+ /**
15
+ * Type returned by ESM imports of images and direct calls to imageMetadata
16
+ */
17
+ export interface ImageMetadata {
18
+ src: string;
19
+ width: number;
20
+ height: number;
21
+ format: InputFormat;
22
+ }
23
+ /**
24
+ * Options accepted by the image transformation service.
25
+ */
26
+ export type ImageTransform = {
27
+ src: ImageMetadata | string;
28
+ width?: number;
29
+ height?: number;
30
+ quality?: ImageQuality;
31
+ format?: OutputFormat;
32
+ [key: string]: any;
33
+ };
34
+ type WithRequired<T, K extends keyof T> = T & {
35
+ [P in K]-?: T[P];
36
+ };
37
+ type ImageSharedProps<T> = T & {
38
+ /**
39
+ * Width of the image, the value of this property will be used to assign the `width` property on the final `img` element.
40
+ *
41
+ * For local images, this value will additionally be used to resize the image to the desired width, taking into account the original aspect ratio of the image.
42
+ *
43
+ * **Example**:
44
+ * ```astro
45
+ * <Image src={...} width={300} alt="..." />
46
+ * ```
47
+ * **Result**:
48
+ * ```html
49
+ * <img src="..." width="300" height="..." alt="..." />
50
+ * ```
51
+ */
52
+ width?: number | `${number}`;
53
+ /**
54
+ * Height of the image, the value of this property will be used to assign the `height` property on the final `img` element.
55
+ *
56
+ * For local images, if `width` is not present, this value will additionally be used to resize the image to the desired height, taking into account the original aspect ratio of the image.
57
+ *
58
+ * **Example**:
59
+ * ```astro
60
+ * <Image src={...} height={300} alt="..." />
61
+ * ```
62
+ * **Result**:
63
+ * ```html
64
+ * <img src="..." height="300" width="..." alt="..." />
65
+ * ```
66
+ */
67
+ height?: number | `${number}`;
68
+ };
69
+ export type LocalImageProps<T> = ImageSharedProps<T> & {
70
+ /**
71
+ * A reference to a local image imported through an ESM import.
72
+ *
73
+ * **Example**:
74
+ * ```js
75
+ * import myImage from "~/assets/my_image.png";
76
+ * ```
77
+ * And then refer to the image, like so:
78
+ * ```astro
79
+ * <Image src={myImage} alt="..."></Image>
80
+ * ```
81
+ */
82
+ src: ImageMetadata;
83
+ /**
84
+ * Desired output format for the image. Defaults to `webp`.
85
+ *
86
+ * **Example**:
87
+ * ```astro
88
+ * <Image src={...} format="avif" alt="..." />
89
+ * ```
90
+ */
91
+ format?: OutputFormat;
92
+ /**
93
+ * Desired quality for the image. Value can either be a preset such as `low` or `high`, or a numeric value from 0 to 100.
94
+ *
95
+ * The perceptual quality of the output image is loader-specific.
96
+ * For instance, a certain service might decide that `high` results in a very beautiful image, but another could choose for it to be at best passable.
97
+ *
98
+ * **Example**:
99
+ * ```astro
100
+ * <Image src={...} quality='high' alt="..." />
101
+ * <Image src={...} quality={300} alt="..." />
102
+ * ```
103
+ */
104
+ quality?: ImageQuality;
105
+ };
106
+ export type RemoteImageProps<T> = WithRequired<ImageSharedProps<T>, 'width' | 'height'> & {
107
+ /**
108
+ * URL of a remote image. Can start with a protocol (ex: `https://`) or alternatively `/`, or `Astro.url`, for images in the `public` folder
109
+ *
110
+ * Remote images are not optimized, and require both `width` and `height` to be set.
111
+ *
112
+ * **Example**:
113
+ * ```
114
+ * <Image src="https://example.com/image.png" width={450} height={300} alt="..." />
115
+ * ```
116
+ */
117
+ src: string;
118
+ };
119
+ export {};
File without changes
@@ -0,0 +1,12 @@
1
+ /**
2
+ * FNV-1a Hash implementation
3
+ * @author Travis Webb (tjwebb) <me@traviswebb.com>
4
+ *
5
+ * Ported from https://github.com/tjwebb/fnv-plus/blob/master/index.js
6
+ * License https://github.com/tjwebb/fnv-plus#license
7
+ *
8
+ * Simplified, optimized and add modified for 52 bit, which provides a larger hash space
9
+ * and still making use of Javascript's 53-bit integer space.
10
+ */
11
+ export declare const fnv1a52: (str: string) => number;
12
+ export declare const etag: (payload: string, weak?: boolean) => string;
@@ -0,0 +1,28 @@
1
+ const fnv1a52 = (str) => {
2
+ const len = str.length;
3
+ let i = 0, t0 = 0, v0 = 8997, t1 = 0, v1 = 33826, t2 = 0, v2 = 40164, t3 = 0, v3 = 52210;
4
+ while (i < len) {
5
+ v0 ^= str.charCodeAt(i++);
6
+ t0 = v0 * 435;
7
+ t1 = v1 * 435;
8
+ t2 = v2 * 435;
9
+ t3 = v3 * 435;
10
+ t2 += v0 << 8;
11
+ t3 += v1 << 8;
12
+ t1 += t0 >>> 16;
13
+ v0 = t0 & 65535;
14
+ t2 += t1 >>> 16;
15
+ v1 = t1 & 65535;
16
+ v3 = t3 + (t2 >>> 16) & 65535;
17
+ v2 = t2 & 65535;
18
+ }
19
+ return (v3 & 15) * 281474976710656 + v2 * 4294967296 + v1 * 65536 + (v0 ^ v3 >> 4);
20
+ };
21
+ const etag = (payload, weak = false) => {
22
+ const prefix = weak ? 'W/"' : '"';
23
+ return prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"';
24
+ };
25
+ export {
26
+ etag,
27
+ fnv1a52
28
+ };
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { ImageMetadata } from '../types.js';
3
+ export interface Metadata extends ImageMetadata {
4
+ orientation?: number;
5
+ }
6
+ export declare function imageMetadata(src: URL | string, data?: Buffer): Promise<Metadata | undefined>;
@@ -0,0 +1,30 @@
1
+ import { createRequire } from "module";
2
+ import fs from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+ const require2 = createRequire(import.meta.url);
5
+ const sizeOf = require2("image-size");
6
+ async function imageMetadata(src, data) {
7
+ let file = data;
8
+ if (!file) {
9
+ try {
10
+ file = await fs.readFile(src);
11
+ } catch (e) {
12
+ return void 0;
13
+ }
14
+ }
15
+ const { width, height, type, orientation } = await sizeOf(file);
16
+ const isPortrait = (orientation || 0) >= 5;
17
+ if (!width || !height || !type) {
18
+ return void 0;
19
+ }
20
+ return {
21
+ src: fileURLToPath(src),
22
+ width: isPortrait ? height : width,
23
+ height: isPortrait ? width : height,
24
+ format: type,
25
+ orientation
26
+ };
27
+ }
28
+ export {
29
+ imageMetadata
30
+ };
@@ -0,0 +1,2 @@
1
+ import { ImageMetadata } from '../types.js';
2
+ export declare function getOrigQueryParams(params: URLSearchParams): Omit<ImageMetadata, 'src'> | undefined;
@@ -0,0 +1,16 @@
1
+ function getOrigQueryParams(params) {
2
+ const width = params.get("origWidth");
3
+ const height = params.get("origHeight");
4
+ const format = params.get("origFormat");
5
+ if (!width || !height || !format) {
6
+ return void 0;
7
+ }
8
+ return {
9
+ width: parseInt(width),
10
+ height: parseInt(height),
11
+ format
12
+ };
13
+ }
14
+ export {
15
+ getOrigQueryParams
16
+ };
@@ -0,0 +1,2 @@
1
+ import { ImageTransform } from '../types.js';
2
+ export declare function propsToFilename(transform: ImageTransform): string;
@@ -0,0 +1,17 @@
1
+ import { basename, extname } from "path";
2
+ import { removeQueryString } from "../../core/path.js";
3
+ import { shorthash } from "../../runtime/server/shorthash.js";
4
+ import { isESMImportedImage } from "../internal.js";
5
+ function propsToFilename(transform) {
6
+ if (!isESMImportedImage(transform.src)) {
7
+ return transform.src;
8
+ }
9
+ let filename = removeQueryString(transform.src.src);
10
+ const ext = extname(filename);
11
+ filename = basename(filename, ext);
12
+ const outputExt = transform.format ? `.${transform.format}` : ext;
13
+ return `/${filename}_${shorthash(JSON.stringify(transform))}${outputExt}`;
14
+ }
15
+ export {
16
+ propsToFilename
17
+ };
@@ -0,0 +1,5 @@
1
+ import type * as vite from 'vite';
2
+ import { AstroPluginOptions } from '../@types/astro';
3
+ export default function assets({ settings, logging, mode, }: AstroPluginOptions & {
4
+ mode: string;
5
+ }): vite.Plugin[];
@@ -0,0 +1,187 @@
1
+ import MagicString from "magic-string";
2
+ import mime from "mime";
3
+ import fs from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { Readable } from "node:stream";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { normalizePath } from "vite";
8
+ import { error } from "../core/logger/core.js";
9
+ import { joinPaths, prependForwardSlash } from "../core/path.js";
10
+ import { VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
11
+ import { isESMImportedImage } from "./internal.js";
12
+ import { isLocalService } from "./services/service.js";
13
+ import { copyWasmFiles } from "./services/vendor/squoosh/copy-wasm.js";
14
+ import { imageMetadata } from "./utils/metadata.js";
15
+ import { getOrigQueryParams } from "./utils/queryParams.js";
16
+ import { propsToFilename } from "./utils/transformToPath.js";
17
+ const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
18
+ function assets({
19
+ settings,
20
+ logging,
21
+ mode
22
+ }) {
23
+ let resolvedConfig;
24
+ globalThis.astroAsset = {};
25
+ return [
26
+ {
27
+ name: "astro:assets",
28
+ config() {
29
+ return {
30
+ resolve: {
31
+ alias: [
32
+ {
33
+ find: /^~\/assets\/(.+)$/,
34
+ replacement: fileURLToPath(new URL("./assets/$1", settings.config.srcDir))
35
+ }
36
+ ]
37
+ }
38
+ };
39
+ },
40
+ async resolveId(id) {
41
+ if (id === VIRTUAL_SERVICE_ID) {
42
+ return await this.resolve(settings.config.image.service);
43
+ }
44
+ if (id === VIRTUAL_MODULE_ID) {
45
+ return resolvedVirtualModuleId;
46
+ }
47
+ },
48
+ load(id) {
49
+ if (id === resolvedVirtualModuleId) {
50
+ return `
51
+ export { getImage, getConfiguredImageService } from "astro/assets";
52
+ export { default as Image } from "astro/components/Image.astro";
53
+ `;
54
+ }
55
+ },
56
+ configureServer(server) {
57
+ server.middlewares.use(async (req, res, next) => {
58
+ var _a;
59
+ if ((_a = req.url) == null ? void 0 : _a.startsWith("/_image")) {
60
+ if (!isLocalService(globalThis.astroAsset.imageService)) {
61
+ return next();
62
+ }
63
+ const url = new URL(req.url, "file:");
64
+ const filePath = url.searchParams.get("href");
65
+ if (!filePath) {
66
+ return next();
67
+ }
68
+ const filePathURL = new URL(filePath, "file:");
69
+ const file = await fs.readFile(filePathURL.pathname);
70
+ let meta = getOrigQueryParams(filePathURL.searchParams);
71
+ if (!meta) {
72
+ meta = await imageMetadata(filePathURL, file);
73
+ if (!meta) {
74
+ return next();
75
+ }
76
+ }
77
+ const transform = await globalThis.astroAsset.imageService.parseURL(url);
78
+ if (transform === void 0) {
79
+ error(logging, "image", `Failed to parse transform for ${url}`);
80
+ }
81
+ let data = file;
82
+ let format = meta.format;
83
+ if (transform) {
84
+ const result = await globalThis.astroAsset.imageService.transform(file, transform);
85
+ data = result.data;
86
+ format = result.format;
87
+ }
88
+ res.setHeader("Content-Type", mime.getType(fileURLToPath(url)) || `image/${format}`);
89
+ res.setHeader("Cache-Control", "max-age=360000");
90
+ const stream = Readable.from(data);
91
+ return stream.pipe(res);
92
+ }
93
+ return next();
94
+ });
95
+ },
96
+ buildStart() {
97
+ if (mode != "build") {
98
+ return;
99
+ }
100
+ globalThis.astroAsset.addStaticImage = (options) => {
101
+ if (!globalThis.astroAsset.staticImages) {
102
+ globalThis.astroAsset.staticImages = /* @__PURE__ */ new Map();
103
+ }
104
+ let filePath;
105
+ if (globalThis.astroAsset.staticImages.has(options)) {
106
+ filePath = globalThis.astroAsset.staticImages.get(options);
107
+ } else {
108
+ if (!isESMImportedImage(options.src)) {
109
+ return options.src;
110
+ }
111
+ filePath = prependForwardSlash(
112
+ joinPaths(
113
+ settings.config.base,
114
+ settings.config.build.assets,
115
+ propsToFilename(options)
116
+ )
117
+ );
118
+ globalThis.astroAsset.staticImages.set(options, filePath);
119
+ }
120
+ return filePath;
121
+ };
122
+ },
123
+ async buildEnd() {
124
+ if (mode != "build") {
125
+ return;
126
+ }
127
+ const dir = settings.config.output === "server" ? settings.config.build.server : settings.config.outDir;
128
+ await copyWasmFiles(new URL("./chunks", dir));
129
+ },
130
+ async renderChunk(code) {
131
+ const assetUrlRE = /__ASTRO_ASSET_IMAGE__([a-z\d]{8})__(?:_(.*?)__)?/g;
132
+ let match;
133
+ let s;
134
+ while (match = assetUrlRE.exec(code)) {
135
+ s = s || (s = new MagicString(code));
136
+ const [full, hash, postfix = ""] = match;
137
+ const file = this.getFileName(hash);
138
+ const outputFilepath = normalizePath(resolvedConfig.base + file + postfix);
139
+ s.overwrite(match.index, match.index + full.length, outputFilepath);
140
+ }
141
+ if (s) {
142
+ return {
143
+ code: s.toString(),
144
+ map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: true }) : null
145
+ };
146
+ } else {
147
+ return null;
148
+ }
149
+ }
150
+ },
151
+ {
152
+ name: "astro:assets:esm",
153
+ enforce: "pre",
154
+ configResolved(viteConfig) {
155
+ resolvedConfig = viteConfig;
156
+ },
157
+ async load(id) {
158
+ if (/\.(heic|heif|avif|jpeg|jpg|png|tiff|webp|gif)$/.test(id)) {
159
+ const url = pathToFileURL(id);
160
+ const meta = await imageMetadata(url);
161
+ if (!meta) {
162
+ return;
163
+ }
164
+ if (!this.meta.watchMode) {
165
+ const pathname = decodeURI(url.pathname);
166
+ const filename = path.basename(pathname, path.extname(pathname) + `.${meta.format}`);
167
+ const handle = this.emitFile({
168
+ name: filename,
169
+ source: await fs.readFile(url),
170
+ type: "asset"
171
+ });
172
+ meta.src = `__ASTRO_ASSET_IMAGE__${handle}__`;
173
+ } else {
174
+ url.searchParams.append("origWidth", meta.width.toString());
175
+ url.searchParams.append("origHeight", meta.height.toString());
176
+ url.searchParams.append("origFormat", meta.format);
177
+ meta.src = url.toString();
178
+ }
179
+ return `export default ${JSON.stringify(meta)}`;
180
+ }
181
+ }
182
+ }
183
+ ];
184
+ }
185
+ export {
186
+ assets as default
187
+ };
@@ -1,5 +1,84 @@
1
+ /// <reference types="node" />
2
+ import { AstroCheck } from '@astrojs/language-server';
3
+ import fsMod from 'fs';
4
+ import type { Arguments as Flags } from 'yargs-parser';
1
5
  import type { AstroSettings } from '../../@types/astro';
2
6
  import type { LogOptions } from '../../core/logger/core.js';
3
- export declare function check(settings: AstroSettings, { logging }: {
7
+ import type { ProcessExit, SyncOptions } from '../../core/sync';
8
+ export type CheckPayload = {
9
+ /**
10
+ * Flags passed via CLI
11
+ */
12
+ flags: Flags;
13
+ /**
14
+ * Logging options
15
+ */
4
16
  logging: LogOptions;
5
- }): Promise<0 | 1>;
17
+ };
18
+ /**
19
+ *
20
+ * Types of response emitted by the checker
21
+ */
22
+ export declare enum CheckResult {
23
+ /**
24
+ * Operation finished without errors
25
+ */
26
+ ExitWithSuccess = 0,
27
+ /**
28
+ * Operation finished with errors
29
+ */
30
+ ExitWithError = 1,
31
+ /**
32
+ * The consumer should not terminate the operation
33
+ */
34
+ Listen = 2
35
+ }
36
+ /**
37
+ * Checks `.astro` files for possible errors.
38
+ *
39
+ * If the `--watch` flag is provided, the command runs indefinitely and provides diagnostics
40
+ * when `.astro` files are modified.
41
+ *
42
+ * Every time an astro files is modified, content collections are also generated.
43
+ *
44
+ * @param {AstroSettings} settings
45
+ * @param {CheckPayload} options Options passed {@link AstroChecker}
46
+ * @param {Flags} options.flags Flags coming from the CLI
47
+ * @param {LogOptions} options.logging Logging options
48
+ */
49
+ export declare function check(settings: AstroSettings, { logging, flags }: CheckPayload): Promise<AstroChecker | undefined>;
50
+ type CheckerConstructor = {
51
+ diagnosticChecker: AstroCheck;
52
+ isWatchMode: boolean;
53
+ syncCli: (settings: AstroSettings, options: SyncOptions) => Promise<ProcessExit>;
54
+ settings: Readonly<AstroSettings>;
55
+ logging: Readonly<LogOptions>;
56
+ fileSystem: typeof fsMod;
57
+ };
58
+ /**
59
+ * Responsible to check files - classic or watch mode - and report diagnostics.
60
+ *
61
+ * When in watch mode, the class does a whole check pass, and then starts watching files.
62
+ * When a change occurs to an `.astro` file, the checker builds content collections again and lint all the `.astro` files.
63
+ */
64
+ export declare class AstroChecker {
65
+ #private;
66
+ constructor({ diagnosticChecker, isWatchMode, syncCli, settings, fileSystem, logging, }: CheckerConstructor);
67
+ /**
68
+ * Check all `.astro` files once and then finishes the operation.
69
+ */
70
+ check(): Promise<CheckResult>;
71
+ /**
72
+ * Check all `.astro` files and then start watching for changes.
73
+ */
74
+ watch(): Promise<CheckResult>;
75
+ /**
76
+ * Stops the watch. It terminates the inner server.
77
+ */
78
+ stop(): Promise<void>;
79
+ /**
80
+ * Whether the checker should run in watch mode
81
+ */
82
+ get isWatchMode(): boolean;
83
+ }
84
+ export {};