Pass the --filter flag to a with task #10648
-
SummaryHello, I am wondering if turborepo can do the following: We are running our dev script which is setup in this way: {
"$schema": "https://turborepo.com/schema.json",
"tasks": {
"//#watch": {
"persistent": true,
"cache": false
},
"dev": {
"cache": false,
"persistent": true,
"dependsOn": [
"^build"
],
"with": [
"//#watch"
]
}
}
}
The dev script calls Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @bombillazo You're asking a great question — right now, What's happeningWhen you define: "dev": {
"with": ["//#watch"]
} The Workaround 1: Use a wrapper scriptInstead of relying purely on Example in your {
"scripts": {
"dev": "node ./scripts/dev.js"
}
} Then in const { execSync } = require("child_process");
const args = process.argv.slice(2).join(" ");
execSync(`turbo run //#watch --filter=${args}`, { stdio: "inherit" }); Now you can call: npm run dev -- my-package And it will forward the filter to your custom task. Workaround 2: Define scoped tasks per packageIf you consistently need to run {
"scripts": {
"watch": "node scripts/watch.js"
}
} Then run: turbo run watch --filter=my-package This keeps your filters at the CLI level, avoids the limitations of TL;DRCurrently, Turbo’s Let me know if you want help writing that up — it would be a very useful addition to Turborepo’s task system. |
Beta Was this translation helpful? Give feedback.
Hi @bombillazo You're asking a great question — right now,
with
tasks in Turborepo don't automatically receive the CLI flags (like--filter
) passed to the parent task.What's happening
When you define:
The
watch
task gets triggered internally, but Turbo doesn't forward any CLI args like--filter
or--force
to that task by default.Workaround 1: Use a wrapper script
Instead of relying purely on
with
, you can create a small wrapper task or script that forwardsprocess.argv
:Example in your
package.json
:Then in
scripts/dev.js
: