Skip to content

Commit

Permalink
Attribute Order issue (#582)
Browse files Browse the repository at this point in the history
Fixes #580 by adding alias to hash
  • Loading branch information
delaneyj authored Feb 3, 2025
1 parent fe409ba commit 9901ae7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
14 changes: 12 additions & 2 deletions site/routes_bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,25 @@ type BundleResults struct {
func bundlePlugins(tmpDir string, manifest PluginManifest) (results *BundleResults, err error) {
start := time.Now()

hasAlias := manifest.Alias != ""
distDir := filepath.Join(tmpDir, "dist")

h := xxh3.New()
h.WriteString(manifest.Version)
if hasAlias {
h.WriteString(manifest.Alias)
}
for _, plugin := range manifest.Plugins {
h.WriteString(plugin.Contents)
}
hash := h.Sum64()
hashedName := fmt.Sprintf("datastar-%s-%x", toolbelt.Kebab(manifest.Version), hash)
var hashedName string

versionKebab := toolbelt.Kebab(manifest.Version)
if hasAlias {
hashedName = fmt.Sprintf("datastar-%s-%s-%x", toolbelt.Kebab(manifest.Alias), versionKebab, hash)
} else {
hashedName = fmt.Sprintf("datastar-%s-%x", versionKebab, hash)
}

bundleResultsPath := filepath.Join(distDir, hashedName+".json")

Expand Down
61 changes: 29 additions & 32 deletions site/routes_bundler.templ
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"path/filepath"
"strings"
"time"
)

templ PageBundler(r *http.Request, manifest PluginManifest, store *BundlerStore) {
Expand Down Expand Up @@ -125,42 +126,38 @@ templ PageBundler(r *http.Request, manifest PluginManifest, store *BundlerStore)
}

templ bundlerResultsFragment(results BundleResults) {
<div id="results" class="flex gap-8">
<table class="table w-full">
<thead>
<tr>
<th>Hash</th>
<th>Compile Time</th>
<th>Source Size Gzipped</th>
<th>Fast 4G</th>
<th>Slow 4G</th>
<th>3G</th>
<th class="text-right">Download</th>
</tr>
</thead>
<tbody>
{{
{{
srcBitsF := float64(8 * results.SourceSizeGzipped)
srcTime := func(mbps float64) string {
srcSecsF := srcBitsF / (mbps * 1024 * 1024)
return fmt.Sprintf("%0.1fms", srcSecsF*1000)
}
}}
<tr>
<td>{ results.Hash }</td>
<td>{ results.CompileTime.String() }</td>
<td>{ humanize.Comma(int64( results.SourceSizeGzipped)) } ({ humanize.IBytes(results.SourceSizeGzipped) }) </td>
<td>{ srcTime(9) }</td>
<td>{ srcTime(1.6) }</td>
<td>{ srcTime(0.5) }</td>
<td class="text-right">
<a class="btn btn-success" href={ templ.SafeURL(results.DownloadURL) }>
@icon("material-symbols:folder-zip")
{ results.Name }.zip
</a>
</td>
</tr>
</tbody>
</table>
}}
<div id="results" class="flex flex-col gap-8">
<a class="btn btn-success btn-lg" href={ templ.SafeURL(results.DownloadURL) }>
@icon("material-symbols:folder-zip")
{ results.Name }.zip
</a>
<div class="flex flex-wrap gap-4">
<div class="stats stats-vertical shadow flex-1">
@bundleStat("mdi:rabbit", "Fast 4G", srcTime(9))
@bundleStat("fluent:animal-turtle-16-filled", "Slow 3G", srcTime(1.6))
@bundleStat("f7:slowmo", "3G", srcTime(0.5))
</div>
<div class="stats stats-vertical shadow flex-1">
@bundleStat("simple-icons:compilerexplorer", "Compile Time", fmt.Sprintf("%0.2fms", float64(results.CompileTime)/float64(time.Millisecond)))
@bundleStat("material-symbols:folder-zip", "Source Size", fmt.Sprintf("%d bytes %s", results.SourceSizeGzipped, humanize.IBytes(results.SourceSizeGzipped)))
</div>
</div>
</div>
}

templ bundleStat(iconName, label, value string) {
<div class="stat">
<div class="stat-figure text-success text-3xl">
@icon(iconName)
</div>
<div class="stat-title">{ label }</div>
<div class="stat-value">{ value }</div>
</div>
}

0 comments on commit 9901ae7

Please sign in to comment.