From ee37eaa27191faad03c04d60fb3ca8ffbb887fbe Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 1 Sep 2022 21:41:20 +0530 Subject: [PATCH] fix(types): allow non async `transformHtml` and `buildEnd` (#1270) --- src/client/app/router.ts | 6 +++--- src/node/config.ts | 12 ++++++------ src/shared/shared.ts | 3 ++- types/shared.d.ts | 2 ++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/client/app/router.ts b/src/client/app/router.ts index aaebbfaf506..89976ca412e 100644 --- a/src/client/app/router.ts +++ b/src/client/app/router.ts @@ -1,7 +1,7 @@ import { reactive, inject, markRaw, nextTick, readonly } from 'vue' import type { Component, InjectionKey } from 'vue' import { notFoundPageData } from '../shared.js' -import type { PageData, PageDataPayload } from '../shared.js' +import type { PageData, PageDataPayload, Awaitable } from '../shared.js' import { inBrowser, withBase } from './utils.js' import { siteDataRef } from './data.js' @@ -14,8 +14,8 @@ export interface Route { export interface Router { route: Route go: (href?: string) => Promise - onBeforeRouteChange?: (to: string) => void | Promise - onAfterRouteChanged?: (to: string) => void | Promise + onBeforeRouteChange?: (to: string) => Awaitable + onAfterRouteChanged?: (to: string) => Awaitable } export const RouterSymbol: InjectionKey = Symbol() diff --git a/src/node/config.ts b/src/node/config.ts index 6206b1fd7b0..11849089d06 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -17,7 +17,8 @@ import { APPEARANCE_KEY, createLangDictionary, CleanUrlsMode, - PageData + PageData, + Awaitable } from './shared' import { DEFAULT_THEME_PATH } from './alias' import { MarkdownOptions } from './markdown/markdown' @@ -90,7 +91,7 @@ export interface UserConfig { * Build end hook: called when SSG finish. * @param siteConfig The resolved configuration. */ - buildEnd?: (siteConfig: SiteConfig) => Promise + buildEnd?: (siteConfig: SiteConfig) => Awaitable /** * HTML transform hook: runs before writing HTML to dist. @@ -107,13 +108,12 @@ export interface UserConfig { head: HeadConfig[] content: string } - ) => Promise + ) => Awaitable } export type RawConfigExports = - | UserConfig - | Promise> - | (() => UserConfig | Promise>) + | Awaitable> + | (() => Awaitable>) export interface SiteConfig extends Pick< diff --git a/src/shared/shared.ts b/src/shared/shared.ts index 2bb1637db84..2459bafed1d 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -13,7 +13,8 @@ export type { Header, DefaultTheme, PageDataPayload, - CleanUrlsMode + CleanUrlsMode, + Awaitable } from '../../types/shared.js' export const EXTERNAL_URL_RE = /^[a-z]+:/i diff --git a/types/shared.d.ts b/types/shared.d.ts index 41130bdc2f9..f37194dc1c2 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -1,6 +1,8 @@ // types shared between server and client export type { DefaultTheme } from './default-theme.js' +export type Awaitable = T | PromiseLike + export interface PageData { relativePath: string title: string