Skip to content

Commit 057d8bf

Browse files
ocavueulivz
authored andcommitted
fix($core): failed to load theme when using "layouts/Layout.vue" as entry file (close: #1563) (#1564)
1 parent 15784ac commit 057d8bf

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

__mocks__/vuepress-theme-without-index/Layout.vue

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports = {}
2+
// This file is just for jest.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "vuepress-theme-without-index",
3+
"main": "Layout.vue"
4+
}

packages/@vuepress/core/lib/node/__tests__/prepare/App.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('App', () => {
1818
theme: '@vuepress/default',
1919
emp: docsTempPath
2020
})
21+
await app.process()
2122
expect(app.sourceDir).toBe(docsPath)
2223
}))
2324
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
title: 'Hello VuePress',
3+
description: '# Hello, VuePress!',
4+
theme: 'vuepress-theme-without-index'
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hello, VuePress!

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,7 @@ module.exports = function loadTheme (ctx) {
5656
function normalizeThemePath (resolved) {
5757
const { entry, name, fromDep } = resolved
5858
if (fromDep) {
59-
const packageRoot = require.resolve(`${name}/package.json`)
60-
const { main } = require(packageRoot)
61-
if (main.endsWith('.vue')) {
62-
// For those cases that "main" field is set to an non-index file
63-
// e.g. `layouts/Layout.vue`
64-
return packageRoot
65-
} else {
66-
// For those cases that "index.js" is not at package root
67-
// e.g. `lib/index.js` (#1362)
68-
return parse(require.resolve(name)).dir
69-
}
59+
return parse(require.resolve(name)).dir
7060
} else if (entry.endsWith('.js') || entry.endsWith('.vue')) {
7161
return parse(entry).dir
7262
} else {

0 commit comments

Comments
 (0)