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
@@ -70,7 +70,7 @@ async function createContentTypesGenerator({
70
70
  return { typesGenerated: true };
71
71
  }
72
72
  async function handleEvent(event, opts) {
73
- const logLevel = (opts == null ? void 0 : opts.logLevel) ?? "info";
73
+ const logLevel = opts?.logLevel ?? "info";
74
74
  if (event.name === "addDir" || event.name === "unlinkDir") {
75
75
  const collection2 = normalizePath(
76
76
  path.relative(fileURLToPath(contentPaths.contentDir), fileURLToPath(event.entry))
@@ -229,7 +229,7 @@ async function createContentTypesGenerator({
229
229
  fs
230
230
  });
231
231
  const entryMetadata = collectionInfo.entries[entryKey];
232
- if ((entryMetadata == null ? void 0 : entryMetadata.slug) !== changedSlug) {
232
+ if (entryMetadata?.slug !== changedSlug) {
233
233
  collectionInfo.entries[entryKey].slug = changedSlug;
234
234
  return { shouldGenerateTypes: true };
235
235
  }
@@ -261,7 +261,7 @@ async function createContentTypesGenerator({
261
261
  );
262
262
  }
263
263
  async function runEvents(opts) {
264
- const logLevel = (opts == null ? void 0 : opts.logLevel) ?? "info";
264
+ const logLevel = opts?.logLevel ?? "info";
265
265
  const eventResponses = [];
266
266
  for (const event of events) {
267
267
  const response = await handleEvent(event.type, event.opts);
@@ -325,9 +325,9 @@ async function writeContentFiles({
325
325
  let contentTypesStr = "";
326
326
  let dataTypesStr = "";
327
327
  for (const collectionKey of Object.keys(collectionEntryMap).sort()) {
328
- const collectionConfig = contentConfig == null ? void 0 : contentConfig.collections[JSON.parse(collectionKey)];
328
+ const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
329
329
  const collection = collectionEntryMap[collectionKey];
330
- if ((collectionConfig == null ? void 0 : collectionConfig.type) && collection.type !== "unknown" && collection.type !== collectionConfig.type) {
330
+ if (collectionConfig?.type && collection.type !== "unknown" && collection.type !== collectionConfig.type) {
331
331
  viteServer.ws.send({
332
332
  type: "error",
333
333
  err: new AstroError({
@@ -349,7 +349,7 @@ async function writeContentFiles({
349
349
  const resolvedType = collection.type === "unknown" ? (
350
350
  // Add empty / unknown collections to the data type map by default
351
351
  // This ensures `getCollection('empty-collection')` doesn't raise a type error
352
- (collectionConfig == null ? void 0 : collectionConfig.type) ?? "data"
352
+ collectionConfig?.type ?? "data"
353
353
  ) : collection.type;
354
354
  switch (resolvedType) {
355
355
  case "content":
@@ -357,7 +357,7 @@ async function writeContentFiles({
357
357
  `;
358
358
  for (const entryKey of Object.keys(collection.entries).sort()) {
359
359
  const entryMetadata = collection.entries[entryKey];
360
- const dataType = (collectionConfig == null ? void 0 : collectionConfig.schema) ? `InferEntrySchema<${collectionKey}>` : "any";
360
+ const dataType = collectionConfig?.schema ? `InferEntrySchema<${collectionKey}>` : "any";
361
361
  const renderType = `{ render(): Render[${JSON.stringify(
362
362
  path.extname(JSON.parse(entryKey))
363
363
  )}] }`;
@@ -378,7 +378,7 @@ async function writeContentFiles({
378
378
  dataTypesStr += `${collectionKey}: {
379
379
  `;
380
380
  for (const entryKey of Object.keys(collection.entries).sort()) {
381
- const dataType = (collectionConfig == null ? void 0 : collectionConfig.schema) ? `InferEntrySchema<${collectionKey}>` : "any";
381
+ const dataType = collectionConfig?.schema ? `InferEntrySchema<${collectionKey}>` : "any";
382
382
  dataTypesStr += `${entryKey}: {
383
383
  id: ${entryKey};
384
384
  collection: ${collectionKey};
@@ -8,7 +8,7 @@ import { z } from "zod";
8
8
  import { VALID_INPUT_FORMATS } from "../assets/consts.js";
9
9
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
10
10
  import { formatYAMLException, isYAMLException } from "../core/errors/utils.js";
11
- import { CONTENT_TYPES_FILE } from "./consts.js";
11
+ import { CONTENT_FLAGS, CONTENT_TYPES_FILE } from "./consts.js";
12
12
  import { errorMap } from "./error-map.js";
13
13
  import { createImage } from "./runtime-assets.js";
14
14
  const collectionConfigParser = z.union([
@@ -78,9 +78,8 @@ async function getEntryData(entry, collectionConfig, pluginContext, config) {
78
78
  let formattedError;
79
79
  const parsed = await schema.safeParseAsync(entry.unvalidatedData, {
80
80
  errorMap(error, ctx) {
81
- var _a, _b;
82
- if (error.code === "custom" && ((_a = error.params) == null ? void 0 : _a.isHoistedAstroError)) {
83
- formattedError = (_b = error.params) == null ? void 0 : _b.astroError;
81
+ if (error.code === "custom" && error.params?.isHoistedAstroError) {
82
+ formattedError = error.params?.astroError;
84
83
  }
85
84
  return errorMap(error, ctx);
86
85
  }
@@ -42,12 +42,11 @@ function astroContentAssetPropagationPlugin({
42
42
  }
43
43
  },
44
44
  async transform(_, id, options) {
45
- var _a;
46
45
  if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
47
46
  const basePath = id.split("?")[0];
48
47
  let stringifiedLinks, stringifiedStyles, stringifiedScripts;
49
- if ((options == null ? void 0 : options.ssr) && devModuleLoader) {
50
- if (!((_a = devModuleLoader.getModuleById(basePath)) == null ? void 0 : _a.ssrModule)) {
48
+ if (options?.ssr && devModuleLoader) {
49
+ if (!devModuleLoader.getModuleById(basePath)?.ssrModule) {
51
50
  await devModuleLoader.import(basePath);
52
51
  }
53
52
  const { stylesMap, urls } = await getStylesForURL(
@@ -101,7 +100,6 @@ function astroConfigBuildPlugin(options, internals) {
101
100
  };
102
101
  },
103
102
  "build:post": ({ ssrOutputs, clientOutputs, mutate }) => {
104
- var _a, _b;
105
103
  const outputs = ssrOutputs.flatMap((o) => o.output);
106
104
  const prependBase = (src) => {
107
105
  if (options.settings.config.build.assetsPrefix) {
@@ -122,8 +120,8 @@ function astroConfigBuildPlugin(options, internals) {
122
120
  const pageData = getPageDataByViteID(internals, pageViteID);
123
121
  if (!pageData)
124
122
  continue;
125
- const _entryCss = (_a = pageData.propagatedStyles) == null ? void 0 : _a.get(id);
126
- const _entryScripts = (_b = pageData.propagatedScripts) == null ? void 0 : _b.get(id);
123
+ const _entryCss = pageData.propagatedStyles?.get(id);
124
+ const _entryScripts = pageData.propagatedScripts?.get(id);
127
125
  if (_entryCss) {
128
126
  for (const value of _entryCss) {
129
127
  if (value.type === "inline")
@@ -224,7 +224,7 @@ async function getEntryModuleBaseInfo({
224
224
  const collection = getEntryCollectionName({ entry, contentDir });
225
225
  if (collection === void 0)
226
226
  throw new AstroError(AstroErrorData.UnknownContentCollectionError);
227
- const collectionConfig = contentConfig == null ? void 0 : contentConfig.collections[collection];
227
+ const collectionConfig = contentConfig?.collections[collection];
228
228
  return {
229
229
  collectionConfig,
230
230
  entry,
@@ -99,14 +99,13 @@ async function getStringifiedLookupMap({
99
99
  for (const filePath of contentGlob) {
100
100
  promises.push(
101
101
  limit(async () => {
102
- var _a, _b, _c, _d, _e;
103
102
  const entryType = getEntryType(filePath, contentPaths, contentEntryExts, dataEntryExts);
104
103
  if (entryType !== "content" && entryType !== "data")
105
104
  return;
106
105
  const collection = getEntryCollectionName({ contentDir, entry: pathToFileURL(filePath) });
107
106
  if (!collection)
108
107
  throw UnexpectedLookupMapError;
109
- if (((_a = lookupMap[collection]) == null ? void 0 : _a.type) && lookupMap[collection].type !== entryType) {
108
+ if (lookupMap[collection]?.type && lookupMap[collection].type !== entryType) {
110
109
  throw new AstroError({
111
110
  ...AstroErrorData.MixedContentDataCollectionError,
112
111
  message: AstroErrorData.MixedContentDataCollectionError.message(collection)
@@ -129,7 +128,7 @@ async function getStringifiedLookupMap({
129
128
  fileUrl: pathToFileURL(filePath),
130
129
  contentEntryType
131
130
  });
132
- if ((_c = (_b = lookupMap[collection]) == null ? void 0 : _b.entries) == null ? void 0 : _c[slug]) {
131
+ if (lookupMap[collection]?.entries?.[slug]) {
133
132
  throw new AstroError({
134
133
  ...AstroErrorData.DuplicateContentEntrySlugError,
135
134
  message: AstroErrorData.DuplicateContentEntrySlugError.message(collection, slug),
@@ -139,7 +138,7 @@ async function getStringifiedLookupMap({
139
138
  lookupMap[collection] = {
140
139
  type: "content",
141
140
  entries: {
142
- ...(_d = lookupMap[collection]) == null ? void 0 : _d.entries,
141
+ ...lookupMap[collection]?.entries,
143
142
  [slug]: rootRelativePath(root, filePath)
144
143
  }
145
144
  };
@@ -148,7 +147,7 @@ async function getStringifiedLookupMap({
148
147
  lookupMap[collection] = {
149
148
  type: "data",
150
149
  entries: {
151
- ...(_e = lookupMap[collection]) == null ? void 0 : _e.entries,
150
+ ...lookupMap[collection]?.entries,
152
151
  [id]: rootRelativePath(root, filePath)
153
152
  }
154
153
  };
@@ -168,7 +167,7 @@ function globWithUnderscoresIgnored(relContentDir, exts) {
168
167
  const contentDir = appendForwardSlash(relContentDir);
169
168
  return [
170
169
  `${contentDir}**/*${extGlob}`,
171
- `!${contentDir}**/_*/**${extGlob}`,
170
+ `!${contentDir}**/_*/**/*${extGlob}`,
172
171
  `!${contentDir}**/_*${extGlob}`
173
172
  ];
174
173
  }
@@ -4,7 +4,7 @@ import { consoleLogDestination } from "../logger/console.js";
4
4
  import { error } from "../logger/core.js";
5
5
  import { prependForwardSlash, removeTrailingForwardSlash } from "../path.js";
6
6
  import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
7
- import { isResponse } from "../render/core";
7
+ import { isResponse } from "../render/core.js";
8
8
  import {
9
9
  createEnvironment,
10
10
  createRenderContext,
@@ -229,7 +229,7 @@ class App {
229
229
  }
230
230
  }
231
231
  /**
232
- * If is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
232
+ * If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
233
233
  * This also handles pre-rendered /404 or /500 routes
234
234
  */
235
235
  async #renderError(request, { routeData, status, response: originalResponse }) {
@@ -272,8 +272,10 @@ class App {
272
272
  return newResponse;
273
273
  const { status, statusText, headers } = oldResponse;
274
274
  return new Response(newResponse.body, {
275
+ // If the original status was 200 (default), override it with the new status (probably 404 or 500)
276
+ // Otherwise, the user set a specific status while rendering and we should respect that one
275
277
  status: status === 200 ? newResponse.status : status,
276
- statusText,
278
+ statusText: status === 200 ? newResponse.statusText : statusText,
277
279
  headers: new Headers(Array.from(headers))
278
280
  });
279
281
  }
@@ -3,6 +3,7 @@ import type { RouteData } from '../../@types/astro';
3
3
  import type { SSRManifest } from './types';
4
4
  import { IncomingMessage } from 'node:http';
5
5
  import { App, type MatchOptions } from './index.js';
6
+ export { apply as applyPolyfills } from '../polyfill.js';
6
7
  declare class NodeIncomingMessage extends IncomingMessage {
7
8
  /**
8
9
  * The read-only body property of the Request interface contains a ReadableStream with the body contents that have been added to the request.
@@ -15,4 +16,3 @@ export declare class NodeApp extends App {
15
16
  }
16
17
  export declare function loadManifest(rootFolder: URL): Promise<SSRManifest>;
17
18
  export declare function loadApp(rootFolder: URL): Promise<NodeApp>;
18
- export {};
@@ -3,9 +3,9 @@ import { IncomingMessage } from "node:http";
3
3
  import { TLSSocket } from "node:tls";
4
4
  import { deserializeManifest } from "./common.js";
5
5
  import { App } from "./index.js";
6
+ import { apply } from "../polyfill.js";
6
7
  const clientAddressSymbol = Symbol.for("astro.clientAddress");
7
8
  function createRequestFromNodeRequest(req, body) {
8
- var _a;
9
9
  const protocol = req.socket instanceof TLSSocket || req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
10
10
  const hostname = req.headers.host || req.headers[":authority"];
11
11
  const url = `${protocol}://${hostname}${req.url}`;
@@ -17,12 +17,16 @@ function createRequestFromNodeRequest(req, body) {
17
17
  headers: new Headers(entries),
18
18
  body: ["HEAD", "GET"].includes(method) ? null : body
19
19
  });
20
- if ((_a = req.socket) == null ? void 0 : _a.remoteAddress) {
20
+ if (req.socket?.remoteAddress) {
21
21
  Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress);
22
22
  }
23
23
  return request;
24
24
  }
25
25
  class NodeIncomingMessage extends IncomingMessage {
26
+ /**
27
+ * The read-only body property of the Request interface contains a ReadableStream with the body contents that have been added to the request.
28
+ */
29
+ body;
26
30
  }
27
31
  class NodeApp extends App {
28
32
  match(req, opts = {}) {
@@ -83,6 +87,7 @@ async function loadApp(rootFolder) {
83
87
  }
84
88
  export {
85
89
  NodeApp,
90
+ apply as applyPolyfills,
86
91
  loadApp,
87
92
  loadManifest
88
93
  };
@@ -3,9 +3,8 @@ import npath from "node:path";
3
3
  import { viteID } from "../util.js";
4
4
  import { getTopLevelPages } from "./graph.js";
5
5
  function shortHashedName(id, ctx) {
6
- var _a;
7
6
  const parents = Array.from(getTopLevelPages(id, ctx));
8
- const firstParentId = (_a = parents[0]) == null ? void 0 : _a[0].id;
7
+ const firstParentId = parents[0]?.[0].id;
9
8
  const firstParentName = firstParentId ? npath.parse(firstParentId).name : "index";
10
9
  const hash = crypto.createHash("sha256");
11
10
  for (const [page] of parents) {
@@ -21,10 +20,9 @@ function createSlugger(settings) {
21
20
  const map = /* @__PURE__ */ new Map();
22
21
  const sep = "-";
23
22
  return function(id, ctx) {
24
- var _a;
25
23
  const parents = Array.from(getTopLevelPages(id, ctx));
26
24
  const allParentsKey = parents.map(([page]) => page.id).sort().join("-");
27
- const firstParentId = ((_a = parents[0]) == null ? void 0 : _a[0].id) || indexPage;
25
+ const firstParentId = parents[0]?.[0].id || indexPage;
28
26
  let dir = firstParentId;
29
27
  let key = "";
30
28
  let i = 0;
@@ -60,11 +60,10 @@ async function getEntryForRedirectRoute(route, internals, outFolder) {
60
60
  return RedirectSinglePageBuiltModule;
61
61
  }
62
62
  function shouldSkipDraft(pageModule, settings) {
63
- var _a;
64
63
  return (
65
64
  // Drafts are disabled
66
65
  !settings.config.markdown.drafts && // This is a draft post
67
- "frontmatter" in pageModule && ((_a = pageModule.frontmatter) == null ? void 0 : _a.draft) === true
66
+ "frontmatter" in pageModule && pageModule.frontmatter?.draft === true
68
67
  );
69
68
  }
70
69
  function rootRelativeFacadeId(facadeId, settings) {
@@ -84,12 +83,11 @@ function chunkIsPage(settings, output, internals) {
84
83
  return false;
85
84
  }
86
85
  async function generatePages(opts, internals) {
87
- var _a, _b;
88
86
  const timer = performance.now();
89
87
  const ssr = isServerLikeOutput(opts.settings.config);
90
88
  const outFolder = ssr ? opts.settings.config.build.server : getOutDirWithinCwd(opts.settings.config.outDir);
91
89
  if (ssr && !hasPrerenderedPages(internals)) {
92
- (_a = globalThis == null ? void 0 : globalThis.astroAsset) == null ? true : delete _a.addStaticImage;
90
+ delete globalThis?.astroAsset?.addStaticImage;
93
91
  return;
94
92
  }
95
93
  const verb = ssr ? "prerendering" : "generating";
@@ -103,7 +101,7 @@ ${bgGreen(black(` ${verb} static routes `))}`);
103
101
  const ssrEntryPage = await import(ssrEntryURLPage.toString());
104
102
  if (opts.settings.config.build.split) {
105
103
  const manifest = ssrEntryPage.manifest;
106
- const ssrEntry = manifest == null ? void 0 : manifest.pageModule;
104
+ const ssrEntry = manifest?.pageModule;
107
105
  if (ssrEntry) {
108
106
  await generatePage(opts, internals, pageData, ssrEntry, builtPaths, manifest);
109
107
  } else {
@@ -142,7 +140,7 @@ ${bgGreen(black(` generating optimized images `))}`);
142
140
  for (const imageData of getStaticImageList()) {
143
141
  await generateImage(opts, imageData[1].options, imageData[1].path);
144
142
  }
145
- (_b = globalThis == null ? void 0 : globalThis.astroAsset) == null ? true : delete _b.addStaticImage;
143
+ delete globalThis?.astroAsset?.addStaticImage;
146
144
  }
147
145
  await runHookBuildGenerated({
148
146
  config: opts.settings.config,
@@ -167,7 +165,7 @@ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths, man
167
165
  let timeStart = performance.now();
168
166
  const pageInfo = getPageDataByComponent(internals, pageData.route.component);
169
167
  const linkIds = [];
170
- const scripts = (pageInfo == null ? void 0 : pageInfo.hoistedScript) ?? null;
168
+ const scripts = pageInfo?.hoistedScript ?? null;
171
169
  const styles = pageData.styles.sort(cssOrder).map(({ sheet }) => sheet).reduce(mergeInlineCss, []);
172
170
  const pageModulePromise = ssrEntry.page;
173
171
  const onRequest = ssrEntry.onRequest;
@@ -218,7 +216,6 @@ async function getPathsForRoute(pageData, mod, opts, builtPaths) {
218
216
  mod,
219
217
  route,
220
218
  routeCache: opts.routeCache,
221
- isValidate: false,
222
219
  logging: opts.logging,
223
220
  ssr: isServerLikeOutput(opts.settings.config)
224
221
  }).catch((err) => {
@@ -255,18 +252,14 @@ async function getPathsForRoute(pageData, mod, opts, builtPaths) {
255
252
  return paths;
256
253
  }
257
254
  function getInvalidRouteSegmentError(e, route, staticPath) {
258
- var _a, _b;
259
- const invalidParam = (_a = e.message.match(/^Expected "([^"]+)"/)) == null ? void 0 : _a[1];
255
+ const invalidParam = e.message.match(/^Expected "([^"]+)"/)?.[1];
260
256
  const received = invalidParam ? staticPath.params[invalidParam] : void 0;
261
257
  let hint = "Learn about dynamic routes at https://docs.astro.build/en/core-concepts/routing/#dynamic-routes";
262
258
  if (invalidParam && typeof received === "string") {
263
- const matchingSegment = (_b = route.segments.find(
264
- (segment) => {
265
- var _a2;
266
- return ((_a2 = segment[0]) == null ? void 0 : _a2.content) === invalidParam;
267
- }
268
- )) == null ? void 0 : _b[0];
269
- const mightBeMissingSpread = (matchingSegment == null ? void 0 : matchingSegment.dynamic) && !(matchingSegment == null ? void 0 : matchingSegment.spread);
259
+ const matchingSegment = route.segments.find(
260
+ (segment) => segment[0]?.content === invalidParam
261
+ )?.[0];
262
+ const mightBeMissingSpread = matchingSegment?.dynamic && !matchingSegment?.spread;
270
263
  if (mightBeMissingSpread) {
271
264
  hint = `If the param contains slashes, try using a rest parameter: **[...${invalidParam}]**. Learn more at https://docs.astro.build/en/core-concepts/routing/#dynamic-routes`;
272
265
  }
@@ -14,9 +14,9 @@ function* walkParentInfos(id, ctx, until, depth = 0, order = 0, seen = /* @__PUR
14
14
  }
15
15
  yield [info, depth, order];
16
16
  }
17
- if (until == null ? void 0 : until(id))
17
+ if (until?.(id))
18
18
  return;
19
- const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
19
+ const importers = (info?.importers || []).concat(info?.dynamicImporters || []);
20
20
  for (const imp of importers) {
21
21
  if (seen.has(imp)) {
22
22
  continue;
@@ -25,8 +25,7 @@ function* walkParentInfos(id, ctx, until, depth = 0, order = 0, seen = /* @__PUR
25
25
  }
26
26
  }
27
27
  function moduleIsTopLevelPage(info) {
28
- var _a, _b;
29
- return ((_a = info.importers[0]) == null ? void 0 : _a.includes(ASTRO_PAGE_RESOLVED_MODULE_ID)) || ((_b = info.dynamicImporters[0]) == null ? void 0 : _b.includes(ASTRO_PAGE_RESOLVED_MODULE_ID));
28
+ return info.importers[0]?.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || info.dynamicImporters[0]?.includes(ASTRO_PAGE_RESOLVED_MODULE_ID);
30
29
  }
31
30
  function* getTopLevelPages(id, ctx) {
32
31
  for (const res of walkParentInfos(id, ctx)) {
@@ -37,8 +37,15 @@ async function build(inlineConfig, options) {
37
37
  await builder.run();
38
38
  }
39
39
  class AstroBuilder {
40
+ settings;
41
+ logging;
42
+ mode = "production";
43
+ origin;
44
+ routeCache;
45
+ manifest;
46
+ timer;
47
+ teardownCompiler;
40
48
  constructor(settings, options) {
41
- this.mode = "production";
42
49
  if (options.mode) {
43
50
  this.mode = options.mode;
44
51
  }
@@ -143,8 +143,8 @@ function cssOrder(a, b) {
143
143
  }
144
144
  function mergeInlineCss(acc, current) {
145
145
  const lastAdded = acc.at(acc.length - 1);
146
- const lastWasInline = (lastAdded == null ? void 0 : lastAdded.type) === "inline";
147
- const currentIsInline = (current == null ? void 0 : current.type) === "inline";
146
+ const lastWasInline = lastAdded?.type === "inline";
147
+ const currentIsInline = current?.type === "inline";
148
148
  if (lastWasInline && currentIsInline) {
149
149
  const merged = { type: "inline", content: lastAdded.content + current.content };
150
150
  acc[acc.length - 1] = merged;
@@ -25,12 +25,11 @@ function createPluginContainer(options, internals) {
25
25
  },
26
26
  // Hooks
27
27
  runBeforeHook(build, input) {
28
- var _a;
29
28
  let plugins = build === "ssr" ? ssrPlugins : clientPlugins;
30
29
  let vitePlugins = [];
31
30
  let lastVitePlugins = [];
32
31
  for (const plugin of plugins) {
33
- if ((_a = plugin.hooks) == null ? void 0 : _a["build:before"]) {
32
+ if (plugin.hooks?.["build:before"]) {
34
33
  let result = plugin.hooks["build:before"]({ build, input });
35
34
  if (result.vitePlugin) {
36
35
  vitePlugins.push(result.vitePlugin);
@@ -43,7 +42,6 @@ function createPluginContainer(options, internals) {
43
42
  };
44
43
  },
45
44
  async runPostHook(ssrReturn, clientReturn) {
46
- var _a;
47
45
  const mutations = /* @__PURE__ */ new Map();
48
46
  const ssrOutputs = [];
49
47
  const clientOutputs = [];
@@ -65,7 +63,7 @@ function createPluginContainer(options, internals) {
65
63
  });
66
64
  };
67
65
  for (const plugin of allPlugins) {
68
- const postHook = (_a = plugin.hooks) == null ? void 0 : _a["build:post"];
66
+ const postHook = plugin.hooks?.["build:post"];
69
67
  if (postHook) {
70
68
  await postHook({
71
69
  ssrOutputs,
@@ -11,10 +11,9 @@ function isPropagatedAsset(id) {
11
11
  }
12
12
  }
13
13
  async function doesParentImportChild(parentInfo, childInfo, childExportNames) {
14
- var _a, _b;
15
14
  if (!childInfo || !parentInfo.ast || !childExportNames)
16
15
  return "no";
17
- if (childExportNames === "dynamic" || ((_a = parentInfo.dynamicallyImportedIds) == null ? void 0 : _a.includes(childInfo.id))) {
16
+ if (childExportNames === "dynamic" || parentInfo.dynamicallyImportedIds?.includes(childInfo.id)) {
18
17
  return "dynamic";
19
18
  }
20
19
  const imports = [];
@@ -64,7 +63,7 @@ async function doesParentImportChild(parentInfo, childInfo, childExportNames) {
64
63
  if (node.declaration.type !== "VariableDeclaration")
65
64
  continue;
66
65
  for (const declarator of node.declaration.declarations) {
67
- if (((_b = declarator.init) == null ? void 0 : _b.type) !== "Identifier")
66
+ if (declarator.init?.type !== "Identifier")
68
67
  continue;
69
68
  if (declarator.id.type !== "Identifier")
70
69
  continue;
@@ -95,7 +94,6 @@ function vitePluginAnalyzer(internals) {
95
94
  const pageScripts = /* @__PURE__ */ new Map();
96
95
  return {
97
96
  async scan(scripts, from) {
98
- var _a;
99
97
  const hoistedScripts = /* @__PURE__ */ new Set();
100
98
  for (let i = 0; i < scripts.length; i++) {
101
99
  const hid = `${from.replace("/@fs", "")}?astro&type=script&index=${i}&lang.ts`;
@@ -149,7 +147,7 @@ function vitePluginAnalyzer(internals) {
149
147
  propagatedMapByImporter: /* @__PURE__ */ new Map()
150
148
  });
151
149
  }
152
- (_a = pageScripts.get(parentInfo.id)) == null ? void 0 : _a.hoistedSet.add(hid);
150
+ pageScripts.get(parentInfo.id)?.hoistedSet.add(hid);
153
151
  }
154
152
  }
155
153
  }
@@ -191,12 +189,11 @@ function vitePluginAnalyzer(internals) {
191
189
  return {
192
190
  name: "@astro/rollup-plugin-astro-analyzer",
193
191
  async generateBundle() {
194
- var _a;
195
192
  const hoistScanner = hoistedScriptScanner();
196
193
  const ids = this.getModuleIds();
197
194
  for (const id of ids) {
198
195
  const info = this.getModuleInfo(id);
199
- if (!((_a = info == null ? void 0 : info.meta) == null ? void 0 : _a.astro))
196
+ if (!info?.meta?.astro)
200
197
  continue;
201
198
  const astro = info.meta.astro;
202
199
  const pageData = getPageDataByViteID(internals, id);
@@ -207,7 +204,7 @@ function vitePluginAnalyzer(internals) {
207
204
  const rid = c.resolvedPath ? decodeURI(c.resolvedPath) : c.specifier;
208
205
  if (internals.discoveredHydratedComponents.has(rid)) {
209
206
  const exportNames = internals.discoveredHydratedComponents.get(rid);
210
- exportNames == null ? void 0 : exportNames.push(c.exportName);
207
+ exportNames?.push(c.exportName);
211
208
  } else {
212
209
  internals.discoveredHydratedComponents.set(rid, [c.exportName]);
213
210
  }
@@ -219,7 +216,7 @@ function vitePluginAnalyzer(internals) {
219
216
  const cid = c.resolvedPath ? decodeURI(c.resolvedPath) : c.specifier;
220
217
  if (internals.discoveredClientOnlyComponents.has(cid)) {
221
218
  const exportNames = internals.discoveredClientOnlyComponents.get(cid);
222
- exportNames == null ? void 0 : exportNames.push(c.exportName);
219
+ exportNames?.push(c.exportName);
223
220
  } else {
224
221
  internals.discoveredClientOnlyComponents.set(cid, [c.exportName]);
225
222
  }
@@ -11,10 +11,9 @@ function vitePluginComponentEntry(internals) {
11
11
  }
12
12
  }
13
13
  function mergeComponentExportNames(components) {
14
- var _a;
15
14
  for (const [componentId, exportNames] of components) {
16
15
  if (componentToExportNames.has(componentId)) {
17
- (_a = componentToExportNames.get(componentId)) == null ? void 0 : _a.push(...exportNames);
16
+ componentToExportNames.get(componentId)?.push(...exportNames);
18
17
  } else {
19
18
  componentToExportNames.set(componentId, exportNames);
20
19
  }
@@ -24,8 +23,7 @@ function vitePluginComponentEntry(internals) {
24
23
  name: "@astro/plugin-component-entry",
25
24
  enforce: "pre",
26
25
  config(config) {
27
- var _a, _b;
28
- const rollupInput = (_b = (_a = config.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.input;
26
+ const rollupInput = config.build?.rollupOptions?.input;
29
27
  if (Array.isArray(rollupInput)) {
30
28
  config.build.rollupOptions.input = rollupInput.map((id) => {
31
29
  if (componentToExportNames.has(id)) {
@@ -1,5 +1,6 @@
1
1
  import * as crypto from "node:crypto";
2
2
  import * as npath from "node:path";
3
+ import {} from "vite";
3
4
  import { isBuildableCSSRequest } from "../../../vite-plugin-astro-server/util.js";
4
5
  import { PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
5
6
  import * as assetName from "../css-asset-name.js";
@@ -39,7 +40,7 @@ function rollupPluginAstroBuildCSS(options) {
39
40
  name: "astro:rollup-plugin-build-css",
40
41
  outputOptions(outputOptions) {
41
42
  const assetFileNames = outputOptions.assetFileNames;
42
- const namingIncludesHash = assetFileNames == null ? void 0 : assetFileNames.toString().includes("[hash]");
43
+ const namingIncludesHash = assetFileNames?.toString().includes("[hash]");
43
44
  const createNameForParentPages = namingIncludesHash ? assetName.shortHashedName : assetName.createSlugger(settings);
44
45
  extendManualChunks(outputOptions, {
45
46
  after(id, meta) {
@@ -145,12 +146,10 @@ function rollupPluginAstroBuildCSS(options) {
145
146
  name: "astro:rollup-plugin-inline-stylesheets",
146
147
  enforce: "post",
147
148
  async generateBundle(_outputOptions, bundle) {
148
- var _a;
149
149
  const inlineConfig = settings.config.build.inlineStylesheets;
150
- const { assetsInlineLimit = 4096 } = ((_a = settings.config.vite) == null ? void 0 : _a.build) ?? {};
150
+ const { assetsInlineLimit = 4096 } = settings.config.vite?.build ?? {};
151
151
  Object.entries(bundle).forEach(([id, stylesheet]) => {
152
- var _a2;
153
- if (stylesheet.type !== "asset" || ((_a2 = stylesheet.name) == null ? void 0 : _a2.endsWith(".css")) !== true || typeof stylesheet.source !== "string")
152
+ if (stylesheet.type !== "asset" || stylesheet.name?.endsWith(".css") !== true || typeof stylesheet.source !== "string")
154
153
  return;
155
154
  const assetSize = new TextEncoder().encode(stylesheet.source).byteLength;
156
155
  const toBeInlined = inlineConfig === "always" ? true : inlineConfig === "never" ? false : assetSize <= assetsInlineLimit;
@@ -159,8 +158,7 @@ function rollupPluginAstroBuildCSS(options) {
159
158
  const sheet = toBeInlined ? { type: "inline", content: stylesheet.source } : { type: "external", src: stylesheet.fileName };
160
159
  const pages = Array.from(eachPageData(internals));
161
160
  pages.forEach((pageData) => {
162
- var _a3;
163
- const orderingInfo = (_a3 = pagesToCss[pageData.moduleSpecifier]) == null ? void 0 : _a3[stylesheet.fileName];
161
+ const orderingInfo = pagesToCss[pageData.moduleSpecifier]?.[stylesheet.fileName];
164
162
  if (orderingInfo !== void 0)
165
163
  return pageData.styles.push({ ...orderingInfo, sheet });
166
164
  const propagatedPaths = pagesToPropagatedCss[pageData.moduleSpecifier];
@@ -196,9 +194,8 @@ function* getParentClientOnlys(id, ctx, internals) {
196
194
  }
197
195
  }
198
196
  function appendCSSToPage(pageData, meta, pagesToCss, depth, order) {
199
- var _a;
200
197
  for (const importedCssImport of meta.importedCss) {
201
- const cssInfo = (_a = pagesToCss[pageData.moduleSpecifier]) == null ? void 0 : _a[importedCssImport];
198
+ const cssInfo = pagesToCss[pageData.moduleSpecifier]?.[importedCssImport];
202
199
  if (cssInfo !== void 0) {
203
200
  if (depth < cssInfo.depth) {
204
201
  cssInfo.depth = depth;
@@ -28,10 +28,9 @@ function vitePluginHoistedScripts(settings, internals) {
28
28
  return void 0;
29
29
  },
30
30
  async generateBundle(_options, bundle) {
31
- var _a, _b;
32
31
  let assetInlineLimit = 4096;
33
- if (((_a = settings.config.vite) == null ? void 0 : _a.build) && settings.config.vite.build.assetsInlineLimit !== void 0) {
34
- assetInlineLimit = (_b = settings.config.vite) == null ? void 0 : _b.build.assetsInlineLimit;
32
+ if (settings.config.vite?.build && settings.config.vite.build.assetsInlineLimit !== void 0) {
33
+ assetInlineLimit = settings.config.vite?.build.assetsInlineLimit;
35
34
  }
36
35
  const considerInlining = /* @__PURE__ */ new Map();
37
36
  const importedByOtherScripts = /* @__PURE__ */ new Set();
@@ -3,10 +3,9 @@ function vitePluginInternals(input, internals) {
3
3
  return {
4
4
  name: "@astro/plugin-build-internals",
5
5
  config(config, options) {
6
- var _a;
7
6
  const extra = {};
8
7
  const noExternal = [], external = [];
9
- if (options.command === "build" && ((_a = config.build) == null ? void 0 : _a.ssr)) {
8
+ if (options.command === "build" && config.build?.ssr) {
10
9
  noExternal.push("astro");
11
10
  external.push("shiki");
12
11
  }
@@ -1,6 +1,7 @@
1
1
  import { extname } from "node:path";
2
2
  import { routeIsRedirect } from "../../redirects/index.js";
3
3
  import { addRollupInput } from "../add-rollup-input.js";
4
+ import {} from "../internal.js";
4
5
  import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
5
6
  import { RENDERERS_MODULE_ID } from "./plugin-renderers.js";
6
7
  import { ASTRO_PAGE_EXTENSION_POST_PATTERN, getPathFromVirtualModulePageName } from "./util.js";
@@ -50,7 +51,10 @@ function vitePluginPages(opts, internals) {
50
51
  exports.push(`export { page }`);
51
52
  imports.push(`import { renderers } from "${RENDERERS_MODULE_ID}";`);
52
53
  exports.push(`export { renderers };`);
53
- if (!opts.settings.config.build.excludeMiddleware) {
54
+ if (
55
+ // TODO: remover in Astro 4.0
56
+ !opts.settings.config.build.excludeMiddleware || opts.settings.adapter?.adapterFeatures?.edgeMiddleware === true
57
+ ) {
54
58
  const middlewareModule = await this.resolve(MIDDLEWARE_MODULE_ID);
55
59
  if (middlewareModule) {
56
60
  imports.push(`import { onRequest } from "${middlewareModule.id}";`);