Caching & dependencies between targets
See original GitHub issueDescription
Adding the ability to specify dependencies between targets (and optionally, configurations) and ensuring these targets / configurations have been run before executing the current target.
Motivation
I’ve got a workspace with a lot of projects. Each of those projects have “build” and “deploy” targets. When running “deploy”, I first have to make sure I’ve already run “build”, otherwise (obviously) I’ll deploy the wrong version.
This is on top of dependencies between projects, which I also have.
The ideal is that when I run nx run my-project:deploy --withDeps
it should first execute my-project:build
.
An additional wrinkle is that, regardless of the configuration I’m using to deploy, I always want to run the production
build configuration.
Suggested Implementation
Ideally in angular.json
, add a field to each target: dependsOnTargets
. This is an array of strings formatted {target}[:{configuration}]
.
Before running any target, nx should first run each target in dependsOnTargets
. Just as if a target is run directly, the cached result should be used if available.
Alternate Implementations
Essentially the same as above, but in nx.json
instead.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7
Just adding on that this type of feature would be great to have. I’m running into a similar issue and using the
run-commands
with chained commands feels like a hack and does not work in the desired way I want.For example, if I have Project X which has a target called
serve
that depends on Project Y and Project Z to be served as well prior to it being run, if I chain them, since it starts a server for each, it doesn’t have a graceful “end” to the task since it will end with likeServed on localhost:3000
. The problem here is that since it runs the first Project X serve, it ends up not continuing since the command hasn’t technically “finished”.It would be nice to just have something like Gradle’s
dependsOn
or Bazel’s:deps
to explicitly define target dependencies. It also makes it more clear so you don’t have to have separate targets and create a “wrapper” target that encompasses those.Really need this feature too. Can be easily done with Turborepo