summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYazan AbdAl-Rahman <yazan.abdalrahman@exalt.ps>2024-08-20 21:38:06 +0300
committerGitHub <noreply@github.com>2024-08-20 18:38:06 +0000
commita7c8bb1596411f91e20ddd5cd54c9dbd055d1059 (patch)
tree408ed9e2935b4749820c30314087e801b0c280c4
parent1f47248143b2298d38dbada5b431570c067ed663 (diff)
feat: glob and directory support for `deno check` and `deno cache` cli arg paths (#25001)
Closes #24668 Closes #20813 --------- Co-authored-by: David Sherret <dsherret@gmail.com>
-rw-r--r--Cargo.lock4
-rw-r--r--cli/Cargo.toml2
-rw-r--r--cli/graph_container.rs37
-rw-r--r--tests/specs/cache/globbing/__test__.jsonc5
-rw-r--r--tests/specs/cache/globbing/excluded.tsx1
-rw-r--r--tests/specs/cache/globbing/main.ts1
-rw-r--r--tests/specs/check/globbing/__test__.jsonc24
-rw-r--r--tests/specs/check/globbing/excluded.tsx0
-rw-r--r--tests/specs/check/globbing/main.ts1
-rw-r--r--tests/specs/check/globbing/sub_dir/main.ts1
10 files changed, 54 insertions, 22 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e43bfcc94..32454d516 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1360,9 +1360,9 @@ dependencies = [
[[package]]
name = "deno_config"
-version = "0.30.0"
+version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e287a8ab3552cf3ef8fc41b2bd7cc041c5e8e1a76de3aeb26e804b570bab37d7"
+checksum = "9657dbcc5210407fd9a1b1571310f2fe25c6dd6be2195c964d19f43d70045a95"
dependencies = [
"anyhow",
"deno_package_json",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index c3fc704f1..06384f479 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -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"
diff --git a/cli/graph_container.rs b/cli/graph_container.rs
index cf913464f..9f71045c6 100644
--- a/cli/graph_container.rs
+++ b/cli/graph_container.rs
@@ -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
@@ -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),
)
}
}
diff --git a/tests/specs/cache/globbing/__test__.jsonc b/tests/specs/cache/globbing/__test__.jsonc
new file mode 100644
index 000000000..9bf210bb4
--- /dev/null
+++ b/tests/specs/cache/globbing/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "args": "cache *.ts",
+ "output": "Download http://localhost:4545/echo.ts\n",
+ "exitCode": 0
+}
diff --git a/tests/specs/cache/globbing/excluded.tsx b/tests/specs/cache/globbing/excluded.tsx
new file mode 100644
index 000000000..b21a330c7
--- /dev/null
+++ b/tests/specs/cache/globbing/excluded.tsx
@@ -0,0 +1 @@
+import "http://localhost:4545/non-existent.ts";
diff --git a/tests/specs/cache/globbing/main.ts b/tests/specs/cache/globbing/main.ts
new file mode 100644
index 000000000..fe4964118
--- /dev/null
+++ b/tests/specs/cache/globbing/main.ts
@@ -0,0 +1 @@
+import "http://localhost:4545/echo.ts";
diff --git a/tests/specs/check/globbing/__test__.jsonc b/tests/specs/check/globbing/__test__.jsonc
new file mode 100644
index 000000000..92d9f4d80
--- /dev/null
+++ b/tests/specs/check/globbing/__test__.jsonc
@@ -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
+ }
+ }
+}
diff --git a/tests/specs/check/globbing/excluded.tsx b/tests/specs/check/globbing/excluded.tsx
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/specs/check/globbing/excluded.tsx
diff --git a/tests/specs/check/globbing/main.ts b/tests/specs/check/globbing/main.ts
new file mode 100644
index 000000000..efa57a7ed
--- /dev/null
+++ b/tests/specs/check/globbing/main.ts
@@ -0,0 +1 @@
+console.log("globbing_support_done");
diff --git a/tests/specs/check/globbing/sub_dir/main.ts b/tests/specs/check/globbing/sub_dir/main.ts
new file mode 100644
index 000000000..4f4c3ce9c
--- /dev/null
+++ b/tests/specs/check/globbing/sub_dir/main.ts
@@ -0,0 +1 @@
+const value: number = "";