astro 2.4.5 → 2.5.1
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/astro-jsx.d.ts +5 -1
- package/dist/@types/astro.d.ts +130 -6
- package/dist/assets/generate.d.ts +22 -0
- package/dist/assets/generate.js +90 -0
- package/dist/assets/internal.d.ts +0 -21
- package/dist/assets/internal.js +0 -86
- package/dist/assets/vite-plugin-assets.js +5 -0
- package/dist/content/consts.d.ts +3 -1
- package/dist/content/consts.js +5 -1
- package/dist/content/runtime-assets.d.ts +1 -1
- package/dist/content/runtime.d.ts +61 -7
- package/dist/content/runtime.js +127 -4
- package/dist/content/template/virtual-mod.d.mts +4 -1
- package/dist/content/types-generator.js +172 -89
- package/dist/content/utils.d.ts +76 -23
- package/dist/content/utils.js +129 -65
- package/dist/content/vite-plugin-content-imports.js +110 -25
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +4 -3
- package/dist/content/vite-plugin-content-virtual-mod.js +89 -45
- package/dist/core/app/common.js +2 -0
- package/dist/core/app/index.js +8 -6
- package/dist/core/app/types.d.ts +9 -2
- package/dist/core/build/generate.js +11 -11
- package/dist/core/build/graph.js +1 -1
- package/dist/core/build/index.d.ts +1 -1
- package/dist/core/build/plugins/index.js +2 -0
- package/dist/core/build/plugins/plugin-middleware.d.ts +8 -0
- package/dist/core/build/plugins/plugin-middleware.js +53 -0
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -2
- package/dist/core/build/plugins/plugin-pages.js +9 -14
- package/dist/core/build/plugins/plugin-prerender.d.ts +0 -2
- package/dist/core/build/plugins/plugin-prerender.js +4 -3
- package/dist/core/build/plugins/plugin-ssr.d.ts +1 -4
- package/dist/core/build/plugins/plugin-ssr.js +15 -22
- package/dist/core/build/static-build.js +12 -7
- package/dist/core/build/types.d.ts +3 -1
- package/dist/core/client-directive/build.d.ts +4 -0
- package/dist/core/client-directive/build.js +28 -0
- package/dist/core/client-directive/default.d.ts +1 -0
- package/dist/core/client-directive/default.js +17 -0
- package/dist/core/client-directive/index.d.ts +2 -0
- package/dist/core/client-directive/index.js +6 -0
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +6 -0
- package/dist/core/config/schema.d.ts +68 -12
- package/dist/core/config/schema.js +29 -3
- package/dist/core/config/settings.js +74 -2
- package/dist/core/config/vite-load.js +2 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/endpoint/index.d.ts +1 -1
- package/dist/core/endpoint/index.js +16 -16
- package/dist/core/errors/errors-data.d.ts +55 -4
- package/dist/core/errors/errors-data.js +67 -7
- package/dist/core/errors/errors.d.ts +1 -0
- package/dist/core/errors/errors.js +5 -1
- package/dist/core/errors/index.d.ts +1 -1
- package/dist/core/errors/index.js +9 -1
- package/dist/core/errors/utils.d.ts +5 -0
- package/dist/core/errors/utils.js +14 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +2 -1
- package/dist/core/middleware/callMiddleware.js +13 -3
- package/dist/core/render/core.js +1 -0
- package/dist/core/render/dev/environment.js +3 -1
- package/dist/core/render/dev/index.js +1 -1
- package/dist/core/render/environment.d.ts +1 -0
- package/dist/core/render/environment.js +2 -0
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +3 -2
- package/dist/core/routing/manifest/create.js +9 -2
- package/dist/core/routing/validation.js +6 -1
- package/dist/core/sync/index.js +11 -1
- package/dist/core/util.js +2 -1
- package/dist/integrations/index.js +29 -3
- package/dist/jsx/babel.js +1 -2
- package/dist/prerender/utils.d.ts +3 -0
- package/dist/prerender/utils.js +10 -0
- package/dist/runtime/client/idle.d.ts +3 -0
- package/dist/runtime/client/idle.js +6 -3
- package/dist/runtime/client/idle.prebuilt.d.ts +1 -1
- package/dist/runtime/client/idle.prebuilt.js +1 -1
- package/dist/runtime/client/load.d.ts +3 -0
- package/dist/runtime/client/load.js +7 -6
- package/dist/runtime/client/load.prebuilt.d.ts +1 -1
- package/dist/runtime/client/load.prebuilt.js +1 -1
- package/dist/runtime/client/media.d.ts +6 -0
- package/dist/runtime/client/media.js +6 -3
- package/dist/runtime/client/media.prebuilt.d.ts +1 -1
- package/dist/runtime/client/media.prebuilt.js +1 -1
- package/dist/runtime/client/only.d.ts +6 -0
- package/dist/runtime/client/only.js +7 -6
- package/dist/runtime/client/only.prebuilt.d.ts +1 -1
- package/dist/runtime/client/only.prebuilt.js +1 -1
- package/dist/runtime/client/visible.d.ts +8 -0
- package/dist/runtime/client/visible.js +9 -6
- package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
- package/dist/runtime/client/visible.prebuilt.js +1 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.js +1 -1
- package/dist/runtime/server/hydration.d.ts +1 -2
- package/dist/runtime/server/hydration.js +4 -9
- package/dist/runtime/server/render/astro/instance.js +1 -2
- package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
- package/dist/runtime/server/render/astro/render-template.js +10 -2
- package/dist/runtime/server/render/common.js +1 -1
- package/dist/runtime/server/render/component.js +20 -6
- package/dist/runtime/server/render/page.js +5 -0
- package/dist/runtime/server/render/util.d.ts +12 -0
- package/dist/runtime/server/render/util.js +89 -1
- package/dist/runtime/server/scripts.d.ts +1 -2
- package/dist/runtime/server/scripts.js +13 -21
- package/dist/vite-plugin-astro-server/request.js +2 -1
- package/dist/vite-plugin-astro-server/route.js +4 -3
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-scanner/index.js +6 -1
- package/dist/vite-plugin-scanner/scan.d.ts +1 -1
- package/dist/vite-plugin-scanner/scan.js +2 -2
- package/package.json +5 -3
- package/src/content/template/types.d.ts +108 -15
- package/src/content/template/virtual-mod.mjs +40 -16
- package/types.d.ts +6 -3
package/astro-jsx.d.ts
CHANGED
|
@@ -18,12 +18,16 @@ declare namespace astroHTML.JSX {
|
|
|
18
18
|
children: {};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
interface IntrinsicAttributes
|
|
21
|
+
interface IntrinsicAttributes
|
|
22
|
+
extends AstroBuiltinProps,
|
|
23
|
+
AstroBuiltinAttributes,
|
|
24
|
+
AstroClientDirectives {
|
|
22
25
|
slot?: string;
|
|
23
26
|
children?: Children;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
type AstroBuiltinProps = import('./dist/@types/astro.js').AstroBuiltinProps;
|
|
30
|
+
type AstroClientDirectives = import('./dist/@types/astro.js').AstroClientDirectives;
|
|
27
31
|
type AstroBuiltinAttributes = import('./dist/@types/astro.js').AstroBuiltinAttributes;
|
|
28
32
|
type AstroDefineVarsAttribute = import('./dist/@types/astro.js').AstroDefineVarsAttribute;
|
|
29
33
|
type AstroScriptAttributes = import('./dist/@types/astro.js').AstroScriptAttributes &
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface AstroBuiltinProps {
|
|
|
29
29
|
'client:visible'?: boolean;
|
|
30
30
|
'client:only'?: boolean | string;
|
|
31
31
|
}
|
|
32
|
+
export interface AstroClientDirectives {
|
|
33
|
+
}
|
|
32
34
|
export interface AstroBuiltinAttributes {
|
|
33
35
|
'class:list'?: Record<string, boolean> | Record<any, any> | Iterable<string> | Iterable<any> | string;
|
|
34
36
|
'set:html'?: any;
|
|
@@ -58,6 +60,7 @@ export interface AstroComponentMetadata {
|
|
|
58
60
|
value: string;
|
|
59
61
|
namespace?: boolean;
|
|
60
62
|
};
|
|
63
|
+
astroStaticSlot: true;
|
|
61
64
|
}
|
|
62
65
|
/** The flags supported by the Astro CLI */
|
|
63
66
|
export interface CLIFlags {
|
|
@@ -407,6 +410,22 @@ export interface AstroUserConfig {
|
|
|
407
410
|
* ```
|
|
408
411
|
*/
|
|
409
412
|
site?: string;
|
|
413
|
+
/**
|
|
414
|
+
* @docs
|
|
415
|
+
* @name compressHTML
|
|
416
|
+
* @type {boolean}
|
|
417
|
+
* @default `false`
|
|
418
|
+
* @description
|
|
419
|
+
* This is an option to minify your HTML output and reduce the size of your HTML files. When enabled, Astro removes all whitespace from your HTML, including line breaks, from `.astro` components. This occurs both in development mode and in the final build.
|
|
420
|
+
* To enable this, set the `compressHTML` flag to `true`.
|
|
421
|
+
*
|
|
422
|
+
* ```js
|
|
423
|
+
* {
|
|
424
|
+
* compressHTML: true
|
|
425
|
+
* }
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
compressHTML?: boolean;
|
|
410
429
|
/**
|
|
411
430
|
* @docs
|
|
412
431
|
* @name base
|
|
@@ -494,7 +513,7 @@ export interface AstroUserConfig {
|
|
|
494
513
|
/**
|
|
495
514
|
* @docs
|
|
496
515
|
* @name output
|
|
497
|
-
* @type {('static' | 'server')}
|
|
516
|
+
* @type {('static' | 'server' | 'hybrid')}
|
|
498
517
|
* @default `'static'`
|
|
499
518
|
* @see adapter
|
|
500
519
|
* @description
|
|
@@ -503,6 +522,7 @@ export interface AstroUserConfig {
|
|
|
503
522
|
*
|
|
504
523
|
* - 'static' - Building a static site to be deploy to any static host.
|
|
505
524
|
* - 'server' - Building an app to be deployed to a host supporting SSR (server-side rendering).
|
|
525
|
+
* - 'hybrid' - Building a static site with a few server-side rendered pages.
|
|
506
526
|
*
|
|
507
527
|
* ```js
|
|
508
528
|
* import { defineConfig } from 'astro/config';
|
|
@@ -512,7 +532,7 @@ export interface AstroUserConfig {
|
|
|
512
532
|
* })
|
|
513
533
|
* ```
|
|
514
534
|
*/
|
|
515
|
-
output?: 'static' | 'server';
|
|
535
|
+
output?: 'static' | 'server' | 'hybrid';
|
|
516
536
|
/**
|
|
517
537
|
* @docs
|
|
518
538
|
* @kind heading
|
|
@@ -552,14 +572,14 @@ export interface AstroUserConfig {
|
|
|
552
572
|
* @type {string}
|
|
553
573
|
* @default `'./dist/client'`
|
|
554
574
|
* @description
|
|
555
|
-
* Controls the output directory of your client-side CSS and JavaScript when `output: 'server'` only.
|
|
575
|
+
* Controls the output directory of your client-side CSS and JavaScript when `output: 'server'` or `output: 'hybrid'` only.
|
|
556
576
|
* `outDir` controls where the code is built to.
|
|
557
577
|
*
|
|
558
578
|
* This value is relative to the `outDir`.
|
|
559
579
|
*
|
|
560
580
|
* ```js
|
|
561
581
|
* {
|
|
562
|
-
* output: 'server',
|
|
582
|
+
* output: 'server', // or 'hybrid'
|
|
563
583
|
* build: {
|
|
564
584
|
* client: './client'
|
|
565
585
|
* }
|
|
@@ -984,6 +1004,7 @@ export interface AstroUserConfig {
|
|
|
984
1004
|
* @name experimental.inlineStylesheets
|
|
985
1005
|
* @type {('always' | 'auto' | 'never')}
|
|
986
1006
|
* @default `never`
|
|
1007
|
+
* @version 2.4.0
|
|
987
1008
|
* @description
|
|
988
1009
|
* Control whether styles are sent to the browser in a separate css file or inlined into `<style>` tags. Choose from the following options:
|
|
989
1010
|
* - `'always'` - all styles are inlined into `<style>` tags
|
|
@@ -999,6 +1020,27 @@ export interface AstroUserConfig {
|
|
|
999
1020
|
* ```
|
|
1000
1021
|
*/
|
|
1001
1022
|
inlineStylesheets?: 'always' | 'auto' | 'never';
|
|
1023
|
+
/**
|
|
1024
|
+
* @docs
|
|
1025
|
+
* @name experimental.customClientDirectives
|
|
1026
|
+
* @type {boolean}
|
|
1027
|
+
* @default `false`
|
|
1028
|
+
* @version 2.5.0
|
|
1029
|
+
* @description
|
|
1030
|
+
* Allow integrations to use the [experimental `addClientDirective` API](/en/reference/integrations-reference/#addclientdirective-option) in the `astro:config:setup` hook
|
|
1031
|
+
* to add custom client directives in Astro files.
|
|
1032
|
+
*
|
|
1033
|
+
* To enable this feature, set `experimental.customClientDirectives` to `true` in your Astro config:
|
|
1034
|
+
*
|
|
1035
|
+
* ```js
|
|
1036
|
+
* {
|
|
1037
|
+
* experimental: {
|
|
1038
|
+
* customClientDirectives: true,
|
|
1039
|
+
* },
|
|
1040
|
+
* }
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
customClientDirectives?: boolean;
|
|
1002
1044
|
/**
|
|
1003
1045
|
* @docs
|
|
1004
1046
|
* @name experimental.middleware
|
|
@@ -1019,6 +1061,43 @@ export interface AstroUserConfig {
|
|
|
1019
1061
|
* ```
|
|
1020
1062
|
*/
|
|
1021
1063
|
middleware?: boolean;
|
|
1064
|
+
/**
|
|
1065
|
+
* @docs
|
|
1066
|
+
* @name experimental.hybridOutput
|
|
1067
|
+
* @type {boolean}
|
|
1068
|
+
* @default `false`
|
|
1069
|
+
* @version 2.5.0
|
|
1070
|
+
* @description
|
|
1071
|
+
* Enable experimental support for hybrid SSR with pre-rendering enabled by default.
|
|
1072
|
+
*
|
|
1073
|
+
* To enable this feature, first set `experimental.hybridOutput` to `true` in your Astro config, and set `output` to `hybrid`.
|
|
1074
|
+
*
|
|
1075
|
+
* ```js
|
|
1076
|
+
* {
|
|
1077
|
+
* output: 'hybrid',
|
|
1078
|
+
* experimental: {
|
|
1079
|
+
* hybridOutput: true,
|
|
1080
|
+
* },
|
|
1081
|
+
* }
|
|
1082
|
+
* ```
|
|
1083
|
+
* Then add `export const prerender = false` to any page or endpoint you want to opt-out of pre-rendering.
|
|
1084
|
+
* ```astro
|
|
1085
|
+
* ---
|
|
1086
|
+
* // pages/contact.astro
|
|
1087
|
+
* export const prerender = false
|
|
1088
|
+
*
|
|
1089
|
+
* if (Astro.request.method === 'POST') {
|
|
1090
|
+
* // handle form submission
|
|
1091
|
+
* }
|
|
1092
|
+
* ---
|
|
1093
|
+
* <form method="POST">
|
|
1094
|
+
* <input type="text" name="name" />
|
|
1095
|
+
* <input type="email" name="email" />
|
|
1096
|
+
* <button type="submit">Submit</button>
|
|
1097
|
+
* </form>
|
|
1098
|
+
* ```
|
|
1099
|
+
*/
|
|
1100
|
+
hybridOutput?: boolean;
|
|
1022
1101
|
};
|
|
1023
1102
|
/** @deprecated - Use "integrations" instead. Run Astro to learn more about migrating. */
|
|
1024
1103
|
renderers?: never;
|
|
@@ -1071,19 +1150,28 @@ export type ContentEntryModule = {
|
|
|
1071
1150
|
filePath: string;
|
|
1072
1151
|
};
|
|
1073
1152
|
};
|
|
1153
|
+
export type DataEntryModule = {
|
|
1154
|
+
id: string;
|
|
1155
|
+
collection: string;
|
|
1156
|
+
data: Record<string, unknown>;
|
|
1157
|
+
_internal: {
|
|
1158
|
+
rawData: string;
|
|
1159
|
+
filePath: string;
|
|
1160
|
+
};
|
|
1161
|
+
};
|
|
1074
1162
|
export interface ContentEntryType {
|
|
1075
1163
|
extensions: string[];
|
|
1076
1164
|
getEntryInfo(params: {
|
|
1077
1165
|
fileUrl: URL;
|
|
1078
1166
|
contents: string;
|
|
1079
|
-
}):
|
|
1167
|
+
}): GetContentEntryInfoReturnType | Promise<GetContentEntryInfoReturnType>;
|
|
1080
1168
|
getRenderModule?(this: rollup.PluginContext, params: {
|
|
1081
1169
|
viteId: string;
|
|
1082
1170
|
entry: ContentEntryModule;
|
|
1083
1171
|
}): rollup.LoadResult | Promise<rollup.LoadResult>;
|
|
1084
1172
|
contentModuleTypes?: string;
|
|
1085
1173
|
}
|
|
1086
|
-
type
|
|
1174
|
+
type GetContentEntryInfoReturnType = {
|
|
1087
1175
|
data: Record<string, unknown>;
|
|
1088
1176
|
/**
|
|
1089
1177
|
* Used for error hints to point to correct line and location
|
|
@@ -1094,17 +1182,33 @@ type GetEntryInfoReturnType = {
|
|
|
1094
1182
|
body: string;
|
|
1095
1183
|
slug: string;
|
|
1096
1184
|
};
|
|
1185
|
+
export interface DataEntryType {
|
|
1186
|
+
extensions: string[];
|
|
1187
|
+
getEntryInfo(params: {
|
|
1188
|
+
fileUrl: URL;
|
|
1189
|
+
contents: string;
|
|
1190
|
+
}): GetDataEntryInfoReturnType | Promise<GetDataEntryInfoReturnType>;
|
|
1191
|
+
}
|
|
1192
|
+
export type GetDataEntryInfoReturnType = {
|
|
1193
|
+
data: Record<string, unknown>;
|
|
1194
|
+
rawData?: string;
|
|
1195
|
+
};
|
|
1097
1196
|
export interface AstroSettings {
|
|
1098
1197
|
config: AstroConfig;
|
|
1099
1198
|
adapter: AstroAdapter | undefined;
|
|
1100
1199
|
injectedRoutes: InjectedRoute[];
|
|
1101
1200
|
pageExtensions: string[];
|
|
1102
1201
|
contentEntryTypes: ContentEntryType[];
|
|
1202
|
+
dataEntryTypes: DataEntryType[];
|
|
1103
1203
|
renderers: AstroRenderer[];
|
|
1104
1204
|
scripts: {
|
|
1105
1205
|
stage: InjectedScriptStage;
|
|
1106
1206
|
content: string;
|
|
1107
1207
|
}[];
|
|
1208
|
+
/**
|
|
1209
|
+
* Map of directive name (e.g. `load`) to the directive script code
|
|
1210
|
+
*/
|
|
1211
|
+
clientDirectives: Map<string, string>;
|
|
1108
1212
|
tsConfig: TsConfigJson | undefined;
|
|
1109
1213
|
tsConfigPath: string | undefined;
|
|
1110
1214
|
watchFiles: string[];
|
|
@@ -1466,6 +1570,7 @@ export interface SSRLoadedRenderer extends AstroRenderer {
|
|
|
1466
1570
|
html: string;
|
|
1467
1571
|
attrs?: Record<string, string>;
|
|
1468
1572
|
}>;
|
|
1573
|
+
supportsAstroStaticSlot?: boolean;
|
|
1469
1574
|
};
|
|
1470
1575
|
}
|
|
1471
1576
|
export type HookParameters<Hook extends keyof AstroIntegration['hooks'], Fn = AstroIntegration['hooks'][Hook]> = Fn extends (...args: any) => any ? Parameters<Fn>[0] : never;
|
|
@@ -1483,6 +1588,7 @@ export interface AstroIntegration {
|
|
|
1483
1588
|
addWatchFile: (path: URL | string) => void;
|
|
1484
1589
|
injectScript: (stage: InjectedScriptStage, content: string) => void;
|
|
1485
1590
|
injectRoute: (injectRoute: InjectedRoute) => void;
|
|
1591
|
+
addClientDirective: (directive: ClientDirectiveConfig) => void;
|
|
1486
1592
|
}) => void | Promise<void>;
|
|
1487
1593
|
'astro:config:done'?: (options: {
|
|
1488
1594
|
config: AstroConfig;
|
|
@@ -1567,6 +1673,7 @@ export interface SSRMetadata {
|
|
|
1567
1673
|
hasDirectives: Set<string>;
|
|
1568
1674
|
hasRenderedHead: boolean;
|
|
1569
1675
|
headInTree: boolean;
|
|
1676
|
+
clientDirectives: Map<string, string>;
|
|
1570
1677
|
}
|
|
1571
1678
|
/**
|
|
1572
1679
|
* A hint on whether the Astro runtime needs to wait on a component to render head
|
|
@@ -1615,3 +1722,20 @@ export type CreatePreviewServer = (params: PreviewServerParams) => PreviewServer
|
|
|
1615
1722
|
export interface PreviewModule {
|
|
1616
1723
|
default: CreatePreviewServer;
|
|
1617
1724
|
}
|
|
1725
|
+
type DirectiveHydrate = () => Promise<void>;
|
|
1726
|
+
type DirectiveLoad = () => Promise<DirectiveHydrate>;
|
|
1727
|
+
type DirectiveOptions = {
|
|
1728
|
+
/**
|
|
1729
|
+
* The component displayName
|
|
1730
|
+
*/
|
|
1731
|
+
name: string;
|
|
1732
|
+
/**
|
|
1733
|
+
* The attribute value provided
|
|
1734
|
+
*/
|
|
1735
|
+
value: string;
|
|
1736
|
+
};
|
|
1737
|
+
export type ClientDirective = (load: DirectiveLoad, options: DirectiveOptions, el: HTMLElement) => void;
|
|
1738
|
+
export interface ClientDirectiveConfig {
|
|
1739
|
+
name: string;
|
|
1740
|
+
entrypoint: string;
|
|
1741
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StaticBuildOptions } from '../core/build/types.js';
|
|
2
|
+
import type { ImageTransform } from './types.js';
|
|
3
|
+
interface GenerationDataUncached {
|
|
4
|
+
cached: false;
|
|
5
|
+
weight: {
|
|
6
|
+
before: number;
|
|
7
|
+
after: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface GenerationDataCached {
|
|
11
|
+
cached: true;
|
|
12
|
+
}
|
|
13
|
+
type GenerationData = GenerationDataUncached | GenerationDataCached;
|
|
14
|
+
export declare function generateImage(buildOpts: StaticBuildOptions, options: ImageTransform, filepath: string): Promise<GenerationData | undefined>;
|
|
15
|
+
export declare function getStaticImageList(): Iterable<[
|
|
16
|
+
string,
|
|
17
|
+
{
|
|
18
|
+
path: string;
|
|
19
|
+
options: ImageTransform;
|
|
20
|
+
}
|
|
21
|
+
]>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path/posix";
|
|
3
|
+
import { warn } from "../core/logger/core.js";
|
|
4
|
+
import { prependForwardSlash } from "../core/path.js";
|
|
5
|
+
import { isHybridOutput } from "../prerender/utils.js";
|
|
6
|
+
import { getConfiguredImageService, isESMImportedImage } from "./internal.js";
|
|
7
|
+
async function generateImage(buildOpts, options, filepath) {
|
|
8
|
+
if (!isESMImportedImage(options.src)) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
let useCache = true;
|
|
12
|
+
const assetsCacheDir = new URL("assets/", buildOpts.settings.config.cacheDir);
|
|
13
|
+
try {
|
|
14
|
+
await fs.promises.mkdir(assetsCacheDir, { recursive: true });
|
|
15
|
+
} catch (err) {
|
|
16
|
+
warn(
|
|
17
|
+
buildOpts.logging,
|
|
18
|
+
"astro:assets",
|
|
19
|
+
`An error was encountered while creating the cache directory. Proceeding without caching. Error: ${err}`
|
|
20
|
+
);
|
|
21
|
+
useCache = false;
|
|
22
|
+
}
|
|
23
|
+
let serverRoot, clientRoot;
|
|
24
|
+
if (buildOpts.settings.config.output === "server" || isHybridOutput(buildOpts.settings.config)) {
|
|
25
|
+
serverRoot = buildOpts.settings.config.build.server;
|
|
26
|
+
clientRoot = buildOpts.settings.config.build.client;
|
|
27
|
+
} else {
|
|
28
|
+
serverRoot = buildOpts.settings.config.outDir;
|
|
29
|
+
clientRoot = buildOpts.settings.config.outDir;
|
|
30
|
+
}
|
|
31
|
+
const finalFileURL = new URL("." + filepath, clientRoot);
|
|
32
|
+
const finalFolderURL = new URL("./", finalFileURL);
|
|
33
|
+
const cachedFileURL = new URL(basename(filepath), assetsCacheDir);
|
|
34
|
+
try {
|
|
35
|
+
await fs.promises.copyFile(cachedFileURL, finalFileURL);
|
|
36
|
+
return {
|
|
37
|
+
cached: true
|
|
38
|
+
};
|
|
39
|
+
} catch (e) {
|
|
40
|
+
}
|
|
41
|
+
const originalImagePath = options.src.src;
|
|
42
|
+
const fileData = await fs.promises.readFile(
|
|
43
|
+
new URL(
|
|
44
|
+
"." + prependForwardSlash(
|
|
45
|
+
join(buildOpts.settings.config.build.assets, basename(originalImagePath))
|
|
46
|
+
),
|
|
47
|
+
serverRoot
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
const imageService = await getConfiguredImageService();
|
|
51
|
+
const resultData = await imageService.transform(
|
|
52
|
+
fileData,
|
|
53
|
+
{ ...options, src: originalImagePath },
|
|
54
|
+
buildOpts.settings.config.image.service.config
|
|
55
|
+
);
|
|
56
|
+
await fs.promises.mkdir(finalFolderURL, { recursive: true });
|
|
57
|
+
if (useCache) {
|
|
58
|
+
try {
|
|
59
|
+
await fs.promises.writeFile(cachedFileURL, resultData.data);
|
|
60
|
+
await fs.promises.copyFile(cachedFileURL, finalFileURL);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
warn(
|
|
63
|
+
buildOpts.logging,
|
|
64
|
+
"astro:assets",
|
|
65
|
+
`An error was encountered while creating the cache directory. Proceeding without caching. Error: ${e}`
|
|
66
|
+
);
|
|
67
|
+
await fs.promises.writeFile(finalFileURL, resultData.data);
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
await fs.promises.writeFile(finalFileURL, resultData.data);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
cached: false,
|
|
74
|
+
weight: {
|
|
75
|
+
before: Math.trunc(fileData.byteLength / 1024),
|
|
76
|
+
after: Math.trunc(resultData.data.byteLength / 1024)
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function getStaticImageList() {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (!((_a = globalThis == null ? void 0 : globalThis.astroAsset) == null ? void 0 : _a.staticImages)) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
return (_b = globalThis.astroAsset.staticImages) == null ? void 0 : _b.entries();
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
generateImage,
|
|
89
|
+
getStaticImageList
|
|
90
|
+
};
|
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
import type { StaticBuildOptions } from '../core/build/types.js';
|
|
2
1
|
import { type ImageService } from './services/service.js';
|
|
3
2
|
import type { GetImageResult, ImageMetadata, ImageTransform } from './types.js';
|
|
4
3
|
export declare function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata;
|
|
5
4
|
export declare function getConfiguredImageService(): Promise<ImageService>;
|
|
6
5
|
export declare function getImage(options: ImageTransform, serviceConfig: Record<string, any>): Promise<GetImageResult>;
|
|
7
|
-
export declare function getStaticImageList(): Iterable<[
|
|
8
|
-
string,
|
|
9
|
-
{
|
|
10
|
-
path: string;
|
|
11
|
-
options: ImageTransform;
|
|
12
|
-
}
|
|
13
|
-
]>;
|
|
14
|
-
interface GenerationDataUncached {
|
|
15
|
-
cached: false;
|
|
16
|
-
weight: {
|
|
17
|
-
before: number;
|
|
18
|
-
after: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
interface GenerationDataCached {
|
|
22
|
-
cached: true;
|
|
23
|
-
}
|
|
24
|
-
type GenerationData = GenerationDataUncached | GenerationDataCached;
|
|
25
|
-
export declare function generateImage(buildOpts: StaticBuildOptions, options: ImageTransform, filepath: string): Promise<GenerationData | undefined>;
|
|
26
|
-
export {};
|
package/dist/assets/internal.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { basename, join } from "node:path/posix";
|
|
3
1
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
4
|
-
import { warn } from "../core/logger/core.js";
|
|
5
|
-
import { prependForwardSlash } from "../core/path.js";
|
|
6
2
|
import { isLocalService } from "./services/service.js";
|
|
7
3
|
function isESMImportedImage(src) {
|
|
8
4
|
return typeof src === "object";
|
|
@@ -45,90 +41,8 @@ async function getImage(options, serviceConfig) {
|
|
|
45
41
|
attributes: service.getHTMLAttributes !== void 0 ? service.getHTMLAttributes(validatedOptions, serviceConfig) : {}
|
|
46
42
|
};
|
|
47
43
|
}
|
|
48
|
-
function getStaticImageList() {
|
|
49
|
-
var _a, _b;
|
|
50
|
-
if (!((_a = globalThis == null ? void 0 : globalThis.astroAsset) == null ? void 0 : _a.staticImages)) {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
return (_b = globalThis.astroAsset.staticImages) == null ? void 0 : _b.entries();
|
|
54
|
-
}
|
|
55
|
-
async function generateImage(buildOpts, options, filepath) {
|
|
56
|
-
if (!isESMImportedImage(options.src)) {
|
|
57
|
-
return void 0;
|
|
58
|
-
}
|
|
59
|
-
let useCache = true;
|
|
60
|
-
const assetsCacheDir = new URL("assets/", buildOpts.settings.config.cacheDir);
|
|
61
|
-
try {
|
|
62
|
-
await fs.promises.mkdir(assetsCacheDir, { recursive: true });
|
|
63
|
-
} catch (err) {
|
|
64
|
-
warn(
|
|
65
|
-
buildOpts.logging,
|
|
66
|
-
"astro:assets",
|
|
67
|
-
`An error was encountered while creating the cache directory. Proceeding without caching. Error: ${err}`
|
|
68
|
-
);
|
|
69
|
-
useCache = false;
|
|
70
|
-
}
|
|
71
|
-
let serverRoot, clientRoot;
|
|
72
|
-
if (buildOpts.settings.config.output === "server") {
|
|
73
|
-
serverRoot = buildOpts.settings.config.build.server;
|
|
74
|
-
clientRoot = buildOpts.settings.config.build.client;
|
|
75
|
-
} else {
|
|
76
|
-
serverRoot = buildOpts.settings.config.outDir;
|
|
77
|
-
clientRoot = buildOpts.settings.config.outDir;
|
|
78
|
-
}
|
|
79
|
-
const finalFileURL = new URL("." + filepath, clientRoot);
|
|
80
|
-
const finalFolderURL = new URL("./", finalFileURL);
|
|
81
|
-
const cachedFileURL = new URL(basename(filepath), assetsCacheDir);
|
|
82
|
-
try {
|
|
83
|
-
await fs.promises.copyFile(cachedFileURL, finalFileURL);
|
|
84
|
-
return {
|
|
85
|
-
cached: true
|
|
86
|
-
};
|
|
87
|
-
} catch (e) {
|
|
88
|
-
}
|
|
89
|
-
const originalImagePath = options.src.src;
|
|
90
|
-
const fileData = await fs.promises.readFile(
|
|
91
|
-
new URL(
|
|
92
|
-
"." + prependForwardSlash(
|
|
93
|
-
join(buildOpts.settings.config.build.assets, basename(originalImagePath))
|
|
94
|
-
),
|
|
95
|
-
serverRoot
|
|
96
|
-
)
|
|
97
|
-
);
|
|
98
|
-
const imageService = await getConfiguredImageService();
|
|
99
|
-
const resultData = await imageService.transform(
|
|
100
|
-
fileData,
|
|
101
|
-
{ ...options, src: originalImagePath },
|
|
102
|
-
buildOpts.settings.config.image.service.config
|
|
103
|
-
);
|
|
104
|
-
await fs.promises.mkdir(finalFolderURL, { recursive: true });
|
|
105
|
-
if (useCache) {
|
|
106
|
-
try {
|
|
107
|
-
await fs.promises.writeFile(cachedFileURL, resultData.data);
|
|
108
|
-
await fs.promises.copyFile(cachedFileURL, finalFileURL);
|
|
109
|
-
} catch (e) {
|
|
110
|
-
warn(
|
|
111
|
-
buildOpts.logging,
|
|
112
|
-
"astro:assets",
|
|
113
|
-
`An error was encountered while creating the cache directory. Proceeding without caching. Error: ${e}`
|
|
114
|
-
);
|
|
115
|
-
await fs.promises.writeFile(finalFileURL, resultData.data);
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
await fs.promises.writeFile(finalFileURL, resultData.data);
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
cached: false,
|
|
122
|
-
weight: {
|
|
123
|
-
before: Math.trunc(fileData.byteLength / 1024),
|
|
124
|
-
after: Math.trunc(resultData.data.byteLength / 1024)
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
44
|
export {
|
|
129
|
-
generateImage,
|
|
130
45
|
getConfiguredImageService,
|
|
131
46
|
getImage,
|
|
132
|
-
getStaticImageList,
|
|
133
47
|
isESMImportedImage
|
|
134
48
|
};
|
|
@@ -20,6 +20,8 @@ import { imageMetadata } from "./utils/metadata.js";
|
|
|
20
20
|
import { getOrigQueryParams } from "./utils/queryParams.js";
|
|
21
21
|
import { hashTransform, propsToFilename } from "./utils/transformToPath.js";
|
|
22
22
|
const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
|
|
23
|
+
const rawRE = /(?:\?|&)raw(?:&|$)/;
|
|
24
|
+
const urlRE = /(\?|&)url(?:&|$)/;
|
|
23
25
|
function assets({
|
|
24
26
|
settings,
|
|
25
27
|
logging,
|
|
@@ -189,6 +191,9 @@ function assets({
|
|
|
189
191
|
resolvedConfig = viteConfig;
|
|
190
192
|
},
|
|
191
193
|
async load(id) {
|
|
194
|
+
if (rawRE.test(id) || urlRE.test(id)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
192
197
|
const cleanedUrl = removeQueryString(id);
|
|
193
198
|
if (/\.(jpeg|jpg|png|tiff|webp|gif|svg)$/.test(cleanedUrl)) {
|
|
194
199
|
const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile, settings);
|
package/dist/content/consts.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
2
|
-
export declare const CONTENT_FLAG = "
|
|
2
|
+
export declare const CONTENT_FLAG = "astroContentCollectionEntry";
|
|
3
|
+
export declare const DATA_FLAG = "astroDataCollectionEntry";
|
|
4
|
+
export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroDataCollectionEntry", "astroPropagatedAssets"];
|
|
3
5
|
export declare const VIRTUAL_MODULE_ID = "astro:content";
|
|
4
6
|
export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
5
7
|
export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
package/dist/content/consts.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
2
|
-
const CONTENT_FLAG = "
|
|
2
|
+
const CONTENT_FLAG = "astroContentCollectionEntry";
|
|
3
|
+
const DATA_FLAG = "astroDataCollectionEntry";
|
|
4
|
+
const CONTENT_FLAGS = [CONTENT_FLAG, DATA_FLAG, PROPAGATED_ASSET_FLAG];
|
|
3
5
|
const VIRTUAL_MODULE_ID = "astro:content";
|
|
4
6
|
const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
5
7
|
const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
|
@@ -7,7 +9,9 @@ const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
|
|
|
7
9
|
const CONTENT_TYPES_FILE = "types.d.ts";
|
|
8
10
|
export {
|
|
9
11
|
CONTENT_FLAG,
|
|
12
|
+
CONTENT_FLAGS,
|
|
10
13
|
CONTENT_TYPES_FILE,
|
|
14
|
+
DATA_FLAG,
|
|
11
15
|
LINKS_PLACEHOLDER,
|
|
12
16
|
PROPAGATED_ASSET_FLAG,
|
|
13
17
|
SCRIPTS_PLACEHOLDER,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PluginContext } from 'rollup';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import type { AstroSettings } from '../@types/astro.js';
|
|
4
|
-
export declare function createImage(settings: AstroSettings, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
|
|
4
|
+
export declare function createImage(settings: Pick<AstroSettings, 'config'>, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
|
2
|
+
import { type AstroComponentFactory } from '../runtime/server/index.js';
|
|
3
|
+
import type { ContentLookupMap } from './utils.js';
|
|
1
4
|
type LazyImport = () => Promise<any>;
|
|
2
5
|
type GlobResult = Record<string, LazyImport>;
|
|
3
6
|
type CollectionToEntryMap = Record<string, GlobResult>;
|
|
@@ -6,8 +9,9 @@ export declare function createCollectionToGlobResultMap({ globResult, contentDir
|
|
|
6
9
|
globResult: GlobResult;
|
|
7
10
|
contentDir: string;
|
|
8
11
|
}): CollectionToEntryMap;
|
|
9
|
-
export declare function createGetCollection({
|
|
10
|
-
|
|
12
|
+
export declare function createGetCollection({ contentCollectionToEntryMap, dataCollectionToEntryMap, getRenderEntryImport, }: {
|
|
13
|
+
contentCollectionToEntryMap: CollectionToEntryMap;
|
|
14
|
+
dataCollectionToEntryMap: CollectionToEntryMap;
|
|
11
15
|
getRenderEntryImport: GetEntryImport;
|
|
12
16
|
}): (collection: string, filter?: ((entry: any) => unknown) | undefined) => Promise<any[]>;
|
|
13
17
|
export declare function createGetEntryBySlug({ getEntryImport, getRenderEntryImport, }: {
|
|
@@ -19,10 +23,60 @@ export declare function createGetEntryBySlug({ getEntryImport, getRenderEntryImp
|
|
|
19
23
|
body: any;
|
|
20
24
|
collection: any;
|
|
21
25
|
data: any;
|
|
22
|
-
render(): Promise<
|
|
23
|
-
Content: import("../runtime/server/index.js").AstroComponentFactory;
|
|
24
|
-
headings: any;
|
|
25
|
-
remarkPluginFrontmatter: any;
|
|
26
|
-
}>;
|
|
26
|
+
render(): Promise<RenderResult>;
|
|
27
27
|
} | undefined>;
|
|
28
|
+
export declare function createGetDataEntryById({ dataCollectionToEntryMap, }: {
|
|
29
|
+
dataCollectionToEntryMap: CollectionToEntryMap;
|
|
30
|
+
}): (collection: string, id: string) => Promise<{
|
|
31
|
+
id: any;
|
|
32
|
+
collection: any;
|
|
33
|
+
data: any;
|
|
34
|
+
}>;
|
|
35
|
+
type ContentEntryResult = {
|
|
36
|
+
id: string;
|
|
37
|
+
slug: string;
|
|
38
|
+
body: string;
|
|
39
|
+
collection: string;
|
|
40
|
+
data: Record<string, any>;
|
|
41
|
+
render(): Promise<RenderResult>;
|
|
42
|
+
};
|
|
43
|
+
type DataEntryResult = {
|
|
44
|
+
id: string;
|
|
45
|
+
collection: string;
|
|
46
|
+
data: Record<string, any>;
|
|
47
|
+
};
|
|
48
|
+
type EntryLookupObject = {
|
|
49
|
+
collection: string;
|
|
50
|
+
id: string;
|
|
51
|
+
} | {
|
|
52
|
+
collection: string;
|
|
53
|
+
slug: string;
|
|
54
|
+
};
|
|
55
|
+
export declare function createGetEntry({ getEntryImport, getRenderEntryImport, }: {
|
|
56
|
+
getEntryImport: GetEntryImport;
|
|
57
|
+
getRenderEntryImport: GetEntryImport;
|
|
58
|
+
}): (collectionOrLookupObject: string | EntryLookupObject, _lookupId?: string) => Promise<ContentEntryResult | DataEntryResult | undefined>;
|
|
59
|
+
export declare function createGetEntries(getEntry: ReturnType<typeof createGetEntry>): (entries: {
|
|
60
|
+
collection: string;
|
|
61
|
+
id: string;
|
|
62
|
+
}[] | {
|
|
63
|
+
collection: string;
|
|
64
|
+
slug: string;
|
|
65
|
+
}[]) => Promise<(ContentEntryResult | DataEntryResult | undefined)[]>;
|
|
66
|
+
type RenderResult = {
|
|
67
|
+
Content: AstroComponentFactory;
|
|
68
|
+
headings: MarkdownHeading[];
|
|
69
|
+
remarkPluginFrontmatter: Record<string, any>;
|
|
70
|
+
};
|
|
71
|
+
export declare function createReference({ lookupMap }: {
|
|
72
|
+
lookupMap: ContentLookupMap;
|
|
73
|
+
}): (collection: string) => import("zod").ZodEffects<import("zod").ZodString, {
|
|
74
|
+
slug: string;
|
|
75
|
+
collection: string;
|
|
76
|
+
id?: undefined;
|
|
77
|
+
} | {
|
|
78
|
+
id: string;
|
|
79
|
+
collection: string;
|
|
80
|
+
slug?: undefined;
|
|
81
|
+
} | undefined, string>;
|
|
28
82
|
export {};
|