diff --git a/__mocks__/vuepress-theme-without-index/Layout.vue b/__mocks__/vuepress-theme-without-index/Layout.vue new file mode 100644 index 0000000000..e69de29bb2 diff --git a/__mocks__/vuepress-theme-without-index/index.js b/__mocks__/vuepress-theme-without-index/index.js new file mode 100644 index 0000000000..964c7556a5 --- /dev/null +++ b/__mocks__/vuepress-theme-without-index/index.js @@ -0,0 +1,2 @@ +module.exports = {} +// This file is just for jest. diff --git a/__mocks__/vuepress-theme-without-index/package.json b/__mocks__/vuepress-theme-without-index/package.json new file mode 100644 index 0000000000..b31f134663 --- /dev/null +++ b/__mocks__/vuepress-theme-without-index/package.json @@ -0,0 +1,4 @@ +{ + "name": "vuepress-theme-without-index", + "main": "Layout.vue" +} diff --git a/packages/@vuepress/core/lib/node/__tests__/prepare/App.spec.js b/packages/@vuepress/core/lib/node/__tests__/prepare/App.spec.js index f33eef167a..dbeb1e3c50 100644 --- a/packages/@vuepress/core/lib/node/__tests__/prepare/App.spec.js +++ b/packages/@vuepress/core/lib/node/__tests__/prepare/App.spec.js @@ -18,6 +18,7 @@ describe('App', () => { theme: '@vuepress/default', emp: docsTempPath }) + await app.process() expect(app.sourceDir).toBe(docsPath) })) }) diff --git a/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/.vuepress/config.js b/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/.vuepress/config.js new file mode 100644 index 0000000000..d2d07ae082 --- /dev/null +++ b/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/.vuepress/config.js @@ -0,0 +1,5 @@ +module.exports = { + title: 'Hello VuePress', + description: '# Hello, VuePress!', + theme: 'vuepress-theme-without-index' + } diff --git a/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/README.md b/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/README.md new file mode 100644 index 0000000000..aef89369f1 --- /dev/null +++ b/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/README.md @@ -0,0 +1 @@ +# Hello, VuePress! diff --git a/packages/@vuepress/core/lib/node/loadTheme.js b/packages/@vuepress/core/lib/node/loadTheme.js index 3cba5c0dbe..11d9d295a5 100755 --- a/packages/@vuepress/core/lib/node/loadTheme.js +++ b/packages/@vuepress/core/lib/node/loadTheme.js @@ -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 {