Skip to content

Commit ad066d4

Browse files
committed
fix: folders
1 parent 18241db commit ad066d4

22 files changed

Lines changed: 289 additions & 156 deletions

File tree

.github/workflows/benchmark.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: actions/setup-node@v4
4242
with:
4343
node-version: latest
44-
cache: 'pnpm'
44+
cache: "pnpm"
4545

4646
- name: Install dependencies
4747
run: pnpm install

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: actions/setup-node@v4
3939
with:
4040
node-version: latest
41-
cache: 'pnpm'
41+
cache: "pnpm"
4242

4343
- name: Install dependencies
4444
run: pnpm install
@@ -66,7 +66,7 @@ jobs:
6666
uses: actions/setup-node@v4
6767
with:
6868
node-version: latest
69-
cache: 'pnpm'
69+
cache: "pnpm"
7070

7171
- name: Install dependencies
7272
run: pnpm install
@@ -94,7 +94,7 @@ jobs:
9494
uses: actions/setup-node@v4
9595
with:
9696
node-version: latest
97-
cache: 'pnpm'
97+
cache: "pnpm"
9898

9999
- name: Install dependencies
100100
run: pnpm install
@@ -126,7 +126,7 @@ jobs:
126126
uses: actions/setup-node@v4
127127
with:
128128
node-version: latest
129-
cache: 'pnpm'
129+
cache: "pnpm"
130130

131131
- name: Install dependencies
132132
run: pnpm install

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: actions/setup-node@v4
3131
with:
3232
node-version: latest
33-
cache: 'pnpm'
33+
cache: "pnpm"
3434

3535
- name: Install dependencies
3636
run: pnpm install

.vscode/extensions.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"recommendations": [
3-
"oxc.oxc-vscode",
4-
"TypeScriptTeam.native-preview",
5-
"rust-lang.rust-analyzer"
6-
]
7-
}
2+
"recommendations": ["oxc.oxc-vscode", "TypeScriptTeam.native-preview", "rust-lang.rust-analyzer"]
3+
}

.vscode/settings.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"typescript.experimental.useTsgo": true,
3-
"editor.defaultFormatter": "oxc.oxc-vscode",
4-
"oxc.typeAware": true,
5-
"oxc.fixKind": "safe_fix",
6-
"oxc.unusedDisableDirectives": "deny",
7-
"[rust]": {
8-
"editor.defaultFormatter": "rust-lang.rust-analyzer"
9-
},
10-
"editor.codeActionsOnSave": {
11-
"source.fixAll.oxc": "explicit"
12-
},
13-
"biome.enabled": false,
14-
"css.lint.unknownAtRules": "ignore",
15-
}
2+
"typescript.experimental.useTsgo": true,
3+
"editor.defaultFormatter": "oxc.oxc-vscode",
4+
"oxc.typeAware": true,
5+
"oxc.fixKind": "safe_fix",
6+
"oxc.unusedDisableDirectives": "deny",
7+
"[rust]": {
8+
"editor.defaultFormatter": "rust-lang.rust-analyzer"
9+
},
10+
"editor.codeActionsOnSave": {
11+
"source.fixAll.oxc": "explicit"
12+
},
13+
"biome.enabled": false,
14+
"css.lint.unknownAtRules": "ignore"
15+
}

crates/maudit-cli/src/dev.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ use std::{
1515
fs,
1616
path::{Path, PathBuf},
1717
};
18-
use tokio::{
19-
signal,
20-
sync::mpsc::channel,
21-
task::JoinHandle,
22-
};
18+
use tokio::{signal, sync::mpsc::channel, task::JoinHandle};
2319
use tracing::{error, info};
2420

2521
use crate::dev::build::BuildManager;
@@ -107,7 +103,6 @@ pub async fn start_dev_env(
107103

108104
match result {
109105
Ok(events) => {
110-
info!(name: "watch", "Received {} events: {:?}", events.len(), events);
111106
// TODO: Handle rescan events, I don't fully understand the implication of them yet
112107
// some issues:
113108
// - https://github.com/notify-rs/notify/issues/434
@@ -177,6 +172,10 @@ pub async fn start_dev_env(
177172
.flat_map(|e| e.paths.iter().cloned())
178173
.collect();
179174

175+
// Expand directory paths to include files inside them
176+
// This is needed because folder renames only report the folder, not contents
177+
changed_paths = expand_directory_paths(changed_paths);
178+
180179
// Deduplicate paths
181180
changed_paths.sort();
182181
changed_paths.dedup();
@@ -302,6 +301,40 @@ fn should_watch_path(path: &Path) -> bool {
302301
true
303302
}
304303

304+
/// Expand directory paths to include all files within them recursively.
305+
/// This is needed because file watcher events for folder renames only include
306+
/// the folder path, not the files inside.
307+
fn expand_directory_paths(paths: Vec<PathBuf>) -> Vec<PathBuf> {
308+
let mut expanded = Vec::new();
309+
310+
for path in paths {
311+
if path.is_dir() {
312+
// Recursively collect all files in the directory
313+
collect_files_recursive(&path, &mut expanded);
314+
// Also keep the directory itself for cases where we need to know a dir changed
315+
expanded.push(path);
316+
} else {
317+
expanded.push(path);
318+
}
319+
}
320+
321+
expanded
322+
}
323+
324+
/// Recursively collect all files in a directory.
325+
fn collect_files_recursive(dir: &Path, files: &mut Vec<PathBuf>) {
326+
if let Ok(entries) = fs::read_dir(dir) {
327+
for entry in entries.filter_map(|e| e.ok()) {
328+
let path = entry.path();
329+
if path.is_dir() {
330+
collect_files_recursive(&path, files);
331+
} else if path.is_file() {
332+
files.push(path);
333+
}
334+
}
335+
}
336+
}
337+
305338
async fn shutdown_signal() {
306339
let ctrl_c = async {
307340
signal::ctrl_c()

crates/maudit-cli/src/dev/build.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl BuildManager {
101101

102102
// Log that we're doing an incremental build
103103
info!(name: "build", "Incremental build: {} files changed", changed_paths.len());
104-
info!(name: "build", "Changed files: {:?}", changed_paths);
104+
debug!(name: "build", "Changed files: {:?}", changed_paths);
105105
info!(name: "build", "Rerunning binary without recompilation...");
106106

107107
self.state
@@ -172,7 +172,10 @@ impl BuildManager {
172172
self.internal_build(false).await
173173
}
174174

175-
async fn internal_build(&self, is_initial: bool) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
175+
async fn internal_build(
176+
&self,
177+
is_initial: bool,
178+
) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
176179
// Cancel any existing build immediately
177180
let cancel = CancellationToken::new();
178181
{
@@ -276,15 +279,20 @@ impl BuildManager {
276279
let stderr_bytes = stderr_task.await.unwrap_or_default();
277280

278281
let duration = build_start_time.elapsed();
279-
let formatted_elapsed_time = format_elapsed_time(
280-
duration,
281-
&FormatElapsedTimeOptions::default_dev(),
282-
);
282+
let formatted_elapsed_time =
283+
format_elapsed_time(duration, &FormatElapsedTimeOptions::default_dev());
283284

284285
if status.success() {
285-
let build_type = if is_initial { "Initial build" } else { "Rebuild" };
286+
let build_type = if is_initial {
287+
"Initial build"
288+
} else {
289+
"Rebuild"
290+
};
286291
info!(name: "build", "{} finished {}", build_type, formatted_elapsed_time);
287-
self.state.status_manager.update(StatusType::Success, "Build finished successfully").await;
292+
self.state
293+
.status_manager
294+
.update(StatusType::Success, "Build finished successfully")
295+
.await;
288296

289297
self.update_dependency_tracker().await;
290298

@@ -294,14 +302,27 @@ impl BuildManager {
294302
// Raw stderr sometimes has something to say whenever cargo fails
295303
println!("{}", stderr_str);
296304

297-
let build_type = if is_initial { "Initial build" } else { "Rebuild" };
305+
let build_type = if is_initial {
306+
"Initial build"
307+
} else {
308+
"Rebuild"
309+
};
298310
error!(name: "build", "{} failed with errors {}", build_type, formatted_elapsed_time);
299311

300312
if is_initial {
301313
error!(name: "build", "Initial build needs to succeed before we can start the dev server");
302-
self.state.status_manager.update(StatusType::Error, "Initial build failed - fix errors and save to retry").await;
314+
self.state
315+
.status_manager
316+
.update(
317+
StatusType::Error,
318+
"Initial build failed - fix errors and save to retry",
319+
)
320+
.await;
303321
} else {
304-
self.state.status_manager.update(StatusType::Error, &rendered_messages.join("\n")).await;
322+
self.state
323+
.status_manager
324+
.update(StatusType::Error, &rendered_messages.join("\n"))
325+
.await;
305326
}
306327

307328
Ok(false)
@@ -341,7 +362,8 @@ impl BuildManager {
341362
}
342363
}
343364

344-
fn get_binary_name_from_cargo_toml() -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
365+
fn get_binary_name_from_cargo_toml() -> Result<String, Box<dyn std::error::Error + Send + Sync>>
366+
{
345367
let cargo_toml_path = PathBuf::from("Cargo.toml");
346368
if !cargo_toml_path.exists() {
347369
return Err("Cargo.toml not found in current directory".into());

crates/maudit-cli/src/dev/server.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,7 @@ async fn ws_handler(
346346
ws.on_upgrade(move |socket| handle_socket(socket, addr, state.status_manager))
347347
}
348348

349-
async fn handle_socket(
350-
socket: WebSocket,
351-
who: SocketAddr,
352-
status_manager: StatusManager,
353-
) {
349+
async fn handle_socket(socket: WebSocket, who: SocketAddr, status_manager: StatusManager) {
354350
let (mut sender, mut receiver) = socket.split();
355351

356352
// Send current persistent status to new connection if there is one
@@ -424,7 +420,9 @@ mod tests {
424420
async fn test_status_manager_update_error_persists() {
425421
let manager = StatusManager::new();
426422

427-
manager.update(StatusType::Error, "Something went wrong").await;
423+
manager
424+
.update(StatusType::Error, "Something went wrong")
425+
.await;
428426

429427
let status = manager.get_current().await;
430428
assert!(status.is_some());
@@ -521,7 +519,9 @@ mod tests {
521519
let manager2 = manager1.clone();
522520

523521
// Update via one clone
524-
manager1.update(StatusType::Error, "Error from clone 1").await;
522+
manager1
523+
.update(StatusType::Error, "Error from clone 1")
524+
.await;
525525

526526
// Should be visible via the other clone
527527
let status = manager2.get_current().await;

crates/maudit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ oxc_sourcemap = "6.0.1"
5050
rayon = "1.11.0"
5151
rapidhash = "4.2.1"
5252
pathdiff = "0.2.3"
53-
rolldown_plugin_replace = {package = "brk_rolldown_plugin_replace", version = "0.8.0"}
53+
rolldown_plugin_replace = { package = "brk_rolldown_plugin_replace", version = "0.8.0" }
5454

5555
[dev-dependencies]
5656
tempfile = "3.24.0"

crates/maudit/src/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,8 @@ pub async fn build(
800800
let asset_path = PathBuf::from(original_file);
801801
if let Ok(canonical_asset) = asset_path.canonicalize() {
802802
for route in &all_bundler_routes {
803-
build_state.track_asset(
804-
canonical_asset.clone(),
805-
route.clone(),
806-
);
803+
build_state
804+
.track_asset(canonical_asset.clone(), route.clone());
807805
}
808806
asset_count += 1;
809807
}

0 commit comments

Comments
 (0)