Skip to content

Commit

Permalink
fix($core): failed to load theme when using "layouts/Layout.vue" as e…
Browse files Browse the repository at this point in the history
…ntry file (close: #1563) (#1564)
  • Loading branch information
ocavue authored and ulivz committed May 11, 2019
1 parent 15784ac commit 057d8bf
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
Empty file.
2 changes: 2 additions & 0 deletions __mocks__/vuepress-theme-without-index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = {}
// This file is just for jest.
4 changes: 4 additions & 0 deletions __mocks__/vuepress-theme-without-index/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "vuepress-theme-without-index",
"main": "Layout.vue"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('App', () => {
theme: '@vuepress/default',
emp: docsTempPath
})
await app.process()
expect(app.sourceDir).toBe(docsPath)
}))
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
title: 'Hello VuePress',
description: '# Hello, VuePress!',
theme: 'vuepress-theme-without-index'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hello, VuePress!
12 changes: 1 addition & 11 deletions packages/@vuepress/core/lib/node/loadTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,7 @@ module.exports = function loadTheme (ctx) {
function normalizeThemePath (resolved) {
const { entry, name, fromDep } = resolved
if (fromDep) {
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 parse(require.resolve(name)).dir
} else if (entry.endsWith('.js') || entry.endsWith('.vue')) {
return parse(entry).dir
} else {
Expand Down

0 comments on commit 057d8bf

Please sign in to comment.