separate node only types

pull/4507/head
Divyansh Singh 8 months ago
parent 4e542a7eca
commit abc9da6d3d

@ -91,10 +91,7 @@ const clientTypes: RollupOptions = {
}, },
external: typesExternal, external: typesExternal,
plugins: [ plugins: [
dts({ dts({ respectExternal: true }),
respectExternal: true,
tsconfig: 'tsconfig.json'
}),
{ {
name: 'cleanup', name: 'cleanup',
async closeBundle() { async closeBundle() {

@ -10,14 +10,9 @@ import {
type ConfigEnv type ConfigEnv
} from 'vite' } from 'vite'
import { DEFAULT_THEME_PATH } from './alias' import { DEFAULT_THEME_PATH } from './alias'
import type { DefaultTheme } from './defaultTheme'
import { resolvePages } from './plugins/dynamicRoutesPlugin' import { resolvePages } from './plugins/dynamicRoutesPlugin'
import { import { APPEARANCE_KEY, slash, type HeadConfig, type SiteData } from './shared'
APPEARANCE_KEY,
slash,
type DefaultTheme,
type HeadConfig,
type SiteData
} from './shared'
import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig' import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig'
export { resolvePages } from './plugins/dynamicRoutesPlugin' export { resolvePages } from './plugins/dynamicRoutesPlugin'

@ -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<string>
}
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<PageSplitSection>
| Generator<PageSplitSection>
| Awaitable<PageSplitSection[]>
}
}
}
export type { DefaultTheme }

@ -8,11 +8,7 @@ export { defineLoader, type LoaderModule } from './plugins/staticDataPlugin'
export * from './postcss/isolateStyles' export * from './postcss/isolateStyles'
export * from './serve/serve' export * from './serve/serve'
export * from './server' export * from './server'
export type { DefaultTheme } from './defaultTheme'
// shared types // shared types
export type { export type { HeadConfig, Header, SiteData } from '../../types/shared'
DefaultTheme,
HeadConfig,
Header,
SiteData
} from '../../types/shared'

@ -5,13 +5,9 @@ import path from 'node:path'
import pMap from 'p-map' import pMap from 'p-map'
import type { Plugin, ViteDevServer } from 'vite' import type { Plugin, ViteDevServer } from 'vite'
import type { SiteConfig } from '../config' import type { SiteConfig } from '../config'
import type { DefaultTheme } from '../defaultTheme'
import { createMarkdownRenderer } from '../markdown/markdown' import { createMarkdownRenderer } from '../markdown/markdown'
import { import { getLocaleForPath, slash, type MarkdownEnv } from '../shared'
getLocaleForPath,
slash,
type DefaultTheme,
type MarkdownEnv
} from '../shared'
import { processIncludes } from '../utils/processIncludes' import { processIncludes } from '../utils/processIncludes'
const debug = _debug('vitepress:local-search') const debug = _debug('vitepress:local-search')

@ -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 { ComputedRef, Ref, ShallowRef } from 'vue'
import type { DocSearchProps } from './docsearch.js' import type { DocSearchProps } from './docsearch.js'
import type { import type { LocalSearchTranslations } from './local-search.js'
LocalSearchTranslations, import type { PageData } from './shared.js'
PageSplitSection
} from './local-search.js'
import type { Awaitable, MarkdownEnv, PageData } from './shared.js'
export namespace DefaultTheme { export namespace DefaultTheme {
export interface Config { export interface Config {
@ -412,42 +409,21 @@ export namespace DefaultTheme {
translations?: LocalSearchTranslations translations?: LocalSearchTranslations
locales?: Record<string, Partial<Omit<LocalSearchOptions, 'locales'>>> locales?: Record<string, Partial<Omit<LocalSearchOptions, 'locales'>>>
miniSearch?: { miniSearch?: MiniSearchOptions
}
interface MiniSearchOptions {
/** /**
* @see https://lucaong.github.io/minisearch/types/MiniSearch.Options.html * @see https://lucaong.github.io/minisearch/types/MiniSearch.Options.html
*/ */
options?: Pick< options?: Pick<
MiniSearchOptions, _MiniSearchOptions,
'extractField' | 'tokenize' | 'processTerm' 'extractField' | 'tokenize' | 'processTerm'
> >
/** /**
* @see https://lucaong.github.io/minisearch/types/MiniSearch.SearchOptions.html * @see https://lucaong.github.io/minisearch/types/MiniSearch.SearchOptions.html
*/ */
searchOptions?: MiniSearchOptions['searchOptions'] 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<PageSplitSection>
| Generator<PageSplitSection>
| Awaitable<PageSplitSection[]>
}
/**
* Allows transformation of content before indexing (node only)
* Return empty string to skip indexing
*/
_render?: (src: string, env: MarkdownEnv, md: any) => Awaitable<string>
} }
// algolia ------------------------------------------------------------------- // algolia -------------------------------------------------------------------

Loading…
Cancel
Save