summaryrefslogtreecommitdiff
path: root/cli/tools/task.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-04-17 15:36:23 -0400
committerGitHub <noreply@github.com>2023-04-17 15:36:23 -0400
commitd2d62b6312f9c09f91e26acd0b4d88b3ddcf94cf (patch)
treef2f5f0eb14e76e38876b3c219c859405fa664aef /cli/tools/task.rs
parent559a61b879366c01fbbc078c03743cd836189ae7 (diff)
refactor(npm): add CliNodeResolver (#18742)
Diffstat (limited to 'cli/tools/task.rs')
-rw-r--r--cli/tools/task.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/cli/tools/task.rs b/cli/tools/task.rs
index 9e82f14d9..c64e2a77c 100644
--- a/cli/tools/task.rs
+++ b/cli/tools/task.rs
@@ -1,8 +1,11 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use crate::args::CliOptions;
use crate::args::Flags;
use crate::args::TaskFlags;
use crate::colors;
+use crate::node::CliNodeResolver;
+use crate::npm::NpmPackageResolver;
use crate::proc_state::ProcState;
use crate::util::fs::canonicalize_path;
use deno_core::anyhow::bail;
@@ -50,7 +53,7 @@ pub async fn execute_script(
Some(path) => canonicalize_path(&PathBuf::from(path))?,
None => config_file_path.parent().unwrap().to_owned(),
};
- let script = get_script_with_args(script, &ps);
+ let script = get_script_with_args(script, &ps.options);
output_task(task_name, &script);
let seq_list = deno_task_shell::parser::parse(&script)
.with_context(|| format!("Error parsing script '{task_name}'."))?;
@@ -92,11 +95,12 @@ pub async fn execute_script(
.unwrap()
.to_owned(),
};
- let script = get_script_with_args(script, &ps);
+ let script = get_script_with_args(script, &ps.options);
output_task(task_name, &script);
let seq_list = deno_task_shell::parser::parse(&script)
.with_context(|| format!("Error parsing script '{task_name}'."))?;
- let npx_commands = resolve_npm_commands(&ps)?;
+ let npx_commands =
+ resolve_npm_commands(&ps.npm_resolver, &ps.node_resolver)?;
let env_vars = collect_env_vars();
let exit_code =
deno_task_shell::execute(seq_list, env_vars, &cwd, npx_commands).await;
@@ -108,9 +112,8 @@ pub async fn execute_script(
}
}
-fn get_script_with_args(script: &str, ps: &ProcState) -> String {
- let additional_args = ps
- .options
+fn get_script_with_args(script: &str, options: &CliOptions) -> String {
+ let additional_args = options
.argv()
.iter()
// surround all the additional arguments in double quotes
@@ -231,13 +234,13 @@ impl ShellCommand for NpmPackageBinCommand {
}
fn resolve_npm_commands(
- ps: &ProcState,
+ npm_resolver: &NpmPackageResolver,
+ node_resolver: &CliNodeResolver,
) -> Result<HashMap<String, Rc<dyn ShellCommand>>, AnyError> {
let mut result = HashMap::new();
- let snapshot = ps.npm_resolver.snapshot();
+ let snapshot = npm_resolver.snapshot();
for id in snapshot.top_level_packages() {
- let bin_commands =
- crate::node::node_resolve_binary_commands(&id.nv, &ps.npm_resolver)?;
+ let bin_commands = node_resolver.resolve_binary_commands(&id.nv)?;
for bin_command in bin_commands {
result.insert(
bin_command.to_string(),