diff options
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index f22567d61..e7913eddc 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1476,16 +1476,34 @@ impl CliOptions { deny_hrtime: self.flags.deny_hrtime, allow_net: self.flags.allow_net.clone(), deny_net: self.flags.deny_net.clone(), - allow_ffi: self.flags.allow_ffi.clone(), - deny_ffi: self.flags.deny_ffi.clone(), - allow_read: self.flags.allow_read.clone(), - deny_read: self.flags.deny_read.clone(), + allow_ffi: convert_option_str_to_path_buf( + &self.flags.allow_ffi, + self.initial_cwd(), + ), + deny_ffi: convert_option_str_to_path_buf( + &self.flags.deny_ffi, + self.initial_cwd(), + ), + allow_read: convert_option_str_to_path_buf( + &self.flags.allow_read, + self.initial_cwd(), + ), + deny_read: convert_option_str_to_path_buf( + &self.flags.deny_read, + self.initial_cwd(), + ), allow_run: self.flags.allow_run.clone(), deny_run: self.flags.deny_run.clone(), allow_sys: self.flags.allow_sys.clone(), deny_sys: self.flags.deny_sys.clone(), - allow_write: self.flags.allow_write.clone(), - deny_write: self.flags.deny_write.clone(), + allow_write: convert_option_str_to_path_buf( + &self.flags.allow_write, + self.initial_cwd(), + ), + deny_write: convert_option_str_to_path_buf( + &self.flags.deny_write, + self.initial_cwd(), + ), prompt: !self.no_prompt(), } } @@ -1584,29 +1602,29 @@ impl CliOptions { } pub fn watch_paths(&self) -> Vec<PathBuf> { - let mut paths = if let DenoSubcommand::Run(RunFlags { + let mut full_paths = Vec::new(); + if let DenoSubcommand::Run(RunFlags { watch: Some(WatchFlagsWithPaths { paths, .. }), .. }) = &self.flags.subcommand { - paths.clone() - } else { - Vec::with_capacity(2) - }; + full_paths.extend(paths.iter().map(|path| self.initial_cwd.join(path))); + } + if let Ok(Some(import_map_path)) = self .resolve_specified_import_map_specifier() .map(|ms| ms.and_then(|ref s| s.to_file_path().ok())) { - paths.push(import_map_path); + full_paths.push(import_map_path); } if let Some(specifier) = self.maybe_config_file_specifier() { if specifier.scheme() == "file" { if let Ok(path) = specifier.to_file_path() { - paths.push(path); + full_paths.push(path); } } } - paths + full_paths } } @@ -1784,6 +1802,20 @@ pub fn npm_pkg_req_ref_to_binary_command( binary_name.to_string() } +fn convert_option_str_to_path_buf( + flag: &Option<Vec<String>>, + initial_cwd: &Path, +) -> Option<Vec<PathBuf>> { + if let Some(allow_ffi_paths) = &flag { + let mut full_paths = Vec::new(); + full_paths + .extend(allow_ffi_paths.iter().map(|path| initial_cwd.join(path))); + Some(full_paths) + } else { + None + } +} + #[cfg(test)] mod test { use crate::util::fs::FileCollector; |