astro 4.4.0 → 4.4.1

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 (92) hide show
  1. package/dist/@types/astro.d.ts +42 -42
  2. package/dist/assets/build/generate.d.ts +1 -1
  3. package/dist/assets/build/generate.js +1 -2
  4. package/dist/cli/add/babel.d.ts +1 -1
  5. package/dist/cli/add/index.js +1 -1
  6. package/dist/cli/db/index.js +2 -0
  7. package/dist/cli/info/index.js +2 -0
  8. package/dist/cli/preferences/index.js +2 -0
  9. package/dist/content/types-generator.js +4 -4
  10. package/dist/core/app/index.js +39 -122
  11. package/dist/core/app/pipeline.d.ts +7 -0
  12. package/dist/core/app/pipeline.js +39 -0
  13. package/dist/core/base-pipeline.d.ts +59 -0
  14. package/dist/core/base-pipeline.js +27 -0
  15. package/dist/core/build/generate.d.ts +1 -1
  16. package/dist/core/build/generate.js +39 -109
  17. package/dist/core/build/index.js +0 -4
  18. package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
  19. package/dist/core/build/pipeline.js +180 -0
  20. package/dist/core/build/types.d.ts +0 -2
  21. package/dist/core/constants.d.ts +10 -1
  22. package/dist/core/constants.js +14 -4
  23. package/dist/core/dev/dev.js +1 -1
  24. package/dist/core/dev/restart.js +1 -1
  25. package/dist/core/endpoint/index.d.ts +5 -4
  26. package/dist/core/endpoint/index.js +7 -34
  27. package/dist/core/errors/errors-data.d.ts +2 -2
  28. package/dist/core/messages.js +2 -2
  29. package/dist/core/middleware/callMiddleware.d.ts +1 -1
  30. package/dist/core/middleware/callMiddleware.js +2 -9
  31. package/dist/core/middleware/index.d.ts +2 -2
  32. package/dist/core/middleware/index.js +74 -9
  33. package/dist/core/module-loader/vite.js +4 -4
  34. package/dist/core/preview/index.js +2 -0
  35. package/dist/core/preview/static-preview-server.js +1 -7
  36. package/dist/core/redirects/helpers.d.ts +1 -3
  37. package/dist/core/redirects/helpers.js +0 -29
  38. package/dist/core/redirects/index.d.ts +2 -1
  39. package/dist/core/redirects/index.js +3 -3
  40. package/dist/core/redirects/render.d.ts +2 -0
  41. package/dist/core/redirects/render.js +33 -0
  42. package/dist/core/render/index.d.ts +7 -13
  43. package/dist/core/render/index.js +7 -7
  44. package/dist/core/render/params-and-props.d.ts +8 -3
  45. package/dist/core/render/params-and-props.js +24 -16
  46. package/dist/core/render/result.d.ts +6 -5
  47. package/dist/core/render/result.js +3 -4
  48. package/dist/core/render-context.d.ts +32 -0
  49. package/dist/core/render-context.js +219 -0
  50. package/dist/core/routing/index.d.ts +0 -1
  51. package/dist/core/routing/index.js +0 -2
  52. package/dist/core/routing/params.d.ts +1 -7
  53. package/dist/core/routing/params.js +0 -15
  54. package/dist/core/sync/index.js +3 -3
  55. package/dist/i18n/middleware.d.ts +0 -5
  56. package/dist/i18n/middleware.js +61 -69
  57. package/dist/i18n/utils.d.ts +25 -0
  58. package/dist/{core/render/context.js → i18n/utils.js} +3 -49
  59. package/dist/prerender/routing.d.ts +1 -1
  60. package/dist/prerender/routing.js +2 -3
  61. package/dist/runtime/client/dev-toolbar/apps/astro.js +13 -9
  62. package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
  63. package/dist/runtime/server/endpoint.js +2 -2
  64. package/dist/vite-plugin-astro/hmr.d.ts +1 -0
  65. package/dist/vite-plugin-astro/hmr.js +7 -4
  66. package/dist/vite-plugin-astro-server/error.d.ts +2 -2
  67. package/dist/vite-plugin-astro-server/error.js +2 -5
  68. package/dist/vite-plugin-astro-server/index.d.ts +0 -6
  69. package/dist/vite-plugin-astro-server/index.js +0 -19
  70. package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
  71. package/dist/vite-plugin-astro-server/pipeline.js +117 -0
  72. package/dist/vite-plugin-astro-server/plugin.js +3 -4
  73. package/dist/vite-plugin-astro-server/request.d.ts +3 -4
  74. package/dist/vite-plugin-astro-server/request.js +6 -9
  75. package/dist/vite-plugin-astro-server/route.d.ts +3 -4
  76. package/dist/vite-plugin-astro-server/route.js +34 -162
  77. package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
  78. package/package.json +3 -8
  79. package/dist/core/app/ssrPipeline.d.ts +0 -3
  80. package/dist/core/app/ssrPipeline.js +0 -6
  81. package/dist/core/build/buildPipeline.js +0 -150
  82. package/dist/core/pipeline.d.ts +0 -39
  83. package/dist/core/pipeline.js +0 -107
  84. package/dist/core/render/context.d.ts +0 -52
  85. package/dist/core/render/core.d.ts +0 -10
  86. package/dist/core/render/core.js +0 -65
  87. package/dist/core/render/environment.d.ts +0 -34
  88. package/dist/core/render/environment.js +0 -6
  89. package/dist/runtime/server/consts.d.ts +0 -1
  90. package/dist/runtime/server/consts.js +0 -4
  91. package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
  92. package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
@@ -1374,7 +1374,7 @@ export interface AstroUserConfig {
1374
1374
  * URLs will be of the form `example.com/[locale]/content/` for every route, including the default language.
1375
1375
  * Localized folders are used for every language, including the default.
1376
1376
  */
1377
- prefixDefaultLocale: boolean;
1377
+ prefixDefaultLocale?: boolean;
1378
1378
  /**
1379
1379
  * @docs
1380
1380
  * @name i18n.routing.redirectToDefaultLocale
@@ -1402,7 +1402,7 @@ export interface AstroUserConfig {
1402
1402
  * })
1403
1403
  *```
1404
1404
  * */
1405
- redirectToDefaultLocale: boolean;
1405
+ redirectToDefaultLocale?: boolean;
1406
1406
  /**
1407
1407
  * @name i18n.routing.strategy
1408
1408
  * @type {"pathname"}
@@ -1412,47 +1412,47 @@ export interface AstroUserConfig {
1412
1412
  *
1413
1413
  * - `"pathname": The strategy is applied to the pathname of the URLs
1414
1414
  */
1415
- strategy: 'pathname';
1416
- /**
1417
- * @name i18n.domains
1418
- * @type {Record<string, string> }
1419
- * @default '{}'
1420
- * @version 4.3.0
1421
- * @description
1422
- *
1423
- * Configures the URL pattern of one or more supported languages to use a custom domain (or sub-domain).
1424
- *
1425
- * When a locale is mapped to a domain, a `/[locale]/` path prefix will not be used.
1426
- * However, localized folders within `src/pages/` are still required, including for your configured `defaultLocale`.
1427
- *
1428
- * Any other locale not configured will default to a localized path-based URL according to your `prefixDefaultLocale` strategy (e.g. `https://example.com/[locale]/blog`).
1429
- *
1430
- * ```js
1431
- * //astro.config.mjs
1432
- * export default defineConfig({
1433
- * site: "https://example.com",
1434
- * output: "server", // required, with no prerendered pages
1435
- * adapter: node({
1436
- * mode: 'standalone',
1437
- * }),
1438
- * i18n: {
1439
- * defaultLocale: "en",
1440
- * locales: ["en", "fr", "pt-br", "es"],
1441
- * prefixDefaultLocale: false,
1442
- * domains: {
1443
- * fr: "https://fr.example.com",
1444
- * es: "https://example.es"
1445
- * }
1446
- * },
1447
- * })
1448
- * ```
1449
- *
1450
- * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`.
1451
- *
1452
- * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature.
1453
- */
1454
- domains?: Record<string, string>;
1415
+ strategy?: 'pathname';
1455
1416
  };
1417
+ /**
1418
+ * @name i18n.domains
1419
+ * @type {Record<string, string> }
1420
+ * @default '{}'
1421
+ * @version 4.3.0
1422
+ * @description
1423
+ *
1424
+ * Configures the URL pattern of one or more supported languages to use a custom domain (or sub-domain).
1425
+ *
1426
+ * When a locale is mapped to a domain, a `/[locale]/` path prefix will not be used.
1427
+ * However, localized folders within `src/pages/` are still required, including for your configured `defaultLocale`.
1428
+ *
1429
+ * Any other locale not configured will default to a localized path-based URL according to your `prefixDefaultLocale` strategy (e.g. `https://example.com/[locale]/blog`).
1430
+ *
1431
+ * ```js
1432
+ * //astro.config.mjs
1433
+ * export default defineConfig({
1434
+ * site: "https://example.com",
1435
+ * output: "server", // required, with no prerendered pages
1436
+ * adapter: node({
1437
+ * mode: 'standalone',
1438
+ * }),
1439
+ * i18n: {
1440
+ * defaultLocale: "en",
1441
+ * locales: ["en", "fr", "pt-br", "es"],
1442
+ * prefixDefaultLocale: false,
1443
+ * domains: {
1444
+ * fr: "https://fr.example.com",
1445
+ * es: "https://example.es"
1446
+ * }
1447
+ * },
1448
+ * })
1449
+ * ```
1450
+ *
1451
+ * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`.
1452
+ *
1453
+ * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature.
1454
+ */
1455
+ domains?: Record<string, string>;
1456
1456
  };
1457
1457
  /** ⚠️ WARNING: SUBJECT TO CHANGE */
1458
1458
  db?: Config.Database;
@@ -1,6 +1,6 @@
1
1
  import type PQueue from 'p-queue';
2
2
  import type { AstroConfig } from '../../@types/astro.js';
3
- import type { BuildPipeline } from '../../core/build/buildPipeline.js';
3
+ import type { BuildPipeline } from '../../core/build/pipeline.js';
4
4
  import type { Logger } from '../../core/logger/core.js';
5
5
  import type { MapValue } from '../../type-utils.js';
6
6
  import type { AssetsGlobalStaticImagesList } from '../types.js';
@@ -11,8 +11,7 @@ import { getConfiguredImageService } from "../internal.js";
11
11
  import { isESMImportedImage } from "../utils/imageKind.js";
12
12
  import { loadRemoteImage } from "./remote.js";
13
13
  async function prepareAssetsGenerationEnv(pipeline, totalCount) {
14
- const config = pipeline.getConfig();
15
- const logger = pipeline.getLogger();
14
+ const { config, logger } = pipeline;
16
15
  let useCache = true;
17
16
  const assetsCacheDir = new URL("assets/", config.cacheDir);
18
17
  const count = { total: totalCount, current: 1 };
@@ -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" | "ExpressionStatement" | "BlockStatement" | "StaticBlock" | "EmptyStatement" | "DebuggerStatement" | "WithStatement" | "ReturnStatement" | "LabeledStatement" | "BreakStatement" | "ContinueStatement" | "IfStatement" | "SwitchStatement" | "ThrowStatement" | "TryStatement" | "WhileStatement" | "DoWhileStatement" | "ForStatement" | "ForInStatement" | "ForOfStatement" | "VariableDeclaration" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayPattern" | "ArrayTypeAnnotation" | "AssignmentPattern" | "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" | "ExportSpecifier" | "File" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Import" | "ImportAttribute" | "ImportDefaultSpecifier" | "ImportNamespaceSpecifier" | "ImportSpecifier" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "JSXAttribute" | "JSXClosingElement" | "JSXClosingFragment" | "JSXElement" | "JSXEmptyExpression" | "JSXExpressionContainer" | "JSXFragment" | "JSXIdentifier" | "JSXMemberExpression" | "JSXNamespacedName" | "JSXOpeningElement" | "JSXOpeningFragment" | "JSXSpreadAttribute" | "JSXSpreadChild" | "JSXText" | "MixedTypeAnnotation" | "ModuleExpression" | "Noop" | "NullLiteral" | "NullLiteralTypeAnnotation" | "NullableTypeAnnotation" | "NumberLiteral" | "NumberLiteralTypeAnnotation" | "NumberTypeAnnotation" | "NumericLiteral" | "ObjectMethod" | "ObjectPattern" | "ObjectProperty" | "ObjectTypeAnnotation" | "ObjectTypeCallProperty" | "ObjectTypeIndexer" | "ObjectTypeInternalSlot" | "ObjectTypeProperty" | "ObjectTypeSpreadProperty" | "OpaqueType" | "OptionalCallExpression" | "OptionalIndexedAccessType" | "OptionalMemberExpression" | "ParenthesizedExpression" | "PipelineBareFunction" | "PipelinePrimaryTopicReference" | "PipelineTopicExpression" | "Placeholder" | "PrivateName" | "QualifiedTypeIdentifier" | "RecordExpression" | "RegExpLiteral" | "RegexLiteral" | "RestElement" | "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: "File" | "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" | "ExpressionStatement" | "BlockStatement" | "StaticBlock" | "EmptyStatement" | "DebuggerStatement" | "WithStatement" | "ReturnStatement" | "LabeledStatement" | "BreakStatement" | "ContinueStatement" | "IfStatement" | "SwitchStatement" | "ThrowStatement" | "TryStatement" | "WhileStatement" | "DoWhileStatement" | "ForStatement" | "ForInStatement" | "ForOfStatement" | "VariableDeclaration" | "AnyTypeAnnotation" | "ArgumentPlaceholder" | "ArrayPattern" | "ArrayTypeAnnotation" | "AssignmentPattern" | "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" | "ExportSpecifier" | "FunctionTypeAnnotation" | "FunctionTypeParam" | "GenericTypeAnnotation" | "Import" | "ImportAttribute" | "ImportDefaultSpecifier" | "ImportNamespaceSpecifier" | "ImportSpecifier" | "IndexedAccessType" | "InferredPredicate" | "InterfaceDeclaration" | "InterfaceExtends" | "InterfaceTypeAnnotation" | "InterpreterDirective" | "IntersectionTypeAnnotation" | "JSXAttribute" | "JSXClosingElement" | "JSXClosingFragment" | "JSXElement" | "JSXEmptyExpression" | "JSXExpressionContainer" | "JSXFragment" | "JSXIdentifier" | "JSXMemberExpression" | "JSXNamespacedName" | "JSXOpeningElement" | "JSXOpeningFragment" | "JSXSpreadAttribute" | "JSXSpreadChild" | "JSXText" | "MixedTypeAnnotation" | "ModuleExpression" | "Noop" | "NullLiteral" | "NullLiteralTypeAnnotation" | "NullableTypeAnnotation" | "NumberLiteral" | "NumberLiteralTypeAnnotation" | "NumberTypeAnnotation" | "NumericLiteral" | "ObjectMethod" | "ObjectPattern" | "ObjectProperty" | "ObjectTypeAnnotation" | "ObjectTypeCallProperty" | "ObjectTypeIndexer" | "ObjectTypeInternalSlot" | "ObjectTypeProperty" | "ObjectTypeSpreadProperty" | "OpaqueType" | "OptionalCallExpression" | "OptionalIndexedAccessType" | "OptionalMemberExpression" | "ParenthesizedExpression" | "PipelineBareFunction" | "PipelinePrimaryTopicReference" | "PipelineTopicExpression" | "Placeholder" | "PrivateName" | "QualifiedTypeIdentifier" | "RecordExpression" | "RegExpLiteral" | "RegexLiteral" | "RestElement" | "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 };
@@ -79,10 +79,10 @@ async function getRegistry() {
79
79
  }
80
80
  async function add(names, { flags }) {
81
81
  ensureProcessNodeEnv("production");
82
+ applyPolyfill();
82
83
  const inlineConfig = flagsToAstroInlineConfig(flags);
83
84
  const { userConfig } = await resolveConfig(inlineConfig, "add");
84
85
  telemetry.record(eventCliSession("add", userConfig));
85
- applyPolyfill();
86
86
  if (flags.help || names.length === 0) {
87
87
  printHelp({
88
88
  commandName: "astro add",
@@ -1,7 +1,9 @@
1
1
  import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
2
2
  import { getPackage } from "../install-package.js";
3
3
  import { resolveConfig } from "../../core/config/config.js";
4
+ import { apply as applyPolyfill } from "../../core/polyfill.js";
4
5
  async function db({ flags }) {
6
+ applyPolyfill();
5
7
  const logger = createLoggerFromFlags(flags);
6
8
  const getPackageOpts = { skipAsk: flags.yes || flags.y, cwd: flags.root };
7
9
  const dbPackage = await getPackage("@astrojs/db", logger, getPackageOpts, []);
@@ -5,6 +5,7 @@ import prompts from "prompts";
5
5
  import { resolveConfig } from "../../core/config/index.js";
6
6
  import { ASTRO_VERSION } from "../../core/constants.js";
7
7
  import { flagsToAstroInlineConfig } from "../flags.js";
8
+ import { apply as applyPolyfill } from "../../core/polyfill.js";
8
9
  async function getInfoOutput({
9
10
  userConfig,
10
11
  print
@@ -29,6 +30,7 @@ async function getInfoOutput({
29
30
  return output.trim();
30
31
  }
31
32
  async function printInfo({ flags }) {
33
+ applyPolyfill();
32
34
  const { userConfig } = await resolveConfig(flagsToAstroInlineConfig(flags), "info");
33
35
  const output = await getInfoOutput({ userConfig, print: true });
34
36
  await copyToClipboard(output);
@@ -10,6 +10,7 @@ import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
10
10
  import { flattie } from "flattie";
11
11
  import { formatWithOptions } from "node:util";
12
12
  import { collectErrorMetadata } from "../../core/errors/dev/utils.js";
13
+ import { apply as applyPolyfill } from "../../core/polyfill.js";
13
14
  const PREFERENCES_SUBCOMMANDS = [
14
15
  "get",
15
16
  "set",
@@ -23,6 +24,7 @@ function isValidSubcommand(subcommand) {
23
24
  return PREFERENCES_SUBCOMMANDS.includes(subcommand);
24
25
  }
25
26
  async function preferences(subcommand, key, value, { flags }) {
27
+ applyPolyfill();
26
28
  if (!isValidSubcommand(subcommand) || flags?.help || flags?.h) {
27
29
  msg.printHelp({
28
30
  commandName: "astro preferences",
@@ -121,7 +121,7 @@ async function createContentTypesGenerator({
121
121
  }
122
122
  const collectionInfo2 = collectionEntryMap[collectionKey2];
123
123
  if (collectionInfo2.type === "content") {
124
- viteServer.ws.send({
124
+ viteServer.hot.send({
125
125
  type: "error",
126
126
  err: new AstroError({
127
127
  ...AstroErrorData.MixedContentDataCollectionError,
@@ -157,7 +157,7 @@ async function createContentTypesGenerator({
157
157
  }
158
158
  const collectionInfo = collectionEntryMap[collectionKey];
159
159
  if (collectionInfo.type === "data") {
160
- viteServer.ws.send({
160
+ viteServer.hot.send({
161
161
  type: "error",
162
162
  err: new AstroError({
163
163
  ...AstroErrorData.MixedContentDataCollectionError,
@@ -280,7 +280,7 @@ async function writeContentFiles({
280
280
  const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
281
281
  const collection = collectionEntryMap[collectionKey];
282
282
  if (collectionConfig?.type && collection.type !== "unknown" && collection.type !== collectionConfig.type) {
283
- viteServer.ws.send({
283
+ viteServer.hot.send({
284
284
  type: "error",
285
285
  err: new AstroError({
286
286
  ...AstroErrorData.ContentCollectionTypeMismatchError,
@@ -292,7 +292,7 @@ async function writeContentFiles({
292
292
  hint: collection.type === "data" ? "Try adding `type: 'data'` to your collection config." : void 0,
293
293
  location: {
294
294
  file: ""
295
- /** required for error overlay `ws` messages */
295
+ /** required for error overlay `hot` messages */
296
296
  }
297
297
  })
298
298
  });
@@ -1,9 +1,6 @@
1
- import { createI18nMiddleware, i18nPipelineHook } from "../../i18n/middleware.js";
2
- import { REROUTE_DIRECTIVE_HEADER } from "../../runtime/server/consts.js";
3
1
  import { getSetCookiesFromResponse } from "../cookies/index.js";
4
2
  import { consoleLogDestination } from "../logger/console.js";
5
3
  import { AstroIntegrationLogger, Logger } from "../logger/core.js";
6
- import { sequence } from "../middleware/index.js";
7
4
  import {
8
5
  appendForwardSlash,
9
6
  collapseDuplicateSlashes,
@@ -12,28 +9,23 @@ import {
12
9
  removeTrailingForwardSlash
13
10
  } from "../path.js";
14
11
  import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
15
- import { createEnvironment, createRenderContext } from "../render/index.js";
16
- import { RouteCache } from "../render/route-cache.js";
17
- import {
18
- createAssetLink,
19
- createModuleScriptElement,
20
- createStylesheetElementSet
21
- } from "../render/ssr-element.js";
12
+ import { createAssetLink } from "../render/ssr-element.js";
22
13
  import { matchRoute } from "../routing/match.js";
23
- import { SSRRoutePipeline } from "./ssrPipeline.js";
14
+ import { AppPipeline } from "./pipeline.js";
24
15
  import { normalizeTheLocale } from "../../i18n/index.js";
16
+ import { RenderContext } from "../render-context.js";
17
+ import {
18
+ clientAddressSymbol,
19
+ clientLocalsSymbol,
20
+ responseSentSymbol,
21
+ REROUTABLE_STATUS_CODES,
22
+ REROUTE_DIRECTIVE_HEADER
23
+ } from "../constants.js";
24
+ import { AstroError, AstroErrorData } from "../errors/index.js";
25
25
  import { deserializeManifest } from "./common.js";
26
- const localsSymbol = Symbol.for("astro.locals");
27
- const clientAddressSymbol = Symbol.for("astro.clientAddress");
28
- const responseSentSymbol = Symbol.for("astro.responseSent");
29
- const REROUTABLE_STATUS_CODES = /* @__PURE__ */ new Set([404, 500]);
30
26
  class App {
31
- /**
32
- * The current environment of the application
33
- */
34
27
  #manifest;
35
28
  #manifestData;
36
- #routeDataToRouteInfo;
37
29
  #logger = new Logger({
38
30
  dest: consoleLogDestination,
39
31
  level: "info"
@@ -47,9 +39,8 @@ class App {
47
39
  this.#manifestData = {
48
40
  routes: manifest.routes.map((route) => route.routeData)
49
41
  };
50
- this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route]));
51
42
  this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
52
- this.#pipeline = new SSRRoutePipeline(this.#createEnvironment(streaming));
43
+ this.#pipeline = this.#createPipeline(streaming);
53
44
  this.#adapterLogger = new AstroIntegrationLogger(
54
45
  this.#logger.options,
55
46
  this.#manifest.adapterName
@@ -59,19 +50,17 @@ class App {
59
50
  return this.#adapterLogger;
60
51
  }
61
52
  /**
62
- * Creates an environment by reading the stored manifest
53
+ * Creates a pipeline by reading the stored manifest
63
54
  *
64
55
  * @param streaming
65
56
  * @private
66
57
  */
67
- #createEnvironment(streaming = false) {
68
- return createEnvironment({
69
- adapterName: this.#manifest.adapterName,
58
+ #createPipeline(streaming = false) {
59
+ return AppPipeline.create({
70
60
  logger: this.#logger,
61
+ manifest: this.#manifest,
71
62
  mode: "production",
72
- compressHTML: this.#manifest.compressHTML,
73
63
  renderers: this.#manifest.renderers,
74
- clientDirectives: this.#manifest.clientDirectives,
75
64
  resolve: async (specifier) => {
76
65
  if (!(specifier in this.#manifest.entryModules)) {
77
66
  throw new Error(`Unable to resolve [${specifier}]`);
@@ -87,9 +76,7 @@ class App {
87
76
  }
88
77
  }
89
78
  },
90
- routeCache: new RouteCache(this.#logger),
91
- site: this.#manifest.site,
92
- ssr: true,
79
+ serverLike: true,
93
80
  streaming
94
81
  });
95
82
  }
@@ -193,7 +180,11 @@ class App {
193
180
  }
194
181
  }
195
182
  if (locals) {
196
- Reflect.set(request, localsSymbol, locals);
183
+ if (typeof locals !== "object") {
184
+ this.#logger.error(null, new AstroError(AstroErrorData.LocalsNotAnObject).stack);
185
+ return this.#renderError(request, { status: 500 });
186
+ }
187
+ Reflect.set(request, clientLocalsSymbol, locals);
197
188
  }
198
189
  if (clientAddress) {
199
190
  Reflect.set(request, clientAddressSymbol, clientAddress);
@@ -210,35 +201,22 @@ class App {
210
201
  const pathname = this.#getPathnameFromRequest(request);
211
202
  const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
212
203
  const mod = await this.#getModuleForRoute(routeData);
213
- const pageModule = await mod.page();
214
- const url = new URL(request.url);
215
- const renderContext = await this.#createRenderContext(
216
- url,
217
- request,
218
- routeData,
219
- mod,
220
- defaultStatus
221
- );
222
204
  let response;
223
205
  try {
224
- const i18nMiddleware = createI18nMiddleware(
225
- this.#manifest.i18n,
226
- this.#manifest.base,
227
- this.#manifest.trailingSlash,
228
- this.#manifest.buildFormat
229
- );
230
- if (i18nMiddleware) {
231
- this.#pipeline.setMiddlewareFunction(sequence(i18nMiddleware, this.#manifest.middleware));
232
- this.#pipeline.onBeforeRenderRoute(i18nPipelineHook);
233
- } else {
234
- this.#pipeline.setMiddlewareFunction(this.#manifest.middleware);
235
- }
236
- response = await this.#pipeline.renderRoute(renderContext, pageModule);
206
+ const renderContext = RenderContext.create({
207
+ pipeline: this.#pipeline,
208
+ locals,
209
+ pathname,
210
+ request,
211
+ routeData,
212
+ status: defaultStatus
213
+ });
214
+ response = await renderContext.render(await mod.page());
237
215
  } catch (err) {
238
216
  this.#logger.error(null, err.stack || err.message || String(err));
239
217
  return this.#renderError(request, { status: 500 });
240
218
  }
241
- if (REROUTABLE_STATUS_CODES.has(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
219
+ if (REROUTABLE_STATUS_CODES.includes(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
242
220
  return this.#renderError(request, {
243
221
  response,
244
222
  status: response.status
@@ -279,61 +257,6 @@ class App {
279
257
  * @returns An iterator that yields key-value pairs as equal-sign-separated strings.
280
258
  */
281
259
  static getSetCookieFromResponse = getSetCookiesFromResponse;
282
- /**
283
- * Creates the render context of the current route
284
- */
285
- async #createRenderContext(url, request, routeData, page, status = 200) {
286
- if (routeData.type === "endpoint") {
287
- const pathname = "/" + this.removeBase(url.pathname);
288
- const mod = await page.page();
289
- const handler = mod;
290
- return await createRenderContext({
291
- request,
292
- pathname,
293
- route: routeData,
294
- status,
295
- env: this.#pipeline.env,
296
- mod: handler,
297
- locales: this.#manifest.i18n?.locales,
298
- routing: this.#manifest.i18n?.routing,
299
- defaultLocale: this.#manifest.i18n?.defaultLocale
300
- });
301
- } else {
302
- const pathname = prependForwardSlash(this.removeBase(url.pathname));
303
- const info = this.#routeDataToRouteInfo.get(routeData);
304
- const links = /* @__PURE__ */ new Set();
305
- const styles = createStylesheetElementSet(info.styles);
306
- let scripts = /* @__PURE__ */ new Set();
307
- for (const script of info.scripts) {
308
- if ("stage" in script) {
309
- if (script.stage === "head-inline") {
310
- scripts.add({
311
- props: {},
312
- children: script.children
313
- });
314
- }
315
- } else {
316
- scripts.add(createModuleScriptElement(script));
317
- }
318
- }
319
- const mod = await page.page();
320
- return await createRenderContext({
321
- request,
322
- pathname,
323
- componentMetadata: this.#manifest.componentMetadata,
324
- scripts,
325
- styles,
326
- links,
327
- route: routeData,
328
- status,
329
- mod,
330
- env: this.#pipeline.env,
331
- locales: this.#manifest.i18n?.locales,
332
- routing: this.#manifest.i18n?.routing,
333
- defaultLocale: this.#manifest.i18n?.defaultLocale
334
- });
335
- }
336
- }
337
260
  /**
338
261
  * If it is a known error code, try sending the according page (e.g. 404.astro / 500.astro).
339
262
  * This also handles pre-rendered /404 or /500 routes
@@ -355,21 +278,15 @@ class App {
355
278
  }
356
279
  const mod = await this.#getModuleForRoute(errorRouteData);
357
280
  try {
358
- const newRenderContext = await this.#createRenderContext(
359
- url,
281
+ const renderContext = RenderContext.create({
282
+ pipeline: this.#pipeline,
283
+ middleware: skipMiddleware ? (_, next) => next() : void 0,
284
+ pathname: this.#getPathnameFromRequest(request),
360
285
  request,
361
- errorRouteData,
362
- mod,
286
+ routeData: errorRouteData,
363
287
  status
364
- );
365
- const page = await mod.page();
366
- if (skipMiddleware === false) {
367
- this.#pipeline.setMiddlewareFunction(this.#manifest.middleware);
368
- }
369
- if (skipMiddleware) {
370
- this.#pipeline.unsetMiddlewareFunction();
371
- }
372
- const response2 = await this.#pipeline.renderRoute(newRenderContext, page);
288
+ });
289
+ const response2 = await renderContext.render(await mod.page());
373
290
  return this.#mergeResponses(response2, originalResponse);
374
291
  } catch {
375
292
  if (skipMiddleware === false) {
@@ -0,0 +1,7 @@
1
+ import type { RouteData, SSRResult } from '../../@types/astro.js';
2
+ import { Pipeline } from '../base-pipeline.js';
3
+ export declare class AppPipeline extends Pipeline {
4
+ static create({ logger, manifest, mode, renderers, resolve, serverLike, streaming, }: Pick<AppPipeline, 'logger' | 'manifest' | 'mode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'>): AppPipeline;
5
+ headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
6
+ componentMetadata(): void;
7
+ }
@@ -0,0 +1,39 @@
1
+ import { Pipeline } from "../base-pipeline.js";
2
+ import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
3
+ class AppPipeline extends Pipeline {
4
+ static create({
5
+ logger,
6
+ manifest,
7
+ mode,
8
+ renderers,
9
+ resolve,
10
+ serverLike,
11
+ streaming
12
+ }) {
13
+ return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming);
14
+ }
15
+ headElements(routeData) {
16
+ const routeInfo = this.manifest.routes.find((route) => route.routeData === routeData);
17
+ const links = /* @__PURE__ */ new Set();
18
+ const scripts = /* @__PURE__ */ new Set();
19
+ const styles = createStylesheetElementSet(routeInfo?.styles ?? []);
20
+ for (const script of routeInfo?.scripts ?? []) {
21
+ if ("stage" in script) {
22
+ if (script.stage === "head-inline") {
23
+ scripts.add({
24
+ props: {},
25
+ children: script.children
26
+ });
27
+ }
28
+ } else {
29
+ scripts.add(createModuleScriptElement(script));
30
+ }
31
+ }
32
+ return { links, styles, scripts };
33
+ }
34
+ componentMetadata() {
35
+ }
36
+ }
37
+ export {
38
+ AppPipeline
39
+ };
@@ -0,0 +1,59 @@
1
+ import type { MiddlewareHandler, RouteData, RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js';
2
+ import type { Logger } from './logger/core.js';
3
+ import { RouteCache } from './render/route-cache.js';
4
+ /**
5
+ * The `Pipeline` represents the static parts of rendering that do not change between requests.
6
+ * These are mostly known when the server first starts up and do not change.
7
+ *
8
+ * Thus, a `Pipeline` is created once at process start and then used by every `RenderContext`.
9
+ */
10
+ export declare abstract class Pipeline {
11
+ readonly logger: Logger;
12
+ readonly manifest: SSRManifest;
13
+ /**
14
+ * "development" or "production"
15
+ */
16
+ readonly mode: RuntimeMode;
17
+ readonly renderers: SSRLoadedRenderer[];
18
+ readonly resolve: (s: string) => Promise<string>;
19
+ /**
20
+ * Based on Astro config's `output` option, `true` if "server" or "hybrid".
21
+ */
22
+ readonly serverLike: boolean;
23
+ readonly streaming: boolean;
24
+ /**
25
+ * Used to provide better error messages for `Astro.clientAddress`
26
+ */
27
+ readonly adapterName: string;
28
+ readonly clientDirectives: Map<string, string>;
29
+ readonly compressHTML: boolean;
30
+ readonly i18n: import("./app/types.js").SSRManifestI18n | undefined;
31
+ readonly middleware: MiddlewareHandler;
32
+ readonly routeCache: RouteCache;
33
+ /**
34
+ * Used for `Astro.site`.
35
+ */
36
+ readonly site: string | undefined;
37
+ readonly internalMiddleware: MiddlewareHandler[];
38
+ constructor(logger: Logger, manifest: SSRManifest,
39
+ /**
40
+ * "development" or "production"
41
+ */
42
+ mode: RuntimeMode, renderers: SSRLoadedRenderer[], resolve: (s: string) => Promise<string>,
43
+ /**
44
+ * Based on Astro config's `output` option, `true` if "server" or "hybrid".
45
+ */
46
+ serverLike: boolean, streaming: boolean,
47
+ /**
48
+ * Used to provide better error messages for `Astro.clientAddress`
49
+ */
50
+ adapterName?: string, clientDirectives?: Map<string, string>, compressHTML?: boolean, i18n?: import("./app/types.js").SSRManifestI18n | undefined, middleware?: MiddlewareHandler, routeCache?: RouteCache,
51
+ /**
52
+ * Used for `Astro.site`.
53
+ */
54
+ site?: string | undefined);
55
+ abstract headElements(routeData: RouteData): Promise<HeadElements> | HeadElements;
56
+ abstract componentMetadata(routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
57
+ }
58
+ export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {
59
+ }
@@ -0,0 +1,27 @@
1
+ import { RouteCache } from "./render/route-cache.js";
2
+ import { createI18nMiddleware } from "../i18n/middleware.js";
3
+ class Pipeline {
4
+ constructor(logger, manifest, mode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, mode), site = manifest.site) {
5
+ this.logger = logger;
6
+ this.manifest = manifest;
7
+ this.mode = mode;
8
+ this.renderers = renderers;
9
+ this.resolve = resolve;
10
+ this.serverLike = serverLike;
11
+ this.streaming = streaming;
12
+ this.adapterName = adapterName;
13
+ this.clientDirectives = clientDirectives;
14
+ this.compressHTML = compressHTML;
15
+ this.i18n = i18n;
16
+ this.middleware = middleware;
17
+ this.routeCache = routeCache;
18
+ this.site = site;
19
+ this.internalMiddleware = [
20
+ createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat)
21
+ ];
22
+ }
23
+ internalMiddleware;
24
+ }
25
+ export {
26
+ Pipeline
27
+ };
@@ -4,4 +4,4 @@ import { type BuildInternals } from '../../core/build/internal.js';
4
4
  import type { StaticBuildOptions } from './types.js';
5
5
  export declare function rootRelativeFacadeId(facadeId: string, settings: AstroSettings): string;
6
6
  export declare function chunkIsPage(settings: AstroSettings, output: OutputAsset | OutputChunk, internals: BuildInternals): boolean;
7
- export declare function generatePages(opts: StaticBuildOptions, internals: BuildInternals): Promise<void>;
7
+ export declare function generatePages(options: StaticBuildOptions, internals: BuildInternals): Promise<void>;