summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-12-08 11:50:09 -0500
committerGitHub <noreply@github.com>2022-12-08 11:50:09 -0500
commit91443bbc0b3e5420d8a0b3506f1b18a88d48560a (patch)
tree804e60461874a71af08760f3aa1809c782558ac0 /cli/args
parenta6b5d05311f54d085a1e44f4a51717b4c0a4c74b (diff)
fix(compile): ensure import map is used when specified in deno config file (#16990)
Closes #14246
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs21
-rw-r--r--cli/args/mod.rs50
2 files changed, 43 insertions, 28 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index f1acbf48d..f4bc0c862 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -10,7 +10,6 @@ use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
use deno_core::url::Url;
use deno_runtime::permissions::parse_sys_kind;
-use deno_runtime::permissions::PermissionsOptions;
use log::debug;
use log::Level;
use once_cell::sync::Lazy;
@@ -482,20 +481,6 @@ impl Flags {
}
}
- pub fn permissions_options(&self) -> PermissionsOptions {
- PermissionsOptions {
- allow_env: self.allow_env.clone(),
- allow_hrtime: self.allow_hrtime,
- allow_net: self.allow_net.clone(),
- allow_ffi: self.allow_ffi.clone(),
- allow_read: self.allow_read.clone(),
- allow_run: self.allow_run.clone(),
- allow_sys: self.allow_sys.clone(),
- allow_write: self.allow_write.clone(),
- prompt: !self.no_prompt,
- }
- }
-
pub fn has_permission(&self) -> bool {
self.allow_all
|| self.allow_hrtime
@@ -2997,11 +2982,7 @@ fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.allow_ffi = Some(vec![]);
flags.allow_hrtime = true;
}
- #[cfg(not(test))]
- let has_no_prompt_env = env::var("DENO_NO_PROMPT") == Ok("1".to_string());
- #[cfg(test)]
- let has_no_prompt_env = false;
- if has_no_prompt_env || matches.is_present("no-prompt") {
+ if matches.is_present("no-prompt") {
flags.no_prompt = true;
}
}
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 38e0abea0..3f3f53d18 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -176,7 +176,7 @@ struct CliOptionOverrides {
import_map_specifier: Option<Option<ModuleSpecifier>>,
}
-/// Holds the common options used by many sub commands
+/// Holds the resolved options of many sources used by sub commands
/// and provides some helper function for creating common objects.
pub struct CliOptions {
// the source of the options is a detail the rest of the
@@ -414,6 +414,14 @@ impl CliOptions {
&self.flags.argv
}
+ pub fn ca_file(&self) -> &Option<String> {
+ &self.flags.ca_file
+ }
+
+ pub fn ca_stores(&self) -> &Option<Vec<String>> {
+ &self.flags.ca_stores
+ }
+
pub fn check_js(&self) -> bool {
self
.maybe_config_file
@@ -467,8 +475,8 @@ impl CliOptions {
.unwrap_or(false)
}
- pub fn location_flag(&self) -> Option<&Url> {
- self.flags.location.as_ref()
+ pub fn location_flag(&self) -> &Option<Url> {
+ &self.flags.location
}
pub fn maybe_custom_root(&self) -> Option<PathBuf> {
@@ -483,6 +491,10 @@ impl CliOptions {
self.flags.no_clear_screen
}
+ pub fn no_prompt(&self) -> bool {
+ resolve_no_prompt(&self.flags)
+ }
+
pub fn no_remote(&self) -> bool {
self.flags.no_remote
}
@@ -492,7 +504,17 @@ impl CliOptions {
}
pub fn permissions_options(&self) -> PermissionsOptions {
- self.flags.permissions_options()
+ PermissionsOptions {
+ allow_env: self.flags.allow_env.clone(),
+ allow_hrtime: self.flags.allow_hrtime,
+ allow_net: self.flags.allow_net.clone(),
+ allow_ffi: self.flags.allow_ffi.clone(),
+ allow_read: self.flags.allow_read.clone(),
+ allow_run: self.flags.allow_run.clone(),
+ allow_sys: self.flags.allow_sys.clone(),
+ allow_write: self.flags.allow_write.clone(),
+ prompt: !self.no_prompt(),
+ }
}
pub fn reload_flag(&self) -> bool {
@@ -525,16 +547,20 @@ impl CliOptions {
self.flags.type_check_mode
}
- pub fn unsafely_ignore_certificate_errors(&self) -> Option<&Vec<String>> {
- self.flags.unsafely_ignore_certificate_errors.as_ref()
+ pub fn unsafely_ignore_certificate_errors(&self) -> &Option<Vec<String>> {
+ &self.flags.unsafely_ignore_certificate_errors
}
pub fn unstable(&self) -> bool {
self.flags.unstable
}
- pub fn watch_paths(&self) -> Option<&Vec<PathBuf>> {
- self.flags.watch.as_ref()
+ pub fn v8_flags(&self) -> &Vec<String> {
+ &self.flags.v8_flags
+ }
+
+ pub fn watch_paths(&self) -> &Option<Vec<PathBuf>> {
+ &self.flags.watch
}
}
@@ -590,6 +616,14 @@ fn resolve_import_map_specifier(
Ok(None)
}
+/// Resolves the no_prompt value based on the cli flags and environment.
+pub fn resolve_no_prompt(flags: &Flags) -> bool {
+ flags.no_prompt || {
+ let value = env::var("DENO_NO_PROMPT");
+ matches!(value.as_ref().map(|s| s.as_str()), Ok("1"))
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;