Skip to content

Commit

Permalink
fix(types): allow non async transformHtml and buildEnd (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Sep 1, 2022
1 parent 8f63033 commit ee37eaa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions 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'

Expand All @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions src/node/config.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand All @@ -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<
Expand Down
3 changes: 2 additions & 1 deletion src/shared/shared.ts
Expand Up @@ -13,7 +13,8 @@ export type {
Header,
DefaultTheme,
PageDataPayload,
CleanUrlsMode
CleanUrlsMode,
Awaitable
} from '../../types/shared.js'

export const EXTERNAL_URL_RE = /^[a-z]+:/i
Expand Down
2 changes: 2 additions & 0 deletions 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> = T | PromiseLike<T>

export interface PageData {
relativePath: string
title: string
Expand Down

0 comments on commit ee37eaa

Please sign in to comment.