Skip to content

Commit 2941f77

Browse files
committed
fix: fixed cli in development for watching
1 parent 16c63ef commit 2941f77

File tree

1 file changed

+14
-7
lines changed
  • packages/perseus-cli/src/bin

1 file changed

+14
-7
lines changed

packages/perseus-cli/src/bin/main.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ use std::sync::mpsc::channel;
2222
#[tokio::main]
2323
async fn main() {
2424
// In development, we'll test in the `basic` example
25-
if cfg!(debug_assertions) {
26-
let example_to_test =
27-
env::var("TEST_EXAMPLE").unwrap_or_else(|_| "../../examples/basic".to_string());
25+
if cfg!(debug_assertions) && env::var("TEST_EXAMPLE").is_ok() {
26+
let example_to_test = env::var("TEST_EXAMPLE").unwrap();
2827
env::set_current_dir(example_to_test).unwrap();
2928
}
3029
let exit_code = real_main().await;
@@ -162,10 +161,14 @@ async fn core(dir: PathBuf) -> Result<i32, Error> {
162161
// This will be updated every time we re-create the process
163162
// We spawn it as a process group, whcih means signals go to grandchild processes as well, which means hot reloading
164163
// can actually work!
165-
let mut child = Command::new(&bin_name)
164+
let mut child = Command::new(&bin_name);
165+
let child = child
166166
.args(&args)
167167
.env("PERSEUS_WATCHING_PROHIBITED", "true")
168-
.env("PERSEUS_USE_RELOAD_SERVER", "true") // This is for internal use ONLY
168+
.env("PERSEUS_USE_RELOAD_SERVER", "true"); // This is for internal use ONLY
169+
#[cfg(debug_assertions)]
170+
let child = child.env_remove("TEST_EXAMPLE"); // We want to use the current directory in development
171+
let mut child = child
169172
.group_spawn()
170173
.map_err(|err| WatchError::SpawnSelfFailed { source: err })?;
171174

@@ -177,10 +180,14 @@ async fn core(dir: PathBuf) -> Result<i32, Error> {
177180
// This gracefully kills the process in the sense that it kills it and all its children
178181
let _ = child.kill();
179182
// Restart it
180-
child = Command::new(&bin_name)
183+
let mut child_l = Command::new(&bin_name);
184+
let child_l = child_l
181185
.args(&args)
182186
.env("PERSEUS_WATCHING_PROHIBITED", "true")
183-
.env("PERSEUS_USE_RELOAD_SERVER", "true") // This is for internal use ONLY
187+
.env("PERSEUS_USE_RELOAD_SERVER", "true"); // This is for internal use ONLY
188+
#[cfg(debug_assertions)]
189+
let child_l = child_l.env_remove("TEST_EXAMPLE"); // We want to use the current directory in development
190+
child = child_l
184191
.group_spawn()
185192
.map_err(|err| WatchError::SpawnSelfFailed { source: err })?;
186193
}

0 commit comments

Comments
 (0)