Skip to content

Commit

Permalink
feat: glob and directory support for deno check and deno cache cl…
Browse files Browse the repository at this point in the history
…i arg paths (#25001)

Closes #24668
Closes #20813

---------

Co-authored-by: David Sherret <dsherret@gmail.com>
  • Loading branch information
yazan-abdalrahman and dsherret authored Aug 20, 2024
1 parent 1f47248 commit a7c8bb1
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 22 deletions.
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 cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ winres.workspace = true
[dependencies]
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_cache_dir = { workspace = true }
deno_config = { version = "=0.30.0", features = ["workspace", "sync"] }
deno_config = { version = "=0.30.1", features = ["workspace", "sync"] }
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "0.146.0", features = ["html", "syntect"] }
deno_emit = "=0.44.0"
Expand Down
37 changes: 18 additions & 19 deletions cli/graph_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
use std::sync::Arc;

use deno_ast::ModuleSpecifier;
use deno_config::glob::FilePatterns;
use deno_config::glob::PathOrPatternSet;
use deno_core::error::AnyError;
use deno_core::parking_lot::RwLock;
use deno_core::resolve_url_or_path;
use deno_graph::ModuleGraph;
use deno_runtime::colors;
use deno_runtime::deno_permissions::PermissionsContainer;

use crate::args::CliOptions;
use crate::module_loader::ModuleLoadPreparer;
use crate::util::fs::collect_specifiers;
use crate::util::path::is_script_ext;

pub trait ModuleGraphContainer: Clone + 'static {
/// Acquires a permit to modify the module graph without other code
Expand Down Expand Up @@ -99,24 +102,20 @@ impl MainModuleGraphContainer {
files: &[String],
) -> Result<Vec<ModuleSpecifier>, AnyError> {
let excludes = self.cli_options.workspace().resolve_config_excludes()?;
Ok(
files
.iter()
.filter_map(|file| {
let file_url =
resolve_url_or_path(file, self.cli_options.initial_cwd()).ok()?;
if file_url.scheme() != "file" {
return Some(file_url);
}
// ignore local files that match any of files listed in `exclude` option
let file_path = file_url.to_file_path().ok()?;
if excludes.matches_path(&file_path) {
None
} else {
Some(file_url)
}
})
.collect::<Vec<_>>(),
let include_patterns =
PathOrPatternSet::from_include_relative_path_or_patterns(
self.cli_options.initial_cwd(),
files,
)?;
let file_patterns = FilePatterns {
base: self.cli_options.initial_cwd().to_path_buf(),
include: Some(include_patterns),
exclude: excludes,
};
collect_specifiers(
file_patterns,
self.cli_options.vendor_dir_path().map(ToOwned::to_owned),
|e| is_script_ext(e.path),
)
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/cache/globbing/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "cache *.ts",
"output": "Download http://localhost:4545/echo.ts\n",
"exitCode": 0
}
1 change: 1 addition & 0 deletions tests/specs/cache/globbing/excluded.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "http://localhost:4545/non-existent.ts";
1 change: 1 addition & 0 deletions tests/specs/cache/globbing/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "http://localhost:4545/echo.ts";
24 changes: 24 additions & 0 deletions tests/specs/check/globbing/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"tests": {
"star": {
"args": "check *.ts",
"output": "Check [WILDLINE]main.ts\n",
"exitCode": 0
},
"star_not_found": {
"args": "check *.js",
"output": "Warning No matching files found.\n",
"exitCode": 0
},
"glob_star": {
"args": "check **/*.ts",
"output": "Check [WILDLINE]main.ts\nCheck [WILDLINE]sub_dir/main.ts\nerror: TS2322[WILDCARD]",
"exitCode": 1
},
"sub_dir": {
"args": "check sub_dir",
"output": "Check [WILDLINE]sub_dir/main.ts\nerror: TS2322[WILDCARD]",
"exitCode": 1
}
}
}
Empty file.
1 change: 1 addition & 0 deletions tests/specs/check/globbing/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("globbing_support_done");
1 change: 1 addition & 0 deletions tests/specs/check/globbing/sub_dir/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const value: number = "";

0 comments on commit a7c8bb1

Please # to comment.