Skip to content

Add --exclude option to filter files during uploads#269

Open
joshedney wants to merge 14 commits intonextfrom
je/plat-15748-exclude-flag
Open

Add --exclude option to filter files during uploads#269
joshedney wants to merge 14 commits intonextfrom
je/plat-15748-exclude-flag

Conversation

@joshedney
Copy link
Contributor

@joshedney joshedney commented Mar 6, 2026

Goal

Add support for excluding files from uploads based on pattern matching. This allows users to filter out unwanted files (e.g., development source maps, temporary files, or specific directories) during upload operations without having to manually organize their file structure.

Design

The --exclude option was implemented at three levels:

  1. CLI Option Definition - Added Exclude []string field to the Upload struct in pkg/options/options.go, making it available for all upload commands
  2. Core Matching Logic - Implemented IsFileExcluded() function in pkg/utils/files.go that supports multiple types of patterns:
    • Wildcard matching using doublestar.Match() for file extensions and patterns (e.g., *.map, *.log)
    • Recursive globbing using ** for deep directory matching (e.g., node_modules/**, **/*.map, **/dist/**)
    • Exact filename matching for specific files (e.g., test.map)
  3. Upload Integration - Added exclusion check in ProcessFileRequest() in pkg/server/request.go before files are uploaded

The implementation uses the github.com/bmatcuk/doublestar/v4 library for advanced glob pattern matching, including ** support for recursive directory traversal. This provides powerful and flexible filtering capabilities similar to .gitignore patterns, while maintaining compatibility with various file path formats across platforms.

Pattern Examples

  • *.map - Exclude all files ending in .map
  • node_modules/** - Exclude all files under node_modules/ directory
  • **/node_modules/** - Exclude node_modules/ at any directory level
  • **/*.test.js - Exclude all .test.js files anywhere in the tree
  • src/**/*.map - Exclude all .map files within the src/ directory tree
  • **/temp/** - Exclude all files in any temp/ directory

Changeset

  • Added Exclude []string field to Upload struct in pkg/options/options.go
  • Implemented IsFileExcluded() function in pkg/utils/files.go with doublestar library
  • Added github.com/bmatcuk/doublestar/v4 dependency to go.mod
  • Added exclusion check in ProcessFileRequest() in pkg/server/request.go
  • Added comprehensive unit tests in test/utils/files_test.go:
    • 15 test cases covering wildcards, exact matches, substrings, ** globbing patterns, and edge cases
  • Added integration test in test/upload/js_test.go
  • Added BDD feature tests in features/cli/exclude-option.feature with 5 scenarios

Testing

Covered by CI

@joshedney joshedney force-pushed the je/plat-15748-exclude-flag branch from e7ac9c6 to f7df5c8 Compare March 6, 2026 09:57
@joshedney joshedney changed the title Je/plat 15748 exclude flag Add --exclude option to filter files during uploads Mar 6, 2026
@joshedney joshedney self-assigned this Mar 6, 2026
@joshedney joshedney requested review from lemnik and tomlongridge March 6, 2026 10:02
Comment on lines +77 to +80
// Check if the pattern contains path separators and matches as substring
if strings.Contains(filePath, pattern) {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this might be too eager to match. It might be more expected for users to need to give a full path match for cases like node_modules/** and avoid unexpected excluding.

Retries int `help:"The number of retry attempts before failing an upload request" default:"0"`
Timeout int `help:"The number of seconds to wait before failing an upload request" default:"300"`
UploadAPIRootUrl string `help:"The upload server hostname, optionally containing port number"`
Exclude []string `help:"Exclude files matching these patterns (supports wildcards like *.map, path/to/*, etc.)"`
Copy link
Contributor

Choose a reason for hiding this comment

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

How consistent are the file paths when they are matched? Is it possible to say in the usage whether the exclude patterns should be relative to where the command is run?

@joshedney joshedney requested a review from tomlongridge March 9, 2026 17:23
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.

2 participants