Attribute Order issue (#582)

Fixes #580 by adding alias to hash
This commit is contained in:
Delaney 2025-02-03 07:43:46 -08:00 committed by GitHub
parent fe409baf4c
commit 9901ae7f4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 34 deletions

View File

@ -271,15 +271,25 @@ type BundleResults struct {
func bundlePlugins(tmpDir string, manifest PluginManifest) (results *BundleResults, err error) { func bundlePlugins(tmpDir string, manifest PluginManifest) (results *BundleResults, err error) {
start := time.Now() start := time.Now()
hasAlias := manifest.Alias != ""
distDir := filepath.Join(tmpDir, "dist") distDir := filepath.Join(tmpDir, "dist")
h := xxh3.New() h := xxh3.New()
h.WriteString(manifest.Version) h.WriteString(manifest.Version)
if hasAlias {
h.WriteString(manifest.Alias)
}
for _, plugin := range manifest.Plugins { for _, plugin := range manifest.Plugins {
h.WriteString(plugin.Contents) h.WriteString(plugin.Contents)
} }
hash := h.Sum64() 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") bundleResultsPath := filepath.Join(distDir, hashedName+".json")

View File

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
) )
templ PageBundler(r *http.Request, manifest PluginManifest, store *BundlerStore) { templ PageBundler(r *http.Request, manifest PluginManifest, store *BundlerStore) {
@ -125,42 +126,38 @@ templ PageBundler(r *http.Request, manifest PluginManifest, store *BundlerStore)
} }
templ bundlerResultsFragment(results BundleResults) { 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) srcBitsF := float64(8 * results.SourceSizeGzipped)
srcTime := func(mbps float64) string { srcTime := func(mbps float64) string {
srcSecsF := srcBitsF / (mbps * 1024 * 1024) srcSecsF := srcBitsF / (mbps * 1024 * 1024)
return fmt.Sprintf("%0.1fms", srcSecsF*1000) return fmt.Sprintf("%0.1fms", srcSecsF*1000)
} }
}} }}
<tr> <div id="results" class="flex flex-col gap-8">
<td>{ results.Hash }</td> <a class="btn btn-success btn-lg" href={ templ.SafeURL(results.DownloadURL) }>
<td>{ results.CompileTime.String() }</td> @icon("material-symbols:folder-zip")
<td>{ humanize.Comma(int64( results.SourceSizeGzipped)) } ({ humanize.IBytes(results.SourceSizeGzipped) }) </td> { results.Name }.zip
<td>{ srcTime(9) }</td> </a>
<td>{ srcTime(1.6) }</td> <div class="flex flex-wrap gap-4">
<td>{ srcTime(0.5) }</td> <div class="stats stats-vertical shadow flex-1">
<td class="text-right"> @bundleStat("mdi:rabbit", "Fast 4G", srcTime(9))
<a class="btn btn-success" href={ templ.SafeURL(results.DownloadURL) }> @bundleStat("fluent:animal-turtle-16-filled", "Slow 3G", srcTime(1.6))
@icon("material-symbols:folder-zip") @bundleStat("f7:slowmo", "3G", srcTime(0.5))
{ results.Name }.zip </div>
</a> <div class="stats stats-vertical shadow flex-1">
</td> @bundleStat("simple-icons:compilerexplorer", "Compile Time", fmt.Sprintf("%0.2fms", float64(results.CompileTime)/float64(time.Millisecond)))
</tr> @bundleStat("material-symbols:folder-zip", "Source Size", fmt.Sprintf("%d bytes %s", results.SourceSizeGzipped, humanize.IBytes(results.SourceSizeGzipped)))
</tbody> </div>
</table> </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> </div>
} }