astro 4.9.2 → 4.10.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 (76) hide show
  1. package/client.d.ts +8 -0
  2. package/components/Picture.astro +2 -1
  3. package/config.d.ts +6 -0
  4. package/config.mjs +1 -0
  5. package/dist/@types/astro.d.ts +124 -0
  6. package/dist/assets/utils/proxy.js +1 -1
  7. package/dist/cli/add/babel.d.ts +1 -1
  8. package/dist/cli/install-package.d.ts +1 -1
  9. package/dist/cli/install-package.js +1 -1
  10. package/dist/config/index.js +2 -2
  11. package/dist/container/index.d.ts +11 -15
  12. package/dist/container/index.js +29 -27
  13. package/dist/container/pipeline.d.ts +1 -0
  14. package/dist/container/pipeline.js +8 -1
  15. package/dist/content/types-generator.js +5 -5
  16. package/dist/content/utils.d.ts +2 -3
  17. package/dist/content/utils.js +3 -4
  18. package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
  19. package/dist/core/app/pipeline.d.ts +2 -1
  20. package/dist/core/app/pipeline.js +44 -19
  21. package/dist/core/app/types.d.ts +1 -0
  22. package/dist/core/base-pipeline.d.ts +15 -3
  23. package/dist/core/base-pipeline.js +10 -1
  24. package/dist/core/build/generate.js +14 -4
  25. package/dist/core/build/pipeline.d.ts +2 -1
  26. package/dist/core/build/pipeline.js +31 -19
  27. package/dist/core/build/plugins/plugin-content.js +2 -1
  28. package/dist/core/build/plugins/plugin-manifest.js +2 -1
  29. package/dist/core/config/config.js +1 -1
  30. package/dist/core/config/schema.d.ts +644 -0
  31. package/dist/core/config/schema.js +5 -1
  32. package/dist/core/config/settings.js +1 -0
  33. package/dist/core/constants.d.ts +1 -1
  34. package/dist/core/constants.js +2 -2
  35. package/dist/core/create-vite.js +2 -0
  36. package/dist/core/dev/dev.js +1 -1
  37. package/dist/core/errors/errors-data.d.ts +61 -1
  38. package/dist/core/errors/errors-data.js +39 -0
  39. package/dist/core/logger/core.d.ts +1 -1
  40. package/dist/core/messages.js +2 -2
  41. package/dist/core/render-context.d.ts +1 -0
  42. package/dist/core/render-context.js +74 -57
  43. package/dist/core/routing/astro-designed-error-pages.d.ts +8 -1
  44. package/dist/core/routing/astro-designed-error-pages.js +29 -12
  45. package/dist/env/config.d.ts +9 -0
  46. package/dist/env/config.js +17 -0
  47. package/dist/env/constants.d.ts +11 -0
  48. package/dist/env/constants.js +21 -0
  49. package/dist/env/runtime.d.ts +6 -0
  50. package/dist/env/runtime.js +21 -0
  51. package/dist/env/schema.d.ts +387 -0
  52. package/dist/env/schema.js +113 -0
  53. package/dist/env/validators.d.ts +13 -0
  54. package/dist/env/validators.js +57 -0
  55. package/dist/env/vite-plugin-env.d.ts +11 -0
  56. package/dist/env/vite-plugin-env.js +174 -0
  57. package/dist/integrations/features-validation.js +9 -1
  58. package/dist/jsx/server.js +2 -1
  59. package/dist/runtime/server/render/astro/render.js +15 -1
  60. package/dist/runtime/server/util.js +1 -1
  61. package/dist/virtual-modules/container.d.ts +16 -0
  62. package/dist/virtual-modules/container.js +18 -0
  63. package/dist/virtual-modules/env-setup.d.ts +1 -0
  64. package/dist/virtual-modules/env-setup.js +4 -0
  65. package/dist/vite-plugin-astro-server/pipeline.d.ts +3 -2
  66. package/dist/vite-plugin-astro-server/pipeline.js +34 -20
  67. package/dist/vite-plugin-astro-server/plugin.js +1 -0
  68. package/dist/vite-plugin-astro-server/response.d.ts +0 -6
  69. package/dist/vite-plugin-astro-server/response.js +0 -13
  70. package/dist/vite-plugin-astro-server/route.js +2 -1
  71. package/dist/vite-plugin-inject-env-ts/index.js +46 -38
  72. package/package.json +19 -20
  73. package/templates/env/module.mjs +18 -0
  74. package/templates/env/types.d.ts +20 -0
  75. /package/{content-module.template.mjs → templates/content/module.mjs} +0 -0
  76. /package/{content-types.template.d.ts → templates/content/types.d.ts} +0 -0
package/client.d.ts CHANGED
@@ -152,6 +152,10 @@ declare module 'astro:i18n' {
152
152
  export * from 'astro/virtual-modules/i18n.js';
153
153
  }
154
154
 
155
+ declare module 'astro:container' {
156
+ export * from 'astro/virtual-modules/container.js';
157
+ }
158
+
155
159
  declare module 'astro:middleware' {
156
160
  export * from 'astro/virtual-modules/middleware.js';
157
161
  }
@@ -160,6 +164,10 @@ declare module 'astro:components' {
160
164
  export * from 'astro/components';
161
165
  }
162
166
 
167
+ declare module 'astro:env/setup' {
168
+ export * from 'astro/virtual-modules/env-setup.js';
169
+ }
170
+
163
171
  type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
164
172
  interface ExportedMarkdownModuleEntities {
165
173
  frontmatter: MD['frontmatter'];
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  import { type LocalImageProps, type RemoteImageProps, getImage } from 'astro:assets';
3
+ import * as mime from 'mrmime';
3
4
  import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro';
4
5
  import { isESMImportedImage, resolveSrc } from '../dist/assets/utils/imageKind';
5
6
  import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
@@ -99,7 +100,7 @@ if (import.meta.env.DEV) {
99
100
  return (
100
101
  <source
101
102
  srcset={srcsetAttribute}
102
- type={'image/' + image.options.format}
103
+ type={mime.lookup(image.options.format ?? image.src) ?? `image/${image.options.format}`}
103
104
  {...sourceAdditionalAttributes}
104
105
  />
105
106
  );
package/config.d.ts CHANGED
@@ -4,6 +4,7 @@ type AstroUserConfig = import('./dist/@types/astro.js').AstroUserConfig;
4
4
  type AstroInlineConfig = import('./dist/@types/astro.js').AstroInlineConfig;
5
5
  type ImageServiceConfig = import('./dist/@types/astro.js').ImageServiceConfig;
6
6
  type SharpImageServiceConfig = import('./dist/assets/services/sharp.js').SharpImageServiceConfig;
7
+ type EnvField = typeof import('./dist/env/config.js').envField;
7
8
 
8
9
  /**
9
10
  * See the full Astro Configuration API Documentation
@@ -37,3 +38,8 @@ export function squooshImageService(): ImageServiceConfig;
37
38
  * See: https://docs.astro.build/en/guides/images/#configure-no-op-passthrough-service
38
39
  */
39
40
  export function passthroughImageService(): ImageServiceConfig;
41
+
42
+ /**
43
+ * Return a valid env field to use in this Astro config for `experimental.env.schema`.
44
+ */
45
+ export const envField: EnvField;
package/config.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  export { defineConfig, getViteConfig } from './dist/config/index.js';
2
+ export { envField } from './dist/env/config.js';
2
3
 
3
4
  export function sharpImageService(config = {}) {
4
5
  return {
@@ -15,6 +15,7 @@ import type { AstroTimer } from '../core/config/timer.js';
15
15
  import type { TSConfig } from '../core/config/tsconfig.js';
16
16
  import type { AstroCookies } from '../core/cookies/index.js';
17
17
  import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js';
18
+ import type { EnvSchema } from '../env/schema.js';
18
19
  import type { getToolbarServerCommunicationHelpers } from '../integrations/hooks.js';
19
20
  import type { AstroPreferences } from '../preferences/index.js';
20
21
  import type { ToolbarAppEventTarget, ToolbarServerHelpers } from '../runtime/client/dev-toolbar/helpers.js';
@@ -1916,6 +1917,113 @@ export interface AstroUserConfig {
1916
1917
  * For a complete overview, and to give feedback on this experimental API, see the [Rerouting RFC](https://github.com/withastro/roadmap/blob/feat/reroute/proposals/0047-rerouting.md).
1917
1918
  */
1918
1919
  rewriting?: boolean;
1920
+ /**
1921
+ * @docs
1922
+ * @name experimental.env
1923
+ * @type {object}
1924
+ * @default `undefined`
1925
+ * @version 4.10.0
1926
+ * @description
1927
+ *
1928
+ * Enables experimental `astro:env` features .
1929
+ *
1930
+ * The `astro:env` API lets you configure a type-safe schema for your environment variables, and indicate whether they should be available on the server or the client. Import and use your defined variables from the appropriate `/client` or `/server` module:
1931
+ *
1932
+ * ```astro
1933
+ * ---
1934
+ * import { PUBLIC_APP_ID } from "astro:env/client"
1935
+ * import { PUBLIC_API_URL, getSecret } from "astro:env/server"
1936
+ * const API_TOKEN = getSecret("API_TOKEN")
1937
+ *
1938
+ * const data = await fetch(`${PUBLIC_API_URL}/users`, {
1939
+ * method: "POST",
1940
+ * headers: {
1941
+ * "Content-Type": "application/json",
1942
+ * "Authorization": `Bearer ${API_TOKEN}`
1943
+ * },
1944
+ * body: JSON.stringify({ appId: PUBLIC_APP_ID })
1945
+ * })
1946
+ * ---
1947
+ * ```
1948
+ *
1949
+ * To define the data type and properties of your environment variables, declare a schema in your Astro config in `experimental.env.schema`. The `envField` helper allows you define your variable as a string, number, or boolean and pass properties in an object:
1950
+ *
1951
+ * ```js
1952
+ * // astro.config.mjs
1953
+ * import { defineConfig, envField } from "astro/config"
1954
+ *
1955
+ * export default defineConfig({
1956
+ * experimental: {
1957
+ * env: {
1958
+ * schema: {
1959
+ * PUBLIC_API_URL: envField.string({ context: "client", access: "public", optional: true }),
1960
+ * PUBLIC_PORT: envField.number({ context: "server", access: "public", default: 4321 }),
1961
+ * API_SECRET: envField.string({ context: "server", access: "secret" }),
1962
+ * }
1963
+ * }
1964
+ * }
1965
+ * })
1966
+ * ```
1967
+ *
1968
+ * There are currently three data types supported: strings, numbers and booleans.
1969
+ *
1970
+ * There are three kinds of environment variables, determined by the combination of `context` (client or server) and `access` (private or public) settings defined in your [`env.schema`](#experimentalenvschema):
1971
+ *
1972
+ * - **Public client variables**: These variables end up in both your final client and server bundles, and can be accessed from both client and server through the `astro:env/client` module:
1973
+ *
1974
+ * ```js
1975
+ * import { PUBLIC_API_URL } from "astro:env/client"
1976
+ * ```
1977
+ *
1978
+ * - **Public server variables**: These variables end up in your final server bundle and can be accessed on the server through the `astro:env/server` module:
1979
+ *
1980
+ * ```js
1981
+ * import { PUBLIC_PORT } from "astro:env/server"
1982
+ * ```
1983
+ *
1984
+ * - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `getSecret()` helper function available from the `astro:env/server` module:
1985
+ *
1986
+ * ```js
1987
+ * import { getSecret } from "astro:env/server"
1988
+ *
1989
+ * const API_SECRET = getSecret("API_SECRET") // typed
1990
+ * const SECRET_NOT_IN_SCHEMA = getSecret("SECRET_NOT_IN_SCHEMA") // string | undefined
1991
+ * ```
1992
+ *
1993
+ * **Note:** Secret client variables are not supported because there is no safe way to send this data to the client. Therefore, it is not possible to configure both `context: "client"` and `access: "secret"` in your schema.
1994
+ *
1995
+ * For a complete overview, and to give feedback on this experimental API, see the [Astro Env RFC](https://github.com/withastro/roadmap/blob/feat/astro-env-rfc/proposals/0046-astro-env.md).
1996
+ */
1997
+ env?: {
1998
+ /**
1999
+ * @docs
2000
+ * @name experimental.env.schema
2001
+ * @kind h4
2002
+ * @type {EnvSchema}
2003
+ * @default `undefined`
2004
+ * @version 4.10.0
2005
+ * @description
2006
+ *
2007
+ * An object that uses `envField` to define the data type (`string`, `number`, or `boolean`) and properties of your environment variables: `context` (client or server), `access` (public or secret), a `default` value to use, and whether or not this environment variable is `optional` (defaults to `false`).
2008
+ * ```js
2009
+ * // astro.config.mjs
2010
+ * import { defineConfig, envField } from "astro/config"
2011
+ *
2012
+ * export default defineConfig({
2013
+ * experimental: {
2014
+ * env: {
2015
+ * schema: {
2016
+ * PUBLIC_API_URL: envField.string({ context: "client", access: "public", optional: true }),
2017
+ * PUBLIC_PORT: envField.number({ context: "server", access: "public", default: 4321 }),
2018
+ * API_SECRET: envField.string({ context: "server", access: "secret" }),
2019
+ * }
2020
+ * }
2021
+ * }
2022
+ * })
2023
+ * ```
2024
+ */
2025
+ schema?: EnvSchema;
2026
+ };
1919
2027
  };
1920
2028
  }
1921
2029
  /**
@@ -2080,6 +2188,7 @@ export interface AstroSettings {
2080
2188
  tsConfigPath: string | undefined;
2081
2189
  watchFiles: string[];
2082
2190
  timer: AstroTimer;
2191
+ dotAstroDir: URL;
2083
2192
  /**
2084
2193
  * Latest version of Astro, will be undefined if:
2085
2194
  * - unable to check
@@ -2318,6 +2427,10 @@ export type AstroFeatureMap = {
2318
2427
  * List of features that orbit around the i18n routing
2319
2428
  */
2320
2429
  i18nDomains?: SupportsKind;
2430
+ /**
2431
+ * The adapter is able to support `getSecret` exported from `astro:env/server`
2432
+ */
2433
+ envGetSecret?: SupportsKind;
2321
2434
  };
2322
2435
  export interface AstroAssetsFeature {
2323
2436
  supportKind?: SupportsKind;
@@ -2951,3 +3064,14 @@ declare global {
2951
3064
  'astro:page-load': Event;
2952
3065
  }
2953
3066
  }
3067
+ export type ContainerImportRendererFn = (containerRenderer: ContainerRenderer) => Promise<SSRLoadedRenderer>;
3068
+ export type ContainerRenderer = {
3069
+ /**
3070
+ * The name of the renderer.
3071
+ */
3072
+ name: string;
3073
+ /**
3074
+ * The entrypoint that is used to render a component on the server
3075
+ */
3076
+ serverEntrypoint: string;
3077
+ };
@@ -9,7 +9,7 @@ function getProxyCode(options, isSSR) {
9
9
  if (name === 'fsPath') {
10
10
  return ${stringifiedFSPath};
11
11
  }
12
- ${!isSSR ? `if (target[name] !== undefined) globalThis.astroAsset.referencedImages.add(${stringifiedFSPath});` : ""}
12
+ ${!isSSR ? `if (target[name] !== undefined && globalThis.astroAsset) globalThis.astroAsset?.referencedImages.add(${stringifiedFSPath});` : ""}
13
13
  return target[name];
14
14
  }
15
15
  })
@@ -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" | "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;
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" | "RestProperty" | "SpreadProperty" | "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" | "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,7 +6,7 @@ type GetPackageOptions = {
6
6
  };
7
7
  export declare function getPackage<T>(packageName: string, logger: Logger, options: GetPackageOptions, otherDeps?: string[]): Promise<T | undefined>;
8
8
  /**
9
- * Get the command to execute and download a package (e.g. `npx`, `yarn dlx`, `pnpx`, etc.)
9
+ * Get the command to execute and download a package (e.g. `npx`, `yarn dlx`, `pnpm dlx`, etc.)
10
10
  * @param packageManager - Optional package manager to use. If not provided, Astro will attempt to detect the preferred package manager.
11
11
  * @returns The command to execute and download a package
12
12
  */
@@ -86,7 +86,7 @@ async function getExecCommand(packageManager) {
86
86
  case "yarn":
87
87
  return "yarn dlx";
88
88
  case "pnpm":
89
- return "pnpx";
89
+ return "pnpm dlx";
90
90
  case "bun":
91
91
  return "bunx";
92
92
  default:
@@ -26,7 +26,7 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
26
26
  dest: nodeLogDestination,
27
27
  level: "info"
28
28
  });
29
- const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
29
+ const { astroConfig: config, userConfig } = 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(
@@ -40,7 +40,7 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
40
40
  { settings, logger, mode }
41
41
  );
42
42
  await runHookConfigDone({ settings, logger });
43
- return mergeConfig(viteConfig, inlineConfig);
43
+ return mergeConfig(viteConfig, userConfig);
44
44
  };
45
45
  }
46
46
  export {
@@ -1,4 +1,4 @@
1
- import type { AstroRenderer, AstroUserConfig, Props, RouteType } from '../@types/astro.js';
1
+ import type { AstroUserConfig, Props, RouteType, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js';
2
2
  import type { AstroComponentFactory } from '../runtime/server/index.js';
3
3
  /**
4
4
  * Options to be passed when rendering a route
@@ -84,21 +84,9 @@ export type AstroContainerOptions = {
84
84
  * @default []
85
85
  * @description
86
86
  *
87
- * List or renderers to use when rendering components. Usually they are entry points
88
- *
89
- * ## Example
90
- *
91
- * ```js
92
- * const container = await AstroContainer.create({
93
- * renderers: [{
94
- * name: "@astrojs/react"
95
- * client: "@astrojs/react/client.js"
96
- * server: "@astrojs/react/server.js"
97
- * }]
98
- * });
99
- * ```
87
+ * List or renderers to use when rendering components. Usually, you want to pass these in an SSR context.
100
88
  */
101
- renderers?: AstroRenderer[];
89
+ renderers?: SSRLoadedRenderer[];
102
90
  /**
103
91
  * @default {}
104
92
  * @description
@@ -116,6 +104,14 @@ export type AstroContainerOptions = {
116
104
  * ```
117
105
  */
118
106
  astroConfig?: AstroContainerUserConfig;
107
+ resolve?: SSRResult['resolve'];
108
+ /**
109
+ * @default {}
110
+ * @description
111
+ *
112
+ * The raw manifest from the build output.
113
+ */
114
+ manifest?: SSRManifest;
119
115
  };
120
116
  export declare class experimental_AstroContainer {
121
117
  #private;
@@ -7,7 +7,7 @@ import { removeLeadingForwardSlash } from "../core/path.js";
7
7
  import { RenderContext } from "../core/render-context.js";
8
8
  import { getParts, getPattern, validateSegment } from "../core/routing/manifest/create.js";
9
9
  import { ContainerPipeline } from "./pipeline.js";
10
- function createManifest(renderers, manifest, middleware) {
10
+ function createManifest(manifest, renderers, middleware) {
11
11
  const defaultMiddleware = (_, next) => {
12
12
  return next();
13
13
  };
@@ -22,13 +22,14 @@ function createManifest(renderers, manifest, middleware) {
22
22
  routes: manifest?.routes ?? [],
23
23
  adapterName: "",
24
24
  clientDirectives: manifest?.clientDirectives ?? /* @__PURE__ */ new Map(),
25
- renderers: manifest?.renderers ?? renderers,
25
+ renderers: renderers ?? manifest?.renderers ?? [],
26
26
  base: manifest?.base ?? ASTRO_CONFIG_DEFAULTS.base,
27
27
  componentMetadata: manifest?.componentMetadata ?? /* @__PURE__ */ new Map(),
28
28
  inlinedScripts: manifest?.inlinedScripts ?? /* @__PURE__ */ new Map(),
29
29
  i18n: manifest?.i18n,
30
30
  checkOrigin: false,
31
- middleware: manifest?.middleware ?? middleware ?? defaultMiddleware
31
+ middleware: manifest?.middleware ?? middleware ?? defaultMiddleware,
32
+ experimentalEnvGetSecretEnabled: false
32
33
  };
33
34
  }
34
35
  class experimental_AstroContainer {
@@ -38,24 +39,30 @@ class experimental_AstroContainer {
38
39
  * @private
39
40
  */
40
41
  #withManifest = false;
42
+ /**
43
+ * Internal function responsible for importing a renderer
44
+ * @private
45
+ */
46
+ #getRenderer;
41
47
  constructor({
42
48
  streaming = false,
43
- renderers = [],
44
49
  manifest,
45
- resolve
50
+ renderers,
51
+ resolve,
52
+ astroConfig
46
53
  }) {
47
54
  this.#pipeline = ContainerPipeline.create({
48
55
  logger: new Logger({
49
56
  level: "info",
50
57
  dest: nodeLogDestination
51
58
  }),
52
- manifest: createManifest(renderers, manifest),
59
+ manifest: createManifest(manifest, renderers),
53
60
  streaming,
54
61
  serverLike: true,
55
- renderers,
62
+ renderers: renderers ?? manifest?.renderers ?? [],
56
63
  resolve: async (specifier) => {
57
64
  if (this.#withManifest) {
58
- return this.#containerResolve(specifier);
65
+ return this.#containerResolve(specifier, astroConfig);
59
66
  } else if (resolve) {
60
67
  return resolve(specifier);
61
68
  }
@@ -63,10 +70,10 @@ class experimental_AstroContainer {
63
70
  }
64
71
  });
65
72
  }
66
- async #containerResolve(specifier) {
73
+ async #containerResolve(specifier, astroConfig) {
67
74
  const found = this.#pipeline.manifest.entryModules[specifier];
68
75
  if (found) {
69
- return new URL(found, ASTRO_CONFIG_DEFAULTS.build.client).toString();
76
+ return new URL(found, astroConfig.build.client).toString();
70
77
  }
71
78
  return found;
72
79
  }
@@ -76,28 +83,23 @@ class experimental_AstroContainer {
76
83
  * @param {AstroContainerOptions=} containerOptions
77
84
  */
78
85
  static async create(containerOptions = {}) {
79
- const { streaming = false, renderers = [] } = containerOptions;
80
- const loadedRenderers = await Promise.all(
81
- renderers.map(async (renderer) => {
82
- const mod = await import(renderer.serverEntrypoint);
83
- if (typeof mod.default !== "undefined") {
84
- return {
85
- ...renderer,
86
- ssr: mod.default
87
- };
88
- }
89
- return void 0;
90
- })
91
- );
92
- const finalRenderers = loadedRenderers.filter((r) => Boolean(r));
93
- return new experimental_AstroContainer({ streaming, renderers: finalRenderers });
86
+ const { streaming = false, manifest, renderers = [], resolve } = containerOptions;
87
+ const astroConfig = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), "container");
88
+ return new experimental_AstroContainer({
89
+ streaming,
90
+ manifest,
91
+ renderers,
92
+ astroConfig,
93
+ resolve
94
+ });
94
95
  }
95
96
  // NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
96
97
  // @ematipico: I plan to use it for a possible integration that could help people
97
98
  static async createFromManifest(manifest) {
98
- const config = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), "container");
99
+ const astroConfig = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), "container");
99
100
  const container = new experimental_AstroContainer({
100
- manifest
101
+ manifest,
102
+ astroConfig
101
103
  });
102
104
  container.#withManifest = true;
103
105
  return container;
@@ -8,4 +8,5 @@ export declare class ContainerPipeline extends Pipeline {
8
8
  tryRewrite(rewritePayload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
9
9
  insertRoute(route: RouteData, componentInstance: ComponentInstance): void;
10
10
  getComponentByRoute(_routeData: RouteData): Promise<ComponentInstance>;
11
+ rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
11
12
  }
@@ -1,10 +1,11 @@
1
1
  import { Pipeline } from "../core/base-pipeline.js";
2
- import { RouteNotFound } from "../core/errors/errors-data.js";
2
+ import { InvalidRewrite404, RouteNotFound } from "../core/errors/errors-data.js";
3
3
  import { AstroError } from "../core/errors/index.js";
4
4
  import {
5
5
  createModuleScriptElement,
6
6
  createStylesheetElementSet
7
7
  } from "../core/render/ssr-element.js";
8
+ import { default404Page } from "../core/routing/astro-designed-error-pages.js";
8
9
  class ContainerPipeline extends Pipeline {
9
10
  /**
10
11
  * Internal cache to store components instances by `RouteData`.
@@ -90,6 +91,12 @@ class ContainerPipeline extends Pipeline {
90
91
  // @ts-expect-error It needs to be implemented.
91
92
  async getComponentByRoute(_routeData) {
92
93
  }
94
+ rewriteKnownRoute(pathname, _sourceRoute) {
95
+ if (pathname === "/404") {
96
+ return { default: default404Page };
97
+ }
98
+ throw new AstroError(InvalidRewrite404);
99
+ }
93
100
  }
94
101
  export {
95
102
  ContainerPipeline
@@ -284,7 +284,7 @@ async function writeContentFiles({
284
284
  }) {
285
285
  let contentTypesStr = "";
286
286
  let dataTypesStr = "";
287
- const collectionSchemasDir = new URL("./collections/", contentPaths.cacheDir);
287
+ const collectionSchemasDir = new URL("./collections/", settings.dotAstroDir);
288
288
  if (settings.config.experimental.contentCollectionJsonSchema && !fs.existsSync(collectionSchemasDir)) {
289
289
  fs.mkdirSync(collectionSchemasDir, { recursive: true });
290
290
  }
@@ -387,11 +387,11 @@ async function writeContentFiles({
387
387
  break;
388
388
  }
389
389
  }
390
- if (!fs.existsSync(contentPaths.cacheDir)) {
391
- fs.mkdirSync(contentPaths.cacheDir, { recursive: true });
390
+ if (!fs.existsSync(settings.dotAstroDir)) {
391
+ fs.mkdirSync(settings.dotAstroDir, { recursive: true });
392
392
  }
393
393
  const configPathRelativeToCacheDir = normalizeConfigPath(
394
- contentPaths.cacheDir.pathname,
394
+ settings.dotAstroDir.pathname,
395
395
  contentPaths.config.url.pathname
396
396
  );
397
397
  for (const contentEntryType of contentEntryTypes) {
@@ -406,7 +406,7 @@ async function writeContentFiles({
406
406
  contentConfig ? `typeof import(${configPathRelativeToCacheDir})` : "never"
407
407
  );
408
408
  await fs.promises.writeFile(
409
- new URL(CONTENT_TYPES_FILE, contentPaths.cacheDir),
409
+ new URL(CONTENT_TYPES_FILE, settings.dotAstroDir),
410
410
  typeTemplateContent
411
411
  );
412
412
  }
@@ -9,7 +9,7 @@ import { CONTENT_FLAGS } from './consts.js';
9
9
  /**
10
10
  * Amap from a collection + slug to the local file path.
11
11
  * This is used internally to resolve entry imports when using `getEntry()`.
12
- * @see `content-module.template.mjs`
12
+ * @see `templates/content/module.mjs`
13
13
  */
14
14
  export type ContentLookupMap = {
15
15
  [collectionName: string]: {
@@ -158,7 +158,6 @@ export declare function contentObservable(initialCtx: ContentCtx): ContentObserv
158
158
  export type ContentPaths = {
159
159
  contentDir: URL;
160
160
  assetsDir: URL;
161
- cacheDir: URL;
162
161
  typesTemplate: URL;
163
162
  virtualModTemplate: URL;
164
163
  config: {
@@ -166,7 +165,7 @@ export type ContentPaths = {
166
165
  url: URL;
167
166
  };
168
167
  };
169
- export declare function getContentPaths({ srcDir, root }: Pick<AstroConfig, 'root' | 'srcDir'>, fs?: typeof fsMod): ContentPaths;
168
+ export declare function getContentPaths({ srcDir }: Pick<AstroConfig, 'root' | 'srcDir'>, fs?: typeof fsMod): ContentPaths;
170
169
  /**
171
170
  * Check for slug in content entry frontmatter and validate the type,
172
171
  * falling back to the `generatedSlug` if none is found.
@@ -284,15 +284,14 @@ function contentObservable(initialCtx) {
284
284
  subscribe
285
285
  };
286
286
  }
287
- function getContentPaths({ srcDir, root }, fs = fsMod) {
287
+ function getContentPaths({ srcDir }, fs = fsMod) {
288
288
  const configStats = search(fs, srcDir);
289
289
  const pkgBase = new URL("../../", import.meta.url);
290
290
  return {
291
- cacheDir: new URL(".astro/", root),
292
291
  contentDir: new URL("./content/", srcDir),
293
292
  assetsDir: new URL("./assets/", srcDir),
294
- typesTemplate: new URL("content-types.template.d.ts", pkgBase),
295
- virtualModTemplate: new URL("content-module.template.mjs", pkgBase),
293
+ typesTemplate: new URL("templates/content/types.d.ts", pkgBase),
294
+ virtualModTemplate: new URL("templates/content/module.mjs", pkgBase),
296
295
  config: configStats
297
296
  };
298
297
  }
@@ -19,7 +19,7 @@ export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV,
19
19
  /**
20
20
  * Generate a map from a collection + slug to the local file path.
21
21
  * This is used internally to resolve entry imports when using `getEntry()`.
22
- * @see `content-module.template.mjs`
22
+ * @see `templates/content/module.mjs`
23
23
  */
24
24
  export declare function generateLookupMap({ settings, fs, }: {
25
25
  settings: AstroSettings;
@@ -7,6 +7,7 @@ export declare class AppPipeline extends Pipeline {
7
7
  headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
8
8
  componentMetadata(): void;
9
9
  getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
10
- tryRewrite(payload: RewritePayload, request: Request): Promise<[RouteData, ComponentInstance]>;
10
+ tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
11
11
  getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule>;
12
+ rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
12
13
  }