diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-04-14 16:22:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 16:22:33 -0400 |
commit | 136dce67cec749dce5989ea29e88359ef79a0045 (patch) | |
tree | 38e96bbbf22dc06cdba418a35467b215f1335549 /cli/tsc | |
parent | a4111442191fff300132259752e6d2d5613d1871 (diff) |
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<T>` 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.
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/mod.rs | 16 |
1 files changed, 10 insertions, 6 deletions
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<ModuleGraph>, pub hash_data: u64, - pub maybe_npm_resolver: Option<NpmPackageResolver>, + pub maybe_npm_resolver: Option<Arc<NpmPackageResolver>>, pub maybe_tsbuildinfo: Option<String>, /// A vector of strings that represent the root/entry point modules for the /// program. @@ -331,7 +331,7 @@ struct State { graph: Arc<ModuleGraph>, maybe_tsbuildinfo: Option<String>, maybe_response: Option<RespondArgs>, - maybe_npm_resolver: Option<NpmPackageResolver>, + maybe_npm_resolver: Option<Arc<NpmPackageResolver>>, remapped_specifiers: HashMap<String, ModuleSpecifier>, root_map: HashMap<String, ModuleSpecifier>, current_dir: PathBuf, @@ -341,7 +341,7 @@ impl State { pub fn new( graph: Arc<ModuleGraph>, hash_data: u64, - maybe_npm_resolver: Option<NpmPackageResolver>, + maybe_npm_resolver: Option<Arc<NpmPackageResolver>>, maybe_tsbuildinfo: Option<String>, root_map: HashMap<String, ModuleSpecifier>, remapped_specifiers: HashMap<String, ModuleSpecifier>, @@ -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<NpmPackageResolver>, ) -> Result<(ModuleSpecifier, MediaType), AnyError> { let maybe_resolution = node_resolve_npm_reference( npm_ref, |