瀏覽代碼

Merge pull request #1877 from mrxiaozhuox/master

CLI: Fixed repeat build error info and upgrade some crates
ealmloff 1 年之前
父節點
當前提交
fa933e35ab
共有 3 個文件被更改,包括 156 次插入132 次删除
  1. 60 46
      Cargo.lock
  2. 7 7
      packages/cli/Cargo.toml
  3. 89 79
      packages/cli/src/server/mod.rs

+ 60 - 46
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",
@@ -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",
@@ -2500,8 +2524,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",
@@ -2513,7 +2537,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",
@@ -3053,22 +3077,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]]
@@ -3081,17 +3096,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"
@@ -3560,7 +3564,7 @@ dependencies = [
  "atomic 0.6.0",
  "pear",
  "serde",
- "toml 0.8.2",
+ "toml 0.8.8",
  "uncased",
  "version_check",
 ]
@@ -4373,7 +4377,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",
@@ -6145,7 +6149,7 @@ dependencies = [
  "anyhow",
  "cargo-lock 9.0.0",
  "cargo_metadata 0.17.0",
- "cargo_toml",
+ "cargo_toml 0.16.3",
  "image",
  "imagequant",
  "lightningcss",
@@ -6898,9 +6902,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",
@@ -7774,11 +7778,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",
 ]
 
@@ -8948,7 +8951,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",
@@ -10125,7 +10128,7 @@ dependencies = [
  "cfg-expr 0.15.6",
  "heck 0.4.1",
  "pkg-config",
- "toml 0.8.2",
+ "toml 0.8.8",
  "version-compare",
 ]
 
@@ -10614,22 +10617,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",
 ]
@@ -10652,6 +10655,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",

+ 7 - 7
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-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"
@@ -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",
@@ -67,9 +67,9 @@ mlua = { version = "0.8.1", features = [
     "macros",
 ], optional = true }
 ctrlc = "3.2.3"
-open = "4.1.0"
-cargo-generate = "0.19"
-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"] }

+ 89 - 79
packages/cli/src/server/mod.rs

@@ -31,93 +31,103 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
     let mut watcher = notify::recommended_watcher(move |info: notify::Result<notify::Event>| {
         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<Template<'static>> = Vec::new();
-
-                    // 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 e.kind {
+                notify::EventKind::Create(_)
+                | notify::EventKind::Remove(_)
+                | notify::EventKind::Modify(_) => {
+                    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<Template<'static>> = Vec::new();
+
+                            // 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);
+                                    }
+                                }
                             }
-                        }
 
-                        match rsx_file_map.update_rsx(path, &config.crate_dir) {
-                            Ok(UpdateResult::UpdatedRsx(msgs)) => {
-                                messages.extend(msgs);
-                                needs_full_rebuild = false;
+                            if needs_full_rebuild {
+                                // Reset the file map to the new state of the project
+                                let FileMapBuildResult {
+                                    map: new_file_map,
+                                    errors,
+                                } = FileMap::<HtmlCtx>::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);
+                                }
                             }
-                            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::<HtmlCtx>::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;
                         }
-                    }
-                } 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,
-                                },
-                                web_info.clone(),
-                            );
-
-                            #[cfg(feature = "plugin")]
-                            let _ = PluginManager::on_serve_rebuild(
-                                chrono::Local::now().timestamp(),
-                                e.paths,
-                            );
+                        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,
+                                        },
+                                        web_info.clone(),
+                                    );
+
+                                    #[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);
+                                }
+                            }
                         }
-                        Err(e) => log::error!("{}", e),
                     }
                 }
+                _ => {}
             }
         }
     })