Skip to content

feat: filter pages in mergePageMetaData to exclude sub-package pages #258#259

Merged
FliPPeDround merged 4 commits intouni-helper:mainfrom
hairyf:main
Nov 8, 2025
Merged

feat: filter pages in mergePageMetaData to exclude sub-package pages #258#259
FliPPeDround merged 4 commits intouni-helper:mainfrom
hairyf:main

Conversation

@hairyf
Copy link
Member

@hairyf hairyf commented Oct 31, 2025

Description 描述

close #258
close #189

Linked Issues 关联的 Issues

Additional context 额外上下文

Summary by CodeRabbit

  • New Features

    • Added an internal sub-package page and enabled navigation to it.
    • Added support for scanning sub-package pages during metadata generation.
  • Behavior Changes

    • Main site metadata now excludes sub-package pages so they are treated separately.
  • Tests

    • Updated tests and expectations to cover the new sub-package scanning and page inclusion.

@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

Walkthrough

Main change: sub-package pages are scanned and their absolute paths are removed from the main pages map before main page metadata is generated; playground is updated with a sub-package demo, config, and type entry.

Changes

Cohort / File(s) Summary
Core filtering logic
packages/core/src/context.ts
Adds logic in mergePageMetaData to collect absolute paths of sub-package pages and remove those entries from the main pages map before generating main page metadata.
PageContext API & flow
packages/core/src/...
PageContext now accepts subPackages in the constructor and adds scanSubPages() (called in tests) to scan sub-package pages prior to merging metadata.
Playground demo component
packages/playground/src/pages/pages-internal-sub/index.vue
New Vue SFC that renders a simple div "this is pages-internal-sub".
Playground types
packages/playground/src/uni-pages.d.ts
Adds the literal path "/pages/pages-internal-sub/index" to the _LocationUrl union type.
Playground plugin config
packages/playground/vite.config.ts
Adds 'src/pages/pages-internal-sub' to the UniPages plugin subPackages array.
Tests
test/files.spec.ts, test/generate.spec.ts
Updates snapshot in files.spec to include pages-internal-sub/index.vue; generate.spec.ts updated to instantiate PageContext with subPackages and call scanSubPages() before merge/resolve steps.

Sequence Diagram(s)

sequenceDiagram
  participant Test as Test
  participant PC as PageContext
  participant FS as FileSystem
  participant Merge as mergePageMetaData

  Note left of Test: Setup with subPackages
  Test->>PC: new PageContext({ dir, subPackages: [...] })
  Test->>PC: await PC.scanSubPages()
  PC->>FS: read sub-package page files
  FS-->>PC: return sub-page file list (absolute paths)
  PC->>Merge: prepare pages map (main + sub)
  Merge->>Merge: compute sub-package roots & remove sub-page paths from main pages map
  Merge->>Merge: parsePages on remaining main pages -> generate main metadata
  Merge-->>PC: merged metadata (excludes sub-package pages)
  Test->>PC: assertions (routes resolved)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the sub-package path root computation and filtering logic in packages/core/src/context.ts.
  • Verify scanSubPages() behavior and integration with existing PageContext lifecycle.
  • Ensure tests (test/generate.spec.ts) correctly reflect intended control flow and that playground config/type changes align.

Possibly related PRs

Suggested reviewers

  • KeJunMao

Poem

🐰 I hopped through pages, sniffed each trail,

Sub-packages tucked behind a veil,
Main paths kept tidy, neat and clear,
No stray routes hopping near,
A tiny hop — the structure cheers! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "feat: filter pages in mergePageMetaData to exclude sub-package pages #258" directly and specifically references the primary code change in the changeset: the addition of filtering logic in mergePageMetaData to exclude sub-package pages from the main pages map. The title is clear, concise, and accurately represents the core modification that addresses the issue. It appropriately references the issue number for additional context.
Linked Issues Check ✅ Passed Issue #258 reports that sub-package pages should be filtered and excluded from the generated pages list. The PR implements this requirement through the core change in packages/core/src/context.ts, where new logic collects absolute paths of all sub-package pages and removes them from the main pages map before generating metadata. Supporting changes include adding the scanSubPages method and subPackages option to PageContext, configuring the playground environment with a test sub-package, updating type definitions, and adding corresponding test coverage. All changes collectively enable and validate the filtering functionality described in the issue.
Out of Scope Changes Check ✅ Passed All changes in the PR are directly related to implementing the sub-package page filtering feature described in issue #258. The core logic change (mergePageMetaData filtering), supporting infrastructure (scanSubPages method, subPackages configuration option), test fixtures (new pages-internal-sub component), type definitions, build configuration updates, and test coverage updates all serve the single objective of excluding sub-package pages from main pages generation. No extraneous changes or unrelated modifications are present.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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.

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 (1)
packages/core/src/context.ts (1)

253-253: Hardcoded 'src/' prefix assumption may break with different directory structures.

The replacement logic assumes all sub-package paths start with 'src/', which may not hold for all project configurations.

Consider normalizing paths relative to a common base instead:

-    const subPages = [...this.subPages.keys()].map(v => v.replace('src/', ''))
+    const basePath = slash(path.join(this.options.root, this.options.outDir))
+    const subPages = [...this.subPages.keys()].map(v => 
+      slash(path.relative(basePath, path.join(this.options.root, v)))
+    )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88d4619 and 80658d1.

📒 Files selected for processing (4)
  • packages/core/src/context.ts (1 hunks)
  • packages/playground/src/pages/pages-internal-sub/index.vue (1 hunks)
  • packages/playground/src/uni-pages.d.ts (1 hunks)
  • packages/playground/vite.config.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-28T03:00:09.715Z
Learnt from: xiaohe0601
Repo: uni-helper/vite-plugin-uni-pages PR: 229
File: packages/core/client.d.ts:9-11
Timestamp: 2025-08-28T03:00:09.715Z
Learning: In uni-helper/vite-plugin-uni-pages, global type declarations like `definePage` are kept in a separate `client.d.ts` file and exposed via the `./client` export. Users need to manually add `uni-helper/vite-plugin-uni-pages/client` to their tsconfig.json to access these global declarations, which is documented as the intended usage pattern.

Applied to files:

  • packages/playground/vite.config.ts
  • packages/playground/src/uni-pages.d.ts
🧬 Code graph analysis (1)
packages/core/src/context.ts (1)
packages/core/src/page.ts (1)
  • Page (15-106)
🔇 Additional comments (3)
packages/playground/src/pages/pages-internal-sub/index.vue (1)

1-5: LGTM! Appropriate test case for sub-package filtering.

This simple Vue component effectively serves as a test case for the new sub-package filtering functionality.

packages/playground/vite.config.ts (1)

19-19: LGTM! Appropriate test configuration.

The addition of the new sub-package path correctly demonstrates the filtering functionality implemented in this PR.

packages/playground/src/uni-pages.d.ts (1)

26-27: Verify this generated file was properly regenerated.

This file is marked as auto-generated (line 4), so it should be regenerated by the plugin rather than manually edited. Please confirm that this change was produced by running the plugin's type generation.

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

🧹 Nitpick comments (1)
test/generate.spec.ts (1)

31-31: Remove commented debug code.

The commented console.log statement appears to be leftover debug code and should be removed to keep the test file clean.

Apply this diff:

-    // console.log(ctx.pages)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80658d1 and 35fa99f.

📒 Files selected for processing (3)
  • packages/core/src/context.ts (1 hunks)
  • test/files.spec.ts (1 hunks)
  • test/generate.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/context.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/generate.spec.ts (1)
packages/core/src/context.ts (1)
  • PageContext (31-503)
🔇 Additional comments (3)
test/files.spec.ts (1)

27-27: LGTM! Snapshot correctly reflects sub-package page discovery.

The addition of "pages-internal-sub/index.vue" to the snapshot is correct. The getPageFiles function scans the pages directory and discovers all page files, including those in sub-package directories. The filtering of sub-package pages from the main pages list occurs later in mergePageMetaData.

test/generate.spec.ts (2)

26-28: LGTM! Correct test setup for sub-package filtering.

The addition of subPackages configuration and the scanSubPages() call correctly set up the test to verify that sub-package pages are filtered from the main pages list. The test flow matches the implementation: scanPages()scanSubPages()mergePageMetaData(), where mergePageMetaData() removes sub-package page paths from the main pages map.


179-182: LGTM! Consistent test setup for the non-merge-pages scenario.

The changes mirror the first test and correctly configure sub-package scanning for the scenario where mergePages is false. This ensures sub-package filtering works correctly in both code paths.

@skiyee
Copy link
Member

skiyee commented Nov 5, 2025

#189 应该是同一个类型的issue,也可以关闭

@FliPPeDround FliPPeDround merged commit de38e00 into uni-helper:main Nov 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants