astro 2.8.2 → 2.8.4

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 (111) hide show
  1. package/components/Code.astro +1 -1
  2. package/dist/@types/astro.d.ts +2 -2
  3. package/dist/assets/consts.d.ts +4 -4
  4. package/dist/assets/consts.js +11 -3
  5. package/dist/assets/index.d.ts +0 -2
  6. package/dist/assets/index.js +0 -4
  7. package/dist/assets/services/service.d.ts +1 -1
  8. package/dist/assets/services/service.js +6 -3
  9. package/dist/assets/services/sharp.js +3 -0
  10. package/dist/assets/services/squoosh.js +25 -0
  11. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +3 -3
  12. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +3 -3
  13. package/dist/assets/services/vendor/squoosh/image-pool.js +2 -2
  14. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +3 -3
  15. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +3 -3
  16. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +3 -3
  17. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +3 -3
  18. package/dist/assets/types.d.ts +1 -0
  19. package/dist/assets/utils/emitAsset.d.ts +2 -2
  20. package/dist/assets/utils/metadata.d.ts +1 -4
  21. package/dist/assets/utils/transformToPath.js +1 -1
  22. package/dist/assets/vendor/image-size/index.js +2 -2
  23. package/dist/assets/vendor/image-size/types/tiff.js +1 -1
  24. package/dist/cli/add/index.d.ts +1 -2
  25. package/dist/cli/add/index.js +7 -4
  26. package/dist/cli/check/index.d.ts +1 -1
  27. package/dist/cli/check/index.js +2 -2
  28. package/dist/cli/check/print.js +1 -1
  29. package/dist/cli/dev/index.js +1 -1
  30. package/dist/cli/index.js +8 -28
  31. package/dist/cli/info/index.d.ts +1 -2
  32. package/dist/cli/info/index.js +2 -2
  33. package/dist/cli/load-settings.js +1 -1
  34. package/dist/cli/sync/index.js +1 -1
  35. package/dist/cli/throw-and-exit.d.ts +2 -0
  36. package/dist/cli/throw-and-exit.js +21 -0
  37. package/dist/config/index.js +1 -1
  38. package/dist/content/runtime-assets.d.ts +1 -1
  39. package/dist/content/runtime-assets.js +1 -1
  40. package/dist/content/vite-plugin-content-imports.js +1 -1
  41. package/dist/core/app/index.d.ts +3 -1
  42. package/dist/core/app/index.js +33 -47
  43. package/dist/core/app/node.d.ts +1 -1
  44. package/dist/core/app/node.js +3 -3
  45. package/dist/core/build/common.js +2 -2
  46. package/dist/core/build/css-asset-name.js +2 -2
  47. package/dist/core/build/generate.d.ts +1 -1
  48. package/dist/core/build/generate.js +21 -43
  49. package/dist/core/build/index.js +9 -2
  50. package/dist/core/build/static-build.js +8 -6
  51. package/dist/core/compile/compile.js +1 -1
  52. package/dist/core/compile/style.js +1 -1
  53. package/dist/core/config/config.d.ts +1 -1
  54. package/dist/core/config/config.js +16 -22
  55. package/dist/core/config/merge.js +10 -0
  56. package/dist/core/config/schema.d.ts +1 -1
  57. package/dist/core/config/schema.js +1 -6
  58. package/dist/core/config/settings.js +1 -1
  59. package/dist/core/config/timer.js +1 -1
  60. package/dist/core/config/tsconfig.js +2 -2
  61. package/dist/core/config/vite-load.d.ts +1 -1
  62. package/dist/core/config/vite-load.js +1 -1
  63. package/dist/core/constants.js +1 -1
  64. package/dist/core/create-vite.d.ts +1 -1
  65. package/dist/core/create-vite.js +2 -2
  66. package/dist/core/dev/container.d.ts +3 -3
  67. package/dist/core/dev/container.js +1 -1
  68. package/dist/core/dev/dev.d.ts +2 -2
  69. package/dist/core/dev/dev.js +1 -1
  70. package/dist/core/errors/dev/vite.js +2 -2
  71. package/dist/core/errors/errors-data.d.ts +1 -1
  72. package/dist/core/errors/errors-data.js +2 -2
  73. package/dist/core/fs/index.js +4 -4
  74. package/dist/core/logger/node.d.ts +1 -1
  75. package/dist/core/logger/node.js +2 -2
  76. package/dist/core/messages.js +2 -2
  77. package/dist/core/module-loader/loader.d.ts +1 -1
  78. package/dist/core/module-loader/loader.js +1 -1
  79. package/dist/core/module-loader/vite.js +1 -1
  80. package/dist/core/preview/index.js +1 -1
  81. package/dist/core/preview/static-preview-server.d.ts +1 -1
  82. package/dist/core/preview/static-preview-server.js +1 -1
  83. package/dist/core/preview/vite-plugin-astro-preview.js +2 -2
  84. package/dist/core/render/core.d.ts +9 -2
  85. package/dist/core/render/core.js +34 -1
  86. package/dist/core/render/dev/environment.d.ts +2 -2
  87. package/dist/core/render/dev/environment.js +6 -7
  88. package/dist/core/render/dev/index.js +3 -29
  89. package/dist/core/render/dev/vite.js +1 -1
  90. package/dist/core/render/index.d.ts +1 -1
  91. package/dist/core/render/index.js +2 -2
  92. package/dist/core/request.d.ts +1 -1
  93. package/dist/core/routing/manifest/create.d.ts +1 -1
  94. package/dist/core/routing/manifest/create.js +22 -3
  95. package/dist/core/util.js +3 -3
  96. package/dist/integrations/index.d.ts +1 -1
  97. package/dist/vite-plugin-astro-server/base.js +1 -1
  98. package/dist/vite-plugin-astro-server/plugin.d.ts +10 -2
  99. package/dist/vite-plugin-astro-server/plugin.js +34 -9
  100. package/dist/vite-plugin-astro-server/request.d.ts +12 -3
  101. package/dist/vite-plugin-astro-server/request.js +23 -15
  102. package/dist/vite-plugin-astro-server/response.d.ts +1 -1
  103. package/dist/vite-plugin-astro-server/route.d.ts +15 -3
  104. package/dist/vite-plugin-astro-server/route.js +32 -20
  105. package/dist/vite-plugin-config-alias/index.js +1 -1
  106. package/dist/vite-plugin-env/index.js +5 -2
  107. package/dist/vite-plugin-jsx/index.js +1 -1
  108. package/dist/vite-plugin-load-fallback/index.d.ts +1 -1
  109. package/dist/vite-plugin-load-fallback/index.js +2 -2
  110. package/dist/vite-plugin-utils/index.js +1 -1
  111. package/package.json +3 -3
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { emitESMImage } from "../assets/index.js";
2
+ import { emitESMImage } from "../assets/utils/emitAsset.js";
3
3
  function createImage(pluginContext, entryFilePath) {
4
4
  return () => {
5
5
  return z.string().transform(async (imagePath, ctx) => {
@@ -1,6 +1,6 @@
1
1
  import * as devalue from "devalue";
2
2
  import { extname } from "node:path";
3
- import { pathToFileURL } from "url";
3
+ import { pathToFileURL } from "node:url";
4
4
  import { AstroErrorData } from "../core/errors/errors-data.js";
5
5
  import { AstroError } from "../core/errors/errors.js";
6
6
  import { escapeViteEnvReferences } from "../vite-plugin-utils/index.js";
@@ -1,4 +1,4 @@
1
- import type { RouteData, SSRManifest } from '../../@types/astro';
1
+ import type { ManifestData, RouteData, SSRManifest } from '../../@types/astro';
2
2
  export { deserializeManifest } from './common.js';
3
3
  export interface MatchOptions {
4
4
  matchNotFound?: boolean | undefined;
@@ -6,6 +6,8 @@ export interface MatchOptions {
6
6
  export declare class App {
7
7
  #private;
8
8
  constructor(manifest: SSRManifest, streaming?: boolean);
9
+ set setManifest(newManifest: SSRManifest);
10
+ set setManifestData(newManifestData: ManifestData);
9
11
  removeBase(pathname: string): string;
10
12
  match(request: Request, { matchNotFound }?: MatchOptions): RouteData | undefined;
11
13
  render(request: Request, routeData?: RouteData, locals?: object): Promise<Response>;
@@ -1,15 +1,14 @@
1
1
  import mime from "mime";
2
2
  import { attachToResponse, getSetCookiesFromResponse } from "../cookies/index.js";
3
- import { callEndpoint, createAPIContext } from "../endpoint/index.js";
3
+ import { callEndpoint } from "../endpoint/index.js";
4
4
  import { consoleLogDestination } from "../logger/console.js";
5
5
  import { error } from "../logger/core.js";
6
- import { callMiddleware } from "../middleware/callMiddleware.js";
7
6
  import { prependForwardSlash, removeTrailingForwardSlash } from "../path.js";
8
7
  import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
9
8
  import {
10
9
  createEnvironment,
11
10
  createRenderContext,
12
- renderPage
11
+ tryRenderPage
13
12
  } from "../render/index.js";
14
13
  import { RouteCache } from "../render/route-cache.js";
15
14
  import {
@@ -22,6 +21,9 @@ import { deserializeManifest } from "./common.js";
22
21
  const clientLocalsSymbol = Symbol.for("astro.locals");
23
22
  const responseSentSymbol = Symbol.for("astro.responseSent");
24
23
  class App {
24
+ /**
25
+ * The current environment of the application
26
+ */
25
27
  #env;
26
28
  #manifest;
27
29
  #manifestData;
@@ -31,7 +33,6 @@ class App {
31
33
  dest: consoleLogDestination,
32
34
  level: "info"
33
35
  };
34
- #base;
35
36
  #baseWithoutTrailingSlash;
36
37
  constructor(manifest, streaming = true) {
37
38
  this.#manifest = manifest;
@@ -39,26 +40,39 @@ class App {
39
40
  routes: manifest.routes.map((route) => route.routeData)
40
41
  };
41
42
  this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route]));
42
- this.#env = createEnvironment({
43
- adapterName: manifest.adapterName,
43
+ this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
44
+ this.#env = this.#createEnvironment(streaming);
45
+ }
46
+ set setManifest(newManifest) {
47
+ this.#manifest = newManifest;
48
+ }
49
+ /**
50
+ * Creates an environment by reading the stored manifest
51
+ *
52
+ * @param streaming
53
+ * @private
54
+ */
55
+ #createEnvironment(streaming = false) {
56
+ return createEnvironment({
57
+ adapterName: this.#manifest.adapterName,
44
58
  logging: this.#logging,
45
- markdown: manifest.markdown,
59
+ markdown: this.#manifest.markdown,
46
60
  mode: "production",
47
- compressHTML: manifest.compressHTML,
48
- renderers: manifest.renderers,
49
- clientDirectives: manifest.clientDirectives,
50
- async resolve(specifier) {
51
- if (!(specifier in manifest.entryModules)) {
61
+ compressHTML: this.#manifest.compressHTML,
62
+ renderers: this.#manifest.renderers,
63
+ clientDirectives: this.#manifest.clientDirectives,
64
+ resolve: async (specifier) => {
65
+ if (!(specifier in this.#manifest.entryModules)) {
52
66
  throw new Error(`Unable to resolve [${specifier}]`);
53
67
  }
54
- const bundlePath = manifest.entryModules[specifier];
68
+ const bundlePath = this.#manifest.entryModules[specifier];
55
69
  switch (true) {
56
70
  case bundlePath.startsWith("data:"):
57
71
  case bundlePath.length === 0: {
58
72
  return bundlePath;
59
73
  }
60
74
  default: {
61
- return createAssetLink(bundlePath, manifest.base, manifest.assetsPrefix);
75
+ return createAssetLink(bundlePath, this.#manifest.base, this.#manifest.assetsPrefix);
62
76
  }
63
77
  }
64
78
  },
@@ -67,11 +81,12 @@ class App {
67
81
  ssr: true,
68
82
  streaming
69
83
  });
70
- this.#base = this.#manifest.base || "/";
71
- this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#base);
84
+ }
85
+ set setManifestData(newManifestData) {
86
+ this.#manifestData = newManifestData;
72
87
  }
73
88
  removeBase(pathname) {
74
- if (pathname.startsWith(this.#base)) {
89
+ if (pathname.startsWith(this.#manifest.base)) {
75
90
  return pathname.slice(this.#baseWithoutTrailingSlash.length + 1);
76
91
  }
77
92
  return pathname;
@@ -200,36 +215,7 @@ class App {
200
215
  mod,
201
216
  env: this.#env
202
217
  });
203
- const apiContext = createAPIContext({
204
- request: renderContext.request,
205
- params: renderContext.params,
206
- props: renderContext.props,
207
- site: this.#env.site,
208
- adapterName: this.#env.adapterName
209
- });
210
- let response;
211
- if (page.onRequest) {
212
- response = await callMiddleware(
213
- this.#env.logging,
214
- page.onRequest,
215
- apiContext,
216
- () => {
217
- return renderPage({
218
- mod,
219
- renderContext,
220
- env: this.#env,
221
- cookies: apiContext.cookies
222
- });
223
- }
224
- );
225
- } else {
226
- response = await renderPage({
227
- mod,
228
- renderContext,
229
- env: this.#env,
230
- cookies: apiContext.cookies
231
- });
232
- }
218
+ const response = await tryRenderPage(renderContext, this.#env, mod, page.onRequest);
233
219
  Reflect.set(request, responseSentSymbol, true);
234
220
  return response;
235
221
  } catch (err) {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { RouteData } from '../../@types/astro';
3
3
  import type { SSRManifest } from './types';
4
- import { IncomingMessage } from 'http';
4
+ import { IncomingMessage } from 'node:http';
5
5
  import { App, type MatchOptions } from './index.js';
6
6
  declare class NodeIncomingMessage extends IncomingMessage {
7
7
  /**
@@ -1,6 +1,6 @@
1
- import * as fs from "fs";
2
- import { IncomingMessage } from "http";
3
- import { TLSSocket } from "tls";
1
+ import * as fs from "node:fs";
2
+ import { IncomingMessage } from "node:http";
3
+ import { TLSSocket } from "node:tls";
4
4
  import { deserializeManifest } from "./common.js";
5
5
  import { App } from "./index.js";
6
6
  const clientAddressSymbol = Symbol.for("astro.clientAddress");
@@ -1,5 +1,5 @@
1
- import npath from "path";
2
- import { fileURLToPath, pathToFileURL } from "url";
1
+ import npath from "node:path";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import { appendForwardSlash } from "../../core/path.js";
4
4
  const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
5
5
  const FALLBACK_OUT_DIR_NAME = "./.astro/";
@@ -1,5 +1,5 @@
1
- import crypto from "crypto";
2
- import npath from "path";
1
+ import crypto from "node:crypto";
2
+ import npath from "node:path";
3
3
  import { viteID } from "../util.js";
4
4
  import { getTopLevelPages } from "./graph.js";
5
5
  function shortHashedName(id, ctx) {
@@ -12,4 +12,4 @@ export declare function generatePages(opts: StaticBuildOptions, internals: Build
12
12
  * @param settings
13
13
  * @param renderers
14
14
  */
15
- export declare function generateRuntimeManifest(settings: AstroSettings, internals: BuildInternals, renderers: SSRLoadedRenderer[]): SSRManifest;
15
+ export declare function createBuildManifest(settings: AstroSettings, internals: BuildInternals, renderers: SSRLoadedRenderer[]): SSRManifest;
@@ -1,7 +1,7 @@
1
- import fs from "fs";
2
1
  import * as colors from "kleur/colors";
3
2
  import { bgGreen, black, cyan, dim, green, magenta } from "kleur/colors";
4
- import { fileURLToPath } from "url";
3
+ import fs from "node:fs";
4
+ import { fileURLToPath } from "node:url";
5
5
  import {
6
6
  generateImage as generateImageInternal,
7
7
  getStaticImageList
@@ -20,16 +20,15 @@ import {
20
20
  import { runHookBuildGenerated } from "../../integrations/index.js";
21
21
  import { isServerLikeOutput } from "../../prerender/utils.js";
22
22
  import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
23
- import { callEndpoint, createAPIContext, throwIfRedirectNotAllowed } from "../endpoint/index.js";
23
+ import { callEndpoint, throwIfRedirectNotAllowed } from "../endpoint/index.js";
24
24
  import { AstroError, AstroErrorData } from "../errors/index.js";
25
25
  import { debug, info } from "../logger/core.js";
26
- import { callMiddleware } from "../middleware/callMiddleware.js";
27
26
  import {
28
27
  getRedirectLocationOrThrow,
29
28
  RedirectSinglePageBuiltModule,
30
29
  routeIsRedirect
31
30
  } from "../redirects/index.js";
32
- import { createEnvironment, createRenderContext, renderPage } from "../render/index.js";
31
+ import { createEnvironment, createRenderContext, tryRenderPage } from "../render/index.js";
33
32
  import { callGetStaticPaths } from "../render/route-cache.js";
34
33
  import {
35
34
  createAssetLink,
@@ -115,26 +114,26 @@ ${bgGreen(black(` ${verb} static routes `))}`);
115
114
  }
116
115
  } else {
117
116
  const ssrEntry = ssrEntryPage;
118
- const manifest = generateRuntimeManifest(opts.settings, internals, ssrEntry.renderers);
117
+ const manifest = createBuildManifest(opts.settings, internals, ssrEntry.renderers);
119
118
  await generatePage(opts, internals, pageData, ssrEntry, builtPaths, manifest);
120
119
  }
121
120
  }
122
121
  }
123
122
  for (const pageData of eachRedirectPageData(internals)) {
124
123
  const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
125
- const manifest = generateRuntimeManifest(opts.settings, internals, entry.renderers);
124
+ const manifest = createBuildManifest(opts.settings, internals, entry.renderers);
126
125
  await generatePage(opts, internals, pageData, entry, builtPaths, manifest);
127
126
  }
128
127
  } else {
129
128
  for (const [pageData, filePath] of eachPageDataFromEntryPoint(internals)) {
130
129
  const ssrEntryURLPage = createEntryURL(filePath, outFolder);
131
130
  const entry = await import(ssrEntryURLPage.toString());
132
- const manifest = generateRuntimeManifest(opts.settings, internals, entry.renderers);
131
+ const manifest = createBuildManifest(opts.settings, internals, entry.renderers);
133
132
  await generatePage(opts, internals, pageData, entry, builtPaths, manifest);
134
133
  }
135
134
  for (const pageData of eachRedirectPageData(internals)) {
136
135
  const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
137
- const manifest = generateRuntimeManifest(opts.settings, internals, entry.renderers);
136
+ const manifest = createBuildManifest(opts.settings, internals, entry.renderers);
138
137
  await generatePage(opts, internals, pageData, entry, builtPaths, manifest);
139
138
  }
140
139
  }
@@ -373,7 +372,7 @@ async function generatePath(pathname, opts, gopts, manifest, onRequest) {
373
372
  clientDirectives: manifest.clientDirectives,
374
373
  compressHTML: manifest.compressHTML,
375
374
  async resolve(specifier) {
376
- const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
375
+ const hashedFilePath = manifest.entryModules[specifier];
377
376
  if (typeof hashedFilePath !== "string") {
378
377
  if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
379
378
  return "";
@@ -421,35 +420,7 @@ async function generatePath(pathname, opts, gopts, manifest, onRequest) {
421
420
  } else {
422
421
  let response;
423
422
  try {
424
- const apiContext = createAPIContext({
425
- request: renderContext.request,
426
- params: renderContext.params,
427
- props: renderContext.props,
428
- site: env.site,
429
- adapterName: env.adapterName
430
- });
431
- if (onRequest) {
432
- response = await callMiddleware(
433
- env.logging,
434
- onRequest,
435
- apiContext,
436
- () => {
437
- return renderPage({
438
- mod,
439
- renderContext,
440
- env,
441
- cookies: apiContext.cookies
442
- });
443
- }
444
- );
445
- } else {
446
- response = await renderPage({
447
- mod,
448
- renderContext,
449
- env,
450
- cookies: apiContext.cookies
451
- });
452
- }
423
+ response = await tryRenderPage(renderContext, env, mod, onRequest);
453
424
  } catch (err) {
454
425
  if (!AstroError.is(err) && !err.id && typeof err === "object") {
455
426
  err.id = pageData.component;
@@ -461,9 +432,16 @@ async function generatePath(pathname, opts, gopts, manifest, onRequest) {
461
432
  return;
462
433
  }
463
434
  const location = getRedirectLocationOrThrow(response.headers);
435
+ const fromPath = new URL(renderContext.request.url).pathname;
436
+ const delay = response.status === 302 ? 2 : 0;
464
437
  body = `<!doctype html>
465
438
  <title>Redirecting to: ${location}</title>
466
- <meta http-equiv="refresh" content="0;url=${location}" />`;
439
+ <meta http-equiv="refresh" content="${delay};url=${location}">
440
+ <meta name="robots" content="noindex">
441
+ <link rel="canonical" href="${location}">
442
+ <body>
443
+ <a href="${location}">Redirecting from <code>${fromPath}</code> to <code>${location}</code></a>
444
+ </body>`;
467
445
  if (pageData.route.type !== "redirect") {
468
446
  pageData.route.redirect = location;
469
447
  }
@@ -479,10 +457,10 @@ async function generatePath(pathname, opts, gopts, manifest, onRequest) {
479
457
  await fs.promises.mkdir(outFolder, { recursive: true });
480
458
  await fs.promises.writeFile(outFile, body, encoding ?? "utf-8");
481
459
  }
482
- function generateRuntimeManifest(settings, internals, renderers) {
460
+ function createBuildManifest(settings, internals, renderers) {
483
461
  return {
484
462
  assets: /* @__PURE__ */ new Set(),
485
- entryModules: {},
463
+ entryModules: Object.fromEntries(internals.entrySpecifierToBundleMap.entries()),
486
464
  routes: [],
487
465
  adapterName: "",
488
466
  markdown: settings.config.markdown,
@@ -497,7 +475,7 @@ function generateRuntimeManifest(settings, internals, renderers) {
497
475
  }
498
476
  export {
499
477
  chunkIsPage,
478
+ createBuildManifest,
500
479
  generatePages,
501
- generateRuntimeManifest,
502
480
  rootRelativeFacadeId
503
481
  };
@@ -1,6 +1,6 @@
1
- import fs from "fs";
2
1
  import * as colors from "kleur/colors";
3
- import { performance } from "perf_hooks";
2
+ import fs from "node:fs";
3
+ import { performance } from "node:perf_hooks";
4
4
  import {
5
5
  runHookBuildDone,
6
6
  runHookBuildStart,
@@ -176,6 +176,13 @@ class AstroBuilder {
176
176
  );
177
177
  }
178
178
  }
179
+ if (config.build.split === true) {
180
+ if (config.output !== "server") {
181
+ throw new Error(
182
+ 'The option `build.split` can only be used when `output` is set to `"server"`.'
183
+ );
184
+ }
185
+ }
179
186
  }
180
187
  /** Stats */
181
188
  async printStats({
@@ -1,11 +1,10 @@
1
1
  import { teardown } from "@astrojs/compiler";
2
2
  import * as eslexer from "es-module-lexer";
3
3
  import glob from "fast-glob";
4
- import fs from "fs";
5
4
  import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
6
- import { extname } from "node:path";
7
- import path from "path";
8
- import { fileURLToPath } from "url";
5
+ import fs from "node:fs";
6
+ import path, { extname } from "node:path";
7
+ import { fileURLToPath } from "node:url";
9
8
  import * as vite from "vite";
10
9
  import {
11
10
  createBuildInternals,
@@ -19,6 +18,7 @@ import { isServerLikeOutput } from "../../prerender/utils.js";
19
18
  import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
20
19
  import { AstroError, AstroErrorData } from "../errors/index.js";
21
20
  import { info } from "../logger/core.js";
21
+ import { routeIsRedirect } from "../redirects/index.js";
22
22
  import { getOutDirWithinCwd } from "./common.js";
23
23
  import { generatePages } from "./generate.js";
24
24
  import { trackPageData } from "./internal.js";
@@ -43,8 +43,10 @@ async function viteBuild(opts) {
43
43
  const astroModuleURL = new URL("./" + component, settings.config.root);
44
44
  const astroModuleId = prependForwardSlash(component);
45
45
  trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
46
- pageInput.add(astroModuleId);
47
- facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
46
+ if (!routeIsRedirect(pageData.route)) {
47
+ pageInput.add(astroModuleId);
48
+ facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
49
+ }
48
50
  }
49
51
  if (((_c = (_b = (_a = settings.config) == null ? void 0 : _a.vite) == null ? void 0 : _b.build) == null ? void 0 : _c.emptyOutDir) !== false) {
50
52
  emptyDir(settings.config.outDir, new Set(".git"));
@@ -1,5 +1,5 @@
1
1
  import { transform } from "@astrojs/compiler";
2
- import { fileURLToPath } from "url";
2
+ import { fileURLToPath } from "node:url";
3
3
  import { normalizePath } from "vite";
4
4
  import { AggregateError, CompilerError } from "../errors/errors.js";
5
5
  import { AstroErrorData } from "../errors/index.js";
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import fs from "node:fs";
2
2
  import { preprocessCSS } from "vite";
3
3
  import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
4
4
  function createStylePreprocessor({
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { Arguments as Flags } from 'yargs-parser';
3
3
  import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
4
- import fs from 'fs';
4
+ import fs from 'node:fs';
5
5
  export declare const LEGACY_ASTRO_CONFIG_KEYS: Set<string>;
6
6
  /** Turn raw config values into normalized values */
7
7
  export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
@@ -1,8 +1,9 @@
1
- import fs from "fs";
2
1
  import * as colors from "kleur/colors";
3
- import path from "path";
4
- import { fileURLToPath, pathToFileURL } from "url";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  import { AstroError, AstroErrorData } from "../errors/index.js";
6
+ import { mergeConfig } from "./merge.js";
6
7
  import { createRelativeSchema } from "./schema.js";
7
8
  import { loadConfigWithVite } from "./vite-load.js";
8
9
  const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
@@ -84,25 +85,18 @@ function resolveRoot(cwd) {
84
85
  return cwd ? path.resolve(cwd) : process.cwd();
85
86
  }
86
87
  function mergeCLIFlags(astroConfig, flags) {
87
- astroConfig.server = astroConfig.server || {};
88
- astroConfig.markdown = astroConfig.markdown || {};
89
- astroConfig.experimental = astroConfig.experimental || {};
90
- if (typeof flags.site === "string")
91
- astroConfig.site = flags.site;
92
- if (typeof flags.base === "string")
93
- astroConfig.base = flags.base;
94
- if (typeof flags.drafts === "boolean")
95
- astroConfig.markdown.drafts = flags.drafts;
96
- if (typeof flags.port === "number") {
97
- astroConfig.server.port = flags.port;
98
- }
99
- if (typeof flags.host === "string" || typeof flags.host === "boolean") {
100
- astroConfig.server.host = flags.host;
101
- }
102
- if (typeof flags.open === "boolean") {
103
- astroConfig.server.open = flags.open;
104
- }
105
- return astroConfig;
88
+ return mergeConfig(astroConfig, {
89
+ site: flags.site,
90
+ base: flags.base,
91
+ markdown: {
92
+ drafts: flags.drafts
93
+ },
94
+ server: {
95
+ port: flags.port,
96
+ host: flags.host,
97
+ open: flags.open
98
+ }
99
+ });
106
100
  }
107
101
  async function search(fsMod, root) {
108
102
  const paths = [
@@ -16,6 +16,16 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
16
16
  merged[key] = mergeViteConfig(existing, value);
17
17
  continue;
18
18
  }
19
+ if (key === "server" && rootPath === "") {
20
+ if (typeof existing === "function" || typeof value === "function") {
21
+ merged[key] = (...args) => {
22
+ const existingConfig = typeof existing === "function" ? existing(...args) : existing;
23
+ const valueConfig = typeof value === "function" ? value(...args) : value;
24
+ return mergeConfigRecursively(existingConfig, valueConfig, key);
25
+ };
26
+ continue;
27
+ }
28
+ }
19
29
  if (Array.isArray(existing) || Array.isArray(value)) {
20
30
  merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
21
31
  continue;
@@ -2,7 +2,7 @@
2
2
  import type { RehypePlugin, RemarkPlugin, RemarkRehype } from '@astrojs/markdown-remark';
3
3
  import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
4
4
  import type { ViteUserConfig } from '../../@types/astro';
5
- import type { OutgoingHttpHeaders } from 'http';
5
+ import type { OutgoingHttpHeaders } from 'node:http';
6
6
  import { z } from 'zod';
7
7
  export declare const AstroConfigSchema: z.ZodObject<{
8
8
  root: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
@@ -171,12 +171,7 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
171
171
  // preprocess
172
172
  (val) => {
173
173
  if (typeof val === "function") {
174
- const result = val({ command: cmd === "dev" ? "dev" : "preview" });
175
- if (val.port)
176
- result.port = val.port;
177
- if (val.host)
178
- result.host = val.host;
179
- return result;
174
+ return val({ command: cmd === "dev" ? "dev" : "preview" });
180
175
  } else {
181
176
  return val;
182
177
  }
@@ -1,6 +1,6 @@
1
1
  import yaml from "js-yaml";
2
2
  import path from "node:path";
3
- import { fileURLToPath, pathToFileURL } from "url";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import { getContentPaths } from "../../content/index.js";
5
5
  import jsxRenderer from "../../jsx/renderer.js";
6
6
  import { isServerLikeOutput } from "../../prerender/utils.js";
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import fs from "node:fs";
2
2
  class AstroTimer {
3
3
  constructor() {
4
4
  this.ongoingTimers = /* @__PURE__ */ new Map();
@@ -1,6 +1,6 @@
1
1
  import { deepmerge } from "deepmerge-ts";
2
- import { existsSync } from "fs";
3
- import { join } from "path";
2
+ import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
4
  import * as tsr from "tsconfig-resolver";
5
5
  const defaultTSConfig = { extends: "astro/tsconfigs/base" };
6
6
  const presets = /* @__PURE__ */ new Map([
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type fsType from 'fs';
2
+ import type fsType from 'node:fs';
3
3
  interface LoadConfigWithViteOptions {
4
4
  root: string;
5
5
  configPath: string;
@@ -1,4 +1,4 @@
1
- import { pathToFileURL } from "url";
1
+ import { pathToFileURL } from "node:url";
2
2
  import { createServer } from "vite";
3
3
  import loadFallbackPlugin from "../../vite-plugin-load-fallback/index.js";
4
4
  import { debug } from "../logger/core.js";
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.8.2";
1
+ const ASTRO_VERSION = "2.8.4";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { AstroSettings } from '../@types/astro';
3
3
  import type { LogOptions } from './logger/core';
4
- import nodeFs from 'fs';
4
+ import nodeFs from 'node:fs';
5
5
  import * as vite from 'vite';
6
6
  interface CreateViteOptions {
7
7
  settings: AstroSettings;
@@ -1,5 +1,5 @@
1
- import nodeFs from "fs";
2
- import { fileURLToPath } from "url";
1
+ import nodeFs from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
3
  import * as vite from "vite";
4
4
  import { crawlFrameworkPkgs } from "vitefu";
5
5
  import astroAssetsPlugin from "../assets/vite-plugin-assets.js";
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
- import type * as http from 'http';
5
- import type { AddressInfo } from 'net';
4
+ import type * as http from 'node:http';
5
+ import type { AddressInfo } from 'node:net';
6
6
  import type { AstroSettings, AstroUserConfig } from '../../@types/astro';
7
- import nodeFs from 'fs';
7
+ import nodeFs from 'node:fs';
8
8
  import * as vite from 'vite';
9
9
  import type { LogOptions } from '../logger/core.js';
10
10
  export interface Container {
@@ -1,4 +1,4 @@
1
- import nodeFs from "fs";
1
+ import nodeFs from "node:fs";
2
2
  import * as vite from "vite";
3
3
  import {
4
4
  runHookConfigDone,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import type http from 'http';
4
- import type { AddressInfo } from 'net';
3
+ import type http from 'node:http';
4
+ import type { AddressInfo } from 'node:net';
5
5
  import type * as vite from 'vite';
6
6
  import type yargs from 'yargs-parser';
7
7
  import type { AstroSettings } from '../../@types/astro';