Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the asset collection keep track of all of the destinations (#3467) #3469

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading