astro 7.2.9 → 7.3.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.
- package/dist/assets/build/generate.d.ts +1 -1
- package/dist/assets/build/generate.js +3 -1
- package/dist/assets/endpoint/dev.js +6 -5
- package/dist/assets/endpoint/generic.js +5 -4
- package/dist/assets/endpoint/node.js +3 -3
- package/dist/assets/endpoint/shared.d.ts +3 -1
- package/dist/assets/endpoint/shared.js +9 -3
- package/dist/assets/fonts/config.d.ts +2 -2
- package/dist/assets/internal.d.ts +2 -1
- package/dist/assets/internal.js +11 -10
- package/dist/assets/services/service.d.ts +8 -7
- package/dist/assets/services/sharp.js +5 -5
- package/dist/assets/vite-plugin-assets.js +22 -5
- package/dist/cli/add/index.js +3 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/cli/preferences/index.js +32 -30
- package/dist/cli/preview/index.js +44 -1
- package/dist/cli/telemetry/index.d.ts +2 -1
- package/dist/cli/telemetry/index.js +2 -2
- package/dist/content/content-layer.js +3 -3
- package/dist/content/data-store-writer.d.ts +18 -5
- package/dist/content/data-store-writer.js +11 -3
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +5 -1
- package/dist/content/mutable-data-store.d.ts +13 -1
- package/dist/content/mutable-data-store.js +35 -5
- package/dist/content/runtime.d.ts +8 -3
- package/dist/content/runtime.js +43 -32
- package/dist/content/types-generator.js +2 -1
- package/dist/content/utils.d.ts +5 -35
- package/dist/content/utils.js +71 -65
- package/dist/content/vite-plugin-content-imports.js +2 -1
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +11 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +36 -3
- package/dist/core/app/entrypoints/index.d.ts +4 -2
- package/dist/core/app/entrypoints/index.js +13 -11
- package/dist/core/app/entrypoints/virtual/dev.js +2 -2
- package/dist/core/app/prerender.d.ts +32 -0
- package/dist/core/app/prerender.js +22 -0
- package/dist/core/build/default-prerenderer.js +5 -2
- package/dist/core/build/generate.d.ts +3 -1
- package/dist/core/build/generate.js +40 -62
- package/dist/core/build/plugins/plugin-manifest.js +1 -1
- package/dist/core/cache/handler.js +12 -1
- package/dist/core/cache/memory-provider.js +35 -8
- package/dist/core/cache/runtime/cache.js +3 -0
- package/dist/core/cache/types.d.ts +2 -0
- package/dist/core/config/schemas/base.d.ts +5 -5
- package/dist/core/config/schemas/relative.d.ts +7 -7
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.d.ts +2 -1
- package/dist/core/cookies/cookies.js +5 -4
- package/dist/core/dev/dev.js +5 -3
- package/dist/core/fetch/fetch-state.d.ts +1 -1
- package/dist/core/fetch/fetch-state.js +4 -23
- package/dist/core/logger/core.d.ts +2 -0
- package/dist/core/logger/core.js +14 -0
- package/dist/core/logger/vite-plugin.d.ts +13 -2
- package/dist/core/logger/vite-plugin.js +8 -7
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/index.js +14 -1
- package/dist/core/render-scope/collect.d.ts +24 -0
- package/dist/core/render-scope/collect.js +27 -0
- package/dist/core/render-scope/node-scope.d.ts +10 -0
- package/dist/core/render-scope/node-scope.js +8 -0
- package/dist/core/render-scope/record.d.ts +14 -0
- package/dist/core/render-scope/record.js +12 -0
- package/dist/core/render-scope/scope.d.ts +38 -0
- package/dist/core/render-scope/scope.js +28 -0
- package/dist/core/rewrites/handler.js +1 -1
- package/dist/core/routing/create-manifest.js +5 -1
- package/dist/core/server-islands/endpoint.js +4 -1
- package/dist/core/server-islands/vite-plugin-server-islands.js +2 -2
- package/dist/core/sync/index.js +1 -1
- package/dist/core/util.d.ts +0 -9
- package/dist/core/util.js +0 -34
- package/dist/core/viteUtils.d.ts +1 -13
- package/dist/core/viteUtils.js +3 -33
- package/dist/types/public/integrations.d.ts +20 -13
- package/dist/vite-plugin-app/createAstroServerApp.js +1 -1
- package/dist/vite-plugin-routes/index.js +22 -8
- package/package.json +6 -6
- package/templates/content/module.mjs +13 -5
- package/dist/core/build/incremental-content-collector.d.ts +0 -10
- package/dist/core/build/incremental-content-collector.js +0 -33
- package/dist/core/build/incremental-image-collector.d.ts +0 -11
- package/dist/core/build/incremental-image-collector.js +0 -32
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StaticBuildOptions } from '../../core/build/types.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type AstroLogger } from '../../core/logger/core.js';
|
|
3
3
|
import type { MapValue } from '../../type-utils.js';
|
|
4
4
|
import type { AstroConfig } from '../../types/public/config.js';
|
|
5
5
|
import type { AssetsGlobalStaticImagesList, SerializedStaticImage } from '../types.js';
|
|
@@ -4,6 +4,7 @@ import colors from "piccolore";
|
|
|
4
4
|
import { getTimeStat } from "../../core/build/util.js";
|
|
5
5
|
import { AstroError } from "../../core/errors/errors.js";
|
|
6
6
|
import { AstroErrorData } from "../../core/errors/index.js";
|
|
7
|
+
import { astroToRuntimeLogger } from "../../core/logger/core.js";
|
|
7
8
|
import { isRemotePath, removeLeadingForwardSlash } from "../../core/path.js";
|
|
8
9
|
import { getClientOutputDirectory } from "../../prerender/utils.js";
|
|
9
10
|
import { getConfiguredImageService } from "../internal.js";
|
|
@@ -165,7 +166,8 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env) {
|
|
|
165
166
|
resultData.data = (await imageService.transform(
|
|
166
167
|
originalImage.data,
|
|
167
168
|
{ ...options, src: originalImagePath },
|
|
168
|
-
env.imageConfig
|
|
169
|
+
env.imageConfig,
|
|
170
|
+
astroToRuntimeLogger(env.logger)
|
|
169
171
|
)).data;
|
|
170
172
|
} catch (e) {
|
|
171
173
|
if (AstroError.is(e)) {
|
|
@@ -44,16 +44,17 @@ async function loadLocalImage(src, url) {
|
|
|
44
44
|
}
|
|
45
45
|
return returnValue;
|
|
46
46
|
}
|
|
47
|
-
const GET = async ({ request }) => {
|
|
47
|
+
const GET = async ({ request, logger }) => {
|
|
48
48
|
if (!import.meta.env.DEV) {
|
|
49
|
-
|
|
49
|
+
logger.error("The dev image endpoint can only be used in dev mode.");
|
|
50
50
|
return new Response("Invalid endpoint", { status: 500 });
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
53
|
-
return await handleImageRequest({ request, loadLocalImage });
|
|
53
|
+
return await handleImageRequest({ request, loadLocalImage, logger });
|
|
54
54
|
} catch (err) {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const message = `Could not process image request: ${err}`;
|
|
56
|
+
logger.error(message);
|
|
57
|
+
return new Response(message, {
|
|
57
58
|
status: 500
|
|
58
59
|
});
|
|
59
60
|
}
|
|
@@ -5,14 +5,14 @@ import * as mime from "mrmime";
|
|
|
5
5
|
import { getConfiguredImageService } from "../internal.js";
|
|
6
6
|
import { etag } from "../utils/etag.js";
|
|
7
7
|
import { loadImage } from "./loadImage.js";
|
|
8
|
-
const GET = async ({ request }) => {
|
|
8
|
+
const GET = async ({ request, logger }) => {
|
|
9
9
|
try {
|
|
10
10
|
const imageService = await getConfiguredImageService();
|
|
11
11
|
if (!("transform" in imageService)) {
|
|
12
12
|
throw new Error("Configured image service is not a local service");
|
|
13
13
|
}
|
|
14
14
|
const url = new URL(request.url);
|
|
15
|
-
const transform = await imageService.parseURL(url, imageConfig);
|
|
15
|
+
const transform = await imageService.parseURL(url, imageConfig, logger);
|
|
16
16
|
if (!transform?.src) {
|
|
17
17
|
throw new Error("Incorrect transform returned by `parseURL`");
|
|
18
18
|
}
|
|
@@ -37,7 +37,8 @@ const GET = async ({ request }) => {
|
|
|
37
37
|
const { data, format } = await imageService.transform(
|
|
38
38
|
new Uint8Array(inputBuffer),
|
|
39
39
|
transform,
|
|
40
|
-
imageConfig
|
|
40
|
+
imageConfig,
|
|
41
|
+
logger
|
|
41
42
|
);
|
|
42
43
|
return new Response(data, {
|
|
43
44
|
status: 200,
|
|
@@ -49,7 +50,7 @@ const GET = async ({ request }) => {
|
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
} catch (err) {
|
|
52
|
-
|
|
53
|
+
logger.error(`Could not process image request: ${err}`);
|
|
53
54
|
return new Response("Internal Server Error", { status: 500 });
|
|
54
55
|
}
|
|
55
56
|
};
|
|
@@ -26,11 +26,11 @@ async function loadLocalImage(src, url) {
|
|
|
26
26
|
return void 0;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
const GET = async ({ request }) => {
|
|
29
|
+
const GET = async ({ request, logger }) => {
|
|
30
30
|
try {
|
|
31
|
-
return await handleImageRequest({ request, loadLocalImage });
|
|
31
|
+
return await handleImageRequest({ request, loadLocalImage, logger });
|
|
32
32
|
} catch (err) {
|
|
33
|
-
|
|
33
|
+
logger.error(`Could not process image request: ${err}`);
|
|
34
34
|
return new Response("Internal Server Error", {
|
|
35
35
|
status: 500
|
|
36
36
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { AstroRuntimeLogger } from '../../types/public/context.js';
|
|
1
2
|
export declare function loadRemoteImage(src: URL): Promise<Buffer | undefined>;
|
|
2
|
-
export declare const handleImageRequest: ({ request, loadLocalImage, }: {
|
|
3
|
+
export declare const handleImageRequest: ({ request, loadLocalImage, logger, }: {
|
|
3
4
|
request: Request;
|
|
4
5
|
loadLocalImage: (src: string, baseUrl: URL) => Promise<Buffer | undefined>;
|
|
6
|
+
logger: AstroRuntimeLogger;
|
|
5
7
|
}) => Promise<Response>;
|
|
@@ -26,14 +26,15 @@ async function loadRemoteImage(src) {
|
|
|
26
26
|
}
|
|
27
27
|
const handleImageRequest = async ({
|
|
28
28
|
request,
|
|
29
|
-
loadLocalImage
|
|
29
|
+
loadLocalImage,
|
|
30
|
+
logger
|
|
30
31
|
}) => {
|
|
31
32
|
const imageService = await getConfiguredImageService();
|
|
32
33
|
if (!("transform" in imageService)) {
|
|
33
34
|
throw new Error("Configured image service is not a local service");
|
|
34
35
|
}
|
|
35
36
|
const url = new URL(request.url);
|
|
36
|
-
const transform = await imageService.parseURL(url, imageConfig);
|
|
37
|
+
const transform = await imageService.parseURL(url, imageConfig, logger);
|
|
37
38
|
if (!transform?.src) {
|
|
38
39
|
return new Response("Invalid request", { status: 400 });
|
|
39
40
|
}
|
|
@@ -55,7 +56,12 @@ const handleImageRequest = async ({
|
|
|
55
56
|
if (!inputBuffer) {
|
|
56
57
|
return new Response("Internal Server Error", { status: 500 });
|
|
57
58
|
}
|
|
58
|
-
const { data, format } = await imageService.transform(
|
|
59
|
+
const { data, format } = await imageService.transform(
|
|
60
|
+
inputBuffer,
|
|
61
|
+
transform,
|
|
62
|
+
imageConfig,
|
|
63
|
+
logger
|
|
64
|
+
);
|
|
59
65
|
return new Response(data, {
|
|
60
66
|
status: 200,
|
|
61
67
|
headers: {
|
|
@@ -7,8 +7,8 @@ export declare const StyleSchema: z.ZodEnum<{
|
|
|
7
7
|
oblique: "oblique";
|
|
8
8
|
}>;
|
|
9
9
|
export declare const DisplaySchema: z.ZodEnum<{
|
|
10
|
-
auto: "auto";
|
|
11
10
|
optional: "optional";
|
|
11
|
+
auto: "auto";
|
|
12
12
|
fallback: "fallback";
|
|
13
13
|
block: "block";
|
|
14
14
|
swap: "swap";
|
|
@@ -45,8 +45,8 @@ export declare const FontFamilySchema: z.ZodObject<{
|
|
|
45
45
|
fallbacks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
46
46
|
optimizedFallbacks: z.ZodOptional<z.ZodBoolean>;
|
|
47
47
|
display: z.ZodOptional<z.ZodEnum<{
|
|
48
|
-
auto: "auto";
|
|
49
48
|
optional: "optional";
|
|
49
|
+
auto: "auto";
|
|
50
50
|
fallback: "fallback";
|
|
51
51
|
block: "block";
|
|
52
52
|
swap: "swap";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AstroConfig } from '../types/public/config.js';
|
|
2
|
+
import type { AstroRuntimeLogger } from '../types/public/context.js';
|
|
2
3
|
import type { AstroAdapterClientConfig } from '../types/public/integrations.js';
|
|
3
4
|
import { type ImageService } from './services/service.js';
|
|
4
5
|
import { type GetImageResult, type UnresolvedImageTransform } from './types.js';
|
|
5
6
|
export { verifyOptions } from './services/service.js';
|
|
6
7
|
export declare const cssFitValues: string[];
|
|
7
8
|
export declare function getConfiguredImageService(): Promise<ImageService>;
|
|
8
|
-
export declare function getImage(options: UnresolvedImageTransform, imageConfig: AstroConfig['image'] & AstroAdapterClientConfig): Promise<GetImageResult>;
|
|
9
|
+
export declare function getImage(options: UnresolvedImageTransform, imageConfig: AstroConfig['image'] & AstroAdapterClientConfig, logger: AstroRuntimeLogger): Promise<GetImageResult>;
|
package/dist/assets/internal.js
CHANGED
|
@@ -34,7 +34,7 @@ async function getConfiguredImageService() {
|
|
|
34
34
|
}
|
|
35
35
|
return globalThis.astroAsset.imageService;
|
|
36
36
|
}
|
|
37
|
-
async function getImage(options, imageConfig) {
|
|
37
|
+
async function getImage(options, imageConfig, logger) {
|
|
38
38
|
if (!options || typeof options !== "object") {
|
|
39
39
|
throw new AstroError({
|
|
40
40
|
...AstroErrorData.ExpectedImageOptions,
|
|
@@ -70,7 +70,7 @@ async function getImage(options, imageConfig) {
|
|
|
70
70
|
message: AstroErrorData.RemoteImageNotAllowed.message(resolvedOptions.src)
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
const getRemoteSize = (url) => service.getRemoteSize?.(url, imageConfig) ?? inferRemoteSize(url, imageConfig);
|
|
73
|
+
const getRemoteSize = (url) => service.getRemoteSize?.(url, imageConfig, logger) ?? inferRemoteSize(url, imageConfig);
|
|
74
74
|
const result = await getRemoteSize(resolvedOptions.src);
|
|
75
75
|
resolvedOptions.width ??= result.width;
|
|
76
76
|
resolvedOptions.height ??= result.height;
|
|
@@ -129,25 +129,26 @@ async function getImage(options, imageConfig) {
|
|
|
129
129
|
const currentPosition = resolvedOptions.position || "center";
|
|
130
130
|
resolvedOptions["data-astro-image-pos"] = currentPosition.replace(/\s+/g, "-");
|
|
131
131
|
}
|
|
132
|
-
const validatedOptions = service.validateOptions ? await service.validateOptions(resolvedOptions, imageConfig) : resolvedOptions;
|
|
132
|
+
const validatedOptions = service.validateOptions ? await service.validateOptions(resolvedOptions, imageConfig, logger) : resolvedOptions;
|
|
133
133
|
validatedOptions.format ??= await peekRemoteFormatForStaticEmit(
|
|
134
134
|
validatedOptions,
|
|
135
135
|
imageConfig,
|
|
136
|
-
service
|
|
136
|
+
service,
|
|
137
|
+
logger
|
|
137
138
|
);
|
|
138
|
-
const srcSetTransforms = service.getSrcSet ? await service.getSrcSet(validatedOptions, imageConfig) : [];
|
|
139
|
+
const srcSetTransforms = service.getSrcSet ? await service.getSrcSet(validatedOptions, imageConfig, logger) : [];
|
|
139
140
|
const lazyImageURLFactory = (getValue) => {
|
|
140
141
|
let cached = null;
|
|
141
142
|
return () => cached ??= getValue();
|
|
142
143
|
};
|
|
143
|
-
const initialImageURL = await service.getURL(validatedOptions, imageConfig);
|
|
144
|
+
const initialImageURL = await service.getURL(validatedOptions, imageConfig, logger);
|
|
144
145
|
let lazyImageURL = lazyImageURLFactory(() => initialImageURL);
|
|
145
146
|
const matchesValidatedTransform = (transform) => transform.width === validatedOptions.width && transform.height === validatedOptions.height && transform.format === validatedOptions.format;
|
|
146
147
|
let srcSets = await Promise.all(
|
|
147
148
|
srcSetTransforms.map(async (srcSet) => {
|
|
148
149
|
return {
|
|
149
150
|
transform: srcSet.transform,
|
|
150
|
-
url: matchesValidatedTransform(srcSet.transform) ? initialImageURL : await service.getURL(srcSet.transform, imageConfig),
|
|
151
|
+
url: matchesValidatedTransform(srcSet.transform) ? initialImageURL : await service.getURL(srcSet.transform, imageConfig, logger),
|
|
151
152
|
descriptor: srcSet.descriptor,
|
|
152
153
|
attributes: srcSet.attributes
|
|
153
154
|
};
|
|
@@ -193,15 +194,15 @@ async function getImage(options, imageConfig) {
|
|
|
193
194
|
values: srcSets,
|
|
194
195
|
attribute: srcSets.map((srcSet) => `${srcSet.url} ${srcSet.descriptor}`).join(", ")
|
|
195
196
|
},
|
|
196
|
-
attributes: service.getHTMLAttributes !== void 0 ? await service.getHTMLAttributes(validatedOptions, imageConfig) : {}
|
|
197
|
+
attributes: service.getHTMLAttributes !== void 0 ? await service.getHTMLAttributes(validatedOptions, imageConfig, logger) : {}
|
|
197
198
|
};
|
|
198
199
|
}
|
|
199
|
-
async function peekRemoteFormatForStaticEmit(options, imageConfig, service) {
|
|
200
|
+
async function peekRemoteFormatForStaticEmit(options, imageConfig, service, logger) {
|
|
200
201
|
if (!isRemoteImage(options.src) || !isRemoteAllowed(options.src, imageConfig) || !globalThis.astroAsset?.addStaticImage || !isLocalService(service) || !service.getRemoteSize) {
|
|
201
202
|
return void 0;
|
|
202
203
|
}
|
|
203
204
|
try {
|
|
204
|
-
const probed = await service.getRemoteSize(options.src, imageConfig);
|
|
205
|
+
const probed = await service.getRemoteSize(options.src, imageConfig, logger);
|
|
205
206
|
return resolveDefaultOutputFormat(probed.format);
|
|
206
207
|
} catch {
|
|
207
208
|
return void 0;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AstroConfig } from '../../types/public/config.js';
|
|
2
2
|
import type { ImageFit, ImageMetadata, ImageOutputFormat, ImageTransform, UnresolvedSrcSetValue } from '../types.js';
|
|
3
|
+
import type { AstroRuntimeLogger } from '../../types/public/context.js';
|
|
3
4
|
export type ImageService = LocalImageService | ExternalImageService;
|
|
4
5
|
export declare function isLocalService(service: ImageService | undefined): service is LocalImageService;
|
|
5
6
|
export declare function parseQuality(quality: string): string | number;
|
|
@@ -19,21 +20,21 @@ interface SharedServiceProps<T extends Record<string, any> = Record<string, any>
|
|
|
19
20
|
* For external services, this should point to the URL your images are coming from, for instance, `/_vercel/image`
|
|
20
21
|
*
|
|
21
22
|
*/
|
|
22
|
-
getURL: (options: ImageTransform, imageConfig: ImageConfig<T
|
|
23
|
+
getURL: (options: ImageTransform, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => string | Promise<string>;
|
|
23
24
|
/**
|
|
24
25
|
* Generate additional `srcset` values for the image.
|
|
25
26
|
*
|
|
26
27
|
* While in most cases this is exclusively used for `srcset`, it can also be used in a more generic way to generate
|
|
27
28
|
* multiple variants of the same image. For instance, you can use this to generate multiple aspect ratios or multiple formats.
|
|
28
29
|
*/
|
|
29
|
-
getSrcSet?: (options: ImageTransform, imageConfig: ImageConfig<T
|
|
30
|
+
getSrcSet?: (options: ImageTransform, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => UnresolvedSrcSetValue[] | Promise<UnresolvedSrcSetValue[]>;
|
|
30
31
|
/**
|
|
31
32
|
* Return any additional HTML attributes separate from `src` that your service requires to show the image properly.
|
|
32
33
|
*
|
|
33
34
|
* For example, you might want to return the `width` and `height` to avoid CLS, or a particular `class` or `style`.
|
|
34
35
|
* In most cases, you'll want to return directly what your user supplied you, minus the attributes that were used to generate the image.
|
|
35
36
|
*/
|
|
36
|
-
getHTMLAttributes?: (options: ImageTransform, imageConfig: ImageConfig<T
|
|
37
|
+
getHTMLAttributes?: (options: ImageTransform, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => Record<string, any> | Promise<Record<string, any>>;
|
|
37
38
|
/**
|
|
38
39
|
* Validate and return the options passed by the user.
|
|
39
40
|
*
|
|
@@ -42,14 +43,14 @@ interface SharedServiceProps<T extends Record<string, any> = Record<string, any>
|
|
|
42
43
|
*
|
|
43
44
|
* 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.)
|
|
44
45
|
*/
|
|
45
|
-
validateOptions?: (options: ImageTransform, imageConfig: ImageConfig<T
|
|
46
|
+
validateOptions?: (options: ImageTransform, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => ImageTransform | Promise<ImageTransform>;
|
|
46
47
|
/**
|
|
47
48
|
* Return the dimensions of a remote image.
|
|
48
49
|
*
|
|
49
50
|
* This is used to infer the width and height of an image from its URL,
|
|
50
51
|
* allowing the service to provide necessary metadata when it's not available locally.
|
|
51
52
|
*/
|
|
52
|
-
getRemoteSize?: (url: string, imageConfig: ImageConfig<T
|
|
53
|
+
getRemoteSize?: (url: string, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => Omit<ImageMetadata, 'src' | 'fsPath'> | Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>;
|
|
53
54
|
}
|
|
54
55
|
export type ExternalImageService<T extends Record<string, any> = Record<string, any>> = SharedServiceProps<T>;
|
|
55
56
|
type LocalImageTransform = {
|
|
@@ -62,12 +63,12 @@ export interface LocalImageService<T extends Record<string, any> = Record<string
|
|
|
62
63
|
*
|
|
63
64
|
* In most cases, this will get query parameters using, for example, `params.get('width')` and return those.
|
|
64
65
|
*/
|
|
65
|
-
parseURL: (url: URL, imageConfig: ImageConfig<T
|
|
66
|
+
parseURL: (url: URL, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => LocalImageTransform | undefined | Promise<LocalImageTransform> | Promise<undefined>;
|
|
66
67
|
/**
|
|
67
68
|
* Performs the image transformations on the input image and returns both the binary data and
|
|
68
69
|
* final image format of the optimized image.
|
|
69
70
|
*/
|
|
70
|
-
transform: (inputBuffer: Uint8Array, transform: LocalImageTransform, imageConfig: ImageConfig<T
|
|
71
|
+
transform: (inputBuffer: Uint8Array, transform: LocalImageTransform, imageConfig: ImageConfig<T>, logger: AstroRuntimeLogger) => Promise<{
|
|
71
72
|
data: Uint8Array;
|
|
72
73
|
format: ImageOutputFormat;
|
|
73
74
|
}>;
|
|
@@ -82,7 +82,7 @@ const sharpService = {
|
|
|
82
82
|
getHTMLAttributes: baseService.getHTMLAttributes,
|
|
83
83
|
getSrcSet: baseService.getSrcSet,
|
|
84
84
|
getRemoteSize: baseService.getRemoteSize,
|
|
85
|
-
async transform(inputBuffer, transformOptions, config) {
|
|
85
|
+
async transform(inputBuffer, transformOptions, config, logger) {
|
|
86
86
|
if (!sharp) sharp = await loadSharp();
|
|
87
87
|
const transform = transformOptions;
|
|
88
88
|
const kernel = config.service.config.kernel;
|
|
@@ -90,8 +90,8 @@ const sharpService = {
|
|
|
90
90
|
const outputFormat = transform.format ?? resolveDefaultOutputFormat(bufferFormat);
|
|
91
91
|
if (outputFormat === "svg") {
|
|
92
92
|
if (bufferFormat && bufferFormat !== "svg") {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
logger.warn(
|
|
94
|
+
`Astro expected an SVG for "${transform.src}" but the source is ${bufferFormat}. Passing it through as ${bufferFormat} instead.`
|
|
95
95
|
);
|
|
96
96
|
return { data: inputBuffer, format: bufferFormat };
|
|
97
97
|
}
|
|
@@ -162,8 +162,8 @@ const sharpService = {
|
|
|
162
162
|
try {
|
|
163
163
|
({ data, info } = await result.toBuffer({ resolveWithObject: true }));
|
|
164
164
|
} catch {
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
logger.warn(
|
|
166
|
+
`Astro could not optimize image "${transform.src}". Sharp doesn't support this format. The image will be used unoptimized. Consider converting to WebP or placing in the public/ folder.`
|
|
167
167
|
);
|
|
168
168
|
return { data: inputBuffer, format: bufferFormat };
|
|
169
169
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
removeBase,
|
|
10
10
|
removeQueryString
|
|
11
11
|
} from "../core/path.js";
|
|
12
|
-
import { recordStaticImage } from "../core/
|
|
12
|
+
import { recordStaticImage } from "../core/render-scope/record.js";
|
|
13
13
|
import { normalizePath } from "../core/viteUtils.js";
|
|
14
14
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
15
15
|
import { isAstroServerEnvironment } from "../environments.js";
|
|
@@ -92,6 +92,21 @@ const addStaticImageFactory = (settings) => {
|
|
|
92
92
|
return stringifyPlaceholderURL(url);
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
|
+
const RUNTIME_LOGGER_SETUP = `
|
|
96
|
+
import { createConsoleLogger as _createConsoleLogger } from "astro/logger/console";
|
|
97
|
+
import { astroToRuntimeLogger as _astroToRuntimeLogger } from "astro/_internal/logger";
|
|
98
|
+
import _loggerDestination, { level as _loggerLevel } from "virtual:astro:logger";
|
|
99
|
+
const _astroLogger = _createConsoleLogger({ level: _loggerLevel });
|
|
100
|
+
if (_loggerDestination) _astroLogger.setDestination(_loggerDestination);
|
|
101
|
+
const _runtimeLogger = _astroToRuntimeLogger(_astroLogger);
|
|
102
|
+
`;
|
|
103
|
+
const CLIENT_RUNTIME_LOGGER_SETUP = `
|
|
104
|
+
const _runtimeLogger = {
|
|
105
|
+
info: (message) => console.info(message),
|
|
106
|
+
warn: (message) => console.warn(message),
|
|
107
|
+
error: (message) => console.error(message),
|
|
108
|
+
};
|
|
109
|
+
`;
|
|
95
110
|
function assets({ fs, settings, sync, logger }) {
|
|
96
111
|
let resolvedConfig;
|
|
97
112
|
let shouldEmitFile = false;
|
|
@@ -133,8 +148,9 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
133
148
|
handler(id) {
|
|
134
149
|
if (id === RESOLVED_VIRTUAL_GET_IMAGE_ID) {
|
|
135
150
|
const isServerEnvironment2 = isAstroServerEnvironment(this.environment);
|
|
136
|
-
const getImageExport2 = isServerEnvironment2 ?
|
|
137
|
-
|
|
151
|
+
const getImageExport2 = isServerEnvironment2 ? `${RUNTIME_LOGGER_SETUP}
|
|
152
|
+
import { getImage as getImageInternal } from "astro/assets";
|
|
153
|
+
export const getImage = async (options) => await getImageInternal(options, imageConfig, _runtimeLogger);` : `import { AstroError, AstroErrorData } from "astro/errors";
|
|
138
154
|
export const getImage = async () => {
|
|
139
155
|
throw new AstroError(
|
|
140
156
|
AstroErrorData.GetImageNotUsedOnServer.message,
|
|
@@ -158,7 +174,7 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
158
174
|
}
|
|
159
175
|
const isServerEnvironment = isAstroServerEnvironment(this.environment);
|
|
160
176
|
const getImageExport = isServerEnvironment ? `import { getImage as getImageInternal } from "astro/assets";
|
|
161
|
-
export const getImage = async (options) => await getImageInternal(options, imageConfig);` : `import { AstroError, AstroErrorData } from "astro/errors";
|
|
177
|
+
export const getImage = async (options) => await getImageInternal(options, imageConfig, _runtimeLogger);` : `import { AstroError, AstroErrorData } from "astro/errors";
|
|
162
178
|
export const getImage = async () => {
|
|
163
179
|
throw new AstroError(
|
|
164
180
|
AstroErrorData.GetImageNotUsedOnServer.message,
|
|
@@ -167,6 +183,7 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
167
183
|
};`;
|
|
168
184
|
return {
|
|
169
185
|
code: `
|
|
186
|
+
${isServerEnvironment ? RUNTIME_LOGGER_SETUP : CLIENT_RUNTIME_LOGGER_SETUP}
|
|
170
187
|
import { getConfiguredImageService as _getConfiguredImageService } from "astro/assets";
|
|
171
188
|
export { isLocalService } from "astro/assets";
|
|
172
189
|
${settings.config.image.responsiveStyles ? `import "${VIRTUAL_IMAGE_STYLES_ID}";` : ""}
|
|
@@ -199,7 +216,7 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
199
216
|
});
|
|
200
217
|
export const inferRemoteSize = async (url) => {
|
|
201
218
|
const service = await _getConfiguredImageService();
|
|
202
|
-
return service.getRemoteSize?.(url, imageConfig) ?? inferRemoteSizeInternal(url, imageConfig);
|
|
219
|
+
return service.getRemoteSize?.(url, imageConfig, _runtimeLogger) ?? inferRemoteSizeInternal(url, imageConfig);
|
|
203
220
|
}
|
|
204
221
|
// This is used by the @astrojs/node integration to locate images.
|
|
205
222
|
// It's unused on other platforms, but on some platforms like Netlify (and presumably also Vercel)
|
package/dist/cli/add/index.js
CHANGED
|
@@ -674,7 +674,9 @@ async function tryToInstallIntegrations({
|
|
|
674
674
|
} catch (err) {
|
|
675
675
|
spinner.error("Error installing dependencies.");
|
|
676
676
|
logger.debug("add", "Error installing dependencies", err);
|
|
677
|
-
|
|
677
|
+
logger.error("add", `
|
|
678
|
+
${err.stdout || err.message}
|
|
679
|
+
`);
|
|
678
680
|
return "failure";
|
|
679
681
|
}
|
|
680
682
|
} else {
|
package/dist/cli/index.js
CHANGED
|
@@ -170,7 +170,7 @@ async function runCommand(cmd, flags) {
|
|
|
170
170
|
enableVerboseLogging();
|
|
171
171
|
}
|
|
172
172
|
const { notify } = await import("./telemetry/index.js");
|
|
173
|
-
await notify();
|
|
173
|
+
await notify(logger);
|
|
174
174
|
switch (cmd) {
|
|
175
175
|
case "add": {
|
|
176
176
|
const { add } = await import("./add/index.js");
|
|
@@ -62,7 +62,7 @@ async function preferences(subcommand, key, value, { flags }) {
|
|
|
62
62
|
json: !!flags.json
|
|
63
63
|
};
|
|
64
64
|
if (subcommand === "list") {
|
|
65
|
-
return listPreferences(settings, opts);
|
|
65
|
+
return listPreferences(settings, logger, opts);
|
|
66
66
|
}
|
|
67
67
|
if (subcommand === "enable" || subcommand === "disable") {
|
|
68
68
|
key = `${key}.enabled`;
|
|
@@ -74,7 +74,8 @@ async function preferences(subcommand, key, value, { flags }) {
|
|
|
74
74
|
}
|
|
75
75
|
if (subcommand === "set" && value === void 0) {
|
|
76
76
|
const type = typeof dlv(DEFAULT_PREFERENCES, key);
|
|
77
|
-
|
|
77
|
+
logger.error(
|
|
78
|
+
"preferences",
|
|
78
79
|
msg.formatErrorMessage(
|
|
79
80
|
collectErrorMetadata(new Error(`Please provide a ${type} value for "${key}"`)),
|
|
80
81
|
true
|
|
@@ -84,79 +85,79 @@ async function preferences(subcommand, key, value, { flags }) {
|
|
|
84
85
|
}
|
|
85
86
|
switch (subcommand) {
|
|
86
87
|
case "get":
|
|
87
|
-
return getPreference(settings, key, opts);
|
|
88
|
+
return getPreference(settings, logger, key, opts);
|
|
88
89
|
case "set":
|
|
89
|
-
return setPreference(settings, key, value, opts);
|
|
90
|
+
return setPreference(settings, logger, key, value, opts);
|
|
90
91
|
case "reset":
|
|
91
92
|
case "delete":
|
|
92
|
-
return resetPreference(settings, key, opts);
|
|
93
|
+
return resetPreference(settings, logger, key, opts);
|
|
93
94
|
case "enable":
|
|
94
|
-
return enablePreference(settings, key, opts);
|
|
95
|
+
return enablePreference(settings, logger, key, opts);
|
|
95
96
|
case "disable":
|
|
96
|
-
return disablePreference(settings, key, opts);
|
|
97
|
+
return disablePreference(settings, logger, key, opts);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
async function getPreference(settings, key, { location = "project" }) {
|
|
100
|
+
async function getPreference(settings, logger, key, { location = "project" }) {
|
|
100
101
|
try {
|
|
101
102
|
let value = await settings.preferences.get(key, { location });
|
|
102
103
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
103
104
|
if (Object.keys(value).length === 0) {
|
|
104
105
|
value = dlv(DEFAULT_PREFERENCES, key);
|
|
105
|
-
|
|
106
|
+
logger.info("SKIP_FORMAT", msg.preferenceDefaultIntro(key));
|
|
106
107
|
}
|
|
107
|
-
prettyPrint({ [key]: value });
|
|
108
|
+
prettyPrint(logger, { [key]: value });
|
|
108
109
|
return 0;
|
|
109
110
|
}
|
|
110
111
|
if (value === void 0) {
|
|
111
112
|
const defaultValue = await settings.preferences.get(key);
|
|
112
|
-
|
|
113
|
+
logger.info("SKIP_FORMAT", msg.preferenceDefault(key, defaultValue));
|
|
113
114
|
return 0;
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
logger.info("SKIP_FORMAT", msg.preferenceGet(key, value));
|
|
116
117
|
return 0;
|
|
117
118
|
} catch {
|
|
118
119
|
}
|
|
119
120
|
return 1;
|
|
120
121
|
}
|
|
121
|
-
async function setPreference(settings, key, value, { location }) {
|
|
122
|
+
async function setPreference(settings, logger, key, value, { location }) {
|
|
122
123
|
try {
|
|
123
124
|
const defaultType = typeof dlv(DEFAULT_PREFERENCES, key);
|
|
124
125
|
if (typeof coerce(key, value) !== defaultType) {
|
|
125
126
|
throw new Error(`${key} expects a "${defaultType}" value!`);
|
|
126
127
|
}
|
|
127
128
|
await settings.preferences.set(key, coerce(key, value), { location });
|
|
128
|
-
|
|
129
|
+
logger.info("SKIP_FORMAT", msg.preferenceSet(key, value));
|
|
129
130
|
return 0;
|
|
130
131
|
} catch (e) {
|
|
131
132
|
if (e instanceof Error) {
|
|
132
|
-
|
|
133
|
+
logger.error("preferences", msg.formatErrorMessage(collectErrorMetadata(e), true));
|
|
133
134
|
return 1;
|
|
134
135
|
}
|
|
135
136
|
throw e;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
|
-
async function enablePreference(settings, key, { location }) {
|
|
139
|
+
async function enablePreference(settings, logger, key, { location }) {
|
|
139
140
|
try {
|
|
140
141
|
await settings.preferences.set(key, true, { location });
|
|
141
|
-
|
|
142
|
+
logger.info("SKIP_FORMAT", msg.preferenceEnabled(key.replace(".enabled", "")));
|
|
142
143
|
return 0;
|
|
143
144
|
} catch {
|
|
144
145
|
}
|
|
145
146
|
return 1;
|
|
146
147
|
}
|
|
147
|
-
async function disablePreference(settings, key, { location }) {
|
|
148
|
+
async function disablePreference(settings, logger, key, { location }) {
|
|
148
149
|
try {
|
|
149
150
|
await settings.preferences.set(key, false, { location });
|
|
150
|
-
|
|
151
|
+
logger.info("SKIP_FORMAT", msg.preferenceDisabled(key.replace(".enabled", "")));
|
|
151
152
|
return 0;
|
|
152
153
|
} catch {
|
|
153
154
|
}
|
|
154
155
|
return 1;
|
|
155
156
|
}
|
|
156
|
-
async function resetPreference(settings, key, { location }) {
|
|
157
|
+
async function resetPreference(settings, logger, key, { location }) {
|
|
157
158
|
try {
|
|
158
159
|
await settings.preferences.set(key, void 0, { location });
|
|
159
|
-
|
|
160
|
+
logger.info("SKIP_FORMAT", msg.preferenceReset(key));
|
|
160
161
|
return 0;
|
|
161
162
|
} catch {
|
|
162
163
|
}
|
|
@@ -184,10 +185,10 @@ function userValues(flatDefault, flatProject, flatGlobal) {
|
|
|
184
185
|
}
|
|
185
186
|
return result;
|
|
186
187
|
}
|
|
187
|
-
async function listPreferences(settings, { location, json }) {
|
|
188
|
+
async function listPreferences(settings, logger, { location, json }) {
|
|
188
189
|
if (json) {
|
|
189
190
|
const resolved = await settings.preferences.getAll();
|
|
190
|
-
|
|
191
|
+
logger.info("SKIP_FORMAT", JSON.stringify(resolved, null, 2));
|
|
191
192
|
return 0;
|
|
192
193
|
}
|
|
193
194
|
const { global, project, fromAstroConfig, defaults } = await settings.preferences.list({
|
|
@@ -201,11 +202,11 @@ async function listPreferences(settings, { location, json }) {
|
|
|
201
202
|
if (userKeys.length > 0) {
|
|
202
203
|
const badge = bgGreen(black(` Your Preferences `));
|
|
203
204
|
const table = formatTable(flatUser, ["Preference", "Value"]);
|
|
204
|
-
|
|
205
|
+
logger.info("SKIP_FORMAT", ["", badge, table].join("\n"));
|
|
205
206
|
} else {
|
|
206
207
|
const badge = bgGreen(black(` Your Preferences `));
|
|
207
208
|
const message = dim("No preferences set");
|
|
208
|
-
|
|
209
|
+
logger.info("SKIP_FORMAT", ["", badge, "", message].join("\n"));
|
|
209
210
|
}
|
|
210
211
|
const flatUnset = annotate(Object.assign({}, flatDefault), "");
|
|
211
212
|
for (const key of userKeys) {
|
|
@@ -215,14 +216,15 @@ async function listPreferences(settings, { location, json }) {
|
|
|
215
216
|
if (unsetKeys.length > 0) {
|
|
216
217
|
const badge = bgGreen(black(` Default Preferences `));
|
|
217
218
|
const table = formatTable(flatUnset, ["Preference", "Value"]);
|
|
218
|
-
|
|
219
|
+
logger.info("SKIP_FORMAT", ["", badge, table].join("\n"));
|
|
219
220
|
} else {
|
|
220
221
|
const badge = bgGreen(black(` Default Preferences `));
|
|
221
222
|
const message = dim("All preferences have been set");
|
|
222
|
-
|
|
223
|
+
logger.info("SKIP_FORMAT", ["", badge, "", message].join("\n"));
|
|
223
224
|
}
|
|
224
225
|
if (fromAstroConfig.devToolbar?.enabled === false && flatUser["devToolbar.enabled"]?.value !== false) {
|
|
225
|
-
|
|
226
|
+
logger.info(
|
|
227
|
+
"SKIP_FORMAT",
|
|
226
228
|
yellow(
|
|
227
229
|
"The dev toolbar is currently disabled. To enable it, set devToolbar: {enabled: true} in your astroConfig file."
|
|
228
230
|
)
|
|
@@ -230,10 +232,10 @@ async function listPreferences(settings, { location, json }) {
|
|
|
230
232
|
}
|
|
231
233
|
return 0;
|
|
232
234
|
}
|
|
233
|
-
function prettyPrint(value) {
|
|
235
|
+
function prettyPrint(logger, value) {
|
|
234
236
|
const flattened = flattie(value);
|
|
235
237
|
const table = formatTable(flattened, ["Preference", "Value"]);
|
|
236
|
-
|
|
238
|
+
logger.info("SKIP_FORMAT", table);
|
|
237
239
|
}
|
|
238
240
|
const chars = {
|
|
239
241
|
h: "\u2500",
|