Skip to content

Commit 6d156a0

Browse files
committed
Merge branch 'main' into meteorlxy-markdown-to-vue
2 parents 5989c91 + a0da533 commit 6d156a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1952
-1771
lines changed

e2e/docs/.vuepress/plugins/foo/fooPlugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { Plugin } from 'vuepress/core'
12
import { getDirname, path } from 'vuepress/utils'
23

34
const __dirname = getDirname(import.meta.url)
45

5-
export const fooPlugin = {
6+
export const fooPlugin: Plugin = {
67
name: 'test-plugin',
78
clientConfigFile: path.resolve(
89
__dirname,

packages/cli/tests/config/loadUserConfig.spec.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,29 @@ const MJS_CASES: [string, unknown][] = [
4747
],
4848
]
4949

50-
describe('cli > config > loadUserConfig', () => {
51-
describe('should load ts config file correctly', () => {
52-
TS_CASES.forEach(([source, expected]) => {
53-
it(JSON.stringify(source), async () => {
54-
const { userConfig } = await loadUserConfig(source)
55-
expect(userConfig).toEqual(expected)
56-
})
50+
describe('should load ts config file correctly', () => {
51+
TS_CASES.forEach(([source, expected]) => {
52+
it(JSON.stringify(source), async () => {
53+
const { userConfig } = await loadUserConfig(source)
54+
expect(userConfig).toEqual(expected)
5755
})
5856
})
57+
})
5958

60-
describe('should load js config file correctly', () => {
61-
JS_CASES.forEach(([source, expected]) => {
62-
it(JSON.stringify(source), async () => {
63-
const { userConfig } = await loadUserConfig(source)
64-
expect(userConfig).toEqual(expected)
65-
})
59+
describe('should load js config file correctly', () => {
60+
JS_CASES.forEach(([source, expected]) => {
61+
it(JSON.stringify(source), async () => {
62+
const { userConfig } = await loadUserConfig(source)
63+
expect(userConfig).toEqual(expected)
6664
})
6765
})
66+
})
6867

69-
describe('should load mjs config file correctly', () => {
70-
MJS_CASES.forEach(([source, expected]) => {
71-
it(JSON.stringify(source), async () => {
72-
const { userConfig } = await loadUserConfig(source)
73-
expect(userConfig).toEqual(expected)
74-
})
68+
describe('should load mjs config file correctly', () => {
69+
MJS_CASES.forEach(([source, expected]) => {
70+
it(JSON.stringify(source), async () => {
71+
const { userConfig } = await loadUserConfig(source)
72+
expect(userConfig).toEqual(expected)
7573
})
7674
})
7775
})

packages/cli/tests/config/resolveUserConfigConventionalPath.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ const TEST_CASES: [string, string][] = [
1414
[resolveFixtures('case6'), '.vuepress/config.mjs'],
1515
]
1616

17-
describe('cli > config > resolveUserConfigConventionalPath', () => {
18-
describe('should resolve conventional config file correctly', () => {
19-
TEST_CASES.forEach(([source, expected]) => {
20-
it(expected, () => {
21-
const configFile = resolveUserConfigConventionalPath(source, source)
22-
expect(configFile).toEqual(path.resolve(source, expected))
23-
})
17+
describe('should resolve conventional config file correctly', () => {
18+
TEST_CASES.forEach(([source, expected]) => {
19+
it(expected, () => {
20+
const configFile = resolveUserConfigConventionalPath(source, source)
21+
expect(configFile).toEqual(path.resolve(source, expected))
2422
})
2523
})
2624
})
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
import { path } from '@vuepress/utils'
2-
import { describe, expect, it, vi } from 'vitest'
2+
import { expect, it, vi } from 'vitest'
33
import { resolveUserConfigPath } from '../../src/index.js'
44

55
const resolveFixtures = (str: string): string =>
66
path.resolve(__dirname, '../__fixtures__/config', str)
77

8-
describe('cli > config > resolveUserConfigPath', () => {
9-
it('should resolve absolute file path correctly', () => {
10-
const absolutePath = resolveFixtures('custom-config.ts')
11-
const configFile = resolveUserConfigPath(absolutePath)
12-
expect(configFile).toEqual(absolutePath)
13-
})
8+
it('should resolve absolute file path correctly', () => {
9+
const absolutePath = resolveFixtures('custom-config.ts')
10+
const configFile = resolveUserConfigPath(absolutePath)
11+
expect(configFile).toEqual(absolutePath)
12+
})
1413

15-
it('should resolve relative file path correctly', () => {
16-
const relativePath = 'custom-config.ts'
17-
const configFile = resolveUserConfigPath(relativePath, resolveFixtures(''))
18-
expect(configFile).toEqual(resolveFixtures(relativePath))
19-
})
14+
it('should resolve relative file path correctly', () => {
15+
const relativePath = 'custom-config.ts'
16+
const configFile = resolveUserConfigPath(relativePath, resolveFixtures(''))
17+
expect(configFile).toEqual(resolveFixtures(relativePath))
18+
})
2019

21-
it('should throw an error if file does not exist', () => {
22-
const consoleError = console.error
23-
console.error = vi.fn()
20+
it('should throw an error if file does not exist', () => {
21+
const consoleError = console.error
22+
console.error = vi.fn()
2423

25-
expect(() => {
26-
resolveUserConfigPath('4-0-4')
27-
}).toThrow()
28-
expect(console.error).toHaveBeenCalled()
24+
expect(() => {
25+
resolveUserConfigPath('4-0-4')
26+
}).toThrow()
27+
expect(console.error).toHaveBeenCalled()
2928

30-
console.error = consoleError
31-
})
29+
console.error = consoleError
3230
})

packages/core/src/app/appInit.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const log = debug('vuepress:core/app')
99
* Initialize a vuepress app
1010
*
1111
* Plugins should be used before initialization.
12+
*
13+
* @internal
1214
*/
1315
export const appInit = async (app: App): Promise<void> => {
1416
log('init start')

packages/core/src/app/appPrepare.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const log = debug('vuepress:core/app')
1616
* - routes
1717
* - site data
1818
* - other files that generated by plugins
19+
*
20+
* @internal
1921
*/
2022
export const appPrepare = async (app: App): Promise<void> => {
2123
log('prepare start')

packages/core/src/app/appUse.ts

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { resolvePluginObject } from './resolvePluginObject.js'
44

55
const log = debug('vuepress:core/app')
66

7+
/**
8+
* Use a plugin in vuepress app.
9+
*
10+
* Should be called before initialization.
11+
*
12+
* @internal
13+
*/
714
export const appUse = (app: App, rawPlugin: Plugin): App => {
815
const pluginObject = resolvePluginObject(app, rawPlugin)
916

packages/core/src/app/createBaseApp.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { createPluginApi } from '../pluginApi/index.js'
2-
import type { App, AppConfig, Plugin } from '../types/index.js'
2+
import type {
3+
App,
4+
AppConfig,
5+
AppPropertiesBase,
6+
Plugin,
7+
} from '../types/index.js'
38
import { appInit } from './appInit.js'
49
import { appPrepare } from './appPrepare.js'
510
import { appUse } from './appUse.js'
@@ -12,12 +17,16 @@ import { resolveAppWriteTemp } from './resolveAppWriteTemp.js'
1217
import { setupAppThemeAndPlugins } from './setupAppThemeAndPlugins.js'
1318

1419
/**
15-
* Create vuepress app
20+
* Create base vuepress app.
21+
*
22+
* Notice that the base app could not be used for dev nor build.
23+
*
24+
* It would be used for creating dev app or build app, or for testing.
1625
*/
17-
export const createBaseApp = (config: AppConfig, isBuild = false): App => {
26+
export const createBaseApp = (config: AppConfig): App => {
1827
const options = resolveAppOptions(config)
1928
const dir = resolveAppDir(options)
20-
const env = resolveAppEnv(options, isBuild)
29+
const env = resolveAppEnv(options)
2130
const pluginApi = createPluginApi()
2231
const siteData = resolveAppSiteData(options)
2332
const version = resolveAppVersion()
@@ -38,7 +47,7 @@ export const createBaseApp = (config: AppConfig, isBuild = false): App => {
3847
use: (plugin: Plugin) => appUse(app, plugin),
3948
init: async () => appInit(app),
4049
prepare: async () => appPrepare(app),
41-
} as App
50+
} satisfies AppPropertiesBase as App
4251

4352
// setup theme and plugins
4453
// notice that we setup theme before plugins,

packages/core/src/app/createBuildApp.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import type { AppConfig, BuildApp } from '../types/index.js'
22
import { createBaseApp } from './createBaseApp.js'
33

44
/**
5-
* Create vuepress build app
5+
* Create vuepress build app.
66
*/
77
export const createBuildApp = (config: AppConfig): BuildApp => {
8-
const app = createBaseApp(config, true) as BuildApp
8+
const app = createBaseApp(config) as BuildApp
9+
10+
// set env flag and add build method
11+
app.env.isBuild = true
912
app.build = async () => app.options.bundler.build(app)
13+
1014
return app
1115
}

packages/core/src/app/createDevApp.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import type { AppConfig, DevApp } from '../types/index.js'
22
import { createBaseApp } from './createBaseApp.js'
33

44
/**
5-
* Create vuepress dev app
5+
* Create vuepress dev app.
66
*/
77
export const createDevApp = (config: AppConfig): DevApp => {
8-
const app = createBaseApp(config, false) as DevApp
8+
const app = createBaseApp(config) as DevApp
9+
10+
// set env flag and add dev method
11+
app.env.isDev = true
912
app.dev = async () => app.options.bundler.dev(app)
13+
1014
return app
1115
}

packages/core/src/app/prepare/prepareClientConfigs.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { App } from '../../types/index.js'
22

33
/**
44
* Generate client configs temp file
5+
*
6+
* @internal
57
*/
68
export const prepareClientConfigs = async (app: App): Promise<void> => {
79
// plugin hook: clientConfigFile

packages/core/src/app/prepare/prepareRoutes.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ if (import.meta.hot) {
2121

2222
/**
2323
* Resolve page redirects
24+
*
25+
* @internal
2426
*/
2527
const resolvePageRedirects = ({ path, pathInferred }: Page): string[] => {
2628
// paths that should redirect to this page, use set to dedupe

packages/core/src/app/prepare/prepareSiteData.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if (import.meta.hot) {
1717

1818
/**
1919
* Generate site data temp file
20+
*
21+
* @internal
2022
*/
2123
export const prepareSiteData = async (app: App): Promise<void> => {
2224
let content = `\

packages/core/src/app/resolveAppDir.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const require = createRequire(import.meta.url)
66

77
/**
88
* Create directory util function
9+
*
10+
* @internal
911
*/
1012
export const createAppDirFunction =
1113
(baseDir: string): AppDirFunction =>

packages/core/src/app/resolveAppEnv.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import type { AppEnv, AppOptions } from '../types/index.js'
22

33
/**
44
* Resolve environment flags for vuepress app
5+
*
6+
* @internal
57
*/
6-
export const resolveAppEnv = (
7-
options: AppOptions,
8-
isBuild: boolean,
9-
): AppEnv => ({
10-
isBuild,
11-
isDev: !isBuild,
8+
export const resolveAppEnv = (options: AppOptions): AppEnv => ({
9+
isBuild: false,
10+
isDev: false,
1211
isDebug: options.debug,
1312
})

packages/core/src/app/resolveAppMarkdown.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { App } from '../types/index.js'
44

55
/**
66
* Resolve markdown-it instance for vuepress app
7+
*
8+
* @internal
79
*/
810
export const resolveAppMarkdown = async (app: App): Promise<Markdown> => {
911
// plugin hook: extendsMarkdownOptions

packages/core/src/app/resolveAppOptions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const require = createRequire(import.meta.url)
66

77
/**
88
* Create app options with default values
9+
*
10+
* @internal
911
*/
1012
export const resolveAppOptions = ({
1113
// site config
@@ -34,6 +36,7 @@ export const resolveAppOptions = ({
3436
templateBuild = path.normalize(
3537
require.resolve('@vuepress/client/templates/build.html'),
3638
),
39+
templateBuildRenderer = templateRenderer,
3740
// common config
3841
bundler,
3942
debug = false,
@@ -61,7 +64,7 @@ export const resolveAppOptions = ({
6164
shouldPreload,
6265
shouldPrefetch,
6366
templateBuild,
64-
templateBuildRenderer: templateRenderer,
67+
templateBuildRenderer,
6568
bundler,
6669
debug,
6770
markdown,

packages/core/src/app/resolveAppPages.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const log = debug('vuepress:core/app')
66

77
/**
88
* Resolve pages for vuepress app
9+
*
10+
* @internal
911
*/
1012
export const resolveAppPages = async (
1113
app: App,

packages/core/src/app/resolveAppSiteData.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { AppOptions, SiteData } from '../types/index.js'
44
* Resolve site data for vuepress app
55
*
66
* Site data will also be used in client
7+
*
8+
* @internal
79
*/
810
export const resolveAppSiteData = (options: AppOptions): SiteData => ({
911
base: options.base,

packages/core/src/app/resolveAppVersion.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const require = createRequire(import.meta.url)
55

66
/**
77
* Resolve version of vuepress app
8+
*
9+
* @internal
810
*/
911
export const resolveAppVersion = (): string => {
1012
const pkgJson = fs.readJsonSync(

packages/core/src/app/resolveAppWriteTemp.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { AppDir, AppWriteTemp } from '../types/index.js'
33

44
/**
55
* Resolve write temp file util for vuepress app
6+
*
7+
* @internal
68
*/
79
export const resolveAppWriteTemp = (dir: AppDir): AppWriteTemp => {
810
const writeTemp: AppWriteTemp = async (file: string, content: string) => {

packages/core/src/app/resolvePluginObject.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { App, Plugin, PluginObject } from '../types/index.js'
33

44
/**
55
* Resolve a plugin object according to name / path / module and config
6+
*
7+
* @internal
68
*/
79
export const resolvePluginObject = <T extends PluginObject = PluginObject>(
810
app: App,

packages/core/src/app/resolveThemeInfo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { resolvePluginObject } from './resolvePluginObject.js'
33

44
/**
55
* Resolve theme info and its parent theme info
6+
*
7+
* @internal
68
*/
79
export const resolveThemeInfo = (app: App, theme: Theme): ThemeInfo => {
810
// resolve current theme info

packages/core/src/app/setupAppThemeAndPlugins.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { resolveThemeInfo } from './resolveThemeInfo.js'
33

44
/**
55
* Setup theme and plugins for vuepress app
6+
*
7+
* @internal
68
*/
79
export const setupAppThemeAndPlugins = (app: App, config: AppConfig): void => {
810
// recursively resolve theme info

packages/core/src/page/createPage.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { resolvePagePermalink } from './resolvePagePermalink.js'
1212
import { resolvePageRouteMeta } from './resolvePageRouteMeta.js'
1313
import { resolvePageSlug } from './resolvePageSlug.js'
1414

15+
/**
16+
* Create vuepress page object
17+
*/
1518
export const createPage = async (
1619
app: App,
1720
options: PageOptions,

0 commit comments

Comments
 (0)