From 1e073ee1d67479e425317fbf0c8cb06b8e008178 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Mon, 20 Jan 2025 09:26:08 +0000 Subject: [PATCH] don't store specifier info --- cli/factory.rs | 35 +++++++++++++++++++---------------- cli/tools/bench/mod.rs | 12 ++++++------ cli/tools/check.rs | 4 ++-- cli/tools/test/mod.rs | 14 +++++++------- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/cli/factory.rs b/cli/factory.rs index 8dce24f97b..200388d0f9 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -1233,17 +1233,17 @@ impl CliFactory { #[derive(Debug, Copy, Clone)] pub struct SpecifierInfo { - /// Type check as an ES module. - pub check: bool, + /// Include as an ES module. + pub include: bool, /// Type check virtual modules from doc snippets. If this is set but `check` /// is not, this may be a markdown file for example. - pub check_doc: bool, + pub include_doc: bool, } pub struct CliFactoryWithWorkspaceFiles { pub inner: CliFactory, pub cli_options: Arc, - specifiers: Vec<(ModuleSpecifier, SpecifierInfo)>, + file_specifiers: Vec, doc_snippet_specifiers: Vec, initial_cwd: PathBuf, } @@ -1280,7 +1280,7 @@ impl CliFactoryWithWorkspaceFiles { let _ = watcher_communicator.watch_paths(cli_options.watch_paths()); } workspace_dirs_with_files.sort_by_cached_key(|(d, _)| d.dir_url().clone()); - let mut specifiers = Vec::new(); + let mut file_specifiers = Vec::new(); let mut doc_snippet_specifiers = Vec::new(); for (_, files) in workspace_dirs_with_files { if let Some(watcher_communicator) = watcher_communicator { @@ -1293,7 +1293,7 @@ impl CliFactoryWithWorkspaceFiles { ); } let file_fetcher = factory.file_fetcher()?; - let dir_specifiers = collect_specifiers( + let specifiers = collect_specifiers( files, cli_options.clone(), file_fetcher.clone(), @@ -1302,7 +1302,7 @@ impl CliFactoryWithWorkspaceFiles { .await?; if let Some(extract_doc_files) = extract_doc_files { let root_permissions = factory.root_permissions_container()?; - for (s, _) in dir_specifiers.iter().filter(|(_, i)| i.check_doc) { + for (s, _) in specifiers.iter().filter(|(_, i)| i.include_doc) { let file = file_fetcher.fetch(s, root_permissions).await?; let snippet_files = extract_doc_files(file)?; for snippet_file in snippet_files { @@ -1311,12 +1311,16 @@ impl CliFactoryWithWorkspaceFiles { } } } - specifiers.extend(dir_specifiers); + file_specifiers.extend( + specifiers + .into_iter() + .filter_map(|(s, i)| i.include.then_some(s)), + ); } Ok(Self { inner: factory, cli_options, - specifiers, + file_specifiers, doc_snippet_specifiers, initial_cwd, }) @@ -1327,25 +1331,24 @@ impl CliFactoryWithWorkspaceFiles { } pub fn found_specifiers(&self) -> bool { - !self.specifiers.is_empty() + !self.file_specifiers.is_empty() || !self.doc_snippet_specifiers.is_empty() } - pub fn checked_specifiers(&self) -> impl Iterator { + pub fn specifiers(&self) -> impl Iterator { self - .specifiers + .file_specifiers .iter() - .filter_map(|(s, i)| i.check.then_some(s)) .chain(self.doc_snippet_specifiers.iter()) } - pub async fn dependent_checked_specifiers( + pub async fn dependent_specifiers( &self, canonicalized_dep_paths: &HashSet, ) -> Result, AnyError> { let graph_kind = self.inner.cli_options()?.type_check_mode().as_graph_kind(); let module_graph_creator = self.inner.module_graph_creator().await?; - let specifiers = self.checked_specifiers().collect::>(); + let specifiers = self.specifiers().collect::>(); let graph = module_graph_creator .create_graph( graph_kind, @@ -1387,7 +1390,7 @@ impl CliFactoryWithWorkspaceFiles { pub async fn check(&self) -> Result<(), AnyError> { let main_graph_container = self.inner.main_module_graph_container().await?.clone(); - let specifiers = self.checked_specifiers().cloned().collect::>(); + let specifiers = self.specifiers().cloned().collect::>(); if specifiers.is_empty() { return Ok(()); } diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index b245fa360f..e18cb13183 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -289,9 +289,9 @@ async fn bench_specifiers( options: BenchSpecifierOptions, ) -> Result<(), AnyError> { let specifiers = if let Some(changed_paths) = changed_paths { - factory.dependent_checked_specifiers(changed_paths).await? + factory.dependent_specifiers(changed_paths).await? } else { - factory.checked_specifiers().collect() + factory.specifiers().collect() }; let worker_factory = Arc::new(factory.inner.create_cli_main_worker_factory().await?); @@ -452,8 +452,8 @@ pub async fn run_benchmarks( |patterns, cli_options, _, _| { async move { let info = SpecifierInfo { - check: true, - check_doc: false, + include: true, + include_doc: false, }; collect_specifiers( patterns, @@ -525,8 +525,8 @@ pub async fn run_benchmarks_with_watch( |patterns, cli_options, _, _| { async move { let info = SpecifierInfo { - check: true, - check_doc: false, + include: true, + include_doc: false, }; collect_specifiers( patterns, diff --git a/cli/tools/check.rs b/cli/tools/check.rs index aa29a9448d..a5fa1abae3 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -67,8 +67,8 @@ pub async fn check( |patterns, cli_options, _, (doc, doc_only)| { async move { let info = SpecifierInfo { - check: !doc_only, - check_doc: doc || doc_only, + include: !doc_only, + include_doc: doc || doc_only, }; collect_specifiers( patterns, diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 7573efb709..8fe81f405f 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1185,9 +1185,9 @@ async fn test_specifiers( options: TestSpecifiersOptions, ) -> Result<(), AnyError> { let mut specifiers = if let Some(changed_paths) = changed_paths { - factory.dependent_checked_specifiers(changed_paths).await? + factory.dependent_specifiers(changed_paths).await? } else { - factory.checked_specifiers().collect() + factory.specifiers().collect() }; if let Some(seed) = options.specifier.shuffle { let mut rng = SmallRng::seed_from_u64(seed); @@ -1467,8 +1467,8 @@ pub async fn collect_specifiers_for_tests( .into_iter() .map(|specifier| { let info = SpecifierInfo { - check: module_specifiers.contains(&specifier), - check_doc: true, + include: module_specifiers.contains(&specifier), + include_doc: true, }; (specifier, info) }) @@ -1476,8 +1476,8 @@ pub async fn collect_specifiers_for_tests( })? } else { let info = SpecifierInfo { - check: true, - check_doc: false, + include: true, + include_doc: false, }; module_specifiers .into_iter() @@ -1488,7 +1488,7 @@ pub async fn collect_specifiers_for_tests( let file = file_fetcher.fetch_bypass_permissions(specifier).await?; let (media_type, _) = file.resolve_media_type_and_charset(); if matches!(media_type, MediaType::Unknown | MediaType::Dts) { - info.check = false; + info.include = false; } } Ok(specifiers)