Rust library to generate static websites

fix: fix

+34 -47
+1 -8
Cargo.lock
··· 1662 1662 checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" 1663 1663 1664 1664 [[package]] 1665 - name = "fixtures-hot-reload" 1666 - version = "0.1.0" 1667 - dependencies = [ 1668 - "maud", 1669 - "maudit", 1670 - ] 1671 - 1672 - [[package]] 1673 1665 name = "fixtures-prefetch-prerender" 1674 1666 version = "0.1.0" 1675 1667 dependencies = [ ··· 2622 2614 "serde_json", 2623 2615 "spinach", 2624 2616 "tar", 2617 + "tempfile", 2625 2618 "tokio", 2626 2619 "tokio-util", 2627 2620 "toml",
+3
crates/maudit-cli/Cargo.toml
··· 35 35 serde_json = "1.0" 36 36 tokio-util = "0.7" 37 37 cargo_metadata = "0.23.1" 38 + 39 + [dev-dependencies] 40 + tempfile = "3.24.0"
+25 -31
crates/maudit-cli/src/dev/build.rs
··· 46 46 /// Returns true if recompilation is needed, false if we can just rerun the binary 47 47 pub async fn needs_recompile(&self, changed_paths: &[PathBuf]) -> bool { 48 48 let dep_tracker = self.dep_tracker.read().await; 49 - 50 - if let Some(tracker) = dep_tracker.as_ref() { 51 - if tracker.has_dependencies() { 52 - let needs_recompile = tracker.needs_recompile(changed_paths); 53 - if !needs_recompile { 54 - debug!(name: "build", "Changed files are not dependencies, rerun binary without recompile"); 55 - } 56 - return needs_recompile; 49 + 50 + if let Some(tracker) = dep_tracker.as_ref() 51 + && tracker.has_dependencies() 52 + { 53 + let needs_recompile = tracker.needs_recompile(changed_paths); 54 + if !needs_recompile { 55 + debug!(name: "build", "Changed files are not dependencies, rerun binary without recompile"); 57 56 } 57 + return needs_recompile; 58 58 } 59 - 59 + 60 60 // If we don't have a dependency tracker yet, always recompile 61 61 true 62 62 } ··· 64 64 /// Rerun the binary without recompiling 65 65 pub async fn rerun_binary(&self) -> Result<bool, Box<dyn std::error::Error>> { 66 66 let binary_path = self.binary_path.read().await; 67 - 67 + 68 68 let Some(path) = binary_path.as_ref() else { 69 69 warn!(name: "build", "No binary path available, falling back to full rebuild"); 70 70 return self.start_build().await; ··· 76 76 } 77 77 78 78 info!(name: "build", "Rerunning binary without recompilation..."); 79 - 79 + 80 80 // Notify that build is starting (even though we're just rerunning) 81 81 update_status( 82 82 &self.websocket_tx, ··· 87 87 .await; 88 88 89 89 let build_start_time = Instant::now(); 90 - 90 + 91 91 let child = Command::new(path) 92 - .envs([ 93 - ("MAUDIT_DEV", "true"), 94 - ("MAUDIT_QUIET", "true"), 95 - ]) 92 + .envs([("MAUDIT_DEV", "true"), ("MAUDIT_QUIET", "true")]) 96 93 .stdout(std::process::Stdio::piped()) 97 94 .stderr(std::process::Stdio::piped()) 98 95 .spawn()?; 99 96 100 97 // Wait for the process to complete 101 98 let output = child.wait_with_output().await?; 102 - 99 + 103 100 let duration = build_start_time.elapsed(); 104 - let formatted_elapsed_time = format_elapsed_time( 105 - duration, 106 - &FormatElapsedTimeOptions::default_dev(), 107 - ); 101 + let formatted_elapsed_time = 102 + format_elapsed_time(duration, &FormatElapsedTimeOptions::default_dev()); 108 103 109 104 if output.status.success() { 110 105 info!(name: "build", "Binary rerun finished {}", formatted_elapsed_time); ··· 119 114 } else { 120 115 let stderr = String::from_utf8_lossy(&output.stderr).to_string(); 121 116 let stdout = String::from_utf8_lossy(&output.stdout).to_string(); 122 - error!(name: "build", "Binary rerun failed {}\nstdout: {}\nstderr: {}", 117 + error!(name: "build", "Binary rerun failed {}\nstdout: {}\nstderr: {}", 123 118 formatted_elapsed_time, stdout, stderr); 124 119 update_status( 125 120 &self.websocket_tx, ··· 282 277 let build_type = if is_initial { "Initial build" } else { "Rebuild" }; 283 278 info!(name: "build", "{} finished {}", build_type, formatted_elapsed_time); 284 279 update_status(&websocket_tx, current_status.clone(), StatusType::Success, "Build finished successfully").await; 285 - 280 + 286 281 // Update dependency tracker after successful build 287 282 Self::update_dependency_tracker_after_build(dep_tracker_clone.clone(), binary_path_clone.clone()).await; 288 - 283 + 289 284 true 290 285 } else { 291 286 let stderr = String::from_utf8_lossy(&output.stderr).to_string(); ··· 380 375 .and_then(|n| n.as_str()) 381 376 { 382 377 // Check if there's a [[bin]] section with a different name 383 - if let Some(bins) = cargo_toml.get("bin").and_then(|b| b.as_array()) { 384 - if let Some(first_bin) = bins.first() { 385 - if let Some(bin_name) = first_bin.get("name").and_then(|n| n.as_str()) { 386 - return Ok(bin_name.to_string()); 387 - } 388 - } 378 + if let Some(bins) = cargo_toml.get("bin").and_then(|b| b.as_array()) 379 + && let Some(first_bin) = bins.first() 380 + && let Some(bin_name) = first_bin.get("name").and_then(|n| n.as_str()) 381 + { 382 + return Ok(bin_name.to_string()); 389 383 } 390 - 384 + 391 385 // No explicit bin name, use package name 392 386 return Ok(package_name.to_string()); 393 387 }
+5 -8
crates/maudit-cli/src/dev/dep_tracker.rs
··· 55 55 let mut current = std::env::current_dir()?; 56 56 loop { 57 57 let cargo_toml = current.join("Cargo.toml"); 58 - if cargo_toml.exists() { 59 - if let Ok(content) = fs::read_to_string(&cargo_toml) { 60 - if content.contains("[workspace]") { 58 + if cargo_toml.exists() 59 + && let Ok(content) = fs::read_to_string(&cargo_toml) 60 + && content.contains("[workspace]") { 61 61 let workspace_target = current.join("target").join("debug"); 62 62 if workspace_target.exists() { 63 63 debug!("Using workspace target directory: {:?}", workspace_target); 64 64 return Ok(workspace_target); 65 65 } 66 66 } 67 - } 68 - } 69 67 70 68 // Move up to parent directory 71 69 if !current.pop() { ··· 181 179 if matches { 182 180 // Check if the file was modified after we last tracked it 183 181 if let Ok(metadata) = fs::metadata(changed_path) { 184 - if let Ok(current_modified) = metadata.modified() { 185 - if current_modified > *last_modified { 182 + if let Ok(current_modified) = metadata.modified() 183 + && current_modified > *last_modified { 186 184 debug!( 187 185 "Dependency {:?} was modified, recompile needed", 188 186 changed_path 189 187 ); 190 188 return true; 191 189 } 192 - } 193 190 } else { 194 191 // File was deleted or can't be read, assume recompile is needed 195 192 debug!(