From 136dce67cec749dce5989ea29e88359ef79a0045 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 14 Apr 2023 16:22:33 -0400 Subject: refactor: break up `ProcState` (#18707) 1. Breaks up functionality within `ProcState` into several other structs to break out the responsibilities (`ProcState` is only a data struct now). 2. Moves towards being able to inject dependencies more easily and have functionality only require what it needs. 3. Exposes `Arc` around the "service structs" instead of it being embedded within them. The idea behind embedding them was to reduce the verbosity of needing to pass around `Arc<...>`, but I don't think it was exactly working and as we move more of these structs to be more injectable I don't think the extra verbosity will be a big deal. --- cli/tsc/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'cli/tsc') diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 919bad0b1..eaa7aba36 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -307,7 +307,7 @@ pub struct Request { pub debug: bool, pub graph: Arc, pub hash_data: u64, - pub maybe_npm_resolver: Option, + pub maybe_npm_resolver: Option>, pub maybe_tsbuildinfo: Option, /// A vector of strings that represent the root/entry point modules for the /// program. @@ -331,7 +331,7 @@ struct State { graph: Arc, maybe_tsbuildinfo: Option, maybe_response: Option, - maybe_npm_resolver: Option, + maybe_npm_resolver: Option>, remapped_specifiers: HashMap, root_map: HashMap, current_dir: PathBuf, @@ -341,7 +341,7 @@ impl State { pub fn new( graph: Arc, hash_data: u64, - maybe_npm_resolver: Option, + maybe_npm_resolver: Option>, maybe_tsbuildinfo: Option, root_map: HashMap, remapped_specifiers: HashMap, @@ -649,7 +649,11 @@ fn resolve_graph_specifier_types( let specifier = node::resolve_specifier_into_node_modules(&module.specifier); NodeResolution::into_specifier_and_media_type( - node::url_to_node_resolution(specifier, npm_resolver).ok(), + node::url_to_node_resolution( + specifier, + &npm_resolver.as_require_npm_resolver(), + ) + .ok(), ) })) } @@ -673,7 +677,7 @@ fn resolve_non_graph_specifier_types( specifier, referrer, NodeResolutionMode::Types, - npm_resolver, + &npm_resolver.as_require_npm_resolver(), &mut PermissionsContainer::allow_all(), ) .ok() @@ -697,7 +701,7 @@ fn resolve_non_graph_specifier_types( pub fn resolve_npm_package_reference_types( npm_ref: &NpmPackageNvReference, - npm_resolver: &NpmPackageResolver, + npm_resolver: &Arc, ) -> Result<(ModuleSpecifier, MediaType), AnyError> { let maybe_resolution = node_resolve_npm_reference( npm_ref, -- cgit v1.2.3