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,
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')

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',
plugins: [
'~/plugins/test',
'~/plugins/doubled',
{ src: '~/plugins/test.plugin', mode: 'abc' },
'~/plugins/test.client',
'~/plugins/test.server',

View File

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