astro 4.5.10 → 4.5.12
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.js +4 -7
- package/dist/assets/internal.js +7 -3
- package/dist/assets/types.d.ts +2 -2
- package/dist/assets/utils/transformToPath.d.ts +1 -1
- package/dist/assets/utils/transformToPath.js +6 -7
- package/dist/assets/vite-plugin-assets.js +16 -9
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +8 -2
- package/dist/content/utils.d.ts +1 -0
- package/dist/content/utils.js +9 -1
- package/dist/core/build/plugins/plugin-css.js +8 -16
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/request.js +1 -1
- package/dist/core/routing/astro-designed-error-pages.js +1 -1
- package/dist/core/routing/manifest/create.js +1 -48
- package/dist/core/routing/priority.d.ts +23 -0
- package/dist/core/routing/priority.js +51 -0
- package/dist/prerender/routing.js +2 -1
- package/dist/vite-plugin-astro-server/route.js +1 -1
- package/package.json +4 -4
- package/types.d.ts +8 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs, { readFileSync } from "node:fs";
|
|
2
|
-
import { basename
|
|
2
|
+
import { basename } from "node:path/posix";
|
|
3
3
|
import { dim, green } from "kleur/colors";
|
|
4
4
|
import { getOutDirWithinCwd } from "../../core/build/common.js";
|
|
5
5
|
import { getTimeStat } from "../../core/build/util.js";
|
|
6
6
|
import { AstroError } from "../../core/errors/errors.js";
|
|
7
7
|
import { AstroErrorData } from "../../core/errors/index.js";
|
|
8
|
-
import { isRemotePath,
|
|
8
|
+
import { isRemotePath, removeLeadingForwardSlash } from "../../core/path.js";
|
|
9
9
|
import { isServerLikeOutput } from "../../prerender/utils.js";
|
|
10
10
|
import { getConfiguredImageService } from "../internal.js";
|
|
11
11
|
import { isESMImportedImage } from "../utils/imageKind.js";
|
|
@@ -45,10 +45,7 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function getFullImagePath(originalFilePath, env) {
|
|
48
|
-
return new URL(
|
|
49
|
-
"." + prependForwardSlash(join(env.assetsFolder, basename(originalFilePath))),
|
|
50
|
-
env.serverRoot
|
|
51
|
-
);
|
|
48
|
+
return new URL(removeLeadingForwardSlash(originalFilePath), env.serverRoot);
|
|
52
49
|
}
|
|
53
50
|
async function generateImagesForPath(originalFilePath, transformsAndPath, env, queue) {
|
|
54
51
|
const originalImageData = await loadImage(originalFilePath, env);
|
|
@@ -57,7 +54,7 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env, q
|
|
|
57
54
|
throw e;
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
|
-
if (!env.isSSR &&
|
|
57
|
+
if (!env.isSSR && transformsAndPath.originalSrcPath && !globalThis.astroAsset.referencedImages?.has(transformsAndPath.originalSrcPath)) {
|
|
61
58
|
try {
|
|
62
59
|
if (transformsAndPath.originalSrcPath) {
|
|
63
60
|
env.logger.debug(
|
package/dist/assets/internal.js
CHANGED
|
@@ -55,7 +55,7 @@ async function getImage(options, imageConfig) {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const originalFilePath = isESMImportedImage(resolvedOptions.src) ? resolvedOptions.src.fsPath : void 0;
|
|
59
59
|
const clonedSrc = isESMImportedImage(resolvedOptions.src) ? (
|
|
60
60
|
// @ts-expect-error - clone is a private, hidden prop
|
|
61
61
|
resolvedOptions.src.clone ?? resolvedOptions.src
|
|
@@ -74,10 +74,14 @@ async function getImage(options, imageConfig) {
|
|
|
74
74
|
);
|
|
75
75
|
if (isLocalService(service) && globalThis.astroAsset.addStaticImage && !(isRemoteImage(validatedOptions.src) && imageURL === validatedOptions.src)) {
|
|
76
76
|
const propsToHash = service.propertiesToHash ?? DEFAULT_HASH_PROPS;
|
|
77
|
-
imageURL = globalThis.astroAsset.addStaticImage(
|
|
77
|
+
imageURL = globalThis.astroAsset.addStaticImage(
|
|
78
|
+
validatedOptions,
|
|
79
|
+
propsToHash,
|
|
80
|
+
originalFilePath
|
|
81
|
+
);
|
|
78
82
|
srcSets = srcSetTransforms.map((srcSet) => ({
|
|
79
83
|
transform: srcSet.transform,
|
|
80
|
-
url: globalThis.astroAsset.addStaticImage(srcSet.transform, propsToHash,
|
|
84
|
+
url: globalThis.astroAsset.addStaticImage(srcSet.transform, propsToHash, originalFilePath),
|
|
81
85
|
descriptor: srcSet.descriptor,
|
|
82
86
|
attributes: srcSet.attributes
|
|
83
87
|
}));
|
package/dist/assets/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type ImageQuality = ImageQualityPreset | number;
|
|
|
6
6
|
export type ImageInputFormat = (typeof VALID_INPUT_FORMATS)[number];
|
|
7
7
|
export type ImageOutputFormat = (typeof VALID_OUTPUT_FORMATS)[number] | (string & {});
|
|
8
8
|
export type AssetsGlobalStaticImagesList = Map<string, {
|
|
9
|
-
originalSrcPath: string;
|
|
9
|
+
originalSrcPath: string | undefined;
|
|
10
10
|
transforms: Map<string, {
|
|
11
11
|
finalPath: string;
|
|
12
12
|
transform: ImageTransform;
|
|
@@ -15,7 +15,7 @@ export type AssetsGlobalStaticImagesList = Map<string, {
|
|
|
15
15
|
declare global {
|
|
16
16
|
var astroAsset: {
|
|
17
17
|
imageService?: ImageService;
|
|
18
|
-
addStaticImage?: ((options: ImageTransform, hashProperties: string[], fsPath: string) => string) | undefined;
|
|
18
|
+
addStaticImage?: ((options: ImageTransform, hashProperties: string[], fsPath: string | undefined) => string) | undefined;
|
|
19
19
|
staticImages?: AssetsGlobalStaticImagesList;
|
|
20
20
|
referencedImages?: Set<string>;
|
|
21
21
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ImageTransform } from '../types.js';
|
|
2
|
-
export declare function propsToFilename(transform: ImageTransform, hash: string): string;
|
|
2
|
+
export declare function propsToFilename(filePath: string, transform: ImageTransform, hash: string): string;
|
|
3
3
|
export declare function hashTransform(transform: ImageTransform, imageService: string, propertiesToHash: string[]): string;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { basename, extname } from "node:path";
|
|
1
|
+
import { basename, dirname, extname } from "node:path";
|
|
2
2
|
import { deterministicString } from "deterministic-object-hash";
|
|
3
3
|
import { removeQueryString } from "../../core/path.js";
|
|
4
4
|
import { shorthash } from "../../runtime/server/shorthash.js";
|
|
5
5
|
import { isESMImportedImage } from "./imageKind.js";
|
|
6
|
-
function propsToFilename(transform, hash) {
|
|
7
|
-
let filename = removeQueryString(
|
|
8
|
-
isESMImportedImage(transform.src) ? transform.src.src : transform.src
|
|
9
|
-
);
|
|
6
|
+
function propsToFilename(filePath, transform, hash) {
|
|
7
|
+
let filename = decodeURIComponent(removeQueryString(filePath));
|
|
10
8
|
const ext = extname(filename);
|
|
11
|
-
filename =
|
|
9
|
+
filename = basename(filename, ext);
|
|
10
|
+
const prefixDirname = isESMImportedImage(transform.src) ? dirname(filePath) : "";
|
|
12
11
|
let outputExt = transform.format ? `.${transform.format}` : ext;
|
|
13
|
-
return
|
|
12
|
+
return decodeURIComponent(`${prefixDirname}/${filename}_${hash}${outputExt}`);
|
|
14
13
|
}
|
|
15
14
|
function hashTransform(transform, imageService, propertiesToHash) {
|
|
16
15
|
const hashFields = propertiesToHash.reduce(
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
appendForwardSlash,
|
|
8
8
|
joinPaths,
|
|
9
9
|
prependForwardSlash,
|
|
10
|
+
removeBase,
|
|
10
11
|
removeQueryString
|
|
11
12
|
} from "../core/path.js";
|
|
12
13
|
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
@@ -77,34 +78,40 @@ function assets({
|
|
|
77
78
|
if (mode != "build") {
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
80
|
-
globalThis.astroAsset.addStaticImage = (options, hashProperties,
|
|
81
|
+
globalThis.astroAsset.addStaticImage = (options, hashProperties, originalFSPath) => {
|
|
81
82
|
if (!globalThis.astroAsset.staticImages) {
|
|
82
83
|
globalThis.astroAsset.staticImages = /* @__PURE__ */ new Map();
|
|
83
84
|
}
|
|
84
85
|
const ESMImportedImageSrc = isESMImportedImage(options.src) ? options.src.src : options.src;
|
|
85
86
|
const fileExtension = extname(ESMImportedImageSrc);
|
|
86
|
-
const
|
|
87
|
-
const
|
|
87
|
+
const assetPrefix = getAssetsPrefix(fileExtension, settings.config.build.assetsPrefix);
|
|
88
|
+
const finalOriginalPath = removeBase(
|
|
89
|
+
removeBase(ESMImportedImageSrc, settings.config.base),
|
|
90
|
+
assetPrefix
|
|
91
|
+
);
|
|
88
92
|
const hash = hashTransform(
|
|
89
93
|
options,
|
|
90
94
|
settings.config.image.service.entrypoint,
|
|
91
95
|
hashProperties
|
|
92
96
|
);
|
|
93
97
|
let finalFilePath;
|
|
94
|
-
let transformsForPath = globalThis.astroAsset.staticImages.get(
|
|
98
|
+
let transformsForPath = globalThis.astroAsset.staticImages.get(finalOriginalPath);
|
|
95
99
|
let transformForHash = transformsForPath?.transforms.get(hash);
|
|
96
100
|
if (transformsForPath && transformForHash) {
|
|
97
101
|
finalFilePath = transformForHash.finalPath;
|
|
98
102
|
} else {
|
|
99
103
|
finalFilePath = prependForwardSlash(
|
|
100
|
-
joinPaths(
|
|
104
|
+
joinPaths(
|
|
105
|
+
isESMImportedImage(options.src) ? "" : settings.config.build.assets,
|
|
106
|
+
prependForwardSlash(propsToFilename(finalOriginalPath, options, hash))
|
|
107
|
+
)
|
|
101
108
|
);
|
|
102
109
|
if (!transformsForPath) {
|
|
103
|
-
globalThis.astroAsset.staticImages.set(
|
|
104
|
-
originalSrcPath:
|
|
110
|
+
globalThis.astroAsset.staticImages.set(finalOriginalPath, {
|
|
111
|
+
originalSrcPath: originalFSPath,
|
|
105
112
|
transforms: /* @__PURE__ */ new Map()
|
|
106
113
|
});
|
|
107
|
-
transformsForPath = globalThis.astroAsset.staticImages.get(
|
|
114
|
+
transformsForPath = globalThis.astroAsset.staticImages.get(finalOriginalPath);
|
|
108
115
|
}
|
|
109
116
|
transformsForPath.transforms.set(hash, {
|
|
110
117
|
finalPath: finalFilePath,
|
|
@@ -112,7 +119,7 @@ function assets({
|
|
|
112
119
|
});
|
|
113
120
|
}
|
|
114
121
|
if (settings.config.build.assetsPrefix) {
|
|
115
|
-
return encodeURI(joinPaths(
|
|
122
|
+
return encodeURI(joinPaths(assetPrefix, finalFilePath));
|
|
116
123
|
} else {
|
|
117
124
|
return encodeURI(prependForwardSlash(joinPaths(settings.config.base, finalFilePath)));
|
|
118
125
|
}
|
package/dist/content/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from './consts.js';
|
|
|
2
2
|
export { errorMap } from './error-map.js';
|
|
3
3
|
export { attachContentServerListeners } from './server-listeners.js';
|
|
4
4
|
export { createContentTypesGenerator } from './types-generator.js';
|
|
5
|
-
export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js';
|
|
5
|
+
export { contentObservable, getContentPaths, getDotAstroTypeReference, hasAssetPropagationFlag, } from './utils.js';
|
|
6
6
|
export { astroContentAssetPropagationPlugin } from './vite-plugin-content-assets.js';
|
|
7
7
|
export { astroContentImportPlugin } from './vite-plugin-content-imports.js';
|
|
8
8
|
export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
|
package/dist/content/index.js
CHANGED
|
@@ -2,7 +2,12 @@ import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from "./consts.js";
|
|
|
2
2
|
import { errorMap } from "./error-map.js";
|
|
3
3
|
import { attachContentServerListeners } from "./server-listeners.js";
|
|
4
4
|
import { createContentTypesGenerator } from "./types-generator.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
contentObservable,
|
|
7
|
+
getContentPaths,
|
|
8
|
+
getDotAstroTypeReference,
|
|
9
|
+
hasAssetPropagationFlag
|
|
10
|
+
} from "./utils.js";
|
|
6
11
|
import { astroContentAssetPropagationPlugin } from "./vite-plugin-content-assets.js";
|
|
7
12
|
import { astroContentImportPlugin } from "./vite-plugin-content-imports.js";
|
|
8
13
|
import { astroContentVirtualModPlugin } from "./vite-plugin-content-virtual-mod.js";
|
|
@@ -17,5 +22,6 @@ export {
|
|
|
17
22
|
createContentTypesGenerator,
|
|
18
23
|
errorMap,
|
|
19
24
|
getContentPaths,
|
|
20
|
-
getDotAstroTypeReference
|
|
25
|
+
getDotAstroTypeReference,
|
|
26
|
+
hasAssetPropagationFlag
|
|
21
27
|
};
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -184,4 +184,5 @@ export declare function getEntrySlug({ id, collection, generatedSlug, contentEnt
|
|
|
184
184
|
contentEntryType: Pick<ContentEntryType, 'getEntryInfo'>;
|
|
185
185
|
}): Promise<string>;
|
|
186
186
|
export declare function getExtGlob(exts: string[]): string;
|
|
187
|
+
export declare function hasAssetPropagationFlag(id: string): boolean;
|
|
187
188
|
export {};
|
package/dist/content/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
9
|
import { MarkdownError } from "../core/errors/index.js";
|
|
10
10
|
import { isYAMLException } from "../core/errors/utils.js";
|
|
11
|
-
import { CONTENT_FLAGS, CONTENT_TYPES_FILE } from "./consts.js";
|
|
11
|
+
import { CONTENT_FLAGS, CONTENT_TYPES_FILE, PROPAGATED_ASSET_FLAG } from "./consts.js";
|
|
12
12
|
import { errorMap } from "./error-map.js";
|
|
13
13
|
import { createImage } from "./runtime-assets.js";
|
|
14
14
|
const collectionConfigParser = z.union([
|
|
@@ -345,6 +345,13 @@ function getExtGlob(exts) {
|
|
|
345
345
|
exts[0]
|
|
346
346
|
) : `{${exts.join(",")}}`;
|
|
347
347
|
}
|
|
348
|
+
function hasAssetPropagationFlag(id) {
|
|
349
|
+
try {
|
|
350
|
+
return new URL(id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG);
|
|
351
|
+
} catch {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
348
355
|
export {
|
|
349
356
|
collectionConfigParser,
|
|
350
357
|
contentConfigParser,
|
|
@@ -363,6 +370,7 @@ export {
|
|
|
363
370
|
getExtGlob,
|
|
364
371
|
globalContentConfigObserver,
|
|
365
372
|
hasAnyContentFlag,
|
|
373
|
+
hasAssetPropagationFlag,
|
|
366
374
|
hasContentFlag,
|
|
367
375
|
hasUnderscoreBelowContentDirectoryPath,
|
|
368
376
|
loadContentConfig,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isBuildableCSSRequest } from "../../../vite-plugin-astro-server/util.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RESOLVED_VIRTUAL_MODULE_ID as ASTRO_CONTENT_VIRTUAL_MODULE_ID } from "../../../content/consts.js";
|
|
3
|
+
import { hasAssetPropagationFlag } from "../../../content/index.js";
|
|
3
4
|
import * as assetName from "../css-asset-name.js";
|
|
4
5
|
import {
|
|
5
6
|
getParentExtendedModuleInfos,
|
|
@@ -52,14 +53,9 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
52
53
|
}
|
|
53
54
|
const ctx = { getModuleInfo: meta.getModuleInfo };
|
|
54
55
|
for (const pageInfo of getParentModuleInfos(id, ctx)) {
|
|
55
|
-
if (
|
|
56
|
+
if (hasAssetPropagationFlag(pageInfo.id)) {
|
|
56
57
|
const chunkId2 = assetName.createNameHash(id, [id]);
|
|
57
58
|
internals.cssModuleToChunkIdMap.set(id, chunkId2);
|
|
58
|
-
if (isContentCollectionCache) {
|
|
59
|
-
const propagatedStyles = internals.propagatedStylesMap.get(pageInfo.id) ?? /* @__PURE__ */ new Set();
|
|
60
|
-
propagatedStyles.add({ type: "external", src: chunkId2 });
|
|
61
|
-
internals.propagatedStylesMap.set(pageInfo.id, propagatedStyles);
|
|
62
|
-
}
|
|
63
59
|
return chunkId2;
|
|
64
60
|
}
|
|
65
61
|
}
|
|
@@ -90,15 +86,11 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
88
|
for (const id of Object.keys(chunk.modules)) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
)) {
|
|
100
|
-
if (new URL(pageInfo.id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG)) {
|
|
101
|
-
for (const parentInfo of getParentModuleInfos(id, this)) {
|
|
89
|
+
const parentModuleInfos = getParentExtendedModuleInfos(id, this, hasAssetPropagationFlag);
|
|
90
|
+
for (const { info: pageInfo, depth, order } of parentModuleInfos) {
|
|
91
|
+
if (hasAssetPropagationFlag(pageInfo.id)) {
|
|
92
|
+
const walkId = isContentCollectionCache ? ASTRO_CONTENT_VIRTUAL_MODULE_ID : id;
|
|
93
|
+
for (const parentInfo of getParentModuleInfos(walkId, this)) {
|
|
102
94
|
if (moduleIsTopLevelPage(parentInfo) === false)
|
|
103
95
|
continue;
|
|
104
96
|
const pageViteID = parentInfo.id;
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
|
|
|
23
23
|
base: restart.container.settings.config.base
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
|
-
const currentVersion = "4.5.
|
|
26
|
+
const currentVersion = "4.5.12";
|
|
27
27
|
if (currentVersion.includes("-")) {
|
|
28
28
|
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
|
|
29
29
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -36,7 +36,7 @@ function serverStart({
|
|
|
36
36
|
host,
|
|
37
37
|
base
|
|
38
38
|
}) {
|
|
39
|
-
const version = "4.5.
|
|
39
|
+
const version = "4.5.12";
|
|
40
40
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
41
41
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
42
42
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -261,7 +261,7 @@ function printHelp({
|
|
|
261
261
|
message.push(
|
|
262
262
|
linebreak(),
|
|
263
263
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
264
|
-
`v${"4.5.
|
|
264
|
+
`v${"4.5.12"}`
|
|
265
265
|
)} ${headline}`
|
|
266
266
|
);
|
|
267
267
|
}
|
package/dist/core/request.js
CHANGED
|
@@ -33,7 +33,7 @@ function createRequest({
|
|
|
33
33
|
get() {
|
|
34
34
|
logger.warn(
|
|
35
35
|
null,
|
|
36
|
-
`\`Astro.request.headers\` is
|
|
36
|
+
`\`Astro.request.headers\` is unavailable in "static" output mode, and in prerendered pages within "hybrid" and "server" output modes. If you need access to request headers, make sure that \`output\` is configured as either \`"server"\` or \`output: "hybrid"\` in your config file, and that the page accessing the headers is rendered on-demand.`
|
|
37
37
|
);
|
|
38
38
|
return _headers;
|
|
39
39
|
}
|
|
@@ -10,6 +10,7 @@ import { MissingIndexForInternationalization } from "../../errors/errors-data.js
|
|
|
10
10
|
import { AstroError } from "../../errors/index.js";
|
|
11
11
|
import { removeLeadingForwardSlash, slash } from "../../path.js";
|
|
12
12
|
import { resolvePages } from "../../util.js";
|
|
13
|
+
import { routeComparator } from "../priority.js";
|
|
13
14
|
import { getRouteGenerator } from "./generator.js";
|
|
14
15
|
const require2 = createRequire(import.meta.url);
|
|
15
16
|
function countOccurrences(needle, haystack) {
|
|
@@ -101,54 +102,6 @@ function isSemanticallyEqualSegment(segmentA, segmentB) {
|
|
|
101
102
|
}
|
|
102
103
|
return true;
|
|
103
104
|
}
|
|
104
|
-
function routeComparator(a, b) {
|
|
105
|
-
const commonLength = Math.min(a.segments.length, b.segments.length);
|
|
106
|
-
for (let index = 0; index < commonLength; index++) {
|
|
107
|
-
const aSegment = a.segments[index];
|
|
108
|
-
const bSegment = b.segments[index];
|
|
109
|
-
const aIsStatic = aSegment.every((part) => !part.dynamic && !part.spread);
|
|
110
|
-
const bIsStatic = bSegment.every((part) => !part.dynamic && !part.spread);
|
|
111
|
-
if (aIsStatic && bIsStatic) {
|
|
112
|
-
const aContent = aSegment.map((part) => part.content).join("");
|
|
113
|
-
const bContent = bSegment.map((part) => part.content).join("");
|
|
114
|
-
if (aContent !== bContent) {
|
|
115
|
-
return aContent.localeCompare(bContent);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (aIsStatic !== bIsStatic) {
|
|
119
|
-
return aIsStatic ? -1 : 1;
|
|
120
|
-
}
|
|
121
|
-
const aAllDynamic = aSegment.every((part) => part.dynamic);
|
|
122
|
-
const bAllDynamic = bSegment.every((part) => part.dynamic);
|
|
123
|
-
if (aAllDynamic !== bAllDynamic) {
|
|
124
|
-
return aAllDynamic ? 1 : -1;
|
|
125
|
-
}
|
|
126
|
-
const aHasSpread = aSegment.some((part) => part.spread);
|
|
127
|
-
const bHasSpread = bSegment.some((part) => part.spread);
|
|
128
|
-
if (aHasSpread !== bHasSpread) {
|
|
129
|
-
return aHasSpread ? 1 : -1;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const aLength = a.segments.length;
|
|
133
|
-
const bLength = b.segments.length;
|
|
134
|
-
if (aLength !== bLength) {
|
|
135
|
-
const aEndsInRest = a.segments.at(-1)?.some((part) => part.spread);
|
|
136
|
-
const bEndsInRest = b.segments.at(-1)?.some((part) => part.spread);
|
|
137
|
-
if (aEndsInRest !== bEndsInRest && Math.abs(aLength - bLength) === 1) {
|
|
138
|
-
if (aLength > bLength && aEndsInRest) {
|
|
139
|
-
return 1;
|
|
140
|
-
}
|
|
141
|
-
if (bLength > aLength && bEndsInRest) {
|
|
142
|
-
return -1;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return aLength > bLength ? -1 : 1;
|
|
146
|
-
}
|
|
147
|
-
if (a.type === "endpoint" !== (b.type === "endpoint")) {
|
|
148
|
-
return a.type === "endpoint" ? -1 : 1;
|
|
149
|
-
}
|
|
150
|
-
return a.route.localeCompare(b.route);
|
|
151
|
-
}
|
|
152
105
|
function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
|
153
106
|
const components = [];
|
|
154
107
|
const routes = [];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RouteData } from '../../@types/astro.js';
|
|
2
|
+
/**
|
|
3
|
+
* Comparator for sorting routes in resolution order.
|
|
4
|
+
*
|
|
5
|
+
* The routes are sorted in by the following rules in order, following the first rule that
|
|
6
|
+
* applies:
|
|
7
|
+
* - More specific routes are sorted before less specific routes. Here, "specific" means
|
|
8
|
+
* the number of segments in the route, so a parent route is always sorted after its children.
|
|
9
|
+
* For example, `/foo/bar` is sorted before `/foo`.
|
|
10
|
+
* Index routes, originating from a file named `index.astro`, are considered to have one more
|
|
11
|
+
* segment than the URL they represent.
|
|
12
|
+
* - Static routes are sorted before dynamic routes.
|
|
13
|
+
* For example, `/foo/bar` is sorted before `/foo/[bar]`.
|
|
14
|
+
* - Dynamic routes with single parameters are sorted before dynamic routes with rest parameters.
|
|
15
|
+
* For example, `/foo/[bar]` is sorted before `/foo/[...bar]`.
|
|
16
|
+
* - Prerendered routes are sorted before non-prerendered routes.
|
|
17
|
+
* - Endpoints are sorted before pages.
|
|
18
|
+
* For example, a file `/foo.ts` is sorted before `/bar.astro`.
|
|
19
|
+
* - If both routes are equal regarding all previosu conditions, they are sorted alphabetically.
|
|
20
|
+
* For example, `/bar` is sorted before `/foo`.
|
|
21
|
+
* The definition of "alphabetically" is dependent on the default locale of the running system.
|
|
22
|
+
*/
|
|
23
|
+
export declare function routeComparator(a: RouteData, b: RouteData): number;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function routeComparator(a, b) {
|
|
2
|
+
const commonLength = Math.min(a.segments.length, b.segments.length);
|
|
3
|
+
for (let index = 0; index < commonLength; index++) {
|
|
4
|
+
const aSegment = a.segments[index];
|
|
5
|
+
const bSegment = b.segments[index];
|
|
6
|
+
const aIsStatic = aSegment.every((part) => !part.dynamic && !part.spread);
|
|
7
|
+
const bIsStatic = bSegment.every((part) => !part.dynamic && !part.spread);
|
|
8
|
+
if (aIsStatic && bIsStatic) {
|
|
9
|
+
const aContent = aSegment.map((part) => part.content).join("");
|
|
10
|
+
const bContent = bSegment.map((part) => part.content).join("");
|
|
11
|
+
if (aContent !== bContent) {
|
|
12
|
+
return aContent.localeCompare(bContent);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (aIsStatic !== bIsStatic) {
|
|
16
|
+
return aIsStatic ? -1 : 1;
|
|
17
|
+
}
|
|
18
|
+
const aAllDynamic = aSegment.every((part) => part.dynamic);
|
|
19
|
+
const bAllDynamic = bSegment.every((part) => part.dynamic);
|
|
20
|
+
if (aAllDynamic !== bAllDynamic) {
|
|
21
|
+
return aAllDynamic ? 1 : -1;
|
|
22
|
+
}
|
|
23
|
+
const aHasSpread = aSegment.some((part) => part.spread);
|
|
24
|
+
const bHasSpread = bSegment.some((part) => part.spread);
|
|
25
|
+
if (aHasSpread !== bHasSpread) {
|
|
26
|
+
return aHasSpread ? 1 : -1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const aLength = a.segments.length;
|
|
30
|
+
const bLength = b.segments.length;
|
|
31
|
+
if (aLength !== bLength) {
|
|
32
|
+
const aEndsInRest = a.segments.at(-1)?.some((part) => part.spread);
|
|
33
|
+
const bEndsInRest = b.segments.at(-1)?.some((part) => part.spread);
|
|
34
|
+
if (aEndsInRest !== bEndsInRest && Math.abs(aLength - bLength) === 1) {
|
|
35
|
+
if (aLength > bLength && aEndsInRest) {
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
if (bLength > aLength && bEndsInRest) {
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return aLength > bLength ? -1 : 1;
|
|
43
|
+
}
|
|
44
|
+
if (a.type === "endpoint" !== (b.type === "endpoint")) {
|
|
45
|
+
return a.type === "endpoint" ? -1 : 1;
|
|
46
|
+
}
|
|
47
|
+
return a.route.localeCompare(b.route);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
routeComparator
|
|
51
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RedirectComponentInstance, routeIsRedirect } from "../core/redirects/index.js";
|
|
2
|
+
import { routeComparator } from "../core/routing/priority.js";
|
|
2
3
|
import { getPrerenderStatus } from "./metadata.js";
|
|
3
4
|
async function getSortedPreloadedMatches({
|
|
4
5
|
pipeline,
|
|
@@ -9,7 +10,7 @@ async function getSortedPreloadedMatches({
|
|
|
9
10
|
pipeline,
|
|
10
11
|
matches,
|
|
11
12
|
settings
|
|
12
|
-
})).sort((a, b) => prioritizePrerenderedMatchesComparator(a.route, b.route));
|
|
13
|
+
})).sort((a, b) => routeComparator(a.route, b.route)).sort((a, b) => prioritizePrerenderedMatchesComparator(a.route, b.route));
|
|
13
14
|
}
|
|
14
15
|
async function preloadAndSetPrerenderStatus({
|
|
15
16
|
pipeline,
|
|
@@ -222,7 +222,7 @@ async function handleRoute({
|
|
|
222
222
|
})
|
|
223
223
|
);
|
|
224
224
|
}
|
|
225
|
-
if (response.status === 404 &&
|
|
225
|
+
if (response.status === 404 && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
|
|
226
226
|
const fourOhFourRoute = await matchRoute("/404", manifestData, pipeline);
|
|
227
227
|
if (options)
|
|
228
228
|
return handleRoute({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.12",
|
|
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",
|
|
@@ -161,9 +161,9 @@
|
|
|
161
161
|
"yargs-parser": "^21.1.1",
|
|
162
162
|
"zod": "^3.22.4",
|
|
163
163
|
"zod-to-json-schema": "^3.22.4",
|
|
164
|
-
"@astrojs/internal-helpers": "0.
|
|
165
|
-
"@astrojs/
|
|
166
|
-
"@astrojs/
|
|
164
|
+
"@astrojs/internal-helpers": "0.4.0",
|
|
165
|
+
"@astrojs/markdown-remark": "4.3.2",
|
|
166
|
+
"@astrojs/telemetry": "3.0.4"
|
|
167
167
|
},
|
|
168
168
|
"optionalDependencies": {
|
|
169
169
|
"sharp": "^0.32.6"
|
package/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import './astro-jsx';
|
|
2
2
|
import type { AstroBuiltinAttributes } from './dist/@types/astro.js';
|
|
3
|
-
import type { Simplify } from './dist/type-utils.js';
|
|
3
|
+
import type { OmitIndexSignature, Simplify } from './dist/type-utils.js';
|
|
4
4
|
|
|
5
5
|
/** Any supported HTML or SVG element name, as defined by the HTML specification */
|
|
6
6
|
export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements;
|
|
7
7
|
|
|
8
8
|
/** The built-in attributes for any known HTML or SVG element name */
|
|
9
9
|
export type HTMLAttributes<Tag extends HTMLTag> = Omit<
|
|
10
|
-
astroHTML.JSX.
|
|
10
|
+
astroHTML.JSX.DefinedIntrinsicElements[Tag],
|
|
11
11
|
keyof Omit<AstroBuiltinAttributes, 'class:list'>
|
|
12
12
|
>;
|
|
13
13
|
|
|
@@ -18,7 +18,12 @@ export type CSSProperty = keyof astroHTML.JSX.KebabCSSDOMProperties;
|
|
|
18
18
|
|
|
19
19
|
type PolymorphicAttributes<P extends { as: HTMLTag }> = Omit<P, 'as'> & {
|
|
20
20
|
as?: P['as'];
|
|
21
|
-
} &
|
|
21
|
+
} & Omit<
|
|
22
|
+
// This is the same as HTMLAttributes<P['as']>, except we're using OmitIndexSignature to remove the index signature,
|
|
23
|
+
// used for data attribute, because it seems like it get too complex for TypeScript with it, not sure why.
|
|
24
|
+
OmitIndexSignature<astroHTML.JSX.DefinedIntrinsicElements[P['as']]>,
|
|
25
|
+
keyof Omit<AstroBuiltinAttributes, 'class:list'>
|
|
26
|
+
>;
|
|
22
27
|
|
|
23
28
|
export type Polymorphic<P extends { as: HTMLTag }> = PolymorphicAttributes<
|
|
24
29
|
Omit<P, 'as'> & { as: NonNullable<P['as']> }
|