euv-cli 0.51.0

Cross-platform CLI tool for the euv native UI framework supporting run, build, check, fmt, doctor, new, and Hyperlane SSE dynamic updates across all supported platforms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
use super::*;

/// Default dev server configuration targeting local Web development with OTA enabled.
impl Default for DevServerConfig {
    /// Returns a sensible default `DevServerConfig` bound to `127.0.0.1:8080`.
    ///
    /// # Returns
    ///
    /// - `Self` - Default development server configuration.
    fn default() -> Self {
        Self {
            target: DevTargetArg::Web,
            render: RenderArg::Auto,
            release: false,
            src_dir: PathBuf::from("."),
            out_dir: PathBuf::from(OUT_DIR_WEB),
            title: None,
            base_url: String::new(),
            package: None,
            host: DEFAULT_DEV_HOST.to_string(),
            port: 8080,
            poll_ms: 250,
            enable_ota: true,
            once: false,
            hot_ota: false,
            watch_ota_path: None,
            ota_store_dir: None,
            ota_project: DEFAULT_DEV_OTA_PROJECT.to_string(),
            ota_channel: DEFAULT_DEV_OTA_CHANNEL.to_string(),
            ota_signing_key: OTA_DEV_SIGNING_KEY.to_string(),
            ota_route: None,
            ota_slot: None,
            debounce_ms: DEFAULT_DEV_DEBOUNCE_MS,
            coop_coep: false,
            spa_fallback: true,
        }
    }
}

/// Change-set inspection helpers for `FileChangeSet`.
impl FileChangeSet {
    /// Returns `true` when no files were added, modified, or removed.
    ///
    /// # Arguments
    ///
    /// - `&Self` - File change set reference.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether the change set is empty.
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.get_added().is_empty()
            && self.get_modified().is_empty()
            && self.get_removed().is_empty()
    }

    /// Returns a flattened list of every added, modified, and removed file path.
    ///
    /// # Arguments
    ///
    /// - `&Self` - File change set reference.
    ///
    /// # Returns
    ///
    /// - `Vec<String>` - Combined changed path list.
    #[must_use]
    pub fn all_paths(&self) -> Vec<String> {
        let mut out: Vec<String> = Vec::with_capacity(
            self.get_added().len() + self.get_modified().len() + self.get_removed().len(),
        );
        out.extend(self.get_added().iter().cloned());
        out.extend(self.get_modified().iter().cloned());
        out.extend(self.get_removed().iter().cloned());
        out
    }

    /// Merges another `FileChangeSet` into `self`, deduplicating paths cleanly.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Destination accumulator change set.
    /// - `Self` - Newly detected file changes to merge.
    pub fn merge(&mut self, other: Self) {
        let Self {
            added,
            modified,
            removed,
        } = self;
        for path in other.get_added().iter() {
            if !added.contains(path) {
                added.push(path.clone());
            }
        }
        for path in other.get_modified().iter() {
            if !modified.contains(path) {
                modified.push(path.clone());
            }
        }
        for path in other.get_removed().iter() {
            if !removed.contains(path) {
                removed.push(path.clone());
            }
        }
    }
}

/// Coalescing debounce window operations on `DebouncedWatcher`.
impl DebouncedWatcher {
    /// Creates a new `DebouncedWatcher` with a quiet window of `debounce_ms` milliseconds.
    ///
    /// # Arguments
    ///
    /// - `u64` - Quiet debounce interval in milliseconds (`0` flushes immediately).
    ///
    /// # Returns
    ///
    /// - `Self` - Empty debounced watcher.
    #[must_use]
    pub fn new(debounce_ms: u64) -> Self {
        Self {
            debounce_ms,
            pending: FileChangeSet::default(),
            last_change_at: None,
        }
    }

    /// Records newly detected filesystem changes and restarts the debounce quiet timer.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Debounced watcher state.
    /// - `FileChangeSet` - Newly detected file change set.
    /// - `Instant` - Monotonic timestamp when the change was observed.
    pub fn record_changes(&mut self, changes: FileChangeSet, now: Instant) {
        if changes.is_empty() {
            return;
        }
        let Self {
            pending,
            last_change_at,
            ..
        } = self;
        pending.merge(changes);
        *last_change_at = Some(now);
    }

    /// Returns `true` when one or more file changes are queued awaiting the debounce window.
    ///
    /// # Returns
    ///
    /// - `bool` - Whether pending changes exist.
    #[must_use]
    pub fn has_pending(&self) -> bool {
        !self.get_pending().is_empty()
    }

    /// Flushes and returns accumulated changes once the debounce quiet window has elapsed.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Debounced watcher state.
    /// - `Instant` - Current monotonic timestamp.
    ///
    /// # Returns
    ///
    /// - `Option<FileChangeSet>` - Coalesced change set if ready to rebuild.
    pub fn flush_ready(&mut self, now: Instant) -> Option<FileChangeSet> {
        let Self {
            debounce_ms,
            pending,
            last_change_at,
        } = self;
        let last_seen: Instant = (*last_change_at)?;
        if pending.is_empty() {
            *last_change_at = None;
            return None;
        }
        let elapsed_ms: u128 = now.saturating_duration_since(last_seen).as_millis();
        if elapsed_ms < u128::from(*debounce_ms) {
            return None;
        }
        *last_change_at = None;
        Some(take(pending))
    }
}

/// Zero-flicker build-before-swap coordination for native app hot restarts.
impl BuildBeforeSwapController {
    /// Records an initial launched process generation.
    pub fn mark_initial_launched(&mut self) {
        let next_gen: u64 = self.get_active_generation().saturating_add(1);
        let _: &mut Self = self.set_active_generation(next_gen).set_last_error(None);
    }

    /// Compiles FIRST via `build_fn`; only invokes `stop_old_fn` and `spawn_new_fn` when compilation succeeds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Swap controller state.
    /// - `BuildFn` - Build step executed while the existing process remains running.
    /// - `StopFn` - Shutdown hook terminating the previous running process.
    /// - `SpawnFn` - Launch hook starting the newly compiled binary.
    ///
    /// # Returns
    ///
    /// - `SwapOutcome` - `Swapped` / `LaunchedInitial` on success, or `KeptRunningOnError` when the old app stayed alive.
    pub fn apply_rebuild<BuildFn, StopFn, SpawnFn>(
        &mut self,
        build_fn: BuildFn,
        stop_old_fn: StopFn,
        spawn_new_fn: SpawnFn,
    ) -> SwapOutcome
    where
        BuildFn: FnOnce() -> io::Result<()>,
        StopFn: FnOnce(),
        SpawnFn: FnOnce() -> io::Result<()>,
    {
        if let Err(err) = build_fn() {
            let err_msg: String = err.to_string();
            let kept: u64 = self.get_kept_alive_on_error_count().saturating_add(1);
            let _: &mut Self = self
                .set_kept_alive_on_error_count(kept)
                .set_last_error(Some(err_msg.clone()));
            return SwapOutcome::KeptRunningOnError(err_msg);
        }
        let had_active: bool = self.get_active_generation() > 0;
        if had_active {
            stop_old_fn();
        }
        if let Err(err) = spawn_new_fn() {
            let err_msg: String = err.to_string();
            let _: &mut Self = self.set_last_error(Some(err_msg.clone()));
            return SwapOutcome::KeptRunningOnError(err_msg);
        }
        let next_gen: u64 = self.get_active_generation().saturating_add(1);
        let _: &mut Self = self.set_active_generation(next_gen).set_last_error(None);
        if had_active {
            let next_swaps: u64 = self.get_swap_count().saturating_add(1);
            let _: &mut Self = self.set_swap_count(next_swaps);
            SwapOutcome::Swapped
        } else {
            SwapOutcome::LaunchedInitial
        }
    }
}

/// Safe lifecycle management for spawned child processes preventing orphan leaks.
impl ChildProcessGuard {
    /// Terminates any existing child process and takes ownership of `next`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Guard owning the current child.
    /// - `Child` - Newly spawned child process.
    pub(crate) fn replace(&mut self, next: Child) {
        self.terminate();
        let Self { child } = self;
        *child = Some(next);
    }

    /// Terminates and reaps the managed child process if currently running.
    pub(crate) fn terminate(&mut self) {
        let Self { child } = self;
        if let Some(mut running) = child.take() {
            drop(running.kill());
            drop(running.wait());
        }
    }
}

/// Guarantees zero orphan child processes when `ChildProcessGuard` goes out of scope.
impl Drop for ChildProcessGuard {
    /// Terminates and reaps the active child process on drop.
    fn drop(&mut self) {
        self.terminate();
    }
}

/// Recursive directory scanning and deterministic diffing for `WatchSnapshot`.
impl WatchSnapshot {
    /// Scans `root` recursively collecting modification stamps for files matching `allowed_exts`.
    ///
    /// # Arguments
    ///
    /// - `&Path` - Root project or documentation directory.
    /// - `&[&str]` - Allowed lowercase file extensions (for example `["md", "rs"]`).
    ///
    /// # Returns
    ///
    /// - `io::Result<Self>` - Collected directory snapshot or I/O error.
    pub fn scan(root: &Path, allowed_exts: &[&str]) -> io::Result<Self> {
        Self::scan_excluding(root, allowed_exts, None)
    }

    /// Scans `root` recursively while excluding `exclude_dir` so generated outputs never self-trigger rebuilds.
    ///
    /// # Arguments
    ///
    /// - `&Path` - Root project or documentation directory.
    /// - `&[&str]` - Allowed lowercase file extensions.
    /// - `Option<&Path>` - Optional output directory excluded from watching.
    ///
    /// # Returns
    ///
    /// - `io::Result<Self>` - Collected directory snapshot or I/O error.
    pub fn scan_excluding(
        root: &Path,
        allowed_exts: &[&str],
        exclude_dir: Option<&Path>,
    ) -> io::Result<Self> {
        let mut entries: BTreeMap<PathBuf, FileStamp> = BTreeMap::new();
        if !root.exists() {
            return Ok(Self { entries });
        }
        let Some(ex) = exclude_dir else {
            scan_dir_stamps(root, allowed_exts, None, None, false, &mut entries)?;
            return Ok(Self { entries });
        };
        let (canonical_exclude, exclude_is_canon): (PathBuf, bool) = match fs::canonicalize(ex) {
            Ok(canon) => (canon, true),
            Err(_) => (ex.to_path_buf(), false),
        };
        let canonical_root: Option<PathBuf> = if exclude_is_canon {
            fs::canonicalize(root).ok()
        } else {
            None
        };
        let (canon_dir, check_real_exclude): (Option<&Path>, bool) =
            if let Some(cr) = canonical_root.as_deref() {
                if canonical_exclude.starts_with(cr) || cr.starts_with(&canonical_exclude) {
                    (Some(cr), true)
                } else {
                    (None, false)
                }
            } else {
                (None, true)
            };
        scan_dir_stamps(
            root,
            allowed_exts,
            Some(canonical_exclude.as_path()),
            canon_dir,
            check_real_exclude,
            &mut entries,
        )?;
        Ok(Self { entries })
    }

    /// Computes added, modified, and removed paths comparing `self` (previous) against `next`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Previous snapshot.
    /// - `&Self` - Freshly scanned snapshot.
    ///
    /// # Returns
    ///
    /// - `FileChangeSet` - Categorized file differences.
    #[must_use]
    pub fn diff(&self, next: &Self) -> FileChangeSet {
        let mut added: Vec<String> = Vec::new();
        let mut modified: Vec<String> = Vec::new();
        let mut removed: Vec<String> = Vec::new();
        let mut prev_iter: Peekable<btree_map::Iter<'_, PathBuf, FileStamp>> =
            self.get_entries().iter().peekable();
        let mut next_iter: Peekable<btree_map::Iter<'_, PathBuf, FileStamp>> =
            next.get_entries().iter().peekable();
        while let (Some(&(prev_path, prev_stamp)), Some(&(next_path, next_stamp))) =
            (prev_iter.peek(), next_iter.peek())
        {
            match prev_path.cmp(next_path) {
                cmp::Ordering::Less => {
                    removed.push(prev_path.display().to_string());
                    let _: Option<(&PathBuf, &FileStamp)> = prev_iter.next();
                }
                cmp::Ordering::Greater => {
                    added.push(next_path.display().to_string());
                    let _: Option<(&PathBuf, &FileStamp)> = next_iter.next();
                }
                cmp::Ordering::Equal => {
                    if prev_stamp != next_stamp {
                        modified.push(next_path.display().to_string());
                    }
                    let _: Option<(&PathBuf, &FileStamp)> = prev_iter.next();
                    let _: Option<(&PathBuf, &FileStamp)> = next_iter.next();
                }
            }
        }
        for (prev_path, _) in prev_iter {
            removed.push(prev_path.display().to_string());
        }
        for (next_path, _) in next_iter {
            added.push(next_path.display().to_string());
        }
        FileChangeSet::new(added, modified, removed)
    }
}

/// Thread-safe HMR broadcast and OTA bundle coordination for `HmrHub`.
impl HmrHub {
    /// Creates a new `HmrHub` initialized at revision `1` with `initial_ota`.
    ///
    /// # Arguments
    ///
    /// - `OtaBundleState` - Initial signed Dynamic WASM OTA artifact.
    ///
    /// # Returns
    ///
    /// - `Self` - Initialized hub ready for concurrent access.
    #[must_use]
    pub fn new(initial_ota: OtaBundleState) -> Self {
        Self {
            revision: AtomicU64::new(1),
            last_event: Mutex::new(Some(HmrEvent::new(
                1,
                HmrEventKind::Reload,
                MSG_INITIAL_BUILD_READY.to_string(),
                Vec::new(),
            ))),
            ota_state: Mutex::new(initial_ota),
            running: AtomicBool::new(true),
        }
    }

    /// Returns the current monotonic rebuild revision counter.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    ///
    /// # Returns
    ///
    /// - `u64` - Current revision number.
    #[must_use]
    pub fn revision(&self) -> u64 {
        let Self { revision, .. } = self;
        revision.load(Ordering::Acquire)
    }

    /// Increments the revision counter and publishes a new `HmrEvent` to all SSE subscribers.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    /// - `HmrEventKind` - Event variant (`Reload`, `OtaUpdate`, or `BuildError`).
    /// - `String` - Human-readable event description.
    /// - `Vec<String>` - List of changed source paths.
    ///
    /// # Returns
    ///
    /// - `u64` - Newly assigned revision number.
    pub fn publish(&self, kind: HmrEventKind, message: String, changed_files: Vec<String>) -> u64 {
        let Self {
            revision,
            last_event,
            ..
        } = self;
        let next_rev: u64 = revision.fetch_add(1, Ordering::AcqRel) + 1;
        let ui_event: HmrEvent = HmrEvent::new(next_rev, kind, message, changed_files);
        if let Ok(mut guard) = last_event.lock() {
            *guard = Some(ui_event);
        }
        next_rev
    }

    /// Replaces the active signed Dynamic WASM OTA bundle served over HTTP.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    /// - `OtaBundleState` - Freshly compiled and signed OTA artifact.
    pub fn set_ota_state(&self, next_state: OtaBundleState) {
        let Self { ota_state, .. } = self;
        if let Ok(mut guard) = ota_state.lock() {
            *guard = next_state;
        }
    }

    /// Returns a cloned copy of the latest published `HmrEvent`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    ///
    /// # Returns
    ///
    /// - `Option<HmrEvent>` - Latest event snapshot.
    #[must_use]
    pub fn current_event(&self) -> Option<HmrEvent> {
        let Self { last_event, .. } = self;
        last_event
            .lock()
            .ok()
            .and_then(|event_guard: MutexGuard<'_, Option<HmrEvent>>| event_guard.clone())
    }

    /// Returns a cloned snapshot of the active OTA manifest and `.wasm` bytes.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    ///
    /// # Returns
    ///
    /// - `Option<OtaBundleState>` - Active OTA artifact if lock is unpoisoned.
    #[must_use]
    pub fn ota_snapshot(&self) -> Option<OtaBundleState> {
        let Self { ota_state, .. } = self;
        ota_state
            .lock()
            .ok()
            .map(|ota_guard: MutexGuard<'_, OtaBundleState>| ota_guard.clone())
    }

    /// Signals all background HTTP and watcher threads to exit cleanly.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    pub fn stop(&self) {
        let Self { running, .. } = self;
        running.store(false, Ordering::Release);
    }

    /// Returns `true` while the dev server has not been shut down.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Hub reference.
    ///
    /// # Returns
    ///
    /// - `bool` - Running state flag.
    #[must_use]
    pub fn is_running(&self) -> bool {
        let Self { running, .. } = self;
        running.load(Ordering::Acquire)
    }
}

/// Runtime inspection and graceful shutdown operations for `DevServerHandle`.
impl DevServerHandle {
    /// Returns the bound local TCP socket address (`ip:port`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Server handle reference.
    ///
    /// # Returns
    ///
    /// - `SocketAddr` - Bound address.
    #[must_use]
    pub fn address(&self) -> SocketAddr {
        let Self { address, .. } = self;
        *address
    }

    /// Returns the base HTTP URL for this running dev server.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Server handle reference.
    ///
    /// # Returns
    ///
    /// - `String` - Formatted `http://<ip>:<port>` URL.
    #[must_use]
    pub fn url(&self) -> String {
        format!("http://{}", self.address())
    }

    /// Returns the current live rebuild revision counter.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Server handle reference.
    ///
    /// # Returns
    ///
    /// - `u64` - Active revision number.
    #[must_use]
    pub fn revision(&self) -> u64 {
        let Self { hub, .. } = self;
        hub.revision()
    }

    /// Returns a reference to the mounted v1 OTA `UpdateStore`.
    ///
    /// # Returns
    ///
    /// - `&UpdateStore` - Backing v1 OTA store reference.
    #[must_use]
    pub fn ota_store(&self) -> &UpdateStore {
        let Self { ota_store, .. } = self;
        ota_store
    }

    /// Returns a reference to the shared `HmrHub`.
    ///
    /// # Returns
    ///
    /// - `&Arc<HmrHub>` - Shared HMR hub handle.
    #[must_use]
    pub fn hub(&self) -> &Arc<HmrHub> {
        let Self { hub, .. } = self;
        hub
    }

    /// Builds a structured `DevServerReport` describing this active server and its v1 OTA endpoints.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Server handle reference.
    ///
    /// # Returns
    ///
    /// - `DevServerReport` - Serializable report snapshot.
    #[must_use]
    pub fn report(&self) -> DevServerReport {
        let Self {
            address,
            out_dir,
            mode,
            page_count,
            ota_project,
            ota_channel,
            hub,
            ..
        } = self;
        let base_url: String = self.url();
        let manifest_path: String =
            format!("/v1/projects/{ota_project}/channels/{ota_channel}/manifest");
        let events_path: String =
            format!("/v1/projects/{ota_project}/channels/{ota_channel}/events");
        let bound_port: u16 = address.port();
        let lan_urls: Vec<String> = detect_lan_ip_addresses()
            .into_iter()
            .map(|lan_ip: String| format!("http://{lan_ip}:{bound_port}{manifest_path}"))
            .collect();
        let mut report: DevServerReport = DevServerReport::new(
            mode.clone(),
            base_url.clone(),
            format!("{base_url}{HMR_ENDPOINT}"),
            format!("{base_url}{OTA_MANIFEST_ENDPOINT}"),
            out_dir.display().to_string(),
            hub.revision(),
            *page_count,
        );
        let _: &mut DevServerReport = report
            .set_v1_manifest_url(format!("{base_url}{manifest_path}"))
            .set_v1_events_url(format!("{base_url}{events_path}"))
            .set_health_url(format!("{base_url}{UPDATE_ROUTE_HEALTHZ}"))
            .set_lan_urls(lan_urls)
            .set_ota_project(ota_project.clone())
            .set_ota_channel(ota_channel.clone());
        report
    }

    /// Gracefully stops the HTTP listener and file watcher threads and joins them.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable server handle.
    pub fn shutdown(&mut self) {
        let Self {
            address,
            hub,
            http_thread,
            watch_thread,
            ..
        } = self;
        hub.stop();
        drop(TcpStream::connect(*address));
        if let Some(handle) = watch_thread.take() {
            drop(handle.join());
        }
        if let Some(handle) = http_thread.take() {
            drop(handle.join());
        }
    }
}

/// Ensures background server threads are cleanly stopped when `DevServerHandle` is dropped.
impl Drop for DevServerHandle {
    /// Signals shutdown and joins background threads on drop.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Handle being dropped.
    fn drop(&mut self) {
        self.shutdown();
    }
}