Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($core): support theme index file which is not at root (close: #1362) #1376

Merged
merged 1 commit into from
Mar 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/@vuepress/core/lib/prepare/loadTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ module.exports = function loadTheme (ctx) {
function normalizeThemePath (resolved) {
const { entry, name, fromDep } = resolved
if (fromDep) {
const pkgPath = require.resolve(name)
let packageRootDir = parse(pkgPath).dir
// For those cases that "main" field was set to non-index file
// e.g. `layouts/Layout.vue`
while (!fs.existsSync(`${packageRootDir}/package.json`)) {
packageRootDir = resolve(packageRootDir, '..')
const packageRoot = require.resolve(`${name}/package.json`)
const { main } = require(packageRoot)
if (main.endsWith('.vue')) {
// For those cases that "main" field is set to an non-index file
// e.g. `layouts/Layout.vue`
return packageRoot
} else {
// For those cases that "index.js" is not at package root
// e.g. `lib/index.js` (#1362)
return parse(require.resolve(name)).dir
}
return packageRootDir
} else if (entry.endsWith('.js') || entry.endsWith('.vue')) {
return parse(entry).dir
} else {
Expand Down