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/tools/bench/mod.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/tools/bench/mod.rs')
-rw-r--r-- | cli/tools/bench/mod.rs | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index 0378d6ae2..d801b908c 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -407,7 +407,8 @@ pub async fn run_benchmarks( bench_flags: BenchFlags, ) -> Result<(), AnyError> { let cli_options = CliOptions::from_flags(flags)?; - let bench_options = cli_options.resolve_bench_options(bench_flags)?; + let workspace_bench_options = + cli_options.resolve_workspace_bench_options(&bench_flags); let factory = CliFactory::from_cli_options(Arc::new(cli_options)); let cli_options = factory.cli_options(); // Various bench files should not share the same permissions in terms of @@ -416,11 +417,21 @@ pub async fn run_benchmarks( let permissions = Permissions::from_options(&cli_options.permissions_options()?)?; - let specifiers = collect_specifiers( - bench_options.files, - cli_options.vendor_dir_path().map(ToOwned::to_owned), - is_supported_bench_path, - )?; + let members_with_bench_options = + cli_options.resolve_bench_options_for_members(&bench_flags)?; + let specifiers = members_with_bench_options + .iter() + .map(|(_, bench_options)| { + collect_specifiers( + bench_options.files.clone(), + cli_options.vendor_dir_path().map(ToOwned::to_owned), + is_supported_bench_path, + ) + }) + .collect::<Result<Vec<_>, _>>()? + .into_iter() + .flatten() + .collect::<Vec<_>>(); if specifiers.is_empty() { return Err(generic_error("No bench modules found")); @@ -429,7 +440,7 @@ pub async fn run_benchmarks( let main_graph_container = factory.main_module_graph_container().await?; main_graph_container.check_specifiers(&specifiers).await?; - if bench_options.no_run { + if workspace_bench_options.no_run { return Ok(()); } @@ -441,8 +452,8 @@ pub async fn run_benchmarks( &permissions, specifiers, BenchSpecifierOptions { - filter: TestFilter::from_flag(&bench_options.filter), - json: bench_options.json, + filter: TestFilter::from_flag(&workspace_bench_options.filter), + json: workspace_bench_options.json, log_level, }, ) @@ -472,24 +483,40 @@ pub async fn run_benchmarks_with_watch( let factory = CliFactoryBuilder::new() .build_from_flags_for_watcher(flags, watcher_communicator.clone())?; let cli_options = factory.cli_options(); - let bench_options = cli_options.resolve_bench_options(bench_flags)?; + let workspace_bench_options = + cli_options.resolve_workspace_bench_options(&bench_flags); let _ = watcher_communicator.watch_paths(cli_options.watch_paths()); - if let Some(set) = &bench_options.files.include { - let watch_paths = set.base_paths(); - if !watch_paths.is_empty() { - let _ = watcher_communicator.watch_paths(watch_paths); - } - } let graph_kind = cli_options.type_check_mode().as_graph_kind(); let module_graph_creator = factory.module_graph_creator().await?; - - let bench_modules = collect_specifiers( - bench_options.files.clone(), - cli_options.vendor_dir_path().map(ToOwned::to_owned), - is_supported_bench_path, - )?; + let members_with_bench_options = + cli_options.resolve_bench_options_for_members(&bench_flags)?; + let watch_paths = members_with_bench_options + .iter() + .filter_map(|(_, bench_options)| { + bench_options + .files + .include + .as_ref() + .map(|set| set.base_paths()) + }) + .flatten() + .collect::<Vec<_>>(); + let _ = watcher_communicator.watch_paths(watch_paths); + let collected_bench_modules = members_with_bench_options + .iter() + .map(|(_, bench_options)| { + collect_specifiers( + bench_options.files.clone(), + cli_options.vendor_dir_path().map(ToOwned::to_owned), + is_supported_bench_path, + ) + }) + .collect::<Result<Vec<_>, _>>()? + .into_iter() + .flatten() + .collect::<Vec<_>>(); // Various bench files should not share the same permissions in terms of // `PermissionsContainer` - otherwise granting/revoking permissions in one @@ -498,7 +525,7 @@ pub async fn run_benchmarks_with_watch( Permissions::from_options(&cli_options.permissions_options()?)?; let graph = module_graph_creator - .create_graph(graph_kind, bench_modules) + .create_graph(graph_kind, collected_bench_modules.clone()) .await?; module_graph_creator.graph_valid(&graph)?; let bench_modules = &graph.roots; @@ -524,16 +551,10 @@ pub async fn run_benchmarks_with_watch( let worker_factory = Arc::new(factory.create_cli_main_worker_factory().await?); - // todo(dsherret): why are we collecting specifiers twice in a row? - // Seems like a perf bug. - let specifiers = collect_specifiers( - bench_options.files, - cli_options.vendor_dir_path().map(ToOwned::to_owned), - is_supported_bench_path, - )? - .into_iter() - .filter(|specifier| bench_modules_to_reload.contains(specifier)) - .collect::<Vec<ModuleSpecifier>>(); + let specifiers = collected_bench_modules + .into_iter() + .filter(|specifier| bench_modules_to_reload.contains(specifier)) + .collect::<Vec<ModuleSpecifier>>(); factory .main_module_graph_container() @@ -541,7 +562,7 @@ pub async fn run_benchmarks_with_watch( .check_specifiers(&specifiers) .await?; - if bench_options.no_run { + if workspace_bench_options.no_run { return Ok(()); } @@ -551,8 +572,8 @@ pub async fn run_benchmarks_with_watch( &permissions, specifiers, BenchSpecifierOptions { - filter: TestFilter::from_flag(&bench_options.filter), - json: bench_options.json, + filter: TestFilter::from_flag(&workspace_bench_options.filter), + json: workspace_bench_options.json, log_level, }, ) |