astro 2.9.7 → 3.0.0-beta.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 (161) hide show
  1. package/astro.js +2 -2
  2. package/components/ViewTransitions.astro +65 -12
  3. package/dist/@types/astro.d.ts +68 -7
  4. package/dist/@types/astro.js +1 -0
  5. package/dist/assets/generate.js +7 -3
  6. package/dist/assets/image-endpoint.d.ts +1 -1
  7. package/dist/assets/image-endpoint.js +3 -3
  8. package/dist/assets/internal.js +1 -2
  9. package/dist/assets/services/noop.d.ts +3 -0
  10. package/dist/assets/services/noop.js +17 -0
  11. package/dist/assets/services/vendor/squoosh/image_data.js +3 -0
  12. package/dist/assets/services/vendor/squoosh/impl.js +2 -3
  13. package/dist/assets/services/vendor/squoosh/utils/workerPool.js +4 -0
  14. package/dist/assets/vendor/image-size/types/tiff.js +1 -1
  15. package/dist/assets/vendor/queue/queue.d.ts +3 -3
  16. package/dist/assets/vite-plugin-assets.d.ts +1 -1
  17. package/dist/assets/vite-plugin-assets.js +1 -23
  18. package/dist/cli/add/index.js +6 -9
  19. package/dist/cli/build/index.js +1 -1
  20. package/dist/cli/check/index.d.ts +2 -78
  21. package/dist/cli/check/index.js +23 -275
  22. package/dist/cli/dev/index.js +1 -1
  23. package/dist/cli/index.js +7 -13
  24. package/dist/cli/info/index.js +3 -4
  25. package/dist/cli/install-package.d.ts +7 -0
  26. package/dist/cli/install-package.js +102 -0
  27. package/dist/cli/preview/index.js +1 -1
  28. package/dist/cli/sync/index.js +1 -1
  29. package/dist/content/runtime-assets.js +1 -2
  30. package/dist/content/runtime.js +3 -5
  31. package/dist/content/server-listeners.js +1 -2
  32. package/dist/content/types-generator.js +8 -8
  33. package/dist/content/utils.js +3 -4
  34. package/dist/content/vite-plugin-content-assets.js +4 -6
  35. package/dist/content/vite-plugin-content-imports.js +1 -1
  36. package/dist/content/vite-plugin-content-virtual-mod.js +5 -6
  37. package/dist/core/app/index.js +5 -3
  38. package/dist/core/app/node.d.ts +1 -1
  39. package/dist/core/app/node.js +7 -2
  40. package/dist/core/build/css-asset-name.js +2 -4
  41. package/dist/core/build/generate.js +10 -17
  42. package/dist/core/build/graph.js +3 -4
  43. package/dist/core/build/index.js +8 -1
  44. package/dist/core/build/internal.js +2 -2
  45. package/dist/core/build/plugin.js +2 -4
  46. package/dist/core/build/plugins/plugin-analyzer.js +6 -9
  47. package/dist/core/build/plugins/plugin-component-entry.js +2 -4
  48. package/dist/core/build/plugins/plugin-css.js +6 -9
  49. package/dist/core/build/plugins/plugin-hoisted-scripts.js +2 -3
  50. package/dist/core/build/plugins/plugin-internals.js +1 -2
  51. package/dist/core/build/plugins/plugin-pages.js +5 -1
  52. package/dist/core/build/plugins/plugin-ssr.js +12 -8
  53. package/dist/core/build/static-build.js +8 -12
  54. package/dist/core/client-directive/build.js +1 -2
  55. package/dist/core/compile/compile.js +2 -1
  56. package/dist/core/compile/style.js +2 -3
  57. package/dist/core/config/schema.d.ts +8 -0
  58. package/dist/core/config/schema.js +11 -3
  59. package/dist/core/config/settings.js +3 -3
  60. package/dist/core/config/timer.js +5 -6
  61. package/dist/core/constants.js +1 -1
  62. package/dist/core/cookies/cookies.d.ts +5 -5
  63. package/dist/core/cookies/cookies.js +9 -9
  64. package/dist/core/create-vite.js +6 -28
  65. package/dist/core/dev/container.d.ts +0 -1
  66. package/dist/core/dev/container.js +0 -5
  67. package/dist/core/dev/dev.js +2 -3
  68. package/dist/core/dev/index.d.ts +1 -1
  69. package/dist/core/dev/index.js +1 -2
  70. package/dist/core/dev/restart.d.ts +1 -4
  71. package/dist/core/dev/restart.js +15 -19
  72. package/dist/core/endpoint/dev/index.js +1 -1
  73. package/dist/core/endpoint/index.js +3 -4
  74. package/dist/core/errors/dev/utils.js +12 -16
  75. package/dist/core/errors/dev/vite.js +11 -13
  76. package/dist/core/errors/errors-data.d.ts +21 -0
  77. package/dist/core/errors/errors-data.js +21 -0
  78. package/dist/core/errors/errors.js +12 -17
  79. package/dist/core/errors/overlay.js +7 -8
  80. package/dist/core/errors/utils.js +1 -1
  81. package/dist/core/fs/index.js +1 -1
  82. package/dist/core/logger/console.js +1 -1
  83. package/dist/core/logger/core.d.ts +26 -6
  84. package/dist/core/logger/core.js +54 -8
  85. package/dist/core/logger/node.d.ts +4 -4
  86. package/dist/core/logger/node.js +6 -6
  87. package/dist/core/messages.js +4 -5
  88. package/dist/core/module-loader/vite.js +2 -2
  89. package/dist/core/polyfill.js +12 -4
  90. package/dist/core/redirects/helpers.js +3 -3
  91. package/dist/core/render/core.js +1 -4
  92. package/dist/core/render/params-and-props.js +2 -3
  93. package/dist/core/render/result.js +1 -2
  94. package/dist/core/render/route-cache.d.ts +1 -2
  95. package/dist/core/render/route-cache.js +6 -11
  96. package/dist/core/routing/manifest/create.js +2 -6
  97. package/dist/core/routing/params.js +1 -1
  98. package/dist/core/routing/validation.js +7 -8
  99. package/dist/core/sync/index.js +1 -1
  100. package/dist/core/util.js +1 -1
  101. package/dist/events/error.js +1 -1
  102. package/dist/events/session.js +12 -13
  103. package/dist/integrations/astroFeaturesValidation.d.ts +14 -0
  104. package/dist/integrations/astroFeaturesValidation.js +109 -0
  105. package/dist/integrations/index.d.ts +3 -1
  106. package/dist/integrations/index.js +96 -31
  107. package/dist/jsx/babel.js +1 -2
  108. package/dist/prerender/metadata.js +1 -2
  109. package/dist/runtime/client/hmr.js +1 -2
  110. package/dist/runtime/server/astro-component.js +1 -2
  111. package/dist/runtime/server/astro-island.js +53 -55
  112. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  113. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  114. package/dist/runtime/server/endpoint.d.ts +2 -1
  115. package/dist/runtime/server/endpoint.js +21 -27
  116. package/dist/runtime/server/hydration.js +9 -0
  117. package/dist/runtime/server/jsx.js +3 -2
  118. package/dist/runtime/server/render/astro/instance.js +6 -3
  119. package/dist/runtime/server/render/astro/render-template.js +4 -3
  120. package/dist/runtime/server/render/astro/render.js +3 -3
  121. package/dist/runtime/server/render/common.js +1 -1
  122. package/dist/runtime/server/render/component.js +11 -13
  123. package/dist/runtime/server/render/dom.js +1 -1
  124. package/dist/runtime/server/render/page.js +2 -3
  125. package/dist/runtime/server/render/slot.js +2 -1
  126. package/dist/runtime/server/render/util.js +1 -2
  127. package/dist/runtime/server/transition.d.ts +1 -0
  128. package/dist/runtime/server/transition.js +1 -0
  129. package/dist/transitions/vite-plugin-transitions.js +1 -0
  130. package/dist/vite-plugin-astro/compile.js +2 -3
  131. package/dist/vite-plugin-astro/hmr.js +3 -5
  132. package/dist/vite-plugin-astro/index.js +1 -1
  133. package/dist/vite-plugin-astro/metadata.js +1 -2
  134. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  135. package/dist/vite-plugin-astro-server/base.js +1 -2
  136. package/dist/vite-plugin-astro-server/controller.js +2 -3
  137. package/dist/vite-plugin-astro-server/css.js +1 -1
  138. package/dist/vite-plugin-astro-server/request.js +1 -1
  139. package/dist/vite-plugin-astro-server/route.js +1 -2
  140. package/dist/vite-plugin-astro-server/scripts.js +2 -3
  141. package/dist/vite-plugin-astro-server/vite.js +1 -1
  142. package/dist/vite-plugin-config-alias/index.js +1 -1
  143. package/dist/vite-plugin-env/index.js +2 -2
  144. package/dist/vite-plugin-head/index.js +4 -6
  145. package/dist/vite-plugin-html/index.js +1 -2
  146. package/dist/vite-plugin-html/transform/index.js +1 -1
  147. package/dist/vite-plugin-html/transform/slots.js +5 -6
  148. package/dist/vite-plugin-html/transform/utils.js +1 -2
  149. package/dist/vite-plugin-jsx/import-source.js +1 -2
  150. package/dist/vite-plugin-jsx/index.js +1 -1
  151. package/dist/vite-plugin-jsx/tag.js +4 -6
  152. package/dist/vite-plugin-markdown/index.js +1 -2
  153. package/dist/vite-plugin-scanner/index.js +2 -1
  154. package/dist/vite-plugin-scanner/scan.js +1 -1
  155. package/dist/vite-plugin-scripts/index.js +1 -1
  156. package/dist/vite-plugin-scripts/page-ssr.js +2 -2
  157. package/package.json +13 -22
  158. package/tsconfigs/base.json +8 -6
  159. package/tsconfigs/strict.json +2 -3
  160. package/dist/cli/check/print.d.ts +0 -2
  161. package/dist/cli/check/print.js +0 -95
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.9.7";
50
+ const version = "3.0.0-beta.0";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
53
53
  const emptyPrefix = " ".repeat(11);
@@ -162,7 +162,6 @@ ${errorList.join(
162
162
  )}`;
163
163
  }
164
164
  function formatErrorMessage(err, args = []) {
165
- var _a, _b, _c;
166
165
  const isOurError = AstroError.is(err) || CompilerError.is(err);
167
166
  args.push(
168
167
  `${bgRed(black(` error `))}${red(
@@ -175,11 +174,11 @@ function formatErrorMessage(err, args = []) {
175
174
  yellow(padMultilineString(isOurError ? renderErrorMarkdown(err.hint, "cli") : err.hint, 4))
176
175
  );
177
176
  }
178
- if (err.id || ((_a = err.loc) == null ? void 0 : _a.file)) {
177
+ if (err.id || err.loc?.file) {
179
178
  args.push(` ${bold("File:")}`);
180
179
  args.push(
181
180
  red(
182
- ` ${err.id ?? ((_b = err.loc) == null ? void 0 : _b.file)}${((_c = err.loc) == null ? void 0 : _c.line) && err.loc.column ? `:${err.loc.line}:${err.loc.column}` : ""}`
181
+ ` ${err.id ?? err.loc?.file}${err.loc?.line && err.loc.column ? `:${err.loc.line}:${err.loc.column}` : ""}`
183
182
  )
184
183
  );
185
184
  }
@@ -233,7 +232,7 @@ function printHelp({
233
232
  message.push(
234
233
  linebreak(),
235
234
  ` ${bgGreen(black(` ${commandName} `))} ${green(
236
- `v${"2.9.7"}`
235
+ `v${"3.0.0-beta.0"}`
237
236
  )} ${headline}`
238
237
  );
239
238
  }
@@ -5,7 +5,7 @@ function createViteLoader(viteServer) {
5
5
  viteServer.watcher.on("unlink", (...args) => events.emit("file-unlink", args));
6
6
  viteServer.watcher.on("change", (...args) => events.emit("file-change", args));
7
7
  wrapMethod(viteServer.ws, "send", (msg) => {
8
- if ((msg == null ? void 0 : msg.type) === "error") {
8
+ if (msg?.type === "error") {
9
9
  events.emit("hmr-error", msg);
10
10
  }
11
11
  });
@@ -15,7 +15,7 @@ function createViteLoader(viteServer) {
15
15
  },
16
16
  async resolveId(spec, parent) {
17
17
  const ret = await viteServer.pluginContainer.resolveId(spec, parent);
18
- return ret == null ? void 0 : ret.id;
18
+ return ret?.id;
19
19
  },
20
20
  getModuleById(id) {
21
21
  return viteServer.moduleGraph.getModuleById(id);
@@ -1,8 +1,16 @@
1
- import { polyfill } from "@astrojs/webapi";
1
+ import { File } from "node:buffer";
2
+ import crypto from "node:crypto";
2
3
  function apply() {
3
- polyfill(globalThis, {
4
- exclude: "window document"
5
- });
4
+ if (!globalThis.crypto) {
5
+ Object.defineProperty(globalThis, "crypto", {
6
+ value: crypto.webcrypto
7
+ });
8
+ }
9
+ if (!globalThis.File) {
10
+ Object.defineProperty(globalThis, "File", {
11
+ value: File
12
+ });
13
+ }
6
14
  }
7
15
  export {
8
16
  apply
@@ -1,11 +1,11 @@
1
1
  function routeIsRedirect(route) {
2
- return (route == null ? void 0 : route.type) === "redirect";
2
+ return route?.type === "redirect";
3
3
  }
4
4
  function redirectRouteGenerate(redirectRoute, data) {
5
5
  const routeData = redirectRoute.redirectRoute;
6
6
  const route = redirectRoute.redirect;
7
7
  if (typeof routeData !== "undefined") {
8
- return (routeData == null ? void 0 : routeData.generate(data)) || (routeData == null ? void 0 : routeData.pathname) || "/";
8
+ return routeData?.generate(data) || routeData?.pathname || "/";
9
9
  } else if (typeof route === "string") {
10
10
  return route;
11
11
  } else if (typeof route === "undefined") {
@@ -15,7 +15,7 @@ function redirectRouteGenerate(redirectRoute, data) {
15
15
  }
16
16
  function redirectRouteStatus(redirectRoute, method = "GET") {
17
17
  const routeData = redirectRoute.redirectRoute;
18
- if (typeof (routeData == null ? void 0 : routeData.redirect) === "object") {
18
+ if (typeof routeData?.redirect === "object") {
19
19
  return routeData.redirect.status;
20
20
  } else if (method !== "GET") {
21
21
  return 308;
@@ -37,10 +37,7 @@ async function renderPage({ mod, renderContext, env, cookies }) {
37
37
  cookies,
38
38
  locals: renderContext.locals ?? {}
39
39
  });
40
- if (typeof mod.components === "object") {
41
- Object.assign(renderContext.props, { components: mod.components });
42
- }
43
- let response = await runtimeRenderPage(
40
+ const response = await runtimeRenderPage(
44
41
  result,
45
42
  Component,
46
43
  renderContext.props,
@@ -1,6 +1,6 @@
1
1
  import { AstroError, AstroErrorData } from "../errors/index.js";
2
2
  import { getParams } from "../routing/params.js";
3
- import { callGetStaticPaths, findPathItemByKey } from "./route-cache.js";
3
+ import { RouteCache, callGetStaticPaths, findPathItemByKey } from "./route-cache.js";
4
4
  async function getParamsAndProps(opts) {
5
5
  const { logging, mod, route, routeCache, pathname, ssr } = opts;
6
6
  if (!route || route.pathname) {
@@ -12,7 +12,6 @@ async function getParamsAndProps(opts) {
12
12
  mod,
13
13
  route,
14
14
  routeCache,
15
- isValidate: true,
16
15
  logging,
17
16
  ssr
18
17
  });
@@ -24,7 +23,7 @@ async function getParamsAndProps(opts) {
24
23
  hint: AstroErrorData.NoMatchingStaticPathFound.hint([route.component])
25
24
  });
26
25
  }
27
- const props = (matchedStaticPath == null ? void 0 : matchedStaticPath.props) ? { ...matchedStaticPath.props } : {};
26
+ const props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {};
28
27
  return [params, props];
29
28
  }
30
29
  function getRouteParams(route, pathname) {
@@ -7,10 +7,9 @@ import { warn } from "../logger/core.js";
7
7
  const clientAddressSymbol = Symbol.for("astro.clientAddress");
8
8
  const responseSentSymbol = Symbol.for("astro.responseSent");
9
9
  function getFunctionExpression(slot) {
10
- var _a;
11
10
  if (!slot)
12
11
  return;
13
- if (((_a = slot.expressions) == null ? void 0 : _a.length) !== 1)
12
+ if (slot.expressions?.length !== 1)
14
13
  return;
15
14
  return slot.expressions[0];
16
15
  }
@@ -4,11 +4,10 @@ interface CallGetStaticPathsOptions {
4
4
  mod: ComponentInstance;
5
5
  route: RouteData;
6
6
  routeCache: RouteCache;
7
- isValidate: boolean;
8
7
  logging: LogOptions;
9
8
  ssr: boolean;
10
9
  }
11
- export declare function callGetStaticPaths({ mod, route, routeCache, isValidate, logging, ssr, }: CallGetStaticPathsOptions): Promise<GetStaticPathsResultKeyed>;
10
+ export declare function callGetStaticPaths({ mod, route, routeCache, logging, ssr, }: CallGetStaticPathsOptions): Promise<GetStaticPathsResultKeyed>;
12
11
  interface RouteCacheEntry {
13
12
  staticPaths: GetStaticPathsResultKeyed;
14
13
  }
@@ -7,12 +7,11 @@ async function callGetStaticPaths({
7
7
  mod,
8
8
  route,
9
9
  routeCache,
10
- isValidate,
11
10
  logging,
12
11
  ssr
13
12
  }) {
14
13
  const cached = routeCache.get(route);
15
- if (cached == null ? void 0 : cached.staticPaths)
14
+ if (cached?.staticPaths)
16
15
  return cached.staticPaths;
17
16
  validateDynamicRouteModule(mod, { ssr, route });
18
17
  if (ssr && !route.prerender) {
@@ -30,12 +29,7 @@ async function callGetStaticPaths({
30
29
  throw new AstroError(AstroErrorData.GetStaticPathsRemovedRSSHelper);
31
30
  }
32
31
  });
33
- if (Array.isArray(staticPaths)) {
34
- staticPaths = staticPaths.flat();
35
- }
36
- if (isValidate) {
37
- validateGetStaticPathsResult(staticPaths, logging, route);
38
- }
32
+ validateGetStaticPathsResult(staticPaths, logging, route);
39
33
  const keyedStaticPaths = staticPaths;
40
34
  keyedStaticPaths.keyed = /* @__PURE__ */ new Map();
41
35
  for (const sp of keyedStaticPaths) {
@@ -46,8 +40,10 @@ async function callGetStaticPaths({
46
40
  return keyedStaticPaths;
47
41
  }
48
42
  class RouteCache {
43
+ logging;
44
+ cache = {};
45
+ mode;
49
46
  constructor(logging, mode = "production") {
50
- this.cache = {};
51
47
  this.logging = logging;
52
48
  this.mode = mode;
53
49
  }
@@ -56,8 +52,7 @@ class RouteCache {
56
52
  this.cache = {};
57
53
  }
58
54
  set(route, entry) {
59
- var _a;
60
- if (this.mode === "production" && ((_a = this.cache[route.component]) == null ? void 0 : _a.staticPaths)) {
55
+ if (this.mode === "production" && this.cache[route.component]?.staticPaths) {
61
56
  warn(
62
57
  this.logging,
63
58
  "routeCache",
@@ -132,7 +132,6 @@ function injectedRouteToItem({ config, cwd }, { pattern, entryPoint }) {
132
132
  };
133
133
  }
134
134
  function createRouteManifest({ settings, cwd, fsMod }, logging) {
135
- var _a;
136
135
  const components = [];
137
136
  const routes = [];
138
137
  const validPageExtensions = /* @__PURE__ */ new Set([
@@ -245,7 +244,7 @@ function createRouteManifest({ settings, cwd, fsMod }, logging) {
245
244
  const pagesDirRootRelative = pages.href.slice(settings.config.root.href.length);
246
245
  warn(logging, "astro", `Missing pages directory: ${pagesDirRootRelative}`);
247
246
  }
248
- (_a = settings.injectedRoutes) == null ? void 0 : _a.sort(
247
+ settings.injectedRoutes?.sort(
249
248
  (a, b) => (
250
249
  // sort injected routes in the same way as user-defined routes
251
250
  comparator(injectedRouteToItem({ config, cwd }, a), injectedRouteToItem({ config, cwd }, b))
@@ -313,10 +312,7 @@ This route collides with: "${collision.component}".`
313
312
  redirect: to,
314
313
  redirectRoute: routes.find((r) => r.route === to)
315
314
  };
316
- const lastSegmentIsDynamic = (r) => {
317
- var _a2, _b;
318
- return !!((_b = (_a2 = r.segments.at(-1)) == null ? void 0 : _a2.at(-1)) == null ? void 0 : _b.dynamic);
319
- };
315
+ const lastSegmentIsDynamic = (r) => !!r.segments.at(-1)?.at(-1)?.dynamic;
320
316
  const redirBase = path.posix.dirname(route);
321
317
  const dynamicRedir = lastSegmentIsDynamic(routeData);
322
318
  let i = 0;
@@ -17,7 +17,7 @@ function stringifyParams(params, route) {
17
17
  const validatedParams = Object.entries(params).reduce((acc, next) => {
18
18
  validateGetStaticPathsParameter(next, route.component);
19
19
  const [key, value] = next;
20
- acc[key] = value == null ? void 0 : value.toString();
20
+ acc[key] = value?.toString();
21
21
  return acc;
22
22
  }, {});
23
23
  return JSON.stringify(route.generate(validatedParams));
@@ -34,18 +34,17 @@ function validateGetStaticPathsResult(result, logging, route) {
34
34
  });
35
35
  }
36
36
  result.forEach((pathObject) => {
37
- if (pathObject.params === void 0 || pathObject.params === null || pathObject.params && Object.keys(pathObject.params).length === 0) {
37
+ if (typeof pathObject === "object" && Array.isArray(pathObject) || pathObject === null) {
38
38
  throw new AstroError({
39
- ...AstroErrorData.GetStaticPathsExpectedParams,
40
- location: {
41
- file: route.component
42
- }
39
+ ...AstroErrorData.InvalidGetStaticPathsEntry,
40
+ message: AstroErrorData.InvalidGetStaticPathsEntry.message(
41
+ Array.isArray(pathObject) ? "array" : typeof pathObject
42
+ )
43
43
  });
44
44
  }
45
- if (typeof pathObject.params !== "object") {
45
+ if (pathObject.params === void 0 || pathObject.params === null || pathObject.params && Object.keys(pathObject.params).length === 0) {
46
46
  throw new AstroError({
47
- ...AstroErrorData.InvalidGetStaticPathParam,
48
- message: AstroErrorData.InvalidGetStaticPathParam.message(typeof pathObject.params),
47
+ ...AstroErrorData.GetStaticPathsExpectedParams,
49
48
  location: {
50
49
  file: route.component
51
50
  }
@@ -26,7 +26,7 @@ async function sync(inlineConfig, options) {
26
26
  logging,
27
27
  command: "build"
28
28
  });
29
- return await syncInternal(settings, { logging, fs: options == null ? void 0 : options.fs });
29
+ return await syncInternal(settings, { logging, fs: options?.fs });
30
30
  }
31
31
  async function syncInternal(settings, { logging, fs }) {
32
32
  const timerStart = performance.now();
package/dist/core/util.js CHANGED
@@ -12,7 +12,7 @@ function isURL(value) {
12
12
  return Object.prototype.toString.call(value) === "[object URL]";
13
13
  }
14
14
  function isMarkdownFile(fileId, option) {
15
- const _suffix = (option == null ? void 0 : option.suffix) ?? "";
15
+ const _suffix = option?.suffix ?? "";
16
16
  for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
17
17
  if (fileId.endsWith(`${markdownFileExtension}${_suffix}`))
18
18
  return true;
@@ -3,7 +3,7 @@ const EVENT_ERROR = "ASTRO_CLI_ERROR";
3
3
  const ANONYMIZE_MESSAGE_REGEX = /^(\w| )+/;
4
4
  function anonymizeErrorMessage(msg) {
5
5
  const matchedMessage = msg.match(ANONYMIZE_MESSAGE_REGEX);
6
- if (!(matchedMessage == null ? void 0 : matchedMessage[0])) {
6
+ if (!matchedMessage?.[0]) {
7
7
  return void 0;
8
8
  }
9
9
  return matchedMessage[0].trim().substring(0, 20);
@@ -33,25 +33,24 @@ function configKeys(obj, parentKey) {
33
33
  }).flat(1);
34
34
  }
35
35
  function eventCliSession(cliCommand, userConfig, flags) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h;
37
36
  const configValues = userConfig ? {
38
37
  markdownPlugins: [
39
- ...((_b = (_a = userConfig == null ? void 0 : userConfig.markdown) == null ? void 0 : _a.remarkPlugins) == null ? void 0 : _b.map(
38
+ ...userConfig?.markdown?.remarkPlugins?.map(
40
39
  (p) => typeof p === "string" ? p : typeof p
41
- )) ?? [],
42
- ...((_d = (_c = userConfig == null ? void 0 : userConfig.markdown) == null ? void 0 : _c.rehypePlugins) == null ? void 0 : _d.map(
40
+ ) ?? [],
41
+ ...userConfig?.markdown?.rehypePlugins?.map(
43
42
  (p) => typeof p === "string" ? p : typeof p
44
- )) ?? []
43
+ ) ?? []
45
44
  ],
46
- adapter: ((_e = userConfig == null ? void 0 : userConfig.adapter) == null ? void 0 : _e.name) ?? null,
47
- integrations: ((userConfig == null ? void 0 : userConfig.integrations) ?? []).filter(Boolean).flat().map((i) => i == null ? void 0 : i.name),
48
- trailingSlash: userConfig == null ? void 0 : userConfig.trailingSlash,
49
- build: (userConfig == null ? void 0 : userConfig.build) ? {
50
- format: (_f = userConfig == null ? void 0 : userConfig.build) == null ? void 0 : _f.format
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
51
50
  } : void 0,
52
- markdown: (userConfig == null ? void 0 : userConfig.markdown) ? {
53
- drafts: (_g = userConfig.markdown) == null ? void 0 : _g.drafts,
54
- syntaxHighlight: (_h = userConfig.markdown) == null ? void 0 : _h.syntaxHighlight
51
+ markdown: userConfig?.markdown ? {
52
+ drafts: userConfig.markdown?.drafts,
53
+ syntaxHighlight: userConfig.markdown?.syntaxHighlight
55
54
  } : void 0
56
55
  } : void 0;
57
56
  const cliFlags = flags ? Object.keys(flags).filter((name) => name != "_") : void 0;
@@ -0,0 +1,14 @@
1
+ import type { AstroConfig, AstroFeatureMap } from '../@types/astro';
2
+ import { type LogOptions } from '../core/logger/core.js';
3
+ type ValidationResult = {
4
+ [Property in keyof AstroFeatureMap]: boolean;
5
+ };
6
+ /**
7
+ * Checks whether an adapter supports certain features that are enabled via Astro configuration.
8
+ *
9
+ * If a configuration is enabled and "unlocks" a feature, but the adapter doesn't support, the function
10
+ * will throw a runtime error.
11
+ *
12
+ */
13
+ export declare function validateSupportedFeatures(adapterName: string, featureMap: AstroFeatureMap | undefined, config: AstroConfig, logging: LogOptions): ValidationResult;
14
+ export {};
@@ -0,0 +1,109 @@
1
+ import { error, warn } from "../core/logger/core.js";
2
+ const STABLE = "stable";
3
+ const DEPRECATED = "deprecated";
4
+ const UNSUPPORTED = "unsupported";
5
+ const EXPERIMENTAL = "experimental";
6
+ const UNSUPPORTED_ASSETS_FEATURE = {
7
+ supportKind: UNSUPPORTED,
8
+ isSquooshCompatible: false,
9
+ isSharpCompatible: false
10
+ };
11
+ const ALL_UNSUPPORTED = {
12
+ serverOutput: UNSUPPORTED,
13
+ staticOutput: UNSUPPORTED,
14
+ hybridOutput: UNSUPPORTED,
15
+ assets: UNSUPPORTED_ASSETS_FEATURE
16
+ };
17
+ function validateSupportedFeatures(adapterName, featureMap = ALL_UNSUPPORTED, config, logging) {
18
+ const {
19
+ assets = UNSUPPORTED_ASSETS_FEATURE,
20
+ serverOutput = UNSUPPORTED,
21
+ staticOutput = UNSUPPORTED,
22
+ hybridOutput = UNSUPPORTED
23
+ } = featureMap;
24
+ const validationResult = {};
25
+ validationResult.staticOutput = validateSupportKind(
26
+ staticOutput,
27
+ adapterName,
28
+ logging,
29
+ "staticOutput",
30
+ () => config?.output === "static"
31
+ );
32
+ validationResult.hybridOutput = validateSupportKind(
33
+ hybridOutput,
34
+ adapterName,
35
+ logging,
36
+ "hybridOutput",
37
+ () => config?.output === "hybrid"
38
+ );
39
+ validationResult.serverOutput = validateSupportKind(
40
+ serverOutput,
41
+ adapterName,
42
+ logging,
43
+ "serverOutput",
44
+ () => config?.output === "server"
45
+ );
46
+ validationResult.assets = validateAssetsFeature(assets, adapterName, config, logging);
47
+ return validationResult;
48
+ }
49
+ function validateSupportKind(supportKind, adapterName, logging, featureName, hasCorrectConfig) {
50
+ if (supportKind === STABLE) {
51
+ return true;
52
+ } else if (supportKind === DEPRECATED) {
53
+ featureIsDeprecated(adapterName, logging);
54
+ } else if (supportKind === EXPERIMENTAL) {
55
+ featureIsExperimental(adapterName, logging);
56
+ }
57
+ if (hasCorrectConfig() && supportKind === UNSUPPORTED) {
58
+ featureIsUnsupported(adapterName, logging, featureName);
59
+ return false;
60
+ } else {
61
+ return true;
62
+ }
63
+ }
64
+ function featureIsUnsupported(adapterName, logging, featureName) {
65
+ error(
66
+ logging,
67
+ `${adapterName}`,
68
+ `The feature ${featureName} is not supported by the adapter ${adapterName}.`
69
+ );
70
+ }
71
+ function featureIsExperimental(adapterName, logging) {
72
+ warn(logging, `${adapterName}`, "The feature is experimental and subject to issues or changes.");
73
+ }
74
+ function featureIsDeprecated(adapterName, logging) {
75
+ warn(
76
+ logging,
77
+ `${adapterName}`,
78
+ "The feature is deprecated and will be moved in the next release."
79
+ );
80
+ }
81
+ const SHARP_SERVICE = "astro/assets/services/sharp";
82
+ const SQUOOSH_SERVICE = "astro/assets/services/squoosh";
83
+ function validateAssetsFeature(assets, adapterName, config, logging) {
84
+ const {
85
+ supportKind = UNSUPPORTED,
86
+ isSharpCompatible = false,
87
+ isSquooshCompatible = false
88
+ } = assets;
89
+ if (config?.image?.service?.entrypoint === SHARP_SERVICE && !isSharpCompatible) {
90
+ error(
91
+ logging,
92
+ "astro",
93
+ `The currently selected adapter \`${adapterName}\` is not compatible with the image service "Sharp".`
94
+ );
95
+ return false;
96
+ }
97
+ if (config?.image?.service?.entrypoint === SQUOOSH_SERVICE && !isSquooshCompatible) {
98
+ error(
99
+ logging,
100
+ "astro",
101
+ `The currently selected adapter \`${adapterName}\` is not compatible with the image service "Squoosh".`
102
+ );
103
+ return false;
104
+ }
105
+ return validateSupportKind(supportKind, adapterName, logging, "assets", () => true);
106
+ }
107
+ export {
108
+ validateSupportedFeatures
109
+ };
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { AddressInfo } from 'node:net';
3
3
  import type { InlineConfig, ViteDevServer } from 'vite';
4
- import type { AstroConfig, AstroSettings, RouteData } from '../@types/astro.js';
4
+ import type { AstroAdapter, AstroConfig, AstroSettings, RouteData } from '../@types/astro.js';
5
5
  import type { SerializedSSRManifest } from '../core/app/types';
6
6
  import type { PageBuildData } from '../core/build/types';
7
7
  import { type LogOptions } from '../core/logger/core.js';
@@ -59,4 +59,6 @@ type RunHookBuildDone = {
59
59
  logging: LogOptions;
60
60
  };
61
61
  export declare function runHookBuildDone({ config, pages, routes, logging }: RunHookBuildDone): Promise<void>;
62
+ export declare function isFunctionPerRouteEnabled(adapter: AstroAdapter | undefined): boolean;
63
+ export declare function isEdgeMiddlewareEnabled(adapter: AstroAdapter | undefined): boolean;
62
64
  export {};