From c8544a2651af4db1dcba0905500d77073836c255 Mon Sep 17 00:00:00 2001 From: Drew Powers <1369770+drwpow@users.noreply.github.com> Date: Tue, 16 Nov 2021 14:00:08 -0700 Subject: [PATCH] Clean up, simplify types (#1816) Also add JSDoc to external types --- packages/astro/package.json | 2 +- packages/astro/src/@types/astro-runtime.ts | 64 ------ .../src/@types/{astro-core.ts => astro.ts} | 184 ++++++++++-------- packages/astro/src/cli/check.ts | 2 +- packages/astro/src/cli/index.ts | 4 +- packages/astro/src/core/build/index.ts | 2 +- packages/astro/src/core/build/types.d.ts | 2 +- packages/astro/src/core/config.ts | 3 +- packages/astro/src/core/create-vite.ts | 2 +- packages/astro/src/core/dev/index.ts | 2 +- packages/astro/src/core/preview/index.ts | 2 +- packages/astro/src/core/ssr/css.ts | 2 +- packages/astro/src/core/ssr/index.ts | 20 +- packages/astro/src/core/ssr/paginate.ts | 12 +- packages/astro/src/core/ssr/routing.ts | 2 +- packages/astro/src/core/ssr/rss.ts | 4 +- packages/astro/src/core/util.ts | 2 +- packages/astro/src/runtime/client/idle.ts | 2 +- packages/astro/src/runtime/client/load.ts | 2 +- packages/astro/src/runtime/client/media.ts | 2 +- packages/astro/src/runtime/client/only.ts | 2 +- packages/astro/src/runtime/client/visible.ts | 2 +- .../astro/src/runtime/server/hydration.ts | 4 +- packages/astro/src/runtime/server/index.ts | 9 +- .../vite-plugin-astro-postprocess/index.ts | 2 +- packages/astro/src/vite-plugin-astro/index.ts | 2 +- .../astro/src/vite-plugin-build-css/index.ts | 2 +- .../src/vite-plugin-build-css/resolve.ts | 2 +- .../astro/src/vite-plugin-build-html/index.ts | 4 +- .../src/vite-plugin-config-alias/index.ts | 2 +- packages/astro/src/vite-plugin-jsx/index.ts | 2 +- .../astro/src/vite-plugin-markdown/index.ts | 2 +- 32 files changed, 166 insertions(+), 186 deletions(-) delete mode 100644 packages/astro/src/@types/astro-runtime.ts rename packages/astro/src/@types/{astro-core.ts => astro.ts} (72%) diff --git a/packages/astro/package.json b/packages/astro/package.json index 5e238c565..98a4ddf0c 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -4,7 +4,7 @@ "author": "Skypack", "license": "MIT", "type": "module", - "types": "./dist/types/@types/astro-core.d.ts", + "types": "./dist/types/@types/astro.d.ts", "repository": { "type": "git", "url": "https://github.com/snowpackjs/astro.git", diff --git a/packages/astro/src/@types/astro-runtime.ts b/packages/astro/src/@types/astro-runtime.ts deleted file mode 100644 index f1984c27c..000000000 --- a/packages/astro/src/@types/astro-runtime.ts +++ /dev/null @@ -1,64 +0,0 @@ -import type { Renderer } from './astro-core'; - -export interface AstroBuiltinProps { - 'client:load'?: boolean; - 'client:idle'?: boolean; - 'client:media'?: string; - 'client:visible'?: boolean; -} - -export interface AstroGlobal extends TopLevelAstro { - props: Record; - request: AstroPageRequest; - slots: Record; -} - -interface AstroPageRequest { - url: URL; - canonicalURL: URL; - params: Params; -} - -type AstroRenderedHTML = string; - -export type FetchContentResultBase = { - astro: { - headers: string[]; - source: string; - html: AstroRenderedHTML; - }; - url: URL; -}; - -export type FetchContentResult = FetchContentResultBase & T; - -export interface HydrateOptions { - value?: string; -} - -export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: string | null) => void>; - -export type Params = Record; - -export interface TopLevelAstro { - fetchContent(globStr: string): Promise[]>; - resolve: (path: string) => string; - site: URL; -} - -export interface SSRMetadata { - renderers: Renderer[]; - pathname: string; -} - -export interface SSRResult { - styles: Set; - scripts: Set; - createAstro(Astro: TopLevelAstro, props: Record, slots: Record | null): AstroGlobal; - _metadata: SSRMetadata; -} - -export interface SSRElement { - props: Record; - children: string; -} diff --git a/packages/astro/src/@types/astro-core.ts b/packages/astro/src/@types/astro.ts similarity index 72% rename from packages/astro/src/@types/astro-core.ts rename to packages/astro/src/@types/astro.ts index 204c94a30..cc2aa7b9d 100644 --- a/packages/astro/src/@types/astro-core.ts +++ b/packages/astro/src/@types/astro.ts @@ -2,7 +2,14 @@ import type babel from '@babel/core'; import type { z } from 'zod'; import type { AstroConfigSchema } from '../core/config'; import type { AstroComponentFactory, Metadata } from '../runtime/server'; -import type vite from '../../vendor/vite'; +import type vite from '../core/vite'; + +export interface AstroBuiltinProps { + 'client:load'?: boolean; + 'client:idle'?: boolean; + 'client:media'?: string; + 'client:visible'?: boolean; +} export interface AstroComponentMetadata { displayName: string; @@ -13,8 +20,34 @@ export interface AstroComponentMetadata { } /** - * The Astro User Config Format: - * This is the type interface for your astro.config.mjs default export. + * Astro.* available in all components + * Docs: https://docs.astro.build/reference/api-reference/#astro-global + */ +export interface AstroGlobal extends AstroGlobalPartial { + /** set props for this astro component (along with default values) */ + props: Record; + /** get information about this page */ + request: { + /** get the current page URL */ + url: URL; + /** get the current canonical URL */ + canonicalURL: URL; + /** get page params (dynamic pages only) */ + params: Params; + }; + /** see if slots are used */ + slots: Record; +} + +export interface AstroGlobalPartial { + fetchContent(globStr: string): Promise[]>; + resolve: (path: string) => string; + site: URL; +} + +/** + * Astro User Config + * Docs: https://docs.astro.build/reference/configuration-reference/ */ export interface AstroUserConfig { /** @@ -103,40 +136,14 @@ export interface AstroUserConfig { // export interface AstroUserConfig extends z.input { // } +/** + * Resolved Astro Config + * Config with user settings along with all defaults filled in. + */ export type AstroConfig = z.output; export type AsyncRendererComponentFn = (Component: any, props: any, children: string | undefined, metadata?: AstroComponentMetadata) => Promise; -export interface CollectionRSS { - /** (required) Title of the RSS Feed */ - title: string; - /** (required) Description of the RSS Feed */ - description: string; - /** Specify arbitrary metadata on opening tag */ - xmlns?: Record; - /** Specify custom data in opening of file */ - customData?: string; - /** - * Specify where the RSS xml file should be written. - * Relative to final build directory. Example: '/foo/bar.xml' - * Defaults to '/rss.xml'. - */ - dest?: string; - /** Return data about each item */ - items: { - /** (required) Title of item */ - title: string; - /** (required) Link to item */ - link: string; - /** Publication date of item */ - pubDate?: Date; - /** Item description */ - description?: string; - /** Append some other XML-valid data to this item */ - customData?: string; - }[]; -} - /** Generic interface for a component (Astro, Svelte, React, etc.) */ export interface ComponentInstance { $$metadata: Metadata; @@ -145,14 +152,36 @@ export interface ComponentInstance { getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult; } -export type GetStaticPathsArgs = { paginate: PaginateFunction; rss: RSSFunction }; +/** + * Astro.fetchContent() result + * Docs: https://docs.astro.build/reference/api-reference/#astrofetchcontent + */ +export type FetchContentResult = FetchContentResultBase & T; -export interface GetStaticPathsOptions { +export type FetchContentResultBase = { + astro: { + headers: string[]; + source: string; + html: string; + }; + url: URL; +}; + +export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: string | null) => void>; + +/** + * getStaticPaths() options + * Docs: https://docs.astro.build/reference/api-reference/#getstaticpaths + */ export interface GetStaticPathsOptions { paginate?: PaginateFunction; rss?: (...args: any[]) => any; } -export type GetStaticPathsResult = { params: Params; props?: Props }[] | { params: Params; props?: Props }[]; +export type GetStaticPathsResult = { params: Params; props?: Props }[]; + +export interface HydrateOptions { + value?: string; +} export interface JSXTransformConfig { /** Babel presets */ @@ -167,7 +196,24 @@ export interface ManifestData { routes: RouteData[]; } -export interface PaginatedCollectionProp { +/** + * paginate() Options + * Docs: https://docs.astro.build/guides/pagination/#calling-the-paginate-function + */ +export interface PaginateOptions { + /** the number of items per-page (default: `10`) */ + pageSize?: number; + /** key: value object of page params (ex: `{ tag: 'javascript' }`) */ + params?: Params; + /** object of props to forward to `page` result */ + props?: Props; +} + +/** + * Page Prop + * Docs: https://docs.astro.build/guides/pagination/#using-the-page-prop + */ +export interface Page { /** result */ data: T[]; /** metadata */ @@ -193,33 +239,7 @@ export interface PaginatedCollectionProp { }; } -export interface PaginatedCollectionResult { - /** 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: 25) */ - 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; - }; -} - -export type PaginateFunction = (data: [], args?: { pageSize?: number; params?: Params; props?: Props }) => GetStaticPathsResult; +export type PaginateFunction = (data: [], args?: PaginateOptions) => GetStaticPathsResult; export type Params = Record; @@ -236,6 +256,10 @@ export interface RenderPageOptions { css?: string[]; } +/** + * Astro Renderer + * Docs: https://docs.astro.build/reference/renderer-reference/ + */ export interface Renderer { /** Name of the renderer (required) */ name: string; @@ -264,9 +288,6 @@ export interface Renderer { knownEntrypoints?: string[]; } -/** tags with attributes represented by an object */ -export type Resource = Record; - export interface RouteData { component: string; generate: (data?: any) => string; @@ -280,9 +301,11 @@ export type RouteCache = Record; export type RuntimeMode = 'development' | 'production'; -export type RSSFunction = (args: RSSFunctionArgs) => void; - -export interface RSSFunctionArgs { +/** + * RSS + * Docs: https://docs.astro.build/reference/api-reference/#rss + */ +export interface RSS { /** (required) Title of the RSS Feed */ title: string; /** (required) Description of the RSS Feed */ @@ -312,16 +335,25 @@ export interface RSSFunctionArgs { }[]; } -export type RSSResult = { url: string; xml?: string }; +export type RSSFunction = (args: RSS) => void; -export type ScriptInfo = ScriptInfoInline | ScriptInfoExternal; +export type RSSResult = { url: string; xml?: string }; export type SSRError = Error & vite.ErrorPayload['err']; -export interface ScriptInfoInline { - content: string; +export interface SSRElement { + props: Record; + children: string; } -export interface ScriptInfoExternal { - src: string; +export interface SSRMetadata { + renderers: Renderer[]; + pathname: string; +} + +export interface SSRResult { + styles: Set; + scripts: Set; + createAstro(Astro: AstroGlobalPartial, props: Record, slots: Record | null): AstroGlobal; + _metadata: SSRMetadata; } diff --git a/packages/astro/src/cli/check.ts b/packages/astro/src/cli/check.ts index 02ab7f219..5fe9e6d7b 100644 --- a/packages/astro/src/cli/check.ts +++ b/packages/astro/src/cli/check.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import { AstroCheck, DiagnosticSeverity } from '@astrojs/language-server'; -import type { AstroConfig } from '../@types/astro-core'; +import type { AstroConfig } from '../@types/astro'; import { bold, black, bgWhite, red, cyan, yellow } from 'kleur/colors'; import glob from 'fast-glob'; diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index b9eaf3cc4..28acf286d 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -1,7 +1,7 @@ /* eslint-disable no-console */ -import type { AstroConfig } from '../@types/astro-core'; -import { LogOptions } from '../core/logger.js'; +import type { AstroConfig } from '../@types/astro'; +import type { LogOptions } from '../core/logger'; import * as colors from 'kleur/colors'; import fs from 'fs'; diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 4a50f85b7..2a843fdec 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, ComponentInstance, GetStaticPathsResult, ManifestData, RouteCache, RouteData, RSSResult } from '../../@types/astro-core'; +import type { AstroConfig, ComponentInstance, GetStaticPathsResult, ManifestData, RouteCache, RouteData, RSSResult } from '../../@types/astro'; import type { LogOptions } from '../logger'; import type { AllPagesData } from './types'; import type { RenderedChunk } from 'rollup'; diff --git a/packages/astro/src/core/build/types.d.ts b/packages/astro/src/core/build/types.d.ts index e1b317859..198b94846 100644 --- a/packages/astro/src/core/build/types.d.ts +++ b/packages/astro/src/core/build/types.d.ts @@ -1,5 +1,5 @@ import type { ComponentPreload } from '../ssr/index'; -import type { RouteData } from '../../@types/astro-core'; +import type { RouteData } from '../../@types/astro'; export interface PageBuildData { paths: string[]; diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 84f486512..51f6b1d1a 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -1,6 +1,5 @@ -import type { AstroConfig, AstroUserConfig } from '../@types/astro-core'; +import type { AstroConfig, AstroUserConfig } from '../@types/astro'; -import { existsSync } from 'fs'; import * as colors from 'kleur/colors'; import path from 'path'; import { pathToFileURL, fileURLToPath } from 'url'; diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index c883333da..c250e8ca5 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -1,4 +1,4 @@ -import type { AstroConfig } from '../@types/astro-core'; +import type { AstroConfig } from '../@types/astro'; import type { AstroDevServer } from './dev'; import type { LogOptions } from './logger'; diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts index 66e891dce..bd8c148b2 100644 --- a/packages/astro/src/core/dev/index.ts +++ b/packages/astro/src/core/dev/index.ts @@ -1,6 +1,6 @@ import type { NextFunction } from 'connect'; import type http from 'http'; -import type { AstroConfig, ManifestData, RouteCache, RouteData } from '../../@types/astro-core'; +import type { AstroConfig, ManifestData, RouteCache, RouteData } from '../../@types/astro'; import type { LogOptions } from '../logger'; import type { HmrContext, ModuleNode } from '../vite'; diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index 3e19c8c55..5aa5d50b9 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -1,4 +1,4 @@ -import type { AstroConfig } from '../../@types/astro-core'; +import type { AstroConfig } from '../../@types/astro'; import type { LogOptions } from '../logger'; import http from 'http'; diff --git a/packages/astro/src/core/ssr/css.ts b/packages/astro/src/core/ssr/css.ts index f091a6467..1a1fd0083 100644 --- a/packages/astro/src/core/ssr/css.ts +++ b/packages/astro/src/core/ssr/css.ts @@ -1,4 +1,4 @@ -import type vite from '../../../vendor/vite'; +import type vite from '../vite'; import { fileURLToPath } from 'url'; import path from 'path'; diff --git a/packages/astro/src/core/ssr/index.ts b/packages/astro/src/core/ssr/index.ts index 193aa43bc..d3f71a7b6 100644 --- a/packages/astro/src/core/ssr/index.ts +++ b/packages/astro/src/core/ssr/index.ts @@ -1,7 +1,21 @@ import type { BuildResult } from 'esbuild'; import type vite from '../vite'; -import type { AstroConfig, ComponentInstance, GetStaticPathsResult, Params, Props, Renderer, RouteCache, RouteData, RuntimeMode, SSRError } from '../../@types/astro-core'; -import type { AstroGlobal, TopLevelAstro, SSRResult, SSRElement } from '../../@types/astro-runtime'; +import type { + AstroConfig, + AstroGlobal, + AstroGlobalPartial, + ComponentInstance, + GetStaticPathsResult, + Params, + Props, + Renderer, + RouteCache, + RouteData, + RuntimeMode, + SSRElement, + SSRError, + SSRResult, +} from '../../@types/astro'; import type { LogOptions } from '../logger'; import fs from 'fs'; @@ -157,7 +171,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO styles: new Set(), scripts: new Set(), /** This function returns the `Astro` faux-global */ - createAstro(astroGlobal: TopLevelAstro, props: Record, slots: Record | null) { + createAstro(astroGlobal: AstroGlobalPartial, props: Record, slots: Record | null) { const site = new URL(origin); const url = new URL('.' + pathname, site); const canonicalURL = getCanonicalURL('.' + pathname, astroConfig.buildOptions.site || origin); diff --git a/packages/astro/src/core/ssr/paginate.ts b/packages/astro/src/core/ssr/paginate.ts index f81753f74..0b50c6237 100644 --- a/packages/astro/src/core/ssr/paginate.ts +++ b/packages/astro/src/core/ssr/paginate.ts @@ -1,12 +1,12 @@ -import { GetStaticPathsResult, PaginatedCollectionProp, PaginateFunction, Params, Props, RouteData } from '../../@types/astro-core'; +import { GetStaticPathsResult, Page, PaginateFunction, Params, Props, RouteData } from '../../@types/astro'; export function generatePaginateFunction(routeMatch: RouteData): PaginateFunction { return function paginateUtility(data: any[], args: { pageSize?: number; params?: Params; props?: Props } = {}) { let { pageSize: _pageSize, params: _params, props: _props } = args; const pageSize = _pageSize || 10; const paramName = 'page'; - const additoonalParams = _params || {}; - const additoonalProps = _props || {}; + const additionalParams = _params || {}; + const additionalProps = _props || {}; let includesFirstPageNumber: boolean; if (routeMatch.params.includes(`...${paramName}`)) { includesFirstPageNumber = false; @@ -24,13 +24,13 @@ export function generatePaginateFunction(routeMatch: RouteData): PaginateFunctio const start = pageSize === Infinity ? 0 : (pageNum - 1) * pageSize; // currentPage is 1-indexed const end = Math.min(start + pageSize, data.length); const params = { - ...additoonalParams, + ...additionalParams, [paramName]: includesFirstPageNumber || pageNum > 1 ? String(pageNum) : undefined, }; return { params, props: { - ...additoonalProps, + ...additionalProps, page: { data: data.slice(start, end), start, @@ -44,7 +44,7 @@ export function generatePaginateFunction(routeMatch: RouteData): PaginateFunctio next: pageNum === lastPage ? undefined : routeMatch.generate({ ...params, page: String(pageNum + 1) }), prev: pageNum === 1 ? undefined : routeMatch.generate({ ...params, page: !includesFirstPageNumber && pageNum - 1 === 1 ? undefined : String(pageNum - 1) }), }, - } as PaginatedCollectionProp, + } as Page, }, }; }); diff --git a/packages/astro/src/core/ssr/routing.ts b/packages/astro/src/core/ssr/routing.ts index cb8edcc86..d3ac3bf58 100644 --- a/packages/astro/src/core/ssr/routing.ts +++ b/packages/astro/src/core/ssr/routing.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, ComponentInstance, GetStaticPathsResult, ManifestData, Params, RouteData } from '../../@types/astro-core'; +import type { AstroConfig, ComponentInstance, GetStaticPathsResult, ManifestData, Params, RouteData } from '../../@types/astro'; import type { LogOptions } from '../logger'; import fs from 'fs'; diff --git a/packages/astro/src/core/ssr/rss.ts b/packages/astro/src/core/ssr/rss.ts index 5631c92ca..278eb7f93 100644 --- a/packages/astro/src/core/ssr/rss.ts +++ b/packages/astro/src/core/ssr/rss.ts @@ -1,4 +1,4 @@ -import type { RSSFunction, RSSFunctionArgs, RSSResult, RouteData } from '../../@types/astro-core'; +import type { RSSFunction, RSS, RSSResult, RouteData } from '../../@types/astro'; import parser from 'fast-xml-parser'; import { canonicalURL } from '../util.js'; @@ -12,7 +12,7 @@ export function validateRSS(args: GenerateRSSArgs): void { if (!Array.isArray(rssData.items)) throw new Error(`[${srcFile}] rss.items should be an array of items`); } -type GenerateRSSArgs = { site: string; rssData: RSSFunctionArgs; srcFile: string; feedURL: string }; +type GenerateRSSArgs = { site: string; rssData: RSS; srcFile: string; feedURL: string }; /** Generate RSS 2.0 feed */ export function generateRSS(args: GenerateRSSArgs): string { diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 2e91d6229..fa8cee9ae 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -1,4 +1,4 @@ -import type { AstroConfig } from '../@types/astro-core'; +import type { AstroConfig } from '../@types/astro'; import type { ErrorPayload } from 'vite'; import eol from 'eol'; import path from 'path'; diff --git a/packages/astro/src/runtime/client/idle.ts b/packages/astro/src/runtime/client/idle.ts index 6cd63c246..6f35f6958 100644 --- a/packages/astro/src/runtime/client/idle.ts +++ b/packages/astro/src/runtime/client/idle.ts @@ -1,4 +1,4 @@ -import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro-runtime'; +import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro'; /** * Hydrate this component as soon as the main thread is free diff --git a/packages/astro/src/runtime/client/load.ts b/packages/astro/src/runtime/client/load.ts index e8cef8045..5d83f340d 100644 --- a/packages/astro/src/runtime/client/load.ts +++ b/packages/astro/src/runtime/client/load.ts @@ -1,4 +1,4 @@ -import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro-runtime'; +import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro'; /** * Hydrate this component immediately diff --git a/packages/astro/src/runtime/client/media.ts b/packages/astro/src/runtime/client/media.ts index 324381891..c846db78f 100644 --- a/packages/astro/src/runtime/client/media.ts +++ b/packages/astro/src/runtime/client/media.ts @@ -1,4 +1,4 @@ -import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro-runtime'; +import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro'; /** * 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 e8cef8045..5d83f340d 100644 --- a/packages/astro/src/runtime/client/only.ts +++ b/packages/astro/src/runtime/client/only.ts @@ -1,4 +1,4 @@ -import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro-runtime'; +import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro'; /** * Hydrate this component immediately diff --git a/packages/astro/src/runtime/client/visible.ts b/packages/astro/src/runtime/client/visible.ts index e68392a01..bf49c8b3c 100644 --- a/packages/astro/src/runtime/client/visible.ts +++ b/packages/astro/src/runtime/client/visible.ts @@ -1,4 +1,4 @@ -import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro-runtime'; +import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro'; /** * Hydrate this component when one of it's children becomes visible. diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts index 4a67825a9..7767f2f66 100644 --- a/packages/astro/src/runtime/server/hydration.ts +++ b/packages/astro/src/runtime/server/hydration.ts @@ -1,5 +1,5 @@ -import type { AstroComponentMetadata } from '../../@types/astro-core'; -import type { SSRElement } from '../../@types/astro-runtime'; +import type { AstroComponentMetadata } from '../../@types/astro'; +import type { SSRElement } from '../../@types/astro'; import { valueToEstree } from 'estree-util-value-to-estree'; import * as astring from 'astring'; import { serializeListValue } from './util.js'; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 22a964593..68f020b47 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -1,6 +1,5 @@ -import type { AstroComponentMetadata, Renderer } from '../../@types/astro-core'; -import type { SSRResult, SSRElement } from '../../@types/astro-runtime'; -import type { TopLevelAstro } from '../../@types/astro-runtime'; +import type { AstroComponentMetadata, Renderer } from '../../@types/astro'; +import type { AstroGlobalPartial, SSRResult, SSRElement } from '../../@types/astro'; import shorthash from 'shorthash'; import { extractDirectives, generateHydrateScript } from './hydration.js'; @@ -269,12 +268,12 @@ function createFetchContentFn(url: URL) { // This has to be cast because the type of fetchContent is the type of the function // that receives the import.meta.glob result, but the user is using it as // another type. - return fetchContent as unknown as TopLevelAstro['fetchContent']; + return fetchContent as unknown as AstroGlobalPartial['fetchContent']; } // This is used to create the top-level Astro global; the one that you can use // Inside of getStaticPaths. -export function createAstro(fileURLStr: string, site: string): TopLevelAstro { +export function createAstro(fileURLStr: string, site: string): AstroGlobalPartial { const url = new URL(fileURLStr); const fetchContent = createFetchContentFn(url); return { diff --git a/packages/astro/src/vite-plugin-astro-postprocess/index.ts b/packages/astro/src/vite-plugin-astro-postprocess/index.ts index 2d4e2776c..23481931f 100644 --- a/packages/astro/src/vite-plugin-astro-postprocess/index.ts +++ b/packages/astro/src/vite-plugin-astro-postprocess/index.ts @@ -1,6 +1,6 @@ import type * as t from '@babel/types'; import type { Plugin } from '../core/vite'; -import type { AstroConfig } from '../@types/astro-core'; +import type { AstroConfig } from '../@types/astro'; import type { AstroDevServer } from '../core/dev/index'; import * as babelTraverse from '@babel/traverse'; diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index f88dc24fb..b6d1ea9d1 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 { TransformResult } from '@astrojs/compiler'; import type { SourceMapInput } from 'rollup'; import type vite from '../core/vite'; -import type { AstroConfig } from '../@types/astro-core'; +import type { AstroConfig } from '../@types/astro'; import esbuild from 'esbuild'; import fs from 'fs'; diff --git a/packages/astro/src/vite-plugin-build-css/index.ts b/packages/astro/src/vite-plugin-build-css/index.ts index 4de830919..4c96167fa 100644 --- a/packages/astro/src/vite-plugin-build-css/index.ts +++ b/packages/astro/src/vite-plugin-build-css/index.ts @@ -1,5 +1,5 @@ import type { RenderedChunk } from 'rollup'; -import type { Plugin as VitePlugin } from 'vite'; +import type { Plugin as VitePlugin } from '../core/vite'; import { STYLE_EXTENSIONS } from '../core/ssr/css.js'; import { getViteTransform, TransformHook } from '../vite-plugin-astro/styles.js'; diff --git a/packages/astro/src/vite-plugin-build-css/resolve.ts b/packages/astro/src/vite-plugin-build-css/resolve.ts index 181f2c6e3..72fef8532 100644 --- a/packages/astro/src/vite-plugin-build-css/resolve.ts +++ b/packages/astro/src/vite-plugin-build-css/resolve.ts @@ -1,5 +1,5 @@ import type { ResolveIdHook, LoadHook } from 'rollup'; -import type { ResolvedConfig, Plugin as VitePlugin } from 'vite'; +import type { ResolvedConfig, Plugin as VitePlugin } from '../core/vite'; export function getVitePluginByName(viteConfig: ResolvedConfig, pluginName: string): VitePlugin { const plugin = viteConfig.plugins.find(({ name }) => name === pluginName); diff --git a/packages/astro/src/vite-plugin-build-html/index.ts b/packages/astro/src/vite-plugin-build-html/index.ts index 6e8181e1f..2fd6cdca2 100644 --- a/packages/astro/src/vite-plugin-build-html/index.ts +++ b/packages/astro/src/vite-plugin-build-html/index.ts @@ -1,6 +1,6 @@ -import type { AstroConfig, RouteCache } from '../@types/astro-core'; +import type { AstroConfig, RouteCache } from '../@types/astro'; import type { LogOptions } from '../core/logger'; -import type { ViteDevServer, Plugin as VitePlugin } from 'vite'; +import type { ViteDevServer, Plugin as VitePlugin } from '../core/vite'; import type { OutputChunk, PreRenderedChunk, RenderedChunk } from 'rollup'; import type { AllPagesData } from '../core/build/types'; import parse5 from 'parse5'; diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index 8154730f4..7ed003b1b 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -2,7 +2,7 @@ import * as tsr from 'tsconfig-resolver'; import * as path from 'path'; import * as url from 'url'; -import type * as vite from 'vite'; +import type * as vite from '../core/vite'; /** Result of successfully parsed tsconfig.json or jsconfig.json. */ export declare interface Alias { diff --git a/packages/astro/src/vite-plugin-jsx/index.ts b/packages/astro/src/vite-plugin-jsx/index.ts index dc6b69b63..43381dacc 100644 --- a/packages/astro/src/vite-plugin-jsx/index.ts +++ b/packages/astro/src/vite-plugin-jsx/index.ts @@ -1,6 +1,6 @@ import type { TransformResult } from 'rollup'; import type { Plugin, ResolvedConfig } from '../core/vite'; -import type { AstroConfig, Renderer } from '../@types/astro-core'; +import type { AstroConfig, Renderer } from '../@types/astro'; import type { LogOptions } from '../core/logger'; import babel from '@babel/core'; diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 927b5b9d2..eaf1b3e3b 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -1,5 +1,5 @@ import type { Plugin } from '../core/vite'; -import type { AstroConfig } from '../@types/astro-core'; +import type { AstroConfig } from '../@types/astro'; import esbuild from 'esbuild'; import fs from 'fs';