fix fragile hak packing (#36)
test / test (push) Successful in 1m25s
build-binaries / build-binaries (push) Successful in 2m9s
build-image / publish (push) Successful in 57s

Reviewed-on: #36
Reviewed-by: xtul <mpiasecki720@protonmail.com>
Co-authored-by: vickydotbat <vickydotbat@tutamail.com>
Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit was merged in pull request #36.
This commit is contained in:
2026-07-10 08:59:07 +00:00
committed by archvillainette
parent 754375fb08
commit 825fff8b67
3 changed files with 80 additions and 18 deletions
+24 -4
View File
@@ -211,11 +211,12 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
if d.IsDir() {
return nil
}
if strings.HasPrefix(filepath.Base(path), ".") {
return nil
rel, err := filepath.Rel(assetsDir, path)
if err != nil {
return err
}
if strings.EqualFold(filepath.Ext(path), ".md") {
return nil // docs (AGENTS.md, README.md, ...) are never HAK resources
if skipTopPackageAsset(rel) {
return nil
}
resource, err := topPackageResourceFromPath(path)
if err != nil {
@@ -388,6 +389,25 @@ func newestMatchingAutogenOverrideInput(scanRoot string, include []string) (time
return newest, newestPath, nil
}
// skipTopPackageAsset reports whether a file under assets/ is not a HAK
// resource and must be ignored by both validation and packing: anything in a
// hidden or underscore-prefixed directory (working dirs like _candidates),
// hidden files, docs, and any extension that is not a known NWN ResType
// (erf.extensionTypes is the whitelist). rel is the path relative to assets/.
func skipTopPackageAsset(rel string) bool {
for _, part := range strings.Split(filepath.ToSlash(rel), "/") {
if strings.HasPrefix(part, ".") || strings.HasPrefix(part, "_") {
return true
}
}
if strings.EqualFold(filepath.Ext(rel), ".md") {
return true
}
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(rel)), ".")
_, ok := erf.HAKResourceTypeForExtension(ext)
return !ok
}
func topPackageResourceFromPath(path string) (erf.Resource, error) {
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
resourceType, ok := erf.HAKResourceTypeForExtension(extension)