diff options
author | Adam Odziemkowski <odziem@users.noreply.github.com> | 2020-05-29 02:43:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 02:43:31 -0400 |
commit | 958f21e7abc36f0a5abaa381ed8d7f94c723f3fb (patch) | |
tree | 0e6d2c8664b0c8a7477fa0c37b7b1fac760ff2fa /cli/main.rs | |
parent | 499353ff399ccb6f1c27694ecc861e34a572cada (diff) |
fix(cli): write lock file before running any code (#5794)
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/cli/main.rs b/cli/main.rs index 68ba5e776..16ca41fe4 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -139,6 +139,19 @@ fn write_to_stdout_ignore_sigpipe(bytes: &[u8]) -> Result<(), std::io::Error> { } } +fn write_lockfile(global_state: GlobalState) -> Result<(), std::io::Error> { + if global_state.flags.lock_write { + if let Some(ref lockfile) = global_state.lockfile { + let g = lockfile.lock().unwrap(); + g.write()?; + } else { + eprintln!("--lock flag must be specified when using --lock-write"); + std::process::exit(11); + } + } + Ok(()) +} + fn create_main_worker( global_state: GlobalState, main_module: ModuleSpecifier, @@ -330,15 +343,7 @@ async fn cache_command(flags: Flags, files: Vec<String>) -> Result<(), ErrBox> { worker.preload_module(&specifier).await.map(|_| ())?; } - if global_state.flags.lock_write { - if let Some(ref lockfile) = global_state.lockfile { - let g = lockfile.lock().unwrap(); - g.write()?; - } else { - eprintln!("--lock flag must be specified when using --lock-write"); - std::process::exit(11); - } - } + write_lockfile(global_state)?; Ok(()) } @@ -514,18 +519,10 @@ async fn run_command(flags: Flags, script: String) -> Result<(), ErrBox> { create_main_worker(global_state.clone(), main_module.clone())?; debug!("main_module {}", main_module); worker.execute_module(&main_module).await?; + write_lockfile(global_state)?; worker.execute("window.dispatchEvent(new Event('load'))")?; (&mut *worker).await?; worker.execute("window.dispatchEvent(new Event('unload'))")?; - if global_state.flags.lock_write { - if let Some(ref lockfile) = global_state.lockfile { - let g = lockfile.lock().unwrap(); - g.write()?; - } else { - eprintln!("--lock flag must be specified when using --lock-write"); - std::process::exit(11); - } - } Ok(()) } |