Skip to content

Commit 22e3152

Browse files
committed
fix: bundle UI assets at startup
Generate the current Topcoat asset bundle before serving the local UI. Assisted-by: Zed:gpt-5.6-luna
1 parent b75d2f8 commit 22e3152

3 files changed

Lines changed: 99 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/git-forge-ui/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2024"
77
gix-forge = { path = "../gix-forge" }
88
gix = { workspace = true, features = ["parallel"] }
99
topcoat = { path = "../../vendor/topcoat/crates/topcoat", default-features = false, features = ["asset", "router", "serve", "view", "discover"] }
10+
topcoat-asset = { path = "../../vendor/topcoat/crates/topcoat-asset", features = ["bundler"] }
1011
tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "signal"] }
1112
anyhow = "1"
1213
arborium = { version = "=2.18.1", features = ["all-languages"] }

crates/git-forge-ui/src/lib.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,48 @@ pub mod render;
33
mod shell;
44
pub mod tree;
55

6-
use std::sync::Arc;
6+
use std::{fs, sync::Arc};
77

88
use topcoat::{
99
asset::{AssetBundle, RouterBuilderAssetExt},
1010
router::{Router, RouterBuilderDiscoverExt},
1111
};
12+
use topcoat_asset::{Bundler, BundlerConfig};
1213

1314
pub async fn build_router(repo: Arc<gix::ThreadSafeRepository>) -> Router {
15+
let executable = std::env::current_exe()
16+
.expect("failed to locate the current executable for asset bundling");
17+
let assets_dir = executable
18+
.parent()
19+
.expect("current executable has no parent directory for asset bundling")
20+
.join("assets");
21+
let binary = fs::read(&executable).unwrap_or_else(|error| {
22+
panic!(
23+
"failed to read executable {} for asset bundling: {error}",
24+
executable.display()
25+
)
26+
});
27+
28+
let config = BundlerConfig::new().cache_dir(assets_dir.join(".cache"));
29+
Bundler::new(&config)
30+
.bundle(&binary, &assets_dir)
31+
.unwrap_or_else(|error| {
32+
panic!(
33+
"failed to bundle assets from {} into {}: {error}",
34+
executable.display(),
35+
assets_dir.display()
36+
)
37+
});
38+
let assets = AssetBundle::load_dir(&assets_dir).unwrap_or_else(|error| {
39+
panic!(
40+
"failed to load the freshly bundled assets from {}: {error}",
41+
assets_dir.display()
42+
)
43+
});
44+
1445
Router::builder()
1546
.discover()
1647
.app_context(repo)
17-
.assets(AssetBundle::load().expect("failed to load bundled assets"))
48+
.assets(assets)
1849
.build()
1950
}

0 commit comments

Comments
 (0)