diff --git a/packages/cli-opt/src/file.rs b/packages/cli-opt/src/file.rs index 254a822436..df465356cc 100644 --- a/packages/cli-opt/src/file.rs +++ b/packages/cli-opt/src/file.rs @@ -1,6 +1,6 @@ use anyhow::Context; use manganis_core::{AssetOptions, CssAssetOptions, ImageAssetOptions, JsAssetOptions}; -use std::{ffi::OsStr, path::Path}; +use std::path::Path; use crate::css::process_scss; @@ -40,56 +40,59 @@ pub(crate) fn process_file_to_with_options( // Processing can be slow. Write to a temporary file first and then rename it to the final output path. If everything // goes well. Without this, the user could quit in the middle of processing and the file will look complete to the // caching system even though it is empty. - let mut partial_ext = output_path.extension().unwrap_or_default().to_os_string(); - partial_ext.push(OsStr::new(".partial")); - let temp_output_path = output_path.with_extension(&partial_ext); - let temp_output_path = &temp_output_path; + let temp_path = output_path.with_file_name(format!( + "partial.{}", + output_path + .file_name() + .unwrap_or_default() + .to_string_lossy() + )); match options { AssetOptions::Unknown => match source.extension().map(|e| e.to_string_lossy()).as_deref() { Some("css") => { - process_css(&CssAssetOptions::new(), source, temp_output_path)?; + process_css(&CssAssetOptions::new(), source, &temp_path)?; } Some("scss" | "sass") => { - process_scss(&CssAssetOptions::new(), source, temp_output_path)?; + process_scss(&CssAssetOptions::new(), source, &temp_path)?; } Some("js") => { - process_js(&JsAssetOptions::new(), source, temp_output_path, !in_folder)?; + process_js(&JsAssetOptions::new(), source, &temp_path, !in_folder)?; } Some("json") => { - process_json(source, temp_output_path)?; + process_json(source, &temp_path)?; } Some("jpg" | "jpeg" | "png" | "webp" | "avif") => { - process_image(&ImageAssetOptions::new(), source, temp_output_path)?; + process_image(&ImageAssetOptions::new(), source, &temp_path)?; } Some(_) | None => { if source.is_dir() { - process_folder(source, temp_output_path)?; + process_folder(source, &temp_path)?; } else { let source_file = std::fs::File::open(source)?; let mut reader = std::io::BufReader::new(source_file); - let output_file = std::fs::File::create(temp_output_path)?; + let output_file = std::fs::File::create(&temp_path)?; let mut writer = std::io::BufWriter::new(output_file); std::io::copy(&mut reader, &mut writer).with_context(|| { format!( "Failed to write file to output location: {}", - temp_output_path.display() + temp_path.display() ) })?; } } }, AssetOptions::Css(options) => { - process_css(options, source, temp_output_path)?; + process_css(options, source, &temp_path)?; } AssetOptions::Js(options) => { - process_js(options, source, temp_output_path, !in_folder)?; + process_js(options, source, &temp_path, !in_folder)?; } AssetOptions::Image(options) => { - process_image(options, source, temp_output_path)?; + process_image(options, source, &temp_path)?; } AssetOptions::Folder(_) => { - process_folder(source, temp_output_path)?; + process_folder(source, &temp_path)?; } _ => { tracing::warn!("Unknown asset options: {:?}", options); @@ -97,7 +100,7 @@ pub(crate) fn process_file_to_with_options( } // If everything was successful, rename the temp file to the final output path - std::fs::rename(temp_output_path, output_path)?; + std::fs::rename(temp_path, output_path)?; Ok(()) } diff --git a/packages/playwright-tests/cli-optimization/images/toasts.png b/packages/playwright-tests/cli-optimization/images/toasts.png new file mode 100644 index 0000000000..382298f9c7 Binary files /dev/null and b/packages/playwright-tests/cli-optimization/images/toasts.png differ diff --git a/packages/playwright-tests/cli-optimization/src/main.rs b/packages/playwright-tests/cli-optimization/src/main.rs index 32cecf8792..a216497178 100644 --- a/packages/playwright-tests/cli-optimization/src/main.rs +++ b/packages/playwright-tests/cli-optimization/src/main.rs @@ -3,6 +3,7 @@ use dioxus::prelude::*; const MONACO_FOLDER: Asset = asset!("/monaco-editor-0.52.2/package/min/vs"); +const SOME_IMAGE: Asset = asset!("/images/toasts.png", ImageAssetOptions::new().with_avif()); fn main() { dioxus::launch(App); @@ -30,5 +31,8 @@ fn App() -> Element { src: "{MONACO_FOLDER}/loader.js", "onload": script } + img { + src: "{SOME_IMAGE}" + } } }