astro 4.0.5 → 4.0.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.
- package/components/Picture.astro +1 -1
- package/dist/assets/build/generate.js +2 -1
- package/dist/assets/endpoint/config.d.ts +2 -0
- package/dist/assets/endpoint/config.js +12 -0
- package/dist/assets/endpoint/generic.js +2 -1
- package/dist/assets/endpoint/node.js +2 -1
- package/dist/assets/internal.d.ts +2 -6
- package/dist/assets/internal.js +2 -31
- package/dist/assets/services/service.js +2 -1
- package/dist/assets/utils/imageKind.d.ts +3 -0
- package/dist/assets/utils/imageKind.js +10 -0
- package/dist/assets/utils/index.d.ts +2 -0
- package/dist/assets/utils/index.js +17 -0
- package/dist/assets/utils/remotePattern.d.ts +2 -0
- package/dist/assets/utils/remotePattern.js +11 -0
- package/dist/assets/utils/transformToPath.js +1 -1
- package/dist/assets/vite-plugin-assets.js +1 -1
- package/dist/core/app/index.js +19 -7
- package/dist/core/build/index.js +1 -1
- package/dist/core/config/schema.d.ts +360 -360
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/container.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.js +2 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/routing/manifest/create.js +1 -1
- package/dist/transitions/router.js +7 -5
- package/dist/vite-plugin-astro-server/request.js +0 -4
- package/package.json +2 -2
package/components/Picture.astro
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { getImage, type LocalImageProps, type RemoteImageProps } from 'astro:assets';
|
|
3
3
|
import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro';
|
|
4
|
-
import { isESMImportedImage } from '../dist/assets/
|
|
4
|
+
import { isESMImportedImage } from '../dist/assets/utils/imageKind';
|
|
5
5
|
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
|
|
6
6
|
import type { HTMLAttributes } from '../types';
|
|
7
7
|
|
|
@@ -5,7 +5,8 @@ import { getOutDirWithinCwd } from "../../core/build/common.js";
|
|
|
5
5
|
import { getTimeStat } from "../../core/build/util.js";
|
|
6
6
|
import { isRemotePath, prependForwardSlash } from "../../core/path.js";
|
|
7
7
|
import { isServerLikeOutput } from "../../prerender/utils.js";
|
|
8
|
-
import { getConfiguredImageService
|
|
8
|
+
import { getConfiguredImageService } from "../internal.js";
|
|
9
|
+
import { isESMImportedImage } from "../utils/imageKind.js";
|
|
9
10
|
import { loadRemoteImage } from "./remote.js";
|
|
10
11
|
async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
11
12
|
const config = pipeline.getConfig();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function injectImageEndpoint(settings, mode) {
|
|
2
|
+
const endpointEntrypoint = settings.config.image.endpoint ?? (mode === "dev" ? "astro/assets/endpoint/node" : "astro/assets/endpoint/generic");
|
|
3
|
+
settings.injectedRoutes.push({
|
|
4
|
+
pattern: "/_image",
|
|
5
|
+
entrypoint: endpointEntrypoint,
|
|
6
|
+
prerender: false
|
|
7
|
+
});
|
|
8
|
+
return settings;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
injectImageEndpoint
|
|
12
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isRemotePath } from "@astrojs/internal-helpers/path";
|
|
2
2
|
import mime from "mime/lite.js";
|
|
3
|
-
import { getConfiguredImageService
|
|
3
|
+
import { getConfiguredImageService } from "../internal.js";
|
|
4
4
|
import { etag } from "../utils/etag.js";
|
|
5
5
|
import { imageConfig } from "astro:assets";
|
|
6
|
+
import { isRemoteAllowed } from "../utils/remotePattern.js";
|
|
6
7
|
async function loadRemoteImage(src) {
|
|
7
8
|
try {
|
|
8
9
|
const res = await fetch(src);
|
|
@@ -2,9 +2,10 @@ import { isRemotePath, removeQueryString } from "@astrojs/internal-helpers/path"
|
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
3
|
import mime from "mime/lite.js";
|
|
4
4
|
import os from "os";
|
|
5
|
-
import { getConfiguredImageService
|
|
5
|
+
import { getConfiguredImageService } from "../internal.js";
|
|
6
6
|
import { etag } from "../utils/etag.js";
|
|
7
7
|
import { assetsDir, imageConfig } from "astro:assets";
|
|
8
|
+
import { isRemoteAllowed } from "../utils/remotePattern.js";
|
|
8
9
|
function replaceFileSystemReferences(src) {
|
|
9
10
|
return os.platform().includes("win32") ? src.replace(/^\/@fs\//, "") : src.replace(/^\/@fs/, "");
|
|
10
11
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type { AstroConfig
|
|
1
|
+
import type { AstroConfig } from '../@types/astro.js';
|
|
2
2
|
import { type ImageService } from './services/service.js';
|
|
3
|
-
import type { GetImageResult,
|
|
4
|
-
export declare function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build'): AstroSettings;
|
|
5
|
-
export declare function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata;
|
|
6
|
-
export declare function isRemoteImage(src: ImageMetadata | string): src is string;
|
|
7
|
-
export declare function isRemoteAllowed(src: string, { domains, remotePatterns, }: Partial<Pick<AstroConfig['image'], 'domains' | 'remotePatterns'>>): boolean;
|
|
3
|
+
import type { GetImageResult, UnresolvedImageTransform } from './types.js';
|
|
8
4
|
export declare function getConfiguredImageService(): Promise<ImageService>;
|
|
9
5
|
export declare function getImage(options: UnresolvedImageTransform, imageConfig: AstroConfig['image']): Promise<GetImageResult>;
|
package/dist/assets/internal.js
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
import { isRemotePath } from "@astrojs/internal-helpers/path";
|
|
2
1
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
3
2
|
import { DEFAULT_HASH_PROPS } from "./consts.js";
|
|
4
3
|
import { isLocalService } from "./services/service.js";
|
|
5
|
-
import {
|
|
6
|
-
function injectImageEndpoint(settings, mode) {
|
|
7
|
-
const endpointEntrypoint = settings.config.image.endpoint ?? (mode === "dev" ? "astro/assets/endpoint/node" : "astro/assets/endpoint/generic");
|
|
8
|
-
settings.injectedRoutes.push({
|
|
9
|
-
pattern: "/_image",
|
|
10
|
-
entrypoint: endpointEntrypoint,
|
|
11
|
-
prerender: false
|
|
12
|
-
});
|
|
13
|
-
return settings;
|
|
14
|
-
}
|
|
15
|
-
function isESMImportedImage(src) {
|
|
16
|
-
return typeof src === "object";
|
|
17
|
-
}
|
|
18
|
-
function isRemoteImage(src) {
|
|
19
|
-
return typeof src === "string";
|
|
20
|
-
}
|
|
21
|
-
function isRemoteAllowed(src, {
|
|
22
|
-
domains = [],
|
|
23
|
-
remotePatterns = []
|
|
24
|
-
}) {
|
|
25
|
-
if (!isRemotePath(src))
|
|
26
|
-
return false;
|
|
27
|
-
const url = new URL(src);
|
|
28
|
-
return domains.some((domain) => matchHostname(url, domain)) || remotePatterns.some((remotePattern) => matchPattern(url, remotePattern));
|
|
29
|
-
}
|
|
4
|
+
import { isESMImportedImage, isRemoteImage } from "./utils/imageKind.js";
|
|
30
5
|
async function getConfiguredImageService() {
|
|
31
6
|
if (!globalThis?.astroAsset?.imageService) {
|
|
32
7
|
const { default: service } = await import(
|
|
@@ -105,9 +80,5 @@ async function getImage(options, imageConfig) {
|
|
|
105
80
|
}
|
|
106
81
|
export {
|
|
107
82
|
getConfiguredImageService,
|
|
108
|
-
getImage
|
|
109
|
-
injectImageEndpoint,
|
|
110
|
-
isESMImportedImage,
|
|
111
|
-
isRemoteAllowed,
|
|
112
|
-
isRemoteImage
|
|
83
|
+
getImage
|
|
113
84
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
2
2
|
import { isRemotePath, joinPaths } from "../../core/path.js";
|
|
3
3
|
import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from "../consts.js";
|
|
4
|
-
import { isESMImportedImage
|
|
4
|
+
import { isESMImportedImage } from "../utils/imageKind.js";
|
|
5
|
+
import { isRemoteAllowed } from "../utils/remotePattern.js";
|
|
5
6
|
function isLocalService(service) {
|
|
6
7
|
if (!service) {
|
|
7
8
|
return false;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { emitESMImage } from './emitAsset.js';
|
|
2
|
+
export { isESMImportedImage, isRemoteImage } from './imageKind.js';
|
|
2
3
|
export { imageMetadata } from './metadata.js';
|
|
3
4
|
export { getOrigQueryParams } from './queryParams.js';
|
|
5
|
+
export { isRemoteAllowed, matchHostname, matchPathname, matchPattern, matchPort, matchProtocol, type RemotePattern, } from './remotePattern.js';
|
|
4
6
|
export { hashTransform, propsToFilename } from './transformToPath.js';
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { emitESMImage } from "./emitAsset.js";
|
|
2
|
+
import { isESMImportedImage, isRemoteImage } from "./imageKind.js";
|
|
2
3
|
import { imageMetadata } from "./metadata.js";
|
|
3
4
|
import { getOrigQueryParams } from "./queryParams.js";
|
|
5
|
+
import {
|
|
6
|
+
isRemoteAllowed,
|
|
7
|
+
matchHostname,
|
|
8
|
+
matchPathname,
|
|
9
|
+
matchPattern,
|
|
10
|
+
matchPort,
|
|
11
|
+
matchProtocol
|
|
12
|
+
} from "./remotePattern.js";
|
|
4
13
|
import { hashTransform, propsToFilename } from "./transformToPath.js";
|
|
5
14
|
export {
|
|
6
15
|
emitESMImage,
|
|
7
16
|
getOrigQueryParams,
|
|
8
17
|
hashTransform,
|
|
9
18
|
imageMetadata,
|
|
19
|
+
isESMImportedImage,
|
|
20
|
+
isRemoteAllowed,
|
|
21
|
+
isRemoteImage,
|
|
22
|
+
matchHostname,
|
|
23
|
+
matchPathname,
|
|
24
|
+
matchPattern,
|
|
25
|
+
matchPort,
|
|
26
|
+
matchProtocol,
|
|
10
27
|
propsToFilename
|
|
11
28
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AstroConfig } from '../../@types/astro.js';
|
|
1
2
|
export type RemotePattern = {
|
|
2
3
|
hostname?: string;
|
|
3
4
|
pathname?: string;
|
|
@@ -9,3 +10,4 @@ export declare function matchPort(url: URL, port?: string): boolean;
|
|
|
9
10
|
export declare function matchProtocol(url: URL, protocol?: string): boolean;
|
|
10
11
|
export declare function matchHostname(url: URL, hostname?: string, allowWildcard?: boolean): boolean;
|
|
11
12
|
export declare function matchPathname(url: URL, pathname?: string, allowWildcard?: boolean): boolean;
|
|
13
|
+
export declare function isRemoteAllowed(src: string, { domains, remotePatterns, }: Partial<Pick<AstroConfig['image'], 'domains' | 'remotePatterns'>>): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRemotePath } from "@astrojs/internal-helpers/path";
|
|
1
2
|
function matchPattern(url, remotePattern) {
|
|
2
3
|
return matchProtocol(url, remotePattern.protocol) && matchHostname(url, remotePattern.hostname, true) && matchPort(url, remotePattern.port) && matchPathname(url, remotePattern.pathname, true);
|
|
3
4
|
}
|
|
@@ -37,7 +38,17 @@ function matchPathname(url, pathname, allowWildcard) {
|
|
|
37
38
|
}
|
|
38
39
|
return false;
|
|
39
40
|
}
|
|
41
|
+
function isRemoteAllowed(src, {
|
|
42
|
+
domains = [],
|
|
43
|
+
remotePatterns = []
|
|
44
|
+
}) {
|
|
45
|
+
if (!isRemotePath(src))
|
|
46
|
+
return false;
|
|
47
|
+
const url = new URL(src);
|
|
48
|
+
return domains.some((domain) => matchHostname(url, domain)) || remotePatterns.some((remotePattern) => matchPattern(url, remotePattern));
|
|
49
|
+
}
|
|
40
50
|
export {
|
|
51
|
+
isRemoteAllowed,
|
|
41
52
|
matchHostname,
|
|
42
53
|
matchPathname,
|
|
43
54
|
matchPattern,
|
|
@@ -2,7 +2,7 @@ import { deterministicString } from "deterministic-object-hash";
|
|
|
2
2
|
import { basename, extname } from "node:path";
|
|
3
3
|
import { removeQueryString } from "../../core/path.js";
|
|
4
4
|
import { shorthash } from "../../runtime/server/shorthash.js";
|
|
5
|
-
import { isESMImportedImage } from "
|
|
5
|
+
import { isESMImportedImage } from "./imageKind.js";
|
|
6
6
|
function propsToFilename(transform, hash) {
|
|
7
7
|
let filename = removeQueryString(
|
|
8
8
|
isESMImportedImage(transform.src) ? transform.src.src : transform.src
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
} from "../core/path.js";
|
|
11
11
|
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
12
12
|
import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
|
|
13
|
-
import { isESMImportedImage } from "./internal.js";
|
|
14
13
|
import { emitESMImage } from "./utils/emitAsset.js";
|
|
14
|
+
import { isESMImportedImage } from "./utils/imageKind.js";
|
|
15
15
|
import { getProxyCode } from "./utils/proxy.js";
|
|
16
16
|
import { hashTransform, propsToFilename } from "./utils/transformToPath.js";
|
|
17
17
|
const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
|
package/dist/core/app/index.js
CHANGED
|
@@ -263,7 +263,8 @@ class App {
|
|
|
263
263
|
* This also handles pre-rendered /404 or /500 routes
|
|
264
264
|
*/
|
|
265
265
|
async #renderError(request, { status, response: originalResponse, skipMiddleware = false }) {
|
|
266
|
-
const
|
|
266
|
+
const errorRoutePath = `/${status}${this.#manifest.trailingSlash === "always" ? "/" : ""}`;
|
|
267
|
+
const errorRouteData = matchRoute(errorRoutePath, this.#manifestData);
|
|
267
268
|
const url = new URL(request.url);
|
|
268
269
|
if (errorRouteData) {
|
|
269
270
|
if (errorRouteData.prerender) {
|
|
@@ -308,8 +309,8 @@ class App {
|
|
|
308
309
|
Reflect.set(response, responseSentSymbol, true);
|
|
309
310
|
return response;
|
|
310
311
|
}
|
|
311
|
-
#mergeResponses(newResponse,
|
|
312
|
-
if (!
|
|
312
|
+
#mergeResponses(newResponse, originalResponse, override) {
|
|
313
|
+
if (!originalResponse) {
|
|
313
314
|
if (override !== void 0) {
|
|
314
315
|
return new Response(newResponse.body, {
|
|
315
316
|
status: override.status,
|
|
@@ -319,12 +320,23 @@ class App {
|
|
|
319
320
|
}
|
|
320
321
|
return newResponse;
|
|
321
322
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
323
|
+
const status = override?.status ? override.status : originalResponse.status === 200 ? newResponse.status : originalResponse.status;
|
|
324
|
+
try {
|
|
325
|
+
originalResponse.headers.delete("Content-type");
|
|
326
|
+
} catch {
|
|
327
|
+
}
|
|
324
328
|
return new Response(newResponse.body, {
|
|
325
329
|
status,
|
|
326
|
-
statusText: status === 200 ? newResponse.statusText : statusText,
|
|
327
|
-
|
|
330
|
+
statusText: status === 200 ? newResponse.statusText : originalResponse.statusText,
|
|
331
|
+
// If you're looking at here for possible bugs, it means that it's not a bug.
|
|
332
|
+
// With the middleware, users can meddle with headers, and we should pass to the 404/500.
|
|
333
|
+
// If users see something weird, it's because they are setting some headers they should not.
|
|
334
|
+
//
|
|
335
|
+
// Although, we don't want it to replace the content-type, because the error page must return `text/html`
|
|
336
|
+
headers: new Headers([
|
|
337
|
+
...Array.from(newResponse.headers),
|
|
338
|
+
...Array.from(originalResponse.headers)
|
|
339
|
+
])
|
|
328
340
|
});
|
|
329
341
|
}
|
|
330
342
|
#getDefaultStatusCode(routeData, pathname) {
|
package/dist/core/build/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { blue, bold, green } from "kleur/colors";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { performance } from "node:perf_hooks";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { injectImageEndpoint } from "../../assets/
|
|
5
|
+
import { injectImageEndpoint } from "../../assets/endpoint/config.js";
|
|
6
6
|
import { telemetry } from "../../events/index.js";
|
|
7
7
|
import { eventCliSession } from "../../events/session.js";
|
|
8
8
|
import {
|