Skip to content

Commit

Permalink
fix($core): cannot retrieve the correct theme name when them path is …
Browse files Browse the repository at this point in the history
…a local absolute path linked to a javascript file.
  • Loading branch information
ulivz committed Jun 2, 2019
1 parent 0f4a9d4 commit 50f64b4
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions packages/@vuepress/core/lib/node/loadTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {}
}
Expand Down

0 comments on commit 50f64b4

Please sign in to comment.