这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Jul 3, 2025

Description

This PR fixes an issue where glob patterns with leading ./ prefixes (like ./packages/*) were not being consistently handled in workspace filtering and glob matching throughout Turborepo.

Problem:

  • Workspace globs like ./packages/* and packages/* should be functionally equivalent
  • The current implementation didn't normalize these patterns, causing inconsistencies in package filtering
  • This led to scenarios where turbo run build --filter="./packages/*" might not match the same packages as turbo run build --filter="packages/*"

Solution:

  • Normalize leading ./ patterns in fix_glob_pattern: Strip the ./ prefix from glob patterns during normalization while preserving ../ patterns (which have different semantic meaning)
  • Enhanced filtering compatibility: Update the package filtering logic to handle both original and normalized patterns, ensuring compatibility with workspace globs that might have or lack the ./ prefix
  • Comprehensive test coverage: Add test cases to validate that ./packages/* and packages/* produce identical results

Key Changes:

  1. crates/turborepo-globwalk/src/lib.rs: Modified fix_glob_pattern() to normalize leading ./ patterns
  2. crates/turborepo-lib/src/run/scope/filter.rs: Enhanced filtering logic to try both original and normalized patterns
  3. crates/turborepo-repository/src/inference.rs: Fixed test assertions for repo state inference

Examples of patterns affected:

  • ./packages/*packages/*
  • ./packages/**packages/**
  • ../packages/*../packages/* (preserved - different semantic meaning)

This ensures consistent behavior across all workspace filtering operations and improves the developer experience by making glob patterns more predictable.

Testing Instructions

  1. Basic functionality test:

    # Both of these should now match identical packages
    turbo run build --filter="./packages/*"
    turbo run build --filter="packages/*"
  2. Run the test suite:

    cargo test test_fix_glob_pattern
    cargo test test_leading_dot_slash_pattern_normalization
  3. Test workspace filtering:

    # In a monorepo with packages in a `packages/` directory
    turbo run build --filter="./packages/*" --dry-run
    turbo run build --filter="packages/*" --dry-run
    # Output should be identical
  4. Verify edge cases:

    # Should preserve ../ patterns (different semantic meaning)
    turbo run build --filter="../packages/*" --dry-run

@anthonyshew anthonyshew requested a review from a team as a code owner July 3, 2025 02:40
@vercel
Copy link
Contributor

vercel bot commented Jul 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-designsystem-docs 🔄 Building (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-gatsby-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-kitchensink-blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-native-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-svelte-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-tailwind-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
examples-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2025 3:26am

@anthonyshew anthonyshew changed the title shew/7f34f fix: normalize package inference for filtering Jul 3, 2025
@anthonyshew anthonyshew linked an issue Jul 3, 2025 that may be closed by this pull request
1 task
Copy link
Contributor

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

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

The ./ is an explicit marker that the filter is targeting paths and not names. We document this: https://turborepo.com/docs/reference/run#--filter-string
I do not think we want to change this behavior as part of a fix.

"/repos/some-app/one/two/included.txt",
"/repos/some-app/one/two/three/included.txt",
], Default::default() ; "exclude nested single file")]
#[test_case(&[
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this test case removed?

let matches = parent_dir_matcher.is_match(info.package_path().as_path());

if matches {
// Also try normalized pattern for compatibility with workspace globs
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop all the changes in this file

@anthonyshew
Copy link
Contributor Author

This PR was part of an experiment I was doing to test how fast we could reliably go in the repo with LLMs. We've seen enough PRs we don't like come through that we think could be improved by first circling back to improve the health of the codebase. As a first step, we're going to be investing in test coverage.

Closing this PR with these interests in mind.

@anthonyshew anthonyshew closed this Jul 7, 2025
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.

Package scoping fails when workspace glob has leading ./

3 participants