Skip to content

Commit 8b10848

Browse files
authored
build: improve types (#3009)
1 parent 0eef3c0 commit 8b10848

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@
103103
"vue": "^3.3.4"
104104
},
105105
"peerDependencies": {
106-
"markdown-it-mathjax3": "^4.3.2"
106+
"markdown-it-mathjax3": "^4.3.2",
107+
"postcss": "^8.4.30"
107108
},
108109
"peerDependenciesMeta": {
109110
"markdown-it-mathjax3": {
110111
"optional": true
112+
},
113+
"postcss": {
114+
"optional": true
111115
}
112116
},
113117
"devDependencies": {

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@ const esmBuild: RollupOptions = {
6262
}
6363
}
6464

65+
const typesExternal = [
66+
...external,
67+
/\/vitepress\/(?!(dist|node_modules)\/).*\.d\.ts$/,
68+
'source-map-js',
69+
'fast-glob'
70+
]
71+
6572
const nodeTypes: RollupOptions = {
6673
input: r('src/node/index.ts'),
6774
output: {
6875
format: 'esm',
6976
file: 'dist/node/index.d.ts'
7077
},
71-
external: [...external, r('types/shared.d.ts'), 'postcss', 'source-map-js'],
78+
external: typesExternal,
7279
plugins: [dts({ respectExternal: true })]
7380
}
7481

@@ -78,7 +85,7 @@ const clientTypes: RollupOptions = {
7885
format: 'esm',
7986
file: 'dist/client/index.d.ts'
8087
},
81-
external,
88+
external: typesExternal,
8289
plugins: [
8390
dts({ respectExternal: true }),
8491
{

src/client/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// exports in this file are exposed to themes and md files via 'vitepress'
2-
// so the user can do `import { useRoute, useSiteData } from 'vitepress'`
2+
// so the user can do `import { useRoute, useData } from 'vitepress'`
33

44
// generic types
55
export type { VitePressData } from './app/data'

src/client/shim.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare module '@localSearchIndex' {
2929
}
3030

3131
declare module 'mark.js/src/vanilla.js' {
32-
import type { Mark } from 'mark.js'
33-
const mark: Mark
32+
import type Mark from 'mark.js'
33+
const mark: typeof Mark
3434
export default mark
3535
}

src/node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export * from './init/init'
77
export * from './contentLoader'
88
export * from './postcss'
99
export { defineLoader, type LoaderModule } from './plugins/staticDataPlugin'
10-
export { loadEnv } from 'vite'
10+
export { loadEnv, type Plugin } from 'vite'
1111

1212
// shared types
1313
export type {

src/node/postcss/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import postcssPrefixSelector from 'postcss-prefix-selector'
22

3-
type Options = Parameters<typeof postcssPrefixSelector>[0]
4-
5-
export function postcssIsolateStyles(options: Options = {}) {
3+
export function postcssIsolateStyles(
4+
options: Parameters<typeof postcssPrefixSelector>[0] = {}
5+
): ReturnType<typeof postcssPrefixSelector> {
66
return postcssPrefixSelector({
77
prefix: ':not(:where(.vp-raw, .vp-raw *))',
88
includeFiles: [/base\.css/],

theme.d.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
// so that users can do `import DefaultTheme from 'vitepress/theme'`
2+
23
import type { DefineComponent } from 'vue'
3-
import { EnhanceAppContext } from './dist/client/index.js'
4+
import type { EnhanceAppContext } from './dist/client/index.js'
5+
import type { DefaultTheme } from './types/default-theme.js'
46

5-
// TODO: add props for these
6-
export const VPImage: DefineComponent
7-
export const VPButton: DefineComponent
8-
export const VPHomeHero: DefineComponent
9-
export const VPHomeFeatures: DefineComponent
10-
export const VPHomeSponsors: DefineComponent
11-
export const VPDocAsideSponsors: DefineComponent
12-
export const VPSponsors: DefineComponent
13-
export const VPTeamPage: DefineComponent
14-
export const VPTeamPageTitle: DefineComponent
15-
export const VPTeamPageSection: DefineComponent
16-
export const VPTeamMembers: DefineComponent
7+
export type { DefaultTheme } from './types/default-theme.js'
178

189
declare const theme: {
1910
Layout: DefineComponent
2011
enhanceApp: (ctx: EnhanceAppContext) => void
2112
}
2213

2314
export default theme
24-
export type { DefaultTheme } from './types/default-theme.js'
15+
export declare const useSidebar: () => DefaultTheme.DocSidebar
2516

26-
export const useSidebar: () => DefaultTheme.DocSidebar
17+
// TODO: add props for these
18+
export declare const VPButton: DefineComponent
19+
export declare const VPDocAsideSponsors: DefineComponent
20+
export declare const VPHomeFeatures: DefineComponent
21+
export declare const VPHomeHero: DefineComponent
22+
export declare const VPHomeSponsors: DefineComponent
23+
export declare const VPImage: DefineComponent
24+
export declare const VPSponsors: DefineComponent
25+
export declare const VPTeamMembers: DefineComponent
26+
export declare const VPTeamPage: DefineComponent
27+
export declare const VPTeamPageSection: DefineComponent
28+
export declare const VPTeamPageTitle: DefineComponent

0 commit comments

Comments
 (0)