diff options
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/bundle.rs | 4 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 15 | ||||
-rw-r--r-- | cli/tools/repl/mod.rs | 4 | ||||
-rw-r--r-- | cli/tools/run.rs | 35 | ||||
-rw-r--r-- | cli/tools/standalone.rs | 3 |
5 files changed, 23 insertions, 38 deletions
diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index 9420d9c8f..e5531d7e1 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -5,7 +5,6 @@ use std::sync::Arc; use deno_core::error::AnyError; use deno_core::futures::FutureExt; -use deno_core::resolve_url_or_path; use deno_graph::Module; use deno_runtime::colors; @@ -35,8 +34,7 @@ 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 module_specifier = cli_options.resolve_main_module()?; let resolver = |_| { let cli_options = cli_options.clone(); diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index a2d9a3027..547dc379b 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -49,7 +49,14 @@ pub async fn format( fmt_options: FmtOptions, ) -> Result<(), AnyError> { if fmt_options.is_stdin { - return format_stdin(fmt_options); + return format_stdin( + fmt_options, + cli_options + .ext_flag() + .as_ref() + .map(|s| s.as_str()) + .unwrap_or("ts"), + ); } let files = fmt_options.files; @@ -456,14 +463,14 @@ fn format_ensure_stable( } /// Format stdin and write result to stdout. -/// Treats input as TypeScript or as set by `--ext` flag. +/// Treats input as set by `--ext` flag. /// Compatible with `--check` flag. -fn format_stdin(fmt_options: FmtOptions) -> Result<(), AnyError> { +fn format_stdin(fmt_options: FmtOptions, ext: &str) -> Result<(), AnyError> { let mut source = String::new(); if stdin().read_to_string(&mut source).is_err() { bail!("Failed to read from stdin"); } - let file_path = PathBuf::from(format!("_stdin.{}", fmt_options.ext)); + let file_path = PathBuf::from(format!("_stdin.{ext}")); let formatted_text = format_file(&file_path, &source, &fmt_options.options)?; if fmt_options.check { if formatted_text.is_some() { diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 7224eb45f..fcc31a764 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -6,7 +6,6 @@ use crate::colors; use crate::proc_state::ProcState; use crate::worker::create_main_worker; use deno_core::error::AnyError; -use deno_core::resolve_path; use deno_runtime::permissions::Permissions; use deno_runtime::permissions::PermissionsContainer; use rustyline::error::ReadlineError; @@ -82,8 +81,7 @@ async fn read_eval_file( pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> { let ps = ProcState::build(flags).await?; - let main_module = - resolve_path("./$deno$repl.ts", ps.options.initial_cwd()).unwrap(); + let main_module = ps.options.resolve_main_module()?; let mut worker = create_main_worker( &ps, main_module, diff --git a/cli/tools/run.rs b/cli/tools/run.rs index 84ec75e1a..007e0fb2a 100644 --- a/cli/tools/run.rs +++ b/cli/tools/run.rs @@ -5,26 +5,18 @@ use std::sync::Arc; use deno_ast::MediaType; use deno_ast::ModuleSpecifier; -use deno_core::anyhow::Context; use deno_core::error::AnyError; -use deno_core::resolve_path; -use deno_core::resolve_url_or_path; -use deno_graph::npm::NpmPackageReqReference; use deno_runtime::permissions::Permissions; use deno_runtime::permissions::PermissionsContainer; use crate::args::EvalFlags; use crate::args::Flags; -use crate::args::RunFlags; use crate::file_fetcher::File; use crate::proc_state::ProcState; use crate::util; use crate::worker::create_main_worker; -pub async fn run_script( - flags: Flags, - run_flags: RunFlags, -) -> Result<i32, AnyError> { +pub async fn run_script(flags: Flags) -> Result<i32, AnyError> { if !flags.has_permission() && flags.has_permission_in_argv() { log::warn!( "{}", @@ -37,7 +29,7 @@ To grant permissions, set them before the script argument. For example: } if flags.watch.is_some() { - return run_with_watch(flags, run_flags.script).await; + return run_with_watch(flags).await; } // TODO(bartlomieju): actually I think it will also fail if there's an import @@ -52,12 +44,8 @@ To grant permissions, set them before the script argument. For example: ps.dir.upgrade_check_file_path(), ); - let main_module = - if NpmPackageReqReference::from_str(&run_flags.script).is_ok() { - ModuleSpecifier::parse(&run_flags.script)? - } else { - resolve_url_or_path(&run_flags.script, ps.options.initial_cwd())? - }; + let main_module = ps.options.resolve_main_module()?; + let permissions = PermissionsContainer::new(Permissions::from_options( &ps.options.permissions_options(), )?); @@ -69,8 +57,8 @@ To grant permissions, set them before the script argument. For example: pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> { let ps = ProcState::build(flags).await?; - let cwd = std::env::current_dir().context("Unable to get CWD")?; - let main_module = resolve_path("./$deno$stdin.ts", &cwd).unwrap(); + let main_module = ps.options.resolve_main_module()?; + let mut worker = create_main_worker( &ps, main_module.clone(), @@ -101,12 +89,12 @@ pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> { // TODO(bartlomieju): this function is not handling `exit_code` set by the runtime // code properly. -async fn run_with_watch(flags: Flags, script: String) -> Result<i32, AnyError> { +async fn run_with_watch(flags: Flags) -> Result<i32, AnyError> { let flags = Arc::new(flags); let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); let mut ps = ProcState::build_for_file_watcher((*flags).clone(), sender.clone()).await?; - let main_module = resolve_url_or_path(&script, ps.options.initial_cwd())?; + let main_module = ps.options.resolve_main_module()?; let operation = |main_module: ModuleSpecifier| { ps.reset_for_file_watcher(); @@ -140,13 +128,8 @@ pub async fn eval_command( flags: Flags, eval_flags: EvalFlags, ) -> Result<i32, AnyError> { - // deno_graph works off of extensions for local files to determine the media - // type, and so our "fake" specifier needs to have the proper extension. let ps = ProcState::build(flags).await?; - let main_module = resolve_path( - &format!("./$deno$eval.{}", eval_flags.ext), - ps.options.initial_cwd(), - )?; + let main_module = ps.options.resolve_main_module()?; let permissions = PermissionsContainer::new(Permissions::from_options( &ps.options.permissions_options(), )?); diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs index dcd2f5d43..93c3aebf0 100644 --- a/cli/tools/standalone.rs +++ b/cli/tools/standalone.rs @@ -39,8 +39,7 @@ pub async fn compile( compile_flags: CompileFlags, ) -> Result<(), AnyError> { let ps = ProcState::build(flags).await?; - let module_specifier = - resolve_url_or_path(&compile_flags.source_file, ps.options.initial_cwd())?; + let module_specifier = ps.options.resolve_main_module()?; let module_roots = { let mut vec = Vec::with_capacity(compile_flags.include.len() + 1); vec.push(module_specifier.clone()); |