Skip to content

Commit 429f465

Browse files
committed
cmd: ignore bad softlinks, remove verbosity level for warning (now 1 is info, 2 is debug); fix bugs for --match/--include/--exclude, see #901
1 parent 58d4d90 commit 429f465

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

cmd/minify/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ Match will filters all files by the given pattern, eg. `--match '*.css'` will on
219219

220220
You may define multiple patterns within one option, such as: `--exclude '**/folder1/**' '**/folder2/**' '**/folder3/**'` Doing this might result in unexpected behaviour when it is followed immediately by the input files, as this would be interpreted as another pattern, and not as inputs. `--exclude dir_to_exclude folder_input` Instead format accordingly: `--exclude dir_to_exclude -- folder_input`.
221221

222+
To match `*` or `?` literally, precede by a backslash. To specify a regular expression directly instead of a glob, use the tilde as a prefix (to use a tilde literally at the beginning, precede by a backslash). Examples of regular expressions:
223+
224+
```
225+
./minify --match ~^path[0-9]/[^/]*.(js|html)$
226+
./minify --match ~^(?i)pathCaseInsensitive[0-9]/[^/]*.(js|html)$
227+
```
228+
222229
### Concatenate
223230
When multiple inputs are given and the output is either standard output or a single file, it will concatenate the files together if you use the bundle option.
224231

cmd/minify/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,11 @@ func run() int {
292292
Debug = log.New(io.Discard, "", 0)
293293
if !quiet {
294294
Error = log.New(os.Stderr, "ERROR: ", 0)
295+
Warning = log.New(os.Stderr, "WARNING: ", 0)
295296
if 0 < verbose {
296-
Warning = log.New(os.Stderr, "WARNING: ", 0)
297-
}
298-
if 1 < verbose {
299297
Info = log.New(os.Stderr, "INFO: ", 0)
300298
}
301-
if 2 < verbose {
299+
if 1 < verbose {
302300
Debug = log.New(os.Stderr, "DEBUG: ", 0)
303301
}
304302
}
@@ -629,10 +627,14 @@ func compilePattern(pattern string) (*regexp.Regexp, error) {
629627
pattern = pattern[1:]
630628
}
631629
pattern = regexp.QuoteMeta(pattern)
630+
pattern = strings.ReplaceAll(pattern, `\\\*`, `\*`)
631+
pattern = strings.ReplaceAll(pattern, `\\\?`, `\?`)
632632
pattern = strings.ReplaceAll(pattern, `\*\*`, `.*`)
633633
pattern = strings.ReplaceAll(pattern, `\*`, fmt.Sprintf(`[^%s]*`, sep))
634-
pattern = strings.ReplaceAll(pattern, `\?`, fmt.Sprintf(`[^%s]?`, sep))
634+
pattern = strings.ReplaceAll(pattern, `\?`, fmt.Sprintf(`[^%s]`, sep))
635635
pattern = "^" + pattern + "$"
636+
} else {
637+
pattern = pattern[1:]
636638
}
637639
return regexp.Compile(pattern)
638640
}
@@ -693,7 +695,8 @@ func createTasks(fsys fs.FS, inputs []string, output string) ([]Task, []string,
693695
info, err = os.Lstat(input)
694696
}
695697
if err != nil {
696-
return nil, nil, err
698+
Error.Println(err)
699+
continue
697700
}
698701

699702
if preserveLinks && info.Mode()&os.ModeSymlink != 0 {
@@ -747,7 +750,8 @@ func createTasks(fsys fs.FS, inputs []string, output string) ([]Task, []string,
747750
// follow and dereference symlinks
748751
info, err := fs.Stat(fsys, input)
749752
if err != nil {
750-
return err
753+
Error.Println(err)
754+
return nil
751755
}
752756
if info.IsDir() {
753757
return fs.WalkDir(fsys, input, walkFn)

0 commit comments

Comments
 (0)