SamKirkland / ftp-deploy

Deploy websites over FTP with one command line
MIT License
89 stars 43 forks source link

`.*` glob matches files in subfolders too #12

Open DemianX0 opened 3 years ago

DemianX0 commented 3 years ago

Expected:

.* should only match (dot) files in the root folder (local-dir) (glob tool example)

Actual:

.* matches all dot-files in subfolders as well. This should happen only for **/.* glob (glob tool example)

I assume this affects all patterns, not tested yet.

Output:

After removing the exclude glob .*:

uploading ".htaccess"
uploading "includes/.htaccess"
uploading "languages/.htaccess"
uploading "maintenance/.htaccess"
uploading "maintenance/archives/.htaccess"

Version:

'@samkirkland/ftp-deploy': 1.1.0

DemianX0 commented 3 years ago

This seems to be intentional, caused by matchBase: true (docs) at https://github.com/SamKirkland/ftp-deploy/blob/5554a6ff4ab20e0cce6bedf00a40c45d9fb44d7d/src/localFiles.ts#L10

Any glob without a / is matched against only the file name (basename). This might be convenient in some use-cases, inconvenient in others, for ex. to exclude all .json files in the root (such as package.json, package-lock.json), but not in the subfolders one has to write a complicated additional negated rule that's not documented:

- *.json
- !*/**/*.json

This is far from obvious without diving into multimatch: https://github.com/sindresorhus/multimatch#how-multiple-patterns-work

Other common-sense patterns I thought about don't match anything:

- /*.json
- ./*.json
- //*.json

The excludeDefaults pattern **/.git* (which is equivalent to .git* with matchBase) suggests matching filenames in subfolders should be explicitly marked. This is what I would suggest by disabling the matchBase option or making it configurable.