mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
fix(nuxt): deprecate scanning directory index plugins (#18418)
This commit is contained in:
parent
dccb733f36
commit
c7eb891e12
@ -21,14 +21,14 @@ For example:
|
||||
|
||||
```bash
|
||||
plugins
|
||||
| - myPlugin.ts
|
||||
| - myPlugin.ts // scanned
|
||||
| - myOtherPlugin
|
||||
| --- supportingFile.ts
|
||||
| --- componentToRegister.vue
|
||||
| --- index.ts
|
||||
| --- supportingFile.ts // not scanned
|
||||
| --- componentToRegister.vue // not scanned
|
||||
| --- index.ts // currently scanned but deprecated
|
||||
```
|
||||
|
||||
Only `myPlugin.ts` and `myOtherPlugin/index.ts` would be registered.
|
||||
Only `myPlugin.ts` and `myOtherPlugin/index.ts` would be registered. You can configure [`plugins`](/docs/api/configuration/nuxt-config#plugins-1) to include unscanned files.
|
||||
|
||||
## Creating Plugins
|
||||
|
||||
|
@ -19,6 +19,12 @@ export function normalizePlugin (plugin: NuxtPlugin | string): NuxtPlugin {
|
||||
throw new Error('Invalid plugin. src option is required: ' + JSON.stringify(plugin))
|
||||
}
|
||||
|
||||
// TODO: only scan top-level files #18418
|
||||
const nonTopLevelPlugin = plugin.src.match(/\/plugins\/[^/]+\/index\.[^/]+$/i)
|
||||
if (nonTopLevelPlugin && nonTopLevelPlugin.length > 0 && !useNuxt().options.plugins.find(i => (typeof i === 'string' ? i : i.src).endsWith(nonTopLevelPlugin[0]))) {
|
||||
console.warn(`[warn] [nuxt] [deprecation] You are using a plugin that is within a subfolder of your plugins directory without adding it to your config explicitly. You can move it to the top-level plugins directory, or include the file '~${nonTopLevelPlugin[0]}' in your plugins config (https://nuxt.com/docs/api/configuration/nuxt-config#plugins-1) to remove this warning.`)
|
||||
}
|
||||
|
||||
// Normalize full path to plugin
|
||||
plugin.src = normalize(resolveAlias(plugin.src))
|
||||
|
||||
|
@ -112,7 +112,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
|
||||
...config.srcDir
|
||||
? await resolveFiles(config.srcDir, [
|
||||
`${config.dir?.plugins || 'plugins'}/*.{ts,js,mjs,cjs,mts,cts}`,
|
||||
`${config.dir?.plugins || 'plugins'}/*/index.*{ts,js,mjs,cjs,mts,cts}`
|
||||
`${config.dir?.plugins || 'plugins'}/*/index.*{ts,js,mjs,cjs,mts,cts}` // TODO: remove, only scan top-level plugins #18418
|
||||
])
|
||||
: []
|
||||
].map(plugin => normalizePlugin(plugin as NuxtPlugin)))
|
||||
|
Loading…
Reference in New Issue
Block a user