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

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

Merged
merged 1 commit into from Sep 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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