astro 4.10.1 → 4.10.2

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.
@@ -1,7 +1,7 @@
1
- import type { UserConfig } from 'vite';
1
+ import type { UserConfig as ViteUserConfig } from 'vite';
2
2
  import type { AstroInlineConfig, AstroUserConfig } from '../@types/astro.js';
3
3
  export declare function defineConfig(config: AstroUserConfig): AstroUserConfig;
4
- export declare function getViteConfig(inlineConfig: UserConfig, inlineAstroConfig?: AstroInlineConfig): ({ mode, command }: {
4
+ export declare function getViteConfig(userViteConfig: ViteUserConfig, inlineAstroConfig?: AstroInlineConfig): ({ mode, command }: {
5
5
  mode: string;
6
6
  command: 'serve' | 'build';
7
7
  }) => Promise<Record<string, any>>;
@@ -2,7 +2,7 @@ import { Logger } from "../core/logger/core.js";
2
2
  function defineConfig(config) {
3
3
  return config;
4
4
  }
5
- function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
5
+ function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
6
6
  return async ({ mode, command }) => {
7
7
  const cmd = command === "serve" ? "dev" : command;
8
8
  const [
@@ -26,8 +26,8 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
26
26
  dest: nodeLogDestination,
27
27
  level: "info"
28
28
  });
29
- const { astroConfig: config, userConfig } = await resolveConfig(inlineAstroConfig, cmd);
30
- let settings = await createSettings(config, inlineConfig.root);
29
+ const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
30
+ let settings = await createSettings(config, userViteConfig.root);
31
31
  settings = await runHookConfigSetup({ settings, command: cmd, logger });
32
32
  const viteConfig = await createVite(
33
33
  {
@@ -40,7 +40,7 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
40
40
  { settings, logger, mode }
41
41
  );
42
42
  await runHookConfigDone({ settings, logger });
43
- return mergeConfig(viteConfig, userConfig);
43
+ return mergeConfig(viteConfig, userViteConfig);
44
44
  };
45
45
  }
46
46
  export {
@@ -5,7 +5,7 @@ export declare class ContainerPipeline extends Pipeline {
5
5
  static create({ logger, manifest, renderers, resolve, serverLike, streaming, }: Pick<ContainerPipeline, 'logger' | 'manifest' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'>): ContainerPipeline;
6
6
  componentMetadata(_routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
7
7
  headElements(routeData: RouteData): Promise<HeadElements> | HeadElements;
8
- tryRewrite(rewritePayload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
8
+ tryRewrite(payload: RewritePayload, request: Request): Promise<[RouteData, ComponentInstance, URL]>;
9
9
  insertRoute(route: RouteData, componentInstance: ComponentInstance): void;
10
10
  getComponentByRoute(_routeData: RouteData): Promise<ComponentInstance>;
11
11
  rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
@@ -5,7 +5,7 @@ import {
5
5
  createModuleScriptElement,
6
6
  createStylesheetElementSet
7
7
  } from "../core/render/ssr-element.js";
8
- import { default404Page } from "../core/routing/astro-designed-error-pages.js";
8
+ import { DEFAULT_404_ROUTE, default404Page } from "../core/routing/astro-designed-error-pages.js";
9
9
  class ContainerPipeline extends Pipeline {
10
10
  /**
11
11
  * Internal cache to store components instances by `RouteData`.
@@ -51,29 +51,28 @@ class ContainerPipeline extends Pipeline {
51
51
  }
52
52
  return { links, styles, scripts };
53
53
  }
54
- async tryRewrite(rewritePayload) {
54
+ async tryRewrite(payload, request) {
55
55
  let foundRoute;
56
+ let finalUrl = void 0;
56
57
  for (const route of this.manifest.routes) {
57
- const routeData = route.routeData;
58
- if (rewritePayload instanceof URL) {
59
- if (routeData.pattern.test(rewritePayload.pathname)) {
60
- foundRoute = routeData;
61
- break;
62
- }
63
- } else if (rewritePayload instanceof Request) {
64
- const url = new URL(rewritePayload.url);
65
- if (routeData.pattern.test(url.pathname)) {
66
- foundRoute = routeData;
67
- break;
68
- }
69
- } else if (routeData.pattern.test(decodeURI(rewritePayload))) {
70
- foundRoute = routeData;
58
+ if (payload instanceof URL) {
59
+ finalUrl = payload;
60
+ } else if (payload instanceof Request) {
61
+ finalUrl = new URL(payload.url);
62
+ } else {
63
+ finalUrl = new URL(payload, new URL(request.url).origin);
64
+ }
65
+ if (route.routeData.pattern.test(decodeURI(finalUrl.pathname))) {
66
+ foundRoute = route.routeData;
67
+ break;
68
+ } else if (finalUrl.pathname === "/404") {
69
+ foundRoute = DEFAULT_404_ROUTE;
71
70
  break;
72
71
  }
73
72
  }
74
- if (foundRoute) {
73
+ if (foundRoute && finalUrl) {
75
74
  const componentInstance = await this.getComponentByRoute(foundRoute);
76
- return [foundRoute, componentInstance];
75
+ return [foundRoute, componentInstance, finalUrl];
77
76
  } else {
78
77
  throw new AstroError(RouteNotFound);
79
78
  }
@@ -55,7 +55,7 @@ function createGetCollection({
55
55
  );
56
56
  let entries = [];
57
57
  if (!import.meta.env?.DEV && cacheEntriesByCollection.has(collection)) {
58
- entries = [...cacheEntriesByCollection.get(collection)];
58
+ entries = cacheEntriesByCollection.get(collection);
59
59
  } else {
60
60
  const limit = pLimit(10);
61
61
  entries = await Promise.all(
@@ -88,7 +88,7 @@ function createGetCollection({
88
88
  if (typeof filter === "function") {
89
89
  return entries.filter(filter);
90
90
  } else {
91
- return entries;
91
+ return entries.slice();
92
92
  }
93
93
  };
94
94
  }
@@ -72,16 +72,14 @@ async function createContentTypesGenerator({
72
72
  if (!isCollectionEvent) return { shouldGenerateTypes: false };
73
73
  switch (event.name) {
74
74
  case "addDir":
75
- collectionEntryMap[JSON.stringify(collection2)] = {
75
+ collectionEntryMap[collectionKey2] = {
76
76
  type: "unknown",
77
77
  entries: {}
78
78
  };
79
79
  logger.debug("content", `${cyan(collection2)} collection added`);
80
80
  break;
81
81
  case "unlinkDir":
82
- if (collectionKey2 in collectionEntryMap) {
83
- delete collectionEntryMap[JSON.stringify(collection2)];
84
- }
82
+ delete collectionEntryMap[collectionKey2];
85
83
  break;
86
84
  }
87
85
  return { shouldGenerateTypes: true };
@@ -13,7 +13,6 @@ import { AstroIntegrationLogger, Logger } from "../logger/core.js";
13
13
  import { sequence } from "../middleware/index.js";
14
14
  import {
15
15
  appendForwardSlash,
16
- collapseDuplicateSlashes,
17
16
  joinPaths,
18
17
  prependForwardSlash,
19
18
  removeTrailingForwardSlash
@@ -204,9 +203,6 @@ class App {
204
203
  if (clientAddress) {
205
204
  Reflect.set(request, clientAddressSymbol, clientAddress);
206
205
  }
207
- if (request.url !== collapseDuplicateSlashes(request.url)) {
208
- request = new Request(collapseDuplicateSlashes(request.url), request);
209
- }
210
206
  if (!routeData) {
211
207
  routeData = this.match(request);
212
208
  this.#logger.debug("router", "Astro matched the following route for " + request.url);
@@ -7,7 +7,7 @@ export declare class AppPipeline extends Pipeline {
7
7
  headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
8
8
  componentMetadata(): void;
9
9
  getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
10
- tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
10
+ tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance, URL]>;
11
11
  getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule>;
12
12
  rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
13
13
  }
@@ -64,8 +64,8 @@ class AppPipeline extends Pipeline {
64
64
  }
65
65
  async tryRewrite(payload, request, sourceRoute) {
66
66
  let foundRoute;
67
+ let finalUrl = void 0;
67
68
  for (const route of this.#manifestData.routes) {
68
- let finalUrl = void 0;
69
69
  if (payload instanceof URL) {
70
70
  finalUrl = payload;
71
71
  } else if (payload instanceof Request) {
@@ -81,13 +81,13 @@ class AppPipeline extends Pipeline {
81
81
  break;
82
82
  }
83
83
  }
84
- if (foundRoute) {
84
+ if (foundRoute && finalUrl) {
85
85
  if (foundRoute.pathname === "/404") {
86
86
  const componentInstance = this.rewriteKnownRoute(foundRoute.pathname, sourceRoute);
87
- return [foundRoute, componentInstance];
87
+ return [foundRoute, componentInstance, finalUrl];
88
88
  } else {
89
89
  const componentInstance = await this.getComponentByRoute(foundRoute);
90
- return [foundRoute, componentInstance];
90
+ return [foundRoute, componentInstance, finalUrl];
91
91
  }
92
92
  }
93
93
  throw new AstroError({
@@ -67,7 +67,7 @@ export declare abstract class Pipeline {
67
67
  * @param {Request} request The original request
68
68
  * @param {RouteData} sourceRoute The original `RouteData`
69
69
  */
70
- abstract tryRewrite(rewritePayload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
70
+ abstract tryRewrite(rewritePayload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance, URL]>;
71
71
  /**
72
72
  * Tells the pipeline how to retrieve a component give a `RouteData`
73
73
  * @param routeData
@@ -26,6 +26,7 @@ import { RenderContext } from "../render-context.js";
26
26
  import { callGetStaticPaths } from "../render/route-cache.js";
27
27
  import { createRequest } from "../request.js";
28
28
  import { matchRoute } from "../routing/match.js";
29
+ import { stringifyParams } from "../routing/params.js";
29
30
  import { getOutputFilename, isServerLikeOutput } from "../util.js";
30
31
  import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
31
32
  import { cssOrder, mergeInlineCss } from "./internal.js";
@@ -212,7 +213,7 @@ async function getPathsForRoute(route, mod, pipeline, builtPaths) {
212
213
  );
213
214
  paths = staticPaths.map((staticPath) => {
214
215
  try {
215
- return route.generate(staticPath.params);
216
+ return stringifyParams(staticPath.params, route);
216
217
  } catch (e) {
217
218
  if (e instanceof TypeError) {
218
219
  throw getInvalidRouteSegmentError(e, route, staticPath);
@@ -38,7 +38,7 @@ export declare class BuildPipeline extends Pipeline {
38
38
  */
39
39
  retrieveRoutesToGenerate(): Map<PageBuildData, string>;
40
40
  getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
41
- tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
41
+ tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance, URL]>;
42
42
  retrieveSsrEntry(route: RouteData, filePath: string): Promise<SinglePageBuiltModule>;
43
43
  rewriteKnownRoute(_pathname: string, sourceRoute: RouteData): ComponentInstance;
44
44
  }
@@ -209,8 +209,8 @@ class BuildPipeline extends Pipeline {
209
209
  }
210
210
  async tryRewrite(payload, request, sourceRoute) {
211
211
  let foundRoute;
212
+ let finalUrl = void 0;
212
213
  for (const route of this.options.manifest.routes) {
213
- let finalUrl = void 0;
214
214
  if (payload instanceof URL) {
215
215
  finalUrl = payload;
216
216
  } else if (payload instanceof Request) {
@@ -226,13 +226,13 @@ class BuildPipeline extends Pipeline {
226
226
  break;
227
227
  }
228
228
  }
229
- if (foundRoute) {
229
+ if (foundRoute && finalUrl) {
230
230
  if (foundRoute.pathname === "/404") {
231
231
  const componentInstance = await this.rewriteKnownRoute(foundRoute.pathname, sourceRoute);
232
- return [foundRoute, componentInstance];
232
+ return [foundRoute, componentInstance, finalUrl];
233
233
  } else {
234
234
  const componentInstance = await this.getComponentByRoute(foundRoute);
235
- return [foundRoute, componentInstance];
235
+ return [foundRoute, componentInstance, finalUrl];
236
236
  }
237
237
  } else {
238
238
  throw new AstroError({