diff --git a/weft/assets.go b/weft/assets.go
index a586900..b09af4b 100644
--- a/weft/assets.go
+++ b/weft/assets.go
@@ -167,24 +167,27 @@ func CreateSubResourcePreload(args ...string) (template.HTML, error) {
}
// CreateImportMap generates an import map script tag which maps JS module asset filenames to their
-// respectful hash-prefixed path name. eg:
+// respectful hash-prefixed path name. Also includes subresource integrity values for these files. eg:
//
-//
+//
func CreateImportMap(nonce string) template.HTML {
- importMapping := make(map[string]string, 0)
- for k, v := range assetHashes {
+ importMapping := make(map[string]*asset, 0)
+ for k, _ := range assetHashes {
if !strings.HasSuffix(k, ".mjs") {
continue
}
filename := path.Base(k)
- importMapping[filename] = v
+ importMapping[filename] = assets[k]
}
if len(importMapping) == 0 {
return template.HTML("")
@@ -196,7 +199,7 @@ func CreateImportMap(nonce string) template.HTML {
// createImportMapTag returns the "
return importMap
diff --git a/weft/assets_test.go b/weft/assets_test.go
index cb04c50..8de43a7 100644
--- a/weft/assets_test.go
+++ b/weft/assets_test.go
@@ -185,19 +185,25 @@ func TestCreateImportTag(t *testing.T) {
work := []struct {
testName string
nonce string
- importMapping map[string]string
+ importMapping map[string]*asset
expected string
}{
{
"No nonce, one module file",
"",
- map[string]string{
- "test.mjs": "/assets/js/hashprefix-test.mjs",
+ map[string]*asset{
+ "test.mjs": &asset{
+ hashedPath: "/assets/js/hashprefix-test.mjs",
+ sri: "sha384-abcd",
+ },
},
``,
@@ -205,15 +211,25 @@ func TestCreateImportTag(t *testing.T) {
{
"Nonce present, two module files",
"abcdefg",
- map[string]string{
- "test1.mjs": "/assets/js/hashprefix-test1.mjs",
- "test2.mjs": "/assets/js/hashprefix-test2.mjs",
+ map[string]*asset{
+ "test1.mjs": &asset{
+ hashedPath: "/assets/js/hashprefix-test1.mjs",
+ sri: "sha384-efgh",
+ },
+ "test2.mjs": &asset{
+ hashedPath: "/assets/js/hashprefix-test2.mjs",
+ sri: "sha384-ijkl",
+ },
},
``,