diff --git a/docs/shared/concepts/myreactapp.json b/docs/shared/concepts/myreactapp.json index 099d6664ff..71373a9a88 100644 --- a/docs/shared/concepts/myreactapp.json +++ b/docs/shared/concepts/myreactapp.json @@ -29,7 +29,8 @@ "serve": { "options": { "cwd": "apps/myreactapp", - "command": "vite serve" + "command": "vite serve", + "continuous": true }, "executor": "nx:run-commands", "configurations": {}, @@ -51,7 +52,8 @@ "serve-static": { "executor": "@nx/web:file-server", "options": { - "buildTarget": "build" + "buildTarget": "build", + "continuous": true }, "configurations": {} }, diff --git a/docs/shared/migration/adding-to-existing-project.md b/docs/shared/migration/adding-to-existing-project.md index f3e678673b..f4fb71a284 100644 --- a/docs/shared/migration/adding-to-existing-project.md +++ b/docs/shared/migration/adding-to-existing-project.md @@ -169,7 +169,8 @@ nx show project my-workspace --web "dev": { "options": { "cwd": ".", - "command": "next dev" + "command": "next dev", + "continuous": true }, "executor": "nx:run-commands", "configurations": {}, @@ -180,7 +181,8 @@ nx show project my-workspace --web "start": { "options": { "cwd": ".", - "command": "next start" + "command": "next start", + "continuous": true }, "dependsOn": ["build"], "executor": "nx:run-commands", diff --git a/docs/shared/migration/adding-to-monorepo.md b/docs/shared/migration/adding-to-monorepo.md index 36f2c78847..a28bed1991 100644 --- a/docs/shared/migration/adding-to-monorepo.md +++ b/docs/shared/migration/adding-to-monorepo.md @@ -165,7 +165,8 @@ nx show project my-workspace --web "dev": { "options": { "cwd": ".", - "command": "next dev" + "command": "next dev", + "continuous": true }, "executor": "nx:run-commands", "configurations": {}, @@ -176,7 +177,8 @@ nx show project my-workspace --web "start": { "options": { "cwd": ".", - "command": "next start" + "command": "next start", + "continuous": true }, "dependsOn": ["build"], "executor": "nx:run-commands", diff --git a/docs/shared/recipes/running-tasks/convert-to-inferred.md b/docs/shared/recipes/running-tasks/convert-to-inferred.md index 44a111a938..217f790aec 100644 --- a/docs/shared/recipes/running-tasks/convert-to-inferred.md +++ b/docs/shared/recipes/running-tasks/convert-to-inferred.md @@ -84,7 +84,8 @@ For example, if we migrated the `@nx/vite` plugin for a single app (i.e. `nx g @ "serve": { "executor": "nx:run-commands", "options": { - "command": "vite dev" + "command": "vite dev", + "continuous": true } }, "build": { diff --git a/docs/shared/recipes/running-tasks/defining-task-pipeline.md b/docs/shared/recipes/running-tasks/defining-task-pipeline.md index 17952aa361..4cc44f44cc 100644 --- a/docs/shared/recipes/running-tasks/defining-task-pipeline.md +++ b/docs/shared/recipes/running-tasks/defining-task-pipeline.md @@ -87,7 +87,23 @@ Or they can be [defined per-project](/reference/project-configuration#dependson) {% /tab %} {% /tabs %} -## Visualize task dependencies +## Continuous Task Dependencies + +If a task has a dependency that never exits, then the task will never start. To support this scenario, you can mark the dependency as a [continuous task](/reference/project-configuration#continuous). Labeling a task as continuous tells Nx to not wait for the process to exit, and it will be run alongside its dependents. + +```json {% fileName="apps/myapp/project.json" %} +{ + "targets": { + "serve": { + "continuous": true + } + } +} +``` + +The `continuous` option is most useful for running development servers. For example, the `e2e` task depends on a continuous `serve` task that starts the server to be tested againts. + +## Visualize Task Dependencies You can also visualize the actual task graph (alongside the projects) using [Nx graph](/features/explore-graph). This can be useful for debugging purposes. diff --git a/docs/shared/reference/project-configuration.md b/docs/shared/reference/project-configuration.md index b306a0f2a0..7dcb6994dc 100644 --- a/docs/shared/reference/project-configuration.md +++ b/docs/shared/reference/project-configuration.md @@ -30,7 +30,8 @@ nx show project myproject --web "dev": { "executor": "nx:run-commands", "options": { - "command": "vite dev" + "command": "vite dev", + "continuous": true }, "metadata": { "technologies": ["vite"] @@ -365,10 +366,14 @@ instance, `"dependsOn": ["build"]` of the `test` target tells Nx that before it can test `mylib` it needs to make sure that `mylib` is built, which will result in `mylib`'s dependencies being built as well. +{% callout type="note" title="Dependencies that do not exit" %} +If you specify a task in `dependsOn` that never exits, then the dependent task will never start. Label such dependencies as [continuous](#continuous) tasks, which tells Nx to not wait for the process to end before starting the dependent task. +{% /callout %} + You can also express task dependencies with an object syntax: {% tabs %} -{% tab label="Version 16+ (self)" %} +{% tab label="Dependencies on self" %} ```json { @@ -386,7 +391,7 @@ You can also express task dependencies with an object syntax: ``` {% /tab %} -{% tab label="Version 16+ (dependencies)" %} +{% tab label="Dependencies on other projects" %} ```json { @@ -405,7 +410,7 @@ You can also express task dependencies with an object syntax: ``` {% /tab %} -{% tab label="Version 16+ (specific projects)" %} +{% tab label="Dependencies on specific projects" %} ```json { @@ -423,25 +428,6 @@ You can also express task dependencies with an object syntax: } ``` -{% /tab %} -{% tab label="Version < 16" %} - -```json -{ - "targets": { - "build": { - "dependsOn": [ - { - "projects": "dependencies", // "dependencies" or "self" - "target": "build", // target name - "params": "ignore" // "forward" or "ignore", defaults to "ignore" - } - ] - } - } -} -``` - {% /tab %} {% /tabs %} @@ -470,9 +456,6 @@ Starting from v19.5.0, wildcards can be used to define dependencies in the `depe You can write the shorthand configuration above in the object syntax like this: -{% tabs %} -{% tab label="Version 16+" %} - ```json { "targets": { @@ -486,30 +469,8 @@ You can write the shorthand configuration above in the object syntax like this: } ``` -{% /tab %} -{% tab label="Version < 16" %} - -```json -{ - "targets": { - "build": { - "dependsOn": [{ "projects": "dependencies", "target": "build" }] - }, - "test": { - "dependsOn": [{ "projects": "self", "target": "build" }] - } - } -} -``` - -{% /tab %} -{% /tabs %} - With the expanded syntax, you also have a third option available to configure how to handle the params passed to the target. You can either forward them or you can ignore them (default). -{% tabs %} -{% tab label="Version 16+" %} - ```json { "targets": { @@ -533,40 +494,8 @@ With the expanded syntax, you also have a third option available to configure ho } ``` -{% /tab %} -{% tab label="Version < 16" %} - -```json -{ - "targets": { - "build": { - // forward params passed to this target to the dependency targets - "dependsOn": [ - { "projects": "dependencies", "target": "build", "params": "forward" } - ] - }, - "test": { - // ignore params passed to this target, won't be forwarded to the dependency targets - "dependsOn": [ - { "projects": "dependencies", "target": "build", "params": "ignore" } - ] - }, - "lint": { - // ignore params passed to this target, won't be forwarded to the dependency targets - "dependsOn": [{ "projects": "dependencies", "target": "build" }] - } - } -} -``` - -{% /tab %} -{% /tabs %} - This also works when defining a relation for the target of the project itself using `"projects": "self"`: -{% tabs %} -{% tab label="Version 16+" %} - ```json { "targets": { @@ -578,30 +507,8 @@ This also works when defining a relation for the target of the project itself us } ``` -{% /tab %} -{% tab label="Version < 16" %} - -```json -{ - "targets": { - "build": { - // forward params passed to this target to the project target - "dependsOn": [ - { "projects": "self", "target": "pre-build", "params": "forward" } - ] - } - } -} -``` - -{% /tab %} -{% /tabs %} - Additionally, when using the expanded object syntax, you can specify individual projects in version 16 or greater. -{% tabs %} -{% tab label="Version 16+" %} - ```json { "targets": { @@ -615,12 +522,42 @@ Additionally, when using the expanded object syntax, you can specify individual } ``` -{% /tab %} -{% /tabs %} - This configuration is usually not needed. Nx comes with reasonable defaults (imported in `nx.json`) which implement the configuration above. +### Continuous + +In Nx 21+, tasks that never exit (sometimes called long-running processes) can be configured with `"continuous": true` to prevent their dependent tasks from waiting for task completion. For example, the `e2e` task depends on a continuous `serve` task to ensure that the development server is running. + +In this example, application's configuration labels the `serve` task as continuous. + +```json {% fileName="apps/myapp/project.json" %} +{ + "targets": { + "serve": { + "continuous": true + } + } +} +``` + +And the E2E project's `e2e` task has a dependency on the `serve` task, which ensures that the server is running when we run the `e2e` task. + +```json {% fileName="apps/myapp-e2e/project.json" %} +{ + "targets": { + "e2e": { + "dependsOn": [ + { + "projects": "myapp", + "target": "serve" + } + ] + } + } +} +``` + ### Sync Generators In the same way that `dependsOn` tells Nx to run another task before running this task, the `syncGenerator` property tells Nx to run a generator to ensure that your files are in the correct state before this task is run. [Sync generators](/concepts/sync-generators) are especially useful for keeping configuration files up to date with the project graph. Sync generators are available in Nx 19.8+.