astro 3.1.0 → 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.
Files changed (36) hide show
  1. package/client.d.ts +1 -3
  2. package/components/ViewTransitions.astro +172 -123
  3. package/content-types.template.d.ts +1 -0
  4. package/dist/@types/astro.d.ts +1 -1
  5. package/dist/assets/internal.d.ts +2 -2
  6. package/dist/assets/services/squoosh.js +3 -3
  7. package/dist/assets/types.d.ts +4 -1
  8. package/dist/assets/utils/emitAsset.js +1 -4
  9. package/dist/assets/utils/metadata.d.ts +1 -1
  10. package/dist/assets/utils/metadata.js +6 -5
  11. package/dist/assets/vite-plugin-assets.js +17 -0
  12. package/dist/cli/add/index.js +10 -3
  13. package/dist/content/runtime.d.ts +2 -1
  14. package/dist/content/runtime.js +13 -4
  15. package/dist/core/build/generate.js +1 -1
  16. package/dist/core/build/plugins/plugin-middleware.js +1 -1
  17. package/dist/core/config/schema.d.ts +36 -60
  18. package/dist/core/config/schema.js +8 -23
  19. package/dist/core/constants.js +1 -1
  20. package/dist/core/cookies/index.d.ts +1 -1
  21. package/dist/core/cookies/index.js +7 -2
  22. package/dist/core/cookies/response.d.ts +1 -0
  23. package/dist/core/cookies/response.js +5 -1
  24. package/dist/core/dev/dev.js +1 -1
  25. package/dist/core/errors/errors-data.d.ts +30 -0
  26. package/dist/core/errors/errors-data.js +14 -0
  27. package/dist/core/messages.js +2 -2
  28. package/dist/core/middleware/callMiddleware.js +9 -2
  29. package/dist/core/middleware/loadMiddleware.js +1 -1
  30. package/dist/events/session.d.ts +14 -14
  31. package/dist/events/session.js +61 -53
  32. package/dist/runtime/server/scripts.js +3 -3
  33. package/dist/vite-plugin-astro/hmr.js +1 -9
  34. package/dist/vite-plugin-config-alias/index.js +7 -4
  35. package/dist/vite-plugin-markdown/index.js +18 -26
  36. 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 }];
@@ -1,5 +1,5 @@
1
1
  import islandScript from "./astro-island.prebuilt.js";
2
- const ISLAND_STYLES = `<style>astro-island,astro-slot,astro-static-slot{display:contents}</style>`;
2
+ const ISLAND_STYLES = `<style style="display:none">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>${getDirectiveScriptText(
27
+ return `${ISLAND_STYLES}<script style="display:none">${getDirectiveScriptText(
28
28
  result,
29
29
  directive
30
30
  )};${islandScript}</script>`;
31
31
  case "directive":
32
- return `<script>${getDirectiveScriptText(result, directive)}</script>`;
32
+ return `<script style="display:none">${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)};`)}
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.0",
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"