mirror of
https://github.com/denoland/deno.git
synced 2025-01-12 17:09:00 -05:00
fix(cli): handle collecting a directory with file:// (#15002)
This commit is contained in:
parent
34301e5a47
commit
d9d86078b0
1 changed files with 47 additions and 10 deletions
|
@ -254,14 +254,18 @@ where
|
||||||
let lowercase_path = path.to_lowercase();
|
let lowercase_path = path.to_lowercase();
|
||||||
if lowercase_path.starts_with("http://")
|
if lowercase_path.starts_with("http://")
|
||||||
|| lowercase_path.starts_with("https://")
|
|| lowercase_path.starts_with("https://")
|
||||||
|| lowercase_path.starts_with("file://")
|
|
||||||
{
|
{
|
||||||
let url = ModuleSpecifier::parse(&path)?;
|
let url = ModuleSpecifier::parse(&path)?;
|
||||||
prepared.push(url);
|
prepared.push(url);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let p = normalize_path(&root_path.join(path));
|
let p = if lowercase_path.starts_with("file://") {
|
||||||
|
specifier_to_file_path(&ModuleSpecifier::parse(&path)?)?
|
||||||
|
} else {
|
||||||
|
root_path.join(path)
|
||||||
|
};
|
||||||
|
let p = normalize_path(&p);
|
||||||
if p.is_dir() {
|
if p.is_dir() {
|
||||||
let test_files = collect_files(&[p], ignore, &predicate).unwrap();
|
let test_files = collect_files(&[p], ignore, &predicate).unwrap();
|
||||||
let mut test_files_as_urls = test_files
|
let mut test_files_as_urls = test_files
|
||||||
|
@ -663,6 +667,14 @@ mod tests {
|
||||||
let ignore_dir_files = ["g.d.ts", ".gitignore"];
|
let ignore_dir_files = ["g.d.ts", ".gitignore"];
|
||||||
create_files(&ignore_dir_path, &ignore_dir_files);
|
create_files(&ignore_dir_path, &ignore_dir_files);
|
||||||
|
|
||||||
|
let predicate = |path: &Path| {
|
||||||
|
// exclude dotfiles
|
||||||
|
path
|
||||||
|
.file_name()
|
||||||
|
.and_then(|f| f.to_str())
|
||||||
|
.map_or(false, |f| !f.starts_with('.'))
|
||||||
|
};
|
||||||
|
|
||||||
let result = collect_specifiers(
|
let result = collect_specifiers(
|
||||||
vec![
|
vec![
|
||||||
"http://localhost:8080".to_string(),
|
"http://localhost:8080".to_string(),
|
||||||
|
@ -670,13 +682,7 @@ mod tests {
|
||||||
"https://localhost:8080".to_string(),
|
"https://localhost:8080".to_string(),
|
||||||
],
|
],
|
||||||
&[ignore_dir_path],
|
&[ignore_dir_path],
|
||||||
|path| {
|
predicate,
|
||||||
// exclude dotfiles
|
|
||||||
path
|
|
||||||
.file_name()
|
|
||||||
.and_then(|f| f.to_str())
|
|
||||||
.map_or(false, |f| !f.starts_with('.'))
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -698,7 +704,38 @@ mod tests {
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| ModuleSpecifier::parse(f).unwrap())
|
.map(|f| ModuleSpecifier::parse(f).unwrap())
|
||||||
.collect::<Vec<ModuleSpecifier>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
|
||||||
|
let scheme = if cfg!(target_os = "windows") {
|
||||||
|
"file:///"
|
||||||
|
} else {
|
||||||
|
"file://"
|
||||||
|
};
|
||||||
|
let result = collect_specifiers(
|
||||||
|
vec![format!(
|
||||||
|
"{}{}",
|
||||||
|
scheme,
|
||||||
|
root_dir_path
|
||||||
|
.join("child")
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.replace('/', "\\")
|
||||||
|
)],
|
||||||
|
&[],
|
||||||
|
predicate,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let expected: Vec<ModuleSpecifier> = [
|
||||||
|
&format!("{}/child/README.md", root_dir_url),
|
||||||
|
&format!("{}/child/e.mjs", root_dir_url),
|
||||||
|
&format!("{}/child/f.mjsx", root_dir_url),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.map(|f| ModuleSpecifier::parse(f).unwrap())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
assert_eq!(result, expected);
|
assert_eq!(result, expected);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue