diff --git a/Cargo.lock b/Cargo.lock index 1939afbe9..127de7f05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -625,7 +625,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", ] @@ -1111,7 +1111,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", @@ -1286,9 +1286,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", @@ -1320,7 +1320,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "toml 0.8.2", + "toml 0.8.8", "walkdir", ] @@ -1386,6 +1386,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" @@ -1393,7 +1407,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]] @@ -2459,8 +2483,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.15", "colored 2.1.0", @@ -2472,7 +2496,7 @@ dependencies = [ "dioxus-hot-reload", "dioxus-html", "dioxus-rsx", - "dirs 4.0.0", + "dirs", "fern", "flate2", "fs_extra", @@ -2502,8 +2526,8 @@ dependencies = [ "tempfile", "thiserror", "tokio", - "toml 0.5.11", - "toml_edit 0.19.15", + "toml 0.8.8", + "toml_edit 0.21.0", "tower", "tower-http 0.2.5", "walkdir", @@ -2515,7 +2539,7 @@ dependencies = [ name = "dioxus-cli-config" version = "0.4.1" dependencies = [ - "cargo_toml", + "cargo_toml 0.16.3", "clap 4.4.15", "once_cell", "serde", @@ -3055,22 +3079,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]] @@ -3083,17 +3098,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" @@ -3562,7 +3566,7 @@ dependencies = [ "atomic 0.6.0", "pear", "serde", - "toml 0.8.2", + "toml 0.8.8", "uncased", "version_check", ] @@ -4142,9 +4146,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", @@ -4244,9 +4248,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", @@ -4276,9 +4280,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", @@ -4375,7 +4379,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", @@ -5081,7 +5085,7 @@ dependencies = [ "httpdate", "itoa 1.0.10", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -6147,7 +6151,7 @@ dependencies = [ "anyhow", "cargo-lock 9.0.0", "cargo_metadata 0.17.0", - "cargo_toml", + "cargo_toml 0.16.3", "image", "imagequant", "lightningcss", @@ -6274,9 +6278,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memmap2" -version = "0.7.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49388d20533534cd19360ad3d6a7dadc885944aa802ba3995040c5ec11288c6" +checksum = "45fd3a57831bf88bc63f8cebc0cf956116276e97fef3966103e96416209f7c92" dependencies = [ "libc", ] @@ -6900,9 +6904,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", @@ -7776,11 +7780,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", ] @@ -8950,7 +8953,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", @@ -10127,7 +10130,7 @@ dependencies = [ "cfg-expr 0.15.6", "heck 0.4.1", "pkg-config", - "toml 0.8.2", + "toml 0.8.8", "version-compare", ] @@ -10616,22 +10619,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", ] @@ -10654,6 +10657,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/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index 8f0c0dc8a..76b4995b1 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -21,13 +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.5.8" +toml = "0.8.8" fs_extra = "1.2.0" -cargo_toml = "0.16.0" +cargo_toml = "0.18.0" futures = "0.3.21" 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" @@ -45,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", @@ -68,9 +68,9 @@ 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"] } diff --git a/packages/cli/src/server/mod.rs b/packages/cli/src/server/mod.rs index 1fe5f2ea5..0158f5c35 100644 --- a/packages/cli/src/server/mod.rs +++ b/packages/cli/src/server/mod.rs @@ -31,93 +31,102 @@ 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> = Vec::new(); + match e.kind { + notify::EventKind::Create(_) | notify::EventKind::Remove(_) | notify::EventKind::Modify(_) => { - // In hot reload mode, we only need to rebuild if non-rsx code is changed - needs_full_rebuild = false; + 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> = Vec::new(); - for path in &e.paths { - // if this is not a rust file, rebuild the whole project - if path.extension().and_then(|p| p.to_str()) != Some("rs") { + // In hot reload mode, we only need to rebuild if non-rsx code is changed + needs_full_rebuild = false; + + for path in &e.paths { + // if this is not a rust file, rebuild the whole project + if path.extension().and_then(|p| p.to_str()) != Some("rs") { + needs_full_rebuild = true; + break; + } + + // Workaround for notify and vscode-like editor: + // when edit & save a file in vscode, there will be two notifications, + // the first one is a file with empty content. + // filter the empty file notification to avoid false rebuild during hot-reload + if let Ok(metadata) = fs::metadata(path) { + if metadata.len() == 0 { + continue; + } + } + + match rsx_file_map.update_rsx(path, &config.crate_dir) { + Ok(UpdateResult::UpdatedRsx(msgs)) => { + messages.extend(msgs); + needs_full_rebuild = false; + } + Ok(UpdateResult::NeedsRebuild) => { + needs_full_rebuild = true; + } + Err(err) => { + log::error!("{}", err); + } + } + } + + if needs_full_rebuild { + // Reset the file map to the new state of the project + let FileMapBuildResult { + map: new_file_map, + errors, + } = FileMap::::create(config.crate_dir.clone()).unwrap(); + + for err in errors { + log::error!("{}", err); + } + + *rsx_file_map = new_file_map; + } else { + for msg in messages { + let _ = hot_reload.messages.send(msg); + } + } + } else { needs_full_rebuild = true; - break; } - // Workaround for notify and vscode-like editor: - // when edit & save a file in vscode, there will be two notifications, - // the first one is a file with empty content. - // filter the empty file notification to avoid false rebuild during hot-reload - if let Ok(metadata) = fs::metadata(path) { - if metadata.len() == 0 { - continue; - } - } + if needs_full_rebuild { + match build_with() { + Ok(res) => { + last_update_time = chrono::Local::now().timestamp(); - match rsx_file_map.update_rsx(path, &config.crate_dir) { - Ok(UpdateResult::UpdatedRsx(msgs)) => { - messages.extend(msgs); - needs_full_rebuild = false; - } - Ok(UpdateResult::NeedsRebuild) => { - needs_full_rebuild = true; - } - Err(err) => { - log::error!("{}", err); - } - } - } + #[allow(clippy::redundant_clone)] + print_console_info( + &config, + PrettierOptions { + changed: e.paths.clone(), + warnings: res.warnings, + elapsed_time: res.elapsed_time, + }, + web_info.clone(), + ); - if needs_full_rebuild { - // Reset the file map to the new state of the project - let FileMapBuildResult { - map: new_file_map, - errors, - } = FileMap::::create(config.crate_dir.clone()).unwrap(); - - for err in errors { - log::error!("{}", err); - } - - *rsx_file_map = new_file_map; - } else { - for msg in messages { - let _ = hot_reload.messages.send(msg); - } - } - } else { - needs_full_rebuild = true; - } - - if needs_full_rebuild { - match build_with() { - Ok(res) => { - last_update_time = chrono::Local::now().timestamp(); - - #[allow(clippy::redundant_clone)] - print_console_info( - &config, - PrettierOptions { - changed: e.paths.clone(), - warnings: res.warnings, - elapsed_time: res.elapsed_time, + #[cfg(feature = "plugin")] + let _ = PluginManager::on_serve_rebuild( + chrono::Local::now().timestamp(), + e.paths, + ); + } + Err(e) => { + last_update_time = chrono::Local::now().timestamp(); + log::error!("{:?}", e); }, - web_info.clone(), - ); - - #[cfg(feature = "plugin")] - let _ = PluginManager::on_serve_rebuild( - chrono::Local::now().timestamp(), - e.paths, - ); + } } - Err(e) => log::error!("{}", e), } - } + }, + _ => {}, } } })