bynk/dev.rs
1//! `bynk dev` — build a project and serve it locally in one step.
2//!
3//! Collapses the manual recipe (compile → `cd` into the generated worker dir →
4//! `wrangler dev`) into a single command (proposal v0.57). The orchestration is
5//! **pre-flight → compile → select → serve**, and almost every piece is reused:
6//! the in-process [`workers::compile_once`](crate::workers), the doctor `Deploy`
7//! capability for the Node + `wrangler` gate, and [`probe`](crate::probe) for locating
8//! `wrangler` with the same provenance ordering doctor reports.
9//!
10//! The serve step runs `wrangler dev` in **local mode** (Miniflare), which
11//! simulates KV / Durable Objects / queues keyed by *binding name* — so no
12//! namespace provisioning is needed and the generated `wrangler.toml` is served
13//! untouched (proposal §1, D4). Everything `wrangler`-specific is encapsulated
14//! here so the serve step can later be swapped for a first-party `workerd`
15//! server without touching the rest (proposal §4).
16//!
17//! Since #552 the step is **one `wrangler dev` per context**, not one per
18//! project: the processes discover each other through wrangler's dev registry
19//! and wire the emitted `[[services]]` bindings between themselves, so a
20//! cross-context call resolves locally. That makes the driver a supervisor of N
21//! children rather than a hand-off to one — hence the port allocation
22//! ([`allocate`]), the joint teardown (`terminate`, private), and the plural
23//! selection rule ([`select_contexts`]) that replaced ADR 0096 D3's ambiguity
24//! error.
25//!
26//! The file is the facade; the children hold the parts of one session:
27//! `run` (the serve loop, its options, the selection and the pre-flight),
28//! `events` (what `bynk dev` tells the user, as text or JSON), `stand_ins`
29//! (stand-in Workers for foreign services), `bindings` (each binding wired
30//! locally or proxied, and the dev configs), `serving` (ports and the
31//! arguments each `wrangler dev` gets), `supervise` (running, reading and
32//! stopping the children) and `watch` (what a rebuild is triggered by and
33//! what it migrates). Containers, Hyperdrive, Vectorize and the inspector live
34//! in the `dev_*` files beside this one.
35
36mod bindings;
37mod events;
38mod run;
39mod serving;
40mod stand_ins;
41mod supervise;
42#[cfg(test)]
43mod test_support;
44mod watch;
45
46// The build/select/`wrangler` plumbing `dev` shares with `deploy` now lives in
47// [`crate::workers`] (it is neither command's to own). Re-exported rather than
48// merely imported, so `bynk::dev::compile_once` and `bynk::dev::select_contexts`
49// — the paths this crate's integration tests already use — keep resolving.
50pub use crate::workers::{
51 SelectError, compile_once, discover_workers, prepare_build_dir, select_contexts,
52};
53
54pub use bindings::DEV_CONFIG;
55pub use events::{DevEvent, DevFormat, ServedContext, event_line, serving_event, serving_report};
56pub(crate) use run::is_remote;
57pub use run::{
58 DevOptions, needs_wrangler_warmup, preflight_failure_message, run, wrangler_age_notice,
59};
60pub use serving::{Serving, allocate, assign_free_inspector};
61pub use stand_ins::{
62 StandIn, foreign_services, stand_in_files, stand_in_name, stand_in_report, stand_ins,
63};
64pub(crate) use supervise::forward_lines;