diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 4703749e32..b3b10750bd 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -27,7 +27,8 @@ import { serializeFunction, determineGlobals, stripWhitespace, - isString + isString, + isIndexFileAndFolder } from '@nuxt/utils' import BuildContext from './context' @@ -139,7 +140,9 @@ export default class Builder { if (!pluginFiles || pluginFiles.length === 0) { throw new Error(`Plugin not found: ${p.src}`) - } else if (pluginFiles.length > 1) { + } + + if (pluginFiles.length > 1 && !isIndexFileAndFolder(pluginFiles)) { consola.warn({ message: `Found ${pluginFiles.length} plugins that match the configuration, suggest to specify extension:`, additional: '\n' + pluginFiles.map(x => `- ${x}`).join('\n') diff --git a/packages/utils/src/resolve.js b/packages/utils/src/resolve.js index 999499d701..d468fa4660 100644 --- a/packages/utils/src/resolve.js +++ b/packages/utils/src/resolve.js @@ -98,3 +98,13 @@ export function defineAlias(src, target, prop, opts = {}) { } }) } + +const isIndex = s => /(.*)\/index\.[^/]+$/.test(s) + +export function isIndexFileAndFolder(pluginFiles) { + // Return early in case the matching file count exceeds 2 (index.js + folder) + if (pluginFiles.length !== 2) { + return false + } + return pluginFiles.some(isIndex) +} diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index a73b7ffed5..d27dab4503 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/doubled', { src: '~/plugins/test.plugin', mode: 'abc' }, '~/plugins/test.client', '~/plugins/test.server', diff --git a/test/fixtures/with-config/plugins/doubled/index.js b/test/fixtures/with-config/plugins/doubled/index.js new file mode 100644 index 0000000000..ead516c976 --- /dev/null +++ b/test/fixtures/with-config/plugins/doubled/index.js @@ -0,0 +1 @@ +export default () => {}