fix: no false positives for plugins with index.js (#4714)

resolves #4713 [release]
This commit is contained in:
Alexander Lichter 2019-01-08 19:25:56 +00:00 committed by Pooya Parsa
parent 38e2ddf7fe
commit eef2af35e4
4 changed files with 17 additions and 2 deletions

View File

@ -27,7 +27,8 @@ import {
serializeFunction, serializeFunction,
determineGlobals, determineGlobals,
stripWhitespace, stripWhitespace,
isString isString,
isIndexFileAndFolder
} from '@nuxt/utils' } from '@nuxt/utils'
import BuildContext from './context' import BuildContext from './context'
@ -139,7 +140,9 @@ export default class Builder {
if (!pluginFiles || pluginFiles.length === 0) { if (!pluginFiles || pluginFiles.length === 0) {
throw new Error(`Plugin not found: ${p.src}`) throw new Error(`Plugin not found: ${p.src}`)
} else if (pluginFiles.length > 1) { }
if (pluginFiles.length > 1 && !isIndexFileAndFolder(pluginFiles)) {
consola.warn({ consola.warn({
message: `Found ${pluginFiles.length} plugins that match the configuration, suggest to specify extension:`, message: `Found ${pluginFiles.length} plugins that match the configuration, suggest to specify extension:`,
additional: '\n' + pluginFiles.map(x => `- ${x}`).join('\n') additional: '\n' + pluginFiles.map(x => `- ${x}`).join('\n')

View File

@ -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)
}

View File

@ -37,6 +37,7 @@ export default {
extensions: 'ts', extensions: 'ts',
plugins: [ plugins: [
'~/plugins/test', '~/plugins/test',
'~/plugins/doubled',
{ src: '~/plugins/test.plugin', mode: 'abc' }, { src: '~/plugins/test.plugin', mode: 'abc' },
'~/plugins/test.client', '~/plugins/test.client',
'~/plugins/test.server', '~/plugins/test.server',

View File

@ -0,0 +1 @@
export default () => {}