Skip to content

Conversation

@fernando-aviles
Copy link
Contributor

@fernando-aviles fernando-aviles commented Jan 7, 2026

Greptile Summary

This PR fixes handling of [locale] placeholders in glob patterns when used with globstar patterns like **/[locale].mdx. The previous implementation failed when the globstar matched intermediate directories because it compared path segments one-to-one, causing a mismatch in segment counts.

The fix introduces a new buildPlaceholderPathFromPattern function that:

  • Uses micromatch to generate a regex from the pattern
  • Leverages the RegExp indices API (ES2022 d flag) to locate where locale values appear in matched paths
  • Replaces locale values back to [locale] placeholders at the correct positions

Changes include:

  • Refactored locale replacement logic to use regex matching with capture group indices
  • Added test case validating [locale] in filename after globstar pattern
  • Added helper functions buildPlaceholderPathFromPattern, toPosixPath, and escapeRegex (unused)

Confidence Score: 4/5

  • This PR is safe to merge with only minor cleanup needed
  • The implementation correctly fixes the globstar pattern issue using a robust regex-based approach with the modern indices API. Test coverage validates the fix. Only minor issue is the unused escapeRegex function that should be removed.
  • No files require special attention beyond removing the unused escapeRegex function

Important Files Changed

Filename Overview
packages/cli/src/fs/config/parseFilesConfig.ts Refactored locale placeholder replacement to use micromatch-based regex matching with indices API; includes unused escapeRegex function

Sequence Diagram

sequenceDiagram
    participant Client as expandGlobPatterns
    participant FG as fast-glob
    participant Build as buildPlaceholderPathFromPattern
    participant MM as micromatch
    participant RE as RegExp (with indices)

    Client->>Client: Replace [locale] with actual locale in pattern
    Client->>FG: sync(absolutePattern, options)
    FG-->>Client: Return matched file paths
    
    loop For each matched path
        Client->>Build: buildPlaceholderPathFromPattern(patternPath, absolutePath, "[locale]")
        Build->>Build: Convert paths to POSIX format
        Build->>MM: makeRe(posixPattern, {literalBrackets: true})
        MM-->>Build: Return base regex
        Build->>Build: Replace \\[locale\\] with ([^/]+) capture group
        Build->>RE: Create RegExp with 'd' flag for indices
        Build->>RE: exec(posixPath)
        RE-->>Build: Return match with indices array
        
        alt Match found with indices
            Build->>Build: Iterate indices in reverse order
            Build->>Build: Replace captured locale with [locale] tag
            Build->>Build: Normalize path back to OS format
            Build-->>Client: Return placeholder path
        else No match or no indices
            Build-->>Client: Return original absolute path
        end
        
        Client->>Client: Add to placeholderPaths array
    end
    
    Client-->>Client: Return {resolvedPaths, placeholderPaths}
Loading

@fernando-aviles fernando-aviles requested a review from a team as a code owner January 7, 2026 20:48
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@fernando-aviles fernando-aviles merged commit a9aae8c into main Jan 7, 2026
20 checks passed
@fernando-aviles fernando-aviles deleted the f/fix-locale-segment branch January 7, 2026 21:30
@github-actions github-actions bot mentioned this pull request Jan 7, 2026
brian-lou pushed a commit that referenced this pull request Jan 7, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## [email protected]

### Patch Changes

- [#933](#933)
[`a9aae8c`](a9aae8c)
Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Fixing
handling of [locale] placeholder in blob patterns

## [email protected]

### Patch Changes

- Updated dependencies
\[[`a9aae8c`](a9aae8c)]:
    -   [email protected]

<!-- greptile_comment -->

<h3>Greptile Summary</h3>


Automated Changesets release PR that publishes `[email protected]` and
`[email protected]` to npm.

- **gtx-cli v2.5.43**: Patch release containing the fix for `[locale]`
placeholder handling in glob patterns (from PR #933)
- **locadex v1.0.71**: Dependency update release tracking the new
gtx-cli version
- Standard release automation: changeset consumed, changelogs updated,
versions bumped

<details open><summary><h3>Confidence Score: 5/5</h3></summary>


- Standard automated release PR with no code changes - safe to merge
- This is an automated Changesets release PR containing only version
bumps and changelog updates. All actual code changes were reviewed and
merged in PR #933. No manual modifications or code logic to review.
- No files require special attention
</details>


<details><summary><h3>Important Files Changed</h3></summary>




| Filename | Overview |
|----------|----------|
| .changeset/six-plants-relax.md | Standard changeset file deletion -
consumed by Changesets release action to generate changelog entries |
| packages/cli/CHANGELOG.md | Auto-generated changelog entry for gtx-cli
v2.5.43, documenting the locale placeholder fix from PR #933 |
| packages/cli/package.json | Version bump from 2.5.42 to 2.5.43 for
gtx-cli package |
| packages/locadex/CHANGELOG.md | Auto-generated changelog entry for
locadex v1.0.71, noting dependency update to [email protected] |
| packages/locadex/package.json | Version bump from 1.0.70 to 1.0.71 for
locadex package (dependency update release) |

</details>


</details>


<details><summary><h3>Sequence Diagram</h3></summary>

```mermaid
sequenceDiagram
    participant Dev as Developer
    participant GH as GitHub
    participant CS as Changesets Action
    participant NPM as npm Registry

    Dev->>GH: Merge PR #933 (locale fix) with changeset
    GH->>CS: Trigger Changesets release action
    CS->>CS: Detect pending changeset
    CS->>GH: Open release PR #935
    Note over CS,GH: - Delete changeset file<br/>- Update CHANGELOGs<br/>- Bump versions
    Dev->>GH: Review and merge PR #935
    GH->>CS: Trigger publish workflow
    CS->>NPM: Publish [email protected]
    CS->>NPM: Publish [email protected]
```
</details>


<!-- greptile_other_comments_section -->

<!-- /greptile_comment -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants