diff options
-rw-r--r-- | cli/main.rs | 33 | ||||
-rw-r--r-- | cli/tests/file_exists.ts | 6 | ||||
-rw-r--r-- | cli/tests/lock_write_fetch.ts | 7 |
3 files changed, 27 insertions, 19 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(()) } diff --git a/cli/tests/file_exists.ts b/cli/tests/file_exists.ts new file mode 100644 index 000000000..5fc5414b3 --- /dev/null +++ b/cli/tests/file_exists.ts @@ -0,0 +1,6 @@ +try { + await Deno.open(Deno.args[0]); + Deno.exit(0); +} catch (e) { + Deno.exit(1); +} diff --git a/cli/tests/lock_write_fetch.ts b/cli/tests/lock_write_fetch.ts index 9e7190596..5a4dea0ce 100644 --- a/cli/tests/lock_write_fetch.ts +++ b/cli/tests/lock_write_fetch.ts @@ -32,6 +32,8 @@ const fetchCheckProc = Deno.run({ const fetchCheckProcCode = (await fetchCheckProc.status()).code; console.log(`fetch check code: ${fetchCheckProcCode}`); +Deno.removeSync("./lock_write_fetch.json"); + const runProc = Deno.run({ stdout: "null", stderr: "null", @@ -39,7 +41,10 @@ const runProc = Deno.run({ Deno.execPath(), "run", "--lock=lock_write_fetch.json", - "https_import.ts", + "--lock-write", + "--allow-read", + "file_exists.ts", + "lock_write_fetch.json", ], }); |