jlandowner
jlandowner7mo ago

How can I create a seqential deno task to pass args to child task?

Hi, I read the docs and created tasks in deno.json like this. https://docs.deno.com/runtime/manual/tools/task_runner#executing-a-task
{
"tasks": {
"task-all": "deno task task-a && deno task task-b",
"task-a": "echo 'this task requires args'",
"task-b": "echo 'this task must run after task-a'"
}
}
{
"tasks": {
"task-all": "deno task task-a && deno task task-b",
"task-a": "echo 'this task requires args'",
"task-b": "echo 'this task must run after task-a'"
}
}
task-a requires args so it can run independently with deno task task-a ARGS I have to run task-b after task-a so I have to do with deno task task-a ARGS && deno task task-b. It is redundant so I created task-all task. I intended to run this deno task task-all ARGS. But in reality each tasks are executed as deno task task-a (no args) and deno task task-b ARGS. How can I create a seqential task to achive this?
Task Runner | Deno Docs
deno task provides a cross platform way to define and execute custom commands
6 Replies
jlandowner
jlandowner7mo ago
I tried to specify $1 but it still does not work.
"task-all": "deno task task-a $1 && deno task task-b",
"task-all": "deno task task-a $1 && deno task task-b",
Deno AI Helper
Deno AI Helper7mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, it seems like you're trying to pass arguments to a task within your deno.json configuration, and you want these arguments to be used by task-a but not by task-b. From what you've described, it looks like you're encountering an issue where task-all is not passing the arguments to task-a as you intended. Unfortunately, the Deno task runner does not currently support passing arguments to individual tasks when they are composed using &&. As a workaround, you might consider writing a small Deno script that programmatically invokes the tasks with the necessary arguments. This script could use Deno's subprocess API (Deno.run) to execute the tasks with more control over the arguments. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you need further assistance, you might want to reach out to the Deno community or check for updates in the Deno documentation or GitHub repository for any new features or patterns that could help with your use case.
jlandowner
jlandowner7mo ago
Thanks, bot. It makes sense. Where should I ask for double-check the accuracy of this advice?
Leokuma
Leokuma7mo ago
@dsherret Can you double check the bot's answer? Sorry for pinging you
dsherret
dsherret7mo ago
yeah, unfortunately like npm run, there's no way to do that out of the box once things start becoming complicated, you may want to extract it out to a script and use dax https://github.com/dsherret/dax?tab=readme-ov-file#executing-commands
jlandowner
jlandowner7mo ago
@Leokuma @dsherret Thank you for checking the answer and more information <:deno_thankyou:1181938324273893376>