Skip to content

Commit

Permalink
feat: refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Aug 15, 2024
1 parent e179369 commit f286a0b
Show file tree
Hide file tree
Showing 198 changed files with 2,006 additions and 2,037 deletions.
20 changes: 9 additions & 11 deletions packages/astro/astro-jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
20 changes: 4 additions & 16 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
/// <reference path="./types/content.d.ts" />
/// <reference path="./types/actions.d.ts" />

// 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.
Expand Down Expand Up @@ -52,7 +46,7 @@ declare module 'astro:assets' {
getImage: (
options: import('./dist/assets/types.js').UnresolvedImageTransform,
) => Promise<import('./dist/assets/types.js').GetImageResult>;
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;
Expand Down Expand Up @@ -172,7 +166,7 @@ declare module 'astro:components' {
export * from 'astro/components';
}

type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
type MD = import('./dist/types/public/content.js').MarkdownInstance<Record<string, any>>;
interface ExportedMarkdownModuleEntities {
frontmatter: MD['frontmatter'];
file: MD['file'];
Expand All @@ -191,7 +185,6 @@ declare module '*.md' {
file,
url,
getHeadings,
getHeaders,
Content,
rawContent,
compiledContent,
Expand All @@ -206,7 +199,6 @@ declare module '*.markdown' {
file,
url,
getHeadings,
getHeaders,
Content,
rawContent,
compiledContent,
Expand All @@ -221,7 +213,6 @@ declare module '*.mkdn' {
file,
url,
getHeadings,
getHeaders,
Content,
rawContent,
compiledContent,
Expand All @@ -236,7 +227,6 @@ declare module '*.mkd' {
file,
url,
getHeadings,
getHeaders,
Content,
rawContent,
compiledContent,
Expand All @@ -251,7 +241,6 @@ declare module '*.mdwn' {
file,
url,
getHeadings,
getHeaders,
Content,
rawContent,
compiledContent,
Expand All @@ -266,7 +255,6 @@ declare module '*.mdown' {
file,
url,
getHeadings,
getHeaders,
Content,
rawContent,
compiledContent,
Expand All @@ -275,7 +263,7 @@ declare module '*.mdown' {
}

declare module '*.mdx' {
type MDX = import('./dist/@types/astro.js').MDXInstance<Record<string, any>>;
type MDX = import('./dist/types/public/content.js').MDXInstance<Record<string, any>>;

export const frontmatter: MDX['frontmatter'];
export const file: MDX['file'];
Expand All @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/index.d.ts
Original file line number Diff line number Diff line change
@@ -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';
5 changes: 0 additions & 5 deletions packages/astro/src/@types/README.md

This file was deleted.

3 changes: 2 additions & 1 deletion packages/astro/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/actions/runtime/middleware.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/actions/runtime/route.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/actions/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -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'];

Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/actions/utils.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/endpoint/config.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/endpoint/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/endpoint/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { assetsDir, imageConfig, outDir } from 'astro:assets';
import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path';
import { readFile } from 'fs/promises';
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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/utils/remotePattern.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AstroConfig } from '../../@types/astro.js';
import { resolveConfig } from '../../core/config/config.js';
import { apply as applyPolyfill } from '../../core/polyfill.js';
import type { AstroConfig } from '../../types/public/config.js';
import { type Flags, createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js';
import { getPackage } from '../install-package.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/flags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { parseArgs } from 'node:util';
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';

export type ParsedArgsResult = ReturnType<typeof parseArgs>;
export type Flags = ParsedArgsResult['values'];
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/preferences/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/config/vite-plugin-content-listen.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
32 changes: 17 additions & 15 deletions packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -25,7 +10,20 @@ 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';
import type { ContainerRenderer } from '../types/public/container.js';

/**
* Options to be passed when rendering a route
Expand Down Expand Up @@ -103,6 +101,10 @@ export type AddClientRenderer = {
entrypoint: string;
};

type ContainerImportRendererFn = (
containerRenderer: ContainerRenderer,
) => Promise<SSRLoadedRenderer>;

function createManifest(
manifest?: AstroContainerManifest,
renderers?: SSRLoadedRenderer[],
Expand Down
10 changes: 3 additions & 7 deletions packages/astro/src/container/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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 {
createModuleScriptElement,
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 {
/**
Expand Down
Loading

0 comments on commit f286a0b

Please sign in to comment.