astro 3.1.1 → 3.1.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 (34) hide show
  1. package/components/ViewTransitions.astro +172 -123
  2. package/content-module.template.mjs +1 -1
  3. package/dist/assets/services/squoosh.js +3 -3
  4. package/dist/assets/utils/emitAsset.js +1 -4
  5. package/dist/assets/utils/metadata.d.ts +1 -1
  6. package/dist/assets/utils/metadata.js +6 -5
  7. package/dist/assets/vite-plugin-assets.js +17 -0
  8. package/dist/cli/add/index.js +10 -3
  9. package/dist/content/runtime.d.ts +3 -3
  10. package/dist/content/runtime.js +6 -11
  11. package/dist/core/build/generate.js +4 -2
  12. package/dist/core/build/plugins/plugin-middleware.js +1 -1
  13. package/dist/core/config/schema.d.ts +36 -60
  14. package/dist/core/config/schema.js +8 -23
  15. package/dist/core/constants.js +1 -1
  16. package/dist/core/cookies/index.d.ts +1 -1
  17. package/dist/core/cookies/index.js +7 -2
  18. package/dist/core/cookies/response.d.ts +1 -0
  19. package/dist/core/cookies/response.js +5 -1
  20. package/dist/core/dev/dev.js +1 -1
  21. package/dist/core/errors/errors-data.d.ts +31 -0
  22. package/dist/core/errors/errors-data.js +14 -0
  23. package/dist/core/messages.js +2 -2
  24. package/dist/core/middleware/callMiddleware.js +9 -2
  25. package/dist/core/middleware/loadMiddleware.js +1 -1
  26. package/dist/events/session.d.ts +14 -14
  27. package/dist/events/session.js +61 -53
  28. package/dist/integrations/astroFeaturesValidation.js +2 -2
  29. package/dist/integrations/index.js +3 -3
  30. package/dist/runtime/server/scripts.js +3 -3
  31. package/dist/vite-plugin-astro/hmr.js +1 -9
  32. package/dist/vite-plugin-config-alias/index.js +7 -4
  33. package/dist/vite-plugin-markdown/index.js +18 -26
  34. package/package.json +2 -2
@@ -1,63 +1,71 @@
1
+ import { AstroConfigSchema } from "../core/config/schema.js";
1
2
  const EVENT_SESSION = "ASTRO_CLI_SESSION_STARTED";
2
- const multiLevelKeys = /* @__PURE__ */ new Set([
3
- "build",
4
- "markdown",
5
- "markdown.shikiConfig",
6
- "server",
7
- "vite",
8
- "vite.resolve",
9
- "vite.css",
10
- "vite.json",
11
- "vite.server",
12
- "vite.server.fs",
13
- "vite.build",
14
- "vite.preview",
15
- "vite.optimizeDeps",
16
- "vite.ssr",
17
- "vite.worker"
18
- ]);
19
- function configKeys(obj, parentKey) {
20
- if (!obj) {
21
- return [];
3
+ function measureIsDefined(val) {
4
+ if (val === void 0) {
5
+ return void 0;
22
6
  }
23
- return Object.entries(obj).map(([key, value]) => {
24
- if (typeof value === "object" && !Array.isArray(value)) {
25
- const localKey = parentKey ? parentKey + "." + key : key;
26
- if (multiLevelKeys.has(localKey)) {
27
- let keys = configKeys(value, localKey).map((subkey) => key + "." + subkey);
28
- keys.unshift(key);
29
- return keys;
30
- }
31
- }
32
- return key;
33
- }).flat(1);
7
+ return Boolean(val);
8
+ }
9
+ function measureStringLiteral(val) {
10
+ return val;
11
+ }
12
+ function measureIntegration(val) {
13
+ if (!val || !val.name) {
14
+ return void 0;
15
+ }
16
+ return val.name;
17
+ }
18
+ function sanitizeConfigInfo(obj, validKeys) {
19
+ if (!obj || validKeys.length === 0) {
20
+ return {};
21
+ }
22
+ return validKeys.reduce(
23
+ (result, key) => {
24
+ result[key] = measureIsDefined(obj[key]);
25
+ return result;
26
+ },
27
+ {}
28
+ );
29
+ }
30
+ function createAnonymousConfigInfo(userConfig) {
31
+ const configInfo = {
32
+ ...sanitizeConfigInfo(userConfig, Object.keys(AstroConfigSchema.shape)),
33
+ build: sanitizeConfigInfo(
34
+ userConfig.build,
35
+ Object.keys(AstroConfigSchema.shape.build._def.innerType.shape)
36
+ ),
37
+ image: sanitizeConfigInfo(
38
+ userConfig.image,
39
+ Object.keys(AstroConfigSchema.shape.image._def.innerType.shape)
40
+ ),
41
+ markdown: sanitizeConfigInfo(
42
+ userConfig.markdown,
43
+ Object.keys(AstroConfigSchema.shape.markdown._def.innerType.shape)
44
+ ),
45
+ experimental: sanitizeConfigInfo(
46
+ userConfig.experimental,
47
+ Object.keys(AstroConfigSchema.shape.experimental._def.innerType.shape)
48
+ ),
49
+ legacy: sanitizeConfigInfo(
50
+ userConfig.legacy,
51
+ Object.keys(AstroConfigSchema.shape.legacy._def.innerType.shape)
52
+ ),
53
+ vite: userConfig.vite ? sanitizeConfigInfo(userConfig.vite, Object.keys(userConfig.vite)) : void 0
54
+ };
55
+ configInfo.build.format = measureStringLiteral(userConfig.build?.format);
56
+ configInfo.markdown.syntaxHighlight = measureStringLiteral(userConfig.markdown?.syntaxHighlight);
57
+ configInfo.output = measureStringLiteral(userConfig.output);
58
+ configInfo.scopedStyleStrategy = measureStringLiteral(userConfig.scopedStyleStrategy);
59
+ configInfo.trailingSlash = measureStringLiteral(userConfig.trailingSlash);
60
+ configInfo.adapter = measureIntegration(userConfig.adapter);
61
+ configInfo.integrations = userConfig.integrations?.flat(100).map(measureIntegration).filter(Boolean);
62
+ return configInfo;
34
63
  }
35
64
  function eventCliSession(cliCommand, userConfig, flags) {
36
- const configValues = userConfig ? {
37
- markdownPlugins: [
38
- ...userConfig?.markdown?.remarkPlugins?.map(
39
- (p) => typeof p === "string" ? p : typeof p
40
- ) ?? [],
41
- ...userConfig?.markdown?.rehypePlugins?.map(
42
- (p) => typeof p === "string" ? p : typeof p
43
- ) ?? []
44
- ],
45
- adapter: userConfig?.adapter?.name ?? null,
46
- integrations: (userConfig?.integrations ?? []).filter(Boolean).flat().map((i) => i?.name),
47
- trailingSlash: userConfig?.trailingSlash,
48
- build: userConfig?.build ? {
49
- format: userConfig?.build?.format
50
- } : void 0,
51
- markdown: userConfig?.markdown ? {
52
- drafts: userConfig.markdown?.drafts,
53
- syntaxHighlight: userConfig.markdown?.syntaxHighlight
54
- } : void 0
55
- } : void 0;
56
65
  const cliFlags = flags ? Object.keys(flags).filter((name) => name != "_") : void 0;
57
66
  const payload = {
58
67
  cliCommand,
59
- configKeys: userConfig ? configKeys(userConfig, "") : void 0,
60
- config: configValues,
68
+ config: createAnonymousConfigInfo(userConfig),
61
69
  flags: cliFlags
62
70
  };
63
71
  return [{ eventName: EVENT_SESSION, payload }];
@@ -81,14 +81,14 @@ function validateAssetsFeature(assets, adapterName, config, logger) {
81
81
  isSquooshCompatible = false
82
82
  } = assets;
83
83
  if (config?.image?.service?.entrypoint === SHARP_SERVICE && !isSharpCompatible) {
84
- logger.error(
84
+ logger.warn(
85
85
  "astro",
86
86
  `The currently selected adapter \`${adapterName}\` is not compatible with the image service "Sharp".`
87
87
  );
88
88
  return false;
89
89
  }
90
90
  if (config?.image?.service?.entrypoint === SQUOOSH_SERVICE && !isSquooshCompatible) {
91
- logger.error(
91
+ logger.warn(
92
92
  "astro",
93
93
  `The currently selected adapter \`${adapterName}\` is not compatible with the image service "Squoosh".`
94
94
  );
@@ -152,7 +152,7 @@ async function runHookConfigDone({
152
152
  logger
153
153
  );
154
154
  for (const [featureName, supported] of Object.entries(validationResult)) {
155
- if (!supported) {
155
+ if (!supported && featureName !== "assets") {
156
156
  logger.error(
157
157
  "astro",
158
158
  `The adapter ${adapter.name} doesn't support the feature ${featureName}. Your project won't be built. You should not use it.`
@@ -160,9 +160,9 @@ async function runHookConfigDone({
160
160
  }
161
161
  }
162
162
  if (!validationResult.assets) {
163
- logger.info(
163
+ logger.warn(
164
164
  "astro",
165
- `The selected adapter ${adapter.name} does not support Sharp or Squoosh for image processing. To ensure your project is still able to build, image processing has been disabled.`
165
+ `The selected adapter ${adapter.name} does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'noop' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`
166
166
  );
167
167
  settings.config.image.service = {
168
168
  entrypoint: "astro/assets/services/noop",
@@ -1,5 +1,5 @@
1
1
  import islandScript from "./astro-island.prebuilt.js";
2
- const ISLAND_STYLES = `<style style="display:none">astro-island,astro-slot,astro-static-slot{display:contents}</style>`;
2
+ const ISLAND_STYLES = `<style>astro-island,astro-slot,astro-static-slot{display:contents}</style>`;
3
3
  function determineIfNeedsHydrationScript(result) {
4
4
  if (result._metadata.hasHydrationScript) {
5
5
  return false;
@@ -24,12 +24,12 @@ function getDirectiveScriptText(result, directive) {
24
24
  function getPrescripts(result, type, directive) {
25
25
  switch (type) {
26
26
  case "both":
27
- return `${ISLAND_STYLES}<script style="display:none">${getDirectiveScriptText(
27
+ return `${ISLAND_STYLES}<script>${getDirectiveScriptText(
28
28
  result,
29
29
  directive
30
30
  )};${islandScript}</script>`;
31
31
  case "directive":
32
- return `<script style="display:none">${getDirectiveScriptText(result, directive)}</script>`;
32
+ return `<script>${getDirectiveScriptText(result, directive)}</script>`;
33
33
  }
34
34
  return "";
35
35
  }
@@ -54,7 +54,7 @@ async function handleHotUpdate(ctx, { config, logger, compile, source }) {
54
54
  ctx.server.moduleGraph.onFileChange(file2);
55
55
  }
56
56
  }
57
- const mods = ctx.modules.filter((m) => !m.url.endsWith("="));
57
+ const mods = [...filtered].filter((m) => !m.url.endsWith("="));
58
58
  const file = ctx.file.replace(config.root.pathname, "/");
59
59
  if (isStyleOnlyChange) {
60
60
  logger.info("astro", msg.hmr({ file, style: true }));
@@ -67,14 +67,6 @@ async function handleHotUpdate(ctx, { config, logger, compile, source }) {
67
67
  }
68
68
  }
69
69
  }
70
- for (const mod of filtered) {
71
- if (mod.id && isAstroScript(mod.id) && mod.file) {
72
- const astroMod = ctx.server.moduleGraph.getModuleById(mod.file);
73
- if (astroMod) {
74
- mods.unshift(astroMod);
75
- }
76
- }
77
- }
78
70
  const isSelfAccepting = mods.every((m) => m.isSelfAccepting || m.url.endsWith(".svelte"));
79
71
  if (isSelfAccepting) {
80
72
  if (/astro\.config\.[cm][jt]s$/.test(file))
@@ -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)};`).join("\n")}
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.3",
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"