Skip to content

Conversation

@feige996
Copy link

@feige996 feige996 commented Nov 6, 2025

本次提交不仅支持普通的exclude过滤,还支持!排除项,使用示例如下:(测试用例通过)

exclude: [
    'pages*/**/components/**/*.*', // 排除所有pages 里面的 components 文件夹
    '!pages-sub2/**/components/**/*.*', // 不排除 pages-sub2/**/components
],

Summary by CodeRabbit

  • New Features

    • File pattern exclusion now supports negation patterns (prefixed with !) to selectively re-include previously excluded files.
  • Tests

    • Added comprehensive test coverage for file discovery with multiple exclusion pattern configurations.
  • Chores

    • Added playground component fixtures across multiple directory structures for testing purposes.

feige996 added 5 commits November 5, 2025 18:33
分离排除规则中的否定模式(以!开头的规则),先使用肯定模式过滤文件,再单独处理否定模式将应包含的文件添加回结果集,确保文件筛选逻辑正确
添加三个测试用例,分别测试:
1. 排除所有 pages 下的 components 目录
2. 排除 pages 下的 components 目录但保留 pages-sub2 下的 components
3. 基本文件获取功能
在 vite.config.ts 中添加 exclude 配置,用于排除 pages 目录下的 components 文件夹,同时保留 pages-sub2 中的 components 文件
@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

The PR modifies getPageFiles to support negation patterns (prefixed with !) in exclude rules, enabling selective re-inclusion of files. The control flow changes from a single glob operation to a two-step process: initial collection with positive patterns, then merging files matching negated patterns. Configuration and comprehensive tests are added to validate the behavior across multiple exclude scenarios.

Changes

Cohort / File(s) Summary
Core exclude pattern handling
packages/core/src/files.ts
Refactored getPageFiles to split exclude patterns into positive and negative (negation) patterns. New logic collects files with positive filters first, then gathers and merges files matching negated patterns (deduplicated). Public API unchanged; internal control flow modified to support ! prefixed patterns.
Plugin configuration
packages/playground/vite.config.ts
Added exclude array to UniPages plugin config with two patterns: blanket exclude for all pages*/**/components/**/*.* and negation pattern !pages-sub2/**/components/**/*.* to re-include components in pages-sub2.
Playground test components (root pages)
packages/playground/src/pages/blog/components/comp.vue, packages/playground/src/pages/blog/components/dir/nest-comp.vue, packages/playground/src/pages/components/comp.vue, packages/playground/src/pages/components/dir/nest-comp.vue
Added minimal static Vue SFCs with template-only rendering (no script/styles). Used to validate exclude behavior against root pages directory.
Playground test components (pages-sub)
packages/playground/src/pages-sub/about/components/comp.vue, packages/playground/src/pages-sub/about/components/dir/nest-comp.vue, packages/playground/src/pages-sub/components/comp.vue, packages/playground/src/pages-sub/components/dir/nest-comp.vue
Added template-only Vue SFCs across nested directory structures. Test subject for exclude rules applied to pages-sub path.
Playground test components (pages-sub2)
packages/playground/src/pages-sub2/about/components/comp.vue, packages/playground/src/pages-sub2/about/components/dir/nest-comp.vue, packages/playground/src/pages-sub2/components/comp.vue, packages/playground/src/pages-sub2/components/dir/nest-comp.vue, packages/playground/src/pages-sub2/about/index.vue, packages/playground/src/pages-sub2/about/your.vue, packages/playground/src/pages-sub2/index.vue
Added new page structure and nested components for pages-sub2. Validates negation pattern re-inclusion behavior. Pages-sub2 index.vue implements Uni-app navigation with title state and button trigger; about pages render static content.
Comprehensive test suite reorganization
test/files.spec.ts
Restructured from single test to three parameterized suites (pages, pages2, pages3) testing different exclude configurations. Changed discovery root from packages/playground/src/pages to packages/playground/src. Added options2 (blanket exclude) and options3 (exclude with negation). Replaced single snapshot with three distinct snapshots reflecting expanded file structure across all page subdirectories.

Sequence Diagram

sequenceDiagram
    participant caller as Caller
    participant glob as Glob Engine
    participant merge as Dedup Merge
    
    rect rgb(220, 240, 255)
    Note over caller,glob: Old Flow (Single Glob)
    caller->>glob: glob(pattern, {ignore: excludePatterns})
    glob->>caller: files (excludes applied uniformly)
    end
    
    rect rgb(240, 255, 220)
    Note over caller,merge: New Flow (Two-Step with Negation)
    caller->>glob: Split excludes into positive & negative
    caller->>glob: glob(pattern, {ignore: positivePatterns})
    glob->>caller: result1 (initial files)
    
    alt if negativePatterns exist
        caller->>glob: glob(negativePatterns)
        glob->>caller: result2 (re-include candidates)
        caller->>merge: merge(result1, result2)
        merge->>caller: final (deduplicated)
    else
        caller->>caller: return result1
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Core logic in files.ts requires careful review of the two-step glob + merge pattern, negation pattern splitting, and deduplication logic
  • Test reorganization involves three distinct exclude scenarios with separate snapshots; verify each snapshot correctly reflects expected behavior under its respective configuration
  • Multiple playground components are simple/trivial additions but collectively represent the test fixture structure; verify directory hierarchy aligns with intended test coverage

Possibly related issues

Suggested labels

size/XXL

Poem

🐰 Negation patterns dance with glee,
Files once lost now wild and free!
The glob engine splits and spans,
Two steps now, not one— new plans!
Inclusion bells ring out so bright, 🔔
When ! patterns set things right!

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title in Chinese describes fixing issues with exclude configuration (not working and not robust enough), which directly aligns with the PR's main objective of adding support for standard and negated exclude patterns.
✨ 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 (7)
packages/playground/src/pages-sub2/about/your.vue (1)

1-7: LGTM! Test fixture is appropriate.

This minimal Vue component serves its purpose as a test fixture to validate the negated exclude pattern functionality introduced in this PR.

Optional refinement: The empty <script> block on line 1 could be removed entirely or replaced with <script setup> if future logic is needed, but for a test fixture this is perfectly fine as-is.

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

20-23: Exclude/negation config looks correct; confirm cwd and document behavior.

  • Patterns assume cwd is the project src root used by file discovery. Please verify the plugin scans with cwd='packages/playground/src' so these patterns match as intended.
  • Suggest adding a brief README note: exclude supports negation ('!') and later entries can re-include earlier exclusions; order matters.
packages/core/src/files.ts (2)

16-20: Clarify naming and intent of pattern groups.

positivePatterns actually hold the “exclude” rules (non-! entries), and negativePatterns are the “re-include” rules. Consider renaming to excludePatterns and reincludePatterns, and adjust comments accordingly for future maintainability.


12-13: Defensive default for exclude.

If ResolvedOptions.exclude can be undefined, default it to [] to avoid surprises.

-  const { exclude } = options
+  const { exclude = [] } = options
test/files.spec.ts (3)

9-9: Remove unnecessary async keyword.

The test function is marked async but contains no await statements or promise handling.

Apply this diff:

-  it('pages', async () => {
+  it('pages', () => {

65-65: Remove unnecessary async keyword.

The test function is marked async but contains no await statements or promise handling.

Apply this diff:

-  it('pages2', async () => {
+  it('pages2', () => {

115-115: Remove unnecessary async keyword.

The test function is marked async but contains no await statements or promise handling.

Apply this diff:

-  it('pages3', async () => {
+  it('pages3', () => {
📜 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 ee07859.

📒 Files selected for processing (18)
  • packages/core/src/files.ts (1 hunks)
  • packages/playground/src/pages-sub/about/components/comp.vue (1 hunks)
  • packages/playground/src/pages-sub/about/components/dir/nest-comp.vue (1 hunks)
  • packages/playground/src/pages-sub/components/comp.vue (1 hunks)
  • packages/playground/src/pages-sub/components/dir/nest-comp.vue (1 hunks)
  • packages/playground/src/pages-sub2/about/components/comp.vue (1 hunks)
  • packages/playground/src/pages-sub2/about/components/dir/nest-comp.vue (1 hunks)
  • packages/playground/src/pages-sub2/about/index.vue (1 hunks)
  • packages/playground/src/pages-sub2/about/your.vue (1 hunks)
  • packages/playground/src/pages-sub2/components/comp.vue (1 hunks)
  • packages/playground/src/pages-sub2/components/dir/nest-comp.vue (1 hunks)
  • packages/playground/src/pages-sub2/index.vue (1 hunks)
  • packages/playground/src/pages/blog/components/comp.vue (1 hunks)
  • packages/playground/src/pages/blog/components/dir/nest-comp.vue (1 hunks)
  • packages/playground/src/pages/components/comp.vue (1 hunks)
  • packages/playground/src/pages/components/dir/nest-comp.vue (1 hunks)
  • packages/playground/vite.config.ts (1 hunks)
  • test/files.spec.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/pages-sub2/index.vue
🧬 Code graph analysis (1)
test/files.spec.ts (2)
packages/core/src/options.ts (1)
  • resolveOptions (9-65)
packages/core/src/files.ts (1)
  • getPageFiles (11-42)
🔇 Additional comments (18)
packages/playground/src/pages-sub/about/components/dir/nest-comp.vue (1)

1-5: LGTM: template-only stub is fine for playground tests.

packages/playground/src/pages-sub2/about/index.vue (1)

1-7: LGTM: minimal page stub fits the test scaffolding.

packages/playground/src/pages/components/dir/nest-comp.vue (1)

1-5: LGTM: static SFC for exclude-rule coverage.

packages/playground/src/pages/blog/components/dir/nest-comp.vue (1)

1-5: LGTM: consistent with other playground stubs.

packages/playground/src/pages/components/comp.vue (1)

1-5: LGTM.

packages/playground/src/pages-sub/components/comp.vue (1)

1-5: LGTM: suitable for exclude/negation test matrix.

packages/playground/src/pages-sub2/about/components/dir/nest-comp.vue (1)

1-5: LGTM: aligns with the “!pages-sub2//components//.” negation case.

packages/playground/src/pages-sub/about/components/comp.vue (1)

1-5: LGTM.

packages/playground/src/pages-sub2/about/components/comp.vue (1)

1-5: LGTM for fixture SFC.

Minimal template is fine for the playground fixture.

packages/playground/src/pages/blog/components/comp.vue (1)

1-5: LGTM for fixture SFC.

Good as a discovery target in tests.

packages/playground/src/pages-sub2/components/dir/nest-comp.vue (1)

1-5: LGTM for fixture SFC.

No issues.

packages/playground/src/pages-sub/components/dir/nest-comp.vue (1)

1-5: LGTM for fixture SFC.

Works for discovery tests.

packages/playground/src/pages-sub2/components/comp.vue (1)

1-5: LGTM for fixture SFC.

Consistent with the other test components.

packages/playground/src/pages-sub2/index.vue (1)

1-60: LGTM for playground page.

Simple nav and route meta are fine for the fixture.

test/files.spec.ts (4)

5-8: LGTM! Test scope broadened to validate cross-directory exclusion.

The change from packages/playground/src/pages to packages/playground/src enables testing the negation pattern feature across multiple page directories (pages, pages-sub, pages-sub2, etc.), which is essential for validating the PR's objectives.


9-59: Comprehensive baseline test validates default behavior.

The snapshot correctly captures all files including component files from all directories when no custom exclude patterns are applied. This serves as an effective baseline for comparing the filtered results in subsequent tests.


61-103: Test correctly validates blanket component exclusion.

The snapshot accurately reflects the behavior of the pages*/**/components/**/*.* pattern: all component files within pages, pages-sub, pages-sub2, and pages-blog directories are excluded, while components/Counter.vue (which doesn't match the pages* prefix) is correctly retained.


105-157: Excellent test coverage for the negation pattern feature!

This test validates the core functionality of the PR: the negation pattern !pages-sub2/**/components/**/*.* correctly overrides the broader exclusion pages*/**/components/**/*.*, selectively re-including only the pages-sub2 component files while keeping other component directories excluded. The snapshot accurately reflects this behavior.

Comment on lines +31 to +39
const includedFiles = fg.sync(negativePatterns.map(pattern => `${pattern}`), {
onlyFiles: true,
cwd: path,
})

// 将应该包含的文件添加回结果集,确保不重复
const filesSet = new Set([...files, ...includedFiles])
files = Array.from(filesSet)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: re-included files are not filtered by allowed extensions.

negativePatterns are globbed without extension filtering, so non-page files (e.g., images, JSON) can leak into results. Filter by FILE_EXTENSIONS before merging and ensure deterministic ordering.

Apply this patch:

-    const includedFiles = fg.sync(negativePatterns.map(pattern => `${pattern}`), {
-      onlyFiles: true,
-      cwd: path,
-    })
-
-    // 将应该包含的文件添加回结果集,确保不重复
-    const filesSet = new Set([...files, ...includedFiles])
-    files = Array.from(filesSet)
+    const includedFiles = fg.sync(negativePatterns, {
+      onlyFiles: true,
+      cwd: path,
+    })
+    // 仅保留受支持的页面后缀
+    const includedPageFiles = includedFiles.filter(f =>
+      FILE_EXTENSIONS.some(ext => f.endsWith(`.${ext}`)),
+    )
+    // 合并并保持结果稳定(去重 + 排序)
+    const filesSet = new Set([...files, ...includedPageFiles])
+    files = Array.from(filesSet).sort()

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/core/src/files.ts around lines 31 to 39, the code re-includes files
matched by negativePatterns without filtering by allowed FILE_EXTENSIONS and
without deterministic ordering; update the logic so includedFiles are filtered
to only keep files whose extensions are in the FILE_EXTENSIONS list (use the
file extension check, e.g., via path.extname and normalizing the extension)
before merging into filesSet, then produce the final files array by converting
filesSet to an array and sorting it (deterministic ordering) so duplicates are
removed, only allowed extensions are included, and ordering is stable.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant