diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2020-01-26 10:43:59 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2020-01-26 13:43:59 -0500 |
commit | ec44be0760d647b3d005387d2f44ad0336d01024 (patch) | |
tree | a23d962ba972a4c47646bf0facac4ec2e47846ef | |
parent | 9d98f0126c5e19704b273579acf40132a38ce43b (diff) |
lock: support lock-write for fetch command (#3787)
-rw-r--r-- | cli/lib.rs | 11 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 7 | ||||
-rw-r--r-- | cli/tests/lock_write_fetch.ts | 44 | ||||
-rw-r--r-- | cli/tests/lock_write_fetch.ts.out | 3 |
4 files changed, 65 insertions, 0 deletions
diff --git a/cli/lib.rs b/cli/lib.rs index 3b174bb75..311d8ce30 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 ce3828b8b..52fc254c5 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 000000000..7d597724d --- /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 000000000..bfdb952f9 --- /dev/null +++ b/cli/tests/lock_write_fetch.ts.out @@ -0,0 +1,3 @@ +fetch code: 0 +fetch check code: 0 +run code: 0 |