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 { reactive, inject, markRaw, nextTick, readonly } from 'vue'
import type { Component, InjectionKey } from 'vue' import type { Component, InjectionKey } from 'vue'
import { notFoundPageData } from '../shared.js' 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 { inBrowser, withBase } from './utils.js'
import { siteDataRef } from './data.js' import { siteDataRef } from './data.js'
@ -14,8 +14,8 @@ export interface Route {
export interface Router { export interface Router {
route: Route route: Route
go: (href?: string) => Promise<void> go: (href?: string) => Promise<void>
onBeforeRouteChange?: (to: string) => void | Promise<void> onBeforeRouteChange?: (to: string) => Awaitable<void>
onAfterRouteChanged?: (to: string) => void | Promise<void> onAfterRouteChanged?: (to: string) => Awaitable<void>
} }
export const RouterSymbol: InjectionKey<Router> = Symbol() export const RouterSymbol: InjectionKey<Router> = Symbol()

@ -17,7 +17,8 @@ import {
APPEARANCE_KEY, APPEARANCE_KEY,
createLangDictionary, createLangDictionary,
CleanUrlsMode, CleanUrlsMode,
PageData PageData,
Awaitable
} from './shared' } from './shared'
import { DEFAULT_THEME_PATH } from './alias' import { DEFAULT_THEME_PATH } from './alias'
import { MarkdownOptions } from './markdown/markdown' import { MarkdownOptions } from './markdown/markdown'
@ -90,7 +91,7 @@ export interface UserConfig<ThemeConfig = any> {
* Build end hook: called when SSG finish. * Build end hook: called when SSG finish.
* @param siteConfig The resolved configuration. * @param siteConfig The resolved configuration.
*/ */
buildEnd?: (siteConfig: SiteConfig) => Promise<void> buildEnd?: (siteConfig: SiteConfig) => Awaitable<void>
/** /**
* HTML transform hook: runs before writing HTML to dist. * HTML transform hook: runs before writing HTML to dist.
@ -107,13 +108,12 @@ export interface UserConfig<ThemeConfig = any> {
head: HeadConfig[] head: HeadConfig[]
content: string content: string
} }
) => Promise<string | void> ) => Awaitable<string | void>
} }
export type RawConfigExports<ThemeConfig = any> = export type RawConfigExports<ThemeConfig = any> =
| UserConfig<ThemeConfig> | Awaitable<UserConfig<ThemeConfig>>
| Promise<UserConfig<ThemeConfig>> | (() => Awaitable<UserConfig<ThemeConfig>>)
| (() => UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>>)
export interface SiteConfig<ThemeConfig = any> export interface SiteConfig<ThemeConfig = any>
extends Pick< extends Pick<

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

2
types/shared.d.ts vendored

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

Loading…
Cancel
Save