diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-11-02 16:32:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 16:32:30 +0100 |
commit | 5dea510b021d78a2c9b6aef9462ae6f4e0fd527a (patch) | |
tree | 728b3663f2852fae25df72ab2599c3cbebfc8ac9 /cli/args/mod.rs | |
parent | 630abb58b08827e63e56f519bf59a84c3283ab23 (diff) |
fix(lock): autodiscovery of lockfile (#16498)
This commit adds autodiscovery of lockfile.
This only happens if Deno discovers the configuration file (either
"deno.json" or "deno.jsonc"). In such case Deno tries to load
"deno.lock"
file that sits next to the configuration file, or creates one for user
if
the lockfile doesn't exist yet.
As a consequence, "--lock" and "--lock-write" flags had been updated.
"--lock" no longer requires a value, if one is not provided, it defaults
to "./deno.lock" resolved from the current working directory.
"--lock-write"
description was updated to say that it forces to overwrite a lockfile.
Autodiscovery is currently not handled by the LSP.
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index e46313858..64755a494 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -24,6 +24,7 @@ use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::normalize_path; +use deno_core::parking_lot::Mutex; use deno_core::url::Url; use deno_runtime::colors; use deno_runtime::deno_tls::rustls::RootCertStore; @@ -33,6 +34,7 @@ use std::collections::BTreeMap; use std::env; use std::net::SocketAddr; use std::path::PathBuf; +use std::sync::Arc; use crate::args::config_file::JsxImportSourceConfig; use crate::deno_dir::DenoDir; @@ -61,11 +63,16 @@ pub struct CliOptions { // application need not concern itself with, so keep these private flags: Flags, maybe_config_file: Option<ConfigFile>, + maybe_lockfile: Option<Arc<Mutex<Lockfile>>>, overrides: CliOptionOverrides, } impl CliOptions { - pub fn new(flags: Flags, maybe_config_file: Option<ConfigFile>) -> Self { + pub fn new( + flags: Flags, + maybe_config_file: Option<ConfigFile>, + maybe_lockfile: Option<Lockfile>, + ) -> Self { if let Some(insecure_allowlist) = flags.unsafely_ignore_certificate_errors.as_ref() { @@ -80,8 +87,11 @@ impl CliOptions { eprintln!("{}", colors::yellow(msg)); } + let maybe_lockfile = maybe_lockfile.map(|l| Arc::new(Mutex::new(l))); + Self { maybe_config_file, + maybe_lockfile, flags, overrides: Default::default(), } @@ -89,7 +99,9 @@ impl CliOptions { pub fn from_flags(flags: Flags) -> Result<Self, AnyError> { let maybe_config_file = ConfigFile::discover(&flags)?; - Ok(Self::new(flags, maybe_config_file)) + let maybe_lock_file = + Lockfile::discover(&flags, maybe_config_file.as_ref())?; + Ok(Self::new(flags, maybe_config_file, maybe_lock_file)) } pub fn maybe_config_file_specifier(&self) -> Option<ModuleSpecifier> { @@ -210,13 +222,8 @@ impl CliOptions { .map(|host| InspectorServer::new(host, version::get_user_agent())) } - pub fn resolve_lock_file(&self) -> Result<Option<Lockfile>, AnyError> { - if let Some(filename) = &self.flags.lock { - let lockfile = Lockfile::new(filename.clone(), self.flags.lock_write)?; - Ok(Some(lockfile)) - } else { - Ok(None) - } + pub fn maybe_lock_file(&self) -> Option<Arc<Mutex<Lockfile>>> { + self.maybe_lockfile.clone() } pub fn resolve_tasks_config( |