From 0a1ae2a9ca120cc309ad5ffea3cfac4f21296e5a Mon Sep 17 00:00:00 2001 From: ocavue Date: Sun, 28 Apr 2019 22:16:26 +0800 Subject: [PATCH 1/2] test: Add a test for themes from dependencies using Layout.vue as entry point --- __mocks__/vuepress-theme-without-index/Layout.vue | 0 __mocks__/vuepress-theme-without-index/index.js | 2 ++ __mocks__/vuepress-theme-without-index/package.json | 4 ++++ .../@vuepress/core/lib/node/__tests__/prepare/App.spec.js | 1 + .../docs-dep-theme-without-index/.vuepress/config.js | 5 +++++ .../prepare/fixtures/docs-dep-theme-without-index/README.md | 1 + 6 files changed, 13 insertions(+) create mode 100644 __mocks__/vuepress-theme-without-index/Layout.vue create mode 100644 __mocks__/vuepress-theme-without-index/index.js create mode 100644 __mocks__/vuepress-theme-without-index/package.json create mode 100644 packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/.vuepress/config.js create mode 100644 packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-dep-theme-without-index/README.md 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! From d7dba3a56599aa80148960f8d0e1e579d77d7297 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sun, 28 Apr 2019 22:14:19 +0800 Subject: [PATCH 2/2] fix: "ENOTDIR: not a directory" error --- packages/@vuepress/core/lib/node/loadTheme.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) 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 {