mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(cli): write lock file before running any code (#5794)
This commit is contained in:
parent
499353ff39
commit
958f21e7ab
3 changed files with 27 additions and 19 deletions
33
cli/main.rs
33
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(())
|
||||
}
|
||||
|
||||
|
|
6
cli/tests/file_exists.ts
Normal file
6
cli/tests/file_exists.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
try {
|
||||
await Deno.open(Deno.args[0]);
|
||||
Deno.exit(0);
|
||||
} catch (e) {
|
||||
Deno.exit(1);
|
||||
}
|
|
@ -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",
|
||||
],
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue