diff options
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/bench.rs | 22 | ||||
-rw-r--r-- | cli/tools/bundle.rs | 23 | ||||
-rw-r--r-- | cli/tools/check.rs | 9 | ||||
-rw-r--r-- | cli/tools/doc.rs | 7 | ||||
-rw-r--r-- | cli/tools/info.rs | 5 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 4 | ||||
-rw-r--r-- | cli/tools/test.rs | 24 | ||||
-rw-r--r-- | cli/tools/vendor/mod.rs | 7 | ||||
-rw-r--r-- | cli/tools/vendor/test.rs | 9 |
9 files changed, 26 insertions, 84 deletions
diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs index 4538aabab..419ac2da6 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<ModuleSpecifier>| { 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::<Vec<ModuleSpecifier>>(); check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?; diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index ac17684e2..437bad1d4 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<deno_emit::BundleEmit, AnyError> { - 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<String> { - 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 6e2ccd4ff..2ab4fe498 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<RwLock<GraphData>>, 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 12f7b7dc4..163d3ffcd 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 87e2d41d2..21b3d03f7 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 f6bbf9b9c..cb7d18c46 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 56674b976..c4c39ede3 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<ModuleSpecifier>| { 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::<Vec<(ModuleSpecifier, TestMode)>>(); check_specifiers(&ps, permissions.clone(), specifiers_with_mode.clone()) diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs index aa306275c..209eb30b7 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::<Result<Vec<_>, AnyError>>()?; + .map(|p| resolve_url_or_path(p)) + .collect::<Result<Vec<_>, _>>()?; ps.create_graph(entry_points).await } diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs index 4ac2bac86..a24fa1e4f 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<VendorOutput, AnyError> { 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<ModuleSpecifier>, original_import_map: Option<ImportMap>, mut loader: TestLoader, analyzer: &dyn deno_graph::ModuleAnalyzer, |