mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
loader: support "all:" prefix in //go:embed patterns
The "all:" prefix in //go:embed directives instructs the compiler to include hidden files (starting with "." or "_") when embedding a directory. Previously, the prefix was passed literally to path.Match, which would never match. Introduce an embedPattern struct that parses and validates the pattern at construction time via newEmbedPattern(). The "all:" prefix is stripped once and stored along with the glob pattern, avoiding repeated string prefix checks. Pattern validation is absorbed into the constructor, guaranteeing that any embedPattern value is valid and eliminating the need for separate validation loops. Fixes embedding with patterns like "//go:embed all:static".
This commit is contained in:
committed by
deadprogram
parent
27e5baeb57
commit
44b0c79eaf
Vendored
+10
-4
@@ -20,6 +20,10 @@ var (
|
||||
//go:embed a/b/.hidden
|
||||
var hidden string
|
||||
|
||||
// A test to check that hidden files ARE included when using "all:" prefix.
|
||||
//go:embed all:a
|
||||
var allFiles embed.FS
|
||||
|
||||
var helloStringBytes = []byte(helloString)
|
||||
|
||||
func main() {
|
||||
@@ -27,11 +31,13 @@ func main() {
|
||||
println("bytes:", strings.TrimSpace(string(helloBytes)))
|
||||
println("[]byte(string):", strings.TrimSpace(string(helloStringBytes)))
|
||||
println("files:")
|
||||
readFiles(".")
|
||||
readFiles(".", files)
|
||||
println("all:a files (should include .hidden):")
|
||||
readFiles(".", allFiles)
|
||||
}
|
||||
|
||||
func readFiles(dir string) {
|
||||
entries, err := files.ReadDir(dir)
|
||||
func readFiles(dir string, fs embed.FS) {
|
||||
entries, err := fs.ReadDir(dir)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
@@ -43,7 +49,7 @@ func readFiles(dir string) {
|
||||
}
|
||||
println("-", entryPath)
|
||||
if entry.IsDir() {
|
||||
readFiles(entryPath)
|
||||
readFiles(entryPath, fs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user