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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 17 additions & 19 deletions
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

Lines changed: 5 additions & 7 deletions
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
})
Lines changed: 19 additions & 21 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 14 additions & 5 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 6 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)