Skip to content

Conversation

rijkvanzanten
Copy link

@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

Summary by CodeRabbit

  • New Features

    • Auto-imports now include store directories from Nuxt layers in addition to the root app.
    • Playground adds a sample layer and a basic store to illustrate layered store usage.
    • Playground page updated to initialize and use the new store alongside existing ones.
  • Chores

    • Bumped @nuxt/kit dependency to a newer version.
    • Removed a resolution override for @nuxt/kit.

Copy link

netlify bot commented Sep 7, 2025

Deploy Preview for pinia-official canceled.

Name Link
🔨 Latest commit 7a57a89
🔍 Latest deploy log https://app.netlify.com/projects/pinia-official/deploys/68bd87cc6e3c34000829671c

Copy link

coderabbitai bot commented Sep 7, 2025

Walkthrough

Updates module to auto-import stores from Nuxt layers by using getLayerDirectories; bumps @nuxt/kit dependency; removes root resolution entry; adds a playground layer with a basic Pinia store and references it in the playground index page.

Changes

Cohort / File(s) Summary
Dependencies
package.json, packages/nuxt/package.json
Removed resolutions entry for @nuxt/kit in root package.json; bumped @nuxt/kit from ^3.9.0 to ^3.19.1 in packages/nuxt/package.json.
Module: layer store auto-imports
packages/nuxt/src/module.ts
Import getLayerDirectories and extend auto-import logic to call addImportsDir(resolve(layer.app, storeDir)) for each layer when options.storesDirs is provided.
Playground: layer scaffolding
packages/nuxt/playground/layers/layer-domain/nuxt.config.ts, packages/nuxt/playground/layers/layer-domain/stores/basic.ts
Add empty nuxt.config.ts for the layer and add a Pinia store useBasicStore with a count ref.
Playground: usage
packages/nuxt/playground/pages/index.vue
Add useBasicStore() initialization and inline source-file comments for store imports; retain existing page logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Nuxt as Nuxt Core
  participant Mod as Module (packages/nuxt/src/module.ts)
  participant Kit as @nuxt/kit
  participant FS as File System

  Dev->>Nuxt: start dev/build
  Nuxt->>Mod: initialize module
  Mod->>Kit: getLayerDirectories(nuxt)
  Kit-->>Mod: [layers...]
  alt options.storesDirs present
    loop each storesDir
      Mod->>FS: addImportsDir(resolve(root.app, storesDir))
      loop each layer
        Mod->>FS: addImportsDir(resolve(layer.app, storesDir)) Note right of Mod: new: include layer store dirs
      end
    end
  end
  FS-->>Nuxt: auto-import metadata (root + layers)
  Nuxt-->>Dev: stores auto-imported (e.g., useBasicStore)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Auto-import Pinia stores from Nuxt layers in main app (#3028)

Poem

I hopped through layers, sniffed each door,
Found tiny stores tucked in the floor.
With whiskered code and nimble foot,
I stitched their paths into the root.
Now every store greets me—what a score! 🐇✨

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

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

📒 Files selected for processing (1)
  • packages/nuxt/src/module.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nuxt/src/module.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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.

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.07%. Comparing base (57bec95) to head (7a57a89).

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.33%   91.07%   -0.27%     
==========================================
  Files          17       17              
  Lines        1397     1400       +3     
  Branches      211      212       +1     
==========================================
- Hits         1276     1275       -1     
- Misses        120      124       +4     
  Partials        1        1              

☔ 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
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

@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.

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: 7a57a89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stores from layers are not auto-imported in main app
1 participant