Skip to content
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

fix: make fast check WalkOption name more clear #434

Merged
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
45 changes: 24 additions & 21 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,21 +1033,16 @@ pub enum ModuleEntryRef<'a> {

#[derive(Debug, Clone)]
pub struct WalkOptions {
pub check_js: bool,
pub follow_dynamic: bool,
pub follow_type_only: bool,
pub check_js: bool,
pub follow_fast_check_modules: bool,
}

impl Default for WalkOptions {
Copy link
Member Author

@dsherret dsherret Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because it's error prone (walk options are situation dependent) and nobody used this except the tests anyway.

fn default() -> Self {
Self {
follow_dynamic: false,
follow_type_only: true,
check_js: true,
follow_fast_check_modules: true,
}
}
/// If the fast check module graph should be preferred
/// to walk over walking all modules.
///
/// For example, when this encounters a package with fast
/// check modules, then it will only walk the fast checked
/// modules and not the rest of the graph.
pub prefer_fast_check_graph: bool,
}

pub struct ModuleEntryIterator<'a> {
Expand All @@ -1057,7 +1052,7 @@ pub struct ModuleEntryIterator<'a> {
follow_dynamic: bool,
follow_type_only: bool,
check_js: bool,
follow_fast_check_modules: bool,
prefer_fast_check_graph: bool,
previous_module: Option<ModuleEntryRef<'a>>,
}

Expand Down Expand Up @@ -1098,7 +1093,7 @@ impl<'a> ModuleEntryIterator<'a> {
follow_dynamic: options.follow_dynamic,
follow_type_only: options.follow_type_only,
check_js: options.check_js,
follow_fast_check_modules: options.follow_fast_check_modules,
prefer_fast_check_graph: options.prefer_fast_check_graph,
previous_module: None,
}
}
Expand Down Expand Up @@ -1159,7 +1154,7 @@ impl<'a> Iterator for ModuleEntryIterator<'a> {
}
}
}
let module_deps = if check_types && self.follow_fast_check_modules {
let module_deps = if check_types && self.prefer_fast_check_graph {
module.dependencies_prefer_fast_check()
} else {
&module.dependencies
Expand Down Expand Up @@ -1566,7 +1561,7 @@ impl ModuleGraph {
follow_dynamic: true,
follow_type_only: true,
check_js: true,
follow_fast_check_modules: true,
prefer_fast_check_graph: false,
},
);

Expand Down Expand Up @@ -1829,7 +1824,7 @@ impl ModuleGraph {
check_js: true,
follow_type_only: false,
follow_dynamic: false,
follow_fast_check_modules: true,
prefer_fast_check_graph: false,
},
)
.validate()
Expand Down Expand Up @@ -4874,7 +4869,7 @@ mod tests {
follow_dynamic: false,
follow_type_only: true,
check_js: true,
follow_fast_check_modules: true,
prefer_fast_check_graph: false,
},
)
.errors()
Expand All @@ -4889,7 +4884,7 @@ mod tests {
follow_dynamic: true,
follow_type_only: true,
check_js: true,
follow_fast_check_modules: true,
prefer_fast_check_graph: false,
},
)
.errors()
Expand Down Expand Up @@ -5021,7 +5016,15 @@ mod tests {
.await;
assert_eq!(graph.specifiers_count(), 4);
let errors = graph
.walk(&roots, Default::default())
.walk(
&roots,
WalkOptions {
check_js: true,
follow_dynamic: false,
follow_type_only: true,
prefer_fast_check_graph: false,
},
)
.errors()
.collect::<Vec<_>>();
assert_eq!(errors.len(), 3);
Expand Down
34 changes: 25 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3600,7 +3600,7 @@ export function a(a: A): B {
check_js: true,
follow_dynamic: true,
follow_type_only: true,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
);
assert_eq!(
Expand Down Expand Up @@ -3628,7 +3628,7 @@ export function a(a: A): B {
check_js: false,
follow_dynamic: false,
follow_type_only: false,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
);
assert_eq!(
Expand All @@ -3651,7 +3651,7 @@ export function a(a: A): B {
check_js: false,
follow_dynamic: true,
follow_type_only: false,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
);
assert_eq!(
Expand All @@ -3676,7 +3676,7 @@ export function a(a: A): B {
check_js: true,
follow_dynamic: false,
follow_type_only: false,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
);
assert_eq!(
Expand All @@ -3700,7 +3700,7 @@ export function a(a: A): B {
check_js: false,
follow_dynamic: false,
follow_type_only: true,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
);
assert_eq!(
Expand All @@ -3725,7 +3725,7 @@ export function a(a: A): B {
check_js: true,
follow_dynamic: false,
follow_type_only: true,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
);
assert_eq!(
Expand All @@ -3747,7 +3747,15 @@ export function a(a: A): B {

// try skip analyzing the dependencies after getting the first module
{
let mut iterator = graph.walk(&roots, Default::default());
let mut iterator = graph.walk(
&roots,
WalkOptions {
check_js: true,
follow_dynamic: false,
follow_type_only: true,
prefer_fast_check_graph: false,
},
);
assert_eq!(
iterator.next().unwrap().0.as_str(),
"https://example.com/jsx-runtime"
Expand All @@ -3763,7 +3771,15 @@ export function a(a: A): B {

// try skipping after first remote
{
let mut iterator = graph.walk(&roots, Default::default());
let mut iterator = graph.walk(
&roots,
WalkOptions {
check_js: true,
follow_dynamic: false,
follow_type_only: true,
prefer_fast_check_graph: false,
},
);
assert_eq!(
iterator.next().unwrap().0.as_str(),
"https://example.com/jsx-runtime"
Expand Down Expand Up @@ -4040,7 +4056,7 @@ export function a(a: A): B {
check_js: true,
follow_type_only: true,
follow_dynamic: false,
follow_fast_check_modules: true,
prefer_fast_check_graph: true,
},
)
.errors()
Expand Down