astro 3.1.1 → 3.1.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.
@@ -37,7 +37,8 @@ function configAliasVitePlugin({
37
37
  return null;
38
38
  const plugin = {
39
39
  name: "astro:tsconfig-alias",
40
- enforce: "pre",
40
+ // use post to only resolve ids that all other plugins before it can't
41
+ enforce: "post",
41
42
  configResolved(config) {
42
43
  patchCreateResolver(config, plugin);
43
44
  },
@@ -56,7 +57,7 @@ function configAliasVitePlugin({
56
57
  };
57
58
  return plugin;
58
59
  }
59
- function patchCreateResolver(config, prePlugin) {
60
+ function patchCreateResolver(config, postPlugin) {
60
61
  const _createResolver = config.createResolver;
61
62
  config.createResolver = function(...args1) {
62
63
  const resolver = _createResolver.apply(config, args1);
@@ -75,14 +76,16 @@ function patchCreateResolver(config, prePlugin) {
75
76
  isEntry: false,
76
77
  ssr
77
78
  };
78
- const resolved = await prePlugin.resolveId.apply(fakePluginContext, [
79
+ const result = await resolver.apply(_createResolver, args2);
80
+ if (result)
81
+ return result;
82
+ const resolved = await postPlugin.resolveId.apply(fakePluginContext, [
79
83
  id,
80
84
  importer,
81
85
  fakeResolveIdOpts
82
86
  ]);
83
87
  if (resolved)
84
88
  return resolved;
85
- return resolver.apply(_createResolver, args2);
86
89
  };
87
90
  };
88
91
  }
@@ -8,7 +8,8 @@ import path from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
9
  import { normalizePath } from "vite";
10
10
  import { AstroError, AstroErrorData, MarkdownError } from "../core/errors/index.js";
11
- import { isMarkdownFile, rootRelativePath } from "../core/util.js";
11
+ import { isMarkdownFile } from "../core/util.js";
12
+ import { shorthash } from "../runtime/server/shorthash.js";
12
13
  import { escapeViteEnvReferences, getFileInfo } from "../vite-plugin-utils/index.js";
13
14
  function safeMatter(source, id) {
14
15
  try {
@@ -71,7 +72,8 @@ function markdown({ settings, logger }) {
71
72
  for (const imagePath of rawImagePaths.values()) {
72
73
  imagePaths.push({
73
74
  raw: imagePath,
74
- resolved: (await this.resolve(imagePath, id))?.id ?? path.join(path.dirname(id), imagePath)
75
+ resolved: (await this.resolve(imagePath, id))?.id ?? path.join(path.dirname(id), imagePath),
76
+ safeName: shorthash(imagePath)
75
77
  });
76
78
  }
77
79
  const { layout } = frontmatter;
@@ -89,36 +91,26 @@ function markdown({ settings, logger }) {
89
91
 
90
92
  ${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
91
93
  import { getImage } from "astro:assets";
94
+ ${imagePaths.map((entry) => `import Astro__${entry.safeName} from ${JSON.stringify(entry.raw)};`)}
92
95
 
93
- export const images = {
94
- ${imagePaths.map(
95
- (entry) => `'${entry.raw}': await getImageSafely((await import("${entry.raw}")).default, "${entry.raw}", "${rootRelativePath(settings.config.root, entry.resolved)}")`
96
- )}
97
- }
98
-
99
- async function getImageSafely(imageSrc, imagePath, resolvedImagePath) {
100
- if (!imageSrc) {
101
- throw new AstroError({
102
- ...AstroErrorData.MarkdownImageNotFound,
103
- message: AstroErrorData.MarkdownImageNotFound.message(
104
- imagePath,
105
- resolvedImagePath
106
- ),
107
- location: { file: "${id}" },
108
- });
96
+ const images = async function() {
97
+ return {
98
+ ${imagePaths.map((entry) => `"${entry.raw}": await getImage({src: Astro__${entry.safeName}})`).join("\n")}
109
99
  }
110
-
111
- return await getImage({src: imageSrc})
112
100
  }
113
101
 
114
- function updateImageReferences(html) {
115
- return html.replaceAll(
116
- /__ASTRO_IMAGE_="([^"]+)"/gm,
117
- (full, imagePath) => spreadAttributes({src: images[imagePath].src, ...images[imagePath].attributes})
118
- );
102
+ async function updateImageReferences(html) {
103
+ return images().then((images) => {
104
+ return html.replaceAll(/__ASTRO_IMAGE_="([^"]+)"/gm, (full, imagePath) =>
105
+ spreadAttributes({
106
+ src: images[imagePath].src,
107
+ ...images[imagePath].attributes,
108
+ })
109
+ );
110
+ });
119
111
  }
120
112
 
121
- const html = updateImageReferences(${JSON.stringify(html)});
113
+ const html = await updateImageReferences(${JSON.stringify(html)});
122
114
 
123
115
  export const frontmatter = ${JSON.stringify(frontmatter)};
124
116
  export const file = ${JSON.stringify(fileId)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
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",
@@ -161,7 +161,7 @@
161
161
  "zod": "3.21.1",
162
162
  "@astrojs/internal-helpers": "0.2.0",
163
163
  "@astrojs/markdown-remark": "3.2.0",
164
- "@astrojs/telemetry": "3.0.1"
164
+ "@astrojs/telemetry": "3.0.2"
165
165
  },
166
166
  "optionalDependencies": {
167
167
  "sharp": "^0.32.5"