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) {
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")

View File

@ -7,6 +7,7 @@ import (
"net/http"
"path/filepath"
"strings"
"time"
)
templ PageBundler(r *http.Request, manifest PluginManifest, store *BundlerStore) {
@ -125,20 +126,6 @@ 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 {
@ -146,21 +133,31 @@ templ bundlerResultsFragment(results BundleResults) {
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) }>
<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>
</td>
</tr>
</tbody>
</table>
<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>
}