Skip to content

fix(workspace): better cli file argument handling #24447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ console_static_text = "=0.8.1"
data-encoding = "2.3.3"
data-url = "=0.3.0"
deno_cache_dir = "=0.10.0"
deno_config = { version = "=0.20.0", default-features = false }
deno_config = { version = "=0.20.1", default-features = false }
dlopen2 = "0.6.1"
ecb = "=0.1.2"
elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh", "std", "pem"] }
Expand Down
22 changes: 13 additions & 9 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use log::debug;
use log::Level;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashSet;
use std::env;
use std::ffi::OsString;
use std::net::SocketAddr;
Expand All @@ -36,7 +37,6 @@ use std::path::PathBuf;
use std::str::FromStr;

use crate::args::resolve_no_prompt;
use crate::util::collections::CheckedSet;
use crate::util::fs::canonicalize_path;

use super::flags_net;
Expand Down Expand Up @@ -865,20 +865,20 @@ impl Flags {
args
}

/// Extract the directory paths the config file should be discovered from.
/// Extract the paths the config file should be discovered from.
///
/// Returns `None` if the config file should not be auto-discovered.
pub fn config_path_args(&self, current_dir: &Path) -> Option<Vec<PathBuf>> {
fn resolve_multiple_files(
files: &[String],
files_or_dirs: &[String],
current_dir: &Path,
) -> Vec<PathBuf> {
let mut seen = CheckedSet::with_capacity(files.len());
let result = files
let mut seen = HashSet::with_capacity(files_or_dirs.len());
let result = files_or_dirs
.iter()
.filter_map(|p| {
let path = normalize_path(current_dir.join(p).parent()?);
if seen.insert(&path) {
let path = normalize_path(current_dir.join(p));
if seen.insert(path.clone()) {
Some(path)
} else {
None
Expand Down Expand Up @@ -9298,7 +9298,7 @@ mod tests {
.unwrap();
assert_eq!(
flags.config_path_args(&cwd),
Some(vec![cwd.join("dir/a/"), cwd.join("dir/b/")])
Some(vec![cwd.join("dir/a/a.js"), cwd.join("dir/b/b.js")])
);

let flags = flags_from_vec(svec!["deno", "lint"]).unwrap();
Expand All @@ -9314,7 +9314,11 @@ mod tests {
.unwrap();
assert_eq!(
flags.config_path_args(&cwd),
Some(vec![cwd.join("dir/a/"), cwd.join("dir/")])
Some(vec![
cwd.join("dir/a/a.js"),
cwd.join("dir/a/a2.js"),
cwd.join("dir/b.js")
])
);
}

Expand Down
Loading