Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Aug 15, 2024
1 parent d85018d commit 2d377d2
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 99 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default vuepress(
'@typescript-eslint/no-non-null-assertion': 'off',
'no-underscore-dangle': [
'warn',
{ allow: ['_context', '_registeredComponents'] },
{ allow: ['_context', '_pageChunk', '_registeredComponents'] },
],
},
},
Expand Down
2 changes: 0 additions & 2 deletions packages/client/src/setupGlobalComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { ClientOnly, Content, RouteLink } from './components/index.js'
* Register global built-in components
*/
export const setupGlobalComponents = (app: App): void => {
/* eslint-disable vue/match-component-file-name, vue/no-reserved-component-names */
app.component('ClientOnly', ClientOnly)
app.component('Content', Content)
app.component('RouteLink', RouteLink)
/* eslint-enable vue/match-component-file-name, vue/no-reserved-component-names */
}
2 changes: 1 addition & 1 deletion packages/client/src/setupGlobalComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const setupGlobalComputed = (
__VUE_HMR_RUNTIME__.updatePageData = async (newPageData: PageData) => {
const oldPageChunk = await routes.value[newPageData.path].loader()
const newPageChunk = { comp: oldPageChunk.comp, data: newPageData }
routes.value[newPageData.path].loader = () =>
routes.value[newPageData.path].loader = async () =>
Promise.resolve(newPageChunk)
if (
newPageData.path ===
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/types/clientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ClientConfig {
app: App
router: Router
siteData: SiteDataRef
}) => void | Promise<void>
}) => Promise<void> | void

/**
* A function to be called inside the setup function of vue app
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/app/createBuildApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { createBaseApp } from './createBaseApp.js'
*/
export const createBuildApp = (config: AppConfig): BuildApp => {
const app = createBaseApp(config, true) as BuildApp
app.build = () => app.options.bundler.build(app)
app.build = async () => app.options.bundler.build(app)
return app
}
2 changes: 1 addition & 1 deletion packages/core/src/app/createDevApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { createBaseApp } from './createBaseApp.js'
*/
export const createDevApp = (config: AppConfig): DevApp => {
const app = createBaseApp(config, false) as DevApp
app.dev = () => app.options.bundler.dev(app)
app.dev = async () => app.options.bundler.dev(app)
return app
}
1 change: 1 addition & 0 deletions packages/core/src/page/resolvePageLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export const resolvePageLang = ({
if (isString(frontmatter.lang) && frontmatter.lang) {
return frontmatter.lang
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unsafe indexed access
return app.siteData.locales[pathLocale]?.lang ?? app.siteData.lang
}
8 changes: 4 additions & 4 deletions packages/core/tests/app/resolveAppEnv.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import type { Bundler, Theme } from '../../src/index.js'
import type { Bundler } from '../../src/index.js'
import { resolveAppEnv, resolveAppOptions } from '../../src/index.js'

const TEST_CASES: [
Expand All @@ -10,7 +10,7 @@ const TEST_CASES: [
[
resolveAppOptions({
source: '/foo',
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
}),
false,
Expand All @@ -25,7 +25,7 @@ const TEST_CASES: [
[
resolveAppOptions({
source: '/foo',
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
debug: true,
}),
Expand All @@ -41,7 +41,7 @@ const TEST_CASES: [
[
resolveAppOptions({
source: '/foo',
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
}),
true,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/app/resolveAppOptions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { path, templateRenderer } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { Bundler, Theme } from '../../src/index.js'
import type { Bundler } from '../../src/index.js'
import { resolveAppOptions } from '../../src/index.js'

describe('core > app > resolveAppOptions', () => {
Expand All @@ -10,7 +10,7 @@ describe('core > app > resolveAppOptions', () => {
expect(
resolveAppOptions({
source,
theme: { name: 'theme' } as Theme,
theme: { name: 'theme' },
bundler: { name: 'bundler' } as Bundler,
}),
).toEqual({
Expand Down
10 changes: 5 additions & 5 deletions packages/core/tests/app/resolveAppPages.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createMarkdown } from '@vuepress/markdown'
import { path } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { Bundler, Theme } from '../../src/index.js'
import type { Bundler } from '../../src/index.js'
import { createBaseApp, resolveAppPages } from '../../src/index.js'

describe('core > app > resolveAppPages', () => {
it('should create two pages with default 404 page', async () => {
const app = createBaseApp({
source: path.resolve(__dirname, '../__fixtures__/pages'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})
app.markdown = createMarkdown()
Expand All @@ -28,7 +28,7 @@ describe('core > app > resolveAppPages', () => {
it('should create two pages with custom 404 page', async () => {
const app = createBaseApp({
source: path.resolve(__dirname, '../__fixtures__/pages-with-404'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})
app.markdown = createMarkdown()
Expand All @@ -47,7 +47,7 @@ describe('core > app > resolveAppPages', () => {
it('should process extendsPageOptions hook correctly', async () => {
const app = createBaseApp({
source: path.resolve(__dirname, '../__fixtures__/pages-with-404'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})

Expand All @@ -71,7 +71,7 @@ describe('core > app > resolveAppPages', () => {
it('should process extendsPage hook correctly', async () => {
const app = createBaseApp({
source: path.resolve(__dirname, '../__fixtures__/pages-with-404'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})

Expand Down
56 changes: 30 additions & 26 deletions packages/core/tests/app/resolveThemeInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
import { importFileDefault, path } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { App, Bundler, Theme, ThemeObject } from '../../src/index.js'
import { createBaseApp, resolveThemeInfo } from '../../src/index.js'

const fixtures = (...args: string[]) =>
const fixtures = (...args: string[]): string =>
path.resolve(__dirname, '../__fixtures__/', ...args)

const createTestApp = async (themePath: string) =>
const createTestApp = async (themePath: string): Promise<App> =>
createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: await importFileDefault(themePath),
bundler: {} as any,
bundler: {} as Bundler,
})

const themeEntryTypes = ['func', 'obj'] as const
const THEME_ENTRY_TYPES = ['func', 'obj'] as const

const getThemePlugin = async (themePath: string) => {
const theme = await importFileDefault(themePath)
return typeof theme === 'function' ? theme() : theme
const getThemePlugin = async (
themePath: string,
app: App,
): Promise<ThemeObject> => {
const theme = await importFileDefault<Theme>(themePath)
return typeof theme === 'function' ? theme(app) : theme
}

describe('core > app > resolveThemeInfo', () => {
describe('plugins', () => {
describe('should resolve theme info without plugins correctly', () => {
themeEntryTypes.forEach((item) =>
THEME_ENTRY_TYPES.forEach((item) => {
it(item, async () => {
const themePath = fixtures(`themes/${item}-empty.js`)
const app = await createTestApp(themePath)
expect(resolveThemeInfo(app, app.options.theme).plugins).toEqual([
await getThemePlugin(themePath),
await getThemePlugin(themePath, app),
])
}),
)
})
})
})

describe('should resolve theme info with plugins correctly', () => {
themeEntryTypes.forEach((item) =>
THEME_ENTRY_TYPES.forEach((item) => {
it(item, async () => {
const themePath = fixtures(`themes/${item}.js`)
const app = await createTestApp(themePath)
expect(resolveThemeInfo(app, app.options.theme).plugins).toEqual([
await importFileDefault(fixtures('plugins/obj.js')),
await getThemePlugin(themePath),
await getThemePlugin(themePath, app),
])
}),
)
})
})
})
})

describe('extends', () => {
describe('should resolve theme info with parent theme correctly', () => {
themeEntryTypes.forEach((item) =>
THEME_ENTRY_TYPES.forEach((item) => {
it(item, async () => {
const themePath = fixtures(`themes/${item}-extends-parent.js`)
const parentThemePath = fixtures(`themes/${item}.js`)
Expand All @@ -58,19 +62,19 @@ describe('core > app > resolveThemeInfo', () => {
expect(resolveThemeInfo(app, app.options.theme)).toEqual({
plugins: [
await importFileDefault(fixtures('plugins/obj.js')),
await getThemePlugin(parentThemePath),
await getThemePlugin(parentThemePath, app),
await importFileDefault(fixtures('plugins/obj-foo.js')),
await getThemePlugin(themePath),
await getThemePlugin(themePath, app),
],
templateBuild: `theme-${item}-extends-parent-template-build`,
templateDev: `theme-${item}-template-dev`,
})
}),
)
})
})
})

describe('should resolve theme info with grandparent theme correctly', () => {
themeEntryTypes.forEach((item) =>
THEME_ENTRY_TYPES.forEach((item) => {
it(item, async () => {
const themePath = fixtures(`themes/${item}-extends-grandparent.js`)
const parentThemePath = fixtures(`themes/${item}-extends-parent.js`)
Expand All @@ -80,17 +84,17 @@ describe('core > app > resolveThemeInfo', () => {
expect(resolveThemeInfo(app, app.options.theme)).toEqual({
plugins: [
await importFileDefault(fixtures('plugins/obj.js')),
await getThemePlugin(grandparentThemePath),
await getThemePlugin(grandparentThemePath, app),
await importFileDefault(fixtures('plugins/obj-foo.js')),
await getThemePlugin(parentThemePath),
await getThemePlugin(parentThemePath, app),
await importFileDefault(fixtures('plugins/obj-bar.js')),
await getThemePlugin(themePath),
await getThemePlugin(themePath, app),
],
templateBuild: `theme-${item}-extends-parent-template-build`,
templateDev: `theme-${item}-extends-grandparent-template-dev`,
})
}),
)
})
})
})
})
})
6 changes: 3 additions & 3 deletions packages/core/tests/page/inferPagePath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { path } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { Bundler, Theme } from '../../src/index.js'
import type { Bundler } from '../../src/index.js'
import { createBaseApp, inferPagePath } from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
locales: {
'/': {},
Expand All @@ -16,7 +16,7 @@ const app = createBaseApp({
})
const appWithoutLocales = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})

Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/page/resolvePageChunkInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { path, sanitizeFileName } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { Bundler } from '../../src/index.js'
import { createBaseApp, resolvePageChunkInfo } from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' },
bundler: {} as any,
bundler: {} as Bundler,
})

describe('core > page > resolvePageChunkInfo', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/page/resolvePageHtmlInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { path } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { Bundler, Theme } from '../../src/index.js'
import type { Bundler } from '../../src/index.js'
import { createBaseApp, resolvePageHtmlInfo } from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})

Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/page/resolvePageLang.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { path } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import type { Bundler, Theme } from '../../src/index.js'
import type { Bundler } from '../../src/index.js'
import { createBaseApp, resolvePageLang } from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
lang: 'site-lang',
locales: {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/pluginApi/createPluginApi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { path } from '@vuepress/utils'
import { describe, expect, it, vi } from 'vitest'
import type { Bundler, HooksName, Theme } from '../../src/index.js'
import type { Bundler, HooksName } from '../../src/index.js'
import { createBaseApp, createPluginApi } from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { path } from '@vuepress/utils'
import { describe, expect, it, vi } from 'vitest'
import type { AliasDefineHook, Bundler, Theme } from '../../src/index.js'
import type { AliasDefineHook, Bundler } from '../../src/index.js'
import { createBaseApp, normalizeAliasDefineHook } from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { path } from '@vuepress/utils'
import { describe, expect, it, vi } from 'vitest'
import type { Bundler, ClientConfigFileHook, Theme } from '../../src/index.js'
import type { Bundler, ClientConfigFileHook } from '../../src/index.js'
import {
createBaseApp,
normalizeClientConfigFileHook,
} from '../../src/index.js'

const app = createBaseApp({
source: path.resolve(__dirname, 'fake-source'),
theme: { name: 'test' } as Theme,
theme: { name: 'test' },
bundler: {} as Bundler,
})
const CLIENT_CONFIG_FILE = path.resolve(
Expand Down
Loading

0 comments on commit 2d377d2

Please sign in to comment.