mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
workspace_files
This commit is contained in:
parent
1dd361492d
commit
798f733c09
1 changed files with 47 additions and 30 deletions
|
@ -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,10 +1302,13 @@ impl CliFactoryWithWorkspaceFiles {
|
||||||
args.clone(),
|
args.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
workspace_files.reserve_exact(specifiers.len());
|
||||||
|
for (specifier, info) in &specifiers {
|
||||||
|
let mut doc_snippet_specifiers = Vec::new();
|
||||||
|
if info.include_doc {
|
||||||
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 specifiers.iter().filter(|(_, i)| i.include_doc) {
|
let file = file_fetcher.fetch(specifier, 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 {
|
||||||
doc_snippet_specifiers.push(snippet_file.url.clone());
|
doc_snippet_specifiers.push(snippet_file.url.clone());
|
||||||
|
@ -1309,29 +1316,30 @@ impl CliFactoryWithWorkspaceFiles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_specifiers.extend(
|
workspace_files.push(WorkspaceFile {
|
||||||
specifiers
|
specifier: specifier.clone(),
|
||||||
.into_iter()
|
doc_snippet_specifiers,
|
||||||
.filter_map(|(s, i)| i.include.then_some(s)),
|
doc_only: !info.include,
|
||||||
);
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue