Browse Source

Fix dx bundle fails when no assets are copied (#3519)

BleemIs42 5 months ago
parent
commit
20cdafbf16
1 changed files with 17 additions and 15 deletions
  1. 17 15
      packages/cli/src/cli/bundle.rs

+ 17 - 15
packages/cli/src/cli/bundle.rs

@@ -179,21 +179,23 @@ impl Bundle {
         }
 
         let asset_dir = bundle.build.asset_dir();
-        let asset_dir_entries = std::fs::read_dir(&asset_dir)
-            .with_context(|| format!("failed to read asset directory {:?}", asset_dir))?;
-        for entry in asset_dir_entries.flatten() {
-            let old = entry
-                .path()
-                .canonicalize()
-                .with_context(|| format!("Failed to canonicalize {entry:?}"))?;
-            let new = PathBuf::from("assets").join(old.file_name().expect("Filename to exist"));
-            tracing::debug!("Bundled asset: {old:?} -> {new:?}");
-
-            bundle_settings
-                .resources_map
-                .as_mut()
-                .expect("to be set")
-                .insert(old.display().to_string(), new.display().to_string());
+        if asset_dir.exists() {
+            let asset_dir_entries = std::fs::read_dir(&asset_dir)
+                .with_context(|| format!("failed to read asset directory {:?}", asset_dir))?;
+            for entry in asset_dir_entries.flatten() {
+                let old = entry
+                    .path()
+                    .canonicalize()
+                    .with_context(|| format!("Failed to canonicalize {entry:?}"))?;
+                let new = PathBuf::from("assets").join(old.file_name().expect("Filename to exist"));
+                tracing::debug!("Bundled asset: {old:?} -> {new:?}");
+
+                bundle_settings
+                    .resources_map
+                    .as_mut()
+                    .expect("to be set")
+                    .insert(old.display().to_string(), new.display().to_string());
+            }
         }
 
         for resource_path in bundle_settings.resources.take().into_iter().flatten() {