astro 1.6.2 → 1.6.3

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 (86) hide show
  1. package/dist/@types/typed-emitter.d.ts +42 -0
  2. package/dist/@types/typed-emitter.js +0 -0
  3. package/dist/cli/index.js +13 -51
  4. package/dist/core/build/generate.js +10 -6
  5. package/dist/core/compile/compile.d.ts +3 -3
  6. package/dist/core/compile/compile.js +15 -10
  7. package/dist/core/compile/style.d.ts +7 -4
  8. package/dist/core/compile/style.js +65 -12
  9. package/dist/core/config/config.d.ts +7 -3
  10. package/dist/core/config/config.js +15 -12
  11. package/dist/core/config/index.d.ts +2 -2
  12. package/dist/core/config/index.js +4 -1
  13. package/dist/core/config/schema.d.ts +69 -69
  14. package/dist/core/config/settings.d.ts +3 -1
  15. package/dist/core/config/settings.js +23 -5
  16. package/dist/core/constants.js +1 -1
  17. package/dist/core/create-vite.d.ts +4 -1
  18. package/dist/core/create-vite.js +7 -4
  19. package/dist/core/dev/container.d.ts +36 -0
  20. package/dist/core/dev/container.js +109 -0
  21. package/dist/core/dev/dev.d.ts +24 -0
  22. package/dist/core/dev/dev.js +55 -0
  23. package/dist/core/dev/index.d.ts +3 -18
  24. package/dist/core/dev/index.js +8 -81
  25. package/dist/core/dev/restart.d.ts +25 -0
  26. package/dist/core/dev/restart.js +143 -0
  27. package/dist/core/endpoint/index.d.ts +2 -1
  28. package/dist/core/endpoint/index.js +12 -1
  29. package/dist/core/errors/dev/vite.d.ts +3 -2
  30. package/dist/core/errors/dev/vite.js +4 -6
  31. package/dist/core/messages.js +2 -2
  32. package/dist/core/module-loader/index.d.ts +3 -0
  33. package/dist/core/module-loader/index.js +6 -0
  34. package/dist/core/module-loader/loader.d.ts +42 -0
  35. package/dist/core/module-loader/loader.js +39 -0
  36. package/dist/core/module-loader/vite.d.ts +3 -0
  37. package/dist/core/module-loader/vite.js +62 -0
  38. package/dist/core/render/dev/css.d.ts +2 -2
  39. package/dist/core/render/dev/css.js +3 -3
  40. package/dist/core/render/dev/environment.d.ts +3 -3
  41. package/dist/core/render/dev/environment.js +3 -3
  42. package/dist/core/render/dev/index.d.ts +4 -4
  43. package/dist/core/render/dev/index.js +8 -8
  44. package/dist/core/render/dev/resolve.d.ts +2 -2
  45. package/dist/core/render/dev/resolve.js +2 -2
  46. package/dist/core/render/dev/scripts.d.ts +2 -2
  47. package/dist/core/render/dev/scripts.js +4 -4
  48. package/dist/core/render/dev/vite.d.ts +2 -2
  49. package/dist/core/render/dev/vite.js +5 -5
  50. package/dist/core/routing/manifest/create.d.ts +10 -3
  51. package/dist/core/routing/manifest/create.js +7 -6
  52. package/dist/core/util.d.ts +3 -4
  53. package/dist/core/util.js +10 -17
  54. package/dist/vite-plugin-astro/index.js +9 -20
  55. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  56. package/dist/vite-plugin-astro-server/base.d.ts +4 -0
  57. package/dist/vite-plugin-astro-server/base.js +36 -0
  58. package/dist/vite-plugin-astro-server/common.d.ts +2 -0
  59. package/dist/vite-plugin-astro-server/common.js +8 -0
  60. package/dist/vite-plugin-astro-server/controller.d.ts +26 -0
  61. package/dist/vite-plugin-astro-server/controller.js +77 -0
  62. package/dist/vite-plugin-astro-server/index.d.ts +3 -10
  63. package/dist/vite-plugin-astro-server/index.js +7 -336
  64. package/dist/vite-plugin-astro-server/plugin.d.ts +11 -0
  65. package/dist/vite-plugin-astro-server/plugin.js +54 -0
  66. package/dist/vite-plugin-astro-server/request.d.ts +7 -0
  67. package/dist/vite-plugin-astro-server/request.js +52 -0
  68. package/dist/vite-plugin-astro-server/response.d.ts +9 -0
  69. package/dist/vite-plugin-astro-server/response.js +85 -0
  70. package/dist/vite-plugin-astro-server/route.d.ts +13 -0
  71. package/dist/vite-plugin-astro-server/route.js +144 -0
  72. package/dist/vite-plugin-astro-server/server-state.d.ts +15 -0
  73. package/dist/vite-plugin-astro-server/server-state.js +42 -0
  74. package/dist/vite-plugin-jsx/index.js +2 -2
  75. package/dist/vite-plugin-load-fallback/index.d.ts +9 -0
  76. package/dist/vite-plugin-load-fallback/index.js +26 -0
  77. package/dist/vite-plugin-markdown/index.js +1 -1
  78. package/dist/vite-plugin-markdown-legacy/index.js +8 -24
  79. package/package.json +4 -2
  80. package/types.d.ts +1 -1
  81. package/dist/vite-style-transform/index.d.ts +0 -2
  82. package/dist/vite-style-transform/index.js +0 -5
  83. package/dist/vite-style-transform/style-transform.d.ts +0 -10
  84. package/dist/vite-style-transform/style-transform.js +0 -80
  85. package/dist/vite-style-transform/transform-with-vite.d.ts +0 -18
  86. package/dist/vite-style-transform/transform-with-vite.js +0 -33
@@ -159,25 +159,28 @@ export declare const AstroConfigSchema: z.ZodObject<{
159
159
  extendDefaultPlugins: boolean;
160
160
  };
161
161
  root: URL;
162
- srcDir: URL;
163
162
  publicDir: URL;
164
- outDir: URL;
165
- trailingSlash: "never" | "always" | "ignore";
166
163
  server: {
167
164
  host: string | boolean;
168
165
  port: number;
169
166
  };
170
- output: "static" | "server";
171
- integrations: {
172
- name: string;
173
- hooks: {};
174
- }[];
175
167
  build: {
176
168
  server: URL;
177
169
  format: "file" | "directory";
178
170
  client: URL;
179
171
  serverEntry: string;
180
172
  };
173
+ legacy: {
174
+ astroFlavoredMarkdown: boolean;
175
+ };
176
+ srcDir: URL;
177
+ outDir: URL;
178
+ trailingSlash: "never" | "always" | "ignore";
179
+ output: "server" | "static";
180
+ integrations: {
181
+ name: string;
182
+ hooks: {};
183
+ }[];
181
184
  style: {
182
185
  postcss: {
183
186
  options?: any;
@@ -185,9 +188,6 @@ export declare const AstroConfigSchema: z.ZodObject<{
185
188
  };
186
189
  };
187
190
  vite: ViteUserConfig;
188
- legacy: {
189
- astroFlavoredMarkdown: boolean;
190
- };
191
191
  }, {
192
192
  site?: string | undefined;
193
193
  base?: string | undefined;
@@ -205,23 +205,26 @@ export declare const AstroConfigSchema: z.ZodObject<{
205
205
  extendDefaultPlugins?: boolean | undefined;
206
206
  } | undefined;
207
207
  root?: string | undefined;
208
- srcDir?: string | undefined;
209
208
  publicDir?: string | undefined;
210
- outDir?: string | undefined;
211
- trailingSlash?: "never" | "always" | "ignore" | undefined;
212
209
  server?: unknown;
213
- output?: "static" | "server" | undefined;
214
- adapter?: {
215
- hooks?: {} | undefined;
216
- name: string;
217
- } | undefined;
218
- integrations?: unknown;
219
210
  build?: {
220
211
  server?: string | undefined;
221
212
  format?: "file" | "directory" | undefined;
222
213
  client?: string | undefined;
223
214
  serverEntry?: string | undefined;
224
215
  } | undefined;
216
+ legacy?: {
217
+ astroFlavoredMarkdown?: boolean | undefined;
218
+ } | undefined;
219
+ srcDir?: string | undefined;
220
+ outDir?: string | undefined;
221
+ trailingSlash?: "never" | "always" | "ignore" | undefined;
222
+ output?: "server" | "static" | undefined;
223
+ adapter?: {
224
+ hooks?: {} | undefined;
225
+ name: string;
226
+ } | undefined;
227
+ integrations?: unknown;
225
228
  style?: {
226
229
  postcss?: {
227
230
  options?: any;
@@ -229,9 +232,6 @@ export declare const AstroConfigSchema: z.ZodObject<{
229
232
  } | undefined;
230
233
  } | undefined;
231
234
  vite?: ViteUserConfig | undefined;
232
- legacy?: {
233
- astroFlavoredMarkdown?: boolean | undefined;
234
- } | undefined;
235
235
  }>;
236
236
  export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL): z.ZodEffects<z.ZodObject<z.extendShape<{
237
237
  root: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
@@ -450,26 +450,29 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
450
450
  extendDefaultPlugins: boolean;
451
451
  };
452
452
  root: URL;
453
- srcDir: URL;
454
453
  publicDir: URL;
455
- outDir: URL;
456
- trailingSlash: "never" | "always" | "ignore";
457
454
  server: {
458
455
  host: string | boolean;
459
456
  port: number;
460
457
  streaming: boolean;
461
458
  };
462
- output: "static" | "server";
463
- integrations: {
464
- name: string;
465
- hooks: {};
466
- }[];
467
459
  build: {
468
460
  server: URL;
469
461
  format: "file" | "directory";
470
462
  client: URL;
471
463
  serverEntry: string;
472
464
  };
465
+ legacy: {
466
+ astroFlavoredMarkdown: boolean;
467
+ };
468
+ srcDir: URL;
469
+ outDir: URL;
470
+ trailingSlash: "never" | "always" | "ignore";
471
+ output: "server" | "static";
472
+ integrations: {
473
+ name: string;
474
+ hooks: {};
475
+ }[];
473
476
  style: {
474
477
  postcss: {
475
478
  options?: any;
@@ -477,9 +480,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
477
480
  };
478
481
  };
479
482
  vite: ViteUserConfig;
480
- legacy: {
481
- astroFlavoredMarkdown: boolean;
482
- };
483
483
  }, {
484
484
  site?: string | undefined;
485
485
  base?: string | undefined;
@@ -497,30 +497,30 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
497
497
  extendDefaultPlugins?: boolean | undefined;
498
498
  } | undefined;
499
499
  root?: string | undefined;
500
- srcDir?: string | undefined;
501
500
  publicDir?: string | undefined;
502
- outDir?: string | undefined;
503
- trailingSlash?: "never" | "always" | "ignore" | undefined;
504
501
  server?: unknown;
505
- output?: "static" | "server" | undefined;
506
- adapter?: {
507
- hooks?: {} | undefined;
508
- name: string;
509
- } | undefined;
510
- integrations?: unknown;
511
502
  build?: {
512
503
  server?: string | undefined;
513
504
  format?: "file" | "directory" | undefined;
514
505
  client?: string | undefined;
515
506
  serverEntry?: string | undefined;
516
507
  } | undefined;
508
+ legacy?: {
509
+ astroFlavoredMarkdown?: boolean | undefined;
510
+ } | undefined;
511
+ srcDir?: string | undefined;
512
+ outDir?: string | undefined;
513
+ trailingSlash?: "never" | "always" | "ignore" | undefined;
514
+ output?: "server" | "static" | undefined;
515
+ adapter?: {
516
+ hooks?: {} | undefined;
517
+ name: string;
518
+ } | undefined;
519
+ integrations?: unknown;
517
520
  style?: {
518
521
  postcss?: unknown;
519
522
  } | undefined;
520
523
  vite?: ViteUserConfig | undefined;
521
- legacy?: {
522
- astroFlavoredMarkdown?: boolean | undefined;
523
- } | undefined;
524
524
  }>, {
525
525
  site?: string | undefined;
526
526
  adapter?: {
@@ -542,26 +542,29 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
542
542
  extendDefaultPlugins: boolean;
543
543
  };
544
544
  root: URL;
545
- srcDir: URL;
546
545
  publicDir: URL;
547
- outDir: URL;
548
- trailingSlash: "never" | "always" | "ignore";
549
546
  server: {
550
547
  host: string | boolean;
551
548
  port: number;
552
549
  streaming: boolean;
553
550
  };
554
- output: "static" | "server";
555
- integrations: {
556
- name: string;
557
- hooks: {};
558
- }[];
559
551
  build: {
560
552
  server: URL;
561
553
  format: "file" | "directory";
562
554
  client: URL;
563
555
  serverEntry: string;
564
556
  };
557
+ legacy: {
558
+ astroFlavoredMarkdown: boolean;
559
+ };
560
+ srcDir: URL;
561
+ outDir: URL;
562
+ trailingSlash: "never" | "always" | "ignore";
563
+ output: "server" | "static";
564
+ integrations: {
565
+ name: string;
566
+ hooks: {};
567
+ }[];
565
568
  style: {
566
569
  postcss: {
567
570
  options?: any;
@@ -569,9 +572,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
569
572
  };
570
573
  };
571
574
  vite: ViteUserConfig;
572
- legacy: {
573
- astroFlavoredMarkdown: boolean;
574
- };
575
575
  }, {
576
576
  site?: string | undefined;
577
577
  base?: string | undefined;
@@ -589,28 +589,28 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
589
589
  extendDefaultPlugins?: boolean | undefined;
590
590
  } | undefined;
591
591
  root?: string | undefined;
592
- srcDir?: string | undefined;
593
592
  publicDir?: string | undefined;
594
- outDir?: string | undefined;
595
- trailingSlash?: "never" | "always" | "ignore" | undefined;
596
593
  server?: unknown;
597
- output?: "static" | "server" | undefined;
598
- adapter?: {
599
- hooks?: {} | undefined;
600
- name: string;
601
- } | undefined;
602
- integrations?: unknown;
603
594
  build?: {
604
595
  server?: string | undefined;
605
596
  format?: "file" | "directory" | undefined;
606
597
  client?: string | undefined;
607
598
  serverEntry?: string | undefined;
608
599
  } | undefined;
600
+ legacy?: {
601
+ astroFlavoredMarkdown?: boolean | undefined;
602
+ } | undefined;
603
+ srcDir?: string | undefined;
604
+ outDir?: string | undefined;
605
+ trailingSlash?: "never" | "always" | "ignore" | undefined;
606
+ output?: "server" | "static" | undefined;
607
+ adapter?: {
608
+ hooks?: {} | undefined;
609
+ name: string;
610
+ } | undefined;
611
+ integrations?: unknown;
609
612
  style?: {
610
613
  postcss?: unknown;
611
614
  } | undefined;
612
615
  vite?: ViteUserConfig | undefined;
613
- legacy?: {
614
- astroFlavoredMarkdown?: boolean | undefined;
615
- } | undefined;
616
616
  }>;
@@ -1,2 +1,4 @@
1
- import type { AstroConfig, AstroSettings } from '../../@types/astro';
1
+ import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro';
2
+ export declare function createBaseSettings(config: AstroConfig): AstroSettings;
2
3
  export declare function createSettings(config: AstroConfig, cwd?: string): AstroSettings;
4
+ export declare function createDefaultDevSettings(userConfig?: AstroUserConfig, root?: string | URL): Promise<AstroSettings>;
@@ -1,20 +1,38 @@
1
1
  import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
2
+ import { fileURLToPath } from "url";
2
3
  import jsxRenderer from "../../jsx/renderer.js";
4
+ import { createDefaultDevConfig } from "./config.js";
3
5
  import { loadTSConfig } from "./tsconfig.js";
4
- function createSettings(config, cwd) {
5
- const tsconfig = loadTSConfig(cwd);
6
+ function createBaseSettings(config) {
6
7
  return {
7
8
  config,
8
- tsConfig: tsconfig == null ? void 0 : tsconfig.config,
9
- tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
9
+ tsConfig: void 0,
10
+ tsConfigPath: void 0,
10
11
  adapter: void 0,
11
12
  injectedRoutes: [],
12
13
  pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
13
14
  renderers: [jsxRenderer],
14
15
  scripts: [],
15
- watchFiles: (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : []
16
+ watchFiles: []
16
17
  };
17
18
  }
19
+ function createSettings(config, cwd) {
20
+ const tsconfig = loadTSConfig(cwd);
21
+ const settings = createBaseSettings(config);
22
+ settings.tsConfig = tsconfig == null ? void 0 : tsconfig.config;
23
+ settings.tsConfigPath = tsconfig == null ? void 0 : tsconfig.path;
24
+ settings.watchFiles = (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : [];
25
+ return settings;
26
+ }
27
+ async function createDefaultDevSettings(userConfig = {}, root) {
28
+ if (root && typeof root !== "string") {
29
+ root = fileURLToPath(root);
30
+ }
31
+ const config = await createDefaultDevConfig(userConfig, root);
32
+ return createBaseSettings(config);
33
+ }
18
34
  export {
35
+ createBaseSettings,
36
+ createDefaultDevSettings,
19
37
  createSettings
20
38
  };
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.6.2";
1
+ const ASTRO_VERSION = "1.6.3";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -1,11 +1,14 @@
1
+ /// <reference types="node" />
1
2
  import type { AstroSettings } from '../@types/astro';
2
3
  import type { LogOptions } from './logger/core';
4
+ import nodeFs from 'fs';
3
5
  import * as vite from 'vite';
4
6
  interface CreateViteOptions {
5
7
  settings: AstroSettings;
6
8
  logging: LogOptions;
7
9
  mode: 'dev' | 'build' | string;
10
+ fs?: typeof nodeFs;
8
11
  }
9
12
  /** Return a common starting point for all Vite actions */
10
- export declare function createVite(commandConfig: vite.InlineConfig, { settings, logging, mode }: CreateViteOptions): Promise<vite.InlineConfig>;
13
+ export declare function createVite(commandConfig: vite.InlineConfig, { settings, logging, mode, fs }: CreateViteOptions): Promise<vite.InlineConfig>;
11
14
  export {};
@@ -1,14 +1,16 @@
1
+ import nodeFs from "fs";
1
2
  import { fileURLToPath } from "url";
2
3
  import * as vite from "vite";
3
4
  import { crawlFrameworkPkgs } from "vitefu";
4
5
  import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
5
- import astroViteServerPlugin from "../vite-plugin-astro-server/index.js";
6
+ import { vitePluginAstroServer } from "../vite-plugin-astro-server/index.js";
6
7
  import astroVitePlugin from "../vite-plugin-astro/index.js";
7
8
  import configAliasVitePlugin from "../vite-plugin-config-alias/index.js";
8
9
  import envVitePlugin from "../vite-plugin-env/index.js";
9
10
  import htmlVitePlugin from "../vite-plugin-html/index.js";
10
11
  import astroIntegrationsContainerPlugin from "../vite-plugin-integrations-container/index.js";
11
12
  import jsxVitePlugin from "../vite-plugin-jsx/index.js";
13
+ import astroLoadFallbackPlugin from "../vite-plugin-load-fallback/index.js";
12
14
  import legacyMarkdownVitePlugin from "../vite-plugin-markdown-legacy/index.js";
13
15
  import markdownVitePlugin from "../vite-plugin-markdown/index.js";
14
16
  import astroScriptsPlugin from "../vite-plugin-scripts/index.js";
@@ -32,7 +34,7 @@ function getSsrNoExternalDeps(projectRoot) {
32
34
  }
33
35
  return noExternalDeps;
34
36
  }
35
- async function createVite(commandConfig, { settings, logging, mode }) {
37
+ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs }) {
36
38
  const astroPkgsConfig = await crawlFrameworkPkgs({
37
39
  root: fileURLToPath(settings.config.root),
38
40
  isBuild: mode === "build",
@@ -62,14 +64,15 @@ async function createVite(commandConfig, { settings, logging, mode }) {
62
64
  configAliasVitePlugin({ settings }),
63
65
  astroVitePlugin({ settings, logging }),
64
66
  astroScriptsPlugin({ settings }),
65
- mode !== "build" && astroViteServerPlugin({ settings, logging }),
67
+ mode !== "build" && vitePluginAstroServer({ settings, logging, fs }),
66
68
  envVitePlugin({ settings }),
67
69
  settings.config.legacy.astroFlavoredMarkdown ? legacyMarkdownVitePlugin({ settings, logging }) : markdownVitePlugin({ settings, logging }),
68
70
  htmlVitePlugin(),
69
71
  jsxVitePlugin({ settings, logging }),
70
72
  astroPostprocessVitePlugin({ settings }),
71
73
  astroIntegrationsContainerPlugin({ settings, logging }),
72
- astroScriptsPageSSRPlugin({ settings })
74
+ astroScriptsPageSSRPlugin({ settings }),
75
+ astroLoadFallbackPlugin({ fs })
73
76
  ],
74
77
  publicDir: fileURLToPath(settings.config.publicDir),
75
78
  root: fileURLToPath(settings.config.root),
@@ -0,0 +1,36 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import * as http from 'http';
5
+ import type { AddressInfo } from 'net';
6
+ import type { AstroSettings, AstroUserConfig } from '../../@types/astro';
7
+ import nodeFs from 'fs';
8
+ import * as vite from 'vite';
9
+ import { LogOptions } from '../logger/core.js';
10
+ export interface Container {
11
+ fs: typeof nodeFs;
12
+ logging: LogOptions;
13
+ settings: AstroSettings;
14
+ viteConfig: vite.InlineConfig;
15
+ viteServer: vite.ViteDevServer;
16
+ resolvedRoot: string;
17
+ configFlag: string | undefined;
18
+ configFlagPath: string | undefined;
19
+ restartInFlight: boolean;
20
+ handle: (req: http.IncomingMessage, res: http.ServerResponse) => void;
21
+ close: () => Promise<void>;
22
+ }
23
+ export interface CreateContainerParams {
24
+ isRestart?: boolean;
25
+ logging?: LogOptions;
26
+ userConfig?: AstroUserConfig;
27
+ settings?: AstroSettings;
28
+ fs?: typeof nodeFs;
29
+ root?: string | URL;
30
+ configFlag?: string;
31
+ configFlagPath?: string;
32
+ }
33
+ export declare function createContainer(params?: CreateContainerParams): Promise<Container>;
34
+ export declare function startContainer({ settings, viteServer, logging, }: Container): Promise<AddressInfo>;
35
+ export declare function isStarted(container: Container): boolean;
36
+ export declare function runInContainer(params: CreateContainerParams, callback: (container: Container) => Promise<void> | void): Promise<void>;
@@ -0,0 +1,109 @@
1
+ import nodeFs from "fs";
2
+ import * as vite from "vite";
3
+ import {
4
+ runHookConfigDone,
5
+ runHookConfigSetup,
6
+ runHookServerDone,
7
+ runHookServerSetup,
8
+ runHookServerStart
9
+ } from "../../integrations/index.js";
10
+ import { createDefaultDevSettings, resolveRoot } from "../config/index.js";
11
+ import { createVite } from "../create-vite.js";
12
+ import { nodeLogDestination } from "../logger/node.js";
13
+ import { appendForwardSlash } from "../path.js";
14
+ import { apply as applyPolyfill } from "../polyfill.js";
15
+ const defaultLogging = {
16
+ dest: nodeLogDestination,
17
+ level: "error"
18
+ };
19
+ async function createContainer(params = {}) {
20
+ let {
21
+ isRestart = false,
22
+ logging = defaultLogging,
23
+ settings = await createDefaultDevSettings(params.userConfig, params.root),
24
+ fs = nodeFs
25
+ } = params;
26
+ applyPolyfill();
27
+ settings = await runHookConfigSetup({
28
+ settings,
29
+ command: "dev",
30
+ logging,
31
+ isRestart
32
+ });
33
+ const { host } = settings.config.server;
34
+ const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
35
+ const viteConfig = await createVite(
36
+ {
37
+ mode: "development",
38
+ server: { host },
39
+ optimizeDeps: {
40
+ include: rendererClientEntries
41
+ },
42
+ define: {
43
+ "import.meta.env.BASE_URL": settings.config.base ? `'${settings.config.base}'` : "undefined"
44
+ }
45
+ },
46
+ { settings, logging, mode: "dev", fs }
47
+ );
48
+ await runHookConfigDone({ settings, logging });
49
+ const viteServer = await vite.createServer(viteConfig);
50
+ runHookServerSetup({ config: settings.config, server: viteServer, logging });
51
+ const container = {
52
+ configFlag: params.configFlag,
53
+ configFlagPath: params.configFlagPath,
54
+ fs,
55
+ logging,
56
+ resolvedRoot: appendForwardSlash(resolveRoot(params.root)),
57
+ restartInFlight: false,
58
+ settings,
59
+ viteConfig,
60
+ viteServer,
61
+ handle(req, res) {
62
+ viteServer.middlewares.handle(req, res, Function.prototype);
63
+ },
64
+ close() {
65
+ return closeContainer(container);
66
+ }
67
+ };
68
+ return container;
69
+ }
70
+ async function closeContainer({ viteServer, settings, logging }) {
71
+ await viteServer.close();
72
+ await runHookServerDone({
73
+ config: settings.config,
74
+ logging
75
+ });
76
+ }
77
+ async function startContainer({
78
+ settings,
79
+ viteServer,
80
+ logging
81
+ }) {
82
+ const { port } = settings.config.server;
83
+ await viteServer.listen(port);
84
+ const devServerAddressInfo = viteServer.httpServer.address();
85
+ await runHookServerStart({
86
+ config: settings.config,
87
+ address: devServerAddressInfo,
88
+ logging
89
+ });
90
+ return devServerAddressInfo;
91
+ }
92
+ function isStarted(container) {
93
+ var _a;
94
+ return !!((_a = container.viteServer.httpServer) == null ? void 0 : _a.listening);
95
+ }
96
+ async function runInContainer(params, callback) {
97
+ const container = await createContainer(params);
98
+ try {
99
+ await callback(container);
100
+ } finally {
101
+ await container.close();
102
+ }
103
+ }
104
+ export {
105
+ createContainer,
106
+ isStarted,
107
+ runInContainer,
108
+ startContainer
109
+ };
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { AstroTelemetry } from '@astrojs/telemetry';
4
+ import type http from 'http';
5
+ import type { AddressInfo } from 'net';
6
+ import * as vite from 'vite';
7
+ import type { AstroSettings } from '../../@types/astro';
8
+ import { LogOptions } from '../logger/core.js';
9
+ export interface DevOptions {
10
+ configFlag: string | undefined;
11
+ configFlagPath: string | undefined;
12
+ logging: LogOptions;
13
+ telemetry: AstroTelemetry;
14
+ handleConfigError: (error: Error) => void;
15
+ isRestart?: boolean;
16
+ }
17
+ export interface DevServer {
18
+ address: AddressInfo;
19
+ handle: (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void;
20
+ watcher: vite.FSWatcher;
21
+ stop(): Promise<void>;
22
+ }
23
+ /** `astro dev` */
24
+ export default function dev(settings: AstroSettings, options: DevOptions): Promise<DevServer>;
@@ -0,0 +1,55 @@
1
+ import { performance } from "perf_hooks";
2
+ import { info, warn } from "../logger/core.js";
3
+ import * as msg from "../messages.js";
4
+ import { startContainer } from "./container.js";
5
+ import { createContainerWithAutomaticRestart } from "./restart.js";
6
+ async function dev(settings, options) {
7
+ var _a, _b;
8
+ const devStart = performance.now();
9
+ await options.telemetry.record([]);
10
+ const restart = await createContainerWithAutomaticRestart({
11
+ flags: {},
12
+ handleConfigError: options.handleConfigError,
13
+ beforeRestart: () => console.clear(),
14
+ params: {
15
+ settings,
16
+ logging: options.logging,
17
+ isRestart: options.isRestart
18
+ }
19
+ });
20
+ const devServerAddressInfo = await startContainer(restart.container);
21
+ const site = settings.config.site ? new URL(settings.config.base, settings.config.site) : void 0;
22
+ info(
23
+ options.logging,
24
+ null,
25
+ msg.serverStart({
26
+ startupTime: performance.now() - devStart,
27
+ resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
28
+ host: settings.config.server.host,
29
+ site,
30
+ isRestart: options.isRestart
31
+ })
32
+ );
33
+ const currentVersion = "1.6.3";
34
+ if (currentVersion.includes("-")) {
35
+ warn(options.logging, null, msg.prerelease({ currentVersion }));
36
+ }
37
+ if (((_b = (_a = restart.container.viteConfig.server) == null ? void 0 : _a.fs) == null ? void 0 : _b.strict) === false) {
38
+ warn(options.logging, null, msg.fsStrictWarning());
39
+ }
40
+ return {
41
+ address: devServerAddressInfo,
42
+ get watcher() {
43
+ return restart.container.viteServer.watcher;
44
+ },
45
+ handle(req, res) {
46
+ return restart.container.handle(req, res);
47
+ },
48
+ async stop() {
49
+ await restart.container.close();
50
+ }
51
+ };
52
+ }
53
+ export {
54
+ dev as default
55
+ };
@@ -1,18 +1,3 @@
1
- /// <reference types="node" />
2
- import type { AstroTelemetry } from '@astrojs/telemetry';
3
- import type { AddressInfo } from 'net';
4
- import * as vite from 'vite';
5
- import type { AstroSettings } from '../../@types/astro';
6
- import { LogOptions } from '../logger/core.js';
7
- export interface DevOptions {
8
- logging: LogOptions;
9
- telemetry: AstroTelemetry;
10
- isRestart?: boolean;
11
- }
12
- export interface DevServer {
13
- address: AddressInfo;
14
- watcher: vite.FSWatcher;
15
- stop(): Promise<void>;
16
- }
17
- /** `astro dev` */
18
- export default function dev(settings: AstroSettings, options: DevOptions): Promise<DevServer>;
1
+ export { createContainer, runInContainer, startContainer } from './container.js';
2
+ export { default } from './dev.js';
3
+ export { createContainerWithAutomaticRestart } from './restart.js';