Skip to content

Commit e693cdc

Browse files
committedOct 10, 2024·
fix(core): fix app env flag regression (close #1612)
1 parent 0f91675 commit e693cdc

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed
 

‎packages/core/src/app/createBaseApp.ts

-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { resolveAppOptions } from './resolveAppOptions.js'
1414
import { resolveAppSiteData } from './resolveAppSiteData.js'
1515
import { resolveAppVersion } from './resolveAppVersion.js'
1616
import { resolveAppWriteTemp } from './resolveAppWriteTemp.js'
17-
import { setupAppThemeAndPlugins } from './setupAppThemeAndPlugins.js'
1817

1918
/**
2019
* Create base vuepress app.
@@ -49,10 +48,5 @@ export const createBaseApp = (config: AppConfig): App => {
4948
prepare: async () => appPrepare(app),
5049
} satisfies AppPropertiesBase as App
5150

52-
// setup theme and plugins
53-
// notice that we setup theme before plugins,
54-
// so user plugins could override theme plugins
55-
setupAppThemeAndPlugins(app, config)
56-
5751
return app
5852
}

‎packages/core/src/app/createBuildApp.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AppConfig, BuildApp } from '../types/index.js'
22
import { createBaseApp } from './createBaseApp.js'
3+
import { setupAppThemeAndPlugins } from './setupAppThemeAndPlugins.js'
34

45
/**
56
* Create vuepress build app.
@@ -11,5 +12,8 @@ export const createBuildApp = (config: AppConfig): BuildApp => {
1112
app.env.isBuild = true
1213
app.build = async () => app.options.bundler.build(app)
1314

15+
// setup theme and plugins
16+
setupAppThemeAndPlugins(app, config)
17+
1418
return app
1519
}

‎packages/core/src/app/createDevApp.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AppConfig, DevApp } from '../types/index.js'
22
import { createBaseApp } from './createBaseApp.js'
3+
import { setupAppThemeAndPlugins } from './setupAppThemeAndPlugins.js'
34

45
/**
56
* Create vuepress dev app.
@@ -11,5 +12,8 @@ export const createDevApp = (config: AppConfig): DevApp => {
1112
app.env.isDev = true
1213
app.dev = async () => app.options.bundler.dev(app)
1314

15+
// setup theme and plugins
16+
setupAppThemeAndPlugins(app, config)
17+
1418
return app
1519
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, it } from 'vitest'
2+
import type { App, BuildApp, Bundler } from '../../src/index.js'
3+
import { createBuildApp } from '../../src/index.js'
4+
5+
it('should create build app correctly', () => {
6+
const checkApp = (app: App): void => {
7+
expect(app.env.isDev).toBe(false)
8+
expect((app as unknown as { dev: never }).dev).toBeUndefined()
9+
10+
expect(app.env.isBuild).toBe(true)
11+
expect(typeof (app as BuildApp).build).toBe('function')
12+
}
13+
14+
const buildApp = createBuildApp({
15+
source: '/foo',
16+
theme: (appInTheme) => {
17+
checkApp(appInTheme)
18+
return { name: 'test-theme' }
19+
},
20+
bundler: {} as Bundler,
21+
plugins: [
22+
(appInPlugin) => {
23+
checkApp(appInPlugin)
24+
return { name: 'test-plugin' }
25+
},
26+
],
27+
})
28+
checkApp(buildApp)
29+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, it } from 'vitest'
2+
import type { App, Bundler, DevApp } from '../../src/index.js'
3+
import { createDevApp } from '../../src/index.js'
4+
5+
it('should create dev app correctly', () => {
6+
const checkApp = (app: App): void => {
7+
expect(app.env.isDev).toBe(true)
8+
expect(typeof (app as DevApp).dev).toBe('function')
9+
10+
expect(app.env.isBuild).toBe(false)
11+
expect((app as unknown as { build: never }).build).toBeUndefined()
12+
}
13+
14+
const devApp = createDevApp({
15+
source: '/foo',
16+
theme: (appInTheme) => {
17+
checkApp(appInTheme)
18+
return { name: 'test-theme' }
19+
},
20+
bundler: {} as Bundler,
21+
plugins: [
22+
(appInPlugin) => {
23+
checkApp(appInPlugin)
24+
return { name: 'test-plugin' }
25+
},
26+
],
27+
})
28+
checkApp(devApp)
29+
})

0 commit comments

Comments
 (0)
Please sign in to comment.