Add --exclude option to filter files during uploads#269
Open
Add --exclude option to filter files during uploads#269
--exclude option to filter files during uploads#269Conversation
e7ac9c6 to
f7df5c8
Compare
--exclude option to filter files during uploads
tomlongridge
reviewed
Mar 6, 2026
pkg/utils/files.go
Outdated
Comment on lines
+77
to
+80
| // Check if the pattern contains path separators and matches as substring | ||
| if strings.Contains(filePath, pattern) { | ||
| return true | ||
| } |
Contributor
There was a problem hiding this comment.
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.
pkg/options/options.go
Outdated
| 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.)"` |
Contributor
There was a problem hiding this comment.
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?
Enforce HTTP/1.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
--excludeoption was implemented at three levels:Exclude []stringfield to theUploadstruct inpkg/options/options.go, making it available for all upload commandsIsFileExcluded()function inpkg/utils/files.gothat supports multiple types of patterns:doublestar.Match()for file extensions and patterns (e.g.,*.map,*.log)**for deep directory matching (e.g.,node_modules/**,**/*.map,**/dist/**)test.map)ProcessFileRequest()inpkg/server/request.gobefore files are uploadedThe implementation uses the
github.com/bmatcuk/doublestar/v4library for advanced glob pattern matching, including**support for recursive directory traversal. This provides powerful and flexible filtering capabilities similar to.gitignorepatterns, while maintaining compatibility with various file path formats across platforms.Pattern Examples
*.map- Exclude all files ending in.mapnode_modules/**- Exclude all files undernode_modules/directory**/node_modules/**- Excludenode_modules/at any directory level**/*.test.js- Exclude all.test.jsfiles anywhere in the treesrc/**/*.map- Exclude all.mapfiles within thesrc/directory tree**/temp/**- Exclude all files in anytemp/directoryChangeset
Exclude []stringfield toUploadstruct inpkg/options/options.goIsFileExcluded()function inpkg/utils/files.gowithdoublestarlibrarygithub.com/bmatcuk/doublestar/v4dependency togo.modProcessFileRequest()inpkg/server/request.gotest/utils/files_test.go:**globbing patterns, and edge casestest/upload/js_test.gofeatures/cli/exclude-option.featurewith 5 scenariosTesting
Covered by CI