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:
parent
9d98f0126c
commit
ec44be0760
4 changed files with 65 additions and 0 deletions
11
cli/lib.rs
11
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);
|
||||
|
|
|
@ -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",
|
||||
|
|
44
cli/tests/lock_write_fetch.ts
Normal file
44
cli/tests/lock_write_fetch.ts
Normal 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");
|
3
cli/tests/lock_write_fetch.ts.out
Normal file
3
cli/tests/lock_write_fetch.ts.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
fetch code: 0
|
||||
fetch check code: 0
|
||||
run code: 0
|
Loading…
Reference in a new issue