summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs33
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(())
}