1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

lock: support lock-write for fetch command (#3787)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2020-01-26 10:43:59 -08:00 committed by Ryan Dahl
parent 9d98f0126c
commit ec44be0760
4 changed files with 65 additions and 0 deletions

View file

@ -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);

View file

@ -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",

View file

@ -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");

View file

@ -0,0 +1,3 @@
fetch code: 0
fetch check code: 0
run code: 0