Skip to content

Commit 8114976

Browse files
committed
Filter on esm libraries
1 parent 324024d commit 8114976

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

internal/app/action/action.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Action struct {
6666
showValidate bool
6767
auditInsert func(*types.AuditEvent) error
6868
containerManager any // Container manager, if available, used to run commands in the container
69-
jsLibs []types.JSLibrary
69+
esmLibs []types.JSLibrary
7070
}
7171

7272
// NewAction creates a new action
@@ -119,8 +119,11 @@ func NewAction(logger *types.Logger, sourceFS *appfs.SourceFs, isDev bool, name,
119119
hiddenParams[h] = true
120120
}
121121

122-
if len(jsLibs) == 0 {
123-
jsLibs = []types.JSLibrary{*&types.JSLibrary{}}
122+
esmLibs := []types.JSLibrary{}
123+
for _, lib := range jsLibs {
124+
if lib.LibType == types.ESModule {
125+
esmLibs = append(esmLibs, lib)
126+
}
124127
}
125128

126129
return &Action{
@@ -142,7 +145,7 @@ func NewAction(logger *types.Logger, sourceFS *appfs.SourceFs, isDev bool, name,
142145
showValidate: showValidate,
143146
auditInsert: auditInsert,
144147
containerManager: containerManager,
145-
jsLibs: jsLibs,
148+
esmLibs: esmLibs,
146149
// Links, AppTemplate and Theme names are initialized later
147150
}, nil
148151
}
@@ -457,7 +460,7 @@ func (a *Action) execAction(w http.ResponseWriter, r *http.Request, isSuggest, i
457460
"path": a.pagePath,
458461
"lightTheme": a.LightTheme,
459462
"darkTheme": a.DarkTheme,
460-
"jsLibs": a.jsLibs,
463+
"esmLibs": a.esmLibs,
461464
}
462465

463466
if !isHtmxRequest {
@@ -815,7 +818,7 @@ func (a *Action) getForm(w http.ResponseWriter, r *http.Request) {
815818
"hasFileUpload": hasFileUpload,
816819
"showSuggest": a.suggest != nil,
817820
"showValidate": a.showValidate,
818-
"jsLibs": a.jsLibs,
821+
"esmLibs": a.esmLibs,
819822
}
820823
err := a.actionTemplate.ExecuteTemplate(w, "form.go.html", input)
821824
if err != nil {

internal/app/action/layout.go.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@
4848
<script src="{{ astatic "astatic/toggle.js" }}"></script>
4949
<script src="{{ astatic "astatic/htmx.min.js" }}"></script>
5050

51-
{{ if gt (len .jsLibs) 0 }}
51+
{{ if gt (len .esmLibs) 0 }}
5252
<script type="importmap">
5353
{
5454
"imports": {
55-
{{ range $i, $lib := .jsLibs }}
55+
{{ range $i, $lib := .esmLibs }}
5656
{{ $libPath := printf "%s%s" "gen/esm/" $lib.SanitizedFileName }}
5757
"{{ $lib.PackageName }}": "{{ static $libPath}}"
58-
{{ if not (eq $i (sub (len $.jsLibs) 1)) }},{{end}}
58+
{{ if not (eq $i (sub (len $.esmLibs) 1)) }},{{end}}
5959
{{ end }}
6060
}
6161
}

0 commit comments

Comments
 (0)