Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/types #11715

Merged
merged 8 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/poor-frogs-dream.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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 {}
}

Comment on lines -5 to -10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary, the default definition is already that. However, it was done in a .d.ts file, which don't get sent to dist so it never worked.

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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That method hasn't existed in a while.

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/components/Picture.astro
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/config.d.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
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.

9 changes: 0 additions & 9 deletions packages/astro/src/@types/app.d.ts

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 { 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';
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,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';
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 { 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;
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
Loading
Loading