Skip to content

Commit 50f64b4

Browse files
committedJun 2, 2019
fix($core): cannot retrieve the correct theme name when them path is a local absolute path linked to a javascript file.
1 parent 0f4a9d4 commit 50f64b4

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed
 

‎packages/@vuepress/core/lib/node/loadTheme.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ const ThemeAPI = require('./theme-api')
3232

3333
module.exports = function loadTheme (ctx) {
3434
const themeResolver = getThemeResolver()
35-
3635
const theme = resolveTheme(ctx, themeResolver)
36+
3737
if (!theme.path) {
38-
throw new Error(`[vuepress] You must specify a theme, or create a local custom theme. \n For more details, refer to https://vuepress.vuejs.org/guide/custom-themes.html#custom-themes. \n`)
38+
throw new Error(
39+
'[vuepress] You must specify a theme, or create a local custom theme. \n'
40+
+ 'For more details, refer to https://vuepress.vuejs.org/guide/custom-themes.html#custom-themes. \n'
41+
)
3942
}
43+
4044
let applyTip = `Apply theme ${chalk.magenta(theme.name)}`
4145
theme.entry.name = '@vuepress/internal-theme-entry-file'
4246

@@ -46,6 +50,7 @@ module.exports = function loadTheme (ctx) {
4650
parentTheme.entry.name = '@vuepress/internal-parent-theme-entry-file'
4751
applyTip += chalk.gray(` (extends ${chalk.magenta(parentTheme.name)})`)
4852
}
53+
4954
logger.tip(applyTip + ' ...')
5055

5156
logger.debug('theme', theme.name, theme.path)
@@ -74,7 +79,9 @@ function resolveTheme (ctx, resolver, ignoreLocal, theme) {
7479
let shortcut
7580
let entry = {}
7681

77-
// 1. From local
82+
/**
83+
* 1. From `.vuepress/theme` directory.
84+
*/
7885
if (!ignoreLocal
7986
&& !fs.existsSync(theme)
8087
&& fs.existsSync(localThemePath)
@@ -84,15 +91,31 @@ function resolveTheme (ctx, resolver, ignoreLocal, theme) {
8491
name = shortcut = 'local'
8592
logger.tip(`Apply local theme at ${chalk.gray(path)}...`)
8693

87-
// 2. From dep
94+
/**
95+
* 2. From deps or custom local path.
96+
* - vuepress-plugin-foo
97+
* - /path/to/a-theme/index.js
98+
*/
8899
} else if (isString(theme)) {
100+
/**
101+
* To let theme resolver get the correct theme name.
102+
*/
103+
if (theme.endsWith('/index.js')) {
104+
theme = theme.replace(/\/index\.js$/, '')
105+
}
106+
89107
const resolved = resolver.resolve(theme, sourceDir)
90108
if (resolved.entry === null) {
91109
throw new Error(`Cannot resolve theme: ${theme}.`)
92110
}
111+
93112
path = normalizeThemePath(resolved)
94113
name = resolved.name
95114
shortcut = resolved.shortcut
115+
116+
/**
117+
* 3. fallback
118+
*/
96119
} else {
97120
return {}
98121
}

0 commit comments

Comments
 (0)
Please sign in to comment.