Skip to content

Conversation

@rijkvanzanten
Copy link
Contributor

@rijkvanzanten rijkvanzanten commented Sep 7, 2025

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • All tests are passing
  • New/updated tests are included

Other information:

  • This is a continuation of Auto Register stores dir in all layers #2757 and feat(nuxt): supports automatic import of stores from extend layers #2828 which can be resolved after this.
  • Special thanks to @danielroe for implementing and shipping support for getLayerDirectories so quickly
  • @posva couple of quick things:
    • I noticed the Nuxt dependencies are currently on v3. Lemme know if you'd like me to fly in a PR to upgrade those to v4 :)
    • I saw that @nuxt/kit was 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 🙏🏻
    • I didn't spot any existing test suites for the Nuxt package, so just another layer to the playground as a way to manually test.

Fixes #3028
Closes #2757
Closes #2828

Summary by CodeRabbit

  • New Features

    • Support for organizing Pinia stores within application layers.
    • UI now displays the layer store count on the homepage.
  • Chores

    • Module updated to automatically discover and import stores from layer directories, improving modular app structure.

@netlify
Copy link

netlify bot commented Sep 7, 2025

Deploy Preview for pinia-official canceled.

Name Link
🔨 Latest commit 996979b
🔍 Latest deploy log https://app.netlify.com/projects/pinia-official/deploys/6909d3e85c049a0008b29996

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Package manifest
package.json
Removed resolutions entry for @nuxt/kit: ^3.9.0; @nuxt/schema: ^3.9.0 unchanged
Module logic
packages/nuxt/src/module.ts
Import getLayerDirectories and iterate Nuxt layers to register each layer's app + stores directory when options.storesDirs is provided
Playground: layer and store
packages/nuxt/playground/layers/layer-domain/nuxt.config.ts, packages/nuxt/playground/layers/layer-domain/stores/basic.ts
Added empty defineNuxtConfig({}) and new Pinia store useBasicStore with count state
Playground: page & test
packages/nuxt/playground/pages/index.vue, packages/nuxt/test/nuxt.spec.ts
Page updated to use useBasicStore() and render its count; test added asserting "Layer store: 0" on GET /

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to inspect:
    • Path resolution correctness for layer.app + storeDir (edge cases, trailing slashes)
    • Proper handling when options.storesDirs is undefined or empty
    • Test robustness and that the playground store import path matches resolution logic

Poem

🐰 I hop through layers, soft and fleet,
Finding stores with tiny feet.
A count of zero, tidy and bright—
Auto-imports stitched just right.
I nibble bugs and dance in light. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(nuxt): resolve auto-imports in layers' accurately describes the main change: implementing auto-import resolution for Pinia stores in Nuxt layers.
Linked Issues check ✅ Passed The PR implements all coding objectives from linked issues: adds getLayerDirectories import, iterates through layers for store directory resolution, creates layer playground structure with store, and adds test case verifying layer store auto-import.
Out of Scope Changes check ✅ Passed Changes are focused on layer auto-import support. Removal of @nuxt/kit resolution from package.json and playground setup are scope-appropriate for implementing and testing the feature.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 7, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.28%. Comparing base (868f6b5) to head (996979b).
⚠️ Report is 1 commits behind head on v3.

Files with missing lines Patch % Lines
packages/nuxt/src/module.ts 50.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rijkvanzanten
Copy link
Contributor Author

rijkvanzanten commented Sep 7, 2025

Not entirely sure why the Publish Any Commit workflow is failing, but it feels unrelated to my changes? edit: this was a fluke. Ran just fine on a subsequent commit

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 57bec95 and de27eb1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is 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 || true
packages/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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@pinia/nuxt@3035
npm i https://pkg.pr.new/pinia@3035
npm i https://pkg.pr.new/@pinia/testing@3035

commit: 996979b

@ThomasRalee
Copy link

@posva it would be awesome if we could merge this one

Copy link
Member

@posva posva left a 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

@github-project-automation github-project-automation bot moved this to 🆕 Triaging in Pinia Roadmap Nov 1, 2025
@posva posva moved this from 🆕 Triaging to 🧑‍💻 In progress in Pinia Roadmap Nov 1, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 defineStore and ref, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a57a89 and 0827e11.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is 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.

@posva posva merged commit e25e525 into vuejs:v3 Nov 4, 2025
8 of 9 checks passed
@github-project-automation github-project-automation bot moved this from 🧑‍💻 In progress to ✅ Done in Pinia Roadmap Nov 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0827e11 and 996979b.

📒 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

@rijkvanzanten
Copy link
Contributor Author

Thank you for adding the test and getting this over the finish line @posva 🫶

@Frederick-88
Copy link

Frederick-88 commented Nov 5, 2025

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,
layer autoimport still not resolved + now my main repo store autoimport also affected

image

as what i mentioned in #3028, here are the fresh repo to test links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Stores from layers are not auto-imported in main app

4 participants