summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs68
-rw-r--r--cli/args/mod.rs25
2 files changed, 79 insertions, 14 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 90899704e..d024f6576 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -458,7 +458,9 @@ impl Flags {
Some(files.clone())
} else if let Run(RunFlags { script }) = &self.subcommand {
if let Ok(module_specifier) = deno_core::resolve_url_or_path(script) {
- if module_specifier.scheme() == "file" {
+ if module_specifier.scheme() == "file"
+ || module_specifier.scheme() == "npm"
+ {
if let Ok(p) = module_specifier.to_file_path() {
Some(vec![p])
} else {
@@ -2145,16 +2147,17 @@ fn lock_arg<'a>() -> Arg<'a> {
Arg::new("lock")
.long("lock")
.value_name("FILE")
- .help("Check the specified lock file")
+ .help("Check the specified lock file. If value is not provided, defaults to \"deno.lock\" in the current working directory.")
.takes_value(true)
+ .min_values(0)
+ .max_values(1)
.value_hint(ValueHint::FilePath)
}
fn lock_write_arg<'a>() -> Arg<'a> {
Arg::new("lock-write")
.long("lock-write")
- .requires("lock")
- .help("Write lock file (use with --lock)")
+ .help("Force overwriting the lock file.")
}
static CONFIG_HELP: Lazy<String> = Lazy::new(|| {
@@ -3098,7 +3101,11 @@ fn lock_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn lock_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("lock") {
- let lockfile = matches.value_of("lock").unwrap();
+ let lockfile = if let Some(path) = matches.value_of("lock") {
+ path
+ } else {
+ "./deno.lock"
+ };
flags.lock = Some(PathBuf::from(lockfile));
}
}
@@ -5335,6 +5342,57 @@ mod tests {
..Flags::default()
}
);
+
+ let r = flags_from_vec(svec![
+ "deno",
+ "run",
+ "--lock",
+ "--lock-write",
+ "script.ts"
+ ]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Run(RunFlags {
+ script: "script.ts".to_string(),
+ }),
+ lock_write: true,
+ lock: Some(PathBuf::from("./deno.lock")),
+ ..Flags::default()
+ }
+ );
+
+ let r = flags_from_vec(svec![
+ "deno",
+ "run",
+ "--lock-write",
+ "--lock",
+ "lock.json",
+ "script.ts"
+ ]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Run(RunFlags {
+ script: "script.ts".to_string(),
+ }),
+ lock_write: true,
+ lock: Some(PathBuf::from("lock.json")),
+ ..Flags::default()
+ }
+ );
+
+ let r = flags_from_vec(svec!["deno", "run", "--lock-write", "script.ts"]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Run(RunFlags {
+ script: "script.ts".to_string(),
+ }),
+ lock_write: true,
+ ..Flags::default()
+ }
+ );
}
#[test]
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(