astro 4.16.13 → 4.16.15

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.
@@ -83,6 +83,8 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env, q
83
83
  async function generateImageInternal(filepath, options) {
84
84
  const isLocalImage = isESMImportedImage(options.src);
85
85
  const finalFileURL = new URL("." + filepath, env.clientRoot);
86
+ const finalFolderURL = new URL("./", finalFileURL);
87
+ await fs.promises.mkdir(finalFolderURL, { recursive: true });
86
88
  const cacheFile = basename(filepath) + (isLocalImage ? "" : ".json");
87
89
  const cachedFileURL = new URL(cacheFile, env.assetsCacheDir);
88
90
  try {
@@ -113,8 +115,6 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env, q
113
115
  throw new Error(`An error was encountered while reading the cache file. Error: ${e}`);
114
116
  }
115
117
  }
116
- const finalFolderURL = new URL("./", finalFileURL);
117
- await fs.promises.mkdir(finalFolderURL, { recursive: true });
118
118
  const originalImagePath = isLocalImage ? options.src.src : options.src;
119
119
  if (!originalImage) {
120
120
  originalImage = await loadImage(originalFilePath, env);
@@ -121,7 +121,7 @@ class ContentLayer {
121
121
  logger.info("Content config changed");
122
122
  shouldClear = true;
123
123
  }
124
- if (previousAstroVersion !== "4.16.13") {
124
+ if (previousAstroVersion !== "4.16.15") {
125
125
  logger.info("Astro version changed");
126
126
  shouldClear = true;
127
127
  }
@@ -129,8 +129,8 @@ class ContentLayer {
129
129
  logger.info("Clearing content store");
130
130
  this.#store.clearAll();
131
131
  }
132
- if ("4.16.13") {
133
- await this.#store.metaStore().set("astro-version", "4.16.13");
132
+ if ("4.16.15") {
133
+ await this.#store.metaStore().set("astro-version", "4.16.15");
134
134
  }
135
135
  if (currentConfigDigest) {
136
136
  await this.#store.metaStore().set("config-digest", currentConfigDigest);
@@ -57,6 +57,7 @@ function glob(globOptions) {
57
57
  untouchedEntries.delete(id);
58
58
  const existingEntry = store.get(id);
59
59
  const digest = generateDigest(contents);
60
+ const filePath = fileURLToPath(fileUrl);
60
61
  if (existingEntry && existingEntry.digest === digest && existingEntry.filePath) {
61
62
  if (existingEntry.deferredRender) {
62
63
  store.addModuleImport(existingEntry.filePath);
@@ -64,9 +65,9 @@ function glob(globOptions) {
64
65
  if (existingEntry.assetImports?.length) {
65
66
  store.addAssetImports(existingEntry.assetImports, existingEntry.filePath);
66
67
  }
68
+ fileToIdMap.set(filePath, id);
67
69
  return;
68
70
  }
69
- const filePath = fileURLToPath(fileUrl);
70
71
  const relativePath = posixRelative(fileURLToPath(config.root), filePath);
71
72
  const parsedData = await parseData({
72
73
  id,
@@ -30,7 +30,6 @@ class AppPipeline extends Pipeline {
30
30
  void 0,
31
31
  void 0,
32
32
  void 0,
33
- false,
34
33
  defaultRoutes
35
34
  );
36
35
  pipeline.#manifestData = manifestData;
@@ -35,7 +35,6 @@ export declare abstract class Pipeline {
35
35
  * Used for `Astro.site`.
36
36
  */
37
37
  readonly site: URL | undefined;
38
- readonly callSetGetEnv: boolean;
39
38
  /**
40
39
  * Array of built-in, internal, routes.
41
40
  * Used to find the route module
@@ -64,7 +63,7 @@ export declare abstract class Pipeline {
64
63
  /**
65
64
  * Used for `Astro.site`.
66
65
  */
67
- site?: URL | undefined, callSetGetEnv?: boolean,
66
+ site?: URL | undefined,
68
67
  /**
69
68
  * Array of built-in, internal, routes.
70
69
  * Used to find the route module
@@ -8,7 +8,7 @@ import { NOOP_MIDDLEWARE_FN } from "./middleware/noop-middleware.js";
8
8
  import { RouteCache } from "./render/route-cache.js";
9
9
  import { createDefaultRoutes } from "./routing/default.js";
10
10
  class Pipeline {
11
- constructor(logger, manifest, mode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, inlinedScripts = manifest.inlinedScripts, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, mode), site = manifest.site ? new URL(manifest.site) : void 0, callSetGetEnv = true, defaultRoutes = createDefaultRoutes(manifest)) {
11
+ constructor(logger, manifest, mode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, inlinedScripts = manifest.inlinedScripts, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, mode), site = manifest.site ? new URL(manifest.site) : void 0, defaultRoutes = createDefaultRoutes(manifest)) {
12
12
  this.logger = logger;
13
13
  this.manifest = manifest;
14
14
  this.mode = mode;
@@ -24,7 +24,6 @@ class Pipeline {
24
24
  this.middleware = middleware;
25
25
  this.routeCache = routeCache;
26
26
  this.site = site;
27
- this.callSetGetEnv = callSetGetEnv;
28
27
  this.defaultRoutes = defaultRoutes;
29
28
  this.internalMiddleware = [];
30
29
  if (i18n?.strategy !== "manual") {
@@ -32,11 +31,6 @@ class Pipeline {
32
31
  createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat)
33
32
  );
34
33
  }
35
- if (callSetGetEnv && manifest.experimentalEnvGetSecretEnabled) {
36
- setGetEnv(() => {
37
- throw new AstroError(AstroErrorData.EnvUnsupportedGetSecret);
38
- }, true);
39
- }
40
34
  }
41
35
  internalMiddleware;
42
36
  resolvedMiddleware = void 0;
@@ -20,6 +20,7 @@ import { runHookBuildGenerated } from "../../integrations/hooks.js";
20
20
  import { getOutputDirectory } from "../../prerender/utils.js";
21
21
  import { NoPrerenderedRoutesWithDomains } from "../errors/errors-data.js";
22
22
  import { AstroError, AstroErrorData } from "../errors/index.js";
23
+ import { NOOP_MIDDLEWARE_FN } from "../middleware/noop-middleware.js";
23
24
  import { getRedirectLocationOrThrow, routeIsRedirect } from "../redirects/index.js";
24
25
  import { RenderContext } from "../render-context.js";
25
26
  import { callGetStaticPaths } from "../render/route-cache.js";
@@ -44,13 +45,7 @@ async function generatePages(options, internals) {
44
45
  const baseDirectory = getOutputDirectory(options.settings.config);
45
46
  const renderersEntryUrl = new URL("renderers.mjs", baseDirectory);
46
47
  const renderers = await import(renderersEntryUrl.toString());
47
- let middleware = (_, next) => next();
48
- try {
49
- middleware = await import(new URL("middleware.mjs", baseDirectory).toString()).then(
50
- (mod) => mod.onRequest
51
- );
52
- } catch {
53
- }
48
+ const middleware = internals.middlewareEntryPoint ? await import(internals.middlewareEntryPoint.toString()).then((mod) => mod.onRequest) : NOOP_MIDDLEWARE_FN;
54
49
  manifest = createBuildManifest(
55
50
  options.settings,
56
51
  internals,
@@ -102,11 +102,11 @@ class BuildPipeline extends Pipeline {
102
102
  }
103
103
  const renderersEntryUrl = new URL(`renderers.mjs?time=${Date.now()}`, baseDirectory);
104
104
  const renderers = await import(renderersEntryUrl.toString());
105
- const middleware = await import(new URL("middleware.mjs", baseDirectory).toString()).then((mod) => {
105
+ const middleware = internals.middlewareEntryPoint ? await import(internals.middlewareEntryPoint.toString()).then((mod) => {
106
106
  return function() {
107
107
  return { onRequest: mod.onRequest };
108
108
  };
109
- }).catch(() => manifest.middleware);
109
+ }) : manifest.middleware;
110
110
  if (!renderers) {
111
111
  throw new Error(
112
112
  "Astro couldn't find the emitted renderers. This is an internal error, please file an issue."
@@ -229,7 +229,6 @@ function generateSSRCode(settings, adapter, middlewareId) {
229
229
  `import { renderers } from '${RENDERERS_MODULE_ID}';`,
230
230
  `import * as serverEntrypointModule from '${ADAPTER_VIRTUAL_MODULE_ID}';`,
231
231
  `import { manifest as defaultManifest } from '${SSR_MANIFEST_VIRTUAL_MODULE_ID}';`,
232
- edgeMiddleware ? `` : `import { onRequest as middleware } from '${middlewareId}';`,
233
232
  settings.config.experimental.serverIslands ? `import { serverIslandMap } from '${VIRTUAL_ISLAND_MAP_ID}';` : ""
234
233
  ];
235
234
  const contents = [
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.16.13";
1
+ const ASTRO_VERSION = "4.16.15";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
22
22
  await telemetry.record([]);
23
23
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
24
24
  const logger = restart.container.logger;
25
- const currentVersion = "4.16.13";
25
+ const currentVersion = "4.16.15";
26
26
  const isPrerelease = currentVersion.includes("-");
27
27
  if (!isPrerelease) {
28
28
  try {
@@ -1050,16 +1050,6 @@ export declare const EnvInvalidVariables: {
1050
1050
  title: string;
1051
1051
  message: (errors: Array<string>) => string;
1052
1052
  };
1053
- /**
1054
- * @docs
1055
- * @description
1056
- * The `astro:env/server` exported function `getSecret()` is not supported by your adapter.
1057
- */
1058
- export declare const EnvUnsupportedGetSecret: {
1059
- name: string;
1060
- title: string;
1061
- message: string;
1062
- };
1063
1053
  /**
1064
1054
  * @docs
1065
1055
  * @description
@@ -381,11 +381,6 @@ const EnvInvalidVariables = {
381
381
  ${errors.map((err) => `- ${err}`).join("\n")}
382
382
  `
383
383
  };
384
- const EnvUnsupportedGetSecret = {
385
- name: "EnvUnsupportedGetSecret",
386
- title: "Unsupported astro:env getSecret",
387
- message: "`astro:env/server` exported function `getSecret` is not supported by your adapter."
388
- };
389
384
  const ServerOnlyModule = {
390
385
  name: "ServerOnlyModule",
391
386
  title: "Module is only available server-side",
@@ -580,7 +575,6 @@ export {
580
575
  DuplicateContentEntrySlugError,
581
576
  EndpointDidNotReturnAResponse,
582
577
  EnvInvalidVariables,
583
- EnvUnsupportedGetSecret,
584
578
  ExpectedImage,
585
579
  ExpectedImageOptions,
586
580
  ExpectedNotESMImage,
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "4.16.13";
41
+ const version = "4.16.15";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -274,7 +274,7 @@ function printHelp({
274
274
  message.push(
275
275
  linebreak(),
276
276
  ` ${bgGreen(black(` ${commandName} `))} ${green(
277
- `v${"4.16.13"}`
277
+ `v${"4.16.15"}`
278
278
  )} ${headline}`
279
279
  );
280
280
  }
@@ -1,7 +1,8 @@
1
1
  import { NOOP_MIDDLEWARE_HEADER } from "../constants.js";
2
- const NOOP_MIDDLEWARE_FN = (ctx, next) => {
3
- ctx.request.headers.set(NOOP_MIDDLEWARE_HEADER, "true");
4
- return next();
2
+ const NOOP_MIDDLEWARE_FN = async (_ctx, next) => {
3
+ const response = await next();
4
+ response.headers.set(NOOP_MIDDLEWARE_HEADER, "true");
5
+ return response;
5
6
  };
6
7
  export {
7
8
  NOOP_MIDDLEWARE_FN
@@ -7,15 +7,11 @@ import { AstroError } from "../errors/index.js";
7
7
  const MIDDLEWARE_MODULE_ID = "\0astro-internal:middleware";
8
8
  const NOOP_MIDDLEWARE = "\0noop-middleware";
9
9
  function vitePluginMiddleware({ settings }) {
10
- let isCommandBuild = false;
11
10
  let resolvedMiddlewareId = void 0;
12
11
  const hasIntegrationMiddleware = settings.middlewares.pre.length > 0 || settings.middlewares.post.length > 0;
13
12
  let userMiddlewareIsPresent = false;
14
13
  return {
15
14
  name: "@astro/plugin-middleware",
16
- config(_, { command }) {
17
- isCommandBuild = command === "build";
18
- },
19
15
  async resolveId(id) {
20
16
  if (id === MIDDLEWARE_MODULE_ID) {
21
17
  const middlewareId = await this.resolve(
@@ -45,14 +41,6 @@ function vitePluginMiddleware({ settings }) {
45
41
  if (!userMiddlewareIsPresent && settings.config.i18n?.routing === "manual") {
46
42
  throw new AstroError(MissingMiddlewareForInternationalization);
47
43
  }
48
- if (isCommandBuild) {
49
- this.emitFile({
50
- type: "chunk",
51
- preserveSignature: "strict",
52
- fileName: "middleware.mjs",
53
- id
54
- });
55
- }
56
44
  const preMiddleware = createMiddlewareImports(settings.middlewares.pre, "pre");
57
45
  const postMiddleware = createMiddlewareImports(settings.middlewares.post, "post");
58
46
  const source = `
@@ -95,7 +83,7 @@ function vitePluginMiddlewareBuild(opts, internals) {
95
83
  },
96
84
  writeBundle(_, bundle) {
97
85
  for (const [chunkName, chunk] of Object.entries(bundle)) {
98
- if (chunk.type !== "asset" && chunk.fileName === "middleware.mjs") {
86
+ if (chunk.type !== "asset" && chunk.facadeModuleId === MIDDLEWARE_MODULE_ID) {
99
87
  const outputDirectory = getOutputDirectory(opts.settings.config);
100
88
  internals.middlewareEntryPoint = new URL(chunkName, outputDirectory);
101
89
  }
@@ -24,6 +24,7 @@ import { callMiddleware } from "./middleware/callMiddleware.js";
24
24
  import { sequence } from "./middleware/index.js";
25
25
  import { renderRedirect } from "./redirects/render.js";
26
26
  import { Slots, getParams, getProps } from "./render/index.js";
27
+ import { isRoute404or500 } from "./routing/match.js";
27
28
  import { copyRequest, setOriginPathname } from "./routing/rewrite.js";
28
29
  const apiContextRoutesSymbol = Symbol.for("context.routes");
29
30
  class RenderContext {
@@ -437,11 +438,8 @@ class RenderContext {
437
438
  return this.#currentLocale;
438
439
  }
439
440
  let computedLocale;
440
- if (routeData.pathname) {
441
- computedLocale = computeCurrentLocale(routeData.pathname, locales, defaultLocale);
442
- } else {
443
- computedLocale = computeCurrentLocale(url.pathname, locales, defaultLocale);
444
- }
441
+ const pathname = routeData.pathname && !isRoute404or500(routeData) ? routeData.pathname : url.pathname;
442
+ computedLocale = computeCurrentLocale(pathname, locales, defaultLocale);
445
443
  this.#currentLocale = computedLocale ?? fallbackTo;
446
444
  return this.#currentLocale;
447
445
  }
@@ -3,3 +3,10 @@ import type { ManifestData, RouteData } from '../../@types/astro.js';
3
3
  export declare function matchRoute(pathname: string, manifest: ManifestData): RouteData | undefined;
4
4
  /** Finds all matching routes from pathname */
5
5
  export declare function matchAllRoutes(pathname: string, manifest: ManifestData): RouteData[];
6
+ /**
7
+ * Determines if the given route matches a 404 or 500 error page.
8
+ *
9
+ * @param {RouteData} route - The route data to check.
10
+ * @returns {boolean} `true` if the route matches a 404 or 500 error page, otherwise `false`.
11
+ */
12
+ export declare function isRoute404or500(route: RouteData): boolean;
@@ -7,7 +7,11 @@ function matchRoute(pathname, manifest) {
7
7
  function matchAllRoutes(pathname, manifest) {
8
8
  return manifest.routes.filter((route) => route.pattern.test(decodeURI(pathname)));
9
9
  }
10
+ function isRoute404or500(route) {
11
+ return route.pattern.test("/404") || route.pattern.test("/500");
12
+ }
10
13
  export {
14
+ isRoute404or500,
11
15
  matchAllRoutes,
12
16
  matchRoute
13
17
  };
@@ -56,8 +56,8 @@ let response = await fetch('${serverIslandUrl}', {
56
56
  method: 'POST',
57
57
  body: JSON.stringify(data),
58
58
  });
59
-
60
- if(response.status === 200 && response.headers.get('content-type') === 'text/html') {
59
+ if (script) {
60
+ if(response.status === 200 && response.headers.get('content-type') === 'text/html') {
61
61
  let html = await response.text();
62
62
 
63
63
  // Swap!
@@ -72,6 +72,7 @@ if(response.status === 200 && response.headers.get('content-type') === 'text/htm
72
72
  script.before(frag);
73
73
  }
74
74
  script.remove();
75
+ }
75
76
  </script>`);
76
77
  }
77
78
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.16.13",
3
+ "version": "4.16.15",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/withastro/astro.git",
10
+ "url": "git+https://github.com/withastro/astro.git",
11
11
  "directory": "packages/astro"
12
12
  },
13
13
  "bugs": "https://github.com/withastro/astro/issues",