summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-04-14 16:22:33 -0400
committerGitHub <noreply@github.com>2023-04-14 16:22:33 -0400
commit136dce67cec749dce5989ea29e88359ef79a0045 (patch)
tree38e96bbbf22dc06cdba418a35467b215f1335549 /cli/tools
parenta4111442191fff300132259752e6d2d5613d1871 (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/tools')
-rw-r--r--cli/tools/bench.rs22
-rw-r--r--cli/tools/bundle.rs8
-rw-r--r--cli/tools/check.rs2
-rw-r--r--cli/tools/coverage/mod.rs3
-rw-r--r--cli/tools/doc.rs5
-rw-r--r--cli/tools/info.rs3
-rw-r--r--cli/tools/installer.rs1
-rw-r--r--cli/tools/standalone.rs10
-rw-r--r--cli/tools/test.rs39
-rw-r--r--cli/tools/vendor/mod.rs11
-rw-r--r--cli/tools/vendor/test.rs17
11 files changed, 69 insertions, 52 deletions
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs
index da80f5b7e..0b6ef8bb1 100644
--- a/cli/tools/bench.rs
+++ b/cli/tools/bench.rs
@@ -422,14 +422,15 @@ async fn check_specifiers(
specifiers: Vec<ModuleSpecifier>,
) -> Result<(), AnyError> {
let lib = ps.options.ts_type_lib_window();
- ps.prepare_module_load(
- specifiers,
- false,
- lib,
- PermissionsContainer::allow_all(),
- PermissionsContainer::new(permissions),
- )
- .await?;
+ ps.module_load_preparer
+ .prepare_module_load(
+ specifiers,
+ false,
+ lib,
+ PermissionsContainer::allow_all(),
+ PermissionsContainer::new(permissions),
+ )
+ .await?;
Ok(())
}
@@ -705,7 +706,10 @@ pub async fn run_benchmarks_with_watch(
} else {
bench_modules.clone()
};
- let graph = ps.create_graph(bench_modules.clone()).await?;
+ let graph = ps
+ .module_graph_builder
+ .create_graph(bench_modules.clone())
+ .await?;
graph_valid_with_cli_options(&graph, &bench_modules, &ps.options)?;
// TODO(@kitsonk) - This should be totally derivable from the graph.
diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs
index 77b4f8a46..26d170d7e 100644
--- a/cli/tools/bundle.rs
+++ b/cli/tools/bundle.rs
@@ -13,7 +13,6 @@ use crate::args::CliOptions;
use crate::args::Flags;
use crate::args::TsConfigType;
use crate::args::TypeCheckMode;
-use crate::graph_util::create_graph_and_maybe_check;
use crate::graph_util::error_for_any_npm_specifier;
use crate::proc_state::ProcState;
use crate::util;
@@ -42,9 +41,10 @@ pub async fn bundle(
async move {
log::debug!(">>>>> bundle START");
let ps = ProcState::from_cli_options(cli_options).await?;
- let graph =
- create_graph_and_maybe_check(vec![module_specifier.clone()], &ps)
- .await?;
+ let graph = ps
+ .module_graph_builder
+ .create_graph_and_maybe_check(vec![module_specifier.clone()])
+ .await?;
let mut paths_to_watch: Vec<PathBuf> = graph
.specifiers()
diff --git a/cli/tools/check.rs b/cli/tools/check.rs
index 91643496a..dcc9b2843 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -56,7 +56,7 @@ pub struct CheckResult {
pub fn check(
graph: Arc<ModuleGraph>,
cache: &TypeCheckCache,
- npm_resolver: &NpmPackageResolver,
+ npm_resolver: Arc<NpmPackageResolver>,
options: CheckOptions,
) -> Result<CheckResult, AnyError> {
let check_js = options.ts_config.get_check_js();
diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs
index 75ee833b0..029778243 100644
--- a/cli/tools/coverage/mod.rs
+++ b/cli/tools/coverage/mod.rs
@@ -697,8 +697,7 @@ pub async fn cover_files(
| MediaType::Mts
| MediaType::Cts
| MediaType::Tsx => {
- let source_hash = ps.emitter.get_source_hash(&file.source);
- match ps.emit_cache.get_emit_code(&file.specifier, source_hash) {
+ match ps.emitter.maybed_cached_emit(&file.specifier, &file.source) {
Some(code) => code.into(),
None => {
return Err(anyhow!(
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index 6b0691827..a07ba175a 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -80,7 +80,10 @@ pub async fn print_docs(
// Save our fake file into file fetcher cache.
ps.file_fetcher.insert_cached(root);
- let graph = ps.create_graph(vec![root_specifier.clone()]).await?;
+ let graph = ps
+ .module_graph_builder
+ .create_graph(vec![root_specifier.clone()])
+ .await?;
if let Some(lockfile) = &ps.lockfile {
graph_lock_or_exit(&graph, &mut lockfile.lock());
diff --git a/cli/tools/info.rs b/cli/tools/info.rs
index a204c7245..69faa10fb 100644
--- a/cli/tools/info.rs
+++ b/cli/tools/info.rs
@@ -36,9 +36,10 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let ps = ProcState::from_flags(flags).await?;
if let Some(specifier) = info_flags.file {
let specifier = resolve_url_or_path(&specifier, ps.options.initial_cwd())?;
- let mut loader = ps.create_graph_loader();
+ let mut loader = ps.module_graph_builder.create_graph_loader();
loader.enable_loading_cache_info(); // for displaying the cache information
let graph = ps
+ .module_graph_builder
.create_graph_with_loader(vec![specifier], &mut loader)
.await?;
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index ec397f78a..461bb1a50 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -235,6 +235,7 @@ pub async fn install_command(
// ensure the module is cached
ProcState::from_flags(flags.clone())
.await?
+ .module_load_preparer
.load_and_type_check_files(&[install_flags.module_url.clone()])
.await?;
diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs
index 29899f0d8..fab3266ea 100644
--- a/cli/tools/standalone.rs
+++ b/cli/tools/standalone.rs
@@ -4,7 +4,6 @@ use crate::args::CaData;
use crate::args::CompileFlags;
use crate::args::Flags;
use crate::cache::DenoDir;
-use crate::graph_util::create_graph_and_maybe_check;
use crate::graph_util::error_for_any_npm_specifier;
use crate::http_util::HttpClient;
use crate::standalone::Metadata;
@@ -56,9 +55,12 @@ pub async fn compile(
)
.await?;
- let graph =
- Arc::try_unwrap(create_graph_and_maybe_check(module_roots, &ps).await?)
- .unwrap();
+ let graph = Arc::try_unwrap(
+ ps.module_graph_builder
+ .create_graph_and_maybe_check(module_roots)
+ .await?,
+ )
+ .unwrap();
// at the moment, we don't support npm specifiers in deno_compile, so show an error
error_for_any_npm_specifier(&graph)?;
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index f90a68561..977073ab7 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -1259,14 +1259,15 @@ pub async fn check_specifiers(
ps.file_fetcher.insert_cached(file);
}
- ps.prepare_module_load(
- specifiers,
- false,
- lib,
- PermissionsContainer::new(Permissions::allow_all()),
- PermissionsContainer::new(permissions.clone()),
- )
- .await?;
+ ps.module_load_preparer
+ .prepare_module_load(
+ specifiers,
+ false,
+ lib,
+ PermissionsContainer::new(Permissions::allow_all()),
+ PermissionsContainer::new(permissions.clone()),
+ )
+ .await?;
}
let module_specifiers = specifiers
@@ -1280,14 +1281,15 @@ pub async fn check_specifiers(
})
.collect();
- ps.prepare_module_load(
- module_specifiers,
- false,
- lib,
- PermissionsContainer::allow_all(),
- PermissionsContainer::new(permissions),
- )
- .await?;
+ ps.module_load_preparer
+ .prepare_module_load(
+ module_specifiers,
+ false,
+ lib,
+ PermissionsContainer::allow_all(),
+ PermissionsContainer::new(permissions),
+ )
+ .await?;
Ok(())
}
@@ -1708,7 +1710,10 @@ pub async fn run_tests_with_watch(
} else {
test_modules.clone()
};
- let graph = ps.create_graph(test_modules.clone()).await?;
+ let graph = ps
+ .module_graph_builder
+ .create_graph(test_modules.clone())
+ .await?;
graph_valid_with_cli_options(&graph, &test_modules, &ps.options)?;
// TODO(@kitsonk) - This should be totally derivable from the graph.
diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs
index 86af7d415..e75b19e2c 100644
--- a/cli/tools/vendor/mod.rs
+++ b/cli/tools/vendor/mod.rs
@@ -65,7 +65,7 @@ pub async fn vendor(
);
if vendored_count > 0 {
let import_map_path = raw_output_dir.join("import_map.json");
- if maybe_update_config_file(&output_dir, &ps) {
+ if maybe_update_config_file(&output_dir, &ps.options) {
log::info!(
concat!(
"\nUpdated your local Deno configuration file with a reference to the ",
@@ -147,15 +147,14 @@ fn validate_options(
Ok(())
}
-fn maybe_update_config_file(output_dir: &Path, ps: &ProcState) -> bool {
+fn maybe_update_config_file(output_dir: &Path, options: &CliOptions) -> bool {
assert!(output_dir.is_absolute());
- let config_file_specifier = match ps.options.maybe_config_file_specifier() {
+ let config_file_specifier = match options.maybe_config_file_specifier() {
Some(f) => f,
None => return false,
};
- let fmt_config = ps
- .options
+ let fmt_config = options
.maybe_config_file()
.as_ref()
.and_then(|config| config.to_fmt_config().ok())
@@ -271,7 +270,7 @@ async fn create_graph(
.map(|p| resolve_url_or_path(p, ps.options.initial_cwd()))
.collect::<Result<Vec<_>, _>>()?;
- ps.create_graph(entry_points).await
+ ps.module_graph_builder.create_graph(entry_points).await
}
#[cfg(test)]
diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs
index c05e088a5..774ff0d58 100644
--- a/cli/tools/vendor/test.rs
+++ b/cli/tools/vendor/test.rs
@@ -263,18 +263,21 @@ async fn build_test_graph(
mut loader: TestLoader,
analyzer: &dyn deno_graph::ModuleAnalyzer,
) -> ModuleGraph {
- let resolver = original_import_map.map(|m| {
- let npm_registry_api = CliNpmRegistryApi::new_uninitialized();
- let npm_resolution =
- NpmResolution::from_serialized(npm_registry_api.clone(), None, None);
- let deps_installer = PackageJsonDepsInstaller::new(
+ let resolver = original_import_map.map(|original_import_map| {
+ let npm_registry_api = Arc::new(CliNpmRegistryApi::new_uninitialized());
+ let npm_resolution = Arc::new(NpmResolution::from_serialized(
+ npm_registry_api.clone(),
+ None,
+ None,
+ ));
+ let deps_installer = Arc::new(PackageJsonDepsInstaller::new(
npm_registry_api.clone(),
npm_resolution.clone(),
None,
- );
+ ));
CliGraphResolver::new(
None,
- Some(Arc::new(m)),
+ Some(Arc::new(original_import_map)),
false,
npm_registry_api,
npm_resolution,