fix(types): allow non async `transformHtml` and `buildEnd` (#1270)

pull/1278/head
Divyansh Singh 3 years ago committed by GitHub
parent 8f630339ba
commit ee37eaa271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<void>
onBeforeRouteChange?: (to: string) => void | Promise<void>
onAfterRouteChanged?: (to: string) => void | Promise<void>
onBeforeRouteChange?: (to: string) => Awaitable<void>
onAfterRouteChanged?: (to: string) => Awaitable<void>
}
export const RouterSymbol: InjectionKey<Router> = Symbol()

@ -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<ThemeConfig = any> {
* Build end hook: called when SSG finish.
* @param siteConfig The resolved configuration.
*/
buildEnd?: (siteConfig: SiteConfig) => Promise<void>
buildEnd?: (siteConfig: SiteConfig) => Awaitable<void>
/**
* HTML transform hook: runs before writing HTML to dist.
@ -107,13 +108,12 @@ export interface UserConfig<ThemeConfig = any> {
head: HeadConfig[]
content: string
}
) => Promise<string | void>
) => Awaitable<string | void>
}
export type RawConfigExports<ThemeConfig = any> =
| UserConfig<ThemeConfig>
| Promise<UserConfig<ThemeConfig>>
| (() => UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>>)
| Awaitable<UserConfig<ThemeConfig>>
| (() => Awaitable<UserConfig<ThemeConfig>>)
export interface SiteConfig<ThemeConfig = any>
extends Pick<

@ -13,7 +13,8 @@ export type {
Header,
DefaultTheme,
PageDataPayload,
CleanUrlsMode
CleanUrlsMode,
Awaitable
} from '../../types/shared.js'
export const EXTERNAL_URL_RE = /^[a-z]+:/i

2
types/shared.d.ts vendored

@ -1,6 +1,8 @@
// types shared between server and client
export type { DefaultTheme } from './default-theme.js'
export type Awaitable<T> = T | PromiseLike<T>
export interface PageData {
relativePath: string
title: string

Loading…
Cancel
Save