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.
This commit is contained in:
David Sherret 2023-04-14 16:22:33 -04:00 committed by GitHub
parent a411144219
commit 136dce67ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1506 additions and 1285 deletions

View file

@ -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,