-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file processing and error handling
- Replace custom `oxc_visitor_processor` with new `utils::global::glob` function - Implement `anyhow::Error` for improved error handling - Update module imports across multiple files - Remove `oxc_visitor_processor.rs` - Add `anyhow` dependency to Cargo.toml - Minor updates to type definitions in index.d.ts
- Loading branch information
Showing
11 changed files
with
102 additions
and
130 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use anyhow::Result; | ||
use rayon::prelude::*; | ||
use std::{env::current_dir, path::PathBuf}; | ||
use wax::Glob; | ||
|
||
#[derive(Debug, Clone)] | ||
#[napi[object]] | ||
pub struct Options { | ||
pub pattern: Option<String>, | ||
pub ignore: Option<Vec<String>>, | ||
pub cwd: Option<String>, | ||
pub concurrency: Option<i32>, | ||
} | ||
|
||
pub fn glob<F>(handler_fn: F, options: Option<Options>) -> Result<()> | ||
where | ||
F: Fn(PathBuf) + Send + Sync + 'static, | ||
{ | ||
let default_pattern: &str = "**/*.{js,ts,jsx,tsx}"; | ||
|
||
let default_ignore_patterns: Vec<String> = | ||
vec!["**/node_modules/**".to_string(), "**/*.d.ts".to_string()]; | ||
|
||
let ignore_patterns_vec: Vec<String> = options | ||
.as_ref() | ||
.and_then(|opts| opts.ignore.clone()) | ||
.unwrap_or_else(|| { | ||
default_ignore_patterns | ||
.iter() | ||
.map(|s| s.to_string()) | ||
.collect() | ||
}); | ||
|
||
let ignore_patterns: Vec<&str> = | ||
ignore_patterns_vec.iter().map(String::as_str).collect(); | ||
|
||
let dir = current_dir()?.display().to_string(); | ||
|
||
let cwd = options | ||
.as_ref() | ||
.and_then(|opts| opts.cwd.clone()) | ||
.unwrap_or(dir); | ||
|
||
let glob = Glob::new(default_pattern)?; | ||
|
||
let entries: Vec<_> = glob.walk(&cwd).not(ignore_patterns)?.collect(); | ||
|
||
entries.par_iter().try_for_each(|item| -> Result<()> { | ||
if let Ok(entry) = item { | ||
if entry.path().is_file() { | ||
handler_fn(entry.path().to_path_buf()); | ||
} | ||
} | ||
Ok(()) | ||
})?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod ast_node; | ||
pub mod global; | ||
pub mod semantic_builder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[napi(object)] | ||
#[derive( | ||
Debug, Default, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, | ||
)] | ||
pub struct Position { | ||
pub line: u32, | ||
pub col: u32, | ||
} |