1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-18 13:22:55 -05:00

fix(task): only pass args to root task (#27213)

When we run `deno task` with args like `deno task foo arg` the argument
should only be passed to the root task, not to its dependencies.

Fixes https://github.com/denoland/deno/issues/27206
This commit is contained in:
Marvin Hagemeister 2024-12-03 16:35:46 +01:00 committed by GitHub
parent 2fbc5fea83
commit d5b63bb642
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 7 deletions

View file

@ -241,12 +241,15 @@ pub async fn execute_script(
description: None, description: None,
}, },
kill_signal, kill_signal,
cli_options.argv(),
) )
.await; .await;
} }
for task_config in &packages_task_configs { for task_config in &packages_task_configs {
let exit_code = task_runner.run_tasks(task_config, &kill_signal).await?; let exit_code = task_runner
.run_tasks(task_config, &kill_signal, cli_options.argv())
.await?;
if exit_code > 0 { if exit_code > 0 {
return Ok(exit_code); return Ok(exit_code);
} }
@ -263,6 +266,7 @@ struct RunSingleOptions<'a> {
cwd: &'a Path, cwd: &'a Path,
custom_commands: HashMap<String, Rc<dyn ShellCommand>>, custom_commands: HashMap<String, Rc<dyn ShellCommand>>,
kill_signal: KillSignal, kill_signal: KillSignal,
argv: &'a [String],
} }
struct TaskRunner<'a> { struct TaskRunner<'a> {
@ -279,9 +283,10 @@ impl<'a> TaskRunner<'a> {
&self, &self,
pkg_tasks_config: &PackageTaskInfo, pkg_tasks_config: &PackageTaskInfo,
kill_signal: &KillSignal, kill_signal: &KillSignal,
argv: &[String],
) -> Result<i32, deno_core::anyhow::Error> { ) -> Result<i32, deno_core::anyhow::Error> {
match sort_tasks_topo(pkg_tasks_config) { match sort_tasks_topo(pkg_tasks_config) {
Ok(sorted) => self.run_tasks_in_parallel(sorted, kill_signal).await, Ok(sorted) => self.run_tasks_in_parallel(sorted, kill_signal, argv).await,
Err(err) => match err { Err(err) => match err {
TaskError::NotFound(name) => { TaskError::NotFound(name) => {
if self.task_flags.is_run { if self.task_flags.is_run {
@ -317,6 +322,7 @@ impl<'a> TaskRunner<'a> {
&self, &self,
tasks: Vec<ResolvedTask<'a>>, tasks: Vec<ResolvedTask<'a>>,
kill_signal: &KillSignal, kill_signal: &KillSignal,
args: &[String],
) -> Result<i32, deno_core::anyhow::Error> { ) -> Result<i32, deno_core::anyhow::Error> {
struct PendingTasksContext<'a> { struct PendingTasksContext<'a> {
completed: HashSet<usize>, completed: HashSet<usize>,
@ -338,13 +344,21 @@ impl<'a> TaskRunner<'a> {
&mut self, &mut self,
runner: &'b TaskRunner<'b>, runner: &'b TaskRunner<'b>,
kill_signal: &KillSignal, kill_signal: &KillSignal,
argv: &'a [String],
) -> Option< ) -> Option<
LocalBoxFuture<'b, Result<(i32, &'a ResolvedTask<'a>), AnyError>>, LocalBoxFuture<'b, Result<(i32, &'a ResolvedTask<'a>), AnyError>>,
> >
where where
'a: 'b, 'a: 'b,
{ {
for task in self.tasks.iter() { let mut tasks_iter = self.tasks.iter().peekable();
while let Some(task) = tasks_iter.next() {
let args = if tasks_iter.peek().is_none() {
argv
} else {
&[]
};
if self.completed.contains(&task.id) if self.completed.contains(&task.id)
|| self.running.contains(&task.id) || self.running.contains(&task.id)
{ {
@ -366,7 +380,13 @@ impl<'a> TaskRunner<'a> {
match task.task_or_script { match task.task_or_script {
TaskOrScript::Task(_, def) => { TaskOrScript::Task(_, def) => {
runner runner
.run_deno_task(task.folder_url, task.name, def, kill_signal) .run_deno_task(
task.folder_url,
task.name,
def,
kill_signal,
args,
)
.await .await
} }
TaskOrScript::Script(scripts, _) => { TaskOrScript::Script(scripts, _) => {
@ -376,6 +396,7 @@ impl<'a> TaskRunner<'a> {
task.name, task.name,
scripts, scripts,
kill_signal, kill_signal,
args,
) )
.await .await
} }
@ -399,7 +420,7 @@ impl<'a> TaskRunner<'a> {
while context.has_remaining_tasks() { while context.has_remaining_tasks() {
while queue.len() < self.concurrency { while queue.len() < self.concurrency {
if let Some(task) = context.get_next_task(self, kill_signal) { if let Some(task) = context.get_next_task(self, kill_signal, args) {
queue.push(task); queue.push(task);
} else { } else {
break; break;
@ -429,6 +450,7 @@ impl<'a> TaskRunner<'a> {
task_name: &str, task_name: &str,
definition: &TaskDefinition, definition: &TaskDefinition,
kill_signal: KillSignal, kill_signal: KillSignal,
argv: &'a [String],
) -> Result<i32, deno_core::anyhow::Error> { ) -> Result<i32, deno_core::anyhow::Error> {
let cwd = match &self.task_flags.cwd { let cwd = match &self.task_flags.cwd {
Some(path) => canonicalize_path(&PathBuf::from(path)) Some(path) => canonicalize_path(&PathBuf::from(path))
@ -447,6 +469,7 @@ impl<'a> TaskRunner<'a> {
cwd: &cwd, cwd: &cwd,
custom_commands, custom_commands,
kill_signal, kill_signal,
argv,
}) })
.await .await
} }
@ -457,6 +480,7 @@ impl<'a> TaskRunner<'a> {
task_name: &str, task_name: &str,
scripts: &IndexMap<String, String>, scripts: &IndexMap<String, String>,
kill_signal: KillSignal, kill_signal: KillSignal,
argv: &[String],
) -> Result<i32, deno_core::anyhow::Error> { ) -> Result<i32, deno_core::anyhow::Error> {
// ensure the npm packages are installed if using a managed resolver // ensure the npm packages are installed if using a managed resolver
if let Some(npm_resolver) = self.npm_resolver.as_managed() { if let Some(npm_resolver) = self.npm_resolver.as_managed() {
@ -489,6 +513,7 @@ impl<'a> TaskRunner<'a> {
cwd: &cwd, cwd: &cwd,
custom_commands: custom_commands.clone(), custom_commands: custom_commands.clone(),
kill_signal: kill_signal.clone(), kill_signal: kill_signal.clone(),
argv,
}) })
.await?; .await?;
if exit_code > 0 { if exit_code > 0 {
@ -510,11 +535,12 @@ impl<'a> TaskRunner<'a> {
cwd, cwd,
custom_commands, custom_commands,
kill_signal, kill_signal,
argv,
} = opts; } = opts;
output_task( output_task(
opts.task_name, opts.task_name,
&task_runner::get_script_with_args(script, self.cli_options.argv()), &task_runner::get_script_with_args(script, argv),
); );
Ok( Ok(
@ -525,7 +551,7 @@ impl<'a> TaskRunner<'a> {
env_vars: self.env_vars.clone(), env_vars: self.env_vars.clone(),
custom_commands, custom_commands,
init_cwd: self.cli_options.initial_cwd(), init_cwd: self.cli_options.initial_cwd(),
argv: self.cli_options.argv(), argv,
root_node_modules_dir: self.npm_resolver.root_node_modules_path(), root_node_modules_dir: self.npm_resolver.root_node_modules_path(),
stdio: None, stdio: None,
kill_signal, kill_signal,

View file

@ -56,6 +56,11 @@
"args": "task a", "args": "task a",
"output": "./cycle_2.out", "output": "./cycle_2.out",
"exitCode": 1 "exitCode": 1
},
"arg_task_with_deps": {
"cwd": "arg_task_with_deps",
"args": "task a a",
"output": "./arg_task_with_deps.out"
} }
} }
} }

View file

@ -0,0 +1,4 @@
Task b echo 'b'
b
Task a echo "a"
a

View file

@ -0,0 +1,9 @@
{
"tasks": {
"a": {
"command": "echo",
"dependencies": ["b"]
},
"b": "echo 'b'"
}
}