astro 4.1.2 → 4.2.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/components/ViewTransitions.astro +6 -1
- package/dist/@types/astro.d.ts +127 -25
- package/dist/assets/internal.js +3 -2
- package/dist/assets/services/noop.js +1 -4
- package/dist/assets/types.d.ts +1 -1
- package/dist/assets/utils/emitAsset.js +1 -1
- package/dist/assets/utils/proxy.d.ts +2 -1
- package/dist/assets/utils/proxy.js +5 -1
- package/dist/assets/vite-plugin-assets.js +21 -14
- package/dist/content/runtime-assets.d.ts +1 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/types-generator.js +0 -26
- package/dist/content/utils.d.ts +1 -1
- package/dist/content/utils.js +3 -10
- package/dist/content/vite-plugin-content-imports.js +1 -0
- package/dist/core/app/createOutgoingHttpHeaders.d.ts +9 -0
- package/dist/core/app/createOutgoingHttpHeaders.js +19 -0
- package/dist/core/app/index.d.ts +38 -1
- package/dist/core/app/index.js +38 -8
- package/dist/core/app/node.d.ts +42 -10
- package/dist/core/app/node.js +87 -46
- package/dist/core/app/types.d.ts +2 -1
- package/dist/core/config/schema.d.ts +146 -66
- package/dist/core/config/schema.js +24 -6
- package/dist/core/config/vite-load.js +2 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +3 -3
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.d.ts +2 -1
- package/dist/core/errors/dev/vite.js +5 -11
- package/dist/core/errors/errors-data.d.ts +5 -0
- package/dist/core/errors/errors-data.js +7 -0
- package/dist/core/errors/overlay.js +2 -2
- package/dist/core/logger/vite.d.ts +0 -1
- package/dist/core/logger/vite.js +1 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/render/context.d.ts +3 -2
- package/dist/core/render/context.js +1 -1
- package/dist/core/render/result.d.ts +2 -1
- package/dist/core/routing/manifest/create.d.ts +1 -1
- package/dist/core/routing/manifest/create.js +175 -117
- package/dist/core/sync/index.js +2 -2
- package/dist/i18n/index.d.ts +3 -2
- package/dist/i18n/index.js +4 -4
- package/dist/i18n/middleware.js +36 -19
- package/dist/prefetch/index.js +17 -1
- package/dist/prefetch/vite-plugin-prefetch.js +4 -1
- package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/astro.js +2 -2
- package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/audit/a11y.js +52 -4
- package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/audit/index.js +3 -3
- package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/settings.js +7 -7
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +8 -0
- package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/utils/window.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/xray.js +4 -4
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/entrypoint.js +64 -68
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/settings.d.ts +2 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/settings.js +10 -5
- package/dist/runtime/client/dev-toolbar/toolbar.d.ts +45 -0
- package/dist/runtime/client/{dev-overlay/overlay.js → dev-toolbar/toolbar.js} +99 -103
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/badge.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/badge.js +2 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/button.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/button.js +3 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/card.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/card.js +2 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/highlight.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/highlight.js +2 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/icon.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/icon.js +2 -2
- package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +8 -0
- package/dist/runtime/client/dev-toolbar/ui-library/index.js +18 -0
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/toggle.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/toggle.js +2 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/tooltip.d.ts +3 -3
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/tooltip.js +2 -2
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/window.d.ts +1 -1
- package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/window.js +3 -3
- package/dist/vite-plugin-astro/compile.js +0 -4
- package/dist/vite-plugin-astro/hmr.d.ts +3 -2
- package/dist/vite-plugin-astro/hmr.js +20 -41
- package/dist/vite-plugin-astro/index.js +36 -3
- package/dist/vite-plugin-astro/query.d.ts +0 -1
- package/dist/vite-plugin-astro/query.js +0 -5
- package/dist/vite-plugin-astro-server/route.js +3 -3
- package/dist/{vite-plugin-dev-overlay/vite-plugin-dev-overlay.d.ts → vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.d.ts} +1 -1
- package/dist/{vite-plugin-dev-overlay/vite-plugin-dev-overlay.js → vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js} +5 -5
- package/dist/vite-plugin-markdown/images.js +46 -19
- package/package.json +4 -3
- package/dist/runtime/client/dev-overlay/overlay.d.ts +0 -45
- package/dist/runtime/client/dev-overlay/plugins/utils/highlight.d.ts +0 -8
- package/dist/runtime/client/dev-overlay/ui-library/index.d.ts +0 -8
- package/dist/runtime/client/dev-overlay/ui-library/index.js +0 -18
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/astro.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/audit/a11y.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/audit/index.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/settings.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/utils/highlight.js +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/utils/icons.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/utils/icons.js +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/utils/window.js +0 -0
- /package/dist/runtime/client/{dev-overlay/plugins → dev-toolbar/apps}/xray.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay → dev-toolbar}/entrypoint.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/icons.d.ts +0 -0
- /package/dist/runtime/client/{dev-overlay → dev-toolbar}/ui-library/icons.js +0 -0
|
@@ -53,6 +53,9 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
53
53
|
if (supportsViewTransitions || getFallback() !== 'none') {
|
|
54
54
|
document.addEventListener('click', (ev) => {
|
|
55
55
|
let link = ev.target;
|
|
56
|
+
if (ev.composed) {
|
|
57
|
+
link = ev.composedPath()[0];
|
|
58
|
+
}
|
|
56
59
|
if (link instanceof Element) {
|
|
57
60
|
link = link.closest('a, area');
|
|
58
61
|
}
|
|
@@ -106,7 +109,9 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
106
109
|
|
|
107
110
|
// the "dialog" method is a special keyword used within <dialog> elements
|
|
108
111
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method
|
|
109
|
-
if (method === 'dialog') {
|
|
112
|
+
if (method === 'dialog' || location.origin !== new URL(action, location.href).origin) {
|
|
113
|
+
// No page transitions in these cases,
|
|
114
|
+
// Let the browser standard action handle this
|
|
110
115
|
return;
|
|
111
116
|
}
|
|
112
117
|
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -15,9 +15,9 @@ import type { TSConfig } from '../core/config/tsconfig.js';
|
|
|
15
15
|
import type { AstroCookies } from '../core/cookies/index.js';
|
|
16
16
|
import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js';
|
|
17
17
|
import type { AstroPreferences } from '../preferences/index.js';
|
|
18
|
-
import type {
|
|
19
|
-
import type { Icon } from '../runtime/client/dev-
|
|
20
|
-
import type {
|
|
18
|
+
import type { AstroDevToolbar, DevToolbarCanvas } from '../runtime/client/dev-toolbar/toolbar.js';
|
|
19
|
+
import type { Icon } from '../runtime/client/dev-toolbar/ui-library/icons.js';
|
|
20
|
+
import type { DevToolbarBadge, DevToolbarButton, DevToolbarCard, DevToolbarHighlight, DevToolbarIcon, DevToolbarToggle, DevToolbarTooltip, DevToolbarWindow } from '../runtime/client/dev-toolbar/ui-library/index.js';
|
|
21
21
|
import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server/index.js';
|
|
22
22
|
import type { DeepPartial, OmitIndexSignature, Simplify } from '../type-utils.js';
|
|
23
23
|
import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
@@ -1374,6 +1374,34 @@ export interface AstroUserConfig {
|
|
|
1374
1374
|
* Localized folders are used for every language, including the default.
|
|
1375
1375
|
*/
|
|
1376
1376
|
prefixDefaultLocale: boolean;
|
|
1377
|
+
/**
|
|
1378
|
+
* @docs
|
|
1379
|
+
* @name i18n.routing.redirectToDefaultLocale
|
|
1380
|
+
* @kind h4
|
|
1381
|
+
* @type {boolean}
|
|
1382
|
+
* @default `true`
|
|
1383
|
+
* @version 4.2.0
|
|
1384
|
+
* @description
|
|
1385
|
+
*
|
|
1386
|
+
* Configures whether or not the home URL (`/`) generated by `src/pages/index.astro`
|
|
1387
|
+
* will redirect to `/[defaultLocale]` when `prefixDefaultLocale: true` is set.
|
|
1388
|
+
*
|
|
1389
|
+
* Set `redirectToDefaultLocale: false` to disable this automatic redirection at the root of your site:
|
|
1390
|
+
* ```js
|
|
1391
|
+
* // astro.config.mjs
|
|
1392
|
+
* export default defineConfig({
|
|
1393
|
+
* i18n:{
|
|
1394
|
+
* defaultLocale: "en",
|
|
1395
|
+
* locales: ["en", "fr"],
|
|
1396
|
+
* routing: {
|
|
1397
|
+
* prefixDefaultLocale: true,
|
|
1398
|
+
* redirectToDefaultLocale: false
|
|
1399
|
+
* }
|
|
1400
|
+
* }
|
|
1401
|
+
* })
|
|
1402
|
+
*```
|
|
1403
|
+
* */
|
|
1404
|
+
redirectToDefaultLocale: boolean;
|
|
1377
1405
|
/**
|
|
1378
1406
|
* @name i18n.routing.strategy
|
|
1379
1407
|
* @type {"pathname"}
|
|
@@ -1444,6 +1472,70 @@ export interface AstroUserConfig {
|
|
|
1444
1472
|
* ```
|
|
1445
1473
|
*/
|
|
1446
1474
|
contentCollectionCache?: boolean;
|
|
1475
|
+
/**
|
|
1476
|
+
* @docs
|
|
1477
|
+
* @name experimental.clientPrerender
|
|
1478
|
+
* @type {boolean}
|
|
1479
|
+
* @default `false`
|
|
1480
|
+
* @version 4.2.0
|
|
1481
|
+
* @description
|
|
1482
|
+
* Enables pre-rendering your prefetched pages on the client in supported browsers.
|
|
1483
|
+
*
|
|
1484
|
+
* This feature uses the experimental [Speculation Rules Web API](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API) and overrides the default `prefetch` behavior globally to prerender links on the client.
|
|
1485
|
+
* You may wish to review the [possible risks when prerendering on the client](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API#unsafe_prefetching) before enabling this feature.
|
|
1486
|
+
*
|
|
1487
|
+
* Enable client side prerendering in your `astro.config.mjs` along with any desired `prefetch` configuration options:
|
|
1488
|
+
*
|
|
1489
|
+
* ```js
|
|
1490
|
+
* // astro.config.mjs
|
|
1491
|
+
* {
|
|
1492
|
+
* prefetch: {
|
|
1493
|
+
* prefetchAll: true,
|
|
1494
|
+
* defaultStrategy: 'viewport',
|
|
1495
|
+
* },
|
|
1496
|
+
* experimental: {
|
|
1497
|
+
* clientPrerender: true,
|
|
1498
|
+
* },
|
|
1499
|
+
* }
|
|
1500
|
+
* ```
|
|
1501
|
+
*
|
|
1502
|
+
* Continue to use the `data-astro-prefetch` attribute on any `<a />` link on your site to opt in to prefetching.
|
|
1503
|
+
* Instead of appending a `<link>` tag to the head of the document or fetching the page with JavaScript, a `<script>` tag will be appended with the corresponding speculation rules.
|
|
1504
|
+
*
|
|
1505
|
+
* Client side prerendering requires browser support. If the Speculation Rules API is not supported, `prefetch` will fallback to the supported strategy.
|
|
1506
|
+
*
|
|
1507
|
+
* See the [Prefetch Guide](https://docs.astro.build/en/guides/prefetch/) for more `prefetch` options and usage.
|
|
1508
|
+
*/
|
|
1509
|
+
clientPrerender?: boolean;
|
|
1510
|
+
/**
|
|
1511
|
+
* @docs
|
|
1512
|
+
* @name experimental.globalRoutePriority
|
|
1513
|
+
* @type {boolean}
|
|
1514
|
+
* @default `false`
|
|
1515
|
+
* @version 4.2.0
|
|
1516
|
+
* @description
|
|
1517
|
+
*
|
|
1518
|
+
* Prioritizes redirects and injected routes equally alongside file-based project routes, following the same [route priority order rules](https://docs.astro.build/en/core-concepts/routing/#route-priority-order) for all routes.
|
|
1519
|
+
*
|
|
1520
|
+
* This allows more control over routing in your project by not automatically prioritizing certain types of routes, and standardizes the route priority ordering for all routes.
|
|
1521
|
+
*
|
|
1522
|
+
* The following example shows which route will build certain page URLs when file-based routes, injected routes, and redirects are combined as shown below:
|
|
1523
|
+
* - File-based route: `/blog/post/[pid]`
|
|
1524
|
+
* - File-based route: `/[page]`
|
|
1525
|
+
* - Injected route: `/blog/[...slug]`
|
|
1526
|
+
* - Redirect: `/blog/tags/[tag]` -> `/[tag]`
|
|
1527
|
+
* - Redirect: `/posts` -> `/blog`
|
|
1528
|
+
*
|
|
1529
|
+
* With `experimental.globalRoutingPriority` enabled (instead of Astro 4.0 default route priority order):
|
|
1530
|
+
*
|
|
1531
|
+
* - `/blog/tags/astro` is built by the redirect to `/tags/[tag]` (instead of the injected route `/blog/[...slug]`)
|
|
1532
|
+
* - `/blog/post/0` is built by the file-based route `/blog/post/[pid]` (instead of the injected route `/blog/[...slug]`)
|
|
1533
|
+
* - `/posts` is built by the redirect to `/blog` (instead of the file-based route `/[page]`)
|
|
1534
|
+
*
|
|
1535
|
+
*
|
|
1536
|
+
* In the event of route collisions, where two routes of equal route priority attempt to build the same URL, Astro will log a warning identifying the conflicting routes.
|
|
1537
|
+
*/
|
|
1538
|
+
globalRoutePriority?: boolean;
|
|
1447
1539
|
};
|
|
1448
1540
|
}
|
|
1449
1541
|
/**
|
|
@@ -1454,6 +1546,14 @@ export interface AstroUserConfig {
|
|
|
1454
1546
|
* - "page-ssr": Injected into the frontmatter of every Astro page. Processed & resolved by Vite.
|
|
1455
1547
|
*/
|
|
1456
1548
|
export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' | 'page-ssr';
|
|
1549
|
+
/**
|
|
1550
|
+
* IDs for different priorities of injected routes and redirects:
|
|
1551
|
+
* - "normal": Merge with discovered file-based project routes, behaving the same as if the route
|
|
1552
|
+
* was defined as a file in the project.
|
|
1553
|
+
* - "legacy": Use the old ordering of routes. Inject routes will override any file-based project route,
|
|
1554
|
+
* and redirects will be overridden by any project route on conflict.
|
|
1555
|
+
*/
|
|
1556
|
+
export type RoutePriorityOverride = 'normal' | 'legacy';
|
|
1457
1557
|
export interface InjectedRoute {
|
|
1458
1558
|
pattern: string;
|
|
1459
1559
|
entrypoint: string;
|
|
@@ -2082,6 +2182,7 @@ export interface AstroIntegration {
|
|
|
2082
2182
|
addClientDirective: (directive: ClientDirectiveConfig) => void;
|
|
2083
2183
|
/**
|
|
2084
2184
|
* @deprecated Use `addDevToolbarApp` instead.
|
|
2185
|
+
* TODO: Fully remove in Astro 5.0
|
|
2085
2186
|
*/
|
|
2086
2187
|
addDevOverlayPlugin: (entrypoint: string) => void;
|
|
2087
2188
|
addDevToolbarApp: (entrypoint: string) => void;
|
|
@@ -2169,6 +2270,7 @@ export interface RoutePart {
|
|
|
2169
2270
|
type RedirectConfig = string | {
|
|
2170
2271
|
status: ValidRedirectStatus;
|
|
2171
2272
|
destination: string;
|
|
2273
|
+
priority?: RoutePriorityOverride;
|
|
2172
2274
|
};
|
|
2173
2275
|
export interface RouteData {
|
|
2174
2276
|
route: string;
|
|
@@ -2302,8 +2404,8 @@ export interface DevToolbarApp {
|
|
|
2302
2404
|
beforeTogglingOff?(canvas: ShadowRoot): boolean | Promise<boolean>;
|
|
2303
2405
|
}
|
|
2304
2406
|
export type DevOverlayPlugin = DevToolbarApp;
|
|
2305
|
-
export type
|
|
2306
|
-
|
|
2407
|
+
export type DevToolbarMetadata = Window & typeof globalThis & {
|
|
2408
|
+
__astro_dev_toolbar__: {
|
|
2307
2409
|
root: string;
|
|
2308
2410
|
version: string;
|
|
2309
2411
|
debugInfo: string;
|
|
@@ -2311,25 +2413,25 @@ export type DevOverlayMetadata = Window & typeof globalThis & {
|
|
|
2311
2413
|
};
|
|
2312
2414
|
declare global {
|
|
2313
2415
|
interface HTMLElementTagNameMap {
|
|
2314
|
-
'astro-dev-toolbar':
|
|
2315
|
-
'astro-dev-toolbar-window':
|
|
2316
|
-
'astro-dev-toolbar-
|
|
2317
|
-
'astro-dev-toolbar-tooltip':
|
|
2318
|
-
'astro-dev-toolbar-highlight':
|
|
2319
|
-
'astro-dev-toolbar-toggle':
|
|
2320
|
-
'astro-dev-toolbar-badge':
|
|
2321
|
-
'astro-dev-toolbar-button':
|
|
2322
|
-
'astro-dev-toolbar-icon':
|
|
2323
|
-
'astro-dev-toolbar-card':
|
|
2324
|
-
'astro-dev-overlay':
|
|
2325
|
-
'astro-dev-overlay-window':
|
|
2326
|
-
'astro-dev-overlay-plugin-canvas':
|
|
2327
|
-
'astro-dev-overlay-tooltip':
|
|
2328
|
-
'astro-dev-overlay-highlight':
|
|
2329
|
-
'astro-dev-overlay-toggle':
|
|
2330
|
-
'astro-dev-overlay-badge':
|
|
2331
|
-
'astro-dev-overlay-button':
|
|
2332
|
-
'astro-dev-overlay-icon':
|
|
2333
|
-
'astro-dev-overlay-card':
|
|
2416
|
+
'astro-dev-toolbar': AstroDevToolbar;
|
|
2417
|
+
'astro-dev-toolbar-window': DevToolbarWindow;
|
|
2418
|
+
'astro-dev-toolbar-app-canvas': DevToolbarCanvas;
|
|
2419
|
+
'astro-dev-toolbar-tooltip': DevToolbarTooltip;
|
|
2420
|
+
'astro-dev-toolbar-highlight': DevToolbarHighlight;
|
|
2421
|
+
'astro-dev-toolbar-toggle': DevToolbarToggle;
|
|
2422
|
+
'astro-dev-toolbar-badge': DevToolbarBadge;
|
|
2423
|
+
'astro-dev-toolbar-button': DevToolbarButton;
|
|
2424
|
+
'astro-dev-toolbar-icon': DevToolbarIcon;
|
|
2425
|
+
'astro-dev-toolbar-card': DevToolbarCard;
|
|
2426
|
+
'astro-dev-overlay': AstroDevToolbar;
|
|
2427
|
+
'astro-dev-overlay-window': DevToolbarWindow;
|
|
2428
|
+
'astro-dev-overlay-plugin-canvas': DevToolbarCanvas;
|
|
2429
|
+
'astro-dev-overlay-tooltip': DevToolbarTooltip;
|
|
2430
|
+
'astro-dev-overlay-highlight': DevToolbarHighlight;
|
|
2431
|
+
'astro-dev-overlay-toggle': DevToolbarToggle;
|
|
2432
|
+
'astro-dev-overlay-badge': DevToolbarBadge;
|
|
2433
|
+
'astro-dev-overlay-button': DevToolbarButton;
|
|
2434
|
+
'astro-dev-overlay-icon': DevToolbarIcon;
|
|
2435
|
+
'astro-dev-overlay-card': DevToolbarCard;
|
|
2334
2436
|
}
|
|
2335
2437
|
}
|
package/dist/assets/internal.js
CHANGED
|
@@ -41,6 +41,7 @@ async function getImage(options, imageConfig) {
|
|
|
41
41
|
...options,
|
|
42
42
|
src: typeof options.src === "object" && "then" in options.src ? (await options.src).default ?? await options.src : options.src
|
|
43
43
|
};
|
|
44
|
+
const originalPath = isESMImportedImage(resolvedOptions.src) ? resolvedOptions.src.fsPath : resolvedOptions.src;
|
|
44
45
|
const clonedSrc = isESMImportedImage(resolvedOptions.src) ? (
|
|
45
46
|
// @ts-expect-error - clone is a private, hidden prop
|
|
46
47
|
resolvedOptions.src.clone ?? resolvedOptions.src
|
|
@@ -59,10 +60,10 @@ async function getImage(options, imageConfig) {
|
|
|
59
60
|
);
|
|
60
61
|
if (isLocalService(service) && globalThis.astroAsset.addStaticImage && !(isRemoteImage(validatedOptions.src) && imageURL === validatedOptions.src)) {
|
|
61
62
|
const propsToHash = service.propertiesToHash ?? DEFAULT_HASH_PROPS;
|
|
62
|
-
imageURL = globalThis.astroAsset.addStaticImage(validatedOptions, propsToHash);
|
|
63
|
+
imageURL = globalThis.astroAsset.addStaticImage(validatedOptions, propsToHash, originalPath);
|
|
63
64
|
srcSets = srcSetTransforms.map((srcSet) => ({
|
|
64
65
|
transform: srcSet.transform,
|
|
65
|
-
url: globalThis.astroAsset.addStaticImage(srcSet.transform, propsToHash),
|
|
66
|
+
url: globalThis.astroAsset.addStaticImage(srcSet.transform, propsToHash, originalPath),
|
|
66
67
|
descriptor: srcSet.descriptor,
|
|
67
68
|
attributes: srcSet.attributes
|
|
68
69
|
}));
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { baseService } from "./service.js";
|
|
2
2
|
const noopService = {
|
|
3
|
+
...baseService,
|
|
3
4
|
propertiesToHash: ["src"],
|
|
4
|
-
validateOptions: baseService.validateOptions,
|
|
5
|
-
getURL: baseService.getURL,
|
|
6
|
-
parseURL: baseService.parseURL,
|
|
7
|
-
getHTMLAttributes: baseService.getHTMLAttributes,
|
|
8
5
|
async transform(inputBuffer, transformOptions) {
|
|
9
6
|
return {
|
|
10
7
|
data: inputBuffer,
|
package/dist/assets/types.d.ts
CHANGED
|
@@ -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[]) => string) | undefined;
|
|
18
|
+
addStaticImage?: ((options: ImageTransform, hashProperties: string[], fsPath: string) => string) | undefined;
|
|
19
19
|
staticImages?: AssetsGlobalStaticImagesList;
|
|
20
20
|
referencedImages?: Set<string>;
|
|
21
21
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ImageMetadata } from '../types.js';
|
|
2
|
+
export declare function getProxyCode(options: ImageMetadata, isSSR: boolean): string;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
function getProxyCode(options, isSSR) {
|
|
2
|
+
const stringifiedFSPath = JSON.stringify(options.fsPath);
|
|
2
3
|
return `
|
|
3
4
|
new Proxy(${JSON.stringify(options)}, {
|
|
4
5
|
get(target, name, receiver) {
|
|
5
6
|
if (name === 'clone') {
|
|
6
7
|
return structuredClone(target);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
if (name === 'fsPath') {
|
|
10
|
+
return ${stringifiedFSPath};
|
|
11
|
+
}
|
|
12
|
+
${!isSSR ? `globalThis.astroAsset.referencedImages.add(${stringifiedFSPath});` : ""}
|
|
9
13
|
return target[name];
|
|
10
14
|
}
|
|
11
15
|
})
|
|
@@ -15,7 +15,8 @@ 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;
|
|
18
|
-
const assetRegex = new RegExp(`\\.(${VALID_INPUT_FORMATS.join("|")})
|
|
18
|
+
const assetRegex = new RegExp(`\\.(${VALID_INPUT_FORMATS.join("|")})`, "i");
|
|
19
|
+
const assetRegexEnds = new RegExp(`\\.(${VALID_INPUT_FORMATS.join("|")})$`, "i");
|
|
19
20
|
function assets({
|
|
20
21
|
settings,
|
|
21
22
|
mode
|
|
@@ -67,12 +68,11 @@ function assets({
|
|
|
67
68
|
if (mode != "build") {
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
|
-
globalThis.astroAsset.addStaticImage = (options, hashProperties) => {
|
|
71
|
+
globalThis.astroAsset.addStaticImage = (options, hashProperties, originalPath) => {
|
|
71
72
|
if (!globalThis.astroAsset.staticImages) {
|
|
72
73
|
globalThis.astroAsset.staticImages = /* @__PURE__ */ new Map();
|
|
73
74
|
}
|
|
74
75
|
const finalOriginalImagePath = (isESMImportedImage(options.src) ? options.src.src : options.src).replace(settings.config.build.assetsPrefix || "", "");
|
|
75
|
-
const originalSrcPath = isESMImportedImage(options.src) ? options.src.fsPath : options.src;
|
|
76
76
|
const hash = hashTransform(
|
|
77
77
|
options,
|
|
78
78
|
settings.config.image.service.entrypoint,
|
|
@@ -89,7 +89,7 @@ function assets({
|
|
|
89
89
|
);
|
|
90
90
|
if (!transformsForPath) {
|
|
91
91
|
globalThis.astroAsset.staticImages.set(finalOriginalImagePath, {
|
|
92
|
-
originalSrcPath,
|
|
92
|
+
originalSrcPath: originalPath,
|
|
93
93
|
transforms: /* @__PURE__ */ new Map()
|
|
94
94
|
});
|
|
95
95
|
transformsForPath = globalThis.astroAsset.staticImages.get(finalOriginalImagePath);
|
|
@@ -137,24 +137,31 @@ function assets({
|
|
|
137
137
|
resolvedConfig = viteConfig;
|
|
138
138
|
},
|
|
139
139
|
async load(id, options) {
|
|
140
|
-
if (id !== removeQueryString(id)) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
140
|
if (assetRegex.test(id)) {
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
if (!globalThis.astroAsset.referencedImages)
|
|
142
|
+
globalThis.astroAsset.referencedImages = /* @__PURE__ */ new Set();
|
|
143
|
+
if (id !== removeQueryString(id)) {
|
|
144
|
+
globalThis.astroAsset.referencedImages.add(removeQueryString(id));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (!assetRegexEnds.test(id)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const imageMetadata = await emitESMImage(id, this.meta.watchMode, this.emitFile);
|
|
151
|
+
if (!imageMetadata) {
|
|
146
152
|
throw new AstroError({
|
|
147
153
|
...AstroErrorData.ImageNotFound,
|
|
148
154
|
message: AstroErrorData.ImageNotFound.message(id)
|
|
149
155
|
});
|
|
150
156
|
}
|
|
151
157
|
if (options?.ssr) {
|
|
152
|
-
return `export default ${getProxyCode(
|
|
158
|
+
return `export default ${getProxyCode(
|
|
159
|
+
imageMetadata,
|
|
160
|
+
isServerLikeOutput(settings.config)
|
|
161
|
+
)}`;
|
|
153
162
|
} else {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
globalThis.astroAsset.referencedImages.add(meta.fsPath);
|
|
157
|
-
return `export default ${JSON.stringify(meta)}`;
|
|
163
|
+
globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
|
|
164
|
+
return `export default ${JSON.stringify(imageMetadata)}`;
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
167
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PluginContext } from 'rollup';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
export declare function createImage(pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, z.ZodNever | {
|
|
4
|
-
ASTRO_ASSET:
|
|
4
|
+
ASTRO_ASSET: string;
|
|
5
5
|
src: string;
|
|
6
6
|
width: number;
|
|
7
7
|
height: number;
|
|
@@ -18,8 +18,6 @@ import {
|
|
|
18
18
|
getEntryType,
|
|
19
19
|
reloadContentConfigObserver
|
|
20
20
|
} from "./utils.js";
|
|
21
|
-
class UnsupportedFileTypeError extends Error {
|
|
22
|
-
}
|
|
23
21
|
async function createContentTypesGenerator({
|
|
24
22
|
contentConfigObserver,
|
|
25
23
|
fs,
|
|
@@ -98,20 +96,6 @@ async function createContentTypesGenerator({
|
|
|
98
96
|
await reloadContentConfigObserver({ fs, settings, viteServer });
|
|
99
97
|
return { shouldGenerateTypes: true };
|
|
100
98
|
}
|
|
101
|
-
if (fileType === "unsupported") {
|
|
102
|
-
if (event.name === "unlink") {
|
|
103
|
-
return { shouldGenerateTypes: false };
|
|
104
|
-
}
|
|
105
|
-
const { id: id2 } = getContentEntryIdAndSlug({
|
|
106
|
-
entry: event.entry,
|
|
107
|
-
contentDir: contentPaths.contentDir,
|
|
108
|
-
collection: ""
|
|
109
|
-
});
|
|
110
|
-
return {
|
|
111
|
-
shouldGenerateTypes: false,
|
|
112
|
-
error: new UnsupportedFileTypeError(id2)
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
99
|
const { entry } = event;
|
|
116
100
|
const { contentDir } = contentPaths;
|
|
117
101
|
const collection = getEntryCollectionName({ entry, contentDir });
|
|
@@ -251,16 +235,6 @@ async function createContentTypesGenerator({
|
|
|
251
235
|
eventResponses.push(response);
|
|
252
236
|
}
|
|
253
237
|
events = [];
|
|
254
|
-
for (const response of eventResponses) {
|
|
255
|
-
if (response.error instanceof UnsupportedFileTypeError) {
|
|
256
|
-
logger.warn(
|
|
257
|
-
"content",
|
|
258
|
-
`Unsupported file type ${bold(
|
|
259
|
-
response.error.message
|
|
260
|
-
)} found. Prefix filename with an underscore (\`_\`) to ignore.`
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
238
|
const observable = contentConfigObserver.get();
|
|
265
239
|
if (eventResponses.some((r) => r.shouldGenerateTypes)) {
|
|
266
240
|
await writeContentFiles({
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export declare function getContentEntryIdAndSlug({ entry, contentDir, collection
|
|
|
117
117
|
id: string;
|
|
118
118
|
slug: string;
|
|
119
119
|
};
|
|
120
|
-
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], dataFileExts: string[]): 'content' | 'data' | 'config' | 'ignored'
|
|
120
|
+
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], dataFileExts: string[]): 'content' | 'data' | 'config' | 'ignored';
|
|
121
121
|
export declare function hasUnderscoreBelowContentDirectoryPath(fileUrl: URL, contentDir: ContentPaths['contentDir']): boolean;
|
|
122
122
|
export declare function parseFrontmatter(fileContents: string): matter.GrayMatterFile<string>;
|
|
123
123
|
/**
|
package/dist/content/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ import path from "node:path";
|
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
-
import { VALID_INPUT_FORMATS } from "../assets/consts.js";
|
|
9
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
10
9
|
import { formatYAMLException, isYAMLException } from "../core/errors/utils.js";
|
|
11
10
|
import { CONTENT_FLAGS, CONTENT_TYPES_FILE } from "./consts.js";
|
|
@@ -163,9 +162,9 @@ function getRelativeEntryPath(entry, collection, contentDir) {
|
|
|
163
162
|
return relativeToCollection;
|
|
164
163
|
}
|
|
165
164
|
function getEntryType(entryPath, paths, contentFileExts, dataFileExts) {
|
|
166
|
-
const { ext
|
|
165
|
+
const { ext } = path.parse(entryPath);
|
|
167
166
|
const fileUrl = pathToFileURL(entryPath);
|
|
168
|
-
if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir)
|
|
167
|
+
if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir)) {
|
|
169
168
|
return "ignored";
|
|
170
169
|
} else if (contentFileExts.includes(ext)) {
|
|
171
170
|
return "content";
|
|
@@ -174,15 +173,9 @@ function getEntryType(entryPath, paths, contentFileExts, dataFileExts) {
|
|
|
174
173
|
} else if (fileUrl.href === paths.config.url.href) {
|
|
175
174
|
return "config";
|
|
176
175
|
} else {
|
|
177
|
-
return "
|
|
176
|
+
return "ignored";
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
|
-
function isOnIgnoreList(fileName) {
|
|
181
|
-
return [".DS_Store"].includes(fileName);
|
|
182
|
-
}
|
|
183
|
-
function isImageAsset(fileExt) {
|
|
184
|
-
return VALID_INPUT_FORMATS.includes(fileExt.slice(1));
|
|
185
|
-
}
|
|
186
179
|
function hasUnderscoreBelowContentDirectoryPath(fileUrl, contentDir) {
|
|
187
180
|
const parts = fileUrl.pathname.replace(contentDir.pathname, "").split("/");
|
|
188
181
|
for (const part of parts) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OutgoingHttpHeaders } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* Takes in a nullable WebAPI Headers object and produces a NodeJS OutgoingHttpHeaders object suitable for usage
|
|
4
|
+
* with ServerResponse.writeHead(..) or ServerResponse.setHeader(..)
|
|
5
|
+
*
|
|
6
|
+
* @param headers WebAPI Headers object
|
|
7
|
+
* @returns {OutgoingHttpHeaders} NodeJS OutgoingHttpHeaders object with multiple set-cookie handled as an array of values
|
|
8
|
+
*/
|
|
9
|
+
export declare const createOutgoingHttpHeaders: (headers: Headers | undefined | null) => OutgoingHttpHeaders | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const createOutgoingHttpHeaders = (headers) => {
|
|
2
|
+
if (!headers) {
|
|
3
|
+
return void 0;
|
|
4
|
+
}
|
|
5
|
+
const nodeHeaders = Object.fromEntries(headers.entries());
|
|
6
|
+
if (Object.keys(nodeHeaders).length === 0) {
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
if (headers.has("set-cookie")) {
|
|
10
|
+
const cookieHeaders = headers.getSetCookie();
|
|
11
|
+
if (cookieHeaders.length > 1) {
|
|
12
|
+
nodeHeaders["set-cookie"] = cookieHeaders;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return nodeHeaders;
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
createOutgoingHttpHeaders
|
|
19
|
+
};
|
package/dist/core/app/index.d.ts
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import type { ManifestData, RouteData, SSRManifest } from '../../@types/astro.js';
|
|
2
|
+
import { getSetCookiesFromResponse } from '../cookies/index.js';
|
|
2
3
|
import { AstroIntegrationLogger } from '../logger/core.js';
|
|
3
4
|
export { deserializeManifest } from './common.js';
|
|
4
5
|
export interface RenderOptions {
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Whether to automatically add all cookies written by `Astro.cookie.set()` to the response headers.
|
|
8
|
+
*
|
|
9
|
+
* When set to `true`, they will be added to the `Set-Cookie` header as comma-separated key=value pairs. You can use the standard `response.headers.getSetCookie()` API to read them individually.
|
|
10
|
+
*
|
|
11
|
+
* When set to `false`, the cookies will only be available from `App.getSetCookieFromResponse(response)`.
|
|
12
|
+
*
|
|
13
|
+
* @default {false}
|
|
14
|
+
*/
|
|
15
|
+
addCookieHeader?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The client IP address that will be made available as `Astro.clientAddress` in pages, and as `ctx.clientAddress` in API routes and middleware.
|
|
18
|
+
*
|
|
19
|
+
* Default: `request[Symbol.for("astro.clientAddress")]`
|
|
20
|
+
*/
|
|
21
|
+
clientAddress?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The mutable object that will be made available as `Astro.locals` in pages, and as `ctx.locals` in API routes and middleware.
|
|
24
|
+
*/
|
|
6
25
|
locals?: object;
|
|
26
|
+
/**
|
|
27
|
+
* **Advanced API**: you probably do not need to use this.
|
|
28
|
+
*
|
|
29
|
+
* Default: `app.match(request)`
|
|
30
|
+
*/
|
|
31
|
+
routeData?: RouteData;
|
|
7
32
|
}
|
|
8
33
|
export interface RenderErrorOptions {
|
|
9
34
|
routeData?: RouteData;
|
|
@@ -28,4 +53,16 @@ export declare class App {
|
|
|
28
53
|
*/
|
|
29
54
|
render(request: Request, routeData?: RouteData, locals?: object): Promise<Response>;
|
|
30
55
|
setCookieHeaders(response: Response): Generator<string, string[], unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Reads all the cookies written by `Astro.cookie.set()` onto the passed response.
|
|
58
|
+
* For example,
|
|
59
|
+
* ```ts
|
|
60
|
+
* for (const cookie_ of App.getSetCookieFromResponse(response)) {
|
|
61
|
+
* const cookie: string = cookie_
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
* @param response The response to read cookies from.
|
|
65
|
+
* @returns An iterator that yields key-value pairs as equal-sign-separated strings.
|
|
66
|
+
*/
|
|
67
|
+
static getSetCookieFromResponse: typeof getSetCookiesFromResponse;
|
|
31
68
|
}
|