From 8f5d50c787d824a548dbbba90264b40674c576dd Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 11 Dec 2024 13:48:22 +0000 Subject: [PATCH] private CliOptions::flags again --- cli/args/mod.rs | 20 +++++++++++++++++++- cli/factory.rs | 18 ++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/cli/args/mod.rs b/cli/args/mod.rs index c42dfe07a0..fce65dc6f4 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -811,7 +811,7 @@ pub struct ScopeOptions { pub struct CliOptions { // the source of the options is a detail the rest of the // application need not concern itself with, so keep these private - pub flags: Arc, + flags: Arc, initial_cwd: PathBuf, main_module_cell: std::sync::OnceLock>, maybe_node_modules_folder: Option, @@ -960,6 +960,24 @@ impl CliOptions { ) } + pub fn with_new_start_dir_and_scope_options( + &self, + start_dir: Arc, + scope_options: Option, + ) -> Result { + let (npmrc, _) = discover_npmrc_from_workspace(&start_dir.workspace)?; + let lockfile = CliLockfile::discover(&self.flags, &start_dir.workspace)?; + Self::new( + self.flags.clone(), + self.initial_cwd().to_path_buf(), + lockfile.map(Arc::new), + npmrc, + start_dir, + false, + scope_options.map(Arc::new), + ) + } + /// This method is purposefully verbose to disourage its use. Do not use it /// except in the factory structs. Instead, prefer specific methods on `CliOptions` /// that can take all sources of information into account (ex. config files or env vars). diff --git a/cli/factory.rs b/cli/factory.rs index 49b1af0f6a..ede7c0206a 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -1,10 +1,8 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use crate::args::check_warn_tsconfig; -use crate::args::discover_npmrc_from_workspace; use crate::args::get_root_cert_store; use crate::args::CaData; -use crate::args::CliLockfile; use crate::args::CliOptions; use crate::args::DenoSubcommand; use crate::args::Flags; @@ -1131,24 +1129,16 @@ impl WorkspaceFileContainer { let dir_count = workspace_dirs_with_files.len(); let mut entries = Vec::with_capacity(dir_count); for (workspace_dir, files) in workspace_dirs_with_files { - let (npmrc, _) = discover_npmrc_from_workspace(&workspace_dir.workspace)?; - let lockfile = - CliLockfile::discover(&cli_options.flags, &workspace_dir.workspace)?; let scope_options = (dir_count > 1).then(|| ScopeOptions { scope: workspace_dir .has_deno_or_pkg_json() .then(|| workspace_dir.dir_url().clone()), all_scopes: all_scopes.clone(), }); - let cli_options = Arc::new(CliOptions::new( - cli_options.flags.clone(), - cli_options.initial_cwd().to_path_buf(), - lockfile.map(Arc::new), - npmrc, - workspace_dir, - false, - scope_options.map(Arc::new), - )?); + let cli_options = Arc::new( + cli_options + .with_new_start_dir_and_scope_options(workspace_dir, scope_options)?, + ); let mut factory = CliFactory::from_cli_options(cli_options.clone()); factory.watcher_communicator = watcher_communicator.clone(); let file_fetcher = factory.file_fetcher()?;