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/dist/core/build/index.js
CHANGED
|
@@ -59,9 +59,9 @@ class AstroBuilder {
|
|
|
59
59
|
}
|
|
60
60
|
async build({ viteConfig }) {
|
|
61
61
|
const buildConfig = {
|
|
62
|
-
client:
|
|
63
|
-
server:
|
|
64
|
-
serverEntry:
|
|
62
|
+
client: this.settings.config.build.client,
|
|
63
|
+
server: this.settings.config.build.server,
|
|
64
|
+
serverEntry: this.settings.config.build.serverEntry
|
|
65
65
|
};
|
|
66
66
|
await runHookBuildStart({ config: this.settings.config, buildConfig, logging: this.logging });
|
|
67
67
|
this.validateConfig();
|
|
@@ -14,7 +14,7 @@ interface LoadConfigOptions {
|
|
|
14
14
|
validate?: boolean;
|
|
15
15
|
logging: LogOptions;
|
|
16
16
|
/** Invalidate when reloading a previously loaded config */
|
|
17
|
-
|
|
17
|
+
isRestart?: boolean;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
|
@@ -6,7 +6,7 @@ import path from "path";
|
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import * as vite from "vite";
|
|
8
8
|
import { mergeConfig as mergeViteConfig } from "vite";
|
|
9
|
-
import { arraify, isObject } from "../util.js";
|
|
9
|
+
import { arraify, isObject, isURL } from "../util.js";
|
|
10
10
|
import { createRelativeSchema } from "./schema.js";
|
|
11
11
|
load.use([loadTypeScript]);
|
|
12
12
|
const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -150,7 +150,7 @@ async function tryLoadConfig(configOptions, flags, root) {
|
|
|
150
150
|
});
|
|
151
151
|
if (!configPath)
|
|
152
152
|
return void 0;
|
|
153
|
-
if (configOptions.
|
|
153
|
+
if (configOptions.isRestart) {
|
|
154
154
|
const tempConfigPath = path.join(
|
|
155
155
|
root,
|
|
156
156
|
`.temp.${Date.now()}.config${path.extname(configPath)}`
|
|
@@ -237,6 +237,10 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
|
237
237
|
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
|
|
238
238
|
continue;
|
|
239
239
|
}
|
|
240
|
+
if (isURL(existing) && isURL(value)) {
|
|
241
|
+
merged[key] = value;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
240
244
|
if (isObject(existing) && isObject(value)) {
|
|
241
245
|
merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
|
|
242
246
|
continue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { openConfig, resolveConfigPath, resolveFlags, resolveRoot, validateConfig, } from './config.js';
|
|
2
2
|
export type { AstroConfigSchema } from './schema';
|
|
3
3
|
export { createSettings } from './settings.js';
|
|
4
|
-
export { loadTSConfig } from './tsconfig.js';
|
|
4
|
+
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
validateConfig
|
|
7
7
|
} from "./config.js";
|
|
8
8
|
import { createSettings } from "./settings.js";
|
|
9
|
-
import { loadTSConfig } from "./tsconfig.js";
|
|
9
|
+
import { loadTSConfig, updateTSConfigForFramework } from "./tsconfig.js";
|
|
10
10
|
export {
|
|
11
11
|
createSettings,
|
|
12
12
|
loadTSConfig,
|
|
@@ -14,5 +14,6 @@ export {
|
|
|
14
14
|
resolveConfigPath,
|
|
15
15
|
resolveFlags,
|
|
16
16
|
resolveRoot,
|
|
17
|
+
updateTSConfigForFramework,
|
|
17
18
|
validateConfig
|
|
18
19
|
};
|
|
@@ -36,10 +36,19 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
36
36
|
}[], unknown>;
|
|
37
37
|
build: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
38
38
|
format: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"file">, z.ZodLiteral<"directory">]>>>;
|
|
39
|
+
client: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
40
|
+
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
41
|
+
serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
39
42
|
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
server: URL;
|
|
40
44
|
format: "file" | "directory";
|
|
45
|
+
client: URL;
|
|
46
|
+
serverEntry: string;
|
|
41
47
|
}, {
|
|
48
|
+
server?: string | undefined;
|
|
42
49
|
format?: "file" | "directory" | undefined;
|
|
50
|
+
client?: string | undefined;
|
|
51
|
+
serverEntry?: string | undefined;
|
|
43
52
|
}>>>;
|
|
44
53
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
45
54
|
host: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>>;
|
|
@@ -164,7 +173,10 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
164
173
|
hooks: {};
|
|
165
174
|
}[];
|
|
166
175
|
build: {
|
|
176
|
+
server: URL;
|
|
167
177
|
format: "file" | "directory";
|
|
178
|
+
client: URL;
|
|
179
|
+
serverEntry: string;
|
|
168
180
|
};
|
|
169
181
|
style: {
|
|
170
182
|
postcss: {
|
|
@@ -205,7 +217,10 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
205
217
|
} | undefined;
|
|
206
218
|
integrations?: unknown;
|
|
207
219
|
build?: {
|
|
220
|
+
server?: string | undefined;
|
|
208
221
|
format?: "file" | "directory" | undefined;
|
|
222
|
+
client?: string | undefined;
|
|
223
|
+
serverEntry?: string | undefined;
|
|
209
224
|
} | undefined;
|
|
210
225
|
style?: {
|
|
211
226
|
postcss?: {
|
|
@@ -218,7 +233,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
218
233
|
astroFlavoredMarkdown?: boolean | undefined;
|
|
219
234
|
} | undefined;
|
|
220
235
|
}>;
|
|
221
|
-
export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL): z.ZodObject<z.extendShape<{
|
|
236
|
+
export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL): z.ZodEffects<z.ZodObject<z.extendShape<{
|
|
222
237
|
root: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
223
238
|
srcDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
224
239
|
publicDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
@@ -252,10 +267,19 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
252
267
|
}[], unknown>;
|
|
253
268
|
build: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
254
269
|
format: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"file">, z.ZodLiteral<"directory">]>>>;
|
|
270
|
+
client: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
271
|
+
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
272
|
+
serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
255
273
|
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
server: URL;
|
|
256
275
|
format: "file" | "directory";
|
|
276
|
+
client: URL;
|
|
277
|
+
serverEntry: string;
|
|
257
278
|
}, {
|
|
279
|
+
server?: string | undefined;
|
|
258
280
|
format?: "file" | "directory" | undefined;
|
|
281
|
+
client?: string | undefined;
|
|
282
|
+
serverEntry?: string | undefined;
|
|
259
283
|
}>>>;
|
|
260
284
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
261
285
|
host: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>>;
|
|
@@ -350,6 +374,22 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
350
374
|
srcDir: z.ZodEffects<z.ZodDefault<z.ZodString>, URL, string | undefined>;
|
|
351
375
|
publicDir: z.ZodEffects<z.ZodDefault<z.ZodString>, URL, string | undefined>;
|
|
352
376
|
outDir: z.ZodEffects<z.ZodDefault<z.ZodString>, URL, string | undefined>;
|
|
377
|
+
build: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
378
|
+
format: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"file">, z.ZodLiteral<"directory">]>>>;
|
|
379
|
+
client: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
380
|
+
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
381
|
+
serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
382
|
+
}, "strip", z.ZodTypeAny, {
|
|
383
|
+
server: URL;
|
|
384
|
+
format: "file" | "directory";
|
|
385
|
+
client: URL;
|
|
386
|
+
serverEntry: string;
|
|
387
|
+
}, {
|
|
388
|
+
server?: string | undefined;
|
|
389
|
+
format?: "file" | "directory" | undefined;
|
|
390
|
+
client?: string | undefined;
|
|
391
|
+
serverEntry?: string | undefined;
|
|
392
|
+
}>>>;
|
|
353
393
|
server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
354
394
|
host: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>>;
|
|
355
395
|
port: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -425,7 +465,102 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
425
465
|
hooks: {};
|
|
426
466
|
}[];
|
|
427
467
|
build: {
|
|
468
|
+
server: URL;
|
|
469
|
+
format: "file" | "directory";
|
|
470
|
+
client: URL;
|
|
471
|
+
serverEntry: string;
|
|
472
|
+
};
|
|
473
|
+
style: {
|
|
474
|
+
postcss: {
|
|
475
|
+
options?: any;
|
|
476
|
+
plugins: any[];
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
vite: ViteUserConfig;
|
|
480
|
+
legacy: {
|
|
481
|
+
astroFlavoredMarkdown: boolean;
|
|
482
|
+
};
|
|
483
|
+
}, {
|
|
484
|
+
site?: string | undefined;
|
|
485
|
+
base?: string | undefined;
|
|
486
|
+
markdown?: {
|
|
487
|
+
drafts?: boolean | undefined;
|
|
488
|
+
syntaxHighlight?: false | "shiki" | "prism" | undefined;
|
|
489
|
+
shikiConfig?: {
|
|
490
|
+
langs?: ILanguageRegistration[] | undefined;
|
|
491
|
+
theme?: string | import("shiki").IShikiTheme | undefined;
|
|
492
|
+
wrap?: boolean | null | undefined;
|
|
493
|
+
} | undefined;
|
|
494
|
+
remarkPlugins?: (string | [string, any] | RemarkPlugin<any[]> | [RemarkPlugin<any[]>, any])[] | undefined;
|
|
495
|
+
rehypePlugins?: (string | [string, any] | RehypePlugin<any[]> | [RehypePlugin<any[]>, any])[] | undefined;
|
|
496
|
+
remarkRehype?: RemarkRehype | undefined;
|
|
497
|
+
extendDefaultPlugins?: boolean | undefined;
|
|
498
|
+
} | undefined;
|
|
499
|
+
root?: string | undefined;
|
|
500
|
+
srcDir?: string | undefined;
|
|
501
|
+
publicDir?: string | undefined;
|
|
502
|
+
outDir?: string | undefined;
|
|
503
|
+
trailingSlash?: "never" | "always" | "ignore" | undefined;
|
|
504
|
+
server?: unknown;
|
|
505
|
+
output?: "static" | "server" | undefined;
|
|
506
|
+
adapter?: {
|
|
507
|
+
hooks?: {} | undefined;
|
|
508
|
+
name: string;
|
|
509
|
+
} | undefined;
|
|
510
|
+
integrations?: unknown;
|
|
511
|
+
build?: {
|
|
512
|
+
server?: string | undefined;
|
|
513
|
+
format?: "file" | "directory" | undefined;
|
|
514
|
+
client?: string | undefined;
|
|
515
|
+
serverEntry?: string | undefined;
|
|
516
|
+
} | undefined;
|
|
517
|
+
style?: {
|
|
518
|
+
postcss?: unknown;
|
|
519
|
+
} | undefined;
|
|
520
|
+
vite?: ViteUserConfig | undefined;
|
|
521
|
+
legacy?: {
|
|
522
|
+
astroFlavoredMarkdown?: boolean | undefined;
|
|
523
|
+
} | undefined;
|
|
524
|
+
}>, {
|
|
525
|
+
site?: string | undefined;
|
|
526
|
+
adapter?: {
|
|
527
|
+
name: string;
|
|
528
|
+
hooks: {};
|
|
529
|
+
} | undefined;
|
|
530
|
+
base: string;
|
|
531
|
+
markdown: {
|
|
532
|
+
drafts: boolean;
|
|
533
|
+
syntaxHighlight: false | "shiki" | "prism";
|
|
534
|
+
shikiConfig: {
|
|
535
|
+
langs: ILanguageRegistration[];
|
|
536
|
+
theme: string | import("shiki").IShikiTheme;
|
|
537
|
+
wrap: boolean | null;
|
|
538
|
+
};
|
|
539
|
+
remarkPlugins: (string | [string, any] | RemarkPlugin<any[]> | [RemarkPlugin<any[]>, any])[];
|
|
540
|
+
rehypePlugins: (string | [string, any] | RehypePlugin<any[]> | [RehypePlugin<any[]>, any])[];
|
|
541
|
+
remarkRehype: RemarkRehype;
|
|
542
|
+
extendDefaultPlugins: boolean;
|
|
543
|
+
};
|
|
544
|
+
root: URL;
|
|
545
|
+
srcDir: URL;
|
|
546
|
+
publicDir: URL;
|
|
547
|
+
outDir: URL;
|
|
548
|
+
trailingSlash: "never" | "always" | "ignore";
|
|
549
|
+
server: {
|
|
550
|
+
host: string | boolean;
|
|
551
|
+
port: number;
|
|
552
|
+
streaming: boolean;
|
|
553
|
+
};
|
|
554
|
+
output: "static" | "server";
|
|
555
|
+
integrations: {
|
|
556
|
+
name: string;
|
|
557
|
+
hooks: {};
|
|
558
|
+
}[];
|
|
559
|
+
build: {
|
|
560
|
+
server: URL;
|
|
428
561
|
format: "file" | "directory";
|
|
562
|
+
client: URL;
|
|
563
|
+
serverEntry: string;
|
|
429
564
|
};
|
|
430
565
|
style: {
|
|
431
566
|
postcss: {
|
|
@@ -466,7 +601,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
|
|
|
466
601
|
} | undefined;
|
|
467
602
|
integrations?: unknown;
|
|
468
603
|
build?: {
|
|
604
|
+
server?: string | undefined;
|
|
469
605
|
format?: "file" | "directory" | undefined;
|
|
606
|
+
client?: string | undefined;
|
|
607
|
+
serverEntry?: string | undefined;
|
|
470
608
|
} | undefined;
|
|
471
609
|
style?: {
|
|
472
610
|
postcss?: unknown;
|
|
@@ -11,7 +11,12 @@ const ASTRO_CONFIG_DEFAULTS = {
|
|
|
11
11
|
outDir: "./dist",
|
|
12
12
|
base: "/",
|
|
13
13
|
trailingSlash: "ignore",
|
|
14
|
-
build: {
|
|
14
|
+
build: {
|
|
15
|
+
format: "directory",
|
|
16
|
+
client: "./dist/client/",
|
|
17
|
+
server: "./dist/server/",
|
|
18
|
+
serverEntry: "entry.mjs"
|
|
19
|
+
},
|
|
15
20
|
server: {
|
|
16
21
|
host: false,
|
|
17
22
|
port: 3e3,
|
|
@@ -51,7 +56,10 @@ const AstroConfigSchema = z.object({
|
|
|
51
56
|
z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default(ASTRO_CONFIG_DEFAULTS.integrations)
|
|
52
57
|
),
|
|
53
58
|
build: z.object({
|
|
54
|
-
format: z.union([z.literal("file"), z.literal("directory")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format)
|
|
59
|
+
format: z.union([z.literal("file"), z.literal("directory")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
|
|
60
|
+
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => new URL(val)),
|
|
61
|
+
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => new URL(val)),
|
|
62
|
+
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry)
|
|
55
63
|
}).optional().default({}),
|
|
56
64
|
server: z.preprocess(
|
|
57
65
|
(val) => typeof val === "function" ? val({ command: "error" }) : val,
|
|
@@ -122,6 +130,12 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
|
|
|
122
130
|
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
|
|
123
131
|
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
|
|
124
132
|
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
|
|
133
|
+
build: z.object({
|
|
134
|
+
format: z.union([z.literal("file"), z.literal("directory")]).optional().default(ASTRO_CONFIG_DEFAULTS.build.format),
|
|
135
|
+
client: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.client).transform((val) => new URL(val, fileProtocolRoot)),
|
|
136
|
+
server: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.server).transform((val) => new URL(val, fileProtocolRoot)),
|
|
137
|
+
serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry)
|
|
138
|
+
}).optional().default({}),
|
|
125
139
|
server: z.preprocess(
|
|
126
140
|
(val) => typeof val === "function" ? val({ command: cmd === "dev" ? "dev" : "preview" }) : val,
|
|
127
141
|
z.object({
|
|
@@ -139,6 +153,14 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
|
|
|
139
153
|
}).optional().default(ASTRO_CONFIG_DEFAULTS.style.postcss)
|
|
140
154
|
)
|
|
141
155
|
}).optional().default({})
|
|
156
|
+
}).transform((config) => {
|
|
157
|
+
if (!config.build.server.toString().startsWith(config.outDir.toString()) && config.build.server.toString().endsWith("dist/server/")) {
|
|
158
|
+
config.build.server = new URL("./dist/server/", config.outDir);
|
|
159
|
+
}
|
|
160
|
+
if (!config.build.client.toString().startsWith(config.outDir.toString()) && config.build.client.toString().endsWith("dist/client/")) {
|
|
161
|
+
config.build.client = new URL("./dist/client/", config.outDir);
|
|
162
|
+
}
|
|
163
|
+
return config;
|
|
142
164
|
});
|
|
143
165
|
return AstroConfigRelativeSchema;
|
|
144
166
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import type { TsConfigJson } from 'tsconfig-resolver';
|
|
2
1
|
import type { AstroConfig, AstroSettings } from '../../@types/astro';
|
|
3
|
-
export
|
|
4
|
-
config: AstroConfig;
|
|
5
|
-
tsConfig?: TsConfigJson;
|
|
6
|
-
tsConfigPath?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function createSettings({ config, tsConfig, tsConfigPath }: CreateSettings): AstroSettings;
|
|
2
|
+
export declare function createSettings(config: AstroConfig, cwd?: string): AstroSettings;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import jsxRenderer from "../../jsx/renderer.js";
|
|
2
|
-
|
|
2
|
+
import { loadTSConfig } from "./tsconfig.js";
|
|
3
|
+
function createSettings(config, cwd) {
|
|
4
|
+
const tsconfig = loadTSConfig(cwd);
|
|
3
5
|
return {
|
|
4
6
|
config,
|
|
5
|
-
tsConfig,
|
|
6
|
-
tsConfigPath,
|
|
7
|
+
tsConfig: tsconfig == null ? void 0 : tsconfig.config,
|
|
8
|
+
tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
|
|
7
9
|
adapter: void 0,
|
|
8
10
|
injectedRoutes: [],
|
|
9
11
|
pageExtensions: [".astro", ".md", ".html"],
|
|
10
12
|
renderers: [jsxRenderer],
|
|
11
|
-
scripts: []
|
|
13
|
+
scripts: [],
|
|
14
|
+
watchFiles: (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : []
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
export {
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import * as tsr from 'tsconfig-resolver';
|
|
2
|
-
export declare
|
|
2
|
+
export declare const defaultTSConfig: tsr.TsConfigJson;
|
|
3
|
+
export declare type frameworkWithTSSettings = 'vue' | 'react' | 'preact' | 'solid-js';
|
|
4
|
+
export declare const presets: Map<frameworkWithTSSettings, tsr.TsConfigJson>;
|
|
5
|
+
/**
|
|
6
|
+
* Load a tsconfig.json or jsconfig.json is the former is not found
|
|
7
|
+
* @param cwd Directory to start from
|
|
8
|
+
* @param resolve Determine if the function should go up directories like TypeScript would
|
|
9
|
+
*/
|
|
10
|
+
export declare function loadTSConfig(cwd: string | undefined, resolve?: boolean): tsr.TsConfigResult;
|
|
11
|
+
export declare function updateTSConfigForFramework(target: tsr.TsConfigJson, framework: frameworkWithTSSettings): tsr.TsConfigJson;
|
|
@@ -1,13 +1,79 @@
|
|
|
1
|
+
import { deepmerge } from "deepmerge-ts";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
1
4
|
import * as tsr from "tsconfig-resolver";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const defaultTSConfig = { extends: "astro/tsconfigs/base" };
|
|
6
|
+
const presets = /* @__PURE__ */ new Map([
|
|
7
|
+
[
|
|
8
|
+
"vue",
|
|
9
|
+
{
|
|
10
|
+
compilerOptions: {
|
|
11
|
+
jsx: "preserve"
|
|
12
|
+
}
|
|
7
13
|
}
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"react",
|
|
17
|
+
{
|
|
18
|
+
compilerOptions: {
|
|
19
|
+
jsx: "react-jsx",
|
|
20
|
+
jsxImportSource: "react"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"preact",
|
|
26
|
+
{
|
|
27
|
+
compilerOptions: {
|
|
28
|
+
jsx: "react-jsx",
|
|
29
|
+
jsxImportSource: "preact"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"solid-js",
|
|
35
|
+
{
|
|
36
|
+
compilerOptions: {
|
|
37
|
+
jsx: "preserve",
|
|
38
|
+
jsxImportSource: "solid-js"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
]);
|
|
43
|
+
function loadTSConfig(cwd, resolve = true) {
|
|
44
|
+
cwd = cwd ?? process.cwd();
|
|
45
|
+
let config = tsr.tsconfigResolverSync({
|
|
46
|
+
cwd,
|
|
47
|
+
filePath: resolve ? void 0 : cwd
|
|
48
|
+
});
|
|
49
|
+
if (!resolve && config.reason === "invalid-config" && !existsSync(join(cwd, "tsconfig.json"))) {
|
|
50
|
+
config = { reason: "not-found", path: void 0, exists: false };
|
|
51
|
+
} else {
|
|
52
|
+
return config;
|
|
53
|
+
}
|
|
54
|
+
if (config.reason === "not-found") {
|
|
55
|
+
const jsconfig = tsr.tsconfigResolverSync({
|
|
56
|
+
cwd,
|
|
57
|
+
filePath: resolve ? void 0 : cwd,
|
|
58
|
+
searchName: "jsconfig.json"
|
|
59
|
+
});
|
|
60
|
+
if (!resolve && jsconfig.reason === "invalid-config" && !existsSync(join(cwd, "jsconfig.json"))) {
|
|
61
|
+
return { reason: "not-found", path: void 0, exists: false };
|
|
62
|
+
} else {
|
|
63
|
+
return jsconfig;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return config;
|
|
67
|
+
}
|
|
68
|
+
function updateTSConfigForFramework(target, framework) {
|
|
69
|
+
if (!presets.has(framework)) {
|
|
70
|
+
return target;
|
|
8
71
|
}
|
|
9
|
-
return
|
|
72
|
+
return deepmerge(target, presets.get(framework));
|
|
10
73
|
}
|
|
11
74
|
export {
|
|
12
|
-
|
|
75
|
+
defaultTSConfig,
|
|
76
|
+
loadTSConfig,
|
|
77
|
+
presets,
|
|
78
|
+
updateTSConfigForFramework
|
|
13
79
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ASTRO_VERSION: string;
|
|
@@ -19,7 +19,7 @@ interface AstroCookieInterface {
|
|
|
19
19
|
interface AstroCookiesInterface {
|
|
20
20
|
get(key: string): AstroCookieInterface;
|
|
21
21
|
has(key: string): boolean;
|
|
22
|
-
set(key: string, value: string | Record<string, any>, options?: AstroCookieSetOptions): void;
|
|
22
|
+
set(key: string, value: string | number | boolean | Record<string, any>, options?: AstroCookieSetOptions): void;
|
|
23
23
|
delete(key: string, options?: AstroCookieDeleteOptions): void;
|
|
24
24
|
}
|
|
25
25
|
declare class AstroCookie implements AstroCookieInterface {
|
package/dist/core/dev/index.js
CHANGED
|
@@ -16,7 +16,12 @@ async function dev(settings, options) {
|
|
|
16
16
|
const devStart = performance.now();
|
|
17
17
|
applyPolyfill();
|
|
18
18
|
await options.telemetry.record([]);
|
|
19
|
-
settings = await runHookConfigSetup({
|
|
19
|
+
settings = await runHookConfigSetup({
|
|
20
|
+
settings,
|
|
21
|
+
command: "dev",
|
|
22
|
+
logging: options.logging,
|
|
23
|
+
isRestart: options.isRestart
|
|
24
|
+
});
|
|
20
25
|
const { host, port } = settings.config.server;
|
|
21
26
|
const { isRestart = false } = options;
|
|
22
27
|
const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
|
|
@@ -49,7 +54,7 @@ async function dev(settings, options) {
|
|
|
49
54
|
isRestart
|
|
50
55
|
})
|
|
51
56
|
);
|
|
52
|
-
const currentVersion = "1.
|
|
57
|
+
const currentVersion = "1.5.0";
|
|
53
58
|
if (currentVersion.includes("-")) {
|
|
54
59
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
55
60
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { preload } from "../../render/dev/index.js";
|
|
2
2
|
import { call as callEndpoint } from "../index.js";
|
|
3
3
|
async function call(ssrOpts) {
|
|
4
|
+
var _a;
|
|
4
5
|
const [, mod] = await preload(ssrOpts);
|
|
5
6
|
return await callEndpoint(mod, {
|
|
6
7
|
...ssrOpts,
|
|
7
|
-
ssr: ssrOpts.settings.config.output === "server"
|
|
8
|
+
ssr: ssrOpts.settings.config.output === "server",
|
|
9
|
+
site: ssrOpts.settings.config.site,
|
|
10
|
+
adapterName: (_a = ssrOpts.settings.config.adapter) == null ? void 0 : _a.name
|
|
8
11
|
});
|
|
9
12
|
}
|
|
10
13
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { EndpointHandler } from '../../@types/astro';
|
|
3
3
|
import type { RenderOptions } from '../render/core';
|
|
4
|
-
export declare type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr' | 'status'>;
|
|
4
|
+
export declare type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr' | 'status' | 'adapterName'>;
|
|
5
5
|
declare type EndpointCallResult = {
|
|
6
6
|
type: 'simple';
|
|
7
7
|
body: string;
|
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
import { renderEndpoint } from "../../runtime/server/index.js";
|
|
2
|
+
import { ASTRO_VERSION } from "../constants.js";
|
|
2
3
|
import { AstroCookies, attachToResponse } from "../cookies/index.js";
|
|
3
4
|
import { getParamsAndProps, GetParamsAndPropsError } from "../render/core.js";
|
|
4
|
-
|
|
5
|
+
const clientAddressSymbol = Symbol.for("astro.clientAddress");
|
|
6
|
+
function createAPIContext({
|
|
7
|
+
request,
|
|
8
|
+
params,
|
|
9
|
+
site,
|
|
10
|
+
props,
|
|
11
|
+
adapterName
|
|
12
|
+
}) {
|
|
5
13
|
return {
|
|
6
14
|
cookies: new AstroCookies(request),
|
|
7
15
|
request,
|
|
8
|
-
params
|
|
16
|
+
params,
|
|
17
|
+
site: site ? new URL(site) : void 0,
|
|
18
|
+
generator: `Astro v${ASTRO_VERSION}`,
|
|
19
|
+
props,
|
|
20
|
+
redirect(path, status) {
|
|
21
|
+
return new Response(null, {
|
|
22
|
+
status: status || 302,
|
|
23
|
+
headers: {
|
|
24
|
+
Location: path
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
url: new URL(request.url),
|
|
29
|
+
get clientAddress() {
|
|
30
|
+
if (!(clientAddressSymbol in request)) {
|
|
31
|
+
if (adapterName) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`clientAddress is not available in the ${adapterName} adapter. File an issue with the adapter to add support.`
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`clientAddress is not available in your environment. Ensure that you are using an SSR adapter that supports this feature.`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Reflect.get(request, clientAddressSymbol);
|
|
42
|
+
}
|
|
9
43
|
};
|
|
10
44
|
}
|
|
11
45
|
async function call(mod, opts) {
|
|
@@ -15,8 +49,14 @@ async function call(mod, opts) {
|
|
|
15
49
|
`[getStaticPath] route pattern matched, but no matching static path found. (${opts.pathname})`
|
|
16
50
|
);
|
|
17
51
|
}
|
|
18
|
-
const [params] = paramsAndPropsResp;
|
|
19
|
-
const context = createAPIContext(
|
|
52
|
+
const [params, props] = paramsAndPropsResp;
|
|
53
|
+
const context = createAPIContext({
|
|
54
|
+
request: opts.request,
|
|
55
|
+
params,
|
|
56
|
+
props,
|
|
57
|
+
site: opts.site,
|
|
58
|
+
adapterName: opts.adapterName
|
|
59
|
+
});
|
|
20
60
|
const response = await renderEndpoint(mod, context, opts.ssr);
|
|
21
61
|
if (response instanceof Response) {
|
|
22
62
|
attachToResponse(response, context.cookies);
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.
|
|
50
|
+
const version = "1.5.0";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -250,7 +250,7 @@ function printHelp({
|
|
|
250
250
|
message.push(
|
|
251
251
|
linebreak(),
|
|
252
252
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
253
|
-
`v${"1.
|
|
253
|
+
`v${"1.5.0"}`
|
|
254
254
|
)} ${headline}`
|
|
255
255
|
);
|
|
256
256
|
}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { AstroTelemetry } from '@astrojs/telemetry';
|
|
3
|
-
import type { AstroSettings } from '../../@types/astro';
|
|
2
|
+
import type { AstroSettings, PreviewServer } from '../../@types/astro';
|
|
4
3
|
import type { LogOptions } from '../logger/core';
|
|
5
|
-
import http from 'http';
|
|
6
4
|
interface PreviewOptions {
|
|
7
5
|
logging: LogOptions;
|
|
8
6
|
telemetry: AstroTelemetry;
|
|
9
7
|
}
|
|
10
|
-
export interface PreviewServer {
|
|
11
|
-
host?: string;
|
|
12
|
-
port: number;
|
|
13
|
-
server: http.Server;
|
|
14
|
-
closed(): Promise<void>;
|
|
15
|
-
stop(): Promise<void>;
|
|
16
|
-
}
|
|
17
8
|
/** The primary dev action */
|
|
18
|
-
export default function preview(
|
|
9
|
+
export default function preview(_settings: AstroSettings, { logging }: PreviewOptions): Promise<PreviewServer>;
|
|
19
10
|
export {};
|