mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: no false positives for plugins with index.js (#4714)
resolves #4713 [release]
This commit is contained in:
parent
38e2ddf7fe
commit
eef2af35e4
@ -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')
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
1
test/fixtures/with-config/nuxt.config.js
vendored
1
test/fixtures/with-config/nuxt.config.js
vendored
@ -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',
|
||||||
|
1
test/fixtures/with-config/plugins/doubled/index.js
vendored
Normal file
1
test/fixtures/with-config/plugins/doubled/index.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default () => {}
|
Loading…
Reference in New Issue
Block a user