-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.go
More file actions
122 lines (105 loc) · 3.06 KB
/
Copy pathfilter.go
File metadata and controls
122 lines (105 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package repomap
import (
"os"
"path/filepath"
"regexp"
"strings"
)
const defaultMaxFileSize = 50_000
// bundleHashRe matches a hex hash segment (8+ chars) separated by dots or hyphens,
// as produced by webpack and other bundlers (e.g. main.a1b2c3d4.js, 4044.62596fd0.chunk.js).
var bundleHashRe = regexp.MustCompile(`[.\-][0-9a-f]{8,}[.\-]`)
// skipDirs holds directory names to skip during filesystem walk.
var skipDirs = map[string]bool{
// VCS
".git": true,
// Dependency caches
"vendor": true,
"node_modules": true,
"__pycache__": true,
".venv": true,
// Build output
"build": true,
"dist": true,
"target": true,
"out": true,
"_app": true, // SvelteKit build output
".svelte-kit": true,
".next": true, // Next.js build output
".nuxt": true, // Nuxt build output
".output": true, // Nitro/Nuxt output
"coverage": true,
// Scratch / temp
".work": true,
".tmp": true,
"tmp": true,
// Caches
".cache": true,
".parcel-cache": true, // Parcel bundler
".turbo": true, // Turborepo cache
".angular": true, // Angular cache
// IDE / tooling config
".idea": true, // JetBrains
".vscode": true, // VS Code
".devcontainer": true, // Dev container config
// Test fixtures
"testdata": true, // Go test fixtures
// Infrastructure tooling
".terraform": true, // Terraform state
// JVM build tools
".gradle": true, // Gradle cache
".mvn": true, // Maven wrapper
// Language-specific package managers
".bundle": true, // Ruby bundler
"Pods": true, // CocoaPods
".dart_tool": true, // Dart toolchain
".pub-cache": true, // Dart pub cache
// Codegen output
"__generated__": true, // GraphQL / generic codegen
"storybook-static": true, // Storybook build output
}
// inSkipDir reports whether path has any component in skipDirs.
func inSkipDir(path string) bool {
for _, part := range strings.Split(filepath.Dir(path), string(filepath.Separator)) {
if skipDirs[part] {
return true
}
}
return false
}
// isBuildArtifact returns true for files that are likely minified, bundled, or generated output.
func isBuildArtifact(path string) bool {
base := filepath.Base(path) //nolint:filepathbase // path is already a relative filename
switch {
// Minified assets
case strings.HasSuffix(base, ".min.js"),
strings.HasSuffix(base, ".min.css"):
return true
// Bundler output
case strings.HasSuffix(base, ".bundle.js"),
strings.HasSuffix(base, ".chunk.js"),
strings.HasSuffix(base, ".chunk.css"):
return true
// Compiled output (e.g. Wasm glue)
case strings.HasSuffix(base, "_compiled.js"):
return true
// Codegen output
case strings.Contains(base, ".generated."):
return true
// Webpack / bundler content-hash filenames
case bundleHashRe.MatchString(base):
return true
}
return false
}
// tooBig reports whether the file exceeds the maxFileSize limit.
func tooBig(path string, maxSize int) bool {
info, err := os.Stat(path)
if err != nil {
return true
}
if maxSize < 0 {
return false
}
return info.Size() > int64(maxSize)
}