astro 2.1.2 → 2.1.4

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 (207) hide show
  1. package/client-base.d.ts +2 -1
  2. package/client-image.d.ts +7 -14
  3. package/dist/@types/astro.d.ts +2 -2
  4. package/dist/@types/typed-emitter.d.ts +1 -2
  5. package/dist/assets/consts.d.ts +5 -1
  6. package/dist/assets/consts.js +8 -3
  7. package/dist/assets/image-endpoint.js +1 -1
  8. package/dist/assets/internal.d.ts +3 -2
  9. package/dist/assets/internal.js +10 -5
  10. package/dist/assets/services/service.d.ts +15 -4
  11. package/dist/assets/services/service.js +35 -29
  12. package/dist/assets/services/sharp.d.ts +1 -1
  13. package/dist/assets/services/sharp.js +5 -4
  14. package/dist/assets/services/squoosh.d.ts +1 -1
  15. package/dist/assets/services/squoosh.js +7 -4
  16. package/dist/assets/services/vendor/squoosh/codecs.js +2 -0
  17. package/dist/assets/services/vendor/squoosh/image-pool.js +2 -0
  18. package/dist/assets/services/vendor/squoosh/impl.js +2 -0
  19. package/dist/assets/types.d.ts +3 -3
  20. package/dist/assets/utils/emitAsset.d.ts +2 -0
  21. package/dist/assets/utils/emitAsset.js +31 -0
  22. package/dist/assets/utils/metadata.d.ts +1 -1
  23. package/dist/assets/utils/metadata.js +2 -4
  24. package/dist/assets/utils/queryParams.d.ts +1 -1
  25. package/dist/assets/utils/transformToPath.d.ts +1 -1
  26. package/dist/assets/vendor/image-size/detector.d.ts +3 -0
  27. package/dist/assets/vendor/image-size/detector.js +28 -0
  28. package/dist/assets/vendor/image-size/index.d.ts +11 -0
  29. package/dist/assets/vendor/image-size/index.js +93 -0
  30. package/dist/assets/vendor/image-size/readUInt.d.ts +4 -0
  31. package/dist/assets/vendor/image-size/readUInt.js +9 -0
  32. package/dist/assets/vendor/image-size/types/bmp.d.ts +2 -0
  33. package/dist/assets/vendor/image-size/types/bmp.js +14 -0
  34. package/dist/assets/vendor/image-size/types/cur.d.ts +2 -0
  35. package/dist/assets/vendor/image-size/types/cur.js +16 -0
  36. package/dist/assets/vendor/image-size/types/dds.d.ts +2 -0
  37. package/dist/assets/vendor/image-size/types/dds.js +14 -0
  38. package/dist/assets/vendor/image-size/types/gif.d.ts +2 -0
  39. package/dist/assets/vendor/image-size/types/gif.js +16 -0
  40. package/dist/assets/vendor/image-size/types/icns.d.ts +2 -0
  41. package/dist/assets/vendor/image-size/types/icns.js +87 -0
  42. package/dist/assets/vendor/image-size/types/ico.d.ts +2 -0
  43. package/dist/assets/vendor/image-size/types/ico.js +42 -0
  44. package/dist/assets/vendor/image-size/types/interface.d.ts +14 -0
  45. package/dist/assets/vendor/image-size/types/interface.js +0 -0
  46. package/dist/assets/vendor/image-size/types/j2c.d.ts +2 -0
  47. package/dist/assets/vendor/image-size/types/j2c.js +14 -0
  48. package/dist/assets/vendor/image-size/types/jp2.d.ts +2 -0
  49. package/dist/assets/vendor/image-size/types/jp2.js +56 -0
  50. package/dist/assets/vendor/image-size/types/jpg.d.ts +2 -0
  51. package/dist/assets/vendor/image-size/types/jpg.js +95 -0
  52. package/dist/assets/vendor/image-size/types/ktx.d.ts +2 -0
  53. package/dist/assets/vendor/image-size/types/ktx.js +15 -0
  54. package/dist/assets/vendor/image-size/types/png.d.ts +2 -0
  55. package/dist/assets/vendor/image-size/types/png.js +33 -0
  56. package/dist/assets/vendor/image-size/types/pnm.d.ts +2 -0
  57. package/dist/assets/vendor/image-size/types/pnm.js +72 -0
  58. package/dist/assets/vendor/image-size/types/psd.d.ts +2 -0
  59. package/dist/assets/vendor/image-size/types/psd.js +14 -0
  60. package/dist/assets/vendor/image-size/types/svg.d.ts +2 -0
  61. package/dist/assets/vendor/image-size/types/svg.js +91 -0
  62. package/dist/assets/vendor/image-size/types/tiff.d.ts +2 -0
  63. package/dist/assets/vendor/image-size/types/tiff.js +81 -0
  64. package/dist/assets/vendor/image-size/types/webp.d.ts +2 -0
  65. package/dist/assets/vendor/image-size/types/webp.js +51 -0
  66. package/dist/assets/vendor/image-size/types.d.ts +19 -0
  67. package/dist/assets/vendor/image-size/types.js +37 -0
  68. package/dist/assets/vendor/queue/queue.d.ts +39 -0
  69. package/dist/assets/vendor/queue/queue.js +187 -0
  70. package/dist/assets/vite-plugin-assets.d.ts +1 -1
  71. package/dist/assets/vite-plugin-assets.js +29 -25
  72. package/dist/cli/check/index.js +43 -2
  73. package/dist/cli/check/print.d.ts +1 -1
  74. package/dist/content/error-map.d.ts +2 -0
  75. package/dist/content/error-map.js +78 -0
  76. package/dist/content/index.d.ts +1 -0
  77. package/dist/content/index.js +2 -0
  78. package/dist/content/runtime-assets.d.ts +8 -0
  79. package/dist/content/runtime-assets.js +24 -0
  80. package/dist/content/{internal.d.ts → runtime.d.ts} +1 -19
  81. package/dist/content/{internal.js → runtime.js} +28 -43
  82. package/dist/content/server-listeners.d.ts +1 -1
  83. package/dist/content/template/virtual-mod-assets.d.mts +1 -0
  84. package/dist/content/template/virtual-mod.d.mts +0 -1
  85. package/dist/content/types-generator.d.ts +3 -3
  86. package/dist/content/types-generator.js +3 -0
  87. package/dist/content/utils.d.ts +9 -4
  88. package/dist/content/utils.js +20 -26
  89. package/dist/content/vite-plugin-content-assets.d.ts +3 -3
  90. package/dist/content/vite-plugin-content-imports.d.ts +1 -1
  91. package/dist/content/vite-plugin-content-imports.js +4 -10
  92. package/dist/content/vite-plugin-content-virtual-mod.js +8 -3
  93. package/dist/core/add/index.d.ts +1 -1
  94. package/dist/core/add/index.js +25 -8
  95. package/dist/core/app/index.js +4 -1
  96. package/dist/core/app/node.d.ts +2 -2
  97. package/dist/core/build/add-rollup-input.d.ts +1 -1
  98. package/dist/core/build/css-asset-name.d.ts +1 -1
  99. package/dist/core/build/generate.d.ts +1 -1
  100. package/dist/core/build/generate.js +5 -1
  101. package/dist/core/build/index.d.ts +1 -1
  102. package/dist/core/build/index.js +4 -0
  103. package/dist/core/build/internal.d.ts +16 -6
  104. package/dist/core/build/internal.js +2 -2
  105. package/dist/core/build/plugin.js +1 -0
  106. package/dist/core/build/plugins/index.js +2 -0
  107. package/dist/core/build/plugins/plugin-alias-resolve.d.ts +1 -1
  108. package/dist/core/build/plugins/plugin-analyzer.js +12 -2
  109. package/dist/core/build/plugins/plugin-component-entry.d.ts +11 -0
  110. package/dist/core/build/plugins/plugin-component-entry.js +74 -0
  111. package/dist/core/build/plugins/plugin-css.d.ts +1 -1
  112. package/dist/core/build/plugins/plugin-hoisted-scripts.d.ts +2 -2
  113. package/dist/core/build/plugins/plugin-internals.js +2 -1
  114. package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
  115. package/dist/core/build/plugins/plugin-ssr.d.ts +1 -1
  116. package/dist/core/build/static-build.d.ts +1 -1
  117. package/dist/core/build/static-build.js +6 -3
  118. package/dist/core/compile/cache.d.ts +1 -1
  119. package/dist/core/compile/style.d.ts +1 -1
  120. package/dist/core/config/config.d.ts +1 -1
  121. package/dist/core/config/schema.d.ts +37 -37
  122. package/dist/core/config/schema.js +9 -1
  123. package/dist/core/config/timer.js +9 -0
  124. package/dist/core/config/tsconfig.js +4 -0
  125. package/dist/core/config/vite-load.js +3 -0
  126. package/dist/core/constants.js +1 -1
  127. package/dist/core/cookies/cookies.js +35 -1
  128. package/dist/core/create-vite.js +35 -4
  129. package/dist/core/dev/container.d.ts +2 -2
  130. package/dist/core/dev/container.js +1 -0
  131. package/dist/core/dev/dev.d.ts +3 -3
  132. package/dist/core/dev/dev.js +2 -1
  133. package/dist/core/endpoint/index.d.ts +1 -1
  134. package/dist/core/endpoint/index.js +1 -0
  135. package/dist/core/errors/dev/utils.d.ts +1 -1
  136. package/dist/core/errors/dev/utils.js +2 -1
  137. package/dist/core/errors/dev/vite.d.ts +1 -1
  138. package/dist/core/errors/dev/vite.js +1 -0
  139. package/dist/core/errors/errors-data.js +489 -4
  140. package/dist/core/errors/errors.d.ts +1 -1
  141. package/dist/core/errors/errors.js +2 -0
  142. package/dist/core/errors/overlay.js +16 -5
  143. package/dist/core/errors/utils.d.ts +2 -2
  144. package/dist/core/logger/console.js +1 -1
  145. package/dist/core/logger/node.js +1 -1
  146. package/dist/core/messages.d.ts +3 -3
  147. package/dist/core/messages.js +2 -2
  148. package/dist/core/module-loader/loader.d.ts +3 -3
  149. package/dist/core/preview/static-preview-server.d.ts +1 -1
  150. package/dist/core/preview/vite-plugin-astro-preview.d.ts +2 -2
  151. package/dist/core/render/dev/css.d.ts +1 -1
  152. package/dist/core/render/dev/css.js +2 -1
  153. package/dist/core/render/dev/environment.js +1 -0
  154. package/dist/core/render/dev/index.js +1 -0
  155. package/dist/core/render/dev/resolve.js +1 -6
  156. package/dist/core/render/dev/vite.js +13 -1
  157. package/dist/core/render/index.d.ts +1 -1
  158. package/dist/core/render/paginate.d.ts +1 -1
  159. package/dist/core/render/result.d.ts +1 -1
  160. package/dist/core/render/result.js +4 -0
  161. package/dist/core/render/route-cache.d.ts +1 -1
  162. package/dist/core/render/route-cache.js +1 -0
  163. package/dist/core/routing/manifest/create.js +4 -1
  164. package/dist/core/sync/index.d.ts +1 -1
  165. package/dist/core/sync/index.js +1 -0
  166. package/dist/events/error.d.ts +2 -2
  167. package/dist/integrations/index.d.ts +2 -2
  168. package/dist/jsx/renderer.js +1 -0
  169. package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
  170. package/dist/runtime/client/visible.prebuilt.js +1 -1
  171. package/dist/runtime/server/hydration.js +1 -0
  172. package/dist/runtime/server/jsx.d.ts +1 -1
  173. package/dist/runtime/server/render/scope.js +5 -0
  174. package/dist/runtime/server/render/tags.d.ts +1 -1
  175. package/dist/runtime/server/scripts.js +2 -2
  176. package/dist/vite-plugin-astro/compile.d.ts +3 -3
  177. package/dist/vite-plugin-astro/compile.js +1 -0
  178. package/dist/vite-plugin-astro/index.js +7 -1
  179. package/dist/vite-plugin-astro-server/base.d.ts +1 -1
  180. package/dist/vite-plugin-astro-server/common.d.ts +1 -1
  181. package/dist/vite-plugin-astro-server/plugin.d.ts +1 -1
  182. package/dist/vite-plugin-astro-server/response.js +2 -2
  183. package/dist/vite-plugin-astro-server/route.d.ts +1 -1
  184. package/dist/vite-plugin-config-alias/index.d.ts +2 -7
  185. package/dist/vite-plugin-config-alias/index.js +32 -41
  186. package/dist/vite-plugin-env/index.js +1 -0
  187. package/dist/vite-plugin-head-propagation/index.d.ts +1 -1
  188. package/dist/vite-plugin-html/transform/slots.d.ts +1 -1
  189. package/dist/vite-plugin-html/transform/utils.d.ts +1 -1
  190. package/dist/vite-plugin-inject-env-ts/index.d.ts +2 -2
  191. package/dist/vite-plugin-inject-env-ts/index.js +5 -1
  192. package/dist/vite-plugin-integrations-container/index.d.ts +3 -3
  193. package/dist/vite-plugin-jsx/import-source.d.ts +2 -2
  194. package/dist/vite-plugin-jsx/index.d.ts +1 -1
  195. package/dist/vite-plugin-jsx/index.js +7 -1
  196. package/dist/vite-plugin-jsx/tag.js +7 -0
  197. package/dist/vite-plugin-markdown/content-entry-type.d.ts +1 -1
  198. package/dist/vite-plugin-markdown/index.js +12 -4
  199. package/dist/vite-plugin-scanner/index.d.ts +2 -2
  200. package/dist/vite-plugin-scanner/scan.d.ts +1 -1
  201. package/dist/vite-plugin-scripts/index.d.ts +2 -2
  202. package/dist/vite-plugin-scripts/page-ssr.d.ts +2 -2
  203. package/package.json +7 -6
  204. package/src/content/template/types.d.ts +12 -1
  205. package/src/content/template/virtual-mod-assets.mjs +7 -0
  206. package/src/content/template/virtual-mod.mjs +1 -7
  207. package/tsconfigs/base.json +4 -1
@@ -1,63 +1,54 @@
1
- import * as path from "path";
2
- const normalize = (pathname) => String(pathname).split(path.sep).join(path.posix.sep);
3
- const getConfigAlias = (settings) => {
4
- const config = settings.tsConfig;
5
- const configPath = settings.tsConfigPath;
6
- if (!config || !configPath)
7
- return null;
8
- const compilerOptions = Object(config.compilerOptions);
9
- if (!compilerOptions.baseUrl)
10
- return null;
11
- const baseUrl = path.posix.resolve(
12
- path.posix.dirname(normalize(configPath).replace(/^\/?/, "/")),
13
- normalize(compilerOptions.baseUrl)
14
- );
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import slash from "slash";
4
+ const getConfigAlias = (paths, baseUrl) => {
15
5
  const aliases = [];
16
- for (let [alias, values] of Object.entries(
17
- Object(compilerOptions.paths)
18
- )) {
19
- values = [].concat(values);
6
+ for (const [alias, values] of Object.entries(paths)) {
20
7
  const find = new RegExp(
21
8
  `^${[...alias].map(
22
9
  (segment) => segment === "*" ? "(.+)" : segment.replace(/[\\^$*+?.()|[\]{}]/, "\\$&")
23
10
  ).join("")}$`
24
11
  );
25
12
  let matchId = 0;
26
- for (let value of values) {
13
+ for (const value of values) {
27
14
  const replacement = [...path.posix.resolve(baseUrl, value)].map((segment) => segment === "*" ? `$${++matchId}` : segment === "$" ? "$$" : segment).join("");
28
15
  aliases.push({ find, replacement });
29
16
  }
30
17
  }
31
- aliases.push({
32
- find: /^(?!\.*\/)(.+)$/,
33
- replacement: `${[...baseUrl].map((segment) => segment === "$" ? "$$" : segment).join("")}/$1`
34
- });
35
18
  return aliases;
36
19
  };
37
20
  function configAliasVitePlugin({
38
21
  settings
39
22
  }) {
40
- const { config } = settings;
41
- const configAlias = getConfigAlias(settings);
42
- if (!configAlias)
43
- return {};
23
+ const { tsConfig, tsConfigPath } = settings;
24
+ if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions)
25
+ return null;
26
+ const { baseUrl, paths } = tsConfig.compilerOptions;
27
+ if (!baseUrl || !paths)
28
+ return null;
29
+ const resolvedBaseUrl = path.posix.resolve(
30
+ path.posix.dirname(slash(tsConfigPath).replace(/^\/?/, "/")),
31
+ slash(baseUrl)
32
+ );
33
+ const configAlias = getConfigAlias(paths, resolvedBaseUrl);
44
34
  return {
45
35
  name: "astro:tsconfig-alias",
46
36
  enforce: "pre",
47
- async resolveId(sourceId, importer, options) {
48
- const resolvedId = await this.resolve(sourceId, importer, { skipSelf: true, ...options });
49
- if (resolvedId)
50
- return resolvedId;
51
- for (const alias of configAlias) {
52
- if (alias.find.test(sourceId)) {
53
- const aliasedSourceId = sourceId.replace(alias.find, alias.replacement);
54
- const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, {
55
- skipSelf: true,
56
- ...options
57
- });
58
- if (resolvedAliasedId)
59
- return resolvedAliasedId;
60
- }
37
+ config() {
38
+ if (configAlias.length) {
39
+ return {
40
+ resolve: {
41
+ alias: configAlias
42
+ }
43
+ };
44
+ }
45
+ },
46
+ resolveId(id) {
47
+ if (id.startsWith(".") || id.startsWith("/"))
48
+ return;
49
+ const resolved = path.posix.join(resolvedBaseUrl, id);
50
+ if (fs.existsSync(resolved)) {
51
+ return resolved;
61
52
  }
62
53
  }
63
54
  };
@@ -51,6 +51,7 @@ function envVitePlugin({ settings }) {
51
51
  }
52
52
  let s;
53
53
  const pattern = new RegExp(
54
+ // Do not allow preceding '.', but do allow preceding '...' for spread operations
54
55
  `(?<!(?<!\\.\\.)\\.)\\b(import\\.meta\\.env\\.(.+?)|import\\.meta\\.env)\\b(?!\\s*?=[^=])`,
55
56
  "g"
56
57
  );
@@ -2,7 +2,7 @@ import type { AstroSettings } from '../@types/astro';
2
2
  import type { BuildInternals } from '../core/build/internal.js';
3
3
  import type { AstroBuildPlugin } from '../core/build/plugin.js';
4
4
  import type { StaticBuildOptions } from '../core/build/types';
5
- import * as vite from 'vite';
5
+ import type * as vite from 'vite';
6
6
  /**
7
7
  * If any component is marked as doing head injection, walk up the tree
8
8
  * and mark parent Astro components as having head injection in the tree.
@@ -1,6 +1,6 @@
1
1
  import type { Root } from 'hast';
2
2
  import type { Plugin } from 'unified';
3
- import MagicString from 'magic-string';
3
+ import type MagicString from 'magic-string';
4
4
  declare const rehypeSlots: Plugin<[{
5
5
  s: MagicString;
6
6
  }], Root>;
@@ -1,5 +1,5 @@
1
1
  import type { Element } from 'hast';
2
- import MagicString from 'magic-string';
2
+ import type MagicString from 'magic-string';
3
3
  export declare function replaceAttribute(s: MagicString, node: Element, key: string, newValue: string): void;
4
4
  export declare function needsEscape(value: any): value is string;
5
5
  export declare function escape(value: string): string;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import type fsMod from 'node:fs';
3
- import { Plugin } from 'vite';
3
+ import { type Plugin } from 'vite';
4
4
  import type { AstroSettings } from '../@types/astro.js';
5
- import { LogOptions } from '../core/logger/core.js';
5
+ import { type LogOptions } from '../core/logger/core.js';
6
6
  export declare function getEnvTsPath({ srcDir }: {
7
7
  srcDir: URL;
8
8
  }): URL;
@@ -14,6 +14,8 @@ function astroInjectEnvTsPlugin({
14
14
  }) {
15
15
  return {
16
16
  name: "astro-inject-env-ts",
17
+ // Use `post` to ensure project setup is complete
18
+ // Ex. `.astro` types have been written
17
19
  enforce: "post",
18
20
  async config() {
19
21
  await setUpEnvTs({ settings, logging, fs });
@@ -39,12 +41,14 @@ async function setUpEnvTs({
39
41
  'types="astro/client-image"'
40
42
  );
41
43
  await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
42
- } else if (typesEnvContents.includes('types="astro/client-image"')) {
44
+ info(logging, "assets", `Added ${bold(envTsPathRelativetoRoot)} types`);
45
+ } else if (!settings.config.experimental.assets && typesEnvContents.includes('types="astro/client-image"')) {
43
46
  typesEnvContents = typesEnvContents.replace(
44
47
  'types="astro/client-image"',
45
48
  'types="astro/client"'
46
49
  );
47
50
  await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
51
+ info(logging, "assets", `Removed ${bold(envTsPathRelativetoRoot)} types`);
48
52
  }
49
53
  if (!fs.existsSync(dotAstroDir))
50
54
  return;
@@ -1,6 +1,6 @@
1
- import { Plugin as VitePlugin } from 'vite';
2
- import { AstroSettings } from '../@types/astro.js';
3
- import { LogOptions } from '../core/logger/core.js';
1
+ import type { Plugin as VitePlugin } from 'vite';
2
+ import type { AstroSettings } from '../@types/astro.js';
3
+ import type { LogOptions } from '../core/logger/core.js';
4
4
  /** Connect Astro integrations into Vite, as needed. */
5
5
  export default function astroIntegrationsContainerPlugin({ settings, logging, }: {
6
6
  settings: AstroSettings;
@@ -1,3 +1,3 @@
1
- import { TsConfigJson } from 'tsconfig-resolver';
2
- import { AstroRenderer } from '../@types/astro';
1
+ import type { TsConfigJson } from 'tsconfig-resolver';
2
+ import type { AstroRenderer } from '../@types/astro';
3
3
  export declare function detectImportSource(code: string, jsxRenderers: Map<string, AstroRenderer>, tsConfig?: TsConfigJson): Promise<string | undefined>;
@@ -1,4 +1,4 @@
1
- import { Plugin } from 'vite';
1
+ import { type Plugin } from 'vite';
2
2
  import type { AstroSettings } from '../@types/astro';
3
3
  import type { LogOptions } from '../core/logger/core.js';
4
4
  interface AstroPluginJSXOptions {
@@ -1,4 +1,6 @@
1
- import { transformWithEsbuild } from "vite";
1
+ import {
2
+ transformWithEsbuild
3
+ } from "vite";
2
4
  import babel from "@babel/core";
3
5
  import * as colors from "kleur/colors";
4
6
  import path from "path";
@@ -61,6 +63,8 @@ async function transformJSX({
61
63
  meta: {
62
64
  astro,
63
65
  vite: {
66
+ // Setting this vite metadata to `ts` causes Vite to resolve .js
67
+ // extensions to .ts files.
64
68
  lang: "ts"
65
69
  }
66
70
  }
@@ -80,6 +84,7 @@ function jsx({ settings, logging }) {
80
84
  return {
81
85
  name: "astro:jsx",
82
86
  enforce: "pre",
87
+ // run transforms before other plugins
83
88
  async configResolved(resolvedConfig) {
84
89
  viteConfig = resolvedConfig;
85
90
  const possibleRenderers = collectJSXRenderers(settings.renderers);
@@ -107,6 +112,7 @@ function jsx({ settings, logging }) {
107
112
  sourcemap: "inline",
108
113
  tsconfigRaw: {
109
114
  compilerOptions: {
115
+ // Ensure client:only imports are treeshaken
110
116
  importsNotUsedAsValues: "remove"
111
117
  }
112
118
  }
@@ -6,6 +6,7 @@ async function tagExportsWithRenderer({
6
6
  return {
7
7
  visitor: {
8
8
  Program: {
9
+ // Inject `import { __astro_tag_component__ } from 'astro/server/index.js'`
9
10
  enter(path) {
10
11
  path.node.body.splice(
11
12
  0,
@@ -21,6 +22,7 @@ async function tagExportsWithRenderer({
21
22
  )
22
23
  );
23
24
  },
25
+ // For each export we found, inject `__astro_tag_component__(exportName, rendererName)`
24
26
  exit(path, state) {
25
27
  const exportedIds = state.get("astro:tags");
26
28
  if (exportedIds) {
@@ -38,6 +40,11 @@ async function tagExportsWithRenderer({
38
40
  }
39
41
  },
40
42
  ExportDeclaration: {
43
+ /**
44
+ * For default anonymous function export, we need to give them a unique name
45
+ * @param path
46
+ * @returns
47
+ */
41
48
  enter(path) {
42
49
  var _a;
43
50
  const node = path.node;
@@ -1,4 +1,4 @@
1
- import { ContentEntryType } from '../@types/astro.js';
1
+ import type { ContentEntryType } from '../@types/astro.js';
2
2
  export declare const markdownContentEntryType: ContentEntryType;
3
3
  /**
4
4
  * MDX content type for compatibility with older `@astrojs/mdx` versions
@@ -10,6 +10,7 @@ import { fileURLToPath } from "node:url";
10
10
  import { pathToFileURL } from "url";
11
11
  import { normalizePath } from "vite";
12
12
  import { imageMetadata } from "../assets/index.js";
13
+ import imageSize from "../assets/vendor/image-size/index.js";
13
14
  import { AstroError, AstroErrorData, MarkdownError } from "../core/errors/index.js";
14
15
  import { warn } from "../core/logger/core.js";
15
16
  import { isMarkdownFile } from "../core/util.js";
@@ -43,6 +44,7 @@ const astroJsxRuntimeModulePath = normalizePath(
43
44
  );
44
45
  function markdown({ settings, logging }) {
45
46
  const markdownAssetMap = /* @__PURE__ */ new Map();
47
+ let imageService = void 0;
46
48
  async function resolveImage(fileId, path) {
47
49
  const resolved = await this.resolve(path, fileId);
48
50
  if (!resolved)
@@ -63,12 +65,15 @@ function markdown({ settings, logging }) {
63
65
  return {
64
66
  enforce: "pre",
65
67
  name: "astro:markdown",
68
+ // Why not the "transform" hook instead of "load" + readFile?
69
+ // A: Vite transforms all "import.meta.env" references to their values before
70
+ // passing to the transform hook. This lets us get the truly raw value
71
+ // to escape "import.meta.env" ourselves.
66
72
  async load(id) {
67
73
  if (isMarkdownFile(id)) {
68
74
  const { fileId, fileUrl } = getFileInfo(id, settings.config);
69
75
  const rawFile = await fs.promises.readFile(fileId, "utf-8");
70
76
  const raw = safeMatter(rawFile, id);
71
- let imageService = void 0;
72
77
  if (settings.config.experimental.assets) {
73
78
  imageService = (await import(settings.config.image.service)).default;
74
79
  }
@@ -79,7 +84,8 @@ function markdown({ settings, logging }) {
79
84
  experimentalAssets: settings.config.experimental.assets,
80
85
  imageService,
81
86
  assetsDir: new URL("./assets/", settings.config.srcDir),
82
- resolveImage: this.meta.watchMode ? void 0 : resolveImage.bind(this, fileId)
87
+ resolveImage: this.meta.watchMode ? void 0 : resolveImage.bind(this, fileId),
88
+ getImageMetadata: imageSize
83
89
  });
84
90
  this;
85
91
  let html = renderResult.code;
@@ -180,10 +186,12 @@ function markdown({ settings, logging }) {
180
186
  }
181
187
  const fileName = this.getFileName(hash);
182
188
  image.src = npath.join(settings.config.base, fileName);
183
- const optimized = globalThis.astroAsset.addStaticImage({ src: image });
189
+ const options = { src: image };
190
+ const validatedOptions = (imageService == null ? void 0 : imageService.validateOptions) ? imageService.validateOptions(options) : options;
191
+ const optimized = globalThis.astroAsset.addStaticImage(validatedOptions);
184
192
  optimizedPaths.set(hash, optimized);
185
193
  }
186
- output.code = output.code.replace(/ASTRO_ASSET_MD_([0-9a-z]{8})/, (_str, hash) => {
194
+ output.code = output.code.replaceAll(/ASTRO_ASSET_MD_([0-9a-z]{8})/gm, (_str, hash) => {
187
195
  const optimizedName = optimizedPaths.get(hash);
188
196
  return optimizedName || this.getFileName(hash);
189
197
  });
@@ -1,5 +1,5 @@
1
- import { Plugin as VitePlugin } from 'vite';
2
- import { AstroSettings } from '../@types/astro.js';
1
+ import { type Plugin as VitePlugin } from 'vite';
2
+ import type { AstroSettings } from '../@types/astro.js';
3
3
  export default function astroScannerPlugin({ settings }: {
4
4
  settings: AstroSettings;
5
5
  }): VitePlugin;
@@ -1,2 +1,2 @@
1
- import { PageOptions } from '../vite-plugin-astro/types.js';
1
+ import type { PageOptions } from '../vite-plugin-astro/types.js';
2
2
  export declare function scan(code: string, id: string): Promise<PageOptions>;
@@ -1,5 +1,5 @@
1
- import { Plugin as VitePlugin } from 'vite';
2
- import { AstroSettings } from '../@types/astro.js';
1
+ import type { Plugin as VitePlugin } from 'vite';
2
+ import type { AstroSettings } from '../@types/astro.js';
3
3
  export declare const BEFORE_HYDRATION_SCRIPT_ID: string;
4
4
  export declare const PAGE_SCRIPT_ID: string;
5
5
  export declare const PAGE_SSR_SCRIPT_ID: string;
@@ -1,5 +1,5 @@
1
- import { Plugin as VitePlugin } from 'vite';
2
- import { AstroSettings } from '../@types/astro.js';
1
+ import { type Plugin as VitePlugin } from 'vite';
2
+ import type { AstroSettings } from '../@types/astro.js';
3
3
  export default function astroScriptsPostPlugin({ settings, }: {
4
4
  settings: AstroSettings;
5
5
  }): VitePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
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",
@@ -53,6 +53,8 @@
53
53
  "./assets/services/sharp": "./dist/assets/services/sharp.js",
54
54
  "./assets/services/squoosh": "./dist/assets/services/squoosh.js",
55
55
  "./content/internal": "./dist/content/internal.js",
56
+ "./content/runtime": "./dist/content/runtime.js",
57
+ "./content/runtime-assets": "./dist/content/runtime-assets.js",
56
58
  "./debug": "./components/Debug.astro",
57
59
  "./internal/*": "./dist/runtime/server/*",
58
60
  "./package.json": "./package.json",
@@ -93,7 +95,7 @@
93
95
  "dependencies": {
94
96
  "@astrojs/compiler": "^1.2.0",
95
97
  "@astrojs/language-server": "^0.28.3",
96
- "@astrojs/markdown-remark": "^2.1.0",
98
+ "@astrojs/markdown-remark": "^2.1.1",
97
99
  "@astrojs/telemetry": "^2.1.0",
98
100
  "@astrojs/webapi": "^2.1.0",
99
101
  "@babel/core": "^7.18.2",
@@ -121,7 +123,6 @@
121
123
  "github-slugger": "^2.0.0",
122
124
  "gray-matter": "^4.0.3",
123
125
  "html-escaper": "^3.0.3",
124
- "image-size": "^1.0.2",
125
126
  "kleur": "^4.1.4",
126
127
  "magic-string": "^0.27.0",
127
128
  "mime": "^3.0.0",
@@ -201,9 +202,9 @@
201
202
  },
202
203
  "scripts": {
203
204
  "prebuild": "astro-scripts prebuild --to-string \"src/runtime/server/astro-island.ts\" \"src/runtime/client/{idle,load,media,only,visible}.ts\"",
204
- "build": "pnpm run prebuild && astro-scripts build \"src/**/*.ts\" && tsc && pnpm run postbuild",
205
- "build:ci": "pnpm run prebuild && astro-scripts build \"src/**/*.ts\"",
206
- "dev": "astro-scripts dev --copy-wasm --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.ts\"",
205
+ "build": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" && tsc && pnpm run postbuild",
206
+ "build:ci": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" && pnpm run postbuild",
207
+ "dev": "astro-scripts dev --copy-wasm --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.{ts,js}\"",
207
208
  "postbuild": "astro-scripts copy \"src/**/*.astro\" && astro-scripts copy \"src/**/*.wasm\"",
208
209
  "test:unit": "mocha --exit --timeout 30000 ./test/units/**/*.test.js",
209
210
  "test:unit:match": "mocha --exit --timeout 30000 ./test/units/**/*.test.js -g",
@@ -13,11 +13,22 @@ declare module 'astro:content' {
13
13
  export type CollectionEntry<C extends keyof typeof entryMap> =
14
14
  (typeof entryMap)[C][keyof (typeof entryMap)[C]];
15
15
 
16
+ // This needs to be in sync with ImageMetadata
16
17
  export const image: () => import('astro/zod').ZodObject<{
17
18
  src: import('astro/zod').ZodString;
18
19
  width: import('astro/zod').ZodNumber;
19
20
  height: import('astro/zod').ZodNumber;
20
- format: import('astro/zod').ZodString;
21
+ format: import('astro/zod').ZodUnion<
22
+ [
23
+ import('astro/zod').ZodLiteral<'png'>,
24
+ import('astro/zod').ZodLiteral<'jpg'>,
25
+ import('astro/zod').ZodLiteral<'jpeg'>,
26
+ import('astro/zod').ZodLiteral<'tiff'>,
27
+ import('astro/zod').ZodLiteral<'webp'>,
28
+ import('astro/zod').ZodLiteral<'gif'>,
29
+ import('astro/zod').ZodLiteral<'svg'>
30
+ ]
31
+ >;
21
32
  }>;
22
33
 
23
34
  type BaseSchemaWithoutEffects =
@@ -0,0 +1,7 @@
1
+ import { createImage } from 'astro/content/runtime-assets';
2
+
3
+ const assetsDir = '@@ASSETS_DIR@@';
4
+
5
+ export const image = createImage({
6
+ assetsDir,
7
+ });
@@ -3,8 +3,7 @@ import {
3
3
  createCollectionToGlobResultMap,
4
4
  createGetCollection,
5
5
  createGetEntryBySlug,
6
- createImage,
7
- } from 'astro/content/internal';
6
+ } from 'astro/content/runtime';
8
7
 
9
8
  export { z } from 'astro/zod';
10
9
 
@@ -13,7 +12,6 @@ export function defineCollection(config) {
13
12
  }
14
13
 
15
14
  const contentDir = '@@CONTENT_DIR@@';
16
- const assetsDir = '@@ASSETS_DIR@@';
17
15
 
18
16
  const entryGlob = import.meta.glob('@@ENTRY_GLOB_PATH@@', {
19
17
  query: { astroContent: true },
@@ -40,7 +38,3 @@ export const getEntryBySlug = createGetEntryBySlug({
40
38
  getCollection,
41
39
  collectionToRenderEntryMap,
42
40
  });
43
-
44
- export const image = createImage({
45
- assetsDir,
46
- });
@@ -22,6 +22,9 @@
22
22
  "baseUrl": ".",
23
23
  "paths": {
24
24
  "~/assets/*": ["src/assets/*"]
25
- }
25
+ },
26
+ // TypeScript 5.0 changed how `isolatedModules` and `importsNotUsedAsValues` works, deprecating the later
27
+ // Until the majority of users are on TypeScript 5.0, we'll have to supress those deprecation errors
28
+ "ignoreDeprecations": "5.0"
26
29
  }
27
30
  }