diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-03 20:54:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-04 00:54:33 +0000 |
commit | 147411e64b22fe74cb258125acab83f9182c9f81 (patch) | |
tree | a1f63dcbf0404c20534986b10f02b649df5a3ad5 /cli/graph_util.rs | |
parent | dd6d19e12051fac2ea5639f621501f4710a1b8e1 (diff) |
feat: npm workspace and better Deno workspace support (#24334)
Adds much better support for the unstable Deno workspaces as well as
support for npm workspaces. npm workspaces is still lacking in that we
only install packages into the root node_modules folder. We'll make it
smarter over time in order for it to figure out when to add node_modules
folders within packages.
This includes a breaking change in config file resolution where we stop
searching for config files on the first found package.json unless it's
in a workspace. For the previous behaviour, the root deno.json needs to
be updated to be a workspace by adding `"workspace":
["./path-to-pkg-json-folder-goes-here"]`. See details in
https://github.com/denoland/deno_config/pull/66
Closes #24340
Closes #24159
Closes #24161
Closes #22020
Closes #18546
Closes #16106
Closes #24160
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r-- | cli/graph_util.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs index f1e98e7c6..2f9ee8d93 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use crate::args::config_to_deno_graph_workspace_member; use crate::args::jsr_url; use crate::args::CliLockfile; use crate::args::CliOptions; @@ -18,12 +19,13 @@ use crate::tools::check; use crate::tools::check::TypeChecker; use crate::util::file_watcher::WatcherCommunicator; use crate::util::fs::canonicalize_path; +use deno_config::workspace::JsrPackageConfig; use deno_emit::LoaderChecksum; use deno_graph::JsrLoadError; use deno_graph::ModuleLoadError; +use deno_graph::WorkspaceFastCheckOption; use deno_runtime::fs_util::specifier_to_file_path; -use deno_config::WorkspaceMemberConfig; use deno_core::anyhow::bail; use deno_core::error::custom_error; use deno_core::error::AnyError; @@ -240,12 +242,12 @@ impl ModuleGraphCreator { pub async fn create_and_validate_publish_graph( &self, - packages: &[WorkspaceMemberConfig], + package_configs: &[JsrPackageConfig], build_fast_check_graph: bool, ) -> Result<ModuleGraph, AnyError> { let mut roots = Vec::new(); - for package in packages { - roots.extend(package.config_file.resolve_export_value_urls()?); + for package_config in package_configs { + roots.extend(package_config.config_file.resolve_export_value_urls()?); } let mut graph = self .create_graph_with_options(CreateGraphOptions { @@ -260,10 +262,16 @@ impl ModuleGraphCreator { self.type_check_graph(graph.clone()).await?; } if build_fast_check_graph { + let fast_check_workspace_members = package_configs + .iter() + .map(|p| config_to_deno_graph_workspace_member(&p.config_file)) + .collect::<Result<Vec<_>, _>>()?; self.module_graph_builder.build_fast_check_graph( &mut graph, BuildFastCheckGraphOptions { - workspace_fast_check: true, + workspace_fast_check: WorkspaceFastCheckOption::Enabled( + &fast_check_workspace_members, + ), }, )?; } @@ -340,10 +348,10 @@ impl ModuleGraphCreator { } } -pub struct BuildFastCheckGraphOptions { +pub struct BuildFastCheckGraphOptions<'a> { /// Whether to do fast check on workspace members. This /// is mostly only useful when publishing. - pub workspace_fast_check: bool, + pub workspace_fast_check: deno_graph::WorkspaceFastCheckOption<'a>, } pub struct ModuleGraphBuilder { @@ -622,7 +630,10 @@ impl ModuleGraphBuilder { } log::debug!("Building fast check graph"); - let fast_check_cache = if !options.workspace_fast_check { + let fast_check_cache = if matches!( + options.workspace_fast_check, + deno_graph::WorkspaceFastCheckOption::Disabled + ) { Some(cache::FastCheckCache::new(self.caches.fast_check_db())) } else { None @@ -631,11 +642,6 @@ impl ModuleGraphBuilder { let cli_resolver = &self.resolver; let graph_resolver = cli_resolver.as_graph_resolver(); let graph_npm_resolver = cli_resolver.create_graph_npm_resolver(); - let workspace_members = if options.workspace_fast_check { - Some(self.options.resolve_deno_graph_workspace_members()?) - } else { - None - }; graph.build_fast_check_type_graph( deno_graph::BuildFastCheckTypeGraphOptions { @@ -645,11 +651,7 @@ impl ModuleGraphBuilder { module_parser: Some(&parser), resolver: Some(graph_resolver), npm_resolver: Some(&graph_npm_resolver), - workspace_fast_check: if let Some(members) = &workspace_members { - deno_graph::WorkspaceFastCheckOption::Enabled(members) - } else { - deno_graph::WorkspaceFastCheckOption::Disabled - }, + workspace_fast_check: options.workspace_fast_check, }, ); Ok(()) |