diff --git a/rollup.config.ts b/rollup.config.ts index 29516baf..6bf7ff1b 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -91,10 +91,7 @@ const clientTypes: RollupOptions = { }, external: typesExternal, plugins: [ - dts({ - respectExternal: true, - tsconfig: 'tsconfig.json' - }), + dts({ respectExternal: true }), { name: 'cleanup', async closeBundle() { diff --git a/src/node/config.ts b/src/node/config.ts index ffffa5ab..5f1698fe 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -10,14 +10,9 @@ import { type ConfigEnv } from 'vite' import { DEFAULT_THEME_PATH } from './alias' +import type { DefaultTheme } from './defaultTheme' import { resolvePages } from './plugins/dynamicRoutesPlugin' -import { - APPEARANCE_KEY, - slash, - type DefaultTheme, - type HeadConfig, - type SiteData -} from './shared' +import { APPEARANCE_KEY, slash, type HeadConfig, type SiteData } from './shared' import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig' export { resolvePages } from './plugins/dynamicRoutesPlugin' diff --git a/src/node/defaultTheme.ts b/src/node/defaultTheme.ts new file mode 100644 index 00000000..21ca830e --- /dev/null +++ b/src/node/defaultTheme.ts @@ -0,0 +1,45 @@ +// this file contains node-only types of default theme +// (functions starting with _ are node-only) + +import type { MarkdownItAsync } from 'markdown-it-async' +import type { DefaultTheme } from '../../types/default-theme' +import type { PageSplitSection } from '../../types/local-search' +import type { Awaitable, MarkdownEnv } from './shared' + +declare module '../../types/default-theme.js' { + namespace DefaultTheme { + interface LocalSearchOptions { + /** + * Allows transformation of content before indexing (node only) + * Return empty string to skip indexing + */ + _render?: ( + src: string, + env: MarkdownEnv, + md: MarkdownItAsync + ) => Awaitable + } + + interface MiniSearchOptions { + /** + * Overrides the default regex based page splitter. + * Supports async generator, making it possible to run in true parallel + * (when used along with `node:child_process` or `worker_threads`) + * --- + * This should be especially useful for scalability reasons. + * --- + * @param {string} path - absolute path to the markdown source file + * @param {string} html - document page rendered as html + */ + _splitIntoSections?: ( + path: string, + html: string + ) => + | AsyncGenerator + | Generator + | Awaitable + } + } +} + +export type { DefaultTheme } diff --git a/src/node/index.ts b/src/node/index.ts index 90c0956a..63ee79f8 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -8,11 +8,7 @@ export { defineLoader, type LoaderModule } from './plugins/staticDataPlugin' export * from './postcss/isolateStyles' export * from './serve/serve' export * from './server' +export type { DefaultTheme } from './defaultTheme' // shared types -export type { - DefaultTheme, - HeadConfig, - Header, - SiteData -} from '../../types/shared' +export type { HeadConfig, Header, SiteData } from '../../types/shared' diff --git a/src/node/plugins/localSearchPlugin.ts b/src/node/plugins/localSearchPlugin.ts index 1456d4f8..bffe74e8 100644 --- a/src/node/plugins/localSearchPlugin.ts +++ b/src/node/plugins/localSearchPlugin.ts @@ -5,13 +5,9 @@ import path from 'node:path' import pMap from 'p-map' import type { Plugin, ViteDevServer } from 'vite' import type { SiteConfig } from '../config' +import type { DefaultTheme } from '../defaultTheme' import { createMarkdownRenderer } from '../markdown/markdown' -import { - getLocaleForPath, - slash, - type DefaultTheme, - type MarkdownEnv -} from '../shared' +import { getLocaleForPath, slash, type MarkdownEnv } from '../shared' import { processIncludes } from '../utils/processIncludes' const debug = _debug('vitepress:local-search') diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index c6767043..5a669c49 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -1,11 +1,8 @@ -import type { Options as MiniSearchOptions } from 'minisearch' +import type { Options as _MiniSearchOptions } from 'minisearch' import type { ComputedRef, Ref, ShallowRef } from 'vue' import type { DocSearchProps } from './docsearch.js' -import type { - LocalSearchTranslations, - PageSplitSection -} from './local-search.js' -import type { Awaitable, MarkdownEnv, PageData } from './shared.js' +import type { LocalSearchTranslations } from './local-search.js' +import type { PageData } from './shared.js' export namespace DefaultTheme { export interface Config { @@ -412,42 +409,21 @@ export namespace DefaultTheme { translations?: LocalSearchTranslations locales?: Record>> - miniSearch?: { - /** - * @see https://lucaong.github.io/minisearch/types/MiniSearch.Options.html - */ - options?: Pick< - MiniSearchOptions, - 'extractField' | 'tokenize' | 'processTerm' - > - /** - * @see https://lucaong.github.io/minisearch/types/MiniSearch.SearchOptions.html - */ - searchOptions?: MiniSearchOptions['searchOptions'] - - /** - * Overrides the default regex based page splitter. - * Supports async generator, making it possible to run in true parallel - * (when used along with `node:child_process` or `worker_threads`) - * --- - * This should be especially useful for scalability reasons. - * --- - * @param {string} path - absolute path to the markdown source file - * @param {string} html - document page rendered as html - */ - _splitIntoSections?: ( - path: string, - html: string - ) => - | AsyncGenerator - | Generator - | Awaitable - } - /** - * Allows transformation of content before indexing (node only) - * Return empty string to skip indexing - */ - _render?: (src: string, env: MarkdownEnv, md: any) => Awaitable + miniSearch?: MiniSearchOptions + } + + interface MiniSearchOptions { + /** + * @see https://lucaong.github.io/minisearch/types/MiniSearch.Options.html + */ + options?: Pick< + _MiniSearchOptions, + 'extractField' | 'tokenize' | 'processTerm' + > + /** + * @see https://lucaong.github.io/minisearch/types/MiniSearch.SearchOptions.html + */ + searchOptions?: _MiniSearchOptions['searchOptions'] } // algolia -------------------------------------------------------------------