-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(nuxt): resolve auto-imports in layers #3035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for pinia-official canceled.
|
WalkthroughAdds auto-import support for Pinia stores from Nuxt layers by discovering layer directories and registering each layer's stores directory; includes playground files and a test to validate that a layer store is auto-imported. Changes
Sequence Diagram(s)sequenceDiagram
participant Module as Nuxt Module
participant Kit as `@nuxt/kit`
participant Layers as Nuxt Layers
participant FS as Filesystem (layer.app + storesDir)
participant AutoImports as Auto-import registry
Module->>Kit: getLayerDirectories(nuxt)
Kit-->>Module: layers[]
loop for each storeDir in options.storesDirs
loop for each layer in layers
Module->>FS: resolve(layer.app + storeDir)
FS-->>Module: store files (if any)
Module->>AutoImports: addImportsDir(resolvedPath)
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v3 #3035 +/- ##
==========================================
- Coverage 91.51% 91.28% -0.24%
==========================================
Files 18 18
Lines 1615 1618 +3
Branches 230 231 +1
==========================================
- Hits 1478 1477 -1
- Misses 135 139 +4
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/nuxt/package.json (1)
45-46: Version bump to @nuxt/kit is fine; align related Nuxt deps to avoid drift.Kit ≥3.19 introduces getLayerDirectories; keeping Nuxt core/schema around 3.19.x avoids subtle type/runtime mismatches in modules and test-utils. (newreleases.io)
Apply:
"devDependencies": { "@nuxt/module-builder": "1.0.1", - "@nuxt/schema": "^3.9.0", - "@nuxt/test-utils": "^3.19.1", - "nuxt": "^3.17.5", + "@nuxt/schema": "^3.19.1", + "@nuxt/test-utils": "^3.19.1", + "nuxt": "^3.19.1", "pinia": "workspace:^", "typescript": "^5.8.3", "vue-tsc": "^2.2.10" },#!/bin/bash # Show Nuxt-related versions and ensure no root-level overrides remain. jq -r '.dependencies["@nuxt/kit"], .devDependencies["@nuxt/schema"], .devDependencies.nuxt, .devDependencies["@nuxt/test-utils"]' packages/nuxt/package.json jq -r '.resolutions?"@nuxt/kit"' package.json 2>/dev/null || echo "no root resolutions for @nuxt/kit"packages/nuxt/playground/pages/index.vue (1)
6-8: Use or remove unused store calls to avoid lints/tree-shaking surprises.Either assign them or comment them out.
-useTestStore() // ~/domain/one/stores/testStore.ts -useSomeStoreStore() // ~/stores/nested/some-stores.ts -useBasicStore() // ~~/layers/layer-domain/stores/basic.ts +// const test = useTestStore() // ~/domain/one/stores/testStore.ts +// const some = useSomeStoreStore() // ~/stores/nested/some-stores.ts +// const basic = useBasicStore() // ~~/layers/layer-domain/stores/basic.ts
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
package.json(0 hunks)packages/nuxt/package.json(1 hunks)packages/nuxt/playground/layers/layer-domain/nuxt.config.ts(1 hunks)packages/nuxt/playground/layers/layer-domain/stores/basic.ts(1 hunks)packages/nuxt/playground/pages/index.vue(1 hunks)packages/nuxt/src/module.ts(2 hunks)
💤 Files with no reviewable changes (1)
- package.json
🔇 Additional comments (3)
packages/nuxt/playground/layers/layer-domain/nuxt.config.ts (1)
1-1: LGTM; ensure the layer is actually extended by the playground app.Add this layer to playground/nuxt.config.{ts,js} via extends so the demo exercises the new behavior.
#!/bin/bash rg -nP --glob 'packages/nuxt/playground/nuxt.config.*' -C2 '(?<=extends:\s)(\[|\')' sed -n '1,120p' packages/nuxt/playground/nuxt.config.ts 2>/dev/null || truepackages/nuxt/src/module.ts (1)
10-11: Importing getLayerDirectories is correct for this use.API exists in Nuxt Kit ≥3.19 and exposes layer.app/root for path composition. (dev.nuxt.com, newreleases.io)
packages/nuxt/playground/layers/layer-domain/stores/basic.ts (1)
1-5: LGTM.Simple store suffices to validate auto-import resolution across layers.
commit: |
|
@posva it would be awesome if we could merge this one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test? A simple one like at #2757 is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nuxt/playground/layers/layer-domain/stores/basic.ts (1)
1-5: Consider adding explicit imports for better IDE support.While Nuxt auto-imports
defineStoreandref, adding explicit imports improves IDE type inference, code portability, and makes dependencies clearer.Apply this diff to add explicit imports:
+import { defineStore } from 'pinia' +import { ref } from 'vue' + export const useBasicStore = defineStore('layer-basic', () => { const count = ref(0) return { count } })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
package.json(0 hunks)packages/nuxt/playground/layers/layer-domain/nuxt.config.ts(1 hunks)packages/nuxt/playground/layers/layer-domain/stores/basic.ts(1 hunks)packages/nuxt/playground/pages/index.vue(1 hunks)packages/nuxt/src/module.ts(2 hunks)
💤 Files with no reviewable changes (1)
- package.json
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/nuxt/src/module.ts
- packages/nuxt/playground/layers/layer-domain/nuxt.config.ts
🔇 Additional comments (1)
packages/nuxt/playground/pages/index.vue (1)
6-8: LGTM! Layer store auto-import test looks good.The addition of
useBasicStore()effectively demonstrates that stores from Nuxt layers are now auto-imported alongside stores from the main app and nested directories. The consistent pattern with inline comments documenting source paths is helpful for understanding the test coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nuxt/test/nuxt.spec.ts (1)
37-39: Good addition: validates layer store auto-import.The test correctly validates that stores from Nuxt layers are auto-imported and accessible. It confirms the fix for issue #3028 by asserting the layer store's initial state is rendered.
Consider enhancing test coverage with additional scenarios:
- Store functionality (mutations/actions) to ensure the store is fully operational, not just imported
- Multiple layers to validate the discovery mechanism works across multiple layer directories
- Nested/extended layers to ensure transitive layer dependencies are handled
Example of testing store functionality:
it('can auto import and use layer store', async () => { const html = await $fetch('/') expect(html).toContain('Layer store: 0') // Could add a test page that increments the store and validates state changes })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/nuxt/playground/pages/index.vue(2 hunks)packages/nuxt/test/nuxt.spec.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/nuxt/playground/pages/index.vue
|
Thank you for adding the test and getting this over the finish line @posva 🫶 |
|
hello @rijkvanzanten @posva , first of all thanks a lot for merging this PR 👏 - i would like to confirm if recent releases resolved the autoimport issues
as when i try bump to these versions,
as what i mentioned in #3028, here are the fresh repo to test links: |

What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
fix #xxx[,#xxx], where "xxx" is the issue number)Other information:
getLayerDirectoriesso quickly@nuxt/kitwas globally overridden in the monorepo workspace package.json. I'm not entirely sure why that was there in the first place, so that needs some extra review caution 🙏🏻Fixes #3028
Closes #2757
Closes #2828
Summary by CodeRabbit
New Features
Chores