From e7df65be1a934aab507a3df07c71c2f9eb842879 Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Tue, 18 Dec 2018 14:19:38 +0000 Subject: [PATCH] fix: detect plugin without extension (#4579) --- packages/builder/src/builder.js | 2 +- test/fixtures/with-config/nuxt.config.js | 1 + test/fixtures/with-config/plugins/test.plugin.js | 5 +++++ test/unit/with-config.test.js | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/with-config/plugins/test.plugin.js diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 9196229faa..093cf14245 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -123,7 +123,7 @@ export default class Builder { resolvePlugins() { // Check plugins exist then set alias to their real path return Promise.all(this.plugins.map(async (p) => { - const ext = path.extname(p.src) ? '' : '{.+([^.]),/index.+([^.])}' + const ext = '{?(.+([^.])),/index.+([^.])}' const pluginFiles = await glob(`${p.src}${ext}`) if (!pluginFiles || pluginFiles.length === 0) { diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 670c6508bf..13caab9570 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -37,6 +37,7 @@ export default { extensions: 'ts', plugins: [ '~/plugins/test', + '~/plugins/test.plugin', { src: '~/plugins/only-client.js', ssr: false } ], loading: '~/components/loading', diff --git a/test/fixtures/with-config/plugins/test.plugin.js b/test/fixtures/with-config/plugins/test.plugin.js new file mode 100644 index 0000000000..9d36fa2f97 --- /dev/null +++ b/test/fixtures/with-config/plugins/test.plugin.js @@ -0,0 +1,5 @@ +if (process.client) { + window.__test_plugin_ext = true +} else { + global.__test_plugin_ext = true +} diff --git a/test/unit/with-config.test.js b/test/unit/with-config.test.js index 754ef49676..7860deab6e 100644 --- a/test/unit/with-config.test.js +++ b/test/unit/with-config.test.js @@ -90,6 +90,7 @@ describe('with-config', () => { expect(html).toContain('

I have custom configurations

') expect(window.__test_plugin).toBe(true) + expect(window.__test_plugin_ext).toBe(true) }) test('/test/about (custom layout)', async () => {