Skip to content

Commit a8620a7

Browse files
committed
fix: use a different temp path to not confuse image opt
1 parent 13dcd80 commit a8620a7

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

packages/cli-opt/src/file.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Context;
22
use manganis_core::{AssetOptions, CssAssetOptions, ImageAssetOptions, JsAssetOptions};
3-
use std::{ffi::OsStr, path::Path};
3+
use std::path::Path;
44

55
use crate::css::process_scss;
66

@@ -40,64 +40,67 @@ pub(crate) fn process_file_to_with_options(
4040
// Processing can be slow. Write to a temporary file first and then rename it to the final output path. If everything
4141
// goes well. Without this, the user could quit in the middle of processing and the file will look complete to the
4242
// caching system even though it is empty.
43-
let mut partial_ext = output_path.extension().unwrap_or_default().to_os_string();
44-
partial_ext.push(OsStr::new(".partial"));
45-
let temp_output_path = output_path.with_extension(&partial_ext);
46-
let temp_output_path = &temp_output_path;
43+
let temp_path = output_path.with_file_name(format!(
44+
"partial.{}",
45+
output_path
46+
.file_name()
47+
.unwrap_or_default()
48+
.to_string_lossy()
49+
));
4750

4851
match options {
4952
AssetOptions::Unknown => match source.extension().map(|e| e.to_string_lossy()).as_deref() {
5053
Some("css") => {
51-
process_css(&CssAssetOptions::new(), source, temp_output_path)?;
54+
process_css(&CssAssetOptions::new(), source, &temp_path)?;
5255
}
5356
Some("scss" | "sass") => {
54-
process_scss(&CssAssetOptions::new(), source, temp_output_path)?;
57+
process_scss(&CssAssetOptions::new(), source, &temp_path)?;
5558
}
5659
Some("js") => {
57-
process_js(&JsAssetOptions::new(), source, temp_output_path, !in_folder)?;
60+
process_js(&JsAssetOptions::new(), source, &temp_path, !in_folder)?;
5861
}
5962
Some("json") => {
60-
process_json(source, temp_output_path)?;
63+
process_json(source, &temp_path)?;
6164
}
6265
Some("jpg" | "jpeg" | "png" | "webp" | "avif") => {
63-
process_image(&ImageAssetOptions::new(), source, temp_output_path)?;
66+
process_image(&ImageAssetOptions::new(), source, &temp_path)?;
6467
}
6568
Some(_) | None => {
6669
if source.is_dir() {
67-
process_folder(source, temp_output_path)?;
70+
process_folder(source, &temp_path)?;
6871
} else {
6972
let source_file = std::fs::File::open(source)?;
7073
let mut reader = std::io::BufReader::new(source_file);
71-
let output_file = std::fs::File::create(temp_output_path)?;
74+
let output_file = std::fs::File::create(&temp_path)?;
7275
let mut writer = std::io::BufWriter::new(output_file);
7376
std::io::copy(&mut reader, &mut writer).with_context(|| {
7477
format!(
7578
"Failed to write file to output location: {}",
76-
temp_output_path.display()
79+
temp_path.display()
7780
)
7881
})?;
7982
}
8083
}
8184
},
8285
AssetOptions::Css(options) => {
83-
process_css(options, source, temp_output_path)?;
86+
process_css(options, source, &temp_path)?;
8487
}
8588
AssetOptions::Js(options) => {
86-
process_js(options, source, temp_output_path, !in_folder)?;
89+
process_js(options, source, &temp_path, !in_folder)?;
8790
}
8891
AssetOptions::Image(options) => {
89-
process_image(options, source, temp_output_path)?;
92+
process_image(options, source, &temp_path)?;
9093
}
9194
AssetOptions::Folder(_) => {
92-
process_folder(source, temp_output_path)?;
95+
process_folder(source, &temp_path)?;
9396
}
9497
_ => {
9598
tracing::warn!("Unknown asset options: {:?}", options);
9699
}
97100
}
98101

99102
// If everything was successful, rename the temp file to the final output path
100-
std::fs::rename(temp_output_path, output_path)?;
103+
std::fs::rename(temp_path, output_path)?;
101104

102105
Ok(())
103106
}
Loading

packages/playwright-tests/cli-optimization/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use dioxus::prelude::*;
44

55
const MONACO_FOLDER: Asset = asset!("/monaco-editor-0.52.2/package/min/vs");
6+
const SOME_IMAGE: Asset = asset!("/images/toasts.png", ImageAssetOptions::new().with_avif());
67

78
fn main() {
89
dioxus::launch(App);
@@ -30,5 +31,8 @@ fn App() -> Element {
3031
src: "{MONACO_FOLDER}/loader.js",
3132
"onload": script
3233
}
34+
img {
35+
src: "{SOME_IMAGE}"
36+
}
3337
}
3438
}

0 commit comments

Comments
 (0)