astro 7.0.0-beta.5 → 7.0.0-beta.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/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/content/content-layer.js +3 -3
- package/dist/core/build/plugins/plugin-manifest.js +1 -4
- package/dist/core/build/vite-build-config.js +6 -0
- package/dist/core/cache/config.d.ts +7 -6
- package/dist/core/cache/runtime/noop.js +1 -1
- package/dist/core/cache/utils.d.ts +3 -3
- package/dist/core/cache/vite-plugin.js +1 -1
- package/dist/core/config/schemas/base.d.ts +12 -12
- package/dist/core/config/schemas/base.js +3 -3
- package/dist/core/config/schemas/relative.d.ts +36 -36
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.js +2 -2
- package/dist/core/messages/runtime.js +1 -1
- package/dist/manifest/serialized.js +2 -5
- package/dist/types/public/config.d.ts +79 -77
- package/dist/vite-plugin-config-alias/index.d.ts +2 -2
- package/dist/vite-plugin-config-alias/index.js +66 -61
- package/package.json +2 -2
|
@@ -197,7 +197,7 @@ ${contentConfig.error.message}`
|
|
|
197
197
|
logger.info("Content config changed");
|
|
198
198
|
shouldClear = true;
|
|
199
199
|
}
|
|
200
|
-
if (previousAstroVersion && previousAstroVersion !== "7.0.0-beta.
|
|
200
|
+
if (previousAstroVersion && previousAstroVersion !== "7.0.0-beta.6") {
|
|
201
201
|
logger.info("Astro version changed");
|
|
202
202
|
shouldClear = true;
|
|
203
203
|
}
|
|
@@ -205,8 +205,8 @@ ${contentConfig.error.message}`
|
|
|
205
205
|
logger.info("Clearing content store");
|
|
206
206
|
this.#store.clearAll();
|
|
207
207
|
}
|
|
208
|
-
if ("7.0.0-beta.
|
|
209
|
-
this.#store.metaStore().set("astro-version", "7.0.0-beta.
|
|
208
|
+
if ("7.0.0-beta.6") {
|
|
209
|
+
this.#store.metaStore().set("astro-version", "7.0.0-beta.6");
|
|
210
210
|
}
|
|
211
211
|
if (currentConfigDigest) {
|
|
212
212
|
this.#store.metaStore().set("content-config-digest", currentConfigDigest);
|
|
@@ -258,10 +258,7 @@ async function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
258
258
|
allowedDomains: settings.config.security?.allowedDomains,
|
|
259
259
|
key: encodedKey,
|
|
260
260
|
sessionConfig: sessionConfigToManifest(settings.config.session),
|
|
261
|
-
cacheConfig: cacheConfigToManifest(
|
|
262
|
-
settings.config.experimental?.cache,
|
|
263
|
-
settings.config.experimental?.routeRules
|
|
264
|
-
),
|
|
261
|
+
cacheConfig: cacheConfigToManifest(settings.config.cache, settings.config.routeRules),
|
|
265
262
|
csp,
|
|
266
263
|
image: {
|
|
267
264
|
objectFit: settings.config.image.objectFit,
|
|
@@ -35,6 +35,12 @@ function createViteBuildConfig(opts) {
|
|
|
35
35
|
...viteConfig.build?.rolldownOptions,
|
|
36
36
|
// Setting as `exports-only` allows us to safely delete inputs that are only used during prerendering
|
|
37
37
|
preserveEntrySignatures: "exports-only",
|
|
38
|
+
checks: {
|
|
39
|
+
...viteConfig.build?.rolldownOptions?.checks,
|
|
40
|
+
// Disable Rolldown's built-in plugin timing warnings. These fire by default
|
|
41
|
+
// and produce noisy warnings about slow plugins during normal builds.
|
|
42
|
+
pluginTimings: false
|
|
43
|
+
},
|
|
38
44
|
...legacyAdapter && settings.buildOutput === "server" ? { input: LEGACY_SSR_ENTRY_VIRTUAL_MODULE } : {},
|
|
39
45
|
output: {
|
|
40
46
|
hoistTransitiveImports: false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
2
|
/**
|
|
3
|
-
* Cache provider configuration (
|
|
4
|
-
* Provider only - routes are configured via
|
|
3
|
+
* Cache provider configuration (`cache`).
|
|
4
|
+
* Provider only - routes are configured via `routeRules`.
|
|
5
5
|
*/
|
|
6
6
|
export declare const CacheSchema: z.ZodObject<{
|
|
7
7
|
provider: z.ZodOptional<z.ZodObject<{
|
|
@@ -11,14 +11,15 @@ export declare const CacheSchema: z.ZodObject<{
|
|
|
11
11
|
}, z.core.$strip>>;
|
|
12
12
|
}, z.core.$strip>;
|
|
13
13
|
/**
|
|
14
|
-
* Route rules configuration (
|
|
15
|
-
* Maps
|
|
14
|
+
* Route rules configuration (`routeRules`).
|
|
15
|
+
* Maps route patterns to route rules. Patterns use the same `[param]` and
|
|
16
|
+
* `[...rest]` syntax as file-based routing; glob wildcards (`*`) are not supported.
|
|
16
17
|
*
|
|
17
18
|
* Example:
|
|
18
19
|
* ```ts
|
|
19
20
|
* routeRules: {
|
|
20
|
-
* '/api
|
|
21
|
-
* '/products
|
|
21
|
+
* '/api/[...path]': { swr: 600 },
|
|
22
|
+
* '/products/[...slug]': { maxAge: 3600, tags: ['products'] },
|
|
22
23
|
* }
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
@@ -26,7 +26,7 @@ class DisabledAstroCache {
|
|
|
26
26
|
hasWarned = true;
|
|
27
27
|
this.#logger?.warn(
|
|
28
28
|
"cache",
|
|
29
|
-
"`cache.set()` was called but caching is not enabled. Configure a cache provider in your Astro config under `
|
|
29
|
+
"`cache.set()` was called but caching is not enabled. Configure a cache provider in your Astro config under `cache` to enable caching."
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -10,7 +10,7 @@ export declare function normalizeRouteRuleCacheOptions(rule: {
|
|
|
10
10
|
tags?: string[];
|
|
11
11
|
} | undefined): CacheOptions | undefined;
|
|
12
12
|
/**
|
|
13
|
-
* Extract cache routes from
|
|
13
|
+
* Extract cache routes from the `routeRules` config.
|
|
14
14
|
*/
|
|
15
|
-
export declare function extractCacheRoutesFromRouteRules(routeRules: AstroConfig['
|
|
16
|
-
export declare function cacheConfigToManifest(cacheConfig: AstroConfig['
|
|
15
|
+
export declare function extractCacheRoutesFromRouteRules(routeRules: AstroConfig['routeRules']): Record<string, CacheOptions> | undefined;
|
|
16
|
+
export declare function cacheConfigToManifest(cacheConfig: AstroConfig['cache'], routeRulesConfig: AstroConfig['routeRules']): SSRManifestCache | undefined;
|
|
@@ -7,7 +7,7 @@ const RESOLVED_VIRTUAL_CACHE_PROVIDER_ID = "\0" + VIRTUAL_CACHE_PROVIDER_ID;
|
|
|
7
7
|
function vitePluginCacheProvider({
|
|
8
8
|
settings
|
|
9
9
|
}) {
|
|
10
|
-
const providerConfig = settings.config.
|
|
10
|
+
const providerConfig = settings.config.cache?.provider;
|
|
11
11
|
if (!providerConfig) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
@@ -504,6 +504,18 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
504
504
|
unicodeRange: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
|
|
505
505
|
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
506
506
|
}, z.core.$strict>>>;
|
|
507
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
508
|
+
provider: z.ZodOptional<z.ZodObject<{
|
|
509
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
510
|
+
entrypoint: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
511
|
+
name: z.ZodOptional<z.ZodString>;
|
|
512
|
+
}, z.core.$strip>>;
|
|
513
|
+
}, z.core.$strip>>;
|
|
514
|
+
routeRules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
515
|
+
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
516
|
+
swr: z.ZodOptional<z.ZodNumber>;
|
|
517
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
518
|
+
}, z.core.$strip>>>;
|
|
507
519
|
experimental: z.ZodPrefault<z.ZodObject<{
|
|
508
520
|
clientPrerender: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
509
521
|
contentIntellisense: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -512,18 +524,6 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
512
524
|
name: z.ZodString;
|
|
513
525
|
optimize: z.ZodCustom<(contents: string) => string | Promise<string>, (contents: string) => string | Promise<string>>;
|
|
514
526
|
}, z.core.$strip>>;
|
|
515
|
-
cache: z.ZodOptional<z.ZodObject<{
|
|
516
|
-
provider: z.ZodOptional<z.ZodObject<{
|
|
517
|
-
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
518
|
-
entrypoint: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
519
|
-
name: z.ZodOptional<z.ZodString>;
|
|
520
|
-
}, z.core.$strip>>;
|
|
521
|
-
}, z.core.$strip>>;
|
|
522
|
-
routeRules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
523
|
-
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
524
|
-
swr: z.ZodOptional<z.ZodNumber>;
|
|
525
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
526
|
-
}, z.core.$strip>>>;
|
|
527
527
|
}, z.core.$strict>>;
|
|
528
528
|
legacy: z.ZodPrefault<z.ZodObject<{
|
|
529
529
|
collectionsBackwardsCompat: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -327,13 +327,13 @@ const AstroConfigSchema = z.object({
|
|
|
327
327
|
config: z.record(z.string(), z.any()).optional()
|
|
328
328
|
}).optional(),
|
|
329
329
|
fonts: z.array(FontFamilySchema).optional(),
|
|
330
|
+
cache: CacheSchema.optional(),
|
|
331
|
+
routeRules: RouteRulesSchema.optional(),
|
|
330
332
|
experimental: z.strictObject({
|
|
331
333
|
clientPrerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.clientPrerender),
|
|
332
334
|
contentIntellisense: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentIntellisense),
|
|
333
335
|
chromeDevtoolsWorkspace: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.chromeDevtoolsWorkspace),
|
|
334
|
-
svgOptimizer: SvgOptimizerSchema.optional()
|
|
335
|
-
cache: CacheSchema.optional(),
|
|
336
|
-
routeRules: RouteRulesSchema.optional()
|
|
336
|
+
svgOptimizer: SvgOptimizerSchema.optional()
|
|
337
337
|
}).prefault({}),
|
|
338
338
|
legacy: z.object({
|
|
339
339
|
collectionsBackwardsCompat: z.boolean().optional().default(false)
|
|
@@ -392,6 +392,18 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
392
392
|
unicodeRange: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
|
|
393
393
|
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
394
394
|
}, z.core.$strict>>>;
|
|
395
|
+
cache: z.ZodOptional<z.ZodObject<{
|
|
396
|
+
provider: z.ZodOptional<z.ZodObject<{
|
|
397
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
398
|
+
entrypoint: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
399
|
+
name: z.ZodOptional<z.ZodString>;
|
|
400
|
+
}, z.core.$strip>>;
|
|
401
|
+
}, z.core.$strip>>;
|
|
402
|
+
routeRules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
403
|
+
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
404
|
+
swr: z.ZodOptional<z.ZodNumber>;
|
|
405
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
406
|
+
}, z.core.$strip>>>;
|
|
395
407
|
experimental: z.ZodPrefault<z.ZodObject<{
|
|
396
408
|
clientPrerender: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
397
409
|
contentIntellisense: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -400,18 +412,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
400
412
|
name: z.ZodString;
|
|
401
413
|
optimize: z.ZodCustom<(contents: string) => string | Promise<string>, (contents: string) => string | Promise<string>>;
|
|
402
414
|
}, z.core.$strip>>;
|
|
403
|
-
cache: z.ZodOptional<z.ZodObject<{
|
|
404
|
-
provider: z.ZodOptional<z.ZodObject<{
|
|
405
|
-
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
406
|
-
entrypoint: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<URL, URL>]>;
|
|
407
|
-
name: z.ZodOptional<z.ZodString>;
|
|
408
|
-
}, z.core.$strip>>;
|
|
409
|
-
}, z.core.$strip>>;
|
|
410
|
-
routeRules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
411
|
-
maxAge: z.ZodOptional<z.ZodNumber>;
|
|
412
|
-
swr: z.ZodOptional<z.ZodNumber>;
|
|
413
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
414
|
-
}, z.core.$strip>>>;
|
|
415
415
|
}, z.core.$strict>>;
|
|
416
416
|
legacy: z.ZodPrefault<z.ZodObject<{
|
|
417
417
|
collectionsBackwardsCompat: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -590,18 +590,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
590
590
|
name: string;
|
|
591
591
|
optimize: (contents: string) => string | Promise<string>;
|
|
592
592
|
} | undefined;
|
|
593
|
-
cache?: {
|
|
594
|
-
provider?: {
|
|
595
|
-
entrypoint: string | URL;
|
|
596
|
-
config?: Record<string, any> | undefined;
|
|
597
|
-
name?: string | undefined;
|
|
598
|
-
} | undefined;
|
|
599
|
-
} | undefined;
|
|
600
|
-
routeRules?: Record<string, {
|
|
601
|
-
maxAge?: number | undefined;
|
|
602
|
-
swr?: number | undefined;
|
|
603
|
-
tags?: string[] | undefined;
|
|
604
|
-
}> | undefined;
|
|
605
593
|
};
|
|
606
594
|
legacy: {
|
|
607
595
|
collectionsBackwardsCompat: boolean;
|
|
@@ -696,6 +684,18 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
696
684
|
unicodeRange?: [string, ...string[]] | undefined;
|
|
697
685
|
options?: Record<string, any> | undefined;
|
|
698
686
|
}[] | undefined;
|
|
687
|
+
cache?: {
|
|
688
|
+
provider?: {
|
|
689
|
+
entrypoint: string | URL;
|
|
690
|
+
config?: Record<string, any> | undefined;
|
|
691
|
+
name?: string | undefined;
|
|
692
|
+
} | undefined;
|
|
693
|
+
} | undefined;
|
|
694
|
+
routeRules?: Record<string, {
|
|
695
|
+
maxAge?: number | undefined;
|
|
696
|
+
swr?: number | undefined;
|
|
697
|
+
tags?: string[] | undefined;
|
|
698
|
+
}> | undefined;
|
|
699
699
|
}, {
|
|
700
700
|
base: string;
|
|
701
701
|
trailingSlash: "never" | "ignore" | "always";
|
|
@@ -840,18 +840,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
840
840
|
name: string;
|
|
841
841
|
optimize: (contents: string) => string | Promise<string>;
|
|
842
842
|
} | undefined;
|
|
843
|
-
cache?: {
|
|
844
|
-
provider?: {
|
|
845
|
-
entrypoint: string | URL;
|
|
846
|
-
config?: Record<string, any> | undefined;
|
|
847
|
-
name?: string | undefined;
|
|
848
|
-
} | undefined;
|
|
849
|
-
} | undefined;
|
|
850
|
-
routeRules?: Record<string, {
|
|
851
|
-
maxAge?: number | undefined;
|
|
852
|
-
swr?: number | undefined;
|
|
853
|
-
tags?: string[] | undefined;
|
|
854
|
-
}> | undefined;
|
|
855
843
|
};
|
|
856
844
|
legacy: {
|
|
857
845
|
collectionsBackwardsCompat: boolean;
|
|
@@ -946,4 +934,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
946
934
|
unicodeRange?: [string, ...string[]] | undefined;
|
|
947
935
|
options?: Record<string, any> | undefined;
|
|
948
936
|
}[] | undefined;
|
|
937
|
+
cache?: {
|
|
938
|
+
provider?: {
|
|
939
|
+
entrypoint: string | URL;
|
|
940
|
+
config?: Record<string, any> | undefined;
|
|
941
|
+
name?: string | undefined;
|
|
942
|
+
} | undefined;
|
|
943
|
+
} | undefined;
|
|
944
|
+
routeRules?: Record<string, {
|
|
945
|
+
maxAge?: number | undefined;
|
|
946
|
+
swr?: number | undefined;
|
|
947
|
+
tags?: string[] | undefined;
|
|
948
|
+
}> | undefined;
|
|
949
949
|
}>>;
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -26,7 +26,7 @@ async function dev(inlineConfig) {
|
|
|
26
26
|
await telemetry.record([]);
|
|
27
27
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
28
28
|
const logger = restart.container.logger;
|
|
29
|
-
const currentVersion = "7.0.0-beta.
|
|
29
|
+
const currentVersion = "7.0.0-beta.6";
|
|
30
30
|
const isPrerelease = currentVersion.includes("-");
|
|
31
31
|
if (!isPrerelease) {
|
|
32
32
|
try {
|
|
@@ -793,8 +793,8 @@ const CacheProviderNotFound = {
|
|
|
793
793
|
const CacheNotEnabled = {
|
|
794
794
|
name: "CacheNotEnabled",
|
|
795
795
|
title: "Cache is not enabled.",
|
|
796
|
-
message: "`Astro.cache` is not available because the cache feature is not enabled. To use caching, configure a cache provider in your Astro config under `
|
|
797
|
-
hint: 'Use an adapter that provides a default cache provider, or set one explicitly: `
|
|
796
|
+
message: "`Astro.cache` is not available because the cache feature is not enabled. To use caching, configure a cache provider in your Astro config under `cache`.",
|
|
797
|
+
hint: 'Use an adapter that provides a default cache provider, or set one explicitly: `cache: { provider: "..." }`. See https://docs.astro.build/en/guides/caching/.'
|
|
798
798
|
};
|
|
799
799
|
const CacheQueryConfigConflict = {
|
|
800
800
|
name: "CacheQueryConfigConflict",
|
|
@@ -83,7 +83,7 @@ function serializedManifestPlugin({
|
|
|
83
83
|
const serialized = await createSerializedManifest(settings, await getEncodedKey());
|
|
84
84
|
manifestData = JSON.stringify(serialized);
|
|
85
85
|
}
|
|
86
|
-
const hasCacheConfig = !!settings.config.
|
|
86
|
+
const hasCacheConfig = !!settings.config.cache?.provider;
|
|
87
87
|
const cacheProviderLine = hasCacheConfig ? `cacheProvider: () => import('${VIRTUAL_CACHE_PROVIDER_ID}'),` : "";
|
|
88
88
|
const code = `
|
|
89
89
|
import { deserializeManifest as _deserializeManifest } from 'astro/app';
|
|
@@ -181,10 +181,7 @@ async function createSerializedManifest(settings, encodedKey) {
|
|
|
181
181
|
// 1mb default
|
|
182
182
|
key: encodedKey ?? await encodeKey(hasEnvironmentKey() ? await getEnvironmentKey() : await createKey()),
|
|
183
183
|
sessionConfig: sessionConfigToManifest(settings.config.session),
|
|
184
|
-
cacheConfig: cacheConfigToManifest(
|
|
185
|
-
settings.config.experimental?.cache,
|
|
186
|
-
settings.config.experimental?.routeRules
|
|
187
|
-
),
|
|
184
|
+
cacheConfig: cacheConfigToManifest(settings.config.cache, settings.config.routeRules),
|
|
188
185
|
csp,
|
|
189
186
|
image: {
|
|
190
187
|
objectFit: settings.config.image.objectFit,
|
|
@@ -2752,6 +2752,85 @@ export interface AstroUserConfig<TLocales extends Locales = never, TDriver exten
|
|
|
2752
2752
|
fonts?: [TFontProviders] extends [never] ? Array<FontFamily> : {
|
|
2753
2753
|
[K in keyof TFontProviders]: FontFamily<TFontProviders[K]>;
|
|
2754
2754
|
};
|
|
2755
|
+
/**
|
|
2756
|
+
* @docs
|
|
2757
|
+
* @kind heading
|
|
2758
|
+
* @name cache
|
|
2759
|
+
* @type {object}
|
|
2760
|
+
* @default `undefined`
|
|
2761
|
+
* @version 7.0.0
|
|
2762
|
+
* @description
|
|
2763
|
+
*
|
|
2764
|
+
* Enables route caching for SSR responses. Provides a platform-agnostic API
|
|
2765
|
+
* for caching rendered pages and API responses, with pluggable providers
|
|
2766
|
+
* that adapters can configure automatically.
|
|
2767
|
+
*
|
|
2768
|
+
* ```js
|
|
2769
|
+
* // astro.config.mjs
|
|
2770
|
+
* import { memoryCache } from 'astro/config';
|
|
2771
|
+
*
|
|
2772
|
+
* {
|
|
2773
|
+
* cache: {
|
|
2774
|
+
* provider: memoryCache(),
|
|
2775
|
+
* },
|
|
2776
|
+
* routeRules: {
|
|
2777
|
+
* '/blog/[...path]': { maxAge: 300, swr: 60 },
|
|
2778
|
+
* },
|
|
2779
|
+
* }
|
|
2780
|
+
* ```
|
|
2781
|
+
*
|
|
2782
|
+
* Use `Astro.cache.set()` in routes and `context.cache.set()` in middleware
|
|
2783
|
+
* or API routes to control caching per-request.
|
|
2784
|
+
*/
|
|
2785
|
+
cache?: {
|
|
2786
|
+
/**
|
|
2787
|
+
* @docs
|
|
2788
|
+
* @name cache.provider
|
|
2789
|
+
* @type {CacheProviderConfig}
|
|
2790
|
+
* @version 7.0.0
|
|
2791
|
+
* @description
|
|
2792
|
+
*
|
|
2793
|
+
* A provider that controls how responses are cached.
|
|
2794
|
+
*
|
|
2795
|
+
* Use the provider's config function to get type-safe configuration:
|
|
2796
|
+
*
|
|
2797
|
+
* ```js
|
|
2798
|
+
* import { defineConfig, memoryCache } from 'astro/config';
|
|
2799
|
+
*
|
|
2800
|
+
* export default defineConfig({
|
|
2801
|
+
* cache: { provider: memoryCache() },
|
|
2802
|
+
* });
|
|
2803
|
+
* ```
|
|
2804
|
+
*/
|
|
2805
|
+
provider?: CacheProviderConfig;
|
|
2806
|
+
};
|
|
2807
|
+
/**
|
|
2808
|
+
* @docs
|
|
2809
|
+
* @kind heading
|
|
2810
|
+
* @name routeRules
|
|
2811
|
+
* @type {Record<string, RouteRule>}
|
|
2812
|
+
* @default `undefined`
|
|
2813
|
+
* @version 7.0.0
|
|
2814
|
+
* @description
|
|
2815
|
+
*
|
|
2816
|
+
* Route patterns mapped to cache rules.
|
|
2817
|
+
* Uses the same `[param]` and `[...rest]` syntax as [file-based routing](/en/guides/routing/#route-priority-order).
|
|
2818
|
+
* Use a `[...rest]` parameter to match a group of routes:
|
|
2819
|
+
*
|
|
2820
|
+
* ```js
|
|
2821
|
+
* // astro.config.mjs
|
|
2822
|
+
* import { memoryCache } from 'astro/config';
|
|
2823
|
+
*
|
|
2824
|
+
* {
|
|
2825
|
+
* cache: { provider: memoryCache() },
|
|
2826
|
+
* routeRules: {
|
|
2827
|
+
* '/api/[...path]': { swr: 600 },
|
|
2828
|
+
* '/products/[...slug]': { maxAge: 3600, tags: ['products'] },
|
|
2829
|
+
* },
|
|
2830
|
+
* }
|
|
2831
|
+
* ```
|
|
2832
|
+
*/
|
|
2833
|
+
routeRules?: RouteRules;
|
|
2755
2834
|
/**
|
|
2756
2835
|
*
|
|
2757
2836
|
* @kind heading
|
|
@@ -2895,83 +2974,6 @@ export interface AstroUserConfig<TLocales extends Locales = never, TDriver exten
|
|
|
2895
2974
|
* See the [experimental SVG optimization docs](https://docs.astro.build/en/reference/experimental-flags/svg-optimization/) for more information.
|
|
2896
2975
|
*/
|
|
2897
2976
|
svgOptimizer?: SvgOptimizer;
|
|
2898
|
-
/**
|
|
2899
|
-
* @name experimental.cache
|
|
2900
|
-
* @type {object}
|
|
2901
|
-
* @default `undefined`
|
|
2902
|
-
* @description
|
|
2903
|
-
*
|
|
2904
|
-
* Enables route caching for SSR responses. Provides a platform-agnostic API
|
|
2905
|
-
* for caching rendered pages and API responses, with pluggable providers
|
|
2906
|
-
* that adapters can configure automatically.
|
|
2907
|
-
*
|
|
2908
|
-
* ```js
|
|
2909
|
-
* // astro.config.mjs
|
|
2910
|
-
* import { memoryCache } from 'astro/config';
|
|
2911
|
-
*
|
|
2912
|
-
* {
|
|
2913
|
-
* experimental: {
|
|
2914
|
-
* cache: {
|
|
2915
|
-
* provider: memoryCache(),
|
|
2916
|
-
* },
|
|
2917
|
-
* routeRules: {
|
|
2918
|
-
* '/blog/[...path]': { maxAge: 300, swr: 60 },
|
|
2919
|
-
* },
|
|
2920
|
-
* },
|
|
2921
|
-
* }
|
|
2922
|
-
* ```
|
|
2923
|
-
*
|
|
2924
|
-
* Use `Astro.cache.set()` in routes and `context.cache.set()` in middleware
|
|
2925
|
-
* or API routes to control caching per-request.
|
|
2926
|
-
*/
|
|
2927
|
-
cache?: {
|
|
2928
|
-
/**
|
|
2929
|
-
* @name experimental.cache.provider
|
|
2930
|
-
* @type {import('../../core/cache/types.js').CacheProviderConfig}
|
|
2931
|
-
* @description
|
|
2932
|
-
*
|
|
2933
|
-
* The cache provider. Adapters typically set a default, but you can
|
|
2934
|
-
* override it with your own.
|
|
2935
|
-
*
|
|
2936
|
-
* Use the provider's config function to get type-safe configuration:
|
|
2937
|
-
*
|
|
2938
|
-
* ```js
|
|
2939
|
-
* import { memoryCache } from 'astro/config';
|
|
2940
|
-
*
|
|
2941
|
-
* export default defineConfig({
|
|
2942
|
-
* experimental: {
|
|
2943
|
-
* cache: { provider: memoryCache() },
|
|
2944
|
-
* },
|
|
2945
|
-
* });
|
|
2946
|
-
* ```
|
|
2947
|
-
*/
|
|
2948
|
-
provider?: CacheProviderConfig;
|
|
2949
|
-
};
|
|
2950
|
-
/**
|
|
2951
|
-
* @name experimental.routeRules
|
|
2952
|
-
* @type {Record<string, RouteRule>}
|
|
2953
|
-
* @default `undefined`
|
|
2954
|
-
* @description
|
|
2955
|
-
*
|
|
2956
|
-
* Route patterns mapped to cache rules.
|
|
2957
|
-
* Uses the same `[param]` and `[...rest]` syntax as file-based routing.
|
|
2958
|
-
*
|
|
2959
|
-
* ```js
|
|
2960
|
-
* // astro.config.mjs
|
|
2961
|
-
* import { memoryCache } from 'astro/config';
|
|
2962
|
-
*
|
|
2963
|
-
* {
|
|
2964
|
-
* experimental: {
|
|
2965
|
-
* cache: { provider: memoryCache() },
|
|
2966
|
-
* routeRules: {
|
|
2967
|
-
* '/api/*': { swr: 600 },
|
|
2968
|
-
* '/products/*': { maxAge: 3600, tags: ['products'] },
|
|
2969
|
-
* },
|
|
2970
|
-
* },
|
|
2971
|
-
* }
|
|
2972
|
-
* ```
|
|
2973
|
-
*/
|
|
2974
|
-
routeRules?: RouteRules;
|
|
2975
2977
|
};
|
|
2976
2978
|
}
|
|
2977
2979
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Plugin as VitePlugin } from 'vite';
|
|
2
2
|
import type { AstroSettings } from '../types/astro.js';
|
|
3
|
-
/** Returns
|
|
3
|
+
/** Returns Vite plugins used to alias paths from tsconfig.json and jsconfig.json. */
|
|
4
4
|
export default function configAliasVitePlugin({ settings, }: {
|
|
5
5
|
settings: AstroSettings;
|
|
6
|
-
}): VitePlugin | null;
|
|
6
|
+
}): VitePlugin[] | null;
|
|
@@ -31,81 +31,86 @@ const getConfigAlias = (settings) => {
|
|
|
31
31
|
}
|
|
32
32
|
return aliases;
|
|
33
33
|
};
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (paths) {
|
|
43
|
-
for (const [aliasPattern, values] of Object.entries(paths)) {
|
|
44
|
-
const resolvedValues = values.map((v) => path.resolve(resolvedBaseUrl, v));
|
|
45
|
-
const customResolver = (id) => {
|
|
46
|
-
for (const resolvedValue of resolvedValues) {
|
|
47
|
-
const resolved = resolvedValue.replace("*", id);
|
|
48
|
-
const stats = fs.statSync(resolved, { throwIfNoEntry: false });
|
|
49
|
-
if (stats && stats.isFile()) {
|
|
50
|
-
return normalizePath(resolved);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
};
|
|
55
|
-
aliases.push({
|
|
56
|
-
// Build regex from alias pattern (e.g., '@styles/*' -> /^@styles\/(.+)$/)
|
|
57
|
-
// First, escape special regex chars. Then replace * with a capture group (.+)
|
|
58
|
-
find: new RegExp(
|
|
59
|
-
`^${aliasPattern.replace(/[\\^$+?.()|[\]{}]/g, "\\$&").replace(/\*/g, "(.+)")}$`
|
|
60
|
-
),
|
|
61
|
-
replacement: aliasPattern.includes("*") ? "$1" : aliasPattern,
|
|
62
|
-
customResolver
|
|
63
|
-
});
|
|
34
|
+
function resolveWithAlias(id, configAlias) {
|
|
35
|
+
for (const alias of configAlias) {
|
|
36
|
+
if (alias.find.test(id)) {
|
|
37
|
+
const updatedId = id.replace(alias.find, alias.replacement);
|
|
38
|
+
const stats = fs.statSync(updatedId, { throwIfNoEntry: false });
|
|
39
|
+
if (stats && stats.isFile()) {
|
|
40
|
+
return normalizePath(updatedId);
|
|
41
|
+
}
|
|
64
42
|
}
|
|
65
43
|
}
|
|
66
|
-
return
|
|
67
|
-
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const cssImportRE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]\s*\)?/g;
|
|
68
47
|
function configAliasVitePlugin({
|
|
69
48
|
settings
|
|
70
49
|
}) {
|
|
71
50
|
const configAlias = getConfigAlias(settings);
|
|
72
51
|
if (!configAlias) return null;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
52
|
+
return [
|
|
53
|
+
// Pre-plugin: rewrite CSS @import aliases to absolute paths before Vite's CSS plugin.
|
|
54
|
+
// Vite's internal CSS @import resolver (postcss-import) uses a mini plugin container
|
|
55
|
+
// that doesn't include user resolveId hooks, so we must rewrite aliases in a transform
|
|
56
|
+
// hook that runs before Vite's CSS processing.
|
|
57
|
+
{
|
|
58
|
+
name: "astro:tsconfig-alias-css",
|
|
59
|
+
enforce: "pre",
|
|
60
|
+
transform: {
|
|
61
|
+
filter: {
|
|
62
|
+
id: {
|
|
63
|
+
include: /\.css$/
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
handler(code) {
|
|
67
|
+
if (!code.includes("@import")) return;
|
|
68
|
+
let hasReplacement = false;
|
|
69
|
+
const result = code.replace(cssImportRE, (match, importId) => {
|
|
70
|
+
if (!importId) return match;
|
|
71
|
+
const resolved = resolveWithAlias(importId, configAlias);
|
|
72
|
+
if (resolved) {
|
|
73
|
+
hasReplacement = true;
|
|
74
|
+
return match.replace(importId, resolved);
|
|
75
|
+
}
|
|
76
|
+
return match;
|
|
77
|
+
});
|
|
78
|
+
if (hasReplacement) {
|
|
79
|
+
return { code: result, map: null };
|
|
80
|
+
}
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|
|
83
83
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
// Post-plugin: resolve JS/TS imports using tsconfig path aliases via resolveId.
|
|
85
|
+
{
|
|
86
|
+
name: "astro:tsconfig-alias",
|
|
87
|
+
// use post to only resolve ids that all other plugins before it can't
|
|
88
|
+
enforce: "post",
|
|
89
|
+
resolveId: {
|
|
90
|
+
filter: {
|
|
91
|
+
id: {
|
|
92
|
+
include: configAlias.map((alias) => alias.find),
|
|
93
|
+
exclude: /(?:\0|^virtual:|^astro:)/
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
async handler(id, importer, options) {
|
|
97
|
+
for (const alias of configAlias) {
|
|
98
|
+
if (alias.find.test(id)) {
|
|
99
|
+
const updatedId = id.replace(alias.find, alias.replacement);
|
|
100
|
+
if (updatedId.includes("*")) {
|
|
101
|
+
return updatedId;
|
|
102
|
+
}
|
|
103
|
+
const resolved = await this.resolve(updatedId, importer, {
|
|
104
|
+
skipSelf: true,
|
|
105
|
+
...options
|
|
106
|
+
});
|
|
107
|
+
if (resolved) return resolved;
|
|
97
108
|
}
|
|
98
|
-
const resolved = await this.resolve(updatedId, importer, {
|
|
99
|
-
skipSelf: true,
|
|
100
|
-
...options
|
|
101
|
-
});
|
|
102
|
-
if (resolved) return resolved;
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
|
-
|
|
108
|
-
return plugin;
|
|
113
|
+
];
|
|
109
114
|
}
|
|
110
115
|
export {
|
|
111
116
|
configAliasVitePlugin as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.6",
|
|
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",
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"yargs-parser": "^22.0.0",
|
|
167
167
|
"zod": "^4.3.6",
|
|
168
168
|
"@astrojs/internal-helpers": "0.10.0",
|
|
169
|
-
"@astrojs/markdown-satteri": "0.3.1-beta.
|
|
169
|
+
"@astrojs/markdown-satteri": "0.3.1-beta.2",
|
|
170
170
|
"@astrojs/telemetry": "3.3.2"
|
|
171
171
|
},
|
|
172
172
|
"optionalDependencies": {
|