77 isNuxt2 ,
88 addImports ,
99 createResolver ,
10- resolveModule ,
10+ resolvePath ,
1111 addImportsDir ,
1212} from '@nuxt/kit'
1313import type { NuxtModule } from '@nuxt/schema'
@@ -43,7 +43,7 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
4343 defaults : {
4444 disableVuex : true ,
4545 } ,
46- setup ( options , nuxt ) {
46+ async setup ( options , nuxt ) {
4747 const resolver = createResolver ( import . meta. url )
4848
4949 // Disable default Vuex store (Nuxt v2.10+ only)
@@ -61,12 +61,9 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
6161 nuxt . options . build . transpile . push ( resolver . resolve ( './runtime' ) )
6262
6363 // Make sure we use the mjs build for pinia
64- nuxt . options . alias . pinia =
65- nuxt . options . alias . pinia ||
66- // FIXME: remove this deprecated call. Ensure it works in Nuxt 2 to 3
67- resolveModule ( 'pinia/dist/pinia.mjs' , {
68- paths : [ nuxt . options . rootDir , import . meta. url ] ,
69- } )
64+ if ( ! nuxt . options . alias . pinia ) {
65+ nuxt . options . alias . pinia = await resolvePath ( 'pinia/dist/pinia.mjs' )
66+ }
7067
7168 nuxt . hook ( 'prepare:types' , ( { references } ) => {
7269 references . push ( { types : '@pinia/nuxt' } )
@@ -97,7 +94,11 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
9794 }
9895
9996 if ( options . storesDirs ) {
100- for ( const storeDir of options . storesDirs ) {
97+ for ( const storeDir of [
98+ ...options . storesDirs ,
99+ /* @ts -expect-error storesDirs isn't on base NuxtOptions type */
100+ ...( nuxt . options . pinia ?. storesDirs || [ ] ) ,
101+ ] ) {
101102 addImportsDir ( resolver . resolve ( nuxt . options . rootDir , storeDir ) )
102103 }
103104 }
0 commit comments