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.
Files changed (71) hide show
  1. package/astro-jsx.d.ts +8 -6
  2. package/components/Code.astro +1 -1
  3. package/config.d.ts +1 -1
  4. package/dist/@types/astro.d.ts +200 -19
  5. package/dist/cli/index.js +35 -36
  6. package/dist/config/index.js +2 -7
  7. package/dist/core/add/index.js +141 -24
  8. package/dist/core/app/index.js +45 -43
  9. package/dist/core/build/generate.js +14 -12
  10. package/dist/core/build/index.js +3 -3
  11. package/dist/core/config/config.d.ts +1 -1
  12. package/dist/core/config/config.js +6 -2
  13. package/dist/core/config/index.d.ts +1 -1
  14. package/dist/core/config/index.js +2 -1
  15. package/dist/core/config/schema.d.ts +139 -1
  16. package/dist/core/config/schema.js +36 -3
  17. package/dist/core/config/settings.d.ts +1 -7
  18. package/dist/core/config/settings.js +7 -4
  19. package/dist/core/config/tsconfig.d.ts +10 -1
  20. package/dist/core/config/tsconfig.js +72 -7
  21. package/dist/core/constants.d.ts +1 -0
  22. package/dist/core/constants.js +4 -0
  23. package/dist/core/cookies/cookies.d.ts +1 -1
  24. package/dist/core/dev/index.js +7 -2
  25. package/dist/core/endpoint/dev/index.d.ts +2 -1
  26. package/dist/core/endpoint/dev/index.js +13 -6
  27. package/dist/core/endpoint/index.d.ts +4 -3
  28. package/dist/core/endpoint/index.js +57 -9
  29. package/dist/core/messages.js +2 -2
  30. package/dist/core/preview/index.d.ts +2 -11
  31. package/dist/core/preview/index.js +31 -125
  32. package/dist/core/preview/static-preview-server.d.ts +17 -0
  33. package/dist/core/preview/static-preview-server.js +127 -0
  34. package/dist/core/render/context.d.ts +20 -0
  35. package/dist/core/render/context.js +15 -0
  36. package/dist/core/render/core.d.ts +4 -24
  37. package/dist/core/render/core.js +26 -47
  38. package/dist/core/render/dev/environment.d.ts +9 -0
  39. package/dist/core/render/dev/environment.js +30 -0
  40. package/dist/core/render/dev/index.d.ts +22 -5
  41. package/dist/core/render/dev/index.js +38 -69
  42. package/dist/core/render/dev/resolve.d.ts +2 -0
  43. package/dist/core/render/dev/resolve.js +14 -0
  44. package/dist/core/render/environment.d.ts +29 -0
  45. package/dist/core/render/environment.js +21 -0
  46. package/dist/core/render/index.d.ts +6 -0
  47. package/dist/core/render/index.js +13 -0
  48. package/dist/core/render/renderer.d.ts +9 -0
  49. package/dist/core/render/renderer.js +23 -0
  50. package/dist/core/render/result.js +3 -3
  51. package/dist/core/routing/manifest/create.js +14 -5
  52. package/dist/core/routing/manifest/generator.js +8 -3
  53. package/dist/core/util.d.ts +3 -14
  54. package/dist/core/util.js +4 -2
  55. package/dist/events/index.js +1 -1
  56. package/dist/integrations/index.d.ts +3 -2
  57. package/dist/integrations/index.js +39 -2
  58. package/dist/jsx/component.d.ts +1 -0
  59. package/dist/jsx/component.js +10 -0
  60. package/dist/jsx/index.d.ts +2 -0
  61. package/dist/jsx/index.js +6 -0
  62. package/dist/jsx-runtime/index.js +1 -1
  63. package/dist/runtime/server/astro-global.js +1 -1
  64. package/dist/runtime/server/index.d.ts +1 -0
  65. package/dist/runtime/server/index.js +2 -0
  66. package/dist/vite-plugin-astro-server/index.js +35 -60
  67. package/dist/vite-plugin-jsx/index.js +9 -5
  68. package/dist/vite-plugin-jsx/tag.d.ts +3 -2
  69. package/dist/vite-plugin-jsx/tag.js +10 -4
  70. package/env.d.ts +1 -1
  71. package/package.json +8 -3
@@ -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: { format: "directory" },
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,8 +130,25 @@ 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
- (val) => typeof val === "function" ? val({ command: cmd === "dev" ? "dev" : "preview" }) : val,
140
+ (val) => {
141
+ if (typeof val === "function") {
142
+ const result = val({ command: cmd === "dev" ? "dev" : "preview" });
143
+ if (val.port)
144
+ result.port = val.port;
145
+ if (val.host)
146
+ result.host = val.host;
147
+ return result;
148
+ } else {
149
+ return val;
150
+ }
151
+ },
127
152
  z.object({
128
153
  host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
129
154
  port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
@@ -139,6 +164,14 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
139
164
  }).optional().default(ASTRO_CONFIG_DEFAULTS.style.postcss)
140
165
  )
141
166
  }).optional().default({})
167
+ }).transform((config) => {
168
+ if (!config.build.server.toString().startsWith(config.outDir.toString()) && config.build.server.toString().endsWith("dist/server/")) {
169
+ config.build.server = new URL("./dist/server/", config.outDir);
170
+ }
171
+ if (!config.build.client.toString().startsWith(config.outDir.toString()) && config.build.client.toString().endsWith("dist/client/")) {
172
+ config.build.client = new URL("./dist/client/", config.outDir);
173
+ }
174
+ return config;
142
175
  });
143
176
  return AstroConfigRelativeSchema;
144
177
  }
@@ -1,8 +1,2 @@
1
- import type { TsConfigJson } from 'tsconfig-resolver';
2
1
  import type { AstroConfig, AstroSettings } from '../../@types/astro';
3
- export interface CreateSettings {
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
- function createSettings({ config, tsConfig, tsConfigPath }) {
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 function loadTSConfig(cwd: string | undefined): tsr.TsConfigResult | undefined;
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,78 @@
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
- function loadTSConfig(cwd) {
3
- for (const searchName of ["tsconfig.json", "jsconfig.json"]) {
4
- const config = tsr.tsconfigResolverSync({ cwd, searchName });
5
- if (config.exists) {
6
- return config;
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
+ ignoreExtends: !resolve
49
+ });
50
+ if (!resolve && config.reason === "invalid-config" && !existsSync(join(cwd, "tsconfig.json"))) {
51
+ config = { reason: "not-found", path: void 0, exists: false };
52
+ }
53
+ if (config.reason === "not-found") {
54
+ const jsconfig = tsr.tsconfigResolverSync({
55
+ cwd,
56
+ filePath: resolve ? void 0 : cwd,
57
+ searchName: "jsconfig.json",
58
+ ignoreExtends: !resolve
59
+ });
60
+ if (!resolve && jsconfig.reason === "invalid-config" && !existsSync(join(cwd, "jsconfig.json"))) {
61
+ return { reason: "not-found", path: void 0, exists: false };
62
+ }
63
+ return jsconfig;
64
+ }
65
+ return config;
66
+ }
67
+ function updateTSConfigForFramework(target, framework) {
68
+ if (!presets.has(framework)) {
69
+ return target;
8
70
  }
9
- return void 0;
71
+ return deepmerge(target, presets.get(framework));
10
72
  }
11
73
  export {
12
- loadTSConfig
74
+ defaultTSConfig,
75
+ loadTSConfig,
76
+ presets,
77
+ updateTSConfigForFramework
13
78
  };
@@ -0,0 +1 @@
1
+ export declare const ASTRO_VERSION: string;
@@ -0,0 +1,4 @@
1
+ const ASTRO_VERSION = "1.5.1";
2
+ export {
3
+ ASTRO_VERSION
4
+ };
@@ -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 {
@@ -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({ settings, command: "dev", logging: options.logging });
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.4.7";
57
+ const currentVersion = "1.5.1";
53
58
  if (currentVersion.includes("-")) {
54
59
  warn(options.logging, null, msg.prerelease({ currentVersion }));
55
60
  }
@@ -1,9 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import type { SSROptions } from '../../render/dev';
3
- export declare function call(ssrOpts: SSROptions): Promise<{
3
+ export declare function call(options: SSROptions): Promise<{
4
4
  type: "simple";
5
5
  body: string;
6
6
  encoding?: BufferEncoding | undefined;
7
+ cookies: import("../../cookies/cookies").AstroCookies;
7
8
  } | {
8
9
  type: "response";
9
10
  response: Response;
@@ -1,11 +1,18 @@
1
- import { preload } from "../../render/dev/index.js";
1
+ import { createRenderContext } from "../../render/index.js";
2
2
  import { call as callEndpoint } from "../index.js";
3
- async function call(ssrOpts) {
4
- const [, mod] = await preload(ssrOpts);
5
- return await callEndpoint(mod, {
6
- ...ssrOpts,
7
- ssr: ssrOpts.settings.config.output === "server"
3
+ async function call(options) {
4
+ const {
5
+ env,
6
+ preload: [, mod]
7
+ } = options;
8
+ const endpointHandler = mod;
9
+ const ctx = createRenderContext({
10
+ request: options.request,
11
+ origin: options.origin,
12
+ pathname: options.pathname,
13
+ route: options.route
8
14
  });
15
+ return await callEndpoint(endpointHandler, env, ctx);
9
16
  }
10
17
  export {
11
18
  call
@@ -1,14 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import type { EndpointHandler } from '../../@types/astro';
3
- import type { RenderOptions } from '../render/core';
4
- export declare type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr' | 'status'>;
3
+ import type { Environment, RenderContext } from '../render/index';
4
+ import { AstroCookies } from '../cookies/index.js';
5
5
  declare type EndpointCallResult = {
6
6
  type: 'simple';
7
7
  body: string;
8
8
  encoding?: BufferEncoding;
9
+ cookies: AstroCookies;
9
10
  } | {
10
11
  type: 'response';
11
12
  response: Response;
12
13
  };
13
- export declare function call(mod: EndpointHandler, opts: EndpointOptions): Promise<EndpointCallResult>;
14
+ export declare function call(mod: EndpointHandler, env: Environment, ctx: RenderContext): Promise<EndpointCallResult>;
14
15
  export {};
@@ -1,23 +1,70 @@
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
- function createAPIContext(request, params) {
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
- async function call(mod, opts) {
12
- const paramsAndPropsResp = await getParamsAndProps({ ...opts, mod });
45
+ async function call(mod, env, ctx) {
46
+ const paramsAndPropsResp = await getParamsAndProps({
47
+ mod,
48
+ route: ctx.route,
49
+ routeCache: env.routeCache,
50
+ pathname: ctx.pathname,
51
+ logging: env.logging,
52
+ ssr: env.ssr
53
+ });
13
54
  if (paramsAndPropsResp === GetParamsAndPropsError.NoMatchingStaticPath) {
14
55
  throw new Error(
15
- `[getStaticPath] route pattern matched, but no matching static path found. (${opts.pathname})`
56
+ `[getStaticPath] route pattern matched, but no matching static path found. (${ctx.pathname})`
16
57
  );
17
58
  }
18
- const [params] = paramsAndPropsResp;
19
- const context = createAPIContext(opts.request, params);
20
- const response = await renderEndpoint(mod, context, opts.ssr);
59
+ const [params, props] = paramsAndPropsResp;
60
+ const context = createAPIContext({
61
+ request: ctx.request,
62
+ params,
63
+ props,
64
+ site: env.site,
65
+ adapterName: env.adapterName
66
+ });
67
+ const response = await renderEndpoint(mod, context, env.ssr);
21
68
  if (response instanceof Response) {
22
69
  attachToResponse(response, context.cookies);
23
70
  return {
@@ -28,7 +75,8 @@ async function call(mod, opts) {
28
75
  return {
29
76
  type: "simple",
30
77
  body: response.body,
31
- encoding: response.encoding
78
+ encoding: response.encoding,
79
+ cookies: context.cookies
32
80
  };
33
81
  }
34
82
  export {
@@ -47,7 +47,7 @@ function serverStart({
47
47
  site,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "1.4.7";
50
+ const version = "1.5.1";
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.4.7"}`
253
+ `v${"1.5.1"}`
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(settings: AstroSettings, { logging }: PreviewOptions): Promise<PreviewServer>;
9
+ export default function preview(_settings: AstroSettings, { logging }: PreviewOptions): Promise<PreviewServer>;
19
10
  export {};