diff --git a/Cargo.lock b/Cargo.lock index 3653503d7..722baf4cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,7 +605,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41e7771d4ab6635cbd685ce8db215b29c78a468098126de77c57f3b2e6eb3757" dependencies = [ - "dirs 5.0.1", + "dirs", "git2", "terminal-prompt", ] @@ -1075,7 +1075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4918709cc4dd777ad2b6303ed03cb37f3ca0ccede8c1b0d28ac6db8f4710e0" dependencies = [ "once_cell", - "proc-macro-crate 2.0.1", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "syn 2.0.48", @@ -1250,9 +1250,9 @@ dependencies = [ [[package]] name = "cargo-generate" -version = "0.18.5" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2885ae054e000b117515ab33e91c10eca90c2788a7baec1b97ada1f1f51e57" +checksum = "92c1b6f44358912a9538fa3b6ac8d3aa3f585444f9dc32f12ed85d1545a9df9f" dependencies = [ "anyhow", "auth-git2", @@ -1284,7 +1284,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "toml 0.8.2", + "toml 0.8.8", "walkdir", ] @@ -1350,6 +1350,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cargo_toml" version = "0.16.3" @@ -1357,7 +1371,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3f9629bc6c4388ea699781dc988c2b99766d7679b151c81990b4fa1208fafd3" dependencies = [ "serde", - "toml 0.8.2", + "toml 0.8.8", +] + +[[package]] +name = "cargo_toml" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "802b755090e39835a4b0440fb0bbee0df7495a8b337f63db21e616f7821c7e8c" +dependencies = [ + "serde", + "toml 0.8.8", ] [[package]] @@ -2370,8 +2394,8 @@ dependencies = [ "axum 0.5.17", "axum-server", "cargo-generate", - "cargo_metadata 0.15.4", - "cargo_toml", + "cargo_metadata 0.18.1", + "cargo_toml 0.18.0", "chrono", "clap 4.4.18", "colored 2.1.0", @@ -2383,11 +2407,11 @@ dependencies = [ "dioxus-hot-reload", "dioxus-html", "dioxus-rsx", - "dirs 4.0.0", + "dirs", "fern", "flate2", "fs_extra", - "futures", + "futures-util", "gitignore", "headers 0.3.9", "html_parser", @@ -2406,14 +2430,13 @@ dependencies = [ "serde", "serde_json", "subprocess", - "syn 2.0.48", "tar", "tauri-bundler", - "tauri-utils", "tempfile", "thiserror", "tokio", - "toml_edit 0.19.15", + "toml 0.8.8", + "toml_edit 0.21.0", "tower", "tower-http 0.2.5", "walkdir", @@ -2425,7 +2448,7 @@ dependencies = [ name = "dioxus-cli-config" version = "0.4.1" dependencies = [ - "cargo_toml", + "cargo_toml 0.16.3", "clap 4.4.18", "once_cell", "serde", @@ -2962,22 +2985,13 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "dirs" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys 0.3.7", -] - [[package]] name = "dirs" version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys 0.4.1", + "dirs-sys", ] [[package]] @@ -2990,17 +3004,6 @@ dependencies = [ "dirs-sys-next", ] -[[package]] -name = "dirs-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "dirs-sys" version = "0.4.1" @@ -3372,7 +3375,7 @@ dependencies = [ "atomic 0.6.0", "pear", "serde", - "toml 0.8.2", + "toml 0.8.8", "uncased", "version_check", ] @@ -3943,9 +3946,9 @@ dependencies = [ [[package]] name = "gix-config" -version = "0.31.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cae98c6b4c66c09379bc35274b172587d6b0ac369a416c39128ad8c6454f9bb" +checksum = "0341471d55d8676e98b88e121d7065dfa4c9c5acea4b6d6ecdd2846e85cce0c3" dependencies = [ "bstr 1.9.0", "gix-config-value", @@ -4045,9 +4048,9 @@ dependencies = [ [[package]] name = "gix-object" -version = "0.38.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740f2a44267f58770a1cb3a3d01d14e67b089c7136c48d4bddbb3cfd2bf86a51" +checksum = "febf79c5825720c1c63fe974c7bbe695d0cb54aabad73f45671c60ce0e501e33" dependencies = [ "bstr 1.9.0", "btoi", @@ -4077,9 +4080,9 @@ dependencies = [ [[package]] name = "gix-ref" -version = "0.38.0" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ec2f6d07ac88d2fb8007ee3fa3e801856fb9d82e7366ec0ca332eb2c9d74a52" +checksum = "3b2069adc212cf7f3317ef55f6444abd06c50f28479dbbac5a86acf3b05cbbfe" dependencies = [ "gix-actor", "gix-date", @@ -4176,7 +4179,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" dependencies = [ "heck 0.4.1", - "proc-macro-crate 2.0.1", + "proc-macro-crate 2.0.0", "proc-macro-error", "proc-macro2", "quote", @@ -5892,7 +5895,7 @@ dependencies = [ "anyhow", "cargo-lock 9.0.0", "cargo_metadata 0.17.0", - "cargo_toml", + "cargo_toml 0.16.3", "image", "imagequant", "lightningcss", @@ -6019,9 +6022,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memmap2" -version = "0.7.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49388d20533534cd19360ad3d6a7dadc885944aa802ba3995040c5ec11288c6" +checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" dependencies = [ "libc", ] @@ -6605,9 +6608,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "open" -version = "4.2.0" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a083c0c7e5e4a8ec4176346cf61f67ac674e8bfb059d9226e1c54a96b377c12" +checksum = "90878fb664448b54c4e592455ad02831e23a3f7e157374a8b95654731aac7349" dependencies = [ "is-wsl", "libc", @@ -7359,11 +7362,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", "toml_edit 0.20.2", ] @@ -8504,7 +8506,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fa50756ef995d410bb1968b403a1eca169b54c3c0eb4be4bcb1da8c7591cb7d" dependencies = [ "cruet", - "proc-macro-crate 2.0.1", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "regex", @@ -9597,7 +9599,7 @@ dependencies = [ "cfg-expr 0.15.6", "heck 0.4.1", "pkg-config", - "toml 0.8.2", + "toml 0.8.8", "version-compare", ] @@ -10086,22 +10088,22 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.2" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" dependencies = [ "indexmap 2.1.0", "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.21.0", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -10124,6 +10126,17 @@ name = "toml_edit" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.1.0", + "toml_datetime", + "winnow", +] + +[[package]] +name = "toml_edit" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ "indexmap 2.1.0", "serde", diff --git a/README.md b/README.md index 6017da7cb..911522603 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ | Guide | - 中文 + 中文 | PT-BR | diff --git a/packages/cli-config/src/config.rs b/packages/cli-config/src/config.rs index 716b2bac4..bdfcf016b 100644 --- a/packages/cli-config/src/config.rs +++ b/packages/cli-config/src/config.rs @@ -338,11 +338,9 @@ pub struct WebHttpsConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CrateConfig { - pub out_dir: PathBuf, pub crate_dir: PathBuf, pub workspace_dir: PathBuf, pub target_dir: PathBuf, - pub asset_dir: PathBuf, #[cfg(feature = "cli")] pub manifest: cargo_toml::Manifest, pub executable: ExecutableType, @@ -383,12 +381,8 @@ impl CrateConfig { let workspace_dir = meta.workspace_root; let target_dir = meta.target_directory; - let out_dir = crate_dir.join(&dioxus_config.application.out_dir); - let cargo_def = &crate_dir.join("Cargo.toml"); - let asset_dir = crate_dir.join(&dioxus_config.application.asset_dir); - let manifest = cargo_toml::Manifest::from_path(cargo_def).unwrap(); let mut output_filename = String::from("dioxus_app"); @@ -414,6 +408,7 @@ impl CrateConfig { let release = false; let hot_reload = false; + let cross_origin_policy = false; let verbose = false; let custom_profile = None; let features = None; @@ -421,26 +416,38 @@ impl CrateConfig { let cargo_args = vec![]; Ok(Self { - out_dir, crate_dir, workspace_dir, target_dir, - asset_dir, #[cfg(feature = "cli")] manifest, executable, - release, dioxus_config, + release, hot_reload, - cross_origin_policy: false, + cross_origin_policy, + verbose, custom_profile, features, - verbose, target, cargo_args, }) } + /// Compose an asset directory. Represents the typical "public" directory + /// with publicly available resources (configurable in the `Dioxus.toml`). + pub fn asset_dir(&self) -> PathBuf { + self.crate_dir + .join(&self.dioxus_config.application.asset_dir) + } + + /// Compose an out directory. Represents the typical "dist" directory that + /// is "distributed" after building an application (configurable in the + /// `Dioxus.toml`). + pub fn out_dir(&self) -> PathBuf { + self.crate_dir.join(&self.dioxus_config.application.out_dir) + } + pub fn as_example(&mut self, example_name: String) -> &mut Self { self.executable = ExecutableType::Example(example_name); self diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index fdadb4381..fd8b4e2de 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -21,12 +21,13 @@ log = "0.4.14" fern = { version = "0.6.0", features = ["colored"] } serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" +toml = "0.8.8" fs_extra = "1.2.0" -cargo_toml = "0.16.0" -futures = "0.3.21" +cargo_toml = "0.18.0" +futures-util = { workspace = true } notify = { version = "5.0.0-pre.16", features = ["serde"] } html_parser = { workspace = true } -cargo_metadata = "0.15.0" +cargo_metadata = "0.18.1" tokio = { version = "1.16.1", features = ["fs", "sync", "rt", "macros"] } atty = "0.2.14" chrono = "0.4.19" @@ -44,7 +45,7 @@ headers = "0.3.7" walkdir = "2" # tools download -dirs = "4.0.0" +dirs = "5.0.1" reqwest = { version = "0.11", features = [ "rustls-tls", "stream", @@ -55,7 +56,6 @@ flate2 = "1.0.22" tar = "0.4.38" zip = "0.6.2" tower = "0.4.12" -syn = { version = "2.0", features = ["full", "extra-traits"] } lazy_static = "1.4.0" # plugin packages @@ -67,13 +67,12 @@ mlua = { version = "0.8.1", features = [ "macros", ], optional = true } ctrlc = "3.2.3" -open = "4.1.0" -cargo-generate = "0.18" -toml_edit = "0.19.11" +open = "5.0.1" +cargo-generate = "0.19.0" +toml_edit = "0.21.0" # bundling tauri-bundler = { version = "=1.4.*", features = ["native-tls-vendored"] } -tauri-utils = "=1.5.*" manganis-cli-support = { workspace = true, features = ["webp", "html"] } diff --git a/packages/cli/src/assets.rs b/packages/cli/src/assets.rs index 9248b47d5..c9fee435f 100644 --- a/packages/cli/src/assets.rs +++ b/packages/cli/src/assets.rs @@ -13,7 +13,7 @@ pub fn asset_manifest(crate_config: &CrateConfig) -> AssetManifest { /// Create a head file that contains all of the imports for assets that the user project uses pub fn create_assets_head(config: &CrateConfig, manifest: &AssetManifest) -> Result<()> { - let mut file = File::create(config.out_dir.join("__assets_head.html"))?; + let mut file = File::create(config.out_dir().join("__assets_head.html"))?; file.write_all(manifest.head().as_bytes())?; Ok(()) } @@ -29,7 +29,7 @@ pub(crate) fn process_assets(config: &CrateConfig, manifest: &AssetManifest) -> .clone() .unwrap_or_default(), ); - let static_asset_output_dir = config.out_dir.join(static_asset_output_dir); + let static_asset_output_dir = config.out_dir().join(static_asset_output_dir); manifest.copy_static_assets_to(static_asset_output_dir)?; diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 6ad009bd9..40563fccd 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -39,14 +39,14 @@ pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result Result {} Err(_e) => { log::warn!("Error copying dir: {}", _e); } } for ignore in &ignore_files { - let ignore = ignore.strip_prefix(&config.asset_dir).unwrap(); - let ignore = config.out_dir.join(ignore); + let ignore = ignore.strip_prefix(&config.asset_dir()).unwrap(); + let ignore = out_dir.join(ignore); if ignore.is_file() { std::fs::remove_file(ignore)?; } @@ -369,13 +369,13 @@ pub fn build_desktop( file_name }; - if !config.out_dir.is_dir() { - create_dir_all(&config.out_dir)?; + if !config.out_dir().is_dir() { + create_dir_all(config.out_dir())?; } - copy(res_path, config.out_dir.join(target_file))?; + copy(res_path, config.out_dir().join(target_file))?; // this code will copy all public file to the output dir - if config.asset_dir.is_dir() { + if config.asset_dir().is_dir() { let copy_options = fs_extra::dir::CopyOptions { overwrite: true, skip_exist: false, @@ -385,20 +385,20 @@ pub fn build_desktop( depth: 0, }; - for entry in std::fs::read_dir(&config.asset_dir)? { + for entry in std::fs::read_dir(config.asset_dir())? { let path = entry?.path(); if path.is_file() { - std::fs::copy(&path, &config.out_dir.join(path.file_name().unwrap()))?; + std::fs::copy(&path, &config.out_dir().join(path.file_name().unwrap()))?; } else { - match fs_extra::dir::copy(&path, &config.out_dir, ©_options) { + match fs_extra::dir::copy(&path, &config.out_dir(), ©_options) { Ok(_) => {} Err(e) => { log::warn!("Error copying dir: {}", e); } } for ignore in &ignore_files { - let ignore = ignore.strip_prefix(&config.asset_dir).unwrap(); - let ignore = config.out_dir.join(ignore); + let ignore = ignore.strip_prefix(&config.asset_dir()).unwrap(); + let ignore = config.out_dir().join(ignore); if ignore.is_file() { std::fs::remove_file(ignore)?; } @@ -443,7 +443,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { .unwrap() .tick_chars("/|\\- "), ); - pb.set_message("💼 Waiting to start build the project..."); + pb.set_message("💼 Waiting to start building the project..."); let stdout = cmd.detached().stream_stdout()?; let reader = std::io::BufReader::new(stdout); @@ -635,7 +635,7 @@ fn build_assets(config: &CrateConfig) -> Result> { if file == "*" { // if the sass open auto, we need auto-check the assets dir. - let asset_dir = config.asset_dir.clone(); + let asset_dir = config.asset_dir().clone(); if asset_dir.is_dir() { for entry in walkdir::WalkDir::new(&asset_dir) .into_iter() @@ -655,7 +655,7 @@ fn build_assets(config: &CrateConfig) -> Result> { temp.file_stem().unwrap().to_str().unwrap() ); let target_path = config - .out_dir + .out_dir() .join( temp.strip_prefix(&asset_dir) .unwrap() @@ -685,11 +685,11 @@ fn build_assets(config: &CrateConfig) -> Result> { } else { file }; - let path = config.asset_dir.join(relative_path); + let path = config.asset_dir().join(relative_path); let out_file = format!("{}.css", path.file_stem().unwrap().to_str().unwrap()); let target_path = config - .out_dir + .out_dir() .join(PathBuf::from(relative_path).parent().unwrap()) .join(out_file); if path.is_file() { @@ -719,11 +719,11 @@ fn build_assets(config: &CrateConfig) -> Result> { } else { path }; - let path = config.asset_dir.join(relative_path); + let path = config.asset_dir().join(relative_path); let out_file = format!("{}.css", path.file_stem().unwrap().to_str().unwrap()); let target_path = config - .out_dir + .out_dir() .join(PathBuf::from(relative_path).parent().unwrap()) .join(out_file); if path.is_file() { diff --git a/packages/cli/src/cli/autoformat.rs b/packages/cli/src/cli/autoformat.rs index 59405c7b9..7eb631dc6 100644 --- a/packages/cli/src/cli/autoformat.rs +++ b/packages/cli/src/cli/autoformat.rs @@ -1,5 +1,5 @@ use dioxus_autofmt::{IndentOptions, IndentType}; -use futures::{stream::FuturesUnordered, StreamExt}; +use futures_util::{stream::FuturesUnordered, StreamExt}; use std::{fs, path::Path, process::exit}; use super::*; diff --git a/packages/cli/src/cli/bundle.rs b/packages/cli/src/cli/bundle.rs index a2231b31f..1bc3a4ff6 100644 --- a/packages/cli/src/cli/bundle.rs +++ b/packages/cli/src/cli/bundle.rs @@ -87,7 +87,7 @@ impl Bundle { build_desktop(&crate_config, false, false)?; // copy the binary to the out dir - let package = crate_config.manifest.package.unwrap(); + let package = crate_config.manifest.package.as_ref().unwrap(); let mut name: PathBuf = match &crate_config.executable { ExecutableType::Binary(name) @@ -149,7 +149,7 @@ impl Bundle { } let mut settings = SettingsBuilder::new() - .project_out_directory(crate_config.out_dir) + .project_out_directory(crate_config.out_dir()) .package_settings(PackageSettings { product_name: crate_config.dioxus_config.application.name.clone(), version: package.version().to_string(), diff --git a/packages/cli/src/cli/cfg.rs b/packages/cli/src/cli/cfg.rs index 39fb5e99c..25d57e588 100644 --- a/packages/cli/src/cli/cfg.rs +++ b/packages/cli/src/cli/cfg.rs @@ -78,6 +78,7 @@ impl From for ConfigOptsBuild { } #[derive(Clone, Debug, Default, Deserialize, Parser)] +#[command(group = clap::ArgGroup::new("release-incompatible").multiple(true).conflicts_with("release"))] pub struct ConfigOptsServe { /// Port of dev server #[clap(long)] @@ -116,8 +117,9 @@ pub struct ConfigOptsServe { #[clap(long, value_enum)] pub platform: Option, - /// Build with hot reloading rsx [default: false] + /// Build with hot reloading rsx. Will not work with release builds. [default: false] #[clap(long)] + #[clap(group = "release-incompatible")] #[serde(default)] pub hot_reload: bool, diff --git a/packages/cli/src/cli/check.rs b/packages/cli/src/cli/check.rs index 0832647f2..614a0c4de 100644 --- a/packages/cli/src/cli/check.rs +++ b/packages/cli/src/cli/check.rs @@ -1,4 +1,4 @@ -use futures::{stream::FuturesUnordered, StreamExt}; +use futures_util::{stream::FuturesUnordered, StreamExt}; use std::{path::Path, process::exit}; use super::*; diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs index 4114d629a..d09dea9e4 100644 --- a/packages/cli/src/main.rs +++ b/packages/cli/src/main.rs @@ -1,7 +1,7 @@ use dioxus_cli_config::DioxusConfig; use std::path::PathBuf; -use anyhow::anyhow; +use anyhow::Context; use clap::Parser; use dioxus_cli::*; @@ -19,24 +19,26 @@ fn get_bin(bin: Option) -> Result { .workspace_packages() .into_iter() .find(|p| p.name == bin) - .ok_or(format!("no such package: {}", bin)) - .map_err(Error::CargoError)? + .ok_or(Error::CargoError(format!("no such package: {}", bin)))? } else { metadata .root_package() - .ok_or("no root package?".into()) - .map_err(Error::CargoError)? + .ok_or(Error::CargoError("no root package?".to_string()))? }; let crate_dir = package .manifest_path .parent() - .ok_or("couldn't take parent dir".into()) - .map_err(Error::CargoError)?; + .ok_or(Error::CargoError("couldn't take parent dir".to_string()))?; Ok(crate_dir.into()) } +/// Simplifies error messages that use the same pattern. +fn error_wrapper(message: &str) -> String { + format!("🚫 {message}:") +} + #[tokio::main] async fn main() -> anyhow::Result<()> { let args = Cli::parse(); @@ -46,35 +48,35 @@ async fn main() -> anyhow::Result<()> { match args.action { Translate(opts) => opts .translate() - .map_err(|e| anyhow!("🚫 Translation of HTML into RSX failed: {}", e)), + .context(error_wrapper("Translation of HTML into RSX failed")), Create(opts) => opts .create() - .map_err(|e| anyhow!("🚫 Creating new project failed: {}", e)), + .context(error_wrapper("Creating new project failed")), Init(opts) => opts .init() - .map_err(|e| anyhow!("🚫 Initialising a new project failed: {}", e)), + .context(error_wrapper("Initialising a new project failed")), Config(opts) => opts .config() - .map_err(|e| anyhow!("🚫 Configuring new project failed: {}", e)), + .context(error_wrapper("Configuring new project failed")), #[cfg(feature = "plugin")] Plugin(opts) => opts .plugin() .await - .map_err(|e| anyhow!("🚫 Error with plugin: {}", e)), + .context(error_wrapper("Error with plugin")), Autoformat(opts) => opts .autoformat() .await - .map_err(|e| anyhow!("🚫 Error autoformatting RSX: {}", e)), + .context(error_wrapper("Error autoformatting RSX")), Check(opts) => opts .check() .await - .map_err(|e| anyhow!("🚫 Error checking RSX: {}", e)), + .context(error_wrapper("Error checking RSX")), Version(opt) => { let version = opt.version(); @@ -85,33 +87,33 @@ async fn main() -> anyhow::Result<()> { action => { let bin = get_bin(args.bin)?; let _dioxus_config = DioxusConfig::load(Some(bin.clone())) - .map_err(|e| anyhow!("Failed to load Dioxus config because: {e}"))? - .unwrap_or_else(|| { - log::info!("You appear to be creating a Dioxus project from scratch; we will use the default config"); - DioxusConfig::default() - }); + .context("Failed to load Dioxus config because")? + .unwrap_or_else(|| { + log::info!("You appear to be creating a Dioxus project from scratch; we will use the default config"); + DioxusConfig::default() + }); #[cfg(feature = "plugin")] PluginManager::init(_dioxus_config.plugin) - .map_err(|e| anyhow!("🚫 Plugin system initialization failed: {e}"))?; + .context(error_wrapper("Plugin system initialization failed"))?; match action { Build(opts) => opts .build(Some(bin.clone()), None) - .map_err(|e| anyhow!("🚫 Building project failed: {}", e)), + .context(error_wrapper("Building project failed")), Clean(opts) => opts .clean(Some(bin.clone())) - .map_err(|e| anyhow!("🚫 Cleaning project failed: {}", e)), + .context(error_wrapper("Cleaning project failed")), Serve(opts) => opts .serve(Some(bin.clone())) .await - .map_err(|e| anyhow!("🚫 Serving project failed: {}", e)), + .context(error_wrapper("Serving project failed")), Bundle(opts) => opts .bundle(Some(bin.clone())) - .map_err(|e| anyhow!("🚫 Bundling project failed: {}", e)), + .context(error_wrapper("Bundling project failed")), _ => unreachable!(), } diff --git a/packages/cli/src/plugin/mod.rs b/packages/cli/src/plugin/mod.rs index 208592f61..03bf34c5f 100644 --- a/packages/cli/src/plugin/mod.rs +++ b/packages/cli/src/plugin/mod.rs @@ -181,8 +181,8 @@ impl PluginManager { let args = lua.create_table()?; args.set("name", crate_config.dioxus_config.application.name.clone())?; args.set("platform", platform)?; - args.set("out_dir", crate_config.out_dir.to_str().unwrap())?; - args.set("asset_dir", crate_config.asset_dir.to_str().unwrap())?; + args.set("out_dir", crate_config.out_dir().to_str().unwrap())?; + args.set("asset_dir", crate_config.asset_dir().to_str().unwrap())?; for i in 1..(manager.len()? as i32 + 1) { let info = manager.get::(i)?; @@ -205,8 +205,8 @@ impl PluginManager { let args = lua.create_table()?; args.set("name", crate_config.dioxus_config.application.name.clone())?; args.set("platform", platform)?; - args.set("out_dir", crate_config.out_dir.to_str().unwrap())?; - args.set("asset_dir", crate_config.asset_dir.to_str().unwrap())?; + args.set("out_dir", crate_config.out_dir().to_str().unwrap())?; + args.set("asset_dir", crate_config.asset_dir().to_str().unwrap())?; for i in 1..(manager.len()? as i32 + 1) { let info = manager.get::(i)?; diff --git a/packages/cli/src/server/desktop/mod.rs b/packages/cli/src/server/desktop/mod.rs index 4742e79ec..db8f03e1e 100644 --- a/packages/cli/src/server/desktop/mod.rs +++ b/packages/cli/src/server/desktop/mod.rs @@ -221,7 +221,7 @@ fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(RAIIChild, ExecutableType::Binary(name) | ExecutableType::Lib(name) | ExecutableType::Example(name) => { - let mut file = config.out_dir.join(name); + let mut file = config.out_dir().join(name); if cfg!(windows) { file.set_extension("exe"); } diff --git a/packages/cli/src/server/mod.rs b/packages/cli/src/server/mod.rs index bafae3486..bd1cafdd8 100644 --- a/packages/cli/src/server/mod.rs +++ b/packages/cli/src/server/mod.rs @@ -31,93 +31,103 @@ async fn setup_file_watcher Result + Send + 'static>( let mut watcher = notify::recommended_watcher(move |info: notify::Result| { let config = watcher_config.clone(); if let Ok(e) = info { - if chrono::Local::now().timestamp() > last_update_time { - let mut needs_full_rebuild; - if let Some(hot_reload) = &hot_reload { - // find changes to the rsx in the file - let mut rsx_file_map = hot_reload.file_map.lock().unwrap(); - let mut messages: Vec