From f4ec13bc6d7983909116f9c70a4e6834c1e00f47 Mon Sep 17 00:00:00 2001 From: David Marr Date: Thu, 20 Jun 2024 10:16:30 -0400 Subject: [PATCH] feat(nuxt): Support nuxt layers in a better way --- packages/nuxt/src/module.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index b528bad4f6..43ec644207 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -7,7 +7,7 @@ import { isNuxt2, addImports, createResolver, - resolveModule, + resolvePath, addImportsDir, } from '@nuxt/kit' import type { NuxtModule } from '@nuxt/schema' @@ -43,7 +43,7 @@ const module: NuxtModule = defineNuxtModule({ defaults: { disableVuex: true, }, - setup(options, nuxt) { + async setup(options, nuxt) { const resolver = createResolver(import.meta.url) // Disable default Vuex store (Nuxt v2.10+ only) @@ -61,12 +61,9 @@ const module: NuxtModule = defineNuxtModule({ nuxt.options.build.transpile.push(resolver.resolve('./runtime')) // Make sure we use the mjs build for pinia - nuxt.options.alias.pinia = - nuxt.options.alias.pinia || - // FIXME: remove this deprecated call. Ensure it works in Nuxt 2 to 3 - resolveModule('pinia/dist/pinia.mjs', { - paths: [nuxt.options.rootDir, import.meta.url], - }) + if (!nuxt.options.alias.pinia) { + nuxt.options.alias.pinia = await resolvePath('pinia/dist/pinia.mjs') + } nuxt.hook('prepare:types', ({ references }) => { references.push({ types: '@pinia/nuxt' }) @@ -97,7 +94,11 @@ const module: NuxtModule = defineNuxtModule({ } if (options.storesDirs) { - for (const storeDir of options.storesDirs) { + for (const storeDir of [ + ...options.storesDirs, + /* @ts-expect-error storesDirs isn't on base NuxtOptions type */ + ...(nuxt.options.pinia?.storesDirs || []), + ]) { addImportsDir(resolver.resolve(nuxt.options.rootDir, storeDir)) } }