From ec44be0760d647b3d005387d2f44ad0336d01024 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Sun, 26 Jan 2020 10:43:59 -0800 Subject: [PATCH] lock: support lock-write for fetch command (#3787) --- cli/lib.rs | 11 ++++++++ cli/tests/integration_tests.rs | 7 +++++ cli/tests/lock_write_fetch.ts | 44 +++++++++++++++++++++++++++++++ cli/tests/lock_write_fetch.ts.out | 3 +++ 4 files changed, 65 insertions(+) create mode 100644 cli/tests/lock_write_fetch.ts create mode 100644 cli/tests/lock_write_fetch.ts.out diff --git a/cli/lib.rs b/cli/lib.rs index 3b174bb751..311d8ce305 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -289,6 +289,17 @@ fn fetch_command(flags: DenoFlags) { let main_future = async move { let result = worker.execute_mod_async(&main_module, None, true).await; js_check(result); + if state.flags.lock_write { + if let Some(ref lockfile) = state.lockfile { + let g = lockfile.lock().unwrap(); + if let Err(e) = g.write() { + print_err_and_exit(ErrBox::from(e)); + } + } else { + eprintln!("--lock flag must be specified when using --lock-write"); + std::process::exit(11); + } + } }; tokio_util::run(main_future); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index ce3828b8b2..52fc254c5d 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -391,6 +391,13 @@ itest!(_054_info_local_imports { exit_code: 0, }); +itest!(lock_write_fetch { + args: + "run --allow-read --allow-write --allow-env --allow-run lock_write_fetch.ts", + output: "lock_write_fetch.ts.out", + exit_code: 0, +}); + itest!(lock_check_ok { args: "run --lock=lock_check_ok.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts", output: "003_relative_import.ts.out", diff --git a/cli/tests/lock_write_fetch.ts b/cli/tests/lock_write_fetch.ts new file mode 100644 index 0000000000..7d597724de --- /dev/null +++ b/cli/tests/lock_write_fetch.ts @@ -0,0 +1,44 @@ +try { + Deno.removeSync("./lock_write_fetch.json"); +} catch {} + +const fetchProc = Deno.run({ + stdout: "null", + stderr: "null", + args: [ + Deno.execPath(), + "fetch", + "--reload", + "--lock=lock_write_fetch.json", + "--lock-write", + "https_import.ts" + ] +}); + +const fetchCode = (await fetchProc.status()).code; +console.log(`fetch code: ${fetchCode}`); + +const fetchCheckProc = Deno.run({ + stdout: "null", + stderr: "null", + args: [ + Deno.execPath(), + "fetch", + "--lock=lock_write_fetch.json", + "https_import.ts" + ] +}); + +const fetchCheckProcCode = (await fetchCheckProc.status()).code; +console.log(`fetch check code: ${fetchCheckProcCode}`); + +const runProc = Deno.run({ + stdout: "null", + stderr: "null", + args: [Deno.execPath(), "--lock=lock_write_fetch.json", "https_import.ts"] +}); + +const runCode = (await runProc.status()).code; +console.log(`run code: ${runCode}`); + +Deno.removeSync("./lock_write_fetch.json"); diff --git a/cli/tests/lock_write_fetch.ts.out b/cli/tests/lock_write_fetch.ts.out new file mode 100644 index 0000000000..bfdb952f94 --- /dev/null +++ b/cli/tests/lock_write_fetch.ts.out @@ -0,0 +1,3 @@ +fetch code: 0 +fetch check code: 0 +run code: 0