Skip to content
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

DependsOn project target does not work as expected #16138

Closed
OSRSBlue opened this issue Apr 5, 2023 · 4 comments · Fixed by #16675 or #16674
Closed

DependsOn project target does not work as expected #16138

OSRSBlue opened this issue Apr 5, 2023 · 4 comments · Fixed by #16675 or #16674
Assignees
Labels

Comments

@OSRSBlue
Copy link

OSRSBlue commented Apr 5, 2023

Current Behavior

Settings DependsOn to a specific project target for my "build:auth-client" does not execute the builds:docs target for my authentication-api project.

{
  "name": "openapi-generator",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/openapi-generator/src",
  "projectType": "library",
  "targets": {
    "build:auth-client": {
      "executor": "nx:run-commands",
      "options": {
          "command": "openapi-generator-cli generate -i ./apps/authentication-api/docs/swagger.yaml -g typescript-axios -o generated-sources/openapi"
        },
      "dependsOn": ["^authentication-api:build:docs"]
    }
  },
  "implicitDependencies": ["authentication-api"],
  "tags": []
}

Expected Behavior

When setting DependsOn to be "authentication-api:build:docs" I would expect it to execute the target build:docs for the package authentication-api. The format above I was using for depends on is "{PROJECTNAME}:{TARGET}".

For example, if I have my implicitDependencies including my app "authentication-api" I would expect to able to set the depends on project as "authentication-api" and the target "build:docs" explicitly.

GitHub Repo

No response

Steps to Reproduce

  1. Run the command "nx build:auth-client openapi-generator" to execute build task for generating client.
  2. Task will fail because "DependsOn" does not execute the build:docs target for the specified authentication-api project, which results in a failure.

Nx Report

Node : 18.4.0
   OS   : darwin arm64
   yarn : 1.22.19
   
   nx : 15.0.3
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.0.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.0.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.0.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.0.3
   @nrwl/js : 15.0.3
   @nrwl/linter : 15.0.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : 15.3.4
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.0.3
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.0.3
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.0.3
   @nrwl/web : 15.0.3
   @nrwl/webpack : 15.0.3
   @nrwl/workspace : 15.0.3
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @nx-go/nx-go: 2.7.0

Failure Logs

[error] The spec file is not found: ./apps/authentication-api/docs/swagger.yaml
[error] Check the path of the OpenAPI spec and try again.

 >  NX   ERROR: Something went wrong in run-commands - Command failed: openapi-generator-cli generate -i ./apps/authentication-api/docs/swagger.yaml -g typescript-axios -o generated-sources/openapi

   Pass --verbose to see the stacktrace.

Additional Information

The issue seems to be that DependsOn does not support specifying a specific project and target as a depends on. I may be using the wrong syntax, but I am trying to execute specific project targets when generating my service clients. I have multiple build X Client targets that are formatted as "build:x-client", which each depend on a single projects generated docs. I would like to have the granularity of depending on explicit project targets so that I do not need to build all of my docs for each API to generate one client that only depends on one API.

For example, I have three targets doing the same thing for each API: build:x-client, build:y-client, and build:z-client. If I want to build just my x-client I would expect to be able to depend on x-api and execute build docs instead of being required to build all of the docs for all my dependencies.

{
  "name": "openapi-generator",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "libs/openapi-generator/src",
  "projectType": "library",
  "targets": {
    "build:x-client": {
      "executor": "nx:run-commands",
      "options": {
          "command": "openapi-generator-cli generate -i ./apps/authentication-api/docs/swagger.yaml -g typescript-axios -o generated-sources/openapi"
        },
      "dependsOn": ["^x-api:build:docs"]
    },

    "build:y-client": {
      "executor": "nx:run-commands",
      "options": {
          "command": "openapi-generator-cli generate -i ./apps/authentication-api/docs/swagger.yaml -g typescript-axios -o generated-sources/openapi"
        },
      "dependsOn": ["^y-api:build:docs"]
    },

    "build:z-client": {
      "executor": "nx:run-commands",
      "options": {
          "command": "openapi-generator-cli generate -i ./apps/authentication-api/docs/swagger.yaml -g typescript-axios -o generated-sources/openapi"
        },
      "dependsOn": ["^z-api:build:docs"]
    }
  },
  "implicitDependencies": ["x-api", "y-api", "z-api"],
  "tags": []
}
@OSRSBlue
Copy link
Author

OSRSBlue commented Apr 5, 2023

I have two approaches for solving this:

  1. Create a custom executor (More work, but preferred to keep my executor expressive)
    This would require me to create a executor and support an option for DependsOnApiClientDocs, which would take the project name and target command that I want to execute before generating the client.

  2. Remove dependsOn and execute two commands sequentially
    This approach I would remove the DependsOn for each target and instead execute a command to build the docs before generating the client sequentially. I feel that this is a hacky work around and less expressive.

What do you all think would be a good approach if their is no support for specifying an explicit project and target with DependsOn?

@AgentEnder AgentEnder added type: feature scope: core core nx functionality and removed type: bug labels Apr 5, 2023
@AgentEnder
Copy link
Member

We are working on this: #16100

The support will only work with the expanded object notation for dependsOn, but should do what you expect.

@OSRSBlue
Copy link
Author

OSRSBlue commented Apr 5, 2023

@AgentEnder Awesome! For the time being I built a simple executor that uses the same object notation to build a specific project target.

@github-actions
Copy link

github-actions bot commented Jun 2, 2023

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants