astro 1.4.7 → 1.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 +8 -6
- package/components/Code.astro +1 -1
- package/config.d.ts +1 -1
- package/dist/@types/astro.d.ts +200 -19
- package/dist/cli/index.js +35 -36
- package/dist/config/index.js +2 -7
- package/dist/core/add/index.js +141 -24
- package/dist/core/app/index.js +45 -43
- package/dist/core/build/generate.js +14 -12
- package/dist/core/build/index.js +3 -3
- package/dist/core/config/config.d.ts +1 -1
- package/dist/core/config/config.js +6 -2
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.js +2 -1
- package/dist/core/config/schema.d.ts +139 -1
- package/dist/core/config/schema.js +36 -3
- package/dist/core/config/settings.d.ts +1 -7
- package/dist/core/config/settings.js +7 -4
- package/dist/core/config/tsconfig.d.ts +10 -1
- package/dist/core/config/tsconfig.js +72 -7
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +4 -0
- package/dist/core/cookies/cookies.d.ts +1 -1
- package/dist/core/dev/index.js +7 -2
- package/dist/core/endpoint/dev/index.d.ts +2 -1
- package/dist/core/endpoint/dev/index.js +13 -6
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +57 -9
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -11
- package/dist/core/preview/index.js +31 -125
- package/dist/core/preview/static-preview-server.d.ts +17 -0
- package/dist/core/preview/static-preview-server.js +127 -0
- package/dist/core/render/context.d.ts +20 -0
- package/dist/core/render/context.js +15 -0
- package/dist/core/render/core.d.ts +4 -24
- package/dist/core/render/core.js +26 -47
- package/dist/core/render/dev/environment.d.ts +9 -0
- package/dist/core/render/dev/environment.js +30 -0
- package/dist/core/render/dev/index.d.ts +22 -5
- package/dist/core/render/dev/index.js +38 -69
- package/dist/core/render/dev/resolve.d.ts +2 -0
- package/dist/core/render/dev/resolve.js +14 -0
- package/dist/core/render/environment.d.ts +29 -0
- package/dist/core/render/environment.js +21 -0
- package/dist/core/render/index.d.ts +6 -0
- package/dist/core/render/index.js +13 -0
- package/dist/core/render/renderer.d.ts +9 -0
- package/dist/core/render/renderer.js +23 -0
- package/dist/core/render/result.js +3 -3
- package/dist/core/routing/manifest/create.js +14 -5
- package/dist/core/routing/manifest/generator.js +8 -3
- package/dist/core/util.d.ts +3 -14
- package/dist/core/util.js +4 -2
- package/dist/events/index.js +1 -1
- package/dist/integrations/index.d.ts +3 -2
- package/dist/integrations/index.js +39 -2
- package/dist/jsx/component.d.ts +1 -0
- package/dist/jsx/component.js +10 -0
- package/dist/jsx/index.d.ts +2 -0
- package/dist/jsx/index.js +6 -0
- package/dist/jsx-runtime/index.js +1 -1
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +2 -0
- package/dist/vite-plugin-astro-server/index.js +35 -60
- package/dist/vite-plugin-jsx/index.js +9 -5
- package/dist/vite-plugin-jsx/tag.d.ts +3 -2
- package/dist/vite-plugin-jsx/tag.js +10 -4
- package/env.d.ts +1 -1
- package/package.json +8 -3
package/astro-jsx.d.ts
CHANGED
|
@@ -23,12 +23,12 @@ declare namespace astroHTML.JSX {
|
|
|
23
23
|
children?: Children;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type AstroBuiltinProps = import('./dist/@types/astro').AstroBuiltinProps;
|
|
27
|
-
type AstroBuiltinAttributes = import('./dist/@types/astro').AstroBuiltinAttributes;
|
|
28
|
-
type AstroDefineVarsAttribute = import('./dist/@types/astro').AstroDefineVarsAttribute;
|
|
29
|
-
type AstroScriptAttributes = import('./dist/@types/astro').AstroScriptAttributes &
|
|
26
|
+
type AstroBuiltinProps = import('./dist/@types/astro.js').AstroBuiltinProps;
|
|
27
|
+
type AstroBuiltinAttributes = import('./dist/@types/astro.js').AstroBuiltinAttributes;
|
|
28
|
+
type AstroDefineVarsAttribute = import('./dist/@types/astro.js').AstroDefineVarsAttribute;
|
|
29
|
+
type AstroScriptAttributes = import('./dist/@types/astro.js').AstroScriptAttributes &
|
|
30
30
|
AstroDefineVarsAttribute;
|
|
31
|
-
type AstroStyleAttributes = import('./dist/@types/astro').AstroStyleAttributes &
|
|
31
|
+
type AstroStyleAttributes = import('./dist/@types/astro.js').AstroStyleAttributes &
|
|
32
32
|
AstroDefineVarsAttribute;
|
|
33
33
|
|
|
34
34
|
// This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework
|
|
@@ -1288,7 +1288,7 @@ declare namespace astroHTML.JSX {
|
|
|
1288
1288
|
zoomAndPan?: string | undefined | null;
|
|
1289
1289
|
}
|
|
1290
1290
|
|
|
1291
|
-
interface
|
|
1291
|
+
interface DefinedIntrinsicElements {
|
|
1292
1292
|
// HTML
|
|
1293
1293
|
a: AnchorHTMLAttributes;
|
|
1294
1294
|
abbr: HTMLAttributes;
|
|
@@ -1461,7 +1461,9 @@ declare namespace astroHTML.JSX {
|
|
|
1461
1461
|
tspan: SVGAttributes;
|
|
1462
1462
|
use: SVGAttributes;
|
|
1463
1463
|
view: SVGAttributes;
|
|
1464
|
+
}
|
|
1464
1465
|
|
|
1466
|
+
interface IntrinsicElements extends DefinedIntrinsicElements {
|
|
1465
1467
|
// Allow for arbitrary elements
|
|
1466
1468
|
[name: string]: { [name: string]: any };
|
|
1467
1469
|
}
|
package/components/Code.astro
CHANGED
package/config.d.ts
CHANGED
package/dist/@types/astro.d.ts
CHANGED
|
@@ -60,8 +60,17 @@ export interface CLIFlags {
|
|
|
60
60
|
drafts?: boolean;
|
|
61
61
|
}
|
|
62
62
|
export interface BuildConfig {
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Use config.build.client instead.
|
|
65
|
+
*/
|
|
63
66
|
client: URL;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use config.build.server instead.
|
|
69
|
+
*/
|
|
64
70
|
server: URL;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use config.build.serverEntry instead.
|
|
73
|
+
*/
|
|
65
74
|
serverEntry: string;
|
|
66
75
|
}
|
|
67
76
|
/**
|
|
@@ -69,7 +78,7 @@ export interface BuildConfig {
|
|
|
69
78
|
*
|
|
70
79
|
* [Astro reference](https://docs.astro.build/reference/api-reference/#astro-global)
|
|
71
80
|
*/
|
|
72
|
-
export interface AstroGlobal<Props extends Record<string, any> = Record<string, any>> extends AstroGlobalPartial {
|
|
81
|
+
export interface AstroGlobal<Props extends Record<string, any> = Record<string, any>> extends AstroGlobalPartial, AstroSharedContext<Props> {
|
|
73
82
|
/**
|
|
74
83
|
* Canonical URL of the current page.
|
|
75
84
|
* @deprecated Use `Astro.url` instead.
|
|
@@ -82,21 +91,13 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
82
91
|
* ```
|
|
83
92
|
*/
|
|
84
93
|
canonicalURL: URL;
|
|
85
|
-
/** The address (usually IP address) of the user. Used with SSR only.
|
|
86
|
-
*
|
|
87
|
-
*/
|
|
88
|
-
clientAddress: string;
|
|
89
94
|
/**
|
|
90
95
|
* A full URL object of the request URL.
|
|
91
96
|
* Equivalent to: `new URL(Astro.request.url)`
|
|
92
97
|
*
|
|
93
98
|
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#url)
|
|
94
99
|
*/
|
|
95
|
-
|
|
96
|
-
* Utility for getting and setting cookies values.
|
|
97
|
-
*/
|
|
98
|
-
cookies: AstroCookies;
|
|
99
|
-
url: URL;
|
|
100
|
+
url: AstroSharedContext['url'];
|
|
100
101
|
/** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
|
|
101
102
|
*
|
|
102
103
|
* Example usage:
|
|
@@ -113,9 +114,9 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
113
114
|
* <h1>{id}</h1>
|
|
114
115
|
* ```
|
|
115
116
|
*
|
|
116
|
-
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#
|
|
117
|
+
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroparams)
|
|
117
118
|
*/
|
|
118
|
-
params:
|
|
119
|
+
params: AstroSharedContext['params'];
|
|
119
120
|
/** List of props passed to this component
|
|
120
121
|
*
|
|
121
122
|
* A common way to get specific props is through [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment), ex:
|
|
@@ -125,7 +126,7 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
125
126
|
*
|
|
126
127
|
* [Astro reference](https://docs.astro.build/en/core-concepts/astro-components/#component-props)
|
|
127
128
|
*/
|
|
128
|
-
props: Props;
|
|
129
|
+
props: AstroSharedContext<Props>['props'];
|
|
129
130
|
/** Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
|
|
130
131
|
*
|
|
131
132
|
* For example, to get a URL object of the current URL, you can use:
|
|
@@ -159,11 +160,11 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
159
160
|
*
|
|
160
161
|
* [Astro reference](https://docs.astro.build/en/guides/server-side-rendering/#astroredirect)
|
|
161
162
|
*/
|
|
162
|
-
redirect
|
|
163
|
+
redirect: AstroSharedContext['redirect'];
|
|
163
164
|
/**
|
|
164
165
|
* The <Astro.self /> element allows a component to reference itself recursively.
|
|
165
166
|
*
|
|
166
|
-
* [Astro reference](https://docs.astro.build/en/guides/
|
|
167
|
+
* [Astro reference](https://docs.astro.build/en/guides/api-reference/#astroself)
|
|
167
168
|
*/
|
|
168
169
|
self: AstroComponentFactory;
|
|
169
170
|
/** Utility functions for modifying an Astro component’s slotted children
|
|
@@ -354,6 +355,7 @@ export interface AstroUserConfig {
|
|
|
354
355
|
* @name outDir
|
|
355
356
|
* @type {string}
|
|
356
357
|
* @default `"./dist"`
|
|
358
|
+
* @see build.server
|
|
357
359
|
* @description Set the directory that `astro build` writes your final build to.
|
|
358
360
|
*
|
|
359
361
|
* The value can be either an absolute file system path or a path relative to the project root.
|
|
@@ -493,6 +495,68 @@ export interface AstroUserConfig {
|
|
|
493
495
|
* This means that when you create relative URLs using `new URL('./relative', Astro.url)`, you will get consistent behavior between dev and build.
|
|
494
496
|
*/
|
|
495
497
|
format?: 'file' | 'directory';
|
|
498
|
+
/**
|
|
499
|
+
* @docs
|
|
500
|
+
* @name build.client
|
|
501
|
+
* @type {string}
|
|
502
|
+
* @default `'./dist/client'`
|
|
503
|
+
* @description
|
|
504
|
+
* Controls the output directory of your client-side CSS and JavaScript when `output: 'server'` only.
|
|
505
|
+
* `outDir` controls where the code is built to.
|
|
506
|
+
*
|
|
507
|
+
* This value is relative to the `outDir`.
|
|
508
|
+
*
|
|
509
|
+
* ```js
|
|
510
|
+
* {
|
|
511
|
+
* output: 'server',
|
|
512
|
+
* build: {
|
|
513
|
+
* client: './client'
|
|
514
|
+
* }
|
|
515
|
+
* }
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
client?: string;
|
|
519
|
+
/**
|
|
520
|
+
* @docs
|
|
521
|
+
* @name build.server
|
|
522
|
+
* @type {string}
|
|
523
|
+
* @default `'./dist/server'`
|
|
524
|
+
* @description
|
|
525
|
+
* Controls the output directory of server JavaScript when building to SSR.
|
|
526
|
+
*
|
|
527
|
+
* This value is relative to the `outDir`.
|
|
528
|
+
*
|
|
529
|
+
* ```js
|
|
530
|
+
* {
|
|
531
|
+
* build: {
|
|
532
|
+
* server: './server'
|
|
533
|
+
* }
|
|
534
|
+
* }
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
server?: string;
|
|
538
|
+
/**
|
|
539
|
+
* @docs
|
|
540
|
+
* @name build.serverEntry
|
|
541
|
+
* @type {string}
|
|
542
|
+
* @default `'entry.mjs'`
|
|
543
|
+
* @description
|
|
544
|
+
* Specifies the file name of the server entrypoint when building to SSR.
|
|
545
|
+
* This entrypoint is usually dependent on which host you are deploying to and
|
|
546
|
+
* will be set by your adapter for you.
|
|
547
|
+
*
|
|
548
|
+
* Note that it is recommended that this file ends with `.mjs` so that the runtime
|
|
549
|
+
* detects that the file is a JavaScript module.
|
|
550
|
+
*
|
|
551
|
+
* ```js
|
|
552
|
+
* {
|
|
553
|
+
* build: {
|
|
554
|
+
* serverEntry: 'main.mjs'
|
|
555
|
+
* }
|
|
556
|
+
* }
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
serverEntry?: string;
|
|
496
560
|
};
|
|
497
561
|
/**
|
|
498
562
|
* @docs
|
|
@@ -820,6 +884,7 @@ export interface AstroSettings {
|
|
|
820
884
|
}[];
|
|
821
885
|
tsConfig: TsConfigJson | undefined;
|
|
822
886
|
tsConfigPath: string | undefined;
|
|
887
|
+
watchFiles: string[];
|
|
823
888
|
}
|
|
824
889
|
export declare type AsyncRendererComponentFn<U> = (Component: any, props: any, slots: Record<string, string>, metadata?: AstroComponentMetadata) => Promise<U>;
|
|
825
890
|
/** Generic interface for a component (Astro, Svelte, React, etc.) */
|
|
@@ -969,19 +1034,116 @@ export interface Page<T = any> {
|
|
|
969
1034
|
}
|
|
970
1035
|
export declare type PaginateFunction = (data: any[], args?: PaginateOptions) => GetStaticPathsResult;
|
|
971
1036
|
export declare type Params = Record<string, string | number | undefined>;
|
|
972
|
-
export declare type Props = Record<string, unknown>;
|
|
973
1037
|
export interface AstroAdapter {
|
|
974
1038
|
name: string;
|
|
975
1039
|
serverEntrypoint?: string;
|
|
1040
|
+
previewEntrypoint?: string;
|
|
976
1041
|
exports?: string[];
|
|
977
1042
|
args?: any;
|
|
978
1043
|
}
|
|
979
1044
|
declare type Body = string;
|
|
980
|
-
|
|
1045
|
+
interface AstroSharedContext<Props extends Record<string, any> = Record<string, any>> {
|
|
1046
|
+
/**
|
|
1047
|
+
* The address (usually IP address) of the user. Used with SSR only.
|
|
1048
|
+
*/
|
|
1049
|
+
clientAddress: string;
|
|
1050
|
+
/**
|
|
1051
|
+
* Utility for getting and setting the values of cookies.
|
|
1052
|
+
*/
|
|
981
1053
|
cookies: AstroCookies;
|
|
982
|
-
|
|
1054
|
+
/**
|
|
1055
|
+
* Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
|
|
1056
|
+
*/
|
|
983
1057
|
request: Request;
|
|
1058
|
+
/**
|
|
1059
|
+
* A full URL object of the request URL.
|
|
1060
|
+
*/
|
|
1061
|
+
url: URL;
|
|
1062
|
+
/**
|
|
1063
|
+
* Route parameters for this request if this is a dynamic route.
|
|
1064
|
+
*/
|
|
1065
|
+
params: Params;
|
|
1066
|
+
/**
|
|
1067
|
+
* List of props returned for this path by `getStaticPaths` (**Static Only**).
|
|
1068
|
+
*/
|
|
1069
|
+
props: Props;
|
|
1070
|
+
/**
|
|
1071
|
+
* Redirect to another page (**SSR Only**).
|
|
1072
|
+
*/
|
|
1073
|
+
redirect(path: string, status?: 301 | 302 | 308): Response;
|
|
984
1074
|
}
|
|
1075
|
+
export interface APIContext<Props extends Record<string, any> = Record<string, any>> extends AstroSharedContext<Props> {
|
|
1076
|
+
site: URL | undefined;
|
|
1077
|
+
generator: string;
|
|
1078
|
+
/**
|
|
1079
|
+
* A full URL object of the request URL.
|
|
1080
|
+
* Equivalent to: `new URL(request.url)`
|
|
1081
|
+
*/
|
|
1082
|
+
url: AstroSharedContext['url'];
|
|
1083
|
+
/**
|
|
1084
|
+
* Parameters matching the page’s dynamic route pattern.
|
|
1085
|
+
* In static builds, this will be the `params` generated by `getStaticPaths`.
|
|
1086
|
+
* In SSR builds, this can be any path segments matching the dynamic route pattern.
|
|
1087
|
+
*
|
|
1088
|
+
* Example usage:
|
|
1089
|
+
* ```ts
|
|
1090
|
+
* export function getStaticPaths() {
|
|
1091
|
+
* return [
|
|
1092
|
+
* { params: { id: '0' }, props: { name: 'Sarah' } },
|
|
1093
|
+
* { params: { id: '1' }, props: { name: 'Chris' } },
|
|
1094
|
+
* { params: { id: '2' }, props: { name: 'Fuzzy' } },
|
|
1095
|
+
* ];
|
|
1096
|
+
* }
|
|
1097
|
+
*
|
|
1098
|
+
* export async function get({ params }) {
|
|
1099
|
+
* return {
|
|
1100
|
+
* body: `Hello user ${params.id}!`,
|
|
1101
|
+
* }
|
|
1102
|
+
* }
|
|
1103
|
+
* ```
|
|
1104
|
+
*
|
|
1105
|
+
* [context reference](https://docs.astro.build/en/guides/api-reference/#contextparams)
|
|
1106
|
+
*/
|
|
1107
|
+
params: AstroSharedContext['params'];
|
|
1108
|
+
/**
|
|
1109
|
+
* List of props passed from `getStaticPaths`. Only available to static builds.
|
|
1110
|
+
*
|
|
1111
|
+
* Example usage:
|
|
1112
|
+
* ```ts
|
|
1113
|
+
* export function getStaticPaths() {
|
|
1114
|
+
* return [
|
|
1115
|
+
* { params: { id: '0' }, props: { name: 'Sarah' } },
|
|
1116
|
+
* { params: { id: '1' }, props: { name: 'Chris' } },
|
|
1117
|
+
* { params: { id: '2' }, props: { name: 'Fuzzy' } },
|
|
1118
|
+
* ];
|
|
1119
|
+
* }
|
|
1120
|
+
*
|
|
1121
|
+
* export function get({ props }) {
|
|
1122
|
+
* return {
|
|
1123
|
+
* body: `Hello ${props.name}!`,
|
|
1124
|
+
* }
|
|
1125
|
+
* }
|
|
1126
|
+
* ```
|
|
1127
|
+
*
|
|
1128
|
+
* [context reference](https://docs.astro.build/en/guides/api-reference/#contextprops)
|
|
1129
|
+
*/
|
|
1130
|
+
props: AstroSharedContext<Props>['props'];
|
|
1131
|
+
/**
|
|
1132
|
+
* Redirect to another page. Only available in SSR builds.
|
|
1133
|
+
*
|
|
1134
|
+
* Example usage:
|
|
1135
|
+
* ```ts
|
|
1136
|
+
* // src/pages/secret.ts
|
|
1137
|
+
* export function get({ redirect }) {
|
|
1138
|
+
* return redirect('/login');
|
|
1139
|
+
* }
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* [context reference](https://docs.astro.build/en/guides/api-reference/#contextredirect)
|
|
1143
|
+
*/
|
|
1144
|
+
redirect: AstroSharedContext['redirect'];
|
|
1145
|
+
}
|
|
1146
|
+
export declare type Props = Record<string, unknown>;
|
|
985
1147
|
export interface EndpointOutput {
|
|
986
1148
|
body: Body;
|
|
987
1149
|
encoding?: BufferEncoding;
|
|
@@ -1019,9 +1181,11 @@ export interface AstroIntegration {
|
|
|
1019
1181
|
hooks: {
|
|
1020
1182
|
'astro:config:setup'?: (options: {
|
|
1021
1183
|
config: AstroConfig;
|
|
1022
|
-
command: 'dev' | 'build';
|
|
1184
|
+
command: 'dev' | 'build' | 'preview';
|
|
1185
|
+
isRestart: boolean;
|
|
1023
1186
|
updateConfig: (newConfig: Record<string, any>) => void;
|
|
1024
1187
|
addRenderer: (renderer: AstroRenderer) => void;
|
|
1188
|
+
addWatchFile: (path: URL | string) => void;
|
|
1025
1189
|
injectScript: (stage: InjectedScriptStage, content: string) => void;
|
|
1026
1190
|
injectRoute: (injectRoute: InjectedRoute) => void;
|
|
1027
1191
|
}) => void | Promise<void>;
|
|
@@ -1110,3 +1274,20 @@ export interface SSRResult {
|
|
|
1110
1274
|
export declare type MarkdownAstroData = {
|
|
1111
1275
|
frontmatter: object;
|
|
1112
1276
|
};
|
|
1277
|
+
export interface PreviewServer {
|
|
1278
|
+
host?: string;
|
|
1279
|
+
port: number;
|
|
1280
|
+
closed(): Promise<void>;
|
|
1281
|
+
stop(): Promise<void>;
|
|
1282
|
+
}
|
|
1283
|
+
export interface PreviewServerParams {
|
|
1284
|
+
outDir: URL;
|
|
1285
|
+
client: URL;
|
|
1286
|
+
serverEntrypoint: URL;
|
|
1287
|
+
host: string | undefined;
|
|
1288
|
+
port: number;
|
|
1289
|
+
}
|
|
1290
|
+
export declare type CreatePreviewServer = (params: PreviewServerParams) => PreviewServer | Promise<PreviewServer>;
|
|
1291
|
+
export interface PreviewModule {
|
|
1292
|
+
default: CreatePreviewServer;
|
|
1293
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -7,12 +7,12 @@ import add from "../core/add/index.js";
|
|
|
7
7
|
import build from "../core/build/index.js";
|
|
8
8
|
import {
|
|
9
9
|
createSettings,
|
|
10
|
-
loadTSConfig,
|
|
11
10
|
openConfig,
|
|
12
11
|
resolveConfigPath,
|
|
13
12
|
resolveFlags,
|
|
14
13
|
resolveRoot
|
|
15
14
|
} from "../core/config/index.js";
|
|
15
|
+
import { ASTRO_VERSION } from "../core/constants.js";
|
|
16
16
|
import devServer from "../core/dev/index.js";
|
|
17
17
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
18
18
|
import { debug, error, info } from "../core/logger/core.js";
|
|
@@ -20,7 +20,7 @@ import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js
|
|
|
20
20
|
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
|
|
21
21
|
import { appendForwardSlash } from "../core/path.js";
|
|
22
22
|
import preview from "../core/preview/index.js";
|
|
23
|
-
import {
|
|
23
|
+
import { createSafeError } from "../core/util.js";
|
|
24
24
|
import * as event from "../events/index.js";
|
|
25
25
|
import { eventConfigError, eventError, telemetry } from "../events/index.js";
|
|
26
26
|
import { check } from "./check/index.js";
|
|
@@ -132,12 +132,7 @@ async function runCommand(cmd, flags) {
|
|
|
132
132
|
if (!initialAstroConfig)
|
|
133
133
|
return;
|
|
134
134
|
telemetry.record(event.eventCliSession(cmd, initialUserConfig, flags));
|
|
135
|
-
let
|
|
136
|
-
let settings = createSettings({
|
|
137
|
-
config: initialAstroConfig,
|
|
138
|
-
tsConfig: initialTsConfig == null ? void 0 : initialTsConfig.config,
|
|
139
|
-
tsConfigPath: initialTsConfig == null ? void 0 : initialTsConfig.path
|
|
140
|
-
});
|
|
135
|
+
let settings = createSettings(initialAstroConfig, root);
|
|
141
136
|
switch (cmd) {
|
|
142
137
|
case "dev": {
|
|
143
138
|
async function startDevServer({ isRestart = false } = {}) {
|
|
@@ -147,35 +142,39 @@ async function runCommand(cmd, flags) {
|
|
|
147
142
|
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags }) : void 0;
|
|
148
143
|
const resolvedRoot = appendForwardSlash(resolveRoot(root));
|
|
149
144
|
const handleServerRestart = (logMsg) => async function(changedFile) {
|
|
150
|
-
if (
|
|
145
|
+
if (restartInFlight)
|
|
146
|
+
return;
|
|
147
|
+
let shouldRestart = false;
|
|
148
|
+
shouldRestart = configFlag ? !!configFlagPath && normalizePath(configFlagPath) === normalizePath(changedFile) : new RegExp(
|
|
151
149
|
`${normalizePath(resolvedRoot)}.*astro.config.((mjs)|(cjs)|(js)|(ts))$`
|
|
152
|
-
).test(normalizePath(changedFile))
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
150
|
+
).test(normalizePath(changedFile));
|
|
151
|
+
if (!shouldRestart && settings.watchFiles.length > 0) {
|
|
152
|
+
shouldRestart = settings.watchFiles.some(
|
|
153
|
+
(path) => normalizePath(path) === normalizePath(changedFile)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (!shouldRestart)
|
|
157
|
+
return;
|
|
158
|
+
restartInFlight = true;
|
|
159
|
+
console.clear();
|
|
160
|
+
try {
|
|
161
|
+
const newConfig = await openConfig({
|
|
162
|
+
cwd: root,
|
|
163
|
+
flags,
|
|
164
|
+
cmd,
|
|
165
|
+
logging,
|
|
166
|
+
isRestart: true
|
|
167
|
+
});
|
|
168
|
+
info(logging, "astro", logMsg + "\n");
|
|
169
|
+
let astroConfig = newConfig.astroConfig;
|
|
170
|
+
settings = createSettings(astroConfig, root);
|
|
171
|
+
await stop();
|
|
172
|
+
await startDevServer({ isRestart: true });
|
|
173
|
+
} catch (e) {
|
|
174
|
+
await handleConfigError(e, { cwd: root, flags, logging });
|
|
175
|
+
await stop();
|
|
176
|
+
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
177
|
+
await startDevServer({ isRestart: true });
|
|
179
178
|
}
|
|
180
179
|
};
|
|
181
180
|
watcher.on("change", handleServerRestart("Configuration updated. Restarting..."));
|
package/dist/config/index.js
CHANGED
|
@@ -7,7 +7,7 @@ function getViteConfig(inlineConfig) {
|
|
|
7
7
|
const [
|
|
8
8
|
{ mergeConfig },
|
|
9
9
|
{ nodeLogDestination },
|
|
10
|
-
{ openConfig, createSettings
|
|
10
|
+
{ openConfig, createSettings },
|
|
11
11
|
{ createVite },
|
|
12
12
|
{ runHookConfigSetup, runHookConfigDone }
|
|
13
13
|
] = await Promise.all([
|
|
@@ -25,12 +25,7 @@ function getViteConfig(inlineConfig) {
|
|
|
25
25
|
cmd,
|
|
26
26
|
logging
|
|
27
27
|
});
|
|
28
|
-
const
|
|
29
|
-
const settings = createSettings({
|
|
30
|
-
config,
|
|
31
|
-
tsConfig: initialTsConfig == null ? void 0 : initialTsConfig.config,
|
|
32
|
-
tsConfigPath: initialTsConfig == null ? void 0 : initialTsConfig.path
|
|
33
|
-
});
|
|
28
|
+
const settings = createSettings(config, inlineConfig.root);
|
|
34
29
|
await runHookConfigSetup({ settings, command: cmd, logging });
|
|
35
30
|
const viteConfig = await createVite(
|
|
36
31
|
{
|