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 <subcommand> --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
This commit is contained in:
Bartek Iwańczuk 2023-03-13 22:44:16 -04:00 committed by GitHub
parent 48ede89f1f
commit 9aa20b3ba7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 24 deletions

View file

@ -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<PathBuf> = 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),
},
})