Skip to content

Commit

Permalink
Make the asset collection keep track of all of the destinations, as t…
Browse files Browse the repository at this point in the history
…here might be more than one destination for the same asset (#3467)
  • Loading branch information
Destroyerrrocket committed Dec 29, 2024
1 parent 26132cf commit 0a60f7d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
18 changes: 14 additions & 4 deletions packages/cli-opt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub use file::process_file_to;
/// This will be filled in primarily by incremental compilation artifacts.
#[derive(Debug, PartialEq, Default, Clone, Serialize, Deserialize)]
pub struct AssetManifest {
/// Map of bundled asset name to the asset itself
pub assets: HashMap<PathBuf, BundledAsset>,
/// Map of bundled asset name to the destination assets.
pub assets: HashMap<PathBuf, HashMap<PathBuf, BundledAsset>>,
}

impl AssetManifest {
Expand Down Expand Up @@ -98,8 +98,18 @@ impl AssetManifest {
while let Some((remaining_buffer, asset)) =
const_serialize::deserialize_const!(BundledAsset, buffer)
{
self.assets
.insert(asset.absolute_source_path().into(), asset);
match self.assets.entry(asset.absolute_source_path().into()) {
std::collections::hash_map::Entry::Occupied(occupied_entry) => {
occupied_entry
.into_mut()
.insert(asset.bundled_path().into(), asset);
}
std::collections::hash_map::Entry::Vacant(vacant_entry) => {
let mut map = HashMap::new();
map.insert(asset.bundled_path().into(), asset);
vacant_entry.insert(map);
}
}
buffer = remaining_buffer;
}
}
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/build/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl AppBundle {
.assets
.assets
.values()
.map(|a| asset_dir.join(a.bundled_path()))
.flat_map(|a| a.keys().cloned())
.collect();
// one possible implementation of walking a directory only visiting files
fn remove_old_assets<'a>(
Expand Down Expand Up @@ -422,11 +422,12 @@ impl AppBundle {
let mut assets_to_transfer = vec![];

// Queue the bundled assets
for (asset, bundled) in &self.app.assets.assets {
let from = asset.clone();
let to = asset_dir.join(bundled.bundled_path());
tracing::debug!("Copying asset {from:?} to {to:?}");
assets_to_transfer.push((from, to, *bundled.options()));
for (from, bundled) in &self.app.assets.assets {
for (bundled_path, bundled) in bundled.iter() {
let to = asset_dir.join(bundled_path);
tracing::debug!("Copying asset {from:?} to {to:?}");
assets_to_transfer.push((from.clone(), to, *bundled.options()));
}
}

// And then queue the legacy assets
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/serve/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ impl AppHandle {

// The asset might've been renamed thanks to the manifest, let's attempt to reload that too
if let Some(resource) = self.app.app.assets.assets.get(&changed_file).as_ref() {
let res = std::fs::copy(&changed_file, asset_dir.join(resource.bundled_path()));
bundled_name = Some(PathBuf::from(resource.bundled_path()));
if let Err(e) = res {
tracing::debug!("Failed to hotreload asset {e}");
for bundled_path in resource.keys() {
let res = std::fs::copy(&changed_file, asset_dir.join(bundled_path));
bundled_name = Some(bundled_path.clone());
if let Err(e) = res {
tracing::debug!("Failed to hotreload asset {e}");
}
}
}

Expand Down

0 comments on commit 0a60f7d

Please sign in to comment.