mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
refactor(npm): add CliNodeResolver (#18742)
This commit is contained in:
parent
559a61b879
commit
d2d62b6312
16 changed files with 474 additions and 442 deletions
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue