Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
]
},
"resolutions": {
"@nuxt/kit": "^3.9.0",
"@nuxt/schema": "^3.9.0"
},
"pnpm": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default defineNuxtConfig({})
5 changes: 5 additions & 0 deletions packages/nuxt/playground/layers/layer-domain/stores/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const useBasicStore = defineStore('layer-basic', () => {
const count = ref(0)

return { count }
})
7 changes: 5 additions & 2 deletions packages/nuxt/playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

const counter = useCounter()

useTestStore()
useSomeStoreStore()
useTestStore() // ~/domain/one/stores/testStore.ts
useSomeStoreStore() // ~/stores/nested/some-stores.ts
const layerStore = useBasicStore() // ~~/layers/layer-domain/stores/basic.ts

// await useAsyncData('counter', () => counter.asyncIncrement().then(() => true))

Expand All @@ -17,5 +18,7 @@ if (import.meta.server) {
<div>
<p>Count: {{ counter.$state.count }}</p>
<button @click="counter.increment()">+</button>

<p>Layer store: {{ layerStore.count }}</p>
</div>
</template>
7 changes: 6 additions & 1 deletion packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
addImports,
createResolver,
addImportsDir,
getLayerDirectories,
} from '@nuxt/kit'
import type { NuxtModule } from '@nuxt/schema'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -73,8 +74,12 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
}

if (options.storesDirs) {
const layers = getLayerDirectories(nuxt)

for (const storeDir of options.storesDirs) {
addImportsDir(resolve(nuxt.options.rootDir, storeDir))
for (const layer of layers) {
addImportsDir(resolve(layer.app, storeDir))
}
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions packages/nuxt/test/nuxt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ describe('Nuxt', async () => {
expect(html).not.toContain('I should not be serialized or hydrated')
expect(html).toContain('skipHydrate-wrapped state is correct')
})

it('can auto import from layers', async () => {
expect(await $fetch('/')).toContain('Layer store: 0')
})
})
37 changes: 32 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading