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/resolver.rs | |
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/resolver.rs')
-rw-r--r-- | cli/resolver.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/cli/resolver.rs b/cli/resolver.rs index b428204aa..113a06fe7 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -27,15 +27,15 @@ use crate::util::sync::AtomicFlag; /// A resolver that takes care of resolution, taking into account loaded /// import map, JSX settings. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct CliGraphResolver { maybe_import_map: Option<Arc<ImportMap>>, maybe_default_jsx_import_source: Option<String>, maybe_jsx_import_source_module: Option<String>, no_npm: bool, - npm_registry_api: CliNpmRegistryApi, - npm_resolution: NpmResolution, - package_json_deps_installer: PackageJsonDepsInstaller, + npm_registry_api: Arc<CliNpmRegistryApi>, + npm_resolution: Arc<NpmResolution>, + package_json_deps_installer: Arc<PackageJsonDepsInstaller>, found_package_json_dep_flag: Arc<AtomicFlag>, sync_download_queue: Option<Arc<TaskQueue>>, } @@ -44,9 +44,12 @@ impl Default for CliGraphResolver { fn default() -> Self { // This is not ideal, but necessary for the LSP. In the future, we should // refactor the LSP and force this to be initialized. - let npm_registry_api = CliNpmRegistryApi::new_uninitialized(); - let npm_resolution = - NpmResolution::from_serialized(npm_registry_api.clone(), None, None); + let npm_registry_api = Arc::new(CliNpmRegistryApi::new_uninitialized()); + let npm_resolution = Arc::new(NpmResolution::from_serialized( + npm_registry_api.clone(), + None, + None, + )); Self { maybe_import_map: Default::default(), maybe_default_jsx_import_source: Default::default(), @@ -66,9 +69,9 @@ impl CliGraphResolver { maybe_jsx_import_source_config: Option<JsxImportSourceConfig>, maybe_import_map: Option<Arc<ImportMap>>, no_npm: bool, - npm_registry_api: CliNpmRegistryApi, - npm_resolution: NpmResolution, - package_json_deps_installer: PackageJsonDepsInstaller, + npm_registry_api: Arc<CliNpmRegistryApi>, + npm_resolution: Arc<NpmResolution>, + package_json_deps_installer: Arc<PackageJsonDepsInstaller>, ) -> Self { Self { maybe_import_map, |