Skip to content

Commit

Permalink
fix: the layer's plugin takes precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Apr 6, 2024
1 parent 9907f33 commit 0bd2f31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/nuxt/src/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
// Normalize and de-duplicate plugins and middleware and hoist (and sort)
// middleware/plugin files that begin with a number
app.middleware = sortMiddleware(uniqueBy(await resolvePaths([...app.middleware].reverse(), 'path'), 'name').reverse())
app.plugins = sortPlugins(uniquePlugins(await resolvePaths([...app.plugins].reverse(), 'src')))
app.plugins = sortPlugins(uniquePlugins(await resolvePaths(app.plugins, 'src')))

// Resolve app.config
app.configs = []
Expand Down Expand Up @@ -290,7 +290,7 @@ function sortPlugins (plugins: NuxtPlugin[]) {
function uniquePlugins (plugins: NuxtPlugin[]) {
const pluginFlags = new Set<string>()
const bucket: NuxtPlugin[] = []
for (const plugin of plugins) {
for (const plugin of [...plugins].reverse()) {
const name = plugin.name ? plugin.name : filename(plugin.src)
const mode = plugin.mode ? plugin.mode : 'all'
const flag = `${name}.${mode}`
Expand All @@ -300,5 +300,5 @@ function uniquePlugins (plugins: NuxtPlugin[]) {
pluginFlags.add(flag)
bucket.push(plugin)
}
return bucket
return bucket.reverse()
}
30 changes: 15 additions & 15 deletions packages/nuxt/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ describe('resolveApp', () => {
"plugins": [
{
"mode": "client",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/chunk-reload.client.ts",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/payload.client.ts",
},
{
"mode": "all",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/router.ts",
"mode": "client",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/check-outdated-build.client.ts",
},
{
"mode": "all",
"src": "<repoRoot>/packages/nuxt/src/head/runtime/plugins/unhead.ts",
"mode": "server",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/revive-payload.server.ts",
},
{
"mode": "client",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/revive-payload.client.ts",
},
{
"filename": "components.plugin.mjs",
Expand All @@ -58,20 +62,16 @@ describe('resolveApp', () => {
"src": "<rootDir>/.nuxt/components.plugin.mjs",
},
{
"mode": "client",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/revive-payload.client.ts",
},
{
"mode": "server",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/revive-payload.server.ts",
"mode": "all",
"src": "<repoRoot>/packages/nuxt/src/head/runtime/plugins/unhead.ts",
},
{
"mode": "client",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/check-outdated-build.client.ts",
"mode": "all",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/router.ts",
},
{
"mode": "client",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/payload.client.ts",
"src": "<repoRoot>/packages/nuxt/src/app/plugins/chunk-reload.client.ts",
},
],
"rootComponent": "<repoRoot>/packages/nuxt/src/app/components/nuxt-root.vue",
Expand Down Expand Up @@ -139,8 +139,8 @@ describe('resolveApp', () => {
"<rootDir>/plugins/00.plugin.ts",
"<rootDir>/layer2/plugins/01.plugin.ts",
"<rootDir>/layer1/plugins/02.plugin.ts",
"<rootDir>/plugins/object-named.ts",
"<rootDir>/layer2/plugins/override-test.ts",
"<rootDir>/plugins/object-named.ts",
]
`)
})
Expand Down

0 comments on commit 0bd2f31

Please sign in to comment.