astro 2.0.17 → 2.1.0

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 (142) hide show
  1. package/README.md +3 -3
  2. package/client-base.d.ts +27 -0
  3. package/client-image.d.ts +48 -0
  4. package/components/Image.astro +28 -0
  5. package/dist/@types/astro.d.ts +101 -1
  6. package/dist/assets/consts.d.ts +4 -0
  7. package/dist/assets/consts.js +20 -0
  8. package/dist/assets/image-endpoint.d.ts +5 -0
  9. package/dist/assets/image-endpoint.js +50 -0
  10. package/dist/assets/index.d.ts +4 -0
  11. package/dist/assets/index.js +10 -0
  12. package/dist/assets/internal.d.ts +36 -0
  13. package/dist/assets/internal.js +70 -0
  14. package/dist/assets/services/service.d.ts +71 -0
  15. package/dist/assets/services/service.js +88 -0
  16. package/dist/assets/services/sharp.d.ts +3 -0
  17. package/dist/assets/services/sharp.js +57 -0
  18. package/dist/assets/services/squoosh.d.ts +3 -0
  19. package/dist/assets/services/squoosh.js +56 -0
  20. package/dist/assets/services/vendor/squoosh/avif/avif_enc.d.js +11 -0
  21. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.d.ts +2 -0
  22. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +1628 -0
  23. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm +0 -0
  24. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.d.ts +2 -0
  25. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +1850 -0
  26. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm +0 -0
  27. package/dist/assets/services/vendor/squoosh/codecs.d.ts +158 -0
  28. package/dist/assets/services/vendor/squoosh/codecs.js +284 -0
  29. package/dist/assets/services/vendor/squoosh/copy-wasm.d.ts +1 -0
  30. package/dist/assets/services/vendor/squoosh/copy-wasm.js +24 -0
  31. package/dist/assets/services/vendor/squoosh/emscripten-types.d.js +0 -0
  32. package/dist/assets/services/vendor/squoosh/emscripten-utils.d.ts +9 -0
  33. package/dist/assets/services/vendor/squoosh/emscripten-utils.js +33 -0
  34. package/dist/assets/services/vendor/squoosh/image-pool.d.ts +4 -0
  35. package/dist/assets/services/vendor/squoosh/image-pool.js +94 -0
  36. package/dist/assets/services/vendor/squoosh/image.d.ts +14 -0
  37. package/dist/assets/services/vendor/squoosh/image.js +27 -0
  38. package/dist/assets/services/vendor/squoosh/image_data.d.ts +9 -0
  39. package/dist/assets/services/vendor/squoosh/image_data.js +22 -0
  40. package/dist/assets/services/vendor/squoosh/impl.d.ts +22 -0
  41. package/dist/assets/services/vendor/squoosh/impl.js +110 -0
  42. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_enc.d.js +11 -0
  43. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.d.ts +2 -0
  44. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +1631 -0
  45. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm +0 -0
  46. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.d.ts +2 -0
  47. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +1737 -0
  48. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm +0 -0
  49. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.d.ts +10 -0
  50. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.js +89 -0
  51. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm +0 -0
  52. package/dist/assets/services/vendor/squoosh/png/squoosh_png.d.ts +15 -0
  53. package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +138 -0
  54. package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm +0 -0
  55. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.d.ts +15 -0
  56. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.js +95 -0
  57. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm +0 -0
  58. package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm +0 -0
  59. package/dist/assets/services/vendor/squoosh/utils/execOnce.d.ts +1 -0
  60. package/dist/assets/services/vendor/squoosh/utils/execOnce.js +14 -0
  61. package/dist/assets/services/vendor/squoosh/utils/workerPool.d.ts +22 -0
  62. package/dist/assets/services/vendor/squoosh/utils/workerPool.js +95 -0
  63. package/dist/assets/services/vendor/squoosh/webp/webp_enc.d.js +4 -0
  64. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.d.ts +2 -0
  65. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +1473 -0
  66. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm +0 -0
  67. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.d.ts +2 -0
  68. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +1640 -0
  69. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm +0 -0
  70. package/dist/assets/types.d.ts +119 -0
  71. package/dist/assets/types.js +0 -0
  72. package/dist/assets/utils/etag.d.ts +12 -0
  73. package/dist/assets/utils/etag.js +28 -0
  74. package/dist/assets/utils/metadata.d.ts +6 -0
  75. package/dist/assets/utils/metadata.js +30 -0
  76. package/dist/assets/utils/queryParams.d.ts +2 -0
  77. package/dist/assets/utils/queryParams.js +16 -0
  78. package/dist/assets/utils/transformToPath.d.ts +2 -0
  79. package/dist/assets/utils/transformToPath.js +17 -0
  80. package/dist/assets/vite-plugin-assets.d.ts +5 -0
  81. package/dist/assets/vite-plugin-assets.js +187 -0
  82. package/dist/cli/check/index.d.ts +81 -2
  83. package/dist/cli/check/index.js +190 -44
  84. package/dist/cli/index.js +39 -16
  85. package/dist/cli/telemetry.js +1 -1
  86. package/dist/content/consts.d.ts +0 -1
  87. package/dist/content/consts.js +1 -3
  88. package/dist/content/internal.d.ts +7 -0
  89. package/dist/content/internal.js +27 -5
  90. package/dist/content/template/virtual-mod.d.mts +1 -0
  91. package/dist/content/types-generator.js +25 -10
  92. package/dist/content/utils.d.ts +16 -13
  93. package/dist/content/utils.js +29 -6
  94. package/dist/content/vite-plugin-content-assets.d.ts +3 -1
  95. package/dist/content/vite-plugin-content-assets.js +10 -6
  96. package/dist/content/vite-plugin-content-imports.js +54 -27
  97. package/dist/content/vite-plugin-content-virtual-mod.js +7 -4
  98. package/dist/core/add/index.js +2 -1
  99. package/dist/core/app/index.js +104 -134
  100. package/dist/core/build/generate.js +30 -5
  101. package/dist/core/build/index.d.ts +2 -0
  102. package/dist/core/build/index.js +16 -0
  103. package/dist/core/build/plugins/plugin-ssr.js +3 -5
  104. package/dist/core/config/config.js +2 -1
  105. package/dist/core/config/schema.d.ts +64 -8
  106. package/dist/core/config/schema.js +17 -3
  107. package/dist/core/config/settings.js +4 -2
  108. package/dist/core/constants.js +1 -1
  109. package/dist/core/cookies/cookies.js +36 -68
  110. package/dist/core/create-vite.js +5 -1
  111. package/dist/core/dev/dev.d.ts +2 -2
  112. package/dist/core/dev/dev.js +24 -4
  113. package/dist/core/errors/dev/vite.js +6 -1
  114. package/dist/core/errors/errors-data.d.ts +17 -1
  115. package/dist/core/errors/errors-data.js +16 -0
  116. package/dist/core/messages.js +2 -2
  117. package/dist/core/path.d.ts +1 -0
  118. package/dist/core/path.js +4 -0
  119. package/dist/core/preview/index.d.ts +3 -1
  120. package/dist/core/preview/index.js +16 -1
  121. package/dist/core/render/dev/css.js +2 -2
  122. package/dist/core/render/dev/environment.js +1 -5
  123. package/dist/core/render/environment.js +1 -2
  124. package/dist/core/render/result.js +13 -35
  125. package/dist/core/sync/index.d.ts +18 -5
  126. package/dist/core/sync/index.js +13 -1
  127. package/dist/integrations/index.js +12 -1
  128. package/dist/runtime/server/render/component.js +1 -1
  129. package/dist/runtime/server/response.js +11 -30
  130. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  131. package/dist/vite-plugin-astro-server/plugin.js +1 -1
  132. package/dist/vite-plugin-env/index.js +4 -4
  133. package/dist/vite-plugin-inject-env-ts/index.js +17 -2
  134. package/dist/vite-plugin-markdown/content-entry-type.d.ts +7 -0
  135. package/dist/vite-plugin-markdown/content-entry-type.js +39 -0
  136. package/dist/vite-plugin-markdown/index.js +70 -4
  137. package/dist/vite-plugin-ssr-manifest/index.d.ts +2 -0
  138. package/dist/vite-plugin-ssr-manifest/index.js +25 -0
  139. package/package.json +26 -9
  140. package/src/content/template/types.d.ts +18 -9
  141. package/src/content/template/virtual-mod.mjs +6 -0
  142. package/tsconfigs/base.json +6 -1
@@ -64,7 +64,7 @@ export declare const AstroErrorData: {
64
64
  * @description
65
65
  * The `Astro.clientAddress` property is only available when [Server-side rendering](https://docs.astro.build/en/guides/server-side-rendering/) is enabled.
66
66
  *
67
- * To get the user's IP address in static mode, different APIs such as [Ipify](https://www.ipify.org/) can be used in a [Client-side script](https://docs.astro.build/en/core-concepts/astro-components/#client-side-scripts) or it may be possible to get the user's IP using a serverless function hosted on your hosting provider.
67
+ * To get the user's IP address in static mode, different APIs such as [Ipify](https://www.ipify.org/) can be used in a [Client-side script](https://docs.astro.build/en/guides/client-side-scripts/) or it may be possible to get the user's IP using a serverless function hosted on your hosting provider.
68
68
  */
69
69
  readonly StaticClientAddressNotAvailable: {
70
70
  readonly title: "`Astro.clientAddress` is not available in static mode.";
@@ -397,6 +397,22 @@ export declare const AstroErrorData: {
397
397
  readonly message: (paramName: string) => string;
398
398
  readonly hint: "Rename your file to `[page].astro` or `[...page].astro`.";
399
399
  };
400
+ readonly ImageMissingAlt: {
401
+ readonly title: "Missing alt property";
402
+ readonly code: 3022;
403
+ readonly message: "The alt property is required.";
404
+ readonly hint: "The `alt` property is important for the purpose of accessibility, without it users using screen readers or other assistive technologies won't be able to understand what your image is supposed to represent. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt for more information.";
405
+ };
406
+ readonly InvalidImageService: {
407
+ readonly title: "Error while loading image service";
408
+ readonly code: 3023;
409
+ readonly message: "There was an error loading the configured image service. Please see the stack trace for more information";
410
+ };
411
+ readonly MissingImageDimension: {
412
+ readonly title: "Missing image dimensions";
413
+ readonly code: 3024;
414
+ readonly message: (missingDimension: 'width' | 'height' | 'both') => string;
415
+ };
400
416
  /**
401
417
  * @docs
402
418
  * @see
@@ -145,6 +145,22 @@ Expected \`true\` value but got \`${suffix}\`.`;
145
145
  message: (paramName) => `[paginate()] page number param \`${paramName}\` not found in your filepath.`,
146
146
  hint: "Rename your file to `[page].astro` or `[...page].astro`."
147
147
  },
148
+ ImageMissingAlt: {
149
+ title: "Missing alt property",
150
+ code: 3022,
151
+ message: "The alt property is required.",
152
+ hint: "The `alt` property is important for the purpose of accessibility, without it users using screen readers or other assistive technologies won't be able to understand what your image is supposed to represent. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt for more information."
153
+ },
154
+ InvalidImageService: {
155
+ title: "Error while loading image service",
156
+ code: 3023,
157
+ message: "There was an error loading the configured image service. Please see the stack trace for more information"
158
+ },
159
+ MissingImageDimension: {
160
+ title: "Missing image dimensions",
161
+ code: 3024,
162
+ message: (missingDimension) => `For remote images, ${missingDimension === "both" ? "width and height are" : `${missingDimension} is`} required.`
163
+ },
148
164
  UnknownViteError: {
149
165
  title: "Unknown Vite Error.",
150
166
  code: 4e3
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.0.17";
50
+ const version = "2.1.0";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
53
53
  const emptyPrefix = " ".repeat(11);
@@ -233,7 +233,7 @@ function printHelp({
233
233
  message.push(
234
234
  linebreak(),
235
235
  ` ${bgGreen(black(` ${commandName} `))} ${green(
236
- `v${"2.0.17"}`
236
+ `v${"2.1.0"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -12,3 +12,4 @@ export declare function isRelativePath(path: string): boolean;
12
12
  export declare function joinPaths(...paths: (string | undefined)[]): string;
13
13
  export declare function removeFileExtension(path: string): string;
14
14
  export declare function removeQueryString(path: string): string;
15
+ export declare function isRemotePath(src: string): boolean;
package/dist/core/path.js CHANGED
@@ -50,10 +50,14 @@ function removeQueryString(path) {
50
50
  const index = path.lastIndexOf("?");
51
51
  return index > 0 ? path.substring(0, index) : path;
52
52
  }
53
+ function isRemotePath(src) {
54
+ return /^(http|ftp|https):?\/\//.test(src) || src.startsWith("data:");
55
+ }
53
56
  export {
54
57
  appendExtension,
55
58
  appendForwardSlash,
56
59
  isRelativePath,
60
+ isRemotePath,
57
61
  joinPaths,
58
62
  prependForwardSlash,
59
63
  removeFileExtension,
@@ -1,10 +1,12 @@
1
1
  import type { AstroTelemetry } from '@astrojs/telemetry';
2
+ import type { Arguments } from 'yargs-parser';
2
3
  import type { AstroSettings, PreviewServer } from '../../@types/astro';
3
4
  import type { LogOptions } from '../logger/core';
4
5
  interface PreviewOptions {
5
6
  logging: LogOptions;
6
7
  telemetry: AstroTelemetry;
8
+ flags?: Arguments;
7
9
  }
8
10
  /** The primary dev action */
9
- export default function preview(_settings: AstroSettings, { logging }: PreviewOptions): Promise<PreviewServer>;
11
+ export default function preview(_settings: AstroSettings, { logging, flags }: PreviewOptions): Promise<PreviewServer | undefined>;
10
12
  export {};
@@ -1,9 +1,24 @@
1
+ import { cyan } from "kleur/colors";
1
2
  import { createRequire } from "module";
2
3
  import { pathToFileURL } from "url";
3
4
  import { runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
5
+ import { printHelp } from "../messages.js";
4
6
  import createStaticPreviewServer from "./static-preview-server.js";
5
7
  import { getResolvedHostForHttpServer } from "./util.js";
6
- async function preview(_settings, { logging }) {
8
+ async function preview(_settings, { logging, flags }) {
9
+ if ((flags == null ? void 0 : flags.help) || (flags == null ? void 0 : flags.h)) {
10
+ printHelp({
11
+ commandName: "astro preview",
12
+ usage: "[...flags]",
13
+ tables: {
14
+ Flags: [["--help (-h)", "See all available flags."]]
15
+ },
16
+ description: `Starts a local server to serve your static dist/ directory. Check ${cyan(
17
+ "https://docs.astro.build/en/reference/cli-reference/#astro-preview"
18
+ )} for more information.`
19
+ });
20
+ return;
21
+ }
7
22
  const settings = await runHookConfigSetup({
8
23
  settings: _settings,
9
24
  command: "preview",
@@ -1,11 +1,11 @@
1
1
  import { viteID } from "../../util.js";
2
- import { isCSSRequest } from "./util.js";
2
+ import { isBuildableCSSRequest } from "./util.js";
3
3
  import { crawlGraph } from "./vite.js";
4
4
  async function getStylesForURL(filePath, loader, mode) {
5
5
  const importedCssUrls = /* @__PURE__ */ new Set();
6
6
  const importedStylesMap = /* @__PURE__ */ new Map();
7
7
  for await (const importedModule of crawlGraph(loader, viteID(filePath), true)) {
8
- if (isCSSRequest(importedModule.url)) {
8
+ if (isBuildableCSSRequest(importedModule.url)) {
9
9
  let ssrModule;
10
10
  try {
11
11
  ssrModule = importedModule.ssrModule ?? await loader.import(importedModule.url);
@@ -1,4 +1,3 @@
1
- import { getContentPaths } from "../../../content/index.js";
2
1
  import { createEnvironment } from "../index.js";
3
2
  import { RouteCache } from "../route-cache.js";
4
3
  import { createResolve } from "./resolve.js";
@@ -8,10 +7,7 @@ function createDevelopmentEnvironment(settings, logging, loader) {
8
7
  let env = createEnvironment({
9
8
  adapterName: (_a = settings.adapter) == null ? void 0 : _a.name,
10
9
  logging,
11
- markdown: {
12
- ...settings.config.markdown,
13
- contentDir: getContentPaths(settings.config).contentDir
14
- },
10
+ markdown: settings.config.markdown,
15
11
  mode,
16
12
  renderers: [],
17
13
  resolve: createResolve(loader, settings.config.root),
@@ -7,8 +7,7 @@ function createBasicEnvironment(options) {
7
7
  return createEnvironment({
8
8
  ...options,
9
9
  markdown: {
10
- ...options.markdown ?? {},
11
- contentDir: new URL("file:///src/content/")
10
+ ...options.markdown ?? {}
12
11
  },
13
12
  mode,
14
13
  renderers: options.renderers ?? [],
@@ -1,22 +1,3 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var _result, _slots, _loggingOpts;
20
1
  import {
21
2
  createScopedResult,
22
3
  renderSlot,
@@ -45,13 +26,13 @@ function getFunctionExpression(slot) {
45
26
  return slot.expressions[0];
46
27
  }
47
28
  class Slots {
29
+ #result;
30
+ #slots;
31
+ #loggingOpts;
48
32
  constructor(result, slots, logging) {
49
- __privateAdd(this, _result, void 0);
50
- __privateAdd(this, _slots, void 0);
51
- __privateAdd(this, _loggingOpts, void 0);
52
- __privateSet(this, _result, result);
53
- __privateSet(this, _slots, slots);
54
- __privateSet(this, _loggingOpts, logging);
33
+ this.#result = result;
34
+ this.#slots = slots;
35
+ this.#loggingOpts = logging;
55
36
  if (slots) {
56
37
  for (const key of Object.keys(slots)) {
57
38
  if (this[key] !== void 0) {
@@ -70,22 +51,22 @@ class Slots {
70
51
  }
71
52
  }
72
53
  has(name) {
73
- if (!__privateGet(this, _slots))
54
+ if (!this.#slots)
74
55
  return false;
75
- return Boolean(__privateGet(this, _slots)[name]);
56
+ return Boolean(this.#slots[name]);
76
57
  }
77
58
  async render(name, args = []) {
78
- if (!__privateGet(this, _slots) || !this.has(name))
59
+ if (!this.#slots || !this.has(name))
79
60
  return;
80
- const scoped = createScopedResult(__privateGet(this, _result), ScopeFlags.RenderSlot);
61
+ const scoped = createScopedResult(this.#result, ScopeFlags.RenderSlot);
81
62
  if (!Array.isArray(args)) {
82
63
  warn(
83
- __privateGet(this, _loggingOpts),
64
+ this.#loggingOpts,
84
65
  "Astro.slots.render",
85
66
  `Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
86
67
  );
87
68
  } else if (args.length > 0) {
88
- const slotValue = __privateGet(this, _slots)[name];
69
+ const slotValue = this.#slots[name];
89
70
  const component = typeof slotValue === "function" ? await slotValue(scoped) : await slotValue;
90
71
  const expression = getFunctionExpression(component);
91
72
  if (expression) {
@@ -98,14 +79,11 @@ class Slots {
98
79
  );
99
80
  }
100
81
  }
101
- const content = await renderSlot(scoped, __privateGet(this, _slots)[name]);
82
+ const content = await renderSlot(scoped, this.#slots[name]);
102
83
  const outHTML = stringifyChunk(scoped, content);
103
84
  return outHTML;
104
85
  }
105
86
  }
106
- _result = new WeakMap();
107
- _slots = new WeakMap();
108
- _loggingOpts = new WeakMap();
109
87
  let renderMarkdown = null;
110
88
  function createResult(args) {
111
89
  const { markdown, params, pathname, renderers, request, resolve } = args;
@@ -1,14 +1,27 @@
1
1
  /// <reference types="node" />
2
2
  import type fsMod from 'node:fs';
3
+ import type { Arguments } from 'yargs-parser';
3
4
  import type { AstroSettings } from '../../@types/astro';
4
5
  import { LogOptions } from '../logger/core.js';
5
- type ProcessExit = 0 | 1;
6
- export declare function syncCli(settings: AstroSettings, { logging, fs }: {
6
+ export type ProcessExit = 0 | 1;
7
+ export type SyncOptions = {
7
8
  logging: LogOptions;
8
9
  fs: typeof fsMod;
9
- }): Promise<ProcessExit>;
10
- export declare function sync(settings: AstroSettings, { logging, fs }: {
10
+ };
11
+ export declare function syncCli(settings: AstroSettings, { logging, fs, flags }: {
11
12
  logging: LogOptions;
12
13
  fs: typeof fsMod;
14
+ flags?: Arguments;
13
15
  }): Promise<ProcessExit>;
14
- export {};
16
+ /**
17
+ * Generate content collection types, and then returns the process exit signal.
18
+ *
19
+ * A non-zero process signal is emitted in case there's an error while generating content collection types.
20
+ *
21
+ * @param {SyncOptions} options
22
+ * @param {AstroSettings} settings Astro settings
23
+ * @param {typeof fsMod} options.fs The file system
24
+ * @param {LogOptions} options.logging Logging options
25
+ * @return {Promise<ProcessExit>}
26
+ */
27
+ export declare function sync(settings: AstroSettings, { logging, fs }: SyncOptions): Promise<ProcessExit>;
@@ -9,7 +9,19 @@ import { getTimeStat } from "../build/util.js";
9
9
  import { createVite } from "../create-vite.js";
10
10
  import { AstroError, AstroErrorData } from "../errors/index.js";
11
11
  import { info } from "../logger/core.js";
12
- async function syncCli(settings, { logging, fs }) {
12
+ import { printHelp } from "../messages.js";
13
+ async function syncCli(settings, { logging, fs, flags }) {
14
+ if ((flags == null ? void 0 : flags.help) || (flags == null ? void 0 : flags.h)) {
15
+ printHelp({
16
+ commandName: "astro sync",
17
+ usage: "[...flags]",
18
+ tables: {
19
+ Flags: [["--help (-h)", "See all available flags."]]
20
+ },
21
+ description: `Generates TypeScript types for all Astro modules.`
22
+ });
23
+ return 0;
24
+ }
13
25
  const resolvedSettings = await runHookConfigSetup({
14
26
  settings,
15
27
  logging,
@@ -3,6 +3,7 @@ import fs from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { mergeConfig } from "../core/config/config.js";
5
5
  import { info } from "../core/logger/core.js";
6
+ import { mdxContentEntryType } from "../vite-plugin-markdown/content-entry-type.js";
6
7
  async function withTakingALongTimeMsg({
7
8
  name,
8
9
  hookResult,
@@ -33,8 +34,10 @@ async function runHookConfigSetup({
33
34
  let addPageExtension2 = function(...input) {
34
35
  const exts = input.flat(Infinity).map((ext) => `.${ext.replace(/^\./, "")}`);
35
36
  updatedSettings.pageExtensions.push(...exts);
37
+ }, addContentEntryType2 = function(contentEntryType) {
38
+ updatedSettings.contentEntryTypes.push(contentEntryType);
36
39
  };
37
- var addPageExtension = addPageExtension2;
40
+ var addPageExtension = addPageExtension2, addContentEntryType = addContentEntryType2;
38
41
  const hooks = {
39
42
  config: updatedConfig,
40
43
  command,
@@ -66,11 +69,19 @@ async function runHookConfigSetup({
66
69
  writable: false,
67
70
  enumerable: false
68
71
  });
72
+ Object.defineProperty(hooks, "addContentEntryType", {
73
+ value: addContentEntryType2,
74
+ writable: false,
75
+ enumerable: false
76
+ });
69
77
  await withTakingALongTimeMsg({
70
78
  name: integration.name,
71
79
  hookResult: integration.hooks["astro:config:setup"](hooks),
72
80
  logging
73
81
  });
82
+ if (integration.name === "@astrojs/mdx" && !updatedSettings.contentEntryTypes.find((c) => c.extensions.includes(".mdx"))) {
83
+ addContentEntryType2(mdxContentEntryType);
84
+ }
74
85
  }
75
86
  }
76
87
  updatedSettings.config = updatedConfig;
@@ -85,7 +85,7 @@ Did you forget to import the component or is it possible there is a typo?`
85
85
  break;
86
86
  }
87
87
  } catch (e) {
88
- error ?? (error = e);
88
+ error ??= e;
89
89
  }
90
90
  }
91
91
  if (!renderer && error) {
@@ -1,42 +1,23 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
1
  import { streamAsyncIterator } from "./util.js";
20
2
  const isNodeJS = typeof process === "object" && Object.prototype.toString.call(process) === "[object process]";
21
3
  let StreamingCompatibleResponse;
22
4
  function createResponseClass() {
23
- var _isStream, _body, _a;
24
- StreamingCompatibleResponse = (_a = class extends Response {
5
+ StreamingCompatibleResponse = class extends Response {
6
+ #isStream;
7
+ #body;
25
8
  constructor(body, init) {
26
9
  let isStream = body instanceof ReadableStream;
27
10
  super(isStream ? null : body, init);
28
- __privateAdd(this, _isStream, void 0);
29
- __privateAdd(this, _body, void 0);
30
- __privateSet(this, _isStream, isStream);
31
- __privateSet(this, _body, body);
11
+ this.#isStream = isStream;
12
+ this.#body = body;
32
13
  }
33
14
  get body() {
34
- return __privateGet(this, _body);
15
+ return this.#body;
35
16
  }
36
17
  async text() {
37
- if (__privateGet(this, _isStream) && isNodeJS) {
18
+ if (this.#isStream && isNodeJS) {
38
19
  let decoder = new TextDecoder();
39
- let body = __privateGet(this, _body);
20
+ let body = this.#body;
40
21
  let out = "";
41
22
  for await (let chunk of streamAsyncIterator(body)) {
42
23
  out += decoder.decode(chunk);
@@ -46,8 +27,8 @@ function createResponseClass() {
46
27
  return super.text();
47
28
  }
48
29
  async arrayBuffer() {
49
- if (__privateGet(this, _isStream) && isNodeJS) {
50
- let body = __privateGet(this, _body);
30
+ if (this.#isStream && isNodeJS) {
31
+ let body = this.#body;
51
32
  let chunks = [];
52
33
  let len = 0;
53
34
  for await (let chunk of streamAsyncIterator(body)) {
@@ -64,7 +45,7 @@ function createResponseClass() {
64
45
  }
65
46
  return super.arrayBuffer();
66
47
  }
67
- }, _isStream = new WeakMap(), _body = new WeakMap(), _a);
48
+ };
68
49
  return StreamingCompatibleResponse;
69
50
  }
70
51
  const createResponse = isNodeJS ? (body, init) => {
@@ -25,7 +25,7 @@ function astro(_opts) {
25
25
  const firstArgEnd = node.arguments[0].end;
26
26
  const lastArgEnd = node.arguments[node.arguments.length - 1].end;
27
27
  const firstArg = code.slice(firstArgStart, firstArgEnd);
28
- s ?? (s = new MagicString(code));
28
+ s ??= new MagicString(code);
29
29
  s.overwrite(
30
30
  firstArgStart,
31
31
  lastArgEnd,
@@ -33,7 +33,7 @@ function createVitePluginAstroServer({
33
33
  handle: baseMiddleware(settings, logging)
34
34
  });
35
35
  }
36
- viteServer.middlewares.use(async (req, res) => {
36
+ viteServer.middlewares.use(async function astroDevHandler(req, res) {
37
37
  if (req.url === void 0 || !req.method) {
38
38
  res.writeHead(500, "Incomplete request");
39
39
  res.end();
@@ -59,21 +59,21 @@ function envVitePlugin({ settings }) {
59
59
  while (match = pattern.exec(source)) {
60
60
  let replacement;
61
61
  if (match[0] === "import.meta.env") {
62
- privateEnv ?? (privateEnv = getPrivateEnv(viteConfig, astroConfig));
63
- references ?? (references = getReferencedPrivateKeys(source, privateEnv));
62
+ privateEnv ??= getPrivateEnv(viteConfig, astroConfig);
63
+ references ??= getReferencedPrivateKeys(source, privateEnv);
64
64
  replacement = `(Object.assign(import.meta.env,{`;
65
65
  for (const key of references.values()) {
66
66
  replacement += `${key}:${privateEnv[key]},`;
67
67
  }
68
68
  replacement += "}))";
69
69
  } else if (match[2]) {
70
- privateEnv ?? (privateEnv = getPrivateEnv(viteConfig, astroConfig));
70
+ privateEnv ??= getPrivateEnv(viteConfig, astroConfig);
71
71
  replacement = privateEnv[match[2]];
72
72
  }
73
73
  if (replacement) {
74
74
  const start = match.index;
75
75
  const end = start + match[0].length;
76
- s ?? (s = new MagicString(source));
76
+ s ??= new MagicString(source);
77
77
  s.overwrite(start, end, replacement);
78
78
  }
79
79
  }
@@ -32,9 +32,22 @@ async function setUpEnvTs({
32
32
  path.relative(fileURLToPath(settings.config.root), fileURLToPath(envTsPath))
33
33
  );
34
34
  if (fs.existsSync(envTsPath)) {
35
+ let typesEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
36
+ if (settings.config.experimental.assets && typesEnvContents.includes('types="astro/client"')) {
37
+ typesEnvContents = typesEnvContents.replace(
38
+ 'types="astro/client"',
39
+ 'types="astro/client-image"'
40
+ );
41
+ await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
42
+ } else if (typesEnvContents.includes('types="astro/client-image"')) {
43
+ typesEnvContents = typesEnvContents.replace(
44
+ 'types="astro/client-image"',
45
+ 'types="astro/client"'
46
+ );
47
+ await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
48
+ }
35
49
  if (!fs.existsSync(dotAstroDir))
36
50
  return;
37
- let typesEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
38
51
  const expectedTypeReference = getDotAstroTypeReference(settings.config);
39
52
  if (!typesEnvContents.includes(expectedTypeReference)) {
40
53
  typesEnvContents = `${expectedTypeReference}
@@ -44,7 +57,9 @@ ${typesEnvContents}`;
44
57
  }
45
58
  } else {
46
59
  let referenceDefs = [];
47
- if (settings.config.integrations.find((i) => i.name === "@astrojs/image")) {
60
+ if (settings.config.experimental.assets) {
61
+ referenceDefs.push('/// <reference types="astro/client-image" />');
62
+ } else if (settings.config.integrations.find((i) => i.name === "@astrojs/image")) {
48
63
  referenceDefs.push('/// <reference types="@astrojs/image/client" />');
49
64
  } else {
50
65
  referenceDefs.push('/// <reference types="astro/client" />');
@@ -0,0 +1,7 @@
1
+ import { ContentEntryType } from '../@types/astro.js';
2
+ export declare const markdownContentEntryType: ContentEntryType;
3
+ /**
4
+ * MDX content type for compatibility with older `@astrojs/mdx` versions
5
+ * TODO: remove in next Astro minor release
6
+ */
7
+ export declare const mdxContentEntryType: ContentEntryType;
@@ -0,0 +1,39 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { parseFrontmatter } from "../content/utils.js";
3
+ const markdownContentEntryType = {
4
+ extensions: [".md"],
5
+ async getEntryInfo({ fileUrl, contents }) {
6
+ const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
7
+ return {
8
+ data: parsed.data,
9
+ body: parsed.content,
10
+ slug: parsed.data.slug,
11
+ rawData: parsed.matter
12
+ };
13
+ }
14
+ };
15
+ const mdxContentEntryType = {
16
+ extensions: [".mdx"],
17
+ async getEntryInfo({ fileUrl, contents }) {
18
+ const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
19
+ return {
20
+ data: parsed.data,
21
+ body: parsed.content,
22
+ slug: parsed.data.slug,
23
+ rawData: parsed.matter
24
+ };
25
+ },
26
+ contentModuleTypes: `declare module 'astro:content' {
27
+ interface Render {
28
+ '.mdx': Promise<{
29
+ Content: import('astro').MarkdownInstance<{}>['Content'];
30
+ headings: import('astro').MarkdownHeading[];
31
+ remarkPluginFrontmatter: Record<string, any>;
32
+ }>;
33
+ }
34
+ }`
35
+ };
36
+ export {
37
+ markdownContentEntryType,
38
+ mdxContentEntryType
39
+ };