Skip to content

Commit bf8c9a4

Browse files
s00dcursoragent
andcommitted
fix(vitepress): unblock CI typecheck
Cast virtual imports past Astro ambient clash; loosen test router setters; cast dts plugin for duplicate Vite types. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 74c4c74 commit bf8c9a4

4 files changed

Lines changed: 44 additions & 52 deletions

File tree

packages/vitepress/src/define-theme.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ export function defineI18nTheme<T extends Theme>(base: T, options: DefineI18nThe
5151
async enhanceApp(ctx: EnhanceAppContext) {
5252
let installed = byApp.get(ctx.app)
5353
if (!installed) {
54+
// Cast via `unknown`: root typecheck also sees Astro's ambient `virtual:i18n-micro/config`.
5455
const [{ config }, messagesMod] = await Promise.all([
55-
import('virtual:i18n-micro/config') as Promise<{ config: VirtualI18nConfig }>,
56-
import('virtual:i18n-micro/messages') as Promise<VirtualMessagesModule>,
56+
import('virtual:i18n-micro/config') as unknown as Promise<{ config: VirtualI18nConfig }>,
57+
import('virtual:i18n-micro/messages') as unknown as Promise<VirtualMessagesModule>,
5758
])
5859

5960
const localeCodes = config.localeCodes.length

packages/vitepress/tests/define-theme.test.ts

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest'
2+
import type { Theme } from 'vitepress'
23

34
vi.mock('virtual:i18n-micro/config', () => ({
45
config: {
@@ -26,35 +27,43 @@ afterEach(() => {
2627
vi.restoreAllMocks()
2728
})
2829

30+
function makeApp() {
31+
const app = {
32+
use: vi.fn((plugin: { global: { getLocale: () => string } }) => {
33+
app._i18n = plugin.global
34+
}),
35+
provide: vi.fn(),
36+
config: { globalProperties: {} as Record<string, unknown> },
37+
component: vi.fn(),
38+
_i18n: undefined as { getLocale: () => string } | undefined,
39+
}
40+
return app
41+
}
42+
43+
function makeRouter(path: string) {
44+
let after: ((to: string) => unknown) | undefined
45+
return {
46+
route: { path },
47+
go: vi.fn(),
48+
set onAfterRouteChange(fn: ((to: string) => unknown) | undefined) {
49+
after = fn
50+
},
51+
get onAfterRouteChange() {
52+
return after
53+
},
54+
}
55+
}
56+
2957
describe('defineI18nTheme', () => {
3058
it('maps VitePress locale key to i18n code on first enhanceApp', async () => {
3159
const { defineI18nTheme } = await import('../src/define-theme')
3260

3361
const theme = defineI18nTheme({
3462
Layout: {} as never,
35-
})
63+
} as Theme)
3664

37-
const app = {
38-
use: vi.fn((plugin: { global: { getLocale: () => string } }) => {
39-
;(app as { _i18n?: { getLocale: () => string } })._i18n = plugin.global
40-
}),
41-
provide: vi.fn(),
42-
config: { globalProperties: {} as Record<string, unknown> },
43-
component: vi.fn(),
44-
_i18n: undefined as { getLocale: () => string } | undefined,
45-
}
46-
47-
let after: ((to: string) => unknown) | undefined
48-
const router = {
49-
route: { path: '/fr/guide/' },
50-
go: vi.fn(),
51-
set onAfterRouteChange(fn: (to: string) => unknown) {
52-
after = fn
53-
},
54-
get onAfterRouteChange() {
55-
return after
56-
},
57-
}
65+
const app = makeApp()
66+
const router = makeRouter('/fr/guide/')
5867

5968
await theme.enhanceApp!({
6069
app: app as never,
@@ -74,37 +83,18 @@ describe('defineI18nTheme', () => {
7483
async enhanceApp({ router }) {
7584
router.onAfterRouteChange = baseHook
7685
},
77-
})
78-
79-
const app = {
80-
use: vi.fn((plugin: { global: { getLocale: () => string } }) => {
81-
;(app as { _i18n?: { getLocale: () => string } })._i18n = plugin.global
82-
}),
83-
provide: vi.fn(),
84-
config: { globalProperties: {} as Record<string, unknown> },
85-
component: vi.fn(),
86-
_i18n: undefined as { getLocale: () => string } | undefined,
87-
}
86+
} as Theme)
8887

89-
let after: ((to: string) => unknown) | undefined
90-
const router = {
91-
route: { path: '/' },
92-
go: vi.fn(),
93-
set onAfterRouteChange(fn: (to: string) => unknown) {
94-
after = fn
95-
},
96-
get onAfterRouteChange() {
97-
return after
98-
},
99-
}
88+
const app = makeApp()
89+
const router = makeRouter('/')
10090

10191
await theme.enhanceApp!({
10292
app: app as never,
10393
router: router as never,
10494
siteData: {} as never,
10595
})
10696

107-
await after?.('/fr/')
97+
await router.onAfterRouteChange?.('/fr/')
10898
expect(baseHook).toHaveBeenCalledWith('/fr/')
10999
expect(app._i18n?.getLocale()).toBe('fr-FR')
110100
})

packages/vitepress/tests/with-i18n-micro.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest'
2-
import { withI18nMicro, warnLocaleMismatch } from '../src/with-i18n-micro'
2+
import { withI18nMicro, warnLocaleMismatch, type VitePressUserConfigLike } from '../src/with-i18n-micro'
33
import { messagesFromGlob } from '../src/messages-from-glob'
44
import { createVitePressI18n } from '../src/create'
55

@@ -38,7 +38,7 @@ describe('withI18nMicro', () => {
3838

3939
it('virtual plugin resolves config module', () => {
4040
const result = withI18nMicro(
41-
{},
41+
{} as VitePressUserConfigLike,
4242
{
4343
locale: 'en',
4444
locales: [{ code: 'en', iso: 'en-US' }],
@@ -136,7 +136,7 @@ describe('createVitePressI18n', () => {
136136
const router = {
137137
route: { path: '/fr/guide/demo' },
138138
go: vi.fn(),
139-
set onAfterRouteChange(fn: (to: string) => unknown) {
139+
set onAfterRouteChange(fn: ((to: string) => unknown) | undefined) {
140140
after = fn
141141
},
142142
get onAfterRouteChange() {
@@ -178,7 +178,7 @@ describe('createVitePressI18n', () => {
178178
const router = {
179179
route: { path: '/' },
180180
go: vi.fn(),
181-
set onAfterRouteChange(fn: (to: string) => unknown) {
181+
set onAfterRouteChange(fn: ((to: string) => unknown) | undefined) {
182182
after = fn
183183
},
184184
get onAfterRouteChange() {

packages/vitepress/vite.config.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default defineConfig({
5353
sourcemap: true,
5454
},
5555
plugins: [
56+
// Cast: root typecheck can see duplicate Vite copies (@types/node 20 vs 26).
5657
dts({
5758
afterDiagnostic(diagnostics) {
5859
const errors = diagnostics.filter((d) => d.category === 1)
@@ -65,6 +66,6 @@ export default defineConfig({
6566
outDir: 'dist',
6667
tsconfigPath: resolve(import.meta.dirname, 'tsconfig.json'),
6768
beforeWriteFile: dualPackageBeforeWriteFile,
68-
}),
69+
}) as never,
6970
],
7071
})

0 commit comments

Comments
 (0)