-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: Watch Mode docs feedback #8317
Comments
So currently, it cannot watch persistent tasks? if I have a package built with TSC (not watching), I want the persistent app to reload whenever the packages are rebuilt. |
Currently persistent tasks are not reloaded. That is something that people have asked for in #8164, so we're definitely looking into it! If you don't mind me asking, what's your specific use case for reloading persistent tasks? We encourage people to keep using the built in watchers for existing tools because often times tool specific watchers have special logic for that tool, for instance |
When working with NestJS in a monorepo setup, I want the server to reboot whenever I edit the packages. For example, I need to reload app-1 and app-2 when package-1 changes. As @wujekbogdan mentioned, the watch mode that bundlers come with can only monitor changes made to files within that specific project. My current workaround is to have a separate compile task and a separate persistent dev task with Nodemon. Additionally, I have separate compile and dev tasks set up. When package code changes, Turbo detects it and triggers the "compile" task for package-1, app-1 and app-2. This updates the app-1 and app-2 dist directory, causing Nodemon to reboot the persistent script. Hopefully, this can be simplified in future versions. apps/app1/package.json
{
"script": {
"compile": "nest build -b swc",
"dev": "nodemon dist/main.js --watch dist --delay 1",
}
}
pacakges/package1/package.json
{
"script": {
"compile": "tsc",
}
}
turbo.json
{
"compile": {
"dependsOn": ["^compile"],
"inputs": ["src/**", "tsconfig.json"],
"outputs": ["dist/**"]
},
"dev": {
"persistent": true
}
}
|
Gotcha. Yeah that seems to be a common setup. We'll get that fixed ASAP |
@michael-land It sounds to me like we already have the behavior you're looking for but the documentation isn't strong enough to help you put the pieces together. Listing out the requirements I think you're describing as I'm understanding them. Let me know if I'm wrong so I can adjust:
Will this work for what you need? // turbo.json
{
"build" {
"dependsOn": ["^build"],
"inputs": ["src/**", "tsconfig.json"],
"outputs": ["dist/**"],
}
} Note that I'm not marking any tasks as persistent here. We're going to solely rely on // apps/app-1/package.json and apps/app-2/package.json
{
"scripts": {
"build": "nest build -b swc",
}
} // packages/package1/package.json
{
"scripts": {
"build": "tsc"
} When I use Does that sound right? (For context, when writing the documentation for this feature, I realized |
Hi Anthony, Thanks for getting back to me. You suggested the configuration If you'd like, I can provide a sample setup for reproduction. |
In that case, I believe you would do:
Note: In a real repo, I would likely use a Package Configuration instead of the
A couple of things worthy of note here:
Tell me if I got it this time. 😄 |
I guess not 🫢. I created a simple repo for reproduction: https://github.com/michael-land/turborepo2-watch In the video, I expect the app's console.log to reprint with the new value whenever I save. |
This appears to be an issue with the Nest.js hot-reloading server not tracing its modules correctly. I made a PR to your reproduction that shows this: michael-land/turborepo2-watch#1 What I'm noticing:
For me, that indicates that the Nest.js hot reloader isn't quite handling what it is meant to, but I admittedly don't know if the Nest.js hot reloader is supposed to handle this case. For the sake of thoroughness, I tried the first strategy I proposed and changed the Overall, it looks like |
I tried your PR, and Next.js example is working fine (I guess next.js might also watch node_modules or .next folder for hot reloads). However, I can't get |
Apologies, I left out that you'll want to remove the |
it works now 🥳 |
Love to hear it. Thinking about what docs updates I need to make to make this more clear. |
Does it mean that if I set up Turbo the way I described here then I'm all set? turbo watch dev --filter=@my-namespace/my-app Where the dev task for the app being watched is defined as: {
"dev": "tsup --watch --onSuccess 'node dist/index.js'"
} The {
"build": "tsup"
} And the turbo config is defined as {
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"dev": {
"persistent": true,
"dependsOn": ["^build"],
"cache": false
},
},
} Based on what you say, it seems that this setup is correct - Or am I wrong? Maybe I need to explicitly include the turbo watch build dev --filter=@my-namespace/my-app |
If I understand it correctly, you enforce the rebuild of the project itself, which will trigger the restart? I still think something like |
@wujekbogdan That sounds to me like it would work. Do you not get the behavior you're looking for? |
Yes, it works, but it would be good to clarify the following things in the docs:
|
Watch mode re-run my persistent task without kill previous job. I'd like it do not re-run persistent tasks. Or allows |
What is the improvement or update you wish to see?
The docs say
It might be misleading.
Is there any context that might help us understand?
This isn't accurate. The watch mode that bundlers (e.g., tsup, esbuild, rollup) come with is only able to watch for changes made to files they're bundling. This is a major issue and the reason why Turbo needed the watch mode that was introduced recently (thank you devs!). I would either remove this from the documentation or add some clarification.
Does the docs page already exist? Please link to it.
https://turbo.build/repo/docs/reference/watch#using-turbo-watch-with-persistent-tasks
The text was updated successfully, but these errors were encountered: