astro 1.4.7 → 1.5.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/Code.astro +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 +140 -23
- 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 +24 -2
- 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 +73 -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.js +4 -1
- package/dist/core/endpoint/index.d.ts +1 -1
- package/dist/core/endpoint/index.js +44 -4
- 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/core.d.ts +1 -1
- package/dist/core/render/result.js +2 -2
- 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/runtime/server/astro-global.js +1 -1
- 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/package.json +4 -2
package/components/Code.astro
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
|
{
|
package/dist/core/add/index.js
CHANGED
|
@@ -2,13 +2,18 @@ import boxen from "boxen";
|
|
|
2
2
|
import { diffWords } from "diff";
|
|
3
3
|
import { execa } from "execa";
|
|
4
4
|
import { existsSync, promises as fs } from "fs";
|
|
5
|
-
import { bold, cyan, dim, green, magenta, yellow } from "kleur/colors";
|
|
5
|
+
import { bold, cyan, dim, green, magenta, red, yellow } from "kleur/colors";
|
|
6
6
|
import ora from "ora";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import preferredPM from "preferred-pm";
|
|
9
9
|
import prompts from "prompts";
|
|
10
10
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
11
|
-
import { resolveConfigPath } from "../config/index.js";
|
|
11
|
+
import { loadTSConfig, resolveConfigPath } from "../config/index.js";
|
|
12
|
+
import {
|
|
13
|
+
defaultTSConfig,
|
|
14
|
+
presets,
|
|
15
|
+
updateTSConfigForFramework
|
|
16
|
+
} from "../config/tsconfig.js";
|
|
12
17
|
import { debug, info } from "../logger/core.js";
|
|
13
18
|
import * as msg from "../messages.js";
|
|
14
19
|
import { printHelp } from "../messages.js";
|
|
@@ -212,7 +217,7 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
212
217
|
switch (configResult) {
|
|
213
218
|
case UpdateResult.cancelled: {
|
|
214
219
|
info(logging, null, msg.cancelled(`Your configuration has ${bold("NOT")} been updated.`));
|
|
215
|
-
|
|
220
|
+
break;
|
|
216
221
|
}
|
|
217
222
|
case UpdateResult.none: {
|
|
218
223
|
const pkgURL = new URL("./package.json", configURL);
|
|
@@ -224,11 +229,11 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
224
229
|
);
|
|
225
230
|
if (missingDeps.length === 0) {
|
|
226
231
|
info(logging, null, msg.success(`Configuration up-to-date.`));
|
|
227
|
-
|
|
232
|
+
break;
|
|
228
233
|
}
|
|
229
234
|
}
|
|
230
235
|
info(logging, null, msg.success(`Configuration up-to-date.`));
|
|
231
|
-
|
|
236
|
+
break;
|
|
232
237
|
}
|
|
233
238
|
default: {
|
|
234
239
|
const list = integrations.map((integration) => ` - ${integration.packageName}`).join("\n");
|
|
@@ -242,6 +247,27 @@ ${list}`
|
|
|
242
247
|
);
|
|
243
248
|
}
|
|
244
249
|
}
|
|
250
|
+
const updateTSConfigResult = await updateTSConfig(cwd, logging, integrations, flags);
|
|
251
|
+
switch (updateTSConfigResult) {
|
|
252
|
+
case UpdateResult.none: {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case UpdateResult.cancelled: {
|
|
256
|
+
info(
|
|
257
|
+
logging,
|
|
258
|
+
null,
|
|
259
|
+
msg.cancelled(`Your TypeScript configuration has ${bold("NOT")} been updated.`)
|
|
260
|
+
);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case UpdateResult.failure: {
|
|
264
|
+
throw new Error(
|
|
265
|
+
`Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
default:
|
|
269
|
+
info(logging, null, msg.success(`Successfully updated TypeScript settings`));
|
|
270
|
+
}
|
|
245
271
|
}
|
|
246
272
|
function isAdapter(integration) {
|
|
247
273
|
return integration.type === "adapter";
|
|
@@ -392,27 +418,12 @@ ${defaultExport}`);
|
|
|
392
418
|
if (input === output) {
|
|
393
419
|
return 0 /* none */;
|
|
394
420
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
let lines = change.value.trim().split("\n").slice(0, change.count);
|
|
398
|
-
if (lines.length === 0)
|
|
399
|
-
continue;
|
|
400
|
-
if (change.added) {
|
|
401
|
-
if (!change.value.trim())
|
|
402
|
-
continue;
|
|
403
|
-
changes.push(change.value);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
if (changes.length === 0) {
|
|
421
|
+
const diff = getDiffContent(input, output);
|
|
422
|
+
if (!diff) {
|
|
407
423
|
return 0 /* none */;
|
|
408
424
|
}
|
|
409
|
-
let diffed = output;
|
|
410
|
-
for (let newContent of changes) {
|
|
411
|
-
const coloredOutput = newContent.split("\n").map((ln) => ln ? green(ln) : "").join("\n");
|
|
412
|
-
diffed = diffed.replace(newContent, coloredOutput);
|
|
413
|
-
}
|
|
414
425
|
const message = `
|
|
415
|
-
${boxen(
|
|
426
|
+
${boxen(diff, {
|
|
416
427
|
margin: 0.5,
|
|
417
428
|
padding: 0.5,
|
|
418
429
|
borderStyle: "round",
|
|
@@ -616,6 +627,90 @@ async function validateIntegrations(integrations) {
|
|
|
616
627
|
}
|
|
617
628
|
}
|
|
618
629
|
}
|
|
630
|
+
async function updateTSConfig(cwd = process.cwd(), logging, integrationsInfo, flags) {
|
|
631
|
+
var _a, _b;
|
|
632
|
+
const integrations = integrationsInfo.map(
|
|
633
|
+
(integration) => integration.id
|
|
634
|
+
);
|
|
635
|
+
const firstIntegrationWithTSSettings = integrations.find(
|
|
636
|
+
(integration) => presets.has(integration)
|
|
637
|
+
);
|
|
638
|
+
if (!firstIntegrationWithTSSettings) {
|
|
639
|
+
return 0 /* none */;
|
|
640
|
+
}
|
|
641
|
+
const inputConfig = loadTSConfig(cwd, false);
|
|
642
|
+
const configFileName = inputConfig.exists ? inputConfig.path.split("/").pop() : "tsconfig.json";
|
|
643
|
+
if (inputConfig.reason === "invalid-config") {
|
|
644
|
+
return 3 /* failure */;
|
|
645
|
+
}
|
|
646
|
+
if (inputConfig.reason === "not-found") {
|
|
647
|
+
debug("add", "Couldn't find tsconfig.json or jsconfig.json, generating one");
|
|
648
|
+
}
|
|
649
|
+
const outputConfig = updateTSConfigForFramework(
|
|
650
|
+
inputConfig.exists ? inputConfig.config : defaultTSConfig,
|
|
651
|
+
firstIntegrationWithTSSettings
|
|
652
|
+
);
|
|
653
|
+
const input = inputConfig.exists ? JSON.stringify(inputConfig.config, null, 2) : "";
|
|
654
|
+
const output = JSON.stringify(outputConfig, null, 2);
|
|
655
|
+
const diff = getDiffContent(input, output);
|
|
656
|
+
if (!diff) {
|
|
657
|
+
return 0 /* none */;
|
|
658
|
+
}
|
|
659
|
+
const message = `
|
|
660
|
+
${boxen(diff, {
|
|
661
|
+
margin: 0.5,
|
|
662
|
+
padding: 0.5,
|
|
663
|
+
borderStyle: "round",
|
|
664
|
+
title: configFileName
|
|
665
|
+
})}
|
|
666
|
+
`;
|
|
667
|
+
info(
|
|
668
|
+
logging,
|
|
669
|
+
null,
|
|
670
|
+
`
|
|
671
|
+
${magenta(`Astro will make the following changes to your ${configFileName}:`)}
|
|
672
|
+
${message}`
|
|
673
|
+
);
|
|
674
|
+
const conflictingIntegrations = [...Object.keys(presets).filter((config) => config !== "vue")];
|
|
675
|
+
const hasConflictingIntegrations = integrations.filter((integration) => presets.has(integration)).length > 1 && integrations.filter((integration) => conflictingIntegrations.includes(integration)).length > 0;
|
|
676
|
+
if (hasConflictingIntegrations) {
|
|
677
|
+
info(
|
|
678
|
+
logging,
|
|
679
|
+
null,
|
|
680
|
+
red(
|
|
681
|
+
` ${bold(
|
|
682
|
+
"Caution:"
|
|
683
|
+
)} Selected UI frameworks require conflicting tsconfig.json settings, as such only settings for ${bold(
|
|
684
|
+
firstIntegrationWithTSSettings
|
|
685
|
+
)} were used.
|
|
686
|
+
More information: https://docs.astro.build/en/guides/typescript/#errors-typing-multiple-jsx-frameworks-at-the-same-time
|
|
687
|
+
`
|
|
688
|
+
)
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
if (integrations.includes("vue") && hasConflictingIntegrations && (((_a = outputConfig.compilerOptions) == null ? void 0 : _a.jsx) !== "preserve" && ((_b = outputConfig.compilerOptions) == null ? void 0 : _b.jsxImportSource) !== void 0 || integrations.includes("react"))) {
|
|
692
|
+
info(
|
|
693
|
+
logging,
|
|
694
|
+
null,
|
|
695
|
+
red(
|
|
696
|
+
` ${bold(
|
|
697
|
+
"Caution:"
|
|
698
|
+
)} Using Vue together with a JSX framework can lead to type checking issues inside Vue files.
|
|
699
|
+
More information: https://docs.astro.build/en/guides/typescript/#vue-components-are-mistakenly-typed-by-the-typesreact-package-when-installed
|
|
700
|
+
`
|
|
701
|
+
)
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
if (await askToContinue({ flags })) {
|
|
705
|
+
await fs.writeFile((inputConfig == null ? void 0 : inputConfig.path) ?? path.join(cwd, "tsconfig.json"), output, {
|
|
706
|
+
encoding: "utf-8"
|
|
707
|
+
});
|
|
708
|
+
debug("add", `Updated ${configFileName} file`);
|
|
709
|
+
return 1 /* updated */;
|
|
710
|
+
} else {
|
|
711
|
+
return 2 /* cancelled */;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
619
714
|
function parseIntegrationName(spec) {
|
|
620
715
|
const result = parseNpmName(spec);
|
|
621
716
|
if (!result)
|
|
@@ -643,6 +738,28 @@ async function askToContinue({ flags }) {
|
|
|
643
738
|
});
|
|
644
739
|
return Boolean(response.askToContinue);
|
|
645
740
|
}
|
|
741
|
+
function getDiffContent(input, output) {
|
|
742
|
+
let changes = [];
|
|
743
|
+
for (const change of diffWords(input, output)) {
|
|
744
|
+
let lines = change.value.trim().split("\n").slice(0, change.count);
|
|
745
|
+
if (lines.length === 0)
|
|
746
|
+
continue;
|
|
747
|
+
if (change.added) {
|
|
748
|
+
if (!change.value.trim())
|
|
749
|
+
continue;
|
|
750
|
+
changes.push(change.value);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (changes.length === 0) {
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
let diffed = output;
|
|
757
|
+
for (let newContent of changes) {
|
|
758
|
+
const coloredOutput = newContent.split("\n").map((ln) => ln ? green(ln) : "").join("\n");
|
|
759
|
+
diffed = diffed.replace(newContent, coloredOutput);
|
|
760
|
+
}
|
|
761
|
+
return diffed;
|
|
762
|
+
}
|
|
646
763
|
export {
|
|
647
764
|
add as default,
|
|
648
765
|
validateIntegrations
|