mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -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(
|
fn create_main_worker(
|
||||||
global_state: GlobalState,
|
global_state: GlobalState,
|
||||||
main_module: ModuleSpecifier,
|
main_module: ModuleSpecifier,
|
||||||
|
@ -330,15 +343,7 @@ async fn cache_command(flags: Flags, files: Vec<String>) -> Result<(), ErrBox> {
|
||||||
worker.preload_module(&specifier).await.map(|_| ())?;
|
worker.preload_module(&specifier).await.map(|_| ())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if global_state.flags.lock_write {
|
write_lockfile(global_state)?;
|
||||||
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -514,18 +519,10 @@ async fn run_command(flags: Flags, script: String) -> Result<(), ErrBox> {
|
||||||
create_main_worker(global_state.clone(), main_module.clone())?;
|
create_main_worker(global_state.clone(), main_module.clone())?;
|
||||||
debug!("main_module {}", main_module);
|
debug!("main_module {}", main_module);
|
||||||
worker.execute_module(&main_module).await?;
|
worker.execute_module(&main_module).await?;
|
||||||
|
write_lockfile(global_state)?;
|
||||||
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
||||||
(&mut *worker).await?;
|
(&mut *worker).await?;
|
||||||
worker.execute("window.dispatchEvent(new Event('unload'))")?;
|
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(())
|
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;
|
const fetchCheckProcCode = (await fetchCheckProc.status()).code;
|
||||||
console.log(`fetch check code: ${fetchCheckProcCode}`);
|
console.log(`fetch check code: ${fetchCheckProcCode}`);
|
||||||
|
|
||||||
|
Deno.removeSync("./lock_write_fetch.json");
|
||||||
|
|
||||||
const runProc = Deno.run({
|
const runProc = Deno.run({
|
||||||
stdout: "null",
|
stdout: "null",
|
||||||
stderr: "null",
|
stderr: "null",
|
||||||
|
@ -39,7 +41,10 @@ const runProc = Deno.run({
|
||||||
Deno.execPath(),
|
Deno.execPath(),
|
||||||
"run",
|
"run",
|
||||||
"--lock=lock_write_fetch.json",
|
"--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