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/worker.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/worker.rs')
-rw-r--r-- | cli/worker.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/cli/worker.rs b/cli/worker.rs index 018bee768..30092cff4 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -184,7 +184,8 @@ impl CliMainWorker { &mut self, id: ModuleId, ) -> Result<(), AnyError> { - if self.ps.npm_resolver.has_packages() || self.ps.graph().has_node_specifier + if self.ps.npm_resolver.has_packages() + || self.ps.graph_container.graph().has_node_specifier { self.initialize_main_module_for_node()?; } @@ -270,8 +271,10 @@ pub async fn create_custom_worker( matches!(node_resolution, node::NodeResolution::CommonJs(_)); (node_resolution.into_url(), is_main_cjs) } else if ps.options.is_npm_main() { - let node_resolution = - node::url_to_node_resolution(main_module, &ps.npm_resolver)?; + let node_resolution = node::url_to_node_resolution( + main_module, + &ps.npm_resolver.as_require_npm_resolver(), + )?; let is_main_cjs = matches!(node_resolution, node::NodeResolution::CommonJs(_)); (node_resolution.into_url(), is_main_cjs) @@ -350,7 +353,7 @@ pub async fn create_custom_worker( should_break_on_first_statement: ps.options.inspect_brk().is_some(), should_wait_for_inspector_session: ps.options.inspect_wait().is_some(), module_loader, - npm_resolver: Some(Rc::new(ps.npm_resolver.clone())), + npm_resolver: Some(Rc::new(ps.npm_resolver.as_require_npm_resolver())), get_error_class_fn: Some(&errors::get_error_class_name), cache_storage_dir, origin_storage_dir, @@ -473,7 +476,7 @@ fn create_web_worker_callback( format_js_error_fn: Some(Arc::new(format_js_error)), source_map_getter: Some(Box::new(module_loader.clone())), module_loader, - npm_resolver: Some(Rc::new(ps.npm_resolver.clone())), + npm_resolver: Some(Rc::new(ps.npm_resolver.as_require_npm_resolver())), worker_type: args.worker_type, maybe_inspector_server, get_error_class_fn: Some(&errors::get_error_class_name), |