From 654e177c919babe4eef4c1c9545ef267b23884e6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 24 Jan 2023 14:23:19 +0100 Subject: [PATCH] refactor(deno_graph): remove unused Resolved::Ok#kind usage (#17504) See https://github.com/denoland/deno_graph/pull/205 for more details. --- Cargo.lock | 16 +++++----- cli/Cargo.toml | 8 ++--- cli/graph_util.rs | 29 ++++++------------- cli/lsp/documents.rs | 4 +-- cli/lsp/language_server.rs | 14 +++------ cli/npm/resolution/specifier.rs | 17 ++++------- cli/proc_state.rs | 22 +++++--------- cli/resolver.rs | 18 ++++-------- cli/standalone.rs | 2 +- .../testdata/bundle/shebang_file.bundle.out | 2 +- cli/tools/bench.rs | 22 ++++---------- cli/tools/bundle.rs | 23 ++------------- cli/tools/check.rs | 9 +++--- cli/tools/doc.rs | 7 ++--- cli/tools/info.rs | 5 ++-- cli/tools/repl/session.rs | 4 +-- cli/tools/test.rs | 24 ++++----------- cli/tools/vendor/mod.rs | 7 ++--- cli/tools/vendor/test.rs | 9 ++---- cli/tsc/mod.rs | 5 ++-- 20 files changed, 75 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d2e2c01bc..2832b4abc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,9 +972,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.52.0" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a4d646da7094c8c4005c1ecfeb9649a1f3875e5e964a1ecf6d44899c5692ebb" +checksum = "9d792edabc692d89ab24cb4fa0f24cd8d71288669962e867b4634a28d04935bd" dependencies = [ "cfg-if", "deno_ast", @@ -990,9 +990,9 @@ dependencies = [ [[package]] name = "deno_emit" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d7152339bef69b44316be53d6b34cf40718c3084a22565d729b4131c53f462" +checksum = "9abbf7099beedb52d5d84cef071825f1abf75234d48c820b15dbd4e47576b64c" dependencies = [ "anyhow", "base64", @@ -1054,9 +1054,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88980ad969ef1922782f4b19159bb3c46919e883292f1c71ddc3bcd8ba1a5a46" +checksum = "f469b4a0694cb7e7fd512f23bc10d32398d7228cd2581a262109359c8e263940" dependencies = [ "anyhow", "cfg-if", @@ -1657,9 +1657,9 @@ dependencies = [ [[package]] name = "eszip" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584906c722ca9751a4e1dd1fde7ca3387e2af2b4b3608e8d44bd29f22095a4a2" +checksum = "98d6b4f119df606d3cdce5b251b326b6f5cc9a5c59054d701ca973c23f90f7b4" dependencies = [ "anyhow", "base64", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index a9b546224f..9ef5e93dda 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -44,9 +44,9 @@ winres.workspace = true [dependencies] deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_core.workspace = true -deno_doc = "0.52.0" -deno_emit = "0.13.0" -deno_graph = "0.41.0" +deno_doc = "0.53.0" +deno_emit = "0.14.0" +deno_graph = "0.42.0" deno_lint = { version = "0.37.0", features = ["docs"] } deno_lockfile.workspace = true deno_runtime.workspace = true @@ -69,7 +69,7 @@ dprint-plugin-markdown = "=0.15.2" dprint-plugin-typescript = "=0.80.2" encoding_rs.workspace = true env_logger = "=0.9.0" -eszip = "=0.32.0" +eszip = "=0.33.0" fancy-regex = "=0.10.0" flate2.workspace = true http.workspace = true diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 35eaae1274..22bddf137e 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -25,7 +25,6 @@ use deno_graph::GraphImport; use deno_graph::MediaType; use deno_graph::ModuleGraph; use deno_graph::ModuleGraphError; -use deno_graph::ModuleKind; use deno_graph::Range; use deno_graph::Resolved; use deno_runtime::permissions::PermissionsContainer; @@ -35,13 +34,6 @@ use std::collections::HashSet; use std::collections::VecDeque; use std::sync::Arc; -pub fn contains_specifier( - v: &[(ModuleSpecifier, ModuleKind)], - specifier: &ModuleSpecifier, -) -> bool { - v.iter().any(|(s, _)| s == specifier) -} - #[derive(Debug, Clone)] #[allow(clippy::large_enum_variant)] pub enum ModuleEntry { @@ -175,7 +167,7 @@ impl GraphData { /// Return `None` if any modules are not known. pub fn walk<'a>( &'a self, - roots: &[(ModuleSpecifier, ModuleKind)], + roots: &[ModuleSpecifier], follow_dynamic: bool, follow_type_only: bool, check_js: bool, @@ -183,7 +175,7 @@ impl GraphData { let mut result = HashMap::<&'a ModuleSpecifier, &'a ModuleEntry>::new(); let mut seen = HashSet::<&ModuleSpecifier>::new(); let mut visiting = VecDeque::<&ModuleSpecifier>::new(); - for (root, _) in roots { + for root in roots { seen.insert(root); visiting.push_back(root); } @@ -274,10 +266,7 @@ impl GraphData { /// Clone part of `self`, containing only modules which are dependencies of /// `roots`. Returns `None` if any roots are not known. - pub fn graph_segment( - &self, - roots: &[(ModuleSpecifier, ModuleKind)], - ) -> Option { + pub fn graph_segment(&self, roots: &[ModuleSpecifier]) -> Option { let mut modules = HashMap::new(); let mut referrer_map = HashMap::new(); let entries = match self.walk(roots, true, true, true) { @@ -305,7 +294,7 @@ impl GraphData { /// not known. pub fn check( &self, - roots: &[(ModuleSpecifier, ModuleKind)], + roots: &[ModuleSpecifier], follow_type_only: bool, check_js: bool, ) -> Option> { @@ -365,7 +354,7 @@ impl GraphData { } } ModuleEntry::Error(error) => { - if !contains_specifier(roots, specifier) { + if !roots.contains(specifier) { if let Some(range) = self.referrer_map.get(specifier) { if !range.specifier.as_str().contains("$deno") { let message = error.to_string(); @@ -388,7 +377,7 @@ impl GraphData { /// Assumes that all of those modules are known. pub fn set_type_checked( &mut self, - roots: &[(ModuleSpecifier, ModuleKind)], + roots: &[ModuleSpecifier], lib: TsTypeLib, ) { let specifiers: Vec = @@ -408,10 +397,10 @@ impl GraphData { /// Check if `roots` are all marked as type checked under `lib`. pub fn is_type_checked( &self, - roots: &[(ModuleSpecifier, ModuleKind)], + roots: &[ModuleSpecifier], lib: &TsTypeLib, ) -> bool { - roots.iter().all(|(r, _)| { + roots.iter().all(|r| { let found = self.follow_redirect(r); match self.modules.get(&found) { Some(ModuleEntry::Module { checked_libs, .. }) => { @@ -527,7 +516,7 @@ pub async fn create_graph_and_maybe_check( let analyzer = ps.parsed_source_cache.as_analyzer(); let graph = Arc::new( deno_graph::create_graph( - vec![(root, deno_graph::ModuleKind::Esm)], + vec![root], &mut cache, deno_graph::GraphOptions { is_dynamic: false, diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 0e3cb2a7fe..bc1e4a808d 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -876,7 +876,7 @@ impl Documents { ) -> bool { let maybe_resolver = self.get_maybe_resolver(); let maybe_specifier = if let Some(resolver) = maybe_resolver { - resolver.resolve(specifier, referrer).to_result().ok() + resolver.resolve(specifier, referrer).ok() } else { deno_core::resolve_import(specifier, referrer.as_str()).ok() }; @@ -1318,7 +1318,7 @@ fn lsp_deno_graph_analyze( specifier, maybe_headers, content, - Some(&deno_graph::ModuleKind::Esm), + Some(deno_graph::ModuleKind::Esm), maybe_resolver, Some(&analyzer), ), diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index b90f613e9f..68f2447c15 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -8,7 +8,6 @@ use deno_core::serde_json; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::ModuleSpecifier; -use deno_graph::ModuleKind; use import_map::ImportMap; use log::error; use log::warn; @@ -158,7 +157,7 @@ impl LanguageServer { ) -> LspResult> { async fn create_graph_for_caching( cli_options: CliOptions, - roots: Vec<(ModuleSpecifier, ModuleKind)>, + roots: Vec, open_docs: Vec, ) -> Result<(), AnyError> { let open_docs = open_docs @@ -2917,7 +2916,7 @@ impl tower_lsp::LanguageServer for LanguageServer { struct PrepareCacheResult { cli_options: CliOptions, - roots: Vec<(ModuleSpecifier, ModuleKind)>, + roots: Vec, open_docs: Vec, mark: PerformanceMark, } @@ -2938,15 +2937,10 @@ impl Inner { params .uris .iter() - .map(|t| { - ( - self.url_map.normalize_url(&t.uri), - deno_graph::ModuleKind::Esm, - ) - }) + .map(|t| self.url_map.normalize_url(&t.uri)) .collect() } else { - vec![(referrer, deno_graph::ModuleKind::Esm)] + vec![referrer] }; let mut cli_options = CliOptions::new( diff --git a/cli/npm/resolution/specifier.rs b/cli/npm/resolution/specifier.rs index 06efac156b..9a7f67cf8a 100644 --- a/cli/npm/resolution/specifier.rs +++ b/cli/npm/resolution/specifier.rs @@ -280,7 +280,7 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec { let root_specifiers = graph .roots .iter() - .map(|(url, _)| graph.resolve(url)) + .map(|url| graph.resolve(url)) .collect::>(); let mut seen = HashSet::new(); let mut specifier_graph = SpecifierTree::default(); @@ -551,7 +551,6 @@ fn cmp_package_req(a: &NpmPackageReq, b: &NpmPackageReq) -> Ordering { #[cfg(test)] mod tests { - use deno_graph::ModuleKind; use pretty_assertions::assert_eq; use super::*; @@ -965,16 +964,10 @@ mod tests { let analyzer = deno_graph::CapturingModuleAnalyzer::default(); let graph = deno_graph::create_graph( vec![ - ( - ModuleSpecifier::parse("file:///dev/local_module_a/mod.ts").unwrap(), - ModuleKind::Esm, - ), - ( - // test redirect at root - ModuleSpecifier::parse("https://deno.land/x/module_redirect/mod.ts") - .unwrap(), - ModuleKind::Esm, - ), + ModuleSpecifier::parse("file:///dev/local_module_a/mod.ts").unwrap(), + // test redirect at root + ModuleSpecifier::parse("https://deno.land/x/module_redirect/mod.ts") + .unwrap(), ], &mut loader, deno_graph::GraphOptions { diff --git a/cli/proc_state.rs b/cli/proc_state.rs index b3c3b90cd1..16e80d6f6e 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -52,7 +52,6 @@ use deno_graph::source::CacheInfo; use deno_graph::source::LoadFuture; use deno_graph::source::Loader; use deno_graph::source::Resolver; -use deno_graph::ModuleKind; use deno_graph::Resolved; use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel; use deno_runtime::deno_node::NodeResolutionMode; @@ -330,10 +329,6 @@ impl ProcState { let has_root_npm_specifier = roots.iter().any(|r| { r.scheme() == "npm" && NpmPackageReference::from_specifier(r).is_ok() }); - let roots = roots - .into_iter() - .map(|s| (s, ModuleKind::Esm)) - .collect::>(); if !has_root_npm_specifier { let graph_data = self.graph_data.read(); @@ -451,11 +446,10 @@ impl ProcState { drop(_pb_clear_guard); // type check if necessary - let is_std_node = roots.len() == 1 && roots[0].0 == *node::MODULE_ALL_URL; + let is_std_node = roots.len() == 1 && roots[0] == *node::MODULE_ALL_URL; if self.options.type_check_mode() != TypeCheckMode::None && !is_std_node { log::debug!("Type checking."); let maybe_config_specifier = self.options.maybe_config_file_specifier(); - let roots = roots.clone(); let options = check::CheckOptions { type_check_mode: self.options.type_check_mode(), debug: self.options.log_level() == Some(log::Level::Debug), @@ -466,7 +460,7 @@ impl ProcState { .ts_config, log_checks: true, reload: self.options.reload_flag() - && !roots.iter().all(|r| reload_exclusions.contains(&r.0)), + && !roots.iter().all(|r| reload_exclusions.contains(r)), }; let check_cache = TypeCheckCache::new(&self.dir.type_checking_cache_db_file_path()); @@ -530,7 +524,7 @@ impl ProcState { } let node_std_graph = self - .create_graph(vec![(node::MODULE_ALL_URL.clone(), ModuleKind::Esm)]) + .create_graph(vec![node::MODULE_ALL_URL.clone()]) .await?; self.graph_data.write().add_graph(&node_std_graph); self.node_std_graph_prepared.store(true, Ordering::Relaxed); @@ -636,9 +630,7 @@ impl ProcState { let specifier = self .maybe_resolver .as_ref() - .and_then(|resolver| { - resolver.resolve(specifier, &referrer).to_result().ok() - }) + .and_then(|resolver| resolver.resolve(specifier, &referrer).ok()) .or_else(|| ModuleSpecifier::parse(specifier).ok()); if let Some(specifier) = specifier { if let Ok(reference) = NpmPackageReference::from_specifier(&specifier) { @@ -655,7 +647,7 @@ impl ProcState { } if let Some(resolver) = &self.maybe_resolver { - resolver.resolve(specifier, &referrer).to_result() + resolver.resolve(specifier, &referrer) } else { deno_core::resolve_import(specifier, referrer.as_str()) .map_err(|err| err.into()) @@ -705,7 +697,7 @@ impl ProcState { pub async fn create_graph( &self, - roots: Vec<(ModuleSpecifier, ModuleKind)>, + roots: Vec, ) -> Result { let mut cache = self.create_graph_loader(); self.create_graph_with_loader(roots, &mut cache).await @@ -713,7 +705,7 @@ impl ProcState { pub async fn create_graph_with_loader( &self, - roots: Vec<(ModuleSpecifier, ModuleKind)>, + roots: Vec, loader: &mut dyn Loader, ) -> Result { let maybe_imports = self.options.to_maybe_imports()?; diff --git a/cli/resolver.rs b/cli/resolver.rs index ec46165e02..817b5d3b08 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -1,8 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use deno_core::error::AnyError; use deno_core::resolve_import; use deno_core::ModuleSpecifier; -use deno_graph::source::ResolveResponse; use deno_graph::source::Resolver; use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE; use import_map::ImportMap; @@ -63,19 +63,13 @@ impl Resolver for CliResolver { &self, specifier: &str, referrer: &ModuleSpecifier, - ) -> ResolveResponse { + ) -> Result { if let Some(import_map) = &self.maybe_import_map { - match import_map.resolve(specifier, referrer) { - Ok(resolved_specifier) => { - ResolveResponse::Specifier(resolved_specifier) - } - Err(err) => ResolveResponse::Err(err.into()), - } + import_map + .resolve(specifier, referrer) + .map_err(|err| err.into()) } else { - match resolve_import(specifier, referrer.as_str()) { - Ok(specifier) => ResolveResponse::Specifier(specifier), - Err(err) => ResolveResponse::Err(err.into()), - } + resolve_import(specifier, referrer.as_str()).map_err(|err| err.into()) } } } diff --git a/cli/standalone.rs b/cli/standalone.rs index 593cff7ce2..829baa5578 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -150,7 +150,7 @@ impl ModuleLoader for EmbeddedModuleLoader { deno_core::resolve_import(specifier, referrer.as_str()) .map_err(|err| err.into()) }, - |r| r.resolve(specifier, &referrer).to_result(), + |r| r.resolve(specifier, &referrer), ) } diff --git a/cli/tests/testdata/bundle/shebang_file.bundle.out b/cli/tests/testdata/bundle/shebang_file.bundle.out index 1be80b68c3..df425f6566 100644 --- a/cli/tests/testdata/bundle/shebang_file.bundle.out +++ b/cli/tests/testdata/bundle/shebang_file.bundle.out @@ -1,4 +1,4 @@ -[WILDCARD] +Bundle file:///[WILDCARD]/subdir/shebang_file.js #!/usr/bin/env -S deno run --allow-read // deno-fmt-ignore-file // deno-lint-ignore-file diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs index 4538aababc..419ac2da66 100644 --- a/cli/tools/bench.rs +++ b/cli/tools/bench.rs @@ -4,7 +4,6 @@ use crate::args::BenchOptions; use crate::args::CliOptions; use crate::args::TypeCheckMode; use crate::colors; -use crate::graph_util::contains_specifier; use crate::graph_util::graph_valid; use crate::ops; use crate::proc_state::ProcState; @@ -24,7 +23,6 @@ use deno_core::futures::stream; use deno_core::futures::FutureExt; use deno_core::futures::StreamExt; use deno_core::ModuleSpecifier; -use deno_graph::ModuleKind; use deno_runtime::permissions::Permissions; use deno_runtime::permissions::PermissionsContainer; use deno_runtime::tokio_util::run_local; @@ -548,19 +546,9 @@ pub async fn run_benchmarks_with_watch( let mut modules_to_reload = if files_changed { Vec::new() } else { - bench_modules - .iter() - .map(|url| (url.clone(), ModuleKind::Esm)) - .collect() + bench_modules.clone() }; - let graph = ps - .create_graph( - bench_modules - .iter() - .map(|s| (s.clone(), ModuleKind::Esm)) - .collect(), - ) - .await?; + let graph = ps.create_graph(bench_modules.clone()).await?; graph_valid(&graph, !no_check, ps.options.check_js())?; // TODO(@kitsonk) - This should be totally derivable from the graph. @@ -618,7 +606,7 @@ pub async fn run_benchmarks_with_watch( deno_core::resolve_url_or_path(&path.to_string_lossy()).ok() }) { if modules.contains(&path) { - modules_to_reload.push((specifier, ModuleKind::Esm)); + modules_to_reload.push(specifier); break; } } @@ -649,7 +637,7 @@ pub async fn run_benchmarks_with_watch( }) }; - let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| { + let operation = |modules_to_reload: Vec| { let permissions = &permissions; let bench_options = &bench_options; ps.borrow_mut().reset_for_file_watcher(); @@ -659,7 +647,7 @@ pub async fn run_benchmarks_with_watch( let specifiers = collect_specifiers(&bench_options.files, is_supported_bench_path)? .into_iter() - .filter(|specifier| contains_specifier(&modules_to_reload, specifier)) + .filter(|specifier| modules_to_reload.contains(specifier)) .collect::>(); check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?; diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index ac17684e20..437bad1d49 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -134,7 +134,7 @@ fn bundle_module_graph( graph: &deno_graph::ModuleGraph, ps: &ProcState, ) -> Result { - log::info!("{} {}", colors::green("Bundle"), graph.roots[0].0); + log::info!("{} {}", colors::green("Bundle"), graph.roots[0]); let ts_config_result = ps .options @@ -145,29 +145,12 @@ fn bundle_module_graph( } } - let mut output = deno_emit::bundle_graph( + deno_emit::bundle_graph( graph, deno_emit::BundleOptions { bundle_type: deno_emit::BundleType::Module, emit_options: ts_config_result.ts_config.into(), emit_ignore_directives: true, }, - )?; - - // todo(https://github.com/denoland/deno_emit/issues/85): move to deno_emit - if let Some(shebang) = shebang_file(graph) { - output.code = format!("{}\n{}", shebang, output.code); - } - - Ok(output) -} - -fn shebang_file(graph: &deno_graph::ModuleGraph) -> Option { - let source = graph.get(&graph.roots[0].0)?.maybe_source.as_ref()?; - let first_line = source.lines().next()?; - if first_line.starts_with("#!") { - Some(first_line.to_string()) - } else { - None - } + ) } diff --git a/cli/tools/check.rs b/cli/tools/check.rs index 6e2ccd4ffe..2ab4fe498b 100644 --- a/cli/tools/check.rs +++ b/cli/tools/check.rs @@ -6,7 +6,6 @@ use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; use deno_core::parking_lot::RwLock; -use deno_graph::ModuleKind; use deno_runtime::colors; use once_cell::sync::Lazy; use regex::Regex; @@ -55,7 +54,7 @@ pub struct CheckResult { /// It is expected that it is determined if a check and/or emit is validated /// before the function is called. pub fn check( - roots: &[(ModuleSpecifier, ModuleKind)], + roots: &[ModuleSpecifier], graph_data: Arc>, cache: &TypeCheckCache, npm_resolver: &NpmPackageResolver, @@ -78,7 +77,7 @@ pub fn check( let root_names = get_tsc_roots(&segment_graph_data, check_js); if options.log_checks { - for (root, _) in roots { + for root in roots { let root_str = root.as_str(); // `$deno` specifiers are internal, don't print them. if !root_str.contains("$deno") { @@ -92,7 +91,7 @@ pub fn check( let maybe_tsbuildinfo = if options.reload { None } else { - cache.get_tsbuildinfo(&roots[0].0) + cache.get_tsbuildinfo(&roots[0]) }; // to make tsc build info work, we need to consistently hash modules, so that // tsc can better determine if an emit is still valid or not, so we provide @@ -137,7 +136,7 @@ pub fn check( }; if let Some(tsbuildinfo) = response.maybe_tsbuildinfo { - cache.set_tsbuildinfo(&roots[0].0, &tsbuildinfo); + cache.set_tsbuildinfo(&roots[0], &tsbuildinfo); } if diagnostics.is_empty() { diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 12f7b7dc45..163d3ffcd9 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -14,7 +14,6 @@ use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_core::resolve_url_or_path; use deno_doc as doc; -use deno_graph::ModuleKind; use deno_graph::ModuleSpecifier; use std::path::PathBuf; @@ -42,7 +41,7 @@ pub async fn print_docs( ); let analyzer = deno_graph::CapturingModuleAnalyzer::default(); let graph = deno_graph::create_graph( - vec![(source_file_specifier.clone(), ModuleKind::Esm)], + vec![source_file_specifier.clone()], &mut loader, deno_graph::GraphOptions { is_dynamic: false, @@ -78,9 +77,7 @@ 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(), ModuleKind::Esm)]) - .await?; + let graph = ps.create_graph(vec![root_specifier.clone()]).await?; let doc_parser = doc::DocParser::new( graph, doc_flags.private, diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 87e2d41d2d..21b3d03f7f 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -14,7 +14,6 @@ use deno_graph::Dependency; use deno_graph::Module; use deno_graph::ModuleGraph; use deno_graph::ModuleGraphError; -use deno_graph::ModuleKind; use deno_graph::Resolved; use deno_runtime::colors; @@ -34,7 +33,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { let ps = ProcState::build(flags).await?; if let Some(specifier) = info_flags.file { let specifier = resolve_url_or_path(&specifier)?; - let graph = ps.create_graph(vec![(specifier, ModuleKind::Esm)]).await?; + let graph = ps.create_graph(vec![specifier]).await?; if info_flags.json { let mut json_graph = json!(graph); @@ -395,7 +394,7 @@ impl<'a> GraphDisplayContext<'a> { ); } - let root_specifier = self.graph.resolve(&self.graph.roots[0].0); + let root_specifier = self.graph.resolve(&self.graph.roots[0]); match self.graph.try_get(&root_specifier) { Ok(Some(root)) => { if let Some(cache_info) = root.maybe_cache_info.as_ref() { diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index f6bbf9b9cf..cb7d18c46a 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -446,9 +446,7 @@ impl ReplSession { .proc_state .maybe_resolver .as_ref() - .and_then(|resolver| { - resolver.resolve(i, &self.referrer).to_result().ok() - }) + .and_then(|resolver| resolver.resolve(i, &self.referrer).ok()) .or_else(|| ModuleSpecifier::parse(i).ok()) .and_then(|url| NpmPackageReference::from_specifier(&url).ok()) }) diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 56674b9762..c4c39ede32 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -7,7 +7,6 @@ use crate::args::TypeCheckMode; use crate::colors; use crate::display; use crate::file_fetcher::File; -use crate::graph_util::contains_specifier; use crate::graph_util::graph_valid; use crate::ops; use crate::proc_state::ProcState; @@ -32,7 +31,6 @@ use deno_core::futures::StreamExt; use deno_core::parking_lot::Mutex; use deno_core::url::Url; use deno_core::ModuleSpecifier; -use deno_graph::ModuleKind; use deno_runtime::fmt_errors::format_js_error; use deno_runtime::ops::io::Stdio; use deno_runtime::ops::io::StdioPipe; @@ -1374,19 +1372,9 @@ pub async fn run_tests_with_watch( let mut modules_to_reload = if files_changed { Vec::new() } else { - test_modules - .iter() - .map(|url| (url.clone(), ModuleKind::Esm)) - .collect() + test_modules.clone() }; - let graph = ps - .create_graph( - test_modules - .iter() - .map(|s| (s.clone(), ModuleKind::Esm)) - .collect(), - ) - .await?; + let graph = ps.create_graph(test_modules.clone()).await?; graph_valid(&graph, !no_check, ps.options.check_js())?; // TODO(@kitsonk) - This should be totally derivable from the graph. @@ -1445,7 +1433,7 @@ pub async fn run_tests_with_watch( deno_core::resolve_url_or_path(&path.to_string_lossy()).ok() }) { if modules.contains(&path) { - modules_to_reload.push((specifier, ModuleKind::Esm)); + modules_to_reload.push(specifier); break; } } @@ -1476,7 +1464,7 @@ pub async fn run_tests_with_watch( }) }; - let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| { + let operation = |modules_to_reload: Vec| { let permissions = &permissions; let test_options = &test_options; ps.borrow_mut().reset_for_file_watcher(); @@ -1490,9 +1478,7 @@ pub async fn run_tests_with_watch( ) .await? .into_iter() - .filter(|(specifier, _)| { - contains_specifier(&modules_to_reload, specifier) - }) + .filter(|(specifier, _)| modules_to_reload.contains(specifier)) .collect::>(); check_specifiers(&ps, permissions.clone(), specifiers_with_mode.clone()) diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs index aa306275c1..209eb30b77 100644 --- a/cli/tools/vendor/mod.rs +++ b/cli/tools/vendor/mod.rs @@ -268,11 +268,8 @@ async fn create_graph( let entry_points = flags .specifiers .iter() - .map(|p| { - let url = resolve_url_or_path(p)?; - Ok((url, deno_graph::ModuleKind::Esm)) - }) - .collect::, AnyError>>()?; + .map(|p| resolve_url_or_path(p)) + .collect::, _>>()?; ps.create_graph(entry_points).await } diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs index 4ac2bac86f..a24fa1e4f3 100644 --- a/cli/tools/vendor/test.rs +++ b/cli/tools/vendor/test.rs @@ -17,7 +17,6 @@ use deno_graph::source::LoadFuture; use deno_graph::source::LoadResponse; use deno_graph::source::Loader; use deno_graph::ModuleGraph; -use deno_graph::ModuleKind; use import_map::ImportMap; use crate::cache::ParsedSourceCache; @@ -214,11 +213,7 @@ impl VendorTestBuilder { pub async fn build(&mut self) -> Result { let output_dir = make_path("/vendor"); - let roots = self - .entry_points - .iter() - .map(|s| (s.to_owned(), deno_graph::ModuleKind::Esm)) - .collect(); + let roots = self.entry_points.clone(); let loader = self.loader.clone(); let parsed_source_cache = ParsedSourceCache::new(None); let analyzer = parsed_source_cache.as_analyzer(); @@ -260,7 +255,7 @@ impl VendorTestBuilder { } async fn build_test_graph( - roots: Vec<(ModuleSpecifier, ModuleKind)>, + roots: Vec, original_import_map: Option, mut loader: TestLoader, analyzer: &dyn deno_graph::ModuleAnalyzer, diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index d540e5b33b..3da2f5f252 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -863,7 +863,6 @@ mod tests { use crate::args::TsConfig; use deno_core::futures::future; use deno_core::OpState; - use deno_graph::ModuleKind; use std::fs; #[derive(Debug, Default)] @@ -907,7 +906,7 @@ mod tests { let fixtures = test_util::testdata_path().join("tsc2"); let mut loader = MockLoader { fixtures }; let graph = deno_graph::create_graph( - vec![(specifier, ModuleKind::Esm)], + vec![specifier], &mut loader, deno_graph::GraphOptions { is_dynamic: false, @@ -939,7 +938,7 @@ mod tests { let fixtures = test_util::testdata_path().join("tsc2"); let mut loader = MockLoader { fixtures }; let graph = deno_graph::create_graph( - vec![(specifier.clone(), ModuleKind::Esm)], + vec![specifier.clone()], &mut loader, deno_graph::GraphOptions { is_dynamic: false,