diff --git a/.changeset/poor-frogs-dream.md b/.changeset/poor-frogs-dream.md new file mode 100644 index 000000000000..fdb3daa85284 --- /dev/null +++ b/.changeset/poor-frogs-dream.md @@ -0,0 +1,7 @@ +--- +'astro': major +--- + +Refactor the exported types from the `astro` module. There should normally be no breaking changes, but if you relied on some previously deprecated types, these might now have been fully removed. + +In most cases, updating your code to move away from previously deprecated APIs in previous versions of Astro should be enough to fix any issues. diff --git a/.github/labeler.yml b/.github/labeler.yml index c1025ad117d1..b0d27800ba97 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -40,5 +40,5 @@ - packages/integrations/vue/** 'docs pr': -- packages/astro/src/@types/astro.ts +- packages/astro/src/types/public/** - packages/astro/src/core/errors/errors-data.ts diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c1b4919901ab..2ce9ac1dbd53 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -11,7 +11,7 @@ on: - "examples/**" - ".github/workflows/check.yml" - "scripts/smoke/check.js" - - "packages/astro/src/@types/astro.ts" + - "packages/astro/src/types/public/**" - "pnpm-lock.yaml" - "packages/astro/types.d.ts" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79962c07e1ce..d516ab47a93f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -229,7 +229,7 @@ jobs: filters: | docs: - 'packages/integrations/*/README.md' - - 'packages/astro/src/@types/astro.ts' + - "packages/astro/src/types/public/**" - 'packages/astro/src/core/errors/errors-data.ts' - name: Build autogenerated docs pages from current astro branch diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index caaa9e726e10..6a657068d1df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -289,7 +289,7 @@ Server-side rendering (SSR) can be complicated. The Astro package (`packages/ast - `components/`: Built-in components to use in your project (e.g. `import Code from 'astro/components/Code.astro'`) - `src/`: Astro source - - `@types/`: TypeScript types. These are centralized to cut down on circular dependencies + - `types/`: TypeScript types. These are centralized to cut down on circular dependencies - `cli/`: Code that powers the `astro` CLI command - `core/`: Code that executes **in the top-level scope** (in Node). Within, you’ll find code that powers the `astro build` and `astro dev` commands, as well as top-level SSR code. - `runtime/`: Code that executes **in different scopes** (i.e. not in a pure Node context). You’ll have to think about code differently here. diff --git a/packages/astro/astro-jsx.d.ts b/packages/astro/astro-jsx.d.ts index b26507d1db58..128709dfc528 100644 --- a/packages/astro/astro-jsx.d.ts +++ b/packages/astro/astro-jsx.d.ts @@ -17,23 +17,21 @@ declare namespace astroHTML.JSX { children: {}; } - interface IntrinsicAttributes - extends AstroBuiltinProps, - AstroBuiltinAttributes, - AstroClientDirectives { + interface IntrinsicAttributes extends AstroComponentDirectives, AstroBuiltinAttributes { slot?: string | undefined | null; children?: Children; } - type AstroBuiltinProps = import('./dist/@types/astro.js').AstroBuiltinProps; - type AstroClientDirectives = import('./dist/@types/astro.js').AstroClientDirectives; - type AstroBuiltinAttributes = import('./dist/@types/astro.js').AstroBuiltinAttributes; - type AstroDefineVarsAttribute = import('./dist/@types/astro.js').AstroDefineVarsAttribute; - type AstroScriptAttributes = import('./dist/@types/astro.js').AstroScriptAttributes & + type AstroComponentDirectives = + import('./dist/types/public/elements.js').AstroComponentDirectives; + type AstroBuiltinAttributes = import('./dist/types/public/elements.js').AstroBuiltinAttributes; + type AstroDefineVarsAttribute = + import('./dist/types/public/elements.js').AstroDefineVarsAttribute; + type AstroScriptAttributes = import('./dist/types/public/elements.js').AstroScriptAttributes & AstroDefineVarsAttribute; - type AstroStyleAttributes = import('./dist/@types/astro.js').AstroStyleAttributes & + type AstroStyleAttributes = import('./dist/types/public/elements.js').AstroStyleAttributes & AstroDefineVarsAttribute; - type AstroSlotAttributes = import('./dist/@types/astro.js').AstroSlotAttributes; + type AstroSlotAttributes = import('./dist/types/public/elements.js').AstroSlotAttributes; // This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework // without importing every single framework's types (which comes with its own set of problems). diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index ed5c1b894d28..796bf3f33deb 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -2,12 +2,6 @@ /// /// -// eslint-disable-next-line @typescript-eslint/no-namespace -declare namespace App { - // eslint-disable-next-line @typescript-eslint/no-empty-interface - export interface Locals {} -} - interface ImportMetaEnv { /** * The prefix for Astro-generated asset links if the build.assetsPrefix config option is set. This can be used to create asset links not handled by Astro. @@ -52,7 +46,7 @@ declare module 'astro:assets' { getImage: ( options: import('./dist/assets/types.js').UnresolvedImageTransform, ) => Promise; - imageConfig: import('./dist/@types/astro.js').AstroConfig['image']; + imageConfig: import('./dist/types/public/config.js').AstroConfig['image']; getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService; inferRemoteSize: typeof import('./dist/assets/utils/index.js').inferRemoteSize; Image: typeof import('./components/Image.astro').default; @@ -172,7 +166,7 @@ declare module 'astro:components' { export * from 'astro/components'; } -type MD = import('./dist/@types/astro.js').MarkdownInstance>; +type MD = import('./dist/types/public/content.js').MarkdownInstance>; interface ExportedMarkdownModuleEntities { frontmatter: MD['frontmatter']; file: MD['file']; @@ -191,7 +185,6 @@ declare module '*.md' { file, url, getHeadings, - getHeaders, Content, rawContent, compiledContent, @@ -206,7 +199,6 @@ declare module '*.markdown' { file, url, getHeadings, - getHeaders, Content, rawContent, compiledContent, @@ -221,7 +213,6 @@ declare module '*.mkdn' { file, url, getHeadings, - getHeaders, Content, rawContent, compiledContent, @@ -236,7 +227,6 @@ declare module '*.mkd' { file, url, getHeadings, - getHeaders, Content, rawContent, compiledContent, @@ -251,7 +241,6 @@ declare module '*.mdwn' { file, url, getHeadings, - getHeaders, Content, rawContent, compiledContent, @@ -266,7 +255,6 @@ declare module '*.mdown' { file, url, getHeadings, - getHeaders, Content, rawContent, compiledContent, @@ -275,7 +263,7 @@ declare module '*.mdown' { } declare module '*.mdx' { - type MDX = import('./dist/@types/astro.js').MDXInstance>; + type MDX = import('./dist/types/public/content.js').MDXInstance>; export const frontmatter: MDX['frontmatter']; export const file: MDX['file']; @@ -288,7 +276,7 @@ declare module '*.mdx' { } declare module 'astro:ssr-manifest' { - export const manifest: import('./dist/@types/astro.js').SSRManifest; + export const manifest: import('./dist/types/public/internal.js').SSRManifest; } // Everything below are Vite's types (apart from image types, which are in `client.d.ts`) diff --git a/packages/astro/components/Picture.astro b/packages/astro/components/Picture.astro index c85548404d29..6686faf15bbe 100644 --- a/packages/astro/components/Picture.astro +++ b/packages/astro/components/Picture.astro @@ -1,7 +1,7 @@ --- import { type LocalImageProps, type RemoteImageProps, getImage } from 'astro:assets'; import * as mime from 'mrmime'; -import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro'; +import type { GetImageResult, ImageOutputFormat } from '../dist/types/public/index.js'; import { isESMImportedImage, resolveSrc } from '../dist/assets/utils/imageKind'; import { AstroError, AstroErrorData } from '../dist/core/errors/index.js'; import type { HTMLAttributes } from '../types'; diff --git a/packages/astro/config.d.ts b/packages/astro/config.d.ts index 9f4c6bfd112d..675c783a191d 100644 --- a/packages/astro/config.d.ts +++ b/packages/astro/config.d.ts @@ -1,8 +1,8 @@ type ViteUserConfig = import('vite').UserConfig; type ViteUserConfigFn = import('vite').UserConfigFn; -type AstroUserConfig = import('./dist/@types/astro.js').AstroUserConfig; -type AstroInlineConfig = import('./dist/@types/astro.js').AstroInlineConfig; -type ImageServiceConfig = import('./dist/@types/astro.js').ImageServiceConfig; +type AstroUserConfig = import('./dist/types/public/config.js').AstroUserConfig; +type AstroInlineConfig = import('./dist/types/public/config.js').AstroInlineConfig; +type ImageServiceConfig = import('./dist/types/public/config.js').ImageServiceConfig; type SharpImageServiceConfig = import('./dist/assets/services/sharp.js').SharpImageServiceConfig; type EnvField = typeof import('./dist/env/config.js').envField; @@ -42,4 +42,4 @@ export function passthroughImageService(): ImageServiceConfig; /** * Return a valid env field to use in this Astro config for `experimental.env.schema`. */ -export const envField: EnvField; +export declare const envField: EnvField; diff --git a/packages/astro/env.d.ts b/packages/astro/env.d.ts index 876a29c60f49..d2a788db3d3f 100644 --- a/packages/astro/env.d.ts +++ b/packages/astro/env.d.ts @@ -4,7 +4,7 @@ // As such, if the typings you're trying to add should be available inside ex: React components, they should instead // be inside `client.d.ts` -type Astro = import('./dist/@types/astro.js').AstroGlobal; +type Astro = import('./dist/types/public/context.js').AstroGlobal; // We have to duplicate the description here because editors won't show the JSDoc comment from the imported type // However, they will for its properties, ex: Astro.request will show the AstroGlobal.request description diff --git a/packages/astro/index.d.ts b/packages/astro/index.d.ts index a9e679be17d9..7b7a236e7970 100644 --- a/packages/astro/index.d.ts +++ b/packages/astro/index.d.ts @@ -1,2 +1,2 @@ -export type * from './dist/@types/astro.js'; +export type * from './dist/types/public/index.js'; export * from './dist/core/index.js'; diff --git a/packages/astro/src/@types/README.md b/packages/astro/src/@types/README.md deleted file mode 100644 index 397329eaf218..000000000000 --- a/packages/astro/src/@types/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# `@types/` - -TypeScript definitions and types for untyped modules. - -[See CONTRIBUTING.md](../../../../CONTRIBUTING.md) for a code overview. diff --git a/packages/astro/src/@types/app.d.ts b/packages/astro/src/@types/app.d.ts deleted file mode 100644 index 1c0908bb8072..000000000000 --- a/packages/astro/src/@types/app.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Shared interfaces throughout the application that can be overridden by the user. - */ -declare namespace App { - /** - * Used by middlewares to store information, that can be read by the user via the global `Astro.locals` - */ - interface Locals {} -} diff --git a/packages/astro/src/actions/index.ts b/packages/astro/src/actions/index.ts index 2423b7017d43..61f5a00cc3ab 100644 --- a/packages/astro/src/actions/index.ts +++ b/packages/astro/src/actions/index.ts @@ -1,9 +1,10 @@ import fsMod from 'node:fs'; import type { Plugin as VitePlugin } from 'vite'; -import type { AstroIntegration, AstroSettings } from '../@types/astro.js'; import { ActionsWithoutServerOutputError } from '../core/errors/errors-data.js'; import { AstroError } from '../core/errors/errors.js'; import { isServerLikeOutput, viteID } from '../core/util.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroIntegration } from '../types/public/integrations.js'; import { ACTIONS_TYPES_FILE, NOOP_ACTIONS, diff --git a/packages/astro/src/actions/runtime/middleware.ts b/packages/astro/src/actions/runtime/middleware.ts index f3f01800a837..b6f3221b5700 100644 --- a/packages/astro/src/actions/runtime/middleware.ts +++ b/packages/astro/src/actions/runtime/middleware.ts @@ -1,8 +1,9 @@ import { yellow } from 'kleur/colors'; -import type { APIContext, MiddlewareNext } from '../../@types/astro.js'; import { ActionQueryStringInvalidError } from '../../core/errors/errors-data.js'; import { AstroError } from '../../core/errors/errors.js'; import { defineMiddleware } from '../../core/middleware/index.js'; +import type { MiddlewareNext } from '../../types/public/common.js'; +import type { APIContext } from '../../types/public/context.js'; import { ACTION_QUERY_PARAMS } from '../consts.js'; import { formContentTypes, hasContentType } from './utils.js'; import { getAction } from './virtual/get-action.js'; diff --git a/packages/astro/src/actions/runtime/route.ts b/packages/astro/src/actions/runtime/route.ts index e4e2ad1ce5b1..7279a093d07e 100644 --- a/packages/astro/src/actions/runtime/route.ts +++ b/packages/astro/src/actions/runtime/route.ts @@ -1,4 +1,4 @@ -import type { APIRoute } from '../../@types/astro.js'; +import type { APIRoute } from '../../types/public/common.js'; import { formContentTypes, hasContentType } from './utils.js'; import { getAction } from './virtual/get-action.js'; import { serializeActionResult } from './virtual/shared.js'; diff --git a/packages/astro/src/actions/runtime/utils.ts b/packages/astro/src/actions/runtime/utils.ts index 776171aa2ac5..199809d4e87c 100644 --- a/packages/astro/src/actions/runtime/utils.ts +++ b/packages/astro/src/actions/runtime/utils.ts @@ -1,4 +1,4 @@ -import type { APIContext } from '../../@types/astro.js'; +import type { APIContext } from '../../types/public/context.js'; export const formContentTypes = ['application/x-www-form-urlencoded', 'multipart/form-data']; diff --git a/packages/astro/src/actions/utils.ts b/packages/astro/src/actions/utils.ts index 5cf78626600f..f1cab8e430f2 100644 --- a/packages/astro/src/actions/utils.ts +++ b/packages/astro/src/actions/utils.ts @@ -1,6 +1,6 @@ -import type { APIContext } from '../@types/astro.js'; +import type { APIContext } from '../types/public/context.js'; import type { Locals } from './runtime/middleware.js'; -import { type ActionAPIContext } from './runtime/utils.js'; +import type { ActionAPIContext } from './runtime/utils.js'; import { deserializeActionResult, getActionQueryString } from './runtime/virtual/shared.js'; export function hasActionPayload(locals: APIContext['locals']): locals is Locals { diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index fcc19f4f53a9..1c4866592828 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -2,7 +2,6 @@ import fs, { readFileSync } from 'node:fs'; import { basename } from 'node:path/posix'; import { dim, green } from 'kleur/colors'; import type PQueue from 'p-queue'; -import type { AstroConfig } from '../../@types/astro.js'; import { getOutDirWithinCwd } from '../../core/build/common.js'; import type { BuildPipeline } from '../../core/build/pipeline.js'; import { getTimeStat } from '../../core/build/util.js'; @@ -12,6 +11,7 @@ import type { Logger } from '../../core/logger/core.js'; import { isRemotePath, removeLeadingForwardSlash } from '../../core/path.js'; import { isServerLikeOutput } from '../../core/util.js'; import type { MapValue } from '../../type-utils.js'; +import type { AstroConfig } from '../../types/public/config.js'; import { getConfiguredImageService } from '../internal.js'; import type { LocalImageService } from '../services/service.js'; import type { AssetsGlobalStaticImagesList, ImageMetadata, ImageTransform } from '../types.js'; diff --git a/packages/astro/src/assets/endpoint/config.ts b/packages/astro/src/assets/endpoint/config.ts index 07cfe8faecbb..ff9dcc79a807 100644 --- a/packages/astro/src/assets/endpoint/config.ts +++ b/packages/astro/src/assets/endpoint/config.ts @@ -1,4 +1,4 @@ -import type { AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build') { const endpointEntrypoint = diff --git a/packages/astro/src/assets/endpoint/generic.ts b/packages/astro/src/assets/endpoint/generic.ts index 5238f3721a4d..d453787fd87e 100644 --- a/packages/astro/src/assets/endpoint/generic.ts +++ b/packages/astro/src/assets/endpoint/generic.ts @@ -2,7 +2,7 @@ import { imageConfig } from 'astro:assets'; import { isRemotePath } from '@astrojs/internal-helpers/path'; import * as mime from 'mrmime'; -import type { APIRoute } from '../../@types/astro.js'; +import type { APIRoute } from '../../types/public/common.js'; import { getConfiguredImageService } from '../internal.js'; import { etag } from '../utils/etag.js'; import { isRemoteAllowed } from '../utils/remotePattern.js'; diff --git a/packages/astro/src/assets/endpoint/node.ts b/packages/astro/src/assets/endpoint/node.ts index cb3ae7806e91..04275652cde2 100644 --- a/packages/astro/src/assets/endpoint/node.ts +++ b/packages/astro/src/assets/endpoint/node.ts @@ -7,7 +7,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; import { assetsDir, imageConfig, outDir } from 'astro:assets'; import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path'; import * as mime from 'mrmime'; -import type { APIRoute } from '../../@types/astro.js'; +import type { APIRoute } from '../../types/public/common.js'; import { getConfiguredImageService } from '../internal.js'; import { etag } from '../utils/etag.js'; import { isRemoteAllowed } from '../utils/remotePattern.js'; diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 38afbf19fc9b..9a5926e8d255 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -1,5 +1,5 @@ -import type { AstroConfig } from '../@types/astro.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; +import type { AstroConfig } from '../types/public/config.js'; import { DEFAULT_HASH_PROPS } from './consts.js'; import { type ImageService, isLocalService } from './services/service.js'; import { diff --git a/packages/astro/src/assets/services/service.ts b/packages/astro/src/assets/services/service.ts index 9cd6d0ecba42..f798e1dfd142 100644 --- a/packages/astro/src/assets/services/service.ts +++ b/packages/astro/src/assets/services/service.ts @@ -1,6 +1,6 @@ -import type { AstroConfig } from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; import { isRemotePath, joinPaths } from '../../core/path.js'; +import type { AstroConfig } from '../../types/public/config.js'; import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from '../consts.js'; import type { ImageOutputFormat, ImageTransform, UnresolvedSrcSetValue } from '../types.js'; import { isESMImportedImage } from '../utils/imageKind.js'; diff --git a/packages/astro/src/assets/utils/remotePattern.ts b/packages/astro/src/assets/utils/remotePattern.ts index 5feefb89fe73..d3e832573a7f 100644 --- a/packages/astro/src/assets/utils/remotePattern.ts +++ b/packages/astro/src/assets/utils/remotePattern.ts @@ -1,5 +1,5 @@ import { isRemotePath } from '@astrojs/internal-helpers/path'; -import type { AstroConfig } from '../../@types/astro.js'; +import type { AstroConfig } from '../../types/public/config.js'; export type RemotePattern = { hostname?: string; diff --git a/packages/astro/src/assets/vite-plugin-assets.ts b/packages/astro/src/assets/vite-plugin-assets.ts index 4c9314e85fad..57bbf847a4ff 100644 --- a/packages/astro/src/assets/vite-plugin-assets.ts +++ b/packages/astro/src/assets/vite-plugin-assets.ts @@ -2,7 +2,6 @@ import { extname } from 'node:path'; import MagicString from 'magic-string'; import type * as vite from 'vite'; import { normalizePath } from 'vite'; -import type { AstroPluginOptions, AstroSettings, ImageTransform } from '../@types/astro.js'; import { extendManualChunks } from '../core/build/plugins/util.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { @@ -13,7 +12,9 @@ import { removeQueryString, } from '../core/path.js'; import { isServerLikeOutput } from '../core/util.js'; +import type { AstroPluginOptions, AstroSettings } from '../types/astro.js'; import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from './consts.js'; +import type { ImageTransform } from './types.js'; import { getAssetsPrefix } from './utils/getAssetsPrefix.js'; import { isESMImportedImage } from './utils/imageKind.js'; import { emitESMImage } from './utils/node/emitAsset.js'; diff --git a/packages/astro/src/cli/db/index.ts b/packages/astro/src/cli/db/index.ts index ae97e498f8c0..7aaea302c173 100644 --- a/packages/astro/src/cli/db/index.ts +++ b/packages/astro/src/cli/db/index.ts @@ -1,5 +1,5 @@ import type { Arguments } from 'yargs-parser'; -import type { AstroConfig } from '../../@types/astro.js'; +import type { AstroConfig } from '../../types/public/config.js'; import { resolveConfig } from '../../core/config/config.js'; import { apply as applyPolyfill } from '../../core/polyfill.js'; import { createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js'; diff --git a/packages/astro/src/cli/flags.ts b/packages/astro/src/cli/flags.ts index 9d57c03166e3..e890b242cd08 100644 --- a/packages/astro/src/cli/flags.ts +++ b/packages/astro/src/cli/flags.ts @@ -1,7 +1,7 @@ import type { Arguments } from 'yargs-parser'; -import type { AstroInlineConfig } from '../@types/astro.js'; import { type LogOptions, Logger } from '../core/logger/core.js'; import { nodeLogDestination } from '../core/logger/node.js'; +import type { AstroInlineConfig } from '../types/public/config.js'; // Alias for now, but allows easier migration to node's `parseArgs` in the future. export type Flags = Arguments; diff --git a/packages/astro/src/cli/info/index.ts b/packages/astro/src/cli/info/index.ts index 3fa91802f26e..9f25a253516a 100644 --- a/packages/astro/src/cli/info/index.ts +++ b/packages/astro/src/cli/info/index.ts @@ -3,10 +3,10 @@ import { arch, platform } from 'node:os'; /* eslint-disable no-console */ import * as colors from 'kleur/colors'; import prompts from 'prompts'; -import type { AstroConfig, AstroUserConfig } from '../../@types/astro.js'; import { resolveConfig } from '../../core/config/index.js'; import { ASTRO_VERSION } from '../../core/constants.js'; import { apply as applyPolyfill } from '../../core/polyfill.js'; +import type { AstroConfig, AstroUserConfig } from '../../types/public/config.js'; import { type Flags, flagsToAstroInlineConfig } from '../flags.js'; interface InfoOptions { diff --git a/packages/astro/src/cli/preferences/index.ts b/packages/astro/src/cli/preferences/index.ts index 3811e7f48708..bd60343c22c5 100644 --- a/packages/astro/src/cli/preferences/index.ts +++ b/packages/astro/src/cli/preferences/index.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import type { AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; import { fileURLToPath } from 'node:url'; import { bgGreen, black, bold, dim, yellow } from 'kleur/colors'; diff --git a/packages/astro/src/config/index.ts b/packages/astro/src/config/index.ts index 3c5faf2fa087..b31105ec7adc 100644 --- a/packages/astro/src/config/index.ts +++ b/packages/astro/src/config/index.ts @@ -1,6 +1,6 @@ import type { UserConfig as ViteUserConfig } from 'vite'; -import type { AstroInlineConfig, AstroUserConfig } from '../@types/astro.js'; import { Logger } from '../core/logger/core.js'; +import type { AstroInlineConfig, AstroUserConfig } from '../types/public/config.js'; export function defineConfig(config: AstroUserConfig) { return config; diff --git a/packages/astro/src/config/vite-plugin-content-listen.ts b/packages/astro/src/config/vite-plugin-content-listen.ts index 1b65c5bfbbb3..6c0408001954 100644 --- a/packages/astro/src/config/vite-plugin-content-listen.ts +++ b/packages/astro/src/config/vite-plugin-content-listen.ts @@ -1,8 +1,8 @@ import type fsMod from 'node:fs'; import type { Plugin, ViteDevServer } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; import { attachContentServerListeners } from '../content/server-listeners.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroSettings } from '../types/astro.js'; /** * Listen for Astro content directory changes and generate types. diff --git a/packages/astro/src/container/index.ts b/packages/astro/src/container/index.ts index f0c600a40623..8a8c83e07877 100644 --- a/packages/astro/src/container/index.ts +++ b/packages/astro/src/container/index.ts @@ -1,19 +1,4 @@ import { posix } from 'node:path'; -import type { - AstroConfig, - AstroUserConfig, - ComponentInstance, - ContainerImportRendererFn, - MiddlewareHandler, - NamedSSRLoadedRendererValue, - Props, - RouteData, - RouteType, - SSRLoadedRenderer, - SSRLoadedRendererValue, - SSRManifest, - SSRResult, -} from '../@types/astro.js'; import { getDefaultClientDirectives } from '../core/client-directive/index.js'; import { ASTRO_CONFIG_DEFAULTS } from '../core/config/schema.js'; import { validateConfig } from '../core/config/validate.js'; @@ -25,8 +10,32 @@ import { RenderContext } from '../core/render-context.js'; import { getParts, validateSegment } from '../core/routing/manifest/create.js'; import { getPattern } from '../core/routing/manifest/pattern.js'; import type { AstroComponentFactory } from '../runtime/server/index.js'; +import type { ComponentInstance } from '../types/astro.js'; +import type { MiddlewareHandler, Props } from '../types/public/common.js'; +import type { AstroConfig, AstroUserConfig } from '../types/public/config.js'; +import type { + NamedSSRLoadedRendererValue, + RouteData, + RouteType, + SSRLoadedRenderer, + SSRLoadedRendererValue, + SSRManifest, + SSRResult, +} from '../types/public/internal.js'; import { ContainerPipeline } from './pipeline.js'; +/** Public type, used for integrations to define a renderer for the container API */ +export type ContainerRenderer = { + /** + * The name of the renderer. + */ + name: string; + /** + * The entrypoint that is used to render a component on the server + */ + serverEntrypoint: string; +}; + /** * Options to be passed when rendering a route */ @@ -103,6 +112,10 @@ export type AddClientRenderer = { entrypoint: string; }; +type ContainerImportRendererFn = ( + containerRenderer: ContainerRenderer, +) => Promise; + function createManifest( manifest?: AstroContainerManifest, renderers?: SSRLoadedRenderer[], diff --git a/packages/astro/src/container/pipeline.ts b/packages/astro/src/container/pipeline.ts index ff2718b8fbc6..73caa4ecd9a4 100644 --- a/packages/astro/src/container/pipeline.ts +++ b/packages/astro/src/container/pipeline.ts @@ -1,10 +1,3 @@ -import type { - ComponentInstance, - RewritePayload, - RouteData, - SSRElement, - SSRResult, -} from '../@types/astro.js'; import { type HeadElements, Pipeline } from '../core/base-pipeline.js'; import type { SinglePageBuiltModule } from '../core/build/types.js'; import { @@ -12,6 +5,9 @@ import { createStylesheetElementSet, } from '../core/render/ssr-element.js'; import { findRouteToRewrite } from '../core/routing/rewrite.js'; +import type { ComponentInstance } from '../types/astro.js'; +import type { RewritePayload } from '../types/public/common.js'; +import type { RouteData, SSRElement, SSRResult } from '../types/public/internal.js'; export class ContainerPipeline extends Pipeline { /** diff --git a/packages/astro/src/content/content-layer.ts b/packages/astro/src/content/content-layer.ts index 4861f3f61aa1..c0ccf27c646e 100644 --- a/packages/astro/src/content/content-layer.ts +++ b/packages/astro/src/content/content-layer.ts @@ -3,9 +3,9 @@ import { isAbsolute } from 'node:path'; import { fileURLToPath } from 'node:url'; import type { FSWatcher } from 'vite'; import xxhash from 'xxhash-wasm'; -import type { AstroSettings } from '../@types/astro.js'; import { AstroUserError } from '../core/errors/errors.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroSettings } from '../types/astro.js'; import { ASSET_IMPORTS_FILE, CONTENT_LAYER_TYPE, diff --git a/packages/astro/src/content/loaders/glob.ts b/packages/astro/src/content/loaders/glob.ts index 4a4ecbcac8d3..27af34196ad0 100644 --- a/packages/astro/src/content/loaders/glob.ts +++ b/packages/astro/src/content/loaders/glob.ts @@ -4,7 +4,7 @@ import fastGlob from 'fast-glob'; import { bold, green } from 'kleur/colors'; import micromatch from 'micromatch'; import pLimit from 'p-limit'; -import type { ContentEntryRenderFuction, ContentEntryType } from '../../@types/astro.js'; +import type { ContentEntryRenderFunction, ContentEntryType } from '../../types/public/content.js'; import type { RenderedContent } from '../data-store.js'; import { getContentEntryIdAndSlug, getEntryConfigByExtMap, posixRelative } from '../utils.js'; import type { Loader } from './types.js'; @@ -69,7 +69,7 @@ export function glob(globOptions: GlobOptions): Loader { load: async ({ settings, logger, watcher, parseData, store, generateDigest }) => { const renderFunctionByContentType = new WeakMap< ContentEntryType, - ContentEntryRenderFuction + ContentEntryRenderFunction >(); const untouchedEntries = new Set(store.keys()); @@ -131,7 +131,7 @@ export function glob(globOptions: GlobOptions): Loader { if (entryType.getRenderFunction) { let render = renderFunctionByContentType.get(entryType); if (!render) { - render = await entryType.getRenderFunction(settings); + render = await entryType.getRenderFunction(settings.config); // Cache the render function for this content type, so it can re-use parsers and other expensive setup renderFunctionByContentType.set(entryType, render); } diff --git a/packages/astro/src/content/loaders/types.ts b/packages/astro/src/content/loaders/types.ts index 26be0495a281..5edfb5ef71fe 100644 --- a/packages/astro/src/content/loaders/types.ts +++ b/packages/astro/src/content/loaders/types.ts @@ -1,6 +1,7 @@ import type { FSWatcher } from 'vite'; import type { ZodSchema } from 'zod'; -import type { AstroIntegrationLogger, AstroSettings } from '../../@types/astro.js'; +import type { AstroIntegrationLogger } from '../../core/logger/core.js'; +import type { AstroSettings } from '../../types/astro.js'; import type { MetaStore, ScopedDataStore } from '../mutable-data-store.js'; export interface ParseDataOptions> { diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts index b462e2e23a46..489625532950 100644 --- a/packages/astro/src/content/runtime.ts +++ b/packages/astro/src/content/runtime.ts @@ -2,7 +2,7 @@ import type { MarkdownHeading } from '@astrojs/markdown-remark'; import { Traverse } from 'neotraverse/modern'; import pLimit from 'p-limit'; import { ZodIssueCode, z } from 'zod'; -import type { GetImageResult, ImageMetadata } from '../@types/astro.js'; +import type { GetImageResult, ImageMetadata } from '../assets/types.js'; import { imageSrcToImportId } from '../assets/utils/resolveImports.js'; import { AstroError, AstroErrorData, AstroUserError } from '../core/errors/index.js'; import { prependForwardSlash } from '../core/path.js'; diff --git a/packages/astro/src/content/server-listeners.ts b/packages/astro/src/content/server-listeners.ts index 5d7868d58935..28f5b16a83e0 100644 --- a/packages/astro/src/content/server-listeners.ts +++ b/packages/astro/src/content/server-listeners.ts @@ -3,10 +3,10 @@ import path from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { bold, cyan, underline } from 'kleur/colors'; import type { ViteDevServer } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; import { loadTSConfig } from '../core/config/tsconfig.js'; import type { Logger } from '../core/logger/core.js'; import { appendForwardSlash } from '../core/path.js'; +import type { AstroSettings } from '../types/astro.js'; import { createContentTypesGenerator } from './types-generator.js'; import { type ContentPaths, getContentPaths, globalContentConfigObserver } from './utils.js'; diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index faf02d95d915..9923a0c343d7 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -7,11 +7,12 @@ import { type ViteDevServer, normalizePath } from 'vite'; import { type ZodSchema, z } from 'zod'; import { zodToJsonSchema } from 'zod-to-json-schema'; import { printNode, zodToTs } from 'zod-to-ts'; -import type { AstroSettings, ContentEntryType } from '../@types/astro.js'; import { AstroError } from '../core/errors/errors.js'; import { AstroErrorData } from '../core/errors/index.js'; import type { Logger } from '../core/logger/core.js'; import { isRelativePath } from '../core/path.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { ContentEntryType } from '../types/public/content.js'; import { CONTENT_LAYER_TYPE, CONTENT_TYPES_FILE, VIRTUAL_MODULE_ID } from './consts.js'; import { type CollectionConfig, diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts index 6d06272470d0..27b0e1915f4a 100644 --- a/packages/astro/src/content/utils.ts +++ b/packages/astro/src/content/utils.ts @@ -7,15 +7,12 @@ import type { PluginContext } from 'rollup'; import { type ViteDevServer, normalizePath } from 'vite'; import xxhash from 'xxhash-wasm'; import { z } from 'zod'; -import type { - AstroConfig, - AstroSettings, - ContentEntryType, - DataEntryType, -} from '../@types/astro.js'; import { AstroError, AstroErrorData, MarkdownError, errorMap } from '../core/errors/index.js'; import { isYAMLException } from '../core/errors/utils.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroConfig } from '../types/public/config.js'; +import type { ContentEntryType, DataEntryType } from '../types/public/content.js'; import { CONTENT_FLAGS, CONTENT_LAYER_TYPE, diff --git a/packages/astro/src/content/vite-plugin-content-assets.ts b/packages/astro/src/content/vite-plugin-content-assets.ts index b810b8f71a4e..059cd92fa6af 100644 --- a/packages/astro/src/content/vite-plugin-content-assets.ts +++ b/packages/astro/src/content/vite-plugin-content-assets.ts @@ -1,7 +1,6 @@ import { extname } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import type { Plugin } from 'vite'; -import type { AstroSettings, SSRElement } from '../@types/astro.js'; import { getAssetsPrefix } from '../assets/utils/getAssetsPrefix.js'; import type { BuildInternals } from '../core/build/internal.js'; import type { AstroBuildPlugin } from '../core/build/plugin.js'; @@ -9,6 +8,8 @@ import type { StaticBuildOptions } from '../core/build/types.js'; import type { ModuleLoader } from '../core/module-loader/loader.js'; import { createViteLoader } from '../core/module-loader/vite.js'; import { joinPaths, prependForwardSlash } from '../core/path.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { SSRElement } from '../types/public/internal.js'; import { getStylesForURL } from '../vite-plugin-astro-server/css.js'; import { getScriptsForURL } from '../vite-plugin-astro-server/scripts.js'; import { diff --git a/packages/astro/src/content/vite-plugin-content-imports.ts b/packages/astro/src/content/vite-plugin-content-imports.ts index 5a944716c353..62f129052a8d 100644 --- a/packages/astro/src/content/vite-plugin-content-imports.ts +++ b/packages/astro/src/content/vite-plugin-content-imports.ts @@ -4,19 +4,19 @@ import { pathToFileURL } from 'node:url'; import * as devalue from 'devalue'; import type { PluginContext } from 'rollup'; import type { Plugin } from 'vite'; -import type { - AstroConfig, - AstroSettings, - ContentEntryModule, - ContentEntryType, - DataEntryModule, - DataEntryType, -} from '../@types/astro.js'; import { getProxyCode } from '../assets/utils/proxy.js'; import { AstroError } from '../core/errors/errors.js'; import { AstroErrorData } from '../core/errors/index.js'; import type { Logger } from '../core/logger/core.js'; import { isServerLikeOutput } from '../core/util.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroConfig } from '../types/public/config.js'; +import type { + ContentEntryModule, + ContentEntryType, + DataEntryModule, + DataEntryType, +} from '../types/public/content.js'; import { CONTENT_FLAG, DATA_FLAG } from './consts.js'; import { type ContentConfig, diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts index 64e5d98ee410..832ca0b171ad 100644 --- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts +++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts @@ -5,12 +5,12 @@ import { dataToEsm } from '@rollup/pluginutils'; import glob from 'fast-glob'; import pLimit from 'p-limit'; import type { Plugin } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; import { encodeName } from '../core/build/util.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { appendForwardSlash, removeFileExtension } from '../core/path.js'; import { isServerLikeOutput } from '../core/util.js'; import { rootRelativePath } from '../core/viteUtils.js'; +import type { AstroSettings } from '../types/astro.js'; import type { AstroPluginMetadata } from '../vite-plugin-astro/index.js'; import { createDefaultAstroMetadata } from '../vite-plugin-astro/metadata.js'; import { diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 8041dda3c6f7..3ffa5f144647 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -1,5 +1,6 @@ -import type { ManifestData, RouteData, SSRManifest } from '../../@types/astro.js'; import { normalizeTheLocale } from '../../i18n/index.js'; +import type { ManifestData } from '../../types/astro.js'; +import type { RouteData, SSRManifest } from '../../types/public/internal.js'; import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER, diff --git a/packages/astro/src/core/app/middlewares.ts b/packages/astro/src/core/app/middlewares.ts index 095158b42ba3..a60b6baf4081 100644 --- a/packages/astro/src/core/app/middlewares.ts +++ b/packages/astro/src/core/app/middlewares.ts @@ -1,4 +1,4 @@ -import type { MiddlewareHandler } from '../../@types/astro.js'; +import type { MiddlewareHandler } from '../../types/public/common.js'; import { defineMiddleware } from '../middleware/index.js'; /** diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index f9afa6189d5a..86f0f5f65c46 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -1,6 +1,6 @@ import fs from 'node:fs'; import type { IncomingMessage, ServerResponse } from 'node:http'; -import type { RouteData } from '../../@types/astro.js'; +import type { RouteData } from '../../types/public/internal.js'; import { deserializeManifest } from './common.js'; import { createOutgoingHttpHeaders } from './createOutgoingHttpHeaders.js'; import { App } from './index.js'; diff --git a/packages/astro/src/core/app/pipeline.ts b/packages/astro/src/core/app/pipeline.ts index b784ba916464..d42472f50493 100644 --- a/packages/astro/src/core/app/pipeline.ts +++ b/packages/astro/src/core/app/pipeline.ts @@ -1,11 +1,6 @@ -import type { - ComponentInstance, - ManifestData, - RewritePayload, - RouteData, - SSRElement, - SSRResult, -} from '../../@types/astro.js'; +import type { ComponentInstance, ManifestData } from '../../types/astro.js'; +import type { RewritePayload } from '../../types/public/common.js'; +import type { RouteData, SSRElement, SSRResult } from '../../types/public/internal.js'; import { Pipeline } from '../base-pipeline.js'; import type { SinglePageBuiltModule } from '../build/types.js'; import { RedirectSinglePageBuiltModule } from '../redirects/component.js'; diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 00e37dacd9ba..29cb00ed4d1f 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -1,14 +1,13 @@ +import type { RoutingStrategies } from '../../i18n/utils.js'; +import type { ComponentInstance, SerializedRouteData } from '../../types/astro.js'; +import type { MiddlewareHandler } from '../../types/public/common.js'; +import type { Locales } from '../../types/public/config.js'; import type { - ComponentInstance, - Locales, - MiddlewareHandler, RouteData, SSRComponentMetadata, SSRLoadedRenderer, SSRResult, - SerializedRouteData, -} from '../../@types/astro.js'; -import type { RoutingStrategies } from '../../i18n/utils.js'; +} from '../../types/public/internal.js'; import type { SinglePageBuiltModule } from '../build/types.js'; export type ComponentPath = string; @@ -82,6 +81,7 @@ export type SSRManifestI18n = { domainLookupTable: Record; }; +/** Public type exposed through the `astro:build:ssr` integration hook */ export type SerializedSSRManifest = Omit< SSRManifest, | 'middleware' diff --git a/packages/astro/src/core/base-pipeline.ts b/packages/astro/src/core/base-pipeline.ts index 01e18bfa0356..562b651744b1 100644 --- a/packages/astro/src/core/base-pipeline.ts +++ b/packages/astro/src/core/base-pipeline.ts @@ -1,15 +1,14 @@ +import { setGetEnv } from '../env/runtime.js'; +import { createI18nMiddleware } from '../i18n/middleware.js'; +import type { ComponentInstance } from '../types/astro.js'; +import type { MiddlewareHandler, RewritePayload } from '../types/public/common.js'; +import type { RuntimeMode } from '../types/public/config.js'; import type { - ComponentInstance, - MiddlewareHandler, - RewritePayload, RouteData, - RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult, -} from '../@types/astro.js'; -import { setGetEnv } from '../env/runtime.js'; -import { createI18nMiddleware } from '../i18n/middleware.js'; +} from '../types/public/internal.js'; import { AstroError } from './errors/errors.js'; import { AstroErrorData } from './errors/index.js'; import type { Logger } from './logger/core.js'; diff --git a/packages/astro/src/core/build/common.ts b/packages/astro/src/core/build/common.ts index a479aed390dd..f9ed45836181 100644 --- a/packages/astro/src/core/build/common.ts +++ b/packages/astro/src/core/build/common.ts @@ -1,7 +1,8 @@ import npath from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import type { AstroConfig, RouteData } from '../../@types/astro.js'; import { appendForwardSlash } from '../../core/path.js'; +import type { AstroConfig } from '../../types/public/config.js'; +import type { RouteData } from '../../types/public/internal.js'; const STATUS_CODE_PAGES = new Set(['/404', '/500']); const FALLBACK_OUT_DIR_NAME = './.astro/'; diff --git a/packages/astro/src/core/build/css-asset-name.ts b/packages/astro/src/core/build/css-asset-name.ts index fbee7f2e2008..57277c989c2a 100644 --- a/packages/astro/src/core/build/css-asset-name.ts +++ b/packages/astro/src/core/build/css-asset-name.ts @@ -4,7 +4,7 @@ import crypto from 'node:crypto'; import npath from 'node:path'; import { fileURLToPath } from 'node:url'; import { normalizePath } from 'vite'; -import type { AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; import { viteID } from '../util.js'; import { getTopLevelPageModuleInfos } from './graph.js'; diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index fae7896b9212..1f71f2d8a55d 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -2,18 +2,6 @@ import fs from 'node:fs'; import os from 'node:os'; import { bgGreen, black, blue, bold, dim, green, magenta, red } from 'kleur/colors'; import PQueue from 'p-queue'; -import type { - AstroConfig, - AstroSettings, - ComponentInstance, - GetStaticPathsItem, - MiddlewareHandler, - RouteData, - RouteType, - SSRError, - SSRLoadedRenderer, - SSRManifest, -} from '../../@types/astro.js'; import { generateImagesForPath, getStaticImageList, @@ -29,7 +17,16 @@ import { import { toRoutingStrategy } from '../../i18n/utils.js'; import { runHookBuildGenerated } from '../../integrations/hooks.js'; import { getOutputDirectory } from '../../prerender/utils.js'; -import type { SSRManifestI18n } from '../app/types.js'; +import type { AstroSettings, ComponentInstance } from '../../types/astro.js'; +import type { GetStaticPathsItem, MiddlewareHandler } from '../../types/public/common.js'; +import type { AstroConfig } from '../../types/public/config.js'; +import type { + RouteData, + RouteType, + SSRError, + SSRLoadedRenderer, +} from '../../types/public/internal.js'; +import type { SSRManifest, SSRManifestI18n } from '../app/types.js'; import { NoPrerenderedRoutesWithDomains } from '../errors/errors-data.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import { getRedirectLocationOrThrow, routeIsRedirect } from '../redirects/index.js'; diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 72df05b89170..74a648304789 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -3,13 +3,6 @@ import { performance } from 'node:perf_hooks'; import { fileURLToPath } from 'node:url'; import { blue, bold, green } from 'kleur/colors'; import type * as vite from 'vite'; -import type { - AstroConfig, - AstroInlineConfig, - AstroSettings, - ManifestData, - RuntimeMode, -} from '../../@types/astro.js'; import { injectImageEndpoint } from '../../assets/endpoint/config.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; @@ -19,6 +12,8 @@ import { runHookConfigDone, runHookConfigSetup, } from '../../integrations/hooks.js'; +import type { AstroSettings, ManifestData } from '../../types/astro.js'; +import type { AstroConfig, AstroInlineConfig, RuntimeMode } from '../../types/public/config.js'; import { resolveConfig } from '../config/config.js'; import { createNodeLogger } from '../config/logging.js'; import { createSettings } from '../config/settings.js'; diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index 5c28a4d40ed9..8c2d928244f2 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -1,5 +1,5 @@ import type { Rollup } from 'vite'; -import type { RouteData, SSRResult } from '../../@types/astro.js'; +import type { RouteData, SSRResult } from '../../types/public/internal.js'; import { prependForwardSlash, removeFileExtension } from '../path.js'; import { viteID } from '../util.js'; import { makePageDataKey } from './plugins/util.js'; diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index 210b31a0e56f..06ed629f2ce6 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -1,4 +1,4 @@ -import type { AstroSettings, ManifestData } from '../../@types/astro.js'; +import type { AstroSettings, ManifestData } from '../../types/astro.js'; import type { Logger } from '../logger/core.js'; import type { AllPagesData } from './types.js'; diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index 4e0d94c57ea6..18357e5ae62b 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -1,11 +1,7 @@ -import type { - ComponentInstance, - RewritePayload, - RouteData, - SSRLoadedRenderer, - SSRResult, -} from '../../@types/astro.js'; import { getOutputDirectory } from '../../prerender/utils.js'; +import type { ComponentInstance } from '../../types/astro.js'; +import type { RewritePayload } from '../../types/public/common.js'; +import type { RouteData, SSRLoadedRenderer, SSRResult } from '../../types/public/internal.js'; import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import type { SSRManifest } from '../app/types.js'; import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-content.ts b/packages/astro/src/core/build/plugins/plugin-content.ts index 9c6d5add0b8d..5fe0b6792036 100644 --- a/packages/astro/src/core/build/plugins/plugin-content.ts +++ b/packages/astro/src/core/build/plugins/plugin-content.ts @@ -4,13 +4,13 @@ import { fileURLToPath } from 'node:url'; import glob from 'fast-glob'; import pLimit from 'p-limit'; import { type Plugin as VitePlugin, normalizePath } from 'vite'; -import type { AstroConfig } from '../../../@types/astro.js'; import { CONTENT_RENDER_FLAG, PROPAGATED_ASSET_FLAG } from '../../../content/consts.js'; import { type ContentLookupMap, hasContentFlag } from '../../../content/utils.js'; import { generateContentEntryFile, generateLookupMap, } from '../../../content/vite-plugin-content-virtual-mod.js'; +import type { AstroConfig } from '../../../types/public/config.js'; import { configPaths } from '../../config/index.js'; import { emptyDir } from '../../fs/index.js'; import { diff --git a/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts b/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts index 7c378490938a..2992c0f2d91d 100644 --- a/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts +++ b/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts @@ -1,5 +1,5 @@ import type { BuildOptions, Rollup, Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../../../@types/astro.js'; +import type { AstroSettings } from '../../../types/astro.js'; import { viteID } from '../../util.js'; import type { BuildInternals } from '../internal.js'; import { getPageDataByViteID } from '../internal.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index e9eda1dc90c2..888a4d44b177 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -1,8 +1,9 @@ import { join } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import type { Plugin as VitePlugin } from 'vite'; -import type { AstroAdapter, AstroSettings } from '../../../@types/astro.js'; import { isFunctionPerRouteEnabled } from '../../../integrations/hooks.js'; +import type { AstroSettings } from '../../../types/astro.js'; +import type { AstroAdapter } from '../../../types/public/integrations.js'; import { routeIsRedirect } from '../../redirects/index.js'; import { VIRTUAL_ISLAND_MAP_ID } from '../../server-islands/vite-plugin-server-islands.js'; import { isServerLikeOutput } from '../../util.js'; diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 7e2272dde60e..96feb85420df 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -5,7 +5,6 @@ import { teardown } from '@astrojs/compiler'; import glob from 'fast-glob'; import { bgGreen, bgMagenta, black, green } from 'kleur/colors'; import * as vite from 'vite'; -import type { RouteData } from '../../@types/astro.js'; import { PROPAGATED_ASSET_FLAG } from '../../content/consts.js'; import { getSymlinkedContentCollections, @@ -22,6 +21,7 @@ import { appendForwardSlash, prependForwardSlash, removeFileExtension } from '.. import { isModeServerWithNoAdapter, isServerLikeOutput } from '../../core/util.js'; import { runHookBuildSetup } from '../../integrations/hooks.js'; import { getOutputDirectory } from '../../prerender/utils.js'; +import type { RouteData } from '../../types/public/internal.js'; import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index 572140ef6669..f06f42501cf1 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -1,14 +1,9 @@ import type * as vite from 'vite'; import type { InlineConfig } from 'vite'; -import type { - AstroSettings, - ComponentInstance, - ManifestData, - MiddlewareHandler, - RouteData, - RuntimeMode, - SSRLoadedRenderer, -} from '../../@types/astro.js'; +import type { AstroSettings, ComponentInstance, ManifestData } from '../../types/astro.js'; +import type { MiddlewareHandler } from '../../types/public/common.js'; +import type { RuntimeMode } from '../../types/public/config.js'; +import type { RouteData, SSRLoadedRenderer } from '../../types/public/internal.js'; import type { Logger } from '../logger/core.js'; export type ComponentPath = string; @@ -20,6 +15,7 @@ export type StylesheetAsset = export type HoistedScriptAsset = { type: 'inline' | 'external'; value: string }; +/** Public type exposed through the `astro:build:setup` integration hook */ export interface PageBuildData { key: string; component: ComponentPath; diff --git a/packages/astro/src/core/build/util.ts b/packages/astro/src/core/build/util.ts index 9dc61f06fd8d..b6b313254379 100644 --- a/packages/astro/src/core/build/util.ts +++ b/packages/astro/src/core/build/util.ts @@ -1,5 +1,5 @@ import type { Rollup } from 'vite'; -import type { AstroConfig } from '../../@types/astro.js'; +import type { AstroConfig } from '../../types/public/config.js'; import type { ViteBuildReturn } from './types.js'; export function getTimeStat(timeStart: number, timeEnd: number) { diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index c3e6e4bb87a8..6e49f5850c63 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -1,11 +1,11 @@ import type { TransformResult } from '@astrojs/compiler'; import type { ResolvedConfig } from 'vite'; -import type { AstroConfig } from '../../@types/astro.js'; import { fileURLToPath } from 'node:url'; import { transform } from '@astrojs/compiler'; import { normalizePath } from 'vite'; import type { AstroPreferences } from '../../preferences/index.js'; +import type { AstroConfig } from '../../types/public/config.js'; import type { AstroError } from '../errors/errors.js'; import { AggregateError, CompilerError } from '../errors/errors.js'; import { AstroErrorData } from '../errors/index.js'; diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index c10066ce3273..3e19db8015f8 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -3,13 +3,13 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import * as colors from 'kleur/colors'; import { ZodError } from 'zod'; +import { eventConfigError, telemetry } from '../../events/index.js'; import type { AstroConfig, AstroInlineConfig, AstroInlineOnlyConfig, AstroUserConfig, -} from '../../@types/astro.js'; -import { eventConfigError, telemetry } from '../../events/index.js'; +} from '../../types/public/config.js'; import { trackAstroConfigZodError } from '../errors/errors.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import { formatConfigErrorMessage } from '../messages.js'; diff --git a/packages/astro/src/core/config/logging.ts b/packages/astro/src/core/config/logging.ts index 004283f85f0c..bd72f8b5e978 100644 --- a/packages/astro/src/core/config/logging.ts +++ b/packages/astro/src/core/config/logging.ts @@ -1,4 +1,4 @@ -import type { AstroInlineConfig } from '../../@types/astro.js'; +import type { AstroInlineConfig } from '../../types/public/config.js'; import { Logger } from '../logger/core.js'; import { nodeLogDestination } from '../logger/node.js'; diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index f49b4708e714..9db1117180b8 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -6,13 +6,13 @@ import type { } from '@astrojs/markdown-remark'; import { markdownConfigDefaults } from '@astrojs/markdown-remark'; import { type BuiltinTheme, bundledThemes } from 'shiki'; -import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro.js'; import type { OutgoingHttpHeaders } from 'node:http'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; import { z } from 'zod'; import { EnvSchema } from '../../env/schema.js'; +import type { AstroUserConfig, ViteUserConfig } from '../../types/public/config.js'; import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from '../path.js'; // The below types are required boilerplate to workaround a Zod issue since v3.21.2. Since that version, diff --git a/packages/astro/src/core/config/settings.ts b/packages/astro/src/core/config/settings.ts index 6c878d7f3323..902ff7d03318 100644 --- a/packages/astro/src/core/config/settings.ts +++ b/packages/astro/src/core/config/settings.ts @@ -1,9 +1,10 @@ import path from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import yaml from 'js-yaml'; -import type { AstroConfig, AstroSettings } from '../../@types/astro.js'; import { getContentPaths } from '../../content/index.js'; import createPreferences from '../../preferences/index.js'; +import type { AstroSettings } from '../../types/astro.js'; +import type { AstroConfig } from '../../types/public/config.js'; import { markdownContentEntryType } from '../../vite-plugin-markdown/content-entry-type.js'; import { getDefaultClientDirectives } from '../client-directive/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; diff --git a/packages/astro/src/core/config/validate.ts b/packages/astro/src/core/config/validate.ts index 4f4497b784d8..75a64f1f7d17 100644 --- a/packages/astro/src/core/config/validate.ts +++ b/packages/astro/src/core/config/validate.ts @@ -1,4 +1,4 @@ -import type { AstroConfig } from '../../@types/astro.js'; +import type { AstroConfig } from '../../types/public/config.js'; import { createRelativeSchema } from './schema.js'; /** Turn raw config values into normalized values */ diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 23a4068a8bda..f2931523a6ed 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -3,7 +3,6 @@ import { fileURLToPath } from 'node:url'; import glob from 'fast-glob'; import * as vite from 'vite'; import { crawlFrameworkPkgs } from 'vitefu'; -import type { AstroSettings } from '../@types/astro.js'; import { getAssetsPrefix } from '../assets/utils/getAssetsPrefix.js'; import astroAssetsPlugin from '../assets/vite-plugin-assets.js'; import astroContainer from '../container/vite-plugin-container.js'; @@ -17,6 +16,7 @@ import astroInternationalization from '../i18n/vite-plugin-i18n.js'; import astroPrefetch from '../prefetch/vite-plugin-prefetch.js'; import astroDevToolbar from '../toolbar/vite-plugin-dev-toolbar.js'; import astroTransitions from '../transitions/vite-plugin-transitions.js'; +import type { AstroSettings } from '../types/astro.js'; import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js'; import { vitePluginAstroServer } from '../vite-plugin-astro-server/index.js'; import astroVitePlugin from '../vite-plugin-astro/index.js'; @@ -185,7 +185,7 @@ export async function createVite( { // Typings are imported from 'astro' (e.g. import { Type } from 'astro') find: /^astro$/, - replacement: fileURLToPath(new URL('../@types/astro.js', import.meta.url)), + replacement: fileURLToPath(new URL('../types/public/index.js', import.meta.url)), }, { find: 'astro:middleware', diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 159d5e44769c..f89e331970c5 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -1,6 +1,6 @@ import type * as http from 'node:http'; import type { AddressInfo } from 'node:net'; -import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; import nodeFs from 'node:fs'; import * as vite from 'vite'; @@ -11,6 +11,7 @@ import { runHookServerDone, runHookServerStart, } from '../../integrations/hooks.js'; +import type { AstroInlineConfig } from '../../types/public/config.js'; import { createVite } from '../create-vite.js'; import type { Logger } from '../logger/core.js'; import { apply as applyPolyfill } from '../polyfill.js'; diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index 12b6d3b55aab..73ec0fa713e2 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -5,13 +5,13 @@ import { performance } from 'node:perf_hooks'; import { green } from 'kleur/colors'; import { gt, major, minor, patch } from 'semver'; import type * as vite from 'vite'; -import type { AstroInlineConfig } from '../../@types/astro.js'; import { DATA_STORE_FILE } from '../../content/consts.js'; import { globalContentLayer } from '../../content/content-layer.js'; import { attachContentServerListeners } from '../../content/index.js'; import { MutableDataStore } from '../../content/mutable-data-store.js'; import { globalContentConfigObserver } from '../../content/utils.js'; import { telemetry } from '../../events/index.js'; +import type { AstroInlineConfig } from '../../types/public/config.js'; import * as msg from '../messages.js'; import { ensureProcessNodeEnv } from '../util.js'; import { startContainer } from './container.js'; diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index ee0ba995c446..8fb6e46a300c 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -1,9 +1,10 @@ import type nodeFs from 'node:fs'; import { fileURLToPath } from 'node:url'; import * as vite from 'vite'; -import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; import { globalContentLayer } from '../../content/content-layer.js'; import { eventCliSession, telemetry } from '../../events/index.js'; +import type { AstroSettings } from '../../types/astro.js'; +import type { AstroInlineConfig } from '../../types/public/config.js'; import { createNodeLogger, createSettings, resolveConfig } from '../config/index.js'; import { collectErrorMetadata } from '../errors/dev/utils.js'; import { isAstroConfigZodError } from '../errors/errors.js'; diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index 341c815a6762..c082a81937de 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -6,7 +6,7 @@ import { bold, underline } from 'kleur/colors'; import stripAnsi from 'strip-ansi'; import type { ESBuildTransformResult } from 'vite'; import { normalizePath } from 'vite'; -import type { SSRError } from '../../../@types/astro.js'; +import type { SSRError } from '../../../types/public/internal.js'; import { removeLeadingForwardSlashWindows } from '../../path.js'; import { AggregateError, type ErrorWithMetadata } from '../errors.js'; import { AstroErrorData } from '../index.js'; diff --git a/packages/astro/src/core/errors/dev/vite.ts b/packages/astro/src/core/errors/dev/vite.ts index 56688877a861..c944ad78d686 100644 --- a/packages/astro/src/core/errors/dev/vite.ts +++ b/packages/astro/src/core/errors/dev/vite.ts @@ -3,11 +3,11 @@ import { fileURLToPath } from 'node:url'; import { codeToHtml, createCssVariablesTheme } from 'shiki'; import type { ShikiTransformer } from 'shiki'; import type { ErrorPayload } from 'vite'; +import type { SSRLoadedRenderer } from '../../../types/public/internal.js'; import type { ModuleLoader } from '../../module-loader/index.js'; import { FailedToLoadModuleSSR, InvalidGlob, MdxIntegrationMissingError } from '../errors-data.js'; import { AstroError, type ErrorWithMetadata } from '../errors.js'; import { createSafeError } from '../utils.js'; -import type { SSRLoadedRenderer } from './../../../@types/astro.js'; import { getDocsForError, renderErrorMarkdown } from './utils.js'; export function enhanceViteSSRError({ diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index 24b9ad687aea..e083ba2f54ae 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -1,5 +1,5 @@ // BEFORE ADDING AN ERROR: Please look at the README.md in this folder for general guidelines on writing error messages -// Additionally, this code, much like `@types/astro.ts`, is used to generate documentation, so make sure to pass +// Additionally, this code, much like `types/public/config.ts`, is used to generate documentation, so make sure to pass // your changes by our wonderful docs team before merging! import type { ZodError } from 'zod'; diff --git a/packages/astro/src/core/errors/utils.ts b/packages/astro/src/core/errors/utils.ts index 05dd49071a48..6754656b9134 100644 --- a/packages/astro/src/core/errors/utils.ts +++ b/packages/astro/src/core/errors/utils.ts @@ -1,6 +1,6 @@ import type { YAMLException } from 'js-yaml'; import type { ErrorPayload as ViteErrorPayload } from 'vite'; -import type { SSRError } from '../../@types/astro.js'; +import type { SSRError } from '../../types/public/internal.js'; /** * Get the line and character based on the offset diff --git a/packages/astro/src/core/index.ts b/packages/astro/src/core/index.ts index bdd7c7f05939..14a8c2f99af0 100644 --- a/packages/astro/src/core/index.ts +++ b/packages/astro/src/core/index.ts @@ -1,6 +1,6 @@ // This is the main entrypoint when importing the `astro` package. -import type { AstroInlineConfig } from '../@types/astro.js'; +import type { AstroInlineConfig } from '../types/public/config.js'; import { default as _build } from './build/index.js'; import { default as _sync } from './sync/index.js'; diff --git a/packages/astro/src/core/middleware/callMiddleware.ts b/packages/astro/src/core/middleware/callMiddleware.ts index 3bdc6052da99..4cc7b6586685 100644 --- a/packages/astro/src/core/middleware/callMiddleware.ts +++ b/packages/astro/src/core/middleware/callMiddleware.ts @@ -1,9 +1,9 @@ import type { - APIContext, MiddlewareHandler, MiddlewareNext, RewritePayload, -} from '../../@types/astro.js'; +} from '../../types/public/common.js'; +import type { APIContext } from '../../types/public/context.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; /** diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts index 56ce0b76c364..31988ae02eac 100644 --- a/packages/astro/src/core/middleware/index.ts +++ b/packages/astro/src/core/middleware/index.ts @@ -1,10 +1,11 @@ -import type { APIContext, MiddlewareHandler, Params, RewritePayload } from '../../@types/astro.js'; import { createCallAction, createGetActionResult } from '../../actions/utils.js'; import { computeCurrentLocale, computePreferredLocale, computePreferredLocaleList, } from '../../i18n/utils.js'; +import type { MiddlewareHandler, Params, RewritePayload } from '../../types/public/common.js'; +import type { APIContext } from '../../types/public/context.js'; import { ASTRO_VERSION, clientAddressSymbol, clientLocalsSymbol } from '../constants.js'; import { AstroCookies } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; diff --git a/packages/astro/src/core/middleware/sequence.ts b/packages/astro/src/core/middleware/sequence.ts index ee08381e6fe4..aefa66a9205d 100644 --- a/packages/astro/src/core/middleware/sequence.ts +++ b/packages/astro/src/core/middleware/sequence.ts @@ -1,4 +1,5 @@ -import type { APIContext, MiddlewareHandler, RewritePayload } from '../../@types/astro.js'; +import type { MiddlewareHandler, RewritePayload } from '../../types/public/common.js'; +import type { APIContext } from '../../types/public/context.js'; import { AstroCookies } from '../cookies/cookies.js'; import { defineMiddleware } from './index.js'; diff --git a/packages/astro/src/core/middleware/vite-plugin.ts b/packages/astro/src/core/middleware/vite-plugin.ts index bb7b54e727d3..8a76bed921c9 100644 --- a/packages/astro/src/core/middleware/vite-plugin.ts +++ b/packages/astro/src/core/middleware/vite-plugin.ts @@ -1,7 +1,7 @@ import type { Plugin as VitePlugin } from 'vite'; import { normalizePath } from 'vite'; -import type { AstroSettings } from '../../@types/astro.js'; import { getOutputDirectory } from '../../prerender/utils.js'; +import type { AstroSettings } from '../../types/astro.js'; import { addRollupInput } from '../build/add-rollup-input.js'; import type { BuildInternals } from '../build/internal.js'; import type { StaticBuildOptions } from '../build/types.js'; diff --git a/packages/astro/src/core/module-loader/loader.ts b/packages/astro/src/core/module-loader/loader.ts index 976354448acc..9973ae6577e8 100644 --- a/packages/astro/src/core/module-loader/loader.ts +++ b/packages/astro/src/core/module-loader/loader.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'node:events'; import type * as fs from 'node:fs'; -import type { TypedEventEmitter } from '../../@types/typed-emitter.js'; +import type { TypedEventEmitter } from '../../types/typed-emitter.js'; // This is a generic interface for a module loader. In the astro cli this is // fulfilled by Vite, see vite.ts diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index b46cf1becc57..a8a533fe85b7 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -1,11 +1,12 @@ import fs from 'node:fs'; import { createRequire } from 'node:module'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import type { AstroInlineConfig, PreviewModule, PreviewServer } from '../../@types/astro.js'; import { AstroIntegrationLogger } from '../../core/logger/core.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; import { runHookConfigDone, runHookConfigSetup } from '../../integrations/hooks.js'; +import type { AstroInlineConfig } from '../../types/public/config.js'; +import type { PreviewModule, PreviewServer } from '../../types/public/preview.js'; import { resolveConfig } from '../config/config.js'; import { createNodeLogger } from '../config/logging.js'; import { createSettings } from '../config/settings.js'; diff --git a/packages/astro/src/core/preview/static-preview-server.ts b/packages/astro/src/core/preview/static-preview-server.ts index 0afa34b6042e..855506ef91ce 100644 --- a/packages/astro/src/core/preview/static-preview-server.ts +++ b/packages/astro/src/core/preview/static-preview-server.ts @@ -2,7 +2,7 @@ import type http from 'node:http'; import { performance } from 'node:perf_hooks'; import { fileURLToPath } from 'node:url'; import { type PreviewServer as VitePreviewServer, preview } from 'vite'; -import type { AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; import type { Logger } from '../logger/core.js'; import * as msg from '../messages.js'; import { getResolvedHostForHttpServer } from './util.js'; diff --git a/packages/astro/src/core/preview/vite-plugin-astro-preview.ts b/packages/astro/src/core/preview/vite-plugin-astro-preview.ts index a425807dccd2..fd9bbae66c57 100644 --- a/packages/astro/src/core/preview/vite-plugin-astro-preview.ts +++ b/packages/astro/src/core/preview/vite-plugin-astro-preview.ts @@ -2,8 +2,8 @@ import fs from 'node:fs'; import type { IncomingMessage, ServerResponse } from 'node:http'; import { fileURLToPath } from 'node:url'; import type { Connect, Plugin } from 'vite'; -import type { AstroSettings } from '../../@types/astro.js'; import { notFoundTemplate, subpathNotUsedTemplate } from '../../template/4xx.js'; +import type { AstroSettings } from '../../types/astro.js'; import { cleanUrl } from '../../vite-plugin-utils/index.js'; import { stripBase } from './util.js'; diff --git a/packages/astro/src/core/redirects/component.ts b/packages/astro/src/core/redirects/component.ts index 00b8d176c1d2..12b37ae0091b 100644 --- a/packages/astro/src/core/redirects/component.ts +++ b/packages/astro/src/core/redirects/component.ts @@ -1,4 +1,4 @@ -import type { ComponentInstance } from '../../@types/astro.js'; +import type { ComponentInstance } from '../../types/astro.js'; import type { SinglePageBuiltModule } from '../build/types.js'; // A stub of a component instance for a given route diff --git a/packages/astro/src/core/redirects/helpers.ts b/packages/astro/src/core/redirects/helpers.ts index 80f18ae0f123..a2dc42df96e5 100644 --- a/packages/astro/src/core/redirects/helpers.ts +++ b/packages/astro/src/core/redirects/helpers.ts @@ -1,4 +1,8 @@ -import type { RedirectRouteData, RouteData } from '../../@types/astro.js'; +import type { RouteData } from '../../types/public/internal.js'; + +type RedirectRouteData = RouteData & { + redirect: string; +}; export function routeIsRedirect(route: RouteData | undefined): route is RedirectRouteData { return route?.type === 'redirect'; diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index a19d11080a97..ab0554d0c03d 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -1,14 +1,3 @@ -import type { - APIContext, - AstroGlobal, - AstroGlobalPartial, - ComponentInstance, - MiddlewareHandler, - Props, - RewritePayload, - RouteData, - SSRResult, -} from '../@types/astro.js'; import type { ActionAPIContext } from '../actions/runtime/utils.js'; import { deserializeActionResult } from '../actions/runtime/virtual/shared.js'; import { createCallAction, createGetActionResult, hasActionPayload } from '../actions/utils.js'; @@ -19,6 +8,10 @@ import { } from '../i18n/utils.js'; import { renderEndpoint } from '../runtime/server/endpoint.js'; import { renderPage } from '../runtime/server/index.js'; +import type { ComponentInstance } from '../types/astro.js'; +import type { MiddlewareHandler, Props, RewritePayload } from '../types/public/common.js'; +import type { APIContext, AstroGlobal, AstroGlobalPartial } from '../types/public/context.js'; +import type { RouteData, SSRResult } from '../types/public/internal.js'; import { ASTRO_VERSION, REROUTE_DIRECTIVE_HEADER, diff --git a/packages/astro/src/core/render/index.ts b/packages/astro/src/core/render/index.ts index db14701b0fde..b56a2eaf2cc0 100644 --- a/packages/astro/src/core/render/index.ts +++ b/packages/astro/src/core/render/index.ts @@ -1,4 +1,5 @@ -import type { ComponentInstance, RouteData } from '../../@types/astro.js'; +import type { ComponentInstance } from '../../types/astro.js'; +import type { RouteData } from '../../types/public/internal.js'; import type { Pipeline } from '../base-pipeline.js'; export { Pipeline } from '../base-pipeline.js'; export { getParams, getProps } from './params-and-props.js'; diff --git a/packages/astro/src/core/render/paginate.ts b/packages/astro/src/core/render/paginate.ts index e962d98d31f4..c462cd4b8646 100644 --- a/packages/astro/src/core/render/paginate.ts +++ b/packages/astro/src/core/render/paginate.ts @@ -4,8 +4,8 @@ import type { PaginateOptions, Params, Props, - RouteData, -} from '../../@types/astro.js'; +} from '../../types/public/common.js'; +import type { RouteData } from '../../types/public/internal.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; export function generatePaginateFunction( diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index cf7d02d48360..a45fb16a8084 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -1,4 +1,6 @@ -import type { ComponentInstance, Params, Props, RouteData } from '../../@types/astro.js'; +import type { ComponentInstance } from '../../types/astro.js'; +import type { Params, Props } from '../../types/public/common.js'; +import type { RouteData } from '../../types/public/internal.js'; import { DEFAULT_404_COMPONENT } from '../constants.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; diff --git a/packages/astro/src/core/render/renderer.ts b/packages/astro/src/core/render/renderer.ts index 42cc8fd05d64..8daec8d53e5f 100644 --- a/packages/astro/src/core/render/renderer.ts +++ b/packages/astro/src/core/render/renderer.ts @@ -1,4 +1,5 @@ -import type { AstroRenderer, SSRLoadedRenderer } from '../../@types/astro.js'; +import type { AstroRenderer } from '../../types/public/integrations.js'; +import type { SSRLoadedRenderer } from '../../types/public/internal.js'; import type { ModuleLoader } from '../module-loader/index.js'; export async function loadRenderer( diff --git a/packages/astro/src/core/render/route-cache.ts b/packages/astro/src/core/render/route-cache.ts index 399795675e06..3329c42cd347 100644 --- a/packages/astro/src/core/render/route-cache.ts +++ b/packages/astro/src/core/render/route-cache.ts @@ -1,13 +1,13 @@ +import type { ComponentInstance } from '../../types/astro.js'; import type { - ComponentInstance, GetStaticPathsItem, GetStaticPathsResult, GetStaticPathsResultKeyed, PaginateFunction, Params, - RouteData, - RuntimeMode, -} from '../../@types/astro.js'; +} from '../../types/public/common.js'; +import type { RuntimeMode } from '../../types/public/config.js'; +import type { RouteData } from '../../types/public/internal.js'; import type { Logger } from '../logger/core.js'; import { stringifyParams } from '../routing/params.js'; diff --git a/packages/astro/src/core/render/slots.ts b/packages/astro/src/core/render/slots.ts index ab87204e465e..1c767083da71 100644 --- a/packages/astro/src/core/render/slots.ts +++ b/packages/astro/src/core/render/slots.ts @@ -1,8 +1,8 @@ -import type { SSRResult } from '../../@types/astro.js'; import { type ComponentSlots, renderSlotToString } from '../../runtime/server/index.js'; import { renderJSX } from '../../runtime/server/jsx.js'; import { chunkToString } from '../../runtime/server/render/index.js'; import { isRenderInstruction } from '../../runtime/server/render/instruction.js'; +import type { SSRResult } from '../../types/public/internal.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; diff --git a/packages/astro/src/core/render/ssr-element.ts b/packages/astro/src/core/render/ssr-element.ts index 7c766ee20e4a..827c8fddf40d 100644 --- a/packages/astro/src/core/render/ssr-element.ts +++ b/packages/astro/src/core/render/ssr-element.ts @@ -1,7 +1,7 @@ -import type { AssetsPrefix, SSRElement } from '../../@types/astro.js'; import { getAssetsPrefix } from '../../assets/utils/getAssetsPrefix.js'; import { fileExtension, joinPaths, prependForwardSlash, slash } from '../../core/path.js'; -import type { StylesheetAsset } from '../app/types.js'; +import type { SSRElement } from '../../types/public/internal.js'; +import type { AssetsPrefix, StylesheetAsset } from '../app/types.js'; export function createAssetLink(href: string, base?: string, assetsPrefix?: AssetsPrefix): string { if (assetsPrefix) { diff --git a/packages/astro/src/core/routing/astro-designed-error-pages.ts b/packages/astro/src/core/routing/astro-designed-error-pages.ts index 4e4b41b70cf7..2c1c1f77c5a3 100644 --- a/packages/astro/src/core/routing/astro-designed-error-pages.ts +++ b/packages/astro/src/core/routing/astro-designed-error-pages.ts @@ -1,5 +1,6 @@ -import type { ComponentInstance, ManifestData, RouteData } from '../../@types/astro.js'; import notFoundTemplate from '../../template/4xx.js'; +import type { ComponentInstance, ManifestData } from '../../types/astro.js'; +import type { RouteData } from '../../types/public/internal.js'; import { DEFAULT_404_COMPONENT, DEFAULT_500_COMPONENT } from '../constants.js'; export const DEFAULT_404_ROUTE: RouteData = { diff --git a/packages/astro/src/core/routing/default.ts b/packages/astro/src/core/routing/default.ts index dd3c8cc538c1..8bcd473d0081 100644 --- a/packages/astro/src/core/routing/default.ts +++ b/packages/astro/src/core/routing/default.ts @@ -1,4 +1,5 @@ -import type { ComponentInstance, ManifestData, SSRManifest } from '../../@types/astro.js'; +import type { ComponentInstance, ManifestData } from '../../types/astro.js'; +import type { SSRManifest } from '../app/types.js'; import { DEFAULT_404_COMPONENT } from '../constants.js'; import { SERVER_ISLAND_COMPONENT, diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index df548ec8248d..14980f63e5ad 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -1,11 +1,4 @@ -import type { - AstroConfig, - AstroSettings, - ManifestData, - RouteData, - RoutePart, - RoutePriorityOverride, -} from '../../../@types/astro.js'; +import type { AstroSettings, ManifestData } from '../../../types/astro.js'; import type { Logger } from '../../logger/core.js'; import nodeFs from 'node:fs'; @@ -15,6 +8,9 @@ import { fileURLToPath } from 'node:url'; import { bold } from 'kleur/colors'; import { toRoutingStrategy } from '../../../i18n/utils.js'; import { getPrerenderDefault } from '../../../prerender/utils.js'; +import type { AstroConfig } from '../../../types/public/config.js'; +import type { RoutePriorityOverride } from '../../../types/public/integrations.js'; +import type { RouteData, RoutePart } from '../../../types/public/internal.js'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from '../../constants.js'; import { MissingIndexForInternationalization } from '../../errors/errors-data.js'; import { AstroError } from '../../errors/index.js'; diff --git a/packages/astro/src/core/routing/manifest/generator.ts b/packages/astro/src/core/routing/manifest/generator.ts index 4ab635ec6608..e3565864d91d 100644 --- a/packages/astro/src/core/routing/manifest/generator.ts +++ b/packages/astro/src/core/routing/manifest/generator.ts @@ -1,6 +1,6 @@ -import type { AstroConfig, RoutePart } from '../../../@types/astro.js'; - import { compile } from 'path-to-regexp'; +import type { AstroConfig } from '../../../types/public/config.js'; +import type { RoutePart } from '../../../types/public/internal.js'; /** * Sanitizes the parameters object by normalizing string values and replacing certain characters with their URL-encoded equivalents. diff --git a/packages/astro/src/core/routing/manifest/pattern.ts b/packages/astro/src/core/routing/manifest/pattern.ts index 65f223aa0c20..8a9a9d27f9fc 100644 --- a/packages/astro/src/core/routing/manifest/pattern.ts +++ b/packages/astro/src/core/routing/manifest/pattern.ts @@ -1,4 +1,5 @@ -import type { AstroConfig, RoutePart } from '../../../@types/astro.js'; +import type { AstroConfig } from '../../../types/public/config.js'; +import type { RoutePart } from '../../../types/public/internal.js'; export function getPattern( segments: RoutePart[][], diff --git a/packages/astro/src/core/routing/manifest/serialization.ts b/packages/astro/src/core/routing/manifest/serialization.ts index 852aa703bf9d..c0cf600f0b79 100644 --- a/packages/astro/src/core/routing/manifest/serialization.ts +++ b/packages/astro/src/core/routing/manifest/serialization.ts @@ -1,4 +1,6 @@ -import type { AstroConfig, RouteData, SerializedRouteData } from '../../../@types/astro.js'; +import type { SerializedRouteData } from '../../../types/astro.js'; +import type { AstroConfig } from '../../../types/public/config.js'; +import type { RouteData } from '../../../types/public/internal.js'; import { getRouteGenerator } from './generator.js'; diff --git a/packages/astro/src/core/routing/match.ts b/packages/astro/src/core/routing/match.ts index 40a8b95fba29..403b3fb9535b 100644 --- a/packages/astro/src/core/routing/match.ts +++ b/packages/astro/src/core/routing/match.ts @@ -1,4 +1,5 @@ -import type { ManifestData, RouteData } from '../../@types/astro.js'; +import type { ManifestData } from '../../types/astro.js'; +import type { RouteData } from '../../types/public/internal.js'; /** Find matching route from pathname */ export function matchRoute(pathname: string, manifest: ManifestData): RouteData | undefined { diff --git a/packages/astro/src/core/routing/params.ts b/packages/astro/src/core/routing/params.ts index 43cd24cc13a7..802c39cc5043 100644 --- a/packages/astro/src/core/routing/params.ts +++ b/packages/astro/src/core/routing/params.ts @@ -1,4 +1,5 @@ -import type { GetStaticPathsItem, Params, RouteData } from '../../@types/astro.js'; +import type { GetStaticPathsItem, Params } from '../../types/public/common.js'; +import type { RouteData } from '../../types/public/internal.js'; import { trimSlashes } from '../path.js'; import { validateGetStaticPathsParameter } from './validation.js'; diff --git a/packages/astro/src/core/routing/priority.ts b/packages/astro/src/core/routing/priority.ts index 4082683970e5..dc1c665c6156 100644 --- a/packages/astro/src/core/routing/priority.ts +++ b/packages/astro/src/core/routing/priority.ts @@ -1,4 +1,4 @@ -import type { RouteData } from '../../@types/astro.js'; +import type { RouteData } from '../../types/public/internal.js'; /** * Comparator for sorting routes in resolution order. diff --git a/packages/astro/src/core/routing/rewrite.ts b/packages/astro/src/core/routing/rewrite.ts index f30caed08c7b..a6fce3354929 100644 --- a/packages/astro/src/core/routing/rewrite.ts +++ b/packages/astro/src/core/routing/rewrite.ts @@ -1,4 +1,6 @@ -import type { AstroConfig, RewritePayload, RouteData } from '../../@types/astro.js'; +import type { RewritePayload } from '../../types/public/common.js'; +import type { AstroConfig } from '../../types/public/config.js'; +import type { RouteData } from '../../types/public/internal.js'; import { shouldAppendForwardSlash } from '../build/util.js'; import { appendForwardSlash, removeTrailingForwardSlash } from '../path.js'; import { DEFAULT_404_ROUTE } from './astro-designed-error-pages.js'; diff --git a/packages/astro/src/core/routing/validation.ts b/packages/astro/src/core/routing/validation.ts index 1f11f55e6cd4..a2f9a25ba320 100644 --- a/packages/astro/src/core/routing/validation.ts +++ b/packages/astro/src/core/routing/validation.ts @@ -1,4 +1,6 @@ -import type { ComponentInstance, GetStaticPathsResult, RouteData } from '../../@types/astro.js'; +import type { ComponentInstance } from '../../types/astro.js'; +import type { GetStaticPathsResult } from '../../types/public/common.js'; +import type { RouteData } from '../../types/public/internal.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; diff --git a/packages/astro/src/core/server-islands/endpoint.ts b/packages/astro/src/core/server-islands/endpoint.ts index 368a1b9b19ac..73ed5717704d 100644 --- a/packages/astro/src/core/server-islands/endpoint.ts +++ b/packages/astro/src/core/server-islands/endpoint.ts @@ -1,9 +1,3 @@ -import type { - ComponentInstance, - ManifestData, - RouteData, - SSRManifest, -} from '../../@types/astro.js'; import { type AstroComponentFactory, type ComponentSlots, @@ -11,6 +5,8 @@ import { renderTemplate, } from '../../runtime/server/index.js'; import { createSlotValueFromString } from '../../runtime/server/render/slot.js'; +import type { ComponentInstance, ManifestData } from '../../types/astro.js'; +import type { RouteData, SSRManifest } from '../../types/public/internal.js'; import { decryptString } from '../encryption.js'; import { getPattern } from '../routing/manifest/pattern.js'; diff --git a/packages/astro/src/core/server-islands/vite-plugin-server-islands.ts b/packages/astro/src/core/server-islands/vite-plugin-server-islands.ts index 573ae9cf9703..8bc79e087d56 100644 --- a/packages/astro/src/core/server-islands/vite-plugin-server-islands.ts +++ b/packages/astro/src/core/server-islands/vite-plugin-server-islands.ts @@ -1,5 +1,5 @@ import type { ConfigEnv, ViteDevServer, Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; import type { AstroPluginMetadata } from '../../vite-plugin-astro/index.js'; export const VIRTUAL_ISLAND_MAP_ID = '@astro-server-islands'; diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 92b3478e344d..02ab6bf9e137 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -3,7 +3,6 @@ import { performance } from 'node:perf_hooks'; import { fileURLToPath } from 'node:url'; import { dim } from 'kleur/colors'; import { type HMRPayload, createServer } from 'vite'; -import type { AstroConfig, AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; import { CONTENT_TYPES_FILE, DATA_STORE_FILE } from '../../content/consts.js'; import { globalContentLayer } from '../../content/content-layer.js'; import { createContentTypesGenerator } from '../../content/index.js'; @@ -13,6 +12,8 @@ import { syncAstroEnv } from '../../env/sync.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; import { runHookConfigDone, runHookConfigSetup } from '../../integrations/hooks.js'; +import type { AstroSettings } from '../../types/astro.js'; +import type { AstroConfig, AstroInlineConfig } from '../../types/public/config.js'; import { getTimeStat } from '../build/util.js'; import { resolveConfig } from '../config/config.js'; import { createNodeLogger } from '../config/logging.js'; diff --git a/packages/astro/src/core/sync/write-files.ts b/packages/astro/src/core/sync/write-files.ts index 91084c36f965..1f7d1d304608 100644 --- a/packages/astro/src/core/sync/write-files.ts +++ b/packages/astro/src/core/sync/write-files.ts @@ -3,7 +3,7 @@ import { dirname, relative } from 'node:path'; import { fileURLToPath } from 'node:url'; import { bold } from 'kleur/colors'; import { normalizePath } from 'vite'; -import type { AstroSettings } from '../../@types/astro.js'; +import type { AstroSettings } from '../../types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; import { REFERENCE_FILE } from './constants.js'; diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 654d1982994c..497d54610262 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -1,7 +1,9 @@ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroConfig } from '../types/public/config.js'; +import type { RouteType } from '../types/public/internal.js'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js'; import { removeTrailingForwardSlash, slash } from './path.js'; diff --git a/packages/astro/src/env/sync.ts b/packages/astro/src/env/sync.ts index 27436f967be7..90a29685dc28 100644 --- a/packages/astro/src/env/sync.ts +++ b/packages/astro/src/env/sync.ts @@ -1,5 +1,5 @@ import fsMod from 'node:fs'; -import type { AstroSettings } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; import { TYPES_TEMPLATE_URL } from './constants.js'; import { getEnvFieldType } from './validators.js'; diff --git a/packages/astro/src/env/vite-plugin-env.ts b/packages/astro/src/env/vite-plugin-env.ts index fdcd6ce4015d..934ba79ca2ab 100644 --- a/packages/astro/src/env/vite-plugin-env.ts +++ b/packages/astro/src/env/vite-plugin-env.ts @@ -1,8 +1,8 @@ import type fsMod from 'node:fs'; import { fileURLToPath } from 'node:url'; import { type Plugin, loadEnv } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; +import type { AstroSettings } from '../types/astro.js'; import { MODULE_TEMPLATE_URL, VIRTUAL_MODULES_IDS, diff --git a/packages/astro/src/events/session.ts b/packages/astro/src/events/session.ts index 18049ac04dd0..6e919f127bee 100644 --- a/packages/astro/src/events/session.ts +++ b/packages/astro/src/events/session.ts @@ -1,5 +1,6 @@ -import type { AstroIntegration, AstroUserConfig } from '../@types/astro.js'; import { AstroConfigSchema } from '../core/config/schema.js'; +import type { AstroUserConfig } from '../types/public/config.js'; +import type { AstroIntegration } from '../types/public/integrations.js'; const EVENT_SESSION = 'ASTRO_CLI_SESSION_STARTED'; diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index aa38b63bbe89..c7e676f75803 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -1,15 +1,11 @@ import { appendForwardSlash, joinPaths } from '@astrojs/internal-helpers/path'; -import type { - APIContext, - AstroConfig, - Locales, - SSRManifest, - ValidRedirectStatus, -} from '../@types/astro.js'; +import type { SSRManifest } from '../core/app/types.js'; import { shouldAppendForwardSlash } from '../core/build/util.js'; import { REROUTE_DIRECTIVE_HEADER } from '../core/constants.js'; import { MissingLocale, i18nNoLocaleFoundInPath } from '../core/errors/errors-data.js'; import { AstroError } from '../core/errors/index.js'; +import type { AstroConfig, Locales, ValidRedirectStatus } from '../types/public/config.js'; +import type { APIContext } from '../types/public/context.js'; import { createI18nMiddleware } from './middleware.js'; import type { RoutingStrategies } from './utils.js'; diff --git a/packages/astro/src/i18n/middleware.ts b/packages/astro/src/i18n/middleware.ts index 097332805759..7c2fc1406b2a 100644 --- a/packages/astro/src/i18n/middleware.ts +++ b/packages/astro/src/i18n/middleware.ts @@ -1,6 +1,7 @@ -import type { APIContext, MiddlewareHandler, SSRManifest } from '../@types/astro.js'; -import type { SSRManifestI18n } from '../core/app/types.js'; +import type { SSRManifest, SSRManifestI18n } from '../core/app/types.js'; import { ROUTE_TYPE_HEADER } from '../core/constants.js'; +import type { MiddlewareHandler } from '../types/public/common.js'; +import type { APIContext } from '../types/public/context.js'; import { type MiddlewarePayload, normalizeTheLocale, diff --git a/packages/astro/src/i18n/utils.ts b/packages/astro/src/i18n/utils.ts index 052fe01fce65..98a44a19ca5e 100644 --- a/packages/astro/src/i18n/utils.ts +++ b/packages/astro/src/i18n/utils.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, Locales } from '../@types/astro.js'; +import type { AstroConfig, Locales } from '../types/public/config.js'; import { normalizeTheLocale, toCodes } from './index.js'; type BrowserLocale = { diff --git a/packages/astro/src/i18n/vite-plugin-i18n.ts b/packages/astro/src/i18n/vite-plugin-i18n.ts index 7aa4d327b223..5ee79a8836a8 100644 --- a/packages/astro/src/i18n/vite-plugin-i18n.ts +++ b/packages/astro/src/i18n/vite-plugin-i18n.ts @@ -1,7 +1,8 @@ import type * as vite from 'vite'; -import type { AstroConfig, AstroSettings } from '../@types/astro.js'; import { AstroError } from '../core/errors/errors.js'; import { AstroErrorData } from '../core/errors/index.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroConfig } from '../types/public/config.js'; const virtualModuleId = 'astro:i18n'; diff --git a/packages/astro/src/integrations/features-validation.ts b/packages/astro/src/integrations/features-validation.ts index 87de3592b726..f59a25b15c28 100644 --- a/packages/astro/src/integrations/features-validation.ts +++ b/packages/astro/src/integrations/features-validation.ts @@ -1,11 +1,11 @@ +import type { Logger } from '../core/logger/core.js'; +import type { AstroConfig } from '../types/public/config.js'; import type { + AdapterSupportsKind, + AstroAdapterFeatureMap, AstroAdapterFeatures, AstroAssetsFeature, - AstroConfig, - AstroFeatureMap, - SupportsKind, -} from '../@types/astro.js'; -import type { Logger } from '../core/logger/core.js'; +} from '../types/public/integrations.js'; const STABLE = 'stable'; const DEPRECATED = 'deprecated'; @@ -19,7 +19,7 @@ const UNSUPPORTED_ASSETS_FEATURE: AstroAssetsFeature = { }; type ValidationResult = { - [Property in keyof AstroFeatureMap]: boolean; + [Property in keyof AstroAdapterFeatureMap]: boolean; }; /** @@ -31,7 +31,7 @@ type ValidationResult = { */ export function validateSupportedFeatures( adapterName: string, - featureMap: AstroFeatureMap, + featureMap: AstroAdapterFeatureMap, config: AstroConfig, adapterFeatures: AstroAdapterFeatures | undefined, logger: Logger, @@ -101,7 +101,7 @@ export function validateSupportedFeatures( } function validateSupportKind( - supportKind: SupportsKind, + supportKind: AdapterSupportsKind, adapterName: string, logger: Logger, featureName: string, diff --git a/packages/astro/src/integrations/hooks.ts b/packages/astro/src/integrations/hooks.ts index c0b9604335b3..39d8ab69feb0 100644 --- a/packages/astro/src/integrations/hooks.ts +++ b/packages/astro/src/integrations/hooks.ts @@ -3,24 +3,23 @@ import type { AddressInfo } from 'node:net'; import { fileURLToPath } from 'node:url'; import { bold } from 'kleur/colors'; import type { InlineConfig, ViteDevServer } from 'vite'; -import type { - AstroAdapter, - AstroConfig, - AstroIntegration, - AstroRenderer, - AstroSettings, - ContentEntryType, - DataEntryType, - HookParameters, - RouteData, - RouteOptions, -} from '../@types/astro.js'; import type { SerializedSSRManifest } from '../core/app/types.js'; import type { PageBuildData } from '../core/build/types.js'; import { buildClientDirectiveEntrypoint } from '../core/client-directive/index.js'; import { mergeConfig } from '../core/config/index.js'; import type { AstroIntegrationLogger, Logger } from '../core/logger/core.js'; import { isServerLikeOutput } from '../core/util.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroConfig } from '../types/public/config.js'; +import type { ContentEntryType, DataEntryType } from '../types/public/content.js'; +import type { + AstroAdapter, + AstroIntegration, + AstroRenderer, + HookParameters, + RouteOptions, +} from '../types/public/integrations.js'; +import type { RouteData } from '../types/public/internal.js'; import { validateSupportedFeatures } from './features-validation.js'; async function withTakingALongTimeMsg({ @@ -198,10 +197,6 @@ export async function runHookConfigSetup({ addWatchFile: (path) => { updatedSettings.watchFiles.push(path instanceof URL ? fileURLToPath(path) : path); }, - addDevOverlayPlugin: (entrypoint) => { - // TODO add a deprecation warning in Astro 5. - hooks.addDevToolbarApp(entrypoint); - }, addDevToolbarApp: (entrypoint) => { updatedSettings.devToolbarApps.push(entrypoint); }, diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts index 413257faab97..86f4d018743a 100644 --- a/packages/astro/src/jsx/renderer.ts +++ b/packages/astro/src/jsx/renderer.ts @@ -1,11 +1,8 @@ -import type { AstroRenderer } from '../@types/astro.js'; -import { jsxTransformOptions } from './transform-options.js'; +import type { AstroRenderer } from '../types/public/integrations.js'; const renderer: AstroRenderer = { name: 'astro:jsx', serverEntrypoint: 'astro/jsx/server.js', - jsxImportSource: 'astro', - jsxTransformOptions, }; export default renderer; diff --git a/packages/astro/src/jsx/server.ts b/packages/astro/src/jsx/server.ts index 73b584baeaf7..bb71231c5813 100644 --- a/packages/astro/src/jsx/server.ts +++ b/packages/astro/src/jsx/server.ts @@ -1,7 +1,7 @@ -import type { NamedSSRLoadedRendererValue } from '../@types/astro.js'; import { AstroError, AstroUserError } from '../core/errors/errors.js'; import { AstroJSX, jsx } from '../jsx-runtime/index.js'; import { renderJSX } from '../runtime/server/jsx.js'; +import type { NamedSSRLoadedRendererValue } from '../types/public/internal.js'; const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); diff --git a/packages/astro/src/jsx/transform-options.ts b/packages/astro/src/jsx/transform-options.ts index ca1d50a6a131..e7405ddc0c2d 100644 --- a/packages/astro/src/jsx/transform-options.ts +++ b/packages/astro/src/jsx/transform-options.ts @@ -1,4 +1,4 @@ -import type { JSXTransformConfig } from '../@types/astro.js'; +import type { JSXTransformConfig } from '../types/astro.js'; /** * @deprecated This function is no longer used. Remove in Astro 5.0 diff --git a/packages/astro/src/preferences/index.ts b/packages/astro/src/preferences/index.ts index 2b92c5fb6cb5..7c8779b43f4e 100644 --- a/packages/astro/src/preferences/index.ts +++ b/packages/astro/src/preferences/index.ts @@ -1,11 +1,10 @@ -import type { AstroConfig } from '../@types/astro.js'; - import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; import dget from 'dlv'; +import type { AstroConfig } from '../types/public/config.js'; import { DEFAULT_PREFERENCES, type Preferences, type PublicPreferences } from './defaults.js'; import { PreferenceStore } from './store.js'; diff --git a/packages/astro/src/prefetch/vite-plugin-prefetch.ts b/packages/astro/src/prefetch/vite-plugin-prefetch.ts index d64c6d5008b9..560895b15bfb 100644 --- a/packages/astro/src/prefetch/vite-plugin-prefetch.ts +++ b/packages/astro/src/prefetch/vite-plugin-prefetch.ts @@ -1,5 +1,5 @@ import type * as vite from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; const virtualModuleId = 'astro:prefetch'; const resolvedVirtualModuleId = '\0' + virtualModuleId; diff --git a/packages/astro/src/prerender/routing.ts b/packages/astro/src/prerender/routing.ts index cbdddff5c8cb..888b012e0b9d 100644 --- a/packages/astro/src/prerender/routing.ts +++ b/packages/astro/src/prerender/routing.ts @@ -1,6 +1,7 @@ -import type { AstroSettings, ComponentInstance, RouteData } from '../@types/astro.js'; import { RedirectComponentInstance, routeIsRedirect } from '../core/redirects/index.js'; import { routeComparator } from '../core/routing/priority.js'; +import type { AstroSettings, ComponentInstance } from '../types/astro.js'; +import type { RouteData } from '../types/public/internal.js'; import type { DevPipeline } from '../vite-plugin-astro-server/pipeline.js'; import { getPrerenderStatus } from './metadata.js'; diff --git a/packages/astro/src/prerender/utils.ts b/packages/astro/src/prerender/utils.ts index 4097b66b1f6d..e34e0d5fd024 100644 --- a/packages/astro/src/prerender/utils.ts +++ b/packages/astro/src/prerender/utils.ts @@ -1,6 +1,6 @@ -import type { AstroConfig } from '../@types/astro.js'; import { getOutDirWithinCwd } from '../core/build/common.js'; import { isServerLikeOutput } from '../core/util.js'; +import type { AstroConfig } from '../types/public/config.js'; export function getPrerenderDefault(config: AstroConfig) { return config.output !== 'server'; diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts index e63667a12d6f..12ab602a255e 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts @@ -1,4 +1,4 @@ -import type { DevToolbarApp, DevToolbarMetadata } from '../../../../@types/astro.js'; +import type { DevToolbarApp, DevToolbarMetadata } from '../../../../types/public/toolbar.js'; import { type Icon, isDefinedIcon } from '../ui-library/icons.js'; import { colorForIntegration, iconForIntegration } from './utils/icons.js'; import { diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts index 6a6aba42d120..cc58411cf3c4 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts @@ -1,4 +1,4 @@ -import type { DevToolbarApp } from '../../../../../@types/astro.js'; +import type { DevToolbarApp } from '../../../../../types/public/toolbar.js'; import { settings } from '../../settings.js'; import type { DevToolbarHighlight } from '../../ui-library/highlight.js'; import { positionHighlight } from '../utils/highlight.js'; diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.ts index 38559e0f9adf..34adf4f01282 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.ts @@ -1,5 +1,5 @@ import { escape as escapeHTML } from 'html-escaper'; -import type { DevToolbarMetadata } from '../../../../../../@types/astro.js'; +import type { DevToolbarMetadata } from '../../../../../../types/public/toolbar.js'; import { attachTooltipToHighlight, createHighlight, diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts index 7ee42da84996..192e4509b504 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/settings.ts @@ -1,4 +1,4 @@ -import type { DevToolbarApp } from '../../../../@types/astro.js'; +import type { DevToolbarApp } from '../../../../types/public/toolbar.js'; import { type Settings, settings } from '../settings.js'; import { isValidPlacement, placements } from '../ui-library/window.js'; import { diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts index 2e56b0f244cf..fafc8e26d57e 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/xray.ts @@ -1,5 +1,5 @@ import { escape as escapeHTML } from 'html-escaper'; -import type { DevToolbarApp, DevToolbarMetadata } from '../../../../@types/astro.js'; +import type { DevToolbarApp, DevToolbarMetadata } from '../../../../types/public/toolbar.js'; import type { DevToolbarHighlight } from '../ui-library/highlight.js'; import { attachTooltipToHighlight, diff --git a/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts b/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts index 9731f3597fbb..86c616becb3a 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts @@ -1,6 +1,6 @@ // @ts-expect-error - This module is private and untyped import { loadDevToolbarApps } from 'astro:toolbar:internal'; -import type { ResolvedDevToolbarApp as DevToolbarAppDefinition } from '../../../@types/astro.js'; +import type { ResolvedDevToolbarApp as DevToolbarAppDefinition } from '../../../types/public/toolbar.js'; import { ToolbarAppEventTarget } from './helpers.js'; import { settings } from './settings.js'; import type { AstroDevToolbar, DevToolbarApp } from './toolbar.js'; diff --git a/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts b/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts index 08ea61cace5c..e24698d4337b 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/toolbar.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import type { ResolvedDevToolbarApp as DevToolbarAppDefinition } from '../../../@types/astro.js'; +import type { ResolvedDevToolbarApp as DevToolbarAppDefinition } from '../../../types/public/toolbar.js'; import { type ToolbarAppEventTarget, serverHelpers } from './helpers.js'; import { settings } from './settings.js'; import { type Icon, getIconElement, isDefinedIcon } from './ui-library/icons.js'; diff --git a/packages/astro/src/runtime/client/idle.ts b/packages/astro/src/runtime/client/idle.ts index 990d5da6ef10..e32b1a42f698 100644 --- a/packages/astro/src/runtime/client/idle.ts +++ b/packages/astro/src/runtime/client/idle.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro.js'; +import type { ClientDirective } from '../../types/public/integrations.js'; const idleDirective: ClientDirective = (load) => { const cb = async () => { diff --git a/packages/astro/src/runtime/client/load.ts b/packages/astro/src/runtime/client/load.ts index b603eecb3b49..98521181c528 100644 --- a/packages/astro/src/runtime/client/load.ts +++ b/packages/astro/src/runtime/client/load.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro.js'; +import type { ClientDirective } from '../../types/public/integrations.js'; const loadDirective: ClientDirective = async (load) => { const hydrate = await load(); diff --git a/packages/astro/src/runtime/client/media.ts b/packages/astro/src/runtime/client/media.ts index f894af31112d..0c6e497e3302 100644 --- a/packages/astro/src/runtime/client/media.ts +++ b/packages/astro/src/runtime/client/media.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro.js'; +import type { ClientDirective } from '../../types/public/integrations.js'; /** * Hydrate this component when a matching media query is found diff --git a/packages/astro/src/runtime/client/only.ts b/packages/astro/src/runtime/client/only.ts index 8e072b7a3fc0..c5fc488d4bd8 100644 --- a/packages/astro/src/runtime/client/only.ts +++ b/packages/astro/src/runtime/client/only.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro.js'; +import type { ClientDirective } from '../../types/public/integrations.js'; /** * Hydrate this component only on the client diff --git a/packages/astro/src/runtime/client/visible.ts b/packages/astro/src/runtime/client/visible.ts index 9be4d9b318a7..c7d858ffb0b4 100644 --- a/packages/astro/src/runtime/client/visible.ts +++ b/packages/astro/src/runtime/client/visible.ts @@ -1,4 +1,5 @@ -import type { ClientDirective, ClientVisibleOptions } from '../../@types/astro.js'; +import type { ClientVisibleOptions } from '../../types/public/elements.js'; +import type { ClientDirective } from '../../types/public/integrations.js'; /** * Hydrate this component when one of it's children becomes visible diff --git a/packages/astro/src/runtime/server/astro-component.ts b/packages/astro/src/runtime/server/astro-component.ts index 928d23ad82a5..20649b64dcb4 100644 --- a/packages/astro/src/runtime/server/astro-component.ts +++ b/packages/astro/src/runtime/server/astro-component.ts @@ -1,5 +1,5 @@ -import type { PropagationHint } from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; +import type { PropagationHint } from '../../types/public/internal.js'; import type { AstroComponentFactory } from './render/index.js'; function validateArgs(args: unknown[]): args is Parameters { diff --git a/packages/astro/src/runtime/server/astro-global.ts b/packages/astro/src/runtime/server/astro-global.ts index 5948c8ff3aff..74b32e331421 100644 --- a/packages/astro/src/runtime/server/astro-global.ts +++ b/packages/astro/src/runtime/server/astro-global.ts @@ -1,6 +1,6 @@ -import type { AstroGlobalPartial } from '../../@types/astro.js'; import { ASTRO_VERSION } from '../../core/constants.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; +import type { AstroGlobalPartial } from '../../types/public/context.js'; /** Create the Astro.glob() runtime function. */ function createAstroGlobFn() { diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index 900d604fd569..674d6209343f 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -1,13 +1,16 @@ import { bold } from 'kleur/colors'; -import type { APIContext, EndpointHandler } from '../../@types/astro.js'; import { REROUTABLE_STATUS_CODES, REROUTE_DIRECTIVE_HEADER } from '../../core/constants.js'; import { EndpointDidNotReturnAResponse } from '../../core/errors/errors-data.js'; import { AstroError } from '../../core/errors/errors.js'; import type { Logger } from '../../core/logger/core.js'; +import type { APIRoute } from '../../types/public/common.js'; +import type { APIContext } from '../../types/public/context.js'; /** Renders an endpoint request to completion, returning the body. */ export async function renderEndpoint( - mod: EndpointHandler, + mod: { + [method: string]: APIRoute; + }, context: APIContext, ssr: boolean, logger: Logger, diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts index ab6396566b5e..982ff9977ecb 100644 --- a/packages/astro/src/runtime/server/hydration.ts +++ b/packages/astro/src/runtime/server/hydration.ts @@ -1,10 +1,10 @@ +import { AstroError, AstroErrorData } from '../../core/errors/index.js'; import type { AstroComponentMetadata, SSRElement, SSRLoadedRenderer, SSRResult, -} from '../../@types/astro.js'; -import { AstroError, AstroErrorData } from '../../core/errors/index.js'; +} from '../../types/public/internal.js'; import { escapeHTML } from './escape.js'; import { serializeProps } from './serialize.js'; diff --git a/packages/astro/src/runtime/server/jsx.ts b/packages/astro/src/runtime/server/jsx.ts index 2491ab58946e..7280e216c31c 100644 --- a/packages/astro/src/runtime/server/jsx.ts +++ b/packages/astro/src/runtime/server/jsx.ts @@ -1,5 +1,5 @@ -import type { SSRResult } from '../../@types/astro.js'; import { AstroJSX, type AstroVNode, isVNode } from '../../jsx-runtime/index.js'; +import type { SSRResult } from '../../types/public/internal.js'; import { HTMLString, escapeHTML, diff --git a/packages/astro/src/runtime/server/render/astro/factory.ts b/packages/astro/src/runtime/server/render/astro/factory.ts index db319eb1aadd..dab33a031991 100644 --- a/packages/astro/src/runtime/server/render/astro/factory.ts +++ b/packages/astro/src/runtime/server/render/astro/factory.ts @@ -1,4 +1,4 @@ -import type { PropagationHint, SSRResult } from '../../../../@types/astro.js'; +import type { PropagationHint, SSRResult } from '../../../../types/public/internal.js'; import type { HeadAndContent } from './head-and-content.js'; import type { RenderTemplateResult } from './render-template.js'; diff --git a/packages/astro/src/runtime/server/render/astro/instance.ts b/packages/astro/src/runtime/server/render/astro/instance.ts index 3246a7e1b294..029231a28d6d 100644 --- a/packages/astro/src/runtime/server/render/astro/instance.ts +++ b/packages/astro/src/runtime/server/render/astro/instance.ts @@ -1,7 +1,7 @@ -import type { SSRResult } from '../../../../@types/astro.js'; import type { ComponentSlots } from '../slot.js'; import type { AstroComponentFactory } from './factory.js'; +import type { SSRResult } from '../../../../types/public/internal.js'; import { isPromise } from '../../util.js'; import { renderChild } from '../any.js'; import type { RenderDestination } from '../common.js'; diff --git a/packages/astro/src/runtime/server/render/astro/render.ts b/packages/astro/src/runtime/server/render/astro/render.ts index 41845b7b9e16..adc335495da1 100644 --- a/packages/astro/src/runtime/server/render/astro/render.ts +++ b/packages/astro/src/runtime/server/render/astro/render.ts @@ -1,5 +1,5 @@ -import type { RouteData, SSRResult } from '../../../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../../../core/errors/index.js'; +import type { RouteData, SSRResult } from '../../../../types/public/internal.js'; import { type RenderDestination, chunkToByteArray, chunkToString, encoder } from '../common.js'; import { promiseWithResolvers } from '../util.js'; import type { AstroComponentFactory } from './factory.js'; diff --git a/packages/astro/src/runtime/server/render/common.ts b/packages/astro/src/runtime/server/render/common.ts index 0845bdd65315..77f05dfccec6 100644 --- a/packages/astro/src/runtime/server/render/common.ts +++ b/packages/astro/src/runtime/server/render/common.ts @@ -1,6 +1,6 @@ -import type { SSRResult } from '../../../@types/astro.js'; import type { RenderInstruction } from './instruction.js'; +import type { SSRResult } from '../../../types/public/internal.js'; import type { HTMLBytes, HTMLString } from '../escape.js'; import { markHTMLString } from '../escape.js'; import { diff --git a/packages/astro/src/runtime/server/render/component.ts b/packages/astro/src/runtime/server/render/component.ts index 449f58fbcc7d..300911acdaca 100644 --- a/packages/astro/src/runtime/server/render/component.ts +++ b/packages/astro/src/runtime/server/render/component.ts @@ -1,9 +1,3 @@ -import type { - AstroComponentMetadata, - RouteData, - SSRLoadedRenderer, - SSRResult, -} from '../../../@types/astro.js'; import { createRenderInstruction } from './instruction.js'; import { clsx } from 'clsx'; @@ -17,6 +11,12 @@ import { type AstroComponentFactory, isAstroComponentFactory } from './astro/fac import { renderTemplate } from './astro/index.js'; import { createAstroComponentInstance } from './astro/instance.js'; +import type { + AstroComponentMetadata, + RouteData, + SSRLoadedRenderer, + SSRResult, +} from '../../../types/public/internal.js'; import { Fragment, type RenderDestination, diff --git a/packages/astro/src/runtime/server/render/dom.ts b/packages/astro/src/runtime/server/render/dom.ts index e2b194df3451..f92b4889a38f 100644 --- a/packages/astro/src/runtime/server/render/dom.ts +++ b/packages/astro/src/runtime/server/render/dom.ts @@ -1,5 +1,4 @@ -import type { SSRResult } from '../../../@types/astro.js'; - +import type { SSRResult } from '../../../types/public/internal.js'; import { markHTMLString } from '../escape.js'; import { renderSlotToString } from './slot.js'; import { toAttributeString } from './util.js'; diff --git a/packages/astro/src/runtime/server/render/head.ts b/packages/astro/src/runtime/server/render/head.ts index 49dd5abed14a..01f11f21e760 100644 --- a/packages/astro/src/runtime/server/render/head.ts +++ b/packages/astro/src/runtime/server/render/head.ts @@ -1,5 +1,4 @@ -import type { SSRResult } from '../../../@types/astro.js'; - +import type { SSRResult } from '../../../types/public/internal.js'; import { markHTMLString } from '../escape.js'; import type { MaybeRenderHeadInstruction, RenderHeadInstruction } from './instruction.js'; import { createRenderInstruction } from './instruction.js'; diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index 35a7ec789947..0e0bcf295ad8 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -1,7 +1,7 @@ -import type { RouteData, SSRResult } from '../../../@types/astro.js'; import { type NonAstroPageComponent, renderComponentToString } from './component.js'; import type { AstroComponentFactory } from './index.js'; +import type { RouteData, SSRResult } from '../../../types/public/internal.js'; import { isAstroComponentFactory } from './astro/index.js'; import { renderToAsyncIterable, renderToReadableStream, renderToString } from './astro/render.js'; import { encoder } from './common.js'; diff --git a/packages/astro/src/runtime/server/render/script.ts b/packages/astro/src/runtime/server/render/script.ts index 1b9c5ce1b37e..6d9283790a06 100644 --- a/packages/astro/src/runtime/server/render/script.ts +++ b/packages/astro/src/runtime/server/render/script.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../../@types/astro.js'; +import type { SSRResult } from '../../../types/public/internal.js'; import { markHTMLString } from '../escape.js'; /** diff --git a/packages/astro/src/runtime/server/render/server-islands.ts b/packages/astro/src/runtime/server/render/server-islands.ts index 0a072113447b..fce702364df9 100644 --- a/packages/astro/src/runtime/server/render/server-islands.ts +++ b/packages/astro/src/runtime/server/render/server-islands.ts @@ -1,5 +1,5 @@ -import type { SSRResult } from '../../../@types/astro.js'; import { encryptString } from '../../../core/encryption.js'; +import type { SSRResult } from '../../../types/public/internal.js'; import { renderChild } from './any.js'; import type { RenderInstance } from './common.js'; import { type ComponentSlots, renderSlotToString } from './slot.js'; diff --git a/packages/astro/src/runtime/server/render/slot.ts b/packages/astro/src/runtime/server/render/slot.ts index d02a32d82b5d..0df37440622c 100644 --- a/packages/astro/src/runtime/server/render/slot.ts +++ b/packages/astro/src/runtime/server/render/slot.ts @@ -1,7 +1,7 @@ -import type { SSRResult } from '../../../@types/astro.js'; import { renderTemplate } from './astro/render-template.js'; import type { RenderInstruction } from './instruction.js'; +import type { SSRResult } from '../../../types/public/internal.js'; import { HTMLString, markHTMLString, unescapeHTML } from '../escape.js'; import { renderChild } from './any.js'; import { type RenderDestination, type RenderInstance, chunkToString } from './common.js'; diff --git a/packages/astro/src/runtime/server/render/tags.ts b/packages/astro/src/runtime/server/render/tags.ts index 093c51a3c46e..baba11a5b0d1 100644 --- a/packages/astro/src/runtime/server/render/tags.ts +++ b/packages/astro/src/runtime/server/render/tags.ts @@ -1,5 +1,5 @@ -import type { SSRElement, SSRResult } from '../../../@types/astro.js'; import type { StylesheetAsset } from '../../../core/app/types.js'; +import type { SSRElement, SSRResult } from '../../../types/public/internal.js'; import { renderElement } from './util.js'; export function renderScriptElement({ props, children }: SSRElement) { diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 019bf9a40828..19ac2f2b1928 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -1,7 +1,7 @@ -import type { SSRElement } from '../../../@types/astro.js'; import type { RenderDestination, RenderDestinationChunk, RenderFunction } from './common.js'; import { clsx } from 'clsx'; +import type { SSRElement } from '../../../types/public/internal.js'; import { HTMLString, markHTMLString } from '../escape.js'; export const voidElementNames = diff --git a/packages/astro/src/runtime/server/scripts.ts b/packages/astro/src/runtime/server/scripts.ts index 84f2dcd525d8..ca9cad1fb186 100644 --- a/packages/astro/src/runtime/server/scripts.ts +++ b/packages/astro/src/runtime/server/scripts.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../@types/astro.js'; +import type { SSRResult } from '../../types/public/internal.js'; import islandScriptDev from './astro-island.prebuilt-dev.js'; import islandScript from './astro-island.prebuilt.js'; diff --git a/packages/astro/src/runtime/server/serialize.ts b/packages/astro/src/runtime/server/serialize.ts index 522b05256601..6afe91917959 100644 --- a/packages/astro/src/runtime/server/serialize.ts +++ b/packages/astro/src/runtime/server/serialize.ts @@ -1,5 +1,5 @@ -import type { AstroComponentMetadata } from '../../@types/astro.js'; import type { ValueOf } from '../../type-utils.js'; +import type { AstroComponentMetadata } from '../../types/public/internal.js'; const PROP_TYPE = { Value: 0, diff --git a/packages/astro/src/runtime/server/transition.ts b/packages/astro/src/runtime/server/transition.ts index 8887d3dae4ed..4baae442afb6 100644 --- a/packages/astro/src/runtime/server/transition.ts +++ b/packages/astro/src/runtime/server/transition.ts @@ -1,12 +1,12 @@ import cssesc from 'cssesc'; +import { fade, slide } from '../../transitions/index.js'; +import type { SSRResult } from '../../types/public/internal.js'; import type { - SSRResult, TransitionAnimation, TransitionAnimationPair, TransitionAnimationValue, TransitionDirectionalAnimations, -} from '../../@types/astro.js'; -import { fade, slide } from '../../transitions/index.js'; +} from '../../types/public/view-transitions.js'; import { markHTMLString } from './escape.js'; const transitionNameMap = new WeakMap(); diff --git a/packages/astro/src/toolbar/index.ts b/packages/astro/src/toolbar/index.ts index bd05e4417447..78d7158b20af 100644 --- a/packages/astro/src/toolbar/index.ts +++ b/packages/astro/src/toolbar/index.ts @@ -1,4 +1,4 @@ -import type { DevToolbarApp } from '../@types/astro.js'; +import type { DevToolbarApp } from '../types/public/toolbar.js'; export function defineToolbarApp(app: DevToolbarApp) { return app; diff --git a/packages/astro/src/toolbar/vite-plugin-dev-toolbar.ts b/packages/astro/src/toolbar/vite-plugin-dev-toolbar.ts index 32c91752f30d..d4d0510e69ce 100644 --- a/packages/astro/src/toolbar/vite-plugin-dev-toolbar.ts +++ b/packages/astro/src/toolbar/vite-plugin-dev-toolbar.ts @@ -1,7 +1,7 @@ import type * as vite from 'vite'; -import type { AstroPluginOptions } from '../@types/astro.js'; import { telemetry } from '../events/index.js'; import { eventAppToggled } from '../events/toolbar.js'; +import type { AstroPluginOptions } from '../types/astro.js'; const PRIVATE_VIRTUAL_MODULE_ID = 'astro:toolbar:internal'; const resolvedPrivateVirtualModuleId = '\0' + PRIVATE_VIRTUAL_MODULE_ID; diff --git a/packages/astro/src/transitions/index.ts b/packages/astro/src/transitions/index.ts index d87052f2daf2..05bfb0972964 100644 --- a/packages/astro/src/transitions/index.ts +++ b/packages/astro/src/transitions/index.ts @@ -1,4 +1,8 @@ -import type { TransitionAnimationPair, TransitionDirectionalAnimations } from '../@types/astro.js'; +import type { + TransitionAnimationPair, + TransitionDirectionalAnimations, +} from '../types/public/view-transitions.js'; + export { createAnimationScope } from '../runtime/server/transition.js'; const EASE_IN_OUT_QUART = 'cubic-bezier(0.76, 0, 0.24, 1)'; diff --git a/packages/astro/src/transitions/vite-plugin-transitions.ts b/packages/astro/src/transitions/vite-plugin-transitions.ts index d88c96f8919f..56f086a06a36 100644 --- a/packages/astro/src/transitions/vite-plugin-transitions.ts +++ b/packages/astro/src/transitions/vite-plugin-transitions.ts @@ -1,5 +1,5 @@ import type * as vite from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; const virtualModuleId = 'astro:transitions'; const resolvedVirtualModuleId = '\0' + virtualModuleId; diff --git a/packages/astro/src/types/README.md b/packages/astro/src/types/README.md new file mode 100644 index 000000000000..10331210628e --- /dev/null +++ b/packages/astro/src/types/README.md @@ -0,0 +1,5 @@ +# `types/` + +In this folder rest the types that are used throughout Astro. Typically folders for corresponding features will have a corresponding `types.ts` file in their folder. For example, the `src/assets/types.ts` contain the types for `astro:assets`. However this folder can be useful for types that are used across multiple features, or generally don't fit in any other folder. + +This folder additionally contain a `public` folder, which contains types that are exposed to users one way or another. Remember that these types are part of the public API, and as such follow the same semver contract as the rest of Astro. diff --git a/packages/astro/src/types/astro.ts b/packages/astro/src/types/astro.ts new file mode 100644 index 000000000000..6aa79a959c13 --- /dev/null +++ b/packages/astro/src/types/astro.ts @@ -0,0 +1,93 @@ +import type { SSRManifest } from '../core/app/types.js'; +import type { AstroTimer } from '../core/config/timer.js'; +import type { TSConfig } from '../core/config/tsconfig.js'; +import type { Logger } from '../core/logger/core.js'; +import type { AstroPreferences } from '../preferences/index.js'; +import type { AstroComponentFactory } from '../runtime/server/index.js'; +import type { GetStaticPathsOptions, GetStaticPathsResult } from './public/common.js'; +import type { AstroConfig } from './public/config.js'; +import type { ContentEntryType, DataEntryType } from './public/content.js'; +import type { + AstroAdapter, + AstroRenderer, + InjectedRoute, + InjectedScriptStage, + InjectedType, + ResolvedInjectedRoute, +} from './public/integrations.js'; +import type { RouteData } from './public/internal.js'; +import type { DevToolbarAppEntry } from './public/toolbar.js'; + +export type SerializedRouteData = Omit< + RouteData, + 'generate' | 'pattern' | 'redirectRoute' | 'fallbackRoutes' +> & { + generate: undefined; + pattern: string; + redirectRoute: SerializedRouteData | undefined; + fallbackRoutes: SerializedRouteData[]; + _meta: { + trailingSlash: AstroConfig['trailingSlash']; + }; +}; + +export interface AstroSettings { + config: AstroConfig; + adapter: AstroAdapter | undefined; + preferences: AstroPreferences; + injectedRoutes: InjectedRoute[]; + resolvedInjectedRoutes: ResolvedInjectedRoute[]; + pageExtensions: string[]; + contentEntryTypes: ContentEntryType[]; + dataEntryTypes: DataEntryType[]; + renderers: AstroRenderer[]; + scripts: { + stage: InjectedScriptStage; + content: string; + }[]; + /** + * Map of directive name (e.g. `load`) to the directive script code + */ + clientDirectives: Map; + devToolbarApps: (DevToolbarAppEntry | string)[]; + middlewares: { pre: string[]; post: string[] }; + tsConfig: TSConfig | undefined; + tsConfigPath: string | undefined; + watchFiles: string[]; + timer: AstroTimer; + dotAstroDir: URL; + /** + * Latest version of Astro, will be undefined if: + * - unable to check + * - the user has disabled the check + * - the check has not completed yet + * - the user is on the latest version already + */ + latestAstroVersion: string | undefined; + serverIslandMap: NonNullable; + serverIslandNameMap: NonNullable; + injectedTypes: Array; +} + +/** Generic interface for a component (Astro, Svelte, React, etc.) */ +export interface ComponentInstance { + default: AstroComponentFactory; + css?: string[]; + partial?: boolean; + prerender?: boolean; + getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult; +} + +export type JSXTransformConfig = Pick< + babel.TransformOptions, + 'presets' | 'plugins' | 'inputSourceMap' +>; + +export interface ManifestData { + routes: RouteData[]; +} + +export interface AstroPluginOptions { + settings: AstroSettings; + logger: Logger; +} diff --git a/packages/astro/src/types/public/common.ts b/packages/astro/src/types/public/common.ts new file mode 100644 index 000000000000..4bb94f5cad5a --- /dev/null +++ b/packages/astro/src/types/public/common.ts @@ -0,0 +1,176 @@ +import type { OmitIndexSignature, Simplify } from '../../type-utils.js'; +import type { APIContext } from './context.js'; + +/** + * getStaticPaths() options + * + * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) + */ +export interface GetStaticPathsOptions { + paginate: PaginateFunction; +} + +export type GetStaticPathsItem = { + params: { [K in keyof Params]: Params[K] | number }; + props?: Props; +}; +export type GetStaticPathsResult = GetStaticPathsItem[]; +export type GetStaticPathsResultKeyed = GetStaticPathsResult & { + keyed: Map; +}; + +/** + * Return an array of pages to generate for a [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes). (**SSG Only**) + * + * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) + */ +export type GetStaticPaths = ( + options: GetStaticPathsOptions, +) => Promise | GetStaticPathsResult; + +/** + * paginate() Options + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#paginate) + */ +export interface PaginateOptions { + /** the number of items per-page (default: `10`) */ + pageSize?: number; + /** key: value object of page params (ex: `{ tag: 'javascript' }`) */ + params?: PaginateParams; + /** object of props to forward to `page` result */ + props?: PaginateProps; +} + +/** + * Represents a single page of data in a paginated collection + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#the-pagination-page-prop) + */ +export interface Page { + /** result */ + data: T[]; + /** metadata */ + /** the count of the first item on the page, starting from 0 */ + start: number; + /** the count of the last item on the page, starting from 0 */ + end: number; + /** total number of results */ + total: number; + /** the current page number, starting from 1 */ + currentPage: number; + /** number of items per page (default: 10) */ + size: number; + /** number of last page */ + lastPage: number; + url: { + /** url of the current page */ + current: string; + /** url of the previous page (if there is one) */ + prev: string | undefined; + /** url of the next page (if there is one) */ + next: string | undefined; + /** url of the first page (if the current page is not the first page) */ + first: string | undefined; + /** url of the next page (if the current page in not the last page) */ + last: string | undefined; + }; +} + +export type PaginateFunction = < + PaginateData, + AdditionalPaginateProps extends Props, + AdditionalPaginateParams extends Params, +>( + data: PaginateData[], + args?: PaginateOptions, +) => { + params: Simplify< + { + page: string | undefined; + } & OmitIndexSignature + >; + props: Simplify< + { + page: Page; + } & OmitIndexSignature + >; +}[]; + +export type APIRoute< + Props extends Record = Record, + APIParams extends Record = Record, +> = (context: APIContext) => Response | Promise; + +export type RewritePayload = string | URL | Request; + +export type MiddlewareNext = (rewritePayload?: RewritePayload) => Promise; +export type MiddlewareHandler = ( + context: APIContext, + next: MiddlewareNext, +) => Promise | Response | Promise | void; + +/** + * Infers the shape of the `params` property returned by `getStaticPaths()`. + * + * @example + * ```ts + * import type { GetStaticPaths } from 'astro'; + * + * export const getStaticPaths = (() => { + * return results.map((entry) => ({ + * params: { slug: entry.slug }, + * })); + * }) satisfies GetStaticPaths; + * + * type Params = InferGetStaticParamsType; + * // ^? { slug: string; } + * + * const { slug } = Astro.params as Params; + * ``` + */ +export type InferGetStaticParamsType = T extends ( + opts?: GetStaticPathsOptions, +) => infer R | Promise + ? R extends Array + ? U extends { params: infer P } + ? P + : never + : never + : never; + +/** + * Infers the shape of the `props` property returned by `getStaticPaths()`. + * + * @example + * ```ts + * import type { GetStaticPaths } from 'astro'; + * + * export const getStaticPaths = (() => { + * return results.map((entry) => ({ + * params: { slug: entry.slug }, + * props: { + * propA: true, + * propB: 42 + * }, + * })); + * }) satisfies GetStaticPaths; + * + * type Props = InferGetStaticPropsType; + * // ^? { propA: boolean; propB: number; } + * + * const { propA, propB } = Astro.props; + * ``` + */ +export type InferGetStaticPropsType = T extends ( + opts: GetStaticPathsOptions, +) => infer R | Promise + ? R extends Array + ? U extends { props: infer P } + ? P + : never + : never + : never; + +export type Params = Record; +export type Props = Record; diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/types/public/config.ts similarity index 58% rename from packages/astro/src/@types/astro.ts rename to packages/astro/src/types/public/config.ts index a10ad5126226..178b9edf7c96 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/types/public/config.ts @@ -1,408 +1,38 @@ -import type { OutgoingHttpHeaders } from 'node:http'; -import type { AddressInfo } from 'node:net'; import type { - MarkdownHeading, - MarkdownVFile, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig, } from '@astrojs/markdown-remark'; -import type * as babel from '@babel/core'; -import type * as rollup from 'rollup'; -import type * as vite from 'vite'; -import type { - ActionAccept, - ActionClient, - ActionInputSchema, - ActionReturnType, -} from '../actions/runtime/virtual/server.js'; -import type { RemotePattern } from '../assets/utils/remotePattern.js'; -import type { DataEntry, RenderedContent } from '../content/data-store.js'; -import type { AssetsPrefix, SSRManifest, SerializedSSRManifest } from '../core/app/types.js'; -import type { PageBuildData } from '../core/build/types.js'; -import type { AstroConfigType } from '../core/config/index.js'; -import type { AstroTimer } from '../core/config/timer.js'; -import type { TSConfig } from '../core/config/tsconfig.js'; -import type { AstroCookies } from '../core/cookies/index.js'; -import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js'; -import type { EnvSchema } from '../env/schema.js'; -import type { getToolbarServerCommunicationHelpers } from '../integrations/hooks.js'; -import type { AstroPreferences } from '../preferences/index.js'; -import type { - ToolbarAppEventTarget, - ToolbarServerHelpers, -} from '../runtime/client/dev-toolbar/helpers.js'; -import type { AstroDevToolbar, DevToolbarCanvas } from '../runtime/client/dev-toolbar/toolbar.js'; -import type { Icon } from '../runtime/client/dev-toolbar/ui-library/icons.js'; -import type { - DevToolbarBadge, - DevToolbarButton, - DevToolbarCard, - DevToolbarHighlight, - DevToolbarIcon, - DevToolbarRadioCheckbox, - DevToolbarSelect, - DevToolbarToggle, - DevToolbarTooltip, - DevToolbarWindow, -} from '../runtime/client/dev-toolbar/ui-library/index.js'; -import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server/index.js'; -import type { - TransitionBeforePreparationEvent, - TransitionBeforeSwapEvent, -} from '../transitions/events.js'; -import type { DeepPartial, OmitIndexSignature, Simplify } from '../type-utils.js'; -import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js'; - -export type { AstroIntegrationLogger, ToolbarServerHelpers }; - -export type { - MarkdownHeading, - RehypePlugins, - RemarkPlugins, - ShikiConfig, -} from '@astrojs/markdown-remark'; -export type { - ExternalImageService, - ImageService, - LocalImageService, -} from '../assets/services/service.js'; -export type { - GetImageResult, - ImageInputFormat, - ImageMetadata, - ImageOutputFormat, - ImageQuality, - ImageQualityPreset, - ImageTransform, - UnresolvedImageTransform, -} from '../assets/types.js'; -export type { RemotePattern } from '../assets/utils/remotePattern.js'; -export type { AssetsPrefix, SSRManifest } from '../core/app/types.js'; -export type { - AstroCookieGetOptions, - AstroCookieSetOptions, - AstroCookies, -} from '../core/cookies/index.js'; - -export interface AstroBuiltinProps { - 'client:load'?: boolean; - 'client:idle'?: boolean; - 'client:media'?: string; - 'client:visible'?: ClientVisibleOptions | boolean; - 'client:only'?: boolean | string; - 'server:defer'?: boolean; -} - -export type ClientVisibleOptions = Pick; - -export interface TransitionAnimation { - name: string; // The name of the keyframe - delay?: number | string; - duration?: number | string; - easing?: string; - fillMode?: string; - direction?: string; -} - -export interface TransitionAnimationPair { - old: TransitionAnimation | TransitionAnimation[]; - new: TransitionAnimation | TransitionAnimation[]; -} - -export interface TransitionDirectionalAnimations { - forwards: TransitionAnimationPair; - backwards: TransitionAnimationPair; -} - -export type TransitionAnimationValue = - | 'initial' - | 'slide' - | 'fade' - | 'none' - | TransitionDirectionalAnimations; - -// Allow users to extend this for astro-jsx.d.ts - -// eslint-disable-next-line @typescript-eslint/no-empty-object-type -export interface AstroClientDirectives {} - -export interface AstroBuiltinAttributes { - 'class:list'?: - | Record - | Record - | Iterable - | Iterable - | string; - 'set:html'?: any; - 'set:text'?: any; - 'is:raw'?: boolean; - 'transition:animate'?: TransitionAnimationValue; - 'transition:name'?: string; - 'transition:persist'?: boolean | string; -} - -export interface AstroDefineVarsAttribute { - 'define:vars'?: any; -} - -export interface AstroStyleAttributes { - 'is:global'?: boolean; - 'is:inline'?: boolean; -} - -export interface AstroScriptAttributes { - 'is:inline'?: boolean; -} - -export interface AstroSlotAttributes { - 'is:inline'?: boolean; -} +import type { OutgoingHttpHeaders } from 'node:http'; +import type { UserConfig as OriginalViteUserConfig, SSROptions as ViteSSROptions } from 'vite'; +import type { RemotePattern } from '../../assets/utils/remotePattern.js'; +import type { AssetsPrefix } from '../../core/app/types.js'; +import type { AstroConfigType } from '../../core/config/schema.js'; +import type { Logger, LoggerLevel } from '../../core/logger/core.js'; +import type { EnvSchema } from '../../env/schema.js'; +import type { AstroIntegration, RoutePriorityOverride } from './integrations.js'; -export interface AstroComponentMetadata { - displayName: string; - hydrate?: 'load' | 'idle' | 'visible' | 'media' | 'only'; - hydrateArgs?: any; - componentUrl?: string; - componentExport?: { value: string; namespace?: boolean }; - astroStaticSlot: true; -} +export type Locales = (string | { codes: string[]; path: string })[]; -/** The flags supported by the Astro CLI */ -export interface CLIFlags { - root?: string; - site?: string; - base?: string; - host?: string | boolean; - port?: number; - config?: string; - open?: string | boolean; +export interface ImageServiceConfig = Record> { + entrypoint: 'astro/assets/services/sharp' | 'astro/assets/services/squoosh' | (string & {}); + config?: T; } -/** - * Astro global available in all contexts in .astro files - * - * [Astro reference](https://docs.astro.build/reference/api-reference/#astro-global) - */ -export interface AstroGlobal< - Props extends Record = Record, - Self = AstroComponentFactory, - Params extends Record = Record, -> extends AstroGlobalPartial, - AstroSharedContext { - /** - * A full URL object of the request URL. - * Equivalent to: `new URL(Astro.request.url)` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#url) - */ - url: AstroSharedContext['url']; - /** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) - * - * Example usage: - * ```astro - * --- - * export async function getStaticPaths() { - * return [ - * { params: { id: '1' } }, - * ]; - * } - * - * const { id } = Astro.params; - * --- - *

{id}

- * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroparams) - */ - params: AstroSharedContext['params']; - /** List of props passed to this component - * - * A common way to get specific props is through [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment), ex: - * ```typescript - * const { name } = Astro.props - * ``` - * - * [Astro reference](https://docs.astro.build/en/basics/astro-components/#component-props) - */ - props: AstroSharedContext['props']; - /** Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object - * - * For example, to get a URL object of the current URL, you can use: - * ```typescript - * const url = new URL(Astro.request.url); - * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrorequest) - */ - request: Request; - /** Information about the outgoing response. This is a standard [ResponseInit](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#init) object - * - * For example, to change the status code you can set a different status on this object: - * ```typescript - * Astro.response.status = 404; - * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroresponse) - */ - response: ResponseInit & { - readonly headers: Headers; - }; - /** - * Get an action result on the server when using a form POST. - * Expects the action function as a parameter. - * Returns a type-safe result with the action data when - * a matching POST request is received - * and `undefined` otherwise. - * - * Example usage: - * - * ```typescript - * import { actions } from 'astro:actions'; - * - * const result = await Astro.getActionResult(actions.myAction); - * ``` - */ - getActionResult: AstroSharedContext['getActionResult']; - /** - * Call an Action directly from an Astro page or API endpoint. - * Expects the action function as the first parameter, - * and the type-safe action input as the second parameter. - * Returns a Promise with the action result. - * - * Example usage: - * - * ```typescript - * import { actions } from 'astro:actions'; - * - * const result = await Astro.callAction(actions.getPost, { postId: 'test' }); - * ``` - */ - callAction: AstroSharedContext['callAction']; - /** Redirect to another page - * - * Example usage: - * ```typescript - * if(!isLoggedIn) { - * return Astro.redirect('/login'); - * } - * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroredirect) - */ - redirect: AstroSharedContext['redirect']; - /** - * It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted - * by the rewritten URL passed as argument. - * - * ## Example - * - * ```js - * if (pageIsNotEnabled) { - * return Astro.rewrite('/fallback-page') - * } - * ``` - */ - rewrite: AstroSharedContext['rewrite']; - /** - * The element allows a component to reference itself recursively. - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroself) - */ - self: Self; - /** Utility functions for modifying an Astro component’s slotted children - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots) - */ - slots: Record & { - /** - * Check whether content for this slot name exists - * - * Example usage: - * ```typescript - * if (Astro.slots.has('default')) { - * // Do something... - * } - * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots) - */ - has(slotName: string): boolean; - /** - * Asynchronously renders this slot and returns a string - * - * Example usage: - * ```astro - * --- - * let html: string = ''; - * if (Astro.slots.has('default')) { - * html = await Astro.slots.render('default') - * } - * --- - * - * ``` - * - * A second parameter can be used to pass arguments to a slotted callback - * - * Example usage: - * ```astro - * --- - * html = await Astro.slots.render('default', ["Hello", "World"]) - * --- - * ``` - * Each item in the array will be passed as an argument that you can use like so: - * ```astro - * - * {(hello, world) =>
{hello}, {world}!
} - *
- * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots) - */ - render(slotName: string, args?: any[]): Promise; - }; -} +export type RuntimeMode = 'development' | 'production'; -/** Union type of supported markdown file extensions */ -type MarkdowFileExtension = (typeof SUPPORTED_MARKDOWN_FILE_EXTENSIONS)[number]; +export type ValidRedirectStatus = 300 | 301 | 302 | 303 | 304 | 307 | 308; -export interface AstroGlobalPartial { - /** - * Fetch local files into your static site setup - * - * Example usage: - * ```typescript - * const posts = await Astro.glob('../pages/post/*.md'); - * ``` - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroglob) - */ - glob(globStr: `${any}.astro`): Promise; - glob>( - globStr: `${any}${MarkdowFileExtension}`, - ): Promise[]>; - glob>(globStr: `${any}.mdx`): Promise[]>; - glob>(globStr: string): Promise; - /** - * Returns a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object built from the [site](https://docs.astro.build/en/reference/configuration-reference/#site) config option - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrosite) - */ - site: URL | undefined; - /** - * Returns a string with the current version of Astro. - * - * Useful for using `` or crediting Astro in a site footer. - * - * [HTML Specification for `generator`](https://html.spec.whatwg.org/multipage/semantics.html#meta-generator) - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrogenerator) - */ - generator: string; -} +export type RedirectConfig = + | string + | { + status: ValidRedirectStatus; + destination: string; + priority?: RoutePriorityOverride; + }; -type ServerConfig = { +export type ServerConfig = { /** * @name server.host * @type {string | boolean} @@ -456,14 +86,17 @@ type ServerConfig = { open?: string | boolean; }; -export interface ViteUserConfig extends vite.UserConfig { - ssr?: vite.SSROptions; +export interface ViteUserConfig extends OriginalViteUserConfig { + ssr?: ViteSSROptions; } -export interface ImageServiceConfig = Record> { - entrypoint: 'astro/assets/services/sharp' | 'astro/assets/services/squoosh' | (string & {}); - config?: T; -} +// NOTE(fks): We choose to keep our hand-generated AstroUserConfig interface so that +// we can add JSDoc-style documentation and link to the definition file in our repo. +// However, Zod comes with the ability to auto-generate AstroConfig from the schema +// above. If we ever get to the point where we no longer need the dedicated type, +// consider replacing it with the following lines: +// export interface AstroUserConfig extends z.input { +// } /** * Astro User Config @@ -2407,58 +2040,6 @@ export interface AstroUserConfig { }; } -// NOTE(fks): We choose to keep our hand-generated AstroUserConfig interface so that -// we can add JSDoc-style documentation and link to the definition file in our repo. -// However, Zod comes with the ability to auto-generate AstroConfig from the schema -// above. If we ever get to the point where we no longer need the dedicated -// @types/config.ts file, consider replacing it with the following lines: -// -// export interface AstroUserConfig extends z.input { -// } - -/** - * IDs for different stages of JS script injection: - * - "before-hydration": Imported client-side, before the hydration script runs. Processed & resolved by Vite. - * - "head-inline": Injected into a script tag in the `` of every page. Not processed or resolved by Vite. - * - "page": Injected into the JavaScript bundle of every page. Processed & resolved by Vite. - * - "page-ssr": Injected into the frontmatter of every Astro page. Processed & resolved by Vite. - */ -export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' | 'page-ssr'; - -/** - * IDs for different priorities of injected routes and redirects: - * - "normal": Merge with discovered file-based project routes, behaving the same as if the route - * was defined as a file in the project. - * - "legacy": Use the old ordering of routes. Inject routes will override any file-based project route, - * and redirects will be overridden by any project route on conflict. - */ -export type RoutePriorityOverride = 'normal' | 'legacy'; - -export interface InjectedRoute { - pattern: string; - entrypoint: string; - prerender?: boolean; -} - -export interface ResolvedInjectedRoute extends InjectedRoute { - resolvedEntryPoint?: URL; -} - -export interface RouteOptions { - /** - * The path to this route relative to the project root. The slash is normalized as forward slash - * across all OS. - * @example "src/pages/blog/[...slug].astro" - */ - readonly component: string; - /** - * Whether this route should be prerendered. If the route has an explicit `prerender` export, - * the value will be passed here. Otherwise, it's undefined and will fallback to a prerender - * default depending on the `output` option. - */ - prerender?: boolean; -} - /** * Resolved Astro Config * Config with user settings along with all defaults filled in. @@ -2510,1230 +2091,10 @@ export interface AstroInlineOnlyConfig { logger?: Logger; } -export type ContentEntryModule = { - id: string; - collection: string; - slug: string; - body: string; - data: Record; - _internal: { - rawData: string; - filePath: string; - }; -}; - -export type DataEntryModule = { - id: string; - collection: string; - data: Record; - _internal: { - rawData: string; - filePath: string; - }; -}; - -export type ContentEntryRenderFuction = (entry: DataEntry) => Promise; - -export interface ContentEntryType { - extensions: string[]; - getEntryInfo(params: { - fileUrl: URL; - contents: string; - }): GetContentEntryInfoReturnType | Promise; - getRenderModule?( - this: rollup.PluginContext, - params: { - contents: string; - fileUrl: URL; - viteId: string; - }, - ): rollup.LoadResult | Promise; - contentModuleTypes?: string; - getRenderFunction?(settings: AstroSettings): Promise; - - /** - * Handle asset propagation for rendered content to avoid bleed. - * Ex. MDX content can import styles and scripts, so `handlePropagation` should be true. - * @default true - */ - handlePropagation?: boolean; -} - -type GetContentEntryInfoReturnType = { - data: Record; - /** - * Used for error hints to point to correct line and location - * Should be the untouched data as read from the file, - * including newlines - */ - rawData: string; - body: string; - slug: string; -}; - -export interface DataEntryType { - extensions: string[]; - getEntryInfo(params: { - fileUrl: URL; - contents: string; - }): GetDataEntryInfoReturnType | Promise; -} - -export type GetDataEntryInfoReturnType = { data: Record; rawData?: string }; - -export interface AstroAdapterFeatures { - /** - * Creates an edge function that will communiate with the Astro middleware - */ - edgeMiddleware: boolean; - /** - * SSR only. Each route becomes its own function/file. - */ - functionPerRoute: boolean; -} - -export interface InjectedType { - filename: string; - content: string; -} - -export interface AstroSettings { - config: AstroConfig; - adapter: AstroAdapter | undefined; - preferences: AstroPreferences; - injectedRoutes: InjectedRoute[]; - resolvedInjectedRoutes: ResolvedInjectedRoute[]; - pageExtensions: string[]; - contentEntryTypes: ContentEntryType[]; - dataEntryTypes: DataEntryType[]; - renderers: AstroRenderer[]; - scripts: { - stage: InjectedScriptStage; - content: string; - }[]; - /** - * Map of directive name (e.g. `load`) to the directive script code - */ - clientDirectives: Map; - devToolbarApps: (DevToolbarAppEntry | string)[]; - middlewares: { pre: string[]; post: string[] }; - tsConfig: TSConfig | undefined; - tsConfigPath: string | undefined; - watchFiles: string[]; - timer: AstroTimer; - dotAstroDir: URL; - /** - * Latest version of Astro, will be undefined if: - * - unable to check - * - the user has disabled the check - * - the check has not completed yet - * - the user is on the latest version already - */ - latestAstroVersion: string | undefined; - serverIslandMap: NonNullable; - serverIslandNameMap: NonNullable; - injectedTypes: Array; -} - -export type AsyncRendererComponentFn = ( - Component: any, - props: any, - slots: Record, - metadata?: AstroComponentMetadata, -) => Promise; - -/** Generic interface for a component (Astro, Svelte, React, etc.) */ -export interface ComponentInstance { - default: AstroComponentFactory; - css?: string[]; - partial?: boolean; - prerender?: boolean; - getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult; -} - -export interface AstroInstance { - file: string; - url: string | undefined; - default: AstroComponentFactory; -} - -export interface MarkdownInstance> { - frontmatter: T; - /** Absolute file path (e.g. `/home/user/projects/.../file.md`) */ - file: string; - /** Browser URL for files under `/src/pages` (e.g. `/en/guides/markdown-content`) */ - url: string | undefined; - /** Component to render content in `.astro` files. Usage: `` */ - Content: AstroComponentFactory; - /** raw Markdown file content, excluding layout HTML and YAML frontmatter */ - rawContent(): string; - /** Markdown file compiled to HTML, excluding layout HTML */ - compiledContent(): string; - /** List of headings (h1 -> h6) with associated metadata */ - getHeadings(): MarkdownHeading[]; - default: AstroComponentFactory; -} - -type MD = MarkdownInstance>; - -export type MDXInstance> = Omit< - MarkdownInstance, - 'rawContent' | 'compiledContent' ->; - -export interface MarkdownLayoutProps> { - frontmatter: { - file: MarkdownInstance['file']; - url: MarkdownInstance['url']; - } & T; - file: MarkdownInstance['file']; - url: MarkdownInstance['url']; - headings: MarkdownHeading[]; - rawContent: MarkdownInstance['rawContent']; - compiledContent: MarkdownInstance['compiledContent']; -} - -export type MDXLayoutProps> = Omit< - MarkdownLayoutProps, - 'rawContent' | 'compiledContent' ->; - -export type GetHydrateCallback = () => Promise<() => void | Promise>; - -/** - * getStaticPaths() options - * - * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) - */ -export interface GetStaticPathsOptions { - paginate: PaginateFunction; -} - -export type GetStaticPathsItem = { - params: { [K in keyof Params]: Params[K] | number }; - props?: Props; -}; -export type GetStaticPathsResult = GetStaticPathsItem[]; -export type GetStaticPathsResultKeyed = GetStaticPathsResult & { - keyed: Map; -}; - -/** - * Return an array of pages to generate for a [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes). (**SSG Only**) - * - * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) - */ -export type GetStaticPaths = ( - options: GetStaticPathsOptions, -) => Promise | GetStaticPathsResult; - -/** - * Infers the shape of the `params` property returned by `getStaticPaths()`. - * - * @example - * ```ts - * import type { GetStaticPaths } from 'astro'; - * - * export const getStaticPaths = (() => { - * return results.map((entry) => ({ - * params: { slug: entry.slug }, - * })); - * }) satisfies GetStaticPaths; - * - * type Params = InferGetStaticParamsType; - * // ^? { slug: string; } - * - * const { slug } = Astro.params as Params; - * ``` - */ -export type InferGetStaticParamsType = T extends ( - opts?: GetStaticPathsOptions, -) => infer R | Promise - ? R extends Array - ? U extends { params: infer P } - ? P - : never - : never - : never; - -/** - * Infers the shape of the `props` property returned by `getStaticPaths()`. - * - * @example - * ```ts - * import type { GetStaticPaths } from 'astro'; - * - * export const getStaticPaths = (() => { - * return results.map((entry) => ({ - * params: { slug: entry.slug }, - * props: { - * propA: true, - * propB: 42 - * }, - * })); - * }) satisfies GetStaticPaths; - * - * type Props = InferGetStaticPropsType; - * // ^? { propA: boolean; propB: number; } - * - * const { propA, propB } = Astro.props; - * ``` - */ -export type InferGetStaticPropsType = T extends ( - opts: GetStaticPathsOptions, -) => infer R | Promise - ? R extends Array - ? U extends { props: infer P } - ? P - : never - : never - : never; - -export interface HydrateOptions { - name: string; - value?: string; -} - -export type JSXTransformConfig = Pick< - babel.TransformOptions, - 'presets' | 'plugins' | 'inputSourceMap' ->; - -export type JSXTransformFn = (options: { - mode: string; - ssr: boolean; -}) => Promise; - -export interface ManifestData { - routes: RouteData[]; -} - -/** @deprecated Type is no longer used by exported APIs */ -export interface MarkdownMetadata { - headings: MarkdownHeading[]; - source: string; - html: string; -} - -/** @deprecated Type is no longer used by exported APIs */ -export interface MarkdownRenderingResult { - metadata: MarkdownMetadata; - vfile: MarkdownVFile; - code: string; -} - -/** @deprecated Type is no longer used by exported APIs */ -export interface MarkdownParserResponse extends MarkdownRenderingResult { - frontmatter: MD['frontmatter']; -} - -/** - * The `content` prop given to a Layout - * - * [Astro reference](https://docs.astro.build/en/guides/markdown-content/#markdown-layouts) - */ -export type MarkdownContent = Record> = T & { - astro: MarkdownMetadata; - url: string | undefined; - file: string; -}; - -/** - * paginate() Options - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#paginate) - */ -export interface PaginateOptions { - /** the number of items per-page (default: `10`) */ - pageSize?: number; - /** key: value object of page params (ex: `{ tag: 'javascript' }`) */ - params?: PaginateParams; - /** object of props to forward to `page` result */ - props?: PaginateProps; -} - -/** - * Represents a single page of data in a paginated collection - * - * [Astro reference](https://docs.astro.build/en/reference/api-reference/#the-pagination-page-prop) - */ -export interface Page { - /** result */ - data: T[]; - /** metadata */ - /** the count of the first item on the page, starting from 0 */ - start: number; - /** the count of the last item on the page, starting from 0 */ - end: number; - /** total number of results */ - total: number; - /** the current page number, starting from 1 */ - currentPage: number; - /** number of items per page (default: 10) */ - size: number; - /** number of last page */ - lastPage: number; - url: { - /** url of the current page */ - current: string; - /** url of the previous page (if there is one) */ - prev: string | undefined; - /** url of the next page (if there is one) */ - next: string | undefined; - /** url of the first page (if the current page is not the first page) */ - first: string | undefined; - /** url of the next page (if the current page in not the last page) */ - last: string | undefined; - }; +// HACK! astro:db augment this type that is used in the config +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Config { + type Database = Record; + } } - -export type PaginateFunction = < - PaginateData, - AdditionalPaginateProps extends Props, - AdditionalPaginateParams extends Params, ->( - data: PaginateData[], - args?: PaginateOptions, -) => { - params: Simplify< - { - page: string | undefined; - } & OmitIndexSignature - >; - props: Simplify< - { - page: Page; - } & OmitIndexSignature - >; -}[]; - -export type Params = Record; - -export type SupportsKind = 'unsupported' | 'stable' | 'experimental' | 'deprecated'; - -export type AstroFeatureMap = { - /** - * The adapter is able serve static pages - */ - staticOutput?: SupportsKind; - /** - * The adapter is able to serve pages that are static or rendered via server - */ - hybridOutput?: SupportsKind; - /** - * The adapter is able to serve SSR pages - */ - serverOutput?: SupportsKind; - /** - * The adapter can emit static assets - */ - assets?: AstroAssetsFeature; - - /** - * List of features that orbit around the i18n routing - */ - i18nDomains?: SupportsKind; - - /** - * The adapter is able to support `getSecret` exported from `astro:env/server` - */ - envGetSecret?: SupportsKind; -}; - -export interface AstroAssetsFeature { - supportKind?: SupportsKind; - /** - * Whether if this adapter deploys files in an environment that is compatible with the library `sharp` - */ - isSharpCompatible?: boolean; - /** - * Whether if this adapter deploys files in an environment that is compatible with the library `squoosh` - */ - isSquooshCompatible?: boolean; -} - -export interface AstroInternationalizationFeature { - /** - * The adapter should be able to create the proper redirects - */ - domains?: SupportsKind; -} - -export type Locales = (string | { codes: string[]; path: string })[]; - -export interface AstroAdapter { - name: string; - serverEntrypoint?: string; - previewEntrypoint?: string; - exports?: string[]; - args?: any; - adapterFeatures?: AstroAdapterFeatures; - /** - * List of features supported by an adapter. - * - * If the adapter is not able to handle certain configurations, Astro will throw an error. - */ - supportedAstroFeatures: AstroFeatureMap; -} - -export type ValidRedirectStatus = 300 | 301 | 302 | 303 | 304 | 307 | 308; - -// Shared types between `Astro` global and API context object -interface AstroSharedContext< - Props extends Record = Record, - RouteParams extends Record = Record, -> { - /** - * The address (usually IP address) of the user. - * - * Throws an error if used within a static site, or within a prerendered page. - */ - clientAddress: string; - /** - * Utility for getting and setting the values of cookies. - */ - cookies: AstroCookies; - /** - * Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object - */ - request: Request; - /** - * A full URL object of the request URL. - */ - url: URL; - /** - * Get action result on the server when using a form POST. - */ - getActionResult: < - TAccept extends ActionAccept, - TInputSchema extends ActionInputSchema, - TAction extends ActionClient, - >( - action: TAction, - ) => ActionReturnType | undefined; - /** - * Call action handler from the server. - */ - callAction: < - TAccept extends ActionAccept, - TInputSchema extends ActionInputSchema, - TOutput, - TAction extends - | ActionClient - | ActionClient['orThrow'], - >( - action: TAction, - input: Parameters[0], - ) => Promise>; - /** - * Route parameters for this request if this is a dynamic route. - */ - params: RouteParams; - /** - * List of props returned for this path by `getStaticPaths` (**Static Only**). - */ - props: Props; - /** - * Redirect to another page (**SSR Only**). - */ - redirect(path: string, status?: ValidRedirectStatus): Response; - - /** - * It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted - * by the rerouted URL passed as argument. - * - * ## Example - * - * ```js - * if (pageIsNotEnabled) { - * return Astro.rewrite('/fallback-page') - * } - * ``` - */ - rewrite(rewritePayload: RewritePayload): Promise; - - /** - * Object accessed via Astro middleware - */ - locals: App.Locals; - - /** - * The current locale that is computed from the `Accept-Language` header of the browser (**SSR Only**). - */ - preferredLocale: string | undefined; - - /** - * The list of locales computed from the `Accept-Language` header of the browser, sorted by quality value (**SSR Only**). - */ - - preferredLocaleList: string[] | undefined; - - /** - * The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise. - */ - currentLocale: string | undefined; -} - -/** - * The `APIContext` is the object made available to endpoints and middleware. - * It is a subset of the `Astro` global object available in pages. - * - * [Reference](https://docs.astro.build/en/reference/api-reference/#endpoint-context) - */ -export interface APIContext< - Props extends Record = Record, - APIParams extends Record = Record, -> extends AstroSharedContext { - /** - * The site provided in the astro config, parsed as an instance of `URL`, without base. - * `undefined` if the site is not provided in the config. - */ - site: URL | undefined; - /** - * A human-readable string representing the Astro version used to create the project. - * For example, `"Astro v1.1.1"`. - */ - generator: string; - /** - * The url of the current request, parsed as an instance of `URL`. - * - * Equivalent to: - * ```ts - * new URL(context.request.url) - * ``` - */ - url: AstroSharedContext['url']; - /** - * Parameters matching the page’s dynamic route pattern. - * In static builds, this will be the `params` generated by `getStaticPaths`. - * In SSR builds, this can be any path segments matching the dynamic route pattern. - * - * Example usage: - * ```ts - * import type { APIContext } from "astro" - * - * export function getStaticPaths() { - * return [ - * { params: { id: '0' }, props: { name: 'Sarah' } }, - * { params: { id: '1' }, props: { name: 'Chris' } }, - * { params: { id: '2' }, props: { name: 'Fuzzy' } }, - * ]; - * } - * - * export async function GET({ params }: APIContext) { - * return new Response(`Hello user ${params.id}!`) - * } - * ``` - * - * [Reference](https://docs.astro.build/en/reference/api-reference/#contextparams) - */ - params: AstroSharedContext['params']; - /** - * List of props passed from `getStaticPaths`. Only available to static builds. - * - * Example usage: - * ```ts - * import type { APIContext } from "astro" - * - * export function getStaticPaths() { - * return [ - * { params: { id: '0' }, props: { name: 'Sarah' } }, - * { params: { id: '1' }, props: { name: 'Chris' } }, - * { params: { id: '2' }, props: { name: 'Fuzzy' } }, - * ]; - * } - * - * export function GET({ props }: APIContext): Response { - * return new Response(`Hello ${props.name}!`); - * } - * ``` - * - * [Reference](https://docs.astro.build/en/reference/api-reference/#contextprops) - */ - props: AstroSharedContext['props']; - /** - * Create a response that redirects to another page. - * - * Example usage: - * ```ts - * // src/pages/secret.ts - * export function GET({ redirect }) { - * return redirect('/login'); - * } - * ``` - * - * [Reference](https://docs.astro.build/en/guides/api-reference/#contextredirect) - */ - redirect: AstroSharedContext['redirect']; - - /** - * It reroutes to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted - * by the rerouted URL passed as argument. - * - * ## Example - * - * ```ts - * // src/pages/secret.ts - * export function GET(ctx) { - * return ctx.rewrite(new URL("../"), ctx.url); - * } - * ``` - */ - rewrite: AstroSharedContext['rewrite']; - - /** - * An object that middlewares can use to store extra information related to the request. - * - * It will be made available to pages as `Astro.locals`, and to endpoints as `context.locals`. - * - * Example usage: - * - * ```ts - * // src/middleware.ts - * import { defineMiddleware } from "astro:middleware"; - * - * export const onRequest = defineMiddleware((context, next) => { - * context.locals.greeting = "Hello!"; - * return next(); - * }); - * ``` - * Inside a `.astro` file: - * ```astro - * --- - * // src/pages/index.astro - * const greeting = Astro.locals.greeting; - * --- - *

{greeting}

- * ``` - * - * [Reference](https://docs.astro.build/en/reference/api-reference/#contextlocals) - */ - locals: App.Locals; - - /** - * Available only when `i18n` configured and in SSR. - * - * It represents the preferred locale of the user. It's computed by checking the supported locales in `i18n.locales` - * and locales supported by the users's browser via the header `Accept-Language` - * - * For example, given `i18n.locales` equals to `['fr', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the - * `Astro.preferredLanguage` will be `fr` because `en` is not supported, its [quality value] is the highest. - * - * [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values - */ - preferredLocale: string | undefined; - - /** - * Available only when `i18n` configured and in SSR. - * - * It represents the list of the preferred locales that are supported by the application. The list is sorted via [quality value]. - * - * For example, given `i18n.locales` equals to `['fr', 'pt', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the - * `Astro.preferredLocaleList` will be equal to `['fs', 'de']` because `en` isn't supported, and `pt` isn't part of the locales contained in the - * header. - * - * When the `Accept-Header` is `*`, the original `i18n.locales` are returned. The value `*` means no preferences, so Astro returns all the supported locales. - * - * [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values - */ - preferredLocaleList: string[] | undefined; - - /** - * The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise. - */ - currentLocale: string | undefined; -} - -export type APIRoute< - Props extends Record = Record, - APIParams extends Record = Record, -> = (context: APIContext) => Response | Promise; - -export interface EndpointHandler { - [method: string]: APIRoute; -} - -export type Props = Record; - -export interface AstroRenderer { - /** Name of the renderer. */ - name: string; - /** Import entrypoint for the client/browser renderer. */ - clientEntrypoint?: string; - /** Import entrypoint for the server/build/ssr renderer. */ - serverEntrypoint: string; - /** @deprecated Vite plugins should transform the JSX instead */ - jsxImportSource?: string; - /** @deprecated Vite plugins should transform the JSX instead */ - jsxTransformOptions?: JSXTransformFn; -} - -export interface NamedSSRLoadedRendererValue extends SSRLoadedRendererValue { - name: string; -} - -export interface SSRLoadedRendererValue { - name?: string; - check: AsyncRendererComponentFn; - renderToStaticMarkup: AsyncRendererComponentFn<{ - html: string; - attrs?: Record; - }>; - supportsAstroStaticSlot?: boolean; - /** - * If provided, Astro will call this function and inject the returned - * script in the HTML before the first component handled by this renderer. - * - * This feature is needed by some renderers (in particular, by Solid). The - * Solid official hydration script sets up a page-level data structure. - * It is mainly used to transfer data between the server side render phase - * and the browser application state. Solid Components rendered later in - * the HTML may inject tiny scripts into the HTML that call into this - * page-level data structure. - */ - renderHydrationScript?: () => string; -} - -export interface SSRLoadedRenderer extends Pick { - ssr: SSRLoadedRendererValue; -} - -export type HookParameters< - Hook extends keyof AstroIntegration['hooks'], - Fn = AstroIntegration['hooks'][Hook], -> = Fn extends (...args: any) => any ? Parameters[0] : never; - -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace Astro { - export interface IntegrationHooks { - 'astro:config:setup': (options: { - config: AstroConfig; - command: 'dev' | 'build' | 'preview'; - isRestart: boolean; - updateConfig: (newConfig: DeepPartial) => AstroConfig; - addRenderer: (renderer: AstroRenderer) => void; - addWatchFile: (path: URL | string) => void; - injectScript: (stage: InjectedScriptStage, content: string) => void; - injectRoute: (injectRoute: InjectedRoute) => void; - addClientDirective: (directive: ClientDirectiveConfig) => void; - /** - * @deprecated Use `addDevToolbarApp` instead. - * TODO: Fully remove in Astro 5.0 - */ - addDevOverlayPlugin: (entrypoint: string) => void; - // TODO: Deprecate the `string` overload once a few apps have been migrated to the new API. - addDevToolbarApp: (entrypoint: DevToolbarAppEntry | string) => void; - addMiddleware: (mid: AstroIntegrationMiddleware) => void; - logger: AstroIntegrationLogger; - // TODO: Add support for `injectElement()` for full HTML element injection, not just scripts. - // This may require some refactoring of `scripts`, `styles`, and `links` into something - // more generalized. Consider the SSR use-case as well. - // injectElement: (stage: vite.HtmlTagDescriptor, element: string) => void; - }) => void | Promise; - 'astro:config:done': (options: { - config: AstroConfig; - setAdapter: (adapter: AstroAdapter) => void; - injectTypes: (injectedType: InjectedType) => URL; - logger: AstroIntegrationLogger; - }) => void | Promise; - 'astro:server:setup': (options: { - server: vite.ViteDevServer; - logger: AstroIntegrationLogger; - toolbar: ReturnType; - }) => void | Promise; - 'astro:server:start': (options: { - address: AddressInfo; - logger: AstroIntegrationLogger; - }) => void | Promise; - 'astro:server:done': (options: { logger: AstroIntegrationLogger }) => void | Promise; - 'astro:build:ssr': (options: { - manifest: SerializedSSRManifest; - /** - * This maps a {@link RouteData} to an {@link URL}, this URL represents - * the physical file you should import. - */ - entryPoints: Map; - /** - * File path of the emitted middleware - */ - middlewareEntryPoint: URL | undefined; - logger: AstroIntegrationLogger; - }) => void | Promise; - 'astro:build:start': (options: { logger: AstroIntegrationLogger }) => void | Promise; - 'astro:build:setup': (options: { - vite: vite.InlineConfig; - pages: Map; - target: 'client' | 'server'; - updateConfig: (newConfig: vite.InlineConfig) => void; - logger: AstroIntegrationLogger; - }) => void | Promise; - 'astro:build:generated': (options: { - dir: URL; - logger: AstroIntegrationLogger; - }) => void | Promise; - 'astro:build:done': (options: { - pages: { pathname: string }[]; - dir: URL; - routes: RouteData[]; - logger: AstroIntegrationLogger; - cacheManifest: boolean; - }) => void | Promise; - 'astro:route:setup': (options: { - route: RouteOptions; - logger: AstroIntegrationLogger; - }) => void | Promise; - } - } -} - -export interface AstroIntegration { - /** The name of the integration. */ - name: string; - /** The different hooks available to extend. */ - hooks: { - [K in keyof Astro.IntegrationHooks]?: Astro.IntegrationHooks[K]; - } & Partial>; -} - -export type RewritePayload = string | URL | Request; - -export type MiddlewareNext = (rewritePayload?: RewritePayload) => Promise; -export type MiddlewareHandler = ( - context: APIContext, - next: MiddlewareNext, -) => Promise | Response | Promise | void; - -// NOTE: when updating this file with other functions, -// remember to update `plugin-page.ts` too, to add that function as a no-op function. -export type AstroMiddlewareInstance = { - onRequest?: MiddlewareHandler; -}; - -export type AstroIntegrationMiddleware = { - order: 'pre' | 'post'; - entrypoint: string; -}; - -export interface AstroPluginOptions { - settings: AstroSettings; - logger: Logger; -} - -/** - * - page: a route that lives in the file system, usually an Astro component - * - endpoint: a route that lives in the file system, usually a JS file that exposes endpoints methods - * - redirect: a route points to another route that lives in the file system - * - fallback: a route that doesn't exist in the file system that needs to be handled with other means, usually the middleware - */ -export type RouteType = 'page' | 'endpoint' | 'redirect' | 'fallback'; - -export interface RoutePart { - content: string; - dynamic: boolean; - spread: boolean; -} - -type RedirectConfig = - | string - | { - status: ValidRedirectStatus; - destination: string; - priority?: RoutePriorityOverride; - }; - -export interface RouteData { - route: string; - component: string; - generate: (data?: any) => string; - params: string[]; - pathname?: string; - // expose the real path name on SSG - distURL?: URL; - pattern: RegExp; - segments: RoutePart[][]; - type: RouteType; - prerender: boolean; - redirect?: RedirectConfig; - redirectRoute?: RouteData; - fallbackRoutes: RouteData[]; - isIndex: boolean; -} - -export type RedirectRouteData = RouteData & { - redirect: string; -}; - -export type SerializedRouteData = Omit< - RouteData, - 'generate' | 'pattern' | 'redirectRoute' | 'fallbackRoutes' -> & { - generate: undefined; - pattern: string; - redirectRoute: SerializedRouteData | undefined; - fallbackRoutes: SerializedRouteData[]; - _meta: { - trailingSlash: AstroConfig['trailingSlash']; - }; -}; - -export type RuntimeMode = 'development' | 'production'; - -export type SSRError = Error & vite.ErrorPayload['err']; - -export interface SSRElement { - props: Record; - children: string; -} - -/** - * A hint on whether the Astro runtime needs to wait on a component to render head - * content. The meanings: - * - * - __none__ (default) The component does not propagation head content. - * - __self__ The component appends head content. - * - __in-tree__ Another component within this component's dependency tree appends head content. - * - * These are used within the runtime to know whether or not a component should be waited on. - */ -export type PropagationHint = 'none' | 'self' | 'in-tree'; - -export type SSRComponentMetadata = { - propagation: PropagationHint; - containsHead: boolean; -}; - -export interface SSRResult { - /** - * Whether the page has failed with a non-recoverable error, or the client disconnected. - */ - cancelled: boolean; - base: string; - styles: Set; - scripts: Set; - links: Set; - componentMetadata: Map; - inlinedScripts: Map; - createAstro( - Astro: AstroGlobalPartial, - props: Record, - slots: Record | null, - ): AstroGlobal; - params: Params; - resolve: (s: string) => Promise; - response: AstroGlobal['response']; - request: AstroGlobal['request']; - actionResult?: ReturnType; - renderers: SSRLoadedRenderer[]; - /** - * Map of directive name (e.g. `load`) to the directive script code - */ - clientDirectives: Map; - compressHTML: boolean; - partial: boolean; - /** - * Only used for logging - */ - pathname: string; - cookies: AstroCookies | undefined; - serverIslandNameMap: Map; - trailingSlash: AstroConfig['trailingSlash']; - key: Promise; - _metadata: SSRMetadata; -} - -/** - * Ephemeral and mutable state during rendering that doesn't rely - * on external configuration - */ -export interface SSRMetadata { - hasHydrationScript: boolean; - /** - * Names of renderers that have injected their hydration scripts - * into the current page. For example, Solid SSR needs a hydration - * script in the page HTML before the first Solid component. - */ - rendererSpecificHydrationScripts: Set; - /** - * Used by `renderScript` to track script ids that have been rendered, - * so we only render each once. - */ - renderedScripts: Set; - hasDirectives: Set; - hasRenderedHead: boolean; - headInTree: boolean; - extraHead: string[]; - propagators: Set; -} - -/* Preview server stuff */ -export interface PreviewServer { - host?: string; - port: number; - closed(): Promise; - stop(): Promise; -} - -export interface PreviewServerParams { - outDir: URL; - client: URL; - serverEntrypoint: URL; - host: string | undefined; - port: number; - base: string; - logger: AstroIntegrationLogger; - headers?: OutgoingHttpHeaders; -} - -export type CreatePreviewServer = ( - params: PreviewServerParams, -) => PreviewServer | Promise; - -export interface PreviewModule { - default: CreatePreviewServer; -} - -/* Client Directives */ -type DirectiveHydrate = () => Promise; -type DirectiveLoad = () => Promise; - -type DirectiveOptions = { - /** - * The component displayName - */ - name: string; - /** - * The attribute value provided - */ - value: string; -}; - -export type ClientDirective = ( - load: DirectiveLoad, - options: DirectiveOptions, - el: HTMLElement, -) => void; - -export interface ClientDirectiveConfig { - name: string; - entrypoint: string; -} - -type DevToolbarAppMeta = { - id: string; - name: string; - icon?: Icon; -}; - -// The param passed to `addDevToolbarApp` in the integration -export type DevToolbarAppEntry = DevToolbarAppMeta & { - entrypoint: string; -}; - -// Public API for the dev toolbar -export type DevToolbarApp = { - /** - * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. - * - * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` - * - * In the future, putting these properties directly on the app object will be removed. - */ - id?: string; - /** - * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. - * - * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` - * - * In the future, putting these properties directly on the app object will be removed. - */ - name?: string; - /** - * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. - * - * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` - * - * In the future, putting these properties directly on the app object will be removed. - */ - icon?: Icon; - init?( - canvas: ShadowRoot, - app: ToolbarAppEventTarget, - server: ToolbarServerHelpers, - ): void | Promise; - beforeTogglingOff?(canvas: ShadowRoot): boolean | Promise; -}; - -// An app that has been loaded and as such contain all of its properties -export type ResolvedDevToolbarApp = DevToolbarAppMeta & Omit; - -// TODO: Remove in Astro 5.0 -export type DevOverlayPlugin = DevToolbarApp; - -export type DevToolbarMetadata = Window & - typeof globalThis & { - __astro_dev_toolbar__: { - root: string; - version: string; - latestAstroVersion: AstroSettings['latestAstroVersion']; - debugInfo: string; - }; - }; - -declare global { - interface HTMLElementTagNameMap { - 'astro-dev-toolbar': AstroDevToolbar; - 'astro-dev-toolbar-window': DevToolbarWindow; - 'astro-dev-toolbar-app-canvas': DevToolbarCanvas; - 'astro-dev-toolbar-tooltip': DevToolbarTooltip; - 'astro-dev-toolbar-highlight': DevToolbarHighlight; - 'astro-dev-toolbar-toggle': DevToolbarToggle; - 'astro-dev-toolbar-badge': DevToolbarBadge; - 'astro-dev-toolbar-button': DevToolbarButton; - 'astro-dev-toolbar-icon': DevToolbarIcon; - 'astro-dev-toolbar-card': DevToolbarCard; - 'astro-dev-toolbar-select': DevToolbarSelect; - 'astro-dev-toolbar-radio-checkbox': DevToolbarRadioCheckbox; - - // Deprecated names - // TODO: Remove in Astro 5.0 - 'astro-dev-overlay': AstroDevToolbar; - 'astro-dev-overlay-window': DevToolbarWindow; - 'astro-dev-overlay-plugin-canvas': DevToolbarCanvas; - 'astro-dev-overlay-tooltip': DevToolbarTooltip; - 'astro-dev-overlay-highlight': DevToolbarHighlight; - 'astro-dev-overlay-toggle': DevToolbarToggle; - 'astro-dev-overlay-badge': DevToolbarBadge; - 'astro-dev-overlay-button': DevToolbarButton; - 'astro-dev-overlay-icon': DevToolbarIcon; - 'astro-dev-overlay-card': DevToolbarCard; - } - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace Config { - type Database = Record; - } - - interface DocumentEventMap { - 'astro:before-preparation': TransitionBeforePreparationEvent; - 'astro:after-preparation': Event; - 'astro:before-swap': TransitionBeforeSwapEvent; - 'astro:after-swap': Event; - 'astro:page-load': Event; - } -} - -// Container types -export type ContainerImportRendererFn = ( - containerRenderer: ContainerRenderer, -) => Promise; - -export type ContainerRenderer = { - /** - * The name of the renderer. - */ - name: string; - /** - * The entrypoint that is used to render a component on the server - */ - serverEntrypoint: string; -}; diff --git a/packages/astro/src/types/public/content.ts b/packages/astro/src/types/public/content.ts new file mode 100644 index 000000000000..ac58c918f48f --- /dev/null +++ b/packages/astro/src/types/public/content.ts @@ -0,0 +1,121 @@ +import type { MarkdownHeading } from '@astrojs/markdown-remark'; +import type * as rollup from 'rollup'; +import type { DataEntry, RenderedContent } from '../../content/data-store.js'; +import type { AstroComponentFactory } from '../../runtime/server/index.js'; +import type { AstroConfig } from './config.js'; + +export interface AstroInstance { + file: string; + url: string | undefined; + default: AstroComponentFactory; +} + +export interface MarkdownInstance> { + frontmatter: T; + /** Absolute file path (e.g. `/home/user/projects/.../file.md`) */ + file: string; + /** Browser URL for files under `/src/pages` (e.g. `/en/guides/markdown-content`) */ + url: string | undefined; + /** Component to render content in `.astro` files. Usage: `` */ + Content: AstroComponentFactory; + /** raw Markdown file content, excluding layout HTML and YAML frontmatter */ + rawContent(): string; + /** Markdown file compiled to HTML, excluding layout HTML */ + compiledContent(): string; + /** List of headings (h1 -> h6) with associated metadata */ + getHeadings(): MarkdownHeading[]; + default: AstroComponentFactory; +} + +export type MDXInstance> = Omit< + MarkdownInstance, + 'rawContent' | 'compiledContent' +>; + +export interface MarkdownLayoutProps> { + frontmatter: { + file: MarkdownInstance['file']; + url: MarkdownInstance['url']; + } & T; + file: MarkdownInstance['file']; + url: MarkdownInstance['url']; + headings: MarkdownHeading[]; + rawContent: MarkdownInstance['rawContent']; + compiledContent: MarkdownInstance['compiledContent']; +} + +export type MDXLayoutProps> = Omit< + MarkdownLayoutProps, + 'rawContent' | 'compiledContent' +>; + +export type ContentEntryModule = { + id: string; + collection: string; + slug: string; + body: string; + data: Record; + _internal: { + rawData: string; + filePath: string; + }; +}; + +export type DataEntryModule = { + id: string; + collection: string; + data: Record; + _internal: { + rawData: string; + filePath: string; + }; +}; + +export type ContentEntryRenderFunction = (entry: DataEntry) => Promise; + +export interface ContentEntryType { + extensions: string[]; + getEntryInfo(params: { + fileUrl: URL; + contents: string; + }): GetContentEntryInfoReturnType | Promise; + getRenderModule?( + this: rollup.PluginContext, + params: { + contents: string; + fileUrl: URL; + viteId: string; + }, + ): rollup.LoadResult | Promise; + contentModuleTypes?: string; + getRenderFunction?(config: AstroConfig): Promise; + + /** + * Handle asset propagation for rendered content to avoid bleed. + * Ex. MDX content can import styles and scripts, so `handlePropagation` should be true. + * @default true + */ + handlePropagation?: boolean; +} + +type GetContentEntryInfoReturnType = { + data: Record; + /** + * Used for error hints to point to correct line and location + * Should be the untouched data as read from the file, + * including newlines + */ + rawData: string; + body: string; + slug: string; +}; + +export interface DataEntryType { + extensions: string[]; + getEntryInfo(params: { + fileUrl: URL; + contents: string; + }): GetDataEntryInfoReturnType | Promise; +} + +export type GetDataEntryInfoReturnType = { data: Record; rawData?: string }; diff --git a/packages/astro/src/types/public/context.ts b/packages/astro/src/types/public/context.ts new file mode 100644 index 000000000000..5f05b7a66273 --- /dev/null +++ b/packages/astro/src/types/public/context.ts @@ -0,0 +1,501 @@ +import type { + ActionAccept, + ActionClient, + ActionInputSchema, + ActionReturnType, +} from '../../actions/runtime/virtual/server.js'; +import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from '../../core/constants.js'; +import type { AstroCookies } from '../../core/cookies/cookies.js'; +import type { AstroComponentFactory } from '../../runtime/server/index.js'; +import type { Params, RewritePayload } from './common.js'; +import type { ValidRedirectStatus } from './config.js'; +import type { AstroInstance, MDXInstance, MarkdownInstance } from './content.js'; + +/** + * Astro global available in all contexts in .astro files + * + * [Astro reference](https://docs.astro.build/reference/api-reference/#astro-global) + */ +export interface AstroGlobal< + Props extends Record = Record, + Self = AstroComponentFactory, + // eslint-disable-next-line @typescript-eslint/no-shadow + Params extends Record = Record, +> extends AstroGlobalPartial, + AstroSharedContext { + /** + * A full URL object of the request URL. + * Equivalent to: `new URL(Astro.request.url)` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#url) + */ + url: AstroSharedContext['url']; + /** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) + * + * Example usage: + * ```astro + * --- + * export async function getStaticPaths() { + * return [ + * { params: { id: '1' } }, + * ]; + * } + * + * const { id } = Astro.params; + * --- + *

{id}

+ * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroparams) + */ + params: AstroSharedContext['params']; + /** List of props passed to this component + * + * A common way to get specific props is through [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment), ex: + * ```typescript + * const { name } = Astro.props + * ``` + * + * [Astro reference](https://docs.astro.build/en/basics/astro-components/#component-props) + */ + props: AstroSharedContext['props']; + /** Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object + * + * For example, to get a URL object of the current URL, you can use: + * ```typescript + * const url = new URL(Astro.request.url); + * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrorequest) + */ + request: Request; + /** Information about the outgoing response. This is a standard [ResponseInit](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#init) object + * + * For example, to change the status code you can set a different status on this object: + * ```typescript + * Astro.response.status = 404; + * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroresponse) + */ + response: ResponseInit & { + readonly headers: Headers; + }; + /** + * Get an action result on the server when using a form POST. + * Expects the action function as a parameter. + * Returns a type-safe result with the action data when + * a matching POST request is received + * and `undefined` otherwise. + * + * Example usage: + * + * ```typescript + * import { actions } from 'astro:actions'; + * + * const result = await Astro.getActionResult(actions.myAction); + * ``` + */ + getActionResult: AstroSharedContext['getActionResult']; + /** + * Call an Action directly from an Astro page or API endpoint. + * Expects the action function as the first parameter, + * and the type-safe action input as the second parameter. + * Returns a Promise with the action result. + * + * Example usage: + * + * ```typescript + * import { actions } from 'astro:actions'; + * + * const result = await Astro.callAction(actions.getPost, { postId: 'test' }); + * ``` + */ + callAction: AstroSharedContext['callAction']; + /** Redirect to another page + * + * Example usage: + * ```typescript + * if(!isLoggedIn) { + * return Astro.redirect('/login'); + * } + * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroredirect) + */ + redirect: AstroSharedContext['redirect']; + /** + * It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted + * by the rewritten URL passed as argument. + * + * ## Example + * + * ```js + * if (pageIsNotEnabled) { + * return Astro.rewrite('/fallback-page') + * } + * ``` + */ + rewrite: AstroSharedContext['rewrite']; + /** + * The element allows a component to reference itself recursively. + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroself) + */ + self: Self; + /** Utility functions for modifying an Astro component’s slotted children + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots) + */ + slots: Record & { + /** + * Check whether content for this slot name exists + * + * Example usage: + * ```typescript + * if (Astro.slots.has('default')) { + * // Do something... + * } + * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots) + */ + has(slotName: string): boolean; + /** + * Asynchronously renders this slot and returns a string + * + * Example usage: + * ```astro + * --- + * let html: string = ''; + * if (Astro.slots.has('default')) { + * html = await Astro.slots.render('default') + * } + * --- + * + * ``` + * + * A second parameter can be used to pass arguments to a slotted callback + * + * Example usage: + * ```astro + * --- + * html = await Astro.slots.render('default', ["Hello", "World"]) + * --- + * ``` + * Each item in the array will be passed as an argument that you can use like so: + * ```astro + * + * {(hello, world) =>
{hello}, {world}!
} + *
+ * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroslots) + */ + render(slotName: string, args?: any[]): Promise; + }; +} + +/** Union type of supported markdown file extensions */ +type MarkdownFileExtension = (typeof SUPPORTED_MARKDOWN_FILE_EXTENSIONS)[number]; + +export interface AstroGlobalPartial { + /** + * Fetch local files into your static site setup + * + * Example usage: + * ```typescript + * const posts = await Astro.glob('../pages/post/*.md'); + * ``` + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroglob) + */ + glob(globStr: `${any}.astro`): Promise; + glob>( + globStr: `${any}${MarkdownFileExtension}`, + ): Promise[]>; + glob>(globStr: `${any}.mdx`): Promise[]>; + glob>(globStr: string): Promise; + /** + * Returns a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object built from the [site](https://docs.astro.build/en/reference/configuration-reference/#site) config option + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrosite) + */ + site: URL | undefined; + /** + * Returns a string with the current version of Astro. + * + * Useful for using `` or crediting Astro in a site footer. + * + * [HTML Specification for `generator`](https://html.spec.whatwg.org/multipage/semantics.html#meta-generator) + * + * [Astro reference](https://docs.astro.build/en/reference/api-reference/#astrogenerator) + */ + generator: string; +} + +// Shared types between `Astro` global and API context object +interface AstroSharedContext< + Props extends Record = Record, + RouteParams extends Record = Record, +> { + /** + * The address (usually IP address) of the user. + * + * Throws an error if used within a static site, or within a prerendered page. + */ + clientAddress: string; + /** + * Utility for getting and setting the values of cookies. + */ + cookies: AstroCookies; + /** + * Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object + */ + request: Request; + /** + * A full URL object of the request URL. + */ + url: URL; + /** + * Get action result on the server when using a form POST. + */ + getActionResult: < + TAccept extends ActionAccept, + TInputSchema extends ActionInputSchema, + TAction extends ActionClient, + >( + action: TAction, + ) => ActionReturnType | undefined; + /** + * Call action handler from the server. + */ + callAction: < + TAccept extends ActionAccept, + TInputSchema extends ActionInputSchema, + TOutput, + TAction extends + | ActionClient + | ActionClient['orThrow'], + >( + action: TAction, + input: Parameters[0], + ) => Promise>; + /** + * Route parameters for this request if this is a dynamic route. + */ + params: RouteParams; + /** + * List of props returned for this path by `getStaticPaths` (**Static Only**). + */ + props: Props; + /** + * Redirect to another page (**SSR Only**). + */ + redirect(path: string, status?: ValidRedirectStatus): Response; + + /** + * It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted + * by the rerouted URL passed as argument. + * + * ## Example + * + * ```js + * if (pageIsNotEnabled) { + * return Astro.rewrite('/fallback-page') + * } + * ``` + */ + rewrite(rewritePayload: RewritePayload): Promise; + + /** + * Object accessed via Astro middleware + */ + locals: App.Locals; + + /** + * The current locale that is computed from the `Accept-Language` header of the browser (**SSR Only**). + */ + preferredLocale: string | undefined; + + /** + * The list of locales computed from the `Accept-Language` header of the browser, sorted by quality value (**SSR Only**). + */ + + preferredLocaleList: string[] | undefined; + + /** + * The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise. + */ + currentLocale: string | undefined; +} + +/** + * The `APIContext` is the object made available to endpoints and middleware. + * It is a subset of the `Astro` global object available in pages. + * + * [Reference](https://docs.astro.build/en/reference/api-reference/#endpoint-context) + */ +export interface APIContext< + Props extends Record = Record, + APIParams extends Record = Record, +> extends AstroSharedContext { + /** + * The site provided in the astro config, parsed as an instance of `URL`, without base. + * `undefined` if the site is not provided in the config. + */ + site: URL | undefined; + /** + * A human-readable string representing the Astro version used to create the project. + * For example, `"Astro v1.1.1"`. + */ + generator: string; + /** + * The url of the current request, parsed as an instance of `URL`. + * + * Equivalent to: + * ```ts + * new URL(context.request.url) + * ``` + */ + url: AstroSharedContext['url']; + /** + * Parameters matching the page’s dynamic route pattern. + * In static builds, this will be the `params` generated by `getStaticPaths`. + * In SSR builds, this can be any path segments matching the dynamic route pattern. + * + * Example usage: + * ```ts + * import type { APIContext } from "astro" + * + * export function getStaticPaths() { + * return [ + * { params: { id: '0' }, props: { name: 'Sarah' } }, + * { params: { id: '1' }, props: { name: 'Chris' } }, + * { params: { id: '2' }, props: { name: 'Fuzzy' } }, + * ]; + * } + * + * export async function GET({ params }: APIContext) { + * return new Response(`Hello user ${params.id}!`) + * } + * ``` + * + * [Reference](https://docs.astro.build/en/reference/api-reference/#contextparams) + */ + params: AstroSharedContext['params']; + /** + * List of props passed from `getStaticPaths`. Only available to static builds. + * + * Example usage: + * ```ts + * import type { APIContext } from "astro" + * + * export function getStaticPaths() { + * return [ + * { params: { id: '0' }, props: { name: 'Sarah' } }, + * { params: { id: '1' }, props: { name: 'Chris' } }, + * { params: { id: '2' }, props: { name: 'Fuzzy' } }, + * ]; + * } + * + * export function GET({ props }: APIContext): Response { + * return new Response(`Hello ${props.name}!`); + * } + * ``` + * + * [Reference](https://docs.astro.build/en/reference/api-reference/#contextprops) + */ + props: AstroSharedContext['props']; + /** + * Create a response that redirects to another page. + * + * Example usage: + * ```ts + * // src/pages/secret.ts + * export function GET({ redirect }) { + * return redirect('/login'); + * } + * ``` + * + * [Reference](https://docs.astro.build/en/guides/api-reference/#contextredirect) + */ + redirect: AstroSharedContext['redirect']; + + /** + * It reroutes to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted + * by the rerouted URL passed as argument. + * + * ## Example + * + * ```ts + * // src/pages/secret.ts + * export function GET(ctx) { + * return ctx.rewrite(new URL("../"), ctx.url); + * } + * ``` + */ + rewrite: AstroSharedContext['rewrite']; + + /** + * An object that middlewares can use to store extra information related to the request. + * + * It will be made available to pages as `Astro.locals`, and to endpoints as `context.locals`. + * + * Example usage: + * + * ```ts + * // src/middleware.ts + * import { defineMiddleware } from "astro:middleware"; + * + * export const onRequest = defineMiddleware((context, next) => { + * context.locals.greeting = "Hello!"; + * return next(); + * }); + * ``` + * Inside a `.astro` file: + * ```astro + * --- + * // src/pages/index.astro + * const greeting = Astro.locals.greeting; + * --- + *

{greeting}

+ * ``` + * + * [Reference](https://docs.astro.build/en/reference/api-reference/#contextlocals) + */ + locals: App.Locals; + + /** + * Available only when `i18n` configured and in SSR. + * + * It represents the preferred locale of the user. It's computed by checking the supported locales in `i18n.locales` + * and locales supported by the users's browser via the header `Accept-Language` + * + * For example, given `i18n.locales` equals to `['fr', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the + * `Astro.preferredLanguage` will be `fr` because `en` is not supported, its [quality value] is the highest. + * + * [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values + */ + preferredLocale: string | undefined; + + /** + * Available only when `i18n` configured and in SSR. + * + * It represents the list of the preferred locales that are supported by the application. The list is sorted via [quality value]. + * + * For example, given `i18n.locales` equals to `['fr', 'pt', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the + * `Astro.preferredLocaleList` will be equal to `['fs', 'de']` because `en` isn't supported, and `pt` isn't part of the locales contained in the + * header. + * + * When the `Accept-Header` is `*`, the original `i18n.locales` are returned. The value `*` means no preferences, so Astro returns all the supported locales. + * + * [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values + */ + preferredLocaleList: string[] | undefined; + + /** + * The current locale computed from the URL of the request. It matches the locales in `i18n.locales`, and returns `undefined` otherwise. + */ + currentLocale: string | undefined; +} diff --git a/packages/astro/src/types/public/elements.ts b/packages/astro/src/types/public/elements.ts new file mode 100644 index 000000000000..83301f7b839a --- /dev/null +++ b/packages/astro/src/types/public/elements.ts @@ -0,0 +1,47 @@ +import type { TransitionAnimationValue } from './view-transitions.js'; + +export interface AstroComponentDirectives extends Astro.ClientDirectives { + 'server:defer'?: boolean; +} + +export interface AstroClientDirectives { + 'client:load'?: boolean; + 'client:idle'?: boolean; + 'client:media'?: string; + 'client:visible'?: ClientVisibleOptions | boolean; + 'client:only'?: boolean | string; +} + +export type ClientVisibleOptions = Pick; + +export interface AstroBuiltinAttributes { + 'class:list'?: + | Record + | Record + | Iterable + | Iterable + | string; + 'set:html'?: any; + 'set:text'?: any; + 'is:raw'?: boolean; + 'transition:animate'?: TransitionAnimationValue; + 'transition:name'?: string; + 'transition:persist'?: boolean | string; +} + +export interface AstroDefineVarsAttribute { + 'define:vars'?: any; +} + +export interface AstroStyleAttributes { + 'is:global'?: boolean; + 'is:inline'?: boolean; +} + +export interface AstroScriptAttributes { + 'is:inline'?: boolean; +} + +export interface AstroSlotAttributes { + 'is:inline'?: boolean; +} diff --git a/packages/astro/src/types/public/extendables.ts b/packages/astro/src/types/public/extendables.ts new file mode 100644 index 000000000000..1592eda190ad --- /dev/null +++ b/packages/astro/src/types/public/extendables.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/no-namespace */ +/* eslint-disable @typescript-eslint/no-empty-object-type */ +import type { AstroClientDirectives } from './elements.js'; +import type { BaseIntegrationHooks } from './integrations.js'; + +// The interfaces in this file can be extended by users +declare global { + namespace App { + /** + * Used by middlewares to store information, that can be read by the user via the global `Astro.locals` + */ + export interface Locals {} + } + + namespace Astro { + export interface IntegrationHooks extends BaseIntegrationHooks {} + export interface ClientDirectives extends AstroClientDirectives {} + } +} + +export {}; diff --git a/packages/astro/src/types/public/index.ts b/packages/astro/src/types/public/index.ts new file mode 100644 index 000000000000..5df509013678 --- /dev/null +++ b/packages/astro/src/types/public/index.ts @@ -0,0 +1,44 @@ +export type * from './config.js'; +export type * from './elements.js'; +export type * from './extendables.js'; +export type * from './toolbar.js'; +export type * from './view-transitions.js'; +export type * from './integrations.js'; +export type * from './internal.js'; +export type * from './context.js'; +export type * from './preview.js'; +export type * from './content.js'; +export type * from './common.js'; + +export type { AstroIntegrationLogger } from '../../core/logger/core.js'; +export type { ToolbarServerHelpers } from '../../runtime/client/dev-toolbar/helpers.js'; + +export type { + MarkdownHeading, + RehypePlugins, + RemarkPlugins, + ShikiConfig, +} from '@astrojs/markdown-remark'; +export type { + ExternalImageService, + ImageService, + LocalImageService, +} from '../../assets/services/service.js'; +export type { + GetImageResult, + ImageInputFormat, + ImageMetadata, + ImageOutputFormat, + ImageQuality, + ImageQualityPreset, + ImageTransform, + UnresolvedImageTransform, +} from '../../assets/types.js'; +export type { RemotePattern } from '../../assets/utils/remotePattern.js'; +export type { AssetsPrefix, SSRManifest } from '../../core/app/types.js'; +export type { + AstroCookieGetOptions, + AstroCookieSetOptions, + AstroCookies, +} from '../../core/cookies/index.js'; +export type { ContainerRenderer } from '../../container/index.js'; diff --git a/packages/astro/src/types/public/integrations.ts b/packages/astro/src/types/public/integrations.ts new file mode 100644 index 000000000000..d41abd8355e9 --- /dev/null +++ b/packages/astro/src/types/public/integrations.ts @@ -0,0 +1,258 @@ +import type { AddressInfo } from 'node:net'; +import type { ViteDevServer, InlineConfig as ViteInlineConfig } from 'vite'; +import type { SerializedSSRManifest } from '../../core/app/types.js'; +import type { PageBuildData } from '../../core/build/types.js'; +import type { AstroIntegrationLogger } from '../../core/logger/core.js'; +import type { getToolbarServerCommunicationHelpers } from '../../integrations/hooks.js'; +import type { DeepPartial } from '../../type-utils.js'; +import type { AstroConfig } from './config.js'; +import type { RouteData } from './internal.js'; +import type { DevToolbarAppEntry } from './toolbar.js'; + +export interface RouteOptions { + /** + * The path to this route relative to the project root. The slash is normalized as forward slash + * across all OS. + * @example "src/pages/blog/[...slug].astro" + */ + readonly component: string; + /** + * Whether this route should be prerendered. If the route has an explicit `prerender` export, + * the value will be passed here. Otherwise, it's undefined and will fallback to a prerender + * default depending on the `output` option. + */ + prerender?: boolean; +} + +/* Client Directives */ +type DirectiveHydrate = () => Promise; +type DirectiveLoad = () => Promise; + +type DirectiveOptions = { + /** + * The component displayName + */ + name: string; + /** + * The attribute value provided + */ + value: string; +}; + +export type ClientDirective = ( + load: DirectiveLoad, + options: DirectiveOptions, + el: HTMLElement, +) => void; + +export interface ClientDirectiveConfig { + name: string; + entrypoint: string; +} + +export interface AstroRenderer { + /** Name of the renderer. */ + name: string; + /** Import entrypoint for the client/browser renderer. */ + clientEntrypoint?: string; + /** Import entrypoint for the server/build/ssr renderer. */ + serverEntrypoint: string; +} + +export type AdapterSupportsKind = 'unsupported' | 'stable' | 'experimental' | 'deprecated'; + +export interface AstroAdapterFeatures { + /** + * Creates an edge function that will communiate with the Astro middleware + */ + edgeMiddleware: boolean; + /** + * SSR only. Each route becomes its own function/file. + */ + functionPerRoute: boolean; +} + +export interface AstroAdapter { + name: string; + serverEntrypoint?: string; + previewEntrypoint?: string; + exports?: string[]; + args?: any; + adapterFeatures?: AstroAdapterFeatures; + /** + * List of features supported by an adapter. + * + * If the adapter is not able to handle certain configurations, Astro will throw an error. + */ + supportedAstroFeatures: AstroAdapterFeatureMap; +} + +export type AstroAdapterFeatureMap = { + /** + * The adapter is able serve static pages + */ + staticOutput?: AdapterSupportsKind; + /** + * The adapter is able to serve pages that are static or rendered via server + */ + hybridOutput?: AdapterSupportsKind; + /** + * The adapter is able to serve SSR pages + */ + serverOutput?: AdapterSupportsKind; + /** + * The adapter can emit static assets + */ + assets?: AstroAssetsFeature; + + /** + * List of features that orbit around the i18n routing + */ + i18nDomains?: AdapterSupportsKind; + + /** + * The adapter is able to support `getSecret` exported from `astro:env/server` + */ + envGetSecret?: AdapterSupportsKind; +}; + +export interface AstroAssetsFeature { + supportKind?: AdapterSupportsKind; + /** + * Whether if this adapter deploys files in an environment that is compatible with the library `sharp` + */ + isSharpCompatible?: boolean; + /** + * Whether if this adapter deploys files in an environment that is compatible with the library `squoosh` + */ + isSquooshCompatible?: boolean; +} + +export interface AstroInternationalizationFeature { + /** + * The adapter should be able to create the proper redirects + */ + domains?: AdapterSupportsKind; +} + +/** + * IDs for different stages of JS script injection: + * - "before-hydration": Imported client-side, before the hydration script runs. Processed & resolved by Vite. + * - "head-inline": Injected into a script tag in the `` of every page. Not processed or resolved by Vite. + * - "page": Injected into the JavaScript bundle of every page. Processed & resolved by Vite. + * - "page-ssr": Injected into the frontmatter of every Astro page. Processed & resolved by Vite. + */ +export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' | 'page-ssr'; + +/** + * IDs for different priorities of injected routes and redirects: + * - "normal": Merge with discovered file-based project routes, behaving the same as if the route + * was defined as a file in the project. + * - "legacy": Use the old ordering of routes. Inject routes will override any file-based project route, + * and redirects will be overridden by any project route on conflict. + */ +export type RoutePriorityOverride = 'normal' | 'legacy'; + +export interface InjectedRoute { + pattern: string; + entrypoint: string; + prerender?: boolean; +} + +export interface ResolvedInjectedRoute extends InjectedRoute { + resolvedEntryPoint?: URL; +} + +export interface InjectedType { + filename: string; + content: string; +} + +export type AstroIntegrationMiddleware = { + order: 'pre' | 'post'; + entrypoint: string; +}; + +export type HookParameters< + Hook extends keyof AstroIntegration['hooks'], + Fn = AstroIntegration['hooks'][Hook], +> = Fn extends (...args: any) => any ? Parameters[0] : never; + +export interface BaseIntegrationHooks { + 'astro:config:setup': (options: { + config: AstroConfig; + command: 'dev' | 'build' | 'preview'; + isRestart: boolean; + updateConfig: (newConfig: DeepPartial) => AstroConfig; + addRenderer: (renderer: AstroRenderer) => void; + addWatchFile: (path: URL | string) => void; + injectScript: (stage: InjectedScriptStage, content: string) => void; + injectRoute: (injectRoute: InjectedRoute) => void; + addClientDirective: (directive: ClientDirectiveConfig) => void; + // TODO: Deprecate the `string` overload once a few apps have been migrated to the new API. + addDevToolbarApp: (entrypoint: DevToolbarAppEntry | string) => void; + addMiddleware: (mid: AstroIntegrationMiddleware) => void; + logger: AstroIntegrationLogger; + }) => void | Promise; + 'astro:config:done': (options: { + config: AstroConfig; + setAdapter: (adapter: AstroAdapter) => void; + injectTypes: (injectedType: InjectedType) => URL; + logger: AstroIntegrationLogger; + }) => void | Promise; + 'astro:server:setup': (options: { + server: ViteDevServer; + logger: AstroIntegrationLogger; + toolbar: ReturnType; + }) => void | Promise; + 'astro:server:start': (options: { + address: AddressInfo; + logger: AstroIntegrationLogger; + }) => void | Promise; + 'astro:server:done': (options: { logger: AstroIntegrationLogger }) => void | Promise; + 'astro:build:ssr': (options: { + manifest: SerializedSSRManifest; + /** + * This maps a {@link RouteData} to an {@link URL}, this URL represents + * the physical file you should import. + */ + entryPoints: Map; + /** + * File path of the emitted middleware + */ + middlewareEntryPoint: URL | undefined; + logger: AstroIntegrationLogger; + }) => void | Promise; + 'astro:build:start': (options: { logger: AstroIntegrationLogger }) => void | Promise; + 'astro:build:setup': (options: { + vite: ViteInlineConfig; + pages: Map; + target: 'client' | 'server'; + updateConfig: (newConfig: ViteInlineConfig) => void; + logger: AstroIntegrationLogger; + }) => void | Promise; + 'astro:build:generated': (options: { + dir: URL; + logger: AstroIntegrationLogger; + }) => void | Promise; + 'astro:build:done': (options: { + pages: { pathname: string }[]; + dir: URL; + routes: RouteData[]; + logger: AstroIntegrationLogger; + cacheManifest: boolean; + }) => void | Promise; + 'astro:route:setup': (options: { + route: RouteOptions; + logger: AstroIntegrationLogger; + }) => void | Promise; +} + +export interface AstroIntegration { + /** The name of the integration. */ + name: string; + /** The different hooks available to extend. */ + hooks: { + [K in keyof Astro.IntegrationHooks]?: Astro.IntegrationHooks[K]; + } & Partial>; +} diff --git a/packages/astro/src/types/public/internal.ts b/packages/astro/src/types/public/internal.ts new file mode 100644 index 000000000000..bee15c6f75c0 --- /dev/null +++ b/packages/astro/src/types/public/internal.ts @@ -0,0 +1,202 @@ +// TODO: Should the types here really be public? + +import type { ErrorPayload as ViteErrorPayload } from 'vite'; +import type { AstroCookies } from '../../core/cookies/cookies.js'; +import type { AstroComponentInstance } from '../../runtime/server/index.js'; +import type { Params } from './common.js'; +import type { AstroConfig, RedirectConfig } from './config.js'; +import type { AstroGlobal, AstroGlobalPartial } from './context.js'; +import type { AstroRenderer } from './integrations.js'; + +export type { SSRManifest } from '../../core/app/types.js'; + +export interface NamedSSRLoadedRendererValue extends SSRLoadedRendererValue { + name: string; +} + +export interface SSRLoadedRendererValue { + name?: string; + check: AsyncRendererComponentFn; + renderToStaticMarkup: AsyncRendererComponentFn<{ + html: string; + attrs?: Record; + }>; + supportsAstroStaticSlot?: boolean; + /** + * If provided, Astro will call this function and inject the returned + * script in the HTML before the first component handled by this renderer. + * + * This feature is needed by some renderers (in particular, by Solid). The + * Solid official hydration script sets up a page-level data structure. + * It is mainly used to transfer data between the server side render phase + * and the browser application state. Solid Components rendered later in + * the HTML may inject tiny scripts into the HTML that call into this + * page-level data structure. + */ + renderHydrationScript?: () => string; +} + +export interface RouteData { + route: string; + component: string; + generate: (data?: any) => string; + params: string[]; + pathname?: string; + // expose the real path name on SSG + distURL?: URL; + pattern: RegExp; + segments: RoutePart[][]; + type: RouteType; + prerender: boolean; + redirect?: RedirectConfig; + redirectRoute?: RouteData; + fallbackRoutes: RouteData[]; + isIndex: boolean; +} + +/** + * - page: a route that lives in the file system, usually an Astro component + * - endpoint: a route that lives in the file system, usually a JS file that exposes endpoints methods + * - redirect: a route points to another route that lives in the file system + * - fallback: a route that doesn't exist in the file system that needs to be handled with other means, usually the middleware + */ +export type RouteType = 'page' | 'endpoint' | 'redirect' | 'fallback'; + +export interface RoutePart { + content: string; + dynamic: boolean; + spread: boolean; +} + +export interface AstroComponentMetadata { + displayName: string; + hydrate?: 'load' | 'idle' | 'visible' | 'media' | 'only'; + hydrateArgs?: any; + componentUrl?: string; + componentExport?: { value: string; namespace?: boolean }; + astroStaticSlot: true; +} + +export type AsyncRendererComponentFn = ( + Component: any, + props: any, + slots: Record, + metadata?: AstroComponentMetadata, +) => Promise; + +export interface NamedSSRLoadedRendererValue extends SSRLoadedRendererValue { + name: string; +} + +export interface SSRLoadedRendererValue { + name?: string; + check: AsyncRendererComponentFn; + renderToStaticMarkup: AsyncRendererComponentFn<{ + html: string; + attrs?: Record; + }>; + supportsAstroStaticSlot?: boolean; + /** + * If provided, Astro will call this function and inject the returned + * script in the HTML before the first component handled by this renderer. + * + * This feature is needed by some renderers (in particular, by Solid). The + * Solid official hydration script sets up a page-level data structure. + * It is mainly used to transfer data between the server side render phase + * and the browser application state. Solid Components rendered later in + * the HTML may inject tiny scripts into the HTML that call into this + * page-level data structure. + */ + renderHydrationScript?: () => string; +} + +export interface SSRLoadedRenderer extends Pick { + ssr: SSRLoadedRendererValue; +} + +export interface SSRElement { + props: Record; + children: string; +} + +export interface SSRResult { + /** + * Whether the page has failed with a non-recoverable error, or the client disconnected. + */ + cancelled: boolean; + base: string; + styles: Set; + scripts: Set; + links: Set; + componentMetadata: Map; + inlinedScripts: Map; + createAstro( + Astro: AstroGlobalPartial, + props: Record, + slots: Record | null, + ): AstroGlobal; + params: Params; + resolve: (s: string) => Promise; + response: AstroGlobal['response']; + request: AstroGlobal['request']; + actionResult?: ReturnType; + renderers: SSRLoadedRenderer[]; + /** + * Map of directive name (e.g. `load`) to the directive script code + */ + clientDirectives: Map; + compressHTML: boolean; + partial: boolean; + /** + * Only used for logging + */ + pathname: string; + cookies: AstroCookies | undefined; + serverIslandNameMap: Map; + trailingSlash: AstroConfig['trailingSlash']; + key: Promise; + _metadata: SSRMetadata; +} + +/** + * A hint on whether the Astro runtime needs to wait on a component to render head + * content. The meanings: + * + * - __none__ (default) The component does not propagation head content. + * - __self__ The component appends head content. + * - __in-tree__ Another component within this component's dependency tree appends head content. + * + * These are used within the runtime to know whether or not a component should be waited on. + */ +export type PropagationHint = 'none' | 'self' | 'in-tree'; + +export type SSRComponentMetadata = { + propagation: PropagationHint; + containsHead: boolean; +}; + +/** + * Ephemeral and mutable state during rendering that doesn't rely + * on external configuration + */ +export interface SSRMetadata { + hasHydrationScript: boolean; + /** + * Names of renderers that have injected their hydration scripts + * into the current page. For example, Solid SSR needs a hydration + * script in the page HTML before the first Solid component. + */ + rendererSpecificHydrationScripts: Set; + /** + * Used by `renderScript` to track script ids that have been rendered, + * so we only render each once. + */ + renderedScripts: Set; + hasDirectives: Set; + hasRenderedHead: boolean; + headInTree: boolean; + extraHead: string[]; + propagators: Set; +} + +export type SSRError = Error & ViteErrorPayload['err']; diff --git a/packages/astro/src/types/public/preview.ts b/packages/astro/src/types/public/preview.ts new file mode 100644 index 000000000000..e2794303f39c --- /dev/null +++ b/packages/astro/src/types/public/preview.ts @@ -0,0 +1,28 @@ +import type { OutgoingHttpHeaders } from 'node:http'; +import type { AstroIntegrationLogger } from '../../core/logger/core.js'; + +export interface PreviewServer { + host?: string; + port: number; + closed(): Promise; + stop(): Promise; +} + +export interface PreviewServerParams { + outDir: URL; + client: URL; + serverEntrypoint: URL; + host: string | undefined; + port: number; + base: string; + logger: AstroIntegrationLogger; + headers?: OutgoingHttpHeaders; +} + +export type CreatePreviewServer = ( + params: PreviewServerParams, +) => PreviewServer | Promise; + +export interface PreviewModule { + default: CreatePreviewServer; +} diff --git a/packages/astro/src/types/public/toolbar.ts b/packages/astro/src/types/public/toolbar.ts new file mode 100644 index 000000000000..7beaab3bb84f --- /dev/null +++ b/packages/astro/src/types/public/toolbar.ts @@ -0,0 +1,96 @@ +import type { + ToolbarAppEventTarget, + ToolbarServerHelpers, +} from '../../runtime/client/dev-toolbar/helpers.js'; +import type { + AstroDevToolbar, + DevToolbarCanvas, +} from '../../runtime/client/dev-toolbar/toolbar.js'; +import type { Icon } from '../../runtime/client/dev-toolbar/ui-library/icons.js'; +import type { + DevToolbarBadge, + DevToolbarButton, + DevToolbarCard, + DevToolbarHighlight, + DevToolbarIcon, + DevToolbarRadioCheckbox, + DevToolbarSelect, + DevToolbarToggle, + DevToolbarTooltip, + DevToolbarWindow, +} from '../../runtime/client/dev-toolbar/ui-library/index.js'; + +declare global { + interface HTMLElementTagNameMap { + 'astro-dev-toolbar': AstroDevToolbar; + 'astro-dev-toolbar-window': DevToolbarWindow; + 'astro-dev-toolbar-app-canvas': DevToolbarCanvas; + 'astro-dev-toolbar-tooltip': DevToolbarTooltip; + 'astro-dev-toolbar-highlight': DevToolbarHighlight; + 'astro-dev-toolbar-toggle': DevToolbarToggle; + 'astro-dev-toolbar-badge': DevToolbarBadge; + 'astro-dev-toolbar-button': DevToolbarButton; + 'astro-dev-toolbar-icon': DevToolbarIcon; + 'astro-dev-toolbar-card': DevToolbarCard; + 'astro-dev-toolbar-select': DevToolbarSelect; + 'astro-dev-toolbar-radio-checkbox': DevToolbarRadioCheckbox; + } +} + +type DevToolbarAppMeta = { + id: string; + name: string; + icon?: Icon; +}; + +// The param passed to `addDevToolbarApp` in the integration +export type DevToolbarAppEntry = DevToolbarAppMeta & { + entrypoint: string; +}; + +// Public API for the dev toolbar +export type DevToolbarApp = { + /** + * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. + * + * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` + * + * In the future, putting these properties directly on the app object will be removed. + */ + id?: string; + /** + * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. + * + * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` + * + * In the future, putting these properties directly on the app object will be removed. + */ + name?: string; + /** + * @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`. + * + * Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })` + * + * In the future, putting these properties directly on the app object will be removed. + */ + icon?: Icon; + init?( + canvas: ShadowRoot, + app: ToolbarAppEventTarget, + server: ToolbarServerHelpers, + ): void | Promise; + beforeTogglingOff?(canvas: ShadowRoot): boolean | Promise; +}; + +// An app that has been loaded and as such contain all of its properties +export type ResolvedDevToolbarApp = DevToolbarAppMeta & Omit; + +export type DevToolbarMetadata = Window & + typeof globalThis & { + __astro_dev_toolbar__: { + root: string; + version: string; + latestAstroVersion: string | undefined; + debugInfo: string; + }; + }; diff --git a/packages/astro/src/types/public/view-transitions.ts b/packages/astro/src/types/public/view-transitions.ts new file mode 100644 index 000000000000..1acd5003bff4 --- /dev/null +++ b/packages/astro/src/types/public/view-transitions.ts @@ -0,0 +1,40 @@ +import type { + TransitionBeforePreparationEvent, + TransitionBeforeSwapEvent, +} from '../../transitions/events.js'; + +export interface TransitionAnimation { + name: string; // The name of the keyframe + delay?: number | string; + duration?: number | string; + easing?: string; + fillMode?: string; + direction?: string; +} + +export interface TransitionAnimationPair { + old: TransitionAnimation | TransitionAnimation[]; + new: TransitionAnimation | TransitionAnimation[]; +} + +export interface TransitionDirectionalAnimations { + forwards: TransitionAnimationPair; + backwards: TransitionAnimationPair; +} + +export type TransitionAnimationValue = + | 'initial' + | 'slide' + | 'fade' + | 'none' + | TransitionDirectionalAnimations; + +declare global { + interface DocumentEventMap { + 'astro:before-preparation': TransitionBeforePreparationEvent; + 'astro:after-preparation': Event; + 'astro:before-swap': TransitionBeforeSwapEvent; + 'astro:after-swap': Event; + 'astro:page-load': Event; + } +} diff --git a/packages/astro/src/@types/typed-emitter.ts b/packages/astro/src/types/typed-emitter.ts similarity index 100% rename from packages/astro/src/@types/typed-emitter.ts rename to packages/astro/src/types/typed-emitter.ts diff --git a/packages/astro/src/virtual-modules/container.ts b/packages/astro/src/virtual-modules/container.ts index 420b3e3e2d94..3efc626d9f2c 100644 --- a/packages/astro/src/virtual-modules/container.ts +++ b/packages/astro/src/virtual-modules/container.ts @@ -1,4 +1,5 @@ -import type { AstroRenderer, SSRLoadedRenderer } from '../@types/astro.js'; +import type { AstroRenderer } from '../types/public/integrations.js'; +import type { SSRLoadedRenderer } from '../types/public/internal.js'; /** * Use this function to provide renderers to the `AstroContainer`: diff --git a/packages/astro/src/virtual-modules/i18n.ts b/packages/astro/src/virtual-modules/i18n.ts index aacdd80a96e1..927d479aab32 100644 --- a/packages/astro/src/virtual-modules/i18n.ts +++ b/packages/astro/src/virtual-modules/i18n.ts @@ -1,9 +1,3 @@ -import type { - APIContext, - AstroConfig, - MiddlewareHandler, - ValidRedirectStatus, -} from '../@types/astro.js'; import type { SSRManifest } from '../core/app/types.js'; import { IncorrectStrategyForI18n } from '../core/errors/errors-data.js'; import { AstroError } from '../core/errors/index.js'; @@ -11,6 +5,9 @@ import * as I18nInternals from '../i18n/index.js'; import type { RedirectToFallback } from '../i18n/index.js'; import { toRoutingStrategy } from '../i18n/utils.js'; import type { I18nInternalConfig } from '../i18n/vite-plugin-i18n.js'; +import type { MiddlewareHandler } from '../types/public/common.js'; +import type { AstroConfig, ValidRedirectStatus } from '../types/public/config.js'; +import type { APIContext } from '../types/public/context.js'; export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/base.ts b/packages/astro/src/vite-plugin-astro-server/base.ts index bea642f6f8c7..562b89ba2204 100644 --- a/packages/astro/src/vite-plugin-astro-server/base.ts +++ b/packages/astro/src/vite-plugin-astro-server/base.ts @@ -1,5 +1,5 @@ import type * as vite from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; import * as fs from 'node:fs'; import path from 'node:path'; diff --git a/packages/astro/src/vite-plugin-astro-server/error.ts b/packages/astro/src/vite-plugin-astro-server/error.ts index 24db9dc49b84..25a237cc278f 100644 --- a/packages/astro/src/vite-plugin-astro-server/error.ts +++ b/packages/astro/src/vite-plugin-astro-server/error.ts @@ -1,10 +1,10 @@ -import type { AstroConfig } from '../@types/astro.js'; import type { ModuleLoader } from '../core/module-loader/index.js'; import type { DevPipeline } from './pipeline.js'; import { collectErrorMetadata } from '../core/errors/dev/index.js'; import { createSafeError } from '../core/errors/index.js'; import { formatErrorMessage } from '../core/messages.js'; +import type { AstroConfig } from '../types/public/config.js'; export function recordServerError( loader: ModuleLoader, diff --git a/packages/astro/src/vite-plugin-astro-server/metadata.ts b/packages/astro/src/vite-plugin-astro-server/metadata.ts index 793ee5669312..7f358ade0c46 100644 --- a/packages/astro/src/vite-plugin-astro-server/metadata.ts +++ b/packages/astro/src/vite-plugin-astro-server/metadata.ts @@ -1,6 +1,6 @@ -import type { SSRComponentMetadata, SSRResult } from '../@types/astro.js'; import type { ModuleInfo, ModuleLoader } from '../core/module-loader/index.js'; import { viteID } from '../core/util.js'; +import type { SSRComponentMetadata, SSRResult } from '../types/public/internal.js'; import { getAstroMetadata } from '../vite-plugin-astro/index.js'; import { crawlGraph } from './vite.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/pipeline.ts b/packages/astro/src/vite-plugin-astro-server/pipeline.ts index 4386eb154bda..5a672279ede8 100644 --- a/packages/astro/src/vite-plugin-astro-server/pipeline.ts +++ b/packages/astro/src/vite-plugin-astro-server/pipeline.ts @@ -1,15 +1,4 @@ import { fileURLToPath } from 'node:url'; -import type { - AstroSettings, - ComponentInstance, - DevToolbarMetadata, - ManifestData, - RewritePayload, - RouteData, - SSRElement, - SSRLoadedRenderer, - SSRManifest, -} from '../@types/astro.js'; import { getInfoOutput } from '../cli/info/index.js'; import { type HeadElements } from '../core/base-pipeline.js'; import { ASTRO_VERSION } from '../core/constants.js'; @@ -22,6 +11,15 @@ import { createDefaultRoutes } from '../core/routing/default.js'; import { findRouteToRewrite } from '../core/routing/rewrite.js'; import { isPage, isServerLikeOutput, viteID } from '../core/util.js'; import { resolveIdToUrl } from '../core/viteUtils.js'; +import type { AstroSettings, ComponentInstance, ManifestData } from '../types/astro.js'; +import type { RewritePayload } from '../types/public/common.js'; +import type { + RouteData, + SSRElement, + SSRLoadedRenderer, + SSRManifest, +} from '../types/public/internal.js'; +import type { DevToolbarMetadata } from '../types/public/toolbar.js'; import { PAGE_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; import { getStylesForURL } from './css.js'; import { getComponentMetadata } from './metadata.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index 2458b5b8d360..3015f1003f82 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -2,8 +2,7 @@ import { AsyncLocalStorage } from 'node:async_hooks'; import type fs from 'node:fs'; import { IncomingMessage } from 'node:http'; import type * as vite from 'vite'; -import type { AstroSettings, ManifestData, SSRManifest } from '../@types/astro.js'; -import type { SSRManifestI18n } from '../core/app/types.js'; +import type { SSRManifest, SSRManifestI18n } from '../core/app/types.js'; import { createKey } from '../core/encryption.js'; import { getViteErrorPayload } from '../core/errors/dev/index.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; @@ -13,6 +12,7 @@ import { createViteLoader } from '../core/module-loader/index.js'; import { injectDefaultRoutes } from '../core/routing/default.js'; import { createRouteManifest } from '../core/routing/index.js'; import { toRoutingStrategy } from '../i18n/utils.js'; +import type { AstroSettings, ManifestData } from '../types/astro.js'; import { baseMiddleware } from './base.js'; import { createController } from './controller.js'; import { recordServerError } from './error.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/request.ts b/packages/astro/src/vite-plugin-astro-server/request.ts index b231bfde35c6..98cf2b5022dd 100644 --- a/packages/astro/src/vite-plugin-astro-server/request.ts +++ b/packages/astro/src/vite-plugin-astro-server/request.ts @@ -1,6 +1,6 @@ import type http from 'node:http'; -import type { ManifestData } from '../@types/astro.js'; import { removeTrailingForwardSlash } from '../core/path.js'; +import type { ManifestData } from '../types/astro.js'; import type { DevServerController } from './controller.js'; import { runWithErrorHandling } from './controller.js'; import { recordServerError } from './error.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index aa70d5324582..c59af5c80c7a 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -1,5 +1,4 @@ import type http from 'node:http'; -import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro.js'; import { REROUTE_DIRECTIVE_HEADER, REWRITE_DIRECTIVE_HEADER_KEY, @@ -13,6 +12,8 @@ import { type SSROptions, getProps } from '../core/render/index.js'; import { createRequest } from '../core/request.js'; import { matchAllRoutes } from '../core/routing/index.js'; import { getSortedPreloadedMatches } from '../prerender/routing.js'; +import type { ComponentInstance, ManifestData } from '../types/astro.js'; +import type { RouteData } from '../types/public/internal.js'; import type { DevPipeline } from './pipeline.js'; import { writeSSRResult, writeWebResponse } from './response.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/scripts.ts b/packages/astro/src/vite-plugin-astro-server/scripts.ts index e21d44116324..95763ab34ae8 100644 --- a/packages/astro/src/vite-plugin-astro-server/scripts.ts +++ b/packages/astro/src/vite-plugin-astro-server/scripts.ts @@ -1,8 +1,8 @@ -import type { SSRElement } from '../@types/astro.js'; import type { ModuleInfo, ModuleLoader } from '../core/module-loader/index.js'; import { createModuleScriptElementWithSrc } from '../core/render/ssr-element.js'; import { viteID } from '../core/util.js'; import { rootRelativePath } from '../core/viteUtils.js'; +import type { SSRElement } from '../types/public/internal.js'; import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types.js'; import { crawlGraph } from './vite.js'; diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index 8dfb68a16fd1..78d6c416f0ff 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -1,7 +1,7 @@ import { type ESBuildTransformResult, transformWithEsbuild } from 'vite'; -import type { AstroConfig } from '../@types/astro.js'; import { type CompileProps, type CompileResult, compile } from '../core/compile/index.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroConfig } from '../types/public/config.js'; import { getFileInfo } from '../vite-plugin-utils/index.js'; import type { CompileMetadata } from './types.js'; import { frontmatterRE } from './utils.js'; diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index d5968a905953..b7dd0a2b6d6d 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -1,7 +1,7 @@ import type { SourceDescription } from 'rollup'; import type * as vite from 'vite'; -import type { AstroConfig, AstroSettings } from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroSettings } from '../types/astro.js'; import type { PluginCssMetadata as AstroPluginCssMetadata, PluginMetadata as AstroPluginMetadata, @@ -9,6 +9,7 @@ import type { } from './types.js'; import { normalizePath } from 'vite'; +import type { AstroConfig } from '../types/public/config.js'; import { hasSpecialQueries, normalizeFilename } from '../vite-plugin-utils/index.js'; import { type CompileAstroResult, compileAstro } from './compile.js'; import { handleHotUpdate } from './hmr.js'; diff --git a/packages/astro/src/vite-plugin-astro/types.ts b/packages/astro/src/vite-plugin-astro/types.ts index ee5003941526..195745443e06 100644 --- a/packages/astro/src/vite-plugin-astro/types.ts +++ b/packages/astro/src/vite-plugin-astro/types.ts @@ -1,6 +1,6 @@ import type { HoistedScript, TransformResult } from '@astrojs/compiler'; -import type { PropagationHint } from '../@types/astro.js'; import type { CompileCssResult } from '../core/compile/types.js'; +import type { PropagationHint } from '../types/public/internal.js'; export interface PageOptions { prerender?: boolean; diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index cb9bdc48c186..9b102c5648cb 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import type { CompilerOptions } from 'typescript'; import { type ResolvedConfig, type Plugin as VitePlugin, normalizePath } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; type Alias = { find: RegExp; diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index 350a29b7ffe1..127575f3918a 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -4,8 +4,9 @@ import { bold } from 'kleur/colors'; import MagicString from 'magic-string'; import type * as vite from 'vite'; import { loadEnv } from 'vite'; -import type { AstroConfig, AstroSettings } from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { AstroConfig } from '../types/public/config.js'; interface EnvPluginOptions { settings: AstroSettings; diff --git a/packages/astro/src/vite-plugin-head/index.ts b/packages/astro/src/vite-plugin-head/index.ts index a7e35dedb119..c9ec2460dcb6 100644 --- a/packages/astro/src/vite-plugin-head/index.ts +++ b/packages/astro/src/vite-plugin-head/index.ts @@ -1,11 +1,11 @@ import type { ModuleInfo } from 'rollup'; import type * as vite from 'vite'; -import type { SSRComponentMetadata, SSRResult } from '../@types/astro.js'; import type { AstroBuildPlugin } from '../core/build/plugin.js'; import type { PluginMetadata } from '../vite-plugin-astro/types.js'; import { getParentModuleInfos, getTopLevelPageModuleInfos } from '../core/build/graph.js'; import type { BuildInternals } from '../core/build/internal.js'; +import type { SSRComponentMetadata, SSRResult } from '../types/public/internal.js'; import { getAstroMetadata } from '../vite-plugin-astro/index.js'; // Detect this in comments, both in .astro components and in js/ts files. diff --git a/packages/astro/src/vite-plugin-integrations-container/index.ts b/packages/astro/src/vite-plugin-integrations-container/index.ts index 49122b24fd84..22623284ec45 100644 --- a/packages/astro/src/vite-plugin-integrations-container/index.ts +++ b/packages/astro/src/vite-plugin-integrations-container/index.ts @@ -1,10 +1,11 @@ import type { PluginContext } from 'rollup'; import type { Plugin as VitePlugin } from 'vite'; -import type { AstroSettings, InjectedRoute, ResolvedInjectedRoute } from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; +import type { AstroSettings } from '../types/astro.js'; import { normalizePath } from 'vite'; import { runHookServerSetup } from '../integrations/hooks.js'; +import type { InjectedRoute, ResolvedInjectedRoute } from '../types/public/integrations.js'; /** Connect Astro integrations into Vite, as needed. */ export default function astroIntegrationsContainerPlugin({ diff --git a/packages/astro/src/vite-plugin-markdown/content-entry-type.ts b/packages/astro/src/vite-plugin-markdown/content-entry-type.ts index 9b78d8f35149..48a45294ef3a 100644 --- a/packages/astro/src/vite-plugin-markdown/content-entry-type.ts +++ b/packages/astro/src/vite-plugin-markdown/content-entry-type.ts @@ -1,7 +1,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; import { createMarkdownProcessor } from '@astrojs/markdown-remark'; -import type { ContentEntryType } from '../@types/astro.js'; import { safeParseFrontmatter } from '../content/utils.js'; +import type { ContentEntryType } from '../types/public/content.js'; export const markdownContentEntryType: ContentEntryType = { extensions: ['.md'], @@ -17,8 +17,8 @@ export const markdownContentEntryType: ContentEntryType = { // We need to handle propagation for Markdown because they support layouts which will bring in styles. handlePropagation: true, - async getRenderFunction(settings) { - const processor = await createMarkdownProcessor(settings.config.markdown); + async getRenderFunction(config) { + const processor = await createMarkdownProcessor(config.markdown); return async function renderToString(entry) { if (!entry.body) { return { diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 37af2dc50c53..694b96448fb5 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -7,12 +7,12 @@ import { } from '@astrojs/markdown-remark'; import type { Plugin } from 'vite'; import { normalizePath } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; import { safeParseFrontmatter } from '../content/utils.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import type { Logger } from '../core/logger/core.js'; import { isMarkdownFile } from '../core/util.js'; import { shorthash } from '../runtime/server/shorthash.js'; +import type { AstroSettings } from '../types/astro.js'; import { createDefaultAstroMetadata } from '../vite-plugin-astro/metadata.js'; import { getFileInfo } from '../vite-plugin-utils/index.js'; import { type MarkdownImagePath, getMarkdownCodeForImages } from './images.js'; diff --git a/packages/astro/src/vite-plugin-mdx/transform-jsx.ts b/packages/astro/src/vite-plugin-mdx/transform-jsx.ts index c3bb8ed76214..31db2793124f 100644 --- a/packages/astro/src/vite-plugin-mdx/transform-jsx.ts +++ b/packages/astro/src/vite-plugin-mdx/transform-jsx.ts @@ -1,7 +1,7 @@ import babel from '@babel/core'; import type { TransformResult } from 'rollup'; -import type { JSXTransformConfig } from '../@types/astro.js'; import { jsxTransformOptions } from '../jsx/transform-options.js'; +import type { JSXTransformConfig } from '../types/astro.js'; import type { PluginMetadata } from '../vite-plugin-astro/types.js'; import { tagExportsPlugin } from './tag.js'; diff --git a/packages/astro/src/vite-plugin-scanner/index.ts b/packages/astro/src/vite-plugin-scanner/index.ts index 842857777a87..2633743ae554 100644 --- a/packages/astro/src/vite-plugin-scanner/index.ts +++ b/packages/astro/src/vite-plugin-scanner/index.ts @@ -2,12 +2,13 @@ import { extname } from 'node:path'; import { bold } from 'kleur/colors'; import type { Plugin as VitePlugin } from 'vite'; import { normalizePath } from 'vite'; -import type { AstroSettings, RouteOptions } from '../@types/astro.js'; import { type Logger } from '../core/logger/core.js'; import { isEndpoint, isPage, isServerLikeOutput } from '../core/util.js'; import { rootRelativePath } from '../core/viteUtils.js'; import { runHookRouteSetup } from '../integrations/hooks.js'; import { getPrerenderDefault } from '../prerender/utils.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { RouteOptions } from '../types/public/integrations.js'; import type { PageOptions } from '../vite-plugin-astro/types.js'; import { scan } from './scan.js'; diff --git a/packages/astro/src/vite-plugin-scanner/scan.ts b/packages/astro/src/vite-plugin-scanner/scan.ts index 52b2d6bd8289..35e3de20a84f 100644 --- a/packages/astro/src/vite-plugin-scanner/scan.ts +++ b/packages/astro/src/vite-plugin-scanner/scan.ts @@ -1,4 +1,4 @@ -import type { AstroSettings } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; import type { PageOptions } from '../vite-plugin-astro/types.js'; import * as eslexer from 'es-module-lexer'; diff --git a/packages/astro/src/vite-plugin-scripts/index.ts b/packages/astro/src/vite-plugin-scripts/index.ts index 9b2848923752..f87f6a381cc8 100644 --- a/packages/astro/src/vite-plugin-scripts/index.ts +++ b/packages/astro/src/vite-plugin-scripts/index.ts @@ -1,5 +1,6 @@ import type { ConfigEnv, Plugin as VitePlugin } from 'vite'; -import type { AstroSettings, InjectedScriptStage } from '../@types/astro.js'; +import type { AstroSettings } from '../types/astro.js'; +import type { InjectedScriptStage } from '../types/public/integrations.js'; // NOTE: We can't use the virtual "\0" ID convention because we need to // inject these as ESM imports into actual code, where they would not diff --git a/packages/astro/src/vite-plugin-scripts/page-ssr.ts b/packages/astro/src/vite-plugin-scripts/page-ssr.ts index 00e907b03cc6..05d8be18dacd 100644 --- a/packages/astro/src/vite-plugin-scripts/page-ssr.ts +++ b/packages/astro/src/vite-plugin-scripts/page-ssr.ts @@ -1,7 +1,7 @@ import MagicString from 'magic-string'; import { type Plugin as VitePlugin, normalizePath } from 'vite'; -import type { AstroSettings } from '../@types/astro.js'; import { isPage } from '../core/util.js'; +import type { AstroSettings } from '../types/astro.js'; import { PAGE_SSR_SCRIPT_ID } from './index.js'; export default function astroScriptsPostPlugin({ diff --git a/packages/astro/src/vite-plugin-utils/index.ts b/packages/astro/src/vite-plugin-utils/index.ts index a0133104cbda..2e7948bdd6ea 100644 --- a/packages/astro/src/vite-plugin-utils/index.ts +++ b/packages/astro/src/vite-plugin-utils/index.ts @@ -1,12 +1,12 @@ import { fileURLToPath } from 'node:url'; import ancestor from 'common-ancestor-path'; -import type { AstroConfig } from '../@types/astro.js'; import { appendExtension, appendForwardSlash, removeLeadingForwardSlashWindows, } from '../core/path.js'; import { viteID } from '../core/util.js'; +import type { AstroConfig } from '../types/public/config.js'; export function getFileInfo(id: string, config: AstroConfig) { const sitePathname = appendForwardSlash( diff --git a/packages/astro/templates/actions.mjs b/packages/astro/templates/actions.mjs index 587f6ed9b7c1..823699e15e65 100644 --- a/packages/astro/templates/actions.mjs +++ b/packages/astro/templates/actions.mjs @@ -55,7 +55,7 @@ function toActionProxy(actionCallback = {}, aggregatedPath = '') { /** * @param {*} param argument passed to the action when called server or client-side. * @param {string} path Built path to call action by path name. - * @param {import('../dist/@types/astro.d.ts').APIContext | undefined} context Injected API context when calling actions from the server. + * @param {import('../dist/types/public/context.js').APIContext | undefined} context Injected API context when calling actions from the server. * Usage: `actions.[name](param)`. * @returns {Promise>} */ diff --git a/packages/astro/test/core-image-unconventional-settings.test.js b/packages/astro/test/core-image-unconventional-settings.test.js index edbfab6f6343..b5d5fc6640de 100644 --- a/packages/astro/test/core-image-unconventional-settings.test.js +++ b/packages/astro/test/core-image-unconventional-settings.test.js @@ -6,7 +6,7 @@ import { testImageService } from './test-image-service.js'; import { loadFixture } from './test-utils.js'; /** - ** @typedef {import('../src/@types/astro').AstroInlineConfig & { root?: string | URL }} AstroInlineConfig + ** @typedef {import('../src/types/public/config.js').AstroInlineConfig & { root?: string | URL }} AstroInlineConfig */ /** @type {AstroInlineConfig} */ diff --git a/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts b/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts index 261fb6bb7dc7..25777dce8adb 100644 --- a/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts +++ b/packages/astro/test/fixtures/core-image-ssr/src/pages/api.ts @@ -1,4 +1,4 @@ -import type { APIRoute } from "../../../../../src/@types/astro"; +import type { APIRoute } from "astro" export const GET = (async ({ params, request }) => { const url = new URL(request.url); diff --git a/packages/astro/test/fixtures/ssr-prerender-chunks/deps/test-adapter/index.js b/packages/astro/test/fixtures/ssr-prerender-chunks/deps/test-adapter/index.js index 82b7b64b1fc9..06eb02e2c6ce 100644 --- a/packages/astro/test/fixtures/ssr-prerender-chunks/deps/test-adapter/index.js +++ b/packages/astro/test/fixtures/ssr-prerender-chunks/deps/test-adapter/index.js @@ -1,6 +1,6 @@ /** * - * @returns {import('../src/@types/astro').AstroIntegration} + * @returns {import('../../../../../src/types/public/integrations.js').AstroIntegration} */ export default function () { return { @@ -82,4 +82,4 @@ export default function () { }, }, }; -} \ No newline at end of file +} diff --git a/packages/astro/test/test-adapter.js b/packages/astro/test/test-adapter.js index fc5249561279..4a2ac65d0047 100644 --- a/packages/astro/test/test-adapter.js +++ b/packages/astro/test/test-adapter.js @@ -1,11 +1,11 @@ import { viteID } from '../dist/core/util.js'; /** - * @typedef {import('../src/@types/astro.js').AstroAdapter} AstroAdapter - * @typedef {import('../src/@types/astro.js').AstroIntegration} AstroIntegration - * @typedef {import('../src/@types/astro.js').HookParameters<"astro:build:ssr">['entryPoints']} EntryPoints - * @typedef {import('../src/@types/astro.js').HookParameters<"astro:build:ssr">['middlewareEntryPoint']} MiddlewareEntryPoint - * @typedef {import('../src/@types/astro.js').HookParameters<"astro:build:done">['routes']} Routes + * @typedef {import('../src/types/public/integrations.js').AstroAdapter} AstroAdapter + * @typedef {import('../src/types/public/integrations.js').AstroIntegration} AstroIntegration + * @typedef {import('../src/types/public/integrations.js').HookParameters<"astro:build:ssr">['entryPoints']} EntryPoints + * @typedef {import('../src/types/public/integrations.js').HookParameters<"astro:build:ssr">['middlewareEntryPoint']} MiddlewareEntryPoint + * @typedef {import('../src/types/public/integrations.js').HookParameters<"astro:build:done">['routes']} Routes */ /** diff --git a/packages/astro/test/test-image-service.js b/packages/astro/test/test-image-service.js index 35a5fa2c8625..de076425cd9a 100644 --- a/packages/astro/test/test-image-service.js +++ b/packages/astro/test/test-image-service.js @@ -12,7 +12,7 @@ export function testImageService(config = {}) { }; } -/** @type {import("../dist/@types/astro").LocalImageService} */ +/** @type {import("../dist/types/public/index.js").LocalImageService} */ export default { ...baseService, propertiesToHash: [...baseService.propertiesToHash, 'data-custom'], diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index 95edeebd2673..115f3c2d5f2e 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -23,8 +23,8 @@ process.env.ASTRO_TELEMETRY_DISABLED = true; /** * @typedef {import('../src/core/dev/dev').DevServer} DevServer - * @typedef {import('../src/@types/astro').AstroInlineConfig & { root?: string | URL }} AstroInlineConfig - * @typedef {import('../src/@types/astro').AstroConfig} AstroConfig + * @typedef {import('../src/types/public/config.js').AstroInlineConfig & { root?: string | URL }} AstroInlineConfig + * @typedef {import('../src/types/public/config.js').AstroConfig} AstroConfig * @typedef {import('../src/core/preview/index').PreviewServer} PreviewServer * @typedef {import('../src/core/app/index').App} App * @typedef {import('../src/cli/check/index').AstroChecker} AstroChecker diff --git a/packages/astro/test/types/call-action.ts b/packages/astro/test/types/call-action.ts index 91610558586f..8cadd1fb06e6 100644 --- a/packages/astro/test/types/call-action.ts +++ b/packages/astro/test/types/call-action.ts @@ -1,6 +1,6 @@ import { describe, it } from 'node:test'; import { expectTypeOf } from 'expect-type'; -import type { APIContext } from '../../dist/@types/astro.js'; +import type { APIContext } from '../../dist/types/public/context.js'; import { type ActionReturnType, defineAction } from '../../dist/actions/runtime/virtual/server.js'; import { z } from '../../zod.mjs'; diff --git a/packages/astro/test/units/test-utils.js b/packages/astro/test/units/test-utils.js index bab850b68530..a104ef2a40a2 100644 --- a/packages/astro/test/units/test-utils.js +++ b/packages/astro/test/units/test-utils.js @@ -211,8 +211,8 @@ export function createBasicPipeline(options = {}) { } /** - * @param {import('../../src/@types/astro.js').AstroInlineConfig} inlineConfig - * @returns {Promise} + * @param {import('../../src/types/public/config.js').AstroInlineConfig} inlineConfig + * @returns {Promise} */ export async function createBasicSettings(inlineConfig = {}) { if (!inlineConfig.root) { @@ -225,7 +225,7 @@ export async function createBasicSettings(inlineConfig = {}) { /** * @typedef {{ * fs?: typeof realFS, - * inlineConfig?: import('../../src/@types/astro.js').AstroInlineConfig, + * inlineConfig?: import('../../src/types/public/config.js').AstroInlineConfig, * logging?: import('../../src/core/logger/core').LogOptions, * }} RunInContainerOptions */ diff --git a/packages/astro/types.d.ts b/packages/astro/types.d.ts index b04f062fdba8..cc0f1c3d2371 100644 --- a/packages/astro/types.d.ts +++ b/packages/astro/types.d.ts @@ -1,6 +1,6 @@ import './astro-jsx'; -import type { AstroBuiltinAttributes } from './dist/@types/astro.js'; import type { OmitIndexSignature, Simplify } from './dist/type-utils.js'; +import type { AstroBuiltinAttributes } from './dist/types/public/elements.js'; /** Any supported HTML or SVG element name, as defined by the HTML specification */ export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements; diff --git a/packages/integrations/node/test/api-route.test.js b/packages/integrations/node/test/api-route.test.js index 804a5ccf4797..9743ce42d51c 100644 --- a/packages/integrations/node/test/api-route.test.js +++ b/packages/integrations/node/test/api-route.test.js @@ -7,7 +7,7 @@ import { createRequestAndResponse, loadFixture } from './test-utils.js'; describe('API routes', () => { /** @type {import('./test-utils').Fixture} */ let fixture; - /** @type {import('astro/src/@types/astro.js').PreviewServer} */ + /** @type {import('../../../astro/src/types/public/preview.js').PreviewServer} */ let previewServer; /** @type {URL} */ let baseUri;