Skip to content

feat: add glob pattern support to copyFiles option#346

Open
sleicht wants to merge 1 commit intoaku11i:mainfrom
sleicht:feature/add-glob-pattern-support-copyfiles
Open

feat: add glob pattern support to copyFiles option#346
sleicht wants to merge 1 commit intoaku11i:mainfrom
sleicht:feature/add-glob-pattern-support-copyfiles

Conversation

@sleicht
Copy link

@sleicht sleicht commented Jan 12, 2026

Closes #345

Summary

Adds glob pattern support to the postCreate.copyFiles configuration option, allowing users to match multiple files with a single pattern instead of listing each file individually.

This enhancement significantly improves the developer experience by enabling flexible file matching whilst maintaining full backward compatibility with exact file paths.

Changes

  • ✅ Created glob-resolver module with pattern detection and expansion
  • ✅ Implements custom **/ pattern matcher for dotfiles (works around Node.js limitation)
  • ✅ Automatically excludes .git directory from recursive searches
  • ✅ Smart handling of literal filenames containing glob metacharacters
  • ✅ Integrated glob resolution into file-copier workflow
  • ✅ Added comprehensive test coverage (22 glob resolver tests, 12 integration tests)
  • ✅ Updated documentation with glob syntax reference and examples
  • ✅ Maintained full backward compatibility with exact file paths

Examples

Before:

{
  "postCreate": {
    "copyFiles": [".env", ".env.local", ".env.development", ".env.production"]
  }
}

After:

{
  "postCreate": {
    "copyFiles": [".env*"]
  }
}

Advanced patterns:

{
  "postCreate": {
    "copyFiles": [
      ".env*",
      "config/**/*.local.yml",
      "secrets/[ab]*.json"
    ]
  }
}

Supported Patterns

  • * - Matches any characters except / (e.g., *.env matches .env but not config/.env)
  • ** - Matches any characters including / (recursive, e.g., **/*.yml matches all .yml files in any subdirectory)
  • ? - Matches any single character (e.g., file?.txt matches file1.txt but not file10.txt)
  • [abc] - Matches any character in the brackets (e.g., file-[ab].txt matches file-a.txt and file-b.txt)

Implementation Highlights

glob-resolver module:

  • resolveGlobPatterns() - Main resolution function with glob expansion
  • recursiveReaddir() - Walks directory trees for **/ patterns
  • matchesPattern() - Regex-based glob pattern matching
  • Literal file paths take precedence over glob patterns (handles files with glob chars in names)

file-copier integration:

  • Resolves glob patterns before file operations
  • Automatically deduplicates files from overlapping patterns
  • Filters out directories (only files are copied)
  • Zero new dependencies (uses Node.js native globSync)

Testing

22 glob-resolver unit tests covering:

  • Simple wildcard patterns (*.env, .env*)
  • Recursive patterns (config/**/*.local.yml)
  • Special character patterns (?, [abc])
  • Literal filenames containing glob metacharacters
  • Dotfile matching with **/ patterns
  • .git directory exclusion
  • Pattern deduplication
  • Edge cases and error handling

12 file-copier integration tests verifying:

  • Wildcard pattern copying
  • Recursive pattern copying
  • Mixed patterns and exact paths
  • Deduplication of overlapping patterns
  • Subdirectory structure preservation
  • Empty pattern handling

All tests passing: 193 tests total (existing + new)

Technical Details

  • Uses Node.js native fs.globSync() (zero dependencies)
  • Custom **/ pattern implementation to handle dotfiles correctly
  • Automatically excludes .git directory from recursive searches
  • Patterns resolved before file copying
  • Directories automatically filtered out
  • Overlapping patterns automatically deduplicated
  • Works with CLI --copy-file flag

Verification Steps

  1. Clone and install dependencies: pnpm install
  2. Run tests: pnpm test
  3. Verify linting: pnpm lint
  4. Test locally with config containing glob patterns
  5. Create a worktree and verify files are copied according to patterns

Backward Compatibility

✅ Fully backward compatible - all existing exact file paths continue to work unchanged. Literal file paths take precedence over glob pattern matching, so files with glob characters in their names are handled correctly.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfd7a8b60d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@sleicht sleicht force-pushed the feature/add-glob-pattern-support-copyfiles branch 2 times, most recently from 4249d30 to 9c0b1b3 Compare January 13, 2026 10:35
@sleicht sleicht force-pushed the feature/add-glob-pattern-support-copyfiles branch 2 times, most recently from 72d905e to 557167b Compare February 10, 2026 13:24
Adds support for glob patterns in the postCreate.copyFiles configuration
option, allowing users to specify patterns like *.env, **/*.local.yml, and
other standard glob patterns instead of listing each file individually.

Features:
- Created glob-resolver module with pattern detection and expansion
- Support for *, **, ?, and [abc] glob patterns
- Handles literal filenames containing glob metacharacters
- Custom **/ pattern matcher for dotfiles (works around Node.js limitation)
- Excludes .git directory from recursive searches
- Full backward compatibility with exact file paths

Implementation:
- Integrated glob resolution into file-copier workflow
- Added recursiveReaddir() for walking directory trees
- Added matchesPattern() for regex-based glob matching
- Literal file paths take precedence over glob patterns
- Zero dependencies added (uses Node.js native globSync)

Testing:
- Added comprehensive test coverage (22 glob resolver tests)
- Added 12 file-copier integration tests
- Fixed attach.test.js module mocking for globSync
- All tests passing (193 tests total)

Documentation:
- Updated configuration.md with glob syntax reference and examples
@sleicht sleicht force-pushed the feature/add-glob-pattern-support-copyfiles branch from cb29a6d to 93f4922 Compare March 2, 2026 06:51
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.

Feature: Glob Pattern Support for copyFiles

1 participant