0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-07 23:06:50 -05:00

don't store specifier info

This commit is contained in:
Nayeem Rahman 2025-01-20 09:26:08 +00:00
parent 766452fca4
commit 1e073ee1d6
4 changed files with 34 additions and 31 deletions

View file

@ -1233,17 +1233,17 @@ impl CliFactory {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct SpecifierInfo { pub struct SpecifierInfo {
/// Type check as an ES module. /// Include as an ES module.
pub check: bool, pub include: bool,
/// Type check virtual modules from doc snippets. If this is set but `check` /// Type check virtual modules from doc snippets. If this is set but `check`
/// is not, this may be a markdown file for example. /// is not, this may be a markdown file for example.
pub check_doc: bool, pub include_doc: bool,
} }
pub struct CliFactoryWithWorkspaceFiles { pub struct CliFactoryWithWorkspaceFiles {
pub inner: CliFactory, pub inner: CliFactory,
pub cli_options: Arc<CliOptions>, pub cli_options: Arc<CliOptions>,
specifiers: Vec<(ModuleSpecifier, SpecifierInfo)>, file_specifiers: Vec<ModuleSpecifier>,
doc_snippet_specifiers: Vec<ModuleSpecifier>, doc_snippet_specifiers: Vec<ModuleSpecifier>,
initial_cwd: PathBuf, initial_cwd: PathBuf,
} }
@ -1280,7 +1280,7 @@ impl CliFactoryWithWorkspaceFiles {
let _ = watcher_communicator.watch_paths(cli_options.watch_paths()); let _ = watcher_communicator.watch_paths(cli_options.watch_paths());
} }
workspace_dirs_with_files.sort_by_cached_key(|(d, _)| d.dir_url().clone()); 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(); let mut doc_snippet_specifiers = Vec::new();
for (_, files) in workspace_dirs_with_files { for (_, files) in workspace_dirs_with_files {
if let Some(watcher_communicator) = watcher_communicator { if let Some(watcher_communicator) = watcher_communicator {
@ -1293,7 +1293,7 @@ impl CliFactoryWithWorkspaceFiles {
); );
} }
let file_fetcher = factory.file_fetcher()?; let file_fetcher = factory.file_fetcher()?;
let dir_specifiers = collect_specifiers( let specifiers = collect_specifiers(
files, files,
cli_options.clone(), cli_options.clone(),
file_fetcher.clone(), file_fetcher.clone(),
@ -1302,7 +1302,7 @@ impl CliFactoryWithWorkspaceFiles {
.await?; .await?;
if let Some(extract_doc_files) = extract_doc_files { if let Some(extract_doc_files) = extract_doc_files {
let root_permissions = factory.root_permissions_container()?; 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 file = file_fetcher.fetch(s, root_permissions).await?;
let snippet_files = extract_doc_files(file)?; let snippet_files = extract_doc_files(file)?;
for snippet_file in snippet_files { 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 { Ok(Self {
inner: factory, inner: factory,
cli_options, cli_options,
specifiers, file_specifiers,
doc_snippet_specifiers, doc_snippet_specifiers,
initial_cwd, initial_cwd,
}) })
@ -1327,25 +1331,24 @@ impl CliFactoryWithWorkspaceFiles {
} }
pub fn found_specifiers(&self) -> bool { 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<Item = &ModuleSpecifier> { pub fn specifiers(&self) -> impl Iterator<Item = &ModuleSpecifier> {
self self
.specifiers .file_specifiers
.iter() .iter()
.filter_map(|(s, i)| i.check.then_some(s))
.chain(self.doc_snippet_specifiers.iter()) .chain(self.doc_snippet_specifiers.iter())
} }
pub async fn dependent_checked_specifiers( pub async fn dependent_specifiers(
&self, &self,
canonicalized_dep_paths: &HashSet<PathBuf>, canonicalized_dep_paths: &HashSet<PathBuf>,
) -> Result<Vec<&ModuleSpecifier>, AnyError> { ) -> Result<Vec<&ModuleSpecifier>, AnyError> {
let graph_kind = let graph_kind =
self.inner.cli_options()?.type_check_mode().as_graph_kind(); self.inner.cli_options()?.type_check_mode().as_graph_kind();
let module_graph_creator = self.inner.module_graph_creator().await?; let module_graph_creator = self.inner.module_graph_creator().await?;
let specifiers = self.checked_specifiers().collect::<Vec<_>>(); let specifiers = self.specifiers().collect::<Vec<_>>();
let graph = module_graph_creator let graph = module_graph_creator
.create_graph( .create_graph(
graph_kind, graph_kind,
@ -1387,7 +1390,7 @@ impl CliFactoryWithWorkspaceFiles {
pub async fn check(&self) -> Result<(), AnyError> { pub async fn check(&self) -> Result<(), AnyError> {
let main_graph_container = let main_graph_container =
self.inner.main_module_graph_container().await?.clone(); self.inner.main_module_graph_container().await?.clone();
let specifiers = self.checked_specifiers().cloned().collect::<Vec<_>>(); let specifiers = self.specifiers().cloned().collect::<Vec<_>>();
if specifiers.is_empty() { if specifiers.is_empty() {
return Ok(()); return Ok(());
} }

View file

@ -289,9 +289,9 @@ async fn bench_specifiers(
options: BenchSpecifierOptions, options: BenchSpecifierOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let specifiers = if let Some(changed_paths) = changed_paths { let specifiers = if let Some(changed_paths) = changed_paths {
factory.dependent_checked_specifiers(changed_paths).await? factory.dependent_specifiers(changed_paths).await?
} else { } else {
factory.checked_specifiers().collect() factory.specifiers().collect()
}; };
let worker_factory = let worker_factory =
Arc::new(factory.inner.create_cli_main_worker_factory().await?); Arc::new(factory.inner.create_cli_main_worker_factory().await?);
@ -452,8 +452,8 @@ pub async fn run_benchmarks(
|patterns, cli_options, _, _| { |patterns, cli_options, _, _| {
async move { async move {
let info = SpecifierInfo { let info = SpecifierInfo {
check: true, include: true,
check_doc: false, include_doc: false,
}; };
collect_specifiers( collect_specifiers(
patterns, patterns,
@ -525,8 +525,8 @@ pub async fn run_benchmarks_with_watch(
|patterns, cli_options, _, _| { |patterns, cli_options, _, _| {
async move { async move {
let info = SpecifierInfo { let info = SpecifierInfo {
check: true, include: true,
check_doc: false, include_doc: false,
}; };
collect_specifiers( collect_specifiers(
patterns, patterns,

View file

@ -67,8 +67,8 @@ pub async fn check(
|patterns, cli_options, _, (doc, doc_only)| { |patterns, cli_options, _, (doc, doc_only)| {
async move { async move {
let info = SpecifierInfo { let info = SpecifierInfo {
check: !doc_only, include: !doc_only,
check_doc: doc || doc_only, include_doc: doc || doc_only,
}; };
collect_specifiers( collect_specifiers(
patterns, patterns,

View file

@ -1185,9 +1185,9 @@ async fn test_specifiers(
options: TestSpecifiersOptions, options: TestSpecifiersOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let mut specifiers = if let Some(changed_paths) = changed_paths { let mut specifiers = if let Some(changed_paths) = changed_paths {
factory.dependent_checked_specifiers(changed_paths).await? factory.dependent_specifiers(changed_paths).await?
} else { } else {
factory.checked_specifiers().collect() factory.specifiers().collect()
}; };
if let Some(seed) = options.specifier.shuffle { if let Some(seed) = options.specifier.shuffle {
let mut rng = SmallRng::seed_from_u64(seed); let mut rng = SmallRng::seed_from_u64(seed);
@ -1467,8 +1467,8 @@ pub async fn collect_specifiers_for_tests(
.into_iter() .into_iter()
.map(|specifier| { .map(|specifier| {
let info = SpecifierInfo { let info = SpecifierInfo {
check: module_specifiers.contains(&specifier), include: module_specifiers.contains(&specifier),
check_doc: true, include_doc: true,
}; };
(specifier, info) (specifier, info)
}) })
@ -1476,8 +1476,8 @@ pub async fn collect_specifiers_for_tests(
})? })?
} else { } else {
let info = SpecifierInfo { let info = SpecifierInfo {
check: true, include: true,
check_doc: false, include_doc: false,
}; };
module_specifiers module_specifiers
.into_iter() .into_iter()
@ -1488,7 +1488,7 @@ pub async fn collect_specifiers_for_tests(
let file = file_fetcher.fetch_bypass_permissions(specifier).await?; let file = file_fetcher.fetch_bypass_permissions(specifier).await?;
let (media_type, _) = file.resolve_media_type_and_charset(); let (media_type, _) = file.resolve_media_type_and_charset();
if matches!(media_type, MediaType::Unknown | MediaType::Dts) { if matches!(media_type, MediaType::Unknown | MediaType::Dts) {
info.check = false; info.include = false;
} }
} }
Ok(specifiers) Ok(specifiers)