提交 50f64b47 编写于 作者: U ULIVZ

fix($core): cannot retrieve the correct theme name when them path is a local...

fix($core): cannot retrieve the correct theme name when them path is a local absolute path linked to a javascript file.
上级 0f4a9d4a
......@@ -32,11 +32,15 @@ const ThemeAPI = require('./theme-api')
module.exports = function loadTheme (ctx) {
const themeResolver = getThemeResolver()
const theme = resolveTheme(ctx, themeResolver)
if (!theme.path) {
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`)
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'
)
}
let applyTip = `Apply theme ${chalk.magenta(theme.name)}`
theme.entry.name = '@vuepress/internal-theme-entry-file'
......@@ -46,6 +50,7 @@ module.exports = function loadTheme (ctx) {
parentTheme.entry.name = '@vuepress/internal-parent-theme-entry-file'
applyTip += chalk.gray(` (extends ${chalk.magenta(parentTheme.name)})`)
}
logger.tip(applyTip + ' ...')
logger.debug('theme', theme.name, theme.path)
......@@ -74,7 +79,9 @@ function resolveTheme (ctx, resolver, ignoreLocal, theme) {
let shortcut
let entry = {}
// 1. From local
/**
* 1. From `.vuepress/theme` directory.
*/
if (!ignoreLocal
&& !fs.existsSync(theme)
&& fs.existsSync(localThemePath)
......@@ -84,15 +91,31 @@ function resolveTheme (ctx, resolver, ignoreLocal, theme) {
name = shortcut = 'local'
logger.tip(`Apply local theme at ${chalk.gray(path)}...`)
// 2. From dep
/**
* 2. From deps or custom local path.
* - vuepress-plugin-foo
* - /path/to/a-theme/index.js
*/
} else if (isString(theme)) {
/**
* To let theme resolver get the correct theme name.
*/
if (theme.endsWith('/index.js')) {
theme = theme.replace(/\/index\.js$/, '')
}
const resolved = resolver.resolve(theme, sourceDir)
if (resolved.entry === null) {
throw new Error(`Cannot resolve theme: ${theme}.`)
}
path = normalizeThemePath(resolved)
name = resolved.name
shortcut = resolved.shortcut
/**
* 3. fallback
*/
} else {
return {}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册