astro 4.7.1 → 4.8.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 (222) hide show
  1. package/client.d.ts +1 -0
  2. package/content-module.template.mjs +2 -0
  3. package/dist/@types/astro.d.ts +219 -3
  4. package/dist/actions/consts.d.ts +3 -0
  5. package/dist/actions/consts.js +8 -0
  6. package/dist/actions/index.d.ts +2 -0
  7. package/dist/actions/index.js +72 -0
  8. package/dist/actions/runtime/middleware.d.ts +7 -0
  9. package/dist/actions/runtime/middleware.js +38 -0
  10. package/dist/actions/runtime/route.d.ts +2 -0
  11. package/dist/actions/runtime/route.js +37 -0
  12. package/dist/actions/runtime/store.d.ts +6 -0
  13. package/dist/actions/runtime/store.js +18 -0
  14. package/dist/actions/runtime/utils.d.ts +4 -0
  15. package/dist/actions/runtime/utils.js +23 -0
  16. package/dist/actions/runtime/virtual/client.d.ts +4 -0
  17. package/dist/actions/runtime/virtual/client.js +20 -0
  18. package/dist/actions/runtime/virtual/server.d.ts +21 -0
  19. package/dist/actions/runtime/virtual/server.js +98 -0
  20. package/dist/actions/runtime/virtual/shared.d.ts +37 -0
  21. package/dist/actions/runtime/virtual/shared.js +104 -0
  22. package/dist/actions/utils.d.ts +2 -0
  23. package/dist/actions/utils.js +18 -0
  24. package/dist/assets/build/generate.js +1 -1
  25. package/dist/assets/internal.js +1 -2
  26. package/dist/assets/services/service.js +2 -4
  27. package/dist/assets/services/sharp.js +2 -4
  28. package/dist/assets/services/squoosh.js +2 -4
  29. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
  30. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
  31. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
  32. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
  33. package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
  34. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
  35. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
  36. package/dist/assets/utils/getAssetsPrefix.js +2 -4
  37. package/dist/assets/utils/remotePattern.js +1 -2
  38. package/dist/assets/utils/remoteProbe.js +1 -2
  39. package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
  40. package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
  41. package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
  42. package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
  43. package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
  44. package/dist/assets/vite-plugin-assets.js +1 -1
  45. package/dist/cli/add/babel.d.ts +1 -1
  46. package/dist/cli/add/imports.js +4 -8
  47. package/dist/cli/add/index.js +23 -46
  48. package/dist/cli/add/wrapper.js +1 -2
  49. package/dist/cli/index.js +1 -2
  50. package/dist/cli/info/index.js +1 -2
  51. package/dist/cli/install-package.js +3 -6
  52. package/dist/cli/throw-and-exit.js +1 -2
  53. package/dist/config/index.d.ts +2 -2
  54. package/dist/config/index.js +2 -2
  55. package/dist/content/index.d.ts +1 -1
  56. package/dist/content/index.js +1 -7
  57. package/dist/content/runtime.d.ts +2 -1
  58. package/dist/content/runtime.js +11 -20
  59. package/dist/content/server-listeners.js +5 -10
  60. package/dist/content/types-generator.js +5 -10
  61. package/dist/content/utils.d.ts +0 -4
  62. package/dist/content/utils.js +4 -15
  63. package/dist/content/vite-plugin-content-assets.d.ts +1 -1
  64. package/dist/content/vite-plugin-content-assets.js +14 -47
  65. package/dist/content/vite-plugin-content-imports.js +6 -11
  66. package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
  67. package/dist/core/app/index.js +11 -46
  68. package/dist/core/app/node.js +4 -3
  69. package/dist/core/app/pipeline.d.ts +7 -2
  70. package/dist/core/app/pipeline.js +70 -2
  71. package/dist/core/app/types.d.ts +1 -0
  72. package/dist/core/base-pipeline.d.ts +16 -1
  73. package/dist/core/build/generate.js +15 -61
  74. package/dist/core/build/index.js +2 -4
  75. package/dist/core/build/internal.d.ts +39 -9
  76. package/dist/core/build/internal.js +43 -54
  77. package/dist/core/build/page-data.js +6 -6
  78. package/dist/core/build/pipeline.d.ts +7 -3
  79. package/dist/core/build/pipeline.js +134 -23
  80. package/dist/core/build/plugins/plugin-analyzer.js +11 -32
  81. package/dist/core/build/plugins/plugin-content.d.ts +1 -0
  82. package/dist/core/build/plugins/plugin-content.js +34 -32
  83. package/dist/core/build/plugins/plugin-css.js +23 -51
  84. package/dist/core/build/plugins/plugin-manifest.js +7 -8
  85. package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
  86. package/dist/core/build/plugins/plugin-pages.js +10 -12
  87. package/dist/core/build/plugins/plugin-ssr.js +15 -13
  88. package/dist/core/build/plugins/util.d.ts +26 -11
  89. package/dist/core/build/plugins/util.js +22 -6
  90. package/dist/core/build/static-build.js +30 -25
  91. package/dist/core/build/types.d.ts +6 -6
  92. package/dist/core/client-directive/build.js +1 -2
  93. package/dist/core/config/config.js +2 -7
  94. package/dist/core/config/logging.js +1 -2
  95. package/dist/core/config/schema.d.ts +92 -60
  96. package/dist/core/config/schema.js +6 -2
  97. package/dist/core/config/settings.js +1 -2
  98. package/dist/core/config/timer.js +4 -8
  99. package/dist/core/constants.js +1 -1
  100. package/dist/core/cookies/cookies.js +3 -6
  101. package/dist/core/dev/dev.js +1 -1
  102. package/dist/core/dev/restart.js +1 -2
  103. package/dist/core/errors/errors-data.d.ts +24 -0
  104. package/dist/core/errors/errors-data.js +13 -2
  105. package/dist/core/errors/errors.js +1 -2
  106. package/dist/core/errors/overlay.js +1 -2
  107. package/dist/core/errors/printer.js +2 -4
  108. package/dist/core/errors/zod-error-map.js +2 -4
  109. package/dist/core/fs/index.js +2 -4
  110. package/dist/core/logger/vite.js +9 -18
  111. package/dist/core/messages.js +2 -2
  112. package/dist/core/middleware/callMiddleware.d.ts +3 -2
  113. package/dist/core/middleware/callMiddleware.js +13 -3
  114. package/dist/core/middleware/index.js +12 -8
  115. package/dist/core/middleware/sequence.js +22 -4
  116. package/dist/core/module-loader/vite.js +1 -2
  117. package/dist/core/render/params-and-props.js +2 -4
  118. package/dist/core/render/slots.js +4 -8
  119. package/dist/core/render-context.d.ts +15 -5
  120. package/dist/core/render-context.js +134 -28
  121. package/dist/core/request.js +1 -2
  122. package/dist/core/routing/manifest/create.js +3 -6
  123. package/dist/core/sync/index.js +10 -3
  124. package/dist/core/util.d.ts +2 -0
  125. package/dist/core/util.js +18 -19
  126. package/dist/i18n/index.js +2 -4
  127. package/dist/i18n/middleware.js +1 -2
  128. package/dist/i18n/utils.js +1 -2
  129. package/dist/i18n/vite-plugin-i18n.js +1 -2
  130. package/dist/integrations/hooks.js +5 -1
  131. package/dist/jsx/babel.d.ts +3 -0
  132. package/dist/jsx/babel.js +9 -18
  133. package/dist/jsx/rehype.d.ts +11 -0
  134. package/dist/jsx/rehype.js +197 -0
  135. package/dist/jsx/server.js +20 -14
  136. package/dist/jsx/transform-options.d.ts +3 -0
  137. package/dist/jsx-runtime/index.js +8 -16
  138. package/dist/preferences/index.js +3 -6
  139. package/dist/preferences/store.js +3 -6
  140. package/dist/prefetch/index.js +8 -16
  141. package/dist/prefetch/vite-plugin-prefetch.js +2 -4
  142. package/dist/prerender/metadata.js +1 -2
  143. package/dist/prerender/routing.js +1 -1
  144. package/dist/prerender/utils.d.ts +0 -1
  145. package/dist/prerender/utils.js +2 -5
  146. package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
  147. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
  148. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
  149. package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
  150. package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
  151. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
  152. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
  153. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
  154. package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
  155. package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
  156. package/dist/runtime/client/dev-toolbar/helpers.js +2 -4
  157. package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
  158. package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
  159. package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
  160. package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
  161. package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
  162. package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
  163. package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
  164. package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
  165. package/dist/runtime/client/visible.js +1 -2
  166. package/dist/runtime/server/astro-component.js +2 -4
  167. package/dist/runtime/server/astro-island.js +7 -14
  168. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
  169. package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
  170. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  171. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  172. package/dist/runtime/server/index.js +3 -6
  173. package/dist/runtime/server/jsx.js +1 -2
  174. package/dist/runtime/server/render/any.js +1 -2
  175. package/dist/runtime/server/render/astro/instance.js +1 -2
  176. package/dist/runtime/server/render/astro/render.js +5 -10
  177. package/dist/runtime/server/render/component.js +6 -11
  178. package/dist/runtime/server/render/dom.js +1 -2
  179. package/dist/runtime/server/render/page.js +1 -2
  180. package/dist/runtime/server/render/script.js +1 -2
  181. package/dist/runtime/server/render/slot.js +1 -2
  182. package/dist/runtime/server/render/tags.js +2 -4
  183. package/dist/runtime/server/render/util.js +2 -4
  184. package/dist/runtime/server/shorthash.js +1 -2
  185. package/dist/runtime/server/transition.js +4 -8
  186. package/dist/runtime/server/util.js +1 -2
  187. package/dist/transitions/events.d.ts +3 -3
  188. package/dist/transitions/events.js +5 -4
  189. package/dist/transitions/router.js +22 -113
  190. package/dist/transitions/swap-functions.d.ts +12 -0
  191. package/dist/transitions/swap-functions.js +105 -0
  192. package/dist/vite-plugin-astro/compile.js +1 -2
  193. package/dist/vite-plugin-astro/hmr.js +5 -10
  194. package/dist/vite-plugin-astro/index.js +2 -4
  195. package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
  196. package/dist/vite-plugin-astro-server/pipeline.js +59 -11
  197. package/dist/vite-plugin-astro-server/plugin.js +6 -6
  198. package/dist/vite-plugin-astro-server/response.js +1 -2
  199. package/dist/vite-plugin-astro-server/route.js +36 -42
  200. package/dist/vite-plugin-astro-server/vite.js +1 -2
  201. package/dist/vite-plugin-config-alias/index.js +7 -14
  202. package/dist/vite-plugin-head/index.js +3 -6
  203. package/dist/vite-plugin-html/index.js +1 -2
  204. package/dist/vite-plugin-html/transform/escape.js +2 -4
  205. package/dist/vite-plugin-html/transform/slots.js +1 -2
  206. package/dist/vite-plugin-html/transform/utils.js +1 -2
  207. package/dist/vite-plugin-inject-env-ts/index.js +37 -11
  208. package/dist/vite-plugin-integrations-container/index.js +3 -6
  209. package/dist/vite-plugin-load-fallback/index.js +1 -2
  210. package/dist/vite-plugin-markdown/index.js +1 -2
  211. package/dist/vite-plugin-mdx/index.d.ts +3 -0
  212. package/dist/vite-plugin-mdx/tag.d.ts +2 -0
  213. package/dist/vite-plugin-mdx/tag.js +3 -6
  214. package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
  215. package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
  216. package/dist/vite-plugin-scanner/index.js +4 -6
  217. package/dist/vite-plugin-scanner/scan.js +2 -4
  218. package/dist/vite-plugin-scripts/page-ssr.js +3 -6
  219. package/package.json +18 -14
  220. package/templates/actions.mjs +61 -0
  221. package/types/actions.d.ts +3 -0
  222. package/types/content.d.ts +2 -2
@@ -5,8 +5,7 @@ const CUR = {
5
5
  validate(input) {
6
6
  const reserved = readUInt16LE(input, 0);
7
7
  const imageCount = readUInt16LE(input, 4);
8
- if (reserved !== 0 || imageCount === 0)
9
- return false;
8
+ if (reserved !== 0 || imageCount === 0) return false;
10
9
  const imageType = readUInt16LE(input, 2);
11
10
  return imageType === TYPE_CURSOR;
12
11
  },
@@ -64,8 +64,7 @@ const ICNS = {
64
64
  let imageHeader = readImageHeader(input, imageOffset);
65
65
  let imageSize = getImageSize(imageHeader[0]);
66
66
  imageOffset += imageHeader[1];
67
- if (imageOffset === fileLength)
68
- return imageSize;
67
+ if (imageOffset === fileLength) return imageSize;
69
68
  const result = {
70
69
  height: imageSize.height,
71
70
  images: [imageSize],
@@ -17,16 +17,14 @@ const ICO = {
17
17
  validate(input) {
18
18
  const reserved = readUInt16LE(input, 0);
19
19
  const imageCount = readUInt16LE(input, 4);
20
- if (reserved !== 0 || imageCount === 0)
21
- return false;
20
+ if (reserved !== 0 || imageCount === 0) return false;
22
21
  const imageType = readUInt16LE(input, 2);
23
22
  return imageType === TYPE_ICON;
24
23
  },
25
24
  calculate(input) {
26
25
  const nbImages = readUInt16LE(input, 4);
27
26
  const imageSize = getImageSize(input, 0);
28
- if (nbImages === 1)
29
- return imageSize;
27
+ if (nbImages === 1) return imageSize;
30
28
  const imgs = [imageSize];
31
29
  for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) {
32
30
  imgs.push(getImageSize(input, imageIndex));
@@ -1,11 +1,9 @@
1
1
  import { readUInt32BE, findBox } from "./utils.js";
2
2
  const JP2 = {
3
3
  validate(input) {
4
- if (readUInt32BE(input, 4) !== 1783636e3 || readUInt32BE(input, 0) < 1)
5
- return false;
4
+ if (readUInt32BE(input, 4) !== 1783636e3 || readUInt32BE(input, 0) < 1) return false;
6
5
  const ftypBox = findBox(input, "ftyp", 0);
7
- if (!ftypBox)
8
- return false;
6
+ if (!ftypBox) return false;
9
7
  return readUInt32BE(input, ftypBox.offset + 4) === 1718909296;
10
8
  },
11
9
  calculate(input) {
@@ -24,11 +24,9 @@ function readUInt(input, bits, offset, isBigEndian) {
24
24
  return methods[methodName](input, offset);
25
25
  }
26
26
  function readBox(buffer, offset) {
27
- if (buffer.length - offset < 4)
28
- return;
27
+ if (buffer.length - offset < 4) return;
29
28
  const boxSize = readUInt32BE(buffer, offset);
30
- if (buffer.length - offset < boxSize)
31
- return;
29
+ if (buffer.length - offset < boxSize) return;
32
30
  return {
33
31
  name: toUTF8String(buffer, 4 + offset, 8 + offset),
34
32
  offset,
@@ -38,10 +36,8 @@ function readBox(buffer, offset) {
38
36
  function findBox(buffer, boxName, offset) {
39
37
  while (offset < buffer.length) {
40
38
  const box = readBox(buffer, offset);
41
- if (!box)
42
- break;
43
- if (box.name === boxName)
44
- return box;
39
+ if (!box) break;
40
+ if (box.name === boxName) return box;
45
41
  offset += box.size;
46
42
  }
47
43
  }
@@ -10,7 +10,7 @@ import {
10
10
  removeBase,
11
11
  removeQueryString
12
12
  } from "../core/path.js";
13
- import { isServerLikeOutput } from "../prerender/utils.js";
13
+ import { isServerLikeOutput } from "../core/util.js";
14
14
  import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
15
15
  import { emitESMImage } from "./utils/emitAsset.js";
16
16
  import { getAssetsPrefix } from "./utils/getAssetsPrefix.js";
@@ -11,7 +11,7 @@ export declare const visit: {
11
11
  node: (node: traverse.Node, opts: traverse.TraverseOptions<traverse.Node>, scope?: traverse.Scope | undefined, state?: any, path?: traverse.NodePath<traverse.Node> | undefined, skipKeys?: Record<string, boolean> | undefined) => void;
12
12
  clearNode: (node: traverse.Node, opts?: traverse.RemovePropertiesOptions | undefined) => void;
13
13
  removeProperties: (tree: traverse.Node, opts?: traverse.RemovePropertiesOptions | undefined) => traverse.Node;
14
- hasType: (tree: traverse.Node, type: "CatchClause" | "ClassBody" | "Identifier" | "Program" | "SpreadElement" | "Super" | "SwitchCase" | "TemplateElement" | "VariableDeclarator" | "ArrayExpression" | "ArrowFunctionExpression" | "AssignmentExpression" | "AwaitExpression" | "BinaryExpression" | "CallExpression" | "ClassExpression" | "ConditionalExpression" | "FunctionExpression" | "ImportExpression" | "LogicalExpression" | "MemberExpression" | "MetaProperty" | "NewExpression" | "ObjectExpression" | "SequenceExpression" | "TaggedTemplateExpression" | "TemplateLiteral" | "ThisExpression" | "UnaryExpression" | "UpdateExpression" | "YieldExpression" | "ClassDeclaration" | "FunctionDeclaration" | "ImportDeclaration" | "ExportNamedDeclaration" | "ExportDefaultDeclaration" | "ExportAllDeclaration" | "ImportSpecifier" | "ImportDefaultSpecifier" | "ImportNamespaceSpecifier" | "ExportSpecifier" | "ObjectPattern" | "ArrayPattern" | "RestElement" | "AssignmentPattern" | "ExpressionStatement" | "BlockStatement" | "StaticBlock" | "EmptyStatement" | "DebuggerStatement" | "WithStatement" | "ReturnStatement" | "LabeledStatement" | "BreakStatement" | "ContinueStatement" | "IfStatement" | "SwitchStatement" | "ThrowStatement" | "TryStatement" | "WhileStatement" | "DoWhileStatement" | "ForStatement" | "ForInStatement" | "ForOfStatement" | "VariableDeclaration" | "File" | "JSXAttribute" | "JSXSpreadAttribute" | "JSXIdentifier" | "JSXNamespacedName" | "JSXElement" | "JSXOpeningElement" | "JSXMemberExpression" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayTypeAnnotation" | "BigIntLiteral" | "BindExpression" | "BooleanLiteral" | "BooleanLiteralTypeAnnotation" | "BooleanTypeAnnotation" | "ClassAccessorProperty" | "ClassImplements" | "ClassMethod" | "ClassPrivateMethod" | "ClassPrivateProperty" | "ClassProperty" | "DecimalLiteral" | "DeclareClass" | "DeclareExportAllDeclaration" | "DeclareExportDeclaration" | "DeclareFunction" | "DeclareInterface" | "DeclareModule" | "DeclareModuleExports" | "DeclareOpaqueType" | "DeclareTypeAlias" | "DeclareVariable" | "DeclaredPredicate" | "Decorator" | "Directive" | "DirectiveLiteral" | "DoExpression" | "EmptyTypeAnnotation" | "EnumBooleanBody" | "EnumBooleanMember" | "EnumDeclaration" | "EnumDefaultedMember" | "EnumNumberBody" | "EnumNumberMember" | "EnumStringBody" | "EnumStringMember" | "EnumSymbolBody" | "ExistsTypeAnnotation" | "ExportDefaultSpecifier" | "ExportNamespaceSpecifier" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Import" | "ImportAttribute" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "JSXClosingElement" | "JSXClosingFragment" | "JSXEmptyExpression" | "JSXExpressionContainer" | "JSXFragment" | "JSXOpeningFragment" | "JSXSpreadChild" | "JSXText" | "MixedTypeAnnotation" | "ModuleExpression" | "Noop" | "NullLiteral" | "NullLiteralTypeAnnotation" | "NullableTypeAnnotation" | "NumberLiteral" | "NumberLiteralTypeAnnotation" | "NumberTypeAnnotation" | "NumericLiteral" | "ObjectMethod" | "ObjectProperty" | "ObjectTypeAnnotation" | "ObjectTypeCallProperty" | "ObjectTypeIndexer" | "ObjectTypeInternalSlot" | "ObjectTypeProperty" | "ObjectTypeSpreadProperty" | "OpaqueType" | "OptionalCallExpression" | "OptionalIndexedAccessType" | "OptionalMemberExpression" | "ParenthesizedExpression" | "PipelineBareFunction" | "PipelinePrimaryTopicReference" | "PipelineTopicExpression" | "Placeholder" | "PrivateName" | "QualifiedTypeIdentifier" | "RecordExpression" | "RegExpLiteral" | "RegexLiteral" | "RestProperty" | "SpreadProperty" | "StringLiteral" | "StringLiteralTypeAnnotation" | "StringTypeAnnotation" | "SymbolTypeAnnotation" | "TSAnyKeyword" | "TSArrayType" | "TSAsExpression" | "TSBigIntKeyword" | "TSBooleanKeyword" | "TSCallSignatureDeclaration" | "TSConditionalType" | "TSConstructSignatureDeclaration" | "TSConstructorType" | "TSDeclareFunction" | "TSDeclareMethod" | "TSEnumDeclaration" | "TSEnumMember" | "TSExportAssignment" | "TSExpressionWithTypeArguments" | "TSExternalModuleReference" | "TSFunctionType" | "TSImportEqualsDeclaration" | "TSImportType" | "TSIndexSignature" | "TSIndexedAccessType" | "TSInferType" | "TSInstantiationExpression" | "TSInterfaceBody" | "TSInterfaceDeclaration" | "TSIntersectionType" | "TSIntrinsicKeyword" | "TSLiteralType" | "TSMappedType" | "TSMethodSignature" | "TSModuleBlock" | "TSModuleDeclaration" | "TSNamedTupleMember" | "TSNamespaceExportDeclaration" | "TSNeverKeyword" | "TSNonNullExpression" | "TSNullKeyword" | "TSNumberKeyword" | "TSObjectKeyword" | "TSOptionalType" | "TSParameterProperty" | "TSParenthesizedType" | "TSPropertySignature" | "TSQualifiedName" | "TSRestType" | "TSSatisfiesExpression" | "TSStringKeyword" | "TSSymbolKeyword" | "TSThisType" | "TSTupleType" | "TSTypeAliasDeclaration" | "TSTypeAnnotation" | "TSTypeAssertion" | "TSTypeLiteral" | "TSTypeOperator" | "TSTypeParameter" | "TSTypeParameterDeclaration" | "TSTypeParameterInstantiation" | "TSTypePredicate" | "TSTypeQuery" | "TSTypeReference" | "TSUndefinedKeyword" | "TSUnionType" | "TSUnknownKeyword" | "TSVoidKeyword" | "ThisTypeAnnotation" | "TopicReference" | "TupleExpression" | "TupleTypeAnnotation" | "TypeAlias" | "TypeAnnotation" | "TypeCastExpression" | "TypeParameter" | "TypeParameterDeclaration" | "TypeParameterInstantiation" | "TypeofTypeAnnotation" | "UnionTypeAnnotation" | "V8IntrinsicIdentifier" | "Variance" | "VoidTypeAnnotation", denylistTypes?: string[] | undefined) => boolean;
14
+ hasType: (tree: traverse.Node, type: "CatchClause" | "ClassBody" | "Identifier" | "Program" | "SpreadElement" | "Super" | "SwitchCase" | "TemplateElement" | "VariableDeclarator" | "JSXIdentifier" | "JSXNamespacedName" | "JSXMemberExpression" | "JSXEmptyExpression" | "JSXExpressionContainer" | "JSXSpreadAttribute" | "JSXAttribute" | "JSXOpeningElement" | "JSXOpeningFragment" | "JSXClosingElement" | "JSXClosingFragment" | "JSXElement" | "JSXFragment" | "JSXText" | "ArrayExpression" | "ArrowFunctionExpression" | "AssignmentExpression" | "AwaitExpression" | "BinaryExpression" | "CallExpression" | "ClassExpression" | "ConditionalExpression" | "FunctionExpression" | "ImportExpression" | "LogicalExpression" | "MemberExpression" | "MetaProperty" | "NewExpression" | "ObjectExpression" | "SequenceExpression" | "TaggedTemplateExpression" | "TemplateLiteral" | "ThisExpression" | "UnaryExpression" | "UpdateExpression" | "YieldExpression" | "ClassDeclaration" | "FunctionDeclaration" | "ImportDeclaration" | "ExportNamedDeclaration" | "ExportDefaultDeclaration" | "ExportAllDeclaration" | "ImportSpecifier" | "ImportDefaultSpecifier" | "ImportNamespaceSpecifier" | "ExportSpecifier" | "ObjectPattern" | "ArrayPattern" | "RestElement" | "AssignmentPattern" | "ExpressionStatement" | "BlockStatement" | "StaticBlock" | "EmptyStatement" | "DebuggerStatement" | "WithStatement" | "ReturnStatement" | "LabeledStatement" | "BreakStatement" | "ContinueStatement" | "IfStatement" | "SwitchStatement" | "ThrowStatement" | "TryStatement" | "WhileStatement" | "DoWhileStatement" | "ForStatement" | "ForInStatement" | "ForOfStatement" | "VariableDeclaration" | "File" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayTypeAnnotation" | "BigIntLiteral" | "BindExpression" | "BooleanLiteral" | "BooleanLiteralTypeAnnotation" | "BooleanTypeAnnotation" | "ClassAccessorProperty" | "ClassImplements" | "ClassMethod" | "ClassPrivateMethod" | "ClassPrivateProperty" | "ClassProperty" | "DecimalLiteral" | "DeclareClass" | "DeclareExportAllDeclaration" | "DeclareExportDeclaration" | "DeclareFunction" | "DeclareInterface" | "DeclareModule" | "DeclareModuleExports" | "DeclareOpaqueType" | "DeclareTypeAlias" | "DeclareVariable" | "DeclaredPredicate" | "Decorator" | "Directive" | "DirectiveLiteral" | "DoExpression" | "EmptyTypeAnnotation" | "EnumBooleanBody" | "EnumBooleanMember" | "EnumDeclaration" | "EnumDefaultedMember" | "EnumNumberBody" | "EnumNumberMember" | "EnumStringBody" | "EnumStringMember" | "EnumSymbolBody" | "ExistsTypeAnnotation" | "ExportDefaultSpecifier" | "ExportNamespaceSpecifier" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Import" | "ImportAttribute" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "JSXSpreadChild" | "MixedTypeAnnotation" | "ModuleExpression" | "Noop" | "NullLiteral" | "NullLiteralTypeAnnotation" | "NullableTypeAnnotation" | "NumberLiteral" | "NumberLiteralTypeAnnotation" | "NumberTypeAnnotation" | "NumericLiteral" | "ObjectMethod" | "ObjectProperty" | "ObjectTypeAnnotation" | "ObjectTypeCallProperty" | "ObjectTypeIndexer" | "ObjectTypeInternalSlot" | "ObjectTypeProperty" | "ObjectTypeSpreadProperty" | "OpaqueType" | "OptionalCallExpression" | "OptionalIndexedAccessType" | "OptionalMemberExpression" | "ParenthesizedExpression" | "PipelineBareFunction" | "PipelinePrimaryTopicReference" | "PipelineTopicExpression" | "Placeholder" | "PrivateName" | "QualifiedTypeIdentifier" | "RecordExpression" | "RegExpLiteral" | "RegexLiteral" | "RestProperty" | "SpreadProperty" | "StringLiteral" | "StringLiteralTypeAnnotation" | "StringTypeAnnotation" | "SymbolTypeAnnotation" | "TSAnyKeyword" | "TSArrayType" | "TSAsExpression" | "TSBigIntKeyword" | "TSBooleanKeyword" | "TSCallSignatureDeclaration" | "TSConditionalType" | "TSConstructSignatureDeclaration" | "TSConstructorType" | "TSDeclareFunction" | "TSDeclareMethod" | "TSEnumDeclaration" | "TSEnumMember" | "TSExportAssignment" | "TSExpressionWithTypeArguments" | "TSExternalModuleReference" | "TSFunctionType" | "TSImportEqualsDeclaration" | "TSImportType" | "TSIndexSignature" | "TSIndexedAccessType" | "TSInferType" | "TSInstantiationExpression" | "TSInterfaceBody" | "TSInterfaceDeclaration" | "TSIntersectionType" | "TSIntrinsicKeyword" | "TSLiteralType" | "TSMappedType" | "TSMethodSignature" | "TSModuleBlock" | "TSModuleDeclaration" | "TSNamedTupleMember" | "TSNamespaceExportDeclaration" | "TSNeverKeyword" | "TSNonNullExpression" | "TSNullKeyword" | "TSNumberKeyword" | "TSObjectKeyword" | "TSOptionalType" | "TSParameterProperty" | "TSParenthesizedType" | "TSPropertySignature" | "TSQualifiedName" | "TSRestType" | "TSSatisfiesExpression" | "TSStringKeyword" | "TSSymbolKeyword" | "TSThisType" | "TSTupleType" | "TSTypeAliasDeclaration" | "TSTypeAnnotation" | "TSTypeAssertion" | "TSTypeLiteral" | "TSTypeOperator" | "TSTypeParameter" | "TSTypeParameterDeclaration" | "TSTypeParameterInstantiation" | "TSTypePredicate" | "TSTypeQuery" | "TSTypeReference" | "TSUndefinedKeyword" | "TSUnionType" | "TSUnknownKeyword" | "TSVoidKeyword" | "ThisTypeAnnotation" | "TopicReference" | "TupleExpression" | "TupleTypeAnnotation" | "TypeAlias" | "TypeAnnotation" | "TypeCastExpression" | "TypeParameter" | "TypeParameterDeclaration" | "TypeParameterInstantiation" | "TypeofTypeAnnotation" | "UnionTypeAnnotation" | "V8IntrinsicIdentifier" | "Variance" | "VoidTypeAnnotation", denylistTypes?: string[] | undefined) => boolean;
15
15
  cache: typeof traverse.cache;
16
16
  };
17
17
  export { t };
@@ -6,8 +6,7 @@ function ensureImport(root, importDeclaration) {
6
6
  if (path.node.source.value === importDeclaration.source.value) {
7
7
  path.node.specifiers.forEach(
8
8
  (specifier) => specifiersToFind.forEach((specifierToFind, i) => {
9
- if (specifier.type !== specifierToFind.type)
10
- return;
9
+ if (specifier.type !== specifierToFind.type) return;
11
10
  if (specifier.local.name === specifierToFind.local.name) {
12
11
  specifiersToFind.splice(i, 1);
13
12
  }
@@ -16,16 +15,13 @@ function ensureImport(root, importDeclaration) {
16
15
  }
17
16
  }
18
17
  });
19
- if (specifiersToFind.length === 0)
20
- return;
18
+ if (specifiersToFind.length === 0) return;
21
19
  visit(root, {
22
20
  Program(path) {
23
21
  const declaration = t.importDeclaration(specifiersToFind, importDeclaration.source);
24
22
  const latestImport = path.get("body").filter((statement) => statement.isImportDeclaration()).pop();
25
- if (latestImport)
26
- latestImport.insertAfter(declaration);
27
- else
28
- path.unshiftContainer("body", declaration);
23
+ if (latestImport) latestImport.insertAfter(declaration);
24
+ else path.unshiftContainer("body", declaration);
29
25
  }
30
26
  });
31
27
  }
@@ -349,8 +349,7 @@ function isAdapter(integration) {
349
349
  async function parseAstroConfig(configURL) {
350
350
  const source = await fs.readFile(fileURLToPath(configURL), { encoding: "utf-8" });
351
351
  const result = parse(source);
352
- if (!result)
353
- throw new Error("Unknown error parsing astro config");
352
+ if (!result) throw new Error("Unknown error parsing astro config");
354
353
  if (result.errors.length > 0)
355
354
  throw new Error("Error parsing astro config: " + JSON.stringify(result.errors));
356
355
  return result;
@@ -379,21 +378,16 @@ async function addIntegration(ast, integration) {
379
378
  visit(ast, {
380
379
  // eslint-disable-next-line @typescript-eslint/no-shadow
381
380
  ExportDefaultDeclaration(path2) {
382
- if (!t.isCallExpression(path2.node.declaration))
383
- return;
381
+ if (!t.isCallExpression(path2.node.declaration)) return;
384
382
  const configObject = path2.node.declaration.arguments[0];
385
- if (!t.isObjectExpression(configObject))
386
- return;
383
+ if (!t.isObjectExpression(configObject)) return;
387
384
  let integrationsProp = configObject.properties.find((prop) => {
388
- if (prop.type !== "ObjectProperty")
389
- return false;
385
+ if (prop.type !== "ObjectProperty") return false;
390
386
  if (prop.key.type === "Identifier") {
391
- if (prop.key.name === "integrations")
392
- return true;
387
+ if (prop.key.name === "integrations") return true;
393
388
  }
394
389
  if (prop.key.type === "StringLiteral") {
395
- if (prop.key.value === "integrations")
396
- return true;
390
+ if (prop.key.value === "integrations") return true;
397
391
  }
398
392
  return false;
399
393
  });
@@ -409,8 +403,7 @@ async function addIntegration(ast, integration) {
409
403
  const existingIntegrationCall = integrationsProp.value.elements.find(
410
404
  (expr) => t.isCallExpression(expr) && t.isIdentifier(expr.callee) && expr.callee.name === integrationId.name
411
405
  );
412
- if (existingIntegrationCall)
413
- return;
406
+ if (existingIntegrationCall) return;
414
407
  integrationsProp.value.elements.push(integrationCall);
415
408
  }
416
409
  });
@@ -424,21 +417,16 @@ async function setAdapter(ast, adapter, exportName) {
424
417
  visit(ast, {
425
418
  // eslint-disable-next-line @typescript-eslint/no-shadow
426
419
  ExportDefaultDeclaration(path2) {
427
- if (!t.isCallExpression(path2.node.declaration))
428
- return;
420
+ if (!t.isCallExpression(path2.node.declaration)) return;
429
421
  const configObject = path2.node.declaration.arguments[0];
430
- if (!t.isObjectExpression(configObject))
431
- return;
422
+ if (!t.isObjectExpression(configObject)) return;
432
423
  let outputProp = configObject.properties.find((prop) => {
433
- if (prop.type !== "ObjectProperty")
434
- return false;
424
+ if (prop.type !== "ObjectProperty") return false;
435
425
  if (prop.key.type === "Identifier") {
436
- if (prop.key.name === "output")
437
- return true;
426
+ if (prop.key.name === "output") return true;
438
427
  }
439
428
  if (prop.key.type === "StringLiteral") {
440
- if (prop.key.value === "output")
441
- return true;
429
+ if (prop.key.value === "output") return true;
442
430
  }
443
431
  return false;
444
432
  });
@@ -448,15 +436,12 @@ async function setAdapter(ast, adapter, exportName) {
448
436
  );
449
437
  }
450
438
  let adapterProp = configObject.properties.find((prop) => {
451
- if (prop.type !== "ObjectProperty")
452
- return false;
439
+ if (prop.type !== "ObjectProperty") return false;
453
440
  if (prop.key.type === "Identifier") {
454
- if (prop.key.name === "adapter")
455
- return true;
441
+ if (prop.key.name === "adapter") return true;
456
442
  }
457
443
  if (prop.key.type === "StringLiteral") {
458
- if (prop.key.value === "adapter")
459
- return true;
444
+ if (prop.key.value === "adapter") return true;
460
445
  }
461
446
  return false;
462
447
  });
@@ -553,8 +538,7 @@ async function getInstallIntegrationsCommand({
553
538
  }) {
554
539
  const pm = await preferredPM(cwd);
555
540
  logger.debug("add", `package manager: ${JSON.stringify(pm)}`);
556
- if (!pm)
557
- return null;
541
+ if (!pm) return null;
558
542
  const dependencies = await convertIntegrationsToInstallSpecifiers(integrations);
559
543
  switch (pm.name) {
560
544
  case "npm":
@@ -583,8 +567,7 @@ async function convertIntegrationsToInstallSpecifiers(integrations) {
583
567
  }
584
568
  async function resolveRangeToInstallSpecifier(name, range) {
585
569
  const versions = await fetchPackageVersions(name);
586
- if (versions instanceof Error)
587
- return name;
570
+ if (versions instanceof Error) return name;
588
571
  const stableVersions = versions.filter((v) => !v.includes("-"));
589
572
  const maxStable = maxSatisfying(stableVersions, range);
590
573
  return `${name}@^${maxStable}`;
@@ -606,11 +589,9 @@ async function tryToInstallIntegrations({
606
589
  }) {
607
590
  const installCommand = await getInstallIntegrationsCommand({ integrations, cwd, logger });
608
591
  const inheritedFlags = Object.entries(flags).map(([flag]) => {
609
- if (flag == "_")
610
- return;
592
+ if (flag == "_") return;
611
593
  if (INHERITED_FLAGS.has(flag)) {
612
- if (flag.length === 1)
613
- return `-${flag}`;
594
+ if (flag.length === 1) return `-${flag}`;
614
595
  return `--${flag}`;
615
596
  }
616
597
  }).filter(Boolean).flat();
@@ -840,8 +821,7 @@ ${message}`
840
821
  }
841
822
  function parseIntegrationName(spec) {
842
823
  const result = parseNpmName(spec);
843
- if (!result)
844
- return;
824
+ if (!result) return;
845
825
  let { scope, name } = result;
846
826
  let tag = "latest";
847
827
  if (scope) {
@@ -855,8 +835,7 @@ function parseIntegrationName(spec) {
855
835
  return { scope, name, tag };
856
836
  }
857
837
  async function askToContinue({ flags }) {
858
- if (flags.yes || flags.y)
859
- return true;
838
+ if (flags.yes || flags.y) return true;
860
839
  const response = await prompts({
861
840
  type: "confirm",
862
841
  name: "askToContinue",
@@ -869,11 +848,9 @@ function getDiffContent(input, output) {
869
848
  let changes = [];
870
849
  for (const change of diffWords(input, output)) {
871
850
  let lines = change.value.trim().split("\n").slice(0, change.count);
872
- if (lines.length === 0)
873
- continue;
851
+ if (lines.length === 0) continue;
874
852
  if (change.added) {
875
- if (!change.value.trim())
876
- continue;
853
+ if (!change.value.trim()) continue;
877
854
  changes.push(change.value);
878
855
  }
879
856
  }
@@ -2,8 +2,7 @@ import { t, visit } from "./babel.js";
2
2
  function wrapDefaultExport(ast, functionIdentifier) {
3
3
  visit(ast, {
4
4
  ExportDefaultDeclaration(path) {
5
- if (!t.isExpression(path.node.declaration))
6
- return;
5
+ if (!t.isExpression(path.node.declaration)) return;
7
6
  if (t.isCallExpression(path.node.declaration) && t.isIdentifier(path.node.declaration.callee) && path.node.declaration.callee.name === functionIdentifier.name)
8
7
  return;
9
8
  path.node.declaration = t.callExpression(functionIdentifier, [path.node.declaration]);
package/dist/cli/index.js CHANGED
@@ -45,8 +45,7 @@ function printVersion() {
45
45
  }
46
46
  function resolveCommand(flags) {
47
47
  const cmd = flags._[2];
48
- if (flags.version)
49
- return "version";
48
+ if (flags.version) return "version";
50
49
  const supportedCommands = /* @__PURE__ */ new Set([
51
50
  "add",
52
51
  "sync",
@@ -60,8 +60,7 @@ async function copyToClipboard(text) {
60
60
  message: "Copy to clipboard?",
61
61
  initial: true
62
62
  });
63
- if (!shouldCopy)
64
- return;
63
+ if (!shouldCopy) return;
65
64
  try {
66
65
  execSync(command, {
67
66
  input: text.trim(),
@@ -25,8 +25,7 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
25
25
  const packageImport = await import(packageName);
26
26
  return packageImport;
27
27
  } catch (e) {
28
- if (options.optional)
29
- return void 0;
28
+ if (options.optional) return void 0;
30
29
  let message = `To continue, Astro requires the following dependency to be installed: ${bold(
31
30
  packageName
32
31
  )}.`;
@@ -178,15 +177,13 @@ async function fetchPackageVersions(packageName) {
178
177
  }
179
178
  let _registry;
180
179
  async function getRegistry() {
181
- if (_registry)
182
- return _registry;
180
+ if (_registry) return _registry;
183
181
  const fallback = "https://registry.npmjs.org";
184
182
  const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
185
183
  try {
186
184
  const { stdout } = await execa(packageManager, ["config", "get", "registry"]);
187
185
  _registry = stdout?.trim()?.replace(/\/$/, "") || fallback;
188
- if (!new URL(_registry).host)
189
- _registry = fallback;
186
+ if (!new URL(_registry).host) _registry = fallback;
190
187
  } catch (e) {
191
188
  _registry = fallback;
192
189
  }
@@ -5,8 +5,7 @@ import { debug } from "../core/logger/core.js";
5
5
  import { formatErrorMessage } from "../core/messages.js";
6
6
  import { eventError, telemetry } from "../events/index.js";
7
7
  async function throwAndExit(cmd, err) {
8
- if (isAstroConfigZodError(err))
9
- return;
8
+ if (isAstroConfigZodError(err)) return;
10
9
  let telemetryPromise;
11
10
  let errorMessage;
12
11
  function exitWithErrorMessage() {
@@ -1,7 +1,7 @@
1
1
  import type { UserConfig } from 'vite';
2
- import type { AstroUserConfig } from '../@types/astro.js';
2
+ import type { AstroInlineConfig, AstroUserConfig } from '../@types/astro.js';
3
3
  export declare function defineConfig(config: AstroUserConfig): AstroUserConfig;
4
- export declare function getViteConfig(inlineConfig: UserConfig): ({ mode, command }: {
4
+ export declare function getViteConfig(inlineConfig: UserConfig, inlineAstroConfig?: AstroInlineConfig): ({ mode, command }: {
5
5
  mode: string;
6
6
  command: 'serve' | 'build';
7
7
  }) => Promise<Record<string, any>>;
@@ -2,7 +2,7 @@ import { Logger } from "../core/logger/core.js";
2
2
  function defineConfig(config) {
3
3
  return config;
4
4
  }
5
- function getViteConfig(inlineConfig) {
5
+ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
6
6
  return async ({ mode, command }) => {
7
7
  const cmd = command === "serve" ? "dev" : command;
8
8
  const [
@@ -26,7 +26,7 @@ function getViteConfig(inlineConfig) {
26
26
  dest: nodeLogDestination,
27
27
  level: "info"
28
28
  });
29
- const { astroConfig: config } = await resolveConfig({}, cmd);
29
+ const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
30
30
  let settings = await createSettings(config, inlineConfig.root);
31
31
  settings = await runHookConfigSetup({ settings, command: cmd, logger });
32
32
  const viteConfig = await createVite(
@@ -1,7 +1,7 @@
1
1
  export { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from './consts.js';
2
2
  export { attachContentServerListeners } from './server-listeners.js';
3
3
  export { createContentTypesGenerator } from './types-generator.js';
4
- export { contentObservable, getContentPaths, getDotAstroTypeReference, hasAssetPropagationFlag, } from './utils.js';
4
+ export { contentObservable, getContentPaths, hasAssetPropagationFlag } from './utils.js';
5
5
  export { astroContentAssetPropagationPlugin } from './vite-plugin-content-assets.js';
6
6
  export { astroContentImportPlugin } from './vite-plugin-content-imports.js';
7
7
  export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
@@ -1,12 +1,7 @@
1
1
  import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from "./consts.js";
2
2
  import { attachContentServerListeners } from "./server-listeners.js";
3
3
  import { createContentTypesGenerator } from "./types-generator.js";
4
- import {
5
- contentObservable,
6
- getContentPaths,
7
- getDotAstroTypeReference,
8
- hasAssetPropagationFlag
9
- } from "./utils.js";
4
+ import { contentObservable, getContentPaths, hasAssetPropagationFlag } from "./utils.js";
10
5
  import { astroContentAssetPropagationPlugin } from "./vite-plugin-content-assets.js";
11
6
  import { astroContentImportPlugin } from "./vite-plugin-content-imports.js";
12
7
  import { astroContentVirtualModPlugin } from "./vite-plugin-content-virtual-mod.js";
@@ -20,6 +15,5 @@ export {
20
15
  contentObservable,
21
16
  createContentTypesGenerator,
22
17
  getContentPaths,
23
- getDotAstroTypeReference,
24
18
  hasAssetPropagationFlag
25
19
  };
@@ -10,10 +10,11 @@ export declare function createCollectionToGlobResultMap({ globResult, contentDir
10
10
  globResult: GlobResult;
11
11
  contentDir: string;
12
12
  }): CollectionToEntryMap;
13
- export declare function createGetCollection({ contentCollectionToEntryMap, dataCollectionToEntryMap, getRenderEntryImport, }: {
13
+ export declare function createGetCollection({ contentCollectionToEntryMap, dataCollectionToEntryMap, getRenderEntryImport, cacheEntriesByCollection, }: {
14
14
  contentCollectionToEntryMap: CollectionToEntryMap;
15
15
  dataCollectionToEntryMap: CollectionToEntryMap;
16
16
  getRenderEntryImport: GetEntryImport;
17
+ cacheEntriesByCollection: Map<string, any[]>;
17
18
  }): (collection: string, filter?: (entry: any) => unknown) => Promise<any[]>;
18
19
  export declare function createGetEntryBySlug({ getEntryImport, getRenderEntryImport, }: {
19
20
  getEntryImport: GetEntryImport;
@@ -12,8 +12,7 @@ import {
12
12
  unescapeHTML
13
13
  } from "../runtime/server/index.js";
14
14
  function defineCollection(config) {
15
- if (!config.type)
16
- config.type = "content";
15
+ if (!config.type) config.type = "content";
17
16
  return config;
18
17
  }
19
18
  function createCollectionToGlobResultMap({
@@ -24,19 +23,18 @@ function createCollectionToGlobResultMap({
24
23
  for (const key in globResult) {
25
24
  const keyRelativeToContentDir = key.replace(new RegExp(`^${contentDir}`), "");
26
25
  const segments = keyRelativeToContentDir.split("/");
27
- if (segments.length <= 1)
28
- continue;
26
+ if (segments.length <= 1) continue;
29
27
  const collection = segments[0];
30
28
  collectionToGlobResultMap[collection] ??= {};
31
29
  collectionToGlobResultMap[collection][key] = globResult[key];
32
30
  }
33
31
  return collectionToGlobResultMap;
34
32
  }
35
- const cacheEntriesByCollection = /* @__PURE__ */ new Map();
36
33
  function createGetCollection({
37
34
  contentCollectionToEntryMap,
38
35
  dataCollectionToEntryMap,
39
- getRenderEntryImport
36
+ getRenderEntryImport,
37
+ cacheEntriesByCollection
40
38
  }) {
41
39
  return async function getCollection(collection, filter) {
42
40
  let type;
@@ -100,8 +98,7 @@ function createGetEntryBySlug({
100
98
  }) {
101
99
  return async function getEntryBySlug(collection, slug) {
102
100
  const entryImport = await getEntryImport(collection, slug);
103
- if (typeof entryImport !== "function")
104
- return void 0;
101
+ if (typeof entryImport !== "function") return void 0;
105
102
  const entry = await entryImport();
106
103
  return {
107
104
  id: entry.id,
@@ -122,8 +119,7 @@ function createGetEntryBySlug({
122
119
  function createGetDataEntryById({ getEntryImport }) {
123
120
  return async function getDataEntryById(collection, id) {
124
121
  const lazyImport = await getEntryImport(collection, id);
125
- if (!lazyImport)
126
- throw new Error(`Entry ${collection} \u2192 ${id} was not found.`);
122
+ if (!lazyImport) throw new Error(`Entry ${collection} \u2192 ${id} was not found.`);
127
123
  const entry = await lazyImport();
128
124
  return {
129
125
  id: entry.id,
@@ -151,8 +147,7 @@ function createGetEntry({
151
147
  lookupId = "id" in collectionOrLookupObject ? collectionOrLookupObject.id : collectionOrLookupObject.slug;
152
148
  }
153
149
  const entryImport = await getEntryImport(collection, lookupId);
154
- if (typeof entryImport !== "function")
155
- return void 0;
150
+ if (typeof entryImport !== "function") return void 0;
156
151
  const entry = await entryImport();
157
152
  if (entry._internal.type === "content") {
158
153
  return {
@@ -193,19 +188,15 @@ async function render({
193
188
  ...AstroErrorData.UnknownContentCollectionError,
194
189
  message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
195
190
  });
196
- if (typeof renderEntryImport !== "function")
197
- throw UnexpectedRenderError;
191
+ if (typeof renderEntryImport !== "function") throw UnexpectedRenderError;
198
192
  const baseMod = await renderEntryImport();
199
- if (baseMod == null || typeof baseMod !== "object")
200
- throw UnexpectedRenderError;
193
+ if (baseMod == null || typeof baseMod !== "object") throw UnexpectedRenderError;
201
194
  const { default: defaultMod } = baseMod;
202
195
  if (isPropagatedAssetsModule(defaultMod)) {
203
196
  const { collectedStyles, collectedLinks, collectedScripts, getMod } = defaultMod;
204
- if (typeof getMod !== "function")
205
- throw UnexpectedRenderError;
197
+ if (typeof getMod !== "function") throw UnexpectedRenderError;
206
198
  const propagationMod = await getMod();
207
- if (propagationMod == null || typeof propagationMod !== "object")
208
- throw UnexpectedRenderError;
199
+ if (propagationMod == null || typeof propagationMod !== "object") throw UnexpectedRenderError;
209
200
  const Content = createComponent({
210
201
  factory(result, baseProps, slots) {
211
202
  let styles = "", links = "", scripts = "";
@@ -20,8 +20,7 @@ async function attachContentServerListeners({
20
20
  )} for changes`
21
21
  );
22
22
  const maybeTsConfigStats = await getTSConfigStatsWhenAllowJsFalse({ contentPaths, settings });
23
- if (maybeTsConfigStats)
24
- warnAllowJsIsFalse({ ...maybeTsConfigStats, logger });
23
+ if (maybeTsConfigStats) warnAllowJsIsFalse({ ...maybeTsConfigStats, logger });
25
24
  await attachListeners();
26
25
  } else {
27
26
  viteServer.watcher.on("addDir", contentDirListener);
@@ -86,18 +85,14 @@ async function getTSConfigStatsWhenAllowJsFalse({
86
85
  const isContentConfigJsFile = [".js", ".mjs"].some(
87
86
  (ext) => contentPaths.config.url.pathname.endsWith(ext)
88
87
  );
89
- if (!isContentConfigJsFile)
90
- return;
88
+ if (!isContentConfigJsFile) return;
91
89
  const inputConfig = await loadTSConfig(fileURLToPath(settings.config.root));
92
- if (typeof inputConfig === "string")
93
- return;
90
+ if (typeof inputConfig === "string") return;
94
91
  const tsConfigFileName = inputConfig.tsconfigFile.split(path.sep).pop();
95
- if (!tsConfigFileName)
96
- return;
92
+ if (!tsConfigFileName) return;
97
93
  const contentConfigFileName = contentPaths.config.url.pathname.split(path.sep).pop();
98
94
  const allowJSOption = inputConfig.tsconfig.compilerOptions?.allowJs;
99
- if (allowJSOption)
100
- return;
95
+ if (allowJSOption) return;
101
96
  return { tsConfigFileName, contentConfigFileName };
102
97
  }
103
98
  export {
@@ -52,8 +52,7 @@ async function createContentTypesGenerator({
52
52
  for (const entry of globResult) {
53
53
  const fullPath = path.join(fileURLToPath(contentPaths.contentDir), entry.path);
54
54
  const entryURL = pathToFileURL(fullPath);
55
- if (entryURL.href.startsWith(contentPaths.config.url.href))
56
- continue;
55
+ if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
57
56
  if (entry.dirent.isFile()) {
58
57
  events.push({ name: "add", entry: entryURL });
59
58
  } else if (entry.dirent.isDirectory()) {
@@ -70,8 +69,7 @@ async function createContentTypesGenerator({
70
69
  );
71
70
  const collectionKey2 = JSON.stringify(collection2);
72
71
  const isCollectionEvent = collection2.split("/").length === 1;
73
- if (!isCollectionEvent)
74
- return { shouldGenerateTypes: false };
72
+ if (!isCollectionEvent) return { shouldGenerateTypes: false };
75
73
  switch (event.name) {
76
74
  case "addDir":
77
75
  collectionEntryMap[JSON.stringify(collection2)] = {
@@ -153,8 +151,7 @@ async function createContentTypesGenerator({
153
151
  }
154
152
  }
155
153
  const contentEntryType = contentEntryConfigByExt.get(path.extname(event.entry.pathname));
156
- if (!contentEntryType)
157
- return { shouldGenerateTypes: false };
154
+ if (!contentEntryType) return { shouldGenerateTypes: false };
158
155
  const { id, slug: generatedSlug } = getContentEntryIdAndSlug({
159
156
  entry,
160
157
  contentDir,
@@ -224,8 +221,7 @@ async function createContentTypesGenerator({
224
221
  entry: pathToFileURL(rawEvent.entry),
225
222
  name: rawEvent.name
226
223
  };
227
- if (!event.entry.pathname.startsWith(contentPaths.contentDir.pathname))
228
- return;
224
+ if (!event.entry.pathname.startsWith(contentPaths.contentDir.pathname)) return;
229
225
  events.push(event);
230
226
  debounceTimeout && clearTimeout(debounceTimeout);
231
227
  const runEventsSafe = async () => {
@@ -267,8 +263,7 @@ async function createContentTypesGenerator({
267
263
  }
268
264
  function invalidateVirtualMod(viteServer) {
269
265
  const virtualMod = viteServer.moduleGraph.getModuleById("\0" + VIRTUAL_MODULE_ID);
270
- if (!virtualMod)
271
- return;
266
+ if (!virtualMod) return;
272
267
  viteServer.moduleGraph.invalidateModule(virtualMod);
273
268
  }
274
269
  function normalizeConfigPath(from, to) {