1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 13:00:36 -05:00

workspace_files

This commit is contained in:
Nayeem Rahman 2025-01-20 10:13:42 +00:00
parent 1dd361492d
commit 798f733c09

View file

@ -1240,11 +1240,16 @@ pub struct SpecifierInfo {
pub include_doc: bool, pub include_doc: bool,
} }
struct WorkspaceFile {
specifier: ModuleSpecifier,
doc_snippet_specifiers: Vec<ModuleSpecifier>,
doc_only: bool,
}
pub struct CliFactoryWithWorkspaceFiles { pub struct CliFactoryWithWorkspaceFiles {
pub inner: CliFactory, pub inner: CliFactory,
pub cli_options: Arc<CliOptions>, pub cli_options: Arc<CliOptions>,
file_specifiers: Vec<ModuleSpecifier>, workspace_files: Vec<WorkspaceFile>,
doc_snippet_specifiers: Vec<ModuleSpecifier>,
} }
impl CliFactoryWithWorkspaceFiles { impl CliFactoryWithWorkspaceFiles {
@ -1278,8 +1283,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 file_specifiers = Vec::new(); let mut workspace_files = 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 {
let _ = watcher_communicator.watch_paths( let _ = watcher_communicator.watch_paths(
@ -1298,40 +1302,44 @@ impl CliFactoryWithWorkspaceFiles {
args.clone(), args.clone(),
) )
.await?; .await?;
if let Some(extract_doc_files) = extract_doc_files { workspace_files.reserve_exact(specifiers.len());
let root_permissions = factory.root_permissions_container()?; for (specifier, info) in &specifiers {
for (s, _) in specifiers.iter().filter(|(_, i)| i.include_doc) { let mut doc_snippet_specifiers = Vec::new();
let file = file_fetcher.fetch(s, root_permissions).await?; if info.include_doc {
let snippet_files = extract_doc_files(file)?; if let Some(extract_doc_files) = extract_doc_files {
for snippet_file in snippet_files { let root_permissions = factory.root_permissions_container()?;
doc_snippet_specifiers.push(snippet_file.url.clone()); let file = file_fetcher.fetch(specifier, root_permissions).await?;
file_fetcher.insert_memory_files(snippet_file); let snippet_files = extract_doc_files(file)?;
for snippet_file in snippet_files {
doc_snippet_specifiers.push(snippet_file.url.clone());
file_fetcher.insert_memory_files(snippet_file);
}
} }
} }
workspace_files.push(WorkspaceFile {
specifier: specifier.clone(),
doc_snippet_specifiers,
doc_only: !info.include,
})
} }
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,
file_specifiers, workspace_files,
doc_snippet_specifiers,
}) })
} }
pub fn found_specifiers(&self) -> bool { pub fn found_specifiers(&self) -> bool {
!self.file_specifiers.is_empty() || !self.doc_snippet_specifiers.is_empty() !self.workspace_files.is_empty()
} }
pub fn specifiers(&self) -> impl Iterator<Item = &ModuleSpecifier> { pub fn specifiers(&self) -> impl Iterator<Item = &ModuleSpecifier> {
self self.workspace_files.iter().flat_map(|f| {
.file_specifiers std::iter::once(&f.specifier)
.iter() .filter(|_| !f.doc_only)
.chain(self.doc_snippet_specifiers.iter()) .chain(f.doc_snippet_specifiers.iter())
})
} }
pub async fn dependent_specifiers( pub async fn dependent_specifiers(
@ -1341,20 +1349,24 @@ impl CliFactoryWithWorkspaceFiles {
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.specifiers().collect::<Vec<_>>();
let graph = module_graph_creator let graph = module_graph_creator
.create_graph( .create_graph(
graph_kind, graph_kind,
specifiers.iter().map(|&s| s.clone()).collect(), self
.workspace_files
.iter()
.map(|f| f.specifier.clone())
.collect(),
crate::graph_util::NpmCachingStrategy::Eager, crate::graph_util::NpmCachingStrategy::Eager,
) )
.await?; .await?;
module_graph_creator.graph_valid(&graph)?; module_graph_creator.graph_valid(&graph)?;
let dependent_specifiers = specifiers let dependent_specifiers = self
.into_iter() .workspace_files
.filter(|s| { .iter()
.filter(|f| {
let mut dependency_specifiers = graph.walk( let mut dependency_specifiers = graph.walk(
std::iter::once(*s), std::iter::once(&f.specifier),
deno_graph::WalkOptions { deno_graph::WalkOptions {
follow_dynamic: true, follow_dynamic: true,
kind: deno_graph::GraphKind::All, kind: deno_graph::GraphKind::All,
@ -1376,6 +1388,11 @@ impl CliFactoryWithWorkspaceFiles {
} }
false false
}) })
.flat_map(|f| {
std::iter::once(&f.specifier)
.filter(|_| !f.doc_only)
.chain(f.doc_snippet_specifiers.iter())
})
.collect(); .collect();
Ok(dependent_specifiers) Ok(dependent_specifiers)
} }