From 9aa20b3ba758765863a4c1055097fda399efcfc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 13 Mar 2023 22:44:16 -0400 Subject: refactor: --watch commands use deno_core::resolve_url_or_path (#18172) This commit changes various CLI subcommands that have support for the "--watch" flag to use initial current working directory when resolving "main module". This is part of migration towards explicitly passing current working directory to "deno_core::resolve_url_or_path" API. As a side effect this makes "deno --watch" more aligned to user expectations, where calling "Deno.chdir()" during program doesn't break watcher. Towards landing https://github.com/denoland/deno/pull/15454 --- cli/tools/bundle.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'cli/tools/bundle.rs') diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index c1d4befb1..5a42f834e 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use deno_core::error::AnyError; use deno_core::futures::FutureExt; -use deno_core::resolve_url_or_path_deprecated; +use deno_core::resolve_url_or_path; use deno_graph::Module; use deno_runtime::colors; @@ -35,16 +35,17 @@ pub async fn bundle( "Use alternative bundlers like \"deno_emit\", \"esbuild\" or \"rollup\" instead." ); + let module_specifier = + resolve_url_or_path(&bundle_flags.source_file, cli_options.initial_cwd())?; + let resolver = |_| { let cli_options = cli_options.clone(); - let source_file1 = &bundle_flags.source_file; - let source_file2 = &bundle_flags.source_file; + let module_specifier = &module_specifier; async move { - let module_specifier = resolve_url_or_path_deprecated(source_file1)?; - log::debug!(">>>>> bundle START"); let ps = ProcState::from_options(cli_options).await?; - let graph = create_graph_and_maybe_check(module_specifier, &ps).await?; + let graph = + create_graph_and_maybe_check(module_specifier.clone(), &ps).await?; let mut paths_to_watch: Vec = graph .specifiers() @@ -74,7 +75,7 @@ pub async fn bundle( result: Ok((ps, graph)), }, Err(e) => ResolutionResult::Restart { - paths_to_watch: vec![PathBuf::from(source_file2)], + paths_to_watch: vec![module_specifier.to_file_path().unwrap()], result: Err(e), }, }) -- cgit v1.2.3