diff --git a/lib/builder/builder.js b/lib/builder/builder.js index 1442466cb9..c2a300c585 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -446,9 +446,17 @@ export default class Builder { // Check plugins exist then set alias to their real path await Promise.all(this.plugins.map(async (p) => { - const pluginFile = `${p.src}${path.extname(p.src) ? '' : '.js'}` - if (!await fsExtra.pathExists(pluginFile)) { - throw new Error(`Plugin not found: ${pluginFile}`) + const ext = path.extname(p.src) ? '' : '.+([^.])' + const pluginFiles = await glob(`${p.src}${ext}`) + + if (!pluginFiles || pluginFiles.length === 0) { + throw new Error(`Plugin not found: ${p.src}`) + } else if (pluginFiles.length > 1) { + consola.warn({ + message: `Found ${pluginFiles.length} plugins that match the configuration, suggest to specify extension:`, + additional: ` ${pluginFiles.join('\n ')}`, + badge: true + }) } const src = this.relativeToBuild(p.src) diff --git a/test/fixtures/with-config/plugins/test.json b/test/fixtures/with-config/plugins/test.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/with-config/with-config.test.js b/test/fixtures/with-config/with-config.test.js index 51962589d3..5edaa02493 100644 --- a/test/fixtures/with-config/with-config.test.js +++ b/test/fixtures/with-config/with-config.test.js @@ -1,3 +1,16 @@ +const consola = require('consola') const { buildFixture } = require('../../utils/build') -buildFixture('with-config') +describe('with-config', () => { + beforeAll(() => { + consola.warn = jest.fn() + }) + buildFixture('with-config', () => { + expect(consola.warn).toHaveBeenCalledTimes(1) + expect(consola.warn.mock.calls[0]).toMatchObject([{ + message: 'Found 2 plugins that match the configuration, suggest to specify extension:', + additional: expect.stringContaining('plugins/test.json'), + badge: true + }]) + }) +}) diff --git a/test/utils/build.js b/test/utils/build.js index 52317fa65d..d03ddc7279 100644 --- a/test/utils/build.js +++ b/test/utils/build.js @@ -1,6 +1,6 @@ import { loadFixture, Nuxt, Builder } from './index' -export const buildFixture = function buildFixture(fixture) { +export const buildFixture = function (fixture, callback) { test(`Build ${fixture}`, async () => { const config = loadFixture(fixture) const nuxt = new Nuxt(config) @@ -10,5 +10,8 @@ export const buildFixture = function buildFixture(fixture) { // 2: BUILD_DONE expect(builder._buildStatus).toBe(2) expect(buildDone).toHaveBeenCalledTimes(1) + if (typeof callback === 'function') { + callback(builder) + } }, 120000) }